fix #385 by quoting inlined uuids
This commit is contained in:
parent
c7c634d694
commit
4bf76920ef
3 changed files with 23 additions and 13 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
* 2.2.next in progress
|
* 2.2.next in progress
|
||||||
|
* Fix [#385](https://github.com/seancorfield/honeysql/issues/385) by quoting inlined UUIDs.
|
||||||
* Address [#352](https://github.com/seancorfield/honeysql/issues/352) by treating `:'` as introducing a function name that should be formatted as a SQL entity (respects quoting, dot-splitting, etc).
|
* Address [#352](https://github.com/seancorfield/honeysql/issues/352) by treating `:'` as introducing a function name that should be formatted as a SQL entity (respects quoting, dot-splitting, etc).
|
||||||
|
|
||||||
* 2.2.861 -- 2022-01-30
|
* 2.2.861 -- 2022-01-30
|
||||||
|
|
|
||||||
|
|
@ -253,6 +253,9 @@
|
||||||
(string? x) (str \' (str/replace x "'" "''") \')
|
(string? x) (str \' (str/replace x "'" "''") \')
|
||||||
(ident? x) (sql-kw x)
|
(ident? x) (sql-kw x)
|
||||||
(vector? x) (str "[" (str/join ", " (map #'sqlize-value x)) "]")
|
(vector? x) (str "[" (str/join ", " (map #'sqlize-value x)) "]")
|
||||||
|
;; issue 385: quoted UUIDs for PostgreSQL/ANSI
|
||||||
|
#?(:clj (instance? java.util.UUID x) :cljs false)
|
||||||
|
(str \' x \') ; UUID cannot contain quotes
|
||||||
:else (str x)))
|
:else (str x)))
|
||||||
|
|
||||||
(defn- param-value [k]
|
(defn- param-value [k]
|
||||||
|
|
|
||||||
|
|
@ -134,10 +134,10 @@
|
||||||
(is (= (format {:with [[[:static {:columns [:a :b :c]}] {:values [[1 2 3] [4 5]]}]]})
|
(is (= (format {:with [[[:static {:columns [:a :b :c]}] {:values [[1 2 3] [4 5]]}]]})
|
||||||
["WITH static (a, b, c) AS (VALUES (?, ?, ?), (?, ?, NULL))" 1 2 3 4 5]))
|
["WITH static (a, b, c) AS (VALUES (?, ?, ?), (?, ?, NULL))" 1 2 3 4 5]))
|
||||||
(is (= (format
|
(is (= (format
|
||||||
{:with [[[:static {:columns [:a :b :c]}]
|
{:with [[[:static {:columns [:a :b :c]}]
|
||||||
{:values [[1 2] [4 5 6]]}]]
|
{:values [[1 2] [4 5 6]]}]]
|
||||||
:select [:*]
|
:select [:*]
|
||||||
:from [:static]})
|
:from [:static]})
|
||||||
["WITH static (a, b, c) AS (VALUES (?, ?, NULL), (?, ?, ?)) SELECT * FROM static" 1 2 4 5 6])))
|
["WITH static (a, b, c) AS (VALUES (?, ?, NULL), (?, ?, ?)) SELECT * FROM static" 1 2 4 5 6])))
|
||||||
|
|
||||||
(deftest insert-into
|
(deftest insert-into
|
||||||
|
|
@ -236,15 +236,15 @@
|
||||||
(deftest inner-parts-test
|
(deftest inner-parts-test
|
||||||
(testing "The correct way to apply ORDER BY to various parts of a UNION"
|
(testing "The correct way to apply ORDER BY to various parts of a UNION"
|
||||||
(is (= (format
|
(is (= (format
|
||||||
{:union
|
{:union
|
||||||
[{:select [:amount :id :created_on]
|
[{:select [:amount :id :created_on]
|
||||||
:from [:transactions]}
|
:from [:transactions]}
|
||||||
{:select [:amount :id :created_on]
|
{:select [:amount :id :created_on]
|
||||||
:from [{:select [:amount :id :created_on]
|
:from [{:select [:amount :id :created_on]
|
||||||
:from [:other_transactions]
|
:from [:other_transactions]
|
||||||
:order-by [[:amount :desc]]
|
:order-by [[:amount :desc]]
|
||||||
:limit 5}]}]
|
:limit 5}]}]
|
||||||
:order-by [[:amount :asc]]})
|
:order-by [[:amount :asc]]})
|
||||||
["SELECT amount, id, created_on FROM transactions UNION SELECT amount, id, created_on FROM (SELECT amount, id, created_on FROM other_transactions ORDER BY amount DESC LIMIT ?) ORDER BY amount ASC" 5]))))
|
["SELECT amount, id, created_on FROM transactions UNION SELECT amount, id, created_on FROM (SELECT amount, id, created_on FROM other_transactions ORDER BY amount DESC LIMIT ?) ORDER BY amount ASC" 5]))))
|
||||||
|
|
||||||
(deftest compare-expressions-test
|
(deftest compare-expressions-test
|
||||||
|
|
@ -362,6 +362,12 @@
|
||||||
#_{:parameterizer :mysql-fill})
|
#_{:parameterizer :mysql-fill})
|
||||||
["WHERE (foo = ?) AND (bar = ?) AND (quux = ?)" "foo" "bar" "quux"]))))
|
["WHERE (foo = ?) AND (bar = ?) AND (quux = ?)" "foo" "bar" "quux"]))))
|
||||||
|
|
||||||
|
#?(:clj
|
||||||
|
(deftest issue-385-test
|
||||||
|
(let [u (java.util.UUID/randomUUID)]
|
||||||
|
(is (= [(str "VALUES ('" (str u) "')")]
|
||||||
|
(format {:values [[u]]} {:inline true}))))))
|
||||||
|
|
||||||
(deftest set-before-from
|
(deftest set-before-from
|
||||||
;; issue 235
|
;; issue 235
|
||||||
(is (=
|
(is (=
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue