diff --git a/CHANGELOG.md b/CHANGELOG.md index 1376258..b67c800 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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**. diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 69b6c72..24fc250 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -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)] diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index 6fc16c9..8fd56ec 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -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"