Avoid recursive equality when formatting values

This commit is contained in:
James Conroy-Finn 2023-10-16 19:12:38 +01:00
parent e252462e6b
commit 052ac101b8
No known key found for this signature in database
GPG key ID: 37A8786A2C3CD764
2 changed files with 9 additions and 1 deletions

View file

@ -936,7 +936,7 @@
(defn- format-values [k xs]
(let [first-xs (when (sequential? xs) (first (drop-while ident? xs)))]
(cond (contains? #{:default 'default} xs)
(cond (or (identical? :default xs) (= 'default xs))
[(str (sql-kw xs) " " (sql-kw k))]
(empty? xs)
[(str (sql-kw k) " ()")]

View file

@ -260,6 +260,14 @@
(is (= (format {:insert-into [:foo :bar] :values [{:foo/id 1}]})
["INSERT INTO foo AS bar (id) VALUES (?)" 1])))
(deftest insert-into-unhashable
(let [unhashable
(reify Object
(toString [_] "Unhashable")
(hashCode [_] (throw (ex-info "Unimplemented `hashCode`!" {}))))]
(is (= (format {:insert-into [[:lift unhashable]]})
["INSERT INTO ?" unhashable]))))
(deftest exists-test
;; EXISTS should never have been implemented as SQL syntax: it's an operator!
#_(is (= (format {:exists {:select [:a] :from [:foo]}})