Searching a Database in Order

FileFlex 3 has added many new searching options since FileFlex 2. Among the changes are a rather radical "re-purposing" of the DBQuery command. Much of what you'd use DBQuery for in past versions, you'd now use indexing and relational queries.

The DBQuery Function

DBQuery now exists to refine or iterate through an existing found set or sort order and perform evaluations.

The DBQuery function allows you to set up complex queries (i.e., this is greater than that and that is less than this). The power in DBQuery is that it allows you to very tightly narrow in on what you're looking for. DBQuery operates by iteratively scanning the entire sort order (physical, indexed, or related), which means that it takes much longer to find something that's near the end of the database file than something that's near the beginning. In general, you should use DBQuery when your sort order size is relatively small. For much larger databases, consider turning to indexed searches and accelerated relational queries.

The DBQuery function requires a single argument, which is a search expression string enclosed in quotation marks. This string must evaluate to a logical expression (i.e., interpreting it must lead to a "TRUE" or "FALSE" conclusion). For example, this line:

DBQuery("SALES > 50000")

will set up a search condition which tells FileFlex that you only want to see records where the value in the database field called "SALES" exceeds $50,000. The DBQuery function will move you to the first matching record, assuming one exists.

Finding the Next Match

Once you've executed DBQuery and wish to find the next match, you should not expect DBSkip to work for you (as it did in previous versions). Each DBQuery begins at the current record and keeps searching. This allows you to find something and iteratively change your search as you traverse records, but it requires you to keep track of your search yourself.

If you want to find the next identical match, do a DBSkip to move to the next record, then another complete DBQuery.

Discuss this chapter on the FileFlex Boards.

Copyright © 1992-1998 by David Gewirtz, under license to Component Enterprises, Inc.

Casa de Bender