|
Makes all records in the database with that do not match the FILTER condition invisible to
If you have several open database aliases, each one can have a filter associated with it. However, a single alias can have only one filter applied to it at a time. Subsequent <MvFILTER> tags referring to that alias will replace the current filter. To remove a filter and not replace it, omit the FILTER attribute. If both NAME and FILTER are omitted, the current filter for the primary database will be removed. The variables alias.d.totrec and alias.d.recno will continue to refer to the complete, unfiltered database. Attributes
ExamplesFILTER_TYPE = "expression"If omitted, FILTER_TYPE defaults to "expression ". Since deleted records are not physically removed from the database until an <MvPACK> tag is executed, it is common practice to filter out deleted records, making them invisible to <MvFIND> and <MvSKIP>. In this example, deleted employees will not be returned when searched for with <MvFIND>. Example:<MvOPEN NAME="employees" DATABASE="{ g.path $ 'workers.dbf' INDEXES="emp_name.mvx"> <MvFILTER NAME = "employees" FILTER = "{ NOT employees.d.deleted }"> <MvFIND NAME = "employees" VALUE = "{ l.name }" EXACT> Operation:The FILTER expression is retrieved once, stored in an internal variable and re-executed for the life of the FILTER. Starting from the current record in the database, a record search is performed till the first match is found. This has performance implications in that, if the filter condition is one that will yield few or no matches, a large part of the database may end up being searched. In the example above, it may safely be assumed most records are NOT deleted and the filter will quickly find a match. If you want to find a series of records that all match a certain criterion, you have two basic options:
In this example the database contains the following records, indexed (sorted) by the value of the salary field.
The tag <MvFIND VALUE="15000"> will move the record pointer to record #2, the 'Novak' record. Apply this filter <MvFILTER FILTER="{'Washer' CIN db_alias.d.title}"> and all of the records that do not satisfy the filter condition ("Title contains 'Washer'") will become "invisible", even though they're still in the database, and in the same locations. The database now effectively looks like:
Run the same search again <MvFIND VALUE="15000"> and now the record pointer will be at the 'Maloney' record. Since the 'Novak' record does not match the filter condition, it is invisible to <MvFIND> This example uses an indexed database, but <MvFILTER> itself can be used with or without an index. Note: The variable alias.d.recno cannot be used in a filter expression. The effect on the currently applied filter of accessing a record that the filter does not apply to is undefined. FILTER_TYPE = "variable"This allows you to dynamically create a string the contains an expression and filter the results on that expression. In this example the variable l.filter_str is assigned a string that contains an expression is evaluated as an expression by FILTER attribute. The expression returns undeleted records where the first letter of the name starts with the letter 'r' or 'R'. Example:<MvASSIGN NAME = "l.filter_str" VALUE = "{ '(NOT employees.d.deleted) AND (toupper(substring(employees.d.name,1,1)) EQ \'R\')' }"> <MvFILTER NAME = "Products" FILTER = "l.filter_str" FILTER_TYPE = "variable"> In this example an user defined function creates and returns a string that is used as the expression for the filter. Example:<MvASSIGN NAME = "l.filter" VALUE = "{ Product_Filter( l.search ) }"> <MvFILTER NAME = "Products" FILTER = "l.filter" FILTER_TYPE = "variable">
|