next up previous contents index
Next: Using the Relation Level Up: Using the Interface Previous: Accessing Tables in Data   Contents   Index

Accessing Tables in Data Sources through the Relation Level

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 names(case sensitive) as defined in the database table schema. The chosen columns define the view and the order of arguments for the database predicate 'PredicateName'.

For 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').


next up previous contents index
Next: Using the Relation Level Up: Using the Interface Previous: Accessing Tables in Data   Contents   Index
Luis Fernando P. de Castro 2003-06-27