address #352 by treating :'foo literally

This commit is contained in:
Sean Corfield 2022-02-02 22:04:44 -08:00
parent 1d22086fce
commit 1f2773bd16
2 changed files with 18 additions and 4 deletions

View file

@ -167,12 +167,17 @@
(defn sql-kw (defn sql-kw
"Given a keyword, return a SQL representation of it as a string. "Given a keyword, return a SQL representation of it as a string.
A `:kebab-case` keyword becomes a `KEBAB CASE` (uppercase) string A keyword whose name begins with a single quote is left exactly as-is
with hyphens replaced by spaces, e.g., `:insert-into` => `INSERT INTO`. (with the `:` and `'` removed), otherwise a `:kebab-case` keyword
becomes a `KEBAB CASE` (uppercase) string with hyphens replaced
by spaces, e.g., `:insert-into` => `INSERT INTO`.
Any namespace qualifier is ignored." Any namespace qualifier is ignored."
[k] [k]
(-> k (name) (dehyphen) (upper-case))) (let [n (name k)]
(if (= \' (first n))
(subs n 1 (count n))
(-> n (dehyphen) (upper-case)))))
(defn- sym->kw (defn- sym->kw
"Given a symbol, produce a keyword, retaining the namespace "Given a symbol, produce a keyword, retaining the namespace

View file

@ -794,7 +794,16 @@ ORDER BY id = ? DESC
(format {:select (keyword "%mixed-kebab.yum-yum/bar-bar.a-b/c-d")} :dialect :mysql :quoted-snake true))) (format {:select (keyword "%mixed-kebab.yum-yum/bar-bar.a-b/c-d")} :dialect :mysql :quoted-snake true)))
(is (= ["SELECT RANSOM(`NoTe`)"] (is (= ["SELECT RANSOM(`NoTe`)"]
(format {:select [[[:ransom :NoTe]]]} :dialect :mysql) (format {:select [[[:ransom :NoTe]]]} :dialect :mysql)
(format {:select :%ransom.NoTe} :dialect :mysql))))) (format {:select :%ransom.NoTe} :dialect :mysql))))
(testing "issue 352: literal function calls"
(is (= ["SELECT sysdate()"]
(format {:select [[[:'sysdate]]]})))
(is (= ["SELECT count(*)"]
(format {:select [[[:'count :*]]]})))
(is (= ["SELECT Mixed-Kebab(`yum-yum`)"]
(format {:select [[[:'Mixed-Kebab :yum-yum]]]} :dialect :mysql)))
(is (= ["SELECT other-project.other_dataset.other_function(?, ?)" 1 2]
(format {:select [[[:'other-project.other_dataset.other_function 1 2]]]})))))
(deftest join-without-on-using (deftest join-without-on-using
;; essentially issue 326 ;; essentially issue 326