diff --git a/doc/differences-from-1-x.md b/doc/differences-from-1-x.md index 22e6bc8..ab94f6a 100644 --- a/doc/differences-from-1-x.md +++ b/doc/differences-from-1-x.md @@ -97,7 +97,7 @@ The following new syntax has been added: * `:inline` -- used as a function to replace the `sql/inline` / `#sql/inline` machinery, * `:interval` -- used as a function to support `INTERVAL `, e.g., `[:interval 30 :days]`. -> Note 1: `:inline` currently inlines strings like `"foo"` as `foo` which matches the 1.x behavior but this will almost certainly change to inline as `'foo'`, i.e., a SQL string value, before release. +> Note 1: in 1.x, inlining a string `"foo"` produced `foo` but in 2.x it produces `'foo'`, i.e., string literals become SQL strings without needing internal quotes (1.x required `"'foo'"`). > Note 2: expect `:raw` to be added in some form before release. diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index d446b3c..72f1ef4 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -421,7 +421,7 @@ (defn- sqlize-value [x] (cond (nil? x) "NULL" - (string? x) x ; I feel this should be 'single-quoted' but 1.x does not + (string? x) (str \' (str/replace x "'" "''") \') (symbol? x) (name x) (keyword? x) (name x) :else (str x))) diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index f843c76..793e033 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -309,8 +309,9 @@ (format {:dialect :mysql}))))) (deftest inlined-values-are-stringified-correctly - (is (= ["SELECT foo, bar, NULL"] + (is (= ["SELECT 'foo', 'It''s a quote!', bar, NULL"] (format {:select [[[:inline "foo"]] + [[:inline "It's a quote!"]] [[:inline :bar]] [[:inline nil]]]}))))