quoting for :%fun.col(s) syntax to match with [[:fun :col]]
This commit is contained in:
parent
d73560b7e3
commit
6ebc017969
2 changed files with 30 additions and 4 deletions
|
|
@ -214,11 +214,13 @@
|
||||||
(fn [fk _] (param-value (fk)))}))
|
(fn [fk _] (param-value (fk)))}))
|
||||||
|
|
||||||
(defn- format-var [x & [opts]]
|
(defn- format-var [x & [opts]]
|
||||||
(let [c (name-_ x)]
|
(let [c (name x)]
|
||||||
(cond (= \% (first c))
|
(cond (= \% (first c))
|
||||||
(let [[f & args] (str/split (subs c 1) #"\.")]
|
(let [[f & args] (str/split (subs c 1) #"\.")
|
||||||
;; TODO: this does not quote arguments -- does that matter?
|
quoted-args (->> args
|
||||||
[(str (upper-case f) "(" (str/join "," args) ")")])
|
(map keyword)
|
||||||
|
(map format-entity))]
|
||||||
|
[(str (upper-case f) "(" (str/join "," quoted-args) ")")])
|
||||||
(= \? (first c))
|
(= \? (first c))
|
||||||
(let [k (keyword (subs c 1))]
|
(let [k (keyword (subs c 1))]
|
||||||
(if *inline*
|
(if *inline*
|
||||||
|
|
|
||||||
|
|
@ -866,3 +866,27 @@
|
||||||
{:with [[:a]],
|
{:with [[:a]],
|
||||||
:insert-into [[:quux [:x :y]]
|
:insert-into [[:quux [:x :y]]
|
||||||
{:select [:id], :from [:table]}]}))))
|
{:select [:id], :from [:table]}]}))))
|
||||||
|
|
||||||
|
(deftest quoting-:%-syntax
|
||||||
|
(testing "quoting of expressions in functions shouldn't depend on syntax"
|
||||||
|
(is (= [(str "SELECT `foo-bar`,"
|
||||||
|
" COUNT(*),"
|
||||||
|
" COUNT(*),"
|
||||||
|
" SYSDATE(),"
|
||||||
|
" SYSDATE(),"
|
||||||
|
" AVG(`bar-bar`),"
|
||||||
|
" AVG(`bar-bar`,`bar-foo`),"
|
||||||
|
" SUM(`foo-foo`)"
|
||||||
|
" FROM `employee`"
|
||||||
|
" GROUP BY `foo-bar`")]
|
||||||
|
(-> (select :foo-bar
|
||||||
|
[[:count :*]]
|
||||||
|
:%count.*
|
||||||
|
:%sysdate
|
||||||
|
:%sysdate.
|
||||||
|
:%avg.bar-bar
|
||||||
|
:%avg.bar-bar.bar-foo
|
||||||
|
[[:sum :foo-foo]])
|
||||||
|
(from :employee)
|
||||||
|
(group-by :foo-bar)
|
||||||
|
(sql/format :dialect :mysql))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue