Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic

The default index

Some record operations require an index to be specified, including record navigation, finding records, and record sets. The default index property is used by the record functions that require an index. Any user defined index, RECBYT, or ROWID may be used as the index controlling the search. Use ctdbSetDefaultIndex() or ctdbSetDefaultIndexByName() to set the default index for a record handle.

/* set the default index to "MyIndex" */

if (ctdbSetDefaultIndexByName(hRecord, "MyIndex") != CTDBRET_OK)

printf("Set default index failed\n");

Use ctdbGetDefaultIndex ()to retrieve the current index or ctdbGetDefaultIndexName() to retrieve the name of the current default index.

/* make sure the default index is set to "MyIndex" */

if (strcmp(ctdbGetDefaultIndexName(hRecord), "MyIndex") != 0)

if (ctdbSetDefaultIndexByName(hRecord, "MyIndex") != CTDBRET_OK)

printf("Set default index failed\n");

The default index is set initially to the first user defined index. Once an index is chosen as the default index, all subsequent searches will be done using this index until a new default index is selected. The default index dictates the order in which records are retrieved by using ctdbFirstRecord(), ctdbLastRecord(), ctdbNextRecord(), and ctdbPrevRecord().

Perform a chronological search in the records in a table using ctdbFirstRecord() and ctdbNextRecord(), given the ROWID index as the default index:

ctdbSetDefaultIndex(hRecord, CTDB_ROWID_IDXNO);

Previous Topic

Next Topic

Selecting the RECBYT index

The RECBYT index can be selected as the default index in order to perform record navigation with ctdbFirstRecord(), ctdbNextRecord(), ctdbPrevRecord(), and ctdbLastRecord(), ordered by the record offset. Pass the index value of CTDB_RECBYT_IDXNO to ctdbSetDefaultIndex() to default to the RECBYT index.

/* set the RECBYT index as the default index */

if (ctdbSetDefaultIndex(hRecord, CTDB_RECBYT_IDXNO) != CTDBRET_OK)

printf("Set RECBYT as default index failed\n");

Previous Topic

Next Topic

Selecting the ROWID index

The ROWID index can be selected as the default index in order to perform record navigation with ctdbFirstRecord(), ctdbNextRecord(), ctdbPrevRecord(), and ctdbLastRecord(), ordered by the ROWID value of each record. Pass the index value of CTDB_ROWID_IDXNO to ctdbSetDefaultIndex() to default to the ROWID index.

/* set the ROWID index as the default index */

if (ctdbSetDefaultIndex(hRecord, CTDB_ROWID_IDXNO) != CTDBRET_OK)

printf("Set ROWID as default index failed\n");

TOCIndex