Once the links between tables and predicates have been successfully established, information can then be extracted from these tables using the corresponding predicates. Continuing from the above example, now rows from the table Test can be obtained:
| ?- test(TId, TName, L, P). TId = t001 TName = X-Ray L = 5 P = 100Backtracking can then be used to retrieve the next row of the table Test.
Records with particular field values may be selected in the same way as in Prolog; no mode specification for database predicates is required. For example:
| ?- test(TId, 'X-Ray', L, P).will automatically generate the query:
SELECT rel1.TId, rel1.TName, rel1.Length, rel1.Price FROM Test rel1 WHERE rel1.TName = ?and
| ?- test('NULL'(_), 'X-Ray', L, P).
generates: (See Section 4.2.6)
SELECT NULL , rel1.TName, rel1.Length, rel1.Price FROM Test rel1 WHERE rel1.TId IS NULL AND rel1.TName = ?During the execution of this query the bind variable ? will be bound to the value 'X-Ray'.
Of course, the same considerations about cursors noted in Section 4.2.3 apply to the relation-level interface. Accordingly, the ODBC interface also defines the predicate odbc_import/4 which allows the user to specify that rows are to be fetched through findall/3. For example, the call
odbc_import('Test'('TId','TName','Length','Price'),test,[findall(true)]).
will behave as described above but will make all database calls
through findall/3 and return rows by backtracking through a list
rather than maintaining open cursors.
Also as a courtesy to Quintus Prolog users we have provided compatibility support for some PRODBI predicates which access tables at a relational level 4.2.
| ?- odbc_attach(PredicateName, table(TableName)).
eg. invoke
| ?- odbc_attach(test2, table('Test')).
and then execute
| ?- test2(TId, TName, L, P).to retrieve the rows.