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/pager.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/pager.c') diff --git a/src/pager.c b/src/pager.c index b93e0aa86..43c00c7ec 100644 --- a/src/pager.c +++ b/src/pager.c @@ -4360,6 +4360,8 @@ int sqlite3PagerOpen( #ifndef SQLITE_OMIT_MEMORYDB if( flags & PAGER_MEMORY ){ memDb = 1; + zPathname = sqlite3DbStrDup(0, zFilename); + nPathname = sqlite3Strlen30(zPathname); zFilename = 0; } #endif @@ -6743,7 +6745,8 @@ int sqlite3PagerWalCallback(Pager *pPager){ */ int sqlite3PagerWalSupported(Pager *pPager){ const sqlite3_io_methods *pMethods = pPager->fd->pMethods; - return pPager->exclusiveMode || (pMethods->iVersion>=2 && pMethods->xShmMap); + return pPager->memDb==0 && + (pPager->exclusiveMode || (pMethods->iVersion>=2 && pMethods->xShmMap)); } /* -- 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/pager.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/pager.c') diff --git a/src/pager.c b/src/pager.c index 43c00c7ec..0154a5d7f 100644 --- a/src/pager.c +++ b/src/pager.c @@ -4360,9 +4360,12 @@ int sqlite3PagerOpen( #ifndef SQLITE_OMIT_MEMORYDB if( flags & PAGER_MEMORY ){ memDb = 1; - zPathname = sqlite3DbStrDup(0, zFilename); - nPathname = sqlite3Strlen30(zPathname); - zFilename = 0; + if( zFilename ){ + zPathname = sqlite3DbStrDup(0, zFilename); + if( zPathname==0 ) return SQLITE_NOMEM; + nPathname = sqlite3Strlen30(zPathname); + zFilename = 0; + } } #endif -- 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/pager.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/pager.c') diff --git a/src/pager.c b/src/pager.c index 0154a5d7f..425fb78ce 100644 --- a/src/pager.c +++ b/src/pager.c @@ -4360,7 +4360,7 @@ int sqlite3PagerOpen( #ifndef SQLITE_OMIT_MEMORYDB if( flags & PAGER_MEMORY ){ memDb = 1; - if( zFilename ){ + if( zFilename && zFilename[0] ){ zPathname = sqlite3DbStrDup(0, zFilename); if( zPathname==0 ) return SQLITE_NOMEM; nPathname = sqlite3Strlen30(zPathname); @@ -6301,9 +6301,16 @@ int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint){ /* ** Return the full pathname of the database file. +** +** Except, if the pager is in-memory only, then return an empty string if +** nullIfMemDb is true. This routine is called with nullIfMemDb==1 when +** used to report the filename to the user, for compatibility with legacy +** behavior. But when the Btree needs to know the filename for matching to +** shared cache, it uses nullIfMemDb==0 so that in-memory databases can +** participate in shared-cache. */ -const char *sqlite3PagerFilename(Pager *pPager){ - return pPager->zFilename; +const char *sqlite3PagerFilename(Pager *pPager, int nullIfMemDb){ + return (nullIfMemDb && pPager->memDb) ? "" : pPager->zFilename; } /* @@ -6748,8 +6755,7 @@ int sqlite3PagerWalCallback(Pager *pPager){ */ int sqlite3PagerWalSupported(Pager *pPager){ const sqlite3_io_methods *pMethods = pPager->fd->pMethods; - return pPager->memDb==0 && - (pPager->exclusiveMode || (pMethods->iVersion>=2 && pMethods->xShmMap)); + return pPager->exclusiveMode || (pMethods->iVersion>=2 && pMethods->xShmMap); } /* -- cgit v1.2.3