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 require an index on which to operate.

Any of the user defined indexes or the RECBYT or ROWID indexes (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 = new CTRecord(ATable);


//set the default index to "MyIndex"

try

{

ARecord.SetDefaultIndex("MyIndex");

}

catch (CTException err)

{

Console.Write("Set default index failed with error {0}\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)

{

Console.Write("Set default index failed with error {0}\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 performed using this index, until a new selection is made for 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 of the records in a table using CTRecord.First() and CTRecord.Next(), and setting the ROWID index as the default index.

TOCIndex