quoting for :%fun.col(s) syntax to match with [[:fun :col]]

This commit is contained in:
Neil McCalum 2021-05-09 17:18:39 +12:00
parent d73560b7e3
commit 6ebc017969
2 changed files with 30 additions and 4 deletions

View file

@ -214,11 +214,13 @@
(fn [fk _] (param-value (fk)))}))
(defn- format-var [x & [opts]]
(let [c (name-_ x)]
(let [c (name x)]
(cond (= \% (first c))
(let [[f & args] (str/split (subs c 1) #"\.")]
;; TODO: this does not quote arguments -- does that matter?
[(str (upper-case f) "(" (str/join "," args) ")")])
(let [[f & args] (str/split (subs c 1) #"\.")
quoted-args (->> args
(map keyword)
(map format-entity))]
[(str (upper-case f) "(" (str/join "," quoted-args) ")")])
(= \? (first c))
(let [k (keyword (subs c 1))]
(if *inline*

View file

@ -866,3 +866,27 @@
{:with [[:a]],
:insert-into [[:quux [:x :y]]
{: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))))))