diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/btree.c | 9 | ||||
-rw-r--r-- | src/pager.c | 12 | ||||
-rw-r--r-- | src/test_osinst.c | 74 |
3 files changed, 70 insertions, 25 deletions
diff --git a/src/btree.c b/src/btree.c index d87eb040f..2f8c6ed3d 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.457 2008/05/07 19:11:03 danielk1977 Exp $ +** $Id: btree.c,v 1.458 2008/05/09 16:57:51 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. @@ -1644,6 +1644,7 @@ int sqlite3BtreeGetAutoVacuum(Btree *p){ static int lockBtree(BtShared *pBt){ int rc; MemPage *pPage1; + int nPage; assert( sqlite3_mutex_held(pBt->mutex) ); if( pBt->pPage1 ) return SQLITE_OK; @@ -1654,7 +1655,11 @@ static int lockBtree(BtShared *pBt){ ** a valid database file. */ rc = SQLITE_NOTADB; - if( sqlite3PagerPagecount(pBt->pPager)>0 ){ + nPage = sqlite3PagerPagecount(pBt->pPager); + if( nPage<0 ){ + rc = SQLITE_IOERR; + goto page1_init_failed; + }else if( nPage>0 ){ int pageSize; int usableSize; u8 *page1 = pPage1->aData; diff --git a/src/pager.c b/src/pager.c index e99e60a53..75f069de6 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.443 2008/05/07 19:11:03 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.444 2008/05/09 16:57:51 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -1397,9 +1397,11 @@ static int pager_end_transaction(Pager *pPager, int hasMaster){ pPager->stmtOpen = 0; } if( pPager->journalOpen ){ - if( (pPager->exclusiveMode || - pPager->journalMode==PAGER_JOURNALMODE_PERSIST) - && (rc = zeroJournalHdr(pPager, hasMaster))==SQLITE_OK ){ + if( pPager->exclusiveMode + || pPager->journalMode==PAGER_JOURNALMODE_PERSIST + ){ + rc = zeroJournalHdr(pPager, hasMaster); + pager_error(pPager, rc); pPager->journalOff = 0; pPager->journalStarted = 0; }else{ @@ -3412,8 +3414,8 @@ static int pagerSharedLock(Pager *pPager){ if( pPager->journalOpen ){ isHot = 1; } - pager_reset(pPager); pPager->errCode = SQLITE_OK; + pager_reset(pPager); } /* If the pager is still in an error state, do not proceed. The error diff --git a/src/test_osinst.c b/src/test_osinst.c index ab7bb54cf..3e61110d1 100644 --- a/src/test_osinst.c +++ b/src/test_osinst.c @@ -303,7 +303,9 @@ static int instWrite( ** Truncate an inst-file. */ static int instTruncate(sqlite3_file *pFile, sqlite_int64 size){ - OS_TIME_IO(OS_TRUNCATE, 0, size, p->pReal->pMethods->xTruncate(p->pReal, size)); + OS_TIME_IO(OS_TRUNCATE, 0, (int)size, + p->pReal->pMethods->xTruncate(p->pReal, size) + ); } /* @@ -632,6 +634,34 @@ static void put32bits(unsigned char *p, unsigned int v){ p[3] = v; } +static void binarylog_flush(InstVfsBinaryLog *pLog){ + sqlite3_file *pFile = pLog->pOut; + +#ifdef SQLITE_TEST + extern int sqlite3_io_error_pending; + extern int sqlite3_io_error_persist; + extern int sqlite3_diskfull_pending; + + int pending = sqlite3_io_error_pending; + int persist = sqlite3_io_error_persist; + int diskfull = sqlite3_diskfull_pending; + + sqlite3_io_error_pending = 0; + sqlite3_io_error_persist = 0; + sqlite3_diskfull_pending = 0; +#endif + + pFile->pMethods->xWrite(pFile, pLog->zBuf, pLog->nBuf, pLog->iOffset); + pLog->iOffset += pLog->nBuf; + pLog->nBuf = 0; + +#ifdef SQLITE_TEST + sqlite3_io_error_pending = pending; + sqlite3_io_error_persist = persist; + sqlite3_diskfull_pending = diskfull; +#endif +} + static void binarylog_xcall( void *p, int eEvent, @@ -646,10 +676,7 @@ static void binarylog_xcall( InstVfsBinaryLog *pLog = (InstVfsBinaryLog *)p; unsigned char *zRec; if( (28+pLog->nBuf)>BINARYLOG_BUFFERSIZE ){ - sqlite3_file *pFile = pLog->pOut; - pFile->pMethods->xWrite(pFile, pLog->zBuf, pLog->nBuf, pLog->iOffset); - pLog->iOffset += pLog->nBuf; - pLog->nBuf = 0; + binarylog_flush(pLog); } zRec = (unsigned char *)&pLog->zBuf[pLog->nBuf]; put32bits(&zRec[0], eEvent); @@ -669,7 +696,7 @@ static void binarylog_xdel(void *p){ InstVfsBinaryLog *pLog = (InstVfsBinaryLog *)p; sqlite3_file *pFile = pLog->pOut; if( pLog->nBuf ){ - pFile->pMethods->xWrite(pFile, pLog->zBuf, pLog->nBuf, pLog->iOffset); + binarylog_flush(pLog); } pFile->pMethods->xClose(pFile); sqlite3_free(pLog->pOut); @@ -698,10 +725,7 @@ static void binarylog_blob( nWrite = nBlob + 28; if( (nWrite+pLog->nBuf)>BINARYLOG_BUFFERSIZE ){ - sqlite3_file *pFile = pLog->pOut; - pFile->pMethods->xWrite(pFile, pLog->zBuf, pLog->nBuf, pLog->iOffset); - pLog->iOffset += pLog->nBuf; - pLog->nBuf = 0; + binarylog_flush(pLog); } zRec = (unsigned char *)&pLog->zBuf[pLog->nBuf]; @@ -750,8 +774,9 @@ sqlite3_vfs *sqlite3_instvfs_binarylog( pParent->xDelete(pParent, p->zOut, 0); rc = pParent->xOpen(pParent, p->zOut, p->pOut, flags, &flags); if( rc==SQLITE_OK ){ - rc = p->pOut->pMethods->xWrite(p->pOut, "sqlite_ostrace1.....", 20, 0); - p->iOffset = 20; + memcpy(p->zBuf, "sqlite_ostrace1.....", 20); + p->iOffset = 0; + p->nBuf = 20; } if( rc ){ binarylog_xdel(p); @@ -863,18 +888,31 @@ static int test_sqlite3_instvfs( case IV_BINARYLOG: { char *zName = 0; char *zLog = 0; + char *zParent = 0; sqlite3_vfs *p; int isDefault = 0; - if( objc>2 && 0==strcmp("-default", Tcl_GetString(objv[2])) ){ + int argbase = 2; + + if( objc>2 && 0==strcmp("-default", Tcl_GetString(objv[argbase])) ){ isDefault = 1; + argbase++; + } + if( objc>(argbase+1) + && 0==strcmp("-parent", Tcl_GetString(objv[argbase])) + ){ + zParent = Tcl_GetString(objv[argbase+1]); + argbase += 2; } - if( (objc-isDefault)!=4 ){ - Tcl_WrongNumArgs(interp, 2, objv, "?-default? NAME LOGFILE"); + + if( (objc-argbase)!=2 ){ + Tcl_WrongNumArgs( + interp, 2, objv, "?-default? ?-parent VFS? NAME LOGFILE" + ); return TCL_ERROR; } - zName = Tcl_GetString(objv[2+isDefault]); - zLog = Tcl_GetString(objv[3+isDefault]); - p = sqlite3_instvfs_binarylog(zName, 0, zLog); + zName = Tcl_GetString(objv[argbase]); + zLog = Tcl_GetString(objv[argbase+1]); + p = sqlite3_instvfs_binarylog(zName, zParent, zLog); if( !p ){ Tcl_AppendResult(interp, "error creating vfs ", 0); return TCL_ERROR; |