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)
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)))
72 ;; For straight up strings
74 (defclass sql (%sql-expression)
78 (:documentation "A literal SQL expression."))
80 (defmethod make-load-form ((sql sql) &optional environment)
81 (declare (ignore environment))
84 `(make-instance 'sql :string ',text)))
86 (defmethod output-sql ((expr sql) database)
87 (declare (ignore database))
88 (write-string (slot-value expr 'text) *sql-stream*)
91 (defmethod print-object ((ident sql) stream)
92 (format stream "#<~S \"~A\">"
94 (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
113 (convert-to-db-default-case
116 (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)))
138 (if (and qual (symbolp (slot-value sql 'qualifier)))
139 (list (make-instance 'sql-ident-table :name
140 (slot-value sql 'qualifier))))))
142 (defmethod make-load-form ((sql sql-ident-attribute) &optional environment)
143 (declare (ignore environment))
144 (with-slots (qualifier type name)
146 `(make-instance 'sql-ident-attribute :name ',name
147 :qualifier ',qualifier
150 (defmethod output-sql ((expr sql-ident-attribute) database)
151 (with-slots (qualifier name type) expr
152 (if (and (not qualifier) (not type))
154 ;; Honor care of name
156 (write-string name *sql-stream*))
158 (write-string (sql-escape (convert-to-db-default-case
159 (symbol-name name) database)) *sql-stream*)))
161 ;;; KMR: The TYPE field is used by CommonSQL for type conversion -- it
162 ;;; should not be output in SQL statements
164 (format *sql-stream* "~@[~A.~]~A~@[ ~A~]"
166 (convert-to-db-default-case (sql-escape qualifier) database))
167 (sql-escape (convert-to-db-default-case name database))
169 (convert-to-db-default-case (symbol-name type) database)))
170 (format *sql-stream* "~@[~A.~]~A"
173 (string (format nil "~s" qualifier))
174 (t (convert-to-db-default-case (sql-escape qualifier)
176 (sql-escape (convert-to-db-default-case name database))))
179 (defmethod output-sql-hash-key ((expr sql-ident-attribute) database)
180 (with-slots (qualifier name type)
182 (list (and database (database-underlying-type database))
183 'sql-ident-attribute qualifier name type)))
185 ;; For SQL Identifiers for tables
187 (defclass sql-ident-table (sql-ident)
189 :initarg :table-alias :initform nil))
190 (:documentation "An SQL table identifier."))
192 (defmethod make-load-form ((sql sql-ident-table) &optional environment)
193 (declare (ignore environment))
194 (with-slots (alias name)
196 `(make-instance 'sql-ident-table :name ',name :table-alias ',alias)))
198 (defmethod output-sql ((expr sql-ident-table) database)
199 (with-slots (name alias)
202 (write-string (sql-escape (convert-to-db-default-case (symbol-name name) database)) *sql-stream*)
204 (write-string (sql-escape (convert-to-db-default-case (symbol-name name) database)) *sql-stream*)
205 (write-char #\Space *sql-stream*)
206 (format *sql-stream* "~s" alias))))
209 (defmethod output-sql-hash-key ((expr sql-ident-table) database)
210 (with-slots (name alias)
212 (list (and database (database-underlying-type database))
213 'sql-ident-table name alias)))
215 (defclass sql-relational-exp (%sql-expression)
220 :initarg :sub-expressions
222 (:documentation "An SQL relational expression."))
224 (defmethod collect-table-refs ((sql sql-relational-exp))
226 (dolist (exp (slot-value sql 'sub-expressions))
227 (let ((refs (collect-table-refs exp)))
228 (if refs (setf tabs (append refs tabs)))))
229 (remove-duplicates tabs
230 :test (lambda (tab1 tab2)
231 (equal (slot-value tab1 'name)
232 (slot-value tab2 'name))))))
237 ;; Write SQL for relational operators (like 'AND' and 'OR').
238 ;; should do arity checking of subexpressions
240 (defmethod output-sql ((expr sql-relational-exp) database)
241 (with-slots (operator sub-expressions)
243 (let ((subs (if (consp (car sub-expressions))
244 (car sub-expressions)
246 (write-char #\( *sql-stream*)
247 (do ((sub subs (cdr sub)))
248 ((null (cdr sub)) (output-sql (car sub) database))
249 (output-sql (car sub) database)
250 (write-char #\Space *sql-stream*)
251 (output-sql operator database)
252 (write-char #\Space *sql-stream*))
253 (write-char #\) *sql-stream*)))
256 (defclass sql-upcase-like (sql-relational-exp)
258 (:documentation "An SQL 'like' that upcases its arguments."))
260 (defmethod output-sql ((expr sql-upcase-like) database)
261 (flet ((write-term (term)
262 (write-string "upper(" *sql-stream*)
263 (output-sql term database)
264 (write-char #\) *sql-stream*)))
265 (with-slots (sub-expressions)
267 (let ((subs (if (consp (car sub-expressions))
268 (car sub-expressions)
270 (write-char #\( *sql-stream*)
271 (do ((sub subs (cdr sub)))
272 ((null (cdr sub)) (write-term (car sub)))
273 (write-term (car sub))
274 (write-string " LIKE " *sql-stream*))
275 (write-char #\) *sql-stream*))))
278 (defclass sql-assignment-exp (sql-relational-exp)
280 (:documentation "An SQL Assignment expression."))
283 (defmethod output-sql ((expr sql-assignment-exp) database)
284 (with-slots (operator sub-expressions)
286 (do ((sub sub-expressions (cdr sub)))
287 ((null (cdr sub)) (output-sql (car sub) database))
288 (output-sql (car sub) database)
289 (write-char #\Space *sql-stream*)
290 (output-sql operator database)
291 (write-char #\Space *sql-stream*)))
294 (defclass sql-value-exp (%sql-expression)
302 "An SQL value expression.")
305 (defmethod collect-table-refs ((sql sql-value-exp))
307 (if (listp (slot-value sql 'components))
309 (dolist (exp (slot-value sql 'components))
310 (let ((refs (collect-table-refs exp)))
311 (if refs (setf tabs (append refs tabs)))))
312 (remove-duplicates tabs
313 :test (lambda (tab1 tab2)
314 (equal (slot-value tab1 'name)
315 (slot-value tab2 'name)))))
320 (defmethod output-sql ((expr sql-value-exp) database)
321 (with-slots (modifier components)
325 (write-char #\( *sql-stream*)
326 (output-sql modifier database)
327 (write-char #\Space *sql-stream*)
328 (output-sql components database)
329 (write-char #\) *sql-stream*))
330 (output-sql components database))))
332 (defclass sql-typecast-exp (sql-value-exp)
334 (:documentation "An SQL typecast expression."))
336 (defmethod output-sql ((expr sql-typecast-exp) database)
337 (with-slots (components)
339 (output-sql components database)))
341 (defmethod collect-table-refs ((sql sql-typecast-exp))
342 (when (slot-value sql 'components)
343 (collect-table-refs (slot-value sql 'components))))
345 (defclass sql-function-exp (%sql-expression)
353 "An SQL function expression."))
355 (defmethod collect-table-refs ((sql sql-function-exp))
357 (dolist (exp (slot-value sql 'components))
358 (let ((refs (collect-table-refs exp)))
359 (if refs (setf tabs (append refs tabs)))))
360 (remove-duplicates tabs
361 :test (lambda (tab1 tab2)
362 (equal (slot-value tab1 'name)
363 (slot-value tab2 'name))))))
364 (defvar *in-subselect* nil)
366 (defmethod output-sql ((expr sql-function-exp) database)
367 (with-slots (name args)
369 (output-sql name database)
370 (let ((*in-subselect* nil)) ;; aboid double parens
371 (when args (output-sql args database))))
375 (defclass sql-between-exp (sql-function-exp)
377 (:documentation "An SQL between expression."))
379 (defmethod output-sql ((expr sql-between-exp) database)
380 (with-slots (name args)
382 (output-sql (first args) database)
383 (write-string " BETWEEN " *sql-stream*)
384 (output-sql (second args) database)
385 (write-string " AND " *sql-stream*)
386 (output-sql (third args) database))
389 (defclass sql-query-modifier-exp (%sql-expression)
390 ((modifier :initarg :modifier :initform nil)
391 (components :initarg :components :initform nil))
392 (:documentation "An SQL query modifier expression."))
394 (defmethod output-sql ((expr sql-query-modifier-exp) database)
395 (with-slots (modifier components)
397 (output-sql modifier database)
398 (write-string " " *sql-stream*)
399 (output-sql (car components) database)
401 (mapc #'(lambda (comp)
402 (write-string ", " *sql-stream*)
403 (output-sql comp database))
407 (defclass sql-set-exp (%sql-expression)
412 :initarg :sub-expressions
414 (:documentation "An SQL set expression."))
416 (defmethod collect-table-refs ((sql sql-set-exp))
418 (dolist (exp (slot-value sql 'sub-expressions))
419 (let ((refs (collect-table-refs exp)))
420 (if refs (setf tabs (append refs tabs)))))
421 (remove-duplicates tabs
422 :test (lambda (tab1 tab2)
423 (equal (slot-value tab1 'name)
424 (slot-value tab2 'name))))))
426 (defmethod output-sql ((expr sql-set-exp) database)
427 (with-slots (operator sub-expressions)
429 (let ((subs (if (consp (car sub-expressions))
430 (car sub-expressions)
432 (when (= (length subs) 1)
433 (output-sql operator database)
434 (write-char #\Space *sql-stream*))
435 (do ((sub subs (cdr sub)))
436 ((null (cdr sub)) (output-sql (car sub) database))
437 (output-sql (car sub) database)
438 (write-char #\Space *sql-stream*)
439 (output-sql operator database)
440 (write-char #\Space *sql-stream*))))
443 (defclass sql-query (%sql-expression)
454 :initarg :set-operation
486 (:documentation "An SQL SELECT query."))
488 (defclass sql-object-query (%sql-expression)
502 (defmethod collect-table-refs ((sql sql-query))
503 (remove-duplicates (collect-table-refs (slot-value sql 'where))
504 :test (lambda (tab1 tab2)
505 (equal (slot-value tab1 'name)
506 (slot-value tab2 'name)))))
508 (defvar *select-arguments*
509 '(:all :database :distinct :flatp :from :group-by :having :order-by
510 :set-operation :where :offset :limit :inner-join :on
511 ;; below keywords are not a SQL argument, but these keywords may terminate select
514 (defun query-arg-p (sym)
515 (member sym *select-arguments*))
517 (defun query-get-selections (select-args)
518 "Return two values: the list of select-args up to the first keyword,
519 uninclusive, and the args from that keyword to the end."
520 (let ((first-key-arg (position-if #'query-arg-p select-args)))
522 (values (subseq select-args 0 first-key-arg)
523 (subseq select-args first-key-arg))
526 (defun make-query (&rest args)
527 (flet ((select-objects (target-args)
529 (every #'(lambda (arg)
531 (find-class arg nil)))
533 (multiple-value-bind (selections arglist)
534 (query-get-selections args)
535 (if (select-objects selections)
536 (destructuring-bind (&key flatp refresh &allow-other-keys) arglist
537 (make-instance 'sql-object-query :objects selections
538 :flatp flatp :refresh refresh
540 (destructuring-bind (&key all flatp set-operation distinct from where
541 group-by having order-by
542 offset limit inner-join on &allow-other-keys)
544 (if (null selections)
545 (error "No target columns supplied to select statement."))
547 (error "No source tables supplied to select statement."))
548 (make-instance 'sql-query :selections selections
549 :all all :flatp flatp :set-operation set-operation
550 :distinct distinct :from from :where where
551 :limit limit :offset offset
552 :group-by group-by :having having :order-by order-by
553 :inner-join inner-join :on on))))))
555 (defmethod output-sql ((query sql-query) database)
556 (with-slots (distinct selections from where group-by having order-by
557 limit offset inner-join on all set-operation)
560 (write-string "(" *sql-stream*))
561 (write-string "SELECT " *sql-stream*)
563 (write-string "ALL " *sql-stream*))
564 (when (and distinct (not all))
565 (write-string "DISTINCT " *sql-stream*)
566 (unless (eql t distinct)
567 (write-string "ON " *sql-stream*)
568 (output-sql distinct database)
569 (write-char #\Space *sql-stream*)))
570 (output-sql (apply #'vector selections) database)
572 (write-string " FROM " *sql-stream*)
573 (flet ((ident-table-equal (a b)
574 (and (if (and (eql (type-of a) 'sql-ident-table)
575 (eql (type-of b) 'sql-ident-table))
576 (string-equal (slot-value a 'alias)
577 (slot-value b 'alias))
579 (string-equal (symbol-name (slot-value a 'name))
580 (symbol-name (slot-value b 'name))))))
582 (list (output-sql (apply #'vector
583 (remove-duplicates from
584 :test #'ident-table-equal))
586 (string (write-string from *sql-stream*))
587 (t (output-sql from database)))))
589 (write-string " INNER JOIN " *sql-stream*)
590 (output-sql inner-join database))
592 (write-string " ON " *sql-stream*)
593 (output-sql on database))
595 (write-string " WHERE " *sql-stream*)
596 (let ((*in-subselect* t))
597 (output-sql where database)))
599 (write-string " GROUP BY " *sql-stream*)
600 (output-sql group-by database))
602 (write-string " HAVING " *sql-stream*)
603 (output-sql having database))
605 (write-string " ORDER BY " *sql-stream*)
607 (do ((order order-by (cdr order)))
609 (let ((item (car order)))
612 (output-sql (car item) database)
613 (format *sql-stream* " ~A" (cadr item)))
615 (output-sql item database)))
617 (write-char #\, *sql-stream*))))
618 (output-sql order-by database)))
620 (write-string " LIMIT " *sql-stream*)
621 (output-sql limit database))
623 (write-string " OFFSET " *sql-stream*)
624 (output-sql offset database))
626 (write-string ")" *sql-stream*))
628 (write-char #\Space *sql-stream*)
629 (output-sql set-operation database)))
632 (defmethod output-sql ((query sql-object-query) database)
633 (declare (ignore database))
634 (with-slots (objects)
637 (format *sql-stream* "(~{~A~^ ~})" objects))))
642 (defclass sql-insert (%sql-expression)
656 "An SQL INSERT statement."))
658 (defmethod output-sql ((ins sql-insert) database)
659 (with-slots (into attributes values query)
661 (write-string "INSERT INTO " *sql-stream*)
664 (string (sql-expression :attribute into))
668 (write-char #\Space *sql-stream*)
669 (output-sql attributes database))
671 (write-string " VALUES " *sql-stream*)
672 (output-sql values database))
674 (write-char #\Space *sql-stream*)
675 (output-sql query database)))
680 (defclass sql-delete (%sql-expression)
688 "An SQL DELETE statement."))
690 (defmethod output-sql ((stmt sql-delete) database)
691 (with-slots (from where)
693 (write-string "DELETE FROM " *sql-stream*)
695 (symbol (write-string (sql-escape from) *sql-stream*))
696 (t (output-sql from database)))
698 (write-string " WHERE " *sql-stream*)
699 (output-sql where database)))
704 (defclass sql-update (%sql-expression)
717 (:documentation "An SQL UPDATE statement."))
719 (defmethod output-sql ((expr sql-update) database)
720 (with-slots (table where attributes values)
722 (flet ((update-assignments ()
723 (mapcar #'(lambda (a b)
724 (make-instance 'sql-assignment-exp
726 :sub-expressions (list a b)))
728 (write-string "UPDATE " *sql-stream*)
729 (output-sql table database)
730 (write-string " SET " *sql-stream*)
731 (output-sql (apply #'vector (update-assignments)) database)
733 (write-string " WHERE " *sql-stream*)
734 (output-sql where database))))
739 (defclass sql-create-table (%sql-expression)
750 :initarg :transactions
753 "An SQL CREATE TABLE statement."))
755 ;; Here's a real warhorse of a function!
757 (declaim (inline listify))
763 (defmethod output-sql ((stmt sql-create-table) database)
764 (flet ((output-column (column-spec)
765 (destructuring-bind (name type &optional db-type &rest constraints)
767 (let ((type (listify type)))
768 (output-sql name database)
769 (write-char #\Space *sql-stream*)
771 (if (stringp db-type) db-type ; override definition
772 (database-get-type-specifier (car type) (cdr type) database
773 (database-underlying-type database)))
775 (let ((constraints (database-constraint-statement
776 (if (and db-type (symbolp db-type))
777 (cons db-type constraints)
781 (write-string " " *sql-stream*)
782 (write-string constraints *sql-stream*)))))))
783 (with-slots (name columns modifiers transactions)
785 (write-string "CREATE TABLE " *sql-stream*)
786 (output-sql name database)
787 (write-string " (" *sql-stream*)
788 (do ((column columns (cdr column)))
790 (output-column (car column)))
791 (output-column (car column))
792 (write-string ", " *sql-stream*))
794 (do ((modifier (listify modifiers) (cdr modifier)))
796 (write-string ", " *sql-stream*)
797 (write-string (car modifier) *sql-stream*)))
798 (write-char #\) *sql-stream*)
799 (when (and (eq :mysql (database-underlying-type database))
801 (db-type-transaction-capable? :mysql database))
802 (write-string " Type=InnoDB" *sql-stream*))))
808 (defclass sql-create-view (%sql-expression)
809 ((name :initarg :name :initform nil)
810 (column-list :initarg :column-list :initform nil)
811 (query :initarg :query :initform nil)
812 (with-check-option :initarg :with-check-option :initform nil))
813 (:documentation "An SQL CREATE VIEW statement."))
815 (defmethod output-sql ((stmt sql-create-view) database)
816 (with-slots (name column-list query with-check-option) stmt
817 (write-string "CREATE VIEW " *sql-stream*)
818 (output-sql name database)
819 (when column-list (write-string " " *sql-stream*)
820 (output-sql (listify column-list) database))
821 (write-string " AS " *sql-stream*)
822 (output-sql query database)
823 (when with-check-option (write-string " WITH CHECK OPTION" *sql-stream*))))
827 ;; DATABASE-OUTPUT-SQL
830 (defmethod database-output-sql ((str string) database)
831 (declare (ignore database)
832 (optimize (speed 3) (safety 1) #+cmu (extensions:inhibit-warnings 3))
833 (type (simple-array * (*)) str))
834 (let ((len (length str)))
835 (declare (type fixnum len))
838 ((and (null (position #\' str))
839 (null (position #\\ str)))
840 (concatenate 'string "'" str "'"))
842 (let ((buf (make-string (+ (* len 2) 2) :initial-element #\')))
845 ((= i len) (subseq buf 0 (1+ j)))
846 (declare (type fixnum i j))
847 (let ((char (aref str i)))
848 (declare (character char))
849 (cond ((char= char #\')
850 (setf (aref buf j) #\')
852 (setf (aref buf j) #\'))
853 ((and (char= char #\\)
854 ;; MTP: only escape backslash with pgsql/mysql
855 (member (database-underlying-type database)
856 '(:postgresql :mysql)
858 (setf (aref buf j) #\\)
860 (setf (aref buf j) #\\))
862 (setf (aref buf j) char))))))))))
864 (let ((keyword-package (symbol-package :foo)))
865 (defmethod database-output-sql ((sym symbol) database)
868 (convert-to-db-default-case
869 (if (equal (symbol-package sym) keyword-package)
870 (concatenate 'string "'" (string sym) "'")
874 (defmethod database-output-sql ((tee (eql t)) database)
875 (declare (ignore database))
878 (defmethod database-output-sql ((num number) database)
879 (declare (ignore database))
880 (princ-to-string num))
882 (defmethod database-output-sql ((arg list) database)
885 (format nil "(~{~A~^,~})" (mapcar #'(lambda (val)
886 (sql-output val database))
889 (defmethod database-output-sql ((arg vector) database)
890 (format nil "~{~A~^,~}" (map 'list #'(lambda (val)
891 (sql-output val database))
894 (defmethod output-sql-hash-key ((arg vector) database)
895 (list 'vector (map 'list (lambda (arg)
896 (or (output-sql-hash-key arg database)
897 (return-from output-sql-hash-key nil)))
900 (defmethod database-output-sql ((self wall-time) database)
901 (declare (ignore database))
902 (db-timestring self))
904 (defmethod database-output-sql ((self duration) database)
905 (declare (ignore database))
906 (format nil "'~a'" (duration-timestring self)))
909 (defmethod database-output-sql ((self money) database)
910 (database-output-sql (slot-value self 'odcl::units) database))
912 (defmethod database-output-sql (thing database)
916 (error 'sql-user-error
919 "No type conversion to SQL for ~A is defined for DB ~A."
920 (type-of thing) (type-of database)))))
924 ;; Column constraint types and conversion to SQL
927 (defparameter *constraint-types*
929 (cons (symbol-name-default-case "NOT-NULL") "NOT NULL")
930 (cons (symbol-name-default-case "PRIMARY-KEY") "PRIMARY KEY")
931 (cons (symbol-name-default-case "NOT") "NOT")
932 (cons (symbol-name-default-case "NULL") "NULL")
933 (cons (symbol-name-default-case "PRIMARY") "PRIMARY")
934 (cons (symbol-name-default-case "KEY") "KEY")
935 (cons (symbol-name-default-case "UNSIGNED") "UNSIGNED")
936 (cons (symbol-name-default-case "ZEROFILL") "ZEROFILL")
937 (cons (symbol-name-default-case "AUTO-INCREMENT") "AUTO_INCREMENT")
938 (cons (symbol-name-default-case "UNIQUE") "UNIQUE")))
940 (defmethod database-constraint-statement (constraint-list database)
941 (declare (ignore database))
942 (make-constraints-description constraint-list))
944 (defun make-constraints-description (constraint-list)
947 (do ((constraint constraint-list (cdr constraint)))
948 ((null constraint) string)
949 (let ((output (assoc (symbol-name (car constraint))
953 (error 'sql-user-error
954 :message (format nil "unsupported column constraint '~A'"
956 (setq string (concatenate 'string string (cdr output))))
957 (if (< 1 (length constraint))
958 (setq string (concatenate 'string string " "))))))))