Home | History | Annotate | Download | only in orig

Lines Matching defs:pBt

9026 SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
9028 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt);
10321 Btree *pBt; /* The B*Tree structure for this database file */
13923 Btree *pBt; /* Separate file holding temporary table */
14475 Btree *pBt = db->aDb[i].pBt;
14476 if( pBt ){
14477 Pager *pPager = sqlite3BtreePager(pBt);
14566 if( db->aDb[i].pBt ){
14567 Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt);
16816 void **pBt;
16830 pBt = (void**)&z[mem.nTitle];
16831 pHdr = (struct MemBlockHdr*)&pBt[mem.nBacktrace];
16847 memcpy(pBt, &aAddr[1], pHdr->nBacktrace*sizeof(void*));
16848 assert(pBt[0]);
16875 void **pBt;
16880 pBt = (void**)pHdr;
16881 pBt -= pHdr->nBacktraceSlots;
16897 z = (char*)pBt;
17038 void **pBt = (void**)pHdr;
17039 pBt -= pHdr->nBacktraceSlots;
17040 mem.xBacktrace((int)pHdr->iSize, pHdr->nBacktrace-1, &pBt[1]);
17051 void **pBt;
17066 pBt = (void**)pHdr;
17067 pBt -= pHdr->nBacktraceSlots;
17068 backtrace_symbols_fd(pBt, pHdr->nBacktrace, fileno(out));
50817 #define MX_CELL_SIZE(pBt) ((int)(pBt->pageSize-8))
50824 #define MX_CELL(pBt) ((pBt->pageSize-8)/6)
50866 ** stored in MemPage.pBt->mutex.
50886 BtShared *pBt; /* Pointer to BtShared that this page is part of */
50935 ** The pBt pointer itself may not be changed while there exists cursors
50942 BtShared *pBt; /* Sharable content of this btree */
50944 u8 sharable; /* True if we can share pBt with another db */
50945 u8 locked; /* True if db currently has pBt locked */
51087 ** found at self->pBt->mutex.
51091 BtShared *pBt; /* The BtShared this cursor points to */
51157 # define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt)
51174 #define PTRMAP_PAGENO(pBt, pgno) ptrmapPageno(pBt, pgno)
51176 #define PTRMAP_ISPAGE(pBt, pgno) (PTRMAP_PAGENO((pBt),(pgno))==(pgno))
51219 assert( p->pBt->inTransaction!=TRANS_NONE || p->pBt->nTransaction==0 ); \
51220 assert( p->pBt->inTransaction>=p->inTrans );
51231 #define ISAUTOVACUUM (pBt->autoVacuum)
51249 BtShared *pBt; /* The tree being checked out */
51250 Pager *pPager; /* The associated pager. Also accessible by pBt->pPager */
51279 assert( sqlite3_mutex_notheld(p->pBt->mutex) );
51282 sqlite3_mutex_enter(p->pBt->mutex);
51283 p->pBt->db = p->db;
51292 BtShared *pBt = p->pBt;
51294 assert( sqlite3_mutex_held(pBt->mutex) );
51296 assert( p->db==pBt->db );
51298 sqlite3_mutex_leave(pBt->mutex);
51323 ** Btree.pBt value. All elements of the list should belong to
51325 assert( p->pNext==0 || p->pNext->pBt>p->pBt );
51326 assert( p->pPrev==0 || p->pPrev->pBt<p->pBt );
51340 assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db );
51350 if( sqlite3_mutex_try(p->pBt->mutex)==SQLITE_OK ){
51351 p->pBt->db = p->db;
51363 assert( pLater->pNext==0 || pLater->pNext->pBt>pLater->pBt );
51399 assert( p->sharable==0 || p->locked==0 || p->db==p->pBt->db );
51400 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->pBt->mutex) );
51442 p = db->aDb[i].pBt;
51451 p = db->aDb[i].pBt;
51478 p = db->aDb[i].pBt;
51480 (p->wantToLock==0 || !sqlite3_mutex_held(p->pBt->mutex)) ){
51495 ** (2) if iDb!=1, then the mutex on db->aDb[iDb].pBt.
51507 p = db->aDb[iDb].pBt;
51525 p->pBt->db = p->db;
51530 Btree *p = db->aDb[i].pBt;
51532 p->pBt->db = p->db;
51685 Schema *pSchema = (Schema *)pBtree->pBt->pSchema;
51727 for(pLock=pBtree->pBt->pLock; pLock; pLock=pLock->pNext){
51762 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
51781 BtShared *pBt = p->pBt;
51793 assert( eLock==READ_LOCK || (p==pBt->pWriter && p->inTrans==TRANS_WRITE) );
51794 assert( eLock==READ_LOCK || pBt->inTransaction==TRANS_WRITE );
51804 if( pBt->pWriter!=p && (pBt->btsFlags & BTS_EXCLUSIVE)!=0 ){
51805 sqlite3ConnectionBlocked(p->db, pBt->pWriter->db);
51809 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
51824 assert( p==pBt->pWriter );
51825 pBt->btsFlags |= BTS_PENDING;
51853 BtShared *pBt = p->pBt;
51873 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
51890 pLock->pNext = pBt->pLock;
51891 pBt->pLock = pLock;
51917 BtShared *pBt = p->pBt;
51918 BtLock **ppIter = &pBt->pLock;
51926 assert( (pBt->btsFlags & BTS_EXCLUSIVE)==0 || pBt->pWriter==pLock->pBtree );
51939 assert( (pBt->btsFlags & BTS_PENDING)==0 || pBt->pWriter );
51940 if( pBt->pWriter==p ){
51941 pBt->pWriter = 0;
51942 pBt->btsFlags &= ~(BTS_EXCLUSIVE|BTS_PENDING);
51943 }else if( pBt->nTransaction==2 ){
51953 pBt->btsFlags &= ~BTS_PENDING;
51961 BtShared *pBt = p->pBt;
51962 if( pBt->pWriter==p ){
51964 pBt->pWriter = 0;
51965 pBt->btsFlags &= ~(BTS_EXCLUSIVE|BTS_PENDING);
51966 for(pLock=pBt->pLock; pLock; pLock=pLock->pNext){
51984 return sqlite3_mutex_held(p->pBt->mutex);
51990 ** on the shared btree structure pBt.
51996 ** on the shared btree structure pBt.
51998 static void invalidateAllOverflowCache(BtShared *pBt){
52000 assert( sqlite3_mutex_held(pBt->mutex) );
52001 for(p=pBt->pCursor; p; p=p->pNext){
52026 BtShared *pBt = pBtree->pBt;
52028 for(p=pBt->pCursor; p; p=p->pNext){
52075 static int btreeSetHasContent(BtShared *pBt, Pgno pgno){
52077 if( !pBt->pHasContent ){
52078 assert( pgno<=pBt->nPage );
52079 pBt->pHasContent = sqlite3BitvecCreate(pBt->nPage);
52080 if( !pBt->pHasContent ){
52084 if( rc==SQLITE_OK && pgno<=sqlite3BitvecSize(pBt->pHasContent) ){
52085 rc = sqlite3BitvecSet(pBt->pHasContent, pgno);
52097 static int btreeGetHasContent(BtShared *pBt, Pgno pgno){
52098 Bitvec *p = pBt->pHasContent;
52106 static void btreeClearHasContent(BtShared *pBt){
52107 sqlite3BitvecDestroy(pBt->pHasContent);
52108 pBt->pHasContent = 0;
52176 static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){
52178 assert( sqlite3_mutex_held(pBt->mutex) );
52179 assert( pExcept==0 || pExcept->pBt==pBt );
52180 for(p=pBt->pCursor; p; p=p->pNext){
52322 static Pgno ptrmapPageno(BtShared *pBt, Pgno pgno){
52325 assert( sqlite3_mutex_held(pBt->mutex) );
52327 nPagesPerMapPage = (pBt->usableSize/5)+1;
52330 if( ret==PENDING_BYTE_PAGE(pBt) ){
52346 static void ptrmapPut(BtShared *pBt, Pgno key, u8 eType, Pgno parent, int *pRC){
52355 assert( sqlite3_mutex_held(pBt->mutex) );
52357 assert( 0==PTRMAP_ISPAGE(pBt, PENDING_BYTE_PAGE(pBt)) );
52359 assert( pBt->autoVacuum );
52364 iPtrmap = PTRMAP_PAGENO(pBt, key);
52365 rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage);
52375 assert( offset <= (int)pBt->usableSize-5 );
52398 static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno){
52405 assert( sqlite3_mutex_held(pBt->mutex) );
52407 iPtrmap = PTRMAP_PAGENO(pBt, key);
52408 rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage);
52419 assert( offset <= (int)pBt->usableSize-5 );
52453 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52484 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52531 surplus = minLocal + (nPayload - minLocal)%(pPage->pBt->usableSize - 4);
52593 nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
52634 ptrmapPut(pPage->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, pRC);
52662 assert( pPage->pBt!=0 );
52663 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
52665 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52666 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
52672 usableSize = pPage->pBt->usableSize;
52746 assert( pPage->pBt );
52747 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52751 usableSize = pPage->pBt->usableSize;
52822 assert( top+nByte <= (int)pPage->pBt->usableSize );
52840 assert( pPage->pBt!=0 );
52843 assert( (start + size) <= (int)pPage->pBt->usableSize );
52844 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52847 if( pPage->pBt->btsFlags & BTS_SECURE_DELETE ){
52864 iLast = pPage->pBt->usableSize - 4;
52886 assert( pbegin <= (int)pPage->pBt->usableSize-4 );
52929 BtShared *pBt; /* A copy of pPage->pBt */
52932 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52936 pBt = pPage->pBt;
52940 pPage->maxLocal = pBt->maxLeaf;
52941 pPage->minLocal = pBt->minLeaf;
52945 pPage->maxLocal = pBt->maxLocal;
52946 pPage->minLocal = pBt->minLocal;
52950 pPage->max1bytePayload = pBt->max1bytePayload;
52965 assert( pPage->pBt!=0 );
52966 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52975 BtShared *pBt; /* The main btree structure */
52983 pBt = pPage->pBt;
52988 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
52989 pPage->maskPage = (u16)(pBt->pageSize - 1);
52991 usableSize = pBt->usableSize;
52997 if( pPage->nCell>MX_CELL(pBt) ){
53001 testcase( pPage->nCell==MX_CELL(pBt) );
53077 BtShared *pBt = pPage->pBt;
53085 assert( sqlite3_mutex_held(pBt->mutex) );
53086 if( pBt->btsFlags & BTS_SECURE_DELETE ){
53087 memset(&data[hdr], 0, pBt->usableSize - hdr);
53093 put2byte(&data[hdr+5], pBt->usableSize);
53094 pPage->nFree = (u16)(pBt->usableSize - first);
53097 pPage->aDataEnd = &data[pBt->usableSize];
53100 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
53101 pPage->maskPage = (u16)(pBt->pageSize - 1);
53111 static MemPage *btreePageFromDbPage(DbPage *pDbPage, Pgno pgno, BtShared *pBt){
53115 pPage->pBt = pBt;
53122 ** Get a page from the pager. Initialize the MemPage.pBt and
53133 BtShared *pBt, /* The btree */
53142 assert( sqlite3_mutex_held(pBt->mutex) );
53143 rc = sqlite3PagerAcquire(pBt->pPager, pgno, (DbPage**)&pDbPage, flags);
53145 *ppPage = btreePageFromDbPage(pDbPage, pgno, pBt);
53151 ** already in the pager cache return NULL. Initialize the MemPage.pBt and
53154 static MemPage *btreePageLookup(BtShared *pBt, Pgno pgno){
53156 assert( sqlite3_mutex_held(pBt->mutex) );
53157 pDbPage = sqlite3PagerLookup(pBt->pPager, pgno);
53159 return btreePageFromDbPage(pDbPage, pgno, pBt);
53168 static Pgno btreePagecount(BtShared *pBt){
53169 return pBt->nPage;
53173 assert( ((p->pBt->nPage)&0x8000000)==0 );
53174 return btreePagecount(p->pBt);
53186 BtShared *pBt, /* The database file */
53192 assert( sqlite3_mutex_held(pBt->mutex) );
53195 if( pgno>btreePagecount(pBt) ){
53198 rc = btreeGetPage(pBt, pgno, ppPage, bReadonly);
53219 assert( pPage->pBt );
53223 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53241 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53259 BtShared *pBt = (BtShared*)pArg;
53260 assert( pBt->db );
53261 assert( sqlite3_mutex_held(pBt->db->mutex) );
53262 return sqlite3InvokeBusyHandler(&pBt->db->busyHandler);
53294 BtShared *pBt = 0; /* Shared part of btree structure */
53375 for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
53376 assert( pBt->nRef>0 );
53377 if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager, 0))
53378 && sqlite3PagerVfs(pBt->pPager)==pVfs ){
53381 Btree *pExisting = db->aDb[iDb].pBt;
53382 if( pExisting && pExisting->pBt==pBt ){
53390 p->pBt = pBt;
53391 pBt->nRef++;
53410 if( pBt==0 ){
53422 pBt = sqlite3MallocZero( sizeof(*pBt) );
53423 if( pBt==0 ){
53427 rc = sqlite3PagerOpen(pVfs, &pBt->pPager, zFilename,
53430 sqlite3PagerSetMmapLimit(pBt->pPager, db->szMmap);
53431 rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
53436 pBt->openFlags = (u8)flags;
53437 pBt->db = db;
53438 sqlite3PagerSetBusyhandler(pBt->pPager, btreeInvokeBusyHandler, pBt);
53439 p->pBt = pBt;
53441 pBt->pCursor = 0;
53442 pBt->pPage1 = 0;
53443 if( sqlite3PagerIsreadonly(pBt->pPager) ) pBt->btsFlags |= BTS_READ_ONLY;
53445 pBt->btsFlags |= BTS_SECURE_DELETE;
53447 pBt->pageSize = (zDbHeader[16]<<8) | (zDbHeader[17]<<16);
53448 if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
53449 || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
53450 pBt->pageSize = 0;
53459 pBt->autoVacuum = (SQLITE_DEFAULT_AUTOVACUUM ? 1 : 0);
53460 pBt->incrVacuum = (SQLITE_DEFAULT_AUTOVACUUM==2 ? 1 : 0);
53466 pBt->btsFlags |= BTS_PAGESIZE_FIXED;
53468 pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
53469 pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0);
53472 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve);
53474 pBt->usableSize = pBt->pageSize - nReserve;
53475 assert( (pBt->pageSize & 7)==0 ); /* 8-byte alignment of pageSize */
53482 pBt->nRef = 1;
53485 pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST);
53486 if( pBt->mutex==0 ){
53493 pBt->pNext = GLOBAL(BtShared*,sqlite3SharedCacheList);
53494 GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt;
53503 ** The list is kept in ascending order by pBt address.
53509 if( (pSib = db->aDb[i].pBt)!=0 && pSib->sharable ){
53511 if( p->pBt<pSib->pBt ){
53516 while( pSib->pNext && pSib->pNext->pBt<p->pBt ){
53535 if( pBt && pBt->pPager ){
53536 sqlite3PagerClose(pBt->pPager);
53538 sqlite3_free(pBt);
53547 sqlite3PagerSetCachesize(p->pBt->pPager, SQLITE_DEFAULT_CACHE_SIZE);
53563 static int removeFromSharingList(BtShared *pBt){
53569 assert( sqlite3_mutex_notheld(pBt->mutex) );
53572 pBt->nRef--;
53573 if( pBt->nRef<=0 ){
53574 if( GLOBAL(BtShared*,sqlite3SharedCacheList)==pBt ){
53575 GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt->pNext;
53578 while( ALWAYS(pList) && pList->pNext!=pBt ){
53582 pList->pNext = pBt->pNext;
53586 sqlite3_mutex_free(pBt->mutex);
53598 ** Make sure pBt->pTmpSpace points to an allocation of
53599 ** MX_CELL_SIZE(pBt) bytes.
53601 static void allocateTempSpace(BtShared *pBt){
53602 if( !pBt->pTmpSpace ){
53603 pBt->pTmpSpace = sqlite3PageMalloc( pBt->pageSize );
53605 /* One of the uses of pBt->pTmpSpace is to format cells before
53615 if( pBt->pTmpSpace ) memset(pBt->pTmpSpace, 0, 4);
53620 ** Free the pBt->pTmpSpace allocation
53622 static void freeTempSpace(BtShared *pBt){
53623 sqlite3PageFree( pBt->pTmpSpace);
53624 pBt->pTmpSpace = 0;
53631 BtShared *pBt = p->pBt;
53637 pCur = pBt->pCursor;
53658 if( !p->sharable || removeFromSharingList(pBt) ){
53659 /* The pBt is no longer on the sharing list, so we can access
53664 assert( !pBt->pCursor );
53665 sqlite3PagerClose(pBt->pPager);
53666 if( pBt->xFreeSchema && pBt->pSchema ){
53667 pBt->xFreeSchema(pBt->pSchema);
53669 sqlite3DbFree(0, pBt->pSchema);
53670 freeTempSpace(pBt);
53671 sqlite3_free(pBt);
53701 BtShared *pBt = p->pBt;
53704 sqlite3PagerSetCachesize(pBt->pPager, mxPage);
53715 BtShared *pBt = p->pBt;
53718 sqlite3PagerSetMmapLimit(pBt->pPager, szMmap);
53737 BtShared *pBt = p->pBt;
53740 sqlite3PagerSetFlags(pBt->pPager, pgFlags);
53751 BtShared *pBt = p->pBt;
53755 assert( pBt && pBt->pPager );
53756 rc = sqlite3PagerNosync(pBt->pPager);
53783 BtShared *pBt = p->pBt;
53786 if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){
53791 nReserve = pBt->pageSize - pBt->usableSize;
53797 assert( !pBt->pPage1 && !pBt->pCursor );
53798 pBt->pageSize = (u32)pageSize;
53799 freeTempSpace(pBt);
53801 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve);
53802 pBt->usableSize = pBt->pageSize - (u16)nReserve;
53803 if( iFix ) pBt->btsFlags |= BTS_PAGESIZE_FIXED;
53812 return p->pBt->pageSize;
53828 assert( sqlite3_mutex_held(p->pBt->mutex) );
53829 return p->pBt->pageSize - p->pBt->usableSize;
53842 n = p->pBt->pageSize - p->pBt->usableSize;
53855 n = sqlite3PagerMaxPageCount(p->pBt->pPager, mxPage);
53870 p->pBt->btsFlags &= ~BTS_SECURE_DELETE;
53871 if( newFlag ) p->pBt->btsFlags |= BTS_SECURE_DELETE;
53873 b = (p->pBt->btsFlags & BTS_SECURE_DELETE)!=0;
53889 BtShared *pBt = p->pBt;
53894 if( (pBt->btsFlags & BTS_PAGESIZE_FIXED)!=0 && (av ?1:0)!=pBt->autoVacuum ){
53897 pBt->autoVacuum = av ?1:0;
53898 pBt->incrVacuum = av==2 ?1:0;
53916 (!p->pBt->autoVacuum)?BTREE_AUTOVACUUM_NONE:
53917 (!p->pBt->incrVacuum)?BTREE_AUTOVACUUM_FULL:
53935 static int lockBtree(BtShared *pBt){
53942 assert( sqlite3_mutex_held(pBt->mutex) );
53943 assert( pBt->pPage1==0 );
53944 rc = sqlite3PagerSharedLock(pBt->pPager);
53946 rc = btreeGetPage(pBt, 1, &pPage1, 0);
53953 sqlite3PagerPagecount(pBt->pPager, &nPageFile);
53968 pBt->btsFlags |= BTS_READ_ONLY;
53975 pBt->btsFlags |= BTS_READ_ONLY;
53989 if( page1[19]==2 && (pBt->btsFlags & BTS_NO_WAL)==0 ){
53991 rc = sqlite3PagerOpenWal(pBt->pPager, &isOpen);
54019 if( (u32)pageSize!=pBt->pageSize ){
54022 ** actually pageSize. Unlock the database, leave pBt->pPage1 at
54027 pBt->usableSize = usableSize;
54028 pBt->pageSize = pageSize;
54029 freeTempSpace(pBt);
54030 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
54034 if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPage>nPageFile ){
54041 pBt->pageSize = pageSize;
54042 pBt->usableSize = usableSize;
54044 pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0);
54045 pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0);
54062 pBt->maxLocal = (u16)((pBt->usableSize-12)*64/255 - 23);
54063 pBt->minLocal = (u16)((pBt->usableSize-12)*32/255 - 23);
54064 pBt->maxLeaf = (u16)(pBt->usableSize - 35);
54065 pBt->minLeaf = (u16)((pBt->usableSize-12)*32/255 - 23);
54066 if( pBt->maxLocal>127 ){
54067 pBt->max1bytePayload = 127;
54069 pBt->max1bytePayload = (u8)pBt->maxLocal;
54071 assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) );
54072 pBt->pPage1 = pPage1;
54073 pBt->nPage = nPage;
54078 pBt->pPage1 = 0;
54084 ** Return the number of cursors open on pBt. This is for use
54095 static int countValidCursors(BtShared *pBt, int wrOnly){
54098 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
54114 static void unlockBtreeIfUnused(BtShared *pBt){
54115 assert( sqlite3_mutex_held(pBt->mutex) );
54116 assert( countValidCursors(pBt,0)==0 || pBt->inTransaction>TRANS_NONE );
54117 if( pBt->inTransaction==TRANS_NONE && pBt->pPage1!=0 ){
54118 assert( pBt->pPage1->aData );
54119 assert( sqlite3PagerRefcount(pBt->pPager)==1 );
54120 assert( pBt->pPage1->aData );
54121 releasePage(pBt->pPage1);
54122 pBt->pPage1 = 0;
54127 ** If pBt points to an empty file then convert that empty file
54131 static int newDatabase(BtShared *pBt){
54136 assert( sqlite3_mutex_held(pBt->mutex) );
54137 if( pBt->nPage>0 ){
54140 pP1 = pBt->pPage1;
54147 data[16] = (u8)((pBt->pageSize>>8)&0xff);
54148 data[17] = (u8)((pBt->pageSize>>16)&0xff);
54151 assert( pBt->usableSize<=pBt->pageSize && pBt->usableSize+255>=pBt->pageSize);
54152 data[20] = (u8)(pBt->pageSize - pBt->usableSize);
54158 pBt->btsFlags |= BTS_PAGESIZE_FIXED;
54160 assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
54161 assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
54162 put4byte(&data[36 + 4*4], pBt->autoVacuum);
54163 put4byte(&data[36 + 7*4], pBt->incrVacuum);
54165 pBt->nPage = 1;
54178 p->pBt->nPage = 0;
54179 rc = newDatabase(p->pBt);
54221 BtShared *pBt = p->pBt;
54234 assert( pBt->inTransaction==TRANS_WRITE || IfNotOmitAV(pBt->bDoTruncate)==0 );
54237 if( (pBt->btsFlags & BTS_READ_ONLY)!=0 && wrflag ){
54247 if( (wrflag && pBt->inTransaction==TRANS_WRITE)
54248 || (pBt->btsFlags & BTS_PENDING)!=0
54250 pBlock = pBt->pWriter->db;
54253 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
54273 pBt->btsFlags &= ~BTS_INITIALLY_EMPTY;
54274 if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY;
54276 /* Call lockBtree() until either pBt->pPage1 is populated or
54278 ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
54280 ** file is not pBt->pageSize. In this case lockBtree() will update
54281 ** pBt->pageSize to the page-size of the file on disk.
54283 while( pBt->pPage1==0 && SQLITE_OK==(rc = lockBtree(pBt)) );
54286 if( (pBt->btsFlags & BTS_READ_ONLY)!=0 ){
54289 rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db));
54291 rc = newDatabase(pBt);
54297 unlockBtreeIfUnused(pBt);
54299 }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
54300 btreeInvokeBusyHandler(pBt) );
54304 pBt->nTransaction++;
54309 p->lock.pNext = pBt->pLock;
54310 pBt->pLock = &p->lock;
54315 if( p->inTrans>pBt->inTransaction ){
54316 pBt->inTransaction = p->inTrans;
54319 MemPage *pPage1 = pBt->pPage1;
54321 assert( !pBt->pWriter );
54322 pBt->pWriter = p;
54323 pBt->btsFlags &= ~BTS_EXCLUSIVE;
54324 if( wrflag>1 ) pBt->btsFlags |= BTS_EXCLUSIVE;
54333 if( pBt->nPage!=get4byte(&pPage1->aData[28]) ){
54336 put4byte(&pPage1->aData[28], pBt->nPage);
54349 rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
54368 BtShared *pBt = pPage->pBt;
54372 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
54386 ptrmapPut(pBt, childPgno, PTRMAP_BTREE, pgno, &rc);
54392 ptrmapPut(pBt, childPgno, PTRMAP_BTREE, pgno, &rc);
54415 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
54475 BtShared *pBt, /* Btree */
54484 Pager *pPager = pBt->pPager;
54489 assert( sqlite3_mutex_held(pBt->mutex) );
54490 assert( pDbPage->pBt==pBt );
54517 ptrmapPut(pBt, nextOvfl, PTRMAP_OVERFLOW2, iFreePage, &rc);
54529 rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0);
54541 ptrmapPut(pBt, iFreePage, eType, iPtrPage, &rc);
54567 static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg, int bCommit){
54571 assert( sqlite3_mutex_held(pBt->mutex) );
54574 if( !PTRMAP_ISPAGE(pBt, iLastPg) && iLastPg!=PENDING_BYTE_PAGE(pBt) ){
54578 nFreeList = get4byte(&pBt->pPage1->aData[36]);
54583 rc = ptrmapGet(pBt, iLastPg, &eType, &iPtrPage);
54600 rc = allocateBtreePage(pBt, &pFreePg, &iFreePg, iLastPg, BTALLOC_EXACT);
54613 rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0);
54631 rc = allocateBtreePage(pBt, &pFreePg, &iFreePg, iNear, eMode);
54640 rc = relocatePage(pBt, pLastPg, eType, iPtrPage, iFreePg, bCommit);
54651 }while( iLastPg==PENDING_BYTE_PAGE(pBt) || PTRMAP_ISPAGE(pBt, iLastPg) );
54652 pBt->bDoTruncate = 1;
54653 pBt->nPage = iLastPg;
54663 static Pgno finalDbSize(BtShared *pBt, Pgno nOrig, Pgno nFree){
54668 nEntry = pBt->usableSize/5;
54669 nPtrmap = (nFree-nOrig+PTRMAP_PAGENO(pBt, nOrig)+nEntry)/nEntry;
54671 if( nOrig>PENDING_BYTE_PAGE(pBt) && nFin<PENDING_BYTE_PAGE(pBt) ){
54674 while( PTRMAP_ISPAGE(pBt, nFin) || nFin==PENDING_BYTE_PAGE(pBt) ){
54691 BtShared *pBt = p->pBt;
54694 assert( pBt->inTransaction==TRANS_WRITE && p->inTrans==TRANS_WRITE );
54695 if( !pBt->autoVacuum ){
54698 Pgno nOrig = btreePagecount(pBt);
54699 Pgno nFree = get4byte(&pBt->pPage1->aData[36]);
54700 Pgno nFin = finalDbSize(pBt, nOrig, nFree);
54705 rc = saveAllCursors(pBt, 0, 0);
54707 invalidateAllOverflowCache(pBt);
54708 rc = incrVacuumStep(pBt, nFin, nOrig, 0);
54711 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
54712 put4byte(&pBt->pPage1->aData[28], pBt->nPage);
54731 static int autoVacuumCommit(BtShared *pBt){
54733 Pager *pPager = pBt->pPager;
54736 assert( sqlite3_mutex_held(pBt->mutex) );
54737 invalidateAllOverflowCache(pBt);
54738 assert(pBt->autoVacuum);
54739 if( !pBt->incrVacuum ){
54745 nOrig = btreePagecount(pBt);
54746 if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){
54754 nFree = get4byte(&pBt->pPage1->aData[36]);
54755 nFin = finalDbSize(pBt, nOrig, nFree);
54758 rc = saveAllCursors(pBt, 0, 0);
54761 rc = incrVacuumStep(pBt
54764 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
54765 put4byte(&pBt->pPage1->aData[32], 0);
54766 put4byte(&pBt->pPage1->aData[36], 0);
54767 put4byte(&pBt->pPage1->aData[28], nFin);
54768 pBt->bDoTruncate = 1;
54769 pBt->nPage = nFin;
54797 ** This call is a no-op if no write-transaction is currently active on pBt.
54799 ** Otherwise, sync the database file for the btree pBt. zMaster points to
54813 BtShared *pBt = p->pBt;
54816 if( pBt->autoVacuum ){
54817 rc = autoVacuumCommit(pBt);
54823 if( pBt->bDoTruncate ){
54824 sqlite3PagerTruncateImage(pBt->pPager, pBt->nPage);
54827 rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zMaster, 0);
54838 BtShared *pBt = p->pBt;
54843 pBt->bDoTruncate = 0;
54858 pBt->nTransaction--;
54859 if( 0==pBt->nTransaction ){
54860 pBt->inTransaction = TRANS_NONE;
54867 unlockBtreeIfUnused(pBt);
54910 BtShared *pBt = p->pBt;
54911 assert( pBt->inTransaction==TRANS_WRITE );
54912 assert( pBt->nTransaction>0 );
54913 rc = sqlite3PagerCommitPhaseTwo(pBt->pPager);
54918 pBt->inTransaction = TRANS_READ;
54919 btreeClearHasContent(pBt);
54962 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
54986 BtShared *pBt = p->pBt;
54991 rc = tripCode = saveAllCursors(pBt, 0, 0);
55003 assert( TRANS_WRITE==pBt->inTransaction );
55004 rc2 = sqlite3PagerRollback(pBt->pPager);
55012 if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
55015 if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
55016 testcase( pBt->nPage!=nPage );
55017 pBt->nPage = nPage;
55020 assert( countValidCursors(pBt, 1)==0 );
55021 pBt->inTransaction = TRANS_READ;
55022 btreeClearHasContent(pBt);
55050 BtShared *pBt = p->pBt;
55053 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
55056 assert( pBt->inTransaction==TRANS_WRITE );
55062 rc = sqlite3PagerOpenSavepoint(pBt->pPager, iStatement);
55082 BtShared *pBt = p->pBt;
55086 rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
55088 if( iSavepoint<0 && (pBt->btsFlags & BTS_INITIALLY_EMPTY)!=0 ){
55089 pBt->nPage = 0;
55091 rc = newDatabase(pBt);
55092 pBt->nPage = get4byte(28 + pBt->pPage1->aData);
55097 assert( pBt->nPage>0 );
55143 BtShared *pBt = p->pBt; /* Shared b-tree handle */
55158 assert( pBt->pPage1 && pBt->pPage1->aData );
55160 if( NEVER(wrFlag && (pBt->btsFlags & BTS_READ_ONLY)!=0) ){
55163 if( iTable==1 && btreePagecount(pBt)==0 ){
55174 pCur->pBt = pBt;
55177 pCur->pNext = pBt->pCursor;
55181 pBt->pCursor = pCur;
55231 BtShared *pBt = pCur->pBt;
55237 pBt->pCursor = pCur->pNext;
55245 unlockBtreeIfUnused(pBt);
55377 BtShared *pBt, /* The database file */
55386 assert( sqlite3_mutex_held(pBt->mutex) );
55396 if( pBt->autoVacuum ){
55401 while( PTRMAP_ISPAGE(pBt, iGuess) || iGuess==PENDING_BYTE_PAGE(pBt) ){
55405 if( iGuess<=btreePagecount(pBt) ){
55406 rc = ptrmapGet(pBt, iGuess, &eType, &pgno);
55417 rc = btreeGetPage(pBt, ovfl, &pPage, (ppPage==0) ? PAGER_GET_READONLY : 0);
55507 BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
55526 || &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
55547 const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */
55612 rc = getOverflowPage(pBt, nextPage, 0, &nextPage);
55644 && pBt->inTransaction==TRANS_READ /* (4) */
55645 && (fd = sqlite3PagerFile(pBt->pPager))->pMethods /* (3) */
55646 && pBt->pPage1->aData[19]==0x01 /* (5) */
55651 rc = sqlite3OsRead(fd, aWrite, a+4, (i64)pBt->pageSize*(nextPage-1));
55659 rc = sqlite3PagerAcquire(pBt->pPager, nextPage, &pDbPage,
55800 BtShared *pBt = pCur->pBt;
55809 rc = getAndInitPage(pBt, newPgno, &pNewPage,
55921 rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
56531 BtShared *pBt, /* The btree */
56545 assert( sqlite3_mutex_held(pBt->mutex) );
56546 assert( eMode==BTALLOC_ANY || (nearby>0 && IfNotOmitAV(pBt->autoVacuum)) );
56547 pPage1 = pBt->pPage1;
56548 mxPage = btreePagecount(pBt);
56568 assert( pBt->autoVacuum );
56569 rc = ptrmapGet(pBt, nearby, &eType, 0);
56603 rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
56627 }else if( k>(u32)(pBt->usableSize/4 - 2) ){
56667 rc = btreeGetPage(pBt, iNewTrunk, &pNewTrunk, 0);
56746 noContent = !btreeGetHasContent(pBt, *pPgno) ? PAGER_GET_NOCONTENT : 0;
56747 rc = btreeGetPage(pBt, *pPgno, ppPage, noContent);
56779 int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate)) ? PAGER_GET_NOCONTENT : 0;
56781 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
56783 pBt->nPage++;
56784 if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ) pBt->nPage++;
56787 if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, pBt->nPage) ){
56793 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
56794 assert( pBt->nPage!=PENDING_BYTE_PAGE(pBt) );
56795 rc = btreeGetPage(pBt, pBt->nPage, &pPg, bNoContent);
56801 pBt->nPage++;
56802 if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ){ pBt->nPage++; }
56805 put4byte(28 + (u8*)pBt->pPage1->aData, pBt->nPage);
56806 *pPgno = pBt->nPage;
56808 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
56809 rc = btreeGetPage(pBt, *pPgno, ppPage, bNoContent);
56818 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
56849 static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
56852 MemPage *pPage1 = pBt->pPage1; /* Local reference to page 1 */
56857 assert( sqlite3_mutex_held(pBt->mutex) );
56865 pPage = btreePageLookup(pBt, iPage);
56874 if( pBt->btsFlags & BTS_SECURE_DELETE ){
56878 if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) )
56883 memset(pPage->aData, 0, pPage->pBt->pageSize);
56890 ptrmapPut(pBt, iPage, PTRMAP_FREEPAGE, 0, &rc);
56905 rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
56911 assert( pBt->usableSize>32 );
56912 if( nLeaf > (u32)pBt->usableSize/4 - 2 ){
56916 if( nLeaf < (u32)pBt->usableSize/4 - 8 ){
56935 if( pPage && (pBt->btsFlags & BTS_SECURE_DELETE)==0 ){
56938 rc = btreeSetHasContent(pBt, iPage);
56951 if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0)) ){
56973 *pRC = freePage2(pPage->pBt, pPage, pPage->pgno);
56981 BtShared *pBt = pPage->pBt;
56988 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
56997 assert( pBt->usableSize > 4 );
56998 ovflPageSize = pBt->usableSize - 4;
57004 if( ovflPgno<2 || ovflPgno>btreePagecount(pBt) ){
57011 rc = getOverflowPage(pBt, ovflPgno, &pOvfl, &iNext);
57015 if( ( pOvfl || ((pOvfl = btreePageLookup(pBt, ovflPgno))!=0) )
57030 rc = freePage2(pBt, pOvfl, ovflPgno);
57070 BtShared *pBt = pPage->pBt;
57075 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
57079 assert( pCell<pPage->aData || pCell>=&pPage->aData[pBt->pageSize]
57121 if( pBt->autoVacuum ){
57125 PTRMAP_ISPAGE(pBt, pgnoOvfl) || pgnoOvfl==PENDING_BYTE_PAGE(pBt)
57129 rc = allocateBtreePage(pBt, &pOvfl, &pgnoOvfl, pgnoOvfl, 0);
57141 if( pBt->autoVacuum && rc==SQLITE_OK ){
57143 ptrmapPut(pBt, pgnoOvfl, eType, pgnoPtrmap, &rc);
57160 assert( pPrior<pPage->aData || pPrior>=&pPage->aData[pBt->pageSize]
57169 spaceLeft = pBt->usableSize - 4;
57180 assert( pPayload<pPage->aData || pPayload>=&pPage->aData[pBt->pageSize]
57224 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
57230 testcase( pc+sz==pPage->pBt->usableSize );
57231 if( pc < (u32)get2byte(&data[hdr+5]) || pc+sz > pPage->pBt->usableSize ){
57283 assert( MX_CELL(pPage->pBt)<=10921 );
57284 assert( pPage->nCell<=MX_CELL(pPage->pBt) || CORRUPT_DB );
57287 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
57322 assert( idx+sz <= (int)pPage->pBt->usableSize );
57333 if( pPage->pBt->autoVacuum ){
57358 const int nUsable = pPage->pBt->usableSize; /* Usable size of page */
57361 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
57362 assert( nCell>=0 && nCell<=(int)MX_CELL(pPage->pBt)
57363 && (int)MX_CELL(pPage->pBt)<=10921);
57426 BtShared *const pBt = pPage->pBt; /* B-Tree Database */
57431 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
57442 rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
57466 ptrmapPut(pBt, pgnoNew, PTRMAP_BTREE, pParent->pgno, &rc);
57518 BtShared *pBt = pPage->pBt;
57529 ptrmapGet(pBt, ovfl, &e, &n);
57534 ptrmapGet(pBt, child, &e, &n);
57540 ptrmapGet(pBt, child, &e, &n);
57567 BtShared * const pBt = pFrom->pBt;
57578 assert( get2byte(&aFrom[iFromHdr+5]) <= (int)pBt->usableSize );
57582 memcpy(&aTo[iData], &aFrom[iData], pBt->usableSize-iData);
57656 BtShared *pBt; /* The whole database */
57684 pBt = pParent->pBt;
57685 assert( sqlite3_mutex_held(pBt->mutex) );
57738 rc = getAndInitPage(pBt, pgno, &apOld[i], 0);
57768 if( pBt->btsFlags & BTS_SECURE_DELETE ){
57772 if( (iOff+szNew[i])>(int)pBt->usableSize ){
57792 k = pBt->pageSize + ROUND8(sizeof(MemPage));
57796 + pBt->pageSize /* aSpace1 */
57832 MemPage *pOld = apCopy[i] = (MemPage*)&aSpace1[pBt->pageSize + k*i];
57835 memcpy(pOld->aData, apOld[i]->aData, pBt->pageSize);
57863 assert( sz<=pBt->maxLocal+23 );
57864 assert( iSpace1 <= (int)pBt->pageSize );
57902 usableSpace = pBt->usableSize - 12 + leafCorrection;
57988 rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0);
57995 ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc);
58115 assert( sz<=pBt->maxLocal+23 );
58116 assert( iOvflSpace <= (int)pBt->pageSize );
58236 ptrmapPut(pBt, get4byte(apCell[i]), PTRMAP_BTREE, pNew->pgno, &rc);
58247 ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc);
58307 BtShared *pBt = pRoot->pBt; /* The BTree */
58310 assert( sqlite3_mutex_held(pBt->mutex) );
58318 rc = allocateBtreePage(pBt,&pChild,&pgnoChild,pRoot->pgno,0);
58321 ptrmapPut(pBt, pgnoChild, PTRMAP_BTREE, pRoot->pgno, &rc);
58362 const int nMin = pCur->pBt->usableSize * 2 / 3;
58441 u8 *pSpace = sqlite3PageMalloc(pCur->pBt->pageSize);
58509 BtShared *pBt = p->pBt;
58519 assert( (pCur->curFlags & BTCF_WriteFlag)!=0 && pBt->inTransaction==TRANS_WRITE
58520 && (pBt->btsFlags & BTS_READ_ONLY)==0 );
58541 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
58571 allocateTempSpace(pBt);
58572 newCell = pBt->pTmpSpace;
58577 assert( szNew <= MX_CELL_SIZE(pBt) );
58647 BtShared *pBt = p->pBt;
58655 assert( pBt->inTransaction==TRANS_WRITE );
58656 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
58690 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
58718 assert( MX_CELL_SIZE(pBt) >= nCell );
58720 allocateTempSpace(pBt);
58721 pTmp = pBt->pTmpSpace;
58770 BtShared *pBt = p->pBt;
58777 assert( pBt->inTransaction==TRANS_WRITE );
58778 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
58781 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
58786 if( pBt->autoVacuum ){
58795 invalidateAllOverflowCache(pBt);
58807 while( pgnoRoot==PTRMAP_PAGENO(pBt, pgnoRoot) ||
58808 pgnoRoot==PENDING_BYTE_PAGE(pBt) ){
58817 rc = allocateBtreePage(pBt, &pPageMove, &pgnoMove, pgnoRoot, BTALLOC_EXACT);
58835 rc = saveAllCursors(pBt, 0, 0);
58842 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
58846 rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage);
58856 rc = relocatePage(pBt, pRoot, eType, iPtrPage, pgnoMove, 0);
58863 rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
58877 ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0, &rc);
58887 assert( sqlite3PagerIswriteable(pBt->pPage1->pDbPage) );
58895 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
58907 assert( (pBt->openFlags & BTREE_SINGLE)==0 || pgnoRoot==2 );
58924 BtShared *pBt, /* The BTree that contains the table */
58935 assert( sqlite3_mutex_held(pBt->mutex) );
58936 if( pgno>btreePagecount(pBt) ){
58940 rc = getAndInitPage(pBt, pgno, &pPage, 0);
58946 rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
58953 rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
58985 BtShared *pBt = p->pBt;
58989 rc = saveAllCursors(pBt, (Pgno)iTable, 0);
58996 rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
59034 BtShared *pBt = p->pBt;
59047 if( NEVER(pBt->pCursor) ){
59048 sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
59052 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
59067 if( pBt->autoVacuum ){
59087 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
59091 rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0);
59097 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
59112 while( maxRootPgno==PENDING_BYTE_PAGE(pBt)
59113 || PTRMAP_ISPAGE(pBt, maxRootPgno) ){
59116 assert( maxRootPgno!=PENDING_BYTE_PAGE(pBt) );
59157 BtShared *pBt = p->pBt;
59162 assert( pBt->pPage1 );
59165 *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
59171 pBt->btsFlags |= BTS_READ_ONLY;
59183 BtShared *pBt = p->pBt;
59189 assert( pBt->pPage1!=0 );
59190 pP1 = pBt->pPage1->aData;
59191 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
59196 assert( pBt->autoVacuum || iMeta==0 );
59198 pBt->incrVacuum = (u8)iMeta;
59286 return p->pBt->pPager;
59377 rc = ptrmapGet(pCheck->pBt, iChild, &ePtrmapType, &iPtrmapParent);
59424 if( pCheck->pBt->autoVacuum ){
59428 if( n>(int)pCheck->pBt->usableSize/4-2 ){
59436 if( pCheck->pBt->autoVacuum ){
59451 if( pCheck->pBt->autoVacuum && N>0 ){
59494 BtShared *pBt;
59505 pBt = pCheck->pBt;
59506 usableSize = pBt->usableSize;
59509 if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){
59554 && (&pCell[info.iOverflow]<=&pPage->aData[pBt->usableSize])
59559 if( pBt->autoVacuum ){
59571 if( pBt->autoVacuum ){
59588 if( pBt->autoVacuum ){
59635 hit = sqlite3PageMalloc( pBt->pageSize );
59716 BtShared *pBt = p->pBt;
59720 assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
59721 nRef = sqlite3PagerRefcount(pBt->pPager);
59722 sCheck.pBt = pBt;
59723 sCheck.pPager = pBt->pPager;
59724 sCheck.nPage = btreePagecount(sCheck.pBt);
59740 i = PENDING_BYTE_PAGE(pBt);
59747 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
59748 get4byte(&pBt->pPage1->aData[36]), "Main freelist: ");
59755 if( pBt->autoVacuum && aRoot[i]>1 ){
59774 (PTRMAP_PAGENO(pBt, i)!=i || !pBt->autoVacuum) ){
59778 (PTRMAP_PAGENO(pBt, i)==i && pBt->autoVacuum) ){
59788 if( NEVER(nRef != sqlite3PagerRefcount(pBt->pPager)) ){
59791 nRef, sqlite3PagerRefcount(pBt->pPager)
59818 assert( p->pBt->pPager!=0 );
59819 return sqlite3PagerFilename(p->pBt->pPager, 1);
59831 assert( p->pBt->pPager!=0 );
59832 return sqlite3PagerJournalname(p->pBt->pPager);
59855 BtShared *pBt = p->pBt;
59857 if( pBt->inTransaction!=TRANS_NONE ){
59860 rc = sqlite3PagerCheckpoint(pBt->pPager, eMode, pnLog, pnCkpt);
59904 BtShared *pBt = p->pBt;
59906 if( !pBt->pSchema && nBytes ){
59907 pBt->pSchema = sqlite3DbMallocZero(0, nBytes);
59908 pBt->xFreeSchema = xFree;
59911 return pBt->pSchema;
59989 VVA_ONLY(rc =) saveAllCursors(pCsr->pBt, pCsr->pgnoRoot, pCsr);
60002 assert( (pCsr->pBt->btsFlags & BTS_READ_ONLY)==0
60003 && pCsr->pBt->inTransaction==TRANS_WRITE );
60025 BtShared *pBt = pBtree->pBt;
60033 pBt->btsFlags &= ~BTS_NO_WAL;
60034 if( iVersion==1 ) pBt->btsFlags |= BTS_NO_WAL;
60038 u8 *aData = pBt->pPage1->aData;
60042 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
60051 pBt->btsFlags &= ~BTS_NO_WAL;
60068 return (p->pBt->btsFlags & BTS_READ_ONLY)!=0;
60182 return pDb->aDb[i].pBt;
60304 assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) );
60341 if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt) ) continue;
60424 if( p->pDestDb && p->pSrc->pBt->inTransaction==TRANS_WRITE ){
60463 if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
60524 if( nDestTruncate==(int)PENDING_BYTE_PAGE(p->pDest->pBt) ){
60552 nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1)
60564 if( iPg!=PENDING_BYTE_PAGE(p->pDest->pBt) ){
60722 assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) );
60755 assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) );
60807 pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
63346 if( i!=1 && sqlite3BtreeSharable(p->db->aDb[i].pBt) ){
63383 if( i!=1 && DbMaskTest(p->lockMask,i) && ALWAYS(aDb[i].pBt!=0) ){
63384 sqlite3BtreeEnter(aDb[i].pBt);
63404 if( i!=1 && DbMaskTest(p->lockMask,i) && ALWAYS(aDb[i].pBt!=0) ){
63405 sqlite3BtreeLeave(aDb[i].pBt);
63955 if( pCx->pBt ){
63956 sqlite3BtreeClose(pCx->pBt);
64149 Btree *pBt = db->aDb[i].pBt;
64150 if( sqlite3BtreeIsInTrans(pBt) ){
64153 sqlite3BtreeEnter(pBt);
64154 rc = sqlite3PagerExclusiveLock(sqlite3BtreePager(pBt));
64155 sqlite3BtreeLeave(pBt);
64179 if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db->aDb[0].pBt))
64183 Btree *pBt = db->aDb[i].pBt;
64184 if( pBt ){
64185 rc = sqlite3BtreeCommitPhaseOne(pBt, 0);
64195 Btree *pBt = db->aDb[i].pBt;
64196 if( pBt ){
64197 rc = sqlite3BtreeCommitPhaseTwo(pBt, 0);
64214 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
64265 Btree *pBt = db->aDb[i].pBt;
64266 if( sqlite3BtreeIsInTrans(pBt) ){
64267 char const *zFile = sqlite3BtreeGetJournalname(pBt);
64272 if( !needSync && !sqlite3BtreeSyncDisabled(pBt) ){
64310 Btree *pBt = db->aDb[i].pBt;
64311 if( pBt ){
64312 rc = sqlite3BtreeCommitPhaseOne(pBt, zMaster);
64343 Btree *pBt = db->aDb[i].pBt;
64344 if( pBt ){
64345 sqlite3BtreeCommitPhaseTwo(pBt, 1);
64419 Btree *pBt = db->aDb[i].pBt;
64420 if( pBt ){
64422 rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_ROLLBACK, iSavepoint);
64425 rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_RELEASE, iSavepoint);
66597 Btree *pBt = db->aDb[i].pBt;
66598 if( pBt ){
66599 int nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
70879 sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT);
70883 rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
71040 Btree *pBt;
71052 pBt = db->aDb[pOp->p1].pBt;
71054 if( pBt ){
71055 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
71068 assert( sqlite3BtreeIsInTrans(pBt) );
71077 rc = sqlite3BtreeBeginStmt(pBt, p->iStatement);
71088 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
71141 assert( db->aDb[iDb].pBt!=0 );
71144 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
71166 assert( pDb->pBt!=0 );
71171 rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, (int)pIn3->u.i);
71296 pX = pDb->pBt;
71400 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt,
71403 rc = sqlite3BtreeBeginTrans(pCx->pBt, 1);
71414 rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
71420 rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, pKeyInfo, pCx->pCursor);
71424 rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, pCx->pCursor);
72962 rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
73002 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
73073 assert( pDb->pBt!=0 );
73080 rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags);
73105 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
73239 z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
73776 Btree *pBt; /* Btree to change journal mode of */
73777 Pager *pPager; /* Pager associated with pBt */
73796 pBt = db->aDb[pOp->p1].pBt;
73797 pPager = sqlite3BtreePager(pBt);
73846 assert( sqlite3BtreeIsInTrans(pBt)==0 );
73848 rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
73891 Btree *pBt;
73896 pBt = db->aDb[pOp->p1].pBt;
73897 rc = sqlite3BtreeIncrVacuum(pBt);
73949 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock);
74333 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
74350 Btree *pBt;
74352 pBt = db->aDb[pOp->p1].pBt;
74355 newMax = sqlite3BtreeLastPage(pBt);
74358 pOut->u.i = sqlite3BtreeMaxPageCount(pBt, newMax);
75326 nBuf = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
75471 assert( pCsr->pKeyInfo && pCsr->pBt==0 );
75482 pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
75639 int nBuf = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
85214 assert( db->aDb[iDb].pBt!=0 );
85401 rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags);
85409 aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt);
85417 pPager = sqlite3BtreePager(aNew->pBt);
85419 sqlite3BtreeSecureDelete(aNew->pBt,
85420 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
85422 sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK));
85456 if( nKey>0 || sqlite3BtreeGetReserve(db->aDb[0].pBt)>0 ){
85477 if( db->aDb[iDb].pBt ){
85478 sqlite3BtreeClose(db->aDb[iDb].pBt);
85479 db->aDb[iDb].pBt = 0;
85529 if( pDb->pBt==0 ) continue;
85546 if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){
85551 sqlite3BtreeClose(pDb->pBt);
85552 pDb->pBt = 0;
86546 if( pDb->pBt==0 ){
87416 && !sqlite3BtreeIsReadonly(db->aDb[db->init.iDb].pBt)
89840 /* if( db->aDb[0].pBt==0 ) return; */
89915 if( db->aDb[1].pBt==0 && !pParse->explain ){
89917 Btree *pBt;
89925 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags);
89932 db->aDb[1].pBt = pBt;
89934 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
89953 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
89974 if( pDb->pBt && (!zDb || 0==sqlite3StrICmp(zDb, pDb->zName)) ){
90813 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
90815 if( pBt ){
90816 p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaClear);
98770 if( db->aDb[1].pBt!=0 ){
98771 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){
98776 sqlite3BtreeClose(db->aDb[1].pBt);
98777 db->aDb[1].pBt = 0;
98835 if( pDb->pBt ){
98836 sqlite3BtreeSetPagerFlags(pDb->pBt,
99057 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
99074 Btree *pBt = pDb->pBt;
99075 assert( pBt!=0 );
99077 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
99084 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
99100 Btree *pBt = pDb->pBt;
99102 assert( pBt!=0 );
99109 pBt, b);
99112 b = sqlite3BtreeSecureDelete(pBt, b);
99178 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
99183 pPager = sqlite3BtreePager(pDb->pBt);
99233 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
99249 Pager *pPager = sqlite3BtreePager(pDb->pBt);
99271 Btree *pBt = pDb->pBt;
99272 assert( pBt!=0 );
99274 returnSingleInt(pParse, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt));
99284 rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto);
99355 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
99384 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
99385 sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz);
99526 Pager *pPager = sqlite3BtreePager(pDb->pBt);
99540 Pager *pPager = sqlite3BtreePager(pDb->pBt);
99763 if( db->aDb[i].pBt==0 ) continue;
99768 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
100491 Btree *pBt;
100496 pBt = db->aDb[i].pBt;
100497 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
100740 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
100775 if( pDb->pBt==0 ){
100785 sqlite3BtreeEnter(pDb->pBt);
100786 if( !sqlite3BtreeIsInReadTrans(pDb->pBt) ){
100787 rc = sqlite3BtreeBeginTrans(pDb->pBt, 0);
100813 sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]);
100855 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
100933 sqlite3BtreeCommit(pDb->pBt);
100935 sqlite3BtreeLeave(pDb->pBt);
101025 Btree *pBt = db->aDb[iDb].pBt; /* Btree database to read cookie from */
101026 if( pBt==0 ) continue;
101031 if( !sqlite3BtreeIsInReadTrans(pBt) ){
101032 rc = sqlite3BtreeBeginTrans(pBt, 0);
101043 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie);
101052 sqlite3BtreeCommit(pBt);
101152 Btree *pBt = db->aDb[i].pBt;
101153 if( pBt ){
101154 assert( sqlite3BtreeHoldsMutex(pBt) );
101155 rc = sqlite3BtreeSchemaLocked(pBt);
109109 pMain = db->aDb[0].pBt;
109138 pTemp = db->aDb[db->nDb-1].pBt;
109316 sqlite3BtreeClose(pDb->pBt);
109317 pDb->pBt = 0;
122770 Btree *pBt = db->aDb[i].pBt;
122771 if( pBt ){
122772 Pager *pPager = sqlite3BtreePager(pBt);
122981 Btree *pBt = db->aDb[j].pBt;
122982 if( pBt && sqlite3BtreeIsInBackup(pBt) ) return 1;
123089 if( pDb->pBt ){
123090 sqlite3BtreeClose(pDb->pBt);
123091 pDb->pBt = 0;
123191 Btree *p = db->aDb[i].pBt;
123970 rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt, eMode, pnLog, pnCkpt);
124134 if( pDb->pBt==0 ) continue;
124135 sqlite3BtreeEnter(pDb->pBt);
124145 sqlite3BtreeLeave(pDb->pBt);
124713 rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
124722 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
124796 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
125418 sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0);
125597 if( db->aDb[i].pBt
125600 return db->aDb[i].pBt;
125611 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
125612 return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
125620 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
125621 return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;