/usr/share/common-lisp/source/clsql/sql/operations.lisp is in cl-sql 6.7.0-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
;;;; *************************************************************************
;;;;
;;;; Definition of SQL operations used with the symbolic SQL syntax.
;;;;
;;;; This file is part of CLSQL.
;;;;
;;;; CLSQL users are granted the rights to distribute and use this software
;;;; as governed by the terms of the Lisp Lesser GNU Public License
;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
;;;; *************************************************************************
(in-package #:clsql-sys)
;; Keep a hashtable for mapping symbols to sql generator functions,
;; for use by the bracketed reader syntax.
(defvar *sql-op-table* (make-hash-table :test #'equal))
;; Define an SQL operation type.
(defmacro defsql (function definition-keys &body body)
`(progn
(defun ,function ,@body)
(let ((symbol (cadr (member :symbol ',definition-keys))))
(setf (gethash (if symbol (symbol-name-default-case symbol) ',function)
*sql-op-table*)
',function))))
;; SQL operations
(defsql sql-query (:symbol "select") (&rest args)
(apply #'make-query args))
(defsql sql-any (:symbol "any") (&rest rest)
(make-instance 'sql-function-exp
:name 'any :args rest))
(defsql sql-some (:symbol "some") (&rest rest)
(make-instance 'sql-function-exp
:name 'some :args rest))
(defsql sql-all (:symbol "all") (&rest rest)
(make-instance 'sql-function-exp
:name 'all :args rest))
(defsql sql-e-string (:symbol "E") (&rest rest)
(make-instance 'sql-escape-string-exp :string (first rest)))
(defsql sql-not (:symbol "not") (&rest rest)
(make-instance 'sql-value-exp
:modifier 'not :components rest))
(defsql sql-union (:symbol "union") (&rest rest)
(make-instance 'sql-set-exp
:operator 'union :sub-expressions rest))
(defsql sql-intersect (:symbol "intersect") (&rest rest)
(make-instance 'sql-set-exp
:operator 'intersect :sub-expressions rest))
(defsql sql-except (:symbol "except") (&rest rest)
(make-instance 'sql-set-exp
:operator 'except :sub-expressions rest))
(defsql sql-minus (:symbol "minus") (&rest rest)
(make-instance 'sql-set-exp
:operator 'minus :sub-expressions rest))
(defsql sql-limit (:symbol "limit") (&rest rest)
(make-instance 'sql-query-modifier-exp
:modifier 'limit :components rest))
(defsql sql-group-by (:symbol "group-by") (&rest rest)
(make-instance 'sql-query-modifier-exp
:modifier '|GROUP BY| :components rest))
(defsql sql-order-by (:symbol "order-by") (&rest rest)
(make-instance 'sql-query-modifier-exp
:modifier '|ORDER BY| :components rest))
(defsql sql-having (:symbol "having") (&rest rest)
(make-instance 'sql-query-modifier-exp
:modifier 'having :components rest))
(defsql sql-null (:symbol "null") (&optional not-null-thing)
(if not-null-thing
(make-instance 'sql-relational-exp :operator 'is
:sub-expressions (list not-null-thing nil))
(make-instance 'sql-value-exp :components 'null)))
(defsql sql-not-null (:symbol "not-null") (&optional not-null-thing)
(if not-null-thing
(make-instance
'sql-relational-exp
:operator 'IS
:sub-expressions (list not-null-thing
(sql-expression :string "NOT NULL")))
(sql-expression :string "NOT NULL")))
(defsql sql-exists (:symbol "exists") (&rest rest)
(make-instance 'sql-function-exp
:name 'exists :args rest))
(defsql sql-* (:symbol "*") (&rest rest)
(if (zerop (length rest))
(make-instance 'sql-ident :name '*)
(make-instance 'sql-relational-exp :operator '* :sub-expressions rest)))
(defsql sql-+ (:symbol "+") (&rest rest)
(if (cdr rest)
(make-instance 'sql-relational-exp
:operator '+ :sub-expressions rest)
(make-instance 'sql-value-exp :modifier '+ :components rest)))
(defsql sql-/ (:symbol "/") (&rest rest)
(make-instance 'sql-relational-exp
:operator '/ :sub-expressions rest))
(defsql sql-- (:symbol "-") (&rest rest)
(if (cdr rest)
(make-instance 'sql-relational-exp
:operator '- :sub-expressions rest)
(make-instance 'sql-value-exp :modifier '- :components rest)))
(defsql sql-like (:symbol "like") (&rest rest)
(make-instance 'sql-relational-exp
:operator 'like :sub-expressions rest))
(defsql sql-uplike (:symbol "uplike") (&rest rest)
(make-instance 'sql-upcase-like
:sub-expressions rest))
(defsql sql-and (:symbol "and") (&rest rest)
(make-instance 'sql-relational-exp
:operator 'and :sub-expressions rest))
(defsql sql-or (:symbol "or") (&rest rest)
(make-instance 'sql-relational-exp
:operator 'or :sub-expressions rest))
(defsql sql-in (:symbol "in") (&rest rest)
(make-instance 'sql-relational-exp
:operator 'in :sub-expressions rest))
(defsql sql-concat-op (:symbol "concat-op") (&rest rest)
(make-instance 'sql-relational-exp
:operator '\|\| :sub-expressions rest))
(defsql sql-concat (:symbol "concat") (&rest rest)
(make-instance 'sql-function-exp
:name 'concat :args rest))
(defsql sql-substr (:symbol "substr") (&rest rest)
(if (= (length rest) 3)
(make-instance 'sql-function-exp
:name 'substr :args rest)
(error 'sql-user-error :message "SUBSTR must have 3 arguments.")))
(defsql sql-substring (:symbol "substring") (&rest rest)
(if (= (length rest) 3)
(make-instance 'sql-function-exp
:name 'substring :args rest)
(error 'sql-user-error :message "SUBSTRING must have 3 arguments.")))
(defsql sql-is (:symbol "is") (&rest rest)
(make-instance 'sql-relational-exp
:operator 'is :sub-expressions rest))
(defsql sql-= (:symbol "=") (&rest rest)
(make-instance 'sql-relational-exp
:operator '= :sub-expressions rest))
(defsql sql-== (:symbol "==") (&rest rest)
(make-instance 'sql-assignment-exp
:operator '= :sub-expressions rest))
(defsql sql-< (:symbol "<") (&rest rest)
(make-instance 'sql-relational-exp
:operator '< :sub-expressions rest))
(defsql sql-> (:symbol ">") (&rest rest)
(make-instance 'sql-relational-exp
:operator '> :sub-expressions rest))
(defsql sql-<> (:symbol "<>") (&rest rest)
(make-instance 'sql-relational-exp
:operator '<> :sub-expressions rest))
(defsql sql->= (:symbol ">=") (&rest rest)
(make-instance 'sql-relational-exp
:operator '>= :sub-expressions rest))
(defsql sql-<= (:symbol "<=") (&rest rest)
(make-instance 'sql-relational-exp
:operator '<= :sub-expressions rest))
(defsql sql-count (:symbol "count") (&rest rest)
(make-instance 'sql-function-exp
:name 'count :args rest))
(defsql sql-max (:symbol "max") (&rest rest)
(make-instance 'sql-function-exp
:name 'max :args rest))
(defsql sql-min (:symbol "min") (&rest rest)
(make-instance 'sql-function-exp
:name 'min :args rest))
(defsql sql-avg (:symbol "avg") (&rest rest)
(make-instance 'sql-function-exp
:name 'avg :args rest))
(defsql sql-sum (:symbol "sum") (&rest rest)
(make-instance 'sql-function-exp
:name 'sum :args rest))
(defsql sql-the (:symbol "the") (&rest rest)
(make-instance 'sql-typecast-exp
:modifier (first rest) :components (second rest)))
(defsql sql-function (:symbol "function") (&rest args)
(make-instance 'sql-function-exp
:name (make-symbol (car args)) :args (cdr args)))
(defsql sql-between (:symbol "between") (&rest rest)
(if (= (length rest) 3)
(make-instance 'sql-between-exp :name 'between :args rest)
(error 'sql-user-error :message "BETWEEN must have 3 arguments.")))
(defsql sql-distinct (:symbol "distinct") (&rest rest)
(make-instance 'sql-query-modifier-exp :modifier 'distinct
:components rest))
(defsql sql-coalesce (:symbol "coalesce") (&rest rest)
(make-instance 'sql-function-exp
:name 'coalesce :args rest))
(defsql sql-nvl (:symbol "nvl") (&rest rest)
(if (= (length rest) 2)
(make-instance 'sql-function-exp
:name 'coalesce :args rest)
(error 'sql-user-error :message "NVL accepts exactly 2 arguments.")))
(defsql sql-userenv (:symbol "userenv") (&rest rest)
(make-instance 'sql-function-exp
:name 'userenv :args rest))
(defsql sql-lower (:symbol "lower") (&rest rest)
(if (= (length rest) 1)
(make-instance 'sql-function-exp
:name 'lower :args rest)
(error 'sql-user-error :message "LOWER must have 1 argument.")))
(defsql sql-upper (:symbol "upper") (&rest rest)
(if (= (length rest) 1)
(make-instance 'sql-function-exp
:name 'upper :args rest)
(error 'sql-user-error :message "UPPER must have 1 argument.")))
|