Fixes #317 by dropping qualifier in :set clause
This commit is contained in:
parent
b010f91586
commit
06f25ed2e3
3 changed files with 34 additions and 9 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
* 2.0.next in progress
|
* 2.0.next in progress
|
||||||
|
* Fix #317 by dropping qualifiers in `:set` clauses (just like we do with `:insert` columns). Note that you can still use explicit _dotted_ names if you want table qualification.
|
||||||
* Fix #312 by adding `:raw` as a clause. There is no helper function equivalent (because it would be ambiguous whether you meant a function form -- `[:raw ..]` -- or a clause form -- `{:raw ..}`; and for the same reason, there is no `nest` helper function since that also works as a clause and as a function/special syntax).
|
* Fix #312 by adding `:raw` as a clause. There is no helper function equivalent (because it would be ambiguous whether you meant a function form -- `[:raw ..]` -- or a clause form -- `{:raw ..}`; and for the same reason, there is no `nest` helper function since that also works as a clause and as a function/special syntax).
|
||||||
|
|
||||||
* 2.0.0-alpha3 (for early testing; 2021-03-13)
|
* 2.0.0-alpha3 (for early testing; 2021-03-13)
|
||||||
|
|
|
||||||
|
|
@ -559,7 +559,7 @@
|
||||||
(let [[sqls params]
|
(let [[sqls params]
|
||||||
(reduce-kv (fn [[sql params] v e]
|
(reduce-kv (fn [[sql params] v e]
|
||||||
(let [[sql' & params'] (format-expr e)]
|
(let [[sql' & params'] (format-expr e)]
|
||||||
[(conj sql (str (format-entity v) " = " sql'))
|
[(conj sql (str (format-entity v {:drop-ns true}) " = " sql'))
|
||||||
(if params' (into params params') params)]))
|
(if params' (into params params') params)]))
|
||||||
[[] []]
|
[[] []]
|
||||||
xs)]
|
xs)]
|
||||||
|
|
|
||||||
|
|
@ -337,17 +337,41 @@
|
||||||
#_{:parameterizer :mysql-fill})
|
#_{:parameterizer :mysql-fill})
|
||||||
["WHERE (foo = ?) AND (bar = ?) AND (quux = ?)" "foo" "bar" "quux"]))))
|
["WHERE (foo = ?) AND (bar = ?) AND (quux = ?)" "foo" "bar" "quux"]))))
|
||||||
|
|
||||||
(deftest set-before-from ; issue 235
|
(deftest set-before-from
|
||||||
|
;; issue 235
|
||||||
(is (=
|
(is (=
|
||||||
["UPDATE \"films\" \"f\" SET \"kind\" = \"c\".\"test\" FROM (SELECT \"b\".\"test\" FROM \"bar\" AS \"b\" WHERE \"b\".\"id\" = ?) AS \"c\" WHERE \"f\".\"kind\" = ?" 1 "drama"]
|
["UPDATE \"films\" \"f\" SET \"kind\" = \"c\".\"test\" FROM (SELECT \"b\".\"test\" FROM \"bar\" AS \"b\" WHERE \"b\".\"id\" = ?) AS \"c\" WHERE \"f\".\"kind\" = ?" 1 "drama"]
|
||||||
(->
|
(->
|
||||||
{:update [:films :f]
|
{:update [:films :f]
|
||||||
:set {:kind :c.test}
|
:set {:kind :c.test}
|
||||||
:from [[{:select [:b.test]
|
:from [[{:select [:b.test]
|
||||||
:from [[:bar :b]]
|
:from [[:bar :b]]
|
||||||
:where [:= :b.id 1]} :c]]
|
:where [:= :b.id 1]} :c]]
|
||||||
:where [:= :f.kind "drama"]}
|
:where [:= :f.kind "drama"]}
|
||||||
(format {:quoted true})))))
|
(format {:quoted true}))))
|
||||||
|
;; issue 317
|
||||||
|
(is (=
|
||||||
|
["UPDATE \"films\" \"f\" SET \"kind\" = \"c\".\"test\" FROM (SELECT \"b\".\"test\" FROM \"bar\" AS \"b\" WHERE \"b\".\"id\" = ?) AS \"c\" WHERE \"f\".\"kind\" = ?" 1 "drama"]
|
||||||
|
(->
|
||||||
|
{:update [:films :f]
|
||||||
|
;; drop ns in set clause...
|
||||||
|
:set {:f/kind :c.test}
|
||||||
|
:from [[{:select [:b.test]
|
||||||
|
:from [[:bar :b]]
|
||||||
|
:where [:= :b.id 1]} :c]]
|
||||||
|
:where [:= :f.kind "drama"]}
|
||||||
|
(format {:quoted true}))))
|
||||||
|
(is (=
|
||||||
|
["UPDATE \"films\" \"f\" SET \"f\".\"kind\" = \"c\".\"test\" FROM (SELECT \"b\".\"test\" FROM \"bar\" AS \"b\" WHERE \"b\".\"id\" = ?) AS \"c\" WHERE \"f\".\"kind\" = ?" 1 "drama"]
|
||||||
|
(->
|
||||||
|
{:update [:films :f]
|
||||||
|
;; ...but keep literal dotted name
|
||||||
|
:set {:f.kind :c.test}
|
||||||
|
:from [[{:select [:b.test]
|
||||||
|
:from [[:bar :b]]
|
||||||
|
:where [:= :b.id 1]} :c]]
|
||||||
|
:where [:= :f.kind "drama"]}
|
||||||
|
(format {:quoted true})))))
|
||||||
|
|
||||||
(deftest set-after-join
|
(deftest set-after-join
|
||||||
(is (=
|
(is (=
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue