-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
Open
Labels
sqliteIssues and PRs related to the SQLite subsystem.Issues and PRs related to the SQLite subsystem.
Description
Statement iterators that have not finished iterating are not invalidated when the statement is reset.
const { DatabaseSync } = require('node:sqlite');
const db = new DatabaseSync(':memory:')
db.exec('CREATE TABLE test (value INTEGER NOT NULL)');
for (let i = 0; i < 10; i++) {
db.prepare('INSERT INTO test (value) VALUES (?)').run(i);
}
const stmt = db.prepare('SELECT * FROM test');
const it = stmt.iterate();
it.next().value; // { value: 0 }
it.next().value; // { value: 1 }
it.next().value; // { value: 2 }
// resets, executes and re-resets statement
stmt.get(); // { value: 0 }
// sqlite3_step restarts from beginning of result
it.next().value; // { value: 0 }
it.next().value; // { value: 1 }
it.next().value; // { value: 2 }
// these will race
const it2 = stmt.iterate();
it.next().value; // { value: 0 }
it2.next().value; // { value: 1 }
it.next().value; // { value: 2 }
it2.next().value; // { value: 3 }If the statement iterator is not done and the statement is reset, then the iterator should be invalidated and subsequent calls to .next() should throw.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
sqliteIssues and PRs related to the SQLite subsystem.Issues and PRs related to the SQLite subsystem.