aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2012-05-27 22:42:57 +0000
committerdrh <drh@noemail.net>2012-05-27 22:42:57 +0000
commit2bfcce45eba070ce39731815cf0f16e7a61e428c (patch)
tree3d433bd08c83c5fad26613118395e87b882d6aa2 /src
parent092a1ebd4c30606ea9ec3dec9b14f3d0b601ab05 (diff)
parentd4e0bb0e65a9cb33ba6139152ddbe652a4ea0393 (diff)
downloadsqlite-2bfcce45eba070ce39731815cf0f16e7a61e428c.tar.gz
sqlite-2bfcce45eba070ce39731815cf0f16e7a61e428c.zip
Merge into trunk the changes that permit :memory: databases to use shared cache.
FossilOrigin-Name: e72179f3a43e4df36b7c2955eaacce6c804272c6
Diffstat (limited to 'src')
-rw-r--r--src/btree.c24
-rw-r--r--src/main.c1
-rw-r--r--src/pager.c18
-rw-r--r--src/pager.h2
-rw-r--r--src/test_btree.c2
-rw-r--r--src/vdbe.c2
6 files changed, 34 insertions, 15 deletions
diff --git a/src/btree.c b/src/btree.c
index 287652692..58a9dce1e 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 && (isMemdb==0 || (vfsFlags&SQLITE_OPEN_URI)!=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);
@@ -1781,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--){
@@ -8046,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);
}
/*
diff --git a/src/main.c b/src/main.c
index d148b4b42..c8fda4787 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2055,6 +2055,7 @@ int sqlite3ParseUri(
memcpy(zFile, zUri, nUri);
zFile[nUri] = '\0';
zFile[nUri+1] = '\0';
+ flags &= ~SQLITE_OPEN_URI;
}
*ppVfs = sqlite3_vfs_find(zVfs);
diff --git a/src/pager.c b/src/pager.c
index b93e0aa86..425fb78ce 100644
--- a/src/pager.c
+++ b/src/pager.c
@@ -4360,7 +4360,12 @@ int sqlite3PagerOpen(
#ifndef SQLITE_OMIT_MEMORYDB
if( flags & PAGER_MEMORY ){
memDb = 1;
- zFilename = 0;
+ if( zFilename && zFilename[0] ){
+ zPathname = sqlite3DbStrDup(0, zFilename);
+ if( zPathname==0 ) return SQLITE_NOMEM;
+ nPathname = sqlite3Strlen30(zPathname);
+ zFilename = 0;
+ }
}
#endif
@@ -6296,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;
}
/*
diff --git a/src/pager.h b/src/pager.h
index eca8a2f07..2b60e058d 100644
--- a/src/pager.h
+++ b/src/pager.h
@@ -151,7 +151,7 @@ int sqlite3PagerCloseWal(Pager *pPager);
u8 sqlite3PagerIsreadonly(Pager*);
int sqlite3PagerRefcount(Pager*);
int sqlite3PagerMemUsed(Pager*);
-const char *sqlite3PagerFilename(Pager*);
+const char *sqlite3PagerFilename(Pager*, int);
const sqlite3_vfs *sqlite3PagerVfs(Pager*);
sqlite3_file *sqlite3PagerFile(Pager*);
const char *sqlite3PagerJournalname(Pager*);
diff --git a/src/test_btree.c b/src/test_btree.c
index 0048397e9..db72889b2 100644
--- a/src/test_btree.c
+++ b/src/test_btree.c
@@ -33,7 +33,7 @@ int sqlite3BtreeSharedCacheReport(
BtShared *pBt;
Tcl_Obj *pRet = Tcl_NewObj();
for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
- const char *zFile = sqlite3PagerFilename(pBt->pPager);
+ const char *zFile = sqlite3PagerFilename(pBt->pPager, 1);
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(zFile, -1));
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(pBt->nRef));
}
diff --git a/src/vdbe.c b/src/vdbe.c
index fa5180c9a..ec4ea2a55 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -5511,7 +5511,7 @@ case OP_JournalMode: { /* out2-prerelease */
if( !sqlite3PagerOkToChangeJournalMode(pPager) ) eNew = eOld;
#ifndef SQLITE_OMIT_WAL
- zFilename = sqlite3PagerFilename(pPager);
+ zFilename = sqlite3PagerFilename(pPager, 1);
/* Do not allow a transition to journal_mode=WAL for a database
** in temporary storage or if the VFS does not support shared memory