sl@0: # 2001 September 15 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. The sl@0: # focus of this script is page cache subsystem. sl@0: # sl@0: # $Id: pager3.test,v 1.3 2005/03/29 03:11:00 danielk1977 Exp $ sl@0: sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # This test makes sure the database file is truncated back to the correct sl@0: # length on a rollback. sl@0: # sl@0: # After some preliminary setup, a transaction is start at NOTE (1). sl@0: # The create table on the following line allocates an additional page sl@0: # at the end of the database file. But that page is not written because sl@0: # the database still has a RESERVED lock, not an EXCLUSIVE lock. The sl@0: # new page is held in memory and the size of the file is unchanged. sl@0: # The insert at NOTE (2) begins adding additional pages. Then it hits sl@0: # a constraint error and aborts. The abort causes sqlite3OsTruncate() sl@0: # to be called to restore the file to the same length as it was after sl@0: # the create table. But the create table results had not yet been sl@0: # written so the file is actually lengthened by this truncate. Finally, sl@0: # the rollback at NOTE (3) is called to undo all the changes since the sl@0: # begin. This rollback should truncate the database again. sl@0: # sl@0: # This test was added because the second truncate at NOTE (3) was not sl@0: # occurring on early versions of SQLite 3.0. sl@0: # sl@0: ifcapable tempdb { sl@0: do_test pager3-1.1 { sl@0: execsql { sl@0: create table t1(a unique, b); sl@0: insert into t1 values(1, 'abcdefghijklmnopqrstuvwxyz'); sl@0: insert into t1 values(2, 'abcdefghijklmnopqrstuvwxyz'); sl@0: update t1 set b=b||a||b; sl@0: update t1 set b=b||a||b; sl@0: update t1 set b=b||a||b; sl@0: update t1 set b=b||a||b; sl@0: update t1 set b=b||a||b; sl@0: update t1 set b=b||a||b; sl@0: create temp table t2 as select * from t1; sl@0: begin; ------- NOTE (1) sl@0: create table t3(x); sl@0: } sl@0: catchsql { sl@0: insert into t1 select 4-a, b from t2; ----- NOTE (2) sl@0: } sl@0: execsql { sl@0: rollback; ------- NOTE (3) sl@0: } sl@0: db close sl@0: sqlite3 db test.db sl@0: set r ok sl@0: ifcapable {integrityck} { sl@0: set r [execsql { sl@0: pragma integrity_check; sl@0: }] sl@0: } sl@0: set r sl@0: } ok sl@0: } sl@0: sl@0: finish_test