/ Check-in [595dfdbf]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Have user interfaces report out the filename of in-memory databases as an empty string, as it always has. This simplifies the changes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | shared-cache-memdb
Files: files | file ages | folders
SHA1: 595dfdbffefb2598cba89980f885289d1c5f5833
User & Date: drh 2012-05-27 01:19:04
Context
2012-05-27
22:42
Merge into trunk the changes that permit :memory: databases to use shared cache. check-in: e72179f3 user: drh tags: trunk
01:19
Have user interfaces report out the filename of in-memory databases as an empty string, as it always has. This simplifies the changes. Closed-Leaf check-in: 595dfdbf user: drh tags: shared-cache-memdb
2012-05-26
20:08
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. check-in: e3ad61e0 user: drh tags: shared-cache-memdb
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  1782   1782         mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
  1783   1783         sqlite3_mutex_enter(mutexOpen);
  1784   1784         mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
  1785   1785         sqlite3_mutex_enter(mutexShared);
  1786   1786   #endif
  1787   1787         for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
  1788   1788           assert( pBt->nRef>0 );
  1789         -        if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager))
         1789  +        if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager, 0))
  1790   1790                    && sqlite3PagerVfs(pBt->pPager)==pVfs ){
  1791   1791             int iDb;
  1792   1792             for(iDb=db->nDb-1; iDb>=0; iDb--){
  1793   1793               Btree *pExisting = db->aDb[iDb].pBt;
  1794   1794               if( pExisting && pExisting->pBt==pBt ){
  1795   1795                 sqlite3_mutex_leave(mutexShared);
  1796   1796                 sqlite3_mutex_leave(mutexOpen);
................................................................................
  8047   8047     *pnErr = sCheck.nErr;
  8048   8048     if( sCheck.nErr==0 ) sqlite3StrAccumReset(&sCheck.errMsg);
  8049   8049     return sqlite3StrAccumFinish(&sCheck.errMsg);
  8050   8050   }
  8051   8051   #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
  8052   8052   
  8053   8053   /*
  8054         -** Return the full pathname of the underlying database file.
         8054  +** Return the full pathname of the underlying database file.  Return
         8055  +** an empty string if the database is in-memory or a TEMP database.
  8055   8056   **
  8056   8057   ** The pager filename is invariant as long as the pager is
  8057   8058   ** open so it is safe to access without the BtShared mutex.
  8058   8059   */
  8059   8060   const char *sqlite3BtreeGetFilename(Btree *p){
  8060   8061     assert( p->pBt->pPager!=0 );
  8061         -  return sqlite3PagerFilename(p->pBt->pPager);
         8062  +  return sqlite3PagerFilename(p->pBt->pPager, 1);
  8062   8063   }
  8063   8064   
  8064   8065   /*
  8065   8066   ** Return the pathname of the journal file for this database. The return
  8066   8067   ** value of this routine is the same regardless of whether the journal file
  8067   8068   ** has been created or not.
  8068   8069   **

Changes to src/pager.c.

  4356   4356   
  4357   4357     /* Set the output variable to NULL in case an error occurs. */
  4358   4358     *ppPager = 0;
  4359   4359   
  4360   4360   #ifndef SQLITE_OMIT_MEMORYDB
  4361   4361     if( flags & PAGER_MEMORY ){
  4362   4362       memDb = 1;
  4363         -    if( zFilename ){
         4363  +    if( zFilename && zFilename[0] ){
  4364   4364         zPathname = sqlite3DbStrDup(0, zFilename);
  4365   4365         if( zPathname==0  ) return SQLITE_NOMEM;
  4366   4366         nPathname = sqlite3Strlen30(zPathname);
  4367   4367         zFilename = 0;
  4368   4368       }
  4369   4369     }
  4370   4370   #endif
................................................................................
  6297   6297     }
  6298   6298   
  6299   6299     return rc;
  6300   6300   }
  6301   6301   
  6302   6302   /*
  6303   6303   ** Return the full pathname of the database file.
         6304  +**
         6305  +** Except, if the pager is in-memory only, then return an empty string if
         6306  +** nullIfMemDb is true.  This routine is called with nullIfMemDb==1 when
         6307  +** used to report the filename to the user, for compatibility with legacy
         6308  +** behavior.  But when the Btree needs to know the filename for matching to
         6309  +** shared cache, it uses nullIfMemDb==0 so that in-memory databases can
         6310  +** participate in shared-cache.
  6304   6311   */
  6305         -const char *sqlite3PagerFilename(Pager *pPager){
  6306         -  return pPager->zFilename;
         6312  +const char *sqlite3PagerFilename(Pager *pPager, int nullIfMemDb){
         6313  +  return (nullIfMemDb && pPager->memDb) ? "" : pPager->zFilename;
  6307   6314   }
  6308   6315   
  6309   6316   /*
  6310   6317   ** Return the VFS structure for the pager.
  6311   6318   */
  6312   6319   const sqlite3_vfs *sqlite3PagerVfs(Pager *pPager){
  6313   6320     return pPager->pVfs;
................................................................................
  6744   6751   
  6745   6752   /*
  6746   6753   ** Return true if the underlying VFS for the given pager supports the
  6747   6754   ** primitives necessary for write-ahead logging.
  6748   6755   */
  6749   6756   int sqlite3PagerWalSupported(Pager *pPager){
  6750   6757     const sqlite3_io_methods *pMethods = pPager->fd->pMethods;
  6751         -  return pPager->memDb==0 && 
  6752         -        (pPager->exclusiveMode || (pMethods->iVersion>=2 && pMethods->xShmMap));
         6758  +  return pPager->exclusiveMode || (pMethods->iVersion>=2 && pMethods->xShmMap);
  6753   6759   }
  6754   6760   
  6755   6761   /*
  6756   6762   ** Attempt to take an exclusive lock on the database file. If a PENDING lock
  6757   6763   ** is obtained instead, immediately release it.
  6758   6764   */
  6759   6765   static int pagerExclusiveLock(Pager *pPager){

Changes to src/pager.h.

   147    147     int sqlite3PagerWalFramesize(Pager *pPager);
   148    148   #endif
   149    149   
   150    150   /* Functions used to query pager state and configuration. */
   151    151   u8 sqlite3PagerIsreadonly(Pager*);
   152    152   int sqlite3PagerRefcount(Pager*);
   153    153   int sqlite3PagerMemUsed(Pager*);
   154         -const char *sqlite3PagerFilename(Pager*);
          154  +const char *sqlite3PagerFilename(Pager*, int);
   155    155   const sqlite3_vfs *sqlite3PagerVfs(Pager*);
   156    156   sqlite3_file *sqlite3PagerFile(Pager*);
   157    157   const char *sqlite3PagerJournalname(Pager*);
   158    158   int sqlite3PagerNosync(Pager*);
   159    159   void *sqlite3PagerTempSpace(Pager*);
   160    160   int sqlite3PagerIsMemdb(Pager*);
   161    161   void sqlite3PagerCacheStat(Pager *, int, int, int *);

Changes to src/test_btree.c.

    29     29     Tcl_Obj *CONST objv[]
    30     30   ){
    31     31   #ifndef SQLITE_OMIT_SHARED_CACHE
    32     32     extern BtShared *sqlite3SharedCacheList;
    33     33     BtShared *pBt;
    34     34     Tcl_Obj *pRet = Tcl_NewObj();
    35     35     for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
    36         -    const char *zFile = sqlite3PagerFilename(pBt->pPager);
           36  +    const char *zFile = sqlite3PagerFilename(pBt->pPager, 1);
    37     37       Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(zFile, -1));
    38     38       Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(pBt->nRef));
    39     39     }
    40     40     Tcl_SetObjResult(interp, pRet);
    41     41   #endif
    42     42     return TCL_OK;
    43     43   }

Changes to src/vdbe.c.

  5507   5507     pBt = db->aDb[pOp->p1].pBt;
  5508   5508     pPager = sqlite3BtreePager(pBt);
  5509   5509     eOld = sqlite3PagerGetJournalMode(pPager);
  5510   5510     if( eNew==PAGER_JOURNALMODE_QUERY ) eNew = eOld;
  5511   5511     if( !sqlite3PagerOkToChangeJournalMode(pPager) ) eNew = eOld;
  5512   5512   
  5513   5513   #ifndef SQLITE_OMIT_WAL
  5514         -  zFilename = sqlite3PagerFilename(pPager);
         5514  +  zFilename = sqlite3PagerFilename(pPager, 1);
  5515   5515   
  5516   5516     /* Do not allow a transition to journal_mode=WAL for a database
  5517   5517     ** in temporary storage or if the VFS does not support shared memory 
  5518   5518     */
  5519   5519     if( eNew==PAGER_JOURNALMODE_WAL
  5520   5520      && (sqlite3Strlen30(zFilename)==0           /* Temp file */
  5521   5521          || !sqlite3PagerWalSupported(pPager))   /* No shared-memory support */

Changes to test/attach.test.

   853    853       SELECT name FROM inmem.sqlite_master;
   854    854     }
   855    855   } {noname inmem}
   856    856   do_test attach-10.2 {
   857    857     lrange [execsql {
   858    858       PRAGMA database_list;
   859    859     }] 9 end
   860         -} {4 noname {} 5 inmem :memory:}
          860  +} {4 noname {} 5 inmem {}}
   861    861   
   862    862   finish_test