diff --git a/core/schema.rs b/core/schema.rs index 38bcf86a5..f4a1643a9 100644 --- a/core/schema.rs +++ b/core/schema.rs @@ -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> { 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)] diff --git a/core/vdbe/mod.rs b/core/vdbe/mod.rs index 45e23fa85..fc458157d 100644 --- a/core/vdbe/mod.rs +++ b/core/vdbe/mod.rs @@ -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();