Class DButils

Summary

General purpose utility methods for help in working with SQL databases.

This is a singleton class. There is only one instance of it, no matter how many times you think you are calling the constructor.

Superclasses:
Object

Package:
database
File:
db_util.icn
Methods:
addColDesc, addCondition, escape, getColNames, mapSQLExpr, mapToSQL

Methods inherited from Object:
Type, className, clone, equals, fieldNames, genMethods, getField, get_class, get_class_name, get_id, hasField, hasMethod, hash_code, instanceOf, invoke, is_instance, setField, to_string

Source code.

Details
Constructor

DButils()

 forces this into a singleton class

Methods:

addColDesc(cd:"", colName, colType, colConstraints)

Parameters:
cd
string of existing column descriptions
colName
name of column
colType
type of column
colConstraints
any constraints placed on column type
Returns:
modified column descriptions string

Add a column description to a list (string) of column descriptions Can be used to help simplify calls to CREATE TABLE


addCondition(wc:"", field, test, values)

Parameters:
wc
existing WHERE clause to add condition to
field
name of field involved in condition test
test
condition to check on field, eg: "="
values
one or more values to test field against
Returns:
modifed WHERE clause with new conditions added, joined by AND

Add a condition clause to a string of condition clauses using conjunction. If values is a structure (list or record), then adds a series of clauses joined by disjunction.

Example:

    addCondition("", "id", "=", ["one","'two","three"])
produces:
    "((id='one') OR (id='two') OR (id='three'))"

Example:

    addCondition("(id='one')", "part_no", "=", "two")
produces:
    "(id='one') AND (part_no='two')"

Also locates '*' (simple wildcards) in values and adjusts test to 'like' provided test had been '='.

Example:

    addCondition("", "filename", "=", "sam*.icn")
produces:
    "(filename LIKE 'sam%.icn')"


escape(s:"")

Parameter:
s
String to examine for single quotes and backslashes
Returns:
copy of s with quotes and backslashes escaped

Escape single quotes and backslashes


getColNames(rec)

Parameter:
rec
Record produced by fetch method in Database class
Returns:
a list of column names from the database record rec


mapSQLExpr(field, op, value)

Parameters:
field
name of field involved in test
op
test to perform, eg: "=". This may get changed to equivalent SQL wild-card operation.
value
used to test fields
Returns:
SQL WHERE clause for wild-card comparisions

Look for wildcards in value and if found, modify expression into SQL wildcard syntax

Internal use only.


mapToSQL(field, test, values)

Parameters:
field
name of field involved in test
test
condition to test, eg: "="
values
one or more values to test field against
Returns:
SQL WHERE clause with conditions joined by disjunction

Build a set of SQL tests joined by disjunction. If values is a string, it's a single test otherwise, step through elements, building tests joined with disjunction.

Internal use only.



This page produced by UniDoc on 2021/04/15 @ 23:59:53.