Repository navigation
Close a compound SQL statement when its END is lowercase - #15046
Conversation
🦋 Changeset detectedLatest commit: 2585d69 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Codeowners approval required for this PR:
Show detailed file reviewers |
alsuren
left a comment
There was a problem hiding this comment.
approve once changeset is fixed
|
Good catch, and correct on both counts. I had not read Rewritten in user-facing terms: it now says which commands are affected, what a user actually sees (statements after the block silently skipped), and keeps a short example. Dropped the reference to the internal helper and the paragraph about existing test coverage. I also confirmed the |
dario-piotrowicz
left a comment
There was a problem hiding this comment.
Looks good to me! 😄
Thanks for the fix @erwinzhang7 😄
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/config
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
|
Both taken, thank you. Dropped the comment: the test name already says what it checks, and the history of why it broke belongs in the changeset rather than the test body. Took the changelog title too, with the typo corrected: "Fixes D1 SQL statements not handling lowercase Also filled in the description checkboxes, which is what the The two Windows test failures look unrelated to this change. The suite passes on Linux and macOS, the failing jobs are |
|
The checks on this one are still pending workflow approval, could someone kick them off when you get a chance? |
d2dc2e8 to
3acbc9b
Compare
|
Hi! The CI failure was |
|
Both failures look unrelated to this change. Tests (Windows, fixtures) fails in @fixture/worker-with-unsafe-external-plugin, and Vite Plugin Playground fails pulling the proxy-everything container. This PR only touches packages/wrangler/src/d1/splitter.ts and its test. |
|
I think the main branch is locked while the wrangler team do a release. I've set it to auto-merge. Hopefully it will go in once the release is out. Thanks for your contribution. |
3acbc9b to
afbb076
Compare
|
Codeowners approval required for this PR:
Show detailed file reviewers |
afbb076 to
0baae01
Compare
splitSqlQuery matched the opening BEGIN/CASE of a compound statement case insensitively but matched the closing END case sensitively. SQLite accepts either case, so a trigger written with a lowercase end never closed and every following statement was folded into the trigger body instead of being split out. The existing tests already covered a lowercase begin, but always paired it with an uppercase END, so the asymmetry went unnoticed.
0baae01 to
2585d69
Compare
Resolves a conflict in packages/wrangler/src/d1/splitter.ts with cloudflare#15046, which added the case-insensitive flag to the compound-statement END marker. This branch's pattern already carries that flag and additionally treats punctuation as a token boundary, so the branch's version is kept.
Spotted while investigating #14991. Independent of that issue and of any fix for it.
The bug
splitSqlQuery()matches the two ends of a compound statement asymmetrically:SQLite accepts either case. With a lowercase
end, the compound statement never closes, socompoundStatementStackstays non-empty and every subsequent;is treated as being inside the trigger body. Everything after the trigger is folded into it instead of being split out and executed.Before, 2 statements, with the
CREATE TABLEswallowed:After, 3 statements, matching the uppercase behaviour exactly.
CASE ... endinside a trigger body is affected the same way, collapsing 3 statements into 1.Why it was not caught
should handle compound statements for BEGINsalready exercises a lowercasebegin, so case insensitivity was clearly intended. But every case in that test pairs it with an uppercaseEND, so only the start predicate was ever exercised in lowercase.Change
One character: add the
iflag toisCompoundStatementEnd, so both predicates agree.This does not widen what counts as an end marker beyond the existing behaviour.
\sENDstill requires whitespace immediately before, so an identifier such asweekend;does not match, exactly as it did not before.DISTINCT/BEGIN/ENDcase handling is not described anywhere in the public docs, and nothing about the supported SQL surface changes.Added
should handle a lowercase end closing a compound statement, placed next to the existing lowercase-begincoverage. Verified it is a real regression test rather than a passing assertion: with theiflag reverted the suite reports 1 failed of 16, and with the fix 16 of 16 pass.oxfmt --checkis clean on both changed files.