changed how where clauses are output to ensure that we do not output a
authorRuss Tyndall <russ@acceleration.net>
Mon, 5 Oct 2009 15:12:20 +0000 (11:12 -0400)
committerNathan Bird <nathan@acceleration.net>
Thu, 30 Jun 2011 20:56:28 +0000 (16:56 -0400)
"where" 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)).

  prev: 814ef0649edf23f0136d5cad2d7738ae72e79871

sql/expressions.lisp

index c7fd033da646d6c0a17520a64f129f79fb37ad34..efb54bb650f00338d4b17590b9e6d346060aa3ef 100644 (file)
@@ -625,9 +625,14 @@ 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)