changed how where clauses are output to ensure that we do not output a "where"
authorRuss Tyndall <russ@acceleration.net>
Mon, 5 Oct 2009 15:12:20 +0000 (11:12 -0400)
committerRuss Tyndall <russ@acceleration.net>
Mon, 5 Oct 2009 15:12:20 +0000 (11:12 -0400)
sql keyword when we will not output a clause. (Some expressions might produce
an empty string in some cases (an and without any children comes to mind)).

sql/expressions.lisp

index d7a95ef74f83a11cd85ab96e69ed87af14cfe9ad..5967f24e941c707d14a175fb7de02db7365506df 100644 (file)
@@ -625,9 +625,13 @@ uninclusive, and the args from that keyword to the end."
       (write-string " ON " *sql-stream*)
       (output-sql on database))
     (when where
-      (write-string " WHERE " *sql-stream*)
-      (let ((*in-subselect* t))
-        (output-sql where database)))
+      (let ((where-out (string-trim '(#\newline #\space #\tab #\return)
+                                   (with-output-to-string (*sql-stream*)
+                                     (let ((*in-subselect* t))
+                                       (output-sql where database))))))
+       (when (> (length where-out) 0)
+         (write-string " WHERE " *sql-stream*)
+         (write-string where-out *sql-stream*))))
     (when group-by
       (write-string " GROUP BY " *sql-stream*)
       (if (listp group-by)