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

     1  # 2006 January 30
     2  #
     3  # The author disclaims copyright to this source code.  In place of
     4  # a legal notice, here is a blessing:
     5  #
     6  #    May you do good and not evil.
     7  #    May you find forgiveness for yourself and forgive others.
     8  #    May you share freely, never taking more than you give.
     9  #
    10  #***********************************************************************
    11  # This file implements regression tests for SQLite library.
    12  #
    13  # This file implements tests to verify that ticket #1644 is
    14  # fixed.  Ticket #1644 complains that precompiled statements
    15  # are not expired correctly as a result of changes to TEMP
    16  # views and triggers.
    17  #
    18  
    19  set testdir [file dirname $argv0]
    20  source $testdir/tester.tcl
    21  
    22  ifcapable !tempdb||!view {
    23    finish_test
    24    return
    25  }  
    26  
    27  # Create two tables T1 and T2 and make V1 point to T1.
    28  do_test tkt1644-1.1 {
    29    execsql {
    30      CREATE TABLE t1(a);
    31      INSERT INTO t1 VALUES(1);
    32      CREATE TABLE t2(b);
    33      INSERT INTO t2 VALUES(99);
    34      CREATE TEMP VIEW v1 AS SELECT * FROM t1;
    35      SELECT * FROM v1;
    36    }
    37  } {1}
    38  
    39  # The "SELECT * FROM v1" should be in the TCL interface cache below.
    40  # It will continue to point to T1 unless the cache is invalidated when
    41  # the view changes.
    42  #
    43  do_test tkt1644-1.2 {
    44    execsql {
    45      DROP VIEW v1;
    46      CREATE TEMP VIEW v1 AS SELECT * FROM t2;
    47      SELECT * FROM v1;
    48    }
    49  } {99}
    50  
    51  # Cache an access to the T1 table.
    52  #
    53  do_test tkt1644-1.3 {
    54    execsql {
    55      SELECT * FROM t1;
    56    }
    57  } {1}
    58  
    59  # Create a temp table T1.  Make sure the cache is invalidated so that
    60  # the statement is recompiled and refers to the empty temp table.
    61  #
    62  do_test tkt1644-1.4 {
    63    execsql {
    64      CREATE TEMP TABLE t1(x);
    65    }
    66    execsql {
    67      SELECT * FROM t1;
    68    }
    69  } {}
    70  
    71  ifcapable view {
    72    do_test tkt1644-2.1 {
    73      execsql {
    74        CREATE TEMP TABLE temp_t1(a, b);
    75      }
    76      set ::DB [sqlite3_connection_pointer db]
    77      set ::STMT [sqlite3_prepare $::DB "SELECT * FROM temp_t1" -1 DUMMY]
    78      execsql {
    79        DROP TABLE temp_t1;
    80      }
    81      list [sqlite3_step $::STMT] [sqlite3_finalize $::STMT]
    82    } {SQLITE_ERROR SQLITE_SCHEMA}
    83    
    84    do_test tkt1644-2.2 {
    85      execsql {
    86        CREATE TABLE real_t1(a, b);
    87        CREATE TEMP VIEW temp_v1 AS SELECT * FROM real_t1;
    88      }
    89      set ::DB [sqlite3_connection_pointer db]
    90      set ::STMT [sqlite3_prepare $::DB "SELECT * FROM temp_v1" -1 DUMMY]
    91      execsql {
    92        DROP VIEW temp_v1;
    93      }
    94      list [sqlite3_step $::STMT] [sqlite3_finalize $::STMT]
    95    } {SQLITE_ERROR SQLITE_SCHEMA}
    96  
    97    do_test tkt1644-2.3 {
    98      execsql {
    99        CREATE TEMP VIEW temp_v1 AS SELECT * FROM real_t1 LIMIT 10 OFFSET 10;
   100      }
   101      set ::DB [sqlite3_connection_pointer db]
   102      set ::STMT [sqlite3_prepare $::DB "SELECT * FROM temp_v1" -1 DUMMY]
   103      execsql {
   104        DROP VIEW temp_v1;
   105      }
   106      list [sqlite3_step $::STMT] [sqlite3_finalize $::STMT]
   107    } {SQLITE_ERROR SQLITE_SCHEMA}
   108  }
   109  
   110  
   111  finish_test