To permit an application to maintain more than one current ISAM position in a single instance of an open file, the following three routines are used: OpenISAMContext(), ChangeISAMContext(), and CloseISAMContext().
These functions make it possible to save multiple positions in the same file. For example, it is possible to do the following with an index defined over city name:
The following code demonstrates these concepts.
Note: FairCom DB has an internal hard limit of 65534 contexts.
Multiple ISAM Context Example
#define namebuf 32
struct { /* data record format */
TEXT name[namebuf]; /* customer name */
LONG num; /* customer number */
} parentimage;
FILNO datno, keyno;
COUNT contextID1, contextID2;
TEXT target[namebuf];
if ((contextID1=OpenISAMContext(datno,keyno,-1)) == -1)
printf("\n\tOpenISAMContext1 error - %d", isam_err);
memset(target,' ',namebuf);
cpybuf(target,"Columbia",strlen("Columbia"));
if (error =
GetRecord(keyno,TransformKey(keyno,target),&parentimage))
printf("\n\tGetRecord error - isam_err = %d",isam_err);
if ((contextID2=OpenISAMContext(datno,keyno,-1))==-1 )
printf("\n\tOpenISAMContext2 error - %d",isam_err);
memset(target,' ',namebuf);
cpybuf(target,"Denver",strlen("Denver"));
if (error =
GetRecord(keyno,TransformKey(keyno,target),&parentimage))
printf("\n\tGetRecord error - isam_err = %d",isam_err);
if (ChangeISAMContext(contextID1))
printf("\n\tError on CHGICON 1 = %d",isam_err);
if (!(error=NextRecord(keyno,&parentimage)))
printf("\n\tSuccessful NXTREC for context1-city name: %s.",
parentimage.name);
These routines permit a similar form of control as the multiple SET and BATCH routines, with the following essential differences: