fix(ext/node): reset statement immidiately in run() (#28506)

Fixes https://github.com/denoland/deno/issues/28492
This commit is contained in:
Divy Srivastava 2025-03-15 20:14:24 +05:30 committed by GitHub
parent 5f00b9700f
commit c638f9ade1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View file

@ -449,9 +449,11 @@ impl StatementSync {
self.bind_params(scope, params)?;
let _reset = ResetGuard(self);
let reset = ResetGuard(self);
self.step()?;
// Reset to return correct change metadata.
drop(reset);
Ok(RunStatementResult {
last_insert_rowid: db.last_insert_rowid(),

View file

@ -286,3 +286,25 @@ Deno.test("[node/sqlite] StatementSync reset guards don't lock db", () => {
db.exec("DROP TABLE IF EXISTS foo");
});
// https://github.com/denoland/deno/issues/28492
Deno.test("[node/sqlite] StatementSync reset step change metadata", () => {
const db = new DatabaseSync(":memory:");
db.exec(`CREATE TABLE people (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
birthdate TEXT NOT NULL
) STRICT`);
const insertPeople = db.prepare(`
INSERT INTO people
(name, birthdate)
VALUES
(:name, :birthdate)
RETURNING id
`);
const id1 = insertPeople.run({ name: "Flash", birthdate: "1956-07-16" });
assertEquals(id1, { lastInsertRowid: 1, changes: 1 });
});