Defines a query that is created at compile time for use in one or more procedures, or within a single class or class hierarchy. A query can be opened with an OPEN QUERY statement, and records can be retrieved using a GET statement, BROWSE widget, or the FILL( ) method on a ProDataSet object handle.
DEFINE NEW SHARED PRIVATE PROTECTED STATICQUERY queryFOR buffer-name field-list , buffer-name field-listCACHE nSCROLLINGRCODE-INFORMATIONNEW SHARED QUERY queryDefines and identifies a query to be shared with one or more procedures called directly or indirectly by the current procedure. The called procedures must define the same query name as SHARED. For shared queries, each buffer-name must be the name of a shared buffer. The shared buffers must be specified in the same order both across shared queries and in the OPEN QUERY.SHARED QUERY queryDefines and identifies a query that was initially defined by another procedure as NEW SHARED. For shared queries, each buffer-name must be the name of a shared buffer. The shared buffers must be specified in the same order across shared queries and in the OPEN QUERY.queryPRIVATE PROTECTED STATIC QUERYDefines and identifies a query as a data member of a class, and optionally specifies an access mode (PRIVATE or PROTECTED) and scope (instance or STATIC) for that data member. You cannot specify these options when defining a query as a data element of a method (including constructors, destructors, and property accessors) or a procedure. For a data member query, each buffer-name must be the name of a compatible data member buffer (see the FOR option).
Note: The specified options are applicable only when defining a data member for a class in a class definition (.cls) file. Note also that you cannot shadow (override) the definition of a given query data member in a class hierarchy.For more information on accessing queries of different access modes and scopes, see the reference entry for Class-based data member access.For more information on where and how to define data members in a class, see the CLASS statement reference entry.QUERY querySpecifies the buffers to be used by the query, where buffer-name is a table or alternate buffer name. For a shared query, each buffer-name must be a shared buffer. If the query is a data member of a class, you must specify the name of a compatible buffer. Thus, if the query is a static data member, the buffer must also be a static data member; if the query is PROTECTED, the buffer must also be defined as PROTECTED or inherited from a super class; and if the data-source is PRIVATE, the buffer can be defined as either PRIVATE or PROTECTED. If the query is a PRIVATE instance data member, you can also specify a default database table buffer; you cannot specify a default database buffer for a query data member defined with any other combination of access mode and scope.The field-list is an optional list of fields to include or exclude when you open the query. This is the syntax for field-list:
FIELDS ( field )EXCEPT ( field )
The FIELDS option specifies the fields you want to include in the query, and the EXCEPT option specifies the fields that you want to exclude from the query. The field parameter is the name of a single field in the table specified by buffer-name. If field is an array reference, the whole array is retrieved even if only one element is specified.
Note: Field lists should be used with caution because they can cause unexpected run-time errors. It is possible, for example, that you may have eliminated a field that is required by a new or revised subroutine or trigger. The result can be a run-time error that may be difficult to debug.
You can use the -rereadfields startup option if you have unexpected run-time errors resulting from field lists. When an error occurs, the -rereadfields startup option causes the AVM to ignore the field list and to fetch the entire record.
Also note that he AVM ignores the FIELDS option for temp-tables.This statement defines a query to retrieve only the name and balance fields from the Customer table:
DEFINE QUERY custq FOR Customer FIELDS (name balance).
DEFINE QUERY custq FOR Customer EXCEPT (name balance).
Retrieves complete records for DataServers that do not support SHARE-LOCK. For more information, see the OpenEdge DataServer Guides (OpenEdge Data Management: DataServer for Microsoft SQL Server, OpenEdge Data Management: DataServer for ODBC, and OpenEdge Data Management: DataServer for Oracle).CACHE nThe SCROLLING option can improve NETWORK performance because query NO-LOCK records can be prefetched with multiple records per network message. (Note that in a join only the lowest level records for a given set of upper level records, can be prefetched). The -defaultscrolling startup parameter has the same effect. See OpenEdge Deployment: Startup Command and Parameter Reference for more information.The following example defines two queries, q-salesrep and q-cust. The first is opened in the main procedure block and is used to find all SalesRep records. The q-cust query is used to find all Customers associated with a SalesRep. The results of the q-cust query are displayed in a browse widget. The q-cust query is reopened each time you find a new SalesRep.
You cannot define a SHARED or NEW SHARED query in a class definition (.cls) file. If you do, ABL generates a compilation error.
A query can be compile-time defined (often referred to as a static query object), where the query is defined and created at compile time using this statement, or it can be run-time defined (often referred to as a dynamic query object), where the query is defined and created at run time using the CREATE QUERY statement and query object handle operations. A compile-time defined query can also be defined as a static data member of a class. In this case, it is a static query object that is also a class static data member.
Specifying a field list (field-list) for buffer-name can increase the performance of remote (network) queries substantially over specifying buffer-name alone.You can use the -rereadfields startup option if you have unexpected run-time errors resulting from field lists. When an error occurs, the -rereadfields startup option causes the AVM to ignore the field list and to fetch the entire record.
You can specify the Field List Disable (-fldisable) startup parameter to cancel field list retrieval and force the AVM to retrieve complete records. This is a run-time client session parameter that is especially useful for deployed applications whose database triggers are later redefined to reference unfetched fields (raising the ERROR condition). Using -fldisable provides a workaround that allows the application to run (although more slowly) until the application can be fixed.
© 2013 Progress Software Corporation and/or its subsidiaries or affiliates. |