3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # $Id: savepoint2.test,v 1.5 2009/06/05 17:09:12 drh Exp $
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
18 # Tests in this file are quite similar to those run by trans.test and
23 return [db eval {SELECT count(*), md5sum(x) FROM t3}]
26 do_test savepoint2-1 {
31 CREATE TABLE t3(x TEXT);
32 INSERT INTO t3 VALUES(randstr(10,400));
33 INSERT INTO t3 VALUES(randstr(10,400));
34 INSERT INTO t3 SELECT randstr(10,400) FROM t3;
35 INSERT INTO t3 SELECT randstr(10,400) FROM t3;
36 INSERT INTO t3 SELECT randstr(10,400) FROM t3;
37 INSERT INTO t3 SELECT randstr(10,400) FROM t3;
38 INSERT INTO t3 SELECT randstr(10,400) FROM t3;
39 INSERT INTO t3 SELECT randstr(10,400) FROM t3;
40 INSERT INTO t3 SELECT randstr(10,400) FROM t3;
41 INSERT INTO t3 SELECT randstr(10,400) FROM t3;
42 INSERT INTO t3 SELECT randstr(10,400) FROM t3;
44 SELECT count(*) FROM t3;
47 wal_check_journal_mode savepoint2-1.1
49 unset -nocomplain ::sig
55 DELETE FROM t3 WHERE random()%10!=0;
56 INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
57 INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
60 DELETE FROM t3 WHERE random()%10!=0;
61 INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
62 DELETE FROM t3 WHERE random()%10!=0;
63 INSERT INTO t3 SELECT randstr(10,10)||x FROM t3;
66 UPDATE t3 SET x = randstr(10, 400) WHERE random()%10;
67 INSERT INTO t3 SELECT x FROM t3 WHERE random()%10;
68 DELETE FROM t3 WHERE random()%10;
71 INSERT INTO t3 SELECT randstr(10,400) FROM t3 WHERE (random()%10 == 0);
76 for {set ii 2} {$ii < ($iterations+2)} {incr ii} {
78 # Record the database signature. Optionally (every second run) open a
79 # transaction. In all cases open savepoint "one", which may or may
80 # not be a transaction savepoint, depending on whether or not a real
81 # transaction has been opened.
83 do_test savepoint2-$ii.1 {
84 if {$ii % 2} { execsql BEGIN }
85 set ::sig(one) [signature]
86 execsql "SAVEPOINT one"
89 # Execute some SQL on the database. Then rollback to savepoint "one".
90 # Check that the database signature is as it was when "one" was opened.
92 do_test savepoint2-$ii.2 {
94 execsql "ROLLBACK to one"
97 integrity_check savepoint2-$ii.2.1
99 # Execute some SQL. Then open savepoint "two". Savepoint "two" is therefore
100 # nested in savepoint "one".
102 do_test savepoint2-$ii.3 {
104 set ::sig(two) [signature]
105 execsql "SAVEPOINT two"
108 # More SQL changes. The rollback to savepoint "two". Check that the
109 # signature is as it was when savepoint "two" was opened.
111 do_test savepoint2-$ii.4 {
113 execsql "ROLLBACK to two"
116 integrity_check savepoint2-$ii.4.1
118 # More SQL changes. The rollback to savepoint "two". Check that the
119 # signature is as it was when savepoint "two" was opened.
121 do_test savepoint2-$ii.5 {
123 execsql "SAVEPOINT three"
125 execsql "RELEASE three"
126 execsql "ROLLBACK to one"
130 # By this point the database is in the same state as it was at the
131 # top of the for{} loop (everything having been rolled back by the
132 # "ROLLBACK TO one" command above). So make a few changes to the
133 # database and COMMIT the open transaction, so that the next iteration
134 # of the for{} loop works on a different dataset.
136 # The transaction being committed here may have been opened normally using
137 # "BEGIN", or may have been opened using a transaction savepoint created
138 # by the "SAVEPOINT one" statement.
140 do_test savepoint2-$ii.6 {
143 sqlite3_get_autocommit db
145 integrity_check savepoint2-$ii.6.1
147 # Check that the connection is still running in WAL mode.
148 wal_check_journal_mode savepoint2-$ii.7
151 unset -nocomplain ::sig
152 unset -nocomplain SQL