This commit is contained in:
pedrocarlo
2025-07-22 00:38:52 -03:00
parent 0779c23bbf
commit f0ff85a43c
2 changed files with 40 additions and 2 deletions

View File

@@ -1706,9 +1706,8 @@ impl Statement {
let mut res = self
.program
.step(&mut self.state, self.mv_store.clone(), self.pager.clone());
for i in 0..MAX_SCHEMA_RETRY {
for _ in 0..MAX_SCHEMA_RETRY {
// Only reprepare if we still need to update schema
dbg!(i);
if !matches!(res, Err(LimboError::SchemaUpdated)) {
break;
}

View File

@@ -24,3 +24,42 @@ fn test_txn_error_doesnt_rollback_txn() -> Result<()> {
Ok(())
}
#[test]
fn test_schema_reprepare() {
let tmp_db = TempDatabase::new_empty(false);
let conn1 = tmp_db.connect_limbo();
conn1.execute("CREATE TABLE t(x, y, z)").unwrap();
conn1
.execute("INSERT INTO t VALUES (1, 2, 3), (10, 20, 30)")
.unwrap();
let conn2 = tmp_db.connect_limbo();
let mut stmt = conn2.prepare("SELECT y, z FROM t").unwrap();
let mut stmt2 = conn2.prepare("SELECT x, z FROM t").unwrap();
conn1.execute("ALTER TABLE t DROP COLUMN x").unwrap();
assert_eq!(
stmt2.step().unwrap_err().to_string(),
"Parse error: no such column: x"
);
let mut rows = Vec::new();
loop {
match stmt.step().unwrap() {
turso_core::StepResult::Done => {
break;
}
turso_core::StepResult::Row => {
let row = stmt.row().unwrap();
rows.push((row.get::<i64>(0).unwrap(), row.get::<i64>(1).unwrap()));
}
turso_core::StepResult::IO => {
stmt.run_once().unwrap();
}
step => panic!("unexpected step result {step:?}"),
}
}
let row = rows[0];
assert_eq!(row, (2, 3));
let row = rows[1];
assert_eq!(row, (20, 30));
}