fixes #344 by special-casing MySQL SET
This commit is contained in:
parent
249ab639ec
commit
9ece8972b5
3 changed files with 22 additions and 6 deletions
|
|
@ -1,6 +1,7 @@
|
|||
# Changes
|
||||
|
||||
* 2.0.next in progress ("gold" mid-August?)
|
||||
* Fixes #344 by no longer dropping the qualifier on columns in a `SET` clause _for the `:mysql` dialect only_; the behavior is unchanged for all other dialects.
|
||||
* Fixes #340 by making hyphen to space logic more general so _operators_ containing `-` should retain the hyphen without special cases.
|
||||
* Documentation improvements: `:fetch`, `:lift`, `:limit`, `:offset`, `:param`, `:select`; also around JSON/PostgreSQL.
|
||||
* Link to the [HoneySQL web app](https://www.john-shaffer.com/honeysql/) in both the README and **Getting Started**.
|
||||
|
|
|
|||
|
|
@ -127,6 +127,11 @@
|
|||
(symbol (name clause))
|
||||
(keyword (name clause))))))
|
||||
|
||||
(defn- mysql?
|
||||
"Helper to detect if MySQL is the current dialect."
|
||||
[]
|
||||
(= :mysql (:dialect *dialect*)))
|
||||
|
||||
(defn- sql-server?
|
||||
"Helper to detect if SQL Server is the current dialect."
|
||||
[]
|
||||
|
|
@ -641,7 +646,7 @@
|
|||
(let [[sqls params]
|
||||
(reduce-kv (fn [[sql params] v e]
|
||||
(let [[sql' & params'] (format-expr e)]
|
||||
[(conj sql (str (format-entity v {:drop-ns true}) " = " sql'))
|
||||
[(conj sql (str (format-entity v {:drop-ns (not (mysql?))}) " = " sql'))
|
||||
(if params' (into params params') params)]))
|
||||
[[] []]
|
||||
xs)]
|
||||
|
|
|
|||
|
|
@ -378,11 +378,21 @@
|
|||
(is (=
|
||||
["UPDATE `foo` INNER JOIN `bar` ON `bar`.`id` = `foo`.`bar_id` SET `a` = ? WHERE `bar`.`b` = ?" 1 42]
|
||||
(->
|
||||
{:update :foo
|
||||
:join [:bar [:= :bar.id :foo.bar_id]]
|
||||
:set {:a 1}
|
||||
:where [:= :bar.b 42]}
|
||||
(format {:dialect :mysql})))))
|
||||
{:update :foo
|
||||
:join [:bar [:= :bar.id :foo.bar_id]]
|
||||
:set {:a 1}
|
||||
:where [:= :bar.b 42]}
|
||||
(format {:dialect :mysql}))))
|
||||
;; issue 344
|
||||
(is (=
|
||||
["UPDATE `foo` INNER JOIN `bar` ON `bar`.`id` = `foo`.`bar_id` SET `f`.`a` = ? WHERE `bar`.`b` = ?" 1 42]
|
||||
(->
|
||||
{:update :foo
|
||||
:join [:bar [:= :bar.id :foo.bar_id]]
|
||||
;; do not drop ns in set clause for MySQL:
|
||||
:set {:f/a 1}
|
||||
:where [:= :bar.b 42]}
|
||||
(format {:dialect :mysql})))))
|
||||
|
||||
(deftest format-arity-test
|
||||
(testing "format can be called with no options"
|
||||
|
|
|
|||
Loading…
Reference in a new issue