Lines Matching refs:pCursor

173  * int cursorEOF(Cursor *pCursor);
178 * int cursorNext(Cursor *pCursor);
181 * void cursorDestroy(Cursor *pCursor);
627 static void interiorCursorDestroy(RecoverInteriorCursor *pCursor){
629 while( pCursor ){
630 RecoverInteriorCursor *p = pCursor;
631 pCursor = pCursor->pParent;
644 static void interiorCursorSetPage(RecoverInteriorCursor *pCursor,
648 if( pCursor->pPage ){
649 sqlite3PagerUnref(pCursor->pPage);
650 pCursor->pPage = NULL;
652 pCursor->pPage = pPage;
653 pCursor->iChild = 0;
660 pCursor->nChildren = decodeUnsigned16(PageHeader(pPage) +
667 RecoverInteriorCursor *pCursor =
669 if( !pCursor ){
673 memset(pCursor, 0, sizeof(*pCursor));
674 pCursor->pParent = pParent;
675 pCursor->nPageSize = nPageSize;
676 interiorCursorSetPage(pCursor, pPage);
677 *ppCursor = pCursor;
682 static unsigned interiorCursorChildPage(RecoverInteriorCursor *pCursor){
687 assert( pCursor->iChild<pCursor->nChildren );
690 pPageHeader = PageHeader(pCursor->pPage);
691 if( pCursor->iChild==pCursor->nChildren-1 ){
701 iCellOffset = decodeUnsigned16(pCellOffsets + pCursor->iChild*2);
702 if( iCellOffset<=pCursor->nPageSize-4 ){
703 return decodeUnsigned32(PageData(pCursor->pPage, iCellOffset));
715 static int interiorCursorEOF(RecoverInteriorCursor *pCursor){
717 while( pCursor && pCursor->iChild>=pCursor->nChildren ){
718 pCursor = pCursor->pParent;
720 return pCursor==NULL;
724 static int interiorCursorPageInUse(RecoverInteriorCursor *pCursor,
727 while( pCursor && pCursor->pPage->pgno!=iPage ){
728 pCursor = pCursor->pParent;
730 return pCursor!=NULL;
751 RecoverInteriorCursor *pCursor = *ppCursor;
757 while( pCursor->iChild<pCursor->nChildren ){
758 const unsigned iPage = interiorCursorChildPage(pCursor);
759 pCursor->iChild++;
760 if( interiorCursorPageInUse(pCursor, iPage) ){
763 int rc = sqlite3PagerAcquire(pCursor->pPage->pPager, iPage, ppPage, 0);
771 if( !pCursor->pParent ){
774 rc = interiorCursorNextPage(&pCursor->pParent, ppPage);
785 *ppCursor = pCursor->pParent;
786 pCursor->pParent = NULL;
787 interiorCursorDestroy(pCursor);
792 interiorCursorSetPage(pCursor, *ppPage);
1120 static int leafCursorLoadPage(RecoverLeafCursor *pCursor, DbPage *pPage){
1124 if( pCursor->pPage ){
1125 sqlite3PagerUnref(pCursor->pPage);
1126 pCursor->pPage = NULL;
1127 pCursor->iCell = pCursor->nCells = 0;
1136 int rc = interiorCursorCreate(pCursor->pParent, pPage, pCursor->nPageSize,
1141 pCursor->pParent = pParent;
1152 pCursor->pPage = pPage;
1153 pCursor->iCell = 0;
1154 pCursor->nCells = decodeUnsigned16(pPageHeader + kiPageCellCountOffset);
1162 static int leafCursorNextPage(RecoverLeafCursor *pCursor){
1163 if( !pCursor->pParent ){
1170 int rc = interiorCursorNextPage(&pCursor->pParent, &pNextPage);
1176 rc = leafCursorLoadPage(pCursor, pNextPage);
1181 } while( !pCursor->pPage );
1186 static void leafCursorDestroyCellData(RecoverLeafCursor *pCursor){
1187 if( pCursor->bFreeRecordHeader ){
1188 sqlite3_free(pCursor->pRecordHeader);
1190 pCursor->bFreeRecordHeader = 0;
1191 pCursor->pRecordHeader = NULL;
1193 if( pCursor->pOverflow ){
1194 overflowDestroy(pCursor->pOverflow);
1195 pCursor->pOverflow = NULL;
1199 static void leafCursorDestroy(RecoverLeafCursor *pCursor){
1200 leafCursorDestroyCellData(pCursor);
1202 if( pCursor->pParent ){
1203 interiorCursorDestroy(pCursor->pParent);
1204 pCursor->pParent = NULL;
1207 if( pCursor->pPage ){
1208 sqlite3PagerUnref(pCursor->pPage);
1209 pCursor->pPage = NULL;
1212 memset(pCursor, 0xA5, sizeof(*pCursor));
1213 sqlite3_free(pCursor);
1232 RecoverLeafCursor *pCursor; /* Leaf cursor being constructed. */
1241 pCursor = sqlite3_malloc(sizeof(RecoverLeafCursor));
1242 if( !pCursor ){
1246 memset(pCursor, 0, sizeof(*pCursor));
1248 pCursor->nPageSize = nPageSize;
1250 rc = leafCursorLoadPage(pCursor, pPage);
1253 leafCursorDestroy(pCursor);
1258 if( !pCursor->pPage ){
1259 rc = leafCursorNextPage(pCursor);
1261 leafCursorDestroy(pCursor);
1266 *ppCursor = pCursor;
1276 static int leafCursorCellDecode(RecoverLeafCursor *pCursor){
1294 assert( pCursor->iCell<pCursor->nCells );
1296 leafCursorDestroyCellData(pCursor);
1299 pPageHeader = PageHeader(pCursor->pPage);
1301 pPageEnd = PageData(pCursor->pPage, pCursor->nPageSize);
1302 if( pCellOffsets + pCursor->iCell*2 + 2 > pPageEnd ){
1305 iCellOffset = decodeUnsigned16(pCellOffsets + pCursor->iCell*2);
1306 if( iCellOffset>=pCursor->nPageSize ){
1310 pCell = PageData(pCursor->pPage, iCellOffset);
1311 nCellMaxBytes = pCursor->nPageSize - iCellOffset;
1324 assert( iCellOffset+nRead<=pCursor->nPageSize );
1325 pCursor->nRecordBytes = nRecordBytes;
1328 assert( iCellOffset+nRead<=pCursor->nPageSize );
1329 pCursor->iRowid = (i64)iRowid;
1331 pCursor->iRecordOffset = iCellOffset + nRead;
1336 rc = overflowMaybeCreate(pCursor->pPage, pCursor->nPageSize,
1337 pCursor->iRecordOffset, pCursor->nRecordBytes,
1338 &pCursor->nLocalRecordBytes,
1339 &pCursor->pOverflow);
1345 iEndOffset = pCursor->iRecordOffset + pCursor->nLocalRecordBytes;
1346 for( i=0; i<pCursor->nCells && pCellOffsets + i*2 + 2 <= pPageEnd; ++i ){
1355 pCursor->nRecordHeaderBytes = nRecordHeaderBytes;
1358 rc = overflowGetSegment(pCursor->pPage,
1359 pCursor->iRecordOffset, pCursor->nLocalRecordBytes,
1360 pCursor->pOverflow, 0, nRecordHeaderBytes,
1361 &pCursor->pRecordHeader, &pCursor->bFreeRecordHeader);
1371 if( !checkVarint(pCursor->pRecordHeader + nRecordHeaderRead,
1375 nRecordHeaderRead += getVarint(pCursor->pRecordHeader + nRecordHeaderRead,
1383 pCursor->nRecordCols = nRecordCols;
1398 static i64 leafCursorCellRowid(RecoverLeafCursor *pCursor){
1399 return pCursor->iRowid;
1402 static unsigned leafCursorCellColumns(RecoverLeafCursor *pCursor){
1403 return pCursor->nRecordCols;
1410 static int leafCursorCellColInfo(RecoverLeafCursor *pCursor,
1424 if( iCol>=pCursor->nRecordCols ){
1434 pRecordHeader = pCursor->pRecordHeader;
1435 if( !checkVarint(pRecordHeader, pCursor->nRecordHeaderBytes) ){
1443 assert( nRecordHeaderBytes==pCursor->nRecordHeaderBytes );
1467 if( nRecordHeaderBytes+iColEndOffset>pCursor->nRecordBytes ){
1478 return overflowGetSegment(pCursor->pPage, pCursor->iRecordOffset,
1479 pCursor->nLocalRecordBytes, pCursor->pOverflow,
1485 static int leafCursorNextValidCell(RecoverLeafCursor *pCursor){
1490 pCursor->iCell++;
1493 if( pCursor->iCell>=pCursor->nCells ){
1494 rc = leafCursorNextPage(pCursor);
1498 assert( pCursor->iCell==0 );
1502 rc = leafCursorCellDecode(pCursor);
1597 RecoverCursor *pCursor; /* Cursor to read rows from leaves. */
1625 pCursor = sqlite3_malloc(sizeof(RecoverCursor));
1626 if( !pCursor ){
1630 memset(pCursor, 0, sizeof(*pCursor));
1631 pCursor->base.pVtab = pVTab;
1632 pCursor->pLeafCursor = pLeafCursor;
1633 pCursor->iEncoding = iEncoding;
1639 pCursor->bEOF = (pLeafCursor->pPage==NULL);
1641 *ppCursor = (sqlite3_vtab_cursor*)pCursor;
1646 RecoverCursor *pCursor = (RecoverCursor*)cur;
1648 if( pCursor->pLeafCursor ){
1649 leafCursorDestroy(pCursor->pLeafCursor);
1650 pCursor->pLeafCursor = NULL;
1652 memset(pCursor, 0xA5, sizeof(*pCursor));
1665 static int recoverValidateLeafCell(Recover *pRecover, RecoverCursor *pCursor){
1669 if( leafCursorCellColumns(pCursor->pLeafCursor)>pRecover->nCols ){
1683 rc = leafCursorCellColInfo(pCursor->pLeafCursor, i, &iType, NULL, NULL);
1694 RecoverCursor *pCursor = (RecoverCursor*)pVtabCursor;
1695 Recover *pRecover = (Recover*)pCursor->base.pVtab;
1703 while( (rc = leafCursorNextValidCell(pCursor->pLeafCursor))==SQLITE_ROW ){
1704 if( recoverValidateLeafCell(pRecover, pCursor)==SQLITE_OK ){
1710 pCursor->bEOF = 1;
1723 RecoverCursor *pCursor = (RecoverCursor*)pVtabCursor;
1724 Recover *pRecover = (Recover*)pCursor->base.pVtab;
1730 if( pCursor->bEOF ){
1737 rc = leafCursorCellDecode(pCursor->pLeafCursor);
1738 if( rc!=SQLITE_OK || recoverValidateLeafCell(pRecover, pCursor)!=SQLITE_OK ){
1746 RecoverCursor *pCursor = (RecoverCursor*)pVtabCursor;
1748 return pCursor->bEOF;
1752 RecoverCursor *pCursor = (RecoverCursor*)cur;
1753 Recover *pRecover = (Recover*)pCursor->base.pVtab;
1767 sqlite3_result_int64(ctx, leafCursorCellRowid(pCursor->pLeafCursor));
1773 rc = leafCursorCellColInfo(pCursor->pLeafCursor, i, &iColType,
1815 if( pCursor->iEncoding==SQLITE_UTF16LE ){
1817 }else if( pCursor->iEncoding==SQLITE_UTF16BE ){
1832 RecoverCursor *pCursor = (RecoverCursor*)pVtabCursor;
1834 *pRowid = leafCursorCellRowid(pCursor->pLeafCursor);