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# 27# This only work if SQLITE_TEMP_STORE!=3 28# 29if {$::TEMP_STORE==3} { 30 finish_test 31 return 32} 33do_test stmt-1.2 { 34 set sqlite_open_file_count 35} {1} 36do_test stmt-1.3 { 37 execsql { 38 BEGIN; 39 INSERT INTO t1 VALUES(1, 1); 40 } 41 set sqlite_open_file_count 42} {2} 43do_test stmt-1.4 { 44 execsql { 45 INSERT INTO t1 SELECT a+1, b+1 FROM t1; 46 } 47 set sqlite_open_file_count 48} {3} 49do_test stmt-1.5 { 50 execsql COMMIT 51 set sqlite_open_file_count 52} {1} 53do_test stmt-1.6.1 { 54 execsql { 55 BEGIN; 56 INSERT INTO t1 SELECT a+2, b+2 FROM t1; 57 } 58 set sqlite_open_file_count 59} {2} 60do_test stmt-1.6.2 { 61 execsql { INSERT INTO t1 SELECT a+4, b+4 FROM t1 } 62 set sqlite_open_file_count 63} {3} 64do_test stmt-1.7 { 65 execsql COMMIT 66 set sqlite_open_file_count 67} {1} 68 69 70proc filecount {testname sql expected} { 71 uplevel [list do_test $testname [subst -nocommand { 72 execsql BEGIN 73 execsql { $sql } 74 set ret [set sqlite_open_file_count] 75 execsql ROLLBACK 76 set ret 77 }] $expected] 78} 79 80filecount stmt-2.1 { INSERT INTO t1 VALUES(9, 9) } 2 81filecount stmt-2.2 { REPLACE INTO t1 VALUES(9, 9) } 2 82filecount stmt-2.3 { INSERT INTO t1 SELECT 9, 9 } 2 83filecount stmt-2.4 { 84 INSERT INTO t1 SELECT 9, 9; 85 INSERT INTO t1 SELECT 10, 10; 86} 3 87 88do_test stmt-2.5 { 89 execsql { CREATE INDEX i1 ON t1(b) } 90} {} 91filecount stmt-2.6 { 92 REPLACE INTO t1 VALUES(5, 5); 93 REPLACE INTO t1 VALUES(5, 5); 94} 3 95 96finish_test 97