AryaWu/sqlite
0
1# 2010 February 182#3# The author disclaims copyright to this source code. In place of4# 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) a13# statement journal for various SQL statements.14#15 16set testdir [file dirname $argv0]17source $testdir/tester.tcl18 19if {[atomic_batch_write test.db]} {20 finish_test21 return22}23 24do_test stmt-1.1 {25 execsql { CREATE TABLE t1(a integer primary key, b INTEGER NOT NULL) }26} {}27 28# The following tests verify the method used for the tests in this file -29# that if a statement journal is required by a statement it is opened and30# remains open until the current transaction is committed or rolled back.31#32# This only work if SQLITE_TEMP_STORE!=333#34if {$::TEMP_STORE==3} {35 finish_test36 return37}38do_test stmt-1.2 {39 set sqlite_open_file_count40} {1}41do_test stmt-1.3 {42 execsql {43 PRAGMA temp_store = file;44 BEGIN;45 INSERT INTO t1 VALUES(1, 1);46 }47 set sqlite_open_file_count48} {2}49do_test stmt-1.4 {50 execsql {51 INSERT INTO t1 SELECT a+1, b+1 FROM t1;52 }53 set sqlite_open_file_count54 # 2016-03-04: statement-journal open deferred55} {2}56do_test stmt-1.5 {57 execsql COMMIT58 set sqlite_open_file_count59} {1}60do_test stmt-1.6.1 {61 execsql {62 BEGIN;63 INSERT INTO t1 SELECT a+2, b+2 FROM t1;64 }65 set sqlite_open_file_count66} {2}67do_test stmt-1.6.2 {68 execsql { INSERT INTO t1 SELECT a+4, b+4 FROM t1 }69 set sqlite_open_file_count70 # 2016-03-04: statement-journal open deferred71} {2}72do_test stmt-1.7 {73 execsql COMMIT74 set sqlite_open_file_count75} {1}76 77 78proc filecount {testname sql expected} {79 uplevel [list do_test $testname [subst -nocommand {80 execsql BEGIN81 execsql { $sql }82 set ret [set sqlite_open_file_count]83 execsql ROLLBACK84 set ret85 }] $expected]86}87 88filecount stmt-2.1 { INSERT INTO t1 VALUES(9, 9) } 289filecount stmt-2.2 { REPLACE INTO t1 VALUES(9, 9) } 290filecount stmt-2.3 { INSERT INTO t1 SELECT 9, 9 } 291filecount stmt-2.4 { 92 INSERT INTO t1 SELECT 9, 9;93 INSERT INTO t1 SELECT 10, 10;94} 295 96do_test stmt-2.5 {97 execsql { CREATE INDEX i1 ON t1(b) }98} {}99filecount stmt-2.6 { 100 REPLACE INTO t1 VALUES(5, 5);101 REPLACE INTO t1 VALUES(5, 5); 102} 2103 104finish_test105 