While all access to a database is possible using SQL as described above, the XSB-ODBC interface supports higher-level interaction for which the user need not know or write SQL statements; that is done as necessary by the interface. With the relation level interface, users can simply declare a predicate to access a table and the system generates the necessary underlying code, generating specialized code for each mode in which the predicate is called.
To declare a predicate to access a database table, a user must use the odbc_import/2 interface predicate.
The syntax of odbc_import/2 is as follows:
| ?- odbc_import('TableName'('FIELD1', 'FIELD2', ..., 'FIELDn'), 'PredicateName').
where 'TableName' is the name of the database table to be
accessed and 'PredicateName' is the name of the XSB predicate
through which access will be made. 'FIELD1', 'FIELD2',
... , 'FIELDn' are the exact attribute namesFor example, to create a link to the Test table through the 'test' predicate:
| ?- odbc_import('Test'('TId','TName','Length','Price'),test).
yes
When connecting to multiple data sources, you should use the form:
| ?- odbc_import(ConnectionName,
'TableName'('FIELD1', 'FIELD2', ..., 'FIELDn'),
'PredicateName').