Class DButils |
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.
Details |
Constructor |
forces this into a singleton class
Methods: |
addColDesc(cd:"", colName, colType, colConstraints)
cd | string of existing column descriptions |
colName | name of column |
colType | type of column |
colConstraints | any constraints placed on column type |
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)
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 |
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')"
s | String to examine for single quotes and backslashes
|
copy of s with quotes and backslashes escaped |
Escape single quotes and backslashes
rec | Record produced by fetch method in Database class
|
a list of column names from the database record rec |
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 |
SQL WHERE clause for wild-card comparisions |
Look for wildcards in value and if found, modify expression into SQL wildcard syntax
Internal use only.
field | name of field involved in test |
test | condition to test, eg: "=" |
values | one or more values to test field against |
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.