xHarbour Reference Documentation > Command Reference xHarbour Developers Network  

SET FILTER

Defines a condition for filtering records in the current work area.

Syntax

SET FILTER TO [<lExpression>]

Arguments

TO <lExpression>
This is logical expression used as filter condition. All records where the expression evaluates to .F. (false) are not visible in the current work area. When no argument is passed to SET FILTER, an existing filter condition is removed from the current work area.

Description

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.

Info

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

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe