utselect.wbb - Create SELECT WHERE Clause from CGI Input Fields

Syntax

CALL "utselect.wbb", cgi$, tpl$, where$, andor$

Description

This program simplifies the parsing of cgi input from an HTML query form. The query form would contain input fields for certain data fields, and once the user filled in and submitted the form, this program would create the WHERE clause of a SELECT statement based on the user entries. It is sensitive to user-defined formatting attributes in the data template.

Parameter

Description

cgi$

String template returned by utcgi.wbb.

tpl$

Data template used in the SELECT statement and can include user-defined formatting attributes, as defined in the Data Template section.

where$

Returns the WHERE clause, suitable for use in a SELECT statement, with the syntax "WHERE CPL(WHERE$)". The assumed data template name used in where$ is "rec": rec.state$="CA". For example: if "rec" is not the right name, a substitution should be performed before executing the SELECT statement.

andor$

Specifies whether the AND or OR boolean is used between fields in where$. If this is not set to "or", then "and" is assumed.

Any field in cgi$ and tpl$ that isn't null in cgi$, is evaluated. The field name for the where clause expression fragment is taken from cgi$.

If a cgi$ field called "opr_name" is found, the where clause operator is taken from that field. Otherwise, the text of the cgi field itself is analyzed for an operator. Operators can be <, >, =, <=, >=, <>, in, like, and between. If there is no operator, but the data in cgi$ contains *, ?, or [ characters, and the tpl$ definition for the field is character rather than numeric, the "like" operator (wildcard) is used. Otherwise, text fields must start with the characters entered, and numeric fields must be equal to the number entered.

If the operator is "between", there must be exactly two occurrences of the same field name, and the where clause will be formed as field >= first-value and field <= second-value.

If the same field occurs multiple times in cgi$ (as can happen with checkboxes, multiple selection lists, or intentionally created duplicate named tags), multiple where clause expressions are created with OR boolean logic (other than the between operator case noted above), distinct from the AND or OR booleans used between unique field names.