| | @@ -1162,11 +1162,11 @@ |
| 1162 | 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | 1164 | */ |
| 1165 | 1165 | #define SQLITE_VERSION "3.28.0" |
| 1166 | 1166 | #define SQLITE_VERSION_NUMBER 3028000 |
| 1167 | | -#define SQLITE_SOURCE_ID "2019-02-25 14:52:43 9da4fb59b28686630d63a79988b458726332cf06cc0e6e84d7c0a7600f5fcab0" |
| 1167 | +#define SQLITE_SOURCE_ID "2019-03-17 23:59:02 cc5ab96715ebb1089b4e9aa647badd2510aaa056f26004718f921f4ac07e2f93" |
| 1168 | 1168 | |
| 1169 | 1169 | /* |
| 1170 | 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | 1172 | ** |
| | @@ -3123,12 +3123,12 @@ |
| 3123 | 3123 | ** following this call. The second parameter may be a NULL pointer, in |
| 3124 | 3124 | ** which case the trigger setting is not reported back. </dd> |
| 3125 | 3125 | ** |
| 3126 | 3126 | ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]] |
| 3127 | 3127 | ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt> |
| 3128 | | -** <dd> ^This option is used to enable or disable the two-argument |
| 3129 | | -** version of the [fts3_tokenizer()] function which is part of the |
| 3128 | +** <dd> ^This option is used to enable or disable the |
| 3129 | +** [fts3_tokenizer()] function which is part of the |
| 3130 | 3130 | ** [FTS3] full-text search engine extension. |
| 3131 | 3131 | ** There should be two additional arguments. |
| 3132 | 3132 | ** The first argument is an integer which is 0 to disable fts3_tokenizer() or |
| 3133 | 3133 | ** positive to enable fts3_tokenizer() or negative to leave the setting |
| 3134 | 3134 | ** unchanged. |
| | @@ -4931,10 +4931,22 @@ |
| 4931 | 4931 | ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so |
| 4932 | 4932 | ** sqlite3_stmt_readonly() returns false for those commands. |
| 4933 | 4933 | */ |
| 4934 | 4934 | SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); |
| 4935 | 4935 | |
| 4936 | +/* |
| 4937 | +** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement |
| 4938 | +** METHOD: sqlite3_stmt |
| 4939 | +** |
| 4940 | +** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the |
| 4941 | +** prepared statement S is an EXPLAIN statement, or 2 if the |
| 4942 | +** statement S is an EXPLAIN QUERY PLAN. |
| 4943 | +** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is |
| 4944 | +** an ordinary statement or a NULL pointer. |
| 4945 | +*/ |
| 4946 | +SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt); |
| 4947 | + |
| 4936 | 4948 | /* |
| 4937 | 4949 | ** CAPI3REF: Determine If A Prepared Statement Has Been Reset |
| 4938 | 4950 | ** METHOD: sqlite3_stmt |
| 4939 | 4951 | ** |
| 4940 | 4952 | ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the |
| | @@ -5070,11 +5082,13 @@ |
| 5070 | 5082 | ** with embedded NULs is undefined. |
| 5071 | 5083 | ** |
| 5072 | 5084 | ** ^The fifth argument to the BLOB and string binding interfaces |
| 5073 | 5085 | ** is a destructor used to dispose of the BLOB or |
| 5074 | 5086 | ** string after SQLite has finished with it. ^The destructor is called |
| 5075 | | -** to dispose of the BLOB or string even if the call to bind API fails. |
| 5087 | +** to dispose of the BLOB or string even if the call to the bind API fails, |
| 5088 | +** except the destructor is not called if the third parameter is a NULL |
| 5089 | +** pointer or the fourth parameter is negative. |
| 5076 | 5090 | ** ^If the fifth argument is |
| 5077 | 5091 | ** the special value [SQLITE_STATIC], then SQLite assumes that the |
| 5078 | 5092 | ** information is in static, unmanaged space and does not need to be freed. |
| 5079 | 5093 | ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then |
| 5080 | 5094 | ** SQLite makes its own private copy of the data immediately, before |
| | @@ -6828,11 +6842,11 @@ |
| 6828 | 6842 | ** |
| 6829 | 6843 | ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename |
| 6830 | 6844 | ** associated with database N of connection D. ^The main database file |
| 6831 | 6845 | ** has the name "main". If there is no attached database N on the database |
| 6832 | 6846 | ** connection D, or if database N is a temporary or in-memory database, then |
| 6833 | | -** a NULL pointer is returned. |
| 6847 | +** this function will return either a NULL pointer or an empty string. |
| 6834 | 6848 | ** |
| 6835 | 6849 | ** ^The filename returned by this function is the output of the |
| 6836 | 6850 | ** xFullPathname method of the [VFS]. ^In other words, the filename |
| 6837 | 6851 | ** will be an absolute pathname, even if the filename used |
| 6838 | 6852 | ** to open the database originally was a URI or relative pathname. |
| | @@ -40220,13 +40234,10 @@ |
| 40220 | 40234 | static sqlite3_vfs aVfs[] = { |
| 40221 | 40235 | #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) |
| 40222 | 40236 | UNIXVFS("unix", autolockIoFinder ), |
| 40223 | 40237 | #elif OS_VXWORKS |
| 40224 | 40238 | UNIXVFS("unix", vxworksIoFinder ), |
| 40225 | | -#elif __Fuchsia__ |
| 40226 | | - /* We are told that Fuchsia only supports dot-file locking */ |
| 40227 | | - UNIXVFS("unix", dotlockIoFinder ), |
| 40228 | 40239 | #else |
| 40229 | 40240 | UNIXVFS("unix", posixIoFinder ), |
| 40230 | 40241 | #endif |
| 40231 | 40242 | UNIXVFS("unix-none", nolockIoFinder ), |
| 40232 | 40243 | UNIXVFS("unix-dotfile", dotlockIoFinder ), |
| | @@ -51308,10 +51319,13 @@ |
| 51308 | 51319 | ** * the desired page is not currently in the wal file. |
| 51309 | 51320 | */ |
| 51310 | 51321 | SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){ |
| 51311 | 51322 | if( pPager->fd->pMethods==0 ) return 0; |
| 51312 | 51323 | if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0; |
| 51324 | +#ifdef SQLITE_HAS_CODEC |
| 51325 | + if( pPager->xCodec!=0 ) return 0; |
| 51326 | +#endif |
| 51313 | 51327 | #ifndef SQLITE_OMIT_WAL |
| 51314 | 51328 | if( pPager->pWal ){ |
| 51315 | 51329 | u32 iRead = 0; |
| 51316 | 51330 | int rc; |
| 51317 | 51331 | rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead); |
| | @@ -54257,12 +54271,18 @@ |
| 54257 | 54271 | |
| 54258 | 54272 | if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){ |
| 54259 | 54273 | rc = sqlite3OsFileSize(pPager->fd, &nByte); |
| 54260 | 54274 | } |
| 54261 | 54275 | if( rc==SQLITE_OK ){ |
| 54262 | | - pNew = (char *)sqlite3PageMalloc(pageSize); |
| 54263 | | - if( !pNew ) rc = SQLITE_NOMEM_BKPT; |
| 54276 | + /* 8 bytes of zeroed overrun space is sufficient so that the b-tree |
| 54277 | + * cell header parser will never run off the end of the allocation */ |
| 54278 | + pNew = (char *)sqlite3PageMalloc(pageSize+8); |
| 54279 | + if( !pNew ){ |
| 54280 | + rc = SQLITE_NOMEM_BKPT; |
| 54281 | + }else{ |
| 54282 | + memset(pNew+pageSize, 0, 8); |
| 54283 | + } |
| 54264 | 54284 | } |
| 54265 | 54285 | |
| 54266 | 54286 | if( rc==SQLITE_OK ){ |
| 54267 | 54287 | pager_reset(pPager); |
| 54268 | 54288 | rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize); |
| | @@ -57639,12 +57659,16 @@ |
| 57639 | 57659 | ** page pgno before the 'move' operation, it needs to be retained |
| 57640 | 57660 | ** for the page moved there. |
| 57641 | 57661 | */ |
| 57642 | 57662 | pPg->flags &= ~PGHDR_NEED_SYNC; |
| 57643 | 57663 | pPgOld = sqlite3PagerLookup(pPager, pgno); |
| 57644 | | - assert( !pPgOld || pPgOld->nRef==1 ); |
| 57664 | + assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB ); |
| 57645 | 57665 | if( pPgOld ){ |
| 57666 | + if( pPgOld->nRef>1 ){ |
| 57667 | + sqlite3PagerUnrefNotNull(pPgOld); |
| 57668 | + return SQLITE_CORRUPT_BKPT; |
| 57669 | + } |
| 57646 | 57670 | pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC); |
| 57647 | 57671 | if( pPager->tempFile ){ |
| 57648 | 57672 | /* Do not discard pages from an in-memory database since we might |
| 57649 | 57673 | ** need to rollback later. Just move the page out of the way. */ |
| 57650 | 57674 | sqlite3PcacheMove(pPgOld, pPager->dbSize+1); |
| | @@ -64486,11 +64510,11 @@ |
| 64486 | 64510 | temp = 0; |
| 64487 | 64511 | src = data = pPage->aData; |
| 64488 | 64512 | hdr = pPage->hdrOffset; |
| 64489 | 64513 | cellOffset = pPage->cellOffset; |
| 64490 | 64514 | nCell = pPage->nCell; |
| 64491 | | - assert( nCell==get2byte(&data[hdr+3]) ); |
| 64515 | + assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB ); |
| 64492 | 64516 | iCellFirst = cellOffset + 2*nCell; |
| 64493 | 64517 | usableSize = pPage->pBt->usableSize; |
| 64494 | 64518 | |
| 64495 | 64519 | /* This block handles pages with two or fewer free blocks and nMaxFrag |
| 64496 | 64520 | ** or fewer fragmented bytes. In this case it is faster to move the |
| | @@ -64638,11 +64662,11 @@ |
| 64638 | 64662 | } |
| 64639 | 64663 | return &aData[pc + x]; |
| 64640 | 64664 | } |
| 64641 | 64665 | iAddr = pc; |
| 64642 | 64666 | pc = get2byte(&aData[pc]); |
| 64643 | | - if( pc<iAddr+size ){ |
| 64667 | + if( pc<=iAddr+size ){ |
| 64644 | 64668 | if( pc ){ |
| 64645 | 64669 | /* The next slot in the chain is not past the end of the current slot */ |
| 64646 | 64670 | *pRc = SQLITE_CORRUPT_PAGE(pPg); |
| 64647 | 64671 | } |
| 64648 | 64672 | return 0; |
| | @@ -68617,11 +68641,11 @@ |
| 68617 | 68641 | pCur->curFlags &= ~BTCF_ValidOvfl; |
| 68618 | 68642 | if( rc ){ |
| 68619 | 68643 | sqlite3_free(pCellKey); |
| 68620 | 68644 | goto moveto_finish; |
| 68621 | 68645 | } |
| 68622 | | - c = xRecordCompare(nCell, pCellKey, pIdxKey); |
| 68646 | + c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey); |
| 68623 | 68647 | sqlite3_free(pCellKey); |
| 68624 | 68648 | } |
| 68625 | 68649 | assert( |
| 68626 | 68650 | (pIdxKey->errCode!=SQLITE_CORRUPT || c==0) |
| 68627 | 68651 | && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed) |
| | @@ -70217,12 +70241,13 @@ |
| 70217 | 70241 | /* Add any overflow cells */ |
| 70218 | 70242 | for(i=0; i<pPg->nOverflow; i++){ |
| 70219 | 70243 | int iCell = (iOld + pPg->aiOvfl[i]) - iNew; |
| 70220 | 70244 | if( iCell>=0 && iCell<nNew ){ |
| 70221 | 70245 | pCellptr = &pPg->aCellIdx[iCell * 2]; |
| 70222 | | - assert( nCell>=iCell ); |
| 70223 | | - memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2); |
| 70246 | + if( nCell>iCell ){ |
| 70247 | + memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2); |
| 70248 | + } |
| 70224 | 70249 | nCell++; |
| 70225 | 70250 | if( pageInsertArray( |
| 70226 | 70251 | pPg, pBegin, &pData, pCellptr, |
| 70227 | 70252 | iCell+iNew, 1, pCArray |
| 70228 | 70253 | ) ) goto editpage_fail; |
| | @@ -72333,10 +72358,13 @@ |
| 72333 | 72358 | BtShared *pBt = p->pBt; |
| 72334 | 72359 | |
| 72335 | 72360 | assert( sqlite3BtreeHoldsMutex(p) ); |
| 72336 | 72361 | assert( p->inTrans==TRANS_WRITE ); |
| 72337 | 72362 | assert( iTable>=2 ); |
| 72363 | + if( iTable>btreePagecount(pBt) ){ |
| 72364 | + return SQLITE_CORRUPT_BKPT; |
| 72365 | + } |
| 72338 | 72366 | |
| 72339 | 72367 | rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0); |
| 72340 | 72368 | if( rc ) return rc; |
| 72341 | 72369 | rc = sqlite3BtreeClearTable(p, iTable, 0); |
| 72342 | 72370 | if( rc ){ |
| | @@ -72681,14 +72709,14 @@ |
| 72681 | 72709 | */ |
| 72682 | 72710 | static void checkList( |
| 72683 | 72711 | IntegrityCk *pCheck, /* Integrity checking context */ |
| 72684 | 72712 | int isFreeList, /* True for a freelist. False for overflow page list */ |
| 72685 | 72713 | int iPage, /* Page number for first page in the list */ |
| 72686 | | - int N /* Expected number of pages in the list */ |
| 72714 | + u32 N /* Expected number of pages in the list */ |
| 72687 | 72715 | ){ |
| 72688 | 72716 | int i; |
| 72689 | | - int expected = N; |
| 72717 | + u32 expected = N; |
| 72690 | 72718 | int nErrAtStart = pCheck->nErr; |
| 72691 | 72719 | while( iPage!=0 && pCheck->mxErr ){ |
| 72692 | 72720 | DbPage *pOvflPage; |
| 72693 | 72721 | unsigned char *pOvflData; |
| 72694 | 72722 | if( checkRef(pCheck, iPage) ) break; |
| | @@ -72943,11 +72971,11 @@ |
| 72943 | 72971 | keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */ |
| 72944 | 72972 | } |
| 72945 | 72973 | |
| 72946 | 72974 | /* Check the content overflow list */ |
| 72947 | 72975 | if( info.nPayload>info.nLocal ){ |
| 72948 | | - int nPage; /* Number of pages on the overflow chain */ |
| 72976 | + u32 nPage; /* Number of pages on the overflow chain */ |
| 72949 | 72977 | Pgno pgnoOvfl; /* First page of the overflow chain */ |
| 72950 | 72978 | assert( pc + info.nSize - 4 <= usableSize ); |
| 72951 | 72979 | nPage = (info.nPayload - info.nLocal + usableSize - 5)/(usableSize - 4); |
| 72952 | 72980 | pgnoOvfl = get4byte(&pCell[info.nSize - 4]); |
| 72953 | 72981 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| | @@ -76831,10 +76859,11 @@ |
| 76831 | 76859 | |
| 76832 | 76860 | while( (pOp = opIterNext(&sIter))!=0 ){ |
| 76833 | 76861 | int opcode = pOp->opcode; |
| 76834 | 76862 | if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename |
| 76835 | 76863 | || opcode==OP_VDestroy |
| 76864 | + || (opcode==OP_Function0 && pOp->p4.pFunc->funcFlags&SQLITE_FUNC_INTERNAL) |
| 76836 | 76865 | || ((opcode==OP_Halt || opcode==OP_HaltIfNull) |
| 76837 | 76866 | && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort)) |
| 76838 | 76867 | ){ |
| 76839 | 76868 | hasAbort = 1; |
| 76840 | 76869 | break; |
| | @@ -82315,13 +82344,16 @@ |
| 82315 | 82344 | n = sqlite3_column_count(pStmt); |
| 82316 | 82345 | if( N<n && N>=0 ){ |
| 82317 | 82346 | N += useType*n; |
| 82318 | 82347 | sqlite3_mutex_enter(db->mutex); |
| 82319 | 82348 | assert( db->mallocFailed==0 ); |
| 82349 | +#ifndef SQLITE_OMIT_UTF16 |
| 82320 | 82350 | if( useUtf16 ){ |
| 82321 | 82351 | ret = sqlite3_value_text16((sqlite3_value*)&p->aColName[N]); |
| 82322 | | - }else{ |
| 82352 | + }else |
| 82353 | +#endif |
| 82354 | + { |
| 82323 | 82355 | ret = sqlite3_value_text((sqlite3_value*)&p->aColName[N]); |
| 82324 | 82356 | } |
| 82325 | 82357 | /* A malloc may have failed inside of the _text() call. If this |
| 82326 | 82358 | ** is the case, clear the mallocFailed flag and return NULL. |
| 82327 | 82359 | */ |
| | @@ -82775,10 +82807,18 @@ |
| 82775 | 82807 | ** database. |
| 82776 | 82808 | */ |
| 82777 | 82809 | SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt){ |
| 82778 | 82810 | return pStmt ? ((Vdbe*)pStmt)->readOnly : 1; |
| 82779 | 82811 | } |
| 82812 | + |
| 82813 | +/* |
| 82814 | +** Return 1 if the statement is an EXPLAIN and return 2 if the |
| 82815 | +** statement is an EXPLAIN QUERY PLAN |
| 82816 | +*/ |
| 82817 | +SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt){ |
| 82818 | + return pStmt ? ((Vdbe*)pStmt)->explain : 0; |
| 82819 | +} |
| 82780 | 82820 | |
| 82781 | 82821 | /* |
| 82782 | 82822 | ** Return true if the prepared statement is in need of being reset. |
| 82783 | 82823 | */ |
| 82784 | 82824 | SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){ |
| | @@ -102329,19 +102369,19 @@ |
| 102329 | 102369 | pVTab = 0; |
| 102330 | 102370 | } |
| 102331 | 102371 | } |
| 102332 | 102372 | #endif |
| 102333 | 102373 | |
| 102334 | | - /* Begin a transaction for database iDb. |
| 102335 | | - ** Then modify the schema cookie (since the ALTER TABLE modifies the |
| 102336 | | - ** schema). Open a statement transaction if the table is a virtual |
| 102337 | | - ** table. |
| 102338 | | - */ |
| 102374 | + /* Begin a transaction for database iDb. Then modify the schema cookie |
| 102375 | + ** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(), |
| 102376 | + ** as the scalar functions (e.g. sqlite_rename_table()) invoked by the |
| 102377 | + ** nested SQL may raise an exception. */ |
| 102339 | 102378 | v = sqlite3GetVdbe(pParse); |
| 102340 | 102379 | if( v==0 ){ |
| 102341 | 102380 | goto exit_rename_table; |
| 102342 | 102381 | } |
| 102382 | + sqlite3MayAbort(pParse); |
| 102343 | 102383 | |
| 102344 | 102384 | /* figure out how many UTF-8 characters are in zName */ |
| 102345 | 102385 | zTabName = pTab->zName; |
| 102346 | 102386 | nTabName = sqlite3Utf8CharLen(zTabName, -1); |
| 102347 | 102387 | |
| | @@ -102406,11 +102446,10 @@ |
| 102406 | 102446 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 102407 | 102447 | if( pVTab ){ |
| 102408 | 102448 | int i = ++pParse->nMem; |
| 102409 | 102449 | sqlite3VdbeLoadString(v, i, zName); |
| 102410 | 102450 | sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB); |
| 102411 | | - sqlite3MayAbort(pParse); |
| 102412 | 102451 | } |
| 102413 | 102452 | #endif |
| 102414 | 102453 | |
| 102415 | 102454 | renameReloadSchema(pParse, iDb); |
| 102416 | 102455 | renameTestSchema(pParse, zDb, iDb==1); |
| | @@ -102727,10 +102766,11 @@ |
| 102727 | 102766 | |
| 102728 | 102767 | /* Do the rename operation using a recursive UPDATE statement that |
| 102729 | 102768 | ** uses the sqlite_rename_column() SQL function to compute the new |
| 102730 | 102769 | ** CREATE statement text for the sqlite_master table. |
| 102731 | 102770 | */ |
| 102771 | + sqlite3MayAbort(pParse); |
| 102732 | 102772 | zNew = sqlite3NameFromToken(db, pNew); |
| 102733 | 102773 | if( !zNew ) goto exit_rename_column; |
| 102734 | 102774 | assert( pNew->n>0 ); |
| 102735 | 102775 | bQuote = sqlite3Isquote(pNew->z[0]); |
| 102736 | 102776 | sqlite3NestedParse(pParse, |
| | @@ -105981,11 +106021,13 @@ |
| 105981 | 106021 | */ |
| 105982 | 106022 | if( rc==SQLITE_OK ){ |
| 105983 | 106023 | sqlite3BtreeEnterAll(db); |
| 105984 | 106024 | db->init.iDb = 0; |
| 105985 | 106025 | db->mDbFlags &= ~(DBFLAG_SchemaKnownOk); |
| 105986 | | - rc = sqlite3Init(db, &zErrDyn); |
| 106026 | + if( !REOPEN_AS_MEMDB(db) ){ |
| 106027 | + rc = sqlite3Init(db, &zErrDyn); |
| 106028 | + } |
| 105987 | 106029 | sqlite3BtreeLeaveAll(db); |
| 105988 | 106030 | assert( zErrDyn==0 || rc!=SQLITE_OK ); |
| 105989 | 106031 | } |
| 105990 | 106032 | #ifdef SQLITE_USER_AUTHENTICATION |
| 105991 | 106033 | if( rc==SQLITE_OK ){ |
| | @@ -114605,10 +114647,14 @@ |
| 114605 | 114647 | static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){ |
| 114606 | 114648 | FuncDef *pDef; |
| 114607 | 114649 | pDef = sqlite3FindFunction(db, zName, 2, SQLITE_UTF8, 0); |
| 114608 | 114650 | if( ALWAYS(pDef) ){ |
| 114609 | 114651 | pDef->funcFlags |= flagVal; |
| 114652 | + } |
| 114653 | + pDef = sqlite3FindFunction(db, zName, 3, SQLITE_UTF8, 0); |
| 114654 | + if( pDef ){ |
| 114655 | + pDef->funcFlags |= flagVal; |
| 114610 | 114656 | } |
| 114611 | 114657 | } |
| 114612 | 114658 | |
| 114613 | 114659 | /* |
| 114614 | 114660 | ** Register the built-in LIKE and GLOB functions. The caseSensitive |
| | @@ -129717,11 +129763,11 @@ |
| 129717 | 129763 | ** Update the accumulator memory cells for an aggregate based on |
| 129718 | 129764 | ** the current cursor position. |
| 129719 | 129765 | ** |
| 129720 | 129766 | ** If regAcc is non-zero and there are no min() or max() aggregates |
| 129721 | 129767 | ** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator |
| 129722 | | -** registers i register regAcc contains 0. The caller will take care |
| 129768 | +** registers if register regAcc contains 0. The caller will take care |
| 129723 | 129769 | ** of setting and clearing regAcc. |
| 129724 | 129770 | */ |
| 129725 | 129771 | static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo){ |
| 129726 | 129772 | Vdbe *v = pParse->pVdbe; |
| 129727 | 129773 | int i; |
| | @@ -137079,10 +137125,38 @@ |
| 137079 | 137125 | sqlite3WalkExpr(&w, pWInfo->pWhere); |
| 137080 | 137126 | sqlite3WalkExprList(&w, pWInfo->pOrderBy); |
| 137081 | 137127 | sqlite3WalkExprList(&w, pWInfo->pResultSet); |
| 137082 | 137128 | } |
| 137083 | 137129 | } |
| 137130 | + |
| 137131 | +/* |
| 137132 | +** The pTruth expression is always true because it is the WHERE clause |
| 137133 | +** a partial index that is driving a query loop. Look through all of the |
| 137134 | +** WHERE clause terms on the query, and if any of those terms must be |
| 137135 | +** true because pTruth is true, then mark those WHERE clause terms as |
| 137136 | +** coded. |
| 137137 | +*/ |
| 137138 | +static void whereApplyPartialIndexConstraints( |
| 137139 | + Expr *pTruth, |
| 137140 | + int iTabCur, |
| 137141 | + WhereClause *pWC |
| 137142 | +){ |
| 137143 | + int i; |
| 137144 | + WhereTerm *pTerm; |
| 137145 | + while( pTruth->op==TK_AND ){ |
| 137146 | + whereApplyPartialIndexConstraints(pTruth->pLeft, iTabCur, pWC); |
| 137147 | + pTruth = pTruth->pRight; |
| 137148 | + } |
| 137149 | + for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){ |
| 137150 | + Expr *pExpr; |
| 137151 | + if( pTerm->wtFlags & TERM_CODED ) continue; |
| 137152 | + pExpr = pTerm->pExpr; |
| 137153 | + if( sqlite3ExprCompare(0, pExpr, pTruth, iTabCur)==0 ){ |
| 137154 | + pTerm->wtFlags |= TERM_CODED; |
| 137155 | + } |
| 137156 | + } |
| 137157 | +} |
| 137084 | 137158 | |
| 137085 | 137159 | /* |
| 137086 | 137160 | ** Generate code for the start of the iLevel-th loop in the WHERE clause |
| 137087 | 137161 | ** implementation described by pWInfo. |
| 137088 | 137162 | */ |
| | @@ -137688,10 +137762,18 @@ |
| 137688 | 137762 | ** https://sqlite.org/src/info/4e8e4857d32d401f |
| 137689 | 137763 | */ |
| 137690 | 137764 | if( pLevel->iLeftJoin==0 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){ |
| 137691 | 137765 | whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo); |
| 137692 | 137766 | } |
| 137767 | + |
| 137768 | + /* If a partial index is driving the loop, try to eliminate WHERE clause |
| 137769 | + ** terms from the query that must be true due to the WHERE clause of |
| 137770 | + ** the partial index |
| 137771 | + */ |
| 137772 | + if( pIdx->pPartIdxWhere ){ |
| 137773 | + whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC); |
| 137774 | + } |
| 137693 | 137775 | |
| 137694 | 137776 | /* Record the instruction used to terminate the loop. */ |
| 137695 | 137777 | if( pLoop->wsFlags & WHERE_ONEROW ){ |
| 137696 | 137778 | pLevel->op = OP_Noop; |
| 137697 | 137779 | }else if( bRev ){ |
| | @@ -139685,10 +139767,16 @@ |
| 139685 | 139767 | if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1; |
| 139686 | 139768 | mask |= exprSelectUsage(pMaskSet, p->x.pSelect); |
| 139687 | 139769 | }else if( p->x.pList ){ |
| 139688 | 139770 | mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList); |
| 139689 | 139771 | } |
| 139772 | +#ifndef SQLITE_OMIT_WINDOWFUNC |
| 139773 | + if( p->op==TK_FUNCTION && p->y.pWin ){ |
| 139774 | + mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition); |
| 139775 | + mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy); |
| 139776 | + } |
| 139777 | +#endif |
| 139690 | 139778 | return mask; |
| 139691 | 139779 | } |
| 139692 | 139780 | SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){ |
| 139693 | 139781 | return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0; |
| 139694 | 139782 | } |
| | @@ -153089,14 +153177,14 @@ |
| 153089 | 153177 | int n = 0; /* Length of the next token token */ |
| 153090 | 153178 | int tokenType; /* type of the next token */ |
| 153091 | 153179 | int lastTokenParsed = -1; /* type of the previous token */ |
| 153092 | 153180 | sqlite3 *db = pParse->db; /* The database connection */ |
| 153093 | 153181 | int mxSqlLen; /* Max length of an SQL string */ |
| 153094 | | - VVA_ONLY( u8 startedWithOom = db->mallocFailed ); |
| 153095 | 153182 | #ifdef sqlite3Parser_ENGINEALWAYSONSTACK |
| 153096 | 153183 | yyParser sEngine; /* Space to hold the Lemon-generated Parser object */ |
| 153097 | 153184 | #endif |
| 153185 | + VVA_ONLY( u8 startedWithOom = db->mallocFailed ); |
| 153098 | 153186 | |
| 153099 | 153187 | assert( zSql!=0 ); |
| 153100 | 153188 | mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; |
| 153101 | 153189 | if( db->nVdbeActive==0 ){ |
| 153102 | 153190 | db->u1.isInterrupted = 0; |
| | @@ -161295,11 +161383,11 @@ |
| 161295 | 161383 | } |
| 161296 | 161384 | isFirstTerm = 0; |
| 161297 | 161385 | zCsr += fts3GetVarint32(zCsr, &nSuffix); |
| 161298 | 161386 | |
| 161299 | 161387 | assert( nPrefix>=0 && nSuffix>=0 ); |
| 161300 | | - if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr ){ |
| 161388 | + if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr || nSuffix==0 ){ |
| 161301 | 161389 | rc = FTS_CORRUPT_VTAB; |
| 161302 | 161390 | goto finish_scan; |
| 161303 | 161391 | } |
| 161304 | 161392 | if( (i64)nPrefix+nSuffix>nAlloc ){ |
| 161305 | 161393 | char *zNew; |
| | @@ -168435,11 +168523,13 @@ |
| 168435 | 168523 | sqlite3_result_error(context, zErr, -1); |
| 168436 | 168524 | sqlite3_free(zErr); |
| 168437 | 168525 | return; |
| 168438 | 168526 | } |
| 168439 | 168527 | } |
| 168440 | | - sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT); |
| 168528 | + if( fts3TokenizerEnabled(context) ){ |
| 168529 | + sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT); |
| 168530 | + } |
| 168441 | 168531 | } |
| 168442 | 168532 | |
| 168443 | 168533 | SQLITE_PRIVATE int sqlite3Fts3IsIdChar(char c){ |
| 168444 | 168534 | static const char isFtsIdChar[] = { |
| 168445 | 168535 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */ |
| | @@ -175688,11 +175778,11 @@ |
| 175688 | 175778 | SnippetPhrase *pPhrase = &pIter->aPhrase[i]; |
| 175689 | 175779 | if( pPhrase->pTail ){ |
| 175690 | 175780 | char *pCsr = pPhrase->pTail; |
| 175691 | 175781 | int iCsr = pPhrase->iTail; |
| 175692 | 175782 | |
| 175693 | | - while( iCsr<(iStart+pIter->nSnippet) ){ |
| 175783 | + while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){ |
| 175694 | 175784 | int j; |
| 175695 | 175785 | u64 mPhrase = (u64)1 << i; |
| 175696 | 175786 | u64 mPos = (u64)1 << (iCsr - iStart); |
| 175697 | 175787 | assert( iCsr>=iStart && (iCsr - iStart)<=64 ); |
| 175698 | 175788 | assert( i>=0 && i<=64 ); |
| | @@ -217166,11 +217256,11 @@ |
| 217166 | 217256 | int nArg, /* Number of args */ |
| 217167 | 217257 | sqlite3_value **apUnused /* Function arguments */ |
| 217168 | 217258 | ){ |
| 217169 | 217259 | assert( nArg==0 ); |
| 217170 | 217260 | UNUSED_PARAM2(nArg, apUnused); |
| 217171 | | - sqlite3_result_text(pCtx, "fts5: 2019-02-25 14:52:43 9da4fb59b28686630d63a79988b458726332cf06cc0e6e84d7c0a7600f5fcab0", -1, SQLITE_TRANSIENT); |
| 217261 | + sqlite3_result_text(pCtx, "fts5: 2019-03-15 16:17:32 0f2129f59f7df929106e2af876c2976dea6528c1dc1850d64cddb256f20e121a", -1, SQLITE_TRANSIENT); |
| 217172 | 217262 | } |
| 217173 | 217263 | |
| 217174 | 217264 | /* |
| 217175 | 217265 | ** Return true if zName is the extension on one of the shadow tables used |
| 217176 | 217266 | ** by this module. |
| | @@ -221930,12 +222020,12 @@ |
| 221930 | 222020 | } |
| 221931 | 222021 | #endif /* SQLITE_CORE */ |
| 221932 | 222022 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 221933 | 222023 | |
| 221934 | 222024 | /************** End of stmt.c ************************************************/ |
| 221935 | | -#if __LINE__!=221935 |
| 222025 | +#if __LINE__!=222025 |
| 221936 | 222026 | #undef SQLITE_SOURCE_ID |
| 221937 | | -#define SQLITE_SOURCE_ID "2019-02-25 14:52:43 9da4fb59b28686630d63a79988b458726332cf06cc0e6e84d7c0a7600f5falt2" |
| 222027 | +#define SQLITE_SOURCE_ID "2019-03-17 23:59:02 cc5ab96715ebb1089b4e9aa647badd2510aaa056f26004718f921f4ac07ealt2" |
| 221938 | 222028 | #endif |
| 221939 | 222029 | /* Return the source-id for this library */ |
| 221940 | 222030 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 221941 | 222031 | /************************** End of sqlite3.c ******************************/ |
| 221942 | 222032 | |