| | @@ -1186,11 +1186,11 @@ |
| 1186 | 1186 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1187 | 1187 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1188 | 1188 | */ |
| 1189 | 1189 | #define SQLITE_VERSION "3.36.0" |
| 1190 | 1190 | #define SQLITE_VERSION_NUMBER 3036000 |
| 1191 | | -#define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e1580e16" |
| 1191 | +#define SQLITE_SOURCE_ID "2021-04-28 17:37:26 65ec39f0f092fe29e1d4e9e96cf07a73d2ef7ce2c41b6f1cd3ab23546ada0e67" |
| 1192 | 1192 | |
| 1193 | 1193 | /* |
| 1194 | 1194 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1195 | 1195 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1196 | 1196 | ** |
| | @@ -10607,10 +10607,19 @@ |
| 10607 | 10607 | ** callback was invoked as a result of a direct insert, update, or delete |
| 10608 | 10608 | ** operation; or 1 for inserts, updates, or deletes invoked by top-level |
| 10609 | 10609 | ** triggers; or 2 for changes resulting from triggers called by top-level |
| 10610 | 10610 | ** triggers; and so forth. |
| 10611 | 10611 | ** |
| 10612 | +** When the [sqlite3_blob_write()] API is used to update a blob column, |
| 10613 | +** the pre-update hook is invoked with SQLITE_DELETE. This is because the |
| 10614 | +** in this case the new values are not available. In this case, when a |
| 10615 | +** callback made with op==SQLITE_DELETE is actuall a write using the |
| 10616 | +** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns |
| 10617 | +** the index of the column being written. In other cases, where the |
| 10618 | +** pre-update hook is being invoked for some other reason, including a |
| 10619 | +** regular DELETE, sqlite3_preupdate_blobwrite() returns -1. |
| 10620 | +** |
| 10612 | 10621 | ** See also: [sqlite3_update_hook()] |
| 10613 | 10622 | */ |
| 10614 | 10623 | #if defined(SQLITE_ENABLE_PREUPDATE_HOOK) |
| 10615 | 10624 | SQLITE_API void *sqlite3_preupdate_hook( |
| 10616 | 10625 | sqlite3 *db, |
| | @@ -10627,10 +10636,11 @@ |
| 10627 | 10636 | ); |
| 10628 | 10637 | SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **); |
| 10629 | 10638 | SQLITE_API int sqlite3_preupdate_count(sqlite3 *); |
| 10630 | 10639 | SQLITE_API int sqlite3_preupdate_depth(sqlite3 *); |
| 10631 | 10640 | SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **); |
| 10641 | +SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *); |
| 10632 | 10642 | #endif |
| 10633 | 10643 | |
| 10634 | 10644 | /* |
| 10635 | 10645 | ** CAPI3REF: Low-level system error code |
| 10636 | 10646 | ** METHOD: sqlite3 |
| | @@ -11167,10 +11177,41 @@ |
| 11167 | 11177 | ** are attached is closed. Refer to the documentation for |
| 11168 | 11178 | ** [sqlite3session_create()] for details. |
| 11169 | 11179 | */ |
| 11170 | 11180 | SQLITE_API void sqlite3session_delete(sqlite3_session *pSession); |
| 11171 | 11181 | |
| 11182 | +/* |
| 11183 | +** CAPIREF: Conigure a Session Object |
| 11184 | +** METHOD: sqlite3_session |
| 11185 | +** |
| 11186 | +** This method is used to configure a session object after it has been |
| 11187 | +** created. At present the only valid value for the second parameter is |
| 11188 | +** [SQLITE_SESSION_OBJCONFIG_SIZE]. |
| 11189 | +*/ |
| 11190 | +SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg); |
| 11191 | + |
| 11192 | +/* |
| 11193 | +** CAPI3REF: Arguments for sqlite3session_object_config() |
| 11194 | +** |
| 11195 | +** The following values may passed as the the 4th parameter to |
| 11196 | +** [sqlite3session_object_config]. |
| 11197 | +** |
| 11198 | +** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd> |
| 11199 | +** This option is used to set, clear or query the flag that enables |
| 11200 | +** the [sqlite3session_changeset_size()] API. Because it imposes some |
| 11201 | +** computational overhead, this API is disabled by default. Argument |
| 11202 | +** pArg must point to a value of type (int). If the value is initially |
| 11203 | +** 0, then the sqlite3session_changeset_size() API is disabled. If it |
| 11204 | +** is greater than 0, then the same API is enabled. Or, if the initial |
| 11205 | +** value is less than zero, no change is made. In all cases the (int) |
| 11206 | +** variable is set to 1 if the sqlite3session_changeset_size() API is |
| 11207 | +** enabled following the current call, or 0 otherwise. |
| 11208 | +** |
| 11209 | +** It is an error (SQLITE_MISUSE) to attempt to modify this setting after |
| 11210 | +** the first table has been attached to the session object. |
| 11211 | +*/ |
| 11212 | +#define SQLITE_SESSION_OBJCONFIG_SIZE 1 |
| 11172 | 11213 | |
| 11173 | 11214 | /* |
| 11174 | 11215 | ** CAPI3REF: Enable Or Disable A Session Object |
| 11175 | 11216 | ** METHOD: sqlite3_session |
| 11176 | 11217 | ** |
| | @@ -11411,10 +11452,26 @@ |
| 11411 | 11452 | sqlite3_session *pSession, /* Session object */ |
| 11412 | 11453 | int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */ |
| 11413 | 11454 | void **ppChangeset /* OUT: Buffer containing changeset */ |
| 11414 | 11455 | ); |
| 11415 | 11456 | |
| 11457 | +/* |
| 11458 | +** CAPI3REF: Return An Upper-limit For The Size Of The Changeset |
| 11459 | +** METHOD: sqlite3session_changeset_size() |
| 11460 | +** |
| 11461 | +** By default, this function always returns 0. For it to return |
| 11462 | +** a useful result, the sqlite3_session object must have been configured |
| 11463 | +** to enable this API using [sqlite3session_object_config()] with the |
| 11464 | +** SQLITE_SESSION_OBJCONFIG_SIZE verb. |
| 11465 | +** |
| 11466 | +** When enabled, this function returns an upper limit, in bytes, for the size |
| 11467 | +** of the changeset that might be produced if sqlite3session_changeset() were |
| 11468 | +** called. The final changeset size might be equal to or smaller than the |
| 11469 | +** size in bytes returned by this function. |
| 11470 | +*/ |
| 11471 | +SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession); |
| 11472 | + |
| 11416 | 11473 | /* |
| 11417 | 11474 | ** CAPI3REF: Load The Difference Between Tables Into A Session |
| 11418 | 11475 | ** METHOD: sqlite3_session |
| 11419 | 11476 | ** |
| 11420 | 11477 | ** If it is not already attached to the session object passed as the first |
| | @@ -17724,10 +17781,11 @@ |
| 17724 | 17781 | #define TF_OOOHidden 0x0400 /* Out-of-Order hidden columns */ |
| 17725 | 17782 | #define TF_HasNotNull 0x0800 /* Contains NOT NULL constraints */ |
| 17726 | 17783 | #define TF_Shadow 0x1000 /* True for a shadow table */ |
| 17727 | 17784 | #define TF_HasStat4 0x2000 /* STAT4 info available for this table */ |
| 17728 | 17785 | #define TF_Ephemeral 0x4000 /* An ephemeral table */ |
| 17786 | +#define TF_Eponymous 0x8000 /* An eponymous virtual table */ |
| 17729 | 17787 | |
| 17730 | 17788 | /* |
| 17731 | 17789 | ** Test to see whether or not a table is a virtual table. This is |
| 17732 | 17790 | ** done as a macro so that it will be optimized out when virtual |
| 17733 | 17791 | ** table support is omitted from the build. |
| | @@ -18553,11 +18611,11 @@ |
| 18553 | 18611 | Upsert *pUpsert; /* ON CONFLICT clause information from an upsert */ |
| 18554 | 18612 | int iBaseReg; /* For TK_REGISTER when parsing RETURNING */ |
| 18555 | 18613 | } uNC; |
| 18556 | 18614 | NameContext *pNext; /* Next outer name context. NULL for outermost */ |
| 18557 | 18615 | int nRef; /* Number of names resolved by this context */ |
| 18558 | | - int nErr; /* Number of errors encountered while resolving names */ |
| 18616 | + int nNcErr; /* Number of errors encountered while resolving names */ |
| 18559 | 18617 | int ncFlags; /* Zero or more NC_* flags defined below */ |
| 18560 | 18618 | Select *pWinSelect; /* SELECT statement for any window functions */ |
| 18561 | 18619 | }; |
| 18562 | 18620 | |
| 18563 | 18621 | /* |
| | @@ -18586,10 +18644,11 @@ |
| 18586 | 18644 | #define NC_AllowWin 0x04000 /* Window functions are allowed here */ |
| 18587 | 18645 | #define NC_HasWin 0x08000 /* One or more window functions seen */ |
| 18588 | 18646 | #define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */ |
| 18589 | 18647 | #define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */ |
| 18590 | 18648 | #define NC_FromDDL 0x40000 /* SQL text comes from sqlite_schema */ |
| 18649 | +#define NC_NoSelect 0x80000 /* Do not descend into sub-selects */ |
| 18591 | 18650 | |
| 18592 | 18651 | /* |
| 18593 | 18652 | ** An instance of the following object describes a single ON CONFLICT |
| 18594 | 18653 | ** clause in an upsert. |
| 18595 | 18654 | ** |
| | @@ -19367,10 +19426,11 @@ |
| 19367 | 19426 | SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker*, Expr*); |
| 19368 | 19427 | SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker*, Select*); |
| 19369 | 19428 | SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker*, Select*); |
| 19370 | 19429 | SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker*,Select*); |
| 19371 | 19430 | SQLITE_PRIVATE void sqlite3WalkerDepthDecrease(Walker*,Select*); |
| 19431 | +SQLITE_PRIVATE void sqlite3WalkWinDefnDummyCallback(Walker*,Select*); |
| 19372 | 19432 | |
| 19373 | 19433 | #ifdef SQLITE_DEBUG |
| 19374 | 19434 | SQLITE_PRIVATE void sqlite3SelectWalkAssert2(Walker*, Select*); |
| 19375 | 19435 | #endif |
| 19376 | 19436 | |
| | @@ -21500,10 +21560,11 @@ |
| 21500 | 21560 | u8 *aRecord; /* old.* database record */ |
| 21501 | 21561 | KeyInfo keyinfo; |
| 21502 | 21562 | UnpackedRecord *pUnpacked; /* Unpacked version of aRecord[] */ |
| 21503 | 21563 | UnpackedRecord *pNewUnpacked; /* Unpacked version of new.* record */ |
| 21504 | 21564 | int iNewReg; /* Register for new.* values */ |
| 21565 | + int iBlobWrite; /* Value returned by preupdate_blobwrite() */ |
| 21505 | 21566 | i64 iKey1; /* First key value passed to hook */ |
| 21506 | 21567 | i64 iKey2; /* Second key value passed to hook */ |
| 21507 | 21568 | Mem *aNew; /* Array of new.* values */ |
| 21508 | 21569 | Table *pTab; /* Schema object being upated */ |
| 21509 | 21570 | Index *pPk; /* PK index if pTab is WITHOUT ROWID */ |
| | @@ -21588,11 +21649,12 @@ |
| 21588 | 21649 | #endif |
| 21589 | 21650 | SQLITE_PRIVATE void sqlite3VdbeFrameMemDel(void*); /* Destructor on Mem */ |
| 21590 | 21651 | SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); /* Actually deletes the Frame */ |
| 21591 | 21652 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *); |
| 21592 | 21653 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 21593 | | -SQLITE_PRIVATE void sqlite3VdbePreUpdateHook(Vdbe*,VdbeCursor*,int,const char*,Table*,i64,int); |
| 21654 | +SQLITE_PRIVATE void sqlite3VdbePreUpdateHook( |
| 21655 | + Vdbe*,VdbeCursor*,int,const char*,Table*,i64,int,int); |
| 21594 | 21656 | #endif |
| 21595 | 21657 | SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p); |
| 21596 | 21658 | |
| 21597 | 21659 | SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, int, VdbeCursor *); |
| 21598 | 21660 | SQLITE_PRIVATE void sqlite3VdbeSorterReset(sqlite3 *, VdbeSorter *); |
| | @@ -29932,10 +29994,11 @@ |
| 29932 | 29994 | for(i=0; i<pSrc->nSrc; i++){ |
| 29933 | 29995 | const SrcItem *pItem = &pSrc->a[i]; |
| 29934 | 29996 | StrAccum x; |
| 29935 | 29997 | char zLine[100]; |
| 29936 | 29998 | sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); |
| 29999 | + x.printfFlags |= SQLITE_PRINTF_INTERNAL; |
| 29937 | 30000 | sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem); |
| 29938 | 30001 | if( pItem->pTab ){ |
| 29939 | 30002 | sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx", |
| 29940 | 30003 | pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed); |
| 29941 | 30004 | } |
| | @@ -48518,11 +48581,11 @@ |
| 48518 | 48581 | return SQLITE_FULL; |
| 48519 | 48582 | } |
| 48520 | 48583 | newSz *= 2; |
| 48521 | 48584 | if( newSz>p->szMax ) newSz = p->szMax; |
| 48522 | 48585 | pNew = sqlite3Realloc(p->aData, newSz); |
| 48523 | | - if( pNew==0 ) return SQLITE_NOMEM; |
| 48586 | + if( pNew==0 ) return SQLITE_IOERR_NOMEM; |
| 48524 | 48587 | p->aData = pNew; |
| 48525 | 48588 | p->szAlloc = newSz; |
| 48526 | 48589 | return SQLITE_OK; |
| 48527 | 48590 | } |
| 48528 | 48591 | |
| | @@ -58067,11 +58130,11 @@ |
| 58067 | 58130 | |
| 58068 | 58131 | if( pPager->errCode ) return pPager->errCode; |
| 58069 | 58132 | assert( pPager->eState>=PAGER_READER && pPager->eState<PAGER_ERROR ); |
| 58070 | 58133 | pPager->subjInMemory = (u8)subjInMemory; |
| 58071 | 58134 | |
| 58072 | | - if( ALWAYS(pPager->eState==PAGER_READER) ){ |
| 58135 | + if( pPager->eState==PAGER_READER ){ |
| 58073 | 58136 | assert( pPager->pInJournal==0 ); |
| 58074 | 58137 | |
| 58075 | 58138 | if( pagerUseWal(pPager) ){ |
| 58076 | 58139 | /* If the pager is configured to use locking_mode=exclusive, and an |
| 58077 | 58140 | ** exclusive lock on the database is not already held, obtain it now. |
| | @@ -66488,10 +66551,11 @@ |
| 66488 | 66551 | unsigned char *data; /* The page data */ |
| 66489 | 66552 | unsigned char *temp; /* Temp area for cell content */ |
| 66490 | 66553 | unsigned char *src; /* Source of content */ |
| 66491 | 66554 | int iCellFirst; /* First allowable cell index */ |
| 66492 | 66555 | int iCellLast; /* Last possible cell index */ |
| 66556 | + int iCellStart; /* First cell offset in input */ |
| 66493 | 66557 | |
| 66494 | 66558 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 66495 | 66559 | assert( pPage->pBt!=0 ); |
| 66496 | 66560 | assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE ); |
| 66497 | 66561 | assert( pPage->nOverflow==0 ); |
| | @@ -66529,11 +66593,11 @@ |
| 66529 | 66593 | if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage); |
| 66530 | 66594 | sz2 = get2byte(&data[iFree2+2]); |
| 66531 | 66595 | if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage); |
| 66532 | 66596 | memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz)); |
| 66533 | 66597 | sz += sz2; |
| 66534 | | - }else if( NEVER(iFree+sz>usableSize) ){ |
| 66598 | + }else if( iFree+sz>usableSize ){ |
| 66535 | 66599 | return SQLITE_CORRUPT_PAGE(pPage); |
| 66536 | 66600 | } |
| 66537 | 66601 | |
| 66538 | 66602 | cbrk = top+sz; |
| 66539 | 66603 | assert( cbrk+(iFree-top) <= usableSize ); |
| | @@ -66548,38 +66612,37 @@ |
| 66548 | 66612 | } |
| 66549 | 66613 | } |
| 66550 | 66614 | |
| 66551 | 66615 | cbrk = usableSize; |
| 66552 | 66616 | iCellLast = usableSize - 4; |
| 66617 | + iCellStart = get2byte(&data[hdr+5]); |
| 66553 | 66618 | for(i=0; i<nCell; i++){ |
| 66554 | 66619 | u8 *pAddr; /* The i-th cell pointer */ |
| 66555 | 66620 | pAddr = &data[cellOffset + i*2]; |
| 66556 | 66621 | pc = get2byte(pAddr); |
| 66557 | 66622 | testcase( pc==iCellFirst ); |
| 66558 | 66623 | testcase( pc==iCellLast ); |
| 66559 | 66624 | /* These conditions have already been verified in btreeInitPage() |
| 66560 | 66625 | ** if PRAGMA cell_size_check=ON. |
| 66561 | 66626 | */ |
| 66562 | | - if( pc<iCellFirst || pc>iCellLast ){ |
| 66627 | + if( pc<iCellStart || pc>iCellLast ){ |
| 66563 | 66628 | return SQLITE_CORRUPT_PAGE(pPage); |
| 66564 | 66629 | } |
| 66565 | | - assert( pc>=iCellFirst && pc<=iCellLast ); |
| 66630 | + assert( pc>=iCellStart && pc<=iCellLast ); |
| 66566 | 66631 | size = pPage->xCellSize(pPage, &src[pc]); |
| 66567 | 66632 | cbrk -= size; |
| 66568 | | - if( cbrk<iCellFirst || pc+size>usableSize ){ |
| 66633 | + if( cbrk<iCellStart || pc+size>usableSize ){ |
| 66569 | 66634 | return SQLITE_CORRUPT_PAGE(pPage); |
| 66570 | 66635 | } |
| 66571 | | - assert( cbrk+size<=usableSize && cbrk>=iCellFirst ); |
| 66636 | + assert( cbrk+size<=usableSize && cbrk>=iCellStart ); |
| 66572 | 66637 | testcase( cbrk+size==usableSize ); |
| 66573 | 66638 | testcase( pc+size==usableSize ); |
| 66574 | 66639 | put2byte(pAddr, cbrk); |
| 66575 | 66640 | if( temp==0 ){ |
| 66576 | | - int x; |
| 66577 | 66641 | if( cbrk==pc ) continue; |
| 66578 | 66642 | temp = sqlite3PagerTempSpace(pPage->pBt->pPager); |
| 66579 | | - x = get2byte(&data[hdr+5]); |
| 66580 | | - memcpy(&temp[x], &data[x], (cbrk+size) - x); |
| 66643 | + memcpy(&temp[iCellStart], &data[iCellStart], (cbrk+size) - iCellStart); |
| 66581 | 66644 | src = temp; |
| 66582 | 66645 | } |
| 66583 | 66646 | memcpy(&data[cbrk], &src[pc], size); |
| 66584 | 66647 | } |
| 66585 | 66648 | data[hdr+7] = 0; |
| | @@ -72055,11 +72118,11 @@ |
| 72055 | 72118 | pData = pEnd; |
| 72056 | 72119 | while( 1/*exit by break*/ ){ |
| 72057 | 72120 | u8 *pCell = pCArray->apCell[i]; |
| 72058 | 72121 | u16 sz = pCArray->szCell[i]; |
| 72059 | 72122 | assert( sz>0 ); |
| 72060 | | - if( SQLITE_WITHIN(pCell,aData,pEnd) ){ |
| 72123 | + if( SQLITE_WITHIN(pCell,aData+j,pEnd) ){ |
| 72061 | 72124 | if( ((uptr)(pCell+sz))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT; |
| 72062 | 72125 | pCell = &pTmp[pCell - aData]; |
| 72063 | 72126 | }else if( (uptr)(pCell+sz)>(uptr)pSrcEnd |
| 72064 | 72127 | && (uptr)(pCell)<(uptr)pSrcEnd |
| 72065 | 72128 | ){ |
| | @@ -72068,13 +72131,12 @@ |
| 72068 | 72131 | |
| 72069 | 72132 | pData -= sz; |
| 72070 | 72133 | put2byte(pCellptr, (pData - aData)); |
| 72071 | 72134 | pCellptr += 2; |
| 72072 | 72135 | if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT; |
| 72073 | | - memcpy(pData, pCell, sz); |
| 72136 | + memmove(pData, pCell, sz); |
| 72074 | 72137 | assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB ); |
| 72075 | | - testcase( sz!=pPg->xCellSize(pPg,pCell) ) |
| 72076 | 72138 | i++; |
| 72077 | 72139 | if( i>=iEnd ) break; |
| 72078 | 72140 | if( pCArray->ixNx[k]<=i ){ |
| 72079 | 72141 | k++; |
| 72080 | 72142 | pSrcEnd = pCArray->apEnd[k]; |
| | @@ -72862,11 +72924,11 @@ |
| 72862 | 72924 | b.apCell[b.nCell] = pTemp+leafCorrection; |
| 72863 | 72925 | assert( leafCorrection==0 || leafCorrection==4 ); |
| 72864 | 72926 | b.szCell[b.nCell] = b.szCell[b.nCell] - leafCorrection; |
| 72865 | 72927 | if( !pOld->leaf ){ |
| 72866 | 72928 | assert( leafCorrection==0 ); |
| 72867 | | - assert( pOld->hdrOffset==0 ); |
| 72929 | + assert( pOld->hdrOffset==0 || CORRUPT_DB ); |
| 72868 | 72930 | /* The right pointer of the child page pOld becomes the left |
| 72869 | 72931 | ** pointer of the divider cell */ |
| 72870 | 72932 | memcpy(b.apCell[b.nCell], &pOld->aData[8], 4); |
| 72871 | 72933 | }else{ |
| 72872 | 72934 | assert( leafCorrection==4 ); |
| | @@ -73770,10 +73832,18 @@ |
| 73770 | 73832 | ** not to clear the cursor here. |
| 73771 | 73833 | */ |
| 73772 | 73834 | if( pCur->curFlags & BTCF_Multiple ){ |
| 73773 | 73835 | rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur); |
| 73774 | 73836 | if( rc ) return rc; |
| 73837 | + if( loc && pCur->iPage<0 ){ |
| 73838 | + /* This can only happen if the schema is corrupt such that there is more |
| 73839 | + ** than one table or index with the same root page as used by the cursor. |
| 73840 | + ** Which can only happen if the SQLITE_NoSchemaError flag was set when |
| 73841 | + ** the schema was loaded. This cannot be asserted though, as a user might |
| 73842 | + ** set the flag, load the schema, and then unset the flag. */ |
| 73843 | + return SQLITE_CORRUPT_BKPT; |
| 73844 | + } |
| 73775 | 73845 | } |
| 73776 | 73846 | |
| 73777 | 73847 | if( pCur->pKeyInfo==0 ){ |
| 73778 | 73848 | assert( pX->pKey==0 ); |
| 73779 | 73849 | /* If this is an insert into a table b-tree, invalidate any incrblob |
| | @@ -73857,21 +73927,20 @@ |
| 73857 | 73927 | x2.nData = pX->nKey; |
| 73858 | 73928 | x2.nZero = 0; |
| 73859 | 73929 | return btreeOverwriteCell(pCur, &x2); |
| 73860 | 73930 | } |
| 73861 | 73931 | } |
| 73862 | | - |
| 73863 | 73932 | } |
| 73864 | 73933 | assert( pCur->eState==CURSOR_VALID |
| 73865 | 73934 | || (pCur->eState==CURSOR_INVALID && loc) |
| 73866 | 73935 | || CORRUPT_DB ); |
| 73867 | 73936 | |
| 73868 | 73937 | pPage = pCur->pPage; |
| 73869 | 73938 | assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) ); |
| 73870 | 73939 | assert( pPage->leaf || !pPage->intKey ); |
| 73871 | 73940 | if( pPage->nFree<0 ){ |
| 73872 | | - if( pCur->eState>CURSOR_INVALID ){ |
| 73941 | + if( NEVER(pCur->eState>CURSOR_INVALID) ){ |
| 73873 | 73942 | rc = SQLITE_CORRUPT_BKPT; |
| 73874 | 73943 | }else{ |
| 73875 | 73944 | rc = btreeComputeFreeSpace(pPage); |
| 73876 | 73945 | } |
| 73877 | 73946 | if( rc ) return rc; |
| | @@ -74148,11 +74217,12 @@ |
| 74148 | 74217 | assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) ); |
| 74149 | 74218 | assert( !hasReadConflicts(p, pCur->pgnoRoot) ); |
| 74150 | 74219 | assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 ); |
| 74151 | 74220 | if( pCur->eState==CURSOR_REQUIRESEEK ){ |
| 74152 | 74221 | rc = btreeRestoreCursorPosition(pCur); |
| 74153 | | - if( rc ) return rc; |
| 74222 | + assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID ); |
| 74223 | + if( rc || pCur->eState!=CURSOR_VALID ) return rc; |
| 74154 | 74224 | } |
| 74155 | 74225 | assert( CORRUPT_DB || pCur->eState==CURSOR_VALID ); |
| 74156 | 74226 | |
| 74157 | 74227 | iCellDepth = pCur->iPage; |
| 74158 | 74228 | iCellIdx = pCur->ix; |
| | @@ -83652,11 +83722,12 @@ |
| 83652 | 83722 | VdbeCursor *pCsr, /* Cursor to grab old.* values from */ |
| 83653 | 83723 | int op, /* SQLITE_INSERT, UPDATE or DELETE */ |
| 83654 | 83724 | const char *zDb, /* Database name */ |
| 83655 | 83725 | Table *pTab, /* Modified table */ |
| 83656 | 83726 | i64 iKey1, /* Initial key value */ |
| 83657 | | - int iReg /* Register for new.* record */ |
| 83727 | + int iReg, /* Register for new.* record */ |
| 83728 | + int iBlobWrite |
| 83658 | 83729 | ){ |
| 83659 | 83730 | sqlite3 *db = v->db; |
| 83660 | 83731 | i64 iKey2; |
| 83661 | 83732 | PreUpdate preupdate; |
| 83662 | 83733 | const char *zTbl = pTab->zName; |
| | @@ -83688,10 +83759,11 @@ |
| 83688 | 83759 | preupdate.keyinfo.nKeyField = pTab->nCol; |
| 83689 | 83760 | preupdate.keyinfo.aSortFlags = (u8*)&fakeSortOrder; |
| 83690 | 83761 | preupdate.iKey1 = iKey1; |
| 83691 | 83762 | preupdate.iKey2 = iKey2; |
| 83692 | 83763 | preupdate.pTab = pTab; |
| 83764 | + preupdate.iBlobWrite = iBlobWrite; |
| 83693 | 83765 | |
| 83694 | 83766 | db->pPreUpdate = &preupdate; |
| 83695 | 83767 | db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2); |
| 83696 | 83768 | db->pPreUpdate = 0; |
| 83697 | 83769 | sqlite3DbFree(db, preupdate.aRecord); |
| | @@ -85613,10 +85685,21 @@ |
| 85613 | 85685 | SQLITE_API int sqlite3_preupdate_depth(sqlite3 *db){ |
| 85614 | 85686 | PreUpdate *p = db->pPreUpdate; |
| 85615 | 85687 | return (p ? p->v->nFrame : 0); |
| 85616 | 85688 | } |
| 85617 | 85689 | #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 85690 | + |
| 85691 | +#ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 85692 | +/* |
| 85693 | +** This function is designed to be called from within a pre-update callback |
| 85694 | +** only. |
| 85695 | +*/ |
| 85696 | +SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *db){ |
| 85697 | + PreUpdate *p = db->pPreUpdate; |
| 85698 | + return (p ? p->iBlobWrite : -1); |
| 85699 | +} |
| 85700 | +#endif |
| 85618 | 85701 | |
| 85619 | 85702 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 85620 | 85703 | /* |
| 85621 | 85704 | ** This function is called from within a pre-update callback to retrieve |
| 85622 | 85705 | ** a field of the row currently being updated or inserted. |
| | @@ -86393,11 +86476,14 @@ |
| 86393 | 86476 | static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){ |
| 86394 | 86477 | int rc; |
| 86395 | 86478 | sqlite3_int64 ix; |
| 86396 | 86479 | assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 ); |
| 86397 | 86480 | assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 ); |
| 86398 | | - ExpandBlob(pMem); |
| 86481 | + if( ExpandBlob(pMem) ){ |
| 86482 | + pMem->u.i = 0; |
| 86483 | + return MEM_Int; |
| 86484 | + } |
| 86399 | 86485 | rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc); |
| 86400 | 86486 | if( rc<=0 ){ |
| 86401 | 86487 | if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){ |
| 86402 | 86488 | pMem->u.i = ix; |
| 86403 | 86489 | return MEM_Int; |
| | @@ -91126,11 +91212,11 @@ |
| 91126 | 91212 | |
| 91127 | 91213 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 91128 | 91214 | /* Invoke the pre-update hook, if any */ |
| 91129 | 91215 | if( pTab ){ |
| 91130 | 91216 | if( db->xPreUpdateCallback && !(pOp->p5 & OPFLAG_ISUPDATE) ){ |
| 91131 | | - sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey,pOp->p2); |
| 91217 | + sqlite3VdbePreUpdateHook(p,pC,SQLITE_INSERT,zDb,pTab,x.nKey,pOp->p2,-1); |
| 91132 | 91218 | } |
| 91133 | 91219 | if( db->xUpdateCallback==0 || pTab->aCol==0 ){ |
| 91134 | 91220 | /* Prevent post-update hook from running in cases when it should not */ |
| 91135 | 91221 | pTab = 0; |
| 91136 | 91222 | } |
| | @@ -91286,11 +91372,11 @@ |
| 91286 | 91372 | || (aMem[pOp->p3].flags & MEM_Int) |
| 91287 | 91373 | ); |
| 91288 | 91374 | sqlite3VdbePreUpdateHook(p, pC, |
| 91289 | 91375 | (opflags & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_DELETE, |
| 91290 | 91376 | zDb, pTab, pC->movetoTarget, |
| 91291 | | - pOp->p3 |
| 91377 | + pOp->p3, -1 |
| 91292 | 91378 | ); |
| 91293 | 91379 | } |
| 91294 | 91380 | if( opflags & OPFLAG_ISNOOP ) break; |
| 91295 | 91381 | #endif |
| 91296 | 91382 | |
| | @@ -92355,11 +92441,11 @@ |
| 92355 | 92441 | } |
| 92356 | 92442 | #endif |
| 92357 | 92443 | |
| 92358 | 92444 | iDb = pOp->p1; |
| 92359 | 92445 | assert( iDb>=0 && iDb<db->nDb ); |
| 92360 | | - assert( DbHasProperty(db, iDb, DB_SchemaLoaded) ); |
| 92446 | + assert( DbHasProperty(db, iDb, DB_SchemaLoaded) || db->mallocFailed ); |
| 92361 | 92447 | |
| 92362 | 92448 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 92363 | 92449 | if( pOp->p4.z==0 ){ |
| 92364 | 92450 | sqlite3SchemaClear(db->aDb[iDb].pSchema); |
| 92365 | 92451 | db->mDbFlags &= ~DBFLAG_SchemaKnownOk; |
| | @@ -94715,11 +94801,11 @@ |
| 94715 | 94801 | ** anyhow. |
| 94716 | 94802 | */ |
| 94717 | 94803 | sqlite3_int64 iKey; |
| 94718 | 94804 | iKey = sqlite3BtreeIntegerKey(p->pCsr); |
| 94719 | 94805 | sqlite3VdbePreUpdateHook( |
| 94720 | | - v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1 |
| 94806 | + v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1, p->iCol |
| 94721 | 94807 | ); |
| 94722 | 94808 | } |
| 94723 | 94809 | #endif |
| 94724 | 94810 | |
| 94725 | 94811 | rc = xCall(p->pCsr, iOffset+p->iOffset, n, z); |
| | @@ -94786,10 +94872,11 @@ |
| 94786 | 94872 | ** already been invalidated. Return SQLITE_ABORT in this case. |
| 94787 | 94873 | */ |
| 94788 | 94874 | rc = SQLITE_ABORT; |
| 94789 | 94875 | }else{ |
| 94790 | 94876 | char *zErr; |
| 94877 | + ((Vdbe*)p->pStmt)->rc = SQLITE_OK; |
| 94791 | 94878 | rc = blobSeekToRow(p, iRow, &zErr); |
| 94792 | 94879 | if( rc!=SQLITE_OK ){ |
| 94793 | 94880 | sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr); |
| 94794 | 94881 | sqlite3DbFree(db, zErr); |
| 94795 | 94882 | } |
| | @@ -98468,19 +98555,14 @@ |
| 98468 | 98555 | if( rc ) return WRC_Abort; |
| 98469 | 98556 | rc = sqlite3WalkExprList(pWalker, pWin->pPartition); |
| 98470 | 98557 | if( rc ) return WRC_Abort; |
| 98471 | 98558 | rc = sqlite3WalkExpr(pWalker, pWin->pFilter); |
| 98472 | 98559 | if( rc ) return WRC_Abort; |
| 98473 | | - |
| 98474 | | - /* The next two are purely for calls to sqlite3RenameExprUnmap() |
| 98475 | | - ** within sqlite3WindowOffsetExpr(). Because of constraints imposed |
| 98476 | | - ** by sqlite3WindowOffsetExpr(), they can never fail. The results do |
| 98477 | | - ** not matter anyhow. */ |
| 98478 | 98560 | rc = sqlite3WalkExpr(pWalker, pWin->pStart); |
| 98479 | | - if( NEVER(rc) ) return WRC_Abort; |
| 98561 | + if( rc ) return WRC_Abort; |
| 98480 | 98562 | rc = sqlite3WalkExpr(pWalker, pWin->pEnd); |
| 98481 | | - if( NEVER(rc) ) return WRC_Abort; |
| 98563 | + if( rc ) return WRC_Abort; |
| 98482 | 98564 | if( bOneOnly ) break; |
| 98483 | 98565 | } |
| 98484 | 98566 | return WRC_Continue; |
| 98485 | 98567 | } |
| 98486 | 98568 | #endif |
| | @@ -98552,10 +98634,20 @@ |
| 98552 | 98634 | if( sqlite3WalkExpr(pWalker, pItem->pExpr) ) return WRC_Abort; |
| 98553 | 98635 | } |
| 98554 | 98636 | } |
| 98555 | 98637 | return WRC_Continue; |
| 98556 | 98638 | } |
| 98639 | + |
| 98640 | +/* |
| 98641 | +** This is a no-op callback for Walker->xSelectCallback2. If this |
| 98642 | +** callback is set, then the Select->pWinDefn list is traversed. |
| 98643 | +*/ |
| 98644 | +SQLITE_PRIVATE void sqlite3WalkWinDefnDummyCallback(Walker *pWalker, Select *p){ |
| 98645 | + UNUSED_PARAMETER(pWalker); |
| 98646 | + UNUSED_PARAMETER(p); |
| 98647 | + /* No-op */ |
| 98648 | +} |
| 98557 | 98649 | |
| 98558 | 98650 | /* |
| 98559 | 98651 | ** Walk all expressions associated with SELECT statement p. Do |
| 98560 | 98652 | ** not invoke the SELECT callback on p, but do (of course) invoke |
| 98561 | 98653 | ** any expr callbacks and SELECT callbacks that come from subqueries. |
| | @@ -98566,14 +98658,16 @@ |
| 98566 | 98658 | if( sqlite3WalkExpr(pWalker, p->pWhere) ) return WRC_Abort; |
| 98567 | 98659 | if( sqlite3WalkExprList(pWalker, p->pGroupBy) ) return WRC_Abort; |
| 98568 | 98660 | if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort; |
| 98569 | 98661 | if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort; |
| 98570 | 98662 | if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort; |
| 98571 | | -#if !defined(SQLITE_OMIT_WINDOWFUNC) && !defined(SQLITE_OMIT_ALTERTABLE) |
| 98572 | | - { |
| 98573 | | - Parse *pParse = pWalker->pParse; |
| 98574 | | - if( pParse && IN_RENAME_OBJECT ){ |
| 98663 | +#if !defined(SQLITE_OMIT_WINDOWFUNC) |
| 98664 | + if( p->pWinDefn ){ |
| 98665 | + Parse *pParse; |
| 98666 | + if( pWalker->xSelectCallback2==sqlite3WalkWinDefnDummyCallback |
| 98667 | + || ((pParse = pWalker->pParse)!=0 && IN_RENAME_OBJECT) |
| 98668 | + ){ |
| 98575 | 98669 | /* The following may return WRC_Abort if there are unresolvable |
| 98576 | 98670 | ** symbols (e.g. a table that does not exist) in a window definition. */ |
| 98577 | 98671 | int rc = walkWindowList(pWalker, p->pWinDefn, 0); |
| 98578 | 98672 | return rc; |
| 98579 | 98673 | } |
| | @@ -98593,11 +98687,11 @@ |
| 98593 | 98687 | SrcList *pSrc; |
| 98594 | 98688 | int i; |
| 98595 | 98689 | SrcItem *pItem; |
| 98596 | 98690 | |
| 98597 | 98691 | pSrc = p->pSrc; |
| 98598 | | - if( pSrc ){ |
| 98692 | + if( ALWAYS(pSrc) ){ |
| 98599 | 98693 | for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){ |
| 98600 | 98694 | if( pItem->pSelect && sqlite3WalkSelect(pWalker, pItem->pSelect) ){ |
| 98601 | 98695 | return WRC_Abort; |
| 98602 | 98696 | } |
| 98603 | 98697 | if( pItem->fg.isTabFunc |
| | @@ -98767,11 +98861,14 @@ |
| 98767 | 98861 | assert( iCol>=0 && iCol<pEList->nExpr ); |
| 98768 | 98862 | pOrig = pEList->a[iCol].pExpr; |
| 98769 | 98863 | assert( pOrig!=0 ); |
| 98770 | 98864 | db = pParse->db; |
| 98771 | 98865 | pDup = sqlite3ExprDup(db, pOrig, 0); |
| 98772 | | - if( pDup!=0 ){ |
| 98866 | + if( db->mallocFailed ){ |
| 98867 | + sqlite3ExprDelete(db, pDup); |
| 98868 | + pDup = 0; |
| 98869 | + }else{ |
| 98773 | 98870 | incrAggFunctionDepth(pDup, nSubquery); |
| 98774 | 98871 | if( pExpr->op==TK_COLLATE ){ |
| 98775 | 98872 | pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken); |
| 98776 | 98873 | } |
| 98777 | 98874 | |
| | @@ -98789,14 +98886,12 @@ |
| 98789 | 98886 | assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 ); |
| 98790 | 98887 | pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken); |
| 98791 | 98888 | pExpr->flags |= EP_MemToken; |
| 98792 | 98889 | } |
| 98793 | 98890 | if( ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 98794 | | - if( pExpr->y.pWin!=0 ){ |
| 98891 | + if( ALWAYS(pExpr->y.pWin!=0) ){ |
| 98795 | 98892 | pExpr->y.pWin->pOwner = pExpr; |
| 98796 | | - }else{ |
| 98797 | | - assert( db->mallocFailed ); |
| 98798 | 98893 | } |
| 98799 | 98894 | } |
| 98800 | 98895 | sqlite3DbFree(db, pDup); |
| 98801 | 98896 | } |
| 98802 | 98897 | } |
| | @@ -99184,12 +99279,12 @@ |
| 99184 | 99279 | ** or HAVING clauses, or as part of a larger expression in the ORDER BY |
| 99185 | 99280 | ** clause is not standard SQL. This is a (goofy) SQLite extension, that |
| 99186 | 99281 | ** is supported for backwards compatibility only. Hence, we issue a warning |
| 99187 | 99282 | ** on sqlite3_log() whenever the capability is used. |
| 99188 | 99283 | */ |
| 99189 | | - if( (pNC->ncFlags & NC_UEList)!=0 |
| 99190 | | - && cnt==0 |
| 99284 | + if( cnt==0 |
| 99285 | + && (pNC->ncFlags & NC_UEList)!=0 |
| 99191 | 99286 | && zTab==0 |
| 99192 | 99287 | ){ |
| 99193 | 99288 | pEList = pNC->uNC.pEList; |
| 99194 | 99289 | assert( pEList!=0 ); |
| 99195 | 99290 | for(j=0; j<pEList->nExpr; j++){ |
| | @@ -99293,11 +99388,11 @@ |
| 99293 | 99388 | sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol); |
| 99294 | 99389 | }else{ |
| 99295 | 99390 | sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol); |
| 99296 | 99391 | } |
| 99297 | 99392 | pParse->checkSchema = 1; |
| 99298 | | - pTopNC->nErr++; |
| 99393 | + pTopNC->nNcErr++; |
| 99299 | 99394 | } |
| 99300 | 99395 | |
| 99301 | 99396 | /* If a column from a table in pSrcList is referenced, then record |
| 99302 | 99397 | ** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes |
| 99303 | 99398 | ** bit 0 to be set. Column 1 sets bit 1. And so forth. Bit 63 is |
| | @@ -99600,11 +99695,11 @@ |
| 99600 | 99695 | pExpr->iTable = exprProbability(pList->a[1].pExpr); |
| 99601 | 99696 | if( pExpr->iTable<0 ){ |
| 99602 | 99697 | sqlite3ErrorMsg(pParse, |
| 99603 | 99698 | "second argument to likelihood() must be a " |
| 99604 | 99699 | "constant between 0.0 and 1.0"); |
| 99605 | | - pNC->nErr++; |
| 99700 | + pNC->nNcErr++; |
| 99606 | 99701 | } |
| 99607 | 99702 | }else{ |
| 99608 | 99703 | /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is |
| 99609 | 99704 | ** equivalent to likelihood(X, 0.0625). |
| 99610 | 99705 | ** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is |
| | @@ -99622,11 +99717,11 @@ |
| 99622 | 99717 | int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0); |
| 99623 | 99718 | if( auth!=SQLITE_OK ){ |
| 99624 | 99719 | if( auth==SQLITE_DENY ){ |
| 99625 | 99720 | sqlite3ErrorMsg(pParse, "not authorized to use function: %s", |
| 99626 | 99721 | pDef->zName); |
| 99627 | | - pNC->nErr++; |
| 99722 | + pNC->nNcErr++; |
| 99628 | 99723 | } |
| 99629 | 99724 | pExpr->op = TK_NULL; |
| 99630 | 99725 | return WRC_Prune; |
| 99631 | 99726 | } |
| 99632 | 99727 | } |
| | @@ -99678,11 +99773,11 @@ |
| 99678 | 99773 | ); |
| 99679 | 99774 | if( pDef && pDef->xValue==0 && pWin ){ |
| 99680 | 99775 | sqlite3ErrorMsg(pParse, |
| 99681 | 99776 | "%.*s() may not be used as a window function", nId, zId |
| 99682 | 99777 | ); |
| 99683 | | - pNC->nErr++; |
| 99778 | + pNC->nNcErr++; |
| 99684 | 99779 | }else if( |
| 99685 | 99780 | (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) |
| 99686 | 99781 | || (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pWin) |
| 99687 | 99782 | || (is_agg && pWin && (pNC->ncFlags & NC_AllowWin)==0) |
| 99688 | 99783 | ){ |
| | @@ -99691,39 +99786,39 @@ |
| 99691 | 99786 | zType = "window"; |
| 99692 | 99787 | }else{ |
| 99693 | 99788 | zType = "aggregate"; |
| 99694 | 99789 | } |
| 99695 | 99790 | sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId); |
| 99696 | | - pNC->nErr++; |
| 99791 | + pNC->nNcErr++; |
| 99697 | 99792 | is_agg = 0; |
| 99698 | 99793 | } |
| 99699 | 99794 | #else |
| 99700 | 99795 | if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){ |
| 99701 | 99796 | sqlite3ErrorMsg(pParse,"misuse of aggregate function %.*s()",nId,zId); |
| 99702 | | - pNC->nErr++; |
| 99797 | + pNC->nNcErr++; |
| 99703 | 99798 | is_agg = 0; |
| 99704 | 99799 | } |
| 99705 | 99800 | #endif |
| 99706 | 99801 | else if( no_such_func && pParse->db->init.busy==0 |
| 99707 | 99802 | #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 99708 | 99803 | && pParse->explain==0 |
| 99709 | 99804 | #endif |
| 99710 | 99805 | ){ |
| 99711 | 99806 | sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId); |
| 99712 | | - pNC->nErr++; |
| 99807 | + pNC->nNcErr++; |
| 99713 | 99808 | }else if( wrong_num_args ){ |
| 99714 | 99809 | sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()", |
| 99715 | 99810 | nId, zId); |
| 99716 | | - pNC->nErr++; |
| 99811 | + pNC->nNcErr++; |
| 99717 | 99812 | } |
| 99718 | 99813 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 99719 | 99814 | else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 99720 | 99815 | sqlite3ErrorMsg(pParse, |
| 99721 | 99816 | "FILTER may not be used with non-aggregate %.*s()", |
| 99722 | 99817 | nId, zId |
| 99723 | 99818 | ); |
| 99724 | | - pNC->nErr++; |
| 99819 | + pNC->nNcErr++; |
| 99725 | 99820 | } |
| 99726 | 99821 | #endif |
| 99727 | 99822 | if( is_agg ){ |
| 99728 | 99823 | /* Window functions may not be arguments of aggregate functions. |
| 99729 | 99824 | ** Or arguments of other window functions. But aggregate functions |
| | @@ -99943,12 +100038,12 @@ |
| 99943 | 100038 | */ |
| 99944 | 100039 | memset(&nc, 0, sizeof(nc)); |
| 99945 | 100040 | nc.pParse = pParse; |
| 99946 | 100041 | nc.pSrcList = pSelect->pSrc; |
| 99947 | 100042 | nc.uNC.pEList = pEList; |
| 99948 | | - nc.ncFlags = NC_AllowAgg|NC_UEList; |
| 99949 | | - nc.nErr = 0; |
| 100043 | + nc.ncFlags = NC_AllowAgg|NC_UEList|NC_NoSelect; |
| 100044 | + nc.nNcErr = 0; |
| 99950 | 100045 | db = pParse->db; |
| 99951 | 100046 | savedSuppErr = db->suppressErr; |
| 99952 | 100047 | if( IN_RENAME_OBJECT==0 ) db->suppressErr = 1; |
| 99953 | 100048 | rc = sqlite3ResolveExprNames(&nc, pE); |
| 99954 | 100049 | db->suppressErr = savedSuppErr; |
| | @@ -100203,11 +100298,11 @@ |
| 100203 | 100298 | int iCol; /* Column number */ |
| 100204 | 100299 | struct ExprList_item *pItem; /* A term of the ORDER BY clause */ |
| 100205 | 100300 | Parse *pParse; /* Parsing context */ |
| 100206 | 100301 | int nResult; /* Number of terms in the result set */ |
| 100207 | 100302 | |
| 100208 | | - if( pOrderBy==0 ) return 0; |
| 100303 | + assert( pOrderBy!=0 ); |
| 100209 | 100304 | nResult = pSelect->pEList->nExpr; |
| 100210 | 100305 | pParse = pNC->pParse; |
| 100211 | 100306 | for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){ |
| 100212 | 100307 | Expr *pE = pItem->pExpr; |
| 100213 | 100308 | Expr *pE2 = sqlite3ExprSkipCollateAndLikely(pE); |
| | @@ -100293,11 +100388,13 @@ |
| 100293 | 100388 | nCompound = 0; |
| 100294 | 100389 | pLeftmost = p; |
| 100295 | 100390 | while( p ){ |
| 100296 | 100391 | assert( (p->selFlags & SF_Expanded)!=0 ); |
| 100297 | 100392 | assert( (p->selFlags & SF_Resolved)==0 ); |
| 100393 | + assert( db->suppressErr==0 ); /* SF_Resolved not set if errors suppressed */ |
| 100298 | 100394 | p->selFlags |= SF_Resolved; |
| 100395 | + |
| 100299 | 100396 | |
| 100300 | 100397 | /* Resolve the expressions in the LIMIT and OFFSET clauses. These |
| 100301 | 100398 | ** are not allowed to refer to any names, so pass an empty NameContext. |
| 100302 | 100399 | */ |
| 100303 | 100400 | memset(&sNC, 0, sizeof(sNC)); |
| | @@ -100368,17 +100465,10 @@ |
| 100368 | 100465 | p->selFlags |= SF_Aggregate | (sNC.ncFlags&NC_MinMaxAgg); |
| 100369 | 100466 | }else{ |
| 100370 | 100467 | sNC.ncFlags &= ~NC_AllowAgg; |
| 100371 | 100468 | } |
| 100372 | 100469 | |
| 100373 | | - /* If a HAVING clause is present, then there must be a GROUP BY clause. |
| 100374 | | - */ |
| 100375 | | - if( p->pHaving && !pGroupBy ){ |
| 100376 | | - sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING"); |
| 100377 | | - return WRC_Abort; |
| 100378 | | - } |
| 100379 | | - |
| 100380 | 100470 | /* Add the output column list to the name-context before parsing the |
| 100381 | 100471 | ** other expressions in the SELECT statement. This is so that |
| 100382 | 100472 | ** expressions in the WHERE clause (etc.) can refer to expressions by |
| 100383 | 100473 | ** aliases in the result set. |
| 100384 | 100474 | ** |
| | @@ -100386,11 +100476,17 @@ |
| 100386 | 100476 | ** re-evaluated for each reference to it. |
| 100387 | 100477 | */ |
| 100388 | 100478 | assert( (sNC.ncFlags & (NC_UAggInfo|NC_UUpsert|NC_UBaseReg))==0 ); |
| 100389 | 100479 | sNC.uNC.pEList = p->pEList; |
| 100390 | 100480 | sNC.ncFlags |= NC_UEList; |
| 100391 | | - if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort; |
| 100481 | + if( p->pHaving ){ |
| 100482 | + if( !pGroupBy ){ |
| 100483 | + sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING"); |
| 100484 | + return WRC_Abort; |
| 100485 | + } |
| 100486 | + if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort; |
| 100487 | + } |
| 100392 | 100488 | if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort; |
| 100393 | 100489 | |
| 100394 | 100490 | /* Resolve names in table-valued-function arguments */ |
| 100395 | 100491 | for(i=0; i<p->pSrc->nSrc; i++){ |
| 100396 | 100492 | SrcItem *pItem = &p->pSrc->a[i]; |
| | @@ -100426,11 +100522,12 @@ |
| 100426 | 100522 | ** If there is an ORDER BY clause on a term of a compound-select other |
| 100427 | 100523 | ** than the right-most term, then that is a syntax error. But the error |
| 100428 | 100524 | ** is not detected until much later, and so we need to go ahead and |
| 100429 | 100525 | ** resolve those symbols on the incorrect ORDER BY for consistency. |
| 100430 | 100526 | */ |
| 100431 | | - if( isCompound<=nCompound /* Defer right-most ORDER BY of a compound */ |
| 100527 | + if( p->pOrderBy!=0 |
| 100528 | + && isCompound<=nCompound /* Defer right-most ORDER BY of a compound */ |
| 100432 | 100529 | && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") |
| 100433 | 100530 | ){ |
| 100434 | 100531 | return WRC_Abort; |
| 100435 | 100532 | } |
| 100436 | 100533 | if( db->mallocFailed ){ |
| | @@ -100550,11 +100647,11 @@ |
| 100550 | 100647 | if( pExpr==0 ) return SQLITE_OK; |
| 100551 | 100648 | savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin); |
| 100552 | 100649 | pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin); |
| 100553 | 100650 | w.pParse = pNC->pParse; |
| 100554 | 100651 | w.xExprCallback = resolveExprStep; |
| 100555 | | - w.xSelectCallback = resolveSelectStep; |
| 100652 | + w.xSelectCallback = (pNC->ncFlags & NC_NoSelect) ? 0 : resolveSelectStep; |
| 100556 | 100653 | w.xSelectCallback2 = 0; |
| 100557 | 100654 | w.u.pNC = pNC; |
| 100558 | 100655 | #if SQLITE_MAX_EXPR_DEPTH>0 |
| 100559 | 100656 | w.pParse->nHeight += pExpr->nHeight; |
| 100560 | 100657 | if( sqlite3ExprCheckHeight(w.pParse, w.pParse->nHeight) ){ |
| | @@ -100569,11 +100666,11 @@ |
| 100569 | 100666 | assert( EP_Win==NC_HasWin ); |
| 100570 | 100667 | testcase( pNC->ncFlags & NC_HasAgg ); |
| 100571 | 100668 | testcase( pNC->ncFlags & NC_HasWin ); |
| 100572 | 100669 | ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) ); |
| 100573 | 100670 | pNC->ncFlags |= savedHasAgg; |
| 100574 | | - return pNC->nErr>0 || w.pParse->nErr>0; |
| 100671 | + return pNC->nNcErr>0 || w.pParse->nErr>0; |
| 100575 | 100672 | } |
| 100576 | 100673 | |
| 100577 | 100674 | /* |
| 100578 | 100675 | ** Resolve all names for all expression in an expression list. This is |
| 100579 | 100676 | ** just like sqlite3ResolveExprNames() except that it works for an expression |
| | @@ -100614,11 +100711,11 @@ |
| 100614 | 100711 | if( pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin) ){ |
| 100615 | 100712 | ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) ); |
| 100616 | 100713 | savedHasAgg |= pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin); |
| 100617 | 100714 | pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin); |
| 100618 | 100715 | } |
| 100619 | | - if( pNC->nErr>0 || w.pParse->nErr>0 ) return WRC_Abort; |
| 100716 | + if( w.pParse->nErr>0 ) return WRC_Abort; |
| 100620 | 100717 | } |
| 100621 | 100718 | pNC->ncFlags |= savedHasAgg; |
| 100622 | 100719 | return WRC_Continue; |
| 100623 | 100720 | } |
| 100624 | 100721 | |
| | @@ -100757,27 +100854,27 @@ |
| 100757 | 100854 | || (pExpr->op==TK_REGISTER && pExpr->op2==TK_IF_NULL_ROW) ); |
| 100758 | 100855 | pExpr = pExpr->pLeft; |
| 100759 | 100856 | assert( pExpr!=0 ); |
| 100760 | 100857 | } |
| 100761 | 100858 | op = pExpr->op; |
| 100859 | + if( op==TK_REGISTER ) op = pExpr->op2; |
| 100860 | + if( (op==TK_COLUMN || op==TK_AGG_COLUMN) && pExpr->y.pTab ){ |
| 100861 | + return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); |
| 100862 | + } |
| 100762 | 100863 | if( op==TK_SELECT ){ |
| 100763 | 100864 | assert( pExpr->flags&EP_xIsSelect ); |
| 100764 | 100865 | assert( pExpr->x.pSelect!=0 ); |
| 100765 | 100866 | assert( pExpr->x.pSelect->pEList!=0 ); |
| 100766 | 100867 | assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 ); |
| 100767 | 100868 | return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr); |
| 100768 | 100869 | } |
| 100769 | | - if( op==TK_REGISTER ) op = pExpr->op2; |
| 100770 | 100870 | #ifndef SQLITE_OMIT_CAST |
| 100771 | 100871 | if( op==TK_CAST ){ |
| 100772 | 100872 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 100773 | 100873 | return sqlite3AffinityType(pExpr->u.zToken, 0); |
| 100774 | 100874 | } |
| 100775 | 100875 | #endif |
| 100776 | | - if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->y.pTab ){ |
| 100777 | | - return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); |
| 100778 | | - } |
| 100779 | 100876 | if( op==TK_SELECT_COLUMN ){ |
| 100780 | 100877 | assert( pExpr->pLeft->flags&EP_xIsSelect ); |
| 100781 | 100878 | return sqlite3ExprAffinity( |
| 100782 | 100879 | pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr |
| 100783 | 100880 | ); |
| | @@ -102029,10 +102126,11 @@ |
| 102029 | 102126 | |
| 102030 | 102127 | /* Figure out where to write the new Expr structure. */ |
| 102031 | 102128 | if( pzBuffer ){ |
| 102032 | 102129 | zAlloc = *pzBuffer; |
| 102033 | 102130 | staticFlag = EP_Static; |
| 102131 | + assert( zAlloc!=0 ); |
| 102034 | 102132 | }else{ |
| 102035 | 102133 | zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, dupFlags)); |
| 102036 | 102134 | staticFlag = 0; |
| 102037 | 102135 | } |
| 102038 | 102136 | pNew = (Expr *)zAlloc; |
| | @@ -102107,11 +102205,12 @@ |
| 102107 | 102205 | }else{ |
| 102108 | 102206 | if( !ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){ |
| 102109 | 102207 | if( pNew->op==TK_SELECT_COLUMN ){ |
| 102110 | 102208 | pNew->pLeft = p->pLeft; |
| 102111 | 102209 | assert( p->iColumn==0 || p->pRight==0 ); |
| 102112 | | - assert( p->pRight==0 || p->pRight==p->pLeft ); |
| 102210 | + assert( p->pRight==0 || p->pRight==p->pLeft |
| 102211 | + || ExprHasProperty(p->pLeft, EP_Subquery) ); |
| 102113 | 102212 | }else{ |
| 102114 | 102213 | pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0); |
| 102115 | 102214 | } |
| 102116 | 102215 | pNew->pRight = sqlite3ExprDup(db, p->pRight, 0); |
| 102117 | 102216 | } |
| | @@ -102352,10 +102451,18 @@ |
| 102352 | 102451 | pNew->pWin = 0; |
| 102353 | 102452 | pNew->pWinDefn = sqlite3WindowListDup(db, p->pWinDefn); |
| 102354 | 102453 | if( p->pWin && db->mallocFailed==0 ) gatherSelectWindows(pNew); |
| 102355 | 102454 | #endif |
| 102356 | 102455 | pNew->selId = p->selId; |
| 102456 | + if( db->mallocFailed ){ |
| 102457 | + /* Any prior OOM might have left the Select object incomplete. |
| 102458 | + ** Delete the whole thing rather than allow an incomplete Select |
| 102459 | + ** to be used by the code generator. */ |
| 102460 | + pNew->pNext = 0; |
| 102461 | + sqlite3SelectDelete(db, pNew); |
| 102462 | + break; |
| 102463 | + } |
| 102357 | 102464 | *pp = pNew; |
| 102358 | 102465 | pp = &pNew->pPrior; |
| 102359 | 102466 | pNext = pNew; |
| 102360 | 102467 | } |
| 102361 | 102468 | |
| | @@ -103052,12 +103159,14 @@ |
| 103052 | 103159 | ** will likely result in an incorrect answer. So when in doubt, return |
| 103053 | 103160 | ** TRUE. |
| 103054 | 103161 | */ |
| 103055 | 103162 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr *p){ |
| 103056 | 103163 | u8 op; |
| 103164 | + assert( p!=0 ); |
| 103057 | 103165 | while( p->op==TK_UPLUS || p->op==TK_UMINUS ){ |
| 103058 | 103166 | p = p->pLeft; |
| 103167 | + assert( p!=0 ); |
| 103059 | 103168 | } |
| 103060 | 103169 | op = p->op; |
| 103061 | 103170 | if( op==TK_REGISTER ) op = p->op2; |
| 103062 | 103171 | switch( op ){ |
| 103063 | 103172 | case TK_INTEGER: |
| | @@ -103903,11 +104012,11 @@ |
| 103903 | 104012 | ** columns as the vector on the LHS. Or, if the RHS of the IN() is not |
| 103904 | 104013 | ** a sub-query, that the LHS is a vector of size 1. |
| 103905 | 104014 | */ |
| 103906 | 104015 | SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){ |
| 103907 | 104016 | int nVector = sqlite3ExprVectorSize(pIn->pLeft); |
| 103908 | | - if( (pIn->flags & EP_xIsSelect) ){ |
| 104017 | + if( (pIn->flags & EP_xIsSelect)!=0 && !pParse->db->mallocFailed ){ |
| 103909 | 104018 | if( nVector!=pIn->x.pSelect->pEList->nExpr ){ |
| 103910 | 104019 | sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector); |
| 103911 | 104020 | return 1; |
| 103912 | 104021 | } |
| 103913 | 104022 | }else if( nVector!=1 ){ |
| | @@ -104720,11 +104829,11 @@ |
| 104720 | 104829 | default: { |
| 104721 | 104830 | /* Make NULL the default case so that if a bug causes an illegal |
| 104722 | 104831 | ** Expr node to be passed into this function, it will be handled |
| 104723 | 104832 | ** sanely and not crash. But keep the assert() to bring the problem |
| 104724 | 104833 | ** to the attention of the developers. */ |
| 104725 | | - assert( op==TK_NULL ); |
| 104834 | + assert( op==TK_NULL || pParse->db->mallocFailed ); |
| 104726 | 104835 | sqlite3VdbeAddOp2(v, OP_Null, 0, target); |
| 104727 | 104836 | return target; |
| 104728 | 104837 | } |
| 104729 | 104838 | #ifndef SQLITE_OMIT_BLOB_LITERAL |
| 104730 | 104839 | case TK_BLOB: { |
| | @@ -106895,10 +107004,11 @@ |
| 106895 | 107004 | ** Or, if zName is not a system table, zero is returned. |
| 106896 | 107005 | */ |
| 106897 | 107006 | static int isAlterableTable(Parse *pParse, Table *pTab){ |
| 106898 | 107007 | if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) |
| 106899 | 107008 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 107009 | + || (pTab->tabFlags & TF_Eponymous)!=0 |
| 106900 | 107010 | || ( (pTab->tabFlags & TF_Shadow)!=0 |
| 106901 | 107011 | && sqlite3ReadOnlyShadowTables(pParse->db) |
| 106902 | 107012 | ) |
| 106903 | 107013 | #endif |
| 106904 | 107014 | ){ |
| | @@ -107782,11 +107892,13 @@ |
| 107782 | 107892 | Parse *pParse, |
| 107783 | 107893 | struct RenameCtx *pCtx, |
| 107784 | 107894 | void *pPtr |
| 107785 | 107895 | ){ |
| 107786 | 107896 | RenameToken **pp; |
| 107787 | | - assert( pPtr!=0 ); |
| 107897 | + if( NEVER(pPtr==0) ){ |
| 107898 | + return 0; |
| 107899 | + } |
| 107788 | 107900 | for(pp=&pParse->pRename; (*pp); pp=&(*pp)->pNext){ |
| 107789 | 107901 | if( (*pp)->p==pPtr ){ |
| 107790 | 107902 | RenameToken *pToken = *pp; |
| 107791 | 107903 | if( pCtx ){ |
| 107792 | 107904 | *pp = pToken->pNext; |
| | @@ -108439,11 +108551,11 @@ |
| 108439 | 108551 | static int renameTableSelectCb(Walker *pWalker, Select *pSelect){ |
| 108440 | 108552 | int i; |
| 108441 | 108553 | RenameCtx *p = pWalker->u.pRename; |
| 108442 | 108554 | SrcList *pSrc = pSelect->pSrc; |
| 108443 | 108555 | if( pSelect->selFlags & SF_View ) return WRC_Prune; |
| 108444 | | - if( pSrc==0 ){ |
| 108556 | + if( NEVER(pSrc==0) ){ |
| 108445 | 108557 | assert( pWalker->pParse->db->mallocFailed ); |
| 108446 | 108558 | return WRC_Abort; |
| 108447 | 108559 | } |
| 108448 | 108560 | for(i=0; i<pSrc->nSrc; i++){ |
| 108449 | 108561 | SrcItem *pItem = &pSrc->a[i]; |
| | @@ -108983,20 +109095,25 @@ |
| 108983 | 109095 | if( iPos<pPk->nKeyCol ) continue; |
| 108984 | 109096 | regOut = reg+1+iPos-(iPos>iColPos); |
| 108985 | 109097 | }else{ |
| 108986 | 109098 | regOut = reg+1+nField; |
| 108987 | 109099 | } |
| 108988 | | - sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut); |
| 109100 | + if( i==pTab->iPKey ){ |
| 109101 | + sqlite3VdbeAddOp2(v, OP_Null, 0, regOut); |
| 109102 | + }else{ |
| 109103 | + sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut); |
| 109104 | + } |
| 108989 | 109105 | nField++; |
| 108990 | 109106 | } |
| 108991 | 109107 | } |
| 108992 | 109108 | sqlite3VdbeAddOp3(v, OP_MakeRecord, reg+1, nField, regRec); |
| 108993 | 109109 | if( pPk ){ |
| 108994 | 109110 | sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iCur, regRec, reg+1, pPk->nKeyCol); |
| 108995 | 109111 | }else{ |
| 108996 | 109112 | sqlite3VdbeAddOp3(v, OP_Insert, iCur, regRec, reg); |
| 108997 | 109113 | } |
| 109114 | + sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION); |
| 108998 | 109115 | |
| 108999 | 109116 | sqlite3VdbeAddOp2(v, OP_Next, iCur, addr+1); VdbeCoverage(v); |
| 109000 | 109117 | sqlite3VdbeJumpHere(v, addr); |
| 109001 | 109118 | } |
| 109002 | 109119 | |
| | @@ -111479,11 +111596,11 @@ |
| 111479 | 111596 | pFix->pName = pName; |
| 111480 | 111597 | pFix->bTemp = (iDb==1); |
| 111481 | 111598 | pFix->w.pParse = pParse; |
| 111482 | 111599 | pFix->w.xExprCallback = fixExprCb; |
| 111483 | 111600 | pFix->w.xSelectCallback = fixSelectCb; |
| 111484 | | - pFix->w.xSelectCallback2 = 0; |
| 111601 | + pFix->w.xSelectCallback2 = sqlite3WalkWinDefnDummyCallback; |
| 111485 | 111602 | pFix->w.walkerDepth = 0; |
| 111486 | 111603 | pFix->w.eCode = 0; |
| 111487 | 111604 | pFix->w.u.pFix = pFix; |
| 111488 | 111605 | } |
| 111489 | 111606 | |
| | @@ -111541,18 +111658,20 @@ |
| 111541 | 111658 | || sqlite3FixSrcList(pFix, pStep->pFrom) |
| 111542 | 111659 | ){ |
| 111543 | 111660 | return 1; |
| 111544 | 111661 | } |
| 111545 | 111662 | #ifndef SQLITE_OMIT_UPSERT |
| 111546 | | - if( pStep->pUpsert ){ |
| 111547 | | - Upsert *pUp = pStep->pUpsert; |
| 111548 | | - if( sqlite3WalkExprList(&pFix->w, pUp->pUpsertTarget) |
| 111549 | | - || sqlite3WalkExpr(&pFix->w, pUp->pUpsertTargetWhere) |
| 111550 | | - || sqlite3WalkExprList(&pFix->w, pUp->pUpsertSet) |
| 111551 | | - || sqlite3WalkExpr(&pFix->w, pUp->pUpsertWhere) |
| 111552 | | - ){ |
| 111553 | | - return 1; |
| 111663 | + { |
| 111664 | + Upsert *pUp; |
| 111665 | + for(pUp=pStep->pUpsert; pUp; pUp=pUp->pNextUpsert){ |
| 111666 | + if( sqlite3WalkExprList(&pFix->w, pUp->pUpsertTarget) |
| 111667 | + || sqlite3WalkExpr(&pFix->w, pUp->pUpsertTargetWhere) |
| 111668 | + || sqlite3WalkExprList(&pFix->w, pUp->pUpsertSet) |
| 111669 | + || sqlite3WalkExpr(&pFix->w, pUp->pUpsertWhere) |
| 111670 | + ){ |
| 111671 | + return 1; |
| 111672 | + } |
| 111554 | 111673 | } |
| 111555 | 111674 | } |
| 111556 | 111675 | #endif |
| 111557 | 111676 | pStep = pStep->pNext; |
| 111558 | 111677 | } |
| | @@ -112272,11 +112391,11 @@ |
| 112272 | 112391 | if( p==0 ){ |
| 112273 | 112392 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 112274 | 112393 | /* If zName is the not the name of a table in the schema created using |
| 112275 | 112394 | ** CREATE, then check to see if it is the name of an virtual table that |
| 112276 | 112395 | ** can be an eponymous virtual table. */ |
| 112277 | | - if( pParse->disableVtab==0 ){ |
| 112396 | + if( pParse->disableVtab==0 && db->init.busy==0 ){ |
| 112278 | 112397 | Module *pMod = (Module*)sqlite3HashFind(&db->aModule, zName); |
| 112279 | 112398 | if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){ |
| 112280 | 112399 | pMod = sqlite3PragmaVtabRegister(db, zName); |
| 112281 | 112400 | } |
| 112282 | 112401 | if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){ |
| | @@ -112295,10 +112414,12 @@ |
| 112295 | 112414 | if( zDbase ){ |
| 112296 | 112415 | sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName); |
| 112297 | 112416 | }else{ |
| 112298 | 112417 | sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName); |
| 112299 | 112418 | } |
| 112419 | + }else{ |
| 112420 | + assert( HasRowid(p) || p->iPKey<0 ); |
| 112300 | 112421 | } |
| 112301 | 112422 | |
| 112302 | 112423 | return p; |
| 112303 | 112424 | } |
| 112304 | 112425 | |
| | @@ -113155,10 +113276,11 @@ |
| 113155 | 113276 | pRet->retTrig.zName = RETURNING_TRIGGER_NAME; |
| 113156 | 113277 | pRet->retTrig.op = TK_RETURNING; |
| 113157 | 113278 | pRet->retTrig.tr_tm = TRIGGER_AFTER; |
| 113158 | 113279 | pRet->retTrig.bReturning = 1; |
| 113159 | 113280 | pRet->retTrig.pSchema = db->aDb[1].pSchema; |
| 113281 | + pRet->retTrig.pTabSchema = db->aDb[1].pSchema; |
| 113160 | 113282 | pRet->retTrig.step_list = &pRet->retTStep; |
| 113161 | 113283 | pRet->retTStep.op = TK_RETURNING; |
| 113162 | 113284 | pRet->retTStep.pTrig = &pRet->retTrig; |
| 113163 | 113285 | pRet->retTStep.pExprList = pList; |
| 113164 | 113286 | pHash = &(db->aDb[1].pSchema->trigHash); |
| | @@ -114013,20 +114135,26 @@ |
| 114013 | 114135 | ExprList *pList; |
| 114014 | 114136 | Token ipkToken; |
| 114015 | 114137 | sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName); |
| 114016 | 114138 | pList = sqlite3ExprListAppend(pParse, 0, |
| 114017 | 114139 | sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0)); |
| 114018 | | - if( pList==0 ) return; |
| 114140 | + if( pList==0 ){ |
| 114141 | + pTab->tabFlags &= ~TF_WithoutRowid; |
| 114142 | + return; |
| 114143 | + } |
| 114019 | 114144 | if( IN_RENAME_OBJECT ){ |
| 114020 | 114145 | sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey); |
| 114021 | 114146 | } |
| 114022 | 114147 | pList->a[0].sortFlags = pParse->iPkSortOrder; |
| 114023 | 114148 | assert( pParse->pNewTable==pTab ); |
| 114024 | 114149 | pTab->iPKey = -1; |
| 114025 | 114150 | sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0, |
| 114026 | 114151 | SQLITE_IDXTYPE_PRIMARYKEY); |
| 114027 | | - if( db->mallocFailed || pParse->nErr ) return; |
| 114152 | + if( db->mallocFailed || pParse->nErr ){ |
| 114153 | + pTab->tabFlags &= ~TF_WithoutRowid; |
| 114154 | + return; |
| 114155 | + } |
| 114028 | 114156 | pPk = sqlite3PrimaryKeyIndex(pTab); |
| 114029 | 114157 | assert( pPk->nKeyCol==1 ); |
| 114030 | 114158 | }else{ |
| 114031 | 114159 | pPk = sqlite3PrimaryKeyIndex(pTab); |
| 114032 | 114160 | assert( pPk!=0 ); |
| | @@ -114226,11 +114354,10 @@ |
| 114226 | 114354 | Index *pIdx; /* An implied index of the table */ |
| 114227 | 114355 | |
| 114228 | 114356 | if( pEnd==0 && pSelect==0 ){ |
| 114229 | 114357 | return; |
| 114230 | 114358 | } |
| 114231 | | - assert( !db->mallocFailed ); |
| 114232 | 114359 | p = pParse->pNewTable; |
| 114233 | 114360 | if( p==0 ) return; |
| 114234 | 114361 | |
| 114235 | 114362 | if( pSelect==0 && sqlite3ShadowTableName(db, p->zName) ){ |
| 114236 | 114363 | p->tabFlags |= TF_Shadow; |
| | @@ -114474,10 +114601,11 @@ |
| 114474 | 114601 | */ |
| 114475 | 114602 | if( db->init.busy ){ |
| 114476 | 114603 | Table *pOld; |
| 114477 | 114604 | Schema *pSchema = p->pSchema; |
| 114478 | 114605 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 114606 | + assert( HasRowid(p) || p->iPKey<0 ); |
| 114479 | 114607 | pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, p); |
| 114480 | 114608 | if( pOld ){ |
| 114481 | 114609 | assert( p==pOld ); /* Malloc must have failed inside HashInsert() */ |
| 114482 | 114610 | sqlite3OomFault(db); |
| 114483 | 114611 | return; |
| | @@ -116421,12 +116549,12 @@ |
| 116421 | 116549 | ** Assign VdbeCursor index numbers to all tables in a SrcList |
| 116422 | 116550 | */ |
| 116423 | 116551 | SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse *pParse, SrcList *pList){ |
| 116424 | 116552 | int i; |
| 116425 | 116553 | SrcItem *pItem; |
| 116426 | | - assert(pList || pParse->db->mallocFailed ); |
| 116427 | | - if( pList ){ |
| 116554 | + assert( pList || pParse->db->mallocFailed ); |
| 116555 | + if( ALWAYS(pList) ){ |
| 116428 | 116556 | for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){ |
| 116429 | 116557 | if( pItem->iCursor>=0 ) continue; |
| 116430 | 116558 | pItem->iCursor = pParse->nTab++; |
| 116431 | 116559 | if( pItem->pSelect ){ |
| 116432 | 116560 | sqlite3SrcListAssignCursors(pParse, pItem->pSelect->pSrc); |
| | @@ -120759,13 +120887,11 @@ |
| 120759 | 120887 | ans = x(v0, v1); |
| 120760 | 120888 | sqlite3_result_double(context, ans); |
| 120761 | 120889 | } |
| 120762 | 120890 | |
| 120763 | 120891 | /* |
| 120764 | | -** Implementation of 2-argument SQL math functions: |
| 120765 | | -** |
| 120766 | | -** power(X,Y) - Compute X to the Y-th power |
| 120892 | +** Implementation of 0-argument pi() function. |
| 120767 | 120893 | */ |
| 120768 | 120894 | static void piFunc( |
| 120769 | 120895 | sqlite3_context *context, |
| 120770 | 120896 | int argc, |
| 120771 | 120897 | sqlite3_value **argv |
| | @@ -122791,11 +122917,11 @@ |
| 122791 | 122917 | /* Verify that the sqlite_sequence table exists and is an ordinary |
| 122792 | 122918 | ** rowid table with exactly two columns. |
| 122793 | 122919 | ** Ticket d8dc2b3a58cd5dc2918a1d4acb 2018-05-23 */ |
| 122794 | 122920 | if( pSeqTab==0 |
| 122795 | 122921 | || !HasRowid(pSeqTab) |
| 122796 | | - || IsVirtual(pSeqTab) |
| 122922 | + || NEVER(IsVirtual(pSeqTab)) |
| 122797 | 122923 | || pSeqTab->nCol!=2 |
| 122798 | 122924 | ){ |
| 122799 | 122925 | pParse->nErr++; |
| 122800 | 122926 | pParse->rc = SQLITE_CORRUPT_SEQUENCE; |
| 122801 | 122927 | return 0; |
| | @@ -130510,18 +130636,18 @@ |
| 130510 | 130636 | |
| 130511 | 130637 | assert( argc==5 ); |
| 130512 | 130638 | UNUSED_PARAMETER2(NotUsed, argc); |
| 130513 | 130639 | assert( sqlite3_mutex_held(db->mutex) ); |
| 130514 | 130640 | db->mDbFlags |= DBFLAG_EncodingFixed; |
| 130641 | + if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */ |
| 130515 | 130642 | pData->nInitRow++; |
| 130516 | 130643 | if( db->mallocFailed ){ |
| 130517 | 130644 | corruptSchema(pData, argv, 0); |
| 130518 | 130645 | return 1; |
| 130519 | 130646 | } |
| 130520 | 130647 | |
| 130521 | 130648 | assert( iDb>=0 && iDb<db->nDb ); |
| 130522 | | - if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */ |
| 130523 | 130649 | if( argv[3]==0 ){ |
| 130524 | 130650 | corruptSchema(pData, argv, 0); |
| 130525 | 130651 | }else if( argv[4] |
| 130526 | 130652 | && 'c'==sqlite3UpperToLower[(unsigned char)argv[4][0]] |
| 130527 | 130653 | && 'r'==sqlite3UpperToLower[(unsigned char)argv[4][1]] ){ |
| | @@ -130794,19 +130920,21 @@ |
| 130794 | 130920 | #endif |
| 130795 | 130921 | } |
| 130796 | 130922 | if( db->mallocFailed ){ |
| 130797 | 130923 | rc = SQLITE_NOMEM_BKPT; |
| 130798 | 130924 | sqlite3ResetAllSchemasOfConnection(db); |
| 130799 | | - } |
| 130925 | + }else |
| 130800 | 130926 | if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){ |
| 130801 | | - /* Black magic: If the SQLITE_NoSchemaError flag is set, then consider |
| 130802 | | - ** the schema loaded, even if errors occurred. In this situation the |
| 130803 | | - ** current sqlite3_prepare() operation will fail, but the following one |
| 130804 | | - ** will attempt to compile the supplied statement against whatever subset |
| 130805 | | - ** of the schema was loaded before the error occurred. The primary |
| 130806 | | - ** purpose of this is to allow access to the sqlite_schema table |
| 130807 | | - ** even when its contents have been corrupted. |
| 130927 | + /* Hack: If the SQLITE_NoSchemaError flag is set, then consider |
| 130928 | + ** the schema loaded, even if errors (other than OOM) occurred. In |
| 130929 | + ** this situation the current sqlite3_prepare() operation will fail, |
| 130930 | + ** but the following one will attempt to compile the supplied statement |
| 130931 | + ** against whatever subset of the schema was loaded before the error |
| 130932 | + ** occurred. |
| 130933 | + ** |
| 130934 | + ** The primary purpose of this is to allow access to the sqlite_schema |
| 130935 | + ** table even when its contents have been corrupted. |
| 130808 | 130936 | */ |
| 130809 | 130937 | DbSetProperty(db, iDb, DB_SchemaLoaded); |
| 130810 | 130938 | rc = SQLITE_OK; |
| 130811 | 130939 | } |
| 130812 | 130940 | |
| | @@ -134976,10 +135104,13 @@ |
| 134976 | 135104 | if( p->pPrior ){ |
| 134977 | 135105 | sqlite3SelectDelete(db, p->pPrior); |
| 134978 | 135106 | } |
| 134979 | 135107 | p->pPrior = pPrior; |
| 134980 | 135108 | pPrior->pNext = p; |
| 135109 | + |
| 135110 | + sqlite3ExprListDelete(db, pPrior->pOrderBy); |
| 135111 | + pPrior->pOrderBy = 0; |
| 134981 | 135112 | |
| 134982 | 135113 | /*** TBD: Insert subroutine calls to close cursors on incomplete |
| 134983 | 135114 | **** subqueries ****/ |
| 134984 | 135115 | ExplainQueryPlanPop(pParse); |
| 134985 | 135116 | return pParse->nErr!=0; |
| | @@ -135056,30 +135187,32 @@ |
| 135056 | 135187 | ifNullRow.flags = EP_IfNullRow; |
| 135057 | 135188 | pCopy = &ifNullRow; |
| 135058 | 135189 | } |
| 135059 | 135190 | testcase( ExprHasProperty(pCopy, EP_Subquery) ); |
| 135060 | 135191 | pNew = sqlite3ExprDup(db, pCopy, 0); |
| 135061 | | - if( pNew && pSubst->isLeftJoin ){ |
| 135192 | + if( db->mallocFailed ){ |
| 135193 | + sqlite3ExprDelete(db, pNew); |
| 135194 | + return pExpr; |
| 135195 | + } |
| 135196 | + if( pSubst->isLeftJoin ){ |
| 135062 | 135197 | ExprSetProperty(pNew, EP_CanBeNull); |
| 135063 | 135198 | } |
| 135064 | | - if( pNew && ExprHasProperty(pExpr,EP_FromJoin) ){ |
| 135199 | + if( ExprHasProperty(pExpr,EP_FromJoin) ){ |
| 135065 | 135200 | sqlite3SetJoinExpr(pNew, pExpr->iRightJoinTable); |
| 135066 | 135201 | } |
| 135067 | 135202 | sqlite3ExprDelete(db, pExpr); |
| 135068 | 135203 | pExpr = pNew; |
| 135069 | 135204 | |
| 135070 | 135205 | /* Ensure that the expression now has an implicit collation sequence, |
| 135071 | 135206 | ** just as it did when it was a column of a view or sub-query. */ |
| 135072 | | - if( pExpr ){ |
| 135073 | | - if( pExpr->op!=TK_COLUMN && pExpr->op!=TK_COLLATE ){ |
| 135074 | | - CollSeq *pColl = sqlite3ExprCollSeq(pSubst->pParse, pExpr); |
| 135075 | | - pExpr = sqlite3ExprAddCollateString(pSubst->pParse, pExpr, |
| 135076 | | - (pColl ? pColl->zName : "BINARY") |
| 135077 | | - ); |
| 135078 | | - } |
| 135079 | | - ExprClearProperty(pExpr, EP_Collate); |
| 135080 | | - } |
| 135207 | + if( pExpr->op!=TK_COLUMN && pExpr->op!=TK_COLLATE ){ |
| 135208 | + CollSeq *pColl = sqlite3ExprCollSeq(pSubst->pParse, pExpr); |
| 135209 | + pExpr = sqlite3ExprAddCollateString(pSubst->pParse, pExpr, |
| 135210 | + (pColl ? pColl->zName : "BINARY") |
| 135211 | + ); |
| 135212 | + } |
| 135213 | + ExprClearProperty(pExpr, EP_Collate); |
| 135081 | 135214 | } |
| 135082 | 135215 | } |
| 135083 | 135216 | }else{ |
| 135084 | 135217 | if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){ |
| 135085 | 135218 | pExpr->iTable = pSubst->iNewTable; |
| | @@ -135194,11 +135327,14 @@ |
| 135194 | 135327 | int i; |
| 135195 | 135328 | SrcItem *pItem; |
| 135196 | 135329 | for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){ |
| 135197 | 135330 | if( i!=iExcept ){ |
| 135198 | 135331 | Select *p; |
| 135199 | | - pItem->iCursor = aCsrMap[pItem->iCursor] = pParse->nTab++; |
| 135332 | + if( !pItem->fg.isRecursive || aCsrMap[pItem->iCursor]==0 ){ |
| 135333 | + aCsrMap[pItem->iCursor] = pParse->nTab++; |
| 135334 | + } |
| 135335 | + pItem->iCursor = aCsrMap[pItem->iCursor]; |
| 135200 | 135336 | for(p=pItem->pSelect; p; p=p->pPrior){ |
| 135201 | 135337 | srclistRenumberCursors(pParse, aCsrMap, p->pSrc, -1); |
| 135202 | 135338 | } |
| 135203 | 135339 | } |
| 135204 | 135340 | } |
| | @@ -135634,11 +135770,11 @@ |
| 135634 | 135770 | pSubitem->pTab = pItemTab; |
| 135635 | 135771 | if( pNew==0 ){ |
| 135636 | 135772 | p->pPrior = pPrior; |
| 135637 | 135773 | }else{ |
| 135638 | 135774 | pNew->selId = ++pParse->nSelect; |
| 135639 | | - if( aCsrMap && db->mallocFailed==0 ){ |
| 135775 | + if( aCsrMap && ALWAYS(db->mallocFailed==0) ){ |
| 135640 | 135776 | renumberCursors(pParse, pNew, iFrom, aCsrMap); |
| 135641 | 135777 | } |
| 135642 | 135778 | pNew->pPrior = pPrior; |
| 135643 | 135779 | if( pPrior ) pPrior->pNext = pNew; |
| 135644 | 135780 | pNew->pNext = p; |
| | @@ -137626,12 +137762,11 @@ |
| 137626 | 137762 | if( pDest->eDest==SRT_Output ){ |
| 137627 | 137763 | generateColumnNames(pParse, p); |
| 137628 | 137764 | } |
| 137629 | 137765 | |
| 137630 | 137766 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 137631 | | - rc = sqlite3WindowRewrite(pParse, p); |
| 137632 | | - if( rc ){ |
| 137767 | + if( sqlite3WindowRewrite(pParse, p) ){ |
| 137633 | 137768 | assert( db->mallocFailed || pParse->nErr>0 ); |
| 137634 | 137769 | goto select_end; |
| 137635 | 137770 | } |
| 137636 | 137771 | #if SELECTTRACE_ENABLED |
| 137637 | 137772 | if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){ |
| | @@ -138344,12 +138479,14 @@ |
| 138344 | 138479 | sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset); |
| 138345 | 138480 | SELECTTRACE(1,pParse,p,("WhereBegin\n")); |
| 138346 | 138481 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct, |
| 138347 | 138482 | WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0 |
| 138348 | 138483 | ); |
| 138349 | | - sqlite3ExprListDelete(db, pDistinct); |
| 138350 | | - if( pWInfo==0 ) goto select_end; |
| 138484 | + if( pWInfo==0 ){ |
| 138485 | + sqlite3ExprListDelete(db, pDistinct); |
| 138486 | + goto select_end; |
| 138487 | + } |
| 138351 | 138488 | eDist = sqlite3WhereIsDistinct(pWInfo); |
| 138352 | 138489 | SELECTTRACE(1,pParse,p,("WhereBegin returns\n")); |
| 138353 | 138490 | if( sqlite3WhereIsOrdered(pWInfo)==pGroupBy->nExpr ){ |
| 138354 | 138491 | /* The optimizer is able to deliver rows in group by order so |
| 138355 | 138492 | ** we do not have to sort. The OP_OpenEphemeral table will be |
| | @@ -138478,10 +138615,11 @@ |
| 138478 | 138615 | }else{ |
| 138479 | 138616 | SELECTTRACE(1,pParse,p,("WhereEnd\n")); |
| 138480 | 138617 | sqlite3WhereEnd(pWInfo); |
| 138481 | 138618 | sqlite3VdbeChangeToNoop(v, addrSortingIdx); |
| 138482 | 138619 | } |
| 138620 | + sqlite3ExprListDelete(db, pDistinct); |
| 138483 | 138621 | |
| 138484 | 138622 | /* Output the final row of result |
| 138485 | 138623 | */ |
| 138486 | 138624 | sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow); |
| 138487 | 138625 | VdbeComment((v, "output final row")); |
| | @@ -138692,10 +138830,12 @@ |
| 138692 | 138830 | |
| 138693 | 138831 | /* Control jumps to here if an error is encountered above, or upon |
| 138694 | 138832 | ** successful coding of the SELECT. |
| 138695 | 138833 | */ |
| 138696 | 138834 | select_end: |
| 138835 | + assert( db->mallocFailed==0 || db->mallocFailed==1 ); |
| 138836 | + pParse->nErr += db->mallocFailed; |
| 138697 | 138837 | sqlite3ExprListDelete(db, pMinMaxOrderBy); |
| 138698 | 138838 | #ifdef SQLITE_DEBUG |
| 138699 | 138839 | if( pAggInfo && !db->mallocFailed ){ |
| 138700 | 138840 | for(i=0; i<pAggInfo->nColumn; i++){ |
| 138701 | 138841 | Expr *pExpr = pAggInfo->aCol[i].pCExpr; |
| | @@ -138982,37 +139122,45 @@ |
| 138982 | 139122 | if( pParse->disableTriggers ){ |
| 138983 | 139123 | return 0; |
| 138984 | 139124 | } |
| 138985 | 139125 | pTmpSchema = pParse->db->aDb[1].pSchema; |
| 138986 | 139126 | p = sqliteHashFirst(&pTmpSchema->trigHash); |
| 138987 | | - if( p==0 ){ |
| 138988 | | - return pTab->pTrigger; |
| 138989 | | - } |
| 138990 | 139127 | pList = pTab->pTrigger; |
| 138991 | | - if( pTmpSchema!=pTab->pSchema ){ |
| 138992 | | - while( p ){ |
| 138993 | | - Trigger *pTrig = (Trigger *)sqliteHashData(p); |
| 138994 | | - if( pTrig->pTabSchema==pTab->pSchema |
| 138995 | | - && 0==sqlite3StrICmp(pTrig->table, pTab->zName) |
| 138996 | | - ){ |
| 138997 | | - pTrig->pNext = pList; |
| 138998 | | - pList = pTrig; |
| 138999 | | - }else if( pTrig->op==TK_RETURNING |
| 139128 | + while( p ){ |
| 139129 | + Trigger *pTrig = (Trigger *)sqliteHashData(p); |
| 139130 | + if( pTrig->pTabSchema==pTab->pSchema |
| 139131 | + && pTrig->table |
| 139132 | + && 0==sqlite3StrICmp(pTrig->table, pTab->zName) |
| 139133 | + && pTrig->pTabSchema!=pTmpSchema |
| 139134 | + ){ |
| 139135 | + pTrig->pNext = pList; |
| 139136 | + pList = pTrig; |
| 139137 | + }else if( pTrig->op==TK_RETURNING |
| 139000 | 139138 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 139001 | | - && pParse->db->pVtabCtx==0 |
| 139139 | + && pParse->db->pVtabCtx==0 |
| 139002 | 139140 | #endif |
| 139003 | | - ){ |
| 139004 | | - assert( pParse->bReturning ); |
| 139005 | | - assert( &(pParse->u1.pReturning->retTrig) == pTrig ); |
| 139006 | | - pTrig->table = pTab->zName; |
| 139007 | | - pTrig->pTabSchema = pTab->pSchema; |
| 139008 | | - pTrig->pNext = pList; |
| 139009 | | - pList = pTrig; |
| 139010 | | - } |
| 139011 | | - p = sqliteHashNext(p); |
| 139012 | | - } |
| 139013 | | - } |
| 139141 | + ){ |
| 139142 | + assert( pParse->bReturning ); |
| 139143 | + assert( &(pParse->u1.pReturning->retTrig) == pTrig ); |
| 139144 | + pTrig->table = pTab->zName; |
| 139145 | + pTrig->pTabSchema = pTab->pSchema; |
| 139146 | + pTrig->pNext = pList; |
| 139147 | + pList = pTrig; |
| 139148 | + } |
| 139149 | + p = sqliteHashNext(p); |
| 139150 | + } |
| 139151 | +#if 0 |
| 139152 | + if( pList ){ |
| 139153 | + Trigger *pX; |
| 139154 | + printf("Triggers for %s:", pTab->zName); |
| 139155 | + for(pX=pList; pX; pX=pX->pNext){ |
| 139156 | + printf(" %s", pX->zName); |
| 139157 | + } |
| 139158 | + printf("\n"); |
| 139159 | + fflush(stdout); |
| 139160 | + } |
| 139161 | +#endif |
| 139014 | 139162 | return pList; |
| 139015 | 139163 | } |
| 139016 | 139164 | |
| 139017 | 139165 | /* |
| 139018 | 139166 | ** This is called by the parser when it sees a CREATE TRIGGER statement |
| | @@ -140581,11 +140729,12 @@ |
| 140581 | 140729 | if( pLimit ){ |
| 140582 | 140730 | pGrp = sqlite3ExprListAppend(pParse, 0, sqlite3PExpr(pParse,TK_ROW,0,0)); |
| 140583 | 140731 | } |
| 140584 | 140732 | #endif |
| 140585 | 140733 | } |
| 140586 | | - if( ALWAYS(pChanges) ){ |
| 140734 | + assert( pChanges!=0 || pParse->db->mallocFailed ); |
| 140735 | + if( pChanges ){ |
| 140587 | 140736 | for(i=0; i<pChanges->nExpr; i++){ |
| 140588 | 140737 | pList = sqlite3ExprListAppend(pParse, pList, |
| 140589 | 140738 | sqlite3ExprDup(db, pChanges->a[i].pExpr, 0) |
| 140590 | 140739 | ); |
| 140591 | 140740 | } |
| | @@ -143607,10 +143756,11 @@ |
| 143607 | 143756 | pMod->pEpoTab = pTab; |
| 143608 | 143757 | pTab->nTabRef = 1; |
| 143609 | 143758 | pTab->pSchema = db->aDb[0].pSchema; |
| 143610 | 143759 | assert( pTab->nModuleArg==0 ); |
| 143611 | 143760 | pTab->iPKey = -1; |
| 143761 | + pTab->tabFlags |= TF_Eponymous; |
| 143612 | 143762 | addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName)); |
| 143613 | 143763 | addModuleArgument(pParse, pTab, 0); |
| 143614 | 143764 | addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName)); |
| 143615 | 143765 | rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr); |
| 143616 | 143766 | if( rc ){ |
| | @@ -145019,10 +145169,11 @@ |
| 145019 | 145169 | zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx)); |
| 145020 | 145170 | assert( zAff!=0 || pParse->db->mallocFailed ); |
| 145021 | 145171 | |
| 145022 | 145172 | if( nSkip ){ |
| 145023 | 145173 | int iIdxCur = pLevel->iIdxCur; |
| 145174 | + sqlite3VdbeAddOp3(v, OP_Null, 0, regBase, regBase+nSkip-1); |
| 145024 | 145175 | sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur); |
| 145025 | 145176 | VdbeCoverageIf(v, bRev==0); |
| 145026 | 145177 | VdbeCoverageIf(v, bRev!=0); |
| 145027 | 145178 | VdbeComment((v, "begin skip-scan on %s", pIdx->zName)); |
| 145028 | 145179 | j = sqlite3VdbeAddOp0(v, OP_Goto); |
| | @@ -145070,11 +145221,11 @@ |
| 145070 | 145221 | Expr *pRight = pTerm->pExpr->pRight; |
| 145071 | 145222 | if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){ |
| 145072 | 145223 | sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk); |
| 145073 | 145224 | VdbeCoverage(v); |
| 145074 | 145225 | } |
| 145075 | | - if( zAff ){ |
| 145226 | + if( pParse->db->mallocFailed==0 ){ |
| 145076 | 145227 | if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_BLOB ){ |
| 145077 | 145228 | zAff[j] = SQLITE_AFF_BLOB; |
| 145078 | 145229 | } |
| 145079 | 145230 | if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){ |
| 145080 | 145231 | zAff[j] = SQLITE_AFF_BLOB; |
| | @@ -147320,10 +147471,11 @@ |
| 147320 | 147471 | sqlite3 *db; /* Database connection (for malloc) */ |
| 147321 | 147472 | Expr *pNew; /* New virtual expression */ |
| 147322 | 147473 | int op; /* Operator for the combined expression */ |
| 147323 | 147474 | int idxNew; /* Index in pWC of the next virtual term */ |
| 147324 | 147475 | |
| 147476 | + if( (pOne->wtFlags | pTwo->wtFlags) & TERM_VNULL ) return; |
| 147325 | 147477 | if( (pOne->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return; |
| 147326 | 147478 | if( (pTwo->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return; |
| 147327 | 147479 | if( (eOp & (WO_EQ|WO_LT|WO_LE))!=eOp |
| 147328 | 147480 | && (eOp & (WO_EQ|WO_GT|WO_GE))!=eOp ) return; |
| 147329 | 147481 | assert( pOne->pExpr->pLeft!=0 && pOne->pExpr->pRight!=0 ); |
| | @@ -148973,11 +149125,13 @@ |
| 148973 | 149125 | ** If the right-hand branch of the expression is a TK_COLUMN, then return |
| 148974 | 149126 | ** a pointer to the right-hand branch. Otherwise, return NULL. |
| 148975 | 149127 | */ |
| 148976 | 149128 | static Expr *whereRightSubexprIsColumn(Expr *p){ |
| 148977 | 149129 | p = sqlite3ExprSkipCollateAndLikely(p->pRight); |
| 148978 | | - if( ALWAYS(p!=0) && p->op==TK_COLUMN ) return p; |
| 149130 | + if( ALWAYS(p!=0) && p->op==TK_COLUMN && !ExprHasProperty(p, EP_FixedCol) ){ |
| 149131 | + return p; |
| 149132 | + } |
| 148979 | 149133 | return 0; |
| 148980 | 149134 | } |
| 148981 | 149135 | |
| 148982 | 149136 | /* |
| 148983 | 149137 | ** Advance to the next WhereTerm that matches according to the criteria |
| | @@ -150652,11 +150806,11 @@ |
| 150652 | 150806 | ** Transfer content from the second pLoop into the first. |
| 150653 | 150807 | */ |
| 150654 | 150808 | static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){ |
| 150655 | 150809 | whereLoopClearUnion(db, pTo); |
| 150656 | 150810 | if( whereLoopResize(db, pTo, pFrom->nLTerm) ){ |
| 150657 | | - memset(&pTo->u, 0, sizeof(pTo->u)); |
| 150811 | + memset(pTo, 0, WHERE_LOOP_XFER_SZ); |
| 150658 | 150812 | return SQLITE_NOMEM_BKPT; |
| 150659 | 150813 | } |
| 150660 | 150814 | memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ); |
| 150661 | 150815 | memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0])); |
| 150662 | 150816 | if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){ |
| | @@ -150694,10 +150848,21 @@ |
| 150694 | 150848 | whereLoopDelete(db, p); |
| 150695 | 150849 | } |
| 150696 | 150850 | assert( pWInfo->pExprMods==0 ); |
| 150697 | 150851 | sqlite3DbFreeNN(db, pWInfo); |
| 150698 | 150852 | } |
| 150853 | + |
| 150854 | +/* Undo all Expr node modifications |
| 150855 | +*/ |
| 150856 | +static void whereUndoExprMods(WhereInfo *pWInfo){ |
| 150857 | + while( pWInfo->pExprMods ){ |
| 150858 | + WhereExprMod *p = pWInfo->pExprMods; |
| 150859 | + pWInfo->pExprMods = p->pNext; |
| 150860 | + memcpy(p->pExpr, &p->orig, sizeof(p->orig)); |
| 150861 | + sqlite3DbFree(pWInfo->pParse->db, p); |
| 150862 | + } |
| 150863 | +} |
| 150699 | 150864 | |
| 150700 | 150865 | /* |
| 150701 | 150866 | ** Return TRUE if all of the following are true: |
| 150702 | 150867 | ** |
| 150703 | 150868 | ** (1) X has the same or lower cost that Y |
| | @@ -152307,11 +152472,13 @@ |
| 152307 | 152472 | rc = whereLoopAddBtree(&sSubBuild, mPrereq); |
| 152308 | 152473 | } |
| 152309 | 152474 | if( rc==SQLITE_OK ){ |
| 152310 | 152475 | rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable); |
| 152311 | 152476 | } |
| 152312 | | - assert( rc==SQLITE_OK || rc==SQLITE_DONE || sCur.n==0 ); |
| 152477 | + assert( rc==SQLITE_OK || rc==SQLITE_DONE || sCur.n==0 |
| 152478 | + || rc==SQLITE_NOMEM ); |
| 152479 | + testcase( rc==SQLITE_NOMEM && sCur.n>0 ); |
| 152313 | 152480 | testcase( rc==SQLITE_DONE ); |
| 152314 | 152481 | if( sCur.n==0 ){ |
| 152315 | 152482 | sSum.n = 0; |
| 152316 | 152483 | break; |
| 152317 | 152484 | }else if( once ){ |
| | @@ -152576,10 +152743,14 @@ |
| 152576 | 152743 | nKeyCol = pIndex->nKeyCol; |
| 152577 | 152744 | nColumn = pIndex->nColumn; |
| 152578 | 152745 | assert( nColumn==nKeyCol+1 || !HasRowid(pIndex->pTable) ); |
| 152579 | 152746 | assert( pIndex->aiColumn[nColumn-1]==XN_ROWID |
| 152580 | 152747 | || !HasRowid(pIndex->pTable)); |
| 152748 | + /* All relevant terms of the index must also be non-NULL in order |
| 152749 | + ** for isOrderDistinct to be true. So the isOrderDistint value |
| 152750 | + ** computed here might be a false positive. Corrections will be |
| 152751 | + ** made at tag-20210426-1 below */ |
| 152581 | 152752 | isOrderDistinct = IsUniqueIndex(pIndex) |
| 152582 | 152753 | && (pLoop->wsFlags & WHERE_SKIPSCAN)==0; |
| 152583 | 152754 | } |
| 152584 | 152755 | |
| 152585 | 152756 | /* Loop through all columns of the index and deal with the ones |
| | @@ -152643,18 +152814,22 @@ |
| 152643 | 152814 | iColumn = XN_ROWID; |
| 152644 | 152815 | revIdx = 0; |
| 152645 | 152816 | } |
| 152646 | 152817 | |
| 152647 | 152818 | /* An unconstrained column that might be NULL means that this |
| 152648 | | - ** WhereLoop is not well-ordered |
| 152819 | + ** WhereLoop is not well-ordered. tag-20210426-1 |
| 152649 | 152820 | */ |
| 152650 | | - if( isOrderDistinct |
| 152651 | | - && iColumn>=0 |
| 152652 | | - && j>=pLoop->u.btree.nEq |
| 152653 | | - && pIndex->pTable->aCol[iColumn].notNull==0 |
| 152654 | | - ){ |
| 152655 | | - isOrderDistinct = 0; |
| 152821 | + if( isOrderDistinct ){ |
| 152822 | + if( iColumn>=0 |
| 152823 | + && j>=pLoop->u.btree.nEq |
| 152824 | + && pIndex->pTable->aCol[iColumn].notNull==0 |
| 152825 | + ){ |
| 152826 | + isOrderDistinct = 0; |
| 152827 | + } |
| 152828 | + if( iColumn==XN_EXPR ){ |
| 152829 | + isOrderDistinct = 0; |
| 152830 | + } |
| 152656 | 152831 | } |
| 152657 | 152832 | |
| 152658 | 152833 | /* Find the ORDER BY term that corresponds to the j-th column |
| 152659 | 152834 | ** of the index and mark that ORDER BY term off |
| 152660 | 152835 | */ |
| | @@ -154026,10 +154201,12 @@ |
| 154026 | 154201 | return pWInfo; |
| 154027 | 154202 | |
| 154028 | 154203 | /* Jump here if malloc fails */ |
| 154029 | 154204 | whereBeginError: |
| 154030 | 154205 | if( pWInfo ){ |
| 154206 | + testcase( pWInfo->pExprMods!=0 ); |
| 154207 | + whereUndoExprMods(pWInfo); |
| 154031 | 154208 | pParse->nQueryLoop = pWInfo->savedNQueryLoop; |
| 154032 | 154209 | whereInfoFree(db, pWInfo); |
| 154033 | 154210 | } |
| 154034 | 154211 | return 0; |
| 154035 | 154212 | } |
| | @@ -154325,20 +154502,13 @@ |
| 154325 | 154502 | if( db->flags & SQLITE_VdbeAddopTrace ) printf("TRANSLATE complete\n"); |
| 154326 | 154503 | #endif |
| 154327 | 154504 | } |
| 154328 | 154505 | } |
| 154329 | 154506 | |
| 154330 | | - /* Undo all Expr node modifications */ |
| 154331 | | - while( pWInfo->pExprMods ){ |
| 154332 | | - WhereExprMod *p = pWInfo->pExprMods; |
| 154333 | | - pWInfo->pExprMods = p->pNext; |
| 154334 | | - memcpy(p->pExpr, &p->orig, sizeof(p->orig)); |
| 154335 | | - sqlite3DbFree(db, p); |
| 154336 | | - } |
| 154337 | | - |
| 154338 | 154507 | /* Final cleanup |
| 154339 | 154508 | */ |
| 154509 | + if( pWInfo->pExprMods ) whereUndoExprMods(pWInfo); |
| 154340 | 154510 | pParse->nQueryLoop = pWInfo->savedNQueryLoop; |
| 154341 | 154511 | whereInfoFree(db, pWInfo); |
| 154342 | 154512 | return; |
| 154343 | 154513 | } |
| 154344 | 154514 | |
| | @@ -155914,10 +156084,11 @@ |
| 155914 | 156084 | Vdbe *pVdbe; /* VDBE object */ |
| 155915 | 156085 | int addrGosub; /* OP_Gosub to this address to return one row */ |
| 155916 | 156086 | int regGosub; /* Register used with OP_Gosub(addrGosub) */ |
| 155917 | 156087 | int regArg; /* First in array of accumulator registers */ |
| 155918 | 156088 | int eDelete; /* See above */ |
| 156089 | + int regRowid; |
| 155919 | 156090 | |
| 155920 | 156091 | WindowCsrAndReg start; |
| 155921 | 156092 | WindowCsrAndReg current; |
| 155922 | 156093 | WindowCsrAndReg end; |
| 155923 | 156094 | }; |
| | @@ -156590,20 +156761,28 @@ |
| 156590 | 156761 | addrContinue = sqlite3VdbeCurrentAddr(v); |
| 156591 | 156762 | |
| 156592 | 156763 | /* If this is a (RANGE BETWEEN a FOLLOWING AND b FOLLOWING) or |
| 156593 | 156764 | ** (RANGE BETWEEN b PRECEDING AND a PRECEDING) frame, ensure the |
| 156594 | 156765 | ** start cursor does not advance past the end cursor within the |
| 156595 | | - ** temporary table. It otherwise might, if (a>b). */ |
| 156766 | + ** temporary table. It otherwise might, if (a>b). Also ensure that, |
| 156767 | + ** if the input cursor is still finding new rows, that the end |
| 156768 | + ** cursor does not go past it to EOF. */ |
| 156596 | 156769 | if( pMWin->eStart==pMWin->eEnd && regCountdown |
| 156597 | | - && pMWin->eFrmType==TK_RANGE && op==WINDOW_AGGINVERSE |
| 156770 | + && pMWin->eFrmType==TK_RANGE |
| 156598 | 156771 | ){ |
| 156599 | 156772 | int regRowid1 = sqlite3GetTempReg(pParse); |
| 156600 | 156773 | int regRowid2 = sqlite3GetTempReg(pParse); |
| 156601 | | - sqlite3VdbeAddOp2(v, OP_Rowid, p->start.csr, regRowid1); |
| 156602 | | - sqlite3VdbeAddOp2(v, OP_Rowid, p->end.csr, regRowid2); |
| 156603 | | - sqlite3VdbeAddOp3(v, OP_Ge, regRowid2, lblDone, regRowid1); |
| 156604 | | - VdbeCoverage(v); |
| 156774 | + if( op==WINDOW_AGGINVERSE ){ |
| 156775 | + sqlite3VdbeAddOp2(v, OP_Rowid, p->start.csr, regRowid1); |
| 156776 | + sqlite3VdbeAddOp2(v, OP_Rowid, p->end.csr, regRowid2); |
| 156777 | + sqlite3VdbeAddOp3(v, OP_Ge, regRowid2, lblDone, regRowid1); |
| 156778 | + VdbeCoverage(v); |
| 156779 | + }else if( p->regRowid ){ |
| 156780 | + sqlite3VdbeAddOp2(v, OP_Rowid, p->end.csr, regRowid1); |
| 156781 | + sqlite3VdbeAddOp3(v, OP_Ge, p->regRowid, lblDone, regRowid1); |
| 156782 | + VdbeCoverageNeverNull(v); |
| 156783 | + } |
| 156605 | 156784 | sqlite3ReleaseTempReg(pParse, regRowid1); |
| 156606 | 156785 | sqlite3ReleaseTempReg(pParse, regRowid2); |
| 156607 | 156786 | assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING ); |
| 156608 | 156787 | } |
| 156609 | 156788 | |
| | @@ -157096,11 +157275,10 @@ |
| 157096 | 157275 | int addrGosubFlush = 0; /* Address of OP_Gosub to flush: */ |
| 157097 | 157276 | int addrInteger = 0; /* Address of OP_Integer */ |
| 157098 | 157277 | int addrEmpty; /* Address of OP_Rewind in flush: */ |
| 157099 | 157278 | int regNew; /* Array of registers holding new input row */ |
| 157100 | 157279 | int regRecord; /* regNew array in record form */ |
| 157101 | | - int regRowid; /* Rowid for regRecord in eph table */ |
| 157102 | 157280 | int regNewPeer = 0; /* Peer values for new row (part of regNew) */ |
| 157103 | 157281 | int regPeer = 0; /* Peer values for current row */ |
| 157104 | 157282 | int regFlushPart = 0; /* Register for "Gosub flush_partition" */ |
| 157105 | 157283 | WindowCodeArg s; /* Context object for sub-routines */ |
| 157106 | 157284 | int lblWhereEnd; /* Label just before sqlite3WhereEnd() code */ |
| | @@ -157168,11 +157346,11 @@ |
| 157168 | 157346 | ** samve values in record form, and the rowid used to insert said record |
| 157169 | 157347 | ** into the ephemeral table. */ |
| 157170 | 157348 | regNew = pParse->nMem+1; |
| 157171 | 157349 | pParse->nMem += nInput; |
| 157172 | 157350 | regRecord = ++pParse->nMem; |
| 157173 | | - regRowid = ++pParse->nMem; |
| 157351 | + s.regRowid = ++pParse->nMem; |
| 157174 | 157352 | |
| 157175 | 157353 | /* If the window frame contains an "<expr> PRECEDING" or "<expr> FOLLOWING" |
| 157176 | 157354 | ** clause, allocate registers to store the results of evaluating each |
| 157177 | 157355 | ** <expr>. */ |
| 157178 | 157356 | if( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING ){ |
| | @@ -157224,13 +157402,13 @@ |
| 157224 | 157402 | VdbeComment((v, "call flush_partition")); |
| 157225 | 157403 | sqlite3VdbeAddOp3(v, OP_Copy, regNewPart, pMWin->regPart, nPart-1); |
| 157226 | 157404 | } |
| 157227 | 157405 | |
| 157228 | 157406 | /* Insert the new row into the ephemeral table */ |
| 157229 | | - sqlite3VdbeAddOp2(v, OP_NewRowid, csrWrite, regRowid); |
| 157230 | | - sqlite3VdbeAddOp3(v, OP_Insert, csrWrite, regRecord, regRowid); |
| 157231 | | - addrNe = sqlite3VdbeAddOp3(v, OP_Ne, pMWin->regOne, 0, regRowid); |
| 157407 | + sqlite3VdbeAddOp2(v, OP_NewRowid, csrWrite, s.regRowid); |
| 157408 | + sqlite3VdbeAddOp3(v, OP_Insert, csrWrite, regRecord, s.regRowid); |
| 157409 | + addrNe = sqlite3VdbeAddOp3(v, OP_Ne, pMWin->regOne, 0, s.regRowid); |
| 157232 | 157410 | VdbeCoverageNeverNull(v); |
| 157233 | 157411 | |
| 157234 | 157412 | /* This block is run for the first row of each partition */ |
| 157235 | 157413 | s.regArg = windowInitAccum(pParse, pMWin); |
| 157236 | 157414 | |
| | @@ -157344,10 +157522,11 @@ |
| 157344 | 157522 | if( pMWin->pPartition ){ |
| 157345 | 157523 | addrInteger = sqlite3VdbeAddOp2(v, OP_Integer, 0, regFlushPart); |
| 157346 | 157524 | sqlite3VdbeJumpHere(v, addrGosubFlush); |
| 157347 | 157525 | } |
| 157348 | 157526 | |
| 157527 | + s.regRowid = 0; |
| 157349 | 157528 | addrEmpty = sqlite3VdbeAddOp1(v, OP_Rewind, csrWrite); |
| 157350 | 157529 | VdbeCoverage(v); |
| 157351 | 157530 | if( pMWin->eEnd==TK_PRECEDING ){ |
| 157352 | 157531 | int bRPS = (pMWin->eStart==TK_PRECEDING && pMWin->eFrmType==TK_RANGE); |
| 157353 | 157532 | windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0); |
| | @@ -161012,12 +161191,11 @@ |
| 161012 | 161191 | break; |
| 161013 | 161192 | case 16: /* ifnotexists ::= IF NOT EXISTS */ |
| 161014 | 161193 | {yymsp[-2].minor.yy60 = 1;} |
| 161015 | 161194 | break; |
| 161016 | 161195 | case 17: /* temp ::= TEMP */ |
| 161017 | | - case 46: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==46); |
| 161018 | | -{yymsp[0].minor.yy60 = 1;} |
| 161196 | +{yymsp[0].minor.yy60 = pParse->db->init.busy==0;} |
| 161019 | 161197 | break; |
| 161020 | 161198 | case 19: /* create_table_args ::= LP columnlist conslist_opt RP table_options */ |
| 161021 | 161199 | { |
| 161022 | 161200 | sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy60,0); |
| 161023 | 161201 | } |
| | @@ -161125,10 +161303,13 @@ |
| 161125 | 161303 | case 43: /* generated ::= LP expr RP */ |
| 161126 | 161304 | {sqlite3AddGenerated(pParse,yymsp[-1].minor.yy602,0);} |
| 161127 | 161305 | break; |
| 161128 | 161306 | case 44: /* generated ::= LP expr RP ID */ |
| 161129 | 161307 | {sqlite3AddGenerated(pParse,yymsp[-2].minor.yy602,&yymsp[0].minor.yy0);} |
| 161308 | + break; |
| 161309 | + case 46: /* autoinc ::= AUTOINCR */ |
| 161310 | +{yymsp[0].minor.yy60 = 1;} |
| 161130 | 161311 | break; |
| 161131 | 161312 | case 47: /* refargs ::= */ |
| 161132 | 161313 | { yymsp[1].minor.yy60 = OE_None*0x0101; /* EV: R-19803-45884 */} |
| 161133 | 161314 | break; |
| 161134 | 161315 | case 48: /* refargs ::= refargs refarg */ |
| | @@ -162296,11 +162477,15 @@ |
| 162296 | 162477 | case 330: /* window_clause ::= WINDOW windowdefn_list */ |
| 162297 | 162478 | { yymsp[-1].minor.yy19 = yymsp[0].minor.yy19; } |
| 162298 | 162479 | break; |
| 162299 | 162480 | case 331: /* filter_over ::= filter_clause over_clause */ |
| 162300 | 162481 | { |
| 162301 | | - yymsp[0].minor.yy19->pFilter = yymsp[-1].minor.yy602; |
| 162482 | + if( yymsp[0].minor.yy19 ){ |
| 162483 | + yymsp[0].minor.yy19->pFilter = yymsp[-1].minor.yy602; |
| 162484 | + }else{ |
| 162485 | + sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy602); |
| 162486 | + } |
| 162302 | 162487 | yylhsminor.yy19 = yymsp[0].minor.yy19; |
| 162303 | 162488 | } |
| 162304 | 162489 | yymsp[-1].minor.yy19 = yylhsminor.yy19; |
| 162305 | 162490 | break; |
| 162306 | 162491 | case 333: /* filter_over ::= filter_clause */ |
| | @@ -162795,10 +162980,11 @@ |
| 162795 | 162980 | #define CC_TILDA 25 /* '~' */ |
| 162796 | 162981 | #define CC_DOT 26 /* '.' */ |
| 162797 | 162982 | #define CC_ID 27 /* unicode characters usable in IDs */ |
| 162798 | 162983 | #define CC_ILLEGAL 28 /* Illegal character */ |
| 162799 | 162984 | #define CC_NUL 29 /* 0x00 */ |
| 162985 | +#define CC_BOM 30 /* First byte of UTF8 BOM: 0xEF 0xBB 0xBF */ |
| 162800 | 162986 | |
| 162801 | 162987 | static const unsigned char aiClass[] = { |
| 162802 | 162988 | #ifdef SQLITE_ASCII |
| 162803 | 162989 | /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf */ |
| 162804 | 162990 | /* 0x */ 29, 28, 28, 28, 28, 28, 28, 28, 28, 7, 7, 28, 7, 7, 28, 28, |
| | @@ -162807,18 +162993,18 @@ |
| 162807 | 162993 | /* 3x */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 19, 12, 14, 13, 6, |
| 162808 | 162994 | /* 4x */ 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 162809 | 162995 | /* 5x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 9, 28, 28, 28, 2, |
| 162810 | 162996 | /* 6x */ 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 162811 | 162997 | /* 7x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 28, 10, 28, 25, 28, |
| 162812 | | -/* 8x */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 162813 | | -/* 9x */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 162814 | | -/* Ax */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 162815 | | -/* Bx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 162816 | | -/* Cx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 162817 | | -/* Dx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 162818 | | -/* Ex */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 162819 | | -/* Fx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 |
| 162998 | +/* 8x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, |
| 162999 | +/* 9x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, |
| 163000 | +/* Ax */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, |
| 163001 | +/* Bx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, |
| 163002 | +/* Cx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, |
| 163003 | +/* Dx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, |
| 163004 | +/* Ex */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 30, |
| 163005 | +/* Fx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27 |
| 162820 | 163006 | #endif |
| 162821 | 163007 | #ifdef SQLITE_EBCDIC |
| 162822 | 163008 | /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf */ |
| 162823 | 163009 | /* 0x */ 29, 28, 28, 28, 28, 7, 28, 28, 28, 28, 28, 28, 7, 7, 28, 28, |
| 162824 | 163010 | /* 1x */ 28, 28, 28, 28, 28, 7, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, |
| | @@ -163757,10 +163943,18 @@ |
| 163757 | 163943 | ** SQL keywords start with the letter 'x'. Fall through */ |
| 163758 | 163944 | /* no break */ deliberate_fall_through |
| 163759 | 163945 | } |
| 163760 | 163946 | case CC_KYWD: |
| 163761 | 163947 | case CC_ID: { |
| 163948 | + i = 1; |
| 163949 | + break; |
| 163950 | + } |
| 163951 | + case CC_BOM: { |
| 163952 | + if( z[1]==0xbb && z[2]==0xbf ){ |
| 163953 | + *tokenType = TK_SPACE; |
| 163954 | + return 3; |
| 163955 | + } |
| 163762 | 163956 | i = 1; |
| 163763 | 163957 | break; |
| 163764 | 163958 | } |
| 163765 | 163959 | case CC_NUL: { |
| 163766 | 163960 | *tokenType = TK_ILLEGAL; |
| | @@ -165745,11 +165939,11 @@ |
| 165745 | 165939 | } |
| 165746 | 165940 | |
| 165747 | 165941 | /* |
| 165748 | 165942 | ** Two variations on the public interface for closing a database |
| 165749 | 165943 | ** connection. The sqlite3_close() version returns SQLITE_BUSY and |
| 165750 | | -** leaves the connection option if there are unfinalized prepared |
| 165944 | +** leaves the connection open if there are unfinalized prepared |
| 165751 | 165945 | ** statements or unfinished sqlite3_backups. The sqlite3_close_v2() |
| 165752 | 165946 | ** version forces the connection to become a zombie if there are |
| 165753 | 165947 | ** unclosed resources, and arranges for deallocation when the last |
| 165754 | 165948 | ** prepare statement or sqlite3_backup closes. |
| 165755 | 165949 | */ |
| | @@ -175552,20 +175746,19 @@ |
| 175552 | 175746 | |
| 175553 | 175747 | /* Determine which, if any, tokens in the expression should be deferred. */ |
| 175554 | 175748 | #ifndef SQLITE_DISABLE_FTS4_DEFERRED |
| 175555 | 175749 | if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){ |
| 175556 | 175750 | Fts3TokenAndCost *aTC; |
| 175557 | | - Fts3Expr **apOr; |
| 175558 | 175751 | aTC = (Fts3TokenAndCost *)sqlite3_malloc64( |
| 175559 | 175752 | sizeof(Fts3TokenAndCost) * nToken |
| 175560 | 175753 | + sizeof(Fts3Expr *) * nOr * 2 |
| 175561 | 175754 | ); |
| 175562 | | - apOr = (Fts3Expr **)&aTC[nToken]; |
| 175563 | 175755 | |
| 175564 | 175756 | if( !aTC ){ |
| 175565 | 175757 | rc = SQLITE_NOMEM; |
| 175566 | 175758 | }else{ |
| 175759 | + Fts3Expr **apOr = (Fts3Expr **)&aTC[nToken]; |
| 175567 | 175760 | int ii; |
| 175568 | 175761 | Fts3TokenAndCost *pTC = aTC; |
| 175569 | 175762 | Fts3Expr **ppOr = apOr; |
| 175570 | 175763 | |
| 175571 | 175764 | fts3EvalTokenCosts(pCsr, 0, pCsr->pExpr, &pTC, &ppOr, &rc); |
| | @@ -176937,10 +177130,11 @@ |
| 176937 | 177130 | /* In case this cursor is being reused, close and zero it. */ |
| 176938 | 177131 | testcase(pCsr->filter.zTerm); |
| 176939 | 177132 | sqlite3Fts3SegReaderFinish(&pCsr->csr); |
| 176940 | 177133 | sqlite3_free((void *)pCsr->filter.zTerm); |
| 176941 | 177134 | sqlite3_free(pCsr->aStat); |
| 177135 | + sqlite3_free(pCsr->zStop); |
| 176942 | 177136 | memset(&pCsr->csr, 0, ((u8*)&pCsr[1]) - (u8*)&pCsr->csr); |
| 176943 | 177137 | |
| 176944 | 177138 | pCsr->filter.flags = FTS3_SEGMENT_REQUIRE_POS|FTS3_SEGMENT_IGNORE_EMPTY; |
| 176945 | 177139 | if( isScan ) pCsr->filter.flags |= FTS3_SEGMENT_SCAN; |
| 176946 | 177140 | |
| | @@ -182458,11 +182652,11 @@ |
| 182458 | 182652 | rc = (pLhs->aNode==0) - (pRhs->aNode==0); |
| 182459 | 182653 | } |
| 182460 | 182654 | if( rc==0 ){ |
| 182461 | 182655 | rc = pRhs->iIdx - pLhs->iIdx; |
| 182462 | 182656 | } |
| 182463 | | - assert( rc!=0 ); |
| 182657 | + assert_fts3_nc( rc!=0 ); |
| 182464 | 182658 | return rc; |
| 182465 | 182659 | } |
| 182466 | 182660 | |
| 182467 | 182661 | /* |
| 182468 | 182662 | ** A different comparison function for SegReader structures. In this |
| | @@ -186468,10 +186662,14 @@ |
| 186468 | 186662 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) |
| 186469 | 186663 | |
| 186470 | 186664 | /* #include <string.h> */ |
| 186471 | 186665 | /* #include <assert.h> */ |
| 186472 | 186666 | |
| 186667 | +#ifndef SQLITE_AMALGAMATION |
| 186668 | +typedef sqlite3_int64 i64; |
| 186669 | +#endif |
| 186670 | + |
| 186473 | 186671 | /* |
| 186474 | 186672 | ** Characters that may appear in the second argument to matchinfo(). |
| 186475 | 186673 | */ |
| 186476 | 186674 | #define FTS3_MATCHINFO_NPHRASE 'p' /* 1 value */ |
| 186477 | 186675 | #define FTS3_MATCHINFO_NCOL 'c' /* 1 value */ |
| | @@ -186518,13 +186716,13 @@ |
| 186518 | 186716 | }; |
| 186519 | 186717 | |
| 186520 | 186718 | struct SnippetPhrase { |
| 186521 | 186719 | int nToken; /* Number of tokens in phrase */ |
| 186522 | 186720 | char *pList; /* Pointer to start of phrase position list */ |
| 186523 | | - int iHead; /* Next value in position list */ |
| 186721 | + i64 iHead; /* Next value in position list */ |
| 186524 | 186722 | char *pHead; /* Position list data following iHead */ |
| 186525 | | - int iTail; /* Next value in trailing position list */ |
| 186723 | + i64 iTail; /* Next value in trailing position list */ |
| 186526 | 186724 | char *pTail; /* Position list data following iTail */ |
| 186527 | 186725 | }; |
| 186528 | 186726 | |
| 186529 | 186727 | struct SnippetFragment { |
| 186530 | 186728 | int iCol; /* Column snippet is extracted from */ |
| | @@ -186685,11 +186883,11 @@ |
| 186685 | 186883 | ** When this function is called, *pp points to the start of an element of |
| 186686 | 186884 | ** the list. *piPos contains the value of the previous entry in the list. |
| 186687 | 186885 | ** After it returns, *piPos contains the value of the next element of the |
| 186688 | 186886 | ** list and *pp is advanced to the following varint. |
| 186689 | 186887 | */ |
| 186690 | | -static void fts3GetDeltaPosition(char **pp, int *piPos){ |
| 186888 | +static void fts3GetDeltaPosition(char **pp, i64 *piPos){ |
| 186691 | 186889 | int iVal; |
| 186692 | 186890 | *pp += fts3GetVarint32(*pp, &iVal); |
| 186693 | 186891 | *piPos += (iVal-2); |
| 186694 | 186892 | } |
| 186695 | 186893 | |
| | @@ -186794,14 +186992,14 @@ |
| 186794 | 186992 | /* |
| 186795 | 186993 | ** Advance the position list iterator specified by the first two |
| 186796 | 186994 | ** arguments so that it points to the first element with a value greater |
| 186797 | 186995 | ** than or equal to parameter iNext. |
| 186798 | 186996 | */ |
| 186799 | | -static void fts3SnippetAdvance(char **ppIter, int *piIter, int iNext){ |
| 186997 | +static void fts3SnippetAdvance(char **ppIter, i64 *piIter, int iNext){ |
| 186800 | 186998 | char *pIter = *ppIter; |
| 186801 | 186999 | if( pIter ){ |
| 186802 | | - int iIter = *piIter; |
| 187000 | + i64 iIter = *piIter; |
| 186803 | 187001 | |
| 186804 | 187002 | while( iIter<iNext ){ |
| 186805 | 187003 | if( 0==(*pIter & 0xFE) ){ |
| 186806 | 187004 | iIter = -1; |
| 186807 | 187005 | pIter = 0; |
| | @@ -186880,11 +187078,11 @@ |
| 186880 | 187078 | |
| 186881 | 187079 | for(i=0; i<pIter->nPhrase; i++){ |
| 186882 | 187080 | SnippetPhrase *pPhrase = &pIter->aPhrase[i]; |
| 186883 | 187081 | if( pPhrase->pTail ){ |
| 186884 | 187082 | char *pCsr = pPhrase->pTail; |
| 186885 | | - int iCsr = pPhrase->iTail; |
| 187083 | + i64 iCsr = pPhrase->iTail; |
| 186886 | 187084 | |
| 186887 | 187085 | while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){ |
| 186888 | 187086 | int j; |
| 186889 | 187087 | u64 mPhrase = (u64)1 << (i%64); |
| 186890 | 187088 | u64 mPos = (u64)1 << (iCsr - iStart); |
| | @@ -186926,11 +187124,11 @@ |
| 186926 | 187124 | |
| 186927 | 187125 | pPhrase->nToken = pExpr->pPhrase->nToken; |
| 186928 | 187126 | rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pCsr); |
| 186929 | 187127 | assert( rc==SQLITE_OK || pCsr==0 ); |
| 186930 | 187128 | if( pCsr ){ |
| 186931 | | - int iFirst = 0; |
| 187129 | + i64 iFirst = 0; |
| 186932 | 187130 | pPhrase->pList = pCsr; |
| 186933 | 187131 | fts3GetDeltaPosition(&pCsr, &iFirst); |
| 186934 | 187132 | if( iFirst<0 ){ |
| 186935 | 187133 | rc = FTS_CORRUPT_VTAB; |
| 186936 | 187134 | }else{ |
| | @@ -187990,12 +188188,12 @@ |
| 187990 | 188188 | typedef struct TermOffset TermOffset; |
| 187991 | 188189 | typedef struct TermOffsetCtx TermOffsetCtx; |
| 187992 | 188190 | |
| 187993 | 188191 | struct TermOffset { |
| 187994 | 188192 | char *pList; /* Position-list */ |
| 187995 | | - int iPos; /* Position just read from pList */ |
| 187996 | | - int iOff; /* Offset of this term from read positions */ |
| 188193 | + i64 iPos; /* Position just read from pList */ |
| 188194 | + i64 iOff; /* Offset of this term from read positions */ |
| 187997 | 188195 | }; |
| 187998 | 188196 | |
| 187999 | 188197 | struct TermOffsetCtx { |
| 188000 | 188198 | Fts3Cursor *pCsr; |
| 188001 | 188199 | int iCol; /* Column of table to populate aTerm for */ |
| | @@ -188010,11 +188208,11 @@ |
| 188010 | 188208 | static int fts3ExprTermOffsetInit(Fts3Expr *pExpr, int iPhrase, void *ctx){ |
| 188011 | 188209 | TermOffsetCtx *p = (TermOffsetCtx *)ctx; |
| 188012 | 188210 | int nTerm; /* Number of tokens in phrase */ |
| 188013 | 188211 | int iTerm; /* For looping through nTerm phrase terms */ |
| 188014 | 188212 | char *pList; /* Pointer to position list for phrase */ |
| 188015 | | - int iPos = 0; /* First position in position-list */ |
| 188213 | + i64 iPos = 0; /* First position in position-list */ |
| 188016 | 188214 | int rc; |
| 188017 | 188215 | |
| 188018 | 188216 | UNUSED_PARAMETER(iPhrase); |
| 188019 | 188217 | rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pList); |
| 188020 | 188218 | nTerm = pExpr->pPhrase->nToken; |
| | @@ -190886,12 +191084,12 @@ |
| 190886 | 191084 | if( pStr->zBuf==0 ){ |
| 190887 | 191085 | jsonInit(pStr, ctx); |
| 190888 | 191086 | jsonAppendChar(pStr, '['); |
| 190889 | 191087 | }else if( pStr->nUsed>1 ){ |
| 190890 | 191088 | jsonAppendChar(pStr, ','); |
| 190891 | | - pStr->pCtx = ctx; |
| 190892 | 191089 | } |
| 191090 | + pStr->pCtx = ctx; |
| 190893 | 191091 | jsonAppendValue(pStr, argv[0]); |
| 190894 | 191092 | } |
| 190895 | 191093 | } |
| 190896 | 191094 | static void jsonArrayCompute(sqlite3_context *ctx, int isFinal){ |
| 190897 | 191095 | JsonString *pStr; |
| | @@ -190947,26 +191145,27 @@ |
| 190947 | 191145 | /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will |
| 190948 | 191146 | ** always have been called to initalize it */ |
| 190949 | 191147 | if( NEVER(!pStr) ) return; |
| 190950 | 191148 | #endif |
| 190951 | 191149 | z = pStr->zBuf; |
| 190952 | | - for(i=1; (c = z[i])!=',' || inStr || nNest; i++){ |
| 190953 | | - if( i>=pStr->nUsed ){ |
| 190954 | | - pStr->nUsed = 1; |
| 190955 | | - return; |
| 190956 | | - } |
| 191150 | + for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){ |
| 190957 | 191151 | if( c=='"' ){ |
| 190958 | 191152 | inStr = !inStr; |
| 190959 | 191153 | }else if( c=='\\' ){ |
| 190960 | 191154 | i++; |
| 190961 | 191155 | }else if( !inStr ){ |
| 190962 | 191156 | if( c=='{' || c=='[' ) nNest++; |
| 190963 | 191157 | if( c=='}' || c==']' ) nNest--; |
| 190964 | 191158 | } |
| 190965 | 191159 | } |
| 190966 | | - pStr->nUsed -= i; |
| 190967 | | - memmove(&z[1], &z[i+1], (size_t)pStr->nUsed-1); |
| 191160 | + if( i<pStr->nUsed ){ |
| 191161 | + pStr->nUsed -= i; |
| 191162 | + memmove(&z[1], &z[i+1], (size_t)pStr->nUsed-1); |
| 191163 | + z[pStr->nUsed] = 0; |
| 191164 | + }else{ |
| 191165 | + pStr->nUsed = 1; |
| 191166 | + } |
| 190968 | 191167 | } |
| 190969 | 191168 | #else |
| 190970 | 191169 | # define jsonGroupInverse 0 |
| 190971 | 191170 | #endif |
| 190972 | 191171 | |
| | @@ -195512,15 +195711,20 @@ |
| 195512 | 195711 | */ |
| 195513 | 195712 | static void rtreedepth(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){ |
| 195514 | 195713 | UNUSED_PARAMETER(nArg); |
| 195515 | 195714 | if( sqlite3_value_type(apArg[0])!=SQLITE_BLOB |
| 195516 | 195715 | || sqlite3_value_bytes(apArg[0])<2 |
| 195716 | + |
| 195517 | 195717 | ){ |
| 195518 | 195718 | sqlite3_result_error(ctx, "Invalid argument to rtreedepth()", -1); |
| 195519 | 195719 | }else{ |
| 195520 | 195720 | u8 *zBlob = (u8 *)sqlite3_value_blob(apArg[0]); |
| 195521 | | - sqlite3_result_int(ctx, readInt16(zBlob)); |
| 195721 | + if( zBlob ){ |
| 195722 | + sqlite3_result_int(ctx, readInt16(zBlob)); |
| 195723 | + }else{ |
| 195724 | + sqlite3_result_error_nomem(ctx); |
| 195725 | + } |
| 195522 | 195726 | } |
| 195523 | 195727 | } |
| 195524 | 195728 | |
| 195525 | 195729 | /* |
| 195526 | 195730 | ** Context object passed between the various routines that make up the |
| | @@ -206045,17 +206249,19 @@ |
| 206045 | 206249 | ** Session handle structure. |
| 206046 | 206250 | */ |
| 206047 | 206251 | struct sqlite3_session { |
| 206048 | 206252 | sqlite3 *db; /* Database handle session is attached to */ |
| 206049 | 206253 | char *zDb; /* Name of database session is attached to */ |
| 206254 | + int bEnableSize; /* True if changeset_size() enabled */ |
| 206050 | 206255 | int bEnable; /* True if currently recording */ |
| 206051 | 206256 | int bIndirect; /* True if all changes are indirect */ |
| 206052 | 206257 | int bAutoAttach; /* True to auto-attach tables */ |
| 206053 | 206258 | int rc; /* Non-zero if an error has occurred */ |
| 206054 | 206259 | void *pFilterCtx; /* First argument to pass to xTableFilter */ |
| 206055 | 206260 | int (*xTableFilter)(void *pCtx, const char *zTab); |
| 206056 | 206261 | i64 nMalloc; /* Number of bytes of data allocated */ |
| 206262 | + i64 nMaxChangesetSize; |
| 206057 | 206263 | sqlite3_value *pZeroBlob; /* Value containing X'' */ |
| 206058 | 206264 | sqlite3_session *pNext; /* Next session object on same db. */ |
| 206059 | 206265 | SessionTable *pTable; /* List of attached tables */ |
| 206060 | 206266 | SessionHook hook; /* APIs to grab new and old data with */ |
| 206061 | 206267 | }; |
| | @@ -206294,12 +206500,13 @@ |
| 206294 | 206500 | /* |
| 206295 | 206501 | ** For each row modified during a session, there exists a single instance of |
| 206296 | 206502 | ** this structure stored in a SessionTable.aChange[] hash table. |
| 206297 | 206503 | */ |
| 206298 | 206504 | struct SessionChange { |
| 206299 | | - int op; /* One of UPDATE, DELETE, INSERT */ |
| 206300 | | - int bIndirect; /* True if this change is "indirect" */ |
| 206505 | + u8 op; /* One of UPDATE, DELETE, INSERT */ |
| 206506 | + u8 bIndirect; /* True if this change is "indirect" */ |
| 206507 | + int nMaxSize; /* Max size of eventual changeset record */ |
| 206301 | 206508 | int nRecord; /* Number of bytes in buffer aRecord[] */ |
| 206302 | 206509 | u8 *aRecord; /* Buffer containing old.* record */ |
| 206303 | 206510 | SessionChange *pNext; /* For hash-table collisions */ |
| 206304 | 206511 | }; |
| 206305 | 206512 | |
| | @@ -207124,10 +207331,16 @@ |
| 207124 | 207331 | } |
| 207125 | 207332 | } |
| 207126 | 207333 | if( 0==sqlite3_stricmp("sqlite_stat1", pTab->zName) ){ |
| 207127 | 207334 | pTab->bStat1 = 1; |
| 207128 | 207335 | } |
| 207336 | + |
| 207337 | + if( pSession->bEnableSize ){ |
| 207338 | + pSession->nMaxChangesetSize += ( |
| 207339 | + 1 + sessionVarintLen(pTab->nCol) + pTab->nCol + strlen(pTab->zName)+1 |
| 207340 | + ); |
| 207341 | + } |
| 207129 | 207342 | } |
| 207130 | 207343 | } |
| 207131 | 207344 | return (pSession->rc || pTab->abPK==0); |
| 207132 | 207345 | } |
| 207133 | 207346 | |
| | @@ -207169,10 +207382,107 @@ |
| 207169 | 207382 | static int sessionStat1Depth(void *pCtx){ |
| 207170 | 207383 | SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx; |
| 207171 | 207384 | return p->hook.xDepth(p->hook.pCtx); |
| 207172 | 207385 | } |
| 207173 | 207386 | |
| 207387 | +static int sessionUpdateMaxSize( |
| 207388 | + int op, |
| 207389 | + sqlite3_session *pSession, /* Session object pTab is attached to */ |
| 207390 | + SessionTable *pTab, /* Table that change applies to */ |
| 207391 | + SessionChange *pC /* Update pC->nMaxSize */ |
| 207392 | +){ |
| 207393 | + i64 nNew = 2; |
| 207394 | + if( pC->op==SQLITE_INSERT ){ |
| 207395 | + if( op!=SQLITE_DELETE ){ |
| 207396 | + int ii; |
| 207397 | + for(ii=0; ii<pTab->nCol; ii++){ |
| 207398 | + sqlite3_value *p = 0; |
| 207399 | + pSession->hook.xNew(pSession->hook.pCtx, ii, &p); |
| 207400 | + sessionSerializeValue(0, p, &nNew); |
| 207401 | + } |
| 207402 | + } |
| 207403 | + }else if( op==SQLITE_DELETE ){ |
| 207404 | + nNew += pC->nRecord; |
| 207405 | + if( sqlite3_preupdate_blobwrite(pSession->db)>=0 ){ |
| 207406 | + nNew += pC->nRecord; |
| 207407 | + } |
| 207408 | + }else{ |
| 207409 | + int ii; |
| 207410 | + u8 *pCsr = pC->aRecord; |
| 207411 | + for(ii=0; ii<pTab->nCol; ii++){ |
| 207412 | + int bChanged = 1; |
| 207413 | + int nOld = 0; |
| 207414 | + int eType; |
| 207415 | + sqlite3_value *p = 0; |
| 207416 | + pSession->hook.xNew(pSession->hook.pCtx, ii, &p); |
| 207417 | + if( p==0 ){ |
| 207418 | + return SQLITE_NOMEM; |
| 207419 | + } |
| 207420 | + |
| 207421 | + eType = *pCsr++; |
| 207422 | + switch( eType ){ |
| 207423 | + case SQLITE_NULL: |
| 207424 | + bChanged = sqlite3_value_type(p)!=SQLITE_NULL; |
| 207425 | + break; |
| 207426 | + |
| 207427 | + case SQLITE_FLOAT: |
| 207428 | + case SQLITE_INTEGER: { |
| 207429 | + if( eType==sqlite3_value_type(p) ){ |
| 207430 | + sqlite3_int64 iVal = sessionGetI64(pCsr); |
| 207431 | + if( eType==SQLITE_INTEGER ){ |
| 207432 | + bChanged = (iVal!=sqlite3_value_int64(p)); |
| 207433 | + }else{ |
| 207434 | + double dVal; |
| 207435 | + memcpy(&dVal, &iVal, 8); |
| 207436 | + bChanged = (dVal!=sqlite3_value_double(p)); |
| 207437 | + } |
| 207438 | + } |
| 207439 | + nOld = 8; |
| 207440 | + pCsr += 8; |
| 207441 | + break; |
| 207442 | + } |
| 207443 | + |
| 207444 | + default: { |
| 207445 | + int nByte; |
| 207446 | + nOld = sessionVarintGet(pCsr, &nByte); |
| 207447 | + pCsr += nOld; |
| 207448 | + nOld += nByte; |
| 207449 | + assert( eType==SQLITE_TEXT || eType==SQLITE_BLOB ); |
| 207450 | + if( eType==sqlite3_value_type(p) |
| 207451 | + && nByte==sqlite3_value_bytes(p) |
| 207452 | + && (nByte==0 || 0==memcmp(pCsr, sqlite3_value_blob(p), nByte)) |
| 207453 | + ){ |
| 207454 | + bChanged = 0; |
| 207455 | + } |
| 207456 | + pCsr += nByte; |
| 207457 | + break; |
| 207458 | + } |
| 207459 | + } |
| 207460 | + |
| 207461 | + if( bChanged && pTab->abPK[ii] ){ |
| 207462 | + nNew = pC->nRecord + 2; |
| 207463 | + break; |
| 207464 | + } |
| 207465 | + |
| 207466 | + if( bChanged ){ |
| 207467 | + nNew += 1 + nOld; |
| 207468 | + sessionSerializeValue(0, p, &nNew); |
| 207469 | + }else if( pTab->abPK[ii] ){ |
| 207470 | + nNew += 2 + nOld; |
| 207471 | + }else{ |
| 207472 | + nNew += 2; |
| 207473 | + } |
| 207474 | + } |
| 207475 | + } |
| 207476 | + |
| 207477 | + if( nNew>pC->nMaxSize ){ |
| 207478 | + int nIncr = nNew - pC->nMaxSize; |
| 207479 | + pC->nMaxSize = nNew; |
| 207480 | + pSession->nMaxChangesetSize += nIncr; |
| 207481 | + } |
| 207482 | + return SQLITE_OK; |
| 207483 | +} |
| 207174 | 207484 | |
| 207175 | 207485 | /* |
| 207176 | 207486 | ** This function is only called from with a pre-update-hook reporting a |
| 207177 | 207487 | ** change on table pTab (attached to session pSession). The type of change |
| 207178 | 207488 | ** (UPDATE, INSERT, DELETE) is specified by the first argument. |
| | @@ -207242,11 +207552,10 @@ |
| 207242 | 207552 | |
| 207243 | 207553 | if( pC==0 ){ |
| 207244 | 207554 | /* Create a new change object containing all the old values (if |
| 207245 | 207555 | ** this is an SQLITE_UPDATE or SQLITE_DELETE), or just the PK |
| 207246 | 207556 | ** values (if this is an INSERT). */ |
| 207247 | | - SessionChange *pChange; /* New change object */ |
| 207248 | 207557 | sqlite3_int64 nByte; /* Number of bytes to allocate */ |
| 207249 | 207558 | int i; /* Used to iterate through columns */ |
| 207250 | 207559 | |
| 207251 | 207560 | assert( rc==SQLITE_OK ); |
| 207252 | 207561 | pTab->nEntry++; |
| | @@ -207268,17 +207577,17 @@ |
| 207268 | 207577 | rc = sessionSerializeValue(0, p, &nByte); |
| 207269 | 207578 | if( rc!=SQLITE_OK ) goto error_out; |
| 207270 | 207579 | } |
| 207271 | 207580 | |
| 207272 | 207581 | /* Allocate the change object */ |
| 207273 | | - pChange = (SessionChange *)sessionMalloc64(pSession, nByte); |
| 207274 | | - if( !pChange ){ |
| 207582 | + pC = (SessionChange *)sessionMalloc64(pSession, nByte); |
| 207583 | + if( !pC ){ |
| 207275 | 207584 | rc = SQLITE_NOMEM; |
| 207276 | 207585 | goto error_out; |
| 207277 | 207586 | }else{ |
| 207278 | | - memset(pChange, 0, sizeof(SessionChange)); |
| 207279 | | - pChange->aRecord = (u8 *)&pChange[1]; |
| 207587 | + memset(pC, 0, sizeof(SessionChange)); |
| 207588 | + pC->aRecord = (u8 *)&pC[1]; |
| 207280 | 207589 | } |
| 207281 | 207590 | |
| 207282 | 207591 | /* Populate the change object. None of the preupdate_old(), |
| 207283 | 207592 | ** preupdate_new() or SerializeValue() calls below may fail as all |
| 207284 | 207593 | ** required values and encodings have already been cached in memory. |
| | @@ -207289,21 +207598,21 @@ |
| 207289 | 207598 | if( op!=SQLITE_INSERT ){ |
| 207290 | 207599 | pSession->hook.xOld(pSession->hook.pCtx, i, &p); |
| 207291 | 207600 | }else if( pTab->abPK[i] ){ |
| 207292 | 207601 | pSession->hook.xNew(pSession->hook.pCtx, i, &p); |
| 207293 | 207602 | } |
| 207294 | | - sessionSerializeValue(&pChange->aRecord[nByte], p, &nByte); |
| 207603 | + sessionSerializeValue(&pC->aRecord[nByte], p, &nByte); |
| 207295 | 207604 | } |
| 207296 | 207605 | |
| 207297 | 207606 | /* Add the change to the hash-table */ |
| 207298 | 207607 | if( pSession->bIndirect || pSession->hook.xDepth(pSession->hook.pCtx) ){ |
| 207299 | | - pChange->bIndirect = 1; |
| 207608 | + pC->bIndirect = 1; |
| 207300 | 207609 | } |
| 207301 | | - pChange->nRecord = nByte; |
| 207302 | | - pChange->op = op; |
| 207303 | | - pChange->pNext = pTab->apChange[iHash]; |
| 207304 | | - pTab->apChange[iHash] = pChange; |
| 207610 | + pC->nRecord = nByte; |
| 207611 | + pC->op = op; |
| 207612 | + pC->pNext = pTab->apChange[iHash]; |
| 207613 | + pTab->apChange[iHash] = pC; |
| 207305 | 207614 | |
| 207306 | 207615 | }else if( pC->bIndirect ){ |
| 207307 | 207616 | /* If the existing change is considered "indirect", but this current |
| 207308 | 207617 | ** change is "direct", mark the change object as direct. */ |
| 207309 | 207618 | if( pSession->hook.xDepth(pSession->hook.pCtx)==0 |
| | @@ -207310,11 +207619,17 @@ |
| 207310 | 207619 | && pSession->bIndirect==0 |
| 207311 | 207620 | ){ |
| 207312 | 207621 | pC->bIndirect = 0; |
| 207313 | 207622 | } |
| 207314 | 207623 | } |
| 207624 | + |
| 207625 | + assert( rc==SQLITE_OK ); |
| 207626 | + if( pSession->bEnableSize ){ |
| 207627 | + rc = sessionUpdateMaxSize(op, pSession, pTab, pC); |
| 207628 | + } |
| 207315 | 207629 | } |
| 207630 | + |
| 207316 | 207631 | |
| 207317 | 207632 | /* If an error has occurred, mark the session object as failed. */ |
| 207318 | 207633 | error_out: |
| 207319 | 207634 | if( pTab->bStat1 ){ |
| 207320 | 207635 | pSession->hook = stat1.hook; |
| | @@ -208523,11 +208838,15 @@ |
| 208523 | 208838 | SQLITE_API int sqlite3session_changeset( |
| 208524 | 208839 | sqlite3_session *pSession, /* Session object */ |
| 208525 | 208840 | int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */ |
| 208526 | 208841 | void **ppChangeset /* OUT: Buffer containing changeset */ |
| 208527 | 208842 | ){ |
| 208528 | | - return sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset, ppChangeset); |
| 208843 | + int rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset,ppChangeset); |
| 208844 | + assert( rc || pnChangeset==0 |
| 208845 | + || pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize |
| 208846 | + ); |
| 208847 | + return rc; |
| 208529 | 208848 | } |
| 208530 | 208849 | |
| 208531 | 208850 | /* |
| 208532 | 208851 | ** Streaming version of sqlite3session_changeset(). |
| 208533 | 208852 | */ |
| | @@ -208614,10 +208933,43 @@ |
| 208614 | 208933 | ** Return the amount of heap memory in use. |
| 208615 | 208934 | */ |
| 208616 | 208935 | SQLITE_API sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession){ |
| 208617 | 208936 | return pSession->nMalloc; |
| 208618 | 208937 | } |
| 208938 | + |
| 208939 | +/* |
| 208940 | +** Configure the session object passed as the first argument. |
| 208941 | +*/ |
| 208942 | +SQLITE_API int sqlite3session_object_config(sqlite3_session *pSession, int op, void *pArg){ |
| 208943 | + int rc = SQLITE_OK; |
| 208944 | + switch( op ){ |
| 208945 | + case SQLITE_SESSION_OBJCONFIG_SIZE: { |
| 208946 | + int iArg = *(int*)pArg; |
| 208947 | + if( iArg>=0 ){ |
| 208948 | + if( pSession->pTable ){ |
| 208949 | + rc = SQLITE_MISUSE; |
| 208950 | + }else{ |
| 208951 | + pSession->bEnableSize = (iArg!=0); |
| 208952 | + } |
| 208953 | + } |
| 208954 | + *(int*)pArg = pSession->bEnableSize; |
| 208955 | + break; |
| 208956 | + } |
| 208957 | + |
| 208958 | + default: |
| 208959 | + rc = SQLITE_MISUSE; |
| 208960 | + } |
| 208961 | + |
| 208962 | + return rc; |
| 208963 | +} |
| 208964 | + |
| 208965 | +/* |
| 208966 | +** Return the maximum size of sqlite3session_changeset() output. |
| 208967 | +*/ |
| 208968 | +SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession){ |
| 208969 | + return pSession->nMaxChangesetSize; |
| 208970 | +} |
| 208619 | 208971 | |
| 208620 | 208972 | /* |
| 208621 | 208973 | ** Do the work for either sqlite3changeset_start() or start_strm(). |
| 208622 | 208974 | */ |
| 208623 | 208975 | static int sessionChangesetStart( |
| | @@ -216198,11 +216550,11 @@ |
| 216198 | 216550 | pRet->db = db; |
| 216199 | 216551 | pRet->iCookie = -1; |
| 216200 | 216552 | |
| 216201 | 216553 | nByte = nArg * (sizeof(char*) + sizeof(u8)); |
| 216202 | 216554 | pRet->azCol = (char**)sqlite3Fts5MallocZero(&rc, nByte); |
| 216203 | | - pRet->abUnindexed = (u8*)&pRet->azCol[nArg]; |
| 216555 | + pRet->abUnindexed = pRet->azCol ? (u8*)&pRet->azCol[nArg] : 0; |
| 216204 | 216556 | pRet->zDb = sqlite3Fts5Strndup(&rc, azArg[1], -1); |
| 216205 | 216557 | pRet->zName = sqlite3Fts5Strndup(&rc, azArg[2], -1); |
| 216206 | 216558 | pRet->bColumnsize = 1; |
| 216207 | 216559 | pRet->eDetail = FTS5_DETAIL_FULL; |
| 216208 | 216560 | #ifdef SQLITE_DEBUG |
| | @@ -219034,10 +219386,11 @@ |
| 219034 | 219386 | } |
| 219035 | 219387 | |
| 219036 | 219388 | return pRet; |
| 219037 | 219389 | } |
| 219038 | 219390 | |
| 219391 | +#ifdef SQLITE_TEST |
| 219039 | 219392 | static char *fts5ExprTermPrint(Fts5ExprTerm *pTerm){ |
| 219040 | 219393 | sqlite3_int64 nByte = 0; |
| 219041 | 219394 | Fts5ExprTerm *p; |
| 219042 | 219395 | char *zQuoted; |
| 219043 | 219396 | |
| | @@ -219400,16 +219753,18 @@ |
| 219400 | 219753 | iCode = sqlite3_value_int(apVal[0]); |
| 219401 | 219754 | if( nArg==2 ) bRemoveDiacritics = sqlite3_value_int(apVal[1]); |
| 219402 | 219755 | sqlite3_result_int(pCtx, sqlite3Fts5UnicodeFold(iCode, bRemoveDiacritics)); |
| 219403 | 219756 | } |
| 219404 | 219757 | } |
| 219758 | +#endif /* ifdef SQLITE_TEST */ |
| 219405 | 219759 | |
| 219406 | 219760 | /* |
| 219407 | 219761 | ** This is called during initialization to register the fts5_expr() scalar |
| 219408 | 219762 | ** UDF with the SQLite handle passed as the only argument. |
| 219409 | 219763 | */ |
| 219410 | 219764 | static int sqlite3Fts5ExprInit(Fts5Global *pGlobal, sqlite3 *db){ |
| 219765 | +#ifdef SQLITE_TEST |
| 219411 | 219766 | struct Fts5ExprFunc { |
| 219412 | 219767 | const char *z; |
| 219413 | 219768 | void (*x)(sqlite3_context*,int,sqlite3_value**); |
| 219414 | 219769 | } aFunc[] = { |
| 219415 | 219770 | { "fts5_expr", fts5ExprFunctionHr }, |
| | @@ -219423,10 +219778,14 @@ |
| 219423 | 219778 | |
| 219424 | 219779 | for(i=0; rc==SQLITE_OK && i<ArraySize(aFunc); i++){ |
| 219425 | 219780 | struct Fts5ExprFunc *p = &aFunc[i]; |
| 219426 | 219781 | rc = sqlite3_create_function(db, p->z, -1, SQLITE_UTF8, pCtx, p->x, 0, 0); |
| 219427 | 219782 | } |
| 219783 | +#else |
| 219784 | + int rc = SQLITE_OK; |
| 219785 | + UNUSED_PARAM2(pGlobal,db); |
| 219786 | +#endif |
| 219428 | 219787 | |
| 219429 | 219788 | /* Avoid warnings indicating that sqlite3Fts5ParserTrace() and |
| 219430 | 219789 | ** sqlite3Fts5ParserFallback() are unused */ |
| 219431 | 219790 | #ifndef NDEBUG |
| 219432 | 219791 | (void)sqlite3Fts5ParserTrace; |
| | @@ -220669,11 +221028,11 @@ |
| 220669 | 221028 | Fts5StructureSegment *pSeg; /* Segment to iterate through */ |
| 220670 | 221029 | int flags; /* Mask of configuration flags */ |
| 220671 | 221030 | int iLeafPgno; /* Current leaf page number */ |
| 220672 | 221031 | Fts5Data *pLeaf; /* Current leaf data */ |
| 220673 | 221032 | Fts5Data *pNextLeaf; /* Leaf page (iLeafPgno+1) */ |
| 220674 | | - int iLeafOffset; /* Byte offset within current leaf */ |
| 221033 | + i64 iLeafOffset; /* Byte offset within current leaf */ |
| 220675 | 221034 | |
| 220676 | 221035 | /* Next method */ |
| 220677 | 221036 | void (*xNext)(Fts5Index*, Fts5SegIter*, int*); |
| 220678 | 221037 | |
| 220679 | 221038 | /* The page and offset from which the current term was read. The offset |
| | @@ -221849,11 +222208,11 @@ |
| 221849 | 222208 | } |
| 221850 | 222209 | } |
| 221851 | 222210 | |
| 221852 | 222211 | static void fts5SegIterLoadRowid(Fts5Index *p, Fts5SegIter *pIter){ |
| 221853 | 222212 | u8 *a = pIter->pLeaf->p; /* Buffer to read data from */ |
| 221854 | | - int iOff = pIter->iLeafOffset; |
| 222213 | + i64 iOff = pIter->iLeafOffset; |
| 221855 | 222214 | |
| 221856 | 222215 | ASSERT_SZLEAF_OK(pIter->pLeaf); |
| 221857 | 222216 | if( iOff>=pIter->pLeaf->szLeaf ){ |
| 221858 | 222217 | fts5SegIterNextPage(p, pIter); |
| 221859 | 222218 | if( pIter->pLeaf==0 ){ |
| | @@ -221882,11 +222241,11 @@ |
| 221882 | 222241 | ** the first position list. The position list belonging to document |
| 221883 | 222242 | ** (Fts5SegIter.iRowid). |
| 221884 | 222243 | */ |
| 221885 | 222244 | static void fts5SegIterLoadTerm(Fts5Index *p, Fts5SegIter *pIter, int nKeep){ |
| 221886 | 222245 | u8 *a = pIter->pLeaf->p; /* Buffer to read data from */ |
| 221887 | | - int iOff = pIter->iLeafOffset; /* Offset to read at */ |
| 222246 | + i64 iOff = pIter->iLeafOffset; /* Offset to read at */ |
| 221888 | 222247 | int nNew; /* Bytes of new data */ |
| 221889 | 222248 | |
| 221890 | 222249 | iOff += fts5GetVarint32(&a[iOff], nNew); |
| 221891 | 222250 | if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){ |
| 221892 | 222251 | p->rc = FTS5_CORRUPT; |
| | @@ -224779,18 +225138,18 @@ |
| 224779 | 225138 | if( pgsz>=(pBuf->n + pPgidx->n + nDoclist + 1) ){ |
| 224780 | 225139 | /* The entire doclist will fit on the current leaf. */ |
| 224781 | 225140 | fts5BufferSafeAppendBlob(pBuf, pDoclist, nDoclist); |
| 224782 | 225141 | }else{ |
| 224783 | 225142 | i64 iRowid = 0; |
| 224784 | | - i64 iDelta = 0; |
| 225143 | + u64 iDelta = 0; |
| 224785 | 225144 | int iOff = 0; |
| 224786 | 225145 | |
| 224787 | 225146 | /* The entire doclist will not fit on this leaf. The following |
| 224788 | 225147 | ** loop iterates through the poslists that make up the current |
| 224789 | 225148 | ** doclist. */ |
| 224790 | 225149 | while( p->rc==SQLITE_OK && iOff<nDoclist ){ |
| 224791 | | - iOff += fts5GetVarint(&pDoclist[iOff], (u64*)&iDelta); |
| 225150 | + iOff += fts5GetVarint(&pDoclist[iOff], &iDelta); |
| 224792 | 225151 | iRowid += iDelta; |
| 224793 | 225152 | |
| 224794 | 225153 | if( writer.bFirstRowidInPage ){ |
| 224795 | 225154 | fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */ |
| 224796 | 225155 | pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid); |
| | @@ -225317,11 +225676,12 @@ |
| 225317 | 225676 | sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, pHead->iPos); |
| 225318 | 225677 | } |
| 225319 | 225678 | nTail = pHead->iter.nPoslist - pHead->iOff; |
| 225320 | 225679 | |
| 225321 | 225680 | /* WRITEPOSLISTSIZE */ |
| 225322 | | - assert( tmp.n+nTail<=nTmp ); |
| 225681 | + assert_nc( tmp.n+nTail<=nTmp ); |
| 225682 | + assert( tmp.n+nTail<=nTmp+nMerge*10 ); |
| 225323 | 225683 | if( tmp.n+nTail>nTmp-FTS5_DATA_ZERO_PADDING ){ |
| 225324 | 225684 | if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT; |
| 225325 | 225685 | break; |
| 225326 | 225686 | } |
| 225327 | 225687 | fts5BufferSafeAppendVarint(&out, (tmp.n+nTail) * 2); |
| | @@ -226958,10 +227318,11 @@ |
| 226958 | 227318 | ); |
| 226959 | 227319 | } |
| 226960 | 227320 | return rc; |
| 226961 | 227321 | #else |
| 226962 | 227322 | return SQLITE_OK; |
| 227323 | + UNUSED_PARAM(db); |
| 226963 | 227324 | #endif |
| 226964 | 227325 | } |
| 226965 | 227326 | |
| 226966 | 227327 | |
| 226967 | 227328 | static int sqlite3Fts5IndexReset(Fts5Index *p){ |
| | @@ -229762,11 +230123,11 @@ |
| 229762 | 230123 | int nArg, /* Number of args */ |
| 229763 | 230124 | sqlite3_value **apUnused /* Function arguments */ |
| 229764 | 230125 | ){ |
| 229765 | 230126 | assert( nArg==0 ); |
| 229766 | 230127 | UNUSED_PARAM2(nArg, apUnused); |
| 229767 | | - sqlite3_result_text(pCtx, "fts5: 2021-04-07 13:20:34 c22e47c77a35ebcd1fdfc0caea9119dd5e24e76d5fdd0f2ffbb58205a7242297", -1, SQLITE_TRANSIENT); |
| 230128 | + sqlite3_result_text(pCtx, "fts5: 2021-04-27 17:18:10 ff3538ae37a02f4f36a15cddd1245171e724aac9c84b2e576980fd3806302775", -1, SQLITE_TRANSIENT); |
| 229768 | 230129 | } |
| 229769 | 230130 | |
| 229770 | 230131 | /* |
| 229771 | 230132 | ** Return true if zName is the extension on one of the shadow tables used |
| 229772 | 230133 | ** by this module. |
| | @@ -234688,12 +235049,12 @@ |
| 234688 | 235049 | } |
| 234689 | 235050 | #endif /* SQLITE_CORE */ |
| 234690 | 235051 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 234691 | 235052 | |
| 234692 | 235053 | /************** End of stmt.c ************************************************/ |
| 234693 | | -#if __LINE__!=234693 |
| 235054 | +#if __LINE__!=235054 |
| 234694 | 235055 | #undef SQLITE_SOURCE_ID |
| 234695 | | -#define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e158alt2" |
| 235056 | +#define SQLITE_SOURCE_ID "2021-04-28 17:37:26 65ec39f0f092fe29e1d4e9e96cf07a73d2ef7ce2c41b6f1cd3ab23546adaalt2" |
| 234696 | 235057 | #endif |
| 234697 | 235058 | /* Return the source-id for this library */ |
| 234698 | 235059 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 234699 | 235060 | /************************** End of sqlite3.c ******************************/ |
| 234700 | 235061 | |