Lines Matching refs:pCur
6476 ** ^The current value of the requested parameter is written into *pCur
6486 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
49239 SQLITE_PRIVATE void sqlite3BtreeEnterCursor(BtCursor *pCur){
49240 sqlite3BtreeEnter(pCur->pBtree);
49242 SQLITE_PRIVATE void sqlite3BtreeLeaveCursor(BtCursor *pCur){
49243 sqlite3BtreeLeave(pCur->pBtree);
49797 ** Invalidate the overflow page-list cache for cursor pCur, if any.
49799 static void invalidateOverflowCache(BtCursor *pCur){
49800 assert( cursorHoldsMutex(pCur) );
49801 sqlite3_free(pCur->aOverflow);
49802 pCur->aOverflow = 0;
49930 static int saveCursorPosition(BtCursor *pCur){
49933 assert( CURSOR_VALID==pCur->eState );
49934 assert( 0==pCur->pKey );
49935 assert( cursorHoldsMutex(pCur) );
49937 rc = sqlite3BtreeKeySize(pCur, &pCur->nKey);
49941 ** stores the integer key in pCur->nKey. In this case this value is
49942 ** all that is required. Otherwise, if pCur is not open on an intKey
49943 ** table, then malloc space for and store the pCur->nKey bytes of key
49946 if( 0==pCur->apPage[0]->intKey ){
49947 void *pKey = sqlite3Malloc( (int)pCur->nKey );
49949 rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey);
49951 pCur->pKey = pKey;
49959 assert( !pCur->apPage[0]->intKey || !pCur->pKey );
49963 for(i=0; i<=pCur->iPage; i++){
49964 releasePage(pCur->apPage[i]);
49965 pCur->apPage[i] = 0;
49967 pCur->iPage = -1;
49968 pCur->eState = CURSOR_REQUIRESEEK;
49971 invalidateOverflowCache(pCur);
49999 SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *pCur){
50000 assert( cursorHoldsMutex(pCur) );
50001 sqlite3_free(pCur->pKey);
50002 pCur->pKey = 0;
50003 pCur->eState = CURSOR_INVALID;
50012 BtCursor *pCur, /* Cursor open on the btree to be searched */
50026 pCur->pKeyInfo, aSpace, sizeof(aSpace), &pFree
50029 sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
50033 rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
50035 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
50047 static int btreeRestoreCursorPosition(BtCursor *pCur){
50049 assert( cursorHoldsMutex(pCur) );
50050 assert( pCur->eState>=CURSOR_REQUIRESEEK );
50051 if( pCur->eState==CURSOR_FAULT ){
50052 return pCur->skipNext;
50054 pCur->eState = CURSOR_INVALID;
50055 rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &pCur->skipNext);
50057 sqlite3_free(pCur->pKey);
50058 pCur->pKey = 0;
50059 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
50077 SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor *pCur, int *pHasMoved){
50080 rc = restoreCursorPosition(pCur);
50085 if( pCur->eState!=CURSOR_VALID || pCur->skipNext!=0 ){
51390 BtCursor *pCur;
51395 pCur = pBt->pCursor;
51396 while( pCur ){
51397 BtCursor *pTmp = pCur;
51398 pCur = pCur->pNext;
52618 BtCursor *pCur;
52620 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
52621 if( pCur->wrFlag && pCur->eState!=CURSOR_FAULT ) r++;
52819 ** on pCur to initialize the memory space prior to invoking this routine.
52826 BtCursor *pCur /* Space for new cursor */
52855 pCur->pgnoRoot = (Pgno)iTable;
52856 pCur->iPage = -1;
52857 pCur->pKeyInfo = pKeyInfo;
52858 pCur->pBtree = p;
52859 pCur->pBt = pBt;
52860 pCur->wrFlag = (u8)wrFlag;
52861 pCur->pNext = pBt->pCursor;
52862 if( pCur->pNext ){
52863 pCur->pNext->pPrev = pCur;
52865 pBt->pCursor = pCur;
52866 pCur->eState = CURSOR_INVALID;
52867 pCur->cachedRowid = 0;
52875 BtCursor *pCur /* Write new cursor here */
52879 rc = btreeCursor(p, iTable, wrFlag, pKeyInfo, pCur);
52910 ** as pCur and having the same root page number as pCur. The value is
52920 SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor *pCur, sqlite3_int64 iRowid){
52922 for(p=pCur->pBt->pCursor; p; p=p->pNext){
52923 if( p->pgnoRoot==pCur->pgnoRoot ) p->cachedRowid = iRowid;
52925 assert( pCur->cachedRowid==iRowid );
52934 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor *pCur){
52935 return pCur->cachedRowid;
52942 SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){
52943 Btree *pBtree = pCur->pBtree;
52946 BtShared *pBt = pCur->pBt;
52948 sqlite3BtreeClearCursor(pCur);
52949 if( pCur->pPrev ){
52950 pCur->pPrev->pNext = pCur->pNext;
52952 pBt->pCursor = pCur->pNext;
52954 if( pCur->pNext ){
52955 pCur->pNext->pPrev = pCur->pPrev;
52957 for(i=0; i<=pCur->iPage; i++){
52958 releasePage(pCur->apPage[i]);
52961 invalidateOverflowCache(pCur);
52962 /* sqlite3_free(pCur); */
52984 static void assertCellInfo(BtCursor *pCur){
52986 int iPage = pCur->iPage;
52988 btreeParseCell(pCur->apPage[iPage], pCur->aiIdx[iPage], &info);
52989 assert( memcmp(&info, &pCur->info, sizeof(info))==0 );
52996 static void getCellInfo(BtCursor *pCur){
52997 if( pCur->info.nSize==0 ){
52998 int iPage = pCur->iPage;
52999 btreeParseCell(pCur->apPage[iPage],pCur->aiIdx[iPage],&pCur->info);
53000 pCur->validNKey = 1;
53002 assertCellInfo(pCur);
53007 #define getCellInfo(pCur) \
53008 if( pCur->info.nSize==0 ){ \
53009 int iPage = pCur->iPage; \
53010 btreeParseCell(pCur->apPage[iPage],pCur->aiIdx[iPage],&pCur->info); \
53011 pCur->validNKey = 1; \
53013 assertCellInfo(pCur); \
53023 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor *pCur){
53024 return pCur && pCur->eState==CURSOR_VALID;
53040 SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){
53041 assert( cursorHoldsMutex(pCur) );
53042 assert( pCur->eState==CURSOR_INVALID || pCur->eState==CURSOR_VALID );
53043 if( pCur->eState!=CURSOR_VALID ){
53046 getCellInfo(pCur);
53047 *pSize = pCur->info.nKey;
53064 SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){
53065 assert( cursorHoldsMutex(pCur) );
53066 assert( pCur->eState==CURSOR_VALID );
53067 getCellInfo(pCur);
53068 *pSize = pCur->info.nData;
53182 ** for the entry that the pCur cursor is pointing to. If the eOp
53209 BtCursor *pCur, /* Cursor pointing to entry to read from */
53219 MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
53220 BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
53223 assert( pCur->eState==CURSOR_VALID );
53224 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
53225 assert( cursorHoldsMutex(pCur) );
53227 getCellInfo(pCur);
53228 aPayload = pCur->info.pCell + pCur->info.nHeader;
53229 nKey = (pPage->intKey ? 0 : (int)pCur->info.nKey);
53231 if( NEVER(offset+amt > nKey+pCur->info.nData)
53232 || &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
53239 if( offset<pCur->info.nLocal ){
53241 if( a+offset>pCur->info.nLocal ){
53242 a = pCur->info.nLocal - offset;
53249 offset -= pCur->info.nLocal;
53256 nextPage = get4byte(&aPayload[pCur->info.nLocal]);
53266 if( pCur->isIncrblobHandle && !pCur->aOverflow ){
53267 int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
53268 pCur->aOverflow = (Pgno *)sqlite3MallocZero(sizeof(Pgno)*nOvfl);
53271 if( ALWAYS(nOvfl) && !pCur->aOverflow ){
53280 if( pCur->aOverflow && pCur->aOverflow[offset/ovflSize] ){
53282 nextPage = pCur->aOverflow[iIdx];
53291 if( pCur->aOverflow ){
53292 assert(!pCur->aOverflow[iIdx] || pCur->aOverflow[iIdx]==nextPage);
53293 pCur->aOverflow[iIdx] = nextPage;
53305 if( pCur->aOverflow && pCur->aOverflow[iIdx+1] ){
53306 nextPage = pCur->aOverflow[iIdx+1];
53375 ** Read part of the key associated with cursor pCur. Exactly
53379 ** The caller must ensure that pCur is pointing to a valid row
53386 SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
53387 assert( cursorHoldsMutex(pCur) );
53388 assert( pCur->eState==CURSOR_VALID );
53389 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
53390 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
53391 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
53395 ** Read part of the data associated with cursor pCur. Exactly
53403 SQLITE_PRIVATE int sqlite3BtreeData(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
53407 if ( pCur->eState==CURSOR_INVALID ){
53412 assert( cursorHoldsMutex(pCur) );
53413 rc = restoreCursorPosition(pCur);
53415 assert( pCur->eState==CURSOR_VALID );
53416 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
53417 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
53418 rc = accessPayload(pCur, offset, amt, pBuf, 0);
53425 ** pCur cursor is pointing to. The pointer is to the beginning of
53443 BtCursor *pCur, /* Cursor pointing to entry to read from */
53452 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
53453 assert( pCur->eState==CURSOR_VALID );
53454 assert( cursorHoldsMutex(pCur) );
53455 pPage = pCur->apPage[pCur->iPage];
53456 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
53457 if( NEVER(pCur->info.nSize==0) ){
53458 btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage],
53459 &pCur->info);
53461 aPayload = pCur->info.pCell;
53462 aPayload += pCur->info.nHeader;
53466 nKey = (int)pCur->info.nKey;
53470 nLocal = pCur->info.nLocal - nKey;
53472 nLocal = pCur->info.nLocal;
53481 ** For the entry that cursor pCur is point to, return as
53494 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, int *pAmt){
53496 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53497 assert( cursorHoldsMutex(pCur) );
53498 if( ALWAYS(pCur->eState==CURSOR_VALID) ){
53499 p = (const void*)fetchPayload(pCur, pAmt, 0);
53503 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, int *pAmt){
53505 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53506 assert( cursorHoldsMutex(pCur) );
53507 if( ALWAYS(pCur->eState==CURSOR_VALID) ){
53508 p = (const void*)fetchPayload(pCur, pAmt, 1);
53523 static int moveToChild(BtCursor *pCur, u32 newPgno){
53525 int i = pCur->iPage;
53527 BtShared *pBt = pCur->pBt;
53529 assert( cursorHoldsMutex(pCur) );
53530 assert( pCur->eState==CURSOR_VALID );
53531 assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
53532 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
53537 pCur->apPage[i+1] = pNewPage;
53538 pCur->aiIdx[i+1] = 0;
53539 pCur->iPage++;
53541 pCur->info.nSize = 0;
53542 pCur->validNKey = 0;
53543 if( pNewPage->nCell<1 || pNewPage->intKey!=pCur->apPage[i]->intKey ){
53572 ** pCur->idx is set to the cell index that contains the pointer
53574 ** right-most child page then pCur->idx is set to one more than
53577 static void moveToParent(BtCursor *pCur){
53578 assert( cursorHoldsMutex(pCur) );
53579 assert( pCur->eState==CURSOR_VALID );
53580 assert( pCur->iPage>0 );
53581 assert( pCur->apPage[pCur->iPage] );
53590 pCur->apPage[pCur->iPage-1],
53591 pCur->aiIdx[pCur->iPage-1],
53592 pCur->apPage[pCur->iPage]->pgno
53595 testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
53597 releasePage(pCur->apPage[pCur->iPage]);
53598 pCur->iPage--;
53599 pCur->info.nSize = 0;
53600 pCur->validNKey = 0;
53624 static int moveToRoot(BtCursor *pCur){
53627 Btree *p = pCur->pBtree;
53630 assert( cursorHoldsMutex(pCur) );
53634 if( pCur->eState>=CURSOR_REQUIRESEEK ){
53635 if( pCur->eState==CURSOR_FAULT ){
53636 assert( pCur->skipNext!=SQLITE_OK );
53637 return pCur->skipNext;
53639 sqlite3BtreeClearCursor(pCur);
53642 if( pCur->iPage>=0 ){
53644 for(i=1; i<=pCur->iPage; i++){
53645 releasePage(pCur->apPage[i]);
53647 pCur->iPage = 0;
53648 }else if( pCur->pgnoRoot==0 ){
53649 pCur->eState = CURSOR_INVALID;
53652 rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0]);
53654 pCur->eState = CURSOR_INVALID;
53657 pCur->iPage = 0;
53659 /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
53663 assert( pCur->apPage[0]->intKey==1 || pCur->apPage[0]->intKey==0 );
53664 if( (pCur->pKeyInfo==0)!=pCur->apPage[0]->intKey ){
53675 pRoot = pCur->apPage[0];
53676 assert( pRoot->pgno==pCur->pgnoRoot );
53677 assert( pRoot->isInit && (pCur->pKeyInfo==0)==pRoot->intKey );
53679 pCur->aiIdx[0] = 0;
53680 pCur->info.nSize = 0;
53681 pCur->atLast = 0;
53682 pCur->validNKey = 0;
53688 pCur->eState = CURSOR_VALID;
53689 rc = moveToChild(pCur, subpage);
53691 pCur->eState = ((pRoot->nCell>0)?CURSOR_VALID:CURSOR_INVALID);
53703 static int moveToLeftmost(BtCursor *pCur){
53708 assert( cursorHoldsMutex(pCur) );
53709 assert( pCur->eState==CURSOR_VALID );
53710 while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){
53711 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
53712 pgno = get4byte(findCell(pPage, pCur->aiIdx[pCur->iPage]));
53713 rc = moveToChild(pCur, pgno);
53728 static int moveToRightmost(BtCursor *pCur){
53733 assert( cursorHoldsMutex(pCur) );
53734 assert( pCur->eState==CURSOR_VALID );
53735 while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){
53737 pCur->aiIdx[pCur->iPage] = pPage->nCell;
53738 rc = moveToChild(pCur, pgno);
53741 pCur->aiIdx[pCur->iPage] = pPage->nCell-1;
53742 pCur->info.nSize = 0;
53743 pCur->validNKey = 0;
53752 SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor *pCur, int *pRes){
53755 assert( cursorHoldsMutex(pCur) );
53756 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53757 rc = moveToRoot(pCur);
53759 if( pCur->eState==CURSOR_INVALID ){
53760 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
53763 assert( pCur->apPage[pCur->iPage]->nCell>0 );
53765 rc = moveToLeftmost(pCur);
53775 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
53778 assert( cursorHoldsMutex(pCur) );
53779 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53782 if( CURSOR_VALID==pCur->eState && pCur->atLast ){
53787 for(ii=0; ii<pCur->iPage; ii++){
53788 assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
53790 assert( pCur->aiIdx[pCur->iPage]==pCur->apPage[pCur->iPage]->nCell-1 );
53791 assert( pCur->apPage[pCur->iPage]->leaf );
53796 rc = moveToRoot(pCur);
53798 if( CURSOR_INVALID==pCur->eState ){
53799 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
53802 assert( pCur->eState==CURSOR_VALID );
53804 rc = moveToRightmost(pCur);
53805 pCur->atLast = rc==SQLITE_OK ?1:0;
53840 BtCursor *pCur, /* The cursor to be moved */
53848 assert( cursorHoldsMutex(pCur) );
53849 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53851 assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );
53855 if( pCur->eState==CURSOR_VALID && pCur->validNKey
53856 && pCur->apPage[0]->intKey
53858 if( pCur->info.nKey==intKey ){
53862 if( pCur->atLast && pCur->info.nKey<intKey ){
53868 rc = moveToRoot(pCur);
53872 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage] );
53873 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->isInit );
53874 assert( pCur->eState==CURSOR_INVALID || pCur->apPage[pCur->iPage]->nCell>0 );
53875 if( pCur->eState==CURSOR_INVALID ){
53877 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
53880 assert( pCur->apPage[0]->intKey || pIdxKey );
53884 MemPage *pPage = pCur->apPage[pCur->iPage];
53898 pCur->aiIdx[pCur->iPage] = (u16)(idx = upr);
53900 pCur->aiIdx[pCur->iPage] = (u16)(idx = (upr+lwr)/2);
53905 assert( idx==pCur->aiIdx[pCur->iPage] );
53906 pCur->info.nSize = 0;
53923 pCur->validNKey = 1;
53924 pCur->info.nKey = nCellKey;
53958 btreeParseCellPtr(pPage, pCellBody, &pCur->info);
53959 nCell = (int)pCur->info.nKey;
53965 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
53992 pCur->aiIdx[pCur->iPage] = (u16)(idx = (lwr+upr)/2);
54004 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
54009 pCur->aiIdx[pCur->iPage] = (u16)lwr;
54010 pCur->info.nSize = 0;
54011 pCur->validNKey = 0;
54012 rc = moveToChild(pCur, chldPg);
54027 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor *pCur){
54032 return (CURSOR_VALID!=pCur->eState);
54041 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int *pRes){
54046 assert( cursorHoldsMutex(pCur) );
54047 rc = restoreCursorPosition(pCur);
54052 if( CURSOR_INVALID==pCur->eState ){
54056 if( pCur->skipNext>0 ){
54057 pCur->skipNext = 0;
54061 pCur->skipNext = 0;
54063 pPage = pCur->apPage[pCur->iPage];
54064 idx = ++pCur->aiIdx[pCur->iPage];
54069 ** the page while cursor pCur is holding a reference to it. Which can
54074 pCur->info.nSize = 0;
54075 pCur->validNKey = 0;
54078 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
54080 rc = moveToLeftmost(pCur);
54085 if( pCur->iPage==0 ){
54087 pCur->eState = CURSOR_INVALID;
54090 moveToParent(pCur);
54091 pPage = pCur->apPage[pCur->iPage];
54092 }while( pCur->aiIdx[pCur->iPage]>=pPage->nCell );
54095 rc = sqlite3BtreeNext(pCur, pRes);
54105 rc = moveToLeftmost(pCur);
54116 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){
54120 assert( cursorHoldsMutex(pCur) );
54121 rc = restoreCursorPosition(pCur);
54125 pCur->atLast = 0;
54126 if( CURSOR_INVALID==pCur->eState ){
54130 if( pCur->skipNext<0 ){
54131 pCur->skipNext = 0;
54135 pCur->skipNext = 0;
54137 pPage = pCur->apPage[pCur->iPage];
54140 int idx = pCur->aiIdx[pCur->iPage];
54141 rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
54145 rc = moveToRightmost(pCur);
54147 while( pCur->aiIdx[pCur->iPage]==0 ){
54148 if( pCur->iPage==0 ){
54149 pCur->eState = CURSOR_INVALID;
54153 moveToParent(pCur);
54155 pCur->info.nSize = 0;
54156 pCur->validNKey = 0;
54158 pCur->aiIdx[pCur->iPage]--;
54159 pPage = pCur->apPage[pCur->iPage];
54161 rc = sqlite3BtreePrevious(pCur, pRes);
55977 ** The page that pCur currently points to has just been modified in
55986 static int balance(BtCursor *pCur){
55988 const int nMin = pCur->pBt->usableSize * 2 / 3;
55996 int iPage = pCur->iPage;
55997 MemPage *pPage = pCur->apPage[iPage];
56007 rc = balance_deeper(pPage, &pCur->apPage[1]);
56009 pCur->iPage = 1;
56010 pCur->aiIdx[0] = 0;
56011 pCur->aiIdx[1] = 0;
56012 assert( pCur->apPage[1]->nOverflow );
56020 MemPage * const pParent = pCur->apPage[iPage-1];
56021 int const iIdx = pCur->aiIdx[iPage-1];
56067 u8 *pSpace = sqlite3PageMalloc(pCur->pBt->pageSize);
56088 pCur->iPage--;
56109 ** MovetoUnpacked() to seek cursor pCur to (pKey, nKey) has already
56111 ** number if pCur points at an entry that is smaller than (pKey, nKey), or
56112 ** a positive value if pCur points at an etry that is larger than
56116 ** cursor pCur is pointing at the existing copy of a row that is to be
56117 ** overwritten. If the seekResult parameter is 0, then cursor pCur may
56122 BtCursor *pCur, /* Insert data into the table of this cursor */
56134 Btree *p = pCur->pBtree;
56139 if( pCur->eState==CURSOR_FAULT ){
56140 assert( pCur->skipNext!=SQLITE_OK );
56141 return pCur->skipNext;
56144 assert( cursorHoldsMutex(pCur) );
56145 assert( pCur->wrFlag && pBt->inTransaction==TRANS_WRITE
56147 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
56154 assert( (pKey==0)==(pCur->pKeyInfo==0) );
56159 if( pCur->pKeyInfo==0 ){
56174 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
56177 rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc);
56180 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
56182 pPage = pCur->apPage[pCur->iPage];
56187 pCur->pgnoRoot, nKey, nData, pPage->pgno,
56197 idx = pCur->aiIdx[pCur->iPage];
56215 idx = ++pCur->aiIdx[pCur->iPage];
56242 pCur->info.nSize = 0;
56243 pCur->validNKey = 0;
56245 rc = balance(pCur);
56251 pCur->apPage[pCur->iPage]->nOverflow = 0;
56252 pCur->eState = CURSOR_INVALID;
56254 assert( pCur->apPage[pCur->iPage]->nOverflow==0 );
56264 SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur){
56265 Btree *p = pCur->pBtree;
56273 assert( cursorHoldsMutex(pCur) );
56276 assert( pCur->wrFlag );
56277 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
56278 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
56280 if( NEVER(pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell)
56281 pCur->eState!=CURSOR_VALID)
56288 if( pCur->pKeyInfo==0 ){
56289 invalidateIncrblobCursors(p, pCur->info.nKey, 0);
56292 iCellDepth = pCur->iPage;
56293 iCellIdx = pCur->aiIdx[iCellDepth];
56294 pPage = pCur->apPage[iCellDepth];
56306 rc = sqlite3BtreePrevious(pCur, ¬Used);
56315 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
56329 MemPage *pLeaf = pCur->apPage[pCur->iPage];
56331 Pgno n = pCur->apPage[iCellDepth+1]->pgno;
56353 ** pCur is pointing to the leaf page from which a cell was removed to
56362 rc = balance(pCur);
56363 if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){
56364 while( pCur->iPage>iCellDepth ){
56365 releasePage(pCur->apPage[pCur->iPage--]);
56367 rc = balance(pCur);
56371 moveToRoot(pCur);
56808 ** The first argument, pCur, is a cursor opened on some b-tree. Count the
56815 SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *pCur, i64 *pnEntry){
56819 if( pCur->pgnoRoot==0 ){
56823 rc = moveToRoot(pCur);
56836 pPage = pCur->apPage[pCur->iPage];
56844 ** pCur->aiIdx[pCur->iPage] value is set to the index of the parent cell
56853 if( pCur->iPage==0 ){
56858 moveToParent(pCur);
56859 }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
56861 pCur->aiIdx[pCur->iPage]++;
56862 pPage = pCur->apPage[pCur->iPage];
56868 iIdx = pCur->aiIdx[pCur->iPage];
56870 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
56872 rc = moveToChild(pCur, get4byte(findCell(pPage, iIdx)));
57591 SQLITE_PRIVATE void sqlite3BtreeCacheOverflow(BtCursor *pCur){
57592 assert( cursorHoldsMutex(pCur) );
57593 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
57594 invalidateOverflowCache(pCur);
57595 pCur->isIncrblobHandle = 1;
59239 ** The data or key is taken from the entry that pCur is currently pointing
59251 BtCursor *pCur, /* Cursor pointing at record to retrieve. */
59261 assert( sqlite3BtreeCursorIsValid(pCur) );
59267 zData = (char *)sqlite3BtreeKeyFetch(pCur, &available);
59269 zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
59282 rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
59284 rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
62550 ** pCur points at an index entry created using the OP_MakeRecord opcode.
62554 ** pCur might be pointing to text obtained from a corrupt database file.
62557 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
62572 assert( sqlite3BtreeCursorIsValid(pCur) );
62573 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
62574 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
62579 rc = sqlite3VdbeMemFromBtree(pCur, 0, (int)nCellKey, 1, &m);
62644 BtCursor *pCur = pC->pCursor;
62647 assert( sqlite3BtreeCursorIsValid(pCur) );
62648 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
62649 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
65158 VdbeCursor *pCur;
65369 VdbeCursor *pCur;
65382 VdbeCursor *pCur;
65397 VdbeCursor *pCur;
67990 VdbeCursor *pCur;
68042 u.ax.pCur = allocateCursor(p, pOp->p1, u.ax.nField, u.ax.iDb, 1);
68043 if( u.ax.pCur==0 ) goto no_mem;
68044 u.ax.pCur->nullRow = 1;
68045 u.ax.pCur->isOrdered = 1;
68046 rc = sqlite3BtreeCursor(u.ax.pX, u.ax.p2, u.ax.wrFlag, u.ax.pKeyInfo, u.ax.pCur->pCursor);
68047 u.ax.pCur->pKeyInfo = u.ax.pKeyInfo;
68057 u.ax.pCur->isTable = pOp->p4type!=P4_KEYINFO;
68058 u.ax.pCur->isIndex = !u.ax.pCur->isTable;
70668 VdbeCursor *pCur;
70674 u.cl.pCur = 0;
70686 u.cl.pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
70687 if( u.cl.pCur ){
70688 u.cl.pCur->pVtabCursor = u.cl.pVtabCursor;
70689 u.cl.pCur->pModule = u.cl.pVtabCursor->pVtab->pModule;
70727 VdbeCursor *pCur;
70735 u.cm.pCur = p->apCsr[pOp->p1];
70738 assert( u.cm.pCur->pVtabCursor );
70739 u.cm.pVtabCursor = u.cm.pCur->pVtabCursor;
70769 u.cm.pCur->nullRow = 0;
70790 VdbeCursor *pCur = p->apCsr[pOp->p1];
70791 assert( pCur->pVtabCursor );
70795 if( pCur->nullRow ){
70799 u.cn.pVtab = pCur->pVtabCursor->pVtab;
70812 rc = u.cn.pModule->xColumn(pCur->pVtabCursor, &u.cn.sContext, pOp->p2);
70846 VdbeCursor *pCur;
70850 u.co.pCur = p->apCsr[pOp->p1];
70851 assert( u.co.pCur->pVtabCursor );
70852 if( u.co.pCur->nullRow ){
70855 u.co.pVtab = u.co.pCur->pVtabCursor->pVtab;
70866 rc = u.co.pModule->xNext(u.co.pCur->pVtabCursor);
70870 u.co.res = u.co.pModule->xEof(u.co.pCur->pVtabCursor);