NextPrevUpTopContentsIndex

sql-operation

Function
Summary

Generates an SQL statement from an operator and arguments.

Package

sql

Signature

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

sql-operation sql-function name &rest args => sql-result

sql-operation sql-operator inop1 left &rest rights => sql-result

sql-operation sql-boolean-operator inop2 left &rest rights => sql-result

Arguments

op

An operator.

args

A set of arguments for op.

name

An arbitrary function.

args

A set of arguments for name .

inop1

An infix operator with non-boolean result.

inop2

An infix operator that returns a boolean.

left

Argument to be placed on the left of an infix operator.

rights

Arguments to be placed on the right of an infix operator.

Values

sql-result

An SQL expression.

Description

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

(sql-operation op args )

is shorthand for

(apply (sql-operator op ) args ) .

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

The pseudo operators sql-boolean-operator and sql-operator 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 that return a boolean and use sql-operator for any other SQL infix operator.

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

Example

The following code, uses sql-operation to produce an 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 Reference Manual - 12 Mar 2008

NextPrevUpTopContentsIndex