1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
4 ;;;; Classes defining SQL expressions and methods for formatting the
5 ;;;; appropriate SQL commands.
7 ;;;; This file is part of CLSQL.
9 ;;;; CLSQL users are granted the rights to distribute and use this software
10 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
11 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
12 ;;;; *************************************************************************
14 (in-package #:clsql-sys)
16 (defvar +empty-string+ "''")
18 (defvar +null-string+ "NULL")
20 (defvar *sql-stream* nil
21 "stream which accumulates SQL output")
23 (defun sql-output (sql-expr &optional (database *default-database*))
24 "Top-level call for generating SQL strings. Returns an SQL
25 string appropriate for DATABASE which corresponds to the
26 supplied lisp expression SQL-EXPR."
27 (progv '(*sql-stream*)
28 `(,(make-string-output-stream))
29 (output-sql sql-expr database)
30 (get-output-stream-string *sql-stream*)))
32 (defmethod output-sql (expr database)
33 (write-string (database-output-sql expr database) *sql-stream*)
36 (defvar *output-hash* (make-hash-table :test #'equal)
37 "For caching generated SQL strings.")
39 (defmethod output-sql :around ((sql t) database)
40 (let* ((hash-key (output-sql-hash-key sql database))
41 (hash-value (when hash-key (gethash hash-key *output-hash*))))
42 (cond ((and hash-key hash-value)
43 (write-string hash-value *sql-stream*))
45 (let ((*sql-stream* (make-string-output-stream)))
47 (setf hash-value (get-output-stream-string *sql-stream*))
48 (setf (gethash hash-key *output-hash*) hash-value))
49 (write-string hash-value *sql-stream*))
51 (call-next-method)))))
53 (defmethod output-sql-hash-key (expr database)
54 (declare (ignore expr database))
58 (defclass %sql-expression ()
61 (defmethod output-sql ((expr %sql-expression) database)
62 (declare (ignore database))
63 (write-string +null-string+ *sql-stream*))
65 (defmethod print-object ((self %sql-expression) stream)
66 (print-unreadable-object
68 (write-string (sql-output self) stream))
71 ;; For straight up strings
73 (defclass sql (%sql-expression)
77 (:documentation "A literal SQL expression."))
79 (defmethod make-load-form ((sql sql) &optional environment)
80 (declare (ignore environment))
83 `(make-instance 'sql :string ',text)))
85 (defmethod output-sql ((expr sql) database)
86 (declare (ignore database))
87 (write-string (slot-value expr 'text) *sql-stream*)
90 (defmethod print-object ((ident sql) stream)
91 (format stream "#<~S \"~A\">"
93 (sql-output ident nil))
96 ;; For SQL Identifiers of generic type
98 (defclass sql-ident (%sql-expression)
101 :initform +null-string+))
102 (:documentation "An SQL identifer."))
104 (defmethod make-load-form ((sql sql-ident) &optional environment)
105 (declare (ignore environment))
108 `(make-instance 'sql-ident :name ',name)))
110 (defmethod output-sql ((expr sql-ident) database)
111 (with-slots (name) expr
115 (symbol (symbol-name name)))
119 ;; For SQL Identifiers for attributes
121 (defclass sql-ident-attribute (sql-ident)
124 :initform +null-string+)
127 :initform +null-string+))
128 (:documentation "An SQL Attribute identifier."))
130 (defmethod collect-table-refs (sql)
131 (declare (ignore sql))
134 (defmethod collect-table-refs ((sql sql-ident-attribute))
135 (let ((qual (slot-value sql 'qualifier)))
137 (list (make-instance 'sql-ident-table :name qual)))))
139 (defmethod make-load-form ((sql sql-ident-attribute) &optional environment)
140 (declare (ignore environment))
141 (with-slots (qualifier type name)
143 `(make-instance 'sql-ident-attribute :name ',name
144 :qualifier ',qualifier
147 (defmethod output-sql ((expr sql-ident-attribute) database)
148 (with-slots (qualifier name type) expr
149 (if (and (not qualifier) (not type))
152 (write-string name *sql-stream*))
155 (sql-escape (symbol-name name)) *sql-stream*)))
157 ;;; KMR: The TYPE field is used by CommonSQL for type conversion -- it
158 ;;; should not be output in SQL statements
160 (format *sql-stream* "~@[~A.~]~A~@[ ~A~]"
162 (sql-escape qualifier))
166 (format *sql-stream* "~@[~A.~]~A"
169 (string (format nil "~s" qualifier))
170 (t (sql-escape qualifier))))
172 (string (format nil "~s" (sql-escape name)))
173 (t (sql-escape name)))))
176 (defmethod output-sql-hash-key ((expr sql-ident-attribute) database)
177 (with-slots (qualifier name type)
179 (list (and database (database-underlying-type database))
180 'sql-ident-attribute qualifier name type)))
182 ;; For SQL Identifiers for tables
184 (defclass sql-ident-table (sql-ident)
186 :initarg :table-alias :initform nil))
187 (:documentation "An SQL table identifier."))
189 (defmethod make-load-form ((sql sql-ident-table) &optional environment)
190 (declare (ignore environment))
191 (with-slots (alias name)
193 `(make-instance 'sql-ident-table :name ',name :table-alias ',alias)))
195 (defmethod output-sql ((expr sql-ident-table) database)
196 (with-slots (name alias) expr
199 (format *sql-stream* "~s" (sql-escape name)))
201 (write-string (sql-escape name) *sql-stream*)))
203 (format *sql-stream* " ~s" alias)))
206 (defmethod output-sql-hash-key ((expr sql-ident-table) database)
207 (with-slots (name alias)
209 (list (and database (database-underlying-type database))
210 'sql-ident-table name alias)))
212 (defclass sql-relational-exp (%sql-expression)
217 :initarg :sub-expressions
219 (:documentation "An SQL relational expression."))
221 (defmethod make-load-form ((self sql-relational-exp) &optional environment)
222 (make-load-form-saving-slots self
223 :slot-names '(operator sub-expressions)
224 :environment environment))
226 (defmethod collect-table-refs ((sql sql-relational-exp))
228 (dolist (exp (slot-value sql 'sub-expressions))
229 (let ((refs (collect-table-refs exp)))
230 (if refs (setf tabs (append refs tabs)))))
231 (remove-duplicates tabs
232 :test (lambda (tab1 tab2)
233 (equal (slot-value tab1 'name)
234 (slot-value tab2 'name))))))
239 ;; Write SQL for relational operators (like 'AND' and 'OR').
240 ;; should do arity checking of subexpressions
242 (defmethod output-sql ((expr sql-relational-exp) database)
243 (with-slots (operator sub-expressions) expr
244 ;; we do this as two runs so as not to emit confusing superflous parentheses
245 ;; The first loop renders all the child outputs so that we can skip anding with
246 ;; empty output (which causes sql errors)
247 ;; the next loop simply emits each sub-expression with the appropriate number of
248 ;; parens and operators
250 (string-trim +whitespace-chars+
251 (with-output-to-string (*sql-stream*)
252 (output-sql sub database)))))
253 (let ((str-subs (loop for sub in sub-expressions
254 for str-sub = (trim sub)
255 when (and str-sub (> (length str-sub) 0))
257 (case (length str-subs)
259 (1 (write-string (first str-subs) *sql-stream*))
261 (write-char #\( *sql-stream*)
262 (write-string (first str-subs) *sql-stream*)
263 (loop for str-sub in (rest str-subs)
265 (write-char #\Space *sql-stream*)
266 (output-sql operator database)
267 (write-char #\Space *sql-stream*)
268 (write-string str-sub *sql-stream*))
269 (write-char #\) *sql-stream*))
273 (defclass sql-upcase-like (sql-relational-exp)
275 (:documentation "An SQL 'like' that upcases its arguments."))
277 (defmethod output-sql ((expr sql-upcase-like) database)
278 (flet ((write-term (term)
279 (write-string "upper(" *sql-stream*)
280 (output-sql term database)
281 (write-char #\) *sql-stream*)))
282 (with-slots (sub-expressions)
284 (let ((subs (if (consp (car sub-expressions))
285 (car sub-expressions)
287 (write-char #\( *sql-stream*)
288 (do ((sub subs (cdr sub)))
289 ((null (cdr sub)) (write-term (car sub)))
290 (write-term (car sub))
291 (write-string " LIKE " *sql-stream*))
292 (write-char #\) *sql-stream*))))
295 (defclass sql-assignment-exp (sql-relational-exp)
297 (:documentation "An SQL Assignment expression."))
300 (defmethod output-sql ((expr sql-assignment-exp) database)
301 (with-slots (operator sub-expressions)
303 (do ((sub sub-expressions (cdr sub)))
304 ((null (cdr sub)) (output-sql (car sub) database))
305 (output-sql (car sub) database)
306 (write-char #\Space *sql-stream*)
307 (output-sql operator database)
308 (write-char #\Space *sql-stream*)))
311 (defclass sql-value-exp (%sql-expression)
319 "An SQL value expression.")
322 (defmethod collect-table-refs ((sql sql-value-exp))
324 (if (listp (slot-value sql 'components))
326 (dolist (exp (slot-value sql 'components))
327 (let ((refs (collect-table-refs exp)))
328 (if refs (setf tabs (append refs tabs)))))
329 (remove-duplicates tabs
330 :test (lambda (tab1 tab2)
331 (equal (slot-value tab1 'name)
332 (slot-value tab2 'name)))))
337 (defmethod output-sql ((expr sql-value-exp) database)
338 (with-slots (modifier components)
342 (write-char #\( *sql-stream*)
343 (output-sql modifier database)
344 (write-char #\Space *sql-stream*)
345 (output-sql components database)
346 (write-char #\) *sql-stream*))
347 (output-sql components database))))
349 (defclass sql-typecast-exp (sql-value-exp)
351 (:documentation "An SQL typecast expression."))
353 (defmethod output-sql ((expr sql-typecast-exp) database)
354 (with-slots (components)
356 (output-sql components database)))
358 (defmethod collect-table-refs ((sql sql-typecast-exp))
359 (when (slot-value sql 'components)
360 (collect-table-refs (slot-value sql 'components))))
362 (defclass sql-function-exp (%sql-expression)
370 "An SQL function expression."))
372 (defmethod collect-table-refs ((sql sql-function-exp))
374 (dolist (exp (slot-value sql 'args))
375 (let ((refs (collect-table-refs exp)))
376 (if refs (setf tabs (append refs tabs)))))
377 (remove-duplicates tabs
378 :test (lambda (tab1 tab2)
379 (equal (slot-value tab1 'name)
380 (slot-value tab2 'name))))))
381 (defvar *in-subselect* nil)
383 (defmethod output-sql ((expr sql-function-exp) database)
384 (with-slots (name args)
386 (output-sql name database)
387 (let ((*in-subselect* nil)) ;; aboid double parens
388 (when args (output-sql args database))))
392 (defclass sql-between-exp (sql-function-exp)
394 (:documentation "An SQL between expression."))
396 (defmethod output-sql ((expr sql-between-exp) database)
399 (output-sql (first args) database)
400 (write-string " BETWEEN " *sql-stream*)
401 (output-sql (second args) database)
402 (write-string " AND " *sql-stream*)
403 (output-sql (third args) database))
406 (defclass sql-query-modifier-exp (%sql-expression)
407 ((modifier :initarg :modifier :initform nil)
408 (components :initarg :components :initform nil))
409 (:documentation "An SQL query modifier expression."))
411 (defmethod output-sql ((expr sql-query-modifier-exp) database)
412 (with-slots (modifier components)
414 (output-sql modifier database)
415 (write-string " " *sql-stream*)
416 (output-sql (car components) database)
418 (mapc #'(lambda (comp)
419 (write-string ", " *sql-stream*)
420 (output-sql comp database))
424 (defclass sql-set-exp (%sql-expression)
429 :initarg :sub-expressions
431 (:documentation "An SQL set expression."))
433 (defmethod collect-table-refs ((sql sql-set-exp))
435 (dolist (exp (slot-value sql 'sub-expressions))
436 (let ((refs (collect-table-refs exp)))
437 (if refs (setf tabs (append refs tabs)))))
438 (remove-duplicates tabs
439 :test (lambda (tab1 tab2)
440 (equal (slot-value tab1 'name)
441 (slot-value tab2 'name))))))
443 (defmethod output-sql ((expr sql-set-exp) database)
444 (with-slots (operator sub-expressions)
446 (let ((subs (if (consp (car sub-expressions))
447 (car sub-expressions)
449 (when (= (length subs) 1)
450 (output-sql operator database)
451 (write-char #\Space *sql-stream*))
452 (do ((sub subs (cdr sub)))
453 ((null (cdr sub)) (output-sql (car sub) database))
454 (output-sql (car sub) database)
455 (write-char #\Space *sql-stream*)
456 (output-sql operator database)
457 (write-char #\Space *sql-stream*))))
460 (defclass sql-query (%sql-expression)
471 :initarg :set-operation
503 (:documentation "An SQL SELECT query."))
505 (defclass sql-object-query (%sql-expression)
519 (defmethod collect-table-refs ((sql sql-query))
520 (remove-duplicates (collect-table-refs (slot-value sql 'where))
521 :test (lambda (tab1 tab2)
522 (equal (slot-value tab1 'name)
523 (slot-value tab2 'name)))))
525 (defvar *select-arguments*
526 '(:all :database :distinct :flatp :from :group-by :having :order-by
527 :set-operation :where :offset :limit :inner-join :on
528 ;; below keywords are not a SQL argument, but these keywords may terminate select
531 (defun query-arg-p (sym)
532 (member sym *select-arguments*))
534 (defun query-get-selections (select-args)
535 "Return two values: the list of select-args up to the first keyword,
536 uninclusive, and the args from that keyword to the end."
537 (let ((first-key-arg (position-if #'query-arg-p select-args)))
539 (values (subseq select-args 0 first-key-arg)
540 (subseq select-args first-key-arg))
543 (defun make-query (&rest args)
544 (flet ((select-objects (target-args)
546 (every #'(lambda (arg)
548 (find-class arg nil)))
550 (multiple-value-bind (selections arglist)
551 (query-get-selections args)
552 (if (select-objects selections)
553 (destructuring-bind (&key flatp refresh &allow-other-keys) arglist
554 (make-instance 'sql-object-query :objects selections
555 :flatp flatp :refresh refresh
557 (destructuring-bind (&key all flatp set-operation distinct from where
558 group-by having order-by
559 offset limit inner-join on &allow-other-keys)
561 (if (null selections)
562 (error "No target columns supplied to select statement."))
564 (error "No source tables supplied to select statement."))
565 (make-instance 'sql-query :selections selections
566 :all all :flatp flatp :set-operation set-operation
567 :distinct distinct :from from :where where
568 :limit limit :offset offset
569 :group-by group-by :having having :order-by order-by
570 :inner-join inner-join :on on))))))
572 (defmethod output-sql ((query sql-query) database)
573 (with-slots (distinct selections from where group-by having order-by
574 limit offset inner-join on all set-operation)
577 (write-string "(" *sql-stream*))
578 (write-string "SELECT " *sql-stream*)
580 (write-string "ALL " *sql-stream*))
581 (when (and distinct (not all))
582 (write-string "DISTINCT " *sql-stream*)
583 (unless (eql t distinct)
584 (write-string "ON " *sql-stream*)
585 (output-sql distinct database)
586 (write-char #\Space *sql-stream*)))
587 (let ((*in-subselect* t))
588 (output-sql (apply #'vector selections) database))
590 (write-string " FROM " *sql-stream*)
591 (flet ((ident-table-equal (a b)
592 (and (if (and (eql (type-of a) 'sql-ident-table)
593 (eql (type-of b) 'sql-ident-table))
594 (string-equal (slot-value a 'alias)
595 (slot-value b 'alias))
597 (string-equal (sql-escape (slot-value a 'name))
598 (sql-escape (slot-value b 'name))))))
600 (list (output-sql (apply #'vector
601 (remove-duplicates from
602 :test #'ident-table-equal))
604 (string (format *sql-stream* "~s" (sql-escape from)))
605 (t (let ((*in-subselect* t))
606 (output-sql from database))))))
608 (write-string " INNER JOIN " *sql-stream*)
609 (output-sql inner-join database))
611 (write-string " ON " *sql-stream*)
612 (output-sql on database))
614 (write-string " WHERE " *sql-stream*)
615 (let ((*in-subselect* t))
616 (output-sql where database)))
618 (write-string " GROUP BY " *sql-stream*)
620 (do ((order group-by (cdr order)))
622 (let ((item (car order)))
625 (output-sql (car item) database)
626 (format *sql-stream* " ~A" (cadr item)))
628 (output-sql item database)))
630 (write-char #\, *sql-stream*))))
631 (output-sql group-by database)))
633 (write-string " HAVING " *sql-stream*)
634 (output-sql having database))
636 (write-string " ORDER BY " *sql-stream*)
638 (do ((order order-by (cdr order)))
640 (let ((item (car order)))
643 (output-sql (car item) database)
644 (format *sql-stream* " ~A" (cadr item)))
646 (output-sql item database)))
648 (write-char #\, *sql-stream*))))
649 (output-sql order-by database)))
651 (write-string " LIMIT " *sql-stream*)
652 (output-sql limit database))
654 (write-string " OFFSET " *sql-stream*)
655 (output-sql offset database))
657 (write-string ")" *sql-stream*))
659 (write-char #\Space *sql-stream*)
660 (output-sql set-operation database)))
663 (defmethod output-sql ((query sql-object-query) database)
664 (declare (ignore database))
665 (with-slots (objects)
668 (format *sql-stream* "(~{~A~^ ~})" objects))))
673 (defclass sql-insert (%sql-expression)
687 "An SQL INSERT statement."))
689 (defmethod output-sql ((ins sql-insert) database)
690 (with-slots (into attributes values query)
692 (write-string "INSERT INTO " *sql-stream*)
695 (string (sql-expression :table into))
699 (write-char #\Space *sql-stream*)
700 (output-sql attributes database))
702 (write-string " VALUES " *sql-stream*)
703 (output-sql values database))
705 (write-char #\Space *sql-stream*)
706 (output-sql query database)))
711 (defclass sql-delete (%sql-expression)
719 "An SQL DELETE statement."))
721 (defmethod output-sql ((stmt sql-delete) database)
722 (with-slots (from where)
724 (write-string "DELETE FROM " *sql-stream*)
726 ((or symbol string) (write-string (sql-escape from) *sql-stream*))
727 (t (output-sql from database)))
729 (write-string " WHERE " *sql-stream*)
730 (output-sql where database)))
735 (defclass sql-update (%sql-expression)
748 (:documentation "An SQL UPDATE statement."))
750 (defmethod output-sql ((expr sql-update) database)
751 (with-slots (table where attributes values)
753 (flet ((update-assignments ()
754 (mapcar #'(lambda (a b)
755 (make-instance 'sql-assignment-exp
757 :sub-expressions (list a b)))
759 (write-string "UPDATE " *sql-stream*)
760 (output-sql table database)
761 (write-string " SET " *sql-stream*)
762 (output-sql (apply #'vector (update-assignments)) database)
764 (write-string " WHERE " *sql-stream*)
765 (output-sql where database))))
770 (defclass sql-create-table (%sql-expression)
781 :initarg :transactions
784 "An SQL CREATE TABLE statement."))
786 ;; Here's a real warhorse of a function!
788 (declaim (inline listify))
794 (defmethod output-sql ((stmt sql-create-table) database)
795 (flet ((output-column (column-spec)
796 (destructuring-bind (name type &optional db-type &rest constraints)
798 (let ((type (listify type)))
799 (output-sql name database)
800 (write-char #\Space *sql-stream*)
802 (if (stringp db-type) db-type ; override definition
803 (database-get-type-specifier (car type) (cdr type) database
804 (database-underlying-type database)))
806 (let ((constraints (database-constraint-statement
807 (if (and db-type (symbolp db-type))
808 (cons db-type constraints)
812 (write-string " " *sql-stream*)
813 (write-string constraints *sql-stream*)))))))
814 (with-slots (name columns modifiers transactions)
816 (write-string "CREATE TABLE " *sql-stream*)
818 (string (format *sql-stream* "~s" (sql-escape name)))
819 (symbol (write-string (sql-escape name) *sql-stream*))
820 (sql-ident (output-sql name database)))
821 (write-string " (" *sql-stream*)
822 (do ((column columns (cdr column)))
824 (output-column (car column)))
825 (output-column (car column))
826 (write-string ", " *sql-stream*))
828 (do ((modifier (listify modifiers) (cdr modifier)))
830 (write-string ", " *sql-stream*)
831 (write-string (car modifier) *sql-stream*)))
832 (write-char #\) *sql-stream*)
833 (when (and (eq :mysql (database-underlying-type database))
835 (db-type-transaction-capable? :mysql database))
836 (write-string " Type=InnoDB" *sql-stream*))))
842 (defclass sql-create-view (%sql-expression)
843 ((name :initarg :name :initform nil)
844 (column-list :initarg :column-list :initform nil)
845 (query :initarg :query :initform nil)
846 (with-check-option :initarg :with-check-option :initform nil))
847 (:documentation "An SQL CREATE VIEW statement."))
849 (defmethod output-sql ((stmt sql-create-view) database)
850 (with-slots (name column-list query with-check-option) stmt
851 (write-string "CREATE VIEW " *sql-stream*)
852 (output-sql name database)
853 (when column-list (write-string " " *sql-stream*)
854 (output-sql (listify column-list) database))
855 (write-string " AS " *sql-stream*)
856 (output-sql query database)
857 (when with-check-option (write-string " WITH CHECK OPTION" *sql-stream*))))
861 ;; DATABASE-OUTPUT-SQL
864 (defmethod database-output-sql ((str string) database)
865 (declare (optimize (speed 3) (safety 1)
866 #+cmu (extensions:inhibit-warnings 3)))
867 (let ((len (length str)))
868 (declare (type fixnum len))
871 ((and (null (position #\' str))
872 (null (position #\\ str)))
873 (concatenate 'string "'" str "'"))
875 (let ((buf (make-string (+ (* len 2) 2) :initial-element #\')))
876 (declare (simple-string buf))
879 ((= i len) (subseq buf 0 (1+ j)))
880 (declare (type fixnum i j))
881 (let ((char (aref str i)))
882 (declare (character char))
883 (cond ((char= char #\')
884 (setf (aref buf j) #\')
886 (setf (aref buf j) #\'))
887 ((and (char= char #\\)
888 ;; MTP: only escape backslash with pgsql/mysql
889 (member (database-underlying-type database)
890 '(:postgresql :mysql)
892 (setf (aref buf j) #\\)
894 (setf (aref buf j) #\\))
896 (setf (aref buf j) char))))))))))
898 (let ((keyword-package (symbol-package :foo)))
899 (defmethod database-output-sql ((sym symbol) database)
902 (if (equal (symbol-package sym) keyword-package)
903 (concatenate 'string "'" (string sym) "'")
904 (symbol-name sym)))))
906 (defmethod database-output-sql ((tee (eql t)) database)
908 (let ((val (database-output-sql-as-type 'boolean t database (database-type database))))
911 (string (format nil "'~A'" val))
912 (integer (format nil "~A" val)))))
915 #+nil(defmethod database-output-sql ((tee (eql t)) database)
916 (declare (ignore database))
919 (defmethod database-output-sql ((num number) database)
920 (declare (ignore database))
921 (number-to-sql-string num))
923 (defmethod database-output-sql ((arg list) database)
926 (format nil "(~{~A~^,~})" (mapcar #'(lambda (val)
927 (sql-output val database))
930 (defmethod database-output-sql ((arg vector) database)
931 (format nil "~{~A~^,~}" (map 'list #'(lambda (val)
932 (sql-output val database))
935 (defmethod output-sql-hash-key ((arg vector) database)
936 (list 'vector (map 'list (lambda (arg)
937 (or (output-sql-hash-key arg database)
938 (return-from output-sql-hash-key nil)))
941 (defmethod database-output-sql ((self wall-time) database)
942 (declare (ignore database))
943 (db-timestring self))
945 (defmethod database-output-sql ((self date) database)
946 (declare (ignore database))
947 (db-datestring self))
949 (defmethod database-output-sql ((self duration) database)
950 (declare (ignore database))
951 (format nil "'~a'" (duration-timestring self)))
954 (defmethod database-output-sql ((self money) database)
955 (database-output-sql (slot-value self 'odcl::units) database))
957 (defmethod database-output-sql (thing database)
961 (error 'sql-user-error
964 "No type conversion to SQL for ~A is defined for DB ~A."
965 (type-of thing) (type-of database)))))
969 ;; Column constraint types and conversion to SQL
972 (defparameter *constraint-types*
974 (cons (symbol-name-default-case "NOT-NULL") "NOT NULL")
975 (cons (symbol-name-default-case "PRIMARY-KEY") "PRIMARY KEY")
976 (cons (symbol-name-default-case "NOT") "NOT")
977 (cons (symbol-name-default-case "NULL") "NULL")
978 (cons (symbol-name-default-case "PRIMARY") "PRIMARY")
979 (cons (symbol-name-default-case "KEY") "KEY")
980 (cons (symbol-name-default-case "UNSIGNED") "UNSIGNED")
981 (cons (symbol-name-default-case "ZEROFILL") "ZEROFILL")
982 (cons (symbol-name-default-case "AUTO-INCREMENT") "AUTO_INCREMENT")
983 (cons (symbol-name-default-case "UNIQUE") "UNIQUE")))
985 (defmethod database-constraint-statement (constraint-list database)
986 (declare (ignore database))
987 (make-constraints-description constraint-list))
989 (defun make-constraints-description (constraint-list)
992 (do ((constraint constraint-list (cdr constraint)))
993 ((null constraint) string)
994 (let ((output (assoc (symbol-name (car constraint))
998 (error 'sql-user-error
999 :message (format nil "unsupported column constraint '~A'"
1001 (setq string (concatenate 'string string (cdr output))))
1002 (if (< 1 (length constraint))
1003 (setq string (concatenate 'string string " "))))))))