Lines Matching refs:pCur
6722 ** ^The current value of the requested parameter is written into *pCur
6732 SQLITE_API int SQLITE_STDCALL sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
52944 SQLITE_PRIVATE void sqlite3BtreeEnterCursor(BtCursor *pCur){
52945 sqlite3BtreeEnter(pCur->pBtree);
52947 SQLITE_PRIVATE void sqlite3BtreeLeaveCursor(BtCursor *pCur){
52948 sqlite3BtreeLeave(pCur->pBtree);
53528 #define invalidateOverflowCache(pCur) (pCur->curFlags &= ~BTCF_ValidOvfl)
53652 static void btreeReleaseAllCursorPages(BtCursor *pCur){
53654 for(i=0; i<=pCur->iPage; i++){
53655 releasePage(pCur->apPage[i]);
53656 pCur->apPage[i] = 0;
53658 pCur->iPage = -1;
53669 static int saveCursorPosition(BtCursor *pCur){
53672 assert( CURSOR_VALID==pCur->eState || CURSOR_SKIPNEXT==pCur->eState );
53673 assert( 0==pCur->pKey );
53674 assert( cursorHoldsMutex(pCur) );
53676 if( pCur->eState==CURSOR_SKIPNEXT ){
53677 pCur->eState = CURSOR_VALID;
53679 pCur->skipNext = 0;
53681 rc = sqlite3BtreeKeySize(pCur, &pCur->nKey);
53685 ** stores the integer key in pCur->nKey. In this case this value is
53686 ** all that is required. Otherwise, if pCur is not open on an intKey
53687 ** table, then malloc space for and store the pCur->nKey bytes of key
53690 if( 0==pCur->apPage[0]->intKey ){
53691 void *pKey = sqlite3Malloc( pCur->nKey );
53693 rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey);
53695 pCur->pKey = pKey;
53703 assert( !pCur->apPage[0]->intKey || !pCur->pKey );
53706 btreeReleaseAllCursorPages(pCur);
53707 pCur->eState = CURSOR_REQUIRESEEK;
53710 invalidateOverflowCache(pCur);
53769 SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *pCur){
53770 assert( cursorHoldsMutex(pCur) );
53771 sqlite3_free(pCur->pKey);
53772 pCur->pKey = 0;
53773 pCur->eState = CURSOR_INVALID;
53782 BtCursor *pCur, /* Cursor open on the btree to be searched */
53796 pCur->pKeyInfo, aSpace, sizeof(aSpace), &pFree
53799 sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
53801 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
53807 rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
53809 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
53821 static int btreeRestoreCursorPosition(BtCursor *pCur){
53824 assert( cursorHoldsMutex(pCur) );
53825 assert( pCur->eState>=CURSOR_REQUIRESEEK );
53826 if( pCur->eState==CURSOR_FAULT ){
53827 return pCur->skipNext;
53829 pCur->eState = CURSOR_INVALID;
53830 rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
53832 sqlite3_free(pCur->pKey);
53833 pCur->pKey = 0;
53834 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
53835 pCur->skipNext |= skipNext;
53836 if( pCur->skipNext && pCur->eState==CURSOR_VALID ){
53837 pCur->eState = CURSOR_SKIPNEXT;
53860 SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor *pCur){
53861 return pCur->eState!=CURSOR_VALID;
53877 SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor *pCur, int *pDifferentRow){
53880 assert( pCur!=0 );
53881 assert( pCur->eState!=CURSOR_VALID );
53882 rc = restoreCursorPosition(pCur);
53887 if( pCur->eState!=CURSOR_VALID ){
53890 assert( pCur->skipNext==0 );
55333 BtCursor *pCur;
55338 pCur = pBt->pCursor;
55339 while( pCur ){
55340 BtCursor *pTmp = pCur;
55341 pCur = pCur->pNext;
55825 BtCursor *pCur;
55827 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
55828 if( (wrOnly==0 || (pCur->curFlags & BTCF_WriteFlag)!=0)
55829 && pCur->eState!=CURSOR_FAULT ) r++;
56895 ** on pCur to initialize the memory space prior to invoking this routine.
56902 BtCursor *pCur /* Space for new cursor */
56935 pCur->pgnoRoot = (Pgno)iTable;
56936 pCur->iPage = -1;
56937 pCur->pKeyInfo = pKeyInfo;
56938 pCur->pBtree = p;
56939 pCur->pBt = pBt;
56941 pCur->curFlags = wrFlag;
56942 pCur->pNext = pBt->pCursor;
56943 if( pCur->pNext ){
56944 pCur->pNext->pPrev = pCur;
56946 pBt->pCursor = pCur;
56947 pCur->eState = CURSOR_INVALID;
56955 BtCursor *pCur /* Write new cursor here */
56959 rc = btreeCursor(p, iTable, wrFlag, pKeyInfo, pCur);
56992 SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){
56993 Btree *pBtree = pCur->pBtree;
56996 BtShared *pBt = pCur->pBt;
56998 sqlite3BtreeClearCursor(pCur);
56999 if( pCur->pPrev ){
57000 pCur->pPrev->pNext = pCur->pNext;
57002 pBt->pCursor = pCur->pNext;
57004 if( pCur->pNext ){
57005 pCur->pNext->pPrev = pCur->pPrev;
57007 for(i=0; i<=pCur->iPage; i++){
57008 releasePage(pCur->apPage[i]);
57011 sqlite3_free(pCur->aOverflow);
57012 /* sqlite3_free(pCur); */
57034 static void assertCellInfo(BtCursor *pCur){
57036 int iPage = pCur->iPage;
57038 btreeParseCell(pCur->apPage[iPage], pCur->aiIdx[iPage], &info);
57039 assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 );
57046 static void getCellInfo(BtCursor *pCur){
57047 if( pCur->info.nSize==0 ){
57048 int iPage = pCur->iPage;
57049 btreeParseCell(pCur->apPage[iPage],pCur->aiIdx[iPage],&pCur->info);
57050 pCur->curFlags |= BTCF_ValidNKey;
57052 assertCellInfo(pCur);
57057 #define getCellInfo(pCur) \
57058 if( pCur->info.nSize==0 ){ \
57059 int iPage = pCur->iPage; \
57060 btreeParseCell(pCur->apPage[iPage],pCur->aiIdx[iPage],&pCur->info); \
57061 pCur->curFlags |= BTCF_ValidNKey; \
57063 assertCellInfo(pCur); \
57073 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor *pCur){
57074 return pCur && pCur->eState==CURSOR_VALID;
57090 SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){
57091 assert( cursorHoldsMutex(pCur) );
57092 assert( pCur->eState==CURSOR_VALID );
57093 getCellInfo(pCur);
57094 *pSize = pCur->info.nKey;
57110 SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){
57111 assert( cursorHoldsMutex(pCur) );
57112 assert( pCur->eState==CURSOR_VALID );
57113 assert( pCur->iPage>=0 );
57114 assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
57115 assert( pCur->apPage[pCur->iPage]->intKeyLeaf==1 );
57116 getCellInfo(pCur);
57117 *pSize = pCur->info.nPayload;
57231 ** for the entry that the pCur cursor is pointing to. The eOp
57260 BtCursor *pCur, /* Cursor pointing to entry to read from */
57269 MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
57270 BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
57277 assert( pCur->eState==CURSOR_VALID );
57278 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
57279 assert( cursorHoldsMutex(pCur) );
57282 getCellInfo(pCur);
57283 aPayload = pCur->info.pPayload;
57285 bEnd = offset+amt==pCur->info.nPayload;
57287 assert( offset+amt <= pCur->info.nPayload );
57289 if( &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize] ){
57295 if( offset<pCur->info.nLocal ){
57297 if( a+offset>pCur->info.nLocal ){
57298 a = pCur->info.nLocal - offset;
57305 offset -= pCur->info.nLocal;
57313 nextPage = get4byte(&aPayload[pCur->info.nLocal]);
57323 if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){
57324 int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
57325 if( nOvfl>pCur->nOvflAlloc ){
57327 pCur->aOverflow, nOvfl*2*sizeof(Pgno)
57332 pCur->nOvflAlloc = nOvfl*2;
57333 pCur->aOverflow = aNew;
57337 memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno));
57338 pCur->curFlags |= BTCF_ValidOvfl;
57346 if( (pCur->curFlags & BTCF_ValidOvfl)!=0
57347 && pCur->aOverflow[offset/ovflSize]
57350 nextPage = pCur->aOverflow[iIdx];
57357 if( (pCur->curFlags & BTCF_ValidOvfl)!=0 ){
57358 assert(!pCur->aOverflow[iIdx] || pCur->aOverflow[iIdx]==nextPage);
57359 pCur->aOverflow[iIdx] = nextPage;
57373 assert( pCur->curFlags & BTCF_ValidOvfl );
57374 assert( pCur->pBtree->db==pBt->db );
57375 if( pCur->aOverflow[iIdx+1] ){
57376 nextPage = pCur->aOverflow[iIdx+1];
57452 ** Read part of the key associated with cursor pCur. Exactly
57456 ** The caller must ensure that pCur is pointing to a valid row
57463 SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
57464 assert( cursorHoldsMutex(pCur) );
57465 assert( pCur->eState==CURSOR_VALID );
57466 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
57467 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
57468 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
57472 ** Read part of the data associated with cursor pCur. Exactly
57480 SQLITE_PRIVATE int sqlite3BtreeData(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
57484 if ( pCur->eState==CURSOR_INVALID ){
57489 assert( cursorHoldsMutex(pCur) );
57490 rc = restoreCursorPosition(pCur);
57492 assert( pCur->eState==CURSOR_VALID );
57493 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
57494 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
57495 rc = accessPayload(pCur, offset, amt, pBuf, 0);
57502 ** pCur cursor is pointing to. The pointer is to the beginning of
57520 BtCursor *pCur, /* Cursor pointing to entry to read from */
57524 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
57525 assert( pCur->eState==CURSOR_VALID );
57526 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
57527 assert( cursorHoldsMutex(pCur) );
57528 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
57529 assert( pCur->info.nSize>0 );
57530 assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
57531 assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
57532 amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
57533 if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
57535 return (void*)pCur->info.pPayload;
57540 ** For the entry that cursor pCur is point to, return as
57553 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){
57554 return fetchPayload(pCur, pAmt);
57556 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
57557 return fetchPayload(pCur, pAmt);
57570 static int moveToChild(BtCursor *pCur, u32 newPgno){
57572 int i = pCur->iPage;
57574 BtShared *pBt = pCur->pBt;
57576 assert( cursorHoldsMutex(pCur) );
57577 assert( pCur->eState==CURSOR_VALID );
57578 assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
57579 assert( pCur->iPage>=0 );
57580 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
57584 (pCur->curFlags & BTCF_WriteFlag)==0 ? PAGER_GET_READONLY : 0);
57586 pCur->apPage[i+1] = pNewPage;
57587 pCur->aiIdx[i+1] = 0;
57588 pCur->iPage++;
57590 pCur->info.nSize = 0;
57591 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
57592 if( pNewPage->nCell<1 || pNewPage->intKey!=pCur->apPage[i]->intKey ){
57623 ** pCur->idx is set to the cell index that contains the pointer
57625 ** right-most child page then pCur->idx is set to one more than
57628 static void moveToParent(BtCursor *pCur){
57629 assert( cursorHoldsMutex(pCur) );
57630 assert( pCur->eState==CURSOR_VALID );
57631 assert( pCur->iPage>0 );
57632 assert( pCur->apPage[pCur->iPage] );
57634 pCur->apPage[pCur->iPage-1],
57635 pCur->aiIdx[pCur->iPage-1],
57636 pCur->apPage[pCur->iPage]->pgno
57638 testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
57640 releasePage(pCur->apPage[pCur->iPage]);
57641 pCur->iPage--;
57642 pCur->info.nSize = 0;
57643 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
57667 static int moveToRoot(BtCursor *pCur){
57671 assert( cursorHoldsMutex(pCur) );
57675 if( pCur->eState>=CURSOR_REQUIRESEEK ){
57676 if( pCur
57677 assert( pCur->skipNext!=SQLITE_OK );
57678 return pCur->skipNext;
57680 sqlite3BtreeClearCursor(pCur);
57683 if( pCur->iPage>=0 ){
57684 while( pCur->iPage ) releasePage(pCur->apPage[pCur->iPage--]);
57685 }else if( pCur->pgnoRoot==0 ){
57686 pCur->eState = CURSOR_INVALID;
57689 rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
57690 (pCur->curFlags & BTCF_WriteFlag)==0 ? PAGER_GET_READONLY : 0);
57692 pCur->eState = CURSOR_INVALID;
57695 pCur->iPage = 0;
57697 pRoot = pCur->apPage[0];
57698 assert( pRoot->pgno==pCur->pgnoRoot );
57700 /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
57707 ** if pCur->iPage>=0). But this is not so if the database is corrupted
57711 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
57715 pCur->aiIdx[0] = 0;
57716 pCur->info.nSize = 0;
57717 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl);
57720 pCur->eState = CURSOR_VALID;
57725 pCur->eState = CURSOR_VALID;
57726 rc = moveToChild(pCur, subpage);
57728 pCur->eState = CURSOR_INVALID;
57740 static int moveToLeftmost(BtCursor *pCur){
57745 assert( cursorHoldsMutex(pCur) );
57746 assert( pCur->eState==CURSOR_VALID );
57747 while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){
57748 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
57749 pgno = get4byte(findCell(pPage, pCur->aiIdx[pCur->iPage]));
57750 rc = moveToChild(pCur, pgno);
57765 static int moveToRightmost(BtCursor *pCur){
57770 assert( cursorHoldsMutex(pCur) );
57771 assert( pCur->eState==CURSOR_VALID );
57772 while( !(pPage = pCur->apPage[pCur->iPage])->leaf ){
57774 pCur->aiIdx[pCur->iPage] = pPage->nCell;
57775 rc = moveToChild(pCur, pgno);
57778 pCur->aiIdx[pCur->iPage] = pPage->nCell-1;
57779 assert( pCur->info.nSize==0 );
57780 assert( (pCur->curFlags & BTCF_ValidNKey)==0 );
57788 SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor *pCur, int *pRes){
57791 assert( cursorHoldsMutex(pCur) );
57792 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
57793 rc = moveToRoot(pCur);
57795 if( pCur->eState==CURSOR_INVALID ){
57796 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
57799 assert( pCur->apPage[pCur->iPage]->nCell>0 );
57801 rc = moveToLeftmost(pCur);
57811 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
57814 assert( cursorHoldsMutex(pCur) );
57815 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
57818 if( CURSOR_VALID==pCur->eState && (pCur->curFlags & BTCF_AtLast)!=0 ){
57823 for(ii=0; ii<pCur->iPage; ii++){
57824 assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
57826 assert( pCur->aiIdx[pCur->iPage]==pCur->apPage[pCur->iPage]->nCell-1 );
57827 assert( pCur->apPage[pCur->iPage]->leaf );
57832 rc = moveToRoot(pCur);
57834 if( CURSOR_INVALID==pCur->eState ){
57835 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
57838 assert( pCur->eState==CURSOR_VALID );
57840 rc = moveToRightmost(pCur);
57842 pCur->curFlags |= BTCF_AtLast;
57844 pCur->curFlags &= ~BTCF_AtLast;
57881 BtCursor *pCur, /* The cursor to be moved */
57890 assert( cursorHoldsMutex(pCur) );
57891 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
57893 assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );
57897 if( pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0
57898 && pCur->apPage[0]->intKey
57900 if( pCur->info.nKey==intKey ){
57904 if( (pCur->curFlags & BTCF_AtLast)!=0 && pCur->info.nKey<intKey ){
57921 rc = moveToRoot(pCur);
57925 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage] );
57926 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->isInit );
57927 assert( pCur->eState==CURSOR_INVALID || pCur->apPage[pCur->iPage]->nCell>0 );
57928 if( pCur->eState==CURSOR_INVALID ){
57930 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
57933 assert( pCur->apPage[0]->intKey || pIdxKey );
57937 MemPage *pPage = pCur->apPage[pCur->iPage];
57952 pCur->aiIdx[pCur->iPage] = (u16)idx;
57971 pCur->curFlags |= BTCF_ValidNKey;
57972 pCur->info.nKey = nCellKey;
57973 pCur->aiIdx[pCur->iPage] = (u16)idx;
58020 btreeParseCellPtr(pPage, pCellBody, &pCur->info);
58021 nCell = (int)pCur->info.nKey;
58027 pCur->aiIdx[pCur->iPage] = (u16)idx;
58028 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 2);
58038 && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
58048 pCur->aiIdx[pCur->iPage] = (u16)idx;
58060 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
58061 pCur->aiIdx[pCur->iPage] = (u16)idx;
58072 pCur->aiIdx[pCur->iPage] = (u16)lwr;
58073 rc = moveToChild(pCur, chldPg);
58077 pCur->info.nSize = 0;
58078 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
58090 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor *pCur){
58095 return (CURSOR_VALID!=pCur->eState);
58119 static SQLITE_NOINLINE int btreeNext(BtCursor *pCur, int *pRes){
58124 assert( cursorHoldsMutex(pCur) );
58125 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
58127 if( pCur->eState!=CURSOR_VALID ){
58128 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
58129 rc = restoreCursorPosition(pCur);
58133 if( CURSOR_INVALID==pCur->eState ){
58137 if( pCur->skipNext ){
58138 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT );
58139 pCur->eState = CURSOR_VALID;
58140 if( pCur->skipNext>0 ){
58141 pCur->skipNext = 0;
58144 pCur->skipNext = 0;
58148 pPage = pCur->apPage[pCur->iPage];
58149 idx = ++pCur->aiIdx[pCur->iPage];
58154 ** the page while cursor pCur is holding a reference to it. Which can
58161 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
58163 return moveToLeftmost(pCur);
58166 if( pCur->iPage==0 ){
58168 pCur->eState = CURSOR_INVALID;
58171 moveToParent(pCur);
58172 pPage = pCur->apPage[pCur->iPage];
58173 }while( pCur->aiIdx[pCur->iPage]>=pPage->nCell );
58175 return sqlite3BtreeNext(pCur, pRes);
58183 return moveToLeftmost(pCur);
58186 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int *pRes){
58188 assert( cursorHoldsMutex(pCur) );
58191 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
58192 pCur->info.nSize = 0;
58193 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
58195 if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur, pRes);
58196 pPage = pCur->apPage[pCur->iPage];
58197 if( (++pCur->aiIdx[pCur->iPage])>=pPage->nCell ){
58198 pCur->aiIdx[pCur->iPage]--;
58199 return btreeNext(pCur, pRes);
58204 return moveToLeftmost(pCur);
58229 static SQLITE_NOINLINE int btreePrevious(BtCursor *pCur, int *pRes){
58233 assert( cursorHoldsMutex(pCur) );
58236 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
58237 assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 );
58238 assert( pCur->info.nSize==0 );
58239 if( pCur->eState!=CURSOR_VALID ){
58240 rc = restoreCursorPosition(pCur);
58244 if( CURSOR_INVALID==pCur->eState ){
58248 if( pCur->skipNext ){
58249 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT );
58250 pCur->eState = CURSOR_VALID;
58251 if( pCur->skipNext<0 ){
58252 pCur->skipNext = 0;
58255 pCur->skipNext = 0;
58259 pPage = pCur->apPage[pCur->iPage];
58262 int idx = pCur->aiIdx[pCur->iPage];
58263 rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
58265 rc = moveToRightmost(pCur);
58267 while( pCur->aiIdx[pCur->iPage]==0 ){
58268 if( pCur->iPage==0 ){
58269 pCur->eState = CURSOR_INVALID;
58273 moveToParent(pCur);
58275 assert( pCur->info.nSize==0 );
58276 assert( (pCur->curFlags & (BTCF_ValidNKey|BTCF_ValidOvfl))==0 );
58278 pCur->aiIdx[pCur->iPage]--;
58279 pPage = pCur->apPage[pCur->iPage];
58281 rc = sqlite3BtreePrevious(pCur, pRes);
58288 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){
58289 assert( cursorHoldsMutex(pCur) );
58292 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
58294 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
58295 pCur->info.nSize = 0;
58296 if( pCur->eState!=CURSOR_VALID
58297 || pCur->aiIdx[pCur->iPage]==0
58298 || pCur->apPage[pCur->iPage]->leaf==0
58300 return btreePrevious(pCur, pRes);
58302 pCur->aiIdx[pCur->iPage]--;
60471 ** The page that pCur currently points to has just been modified in
60480 static int balance(BtCursor *pCur){
60482 const int nMin = pCur->pBt->usableSize * 2 / 3;
60490 int iPage = pCur->iPage;
60491 MemPage *pPage = pCur->apPage[iPage];
60501 rc = balance_deeper(pPage, &pCur->apPage[1]);
60503 pCur->iPage = 1;
60504 pCur->aiIdx[0] = 0;
60505 pCur->aiIdx[1] = 0;
60506 assert( pCur->apPage[1]->nOverflow );
60514 MemPage * const pParent = pCur->apPage[iPage-1];
60515 int const iIdx = pCur->aiIdx[iPage-1];
60561 u8 *pSpace = sqlite3PageMalloc(pCur->pBt->pageSize);
60563 pCur->hints&BTREE_BULKLOAD);
60583 pCur->iPage--;
60584 assert( pCur->iPage>=0 );
60605 ** MovetoUnpacked() to seek cursor pCur to (pKey, nKey) has already
60607 ** number if pCur points at an entry that is smaller than (pKey, nKey), or
60608 ** a positive value if pCur points at an entry that is larger than
60612 ** cursor pCur is pointing at the existing copy of a row that is to be
60613 ** overwritten. If the seekResult parameter is 0, then cursor pCur may
60618 BtCursor *pCur, /* Insert data into the table of this cursor */
60630 Btree *p = pCur->pBtree;
60635 if( pCur->eState==CURSOR_FAULT ){
60636 assert( pCur->skipNext!=SQLITE_OK );
60637 return pCur->skipNext;
60640 assert( cursorHoldsMutex(pCur) );
60641 assert( (pCur->curFlags & BTCF_WriteFlag)!=0
60644 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
60651 assert( (pKey==0)==(pCur->pKeyInfo==0) );
60664 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
60667 if( pCur->pKeyInfo==0 ){
60675 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && nKey>0
60676 && pCur->info.nKey==nKey-1 ){
60682 rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc);
60685 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
60687 pPage = pCur->apPage[pCur->iPage];
60692 pCur->pgnoRoot, nKey, nData, pPage->pgno,
60701 idx = pCur->aiIdx[pCur->iPage];
60718 idx = ++pCur->aiIdx[pCur->iPage];
60745 pCur->info.nSize = 0;
60747 pCur->curFlags &= ~(BTCF_ValidNKey);
60748 rc = balance(pCur);
60754 pCur->apPage[pCur->iPage]->nOverflow = 0;
60755 pCur->eState = CURSOR_INVALID;
60757 assert( pCur->apPage[pCur->iPage]->nOverflow==0 );
60767 SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur){
60768 Btree *p = pCur->pBtree;
60777 assert( cursorHoldsMutex(pCur) );
60780 assert( pCur->curFlags & BTCF_WriteFlag );
60781 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
60782 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
60784 if( NEVER(pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell)
60785 || NEVER(pCur->eState!=CURSOR_VALID)
60790 iCellDepth = pCur->iPage;
60791 iCellIdx = pCur->aiIdx[iCellDepth];
60792 pPage = pCur
60804 rc = sqlite3BtreePrevious(pCur, ¬Used);
60813 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
60818 if( pCur->pKeyInfo==0 ){
60819 invalidateIncrblobCursors(p, pCur->info.nKey, 0);
60834 MemPage *pLeaf = pCur->apPage[pCur->iPage];
60836 Pgno n = pCur->apPage[iCellDepth+1]->pgno;
60856 ** pCur is pointing to the leaf page from which a cell was removed to
60865 rc = balance(pCur);
60866 if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){
60867 while( pCur->iPage>iCellDepth ){
60868 releasePage(pCur->apPage[pCur->iPage--]);
60870 rc = balance(pCur);
60874 moveToRoot(pCur);
61130 ** Delete all information from the single table that pCur is open on.
61132 ** This routine only work for pCur on an ephemeral table.
61134 SQLITE_PRIVATE int sqlite3BtreeClearTableOfCursor(BtCursor *pCur){
61135 return sqlite3BtreeClearTable(pCur->pBtree, pCur->pgnoRoot, 0);
61346 ** The first argument, pCur, is a cursor opened on some b-tree. Count the
61353 SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *pCur, i64 *pnEntry){
61357 if( pCur->pgnoRoot==0 ){
61361 rc = moveToRoot(pCur);
61374 pPage = pCur->apPage[pCur->iPage];
61382 ** pCur->aiIdx[pCur->iPage] value is set to the index of the parent cell
61391 if( pCur->iPage==0 ){
61394 return moveToRoot(pCur);
61396 moveToParent(pCur);
61397 }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
61399 pCur->aiIdx[pCur->iPage]++;
61400 pPage = pCur->apPage[pCur->iPage];
61406 iIdx = pCur->aiIdx[pCur->iPage];
61408 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
61410 rc = moveToChild(pCur, get4byte(findCell(pPage, iIdx)));
62246 SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *pCur){
62247 pCur->curFlags |= BTCF_Incrblob;
64040 ** The data or key is taken from the entry that pCur is currently pointing
64055 BtCursor *pCur, /* Cursor pointing at record to retrieve. */
64065 assert( sqlite3BtreeCursorIsValid(pCur) );
64072 zData = (char *)sqlite3BtreeKeyFetch(pCur, &available);
64074 zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
64086 rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
64088 rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
68784 ** pCur points at an index entry created using the OP_MakeRecord opcode.
68788 ** pCur might be pointing to text obtained from a corrupt database file.
68791 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
68804 assert( sqlite3BtreeCursorIsValid(pCur) );
68805 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
68806 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
68811 rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
68877 BtCursor *pCur = pC->pCursor;
68880 assert( sqlite3BtreeCursorIsValid(pCur) );
68881 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
68882 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
74126 VdbeCursor *pCur;
74131 pCur = p->apCsr[pOp->p1];
74132 if( pCur && pCur->pgnoRoot==(u32)pOp->p2 ){
74133 assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */
74198 pCur = allocateCursor(p, pOp->p1, nField, iDb, 1);
74199 if( pCur==0 ) goto no_mem;
74200 pCur->nullRow = 1;
74201 pCur->isOrdered = 1;
74202 pCur->pgnoRoot = p2;
74203 rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
74204 pCur->pKeyInfo = pKeyInfo;
74209 pCur->isTable = pOp->p4type!=P4_KEYINFO;
74214 sqlite3BtreeCursorHints(pCur->pCursor,
76934 VdbeCursor *pCur;
76940 pCur = 0;
76955 pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
76956 if( pCur ){
76957 pCur->pVtabCursor = pVtabCursor;
76997 VdbeCursor *pCur;
77004 pCur = p->apCsr[pOp->p1];
77007 assert( pCur->pVtabCursor );
77008 pVtabCursor = pCur->pVtabCursor;
77028 pCur->nullRow = 0;
77049 VdbeCursor *pCur = p->apCsr[pOp->p1];
77050 assert( pCur->pVtabCursor );
77054 if( pCur->nullRow ){
77058 pVtab = pCur->pVtabCursor->pVtab;
77064 rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2);
77091 VdbeCursor *pCur;
77094 pCur = p->apCsr[pOp->p1];
77095 assert( pCur->pVtabCursor );
77096 if( pCur->nullRow ){
77099 pVtab = pCur->pVtabCursor->pVtab;
77109 rc = pModule->xNext(pCur->pVtabCursor);
77112 res = pModule->xEof(pCur->pVtabCursor);
152142 static RtreeSearchPoint *rtreeSearchPointFirst(RtreeCursor *pCur){
152143 return pCur->bPoint ? &pCur->sPoint : pCur->nPoint ? pCur->aPoint : 0;
152149 static RtreeNode *rtreeNodeOfFirstSearchPoint(RtreeCursor *pCur, int *pRC){
152151 int ii = 1 - pCur->bPoint;
152153 assert( pCur->bPoint || pCur->nPoint );
152154 if( pCur->aNode[ii]==0 ){
152156 id = ii ? pCur->aPoint[0].id : pCur->sPoint.id;
152157 *pRC = nodeAcquire(RTREE_OF_CURSOR(pCur), id, 0, &pCur->aNode[ii]);
152159 return pCur->aNode[ii];
152166 RtreeCursor *pCur, /* The cursor */
152172 if( pCur->nPoint>=pCur->nPointAlloc ){
152173 int nNew = pCur->nPointAlloc*2 + 8;
152174 pNew = sqlite3_realloc(pCur->aPoint, nNew*sizeof(pCur->aPoint[0]));
152176 pCur->aPoint = pNew;
152177 pCur->nPointAlloc = nNew;
152179 i = pCur->nPoint++;
152180 pNew = pCur->aPoint + i;
152187 pParent = pCur->aPoint + j;
152189 rtreeSearchPointSwap(pCur, j, i);
152201 RtreeCursor *pCur, /* The cursor */
152206 pFirst = rtreeSearchPointFirst(pCur);
152207 pCur->anQueue[iLevel]++;
152212 if( pCur->bPoint ){
152214 pNew = rtreeEnqueue(pCur, rScore, iLevel);
152216 ii = (int)(pNew - pCur->aPoint) + 1;
152218 assert( pCur->aNode[ii]==0 );
152219 pCur->aNode[ii] = pCur->aNode[0];
152221 nodeRelease(RTREE_OF_CURSOR(pCur), pCur->aNode[0]);
152223 pCur->aNode[0] = 0;
152224 *pNew = pCur->sPoint;
152226 pCur->sPoint.rScore = rScore;
152227 pCur->sPoint.iLevel = iLevel;
152228 pCur->bPoint = 1;
152229 return &pCur->sPoint;
152231 return rtreeEnqueue(pCur, rScore, iLevel);
152237 static void tracePoint(RtreeSearchPoint *p, int idx, RtreeCursor *pCur){
152244 printf(" %p\n", pCur->aNode[idx]);
152249 static void traceQueue(RtreeCursor *pCur, const char *zPrefix){
152252 if( pCur->bPoint ){
152253 tracePoint(&pCur->sPoint, -1, pCur);
152255 for(ii=0; ii<pCur->nPoint; ii++){
152256 if( ii>0 || pCur->bPoint ) printf(" ");
152257 tracePoint(&pCur->aPoint[ii], ii, pCur);
152310 ** Continue the search on cursor pCur until the front of the queue
152315 static int rtreeStepToLeaf(RtreeCursor *pCur){
152317 Rtree *pRtree = RTREE_OF_CURSOR(pCur);
152322 int nConstraint = pCur->nConstraint;
152328 while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){
152329 pNode = rtreeNodeOfFirstSearchPoint(pCur, &rc);
152338 RtreeConstraint *pConstraint = pCur->aConstraint + ii;
152361 RTREE_QUEUE_TRACE(pCur, "POP-S:");
152362 rtreeSearchPointPop(pCur);
152365 p = rtreeSearchPointNew(pCur, rScore, x.iLevel);
152370 RTREE_QUEUE_TRACE(pCur, "PUSH-S:");
152374 RTREE_QUEUE_TRACE(pCur, "POP-Se:");
152375 rtreeSearchPointPop(pCur);
152378 pCur->atEOF = p==0;