mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-31 22:04:23 +01:00
Ensure virtual table name uniqueness
This commit is contained in:
@@ -475,19 +475,22 @@ pub fn translate_create_virtual_table(
|
||||
if !vtab_module.module_kind.eq(&VTabKind::VirtualTable) {
|
||||
bail_parse_error!("module {} is not a virtual table", module_name_str);
|
||||
};
|
||||
if schema.get_table(&table_name).is_some() && *if_not_exists {
|
||||
let mut program = ProgramBuilder::new(ProgramBuilderOpts {
|
||||
query_mode,
|
||||
num_cursors: 1,
|
||||
approx_num_insns: 5,
|
||||
approx_num_labels: 1,
|
||||
});
|
||||
let init_label = program.emit_init();
|
||||
program.emit_halt();
|
||||
program.preassign_label_to_next_insn(init_label);
|
||||
program.emit_transaction(true);
|
||||
program.emit_constant_insns();
|
||||
return Ok(program);
|
||||
if schema.get_table(&table_name).is_some() {
|
||||
if *if_not_exists {
|
||||
let mut program = ProgramBuilder::new(ProgramBuilderOpts {
|
||||
query_mode,
|
||||
num_cursors: 1,
|
||||
approx_num_insns: 5,
|
||||
approx_num_labels: 1,
|
||||
});
|
||||
let init_label = program.emit_init();
|
||||
program.emit_halt();
|
||||
program.preassign_label_to_next_insn(init_label);
|
||||
program.emit_transaction(true);
|
||||
program.emit_constant_insns();
|
||||
return Ok(program);
|
||||
}
|
||||
bail_parse_error!("Table {} already exists", tbl_name);
|
||||
}
|
||||
|
||||
let mut program = ProgramBuilder::new(ProgramBuilderOpts {
|
||||
|
||||
@@ -581,6 +581,36 @@ def test_sqlite_vfs_compat():
|
||||
sqlite.quit()
|
||||
|
||||
|
||||
def test_create_virtual_table():
|
||||
ext_path = "target/debug/liblimbo_ext_tests"
|
||||
|
||||
limbo = TestLimboShell()
|
||||
limbo.execute_dot(f".load {ext_path}")
|
||||
|
||||
limbo.debug_print("CREATE VIRTUAL TABLE t1 USING kv_store;")
|
||||
limbo.run_test_fn(
|
||||
"CREATE VIRTUAL TABLE t1 USING kv_store;",
|
||||
lambda res: "× Parse error: Table t1 already exists" == res,
|
||||
"create virtual table fails if virtual table with the same name already exists",
|
||||
)
|
||||
|
||||
limbo.debug_print("CREATE TABLE t2 (col INTEGER);")
|
||||
limbo.run_test_fn(
|
||||
"CREATE VIRTUAL TABLE t2 USING kv_store;",
|
||||
lambda res: "× Parse error: Table t2 already exists" == res,
|
||||
"create virtual table fails if regular table with the same name already exists",
|
||||
)
|
||||
|
||||
limbo.debug_print("CREATE VIRTUAL TABLE t3 USING kv_store;")
|
||||
limbo.run_test_fn(
|
||||
"CREATE TABLE t3 (col INTEGER);",
|
||||
lambda res: "× Parse error: Table t3 already exists" == res,
|
||||
"create table fails if virtual table with the same name already exists",
|
||||
)
|
||||
|
||||
limbo.quit()
|
||||
|
||||
|
||||
def cleanup():
|
||||
if os.path.exists("testing/vfs.db"):
|
||||
os.remove("testing/vfs.db")
|
||||
@@ -600,6 +630,7 @@ def main():
|
||||
test_sqlite_vfs_compat()
|
||||
test_kv()
|
||||
test_drop_virtual_table()
|
||||
test_create_virtual_table()
|
||||
except Exception as e:
|
||||
console.error(f"Test FAILED: {e}")
|
||||
cleanup()
|
||||
|
||||
Reference in New Issue
Block a user