1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
6 ;;;; Classes defining SQL expressions and methods for formatting the
7 ;;;; appropriate SQL commands.
9 ;;;; This file is part of CLSQL.
11 ;;;; CLSQL users are granted the rights to distribute and use this software
12 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
13 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
14 ;;;; *************************************************************************
16 (in-package #:clsql-sys)
18 (defvar +empty-string+ "''")
20 (defvar +null-string+ "NULL")
22 (defvar *sql-stream* nil
23 "stream which accumulates SQL output")
25 (defun sql-output (sql-expr &optional (database *default-database*))
26 "Top-level call for generating SQL strings. Returns an SQL
27 string appropriate for DATABASE which corresponds to the
28 supplied lisp expression SQL-EXPR."
29 (progv '(*sql-stream*)
30 `(,(make-string-output-stream))
31 (output-sql sql-expr database)
32 (get-output-stream-string *sql-stream*)))
34 (defmethod output-sql (expr database)
35 (write-string (database-output-sql expr database) *sql-stream*)
38 (defvar *output-hash* (make-hash-table :test #'equal)
39 "For caching generated SQL strings.")
41 (defmethod output-sql :around ((sql t) database)
42 (let* ((hash-key (output-sql-hash-key sql database))
43 (hash-value (when hash-key (gethash hash-key *output-hash*))))
44 (cond ((and hash-key hash-value)
45 (write-string hash-value *sql-stream*))
47 (let ((*sql-stream* (make-string-output-stream)))
49 (setf hash-value (get-output-stream-string *sql-stream*))
50 (setf (gethash hash-key *output-hash*) hash-value))
51 (write-string hash-value *sql-stream*))
53 (call-next-method)))))
55 (defmethod output-sql-hash-key (expr database)
56 (declare (ignore expr database))
60 (defclass %sql-expression ()
63 (defmethod output-sql ((expr %sql-expression) database)
64 (declare (ignore database))
65 (write-string +null-string+ *sql-stream*))
67 (defmethod print-object ((self %sql-expression) stream)
68 (print-unreadable-object
70 (write-string (sql-output self) stream))
73 ;; For straight up strings
75 (defclass sql (%sql-expression)
79 (:documentation "A literal SQL expression."))
81 (defmethod make-load-form ((sql sql) &optional environment)
82 (declare (ignore environment))
85 `(make-instance 'sql :string ',text)))
87 (defmethod output-sql ((expr sql) database)
88 (declare (ignore database))
89 (write-string (slot-value expr 'text) *sql-stream*)
92 (defmethod print-object ((ident sql) stream)
93 (format stream "#<~S \"~A\">"
95 (sql-output ident nil))
98 ;; For SQL Identifiers of generic type
100 (defclass sql-ident (%sql-expression)
103 :initform +null-string+))
104 (:documentation "An SQL identifer."))
106 (defmethod make-load-form ((sql sql-ident) &optional environment)
107 (declare (ignore environment))
110 `(make-instance 'sql-ident :name ',name)))
112 (defmethod output-sql ((expr sql-ident) database)
113 (with-slots (name) expr
117 (symbol (symbol-name name)))
121 ;; For SQL Identifiers for attributes
123 (defclass sql-ident-attribute (sql-ident)
126 :initform +null-string+)
129 :initform +null-string+))
130 (:documentation "An SQL Attribute identifier."))
132 (defmethod collect-table-refs (sql)
133 (declare (ignore sql))
136 (defmethod collect-table-refs ((sql sql-ident-attribute))
137 (let ((qual (slot-value sql 'qualifier)))
139 (list (make-instance 'sql-ident-table :name qual)))))
141 (defmethod make-load-form ((sql sql-ident-attribute) &optional environment)
142 (declare (ignore environment))
143 (with-slots (qualifier type name)
145 `(make-instance 'sql-ident-attribute :name ',name
146 :qualifier ',qualifier
149 (defmethod output-sql ((expr sql-ident-attribute) database)
150 (with-slots (qualifier name type) expr
151 (if (and (not qualifier) (not type))
154 (write-string name *sql-stream*))
157 (sql-escape (symbol-name name)) *sql-stream*)))
159 ;;; KMR: The TYPE field is used by CommonSQL for type conversion -- it
160 ;;; should not be output in SQL statements
162 (format *sql-stream* "~@[~A.~]~A~@[ ~A~]"
164 (sql-escape qualifier))
168 (format *sql-stream* "~@[~A.~]~A"
171 (string (format nil "~s" qualifier))
172 (t (sql-escape qualifier))))
174 (string (format nil "~s" (sql-escape name)))
175 (t (sql-escape name)))))
178 (defmethod output-sql-hash-key ((expr sql-ident-attribute) database)
179 (with-slots (qualifier name type)
181 (list (and database (database-underlying-type database))
182 'sql-ident-attribute qualifier name type)))
184 ;; For SQL Identifiers for tables
186 (defclass sql-ident-table (sql-ident)
188 :initarg :table-alias :initform nil))
189 (:documentation "An SQL table identifier."))
191 (defmethod make-load-form ((sql sql-ident-table) &optional environment)
192 (declare (ignore environment))
193 (with-slots (alias name)
195 `(make-instance 'sql-ident-table :name ',name :table-alias ',alias)))
197 (defmethod output-sql ((expr sql-ident-table) database)
198 (with-slots (name alias) expr
201 (format *sql-stream* "~s" (sql-escape name)))
203 (write-string (sql-escape name) *sql-stream*)))
205 (format *sql-stream* " ~s" alias)))
208 (defmethod output-sql-hash-key ((expr sql-ident-table) database)
209 (with-slots (name alias)
211 (list (and database (database-underlying-type database))
212 'sql-ident-table name alias)))
214 (defclass sql-relational-exp (%sql-expression)
219 :initarg :sub-expressions
221 (:documentation "An SQL relational expression."))
223 (defmethod make-load-form ((self sql-relational-exp) &optional environment)
224 (make-load-form-saving-slots self
225 :slot-names '(operator sub-expressions)
226 :environment environment))
228 (defmethod collect-table-refs ((sql sql-relational-exp))
230 (dolist (exp (slot-value sql 'sub-expressions))
231 (let ((refs (collect-table-refs exp)))
232 (if refs (setf tabs (append refs tabs)))))
233 (remove-duplicates tabs
234 :test (lambda (tab1 tab2)
235 (equal (slot-value tab1 'name)
236 (slot-value tab2 'name))))))
241 ;; Write SQL for relational operators (like 'AND' and 'OR').
242 ;; should do arity checking of subexpressions
244 (defmethod output-sql ((expr sql-relational-exp) database)
245 (with-slots (operator sub-expressions) expr
246 ;; we do this as two runs so as not to emit confusing superflous parentheses
247 ;; The first loop renders all the child outputs so that we can skip anding with
248 ;; empty output (which causes sql errors)
249 ;; the next loop simply emits each sub-expression with the appropriate number of
250 ;; parens and operators
252 (string-trim +whitespace-chars+
253 (with-output-to-string (*sql-stream*)
254 (output-sql sub database)))))
255 (let ((str-subs (loop for sub in sub-expressions
256 for str-sub = (trim sub)
257 when (and str-sub (> (length str-sub) 0))
259 (case (length str-subs)
261 (1 (write-string (first str-subs) *sql-stream*))
263 (write-char #\( *sql-stream*)
264 (write-string (first str-subs) *sql-stream*)
265 (loop for str-sub in (rest str-subs)
267 (write-char #\Space *sql-stream*)
268 (output-sql operator database)
269 (write-char #\Space *sql-stream*)
270 (write-string str-sub *sql-stream*))
271 (write-char #\) *sql-stream*))
275 (defclass sql-upcase-like (sql-relational-exp)
277 (:documentation "An SQL 'like' that upcases its arguments."))
279 (defmethod output-sql ((expr sql-upcase-like) database)
280 (flet ((write-term (term)
281 (write-string "upper(" *sql-stream*)
282 (output-sql term database)
283 (write-char #\) *sql-stream*)))
284 (with-slots (sub-expressions)
286 (let ((subs (if (consp (car sub-expressions))
287 (car sub-expressions)
289 (write-char #\( *sql-stream*)
290 (do ((sub subs (cdr sub)))
291 ((null (cdr sub)) (write-term (car sub)))
292 (write-term (car sub))
293 (write-string " LIKE " *sql-stream*))
294 (write-char #\) *sql-stream*))))
297 (defclass sql-assignment-exp (sql-relational-exp)
299 (:documentation "An SQL Assignment expression."))
302 (defmethod output-sql ((expr sql-assignment-exp) database)
303 (with-slots (operator sub-expressions)
305 (do ((sub sub-expressions (cdr sub)))
306 ((null (cdr sub)) (output-sql (car sub) database))
307 (output-sql (car sub) database)
308 (write-char #\Space *sql-stream*)
309 (output-sql operator database)
310 (write-char #\Space *sql-stream*)))
313 (defclass sql-value-exp (%sql-expression)
321 "An SQL value expression.")
324 (defmethod collect-table-refs ((sql sql-value-exp))
326 (if (listp (slot-value sql 'components))
328 (dolist (exp (slot-value sql 'components))
329 (let ((refs (collect-table-refs exp)))
330 (if refs (setf tabs (append refs tabs)))))
331 (remove-duplicates tabs
332 :test (lambda (tab1 tab2)
333 (equal (slot-value tab1 'name)
334 (slot-value tab2 'name)))))
339 (defmethod output-sql ((expr sql-value-exp) database)
340 (with-slots (modifier components)
344 (write-char #\( *sql-stream*)
345 (output-sql modifier database)
346 (write-char #\Space *sql-stream*)
347 (output-sql components database)
348 (write-char #\) *sql-stream*))
349 (output-sql components database))))
351 (defclass sql-typecast-exp (sql-value-exp)
353 (:documentation "An SQL typecast expression."))
355 (defmethod output-sql ((expr sql-typecast-exp) database)
356 (with-slots (components)
358 (output-sql components database)))
360 (defmethod collect-table-refs ((sql sql-typecast-exp))
361 (when (slot-value sql 'components)
362 (collect-table-refs (slot-value sql 'components))))
364 (defclass sql-function-exp (%sql-expression)
372 "An SQL function expression."))
374 (defmethod collect-table-refs ((sql sql-function-exp))
376 (dolist (exp (slot-value sql 'args))
377 (let ((refs (collect-table-refs exp)))
378 (if refs (setf tabs (append refs tabs)))))
379 (remove-duplicates tabs
380 :test (lambda (tab1 tab2)
381 (equal (slot-value tab1 'name)
382 (slot-value tab2 'name))))))
383 (defvar *in-subselect* nil)
385 (defmethod output-sql ((expr sql-function-exp) database)
386 (with-slots (name args)
388 (output-sql name database)
389 (let ((*in-subselect* nil)) ;; aboid double parens
390 (when args (output-sql args database))))
394 (defclass sql-between-exp (sql-function-exp)
396 (:documentation "An SQL between expression."))
398 (defmethod output-sql ((expr sql-between-exp) database)
401 (output-sql (first args) database)
402 (write-string " BETWEEN " *sql-stream*)
403 (output-sql (second args) database)
404 (write-string " AND " *sql-stream*)
405 (output-sql (third args) database))
408 (defclass sql-query-modifier-exp (%sql-expression)
409 ((modifier :initarg :modifier :initform nil)
410 (components :initarg :components :initform nil))
411 (:documentation "An SQL query modifier expression."))
413 (defmethod output-sql ((expr sql-query-modifier-exp) database)
414 (with-slots (modifier components)
416 (output-sql modifier database)
417 (write-string " " *sql-stream*)
418 (output-sql (car components) database)
420 (mapc #'(lambda (comp)
421 (write-string ", " *sql-stream*)
422 (output-sql comp database))
426 (defclass sql-set-exp (%sql-expression)
431 :initarg :sub-expressions
433 (:documentation "An SQL set expression."))
435 (defmethod collect-table-refs ((sql sql-set-exp))
437 (dolist (exp (slot-value sql 'sub-expressions))
438 (let ((refs (collect-table-refs exp)))
439 (if refs (setf tabs (append refs tabs)))))
440 (remove-duplicates tabs
441 :test (lambda (tab1 tab2)
442 (equal (slot-value tab1 'name)
443 (slot-value tab2 'name))))))
445 (defmethod output-sql ((expr sql-set-exp) database)
446 (with-slots (operator sub-expressions)
448 (let ((subs (if (consp (car sub-expressions))
449 (car sub-expressions)
451 (when (= (length subs) 1)
452 (output-sql operator database)
453 (write-char #\Space *sql-stream*))
454 (do ((sub subs (cdr sub)))
455 ((null (cdr sub)) (output-sql (car sub) database))
456 (output-sql (car sub) database)
457 (write-char #\Space *sql-stream*)
458 (output-sql operator database)
459 (write-char #\Space *sql-stream*))))
462 (defclass sql-query (%sql-expression)
473 :initarg :set-operation
505 (:documentation "An SQL SELECT query."))
507 (defclass sql-object-query (%sql-expression)
521 (defmethod collect-table-refs ((sql sql-query))
522 (remove-duplicates (collect-table-refs (slot-value sql 'where))
523 :test (lambda (tab1 tab2)
524 (equal (slot-value tab1 'name)
525 (slot-value tab2 'name)))))
527 (defvar *select-arguments*
528 '(:all :database :distinct :flatp :from :group-by :having :order-by
529 :set-operation :where :offset :limit :inner-join :on
530 ;; below keywords are not a SQL argument, but these keywords may terminate select
533 (defun query-arg-p (sym)
534 (member sym *select-arguments*))
536 (defun query-get-selections (select-args)
537 "Return two values: the list of select-args up to the first keyword,
538 uninclusive, and the args from that keyword to the end."
539 (let ((first-key-arg (position-if #'query-arg-p select-args)))
541 (values (subseq select-args 0 first-key-arg)
542 (subseq select-args first-key-arg))
545 (defun make-query (&rest args)
546 (flet ((select-objects (target-args)
548 (every #'(lambda (arg)
550 (find-class arg nil)))
552 (multiple-value-bind (selections arglist)
553 (query-get-selections args)
554 (if (select-objects selections)
555 (destructuring-bind (&key flatp refresh &allow-other-keys) arglist
556 (make-instance 'sql-object-query :objects selections
557 :flatp flatp :refresh refresh
559 (destructuring-bind (&key all flatp set-operation distinct from where
560 group-by having order-by
561 offset limit inner-join on &allow-other-keys)
563 (if (null selections)
564 (error "No target columns supplied to select statement."))
566 (error "No source tables supplied to select statement."))
567 (make-instance 'sql-query :selections selections
568 :all all :flatp flatp :set-operation set-operation
569 :distinct distinct :from from :where where
570 :limit limit :offset offset
571 :group-by group-by :having having :order-by order-by
572 :inner-join inner-join :on on))))))
574 (defmethod output-sql ((query sql-query) database)
575 (with-slots (distinct selections from where group-by having order-by
576 limit offset inner-join on all set-operation)
579 (write-string "(" *sql-stream*))
580 (write-string "SELECT " *sql-stream*)
582 (write-string "ALL " *sql-stream*))
583 (when (and distinct (not all))
584 (write-string "DISTINCT " *sql-stream*)
585 (unless (eql t distinct)
586 (write-string "ON " *sql-stream*)
587 (output-sql distinct database)
588 (write-char #\Space *sql-stream*)))
589 (let ((*in-subselect* t))
590 (output-sql (apply #'vector selections) database))
592 (write-string " FROM " *sql-stream*)
593 (flet ((ident-table-equal (a b)
594 (and (if (and (eql (type-of a) 'sql-ident-table)
595 (eql (type-of b) 'sql-ident-table))
596 (string-equal (slot-value a 'alias)
597 (slot-value b 'alias))
599 (string-equal (sql-escape (slot-value a 'name))
600 (sql-escape (slot-value b 'name))))))
602 (list (output-sql (apply #'vector
603 (remove-duplicates from
604 :test #'ident-table-equal))
606 (string (format *sql-stream* "~s" (sql-escape from)))
607 (t (let ((*in-subselect* t))
608 (output-sql from database))))))
610 (write-string " INNER JOIN " *sql-stream*)
611 (output-sql inner-join database))
613 (write-string " ON " *sql-stream*)
614 (output-sql on database))
616 (write-string " WHERE " *sql-stream*)
617 (let ((*in-subselect* t))
618 (output-sql where database)))
620 (write-string " GROUP BY " *sql-stream*)
622 (do ((order group-by (cdr order)))
624 (let ((item (car order)))
627 (output-sql (car item) database)
628 (format *sql-stream* " ~A" (cadr item)))
630 (output-sql item database)))
632 (write-char #\, *sql-stream*))))
633 (output-sql group-by database)))
635 (write-string " HAVING " *sql-stream*)
636 (output-sql having database))
638 (write-string " ORDER BY " *sql-stream*)
640 (do ((order order-by (cdr order)))
642 (let ((item (car order)))
645 (output-sql (car item) database)
646 (format *sql-stream* " ~A" (cadr item)))
648 (output-sql item database)))
650 (write-char #\, *sql-stream*))))
651 (output-sql order-by database)))
653 (write-string " LIMIT " *sql-stream*)
654 (output-sql limit database))
656 (write-string " OFFSET " *sql-stream*)
657 (output-sql offset database))
659 (write-string ")" *sql-stream*))
661 (write-char #\Space *sql-stream*)
662 (output-sql set-operation database)))
665 (defmethod output-sql ((query sql-object-query) database)
666 (declare (ignore database))
667 (with-slots (objects)
670 (format *sql-stream* "(~{~A~^ ~})" objects))))
675 (defclass sql-insert (%sql-expression)
689 "An SQL INSERT statement."))
691 (defmethod output-sql ((ins sql-insert) database)
692 (with-slots (into attributes values query)
694 (write-string "INSERT INTO " *sql-stream*)
697 (string (sql-expression :table into))
701 (write-char #\Space *sql-stream*)
702 (output-sql attributes database))
704 (write-string " VALUES " *sql-stream*)
705 (output-sql values database))
707 (write-char #\Space *sql-stream*)
708 (output-sql query database)))
713 (defclass sql-delete (%sql-expression)
721 "An SQL DELETE statement."))
723 (defmethod output-sql ((stmt sql-delete) database)
724 (with-slots (from where)
726 (write-string "DELETE FROM " *sql-stream*)
728 ((or symbol string) (write-string (sql-escape from) *sql-stream*))
729 (t (output-sql from database)))
731 (write-string " WHERE " *sql-stream*)
732 (output-sql where database)))
737 (defclass sql-update (%sql-expression)
750 (:documentation "An SQL UPDATE statement."))
752 (defmethod output-sql ((expr sql-update) database)
753 (with-slots (table where attributes values)
755 (flet ((update-assignments ()
756 (mapcar #'(lambda (a b)
757 (make-instance 'sql-assignment-exp
759 :sub-expressions (list a b)))
761 (write-string "UPDATE " *sql-stream*)
762 (output-sql table database)
763 (write-string " SET " *sql-stream*)
764 (output-sql (apply #'vector (update-assignments)) database)
766 (write-string " WHERE " *sql-stream*)
767 (output-sql where database))))
772 (defclass sql-create-table (%sql-expression)
783 :initarg :transactions
786 "An SQL CREATE TABLE statement."))
788 ;; Here's a real warhorse of a function!
790 (declaim (inline listify))
796 (defmethod output-sql ((stmt sql-create-table) database)
797 (flet ((output-column (column-spec)
798 (destructuring-bind (name type &optional db-type &rest constraints)
800 (let ((type (listify type)))
801 (output-sql name database)
802 (write-char #\Space *sql-stream*)
804 (if (stringp db-type) db-type ; override definition
805 (database-get-type-specifier (car type) (cdr type) database
806 (database-underlying-type database)))
808 (let ((constraints (database-constraint-statement
809 (if (and db-type (symbolp db-type))
810 (cons db-type constraints)
814 (write-string " " *sql-stream*)
815 (write-string constraints *sql-stream*)))))))
816 (with-slots (name columns modifiers transactions)
818 (write-string "CREATE TABLE " *sql-stream*)
820 (string (format *sql-stream* "~s" (sql-escape name)))
821 (symbol (write-string (sql-escape name) *sql-stream*))
822 (sql-ident (output-sql name database)))
823 (write-string " (" *sql-stream*)
824 (do ((column columns (cdr column)))
826 (output-column (car column)))
827 (output-column (car column))
828 (write-string ", " *sql-stream*))
830 (do ((modifier (listify modifiers) (cdr modifier)))
832 (write-string ", " *sql-stream*)
833 (write-string (car modifier) *sql-stream*)))
834 (write-char #\) *sql-stream*)
835 (when (and (eq :mysql (database-underlying-type database))
837 (db-type-transaction-capable? :mysql database))
838 (write-string " Type=InnoDB" *sql-stream*))))
844 (defclass sql-create-view (%sql-expression)
845 ((name :initarg :name :initform nil)
846 (column-list :initarg :column-list :initform nil)
847 (query :initarg :query :initform nil)
848 (with-check-option :initarg :with-check-option :initform nil))
849 (:documentation "An SQL CREATE VIEW statement."))
851 (defmethod output-sql ((stmt sql-create-view) database)
852 (with-slots (name column-list query with-check-option) stmt
853 (write-string "CREATE VIEW " *sql-stream*)
854 (output-sql name database)
855 (when column-list (write-string " " *sql-stream*)
856 (output-sql (listify column-list) database))
857 (write-string " AS " *sql-stream*)
858 (output-sql query database)
859 (when with-check-option (write-string " WITH CHECK OPTION" *sql-stream*))))
863 ;; DATABASE-OUTPUT-SQL
866 (defmethod database-output-sql ((str string) database)
867 (declare (optimize (speed 3) (safety 1)
868 #+cmu (extensions:inhibit-warnings 3)))
869 (let ((len (length str)))
870 (declare (type fixnum len))
873 ((and (null (position #\' str))
874 (null (position #\\ str)))
875 (concatenate 'string "'" str "'"))
877 (let ((buf (make-string (+ (* len 2) 2) :initial-element #\')))
878 (declare (simple-string buf))
881 ((= i len) (subseq buf 0 (1+ j)))
882 (declare (type fixnum i j))
883 (let ((char (aref str i)))
884 (declare (character char))
885 (cond ((char= char #\')
886 (setf (aref buf j) #\')
888 (setf (aref buf j) #\'))
889 ((and (char= char #\\)
890 ;; MTP: only escape backslash with pgsql/mysql
891 (member (database-underlying-type database)
892 '(:postgresql :mysql)
894 (setf (aref buf j) #\\)
896 (setf (aref buf j) #\\))
898 (setf (aref buf j) char))))))))))
900 (let ((keyword-package (symbol-package :foo)))
901 (defmethod database-output-sql ((sym symbol) database)
904 (if (equal (symbol-package sym) keyword-package)
905 (concatenate 'string "'" (string sym) "'")
906 (symbol-name sym)))))
908 (defmethod database-output-sql ((tee (eql t)) database)
910 (let ((val (database-output-sql-as-type 'boolean t database (database-type database))))
913 (string (format nil "'~A'" val))
914 (integer (format nil "~A" val)))))
917 #+nil(defmethod database-output-sql ((tee (eql t)) database)
918 (declare (ignore database))
921 (defmethod database-output-sql ((num number) database)
922 (declare (ignore database))
923 (number-to-sql-string num))
925 (defmethod database-output-sql ((arg list) database)
928 (format nil "(~{~A~^,~})" (mapcar #'(lambda (val)
929 (sql-output val database))
932 (defmethod database-output-sql ((arg vector) database)
933 (format nil "~{~A~^,~}" (map 'list #'(lambda (val)
934 (sql-output val database))
937 (defmethod output-sql-hash-key ((arg vector) database)
938 (list 'vector (map 'list (lambda (arg)
939 (or (output-sql-hash-key arg database)
940 (return-from output-sql-hash-key nil)))
943 (defmethod database-output-sql ((self wall-time) database)
944 (declare (ignore database))
945 (db-timestring self))
947 (defmethod database-output-sql ((self date) database)
948 (declare (ignore database))
949 (db-datestring self))
951 (defmethod database-output-sql ((self duration) database)
952 (declare (ignore database))
953 (format nil "'~a'" (duration-timestring self)))
956 (defmethod database-output-sql ((self money) database)
957 (database-output-sql (slot-value self 'odcl::units) database))
959 (defmethod database-output-sql (thing database)
963 (error 'sql-user-error
966 "No type conversion to SQL for ~A is defined for DB ~A."
967 (type-of thing) (type-of database)))))
971 ;; Column constraint types and conversion to SQL
974 (defparameter *constraint-types*
976 (cons (symbol-name-default-case "NOT-NULL") "NOT NULL")
977 (cons (symbol-name-default-case "PRIMARY-KEY") "PRIMARY KEY")
978 (cons (symbol-name-default-case "NOT") "NOT")
979 (cons (symbol-name-default-case "NULL") "NULL")
980 (cons (symbol-name-default-case "PRIMARY") "PRIMARY")
981 (cons (symbol-name-default-case "KEY") "KEY")
982 (cons (symbol-name-default-case "UNSIGNED") "UNSIGNED")
983 (cons (symbol-name-default-case "ZEROFILL") "ZEROFILL")
984 (cons (symbol-name-default-case "AUTO-INCREMENT") "AUTO_INCREMENT")
985 (cons (symbol-name-default-case "UNIQUE") "UNIQUE")))
987 (defmethod database-constraint-statement (constraint-list database)
988 (declare (ignore database))
989 (make-constraints-description constraint-list))
991 (defun make-constraints-description (constraint-list)
994 (do ((constraint constraint-list (cdr constraint)))
995 ((null constraint) string)
996 (let ((output (assoc (symbol-name (car constraint))
1000 (error 'sql-user-error
1001 :message (format nil "unsupported column constraint '~A'"
1003 (setq string (concatenate 'string string (cdr output))))
1004 (if (< 1 (length constraint))
1005 (setq string (concatenate 'string string " "))))))))