/******************************************************************************
** This file is an amalgamation of many separate C source files from SQLite
-** version 3.6.14. By combining all the individual C code files into this
+** version 3.6.14.1. By combining all the individual C code files into this
** single large file, the entire code can be compiled as a one translation
** unit. This allows many compilers to do optimizations that would not be
** possible if the files were compiled separately. Performance improvements
** is also in a separate file. This file contains only code for the core
** SQLite library.
**
-** This amalgamation was generated on 2009-05-07 01:56:00 UTC.
+** This amalgamation was generated on 2009-05-18 18:33:54 UTC.
*/
#define SQLITE_CORE 1
#define SQLITE_AMALGAMATION 1
**
** Requirements: [H10011] [H10014]
*/
-#define SQLITE_VERSION "3.6.14"
+#define SQLITE_VERSION "3.6.14.1"
#define SQLITE_VERSION_NUMBER 3006014
/*
# define SQLITE_OS_WINCE 0
#endif
-#include <ctype.h>
/*
** Define the maximum size of a temporary filename
PCache1 *pCache,
unsigned int iLimit
){
+ TESTONLY( int nPage = 0; ) /* Used to assert pCache->nPage is correct */
unsigned int h;
assert( sqlite3_mutex_held(pcache1.mutex) );
for(h=0; h<pCache->nHash; h++){
PgHdr1 *pPage;
while( (pPage = *pp)!=0 ){
if( pPage->iKey>=iLimit ){
- pcache1PinPage(pPage);
+ pCache->nPage--;
*pp = pPage->pNext;
+ pcache1PinPage(pPage);
pcache1FreePage(pPage);
}else{
pp = &pPage->pNext;
+ TESTONLY( nPage++ );
}
}
}
+ assert( pCache->nPage==nPage );
}
/******************************************************************************/
);
}
- if( sqlite3PcachePagecount(pPager->pPCache)>0 ){
+ if( pPager->pBackup || sqlite3PcachePagecount(pPager->pPCache)>0 ){
/* The shared-lock has just been acquired on the database file
** and there are already pages in the cache (from a previous
** read or write transaction). Check to see if the database
Pgno nRemaining; /* Number of pages left to copy */
Pgno nPagecount; /* Total number of pages to copy */
+ int isAttached; /* True once backup has been registered with pager */
sqlite3_backup *pNext; /* Next backup associated with source pager */
};
p->pDestDb = pDestDb;
p->pSrcDb = pSrcDb;
p->iNext = 1;
+ p->isAttached = 0;
if( 0==p->pSrc || 0==p->pDest ){
/* One (or both) of the named databases did not exist. An error has
p = 0;
}
}
-
- /* If everything has gone as planned, attach the backup object to the
- ** source pager. The source pager calls BackupUpdate() and BackupRestart()
- ** to notify this module if the source file is modified mid-backup.
- */
if( p ){
- sqlite3_backup **pp; /* Pointer to head of pagers backup list */
- sqlite3BtreeEnter(p->pSrc);
- pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc));
- p->pNext = *pp;
- *pp = p;
- sqlite3BtreeLeave(p->pSrc);
p->pSrc->nBackup++;
}
return rc;
}
+/*
+** Register this backup object with the associated source pager for
+** callbacks when pages are changed or the cache invalidated.
+*/
+static void attachBackupObject(sqlite3_backup *p){
+ sqlite3_backup **pp;
+ assert( sqlite3BtreeHoldsMutex(p->pSrc) );
+ pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc));
+ p->pNext = *pp;
+ *pp = p;
+ p->isAttached = 1;
+}
+
/*
** Copy nPage pages from the source b-tree to the destination.
*/
p->nRemaining = nSrcPage+1-p->iNext;
if( p->iNext>(Pgno)nSrcPage ){
rc = SQLITE_DONE;
+ }else if( !p->isAttached ){
+ attachBackupObject(p);
}
}
/* Detach this backup from the source pager. */
if( p->pDestDb ){
+ p->pSrc->nBackup--;
+ }
+ if( p->isAttached ){
pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc));
while( *pp!=p ){
pp = &(*pp)->pNext;
}
*pp = p->pNext;
- p->pSrc->nBackup--;
}
/* If a transaction is still open on the Btree, roll it back. */
pOut = &p->aMem[pOp->p2];
sqlite3VdbeMemReleaseExternal(pOut);
pOut->flags = MEM_Null;
+ pOut->n = 0;
}else
/* Do common setup for opcodes marked with one of the following