From dc2bb7cb9b3e2727301280135632daee9df6e784 Mon Sep 17 00:00:00 2001 From: Zaid Humayun Date: Sun, 9 Feb 2025 14:07:19 +0530 Subject: [PATCH] DropTable: implementation complete added helper methods to Schema to remove table and indices from in-memory structures completed the implementation for DropTable using that --- core/schema.rs | 10 ++++++++++ core/vdbe/mod.rs | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) 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();