Skip to content

Read IN and NOT IN subqueries of a WHILE condition in every round to close #3200 - #3210

Open
zzoraemon043 wants to merge 1 commit into
AlaSQL:mainfrom
zzoraemon043:fix/while-in-subquery
Open

zzoraemon043 wants to merge 1 commit into
AlaSQL:mainfrom
zzoraemon043:fix/while-in-subquery

Conversation

@zzoraemon043

Copy link
Copy Markdown
Contributor

Thank you for the time you are putting into AlaSQL!

Closes #3200

alasql.precompile gives the WHILE one run context, and the condition is evaluated with it in every round. The IN and NOT IN lookup keeps the subquery result in this.ctx.caches, so the first round's result was used for the whole loop.

Each round now evaluates the condition with a run context of its own, on an object made with Object.create from the WHILE, so this.queriesfn is read as before and nothing is written to the statement.

Before the fix / after:

  • WHILE 1 IN (SELECT x FROM w) BEGIN DELETE FROM w WHERE x = 1; ... IF @n > 5 BREAK; END gives @n = 6 / 1
  • WHILE 1 NOT IN (SELECT x FROM w) BEGIN INSERT INTO w VALUES (1); ... END gives 6 / 1
  • the same through alasql.promise (the asynchronous loop) gives 6 / 1

test/test3200.js covers IN, NOT IN, a row deleted in each round, and the asynchronous loop. All 4 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.

A WHILE condition with IN (SELECT ...) reads the subquery only in the first round

1 participant