FILEFLEX API REFERENCE



NAME
DBQuery -- Search records against query expression

SYNTAX
DBQuery(query-expression)

CATEGORY
Retrieving Information

DESCRIPTION
THIS FUNCTION HAS CHANGED IN FILEFLEX 3.0

DBQuery performs an iterative scan of records looking for a match against the query expression.

DBQuery has changed considerably since FileFlex 2.0. It no longer uses DBSkip to travel through matches. It also does not perform a DBTop to go to the head of the database. Instead, DBQuery scans from the current record using the internal active skip mechanism (meaning index order, if active) until it finds a match.

To continue a subsequent DBQuery (for the next match), you'll first need to do a DBSkip(1) to move to the next record or DBQuery will again check the current record. Any subsequent DBQuery calls with different expressions will continue from where the last left off.

This allows for refinements on an indexed search (no, you can't stack seeks), and weird, funky, iterative query scans.

DBQuery will locate a record based on the contents of one or more database fields for which you do not have an index or for which you do not wish to use the index file for some reason (e.g., you want to perform a complex query), you can use the DBQuery function.

The DBQuery function takes a single argument, which must be either a string or a container that holds a string. The string must evaluate to a logical expression (i.e., one that can be True or False). Generally, these expressions are strings that contain the name of a database field, a comparison operator (=,>,<,<>, etc.) and a value to be compared. For example, this line:

put DBQuery("sales > 50000") into dbResult

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.

You can combine search terms using logical connections (.AND., .OR., and .NOT.). For example, to find records where sales are more than $50,000 and the customer is located in Michigan, you could use a line like this:

put DBQuery("sales > 50000 .AND. state='CA'") into dbResult

The expression parser in DBQuery recognizes some new functions. These new functions are also available in relational queries and indexed searches. The new functions are:

  • CHAR(number): returns the character corresponding to the ASCII code
  • DAY(datestring): returns the day of the date function -- as in DAY(DATE())
  • LEFT(string,count): returns the left count characters of the string
  • LTRIM(string): removes blanks from the left of string
  • TRIM(string): removes blanks from the end (right side) of string)
  • ALLTRIM(string): removes blanks from beginning and end


SEE ALSO
DBSeek, DBSkip

INTERNAL FUNCTION NUMBER
35


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

Casa de Bender