X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=sql%2Fexpressions.lisp;h=ace360378f240fb47b0bf126466d2383b5412b5b;hp=cc2e53b20fcab7f189b85ebd14fdd9a937607a99;hb=d0b5c8c2a14929792d2d5818b57db27cae4484b2;hpb=e520ca44fbd7999a3185f34e68f656b954707993 diff --git a/sql/expressions.lisp b/sql/expressions.lisp index cc2e53b..ace3603 100644 --- a/sql/expressions.lisp +++ b/sql/expressions.lisp @@ -186,11 +186,6 @@ sql `(make-instance 'sql-ident-table :name ',name :table-alias ',alias))) -(defun generate-sql (expr database) - (let ((*sql-stream* (make-string-output-stream))) - (output-sql expr database) - (get-output-stream-string *sql-stream*))) - (defmethod output-sql ((expr sql-ident-table) database) (with-slots (name alias) expr @@ -583,10 +578,21 @@ uninclusive, and the args from that keyword to the end." (output-sql (apply #'vector selections) database) (when from (write-string " FROM " *sql-stream*) - (typecase from - (list (output-sql (apply #'vector from) database)) - (string (write-string from *sql-stream*)) - (t (output-sql from database)))) + (flet ((ident-table-equal (a b) + (and (if (and (eql (type-of a) 'sql-ident-table) + (eql (type-of b) 'sql-ident-table)) + (string-equal (slot-value a 'alias) + (slot-value b 'alias)) + t) + (string-equal (symbol-name (slot-value a 'name)) + (symbol-name (slot-value b 'name)))))) + (typecase from + (list (output-sql (apply #'vector + (remove-duplicates from + :test #'ident-table-equal)) + database)) + (string (write-string from *sql-stream*)) + (t (output-sql from database))))) (when inner-join (write-string " INNER JOIN " *sql-stream*) (output-sql inner-join database)) @@ -835,22 +841,14 @@ uninclusive, and the args from that keyword to the end." (cons (symbol-name-default-case "NOT") "NOT") (cons (symbol-name-default-case "NULL") "NULL") (cons (symbol-name-default-case "PRIMARY") "PRIMARY") - (cons (symbol-name-default-case "KEY") "KEY"))) + (cons (symbol-name-default-case "KEY") "KEY") + (cons (symbol-name-default-case "AUTO-INCREMENT") "AUTO_INCREMENT") + (cons (symbol-name-default-case "UNIQUE") "UNIQUE"))) ;; ;; Convert type spec to sql syntax ;; -(defmethod database-constraint-description (constraint database) - (declare (ignore database)) - (let ((output (assoc (symbol-name constraint) *constraint-types* - :test #'equal))) - (if (null output) - (error 'sql-user-error - :message (format nil "unsupported column constraint '~A'" - constraint)) - (cdr output)))) - (defmethod database-constraint-statement (constraint-list database) (declare (ignore database)) (make-constraints-description constraint-list))