From 78da4831fd20e83f64c74fd6140ed6e8ee73a495 Mon Sep 17 00:00:00 2001 From: Russ Tyndall Date: Thu, 20 Aug 2009 14:23:33 -0400 Subject: [PATCH] special cased MSSQL/ODBC limit handling in output-sql of sql-query --- sql/expressions.lisp | 12 ++++++++---- tests/test-init.lisp | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sql/expressions.lisp b/sql/expressions.lisp index 2b9b913..d09b154 100644 --- a/sql/expressions.lisp +++ b/sql/expressions.lisp @@ -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 diff --git a/tests/test-init.lisp b/tests/test-init.lisp index 3efa6d6..4a83cf9 100644 --- a/tests/test-init.lisp +++ b/tests/test-init.lisp @@ -287,7 +287,7 @@ (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)) -- 2.34.1