os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/pager3.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/pager3.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,73 @@
     1.4 +# 2001 September 15
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +# This file implements regression tests for SQLite library.  The
    1.15 +# focus of this script is page cache subsystem.
    1.16 +#
    1.17 +# $Id: pager3.test,v 1.3 2005/03/29 03:11:00 danielk1977 Exp $
    1.18 +
    1.19 +
    1.20 +set testdir [file dirname $argv0]
    1.21 +source $testdir/tester.tcl
    1.22 +
    1.23 +# This test makes sure the database file is truncated back to the correct
    1.24 +# length on a rollback.
    1.25 +#
    1.26 +# After some preliminary setup, a transaction is start at NOTE (1).
    1.27 +# The create table on the following line allocates an additional page
    1.28 +# at the end of the database file.  But that page is not written because
    1.29 +# the database still has a RESERVED lock, not an EXCLUSIVE lock.  The
    1.30 +# new page is held in memory and the size of the file is unchanged.
    1.31 +# The insert at NOTE (2) begins adding additional pages.  Then it hits
    1.32 +# a constraint error and aborts.  The abort causes sqlite3OsTruncate()
    1.33 +# to be called to restore the file to the same length as it was after
    1.34 +# the create table.  But the create table results had not yet been
    1.35 +# written so the file is actually lengthened by this truncate.  Finally,
    1.36 +# the rollback at NOTE (3) is called to undo all the changes since the
    1.37 +# begin.  This rollback should truncate the database again.
    1.38 +# 
    1.39 +# This test was added because the second truncate at NOTE (3) was not
    1.40 +# occurring on early versions of SQLite 3.0.
    1.41 +#
    1.42 +ifcapable tempdb {
    1.43 +  do_test pager3-1.1 {
    1.44 +    execsql {
    1.45 +      create table t1(a unique, b);
    1.46 +      insert into t1 values(1, 'abcdefghijklmnopqrstuvwxyz');
    1.47 +      insert into t1 values(2, 'abcdefghijklmnopqrstuvwxyz');
    1.48 +      update t1 set b=b||a||b;
    1.49 +      update t1 set b=b||a||b;
    1.50 +      update t1 set b=b||a||b;
    1.51 +      update t1 set b=b||a||b;
    1.52 +      update t1 set b=b||a||b;
    1.53 +      update t1 set b=b||a||b;
    1.54 +      create temp table t2 as select * from t1;
    1.55 +      begin;                  ------- NOTE (1)
    1.56 +      create table t3(x);
    1.57 +    }
    1.58 +    catchsql {
    1.59 +      insert into t1 select 4-a, b from t2;  ----- NOTE (2)
    1.60 +    }
    1.61 +    execsql {
    1.62 +      rollback;  ------- NOTE (3)
    1.63 +    }
    1.64 +    db close
    1.65 +    sqlite3 db test.db
    1.66 +    set r ok
    1.67 +    ifcapable {integrityck} {
    1.68 +      set r [execsql {
    1.69 +        pragma integrity_check;
    1.70 +      }]
    1.71 +    }
    1.72 +    set r
    1.73 +  } ok
    1.74 +}
    1.75 +
    1.76 +finish_test