diff --git a/src/honeysql/format.clj b/src/honeysql/format.clj index 004a640..9e4bf18 100644 --- a/src/honeysql/format.clj +++ b/src/honeysql/format.clj @@ -247,7 +247,7 @@ (-to-sql [x] (.s x)) clojure.lang.IPersistentMap (-to-sql [x] (let [clause-ops (concat - (filter #(contains? x %) clause-order) + (filter #(and (contains? x %) (get x %)) clause-order) (remove known-clauses (keys x))) sql-str (binding [*subquery?* true *fn-context?* false] diff --git a/test/honeysql/core_test.clj b/test/honeysql/core_test.clj index 161b52f..4dc0108 100644 --- a/test/honeysql/core_test.clj +++ b/test/honeysql/core_test.clj @@ -54,4 +54,7 @@ ["SELECT DISTINCT f.*, b.baz, c.quux, b.bla AS bla_bla, now(), @x := 10 FROM foo f, baz b INNER JOIN draq ON f.b = draq.x LEFT JOIN clod c ON f.a = c.d RIGHT JOIN bock ON bock.z = c.e WHERE ((f.a = ? AND b.baz <> ?) OR (1 < 2 AND 2 < 3) OR (f.e in (1, ?, 3)) OR f.e BETWEEN 10 AND 20) GROUP BY f.a HAVING 0 < f.e ORDER BY b.baz DESC, c.quux LIMIT 50 OFFSET 10 " "bort" "gabba" 2]))) (testing "SQL data prints and reads correctly" - (is (= m1 (read-string (pr-str m1))))))) + (is (= m1 (read-string (pr-str m1))))) + (testing "Keys with value 'nil' are ignored" + (is (= (sql/format {:select '(:a.id) :from '([:foo :a]) :group-by nil :order-by nil}) + ["SELECT a.id FROM foo a"])))))