Product Documentation

FairCom DB API for C

Previous Topic

Next Topic

Finding records

You can search for records in a table using one of the ctdbFindRecord(), ctdbFindTarget() and ctdbFindRowid() functions. FairCom DB API performs the find operations against the table indexes, when an index entry is found, the record data is loaded from disk into the record handle's record buffer.

Before you can call ctdbFindRecord(), 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 make up the index segment.
  4. Call ctdbFindRecord() with the appropriate find mode.

/* find record which product code is DISKETTE */

CTHANDLE hRecord = ctdbAllocRecord(hTable);


/* clear the record buffer */

ctdbClearRecord(hRecord);


/* set the default index to index 0 */

ctdbSetDefaultIndex(hRecord, 0);


/* populate the 'product' field (field 1)*/

ctdbSetFieldAsString(hRecord, 1, "DISKETTE");


/* find the record */

if (ctdbFindRecord(hRecord, CTFIND_EQ) != CTDBRET_OK)

printf("Record not found\n");

ctdbFindRecord(), ctdbFindTarget() and ctdbFindRowid() return CTDBRET_OK if a record is found or INOT_ERR (101) if no record is found. Any other return value indicates an error condition.

TOCIndex