Lines Matching defs:pCur

392 static int fileBtreeCloseCursor(BtCursor *pCur);
931 BtCursor *pCur;
936 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
937 if( pCur->pPage && pCur->pPage->isInit==0 ){
938 sqlitepager_unref(pCur->pPage);
939 pCur->pPage = 0;
992 BtCursor *pCur;
995 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
996 if( pCur->pPage && pCur->pPage->isInit==0 ){
997 sqlitepager_unref(pCur->pPage);
998 pCur->pPage = 0;
1044 BtCursor *pCur, *pRing;
1057 pCur = sqliteMalloc( sizeof(*pCur) );
1058 if( pCur==0 ){
1062 pCur->pgnoRoot = (Pgno)iTable;
1063 rc = sqlitepager_get(pBt->pPager, pCur->pgnoRoot, (void**)&pCur->pPage);
1067 rc = initPage(pBt, pCur->pPage, pCur->pgnoRoot, 0);
1071 pCur->pOps = &sqliteBtreeCursorOps;
1072 pCur->pBt = pBt;
1073 pCur->wrFlag = wrFlag;
1074 pCur->idx = 0;
1075 pCur->eSkip = SKIP_INVALID;
1076 pCur->pNext = pBt->pCursor;
1077 if( pCur->pNext ){
1078 pCur->pNext->pPrev = pCur;
1080 pCur->pPrev = 0;
1082 while( pRing && pRing->pgnoRoot!=pCur->pgnoRoot ){ pRing = pRing->pNext; }
1084 pCur->pShared = pRing->pShared;
1085 pRing->pShared = pCur;
1087 pCur->pShared = pCur;
1089 pBt->pCursor = pCur;
1090 *ppCur = pCur;
1095 if( pCur ){
1096 if( pCur->pPage ) sqlitepager_unref(pCur->pPage);
1097 sqliteFree(pCur);
1107 static int fileBtreeCloseCursor(BtCursor *pCur){
1108 Btree *pBt = pCur->pBt;
1109 if( pCur->pPrev ){
1110 pCur->pPrev->pNext = pCur->pNext;
1112 pBt->pCursor = pCur->pNext;
1114 if( pCur->pNext ){
1115 pCur->pNext->pPrev = pCur->pPrev;
1117 if( pCur->pPage ){
1118 sqlitepager_unref(pCur->pPage);
1120 if( pCur->pShared!=pCur ){
1121 BtCursor *pRing = pCur->pShared;
1122 while( pRing->pShared!=pCur ){ pRing = pRing->pShared; }
1123 pRing->pShared = pCur->pShared;
1126 sqliteFree(pCur);
1134 static void getTempCursor(BtCursor *pCur, BtCursor *pTempCur){
1135 memcpy(pTempCur, pCur, sizeof(*pCur));
1147 static void releaseTempCursor(BtCursor *pCur){
1148 if( pCur->pPage ){
1149 sqlitepager_unref(pCur->pPage);
1160 static int fileBtreeKeySize(BtCursor *pCur, int *pSize){
1164 pPage = pCur->pPage;
1166 if( pCur->idx >= pPage->nCell ){
1169 pCell = pPage->apCell[pCur->idx];
1170 *pSize = NKEY(pCur->pBt, pCell->h);
1176 ** Read payload information from the entry that the pCur cursor is
1183 static int getPayload(BtCursor *pCur, int offset, int amt, char *zBuf){
1187 Btree *pBt = pCur->pBt;
1188 assert( pCur!=0 && pCur->pPage!=0 );
1189 assert( pCur->idx>=0 && pCur->idx<pCur->pPage->nCell );
1190 aPayload = pCur->pPage->apCell[pCur->idx]->aPayload;
1207 nextPage = SWAB32(pBt, pCur->pPage->apCell[pCur->idx]->ovfl);
1237 ** Read part of the key associated with cursor pCur. A maximum
1249 static int fileBtreeKey(BtCursor *pCur, int offset, int amt, char *zBuf){
1254 assert( pCur->pPage!=0 );
1255 pPage = pCur->pPage;
1256 if( pCur->idx >= pPage->nCell ){
1259 assert( amt+offset <= NKEY(pCur->pBt, pPage->apCell[pCur->idx]->h) );
1260 getPayload(pCur, offset, amt, zBuf);
1271 static int fileBtreeDataSize(BtCursor *pCur, int *pSize){
1275 pPage = pCur->pPage;
1277 if( pCur->idx >= pPage->nCell ){
1280 pCell = pPage->apCell[pCur->idx];
1281 *pSize = NDATA(pCur->pBt, pCell->h);
1287 ** Read part of the data associated with cursor pCur. A maximum
1294 static int fileBtreeData(BtCursor *pCur, int offset, int amt, char *zBuf){
1300 assert( pCur->pPage!=0 );
1301 pPage = pCur->pPage;
1302 if( pCur->idx >= pPage->nCell ){
1305 pCell = pPage->apCell[pCur->idx];
1306 assert( amt+offset <= NDATA(pCur->pBt, pCell->h) );
1307 getPayload(pCur, offset + NKEY(pCur->pBt, pCell->h), amt, zBuf);
1312 ** Compare an external key against the key on the entry that pCur points to.
1315 ** of the key associated with pCur are ignored, as if they do not exist.
1321 ** *pRes<0 This means pCur<pKey
1323 ** *pRes==0 This means pCur==pKey for all nKey bytes
1325 ** *pRes>0 This means pCur>pKey
1329 ** keys must be exactly the same length. (The length of the pCur key
1333 BtCursor *pCur, /* Pointer to entry to compare against */
1334 const void *pKey, /* Key to compare against entry that pCur points to */
1336 int nIgnore, /* Ignore this many bytes at the end of pCur */
1342 Btree *pBt = pCur->pBt;
1345 assert( pCur->pPage );
1346 assert( pCur->idx>=0 && pCur->idx<pCur->pPage->nCell );
1347 pCell = pCur->pPage->apCell[pCur->idx];
1398 static int moveToChild(BtCursor *pCur, int newPgno){
1401 Btree *pBt = pCur->pBt;
1406 rc = initPage(pBt, pNewPage, newPgno, pCur->pPage);
1408 assert( pCur->idx>=pCur->pPage->nCell
1409 || pCur->pPage->apCell[pCur->idx]->h.leftChild==SWAB32(pBt,newPgno) );
1410 assert( pCur->idx<pCur->pPage->nCell
1411 || pCur->pPage->u.hdr.rightChild==SWAB32(pBt,newPgno) );
1412 pNewPage->idxParent = pCur->idx;
1413 pCur->pPage->idxShift = 0;
1414 sqlitepager_unref(pCur->pPage);
1415 pCur->pPage = pNewPage;
1416 pCur->idx = 0;
1426 ** pCur->idx is set to the cell index that contains the pointer
1428 ** right-most child page then pCur->idx is set to one more than
1431 static void moveToParent(BtCursor *pCur){
1436 pPage = pCur->pPage;
1443 pCur->pPage = pParent;
1446 pCur->idx = idxParent;
1448 /* Verify that pCur->idx is the correct index to point back to the child
1451 oldPgno = SWAB32(pCur->pBt, sqlitepager_pagenumber(pPage));
1452 if( pCur->idx<pParent->nCell ){
1465 pCur->idx = pParent->nCell;
1466 oldPgno = SWAB32(pCur->pBt, sqlitepager_pagenumber(pPage));
1469 pCur->idx = i;
1479 static int moveToRoot(BtCursor *pCur){
1482 Btree *pBt = pCur->pBt;
1484 rc = sqlitepager_get(pBt->pPager, pCur->pgnoRoot, (void**)&pNew);
1486 rc = initPage(pBt, pNew, pCur->pgnoRoot, 0);
1488 sqlitepager_unref(pCur->pPage);
1489 pCur->pPage = pNew;
1490 pCur->idx = 0;
1498 static int moveToLeftmost(BtCursor *pCur){
1502 while( (pgno = pCur->pPage->apCell[pCur->idx]->h.leftChild)!=0 ){
1503 rc = moveToChild(pCur, pgno);
1516 static int moveToRightmost(BtCursor *pCur){
1520 while( (pgno = pCur->pPage->u.hdr.rightChild)!=0 ){
1521 pCur->idx = pCur->pPage->nCell;
1522 rc = moveToChild(pCur, pgno);
1525 pCur->idx = pCur->pPage->nCell - 1;
1533 static int fileBtreeFirst(BtCursor *pCur, int *pRes){
1535 if( pCur->pPage==0 ) return SQLITE_ABORT;
1536 rc = moveToRoot(pCur);
1538 if( pCur->pPage->nCell==0 ){
1543 rc = moveToLeftmost(pCur);
1544 pCur->eSkip = SKIP_NONE;
1552 static int fileBtreeLast(BtCursor *pCur, int *pRes){
1554 if( pCur->pPage==0 ) return SQLITE_ABORT;
1555 rc = moveToRoot(pCur);
1557 assert( pCur->pPage->isInit );
1558 if( pCur->pPage->nCell==0 ){
1563 rc = moveToRightmost(pCur);
1564 pCur->eSkip = SKIP_NONE;
1577 ** cursor is left pointing is stored in pCur->iMatch. The same
1592 int fileBtreeMoveto(BtCursor *pCur, const void *pKey, int nKey, int *pRes){
1594 if( pCur->pPage==0 ) return SQLITE_ABORT;
1595 pCur->eSkip = SKIP_NONE;
1596 rc = moveToRoot(pCur);
1601 MemPage *pPage = pCur->pPage;
1606 pCur->idx = (lwr+upr)/2;
1607 rc = fileBtreeKeyCompare(pCur, pKey, nKey, 0, &c);
1610 pCur->iMatch = c;
1615 lwr = pCur->idx+1;
1617 upr = pCur->idx-1;
1628 pCur->iMatch = c;
1632 pCur->idx = lwr;
1633 rc = moveToChild(pCur, chldPg);
1645 static int fileBtreeNext(BtCursor *pCur, int *pRes){
1647 MemPage *pPage = pCur->pPage;
1654 assert( pCur->eSkip!=SKIP_INVALID );
1659 assert( pCur->idx<pPage->nCell );
1660 if( pCur->eSkip==SKIP_NEXT ){
1661 pCur->eSkip = SKIP_NONE;
1665 pCur->eSkip = SKIP_NONE;
1666 pCur->idx++;
1667 if( pCur->idx>=pPage->nCell ){
1669 rc = moveToChild(pCur, pPage->u.hdr.rightChild);
1671 rc = moveToLeftmost(pCur);
1680 moveToParent(pCur);
1681 pPage = pCur->pPage;
1682 }while( pCur->idx>=pPage->nCell );
1690 rc = moveToLeftmost(pCur);
1700 static int fileBtreePrevious(BtCursor *pCur, int *pRes){
1704 pPage = pCur->pPage;
1710 assert( pCur->eSkip!=SKIP_INVALID );
1715 if( pCur->eSkip==SKIP_PREV ){
1716 pCur->eSkip = SKIP_NONE;
1720 pCur->eSkip = SKIP_NONE;
1721 assert( pCur->idx>=0 );
1722 if( (pgno = pPage->apCell[pCur->idx]->h.leftChild)!=0 ){
1723 rc = moveToChild(pCur, pgno);
1725 rc = moveToRightmost(pCur);
1727 while( pCur->idx==0 ){
1732 moveToParent(pCur);
1733 pPage = pCur->pPage;
1735 pCur->idx--;
2168 ** pCur is left pointing to the same cell as when this routine was called
2169 ** even if that cell gets moved to a different page. pCur may be NULL.
2170 ** Set the pCur parameter to NULL if you do not care about keeping track
2186 static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){
2249 if( pCur && pCur->pPage==pChild ){
2251 pCur->pPage = pPage;
2285 if( pCur && pCur->pPage==pPage ){
2287 pCur->pPage = pChild;
2363 ** cursor pointing at the same cell. If pCur points to a page that
2368 if( pCur ){
2371 if( pCur->pPage==apOld[i] ){
2372 iCur += pCur->idx;
2376 if( i<nOld-1 && pCur->pPage==pParent && pCur->idx==idxDiv[i] ){
2381 pOldCurPage = pCur->pPage;
2523 if( pCur && iCur==j ){ pCur->pPage = pNew; pCur->idx = pNew->nCell; }
2533 if( pCur && iCur==j ){ pCur->pPage = pParent; pCur->idx = nxDiv; }
2546 if( pCur ){
2547 if( j<=iCur && pCur->pPage==pParent && pCur->idx>idxDiv[nOld-1] ){
2548 assert( pCur->pPage==pOldCurPage );
2549 pCur->idx += nNew - nOld;
2552 sqlitepager_ref(pCur->pPage);
2568 rc = balance(pBt, pParent, pCur);
2583 if( pCur && pCur->pPage==0 ){
2584 pCur->pPage = pParent;
2585 pCur->idx = 0;
2594 ** as pCur points to. If any of those cursors were opened with
2601 ** all cursors other than pCur so that they are pointing to the
2607 static int checkReadLocks(BtCursor *pCur){
2609 assert( pCur->wrFlag );
2610 for(p=pCur->pShared; p!=pCur; p=p->pShared){
2612 assert( p->pgnoRoot==pCur->pgnoRoot );
2628 BtCursor *pCur, /* Insert data into the table of this cursor */
2637 Btree *pBt = pCur->pBt;
2639 if( pCur->pPage==0 ){
2647 if( !pCur->wrFlag ){
2650 if( checkReadLocks(pCur) ){
2651 return SQLITE_LOCKED; /* The table pCur points to has a read lock */
2653 rc = fileBtreeMoveto(pCur, pKey, nKey, &loc);
2655 pPage = pCur->pPage;
2663 newCell.h.leftChild = pPage->apCell[pCur->idx]->h.leftChild;
2664 rc = clearCell(pBt, pPage->apCell[pCur->idx]);
2666 dropCell(pBt, pPage, pCur->idx, cellSize(pBt, pPage->apCell[pCur->idx]));
2669 pCur->idx++;
2673 insertCell(pBt, pPage, pCur->idx, &newCell, szNew);
2674 rc = balance(pCur->pBt, pPage, pCur);
2675 /* sqliteBtreePageDump(pCur->pBt, pCur->pgnoRoot, 1); */
2677 pCur->eSkip = SKIP_INVALID;
2686 ** the pCur->eSkip flag is set to SKIP_NEXT which forces the next call to
2690 ** pCur->eSkip is set to SKIP_PREV is the cursor is left pointing to
2695 static int fileBtreeDelete(BtCursor *pCur){
2696 MemPage *pPage = pCur->pPage;
2700 Btree *pBt = pCur->pBt;
2703 if( pCur->pPage==0 ){
2711 if( pCur->idx >= pPage->nCell ){
2714 if( !pCur->wrFlag ){
2717 if( checkReadLocks(pCur) ){
2718 return SQLITE_LOCKED; /* The table pCur points to has a read lock */
2722 pCell = pPage->apCell[pCur->idx];
2738 getTempCursor(pCur, &leafCur);
2746 dropCell(pBt, pPage, pCur->idx, cellSize(pBt, pCell));
2750 insertCell(pBt, pPage, pCur->idx, pNext, szNext);
2751 rc = balance(pBt, pPage, pCur);
2753 pCur->eSkip = SKIP_NEXT;
2755 rc = balance(pBt, leafCur.pPage, pCur);
2758 dropCell(pBt, pPage, pCur->idx, cellSize(pBt, pCell));
2759 if( pCur->idx>=pPage->nCell ){
2760 pCur->idx = pPage->nCell-1;
2761 if( pCur->idx<0 ){
2762 pCur->idx = 0;
2763 pCur->eSkip = SKIP_NEXT;
2765 pCur->eSkip = SKIP_PREV;
2768 pCur->eSkip = SKIP_NEXT;
2770 rc = balance(pBt, pPage, pCur);
2850 BtCursor *pCur;
2854 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
2855 if( pCur->pgnoRoot==(Pgno)iTable ){
2856 if( pCur->wrFlag==0 ) return SQLITE_LOCKED;
2857 moveToRoot(pCur);
2875 BtCursor *pCur;
2879 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
2880 if( pCur->pgnoRoot==(Pgno)iTable ){
3130 static int fileBtreeCursorDump(BtCursor *pCur, int *aResult){
3132 MemPage *pPage = pCur->pPage;
3133 Btree *pBt = pCur->pBt;
3135 aResult[1] = pCur->idx;
3137 if( pCur->idx>=0 && pCur->idx<pPage->nCell ){
3138 aResult[3] = cellSize(pBt, pPage->apCell[pCur->idx]);
3139 aResult[6] = SWAB32(pBt, pPage->apCell[pCur->idx]->h.leftChild);