c-treeDB API allows users to define record filters using ctdbFilterRecord(). When a filter is set, all records retrieved from a table are filtered against the given expression, and only records matching filter criteria are returned.
/* set filter */
if (ctdbFilterRecord(hRecord, "ZIPCODE == 12345") != CTDBRET_OK)
printf("Start filter failed\n");
Only the user who sets a filter will have their records filtered. The filter is turned off when the table is closed, or when ctdbFilterRecord() is called with a NULL or an empty string " " as the filter expression. Only one filter may be active per table per user at once, so if a new filter is set to a table with an existing filter for the specific table, the old filter will be overridden.
/* terminate filter */
if (ctdbFilterRecord(hRecord, NULL) != CTDBRET_OK)
printf("Terminate filter failed\n");
Use ctdbGetFilter() to retrieve the current filter expression. If no filters are active, ctdbGetFilter() returns NULL. Use ctdbIsFilteredRecord() to test if filters are active for a table.
When used in the client/server model, this feature has the potential to increase the performance since just the records matching the criteria will be returned, reducing the network traffic.
Record filters, when used in conjunction with sets (ctdbRecordSetOn()), provide the c-treeDB API API with simple query capabilities.