Index: src/btree.c ================================================================== --- src/btree.c +++ src/btree.c @@ -7,11 +7,11 @@ ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.340 2007/03/19 11:54:10 drh Exp $ +** $Id: btree.c,v 1.341 2007/03/19 17:44:27 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to ** ** Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3: @@ -289,10 +289,11 @@ u8 *pCell; /* Pointers to the body of the overflow cell */ u16 idx; /* Insert this cell before idx-th non-overflow cell */ } aOvfl[5]; BtShared *pBt; /* Pointer back to BTree structure */ u8 *aData; /* Pointer back to the start of the page */ + DbPage *pDbPage; /* Pager page handle */ Pgno pgno; /* Page number for this page */ MemPage *pParent; /* The parent of this page. NULL for root */ }; /* @@ -813,13 +814,14 @@ ** This routine updates the pointer map entry for page number 'key' ** so that it maps to type 'eType' and parent page number 'pgno'. ** An error code is returned if something goes wrong, otherwise SQLITE_OK. */ static int ptrmapPut(BtShared *pBt, Pgno key, u8 eType, Pgno parent){ - u8 *pPtrmap; /* The pointer map page */ - Pgno iPtrmap; /* The pointer map page number */ - int offset; /* Offset in pointer map page */ + DbPage *pDbPage; /* The pointer map page */ + u8 *pPtrmap; /* The pointer map data */ + Pgno iPtrmap; /* The pointer map page number */ + int offset; /* Offset in pointer map page */ int rc; /* The master-journal page number must never be used as a pointer map page */ assert( 0==PTRMAP_ISPAGE(pBt, PENDING_BYTE_PAGE(pBt)) ); @@ -826,26 +828,27 @@ assert( pBt->autoVacuum ); if( key==0 ){ return SQLITE_CORRUPT_BKPT; } iPtrmap = PTRMAP_PAGENO(pBt, key); - rc = sqlite3pager_get(pBt->pPager, iPtrmap, (void **)&pPtrmap); + rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage); if( rc!=SQLITE_OK ){ return rc; } offset = PTRMAP_PTROFFSET(pBt, key); + pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage); if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=parent ){ TRACE(("PTRMAP_UPDATE: %d->(%d,%d)\n", key, eType, parent)); - rc = sqlite3pager_write(pPtrmap); + rc = sqlite3PagerWrite(pDbPage); if( rc==SQLITE_OK ){ pPtrmap[offset] = eType; put4byte(&pPtrmap[offset+1], parent); } } - sqlite3pager_unref(pPtrmap); + sqlite3PagerUnref(pDbPage); return rc; } /* ** Read an entry from the pointer map. @@ -853,27 +856,29 @@ ** This routine retrieves the pointer map entry for page 'key', writing ** the type and parent page number to *pEType and *pPgno respectively. ** An error code is returned if something goes wrong, otherwise SQLITE_OK. */ static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno){ + DbPage *pDbPage; /* The pointer map page */ int iPtrmap; /* Pointer map page index */ u8 *pPtrmap; /* Pointer map page data */ int offset; /* Offset of entry in pointer map */ int rc; iPtrmap = PTRMAP_PAGENO(pBt, key); - rc = sqlite3pager_get(pBt->pPager, iPtrmap, (void **)&pPtrmap); + rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage); if( rc!=0 ){ return rc; } + pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage); offset = PTRMAP_PTROFFSET(pBt, key); assert( pEType!=0 ); *pEType = pPtrmap[offset]; if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]); - sqlite3pager_unref(pPtrmap); + sqlite3PagerUnref(pDbPage); if( *pEType<1 || *pEType>5 ) return SQLITE_CORRUPT_BKPT; return SQLITE_OK; } #endif /* SQLITE_OMIT_AUTOVACUUM */ @@ -1069,11 +1074,11 @@ int brk; /* Offset to the cell content area */ int nCell; /* Number of cells on the page */ unsigned char *data; /* The page data */ unsigned char *temp; /* Temp area for cell content */ - assert( sqlite3pager_iswriteable(pPage->aData) ); + assert( sqlite3PagerIswriteable(pPage->pDbPage) ); assert( pPage->pBt!=0 ); assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE ); assert( pPage->nOverflow==0 ); temp = sqliteMalloc( pPage->pBt->pageSize ); if( temp==0 ) return SQLITE_NOMEM; @@ -1127,11 +1132,11 @@ int nCell; int cellOffset; unsigned char *data; data = pPage->aData; - assert( sqlite3pager_iswriteable(data) ); + assert( sqlite3PagerIswriteable(pPage->pDbPage) ); assert( pPage->pBt ); if( nByte<4 ) nByte = 4; if( pPage->nFreenOverflow>0 ) return 0; pPage->nFree -= nByte; hdr = pPage->hdrOffset; @@ -1184,11 +1189,11 @@ static void freeSpace(MemPage *pPage, int start, int size){ int addr, pbegin, hdr; unsigned char *data = pPage->aData; assert( pPage->pBt!=0 ); - assert( sqlite3pager_iswriteable(data) ); + assert( sqlite3PagerIswriteable(pPage->pDbPage) ); assert( start>=pPage->hdrOffset+6+(pPage->leaf?0:4) ); assert( (start + size)<=pPage->pBt->usableSize ); if( size<4 ) size = 4; #ifdef SQLITE_SECURE_DELETE @@ -1293,20 +1298,20 @@ int top; /* First byte of the cell content area */ pBt = pPage->pBt; assert( pBt!=0 ); assert( pParent==0 || pParent->pBt==pBt ); - assert( pPage->pgno==sqlite3pager_pagenumber(pPage->aData) ); + assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) ); assert( pPage->aData == &((unsigned char*)pPage)[-pBt->pageSize] ); if( pPage->pParent!=pParent && (pPage->pParent!=0 || pPage->isInit) ){ /* The parent page should never change unless the file is corrupt */ return SQLITE_CORRUPT_BKPT; } if( pPage->isInit ) return SQLITE_OK; if( pPage->pParent==0 && pParent!=0 ){ pPage->pParent = pParent; - sqlite3pager_ref(pParent->aData); + sqlite3PagerRef(pParent->pDbPage); } hdr = pPage->hdrOffset; data = pPage->aData; decodeFlags(pPage, data[hdr]); pPage->nOverflow = 0; @@ -1360,13 +1365,13 @@ unsigned char *data = pPage->aData; BtShared *pBt = pPage->pBt; int hdr = pPage->hdrOffset; int first; - assert( sqlite3pager_pagenumber(data)==pPage->pgno ); + assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno ); assert( &data[pBt->pageSize] == (unsigned char*)pPage ); - assert( sqlite3pager_iswriteable(data) ); + assert( sqlite3PagerIswriteable(pPage->pDbPage) ); memset(&data[hdr], 0, pBt->usableSize - hdr); data[hdr] = flags; first = hdr + 8 + 4*((flags&PTF_LEAF)==0); memset(&data[hdr+1], 0, 4); data[hdr+7] = 0; @@ -1385,22 +1390,24 @@ ** Get a page from the pager. Initialize the MemPage.pBt and ** MemPage.aData elements if needed. */ static int getPage(BtShared *pBt, Pgno pgno, MemPage **ppPage, int clrFlag){ int rc; - unsigned char *aData; MemPage *pPage; - rc = sqlite3pager_acquire(pBt->pPager, pgno, (void**)&aData, clrFlag); + DbPage *pDbPage; + + rc = sqlite3PagerAcquire(pBt->pPager, pgno, (DbPage**)&pDbPage, clrFlag); if( rc ) return rc; - pPage = (MemPage*)&aData[pBt->pageSize]; - pPage->aData = aData; + pPage = (MemPage *)sqlite3PagerGetExtra(pDbPage); + pPage->aData = sqlite3PagerGetData(pDbPage); + pPage->pDbPage = pDbPage; pPage->pBt = pBt; pPage->pgno = pgno; pPage->hdrOffset = pPage->pgno==1 ? 100 : 0; *ppPage = pPage; if( clrFlag ){ - sqlite3pager_dont_rollback(aData); + sqlite3PagerDontRollback(pPage->pDbPage); } return SQLITE_OK; } /* @@ -1432,23 +1439,23 @@ static void releasePage(MemPage *pPage){ if( pPage ){ assert( pPage->aData ); assert( pPage->pBt ); assert( &pPage->aData[pPage->pBt->pageSize]==(unsigned char*)pPage ); - sqlite3pager_unref(pPage->aData); + sqlite3PagerUnref(pPage->pDbPage); } } /* ** This routine is called when the reference count for a page ** reaches zero. We need to unref the pParent pointer when that ** happens. */ -static void pageDestructor(void *pData, int pageSize){ +static void pageDestructor(DbPage *pData, int pageSize){ MemPage *pPage; assert( (pageSize & 7)==0 ); - pPage = (MemPage*)&((char*)pData)[pageSize]; + pPage = (MemPage *)sqlite3PagerGetExtra(pData); if( pPage->pParent ){ MemPage *pParent = pPage->pParent; pPage->pParent = 0; releasePage(pParent); } @@ -1461,14 +1468,14 @@ ** the transaction, for each page restored this routine is called. ** ** This routine needs to reset the extra data section at the end of the ** page to agree with the restored data. */ -static void pageReinit(void *pData, int pageSize){ +static void pageReinit(DbPage *pData, int pageSize){ MemPage *pPage; assert( (pageSize & 7)==0 ); - pPage = (MemPage*)&((char*)pData)[pageSize]; + pPage = (MemPage *)sqlite3PagerGetExtra(pData); if( pPage->isInit ){ pPage->isInit = 0; initPage(pPage, pPage->pParent); } } @@ -1524,11 +1531,11 @@ sqliteFree(p); return SQLITE_NOMEM; } for(pBt=pTsdro->pBtree; pBt; pBt=pBt->pNext){ assert( pBt->nRef>0 ); - if( 0==strcmp(zFullPathname, sqlite3pager_filename(pBt->pPager)) ){ + if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager)) ){ p->pBt = pBt; *ppBtree = p; pBt->nRef++; sqliteFree(zFullPathname); return SQLITE_OK; @@ -1553,30 +1560,30 @@ if( pBt==0 ){ *ppBtree = 0; sqliteFree(p); return SQLITE_NOMEM; } - rc = sqlite3pager_open(&pBt->pPager, zFilename, EXTRA_SIZE, flags); + rc = sqlite3PagerOpen(&pBt->pPager, zFilename, EXTRA_SIZE, flags); if( rc==SQLITE_OK ){ - rc = sqlite3pager_read_fileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader); + rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader); } if( rc!=SQLITE_OK ){ if( pBt->pPager ){ - sqlite3pager_close(pBt->pPager); + sqlite3PagerClose(pBt->pPager); } sqliteFree(pBt); sqliteFree(p); *ppBtree = 0; return rc; } p->pBt = pBt; - sqlite3pager_set_destructor(pBt->pPager, pageDestructor); - sqlite3pager_set_reiniter(pBt->pPager, pageReinit); + sqlite3PagerSetDestructor(pBt->pPager, pageDestructor); + sqlite3PagerSetReiniter(pBt->pPager, pageReinit); pBt->pCursor = 0; pBt->pPage1 = 0; - pBt->readOnly = sqlite3pager_isreadonly(pBt->pPager); + pBt->readOnly = sqlite3PagerIsreadonly(pBt->pPager); pBt->pageSize = get2byte(&zDbHeader[16]); if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){ pBt->pageSize = SQLITE_DEFAULT_PAGE_SIZE; pBt->maxEmbedFrac = 64; /* 25% */ @@ -1604,11 +1611,11 @@ pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0); #endif } pBt->usableSize = pBt->pageSize - nReserve; assert( (pBt->pageSize & 7)==0 ); /* 8-byte alignment of pageSize */ - sqlite3pager_set_pagesize(pBt->pPager, pBt->pageSize); + sqlite3PagerSetPagesize(pBt->pPager, pBt->pageSize); #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO) /* Add the new btree to the linked list starting at ThreadData.pBtree. ** There is no chance that a malloc() may fail inside of the ** sqlite3ThreadData() call, as the ThreadData structure must have already @@ -1681,11 +1688,11 @@ } #endif /* Close the pager and free the shared-btree structure */ assert( !pBt->pCursor ); - sqlite3pager_close(pBt->pPager); + sqlite3PagerClose(pBt->pPager); if( pBt->xFreeSchema && pBt->pSchema ){ pBt->xFreeSchema(pBt->pSchema); } sqliteFree(pBt->pSchema); sqliteFree(pBt); @@ -1696,11 +1703,11 @@ ** Change the busy handler callback function. */ int sqlite3BtreeSetBusyHandler(Btree *p, BusyHandler *pHandler){ BtShared *pBt = p->pBt; pBt->pBusyHandler = pHandler; - sqlite3pager_set_busyhandler(pBt->pPager, pHandler); + sqlite3PagerSetBusyhandler(pBt->pPager, pHandler); return SQLITE_OK; } /* ** Change the limit on the number of pages allowed in the cache. @@ -1717,11 +1724,11 @@ ** Synchronous is on by default so database corruption is not ** normally a worry. */ int sqlite3BtreeSetCacheSize(Btree *p, int mxPage){ BtShared *pBt = p->pBt; - sqlite3pager_set_cachesize(pBt->pPager, mxPage); + sqlite3PagerSetCachesize(pBt->pPager, mxPage); return SQLITE_OK; } /* ** Change the way data is synced to disk in order to increase or decrease @@ -1732,11 +1739,11 @@ ** probability of damage to near zero but with a write performance reduction. */ #ifndef SQLITE_OMIT_PAGER_PRAGMAS int sqlite3BtreeSetSafetyLevel(Btree *p, int level, int fullSync){ BtShared *pBt = p->pBt; - sqlite3pager_set_safety_level(pBt->pPager, level, fullSync); + sqlite3PagerSetSafetyLevel(pBt->pPager, level, fullSync); return SQLITE_OK; } #endif /* @@ -1744,11 +1751,11 @@ ** words, return TRUE if no sync() occurs on the disk files. */ int sqlite3BtreeSyncDisabled(Btree *p){ BtShared *pBt = p->pBt; assert( pBt && pBt->pPager ); - return sqlite3pager_nosync(pBt->pPager); + return sqlite3PagerNosync(pBt->pPager); } #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM) /* ** Change the default pages size and the number of reserved bytes per page. @@ -1775,11 +1782,11 @@ } if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE && ((pageSize-1)&pageSize)==0 ){ assert( (pageSize & 7)==0 ); assert( !pBt->pPage1 && !pBt->pCursor ); - pBt->pageSize = sqlite3pager_set_pagesize(pBt->pPager, pageSize); + pBt->pageSize = sqlite3PagerSetPagesize(pBt->pPager, pageSize); } pBt->usableSize = pBt->pageSize - nReserve; return SQLITE_OK; } @@ -1846,11 +1853,11 @@ /* Do some checking to help insure the file we opened really is ** a valid database file. */ rc = SQLITE_NOTADB; - if( sqlite3pager_pagecount(pBt->pPager)>0 ){ + if( sqlite3PagerPagecount(pBt->pPager)>0 ){ u8 *page1 = pPage1->aData; if( memcmp(page1, zMagicHeader, 16)!=0 ){ goto page1_init_failed; } if( page1[18]>1 || page1[19]>1 ){ @@ -1935,11 +1942,11 @@ ** ** If there is a transaction in progress, this routine is a no-op. */ static void unlockBtreeIfUnused(BtShared *pBt){ if( pBt->inTransaction==TRANS_NONE && pBt->pCursor==0 && pBt->pPage1!=0 ){ - if( sqlite3pager_refcount(pBt->pPager)>=1 ){ + if( sqlite3PagerRefcount(pBt->pPager)>=1 ){ if( pBt->pPage1->aData==0 ){ MemPage *pPage = pBt->pPage1; pPage->aData = &((u8*)pPage)[-pBt->pageSize]; pPage->pBt = pBt; pPage->pgno = 1; @@ -1957,15 +1964,15 @@ */ static int newDatabase(BtShared *pBt){ MemPage *pP1; unsigned char *data; int rc; - if( sqlite3pager_pagecount(pBt->pPager)>0 ) return SQLITE_OK; + if( sqlite3PagerPagecount(pBt->pPager)>0 ) return SQLITE_OK; pP1 = pBt->pPage1; assert( pP1!=0 ); data = pP1->aData; - rc = sqlite3pager_write(data); + rc = sqlite3PagerWrite(pP1->pDbPage); if( rc ) return rc; memcpy(data, zMagicHeader, sizeof(zMagicHeader)); assert( sizeof(zMagicHeader)==16 ); put2byte(&data[16], pBt->pageSize); data[18] = 1; @@ -2051,11 +2058,11 @@ if( pBt->pPage1==0 ){ rc = lockBtree(pBt); } if( rc==SQLITE_OK && wrflag ){ - rc = sqlite3pager_begin(pBt->pPage1->aData, wrflag>1); + rc = sqlite3PagerBegin(pBt->pPage1->pDbPage, wrflag>1); if( rc==SQLITE_OK ){ rc = newDatabase(pBt); } } @@ -2207,11 +2214,11 @@ eType==PTRMAP_BTREE || eType==PTRMAP_ROOTPAGE ); /* Move page iDbPage from it's current location to page number iFreePage */ TRACE(("AUTOVACUUM: Moving %d to free page %d (ptr page %d type %d)\n", iDbPage, iFreePage, iPtrPage, eType)); - rc = sqlite3pager_movepage(pPager, pDbPage->aData, iFreePage); + rc = sqlite3PagerMovepage(pPager, pDbPage->pDbPage, iFreePage); if( rc!=SQLITE_OK ){ return rc; } pDbPage->pgno = iFreePage; @@ -2245,11 +2252,11 @@ if( eType!=PTRMAP_ROOTPAGE ){ rc = getPage(pBt, iPtrPage, &pPtrPage, 0); if( rc!=SQLITE_OK ){ return rc; } - rc = sqlite3pager_write(pPtrPage->aData); + rc = sqlite3PagerWrite(pPtrPage->pDbPage); if( rc!=SQLITE_OK ){ releasePage(pPtrPage); return rc; } rc = modifyPagePointer(pPtrPage, iDbPage, iFreePage, eType); @@ -2263,11 +2270,11 @@ /* Forward declaration required by autoVacuumCommit(). */ static int allocatePage(BtShared *, MemPage **, Pgno *, Pgno, u8); /* -** This routine is called prior to sqlite3pager_commit when a transaction +** This routine is called prior to sqlite3PagerCommit when a transaction ** is commited for an auto-vacuum database. */ static int autoVacuumCommit(BtShared *pBt, Pgno *nTrunc){ Pager *pPager = pBt->pPager; Pgno nFreeList; /* Number of pages remaining on the free-list. */ @@ -2282,15 +2289,15 @@ Pgno iPtrPage; /* The page that contains a pointer to iDbPage */ Pgno iFreePage; /* The free-list page to move iDbPage to */ MemPage *pFreeMemPage = 0; /* "" */ #ifndef NDEBUG - int nRef = sqlite3pager_refcount(pPager); + int nRef = sqlite3PagerRefcount(pPager); #endif assert( pBt->autoVacuum ); - if( PTRMAP_ISPAGE(pBt, sqlite3pager_pagecount(pPager)) ){ + if( PTRMAP_ISPAGE(pBt, sqlite3PagerPagecount(pPager)) ){ return SQLITE_CORRUPT_BKPT; } /* Figure out how many free-pages are in the database. If there are no ** free pages, then auto-vacuum is a no-op. @@ -2308,11 +2315,11 @@ ** The final size is the original size, less the number of free pages ** in the database, less any pointer-map pages that will no longer ** be required, less 1 if the pending-byte page was part of the database ** but is not after the truncation. **/ - origSize = sqlite3pager_pagecount(pPager); + origSize = sqlite3PagerPagecount(pPager); if( origSize==PENDING_BYTE_PAGE(pBt) ){ origSize--; } nPtrMap = (nFreeList-origSize+PTRMAP_PAGENO(pBt, origSize)+pgsz/5)/(pgsz/5); finSize = origSize - nFreeList - nPtrMap; @@ -2382,21 +2389,21 @@ /* The entire free-list has been swapped to the end of the file. So ** truncate the database file to finSize pages and consider the ** free-list empty. */ - rc = sqlite3pager_write(pBt->pPage1->aData); + rc = sqlite3PagerWrite(pBt->pPage1->pDbPage); if( rc!=SQLITE_OK ) goto autovacuum_out; put4byte(&pBt->pPage1->aData[32], 0); put4byte(&pBt->pPage1->aData[36], 0); *nTrunc = finSize; assert( finSize!=PENDING_BYTE_PAGE(pBt) ); autovacuum_out: - assert( nRef==sqlite3pager_refcount(pPager) ); + assert( nRef==sqlite3PagerRefcount(pPager) ); if( rc!=SQLITE_OK ){ - sqlite3pager_rollback(pPager); + sqlite3PagerRollback(pPager); } return rc; } #endif @@ -2416,11 +2423,11 @@ */ if( p->inTrans==TRANS_WRITE ){ int rc; assert( pBt->inTransaction==TRANS_WRITE ); assert( pBt->nTransaction>0 ); - rc = sqlite3pager_commit(pBt->pPager); + rc = sqlite3PagerCommit(pBt->pPager); if( rc!=SQLITE_OK ){ return rc; } pBt->inTransaction = TRANS_READ; pBt->inStmt = 0; @@ -2521,11 +2528,11 @@ if( p->inTrans==TRANS_WRITE ){ int rc2; assert( TRANS_WRITE==pBt->inTransaction ); - rc2 = sqlite3pager_rollback(pBt->pPager); + rc2 = sqlite3PagerRollback(pBt->pPager); if( rc2!=SQLITE_OK ){ rc = rc2; } /* The rollback may have destroyed the pPage1->aData value. So @@ -2574,11 +2581,11 @@ BtShared *pBt = p->pBt; if( (p->inTrans!=TRANS_WRITE) || pBt->inStmt ){ return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR; } assert( pBt->inTransaction==TRANS_WRITE ); - rc = pBt->readOnly ? SQLITE_OK : sqlite3pager_stmt_begin(pBt->pPager); + rc = pBt->readOnly ? SQLITE_OK : sqlite3PagerStmtBegin(pBt->pPager); pBt->inStmt = 1; return rc; } @@ -2588,11 +2595,11 @@ */ int sqlite3BtreeCommitStmt(Btree *p){ int rc; BtShared *pBt = p->pBt; if( pBt->inStmt && !pBt->readOnly ){ - rc = sqlite3pager_stmt_commit(pBt->pPager); + rc = sqlite3PagerStmtCommit(pBt->pPager); }else{ rc = SQLITE_OK; } pBt->inStmt = 0; return rc; @@ -2609,11 +2616,11 @@ int sqlite3BtreeRollbackStmt(Btree *p){ int rc = SQLITE_OK; BtShared *pBt = p->pBt; sqlite3MallocDisallow(); if( pBt->inStmt && !pBt->readOnly ){ - rc = sqlite3pager_stmt_rollback(pBt->pPager); + rc = sqlite3PagerStmtRollback(pBt->pPager); assert( countWriteCursors(pBt)==0 ); pBt->inStmt = 0; } sqlite3MallocAllow(); return rc; @@ -2701,11 +2708,11 @@ if( pCur==0 ){ rc = SQLITE_NOMEM; goto create_cursor_exception; } pCur->pgnoRoot = (Pgno)iTable; - if( iTable==1 && sqlite3pager_pagecount(pBt->pPager)==0 ){ + if( iTable==1 && sqlite3PagerPagecount(pBt->pPager)==0 ){ rc = SQLITE_EMPTY; goto create_cursor_exception; } rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->pPage, 0); if( rc!=SQLITE_OK ){ @@ -2780,21 +2787,21 @@ static void getTempCursor(BtCursor *pCur, BtCursor *pTempCur){ memcpy(pTempCur, pCur, sizeof(*pCur)); pTempCur->pNext = 0; pTempCur->pPrev = 0; if( pTempCur->pPage ){ - sqlite3pager_ref(pTempCur->pPage->aData); + sqlite3PagerRef(pTempCur->pPage->pDbPage); } } /* ** Delete a temporary cursor such as was made by the CreateTemporaryCursor() ** function above. */ static void releaseTempCursor(BtCursor *pCur){ if( pCur->pPage ){ - sqlite3pager_unref(pCur->pPage->aData); + sqlite3PagerUnref(pCur->pPage->pDbPage); } } /* ** Make sure the BtCursor.info field of the given cursor is valid. @@ -2920,14 +2927,16 @@ } ovflSize = pBt->usableSize - 4; if( amt>0 ){ nextPage = get4byte(&aPayload[pCur->info.nLocal]); while( amt>0 && nextPage ){ - rc = sqlite3pager_get(pBt->pPager, nextPage, (void**)&aPayload); + DbPage *pDbPage; + rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage); if( rc!=0 ){ return rc; } + aPayload = sqlite3PagerGetData(pDbPage); nextPage = get4byte(aPayload); if( offset ovflSize ){ a = ovflSize - offset; @@ -2937,11 +2946,11 @@ amt -= a; pBuf += a; }else{ offset -= ovflSize; } - sqlite3pager_unref(aPayload); + sqlite3PagerUnref(pDbPage); } } if( amt>0 ){ return SQLITE_CORRUPT_BKPT; @@ -3134,11 +3143,11 @@ assert( pPage!=0 ); assert( !isRootPage(pPage) ); pParent = pPage->pParent; assert( pParent!=0 ); idxParent = pPage->idxParent; - sqlite3pager_ref(pParent->aData); + sqlite3PagerRef(pParent->pDbPage); releasePage(pPage); pCur->pPage = pParent; pCur->info.nSize = 0; assert( pParent->idxShift==0 ); pCur->idx = idxParent; @@ -3538,18 +3547,18 @@ } /* ** Allocate a new page from the database file. ** -** The new page is marked as dirty. (In other words, sqlite3pager_write() +** The new page is marked as dirty. (In other words, sqlite3PagerWrite() ** has already been called on the new page.) The new page has also ** been referenced and the calling routine is responsible for calling -** sqlite3pager_unref() on the new page when it is done. +** sqlite3PagerUnref() on the new page when it is done. ** ** SQLITE_OK is returned on success. Any other return value indicates ** an error. *ppPage and *pPgno are undefined in the event of an error. -** Do not invoke sqlite3pager_unref() on *ppPage if an error is returned. +** Do not invoke sqlite3PagerUnref() on *ppPage if an error is returned. ** ** If the "nearby" parameter is not 0, then a (feeble) effort is made to ** locate a page close to the page number "nearby". This can be used in an ** attempt to keep related pages close to each other in the database file, ** which in turn can make database access faster. @@ -3598,11 +3607,11 @@ #endif /* Decrement the free-list count by 1. Set iTrunk to the index of the ** first free-list trunk page. iPrevTrunk is initially 1. */ - rc = sqlite3pager_write(pPage1->aData); + rc = sqlite3PagerWrite(pPage1->pDbPage); if( rc ) return rc; put4byte(&pPage1->aData[36], n-1); /* The code within this loop is run only once if the 'searchList' variable ** is not true. Otherwise, it runs once for each trunk-page on the @@ -3625,11 +3634,11 @@ if( k==0 && !searchList ){ /* The trunk has no leaves and the list is not being searched. ** So extract the trunk page itself and use it as the newly ** allocated page */ assert( pPrevTrunk==0 ); - rc = sqlite3pager_write(pTrunk->aData); + rc = sqlite3PagerWrite(pTrunk->pDbPage); if( rc ){ goto end_allocate_page; } *pPgno = iTrunk; memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4); @@ -3646,11 +3655,11 @@ ** to allocate, regardless of whether it has leaves. */ assert( *pPgno==iTrunk ); *ppPage = pTrunk; searchList = 0; - rc = sqlite3pager_write(pTrunk->aData); + rc = sqlite3PagerWrite(pTrunk->pDbPage); if( rc ){ goto end_allocate_page; } if( k==0 ){ if( !pPrevTrunk ){ @@ -3667,11 +3676,11 @@ Pgno iNewTrunk = get4byte(&pTrunk->aData[8]); rc = getPage(pBt, iNewTrunk, &pNewTrunk, 0); if( rc!=SQLITE_OK ){ goto end_allocate_page; } - rc = sqlite3pager_write(pNewTrunk->aData); + rc = sqlite3PagerWrite(pNewTrunk->pDbPage); if( rc!=SQLITE_OK ){ releasePage(pNewTrunk); goto end_allocate_page; } memcpy(&pNewTrunk->aData[0], &pTrunk->aData[0], 4); @@ -3679,11 +3688,11 @@ memcpy(&pNewTrunk->aData[8], &pTrunk->aData[12], (k-1)*4); releasePage(pNewTrunk); if( !pPrevTrunk ){ put4byte(&pPage1->aData[32], iNewTrunk); }else{ - rc = sqlite3pager_write(pPrevTrunk->aData); + rc = sqlite3PagerWrite(pPrevTrunk->pDbPage); if( rc ){ goto end_allocate_page; } put4byte(&pPrevTrunk->aData[0], iNewTrunk); } @@ -3694,11 +3703,11 @@ }else{ /* Extract a leaf from the trunk */ int closest; Pgno iPage; unsigned char *aData = pTrunk->aData; - rc = sqlite3pager_write(aData); + rc = sqlite3PagerWrite(pTrunk->pDbPage); if( rc ){ goto end_allocate_page; } if( nearby>0 ){ int i, dist; @@ -3718,11 +3727,11 @@ } iPage = get4byte(&aData[8+closest*4]); if( !searchList || iPage==nearby ){ *pPgno = iPage; - if( *pPgno>sqlite3pager_pagecount(pBt->pPager) ){ + if( *pPgno>sqlite3PagerPagecount(pBt->pPager) ){ /* Free page off the end of the file */ return SQLITE_CORRUPT_BKPT; } TRACE(("ALLOCATE: %d was leaf %d of %d on trunk %d" ": %d more free pages\n", @@ -3731,11 +3740,11 @@ memcpy(&aData[8+closest*4], &aData[4+k*4], 4); } put4byte(&aData[4], k-1); rc = getPage(pBt, *pPgno, ppPage, 1); if( rc==SQLITE_OK ){ - rc = sqlite3pager_write((*ppPage)->aData); + rc = sqlite3PagerWrite((*ppPage)->pDbPage); if( rc!=SQLITE_OK ){ releasePage(*ppPage); } } searchList = 0; @@ -3745,11 +3754,11 @@ pPrevTrunk = 0; }while( searchList ); }else{ /* There are no pages on the freelist, so create a new page at the ** end of the file */ - *pPgno = sqlite3pager_pagecount(pBt->pPager) + 1; + *pPgno = sqlite3PagerPagecount(pBt->pPager) + 1; #ifndef SQLITE_OMIT_AUTOVACUUM if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, *pPgno) ){ /* If *pPgno refers to a pointer-map page, allocate two new pages ** at the end of the file instead of one. The first allocated page @@ -3762,11 +3771,11 @@ #endif assert( *pPgno!=PENDING_BYTE_PAGE(pBt) ); rc = getPage(pBt, *pPgno, ppPage, 0); if( rc ) return rc; - rc = sqlite3pager_write((*ppPage)->aData); + rc = sqlite3PagerWrite((*ppPage)->pDbPage); if( rc!=SQLITE_OK ){ releasePage(*ppPage); } TRACE(("ALLOCATE: %d from end of file\n", *pPgno)); } @@ -3780,11 +3789,11 @@ } /* ** Add a page of the database file to the freelist. ** -** sqlite3pager_unref() is NOT called for pPage. +** sqlite3PagerUnref() is NOT called for pPage. */ static int freePage(MemPage *pPage){ BtShared *pBt = pPage->pBt; MemPage *pPage1 = pBt->pPage1; int rc, n, k; @@ -3794,20 +3803,20 @@ pPage->isInit = 0; releasePage(pPage->pParent); pPage->pParent = 0; /* Increment the free page count on pPage1 */ - rc = sqlite3pager_write(pPage1->aData); + rc = sqlite3PagerWrite(pPage1->pDbPage); if( rc ) return rc; n = get4byte(&pPage1->aData[36]); put4byte(&pPage1->aData[36], n+1); #ifdef SQLITE_SECURE_DELETE /* If the SQLITE_SECURE_DELETE compile-time option is enabled, then ** always fully overwrite deleted information with zeros. */ - rc = sqlite3pager_write(pPage->aData); + rc = sqlite3PagerWrite(pPage->pDbPage); if( rc ) return rc; memset(pPage->aData, 0, pPage->pBt->pageSize); #endif #ifndef SQLITE_OMIT_AUTOVACUUM @@ -3820,11 +3829,11 @@ } #endif if( n==0 ){ /* This is the first free page */ - rc = sqlite3pager_write(pPage->aData); + rc = sqlite3PagerWrite(pPage->pDbPage); if( rc ) return rc; memset(pPage->aData, 0, 8); put4byte(&pPage1->aData[32], pPage->pgno); TRACE(("FREE-PAGE: %d first\n", pPage->pgno)); }else{ @@ -3835,25 +3844,25 @@ if( rc ) return rc; k = get4byte(&pTrunk->aData[4]); if( k>=pBt->usableSize/4 - 8 ){ /* The trunk is full. Turn the page being freed into a new ** trunk page with no leaves. */ - rc = sqlite3pager_write(pPage->aData); + rc = sqlite3PagerWrite(pPage->pDbPage); if( rc ) return rc; put4byte(pPage->aData, pTrunk->pgno); put4byte(&pPage->aData[4], 0); put4byte(&pPage1->aData[32], pPage->pgno); TRACE(("FREE-PAGE: %d new trunk page replacing %d\n", pPage->pgno, pTrunk->pgno)); }else{ /* Add the newly freed page as a leaf on the current trunk */ - rc = sqlite3pager_write(pTrunk->aData); + rc = sqlite3PagerWrite(pTrunk->pDbPage); if( rc ) return rc; put4byte(&pTrunk->aData[4], k+1); put4byte(&pTrunk->aData[8+k*4], pPage->pgno); #ifndef SQLITE_SECURE_DELETE - sqlite3pager_dont_write(pBt->pPager, pPage->pgno); + sqlite3PagerDontWrite(pBt->pPager, pPage->pgno); #endif TRACE(("FREE-PAGE: %d leaf on trunk page %d\n",pPage->pgno,pTrunk->pgno)); } releasePage(pTrunk); } @@ -3879,20 +3888,20 @@ ovflPageSize = pBt->usableSize - 4; nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize; assert( ovflPgno==0 || nOvfl>0 ); while( nOvfl-- ){ MemPage *pOvfl; - if( ovflPgno==0 || ovflPgno>sqlite3pager_pagecount(pBt->pPager) ){ + if( ovflPgno==0 || ovflPgno>sqlite3PagerPagecount(pBt->pPager) ){ return SQLITE_CORRUPT_BKPT; } rc = getPage(pBt, ovflPgno, &pOvfl, 0); if( rc ) return rc; if( nOvfl ){ ovflPgno = get4byte(pOvfl->aData); } rc = freePage(pOvfl); - sqlite3pager_unref(pOvfl->aData); + sqlite3PagerUnref(pOvfl->pDbPage); if( rc ) return rc; } return SQLITE_OK; } @@ -4012,28 +4021,28 @@ ** given in the second argument so that MemPage.pParent holds the ** pointer in the third argument. */ static int reparentPage(BtShared *pBt, Pgno pgno, MemPage *pNewParent, int idx){ MemPage *pThis; - unsigned char *aData; + DbPage *pDbPage; assert( pNewParent!=0 ); if( pgno==0 ) return SQLITE_OK; assert( pBt->pPager!=0 ); - aData = sqlite3pager_lookup(pBt->pPager, pgno); - if( aData ){ - pThis = (MemPage*)&aData[pBt->pageSize]; + pDbPage = sqlite3PagerLookup(pBt->pPager, pgno); + if( pDbPage ){ + pThis = (MemPage *)sqlite3PagerGetExtra(pDbPage); if( pThis->isInit ){ - assert( pThis->aData==aData ); + assert( pThis->aData==(sqlite3PagerGetData(pDbPage)) ); if( pThis->pParent!=pNewParent ){ - if( pThis->pParent ) sqlite3pager_unref(pThis->pParent->aData); + if( pThis->pParent ) sqlite3PagerUnref(pThis->pParent->pDbPage); pThis->pParent = pNewParent; - sqlite3pager_ref(pNewParent->aData); + sqlite3PagerRef(pNewParent->pDbPage); } pThis->idxParent = idx; } - sqlite3pager_unref(aData); + sqlite3PagerUnref(pDbPage); } #ifndef SQLITE_OMIT_AUTOVACUUM if( pBt->autoVacuum ){ return ptrmapPut(pBt, pgno, PTRMAP_BTREE, pNewParent->pgno); @@ -4090,11 +4099,11 @@ u8 *data; /* pPage->aData */ u8 *ptr; /* Used to move bytes around within data[] */ assert( idx>=0 && idxnCell ); assert( sz==cellSize(pPage, idx) ); - assert( sqlite3pager_iswriteable(pPage->aData) ); + assert( sqlite3PagerIswriteable(pPage->pDbPage) ); data = pPage->aData; ptr = &data[pPage->cellOffset + 2*idx]; pc = get2byte(ptr); assert( pc>10 && pc+sz<=pPage->pBt->usableSize ); freeSpace(pPage, pc, sz); @@ -4143,11 +4152,11 @@ u8 *data; /* The content of the whole page */ u8 *ptr; /* Used for moving information around in data[] */ assert( i>=0 && i<=pPage->nCell+pPage->nOverflow ); assert( sz==cellSizePtr(pPage, pCell) ); - assert( sqlite3pager_iswriteable(pPage->aData) ); + assert( sqlite3PagerIswriteable(pPage->pDbPage) ); if( pPage->nOverflow || sz+2>pPage->nFree ){ if( pTemp ){ memcpy(pTemp+nSkip, pCell+nSkip, sz-nSkip); pCell = pTemp; } @@ -4307,11 +4316,11 @@ assemblePage(pNew, 1, &pCell, &szCell); pPage->nOverflow = 0; /* Set the parent of the newly allocated page to pParent. */ pNew->pParent = pParent; - sqlite3pager_ref(pParent->aData); + sqlite3PagerRef(pParent->pDbPage); /* pPage is currently the right-child of pParent. Change this ** so that the right-child is the new page allocated above and ** pPage is the next-to-right child. */ @@ -4432,15 +4441,15 @@ /* ** Find the parent page. */ assert( pPage->isInit ); - assert( sqlite3pager_iswriteable(pPage->aData) ); + assert( sqlite3PagerIswriteable(pPage->pDbPage) ); pBt = pPage->pBt; pParent = pPage->pParent; assert( pParent ); - if( SQLITE_OK!=(rc = sqlite3pager_write(pParent->aData)) ){ + if( SQLITE_OK!=(rc = sqlite3PagerWrite(pParent->pDbPage)) ){ return rc; } TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno)); #ifndef SQLITE_OMIT_QUICKBALANCE @@ -4474,11 +4483,11 @@ ** is the rightmost child of pParent then set idx to pParent->nCell */ if( pParent->idxShift ){ Pgno pgno; pgno = pPage->pgno; - assert( pgno==sqlite3pager_pagenumber(pPage->aData) ); + assert( pgno==sqlite3PagerPagenumber(pPage->pDbPage) ); for(idx=0; idxnCell; idx++){ if( get4byte(findCell(pParent, idx))==pgno ){ break; } } @@ -4491,11 +4500,11 @@ /* ** Initialize variables so that it will be safe to jump ** directly to balance_cleanup at any moment. */ nOld = nNew = 0; - sqlite3pager_ref(pParent->aData); + sqlite3PagerRef(pParent->pDbPage); /* ** Find sibling pages to pPage and the cells in pParent that divide ** the siblings. An attempt is made to find NN siblings on either ** side of pPage. More siblings are taken from one side, however, if @@ -4735,11 +4744,11 @@ MemPage *pNew; if( iaData); + rc = sqlite3PagerWrite(pNew->pDbPage); if( rc ) goto balance_cleanup; }else{ assert( i>0 ); rc = allocatePage(pBt, &pNew, &pgnoNew[i], pgnoNew[i-1], 0); if( rc ) goto balance_cleanup; @@ -4978,11 +4987,11 @@ ** for the right-pointer to the child page. The child page becomes ** the virtual root of the tree. */ pgnoChild = get4byte(&pPage->aData[pPage->hdrOffset+8]); assert( pgnoChild>0 ); - assert( pgnoChild<=sqlite3pager_pagecount(pPage->pBt->pPager) ); + assert( pgnoChild<=sqlite3PagerPagecount(pPage->pBt->pPager) ); rc = getPage(pPage->pBt, pgnoChild, &pChild, 0); if( rc ) goto end_shallow_balance; if( pPage->pgno==1 ){ rc = initPage(pChild, pPage); if( rc ) goto end_shallow_balance; @@ -5062,11 +5071,11 @@ assert( pPage->pParent==0 ); assert( pPage->nOverflow>0 ); pBt = pPage->pBt; rc = allocatePage(pBt, &pChild, &pgnoChild, pPage->pgno, 0); if( rc ) return rc; - assert( sqlite3pager_iswriteable(pChild->aData) ); + assert( sqlite3PagerIswriteable(pChild->pDbPage) ); usableSize = pBt->usableSize; data = pPage->aData; hdr = pPage->hdrOffset; brk = get2byte(&data[hdr+5]); cdata = pChild->aData; @@ -5211,11 +5220,11 @@ assert( pPage->leaf || !pPage->leafData ); TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n", pCur->pgnoRoot, nKey, nData, pPage->pgno, loc==0 ? "overwrite" : "new entry")); assert( pPage->isInit ); - rc = sqlite3pager_write(pPage->aData); + rc = sqlite3PagerWrite(pPage->pDbPage); if( rc ) return rc; newCell = sqliteMallocRaw( MX_CELL_SIZE(pBt) ); if( newCell==0 ) return SQLITE_NOMEM; rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, &szNew); if( rc ) goto end_insert; @@ -5279,17 +5288,17 @@ return SQLITE_LOCKED; /* The table pCur points to has a read lock */ } /* Restore the current cursor position (a no-op if the cursor is not in ** CURSOR_REQUIRESEEK state) and save the positions of any other cursors - ** open on the same table. Then call sqlite3pager_write() on the page + ** open on the same table. Then call sqlite3PagerWrite() on the page ** that the entry will be deleted from. */ if( (rc = restoreOrClearCursorPosition(pCur, 1))!=0 || (rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur))!=0 || - (rc = sqlite3pager_write(pPage->aData))!=0 + (rc = sqlite3PagerWrite(pPage->pDbPage))!=0 ){ return rc; } /* Locate the cell within it's page and leave pCell pointing to the @@ -5325,11 +5334,11 @@ if( rc!=SQLITE_NOMEM ){ rc = SQLITE_CORRUPT_BKPT; } } if( rc==SQLITE_OK ){ - rc = sqlite3pager_write(leafCur.pPage->aData); + rc = sqlite3PagerWrite(leafCur.pPage->pDbPage); } if( rc==SQLITE_OK ){ TRACE(("DELETE: table=%d delete internal from %d replace from leaf %d\n", pCur->pgnoRoot, pPage->pgno, leafCur.pPage->pgno)); dropCell(pPage, pCur->idx, cellSizePtr(pPage, pCell)); @@ -5445,11 +5454,11 @@ releasePage(pRoot); return rc; } assert( eType!=PTRMAP_ROOTPAGE ); assert( eType!=PTRMAP_FREEPAGE ); - rc = sqlite3pager_write(pRoot->aData); + rc = sqlite3PagerWrite(pRoot->pDbPage); if( rc!=SQLITE_OK ){ releasePage(pRoot); return rc; } rc = relocatePage(pBt, pRoot, eType, iPtrPage, pgnoMove); @@ -5459,11 +5468,11 @@ } rc = getPage(pBt, pgnoRoot, &pRoot, 0); if( rc!=SQLITE_OK ){ return rc; } - rc = sqlite3pager_write(pRoot->aData); + rc = sqlite3PagerWrite(pRoot->pDbPage); if( rc!=SQLITE_OK ){ releasePage(pRoot); return rc; } }else{ @@ -5485,13 +5494,13 @@ }else{ rc = allocatePage(pBt, &pRoot, &pgnoRoot, 1, 0); if( rc ) return rc; } #endif - assert( sqlite3pager_iswriteable(pRoot->aData) ); + assert( sqlite3PagerIswriteable(pRoot->pDbPage) ); zeroPage(pRoot, flags | PTF_LEAF); - sqlite3pager_unref(pRoot->aData); + sqlite3PagerUnref(pRoot->pDbPage); *piTable = (int)pgnoRoot; return SQLITE_OK; } /* @@ -5507,11 +5516,11 @@ MemPage *pPage = 0; int rc; unsigned char *pCell; int i; - if( pgno>sqlite3pager_pagecount(pBt->pPager) ){ + if( pgno>sqlite3PagerPagecount(pBt->pPager) ){ return SQLITE_CORRUPT_BKPT; } rc = getAndInitPage(pBt, pgno, &pPage, pParent); if( rc ) goto cleardatabasepage_out; @@ -5528,11 +5537,11 @@ rc = clearDatabasePage(pBt, get4byte(&pPage->aData[8]), pPage->pParent, 1); if( rc ) goto cleardatabasepage_out; } if( freePageFlag ){ rc = freePage(pPage); - }else if( (rc = sqlite3pager_write(pPage->aData))==0 ){ + }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){ zeroPage(pPage, pPage->aData[0] | PTF_LEAF); } cleardatabasepage_out: releasePage(pPage); @@ -5704,10 +5713,11 @@ ** The schema layer numbers meta values differently. At the schema ** layer (and the SetCookie and ReadCookie opcodes) the number of ** free pages is not visible. So Cookie[0] is the same as Meta[1]. */ int sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){ + DbPage *pDbPage; int rc; unsigned char *pP1; BtShared *pBt = p->pBt; /* Reading a meta-data value requires a read-lock on page 1 (and hence @@ -5719,14 +5729,15 @@ if( rc!=SQLITE_OK ){ return rc; } assert( idx>=0 && idx<=15 ); - rc = sqlite3pager_get(pBt->pPager, 1, (void**)&pP1); + rc = sqlite3PagerGet(pBt->pPager, 1, &pDbPage); if( rc ) return rc; + pP1 = (unsigned char *)sqlite3PagerGetData(pDbPage); *pMeta = get4byte(&pP1[36 + idx*4]); - sqlite3pager_unref(pP1); + sqlite3PagerUnref(pDbPage); /* If autovacuumed is disabled in this build but we are trying to ** access an autovacuumed database, then make the database readonly. */ #ifdef SQLITE_OMIT_AUTOVACUUM @@ -5750,11 +5761,11 @@ if( p->inTrans!=TRANS_WRITE ){ return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR; } assert( pBt->pPage1!=0 ); pP1 = pBt->pPage1->aData; - rc = sqlite3pager_write(pP1); + rc = sqlite3PagerWrite(pBt->pPage1->pDbPage); if( rc ) return rc; put4byte(&pP1[36 + idx*4], iMeta); return SQLITE_OK; } @@ -5865,11 +5876,11 @@ idx = get2byte(pCell); } btreePageDump(pBt, get4byte(&data[hdr+8]), 1, pPage); } pPage->isInit = isInit; - sqlite3pager_unref(data); + sqlite3PagerUnref(pPage->pDbPage); fflush(stdout); return SQLITE_OK; } int sqlite3BtreePageDump(Btree *p, int pgno, int recursive){ return btreePageDump(p->pBt, pgno, recursive, 0); @@ -5909,11 +5920,11 @@ getTempCursor(pCur, &tmpCur); while( upCnt-- ){ moveToParent(&tmpCur); } pPage = tmpCur.pPage; - aResult[0] = sqlite3pager_pagenumber(pPage->aData); + aResult[0] = sqlite3PagerPagenumber(pPage->pDbPage); assert( aResult[0]==pPage->pgno ); aResult[1] = tmpCur.idx; aResult[2] = pPage->nCell; if( tmpCur.idx>=0 && tmpCur.idxnCell ){ getCellInfo(&tmpCur); @@ -6070,24 +6081,26 @@ ){ int i; int expected = N; int iFirst = iPage; while( N-- > 0 && pCheck->mxErr ){ - unsigned char *pOvfl; + DbPage *pOvflPage; + unsigned char *pOvflData; if( iPage<1 ){ checkAppendMsg(pCheck, zContext, "%d of %d pages missing from overflow list starting at %d", N+1, expected, iFirst); break; } if( checkRef(pCheck, iPage, zContext) ) break; - if( sqlite3pager_get(pCheck->pPager, (Pgno)iPage, (void**)&pOvfl) ){ + if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage) ){ checkAppendMsg(pCheck, zContext, "failed to get page %d", iPage); break; } + pOvflData = (unsigned char *)sqlite3PagerGetData(pOvflPage); if( isFreeList ){ - int n = get4byte(&pOvfl[4]); + int n = get4byte(&pOvflData[4]); #ifndef SQLITE_OMIT_AUTOVACUUM if( pCheck->pBt->autoVacuum ){ checkPtrmap(pCheck, iPage, PTRMAP_FREEPAGE, 0, zContext); } #endif @@ -6095,11 +6108,11 @@ checkAppendMsg(pCheck, zContext, "freelist leaf count too big on page %d", iPage); N--; }else{ for(i=0; ipBt->autoVacuum ){ checkPtrmap(pCheck, iFreePage, PTRMAP_FREEPAGE, 0, zContext); } #endif @@ -6113,17 +6126,17 @@ /* If this database supports auto-vacuum and iPage is not the last ** page in this overflow list, check that the pointer-map entry for ** the following page matches iPage. */ if( pCheck->pBt->autoVacuum && N>0 ){ - i = get4byte(pOvfl); + i = get4byte(pOvflData); checkPtrmap(pCheck, i, PTRMAP_OVERFLOW2, iPage, zContext); } } #endif - iPage = get4byte(pOvfl); - sqlite3pager_unref(pOvfl); + iPage = get4byte(pOvflData); + sqlite3PagerUnref(pOvflPage); } } #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ #ifndef SQLITE_OMIT_INTEGRITY_CHECK @@ -6309,17 +6322,17 @@ int i; int nRef; IntegrityCk sCheck; BtShared *pBt = p->pBt; - nRef = sqlite3pager_refcount(pBt->pPager); + nRef = sqlite3PagerRefcount(pBt->pPager); if( lockBtreeWithRetry(p)!=SQLITE_OK ){ return sqliteStrDup("Unable to acquire a read lock on the database"); } sCheck.pBt = pBt; sCheck.pPager = pBt->pPager; - sCheck.nPage = sqlite3pager_pagecount(sCheck.pPager); + sCheck.nPage = sqlite3PagerPagecount(sCheck.pPager); sCheck.mxErr = mxErr; sCheck.nErr = 0; *pnErr = 0; if( sCheck.nPage==0 ){ unlockBtreeIfUnused(pBt); @@ -6379,14 +6392,14 @@ } /* Make sure this analysis did not leave any unref() pages */ unlockBtreeIfUnused(pBt); - if( nRef != sqlite3pager_refcount(pBt->pPager) ){ + if( nRef != sqlite3PagerRefcount(pBt->pPager) ){ checkAppendMsg(&sCheck, 0, "Outstanding page count goes from %d to %d during this analysis", - nRef, sqlite3pager_refcount(pBt->pPager) + nRef, sqlite3PagerRefcount(pBt->pPager) ); } /* Clean up and report errors. */ @@ -6399,29 +6412,29 @@ /* ** Return the full pathname of the underlying database file. */ const char *sqlite3BtreeGetFilename(Btree *p){ assert( p->pBt->pPager!=0 ); - return sqlite3pager_filename(p->pBt->pPager); + return sqlite3PagerFilename(p->pBt->pPager); } /* ** Return the pathname of the directory that contains the database file. */ const char *sqlite3BtreeGetDirname(Btree *p){ assert( p->pBt->pPager!=0 ); - return sqlite3pager_dirname(p->pBt->pPager); + return sqlite3PagerDirname(p->pBt->pPager); } /* ** Return the pathname of the journal file for this database. The return ** value of this routine is the same regardless of whether the journal file ** has been created or not. */ const char *sqlite3BtreeGetJournalname(Btree *p){ assert( p->pBt->pPager!=0 ); - return sqlite3pager_journalname(p->pBt->pPager); + return sqlite3PagerJournalname(p->pBt->pPager); } #ifndef SQLITE_OMIT_VACUUM /* ** Copy the complete content of pBtFrom into pBtTo. A transaction @@ -6439,32 +6452,32 @@ if( pTo->inTrans!=TRANS_WRITE || pFrom->inTrans!=TRANS_WRITE ){ return SQLITE_ERROR; } if( pBtTo->pCursor ) return SQLITE_BUSY; - nToPage = sqlite3pager_pagecount(pBtTo->pPager); - nPage = sqlite3pager_pagecount(pBtFrom->pPager); + nToPage = sqlite3PagerPagecount(pBtTo->pPager); + nPage = sqlite3PagerPagecount(pBtFrom->pPager); iSkip = PENDING_BYTE_PAGE(pBtTo); for(i=1; rc==SQLITE_OK && i<=nPage; i++){ - void *pPage; + DbPage *pDbPage; if( i==iSkip ) continue; - rc = sqlite3pager_get(pBtFrom->pPager, i, &pPage); + rc = sqlite3PagerGet(pBtFrom->pPager, i, &pDbPage); if( rc ) break; - rc = sqlite3pager_overwrite(pBtTo->pPager, i, pPage); - sqlite3pager_unref(pPage); + rc = sqlite3PagerOverwrite(pBtTo->pPager, i, sqlite3PagerGetData(pDbPage)); + sqlite3PagerUnref(pDbPage); } for(i=nPage+1; rc==SQLITE_OK && i<=nToPage; i++){ - void *pPage; + DbPage *pDbPage; if( i==iSkip ) continue; - rc = sqlite3pager_get(pBtTo->pPager, i, &pPage); + rc = sqlite3PagerGet(pBtTo->pPager, i, &pDbPage); if( rc ) break; - rc = sqlite3pager_write(pPage); - sqlite3pager_unref(pPage); - sqlite3pager_dont_write(pBtTo->pPager, i); + rc = sqlite3PagerWrite(pDbPage); + sqlite3PagerUnref(pDbPage); + sqlite3PagerDontWrite(pBtTo->pPager, i); } if( !rc && nPagepPager, nPage); + rc = sqlite3PagerTruncate(pBtTo->pPager, nPage); } if( rc ){ sqlite3BtreeRollback(pTo); } return rc; @@ -6517,11 +6530,11 @@ if( rc!=SQLITE_OK ){ return rc; } } #endif - rc = sqlite3pager_sync(pBt->pPager, zMaster, nTrunc); + rc = sqlite3PagerSync(pBt->pPager, zMaster, nTrunc); } return rc; } /* @@ -6592,15 +6605,15 @@ const ThreadData *pTd = sqlite3ThreadDataReadOnly(); if( pTd->useSharedData ){ BtShared *pBt; Tcl_Obj *pRet = Tcl_NewObj(); for(pBt=pTd->pBtree; pBt; pBt=pBt->pNext){ - const char *zFile = sqlite3pager_filename(pBt->pPager); + const char *zFile = sqlite3PagerFilename(pBt->pPager); Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(zFile, -1)); Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(pBt->nRef)); } Tcl_SetObjResult(interp, pRet); } #endif return TCL_OK; } #endif Index: src/pager.c ================================================================== --- src/pager.c +++ src/pager.c @@ -16,11 +16,11 @@ ** is separate from the database file. The pager also implements file ** locking to prevent two processes from writing the same database ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.291 2007/03/19 13:53:38 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.292 2007/03/19 17:44:27 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" #include "os.h" #include "pager.h" @@ -88,19 +88,19 @@ ** disk. All that remains to do is to remove the ** journal file and the transaction will be ** committed. ** ** The page cache comes up in PAGER_UNLOCK. The first time a -** sqlite3pager_get() occurs, the state transitions to PAGER_SHARED. +** sqlite3PagerGet() occurs, the state transitions to PAGER_SHARED. ** After all pages have been released using sqlite_page_unref(), ** the state transitions back to PAGER_UNLOCK. The first time -** that sqlite3pager_write() is called, the state transitions to +** that sqlite3PagerWrite() is called, the state transitions to ** PAGER_RESERVED. (Note that sqlite_page_write() can only be ** called on an outstanding page which means that the pager must ** be in PAGER_SHARED before it transitions to PAGER_RESERVED.) ** The transition to PAGER_EXCLUSIVE occurs when before any changes -** are made to the database file. After an sqlite3pager_rollback() +** are made to the database file. After an sqlite3PagerRollback() ** or sqlite_pager_commit(), the state goes back to PAGER_SHARED. */ #define PAGER_UNLOCK 0 #define PAGER_SHARED 1 /* same as SHARED_LOCK */ #define PAGER_RESERVED 2 /* same as RESERVED_LOCK */ @@ -133,20 +133,20 @@ /* ** Each in-memory image of a page begins with the following header. ** This header is only visible to this pager module. The client ** code that calls pager sees only the data that follows the header. ** -** Client code should call sqlite3pager_write() on a page prior to making -** any modifications to that page. The first time sqlite3pager_write() +** Client code should call sqlite3PagerWrite() on a page prior to making +** any modifications to that page. The first time sqlite3PagerWrite() ** is called, the original page contents are written into the rollback ** journal and PgHdr.inJournal and PgHdr.needSync are set. Later, once ** the journal page has made it onto the disk surface, PgHdr.needSync ** is cleared. The modified page cannot be written back into the original ** database file until the journal pages has been synced to disk and the ** PgHdr.needSync has been cleared. ** -** The PgHdr.dirty flag is set when sqlite3pager_write() is called and +** The PgHdr.dirty flag is set when sqlite3PagerWrite() is called and ** is cleared again when the page content is written back to the original ** database file. */ typedef struct PgHdr PgHdr; struct PgHdr { @@ -215,11 +215,11 @@ ** Pager.errCode may be set to SQLITE_IOERR, SQLITE_CORRUPT, SQLITE_PROTOCOL ** or SQLITE_FULL. Once one of the first three errors occurs, it persists ** and is returned as the result of every major pager API call. The ** SQLITE_FULL return code is slightly different. It persists only until the ** next successful rollback is performed on the pager cache. Also, -** SQLITE_FULL does not affect the sqlite3pager_get() and sqlite3pager_lookup() +** SQLITE_FULL does not affect the sqlite3PagerGet() and sqlite3PagerLookup() ** APIs, they may still be used successfully. */ struct Pager { u8 journalOpen; /* True if journal file descriptors is valid */ u8 journalStarted; /* True if header of journal is synced */ @@ -273,12 +273,12 @@ int sectorSize; /* Assumed sector size during rollback */ #ifdef SQLITE_TEST int nHit, nMiss, nOvfl; /* Cache hits, missing, and LRU overflows */ int nRead,nWrite; /* Database pages read/written */ #endif - void (*xDestructor)(void*,int); /* Call this routine when freeing pages */ - void (*xReiniter)(void*,int); /* Call this routine when reloading pages */ + void (*xDestructor)(DbPage*,int); /* Call this routine when freeing pages */ + void (*xReiniter)(DbPage*,int); /* Call this routine when reloading pages */ void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */ void *pCodecArg; /* First argument to xCodec() */ int nHash; /* Size of the pager hash table */ PgHdr **aHash; /* Hash table to map page number to PgHdr */ #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT @@ -799,11 +799,11 @@ /* ** Add or remove a page from the list of all pages that are in the ** statement journal. ** ** The Pager keeps a separate list of pages that are currently in -** the statement journal. This helps the sqlite3pager_stmt_commit() +** the statement journal. This helps the sqlite3PagerStmtCommit() ** routine run MUCH faster for the common case where there are many ** pages in memory but only a few are in the statement journal. */ static void page_add_to_stmt_list(PgHdr *pPg){ Pager *pPager = pPg->pPager; @@ -888,11 +888,11 @@ pPager->nHash = 0; sqliteFree(pPager->aHash); pPager->nPage = 0; pPager->aHash = 0; if( pPager->state>=PAGER_RESERVED ){ - sqlite3pager_rollback(pPager); + sqlite3PagerRollback(pPager); } pager_unlock(pPager); pPager->nRef = 0; assert( pPager->errCode || (pPager->journalOpen==0 && pPager->stmtOpen==0) ); } @@ -912,11 +912,11 @@ int rc; assert( !MEMDB ); if( pPager->statestmtOpen ){ sqlite3OsClose(&pPager->stfd); pPager->stmtOpen = 0; } if( pPager->journalOpen ){ @@ -1067,18 +1067,18 @@ if( pPg ){ /* No page should ever be explicitly rolled back that is in use, except ** for page 1 which is held in use in order to keep the lock on the ** database active. However such a page may be rolled back as a result ** of an internal error resulting in an automatic call to - ** sqlite3pager_rollback(). + ** sqlite3PagerRollback(). */ void *pData; /* assert( pPg->nRef==0 || pPg->pgno==1 ); */ pData = PGHDR_TO_DATA(pPg); memcpy(pData, aData, pPager->pageSize); if( pPager->xDestructor ){ /*** FIX ME: Should this be xReinit? ***/ - pPager->xDestructor(pData, pPager->pageSize); + pPager->xDestructor(pPg, pPager->pageSize); } #ifdef SQLITE_CHECK_PAGES pPg->pageHash = pager_pagehash(pPg); #endif CODEC1(pPager, pData, pPg->pgno, 3); @@ -1199,11 +1199,11 @@ memset(zBuf, 0, pPager->pageSize); } if( pPg->nRef==0 || memcmp(zBuf, PGHDR_TO_DATA(pPg), pPager->pageSize) ){ memcpy(PGHDR_TO_DATA(pPg), zBuf, pPager->pageSize); if( pPager->xReiniter ){ - pPager->xReiniter(PGHDR_TO_DATA(pPg), pPager->pageSize); + pPager->xReiniter(pPg, pPager->pageSize); }else{ memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra); } } pPg->needSync = 0; @@ -1511,11 +1511,11 @@ } /* ** Change the maximum number of in-memory pages that are allowed. */ -void sqlite3pager_set_cachesize(Pager *pPager, int mxPage){ +void sqlite3PagerSetCachesize(Pager *pPager, int mxPage){ if( mxPage>10 ){ pPager->mxPage = mxPage; }else{ pPager->mxPage = 10; } @@ -1546,11 +1546,11 @@ ** ** Numeric values associated with these states are OFF==1, NORMAL=2, ** and FULL=3. */ #ifndef SQLITE_OMIT_PAGER_PRAGMAS -void sqlite3pager_set_safety_level(Pager *pPager, int level, int full_fsync){ +void sqlite3PagerSetSafetyLevel(Pager *pPager, int level, int full_fsync){ pPager->noSync = level==1 || pPager->tempFile; pPager->fullSync = level==3 && !pPager->tempFile; pPager->full_fsync = full_fsync; if( pPager->noSync ) pPager->needSync = 0; } @@ -1572,11 +1572,11 @@ ** other error code if we fail. ** ** The OS will automatically delete the temporary file when it is ** closed. */ -static int sqlite3pager_opentemp(OsFile **pFd){ +static int sqlite3PagerOpentemp(OsFile **pFd){ int cnt = 8; int rc; char zFile[SQLITE_TEMPNAME_SIZE]; #ifdef SQLITE_TEST @@ -1591,22 +1591,22 @@ } /* ** Create a new page cache and put a pointer to the page cache in *ppPager. ** The file to be cached need not exist. The file is not locked until -** the first call to sqlite3pager_get() and is only held open until the -** last page is released using sqlite3pager_unref(). +** the first call to sqlite3PagerGet() and is only held open until the +** last page is released using sqlite3PagerUnref(). ** ** If zFilename is NULL then a randomly-named temporary file is created ** and used as the file to be cached. The file will be deleted ** automatically when it is closed. ** ** If zFilename is ":memory:" then all information is held in cache. ** It is never written to disk. This can be used to implement an ** in-memory database. */ -int sqlite3pager_open( +int sqlite3PagerOpen( Pager **ppPager, /* Return the Pager structure here */ const char *zFilename, /* Name of the database file to open */ int nExtra, /* Extra bytes append to each in-memory page */ int flags /* flags controlling this file */ ){ @@ -1659,11 +1659,11 @@ if( zFullPathname ){ rc = sqlite3OsOpenReadWrite(zFullPathname, &fd, &readOnly); } } }else{ - rc = sqlite3pager_opentemp(&fd); + rc = sqlite3PagerOpentemp(&fd); sqlite3OsTempFileName(zTemp); zFilename = zTemp; zFullPathname = sqlite3OsFullPathname(zFilename); if( rc==SQLITE_OK ){ tempFile = 1; @@ -1750,23 +1750,23 @@ } /* ** Set the busy handler function. */ -void sqlite3pager_set_busyhandler(Pager *pPager, BusyHandler *pBusyHandler){ +void sqlite3PagerSetBusyhandler(Pager *pPager, BusyHandler *pBusyHandler){ pPager->pBusyHandler = pBusyHandler; } /* ** Set the destructor for this pager. If not NULL, the destructor is called ** when the reference count on each page reaches zero. The destructor can ** be used to clean up information in the extra segment appended to each page. ** -** The destructor is not called as a result sqlite3pager_close(). -** Destructors are only called by sqlite3pager_unref(). +** The destructor is not called as a result sqlite3PagerClose(). +** Destructors are only called by sqlite3PagerUnref(). */ -void sqlite3pager_set_destructor(Pager *pPager, void (*xDesc)(void*,int)){ +void sqlite3PagerSetDestructor(Pager *pPager, void (*xDesc)(DbPage*,int)){ pPager->xDestructor = xDesc; } /* ** Set the reinitializer for this pager. If not NULL, the reinitializer @@ -1773,20 +1773,20 @@ ** is called when the content of a page in cache is restored to its original ** value as a result of a rollback. The callback gives higher-level code ** an opportunity to restore the EXTRA section to agree with the restored ** page data. */ -void sqlite3pager_set_reiniter(Pager *pPager, void (*xReinit)(void*,int)){ +void sqlite3PagerSetReiniter(Pager *pPager, void (*xReinit)(DbPage*,int)){ pPager->xReiniter = xReinit; } /* ** Set the page size. Return the new size. If the suggest new page ** size is inappropriate, then an alternative page size is selected ** and returned. */ -int sqlite3pager_set_pagesize(Pager *pPager, int pageSize){ +int sqlite3PagerSetPagesize(Pager *pPager, int pageSize){ assert( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE ); if( !pPager->memDb ){ pPager->pageSize = pageSize; sqlite3ReallocOrFree((void **)&pPager->pTmpSpace, pageSize); } @@ -1829,11 +1829,11 @@ ** may be called even if the file does not exist or contain a header. In ** these cases sqlite3OsRead() will return an error, to which the correct ** response is to zero the memory at pDest and continue. A real IO error ** will presumably recur and be picked up later (Todo: Think about this). */ -int sqlite3pager_read_fileheader(Pager *pPager, int N, unsigned char *pDest){ +int sqlite3PagerReadFileheader(Pager *pPager, int N, unsigned char *pDest){ int rc = SQLITE_OK; memset(pDest, 0, N); if( MEMDB==0 ){ disable_simulated_io_errors(); sqlite3OsSeek(pPager->fd, 0); @@ -1854,11 +1854,11 @@ ** If the PENDING_BYTE lies on the page directly after the end of the ** file, then consider this page part of the file too. For example, if ** PENDING_BYTE is byte 4096 (the first byte of page 5) and the size of the ** file is 4096 bytes, 5 is returned instead of 4. */ -int sqlite3pager_pagecount(Pager *pPager){ +int sqlite3PagerPagecount(Pager *pPager){ i64 n; int rc; assert( pPager!=0 ); if( pPager->errCode ){ return 0; @@ -1906,11 +1906,11 @@ static int syncJournal(Pager*); /* ** Unlink pPg from it's hash chain. Also set the page number to 0 to indicate ** that the page is not part of any hash chain. This is required because the -** sqlite3pager_movepage() routine can leave a page in the +** sqlite3PagerMovepage() routine can leave a page in the ** pNextFree/pPrevFree list that is not a part of any hash-chain. */ static void unlinkHashChain(Pager *pPager, PgHdr *pPg){ if( pPg->pgno==0 ){ assert( pPg->pNextHash==0 && pPg->pPrevHash==0 ); @@ -2031,14 +2031,14 @@ } /* ** Truncate the file to the number of pages specified. */ -int sqlite3pager_truncate(Pager *pPager, Pgno nPage){ +int sqlite3PagerTruncate(Pager *pPager, Pgno nPage){ int rc; assert( pPager->state>=PAGER_SHARED || MEMDB ); - sqlite3pager_pagecount(pPager); + sqlite3PagerPagecount(pPager); if( pPager->errCode ){ rc = pPager->errCode; return rc; } if( nPage>=(unsigned)pPager->dbSize ){ @@ -2079,11 +2079,11 @@ ** This function always succeeds. If a transaction is active an attempt ** is made to roll it back. If an error occurs during the rollback ** a hot journal may be left in the filesystem but no error is returned ** to the caller. */ -int sqlite3pager_close(Pager *pPager){ +int sqlite3PagerClose(Pager *pPager){ #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT /* A malloc() cannot fail in sqlite3ThreadData() as one or more calls to ** malloc() must have already been made by this thread before it gets ** to this point. This means the ThreadData must have been allocated already ** so that ThreadData.nAlloc can be set. @@ -2133,12 +2133,11 @@ } /* ** Return the page number for the given page data. */ -Pgno sqlite3pager_pagenumber(void *pData){ - PgHdr *p = DATA_TO_PGHDR(pData); +Pgno sqlite3PagerPagenumber(DbPage *p){ return p->pgno; } /* ** The page_ref() function increments the reference count for a page. @@ -2187,12 +2186,11 @@ /* ** Increment the reference count for a page. The input pointer is ** a reference to the page data. */ -int sqlite3pager_ref(void *pData){ - PgHdr *pPg = DATA_TO_PGHDR(pData); +int sqlite3PagerRef(DbPage *pPg){ page_ref(pPg); return SQLITE_OK; } /* @@ -2392,11 +2390,11 @@ while( pList ){ assert( pList->dirty ); rc = sqlite3OsSeek(pPager->fd, (pList->pgno-1)*(i64)pPager->pageSize); if( rc ) return rc; /* If there are dirty pages in the page cache with page numbers greater - ** than Pager.dbSize, this means sqlite3pager_truncate() was called to + ** than Pager.dbSize, this means sqlite3PagerTruncate() was called to ** make the file smaller (presumably by auto-vacuum code). Do not write ** any such pages to the file. */ if( pList->pgno<=pPager->dbSize ){ char *pData = CODEC2(pPager, PGHDR_TO_DATA(pList), pList->pgno, 6); @@ -2439,11 +2437,11 @@ */ static int hasHotJournal(Pager *pPager){ if( !pPager->useJournal ) return 0; if( !sqlite3OsFileExists(pPager->zJournal) ) return 0; if( sqlite3OsCheckReservedLock(pPager->fd) ) return 0; - if( sqlite3pager_pagecount(pPager)==0 ){ + if( sqlite3PagerPagecount(pPager)==0 ){ sqlite3OsDelete(pPager->zJournal); return 0; }else{ return 1; } @@ -2543,11 +2541,11 @@ ** been released, the function returns. A negative value for nReq means ** free as much memory as possible. The return value is the total number ** of bytes of memory released. */ #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT -int sqlite3pager_release_memory(int nReq){ +int sqlite3PagerReleaseMemory(int nReq){ const ThreadData *pTsdro = sqlite3ThreadDataReadOnly(); Pager *p; int nReleased = 0; int i; @@ -2630,11 +2628,11 @@ ** to zeros the first time a page is loaded into memory. ** ** The acquisition might fail for several reasons. In all cases, ** an appropriate error code is returned and *ppPage is set to NULL. ** -** See also sqlite3pager_lookup(). Both this routine and _lookup() attempt +** See also sqlite3PagerLookup(). Both this routine and _lookup() attempt ** to find a page in the in-memory cache first. If the page is not already ** in memory, this routine goes to disk to read it in whereas _lookup() ** just returns 0. This routine acquires a read-lock the first time it ** has to go to disk, and could also playback an old journal if necessary. ** Since _lookup() never goes to disk, it never has to deal with locks @@ -2643,11 +2641,11 @@ ** If clrFlag is false, the page contents are actually read from disk. ** If clfFlag is true, it means the page is about to be erased and ** rewritten without first being read so there is no point it doing ** the disk I/O. */ -int sqlite3pager_acquire(Pager *pPager, Pgno pgno, void **ppPage, int clrFlag){ +int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag){ PgHdr *pPg; int rc; /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page ** number greater than this, or zero, is requested. @@ -2795,19 +2793,19 @@ pPager->nRef++; if( pPager->nExtra>0 ){ memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra); } if( pPager->errCode ){ - sqlite3pager_unref(PGHDR_TO_DATA(pPg)); + sqlite3PagerUnref(pPg); rc = pPager->errCode; return rc; } /* Populate the page with data, either by reading from the database ** file, or by setting the entire page to zero. */ - if( sqlite3pager_pagecount(pPager)<(int)pgno || MEMDB + if( sqlite3PagerPagecount(pPager)<(int)pgno || MEMDB || (clrFlag && !pPager->alwaysRollback) ){ memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize); }else{ assert( MEMDB==0 ); @@ -2819,11 +2817,11 @@ IOTRACE(("PGIN %p %d\n", pPager, pgno)) TRACE3("FETCH %d page %d\n", PAGERID(pPager), pPg->pgno); CODEC1(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3); if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){ pPg->pgno = 0; - sqlite3pager_unref(PGHDR_TO_DATA(pPg)); + sqlite3PagerUnref(pPg); return rc; }else{ TEST_INCR(pPager->nRead); } } @@ -2844,26 +2842,26 @@ }else{ /* The requested page is in the page cache. */ TEST_INCR(pPager->nHit); page_ref(pPg); } - *ppPage = PGHDR_TO_DATA(pPg); + *ppPage = pPg; return SQLITE_OK; } /* ** Acquire a page if it is already in the in-memory cache. Do ** not read the page from disk. Return a pointer to the page, ** or 0 if the page is not in cache. ** -** See also sqlite3pager_get(). The difference between this routine -** and sqlite3pager_get() is that _get() will go to the disk and read +** See also sqlite3PagerGet(). The difference between this routine +** and sqlite3PagerGet() is that _get() will go to the disk and read ** in the page if the page is not already in cache. This routine ** returns NULL if the page is not in cache or if a disk I/O error ** has ever happened. */ -void *sqlite3pager_lookup(Pager *pPager, Pgno pgno){ +DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno){ PgHdr *pPg; assert( pPager!=0 ); assert( pgno!=0 ); if( pPager->errCode && pPager->errCode!=SQLITE_FULL ){ @@ -2870,11 +2868,11 @@ return 0; } pPg = pager_lookup(pPager, pgno); if( pPg==0 ) return 0; page_ref(pPg); - return PGHDR_TO_DATA(pPg); + return pPg; } /* ** Release a page. ** @@ -2881,16 +2879,14 @@ ** If the number of references to the page drop to zero, then the ** page is added to the LRU list. When all references to all pages ** are released, a rollback occurs and the lock on the database is ** removed. */ -int sqlite3pager_unref(void *pData){ - PgHdr *pPg; +int sqlite3PagerUnref(DbPage *pPg){ /* Decrement the reference count for this page */ - pPg = DATA_TO_PGHDR(pData); assert( pPg->nRef>0 ); pPg->nRef--; REFINFO(pPg); CHECK_PAGE(pPg); @@ -2911,11 +2907,11 @@ } if( pPg->needSync==0 && pPager->pFirstSynced==0 ){ pPager->pFirstSynced = pPg; } if( pPager->xDestructor ){ - pPager->xDestructor(pData, pPager->pageSize); + pPager->xDestructor(pPg, pPager->pageSize); } /* When all pages reach the freelist, drop the read lock from ** the database file. */ @@ -2940,11 +2936,11 @@ assert( !MEMDB ); assert( pPager->state>=PAGER_RESERVED ); assert( pPager->journalOpen==0 ); assert( pPager->useJournal ); assert( pPager->aInJournal==0 ); - sqlite3pager_pagecount(pPager); + sqlite3PagerPagecount(pPager); pPager->aInJournal = sqliteMalloc( pPager->dbSize/8 + 1 ); if( pPager->aInJournal==0 ){ rc = SQLITE_NOMEM; goto failed_to_open_journal; } @@ -2971,11 +2967,11 @@ pPager->origDbSize = pPager->dbSize; rc = writeJournalHdr(pPager); if( pPager->stmtAutoopen && rc==SQLITE_OK ){ - rc = sqlite3pager_stmt_begin(pPager); + rc = sqlite3PagerStmtBegin(pPager); } if( rc!=SQLITE_OK && rc!=SQLITE_NOMEM ){ rc = pager_unwritelock(pPager); if( rc==SQLITE_OK ){ rc = SQLITE_FULL; @@ -3001,14 +2997,14 @@ /* ** Acquire a write-lock on the database. The lock is removed when ** the any of the following happen: ** -** * sqlite3pager_commit() is called. -** * sqlite3pager_rollback() is called. -** * sqlite3pager_close() is called. -** * sqlite3pager_unref() is called to on every outstanding page. +** * sqlite3PagerCommit() is called. +** * sqlite3PagerRollback() is called. +** * sqlite3PagerClose() is called. +** * sqlite3PagerUnref() is called to on every outstanding page. ** ** The first parameter to this routine is a pointer to any open page of the ** database file. Nothing changes about the page - it is used merely to ** acquire a pointer to the Pager structure and as proof that there is ** already a read-lock on the database. @@ -3024,12 +3020,11 @@ ** ** If exFlag is true, go ahead and get an EXCLUSIVE lock on the file ** immediately instead of waiting until we try to flush the cache. The ** exFlag is ignored if a transaction is already active. */ -int sqlite3pager_begin(void *pData, int exFlag){ - PgHdr *pPg = DATA_TO_PGHDR(pData); +int sqlite3PagerBegin(DbPage *pPg, int exFlag){ Pager *pPager = pPg->pPager; int rc = SQLITE_OK; assert( pPg->nRef>0 ); assert( pPager->state!=PAGER_UNLOCK ); if( pPager->state==PAGER_SHARED ){ @@ -3106,15 +3101,15 @@ ** change any page data until this routine returns SQLITE_OK. ** ** If the journal file could not be written because the disk is full, ** then this routine returns SQLITE_FULL and does an immediate rollback. ** All subsequent write attempts also return SQLITE_FULL until there -** is a call to sqlite3pager_commit() or sqlite3pager_rollback() to +** is a call to sqlite3PagerCommit() or sqlite3PagerRollback() to ** reset. */ -static int pager_write(void *pData){ - PgHdr *pPg = DATA_TO_PGHDR(pData); +static int pager_write(PgHdr *pPg){ + void *pData = PGHDR_TO_DATA(pPg); Pager *pPager = pPg->pPager; int rc = SQLITE_OK; /* Check for errors */ @@ -3143,11 +3138,11 @@ ** ** First check to see that the transaction journal exists and ** create it if it does not. */ assert( pPager->state!=PAGER_UNLOCK ); - rc = sqlite3pager_begin(pData, 0); + rc = sqlite3PagerBegin(pPg, 0); if( rc!=SQLITE_OK ){ return rc; } assert( pPager->state>=PAGER_RESERVED ); if( !pPager->journalOpen && pPager->useJournal ){ @@ -3273,14 +3268,14 @@ ** The difference between this function and pager_write() is that this ** function also deals with the special case where 2 or more pages ** fit on a single disk sector. In this case all co-resident pages ** must have been written to the journal file before returning. */ -int sqlite3pager_write(void *pData){ +int sqlite3PagerWrite(DbPage *pDbPage){ int rc = SQLITE_OK; - PgHdr *pPg = DATA_TO_PGHDR(pData); + PgHdr *pPg = pDbPage; Pager *pPager = pPg->pPager; Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize); if( !MEMDB && nPagePerSector>1 ){ Pgno nPageCount; /* Total number of pages in database file */ @@ -3298,11 +3293,11 @@ ** an integer power of 2. It sets variable pg1 to the identifier ** of the first page of the sector pPg is located on. */ pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1; - nPageCount = sqlite3pager_pagecount(pPager); + nPageCount = sqlite3PagerPagecount(pPager); if( pPg->pgno>nPageCount ){ nPage = (pPg->pgno - pg1)+1; }else if( (pg1+nPagePerSector-1)>nPageCount ){ nPage = nPageCount+1-pg1; }else{ @@ -3316,56 +3311,55 @@ Pgno pg = pg1+ii; if( !pPager->aInJournal || pg==pPg->pgno || pg>pPager->origDbSize || !(pPager->aInJournal[pg/8]&(1<<(pg&7))) ) { if( pg!=PAGER_MJ_PGNO(pPager) ){ - void *pPage; - rc = sqlite3pager_get(pPager, pg, &pPage); + PgHdr *pPage; + rc = sqlite3PagerGet(pPager, pg, &pPage); if( rc==SQLITE_OK ){ rc = pager_write(pPage); - sqlite3pager_unref(pPage); + sqlite3PagerUnref(pPage); } } } } assert( pPager->doNotSync==1 ); pPager->doNotSync = 0; }else{ - rc = pager_write(pData); + rc = pager_write(pDbPage); } return rc; } /* ** Return TRUE if the page given in the argument was previously passed -** to sqlite3pager_write(). In other words, return TRUE if it is ok +** to sqlite3PagerWrite(). In other words, return TRUE if it is ok ** to change the content of the page. */ #ifndef NDEBUG -int sqlite3pager_iswriteable(void *pData){ - PgHdr *pPg = DATA_TO_PGHDR(pData); +int sqlite3PagerIswriteable(DbPage *pPg){ return pPg->dirty; } #endif #ifndef SQLITE_OMIT_VACUUM /* ** Replace the content of a single page with the information in the third ** argument. */ -int sqlite3pager_overwrite(Pager *pPager, Pgno pgno, void *pData){ - void *pPage; +int sqlite3PagerOverwrite(Pager *pPager, Pgno pgno, void *pData){ + PgHdr *pPg; int rc; - rc = sqlite3pager_get(pPager, pgno, &pPage); + rc = sqlite3PagerGet(pPager, pgno, &pPg); if( rc==SQLITE_OK ){ - rc = sqlite3pager_write(pPage); + rc = sqlite3PagerWrite(pPg); if( rc==SQLITE_OK ){ - memcpy(pPage, pData, pPager->pageSize); + memcpy(sqlite3PagerGetData(pPg), pData, pPager->pageSize); } - sqlite3pager_unref(pPage); + sqlite3PagerUnref(pPg); } return rc; } #endif @@ -3377,25 +3371,25 @@ ** The overlying software layer calls this routine when all of the data ** on the given page is unused. The pager marks the page as clean so ** that it does not get written to disk. ** ** Tests show that this optimization, together with the -** sqlite3pager_dont_rollback() below, more than double the speed +** sqlite3PagerDontRollback() below, more than double the speed ** of large INSERT operations and quadruple the speed of large DELETEs. ** ** When this routine is called, set the alwaysRollback flag to true. -** Subsequent calls to sqlite3pager_dont_rollback() for the same page +** Subsequent calls to sqlite3PagerDontRollback() for the same page ** will thereafter be ignored. This is necessary to avoid a problem ** where a page with data is added to the freelist during one part of ** a transaction then removed from the freelist during a later part ** of the same transaction and reused for some other purpose. When it ** is first added to the freelist, this routine is called. When reused, ** the dont_rollback() routine is called. But because the page contains ** critical data, we still need to be sure it gets rolled back in spite ** of the dont_rollback() call. */ -void sqlite3pager_dont_write(Pager *pPager, Pgno pgno){ +void sqlite3PagerDontWrite(Pager *pPager, Pgno pgno){ PgHdr *pPg; if( MEMDB ) return; pPg = pager_lookup(pPager, pgno); @@ -3427,12 +3421,11 @@ ** A call to this routine tells the pager that if a rollback occurs, ** it is not necessary to restore the data on the given page. This ** means that the pager does not have to record the given page in the ** rollback journal. */ -void sqlite3pager_dont_rollback(void *pData){ - PgHdr *pPg = DATA_TO_PGHDR(pData); +void sqlite3PagerDontRollback(DbPage *pPg){ Pager *pPager = pPg->pPager; assert( pPager->state>=PAGER_RESERVED ); if( pPager->journalOpen==0 ) return; if( pPg->alwaysRollback || pPager->alwaysRollback || MEMDB ) return; @@ -3461,11 +3454,11 @@ ** ** If the commit fails for any reason, a rollback attempt is made ** and an error code is returned. If the commit worked, SQLITE_OK ** is returned. */ -int sqlite3pager_commit(Pager *pPager){ +int sqlite3PagerCommit(Pager *pPager){ int rc; PgHdr *pPg; if( pPager->errCode ){ return pPager->errCode; @@ -3504,11 +3497,11 @@ assert( pPager->needSync==0 ); rc = pager_unwritelock(pPager); return rc; } assert( pPager->journalOpen ); - rc = sqlite3pager_sync(pPager, 0, 0); + rc = sqlite3PagerSync(pPager, 0, 0); if( rc==SQLITE_OK ){ rc = pager_unwritelock(pPager); } return rc; } @@ -3523,11 +3516,11 @@ ** process is writing trash into the journal file (SQLITE_CORRUPT) or ** unless a prior malloc() failed (SQLITE_NOMEM). Appropriate error ** codes are returned for all these occasions. Otherwise, ** SQLITE_OK is returned. */ -int sqlite3pager_rollback(Pager *pPager){ +int sqlite3PagerRollback(Pager *pPager){ int rc; TRACE2("ROLLBACK %d\n", PAGERID(pPager)); if( MEMDB ){ PgHdr *p; for(p=pPager->pAll; p; p=p->pNextAll){ @@ -3550,11 +3543,11 @@ p->dirty = 0; p->inJournal = 0; p->inStmt = 0; p->pPrevStmt = p->pNextStmt = 0; if( pPager->xReiniter ){ - pPager->xReiniter(PGHDR_TO_DATA(p), pPager->pageSize); + pPager->xReiniter(p, pPager->pageSize); } } pPager->pDirty = 0; pPager->pStmt = 0; pPager->dbSize = pPager->origDbSize; @@ -3596,26 +3589,26 @@ /* ** Return TRUE if the database file is opened read-only. Return FALSE ** if the database is (in theory) writable. */ -int sqlite3pager_isreadonly(Pager *pPager){ +int sqlite3PagerIsreadonly(Pager *pPager){ return pPager->readOnly; } /* ** Return the number of references to the pager. */ -int sqlite3pager_refcount(Pager *pPager){ +int sqlite3PagerRefcount(Pager *pPager){ return pPager->nRef; } #ifdef SQLITE_TEST /* ** This routine is used for testing and analysis only. */ -int *sqlite3pager_stats(Pager *pPager){ +int *sqlite3PagerStats(Pager *pPager){ static int a[11]; a[0] = pPager->nRef; a[1] = pPager->nPage; a[2] = pPager->mxPage; a[3] = pPager->dbSize; @@ -3635,11 +3628,11 @@ ** ** This routine should be called with the transaction journal already ** open. A new statement journal is created that can be used to rollback ** changes of a single SQL command within a larger transaction. */ -int sqlite3pager_stmt_begin(Pager *pPager){ +int sqlite3PagerStmtBegin(Pager *pPager){ int rc; assert( !pPager->stmtInUse ); assert( pPager->state>=PAGER_SHARED ); assert( pPager->dbSize>=0 ); TRACE2("STMT-BEGIN %d\n", PAGERID(pPager)); @@ -3666,11 +3659,11 @@ pPager->stmtJSize = pPager->journalOff; pPager->stmtSize = pPager->dbSize; pPager->stmtHdrOff = 0; pPager->stmtCksum = pPager->cksumInit; if( !pPager->stmtOpen ){ - rc = sqlite3pager_opentemp(&pPager->stfd); + rc = sqlite3PagerOpentemp(&pPager->stfd); if( rc ) goto stmt_begin_failed; pPager->stmtOpen = 1; pPager->stmtNRec = 0; } pPager->stmtInUse = 1; @@ -3685,11 +3678,11 @@ } /* ** Commit a statement. */ -int sqlite3pager_stmt_commit(Pager *pPager){ +int sqlite3PagerStmtCommit(Pager *pPager){ if( pPager->stmtInUse ){ PgHdr *pPg, *pNext; TRACE2("STMT-COMMIT %d\n", PAGERID(pPager)); if( !MEMDB ){ sqlite3OsSeek(pPager->stfd, 0); @@ -3717,11 +3710,11 @@ } /* ** Rollback a statement. */ -int sqlite3pager_stmt_rollback(Pager *pPager){ +int sqlite3PagerStmtRollback(Pager *pPager){ int rc; if( pPager->stmtInUse ){ TRACE2("STMT-ROLLBACK %d\n", PAGERID(pPager)); if( MEMDB ){ PgHdr *pPg; @@ -3737,11 +3730,11 @@ memoryTruncate(pPager); rc = SQLITE_OK; }else{ rc = pager_stmt_playback(pPager); } - sqlite3pager_stmt_commit(pPager); + sqlite3PagerStmtCommit(pPager); }else{ rc = SQLITE_OK; } pPager->stmtAutoopen = 0; return rc; @@ -3748,40 +3741,40 @@ } /* ** Return the full pathname of the database file. */ -const char *sqlite3pager_filename(Pager *pPager){ +const char *sqlite3PagerFilename(Pager *pPager){ return pPager->zFilename; } /* ** Return the directory of the database file. */ -const char *sqlite3pager_dirname(Pager *pPager){ +const char *sqlite3PagerDirname(Pager *pPager){ return pPager->zDirectory; } /* ** Return the full pathname of the journal file. */ -const char *sqlite3pager_journalname(Pager *pPager){ +const char *sqlite3PagerJournalname(Pager *pPager){ return pPager->zJournal; } /* ** Return true if fsync() calls are disabled for this pager. Return FALSE ** if fsync()s are executed normally. */ -int sqlite3pager_nosync(Pager *pPager){ +int sqlite3PagerNosync(Pager *pPager){ return pPager->noSync; } /* ** Set the codec for this pager */ -void sqlite3pager_set_codec( +void sqlite3PagerSetCodec( Pager *pPager, void *(*xCodec)(void*,void*,Pgno,int), void *pCodecArg ){ pPager->xCodec = xCodec; @@ -3791,31 +3784,29 @@ /* ** This routine is called to increment the database file change-counter, ** stored at byte 24 of the pager file. */ static int pager_incr_changecounter(Pager *pPager){ - void *pPage; PgHdr *pPgHdr; u32 change_counter; int rc; /* Open page 1 of the file for writing. */ - rc = sqlite3pager_get(pPager, 1, &pPage); + rc = sqlite3PagerGet(pPager, 1, &pPgHdr); if( rc!=SQLITE_OK ) return rc; - rc = sqlite3pager_write(pPage); + rc = sqlite3PagerWrite(pPgHdr); if( rc!=SQLITE_OK ) return rc; /* Read the current value at byte 24. */ - pPgHdr = DATA_TO_PGHDR(pPage); change_counter = retrieve32bits(pPgHdr, 24); /* Increment the value just read and write it back to byte 24. */ change_counter++; put32bits(((char*)PGHDR_TO_DATA(pPgHdr))+24, change_counter); /* Release the page reference. */ - sqlite3pager_unref(pPage); + sqlite3PagerUnref(pPgHdr); return SQLITE_OK; } /* ** Sync the database file for the pager pPager. zMaster points to the name @@ -3827,16 +3818,16 @@ ** to the database file and the database file synced. The only thing that ** remains to commit the transaction is to delete the journal file (or ** master journal file if specified). ** ** Note that if zMaster==NULL, this does not overwrite a previous value -** passed to an sqlite3pager_sync() call. +** passed to an sqlite3PagerSync() call. ** ** If parameter nTrunc is non-zero, then the pager file is truncated to ** nTrunc pages (this is used by auto-vacuum databases). */ -int sqlite3pager_sync(Pager *pPager, const char *zMaster, Pgno nTrunc){ +int sqlite3PagerSync(Pager *pPager, const char *zMaster, Pgno nTrunc){ int rc = SQLITE_OK; TRACE4("DATABASE SYNC: File=%s zMaster=%s nTrunc=%d\n", pPager->zFilename, zMaster, nTrunc); @@ -3861,18 +3852,17 @@ /* If this transaction has made the database smaller, then all pages ** being discarded by the truncation must be written to the journal ** file. */ Pgno i; - void *pPage; int iSkip = PAGER_MJ_PGNO(pPager); for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){ if( !(pPager->aInJournal[i/8] & (1<<(i&7))) && i!=iSkip ){ - rc = sqlite3pager_get(pPager, i, &pPage); + rc = sqlite3PagerGet(pPager, i, &pPg); if( rc!=SQLITE_OK ) goto sync_exit; - rc = sqlite3pager_write(pPage); - sqlite3pager_unref(pPage); + rc = sqlite3PagerWrite(pPg); + sqlite3PagerUnref(pPg); if( rc!=SQLITE_OK ) goto sync_exit; } } } #endif @@ -3882,11 +3872,11 @@ if( rc!=SQLITE_OK ) goto sync_exit; } #ifndef SQLITE_OMIT_AUTOVACUUM if( nTrunc!=0 ){ - rc = sqlite3pager_truncate(pPager, nTrunc); + rc = sqlite3PagerTruncate(pPager, nTrunc); if( rc!=SQLITE_OK ) goto sync_exit; } #endif /* Write all dirty pages to the database file */ @@ -3900,11 +3890,11 @@ } IOTRACE(("DBSYNC %p\n", pPager)) pPager->state = PAGER_SYNCED; }else if( MEMDB && nTrunc!=0 ){ - rc = sqlite3pager_truncate(pPager, nTrunc); + rc = sqlite3PagerTruncate(pPager, nTrunc); } sync_exit: return rc; } @@ -3925,12 +3915,11 @@ ** A transaction must be active when this routine is called. It used to be ** required that a statement transaction was not active, but this restriction ** has been removed (CREATE INDEX needs to move a page when a statement ** transaction is active). */ -int sqlite3pager_movepage(Pager *pPager, void *pData, Pgno pgno){ - PgHdr *pPg = DATA_TO_PGHDR(pData); +int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno){ PgHdr *pPgOld; int h; Pgno needSyncPgno = 0; assert( pPg->nRef>0 ); @@ -3987,45 +3976,61 @@ ** sync()ed before any data is written to database file page needSyncPgno. ** Currently, no such page exists in the page-cache and the ** Pager.aInJournal bit has been set. This needs to be remedied by loading ** the page into the pager-cache and setting the PgHdr.needSync flag. ** - ** The sqlite3pager_get() call may cause the journal to sync. So make + ** The sqlite3PagerGet() call may cause the journal to sync. So make ** sure the Pager.needSync flag is set too. */ int rc; - void *pNeedSync; + PgHdr *pPgHdr; assert( pPager->needSync ); - rc = sqlite3pager_get(pPager, needSyncPgno, &pNeedSync); + rc = sqlite3PagerGet(pPager, needSyncPgno, &pPgHdr); if( rc!=SQLITE_OK ) return rc; pPager->needSync = 1; - DATA_TO_PGHDR(pNeedSync)->needSync = 1; - DATA_TO_PGHDR(pNeedSync)->inJournal = 1; - makeDirty(DATA_TO_PGHDR(pNeedSync)); - sqlite3pager_unref(pNeedSync); + pPgHdr->needSync = 1; + pPgHdr->inJournal = 1; + makeDirty(pPgHdr); + sqlite3PagerUnref(pPgHdr); } return SQLITE_OK; } #endif + +/* +** Return a pointer to the data for the specified page. +*/ +void *sqlite3PagerGetData(DbPage *pPg){ + return PGHDR_TO_DATA(pPg); +} + +/* +** Return a pointer to the Pager.nExtra bytes of "extra" space +** allocated along with the specified page. +*/ +void *sqlite3PagerGetExtra(DbPage *pPg){ + Pager *pPager = pPg->pPager; + return (pPager?PGHDR_TO_EXTRA(pPg, pPager):0); +} #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) /* ** Return the current state of the file lock for the given pager. ** The return value is one of NO_LOCK, SHARED_LOCK, RESERVED_LOCK, ** PENDING_LOCK, or EXCLUSIVE_LOCK. */ -int sqlite3pager_lockstate(Pager *pPager){ +int sqlite3PagerLockstate(Pager *pPager){ return sqlite3OsLockState(pPager->fd); } #endif #ifdef SQLITE_DEBUG /* ** Print a listing of all referenced pages and their ref count. */ -void sqlite3pager_refdump(Pager *pPager){ +void sqlite3PagerRefdump(Pager *pPager){ PgHdr *pPg; for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){ if( pPg->nRef<=0 ) continue; sqlite3DebugPrintf("PAGE %3d addr=%p nRef=%d\n", pPg->pgno, PGHDR_TO_DATA(pPg), pPg->nRef); Index: src/pager.h ================================================================== --- src/pager.h +++ src/pager.h @@ -11,11 +11,11 @@ ************************************************************************* ** This header file defines the interface that the sqlite page cache ** subsystem. The page cache subsystem reads and writes a file a page ** at a time and provides a journal for rollback. ** -** @(#) $Id: pager.h,v 1.53 2007/03/04 13:15:28 drh Exp $ +** @(#) $Id: pager.h,v 1.54 2007/03/19 17:44:27 danielk1977 Exp $ */ #ifndef _PAGER_H_ #define _PAGER_H_ @@ -55,11 +55,16 @@ ** Each open file is managed by a separate instance of the "Pager" structure. */ typedef struct Pager Pager; /* -** Allowed values for the flags parameter to sqlite3pager_open(). +** Handle type for pages. +*/ +typedef struct PgHdr DbPage; + +/* +** Allowed values for the flags parameter to sqlite3PagerOpen(). ** ** NOTE: This values must match the corresponding BTREE_ values in btree.h. */ #define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */ #define PAGER_NO_READLOCK 0x0002 /* Omit readlocks on readonly files */ @@ -67,58 +72,61 @@ /* ** See source code comments for a detailed description of the following ** routines: */ -int sqlite3pager_open(Pager **ppPager, const char *zFilename, +int sqlite3PagerOpen(Pager **ppPager, const char *zFilename, int nExtra, int flags); -void sqlite3pager_set_busyhandler(Pager*, BusyHandler *pBusyHandler); -void sqlite3pager_set_destructor(Pager*, void(*)(void*,int)); -void sqlite3pager_set_reiniter(Pager*, void(*)(void*,int)); -int sqlite3pager_set_pagesize(Pager*, int); -int sqlite3pager_read_fileheader(Pager*, int, unsigned char*); -void sqlite3pager_set_cachesize(Pager*, int); -int sqlite3pager_close(Pager *pPager); -int sqlite3pager_acquire(Pager *pPager, Pgno pgno, void **ppPage, int clrFlag); -#define sqlite3pager_get(A,B,C) sqlite3pager_acquire(A,B,C,0) -void *sqlite3pager_lookup(Pager *pPager, Pgno pgno); -int sqlite3pager_ref(void*); -int sqlite3pager_unref(void*); -Pgno sqlite3pager_pagenumber(void*); -int sqlite3pager_write(void*); -int sqlite3pager_iswriteable(void*); -int sqlite3pager_overwrite(Pager *pPager, Pgno pgno, void*); -int sqlite3pager_pagecount(Pager*); -int sqlite3pager_truncate(Pager*,Pgno); -int sqlite3pager_begin(void*, int exFlag); -int sqlite3pager_commit(Pager*); -int sqlite3pager_sync(Pager*,const char *zMaster, Pgno); -int sqlite3pager_rollback(Pager*); -int sqlite3pager_isreadonly(Pager*); -int sqlite3pager_stmt_begin(Pager*); -int sqlite3pager_stmt_commit(Pager*); -int sqlite3pager_stmt_rollback(Pager*); -void sqlite3pager_dont_rollback(void*); -void sqlite3pager_dont_write(Pager*, Pgno); -int sqlite3pager_refcount(Pager*); -int *sqlite3pager_stats(Pager*); -void sqlite3pager_set_safety_level(Pager*,int,int); -const char *sqlite3pager_filename(Pager*); -const char *sqlite3pager_dirname(Pager*); -const char *sqlite3pager_journalname(Pager*); -int sqlite3pager_nosync(Pager*); -int sqlite3pager_rename(Pager*, const char *zNewName); -void sqlite3pager_set_codec(Pager*,void*(*)(void*,void*,Pgno,int),void*); -int sqlite3pager_movepage(Pager*,void*,Pgno); -int sqlite3pager_reset(Pager*); -int sqlite3pager_release_memory(int); +void sqlite3PagerSetBusyhandler(Pager*, BusyHandler *pBusyHandler); +void sqlite3PagerSetDestructor(Pager*, void(*)(DbPage*,int)); +void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*,int)); +int sqlite3PagerSetPagesize(Pager*, int); +int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); +void sqlite3PagerSetCachesize(Pager*, int); +int sqlite3PagerClose(Pager *pPager); +int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag); +#define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0) +DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno); +int sqlite3PagerRef(DbPage*); +int sqlite3PagerUnref(DbPage*); +Pgno sqlite3PagerPagenumber(DbPage*); +int sqlite3PagerWrite(DbPage*); +int sqlite3PagerIswriteable(DbPage*); +int sqlite3PagerOverwrite(Pager *pPager, Pgno pgno, void*); +int sqlite3PagerPagecount(Pager*); +int sqlite3PagerTruncate(Pager*,Pgno); +int sqlite3PagerBegin(DbPage*, int exFlag); +int sqlite3PagerCommit(Pager*); +int sqlite3PagerSync(Pager*,const char *zMaster, Pgno); +int sqlite3PagerRollback(Pager*); +int sqlite3PagerIsreadonly(Pager*); +int sqlite3PagerStmtBegin(Pager*); +int sqlite3PagerStmtCommit(Pager*); +int sqlite3PagerStmtRollback(Pager*); +void sqlite3PagerDontRollback(DbPage*); +void sqlite3PagerDontWrite(Pager*, Pgno); +int sqlite3PagerRefcount(Pager*); +int *sqlite3PagerStats(Pager*); +void sqlite3PagerSetSafetyLevel(Pager*,int,int); +const char *sqlite3PagerFilename(Pager*); +const char *sqlite3PagerDirname(Pager*); +const char *sqlite3PagerJournalname(Pager*); +int sqlite3PagerNosync(Pager*); +int sqlite3PagerRename(Pager*, const char *zNewName); +void sqlite3PagerSetCodec(Pager*,void*(*)(void*,void*,Pgno,int),void*); +int sqlite3PagerMovepage(Pager*,DbPage*,Pgno); +int sqlite3PagerReset(Pager*); +int sqlite3PagerReleaseMemory(int); + +void *sqlite3PagerGetData(DbPage *); +void *sqlite3PagerGetExtra(DbPage *); #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) -int sqlite3pager_lockstate(Pager*); +int sqlite3PagerLockstate(Pager*); #endif #ifdef SQLITE_TEST -void sqlite3pager_refdump(Pager*); +void sqlite3PagerRefdump(Pager*); int pager3_refinfo_enable; #endif #endif /* _PAGER_H_ */ Index: src/pragma.c ================================================================== --- src/pragma.c +++ src/pragma.c @@ -9,11 +9,11 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains code used to implement the PRAGMA command. ** -** $Id: pragma.c,v 1.128 2007/03/14 15:37:04 danielk1977 Exp $ +** $Id: pragma.c,v 1.129 2007/03/19 17:44:28 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" #include @@ -939,11 +939,11 @@ sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, P3_STATIC); pBt = db->aDb[i].pBt; if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){ sqlite3VdbeOp3(v, OP_String8, 0, 0, "closed", P3_STATIC); }else{ - int j = sqlite3pager_lockstate(pPager); + int j = sqlite3PagerLockstate(pPager); sqlite3VdbeOp3(v, OP_String8, 0, 0, (j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC); } sqlite3VdbeAddOp(v, OP_Callback, 2, 0); } Index: src/test2.c ================================================================== --- src/test2.c +++ src/test2.c @@ -11,11 +11,11 @@ ************************************************************************* ** Code for testing the pager.c module in SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test2.c,v 1.40 2007/03/15 12:17:43 drh Exp $ +** $Id: test2.c,v 1.41 2007/03/19 17:44:28 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" #include "pager.h" #include "tcl.h" @@ -76,17 +76,17 @@ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " FILENAME N-PAGE\"", 0); return TCL_ERROR; } if( Tcl_GetInt(interp, argv[2], &nPage) ) return TCL_ERROR; - rc = sqlite3pager_open(&pPager, argv[1], 0, 0); + rc = sqlite3PagerOpen(&pPager, argv[1], 0, 0); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } - sqlite3pager_set_cachesize(pPager, nPage); - sqlite3pager_set_pagesize(pPager, test_pagesize); + sqlite3PagerSetCachesize(pPager, nPage); + sqlite3PagerSetPagesize(pPager, test_pagesize); sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPager); Tcl_AppendResult(interp, zBuf, 0); return TCL_OK; } @@ -107,11 +107,11 @@ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pPager = sqlite3TextToPtr(argv[1]); - rc = sqlite3pager_close(pPager); + rc = sqlite3PagerClose(pPager); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } return TCL_OK; @@ -134,11 +134,11 @@ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pPager = sqlite3TextToPtr(argv[1]); - rc = sqlite3pager_rollback(pPager); + rc = sqlite3PagerRollback(pPager); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } return TCL_OK; @@ -161,11 +161,11 @@ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pPager = sqlite3TextToPtr(argv[1]); - rc = sqlite3pager_commit(pPager); + rc = sqlite3PagerCommit(pPager); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } return TCL_OK; @@ -188,11 +188,11 @@ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pPager = sqlite3TextToPtr(argv[1]); - rc = sqlite3pager_stmt_begin(pPager); + rc = sqlite3PagerStmtBegin(pPager); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } return TCL_OK; @@ -215,11 +215,11 @@ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pPager = sqlite3TextToPtr(argv[1]); - rc = sqlite3pager_stmt_rollback(pPager); + rc = sqlite3PagerStmtRollback(pPager); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } return TCL_OK; @@ -242,11 +242,11 @@ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pPager = sqlite3TextToPtr(argv[1]); - rc = sqlite3pager_stmt_commit(pPager); + rc = sqlite3PagerStmtCommit(pPager); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } return TCL_OK; @@ -269,11 +269,11 @@ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pPager = sqlite3TextToPtr(argv[1]); - a = sqlite3pager_stats(pPager); + a = sqlite3PagerStats(pPager); for(i=0; i<9; i++){ static char *zName[] = { "ref", "page", "max", "size", "state", "err", "hit", "miss", "ovfl", }; @@ -302,11 +302,11 @@ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pPager = sqlite3TextToPtr(argv[1]); - sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",sqlite3pager_pagecount(pPager)); + sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",sqlite3PagerPagecount(pPager)); Tcl_AppendResult(interp, zBuf, 0); return TCL_OK; } /* @@ -320,21 +320,21 @@ int argc, /* Number of arguments */ const char **argv /* Text of each argument */ ){ Pager *pPager; char zBuf[100]; - void *pPage; + DbPage *pPage; int pgno; int rc; if( argc!=3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID PGNO\"", 0); return TCL_ERROR; } pPager = sqlite3TextToPtr(argv[1]); if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR; - rc = sqlite3pager_get(pPager, pgno, &pPage); + rc = sqlite3PagerGet(pPager, pgno, &pPage); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPage); @@ -354,20 +354,20 @@ int argc, /* Number of arguments */ const char **argv /* Text of each argument */ ){ Pager *pPager; char zBuf[100]; - void *pPage; + DbPage *pPage; int pgno; if( argc!=3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID PGNO\"", 0); return TCL_ERROR; } pPager = sqlite3TextToPtr(argv[1]); if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR; - pPage = sqlite3pager_lookup(pPager, pgno); + pPage = sqlite3PagerLookup(pPager, pgno); if( pPage ){ sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPage); Tcl_AppendResult(interp, zBuf, 0); } return TCL_OK; @@ -390,11 +390,11 @@ " ID PGNO\"", 0); return TCL_ERROR; } pPager = sqlite3TextToPtr(argv[1]); if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR; - rc = sqlite3pager_truncate(pPager, pgno); + rc = sqlite3PagerTruncate(pPager, pgno); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } return TCL_OK; @@ -410,19 +410,19 @@ void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */ ){ - void *pPage; + DbPage *pPage; int rc; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " PAGE\"", 0); return TCL_ERROR; } - pPage = sqlite3TextToPtr(argv[1]); - rc = sqlite3pager_unref(pPage); + pPage = (DbPage *)sqlite3TextToPtr(argv[1]); + rc = sqlite3PagerUnref(pPage); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } return TCL_OK; @@ -438,18 +438,18 @@ Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */ ){ char zBuf[100]; - void *pPage; + DbPage *pPage; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " PAGE\"", 0); return TCL_ERROR; } pPage = sqlite3TextToPtr(argv[1]); - memcpy(zBuf, pPage, sizeof(zBuf)); + memcpy(zBuf, sqlite3PagerGetData(pPage), sizeof(zBuf)); Tcl_AppendResult(interp, zBuf, 0); return TCL_OK; } /* @@ -462,18 +462,18 @@ Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */ ){ char zBuf[100]; - void *pPage; + DbPage *pPage; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " PAGE\"", 0); return TCL_ERROR; } - pPage = sqlite3TextToPtr(argv[1]); - sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", sqlite3pager_pagenumber(pPage)); + pPage = (DbPage *)sqlite3TextToPtr(argv[1]); + sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", sqlite3PagerPagenumber(pPage)); Tcl_AppendResult(interp, zBuf, 0); return TCL_OK; } /* @@ -485,25 +485,27 @@ void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */ ){ - void *pPage; + DbPage *pPage; + char *pData; int rc; if( argc!=3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " PAGE DATA\"", 0); return TCL_ERROR; } - pPage = sqlite3TextToPtr(argv[1]); - rc = sqlite3pager_write(pPage); + pPage = (DbPage *)sqlite3TextToPtr(argv[1]); + rc = sqlite3PagerWrite(pPage); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } - strncpy((char*)pPage, argv[2], test_pagesize-1); - ((char*)pPage)[test_pagesize-1] = 0; + pData = sqlite3PagerGetData(pPage); + strncpy(pData, argv[2], test_pagesize-1); + pData[test_pagesize-1] = 0; return TCL_OK; } #ifndef SQLITE_OMIT_DISKIO /* Index: src/test3.c ================================================================== --- src/test3.c +++ src/test3.c @@ -11,11 +11,11 @@ ************************************************************************* ** Code for testing the btree.c module in SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test3.c,v 1.70 2007/02/10 19:22:36 drh Exp $ +** $Id: test3.c,v 1.71 2007/03/19 17:44:28 danielk1977 Exp $ */ #include "sqliteInt.h" #include "pager.h" #include "btree.h" #include "tcl.h" @@ -509,11 +509,11 @@ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pBt = sqlite3TextToPtr(argv[1]); - a = sqlite3pager_stats(sqlite3BtreePager(pBt)); + a = sqlite3PagerStats(sqlite3BtreePager(pBt)); for(i=0; i<11; i++){ static char *zName[] = { "ref", "page", "max", "size", "state", "err", "hit", "miss", "ovfl", "read", "write" }; @@ -543,11 +543,11 @@ " ID\"", 0); return TCL_ERROR; } pBt = sqlite3TextToPtr(argv[1]); #ifdef SQLITE_DEBUG - sqlite3pager_refdump(sqlite3BtreePager(pBt)); + sqlite3PagerRefdump(sqlite3BtreePager(pBt)); #endif return TCL_OK; } /* @@ -1280,19 +1280,21 @@ Tcl_DStringInit(&str); n = aResult[6] - aResult[8]; n = (n + dataSize - 1)/dataSize; pgno = (u32)aResult[10]; while( pgno && n-- ){ + DbPage *pDbPage; sprintf(zElem, "%d", pgno); Tcl_DStringAppendElement(&str, zElem); - if( sqlite3pager_get(pPager, pgno, &pPage)!=SQLITE_OK ){ + if( sqlite3PagerGet(pPager, pgno, &pDbPage)!=SQLITE_OK ){ Tcl_DStringFree(&str); Tcl_AppendResult(interp, "unable to get page ", zElem, 0); return TCL_ERROR; } + pPage = sqlite3PagerGetData(pDbPage); pgno = get4byte((unsigned char*)pPage); - sqlite3pager_unref(pPage); + sqlite3PagerUnref(pDbPage); } Tcl_DStringResult(interp, &str); return SQLITE_OK; } Index: src/util.c ================================================================== --- src/util.c +++ src/util.c @@ -12,11 +12,11 @@ ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** -** $Id: util.c,v 1.194 2007/03/15 15:33:32 danielk1977 Exp $ +** $Id: util.c,v 1.195 2007/03/19 17:44:28 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" #include #include @@ -81,11 +81,11 @@ /* ** Release memory held by SQLite instances created by the current thread. */ int sqlite3_release_memory(int n){ - return sqlite3pager_release_memory(n); + return sqlite3PagerReleaseMemory(n); } #else /* If SQLITE_ENABLE_MEMORY_MANAGEMENT is not defined, then define a version ** of sqlite3_release_memory() to be used by other code in this file. ** This is done for no better reason than to reduce the number of