summaryrefslogtreecommitdiff
path: root/test/shared.test
diff options
context:
space:
mode:
Diffstat (limited to 'test/shared.test')
-rw-r--r--test/shared.test130
1 files changed, 126 insertions, 4 deletions
diff --git a/test/shared.test b/test/shared.test
index 37564e6..4eab476 100644
--- a/test/shared.test
+++ b/test/shared.test
@@ -904,9 +904,11 @@ do_test shared-$av.11.8 {
set res
} {1 4 {} 7}
if {[llength [info command sqlite3_shared_cache_report]]==1} {
- do_test shared-$av.11.9 {
- string tolower [sqlite3_shared_cache_report]
- } [string tolower [list [file nativename [file normalize test.db]] 2]]
+ ifcapable curdir {
+ do_test shared-$av.11.9 {
+ string tolower [sqlite3_shared_cache_report]
+ } [string tolower [list [file nativename [file normalize test.db]] 2]]
+ }
}
do_test shared-$av.11.11 {
@@ -1056,7 +1058,127 @@ do_test shared-$av-15.2 {
db close
db2 close
-}
+# Shared cache on a :memory: database. This only works for URI filenames.
+#
+do_test shared-$av-16.1 {
+ sqlite3 db1 file::memory: -uri 1
+ sqlite3 db2 file::memory: -uri 1
+ db1 eval {
+ CREATE TABLE t1(x); INSERT INTO t1 VALUES(1),(2),(3);
+ }
+ db2 eval {
+ SELECT x FROM t1 ORDER BY x;
+ }
+} {1 2 3}
+do_test shared-$av-16.2 {
+ db2 eval {
+ INSERT INTO t1 VALUES(99);
+ DELETE FROM t1 WHERE x=2;
+ }
+ db1 eval {
+ SELECT x FROM t1 ORDER BY x;
+ }
+} {1 3 99}
+
+# Verify that there is no cache sharing ordinary (non-URI) filenames are
+# used.
+#
+do_test shared-$av-16.3 {
+ db1 close
+ db2 close
+ sqlite3 db1 :memory:
+ sqlite3 db2 :memory:
+ db1 eval {
+ CREATE TABLE t1(x); INSERT INTO t1 VALUES(4),(5),(6);
+ }
+ catchsql {
+ SELECT * FROM t1;
+ } db2
+} {1 {no such table: t1}}
+
+# Shared cache on named memory databases.
+#
+do_test shared-$av-16.4 {
+ db1 close
+ db2 close
+ forcedelete test.db test.db-wal test.db-journal
+ sqlite3 db1 file:test.db?mode=memory -uri 1
+ sqlite3 db2 file:test.db?mode=memory -uri 1
+ db1 eval {
+ CREATE TABLE t1(x); INSERT INTO t1 VALUES(1),(2),(3);
+ }
+ db2 eval {
+ SELECT x FROM t1 ORDER BY x;
+ }
+} {1 2 3}
+do_test shared-$av-16.5 {
+ db2 eval {
+ INSERT INTO t1 VALUES(99);
+ DELETE FROM t1 WHERE x=2;
+ }
+ db1 eval {
+ SELECT x FROM t1 ORDER BY x;
+ }
+} {1 3 99}
+do_test shared-$av-16.6 {
+ file exists test.db
+} {0} ;# Verify that the database is in-memory
+
+# Shared cache on named memory databases with different names.
+#
+do_test shared-$av-16.7 {
+ db1 close
+ db2 close
+ forcedelete test1.db test2.db
+ sqlite3 db1 file:test1.db?mode=memory -uri 1
+ sqlite3 db2 file:test2.db?mode=memory -uri 1
+ db1 eval {
+ CREATE TABLE t1(x); INSERT INTO t1 VALUES(1),(2),(3);
+ }
+ catchsql {
+ SELECT x FROM t1 ORDER BY x;
+ } db2
+} {1 {no such table: t1}}
+do_test shared-$av-16.8 {
+ file exists test1.db
+} {0} ;# Verify that the database is in-memory
+
+# Shared cache on named memory databases attached to readonly connections.
+#
+do_test shared-$av-16.8.1 {
+ db1 close
+ db2 close
+
+ sqlite3 db test1.db
+ db eval {
+ CREATE TABLE yy(a, b);
+ INSERT INTO yy VALUES(77, 88);
+ }
+ db close
+
+ sqlite3 db1 test1.db -uri 1 -readonly 1
+ sqlite3 db2 test2.db -uri 1
+
+ db1 eval {
+ ATTACH 'file:mem?mode=memory&cache=shared' AS shared;
+ CREATE TABLE shared.xx(a, b);
+ INSERT INTO xx VALUES(55, 66);
+ }
+ db2 eval {
+ ATTACH 'file:mem?mode=memory&cache=shared' AS shared;
+ SELECT * FROM xx;
+ }
+} {55 66}
+
+do_test shared-$av-16.8.2 { db1 eval { SELECT * FROM yy } } {77 88}
+do_test shared-$av-16.8.3 {
+ list [catch {db1 eval { INSERT INTO yy VALUES(1, 2) }} msg] $msg
+} {1 {attempt to write a readonly database}}
+
+db1 close
+db2 close
+
+} ;# end of autovacuum on/off loop
sqlite3_enable_shared_cache $::enable_shared_cache
finish_test