GetConditionalIndex
Get the conditional index resource from a data file.
Short Name
GETCIDX()
Type
ISAM function
Declaration
VRLEN GetConditionalIndex(FILNO keyno, LONG bufsiz, pVOID idxcnd)
Description
In V12 the file number typedef was formally changed from COUNT, a two-byte value to FILNO, a four-byte value. Refer to this link for compatibility details. Four Byte File Numbering
GetConditionalIndex() returns the length of the NULL terminated ASCII string, including the NULL byte, containing the symbolic conditional expression for index keyno. This assumes an ISAM mapping exists between keyno and a data file.
Return
If idxcnd is non-NULL and bufsiz is greater than or equal to the length returned, the string is returned to the address specified by idxcnd. If idxcnd is NULL or bufsiz is too small, the length is returned by GetConditionalIndex(), no error is raised, and no string is returned. A zero return indicates no conditional expression or an error condition returned in isam_err, as follows:
Value |
Symbolic Constant |
Explanation |
---|---|---|
0 |
NO_ERROR |
Successful retrieval of conditional index resource. |
401 |
RNON_ERR |
RESOURCES not enabled. |
614 |
HMAP_ERR |
No map to a data file exists for keyno. |
See FairCom DB Error Codes for a complete listing of valid FairCom DB error values.
Example
LONG i;
FILNO keyno;
LONG bufsiz = INPBUFSIZ;
VRLEN returnvalue;
pTEXT tempbuffer;
TEXT inpbuf[INPBUFSIZ];
printf(
"\nEdit condition for (1) Name or (2) Customer Number index: "
);
ctsfill(inpbuf,0,INPBUFSIZ); /* Select an index */
gets(inpbuf);
if (inpbuf[0] != '\0') {
sscanf(inpbuf,"%d",&i);
keyno = (FILNO) i;
printf("\n\nEnter a conditional expression, such as ");
if (keyno == 1)
printf("strncmp(LastName, \"S\", 1) == 0." );
else
printf("Customer >= 50." );
ctsfill(inpbuf, 0, INPBUFSIZ);
if ((returnvalue =
GetConditionalIndex(keyno, bufsiz, inpbuf)) == 0) {
/* Retrieve the current condition */
if (isam_err) {
printf("Error %d getting conditional expression.", isam_err);
return;
}
}
else if (returnvalue > (VRLEN) bufsiz) {
/* If buffer too small */
bufsiz = (LONG) returnvalue + 1;
/* Set a new size */
mbfree(inpbuf);
tempbuffer = (pTEXT) mballc(1, (UINT)bufsiz);
/* Allocate space */
inpbuf = (pTEXT) mballc(1, (UINT)bufsiz);
if (!tempbuffer || !inpbuf) {
printf("Error allocating space for buffers\n");
return;
}
GetConditionalIndex(keyno, bufsiz, tempbuffer);
/* Retrieve the condition */
cpybuf(inpbuf, tempbuffer, bufsiz);
mbfree(tempbuffer);
}
printf("\nThe conditional expression is %s.", inpbuf);
}
See also
UpdateConditionalIndex()