The features of this class can be divided into three logic groups. The column attributes - name, table_name, type, is_required, etc. comprise the first group.
Note that the open feature being redefined from the RECORDSET class verifies is there in the database a table with the specified name. As usual in DALE, table's name is allowed to be composed including also table's qualifier and/or table's owner names.
The following examples explain how to manipulate with records of database table:
db : DATABASE table : DB_TABLE -- database table cursor: RS_CURSOR -- cursor for the table record: RECORD -- record of the table query : QUERY c : CHARACTER a : ARRAY [ANY] ... !!table.open (db, "People") -- open table People; note that an -- error will be triggered if there's -- no such table in the database -- How to add new record to the table: record := table.empty_record -- } create new empty record.put ("Ken Jordan", "Name") -- } record and fill up record.put (50, "Age") -- } its fields table.add (record) -- add record to the table -- same but using array instead of record (for simplicity, let the -- table to contain only two fields - Name and Age: table.add_list (<<"Ken Jordan", 50>>) -- How to insert a new record into the table in the specified -- location (see comments after code): record := table.empty_record -- } create new empty record.put ("Sandy Williams", "Name") -- } record and fill up record.put (30, "Age") -- } its fields cursor := table.cursor -- obtain cursor at the table cursor.at (1000) -- locate cursor at 1000th record table.insert (cursor, record) -- insert new 1000th record -- How to update an existing record in the table: cursor := table.cursor -- obtain cursor at the table record := table.empty_record -- get new empty record record.put ("Lora Ashly", "Name") -- update Name of the person table.put (cursor, record) -- update first record -- or: cursor := table.cursor -- obtain cursor at the table cursor.last -- locate on the last record record := table.item_at (cursor) -- get record under cursor record.put ( record.field ("Age").to_integer + 1, "Age") -- increment age table.put (cursor, record) -- update record under cursor -- or, what's the same: cursor := table.cursor -- obtain cursor at the table cursor.last -- locate on the last record record := table.item_at (cursor) -- get record under cursor record.field ("Age").plus (1) -- increment age table.put (cursor, record) -- update record under cursor -- How to delete record from the table: cursor := table.cursor -- obtain cursor at the table cursor.forth -- locate at 2nd record table.delete (cursor) -- delete that record -- How to filter records in a table: table.where ("Age >= 18") -- since this point only adult people -- will be selected -- How to sort records in a table: table.order_by ("Name") -- since this point all the people -- will be sorted by their name
Some comments on modification of records via put, add, delete, insert, etc. These features make easier the usage of basic operations under table's contents. For example, if you want to add a new record to a table you can create a QUERY object, construct the correspondent INSERT statement from the table's name and fields values, then execute that query and, probably, check rows count to ensure that operation was successful. The add, add_list, insert, insert_list features fulfill most of those operations by themselves and, therefore, make developer's code short, elegant and safe.
However, in SQL data access model, records don't have an absolute "position" inside the table. Therefore when you add a new record to the table you have to ensure that the record will be at the end of actual table's view; when you insert a new record you have to ensure that the record will be in actual table's view at the location where the specified cursor stays.
class DB_TYPE
This class allows to get information about capabilities and peculiarities of current data source.
This class gives an opportunity to deal with transactions. Use the DB_INFORMATION class to find out whether transactions are supported in a data source.
The next schema explains how to commit or roll back transactions:
database: DATABASE ... -- establish connection, etc. database.options.set_autocommit_mode (FALSE) -- turn it off ... -- some modification of database's contents database.transaction.commit -- or database.transaction.rollback
This class is used to store long binary data.
Every call to ODBC API returns a code which indicates a success or a failure. You can obtain this information via the status of every ODBC_ELEMENT.
These two classes allow to get and set options of DATABASE and QUERY. For example, to change scrolling mode of a query you can write:
const: ODBC_CONSTANTS ... query.options.set_scroll_mode (const.SQL_CURSOR_FORWARD_ONLY)