The "AS" alias is no longer split before quoting

Fixes #216
This commit is contained in:
Gordon Stratton 2018-10-01 15:19:03 +00:00
parent c190acf282
commit 5faae8790f
2 changed files with 16 additions and 9 deletions

View file

@ -351,14 +351,13 @@
;; alias ;; alias
(do (do
(assert (= 2 (count x)) (str "Alias should have two parts" x)) (assert (= 2 (count x)) (str "Alias should have two parts" x))
(str (to-sql (first x)) (let [[target alias] x]
; Omit AS in FROM, JOIN, etc. - Oracle doesn't allow it (str (to-sql target)
(if (= :select *clause*) ; Omit AS in FROM, JOIN, etc. - Oracle doesn't allow it
" AS " (if (= :select *clause*) " AS " " ")
" ") (if (or (string? alias) (keyword? alias) (symbol? alias))
(if (string? (second x)) (quote-identifier alias :split false)
(quote-identifier (second x)) (to-sql alias)))))))
(to-sql (second x)))))))
(extend-protocol types/Inlinable (extend-protocol types/Inlinable
#?(:clj clojure.lang.Keyword #?(:clj clojure.lang.Keyword

View file

@ -37,6 +37,14 @@
(is (= (quote-identifier :foo/bar) "foo/bar")) (is (= (quote-identifier :foo/bar) "foo/bar"))
(is (= (quote-identifier :foo/bar :style :ansi) "\"foo/bar\""))) (is (= (quote-identifier :foo/bar :style :ansi) "\"foo/bar\"")))
(deftest alias-splitting
(is (= ["SELECT `aa`.`c` AS `a.c`, `bb`.`c` AS `b.c`, `cc`.`c` AS `c.c`"]
(format {:select [[:aa.c "a.c"]
[:bb.c :b.c]
[:cc.c 'c.c]]}
:quoting :mysql))
"aliases containing \".\" are quoted as necessary but not split"))
(deftest test-cte (deftest test-cte
(is (= (format-clause (is (= (format-clause
(first {:with [[:query {:select [:foo] :from [:bar]}]]}) nil) (first {:with [[:query {:select [:foo] :from [:bar]}]]}) nil)