Previous Topic

Next Topic

Working with Tables

A database may contain multiple tables, and a table may belong to multiple databases. Tables created using the c-treeDB interface are kept as files with the extension .dat. Indices are stored in separate files with the extension .idx. The general process to create and use a c-treeDB table and its associated indices is as follows:

  • Allocate table handle
  • Add or insert fields
  • Add indices
  • Add index segments
  • Create the table
  • Open the table
  • Operate on records

Before you can work with an existing table, the table must be opened as follows:

  • Allocate table handle
  • Open the table
  • Operate on records

With c-treeDB, it is possible to modify an existing table. The general process to modify a table after it has been created is as follows:

  • Open the table
  • Make changes to:
    • Fields and/or
    • Indices and/or
    • Segments
  • Call the alter table function: ctdbAlterTable().

More details on this process are described in "Altering a table".

In general, the table creation is done once in the application; the table is opened and the data is added in a separate routine. During table creation, besides the table layer itself, three c-treeDB APIs will be directly involved: the fields, indices and segments. These APIs are only directly involved when the table is being created, or in the event the table structure is modified. When records are being added to or searched in the table, these APIs are not relevant, but the record layer is crucial.

With this in mind, this section on Tables discusses these layers in the appropriate order:

  • Table creation using fields, indices, and segments.
  • Table parameters and properties.
  • Opening and manipulating tables.