Skip to content

[wrangler] Recognise a lowercase end when splitting D1 SQL statements - #15094

Closed
LeSingh1 wants to merge 1 commit into
cloudflare:mainfrom
LeSingh1:fix/d1-splitter-lowercase-end
Closed

[wrangler] Recognise a lowercase end when splitting D1 SQL statements#15094
LeSingh1 wants to merge 1 commit into
cloudflare:mainfrom
LeSingh1:fix/d1-splitter-lowercase-end

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #15093.

splitSqlQuery() matches the opening marker of a compound statement case-insensitively (/[\s]BEGIN\s*$/i, /[\s]CASE\s*$/i) but matched the closing one case-sensitively (/\sEND[;\s]$/). A trigger or CASE body closed with a lowercase end; therefore never terminated, and every statement after it in the file was swallowed into the compound statement and handed to D1 as one statement — silently dropping the intermediate result sets, with no error and only a wrong 🚣 N commands executed successfully. count as a hint.

The one-character fix is to match the closing marker case-insensitively too, so the two halves of the pair agree.

The added test covers a trigger body closed with end; followed by another statement. It fails on main (the two statements come back as one) and passes with the change; the 15 existing splitSqlQuery() tests are untouched and still pass.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: this restores the documented/expected behaviour of SQL splitting; no public API or documented behaviour changes.

Note

This is a contribution from an AI agent: Claude Code, Claude Opus 5.


Open in Devin Review

The compound-statement start marker (`BEGIN`/`CASE`) is matched
case-insensitively, but the closing `END` marker was not. A trigger body
closed with `end;` therefore never terminated, so every following
statement in the file was swallowed into it and sent to D1 as a single
statement.

Match the closing marker case-insensitively too.
@changeset-bot

changeset-bot Bot commented Aug 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d55226d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

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

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Aug 9, 2026
@workers-devprod
workers-devprod requested review from a team and emily-shen and removed request for a team August 9, 2026 00:59
@workers-devprod

workers-devprod commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/d1
  • ✅ @cloudflare/wrangler
Show detailed file reviewers
  • packages/wrangler/src/tests/d1/splitter.test.ts: [@cloudflare/d1]
  • packages/wrangler/src/d1/splitter.ts: [@cloudflare/d1]

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@dario-piotrowicz dario-piotrowicz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks @LeSingh1 😄

I only left one minor comment

Comment on lines +334 to +338
CREATE TRIGGER IF NOT EXISTS update_trigger AFTER UPDATE ON items
begin
DELETE FROM updates WHERE item_id=old.id;
end;
CREATE TABLE tasks (id INTEGER PRIMARY KEY);`)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you indent this SQL text? 🙏

@erwinzhang7

Copy link
Copy Markdown

Heads up, this is the same fix as #15046, same line in splitter.ts, and both PRs add .changeset/d1-splitter-lowercase-end.md, so whichever lands first the other will need a rebase on that file.

@LeSingh1

Copy link
Copy Markdown
Contributor Author

Thanks for flagging @erwinzhang7 — you are right, and #15046 came first (Aug 5 vs Aug 9). Same line, same fix, same changeset filename. My duplicate check only looked at my own open PRs, which is how I missed yours.

Happy to close this in favour of #15046. One hesitation: I hit this repo's open pull request limit earlier today and @petebacondarwin found he could not reopen a closed PR of mine either, so closing is not easily reversible right now. This one is already approved, so @dario-piotrowicz — would you rather I close it and take #15046, or land this and close that one? I am happy either way, and #15046 got there first so my vote is yours.

@petebacondarwin

petebacondarwin commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Thanks for the discussion. Closing this one in favour of #15046

@github-project-automation github-project-automation Bot moved this from Untriaged to Done in workers-sdk Aug 12, 2026
@dario-piotrowicz

Copy link
Copy Markdown
Member

@LeSingh1 sorry about that I got my wires crossed and forgot to that we had 15046 already with this fix 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

wrangler d1 execute --file silently merges statements after a compound statement closed with a lowercase end;

5 participants