Lines Matching refs:pCur
385 static int fileBtreeCloseCursor(BtCursor *pCur);
924 BtCursor *pCur; in fileBtreeRollback() local
929 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){ in fileBtreeRollback()
930 if( pCur->pPage && pCur->pPage->isInit==0 ){ in fileBtreeRollback()
931 sqlitepager_unref(pCur->pPage); in fileBtreeRollback()
932 pCur->pPage = 0; in fileBtreeRollback()
985 BtCursor *pCur; in fileBtreeRollbackCkpt() local
988 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){ in fileBtreeRollbackCkpt()
989 if( pCur->pPage && pCur->pPage->isInit==0 ){ in fileBtreeRollbackCkpt()
990 sqlitepager_unref(pCur->pPage); in fileBtreeRollbackCkpt()
991 pCur->pPage = 0; in fileBtreeRollbackCkpt()
1037 BtCursor *pCur, *pRing; in fileBtreeCursor() local
1050 pCur = sqliteMalloc( sizeof(*pCur) ); in fileBtreeCursor()
1051 if( pCur==0 ){ in fileBtreeCursor()
1055 pCur->pgnoRoot = (Pgno)iTable; in fileBtreeCursor()
1056 rc = sqlitepager_get(pBt->pPager, pCur->pgnoRoot, (void**)&pCur->pPage); in fileBtreeCursor()
1060 rc = initPage(pBt, pCur->pPage, pCur->pgnoRoot, 0); in fileBtreeCursor()
1064 pCur->pOps = &sqliteBtreeCursorOps; in fileBtreeCursor()
1065 pCur->pBt = pBt; in fileBtreeCursor()
1066 pCur->wrFlag = wrFlag; in fileBtreeCursor()
1067 pCur->idx = 0; in fileBtreeCursor()
1068 pCur->eSkip = SKIP_INVALID; in fileBtreeCursor()
1069 pCur->pNext = pBt->pCursor; in fileBtreeCursor()
1070 if( pCur->pNext ){ in fileBtreeCursor()
1071 pCur->pNext->pPrev = pCur; in fileBtreeCursor()
1073 pCur->pPrev = 0; in fileBtreeCursor()
1075 while( pRing && pRing->pgnoRoot!=pCur->pgnoRoot ){ pRing = pRing->pNext; } in fileBtreeCursor()
1077 pCur->pShared = pRing->pShared; in fileBtreeCursor()
1078 pRing->pShared = pCur; in fileBtreeCursor()
1080 pCur->pShared = pCur; in fileBtreeCursor()
1082 pBt->pCursor = pCur; in fileBtreeCursor()
1083 *ppCur = pCur; in fileBtreeCursor()
1088 if( pCur ){ in fileBtreeCursor()
1089 if( pCur->pPage ) sqlitepager_unref(pCur->pPage); in fileBtreeCursor()
1090 sqliteFree(pCur); in fileBtreeCursor()
1100 static int fileBtreeCloseCursor(BtCursor *pCur){ in fileBtreeCloseCursor() argument
1101 Btree *pBt = pCur->pBt; in fileBtreeCloseCursor()
1102 if( pCur->pPrev ){ in fileBtreeCloseCursor()
1103 pCur->pPrev->pNext = pCur->pNext; in fileBtreeCloseCursor()
1105 pBt->pCursor = pCur->pNext; in fileBtreeCloseCursor()
1107 if( pCur->pNext ){ in fileBtreeCloseCursor()
1108 pCur->pNext->pPrev = pCur->pPrev; in fileBtreeCloseCursor()
1110 if( pCur->pPage ){ in fileBtreeCloseCursor()
1111 sqlitepager_unref(pCur->pPage); in fileBtreeCloseCursor()
1113 if( pCur->pShared!=pCur ){ in fileBtreeCloseCursor()
1114 BtCursor *pRing = pCur->pShared; in fileBtreeCloseCursor()
1115 while( pRing->pShared!=pCur ){ pRing = pRing->pShared; } in fileBtreeCloseCursor()
1116 pRing->pShared = pCur->pShared; in fileBtreeCloseCursor()
1119 sqliteFree(pCur); in fileBtreeCloseCursor()
1127 static void getTempCursor(BtCursor *pCur, BtCursor *pTempCur){ in getTempCursor() argument
1128 memcpy(pTempCur, pCur, sizeof(*pCur)); in getTempCursor()
1140 static void releaseTempCursor(BtCursor *pCur){ in releaseTempCursor() argument
1141 if( pCur->pPage ){ in releaseTempCursor()
1142 sqlitepager_unref(pCur->pPage); in releaseTempCursor()
1153 static int fileBtreeKeySize(BtCursor *pCur, int *pSize){ in fileBtreeKeySize() argument
1157 pPage = pCur->pPage; in fileBtreeKeySize()
1159 if( pCur->idx >= pPage->nCell ){ in fileBtreeKeySize()
1162 pCell = pPage->apCell[pCur->idx]; in fileBtreeKeySize()
1163 *pSize = NKEY(pCur->pBt, pCell->h); in fileBtreeKeySize()
1176 static int getPayload(BtCursor *pCur, int offset, int amt, char *zBuf){ in getPayload() argument
1180 Btree *pBt = pCur->pBt; in getPayload()
1181 assert( pCur!=0 && pCur->pPage!=0 ); in getPayload()
1182 assert( pCur->idx>=0 && pCur->idx<pCur->pPage->nCell ); in getPayload()
1183 aPayload = pCur->pPage->apCell[pCur->idx]->aPayload; in getPayload()
1200 nextPage = SWAB32(pBt, pCur->pPage->apCell[pCur->idx]->ovfl); in getPayload()
1242 static int fileBtreeKey(BtCursor *pCur, int offset, int amt, char *zBuf){ in fileBtreeKey() argument
1247 assert( pCur->pPage!=0 ); in fileBtreeKey()
1248 pPage = pCur->pPage; in fileBtreeKey()
1249 if( pCur->idx >= pPage->nCell ){ in fileBtreeKey()
1252 assert( amt+offset <= NKEY(pCur->pBt, pPage->apCell[pCur->idx]->h) ); in fileBtreeKey()
1253 getPayload(pCur, offset, amt, zBuf); in fileBtreeKey()
1264 static int fileBtreeDataSize(BtCursor *pCur, int *pSize){ in fileBtreeDataSize() argument
1268 pPage = pCur->pPage; in fileBtreeDataSize()
1270 if( pCur->idx >= pPage->nCell ){ in fileBtreeDataSize()
1273 pCell = pPage->apCell[pCur->idx]; in fileBtreeDataSize()
1274 *pSize = NDATA(pCur->pBt, pCell->h); in fileBtreeDataSize()
1287 static int fileBtreeData(BtCursor *pCur, int offset, int amt, char *zBuf){ in fileBtreeData() argument
1293 assert( pCur->pPage!=0 ); in fileBtreeData()
1294 pPage = pCur->pPage; in fileBtreeData()
1295 if( pCur->idx >= pPage->nCell ){ in fileBtreeData()
1298 pCell = pPage->apCell[pCur->idx]; in fileBtreeData()
1299 assert( amt+offset <= NDATA(pCur->pBt, pCell->h) ); in fileBtreeData()
1300 getPayload(pCur, offset + NKEY(pCur->pBt, pCell->h), amt, zBuf); in fileBtreeData()
1326 BtCursor *pCur, /* Pointer to entry to compare against */ in fileBtreeKeyCompare() argument
1335 Btree *pBt = pCur->pBt; in fileBtreeKeyCompare()
1338 assert( pCur->pPage ); in fileBtreeKeyCompare()
1339 assert( pCur->idx>=0 && pCur->idx<pCur->pPage->nCell ); in fileBtreeKeyCompare()
1340 pCell = pCur->pPage->apCell[pCur->idx]; in fileBtreeKeyCompare()
1391 static int moveToChild(BtCursor *pCur, int newPgno){ in moveToChild() argument
1394 Btree *pBt = pCur->pBt; in moveToChild()
1399 rc = initPage(pBt, pNewPage, newPgno, pCur->pPage); in moveToChild()
1401 assert( pCur->idx>=pCur->pPage->nCell in moveToChild()
1402 || pCur->pPage->apCell[pCur->idx]->h.leftChild==SWAB32(pBt,newPgno) ); in moveToChild()
1403 assert( pCur->idx<pCur->pPage->nCell in moveToChild()
1404 || pCur->pPage->u.hdr.rightChild==SWAB32(pBt,newPgno) ); in moveToChild()
1405 pNewPage->idxParent = pCur->idx; in moveToChild()
1406 pCur->pPage->idxShift = 0; in moveToChild()
1407 sqlitepager_unref(pCur->pPage); in moveToChild()
1408 pCur->pPage = pNewPage; in moveToChild()
1409 pCur->idx = 0; in moveToChild()
1424 static void moveToParent(BtCursor *pCur){ in moveToParent() argument
1429 pPage = pCur->pPage; in moveToParent()
1436 pCur->pPage = pParent; in moveToParent()
1439 pCur->idx = idxParent; in moveToParent()
1444 oldPgno = SWAB32(pCur->pBt, sqlitepager_pagenumber(pPage)); in moveToParent()
1445 if( pCur->idx<pParent->nCell ){ in moveToParent()
1458 pCur->idx = pParent->nCell; in moveToParent()
1459 oldPgno = SWAB32(pCur->pBt, sqlitepager_pagenumber(pPage)); in moveToParent()
1462 pCur->idx = i; in moveToParent()
1472 static int moveToRoot(BtCursor *pCur){ in moveToRoot() argument
1475 Btree *pBt = pCur->pBt; in moveToRoot()
1477 rc = sqlitepager_get(pBt->pPager, pCur->pgnoRoot, (void**)&pNew); in moveToRoot()
1479 rc = initPage(pBt, pNew, pCur->pgnoRoot, 0); in moveToRoot()
1481 sqlitepager_unref(pCur->pPage); in moveToRoot()
1482 pCur->pPage = pNew; in moveToRoot()
1483 pCur->idx = 0; in moveToRoot()
1491 static int moveToLeftmost(BtCursor *pCur){ in moveToLeftmost() argument
1495 while( (pgno = pCur->pPage->apCell[pCur->idx]->h.leftChild)!=0 ){ in moveToLeftmost()
1496 rc = moveToChild(pCur, pgno); in moveToLeftmost()
1509 static int moveToRightmost(BtCursor *pCur){ in moveToRightmost() argument
1513 while( (pgno = pCur->pPage->u.hdr.rightChild)!=0 ){ in moveToRightmost()
1514 pCur->idx = pCur->pPage->nCell; in moveToRightmost()
1515 rc = moveToChild(pCur, pgno); in moveToRightmost()
1518 pCur->idx = pCur->pPage->nCell - 1; in moveToRightmost()
1526 static int fileBtreeFirst(BtCursor *pCur, int *pRes){ in fileBtreeFirst() argument
1528 if( pCur->pPage==0 ) return SQLITE_ABORT; in fileBtreeFirst()
1529 rc = moveToRoot(pCur); in fileBtreeFirst()
1531 if( pCur->pPage->nCell==0 ){ in fileBtreeFirst()
1536 rc = moveToLeftmost(pCur); in fileBtreeFirst()
1537 pCur->eSkip = SKIP_NONE; in fileBtreeFirst()
1545 static int fileBtreeLast(BtCursor *pCur, int *pRes){ in fileBtreeLast() argument
1547 if( pCur->pPage==0 ) return SQLITE_ABORT; in fileBtreeLast()
1548 rc = moveToRoot(pCur); in fileBtreeLast()
1550 assert( pCur->pPage->isInit ); in fileBtreeLast()
1551 if( pCur->pPage->nCell==0 ){ in fileBtreeLast()
1556 rc = moveToRightmost(pCur); in fileBtreeLast()
1557 pCur->eSkip = SKIP_NONE; in fileBtreeLast()
1585 int fileBtreeMoveto(BtCursor *pCur, const void *pKey, int nKey, int *pRes){ in fileBtreeMoveto() argument
1587 if( pCur->pPage==0 ) return SQLITE_ABORT; in fileBtreeMoveto()
1588 pCur->eSkip = SKIP_NONE; in fileBtreeMoveto()
1589 rc = moveToRoot(pCur); in fileBtreeMoveto()
1594 MemPage *pPage = pCur->pPage; in fileBtreeMoveto()
1599 pCur->idx = (lwr+upr)/2; in fileBtreeMoveto()
1600 rc = fileBtreeKeyCompare(pCur, pKey, nKey, 0, &c); in fileBtreeMoveto()
1603 pCur->iMatch = c; in fileBtreeMoveto()
1608 lwr = pCur->idx+1; in fileBtreeMoveto()
1610 upr = pCur->idx-1; in fileBtreeMoveto()
1621 pCur->iMatch = c; in fileBtreeMoveto()
1625 pCur->idx = lwr; in fileBtreeMoveto()
1626 rc = moveToChild(pCur, chldPg); in fileBtreeMoveto()
1638 static int fileBtreeNext(BtCursor *pCur, int *pRes){ in fileBtreeNext() argument
1640 MemPage *pPage = pCur->pPage; in fileBtreeNext()
1647 assert( pCur->eSkip!=SKIP_INVALID ); in fileBtreeNext()
1652 assert( pCur->idx<pPage->nCell ); in fileBtreeNext()
1653 if( pCur->eSkip==SKIP_NEXT ){ in fileBtreeNext()
1654 pCur->eSkip = SKIP_NONE; in fileBtreeNext()
1658 pCur->eSkip = SKIP_NONE; in fileBtreeNext()
1659 pCur->idx++; in fileBtreeNext()
1660 if( pCur->idx>=pPage->nCell ){ in fileBtreeNext()
1662 rc = moveToChild(pCur, pPage->u.hdr.rightChild); in fileBtreeNext()
1664 rc = moveToLeftmost(pCur); in fileBtreeNext()
1673 moveToParent(pCur); in fileBtreeNext()
1674 pPage = pCur->pPage; in fileBtreeNext()
1675 }while( pCur->idx>=pPage->nCell ); in fileBtreeNext()
1683 rc = moveToLeftmost(pCur); in fileBtreeNext()
1693 static int fileBtreePrevious(BtCursor *pCur, int *pRes){ in fileBtreePrevious() argument
1697 pPage = pCur->pPage; in fileBtreePrevious()
1703 assert( pCur->eSkip!=SKIP_INVALID ); in fileBtreePrevious()
1708 if( pCur->eSkip==SKIP_PREV ){ in fileBtreePrevious()
1709 pCur->eSkip = SKIP_NONE; in fileBtreePrevious()
1713 pCur->eSkip = SKIP_NONE; in fileBtreePrevious()
1714 assert( pCur->idx>=0 ); in fileBtreePrevious()
1715 if( (pgno = pPage->apCell[pCur->idx]->h.leftChild)!=0 ){ in fileBtreePrevious()
1716 rc = moveToChild(pCur, pgno); in fileBtreePrevious()
1718 rc = moveToRightmost(pCur); in fileBtreePrevious()
1720 while( pCur->idx==0 ){ in fileBtreePrevious()
1725 moveToParent(pCur); in fileBtreePrevious()
1726 pPage = pCur->pPage; in fileBtreePrevious()
1728 pCur->idx--; in fileBtreePrevious()
2179 static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){ in balance() argument
2242 if( pCur && pCur->pPage==pChild ){ in balance()
2244 pCur->pPage = pPage; in balance()
2278 if( pCur && pCur->pPage==pPage ){ in balance()
2280 pCur->pPage = pChild; in balance()
2361 if( pCur ){ in balance()
2364 if( pCur->pPage==apOld[i] ){ in balance()
2365 iCur += pCur->idx; in balance()
2369 if( i<nOld-1 && pCur->pPage==pParent && pCur->idx==idxDiv[i] ){ in balance()
2374 pOldCurPage = pCur->pPage; in balance()
2515 if( pCur && iCur==j ){ pCur->pPage = pNew; pCur->idx = pNew->nCell; } in balance()
2525 if( pCur && iCur==j ){ pCur->pPage = pParent; pCur->idx = nxDiv; } in balance()
2538 if( pCur ){ in balance()
2539 if( j<=iCur && pCur->pPage==pParent && pCur->idx>idxDiv[nOld-1] ){ in balance()
2540 assert( pCur->pPage==pOldCurPage ); in balance()
2541 pCur->idx += nNew - nOld; in balance()
2544 sqlitepager_ref(pCur->pPage); in balance()
2560 rc = balance(pBt, pParent, pCur); in balance()
2575 if( pCur && pCur->pPage==0 ){ in balance()
2576 pCur->pPage = pParent; in balance()
2577 pCur->idx = 0; in balance()
2599 static int checkReadLocks(BtCursor *pCur){ in checkReadLocks() argument
2601 assert( pCur->wrFlag ); in checkReadLocks()
2602 for(p=pCur->pShared; p!=pCur; p=p->pShared){ in checkReadLocks()
2604 assert( p->pgnoRoot==pCur->pgnoRoot ); in checkReadLocks()
2620 BtCursor *pCur, /* Insert data into the table of this cursor */ in fileBtreeInsert() argument
2629 Btree *pBt = pCur->pBt; in fileBtreeInsert()
2631 if( pCur->pPage==0 ){ in fileBtreeInsert()
2639 if( !pCur->wrFlag ){ in fileBtreeInsert()
2642 if( checkReadLocks(pCur) ){ in fileBtreeInsert()
2645 rc = fileBtreeMoveto(pCur, pKey, nKey, &loc); in fileBtreeInsert()
2647 pPage = pCur->pPage; in fileBtreeInsert()
2655 newCell.h.leftChild = pPage->apCell[pCur->idx]->h.leftChild; in fileBtreeInsert()
2656 rc = clearCell(pBt, pPage->apCell[pCur->idx]); in fileBtreeInsert()
2658 dropCell(pBt, pPage, pCur->idx, cellSize(pBt, pPage->apCell[pCur->idx])); in fileBtreeInsert()
2661 pCur->idx++; in fileBtreeInsert()
2665 insertCell(pBt, pPage, pCur->idx, &newCell, szNew); in fileBtreeInsert()
2666 rc = balance(pCur->pBt, pPage, pCur); in fileBtreeInsert()
2669 pCur->eSkip = SKIP_INVALID; in fileBtreeInsert()
2687 static int fileBtreeDelete(BtCursor *pCur){ in fileBtreeDelete() argument
2688 MemPage *pPage = pCur->pPage; in fileBtreeDelete()
2692 Btree *pBt = pCur->pBt; in fileBtreeDelete()
2695 if( pCur->pPage==0 ){ in fileBtreeDelete()
2703 if( pCur->idx >= pPage->nCell ){ in fileBtreeDelete()
2706 if( !pCur->wrFlag ){ in fileBtreeDelete()
2709 if( checkReadLocks(pCur) ){ in fileBtreeDelete()
2714 pCell = pPage->apCell[pCur->idx]; in fileBtreeDelete()
2729 getTempCursor(pCur, &leafCur); in fileBtreeDelete()
2737 dropCell(pBt, pPage, pCur->idx, cellSize(pBt, pCell)); in fileBtreeDelete()
2741 insertCell(pBt, pPage, pCur->idx, pNext, szNext); in fileBtreeDelete()
2742 rc = balance(pBt, pPage, pCur); in fileBtreeDelete()
2744 pCur->eSkip = SKIP_NEXT; in fileBtreeDelete()
2746 rc = balance(pBt, leafCur.pPage, pCur); in fileBtreeDelete()
2749 dropCell(pBt, pPage, pCur->idx, cellSize(pBt, pCell)); in fileBtreeDelete()
2750 if( pCur->idx>=pPage->nCell ){ in fileBtreeDelete()
2751 pCur->idx = pPage->nCell-1; in fileBtreeDelete()
2752 if( pCur->idx<0 ){ in fileBtreeDelete()
2753 pCur->idx = 0; in fileBtreeDelete()
2754 pCur->eSkip = SKIP_NEXT; in fileBtreeDelete()
2756 pCur->eSkip = SKIP_PREV; in fileBtreeDelete()
2759 pCur->eSkip = SKIP_NEXT; in fileBtreeDelete()
2761 rc = balance(pBt, pPage, pCur); in fileBtreeDelete()
2841 BtCursor *pCur; in fileBtreeClearTable() local
2845 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){ in fileBtreeClearTable()
2846 if( pCur->pgnoRoot==(Pgno)iTable ){ in fileBtreeClearTable()
2847 if( pCur->wrFlag==0 ) return SQLITE_LOCKED; in fileBtreeClearTable()
2848 moveToRoot(pCur); in fileBtreeClearTable()
2866 BtCursor *pCur; in fileBtreeDropTable() local
2870 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){ in fileBtreeDropTable()
2871 if( pCur->pgnoRoot==(Pgno)iTable ){ in fileBtreeDropTable()
3121 static int fileBtreeCursorDump(BtCursor *pCur, int *aResult){ in fileBtreeCursorDump() argument
3123 MemPage *pPage = pCur->pPage; in fileBtreeCursorDump()
3124 Btree *pBt = pCur->pBt; in fileBtreeCursorDump()
3126 aResult[1] = pCur->idx; in fileBtreeCursorDump()
3128 if( pCur->idx>=0 && pCur->idx<pPage->nCell ){ in fileBtreeCursorDump()
3129 aResult[3] = cellSize(pBt, pPage->apCell[pCur->idx]); in fileBtreeCursorDump()
3130 aResult[6] = SWAB32(pBt, pPage->apCell[pCur->idx]->h.leftChild); in fileBtreeCursorDump()