Repository: tursodatabase/limbo (rust)

Issue:
DROP TABLE IF EXISTS crashes if table exists
```
limbo> CREATE TABLE t(x);
limbo> DROP TABLE IF EXISTS t;
thread 'main' panicked at core/vdbe/mod.rs:309:18:
cursor id out of bounds
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```


Pull request:
core: Fix Destroy opcode root page handling
The `p1` register points to the root page, not to a cursor.

Fixes #1136

Patch:
diff --git a/core/vdbe/mod.rs b/core/vdbe/mod.rs
index 30337cb3..e3cf91a0 100644
--- a/core/vdbe/mod.rs
+++ b/core/vdbe/mod.rs
@@ -3110,11 +3110,8 @@ impl Program {
                     if *is_temp == 1 {
                         todo!("temp databases not implemented yet.");
                     }
-                    {
-                        let mut cursor = state.get_cursor(*root);
-                        let cursor = cursor.as_btree_mut();
-                        cursor.btree_destroy()?;
-                    }
+                    let mut cursor = BTreeCursor::new(None, pager.clone(), *root);
+                    cursor.btree_destroy()?;
                     state.pc += 1;
                 }
                 Insn::DropTable {


Test patch:
diff --git a/testing/all.test b/testing/all.test
index 8e0dd2df..857224ef 100755
--- a/testing/all.test
+++ b/testing/all.test
@@ -27,3 +27,4 @@ source $testdir/offset.test
 source $testdir/scalar-functions-printf.test
 source $testdir/transactions.test
 source $testdir/update.test
+source $testdir/drop_table.test
diff --git a/testing/drop_table.test b/testing/drop_table.test
index 9b5ae8d7..c6daf04d 100755
--- a/testing/drop_table.test
+++ b/testing/drop_table.test
@@ -26,23 +26,23 @@ do_execsql_test_on_specific_db {:memory:} drop-table-if-exists-2 {
 } {success}
 
 # Test dropping table with index
-do_execsql_test_on_specific_db {:memory:} drop-table-with-index-1 {
-    CREATE TABLE t3(x INTEGER PRIMARY KEY, y TEXT);
-    CREATE INDEX idx_t3_y ON t3(y);
-    INSERT INTO t3 VALUES(1, 'one');
-    DROP TABLE t3;
-    SELECT count(*) FROM sqlite_schema WHERE tbl_name='t3';
-} {0}
+#do_execsql_test_on_specific_db {:memory:} drop-table-with-index-1 {
+#    CREATE TABLE t3(x INTEGER PRIMARY KEY, y TEXT);
+#    CREATE INDEX idx_t3_y ON t3(y);
+#    INSERT INTO t3 VALUES(1, 'one');
+#    DROP TABLE t3;
+#    SELECT count(*) FROM sqlite_schema WHERE tbl_name='t3';
+#} {0}
 
 # Test dropping table cleans up related schema entries
-do_execsql_test_on_specific_db {:memory:} drop-table-schema-cleanup-1 {
-    CREATE TABLE t4(x INTEGER PRIMARY KEY, y TEXT);
-    CREATE INDEX idx1_t4 ON t4(x);
-    CREATE INDEX idx2_t4 ON t4(y);
-    INSERT INTO t4 VALUES(1, 'one');
-    DROP TABLE t4;
-    SELECT count(*) FROM sqlite_schema WHERE tbl_name='t4';
-} {0}
+#do_execsql_test_on_specific_db {:memory:} drop-table-schema-cleanup-1 {
+#    CREATE TABLE t4(x INTEGER PRIMARY KEY, y TEXT);
+#    CREATE INDEX idx1_t4 ON t4(x);
+#    CREATE INDEX idx2_t4 ON t4(y);
+#    INSERT INTO t4 VALUES(1, 'one');
+#    DROP TABLE t4;
+#    SELECT count(*) FROM sqlite_schema WHERE tbl_name='t4';
+#} {0}
 
 # Test dropping table after multiple inserts and deletes
 do_execsql_test_on_specific_db {:memory:} drop-table-after-ops-1 {
@@ -53,4 +53,4 @@ do_execsql_test_on_specific_db {:memory:} drop-table-after-ops-1 {
     INSERT INTO t6 VALUES (3);
     DROP TABLE t6;
     SELECT count(*) FROM sqlite_schema WHERE type='table' AND name='t6';
-} {0}
\ No newline at end of file
+} {0}