Skip to content

Opening Database Tables

Nothing can be done with a table until that table has been opened. Tables are opened with the Open command. Like other commands that address tables, this command uses the DataFlex name of the table.

Record Buffers

When a table is opened, a buffer is established in memory containing enough room for all the fixed-length columns in the table's definition. The size of this buffer is slightly larger than the size of the table's record length. Except for the special case of system tables, the buffer is empty immediately after an open.

A DataFlex program may have literally hundreds of tables open at the same time (memory capacity of the computer permitting). There are as many record buffers in memory as there are tables open, but each buffer contains only one record from its table. Buffers may be empty or may contain a record, but they may not contain more than one record at a time.

When a record buffer is empty, it is said to be inactive. When it contains an existing record, it becomes active. Active record buffers must either be saved, cleared, deleted, or deactivated (disassociated from the existing record on disk) by moving a value to their record number. If another record is moved to a buffer containing an active record, an error is triggered.

When a table's record buffer is active, the table's status is true. When the buffer is inactive, the table's status is false. Each open table has its own status at all times, and it may be queried regardless of finds that have been done in other tables. See the DataFlex Language Reference for more information on the DF_FILE_STATUS attribute.

System Tables

A table that is defined to have a maximum of one record—a so-called "system" table—differs from other (multi-record) tables in that the contents of its single record are moved into the record buffer immediately when the table is opened.

Whether a table is a system table is controlled by the DF_FILE_IS_SYSTEM_FILE Database API attribute.

System tables are useful for data that pertains to a site or even an application. It is common, for example, for an entity (typically a company) to maintain its name, address, and telephone number in a system table for use in applications generally. It is also common for an application to rely on a system table to hold the last invoice number for an application in which multiple users may be creating new invoices in a single transaction table concurrently.

Since system tables have only one record, it is not necessary to clear or find the single record in the table; the runtime does this for you. When a system table is opened, the data from its only record is automatically moved into its buffer.

See Also