From 110c31e2bcefa8398ab76fd9c47fd297046cf311 Mon Sep 17 00:00:00 2001 From: Starks Date: Wed, 22 Jul 2015 13:50:03 +0200 Subject: [PATCH 1/3] quoting of AS clauses should not be splitted on "." quoting of AS clauses should not be splitted on "." --- src/honeysql/format.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/honeysql/format.clj b/src/honeysql/format.clj index 590bfc7..1fae10b 100644 --- a/src/honeysql/format.clj +++ b/src/honeysql/format.clj @@ -303,7 +303,7 @@ " AS " " ") (if (string? (second x)) - (quote-identifier (second x)) + (quote-identifier (second x) :split false) (to-sql (second x)))))) SqlCall (to-sql [x] From 0a5eaedd9b58395aa80b1f708eebd964071cee35 Mon Sep 17 00:00:00 2001 From: Starks Date: Wed, 22 Jul 2015 17:06:56 +0200 Subject: [PATCH 2/3] quoting of AS clauses should not be splitted on "." quoting of AS clauses should not be splitted on "." --- src/honeysql/format.clj | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/honeysql/format.clj b/src/honeysql/format.clj index 1fae10b..4239423 100644 --- a/src/honeysql/format.clj +++ b/src/honeysql/format.clj @@ -85,7 +85,9 @@ "regex" "regexp"}) (defprotocol ToSql - (to-sql [x])) + (to-sql + [x] + [x & args])) (defmulti fn-handler (fn [op & args] op)) @@ -277,13 +279,14 @@ (extend-protocol ToSql clojure.lang.Keyword - (to-sql [x] + (to-sql [x & {:as args}] (let [s (name x)] (case (.charAt s 0) \% (let [call-args (string/split (subs s 1) #"\." 2)] (to-sql (apply call (map keyword call-args)))) \? (to-sql (param (keyword (subs s 1)))) - (quote-identifier x)))) + (->> (apply concat (select-keys args [:split])) + (apply quote-identifier x))))) clojure.lang.Symbol (to-sql [x] (quote-identifier x)) java.lang.Number @@ -302,9 +305,13 @@ (if (= :select *clause*) " AS " " ") - (if (string? (second x)) - (quote-identifier (second x) :split false) - (to-sql (second x)))))) + (cond (string? (second x)) + (quote-identifier (second x) :split false) + (keyword? (second x)) + (to-sql (second x) :split false) + :else + (to-sql (second x)) + )))) SqlCall (to-sql [x] (binding [*fn-context?* true] From 9eb87987ed00d4b4feb303e72c48a60fda4d1431 Mon Sep 17 00:00:00 2001 From: Starks Date: Wed, 22 Jul 2015 17:14:10 +0200 Subject: [PATCH 3/3] quoting of AS clauses should not be splitted on "." quoting of AS clauses should not be splitted on "." --- test/honeysql/core_test.clj | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/honeysql/core_test.clj b/test/honeysql/core_test.clj index cea3b31..7de548b 100644 --- a/test/honeysql/core_test.clj +++ b/test/honeysql/core_test.clj @@ -127,3 +127,10 @@ :from [:customers] :where [:in :id :?ids]} {:ids values}))))))) + +(deftest test-quoting + (testing ":quoting :ansi" + (is (= ["SELECT \"b\".\"bla\" AS \"bla.bla\", \"b\".\"bla\" AS \"blu.blu\" FROM \"baz\" \"b\"" ] + (-> (select [:b.bla :bla.bla] [:b.bla "blu.blu"]) + (from [:baz :b]) + (sql/format :quoting :ansi))))))