r9450: 22 May 2004 Kevin Rosenberg
[clsql.git] / sql / classes.lisp
index 55801df9712ee977242ebff4433687b9b545ef31..6848621aa387c6436a22907ce5863c0b59589580 100644 (file)
            (call-next-method)))))
 
 (defmethod output-sql ((expr sql-ident) database)
-  (with-slots (name)
-      expr
+  (with-slots (name) expr
     (write-string
      (convert-to-db-default-case 
       (etypecase name
     :initform "NULL")
    (type
     :initarg :type
-    :initform "NULL")
-   (params
-    :initarg :params
-    :initform nil))
+    :initform "NULL"))
   (:documentation "An SQL Attribute identifier."))
 
 (defmethod collect-table-refs (sql)
       :type ',type)))
 
 (defmethod output-sql ((expr sql-ident-attribute) database)
-  (with-slots (qualifier name type params)
-      expr
+  (with-slots (qualifier name type) expr
     (if (and (not qualifier) (not type))
-       (write-string (sql-escape (convert-to-db-default-case 
-                                  (symbol-name name) database)) *sql-stream*)
+       (etypecase name
+         ;; Honor care of name
+         (string
+          (write-string name *sql-stream*))
+         (symbol
+          (write-string (sql-escape (convert-to-db-default-case 
+                                     (symbol-name name) database)) *sql-stream*)))
+      
        ;;; KMR: The TYPE field is used by CommonSQL for type conversion -- it
       ;;; should not be output in SQL statements
       #+ignore
 
 (defmethod output-sql-hash-key ((expr sql-ident-attribute) database)
   (declare (ignore database))
-  (with-slots (qualifier name type params)
+  (with-slots (qualifier name type)
     expr
-    (list 'sql-ident-attribute qualifier name type params)))
+    (list 'sql-ident-attribute qualifier name type)))
 
 ;; For SQL Identifiers for tables
 (defclass sql-ident-table (sql-ident)
@@ -584,9 +585,7 @@ uninclusive, and the args from that keyword to the end."
       (write-string " FROM " *sql-stream*)
       (typecase from 
         (list (output-sql (apply #'vector from) database))
-        (string (write-string 
-                 (sql-escape 
-                  (convert-to-db-default-case from database)) *sql-stream*))
+        (string (write-string from *sql-stream*))
         (t (output-sql from database))))
     (when inner-join
       (write-string " INNER JOIN " *sql-stream*)
@@ -768,10 +767,14 @@ uninclusive, and the args from that keyword to the end."
                (write-char #\Space *sql-stream*)
                (write-string
                 (if (stringp db-type) db-type ; override definition
-                    (database-get-type-specifier (car type) (cdr type) database))
+                 (database-get-type-specifier (car type) (cdr type) database
+                                              (database-underlying-type database)))
                 *sql-stream*)
-               (let ((constraints
-                      (database-constraint-statement constraints database)))
+               (let ((constraints (database-constraint-statement  
+                                   (if (and db-type (symbolp db-type))
+                                       (cons db-type constraints)
+                                       constraints)
+                                   database)))
                  (when constraints
                    (write-string " " *sql-stream*)
                    (write-string constraints *sql-stream*)))))))
@@ -824,7 +827,11 @@ uninclusive, and the args from that keyword to the end."
 (defparameter *constraint-types*
   (list 
    (cons (symbol-name-default-case "NOT-NULL") "NOT NULL") 
-   (cons (symbol-name-default-case "PRIMARY-KEY") "PRIMARY KEY")))
+   (cons (symbol-name-default-case "PRIMARY-KEY") "PRIMARY KEY")
+   (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")))
 
 ;;
 ;; Convert type spec to sql syntax