Quote ALTER SCHEMA SET values - #70
jacodegroothydrab wants to merge 5 commits into
Conversation
|
Please escape control characters such as Also, please remove or substantially shorten the explanatory comment blocks in |
|
I have addressed your feedback
Please let me know if you require further changes. |
|
Rather than extending the replacement chain one character at a time, please use the existing escaped = json.dumps(str(value), ensure_ascii=False)[1:-1].replace("'", "''")Please add regression coverage containing |
|
Done — the fallback now uses |
4c599b4 to
403ffa7
Compare
|
The
|
|
@jacodegroothydrab are you still interested in getting this merged? |
Yes, still interested. Apologies for the delay, I have been travelling and didn't spot your feedback I will implement your improvements by EOD |
…e literal
update_schema built its SQL literal with a bare f"'{new_value}'", so an
apostrophe in the value ended the string early and the rest arrived as bare SQL:
001003 (42000): SQL compilation error: syntax error line 1 at position 39
unexpected 'comment'. on ALTER SCHEMA MY_DB.MY_SCHEMA SET comment = '...
Any schema comment containing an apostrophe therefore fails to apply. Only the
ALTER path is affected -- CREATE already renders through props.quote_value,
which dollar-quotes and needs no escaping. update_schema was the one branch
that hand-rolled its quoting; it now goes through quote_value too.
quote_value itself had the mirror-image gap: $$ is a safe delimiter only while
the value does not contain $$. It now falls back to a single-quoted literal
with ' and backslash doubled in that case, so a value cannot break out by
either route.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Snowflake needs escape sequences, not raw control characters, inside a single-quoted literal, so the $$ fallback regressed multiline values. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The hand-rolled replacement chain covered newline, carriage return and tab but left backspace, form feed, NUL and the rest of the C0 range raw in the single-quoted literal. json.dumps escapes the whole range using the same backslash syntax Snowflake accepts, so the fallback now only has to double apostrophes on top of it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Same hand-rolled f"'{new_value}'" as update_schema, same fix. Adds a
test with a `"` in the $$ fallback and collapses the quote_value tests
into one parametrized case.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
403ffa7 to
37b0aec
Compare
|
Rebased on current
|
|
Nice fix for the embedded Verified directly: >>> quote_value("abc$")
'$$abc$$$'
>>> quote_value("$")
'$$$$$'Both are unbalanced and reproduce the same syntax-error class this PR is fixing, just triggered by a trailing single Suggested fix: also route the trailing- if "$$" in str(value) or str(value).endswith("$"):Separately (lower confidence): the single-quote fallback escapes control characters using JSON-style sequences (backslash-u0000, backslash-b, backslash-f, etc.), assuming Snowflake decodes those identically to JSON. Might be worth confirming against a live account for the rarer ones (e.g. NUL), since only this PR's own test currently asserts that mapping is correct. |
update_schemabuilds its literal by hand:so an apostrophe ends the string early and the rest arrives as bare SQL:
Any schema comment containing an apostrophe fails to apply.
CREATEis unaffected — it already renders throughprops.quote_value.update_schemawas the one branch that hand-rolled its quoting; it now usesquote_valuetoo.quote_valuehad the mirror-image gap:$$is a safe delimiter only while the value doesn't contain$$. It now falls back to a single-quoted literal with'and backslash doubled in that case.4 regression tests, all four failing against the current code.