Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic

Navigating records

c-treeDB API 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 ctdbFirstRecord() to position the current record at the first record of a table and retrieve the record data from disk into the specified record handle’s record buffer. If the table is empty (contains no records), ctdbFirstRecord() returns INOT_ERR (101).

/* get the first record of the table */

if (ctdbFirstRecord(hRecord) != CTDBRET_OK)

printf("First record failed\n");

Previous Topic

Next Topic

Last record

Call ctdbLastRecord() to position the current record at the last record of a table and retrieve the record data from disk into the specified record handle’s record buffer. If the table is empty (contains no records), ctdbLastRecord() returns INOT_ERR (101).

/* get the last record of the table */

if (ctdbLastRecord(hRecord) != CTDBRET_OK)

printf("Last record failed\n");

Previous Topic

Next Topic

Next record

ctdbNextRecord() positions the current record at the next record of a table and retrieves the record data from disk into the specified record handle’s record buffer. If the current record was the last record of a table, ctdbNextRecord() returns INOT_ERR (101).

/* get the next record */

if (ctdbNextRecord(hRecord) != CTDBRET_OK)

printf("Next record failed\n");

A current record must exist before ctdbNextRecord() is called or an ICUR_ERR (100) error is returned indicating that there can be no next record if the current record does not exist. Establish a current record by calling ctdbFirstRecord(), ctdbLastRecord(), ctdbFindRecord(), or ctdbSeekRecord().

Previous Topic

Next Topic

Previous record

ctdbPrevRecord() positions the current record at the previous record of a table and retrieves the record data from disk into the specified record handle’s record buffer. If the current record was the first record of a table, ctdbPrevRecord() returns INOT_ERR (101).

/* get the previous record */

if (ctdbPrevRecord(hRecord) != CTDBRET_OK)

printf("Previous record failed\n");

A current record must exist before ctdbPrevRecord() is called or an ICUR_ERR (100) error is returned indicating that there can be no previous record if the current record does not exist. You can establish a current record by calling ctdbFirstRecord(), ctdbLastRecord(), ctdbFindRecord(), or ctdbSeekRecord().

Previous Topic

Next Topic

Seek to record

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

You can use ctdbGetRecordPos() and ctdbSeekRecord() to implement a bookmark system for your records. Retrieve the record offset with ctdbGetRecordPos(), that is the bookmark value, and later on you can quickly come back to the record by calling ctdbSeekRecord().

/* get record bookmark */

CTOFFSET GetBookMark(CTHANDLE hRecord)

{

CTOFFSET Retval;

ctdbGetRecordPos(hRecord, &Retval);

return Retval;

}

/* goto record bookmark

CTDBRET GotoBookmark(CTHANDLE hRecord, CTOFFSET bookmark)

{

return ctdbSeekRecord(hRecord, bookmark);

}

TOCIndex