From 1f69b5052a5c00b639dd646d5b70fb67045559d5 Mon Sep 17 00:00:00 2001 From: Russ Tyndall Date: Mon, 27 Jun 2011 14:48:27 -0400 Subject: [PATCH] TOP X mssql limit clause must appear after DISTINCT if they are both present --- ChangeLog | 1 + sql/expressions.lisp | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index aa4a5c5..6223422 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2011-06-27 Nathan Bird * db-odbc/: memory management improvements: leak slower + * MSSQL: TOP + DISTINCT work together 2011-06-20 Nathan Bird diff --git a/sql/expressions.lisp b/sql/expressions.lisp index c7236a4..c7fd033 100644 --- a/sql/expressions.lisp +++ b/sql/expressions.lisp @@ -421,7 +421,7 @@ (defmethod output-sql ((expr sql-query-modifier-exp) database) (with-slots (modifier components) expr - (output-sql modifier database) + (%write-operator modifier database) (write-string " " *sql-stream*) (output-sql (car components) database) (when components @@ -586,10 +586,6 @@ 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*)) (when (and distinct (not all)) @@ -598,6 +594,10 @@ uninclusive, and the args from that keyword to the end." (write-string " ON " *sql-stream*) (output-sql distinct database) (write-char #\Space *sql-stream*))) + (when (and limit (eql :mssql (database-underlying-type database))) + (write-string " TOP " *sql-stream*) + (output-sql limit database) + (write-string " " *sql-stream*)) (let ((*in-subselect* t)) (output-sql (apply #'vector selections) database)) (when from -- 2.34.1