special cased MSSQL/ODBC limit handling in output-sql of sql-query
authorRuss Tyndall <russ@acceleration.net>
Thu, 20 Aug 2009 18:23:33 +0000 (14:23 -0400)
committerNathan Bird <nathan@acceleration.net>
Mon, 20 Jun 2011 20:06:18 +0000 (16:06 -0400)
sql/expressions.lisp
tests/test-init.lisp

index 2b9b913da4685ed9180d0abd5156015092037ff9..d09b154e0ef99907195f6b41f078f420e7c95283 100644 (file)
@@ -586,12 +586,16 @@ uninclusive, and the args from that keyword to the end."
     (when *in-subselect*
       (write-string "(" *sql-stream*))
     (write-string "SELECT " *sql-stream*)
+    (when (and limit (eql :mssql (database-underlying-type database)))
+      (write-string " TOP " *sql-stream*)
+      (output-sql limit database)
+      (write-string " " *sql-stream*))
     (when all
-      (write-string "ALL " *sql-stream*))
+      (write-string " ALL " *sql-stream*))
     (when (and distinct (not all))
-      (write-string "DISTINCT " *sql-stream*)
+      (write-string " DISTINCT " *sql-stream*)
       (unless (eql t distinct)
-        (write-string "ON " *sql-stream*)
+        (write-string " ON " *sql-stream*)
         (output-sql distinct database)
         (write-char #\Space *sql-stream*)))
     (let ((*in-subselect* t))
@@ -657,7 +661,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 (eql :mssql (database-underlying-type database))))
       (write-string " LIMIT " *sql-stream*)
       (output-sql limit database))
     (when offset
index 3efa6d62d193130c0431a0142afb8ab1796a7123..4a83cf9cd28a3950089d91ce8ff581e93a911ab0 100644 (file)
                 (clsql-sys:in test :fdml/select/9))
            (push (cons test "mssql uses integer math for AVG.") skip-tests))
           ((and (not (member *test-database-underlying-type*
-                             '(:postgresql :mysql :sqlite3)))
+                             '(:postgresql :mysql :sqlite3 )))
                 (clsql-sys:in test :fdml/select/37 :fdml/select/38))
            (push (cons test "LIMIT keyword not supported in SELECT.") skip-tests))
          ((and (not (clsql-sys:db-type-has-auto-increment? db-underlying-type))