Product Documentation

c-treeDB API for C++ - Developers Guide

Previous Topic

Next Topic

Creating a record object

A valid record object is required before most record operations can take place. You need to pass a valid CTTable object to the CTRecord constructor.

// create a CTRecord object

CTRecord ARecord(ATable);

If you create a dynamic CTRecord object with the new operator, you are required to destroy the object with the delete operator.

// create a dynamic CTRecord object

CTRecord* pRecord = new CTRecord(ATable);

if (!pRecord)

{

printf("CTRecord creation failed\n");

}

... other operations ..

// destroy the CTRecord object

delete pRecord;

After the record object has been created, but before any record operations can take place, the table associated with the record object must be opened.

In This Section

Record buffer layout

Sharing the same context

Resetting a record

Previous Topic

Next Topic

Record buffer layout

Based on the fields added by the user, c-treeDB will organize the record buffer as follows:

$DELFLD$

$NULFLD$

$ROWID$

field 0

field 1

...

field n

The user fields are stored in the table record in the same order in which they were added.. To initiate the operation on the records, a record handle must be declared and instantiated. Once the table associated with the record handle is opened, the record handle can be used to store the information that come from or go to the fields in the table.

Previous Topic

Next Topic

Sharing the same context

Every time one of the CTRecord class constructors creates a record object, the record object acquires its own context, so that each record buffer operates independently. Record operations that move the current record position will not interfere with each other.

There are situations where it may be necessary to have several different record objects sharing the same record context. In this case the developer can create the first record buffer using one of the CTRecord class constructors to acquire a new context. The initial record can then be duplicated by creating a new record object and passing the original record object instead of a table object. The duplicated records will share the same context of the original record buffer, but the duplicated record handle will not share the same memory buffer for holding the record data.

// create two records sharing the same context

CTRecord ARecord1(ATable);


// create the duplicated record object

CTRecord ARecord2(ARecord1);

In the code fragment above, the record object ARecord1 was created passing a table object as the parent object. ARecord1 is created with a new record context. ARecord2 was created passing the ARecord1 object as the parent object. ARecord2 is a duplicated copy of ARecord1.

Previous Topic

Next Topic

Resetting a record

A record object may be reset to its initial state, i.e. to the same state it had just after being created. The record reset function will perform the following actions on a record handle:

  • The context associated with the record is released
  • Record sets are turned off
  • Memory allocated for record buffer is released
  • Record properties are reinitialized.

// reset a record

try

{

ARecord.Reset();

}

catch (CTException &err)

{

printf("Record reset failed with error %d\n", err.GetErrorCode());

}

All records associated with a table can be reset in one operation by calling CTTable::ResetAll() method.

// reset all records

try

{

ATable.ResetAll();

}

catch (CTException &err)

{

printf("Reset all records failed with error %d\n", err.GetErrorCode());

}

When a table is closed, all records associated with that table are automatically reset by the CTTable::Close() method.

TOCIndex