Product Documentation

c-treeDB API for C++ - Developers Guide

Previous Topic

Next Topic

Navigating records

c-treeDB provides features that allow navigation among records of a particular table. You can position the current record at the first record, last record, next record, previous record, or seek to a specific record if you know the record offset.

Setting a different default index for the record may change the order of the record navigation.

The record navigation function not only updates the current position of a record, but the record data is read from disk and placed in the record buffer inside the record handle. As the record is read from disk, the new record flag is set to false to indicate that the data in the record buffer originated from an existing record in the table.

In This Section

First record

Last record

Next record

Previous record

Seek to record

Previous Topic

Next Topic

First record

Call CTRecord::First() to position the current record at the first record of a table. If the table is empty, i.e. the table contains no records, CTRecord::First() returns NO (false).

// get the first record of the table

try

{

if (ARecord.First())

printf("First record found\n");

else

printf("Table is empty\n");

}

catch (CTException &err)

{

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

}

Previous Topic

Next Topic

Last record

Call CTRecord::Last() to position the current record at the last record of a table. If the table is empty, i.e. the table contains no records, CTRecord::Last() returns NO (false).

// get the last record of the table

try

{

if (ARecord.Last())

printf("Last record found\n");

else

printf("Table is empty\n");

}

catch (CTException &err)

{

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

}

Previous Topic

Next Topic

Next record

Call CTRecord::Next() to position the current record at the next record of a table. If the current record is already the last record of a table, CTRecord::Next() returns NO (false).

// get the next record of the table

try

{

if (ARecord.Next())

printf("Next record found\n");

else

printf("No more records\n");

}

catch (CTException &err)

{

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

}

A current record must exist before CTRecord::Next() is called or an ICUR_ERR (100) is thrown indicating that there can be no next record is the current record does not exist. You can establish a current record by calling CTRecord::First(), CTRecord::Last(), CTRecord::Find() or CTRecord::SeekRecord().

Previous Topic

Next Topic

Previous record

Call CTRecord::Prev() to position the current record at the previous record of a table. If the current record is already the first record of a table, CTRecord::Prev() returns NO (false).

// get the previous record of the table

try

{

if (ARecord.Prev())

printf("Previous record found\n");

else

printf("Already at first record\n");

}

catch (CTException &err)

{

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

}

A current record must exist before CTRecord::Prev() is called, or an ICUR_ERR (100)exception is thrown indicating that there can be no previous record if the current record does not exist. You can establish a current record by calling CTRecord::First(), CTRecord::Last(), CTRecord::Find() or CTRecord::SeekRecord().

Previous Topic

Next Topic

Seek to record

If you know in advance the offset of a given record, CTRecord::SeekRecord() can be used to make it the current record.

You can use CTRecord::GetRecordPos() and CTRecord::SeekRecord() to implement a bookmark system for your records. Retrieve the record offset with CTRecord::GetRecordPos(), which is the bookmark value, and later on you can quickly go back to the record by calling CTRecord::SeekRecord().

// get record bookmark

CTOFFSET GetBookMark(CTRecord &ARecord)

{

return ARecord.GetRecordPos();

}

// goto record bookmark

void GotoBookmark(CTRecord &ARecord, CTOFFSET bookmark)

{

ARecord.SeekRecord(bookmark);

}

TOCIndex