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 --- src/btree.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/btree.c') diff --git a/src/btree.c b/src/btree.c index 287652692..a59e6d10c 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1757,7 +1757,7 @@ int sqlite3BtreeOpen( ** If this Btree is a candidate for shared cache, try to find an ** existing BtShared object that we can share with */ - if( isMemdb==0 && isTempDb==0 ){ + if( isTempDb==0 ){ if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){ int nFullPathname = pVfs->mxPathname+1; char *zFullPathname = sqlite3Malloc(nFullPathname); @@ -1767,11 +1767,16 @@ int sqlite3BtreeOpen( sqlite3_free(p); return SQLITE_NOMEM; } - rc = sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname); - if( rc ){ - sqlite3_free(zFullPathname); - sqlite3_free(p); - return rc; + if( isMemdb ){ + memcpy(zFullPathname, zFilename, sqlite3Strlen30(zFilename)+1); + }else{ + rc = sqlite3OsFullPathname(pVfs, zFilename, + nFullPathname, zFullPathname); + if( rc ){ + sqlite3_free(zFullPathname); + sqlite3_free(p); + return rc; + } } #if SQLITE_THREADSAFE mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN); -- 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 --- src/btree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/btree.c') diff --git a/src/btree.c b/src/btree.c index a59e6d10c..136cc196a 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1757,7 +1757,7 @@ int sqlite3BtreeOpen( ** If this Btree is a candidate for shared cache, try to find an ** existing BtShared object that we can share with */ - if( isTempDb==0 ){ + if( isTempDb==0 && (isMemdb==0 || (vfsFlags&SQLITE_OPEN_URI)!=0) ){ if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){ int nFullPathname = pVfs->mxPathname+1; char *zFullPathname = sqlite3Malloc(nFullPathname); -- cgit v1.2.3 From d4e0bb0e65a9cb33ba6139152ddbe652a4ea0393 Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 27 May 2012 01:19:04 +0000 Subject: Have user interfaces report out the filename of in-memory databases as an empty string, as it always has. This simplifies the changes. FossilOrigin-Name: 595dfdbffefb2598cba89980f885289d1c5f5833 --- src/btree.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/btree.c') diff --git a/src/btree.c b/src/btree.c index 136cc196a..58a9dce1e 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1786,7 +1786,7 @@ int sqlite3BtreeOpen( #endif for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){ assert( pBt->nRef>0 ); - if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager)) + if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager, 0)) && sqlite3PagerVfs(pBt->pPager)==pVfs ){ int iDb; for(iDb=db->nDb-1; iDb>=0; iDb--){ @@ -8051,14 +8051,15 @@ char *sqlite3BtreeIntegrityCheck( #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ /* -** Return the full pathname of the underlying database file. +** Return the full pathname of the underlying database file. Return +** an empty string if the database is in-memory or a TEMP database. ** ** The pager filename is invariant as long as the pager is ** open so it is safe to access without the BtShared mutex. */ const char *sqlite3BtreeGetFilename(Btree *p){ assert( p->pBt->pPager!=0 ); - return sqlite3PagerFilename(p->pBt->pPager); + return sqlite3PagerFilename(p->pBt->pPager, 1); } /* -- 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 --- src/btree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/btree.c') diff --git a/src/btree.c b/src/btree.c index 58a9dce1e..c16eca5f6 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1721,7 +1721,8 @@ int sqlite3BtreeOpen( const int isMemdb = 0; #else const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0) - || (isTempDb && sqlite3TempInMemory(db)); + || (isTempDb && sqlite3TempInMemory(db)) + || (vfsFlags & SQLITE_OPEN_MEMORY)!=0; #endif assert( db!=0 ); -- cgit v1.2.3