Skip to content

Do not name the result of CASE r, the row of UPDATE and DELETE, to close #3197 - #3198

Open
zzoraemon043 wants to merge 1 commit into
AlaSQL:mainfrom
zzoraemon043:fix/case-in-update-delete
Open

zzoraemon043 wants to merge 1 commit into
AlaSQL:mainfrom
zzoraemon043:fix/case-in-update-delete

Conversation

@zzoraemon043

Copy link
Copy Markdown
Contributor

Closes #3197

CaseValue.toJS wraps CASE in an arrow function whose parameter is the row variable and then declares let y, r; for the result. UPDATE, DELETE and CHECK compile with the row named r, so the generated function fails with Identifier 'r' has already been declared. SELECT uses p and was not affected.

The result is now caseResult, which none of the row variables (a, b, g, p, r, x) can be.

Same error before the fix, now working:

  • UPDATE s SET b = CASE WHEN a = 1 THEN 5 ELSE 1 END
  • UPDATE s SET b = 1 WHERE CASE WHEN a = 1 THEN 5 ELSE 1 END = 5
  • DELETE FROM s WHERE CASE a WHEN 2 THEN 1 ELSE 0 END = 1
  • CREATE TABLE c (a INT, b INT, CHECK (CASE WHEN a > 0 THEN b > 0 ELSE TRUE END))

test/test3197.js covers SET, nested CASE, WHERE of UPDATE and DELETE, and a CHECK constraint. All 6 fail before the change and pass after it. The full suite has no new failures (test107-B and test2149 fail the same way on main on Windows).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CASE in UPDATE or DELETE throws a SyntaxError

1 participant