|
||||||||||
|
||||||||||
Other Library Functions |
function | dbTableUpdate |
Library: omdb - high level database access
Include: omdb.xin |
define external function dbTableUpdate value dbTable table from read-only stream values null value stream null optional where value stream where optional
Where:
table
values
null
where
This function updates records in a table using the supplied data and criteria. A NULL data value may be represented as an unattached stream or as an optionally defined string. The column name is identified as the key of each "values" parameter shelf item.
Date and time fields
If the record has a date, time, or timestamp field, you must represent the field's value in the OmniMark Date and Time library format. (This format returns the time with a time zone offset from UTC time, which most databases do not provide.)
The following program shows how to retrieve the average for each enrolled student and use dbTableUpdate to update his or her current average. The field data is updated through the dbTable OMX component.
process ; local variables local dbDatabase this-db local dbField student-average variable local dbTable student local stream SQL-query initial { "select sid, ave(Grade) " || "from StudentCourse " || "group by sid " } local stream average variable initial { ' ' with key 'Average' } ; create the database OMX objects set this-db to dbOpenODBC 'dbDemo' dbQuery this-db sql SQL-query record student-average set student to dbTableOpen this-db table 'Student' ; retrieve all student course averages repeat ; exit the loop if no more data exists exit unless dbRecordExists student-average ; update the student average set average{'Average'} to dbFieldValue student-average[2] null '0' dbTableUpdate student from average where "sid = ' " || dbFieldValue student-average{'sid'} || " ' " ; advance the cursor dbRecordMove student-average again ; catch the database exceptions 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'
---- |