r9736: fix bug preventing the :DB-CONSTRAINTS View Class slot option accepting a...
[clsql.git] / sql / expressions.lisp
index 10b1130aa11dd81f38a0dc5199bfa3788c9a5f74..ace360378f240fb47b0bf126466d2383b5412b5b 100644 (file)
@@ -578,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))
@@ -830,7 +841,9 @@ 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