Language Reference Guide : C. Generated User Classes : Query_Control User Class
 
Share this page          
Query_Control User Class
The Query_Control user class handles all processing for the query bar and its toolbar segments. It is responsible for opening and closing the QueryObject, applying new sort and selection criteria settings, and navigating through the results.
In most cases, you need to use only three of its methods:
Setup
Links the Query_Control with the query bar and QueryObject
OpenQuery
Initiates processing
CloseQuery
Terminates processing
Methods such as NextRow or FindRow may be useful if you also want to provide menu items to browse the results of a query.
All attributes of the QueryObject are private, and can only be set through the Setup and OpenQuery methods.
Example—Query_Control user class:
This is an example of a frame script to create and initialize a QueryObject and run it using a query bar and Query_Control:
initialize() =
declare
          qo = QueryObject;    /* Create QueryObject */
          qc = Query_Control;  /* Create Query_Control */
          i = smallint not NULL;
          status = integer not NULL;
endddeclare
begin
          /*
          *  Set up QueryObject attributes that are common
          *  for all SELECTs. Fill in ColumnName and
          *  Targets[1] attributes for each column to be
          *  retrieved or updated. Supply TableName
          *  and set IsSelectTarget and IsUpdateTarget
          *  appropriately. If sorting, set the default
          *  sort order using the OrderBy and AsName
          *  attributes for the column to be used for
          *  default ordering. During execution, the
          *  Query_Control object will adjust OrderBy
          *  settings and supply a RunTimeWhere clause based
          *  on user settings in the SortBar and CriteriaBar
          *  controls.
          */
          /* Set table */
          qo.Tables[1].TableName = 'v_customer';
          /* Set columns */
          qo.Columns[1].ColumnName = 'acctno';
          qo.Columns[2].ColumnName = 'cname';
          qo.Columns[3].ColumnName = 'cacctbal';
          for i = 1 to qo.Columns.LastRow do
          /*
          *  Associate each column with its corresponding
          *  form field ('customer' is the name of the
          *  composite form field; the names of its three
          *  component fields match the column names in the
          *  database).
          */
          qo.Columns[i].Targets[1].Expression = 'customer.'
                    + qo.Columns[i].ColumnName;
          /*
          * Set other column attributes
          */
          qo.Columns[i].Targets[1].IsSelectTarget = TRUE;
          qo.Columns[i].Targets[1].IsUpdateTarget = FALSE;
          qo.Columns[i].FromTable = qo.Tables[1];
          endfor;
          qo.Scope = CurFrame.Scope;
          /*
          *  Default ordering is by acctno, so set its
          *  OrderBy and AsName attributes.
          */
          qo.Columns[1].OrderBy = 1;
          qo.Columns[1].AsName = 'acctno';
          /*  Clear all fields on the form */
          CurFrame.TopForm.SetToDefault();
          /*
          *  Initialize the Query_Control object. Call
          *  Setup to associate the Query_Control object
          *  with the QueryObject and the query bar.
          */
          status = qc.Setup(queryTarget = qo,
                    queryBar = field(queryBar));
                    if status != ER_OK then
                              message 'Error during query setup';
          resume;
          endif;
          /*
          *  Begin query processing. After the
          *  Query_Control object is opened, it handles all
          *  further processing and manages all interaction
          *  with the database.
          */
          status = qc.OpenQuery(querymode = QY_CACHE,
                    queryscope = CurFrame.Scope,
                    checkcols = TRUE);
          if status != ER_OK then
                    message 'Error opening query';
          resume;
          endif;
end
on Terminate=
          begin
                    qc.CloseQuery();
          end
Inherits From
UserObject Class
Inherited By
None
Methods
CloseQuery
FindRow
FirstRow
HandleSelect
LastRow
NextRow
OpenQuery
PrevRow
Setup