Namespace: Consultingwerk.OERA.Query
Class 
QueryString Copy to Clipboard
Parent classes:
Inherits: Progress.Lang.Object
Implements: Consultingwerk.OERA.Query.IThrowsErrorsOnInvalidSourceMapping
Inherited by: Consultingwerk.OERA.Query.DSQueryString, Consultingwerk.OERA.Query.DSQueryStringForKeyValueTable, Consultingwerk.OERA.Query.DSQueryStringProcedural

File:QueryString
Purpose:Manage query string tranformation and manipulation.
String based, need no handles or compilation.
Manages a query string with field expressions and allows a caller
to add these expressions to the correct tables in an existing query.
The main purpose is to support query transformation from a query
with field expressions against a domain table to a query expressed
against physical tables.
The mapping and transformation is optionally triggered by
passing an object that implements IQueryMap as the second parameter.
Parameters: pcQueryWhere complete query expression
pQueryMap optional IQueryMap (columnSource, defaultQuery)
Notes: This is a copied subset of ADM2's query manipulation with
additional parsing.
- The object is in a rather unfinished, unintentended and unplanned...
- ADM methods and the parsing has overlaps and is rather disjoint.
- extents... could be changed to classes, but
- Several private variables, mcQueryWhere, mcTargetQuery,
mcTargetTables serves no current purpose, except as a
safety/debug support (afraid to loose control) ...
(I will of course forget to remove this comment when they are
removed, so it may not be true ..)
- The passed pcQueryWhere goes through a rather crude form of parsing
that may fail with too complex queries ...
There is still an attempt to handle anything by just giving up and
treat complex expressions as a single expression while the
transformation continues.. . If it fails with expressions on
functions with parenthesis try to add a parenthesis around
functions that also have parenthesis (no promise..) or fix the code.
- The passed query is expected to be a working (compilable) dynamic
temp-table query with no database options like locking. Outer
joins would not make sense in this context either.
- It is crucial that all values are quoted to be correctly parsed,
(also needed to handle non american numeric and date formats,
assuming same session format settings here as when applied)
- The transformation can split the expressions on different tables
if they are using an AND operator. An expression against multiple
tables with an OR operator between them will be added to the query
entry of the last of the tables.
- Allthough some of the code is based on the ADM, it is still meant
as sample of query manipulation.
There are alternatives to full parsing.
The query syntax is after all is a subset of the ABL programming
language. Maybe reconsider the design to see if some of the
complexity could be better encapsulated in the data access or data
source object. Even if this logic expects the query to be in
compilable form it is not really necessary at this stage, so tokens
and special patterns could be used to ease the
transformation/mapping.



Top Method Summary
Options Name Purpose
+ AddQueryWhere (character, character, character) Inserts a new expression to query's prepare string for a specified buffer.
- CHARACTER BufferWhereClause (character, character) Returns the complete query where clause for a specified buffer INCLUDING leading and trailing blanks. EXCLUDING commas and period.
+ CHARACTER BuildQueryString (handle) Builds the QueryString for the Query
- LOGICAL CanAddRefTables (character, integer, character) Evaluates if pcRefTables can be added to piTableLevel entry in a pcTables ordered query
+ CHARACTER CheckIndex (handle) Returns the Index information of the query used for a buffer
# ClearQuery () Clears the internal state to allow parsing another query string
# CHARACTER EscapeKnownFunction (character) Escapes the brackets around known ABL functions in the query string
- CHARACTER GetEvaluation (integer)
- CHARACTER GetEvaluationTables (integer, character)
- CHARACTER GetTableEvaluation (integer, integer, character) Performs the Query evaluation for a table
- CHARACTER InsertExpression (character, character, character) Inserts an expression into ONE buffer's where-clause.
- CHARACTER InsertString (character, character, integer, integer) Workaround for temporary core bug
+ LOGICAL InsertToQuery (handle) Insert the QueryString into the query
- CHARACTER NewQuerySort (character, character) /*------------------------------------------------------------------------------ Purpose : Insert sort criteria (BY phrase) in a QueryString. Notes: @param pcQuery Query String to add sort to (current sort will be replaced) @param pcSort New sort expression @return The new query string ------------------------------------------------------------------------------*/
# ParseQuery (character) Parses the logical buffer's target query and stores it for transformation to the datasource query.
# ParseSortExpression (character) Parses the Sort Expression
- CHARACTER ResolveColumn (character, integer)
- CHARACTER SortExpression (character) Returns the sort expression of the passed querystring
- CHARACTER TableEvaluation (integer, character) Performs the Query evaluation for a table
- CHARACTER WhereClauseBuffer (character) Returns the buffername of a where clause expression. This function avoids problems with leading or double blanks in where clauses.

Top Constructor Summary
Options Name Purpose
+ QueryString (character, IQueryMap) Constructor of the QueryString class

Top Property Summary
Options Name Purpose
+ LOGICAL FilterUsingInnerJoin Instructs the Query-Builder in method BuildQueryString to remove an eventually present OUTER-JOIN keyword from the source default query when filtering on a ceratin table.
+ LOGICAL ThrowErrorsOnInvalidSourceMapping Get and sets if this class throws an error when the client query string contains columns that are not mapped to a data source column


Method Detail
Top

PUBLIC AddQueryWhere (character, character, character)

Purpose: Inserts a new expression to query's prepare string for a
specified buffer.
Notes:

Parameters:
pcBuffer CHARACTER
The name of the Buffer
pcExpression CHARACTER
The new expression
pcAndOr CHARACTER
Specifies what operator is used to add the new expression to existing expression(s), AND (default) / OR
Top

PRIVATE CHARACTER BufferWhereClause (character, character)

Purpose: Returns the complete query where clause for a specified buffer
INCLUDING leading and trailing blanks.
EXCLUDING commas and period.
Notes: This is supported as a 'utility function' that doesn't use any
properties.

Parameters:
pcBuffer CHARACTER
The Buffer name
pcWhere CHARACTER
A complete query:prepare-string or ? to use the current query
Returns CHARACTER
The expression when found, '' if nothing is found.
Top

PUBLIC CHARACTER BuildQueryString (handle)

Purpose: Builds the QueryString for the Query
Notes:

Parameters:
phQuery HANDLE
The HANDLE of the QUERY widget
Returns CHARACTER
The Query String
Top

PRIVATE LOGICAL CanAddRefTables (character, integer, character)

Purpose: Evaluates if pcRefTables can be added to piTableLevel entry in a
pcTables ordered query
Notes:

Parameters:
pcRefTables CHARACTER
The references tables
piTableLevel INTEGER
The current table level
pcTables CHARACTER
The tables to be added
Returns LOGICAL
Logical value indicating if pcRefTables can be added to piTableLevel entry in a pcTables ordered query
Top

PUBLIC CHARACTER CheckIndex (handle)

Purpose: Returns the Index information of the query used for a buffer
Notes: For debugging/logging purposes only

Parameters:
phBuffer HANDLE
The handle to the buffer to return index information for
Returns CHARACTER
The index information of the query used for the buffer handle
Top

PROTECTED ClearQuery ()

Purpose: Clears the internal state to allow parsing another query string
Notes:

Top

PROTECTED CHARACTER EscapeKnownFunction (character)

Purpose: Escapes the brackets around known ABL functions in the query string
Notes: SCL-1201, workaround for parsing issues with RECID() or ROWID()
function used in the query string

Parameters:
pcQueryString CHARACTER
The Query String to escape
Returns CHARACTER
The query string with the escaped brackets
Top

PRIVATE CHARACTER GetEvaluation (integer)

Purpose:
Notes:

Parameters:
piEval INTEGER
piEval
Returns CHARACTER
The return value
Top

PRIVATE CHARACTER GetEvaluationTables (integer, character)

Purpose:
Notes:

Parameters:
piEval INTEGER
piEval
pcTables CHARACTER
pcTables
Returns CHARACTER
The return value
Top

PRIVATE CHARACTER GetTableEvaluation (integer, integer, character)

Purpose: Performs the Query evaluation for a table
Notes:

Parameters:
piEval INTEGER
piTableEntry INTEGER
The entry of the table
pcTables CHARACTER
The list of tables to evaluate
Returns CHARACTER
The evaluated query string
Top

PRIVATE CHARACTER InsertExpression (character, character, character)

Purpose: Inserts an expression into ONE buffer's where-clause.
Notes: - The new expression is embedded in parenthesis and a parentheses
is also placed around the existing one, which is different.
than the original ADM's version which is just appended
This would be problematic in adm, as it would be to many
parenthesises.
(could be improved to check for any OR and avoid parenthesis if not
found )
- Lock keywords must be unabbreviated or without -lock (i.e. SHARE
or EXCLUSIVE.)
- Any keyword in comments may cause problems.

Parameters:
pcWhere CHARACTER
Complete where clause with or without the FOR keyword, but without any comma before or after.
pcExpression CHARACTER
New expression OR OF phrase (Existing OF phrase is replaced)
pcAndOr CHARACTER
Specifies what operator is used to add the new expression to existing ones. AND (default)/OR
Returns CHARACTER
The new query string
Top

PRIVATE CHARACTER InsertString (character, character, integer, integer)

Purpose: Workaround for temporary core bug
Notes:

Parameters:
pcString CHARACTER
The String to insert
pcTargetString CHARACTER
The String to instert into
piPos INTEGER
The position to instert
piLength INTEGER
The length of the original string
Returns CHARACTER
The resulting string
Top

PUBLIC LOGICAL InsertToQuery (handle)

Purpose: Insert the QueryString into the query
Notes: Actually performs QUERY-PREPARE on the Query-Handle

Parameters:
phQuery HANDLE
The HANDLE of the QUERY widget
Returns LOGICAL
True if successful
Top

PRIVATE CHARACTER NewQuerySort (character, character)

Purpose : Insert sort criteria (BY phrase) in a QueryString.
Notes:

Parameters:
pcQuery CHARACTER
Query String to add sort to (current sort will be replaced)
pcSort CHARACTER
New sort expression
Returns CHARACTER
The new query string
Top

PROTECTED ParseQuery (character)

Purpose: Parses the logical buffer's target query and stores it for
transformation to the datasource query.
Notes: See main comments

Parameters:
pcQuery CHARACTER
The QueryString to parse
Top

PROTECTED ParseSortExpression (character)

Purpose: Parses the Sort Expression
Notes:

Parameters:
pcSort CHARACTER
The sort expression to parse
Top

PRIVATE CHARACTER ResolveColumn (character, integer)

Purpose:
Notes:

Parameters:
pcColumn CHARACTER
pcColumn
piExp INTEGER
piExp
Returns CHARACTER
Return value
Top

PRIVATE CHARACTER SortExpression (character)

Purpose: Returns the sort expression of the passed querystring
Notes: Includes the first BY also (getQuerySort does not) and
removes extra spaces.

Parameters:
pcQueryString CHARACTER
The complete QueryString
Returns CHARACTER
The sort expression of the QueryString including the first BY
Top

PRIVATE CHARACTER TableEvaluation (integer, character)

Purpose: Performs the Query evaluation for a table
Notes:

Parameters:
piTableEntry INTEGER
The entry of the table
pcTables CHARACTER
The list of tables to evaluate
Returns CHARACTER
The evaluated query string
Top

PRIVATE CHARACTER WhereClauseBuffer (character)

Purpose: Returns the buffername of a where clause expression.
This function avoids problems with leading or double blanks in
where clauses.
Notes:

Parameters:
pcWhere CHARACTER
Complete where clause for ONE table with or without the FOR keyword. The buffername must be the second token in the where clause as in "EACH order OF Customer" or if "FOR" is specified, the third token as in "FOR EACH order".
Returns CHARACTER
The name of the buffer of the where clause expression


Constructor Detail
Top

PUBLIC QueryString (character, IQueryMap)

Purpose: Constructor of the QueryString class
Notes:

Parameters:
pcQueryWhere CHARACTER
The query string to parse
poQueryMap Consultingwerk.OERA.Query.IQueryMap
The reference to the IQueryMap instance that provides call backs for the query manipulation


Property Detail
Top

PUBLIC LOGICAL FilterUsingInnerJoin

Purpose: Instructs the Query-Builder in method BuildQueryString to remove
an eventually present OUTER-JOIN keyword from the source default
query when filtering on a ceratin table.
Notes: This allows to filter Customers by SalesRep fields in a Query:
FOR EACH Customer, FIRST SalesRep OF Customer OUTER-JOIN
See Bug 2609 for a detailled discussion on the new functionality

Returns LOGICAL
Top

PUBLIC LOGICAL ThrowErrorsOnInvalidSourceMapping

Purpose: Get and sets if this class throws an error when the client query
string contains columns that are not mapped to a data source column
Notes:

Returns LOGICAL


©2006-2016 Consultingwerk Ltd.         info@consultingwerk.de         http://www.consultingwerk.de       26.08.2016 08:30:23