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

Using the Relation Level Interface

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 = 100

Backtracking 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).
generates 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 7.3.7)


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 'X-Ray'.

Note that if a field includes a quote $(')$ then this should be represented by using two quotes.

Also as a courtesy to Quintus Prolog users we have provided compatibility support for some PRODBI predicates which access tables at a relational level.


i) | ?- odbc_attach(PredicateName, table(TableName)).

eg. invoke

| ?- odbc_attach(test2, table('Test')).
and then execute
| ?- test2(TId, TName, L, P).
to retrieve the rows.

ii) | ?- odbc_record('Test', R).

    R = [t001, X-Ray, 5, 100];

    R = ...
You can use odbc_record/2 to treat the whole database row as a single list structure.


next up previous contents index
Next: The View Level Interface Up: Using the Interface Previous: Accessing Tables in Data   Contents   Index
Baoqiu Cui
2000-04-23