This commit is contained in:
Jarred Sumner
2024-06-20 16:24:34 -07:00
parent 1bd57adcbc
commit 144f815820
2 changed files with 14 additions and 2 deletions

View File

@@ -2219,6 +2219,8 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionRun, (JSC::JSGlob
DO_REBIND(arg0);
}
int total_changes_before = sqlite3_total_changes(castedThis->version_db->db);
int status = sqlite3_step(stmt);
if (!sqlite3_stmt_readonly(stmt)) {
castedThis->version_db->version++;
@@ -2228,8 +2230,6 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionRun, (JSC::JSGlob
initializeColumnNames(lexicalGlobalObject, castedThis);
}
int total_changes_before = sqlite3_total_changes(castedThis->version_db->db);
while (status == SQLITE_ROW) {
status = sqlite3_step(stmt);
}

View File

@@ -1251,3 +1251,15 @@ it("query should work if the cached statement was finalized", () => {
expect(() => prevQuery.get()).toThrow();
}
});
// https://github.com/oven-sh/bun/issues/12012
it("reports changes in Statement#run", () => {
const db = new Database(":memory:");
db.exec("CREATE TABLE cats (id INTEGER PRIMARY KEY, name TEXT)");
const sql = "INSERT INTO cats (name) VALUES ('Fluffy'), ('Furry')";
expect(db.run(sql).changes).toBe(2);
expect(db.prepare(sql).run().changes).toBe(2);
expect(db.query(sql).run().changes).toBe(2);
});