|
1 # 2001 September 15 |
|
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. The |
|
12 # focus of this script is page cache subsystem. |
|
13 # |
|
14 # $Id: pager3.test,v 1.3 2005/03/29 03:11:00 danielk1977 Exp $ |
|
15 |
|
16 |
|
17 set testdir [file dirname $argv0] |
|
18 source $testdir/tester.tcl |
|
19 |
|
20 # This test makes sure the database file is truncated back to the correct |
|
21 # length on a rollback. |
|
22 # |
|
23 # After some preliminary setup, a transaction is start at NOTE (1). |
|
24 # The create table on the following line allocates an additional page |
|
25 # at the end of the database file. But that page is not written because |
|
26 # the database still has a RESERVED lock, not an EXCLUSIVE lock. The |
|
27 # new page is held in memory and the size of the file is unchanged. |
|
28 # The insert at NOTE (2) begins adding additional pages. Then it hits |
|
29 # a constraint error and aborts. The abort causes sqlite3OsTruncate() |
|
30 # to be called to restore the file to the same length as it was after |
|
31 # the create table. But the create table results had not yet been |
|
32 # written so the file is actually lengthened by this truncate. Finally, |
|
33 # the rollback at NOTE (3) is called to undo all the changes since the |
|
34 # begin. This rollback should truncate the database again. |
|
35 # |
|
36 # This test was added because the second truncate at NOTE (3) was not |
|
37 # occurring on early versions of SQLite 3.0. |
|
38 # |
|
39 ifcapable tempdb { |
|
40 do_test pager3-1.1 { |
|
41 execsql { |
|
42 create table t1(a unique, b); |
|
43 insert into t1 values(1, 'abcdefghijklmnopqrstuvwxyz'); |
|
44 insert into t1 values(2, 'abcdefghijklmnopqrstuvwxyz'); |
|
45 update t1 set b=b||a||b; |
|
46 update t1 set b=b||a||b; |
|
47 update t1 set b=b||a||b; |
|
48 update t1 set b=b||a||b; |
|
49 update t1 set b=b||a||b; |
|
50 update t1 set b=b||a||b; |
|
51 create temp table t2 as select * from t1; |
|
52 begin; ------- NOTE (1) |
|
53 create table t3(x); |
|
54 } |
|
55 catchsql { |
|
56 insert into t1 select 4-a, b from t2; ----- NOTE (2) |
|
57 } |
|
58 execsql { |
|
59 rollback; ------- NOTE (3) |
|
60 } |
|
61 db close |
|
62 sqlite3 db test.db |
|
63 set r ok |
|
64 ifcapable {integrityck} { |
|
65 set r [execsql { |
|
66 pragma integrity_check; |
|
67 }] |
|
68 } |
|
69 set r |
|
70 } ok |
|
71 } |
|
72 |
|
73 finish_test |