Returned SQLite rows do not reflect column changes if the schema changes in a different process after a prepared statement is created
littledivy opened this issue · 1 comments
littledivy commented
Version
0.1.5
Platform
Darwin mini.local 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:47:26 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T8101 arm64
What steps will reproduce the bug?
import { Database } from "bun:sqlite";
const db = Database.open("test.db");
db.run("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)");
db.run("INSERT INTO test (id, name) VALUES (1, 'test')");
const stmt = db.prepare("SELECT * FROM test");
const result = stmt.all();
console.log(result);
db.run("ALTER TABLE test ADD COLUMN age INTEGER");
db.run("UPDATE test SET age = 20 WHERE id = 1");
const result2 = stmt.all();
console.log(result2);
db.run("ALTER TABLE test RENAME COLUMN age TO age2");
const result3 = stmt.all();
console.log(result3)
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
[ { id: 1, name: 'test' } ]
[ { id: 1, name: 'test', age: 20 } ]
[ { id: 1, name: 'test', age2: 20 } ]
(Should be same as better-sqlite3
and deno.land/x/sqlite
)
What do you see instead?
[ test { id: 1, name: "test" } ]
[ test { id: 1, name: "test" } ]
[ test { id: 1, name: "test" } ]
Additional information
Bun is caching column count/names for performance, skipping essential checks to invalidate the cache. If this is expected behaviour, please mention it in the benchmarks and docs.
littledivy commented
Not fixed. #1056 (review)