github.com/jdgcs/sqlite3@v1.12.1-0.20210908114423-bc5f96e4dd51/testdata/tcl/vtabdrop.test (about)

     1  # 2018 December 28
     2  #
     3  #    May you do good and not evil.
     4  #    May you find forgiveness for yourself and forgive others.
     5  #    May you share freely, never taking more than you give.
     6  #
     7  #***********************************************************************
     8  #
     9  # The tests in this file test edge cases surrounding DROP TABLE on 
    10  # virtual tables.
    11  #
    12  
    13  set testdir [file dirname $argv0]
    14  source $testdir/tester.tcl
    15  
    16  ifcapable !vtab { finish_test ; return }
    17  source $testdir/fts3_common.tcl
    18  source $testdir/malloc_common.tcl
    19  
    20  set testprefix vtabdrop
    21  
    22  #-------------------------------------------------------------------------
    23  # Test that if a DROP TABLE is executed against an rtree table, but the
    24  # xDestroy() call fails, the rtree table is not dropped, the sqlite_master
    25  # table is not modified and the internal schema remains intact.
    26  # 
    27  ifcapable rtree {
    28    do_execsql_test 1.0 {
    29      CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2);
    30      CREATE TABLE t1(x, y);
    31      INSERT INTO t1 VALUES(1, 2);
    32    }
    33    
    34    do_test 1.1 {
    35      execsql {
    36        BEGIN;
    37          INSERT INTO t1 VALUES(3, 4);
    38      }
    39      db eval { SELECT * FROM t1 } {
    40        catchsql { DROP TABLE rt }
    41      }
    42      execsql COMMIT
    43    } {}
    44    
    45    do_execsql_test 1.2 {
    46      SELECT name FROM sqlite_master ORDER BY 1;
    47      SELECT * FROM t1;
    48      SELECT * FROM rt;
    49    } {rt rt_node rt_parent rt_rowid t1 1 2 3 4}
    50    
    51    db close
    52    sqlite3 db test.db
    53    
    54    do_execsql_test 1.3 {
    55      SELECT name FROM sqlite_master ORDER BY 1;
    56    } {rt rt_node rt_parent rt_rowid t1}
    57  }
    58  
    59  #-------------------------------------------------------------------------
    60  # Same as tests 1.*, except with fts5 instead of rtree.
    61  # 
    62  ifcapable fts5 {
    63    reset_db
    64    do_execsql_test 2.0 {
    65      CREATE VIRTUAL TABLE ft USING fts5(x);
    66      CREATE TABLE t1(x, y);
    67      INSERT INTO t1 VALUES(1, 2);
    68    }
    69    
    70    do_test 2.1 {
    71      execsql {
    72        BEGIN;
    73          INSERT INTO t1 VALUES(3, 4);
    74      }
    75      db eval { SELECT * FROM t1 } {
    76        catchsql { DROP TABLE ft }
    77      }
    78      execsql COMMIT
    79    } {}
    80    
    81    do_execsql_test 2.2 {
    82      SELECT name FROM sqlite_master ORDER BY 1;
    83    } {ft ft_config ft_content ft_data ft_docsize ft_idx t1}
    84    
    85    db close
    86    sqlite3 db test.db
    87    
    88    do_execsql_test 2.3 {
    89      SELECT name FROM sqlite_master ORDER BY 1;
    90    } {ft ft_config ft_content ft_data ft_docsize ft_idx t1}
    91  }
    92  
    93  #-------------------------------------------------------------------------
    94  # Same as tests 1.*, except with fts3 instead of rtree.
    95  # 
    96  ifcapable fts3 {
    97    reset_db
    98    do_execsql_test 2.0 {
    99      CREATE VIRTUAL TABLE ft USING fts3(x);
   100      CREATE TABLE t1(x, y);
   101      INSERT INTO t1 VALUES(1, 2);
   102    }
   103    
   104    do_test 2.1 {
   105      execsql {
   106        BEGIN;
   107          INSERT INTO t1 VALUES(3, 4);
   108      }
   109      db eval { SELECT * FROM t1 } {
   110        catchsql { DROP TABLE ft }
   111      }
   112      execsql COMMIT
   113    } {}
   114    
   115    do_execsql_test 2.2 {
   116      SELECT name FROM sqlite_master ORDER BY 1;
   117    } {ft ft_content ft_segdir ft_segments sqlite_autoindex_ft_segdir_1 t1}
   118    
   119    db close
   120    sqlite3 db test.db
   121    
   122    do_execsql_test 2.3 {
   123      SELECT name FROM sqlite_master ORDER BY 1;
   124    } {ft ft_content ft_segdir ft_segments sqlite_autoindex_ft_segdir_1 t1}
   125  }
   126  
   127  finish_test