sl@0: # 2006 January 30 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. sl@0: # sl@0: # This file implements tests to verify that ticket #1644 is sl@0: # fixed. Ticket #1644 complains that precompiled statements sl@0: # are not expired correctly as a result of changes to TEMP sl@0: # views and triggers. sl@0: # sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable !tempdb||!view { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Create two tables T1 and T2 and make V1 point to T1. sl@0: do_test tkt1644-1.1 { sl@0: execsql { sl@0: CREATE TABLE t1(a); sl@0: INSERT INTO t1 VALUES(1); sl@0: CREATE TABLE t2(b); sl@0: INSERT INTO t2 VALUES(99); sl@0: CREATE TEMP VIEW v1 AS SELECT * FROM t1; sl@0: SELECT * FROM v1; sl@0: } sl@0: } {1} sl@0: sl@0: # The "SELECT * FROM v1" should be in the TCL interface cache below. sl@0: # It will continue to point to T1 unless the cache is invalidated when sl@0: # the view changes. sl@0: # sl@0: do_test tkt1644-1.2 { sl@0: execsql { sl@0: DROP VIEW v1; sl@0: CREATE TEMP VIEW v1 AS SELECT * FROM t2; sl@0: SELECT * FROM v1; sl@0: } sl@0: } {99} sl@0: sl@0: # Cache an access to the T1 table. sl@0: # sl@0: do_test tkt1644-1.3 { sl@0: execsql { sl@0: SELECT * FROM t1; sl@0: } sl@0: } {1} sl@0: sl@0: # Create a temp table T1. Make sure the cache is invalidated so that sl@0: # the statement is recompiled and refers to the empty temp table. sl@0: # sl@0: do_test tkt1644-1.4 { sl@0: execsql { sl@0: CREATE TEMP TABLE t1(x); sl@0: } sl@0: execsql { sl@0: SELECT * FROM t1; sl@0: } sl@0: } {} sl@0: sl@0: ifcapable view { sl@0: do_test tkt1644-2.1 { sl@0: execsql { sl@0: CREATE TEMP TABLE temp_t1(a, b); sl@0: } sl@0: set ::DB [sqlite3_connection_pointer db] sl@0: set ::STMT [sqlite3_prepare $::DB "SELECT * FROM temp_t1" -1 DUMMY] sl@0: execsql { sl@0: DROP TABLE temp_t1; sl@0: } sl@0: list [sqlite3_step $::STMT] [sqlite3_finalize $::STMT] sl@0: } {SQLITE_ERROR SQLITE_SCHEMA} sl@0: sl@0: do_test tkt1644-2.2 { sl@0: execsql { sl@0: CREATE TABLE real_t1(a, b); sl@0: CREATE TEMP VIEW temp_v1 AS SELECT * FROM real_t1; sl@0: } sl@0: set ::DB [sqlite3_connection_pointer db] sl@0: set ::STMT [sqlite3_prepare $::DB "SELECT * FROM temp_v1" -1 DUMMY] sl@0: execsql { sl@0: DROP VIEW temp_v1; sl@0: } sl@0: list [sqlite3_step $::STMT] [sqlite3_finalize $::STMT] sl@0: } {SQLITE_ERROR SQLITE_SCHEMA} sl@0: sl@0: do_test tkt1644-2.3 { sl@0: execsql { sl@0: CREATE TEMP VIEW temp_v1 AS SELECT * FROM real_t1 LIMIT 10 OFFSET 10; sl@0: } sl@0: set ::DB [sqlite3_connection_pointer db] sl@0: set ::STMT [sqlite3_prepare $::DB "SELECT * FROM temp_v1" -1 DUMMY] sl@0: execsql { sl@0: DROP VIEW temp_v1; sl@0: } sl@0: list [sqlite3_step $::STMT] [sqlite3_finalize $::STMT] sl@0: } {SQLITE_ERROR SQLITE_SCHEMA} sl@0: } sl@0: sl@0: sl@0: finish_test