FILEFLEX API REFERENCE



NAME
DBSeek -- Search for a record using an index

SYNTAX
DBSeek(seek-expression)

CATEGORY
Using Index Files

DESCRIPTION
To locate a record that matches a specific expression in the indexed field(s) of your database and retrieve that record's values, you will use the FileFlex DBSeek function. The function takes a single argument, which is the seek expression, (i.e., the value to be searched for in the indexed database file using the current index).

The DBSeek function repositions the current record pointer to the record that matches the criterion in the seek expression or the one immediately following where the record would have been found if no matching expression is located in the currently active index. You can then use the DBGetCurrRecVal function to return the values in that records fields.

You must, of course, make sure that the index file that arranges the file in order by the desired field on which you wish to search is the current index file. Use the DBSelectIndex function for this:

put DBSelectIndex(starID) into dbResult
put DBSeek("Marilyn Monroe") into dbResult

You are now ready to retrieve the desired field(s) from this record.

Once you have located a record matching your index criterion with DBSeek, you may want to locate other matching records in the file. In that case, you should use DBSkip(1) to move the current record pointer to the next matching record in indexed order.

When the indexed field on which you are performing a DBSeek operation is a character field, DBSeek may locate a record that only partly matches your search criteria. Furthermore, if it does not find a matching record, it positions the record pointer at the next record in the file AFTER where it expected to find the information for which you have instructed it to search.

You can determine which type of result DBSeek has obtained because its return value is:

  • 0 to mean an exact match was found
  • 2 to mean a partial match was found
  • 4 to mean no match was found

Where an exact match is not important, you need only check for a return value of 4. All other times, you should check for a return value other than 0 and respond accordingly.

A trick often used by FileFlex developers is to do a DBSeek on a partial match (for example, "Appl" as the seek expression to find all the possible "Apple Computer", "Apple Computer, Inc.", "Apple Pie", etc entries). Even though the DBSeek return code is other than zero, by grabbing the search field value using DBGetFieldByName and comparing, it's possible to tell if a record is a near match.


NOTES
Index files are maintained automatically by FileFlex. Whenever you execute a DBWriteRec function call, FileFlex updates all currently open index files for that database. No special programming is needed.

INTERNAL FUNCTION NUMBER
13


Copyright © 1992-1998 by David Gewirtz, under license to Component Enterprises, Inc.
Contact: info@component-net.com

Casa de Bender