xref: /sqlite-3.40.0/test/sharedB.test (revision a895a4d2)
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# Open two database connections on the same database in shared cache
13# mode.  Hold one open while repeatedly closing, reopening, and using
14# the second.
15#
16
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20if {[run_thread_tests]==0} { finish_test ; return }
21db close
22set ::testprefix sharedB
23
24set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
25
26#-------------------------------------------------------------------------
27#
28do_test 1.1 {
29  sqlite3 db1 test.db
30  sqlite3 db2 test.db
31
32  db1 eval {
33    CREATE TABLE t1(x,y TEXT COLLATE nocase);
34    WITH RECURSIVE
35      c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<100)
36    INSERT INTO t1(x,y) SELECT i, printf('x%03dy',i) FROM c;
37    CREATE INDEX t1yx ON t1(y,x);
38  }
39  db2 eval {
40    SELECT x FROM t1 WHERE y='X014Y';
41  }
42} {14}
43
44for {set j 1} {$j<=100} {incr j} {
45  do_test 1.2.$j {
46    db2 close
47    sqlite3 db2 test.db
48    db2 eval {
49      SELECT x FROM t1 WHERE y='X014Y';
50    }
51  } {14}
52}
53
54db1 close
55db2 close
56sqlite3_enable_shared_cache $::enable_shared_cache
57finish_test
58