| | @@ -456,11 +456,11 @@ |
| 456 | 456 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 457 | 457 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 458 | 458 | */ |
| 459 | 459 | #define SQLITE_VERSION "3.42.0" |
| 460 | 460 | #define SQLITE_VERSION_NUMBER 3042000 |
| 461 | | -#define SQLITE_SOURCE_ID "2023-05-01 20:42:15 342af5b4fa0bd7c699e5497161db13d0cf795c7a5875ae30d666122e518f213b" |
| 461 | +#define SQLITE_SOURCE_ID "2023-05-05 14:16:31 fece588b186c4f9f76d626313e35336fd5681e966e9bd0fa1053b147c4e3c315" |
| 462 | 462 | |
| 463 | 463 | /* |
| 464 | 464 | ** CAPI3REF: Run-Time Library Version Numbers |
| 465 | 465 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 466 | 466 | ** |
| | @@ -2450,32 +2450,32 @@ |
| 2450 | 2450 | ** configuration setting is never used, then the default maximum is determined |
| 2451 | 2451 | ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that |
| 2452 | 2452 | ** compile-time option is not set, then the default maximum is 1073741824. |
| 2453 | 2453 | ** </dl> |
| 2454 | 2454 | */ |
| 2455 | | -#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 2456 | | -#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 2457 | | -#define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| 2458 | | -#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ |
| 2459 | | -#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ |
| 2460 | | -#define SQLITE_CONFIG_SCRATCH 6 /* No longer used */ |
| 2461 | | -#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ |
| 2462 | | -#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ |
| 2463 | | -#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ |
| 2464 | | -#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ |
| 2465 | | -#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ |
| 2466 | | -/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ |
| 2467 | | -#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ |
| 2468 | | -#define SQLITE_CONFIG_PCACHE 14 /* no-op */ |
| 2469 | | -#define SQLITE_CONFIG_GETPCACHE 15 /* no-op */ |
| 2470 | | -#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ |
| 2471 | | -#define SQLITE_CONFIG_URI 17 /* int */ |
| 2472 | | -#define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */ |
| 2473 | | -#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ |
| 2455 | +#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 2456 | +#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 2457 | +#define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| 2458 | +#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ |
| 2459 | +#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ |
| 2460 | +#define SQLITE_CONFIG_SCRATCH 6 /* No longer used */ |
| 2461 | +#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ |
| 2462 | +#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ |
| 2463 | +#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ |
| 2464 | +#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ |
| 2465 | +#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ |
| 2466 | +/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ |
| 2467 | +#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ |
| 2468 | +#define SQLITE_CONFIG_PCACHE 14 /* no-op */ |
| 2469 | +#define SQLITE_CONFIG_GETPCACHE 15 /* no-op */ |
| 2470 | +#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ |
| 2471 | +#define SQLITE_CONFIG_URI 17 /* int */ |
| 2472 | +#define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */ |
| 2473 | +#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ |
| 2474 | 2474 | #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ |
| 2475 | | -#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ |
| 2476 | | -#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ |
| 2475 | +#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ |
| 2476 | +#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ |
| 2477 | 2477 | #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ |
| 2478 | 2478 | #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
| 2479 | 2479 | #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ |
| 2480 | 2480 | #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ |
| 2481 | 2481 | #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ |
| | @@ -6563,10 +6563,17 @@ |
| 6563 | 6563 | ** ^SQLite implements this interface by calling the xSleep() |
| 6564 | 6564 | ** method of the default [sqlite3_vfs] object. If the xSleep() method |
| 6565 | 6565 | ** of the default VFS is not implemented correctly, or not implemented at |
| 6566 | 6566 | ** all, then the behavior of sqlite3_sleep() may deviate from the description |
| 6567 | 6567 | ** in the previous paragraphs. |
| 6568 | +** |
| 6569 | +** If a negative argument is passed to sqlite3_sleep() the results vary by |
| 6570 | +** VFS and operating system. Some system treat a negative argument as an |
| 6571 | +** instruction to sleep forever. Others understand it to mean do not sleep |
| 6572 | +** at all. ^In SQLite version 3.42.0 and later, a negative |
| 6573 | +** argument passed into sqlite3_sleep() is changed to zero before it is relayed |
| 6574 | +** down into the xSleep method of the VFS. |
| 6568 | 6575 | */ |
| 6569 | 6576 | SQLITE_API int sqlite3_sleep(int); |
| 6570 | 6577 | |
| 6571 | 6578 | /* |
| 6572 | 6579 | ** CAPI3REF: Name Of The Folder Holding Temporary Files |
| | @@ -18293,10 +18300,11 @@ |
| 18293 | 18300 | unsigned bHasVCol:1; /* Index references one or more VIRTUAL columns */ |
| 18294 | 18301 | unsigned bHasExpr:1; /* Index contains an expression, either a literal |
| 18295 | 18302 | ** expression, or a reference to a VIRTUAL column */ |
| 18296 | 18303 | #ifdef SQLITE_ENABLE_STAT4 |
| 18297 | 18304 | int nSample; /* Number of elements in aSample[] */ |
| 18305 | + int mxSample; /* Number of slots allocated to aSample[] */ |
| 18298 | 18306 | int nSampleCol; /* Size of IndexSample.anEq[] and so on */ |
| 18299 | 18307 | tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */ |
| 18300 | 18308 | IndexSample *aSample; /* Samples of the left-most key */ |
| 18301 | 18309 | tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this index */ |
| 18302 | 18310 | tRowcnt nRowEst0; /* Non-logarithmic number of rows in the index */ |
| | @@ -23687,10 +23695,11 @@ |
| 23687 | 23695 | char validYMD; /* True (1) if Y,M,D are valid */ |
| 23688 | 23696 | char validHMS; /* True (1) if h,m,s are valid */ |
| 23689 | 23697 | char validTZ; /* True (1) if tz is valid */ |
| 23690 | 23698 | char tzSet; /* Timezone was set explicitly */ |
| 23691 | 23699 | char isError; /* An overflow has occurred */ |
| 23700 | + char useSubsec; /* Display subsecond precision */ |
| 23692 | 23701 | }; |
| 23693 | 23702 | |
| 23694 | 23703 | |
| 23695 | 23704 | /* |
| 23696 | 23705 | ** Convert zDate into one or more integers according to the conversion |
| | @@ -24001,10 +24010,15 @@ |
| 24001 | 24010 | }else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){ |
| 24002 | 24011 | return setDateTimeToCurrent(context, p); |
| 24003 | 24012 | }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8)>0 ){ |
| 24004 | 24013 | setRawDateNumber(p, r); |
| 24005 | 24014 | return 0; |
| 24015 | + }else if( (sqlite3StrICmp(zDate,"subsec")==0 |
| 24016 | + || sqlite3StrICmp(zDate,"subsecond")==0) |
| 24017 | + && sqlite3NotPureFunc(context) ){ |
| 24018 | + p->useSubsec = 1; |
| 24019 | + return setDateTimeToCurrent(context, p); |
| 24006 | 24020 | } |
| 24007 | 24021 | return 1; |
| 24008 | 24022 | } |
| 24009 | 24023 | |
| 24010 | 24024 | /* The julian day number for 9999-12-31 23:59:59.999 is 5373484.4999999. |
| | @@ -24415,12 +24429,26 @@ |
| 24415 | 24429 | /* |
| 24416 | 24430 | ** start of TTTTT |
| 24417 | 24431 | ** |
| 24418 | 24432 | ** Move the date backwards to the beginning of the current day, |
| 24419 | 24433 | ** or month or year. |
| 24434 | + ** |
| 24435 | + ** subsecond |
| 24436 | + ** subsec |
| 24437 | + ** |
| 24438 | + ** Show subsecond precision in the output of datetime() and |
| 24439 | + ** unixepoch() and strftime('%s'). |
| 24420 | 24440 | */ |
| 24421 | | - if( sqlite3_strnicmp(z, "start of ", 9)!=0 ) break; |
| 24441 | + if( sqlite3_strnicmp(z, "start of ", 9)!=0 ){ |
| 24442 | + if( sqlite3_stricmp(z, "subsec")==0 |
| 24443 | + || sqlite3_stricmp(z, "subsecond")==0 |
| 24444 | + ){ |
| 24445 | + p->useSubsec = 1; |
| 24446 | + rc = 0; |
| 24447 | + } |
| 24448 | + break; |
| 24449 | + } |
| 24422 | 24450 | if( !p->validJD && !p->validYMD && !p->validHMS ) break; |
| 24423 | 24451 | z += 9; |
| 24424 | 24452 | computeYMD(p); |
| 24425 | 24453 | p->validHMS = 1; |
| 24426 | 24454 | p->h = p->m = 0; |
| | @@ -24614,11 +24642,15 @@ |
| 24614 | 24642 | sqlite3_value **argv |
| 24615 | 24643 | ){ |
| 24616 | 24644 | DateTime x; |
| 24617 | 24645 | if( isDate(context, argc, argv, &x)==0 ){ |
| 24618 | 24646 | computeJD(&x); |
| 24619 | | - sqlite3_result_int64(context, x.iJD/1000 - 21086676*(i64)10000); |
| 24647 | + if( x.useSubsec ){ |
| 24648 | + sqlite3_result_double(context, (x.iJD - 21086676*(i64)10000000)/1000.0); |
| 24649 | + }else{ |
| 24650 | + sqlite3_result_int64(context, x.iJD/1000 - 21086676*(i64)10000); |
| 24651 | + } |
| 24620 | 24652 | } |
| 24621 | 24653 | } |
| 24622 | 24654 | |
| 24623 | 24655 | /* |
| 24624 | 24656 | ** datetime( TIMESTRING, MOD, MOD, ...) |
| | @@ -24630,12 +24662,12 @@ |
| 24630 | 24662 | int argc, |
| 24631 | 24663 | sqlite3_value **argv |
| 24632 | 24664 | ){ |
| 24633 | 24665 | DateTime x; |
| 24634 | 24666 | if( isDate(context, argc, argv, &x)==0 ){ |
| 24635 | | - int Y, s; |
| 24636 | | - char zBuf[24]; |
| 24667 | + int Y, s, n; |
| 24668 | + char zBuf[32]; |
| 24637 | 24669 | computeYMD_HMS(&x); |
| 24638 | 24670 | Y = x.Y; |
| 24639 | 24671 | if( Y<0 ) Y = -Y; |
| 24640 | 24672 | zBuf[1] = '0' + (Y/1000)%10; |
| 24641 | 24673 | zBuf[2] = '0' + (Y/100)%10; |
| | @@ -24652,19 +24684,32 @@ |
| 24652 | 24684 | zBuf[13] = '0' + (x.h)%10; |
| 24653 | 24685 | zBuf[14] = ':'; |
| 24654 | 24686 | zBuf[15] = '0' + (x.m/10)%10; |
| 24655 | 24687 | zBuf[16] = '0' + (x.m)%10; |
| 24656 | 24688 | zBuf[17] = ':'; |
| 24657 | | - s = (int)x.s; |
| 24658 | | - zBuf[18] = '0' + (s/10)%10; |
| 24659 | | - zBuf[19] = '0' + (s)%10; |
| 24660 | | - zBuf[20] = 0; |
| 24689 | + if( x.useSubsec ){ |
| 24690 | + s = (int)1000.0*x.s; |
| 24691 | + zBuf[18] = '0' + (s/10000)%10; |
| 24692 | + zBuf[19] = '0' + (s/1000)%10; |
| 24693 | + zBuf[20] = '.'; |
| 24694 | + zBuf[21] = '0' + (s/100)%10; |
| 24695 | + zBuf[22] = '0' + (s/10)%10; |
| 24696 | + zBuf[23] = '0' + (s)%10; |
| 24697 | + zBuf[24] = 0; |
| 24698 | + n = 24; |
| 24699 | + }else{ |
| 24700 | + s = (int)x.s; |
| 24701 | + zBuf[18] = '0' + (s/10)%10; |
| 24702 | + zBuf[19] = '0' + (s)%10; |
| 24703 | + zBuf[20] = 0; |
| 24704 | + n = 20; |
| 24705 | + } |
| 24661 | 24706 | if( x.Y<0 ){ |
| 24662 | 24707 | zBuf[0] = '-'; |
| 24663 | | - sqlite3_result_text(context, zBuf, 20, SQLITE_TRANSIENT); |
| 24708 | + sqlite3_result_text(context, zBuf, n, SQLITE_TRANSIENT); |
| 24664 | 24709 | }else{ |
| 24665 | | - sqlite3_result_text(context, &zBuf[1], 19, SQLITE_TRANSIENT); |
| 24710 | + sqlite3_result_text(context, &zBuf[1], n-1, SQLITE_TRANSIENT); |
| 24666 | 24711 | } |
| 24667 | 24712 | } |
| 24668 | 24713 | } |
| 24669 | 24714 | |
| 24670 | 24715 | /* |
| | @@ -24677,24 +24722,37 @@ |
| 24677 | 24722 | int argc, |
| 24678 | 24723 | sqlite3_value **argv |
| 24679 | 24724 | ){ |
| 24680 | 24725 | DateTime x; |
| 24681 | 24726 | if( isDate(context, argc, argv, &x)==0 ){ |
| 24682 | | - int s; |
| 24727 | + int s, n; |
| 24683 | 24728 | char zBuf[16]; |
| 24684 | 24729 | computeHMS(&x); |
| 24685 | 24730 | zBuf[0] = '0' + (x.h/10)%10; |
| 24686 | 24731 | zBuf[1] = '0' + (x.h)%10; |
| 24687 | 24732 | zBuf[2] = ':'; |
| 24688 | 24733 | zBuf[3] = '0' + (x.m/10)%10; |
| 24689 | 24734 | zBuf[4] = '0' + (x.m)%10; |
| 24690 | 24735 | zBuf[5] = ':'; |
| 24691 | | - s = (int)x.s; |
| 24692 | | - zBuf[6] = '0' + (s/10)%10; |
| 24693 | | - zBuf[7] = '0' + (s)%10; |
| 24694 | | - zBuf[8] = 0; |
| 24695 | | - sqlite3_result_text(context, zBuf, 8, SQLITE_TRANSIENT); |
| 24736 | + if( x.useSubsec ){ |
| 24737 | + s = (int)1000.0*x.s; |
| 24738 | + zBuf[6] = '0' + (s/10000)%10; |
| 24739 | + zBuf[7] = '0' + (s/1000)%10; |
| 24740 | + zBuf[8] = '.'; |
| 24741 | + zBuf[9] = '0' + (s/100)%10; |
| 24742 | + zBuf[10] = '0' + (s/10)%10; |
| 24743 | + zBuf[11] = '0' + (s)%10; |
| 24744 | + zBuf[12] = 0; |
| 24745 | + n = 12; |
| 24746 | + }else{ |
| 24747 | + s = (int)x.s; |
| 24748 | + zBuf[6] = '0' + (s/10)%10; |
| 24749 | + zBuf[7] = '0' + (s)%10; |
| 24750 | + zBuf[8] = 0; |
| 24751 | + n = 8; |
| 24752 | + } |
| 24753 | + sqlite3_result_text(context, zBuf, n, SQLITE_TRANSIENT); |
| 24696 | 24754 | } |
| 24697 | 24755 | } |
| 24698 | 24756 | |
| 24699 | 24757 | /* |
| 24700 | 24758 | ** date( TIMESTRING, MOD, MOD, ...) |
| | @@ -24821,12 +24879,17 @@ |
| 24821 | 24879 | case 'M': { |
| 24822 | 24880 | sqlite3_str_appendf(&sRes,"%02d",x.m); |
| 24823 | 24881 | break; |
| 24824 | 24882 | } |
| 24825 | 24883 | case 's': { |
| 24826 | | - i64 iS = (i64)(x.iJD/1000 - 21086676*(i64)10000); |
| 24827 | | - sqlite3_str_appendf(&sRes,"%lld",iS); |
| 24884 | + if( x.useSubsec ){ |
| 24885 | + sqlite3_str_appendf(&sRes,"%.3f", |
| 24886 | + (x.iJD - 21086676*(i64)10000000)/1000.0); |
| 24887 | + }else{ |
| 24888 | + i64 iS = (i64)(x.iJD/1000 - 21086676*(i64)10000); |
| 24889 | + sqlite3_str_appendf(&sRes,"%lld",iS); |
| 24890 | + } |
| 24828 | 24891 | break; |
| 24829 | 24892 | } |
| 24830 | 24893 | case 'S': { |
| 24831 | 24894 | sqlite3_str_appendf(&sRes,"%02d",(int)x.s); |
| 24832 | 24895 | break; |
| | @@ -30700,10 +30763,11 @@ |
| 30700 | 30763 | nsd = 16 + flag_altform2*10; |
| 30701 | 30764 | bufpt = buf; |
| 30702 | 30765 | { |
| 30703 | 30766 | i64 szBufNeeded; /* Size of a temporary buffer needed */ |
| 30704 | 30767 | szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+15; |
| 30768 | + if( cThousand ) szBufNeeded += (e2+2)/3; |
| 30705 | 30769 | if( szBufNeeded > etBUFSIZE ){ |
| 30706 | 30770 | bufpt = zExtra = printfTempBuf(pAccum, szBufNeeded); |
| 30707 | 30771 | if( bufpt==0 ) return; |
| 30708 | 30772 | } |
| 30709 | 30773 | } |
| | @@ -30717,14 +30781,16 @@ |
| 30717 | 30781 | if( e2<0 ){ |
| 30718 | 30782 | *(bufpt++) = '0'; |
| 30719 | 30783 | }else if( msd>0 ){ |
| 30720 | 30784 | for(; e2>=0; e2--){ |
| 30721 | 30785 | *(bufpt++) = et_getdigit_int(&longvalue,&msd); |
| 30786 | + if( cThousand && (e2%3)==0 && e2>1 ) *(bufpt++) = ','; |
| 30722 | 30787 | } |
| 30723 | 30788 | }else{ |
| 30724 | 30789 | for(; e2>=0; e2--){ |
| 30725 | 30790 | *(bufpt++) = et_getdigit(&realvalue,&nsd); |
| 30791 | + if( cThousand && (e2%3)==0 && e2>1 ) *(bufpt++) = ','; |
| 30726 | 30792 | } |
| 30727 | 30793 | } |
| 30728 | 30794 | /* The decimal point */ |
| 30729 | 30795 | if( flag_dp ){ |
| 30730 | 30796 | *(bufpt++) = '.'; |
| | @@ -67126,11 +67192,13 @@ |
| 67126 | 67192 | if( pWal->syncHeader ){ |
| 67127 | 67193 | rc = sqlite3OsSync(pWal->pWalFd, CKPT_SYNC_FLAGS(sync_flags)); |
| 67128 | 67194 | if( rc ) return rc; |
| 67129 | 67195 | } |
| 67130 | 67196 | } |
| 67131 | | - assert( (int)pWal->szPage==szPage ); |
| 67197 | + if( (int)pWal->szPage!=szPage ){ |
| 67198 | + return SQLITE_CORRUPT_BKPT; /* TH3 test case: cov1/corrupt155.test */ |
| 67199 | + } |
| 67132 | 67200 | |
| 67133 | 67201 | /* Setup information needed to write frames into the WAL */ |
| 67134 | 67202 | w.pWal = pWal; |
| 67135 | 67203 | w.pFd = pWal->pWalFd; |
| 67136 | 67204 | w.iSyncPoint = 0; |
| | @@ -67786,11 +67854,11 @@ |
| 67786 | 67854 | ** Cell content makes use of variable length integers. A variable |
| 67787 | 67855 | ** length integer is 1 to 9 bytes where the lower 7 bits of each |
| 67788 | 67856 | ** byte are used. The integer consists of all bytes that have bit 8 set and |
| 67789 | 67857 | ** the first byte with bit 8 clear. The most significant byte of the integer |
| 67790 | 67858 | ** appears first. A variable-length integer may not be more than 9 bytes long. |
| 67791 | | -** As a special case, all 8 bytes of the 9th byte are used as data. This |
| 67859 | +** As a special case, all 8 bits of the 9th byte are used as data. This |
| 67792 | 67860 | ** allows a 64-bit integer to be encoded in 9 bytes. |
| 67793 | 67861 | ** |
| 67794 | 67862 | ** 0x00 becomes 0x00000000 |
| 67795 | 67863 | ** 0x7f becomes 0x0000007f |
| 67796 | 67864 | ** 0x81 0x00 becomes 0x00000080 |
| | @@ -116967,17 +117035,22 @@ |
| 116967 | 117035 | if( zIndex==0 ) continue; |
| 116968 | 117036 | nSample = sqlite3_column_int(pStmt, 1); |
| 116969 | 117037 | pIdx = findIndexOrPrimaryKey(db, zIndex, zDb); |
| 116970 | 117038 | assert( pIdx==0 || pIdx->nSample==0 ); |
| 116971 | 117039 | if( pIdx==0 ) continue; |
| 117040 | + if( pIdx->aSample!=0 ){ |
| 117041 | + /* The same index appears in sqlite_stat4 under multiple names */ |
| 117042 | + continue; |
| 117043 | + } |
| 116972 | 117044 | assert( !HasRowid(pIdx->pTable) || pIdx->nColumn==pIdx->nKeyCol+1 ); |
| 116973 | 117045 | if( !HasRowid(pIdx->pTable) && IsPrimaryKeyIndex(pIdx) ){ |
| 116974 | 117046 | nIdxCol = pIdx->nKeyCol; |
| 116975 | 117047 | }else{ |
| 116976 | 117048 | nIdxCol = pIdx->nColumn; |
| 116977 | 117049 | } |
| 116978 | 117050 | pIdx->nSampleCol = nIdxCol; |
| 117051 | + pIdx->mxSample = nSample; |
| 116979 | 117052 | nByte = sizeof(IndexSample) * nSample; |
| 116980 | 117053 | nByte += sizeof(tRowcnt) * nIdxCol * 3 * nSample; |
| 116981 | 117054 | nByte += nIdxCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */ |
| 116982 | 117055 | |
| 116983 | 117056 | pIdx->aSample = sqlite3DbMallocZero(db, nByte); |
| | @@ -117013,10 +117086,15 @@ |
| 117013 | 117086 | |
| 117014 | 117087 | zIndex = (char *)sqlite3_column_text(pStmt, 0); |
| 117015 | 117088 | if( zIndex==0 ) continue; |
| 117016 | 117089 | pIdx = findIndexOrPrimaryKey(db, zIndex, zDb); |
| 117017 | 117090 | if( pIdx==0 ) continue; |
| 117091 | + if( pIdx->nSample>=pIdx->mxSample ){ |
| 117092 | + /* Too many slots used because the same index appears in |
| 117093 | + ** sqlite_stat4 using multiple names */ |
| 117094 | + continue; |
| 117095 | + } |
| 117018 | 117096 | /* This next condition is true if data has already been loaded from |
| 117019 | 117097 | ** the sqlite_stat4 table. */ |
| 117020 | 117098 | nCol = pIdx->nSampleCol; |
| 117021 | 117099 | if( pIdx!=pPrevIdx ){ |
| 117022 | 117100 | initAvgEq(pPrevIdx); |
| | @@ -117056,11 +117134,12 @@ |
| 117056 | 117134 | static int loadStat4(sqlite3 *db, const char *zDb){ |
| 117057 | 117135 | int rc = SQLITE_OK; /* Result codes from subroutines */ |
| 117058 | 117136 | const Table *pStat4; |
| 117059 | 117137 | |
| 117060 | 117138 | assert( db->lookaside.bDisable ); |
| 117061 | | - if( (pStat4 = sqlite3FindTable(db, "sqlite_stat4", zDb))!=0 |
| 117139 | + if( OptimizationEnabled(db, SQLITE_Stat4) |
| 117140 | + && (pStat4 = sqlite3FindTable(db, "sqlite_stat4", zDb))!=0 |
| 117062 | 117141 | && IsOrdinaryTable(pStat4) |
| 117063 | 117142 | ){ |
| 117064 | 117143 | rc = loadStatTbl(db, |
| 117065 | 117144 | "SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx COLLATE nocase", |
| 117066 | 117145 | "SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat4", |
| | @@ -118904,11 +118983,11 @@ |
| 118904 | 118983 | } |
| 118905 | 118984 | |
| 118906 | 118985 | if( IsOrdinaryTable(pTable) ){ |
| 118907 | 118986 | sqlite3FkDelete(db, pTable); |
| 118908 | 118987 | } |
| 118909 | | -#ifndef SQLITE_OMIT_VIRTUAL_TABLE |
| 118988 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 118910 | 118989 | else if( IsVirtual(pTable) ){ |
| 118911 | 118990 | sqlite3VtabClear(db, pTable); |
| 118912 | 118991 | } |
| 118913 | 118992 | #endif |
| 118914 | 118993 | else{ |
| | @@ -126832,11 +126911,11 @@ |
| 126832 | 126911 | |
| 126833 | 126912 | #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 126834 | 126913 | /* |
| 126835 | 126914 | ** The "unknown" function is automatically substituted in place of |
| 126836 | 126915 | ** any unrecognized function name when doing an EXPLAIN or EXPLAIN QUERY PLAN |
| 126837 | | -** when the SQLITE_ENABLE_UNKNOWN_FUNCTION compile-time option is used. |
| 126916 | +** when the SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION compile-time option is used. |
| 126838 | 126917 | ** When the "sqlite3" command-line shell is built using this functionality, |
| 126839 | 126918 | ** that allows an EXPLAIN or EXPLAIN QUERY PLAN for complex queries |
| 126840 | 126919 | ** involving application-defined functions to be examined in a generic |
| 126841 | 126920 | ** sqlite3 shell. |
| 126842 | 126921 | */ |
| | @@ -139592,11 +139671,11 @@ |
| 139592 | 139671 | ** by a prior OP_MakeRecord. In this case nData==1 and regData |
| 139593 | 139672 | ** will be completely unrelated to regOrigData. |
| 139594 | 139673 | ** (2) All output columns are included in the sort record. In that |
| 139595 | 139674 | ** case regData==regOrigData. |
| 139596 | 139675 | ** (3) Some output columns are omitted from the sort record due to |
| 139597 | | - ** the SQLITE_ENABLE_SORTER_REFERENCE optimization, or due to the |
| 139676 | + ** the SQLITE_ENABLE_SORTER_REFERENCES optimization, or due to the |
| 139598 | 139677 | ** SQLITE_ECEL_OMITREF optimization, or due to the |
| 139599 | 139678 | ** SortCtx.pDeferredRowLoad optimiation. In any of these cases |
| 139600 | 139679 | ** regOrigData is 0 to prevent this routine from trying to copy |
| 139601 | 139680 | ** values that might not yet exist. |
| 139602 | 139681 | */ |
| | @@ -152059,11 +152138,14 @@ |
| 152059 | 152138 | default: |
| 152060 | 152139 | xMethod = pMod->xRelease; |
| 152061 | 152140 | break; |
| 152062 | 152141 | } |
| 152063 | 152142 | if( xMethod && pVTab->iSavepoint>iSavepoint ){ |
| 152143 | + u64 savedFlags = (db->flags & SQLITE_Defensive); |
| 152144 | + db->flags &= ~(u64)SQLITE_Defensive; |
| 152064 | 152145 | rc = xMethod(pVTab->pVtab, iSavepoint); |
| 152146 | + db->flags |= savedFlags; |
| 152065 | 152147 | } |
| 152066 | 152148 | sqlite3VtabUnlock(pVTab); |
| 152067 | 152149 | } |
| 152068 | 152150 | } |
| 152069 | 152151 | } |
| | @@ -153984,10 +154066,13 @@ |
| 153984 | 154066 | rc = WRC_Prune; |
| 153985 | 154067 | reg = ++pWalker->pParse->nMem; /* Register for column value */ |
| 153986 | 154068 | reg = sqlite3ExprCodeTarget(pWalker->pParse, pExpr, reg); |
| 153987 | 154069 | pExpr->op = TK_REGISTER; |
| 153988 | 154070 | pExpr->iTable = reg; |
| 154071 | + }else if( pExpr->op==TK_TRUEFALSE ){ |
| 154072 | + /* Do not walk disabled expressions. tag-20230504-1 */ |
| 154073 | + return WRC_Prune; |
| 153989 | 154074 | } |
| 153990 | 154075 | return rc; |
| 153991 | 154076 | } |
| 153992 | 154077 | |
| 153993 | 154078 | /* |
| | @@ -156951,11 +157036,11 @@ |
| 156951 | 157036 | if( op==TK_ISNULL |
| 156952 | 157037 | && !ExprHasProperty(pExpr,EP_OuterON) |
| 156953 | 157038 | && 0==sqlite3ExprCanBeNull(pLeft) |
| 156954 | 157039 | ){ |
| 156955 | 157040 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 156956 | | - pExpr->op = TK_TRUEFALSE; |
| 157041 | + pExpr->op = TK_TRUEFALSE; /* See tag-20230504-1 */ |
| 156957 | 157042 | pExpr->u.zToken = "false"; |
| 156958 | 157043 | ExprSetProperty(pExpr, EP_IsFalse); |
| 156959 | 157044 | pTerm->prereqAll = 0; |
| 156960 | 157045 | pTerm->eOperator = 0; |
| 156961 | 157046 | } |
| | @@ -178633,11 +178718,11 @@ |
| 178633 | 178718 | if( pVfs==0 ) return 0; |
| 178634 | 178719 | |
| 178635 | 178720 | /* This function works in milliseconds, but the underlying OsSleep() |
| 178636 | 178721 | ** API uses microseconds. Hence the 1000's. |
| 178637 | 178722 | */ |
| 178638 | | - rc = (sqlite3OsSleep(pVfs, 1000*ms)/1000); |
| 178723 | + rc = (sqlite3OsSleep(pVfs, ms<0 ? 0 : 1000*ms)/1000); |
| 178639 | 178724 | return rc; |
| 178640 | 178725 | } |
| 178641 | 178726 | |
| 178642 | 178727 | /* |
| 178643 | 178728 | ** Enable or disable the extended result codes. |
| | @@ -200613,21 +200698,20 @@ |
| 200613 | 200698 | switch( (u8)z[i] ){ |
| 200614 | 200699 | case '{': { |
| 200615 | 200700 | /* Parse object */ |
| 200616 | 200701 | iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0); |
| 200617 | 200702 | if( iThis<0 ) return -1; |
| 200703 | + if( ++pParse->iDepth > JSON_MAX_DEPTH ){ |
| 200704 | + pParse->iErr = i; |
| 200705 | + return -1; |
| 200706 | + } |
| 200618 | 200707 | for(j=i+1;;j++){ |
| 200619 | | - if( ++pParse->iDepth > JSON_MAX_DEPTH ){ |
| 200620 | | - pParse->iErr = j; |
| 200621 | | - return -1; |
| 200622 | | - } |
| 200623 | 200708 | x = jsonParseValue(pParse, j); |
| 200624 | 200709 | if( x<=0 ){ |
| 200625 | 200710 | if( x==(-2) ){ |
| 200626 | 200711 | j = pParse->iErr; |
| 200627 | 200712 | if( pParse->nNode!=(u32)iThis+1 ) pParse->hasNonstd = 1; |
| 200628 | | - pParse->iDepth--; |
| 200629 | 200713 | break; |
| 200630 | 200714 | } |
| 200631 | 200715 | j += json5Whitespace(&z[j]); |
| 200632 | 200716 | if( sqlite3JsonId1(z[j]) |
| 200633 | 200717 | || (z[j]=='\\' && z[j+1]=='u' && jsonIs4Hex(&z[j+2])) |
| | @@ -200671,11 +200755,10 @@ |
| 200671 | 200755 | } |
| 200672 | 200756 | j = pParse->iErr+1; |
| 200673 | 200757 | } |
| 200674 | 200758 | parse_object_value: |
| 200675 | 200759 | x = jsonParseValue(pParse, j); |
| 200676 | | - pParse->iDepth--; |
| 200677 | 200760 | if( x<=0 ){ |
| 200678 | 200761 | if( x!=(-1) ) pParse->iErr = j; |
| 200679 | 200762 | return -1; |
| 200680 | 200763 | } |
| 200681 | 200764 | j = x; |
| | @@ -200704,24 +200787,24 @@ |
| 200704 | 200787 | } |
| 200705 | 200788 | pParse->iErr = j; |
| 200706 | 200789 | return -1; |
| 200707 | 200790 | } |
| 200708 | 200791 | pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1; |
| 200792 | + pParse->iDepth--; |
| 200709 | 200793 | return j+1; |
| 200710 | 200794 | } |
| 200711 | 200795 | case '[': { |
| 200712 | 200796 | /* Parse array */ |
| 200713 | 200797 | iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0); |
| 200714 | 200798 | if( iThis<0 ) return -1; |
| 200799 | + if( ++pParse->iDepth > JSON_MAX_DEPTH ){ |
| 200800 | + pParse->iErr = i; |
| 200801 | + return -1; |
| 200802 | + } |
| 200715 | 200803 | memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u)); |
| 200716 | 200804 | for(j=i+1;;j++){ |
| 200717 | | - if( ++pParse->iDepth > JSON_MAX_DEPTH ){ |
| 200718 | | - pParse->iErr = j; |
| 200719 | | - return -1; |
| 200720 | | - } |
| 200721 | 200805 | x = jsonParseValue(pParse, j); |
| 200722 | | - pParse->iDepth--; |
| 200723 | 200806 | if( x<=0 ){ |
| 200724 | 200807 | if( x==(-3) ){ |
| 200725 | 200808 | j = pParse->iErr; |
| 200726 | 200809 | if( pParse->nNode!=(u32)iThis+1 ) pParse->hasNonstd = 1; |
| 200727 | 200810 | break; |
| | @@ -200755,10 +200838,11 @@ |
| 200755 | 200838 | } |
| 200756 | 200839 | pParse->iErr = j; |
| 200757 | 200840 | return -1; |
| 200758 | 200841 | } |
| 200759 | 200842 | pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1; |
| 200843 | + pParse->iDepth--; |
| 200760 | 200844 | return j+1; |
| 200761 | 200845 | } |
| 200762 | 200846 | case '\'': { |
| 200763 | 200847 | u8 jnFlags; |
| 200764 | 200848 | char cDelim; |
| | @@ -200804,18 +200888,10 @@ |
| 200804 | 200888 | j++; |
| 200805 | 200889 | } |
| 200806 | 200890 | jsonParseAddNode(pParse, JSON_STRING | (jnFlags<<8), j+1-i, &z[i]); |
| 200807 | 200891 | return j+1; |
| 200808 | 200892 | } |
| 200809 | | - case 'n': { |
| 200810 | | - if( strncmp(z+i,"null",4)==0 && !sqlite3Isalnum(z[i+4]) ){ |
| 200811 | | - jsonParseAddNode(pParse, JSON_NULL, 0, 0); |
| 200812 | | - return i+4; |
| 200813 | | - } |
| 200814 | | - pParse->iErr = i; |
| 200815 | | - return -1; |
| 200816 | | - } |
| 200817 | 200893 | case 't': { |
| 200818 | 200894 | if( strncmp(z+i,"true",4)==0 && !sqlite3Isalnum(z[i+4]) ){ |
| 200819 | 200895 | jsonParseAddNode(pParse, JSON_TRUE, 0, 0); |
| 200820 | 200896 | return i+4; |
| 200821 | 200897 | } |
| | @@ -201012,10 +201088,17 @@ |
| 201012 | 201088 | goto json_parse_restart; |
| 201013 | 201089 | } |
| 201014 | 201090 | pParse->iErr = i; |
| 201015 | 201091 | return -1; |
| 201016 | 201092 | } |
| 201093 | + case 'n': { |
| 201094 | + if( strncmp(z+i,"null",4)==0 && !sqlite3Isalnum(z[i+4]) ){ |
| 201095 | + jsonParseAddNode(pParse, JSON_NULL, 0, 0); |
| 201096 | + return i+4; |
| 201097 | + } |
| 201098 | + /* fall-through into the default case that checks for NaN */ |
| 201099 | + } |
| 201017 | 201100 | default: { |
| 201018 | 201101 | u32 k; |
| 201019 | 201102 | int nn; |
| 201020 | 201103 | c = z[i]; |
| 201021 | 201104 | for(k=0; k<sizeof(aNanInfName)/sizeof(aNanInfName[0]); k++){ |
| | @@ -202089,10 +202172,11 @@ |
| 202089 | 202172 | int argc, |
| 202090 | 202173 | sqlite3_value **argv |
| 202091 | 202174 | ){ |
| 202092 | 202175 | JsonParse *p; /* The parse */ |
| 202093 | 202176 | UNUSED_PARAMETER(argc); |
| 202177 | + if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 202094 | 202178 | p = jsonParseCached(ctx, argv, 0); |
| 202095 | 202179 | if( p==0 || p->oom ){ |
| 202096 | 202180 | sqlite3_result_error_nomem(ctx); |
| 202097 | 202181 | sqlite3_free(p); |
| 202098 | 202182 | }else{ |
| | @@ -202134,10 +202218,11 @@ |
| 202134 | 202218 | int argc, |
| 202135 | 202219 | sqlite3_value **argv |
| 202136 | 202220 | ){ |
| 202137 | 202221 | JsonParse *p; /* The parse */ |
| 202138 | 202222 | UNUSED_PARAMETER(argc); |
| 202223 | + if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 202139 | 202224 | p = jsonParseCached(ctx, argv, 0); |
| 202140 | 202225 | if( p==0 || p->oom ){ |
| 202141 | 202226 | sqlite3_result_error_nomem(ctx); |
| 202142 | 202227 | sqlite3_free(p); |
| 202143 | 202228 | }else if( p->nErr==0 ){ |
| | @@ -218806,19 +218891,19 @@ |
| 218806 | 218891 | } |
| 218807 | 218892 | }else{ |
| 218808 | 218893 | int ii; |
| 218809 | 218894 | u8 *pCsr = pC->aRecord; |
| 218810 | 218895 | if( pTab->bRowid ){ |
| 218811 | | - nNew += 9; |
| 218896 | + nNew += 9 + 1; |
| 218812 | 218897 | pCsr += 9; |
| 218813 | 218898 | } |
| 218814 | | - for(ii=0; ii<(pTab->nCol-pTab->bRowid); ii++){ |
| 218899 | + for(ii=pTab->bRowid; ii<pTab->nCol; ii++){ |
| 218815 | 218900 | int bChanged = 1; |
| 218816 | 218901 | int nOld = 0; |
| 218817 | 218902 | int eType; |
| 218818 | 218903 | sqlite3_value *p = 0; |
| 218819 | | - pSession->hook.xNew(pSession->hook.pCtx, ii, &p); |
| 218904 | + pSession->hook.xNew(pSession->hook.pCtx, ii-pTab->bRowid, &p); |
| 218820 | 218905 | if( p==0 ){ |
| 218821 | 218906 | return SQLITE_NOMEM; |
| 218822 | 218907 | } |
| 218823 | 218908 | |
| 218824 | 218909 | eType = *pCsr++; |
| | @@ -219962,11 +220047,11 @@ |
| 219962 | 220047 | } |
| 219963 | 220048 | |
| 219964 | 220049 | /* If at least one field has been modified, this is not a no-op. */ |
| 219965 | 220050 | if( bChanged ) bNoop = 0; |
| 219966 | 220051 | |
| 219967 | | - /* Add a field to the old.* record. This is omitted if this modules is |
| 220052 | + /* Add a field to the old.* record. This is omitted if this module is |
| 219968 | 220053 | ** currently generating a patchset. */ |
| 219969 | 220054 | if( bPatchset==0 ){ |
| 219970 | 220055 | if( bChanged || abPK[i] ){ |
| 219971 | 220056 | sessionAppendBlob(pBuf, pCsr, nAdvance, &rc); |
| 219972 | 220057 | }else{ |
| | @@ -220404,11 +220489,11 @@ |
| 220404 | 220489 | ){ |
| 220405 | 220490 | int rc; |
| 220406 | 220491 | |
| 220407 | 220492 | if( pnChangeset==0 || ppChangeset==0 ) return SQLITE_MISUSE; |
| 220408 | 220493 | rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset, ppChangeset); |
| 220409 | | - assert( 1 || rc || pnChangeset==0 |
| 220494 | + assert( rc || pnChangeset==0 |
| 220410 | 220495 | || pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize |
| 220411 | 220496 | ); |
| 220412 | 220497 | return rc; |
| 220413 | 220498 | } |
| 220414 | 220499 | |
| | @@ -224719,11 +224804,11 @@ |
| 224719 | 224804 | static int sqlite3Fts5GetVarint32(const unsigned char *p, u32 *v); |
| 224720 | 224805 | static int sqlite3Fts5GetVarintLen(u32 iVal); |
| 224721 | 224806 | static u8 sqlite3Fts5GetVarint(const unsigned char*, u64*); |
| 224722 | 224807 | static int sqlite3Fts5PutVarint(unsigned char *p, u64 v); |
| 224723 | 224808 | |
| 224724 | | -#define fts5GetVarint32(a,b) sqlite3Fts5GetVarint32(a,(u32*)&b) |
| 224809 | +#define fts5GetVarint32(a,b) sqlite3Fts5GetVarint32(a,(u32*)&(b)) |
| 224725 | 224810 | #define fts5GetVarint sqlite3Fts5GetVarint |
| 224726 | 224811 | |
| 224727 | 224812 | #define fts5FastGetVarint32(a, iOff, nVal) { \ |
| 224728 | 224813 | nVal = (a)[iOff++]; \ |
| 224729 | 224814 | if( nVal & 0x80 ){ \ |
| | @@ -228211,10 +228296,11 @@ |
| 228211 | 228296 | if( rc==SQLITE_OK && sqlite3_stricmp(pRet->zName, FTS5_RANK_NAME)==0 ){ |
| 228212 | 228297 | *pzErr = sqlite3_mprintf("reserved fts5 table name: %s", pRet->zName); |
| 228213 | 228298 | rc = SQLITE_ERROR; |
| 228214 | 228299 | } |
| 228215 | 228300 | |
| 228301 | + assert( (pRet->abUnindexed && pRet->azCol) || rc!=SQLITE_OK ); |
| 228216 | 228302 | for(i=3; rc==SQLITE_OK && i<nArg; i++){ |
| 228217 | 228303 | const char *zOrig = azArg[i]; |
| 228218 | 228304 | const char *z; |
| 228219 | 228305 | char *zOne = 0; |
| 228220 | 228306 | char *zTwo = 0; |
| | @@ -233245,10 +233331,11 @@ |
| 233245 | 233331 | Fts5StructureSegment *pSeg = &pLvl->aSeg[iSeg]; |
| 233246 | 233332 | if( i>=nData ){ |
| 233247 | 233333 | rc = FTS5_CORRUPT; |
| 233248 | 233334 | break; |
| 233249 | 233335 | } |
| 233336 | + assert( pSeg!=0 ); |
| 233250 | 233337 | i += fts5GetVarint32(&pData[i], pSeg->iSegid); |
| 233251 | 233338 | i += fts5GetVarint32(&pData[i], pSeg->pgnoFirst); |
| 233252 | 233339 | i += fts5GetVarint32(&pData[i], pSeg->pgnoLast); |
| 233253 | 233340 | if( pSeg->pgnoLast<pSeg->pgnoFirst ){ |
| 233254 | 233341 | rc = FTS5_CORRUPT; |
| | @@ -242386,11 +242473,11 @@ |
| 242386 | 242473 | int nArg, /* Number of args */ |
| 242387 | 242474 | sqlite3_value **apUnused /* Function arguments */ |
| 242388 | 242475 | ){ |
| 242389 | 242476 | assert( nArg==0 ); |
| 242390 | 242477 | UNUSED_PARAM2(nArg, apUnused); |
| 242391 | | - sqlite3_result_text(pCtx, "fts5: 2023-05-01 20:09:52 62d703d83cf8cf3358715792347c49315a82c659e475158e385746f4329a4f39", -1, SQLITE_TRANSIENT); |
| 242478 | + sqlite3_result_text(pCtx, "fts5: 2023-05-05 14:16:31 fece588b186c4f9f76d626313e35336fd5681e966e9bd0fa1053b147c4e3c315", -1, SQLITE_TRANSIENT); |
| 242392 | 242479 | } |
| 242393 | 242480 | |
| 242394 | 242481 | /* |
| 242395 | 242482 | ** Return true if zName is the extension on one of the shadow tables used |
| 242396 | 242483 | ** by this module. |
| 242397 | 242484 | |