Lines Matching refs:pBt

8070 SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
9272 Btree *pBt; /* The B*Tree structure for this database file */ member
12533 Btree *pBt; /* Separate file holding temporary table */ member
13041 Btree *pBt = db->aDb[i].pBt; in sqlite3_db_status() local
13042 if( pBt ){ in sqlite3_db_status()
13043 Pager *pPager = sqlite3BtreePager(pBt); in sqlite3_db_status()
15126 void **pBt; in sqlite3MemMalloc() local
15140 pBt = (void**)&z[mem.nTitle]; in sqlite3MemMalloc()
15141 pHdr = (struct MemBlockHdr*)&pBt[mem.nBacktrace]; in sqlite3MemMalloc()
15157 memcpy(pBt, &aAddr[1], pHdr->nBacktrace*sizeof(void*)); in sqlite3MemMalloc()
15158 assert(pBt[0]); in sqlite3MemMalloc()
15185 void **pBt; in sqlite3MemFree() local
15190 pBt = (void**)pHdr; in sqlite3MemFree()
15191 pBt -= pHdr->nBacktraceSlots; in sqlite3MemFree()
15207 z = (char*)pBt; in sqlite3MemFree()
15348 void **pBt = (void**)pHdr; in sqlite3MemdebugSync() local
15349 pBt -= pHdr->nBacktraceSlots; in sqlite3MemdebugSync()
15350 mem.xBacktrace(pHdr->iSize, pHdr->nBacktrace-1, &pBt[1]); in sqlite3MemdebugSync()
15361 void **pBt; in sqlite3MemdebugDump() local
15376 pBt = (void**)pHdr; in sqlite3MemdebugDump()
15377 pBt -= pHdr->nBacktraceSlots; in sqlite3MemdebugDump()
15378 backtrace_symbols_fd(pBt, pHdr->nBacktrace, fileno(out)); in sqlite3MemdebugDump()
46819 #define MX_CELL_SIZE(pBt) ((int)(pBt->pageSize-8))
46826 #define MX_CELL(pBt) ((pBt->pageSize-8)/6)
46888 BtShared *pBt; /* Pointer to BtShared that this page is part of */
46942 BtShared *pBt; /* Sharable content of this btree */
47084 BtShared *pBt; /* The BtShared this cursor points to */
47139 # define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt)
47156 #define PTRMAP_PAGENO(pBt, pgno) ptrmapPageno(pBt, pgno)
47158 #define PTRMAP_ISPAGE(pBt, pgno) (PTRMAP_PAGENO((pBt),(pgno))==(pgno))
47201 assert( p->pBt->inTransaction!=TRANS_NONE || p->pBt->nTransaction==0 ); \
47202 assert( p->pBt->inTransaction>=p->inTrans );
47213 #define ISAUTOVACUUM (pBt->autoVacuum)
47225 BtShared *pBt; /* The tree being checked out */
47255 assert( sqlite3_mutex_notheld(p->pBt->mutex) );
47258 sqlite3_mutex_enter(p->pBt->mutex);
47259 p->pBt->db = p->db;
47268 BtShared *pBt = p->pBt;
47270 assert( sqlite3_mutex_held(pBt->mutex) );
47272 assert( p->db==pBt->db );
47274 sqlite3_mutex_leave(pBt->mutex);
47301 assert( p->pNext==0 || p->pNext->pBt>p->pBt );
47302 assert( p->pPrev==0 || p->pPrev->pBt<p->pBt );
47316 assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db );
47326 if( sqlite3_mutex_try(p->pBt->mutex)==SQLITE_OK ){
47327 p->pBt->db = p->db;
47339 assert( pLater->pNext==0 || pLater->pNext->pBt>pLater->pBt );
47375 assert( p->sharable==0 || p->locked==0 || p->db==p->pBt->db );
47376 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->pBt->mutex) );
47418 p = db->aDb[i].pBt;
47427 p = db->aDb[i].pBt;
47454 p = db->aDb[i].pBt;
47456 (p->wantToLock==0 || !sqlite3_mutex_held(p->pBt->mutex)) ){
47483 p = db->aDb[iDb].pBt;
47501 p->pBt->db = p->db;
47506 Btree *p = db->aDb[i].pBt;
47508 p->pBt->db = p->db;
47642 Schema *pSchema = (Schema *)pBtree->pBt->pSchema;
47684 for(pLock=pBtree->pBt->pLock; pLock; pLock=pLock->pNext){
47719 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
47738 BtShared *pBt = p->pBt;
47750 assert( eLock==READ_LOCK || (p==pBt->pWriter && p->inTrans==TRANS_WRITE) );
47751 assert( eLock==READ_LOCK || pBt->inTransaction==TRANS_WRITE );
47761 if( pBt->pWriter!=p && pBt->isExclusive ){
47762 sqlite3ConnectionBlocked(p->db, pBt->pWriter->db);
47766 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
47781 assert( p==pBt->pWriter );
47782 pBt->isPending = 1;
47810 BtShared *pBt = p->pBt;
47830 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
47847 pLock->pNext = pBt->pLock;
47848 pBt->pLock = pLock;
47874 BtShared *pBt = p->pBt;
47875 BtLock **ppIter = &pBt->pLock;
47883 assert( pBt->isExclusive==0 || pBt->pWriter==pLock->pBtree );
47896 assert( pBt->isPending==0 || pBt->pWriter );
47897 if( pBt->pWriter==p ){
47898 pBt->pWriter = 0;
47899 pBt->isExclusive = 0;
47900 pBt->isPending = 0;
47901 }else if( pBt->nTransaction==2 ){
47911 pBt->isPending = 0;
47919 BtShared *pBt = p->pBt;
47920 if( pBt->pWriter==p ){
47922 pBt->pWriter = 0;
47923 pBt->isExclusive = 0;
47924 pBt->isPending = 0;
47925 for(pLock=pBt->pLock; pLock; pLock=pLock->pNext){
47943 return sqlite3_mutex_held(p->pBt->mutex);
47962 static void invalidateAllOverflowCache(BtShared *pBt){
47964 assert( sqlite3_mutex_held(pBt->mutex) );
47965 for(p=pBt->pCursor; p; p=p->pNext){
47989 BtShared *pBt = pBtree->pBt;
47991 for(p=pBt->pCursor; p; p=p->pNext){
48040 static int btreeSetHasContent(BtShared *pBt, Pgno pgno){
48042 if( !pBt->pHasContent ){
48043 assert( pgno<=pBt->nPage );
48044 pBt->pHasContent = sqlite3BitvecCreate(pBt->nPage);
48045 if( !pBt->pHasContent ){
48049 if( rc==SQLITE_OK && pgno<=sqlite3BitvecSize(pBt->pHasContent) ){
48050 rc = sqlite3BitvecSet(pBt->pHasContent, pgno);
48062 static int btreeGetHasContent(BtShared *pBt, Pgno pgno){
48063 Bitvec *p = pBt->pHasContent;
48071 static void btreeClearHasContent(BtShared *pBt){
48072 sqlite3BitvecDestroy(pBt->pHasContent);
48073 pBt->pHasContent = 0;
48133 static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){
48135 assert( sqlite3_mutex_held(pBt->mutex) );
48136 assert( pExcept==0 || pExcept->pBt==pBt );
48137 for(p=pBt->pCursor; p; p=p->pNext){
48253 static Pgno ptrmapPageno(BtShared *pBt, Pgno pgno){
48256 assert( sqlite3_mutex_held(pBt->mutex) );
48258 nPagesPerMapPage = (pBt->usableSize/5)+1;
48261 if( ret==PENDING_BYTE_PAGE(pBt) ){
48277 static void ptrmapPut(BtShared *pBt, Pgno key, u8 eType, Pgno parent, int *pRC){
48286 assert( sqlite3_mutex_held(pBt->mutex) );
48288 assert( 0==PTRMAP_ISPAGE(pBt, PENDING_BYTE_PAGE(pBt)) );
48290 assert( pBt->autoVacuum );
48295 iPtrmap = PTRMAP_PAGENO(pBt, key);
48296 rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage);
48306 assert( offset <= (int)pBt->usableSize-5 );
48329 static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno){
48336 assert( sqlite3_mutex_held(pBt->mutex) );
48338 iPtrmap = PTRMAP_PAGENO(pBt, key);
48339 rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage);
48350 assert( offset <= (int)pBt->usableSize-5 );
48384 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
48417 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
48463 surplus = minLocal + (nPayload - minLocal)%(pPage->pBt->usableSize - 4);
48525 nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
48566 ptrmapPut(pPage->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, pRC);
48594 assert( pPage->pBt!=0 );
48595 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
48597 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
48598 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
48604 usableSize = pPage->pBt->usableSize;
48678 assert( pPage->pBt );
48679 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
48683 usableSize = pPage->pBt->usableSize;
48754 assert( top+nByte <= (int)pPage->pBt->usableSize );
48772 assert( pPage->pBt!=0 );
48775 assert( (start + size) <= (int)pPage->pBt->usableSize );
48776 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
48779 if( pPage->pBt->secureDelete ){
48796 iLast = pPage->pBt->usableSize - 4;
48818 assert( pbegin <= (int)pPage->pBt->usableSize-4 );
48861 BtShared *pBt; /* A copy of pPage->pBt */
48864 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
48868 pBt = pPage->pBt;
48872 pPage->maxLocal = pBt->maxLeaf;
48873 pPage->minLocal = pBt->minLeaf;
48877 pPage->maxLocal = pBt->maxLocal;
48878 pPage->minLocal = pBt->minLocal;
48896 assert( pPage->pBt!=0 );
48897 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
48906 BtShared *pBt; /* The main btree structure */
48914 pBt = pPage->pBt;
48919 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
48920 pPage->maskPage = (u16)(pBt->pageSize - 1);
48922 usableSize = pBt->usableSize;
48926 if( pPage->nCell>MX_CELL(pBt) ){
48930 testcase( pPage->nCell==MX_CELL(pBt) );
49006 BtShared *pBt = pPage->pBt;
49014 assert( sqlite3_mutex_held(pBt->mutex) );
49015 if( pBt->secureDelete ){
49016 memset(&data[hdr], 0, pBt->usableSize - hdr);
49022 put2byte(&data[hdr+5], pBt->usableSize);
49023 pPage->nFree = (u16)(pBt->usableSize - first);
49028 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
49029 pPage->maskPage = (u16)(pBt->pageSize - 1);
49039 static MemPage *btreePageFromDbPage(DbPage *pDbPage, Pgno pgno, BtShared *pBt){
49043 pPage->pBt = pBt;
49061 BtShared *pBt, /* The btree */
49069 assert( sqlite3_mutex_held(pBt->mutex) );
49070 rc = sqlite3PagerAcquire(pBt->pPager, pgno, (DbPage**)&pDbPage, noContent);
49072 *ppPage = btreePageFromDbPage(pDbPage, pgno, pBt);
49081 static MemPage *btreePageLookup(BtShared *pBt, Pgno pgno){
49083 assert( sqlite3_mutex_held(pBt->mutex) );
49084 pDbPage = sqlite3PagerLookup(pBt->pPager, pgno);
49086 return btreePageFromDbPage(pDbPage, pgno, pBt);
49095 static Pgno btreePagecount(BtShared *pBt){
49096 return pBt->nPage;
49100 assert( ((p->pBt->nPage)&0x8000000)==0 );
49101 return (int)btreePagecount(p->pBt);
49113 BtShared *pBt, /* The database file */
49118 assert( sqlite3_mutex_held(pBt->mutex) );
49120 if( pgno>btreePagecount(pBt) ){
49123 rc = btreeGetPage(pBt, pgno, ppPage, 0);
49144 assert( pPage->pBt );
49147 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
49165 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
49183 BtShared *pBt = (BtShared*)pArg;
49184 assert( pBt->db );
49185 assert( sqlite3_mutex_held(pBt->db->mutex) );
49186 return sqlite3InvokeBusyHandler(&pBt->db->busyHandler);
49221 BtShared *pBt = 0; /* Shared part of btree structure */
49292 for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
49293 assert( pBt->nRef>0 );
49294 if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager))
49295 && sqlite3PagerVfs(pBt->pPager)==pVfs ){
49298 Btree *pExisting = db->aDb[iDb].pBt;
49299 if( pExisting && pExisting->pBt==pBt ){
49307 p->pBt = pBt;
49308 pBt->nRef++;
49327 if( pBt==0 ){
49339 pBt = sqlite3MallocZero( sizeof(*pBt) );
49340 if( pBt==0 ){
49344 rc = sqlite3PagerOpen(pVfs, &pBt->pPager, zFilename,
49347 rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
49352 pBt->openFlags = (u8)flags;
49353 pBt->db = db;
49354 sqlite3PagerSetBusyhandler(pBt->pPager, btreeInvokeBusyHandler, pBt);
49355 p->pBt = pBt;
49357 pBt->pCursor = 0;
49358 pBt->pPage1 = 0;
49359 pBt->readOnly = sqlite3PagerIsreadonly(pBt->pPager);
49361 pBt->secureDelete = 1;
49363 pBt->pageSize = (zDbHeader[16]<<8) | (zDbHeader[17]<<16);
49364 if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
49365 || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
49366 pBt->pageSize = 0;
49375 pBt->autoVacuum = (SQLITE_DEFAULT_AUTOVACUUM ? 1 : 0);
49376 pBt->incrVacuum = (SQLITE_DEFAULT_AUTOVACUUM==2 ? 1 : 0);
49382 pBt->pageSizeFixed = 1;
49384 pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
49385 pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0);
49388 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve);
49390 pBt->usableSize = pBt->pageSize - nReserve;
49391 assert( (pBt->pageSize & 7)==0 ); /* 8-byte alignment of pageSize */
49398 pBt->nRef = 1;
49401 pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST);
49402 if( pBt->mutex==0 ){
49409 pBt->pNext = GLOBAL(BtShared*,sqlite3SharedCacheList);
49410 GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt;
49425 if( (pSib = db->aDb[i].pBt)!=0 && pSib->sharable ){
49427 if( p->pBt<pSib->pBt ){
49432 while( pSib->pNext && pSib->pNext->pBt<p->pBt ){
49451 if( pBt && pBt->pPager ){
49452 sqlite3PagerClose(pBt->pPager);
49454 sqlite3_free(pBt);
49463 sqlite3PagerSetCachesize(p->pBt->pPager, SQLITE_DEFAULT_CACHE_SIZE);
49479 static int removeFromSharingList(BtShared *pBt){
49485 assert( sqlite3_mutex_notheld(pBt->mutex) );
49488 pBt->nRef--;
49489 if( pBt->nRef<=0 ){
49490 if( GLOBAL(BtShared*,sqlite3SharedCacheList)==pBt ){
49491 GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt->pNext;
49494 while( ALWAYS(pList) && pList->pNext!=pBt ){
49498 pList->pNext = pBt->pNext;
49502 sqlite3_mutex_free(pBt->mutex);
49517 static void allocateTempSpace(BtShared *pBt){
49518 if( !pBt->pTmpSpace ){
49519 pBt->pTmpSpace = sqlite3PageMalloc( pBt->pageSize );
49526 static void freeTempSpace(BtShared *pBt){
49527 sqlite3PageFree( pBt->pTmpSpace);
49528 pBt->pTmpSpace = 0;
49535 BtShared *pBt = p->pBt;
49541 pCur = pBt->pCursor;
49562 if( !p->sharable || removeFromSharingList(pBt) ){
49568 assert( !pBt->pCursor );
49569 sqlite3PagerClose(pBt->pPager);
49570 if( pBt->xFreeSchema && pBt->pSchema ){
49571 pBt->xFreeSchema(pBt->pSchema);
49573 sqlite3DbFree(0, pBt->pSchema);
49574 freeTempSpace(pBt);
49575 sqlite3_free(pBt);
49605 BtShared *pBt = p->pBt;
49608 sqlite3PagerSetCachesize(pBt->pPager, mxPage);
49628 BtShared *pBt = p->pBt;
49632 sqlite3PagerSetSafetyLevel(pBt->pPager, level, fullSync, ckptFullSync);
49643 BtShared *pBt = p->pBt;
49647 assert( pBt && pBt->pPager );
49648 rc = sqlite3PagerNosync(pBt->pPager);
49675 BtShared *pBt = p->pBt;
49678 if( pBt->pageSizeFixed ){
49683 nReserve = pBt->pageSize - pBt->usableSize;
49689 assert( !pBt->pPage1 && !pBt->pCursor );
49690 pBt->pageSize = (u32)pageSize;
49691 freeTempSpace(pBt);
49693 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve);
49694 pBt->usableSize = pBt->pageSize - (u16)nReserve;
49695 if( iFix ) pBt->pageSizeFixed = 1;
49704 return p->pBt->pageSize;
49716 n = p->pBt->pageSize - p->pBt->usableSize;
49729 n = sqlite3PagerMaxPageCount(p->pBt->pPager, mxPage);
49744 p->pBt->secureDelete = (newFlag!=0) ? 1 : 0;
49746 b = p->pBt->secureDelete;
49762 BtShared *pBt = p->pBt;
49767 if( pBt->pageSizeFixed && (av ?1:0)!=pBt->autoVacuum ){
49770 pBt->autoVacuum = av ?1:0;
49771 pBt->incrVacuum = av==2 ?1:0;
49789 (!p->pBt->autoVacuum)?BTREE_AUTOVACUUM_NONE:
49790 (!p->pBt->incrVacuum)?BTREE_AUTOVACUUM_FULL:
49808 static int lockBtree(BtShared *pBt){
49815 assert( sqlite3_mutex_held(pBt->mutex) );
49816 assert( pBt->pPage1==0 );
49817 rc = sqlite3PagerSharedLock(pBt->pPager);
49819 rc = btreeGetPage(pBt, 1, &pPage1, 0);
49826 sqlite3PagerPagecount(pBt->pPager, &nPageFile);
49841 pBt->readOnly = 1;
49848 pBt->readOnly = 1;
49862 if( page1[19]==2 && pBt->doNotUseWAL==0 ){
49864 rc = sqlite3PagerOpenWal(pBt->pPager, &isOpen);
49892 if( (u32)pageSize!=pBt->pageSize ){
49900 pBt->usableSize = usableSize;
49901 pBt->pageSize = pageSize;
49902 freeTempSpace(pBt);
49903 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
49907 if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPage>nPageFile ){
49914 pBt->pageSize = pageSize;
49915 pBt->usableSize = usableSize;
49917 pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0);
49918 pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0);
49935 pBt->maxLocal = (u16)((pBt->usableSize-12)*64/255 - 23);
49936 pBt->minLocal = (u16)((pBt->usableSize-12)*32/255 - 23);
49937 pBt->maxLeaf = (u16)(pBt->usableSize - 35);
49938 pBt->minLeaf = (u16)((pBt->usableSize-12)*32/255 - 23);
49939 assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) );
49940 pBt->pPage1 = pPage1;
49941 pBt->nPage = nPage;
49946 pBt->pPage1 = 0;
49958 static void unlockBtreeIfUnused(BtShared *pBt){
49959 assert( sqlite3_mutex_held(pBt->mutex) );
49960 assert( pBt->pCursor==0 || pBt->inTransaction>TRANS_NONE );
49961 if( pBt->inTransaction==TRANS_NONE && pBt->pPage1!=0 ){
49962 assert( pBt->pPage1->aData );
49963 assert( sqlite3PagerRefcount(pBt->pPager)==1 );
49964 assert( pBt->pPage1->aData );
49965 releasePage(pBt->pPage1);
49966 pBt->pPage1 = 0;
49975 static int newDatabase(BtShared *pBt){
49980 assert( sqlite3_mutex_held(pBt->mutex) );
49981 if( pBt->nPage>0 ){
49984 pP1 = pBt->pPage1;
49991 data[16] = (u8)((pBt->pageSize>>8)&0xff);
49992 data[17] = (u8)((pBt->pageSize>>16)&0xff);
49995 assert( pBt->usableSize<=pBt->pageSize && pBt->usableSize+255>=pBt->pageSize);
49996 data[20] = (u8)(pBt->pageSize - pBt->usableSize);
50002 pBt->pageSizeFixed = 1;
50004 assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
50005 assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
50006 put4byte(&data[36 + 4*4], pBt->autoVacuum);
50007 put4byte(&data[36 + 7*4], pBt->incrVacuum);
50009 pBt->nPage = 1;
50051 BtShared *pBt = p->pBt;
50066 if( pBt->readOnly && wrflag ){
50076 if( (wrflag && pBt->inTransaction==TRANS_WRITE) || pBt->isPending ){
50077 pBlock = pBt->pWriter->db;
50080 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
50100 pBt->initiallyEmpty = (u8)(pBt->nPage==0);
50109 while( pBt->pPage1==0 && SQLITE_OK==(rc = lockBtree(pBt)) );
50112 if( pBt->readOnly ){
50115 rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db));
50117 rc = newDatabase(pBt);
50123 unlockBtreeIfUnused(pBt);
50125 }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
50126 btreeInvokeBusyHandler(pBt) );
50130 pBt->nTransaction++;
50135 p->lock.pNext = pBt->pLock;
50136 pBt->pLock = &p->lock;
50141 if( p->inTrans>pBt->inTransaction ){
50142 pBt->inTransaction = p->inTrans;
50145 MemPage *pPage1 = pBt->pPage1;
50147 assert( !pBt->pWriter );
50148 pBt->pWriter = p;
50149 pBt->isExclusive = (u8)(wrflag>1);
50158 if( pBt->nPage!=get4byte(&pPage1->aData[28]) ){
50161 put4byte(&pPage1->aData[28], pBt->nPage);
50174 rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
50193 BtShared *pBt = pPage->pBt;
50197 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
50211 ptrmapPut(pBt, childPgno, PTRMAP_BTREE, pgno, &rc);
50217 ptrmapPut(pBt, childPgno, PTRMAP_BTREE, pgno, &rc);
50240 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
50299 BtShared *pBt, /* Btree */
50308 Pager *pPager = pBt->pPager;
50313 assert( sqlite3_mutex_held(pBt->mutex) );
50314 assert( pDbPage->pBt==pBt );
50341 ptrmapPut(pBt, nextOvfl, PTRMAP_OVERFLOW2, iFreePage, &rc);
50353 rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0);
50365 ptrmapPut(pBt, iFreePage, eType, iPtrPage, &rc);
50392 static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg){
50396 assert( sqlite3_mutex_held(pBt->mutex) );
50399 if( !PTRMAP_ISPAGE(pBt, iLastPg) && iLastPg!=PENDING_BYTE_PAGE(pBt) ){
50403 nFreeList = get4byte(&pBt->pPage1->aData[36]);
50408 rc = ptrmapGet(pBt, iLastPg, &eType, &iPtrPage);
50425 rc = allocateBtreePage(pBt, &pFreePg, &iFreePg, iLastPg, 1);
50436 rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0);
50450 rc = allocateBtreePage(pBt, &pFreePg, &iFreePg, 0, 0);
50461 rc = relocatePage(pBt, pLastPg, eType, iPtrPage, iFreePg, nFin!=0);
50472 while( iLastPg==PENDING_BYTE_PAGE(pBt)||PTRMAP_ISPAGE(pBt, iLastPg) ){
50473 if( PTRMAP_ISPAGE(pBt, iLastPg) ){
50475 rc = btreeGetPage(pBt, iLastPg, &pPg, 0);
50487 sqlite3PagerTruncateImage(pBt->pPager, iLastPg);
50488 pBt->nPage = iLastPg;
50503 BtShared *pBt = p->pBt;
50506 assert( pBt->inTransaction==TRANS_WRITE && p->inTrans==TRANS_WRITE );
50507 if( !pBt->autoVacuum ){
50510 invalidateAllOverflowCache(pBt);
50511 rc = incrVacuumStep(pBt, 0, btreePagecount(pBt));
50513 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
50514 put4byte(&pBt->pPage1->aData[28], pBt->nPage);
50530 static int autoVacuumCommit(BtShared *pBt){
50532 Pager *pPager = pBt->pPager;
50535 assert( sqlite3_mutex_held(pBt->mutex) );
50536 invalidateAllOverflowCache(pBt);
50537 assert(pBt->autoVacuum);
50538 if( !pBt->incrVacuum ){
50546 nOrig = btreePagecount(pBt);
50547 if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){
50555 nFree = get4byte(&pBt->pPage1->aData[36]);
50556 nEntry = pBt->usableSize/5;
50557 nPtrmap = (nFree-nOrig+PTRMAP_PAGENO(pBt, nOrig)+nEntry)/nEntry;
50559 if( nOrig>PENDING_BYTE_PAGE(pBt) && nFin<PENDING_BYTE_PAGE(pBt) ){
50562 while( PTRMAP_ISPAGE(pBt, nFin) || nFin==PENDING_BYTE_PAGE(pBt) ){
50568 rc = incrVacuumStep(pBt, nFin, iFree);
50571 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
50572 put4byte(&pBt->pPage1->aData[32], 0);
50573 put4byte(&pBt->pPage1->aData[36], 0);
50574 put4byte(&pBt->pPage1->aData[28], nFin);
50575 sqlite3PagerTruncateImage(pBt->pPager, nFin);
50576 pBt->nPage = nFin;
50620 BtShared *pBt = p->pBt;
50623 if( pBt->autoVacuum ){
50624 rc = autoVacuumCommit(pBt);
50631 rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zMaster, 0);
50642 BtShared *pBt = p->pBt;
50645 btreeClearHasContent(pBt);
50659 pBt->nTransaction--;
50660 if( 0==pBt->nTransaction ){
50661 pBt->inTransaction = TRANS_NONE;
50668 unlockBtreeIfUnused(pBt);
50711 BtShared *pBt = p->pBt;
50712 assert( pBt->inTransaction==TRANS_WRITE );
50713 assert( pBt->nTransaction>0 );
50714 rc = sqlite3PagerCommitPhaseTwo(pBt->pPager);
50719 pBt->inTransaction = TRANS_READ;
50752 static int countWriteCursors(BtShared *pBt){
50755 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
50782 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
50806 BtShared *pBt = p->pBt;
50810 rc = saveAllCursors(pBt, 0, 0);
50828 assert( TRANS_WRITE==pBt->inTransaction );
50829 rc2 = sqlite3PagerRollback(pBt->pPager);
50837 if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
50840 if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
50841 testcase( pBt->nPage!=nPage );
50842 pBt->nPage = nPage;
50845 assert( countWriteCursors(pBt)==0 );
50846 pBt->inTransaction = TRANS_READ;
50874 BtShared *pBt = p->pBt;
50877 assert( pBt->readOnly==0 );
50880 assert( pBt->inTransaction==TRANS_WRITE );
50886 rc = sqlite3PagerOpenSavepoint(pBt->pPager, iStatement);
50906 BtShared *pBt = p->pBt;
50910 rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
50912 if( iSavepoint<0 && pBt->initiallyEmpty ) pBt->nPage = 0;
50913 rc = newDatabase(pBt);
50914 pBt->nPage = get4byte(28 + pBt->pPage1->aData);
50919 assert( pBt->nPage>0 );
50965 BtShared *pBt = p->pBt; /* Shared b-tree handle */
50980 assert( pBt->pPage1 && pBt->pPage1->aData );
50982 if( NEVER(wrFlag && pBt->readOnly) ){
50985 if( iTable==1 && btreePagecount(pBt)==0 ){
50995 pCur->pBt = pBt;
50997 pCur->pNext = pBt->pCursor;
51001 pBt->pCursor = pCur;
51058 for(p=pCur->pBt->pCursor; p; p=p->pNext){
51082 BtShared *pBt = pCur->pBt;
51088 pBt->pCursor = pCur->pNext;
51096 unlockBtreeIfUnused(pBt);
51228 BtShared *pBt, /* The database file */
51237 assert( sqlite3_mutex_held(pBt->mutex) );
51247 if( pBt->autoVacuum ){
51252 while( PTRMAP_ISPAGE(pBt, iGuess) || iGuess==PENDING_BYTE_PAGE(pBt) ){
51256 if( iGuess<=btreePagecount(pBt) ){
51257 rc = ptrmapGet(pBt, iGuess, &eType, &pgno);
51268 rc = btreeGetPage(pBt, ovfl, &pPage, 0);
51356 BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
51368 || &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
51389 const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */
51445 rc = getOverflowPage(pBt, nextPage, 0, &nextPage);
51453 rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage);
51629 BtShared *pBt = pCur->pBt;
51637 rc = getAndInitPage(pBt, newPgno, &pNewPage);
51720 BtShared *pBt = p->pBt;
51741 rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0]);
52271 BtShared *pBt,
52285 assert( sqlite3_mutex_held(pBt->mutex) );
52286 pPage1 = pBt->pPage1;
52287 mxPage = btreePagecount(pBt);
52306 assert( pBt->autoVacuum );
52307 rc = ptrmapGet(pBt, nearby, &eType, 0);
52338 rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
52360 }else if( k>(u32)(pBt->usableSize/4 - 2) ){
52398 rc = btreeGetPage(pBt, iNewTrunk, &pNewTrunk, 0);
52465 noContent = !btreeGetHasContent(pBt, *pPgno);
52466 rc = btreeGetPage(pBt, *pPgno, ppPage, noContent);
52482 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
52484 pBt->nPage++;
52485 if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ) pBt->nPage++;
52488 if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, pBt->nPage) ){
52494 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
52495 assert( pBt->nPage!=PENDING_BYTE_PAGE(pBt) );
52496 rc = btreeGetPage(pBt, pBt->nPage, &pPg, 1);
52502 pBt->nPage++;
52503 if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ){ pBt->nPage++; }
52506 put4byte(28 + (u8*)pBt->pPage1->aData, pBt->nPage);
52507 *pPgno = pBt->nPage;
52509 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
52510 rc = btreeGetPage(pBt, *pPgno, ppPage, 1);
52519 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
52549 static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
52552 MemPage *pPage1 = pBt->pPage1; /* Local reference to page 1 */
52557 assert( sqlite3_mutex_held(pBt->mutex) );
52565 pPage = btreePageLookup(pBt, iPage);
52574 if( pBt->secureDelete ){
52578 if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) )
52583 memset(pPage->aData, 0, pPage->pBt->pageSize);
52590 ptrmapPut(pBt, iPage, PTRMAP_FREEPAGE, 0, &rc);
52605 rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
52611 assert( pBt->usableSize>32 );
52612 if( nLeaf > (u32)pBt->usableSize/4 - 2 ){
52616 if( nLeaf < (u32)pBt->usableSize/4 - 8 ){
52635 if( pPage && !pBt->secureDelete ){
52638 rc = btreeSetHasContent(pBt, iPage);
52651 if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0)) ){
52673 *pRC = freePage2(pPage->pBt, pPage, pPage->pgno);
52681 BtShared *pBt = pPage->pBt;
52688 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52694 assert( pBt->usableSize > 4 );
52695 ovflPageSize = pBt->usableSize - 4;
52701 if( ovflPgno<2 || ovflPgno>btreePagecount(pBt) ){
52708 rc = getOverflowPage(pBt, ovflPgno, &pOvfl, &iNext);
52712 if( ( pOvfl || ((pOvfl = btreePageLookup(pBt, ovflPgno))!=0) )
52727 rc = freePage2(pBt, pOvfl, ovflPgno);
52767 BtShared *pBt = pPage->pBt;
52772 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52776 assert( pCell<pPage->aData || pCell>=&pPage->aData[pBt->pageSize]
52818 if( pBt->autoVacuum ){
52822 PTRMAP_ISPAGE(pBt, pgnoOvfl) || pgnoOvfl==PENDING_BYTE_PAGE(pBt)
52826 rc = allocateBtreePage(pBt, &pOvfl, &pgnoOvfl, pgnoOvfl, 0);
52838 if( pBt->autoVacuum && rc==SQLITE_OK ){
52840 ptrmapPut(pBt, pgnoOvfl, eType, pgnoPtrmap, &rc);
52857 assert( pPrior<pPage->aData || pPrior>=&pPage->aData[pBt->pageSize]
52866 spaceLeft = pBt->usableSize - 4;
52877 assert( pPayload<pPage->aData || pPayload>=&pPage->aData[pBt->pageSize]
52922 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52928 testcase( pc+sz==pPage->pBt->usableSize );
52929 if( pc < (u32)get2byte(&data[hdr+5]) || pc+sz > pPage->pBt->usableSize ){
52989 assert( pPage->nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=10921 );
52991 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53026 assert( idx+sz <= (int)pPage->pBt->usableSize );
53043 if( pPage->pBt->autoVacuum ){
53068 const int nUsable = pPage->pBt->usableSize; /* Usable size of page */
53071 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53072 assert( nCell>=0 && nCell<=(int)MX_CELL(pPage->pBt)
53073 && (int)MX_CELL(pPage->pBt)<=10921);
53136 BtShared *const pBt = pPage->pBt; /* B-Tree Database */
53141 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53152 rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
53176 ptrmapPut(pBt, pgnoNew, PTRMAP_BTREE, pParent->pgno, &rc);
53228 BtShared *pBt = pPage->pBt;
53239 ptrmapGet(pBt, ovfl, &e, &n);
53244 ptrmapGet(pBt, child, &e, &n);
53250 ptrmapGet(pBt, child, &e, &n);
53277 BtShared * const pBt = pFrom->pBt;
53288 assert( get2byte(&aFrom[iFromHdr+5]) <= (int)pBt->usableSize );
53292 memcpy(&aTo[iData], &aFrom[iData], pBt->usableSize-iData);
53362 BtShared *pBt; /* The whole database */
53390 pBt = pParent->pBt;
53391 assert( sqlite3_mutex_held(pBt->mutex) );
53443 rc = getAndInitPage(pBt, pgno, &apOld[i]);
53473 if( pBt->secureDelete ){
53475 if( (iOff+szNew[i])>(int)pBt->usableSize ){
53495 k = pBt->pageSize + ROUND8(sizeof(MemPage));
53499 + pBt->pageSize /* aSpace1 */
53535 MemPage *pOld = apCopy[i] = (MemPage*)&aSpace1[pBt->pageSize + k*i];
53538 memcpy(pOld->aData, apOld[i]->aData, pBt->pageSize);
53566 assert( sz<=pBt->maxLocal+23 );
53567 assert( iSpace1 <= (int)pBt->pageSize );
53605 usableSpace = pBt->usableSize - 12 + leafCorrection;
53683 rc = allocateBtreePage(pBt, &pNew, &pgno, pgno, 0);
53690 ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc);
53810 assert( sz<=pBt->maxLocal+23 );
53811 assert( iOvflSpace <= (int)pBt->pageSize );
53929 ptrmapPut(pBt, get4byte(apCell[i]), PTRMAP_BTREE, pNew->pgno, &rc);
53940 ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc);
53997 BtShared *pBt = pRoot->pBt; /* The BTree */
54000 assert( sqlite3_mutex_held(pBt->mutex) );
54008 rc = allocateBtreePage(pBt,&pChild,&pgnoChild,pRoot->pgno,0);
54011 ptrmapPut(pBt, pgnoChild, PTRMAP_BTREE, pRoot->pgno, &rc);
54049 const int nMin = pCur->pBt->usableSize * 2 / 3;
54128 u8 *pSpace = sqlite3PageMalloc(pCur->pBt->pageSize);
54196 BtShared *pBt = p->pBt;
54206 assert( pCur->wrFlag && pBt->inTransaction==TRANS_WRITE && !pBt->readOnly );
54234 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
54250 allocateTempSpace(pBt);
54251 newCell = pBt->pTmpSpace;
54256 assert( szNew <= MX_CELL_SIZE(pBt) );
54326 BtShared *pBt = p->pBt;
54334 assert( pBt->inTransaction==TRANS_WRITE );
54335 assert( !pBt->readOnly );
54375 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
54396 assert( MX_CELL_SIZE(pBt) >= nCell );
54398 allocateTempSpace(pBt);
54399 pTmp = pBt->pTmpSpace;
54448 BtShared *pBt = p->pBt;
54455 assert( pBt->inTransaction==TRANS_WRITE );
54456 assert( !pBt->readOnly );
54459 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
54464 if( pBt->autoVacuum ){
54473 invalidateAllOverflowCache(pBt);
54485 while( pgnoRoot==PTRMAP_PAGENO(pBt, pgnoRoot) ||
54486 pgnoRoot==PENDING_BYTE_PAGE(pBt) ){
54495 rc = allocateBtreePage(pBt, &pPageMove, &pgnoMove, pgnoRoot, 1);
54513 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
54517 rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage);
54527 rc = relocatePage(pBt, pRoot, eType, iPtrPage, pgnoMove, 0);
54534 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
54548 ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0, &rc);
54558 assert( sqlite3PagerIswriteable(pBt->pPage1->pDbPage) );
54566 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
54578 assert( (pBt->openFlags & BTREE_SINGLE)==0 || pgnoRoot==2 );
54595 BtShared *pBt, /* The BTree that contains the table */
54605 assert( sqlite3_mutex_held(pBt->mutex) );
54606 if( pgno>btreePagecount(pBt) ){
54610 rc = getAndInitPage(pBt, pgno, &pPage);
54615 rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
54622 rc = clearDatabasePage(pBt, get4byte(&pPage->aData[8]), 1, pnChange);
54654 BtShared *pBt = p->pBt;
54663 rc = saveAllCursors(pBt, (Pgno)iTable, 0);
54665 rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
54694 BtShared *pBt = p->pBt;
54707 if( NEVER(pBt->pCursor) ){
54708 sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
54712 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
54727 if( pBt->autoVacuum ){
54747 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
54751 rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0);
54757 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
54772 while( maxRootPgno==PENDING_BYTE_PAGE(pBt)
54773 || PTRMAP_ISPAGE(pBt, maxRootPgno) ){
54776 assert( maxRootPgno!=PENDING_BYTE_PAGE(pBt) );
54817 BtShared *pBt = p->pBt;
54822 assert( pBt->pPage1 );
54825 *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
54830 if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ) pBt->readOnly = 1;
54841 BtShared *pBt = p->pBt;
54847 assert( pBt->pPage1!=0 );
54848 pP1 = pBt->pPage1->aData;
54849 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
54854 assert( pBt->autoVacuum || iMeta==0 );
54856 pBt->incrVacuum = (u8)iMeta;
54939 return p->pBt->pPager;
55010 rc = ptrmapGet(pCheck->pBt, iChild, &ePtrmapType, &iPtrmapParent);
55057 if( pCheck->pBt->autoVacuum ){
55061 if( n>(int)pCheck->pBt->usableSize/4-2 ){
55069 if( pCheck->pBt->autoVacuum ){
55084 if( pCheck->pBt->autoVacuum && N>0 ){
55127 BtShared *pBt;
55138 pBt = pCheck->pBt;
55139 usableSize = pBt->usableSize;
55142 if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){
55187 && (&pCell[info.iOverflow]<=&pPage->aData[pBt->usableSize])
55192 if( pBt->autoVacuum ){
55204 if( pBt->autoVacuum ){
55221 if( pBt->autoVacuum ){
55268 hit = sqlite3PageMalloc( pBt->pageSize );
55349 BtShared *pBt = p->pBt;
55353 assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
55354 nRef = sqlite3PagerRefcount(pBt->pPager);
55355 sCheck.pBt = pBt;
55356 sCheck.pPager = pBt->pPager;
55357 sCheck.nPage = btreePagecount(sCheck.pBt);
55373 i = PENDING_BYTE_PAGE(pBt);
55382 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
55383 get4byte(&pBt->pPage1->aData[36]), "Main freelist: ");
55390 if( pBt->autoVacuum && aRoot[i]>1 ){
55409 (PTRMAP_PAGENO(pBt, i)!=i || !pBt->autoVacuum) ){
55413 (PTRMAP_PAGENO(pBt, i)==i && pBt->autoVacuum) ){
55423 if( NEVER(nRef != sqlite3PagerRefcount(pBt->pPager)) ){
55426 nRef, sqlite3PagerRefcount(pBt->pPager)
55452 assert( p->pBt->pPager!=0 );
55453 return sqlite3PagerFilename(p->pBt->pPager);
55465 assert( p->pBt->pPager!=0 );
55466 return sqlite3PagerJournalname(p->pBt->pPager);
55489 BtShared *pBt = p->pBt;
55491 if( pBt->inTransaction!=TRANS_NONE ){
55494 rc = sqlite3PagerCheckpoint(pBt->pPager, eMode, pnLog, pnCkpt);
55538 BtShared *pBt = p->pBt;
55540 if( !pBt->pSchema && nBytes ){
55541 pBt->pSchema = sqlite3DbMallocZero(0, nBytes);
55542 pBt->xFreeSchema = xFree;
55545 return pBt->pSchema;
55625 assert( !pCsr->pBt->readOnly && pCsr->pBt->inTransaction==TRANS_WRITE );
55657 BtShared *pBt = pBtree->pBt;
55666 pBt->doNotUseWAL = (u8)(iVersion==1);
55670 u8 *aData = pBt->pPage1->aData;
55674 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
55683 pBt->doNotUseWAL = 0;
55803 return pDb->aDb[i].pBt;
55918 assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) );
55955 if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt) ) continue;
56035 if( p->pDestDb && p->pSrc->pBt->inTransaction==TRANS_WRITE ){
56074 if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
56125 if( nDestTruncate==(int)PENDING_BYTE_PAGE(p->pDest->pBt) ){
56150 nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1)
56305 assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) );
56338 assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) );
56380 pTo->pBt->pageSizeFixed = 0;
58517 if( i!=1 && sqlite3BtreeSharable(p->db->aDb[i].pBt) ){
58555 if( i!=1 && (mask & p->lockMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
58556 sqlite3BtreeEnter(aDb[i].pBt);
58577 if( i!=1 && (mask & p->lockMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
58578 sqlite3BtreeLeave(aDb[i].pBt);
59116 if( pCx->pBt ){
59117 sqlite3BtreeClose(pCx->pBt);
59302 Btree *pBt = db->aDb[i].pBt;
59303 if( sqlite3BtreeIsInTrans(pBt) ){
59306 rc = sqlite3PagerExclusiveLock(sqlite3BtreePager(pBt));
59330 if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db->aDb[0].pBt))
59334 Btree *pBt = db->aDb[i].pBt;
59335 if( pBt ){
59336 rc = sqlite3BtreeCommitPhaseOne(pBt, 0);
59346 Btree *pBt = db->aDb[i].pBt;
59347 if( pBt ){
59348 rc = sqlite3BtreeCommitPhaseTwo(pBt, 0);
59365 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
59401 Btree *pBt = db->aDb[i].pBt;
59402 if( sqlite3BtreeIsInTrans(pBt) ){
59403 char const *zFile = sqlite3BtreeGetJournalname(pBt);
59408 if( !needSync && !sqlite3BtreeSyncDisabled(pBt) ){
59446 Btree *pBt = db->aDb[i].pBt;
59447 if( pBt ){
59448 rc = sqlite3BtreeCommitPhaseOne(pBt, zMaster);
59479 Btree *pBt = db->aDb[i].pBt;
59480 if( pBt ){
59481 sqlite3BtreeCommitPhaseTwo(pBt, 1);
59542 Btree *p = db->aDb[i].pBt;
59578 Btree *pBt = db->aDb[i].pBt;
59579 if( pBt ){
59581 rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_ROLLBACK, iSavepoint);
59584 rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_RELEASE, iSavepoint);
61114 Btree *pBt = db->aDb[i].pBt;
61115 if( pBt ){
61116 int nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
63053 Btree *pBt;
63066 Btree *pBt;
63263 Btree *pBt; /* Btree to change journal mode of */
63270 Btree *pBt;
65458 rc = sqlite3BtreeSavepoint(db->aDb[u.aq.ii].pBt, u.aq.p1, u.aq.iSavepoint);
65610 Btree *pBt;
65615 u.as.pBt = db->aDb[pOp->p1].pBt;
65617 if( u.as.pBt ){
65618 rc = sqlite3BtreeBeginTrans(u.as.pBt, pOp->p2);
65631 assert( sqlite3BtreeIsInTrans(u.as.pBt) );
65640 rc = sqlite3BtreeBeginStmt(u.as.pBt, p->iStatement);
65675 assert( db->aDb[u.at.iDb].pBt!=0 );
65678 sqlite3BtreeGetMeta(db->aDb[u.at.iDb].pBt, u.at.iCookie, (u32 *)&u.at.iMeta);
65701 assert( u.au.pDb->pBt!=0 );
65706 rc = sqlite3BtreeUpdateMeta(u.au.pDb->pBt, pOp->p2, (int)pIn3->u.i);
65746 Btree *pBt;
65752 u.av.pBt = db->aDb[pOp->p1].pBt;
65753 if( u.av.pBt ){
65754 sqlite3BtreeGetMeta(u.av.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.av.iMeta);
65859 u.aw.pX = u.aw.pDb->pBt;
65962 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ax.pCx->pBt,
65965 rc = sqlite3BtreeBeginTrans(u.ax.pCx->pBt, 1);
65976 rc = sqlite3BtreeCreateTable(u.ax.pCx->pBt, &pgno, BTREE_BLOBKEY);
65979 rc = sqlite3BtreeCursor(u.ax.pCx->pBt, pgno, 1,
65986 rc = sqlite3BtreeCursor(u.ax.pCx->pBt, MASTER_ROOT, 1, 0, u.ax.pCx->pCursor);
67396 rc = sqlite3BtreeDropTable(db->aDb[u.br.iDb].pBt, pOp->p1, &u.br.iMoved);
67437 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bs.nChange : 0)
67484 assert( u.bt.pDb->pBt!=0 );
67491 rc = sqlite3BtreeCreateTable(u.bt.pDb->pBt, &u.bt.pgno, u.bt.flags);
67518 assert( u.bu.iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[u.bu.iDb].pBt) );
67649 u.bv.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.bv.aRoot, u.bv.nRoot,
68176 Btree *pBt; /* Btree to change journal mode of */
68194 u.ce.pBt = db->aDb[pOp->p1].pBt;
68195 u.ce.pPager = sqlite3BtreePager(u.ce.pBt);
68244 assert( sqlite3BtreeIsInTrans(u.ce.pBt)==0 );
68246 rc = sqlite3BtreeSetVersion(u.ce.pBt, (u.ce.eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
68289 Btree *pBt;
68294 u.cf.pBt = db->aDb[pOp->p1].pBt;
68295 rc = sqlite3BtreeIncrVacuum(u.cf.pBt);
68344 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock);
68731 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
68748 Btree *pBt;
68750 pBt = db->aDb[pOp->p1].pBt;
68753 newMax = sqlite3BtreeLastPage(pBt);
68756 pOut->u.i = sqlite3BtreeMaxPageCount(pBt, newMax);
76417 assert( db->aDb[iDb].pBt!=0 );
76671 rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags);
76679 aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt);
76687 pPager = sqlite3BtreePager(aNew->pBt);
76689 sqlite3BtreeSecureDelete(aNew->pBt,
76690 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
76723 if( nKey>0 || sqlite3BtreeGetReserve(db->aDb[0].pBt)>0 ){
76744 if( db->aDb[iDb].pBt ){
76745 sqlite3BtreeClose(db->aDb[iDb].pBt);
76746 db->aDb[iDb].pBt = 0;
76796 if( pDb->pBt==0 ) continue;
76813 if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){
76818 sqlite3BtreeClose(pDb->pBt);
76819 pDb->pBt = 0;
77791 if( pDb->pBt==0 ){
80773 if( db->aDb[1].pBt==0 && !pParse->explain ){
80775 Btree *pBt;
80783 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags);
80790 db->aDb[1].pBt = pBt;
80792 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
80835 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
80858 if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zName)) ){
81536 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
81538 if( pBt ){
81539 p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaClear);
88194 if( db->aDb[1].pBt!=0 ){
88195 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){
88200 sqlite3BtreeClose(db->aDb[1].pBt);
88201 db->aDb[1].pBt = 0;
88477 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
88491 Btree *pBt = pDb->pBt;
88492 assert( pBt!=0 );
88494 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
88501 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
88516 Btree *pBt = pDb->pBt;
88518 assert( pBt!=0 );
88525 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
88528 b = sqlite3BtreeSecureDelete(pBt, b);
88590 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
88595 pPager = sqlite3BtreePager(pDb->pBt);
88649 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
88664 Pager *pPager = sqlite3BtreePager(pDb->pBt);
88685 Btree *pBt = pDb->pBt;
88686 assert( pBt!=0 );
88692 if( ALWAYS(pBt) ){
88693 auto_vacuum = sqlite3BtreeGetAutoVacuum(pBt);
88708 int rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto);
88784 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
88871 Pager *pPager = sqlite3BtreePager(pDb->pBt);
88885 Pager *pPager = sqlite3BtreePager(pDb->pBt);
89045 if( db->aDb[i].pBt==0 ) continue;
89050 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
89531 Btree *pBt;
89537 pBt = db->aDb[i].pBt;
89538 if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
89598 sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
89786 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
89821 if( pDb->pBt==0 ){
89831 sqlite3BtreeEnter(pDb->pBt);
89832 if( !sqlite3BtreeIsInReadTrans(pDb->pBt) ){
89833 rc = sqlite3BtreeBeginTrans(pDb->pBt, 0);
89859 sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]);
89894 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
89972 sqlite3BtreeCommit(pDb->pBt);
89974 sqlite3BtreeLeave(pDb->pBt);
90064 Btree *pBt = db->aDb[iDb].pBt; /* Btree database to read cookie from */
90065 if( pBt==0 ) continue;
90070 if( !sqlite3BtreeIsInReadTrans(pBt) ){
90071 rc = sqlite3BtreeBeginTrans(pBt, 0);
90082 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie);
90091 sqlite3BtreeCommit(pBt);
90180 Btree *pBt = db->aDb[i].pBt;
90181 if( pBt ){
90182 assert( sqlite3BtreeHoldsMutex(pBt) );
90183 rc = sqlite3BtreeSchemaLocked(pBt);
97046 pMain = db->aDb[0].pBt;
97075 pTemp = db->aDb[db->nDb-1].pBt;
97250 sqlite3BtreeClose(pDb->pBt);
97251 pDb->pBt = 0;
108639 Btree *pBt = db->aDb[j].pBt;
108640 if( pBt && sqlite3BtreeIsInBackup(pBt) ){
108653 if( pDb->pBt ){
108654 sqlite3BtreeClose(pDb->pBt);
108655 pDb->pBt = 0;
108739 if( db->aDb[i].pBt ){
108740 if( sqlite3BtreeIsInTrans(db->aDb[i].pBt) ){
108743 sqlite3BtreeRollback(db->aDb[i].pBt);
109391 rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt, eMode, pnLog, pnCkpt);
110098 rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
110107 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
110180 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
110587 Btree *pBtree = db->aDb[iDb].pBt;
110764 sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0);