Lines Matching full:pcur
6819 ** ^The current value of the requested parameter is written into *pCur
6829 SQLITE_API int SQLITE_STDCALL sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
54377 SQLITE_PRIVATE void sqlite3BtreeEnterCursor(BtCursor *pCur){
54378 sqlite3BtreeEnter(pCur->pBtree);
54380 SQLITE_PRIVATE void sqlite3BtreeLeaveCursor(BtCursor *pCur){
54381 sqlite3BtreeLeave(pCur->pBtree);
54962 #define invalidateOverflowCache(pCur) (pCur->curFlags &= ~BTCF_ValidOvfl)
55088 static void btreeReleaseAllCursorPages(BtCursor *pCur){
55090 for(i=0; i<=pCur->iPage; i++){
55091 releasePage(pCur->apPage[i]);
55092 pCur->apPage[i] = 0;
55094 pCur->iPage = -1;
55100 ** function saves the current cursor key in variables pCur->nKey and
55101 ** pCur->pKey. SQLITE_OK is returned if successful or an SQLite error
55105 ** (the rowid) is stored in pCur->nKey and pCur->pKey is left set to
55106 ** NULL. If the cursor is open on a non-intkey table, then pCur->pKey is
55107 ** set to point to a malloced buffer pCur->nKey bytes in size containing
55110 static int saveCursorKey(BtCursor *pCur){
55112 assert( CURSOR_VALID==pCur->eState );
55113 assert( 0==pCur->pKey );
55114 pCur) );
55116 rc = sqlite3BtreeKeySize(pCur, &pCur->nKey);
55120 ** stores the integer key in pCur->nKey. In this case this value is
55121 ** all that is required. Otherwise, if pCur is not open on an intKey
55122 ** table, then malloc space for and store the pCur->nKey bytes of key
55124 if( 0==pCur->curIntKey ){
55125 void *pKey = sqlite3Malloc( pCur->nKey );
55127 rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey);
55129 pCur->pKey = pKey;
55137 assert( !pCur->curIntKey || !pCur->pKey );
55148 static int saveCursorPosition(BtCursor *pCur){
55151 assert( CURSOR_VALID==pCur->eState || CURSOR_SKIPNEXT==pCur->eState );
55152 assert( 0==pCur->pKey );
55153 assert( cursorHoldsMutex(pCur) );
55155 if( pCur->eState==CURSOR_SKIPNEXT ){
55156 pCur->eState = CURSOR_VALID;
55158 pCur->skipNext = 0;
55161 rc = saveCursorKey(pCur);
55163 btreeReleaseAllCursorPages(pCur);
55164 pCur->eState = CURSOR_REQUIRESEEK;
55167 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl|BTCF_AtLast);
55237 SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *pCur){
55238 assert( cursorHoldsMutex(pCur) );
55239 sqlite3_free(pCur->pKey);
55240 pCur->pKey = 0;
55241 pCur->eState = CURSOR_INVALID;
55250 BtCursor *pCur, /* Cursor open on the btree to be searched */
55264 pCur->pKeyInfo, aSpace, sizeof(aSpace), &pFree
55267 sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
55269 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
55275 rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
55277 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
55289 static int btreeRestoreCursorPosition(BtCursor *pCur){
55292 assert( cursorHoldsMutex(pCur) );
55293 assert( pCur->eState>=CURSOR_REQUIRESEEK );
55294 if( pCur->eState==CURSOR_FAULT ){
55295 return pCur->skipNext;
55297 pCur->eState = CURSOR_INVALID;
55298 rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
55300 sqlite3_free(pCur->pKey);
55301 pCur->pKey = 0;
55302 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
55303 pCur->skipNext |= skipNext;
55304 if( pCur->skipNext && pCur->eState==CURSOR_VALID ){
55305 pCur->eState = CURSOR_SKIPNEXT;
55328 SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor *pCur){
55329 return pCur->eState!=CURSOR_VALID;
55345 SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor *pCur, int *pDifferentRow){
55348 assert( pCur!=0 );
55349 assert( pCur->eState!=CURSOR_VALID );
55350 rc = restoreCursorPosition(pCur);
55355 if( pCur->eState!=CURSOR_VALID ){
55358 assert( pCur->skipNext==0 );
56454 ** If pCur!=0 then the page is being fetched as part of a moveToChild()
56456 ** And if the fetch fails, this routine must decrement pCur->iPage.
56458 ** The page is fetched as read-write unless pCur is not NULL and is
56468 BtCursor *pCur, /* Cursor to receive the page, or NULL */
56474 assert( pCur==0 || ppPage==&pCur->apPage[pCur->iPage] );
56475 assert( pCur==0 || bReadOnly==pCur->curPagerFlags );
56476 assert( pCur==0 || pCur->iPage>0 );
56497 if( pCur
56498 && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey)
56507 if( pCur ) pCur->iPage--;
56984 BtCursor *pCur;
56989 pCur = pBt->pCursor;
56990 while( pCur ){
56991 BtCursor *pTmp = pCur;
56992 pCur = pCur->pNext;
57476 BtCursor *pCur;
57478 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
57479 if( (wrOnly==0 || (pCur->curFlags & BTCF_WriteFlag)!=0)
57480 && pCur->eState!=CURSOR_FAULT ) r++;
58548 ** on pCur to initialize the memory space prior to invoking this routine.
58555 BtCursor *pCur /* Space for new cursor */
58587 pCur->pgnoRoot = (Pgno)iTable;
58588 pCur->iPage = -1;
58589 pCur->pKeyInfo = pKeyInfo;
58590 pCur->pBtree = p;
58591 pCur->pBt = pBt;
58593 pCur->curFlags = wrFlag;
58594 pCur->curPagerFlags = wrFlag ? 0 : PAGER_GET_READONLY;
58600 pCur->curFlags |= BTCF_Multiple;
58603 pCur->pNext = pBt->pCursor;
58604 pBt->pCursor = pCur;
58605 pCur->eState = CURSOR_INVALID;
58613 BtCursor *pCur /* Write new cursor here */
58620 rc = btreeCursor(p, iTable, wrFlag, pKeyInfo, pCur);
58654 SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){
58655 Btree *pBtree = pCur->pBtree;
58658 BtShared *pBt = pCur->pBt;
58660 sqlite3BtreeClearCursor(pCur);
58662 if( pBt->pCursor==pCur ){
58663 pBt->pCursor = pCur->pNext;
58667 if( pPrev->pNext==pCur ){
58668 pPrev->pNext = pCur->pNext;
58674 for(i=0; i<=pCur->iPage; i++){
58675 releasePage(pCur->apPage[i]);
58678 sqlite3_free(pCur->aOverflow);
58679 /* sqlite3_free(pCur); */
58694 static void assertCellInfo(BtCursor *pCur){
58696 int iPage = pCur->iPage;
58698 btreeParseCell(pCur->apPage[iPage], pCur->aiIdx[iPage], &info);
58699 assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 );
58704 static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur){
58705 if( pCur->info.nSize==0 ){
58706 int iPage = pCur->iPage;
58707 pCur->curFlags |= BTCF_ValidNKey;
58708 btreeParseCell(pCur->apPage[iPage],pCur->aiIdx[iPage],&pCur->info);
58710 assertCellInfo(pCur);
58720 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor *pCur){
58721 return pCur && pCur->eState==CURSOR_VALID;
58737 SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){
58738 assert( cursorHoldsMutex(pCur) );
58739 assert( pCur->eState==CURSOR_VALID );
58740 getCellInfo(pCur);
58741 *pSize = pCur->info.nKey;
58757 SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){
58758 assert( cursorHoldsMutex(pCur) );
58759 assert( pCur->eState==CURSOR_VALID );
58760 assert( pCur->iPage>=0 );
58761 assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
58762 assert( pCur->apPage[pCur->iPage]->intKeyLeaf==1 );
58763 getCellInfo(pCur);
58764 *pSize = pCur->info.nPayload;
58878 ** for the entry that the pCur cursor is pointing to. The eOp
58907 BtCursor *pCur, /* Cursor pointing to entry to read from */
58916 MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
58917 BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
58924 assert( pCur->eState==CURSOR_VALID );
58925 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
58926 assert( cursorHoldsMutex(pCur) );
58929 getCellInfo(pCur);
58930 aPayload = pCur->info.pPayload;
58932 bEnd = offset+amt==pCur->info.nPayload;
58934 assert( offset+amt <= pCur->info.nPayload );
58936 if( &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize] ){
58942 if( offset<pCur->info.nLocal ){
58944 if( a+offset>pCur->info.nLocal ){
58945 a = pCur->info.nLocal - offset;
58952 offset -= pCur->info.nLocal;
58960 nextPage = get4byte(&aPayload[pCur->info.nLocal]);
58970 if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){
58971 int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
58972 if( nOvfl>pCur->nOvflAlloc ){
58974 pCur->aOverflow, nOvfl*2*sizeof(Pgno)
58979 pCur->nOvflAlloc = nOvfl*2;
58980 pCur->aOverflow = aNew;
58984 memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno));
58985 pCur->curFlags |= BTCF_ValidOvfl;
58993 if( (pCur->curFlags & BTCF_ValidOvfl)!=0
58994 && pCur->aOverflow[offset/ovflSize]
58997 nextPage = pCur->aOverflow[iIdx];
59004 if( (pCur->curFlags & BTCF_ValidOvfl)!=0 ){
59005 assert(!pCur->aOverflow[iIdx] || pCur->aOverflow[iIdx]==nextPage);
59006 pCur->aOverflow[iIdx] = nextPage;
59020 assert( pCur->curFlags & BTCF_ValidOvfl );
59021 assert( pCur->pBtree->db==pBt->db );
59022 if( pCur->aOverflow[iIdx+1] ){
59023 nextPage = pCur->aOverflow[iIdx+1];
59099 ** Read part of the key associated with cursor pCur. Exactly
59103 ** The caller must ensure that pCur is pointing to a valid row
59110 SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
59111 assert( cursorHoldsMutex(pCur) );
59112 assert( pCur->eState==CURSOR_VALID );
59113 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
59114 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
59115 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
59119 ** Read part of the data associated with cursor pCur. Exactly
59127 SQLITE_PRIVATE int sqlite3BtreeData(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
59131 if ( pCur->eState==CURSOR_INVALID ){
59136 assert( cursorHoldsMutex(pCur) );
59137 rc = restoreCursorPosition(pCur);
59139 assert( pCur->eState==CURSOR_VALID );
59140 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
59141 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
59142 rc = accessPayload(pCur, offset, amt, pBuf, 0);
59149 ** pCur cursor is pointing to. The pointer is to the beginning of
59167 BtCursor *pCur, /* Cursor pointing to entry to read from */
59171 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
59172 assert( pCur->eState==CURSOR_VALID );
59173 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
59174 assert( cursorHoldsMutex(pCur) );
59175 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
59176 assert( pCur->info.nSize>0 );
59177 assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
59178 assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
59179 amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
59180 if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
59182 return (void*)pCur->info.pPayload;
59187 ** For the entry that cursor pCur is point to, return as
59200 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){
59201 return fetchPayload(pCur, pAmt);
59203 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
59204 return fetchPayload(pCur, pAmt);
59217 static int moveToChild(BtCursor *pCur, u32 newPgno){
59218 BtShared *pBt = pCur->pBt;
59220 assert( cursorHoldsMutex(pCur) );
59221 assert( pCur->eState==CURSOR_VALID );
59222 assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
59223 assert( pCur->iPage>=0 );
59224 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
59227 pCur->info.nSize = 0;
59228 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
59229 pCur->iPage++;
59230 pCur->aiIdx[pCur->iPage] = 0;
59231 return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage],
59232 pCur, pCur->curPagerFlags);
59260 ** pCur->idx is set to the cell index that contains the pointer
59262 ** right-most child page then pCur->idx is set to one more than
59265 static void moveToParent(BtCursor *pCur){
59266 assert( cursorHoldsMutex(pCur) );
59267 assert( pCur->eState==CURSOR_VALID );
59268 assert( pCur->iPage>0 );
59269 assert( pCur->apPage[pCur->iPage] );
59271 pCur->apPage[pCur->iPage-1],
59272 pCur->aiIdx[pCur->iPage-1],
59273 pCur->apPage[pCur->iPage]->pgno
59275 testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
59276 pCur->info.nSize = 0;
59277 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
59278 releasePageNotNull(pCur->apPage[pCur->iPage--]);
59302 static int moveToRoot(BtCursor *pCur){
59306 assert( cursorHoldsMutex(pCur) );
59310 if( pCur->eState>=CURSOR_REQUIRESEEK ){
59311 if( pCur->eState==CURSOR_FAULT ){
59312 assert( pCur->skipNext!=SQLITE_OK );
59313 return pCur->skipNext;
59315 sqlite3BtreeClearCursor(pCur);
59318 if( pCur->iPage>=0 ){
59319 while( pCur->iPage ){
59320 assert( pCur->apPage[pCur->iPage]!=0 );
59321 releasePageNotNull(pCur->apPage[pCur->iPage--]);
59323 }else if( pCur->pgnoRoot==0 ){
59324 pCur->eState = CURSOR_INVALID;
59327 assert( pCur->iPage==(-1) );
59328 rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
59329 0, pCur->curPagerFlags);
59331 pCur->eState = CURSOR_INVALID;
59334 pCur->iPage = 0;
59335 pCur->curIntKey = pCur->apPage[0]->intKey;
59337 pRoot = pCur->apPage[0];
59338 assert( pRoot->pgno==pCur->pgnoRoot );
59340 /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
59347 ** if pCur->iPage>=0). But this is not so if the database is corrupted
59351 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
59355 pCur->aiIdx[0] = 0;
59356 pCur->info.nSize = 0;
59357 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl);
59360 pCur->eState = CURSOR_VALID;
59365 pCur->eState = CURSOR_VALID;
59366 rc = moveToChild(pCur, subpage);
59368 pCur->eState = CURSOR_INVALID;
59380 static int moveToLeftmost(BtCursor *pCur){
59385 assert( cursorHoldsMutex(pCur
59386 assert( pCur->eState==CURSOR_VALID );
59387 while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){
59388 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
59389 pgno = get4byte(findCell(pPage, pCur->aiIdx[pCur->iPage]));
59390 rc = moveToChild(pCur, pgno);
59405 static int moveToRightmost(BtCursor *pCur){
59410 assert( cursorHoldsMutex(pCur) );
59411 assert( pCur->eState==CURSOR_VALID );
59412 while( !(pPage = pCur->apPage[pCur->iPage])->leaf ){
59414 pCur->aiIdx[pCur->iPage] = pPage->nCell;
59415 rc = moveToChild(pCur, pgno);
59418 pCur->aiIdx[pCur->iPage] = pPage->nCell-1;
59419 assert( pCur->info.nSize==0 );
59420 assert( (pCur->curFlags & BTCF_ValidNKey)==0 );
59428 SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor *pCur, int *pRes){
59431 assert( cursorHoldsMutex(pCur) );
59432 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
59433 rc = moveToRoot(pCur);
59435 if( pCur->eState==CURSOR_INVALID ){
59436 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
59439 assert( pCur->apPage[pCur->iPage]->nCell>0 );
59441 rc = moveToLeftmost(pCur);
59451 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
59454 assert( cursorHoldsMutex(pCur) );
59455 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
59458 if( CURSOR_VALID==pCur->eState && (pCur->curFlags & BTCF_AtLast)!=0 ){
59463 for(ii=0; ii<pCur->iPage; ii++){
59464 assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
59466 assert( pCur->aiIdx[pCur->iPage]==pCur->apPage[pCur->iPage]->nCell-1 );
59467 assert( pCur->apPage[pCur->iPage]->leaf );
59472 rc = moveToRoot(pCur);
59474 if( CURSOR_INVALID==pCur->eState ){
59475 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
59478 assert( pCur->eState==CURSOR_VALID );
59480 rc = moveToRightmost(pCur);
59482 pCur->curFlags |= BTCF_AtLast;
59484 pCur->curFlags &= ~BTCF_AtLast;
59521 BtCursor *pCur, /* The cursor to be moved */
59530 assert( cursorHoldsMutex(pCur) );
59531 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
59533 assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );
59537 if( pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0
59538 && pCur->curIntKey
59540 if( pCur->info.nKey==intKey ){
59544 if( (pCur->curFlags & BTCF_AtLast)!=0 && pCur->info.nKey<intKey ){
59561 rc = moveToRoot(pCur);
59565 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage] );
59566 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->isInit );
59567 assert( pCur->eState==CURSOR_INVALID || pCur->apPage[pCur->iPage]->nCell>0 );
59568 if( pCur->eState==CURSOR_INVALID ){
59570 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
59573 assert( pCur->apPage[0]->intKey==pCur->curIntKey );
59574 assert( pCur->curIntKey || pIdxKey );
59578 MemPage *pPage = pCur->apPage[pCur->iPage];
59593 pCur->aiIdx[pCur->iPage] = (u16)idx;
59612 pCur->curFlags |= BTCF_ValidNKey;
59613 pCur->info.nKey = nCellKey;
59614 pCur->aiIdx[pCur->iPage] = (u16)idx;
59666 pPage->xParseCell(pPage, pCellBody, &pCur->info);
59667 nCell = (int)pCur->info.nKey;
59681 pCur->aiIdx[pCur->iPage] = (u16)idx;
59682 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 2);
59692 && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
59702 pCur->aiIdx[pCur->iPage] = (u16)idx;
59714 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
59715 pCur->aiIdx[pCur->iPage] = (u16)idx;
59726 pCur->aiIdx[pCur->iPage] = (u16)lwr;
59727 rc = moveToChild(pCur, chldPg);
59731 pCur->info.nSize = 0;
59732 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
59744 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor *pCur){
59749 return (CURSOR_VALID!=pCur->eState);
59773 static SQLITE_NOINLINE int btreeNext(BtCursor *pCur, int *pRes){
59778 assert( cursorHoldsMutex(pCur) );
59779 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
59781 if( pCur->eState!=CURSOR_VALID ){
59782 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
59783 rc = restoreCursorPosition(pCur);
59787 if( CURSOR_INVALID==pCur->eState ){
59791 if( pCur->skipNext ){
59792 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT );
59793 pCur->eState = CURSOR_VALID;
59794 if( pCur->skipNext>0 ){
59795 pCur->skipNext = 0;
59798 pCur->skipNext = 0;
59802 pPage = pCur->apPage[pCur->iPage];
59803 idx = ++pCur->aiIdx[pCur->iPage];
59808 ** the page while cursor pCur is holding a reference to it. Which can
59815 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
59817 return moveToLeftmost(pCur);
59820 if( pCur->iPage==0 ){
59822 pCur->eState = CURSOR_INVALID;
59825 moveToParent(pCur);
59826 pPage = pCur->apPage[pCur->iPage];
59827 }while( pCur->aiIdx[pCur->iPage]>=pPage->nCell );
59829 return sqlite3BtreeNext(pCur, pRes);
59837 return moveToLeftmost(pCur);
59840 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int *pRes){
59842 assert( cursorHoldsMutex(pCur) );
59845 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
59846 pCur->info.nSize = 0;
59847 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
59849 if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur, pRes);
59850 pPage = pCur->apPage[pCur->iPage];
59851 if( (++pCur->aiIdx[pCur->iPage])>=pPage->nCell ){
59852 pCur->aiIdx[pCur->iPage]--;
59853 return btreeNext(pCur, pRes);
59858 return moveToLeftmost(pCur);
59883 static SQLITE_NOINLINE int btreePrevious(BtCursor *pCur, int *pRes){
59887 assert( cursorHoldsMutex(pCur) );
59890 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
59891 assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 );
59892 assert( pCur->info.nSize==0 );
59893 if( pCur->eState!=CURSOR_VALID ){
59894 rc = restoreCursorPosition(pCur);
59898 if( CURSOR_INVALID==pCur->eState ){
59902 if( pCur->skipNext ){
59903 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT );
59904 pCur->eState = CURSOR_VALID;
59905 if( pCur->skipNext<0 ){
59906 pCur->skipNext = 0;
59909 pCur->skipNext = 0;
59913 pPage = pCur->apPage[pCur->iPage];
59916 int idx = pCur->aiIdx[pCur->iPage];
59917 rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
59919 rc = moveToRightmost(pCur);
59921 while( pCur->aiIdx[pCur->iPage]==0 ){
59922 if( pCur->iPage==0 ){
59923 pCur->eState = CURSOR_INVALID;
59927 moveToParent(pCur);
59929 assert( pCur->info.nSize==0 );
59930 assert( (pCur->curFlags & (BTCF_ValidNKey|BTCF_ValidOvfl))==0 );
59932 pCur->aiIdx[pCur->iPage]--;
59933 pPage = pCur->apPage[pCur->iPage];
59935 rc = sqlite3BtreePrevious(pCur, pRes);
59942 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){
59943 assert( cursorHoldsMutex(pCur) );
59946 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
59948 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
59949 pCur->info.nSize = 0;
59950 if( pCur->eState!=CURSOR_VALID
59951 || pCur->aiIdx[pCur->iPage]==0
59952 || pCur->apPage[pCur->iPage]->leaf==0
59954 return btreePrevious(pCur, pRes);
59956 pCur->aiIdx[pCur->iPage]--;
62262 ** The page that pCur currently points to has just been modified in
62271 static int balance(BtCursor *pCur){
62273 const int nMin = pCur->pBt->usableSize * 2 / 3;
62281 int iPage = pCur->iPage;
62282 MemPage *pPage = pCur->apPage[iPage];
62292 rc = balance_deeper(pPage, &pCur->apPage[1]);
62294 pCur->iPage = 1;
62295 pCur->aiIdx[0] = 0;
62296 pCur->aiIdx[1] = 0;
62297 assert( pCur->apPage[1]->nOverflow );
62305 MemPage * const pParent = pCur->apPage[iPage-1];
62306 int const iIdx = pCur->aiIdx[iPage-1];
62352 u8 *pSpace = sqlite3PageMalloc(pCur->pBt->pageSize);
62354 pCur->hints&BTREE_BULKLOAD);
62374 pCur->iPage--;
62375 assert( pCur->iPage>=0 );
62396 ** MovetoUnpacked() to seek cursor pCur to (pKey, nKey) has already
62398 ** number if pCur points at an entry that is smaller than (pKey, nKey), or
62399 ** a positive value if pCur points at an entry that is larger than
62403 ** cursor pCur is pointing at the existing copy of a row that is to be
62404 ** overwritten. If the seekResult parameter is 0, then cursor pCur may
62409 BtCursor *pCur, /* Insert data into the table of this cursor */
62421 Btree *p = pCur->pBtree;
62426 if( pCur->eState==CURSOR_FAULT ){
62427 assert( pCur->skipNext!=SQLITE_OK );
62428 return pCur->skipNext;
62431 assert( cursorHoldsMutex(pCur) );
62432 assert( (pCur->curFlags & BTCF_WriteFlag)!=0
62435 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
62442 assert( (pKey==0)==(pCur->pKeyInfo==0) );
62455 if( pCur->curFlags & BTCF_Multiple ){
62456 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
62460 if( pCur->pKeyInfo==0 ){
62469 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && nKey>0
62470 && pCur->info.nKey==nKey-1 ){
62473 rc = sqlite3BtreeMovetoUnpacked(pCur, 0, nKey, appendBias, &loc);
62477 rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc);
62480 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
62482 pPage = pCur->apPage[pCur->iPage];
62487 pCur
62496 idx = pCur->aiIdx[pCur->iPage];
62513 idx = ++pCur->aiIdx[pCur->iPage];
62540 pCur->info.nSize = 0;
62542 pCur->curFlags &= ~(BTCF_ValidNKey);
62543 rc = balance(pCur);
62549 pCur->apPage[pCur->iPage]->nOverflow = 0;
62550 pCur->eState = CURSOR_INVALID;
62552 assert( pCur->apPage[pCur->iPage]->nOverflow==0 );
62567 SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, int bPreserve){
62568 Btree *p = pCur->pBtree;
62578 assert( cursorHoldsMutex(pCur) );
62581 assert( pCur->curFlags & BTCF_WriteFlag );
62582 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
62583 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
62584 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
62585 assert( pCur->eState==CURSOR_VALID );
62587 iCellDepth = pCur->iPage;
62588 iCellIdx = pCur->aiIdx[iCellDepth];
62589 pPage = pCur->apPage[iCellDepth];
62601 rc = sqlite3BtreePrevious(pCur, ¬Used);
62607 if( pCur->curFlags & BTCF_Multiple ){
62608 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
62614 if( pCur->pKeyInfo==0 ){
62615 invalidateIncrblobCursors(p, pCur->info.nKey, 0);
62633 rc = saveCursorKey(pCur);
62655 MemPage *pLeaf = pCur->apPage[pCur->iPage];
62657 Pgno n = pCur->apPage[iCellDepth+1]->pgno;
62678 ** pCur is pointing to the leaf page from which a cell was removed to
62687 rc = balance(pCur);
62688 if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){
62689 while( pCur->iPage>iCellDepth ){
62690 releasePage(pCur->apPage[pCur->iPage--]);
62692 rc = balance(pCur);
62697 assert( bPreserve && pCur->iPage==iCellDepth );
62698 assert( pPage==pCur->apPage[pCur->iPage] );
62700 pCur->eState = CURSOR_SKIPNEXT;
62702 pCur->skipNext = -1;
62703 pCur->aiIdx[iCellDepth] = pPage->nCell-1;
62705 pCur->skipNext = 1;
62708 rc = moveToRoot(pCur);
62710 pCur->eState = CURSOR_REQUIRESEEK;
62970 ** Delete all information from the single table that pCur is open on.
62972 ** This routine only work for pCur on an ephemeral table.
62974 SQLITE_PRIVATE int sqlite3BtreeClearTableOfCursor(BtCursor *pCur){
62975 return sqlite3BtreeClearTable(pCur->pBtree, pCur->pgnoRoot, 0);
63186 ** The first argument, pCur, is a cursor opened on some b-tree. Count the
63193 SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *pCur, i64 *pnEntry){
63197 if( pCur->pgnoRoot==0 ){
63201 rc = moveToRoot(pCur);
63214 pPage = pCur->apPage[pCur->iPage];
63222 ** pCur->aiIdx[pCur->iPage] value is set to the index of the parent cell
63231 if( pCur->iPage==0 ){
63234 return moveToRoot(pCur);
63236 moveToParent(pCur);
63237 }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
63239 pCur->aiIdx[pCur->iPage]++;
63240 pPage = pCur->apPage[pCur->iPage];
63246 iIdx = pCur->aiIdx[pCur->iPage];
63248 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
63250 rc = moveToChild(pCur, get4byte(findCell(pPage, iIdx)));
64086 SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *pCur){
64087 pCur->curFlags |= BTCF_Incrblob;
64088 pCur->pBtree->hasIncrblobCur = 1;
65900 ** The data or key is taken from the entry that pCur is currently pointing
65915 BtCursor *pCur, /* Cursor pointing at record to retrieve. */
65925 rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
65927 rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
65941 BtCursor *pCur, /* Cursor pointing at record to retrieve. */
65951 assert( sqlite3BtreeCursorIsValid(pCur) );
65958 zData = (char *)sqlite3BtreeKeyFetch(pCur, &available);
65960 zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
65969 rc = vdbeMemFromBtreeResize(pCur, offset, amt, key, pMem);
70737 ** pCur points at an index entry created using the OP_MakeRecord opcode.
70741 ** pCur might be pointing to text obtained from a corrupt database file.
70744 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
70757 assert( sqlite3BtreeCursorIsValid(pCur) );
70758 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
70759 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
70764 rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
70830 BtCursor *pCur = pC->pCursor;
70833 assert( sqlite3BtreeCursorIsValid(pCur) );
70834 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
70835 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
76200 VdbeCursor *pCur;
76205 pCur = p->apCsr[pOp->p1];
76206 if( pCur && pCur->pgnoRoot==(u32)pOp->p2 ){
76207 assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */
76272 pCur = allocateCursor(p, pOp->p1, nField, iDb, 1);
76273 if( pCur==0 ) goto no_mem;
76274 pCur->nullRow = 1;
76275 pCur->isOrdered = 1;
76276 pCur->pgnoRoot = p2;
76277 rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
76278 pCur->pKeyInfo = pKeyInfo;
76283 pCur->isTable = pOp->p4type!=P4_KEYINFO;
76288 sqlite3BtreeCursorHints(pCur->pCursor,
79091 VdbeCursor *pCur;
79097 pCur = 0;
79112 pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
79113 if( pCur ){
79114 pCur->pVtabCursor = pVtabCursor;
79154 VdbeCursor *pCur;
79161 pCur = p->apCsr[pOp->p1];
79164 assert( pCur->pVtabCursor );
79165 pVtabCursor = pCur->pVtabCursor;
79185 pCur->nullRow = 0;
79206 VdbeCursor *pCur = p->apCsr[pOp->p1];
79207 assert( pCur->pVtabCursor );
79211 if( pCur->nullRow ){
79215 pVtab = pCur->pVtabCursor->pVtab;
79221 rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2);
79248 VdbeCursor *pCur;
79251 pCur = p->apCsr[pOp->p1];
79252 assert( pCur->pVtabCursor );
79253 if( pCur->nullRow ){
79256 pVtab = pCur->pVtabCursor->pVtab;
79266 rc = pModule->xNext(pCur->pVtabCursor);
79269 res = pModule->xEof(pCur->pVtabCursor);
155182 static RtreeSearchPoint *rtreeSearchPointFirst(RtreeCursor *pCur){
155183 return pCur->bPoint ? &pCur->sPoint : pCur->nPoint ? pCur->aPoint : 0;
155189 static RtreeNode *rtreeNodeOfFirstSearchPoint(RtreeCursor *pCur, int *pRC){
155191 int ii = 1 - pCur->bPoint;
155193 assert( pCur->bPoint || pCur->nPoint );
155194 if( pCur->aNode[ii]==0 ){
155196 id = ii ? pCur->aPoint[0].id : pCur->sPoint.id;
155197 *pRC = nodeAcquire(RTREE_OF_CURSOR(pCur), id, 0, &pCur->aNode[ii]);
155199 return pCur->aNode[ii];
155206 RtreeCursor *pCur, /* The cursor */
155212 if( pCur->nPoint>=pCur->nPointAlloc ){
155213 int nNew = pCur->nPointAlloc*2 + 8;
155214 pNew = sqlite3_realloc(pCur->aPoint, nNew*sizeof(pCur->aPoint[0]));
155216 pCur->aPoint = pNew;
155217 pCur->nPointAlloc = nNew;
155219 i = pCur->nPoint++;
155220 pNew = pCur->aPoint + i;
155227 pParent = pCur->aPoint + j;
155229 rtreeSearchPointSwap(pCur, j, i);
155241 RtreeCursor *pCur, /* The cursor */
155246 pFirst = rtreeSearchPointFirst(pCur);
155247 pCur->anQueue[iLevel]++;
155252 if( pCur->bPoint ){
155254 pNew = rtreeEnqueue(pCur, rScore, iLevel);
155256 ii = (int)(pNew - pCur->aPoint) + 1;
155258 assert( pCur->aNode[ii]==0 );
155259 pCur->aNode[ii] = pCur->aNode[0];
155261 nodeRelease(RTREE_OF_CURSOR(pCur), pCur->aNode[0]);
155263 pCur->aNode[0] = 0;
155264 *pNew = pCur->sPoint;
155266 pCur->sPoint.rScore = rScore;
155267 pCur->sPoint.iLevel = iLevel;
155268 pCur->bPoint = 1;
155269 return &pCur->sPoint;
155271 return rtreeEnqueue(pCur, rScore, iLevel);
155277 static void tracePoint(RtreeSearchPoint *p, int idx, RtreeCursor *pCur){
155284 printf(" %p\n", pCur->aNode[idx]);
155289 static void traceQueue(RtreeCursor *pCur, const char *zPrefix){
155292 if( pCur->bPoint ){
155293 tracePoint(&pCur->sPoint, -1, pCur);
155295 for(ii=0; ii<pCur->nPoint; ii++){
155296 if( ii>0 || pCur->bPoint ) printf(" ");
155297 tracePoint(&pCur->aPoint[ii], ii, pCur);
155350 ** Continue the search on cursor pCur until the front of the queue
155355 static int rtreeStepToLeaf(RtreeCursor *pCur){
155357 Rtree *pRtree = RTREE_OF_CURSOR(pCur);
155362 int nConstraint = pCur->nConstraint;
155368 while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){
155369 pNode = rtreeNodeOfFirstSearchPoint(pCur, &rc);
155378 RtreeConstraint *pConstraint = pCur->aConstraint + ii;
155401 RTREE_QUEUE_TRACE(pCur, "POP-S:");
155402 rtreeSearchPointPop(pCur);
155405 p = rtreeSearchPointNew(pCur, rScore, x.iLevel);
155410 RTREE_QUEUE_TRACE(pCur, "PUSH-S:");
155414 RTREE_QUEUE_TRACE(pCur, "POP-Se:");
155415 rtreeSearchPointPop(pCur);
155418 pCur->atEOF = p==0;
165134 JsonEachCursor *pCur;
165137 pCur = sqlite3_malloc( sizeof(*pCur) );
165138 if( pCur==0 ) return SQLITE_NOMEM;
165139 memset(pCur, 0, sizeof(*pCur));
165140 *ppCursor = &pCur->base;
165148 JsonEachCursor *pCur = (JsonEachCursor*)*ppCursor;
165149 pCur->bRecursive = 1;