Lines Matching refs:pCur

515 #define invalidateOverflowCache(pCur) (pCur->curFlags &= ~BTCF_ValidOvfl)  argument
642 static void btreeReleaseAllCursorPages(BtCursor *pCur){ in btreeReleaseAllCursorPages() argument
644 if( pCur->iPage>=0 ){ in btreeReleaseAllCursorPages()
645 for(i=0; i<pCur->iPage; i++){ in btreeReleaseAllCursorPages()
646 releasePageNotNull(pCur->apPage[i]); in btreeReleaseAllCursorPages()
648 releasePageNotNull(pCur->pPage); in btreeReleaseAllCursorPages()
649 pCur->iPage = -1; in btreeReleaseAllCursorPages()
666 static int saveCursorKey(BtCursor *pCur){ in saveCursorKey() argument
668 assert( CURSOR_VALID==pCur->eState ); in saveCursorKey()
669 assert( 0==pCur->pKey ); in saveCursorKey()
670 assert( cursorHoldsMutex(pCur) ); in saveCursorKey()
672 if( pCur->curIntKey ){ in saveCursorKey()
674 pCur->nKey = sqlite3BtreeIntegerKey(pCur); in saveCursorKey()
683 pCur->nKey = sqlite3BtreePayloadSize(pCur); in saveCursorKey()
684 pKey = sqlite3Malloc( pCur->nKey + 9 + 8 ); in saveCursorKey()
686 rc = sqlite3BtreePayload(pCur, 0, (int)pCur->nKey, pKey); in saveCursorKey()
688 memset(((u8*)pKey)+pCur->nKey, 0, 9+8); in saveCursorKey()
689 pCur->pKey = pKey; in saveCursorKey()
697 assert( !pCur->curIntKey || !pCur->pKey ); in saveCursorKey()
708 static int saveCursorPosition(BtCursor *pCur){ in saveCursorPosition() argument
711 assert( CURSOR_VALID==pCur->eState || CURSOR_SKIPNEXT==pCur->eState ); in saveCursorPosition()
712 assert( 0==pCur->pKey ); in saveCursorPosition()
713 assert( cursorHoldsMutex(pCur) ); in saveCursorPosition()
715 if( pCur->curFlags & BTCF_Pinned ){ in saveCursorPosition()
718 if( pCur->eState==CURSOR_SKIPNEXT ){ in saveCursorPosition()
719 pCur->eState = CURSOR_VALID; in saveCursorPosition()
721 pCur->skipNext = 0; in saveCursorPosition()
724 rc = saveCursorKey(pCur); in saveCursorPosition()
726 btreeReleaseAllCursorPages(pCur); in saveCursorPosition()
727 pCur->eState = CURSOR_REQUIRESEEK; in saveCursorPosition()
730 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl|BTCF_AtLast); in saveCursorPosition()
800 void sqlite3BtreeClearCursor(BtCursor *pCur){ in sqlite3BtreeClearCursor() argument
801 assert( cursorHoldsMutex(pCur) ); in sqlite3BtreeClearCursor()
802 sqlite3_free(pCur->pKey); in sqlite3BtreeClearCursor()
803 pCur->pKey = 0; in sqlite3BtreeClearCursor()
804 pCur->eState = CURSOR_INVALID; in sqlite3BtreeClearCursor()
813 BtCursor *pCur, /* Cursor open on the btree to be searched */ in btreeMoveto() argument
823 KeyInfo *pKeyInfo = pCur->pKeyInfo; in btreeMoveto()
831 rc = sqlite3BtreeIndexMoveto(pCur, pIdxKey, pRes); in btreeMoveto()
833 sqlite3DbFree(pCur->pKeyInfo->db, pIdxKey); in btreeMoveto()
836 rc = sqlite3BtreeTableMoveto(pCur, nKey, bias, pRes); in btreeMoveto()
848 static int btreeRestoreCursorPosition(BtCursor *pCur){ in btreeRestoreCursorPosition() argument
851 assert( cursorOwnsBtShared(pCur) ); in btreeRestoreCursorPosition()
852 assert( pCur->eState>=CURSOR_REQUIRESEEK ); in btreeRestoreCursorPosition()
853 if( pCur->eState==CURSOR_FAULT ){ in btreeRestoreCursorPosition()
854 return pCur->skipNext; in btreeRestoreCursorPosition()
856 pCur->eState = CURSOR_INVALID; in btreeRestoreCursorPosition()
860 rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext); in btreeRestoreCursorPosition()
863 sqlite3_free(pCur->pKey); in btreeRestoreCursorPosition()
864 pCur->pKey = 0; in btreeRestoreCursorPosition()
865 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID ); in btreeRestoreCursorPosition()
866 if( skipNext ) pCur->skipNext = skipNext; in btreeRestoreCursorPosition()
867 if( pCur->skipNext && pCur->eState==CURSOR_VALID ){ in btreeRestoreCursorPosition()
868 pCur->eState = CURSOR_SKIPNEXT; in btreeRestoreCursorPosition()
891 int sqlite3BtreeCursorHasMoved(BtCursor *pCur){ in sqlite3BtreeCursorHasMoved() argument
892 assert( EIGHT_BYTE_ALIGNMENT(pCur) in sqlite3BtreeCursorHasMoved()
893 || pCur==sqlite3BtreeFakeValidCursor() ); in sqlite3BtreeCursorHasMoved()
895 assert( sizeof(pCur->eState)==1 ); in sqlite3BtreeCursorHasMoved()
896 return CURSOR_VALID != *(u8*)pCur; in sqlite3BtreeCursorHasMoved()
923 int sqlite3BtreeCursorRestore(BtCursor *pCur, int *pDifferentRow){ in sqlite3BtreeCursorRestore() argument
926 assert( pCur!=0 ); in sqlite3BtreeCursorRestore()
927 assert( pCur->eState!=CURSOR_VALID ); in sqlite3BtreeCursorRestore()
928 rc = restoreCursorPosition(pCur); in sqlite3BtreeCursorRestore()
933 if( pCur->eState!=CURSOR_VALID ){ in sqlite3BtreeCursorRestore()
947 void sqlite3BtreeCursorHint(BtCursor *pCur, int eHintType, ...){ in sqlite3BtreeCursorHint() argument
955 void sqlite3BtreeCursorHintFlags(BtCursor *pCur, unsigned x){ in sqlite3BtreeCursorHintFlags() argument
957 pCur->hints = x; in sqlite3BtreeCursorHintFlags()
2264 BtCursor *pCur, /* Cursor to receive the page, or NULL */ in getAndInitPage() argument
2270 assert( pCur==0 || ppPage==&pCur->pPage ); in getAndInitPage()
2271 assert( pCur==0 || bReadOnly==pCur->curPagerFlags ); in getAndInitPage()
2272 assert( pCur==0 || pCur->iPage>0 ); in getAndInitPage()
2295 if( pCur && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) ){ in getAndInitPage()
2304 if( pCur ){ in getAndInitPage()
2305 pCur->iPage--; in getAndInitPage()
2306 pCur->pPage = pCur->apPage[pCur->iPage]; in getAndInitPage()
2775 BtCursor *pCur = pBt->pCursor; in allocateTempSpace() local
2776 pBt->pCursor = pCur->pNext; /* Unlink the cursor */ in allocateTempSpace()
2777 memset(pCur, 0, sizeof(*pCur)); in allocateTempSpace()
2825 BtCursor *pCur = pBt->pCursor; in sqlite3BtreeClose() local
2826 while( pCur ){ in sqlite3BtreeClose()
2827 BtCursor *pTmp = pCur; in sqlite3BtreeClose()
2828 pCur = pCur->pNext; in sqlite3BtreeClose()
3364 BtCursor *pCur; in countValidCursors() local
3366 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){ in countValidCursors()
3367 if( (wrOnly==0 || (pCur->curFlags & BTCF_WriteFlag)!=0) in countValidCursors()
3368 && pCur->eState!=CURSOR_FAULT ) r++; in countValidCursors()
4526 BtCursor *pCur /* Space for new cursor */ in btreeCursor() argument
4562 pCur->pgnoRoot = iTable; in btreeCursor()
4563 pCur->iPage = -1; in btreeCursor()
4564 pCur->pKeyInfo = pKeyInfo; in btreeCursor()
4565 pCur->pBtree = p; in btreeCursor()
4566 pCur->pBt = pBt; in btreeCursor()
4567 pCur->curFlags = 0; in btreeCursor()
4573 pCur->curFlags = BTCF_Multiple; in btreeCursor()
4576 pCur->eState = CURSOR_INVALID; in btreeCursor()
4577 pCur->pNext = pBt->pCursor; in btreeCursor()
4578 pBt->pCursor = pCur; in btreeCursor()
4580 pCur->curFlags |= BTCF_WriteFlag; in btreeCursor()
4581 pCur->curPagerFlags = 0; in btreeCursor()
4584 pCur->curPagerFlags = PAGER_GET_READONLY; in btreeCursor()
4593 BtCursor *pCur /* Space for new cursor */ in btreeCursorWithLock() argument
4597 rc = btreeCursor(p, iTable, wrFlag, pKeyInfo, pCur); in btreeCursorWithLock()
4606 BtCursor *pCur /* Write new cursor here */ in sqlite3BtreeCursor() argument
4609 return btreeCursorWithLock(p, iTable, wrFlag, pKeyInfo, pCur); in sqlite3BtreeCursor()
4611 return btreeCursor(p, iTable, wrFlag, pKeyInfo, pCur); in sqlite3BtreeCursor()
4643 int sqlite3BtreeCloseCursor(BtCursor *pCur){ in sqlite3BtreeCloseCursor() argument
4644 Btree *pBtree = pCur->pBtree; in sqlite3BtreeCloseCursor()
4646 BtShared *pBt = pCur->pBt; in sqlite3BtreeCloseCursor()
4649 if( pBt->pCursor==pCur ){ in sqlite3BtreeCloseCursor()
4650 pBt->pCursor = pCur->pNext; in sqlite3BtreeCloseCursor()
4654 if( pPrev->pNext==pCur ){ in sqlite3BtreeCloseCursor()
4655 pPrev->pNext = pCur->pNext; in sqlite3BtreeCloseCursor()
4661 btreeReleaseAllCursorPages(pCur); in sqlite3BtreeCloseCursor()
4663 sqlite3_free(pCur->aOverflow); in sqlite3BtreeCloseCursor()
4664 sqlite3_free(pCur->pKey); in sqlite3BtreeCloseCursor()
4673 pCur->pBtree = 0; in sqlite3BtreeCloseCursor()
4695 static void assertCellInfo(BtCursor *pCur){ in assertCellInfo() argument
4698 btreeParseCell(pCur->pPage, pCur->ix, &info); in assertCellInfo()
4699 assert( CORRUPT_DB || cellInfoEqual(&info, &pCur->info) ); in assertCellInfo()
4704 static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur){ in getCellInfo() argument
4705 if( pCur->info.nSize==0 ){ in getCellInfo()
4706 pCur->curFlags |= BTCF_ValidNKey; in getCellInfo()
4707 btreeParseCell(pCur->pPage,pCur->ix,&pCur->info); in getCellInfo()
4709 assertCellInfo(pCur); in getCellInfo()
4719 int sqlite3BtreeCursorIsValid(BtCursor *pCur){ in sqlite3BtreeCursorIsValid() argument
4720 return pCur && pCur->eState==CURSOR_VALID; in sqlite3BtreeCursorIsValid()
4723 int sqlite3BtreeCursorIsValidNN(BtCursor *pCur){ in sqlite3BtreeCursorIsValidNN() argument
4724 assert( pCur!=0 ); in sqlite3BtreeCursorIsValidNN()
4725 return pCur->eState==CURSOR_VALID; in sqlite3BtreeCursorIsValidNN()
4734 i64 sqlite3BtreeIntegerKey(BtCursor *pCur){ in sqlite3BtreeIntegerKey() argument
4735 assert( cursorHoldsMutex(pCur) ); in sqlite3BtreeIntegerKey()
4736 assert( pCur->eState==CURSOR_VALID ); in sqlite3BtreeIntegerKey()
4737 assert( pCur->curIntKey ); in sqlite3BtreeIntegerKey()
4738 getCellInfo(pCur); in sqlite3BtreeIntegerKey()
4739 return pCur->info.nKey; in sqlite3BtreeIntegerKey()
4745 void sqlite3BtreeCursorPin(BtCursor *pCur){ in sqlite3BtreeCursorPin() argument
4746 assert( (pCur->curFlags & BTCF_Pinned)==0 ); in sqlite3BtreeCursorPin()
4747 pCur->curFlags |= BTCF_Pinned; in sqlite3BtreeCursorPin()
4749 void sqlite3BtreeCursorUnpin(BtCursor *pCur){ in sqlite3BtreeCursorUnpin() argument
4750 assert( (pCur->curFlags & BTCF_Pinned)!=0 ); in sqlite3BtreeCursorUnpin()
4751 pCur->curFlags &= ~BTCF_Pinned; in sqlite3BtreeCursorUnpin()
4759 i64 sqlite3BtreeOffset(BtCursor *pCur){ in sqlite3BtreeOffset() argument
4760 assert( cursorHoldsMutex(pCur) ); in sqlite3BtreeOffset()
4761 assert( pCur->eState==CURSOR_VALID ); in sqlite3BtreeOffset()
4762 getCellInfo(pCur); in sqlite3BtreeOffset()
4763 return (i64)pCur->pBt->pageSize*((i64)pCur->pPage->pgno - 1) + in sqlite3BtreeOffset()
4764 (i64)(pCur->info.pPayload - pCur->pPage->aData); in sqlite3BtreeOffset()
4777 u32 sqlite3BtreePayloadSize(BtCursor *pCur){ in sqlite3BtreePayloadSize() argument
4778 assert( cursorHoldsMutex(pCur) ); in sqlite3BtreePayloadSize()
4779 assert( pCur->eState==CURSOR_VALID ); in sqlite3BtreePayloadSize()
4780 getCellInfo(pCur); in sqlite3BtreePayloadSize()
4781 return pCur->info.nPayload; in sqlite3BtreePayloadSize()
4797 sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor *pCur){ in sqlite3BtreeMaxRecordSize() argument
4798 assert( cursorHoldsMutex(pCur) ); in sqlite3BtreeMaxRecordSize()
4799 assert( pCur->eState==CURSOR_VALID ); in sqlite3BtreeMaxRecordSize()
4800 return pCur->pBt->pageSize * (sqlite3_int64)pCur->pBt->nPage; in sqlite3BtreeMaxRecordSize()
4941 BtCursor *pCur, /* Cursor pointing to entry to read from */ in accessPayload() argument
4950 MemPage *pPage = pCur->pPage; /* Btree page of current entry */ in accessPayload()
4951 BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */ in accessPayload()
4958 assert( pCur->eState==CURSOR_VALID ); in accessPayload()
4959 if( pCur->ix>=pPage->nCell ){ in accessPayload()
4962 assert( cursorHoldsMutex(pCur) ); in accessPayload()
4964 getCellInfo(pCur); in accessPayload()
4965 aPayload = pCur->info.pPayload; in accessPayload()
4966 assert( offset+amt <= pCur->info.nPayload ); in accessPayload()
4969 if( (uptr)(aPayload - pPage->aData) > (pBt->usableSize - pCur->info.nLocal) ){ in accessPayload()
4979 if( offset<pCur->info.nLocal ){ in accessPayload()
4981 if( a+offset>pCur->info.nLocal ){ in accessPayload()
4982 a = pCur->info.nLocal - offset; in accessPayload()
4989 offset -= pCur->info.nLocal; in accessPayload()
4997 nextPage = get4byte(&aPayload[pCur->info.nLocal]); in accessPayload()
5006 if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){ in accessPayload()
5007 int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize; in accessPayload()
5008 if( pCur->aOverflow==0 in accessPayload()
5009 || nOvfl*(int)sizeof(Pgno) > sqlite3MallocSize(pCur->aOverflow) in accessPayload()
5012 pCur->aOverflow, nOvfl*2*sizeof(Pgno) in accessPayload()
5017 pCur->aOverflow = aNew; in accessPayload()
5020 memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno)); in accessPayload()
5021 pCur->curFlags |= BTCF_ValidOvfl; in accessPayload()
5027 if( pCur->aOverflow[offset/ovflSize] ){ in accessPayload()
5029 nextPage = pCur->aOverflow[iIdx]; in accessPayload()
5038 assert( pCur->aOverflow[iIdx]==0 in accessPayload()
5039 || pCur->aOverflow[iIdx]==nextPage in accessPayload()
5041 pCur->aOverflow[iIdx] = nextPage; in accessPayload()
5050 assert( pCur->curFlags & BTCF_ValidOvfl ); in accessPayload()
5051 assert( pCur->pBtree->db==pBt->db ); in accessPayload()
5052 if( pCur->aOverflow[iIdx+1] ){ in accessPayload()
5053 nextPage = pCur->aOverflow[iIdx+1]; in accessPayload()
5144 int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ in sqlite3BtreePayload() argument
5145 assert( cursorHoldsMutex(pCur) ); in sqlite3BtreePayload()
5146 assert( pCur->eState==CURSOR_VALID ); in sqlite3BtreePayload()
5147 assert( pCur->iPage>=0 && pCur->pPage ); in sqlite3BtreePayload()
5148 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0); in sqlite3BtreePayload()
5158 BtCursor *pCur, in accessPayloadChecked() argument
5164 if ( pCur->eState==CURSOR_INVALID ){ in accessPayloadChecked()
5167 assert( cursorOwnsBtShared(pCur) ); in accessPayloadChecked()
5168 rc = btreeRestoreCursorPosition(pCur); in accessPayloadChecked()
5169 return rc ? rc : accessPayload(pCur, offset, amt, pBuf, 0); in accessPayloadChecked()
5171 int sqlite3BtreePayloadChecked(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ in sqlite3BtreePayloadChecked() argument
5172 if( pCur->eState==CURSOR_VALID ){ in sqlite3BtreePayloadChecked()
5173 assert( cursorOwnsBtShared(pCur) ); in sqlite3BtreePayloadChecked()
5174 return accessPayload(pCur, offset, amt, pBuf, 0); in sqlite3BtreePayloadChecked()
5176 return accessPayloadChecked(pCur, offset, amt, pBuf); in sqlite3BtreePayloadChecked()
5201 BtCursor *pCur, /* Cursor pointing to entry to read from */ in fetchPayload() argument
5205 assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage); in fetchPayload()
5206 assert( pCur->eState==CURSOR_VALID ); in fetchPayload()
5207 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); in fetchPayload()
5208 assert( cursorOwnsBtShared(pCur) ); in fetchPayload()
5209 assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB ); in fetchPayload()
5210 assert( pCur->info.nSize>0 ); in fetchPayload()
5211 assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB ); in fetchPayload()
5212 assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB); in fetchPayload()
5213 amt = pCur->info.nLocal; in fetchPayload()
5214 if( amt>(int)(pCur->pPage->aDataEnd - pCur->info.pPayload) ){ in fetchPayload()
5218 amt = MAX(0, (int)(pCur->pPage->aDataEnd - pCur->info.pPayload)); in fetchPayload()
5221 return (void*)pCur->info.pPayload; in fetchPayload()
5239 const void *sqlite3BtreePayloadFetch(BtCursor *pCur, u32 *pAmt){ in sqlite3BtreePayloadFetch() argument
5240 return fetchPayload(pCur, pAmt); in sqlite3BtreePayloadFetch()
5253 static int moveToChild(BtCursor *pCur, u32 newPgno){ in moveToChild() argument
5254 assert( cursorOwnsBtShared(pCur) ); in moveToChild()
5255 assert( pCur->eState==CURSOR_VALID ); in moveToChild()
5256 assert( pCur->iPage<BTCURSOR_MAX_DEPTH ); in moveToChild()
5257 assert( pCur->iPage>=0 ); in moveToChild()
5258 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){ in moveToChild()
5261 pCur->info.nSize = 0; in moveToChild()
5262 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl); in moveToChild()
5263 pCur->aiIdx[pCur->iPage] = pCur->ix; in moveToChild()
5264 pCur->apPage[pCur->iPage] = pCur->pPage; in moveToChild()
5265 pCur->ix = 0; in moveToChild()
5266 pCur->iPage++; in moveToChild()
5267 return getAndInitPage(pCur->pBt, newPgno, &pCur->pPage, pCur, in moveToChild()
5268 pCur->curPagerFlags); in moveToChild()
5301 static void moveToParent(BtCursor *pCur){ in moveToParent() argument
5303 assert( cursorOwnsBtShared(pCur) ); in moveToParent()
5304 assert( pCur->eState==CURSOR_VALID ); in moveToParent()
5305 assert( pCur->iPage>0 ); in moveToParent()
5306 assert( pCur->pPage ); in moveToParent()
5308 pCur->apPage[pCur->iPage-1], in moveToParent()
5309 pCur->aiIdx[pCur->iPage-1], in moveToParent()
5310 pCur->pPage->pgno in moveToParent()
5312 testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell ); in moveToParent()
5313 pCur->info.nSize = 0; in moveToParent()
5314 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl); in moveToParent()
5315 pCur->ix = pCur->aiIdx[pCur->iPage-1]; in moveToParent()
5316 pLeaf = pCur->pPage; in moveToParent()
5317 pCur->pPage = pCur->apPage[--pCur->iPage]; in moveToParent()
5342 static int moveToRoot(BtCursor *pCur){ in moveToRoot() argument
5346 assert( cursorOwnsBtShared(pCur) ); in moveToRoot()
5350 assert( pCur->eState < CURSOR_REQUIRESEEK || pCur->iPage<0 ); in moveToRoot()
5351 assert( pCur->pgnoRoot>0 || pCur->iPage<0 ); in moveToRoot()
5353 if( pCur->iPage>=0 ){ in moveToRoot()
5354 if( pCur->iPage ){ in moveToRoot()
5355 releasePageNotNull(pCur->pPage); in moveToRoot()
5356 while( --pCur->iPage ){ in moveToRoot()
5357 releasePageNotNull(pCur->apPage[pCur->iPage]); in moveToRoot()
5359 pRoot = pCur->pPage = pCur->apPage[0]; in moveToRoot()
5362 }else if( pCur->pgnoRoot==0 ){ in moveToRoot()
5363 pCur->eState = CURSOR_INVALID; in moveToRoot()
5366 assert( pCur->iPage==(-1) ); in moveToRoot()
5367 if( pCur->eState>=CURSOR_REQUIRESEEK ){ in moveToRoot()
5368 if( pCur->eState==CURSOR_FAULT ){ in moveToRoot()
5369 assert( pCur->skipNext!=SQLITE_OK ); in moveToRoot()
5370 return pCur->skipNext; in moveToRoot()
5372 sqlite3BtreeClearCursor(pCur); in moveToRoot()
5374 rc = getAndInitPage(pCur->pBt, pCur->pgnoRoot, &pCur->pPage, in moveToRoot()
5375 0, pCur->curPagerFlags); in moveToRoot()
5377 pCur->eState = CURSOR_INVALID; in moveToRoot()
5380 pCur->iPage = 0; in moveToRoot()
5381 pCur->curIntKey = pCur->pPage->intKey; in moveToRoot()
5383 pRoot = pCur->pPage; in moveToRoot()
5384 assert( pRoot->pgno==pCur->pgnoRoot || CORRUPT_DB ); in moveToRoot()
5397 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){ in moveToRoot()
5398 return SQLITE_CORRUPT_PAGE(pCur->pPage); in moveToRoot()
5402 pCur->ix = 0; in moveToRoot()
5403 pCur->info.nSize = 0; in moveToRoot()
5404 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl); in moveToRoot()
5407 pCur->eState = CURSOR_VALID; in moveToRoot()
5412 pCur->eState = CURSOR_VALID; in moveToRoot()
5413 rc = moveToChild(pCur, subpage); in moveToRoot()
5415 pCur->eState = CURSOR_INVALID; in moveToRoot()
5428 static int moveToLeftmost(BtCursor *pCur){ in moveToLeftmost() argument
5433 assert( cursorOwnsBtShared(pCur) ); in moveToLeftmost()
5434 assert( pCur->eState==CURSOR_VALID ); in moveToLeftmost()
5435 while( rc==SQLITE_OK && !(pPage = pCur->pPage)->leaf ){ in moveToLeftmost()
5436 assert( pCur->ix<pPage->nCell ); in moveToLeftmost()
5437 pgno = get4byte(findCell(pPage, pCur->ix)); in moveToLeftmost()
5438 rc = moveToChild(pCur, pgno); in moveToLeftmost()
5453 static int moveToRightmost(BtCursor *pCur){ in moveToRightmost() argument
5458 assert( cursorOwnsBtShared(pCur) ); in moveToRightmost()
5459 assert( pCur->eState==CURSOR_VALID ); in moveToRightmost()
5460 while( !(pPage = pCur->pPage)->leaf ){ in moveToRightmost()
5462 pCur->ix = pPage->nCell; in moveToRightmost()
5463 rc = moveToChild(pCur, pgno); in moveToRightmost()
5466 pCur->ix = pPage->nCell-1; in moveToRightmost()
5467 assert( pCur->info.nSize==0 ); in moveToRightmost()
5468 assert( (pCur->curFlags & BTCF_ValidNKey)==0 ); in moveToRightmost()
5476 int sqlite3BtreeFirst(BtCursor *pCur, int *pRes){ in sqlite3BtreeFirst() argument
5479 assert( cursorOwnsBtShared(pCur) ); in sqlite3BtreeFirst()
5480 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); in sqlite3BtreeFirst()
5481 rc = moveToRoot(pCur); in sqlite3BtreeFirst()
5483 assert( pCur->pPage->nCell>0 ); in sqlite3BtreeFirst()
5485 rc = moveToLeftmost(pCur); in sqlite3BtreeFirst()
5487 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 ); in sqlite3BtreeFirst()
5498 int sqlite3BtreeLast(BtCursor *pCur, int *pRes){ in sqlite3BtreeLast() argument
5501 assert( cursorOwnsBtShared(pCur) ); in sqlite3BtreeLast()
5502 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); in sqlite3BtreeLast()
5505 if( CURSOR_VALID==pCur->eState && (pCur->curFlags & BTCF_AtLast)!=0 ){ in sqlite3BtreeLast()
5510 for(ii=0; ii<pCur->iPage; ii++){ in sqlite3BtreeLast()
5511 assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell ); in sqlite3BtreeLast()
5513 assert( pCur->ix==pCur->pPage->nCell-1 || CORRUPT_DB ); in sqlite3BtreeLast()
5514 testcase( pCur->ix!=pCur->pPage->nCell-1 ); in sqlite3BtreeLast()
5516 assert( pCur->pPage->leaf ); in sqlite3BtreeLast()
5522 rc = moveToRoot(pCur); in sqlite3BtreeLast()
5524 assert( pCur->eState==CURSOR_VALID ); in sqlite3BtreeLast()
5526 rc = moveToRightmost(pCur); in sqlite3BtreeLast()
5528 pCur->curFlags |= BTCF_AtLast; in sqlite3BtreeLast()
5530 pCur->curFlags &= ~BTCF_AtLast; in sqlite3BtreeLast()
5533 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 ); in sqlite3BtreeLast()
5564 BtCursor *pCur, /* The cursor to be moved */ in sqlite3BtreeTableMoveto() argument
5571 assert( cursorOwnsBtShared(pCur) ); in sqlite3BtreeTableMoveto()
5572 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); in sqlite3BtreeTableMoveto()
5574 assert( pCur->pKeyInfo==0 ); in sqlite3BtreeTableMoveto()
5575 assert( pCur->eState!=CURSOR_VALID || pCur->curIntKey!=0 ); in sqlite3BtreeTableMoveto()
5579 if( pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0 ){ in sqlite3BtreeTableMoveto()
5580 if( pCur->info.nKey==intKey ){ in sqlite3BtreeTableMoveto()
5584 if( pCur->info.nKey<intKey ){ in sqlite3BtreeTableMoveto()
5585 if( (pCur->curFlags & BTCF_AtLast)!=0 ){ in sqlite3BtreeTableMoveto()
5593 if( pCur->info.nKey+1==intKey ){ in sqlite3BtreeTableMoveto()
5595 rc = sqlite3BtreeNext(pCur, 0); in sqlite3BtreeTableMoveto()
5597 getCellInfo(pCur); in sqlite3BtreeTableMoveto()
5598 if( pCur->info.nKey==intKey ){ in sqlite3BtreeTableMoveto()
5609 pCur->pBtree->nSeek++; /* Performance measurement during testing */ in sqlite3BtreeTableMoveto()
5612 rc = moveToRoot(pCur); in sqlite3BtreeTableMoveto()
5615 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 ); in sqlite3BtreeTableMoveto()
5621 assert( pCur->pPage ); in sqlite3BtreeTableMoveto()
5622 assert( pCur->pPage->isInit ); in sqlite3BtreeTableMoveto()
5623 assert( pCur->eState==CURSOR_VALID ); in sqlite3BtreeTableMoveto()
5624 assert( pCur->pPage->nCell > 0 ); in sqlite3BtreeTableMoveto()
5625 assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey ); in sqlite3BtreeTableMoveto()
5626 assert( pCur->curIntKey ); in sqlite3BtreeTableMoveto()
5631 MemPage *pPage = pCur->pPage; in sqlite3BtreeTableMoveto()
5665 pCur->ix = (u16)idx; in sqlite3BtreeTableMoveto()
5670 pCur->curFlags |= BTCF_ValidNKey; in sqlite3BtreeTableMoveto()
5671 pCur->info.nKey = nCellKey; in sqlite3BtreeTableMoveto()
5672 pCur->info.nSize = 0; in sqlite3BtreeTableMoveto()
5683 assert( pCur->ix<pCur->pPage->nCell ); in sqlite3BtreeTableMoveto()
5684 pCur->ix = (u16)idx; in sqlite3BtreeTableMoveto()
5695 pCur->ix = (u16)lwr; in sqlite3BtreeTableMoveto()
5696 rc = moveToChild(pCur, chldPg); in sqlite3BtreeTableMoveto()
5700 pCur->info.nSize = 0; in sqlite3BtreeTableMoveto()
5701 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 ); in sqlite3BtreeTableMoveto()
5722 BtCursor *pCur, in indexCellCompare() argument
5727 MemPage *pPage = pCur->pPage; in indexCellCompare()
5758 static int cursorOnLastPage(BtCursor *pCur){ in cursorOnLastPage() argument
5760 assert( pCur->eState==CURSOR_VALID ); in cursorOnLastPage()
5761 for(i=0; i<pCur->iPage; i++){ in cursorOnLastPage()
5762 MemPage *pPage = pCur->apPage[i]; in cursorOnLastPage()
5763 if( pCur->aiIdx[i]<pPage->nCell ) return 0; in cursorOnLastPage()
5795 BtCursor *pCur, /* The cursor to be moved */ in sqlite3BtreeIndexMoveto() argument
5802 assert( cursorOwnsBtShared(pCur) ); in sqlite3BtreeIndexMoveto()
5803 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); in sqlite3BtreeIndexMoveto()
5805 assert( pCur->pKeyInfo!=0 ); in sqlite3BtreeIndexMoveto()
5808 pCur->pBtree->nSeek++; /* Performance measurement during testing */ in sqlite3BtreeIndexMoveto()
5830 if( pCur->eState==CURSOR_VALID in sqlite3BtreeIndexMoveto()
5831 && pCur->pPage->leaf in sqlite3BtreeIndexMoveto()
5832 && cursorOnLastPage(pCur) in sqlite3BtreeIndexMoveto()
5835 if( pCur->ix==pCur->pPage->nCell-1 in sqlite3BtreeIndexMoveto()
5836 && (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0 in sqlite3BtreeIndexMoveto()
5842 if( pCur->iPage>0 in sqlite3BtreeIndexMoveto()
5843 && indexCellCompare(pCur, 0, pIdxKey, xRecordCompare)<=0 in sqlite3BtreeIndexMoveto()
5846 pCur->curFlags &= ~BTCF_ValidOvfl; in sqlite3BtreeIndexMoveto()
5847 if( !pCur->pPage->isInit ){ in sqlite3BtreeIndexMoveto()
5855 rc = moveToRoot(pCur); in sqlite3BtreeIndexMoveto()
5858 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 ); in sqlite3BtreeIndexMoveto()
5866 assert( pCur->pPage ); in sqlite3BtreeIndexMoveto()
5867 assert( pCur->pPage->isInit ); in sqlite3BtreeIndexMoveto()
5868 assert( pCur->eState==CURSOR_VALID ); in sqlite3BtreeIndexMoveto()
5869 assert( pCur->pPage->nCell > 0 ); in sqlite3BtreeIndexMoveto()
5870 assert( pCur->curIntKey==0 ); in sqlite3BtreeIndexMoveto()
5875 MemPage *pPage = pCur->pPage; in sqlite3BtreeIndexMoveto()
5928 pPage->xParseCell(pPage, pCellBody, &pCur->info); in sqlite3BtreeIndexMoveto()
5929 nCell = (int)pCur->info.nKey; in sqlite3BtreeIndexMoveto()
5934 if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){ in sqlite3BtreeIndexMoveto()
5943 pCur->ix = (u16)idx; in sqlite3BtreeIndexMoveto()
5944 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0); in sqlite3BtreeIndexMoveto()
5946 pCur->curFlags &= ~BTCF_ValidOvfl; in sqlite3BtreeIndexMoveto()
5956 && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed) in sqlite3BtreeIndexMoveto()
5966 pCur->ix = (u16)idx; in sqlite3BtreeIndexMoveto()
5977 assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB ); in sqlite3BtreeIndexMoveto()
5978 pCur->ix = (u16)idx; in sqlite3BtreeIndexMoveto()
5988 pCur->ix = (u16)lwr; in sqlite3BtreeIndexMoveto()
5989 rc = moveToChild(pCur, chldPg); in sqlite3BtreeIndexMoveto()
5993 pCur->info.nSize = 0; in sqlite3BtreeIndexMoveto()
5994 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 ); in sqlite3BtreeIndexMoveto()
6006 int sqlite3BtreeEof(BtCursor *pCur){ in sqlite3BtreeEof() argument
6011 return (CURSOR_VALID!=pCur->eState); in sqlite3BtreeEof()
6019 i64 sqlite3BtreeRowCountEst(BtCursor *pCur){ in sqlite3BtreeRowCountEst() argument
6023 assert( cursorOwnsBtShared(pCur) ); in sqlite3BtreeRowCountEst()
6024 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); in sqlite3BtreeRowCountEst()
6029 if( NEVER(pCur->eState!=CURSOR_VALID) ) return -1; in sqlite3BtreeRowCountEst()
6030 if( NEVER(pCur->pPage->leaf==0) ) return -1; in sqlite3BtreeRowCountEst()
6032 n = pCur->pPage->nCell; in sqlite3BtreeRowCountEst()
6033 for(i=0; i<pCur->iPage; i++){ in sqlite3BtreeRowCountEst()
6034 n *= pCur->apPage[i]->nCell; in sqlite3BtreeRowCountEst()
6059 static SQLITE_NOINLINE int btreeNext(BtCursor *pCur){ in btreeNext() argument
6064 assert( cursorOwnsBtShared(pCur) ); in btreeNext()
6065 if( pCur->eState!=CURSOR_VALID ){ in btreeNext()
6066 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 ); in btreeNext()
6067 rc = restoreCursorPosition(pCur); in btreeNext()
6071 if( CURSOR_INVALID==pCur->eState ){ in btreeNext()
6074 if( pCur->eState==CURSOR_SKIPNEXT ){ in btreeNext()
6075 pCur->eState = CURSOR_VALID; in btreeNext()
6076 if( pCur->skipNext>0 ) return SQLITE_OK; in btreeNext()
6080 pPage = pCur->pPage; in btreeNext()
6081 idx = ++pCur->ix; in btreeNext()
6088 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8])); in btreeNext()
6090 return moveToLeftmost(pCur); in btreeNext()
6093 if( pCur->iPage==0 ){ in btreeNext()
6094 pCur->eState = CURSOR_INVALID; in btreeNext()
6097 moveToParent(pCur); in btreeNext()
6098 pPage = pCur->pPage; in btreeNext()
6099 }while( pCur->ix>=pPage->nCell ); in btreeNext()
6101 return sqlite3BtreeNext(pCur, 0); in btreeNext()
6109 return moveToLeftmost(pCur); in btreeNext()
6112 int sqlite3BtreeNext(BtCursor *pCur, int flags){ in sqlite3BtreeNext() argument
6115 assert( cursorOwnsBtShared(pCur) ); in sqlite3BtreeNext()
6117 pCur->info.nSize = 0; in sqlite3BtreeNext()
6118 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl); in sqlite3BtreeNext()
6119 if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur); in sqlite3BtreeNext()
6120 pPage = pCur->pPage; in sqlite3BtreeNext()
6121 if( (++pCur->ix)>=pPage->nCell ){ in sqlite3BtreeNext()
6122 pCur->ix--; in sqlite3BtreeNext()
6123 return btreeNext(pCur); in sqlite3BtreeNext()
6128 return moveToLeftmost(pCur); in sqlite3BtreeNext()
6152 static SQLITE_NOINLINE int btreePrevious(BtCursor *pCur){ in btreePrevious() argument
6156 assert( cursorOwnsBtShared(pCur) ); in btreePrevious()
6157 assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 ); in btreePrevious()
6158 assert( pCur->info.nSize==0 ); in btreePrevious()
6159 if( pCur->eState!=CURSOR_VALID ){ in btreePrevious()
6160 rc = restoreCursorPosition(pCur); in btreePrevious()
6164 if( CURSOR_INVALID==pCur->eState ){ in btreePrevious()
6167 if( CURSOR_SKIPNEXT==pCur->eState ){ in btreePrevious()
6168 pCur->eState = CURSOR_VALID; in btreePrevious()
6169 if( pCur->skipNext<0 ) return SQLITE_OK; in btreePrevious()
6173 pPage = pCur->pPage; in btreePrevious()
6176 int idx = pCur->ix; in btreePrevious()
6177 rc = moveToChild(pCur, get4byte(findCell(pPage, idx))); in btreePrevious()
6179 rc = moveToRightmost(pCur); in btreePrevious()
6181 while( pCur->ix==0 ){ in btreePrevious()
6182 if( pCur->iPage==0 ){ in btreePrevious()
6183 pCur->eState = CURSOR_INVALID; in btreePrevious()
6186 moveToParent(pCur); in btreePrevious()
6188 assert( pCur->info.nSize==0 ); in btreePrevious()
6189 assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 ); in btreePrevious()
6191 pCur->ix--; in btreePrevious()
6192 pPage = pCur->pPage; in btreePrevious()
6194 rc = sqlite3BtreePrevious(pCur, 0); in btreePrevious()
6201 int sqlite3BtreePrevious(BtCursor *pCur, int flags){ in sqlite3BtreePrevious() argument
6202 assert( cursorOwnsBtShared(pCur) ); in sqlite3BtreePrevious()
6205 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey); in sqlite3BtreePrevious()
6206 pCur->info.nSize = 0; in sqlite3BtreePrevious()
6207 if( pCur->eState!=CURSOR_VALID in sqlite3BtreePrevious()
6208 || pCur->ix==0 in sqlite3BtreePrevious()
6209 || pCur->pPage->leaf==0 in sqlite3BtreePrevious()
6211 return btreePrevious(pCur); in sqlite3BtreePrevious()
6213 pCur->ix--; in sqlite3BtreePrevious()
8709 static int anotherValidCursor(BtCursor *pCur){ in anotherValidCursor() argument
8711 for(pOther=pCur->pBt->pCursor; pOther; pOther=pOther->pNext){ in anotherValidCursor()
8712 if( pOther!=pCur in anotherValidCursor()
8714 && pOther->pPage==pCur->pPage in anotherValidCursor()
8732 static int balance(BtCursor *pCur){ in balance() argument
8742 MemPage *pPage = pCur->pPage; in balance()
8745 if( pPage->nOverflow==0 && pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){ in balance()
8751 }else if( (iPage = pCur->iPage)==0 ){ in balance()
8752 if( pPage->nOverflow && (rc = anotherValidCursor(pCur))==SQLITE_OK ){ in balance()
8760 rc = balance_deeper(pPage, &pCur->apPage[1]); in balance()
8762 pCur->iPage = 1; in balance()
8763 pCur->ix = 0; in balance()
8764 pCur->aiIdx[0] = 0; in balance()
8765 pCur->apPage[0] = pPage; in balance()
8766 pCur->pPage = pCur->apPage[1]; in balance()
8767 assert( pCur->pPage->nOverflow ); in balance()
8778 MemPage * const pParent = pCur->apPage[iPage-1]; in balance()
8779 int const iIdx = pCur->aiIdx[iPage-1]; in balance()
8829 u8 *pSpace = sqlite3PageMalloc(pCur->pBt->pageSize); in balance()
8831 pCur->hints&BTREE_BULKLOAD); in balance()
8851 pCur->iPage--; in balance()
8852 assert( pCur->iPage>=0 ); in balance()
8853 pCur->pPage = pCur->apPage[pCur->iPage]; in balance()
8909 static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){ in btreeOverwriteCell() argument
8913 MemPage *pPage = pCur->pPage; /* Page being written */ in btreeOverwriteCell()
8918 if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd in btreeOverwriteCell()
8919 || pCur->info.pPayload < pPage->aData + pPage->cellOffset in btreeOverwriteCell()
8924 rc = btreeOverwriteContent(pPage, pCur->info.pPayload, pX, in btreeOverwriteCell()
8925 0, pCur->info.nLocal); in btreeOverwriteCell()
8927 if( pCur->info.nLocal==nTotal ) return SQLITE_OK; in btreeOverwriteCell()
8930 iOffset = pCur->info.nLocal; in btreeOverwriteCell()
8933 ovflPgno = get4byte(pCur->info.pPayload + iOffset); in btreeOverwriteCell()
8989 BtCursor *pCur, /* Insert data into the table of this cursor */ in sqlite3BtreeInsert() argument
8999 Btree *p = pCur->pBtree; in sqlite3BtreeInsert()
9005 assert( (flags & BTREE_PREFORMAT)==0 || seekResult || pCur->pKeyInfo==0 ); in sqlite3BtreeInsert()
9018 if( pCur->curFlags & BTCF_Multiple ){ in sqlite3BtreeInsert()
9019 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur); in sqlite3BtreeInsert()
9021 if( loc && pCur->iPage<0 ){ in sqlite3BtreeInsert()
9034 if( pCur->eState>=CURSOR_REQUIRESEEK ){ in sqlite3BtreeInsert()
9035 testcase( pCur->eState==CURSOR_REQUIRESEEK ); in sqlite3BtreeInsert()
9036 testcase( pCur->eState==CURSOR_FAULT ); in sqlite3BtreeInsert()
9037 rc = moveToRoot(pCur); in sqlite3BtreeInsert()
9041 assert( cursorOwnsBtShared(pCur) ); in sqlite3BtreeInsert()
9042 assert( (pCur->curFlags & BTCF_WriteFlag)!=0 in sqlite3BtreeInsert()
9045 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) ); in sqlite3BtreeInsert()
9052 assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) ); in sqlite3BtreeInsert()
9054 if( pCur->pKeyInfo==0 ){ in sqlite3BtreeInsert()
9059 invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0); in sqlite3BtreeInsert()
9067 assert( pCur->curFlags & BTCF_ValidNKey ); in sqlite3BtreeInsert()
9068 assert( pX->nKey==pCur->info.nKey ); in sqlite3BtreeInsert()
9077 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){ in sqlite3BtreeInsert()
9081 if( pCur->info.nSize!=0 in sqlite3BtreeInsert()
9082 && pCur->info.nPayload==(u32)pX->nData+pX->nZero in sqlite3BtreeInsert()
9085 return btreeOverwriteCell(pCur, pX); in sqlite3BtreeInsert()
9093 rc = sqlite3BtreeTableMoveto(pCur, pX->nKey, in sqlite3BtreeInsert()
9113 r.pKeyInfo = pCur->pKeyInfo; in sqlite3BtreeInsert()
9118 rc = sqlite3BtreeIndexMoveto(pCur, &r, &loc); in sqlite3BtreeInsert()
9120 rc = btreeMoveto(pCur, pX->pKey, pX->nKey, in sqlite3BtreeInsert()
9131 getCellInfo(pCur); in sqlite3BtreeInsert()
9132 if( pCur->info.nKey==pX->nKey ){ in sqlite3BtreeInsert()
9137 return btreeOverwriteCell(pCur, &x2); in sqlite3BtreeInsert()
9141 assert( pCur->eState==CURSOR_VALID in sqlite3BtreeInsert()
9142 || (pCur->eState==CURSOR_INVALID && loc) ); in sqlite3BtreeInsert()
9144 pPage = pCur->pPage; in sqlite3BtreeInsert()
9148 if( NEVER(pCur->eState>CURSOR_INVALID) ){ in sqlite3BtreeInsert()
9158 pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno, in sqlite3BtreeInsert()
9181 idx = pCur->ix; in sqlite3BtreeInsert()
9197 testcase( pCur->curFlags & BTCF_ValidOvfl ); in sqlite3BtreeInsert()
9198 invalidateOverflowCache(pCur); in sqlite3BtreeInsert()
9225 idx = ++pCur->ix; in sqlite3BtreeInsert()
9226 pCur->curFlags &= ~BTCF_ValidNKey; in sqlite3BtreeInsert()
9254 pCur->info.nSize = 0; in sqlite3BtreeInsert()
9257 pCur->curFlags &= ~(BTCF_ValidNKey); in sqlite3BtreeInsert()
9258 rc = balance(pCur); in sqlite3BtreeInsert()
9264 pCur->pPage->nOverflow = 0; in sqlite3BtreeInsert()
9265 pCur->eState = CURSOR_INVALID; in sqlite3BtreeInsert()
9267 btreeReleaseAllCursorPages(pCur); in sqlite3BtreeInsert()
9268 if( pCur->pKeyInfo ){ in sqlite3BtreeInsert()
9269 assert( pCur->pKey==0 ); in sqlite3BtreeInsert()
9270 pCur->pKey = sqlite3Malloc( pX->nKey ); in sqlite3BtreeInsert()
9271 if( pCur->pKey==0 ){ in sqlite3BtreeInsert()
9274 memcpy(pCur->pKey, pX->pKey, pX->nKey); in sqlite3BtreeInsert()
9277 pCur->eState = CURSOR_REQUIRESEEK; in sqlite3BtreeInsert()
9278 pCur->nKey = pX->nKey; in sqlite3BtreeInsert()
9281 assert( pCur->iPage<0 || pCur->pPage->nOverflow==0 ); in sqlite3BtreeInsert()
9416 int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ in sqlite3BtreeDelete() argument
9417 Btree *p = pCur->pBtree; in sqlite3BtreeDelete()
9427 assert( cursorOwnsBtShared(pCur) ); in sqlite3BtreeDelete()
9430 assert( pCur->curFlags & BTCF_WriteFlag ); in sqlite3BtreeDelete()
9431 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) ); in sqlite3BtreeDelete()
9432 assert( !hasReadConflicts(p, pCur->pgnoRoot) ); in sqlite3BtreeDelete()
9434 if( pCur->eState!=CURSOR_VALID ){ in sqlite3BtreeDelete()
9435 if( pCur->eState>=CURSOR_REQUIRESEEK ){ in sqlite3BtreeDelete()
9436 rc = btreeRestoreCursorPosition(pCur); in sqlite3BtreeDelete()
9437 assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID ); in sqlite3BtreeDelete()
9438 if( rc || pCur->eState!=CURSOR_VALID ) return rc; in sqlite3BtreeDelete()
9443 assert( pCur->eState==CURSOR_VALID ); in sqlite3BtreeDelete()
9445 iCellDepth = pCur->iPage; in sqlite3BtreeDelete()
9446 iCellIdx = pCur->ix; in sqlite3BtreeDelete()
9447 pPage = pCur->pPage; in sqlite3BtreeDelete()
9481 rc = saveCursorKey(pCur); in sqlite3BtreeDelete()
9496 rc = sqlite3BtreePrevious(pCur, 0); in sqlite3BtreeDelete()
9503 if( pCur->curFlags & BTCF_Multiple ){ in sqlite3BtreeDelete()
9504 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur); in sqlite3BtreeDelete()
9510 if( pCur->pKeyInfo==0 && p->hasIncrblobCur ){ in sqlite3BtreeDelete()
9511 invalidateIncrblobCursors(p, pCur->pgnoRoot, pCur->info.nKey, 0); in sqlite3BtreeDelete()
9529 MemPage *pLeaf = pCur->pPage; in sqlite3BtreeDelete()
9538 if( iCellDepth<pCur->iPage-1 ){ in sqlite3BtreeDelete()
9539 n = pCur->apPage[iCellDepth+1]->pgno; in sqlite3BtreeDelete()
9541 n = pCur->pPage->pgno; in sqlite3BtreeDelete()
9572 assert( pCur->pPage->nOverflow==0 ); in sqlite3BtreeDelete()
9573 assert( pCur->pPage->nFree>=0 ); in sqlite3BtreeDelete()
9574 if( pCur->pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){ in sqlite3BtreeDelete()
9579 rc = balance(pCur); in sqlite3BtreeDelete()
9581 if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){ in sqlite3BtreeDelete()
9582 releasePageNotNull(pCur->pPage); in sqlite3BtreeDelete()
9583 pCur->iPage--; in sqlite3BtreeDelete()
9584 while( pCur->iPage>iCellDepth ){ in sqlite3BtreeDelete()
9585 releasePage(pCur->apPage[pCur->iPage--]); in sqlite3BtreeDelete()
9587 pCur->pPage = pCur->apPage[pCur->iPage]; in sqlite3BtreeDelete()
9588 rc = balance(pCur); in sqlite3BtreeDelete()
9593 assert( (pCur->iPage==iCellDepth || CORRUPT_DB) ); in sqlite3BtreeDelete()
9594 assert( pPage==pCur->pPage || CORRUPT_DB ); in sqlite3BtreeDelete()
9596 pCur->eState = CURSOR_SKIPNEXT; in sqlite3BtreeDelete()
9598 pCur->skipNext = -1; in sqlite3BtreeDelete()
9599 pCur->ix = pPage->nCell-1; in sqlite3BtreeDelete()
9601 pCur->skipNext = 1; in sqlite3BtreeDelete()
9604 rc = moveToRoot(pCur); in sqlite3BtreeDelete()
9606 btreeReleaseAllCursorPages(pCur); in sqlite3BtreeDelete()
9607 pCur->eState = CURSOR_REQUIRESEEK; in sqlite3BtreeDelete()
9876 int sqlite3BtreeClearTableOfCursor(BtCursor *pCur){ in sqlite3BtreeClearTableOfCursor() argument
9877 return sqlite3BtreeClearTable(pCur->pBtree, pCur->pgnoRoot, 0); in sqlite3BtreeClearTableOfCursor()
10076 int sqlite3BtreeCount(sqlite3 *db, BtCursor *pCur, i64 *pnEntry){ in sqlite3BtreeCount() argument
10080 rc = moveToRoot(pCur); in sqlite3BtreeCount()
10097 pPage = pCur->pPage; in sqlite3BtreeCount()
10114 if( pCur->iPage==0 ){ in sqlite3BtreeCount()
10117 return moveToRoot(pCur); in sqlite3BtreeCount()
10119 moveToParent(pCur); in sqlite3BtreeCount()
10120 }while ( pCur->ix>=pCur->pPage->nCell ); in sqlite3BtreeCount()
10122 pCur->ix++; in sqlite3BtreeCount()
10123 pPage = pCur->pPage; in sqlite3BtreeCount()
10129 iIdx = pCur->ix; in sqlite3BtreeCount()
10131 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8])); in sqlite3BtreeCount()
10133 rc = moveToChild(pCur, get4byte(findCell(pPage, iIdx))); in sqlite3BtreeCount()
11013 void sqlite3BtreeIncrblobCursor(BtCursor *pCur){ in sqlite3BtreeIncrblobCursor() argument
11014 pCur->curFlags |= BTCF_Incrblob; in sqlite3BtreeIncrblobCursor()
11015 pCur->pBtree->hasIncrblobCur = 1; in sqlite3BtreeIncrblobCursor()