Skip to content

Commit

Permalink
Revert "fix #528 by not ?-escaping operators"
Browse files Browse the repository at this point in the history
This reverts commit eb680a2.
  • Loading branch information
seancorfield committed Apr 4, 2024
1 parent 6c88c0b commit d1e9617
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 28 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Changes

* 2.6.next in progress
* Fix [#528](https://github.com/seancorfield/honeysql/issues/528) by preventing the `?` -> `??` escaping in SQL keywords just for operators.
* Address [#527](https://github.com/seancorfield/honeysql/issues/527) by adding tests and more documentation for `:composite`.
* Update Clojure versions (to 1.11.2 and 1.12.0-alpha9).

Expand Down
25 changes: 2 additions & 23 deletions src/honey/sql.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -326,27 +326,6 @@
[v a d (format-entity v {:aliased a :drop-ns d})])))
)

(defn sql-op-kw
"Given a keyword for an operator, return a SQL representation of it as a string.
A keyword whose name begins with a single quote is left exactly as-is
(with the `:` and `'` removed), otherwise a `:kebab-case` keyword
becomes a `KEBAB CASE` (uppercase) string with hyphens replaced
by spaces, e.g., `:insert-into` => `INSERT INTO`.
Any namespace qualifier is ignored.
Unlike sql-kw below, ? is NOT escaped to ??."
[k]
(when k
(let [n (name k)]
(if (= \' (first n))
(let [ident (subs n 1)
ident-l (str/lower-case ident)]
(binding [*quoted* (when-not (contains? #{"array"} ident-l) *quoted*)]
(format-entity (keyword ident))))
(-> n (dehyphen) (upper-case))))))

(defn sql-kw
"Given a keyword, return a SQL representation of it as a string.
Expand Down Expand Up @@ -1964,10 +1943,10 @@
(when-not (pos? (count sqls))
(throw (ex-info (str "no operands found for " op')
{:expr expr})))
(into [(cond-> (str/join (str " " (sql-op-kw op) " ") sqls)
(into [(cond-> (str/join (str " " (sql-kw op) " ") sqls)
(and (contains? @op-can-be-unary op)
(= 1 (count sqls)))
(as-> s (str (sql-op-kw op) " " s))
(as-> s (str (sql-kw op) " " s))
nested
(as-> s (str "(" s ")")))]
params)))
Expand Down
8 changes: 4 additions & 4 deletions test/honey/sql/pg_ops_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
(sql/format {:select [[[:#> :a :b] :x]]})))
(is (= ["SELECT a #>> b AS x"]
(sql/format {:select [[[:#>> :a :b] :x]]})))
(is (= ["SELECT a ? b AS x"]
(is (= ["SELECT a ?? b AS x"]
(sql/format {:select [[[:? :a :b] :x]]})))
(is (= ["SELECT a ?| b AS x"]
(is (= ["SELECT a ??| b AS x"]
(sql/format {:select [[[:?| :a :b] :x]]})))
(is (= ["SELECT a ?& b AS x"]
(is (= ["SELECT a ??& b AS x"]
(sql/format {:select [[[:?& :a :b] :x]]})))
(is (= ["SELECT a #- b AS x"]
(sql/format {:select [[[:#- :a :b] :x]]}))))
Expand All @@ -33,7 +33,7 @@
(sql/format {:select [[[sut/at> :a :b] :x]]})))
(is (= ["SELECT a <@ b AS x"]
(sql/format {:select [[[sut/<at :a :b] :x]]})))
(is (= ["SELECT a @? b AS x"]
(is (= ["SELECT a @?? b AS x"]
(sql/format {:select [[[sut/at? :a :b] :x]]})))
(is (= ["SELECT a @@ b AS x"]
(sql/format {:select [[[sut/atat :a :b] :x]]}))))
Expand Down

0 comments on commit d1e9617

Please sign in to comment.