All Manuals > LispWorks® User Guide and Reference Manual > 45 The SQL Package

sql-operation Function

Summary

Generates a SQL statement from an operator and arguments.

Package

sql

Signature

sql-operation op &rest args => sql-result

Arguments
op
An operator.
args
A set of arguments for op.
Values
sql-result
A SQL expression.
Description

The function sql-operation takes an operator op and its arguments args, and returns a SQL expression.

(sql-operation op args)

is shorthand for:

(apply (sql-operator op) args).

The following pseudo operators can be used for op:

sql-function

A call for the form:

(sql-operation 'sql-function name &rest function-args)

allows an arbitrary function name to be passed. In this case, name is put in the SQL expression using princ, and function-args are given as arguments.

sql-boolean-operator and sql-operator

Calls for the form:

(sql-operation 'sql-operator value-inop left &rest rights)
(sql-operation 'sql-boolean-operator bool-inop left &rest rights)

generate SQL that calls an infix operator with left on the left and rights on the right separated by spaces.

Use sql-boolean-operator for SQL infix operators bool-inop that return a boolean and use sql-operator for any other SQL infix operator value-inop.

Notes

The pseudo operator sql-operator should not be confused with the Common SQL function sql-operator.

Examples

The following code, uses sql-operation to produce a SQL expression.

(sql-operation 'select
  (sql-expression :table 'foo :attribute 'bar)
  (sql-expression :attribute 'baz)
  :from (list
           (sql-expression :table 'foo)
           (sql-expression :table 'quux))
  :where
     (sql-operation 'or
       (sql-operation '>
         (sql-expression :attribute 'baz)
         3)
       (sql-operation 'like
         (sql-expression :table 'foo :attribute 'bar)
         "SU%")))

The following SQL expression is produced.

#<SQL-QUERY: "(SELECT FOO.BAR,BAZ FROM FOO,QUUX
      WHERE ((BAZ > 3) OR (FOO.BAR LIKE 'SU%')))">

The following code illustrates use of the pseudo operator sql-function:

(sql-operation 'sql-function "TO_DATE" "03/06/99"
 "mm/DD/RR")

The following SQL expression is produced.

#<SQL-VALUE-EXP "TO_DATE('03/06/99','mm/DD/RR')">
See also

sql
sql-expression
sql-operator


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:56