Product Documentation

FairCom ISAM for C

Previous Topic

Next Topic

ctSetAutoContext

This function can replace two calls to the server with one, reducing traffic and boosting performance.

Declaration

NINT ctSetAutoContextId(COUNT contextId);

Description

To use ctSetAutoContextId() as a replacement for ChangeISAMContext() at the ISAM level, call ctSetAutoContextId(), passing the context ID you wish to use in the next record read call. Check for a return code of NO_ERROR to indicate success. Then call your record read function. The following functions are the record read functions that support this feature:

BLKIREC, EQLVREC, EQLREC, GTEVREC, GTEREC, GTVREC, GTREC, GetLTEVRecord, LTEREC, LTVREC, LTREC

Example

FILNO datno1,datno2; /* data file numbers */

pVOID bufptr1,bufptr2; /* data buffer pointer */

COUNT contextID_1,contextID_2,contextID_3; /* context ID's */

OpenFileWithResource(datno1,"data1",ctSHARED);

OpenFileWithResource(datno2,"data2",ctSHARED);

/* move to first record for datno1 using first key */

FirstRecord(datno1 + 1,bufptr1);

/* establish first context for datno1 at first record. keyno == -1 saves all key positions. */

contextID_1 = OpenISAMContext(datno1,-1,-1);

/* move to first record for datno2 using third key. */

FirstRecord(datno2 + 3,bufptr2);

/* establish first context for datno2 at first record. keyno != -1 saves only key value for third key. */

contextID_2 = OpenISAMContext(datno2, datno2 + 3,-1);

NextRecord(datno1 + 1,bufptr1);

/* position datno1 at third record by first key. */

NextRecord(datno1 + 1,bufptr1);

/* Third record by first key becomes the saved position for contextID_1 and contextID_3 becomes the active context for datno1. */

contextID_3 = OpenISAMContext(datno1,-1,-1);

/* move from third record by first key, to the next record using the second key. Call this record 4' */

NextRecord(datno1 + 2,bufptr1);

/* Save record 4' as contextID_3. Make the 3rd record the current position for datno1, and contextID_1 becomes the active context for datno1. contextID_2 is still the active context for datno2. */

ctSetAutoContextId(contextID_1);

/* move to the 4th record by key 1 for datno1.*/

NextRecord(datno1 + 1,bufptr1);

TOCIndex