1153eda0aSdan# 2010 June 15 2153eda0aSdan# 3153eda0aSdan# The author disclaims copyright to this source code. In place of 4153eda0aSdan# a legal notice, here is a blessing: 5153eda0aSdan# 6153eda0aSdan# May you do good and not evil. 7153eda0aSdan# May you find forgiveness for yourself and forgive others. 8153eda0aSdan# May you share freely, never taking more than you give. 9153eda0aSdan# 10153eda0aSdan#*********************************************************************** 11153eda0aSdan# 12153eda0aSdan 13153eda0aSdanset testdir [file dirname $argv0] 14153eda0aSdansource $testdir/tester.tcl 15153eda0aSdansource $testdir/lock_common.tcl 16153eda0aSdansource $testdir/malloc_common.tcl 17153eda0aSdan 18153eda0aSdanset otn 0 19153eda0aSdantestvfs tv -default 1 20153eda0aSdanforeach code [list { 21153eda0aSdan set s 512 22153eda0aSdan} { 23153eda0aSdan set s 1024 24153eda0aSdan set sql { PRAGMA journal_mode = memory } 25153eda0aSdan} { 26153eda0aSdan set s 1024 27153eda0aSdan set sql { 28153eda0aSdan PRAGMA journal_mode = memory; 29153eda0aSdan PRAGMA locking_mode = exclusive; 30153eda0aSdan } 31153eda0aSdan} { 32153eda0aSdan set s 2048 33153eda0aSdan tv devchar safe_append 34153eda0aSdan} { 35153eda0aSdan set s 4096 36153eda0aSdan} { 37153eda0aSdan set s 4096 38153eda0aSdan set sql { PRAGMA journal_mode = WAL } 39153eda0aSdan} { 400e986f51Sdan set s 4096 410e986f51Sdan set sql { PRAGMA auto_vacuum = 1 } 420e986f51Sdan} { 43153eda0aSdan set s 8192 44153eda0aSdan set sql { PRAGMA synchronous = off } 45153eda0aSdan}] { 46153eda0aSdan 47153eda0aSdan incr otn 48153eda0aSdan set sql "" 49153eda0aSdan tv devchar {} 50153eda0aSdan eval $code 51153eda0aSdan tv sectorsize $s 52153eda0aSdan 53153eda0aSdan do_test pager2-1.$otn.0 { 54153eda0aSdan faultsim_delete_and_reopen 55153eda0aSdan execsql $sql 56153eda0aSdan execsql { 57153eda0aSdan PRAGMA cache_size = 10; 58153eda0aSdan CREATE TABLE t1(i INTEGER PRIMARY KEY, j blob); 59153eda0aSdan } 60153eda0aSdan } {} 61153eda0aSdan 62153eda0aSdan set tn 0 63153eda0aSdan set lowpoint 0 64153eda0aSdan foreach x { 65153eda0aSdan 100 x 0 100 66153eda0aSdan x 67153eda0aSdan 70 22 96 59 96 50 22 56 21 16 37 64 43 40 0 38 22 38 55 0 6 68153eda0aSdan 43 62 32 93 54 18 13 29 45 66 29 25 61 31 53 82 75 25 96 86 10 69 69153eda0aSdan 2 29 6 60 80 95 42 82 85 50 68 96 90 39 78 69 87 97 48 74 65 43 70153eda0aSdan x 71153eda0aSdan 86 34 26 50 41 85 58 44 89 22 6 51 45 46 58 32 97 6 1 12 32 2 72153eda0aSdan 69 39 48 71 33 31 5 58 90 43 24 54 12 9 18 57 4 38 91 42 27 45 73153eda0aSdan 50 38 56 29 10 0 26 37 83 1 78 15 47 30 75 62 46 29 68 5 30 4 74153eda0aSdan 27 96 33 95 79 75 56 10 29 70 32 75 52 88 5 36 50 57 46 63 88 65 75153eda0aSdan x 76153eda0aSdan 44 95 64 20 24 35 69 61 61 2 35 92 42 46 23 98 78 1 38 72 79 35 77153eda0aSdan 94 37 13 59 5 93 27 58 80 75 58 7 67 13 10 76 84 4 8 70 81 45 78153eda0aSdan 8 41 98 5 60 26 92 29 91 90 2 62 40 4 5 22 80 15 83 76 52 88 79153eda0aSdan 29 5 68 73 72 7 54 17 89 32 81 94 51 28 53 71 8 42 54 59 70 79 80153eda0aSdan x 81153eda0aSdan } { 82153eda0aSdan incr tn 83153eda0aSdan set now [db one {SELECT count(i) FROM t1}] 84153eda0aSdan if {$x == "x"} { 85153eda0aSdan execsql { COMMIT ; BEGIN } 86153eda0aSdan set lowpoint $now 87153eda0aSdan do_test pager2.1.$otn.$tn { 88153eda0aSdan sqlite3 db2 test.db 89153eda0aSdan execsql { 90153eda0aSdan SELECT COALESCE(max(i), 0) FROM t1; 91153eda0aSdan PRAGMA integrity_check; 92153eda0aSdan } 93153eda0aSdan } [list $lowpoint ok] 94153eda0aSdan db2 close 95153eda0aSdan } else { 96153eda0aSdan if {$now > $x } { 97153eda0aSdan if { $x>=$lowpoint } { 98153eda0aSdan execsql "ROLLBACK TO sp_$x" 99153eda0aSdan } else { 100153eda0aSdan execsql "DELETE FROM t1 WHERE i>$x" 101153eda0aSdan set lowpoint $x 102153eda0aSdan } 103153eda0aSdan } elseif {$now < $x} { 104153eda0aSdan for {set k $now} {$k < $x} {incr k} { 105153eda0aSdan execsql "SAVEPOINT sp_$k" 106153eda0aSdan execsql { INSERT INTO t1(j) VALUES(randomblob(1500)) } 107153eda0aSdan } 108153eda0aSdan } 109153eda0aSdan do_execsql_test pager2.1.$otn.$tn { 110153eda0aSdan SELECT COALESCE(max(i), 0) FROM t1; 111153eda0aSdan PRAGMA integrity_check; 112153eda0aSdan } [list $x ok] 113153eda0aSdan } 114153eda0aSdan } 115153eda0aSdan} 116153eda0aSdandb close 117153eda0aSdantv delete 118153eda0aSdan 11922b328b2Sdan 12022b328b2Sdan#------------------------------------------------------------------------- 1215653e4daSdan# pager2-2.1: Test a ROLLBACK with journal_mode=off. 1225653e4daSdan# pager2-2.2: Test shrinking the database (auto-vacuum) with 1235653e4daSdan# journal_mode=off 1245653e4daSdan# 12522b328b2Sdando_test pager2-2.1 { 12622b328b2Sdan faultsim_delete_and_reopen 12722b328b2Sdan execsql { 12822b328b2Sdan CREATE TABLE t1(a, b); 12922b328b2Sdan PRAGMA journal_mode = off; 13022b328b2Sdan BEGIN; 13122b328b2Sdan INSERT INTO t1 VALUES(1, 2); 13222b328b2Sdan ROLLBACK; 13322b328b2Sdan SELECT * FROM t1; 13422b328b2Sdan } 135354bfe03Sdan} {off} 1365653e4daSdando_test pager2-2.2 { 1375653e4daSdan faultsim_delete_and_reopen 1385653e4daSdan execsql { 1395653e4daSdan PRAGMA auto_vacuum = incremental; 1405653e4daSdan PRAGMA page_size = 1024; 1415653e4daSdan PRAGMA journal_mode = off; 1425653e4daSdan CREATE TABLE t1(a, b); 1435653e4daSdan INSERT INTO t1 VALUES(zeroblob(5000), zeroblob(5000)); 1445653e4daSdan DELETE FROM t1; 1455653e4daSdan PRAGMA incremental_vacuum; 1465653e4daSdan } 1475653e4daSdan file size test.db 1485653e4daSdan} {3072} 14922b328b2Sdan 150*abd6d84aSdan#------------------------------------------------------------------------- 151*abd6d84aSdan# Test that shared in-memory databases seem to work. 152*abd6d84aSdan# 153*abd6d84aSdandb close 154*abd6d84aSdando_test pager2-3.1 { 155*abd6d84aSdan forcedelete test.db 156*abd6d84aSdan sqlite3_shutdown 157*abd6d84aSdan sqlite3_config_uri 1 158*abd6d84aSdan 159*abd6d84aSdan sqlite3 db1 {file:test.db?mode=memory&cache=shared} 160*abd6d84aSdan sqlite3 db2 {file:test.db?mode=memory&cache=shared} 161*abd6d84aSdan sqlite3 db3 test.db 162*abd6d84aSdan 163*abd6d84aSdan db1 eval { CREATE TABLE t1(a, b) } 164*abd6d84aSdan db2 eval { INSERT INTO t1 VALUES(1, 2) } 165*abd6d84aSdan list [catch { db3 eval { INSERT INTO t1 VALUES(3, 4) } } msg] $msg 166*abd6d84aSdan} {1 {no such table: t1}} 167*abd6d84aSdan 168153eda0aSdanfinish_test 169