Add tests to make sure statement journals are only opened when necessary. (CVS 2500)

FossilOrigin-Name: 914d6e6549446a6ddf25e5da57d2fe9446750625
This commit is contained in:
drh
2005-06-07 02:12:30 +00:00
parent 3844990cfc
commit af6df11f8a
5 changed files with 112 additions and 110 deletions
+88 -97
View File
@@ -13,7 +13,7 @@
# This file implements tests for the conflict resolution extension
# to SQLite.
#
# $Id: conflict.test,v 1.23 2005/03/20 19:10:13 drh Exp $
# $Id: conflict.test,v 1.24 2005/06/07 02:12:30 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -31,40 +31,37 @@ do_test conflict-1.0 {
# Six columns of configuration data as follows:
#
# i The reference number of the test
# conf The conflict resolution algorithm on the BEGIN statement
# cmd An INSERT or REPLACE command to execute against table t1
# t0 True if there is an error from $cmd
# t1 Content of "c" column of t1 assuming no error in $cmd
# t2 Content of "x" column of t2
# t3 Number of temporary files created by this test
#
foreach {i conf cmd t0 t1 t2} {
1 {} INSERT 1 {} 1
2 {} {INSERT OR IGNORE} 0 3 1
3 {} {INSERT OR REPLACE} 0 4 1
4 {} REPLACE 0 4 1
5 {} {INSERT OR FAIL} 1 {} 1
6 {} {INSERT OR ABORT} 1 {} 1
7 {} {INSERT OR ROLLBACK} 1 {} {}
foreach {i cmd t0 t1 t2 t3} {
1 INSERT 1 {} 1 0
2 {INSERT OR IGNORE} 0 3 1 0
3 {INSERT OR REPLACE} 0 4 1 0
4 REPLACE 0 4 1 0
5 {INSERT OR FAIL} 1 {} 1 0
6 {INSERT OR ABORT} 1 {} 1 0
7 {INSERT OR ROLLBACK} 1 {} {} 0
} {
if { $conf=={} } {
do_test conflict-1.$i {
if {$conf!=""} {set conf "ON CONFLICT $conf"}
set ::sqlite_opentemp_count 0
set r0 [catch {execsql [subst {
DELETE FROM t1;
DELETE FROM t2;
INSERT INTO t1 VALUES(1,2,3);
BEGIN $conf;
BEGIN;
INSERT INTO t2 VALUES(1);
$cmd INTO t1 VALUES(1,2,4);
}]} r1]
catch {execsql {COMMIT}}
if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
set r2 [execsql {SELECT x FROM t2}]
list $r0 $r1 $r2
} [list $t0 $t1 $t2]
}
set r3 $::sqlite_opentemp_count
list $r0 $r1 $r2 $r3
} [list $t0 $t1 $t2 $t3]
}
# Create tables for the first group of tests.
@@ -82,28 +79,26 @@ do_test conflict-2.0 {
# Six columns of configuration data as follows:
#
# i The reference number of the test
# conf The conflict resolution algorithm on the BEGIN statement
# cmd An INSERT or REPLACE command to execute against table t1
# t0 True if there is an error from $cmd
# t1 Content of "c" column of t1 assuming no error in $cmd
# t2 Content of "x" column of t2
#
foreach {i conf cmd t0 t1 t2} {
1 {} INSERT 1 {} 1
2 {} {INSERT OR IGNORE} 0 3 1
3 {} {INSERT OR REPLACE} 0 4 1
4 {} REPLACE 0 4 1
5 {} {INSERT OR FAIL} 1 {} 1
6 {} {INSERT OR ABORT} 1 {} 1
7 {} {INSERT OR ROLLBACK} 1 {} {}
foreach {i cmd t0 t1 t2} {
1 INSERT 1 {} 1
2 {INSERT OR IGNORE} 0 3 1
3 {INSERT OR REPLACE} 0 4 1
4 REPLACE 0 4 1
5 {INSERT OR FAIL} 1 {} 1
6 {INSERT OR ABORT} 1 {} 1
7 {INSERT OR ROLLBACK} 1 {} {}
} {
do_test conflict-2.$i {
if {$conf!=""} {set conf "ON CONFLICT $conf"}
set r0 [catch {execsql [subst {
DELETE FROM t1;
DELETE FROM t2;
INSERT INTO t1 VALUES(1,2,3);
BEGIN $conf;
BEGIN;
INSERT INTO t2 VALUES(1);
$cmd INTO t1 VALUES(1,2,4);
}]} r1]
@@ -129,28 +124,26 @@ do_test conflict-3.0 {
# Six columns of configuration data as follows:
#
# i The reference number of the test
# conf The conflict resolution algorithm on the BEGIN statement
# cmd An INSERT or REPLACE command to execute against table t1
# t0 True if there is an error from $cmd
# t1 Content of "c" column of t1 assuming no error in $cmd
# t2 Content of "x" column of t2
#
foreach {i conf cmd t0 t1 t2} {
1 {} INSERT 1 {} 1
2 {} {INSERT OR IGNORE} 0 3 1
3 {} {INSERT OR REPLACE} 0 4 1
4 {} REPLACE 0 4 1
5 {} {INSERT OR FAIL} 1 {} 1
6 {} {INSERT OR ABORT} 1 {} 1
7 {} {INSERT OR ROLLBACK} 1 {} {}
foreach {i cmd t0 t1 t2} {
1 INSERT 1 {} 1
2 {INSERT OR IGNORE} 0 3 1
3 {INSERT OR REPLACE} 0 4 1
4 REPLACE 0 4 1
5 {INSERT OR FAIL} 1 {} 1
6 {INSERT OR ABORT} 1 {} 1
7 {INSERT OR ROLLBACK} 1 {} {}
} {
do_test conflict-3.$i {
if {$conf!=""} {set conf "ON CONFLICT $conf"}
set r0 [catch {execsql [subst {
DELETE FROM t1;
DELETE FROM t2;
INSERT INTO t1 VALUES(1,2,3);
BEGIN $conf;
BEGIN;
INSERT INTO t2 VALUES(1);
$cmd INTO t1 VALUES(1,2,4);
}]} r1]
@@ -173,34 +166,32 @@ do_test conflict-4.0 {
#
# i The reference number of the test
# conf1 The conflict resolution algorithm on the UNIQUE constraint
# conf2 The conflict resolution algorithm on the BEGIN statement
# cmd An INSERT or REPLACE command to execute against table t1
# t0 True if there is an error from $cmd
# t1 Content of "c" column of t1 assuming no error in $cmd
# t2 Content of "x" column of t2
#
foreach {i conf1 conf2 cmd t0 t1 t2} {
1 {} {} INSERT 1 {} 1
2 REPLACE {} INSERT 0 4 1
3 IGNORE {} INSERT 0 3 1
4 FAIL {} INSERT 1 {} 1
5 ABORT {} INSERT 1 {} 1
6 ROLLBACK {} INSERT 1 {} {}
7 REPLACE {} {INSERT OR IGNORE} 0 3 1
8 IGNORE {} {INSERT OR REPLACE} 0 4 1
9 FAIL {} {INSERT OR IGNORE} 0 3 1
10 ABORT {} {INSERT OR REPLACE} 0 4 1
11 ROLLBACK {} {INSERT OR IGNORE } 0 3 1
foreach {i conf1 cmd t0 t1 t2} {
1 {} INSERT 1 {} 1
2 REPLACE INSERT 0 4 1
3 IGNORE INSERT 0 3 1
4 FAIL INSERT 1 {} 1
5 ABORT INSERT 1 {} 1
6 ROLLBACK INSERT 1 {} {}
7 REPLACE {INSERT OR IGNORE} 0 3 1
8 IGNORE {INSERT OR REPLACE} 0 4 1
9 FAIL {INSERT OR IGNORE} 0 3 1
10 ABORT {INSERT OR REPLACE} 0 4 1
11 ROLLBACK {INSERT OR IGNORE } 0 3 1
} {
do_test conflict-4.$i {
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
set r0 [catch {execsql [subst {
DROP TABLE t1;
CREATE TABLE t1(a,b,c,UNIQUE(a,b) $conf1);
DELETE FROM t2;
INSERT INTO t1 VALUES(1,2,3);
BEGIN $conf2;
BEGIN;
INSERT INTO t2 VALUES(1);
$cmd INTO t1 VALUES(1,2,4);
}]} r1]
@@ -223,39 +214,37 @@ do_test conflict-5.0 {
#
# i The reference number of the test
# conf1 The conflict resolution algorithm on the NOT NULL constraint
# conf2 The conflict resolution algorithm on the BEGIN statement
# cmd An INSERT or REPLACE command to execute against table t1
# t0 True if there is an error from $cmd
# t1 Content of "c" column of t1 assuming no error in $cmd
# t2 Content of "x" column of t2
#
foreach {i conf1 conf2 cmd t0 t1 t2} {
1 {} {} INSERT 1 {} 1
2 REPLACE {} INSERT 0 5 1
3 IGNORE {} INSERT 0 {} 1
4 FAIL {} INSERT 1 {} 1
5 ABORT {} INSERT 1 {} 1
6 ROLLBACK {} INSERT 1 {} {}
7 REPLACE {} {INSERT OR IGNORE} 0 {} 1
8 IGNORE {} {INSERT OR REPLACE} 0 5 1
9 FAIL {} {INSERT OR IGNORE} 0 {} 1
10 ABORT {} {INSERT OR REPLACE} 0 5 1
11 ROLLBACK {} {INSERT OR IGNORE} 0 {} 1
12 {} {} {INSERT OR IGNORE} 0 {} 1
13 {} {} {INSERT OR REPLACE} 0 5 1
14 {} {} {INSERT OR FAIL} 1 {} 1
15 {} {} {INSERT OR ABORT} 1 {} 1
16 {} {} {INSERT OR ROLLBACK} 1 {} {}
foreach {i conf1 cmd t0 t1 t2} {
1 {} INSERT 1 {} 1
2 REPLACE INSERT 0 5 1
3 IGNORE INSERT 0 {} 1
4 FAIL INSERT 1 {} 1
5 ABORT INSERT 1 {} 1
6 ROLLBACK INSERT 1 {} {}
7 REPLACE {INSERT OR IGNORE} 0 {} 1
8 IGNORE {INSERT OR REPLACE} 0 5 1
9 FAIL {INSERT OR IGNORE} 0 {} 1
10 ABORT {INSERT OR REPLACE} 0 5 1
11 ROLLBACK {INSERT OR IGNORE} 0 {} 1
12 {} {INSERT OR IGNORE} 0 {} 1
13 {} {INSERT OR REPLACE} 0 5 1
14 {} {INSERT OR FAIL} 1 {} 1
15 {} {INSERT OR ABORT} 1 {} 1
16 {} {INSERT OR ROLLBACK} 1 {} {}
} {
if {$t0} {set t1 {t1.c may not be NULL}}
do_test conflict-5.$i {
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
set r0 [catch {execsql [subst {
DROP TABLE t1;
CREATE TABLE t1(a,b,c NOT NULL $conf1 DEFAULT 5);
DELETE FROM t2;
BEGIN $conf2;
BEGIN;
INSERT INTO t2 VALUES(1);
$cmd INTO t1 VALUES(1,2,NULL);
}]} r1]
@@ -284,40 +273,42 @@ do_test conflict-6.0 {
#
# i The reference number of the test
# conf1 The conflict resolution algorithm on the UNIQUE constraint
# conf2 The conflict resolution algorithm on the BEGIN statement
# cmd An UPDATE command to execute against table t1
# t0 True if there is an error from $cmd
# t1 Content of "b" column of t1 assuming no error in $cmd
# t2 Content of "x" column of t3
# t3 Number of temporary files created
#
foreach {i conf1 conf2 cmd t0 t1 t2} {
1 {} {} UPDATE 1 {6 7 8 9} 1
2 REPLACE {} UPDATE 0 {7 6 9} 1
3 IGNORE {} UPDATE 0 {6 7 3 9} 1
4 FAIL {} UPDATE 1 {6 7 3 4} 1
5 ABORT {} UPDATE 1 {1 2 3 4} 1
6 ROLLBACK {} UPDATE 1 {1 2 3 4} 0
7 REPLACE {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1
8 IGNORE {} {UPDATE OR REPLACE} 0 {7 6 9} 1
9 FAIL {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1
10 ABORT {} {UPDATE OR REPLACE} 0 {7 6 9} 1
11 ROLLBACK {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1
12 {} {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1
13 {} {} {UPDATE OR REPLACE} 0 {7 6 9} 1
14 {} {} {UPDATE OR FAIL} 1 {6 7 3 4} 1
15 {} {} {UPDATE OR ABORT} 1 {1 2 3 4} 1
16 {} {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0
foreach {i conf1 cmd t0 t1 t2 t3} {
1 {} UPDATE 1 {6 7 8 9} 1 1
2 REPLACE UPDATE 0 {7 6 9} 1 0
3 IGNORE UPDATE 0 {6 7 3 9} 1 0
4 FAIL UPDATE 1 {6 7 3 4} 1 0
5 ABORT UPDATE 1 {1 2 3 4} 1 1
6 ROLLBACK UPDATE 1 {1 2 3 4} 0 0
7 REPLACE {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0
8 IGNORE {UPDATE OR REPLACE} 0 {7 6 9} 1 0
9 FAIL {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0
10 ABORT {UPDATE OR REPLACE} 0 {7 6 9} 1 0
11 ROLLBACK {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0
12 {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0
13 {} {UPDATE OR REPLACE} 0 {7 6 9} 1 0
14 {} {UPDATE OR FAIL} 1 {6 7 3 4} 1 0
15 {} {UPDATE OR ABORT} 1 {1 2 3 4} 1 1
16 {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0 0
} {
if {$t0} {set t1 {column a is not unique}}
do_test conflict-6.$i {
db close
sqlite3 db test.db
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
set ::sqlite_opentemp_count 0
set r0 [catch {execsql [subst {
DROP TABLE t1;
CREATE TABLE t1(a,b,c, UNIQUE(a) $conf1);
INSERT INTO t1 SELECT * FROM t2;
UPDATE t3 SET x=0;
BEGIN $conf2;
BEGIN;
$cmd t3 SET x=1;
$cmd t1 SET b=b*2;
$cmd t1 SET a=c+5;
@@ -325,8 +316,8 @@ foreach {i conf1 conf2 cmd t0 t1 t2} {
catch {execsql {COMMIT}}
if {!$r0} {set r1 [execsql {SELECT a FROM t1 ORDER BY b}]}
set r2 [execsql {SELECT x FROM t3}]
list $r0 $r1 $r2
} [list $t0 $t1 $t2]
list $r0 $r1 $r2 $::sqlite_opentemp_count
} [list $t0 $t1 $t2 $t3]
}
# Test to make sure a lot of IGNOREs don't cause a stack overflow