![]() |
|
||||
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
|||||
|
|
||||||
| Other Library Functions | ||||||
| function |
dbQuery |
|
Library: Database access (OMDB) legacy library
Include: omdb.xin |
define external function dbQuery
value dbDatabase database
SQL value stream query
record modifiable dbField record
Argument definitions
Use dbQuery to execute an SQL statement on a database.
You must include the following line at the beginning of your OmniMark program:
include "omdb.xin"
The dbDatabase object database must represent an existing database connection (else external exception OMDB101).
The SQL statement supplied for query must be a valid SQL statement (else external exception OMDB501).
The connection represented by dbDatabase must remain open for as long as you are using the record set produced by the dbQuery.
The data cursor is positioned on the first row of the result set, assuming a row exists.
External exception OMDB202 is thrown if the query does not produce any columns.
The result set produced by the dbQuery function is attached to the dbField OMX shelf variable. Each item on the dbField OMX shelf may be used to access the value of a queried field in the current row of the result set. The key of each shelf item is the unique name of the corresponding field.
The key name of the field item is set to the queried column name. If that key name already exists in the dbField shelf, a suffix is added to the key name to make it unique. The suffix consists of an asterisk followed by the occurrence count. For example, the first column in the query named "StudentID" will correspond to the dbField item with the key "StudentID". The second occurrence of a column named "StudentID" in the query will correspond to the dbField item with a key named "StudentID*2".
include "omdb.xin"
process
local dbDatabase my-database
local dbField 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 dbOpenODBC "DatabaseDemo"
dbQuery my-database SQL SQL-query record my-query
repeat over my-query
output key of my-query
output '%t' when ! #last
again
output '%n' || ( '-' repeated 45 ) || '%n'
repeat
exit unless dbRecordExists my-query
repeat over my-query
output dbFieldValue my-query null '-DNF-'
output '%t' when ! #last
again
output '%n'
dbRecordMove my-query
again
catch #external-exception identity catch-id message catch-msg
output 'An error occurred while accessing an omDB function.%n'
output '%g(catch-id) : %g(catch-msg)%n'
Copyright © Stilo International plc, 1988-2008.