diff --git a/CHANGELOG.md b/CHANGELOG.md index cf9c19e..c942741 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changes +* 2.6.next in progress + * Make SQL Server dialect auto-lift Boolean values to parameters since SQL Server has no `TRUE` / `FALSE` literals. + * 2.6.1243 -- 2024-12-13 * Address [#558](https://github.com/seancorfield/honeysql/issues/558) by adding `:patch-into` (and `patch-into` helper) for XTDB (but in core). * Address [#556](https://github.com/seancorfield/honeysql/issues/556) by adding an XTDB section to the documentation with examples. diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 093c7dd..d1d9765 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -112,7 +112,8 @@ (assoc m k (assoc v :dialect k))) {} {:ansi {:quote #(strop "\"" % "\"")} - :sqlserver {:quote #(strop "[" % "]")} + :sqlserver {:quote #(strop "[" % "]") + :auto-lift-boolean true} :mysql {:quote #(strop "`" % "`") :clause-order-fn #(add-clause-before % :set :where)} @@ -2233,7 +2234,9 @@ (into [(str "(" (join ", " sqls) ")")] params)))) (boolean? expr) - [(upper-case (str expr))] + (if (:auto-lift-boolean *dialect*) + ["?" expr] + [(upper-case (str expr))]) (nil? expr) ["NULL"] diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index 40a2fc0..8e697eb 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -22,6 +22,8 @@ (sut/format-expr [:is :id nil]))) (is (= ["id = TRUE"] (sut/format-expr [:= :id true]))) + (is (= ["[id] = ?" true] + (sut/format [:= :id true] {:dialect :sqlserver}))) (is (= ["id IS TRUE"] (sut/format-expr [:is :id true]))) (is (= ["id <> TRUE"]