xHarbour Reference Documentation > Command Reference |
Defines a condition for filtering records in the current work area.
SET FILTER TO [<lExpression>]
The SET FILTER command defines a logical expression for the current work area. The expression is evaluated for each record during relative database navigation with SKIP, GO TOP or GO BOTTOM. All records where the filter expression evaluates to .F. (false) are ignored and the record pointer is advanced until the expression yields .T. (true) or the end of file is reached.
As a result, all records where <lExpression> yields .F. (false) are logically filtered and not visible during relative database navigation. Absolute navigation with GOTO <nRecordNumber>, however, allows for positioning the record pointer to a record where <lExpression> yields .F. (false).
To activate a filter after SET FILTER is issued, the record pointer must be moved relatively. This is usually achieved with GO TOP.
Optimization: when database navigation appears to be slow with a filter condition, try to create an index with an expression that matches the filter and SET OPTIMIZE to ON.
Index: The SET FILTER condition has no effect on index creation with INDEX or REINDEX.
See also: | DbClearFilter(), DbFilter(), DbSetFilter(), SET DELETED, SET OPTIMIZE, SET SCOPE |
Category: | Database commands , SET commands |
Source: | rdd\dbcmd.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example demonstrates the effect of a filter condition PROCEDURE Main USE Customer INDEX ON Upper(LastName) TO Cust01 GO TOP ? Recno(), Lastname // result: 28 Abbey SET FILTER TO Upper(LastName) > "L" GO TOP ? Recno(), Lastname // result: 182 MacDonald CLOSE Customer RETURN
http://www.xHarbour.com