Lines Matching refs:pBt
365 Btree *pBt; /* The Btree to which this cursor belongs */ member
405 static int cellSize(Btree *pBt, Cell *pCell){ in cellSize() argument
406 int n = NKEY(pBt, pCell->h) + NDATA(pBt, pCell->h); in cellSize()
421 static void defragmentPage(Btree *pBt, MemPage *pPage){ in defragmentPage() argument
429 pPage->u.hdr.firstCell = SWAB16(pBt, pc); in defragmentPage()
439 n = cellSize(pBt, pCell); in defragmentPage()
440 pCell->h.iNext = SWAB16(pBt, pc + n); in defragmentPage()
451 pFBlk->iSize = SWAB16(pBt, SQLITE_USABLE_SIZE - pc); in defragmentPage()
453 pPage->u.hdr.firstFree = SWAB16(pBt, pc); in defragmentPage()
470 static int allocateSpace(Btree *pBt, MemPage *pPage, int nByte){ in allocateSpace() argument
484 p = (FreeBlk*)&pPage->u.aDisk[SWAB16(pBt, *pIdx)]; in allocateSpace()
485 while( (iSize = SWAB16(pBt, p->iSize))<nByte ){ in allocateSpace()
488 defragmentPage(pBt, pPage); in allocateSpace()
493 p = (FreeBlk*)&pPage->u.aDisk[SWAB16(pBt, *pIdx)]; in allocateSpace()
496 start = SWAB16(pBt, *pIdx); in allocateSpace()
500 start = SWAB16(pBt, *pIdx); in allocateSpace()
503 pNew->iSize = SWAB16(pBt, iSize - nByte); in allocateSpace()
504 *pIdx = SWAB16(pBt, start + nByte); in allocateSpace()
519 static void freeSpace(Btree *pBt, MemPage *pPage, int start, int size){ in freeSpace() argument
532 idx = SWAB16(pBt, *pIdx); in freeSpace()
535 iSize = SWAB16(pBt, pFBlk->iSize); in freeSpace()
537 pFBlk->iSize = SWAB16(pBt, iSize + size); in freeSpace()
538 if( idx + iSize + size == SWAB16(pBt, pFBlk->iNext) ){ in freeSpace()
540 if( pBt->needSwab ){ in freeSpace()
551 idx = SWAB16(pBt, *pIdx); in freeSpace()
555 pNew->iSize = SWAB16(pBt, size); in freeSpace()
556 pNew->iNext = SWAB16(pBt, idx); in freeSpace()
559 pNew->iSize = SWAB16(pBt, size + SWAB16(pBt, pNext->iSize)); in freeSpace()
562 *pIdx = SWAB16(pBt, start); in freeSpace()
580 static int initPage(Bt *pBt, MemPage *pPage, Pgno pgnoThis, MemPage *pParent){ in initPage() argument
599 idx = SWAB16(pBt, pPage->u.hdr.firstCell); in initPage()
605 sz = cellSize(pBt, pCell); in initPage()
609 idx = SWAB16(pBt, pCell->h.iNext); in initPage()
612 idx = SWAB16(pBt, pPage->u.hdr.firstFree); in initPage()
618 pPage->nFree += SWAB16(pBt, pFBlk->iSize); in initPage()
619 iNext = SWAB16(pBt, pFBlk->iNext); in initPage()
639 static void zeroPage(Btree *pBt, MemPage *pPage){ in zeroPage() argument
646 pHdr->firstFree = SWAB16(pBt, sizeof(*pHdr)); in zeroPage()
650 pFBlk->iSize = SWAB16(pBt, pPage->nFree); in zeroPage()
686 Btree *pBt; in sqliteBtreeOpen() local
705 pBt = sqliteMalloc( sizeof(*pBt) ); in sqliteBtreeOpen()
706 if( pBt==0 ){ in sqliteBtreeOpen()
711 rc = sqlitepager_open(&pBt->pPager, zFilename, nCache, EXTRA_SIZE, in sqliteBtreeOpen()
714 if( pBt->pPager ) sqlitepager_close(pBt->pPager); in sqliteBtreeOpen()
715 sqliteFree(pBt); in sqliteBtreeOpen()
719 sqlitepager_set_destructor(pBt->pPager, pageDestructor); in sqliteBtreeOpen()
720 pBt->pCursor = 0; in sqliteBtreeOpen()
721 pBt->page1 = 0; in sqliteBtreeOpen()
722 pBt->readOnly = sqlitepager_isreadonly(pBt->pPager); in sqliteBtreeOpen()
723 pBt->pOps = &sqliteBtreeOps; in sqliteBtreeOpen()
724 *ppBtree = pBt; in sqliteBtreeOpen()
731 static int fileBtreeClose(Btree *pBt){ in fileBtreeClose() argument
732 while( pBt->pCursor ){ in fileBtreeClose()
733 fileBtreeCloseCursor(pBt->pCursor); in fileBtreeClose()
735 sqlitepager_close(pBt->pPager); in fileBtreeClose()
736 sqliteFree(pBt); in fileBtreeClose()
755 static int fileBtreeSetCacheSize(Btree *pBt, int mxPage){ in fileBtreeSetCacheSize() argument
756 sqlitepager_set_cachesize(pBt->pPager, mxPage); in fileBtreeSetCacheSize()
768 static int fileBtreeSetSafetyLevel(Btree *pBt, int level){ in fileBtreeSetSafetyLevel() argument
769 sqlitepager_set_safety_level(pBt->pPager, level); in fileBtreeSetSafetyLevel()
783 static int lockBtree(Btree *pBt){ in lockBtree() argument
785 if( pBt->page1 ) return SQLITE_OK; in lockBtree()
786 rc = sqlitepager_get(pBt->pPager, 1, (void**)&pBt->page1); in lockBtree()
792 if( sqlitepager_pagecount(pBt->pPager)>0 ){ in lockBtree()
793 PageOne *pP1 = pBt->page1; in lockBtree()
799 pBt->needSwab = pP1->iMagic!=MAGIC; in lockBtree()
804 sqlitepager_unref(pBt->page1); in lockBtree()
805 pBt->page1 = 0; in lockBtree()
819 static void unlockBtreeIfUnused(Btree *pBt){ in unlockBtreeIfUnused() argument
820 if( pBt->inTrans==0 && pBt->pCursor==0 && pBt->page1!=0 ){ in unlockBtreeIfUnused()
821 sqlitepager_unref(pBt->page1); in unlockBtreeIfUnused()
822 pBt->page1 = 0; in unlockBtreeIfUnused()
823 pBt->inTrans = 0; in unlockBtreeIfUnused()
824 pBt->inCkpt = 0; in unlockBtreeIfUnused()
832 static int newDatabase(Btree *pBt){ in newDatabase() argument
836 if( sqlitepager_pagecount(pBt->pPager)>1 ) return SQLITE_OK; in newDatabase()
837 pP1 = pBt->page1; in newDatabase()
838 rc = sqlitepager_write(pBt->page1); in newDatabase()
840 rc = sqlitepager_get(pBt->pPager, 2, (void**)&pRoot); in newDatabase()
850 pBt->needSwab = 0; in newDatabase()
853 pBt->needSwab = 1; in newDatabase()
855 zeroPage(pBt, pRoot); in newDatabase()
875 static int fileBtreeBeginTrans(Btree *pBt){ in fileBtreeBeginTrans() argument
877 if( pBt->inTrans ) return SQLITE_ERROR; in fileBtreeBeginTrans()
878 if( pBt->readOnly ) return SQLITE_READONLY; in fileBtreeBeginTrans()
879 if( pBt->page1==0 ){ in fileBtreeBeginTrans()
880 rc = lockBtree(pBt); in fileBtreeBeginTrans()
885 rc = sqlitepager_begin(pBt->page1); in fileBtreeBeginTrans()
887 rc = newDatabase(pBt); in fileBtreeBeginTrans()
890 pBt->inTrans = 1; in fileBtreeBeginTrans()
891 pBt->inCkpt = 0; in fileBtreeBeginTrans()
893 unlockBtreeIfUnused(pBt); in fileBtreeBeginTrans()
904 static int fileBtreeCommit(Btree *pBt){ in fileBtreeCommit() argument
906 rc = pBt->readOnly ? SQLITE_OK : sqlitepager_commit(pBt->pPager); in fileBtreeCommit()
907 pBt->inTrans = 0; in fileBtreeCommit()
908 pBt->inCkpt = 0; in fileBtreeCommit()
909 unlockBtreeIfUnused(pBt); in fileBtreeCommit()
922 static int fileBtreeRollback(Btree *pBt){ in fileBtreeRollback() argument
925 if( pBt->inTrans==0 ) return SQLITE_OK; in fileBtreeRollback()
926 pBt->inTrans = 0; in fileBtreeRollback()
927 pBt->inCkpt = 0; in fileBtreeRollback()
928 rc = pBt->readOnly ? SQLITE_OK : sqlitepager_rollback(pBt->pPager); in fileBtreeRollback()
929 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){ in fileBtreeRollback()
935 unlockBtreeIfUnused(pBt); in fileBtreeRollback()
949 static int fileBtreeBeginCkpt(Btree *pBt){ in fileBtreeBeginCkpt() argument
951 if( !pBt->inTrans || pBt->inCkpt ){ in fileBtreeBeginCkpt()
952 return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR; in fileBtreeBeginCkpt()
954 rc = pBt->readOnly ? SQLITE_OK : sqlitepager_ckpt_begin(pBt->pPager); in fileBtreeBeginCkpt()
955 pBt->inCkpt = 1; in fileBtreeBeginCkpt()
964 static int fileBtreeCommitCkpt(Btree *pBt){ in fileBtreeCommitCkpt() argument
966 if( pBt->inCkpt && !pBt->readOnly ){ in fileBtreeCommitCkpt()
967 rc = sqlitepager_ckpt_commit(pBt->pPager); in fileBtreeCommitCkpt()
971 pBt->inCkpt = 0; in fileBtreeCommitCkpt()
983 static int fileBtreeRollbackCkpt(Btree *pBt){ in fileBtreeRollbackCkpt() argument
986 if( pBt->inCkpt==0 || pBt->readOnly ) return SQLITE_OK; in fileBtreeRollbackCkpt()
987 rc = sqlitepager_ckpt_rollback(pBt->pPager); in fileBtreeRollbackCkpt()
988 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){ in fileBtreeRollbackCkpt()
994 pBt->inCkpt = 0; in fileBtreeRollbackCkpt()
1035 int fileBtreeCursor(Btree *pBt, int iTable, int wrFlag, BtCursor **ppCur){ in fileBtreeCursor() argument
1039 if( pBt->readOnly && wrFlag ){ in fileBtreeCursor()
1043 if( pBt->page1==0 ){ in fileBtreeCursor()
1044 rc = lockBtree(pBt); in fileBtreeCursor()
1056 rc = sqlitepager_get(pBt->pPager, pCur->pgnoRoot, (void**)&pCur->pPage); in fileBtreeCursor()
1060 rc = initPage(pBt, pCur->pPage, pCur->pgnoRoot, 0); in fileBtreeCursor()
1065 pCur->pBt = pBt; in fileBtreeCursor()
1069 pCur->pNext = pBt->pCursor; in fileBtreeCursor()
1074 pRing = pBt->pCursor; in fileBtreeCursor()
1082 pBt->pCursor = pCur; in fileBtreeCursor()
1092 unlockBtreeIfUnused(pBt); in fileBtreeCursor()
1101 Btree *pBt = pCur->pBt; in fileBtreeCloseCursor() local
1105 pBt->pCursor = pCur->pNext; in fileBtreeCloseCursor()
1118 unlockBtreeIfUnused(pBt); in fileBtreeCloseCursor()
1163 *pSize = NKEY(pCur->pBt, pCell->h); in fileBtreeKeySize()
1180 Btree *pBt = pCur->pBt; in getPayload() local
1200 nextPage = SWAB32(pBt, pCur->pPage->apCell[pCur->idx]->ovfl); in getPayload()
1204 rc = sqlitepager_get(pBt->pPager, nextPage, (void**)&pOvfl); in getPayload()
1208 nextPage = SWAB32(pBt, pOvfl->iNext); in getPayload()
1252 assert( amt+offset <= NKEY(pCur->pBt, pPage->apCell[pCur->idx]->h) ); in fileBtreeKey()
1274 *pSize = NDATA(pCur->pBt, pCell->h); in fileBtreeDataSize()
1299 assert( amt+offset <= NDATA(pCur->pBt, pCell->h) ); in fileBtreeData()
1300 getPayload(pCur, offset + NKEY(pCur->pBt, pCell->h), amt, zBuf); in fileBtreeData()
1335 Btree *pBt = pCur->pBt; in fileBtreeKeyCompare() local
1341 nLocal = NKEY(pBt, pCell->h) - nIgnore; in fileBtreeKeyCompare()
1355 nextPage = SWAB32(pBt, pCell->ovfl); in fileBtreeKeyCompare()
1361 rc = sqlitepager_get(pBt->pPager, nextPage, (void**)&pOvfl); in fileBtreeKeyCompare()
1365 nextPage = SWAB32(pBt, pOvfl->iNext); in fileBtreeKeyCompare()
1394 Btree *pBt = pCur->pBt; in moveToChild() local
1396 newPgno = SWAB32(pBt, newPgno); in moveToChild()
1397 rc = sqlitepager_get(pBt->pPager, newPgno, (void**)&pNewPage); in moveToChild()
1399 rc = initPage(pBt, pNewPage, newPgno, pCur->pPage); in moveToChild()
1402 || pCur->pPage->apCell[pCur->idx]->h.leftChild==SWAB32(pBt,newPgno) ); in moveToChild()
1404 || pCur->pPage->u.hdr.rightChild==SWAB32(pBt,newPgno) ); in moveToChild()
1444 oldPgno = SWAB32(pCur->pBt, sqlitepager_pagenumber(pPage)); in moveToParent()
1459 oldPgno = SWAB32(pCur->pBt, sqlitepager_pagenumber(pPage)); in moveToParent()
1475 Btree *pBt = pCur->pBt; in moveToRoot() local
1477 rc = sqlitepager_get(pBt->pPager, pCur->pgnoRoot, (void**)&pNew); in moveToRoot()
1479 rc = initPage(pBt, pNew, pCur->pgnoRoot, 0); in moveToRoot()
1752 static int allocatePage(Btree *pBt, MemPage **ppPage, Pgno *pPgno, Pgno nearby){ in allocatePage() argument
1753 PageOne *pPage1 = pBt->page1; in allocatePage()
1761 SWAB_ADD(pBt, pPage1->nFree, -1); in allocatePage()
1762 rc = sqlitepager_get(pBt->pPager, SWAB32(pBt, pPage1->freeList), in allocatePage()
1772 *pPgno = SWAB32(pBt, pPage1->freeList); in allocatePage()
1777 n = SWAB32(pBt, pInfo->nFree); in allocatePage()
1781 dist = SWAB32(pBt, pInfo->aFree[0]) - nearby; in allocatePage()
1784 int d2 = SWAB32(pBt, pInfo->aFree[i]) - nearby; in allocatePage()
1791 SWAB_ADD(pBt, pInfo->nFree, -1); in allocatePage()
1792 *pPgno = SWAB32(pBt, pInfo->aFree[closest]); in allocatePage()
1794 rc = sqlitepager_get(pBt->pPager, *pPgno, (void**)ppPage); in allocatePage()
1802 *pPgno = sqlitepager_pagecount(pBt->pPager) + 1; in allocatePage()
1803 rc = sqlitepager_get(pBt->pPager, *pPgno, (void**)ppPage); in allocatePage()
1816 static int freePage(Btree *pBt, void *pPage, Pgno pgno){ in freePage() argument
1817 PageOne *pPage1 = pBt->page1; in freePage()
1839 SWAB_ADD(pBt, pPage1->nFree, 1); in freePage()
1842 rc = sqlitepager_get(pBt->pPager, SWAB32(pBt, pPage1->freeList), in freePage()
1846 int n = SWAB32(pBt, pInfo->nFree); in freePage()
1850 pInfo->aFree[n] = SWAB32(pBt, pgno); in freePage()
1851 SWAB_ADD(pBt, pInfo->nFree, 1); in freePage()
1853 sqlitepager_dont_write(pBt->pPager, pgno); in freePage()
1862 rc = sqlitepager_get(pBt->pPager, pgno, (void**)&pOvfl); in freePage()
1872 pPage1->freeList = SWAB32(pBt, pgno); in freePage()
1882 static int clearCell(Btree *pBt, Cell *pCell){ in clearCell() argument
1883 Pager *pPager = pBt->pPager; in clearCell()
1888 if( NKEY(pBt, pCell->h) + NDATA(pBt, pCell->h) <= MX_LOCAL_PAYLOAD ){ in clearCell()
1891 ovfl = SWAB32(pBt, pCell->ovfl); in clearCell()
1896 nextOvfl = SWAB32(pBt, pOvfl->iNext); in clearCell()
1897 rc = freePage(pBt, pOvfl, ovfl); in clearCell()
1910 Btree *pBt, /* The whole Btree. Needed to allocate pages */ in fillInCell() argument
1925 pCell->h.nKey = SWAB16(pBt, nKey & 0xffff); in fillInCell()
1927 pCell->h.nData = SWAB16(pBt, nData & 0xffff); in fillInCell()
1940 rc = allocatePage(pBt, (MemPage**)&pOvfl, pNext, nearby); in fillInCell()
1948 clearCell(pBt, pCell); in fillInCell()
1951 if( pBt->needSwab ) *pNext = swab32(*pNext); in fillInCell()
2008 static void reparentChildPages(Btree *pBt, MemPage *pPage){ in reparentChildPages() argument
2010 Pager *pPager = pBt->pPager; in reparentChildPages()
2012 reparentPage(pPager, SWAB32(pBt, pPage->apCell[i]->h.leftChild), pPage, i); in reparentChildPages()
2014 reparentPage(pPager, SWAB32(pBt, pPage->u.hdr.rightChild), pPage, i); in reparentChildPages()
2031 static void dropCell(Btree *pBt, MemPage *pPage, int idx, int sz){ in dropCell() argument
2034 assert( sz==cellSize(pBt, pPage->apCell[idx]) ); in dropCell()
2036 freeSpace(pBt, pPage, Addr(pPage->apCell[idx]) - Addr(pPage), sz); in dropCell()
2057 static void insertCell(Btree *pBt, MemPage *pPage, int i, Cell *pCell, int sz){ in insertCell() argument
2060 assert( sz==cellSize(pBt, pCell) ); in insertCell()
2062 idx = allocateSpace(pBt, pPage, sz); in insertCell()
2083 static void relinkCellList(Btree *pBt, MemPage *pPage){ in relinkCellList() argument
2091 *pIdx = SWAB16(pBt, idx); in relinkCellList()
2179 static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){ in balance() argument
2213 relinkCellList(pBt, pPage); in balance()
2234 pgnoChild = SWAB32(pBt, pPage->u.hdr.rightChild); in balance()
2235 rc = sqlitepager_get(pBt->pPager, pgnoChild, (void**)&pChild); in balance()
2239 rc = initPage(pBt, pPage, sqlitepager_pagenumber(pPage), 0); in balance()
2241 reparentChildPages(pBt, pPage); in balance()
2247 freePage(pBt, pChild, pgnoChild); in balance()
2250 relinkCellList(pBt, pPage); in balance()
2257 relinkCellList(pBt, pPage); in balance()
2270 rc = allocatePage(pBt, &pChild, &pgnoChild, sqlitepager_pagenumber(pPage)); in balance()
2284 zeroPage(pBt, pPage); in balance()
2285 pPage->u.hdr.rightChild = SWAB32(pBt, pgnoChild); in balance()
2301 swabPgno = SWAB32(pBt, pgno); in balance()
2339 pgnoOld[i] = SWAB32(pBt, apDiv[i]->h.leftChild); in balance()
2341 pgnoOld[i] = SWAB32(pBt, pParent->u.hdr.rightChild); in balance()
2345 rc = sqlitepager_get(pBt->pPager, pgnoOld[i], (void**)&apOld[i]); in balance()
2347 rc = initPage(pBt, apOld[i], pgnoOld[i], pParent); in balance()
2397 szCell[nCell] = cellSize(pBt, apCell[nCell]); in balance()
2401 szCell[nCell] = cellSize(pBt, apDiv[i]); in balance()
2404 dropCell(pBt, pParent, nxDiv, szCell[nCell]); in balance()
2405 assert( SWAB32(pBt, apCell[nCell]->h.leftChild)==pgnoOld[i] ); in balance()
2453 rc = allocatePage(pBt, &apNew[i], &pgnoNew[i], pgnoNew[i-1]); in balance()
2457 zeroPage(pBt, apNew[i]); in balance()
2464 rc = freePage(pBt, apOld[i], pgnoOld[i]); in balance()
2516 insertCell(pBt, pNew, pNew->nCell, apCell[j], szCell[j]); in balance()
2521 relinkCellList(pBt, pNew); in balance()
2524 apCell[j]->h.leftChild = SWAB32(pBt, pgnoNew[i]); in balance()
2526 insertCell(pBt, pParent, nxDiv, apCell[j], szCell[j]); in balance()
2534 pParent->u.hdr.rightChild = SWAB32(pBt, pgnoNew[nNew-1]); in balance()
2536 pParent->apCell[nxDiv]->h.leftChild = SWAB32(pBt, pgnoNew[nNew-1]); in balance()
2553 reparentChildPages(pBt, apNew[i]); in balance()
2555 reparentChildPages(pBt, pParent); in balance()
2560 rc = balance(pBt, pParent, pCur); in balance()
2629 Btree *pBt = pCur->pBt; in fileBtreeInsert() local
2634 if( !pBt->inTrans || nKey+nData==0 ){ in fileBtreeInsert()
2636 return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR; in fileBtreeInsert()
2638 assert( !pBt->readOnly ); in fileBtreeInsert()
2651 rc = fillInCell(pBt, &newCell, pKey, nKey, pData, nData); in fileBtreeInsert()
2653 szNew = cellSize(pBt, &newCell); in fileBtreeInsert()
2656 rc = clearCell(pBt, pPage->apCell[pCur->idx]); in fileBtreeInsert()
2658 dropCell(pBt, pPage, pCur->idx, cellSize(pBt, pPage->apCell[pCur->idx])); in fileBtreeInsert()
2665 insertCell(pBt, pPage, pCur->idx, &newCell, szNew); in fileBtreeInsert()
2666 rc = balance(pCur->pBt, pPage, pCur); in fileBtreeInsert()
2692 Btree *pBt = pCur->pBt; in fileBtreeDelete() local
2698 if( !pBt->inTrans ){ in fileBtreeDelete()
2700 return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR; in fileBtreeDelete()
2702 assert( !pBt->readOnly ); in fileBtreeDelete()
2715 pgnoChild = SWAB32(pBt, pCell->h.leftChild); in fileBtreeDelete()
2716 clearCell(pBt, pCell); in fileBtreeDelete()
2737 dropCell(pBt, pPage, pCur->idx, cellSize(pBt, pCell)); in fileBtreeDelete()
2739 szNext = cellSize(pBt, pNext); in fileBtreeDelete()
2740 pNext->h.leftChild = SWAB32(pBt, pgnoChild); in fileBtreeDelete()
2741 insertCell(pBt, pPage, pCur->idx, pNext, szNext); in fileBtreeDelete()
2742 rc = balance(pBt, pPage, pCur); in fileBtreeDelete()
2745 dropCell(pBt, leafCur.pPage, leafCur.idx, szNext); in fileBtreeDelete()
2746 rc = balance(pBt, leafCur.pPage, pCur); in fileBtreeDelete()
2749 dropCell(pBt, pPage, pCur->idx, cellSize(pBt, pCell)); in fileBtreeDelete()
2761 rc = balance(pBt, pPage, pCur); in fileBtreeDelete()
2776 static int fileBtreeCreateTable(Btree *pBt, int *piTable){ in fileBtreeCreateTable() argument
2780 if( !pBt->inTrans ){ in fileBtreeCreateTable()
2782 return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR; in fileBtreeCreateTable()
2784 if( pBt->readOnly ){ in fileBtreeCreateTable()
2787 rc = allocatePage(pBt, &pRoot, &pgnoRoot, 0); in fileBtreeCreateTable()
2790 zeroPage(pBt, pRoot); in fileBtreeCreateTable()
2800 static int clearDatabasePage(Btree *pBt, Pgno pgno, int freePageFlag){ in clearDatabasePage() argument
2806 rc = sqlitepager_get(pBt->pPager, pgno, (void**)&pPage); in clearDatabasePage()
2810 rc = initPage(pBt, pPage, pgno, 0); in clearDatabasePage()
2812 idx = SWAB16(pBt, pPage->u.hdr.firstCell); in clearDatabasePage()
2815 idx = SWAB16(pBt, pCell->h.iNext); in clearDatabasePage()
2817 rc = clearDatabasePage(pBt, SWAB32(pBt, pCell->h.leftChild), 1); in clearDatabasePage()
2820 rc = clearCell(pBt, pCell); in clearDatabasePage()
2824 rc = clearDatabasePage(pBt, SWAB32(pBt, pPage->u.hdr.rightChild), 1); in clearDatabasePage()
2828 rc = freePage(pBt, pPage, pgno); in clearDatabasePage()
2830 zeroPage(pBt, pPage); in clearDatabasePage()
2839 static int fileBtreeClearTable(Btree *pBt, int iTable){ in fileBtreeClearTable() argument
2842 if( !pBt->inTrans ){ in fileBtreeClearTable()
2843 return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR; in fileBtreeClearTable()
2845 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){ in fileBtreeClearTable()
2851 rc = clearDatabasePage(pBt, (Pgno)iTable, 0); in fileBtreeClearTable()
2853 fileBtreeRollback(pBt); in fileBtreeClearTable()
2863 static int fileBtreeDropTable(Btree *pBt, int iTable){ in fileBtreeDropTable() argument
2867 if( !pBt->inTrans ){ in fileBtreeDropTable()
2868 return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR; in fileBtreeDropTable()
2870 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){ in fileBtreeDropTable()
2875 rc = sqlitepager_get(pBt->pPager, (Pgno)iTable, (void**)&pPage); in fileBtreeDropTable()
2877 rc = fileBtreeClearTable(pBt, iTable); in fileBtreeDropTable()
2880 rc = freePage(pBt, pPage, iTable); in fileBtreeDropTable()
2882 zeroPage(pBt, pPage); in fileBtreeDropTable()
2954 rc = allocatePage(pBt, &pPage, pTo, 0);
2960 idx = SWAB16(pBt, pPage->u.hdr.firstCell);
2963 idx = SWAB16(pBt, pCell->h.iNext);
2990 static int fileBtreeGetMeta(Btree *pBt, int *aMeta){ in fileBtreeGetMeta() argument
2995 rc = sqlitepager_get(pBt->pPager, 1, (void**)&pP1); in fileBtreeGetMeta()
2997 aMeta[0] = SWAB32(pBt, pP1->nFree); in fileBtreeGetMeta()
2999 aMeta[i+1] = SWAB32(pBt, pP1->aMeta[i]); in fileBtreeGetMeta()
3008 static int fileBtreeUpdateMeta(Btree *pBt, int *aMeta){ in fileBtreeUpdateMeta() argument
3011 if( !pBt->inTrans ){ in fileBtreeUpdateMeta()
3012 return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR; in fileBtreeUpdateMeta()
3014 pP1 = pBt->page1; in fileBtreeUpdateMeta()
3018 pP1->aMeta[i] = SWAB32(pBt, aMeta[i+1]); in fileBtreeUpdateMeta()
3034 static int fileBtreePageDump(Btree *pBt, int pgno, int recursive){ in fileBtreePageDump() argument
3042 rc = sqlitepager_get(pBt->pPager, (Pgno)pgno, (void**)&pPage); in fileBtreePageDump()
3048 idx = SWAB16(pBt, pPage->u.hdr.firstCell); in fileBtreePageDump()
3051 int sz = cellSize(pBt, pCell); in fileBtreePageDump()
3053 sz = NKEY(pBt, pCell->h) + NDATA(pBt, pCell->h); in fileBtreePageDump()
3063 NKEY(pBt, pCell->h), NDATA(pBt, pCell->h), in fileBtreePageDump()
3070 idx = SWAB16(pBt, pCell->h.iNext); in fileBtreePageDump()
3075 printf("right_child: %d\n", SWAB32(pBt, pPage->u.hdr.rightChild)); in fileBtreePageDump()
3078 idx = SWAB16(pBt, pPage->u.hdr.firstFree); in fileBtreePageDump()
3082 nFree += SWAB16(pBt, p->iSize); in fileBtreePageDump()
3084 i, range, SWAB16(pBt, p->iSize), nFree); in fileBtreePageDump()
3085 idx = SWAB16(pBt, p->iNext); in fileBtreePageDump()
3092 idx = SWAB16(pBt, pPage->u.hdr.firstCell); in fileBtreePageDump()
3095 fileBtreePageDump(pBt, SWAB32(pBt, pCell->h.leftChild), 1); in fileBtreePageDump()
3096 idx = SWAB16(pBt, pCell->h.iNext); in fileBtreePageDump()
3098 fileBtreePageDump(pBt, SWAB32(pBt, pPage->u.hdr.rightChild), 1); in fileBtreePageDump()
3124 Btree *pBt = pCur->pBt; in fileBtreeCursorDump() local
3129 aResult[3] = cellSize(pBt, pPage->apCell[pCur->idx]); in fileBtreeCursorDump()
3130 aResult[6] = SWAB32(pBt, pPage->apCell[pCur->idx]->h.leftChild); in fileBtreeCursorDump()
3137 idx = SWAB16(pBt, pPage->u.hdr.firstFree); in fileBtreeCursorDump()
3140 idx = SWAB16(pBt, ((FreeBlk*)&pPage->u.aDisk[idx])->iNext); in fileBtreeCursorDump()
3143 aResult[7] = SWAB32(pBt, pPage->u.hdr.rightChild); in fileBtreeCursorDump()
3152 static Pager *fileBtreePager(Btree *pBt){ in fileBtreePager() argument
3153 return pBt->pPager; in fileBtreePager()
3162 Btree *pBt; /* The tree being checked out */ member
3236 int n = SWAB32(pCheck->pBt, pInfo->nFree); in checkList()
3238 checkRef(pCheck, SWAB32(pCheck->pBt, pInfo->aFree[i]), zContext); in checkList()
3242 iPage = SWAB32(pCheck->pBt, pOvfl->iNext); in checkList()
3297 Btree *pBt; in checkTreePage() local
3304 cur.pBt = pBt = pCheck->pBt; in checkTreePage()
3313 if( (rc = initPage(pBt, pPage, (Pgno)iPage, pParent))!=0 ){ in checkTreePage()
3338 nKey2 = NKEY(pBt, pCell->h); in checkTreePage()
3339 sz = nKey2 + NDATA(pBt, pCell->h); in checkTreePage()
3343 checkList(pCheck, 0, SWAB32(pBt, pCell->ovfl), nPage, zContext); in checkTreePage()
3357 pgno = SWAB32(pBt, pCell->h.leftChild); in checkTreePage()
3367 pgno = SWAB32(pBt, pPage->u.hdr.rightChild); in checkTreePage()
3376 for(i=SWAB16(pBt, pPage->u.hdr.firstCell); i>0 && i<SQLITE_USABLE_SIZE; ){ in checkTreePage()
3379 for(j=i+cellSize(pBt, pCell)-1; j>=i; j--) hit[j]++; in checkTreePage()
3380 i = SWAB16(pBt, pCell->h.iNext); in checkTreePage()
3382 for(i=SWAB16(pBt,pPage->u.hdr.firstFree); i>0 && i<SQLITE_USABLE_SIZE; ){ in checkTreePage()
3385 for(j=i+SWAB16(pBt,pFBlk->iSize)-1; j>=i; j--) hit[j]++; in checkTreePage()
3386 i = SWAB16(pBt,pFBlk->iNext); in checkTreePage()
3424 char *fileBtreeIntegrityCheck(Btree *pBt, int *aRoot, int nRoot){ in fileBtreeIntegrityCheck() argument
3429 nRef = *sqlitepager_stats(pBt->pPager); in fileBtreeIntegrityCheck()
3430 if( lockBtree(pBt)!=SQLITE_OK ){ in fileBtreeIntegrityCheck()
3433 sCheck.pBt = pBt; in fileBtreeIntegrityCheck()
3434 sCheck.pPager = pBt->pPager; in fileBtreeIntegrityCheck()
3437 unlockBtreeIfUnused(pBt); in fileBtreeIntegrityCheck()
3447 checkList(&sCheck, 1, SWAB32(pBt, pBt->page1->freeList), in fileBtreeIntegrityCheck()
3448 SWAB32(pBt, pBt->page1->nFree), "Main freelist: "); in fileBtreeIntegrityCheck()
3469 unlockBtreeIfUnused(pBt); in fileBtreeIntegrityCheck()
3470 if( nRef != *sqlitepager_stats(pBt->pPager) ){ in fileBtreeIntegrityCheck()
3474 nRef, *sqlitepager_stats(pBt->pPager) in fileBtreeIntegrityCheck()
3488 static const char *fileBtreeGetFilename(Btree *pBt){ in fileBtreeGetFilename() argument
3489 assert( pBt->pPager!=0 ); in fileBtreeGetFilename()
3490 return sqlitepager_filename(pBt->pPager); in fileBtreeGetFilename()