In some cases it is necessary to build SQL-expressions dynamically under program control. The following functions are provided to this end:
sql-operationFunction
sql-operation op &rest args
[] syntax above where SQL strings represent symbolic expressions. This function is shorthand for (apply (sql-operator op) args)sql
-expressionFunction
sql-expression &key string table alias attribute type
[] syntax as discussed in Section 14.5.1 on page 133. Valid combinations are: Function
sql-operator symbol
sql-symbol). Function
sql &rest args
. Each argument tosql is turned into SQL and then the args are concatenated with a single space between each pair. The rules for translation into SQL are as follows (based on the type of each individual argumentx): string --> (format nil "'~A'" x)
x between single quotes (this corresponds to an SQL string constant); (sql null) --> "NULL"
symbol --> (symbol-name x)
number --> (princ-to-string x)
list --> (format nil "(~{~A~^,~})" (mapcar #'sql x))
x in SQL, between parentheses separated by commas.
vector --> (format nil "~{~A~^,~}" (map 'list #'sql x))
x in SQL, comma-separated, without parentheses. This is to allow the easy generation of SQL lists that require no parentheses such as table lists in select statements. sql-expression --> x otherwise --> (error)