diff --git a/CHANGELOG.md b/CHANGELOG.md index eaafc4d..6b268a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changes * 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). * 2.2.861 -- 2022-01-30 diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index d5bbfcd..a3441d3 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -253,6 +253,9 @@ (string? x) (str \' (str/replace x "'" "''") \') (ident? x) (sql-kw 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))) (defn- param-value [k] diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index 00b7b57..0abe446 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -134,10 +134,10 @@ (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])) (is (= (format - {:with [[[:static {:columns [:a :b :c]}] - {:values [[1 2] [4 5 6]]}]] - :select [:*] - :from [:static]}) + {:with [[[:static {:columns [:a :b :c]}] + {:values [[1 2] [4 5 6]]}]] + :select [:*] + :from [:static]}) ["WITH static (a, b, c) AS (VALUES (?, ?, NULL), (?, ?, ?)) SELECT * FROM static" 1 2 4 5 6]))) (deftest insert-into @@ -236,15 +236,15 @@ (deftest inner-parts-test (testing "The correct way to apply ORDER BY to various parts of a UNION" (is (= (format - {:union - [{:select [:amount :id :created_on] - :from [:transactions]} - {:select [:amount :id :created_on] - :from [{:select [:amount :id :created_on] - :from [:other_transactions] - :order-by [[:amount :desc]] - :limit 5}]}] - :order-by [[:amount :asc]]}) + {:union + [{:select [:amount :id :created_on] + :from [:transactions]} + {:select [:amount :id :created_on] + :from [{:select [:amount :id :created_on] + :from [:other_transactions] + :order-by [[:amount :desc]] + :limit 5}]}] + :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])))) (deftest compare-expressions-test @@ -362,6 +362,12 @@ #_{:parameterizer :mysql-fill}) ["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 ;; issue 235 (is (=