| | @@ -452,11 +452,11 @@ |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | 455 | #define SQLITE_VERSION "3.41.0" |
| 456 | 456 | #define SQLITE_VERSION_NUMBER 3041000 |
| 457 | | -#define SQLITE_SOURCE_ID "2023-02-03 14:57:40 c045d76b908a8c90d22511df7884e78d452b250db9ba70d4cb0935048a3c3ac4" |
| 457 | +#define SQLITE_SOURCE_ID "2023-02-08 14:49:52 6b41ba2e996ab7b9c3943ab93a19748db5cf37792f5d59d20eec301085282355" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -10123,11 +10123,11 @@ |
| 10123 | 10123 | ** ^(Use these routines to access all values on the right-hand side |
| 10124 | 10124 | ** of the IN constraint using code like the following: |
| 10125 | 10125 | ** |
| 10126 | 10126 | ** <blockquote><pre> |
| 10127 | 10127 | ** for(rc=sqlite3_vtab_in_first(pList, &pVal); |
| 10128 | | -** rc==SQLITE_OK && pVal |
| 10128 | +** rc==SQLITE_OK && pVal; |
| 10129 | 10129 | ** rc=sqlite3_vtab_in_next(pList, &pVal) |
| 10130 | 10130 | ** ){ |
| 10131 | 10131 | ** // do something with pVal |
| 10132 | 10132 | ** } |
| 10133 | 10133 | ** if( rc!=SQLITE_OK ){ |
| | @@ -10835,10 +10835,23 @@ |
| 10835 | 10835 | ** builds on processors without floating point support. |
| 10836 | 10836 | */ |
| 10837 | 10837 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 10838 | 10838 | # undef double |
| 10839 | 10839 | #endif |
| 10840 | + |
| 10841 | +#if defined(__wasi__) |
| 10842 | +# undef SQLITE_WASI |
| 10843 | +# define SQLITE_WASI 1 |
| 10844 | +# undef SQLITE_OMIT_WAL |
| 10845 | +# define SQLITE_OMIT_WAL 1/* because it requires shared memory APIs */ |
| 10846 | +# ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 10847 | +# define SQLITE_OMIT_LOAD_EXTENSION |
| 10848 | +# endif |
| 10849 | +# ifndef SQLITE_THREADSAFE |
| 10850 | +# define SQLITE_THREADSAFE 0 |
| 10851 | +# endif |
| 10852 | +#endif |
| 10840 | 10853 | |
| 10841 | 10854 | #if 0 |
| 10842 | 10855 | } /* End of the 'extern "C"' block */ |
| 10843 | 10856 | #endif |
| 10844 | 10857 | #endif /* SQLITE3_H */ |
| | @@ -17103,10 +17116,11 @@ |
| 17103 | 17116 | u8 mTrace; /* zero or more SQLITE_TRACE flags */ |
| 17104 | 17117 | u8 noSharedCache; /* True if no shared-cache backends */ |
| 17105 | 17118 | u8 nSqlExec; /* Number of pending OP_SqlExec opcodes */ |
| 17106 | 17119 | u8 eOpenState; /* Current condition of the connection */ |
| 17107 | 17120 | int nextPagesize; /* Pagesize after VACUUM if >0 */ |
| 17121 | + i64 txnTime; /* Timestamp for current transaction */ |
| 17108 | 17122 | i64 nChange; /* Value returned by sqlite3_changes() */ |
| 17109 | 17123 | i64 nTotalChange; /* Value returned by sqlite3_total_changes() */ |
| 17110 | 17124 | int aLimit[SQLITE_N_LIMIT]; /* Limits */ |
| 17111 | 17125 | int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */ |
| 17112 | 17126 | struct sqlite3InitInfo { /* Information used during initialization */ |
| | @@ -20822,11 +20836,11 @@ |
| 20822 | 20836 | SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*); |
| 20823 | 20837 | #if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \ |
| 20824 | 20838 | && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 20825 | 20839 | SQLITE_PRIVATE void sqlite3VtabUsesAllSchemas(sqlite3_index_info*); |
| 20826 | 20840 | #endif |
| 20827 | | -SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*); |
| 20841 | +SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*, int); |
| 20828 | 20842 | SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int); |
| 20829 | 20843 | SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *); |
| 20830 | 20844 | SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse*,sqlite3*); |
| 20831 | 20845 | SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse*); |
| 20832 | 20846 | SQLITE_PRIVATE void *sqlite3ParserAddCleanup(Parse*,void(*)(sqlite3*,void*),void*); |
| | @@ -23810,16 +23824,20 @@ |
| 23810 | 23824 | } |
| 23811 | 23825 | return 0; |
| 23812 | 23826 | } |
| 23813 | 23827 | |
| 23814 | 23828 | /* |
| 23815 | | -** Set the time to the current time reported by the VFS. |
| 23829 | +** Set the time to the current time reported for the prepared statement |
| 23830 | +** that is currently executing. The same time is reported for all |
| 23831 | +** invocations of this routine from within the same call to sqlite3_step(). |
| 23832 | +** |
| 23833 | +** Or if bTxn is true, use the transaction time. |
| 23816 | 23834 | ** |
| 23817 | 23835 | ** Return the number of errors. |
| 23818 | 23836 | */ |
| 23819 | | -static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){ |
| 23820 | | - p->iJD = sqlite3StmtCurrentTime(context); |
| 23837 | +static int setCurrentStmtTime(sqlite3_context *context, DateTime *p, int bTxn){ |
| 23838 | + p->iJD = sqlite3StmtCurrentTime(context, bTxn); |
| 23821 | 23839 | if( p->iJD>0 ){ |
| 23822 | 23840 | p->validJD = 1; |
| 23823 | 23841 | return 0; |
| 23824 | 23842 | }else{ |
| 23825 | 23843 | return 1; |
| | @@ -23866,11 +23884,13 @@ |
| 23866 | 23884 | if( parseYyyyMmDd(zDate,p)==0 ){ |
| 23867 | 23885 | return 0; |
| 23868 | 23886 | }else if( parseHhMmSs(zDate, p)==0 ){ |
| 23869 | 23887 | return 0; |
| 23870 | 23888 | }else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){ |
| 23871 | | - return setDateTimeToCurrent(context, p); |
| 23889 | + return setCurrentStmtTime(context, p, 0); |
| 23890 | + }else if( sqlite3StrICmp(zDate,"txn")==0 && sqlite3NotPureFunc(context) ){ |
| 23891 | + return setCurrentStmtTime(context, p, 1); |
| 23872 | 23892 | }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8)>0 ){ |
| 23873 | 23893 | setRawDateNumber(p, r); |
| 23874 | 23894 | return 0; |
| 23875 | 23895 | } |
| 23876 | 23896 | return 1; |
| | @@ -24410,12 +24430,15 @@ |
| 24410 | 24430 | ** Process time function arguments. argv[0] is a date-time stamp. |
| 24411 | 24431 | ** argv[1] and following are modifiers. Parse them all and write |
| 24412 | 24432 | ** the resulting time into the DateTime structure p. Return 0 |
| 24413 | 24433 | ** on success and 1 if there are any errors. |
| 24414 | 24434 | ** |
| 24415 | | -** If there are zero parameters (if even argv[0] is undefined) |
| 24416 | | -** then assume a default value of "now" for argv[0]. |
| 24435 | +** If there are zero parameters (if argc<=0) then assume a default |
| 24436 | +** value of "now" for argv[0] if argc==0 and "txn" if argc<0. SQL |
| 24437 | +** functions will always have argc>=0, but the special implementations |
| 24438 | +** of CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP set argc to -1 |
| 24439 | +** in order to force the use of 'txn' semantics. |
| 24417 | 24440 | */ |
| 24418 | 24441 | static int isDate( |
| 24419 | 24442 | sqlite3_context *context, |
| 24420 | 24443 | int argc, |
| 24421 | 24444 | sqlite3_value **argv, |
| | @@ -24423,13 +24446,13 @@ |
| 24423 | 24446 | ){ |
| 24424 | 24447 | int i, n; |
| 24425 | 24448 | const unsigned char *z; |
| 24426 | 24449 | int eType; |
| 24427 | 24450 | memset(p, 0, sizeof(*p)); |
| 24428 | | - if( argc==0 ){ |
| 24451 | + if( argc<=0 ){ |
| 24429 | 24452 | if( !sqlite3NotPureFunc(context) ) return 1; |
| 24430 | | - return setDateTimeToCurrent(context, p); |
| 24453 | + return setCurrentStmtTime(context, p, argc<0); |
| 24431 | 24454 | } |
| 24432 | 24455 | if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT |
| 24433 | 24456 | || eType==SQLITE_INTEGER ){ |
| 24434 | 24457 | setRawDateNumber(p, sqlite3_value_double(argv[0])); |
| 24435 | 24458 | }else{ |
| | @@ -24732,11 +24755,11 @@ |
| 24732 | 24755 | sqlite3_context *context, |
| 24733 | 24756 | int NotUsed, |
| 24734 | 24757 | sqlite3_value **NotUsed2 |
| 24735 | 24758 | ){ |
| 24736 | 24759 | UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 24737 | | - timeFunc(context, 0, 0); |
| 24760 | + timeFunc(context, -1, 0); |
| 24738 | 24761 | } |
| 24739 | 24762 | |
| 24740 | 24763 | /* |
| 24741 | 24764 | ** current_date() |
| 24742 | 24765 | ** |
| | @@ -24746,11 +24769,11 @@ |
| 24746 | 24769 | sqlite3_context *context, |
| 24747 | 24770 | int NotUsed, |
| 24748 | 24771 | sqlite3_value **NotUsed2 |
| 24749 | 24772 | ){ |
| 24750 | 24773 | UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 24751 | | - dateFunc(context, 0, 0); |
| 24774 | + dateFunc(context, -1, 0); |
| 24752 | 24775 | } |
| 24753 | 24776 | |
| 24754 | 24777 | /* |
| 24755 | 24778 | ** current_timestamp() |
| 24756 | 24779 | ** |
| | @@ -24760,11 +24783,11 @@ |
| 24760 | 24783 | sqlite3_context *context, |
| 24761 | 24784 | int NotUsed, |
| 24762 | 24785 | sqlite3_value **NotUsed2 |
| 24763 | 24786 | ){ |
| 24764 | 24787 | UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 24765 | | - datetimeFunc(context, 0, 0); |
| 24788 | + datetimeFunc(context, -1, 0); |
| 24766 | 24789 | } |
| 24767 | 24790 | #endif /* !defined(SQLITE_OMIT_DATETIME_FUNCS) */ |
| 24768 | 24791 | |
| 24769 | 24792 | #ifdef SQLITE_OMIT_DATETIME_FUNCS |
| 24770 | 24793 | /* |
| | @@ -24791,11 +24814,11 @@ |
| 24791 | 24814 | char zBuf[20]; |
| 24792 | 24815 | |
| 24793 | 24816 | UNUSED_PARAMETER(argc); |
| 24794 | 24817 | UNUSED_PARAMETER(argv); |
| 24795 | 24818 | |
| 24796 | | - iT = sqlite3StmtCurrentTime(context); |
| 24819 | + iT = sqlite3StmtCurrentTime(context, 1); |
| 24797 | 24820 | if( iT<=0 ) return; |
| 24798 | 24821 | t = iT/1000 - 10000*(sqlite3_int64)21086676; |
| 24799 | 24822 | #if HAVE_GMTIME_R |
| 24800 | 24823 | pTm = gmtime_r(&t, &sNow); |
| 24801 | 24824 | #else |
| | @@ -36999,11 +37022,12 @@ |
| 36999 | 37022 | #include <sys/ioctl.h> |
| 37000 | 37023 | #include <unistd.h> /* amalgamator: keep */ |
| 37001 | 37024 | /* #include <time.h> */ |
| 37002 | 37025 | #include <sys/time.h> /* amalgamator: keep */ |
| 37003 | 37026 | #include <errno.h> |
| 37004 | | -#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 37027 | +#if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \ |
| 37028 | + && !defined(SQLITE_WASI) |
| 37005 | 37029 | # include <sys/mman.h> |
| 37006 | 37030 | #endif |
| 37007 | 37031 | |
| 37008 | 37032 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 37009 | 37033 | /* # include <sys/ioctl.h> */ |
| | @@ -37087,13 +37111,50 @@ |
| 37087 | 37111 | /* |
| 37088 | 37112 | ** Maximum supported symbolic links |
| 37089 | 37113 | */ |
| 37090 | 37114 | #define SQLITE_MAX_SYMLINKS 100 |
| 37091 | 37115 | |
| 37116 | +/* |
| 37117 | +** Remove and stub certain info for WASI (WebAssembly System |
| 37118 | +** Interface) builds. |
| 37119 | +*/ |
| 37120 | +#ifdef SQLITE_WASI |
| 37121 | +# undef HAVE_FCHMOD |
| 37122 | +# undef HAVE_FCHOWN |
| 37123 | +# undef HAVE_MREMAP |
| 37124 | +# define HAVE_MREMAP 0 |
| 37125 | +# ifndef SQLITE_DEFAULT_UNIX_VFS |
| 37126 | +# define SQLITE_DEFAULT_UNIX_VFS "unix-dotfile" |
| 37127 | + /* ^^^ should SQLITE_DEFAULT_UNIX_VFS be "unix-none"? */ |
| 37128 | +# endif |
| 37129 | +# ifndef F_RDLCK |
| 37130 | +# define F_RDLCK 0 |
| 37131 | +# define F_WRLCK 1 |
| 37132 | +# define F_UNLCK 2 |
| 37133 | +# if __LONG_MAX == 0x7fffffffL |
| 37134 | +# define F_GETLK 12 |
| 37135 | +# define F_SETLK 13 |
| 37136 | +# define F_SETLKW 14 |
| 37137 | +# else |
| 37138 | +# define F_GETLK 5 |
| 37139 | +# define F_SETLK 6 |
| 37140 | +# define F_SETLKW 7 |
| 37141 | +# endif |
| 37142 | +# endif |
| 37143 | +#else /* !SQLITE_WASI */ |
| 37144 | +# ifndef HAVE_FCHMOD |
| 37145 | +# define HAVE_FCHMOD |
| 37146 | +# endif |
| 37147 | +#endif /* SQLITE_WASI */ |
| 37148 | + |
| 37149 | +#ifdef SQLITE_WASI |
| 37150 | +# define osGetpid(X) (pid_t)1 |
| 37151 | +#else |
| 37092 | 37152 | /* Always cast the getpid() return type for compatibility with |
| 37093 | 37153 | ** kernel modules in VxWorks. */ |
| 37094 | | -#define osGetpid(X) (pid_t)getpid() |
| 37154 | +# define osGetpid(X) (pid_t)getpid() |
| 37155 | +#endif |
| 37095 | 37156 | |
| 37096 | 37157 | /* |
| 37097 | 37158 | ** Only set the lastErrno if the error code is a real error and not |
| 37098 | 37159 | ** a normal expected return code of SQLITE_BUSY or SQLITE_OK |
| 37099 | 37160 | */ |
| | @@ -37361,11 +37422,15 @@ |
| 37361 | 37422 | { "pwrite64", (sqlite3_syscall_ptr)0, 0 }, |
| 37362 | 37423 | #endif |
| 37363 | 37424 | #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off64_t))\ |
| 37364 | 37425 | aSyscall[13].pCurrent) |
| 37365 | 37426 | |
| 37427 | +#if defined(HAVE_FCHMOD) |
| 37366 | 37428 | { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, |
| 37429 | +#else |
| 37430 | + { "fchmod", (sqlite3_syscall_ptr)0, 0 }, |
| 37431 | +#endif |
| 37367 | 37432 | #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) |
| 37368 | 37433 | |
| 37369 | 37434 | #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE |
| 37370 | 37435 | { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 }, |
| 37371 | 37436 | #else |
| | @@ -37397,18 +37462,20 @@ |
| 37397 | 37462 | #else |
| 37398 | 37463 | { "geteuid", (sqlite3_syscall_ptr)0, 0 }, |
| 37399 | 37464 | #endif |
| 37400 | 37465 | #define osGeteuid ((uid_t(*)(void))aSyscall[21].pCurrent) |
| 37401 | 37466 | |
| 37402 | | -#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 37467 | +#if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \ |
| 37468 | + && !defined(SQLITE_WASI) |
| 37403 | 37469 | { "mmap", (sqlite3_syscall_ptr)mmap, 0 }, |
| 37404 | 37470 | #else |
| 37405 | 37471 | { "mmap", (sqlite3_syscall_ptr)0, 0 }, |
| 37406 | 37472 | #endif |
| 37407 | 37473 | #define osMmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[22].pCurrent) |
| 37408 | 37474 | |
| 37409 | | -#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 37475 | +#if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \ |
| 37476 | + && !defined(SQLITE_WASI) |
| 37410 | 37477 | { "munmap", (sqlite3_syscall_ptr)munmap, 0 }, |
| 37411 | 37478 | #else |
| 37412 | 37479 | { "munmap", (sqlite3_syscall_ptr)0, 0 }, |
| 37413 | 37480 | #endif |
| 37414 | 37481 | #define osMunmap ((int(*)(void*,size_t))aSyscall[23].pCurrent) |
| | @@ -61699,11 +61766,11 @@ |
| 61699 | 61766 | UNUSED_PARAMETER(isDirectMode); |
| 61700 | 61767 | #else |
| 61701 | 61768 | # define DIRECT_MODE isDirectMode |
| 61702 | 61769 | #endif |
| 61703 | 61770 | |
| 61704 | | - if( !pPager->changeCountDone && ALWAYS(pPager->dbSize>0) ){ |
| 61771 | + if( !pPager->changeCountDone && pPager->dbSize>0 ){ |
| 61705 | 61772 | PgHdr *pPgHdr; /* Reference to page 1 */ |
| 61706 | 61773 | |
| 61707 | 61774 | assert( !pPager->tempFile && isOpen(pPager->fd) ); |
| 61708 | 61775 | |
| 61709 | 61776 | /* Open page 1 of the file for writing. */ |
| | @@ -81848,11 +81915,13 @@ |
| 81848 | 81915 | rc = ctx.isError; |
| 81849 | 81916 | sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); |
| 81850 | 81917 | }else{ |
| 81851 | 81918 | sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8); |
| 81852 | 81919 | assert( rc==SQLITE_OK ); |
| 81853 | | - assert( enc==pVal->enc || db->mallocFailed ); |
| 81920 | + assert( enc==pVal->enc |
| 81921 | + || (pVal->flags & MEM_Str)==0 |
| 81922 | + || db->mallocFailed ); |
| 81854 | 81923 | #if 0 /* Not reachable except after a prior failure */ |
| 81855 | 81924 | rc = sqlite3VdbeChangeEncoding(pVal, enc); |
| 81856 | 81925 | if( rc==SQLITE_OK && sqlite3VdbeMemTooBig(pVal) ){ |
| 81857 | 81926 | rc = SQLITE_TOOBIG; |
| 81858 | 81927 | pCtx->pParse->nErr++; |
| | @@ -85716,10 +85785,11 @@ |
| 85716 | 85785 | ** by connection db have now been released. Call sqlite3ConnectionUnlocked() |
| 85717 | 85786 | ** to invoke any required unlock-notify callbacks. |
| 85718 | 85787 | */ |
| 85719 | 85788 | if( db->autoCommit ){ |
| 85720 | 85789 | sqlite3ConnectionUnlocked(db); |
| 85790 | + db->txnTime = 0; |
| 85721 | 85791 | } |
| 85722 | 85792 | |
| 85723 | 85793 | assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 ); |
| 85724 | 85794 | return (p->rc==SQLITE_BUSY ? SQLITE_BUSY : SQLITE_OK); |
| 85725 | 85795 | } |
| | @@ -88674,22 +88744,31 @@ |
| 88674 | 88744 | ** Return the current time for a statement. If the current time |
| 88675 | 88745 | ** is requested more than once within the same run of a single prepared |
| 88676 | 88746 | ** statement, the exact same time is returned for each invocation regardless |
| 88677 | 88747 | ** of the amount of time that elapses between invocations. In other words, |
| 88678 | 88748 | ** the time returned is always the time of the first call. |
| 88749 | +** |
| 88750 | +** Or, if bTxn, return the transaction time. The transaction time is the |
| 88751 | +** same for all calls within the same transaction. |
| 88752 | +** |
| 88753 | +** bTxn is 0 for SQL like datetime('now') and is 1 for datetime('txn'). |
| 88679 | 88754 | */ |
| 88680 | | -SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p){ |
| 88755 | +SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p, int bTxn){ |
| 88681 | 88756 | int rc; |
| 88682 | 88757 | #ifndef SQLITE_ENABLE_STAT4 |
| 88683 | | - sqlite3_int64 *piTime = &p->pVdbe->iCurrentTime; |
| 88758 | + sqlite3_int64 *piTime; |
| 88759 | + sqlite3 *db = p->pOut->db; |
| 88684 | 88760 | assert( p->pVdbe!=0 ); |
| 88761 | + piTime = bTxn ? &db->txnTime : &p->pVdbe->iCurrentTime; |
| 88685 | 88762 | #else |
| 88686 | 88763 | sqlite3_int64 iTime = 0; |
| 88687 | | - sqlite3_int64 *piTime = p->pVdbe!=0 ? &p->pVdbe->iCurrentTime : &iTime; |
| 88764 | + sqlite3_int64 *piTime; |
| 88765 | + sqlite3 *db = p->pOut->db; |
| 88766 | + piTime = bTxn ? &db->txnTime : p->pVdbe!=0 ? &p->pVdbe->iCurrentTime : &iTime; |
| 88688 | 88767 | #endif |
| 88689 | 88768 | if( *piTime==0 ){ |
| 88690 | | - rc = sqlite3OsCurrentTimeInt64(p->pOut->db->pVfs, piTime); |
| 88769 | + rc = sqlite3OsCurrentTimeInt64(db->pVfs, piTime); |
| 88691 | 88770 | if( rc ) *piTime = 0; |
| 88692 | 88771 | } |
| 88693 | 88772 | return *piTime; |
| 88694 | 88773 | } |
| 88695 | 88774 | |
| | @@ -158421,16 +158500,16 @@ |
| 158421 | 158500 | ** be greater than or equal to the (iCol) field prefix of sample i. |
| 158422 | 158501 | ** If (i>0), then pRec must also be greater than sample (i-1). */ |
| 158423 | 158502 | if( iCol>0 ){ |
| 158424 | 158503 | pRec->nField = iCol; |
| 158425 | 158504 | assert( sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)<=0 |
| 158426 | | - || pParse->db->mallocFailed ); |
| 158505 | + || pParse->db->mallocFailed || CORRUPT_DB ); |
| 158427 | 158506 | } |
| 158428 | 158507 | if( i>0 ){ |
| 158429 | 158508 | pRec->nField = nField; |
| 158430 | 158509 | assert( sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0 |
| 158431 | | - || pParse->db->mallocFailed ); |
| 158510 | + || pParse->db->mallocFailed || CORRUPT_DB ); |
| 158432 | 158511 | } |
| 158433 | 158512 | } |
| 158434 | 158513 | } |
| 158435 | 158514 | #endif /* ifdef SQLITE_DEBUG */ |
| 158436 | 158515 | |
| | @@ -162396,28 +162475,27 @@ |
| 162396 | 162475 | */ |
| 162397 | 162476 | static SQLITE_NOINLINE void whereCheckIfBloomFilterIsUseful( |
| 162398 | 162477 | const WhereInfo *pWInfo |
| 162399 | 162478 | ){ |
| 162400 | 162479 | int i; |
| 162401 | | - LogEst nSearch; |
| 162480 | + LogEst nSearch = 0; |
| 162402 | 162481 | |
| 162403 | 162482 | assert( pWInfo->nLevel>=2 ); |
| 162404 | 162483 | assert( OptimizationEnabled(pWInfo->pParse->db, SQLITE_BloomFilter) ); |
| 162405 | | - nSearch = pWInfo->a[0].pWLoop->nOut; |
| 162406 | | - for(i=1; i<pWInfo->nLevel; i++){ |
| 162484 | + for(i=0; i<pWInfo->nLevel; i++){ |
| 162407 | 162485 | WhereLoop *pLoop = pWInfo->a[i].pWLoop; |
| 162408 | 162486 | const unsigned int reqFlags = (WHERE_SELFCULL|WHERE_COLUMN_EQ); |
| 162409 | | - if( (pLoop->wsFlags & reqFlags)==reqFlags |
| 162487 | + SrcItem *pItem = &pWInfo->pTabList->a[pLoop->iTab]; |
| 162488 | + Table *pTab = pItem->pTab; |
| 162489 | + if( (pTab->tabFlags & TF_HasStat1)==0 ) break; |
| 162490 | + pTab->tabFlags |= TF_StatsUsed; |
| 162491 | + if( i>=1 |
| 162492 | + && (pLoop->wsFlags & reqFlags)==reqFlags |
| 162410 | 162493 | /* vvvvvv--- Always the case if WHERE_COLUMN_EQ is defined */ |
| 162411 | 162494 | && ALWAYS((pLoop->wsFlags & (WHERE_IPK|WHERE_INDEXED))!=0) |
| 162412 | 162495 | ){ |
| 162413 | | - SrcItem *pItem = &pWInfo->pTabList->a[pLoop->iTab]; |
| 162414 | | - Table *pTab = pItem->pTab; |
| 162415 | | - pTab->tabFlags |= TF_StatsUsed; |
| 162416 | | - if( nSearch > pTab->nRowLogEst |
| 162417 | | - && (pTab->tabFlags & TF_HasStat1)!=0 |
| 162418 | | - ){ |
| 162496 | + if( nSearch > pTab->nRowLogEst ){ |
| 162419 | 162497 | testcase( pItem->fg.jointype & JT_LEFT ); |
| 162420 | 162498 | pLoop->wsFlags |= WHERE_BLOOMFILTER; |
| 162421 | 162499 | pLoop->wsFlags &= ~WHERE_IDX_ONLY; |
| 162422 | 162500 | WHERETRACE(0xffffffff, ( |
| 162423 | 162501 | "-> use Bloom-filter on loop %c because there are ~%.1e " |
| | @@ -215795,11 +215873,11 @@ |
| 215795 | 215873 | if( pCsr->iDb<0 ) return SQLITE_OK; |
| 215796 | 215874 | }else{ |
| 215797 | 215875 | pCsr->iDb = 0; |
| 215798 | 215876 | } |
| 215799 | 215877 | pBt = db->aDb[pCsr->iDb].pBt; |
| 215800 | | - if( pBt==0 ) return SQLITE_OK; |
| 215878 | + if( NEVER(pBt==0) ) return SQLITE_OK; |
| 215801 | 215879 | pCsr->pPager = sqlite3BtreePager(pBt); |
| 215802 | 215880 | pCsr->szPage = sqlite3BtreeGetPageSize(pBt); |
| 215803 | 215881 | pCsr->mxPgno = sqlite3BtreeLastPage(pBt); |
| 215804 | 215882 | if( idxNum & 1 ){ |
| 215805 | 215883 | assert( argc>(idxNum>>1) ); |
| | @@ -215886,22 +215964,24 @@ |
| 215886 | 215964 | if( argc==1 ){ |
| 215887 | 215965 | zErr = "cannot delete"; |
| 215888 | 215966 | goto update_fail; |
| 215889 | 215967 | } |
| 215890 | 215968 | pgno = sqlite3_value_int(argv[0]); |
| 215891 | | - if( (Pgno)sqlite3_value_int(argv[1])!=pgno ){ |
| 215969 | + if( sqlite3_value_type(argv[0])==SQLITE_NULL |
| 215970 | + || (Pgno)sqlite3_value_int(argv[1])!=pgno |
| 215971 | + ){ |
| 215892 | 215972 | zErr = "cannot insert"; |
| 215893 | 215973 | goto update_fail; |
| 215894 | 215974 | } |
| 215895 | 215975 | zSchema = (const char*)sqlite3_value_text(argv[4]); |
| 215896 | | - iDb = zSchema ? sqlite3FindDbName(pTab->db, zSchema) : -1; |
| 215897 | | - if( iDb<0 ){ |
| 215976 | + iDb = ALWAYS(zSchema) ? sqlite3FindDbName(pTab->db, zSchema) : -1; |
| 215977 | + if( NEVER(iDb<0) ){ |
| 215898 | 215978 | zErr = "no such schema"; |
| 215899 | 215979 | goto update_fail; |
| 215900 | 215980 | } |
| 215901 | 215981 | pBt = pTab->db->aDb[iDb].pBt; |
| 215902 | | - if( pgno<1 || pBt==0 || pgno>sqlite3BtreeLastPage(pBt) ){ |
| 215982 | + if( NEVER(pgno<1) || NEVER(pBt==0) || NEVER(pgno>sqlite3BtreeLastPage(pBt)) ){ |
| 215903 | 215983 | zErr = "bad page number"; |
| 215904 | 215984 | goto update_fail; |
| 215905 | 215985 | } |
| 215906 | 215986 | szPage = sqlite3BtreeGetPageSize(pBt); |
| 215907 | 215987 | if( sqlite3_value_type(argv[3])!=SQLITE_BLOB |
| | @@ -215936,16 +216016,15 @@ |
| 215936 | 216016 | */ |
| 215937 | 216017 | static int dbpageBegin(sqlite3_vtab *pVtab){ |
| 215938 | 216018 | DbpageTable *pTab = (DbpageTable *)pVtab; |
| 215939 | 216019 | sqlite3 *db = pTab->db; |
| 215940 | 216020 | int i; |
| 215941 | | - int rc = SQLITE_OK; |
| 215942 | | - for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ |
| 216021 | + for(i=0; i<db->nDb; i++){ |
| 215943 | 216022 | Btree *pBt = db->aDb[i].pBt; |
| 215944 | | - if( pBt ) rc = sqlite3BtreeBeginTrans(pBt, 1, 0); |
| 216023 | + if( pBt ) (void)sqlite3BtreeBeginTrans(pBt, 1, 0); |
| 215945 | 216024 | } |
| 215946 | | - return rc; |
| 216025 | + return SQLITE_OK; |
| 215947 | 216026 | } |
| 215948 | 216027 | |
| 215949 | 216028 | |
| 215950 | 216029 | /* |
| 215951 | 216030 | ** Invoke this routine to register the "dbpage" virtual table module |
| | @@ -230526,10 +230605,12 @@ |
| 230526 | 230605 | |
| 230527 | 230606 | #if FTS5_MAX_PREFIX_INDEXES > 31 |
| 230528 | 230607 | # error "FTS5_MAX_PREFIX_INDEXES is too large" |
| 230529 | 230608 | #endif |
| 230530 | 230609 | |
| 230610 | +#define FTS5_MAX_LEVEL 64 |
| 230611 | + |
| 230531 | 230612 | /* |
| 230532 | 230613 | ** Details: |
| 230533 | 230614 | ** |
| 230534 | 230615 | ** The %_data table managed by this module, |
| 230535 | 230616 | ** |
| | @@ -235243,11 +235324,11 @@ |
| 235243 | 235324 | Fts5StructureLevel *pLvl; |
| 235244 | 235325 | nByte = nSeg * sizeof(Fts5StructureSegment); |
| 235245 | 235326 | pNew->nLevel = pStruct->nLevel+1; |
| 235246 | 235327 | pNew->nRef = 1; |
| 235247 | 235328 | pNew->nWriteCounter = pStruct->nWriteCounter; |
| 235248 | | - pLvl = &pNew->aLevel[pStruct->nLevel]; |
| 235329 | + pLvl = &pNew->aLevel[MIN(pStruct->nLevel, FTS5_MAX_LEVEL-1)]; |
| 235249 | 235330 | pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(&p->rc, nByte); |
| 235250 | 235331 | if( pLvl->aSeg ){ |
| 235251 | 235332 | int iLvl, iSeg; |
| 235252 | 235333 | int iSegOut = 0; |
| 235253 | 235334 | /* Iterate through all segments, from oldest to newest. Add them to |
| | @@ -240088,11 +240169,11 @@ |
| 240088 | 240169 | int nArg, /* Number of args */ |
| 240089 | 240170 | sqlite3_value **apUnused /* Function arguments */ |
| 240090 | 240171 | ){ |
| 240091 | 240172 | assert( nArg==0 ); |
| 240092 | 240173 | UNUSED_PARAM2(nArg, apUnused); |
| 240093 | | - sqlite3_result_text(pCtx, "fts5: 2023-02-03 12:03:56 75cdaafc77b8a1efc84e71e90470994227f376e7d7de34c813e75dcadbb9f268", -1, SQLITE_TRANSIENT); |
| 240174 | + sqlite3_result_text(pCtx, "fts5: 2023-02-08 14:49:52 6b41ba2e996ab7b9c3943ab93a19748db5cf37792f5d59d20eec301085282355", -1, SQLITE_TRANSIENT); |
| 240094 | 240175 | } |
| 240095 | 240176 | |
| 240096 | 240177 | /* |
| 240097 | 240178 | ** Return true if zName is the extension on one of the shadow tables used |
| 240098 | 240179 | ** by this module. |
| 240099 | 240180 | |