The query manager was created to abstract commonly-performed life-cycle management of static and dynamic queries, and browses into a standard block of 4GL / ABL code.

This code requires use of the procedure manager, which can be found on the PEG Utilities page. It can also be run in a non-procedure-managed environment with some minor tweaking.

Question, comments, concerns, etc - please mail me at timk@tdkcs.ca.

Tim Kuehn
TDK Consulting Services Inc


This release consists of the following files:

Program Name Description
Main Code
qry-mgr.sp Main code file
qry-mgr.spi Header file (needed for calling functions)
qry-mgr-compound.sp Super Procedure code for working with compound-value conditionals (ie date & time, account year and period, etc.)
qry-mgr-compound.spi Header file for compound-value searches
Support code
qry-mgr.tt Temp table used by the query manger.
qry-mgr.i Global Defines used by the query manager
qry-mgr-compound.i Include file of standard procedure definitions used for managing compound-value searches
Test Code
qry-brkby-report-test.p Demonstrates the "break-by" functionality on the sports "customer" table. Output is to a file "e:\tmp\customer.out"
qry-brkby-test.p Demonstrates the "break-by" functionality on the sports "customer" table using a browse.
qry-mgr-test.p Demonstrates how to import a browse, set join and filter conditions, and then open a query on the "customer" and "invoice" tables of the sports db.

List of procedures / functions in qry-mgr.sp by functional grouping:

Procedure / Function Description
Query String Converstion
get-qrymgr-quoted-string Takes a string and returns it ready for use in a query string specification.
Create / Import / Delete Queries and Browses
create-qrymgr-query Create a new dynamic query with an associated set of either new buffers or previously existing buffers.
import-qrymgr-query Import an externally defined query into the manager
import-qrymgr-browse Import a browse and it's associated query, and set other values
to sane defaults
delete-qrymgr-query Delete a managed query and any associated dynamic buffers that may've been created when the query was instantiated
Associate Queries & Browses in the manager
set-qrymgr-query-browse-handle Given a query handle and browse handle, associate the browse with the query in the tt-query table.
Browse UI Control
refresh-qrymgr-browse Refresh the browse associated with a query
select-focused-row-qrymgr-browse Select the currently focused row for this browse
apply-event-to-qrymgr-browse Given a

CURSOR-UP, CURSOR-DOWN,
PAGE-UP, PAGE-DOWN

event applied to a browse, make sure when we're done the selected row's still has focus.

Return a logical to indicate where to do a RETURN NO-APPLY or not.
Query Control - Joins and Searches
set-qrymgr-query-buffer-join-spec Set the join spec for a given query buffer. This is distinct from the search spec in that it's intended to only join the current join level buffer to a prior join level buffers. For the first level buffer, it is only used to specify if this is a "FIRST", "EACH", or "LAST" record set is required.
set-qrymgr-query-buffer-search-spec Set the search spec for a given query buffer. This replaces any current specification that may be on this buffer.
add-qrymgr-query-buffer-compound-search-spec Given a two-field component search configuration, construct a query spec to do range or equality matching for that component field setup
Query Control - Range Value Searches
add-qrymgr-query-buffer-search-spec-date-range Add a date range to a query buffer spec
add-qrymgr-query-buffer-search-spec-decimal-range Add a decimal range to a query buffer spec
add-qrymgr-query-buffer-search-spec-integer-range Add a integer range to a query buffer spec
add-qrymgr-query-buffer-search-spec-character-range Add a character range to a query buffer spec
Query Control - Single Value Searches
add-qrymgr-query-buffer-search-spec-numeric Add a numeric equivalance filter to a query buffer spec from a numeric-string
add-qrymgr-query-buffer-search-spec-decimal Add a decimal filter to a query buffer spec from a boolean matching condition
add-qrymgr-query-buffer-search-spec-integer Add a integer filter to a query buffer spec from a boolean matching condition
add-qrymgr-query-buffer-search-spec-logical Add a logical filter to a query buffer spec from a boolean matching condition
add-qrymgr-query-buffer-search-spec-character Add a character search to a query buffer spec. Optionally addes a MATCH specification if "can-match" is specified in the flag list and a "match" character is specified (ie a "*" or ".") in the search string.
add-qrymgr-query-buffer-search-spec-date Add a date search to a query buffer spec
Query / Search - Open, Refresh, Reposition, and Close Control
reset-qrymgr-query-buffer-search-spec Reset the search spec for a given query / buffer combination. This is for filtering the queries based on a given buffer, and doesn't affect the table join specification for this buffer.
open-qrymgr-query Open a query with the supplied search / sort specification.

If the query handle points to a static query that isn't under management by this code, then import it first and then open it with the supplied specification
reopen-qrymgr-query Reopen a query, assuming we're going to use the last used search spec
set-qrymgr-query-position Save or recall buffer positions for a given query
move-qrymgr-query-position Move the query one direction or another in the result list, and stay within the list if the operation would've moved the query outside of the result list.

NOTE: The "prev" direction and "stay-in-list" flag option will not work with queries that are defined with forward-only = TRUE.
close-qrymgr-query Close a query that's not needed any more, if it's against a valid handle
Query Attribute Inquiry
get-qrymgr-query-spec Get the last used search specification for a given query
get-qrymgr-buffer-db-table-handle Get the handle associated with the named buffer for this query that this manager knows about and return it
get-qrymgr-buffer-order-handle Get the n'th buffer associated with this query and return it
get-qrymgr-buffer-field-set-name Get the field set name for a given buffer-field-list specification.
dump-qrymgr-query Dump information pertaining to a query
Query First/Last Break Condition Support
is-qrymgr-break-condition Determine if the desired break conditions have been met for a given query.
create-qrymgr-named-buffer-field-set Create a named field set for a given query and set of associated buffers and fields.

NOTE: If the current named field value set already exists, nothing is done
save-qrymgr-named-buffer-field-set-current-values Save the value for a set of buffer fields to a set of temp-table records for a given query and name.
check-qrymgr-named-buffer-field-set-values Given a named buffer field set, see if the corresponding table buffer field values have changed from when they were last saved.
delete-qrymgr-named-buffer-field-set Delete a named buffer field set and all associated records from a query
Table Field Values
get-qrymgr-string-value Given a search spec and table, field, array spec,

find the first or last value in a result list in the specified sort order and return it as a string
get-qrymgr-decimal-value Interface to get-qrymgr-string-value() that returns a decimal value
get-qrymgr-integer-value Interface to get-qrymgr-string-value() that returns a integer value
get-qrymgr-date-value Interface to get-qrymgr-string-value() that returns a date value

List of functions in qry-mgr-compound.sp:

Procedure / Function Description
Compound Value Queries
add-qrymgr-query-buffer-compound-search-spec-character-range Add a compound character range to a query buffer spec.
add-qrymgr-query-buffer-compound-search-spec-date-range Add a compound date range to a query buffer spec.
add-qrymgr-query-buffer-compound-search-spec-decimal-range Add a compound decimal range to a query buffer spec.
add-qrymgr-query-buffer-compound-search-spec-integer-range Add a compound integer range to a query buffer spec.
add-qrymgr-query-buffer-compound-search-spec-date-time-range Add a date/time range to a query buffer spec.
add-qrymgr-query-buffer-compound-search-spec-date-time Add a date/time search to a query buffer spec.


DISCLAIMER: The query manager code was created by TDK Consulting Services Inc. under contract to Taylor Steel Inc. and is distributed with no guarantees of functionality, or any other warrantee express or implied.