Product Documentation

c-treeDB API for C++ - Developers Guide

Previous Topic

Next Topic

The default index

Some of the record operations such as record navigation, finding records and record sets require an index to be specified. The default index property is used by the record functions that required an index to operate on.

Any of the user defined indexes, or RECBYT, or ROWID, in the case these are created, may be used as the index controlling the search. To set the default index use one of the overloaded CTRecord::SetDefaultIndex() methods. You can use the index number of the index name to identify the default index.

// create a new record object

CTRecord ARecord(ATable);

//set the default index to "MyIndex"

try

{

ARecord.SetDefaultIndex("MyIndex");

}

catch (CTException &err)

{

printf("Set default index failed with error %d\n", err.GetErrorCode());

}

Use CTRecord::GetDefaultIndex() to retrieve the current index number or CTRecord::GetDefaultIndexName() to retrieve the name of the current default index.

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

try

{

if (ARecord.GetDefaultIndexName() != "MyIndex")

{

ARecord.SetDefaultIndex("MyIndex");

}

}

catch (CTException &err)

{

printf("Set default index failed with error %d\n", err.GetErrorCode());

}

If no index is set as the default index before the first search, the default index is the first user-defined index. Once an index is chosen as the default index, all subsequent searches will be done using this index, up to a new selection in the default index. For instance: the user may set the default index as the ROWID index, search for the first input record, then change the default index to the user defined index (i_name, for instance, an index over the name field in the table), and search for the next record on this particular sequence, taking as the previous record the first input record.

A user may perform a chronological search in the records in a table using CTRecord::First() and CTRecord::Next(), and setting the ROWID index as the default index:

In This Section

Selecting the RECBYT index

Selecting the ROWID index

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 CTRecord::First(), CTRecord::Last(), CTRecord::Next() and CTRecord::Prev(), ordered by the record offset. The RECBYT index can be selected as the default index by passing the index value of CTDB_RECBYT_IDXNO to CTRecord::SetDefaultIndex() method.

// set the RECBYT index as the default index

try

{

ARecord.SetDefaultIndex(CTDB_RECBYT_IDXNO);

}

catch (CTException &err)

{

printf("Set default index failed with error %d\n", err.GetErrorCode());

}

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 CTRecord::First(), CTRecord::Last(), CTRecord::Next() and CTRecord::Prev(), ordered by the ROWID value of each record. The ROWID index can be selected as the default index by passing the index value of CTDB_ROWID_IDXNO to CTRecord::SetDefaultIndex() method.

// set the ROWID index as the default index

try

{

ARecord.SetDefaultIndex(CTDB_ROWID_IDXNO);

}

catch (CTException &err)

{

printf("Set default index failed with error %d\n", err.GetErrorCode());

}

TOCIndex