made clsql emit double quoted table names
[clsql.git] / sql / expressions.lisp
index 971609e2e68eee3cc2f171f24800cda10c77d71d..80fffc5277f66d8c8673abc4f56d99d694032508 100644 (file)
     `(make-instance 'sql-ident :name ',name)))
 
 (defmethod output-sql ((expr sql-ident) database)
+  
   (with-slots (name) expr
     (write-string
      (etypecase name
               (when qualifier
                 (typecase qualifier
                   (string (format nil "~s" qualifier))
-                  (t (sql-escape qualifier))))
+                  (t (format nil "~s" (sql-escape qualifier)))))
               (typecase name
                 (string (format nil "~s" (sql-escape name)))
-                (t (sql-escape name)))))
+                (t (format nil "~s" (sql-escape name))))))
     t))
 
 (defmethod output-sql-hash-key ((expr sql-ident-attribute) database)
@@ -587,6 +588,9 @@ uninclusive, and the args from that keyword to the end."
     (write-string "SELECT " *sql-stream*)
     (when all
       (write-string "ALL " *sql-stream*))
+    (when (and limit (eq :odbc (database-type database)))
+      (write-string " TOP " *sql-stream*)
+      (output-sql limit database))
     (when (and distinct (not all))
       (write-string "DISTINCT " *sql-stream*)
       (unless (eql t distinct)
@@ -656,7 +660,7 @@ uninclusive, and the args from that keyword to the end."
               (when (cdr order)
                 (write-char #\, *sql-stream*))))
           (output-sql order-by database)))
-    (when limit
+    (when (and limit (not (eq :odbc (database-type database))))
       (write-string " LIMIT " *sql-stream*)
       (output-sql limit database))
     (when offset