Lines Matching refs:pIter
52005 WalIterator *pIter = 0; /* Wal iterator context */
52020 rc = walIteratorInit(pWal, &pIter);
52024 assert( pIter );
52086 while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
52166 walIteratorFree(pIter);
54752 BtLock *pIter;
54779 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
54780 /* The condition (pIter->eLock!=eLock) in the following if(...)
54783 ** (eLock==WRITE_LOCK || pIter->eLock==WRITE_LOCK)
54789 assert( pIter->eLock==READ_LOCK || pIter->eLock==WRITE_LOCK );
54790 assert( eLock==READ_LOCK || pIter->pBtree==p || pIter->eLock==READ_LOCK);
54791 if( pIter->pBtree!=p && pIter->iTable==iTab && pIter->eLock!=eLock ){
54792 sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
54825 BtLock *pIter;
54843 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
54844 if( pIter->iTable==iTable && pIter->pBtree==p ){
54845 pLock = pIter;
55579 u8 *pIter; /* For scanning through pCell */
55589 pIter = pCell;
55593 ** pIter += getVarint32(pIter, nPayload);
55597 nPayload = *pIter;
55599 u8 *pEnd = &pIter[8];
55602 nPayload = (nPayload<<7) | (*++pIter & 0x7f);
55603 }while( (*pIter)>=0x80 && pIter<pEnd );
55605 pIter++;
55609 ** pIter += getVarint(pIter, (u64*)&pInfo->nKey);
55613 iKey = *pIter;
55615 u8 *pEnd = &pIter[7];
55618 iKey = (iKey<<7) | (*++pIter & 0x7f);
55619 if( (*pIter)<0x80 ) break;
55620 if( pIter>=pEnd ){
55621 iKey = (iKey<<8) | *++pIter;
55626 pIter++;
55630 pInfo->pPayload = pIter;
55637 pInfo->nSize = nPayload + (u16)(pIter - pCell);
55650 u8 *pIter; /* For scanning through pCell */
55657 pIter = pCell + pPage->childPtrSize;
55658 nPayload = *pIter;
55660 u8 *pEnd = &pIter[8];
55663 nPayload = (nPayload<<7) | (*++pIter & 0x7f);
55664 }while( *(pIter)>=0x80 && pIter<pEnd );
55666 pIter++;
55669 pInfo->pPayload = pIter;
55676 pInfo->nSize = nPayload + (u16)(pIter - pCell);
55705 u8 *pIter = pCell + pPage->childPtrSize; /* For looping over bytes of pCell */
55719 nSize = *pIter;
55721 pEnd = &pIter[8];
55724 nSize = (nSize<<7) | (*++pIter & 0x7f);
55725 }while( *(pIter)>=0x80 && pIter<pEnd );
55727 pIter++;
55729 /* pIter now points at the 64-bit integer key value, a variable length
55730 ** integer. The following block moves pIter to point at the first byte
55732 pEnd = &pIter[9];
55733 while( (*pIter++)&0x80 && pIter<pEnd );
55738 nSize += (u32)(pIter - pCell);
55748 nSize += 4 + (u16)(pIter - pCell);
55754 u8 *pIter = pCell + 4; /* For looping over bytes of pCell */
55769 pEnd = pIter + 9;
55770 while( (*pIter++)&0x80 && pIter<pEnd );
55771 assert( debuginfo.nSize==(u16)(pIter - pCell) || CORRUPT_DB );
55772 return (u16)(pIter - pCell);
57632 BtLock *pIter;
57633 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
57634 if( pIter->pBtree!=p ){
57635 pBlock = pIter->pBtree->db;
140244 char *pIter; /* Used to iterate through aAll */
140248 pIter = pDL->pNextDocid;
140250 pIter = pDL->aAll;
140253 if( pIter>=pEnd ){
140258 pIter += sqlite3Fts3GetVarint(pIter, &iDelta);
140264 pDL->pList = pIter;
140265 fts3PoslistCopy(0, &pIter);
140266 pDL->nList = (int)(pIter - pDL->pList);
140268 /* pIter now points just past the 0x00 that terminates the position-
140270 ** edited in place by fts3EvalNearTrim(), then pIter may not actually
140272 ** with this case by advancing pIter past the zero-padding added by
140274 while( pIter<pEnd && *pIter==0 ) pIter++;
140276 pDL->pNextDocid = pIter;
140277 assert( pIter>=&pDL->aAll[pDL->nAll] || *pIter );
141611 char *pIter;
141624 pIter = pPhrase->doclist.pList;
141676 pIter = pPh->pOrPoslist;
141680 (pIter >= (pPh->doclist.aAll + pPh->doclist.nAll));
141681 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
141684 &pIter, &iDocid, &bEof
141688 bEof = !pPh->doclist.nAll || (pIter && pIter<=pPh->doclist.aAll);
141689 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){
141693 &pIter, &iDocid, &dummy, &bEof
141697 pPh->pOrPoslist = pIter;
141703 pIter = pPhrase->pOrPoslist;
141705 pIter = 0;
141708 if( pIter==0 ) return SQLITE_OK;
141710 if( *pIter==0x01 ){
141711 pIter++;
141712 pIter += fts3GetVarint32(pIter, &iThis);
141717 fts3ColumnlistCopy(0, &pIter);
141718 if( *pIter==0x00 ) return SQLITE_OK;
141719 pIter++;
141720 pIter += fts3GetVarint32(pIter, &iThis);
141722 if( *pIter==0x00 ){
141723 pIter = 0;
141726 *ppOut = ((iCol==iThis)?pIter:0);
143067 Fts3Expr *pIter = pNotBranch;
143068 while( pIter->pLeft ){
143069 pIter = pIter->pLeft;
143071 pIter->pLeft = pRet;
143072 pRet->pParent = pIter;
148036 SegmentNode *pIter;
148039 for(pIter=pTree->pLeftmost; pIter && rc==SQLITE_OK; pIter=pIter->pRight){
148040 int nStart = fts3TreeFinishNode(pIter, iHeight, iNextLeaf);
148041 int nWrite = pIter->nData - nStart;
148043 rc = fts3WriteSegment(p, iNextFree, &pIter->aData[nStart], nWrite);
148045 iNextLeaf += (pIter->nEntry+1);
151911 char *pIter = *ppIter;
151912 if( pIter ){
151916 if( 0==(*pIter & 0xFE) ){
151918 pIter = 0;
151921 fts3GetDeltaPosition(&pIter, &iIter);
151925 *ppIter = pIter;
151932 static int fts3SnippetNextCandidate(SnippetIter *pIter){
151935 if( pIter->iCurrent<0 ){
151940 pIter->iCurrent = 0;
151945 for(i=0; i<pIter->nPhrase; i++){
151946 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
151947 fts3SnippetAdvance(&pPhrase->pHead, &pPhrase->iHead, pIter->nSnippet);
151953 for(i=0; i<pIter->nPhrase; i++){
151954 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
151963 pIter->iCurrent = iStart = iEnd - pIter->nSnippet + 1;
151964 for(i=0; i<pIter->nPhrase; i++){
151965 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
151976 ** iterator pIter.
151979 SnippetIter *pIter, /* Snippet iterator */
151986 int iStart = pIter->iCurrent; /* First token of snippet */
151992 for(i=0; i<pIter->nPhrase; i++){
151993 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
151998 while( iCsr<(iStart+pIter->nSnippet) ){
152428 char *pIter = pPhrase->doclist.pList;
152439 int nHit = fts3ColumnlistCount(&pIter);
152447 assert( *pIter==0x00 || *pIter==0x01 );
152448 if( *pIter!=0x01 ) break;
152449 pIter++;
152450 pIter += fts3GetVarint32(pIter, &iCol);
152653 static int fts3LcsIteratorAdvance(LcsIterator *pIter){
152654 char *pRead = pIter->pRead;
152663 pIter->iPos += (int)(iRead-2);
152666 pIter->pRead = pRead;
152696 LcsIterator *pIter = &aIter[i];
152697 nToken -= pIter->pExpr->pPhrase->nToken;
152698 pIter->iPosOffset = nToken;
152722 LcsIterator *pIter = &aIter[i];
152723 if( pIter->pRead==0 ){
152727 if( pAdv==0 || pIter->iPos<pAdv->iPos ){
152728 pAdv = pIter;
152730 if( nThisLcs==0 || pIter->iPos==pIter[-1].iPos ){
158099 UBreakIterator *pIter; /* ICU break-iterator object */
158212 pCsr->pIter = ubrk_open(UBRK_WORD, p->zLocale, pCsr->aChar, iOut, &status);
158219 ubrk_first(pCsr->pIter);
158229 ubrk_close(pCsr->pIter);
158255 iStart = ubrk_current(pCsr->pIter);
158256 iEnd = ubrk_next(pCsr->pIter);
159475 static void rbuObjIterFreeCols(RbuObjIter *pIter){
159477 for(i=0; i<pIter->nTblCol; i++){
159478 sqlite3_free(pIter->azTblCol[i]);
159479 sqlite3_free(pIter->azTblType[i]);
159481 sqlite3_free(pIter->azTblCol);
159482 pIter->azTblCol = 0;
159483 pIter->azTblType = 0;
159484 pIter->aiSrcOrder = 0;
159485 pIter->abTblPk = 0;
159486 pIter->abNotNull = 0;
159487 pIter->nTblCol = 0;
159488 pIter->eType = 0; /* Invalid value */
159495 static void rbuObjIterClearStatements(RbuObjIter *pIter){
159498 sqlite3_finalize(pIter->pSelect);
159499 sqlite3_finalize(pIter->pInsert);
159500 sqlite3_finalize(pIter->pDelete);
159501 sqlite3_finalize(pIter->pTmpInsert);
159502 pUp = pIter->pRbuUpdate;
159510 pIter->pSelect = 0;
159511 pIter->pInsert = 0;
159512 pIter->pDelete = 0;
159513 pIter->pRbuUpdate = 0;
159514 pIter->pTmpInsert = 0;
159515 pIter->nCol = 0;
159522 static void rbuObjIterFinalize(RbuObjIter *pIter){
159523 rbuObjIterClearStatements(pIter);
159524 sqlite3_finalize(pIter->pTblIter);
159525 sqlite3_finalize(pIter->pIdxIter);
159526 rbuObjIterFreeCols(pIter);
159527 memset(pIter, 0, sizeof(RbuObjIter));
159538 static int rbuObjIterNext(sqlite3rbu *p, RbuObjIter *pIter){
159543 rbuObjIterClearStatements(pIter);
159544 if( pIter->zIdx==0 ){
159555 if( pIter->bCleanup ){
159556 rbuObjIterFreeCols(pIter);
159557 pIter->bCleanup = 0;
159558 rc = sqlite3_step(pIter->pTblIter);
159560 rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg);
159561 pIter->zTbl = 0;
159563 pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0);
159564 pIter->zDataTbl = (const char*)sqlite3_column_text(pIter->pTblIter,1);
159565 rc = (pIter->zDataTbl && pIter->zTbl) ? SQLITE_OK : SQLITE_NOMEM;
159568 if( pIter->zIdx==0 ){
159569 sqlite3_stmt *pIdx = pIter->pIdxIter;
159570 rc = sqlite3_bind_text(pIdx, 1, pIter->zTbl, -1, SQLITE_STATIC);
159573 rc = sqlite3_step(pIter->pIdxIter);
159575 rc = resetAndCollectError(pIter->pIdxIter, &p->zErrmsg);
159576 pIter->bCleanup = 1;
159577 pIter->zIdx = 0;
159579 pIter->zIdx = (const char*)sqlite3_column_text(pIter->pIdxIter, 0);
159580 pIter->iTnum = sqlite3_column_int(pIter->pIdxIter, 1);
159581 pIter->bUnique = sqlite3_column_int(pIter->pIdxIter, 2);
159582 rc = pIter->zIdx ? SQLITE_OK : SQLITE_NOMEM;
159590 rbuObjIterFinalize(pIter);
159638 static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
159640 memset(pIter, 0, sizeof(RbuObjIter));
159642 rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
159649 rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
159656 pIter->bCleanup = 1;
159658 return rbuObjIterNext(p, pIter);
159738 ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
159742 static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){
159748 pIter->azTblCol = azNew;
159749 pIter->azTblType = &azNew[nCol];
159750 pIter->aiSrcOrder = (int*)&pIter->azTblType[nCol];
159751 pIter->abTblPk = (u8*)&pIter->aiSrcOrder[nCol];
159752 pIter->abNotNull = (u8*)&pIter->abTblPk[nCol];
159753 pIter->abIndexed = (u8*)&pIter->abNotNull[nCol];
159921 ** the pIter->abIndexed[] array.
159923 static void rbuObjIterCacheIndexedCols(sqlite3rbu *p, RbuObjIter *pIter){
159928 memcpy(pIter->abIndexed, pIter->abTblPk, sizeof(u8)*pIter->nTblCol);
159930 sqlite3_mprintf("PRAGMA main.index_list = %Q", pIter->zTbl)
159943 if( iCid>=0 ) pIter->abIndexed[iCid] = 1;
159950 if( bIndex==0 ) pIter->abIndexed = 0;
159955 ** If they are not already populated, populate the pIter->azTblCol[],
159956 ** pIter->abTblPk[], pIter->nTblCol and pIter->bRowid variables according to
159963 static int rbuObjIterCacheTableInfo(sqlite3rbu *p, RbuObjIter *pIter){
159964 if( pIter->azTblCol==0 ){
159973 assert( pIter->eType==0 );
159974 rbuTableType(p, pIter->zTbl, &pIter->eType, &iTnum, &pIter->iPkTnum);
159975 if( p->rc==SQLITE_OK && pIter->eType==RBU_PK_NOTABLE ){
159977 p->zErrmsg = sqlite3_mprintf("no such table: %s", pIter->zTbl);
159980 if( pIter->zIdx==0 ) pIter->iTnum = iTnum;
159982 assert( pIter->eType==RBU_PK_NONE || pIter->eType==RBU_PK_IPK
159983 || pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_WITHOUT_ROWID
159984 || pIter->eType==RBU_PK_VTAB
159991 sqlite3_mprintf("SELECT * FROM '%q'", pIter->zDataTbl)
159995 rbuAllocateIterArrays(p, pIter, nCol);
160001 pIter->aiSrcOrder[pIter->nTblCol] = pIter->nTblCol;
160002 pIter->azTblCol[pIter->nTblCol++] = zCopy;
160012 && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
160016 "table %q %s rbu_rowid column", pIter->zDataTbl,
160026 sqlite3_mprintf("PRAGMA table_info(%Q)", pIter->zTbl)
160032 for(i=iOrder; i<pIter->nTblCol; i++){
160033 if( 0==strcmp(zName, pIter->azTblCol[i]) ) break;
160035 if( i==pIter->nTblCol ){
160038 pIter->zDataTbl, zName
160046 SWAP(int, pIter->aiSrcOrder[i], pIter->aiSrcOrder[iOrder]);
160047 SWAP(char*, pIter->azTblCol[i], pIter->azTblCol[iOrder]);
160050 pIter->azTblType[iOrder] = rbuStrndup(zType, &p->rc);
160051 pIter->abTblPk[iOrder] = (iPk!=0);
160052 pIter->abNotNull[iOrder] = (u8)bNotNull || (iPk!=0);
160058 rbuObjIterCacheIndexedCols(p, pIter);
160059 assert( pIter->eType!=RBU_PK_VTAB || pIter->abIndexed==0 );
160068 ** column names currently stored in the pIter->azTblCol[] array.
160072 RbuObjIter *pIter /* Object iterator for column names */
160077 for(i=0; i<pIter->nTblCol; i++){
160078 const char *z = pIter->azTblCol[i];
160111 RbuObjIter *pIter, /* Object iterator for column names */
160131 sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", pIter->zIdx)
160145 if( pIter->eType==RBU_PK_IPK ){
160147 for(i=0; pIter->abTblPk[i]==0; i++);
160148 assert( i<pIter->nTblCol );
160149 zCol = pIter->azTblCol[i];
160155 zCol = pIter->azTblCol[iCid];
160156 zType = pIter->azTblType[iCid];
160160 if( pIter->bUnique==0 || sqlite3_column_int(pXInfo, 5) ){
160213 RbuObjIter *pIter,
160217 if( p->rc==SQLITE_OK && pIter->abIndexed ){
160220 for(i=0; i<pIter->nTblCol; i++){
160221 if( pIter->abIndexed[i] ){
160222 const char *zCol = pIter->azTblCol[i];
160235 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
160254 RbuObjIter *pIter
160257 if( pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE ){
160258 zList = rbuMPrintf(p, "_rowid_ = ?%d", pIter->nTblCol+1);
160259 }else if( pIter->eType==RBU_PK_EXTERNAL ){
160262 for(i=0; i<pIter->nTblCol; i++){
160263 if( pIter->abTblPk[i] ){
160275 for(i=0; i<pIter->nTblCol; i++){
160276 if( pIter->abTblPk[i] ){
160277 const char *zCol = pIter->azTblCol[i];
160318 RbuObjIter *pIter,
160325 if( (int)strlen(zMask)!=pIter->nTblCol ){
160329 for(i=0; i<pIter->nTblCol; i++){
160330 char c = zMask[pIter->aiSrcOrder[i]];
160333 zList, zSep, pIter->azTblCol[i], i+1
160339 zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
160345 zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
160397 static char *rbuWithoutRowidPK(sqlite3rbu *p, RbuObjIter *pIter){
160399 assert( pIter->zIdx==0 );
160402 sqlite3_stmt *pXList = 0; /* PRAGMA index_list = (pIter->zTbl) */
160406 sqlite3_mprintf("PRAGMA main.index_list = %Q", pIter->zTbl)
160456 static void rbuCreateImposterTable2(sqlite3rbu *p, RbuObjIter *pIter){
160457 if( p->rc==SQLITE_OK && pIter->eType==RBU_PK_EXTERNAL ){
160458 int tnum = pIter->iPkTnum; /* Root page of PK index */
160492 iCid, pIter->azTblType[iCid], zCollate
160530 static void rbuCreateImposterTable(sqlite3rbu *p, RbuObjIter *pIter){
160531 if( p->rc==SQLITE_OK && pIter->eType!=RBU_PK_VTAB ){
160532 int tnum = pIter->iTnum;
160538 for(iCol=0; p->rc==SQLITE_OK && iCol<pIter->nTblCol; iCol++){
160540 const char *zCol = pIter->azTblCol[iCol];
160544 p->dbMain, "main", pIter->zTbl, zCol, 0, &zColl, 0, 0, 0
160547 if( pIter->eType==RBU_PK_IPK && pIter->abTblPk[iCol] ){
160553 zSql, zComma, zCol, pIter->azTblType[iCol], zPk, zColl,
160554 (pIter->abNotNull[iCol] ? " NOT NULL" : "")
160559 if( pIter->eType==RBU_PK_WITHOUT_ROWID ){
160560 char *zPk = rbuWithoutRowidPK(p, pIter);
160568 pIter->zTbl, zSql,
160569 (pIter->eType==RBU_PK_WITHOUT_ROWID ? " WITHOUT ROWID" : "")
160588 RbuObjIter *pIter,
160592 int bRbuRowid = (pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE);
160593 char *zBind = rbuObjIterGetBindlist(p, pIter->nTblCol + 1 + bRbuRowid);
160595 assert( pIter->pTmpInsert==0 );
160597 p->dbRbu, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf(
160599 p->zStateDb, pIter->zDataTbl, zCollist, zRbuRowid, zBind
160633 RbuObjIter *pIter,
160636 assert( pIter->bCleanup==0 );
160637 if( pIter->pSelect==0 && rbuObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){
160638 const int tnum = pIter->iTnum;
160641 const char *zIdx = pIter->zIdx;
160650 const char *zTbl = pIter->zTbl;
160657 assert( pIter->eType!=RBU_PK_VTAB );
160659 p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
160673 pIter->nCol = nBind;
160676 p->dbMain, &pIter->pInsert, &p->zErrmsg,
160684 p->dbMain, &pIter->pDelete, &p->zErrmsg,
160692 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
160695 zCollist, p->zStateDb, pIter->zDataTbl,
160705 zCollist, pIter->zDataTbl,
160706 zCollist, p->zStateDb, pIter->zDataTbl,
160710 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
160718 int bRbuRowid = (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE);
160719 const char *zTbl = pIter->zTbl; /* Table this step applies to */
160722 char *zBindings = rbuObjIterGetBindlist(p, pIter->nTblCol + bRbuRowid);
160723 char *zWhere = rbuObjIterGetWhere(p, pIter);
160724 char *zOldlist = rbuObjIterGetOldlist(p, pIter, "old");
160725 char *zNewlist = rbuObjIterGetOldlist(p, pIter, "new");
160727 zCollist = rbuObjIterGetCollist(p, pIter);
160728 pIter->nCol = pIter->nTblCol;
160731 rbuCreateImposterTable(p, pIter);
160732 rbuCreateImposterTable2(p, pIter);
160733 zWrite = (pIter->eType==RBU_PK_VTAB ? "" : "rbu_imp_");
160737 p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pInsert, pz,
160747 p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pDelete, pz,
160754 if( pIter->abIndexed ){
160756 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
160764 , p->zStateDb, pIter->zDataTbl
160765 , (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
160766 , pIter->zDataTbl
160789 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
160799 rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
160804 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
160808 pIter->zDataTbl, zLimit
160828 ** table object that pIter currently points to, assuming that the
160836 RbuObjIter *pIter, /* Object iterator */
160851 for(pp=&pIter->pRbuUpdate; *pp; pp=&((*pp)->pNext)){
160855 pUp->pNext = pIter->pRbuUpdate;
160856 pIter->pRbuUpdate = pUp;
160865 for(pp=&pIter->pRbuUpdate; *pp!=pUp; pp=&((*pp)->pNext));
160870 pUp = (RbuUpdateStmt*)rbuMalloc(p, sizeof(RbuUpdateStmt)+pIter->nTblCol+1);
160874 char *zWhere = rbuObjIterGetWhere(p, pIter);
160875 char *zSet = rbuObjIterGetSetlist(p, pIter, zMask);
160879 memcpy(pUp->zMask, zMask, pIter->nTblCol);
160880 pUp->pNext = pIter->pRbuUpdate;
160881 pIter->pRbuUpdate = pUp;
160886 if( pIter->eType!=RBU_PK_VTAB ) zPrefix = "rbu_imp_";
160888 zPrefix, pIter->zTbl, zSet, zWhere
161358 RbuObjIter *pIter = &p->objiter;
161364 assert( eType!=RBU_UPDATE || pIter->zIdx==0 );
161366 if( pIter->zIdx==0 && eType==RBU_IDX_DELETE ){
161379 assert( eType!=RBU_DELETE || pIter->zIdx==0 );
161382 pWriter = pIter->pDelete;
161384 pWriter = pIter->pInsert;
161387 for(i=0; i<pIter->nCol; i++){
161392 && pIter->zIdx==0 && pIter->eType==RBU_PK_IPK && pIter->abTblPk[i]
161393 && sqlite3_column_type(pIter->pSelect, i)==SQLITE_NULL
161400 if( eType==RBU_DELETE && pIter->abTblPk[i]==0 ){
161404 pVal = sqlite3_column_value(pIter->pSelect, i);
161408 if( pIter->zIdx==0
161409 && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
161416 ** Hence column_value(pIter->nCol+1).
161418 assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid");
161419 pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
161420 p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
161430 rbuGetUpdateStmt(p, pIter, zMask, &pUpdate);
161432 for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){
161433 char c = zMask[pIter->aiSrcOrder[i]];
161434 pVal = sqlite3_column_value(pIter->pSelect, i);
161435 if( pIter->abTblPk[i] || c!='.' ){
161440 && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
161443 assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid");
161444 pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
161445 p->rc = sqlite3_bind_value(pUpdate, pIter->nCol+1, pVal);
161538 RbuObjIter *pIter = &p->objiter;
161539 while( p->rc==SQLITE_OK && pIter->zTbl ){
161541 if( pIter->bCleanup ){
161545 if( pIter->abIndexed ){
161547 "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zDataTbl
161551 rbuObjIterPrepareAll(p, pIter, 0);
161555 int rc = sqlite3_step(pIter->pSelect);
161561 p->rc = sqlite3_reset(pIter->pSelect);
161566 rbuObjIterNext(p, pIter);
161570 assert( pIter->zTbl==0 );
161740 RbuObjIter *pIter = &p->objiter;
161743 while( rc==SQLITE_OK && pIter->zTbl && (pIter->bCleanup
161744 || rbuStrCompare(pIter->zIdx, pState->zIdx)
161745 || rbuStrCompare(pIter->zTbl, pState->zTbl)
161747 rc = rbuObjIterNext(p, pIter);
161750 if( rc==SQLITE_OK && !pIter->zTbl ){
166409 Fts5PoslistReader *pIter /* Iterator object to initialize */
166460 ** sqlite3Fts5IndexQuery(p, "token", 5, 0, 0, &pIter);
166461 ** 0==sqlite3Fts5IterEof(pIter);
166462 ** sqlite3Fts5IterNext(pIter)
166464 ** i64 iRowid = sqlite3Fts5IterRowid(pIter);
166489 static int sqlite3Fts5IterPoslistBuffer(Fts5IndexIter *pIter, Fts5Buffer *pBuf);
168087 static int fts5CInstIterNext(CInstIter *pIter){
168089 pIter->iStart = -1;
168090 pIter->iEnd = -1;
168092 while( rc==SQLITE_OK && pIter->iInst<pIter->nInst ){
168094 rc = pIter->pApi->xInst(pIter->pFts, pIter->iInst, &ip, &ic, &io);
168096 if( ic==pIter->iCol ){
168097 int iEnd = io - 1 + pIter->pApi->xPhraseSize(pIter->pFts, ip);
168098 if( pIter->iStart<0 ){
168099 pIter->iStart = io;
168100 pIter->iEnd = iEnd;
168101 }else if( io<=pIter->iEnd ){
168102 if( iEnd>pIter->iEnd ) pIter->iEnd = iEnd;
168107 pIter->iInst++;
168122 CInstIter *pIter
168126 memset(pIter, 0, sizeof(CInstIter));
168127 pIter->pApi = pApi;
168128 pIter->pFts = pFts;
168129 pIter->iCol = iCol;
168130 rc = pApi->xInstCount(pFts, &pIter->nInst);
168133 rc = fts5CInstIterNext(pIter);
168797 static int sqlite3Fts5PoslistReaderNext(Fts5PoslistReader *pIter){
168798 if( sqlite3Fts5PoslistNext64(pIter->a, pIter->n, &pIter->i, &pIter->iPos) ){
168799 pIter->bEof = 1;
168801 return pIter->bEof;
168806 Fts5PoslistReader *pIter /* Iterator object to initialize */
168808 memset(pIter, 0, sizeof(*pIter));
168809 pIter->a = a;
168810 pIter->n = n;
168811 sqlite3Fts5PoslistReaderNext(pIter);
168812 return pIter->bEof;
169847 Fts5IndexIter *pIter; /* Iterator for this term */
170051 if( 0==sqlite3Fts5IterEof(p->pIter) ){
170052 i64 iRowid = sqlite3Fts5IterRowid(p->pIter);
170083 Fts5IndexIter *pIter = p->pIter;
170084 if( sqlite3Fts5IterEof(pIter)==0 && sqlite3Fts5IterRowid(pIter)==iRowid ){
170088 rc = sqlite3Fts5IterPoslist(pIter, pColset, &a, &n, &dummy);
170194 rc = sqlite3Fts5IterPoslist(pTerm->pIter, pColset, &a, &n, &dummy);
170414 if( sqlite3Fts5IterEof(p->pIter)==0 ){
170415 i64 ii = sqlite3Fts5IterRowid(p->pIter);
170420 rc = sqlite3Fts5IterNextFrom(p->pIter, iFrom);
170422 rc = sqlite3Fts5IterNext(p->pIter);
170425 if( sqlite3Fts5IterEof(p->pIter)==0 ){
170438 Fts5IndexIter *pIter = pTerm->pIter;
170442 rc = sqlite3Fts5IterNextFrom(pIter, iFrom);
170444 rc = sqlite3Fts5IterNext(pIter);
170447 pNode->bEof = (rc || sqlite3Fts5IterEof(pIter));
170454 ** Advance iterator pIter until it points to a value equal to or laster
170463 Fts5IndexIter *pIter, /* Iterator to advance */
170472 iRowid = sqlite3Fts5IterRowid(pIter);
170474 int rc = sqlite3Fts5IterNextFrom(pIter, iLast);
170475 if( rc || sqlite3Fts5IterEof(pIter) ){
170480 iRowid = sqlite3Fts5IterRowid(pIter);
170500 if( sqlite3Fts5IterEof(p->pIter)==0 ){
170501 i64 iRowid = sqlite3Fts5IterRowid(p->pIter);
170503 rc = sqlite3Fts5IterNextFrom(p->pIter, iLast);
170538 pPhrase->aTerm[0].pIter, &pPhrase->poslist
170562 Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter;
170570 rc = sqlite3Fts5IterPoslist(pIter, pColset,
170613 iLast = sqlite3Fts5IterRowid(pLeft->aTerm[0].pIter);
170631 Fts5IndexIter *pIter = pPhrase->aTerm[j].pIter;
170632 i64 iRowid = sqlite3Fts5IterRowid(pIter);
170635 if( fts5ExprAdvanceto(pIter, bDesc, &iLast, &rc, &pNode->bEof) ){
170670 if( p->pIter ){
170671 sqlite3Fts5IterClose(p->pIter);
170672 p->pIter = 0;
170679 &p->pIter
170681 assert( rc==SQLITE_OK || p->pIter==0 );
170682 if( p->pIter && 0==sqlite3Fts5IterEof(p->pIter) ){
170855 Fts5IndexIter *pIter = pNode->pNear->apPhrase[0]->aTerm[0].pIter;
170857 rc = sqlite3Fts5IterNextFrom(pIter, iFrom);
170859 rc = sqlite3Fts5IterNext(pIter);
170861 if( rc==SQLITE_OK && sqlite3Fts5IterEof(pIter)==0 ){
171103 sqlite3Fts5IterClose(pTerm->pIter);
171107 sqlite3Fts5IterClose(pSyn->pIter);
172385 Fts5HashEntry *pIter;
172386 for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
172387 if( pTerm==0 || 0==memcmp(pIter->zKey, pTerm, nTerm) ){
172388 Fts5HashEntry *pEntry = pIter;
173677 static int fts5DlidxIterNextR(Fts5Index *p, Fts5DlidxIter *pIter, int iLvl){
173678 Fts5DlidxLvl *pLvl = &pIter->aLvl[iLvl];
173680 assert( iLvl<pIter->nLvl );
173682 if( (iLvl+1) < pIter->nLvl ){
173683 fts5DlidxIterNextR(p, pIter, iLvl+1);
173688 FTS5_DLIDX_ROWID(pIter->iSegid, iLvl, pLvl[1].iLeafPgno)
173695 return pIter->aLvl[0].bEof;
173697 static int fts5DlidxIterNext(Fts5Index *p, Fts5DlidxIter *pIter){
173698 return fts5DlidxIterNextR(p, pIter, 0);
173709 ** When this function is called pIter->iLeafPgno is the page number the
173712 static int fts5DlidxIterFirst(Fts5DlidxIter *pIter){
173714 for(i=0; i<pIter->nLvl; i++){
173715 fts5DlidxLvlNext(&pIter->aLvl[i]);
173717 return pIter->aLvl[0].bEof;
173721 static int fts5DlidxIterEof(Fts5Index *p, Fts5DlidxIter *pIter){
173722 return p->rc!=SQLITE_OK || pIter->aLvl[0].bEof;
173725 static void fts5DlidxIterLast(Fts5Index *p, Fts5DlidxIter *pIter){
173729 for(i=pIter->nLvl-1; p->rc==SQLITE_OK && i>=0; i--){
173730 Fts5DlidxLvl *pLvl = &pIter->aLvl[i];
173739 FTS5_DLIDX_ROWID(pIter->iSegid, i-1, pLvl->iLeafPgno)
173797 static int fts5DlidxIterPrevR(Fts5Index *p, Fts5DlidxIter *pIter, int iLvl){
173798 Fts5DlidxLvl *pLvl = &pIter->aLvl[iLvl];
173800 assert( iLvl<pIter->nLvl );
173802 if( (iLvl+1) < pIter->nLvl ){
173803 fts5DlidxIterPrevR(p, pIter, iLvl+1);
173808 FTS5_DLIDX_ROWID(pIter->iSegid, iLvl, pLvl[1].iLeafPgno)
173818 return pIter->aLvl[0].bEof;
173820 static int fts5DlidxIterPrev(Fts5Index *p, Fts5DlidxIter *pIter){
173821 return fts5DlidxIterPrevR(p, pIter, 0);
173827 static void fts5DlidxIterFree(Fts5DlidxIter *pIter){
173828 if( pIter ){
173830 for(i=0; i<pIter->nLvl; i++){
173831 fts5DataRelease(pIter->aLvl[i].pData);
173833 sqlite3_free(pIter);
173843 Fts5DlidxIter *pIter = 0;
173851 pNew = (Fts5DlidxIter*)sqlite3_realloc(pIter, nByte);
173857 pIter = pNew;
173863 pIter->nLvl = i+1;
173868 pIter->iSegid = iSegid;
173870 fts5DlidxIterFirst(pIter);
173872 fts5DlidxIterLast(p, pIter);
173877 fts5DlidxIterFree(pIter);
173878 pIter = 0;
173881 return pIter;
173884 static i64 fts5DlidxIterRowid(Fts5DlidxIter *pIter){
173885 return pIter->aLvl[0].iRowid;
173887 static int fts5DlidxIterPgno(Fts5DlidxIter *pIter){
173888 return pIter->aLvl[0].iLeafPgno;
173896 Fts5SegIter *pIter /* Iterator to advance to next page */
173899 Fts5StructureSegment *pSeg = pIter->pSeg;
173900 fts5DataRelease(pIter->pLeaf);
173901 pIter->iLeafPgno++;
173902 if( pIter->pNextLeaf ){
173903 pIter->pLeaf = pIter->pNextLeaf;
173904 pIter->pNextLeaf = 0;
173905 }else if( pIter->iLeafPgno<=pSeg->pgnoLast ){
173906 pIter->pLeaf = fts5DataRead(p,
173907 FTS5_SEGMENT_ROWID(pSeg->iSegid, pIter->iLeafPgno)
173910 pIter->pLeaf = 0;
173912 pLeaf = pIter->pLeaf;
173915 pIter->iPgidxOff = pLeaf->szLeaf;
173917 pIter->iEndofDoclist = pLeaf->nn+1;
173919 pIter->iPgidxOff += fts5GetVarint32(&pLeaf->p[pIter->iPgidxOff],
173920 pIter->iEndofDoclist
173953 static void fts5SegIterLoadNPos(Fts5Index *p, Fts5SegIter *pIter){
173955 int iOff = pIter->iLeafOffset; /* Offset to read at */
173957 ASSERT_SZLEAF_OK(pIter->pLeaf);
173958 fts5FastGetVarint32(pIter->pLeaf->p, iOff, nSz);
173959 pIter->bDel = (nSz & 0x0001);
173960 pIter->nPos = nSz>>1;
173961 pIter->iLeafOffset = iOff;
173965 static void fts5SegIterLoadRowid(Fts5Index *p, Fts5SegIter *pIter){
173966 u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
173967 int iOff = pIter->iLeafOffset;
173969 ASSERT_SZLEAF_OK(pIter->pLeaf);
173970 if( iOff>=pIter->pLeaf->szLeaf ){
173971 fts5SegIterNextPage(p, pIter);
173972 if( pIter->pLeaf==0 ){
173977 a = pIter->pLeaf->p;
173979 iOff += sqlite3Fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
173980 pIter->iLeafOffset = iOff;
173998 static void fts5SegIterLoadTerm(Fts5Index *p, Fts5SegIter *pIter, int nKeep){
173999 u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
174000 int iOff = pIter->iLeafOffset; /* Offset to read at */
174004 pIter->term.n = nKeep;
174005 fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
174007 pIter->iTermLeafOffset = iOff;
174008 pIter->iTermLeafPgno = pIter->iLeafPgno;
174009 pIter->iLeafOffset = iOff;
174011 if( pIter->iPgidxOff>=pIter->pLeaf->nn ){
174012 pIter->iEndofDoclist = pIter->pLeaf->nn+1;
174015 pIter->iPgidxOff += fts5GetVarint32(&a[pIter->iPgidxOff], nExtra);
174016 pIter->iEndofDoclist += nExtra;
174019 fts5SegIterLoadRowid(p, pIter);
174023 ** Initialize the iterator object pIter to iterate through the entries in
174033 Fts5SegIter *pIter /* Object to populate */
174039 ** The caller will see the (pIter->pLeaf==0) and assume the iterator is
174041 assert( pIter->pLeaf==0 );
174046 memset(pIter, 0, sizeof(*pIter));
174047 pIter->pSeg = pSeg;
174048 pIter->iLeafPgno = pSeg->pgnoFirst-1;
174049 fts5SegIterNextPage(p, pIter);
174053 pIter->iLeafOffset = 4;
174054 assert_nc( pIter->pLeaf->nn>4 );
174055 assert( fts5LeafFirstTermOff(pIter->pLeaf)==4 );
174056 pIter->iPgidxOff = pIter->pLeaf->szLeaf+1;
174057 fts5SegIterLoadTerm(p, pIter, 0);
174058 fts5SegIterLoadNPos(p, pIter);
174077 static void fts5SegIterReverseInitPage(Fts5Index *p, Fts5SegIter *pIter){
174078 int n = pIter->pLeaf->szLeaf;
174079 int i = pIter->iLeafOffset;
174080 u8 *a = pIter->pLeaf->p;
174083 if( n>pIter->iEndofDoclist ){
174084 n = pIter->iEndofDoclist;
174087 ASSERT_SZLEAF_OK(pIter->pLeaf);
174097 pIter->iRowid += iDelta;
174099 if( iRowidOffset>=pIter->nRowidOffset ){
174100 int nNew = pIter->nRowidOffset + 8;
174101 int *aNew = (int*)sqlite3_realloc(pIter->aRowidOffset, nNew*sizeof(int));
174106 pIter->aRowidOffset = aNew;
174107 pIter->nRowidOffset = nNew;
174110 pIter->aRowidOffset[iRowidOffset++] = pIter->iLeafOffset;
174111 pIter->iLeafOffset = i;
174113 pIter->iRowidOffset = iRowidOffset;
174114 fts5SegIterLoadNPos(p, pIter);
174120 static void fts5SegIterReverseNewPage(Fts5Index *p, Fts5SegIter *pIter){
174121 assert( pIter->flags & FTS5_SEGITER_REVERSE );
174122 assert( pIter->flags & FTS5_SEGITER_ONETERM );
174124 fts5DataRelease(pIter->pLeaf);
174125 pIter->pLeaf = 0;
174126 while( p->rc==SQLITE_OK && pIter->iLeafPgno>pIter->iTermLeafPgno ){
174128 pIter->iLeafPgno--;
174130 pIter->pSeg->iSegid, pIter->iLeafPgno
174135 ** In this case leaf pIter->pLeaf==0, this iterator is at EOF. */
174136 if( pIter->iLeafPgno==pIter->iTermLeafPgno
174137 && pIter->iTermLeafOffset<pNew->szLeaf
174139 pIter->pLeaf = pNew;
174140 pIter->iLeafOffset = pIter->iTermLeafOffset;
174145 pIter->pLeaf = pNew;
174146 pIter->iLeafOffset = iRowidOff;
174150 if( pIter->pLeaf ){
174151 u8 *a = &pIter->pLeaf->p[pIter->iLeafOffset];
174152 pIter->iLeafOffset += fts5GetVarint(a, (u64*)&pIter->iRowid);
174160 if( pIter->pLeaf ){
174161 pIter->iEndofDoclist = pIter->pLeaf->nn+1;
174162 fts5SegIterReverseInitPage(p, pIter);
174171 static int fts5MultiIterIsEmpty(Fts5Index *p, Fts5IndexIter *pIter){
174172 Fts5SegIter *pSeg = &pIter->aSeg[pIter->aFirst[1].iFirst];
174177 ** Advance iterator pIter to the next entry.
174185 Fts5SegIter *pIter, /* Iterator to advance */
174190 if( pIter->flags & FTS5_SEGITER_REVERSE ){
174191 assert( pIter->pNextLeaf==0 );
174192 if( pIter->iRowidOffset>0 ){
174193 u8 *a = pIter->pLeaf->p;
174199 pIter->iRowidOffset--;
174200 pIter->iLeafOffset = iOff = pIter->aRowidOffset[pIter->iRowidOffset];
174204 pIter->iRowid -= iDelta;
174205 fts5SegIterLoadNPos(p, pIter);
174207 fts5SegIterReverseNewPage(p, pIter);
174210 Fts5Data *pLeaf = pIter->pLeaf;
174220 iOff = pIter->iLeafOffset + pIter->nPos;
174224 assert_nc( iOff<=pIter->iEndofDoclist );
174225 if( iOff>=pIter->iEndofDoclist ){
174233 pIter->iRowid += iDelta;
174236 pIter->iLeafOffset = iOff;
174238 }else if( pIter->pSeg==0 ){
174242 if( 0==(pIter->flags & FTS5_SEGITER_ONETERM) ){
174247 fts5DataRelease(pIter->pLeaf);
174248 pIter->pLeaf = 0;
174250 pIter->pLeaf->p = (u8*)pList;
174251 pIter->pLeaf->nn = nList;
174252 pIter->pLeaf->szLeaf = nList;
174253 pIter->iEndofDoclist = nList+1;
174254 sqlite3Fts5BufferSet(&p->rc, &pIter->term, strlen(zTerm), (u8*)zTerm);
174255 pIter->iLeafOffset = fts5GetVarint(pList, (u64*)&pIter->iRowid);
174262 fts5SegIterNextPage(p, pIter);
174263 pLeaf = pIter->pLeaf;
174267 iOff += sqlite3Fts5GetVarint(&pLeaf->p[iOff], (u64*)&pIter->iRowid);
174268 pIter->iLeafOffset = iOff;
174271 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
174272 &pLeaf->p[pLeaf->szLeaf], pIter->iEndofDoclist
174278 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
174281 pIter->iLeafOffset = iOff;
174282 pIter->iEndofDoclist = iOff;
174293 if( pIter->pLeaf ){
174295 if( pIter->flags & FTS5_SEGITER_ONETERM ){
174296 fts5DataRelease(pIter->pLeaf);
174297 pIter->pLeaf = 0;
174299 fts5SegIterLoadTerm(p, pIter, nKeep);
174300 fts5SegIterLoadNPos(p, pIter);
174304 fts5SegIterLoadNPos(p, pIter);
174314 ** Iterator pIter currently points to the first rowid in a doclist. This
174318 pIter){
174319 Fts5DlidxIter *pDlidx = pIter->pDlidx;
174324 int iSegid = pIter->pSeg->iSegid;
174328 Fts5Data *pLeaf = pIter->pLeaf; /* Current leaf data */
174333 pIter->iLeafOffset -= sqlite3Fts5GetVarintLen(pIter->nPos*2+pIter->bDel);
174338 if( pIter->iEndofDoclist>=pLeaf->szLeaf ){
174340 Fts5StructureSegment *pSeg = pIter->pSeg;
174344 for(pgno=pIter->iLeafPgno+1; !p->rc && pgno<=pSeg->pgnoLast; pgno++){
174364 ** pIter->iLeafOffset is already set to point to the position-list size
174373 fts5DataRelease(pIter->pLeaf);
174374 pIter->pLeaf = pLast;
174375 pIter->iLeafPgno = pgnoLast;
174377 iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
174378 pIter->iLeafOffset = iOff;
174381 pIter->iEndofDoclist = pLast->nn+1;
174383 pIter->iEndofDoclist = fts5LeafFirstTermOff(pLast);
174388 fts5SegIterReverseInitPage(p, pIter);
174392 ** Iterator pIter currently points to the first rowid of a doclist.
174395 ** doclist-index from disk and initialize an iterator at (pIter->pDlidx).
174397 static void fts5SegIterLoadDlidx(Fts5Index *p, Fts5SegIter *pIter){
174398 int iSeg = pIter->pSeg->iSegid;
174399 int bRev = (pIter->flags & FTS5_SEGITER_REVERSE);
174400 Fts5Data *pLeaf = pIter->pLeaf; /* Current leaf data */
174402 assert( pIter->flags & FTS5_SEGITER_ONETERM );
174403 assert( pIter->pDlidx==0 );
174408 if( pIter->iTermLeafPgno==pIter->iLeafPgno
174409 && pIter->iEndofDoclist<pLeaf->szLeaf
174414 pIter->pDlidx = fts5DlidxIterInit(p, bRev, iSeg, pIter->iTermLeafPgno);
174439 Fts5SegIter *pIter, /* Iterator to seek */
174443 const u8 *a = pIter->pLeaf->p;
174444 int szLeaf = pIter->pLeaf->szLeaf;
174445 int n = pIter->pLeaf->nn;
174504 fts5DataRelease(pIter->pLeaf);
174505 pIter->pLeaf = 0;
174509 fts5SegIterNextPage(p, pIter);
174510 if( pIter->pLeaf==0 ) return;
174511 a = pIter->pLeaf->p;
174512 if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
174513 fts5GetVarint32(&pIter->pLeaf->p[pIter->pLeaf->szLeaf], iOff);
174514 if( iOff<4 || iOff>=pIter->pLeaf->szLeaf ){
174527 pIter->iLeafOffset = iOff + nNew;
174528 pIter->iTermLeafOffset = pIter->iLeafOffset;
174529 pIter->iTermLeafPgno = pIter->iLeafPgno;
174531 fts5BufferSet(&p->rc, &pIter->term, nKeep, pTerm);
174532 fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
174535 pIter->iEndofDoclist = pIter->pLeaf->nn+1;
174539 pIter->iEndofDoclist = iTermOff + nExtra;
174541 pIter->iPgidxOff = iPgidx;
174543 fts5SegIterLoadRowid(p, pIter);
174544 fts5SegIterLoadNPos(p, pIter);
174548 ** Initialize the object pIter to point to term pTerm/nTerm within segment
174560 Fts5SegIter *pIter /* Object to populate */
174571 memset(pIter, 0, sizeof(*pIter));
174572 pIter->pSeg = pSeg;
174599 pIter->iLeafPgno = iPg - 1;
174600 fts5SegIterNextPage(p, pIter);
174602 if( pIter->pLeaf ){
174603 fts5LeafSeek(p, bGe, pIter, pTerm, nTerm);
174607 pIter->flags |= FTS5_SEGITER_ONETERM;
174608 if( pIter->pLeaf ){
174610 pIter->flags |= FTS5_SEGITER_REVERSE;
174613 fts5SegIterLoadDlidx(p, pIter);
174616 fts5SegIterReverse(p, pIter);
174630 || pIter->pLeaf==0 /* 2 */
174631 || fts5BufferCompareBlob(&pIter->term, pTerm, nTerm)==0 /* 3 */
174632 || (bGe && fts5BufferCompareBlob(&pIter->term, pTerm, nTerm)>0) /* 4 */
174637 ** Initialize the object pIter to point to term pTerm/nTerm within the
174648 Fts5SegIter *pIter /* Object to populate */
174663 pIter->flags |= FTS5_SEGITER_ONETERM;
174671 sqlite3Fts5BufferSet(&p->rc, &pIter->term, n, z);
174676 pIter->pLeaf = pLeaf;
174677 pIter->iLeafOffset = fts5GetVarint(pLeaf->p, (u64*)&pIter->iRowid);
174678 pIter->iEndofDoclist = pLeaf->nn+1;
174681 pIter->flags |= FTS5_SEGITER_REVERSE;
174682 fts5SegIterReverseInitPage(p, pIter);
174684 fts5SegIterLoadNPos(p, pIter);
174692 static void fts5SegIterClear(Fts5SegIter *pIter){
174693 fts5BufferFree(&pIter->term);
174694 fts5DataRelease(pIter->pLeaf);
174695 fts5DataRelease(pIter->pNextLeaf);
174696 fts5DlidxIterFree(pIter->pDlidx);
174697 sqlite3_free(pIter->aRowidOffset);
174698 memset(pIter, 0, sizeof(Fts5SegIter));
174710 Fts5IndexIter *pIter,
174715 int i1 = p1 - pIter->aSeg;
174716 int i2 = p2 - pIter->aSeg;
174731 res = ((p1->iRowid > p2->iRowid)==pIter->bRev) ? -1 : 1;
174748 ** statement used to verify that the contents of the pIter->aFirst[] array
174751 static void fts5AssertMultiIterSetup(Fts5Index *p, Fts5IndexIter *pIter){
174753 Fts5SegIter *pFirst = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
174756 assert( (pFirst->pLeaf==0)==pIter->bEof );
174758 /* Check that pIter->iSwitchRowid is set correctly. */
174759 for(i=0; i<pIter->nSeg; i++){
174760 Fts5SegIter *p1 = &pIter->aSeg[i];
174764 || p1->iRowid==pIter->iSwitchRowid
174765 || (p1->iRowid<pIter->iSwitchRowid)==pIter->bRev
174769 for(i=0; i<pIter->nSeg; i+=2){
174770 Fts5SegIter *p1 = &pIter->aSeg[i];
174771 Fts5SegIter *p2 = &pIter->aSeg[i+1];
174772 Fts5CResult *pRes = &pIter->aFirst[(pIter->nSeg + i) / 2];
174773 fts5AssertComparisonResult(pIter, p1, p2, pRes);
174776 for(i=1; i<(pIter->nSeg / 2); i+=2){
174777 Fts5SegIter *p1 = &pIter->aSeg[ pIter->aFirst[i*2].iFirst ];
174778 Fts5SegIter *p2 = &pIter->aSeg[ pIter->aFirst[i*2+1].iFirst ];
174779 Fts5CResult *pRes = &pIter->aFirst[i];
174780 fts5AssertComparisonResult(pIter, p1, p2, pRes);
174789 ** Do the comparison necessary to populate pIter->aFirst[iOut].
174792 ** in the pIter->aSeg[] array that is (a) not at EOF, and (b) pointing
174796 static int fts5MultiIterDoCompare(Fts5IndexIter *pIter, int iOut){
174802 Fts5CResult *pRes = &pIter->aFirst[iOut];
174804 assert( iOut<pIter->nSeg && iOut>0 );
174805 assert( pIter->bRev==0 || pIter->bRev==1 );
174807 if( iOut>=(pIter->nSeg/2) ){
174808 i1 = (iOut - pIter->nSeg/2) * 2;
174811 i1 = pIter->aFirst[iOut*2].iFirst;
174812 i2 = pIter->aFirst[iOut*2+1].iFirst;
174814 p1 = &pIter->aSeg[i1];
174815 p2 = &pIter->aSeg[i2];
174832 res = ((p1->iRowid > p2->iRowid)==pIter->bRev) ? -1 : +1;
174852 Fts5SegIter *pIter, /* Iterator to advance */
174855 assert( iLeafPgno>pIter->iLeafPgno );
174857 if( iLeafPgno>pIter->pSeg->pgnoLast ){
174860 fts5DataRelease(pIter->pNextLeaf);
174861 pIter->pNextLeaf = 0;
174862 pIter->iLeafPgno = iLeafPgno-1;
174863 fts5SegIterNextPage(p, pIter);
174864 assert( p->rc!=SQLITE_OK || pIter->iLeafPgno==iLeafPgno );
174868 u8 *a = pIter->pLeaf->p;
174869 int n = pIter->pLeaf->szLeaf;
174871 iOff = fts5LeafFirstRowidOff(pIter->pLeaf);
174875 iOff += fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
174876 pIter->iLeafOffset = iOff;
174877 fts5SegIterLoadNPos(p, pIter);
174890 Fts5SegIter *pIter, /* Iterator to advance */
174893 int bRev = (pIter->flags & FTS5_SEGITER_REVERSE);
174894 Fts5DlidxIter *pDlidx = pIter->pDlidx;
174895 int iLeafPgno = pIter->iLeafPgno;
174898 assert( pIter->flags & FTS5_SEGITER_ONETERM );
174899 assert( pIter->pDlidx );
174900 assert( pIter->pLeaf );
174907 assert_nc( iLeafPgno>=pIter->iLeafPgno || p->rc );
174908 if( iLeafPgno>pIter->iLeafPgno ){
174909 fts5SegIterGotoPage(p, pIter, iLeafPgno);
174913 assert( pIter->pNextLeaf==0 );
174914 assert( iMatch<pIter->iRowid );
174920 assert( fts5DlidxIterEof(p, pDlidx) || iLeafPgno<=pIter->iLeafPgno );
174922 if( iLeafPgno<pIter->iLeafPgno ){
174923 pIter->iLeafPgno = iLeafPgno+1;
174924 fts5SegIterReverseNewPage(p, pIter);
174930 if( bMove ) fts5SegIterNext(p, pIter, 0);
174931 if( pIter->pLeaf==0 ) break;
174932 if( bRev==0 && pIter->iRowid>=iMatch ) break;
174933 if( bRev!=0 && pIter->iRowid<=iMatch ) break;
174942 static void fts5MultiIterFree(Fts5Index *p, Fts5IndexIter *pIter){
174943 if( pIter ){
174945 for(i=0; i<pIter->nSeg; i++){
174946 fts5SegIterClear(&pIter->aSeg[i]);
174948 fts5StructureRelease(pIter->pStruct);
174949 fts5BufferFree(&pIter->poslist);
174950 sqlite3_free(pIter);
174956 Fts5IndexIter *pIter, /* Iterator to update aFirst[] array for */
174961 for(i=(pIter->nSeg+iChanged)/2; i>=iMinset && p->rc==SQLITE_OK; i=i/2){
174963 if( (iEq = fts5MultiIterDoCompare(pIter, i)) ){
174964 fts5SegIterNext(p, &pIter->aSeg[iEq], 0);
174965 i = pIter->nSeg + iEq;
174971 ** Sub-iterator iChanged of iterator pIter has just been advanced. It still
174973 ** attempts to update the contents of the pIter->aFirst[] accordingly.
174982 Fts5IndexIter *pIter, /* Iterator to update aFirst[] array for */
174985 Fts5SegIter *pNew = &pIter->aSeg[iChanged];
174987 if( pNew->iRowid==pIter->iSwitchRowid
174988 || (pNew->iRowid<pIter->iSwitchRowid)==pIter->bRev
174991 Fts5SegIter *pOther = &pIter->aSeg[iChanged ^ 0x0001];
174992 pIter->iSwitchRowid = pIter->bRev ? SMALLEST_INT64 : LARGEST_INT64;
174993 for(i=(pIter->nSeg+iChanged)/2; 1; i=i/2){
174994 Fts5CResult *pRes = &pIter->aFirst[i];
175002 }else if( (pOther->iRowid>pNew->iRowid)==pIter->bRev ){
175003 pIter->iSwitchRowid = pOther->iRowid;
175005 }else if( (pOther->iRowid>pIter->iSwitchRowid)==pIter->bRev ){
175006 pIter->iSwitchRowid = pOther->iRowid;
175009 pRes->iFirst = (pNew - pIter->aSeg);
175012 pOther = &pIter->aSeg[ pIter->aFirst[i ^ 0x0001].iFirst ];
175020 ** Set the pIter->bEof variable based on the state of the sub-iterators.
175022 static void fts5MultiIterSetEof(Fts5IndexIter *pIter){
175023 Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
175024 pIter->bEof = pSeg->pLeaf==0;
175025 pIter->iSwitchRowid = pSeg->iRowid;
175037 Fts5IndexIter *pIter,
175044 int iFirst = pIter->aFirst[1].iFirst;
175046 Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
175055 || fts5MultiIterAdvanceRowid(p, pIter, iFirst)
175057 fts5MultiIterAdvanced(p, pIter, iFirst, 1);
175058 fts5MultiIterSetEof(pIter);
175060 fts5AssertMultiIterSetup(p, pIter);
175063 }while( pIter->bSkipEmpty && fts5MultiIterIsEmpty(p, pIter) );
175140 Fts5SegIter *pIter = &pNew->aSeg[iIter++];
175141 fts5SegIterHashInit(p, pTerm, nTerm, flags, pIter);
175146 Fts5SegIter *pIter = &pNew->aSeg[iIter++];
175148 fts5SegIterInit(p, pSeg, pIter);
175150 fts5SegIterSeekInit(p, &buf, pTerm, nTerm, flags, pSeg, pIter);
175200 Fts5SegIter *pIter = &pNew->aSeg[1];
175203 pIter->flags = FTS5_SEGITER_ONETERM;
175205 pIter->pLeaf = pData;
175206 pIter->iLeafOffset = fts5GetVarint(pData->p, (u64*)&pIter->iRowid);
175207 pIter->iEndofDoclist = pData->nn;
175211 pIter->flags |= FTS5_SEGITER_REVERSE;
175212 fts5SegIterReverseInitPage(p, pIter);
175214 fts5SegIterLoadNPos(p, pIter);
175231 static int fts5MultiIterEof(Fts5Index *p, Fts5IndexIter *pIter){
175233 || (pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf==0)==pIter->bEof
175235 return (p->rc || pIter->bEof);
175243 static i64 fts5MultiIterRowid(Fts5IndexIter *pIter){
175244 assert( pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf );
175245 return pIter->aSeg[ pIter->aFirst[1].iFirst ].iRowid;
175253 Fts5IndexIter *pIter,
175258 fts5MultiIterNext(p, pIter, 1, iMatch);
175259 if( fts5MultiIterEof(p, pIter) ) break;
175260 iRowid = fts5MultiIterRowid(pIter);
175261 if( pIter->bRev==0 && iRowid>=iMatch ) break;
175262 if( pIter->bRev!=0 && iRowid<=iMatch ) break;
175270 static const u8 *fts5MultiIterTerm(Fts5IndexIter *pIter, int *pn){
175271 Fts5SegIter *p = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
175845 ** Iterator pIter was used to iterate through the input segments of on an
175849 static void fts5TrimSegments(Fts5Index *p, Fts5IndexIter *pIter){
175853 for(i=0; i<pIter->nSeg; i++){
175854 Fts5SegIter *pSeg = &pIter->aSeg[i];
175927 Fts5IndexIter *pIter = 0; /* Iterator to read input data */
175978 for(fts5MultiIterNew(p, pStruct, 0, 0, 0, 0, iLvl, nInput, &pIter);
175979 fts5MultiIterEof(p, pIter)==0;
175980 fts5MultiIterNext(p, pIter, 0, 0)
175982 Fts5SegIter *pSegIter = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
175990 pTerm = fts5MultiIterTerm(pIter, &nTerm);
176004 fts5WriteAppendRowid(p, &writer, fts5MultiIterRowid(pIter), nPos);
176014 if( fts5MultiIterEof(p, pIter) ){
176036 fts5TrimSegments(p, pIter);
176040 fts5MultiIterFree(p, pIter);
176492 ** Iterator pIter currently points to a valid entry (not EOF). This
176628 static void fts5DoclistIterNext(Fts5DoclistIter *pIter){
176629 u8 *p = pIter->aPoslist + pIter->nSize + pIter->nPoslist;
176631 assert( pIter->aPoslist );
176632 if( p>=pIter->aEof ){
176633 pIter->aPoslist = 0;
176638 pIter->iRowid += iDelta;
176643 pIter->nSize = fts5GetVarint32(p, nPos);
176644 pIter->nPoslist = (nPos>>1);
176646 pIter->nPoslist = ((int)(p[0])) >> 1;
176647 pIter->nSize = 1;
176650 pIter->aPoslist = p;
176656 Fts5DoclistIter *pIter
176658 memset(pIter, 0, sizeof(*pIter));
176659 pIter->aPoslist = pBuf->p;
176660 pIter->aEof = &pBuf->p[pBuf->n];
176661 fts5DoclistIterNext(pIter);
177123 static int sqlite3Fts5IterEof(Fts5IndexIter *pIter){
177124 assert( pIter->pIndex->rc==SQLITE_OK );
177125 return pIter->bEof;
177131 static int sqlite3Fts5IterNext(Fts5IndexIter *pIter){
177132 assert( pIter->pIndex->rc==SQLITE_OK );
177133 fts5MultiIterNext(pIter->pIndex, pIter, 0, 0);
177134 return fts5IndexReturn(pIter->pIndex);
177140 static int sqlite3Fts5IterNextScan(Fts5IndexIter *pIter){
177141 Fts5Index *p = pIter->pIndex;
177143 assert( pIter->pIndex->rc==SQLITE_OK );
177145 fts5MultiIterNext(p, pIter, 0, 0);
177147 Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
177151 pIter->bEof = 1;
177155 return fts5IndexReturn(pIter->pIndex);
177163 static int sqlite3Fts5IterNextFrom(Fts5IndexIter *pIter, i64 iMatch){
177164 fts5MultiIterNextFrom(pIter->pIndex, pIter, iMatch);
177165 return fts5IndexReturn(pIter->pIndex);
177171 static i64 sqlite3Fts5IterRowid(Fts5IndexIter *pIter){
177172 return fts5MultiIterRowid(pIter);
177178 static const char *sqlite3Fts5IterTerm(Fts5IndexIter *pIter, int *pn){
177180 const char *z = (const char*)fts5MultiIterTerm(pIter, &n);
177215 Fts5IndexIter *pIter,
177221 Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
177222 assert( pIter->pIndex->rc==SQLITE_OK );
177226 if( pColset==0 || pIter->bFiltered ){
177233 fts5BufferZero(&pIter->poslist);
177234 fts5IndexExtractColset(pColset, pPos, pSeg->nPos, &pIter->poslist);
177235 *pp = pIter->poslist.p;
177236 *pn = pIter->poslist.n;
177239 fts5BufferZero(&pIter->poslist);
177240 fts5SegiterPoslist(pIter->pIndex, pSeg, pColset, &pIter->poslist);
177241 *pp = pIter->poslist.p;
177242 *pn = pIter->poslist.n;
177244 return fts5IndexReturn(pIter->pIndex);
177252 static int sqlite3Fts5IterPoslistBuffer(Fts5IndexIter *pIter, Fts5Buffer *pBuf){
177253 Fts5Index *p = pIter->pIndex;
177254 Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
177264 static void sqlite3Fts5IterClose(Fts5IndexIter *pIter){
177265 if( pIter ){
177266 Fts5Index *pIndex = pIter->pIndex;
177267 fts5MultiIterFree(pIter->pIndex, pIter);
177758 Fts5IndexIter *pIter; /* Used to iterate through entire index */
177792 for(fts5MultiIterNew(p, pStruct, 0, 0, 0, 0, -1, 0, &pIter);
177793 fts5MultiIterEof(p, pIter)==0;
177794 fts5MultiIterNext(p, pIter, 0, 0)
177799 i64 iRowid = fts5MultiIterRowid(pIter);
177800 char *z = (char*)fts5MultiIterTerm(pIter, &n);
177806 fts5SegiterPoslist(p, &pIter->aSeg[pIter->aFirst[1].iFirst] , 0, &poslist);
177815 fts5MultiIterFree(p, pIter);
180079 Fts5PhraseIter *pIter,
180082 if( pIter->a>=pIter->b ){
180087 pIter->a += fts5GetVarint32(pIter->a, iVal);
180089 pIter->a += fts5GetVarint32(pIter->a, iVal);
180092 pIter->a += fts5GetVarint32(pIter->a, iVal);
180101 Fts5PhraseIter *pIter,
180105 int n = fts5CsrPoslist(pCsr, iPhrase, &pIter->a);
180106 pIter->b = &pIter->a[n];
180109 fts5ApiPhraseNext(pCtx, pIter, piCol, piOff);
183813 Fts5IndexIter *pIter; /* Term/rowid iterator object */
184054 sqlite3Fts5IterClose(pCsr->pIter);
184055 pCsr->pIter = 0;
184089 if( sqlite3Fts5IterEof(pCsr->pIter) ){
184095 zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
184109 rc = sqlite3Fts5IterPoslist(pCsr->pIter, 0, &pPos, &nPos, &dummy);
184127 rc = sqlite3Fts5IterNextScan(pCsr->pIter);
184130 zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
184132 if( sqlite3Fts5IterEof(pCsr->pIter) ) break;
184162 rc = sqlite3Fts5IndexQuery(pCsr->pIndex, 0, 0, flags, 0, &pCsr->pIter);