quote aliases better
This commit is contained in:
parent
b3da410e38
commit
74669d62b5
2 changed files with 6 additions and 4 deletions
|
|
@ -200,7 +200,9 @@
|
||||||
;; alias
|
;; alias
|
||||||
(str (to-sql (first x))
|
(str (to-sql (first x))
|
||||||
" AS "
|
" AS "
|
||||||
(str "\"" (name (second x)) "\""))))
|
(if (string? (second x))
|
||||||
|
(quote-identifier (second x))
|
||||||
|
(to-sql (second x))))))
|
||||||
SqlCall
|
SqlCall
|
||||||
(-to-sql [x] (binding [*fn-context?* true]
|
(-to-sql [x] (binding [*fn-context?* true]
|
||||||
(let [fn-name (name (.name x))
|
(let [fn-name (name (.name x))
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
;; TODO: more tests
|
;; TODO: more tests
|
||||||
|
|
||||||
(deftest test-select
|
(deftest test-select
|
||||||
(let [m1 (-> (select :f.* :b.baz :c.quux [:b.bla "bla bla"]
|
(let [m1 (-> (select :f.* :b.baz :c.quux [:b.bla :bla-bla]
|
||||||
:%now (sql/raw "@x := 10"))
|
:%now (sql/raw "@x := 10"))
|
||||||
;;(un-select :c.quux)
|
;;(un-select :c.quux)
|
||||||
(modifiers :distinct)
|
(modifiers :distinct)
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
(order-by [:b.baz :desc] :c.quux)
|
(order-by [:b.baz :desc] :c.quux)
|
||||||
(limit 50)
|
(limit 50)
|
||||||
(offset 10))
|
(offset 10))
|
||||||
m2 {:select [:f.* :b.baz :c.quux [:b.bla "bla bla"]
|
m2 {:select [:f.* :b.baz :c.quux [:b.bla :bla-bla]
|
||||||
:%now (sql/raw "@x := 10")]
|
:%now (sql/raw "@x := 10")]
|
||||||
;;:un-select :c.quux
|
;;:un-select :c.quux
|
||||||
:modifiers :distinct
|
:modifiers :distinct
|
||||||
|
|
@ -51,7 +51,7 @@
|
||||||
(is (= m1 m3)))
|
(is (= m1 m3)))
|
||||||
(testing "SQL data formats correctly"
|
(testing "SQL data formats correctly"
|
||||||
(is (= (sql/format m1 {:param1 "gabba" :param2 2})
|
(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 INNER JOIN draq ON f.b = draq.x LEFT JOIN clod AS 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 "
|
["SELECT DISTINCT f.*, b.baz, c.quux, b.bla AS bla_bla, now(), @x := 10 FROM foo AS f, baz AS b INNER JOIN draq ON f.b = draq.x LEFT JOIN clod AS 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])))
|
"bort" "gabba" 2])))
|
||||||
(testing "SQL data prints and reads correctly"
|
(testing "SQL data prints and reads correctly"
|
||||||
(is (= m1 (read-string (pr-str m1)))))))
|
(is (= m1 (read-string (pr-str m1)))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue