• Home
  • Raw
  • Download

Lines Matching refs:pIter

11558 SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
11593 sqlite3_changeset_iter *pIter, /* Iterator object */
11627 sqlite3_changeset_iter *pIter, /* Iterator object */
11658 sqlite3_changeset_iter *pIter, /* Changeset iterator */
11692 sqlite3_changeset_iter *pIter, /* Changeset iterator */
11720 sqlite3_changeset_iter *pIter, /* Changeset iterator */
11737 sqlite3_changeset_iter *pIter, /* Changeset iterator */
11772 SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
65260 WalIterator *pIter = 0; /* Wal iterator context */
65305 rc = walIteratorInit(pWal, pInfo->nBackfill, &pIter);
65306 assert( rc==SQLITE_OK || pIter==0 );
65309 if( pIter
65342 while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
65427 walIteratorFree(pIter);
68717 BtLock *pIter;
68744 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
68754 assert( pIter->eLock==READ_LOCK || pIter->eLock==WRITE_LOCK );
68755 assert( eLock==READ_LOCK || pIter->pBtree==p || pIter->eLock==READ_LOCK);
68756 if( pIter->pBtree!=p && pIter->iTable==iTab && pIter->eLock!=eLock ){
68757 sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
68790 BtLock *pIter;
68808 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
68809 if( pIter->iTable==iTable && pIter->pBtree==p ){
68810 pLock = pIter;
69625 u8 *pIter; /* For scanning through pCell */
69633 pIter = pCell;
69641 nPayload = *pIter;
69643 u8 *pEnd = &pIter[8];
69646 nPayload = (nPayload<<7) | (*++pIter & 0x7f);
69647 }while( (*pIter)>=0x80 && pIter<pEnd );
69649 pIter++;
69658 iKey = *pIter;
69661 iKey = ((iKey&0x7f)<<7) | ((x = *++pIter) & 0x7f);
69663 iKey = (iKey<<7) | ((x =*++pIter) & 0x7f);
69665 iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
69667 iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
69669 iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
69671 iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
69673 iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
69675 iKey = (iKey<<8) | (*++pIter);
69684 pIter++;
69688 pInfo->pPayload = pIter;
69695 pInfo->nSize = nPayload + (u16)(pIter - pCell);
69707 u8 *pIter; /* For scanning through pCell */
69713 pIter = pCell + pPage->childPtrSize;
69714 nPayload = *pIter;
69716 u8 *pEnd = &pIter[8];
69719 nPayload = (nPayload<<7) | (*++pIter & 0x7f);
69720 }while( *(pIter)>=0x80 && pIter<pEnd );
69722 pIter++;
69725 pInfo->pPayload = pIter;
69732 pInfo->nSize = nPayload + (u16)(pIter - pCell);
69761 u8 *pIter = pCell + pPage->childPtrSize; /* For looping over bytes of pCell */
69774 nSize = *pIter;
69776 pEnd = &pIter[8];
69779 nSize = (nSize<<7) | (*++pIter & 0x7f);
69780 }while( *(pIter)>=0x80 && pIter<pEnd );
69782 pIter++;
69786 nSize += (u32)(pIter - pCell);
69796 nSize += 4 + (u16)(pIter - pCell);
69802 u8 *pIter = pCell + 4; /* For looping over bytes of pCell */
69817 pEnd = pIter + 9;
69818 while( (*pIter++)&0x80 && pIter<pEnd );
69819 assert( debuginfo.nSize==(u16)(pIter - pCell) || CORRUPT_DB );
69820 return (u16)(pIter - pCell);
69823 u8 *pIter = pCell; /* For looping over bytes of pCell */
69836 nSize = *pIter;
69838 pEnd = &pIter[8];
69841 nSize = (nSize<<7) | (*++pIter & 0x7f);
69842 }while( *(pIter)>=0x80 && pIter<pEnd );
69844 pIter++;
69848 if( (*pIter++)&0x80
69849 && (*pIter++)&0x80
69850 && (*pIter++)&0x80
69851 && (*pIter++)&0x80
69852 && (*pIter++)&0x80
69853 && (*pIter++)&0x80
69854 && (*pIter++)&0x80
69855 && (*pIter++)&0x80 ){ pIter++; }
69859 nSize += (u32)(pIter - pCell);
69869 nSize += 4 + (u16)(pIter - pCell);
71955 BtLock *pIter;
71956 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
71957 if( pIter->pBtree!=p ){
71958 pBlock = pIter->pBtree->db;
102893 FileChunk *pIter;
102895 for(pIter=pFirst; pIter; pIter=pNext){
102896 pNext = pIter->pNext;
102897 sqlite3_free(pIter);
102914 FileChunk *pIter;
102915 for(pIter=copy.pFirst; pIter; pIter=pIter->pNext){
102919 rc = sqlite3OsWrite(pReal, (u8*)pIter->zChunk, nChunk, iOff);
103023 FileChunk *pIter = 0;
103029 for(pIter=p->pFirst; ALWAYS(pIter) && iOff<size; pIter=pIter->pNext){
103032 if( ALWAYS(pIter) ){
103033 memjrnlFreeChunks(pIter->pNext);
103034 pIter->pNext = 0;
103038 p->endpoint.pChunk = pIter;
129936 static Index *indexIteratorFirst(IndexIterator *pIter, int *pIx){
129937 assert( pIter->i==0 );
129938 if( pIter->eType ){
129939 *pIx = pIter->u.ax.aIdx[0].ix;
129940 return pIter->u.ax.aIdx[0].p;
129943 return pIter->u.lx.pIdx;
129948 static Index *indexIteratorNext(IndexIterator *pIter, int *pIx){
129949 if( pIter->eType ){
129950 int i = ++pIter->i;
129951 if( i>=pIter->u.ax.nIdx ){
129955 *pIx = pIter->u.ax.aIdx[i].ix;
129956 return pIter->u.ax.aIdx[i].p;
129959 pIter->u.lx.pIdx = pIter->u.lx.pIdx->pNext;
129960 return pIter->u.lx.pIdx;
184005 char *pIter; /* Used to iterate through aAll */
184009 pIter = pDL->pNextDocid;
184010 assert( pDL->aAll!=0 || pIter==0 );
184012 pIter = pDL->aAll;
184015 if( pIter==0 || pIter>=(pEnd = pDL->aAll + pDL->nAll) ){
184020 pIter += sqlite3Fts3GetVarint(pIter, &iDelta);
184026 pDL->pList = pIter;
184027 fts3PoslistCopy(0, &pIter);
184028 pDL->nList = (int)(pIter - pDL->pList);
184036 while( pIter<pEnd && *pIter==0 ) pIter++;
184038 pDL->pNextDocid = pIter;
184039 assert( pIter>=&pDL->aAll[pDL->nAll] || *pIter );
185375 char *pIter;
185388 pIter = pPhrase->doclist.pList;
185443 pIter = pPh->pOrPoslist;
185447 (pIter >= (pPh->doclist.aAll + pPh->doclist.nAll));
185448 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
185451 &pIter, &iDocid, &bEof
185455 bEof = !pPh->doclist.nAll || (pIter && pIter<=pPh->doclist.aAll);
185456 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){
185460 &pIter, &iDocid, &dummy, &bEof
185464 pPh->pOrPoslist = pIter;
185470 pIter = pPhrase->pOrPoslist;
185472 pIter = 0;
185475 if( pIter==0 ) return SQLITE_OK;
185477 if( *pIter==0x01 ){
185478 pIter++;
185479 pIter += fts3GetVarint32(pIter, &iThis);
185484 fts3ColumnlistCopy(0, &pIter);
185485 if( *pIter==0x00 ) return SQLITE_OK;
185486 pIter++;
185487 pIter += fts3GetVarint32(pIter, &iThis);
185489 if( *pIter==0x00 ){
185490 pIter = 0;
185493 *ppOut = ((iCol==iThis)?pIter:0);
186841 Fts3Expr *pIter = pNotBranch;
186842 while( pIter->pLeft ){
186843 pIter = pIter->pLeft;
186845 pIter->pLeft = pRet;
186846 pRet->pParent = pIter;
191858 SegmentNode *pIter;
191861 for(pIter=pTree->pLeftmost; pIter && rc==SQLITE_OK; pIter=pIter->pRight){
191862 int nStart = fts3TreeFinishNode(pIter, iHeight, iNextLeaf);
191863 int nWrite = pIter->nData - nStart;
191865 rc = fts3WriteSegment(p, iNextFree, &pIter->aData[nStart], nWrite);
191867 iNextLeaf += (pIter->nEntry+1);
195841 char *pIter = *ppIter;
195842 if( pIter ){
195846 if( 0==(*pIter & 0xFE) ){
195848 pIter = 0;
195851 fts3GetDeltaPosition(&pIter, &iIter);
195855 *ppIter = pIter;
195862 static int fts3SnippetNextCandidate(SnippetIter *pIter){
195865 if( pIter->iCurrent<0 ){
195870 pIter->iCurrent = 0;
195875 for(i=0; i<pIter->nPhrase; i++){
195876 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
195877 fts3SnippetAdvance(&pPhrase->pHead, &pPhrase->iHead, pIter->nSnippet);
195883 for(i=0; i<pIter->nPhrase; i++){
195884 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
195893 pIter->iCurrent = iStart = iEnd - pIter->nSnippet + 1;
195894 for(i=0; i<pIter->nPhrase; i++){
195895 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
195909 SnippetIter *pIter, /* Snippet iterator */
195916 int iStart = pIter->iCurrent; /* First token of snippet */
195922 for(i=0; i<pIter->nPhrase; i++){
195923 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
195928 while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){
196362 char *pIter = pPhrase->doclist.pList;
196372 if( pIter ) while( 1 ){
196373 int nHit = fts3ColumnlistCount(&pIter);
196381 assert( *pIter==0x00 || *pIter==0x01 );
196382 if( *pIter!=0x01 ) break;
196383 pIter++;
196384 pIter += fts3GetVarint32(pIter, &iCol);
196603 static int fts3LcsIteratorAdvance(LcsIterator *pIter){
196608 if( NEVER(pIter==0) ) return 1;
196609 pRead = pIter->pRead;
196615 pIter->iPos += (int)(iRead-2);
196618 pIter->pRead = pRead;
196648 LcsIterator *pIter = &aIter[i];
196649 nToken -= pIter->pExpr->pPhrase->nToken;
196650 pIter->iPosOffset = nToken;
196677 LcsIterator *pIter = &aIter[i];
196678 if( pIter->pRead==0 ){
196682 if( pAdv==0 || pIter->iPos<pAdv->iPos ){
196683 pAdv = pIter;
196685 if( nThisLcs==0 || pIter->iPos==pIter[-1].iPos ){
207732 UBreakIterator *pIter; /* ICU break-iterator object */
207845 pCsr->pIter = ubrk_open(UBRK_WORD, p->zLocale, pCsr->aChar, iOut, &status);
207852 ubrk_first(pCsr->pIter);
207862 ubrk_close(pCsr->pIter);
207888 iStart = ubrk_current(pCsr->pIter);
207889 iEnd = ubrk_next(pCsr->pIter);
209392 static void rbuObjIterFreeCols(RbuObjIter *pIter){
209394 for(i=0; i<pIter->nTblCol; i++){
209395 sqlite3_free(pIter->azTblCol[i]);
209396 sqlite3_free(pIter->azTblType[i]);
209398 sqlite3_free(pIter->azTblCol);
209399 pIter->azTblCol = 0;
209400 pIter->azTblType = 0;
209401 pIter->aiSrcOrder = 0;
209402 pIter->abTblPk = 0;
209403 pIter->abNotNull = 0;
209404 pIter->nTblCol = 0;
209405 pIter->eType = 0; /* Invalid value */
209412 static void rbuObjIterClearStatements(RbuObjIter *pIter){
209415 sqlite3_finalize(pIter->pSelect);
209416 sqlite3_finalize(pIter->pInsert);
209417 sqlite3_finalize(pIter->pDelete);
209418 sqlite3_finalize(pIter->pTmpInsert);
209419 pUp = pIter->pRbuUpdate;
209426 sqlite3_free(pIter->aIdxCol);
209427 sqlite3_free(pIter->zIdxSql);
209429 pIter->pSelect = 0;
209430 pIter->pInsert = 0;
209431 pIter->pDelete = 0;
209432 pIter->pRbuUpdate = 0;
209433 pIter->pTmpInsert = 0;
209434 pIter->nCol = 0;
209435 pIter->nIdxCol = 0;
209436 pIter->aIdxCol = 0;
209437 pIter->zIdxSql = 0;
209444 static void rbuObjIterFinalize(RbuObjIter *pIter){
209445 rbuObjIterClearStatements(pIter);
209446 sqlite3_finalize(pIter->pTblIter);
209447 sqlite3_finalize(pIter->pIdxIter);
209448 rbuObjIterFreeCols(pIter);
209449 memset(pIter, 0, sizeof(RbuObjIter));
209460 static int rbuObjIterNext(sqlite3rbu *p, RbuObjIter *pIter){
209465 rbuObjIterClearStatements(pIter);
209466 if( pIter->zIdx==0 ){
209477 if( pIter->bCleanup ){
209478 rbuObjIterFreeCols(pIter);
209479 pIter->bCleanup = 0;
209480 rc = sqlite3_step(pIter->pTblIter);
209482 rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg);
209483 pIter->zTbl = 0;
209485 pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0);
209486 pIter->zDataTbl = (const char*)sqlite3_column_text(pIter->pTblIter,1);
209487 rc = (pIter->zDataTbl && pIter->zTbl) ? SQLITE_OK : SQLITE_NOMEM;
209490 if( pIter->zIdx==0 ){
209491 sqlite3_stmt *pIdx = pIter->pIdxIter;
209492 rc = sqlite3_bind_text(pIdx, 1, pIter->zTbl, -1, SQLITE_STATIC);
209495 rc = sqlite3_step(pIter->pIdxIter);
209497 rc = resetAndCollectError(pIter->pIdxIter, &p->zErrmsg);
209498 pIter->bCleanup = 1;
209499 pIter->zIdx = 0;
209501 pIter->zIdx = (const char*)sqlite3_column_text(pIter->pIdxIter, 0);
209502 pIter->iTnum = sqlite3_column_int(pIter->pIdxIter, 1);
209503 pIter->bUnique = sqlite3_column_int(pIter->pIdxIter, 2);
209504 rc = pIter->zIdx ? SQLITE_OK : SQLITE_NOMEM;
209512 rbuObjIterFinalize(pIter);
209576 static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
209578 memset(pIter, 0, sizeof(RbuObjIter));
209580 rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
209590 rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
209597 pIter->bCleanup = 1;
209599 return rbuObjIterNext(p, pIter);
209683 static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){
209689 pIter->azTblCol = azNew;
209690 pIter->azTblType = &azNew[nCol];
209691 pIter->aiSrcOrder = (int*)&pIter->azTblType[nCol];
209692 pIter->abTblPk = (u8*)&pIter->aiSrcOrder[nCol];
209693 pIter->abNotNull = (u8*)&pIter->abTblPk[nCol];
209694 pIter->abIndexed = (u8*)&pIter->abNotNull[nCol];
209867 static void rbuObjIterCacheIndexedCols(sqlite3rbu *p, RbuObjIter *pIter){
209872 memcpy(pIter->abIndexed, pIter->abTblPk, sizeof(u8)*pIter->nTblCol);
209874 sqlite3_mprintf("PRAGMA main.index_list = %Q", pIter->zTbl)
209878 pIter->nIndex = 0;
209885 memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol);
209892 if( iCid>=0 ) pIter->abIndexed[iCid] = 1;
209894 memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol);
209899 pIter->nIndex++;
209902 if( pIter->eType==RBU_PK_WITHOUT_ROWID ){
209904 pIter->nIndex--;
209908 if( bIndex==0 ) pIter->abIndexed = 0;
209921 static int rbuObjIterCacheTableInfo(sqlite3rbu *p, RbuObjIter *pIter){
209922 if( pIter->azTblCol==0 ){
209931 assert( pIter->eType==0 );
209932 rbuTableType(p, pIter->zTbl, &pIter->eType, &iTnum, &pIter->iPkTnum);
209933 if( p->rc==SQLITE_OK && pIter->eType==RBU_PK_NOTABLE ){
209935 p->zErrmsg = sqlite3_mprintf("no such table: %s", pIter->zTbl);
209938 if( pIter->zIdx==0 ) pIter->iTnum = iTnum;
209940 assert( pIter->eType==RBU_PK_NONE || pIter->eType==RBU_PK_IPK
209941 || pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_WITHOUT_ROWID
209942 || pIter->eType==RBU_PK_VTAB
209949 sqlite3_mprintf("SELECT * FROM '%q'", pIter->zDataTbl)
209953 rbuAllocateIterArrays(p, pIter, nCol);
209959 pIter->aiSrcOrder[pIter->nTblCol] = pIter->nTblCol;
209960 pIter->azTblCol[pIter->nTblCol++] = zCopy;
209971 && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
209975 "table %q %s rbu_rowid column", pIter->zDataTbl,
209985 sqlite3_mprintf("PRAGMA table_info(%Q)", pIter->zTbl)
209991 for(i=iOrder; i<pIter->nTblCol; i++){
209992 if( 0==strcmp(zName, pIter->azTblCol[i]) ) break;
209994 if( i==pIter->nTblCol ){
209997 pIter->zDataTbl, zName
210005 SWAP(int, pIter->aiSrcOrder[i], pIter->aiSrcOrder[iOrder]);
210006 SWAP(char*, pIter->azTblCol[i], pIter->azTblCol[iOrder]);
210009 pIter->azTblType[iOrder] = rbuStrndup(zType, &p->rc);
210011 pIter->abTblPk[iOrder] = (u8)iPk;
210012 pIter->abNotNull[iOrder] = (u8)bNotNull || (iPk!=0);
210018 rbuObjIterCacheIndexedCols(p, pIter);
210019 assert( pIter->eType!=RBU_PK_VTAB || pIter->abIndexed==0 );
210020 assert( pIter->eType!=RBU_PK_VTAB || pIter->nIndex==0 );
210033 RbuObjIter *pIter /* Object iterator for column names */
210038 for(i=0; i<pIter->nTblCol; i++){
210039 const char *z = pIter->azTblCol[i];
210054 RbuObjIter *pIter, /* Object iterator for column names */
210064 for(i=0; i<pIter->nTblCol; i++){
210065 if( (int)pIter->abTblPk[i]==iPk ){
210066 const char *zCol = pIter->azTblCol[i];
210072 if( i==pIter->nTblCol ) break;
210099 RbuObjIter *pIter, /* RBU iterator object */
210108 "SELECT max(_rowid_) FROM \"%s%w\"", zWrite, pIter->zTbl
210117 char *zOrder = rbuObjIterGetPkList(p, pIter, "", ", ", " DESC");
210118 char *zSelect = rbuObjIterGetPkList(p, pIter, "quote(", "||','||", ")");
210119 char *zList = rbuObjIterGetPkList(p, pIter, "", ", ", "");
210125 zSelect, zWrite, pIter->zTbl, zOrder
210166 RbuObjIter *pIter /* RBU iterator object */
210179 sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", pIter->zIdx)
210191 if( pIter->eType==RBU_PK_IPK ){
210193 for(i=0; pIter->abTblPk[i]==0; i++);
210194 assert( i<pIter->nTblCol );
210195 zCol = pIter->azTblCol[i];
210200 zCol = pIter->azTblCol[iCid];
210223 zSelect, pIter->zTbl, zOrder
210228 for(iCol=0; iCol<pIter->nCol; iCol++){
210281 RbuObjIter *pIter, /* Object iterator for column names */
210301 sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", pIter->zIdx)
210315 pIter->aIdxCol[iSeq].nSpan, pIter->aIdxCol[iSeq].zSpan, zCollate
210322 if( pIter->eType==RBU_PK_IPK ){
210324 for(i=0; pIter->abTblPk[i]==0; i++);
210325 assert( i<pIter->nTblCol );
210326 zCol = pIter->azTblCol[i];
210334 zCol = pIter->azTblCol[iCid];
210335 zType = pIter->azTblType[iCid];
210340 if( pIter->bUnique==0 || sqlite3_column_int(pXInfo, 5) ){
210393 RbuObjIter *pIter,
210397 if( p->rc==SQLITE_OK && pIter->abIndexed ){
210400 for(i=0; i<pIter->nTblCol; i++){
210401 if( pIter->abIndexed[i] ){
210402 const char *zCol = pIter->azTblCol[i];
210415 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
210434 RbuObjIter *pIter
210437 if( pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE ){
210438 zList = rbuMPrintf(p, "_rowid_ = ?%d", pIter->nTblCol+1);
210439 }else if( pIter->eType==RBU_PK_EXTERNAL ){
210442 for(i=0; i<pIter->nTblCol; i++){
210443 if( pIter->abTblPk[i] ){
210455 for(i=0; i<pIter->nTblCol; i++){
210456 if( pIter->abTblPk[i] ){
210457 const char *zCol = pIter->azTblCol[i];
210498 RbuObjIter *pIter,
210505 if( (int)strlen(zMask)!=pIter->nTblCol ){
210509 for(i=0; i<pIter->nTblCol; i++){
210510 char c = zMask[pIter->aiSrcOrder[i]];
210513 zList, zSep, pIter->azTblCol[i], i+1
210519 zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
210525 zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
210577 static char *rbuWithoutRowidPK(sqlite3rbu *p, RbuObjIter *pIter){
210579 assert( pIter->zIdx==0 );
210586 sqlite3_mprintf("PRAGMA main.index_list = %Q", pIter->zTbl)
210636 static void rbuCreateImposterTable2(sqlite3rbu *p, RbuObjIter *pIter){
210637 if( p->rc==SQLITE_OK && pIter->eType==RBU_PK_EXTERNAL ){
210638 int tnum = pIter->iPkTnum; /* Root page of PK index */
210672 iCid, pIter->azTblType[iCid], zCollate
210710 static void rbuCreateImposterTable(sqlite3rbu *p, RbuObjIter *pIter){
210711 if( p->rc==SQLITE_OK && pIter->eType!=RBU_PK_VTAB ){
210712 int tnum = pIter->iTnum;
210718 for(iCol=0; p->rc==SQLITE_OK && iCol<pIter->nTblCol; iCol++){
210720 const char *zCol = pIter->azTblCol[iCol];
210724 p->dbMain, "main", pIter->zTbl, zCol, 0, &zColl, 0, 0, 0
210727 if( pIter->eType==RBU_PK_IPK && pIter->abTblPk[iCol] ){
210733 zSql, zComma, zCol, pIter->azTblType[iCol], zPk, zColl,
210734 (pIter->abNotNull[iCol] ? " NOT NULL" : "")
210739 if( pIter->eType==RBU_PK_WITHOUT_ROWID ){
210740 char *zPk = rbuWithoutRowidPK(p, pIter);
210748 pIter->zTbl, zSql,
210749 (pIter->eType==RBU_PK_WITHOUT_ROWID ? " WITHOUT ROWID" : "")
210768 RbuObjIter *pIter,
210772 int bRbuRowid = (pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE);
210773 char *zBind = rbuObjIterGetBindlist(p, pIter->nTblCol + 1 + bRbuRowid);
210775 assert( pIter->pTmpInsert==0 );
210777 p->dbRbu, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf(
210779 p->zStateDb, pIter->zDataTbl, zCollist, zRbuRowid, zBind
210814 static char *rbuObjIterGetIndexWhere(sqlite3rbu *p, RbuObjIter *pIter){
210819 assert( pIter->zIdxSql==0 && pIter->nIdxCol==0 && pIter->aIdxCol==0 );
210828 rc = sqlite3_bind_text(pStmt, 1, pIter->zIdx, -1, SQLITE_STATIC);
210832 pIter->zIdxSql = zSql = rbuStrndup(zSql, &rc);
210845 pIter->aIdxCol, (nIdxAlloc+16)*sizeof(RbuSpan)
210851 pIter->aIdxCol = aIdxCol;
210858 pIter->aIdxCol[0].zSpan = &zSql[i+1];
210865 int nSpan = &zSql[i] - pIter->aIdxCol[iIdxCol].zSpan;
210866 pIter->aIdxCol[iIdxCol++].nSpan = nSpan;
210871 int nSpan = &zSql[i] - pIter->aIdxCol[iIdxCol].zSpan;
210872 pIter->aIdxCol[iIdxCol++].nSpan = nSpan;
210873 pIter->aIdxCol[iIdxCol].zSpan = &zSql[i+1];
210897 pIter->nIdxCol = iIdxCol;
210916 RbuObjIter *pIter,
210919 assert( pIter->bCleanup==0 );
210920 if( pIter->pSelect==0 && rbuObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){
210921 const int tnum = pIter->iTnum;
210924 const char *zIdx = pIter->zIdx;
210933 const char *zTbl = pIter->zTbl;
210941 assert( pIter->eType!=RBU_PK_VTAB );
210942 zPart = rbuObjIterGetIndexWhere(p, pIter);
210944 p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
210958 pIter->nCol = nBind;
210961 p->dbMain, &pIter->pInsert, &p->zErrmsg,
210969 p->dbMain, &pIter->pDelete, &p->zErrmsg,
210980 zStart = rbuVacuumIndexStart(p, pIter);
210990 pIter->zDataTbl,
210998 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
211001 zCollist, p->zStateDb, pIter->zDataTbl,
211011 zCollist, p->zStateDb, pIter->zDataTbl, zPart,
211012 zCollist, pIter->zDataTbl,
211019 p->rc = prepareFreeAndCollectError(p->dbRbu,&pIter->pSelect,pz,zSql);
211031 int bRbuRowid = (pIter->eType==RBU_PK_VTAB)
211032 ||(pIter->eType==RBU_PK_NONE)
211033 ||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p));
211034 const char *zTbl = pIter->zTbl; /* Table this step applies to */
211037 char *zBindings = rbuObjIterGetBindlist(p, pIter->nTblCol + bRbuRowid);
211038 char *zWhere = rbuObjIterGetWhere(p, pIter);
211039 char *zOldlist = rbuObjIterGetOldlist(p, pIter, "old");
211040 char *zNewlist = rbuObjIterGetOldlist(p, pIter, "new");
211042 zCollist = rbuObjIterGetCollist(p, pIter);
211043 pIter->nCol = pIter->nTblCol;
211046 rbuCreateImposterTable(p, pIter);
211047 rbuCreateImposterTable2(p, pIter);
211048 zWrite = (pIter->eType==RBU_PK_VTAB ? "" : "rbu_imp_");
211052 p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pInsert, pz,
211064 p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pDelete, pz,
211071 if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
211073 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
211081 , p->zStateDb, pIter->zDataTbl
211082 , (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
211083 , pIter->zDataTbl
211106 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
211116 rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
211130 zStart = rbuVacuumTableStart(p, pIter, bRbuRowid, zWrite);
211139 zOrder = rbuObjIterGetPkList(p, pIter, "", ", ", "");
211144 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
211150 pIter->zDataTbl, (zStart ? zStart : ""),
211183 RbuObjIter *pIter, /* Object iterator */
211198 for(pp=&pIter->pRbuUpdate; *pp; pp=&((*pp)->pNext)){
211202 pUp->pNext = pIter->pRbuUpdate;
211203 pIter->pRbuUpdate = pUp;
211212 for(pp=&pIter->pRbuUpdate; *pp!=pUp; pp=&((*pp)->pNext));
211217 pUp = (RbuUpdateStmt*)rbuMalloc(p, sizeof(RbuUpdateStmt)+pIter->nTblCol+1);
211221 char *zWhere = rbuObjIterGetWhere(p, pIter);
211222 char *zSet = rbuObjIterGetSetlist(p, pIter, zMask);
211226 memcpy(pUp->zMask, zMask, pIter->nTblCol);
211227 pUp->pNext = pIter->pRbuUpdate;
211228 pIter->pRbuUpdate = pUp;
211233 if( pIter->eType!=RBU_PK_VTAB ) zPrefix = "rbu_imp_";
211235 zPrefix, pIter->zTbl, zSet, zWhere
211937 RbuObjIter *pIter = &p->objiter;
211943 assert( eType!=RBU_DELETE || pIter->zIdx==0 );
211957 pWriter = pIter->pDelete;
211959 pWriter = pIter->pInsert;
211962 for(i=0; i<pIter->nCol; i++){
211967 && pIter->zIdx==0 && pIter->eType==RBU_PK_IPK && pIter->abTblPk[i]
211968 && sqlite3_column_type(pIter->pSelect, i)==SQLITE_NULL
211975 if( eType==RBU_DELETE && pIter->abTblPk[i]==0 ){
211979 pVal = sqlite3_column_value(pIter->pSelect, i);
211983 if( pIter->zIdx==0 ){
211984 if( pIter->eType==RBU_PK_VTAB
211985 || pIter->eType==RBU_PK_NONE
211986 || (pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p))
211995 assertColumnName(pIter->pSelect, pIter->nCol+1,
211998 pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
211999 p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
212020 RbuObjIter *pIter = &p->objiter;
212029 assert( eType!=RBU_UPDATE || pIter->zIdx==0 );
212031 if( pIter->zIdx==0 && (eType==RBU_IDX_DELETE || eType==RBU_IDX_INSERT) ){
212035 if( pIter->zIdx==0 ){
212049 rbuGetUpdateStmt(p, pIter, zMask, &pUpdate);
212052 for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){
212053 char c = zMask[pIter->aiSrcOrder[i]];
212054 pVal = sqlite3_column_value(pIter->pSelect, i);
212055 if( pIter->abTblPk[i] || c!='.' ){
212060 && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
212063 assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid");
212064 pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
212065 p->rc = sqlite3_bind_value(pUpdate, pIter->nCol+1, pVal);
212252 RbuObjIter *pIter = &p->objiter;
212262 while( p->rc==SQLITE_OK && pIter->zTbl ){
212264 if( pIter->bCleanup ){
212268 if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
212270 "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zDataTbl
212274 rbuObjIterPrepareAll(p, pIter, 0);
212278 int rc = sqlite3_step(pIter->pSelect);
212284 p->rc = sqlite3_reset(pIter->pSelect);
212289 rbuObjIterNext(p, pIter);
212293 assert( pIter->zTbl==0 );
212396 RbuObjIter *pIter = &p->objiter;
212399 while( rc==SQLITE_OK && pIter->zTbl && (pIter->bCleanup
212400 || rbuStrCompare(pIter->zIdx, pState->zIdx)
212401 || (pState->zDataTbl==0 && rbuStrCompare(pIter->zTbl, pState->zTbl))
212402 || (pState->zDataTbl && rbuStrCompare(pIter->zDataTbl, pState->zDataTbl))
212404 rc = rbuObjIterNext(p, pIter);
212407 if( rc==SQLITE_OK && !pIter->zTbl ){
213116 rbu_file *pIter;
213120 for(pIter=pRbuVfs->pMain; pIter; pIter=pIter->pMainNext);
213124 for(pIter=pRbuVfs->pMainRbu; pIter && pIter!=p; pIter=pIter->pMainRbuNext){}
213125 if( pIter==0 ){
218706 sqlite3_changeset_iter *pIter, /* Iterator handle */
218712 *pOp = pIter->op;
218713 *pnCol = pIter->nCol;
218714 *pzTab = pIter->zTab;
218715 if( pbIndirect ) *pbIndirect = pIter->bIndirect;
218726 sqlite3_changeset_iter *pIter, /* Iterator object */
218730 *pabPK = pIter->abPK;
218731 if( pnCol ) *pnCol = pIter->nCol;
218749 sqlite3_changeset_iter *pIter, /* Changeset iterator */
218753 if( pIter->op!=SQLITE_UPDATE && pIter->op!=SQLITE_DELETE ){
218756 if( iVal<0 || iVal>=pIter->nCol ){
218759 *ppValue = pIter->apValue[iVal];
218777 sqlite3_changeset_iter *pIter, /* Changeset iterator */
218781 if( pIter->op!=SQLITE_UPDATE && pIter->op!=SQLITE_INSERT ){
218784 if( iVal<0 || iVal>=pIter->nCol ){
218787 *ppValue = pIter->apValue[pIter->nCol+iVal];
218796 #define sessionChangesetNew(pIter, iVal) (pIter)->apValue[(pIter)->nCol+(iVal)]
218797 #define sessionChangesetOld(pIter, iVal) (pIter)->apValue[(iVal)]
218811 sqlite3_changeset_iter *pIter, /* Changeset iterator */
218815 if( !pIter->pConflict ){
218818 if( iVal<0 || iVal>=pIter->nCol ){
218821 *ppValue = sqlite3_column_value(pIter->pConflict, iVal);
218834 sqlite3_changeset_iter *pIter, /* Changeset iterator */
218837 if( pIter->pConflict || pIter->apValue ){
218840 *pnOut = pIter->nCol;
219101 sqlite3_changeset_iter *pIter,
219108 int nCol = pIter->nCol;
219109 int nU32 = (pIter->nCol+33)/32;
219122 for(ii=0; ii<pIter->nCol; ii++){
219123 if( sessionChangesetNew(pIter, ii) ){
219161 int bStat1 = (sqlite3_stricmp(pIter->zTab, "sqlite_stat1")==0);
219174 sessionAppendIdent(&buf, pIter->zTab, &rc);
219178 for(ii=0; ii<pIter->nCol; ii++){
219179 if( p->abPK[ii]==0 && sessionChangesetNew(pIter, ii) ){
219191 for(ii=0; ii<pIter->nCol; ii++){
219192 if( p->abPK[ii] || (bPatchset==0 && sessionChangesetOld(pIter, ii)) ){
219449 sqlite3_changeset_iter *pIter, /* Iterator to read values from */
219467 (void)xValue(pIter, i, &pVal);
219499 sqlite3_changeset_iter *pIter, /* Changeset iterator */
219508 sqlite3changeset_op(pIter, &zDummy, &nCol, &op, 0);
219509 rc = sessionBindRow(pIter,
219535 sqlite3_changeset_iter *pIter /* Iterator pointing at current change */
219540 int eOp = pIter->op;
219543 const char *zTab = pIter->zTab;
219561 sqlite3changeset_old(pIter, i, &pVal);
219563 sqlite3changeset_new(pIter, i, &pVal);
219609 sqlite3_changeset_iter *pIter, /* Changeset iterator */
219620 sqlite3changeset_op(pIter, &zDummy, &nCol, &op, 0);
219628 rc = sessionSeekToRow(p->db, pIter, p->abPK, p->pSelect);
219635 pIter->pConflict = p->pSelect;
219636 res = xConflict(pCtx, eType, pIter);
219637 pIter->pConflict = 0;
219643 u8 *aBlob = &pIter->in.aData[pIter->in.iCurrent];
219644 int nBlob = pIter->in.iNext - pIter->in.iCurrent;
219649 res = xConflict(pCtx, eType+1, pIter);
219673 rc = sessionRebaseAdd(p, res, pIter);
219705 sqlite3_changeset_iter *pIter, /* Changeset iterator */
219721 sqlite3changeset_op(pIter, &zDummy, &nCol, &op, 0);
219736 u8 *abPK = (pIter->bPatchset ? p->abPK : 0);
219737 rc = sessionBindRow(pIter, sqlite3changeset_old, nCol, abPK, p->pDelete);
219747 SQLITE_CHANGESET_DATA, p, pIter, xConflict, pCtx, pbRetry
219751 SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, 0
219758 int bPatchset = (pbRetry==0 || pIter->bPatchset);
219760 rc = sessionUpdateFind(pIter, p, bPatchset, &pUp);
219764 sqlite3_value *pOld = sessionChangesetOld(pIter, i);
219765 sqlite3_value *pNew = sessionChangesetNew(pIter, i);
219786 SQLITE_CHANGESET_DATA, p, pIter, xConflict, pCtx, pbRetry
219792 SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, 0
219802 rc = sessionSeekToRow(p->db, pIter, p->abPK, p->pSelect);
219810 rc = sessionBindRow(pIter, sqlite3changeset_new, nCol, 0, p->pInsert);
219819 SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, pbReplace
219839 sqlite3_changeset_iter *pIter, /* Changeset iterator to read change from */
219848 rc = sessionApplyOneOp(pIter, pApply, xConflict, pCtx, &bReplace, &bRetry);
219858 assert( pIter->op==SQLITE_UPDATE || pIter->op==SQLITE_DELETE );
219859 rc = sessionApplyOneOp(pIter, pApply, xConflict, pCtx, 0, 0);
219868 assert( pIter->op==SQLITE_INSERT );
219871 rc = sessionBindRow(pIter,
219880 rc = sessionApplyOneOp(pIter, pApply, xConflict, pCtx, 0, 0);
219952 sqlite3_changeset_iter *pIter, /* Changeset to apply */
219975 pIter->in.bNoDiscard = 1;
219986 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3changeset_next(pIter) ){
219991 sqlite3changeset_op(pIter, &zNew, &nCol, &op, 0);
219997 db, pIter->bPatchset, zTab, &sApply, xConflict, pCtx
220034 sqlite3changeset_pk(pIter, &abPK, 0);
220088 rc = sessionApplyOneWithRetry(db, pIter, &sApply, xConflict, pCtx);
220091 bPatchset = pIter->bPatchset;
220093 rc = sqlite3changeset_finalize(pIter);
220095 sqlite3changeset_finalize(pIter);
220165 sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */
220167 int rc = sessionChangesetStart(&pIter, 0, 0, nChangeset, pChangeset, bInv, 1);
220170 db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags
220223 sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */
220225 int rc = sessionChangesetStart(&pIter, xInput, pIn, 0, 0, bInverse, 1);
220228 db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags
220450 sqlite3_changeset_iter *pIter, /* Iterator to read from */
220459 while( SQLITE_ROW==sessionChangesetNext(pIter, &aRec, &nRec, 0) ){
220470 pGrp->bPatch = pIter->bPatchset;
220471 }else if( pIter->bPatchset!=pGrp->bPatch ){
220476 sqlite3changeset_op(pIter, &zNew, &nCol, &op, &bIndirect);
220482 sqlite3changeset_pk(pIter, &abPK, 0);
220513 if( sessionGrowHash(0, pIter->bPatchset, pTab) ){
220518 pTab, (pIter->bPatchset && op==SQLITE_DELETE), aRec, pTab->nChange
220527 if( pIter->bPatchset ){
220540 pIter->bPatchset, pExist, op, bIndirect, aRec, nRec, &pChange
220550 if( rc==SQLITE_OK ) rc = pIter->rc;
220641 sqlite3_changeset_iter *pIter; /* Iterator opened on pData/nData */
220644 rc = sqlite3changeset_start(&pIter, nData, pData);
220646 rc = sessionChangesetToHash(pIter, pGrp, 0);
220648 sqlite3changeset_finalize(pIter);
220672 sqlite3_changeset_iter *pIter; /* Iterator opened on pData/nData */
220675 rc = sqlite3changeset_start_strm(&pIter, xInput, pIn);
220677 rc = sessionChangesetToHash(pIter, pGrp, 0);
220679 sqlite3changeset_finalize(pIter);
220826 sqlite3_changeset_iter *pIter, /* Iterator pointed at local change */
220840 *pOut++ = pIter->bIndirect;
220841 for(i=0; i<pIter->nCol; i++){
220844 if( pIter->abPK[i] || a2[0]==0 ){
220845 if( !pIter->abPK[i] && a1[0] ) bData = 1;
220860 for(i=0; i<pIter->nCol; i++){
220863 if( pIter->abPK[i] || a2[0]!=0xFF ){
220894 sqlite3_changeset_iter *pIter, /* Input data */
220907 while( SQLITE_ROW==sessionChangesetNext(pIter, &aRec, &nRec, &bNew) ){
220912 const char *zTab = pIter->zTab;
220919 if( pIter->bPatchset ){
220924 sessionAppendByte(&sOut, pIter->bPatchset ? 'P' : 'T', &rc);
220925 sessionAppendVarint(&sOut, pIter->nCol, &rc);
220926 sessionAppendBlob(&sOut, pIter->abPK, pIter->nCol, &rc);
220927 sessionAppendBlob(&sOut,(u8*)pIter->zTab,(int)strlen(pIter->zTab)+1,&rc);
220942 switch( pIter->op ){
220948 sessionAppendByte(&sOut, pIter->bIndirect, &rc);
220960 sessionSkipRecord(&pCsr, pIter->nCol);
220962 sessionAppendByte(&sOut, pIter->bIndirect, &rc);
220963 sessionAppendRecordMerge(&sOut, pIter->nCol,
220969 sessionAppendPartialUpdate(&sOut, pIter,
220976 assert( pIter->op==SQLITE_DELETE );
220980 sessionAppendByte(&sOut, pIter->bIndirect, &rc);
220981 sessionAppendRecordMerge(&sOut, pIter->nCol,
220990 sessionAppendByte(&sOut, pIter->op, &rc);
220991 sessionAppendByte(&sOut, pIter->bIndirect, &rc);
221045 sqlite3_changeset_iter *pIter = 0; /* Iterator opened on pData/nData */
221047 rc = sqlite3changeset_start(&pIter, nRebase, (void*)pRebase);
221049 rc = sessionChangesetToHash(pIter, &p->grp, 1);
221051 sqlite3changeset_finalize(pIter);
221063 sqlite3_changeset_iter *pIter = 0; /* Iterator to skip through input */
221064 int rc = sqlite3changeset_start(&pIter, nIn, (void*)pIn);
221067 rc = sessionRebase(p, pIter, 0, 0, pnOut, ppOut);
221068 sqlite3changeset_finalize(pIter);
221084 sqlite3_changeset_iter *pIter = 0; /* Iterator to skip through input */
221085 int rc = sqlite3changeset_start_strm(&pIter, xInput, pIn);
221088 rc = sessionRebase(p, pIter, xOutput, pOut, 0, 0);
221089 sqlite3changeset_finalize(pIter);
222037 Fts5PoslistReader *pIter /* Iterator object to initialize */
224123 static int fts5CInstIterNext(CInstIter *pIter){
224125 pIter->iStart = -1;
224126 pIter->iEnd = -1;
224128 while( rc==SQLITE_OK && pIter->iInst<pIter->nInst ){
224130 rc = pIter->pApi->xInst(pIter->pFts, pIter->iInst, &ip, &ic, &io);
224132 if( ic==pIter->iCol ){
224133 int iEnd = io - 1 + pIter->pApi->xPhraseSize(pIter->pFts, ip);
224134 if( pIter->iStart<0 ){
224135 pIter->iStart = io;
224136 pIter->iEnd = iEnd;
224137 }else if( io<=pIter->iEnd ){
224138 if( iEnd>pIter->iEnd ) pIter->iEnd = iEnd;
224143 pIter->iInst++;
224158 CInstIter *pIter
224162 memset(pIter, 0, sizeof(CInstIter));
224163 pIter->pApi = pApi;
224164 pIter->pFts = pFts;
224165 pIter->iCol = iCol;
224166 rc = pApi->xInstCount(pFts, &pIter->nInst);
224169 rc = fts5CInstIterNext(pIter);
224993 static int sqlite3Fts5PoslistReaderNext(Fts5PoslistReader *pIter){
224994 if( sqlite3Fts5PoslistNext64(pIter->a, pIter->n, &pIter->i, &pIter->iPos) ){
224995 pIter->bEof = 1;
224997 return pIter->bEof;
225002 Fts5PoslistReader *pIter /* Iterator object to initialize */
225004 memset(pIter, 0, sizeof(*pIter));
225005 pIter->a = a;
225006 pIter->n = n;
225007 sqlite3Fts5PoslistReaderNext(pIter);
225008 return pIter->bEof;
226253 Fts5IndexIter *pIter; /* Iterator for this term */
226600 if( 0==sqlite3Fts5IterEof(p->pIter) ){
226601 i64 iRowid = p->pIter->iRowid;
226631 Fts5IndexIter *pIter = p->pIter;
226632 if( sqlite3Fts5IterEof(pIter)==0 && pIter->iRowid==iRowid ){
226633 if( pIter->nData==0 ) continue;
226646 sqlite3Fts5PoslistReaderInit(pIter->pData, pIter->nData, &aIter[nIter]);
226737 a = (u8*)pTerm->pIter->pData;
226738 n = pTerm->pIter->nData;
226937 Fts5IndexIter *pIter, /* Iterator to advance */
226946 iRowid = pIter->iRowid;
226948 int rc = sqlite3Fts5IterNextFrom(pIter, iLast);
226949 if( rc || sqlite3Fts5IterEof(pIter) ){
226954 iRowid = pIter->iRowid;
226974 if( sqlite3Fts5IterEof(p->pIter)==0 ){
226975 i64 iRowid = p->pIter->iRowid;
226977 rc = sqlite3Fts5IterNextFrom(p->pIter, iLast);
227005 Fts5IndexIter *pIter = pTerm->pIter;
227006 if( sqlite3Fts5IterEof(pIter)==0 ){
227007 if( pIter->iRowid==pNode->iRowid && pIter->nData>0 ){
227028 Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter;
227029 fts5BufferSet(&rc, &pPhrase->poslist, pIter->nData, pIter->pData);
227073 if( p->pIter ){
227074 sqlite3Fts5IterClose(p->pIter);
227075 p->pIter = 0;
227082 &p->pIter
227084 assert( (rc==SQLITE_OK)==(p->pIter!=0) );
227086 if( 0==sqlite3Fts5IterEof(p->pIter) ){
227214 iLast = pLeft->aTerm[0].pIter->iRowid;
227233 Fts5IndexIter *pIter = pPhrase->aTerm[j].pIter;
227234 if( pIter->iRowid==iLast || pIter->bEof ) continue;
227236 if( fts5ExprAdvanceto(pIter, bDesc, &iLast, &rc, &pNode->bEof) ){
227278 if( sqlite3Fts5IterEof(p->pIter)==0 ){
227279 i64 ii = p->pIter->iRowid;
227284 rc = sqlite3Fts5IterNextFrom(p->pIter, iFrom);
227286 rc = sqlite3Fts5IterNext(p->pIter);
227289 if( sqlite3Fts5IterEof(p->pIter)==0 ){
227302 Fts5IndexIter *pIter = pTerm->pIter;
227306 rc = sqlite3Fts5IterNextFrom(pIter, iFrom);
227308 rc = sqlite3Fts5IterNext(pIter);
227311 pNode->bEof = (rc || sqlite3Fts5IterEof(pIter));
227333 Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter;
227339 pPhrase->poslist.n = pIter->nData;
227341 pPhrase->poslist.p = (u8*)pIter->pData;
227343 pNode->iRowid = pIter->iRowid;
227358 Fts5IndexIter *pIter = pNode->pNear->apPhrase[0]->aTerm[0].pIter;
227362 rc = sqlite3Fts5IterNextFrom(pIter, iFrom);
227364 rc = sqlite3Fts5IterNext(pIter);
227366 if( rc==SQLITE_OK && sqlite3Fts5IterEof(pIter)==0 ){
227716 sqlite3Fts5IterClose(pTerm->pIter);
227719 sqlite3Fts5IterClose(pSyn->pIter);
229221 *ppCollist = pPhrase->aTerm[0].pIter->pData;
229222 *pnCollist = pPhrase->aTerm[0].pIter->nData;
229688 Fts5HashEntry *pIter;
229689 for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
229691 || (pIter->nKey+1>=nTerm && 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm))
229693 Fts5HashEntry *pEntry = pIter;
231157 static int fts5DlidxIterNextR(Fts5Index *p, Fts5DlidxIter *pIter, int iLvl){
231158 Fts5DlidxLvl *pLvl = &pIter->aLvl[iLvl];
231160 assert( iLvl<pIter->nLvl );
231162 if( (iLvl+1) < pIter->nLvl ){
231163 fts5DlidxIterNextR(p, pIter, iLvl+1);
231168 FTS5_DLIDX_ROWID(pIter->iSegid, iLvl, pLvl[1].iLeafPgno)
231175 return pIter->aLvl[0].bEof;
231177 static int fts5DlidxIterNext(Fts5Index *p, Fts5DlidxIter *pIter){
231178 return fts5DlidxIterNextR(p, pIter, 0);
231192 static int fts5DlidxIterFirst(Fts5DlidxIter *pIter){
231194 for(i=0; i<pIter->nLvl; i++){
231195 fts5DlidxLvlNext(&pIter->aLvl[i]);
231197 return pIter->aLvl[0].bEof;
231201 static int fts5DlidxIterEof(Fts5Index *p, Fts5DlidxIter *pIter){
231202 return p->rc!=SQLITE_OK || pIter->aLvl[0].bEof;
231205 static void fts5DlidxIterLast(Fts5Index *p, Fts5DlidxIter *pIter){
231209 for(i=pIter->nLvl-1; p->rc==SQLITE_OK && i>=0; i--){
231210 Fts5DlidxLvl *pLvl = &pIter->aLvl[i];
231219 FTS5_DLIDX_ROWID(pIter->iSegid, i-1, pLvl->iLeafPgno)
231277 static int fts5DlidxIterPrevR(Fts5Index *p, Fts5DlidxIter *pIter, int iLvl){
231278 Fts5DlidxLvl *pLvl = &pIter->aLvl[iLvl];
231280 assert( iLvl<pIter->nLvl );
231282 if( (iLvl+1) < pIter->nLvl ){
231283 fts5DlidxIterPrevR(p, pIter, iLvl+1);
231288 FTS5_DLIDX_ROWID(pIter->iSegid, iLvl, pLvl[1].iLeafPgno)
231298 return pIter->aLvl[0].bEof;
231300 static int fts5DlidxIterPrev(Fts5Index *p, Fts5DlidxIter *pIter){
231301 return fts5DlidxIterPrevR(p, pIter, 0);
231307 static void fts5DlidxIterFree(Fts5DlidxIter *pIter){
231308 if( pIter ){
231310 for(i=0; i<pIter->nLvl; i++){
231311 fts5DataRelease(pIter->aLvl[i].pData);
231313 sqlite3_free(pIter);
231323 Fts5DlidxIter *pIter = 0;
231331 pNew = (Fts5DlidxIter*)sqlite3_realloc64(pIter, nByte);
231337 pIter = pNew;
231343 pIter->nLvl = i+1;
231348 pIter->iSegid = iSegid;
231350 fts5DlidxIterFirst(pIter);
231352 fts5DlidxIterLast(p, pIter);
231357 fts5DlidxIterFree(pIter);
231358 pIter = 0;
231361 return pIter;
231364 static i64 fts5DlidxIterRowid(Fts5DlidxIter *pIter){
231365 return pIter->aLvl[0].iRowid;
231367 static int fts5DlidxIterPgno(Fts5DlidxIter *pIter){
231368 return pIter->aLvl[0].iLeafPgno;
231376 Fts5SegIter *pIter /* Iterator to advance to next page */
231379 Fts5StructureSegment *pSeg = pIter->pSeg;
231380 fts5DataRelease(pIter->pLeaf);
231381 pIter->iLeafPgno++;
231382 if( pIter->pNextLeaf ){
231383 pIter->pLeaf = pIter->pNextLeaf;
231384 pIter->pNextLeaf = 0;
231385 }else if( pIter->iLeafPgno<=pSeg->pgnoLast ){
231386 pIter->pLeaf = fts5LeafRead(p,
231387 FTS5_SEGMENT_ROWID(pSeg->iSegid, pIter->iLeafPgno)
231390 pIter->pLeaf = 0;
231392 pLeaf = pIter->pLeaf;
231395 pIter->iPgidxOff = pLeaf->szLeaf;
231397 pIter->iEndofDoclist = pLeaf->nn+1;
231399 pIter->iPgidxOff += fts5GetVarint32(&pLeaf->p[pIter->iPgidxOff],
231400 pIter->iEndofDoclist
231433 static void fts5SegIterLoadNPos(Fts5Index *p, Fts5SegIter *pIter){
231435 int iOff = pIter->iLeafOffset; /* Offset to read at */
231436 ASSERT_SZLEAF_OK(pIter->pLeaf);
231438 int iEod = MIN(pIter->iEndofDoclist, pIter->pLeaf->szLeaf);
231439 pIter->bDel = 0;
231440 pIter->nPos = 1;
231441 if( iOff<iEod && pIter->pLeaf->p[iOff]==0 ){
231442 pIter->bDel = 1;
231444 if( iOff<iEod && pIter->pLeaf->p[iOff]==0 ){
231445 pIter->nPos = 1;
231448 pIter->nPos = 0;
231453 fts5FastGetVarint32(pIter->pLeaf->p, iOff, nSz);
231454 pIter->bDel = (nSz & 0x0001);
231455 pIter->nPos = nSz>>1;
231456 assert_nc( pIter->nPos>=0 );
231458 pIter->iLeafOffset = iOff;
231462 static void fts5SegIterLoadRowid(Fts5Index *p, Fts5SegIter *pIter){
231463 u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
231464 i64 iOff = pIter->iLeafOffset;
231466 ASSERT_SZLEAF_OK(pIter->pLeaf);
231467 if( iOff>=pIter->pLeaf->szLeaf ){
231468 fts5SegIterNextPage(p, pIter);
231469 if( pIter->pLeaf==0 ){
231474 a = pIter->pLeaf->p;
231476 iOff += sqlite3Fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
231477 pIter->iLeafOffset = iOff;
231495 static void fts5SegIterLoadTerm(Fts5Index *p, Fts5SegIter *pIter, int nKeep){
231496 u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
231497 i64 iOff = pIter->iLeafOffset; /* Offset to read at */
231501 if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
231505 pIter->term.n = nKeep;
231506 fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
231507 assert( pIter->term.n<=pIter->term.nSpace );
231509 pIter->iTermLeafOffset = iOff;
231510 pIter->iTermLeafPgno = pIter->iLeafPgno;
231511 pIter->iLeafOffset = iOff;
231513 if( pIter->iPgidxOff>=pIter->pLeaf->nn ){
231514 pIter->iEndofDoclist = pIter->pLeaf->nn+1;
231517 pIter->iPgidxOff += fts5GetVarint32(&a[pIter->iPgidxOff], nExtra);
231518 pIter->iEndofDoclist += nExtra;
231521 fts5SegIterLoadRowid(p, pIter);
231528 static void fts5SegIterSetNext(Fts5Index *p, Fts5SegIter *pIter){
231529 if( pIter->flags & FTS5_SEGITER_REVERSE ){
231530 pIter->xNext = fts5SegIterNext_Reverse;
231532 pIter->xNext = fts5SegIterNext_None;
231534 pIter->xNext = fts5SegIterNext;
231549 Fts5SegIter *pIter /* Object to populate */
231557 assert( pIter->pLeaf==0 );
231562 memset(pIter, 0, sizeof(*pIter));
231563 fts5SegIterSetNext(p, pIter);
231564 pIter->pSeg = pSeg;
231565 pIter->iLeafPgno = pSeg->pgnoFirst-1;
231566 fts5SegIterNextPage(p, pIter);
231570 pIter->iLeafOffset = 4;
231571 assert( pIter->pLeaf!=0 );
231572 assert_nc( pIter->pLeaf->nn>4 );
231573 assert_nc( fts5LeafFirstTermOff(pIter->pLeaf)==4 );
231574 pIter->iPgidxOff = pIter->pLeaf->szLeaf+1;
231575 fts5SegIterLoadTerm(p, pIter, 0);
231576 fts5SegIterLoadNPos(p, pIter);
231595 static void fts5SegIterReverseInitPage(Fts5Index *p, Fts5SegIter *pIter){
231597 int n = pIter->pLeaf->szLeaf;
231598 int i = pIter->iLeafOffset;
231599 u8 *a = pIter->pLeaf->p;
231602 if( n>pIter->iEndofDoclist ){
231603 n = pIter->iEndofDoclist;
231606 ASSERT_SZLEAF_OK(pIter->pLeaf);
231624 pIter->iRowid += iDelta;
231627 if( iRowidOffset>=pIter->nRowidOffset ){
231628 int nNew = pIter->nRowidOffset + 8;
231629 int *aNew = (int*)sqlite3_realloc64(pIter->aRowidOffset,nNew*sizeof(int));
231634 pIter->aRowidOffset = aNew;
231635 pIter->nRowidOffset = nNew;
231638 pIter->aRowidOffset[iRowidOffset++] = pIter->iLeafOffset;
231639 pIter->iLeafOffset = i;
231641 pIter->iRowidOffset = iRowidOffset;
231642 fts5SegIterLoadNPos(p, pIter);
231648 static void fts5SegIterReverseNewPage(Fts5Index *p, Fts5SegIter *pIter){
231649 assert( pIter->flags & FTS5_SEGITER_REVERSE );
231650 assert( pIter->flags & FTS5_SEGITER_ONETERM );
231652 fts5DataRelease(pIter->pLeaf);
231653 pIter->pLeaf = 0;
231654 while( p->rc==SQLITE_OK && pIter->iLeafPgno>pIter->iTermLeafPgno ){
231656 pIter->iLeafPgno--;
231658 pIter->pSeg->iSegid, pIter->iLeafPgno
231664 if( pIter->iLeafPgno==pIter->iTermLeafPgno ){
231665 assert( pIter->pLeaf==0 );
231666 if( pIter->iTermLeafOffset<pNew->szLeaf ){
231667 pIter->pLeaf = pNew;
231668 pIter->iLeafOffset = pIter->iTermLeafOffset;
231677 pIter->pLeaf = pNew;
231678 pIter->iLeafOffset = iRowidOff;
231683 if( pIter->pLeaf ){
231684 u8 *a = &pIter->pLeaf->p[pIter->iLeafOffset];
231685 pIter->iLeafOffset += fts5GetVarint(a, (u64*)&pIter->iRowid);
231693 if( pIter->pLeaf ){
231694 pIter->iEndofDoclist = pIter->pLeaf->nn+1;
231695 fts5SegIterReverseInitPage(p, pIter);
231704 static int fts5MultiIterIsEmpty(Fts5Index *p, Fts5Iter *pIter){
231705 Fts5SegIter *pSeg = &pIter->aSeg[pIter->aFirst[1].iFirst];
231716 Fts5SegIter *pIter, /* Iterator to advance */
231719 assert( pIter->flags & FTS5_SEGITER_REVERSE );
231720 assert( pIter->pNextLeaf==0 );
231723 if( pIter->iRowidOffset>0 ){
231724 u8 *a = pIter->pLeaf->p;
231728 pIter->iRowidOffset--;
231729 pIter->iLeafOffset = pIter->aRowidOffset[pIter->iRowidOffset];
231730 fts5SegIterLoadNPos(p, pIter);
231731 iOff = pIter->iLeafOffset;
231733 iOff += pIter->nPos;
231736 pIter->iRowid -= iDelta;
231738 fts5SegIterReverseNewPage(p, pIter);
231750 Fts5SegIter *pIter, /* Iterator to advance */
231756 assert( (pIter->flags & FTS5_SEGITER_REVERSE)==0 );
231759 ASSERT_SZLEAF_OK(pIter->pLeaf);
231760 iOff = pIter->iLeafOffset;
231763 if( pIter->pSeg && iOff>=pIter->pLeaf->szLeaf ){
231764 fts5SegIterNextPage(p, pIter);
231765 if( p->rc || pIter->pLeaf==0 ) return;
231766 pIter->iRowid = 0;
231770 if( iOff<pIter->iEndofDoclist ){
231773 iOff += sqlite3Fts5GetVarint(&pIter->pLeaf->p[iOff], (u64*)&iDelta);
231774 pIter->iLeafOffset = iOff;
231775 pIter->iRowid += iDelta;
231776 }else if( (pIter->flags & FTS5_SEGITER_ONETERM)==0 ){
231777 if( pIter->pSeg ){
231779 if( iOff!=fts5LeafFirstTermOff(pIter->pLeaf) ){
231780 iOff += fts5GetVarint32(&pIter->pLeaf->p[iOff], nKeep);
231782 pIter->iLeafOffset = iOff;
231783 fts5SegIterLoadTerm(p, pIter, nKeep);
231791 pIter->pLeaf->p = (u8*)pList;
231792 pIter->pLeaf->nn = nList;
231793 pIter->pLeaf->szLeaf = nList;
231794 pIter->iEndofDoclist = nList;
231795 sqlite3Fts5BufferSet(&p->rc,&pIter->term, (int)strlen(zTerm), (u8*)zTerm);
231796 pIter->iLeafOffset = fts5GetVarint(pList, (u64*)&pIter->iRowid);
231804 fts5SegIterLoadNPos(p, pIter);
231808 fts5DataRelease(pIter->pLeaf);
231809 pIter->pLeaf = 0;
231822 Fts5SegIter *pIter, /* Iterator to advance */
231825 Fts5Data *pLeaf = pIter->pLeaf;
231840 iOff = pIter->iLeafOffset + pIter->nPos;
231844 assert_nc( iOff<=pIter->iEndofDoclist );
231845 if( iOff>=pIter->iEndofDoclist ){
231853 pIter->iRowid += iDelta;
231856 pIter->iLeafOffset = iOff;
231858 }else if( pIter->pSeg==0 ){
231862 assert( (pIter->flags & FTS5_SEGITER_ONETERM) || pbNewTerm );
231863 if( 0==(pIter->flags & FTS5_SEGITER_ONETERM) ){
231868 fts5DataRelease(pIter->pLeaf);
231869 pIter->pLeaf = 0;
231871 pIter->pLeaf->p = (u8*)pList;
231872 pIter->pLeaf->nn = nList;
231873 pIter->pLeaf->szLeaf = nList;
231874 pIter->iEndofDoclist = nList+1;
231875 sqlite3Fts5BufferSet(&p->rc, &pIter->term, (int)strlen(zTerm),
231877 pIter->iLeafOffset = fts5GetVarint(pList, (u64*)&pIter->iRowid);
231884 fts5SegIterNextPage(p, pIter);
231885 pLeaf = pIter->pLeaf;
231889 iOff += sqlite3Fts5GetVarint(&pLeaf->p[iOff], (u64*)&pIter->iRowid);
231890 pIter->iLeafOffset = iOff;
231893 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
231894 &pLeaf->p[pLeaf->szLeaf], pIter->iEndofDoclist
231899 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
231902 pIter->iLeafOffset = iOff;
231903 pIter->iEndofDoclist = iOff;
231915 if( pIter->pLeaf ){
231917 if( pIter->flags & FTS5_SEGITER_ONETERM ){
231918 fts5DataRelease(pIter->pLeaf);
231919 pIter->pLeaf = 0;
231921 fts5SegIterLoadTerm(p, pIter, nKeep);
231922 fts5SegIterLoadNPos(p, pIter);
231930 assert_nc( pIter->iLeafOffset<=pIter->pLeaf->nn );
231931 fts5FastGetVarint32(pIter->pLeaf->p, pIter->iLeafOffset, nSz);
231932 pIter->bDel = (nSz & 0x0001);
231933 pIter->nPos = nSz>>1;
231934 assert_nc( pIter->nPos>=0 );
231951 static void fts5SegIterReverse(Fts5Index *p, Fts5SegIter *pIter){
231952 Fts5DlidxIter *pDlidx = pIter->pDlidx;
231957 int iSegid = pIter->pSeg->iSegid;
231961 Fts5Data *pLeaf = pIter->pLeaf; /* Current leaf data */
231967 if( pIter->iTermLeafPgno==pIter->iLeafPgno ){
231968 iPoslist = pIter->iTermLeafOffset;
231973 pIter->iLeafOffset = iPoslist;
231978 if( pIter->iEndofDoclist>=pLeaf->szLeaf ){
231980 Fts5StructureSegment *pSeg = pIter->pSeg;
231984 for(pgno=pIter->iLeafPgno+1; !p->rc && pgno<=pSeg->pgnoLast; pgno++){
232013 fts5DataRelease(pIter->pLeaf);
232014 pIter->pLeaf = pLast;
232015 pIter->iLeafPgno = pgnoLast;
232021 iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
232022 pIter->iLeafOffset = iOff;
232025 pIter->iEndofDoclist = pLast->nn+1;
232027 pIter->iEndofDoclist = fts5LeafFirstTermOff(pLast);
232031 fts5SegIterReverseInitPage(p, pIter);
232040 static void fts5SegIterLoadDlidx(Fts5Index *p, Fts5SegIter *pIter){
232041 int iSeg = pIter->pSeg->iSegid;
232042 int bRev = (pIter->flags & FTS5_SEGITER_REVERSE);
232043 Fts5Data *pLeaf = pIter->pLeaf; /* Current leaf data */
232045 assert( pIter->flags & FTS5_SEGITER_ONETERM );
232046 assert( pIter->pDlidx==0 );
232051 if( pIter->iTermLeafPgno==pIter->iLeafPgno
232052 && pIter->iEndofDoclist<pLeaf->szLeaf
232057 pIter->pDlidx = fts5DlidxIterInit(p, bRev, iSeg, pIter->iTermLeafPgno);
232077 Fts5SegIter *pIter, /* Iterator to seek */
232081 const u8 *a = pIter->pLeaf->p;
232082 u32 n = (u32)pIter->pLeaf->nn;
232093 iPgidx = (u32)pIter->pLeaf->szLeaf;
232150 fts5DataRelease(pIter->pLeaf);
232151 pIter->pLeaf = 0;
232155 fts5SegIterNextPage(p, pIter);
232156 if( pIter->pLeaf==0 ) return;
232157 a = pIter->pLeaf->p;
232158 if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
232159 iPgidx = (u32)pIter->pLeaf->szLeaf;
232160 iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
232161 if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){
232167 n = (u32)pIter->pLeaf->nn;
232180 pIter->iLeafOffset = iOff + nNew;
232181 pIter->iTermLeafOffset = pIter->iLeafOffset;
232182 pIter->iTermLeafPgno = pIter->iLeafPgno;
232184 fts5BufferSet(&p->rc, &pIter->term, nKeep, pTerm);
232185 fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
232188 pIter->iEndofDoclist = pIter->pLeaf->nn+1;
232192 pIter->iEndofDoclist = iTermOff + nExtra;
232194 pIter->iPgidxOff = iPgidx;
232196 fts5SegIterLoadRowid(p, pIter);
232197 fts5SegIterLoadNPos(p, pIter);
232224 Fts5SegIter *pIter /* Object to populate */
232233 memset(pIter, 0, sizeof(*pIter));
232234 pIter->pSeg = pSeg;
232255 pIter->iLeafPgno = iPg - 1;
232256 fts5SegIterNextPage(p, pIter);
232258 if( pIter->pLeaf ){
232259 fts5LeafSeek(p, bGe, pIter, pTerm, nTerm);
232263 pIter->flags |= FTS5_SEGITER_ONETERM;
232264 if( pIter->pLeaf ){
232266 pIter->flags |= FTS5_SEGITER_REVERSE;
232269 fts5SegIterLoadDlidx(p, pIter);
232272 fts5SegIterReverse(p, pIter);
232277 fts5SegIterSetNext(p, pIter);
232288 || pIter->pLeaf==0 /* 2 */
232289 || fts5BufferCompareBlob(&pIter->term, pTerm, nTerm)==0 /* 3 */
232290 || (bGe && fts5BufferCompareBlob(&pIter->term, pTerm, nTerm)>0) /* 4 */
232306 Fts5SegIter *pIter /* Object to populate */
232337 pIter->flags |= FTS5_SEGITER_ONETERM;
232341 sqlite3Fts5BufferSet(&p->rc, &pIter->term, n, z);
232343 pIter->pLeaf = pLeaf;
232344 pIter->iLeafOffset = fts5GetVarint(pLeaf->p, (u64*)&pIter->iRowid);
232345 pIter->iEndofDoclist = pLeaf->nn;
232348 pIter->flags |= FTS5_SEGITER_REVERSE;
232349 fts5SegIterReverseInitPage(p, pIter);
232351 fts5SegIterLoadNPos(p, pIter);
232355 fts5SegIterSetNext(p, pIter);
232361 static void fts5SegIterClear(Fts5SegIter *pIter){
232362 fts5BufferFree(&pIter->term);
232363 fts5DataRelease(pIter->pLeaf);
232364 fts5DataRelease(pIter->pNextLeaf);
232365 fts5DlidxIterFree(pIter->pDlidx);
232366 sqlite3_free(pIter->aRowidOffset);
232367 memset(pIter, 0, sizeof(Fts5SegIter));
232379 Fts5Iter *pIter,
232384 int i1 = p1 - pIter->aSeg;
232385 int i2 = p2 - pIter->aSeg;
232400 res = ((p1->iRowid > p2->iRowid)==pIter->bRev) ? -1 : 1;
232420 static void fts5AssertMultiIterSetup(Fts5Index *p, Fts5Iter *pIter){
232422 Fts5SegIter *pFirst = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
232425 assert( (pFirst->pLeaf==0)==pIter->base.bEof );
232428 for(i=0; i<pIter->nSeg; i++){
232429 Fts5SegIter *p1 = &pIter->aSeg[i];
232433 || p1->iRowid==pIter->iSwitchRowid
232434 || (p1->iRowid<pIter->iSwitchRowid)==pIter->bRev
232438 for(i=0; i<pIter->nSeg; i+=2){
232439 Fts5SegIter *p1 = &pIter->aSeg[i];
232440 Fts5SegIter *p2 = &pIter->aSeg[i+1];
232441 Fts5CResult *pRes = &pIter->aFirst[(pIter->nSeg + i) / 2];
232442 fts5AssertComparisonResult(pIter, p1, p2, pRes);
232445 for(i=1; i<(pIter->nSeg / 2); i+=2){
232446 Fts5SegIter *p1 = &pIter->aSeg[ pIter->aFirst[i*2].iFirst ];
232447 Fts5SegIter *p2 = &pIter->aSeg[ pIter->aFirst[i*2+1].iFirst ];
232448 Fts5CResult *pRes = &pIter->aFirst[i];
232449 fts5AssertComparisonResult(pIter, p1, p2, pRes);
232465 static int fts5MultiIterDoCompare(Fts5Iter *pIter, int iOut){
232471 Fts5CResult *pRes = &pIter->aFirst[iOut];
232473 assert( iOut<pIter->nSeg && iOut>0 );
232474 assert( pIter->bRev==0 || pIter->bRev==1 );
232476 if( iOut>=(pIter->nSeg/2) ){
232477 i1 = (iOut - pIter->nSeg/2) * 2;
232480 i1 = pIter->aFirst[iOut*2].iFirst;
232481 i2 = pIter->aFirst[iOut*2+1].iFirst;
232483 p1 = &pIter->aSeg[i1];
232484 p2 = &pIter->aSeg[i2];
232501 res = ((p1->iRowid > p2->iRowid)==pIter->bRev) ? -1 : +1;
232521 Fts5SegIter *pIter, /* Iterator to advance */
232524 assert( iLeafPgno>pIter->iLeafPgno );
232526 if( iLeafPgno>pIter->pSeg->pgnoLast ){
232529 fts5DataRelease(pIter->pNextLeaf);
232530 pIter->pNextLeaf = 0;
232531 pIter->iLeafPgno = iLeafPgno-1;
232532 fts5SegIterNextPage(p, pIter);
232533 assert( p->rc!=SQLITE_OK || pIter->iLeafPgno==iLeafPgno );
232535 if( p->rc==SQLITE_OK && ALWAYS(pIter->pLeaf!=0) ){
232537 u8 *a = pIter->pLeaf->p;
232538 int n = pIter->pLeaf->szLeaf;
232540 iOff = fts5LeafFirstRowidOff(pIter->pLeaf);
232544 iOff += fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
232545 pIter->iLeafOffset = iOff;
232546 fts5SegIterLoadNPos(p, pIter);
232559 Fts5SegIter *pIter, /* Iterator to advance */
232562 int bRev = (pIter->flags & FTS5_SEGITER_REVERSE);
232563 Fts5DlidxIter *pDlidx = pIter->pDlidx;
232564 int iLeafPgno = pIter->iLeafPgno;
232567 assert( pIter->flags & FTS5_SEGITER_ONETERM );
232568 assert( pIter->pDlidx );
232569 assert( pIter->pLeaf );
232576 assert_nc( iLeafPgno>=pIter->iLeafPgno || p->rc );
232577 if( iLeafPgno>pIter->iLeafPgno ){
232578 fts5SegIterGotoPage(p, pIter, iLeafPgno);
232582 assert( pIter->pNextLeaf==0 );
232583 assert( iMatch<pIter->iRowid );
232589 assert( fts5DlidxIterEof(p, pDlidx) || iLeafPgno<=pIter->iLeafPgno );
232591 if( iLeafPgno<pIter->iLeafPgno ){
232592 pIter->iLeafPgno = iLeafPgno+1;
232593 fts5SegIterReverseNewPage(p, pIter);
232599 if( bMove && p->rc==SQLITE_OK ) pIter->xNext(p, pIter, 0);
232600 if( pIter->pLeaf==0 ) break;
232601 if( bRev==0 && pIter->iRowid>=iMatch ) break;
232602 if( bRev!=0 && pIter->iRowid<=iMatch ) break;
232611 static void fts5MultiIterFree(Fts5Iter *pIter){
232612 if( pIter ){
232614 for(i=0; i<pIter->nSeg; i++){
232615 fts5SegIterClear(&pIter->aSeg[i]);
232617 fts5BufferFree(&pIter->poslist);
232618 sqlite3_free(pIter);
232624 Fts5Iter *pIter, /* Iterator to update aFirst[] array for */
232629 for(i=(pIter->nSeg+iChanged)/2; i>=iMinset && p->rc==SQLITE_OK; i=i/2){
232631 if( (iEq = fts5MultiIterDoCompare(pIter, i)) ){
232632 Fts5SegIter *pSeg = &pIter->aSeg[iEq];
232635 i = pIter->nSeg + iEq;
232651 Fts5Iter *pIter, /* Iterator to update aFirst[] array for */
232655 Fts5SegIter *pNew = &pIter->aSeg[iChanged];
232657 if( pNew->iRowid==pIter->iSwitchRowid
232658 || (pNew->iRowid<pIter->iSwitchRowid)==pIter->bRev
232661 Fts5SegIter *pOther = &pIter->aSeg[iChanged ^ 0x0001];
232662 pIter->iSwitchRowid = pIter->bRev ? SMALLEST_INT64 : LARGEST_INT64;
232663 for(i=(pIter->nSeg+iChanged)/2; 1; i=i/2){
232664 Fts5CResult *pRes = &pIter->aFirst[i];
232672 }else if( (pOther->iRowid>pNew->iRowid)==pIter->bRev ){
232673 pIter->iSwitchRowid = pOther->iRowid;
232675 }else if( (pOther->iRowid>pIter->iSwitchRowid)==pIter->bRev ){
232676 pIter->iSwitchRowid = pOther->iRowid;
232679 pRes->iFirst = (u16)(pNew - pIter->aSeg);
232682 pOther = &pIter->aSeg[ pIter->aFirst[i ^ 0x0001].iFirst ];
232693 static void fts5MultiIterSetEof(Fts5Iter *pIter){
232694 Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
232695 pIter->base.bEof = pSeg->pLeaf==0;
232696 pIter->iSwitchRowid = pSeg->iRowid;
232708 Fts5Iter *pIter,
232713 assert( pIter->base.bEof==0 );
232715 int iFirst = pIter->aFirst[1].iFirst;
232717 Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
232726 || fts5MultiIterAdvanceRowid(pIter, iFirst, &pSeg)
232728 fts5MultiIterAdvanced(p, pIter, iFirst, 1);
232729 fts5MultiIterSetEof(pIter);
232730 pSeg = &pIter->aSeg[pIter->aFirst[1].iFirst];
232734 fts5AssertMultiIterSetup(p, pIter);
232735 assert( pSeg==&pIter->aSeg[pIter->aFirst[1].iFirst] && pSeg->pLeaf );
232736 if( pIter->bSkipEmpty==0 || pSeg->nPos ){
232737 pIter->xSetOutputs(pIter, pSeg);
232746 Fts5Iter *pIter,
232749 assert( pIter->bSkipEmpty );
232753 int iFirst = pIter->aFirst[1].iFirst;
232754 Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
232760 || fts5MultiIterAdvanceRowid(pIter, iFirst, &pSeg)
232762 fts5MultiIterAdvanced(p, pIter, iFirst, 1);
232763 fts5MultiIterSetEof(pIter);
232766 fts5AssertMultiIterSetup(p, pIter);
232768 }while( fts5MultiIterIsEmpty(p, pIter) );
233010 Fts5Iter *pIter
233019 if( pColset->nCol>1 && sqlite3Fts5BufferSize(pRc, &pIter->poslist, nPos) ){
233027 pIter->base.pData = pIter->poslist.p;
233028 pIter->base.nData = pIter->poslist.n;
233041 pIter->base.pData = aCopy;
233042 pIter->base.nData = p-aCopy;
233045 fts5BufferSafeAppendBlob(&pIter->poslist, aCopy, p-aCopy);
233048 pIter->base.pData = pIter->poslist.p;
233049 pIter->base.nData = pIter->poslist.n;
233066 static void fts5IterSetOutputs_None(Fts5Iter *pIter, Fts5SegIter *pSeg){
233067 assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_NONE );
233068 pIter->base.iRowid = pSeg->iRowid;
233069 pIter->base.nData = pSeg->nPos;
233076 static void fts5IterSetOutputs_Nocolset(Fts5Iter *pIter, Fts5SegIter *pSeg){
233077 pIter->base.iRowid = pSeg->iRowid;
233078 pIter->base.nData = pSeg->nPos;
233080 assert( pIter->pIndex->pConfig->eDetail!=FTS5_DETAIL_NONE );
233081 assert( pIter->pColset==0 );
233086 pIter->base.pData = &pSeg->pLeaf->p[pSeg->iLeafOffset];
233091 fts5BufferZero(&pIter->poslist);
233092 fts5SegiterPoslist(pIter->pIndex, pSeg, 0, &pIter->poslist);
233093 pIter->base.pData = pIter->poslist.p;
233101 static void fts5IterSetOutputs_ZeroColset(Fts5Iter *pIter, Fts5SegIter *pSeg){
233103 pIter->base.nData = 0;
233111 static void fts5IterSetOutputs_Col(Fts5Iter *pIter, Fts5SegIter *pSeg){
233112 fts5BufferZero(&pIter->poslist);
233113 fts5SegiterPoslist(pIter->pIndex, pSeg, pIter->pColset, &pIter->poslist);
233114 pIter->base.iRowid = pSeg->iRowid;
233115 pIter->base.pData = pIter->poslist.p;
233116 pIter->base.nData = pIter->poslist.n;
233129 static void fts5IterSetOutputs_Col100(Fts5Iter *pIter, Fts5SegIter *pSeg){
233131 assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_COLUMNS );
233132 assert( pIter->pColset );
233135 fts5IterSetOutputs_Col(pIter, pSeg);
233140 int *aiCol = pIter->pColset->aiCol;
233141 int *aiColEnd = &aiCol[pIter->pColset->nCol];
233143 u8 *aOut = pIter->poslist.p;
233146 pIter->base.iRowid = pSeg->iRowid;
233161 pIter->base.pData = pIter->poslist.p;
233162 pIter->base.nData = aOut - pIter->poslist.p;
233169 static void fts5IterSetOutputs_Full(Fts5Iter *pIter, Fts5SegIter *pSeg){
233170 Fts5Colset *pColset = pIter->pColset;
233171 pIter->base.iRowid = pSeg->iRowid;
233173 assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_FULL );
233180 int *pRc = &pIter->pIndex->rc;
233181 fts5BufferZero(&pIter->poslist);
233182 fts5IndexExtractColset(pRc, pColset, a, pSeg->nPos, pIter);
233187 fts5BufferZero(&pIter->poslist);
233188 fts5SegiterPoslist(pIter->pIndex, pSeg, pColset, &pIter->poslist);
233189 pIter->base.pData = pIter->poslist.p;
233190 pIter->base.nData = pIter->poslist.n;
233194 static void fts5IterSetOutputCb(int *pRc, Fts5Iter *pIter){
233195 assert( pIter!=0 || (*pRc)!=SQLITE_OK );
233197 Fts5Config *pConfig = pIter->pIndex->pConfig;
233199 pIter->xSetOutputs = fts5IterSetOutputs_None;
233202 else if( pIter->pColset==0 ){
233203 pIter->xSetOutputs = fts5IterSetOutputs_Nocolset;
233206 else if( pIter->pColset->nCol==0 ){
233207 pIter->xSetOutputs = fts5IterSetOutputs_ZeroColset;
233211 pIter->xSetOutputs = fts5IterSetOutputs_Full;
233217 pIter->xSetOutputs = fts5IterSetOutputs_Col100;
233218 sqlite3Fts5BufferSize(pRc, &pIter->poslist, pConfig->nCol);
233220 pIter->xSetOutputs = fts5IterSetOutputs_Col;
233284 Fts5SegIter *pIter = &pNew->aSeg[iIter++];
233285 fts5SegIterHashInit(p, pTerm, nTerm, flags, pIter);
233290 Fts5SegIter *pIter = &pNew->aSeg[iIter++];
233292 fts5SegIterInit(p, pSeg, pIter);
233294 fts5SegIterSeekInit(p, pTerm, nTerm, flags, pSeg, pIter);
233353 Fts5SegIter *pIter = &pNew->aSeg[1];
233355 pIter->flags = FTS5_SEGITER_ONETERM;
233357 pIter->pLeaf = pData;
233358 pIter->iLeafOffset = fts5GetVarint(pData->p, (u64*)&pIter->iRowid);
233359 pIter->iEndofDoclist = pData->nn;
233363 pIter->flags |= FTS5_SEGITER_REVERSE;
233364 fts5SegIterReverseInitPage(p, pIter);
233366 fts5SegIterLoadNPos(p, pIter);
233372 fts5SegIterSetNext(p, pIter);
233384 static int fts5MultiIterEof(Fts5Index *p, Fts5Iter *pIter){
233385 assert( pIter!=0 || p->rc!=SQLITE_OK );
233387 || (pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf==0)==pIter->base.bEof
233389 return (p->rc || pIter->base.bEof);
233397 static i64 fts5MultiIterRowid(Fts5Iter *pIter){
233398 assert( pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf );
233399 return pIter->aSeg[ pIter->aFirst[1].iFirst ].iRowid;
233407 Fts5Iter *pIter,
233412 fts5MultiIterNext(p, pIter, 1, iMatch);
233413 if( fts5MultiIterEof(p, pIter) ) break;
233414 iRowid = fts5MultiIterRowid(pIter);
233415 if( pIter->bRev==0 && iRowid>=iMatch ) break;
233416 if( pIter->bRev!=0 && iRowid<=iMatch ) break;
233424 static const u8 *fts5MultiIterTerm(Fts5Iter *pIter, int *pn){
233425 Fts5SegIter *p = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
234001 static void fts5TrimSegments(Fts5Index *p, Fts5Iter *pIter){
234005 for(i=0; i<pIter->nSeg && p->rc==SQLITE_OK; i++){
234006 Fts5SegIter *pSeg = &pIter->aSeg[i];
234088 Fts5Iter *pIter = 0; /* Iterator to read input data */
234142 for(fts5MultiIterNew(p, pStruct, flags, 0, 0, 0, iLvl, nInput, &pIter);
234143 fts5MultiIterEof(p, pIter)==0;
234144 fts5MultiIterNext(p, pIter, 0, 0)
234146 Fts5SegIter *pSegIter = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
234151 pTerm = fts5MultiIterTerm(pIter, &nTerm);
234171 fts5WriteAppendRowid(p, &writer, fts5MultiIterRowid(pIter));
234192 assert( pIter!=0 || p->rc!=SQLITE_OK );
234193 if( fts5MultiIterEof(p, pIter) ){
234215 fts5TrimSegments(p, pIter);
234219 fts5MultiIterFree(pIter);
234674 static void fts5DoclistIterNext(Fts5DoclistIter *pIter){
234675 u8 *p = pIter->aPoslist + pIter->nSize + pIter->nPoslist;
234677 assert( pIter->aPoslist || (p==0 && pIter->aPoslist==0) );
234678 if( p>=pIter->aEof ){
234679 pIter->aPoslist = 0;
234684 pIter->iRowid += iDelta;
234689 pIter->nSize = fts5GetVarint32(p, nPos);
234690 pIter->nPoslist = (nPos>>1);
234692 pIter->nPoslist = ((int)(p[0])) >> 1;
234693 pIter->nSize = 1;
234696 pIter->aPoslist = p;
234697 if( &pIter->aPoslist[pIter->nPoslist]>pIter->aEof ){
234698 pIter->aPoslist = 0;
234705 Fts5DoclistIter *pIter
234707 memset(pIter, 0, sizeof(*pIter));
234709 pIter->aPoslist = pBuf->p;
234710 pIter->aEof = &pBuf->p[pBuf->n];
234711 fts5DoclistIterNext(pIter);
235434 Fts5Iter *pIter = (Fts5Iter*)pIndexIter;
235435 assert( pIter->pIndex->rc==SQLITE_OK );
235436 fts5MultiIterNext(pIter->pIndex, pIter, 0, 0);
235437 return fts5IndexReturn(pIter->pIndex);
235444 Fts5Iter *pIter = (Fts5Iter*)pIndexIter;
235445 Fts5Index *p = pIter->pIndex;
235447 assert( pIter->pIndex->rc==SQLITE_OK );
235449 fts5MultiIterNext(p, pIter, 0, 0);
235451 Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
235455 pIter->base.bEof = 1;
235459 return fts5IndexReturn(pIter->pIndex);
235468 Fts5Iter *pIter = (Fts5Iter*)pIndexIter;
235469 fts5MultiIterNextFrom(pIter->pIndex, pIter, iMatch);
235470 return fts5IndexReturn(pIter->pIndex);
235489 Fts5Iter *pIter = (Fts5Iter*)pIndexIter;
235490 Fts5Index *pIndex = pIter->pIndex;
235491 fts5MultiIterFree(pIter);
235656 Fts5IndexIter *pIter = 0;
235657 int rc = sqlite3Fts5IndexQuery(p, z, n, flags, 0, &pIter);
235659 while( rc==SQLITE_OK && ALWAYS(pIter!=0) && 0==sqlite3Fts5IterEof(pIter) ){
235660 i64 rowid = pIter->iRowid;
235666 for(sqlite3Fts5PoslistReaderInit(pIter->pData, pIter->nData, &sReader);
235676 rc = sqlite3Fts5IterNext(pIter);
235679 sqlite3Fts5IterClose(pIter);
236022 Fts5Iter *pIter; /* Used to iterate through entire index */
236061 for(fts5MultiIterNew(p, pStruct, flags, 0, 0, 0, -1, 0, &pIter);
236062 fts5MultiIterEof(p, pIter)==0;
236063 fts5MultiIterNext(p, pIter, 0, 0)
236068 i64 iRowid = fts5MultiIterRowid(pIter);
236069 char *z = (char*)fts5MultiIterTerm(pIter, &n);
236076 if( 0==fts5MultiIterIsEmpty(p, pIter) ){
236081 fts5SegiterPoslist(p, &pIter->aSeg[pIter->aFirst[1].iFirst], 0, &poslist);
236092 fts5MultiIterFree(pIter);
238770 Fts5PhraseIter *pIter,
238774 if( pIter->a>=pIter->b ){
238779 pIter->a += fts5GetVarint32(pIter->a, iVal);
238781 pIter->a += fts5GetVarint32(pIter->a, iVal);
238784 pIter->a += fts5GetVarint32(pIter->a, iVal);
238793 Fts5PhraseIter *pIter,
238798 int rc = fts5CsrPoslist(pCsr, iPhrase, &pIter->a, &n);
238800 assert( pIter->a || n==0 );
238801 pIter->b = (pIter->a ? &pIter->a[n] : 0);
238804 fts5ApiPhraseNext(pCtx, pIter, piCol, piOff);
238811 Fts5PhraseIter *pIter,
238818 if( pIter->a>=pIter->b ){
238822 pIter->a += fts5GetVarint32(&pIter->a[0], iIncr);
238828 if( pIter->a>=pIter->b ){
238832 if( pIter->a[0]==0x01 ) break;
238833 pIter->a += fts5GetVarint32(pIter->a, dummy);
238835 pIter->a += 1 + fts5GetVarint32(&pIter->a[1], *piCol);
238842 Fts5PhraseIter *pIter,
238855 pIter->a = &pSorter->aPoslist[i1];
238857 rc = sqlite3Fts5ExprPhraseCollist(pCsr->pExpr, iPhrase, &pIter->a, &n);
238860 assert( pIter->a || n==0 );
238861 pIter->b = (pIter->a ? &pIter->a[n] : 0);
238863 fts5ApiPhraseNextColumn(pCtx, pIter, piCol);
238867 rc = fts5CsrPoslist(pCsr, iPhrase, &pIter->a, &n);
238869 assert( pIter->a || n==0 );
238870 pIter->b = (pIter->a ? &pIter->a[n] : 0);
238873 }else if( pIter->a[0]==0x01 ){
238874 pIter->a += 1 + fts5GetVarint32(&pIter->a[1], *piCol);
243313 Fts5IndexIter *pIter; /* Term/rowid iterator object */
243647 sqlite3Fts5IterClose(pCsr->pIter);
243650 pCsr->pIter = 0;
243673 if( sqlite3Fts5IterEof(pCsr->pIter) ){
243678 zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
243695 Fts5IndexIter *pIter = pCsr->pIter;
243699 assert( sqlite3Fts5IterEof(pIter)==0 );
243702 || sqlite3Fts5PoslistNext64(pIter->pData, pIter->nData, po, pp)
243707 rc = sqlite3Fts5IterNextScan(pCsr->pIter);
243745 if( sqlite3Fts5IterEof(pCsr->pIter) ){
243751 zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
243774 pPos = pCsr->pIter->pData;
243775 nPos = pCsr->pIter->nData;
243823 rc = sqlite3Fts5IterNextScan(pCsr->pIter);
243828 zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
243834 if( sqlite3Fts5IterEof(pCsr->pIter) ) break;
243904 rc = sqlite3Fts5IndexQuery(pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
243968 sqlite3_result_int64(pCtx, pCsr->pIter->iRowid);