Skip to content

Commit

Permalink
SQL Server has no TRUE / FALSE literals
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Corfield <[email protected]>
  • Loading branch information
seancorfield committed Dec 14, 2024
1 parent c98df6d commit 0f26e7d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 5 additions & 2 deletions src/honey/sql.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down Expand Up @@ -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"]
Expand Down
2 changes: 2 additions & 0 deletions test/honey/sql_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 0f26e7d

Please sign in to comment.