Fix inline string behavior

This commit is contained in:
Sean Corfield 2020-09-25 16:38:11 -07:00
parent 63a079ca8d
commit 1ebbbc1772
3 changed files with 4 additions and 3 deletions

View file

@ -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 <n> <units>`, 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.

View file

@ -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)))

View file

@ -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]]]}))))