3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # The tests in this file are intended to show that closing one database
13 # connection to a shared-cache while there exist other connections (a)
14 # does not cause the schema to be reloaded and (b) does not cause any
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
20 ifcapable !shared_cache { finish_test ; return }
21 set testprefix shared8
24 set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
25 do_test 0.0 { sqlite3_enable_shared_cache } {1}
28 array set R {1 i 2 ii 3 iii 4 iv 5 v 6 vi 7 vii 8 viii 9 ix 10 x}
32 #-------------------------------------------------------------------------
33 # The following tests work as follows:
35 # 1.0: Open connection [db1] and populate the database.
37 # 1.1: Using "PRAGMA writable_schema", destroy the database schema on
38 # disk. The schema is still in memory, so it is possible to keep
39 # using it, but any attempt to reload it from disk will fail.
41 # 1.3-4: Open connection db2. Check that it can see the db schema. Then
42 # close db1 and check that db2 still works. This shows that closing
43 # db1 did not reset the in-memory schema.
45 # 1.5-7: Similar to 1.3-4.
47 # 1.8: Close all database connections (deleting the in-memory schema).
48 # Then open a new connection and check that it cannot read the db.
54 CREATE TABLE t1(a, b);
55 INSERT INTO t1 VALUES(1, 1);
56 INSERT INTO t1 VALUES(2, 2);
57 INSERT INTO t1 VALUES(3, 3);
58 INSERT INTO t1 VALUES(4, 4);
59 CREATE VIEW v1 AS SELECT a, roman(b) FROM t1;
62 } {1 i 2 ii 3 iii 4 iv}
66 PRAGMA writable_schema = 1;
67 DELETE FROM sqlite_master WHERE 1;
68 PRAGMA writable_schema = 0;
69 SELECT * FROM sqlite_master;
74 execsql { SELECT * FROM v1 } db1
75 } {1 i 2 ii 3 iii 4 iv}
80 execsql { SELECT * FROM v1 } db2
81 } {1 i 2 ii 3 iii 4 iv}
85 execsql { SELECT * FROM v1 } db2
86 } {1 i 2 ii 3 iii 4 iv}
91 execsql { SELECT * FROM v1 } db3
92 } {1 i 2 ii 3 iii 4 iv}
95 execsql { SELECT * FROM v1 } db2
96 } {1 i 2 ii 3 iii 4 iv}
100 execsql { SELECT * FROM v1 } db3
101 } {1 i 2 ii 3 iii 4 iv}
106 catchsql { SELECT * FROM v1 } db4
107 } {1 {no such table: v1}}
110 foreach db {db1 db2 db3 db4} { catch { $db close } }
111 sqlite3_enable_shared_cache $::enable_shared_cache