X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=sql%2Fexpressions.lisp;h=50aa5d1fd478942ec8dfdd6eebd15f6d1bb4d252;hp=de8124d40432645443244ba0ea79e8b5c3b90b23;hb=cb683851a0af33e88b7c4995435dc0cf226f6cba;hpb=e132f72fe34b078ca642ec99d1415f6b9511d598 diff --git a/sql/expressions.lisp b/sql/expressions.lisp index de8124d..50aa5d1 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 @@ -374,6 +369,7 @@ :test (lambda (tab1 tab2) (equal (slot-value tab1 'name) (slot-value tab2 'name)))))) +(defvar *in-subselect* nil) (defmethod output-sql ((expr sql-function-exp) database) (with-slots (name args) @@ -564,8 +560,6 @@ uninclusive, and the args from that keyword to the end." :group-by group-by :having having :order-by order-by :inner-join inner-join :on on)))))) -(defvar *in-subselect* nil) - (defmethod output-sql ((query sql-query) database) (with-slots (distinct selections from where group-by having order-by limit offset inner-join on all set-operation) @@ -584,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)) @@ -842,16 +847,6 @@ uninclusive, and the args from that keyword to the end." ;; 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))