changed how where clauses are output to ensure that we do not output a "where"
[clsql.git] / 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)