DropTable: implementation complete

added helper methods to Schema to remove table and indices from in-memory structures
completed the implementation for DropTable using that
This commit is contained in:
Zaid Humayun
2025-02-09 14:07:19 +05:30
parent 40b08c559c
commit dc2bb7cb9b
2 changed files with 16 additions and 1 deletions

View File

@@ -30,6 +30,11 @@ impl Schema {
self.tables.insert(name, table);
}
pub fn remove_table(&mut self, table_name: &str) {
let name = normalize_ident(table_name);
self.tables.remove(&name);
}
pub fn get_table(&self, name: &str) -> Option<Rc<BTreeTable>> {
let name = normalize_ident(name);
self.tables.get(&name).cloned()
@@ -42,6 +47,11 @@ impl Schema {
.or_default()
.push(index.clone())
}
pub fn remove_indices_for_table(&mut self, table_name: &str) {
let name = normalize_ident(table_name);
self.indexes.remove(&name);
}
}
#[derive(Clone, Debug)]

View File

@@ -2709,7 +2709,12 @@ impl Program {
if *db > 0 {
todo!("temp databases not implemented yet");
}
// TODO (Zaid): implement the functionality to clean up in-memory structures for table_name
if let Some(conn) = self.connection.upgrade() {
let mut schema = RefCell::borrow_mut(&conn.schema);
schema.remove_indices_for_table(table_name);
schema.remove_table(table_name);
}
state.pc += 1;
}
Insn::Close { cursor_id } => {
let mut cursors = state.cursors.borrow_mut();