From 02d20bd78cbe2bd139a4650d0cb95deed2633094 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sun, 11 Sep 2022 20:52:53 -0700 Subject: [PATCH] address #430 by expanding escape hatch from #352 --- CHANGELOG.md | 3 ++- src/honey/sql.cljc | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0017922..14f3e9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changes * 2.3.next in progress + * Address [#430](https://github.com/seancorfield/honeysql/issues/430) by treating `:'` as introducing a name that should be treating literally and not formatted as a SQL entity (which respects quoting, dot-splitting, etc); this expands the "escape hatch" introduced in [#352](https://github.com/seancorfield/honeysql/issues/352) in 2.2.868. * Address [#427](https://github.com/seancorfield/honeysql/issues/427) by adding `set-options!`. * 2.3.928 -- 2022-09-04 @@ -37,7 +38,7 @@ * 2.2.868 -- 2022-02-21 * Address [#387](https://github.com/seancorfield/honeysql/issues/387) by making the function simpler. * 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 not be formatted as a SQL entity (which respects quoting, dot-splitting, etc). * 2.2.861 -- 2022-01-30 * Address [#382](https://github.com/seancorfield/honeysql/issues/382) by adding `:case-expr` for BigQuery support. diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 4d8c720..3d2746b 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -314,6 +314,8 @@ {::wrapper (fn [fk _] (param-value (fk)))})) +(def ^:private ^:dynamic *formatted-column* (atom false)) + (defn- format-var [x & [opts]] ;; rather than name/namespace, we want to allow ;; for multiple / in the %fun.call case so that @@ -329,6 +331,10 @@ (if *inline* [(sqlize-value (param-value k))] ["?" (->param k)])) + (= \' (first c)) + (do + (reset! *formatted-column* true) + [(subs c 1)]) :else [(format-entity x opts)]))) @@ -939,8 +945,6 @@ (let [[if-exists tables & more] (destructure-drop-items params "DROP options")] [(str/join " " (remove nil? (into [(sql-kw k) if-exists tables] more)))])) -(def ^:private ^:dynamic *formatted-column* (atom false)) - (defn- format-single-column [xs] (reset! *formatted-column* true) (str/join " " (cons (format-simple-expr (first xs) "column operation")