r9615: * sql/expressions.lisp: Avoid duplicate FROM names when selecting
[clsql.git] / sql / expressions.lisp
index cc2e53b20fcab7f189b85ebd14fdd9a937607a99..f2d63c9c85c47e9dd810bce8dff46480291692d8 100644 (file)
     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
@@ -584,7 +579,12 @@ uninclusive, and the args from that keyword to the end."
     (when from
       (write-string " FROM " *sql-stream*)
       (typecase from 
-        (list (output-sql (apply #'vector from) database))
+        (list (output-sql (apply #'vector (remove-duplicates 
+                                          from 
+                                          :test #'(lambda (a b)
+                                                    (string-equal (symbol-name (slot-value a 'name))
+                                                                  (symbol-name (slot-value b 'name))))))
+                         database))
         (string (write-string from *sql-stream*))
         (t (output-sql from database))))
     (when inner-join
@@ -841,16 +841,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))