SETFLTRN
Sets a filter having the specified filter number. Multiple filters allows advanced data filtering capability.
Type
Low-Level function
Declaration
COUNT SETFLTRN(FILNO datno, UCOUNT fltnum, UCOUNT fltopts, pTEXT expression);
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
The function prototype for SETFLTRN() is very similar to SetDataFilter(). SETFLTRN() includes two additional parameters:
The filter number determines the order in which a filter is evaluated: filters are evaluated in ascending order by filter number. Two filters cannot have the same filter number. A call to SETFLTRN() for filter number N replaces an existing filter that has that filter number.
A call to SETFLTRN() may specify a filter number in the range 0 through 16383. The upper two bits of the filter number value are reserved for internal use. A call to SETFLTRN() with a filter number larger than 16383 fails with error PBAD_ERR (749, bad parameter value).
Currently the only supported filter option is ctDATFLT_OPTION_CURCTX, which indicates that the data filter applies only to the ISAM context in which it was created. When this filter option is not specified (that is, if the caller specifies zero for fltops), the filter applies to all ISAM contexts, and is how the current SetDataFilter() function behaves.
c-treeDB layers use SETFLTRN() with the ctDATFLT_OPTION_CURCTX option for data filters as c-treeDB expects a data filter to apply only to a particular context.
Return
Value |
Symbolic Constant |
Explanation |
---|---|---|
0 |
NO_ERROR |
Successful segment configuration. |
116 |
IMOD_ERR |
RESETFLTR() called but server version does not support numbered filters. |
454 |
NSUP_ERR |
Not supported with your server version. |
749 |
PBAD_ERR |
Bad parameter value |
See c-tree Error Codes for a complete listing of valid c-tree error values.
Example
rc = NXTVREC(CUSTDAT, recbuf, &reclen);
if (rc != INOT_ERR) {
ctrt_printf("Error: Failed to read record: %d\n", rc);
goto err_ret;
}
/* Set filter to read record 'b' only. */
if ((rc = SETFLTRN(CUSTDAT, 1, 0, "!strncmp(ZipCode, \"b\", 1)"))) {
ctrt_printf("Error: Failed to set data filter: %d\n", rc);
goto err_ret;
}
/* Read the record. */
reclen = bufsiz;
if ((rc = FRSVREC(CUSTDAT, recbuf, &reclen))) {
ctrt_printf("Error: Failed to read record: %d\n", rc);
goto err_ret;
}
if (recbuf[4] != 'b') {
ctrt_printf("Error: First record value (%c) does not match expected value (b)\n",
recbuf[4]);
rc = 1;
goto err_ret;
}
rc = NXTVREC(CUSTDAT, recbuf, &reclen);
if (rc != INOT_ERR) {
ctrt_printf("Error: Failed to read record: %d\n", rc);
goto err_ret;
}
ctrt_printf("Successfully read record b with filter.\n");
/* Set filter to read record 'a' only. */
if ((rc = SETFLTRN(CUSTDAT, 1, 0, "!strncmp(ZipCode, \"a\", 1)"))) {
ctrt_printf("Error: Failed to set data filter: %d\n", rc);
goto err_ret;
}
/* Read the record. */
reclen = bufsiz;
if ((rc = FRSVREC(CUSTDAT, recbuf, &reclen))) {
ctrt_printf("Error: Failed to read record: %d\n", rc);
goto err_ret;
}
if (recbuf[4] != 'a') {
ctrt_printf("Error: First record value (%c) does not match expected value (a)\n",
recbuf[4]);
rc = 1;
goto err_ret;
}
rc = NXTVREC(CUSTDAT, recbuf, &reclen);
if (rc != INOT_ERR) {
ctrt_printf("Error: Failed to read record: %d\n", rc);
goto err_ret;
}
rc = NO_ERROR;
ctrt_printf("Successfully read record a with filter.\n");
/* Set filter to read record 'a' and 'b' only. */
if ((rc = SETFLTRN(CUSTDAT, 2, 0, "!strncmp(ZipCode, \"b\", 1)"))) {
ctrt_printf("Error: Failed to set data filter: %d\n", rc);
goto err_ret;
}
/* Read the record. */
reclen = bufsiz;
rc = FRSVREC(CUSTDAT, recbuf, &reclen);
if (rc != INOT_ERR) {
ctrt_printf("Error: Expected record read to fail with INOT_ERR but return code is : %d\n",
rc);
if (!rc)
rc = 1;
goto err_ret;
}
See also