Product Documentation

FairCom DB API API for C++ - Developers Guide

Previous Topic

Next Topic

Finding records

You can search for records in a table using one of the CTRecord::Find(), CTRecord::FindTarget() and CTRecord::FindRowid() methods. FairCom DB API performs the find operations against the table indexes. When an index entry is found, the record data is loaded into the record buffer.

Before you can call CTRecord::Find(), you need to prepare the data you want to find:

  1. Clear a record buffer
  2. Set the default index with the appropriate value
  3. Populate the fields that makeup the index segment
  4. Call CTRecord::Find() with the appropriate find mode

// find record which product code is DISKETTE

CTRecord ARecord(ATable);


// clear the record buffer

ARecord.Clear();


// set the default index to "MyIndex"

ARecord.SetDefaultIndex("MyIndex");


// populate the 'product' field

ARecord.SetFieldAsString("product", "DISKETTE");


// find the record

try

{

if (ARecord.Find(CTFIND_EQ))

printf("Record found\n");

else

printf("Record not found\n");

}

catch (CTException &err)

{

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

}

CTRecord::Find(), CTRecord::FindTarget() and CTRecord::FindRowid() returns YES (true) if the record was found or NO (false) if the record was not found. These methods throw an exception if an error occurs.

In This Section

Find Modes

Building a target key

Finding records by target key

Finding records by ROWID

TOCIndex