1# 2013 May 14 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# Test some specific circumstances to do with shared cache mode. 13# 14 15 16set testdir [file dirname $argv0] 17source $testdir/tester.tcl 18db close 19set ::testprefix sharedA 20 21set ::enable_shared_cache [sqlite3_enable_shared_cache 1] 22 23#------------------------------------------------------------------------- 24# 25do_test 0.1 { 26 sqlite3 db1 test.db 27 sqlite3 db2 test.db 28 29 db1 eval { 30 CREATE TABLE t1(x); 31 INSERT INTO t1 VALUES(randomblob(100)); 32 INSERT INTO t1 SELECT randomblob(100) FROM t1; 33 INSERT INTO t1 SELECT randomblob(100) FROM t1; 34 INSERT INTO t1 SELECT randomblob(100) FROM t1; 35 INSERT INTO t1 SELECT randomblob(100) FROM t1; 36 INSERT INTO t1 SELECT randomblob(100) FROM t1; 37 INSERT INTO t1 SELECT randomblob(100) FROM t1; 38 CREATE INDEX i1 ON t1(x); 39 } 40 41 db1 eval { 42 BEGIN; 43 DROP INDEX i1; 44 } 45 46 db2 close 47 48 db1 eval { 49 INSERT INTO t1 SELECT randomblob(100) FROM t1; 50 ROLLBACK; 51 PRAGMA integrity_check; 52 } 53} {ok} 54 55db1 close 56forcedelete test.db 57 58 59#------------------------------------------------------------------------- 60# 61do_test 1.1 { 62 sqlite3 db1 test.db 63 sqlite3 db2 test.db 64 db2 eval { 65 CREATE TABLE t1(x); 66 INSERT INTO t1 VALUES(123); 67 } 68 db1 eval { 69 SELECT * FROM t1; 70 CREATE INDEX i1 ON t1(x); 71 } 72} {123} 73 74do_test 1.2 { 75 db2 eval { SELECT * FROM t1 ORDER BY x; } 76 77 db1 eval { 78 BEGIN; DROP INDEX i1; 79 } 80 db1 close 81 82 db2 eval { SELECT * FROM t1 ORDER BY x; } 83} {123} 84 85do_test 1.3 { 86 db2 close 87} {} 88 89#------------------------------------------------------------------------- 90# 91testvfs tvfs 92tvfs filter xRead 93tvfs script read_callback 94proc read_callback {args} { } 95 96do_test 2.1 { 97 forcedelete test.db test.db2 98 sqlite3 db1 test.db -vfs tvfs 99 db1 eval { ATTACH 'test.db2' AS two } 100 101 db1 eval { 102 CREATE TABLE t1(x); 103 INSERT INTO t1 VALUES(1); 104 INSERT INTO t1 VALUES(2); 105 INSERT INTO t1 VALUES(3); 106 CREATE TABLE two.t2(x); 107 INSERT INTO t2 SELECT * FROM t1; 108 } 109 110 sqlite3 db2 test.db -vfs tvfs 111 db2 eval { SELECT * FROM t1 } 112} {1 2 3} 113 114do_test 2.2 { 115 set ::STMT [sqlite3_prepare db2 "CREATE INDEX i1 ON t1(x)" -1 tail] 116 set {} {} 117} {} 118 119do_test 2.3 { 120 db1 eval { 121 BEGIN; 122 CREATE INDEX i1 ON t1(x); 123 INSERT INTO t2 VALUES('value!'); 124 } 125} {} 126 127set ::bFired 0 128proc read_callback {call file args} { 129 if { $::bFired==0 && [string match *test.db2-journal $file] } { 130 sqlthread spawn ::thread_result [subst -nocommands { 131 sqlite3_step $::STMT 132 set rc [sqlite3_finalize $::STMT] 133 }] 134 after 1000 { set ::bFired 1 } 135 vwait ::bFired 136 } 137} 138do_test 2.4 { db1 eval ROLLBACK } {} 139 140if {[info exists ::thread_result]==0} { vwait ::thread_result } 141do_test 2.5 { 142 list $::thread_result [sqlite3_errmsg db2] 143} {SQLITE_SCHEMA {database schema has changed}} 144 145db1 close 146db2 close 147tvfs delete 148 149sqlite3_enable_shared_cache $::enable_shared_cache 150finish_test 151 152