CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
shared8.test114 linesDownload Raw Back to test
1# 2012 May 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# The tests in this file are intended to show that closing one database13# 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 any15# other problems.16#17 18set testdir [file dirname $argv0]19source $testdir/tester.tcl20ifcapable !shared_cache { finish_test ; return }21set testprefix shared822 23db close24set ::enable_shared_cache [sqlite3_enable_shared_cache 1]25do_test 0.0 { sqlite3_enable_shared_cache } {1}26 27proc roman {n} {28  array set R {1 i 2 ii 3 iii 4 iv 5 v 6 vi 7 vii 8 viii 9 ix 10 x}29  set R($n)30}31 32#-------------------------------------------------------------------------33# The following tests work as follows:34#35#    1.0: Open connection [db1] and populate the database.36#37#    1.1: Using "PRAGMA writable_schema", destroy the database schema on38#         disk. The schema is still in memory, so it is possible to keep39#         using it, but any attempt to reload it from disk will fail.40#41#    1.3-4: Open connection db2. Check that it can see the db schema. Then42#           close db1 and check that db2 still works. This shows that closing43#           db1 did not reset the in-memory schema.44#45#    1.5-7: Similar to 1.3-4.46#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.49#         50do_test 1.0 {51  sqlite3 db1 test.db52  db1 func roman roman53  execsql {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;60    SELECT * FROM v1;61  } db162} {1 i 2 ii 3 iii 4 iv}63 64do_test 1.1 {65  sqlite3_db_config db1 DEFENSIVE 066  execsql { 67    PRAGMA writable_schema = 1;68    DELETE FROM sqlite_master WHERE 1;69    PRAGMA writable_schema = 0;70    SELECT * FROM sqlite_master;71  } db172} {}73 74do_test 1.2 {75  execsql { SELECT * FROM v1 } db176} {1 i 2 ii 3 iii 4 iv}77 78do_test 1.3 {79  sqlite3 db2 test.db80  db2 func roman roman81  execsql { SELECT * FROM v1 } db282} {1 i 2 ii 3 iii 4 iv}83 84do_test 1.4 {85  db1 close86  execsql { SELECT * FROM v1 } db287} {1 i 2 ii 3 iii 4 iv}88 89do_test 1.5 {90  sqlite3 db3 test.db91  db3 func roman roman92  execsql { SELECT * FROM v1 } db393} {1 i 2 ii 3 iii 4 iv}94 95do_test 1.6 {96  execsql { SELECT * FROM v1 } db297} {1 i 2 ii 3 iii 4 iv}98 99do_test 1.7 {100  db2 close101  execsql { SELECT * FROM v1 } db3102} {1 i 2 ii 3 iii 4 iv}103 104do_test 1.8 {105  db3 close106  sqlite3 db4 test.db107  catchsql { SELECT * FROM v1 } db4108} {1 {no such table: v1}}109 110 111foreach db {db1 db2 db3 db4} { catch { $db close } }112sqlite3_enable_shared_cache $::enable_shared_cache113finish_test114