|
|||||
db.field
|
The db.field OMX component allows you to access the data value that exists within a row of a database record set field. This OMX component is a shelf, where each field value is placed in a separate item on the shelf, and each item key is the unique name of the field. Use the db.field OMX component in conjunction with db.database to create a connection to a database and obtain a read-only set of data from that database.
Within your program, you can create as many instances of the db.field OMX component as you require by declaring global and local shelves of type "db.field". These shelves must be declared as variable.
When you use the db.query function, the db.field shelf is automatically bound to the record set created by the SQL query that you specify in that function. When you move the data cursor in the record set, using the db.move-record function, the db.field shelf is automatically repopulated with whatever values are in the current row. You retrieve values from the db.field OMX variable with the db.reader function.
Please refer to OMX Components for a general description of OMX components and how they are used.
The functions
db.query
- execute an SQL query on the specified database.
db.execute
- execute a stored procedure. (Must be a query.)
db.reader
- commit all the insert, delete, or update operations performed since the last db.commit or dbRollback.
db.record-exists
- check whether the data cursor is positioned on an existing row or not.
db.move-record
- change the position of the data cursor within the specified record set.
db.advance-recordset
- test for another result set.
Once you have declared your db.field OMX shelves, you can use those variables in the db.query
and db.reader
functions that are part of the OmniMark Database library. For example:
import "omdb.xmd" prefixed by db. process local db.database my-database local db.field my-query variable local stream SQL-query initial { "select C.CourseName, S.StudentName, SC.Grade " || "from Student S, Course C, StudentCourse sc " || "where SC.CID = C.CID and S.SID = SC.SID " } set my-database to db.open-odbc "MyDatabase" db.query my-database sql sql-query into my-query repeat exit unless db.record-exists my-query repeat over my-query output db.reader of my-query null '-dnf-' output '%t' when ! #last again output '%n' db.move-record my-query again