AryaWu/sqlite
0
1# 2010 June 152#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 13set testdir [file dirname $argv0]14source $testdir/tester.tcl15source $testdir/lock_common.tcl16source $testdir/malloc_common.tcl17 18set otn 019testvfs tv -default 120foreach code [list {21 set s 51222} {23 set s 102424 set sql { PRAGMA journal_mode = memory }25} {26 set s 102427 set sql { 28 PRAGMA journal_mode = memory;29 PRAGMA locking_mode = exclusive;30 }31} {32 set s 204833 tv devchar safe_append34} {35 set s 409636} {37 set s 409638 set sql { PRAGMA journal_mode = WAL }39} {40 set s 409641 set sql { PRAGMA auto_vacuum = 1 }42} {43 set s 819244 set sql { PRAGMA synchronous = off }45}] {46 47 incr otn48 set sql ""49 tv devchar {}50 eval $code51 tv sectorsize $s52 53 do_test pager2-1.$otn.0 {54 faultsim_delete_and_reopen55 execsql $sql56 execsql {57 PRAGMA cache_size = 10;58 CREATE TABLE t1(i INTEGER PRIMARY KEY, j blob);59 }60 } {}61 62 set tn 063 set lowpoint 064 foreach x {65 100 x 0 10066 x67 70 22 96 59 96 50 22 56 21 16 37 64 43 40 0 38 22 38 55 0 6 68 43 62 32 93 54 18 13 29 45 66 29 25 61 31 53 82 75 25 96 86 10 69 69 2 29 6 60 80 95 42 82 85 50 68 96 90 39 78 69 87 97 48 74 65 43 70 x71 86 34 26 50 41 85 58 44 89 22 6 51 45 46 58 32 97 6 1 12 32 2 72 69 39 48 71 33 31 5 58 90 43 24 54 12 9 18 57 4 38 91 42 27 45 73 50 38 56 29 10 0 26 37 83 1 78 15 47 30 75 62 46 29 68 5 30 4 74 27 96 33 95 79 75 56 10 29 70 32 75 52 88 5 36 50 57 46 63 88 65 75 x76 44 95 64 20 24 35 69 61 61 2 35 92 42 46 23 98 78 1 38 72 79 35 77 94 37 13 59 5 93 27 58 80 75 58 7 67 13 10 76 84 4 8 70 81 45 78 8 41 98 5 60 26 92 29 91 90 2 62 40 4 5 22 80 15 83 76 52 88 79 29 5 68 73 72 7 54 17 89 32 81 94 51 28 53 71 8 42 54 59 70 79 80 x81 } {82 incr tn83 set now [db one {SELECT count(i) FROM t1}]84 if {$x == "x"} {85 execsql { COMMIT ; BEGIN }86 set lowpoint $now87 do_test pager2.1.$otn.$tn { 88 sqlite3 db2 test.db89 execsql {90 SELECT COALESCE(max(i), 0) FROM t1;91 PRAGMA integrity_check;92 } 93 } [list $lowpoint ok]94 db2 close95 } else {96 if {$now > $x } {97 if { $x>=$lowpoint } {98 execsql "ROLLBACK TO sp_$x"99 } else {100 execsql "DELETE FROM t1 WHERE i>$x"101 set lowpoint $x102 }103 } elseif {$now < $x} {104 for {set k $now} {$k < $x} {incr k} {105 execsql "SAVEPOINT sp_$k"106 execsql { INSERT INTO t1(j) VALUES(randomblob(1500)) }107 }108 }109 do_execsql_test pager2.1.$otn.$tn { 110 SELECT COALESCE(max(i), 0) FROM t1;111 PRAGMA integrity_check;112 } [list $x ok]113 }114 }115}116db close117tv delete118 119 120#-------------------------------------------------------------------------121# pager2-2.1: Test a ROLLBACK with journal_mode=off.122# pager2-2.2: Test shrinking the database (auto-vacuum) with 123# journal_mode=off124#125do_test pager2-2.1 {126 faultsim_delete_and_reopen127 execsql {128 CREATE TABLE t1(a, b);129 PRAGMA journal_mode = off;130 BEGIN;131 INSERT INTO t1 VALUES(1, 2);132 ROLLBACK;133 SELECT * FROM t1;134 }135} {off}136do_test pager2-2.2 {137 faultsim_delete_and_reopen138 execsql {139 PRAGMA auto_vacuum = incremental;140 PRAGMA page_size = 1024;141 PRAGMA journal_mode = off;142 CREATE TABLE t1(a, b);143 INSERT INTO t1 VALUES(zeroblob(5000), zeroblob(5000));144 DELETE FROM t1;145 PRAGMA incremental_vacuum;146 }147 file size test.db148} {3072}149 150ifcapable shared_cache {151 #-------------------------------------------------------------------------152 # Test that shared in-memory databases seem to work.153 #154 db close155 do_test pager2-3.1 {156 forcedelete test.db157 sqlite3_shutdown158 sqlite3_config_uri 1159 160 sqlite3 db1 {file:test.db?mode=memory&cache=shared}161 sqlite3 db2 {file:test.db?mode=memory&cache=shared}162 sqlite3 db3 test.db163 164 db1 eval { CREATE TABLE t1(a, b) }165 db2 eval { INSERT INTO t1 VALUES(1, 2) }166 list [catch { db3 eval { INSERT INTO t1 VALUES(3, 4) } } msg] $msg167 } {1 {no such table: t1}}168 db1 close169}170 171finish_test172 