From afc8b7f0c14ba5acd6d08245e32d1a39fe96a185 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 26 May 2012 18:06:38 +0000 Subject: Enable the use of shared cache for an in-memory database, so that separate database connections can share the same in-memory database. FossilOrigin-Name: 4590e433f2a595bb80fb061024b0a3d2ca25b7b2 --- test/shared.test | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'test/shared.test') diff --git a/test/shared.test b/test/shared.test index 37564e696..156f894a1 100644 --- a/test/shared.test +++ b/test/shared.test @@ -1056,7 +1056,29 @@ do_test shared-$av-15.2 { db close db2 close -} +# Shared cache on a :memory: database. +# +do_test shared-$av-16.1 { + sqlite3 db1 :memory: + sqlite3 db2 :memory: + 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} + +} ;# end of autovacuum on/off loop sqlite3_enable_shared_cache $::enable_shared_cache finish_test -- cgit v1.2.3 From 4ab9d254e066247855b8907d001b9994aa072f1f Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 26 May 2012 20:08:49 +0000 Subject: Only allow :memory: databases to share cache if there are created using a URI filename. This minimizes the risk of breakages in legacy applications that have shared-cache enabled but also use :memory: databases which they expect to keep separate. FossilOrigin-Name: e3ad61e0308a8442c2bdb7cdb3465576cd39ed4a --- test/shared.test | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'test/shared.test') diff --git a/test/shared.test b/test/shared.test index 156f894a1..0c5c408b3 100644 --- a/test/shared.test +++ b/test/shared.test @@ -1056,11 +1056,11 @@ do_test shared-$av-15.2 { db close db2 close -# Shared cache on a :memory: database. +# Shared cache on a :memory: database. This only works for URI filenames. # do_test shared-$av-16.1 { - sqlite3 db1 :memory: - sqlite3 db2 :memory: + 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); } @@ -1078,6 +1078,24 @@ do_test shared-$av-16.2 { } } {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}} +db1 close +db2 close + } ;# end of autovacuum on/off loop sqlite3_enable_shared_cache $::enable_shared_cache -- cgit v1.2.3 From 9c67b2aae06e8571e8c5faa8968fab8286a70672 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 28 May 2012 13:58:00 +0000 Subject: Add the mode=memory option to URI filenames, which when present forces the database to be an in-memory database. This enables named in-memory databases. FossilOrigin-Name: 651520fa84ee0c488bef660bab9865500309d5e9 --- test/shared.test | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'test/shared.test') diff --git a/test/shared.test b/test/shared.test index 0c5c408b3..44df2b469 100644 --- a/test/shared.test +++ b/test/shared.test @@ -1093,6 +1093,55 @@ do_test shared-$av-16.3 { 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 + + db1 close db2 close -- cgit v1.2.3