QUERY-PREPARE( ) method
- Last Updated: February 11, 2026
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
Compiles a predicate (query condition).
Return type: LOGICAL
Applies to: Query object handle
Syntax
|
- predicate-expression
- A CHARACTER expression that evaluates to an
OPEN QUERY ... FOR EACHstatement without theOPEN QUERY .... You can also use a field phrase.
The QUERY-PREPARE method corresponds to the OPEN
QUERY statement's compilation phase. To open the query object, use the
QUERY-OPEN method.
If the QUERY-PREPARE method encounters an error, it
returns FALSE and generates an error message, but does not raise ERROR. If you use the
QUERY-PREPARE method in a statement that uses the
NO-ERROR option and an error occurs, the QUERY-PREPARE
method returns FALSE and diverts the error to the ERROR-STATUS system handle. In either instance,
ERROR-STATUS:ERROR returns FALSE. You can get information on the error
through the GET-MESSAGE method of the ERROR-STATUS system
handle, as usual.
Examples
|
|
|
Notes
- The
QUERY-PREPAREmethod is compatible with indexed reposition of queries with joins. In predicate-expression, just include theINDEXED-REPOSITIONoption. For more information on theINDEXED-REPOSITIONoption, see the reference entry for the OPEN QUERY statement. - Unless explicitly specified otherwise in the predicate-expression, the default record lock type for the
QUERY-PREPAREmethod isNO-LOCK. - Like the
FORstatement, theQUERY-PREPAREmethod predicate-expression supports theBREAKandBYoptions for sorting and accumulating data by break groups.
To test whether a break group has changed, you can use the FIRST-OF( ) method and LAST-OF( ) method of the query object handle.hQuery:QUERY-PREPARE("FOR EACH Customer WHERE Customer.CustNum > 50 BREAK BY Customer.SalesRep BY Customer.Country"). - The
QUOTERfunction can be used to wrap character values with internal quotes, as in this example:hQuery:QUERY-PREPARE("FOR EACH Customer WHERE Customer.Name = " + QUOTER(my-name)). - The
NAMEattribute of the Temp-table object handle is writeable for dynamic and AVM-generated temp-tables. You might need to update a predicate-expression that references a renamed temp-table with new strings using the new table name. - The DYNAMIC-FUNCTION function can be used inside the predicate-expression, as in this example:
hquery:QUERY-PREPARE("FOR EACH tt WHERE ~ DYNAMIC-FUNCTION( 'GetLogical', " + cExpression + ") = TRUE"). - If the predicate-expression contains special characters,
QUERY-PREPAREmay fail with an error,"Could not tokenize PREPARE string…".For example, the left curly brace ({) is a special character used in source code as an argument reference, an include file reference, or a preprocessor name reference, and has special meaning to the compiler. To avoid the error, special characters in the predicate-expression must be escaped with a tilde (~). DuringQUERY-PREPARE, the string is compiled twice, once when the r-code is written and once at runtime. Therefore, it may be necessary to escape special characters multiple times. - The
QUERY-PREPARE()method cannot be used together with other assignments in a singleASSIGNstatement.