Namespace: OpenEdge.DataAdmin.Lang
Class
QueryString
Parent classes:
Inherits: Progress.Lang.Object

CLASS QueryString HD
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 BaseQuery are important for transformation, but can also
be used provide table options to the main query when used with no tranformation.
(and workaround the lack of full query parsing)
- The passed pcQueryWhere could 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.




Method Summary
Options Name Purpose
AddExpression (character)
AddFilter (character, character, character) /* we just add it to the 1st table - the table position is resolved in all methods that returns the query */
AddFilter (log[], character[], character[], character[])
CHARACTER BufferWhereClause (character, character, integer) Returns the complete query where clause for a specified buffer INCLUDING leading and trailing blanks. EXCLUDING commas and period. Parameters: pcBuffer - Buffer name. pcWhere - A complete query:prepare-string. - ? use the current query
CHARACTER BuildDefaultQueryString (character) Return a default query from data (no table options) ------------------------------------------------------------------------------*/
CHARACTER BuildFindString (character) /* untested and doesn't do anything that you could not do with buildQueryString */
CHARACTER BuildFindString (character, character) /* untested and doesn't do anything that you could not do with buildQueryString */
CHARACTER BuildFindString (handle)
CHARACTER BuildParsedQueryString (character)
CHARACTER BuildQueryString ()
CHARACTER BuildQueryString (character)
CHARACTER BuildQueryString (handle)
CHARACTER BuildSortExpression (character) /* return sort only for specified tables */
LOGICAL CanAddRefTables (character, integer, character) /* can pcRefTables be added to piTableLevel entry in a pcTables ordered query */
CHARACTER CheckIndex (handle)
ClearFilter ()
ClearQuery ()
CHARACTER GetCased (character)
CHARACTER GetEvaluation (integer)
CHARACTER GetEvaluationTables (integer, character)
CHARACTER GetParsedQueryTables ()
CHARACTER GetTableEvaluation (integer, integer, character)
CHARACTER GetTableExpression (character)
CHARACTER GetUnparsedWhereClause (character) /** get the buffer where clause from the unparsed query ..*/
CHARACTER InsertExpression (character, character, character) Inserts an expression into ONE buffer's where-clause. Parameters: pcWhere - Complete where clause with or without the FOR keyword, but without any comma before or after. pcExpression - New expression OR OF phrase (Existing OF phrase is replaced) pcAndOr - Specifies what operator is used to add the new expression to existing ones. - AND (default) - OR
CHARACTER InsertString (character, character, integer, integer) /* workaround for temporary core bug */
LOGICAL InsertToQuery (handle) /* insert the querystring into the query - uses mQueryRef IQueryMap:BaseQuery if unprepared - buffers decide the order (can be different than BaseQuery )*/
CHARACTER MaskQuotes (character, character) Utility function that masks all quoted strings in the passed string Parameters: pcString = string that might have embedded quoted strings. must be syntactically correct - paired single or double. pcReplaceChar = single char to insert in quoted positions.
CHARACTER MergeQueryString (character, character)
CHARACTER NewQuerySort (character, character) /*------------------------------------------------------------------------------ Purpose : Insert sort criteria (BY phrase) in a QueryString. Parameters: pcQuery - Query to add sort to (current sort will be replaced) pcSort - new sort expression . ------------------------------------------------------------------------------*/
ParseQuery (character) Parses the logical buffer's target query and stores it for transformation to the datasource query.
ParseSortExpression (character)
CHARACTER ResolveColumn (character, integer) /* called from parsequery and parseSortExpression */
SetQueryString (character) /* set querystring */
SetSort (character) /* ParseSortExpression will transform and set SortExpression property, which has a protected set */
Showdata ()
CHARACTER TableEvaluation (integer, character)
CHARACTER WhereClauseBuffer (character) Returns the buffername of a where clause expression. This function avoids problems with leading or double blanks in where clauses. Parameters: pcWhere - 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".

Constructor Summary
Options Name Purpose
QueryString () /* use as utility - InsertExpression */
QueryString (character) /* queryWhere is a simple query without any table options like no-lock */
QueryString (character, character) /* QueryWhere - is a simple query without any table options like no-lock can have query options like indexed-reposition Basequery - query to which the QueryWhere and filters should be merged - provide table options as well as a fixed expressions - uses BuildDefaultQuery if base query is blank or ? */
QueryString (character, IQueryMap) /* queryWhere is a simple query without any table options like no-lock Basequery */
QueryString (IQueryMap)

Property Summary
Options Name Purpose
CHARACTER BaseQuery
LOGICAL MergeQuery
CHARACTER QueryOptions
CHARACTER SortExpression
CHARACTER Statement
CHARACTER Tables
LOGICAL UpperCaseKeyWords


Method Detail
Top

AddExpression (character)

Parameters:
pcExpression CHARACTER
Top

AddFilter (character, character, character)

/* we just add it to the 1st table - the table position is resolved in all methods
that returns the query
Parameters:
pColumnName CHARACTER
pColumnOperator CHARACTER
pColValue CHARACTER
Top

AddFilter (log[], character[], character[], character[])

Parameters:
logicalAnd LOGICAL
columnNames CHARACTER
columnOperators CHARACTER
colValues CHARACTER
Top

CHARACTER BufferWhereClause (character, character, integer)

Purpose: Returns the complete query where clause for a specified buffer
INCLUDING leading and trailing blanks.
EXCLUDING commas and period.
Parameters: pcBuffer - Buffer name.
pcWhere - A complete query:prepare-string.
- ? use the current query
Notes: This is supported as a 'utility function' that doesn't use any
properties.
- RETURNs the expression immediately when found.
RETURNs '' at bottom if nothing is found.
Parameters:
pcBuffer CHARACTER
pcWhere CHARACTER
piPos INTEGER
Returns CHARACTER
Top

CHARACTER BuildDefaultQueryString (character)

Purpose: Return a default query from data (no table options)
Parameters:
pcTables CHARACTER
Returns CHARACTER
Top

CHARACTER BuildFindString (character)

/* untested and doesn't do anything that you could not do with buildQueryString
Parameters:
pcTable CHARACTER
Returns CHARACTER
Top

CHARACTER BuildFindString (character, character)

/* untested and doesn't do anything that you could not do with buildQueryString
Parameters:
pcTable CHARACTER
pcQuery CHARACTER
Returns CHARACTER
Top

CHARACTER BuildFindString (handle)

Parameters:
phQuery HANDLE
Returns CHARACTER
Top

CHARACTER BuildParsedQueryString (character)

Parameters:
pcTables CHARACTER
Returns CHARACTER
Top

CHARACTER BuildQueryString ()

Returns CHARACTER
Top

CHARACTER BuildQueryString (character)

Parameters:
pcTables CHARACTER
Returns CHARACTER
Top

CHARACTER BuildQueryString (handle)

Parameters:
phQuery HANDLE
Returns CHARACTER
Top

CHARACTER BuildSortExpression (character)

/* return sort only for specified tables
Parameters:
pcTables CHARACTER
Returns CHARACTER
Top

LOGICAL CanAddRefTables (character, integer, character)

/* can pcRefTables be added to piTableLevel entry in a pcTables ordered query
Parameters:
pcRefTables CHARACTER
piTableLevel INTEGER
pcTables CHARACTER
Returns LOGICAL
Top

CHARACTER CheckIndex (handle)

Parameters:
phBuffer HANDLE
Returns CHARACTER
Top

ClearFilter ()

Top

ClearQuery ()

Top

CHARACTER GetCased (character)

Parameters:
word CHARACTER
Returns CHARACTER
Top

CHARACTER GetEvaluation (integer)

Parameters:
piEval INTEGER
Returns CHARACTER
Top

CHARACTER GetEvaluationTables (integer, character)

Parameters:
piEval INTEGER
pcTables CHARACTER
Returns CHARACTER
Top

CHARACTER GetParsedQueryTables ()

Returns CHARACTER
Top

CHARACTER GetTableEvaluation (integer, integer, character)

Parameters:
piEval INTEGER
piTableEntry INTEGER
pcTables CHARACTER
Returns CHARACTER
Top

CHARACTER GetTableExpression (character)

Parameters:
pcTable CHARACTER
Returns CHARACTER
Top

CHARACTER GetUnparsedWhereClause (character)

Purpose: get the buffer where clause from the unparsed query ..
Parameters:
pcBuffer CHARACTER
Returns CHARACTER
Top

CHARACTER InsertExpression (character, character, character)

Purpose: Inserts an expression into ONE buffer's where-clause.
Parameters:
pcWhere - Complete where clause with or without the FOR keyword,
but without any comma before or after.
pcExpression - New expression OR OF phrase (Existing OF phrase is replaced)
pcAndOr - Specifies what operator is used to add the new expression
to existing ones.
- AND (default)
- OR
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
pcExpression CHARACTER
pcAndOr CHARACTER
Returns CHARACTER
Top

CHARACTER InsertString (character, character, integer, integer)

/* workaround for temporary core bug
Parameters:
pcString CHARACTER
pcTargetString CHARACTER
piPos INTEGER
piLength INTEGER
Returns CHARACTER
Top

LOGICAL InsertToQuery (handle)

/* insert the querystring into the query
- uses mQueryRef IQueryMap:BaseQuery if unprepared
- buffers decide the order (can be different than BaseQuery )
Parameters:
phQuery HANDLE
Returns LOGICAL
Top

CHARACTER MaskQuotes (character, character)

Purpose: Utility function that masks all quoted strings in the passed string
Parameters: pcString = string that might have embedded quoted strings.
must be syntactically correct - paired single or double.
pcReplaceChar = single char to insert in quoted positions.
Notes: Used in various query manipulation before looking for keywords
(Basically a workaround for lack of full parsing )
Parameters:
pcString CHARACTER
pcReplaceChar CHARACTER
Returns CHARACTER
Top

CHARACTER MergeQueryString (character, character)

Parameters:
pcTables CHARACTER
pcBaseQuery CHARACTER
Returns CHARACTER
Top

CHARACTER NewQuerySort (character, character)

Purpose : Insert sort criteria (BY phrase) in a QueryString.
Parameters:
pcQuery - Query to add sort to (current sort will be replaced)
pcSort - new sort expression .
Parameters:
pcQuery CHARACTER
pcSort CHARACTER
Returns CHARACTER
Top

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
Top

ParseSortExpression (character)

Parameters:
pcSort CHARACTER
Top

CHARACTER ResolveColumn (character, integer)

/* called from parsequery and parseSortExpression
Parameters:
pcColumn CHARACTER
piExp INTEGER
Returns CHARACTER
Top

SetQueryString (character)

/* set querystring
Parameters:
cQuery CHARACTER
Top

SetSort (character)

/* ParseSortExpression will transform and set SortExpression property,
which has a protected set
Parameters:
cSort CHARACTER
Top

Showdata ()

Top

CHARACTER TableEvaluation (integer, character)

Parameters:
piTableEntry INTEGER
pcTables CHARACTER
Returns CHARACTER
Top

CHARACTER WhereClauseBuffer (character)

Purpose: Returns the buffername of a where clause expression.
This function avoids problems with leading or double blanks in
where clauses.
Parameters:
pcWhere - 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".
Notes: Used internally in query.p.
Parameters:
pcWhere CHARACTER
Returns CHARACTER


Constructor Detail
Top

QueryString ()

/* use as utility - InsertExpression
Top

QueryString (character)

/* queryWhere is a simple query without any table options like no-lock
Parameters:
pcQueryWhere CHARACTER
Top

QueryString (character, character)

/* QueryWhere - is a simple query without any table options like no-lock can have query options
like indexed-reposition
Basequery - query to which the QueryWhere and filters should be merged
- provide table options as well as a fixed expressions
- uses BuildDefaultQuery if base query is blank or ?
Parameters:
pcQueryWhere CHARACTER
pcBaseWhere CHARACTER
Top

QueryString (character, IQueryMap)

/* queryWhere is a simple query without any table options like no-lock
Basequery
Parameters:
pcQueryWhere CHARACTER
pQueryMap OpenEdge.DataAdmin.Lang.IQueryMap
Top

QueryString (IQueryMap)

Parameters:
pQueryMap OpenEdge.DataAdmin.Lang.IQueryMap


Property Detail
Top

CHARACTER BaseQuery

Returns CHARACTER
Top

LOGICAL MergeQuery

Returns LOGICAL
Top

CHARACTER QueryOptions

Returns CHARACTER
Top

CHARACTER SortExpression

Returns CHARACTER
Top

CHARACTER Statement

Returns CHARACTER
Top

CHARACTER Tables

Returns CHARACTER
Top

LOGICAL UpperCaseKeyWords

Returns LOGICAL


Copyright © 2022 Progress Software Corporation. All rights Reserved.

Progress® OpenEdge® Release 11.7.15