mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-18 09:04:19 +01:00
Fix panic on CREATE VIRTUAL TABLE IF NOT EXISTS by halting VM properly
Fixes a runtime panic caused by failing to halt the virtual machine after executing CREATE VIRTUAL TABLE IF NOT EXISTS. Previously resulted in: thread 'main' panicked at core/vdbe/mod.rs:408:52: index out of bounds: the len is 3 but the index is 3
This commit is contained in:
@@ -484,10 +484,12 @@ pub fn translate_create_virtual_table(
|
|||||||
approx_num_labels: 1,
|
approx_num_labels: 1,
|
||||||
});
|
});
|
||||||
let init_label = program.emit_init();
|
let init_label = program.emit_init();
|
||||||
|
let start_offset = program.offset();
|
||||||
program.emit_halt();
|
program.emit_halt();
|
||||||
program.preassign_label_to_next_insn(init_label);
|
program.preassign_label_to_next_insn(init_label);
|
||||||
program.emit_transaction(true);
|
program.emit_transaction(true);
|
||||||
program.emit_constant_insns();
|
program.emit_constant_insns();
|
||||||
|
program.emit_goto(start_offset);
|
||||||
return Ok(program);
|
return Ok(program);
|
||||||
}
|
}
|
||||||
bail_parse_error!("Table {} already exists", tbl_name);
|
bail_parse_error!("Table {} already exists", tbl_name);
|
||||||
|
|||||||
@@ -593,6 +593,11 @@ def test_create_virtual_table():
|
|||||||
lambda res: "× Parse error: Table t1 already exists" == res,
|
lambda res: "× Parse error: Table t1 already exists" == res,
|
||||||
"create virtual table fails if virtual table with the same name already exists",
|
"create virtual table fails if virtual table with the same name already exists",
|
||||||
)
|
)
|
||||||
|
limbo.run_test_fn(
|
||||||
|
"CREATE VIRTUAL TABLE IF NOT EXISTS t1 USING kv_store;",
|
||||||
|
null,
|
||||||
|
"create virtual table with IF NOT EXISTS succeeds",
|
||||||
|
)
|
||||||
|
|
||||||
limbo.debug_print("CREATE TABLE t2 (col INTEGER);")
|
limbo.debug_print("CREATE TABLE t2 (col INTEGER);")
|
||||||
limbo.run_test_fn(
|
limbo.run_test_fn(
|
||||||
@@ -600,6 +605,11 @@ def test_create_virtual_table():
|
|||||||
lambda res: "× Parse error: Table t2 already exists" == res,
|
lambda res: "× Parse error: Table t2 already exists" == res,
|
||||||
"create virtual table fails if regular table with the same name already exists",
|
"create virtual table fails if regular table with the same name already exists",
|
||||||
)
|
)
|
||||||
|
limbo.run_test_fn(
|
||||||
|
"CREATE VIRTUAL TABLE IF NOT EXISTS t2 USING kv_store;",
|
||||||
|
null,
|
||||||
|
"create virtual table with IF NOT EXISTS succeeds",
|
||||||
|
)
|
||||||
|
|
||||||
limbo.debug_print("CREATE VIRTUAL TABLE t3 USING kv_store;")
|
limbo.debug_print("CREATE VIRTUAL TABLE t3 USING kv_store;")
|
||||||
limbo.run_test_fn(
|
limbo.run_test_fn(
|
||||||
|
|||||||
Reference in New Issue
Block a user