From e0c190b50ed7ff3eae6c9b60a6e140957babfde6 Mon Sep 17 00:00:00 2001 From: Justin Kramer Date: Fri, 24 Aug 2012 22:47:54 -0400 Subject: [PATCH] data reader & test for param --- resources/data_readers.clj | 3 ++- test/honeysql/core_test.clj | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/resources/data_readers.clj b/resources/data_readers.clj index 90e84e1..56636a8 100644 --- a/resources/data_readers.clj +++ b/resources/data_readers.clj @@ -1,2 +1,3 @@ {sql/call honeysql.types/read-sql-call - sql/raw honeysql.types/read-sql-raw} \ No newline at end of file + sql/raw honeysql.types/read-sql-raw + sql/param honeysql.types/read-sql-param} \ No newline at end of file diff --git a/test/honeysql/core_test.clj b/test/honeysql/core_test.clj index fe70a9d..8003b0c 100644 --- a/test/honeysql/core_test.clj +++ b/test/honeysql/core_test.clj @@ -15,9 +15,9 @@ (join [[:clod :c] [:= :f.a :c.d] :left] [:draq [:= :f.b :draq.x]]) (where [:or - [:and [:= :f.a "bort"] [:not= :b.baz "gabba"]] + [:and [:= :f.a "bort"] [:not= :b.baz (sql/param :param1)]] [:< 1 2 3] - [:in :f.e [1 2 3]] + [:in :f.e [1 (sql/param :param2) 3]] [:between :f.e 10 20]]) ;;(merge-where [:not= nil :b.bla]) (group :f.a) @@ -33,9 +33,9 @@ :join [[[:clod :c] [:= :f.a :c.d] :left] [:draq [:= :f.b :draq.x]]] :where [:or - [:and [:= :f.a "bort"] [:not= :b.baz "gabba"]] + [:and [:= :f.a "bort"] [:not= :b.baz (sql/param :param1)]] [:< 1 2 3] - [:in :f.e [1 2 3]] + [:in :f.e [1 (sql/param :param2) 3]] [:between :f.e 10 20]] ;;:merge-where [:not= nil :b.bla] :group-by :f.a @@ -48,7 +48,8 @@ (testing "Various construction methods are consistent" (is (= m1 m3))) (testing "SQL data formats correctly" - (is (= (sql/format m1) - ["SELECT DISTINCT f.*, b.baz, c.quux, b.bla AS \"bla-bla\", NOW(), @x := 10 FROM foo AS f, baz AS b LEFT JOIN clod AS c ON f.a = c.d JOIN draq ON f.b = draq.x WHERE ((f.a = ? AND b.baz <> ?) OR (1 < 2 AND 2 < 3) OR (f.e IN (1, 2, 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"]))) + (is (= (sql/format m1 {:param1 "gabba" :param2 2}) + ["SELECT DISTINCT f.*, b.baz, c.quux, b.bla AS \"bla-bla\", NOW(), @x := 10 FROM foo AS f, baz AS b LEFT JOIN clod AS c ON f.a = c.d JOIN draq ON f.b = draq.x 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))))))) \ No newline at end of file