/ Check-in [997ef5f6]
Login

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

Overview
Comment:Fix corner-case problems with shared-cache for in-memory databases.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | shared-cache-memdb
Files: files | file ages | folders
SHA1:997ef5f61e2a603ee2c36e87c42784ca48eebdc3
User & Date: drh 2012-05-27 00:11:02
Context
2012-05-27
00:11
Fix corner-case problems with shared-cache for in-memory databases. Closed-Leaf check-in: 997ef5f6 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.

  8056   8056   ** The pager filename is invariant as long as the pager is
  8057   8057   ** open so it is safe to access without the BtShared mutex.
  8058   8058   */
  8059   8059   const char *sqlite3BtreeGetFilename(Btree *p){
  8060   8060     assert( p->pBt->pPager!=0 );
  8061   8061     return sqlite3PagerFilename(p->pBt->pPager);
  8062   8062   }
         8063  +
         8064  +/*
         8065  +** Return true if the Btree is a persistent database, not an in-memory
         8066  +** or temporary database.
         8067  +*/
         8068  +int sqlite3BtreePersists(Btree *p){
         8069  +  Pager *pPager = p->pBt->pPager;
         8070  +  const char *z;
         8071  +  assert( pPager!=0 );
         8072  +  return sqlite3PagerIsMemdb(pPager)==0
         8073  +      && (z = sqlite3PagerFilename(pPager))!=0 && z[0]!=0;
         8074  +}
  8063   8075   
  8064   8076   /*
  8065   8077   ** Return the pathname of the journal file for this database. The return
  8066   8078   ** value of this routine is the same regardless of whether the journal file
  8067   8079   ** has been created or not.
  8068   8080   **
  8069   8081   ** The pager journal filename is invariant as long as the pager is

Changes to src/btree.h.

    86     86   void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
    87     87   int sqlite3BtreeSchemaLocked(Btree *pBtree);
    88     88   int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
    89     89   int sqlite3BtreeSavepoint(Btree *, int, int);
    90     90   
    91     91   const char *sqlite3BtreeGetFilename(Btree *);
    92     92   const char *sqlite3BtreeGetJournalname(Btree *);
           93  +int sqlite3BtreePersists(Btree*);
    93     94   int sqlite3BtreeCopyFile(Btree *, Btree *);
    94     95   
    95     96   int sqlite3BtreeIncrVacuum(Btree *);
    96     97   
    97     98   /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
    98     99   ** of the flags shown below.
    99    100   **

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

Changes to src/vdbeaux.c.

  1785   1785       }
  1786   1786     }
  1787   1787   
  1788   1788     /* The simple case - no more than one database file (not counting the
  1789   1789     ** TEMP database) has a transaction active.   There is no need for the
  1790   1790     ** master-journal.
  1791   1791     **
  1792         -  ** If the return value of sqlite3BtreeGetFilename() is a zero length
  1793         -  ** string, it means the main database is :memory: or a temp file.  In 
  1794         -  ** that case we do not support atomic multi-file commits, so use the 
         1792  +  ** If the main database is :memory: or a temp file then
         1793  +  ** we do not support atomic multi-file commits, so use the 
  1795   1794     ** simple case then too.
  1796   1795     */
  1797         -  if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db->aDb[0].pBt))
         1796  +  if( 0==sqlite3BtreePersists(db->aDb[0].pBt)
  1798   1797      || nTrans<=1
  1799   1798     ){
  1800   1799       for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
  1801   1800         Btree *pBt = db->aDb[i].pBt;
  1802   1801         if( pBt ){
  1803   1802           rc = sqlite3BtreeCommitPhaseOne(pBt, 0);
  1804   1803         }