blob: 1d09b69b8291e4963d2612e915664c04e5e95611 [file] [log] [blame]
drhf012ea32006-05-24 12:43:26 +00001# 2005 January 19
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#
danielk19778c0a7912008-08-20 14:49:23 +000012# $Id: shared3.test,v 1.4 2008/08/20 14:49:25 danielk1977 Exp $
drhf012ea32006-05-24 12:43:26 +000013
14set testdir [file dirname $argv0]
15source $testdir/tester.tcl
dan56c517a2013-09-26 11:04:33 +000016set testprefix shared3
drhf012ea32006-05-24 12:43:26 +000017db close
18
19ifcapable !shared_cache {
20 finish_test
21 return
22}
23set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
24
25# Ticket #1824
26#
27do_test shared3-1.1 {
mistachkinfda06be2011-08-02 00:57:34 +000028 forcedelete test.db test.db-journal
drhf012ea32006-05-24 12:43:26 +000029 sqlite3 db1 test.db
30 db1 eval {
31 PRAGMA encoding=UTF16;
32 CREATE TABLE t1(x,y);
33 INSERT INTO t1 VALUES('abc','This is a test string');
34 }
35 db1 close
36 sqlite3 db1 test.db
37 db1 eval {SELECT * FROM t1}
38} {abc {This is a test string}}
39do_test shared3-1.2 {
40 sqlite3 db2 test.db
41 db2 eval {SELECT y FROM t1 WHERE x='abc'}
42} {{This is a test string}}
43
44db1 close
45db2 close
46
danielk19779324c8f2008-06-20 17:51:16 +000047do_test shared3-2.1 {
48 sqlite3 db1 test.db
49 execsql {
danielk1977171bfed2008-06-23 09:50:50 +000050 PRAGMA main.cache_size = 10;
danielk19779324c8f2008-06-20 17:51:16 +000051 } db1
52} {}
53do_test shared3-2.2 {
54 execsql { PRAGMA main.cache_size } db1
danielk1977171bfed2008-06-23 09:50:50 +000055} {10}
danielk19779324c8f2008-06-20 17:51:16 +000056do_test shared3-2.3 {
57 sqlite3 db2 test.db
58 execsql { PRAGMA main.cache_size } db1
danielk1977171bfed2008-06-23 09:50:50 +000059} {10}
danielk19779324c8f2008-06-20 17:51:16 +000060do_test shared3-2.4 {
61 execsql { PRAGMA main.cache_size } db2
danielk1977171bfed2008-06-23 09:50:50 +000062} {10}
danielk19779324c8f2008-06-20 17:51:16 +000063do_test shared3-2.5 {
64 execsql { PRAGMA main.cache_size } db1
danielk1977171bfed2008-06-23 09:50:50 +000065} {10}
66
67# The cache-size should now be 10 pages. However at one point there was
68# a bug that caused the cache size to return to the default value when
69# a second connection was opened on the shared-cache (as happened in
70# test case shared3-2.3 above). The goal of the following tests is to
71# ensure that the cache-size really is 10 pages.
72#
73if {$::tcl_platform(platform)=="unix"} {
74 set alternative_name ./test.db
75} else {
76 set alternative_name TEST.DB
77}
78do_test shared3-2.6 {
79 sqlite3 db3 $alternative_name
80 catchsql {select count(*) from sqlite_master} db3
81} {0 1}
82do_test shared3-2.7 {
83 execsql {
84 BEGIN;
85 INSERT INTO t1 VALUES(10, randomblob(5000))
86 } db1
87 catchsql {select count(*) from sqlite_master} db3
88} {0 1}
89do_test shared3-2.8 {
danielk19778c0a7912008-08-20 14:49:23 +000090 db3 close
danielk1977171bfed2008-06-23 09:50:50 +000091 execsql {
92 INSERT INTO t1 VALUES(10, randomblob(10000))
93 } db1
94
95 # If the pager-cache is really still limited to 10 pages, then the INSERT
96 # statement above should have caused the pager to grab an exclusive lock
97 # on the database file so that the cache could be spilled.
98 #
dancb354602010-07-08 09:44:42 +000099 catch { sqlite3 db3 $alternative_name }
danielk1977171bfed2008-06-23 09:50:50 +0000100 catchsql {select count(*) from sqlite_master} db3
101} {1 {database is locked}}
danielk19779324c8f2008-06-20 17:51:16 +0000102
103db1 close
104db2 close
danielk1977171bfed2008-06-23 09:50:50 +0000105db3 close
danielk19779324c8f2008-06-20 17:51:16 +0000106
dan56c517a2013-09-26 11:04:33 +0000107#-------------------------------------------------------------------------
108# At one point this was causing a faulty assert to fail.
109#
110forcedelete test.db
111sqlite3 db test.db
112sqlite3 db2 test.db
113do_execsql_test 3.1 {
114 PRAGMA auto_vacuum = 2;
115 CREATE TABLE t1(x, y);
116 INSERT INTO t1 VALUES(randomblob(500), randomblob(500));
117 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
118 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
119 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
120 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
121 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
122 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
123 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
124}
125do_test 3.2 {
126 execsql { SELECT count(*) FROM sqlite_master } db2
127} {1}
128do_execsql_test 3.3 {
129 BEGIN;
130 DELETE FROM t1 WHERE 1;
131 PRAGMA incremental_vacuum;
132} {}
133do_test 3.4 {
134 execsql { SELECT count(*) FROM sqlite_master } db2
135} {1}
136do_test 3.5 {
137 execsql { COMMIT }
138} {}
139
drhf012ea32006-05-24 12:43:26 +0000140sqlite3_enable_shared_cache $::enable_shared_cache
141finish_test