Which Cloudflare product(s) does this pertain to?
Wrangler core, D1
What versions are you using?
main (reproduced at 898dc6e)
Describe the Bug
splitSqlIntoStatements() in packages/wrangler/src/d1/splitter.ts scans for quotes so that SQL syntax inside them is not interpreted. It handles ', " and backticks, but not SQLite's bracket-quoted identifiers ([name]).
As a result a trigger body that references such an identifier is split apart. Given:
CREATE TRIGGER t AFTER INSERT ON items
BEGIN
UPDATE x SET [end] = 1;
UPDATE y SET z = 2;
END;
SELECT 1;
splitSqlQuery() returns four fragments instead of two:
CREATE TRIGGER t AFTER INSERT ON items\nBEGIN\n UPDATE x SET [end] = 1
UPDATE y SET z = 2
END
SELECT 1
Each fragment is then sent to D1 separately, so wrangler d1 execute --file and wrangler d1 migrations apply fail or apply a migration partially.
Notably normalizeSqlLineEndings(), in the same file, does treat [ … ] as a quote pair, so the two scanners disagree about the same syntax.
Please provide a link to a minimal reproduction
The snippet above reproduces directly through splitSqlQuery(); no account or network access is needed.
Additional context
Found while working on #15226, which fixes a different splitter issue (compound statement markers that are not padded with whitespace). This one is pre-existing and independent — it reproduces identically before and after that change — and needs a fix in the scanner rather than in the marker regexes, so it is filed separately. Happy to send a PR.
Which Cloudflare product(s) does this pertain to?
Wrangler core, D1
What versions are you using?
main(reproduced at 898dc6e)Describe the Bug
splitSqlIntoStatements()inpackages/wrangler/src/d1/splitter.tsscans for quotes so that SQL syntax inside them is not interpreted. It handles',"and backticks, but not SQLite's bracket-quoted identifiers ([name]).As a result a trigger body that references such an identifier is split apart. Given:
splitSqlQuery()returns four fragments instead of two:Each fragment is then sent to D1 separately, so
wrangler d1 execute --fileandwrangler d1 migrations applyfail or apply a migration partially.Notably
normalizeSqlLineEndings(), in the same file, does treat[…]as a quote pair, so the two scanners disagree about the same syntax.Please provide a link to a minimal reproduction
The snippet above reproduces directly through
splitSqlQuery(); no account or network access is needed.Additional context
Found while working on #15226, which fixes a different splitter issue (compound statement markers that are not padded with whitespace). This one is pre-existing and independent — it reproduces identically before and after that change — and needs a fix in the scanner rather than in the marker regexes, so it is filed separately. Happy to send a PR.