blob: 49a41414b779dc1f9cd113a5aaf9a4337d431bf2 [file] [log] [blame]
danda730f62010-02-18 08:19:19 +00001# 2010 February 18
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#
12# The tests in this file check that SQLite uses (or does not use) a
13# statement journal for various SQL statements.
14#
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19do_test stmt-1.1 {
20 execsql { CREATE TABLE t1(a integer primary key, b INTEGER NOT NULL) }
21} {}
22
23# The following tests verify the method used for the tests in this file -
24# that if a statement journal is required by a statement it is opened and
25# remains open until the current transaction is committed or rolled back.
26#
drh78e0fcf2010-02-23 21:08:40 +000027# This only work if SQLITE_TEMP_STORE!=3
28#
29if {$::TEMP_STORE==3} {
30 finish_test
31 return
32}
danda730f62010-02-18 08:19:19 +000033do_test stmt-1.2 {
34 set sqlite_open_file_count
35} {1}
36do_test stmt-1.3 {
37 execsql {
dand2db0902010-09-20 14:55:33 +000038 PRAGMA temp_store = file;
danda730f62010-02-18 08:19:19 +000039 BEGIN;
40 INSERT INTO t1 VALUES(1, 1);
41 }
42 set sqlite_open_file_count
43} {2}
44do_test stmt-1.4 {
45 execsql {
46 INSERT INTO t1 SELECT a+1, b+1 FROM t1;
47 }
48 set sqlite_open_file_count
49} {3}
50do_test stmt-1.5 {
51 execsql COMMIT
52 set sqlite_open_file_count
53} {1}
dan459564f2010-06-03 12:35:28 +000054do_test stmt-1.6.1 {
danda730f62010-02-18 08:19:19 +000055 execsql {
56 BEGIN;
57 INSERT INTO t1 SELECT a+2, b+2 FROM t1;
58 }
59 set sqlite_open_file_count
dan459564f2010-06-03 12:35:28 +000060} {2}
61do_test stmt-1.6.2 {
62 execsql { INSERT INTO t1 SELECT a+4, b+4 FROM t1 }
63 set sqlite_open_file_count
danda730f62010-02-18 08:19:19 +000064} {3}
65do_test stmt-1.7 {
66 execsql COMMIT
67 set sqlite_open_file_count
68} {1}
69
70
71proc filecount {testname sql expected} {
72 uplevel [list do_test $testname [subst -nocommand {
73 execsql BEGIN
74 execsql { $sql }
75 set ret [set sqlite_open_file_count]
76 execsql ROLLBACK
77 set ret
78 }] $expected]
79}
80
dan459564f2010-06-03 12:35:28 +000081filecount stmt-2.1 { INSERT INTO t1 VALUES(9, 9) } 2
82filecount stmt-2.2 { REPLACE INTO t1 VALUES(9, 9) } 2
83filecount stmt-2.3 { INSERT INTO t1 SELECT 9, 9 } 2
84filecount stmt-2.4 {
85 INSERT INTO t1 SELECT 9, 9;
86 INSERT INTO t1 SELECT 10, 10;
87} 3
danda730f62010-02-18 08:19:19 +000088
dan459564f2010-06-03 12:35:28 +000089do_test stmt-2.5 {
danda730f62010-02-18 08:19:19 +000090 execsql { CREATE INDEX i1 ON t1(b) }
91} {}
dan459564f2010-06-03 12:35:28 +000092filecount stmt-2.6 {
93 REPLACE INTO t1 VALUES(5, 5);
94 REPLACE INTO t1 VALUES(5, 5);
95} 3
danda730f62010-02-18 08:19:19 +000096
97finish_test