From 15f73f9442cc63dfad55e5f0cce1f6d463e51077 Mon Sep 17 00:00:00 2001 From: Oleksandr Yakushev Date: Fri, 27 Sep 2024 11:19:17 +0300 Subject: [PATCH] Replace first character checks with starts-with? --- src/honey/sql.cljc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 23326ea..bfdb902 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -280,7 +280,7 @@ Handles quoting, splitting at / or ., replacing - with _ etc." [e & [{:keys [aliased drop-ns]}]] - (let [e (if (and aliased (keyword? e) (= \' (first (name e)))) + (let [e (if (and aliased (keyword? e) (str/starts-with? (name e) "'")) ;; #497 quoted alias support (should behave like string) (subs (name e) 1) e) @@ -350,7 +350,7 @@ (let [n (cond-> (name k) *escape-?* (str/replace "?" "??"))] - (if (= \' (first n)) + (if (str/starts-with? n "'") (let [ident (subs n 1) ident-l (str/lower-case ident)] (binding [*quoted* (when-not (contains? #{"array"} ident-l) *quoted*)] @@ -419,13 +419,16 @@ ;; rather than name/namespace, we want to allow ;; for multiple / in the %fun.call case so that ;; qualified column names can be used: - (let [c (cond-> (str x) (keyword? x) (subs 1))] - (cond (= \% (first c)) + (let [c (if (keyword? x) + #?(:clj (str (.sym ^clojure.lang.Keyword x)) ;; Omits leading colon + :default (subs (str x) 1)) + (str x))] + (cond (str/starts-with? c "%") (let [[f & args] (str/split (subs c 1) #"\.")] [(str (format-fn-name f) "(" (join ", " (map #(format-entity (keyword %) opts)) args) ")")]) - (= \? (first c)) + (str/starts-with? c "?") (let [k (keyword (subs c 1))] (cond *inline* [(sqlize-value (param-value k))] @@ -433,7 +436,7 @@ (->numbered-param k) :else ["?" (->param k)])) - (= \' (first c)) + (str/starts-with? c "'") (do (reset! *formatted-column* true) [(subs c 1)])