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 x 20 21set ::enable_shared_cache [sqlite3_enable_shared_cache 1] 22 23#------------------------------------------------------------------------- 24# 25do_test 1.1 { 26 sqlite3 db1 test.db 27 sqlite3 db2 test.db 28 db2 eval { 29 CREATE TABLE t1(x); 30 INSERT INTO t1 VALUES(123); 31 } 32 db1 eval { 33 SELECT * FROM t1; 34 CREATE INDEX i1 ON t1(x); 35 } 36} {123} 37 38do_test 1.2 { 39 db2 eval { SELECT * FROM t1 ORDER BY x; } 40 41 db1 eval { 42 BEGIN; DROP INDEX i1; 43 } 44 db1 close 45 46 db2 eval { SELECT * FROM t1 ORDER BY x; } 47} {123} 48 49do_test 1.3 { 50 db2 close 51} {} 52 53#------------------------------------------------------------------------- 54# 55testvfs tvfs 56tvfs filter xRead 57tvfs script read_callback 58proc read_callback {args} { } 59 60do_test 2.1 { 61 forcedelete test.db test.db2 62 sqlite3 db1 test.db -vfs tvfs 63 db1 eval { ATTACH 'test.db2' AS two } 64 65 db1 eval { 66 CREATE TABLE t1(x); 67 INSERT INTO t1 VALUES(1); 68 INSERT INTO t1 VALUES(2); 69 INSERT INTO t1 VALUES(3); 70 CREATE TABLE two.t2(x); 71 INSERT INTO t2 SELECT * FROM t1; 72 } 73 74 sqlite3 db2 test.db -vfs tvfs 75 db2 eval { SELECT * FROM t1 } 76} {1 2 3} 77 78do_test 2.2 { 79 set ::STMT [sqlite3_prepare db2 "CREATE INDEX i1 ON t1(x)" -1 tail] 80 set {} {} 81} {} 82 83do_test 2.3 { 84 db1 eval { 85 BEGIN; 86 CREATE INDEX i1 ON t1(x); 87 INSERT INTO t2 VALUES('value!'); 88 } 89} {} 90 91set ::bFired 0 92proc read_callback {call file args} { 93 if { $::bFired==0 && [string match *test.db2-journal $file] } { 94 sqlthread spawn ::thread_result [subst -nocommands { 95 sqlite3_step $::STMT 96 set rc [sqlite3_finalize $::STMT] 97 }] 98 after 1000 { set ::bFired 1 } 99 vwait ::bFired 100 } 101} 102do_test 2.4 { db1 eval ROLLBACK } {} 103 104if {[info exists ::thread_result]==0} { vwait ::thread_result } 105do_test 2.5 { 106 list $::thread_result [sqlite3_errmsg db2] 107} {SQLITE_SCHEMA {database schema has changed}} 108 109db1 close 110db2 close 111tvfs delete 112 113sqlite3_enable_shared_cache $::enable_shared_cache 114finish_test 115 116