1# 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# 27do_test stmt-1.2 { 28 set sqlite_open_file_count 29} {1} 30do_test stmt-1.3 { 31 execsql { 32 BEGIN; 33 INSERT INTO t1 VALUES(1, 1); 34 } 35 set sqlite_open_file_count 36} {2} 37do_test stmt-1.4 { 38 execsql { 39 INSERT INTO t1 SELECT a+1, b+1 FROM t1; 40 } 41 set sqlite_open_file_count 42} {3} 43do_test stmt-1.5 { 44 execsql COMMIT 45 set sqlite_open_file_count 46} {1} 47do_test stmt-1.6 { 48 execsql { 49 BEGIN; 50 INSERT INTO t1 SELECT a+2, b+2 FROM t1; 51 } 52 set sqlite_open_file_count 53} {3} 54do_test stmt-1.7 { 55 execsql COMMIT 56 set sqlite_open_file_count 57} {1} 58 59 60proc filecount {testname sql expected} { 61 uplevel [list do_test $testname [subst -nocommand { 62 execsql BEGIN 63 execsql { $sql } 64 set ret [set sqlite_open_file_count] 65 execsql ROLLBACK 66 set ret 67 }] $expected] 68} 69 70filecount stmt-2.1 { INSERT INTO t1 VALUES(5, 5) } 2 71filecount stmt-2.2 { REPLACE INTO t1 VALUES(5, 5) } 2 72filecount stmt-2.3 { INSERT INTO t1 SELECT 5, 5 } 3 73 74do_test stmt-2.4 { 75 execsql { CREATE INDEX i1 ON t1(b) } 76} {} 77filecount stmt-2.5 { REPLACE INTO t1 VALUES(5, 5) } 3 78 79finish_test 80 81