Fossil SCM

Update the built-in SQLite to the latest trunk version, which includes the 3.54.1 fixes plus other enhancements.

drh 2026-10-16 17:06 UTC trunk
Commit 564007c6035bec87abfd5f0fdc4af2c9078405c3cf7ba4dde4b93cb2dcecad95
3 files changed +317 -83 +631 -293 +5 -5
+317 -83
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -14,10 +14,11 @@
1414
** ext/misc/decimal.c
1515
** ext/misc/diskused.c
1616
** ext/misc/fileio.c
1717
** ext/misc/ieee754.c
1818
** ext/misc/memtrace.c
19
+** ext/misc/optname.c
1920
** ext/misc/pcachetrace.c
2021
** ext/misc/regexp.c
2122
** ext/misc/series.c
2223
** ext/misc/sha1.c
2324
** ext/misc/shathree.c
@@ -6719,10 +6720,35 @@
67196720
pX = decimalPow2(e);
67206721
decimalMul(pA, pX);
67216722
decimal_free(pX);
67226723
return pA;
67236724
}
6725
+
6726
+/*
6727
+** Extract a 32-bit signed integer from argument pVal and write the
6728
+** results into *pResult. Return 0 on success and 1 if the value is
6729
+** too larger to fit in 32-bits.
6730
+*/
6731
+static int decimalSafeInt(
6732
+ sqlite3_context *context,
6733
+ sqlite3_value *pVal,
6734
+ int *pResult
6735
+){
6736
+ sqlite3_int64 i64 = sqlite3_value_int64(pVal);
6737
+ if( i64<-2147483648LL || i64>2147483647LL ){
6738
+ char *zMsg = sqlite3_mprintf(
6739
+ "value %lld is too large: range limit -2147483648..+2147483647",
6740
+ i64);
6741
+ sqlite3_result_error(context, zMsg, -1);
6742
+ sqlite3_free(zMsg);
6743
+ *pResult = 0;
6744
+ return 1;
6745
+ }else{
6746
+ *pResult = (int)i64;
6747
+ return 0;
6748
+ }
6749
+}
67246750
67256751
/*
67266752
** SQL Function: decimal(X)
67276753
** OR: decimal_exp(X)
67286754
**
@@ -6741,12 +6767,16 @@
67416767
sqlite3_value **argv
67426768
){
67436769
Decimal *p = decimal_new(context, argv[0], 0);
67446770
int N;
67456771
if( argc==2 ){
6746
- N = sqlite3_value_int(argv[1]);
6747
- if( N>0 ) decimal_round(p, N);
6772
+ if( decimalSafeInt(context, argv[1], &N) ){
6773
+ decimal_free(p);
6774
+ p = 0;
6775
+ }else if( N>0 ){
6776
+ decimal_round(p, N);
6777
+ }
67486778
}else{
67496779
N = 0;
67506780
}
67516781
if( p ){
67526782
if( sqlite3_user_data(context)!=0 ){
@@ -6917,13 +6947,17 @@
69176947
int argc,
69186948
sqlite3_value **argv
69196949
){
69206950
UNUSED_PARAMETER(argc);
69216951
if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){
6922
- Decimal *pA = decimalPow2(sqlite3_value_int(argv[0]));
6923
- decimal_result_sci(context, pA, 0);
6924
- decimal_free(pA);
6952
+ int N;
6953
+ if( decimalSafeInt(context, argv[0], &N) ) return;
6954
+ Decimal *pA = decimalPow2(N);
6955
+ if( pA ){
6956
+ decimal_result_sci(context, pA, 0);
6957
+ decimal_free(pA);
6958
+ }
69256959
}
69266960
}
69276961
69286962
#ifdef _WIN32
69296963
@@ -7729,10 +7763,125 @@
77297763
}
77307764
77317765
#endif
77327766
77337767
/************************* End ext/misc/base85.c ********************/
7768
+/************************* Begin ext/misc/optname.c ******************/
7769
+/*
7770
+** 2026-10-10
7771
+**
7772
+** The author disclaims copyright to this source code. In place of
7773
+** a legal notice, here is a blessing:
7774
+**
7775
+** May you do good and not evil.
7776
+** May you find forgiveness for yourself and forgive others.
7777
+** May you share freely, never taking more than you give.
7778
+**
7779
+*************************************************************************
7780
+**
7781
+** The sqlite3_test_control() interface with SQLITE_TESTCTRL_OPTIMIZATIONS
7782
+** and SQLITE_TESTCTRL_GETOPT are used to enable and/or disable various
7783
+** optimizations within SQLite. Optimizations are identified by a bitmask.
7784
+** This file contains external code that will map symbolic names into
7785
+** bitmask values, and bitmask values into symbolic names.
7786
+**
7787
+** This code is not part of the SQLite core because we don't want to use
7788
+** code space to store all the symbolic names.
7789
+*/
7790
+/* #include "sqlite3.h" */
7791
+
7792
+/*
7793
+** Convert an optimization number (as recorded in sqliteInt.h) into
7794
+** a mask for that optimization.
7795
+*/
7796
+#define OPT_MASK(N) ((1ull)<<((N)-1))
7797
+
7798
+
7799
+/*
7800
+** This is the mapping between bits and names.
7801
+**
7802
+** Some bit values have multiple names. The preferred name always
7803
+** comes first.
7804
+*/
7805
+static const struct OptName {
7806
+ sqlite3_uint64 uMask;
7807
+ const char *zName;
7808
+} aOpt[] = {
7809
+ { OPT_MASK(1), "QueryFlattener" },
7810
+ { OPT_MASK(1), "Flatten" }, /* Alias for prior */
7811
+ { OPT_MASK(2), "WindowFunc" },
7812
+ { OPT_MASK(3), "GroupByOrder" },
7813
+ { OPT_MASK(4), "JoinMiss" },
7814
+ { OPT_MASK(5), "DistinctOpt" },
7815
+ { OPT_MASK(6), "CoverIdxScan" },
7816
+ { OPT_MASK(7), "OrderByIdxJoin" },
7817
+ { OPT_MASK(8), "Transitive" },
7818
+ { OPT_MASK(9), "OmitNoopJoin" },
7819
+ { OPT_MASK(10), "CountOfView" },
7820
+ { OPT_MASK(11), "CursorHints" },
7821
+ { OPT_MASK(12), "Stat4" },
7822
+ { OPT_MASK(13), "PushDown" },
7823
+ { OPT_MASK(14), "SimplifyJoin" },
7824
+ { OPT_MASK(15), "SkipScan" },
7825
+ { OPT_MASK(16), "PropagateConst" },
7826
+ { OPT_MASK(17), "MinMaxOpt" },
7827
+ { OPT_MASK(18), "SeekScan" },
7828
+ { OPT_MASK(19), "OmitOrderBy" },
7829
+ { OPT_MASK(20), "BloomFilter" },
7830
+ /* 21 currently unused */
7831
+ { OPT_MASK(22), "BalancedMerge" },
7832
+ { OPT_MASK(23), "ReleaseReg" },
7833
+ { OPT_MASK(24), "FlttnUnionAll" },
7834
+ { OPT_MASK(25), "IndexedExpr" },
7835
+ { OPT_MASK(26), "Coroutines" },
7836
+ { OPT_MASK(27), "NullUnusedCols" },
7837
+ { OPT_MASK(28), "OnePass" },
7838
+ { OPT_MASK(29), "OrderBySubq" },
7839
+ { OPT_MASK(29), "OrderBySubquery" }, /* Alias for prior */
7840
+ { OPT_MASK(30), "StarQuery" },
7841
+ { OPT_MASK(31), "ExistsToJoin" },
7842
+ { OPT_MASK(32), "UnionLimit" },
7843
+ /* Special names */
7844
+ { 0xffffffffffffffffULL, "All" },
7845
+ { 0x0000000000000000ULL, "None" },
7846
+};
7847
+
7848
+/*
7849
+** Given a symbolic name, try to compute the corresponding mask.
7850
+**
7851
+** The return value is:
7852
+**
7853
+** SQLITE_OK Successful match
7854
+** SQLITE_NOTFOUND No match
7855
+** SQLITE_MISUSE Bad arguments
7856
+*/
7857
+int sqlite3_optimization_mask(const char *zName, sqlite3_uint64 *pMask){
7858
+ unsigned int i;
7859
+ if( zName==0 || pMask==0 ){ return SQLITE_MISUSE; }
7860
+ for(i=0; i<sizeof(aOpt)/sizeof(aOpt[0]); i++){
7861
+ if( sqlite3_stricmp(zName, aOpt[i].zName)==0 ){
7862
+ *pMask = aOpt[i].uMask;
7863
+ return SQLITE_OK;
7864
+ }
7865
+ }
7866
+ *pMask = 0;
7867
+ return SQLITE_NOTFOUND;
7868
+}
7869
+
7870
+/*
7871
+** Given a bitmap, return the canonical symbolic name. Return 0 for
7872
+** a bitmap input of 0 or a bitmap value that matches nothing.
7873
+*/
7874
+const char *sqlite3_optimization_name(sqlite3_uint64 mask){
7875
+ unsigned int i;
7876
+ for(i=0; i<sizeof(aOpt)/sizeof(aOpt[0]); i++){
7877
+ if( aOpt[i].uMask==mask ){ return aOpt[i].zName; }
7878
+ }
7879
+ return 0;
7880
+}
7881
+
7882
+/************************* End ext/misc/optname.c ********************/
77347883
/************************* Begin ext/misc/ieee754.c ******************/
77357884
/*
77367885
** 2013-04-17
77377886
**
77387887
** The author disclaims copyright to this source code. In place of
@@ -25076,10 +25225,11 @@
2507625225
unsigned mEqpLines; /* Mask of vertical lines in the EQP output graph */
2507725226
u8 nPopOutput; /* Revert .output settings when reaching zero */
2507825227
u8 nPopMode; /* Revert .mode settings when reaching zero */
2507925228
u8 enableTimer; /* Enable the timer. 2: permanently 1: only once */
2508025229
u8 bDelimitNonprint; /* Add \001...\002 around non-printing in prompts */
25230
+ u8 bTestParse; /* Undocumented --test-parse flags */
2508125231
int inputNesting; /* Track nesting level of .read and other redirects */
2508225232
double prevTimer; /* Last reported timer value */
2508325233
double tmProgress; /* --timeout option for .progress */
2508425234
i64 lineno; /* Line number of last line read from in */
2508525235
const char *zInFile; /* Name of the input file */
@@ -25187,11 +25337,11 @@
2518725337
2518825338
/* Names of values for Mode.spec.eEsc and Mode.spec.eText
2518925339
*/
2519025340
static const char *qrfEscNames[] = { "auto", "off", "ascii", "symbol" };
2519125341
static const char *qrfQuoteNames[] =
25192
- { "off","off","sql","hex","csv","tcl","json","relaxed"};
25342
+ { "off","off","sql","csv","html","tcl","json","relaxed"};
2519325343
2519425344
/*
2519525345
** These are the allowed shellFlgs values
2519625346
*/
2519725347
#define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */
@@ -25276,11 +25426,11 @@
2527625426
{ "ascii", 7, 6, 9, 1, 1, 0, 1, 12, 0, 0 },
2527725427
{ "box", 0, 0, 9, 1, 1, 0, 3, 1, 2, 0 },
2527825428
{ "c", 4, 1, 10, 5, 5, 4, 1, 12, 0, 0 },
2527925429
{ "column", 0, 0, 9, 1, 1, 0, 3, 2, 2, 0 },
2528025430
{ "count", 0, 0, 0, 0, 0, 0, 0, 3, 0, 0 },
25281
- { "csv", 4, 5, 9, 3, 3, 0, 1, 4, 0, 0 },
25431
+ { "csv", 4, 5, 9, 3, 3, 0, 1, 12, 0, 0 },
2528225432
{ "html", 0, 0, 9, 4, 4, 0, 3, 7, 0, 0 },
2528325433
{ "insert", 0, 0, 10, 2, 2, 0, 1, 8, 0, 0 },
2528425434
{ "jatom", 4, 1, 11, 6, 6, 0, 1, 12, 0, 0 },
2528525435
{ "jobject", 0, 1, 11, 6, 6, 0, 0, 10, 0, 0 },
2528625436
{ "json", 0, 0, 11, 6, 6, 0, 0, 9, 0, 0 },
@@ -26495,14 +26645,20 @@
2649526645
sqlite3_context *pCtx,
2649626646
int nVal,
2649726647
sqlite3_value **apVal
2649826648
){
2649926649
double r = sqlite3_value_double(apVal[0]);
26500
- int n = nVal>=2 ? sqlite3_value_int(apVal[1]) : 26;
26650
+ i64 nn = nVal>=2 ? sqlite3_value_int64(apVal[1]) : 26;
26651
+ int n;
2650126652
char z[400];
26502
- if( n<1 ) n = 1;
26503
- if( n>350 ) n = 350;
26653
+ if( nn<1 ){
26654
+ n = 1;
26655
+ }else if( nn>350 ){
26656
+ n = 350;
26657
+ }else{
26658
+ n = (int)nn;
26659
+ }
2650426660
z[sizeof(z)-1] = 0;
2650526661
snprintf(z, sizeof(z)-1, "%#+.*e", n, r);
2650626662
sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT);
2650726663
}
2650826664
@@ -30111,11 +30267,13 @@
3011130267
sqlite3_ieee_init(p->db, 0, 0);
3011230268
sqlite3_series_init(p->db, 0, 0);
3011330269
sqlite3_diskused_init(p->db, 0, 0);
3011430270
sqlite3_strdup_init(p->db, 0, 0);
3011530271
#ifndef SQLITE_SHELL_FIDDLE
30116
- sqlite3_fileio_init(p->db, 0, 0);
30272
+ if( !p->bSafeMode ){
30273
+ sqlite3_fileio_init(p->db, 0, 0);
30274
+ }
3011730275
sqlite3_completion_init(p->db, 0, 0);
3011830276
#endif
3011930277
#ifdef SQLITE_HAVE_ZLIB
3012030278
if( !p->bSafeModePersist ){
3012130279
sqlite3_zipfile_init(p->db, 0, 0);
@@ -33259,13 +33417,21 @@
3325933417
dotCmdError(p, i, "unknown argument", 0);
3326033418
return 1;
3326133419
}
3326233420
}else if( cli_strcmp(z,"-v")==0 ){
3326333421
eVerbose++;
33264
- }else if( cli_strcmp(z,"-schema")==0 && i<nArg-1 ){
33422
+ }else if( cli_strcmp(z,"-schema")==0 ){
33423
+ if( i==nArg-1 ){
33424
+ dotCmdError(p, i, "missing argument", 0);
33425
+ return 1;
33426
+ }
3326533427
zSchema = azArg[++i];
33266
- }else if( cli_strcmp(z,"-skip")==0 && i<nArg-1 ){
33428
+ }else if( cli_strcmp(z,"-skip")==0 ){
33429
+ if( i==nArg-1 ){
33430
+ dotCmdError(p, i, "missing argument", 0);
33431
+ return 1;
33432
+ }
3326733433
nSkip = integerValue(azArg[++i]);
3326833434
}else if( cli_strcmp(z,"-ascii")==0 ){
3326933435
if( sCtx.cColSep==0 ) sCtx.cColSep = '\037';
3327033436
if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\036';
3327133437
xRead = ascii_read_one_field;
@@ -33272,12 +33438,20 @@
3327233438
}else if( cli_strcmp(z,"-csv")==0 ){
3327333439
if( sCtx.cColSep==0 ) sCtx.cColSep = ',';
3327433440
if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\n';
3327533441
xRead = csv_read_one_field;
3327633442
}else if( cli_strcmp(z,"-esc")==0 ){
33443
+ if( i==nArg-1 ){
33444
+ dotCmdError(p, i, "missing argument", 0);
33445
+ return 1;
33446
+ }
3327733447
sCtx.cUQEscape = azArg[++i][0];
3327833448
}else if( cli_strcmp(z,"-qesc")==0 ){
33449
+ if( i==nArg-1 ){
33450
+ dotCmdError(p, i, "missing argument", 0);
33451
+ return 1;
33452
+ }
3327933453
sCtx.cQEscape = azArg[++i][0];
3328033454
}else if( cli_strcmp(z,"-colsep")==0 ){
3328133455
if( i==nArg-1 ){
3328233456
dotCmdError(p, i, "missing argument", 0);
3328333457
return 1;
@@ -34251,11 +34425,12 @@
3425134425
append_c_string(pDesc, p->mode.spec.zNull);
3425234426
}
3425334427
if( bAll
3425434428
|| (pI->eText!=p->mode.spec.eText && (pI->eText>1 || p->mode.spec.eText>1))
3425534429
){
34256
- sqlite3_str_appendf(pDesc," --quote %s",qrfQuoteNames[p->mode.spec.eText]);
34430
+ sqlite3_str_appendf(pDesc," --quote %s",
34431
+ qrfQuoteNames[p->mode.spec.eText]);
3425734432
}
3425834433
if( bAll
3425934434
|| ((p->mode.spec.bRowCount==QRF_Yes) != ((pI->mFlg&4)!=0))
3426034435
){
3426134436
sqlite3_str_appendf(pDesc," --rowcount %s",
@@ -37581,53 +37756,18 @@
3758137756
** -LABEL Disable the named optimization
3758237757
**
3758337758
** INTEGER Mask of optimizations to disable
3758437759
*/
3758537760
case SQLITE_TESTCTRL_OPTIMIZATIONS: {
37586
- static const struct {
37587
- unsigned int mask; /* Mask for this optimization */
37588
- unsigned int bDsply; /* Display this on output */
37589
- const char *zLabel; /* Name of optimization */
37590
- } aLabel[] = {
37591
- { 0x00000001, 1, "QueryFlattener" },
37592
- { 0x00000001, 0, "Flatten" },
37593
- { 0x00000002, 1, "WindowFunc" },
37594
- { 0x00000004, 1, "GroupByOrder" },
37595
- { 0x00000010, 1, "DistinctOpt" },
37596
- { 0x00000020, 1, "CoverIdxScan" },
37597
- { 0x00000040, 1, "OrderByIdxJoin" },
37598
- { 0x00000080, 1, "Transitive" },
37599
- { 0x00000100, 1, "OmitNoopJoin" },
37600
- { 0x00000200, 1, "CountOfView" },
37601
- { 0x00000400, 1, "CursorHints" },
37602
- { 0x00000800, 1, "Stat4" },
37603
- { 0x00001000, 1, "PushDown" },
37604
- { 0x00002000, 1, "SimplifyJoin" },
37605
- { 0x00004000, 1, "SkipScan" },
37606
- { 0x00008000, 1, "PropagateConst" },
37607
- { 0x00010000, 1, "MinMaxOpt" },
37608
- { 0x00020000, 1, "SeekScan" },
37609
- { 0x00040000, 1, "OmitOrderBy" },
37610
- { 0x00080000, 1, "BloomFilter" },
37611
- { 0x00200000, 1, "BalancedMerge" },
37612
- { 0x00400000, 1, "ReleaseReg" },
37613
- { 0x00800000, 1, "FlttnUnionAll" },
37614
- { 0x01000000, 1, "IndexedEXpr" },
37615
- { 0x02000000, 1, "Coroutines" },
37616
- { 0x04000000, 1, "NullUnusedCols" },
37617
- { 0x08000000, 1, "OnePass" },
37618
- { 0x10000000, 1, "OrderBySubq" },
37619
- { 0x20000000, 1, "StarQuery" },
37620
- { 0x40000000, 1, "ExistsToJoin" },
37621
- { 0x80000000, 1, "UnionLimit" },
37622
- { 0xffffffff, 0, "All" },
37623
- };
37624
- unsigned int curOpt;
37625
- unsigned int newOpt;
37626
- unsigned int m;
37627
- int ii;
37628
- int nOff;
37761
+ unsigned int curOpt; /* Current opt-disabled mask */
37762
+ unsigned int newOpt; /* New opt-disabled mask */
37763
+ unsigned int m; /* A working mask value */
37764
+ sqlite3_uint64 mm; /* 64-bit working mask value */
37765
+ int ii, jj; /* Loop counters */
37766
+ int nOff; /* Number of disabled optimizations */
37767
+ const char *zName; /* Name of an optimization */
37768
+
3762937769
sqlite3_test_control(SQLITE_TESTCTRL_GETOPT, p->db, &curOpt);
3763037770
newOpt = curOpt;
3763137771
for(ii=2; ii<nArg; ii++){
3763237772
const char *z = azArg[ii];
3763337773
int useLabel = 0;
@@ -37640,29 +37780,27 @@
3764037780
zLabel = z;
3764137781
}else{
3764237782
newOpt = (unsigned int)strtol(z,0,0);
3764337783
}
3764437784
if( useLabel ){
37645
- int jj;
37646
- for(jj=0; jj<ArraySize(aLabel); jj++){
37647
- if( sqlite3_stricmp(zLabel, aLabel[jj].zLabel)==0 ) break;
37648
- }
37649
- if( jj>=ArraySize(aLabel) ){
37785
+ if( sqlite3_optimization_mask(zLabel,&mm)==SQLITE_NOTFOUND ){
3765037786
cli_printf(stderr,
3765137787
"Error: no such optimization: \"%s\"\n", zLabel);
37652
- cli_puts("Should be one of:", stderr);
37653
- for(jj=0; jj<ArraySize(aLabel); jj++){
37654
- cli_printf(stderr," %s", aLabel[jj].zLabel);
37788
+ cli_puts("Should be one of: All", stderr);
37789
+ for(jj=0; jj<32; jj++){
37790
+ zName = sqlite3_optimization_name(1ull<<jj);
37791
+ if( zName ) cli_printf(stderr," %s", zName);
3765537792
}
3765637793
cli_puts("\n", stderr);
3765737794
rc = 1;
3765837795
goto meta_command_exit;
3765937796
}
37797
+ m = (u32)mm;
3766037798
if( useLabel=='+' ){
37661
- newOpt &= ~aLabel[jj].mask;
37799
+ newOpt &= ~m;
3766237800
}else{
37663
- newOpt |= aLabel[jj].mask;
37801
+ newOpt |= m;
3766437802
}
3766537803
}
3766637804
}
3766737805
if( curOpt!=newOpt ){
3766837806
sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,p->db,newOpt);
@@ -37670,22 +37808,24 @@
3767037808
for(ii=nOff=0, m=1; ii<32; ii++, m <<= 1){
3767137809
if( m & newOpt ) nOff++;
3767237810
}
3767337811
if( nOff<12 ){
3767437812
cli_puts("+All", p->out);
37675
- for(ii=0; ii<ArraySize(aLabel); ii++){
37676
- if( !aLabel[ii].bDsply ) continue;
37677
- if( (newOpt & aLabel[ii].mask)!=0 ){
37678
- cli_printf(p->out, " -%s", aLabel[ii].zLabel);
37813
+ for(ii=0, m=1; ii<32; ii++, m <<= 1){
37814
+ if( (newOpt & m)!=0
37815
+ && (zName = sqlite3_optimization_name(m))!=0
37816
+ ){
37817
+ cli_printf(p->out, " -%s", zName);
3767937818
}
3768037819
}
3768137820
}else{
3768237821
cli_puts("-All", p->out);
37683
- for(ii=0; ii<ArraySize(aLabel); ii++){
37684
- if( !aLabel[ii].bDsply ) continue;
37685
- if( (newOpt & aLabel[ii].mask)==0 ){
37686
- cli_printf(p->out, " +%s", aLabel[ii].zLabel);
37822
+ for(ii=0, m=1; ii<32; ii++, m <<= 1){
37823
+ if( (newOpt & m)==0
37824
+ && (zName = sqlite3_optimization_name(m))!=0
37825
+ ){
37826
+ cli_printf(p->out, " +%s", zName);
3768737827
}
3768837828
}
3768937829
}
3769037830
cli_puts("\n", p->out);
3769137831
rc2 = isOk = 3;
@@ -38313,10 +38453,67 @@
3831338453
}
3831438454
}
3831538455
3831638456
return rc;
3831738457
}
38458
+
38459
+/*
38460
+** When the (undocumented) command-line option --test-parse is used,
38461
+** this routine is run instead of runOneSqlLine() to process SQL. Don't
38462
+** actually run any SQL. Instead just provide a one-line summary of the
38463
+** SQL that would have run.
38464
+*/
38465
+static void runTestParse(
38466
+ ShellState *p, /* Execution context */
38467
+ char *zSql /* SQL to be run */
38468
+){
38469
+ int nNL = 0;
38470
+ char *zNL;
38471
+ size_t i, j, n;
38472
+ int nPre = 0;
38473
+ int nSuf = 0;
38474
+ int mxPre = 20;
38475
+ char zPre[50], zSuf[50];
38476
+
38477
+ for(zNL=strchr(zSql,'\n'); zNL!=0; zNL=strchr(zNL+1,'\n')){ nNL++; }
38478
+ n = strlen(zSql);
38479
+ if( n<40 ) mxPre = 40;
38480
+ for(i=0; nPre<mxPre && i<n; i++){
38481
+ char c = zSql[i];
38482
+ if( c=='\n' ){
38483
+ zPre[nPre++] = '\\';
38484
+ zPre[nPre++] = 'n';
38485
+ }else if( c>0 && c<' ' ){
38486
+ zPre[nPre++] = '^';
38487
+ zPre[nPre++] = c+0x40;
38488
+ }else{
38489
+ zPre[nPre++] = c;
38490
+ }
38491
+ }
38492
+ zPre[nPre] = 0;
38493
+ j = n - 20;
38494
+ if( j<i ){
38495
+ j = i;
38496
+ }else{
38497
+ memcpy(zSuf," ... ", 5);
38498
+ nSuf = 5;
38499
+ }
38500
+ for(i=j; i<n; i++){
38501
+ char c = zSql[i];
38502
+ if( c=='\n' ){
38503
+ zSuf[nSuf++] = '\\';
38504
+ zSuf[nSuf++] = 'n';
38505
+ }else if( c>0 && c<' ' ){
38506
+ zSuf[nSuf++] = '^';
38507
+ zSuf[nSuf++] = c+0x40;
38508
+ }else{
38509
+ zSuf[nSuf++] = c;
38510
+ }
38511
+ }
38512
+ zSuf[nSuf] = 0;
38513
+ cli_printf(p->out, "%d line%s: %s%s\n", nNL+1, (nNL?"s":""), zPre, zSuf);
38514
+}
3831838515
3831938516
/*
3832038517
** Run a single line of SQL. Return the number of errors.
3832138518
*/
3832238519
static int runOneSqlLine(
@@ -38329,13 +38526,18 @@
3832938526
char *zErrMsg = 0;
3833038527
3833138528
open_db(p, 0);
3833238529
if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql);
3833338530
if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
38334
- BEGIN_TIMER(p);
38335
- rc = shell_exec(p, zSql, &zErrMsg);
38336
- END_TIMER(p);
38531
+ if( p->bTestParse ){
38532
+ runTestParse(p, zSql);
38533
+ rc = SQLITE_OK;
38534
+ }else{
38535
+ BEGIN_TIMER(p);
38536
+ rc = shell_exec(p, zSql, &zErrMsg);
38537
+ END_TIMER(p);
38538
+ }
3833738539
if( rc || zErrMsg ){
3833838540
sqlite3_str *pPrefix = sqlite3_str_new(p->db);
3833938541
const char *zErrorTail;
3834038542
const char *zErrorType;
3834138543
if( zErrMsg==0 ){
@@ -38426,10 +38628,31 @@
3842638628
memcpy(zLine, zBegin, nZ);
3842738629
zLine[nZ] = 0;
3842838630
return zLine;
3842938631
}
3843038632
#endif /* SQLITE_SHELL_FIDDLE */
38633
+
38634
+/*
38635
+** Return true if the input would is complete SQL, or complete SQL
38636
+** followed by only whitespace. This is similar to sqlite3_complete()
38637
+** except that if the final semicolon is followed by whitespace, it
38638
+** still returns true.
38639
+*/
38640
+static int line_is_complete(char *zSql, int nSql){
38641
+ sqlite3_int64 x;
38642
+ assert( nSql>=0 && zSql[nSql]==0 );
38643
+ x = sqlite3_incomplete(zSql);
38644
+ if( x==0x00 || x==0x10 ) return 1;
38645
+ if( x==0x2d0001 ){
38646
+ zSql[nSql] = '\n';
38647
+ zSql[nSql+1] = 0;
38648
+ x = sqlite3_incomplete(zSql);
38649
+ zSql[nSql] = 0;
38650
+ if( x==0x00 || x==0x10 ) return 1;
38651
+ }
38652
+ return 0;
38653
+}
3843138654
3843238655
/*
3843338656
** Read input from *in and process it. If *in==0 then input
3843438657
** is interactive - the user is typing it it. Otherwise, input
3843538658
** is coming from a file or device. A prompt is issued and history
@@ -38495,13 +38718,13 @@
3849538718
#ifdef SQLITE_SHELL_LEGACY_COMMAND_TERMINATOR
3849638719
if( line_is_command_terminator(zLine, zSql, nSql) ){
3849738720
memcpy(zLine,";",2);
3849838721
}
3849938722
#endif
38500
- hasSemi = strchr(zLine,';')!=0;
38723
+ if( strchr(zLine,';')!=0 ) hasSemi = 1;
3850138724
nLine = strlen(zLine);
38502
- if( nSql+nLine+2>=nAlloc ){
38725
+ if( nSql+nLine+4>=nAlloc ){
3850338726
/* Grow buffer by half-again increments when big. */
3850438727
nAlloc = nSql+(nSql>>1)+nLine+100;
3850538728
zSql = realloc(zSql, nAlloc);
3850638729
shell_check_oom(zSql);
3850738730
}
@@ -38524,11 +38747,11 @@
3852438747
zSrc, startline, zSize);
3852538748
nSql = 0;
3852638749
errCnt++;
3852738750
break;
3852838751
}
38529
- if( nSql && hasSemi && sqlite3_complete(zSql) ){
38752
+ if( nSql && hasSemi && line_is_complete(zSql, nSql) ){
3853038753
echo_group_input(p, zSql);
3853138754
errCnt += runOneSqlLine(p, zSql, p->zInFile, startline);
3853238755
nSql = 0;
3853338756
if( p->nPopOutput ){
3853438757
output_reset(p);
@@ -39258,11 +39481,12 @@
3925839481
}else if( cli_strcmp(z,"-bail")==0 ){
3925939482
bail_on_error = 1;
3926039483
}else if( cli_strcmp(z,"-nonce")==0 ){
3926139484
free(data.zNonce);
3926239485
data.zNonce = strdup(cmdline_option_value(argc, argv, ++i));
39263
- }else if( cli_strcmp(z,"-unsafe-testing")==0 ){
39486
+ }else if( cli_strcmp(z,"-unsafe-testing")==0
39487
+ || cli_strcmp(z,"-unsafe")==0 ){
3926439488
ShellSetFlag(&data,SHFLG_TestingMode);
3926539489
}else if( cli_strcmp(z,"-safe")==0 ){
3926639490
/* no-op - catch this on the second pass */
3926739491
}else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){
3926839492
/* skip over the argument */
@@ -39277,10 +39501,17 @@
3927739501
int kk;
3927839502
for(kk=0; kk<argc; kk++){
3927939503
sqlite3_fprintf(stdout,"argv[%d] = \"%s\"\n", kk, argv[kk]);
3928039504
}
3928139505
return 0;
39506
+ }else if( cli_strcmp(z,"-test-parse")==0 ){
39507
+ /* Undocumented test option. Read input normally and process all
39508
+ ** dot-commands. But do not process any SQL. Instead, whenever input
39509
+ ** text would have been processed as SQL, print a one-line summary of
39510
+ ** the input. This is used by test script to verify that the end-of-SQL
39511
+ ** parsing logic is working correctly. */
39512
+ data.bTestParse = 1;
3928239513
}
3928339514
}
3928439515
#ifndef SQLITE_SHELL_FIDDLE
3928539516
if( !bEnableVfstrace ) verify_uninitialized();
3928639517
#endif
@@ -39573,11 +39804,14 @@
3957339804
stdin_is_interactive = 0;
3957439805
break;
3957539806
#endif
3957639807
}else if( cli_strcmp(z,"-safe")==0 ){
3957739808
data.bSafeMode = data.bSafeModePersist = 1;
39578
- }else if( cli_strcmp(z,"-unsafe-testing")==0 ){
39809
+ }else if( cli_strcmp(z,"-unsafe-testing")==0
39810
+ || cli_strcmp(z,"-unsafe")==0 ){
39811
+ /* Acted upon in first pass. */
39812
+ }else if( cli_strcmp(z,"-test-parse")==0 ){
3957939813
/* Acted upon in first pass. */
3958039814
}else{
3958139815
cli_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
3958239816
eputz("Use -help for a list of options.\n");
3958339817
rc = 1;
3958439818
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -14,10 +14,11 @@
14 ** ext/misc/decimal.c
15 ** ext/misc/diskused.c
16 ** ext/misc/fileio.c
17 ** ext/misc/ieee754.c
18 ** ext/misc/memtrace.c
 
19 ** ext/misc/pcachetrace.c
20 ** ext/misc/regexp.c
21 ** ext/misc/series.c
22 ** ext/misc/sha1.c
23 ** ext/misc/shathree.c
@@ -6719,10 +6720,35 @@
6719 pX = decimalPow2(e);
6720 decimalMul(pA, pX);
6721 decimal_free(pX);
6722 return pA;
6723 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6724
6725 /*
6726 ** SQL Function: decimal(X)
6727 ** OR: decimal_exp(X)
6728 **
@@ -6741,12 +6767,16 @@
6741 sqlite3_value **argv
6742 ){
6743 Decimal *p = decimal_new(context, argv[0], 0);
6744 int N;
6745 if( argc==2 ){
6746 N = sqlite3_value_int(argv[1]);
6747 if( N>0 ) decimal_round(p, N);
 
 
 
 
6748 }else{
6749 N = 0;
6750 }
6751 if( p ){
6752 if( sqlite3_user_data(context)!=0 ){
@@ -6917,13 +6947,17 @@
6917 int argc,
6918 sqlite3_value **argv
6919 ){
6920 UNUSED_PARAMETER(argc);
6921 if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){
6922 Decimal *pA = decimalPow2(sqlite3_value_int(argv[0]));
6923 decimal_result_sci(context, pA, 0);
6924 decimal_free(pA);
 
 
 
 
6925 }
6926 }
6927
6928 #ifdef _WIN32
6929
@@ -7729,10 +7763,125 @@
7729 }
7730
7731 #endif
7732
7733 /************************* End ext/misc/base85.c ********************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7734 /************************* Begin ext/misc/ieee754.c ******************/
7735 /*
7736 ** 2013-04-17
7737 **
7738 ** The author disclaims copyright to this source code. In place of
@@ -25076,10 +25225,11 @@
25076 unsigned mEqpLines; /* Mask of vertical lines in the EQP output graph */
25077 u8 nPopOutput; /* Revert .output settings when reaching zero */
25078 u8 nPopMode; /* Revert .mode settings when reaching zero */
25079 u8 enableTimer; /* Enable the timer. 2: permanently 1: only once */
25080 u8 bDelimitNonprint; /* Add \001...\002 around non-printing in prompts */
 
25081 int inputNesting; /* Track nesting level of .read and other redirects */
25082 double prevTimer; /* Last reported timer value */
25083 double tmProgress; /* --timeout option for .progress */
25084 i64 lineno; /* Line number of last line read from in */
25085 const char *zInFile; /* Name of the input file */
@@ -25187,11 +25337,11 @@
25187
25188 /* Names of values for Mode.spec.eEsc and Mode.spec.eText
25189 */
25190 static const char *qrfEscNames[] = { "auto", "off", "ascii", "symbol" };
25191 static const char *qrfQuoteNames[] =
25192 { "off","off","sql","hex","csv","tcl","json","relaxed"};
25193
25194 /*
25195 ** These are the allowed shellFlgs values
25196 */
25197 #define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */
@@ -25276,11 +25426,11 @@
25276 { "ascii", 7, 6, 9, 1, 1, 0, 1, 12, 0, 0 },
25277 { "box", 0, 0, 9, 1, 1, 0, 3, 1, 2, 0 },
25278 { "c", 4, 1, 10, 5, 5, 4, 1, 12, 0, 0 },
25279 { "column", 0, 0, 9, 1, 1, 0, 3, 2, 2, 0 },
25280 { "count", 0, 0, 0, 0, 0, 0, 0, 3, 0, 0 },
25281 { "csv", 4, 5, 9, 3, 3, 0, 1, 4, 0, 0 },
25282 { "html", 0, 0, 9, 4, 4, 0, 3, 7, 0, 0 },
25283 { "insert", 0, 0, 10, 2, 2, 0, 1, 8, 0, 0 },
25284 { "jatom", 4, 1, 11, 6, 6, 0, 1, 12, 0, 0 },
25285 { "jobject", 0, 1, 11, 6, 6, 0, 0, 10, 0, 0 },
25286 { "json", 0, 0, 11, 6, 6, 0, 0, 9, 0, 0 },
@@ -26495,14 +26645,20 @@
26495 sqlite3_context *pCtx,
26496 int nVal,
26497 sqlite3_value **apVal
26498 ){
26499 double r = sqlite3_value_double(apVal[0]);
26500 int n = nVal>=2 ? sqlite3_value_int(apVal[1]) : 26;
 
26501 char z[400];
26502 if( n<1 ) n = 1;
26503 if( n>350 ) n = 350;
 
 
 
 
 
26504 z[sizeof(z)-1] = 0;
26505 snprintf(z, sizeof(z)-1, "%#+.*e", n, r);
26506 sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT);
26507 }
26508
@@ -30111,11 +30267,13 @@
30111 sqlite3_ieee_init(p->db, 0, 0);
30112 sqlite3_series_init(p->db, 0, 0);
30113 sqlite3_diskused_init(p->db, 0, 0);
30114 sqlite3_strdup_init(p->db, 0, 0);
30115 #ifndef SQLITE_SHELL_FIDDLE
30116 sqlite3_fileio_init(p->db, 0, 0);
 
 
30117 sqlite3_completion_init(p->db, 0, 0);
30118 #endif
30119 #ifdef SQLITE_HAVE_ZLIB
30120 if( !p->bSafeModePersist ){
30121 sqlite3_zipfile_init(p->db, 0, 0);
@@ -33259,13 +33417,21 @@
33259 dotCmdError(p, i, "unknown argument", 0);
33260 return 1;
33261 }
33262 }else if( cli_strcmp(z,"-v")==0 ){
33263 eVerbose++;
33264 }else if( cli_strcmp(z,"-schema")==0 && i<nArg-1 ){
 
 
 
 
33265 zSchema = azArg[++i];
33266 }else if( cli_strcmp(z,"-skip")==0 && i<nArg-1 ){
 
 
 
 
33267 nSkip = integerValue(azArg[++i]);
33268 }else if( cli_strcmp(z,"-ascii")==0 ){
33269 if( sCtx.cColSep==0 ) sCtx.cColSep = '\037';
33270 if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\036';
33271 xRead = ascii_read_one_field;
@@ -33272,12 +33438,20 @@
33272 }else if( cli_strcmp(z,"-csv")==0 ){
33273 if( sCtx.cColSep==0 ) sCtx.cColSep = ',';
33274 if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\n';
33275 xRead = csv_read_one_field;
33276 }else if( cli_strcmp(z,"-esc")==0 ){
 
 
 
 
33277 sCtx.cUQEscape = azArg[++i][0];
33278 }else if( cli_strcmp(z,"-qesc")==0 ){
 
 
 
 
33279 sCtx.cQEscape = azArg[++i][0];
33280 }else if( cli_strcmp(z,"-colsep")==0 ){
33281 if( i==nArg-1 ){
33282 dotCmdError(p, i, "missing argument", 0);
33283 return 1;
@@ -34251,11 +34425,12 @@
34251 append_c_string(pDesc, p->mode.spec.zNull);
34252 }
34253 if( bAll
34254 || (pI->eText!=p->mode.spec.eText && (pI->eText>1 || p->mode.spec.eText>1))
34255 ){
34256 sqlite3_str_appendf(pDesc," --quote %s",qrfQuoteNames[p->mode.spec.eText]);
 
34257 }
34258 if( bAll
34259 || ((p->mode.spec.bRowCount==QRF_Yes) != ((pI->mFlg&4)!=0))
34260 ){
34261 sqlite3_str_appendf(pDesc," --rowcount %s",
@@ -37581,53 +37756,18 @@
37581 ** -LABEL Disable the named optimization
37582 **
37583 ** INTEGER Mask of optimizations to disable
37584 */
37585 case SQLITE_TESTCTRL_OPTIMIZATIONS: {
37586 static const struct {
37587 unsigned int mask; /* Mask for this optimization */
37588 unsigned int bDsply; /* Display this on output */
37589 const char *zLabel; /* Name of optimization */
37590 } aLabel[] = {
37591 { 0x00000001, 1, "QueryFlattener" },
37592 { 0x00000001, 0, "Flatten" },
37593 { 0x00000002, 1, "WindowFunc" },
37594 { 0x00000004, 1, "GroupByOrder" },
37595 { 0x00000010, 1, "DistinctOpt" },
37596 { 0x00000020, 1, "CoverIdxScan" },
37597 { 0x00000040, 1, "OrderByIdxJoin" },
37598 { 0x00000080, 1, "Transitive" },
37599 { 0x00000100, 1, "OmitNoopJoin" },
37600 { 0x00000200, 1, "CountOfView" },
37601 { 0x00000400, 1, "CursorHints" },
37602 { 0x00000800, 1, "Stat4" },
37603 { 0x00001000, 1, "PushDown" },
37604 { 0x00002000, 1, "SimplifyJoin" },
37605 { 0x00004000, 1, "SkipScan" },
37606 { 0x00008000, 1, "PropagateConst" },
37607 { 0x00010000, 1, "MinMaxOpt" },
37608 { 0x00020000, 1, "SeekScan" },
37609 { 0x00040000, 1, "OmitOrderBy" },
37610 { 0x00080000, 1, "BloomFilter" },
37611 { 0x00200000, 1, "BalancedMerge" },
37612 { 0x00400000, 1, "ReleaseReg" },
37613 { 0x00800000, 1, "FlttnUnionAll" },
37614 { 0x01000000, 1, "IndexedEXpr" },
37615 { 0x02000000, 1, "Coroutines" },
37616 { 0x04000000, 1, "NullUnusedCols" },
37617 { 0x08000000, 1, "OnePass" },
37618 { 0x10000000, 1, "OrderBySubq" },
37619 { 0x20000000, 1, "StarQuery" },
37620 { 0x40000000, 1, "ExistsToJoin" },
37621 { 0x80000000, 1, "UnionLimit" },
37622 { 0xffffffff, 0, "All" },
37623 };
37624 unsigned int curOpt;
37625 unsigned int newOpt;
37626 unsigned int m;
37627 int ii;
37628 int nOff;
37629 sqlite3_test_control(SQLITE_TESTCTRL_GETOPT, p->db, &curOpt);
37630 newOpt = curOpt;
37631 for(ii=2; ii<nArg; ii++){
37632 const char *z = azArg[ii];
37633 int useLabel = 0;
@@ -37640,29 +37780,27 @@
37640 zLabel = z;
37641 }else{
37642 newOpt = (unsigned int)strtol(z,0,0);
37643 }
37644 if( useLabel ){
37645 int jj;
37646 for(jj=0; jj<ArraySize(aLabel); jj++){
37647 if( sqlite3_stricmp(zLabel, aLabel[jj].zLabel)==0 ) break;
37648 }
37649 if( jj>=ArraySize(aLabel) ){
37650 cli_printf(stderr,
37651 "Error: no such optimization: \"%s\"\n", zLabel);
37652 cli_puts("Should be one of:", stderr);
37653 for(jj=0; jj<ArraySize(aLabel); jj++){
37654 cli_printf(stderr," %s", aLabel[jj].zLabel);
 
37655 }
37656 cli_puts("\n", stderr);
37657 rc = 1;
37658 goto meta_command_exit;
37659 }
 
37660 if( useLabel=='+' ){
37661 newOpt &= ~aLabel[jj].mask;
37662 }else{
37663 newOpt |= aLabel[jj].mask;
37664 }
37665 }
37666 }
37667 if( curOpt!=newOpt ){
37668 sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,p->db,newOpt);
@@ -37670,22 +37808,24 @@
37670 for(ii=nOff=0, m=1; ii<32; ii++, m <<= 1){
37671 if( m & newOpt ) nOff++;
37672 }
37673 if( nOff<12 ){
37674 cli_puts("+All", p->out);
37675 for(ii=0; ii<ArraySize(aLabel); ii++){
37676 if( !aLabel[ii].bDsply ) continue;
37677 if( (newOpt & aLabel[ii].mask)!=0 ){
37678 cli_printf(p->out, " -%s", aLabel[ii].zLabel);
 
37679 }
37680 }
37681 }else{
37682 cli_puts("-All", p->out);
37683 for(ii=0; ii<ArraySize(aLabel); ii++){
37684 if( !aLabel[ii].bDsply ) continue;
37685 if( (newOpt & aLabel[ii].mask)==0 ){
37686 cli_printf(p->out, " +%s", aLabel[ii].zLabel);
 
37687 }
37688 }
37689 }
37690 cli_puts("\n", p->out);
37691 rc2 = isOk = 3;
@@ -38313,10 +38453,67 @@
38313 }
38314 }
38315
38316 return rc;
38317 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38318
38319 /*
38320 ** Run a single line of SQL. Return the number of errors.
38321 */
38322 static int runOneSqlLine(
@@ -38329,13 +38526,18 @@
38329 char *zErrMsg = 0;
38330
38331 open_db(p, 0);
38332 if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql);
38333 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
38334 BEGIN_TIMER(p);
38335 rc = shell_exec(p, zSql, &zErrMsg);
38336 END_TIMER(p);
 
 
 
 
 
38337 if( rc || zErrMsg ){
38338 sqlite3_str *pPrefix = sqlite3_str_new(p->db);
38339 const char *zErrorTail;
38340 const char *zErrorType;
38341 if( zErrMsg==0 ){
@@ -38426,10 +38628,31 @@
38426 memcpy(zLine, zBegin, nZ);
38427 zLine[nZ] = 0;
38428 return zLine;
38429 }
38430 #endif /* SQLITE_SHELL_FIDDLE */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38431
38432 /*
38433 ** Read input from *in and process it. If *in==0 then input
38434 ** is interactive - the user is typing it it. Otherwise, input
38435 ** is coming from a file or device. A prompt is issued and history
@@ -38495,13 +38718,13 @@
38495 #ifdef SQLITE_SHELL_LEGACY_COMMAND_TERMINATOR
38496 if( line_is_command_terminator(zLine, zSql, nSql) ){
38497 memcpy(zLine,";",2);
38498 }
38499 #endif
38500 hasSemi = strchr(zLine,';')!=0;
38501 nLine = strlen(zLine);
38502 if( nSql+nLine+2>=nAlloc ){
38503 /* Grow buffer by half-again increments when big. */
38504 nAlloc = nSql+(nSql>>1)+nLine+100;
38505 zSql = realloc(zSql, nAlloc);
38506 shell_check_oom(zSql);
38507 }
@@ -38524,11 +38747,11 @@
38524 zSrc, startline, zSize);
38525 nSql = 0;
38526 errCnt++;
38527 break;
38528 }
38529 if( nSql && hasSemi && sqlite3_complete(zSql) ){
38530 echo_group_input(p, zSql);
38531 errCnt += runOneSqlLine(p, zSql, p->zInFile, startline);
38532 nSql = 0;
38533 if( p->nPopOutput ){
38534 output_reset(p);
@@ -39258,11 +39481,12 @@
39258 }else if( cli_strcmp(z,"-bail")==0 ){
39259 bail_on_error = 1;
39260 }else if( cli_strcmp(z,"-nonce")==0 ){
39261 free(data.zNonce);
39262 data.zNonce = strdup(cmdline_option_value(argc, argv, ++i));
39263 }else if( cli_strcmp(z,"-unsafe-testing")==0 ){
 
39264 ShellSetFlag(&data,SHFLG_TestingMode);
39265 }else if( cli_strcmp(z,"-safe")==0 ){
39266 /* no-op - catch this on the second pass */
39267 }else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){
39268 /* skip over the argument */
@@ -39277,10 +39501,17 @@
39277 int kk;
39278 for(kk=0; kk<argc; kk++){
39279 sqlite3_fprintf(stdout,"argv[%d] = \"%s\"\n", kk, argv[kk]);
39280 }
39281 return 0;
 
 
 
 
 
 
 
39282 }
39283 }
39284 #ifndef SQLITE_SHELL_FIDDLE
39285 if( !bEnableVfstrace ) verify_uninitialized();
39286 #endif
@@ -39573,11 +39804,14 @@
39573 stdin_is_interactive = 0;
39574 break;
39575 #endif
39576 }else if( cli_strcmp(z,"-safe")==0 ){
39577 data.bSafeMode = data.bSafeModePersist = 1;
39578 }else if( cli_strcmp(z,"-unsafe-testing")==0 ){
 
 
 
39579 /* Acted upon in first pass. */
39580 }else{
39581 cli_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
39582 eputz("Use -help for a list of options.\n");
39583 rc = 1;
39584
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -14,10 +14,11 @@
14 ** ext/misc/decimal.c
15 ** ext/misc/diskused.c
16 ** ext/misc/fileio.c
17 ** ext/misc/ieee754.c
18 ** ext/misc/memtrace.c
19 ** ext/misc/optname.c
20 ** ext/misc/pcachetrace.c
21 ** ext/misc/regexp.c
22 ** ext/misc/series.c
23 ** ext/misc/sha1.c
24 ** ext/misc/shathree.c
@@ -6719,10 +6720,35 @@
6720 pX = decimalPow2(e);
6721 decimalMul(pA, pX);
6722 decimal_free(pX);
6723 return pA;
6724 }
6725
6726 /*
6727 ** Extract a 32-bit signed integer from argument pVal and write the
6728 ** results into *pResult. Return 0 on success and 1 if the value is
6729 ** too larger to fit in 32-bits.
6730 */
6731 static int decimalSafeInt(
6732 sqlite3_context *context,
6733 sqlite3_value *pVal,
6734 int *pResult
6735 ){
6736 sqlite3_int64 i64 = sqlite3_value_int64(pVal);
6737 if( i64<-2147483648LL || i64>2147483647LL ){
6738 char *zMsg = sqlite3_mprintf(
6739 "value %lld is too large: range limit -2147483648..+2147483647",
6740 i64);
6741 sqlite3_result_error(context, zMsg, -1);
6742 sqlite3_free(zMsg);
6743 *pResult = 0;
6744 return 1;
6745 }else{
6746 *pResult = (int)i64;
6747 return 0;
6748 }
6749 }
6750
6751 /*
6752 ** SQL Function: decimal(X)
6753 ** OR: decimal_exp(X)
6754 **
@@ -6741,12 +6767,16 @@
6767 sqlite3_value **argv
6768 ){
6769 Decimal *p = decimal_new(context, argv[0], 0);
6770 int N;
6771 if( argc==2 ){
6772 if( decimalSafeInt(context, argv[1], &N) ){
6773 decimal_free(p);
6774 p = 0;
6775 }else if( N>0 ){
6776 decimal_round(p, N);
6777 }
6778 }else{
6779 N = 0;
6780 }
6781 if( p ){
6782 if( sqlite3_user_data(context)!=0 ){
@@ -6917,13 +6947,17 @@
6947 int argc,
6948 sqlite3_value **argv
6949 ){
6950 UNUSED_PARAMETER(argc);
6951 if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){
6952 int N;
6953 if( decimalSafeInt(context, argv[0], &N) ) return;
6954 Decimal *pA = decimalPow2(N);
6955 if( pA ){
6956 decimal_result_sci(context, pA, 0);
6957 decimal_free(pA);
6958 }
6959 }
6960 }
6961
6962 #ifdef _WIN32
6963
@@ -7729,10 +7763,125 @@
7763 }
7764
7765 #endif
7766
7767 /************************* End ext/misc/base85.c ********************/
7768 /************************* Begin ext/misc/optname.c ******************/
7769 /*
7770 ** 2026-10-10
7771 **
7772 ** The author disclaims copyright to this source code. In place of
7773 ** a legal notice, here is a blessing:
7774 **
7775 ** May you do good and not evil.
7776 ** May you find forgiveness for yourself and forgive others.
7777 ** May you share freely, never taking more than you give.
7778 **
7779 *************************************************************************
7780 **
7781 ** The sqlite3_test_control() interface with SQLITE_TESTCTRL_OPTIMIZATIONS
7782 ** and SQLITE_TESTCTRL_GETOPT are used to enable and/or disable various
7783 ** optimizations within SQLite. Optimizations are identified by a bitmask.
7784 ** This file contains external code that will map symbolic names into
7785 ** bitmask values, and bitmask values into symbolic names.
7786 **
7787 ** This code is not part of the SQLite core because we don't want to use
7788 ** code space to store all the symbolic names.
7789 */
7790 /* #include "sqlite3.h" */
7791
7792 /*
7793 ** Convert an optimization number (as recorded in sqliteInt.h) into
7794 ** a mask for that optimization.
7795 */
7796 #define OPT_MASK(N) ((1ull)<<((N)-1))
7797
7798
7799 /*
7800 ** This is the mapping between bits and names.
7801 **
7802 ** Some bit values have multiple names. The preferred name always
7803 ** comes first.
7804 */
7805 static const struct OptName {
7806 sqlite3_uint64 uMask;
7807 const char *zName;
7808 } aOpt[] = {
7809 { OPT_MASK(1), "QueryFlattener" },
7810 { OPT_MASK(1), "Flatten" }, /* Alias for prior */
7811 { OPT_MASK(2), "WindowFunc" },
7812 { OPT_MASK(3), "GroupByOrder" },
7813 { OPT_MASK(4), "JoinMiss" },
7814 { OPT_MASK(5), "DistinctOpt" },
7815 { OPT_MASK(6), "CoverIdxScan" },
7816 { OPT_MASK(7), "OrderByIdxJoin" },
7817 { OPT_MASK(8), "Transitive" },
7818 { OPT_MASK(9), "OmitNoopJoin" },
7819 { OPT_MASK(10), "CountOfView" },
7820 { OPT_MASK(11), "CursorHints" },
7821 { OPT_MASK(12), "Stat4" },
7822 { OPT_MASK(13), "PushDown" },
7823 { OPT_MASK(14), "SimplifyJoin" },
7824 { OPT_MASK(15), "SkipScan" },
7825 { OPT_MASK(16), "PropagateConst" },
7826 { OPT_MASK(17), "MinMaxOpt" },
7827 { OPT_MASK(18), "SeekScan" },
7828 { OPT_MASK(19), "OmitOrderBy" },
7829 { OPT_MASK(20), "BloomFilter" },
7830 /* 21 currently unused */
7831 { OPT_MASK(22), "BalancedMerge" },
7832 { OPT_MASK(23), "ReleaseReg" },
7833 { OPT_MASK(24), "FlttnUnionAll" },
7834 { OPT_MASK(25), "IndexedExpr" },
7835 { OPT_MASK(26), "Coroutines" },
7836 { OPT_MASK(27), "NullUnusedCols" },
7837 { OPT_MASK(28), "OnePass" },
7838 { OPT_MASK(29), "OrderBySubq" },
7839 { OPT_MASK(29), "OrderBySubquery" }, /* Alias for prior */
7840 { OPT_MASK(30), "StarQuery" },
7841 { OPT_MASK(31), "ExistsToJoin" },
7842 { OPT_MASK(32), "UnionLimit" },
7843 /* Special names */
7844 { 0xffffffffffffffffULL, "All" },
7845 { 0x0000000000000000ULL, "None" },
7846 };
7847
7848 /*
7849 ** Given a symbolic name, try to compute the corresponding mask.
7850 **
7851 ** The return value is:
7852 **
7853 ** SQLITE_OK Successful match
7854 ** SQLITE_NOTFOUND No match
7855 ** SQLITE_MISUSE Bad arguments
7856 */
7857 int sqlite3_optimization_mask(const char *zName, sqlite3_uint64 *pMask){
7858 unsigned int i;
7859 if( zName==0 || pMask==0 ){ return SQLITE_MISUSE; }
7860 for(i=0; i<sizeof(aOpt)/sizeof(aOpt[0]); i++){
7861 if( sqlite3_stricmp(zName, aOpt[i].zName)==0 ){
7862 *pMask = aOpt[i].uMask;
7863 return SQLITE_OK;
7864 }
7865 }
7866 *pMask = 0;
7867 return SQLITE_NOTFOUND;
7868 }
7869
7870 /*
7871 ** Given a bitmap, return the canonical symbolic name. Return 0 for
7872 ** a bitmap input of 0 or a bitmap value that matches nothing.
7873 */
7874 const char *sqlite3_optimization_name(sqlite3_uint64 mask){
7875 unsigned int i;
7876 for(i=0; i<sizeof(aOpt)/sizeof(aOpt[0]); i++){
7877 if( aOpt[i].uMask==mask ){ return aOpt[i].zName; }
7878 }
7879 return 0;
7880 }
7881
7882 /************************* End ext/misc/optname.c ********************/
7883 /************************* Begin ext/misc/ieee754.c ******************/
7884 /*
7885 ** 2013-04-17
7886 **
7887 ** The author disclaims copyright to this source code. In place of
@@ -25076,10 +25225,11 @@
25225 unsigned mEqpLines; /* Mask of vertical lines in the EQP output graph */
25226 u8 nPopOutput; /* Revert .output settings when reaching zero */
25227 u8 nPopMode; /* Revert .mode settings when reaching zero */
25228 u8 enableTimer; /* Enable the timer. 2: permanently 1: only once */
25229 u8 bDelimitNonprint; /* Add \001...\002 around non-printing in prompts */
25230 u8 bTestParse; /* Undocumented --test-parse flags */
25231 int inputNesting; /* Track nesting level of .read and other redirects */
25232 double prevTimer; /* Last reported timer value */
25233 double tmProgress; /* --timeout option for .progress */
25234 i64 lineno; /* Line number of last line read from in */
25235 const char *zInFile; /* Name of the input file */
@@ -25187,11 +25337,11 @@
25337
25338 /* Names of values for Mode.spec.eEsc and Mode.spec.eText
25339 */
25340 static const char *qrfEscNames[] = { "auto", "off", "ascii", "symbol" };
25341 static const char *qrfQuoteNames[] =
25342 { "off","off","sql","csv","html","tcl","json","relaxed"};
25343
25344 /*
25345 ** These are the allowed shellFlgs values
25346 */
25347 #define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */
@@ -25276,11 +25426,11 @@
25426 { "ascii", 7, 6, 9, 1, 1, 0, 1, 12, 0, 0 },
25427 { "box", 0, 0, 9, 1, 1, 0, 3, 1, 2, 0 },
25428 { "c", 4, 1, 10, 5, 5, 4, 1, 12, 0, 0 },
25429 { "column", 0, 0, 9, 1, 1, 0, 3, 2, 2, 0 },
25430 { "count", 0, 0, 0, 0, 0, 0, 0, 3, 0, 0 },
25431 { "csv", 4, 5, 9, 3, 3, 0, 1, 12, 0, 0 },
25432 { "html", 0, 0, 9, 4, 4, 0, 3, 7, 0, 0 },
25433 { "insert", 0, 0, 10, 2, 2, 0, 1, 8, 0, 0 },
25434 { "jatom", 4, 1, 11, 6, 6, 0, 1, 12, 0, 0 },
25435 { "jobject", 0, 1, 11, 6, 6, 0, 0, 10, 0, 0 },
25436 { "json", 0, 0, 11, 6, 6, 0, 0, 9, 0, 0 },
@@ -26495,14 +26645,20 @@
26645 sqlite3_context *pCtx,
26646 int nVal,
26647 sqlite3_value **apVal
26648 ){
26649 double r = sqlite3_value_double(apVal[0]);
26650 i64 nn = nVal>=2 ? sqlite3_value_int64(apVal[1]) : 26;
26651 int n;
26652 char z[400];
26653 if( nn<1 ){
26654 n = 1;
26655 }else if( nn>350 ){
26656 n = 350;
26657 }else{
26658 n = (int)nn;
26659 }
26660 z[sizeof(z)-1] = 0;
26661 snprintf(z, sizeof(z)-1, "%#+.*e", n, r);
26662 sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT);
26663 }
26664
@@ -30111,11 +30267,13 @@
30267 sqlite3_ieee_init(p->db, 0, 0);
30268 sqlite3_series_init(p->db, 0, 0);
30269 sqlite3_diskused_init(p->db, 0, 0);
30270 sqlite3_strdup_init(p->db, 0, 0);
30271 #ifndef SQLITE_SHELL_FIDDLE
30272 if( !p->bSafeMode ){
30273 sqlite3_fileio_init(p->db, 0, 0);
30274 }
30275 sqlite3_completion_init(p->db, 0, 0);
30276 #endif
30277 #ifdef SQLITE_HAVE_ZLIB
30278 if( !p->bSafeModePersist ){
30279 sqlite3_zipfile_init(p->db, 0, 0);
@@ -33259,13 +33417,21 @@
33417 dotCmdError(p, i, "unknown argument", 0);
33418 return 1;
33419 }
33420 }else if( cli_strcmp(z,"-v")==0 ){
33421 eVerbose++;
33422 }else if( cli_strcmp(z,"-schema")==0 ){
33423 if( i==nArg-1 ){
33424 dotCmdError(p, i, "missing argument", 0);
33425 return 1;
33426 }
33427 zSchema = azArg[++i];
33428 }else if( cli_strcmp(z,"-skip")==0 ){
33429 if( i==nArg-1 ){
33430 dotCmdError(p, i, "missing argument", 0);
33431 return 1;
33432 }
33433 nSkip = integerValue(azArg[++i]);
33434 }else if( cli_strcmp(z,"-ascii")==0 ){
33435 if( sCtx.cColSep==0 ) sCtx.cColSep = '\037';
33436 if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\036';
33437 xRead = ascii_read_one_field;
@@ -33272,12 +33438,20 @@
33438 }else if( cli_strcmp(z,"-csv")==0 ){
33439 if( sCtx.cColSep==0 ) sCtx.cColSep = ',';
33440 if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\n';
33441 xRead = csv_read_one_field;
33442 }else if( cli_strcmp(z,"-esc")==0 ){
33443 if( i==nArg-1 ){
33444 dotCmdError(p, i, "missing argument", 0);
33445 return 1;
33446 }
33447 sCtx.cUQEscape = azArg[++i][0];
33448 }else if( cli_strcmp(z,"-qesc")==0 ){
33449 if( i==nArg-1 ){
33450 dotCmdError(p, i, "missing argument", 0);
33451 return 1;
33452 }
33453 sCtx.cQEscape = azArg[++i][0];
33454 }else if( cli_strcmp(z,"-colsep")==0 ){
33455 if( i==nArg-1 ){
33456 dotCmdError(p, i, "missing argument", 0);
33457 return 1;
@@ -34251,11 +34425,12 @@
34425 append_c_string(pDesc, p->mode.spec.zNull);
34426 }
34427 if( bAll
34428 || (pI->eText!=p->mode.spec.eText && (pI->eText>1 || p->mode.spec.eText>1))
34429 ){
34430 sqlite3_str_appendf(pDesc," --quote %s",
34431 qrfQuoteNames[p->mode.spec.eText]);
34432 }
34433 if( bAll
34434 || ((p->mode.spec.bRowCount==QRF_Yes) != ((pI->mFlg&4)!=0))
34435 ){
34436 sqlite3_str_appendf(pDesc," --rowcount %s",
@@ -37581,53 +37756,18 @@
37756 ** -LABEL Disable the named optimization
37757 **
37758 ** INTEGER Mask of optimizations to disable
37759 */
37760 case SQLITE_TESTCTRL_OPTIMIZATIONS: {
37761 unsigned int curOpt; /* Current opt-disabled mask */
37762 unsigned int newOpt; /* New opt-disabled mask */
37763 unsigned int m; /* A working mask value */
37764 sqlite3_uint64 mm; /* 64-bit working mask value */
37765 int ii, jj; /* Loop counters */
37766 int nOff; /* Number of disabled optimizations */
37767 const char *zName; /* Name of an optimization */
37768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37769 sqlite3_test_control(SQLITE_TESTCTRL_GETOPT, p->db, &curOpt);
37770 newOpt = curOpt;
37771 for(ii=2; ii<nArg; ii++){
37772 const char *z = azArg[ii];
37773 int useLabel = 0;
@@ -37640,29 +37780,27 @@
37780 zLabel = z;
37781 }else{
37782 newOpt = (unsigned int)strtol(z,0,0);
37783 }
37784 if( useLabel ){
37785 if( sqlite3_optimization_mask(zLabel,&mm)==SQLITE_NOTFOUND ){
 
 
 
 
37786 cli_printf(stderr,
37787 "Error: no such optimization: \"%s\"\n", zLabel);
37788 cli_puts("Should be one of: All", stderr);
37789 for(jj=0; jj<32; jj++){
37790 zName = sqlite3_optimization_name(1ull<<jj);
37791 if( zName ) cli_printf(stderr," %s", zName);
37792 }
37793 cli_puts("\n", stderr);
37794 rc = 1;
37795 goto meta_command_exit;
37796 }
37797 m = (u32)mm;
37798 if( useLabel=='+' ){
37799 newOpt &= ~m;
37800 }else{
37801 newOpt |= m;
37802 }
37803 }
37804 }
37805 if( curOpt!=newOpt ){
37806 sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,p->db,newOpt);
@@ -37670,22 +37808,24 @@
37808 for(ii=nOff=0, m=1; ii<32; ii++, m <<= 1){
37809 if( m & newOpt ) nOff++;
37810 }
37811 if( nOff<12 ){
37812 cli_puts("+All", p->out);
37813 for(ii=0, m=1; ii<32; ii++, m <<= 1){
37814 if( (newOpt & m)!=0
37815 && (zName = sqlite3_optimization_name(m))!=0
37816 ){
37817 cli_printf(p->out, " -%s", zName);
37818 }
37819 }
37820 }else{
37821 cli_puts("-All", p->out);
37822 for(ii=0, m=1; ii<32; ii++, m <<= 1){
37823 if( (newOpt & m)==0
37824 && (zName = sqlite3_optimization_name(m))!=0
37825 ){
37826 cli_printf(p->out, " +%s", zName);
37827 }
37828 }
37829 }
37830 cli_puts("\n", p->out);
37831 rc2 = isOk = 3;
@@ -38313,10 +38453,67 @@
38453 }
38454 }
38455
38456 return rc;
38457 }
38458
38459 /*
38460 ** When the (undocumented) command-line option --test-parse is used,
38461 ** this routine is run instead of runOneSqlLine() to process SQL. Don't
38462 ** actually run any SQL. Instead just provide a one-line summary of the
38463 ** SQL that would have run.
38464 */
38465 static void runTestParse(
38466 ShellState *p, /* Execution context */
38467 char *zSql /* SQL to be run */
38468 ){
38469 int nNL = 0;
38470 char *zNL;
38471 size_t i, j, n;
38472 int nPre = 0;
38473 int nSuf = 0;
38474 int mxPre = 20;
38475 char zPre[50], zSuf[50];
38476
38477 for(zNL=strchr(zSql,'\n'); zNL!=0; zNL=strchr(zNL+1,'\n')){ nNL++; }
38478 n = strlen(zSql);
38479 if( n<40 ) mxPre = 40;
38480 for(i=0; nPre<mxPre && i<n; i++){
38481 char c = zSql[i];
38482 if( c=='\n' ){
38483 zPre[nPre++] = '\\';
38484 zPre[nPre++] = 'n';
38485 }else if( c>0 && c<' ' ){
38486 zPre[nPre++] = '^';
38487 zPre[nPre++] = c+0x40;
38488 }else{
38489 zPre[nPre++] = c;
38490 }
38491 }
38492 zPre[nPre] = 0;
38493 j = n - 20;
38494 if( j<i ){
38495 j = i;
38496 }else{
38497 memcpy(zSuf," ... ", 5);
38498 nSuf = 5;
38499 }
38500 for(i=j; i<n; i++){
38501 char c = zSql[i];
38502 if( c=='\n' ){
38503 zSuf[nSuf++] = '\\';
38504 zSuf[nSuf++] = 'n';
38505 }else if( c>0 && c<' ' ){
38506 zSuf[nSuf++] = '^';
38507 zSuf[nSuf++] = c+0x40;
38508 }else{
38509 zSuf[nSuf++] = c;
38510 }
38511 }
38512 zSuf[nSuf] = 0;
38513 cli_printf(p->out, "%d line%s: %s%s\n", nNL+1, (nNL?"s":""), zPre, zSuf);
38514 }
38515
38516 /*
38517 ** Run a single line of SQL. Return the number of errors.
38518 */
38519 static int runOneSqlLine(
@@ -38329,13 +38526,18 @@
38526 char *zErrMsg = 0;
38527
38528 open_db(p, 0);
38529 if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql);
38530 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
38531 if( p->bTestParse ){
38532 runTestParse(p, zSql);
38533 rc = SQLITE_OK;
38534 }else{
38535 BEGIN_TIMER(p);
38536 rc = shell_exec(p, zSql, &zErrMsg);
38537 END_TIMER(p);
38538 }
38539 if( rc || zErrMsg ){
38540 sqlite3_str *pPrefix = sqlite3_str_new(p->db);
38541 const char *zErrorTail;
38542 const char *zErrorType;
38543 if( zErrMsg==0 ){
@@ -38426,10 +38628,31 @@
38628 memcpy(zLine, zBegin, nZ);
38629 zLine[nZ] = 0;
38630 return zLine;
38631 }
38632 #endif /* SQLITE_SHELL_FIDDLE */
38633
38634 /*
38635 ** Return true if the input would is complete SQL, or complete SQL
38636 ** followed by only whitespace. This is similar to sqlite3_complete()
38637 ** except that if the final semicolon is followed by whitespace, it
38638 ** still returns true.
38639 */
38640 static int line_is_complete(char *zSql, int nSql){
38641 sqlite3_int64 x;
38642 assert( nSql>=0 && zSql[nSql]==0 );
38643 x = sqlite3_incomplete(zSql);
38644 if( x==0x00 || x==0x10 ) return 1;
38645 if( x==0x2d0001 ){
38646 zSql[nSql] = '\n';
38647 zSql[nSql+1] = 0;
38648 x = sqlite3_incomplete(zSql);
38649 zSql[nSql] = 0;
38650 if( x==0x00 || x==0x10 ) return 1;
38651 }
38652 return 0;
38653 }
38654
38655 /*
38656 ** Read input from *in and process it. If *in==0 then input
38657 ** is interactive - the user is typing it it. Otherwise, input
38658 ** is coming from a file or device. A prompt is issued and history
@@ -38495,13 +38718,13 @@
38718 #ifdef SQLITE_SHELL_LEGACY_COMMAND_TERMINATOR
38719 if( line_is_command_terminator(zLine, zSql, nSql) ){
38720 memcpy(zLine,";",2);
38721 }
38722 #endif
38723 if( strchr(zLine,';')!=0 ) hasSemi = 1;
38724 nLine = strlen(zLine);
38725 if( nSql+nLine+4>=nAlloc ){
38726 /* Grow buffer by half-again increments when big. */
38727 nAlloc = nSql+(nSql>>1)+nLine+100;
38728 zSql = realloc(zSql, nAlloc);
38729 shell_check_oom(zSql);
38730 }
@@ -38524,11 +38747,11 @@
38747 zSrc, startline, zSize);
38748 nSql = 0;
38749 errCnt++;
38750 break;
38751 }
38752 if( nSql && hasSemi && line_is_complete(zSql, nSql) ){
38753 echo_group_input(p, zSql);
38754 errCnt += runOneSqlLine(p, zSql, p->zInFile, startline);
38755 nSql = 0;
38756 if( p->nPopOutput ){
38757 output_reset(p);
@@ -39258,11 +39481,12 @@
39481 }else if( cli_strcmp(z,"-bail")==0 ){
39482 bail_on_error = 1;
39483 }else if( cli_strcmp(z,"-nonce")==0 ){
39484 free(data.zNonce);
39485 data.zNonce = strdup(cmdline_option_value(argc, argv, ++i));
39486 }else if( cli_strcmp(z,"-unsafe-testing")==0
39487 || cli_strcmp(z,"-unsafe")==0 ){
39488 ShellSetFlag(&data,SHFLG_TestingMode);
39489 }else if( cli_strcmp(z,"-safe")==0 ){
39490 /* no-op - catch this on the second pass */
39491 }else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){
39492 /* skip over the argument */
@@ -39277,10 +39501,17 @@
39501 int kk;
39502 for(kk=0; kk<argc; kk++){
39503 sqlite3_fprintf(stdout,"argv[%d] = \"%s\"\n", kk, argv[kk]);
39504 }
39505 return 0;
39506 }else if( cli_strcmp(z,"-test-parse")==0 ){
39507 /* Undocumented test option. Read input normally and process all
39508 ** dot-commands. But do not process any SQL. Instead, whenever input
39509 ** text would have been processed as SQL, print a one-line summary of
39510 ** the input. This is used by test script to verify that the end-of-SQL
39511 ** parsing logic is working correctly. */
39512 data.bTestParse = 1;
39513 }
39514 }
39515 #ifndef SQLITE_SHELL_FIDDLE
39516 if( !bEnableVfstrace ) verify_uninitialized();
39517 #endif
@@ -39573,11 +39804,14 @@
39804 stdin_is_interactive = 0;
39805 break;
39806 #endif
39807 }else if( cli_strcmp(z,"-safe")==0 ){
39808 data.bSafeMode = data.bSafeModePersist = 1;
39809 }else if( cli_strcmp(z,"-unsafe-testing")==0
39810 || cli_strcmp(z,"-unsafe")==0 ){
39811 /* Acted upon in first pass. */
39812 }else if( cli_strcmp(z,"-test-parse")==0 ){
39813 /* Acted upon in first pass. */
39814 }else{
39815 cli_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
39816 eputz("Use -help for a list of options.\n");
39817 rc = 1;
39818
+631 -293
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.54.0. By combining all the individual C code files into this
3
+** version 3.55.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** a3332bd623d997921c3186433cd1eab0c941 with changes in files:
21
+** 668541c592b89d32716420615450d55d9faf with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -465,16 +465,16 @@
465465
**
466466
** See also: [sqlite3_libversion()],
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470
-#define SQLITE_VERSION "3.54.0"
471
-#define SQLITE_VERSION_NUMBER 3054000
472
-#define SQLITE_SOURCE_ID "2026-10-09 11:47:51 a3332bd623d997921c3186433cd1eab0c9413aa0f68d93b1731cf80128ec3a36"
470
+#define SQLITE_VERSION "3.55.0"
471
+#define SQLITE_VERSION_NUMBER 3055000
472
+#define SQLITE_SOURCE_ID "2026-10-16 14:31:53 668541c592b89d32716420615450d55d9faf89da8a8e389c673973d8383cca98"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2026-10-09T11:47:51.732Z"
475
+#define SQLITE_SCM_DATETIME "2026-10-16T14:31:53.543Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -4399,11 +4399,11 @@
43994399
** parameter on F or if the value of P does not match any of the
44004400
** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
44014401
**
44024402
** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
44034403
** 64-bit signed integer and returns that integer, or D if P does not
4404
-** exist or ff the value of P is something other than an integer.
4404
+** exist or if the value of P is something other than an integer.
44054405
**
44064406
** The sqlite3_uri_key(F,N) returns a pointer to the name (not
44074407
** the value) of the N-th query parameter for filename F, or a NULL
44084408
** pointer if N is less than zero or greater than the number of query
44094409
** parameters minus 1. The N value is zero-based so N should be 0 to obtain
@@ -18876,11 +18876,10 @@
1887618876
unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
1887718877
int errCode; /* Most recent error code (SQLITE_*) */
1887818878
int errByteOffset; /* Byte offset of error in SQL statement */
1887918879
int errMask; /* & result codes with this before returning */
1888018880
int iSysErrno; /* Errno value from last system error */
18881
- u32 dbOptFlags; /* Flags to enable/disable optimizations */
1888218881
u8 enc; /* Text encoding */
1888318882
u8 autoCommit; /* The auto-commit flag. */
1888418883
u8 temp_store; /* 1: file 2: memory 0: default */
1888518884
u8 mallocFailed; /* True if we have seen a malloc failure */
1888618885
u8 bBenignMalloc; /* Do not require OOMs if true */
@@ -18895,10 +18894,11 @@
1889518894
u8 eOpenState; /* Current condition of the connection */
1889618895
u8 nFpDigit; /* Significant digits to keep on double->text */
1889718896
int nextPagesize; /* Pagesize after VACUUM if >0 */
1889818897
i64 nChange; /* Value returned by sqlite3_changes() */
1889918898
i64 nTotalChange; /* Value returned by sqlite3_total_changes() */
18899
+ u32 dbOptFlags; /* Flags to enable/disable optimizations */
1890018900
int aLimit[SQLITE_N_LIMIT]; /* Limits */
1890118901
int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */
1890218902
struct sqlite3InitInfo { /* Information used during initialization */
1890318903
Pgno newTnum; /* Rootpage of table being initialized */
1890418904
u8 iDb; /* Which db file is being initialized */
@@ -19094,55 +19094,53 @@
1909419094
#define DBFLAG_EncodingFixed 0x0040 /* No longer possible to change enc. */
1909519095
1909619096
/*
1909719097
** Bits of the sqlite3.dbOptFlags field that are used by the
1909819098
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
19099
-** selectively disable various optimizations.
19099
+** selectively disable various optimizations. The numbers in each macro
19100
+** are the one-based bit position (for improved readability).
19101
+**
19102
+** Keep these values in sync with the ext/misc/optname.c extension.
1910019103
*/
19101
-#define SQLITE_QueryFlattener 0x00000001 /* Query flattening */
19102
-#define SQLITE_WindowFunc 0x00000002 /* Use xInverse for window functions */
19103
-#define SQLITE_GroupByOrder 0x00000004 /* GROUPBY cover of ORDERBY */
19104
- /* 0x00000008 -- Available for reuse */
19105
-#define SQLITE_DistinctOpt 0x00000010 /* DISTINCT using indexes */
19106
-#define SQLITE_CoverIdxScan 0x00000020 /* Covering index scans */
19107
-#define SQLITE_OrderByIdxJoin 0x00000040 /* ORDER BY of joins via index */
19108
-#define SQLITE_Transitive 0x00000080 /* Transitive constraints */
19109
-#define SQLITE_OmitNoopJoin 0x00000100 /* Omit unused tables in joins */
19110
-#define SQLITE_CountOfView 0x00000200 /* The count-of-view optimization */
19111
-#define SQLITE_CursorHints 0x00000400 /* Add OP_CursorHint opcodes */
19112
-#define SQLITE_Stat4 0x00000800 /* Use STAT4 data */
19113
- /* TH3 expects this value ^^^^^^^^^^ */
19114
-#define SQLITE_PushDown 0x00001000 /* WHERE-clause push-down opt */
19115
-#define SQLITE_SimplifyJoin 0x00002000 /* Convert LEFT JOIN to JOIN */
19116
-#define SQLITE_SkipScan 0x00004000 /* Skip-scans */
19117
-#define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */
19118
-#define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */
19119
-#define SQLITE_SeekScan 0x00020000 /* The OP_SeekScan optimization */
19120
-#define SQLITE_OmitOrderBy 0x00040000 /* Omit pointless ORDER BY */
19121
- /* TH3 expects this value ^^^^^^^^^^ */
19122
-#define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filters */
19123
- /* TH3 expects this value ^^^^^^^^^^ */
19124
- /* 0x00100000 -- Available for reuse */
19125
-#define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
19126
-#define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
19127
-#define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
19128
- /* TH3 expects this value ^^^^^^^^^^ */
19129
-#define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
19130
-#define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
19131
-#define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
19132
-#define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
19133
-#define SQLITE_OrderBySubq 0x10000000 /* ORDER BY in subquery helps outer */
19134
-#define SQLITE_StarQuery 0x20000000 /* Heurists for star queries */
19135
-#define SQLITE_ExistsToJoin 0x40000000 /* The EXISTS-to-JOIN optimization */
19136
-#define SQLITE_UnionLimit 0x80000000 /* Optimizations for UNION + LIMIT */
19137
-#define SQLITE_AllOpts 0xffffffff /* All optimizations */
19104
+#define SQLITE_QueryFlattener 1 /* Query flattening */
19105
+#define SQLITE_WindowFunc 2 /* Use xInverse for window functions */
19106
+#define SQLITE_GroupByOrder 3 /* GROUPBY cover of ORDERBY */
19107
+#define SQLITE_JoinMiss 4 /* Unwind join loops on a lookup miss*/
19108
+#define SQLITE_DistinctOpt 5 /* DISTINCT using indexes */
19109
+#define SQLITE_CoverIdxScan 6 /* Covering index scans */
19110
+#define SQLITE_OrderByIdxJoin 7 /* ORDER BY of joins via index */
19111
+#define SQLITE_Transitive 8 /* Transitive constraints */
19112
+#define SQLITE_OmitNoopJoin 9 /* Omit unused tables in joins */
19113
+#define SQLITE_CountOfView 10 /* The count-of-view optimization */
19114
+#define SQLITE_CursorHints 11 /* Add OP_CursorHint opcodes */
19115
+#define SQLITE_Stat4 12 /* Use STAT4 data */
19116
+#define SQLITE_PushDown 13 /* WHERE-clause push-down opt */
19117
+#define SQLITE_SimplifyJoin 14 /* Convert LEFT JOIN to JOIN */
19118
+#define SQLITE_SkipScan 15 /* Skip-scans */
19119
+#define SQLITE_PropagateConst 16 /* The constant propagation opt */
19120
+#define SQLITE_MinMaxOpt 17 /* The min/max optimization */
19121
+#define SQLITE_SeekScan 18 /* The OP_SeekScan optimization */
19122
+#define SQLITE_OmitOrderBy 19 /* Omit pointless ORDER BY */
19123
+#define SQLITE_BloomFilter 20 /* Use a Bloom filters */
19124
+ /* 21 -- Available for reuse */
19125
+#define SQLITE_BalancedMerge 22 /* Balance multi-way merges */
19126
+#define SQLITE_ReleaseReg 23 /* Use OP_ReleaseReg for testing */
19127
+#define SQLITE_FlttnUnionAll 24 /* Disable the UNION ALL flattener */
19128
+#define SQLITE_IndexedExpr 25 /* Pull exprs from index when able */
19129
+#define SQLITE_Coroutines 26 /* Co-routines for subqueries */
19130
+#define SQLITE_NullUnusedCols 27 /* NULL unused columns in subqueries */
19131
+#define SQLITE_OnePass 28 /* Single-pass DELETE and UPDATE */
19132
+#define SQLITE_OrderBySubq 29 /* ORDER BY in subquery helps outer */
19133
+#define SQLITE_StarQuery 30 /* Heurists for star queries */
19134
+#define SQLITE_ExistsToJoin 31 /* The EXISTS-to-JOIN optimization */
19135
+#define SQLITE_UnionLimit 32 /* Optimizations for UNION + LIMIT */
1913819136
1913919137
/*
1914019138
** Macros for testing whether or not optimizations are enabled or disabled.
1914119139
*/
19142
-#define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0)
19143
-#define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0)
19140
+#define OptimizationDisabled(D,M) (((D)->dbOptFlags&(1ul<<((M)-1)))!=0)
19141
+#define OptimizationEnabled(D,M) (((D)->dbOptFlags&(1ul<<((M)-1)))==0)
1914419142
1914519143
/*
1914619144
** Return true if it OK to factor constant expressions into the initialization
1914719145
** code. The argument is a Parse object for the code generator.
1914819146
*/
@@ -21119,10 +21117,11 @@
2111921117
int nRangeReg; /* Size of the temporary register block */
2112021118
int iRangeReg; /* First register in temporary register block */
2112121119
int nErr; /* Number of errors seen */
2112221120
int nTab; /* Number of previously allocated VDBE cursors */
2112321121
int nMem; /* Number of memory cells used so far */
21122
+ int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */
2112421123
int iSelfTab; /* Table associated with an index on expr, or negative
2112521124
** of the base register during check-constraint eval */
2112621125
int nNestSel; /* Number of nested SELECT statements and/or VIEWs */
2112721126
int nLabel; /* The *negative* of the number of labels used */
2112821127
int nLabelAlloc; /* Number of slots in aLabel */
@@ -22448,15 +22447,14 @@
2244822447
SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr*);
2244922448
SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*);
2245022449
SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse*,Expr*);
2245122450
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
2245222451
SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
22452
+SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int,int);
2245322453
SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int,int);
2245422454
SQLITE_PRIVATE int sqlite3ExprListIsConstant(Parse *pParse, ExprList *pList, int bNoIs);
22455
-#ifdef SQLITE_ENABLE_CURSOR_HINTS
2245622455
SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
22457
-#endif
2245822456
SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*, Parse*, int);
2245922457
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
2246022458
SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
2246122459
SQLITE_PRIVATE int sqlite3ExprIsLikeOperator(const Expr*);
2246222460
SQLITE_PRIVATE int sqlite3IsRowid(const char*);
@@ -26055,36 +26053,39 @@
2605526053
p->isUtc = 1;
2605626054
p->isLocal = 0;
2605726055
}
2605826056
}
2605926057
}
26058
+
26059
+/*
26060
+** Return the number of dates in a specific month.
26061
+*/
26062
+static int daysOfMonth(int Y, int M){
26063
+ if( (1<<M) & 0x15aa ){
26064
+ return 31;
26065
+ }else if( M!=2 ){
26066
+ return 30;
26067
+ }else if( Y%4==0 && (Y%100!=0 || Y%400==0) ){
26068
+ return 29;
26069
+ }else{
26070
+ return 28;
26071
+ }
26072
+}
2606026073
2606126074
/*
2606226075
** Given the YYYY-MM-DD information current in p, determine if there
2606326076
** is day-of-month overflow and set nFloor to the number of days that
2606426077
** would need to be subtracted from the date in order to bring the
2606526078
** date back to the end of the month.
2606626079
*/
2606726080
static void computeFloor(DateTime *p){
26081
+ int mxD; /* Maximum day number for the current month */
2606826082
assert( p->validYMD || p->isError );
26069
- assert( p->D>=0 && p->D<=31 );
26083
+ assert( p->D>=0 && p->D<=32 );
2607026084
assert( p->M>=0 && p->M<=12 );
26071
- if( p->validHMS && p->h==24 ){
26072
- p->h = 0;
26073
- p->D++;
26074
- }
26075
- if( p->D<=28 ){
26076
- p->nFloor = 0;
26077
- }else if( (1<<p->M) & 0x15aa ){
26078
- p->nFloor = 0;
26079
- }else if( p->M!=2 ){
26080
- p->nFloor = (p->D==31);
26081
- }else if( p->Y%4!=0 || (p->Y%100==0 && p->Y%400!=0) ){
26082
- p->nFloor = p->D - 28;
26083
- }else{
26084
- p->nFloor = p->D - 29;
26085
- }
26085
+ mxD = daysOfMonth(p->Y, p->M);
26086
+ p->nFloor = p->D>mxD ? p->D - mxD : 0;
2608626087
}
2608726088
2608826089
/*
2608926090
** Parse dates of the form
2609026091
**
@@ -26110,11 +26111,23 @@
2611026111
return 1;
2611126112
}
2611226113
zDate += 10;
2611326114
while( sqlite3Isspace(*zDate) || 'T'==*(u8*)zDate ){ zDate++; }
2611426115
if( parseHhMmSs(zDate, p)==0 ){
26115
- /* We got the time */
26116
+ if( p->h==24 ){
26117
+ int mxD = daysOfMonth(Y,M);
26118
+ p->h = 0;
26119
+ D++;
26120
+ if( D>mxD ){
26121
+ D -= mxD;
26122
+ M++;
26123
+ if( M>12 ){
26124
+ M = 1;
26125
+ Y++;
26126
+ }
26127
+ }
26128
+ }
2611626129
}else if( *zDate==0 ){
2611726130
p->validHMS = 0;
2611826131
}else{
2611926132
return 1;
2612026133
}
@@ -46240,32 +46253,39 @@
4624046253
#ifdef SQLITE_MMAP_READWRITE
4624146254
if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE;
4624246255
#endif
4624346256
4624446257
if( pOrig ){
46258
+ i64 nReuse = pFd->mmapSize & ~((int)osGetpagesize()-1);
46259
+
46260
+ /* Unmap any part of the current mapping that will not be reused */
46261
+ if( nReuse<pFd->mmapSizeActual ){
46262
+ osMunmap(&pOrig[nReuse], pFd->mmapSizeActual - nReuse);
46263
+ }
46264
+
46265
+ /* If nReuse is now zero, then the entire mapping was unmapped by the
46266
+ ** call above. In this case do not attempt to extend pOrig. */
46267
+ if( nReuse>0 ){
4624546268
#if HAVE_MREMAP
46246
- i64 nReuse = pFd->mmapSize;
46247
- pNew = osMremap(pOrig, nReuse, nNew, MREMAP_MAYMOVE);
46248
- zErr = "mremap";
46269
+ pNew = osMremap(pOrig, nReuse, nNew, MREMAP_MAYMOVE);
46270
+ zErr = "mremap";
4624946271
#else
46250
- const int szSyspage = osGetpagesize();
46251
- i64 nReuse = (pFd->mmapSize & ~(szSyspage-1));
46252
- u8 *pReq = &pOrig[nReuse];
46253
- pNew = osMmap(pReq, nNew-nReuse, flags, MAP_SHARED, h, nReuse);
46254
- if( pNew!=MAP_FAILED ){
46255
- if( pNew!=pReq ){
46256
- osMunmap(pNew, nNew - nReuse);
46257
- pNew = 0;
46258
- }else{
46259
- pNew = pOrig;
46260
- }
46261
- }
46272
+ pNew = osMmap(&pOrig[nReuse], nNew-nReuse, flags, MAP_SHARED, h, nReuse);
46273
+ if( pNew!=MAP_FAILED ){
46274
+ if( pNew!=&pOrig[nReuse] ){
46275
+ osMunmap(pNew, nNew - nReuse);
46276
+ pNew = 0;
46277
+ }else{
46278
+ pNew = pOrig;
46279
+ }
46280
+ }
4626246281
#endif
4626346282
46264
- /* The attempt to extend the existing mapping failed. Free it. */
46265
- if( pNew==MAP_FAILED || pNew==0 ){
46266
- osMunmap(pOrig, nReuse);
46283
+ /* The attempt to extend the existing mapping failed. Free it. */
46284
+ if( pNew==MAP_FAILED || pNew==0 ){
46285
+ osMunmap(pOrig, nReuse);
46286
+ }
4626746287
}
4626846288
}
4626946289
4627046290
/* If pNew is still NULL, try to create an entirely new mapping. */
4627146291
if( pNew==0 ){
@@ -72669,16 +72689,22 @@
7266972689
SQLITE_PRIVATE void sqlite3BtreeEnter(Btree *p){
7267072690
p->pBt->db = p->db;
7267172691
}
7267272692
SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
7267372693
int i;
72694
+ u8 skipOk = 1;
72695
+ /* As in the threadsafe build: set db->noSharedCache when no attached
72696
+ ** Btree is sharable, so that schema and table-lock checks are skipped */
72697
+ if( db->noSharedCache ) return;
7267472698
for(i=0; i<db->nDb; i++){
7267572699
Btree *p = db->aDb[i].pBt;
7267672700
if( p ){
7267772701
p->pBt->db = p->db;
72702
+ if( p->sharable ) skipOk = 0;
7267872703
}
7267972704
}
72705
+ db->noSharedCache = skipOk;
7268072706
}
7268172707
#endif /* if SQLITE_THREADSAFE */
7268272708
7268372709
#ifndef SQLITE_OMIT_INCRBLOB
7268472710
/*
@@ -80129,11 +80155,11 @@
8012980155
** the source page. Make sure this does not cause problems by not
8013080156
** reading the first 4 bytes */
8013180157
memcpy(&data[idx+4], pCell+4, sz-4);
8013280158
put4byte(&data[idx], iChild);
8013380159
pIns = pPage->aCellIdx + i*2;
80134
- memmove(pIns+2, pIns, 2*(pPage->nCell - i));
80160
+ if( i<pPage->nCell ) memmove(pIns+2, pIns, 2*(pPage->nCell - i));
8013580161
put2byte(pIns, idx);
8013680162
pPage->nCell++;
8013780163
/* increment the cell count */
8013880164
if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
8013980165
assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
@@ -80213,11 +80239,11 @@
8021380239
assert( idx >= pPage->cellOffset+2*pPage->nCell+2 || CORRUPT_DB );
8021480240
assert( idx+sz <= (int)pPage->pBt->usableSize );
8021580241
pPage->nFree -= (u16)(2 + sz);
8021680242
memcpy(&data[idx], pCell, sz);
8021780243
pIns = pPage->aCellIdx + i*2;
80218
- memmove(pIns+2, pIns, 2*(pPage->nCell - i));
80244
+ if( i<pPage->nCell ) memmove(pIns+2, pIns, 2*(pPage->nCell - i));
8021980245
put2byte(pIns, idx);
8022080246
pPage->nCell++;
8022180247
/* increment the cell count */
8022280248
if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
8022380249
assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
@@ -81166,10 +81192,11 @@
8116681192
int limit = pOld->nCell;
8116781193
u8 *aData = pOld->aData;
8116881194
u16 maskPage = pOld->maskPage;
8116981195
u8 *piCell = aData + pOld->cellOffset;
8117081196
u8 *piEnd;
81197
+ u8 **ppCell;
8117181198
VVA_ONLY( int nCellAtStart = b.nCell; )
8117281199
8117381200
/* Verify that all sibling pages are of the same "type" (table-leaf,
8117481201
** table-interior, index-leaf, or index-interior).
8117581202
*/
@@ -81201,27 +81228,29 @@
8120181228
rc = SQLITE_CORRUPT_PAGE(pOld);
8120281229
goto balance_cleanup;
8120381230
}
8120481231
limit = pOld->aiOvfl[0];
8120581232
for(j=0; j<limit; j++){
81206
- b.apCell[b.nCell] = aData + (maskPage & get2byteAligned(piCell));
81233
+ b.apCell[b.nCell+j] = aData + (maskPage & get2byteAligned(piCell));
8120781234
piCell += 2;
81208
- b.nCell++;
8120981235
}
81236
+ b.nCell += limit;
8121081237
for(k=0; k<pOld->nOverflow; k++){
8121181238
assert( k==0 || pOld->aiOvfl[k-1]+1==pOld->aiOvfl[k] );/* NOTE 1 */
8121281239
b.apCell[b.nCell] = pOld->apOvfl[k];
8121381240
b.nCell++;
8121481241
}
8121581242
}
8121681243
piEnd = aData + pOld->cellOffset + 2*pOld->nCell;
81244
+ /* Collect cell pointers before updating the cell count. */
81245
+ ppCell = &b.apCell[b.nCell];
8121781246
while( piCell<piEnd ){
81218
- assert( b.nCell<nMaxCells );
81219
- b.apCell[b.nCell] = aData + (maskPage & get2byteAligned(piCell));
81247
+ assert( ppCell<&b.apCell[nMaxCells] );
81248
+ *ppCell++ = aData + (maskPage & get2byteAligned(piCell));
8122081249
piCell += 2;
81221
- b.nCell++;
8122281250
}
81251
+ b.nCell = (int)(ppCell - b.apCell);
8122381252
assert( (b.nCell-nCellAtStart)==(pOld->nCell+pOld->nOverflow) );
8122481253
8122581254
cntOld[i] = b.nCell;
8122681255
if( i<nOld-1 && !leafData){
8122781256
u16 sz = (u16)szNew[i];
@@ -87092,10 +87121,11 @@
8709287121
zVal = &pExpr->u.zToken[2];
8709387122
nVal = sqlite3Strlen30(zVal)-1;
8709487123
assert( zVal[nVal]=='\'' );
8709587124
sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
8709687125
0, SQLITE_DYNAMIC);
87126
+ pVal->enc = enc;
8709787127
}
8709887128
#endif
8709987129
#ifdef SQLITE_ENABLE_STAT4
8710087130
else if( op==TK_FUNCTION && pCtx!=0 ){
8710187131
rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
@@ -87486,10 +87516,11 @@
8748687516
p->pParse = pParse;
8748787517
pParse->pVdbe = p;
8748887518
assert( pParse->aLabel==0 );
8748987519
assert( pParse->nLabel==0 );
8749087520
assert( p->nOpAlloc==0 );
87521
+ assert( pParse->szOpAlloc==0 );
8749187522
sqlite3VdbeAddOp2(p, OP_Init, 0, 1);
8749287523
return p;
8749387524
}
8749487525
8749587526
/*
@@ -87516,10 +87547,11 @@
8751687547
SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n, u8 prepFlags){
8751787548
if( p==0 ) return;
8751887549
p->prepFlags = prepFlags;
8751987550
if( (prepFlags & SQLITE_PREPARE_SAVESQL)==0 ){
8752087551
p->expmask = 0;
87552
+ p->smimask = 0;
8752187553
}
8752287554
assert( p->zSql==0 );
8752387555
p->zSql = sqlite3DbStrNDup(p->db, z, n);
8752487556
}
8752587557
@@ -87636,11 +87668,12 @@
8763687668
8763787669
assert( nOp<=(int)(1024/sizeof(Op)) );
8763887670
assert( nNew>=(v->nOpAlloc+nOp) );
8763987671
pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
8764087672
if( pNew ){
87641
- v->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
87673
+ p->szOpAlloc = sqlite3DbMallocSize(p->db, pNew);
87674
+ v->nOpAlloc = p->szOpAlloc/sizeof(Op);
8764287675
v->aOp = pNew;
8764387676
}
8764487677
return (pNew ? SQLITE_OK : SQLITE_NOMEM_BKPT);
8764587678
}
8764687679
@@ -90143,11 +90176,11 @@
9014390176
** of the prepared statement.
9014490177
*/
9014590178
n = ROUND8P(sizeof(Op)*p->nOp); /* Bytes of opcode memory used */
9014690179
x.pSpace = &((u8*)p->aOp)[n]; /* Unused opcode memory */
9014790180
assert( EIGHT_BYTE_ALIGNMENT(x.pSpace) );
90148
- x.nFree = ROUNDDOWN8((p->nOpAlloc-p->nOp)*sizeof(Op)); /* Bytes unused mem */
90181
+ x.nFree = ROUNDDOWN8(pParse->szOpAlloc - n); /* Bytes unused memory */
9014990182
assert( x.nFree>=0 );
9015090183
assert( EIGHT_BYTE_ALIGNMENT(&x.pSpace[x.nFree]) );
9015190184
9015290185
resolveP2Values(p, &nArg);
9015390186
p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
@@ -92794,14 +92827,16 @@
9279492827
assert( iVar>0 );
9279592828
assert( (v->db->flags & SQLITE_EnableQPSG)==0
9279692829
|| (v->db->mDbFlags & DBFLAG_InternalFunc)!=0 );
9279792830
9279892831
m = (iVar>=32) ? 0x80000000 : ((u32)1 << (iVar-1));
92799
- v->expmask |= m;
9280092832
if( bSmallint ){
92801
- v->smimask |= m;
92833
+ if( (v->expmask & m)==0 ) v->smimask |= m;
92834
+ }else{
92835
+ v->smimask &= ~m;
9280292836
}
92837
+ v->expmask |= m;
9280392838
9280492839
/* smimask is always a subset of expmask */
9280592840
assert( (v->smimask & v->expmask) == v->smimask );
9280692841
}
9280792842
@@ -94950,14 +94985,12 @@
9495094985
if( i>=(unsigned int)p->nVar ){
9495194986
sqlite3Error(p->db, SQLITE_RANGE);
9495294987
sqlite3_mutex_leave(p->db->mutex);
9495394988
return SQLITE_RANGE;
9495494989
}
94990
+
9495594991
pVar = &p->aVar[i];
94956
- sqlite3VdbeMemRelease(pVar);
94957
- pVar->flags = MEM_Null;
94958
- p->db->errCode = SQLITE_OK;
9495994992
9496094993
/* If the bit corresponding to this variable in Vdbe.expmask is set, then
9496194994
** binding a new value to this variable invalidates the current query plan.
9496294995
**
9496394996
** IMPLEMENTATION-OF: R-57496-20354 If the specific value bound to a host
@@ -94967,15 +95000,24 @@
9496795000
** following any change to the bindings of that parameter.
9496895001
*/
9496995002
assert( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || p->expmask==0 );
9497095003
assert( (p->expmask & p->smimask)==p->smimask );
9497195004
if( p->expmask!=0 && (p->expmask & (i>=31 ? 0x80000000 : (u32)1<<i))!=0 ){
94972
- /* We might avoid a reprepare here if p->smimask is set and the old
94973
- ** value is an integer other than (0,1). But that is such a corner
94974
- ** case that it does not seem worth the extra code to implement. */
94975
- p->expired = 1;
95005
+ /* If the p->smimask bit is also set, then only expire the statement if
95006
+ ** the value being clobbered was integer value 0 or 1. */
95007
+ if( (p->smimask==0)
95008
+ || (p->smimask & (i>=31 ? 0x80000000 : (u32)1<<i))==0
95009
+ || ((pVar->flags & MEM_Int)!=0 && pVar->u.i>=0 && pVar->u.i<=1)
95010
+ ){
95011
+ p->expired = 1;
95012
+ }
9497695013
}
95014
+
95015
+ sqlite3VdbeMemRelease(pVar);
95016
+ pVar->flags = MEM_Null;
95017
+ p->db->errCode = SQLITE_OK;
95018
+
9497795019
return SQLITE_OK;
9497895020
}
9497995021
9498095022
/*
9498195023
** Bind a text or BLOB value.
@@ -95099,12 +95141,12 @@
9509995141
int sm1 = (pVar->flags & MEM_Int)!=0 && pVar->u.i>=0 && pVar->u.i<=1;
9510095142
int sm2 = iValue>=0 && iValue<=1;
9510195143
if( sm1!=sm2 ){
9510295144
p->expired = 1;
9510395145
}
95104
- }else if( (pVar->flags & MEM_Int)==0 || pVar->u.i!=iValue ){
95105
- /* Always expire if the value really is changing */
95146
+ }else if( (pVar->flags & MEM_Int)==0 || iValue!=pVar->u.i ){
95147
+ /* Always expire if the smimask bit is clear */
9510695148
p->expired = 1;
9510795149
}
9510895150
}
9510995151
}
9511095152
sqlite3VdbeMemSetInt64(pVar, iValue);
@@ -98405,11 +98447,22 @@
9840598447
** raise an SQLITE_MISMATCH exception.
9840698448
*/
9840798449
case OP_MustBeInt: { /* jump0, in1 */
9840898450
pIn1 = &aMem[pOp->p1];
9840998451
if( (pIn1->flags & MEM_Int)==0 ){
98410
- applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
98452
+ if( (pIn1->flags & MEM_Real)!=0 ){
98453
+ sqlite3_int64 ix;
98454
+ if( pIn1->u.r>=-9223372036854775808.0
98455
+ && pIn1->u.r<+9223372036854775808.0
98456
+ && (double)(ix = sqlite3RealToI64(pIn1->u.r))==pIn1->u.r
98457
+ ){
98458
+ pIn1->u.i = ix;
98459
+ MemSetTypeFlag(pIn1, MEM_Int);
98460
+ }
98461
+ }else{
98462
+ applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
98463
+ }
9841198464
if( (pIn1->flags & MEM_Int)==0 ){
9841298465
VdbeBranchTaken(1, 2);
9841398466
if( pOp->p2==0 ){
9841498467
rc = SQLITE_MISMATCH;
9841598468
goto abort_due_to_error;
@@ -100995,10 +101048,13 @@
100995101048
assert( !sqlite3BtreeClosesWithCursor(pCx->ub.pBtx, pCx->uc.pCursor) );
100996101049
sqlite3BtreeClose(pCx->ub.pBtx);
100997101050
p->apCsr[pOp->p1] = 0; /* Not required; helps with static analysis */
100998101051
}else{
100999101052
assert( sqlite3BtreeClosesWithCursor(pCx->ub.pBtx, pCx->uc.pCursor) );
101053
+ if( pOp->opcode==OP_OpenAutoindex ){
101054
+ sqlite3BtreeCursorHintFlags(pCx->uc.pCursor, BTREE_SEEK_EQ);
101055
+ }
101000101056
}
101001101057
}
101002101058
}
101003101059
if( rc ) goto abort_due_to_error;
101004101060
pCx->nullRow = 1;
@@ -101129,15 +101185,26 @@
101129101185
** greater than or equal to the key and P2 is not zero, then jump to P2.
101130101186
**
101131101187
** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
101132101188
** opcode will either land on a record that exactly matches the key, or
101133101189
** else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ,
101134
-** this opcode must be followed by an IdxLE opcode with the same arguments.
101190
+** this opcode must be followed by an IdxLE opcode with the same arguments,
101191
+** except that the P2 argument (the jump destination) can be different.
101135101192
** The IdxGT opcode will be skipped if this opcode succeeds, but the
101136101193
** IdxGT opcode will be used on subsequent loop iterations. The
101137101194
** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
101138101195
** is an equality search.
101196
+**
101197
+** The P2 of the IdxLE might be less than the P2 of this opcode. The P2
101198
+** of the IdxLE will be the location to jump to if there are one or more
101199
+** matching rows and is the location to continue with the next row of the
101200
+** first containing loop. The P2 of this opcode will be the location to
101201
+** jump to if zero rows of cursor P1 match the key, and that will be the
101202
+** continuation address of the first outer loop that contributes to the
101203
+** key. The P2 of this opcode might be greater than the P2 of the
101204
+** subsequent IdxLE if the first outer loop that influences the key is
101205
+** outer to the immediately next outer loop.
101139101206
**
101140101207
** This opcode leaves the cursor configured to move in forward order,
101141101208
** from the beginning toward the end. In other words, the cursor is
101142101209
** configured to use Next, not Prev.
101143101210
**
@@ -101196,15 +101263,26 @@
101196101263
** configured to use Prev, not Next.
101197101264
**
101198101265
** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
101199101266
** opcode will either land on a record that exactly matches the key, or
101200101267
** else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ,
101201
-** this opcode must be followed by an IdxLE opcode with the same arguments.
101268
+** this opcode must be followed by an IdxGE opcode with the same arguments
101269
+** except the P2 of IdxGE might be less than the P2 of this opcode.
101202101270
** The IdxGE opcode will be skipped if this opcode succeeds, but the
101203101271
** IdxGE opcode will be used on subsequent loop iterations. The
101204101272
** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
101205101273
** is an equality search.
101274
+**
101275
+** The P2 of the IdxGE might be less than the P2 of this opcode. The P2
101276
+** of the IdxGE will be the location to jump to if there are one or more
101277
+** matching rows and is the location to continue with the next row of the
101278
+** first containing loop. The P2 of this opcode will be the location to
101279
+** jump to if no rows of cursor P1 match the key, and that will be the
101280
+** continuation address of the first outer loop that contributes to the
101281
+** key. The P2 of this opcode might be greater than the P2 of the
101282
+** subsequent IdxLE if the first outer loop that influences the key is
101283
+** outer to the immediately next outer loop.
101206101284
**
101207101285
** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
101208101286
*/
101209101287
case OP_SeekLT: /* jump0, in3, group, ncycle */
101210101288
case OP_SeekLE: /* jump0, in3, group, ncycle */
@@ -101310,11 +101388,13 @@
101310101388
assert( pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE );
101311101389
assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT );
101312101390
assert( pOp->opcode==OP_SeekGE || pOp[1].opcode==OP_IdxLT );
101313101391
assert( pOp->opcode==OP_SeekLE || pOp[1].opcode==OP_IdxGT );
101314101392
assert( pOp[1].p1==pOp[0].p1 );
101315
- assert( pOp[1].p2==pOp[0].p2 );
101393
+ assert( pOp[1].p2<=pOp[0].p2 );
101394
+ testcase( pOp->opcode==OP_SeekGE && pOp[1].p2<pOp[0].p2 );
101395
+ testcase( pOp->opcode==OP_SeekLE && pOp[1].p2<pOp[0].p2 );
101316101396
assert( pOp[1].p3==pOp[0].p3 );
101317101397
assert( pOp[1].p4.i==pOp[0].p4.i );
101318101398
}
101319101399
101320101400
nField = pOp->p4.i;
@@ -113193,15 +113273,14 @@
113193113273
char aff;
113194113274
assert( pExpr->op==TK_EQ || pExpr->op==TK_IN || pExpr->op==TK_LT ||
113195113275
pExpr->op==TK_GT || pExpr->op==TK_GE || pExpr->op==TK_LE ||
113196113276
pExpr->op==TK_NE || pExpr->op==TK_IS || pExpr->op==TK_ISNOT );
113197113277
assert( pExpr->pLeft );
113278
+ assert( !ExprUseXSelect(pExpr) );
113198113279
aff = sqlite3ExprAffinity(pExpr->pLeft);
113199113280
if( pExpr->pRight ){
113200113281
aff = sqlite3CompareAffinity(pExpr->pRight, aff);
113201
- }else if( ExprUseXSelect(pExpr) ){
113202
- aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff);
113203113282
}else if( aff==0 ){
113204113283
aff = SQLITE_AFF_BLOB;
113205113284
}
113206113285
return aff;
113207113286
}
@@ -115560,11 +115639,11 @@
115560115639
** table other than iCur.
115561115640
**
115562115641
** Consider uncorrelated subqueries to be constants if the bAllowSubq
115563115642
** parameter is true.
115564115643
*/
115565
-static int sqlite3ExprIsTableConstant(Expr *p, int iCur, int bAllowSubq){
115644
+SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur, int bAllowSubq){
115566115645
Walker w;
115567115646
w.eCode = 3;
115568115647
w.pParse = 0;
115569115648
w.xExprCallback = exprNodeIsConstant;
115570115649
if( bAllowSubq ){
@@ -115740,11 +115819,10 @@
115740115819
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){
115741115820
assert( isInit==0 || isInit==1 );
115742115821
return exprIsConst(0, p, 4+isInit);
115743115822
}
115744115823
115745
-#ifdef SQLITE_ENABLE_CURSOR_HINTS
115746115824
/*
115747115825
** Walk an expression tree. Return 1 if the expression contains a
115748115826
** subquery of some kind. Return 0 if there are no subqueries.
115749115827
*/
115750115828
SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr *p){
@@ -115756,11 +115834,10 @@
115756115834
w.xSelectCallback2 = sqlite3SelectWalkAssert2;
115757115835
#endif
115758115836
sqlite3WalkExpr(&w, p);
115759115837
return w.eCode==0;
115760115838
}
115761
-#endif
115762115839
115763115840
/*
115764115841
** If the expression p codes a constant integer between 0 and 0x7fffffff,
115765115842
** then return 1 and put the value of the integer in *pValue. If the
115766115843
** expression is not an integer or if it is an integer that is out side
@@ -115775,14 +115852,11 @@
115775115852
**
115776115853
** If pParse is not NULL and expression p is a variable, then the variable
115777115854
** is marked so as to cause the statement to be reprepared each time a new
115778115855
** value is bound to it. Except, if parameter bRSI is true, then the statement
115779115856
** will only be reprepared if the rebind changes the value to or from a
115780
-** "small integer" (either 0 or 1). Note that if p is a variable then
115781
-** reprepare is always enabled for that variable, regardless of its current
115782
-** binding. The RSI is only enabled if the current binding is a small
115783
-** integer. "RSI" stands for "Reprepare Small Integers".
115857
+** "small integer" (either 0 or 1).
115784115858
*/
115785115859
SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr *p, int *pValue, Parse *pParse, int bRSI){
115786115860
int iSign = 1; /* Either +1 or -1. */
115787115861
while( 1/*exit-by-break*/ ){
115788115862
if( NEVER(p==0) ) return 0;
@@ -115801,11 +115875,10 @@
115801115875
pParse = 0;
115802115876
continue;
115803115877
}
115804115878
if( p->op==TK_VARIABLE && pParse!=0 ){
115805115879
sqlite3_value *pVal; /* The variable */
115806
- int isSmall = 0; /* Only reprepare if change to/from small integer */
115807115880
int rc = 0; /* 1 if successful, 0 if failed */
115808115881
assert( iSign==1 );
115809115882
if( NEVER(pParse->pVdbe==0) ) break;
115810115883
if( (pParse->db->flags & SQLITE_EnableQPSG)!=0 ) break;
115811115884
pVal = sqlite3VdbeGetBoundValue(pParse->pReprepare, p->iColumn,
@@ -115815,18 +115888,15 @@
115815115888
if( sqlite3_value_type(pVal)==SQLITE_INTEGER
115816115889
&& (vv = sqlite3_value_int64(pVal))>=0
115817115890
&& vv<=0x7fffffff
115818115891
){
115819115892
*pValue = (int)vv;
115820
- if( bRSI ){
115821
- isSmall = vv<=1;
115822
- }
115823115893
rc = 1;
115824115894
}
115825115895
sqlite3ValueFree(pVal);
115826115896
}
115827
- sqlite3VdbeReprepareOnBind(pParse->pVdbe, p->iColumn, isSmall);
115897
+ sqlite3VdbeReprepareOnBind(pParse->pVdbe, p->iColumn, bRSI);
115828115898
return rc;
115829115899
}
115830115900
break;
115831115901
}
115832115902
return 0;
@@ -116862,10 +116932,16 @@
116862116932
ExprSetVVAProperty(pExpr, EP_NoReduce);
116863116933
if( addrOnce ){
116864116934
sqlite3VdbeJumpHere(v, addrOnce);
116865116935
}
116866116936
sqlite3VdbeScanStatusRange(v, addrExplain, addrExplain, -1);
116937
+
116938
+ if( dest.eDest==SRT_Mem
116939
+ && sqlite3ExprCanReturnSubtype(pParse, pSel->pEList->a[0].pExpr)
116940
+ ){
116941
+ sqlite3VdbeAddOp1(v, OP_ClrSubtype, rReg);
116942
+ }
116867116943
116868116944
/* Subroutine return */
116869116945
assert( ExprUseYSub(pExpr) );
116870116946
assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn
116871116947
|| pParse->nErr );
@@ -117082,11 +117158,10 @@
117082117158
rLhs = sqlite3GetTempRange(pParse, nVector);
117083117159
for(i=0; i<nVector; i++){
117084117160
testcase( aiMap[i]!=i );
117085117161
sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0);
117086117162
}
117087
- sqlite3ReleaseTempReg(pParse, rLhsOrig);
117088117163
}
117089117164
}
117090117165
117091117166
117092117167
/* Step 2: Check to see if the LHS contains any NULL columns. If the
@@ -117618,11 +117693,11 @@
117618117693
** pExpr is able to return a subtype, set pWalker->eCode and abort
117619117694
** the search. If pExpr can never return a subtype, prune search.
117620117695
**
117621117696
** The only expressions that can return a subtype are:
117622117697
**
117623
-** 1. A function
117698
+** 1. A function, including an aggregate function
117624117699
** 2. The no-op "+" operator
117625117700
** 3. A CASE...END expression
117626117701
** 4. A CAST() expression
117627117702
** 5. A "expr COLLATE colseq" expression.
117628117703
**
@@ -117643,18 +117718,23 @@
117643117718
if( pExpr->op==TK_CASE || pExpr->op==TK_UPLUS
117644117719
|| pExpr->op==TK_COLLATE || pExpr->op==TK_CAST
117645117720
){
117646117721
return WRC_Continue;
117647117722
}
117648
- if( pExpr->op!=TK_FUNCTION ){
117723
+ if( pExpr->op!=TK_FUNCTION && pExpr->op!=TK_AGG_FUNCTION ){
117649117724
return WRC_Prune;
117650117725
}
117651117726
assert( ExprUseXList(pExpr) );
117652117727
db = pWalker->pParse->db;
117653117728
n = pExpr->x.pList ? pExpr->x.pList->nExpr : 0;
117654117729
pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
117655
- if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
117730
+#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
117731
+ if( pDef==0 ) return WRC_Continue;
117732
+#else
117733
+ assert( pDef!=0 );
117734
+#endif
117735
+ if( (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
117656117736
pWalker->eCode = 1;
117657117737
return WRC_Abort;
117658117738
}
117659117739
return WRC_Continue;
117660117740
}
@@ -117720,14 +117800,20 @@
117720117800
continue;
117721117801
}
117722117802
117723117803
v = pParse->pVdbe;
117724117804
assert( v!=0 );
117725
- if( p->bMaybeNullRow ){
117726
- /* If the index is on a NULL row due to an outer join, then we
117727
- ** cannot extract the value from the index. The value must be
117728
- ** computed using the original expression. */
117805
+ if( p->bMaybeNullRow || sqlite3ExprIsConstant(pParse, pExpr) ){
117806
+ /* The value of pExpr should be computed from the original expression,
117807
+ ** not from the index, if either:
117808
+ **
117809
+ ** 1. The index might be on a NULL row due to an outer join.
117810
+ **
117811
+ ** 2. The expression is a constant. This prevents an attempt to
117812
+ ** use an index value outside of the loop that positions the
117813
+ ** index. (Bug 2026-10-11T19:26:40Z).
117814
+ */
117729117815
int addr = sqlite3VdbeCurrentAddr(v);
117730117816
sqlite3VdbeAddOp3(v, OP_IfNullRow, p->iIdxCur, addr+3, target);
117731117817
VdbeCoverage(v);
117732117818
sqlite3VdbeAddOp3(v, OP_Column, p->iIdxCur, p->iIdxCol, target);
117733117819
VdbeComment((v, "%s expr-column %d", p->zIdxName, p->iIdxCol));
@@ -120450,11 +120536,11 @@
120450120536
assert( pOBList->nExpr>0 );
120451120537
assert( pItem->bOBUnique==0 );
120452120538
if( pOBList->nExpr==1
120453120539
&& nArg==1
120454120540
&& sqlite3ExprCompare(0,pOBList->a[0].pExpr,
120455
- pExpr->x.pList->a[0].pExpr,0)==0
120541
+ pExpr->x.pList->a[0].pExpr,-1)==0
120456120542
){
120457120543
pItem->bOBPayload = 0;
120458120544
pItem->bOBUnique = ExprHasProperty(pExpr, EP_Distinct);
120459120545
}else{
120460120546
pItem->bOBPayload = 1;
@@ -120538,10 +120624,17 @@
120538120624
** Deallocate a register, making available for reuse for some other
120539120625
** purpose.
120540120626
*/
120541120627
SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){
120542120628
if( iReg ){
120629
+#ifdef SQLITE_DEBUG
120630
+ /* Verify that iReg is not already on the unused register list */
120631
+ int kk;
120632
+ for(kk=0; kk<pParse->nTempReg; kk++){
120633
+ assert( pParse->aTempReg[kk]!=iReg );
120634
+ }
120635
+#endif
120543120636
sqlite3VdbeReleaseRegisters(pParse, iReg, 1, 0, 0);
120544120637
if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){
120545120638
pParse->aTempReg[pParse->nTempReg++] = iReg;
120546120639
}
120547120640
}
@@ -127356,10 +127449,11 @@
127356127449
127357127450
if( db->nSchemaLock==0 ){
127358127451
for(i=0; i<db->nDb; i++){
127359127452
if( DbHasProperty(db, i, DB_ResetWanted) ){
127360127453
sqlite3SchemaClear(db->aDb[i].pSchema);
127454
+ db->mDbFlags &= ~DBFLAG_SchemaKnownOk;
127361127455
}
127362127456
}
127363127457
}
127364127458
}
127365127459
@@ -134158,19 +134252,22 @@
134158134252
}
134159134253
nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
134160134254
regBase = sqlite3GetTempRange(pParse, nCol);
134161134255
if( pPrior && (regBase!=regPrior || pPrior->pPartIdxWhere) ) pPrior = 0;
134162134256
for(j=0; j<nCol; j++){
134257
+ int iTabCol;
134163134258
if( pPrior
134164134259
&& pPrior->aiColumn[j]==pIdx->aiColumn[j]
134165134260
&& pPrior->aiColumn[j]!=XN_EXPR
134166134261
){
134167134262
/* This column was already computed by the previous index */
134168134263
continue;
134169134264
}
134170134265
sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iDataCur, j, regBase+j);
134171
- if( pIdx->aiColumn[j]>=0 ){
134266
+ if( (iTabCol = pIdx->aiColumn[j])>=0
134267
+ && (pIdx->pTable->aCol[iTabCol].colFlags & COLFLAG_VIRTUAL)==0
134268
+ ){
134172134269
/* If the column affinity is REAL but the number is an integer, then it
134173134270
** might be stored in the table as an integer (using a compact
134174134271
** representation) then converted to REAL by an OP_RealAffinity opcode.
134175134272
** But we are getting ready to store this value back into an index, where
134176134273
** it should be converted by to INTEGER again. So omit the
@@ -134530,10 +134627,18 @@
134530134627
str.printfFlags = SQLITE_PRINTF_SQLFUNC;
134531134628
sqlite3_str_appendf(&str, zFormat, &x);
134532134629
sqlite3_result_str(context, &str, SQLITE_XFER);
134533134630
}
134534134631
}
134632
+
134633
+/* Return true if any of the eight bytes in word is NUL or non-ASCII. */
134634
+static SQLITE_INLINE int containsNulOrNonAscii(u64 word){
134635
+ const u64 byteOnes = UINT64_C(0x0101010101010101);
134636
+ const u64 byteHighBits = UINT64_C(0x8080808080808080);
134637
+ /* NUL causes a borrow into a high bit; non-ASCII already has one set. */
134638
+ return ((word | (word - byteOnes)) & byteHighBits)!=0;
134639
+}
134535134640
134536134641
/*
134537134642
** Implementation of the substr() function.
134538134643
**
134539134644
** substr(x,p1,p2) returns p2 characters of x[] beginning with p1.
@@ -134614,10 +134719,24 @@
134614134719
}
134615134720
p1 -= p2;
134616134721
}
134617134722
assert( p1>=0 && p2>=0 );
134618134723
if( p0type!=SQLITE_BLOB ){
134724
+ if( p1>=8 ){
134725
+ /* Skip 8 characters at a time while all 8 bytes are in 0x01..0x7f */
134726
+ const unsigned char *zEnd = z + sqlite3_value_bytes(argv[0]);
134727
+ while( p1>=8 && zEnd-z>=8 ){
134728
+ u64 word;
134729
+ memcpy(&word, z, sizeof(word));
134730
+ /* Handle NUL and UTF-8 with the scalar loop below. */
134731
+ if( containsNulOrNonAscii(word) ){
134732
+ break;
134733
+ }
134734
+ z += 8;
134735
+ p1 -= 8;
134736
+ }
134737
+ }
134619134738
for( ; p1>0; p1--){
134620134739
/* vvvvvv---- See tag-20260418-01 */
134621134740
if( (u8)(z[0]-1)<(0x80-1) ){
134622134741
z++;
134623134742
}else if( z[0]==0 ){
@@ -134991,22 +135110,33 @@
134991135110
** c or cx.
134992135111
*/
134993135112
if( c<0x80 ){
134994135113
char zStop[3];
134995135114
int bMatch;
135115
+ /* If the next pattern character is an ordinary ASCII character,
135116
+ ** then a candidate position can only match if the next input
135117
+ ** character is nx or ny. Check that inline, to avoid most of the
135118
+ ** recursive calls. nx==0 disables this check. */
135119
+ u8 nx = zPattern[0], ny = nx;
135120
+ if( nx>=0x80 || nx==matchAll || nx==matchOne || nx==matchOther ){
135121
+ nx = 0;
135122
+ }
134996135123
if( noCase ){
134997135124
zStop[0] = sqlite3Toupper(c);
134998135125
zStop[1] = sqlite3Tolower(c);
134999135126
zStop[2] = 0;
135127
+ nx = sqlite3Toupper(nx);
135128
+ ny = sqlite3Tolower(ny);
135000135129
}else{
135001135130
zStop[0] = c;
135002135131
zStop[1] = 0;
135003135132
}
135004135133
while(1){
135005135134
zString += strcspn((const char*)zString, zStop);
135006135135
if( zString[0]==0 ) break;
135007135136
zString++;
135137
+ if( nx && zString[0]!=nx && zString[0]!=ny ) continue;
135008135138
bMatch = patternCompare(zPattern,zString,pInfo,matchOther);
135009135139
if( bMatch!=SQLITE_NOMATCH ) return bMatch;
135010135140
}
135011135141
}else{
135012135142
int bMatch;
@@ -135280,18 +135410,24 @@
135280135410
static void compileoptiongetFunc(
135281135411
sqlite3_context *context,
135282135412
int argc,
135283135413
sqlite3_value **argv
135284135414
){
135285
- int n;
135415
+ i64 n;
135416
+ const char *zRes;
135286135417
assert( argc==1 );
135287135418
UNUSED_PARAMETER(argc);
135288135419
/* IMP: R-04922-24076 The sqlite_compileoption_get() SQL function
135289135420
** is a wrapper around the sqlite3_compileoption_get() C/C++ function.
135290135421
*/
135291
- n = sqlite3_value_int(argv[0]);
135292
- sqlite3_result_text(context, sqlite3_compileoption_get(n), -1, SQLITE_STATIC);
135422
+ n = sqlite3_value_int64(argv[0]);
135423
+ /* Use a negative lower bound to assist testing of the
135424
+ ** sqlite3_compileoption_get() C-language interface and its handling
135425
+ ** of negative inputs.
135426
+ ** vvvvv */
135427
+ zRes = (n>=(-10) && n<10000) ? sqlite3_compileoption_get((int)n) : 0;
135428
+ sqlite3_result_text(context, zRes, -1, SQLITE_STATIC);
135293135429
}
135294135430
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
135295135431
135296135432
/* Array for converting from half-bytes (nybbles) into ASCII hex
135297135433
** digits. */
@@ -153606,11 +153742,13 @@
153606153742
static int renumberCursorsCb(Walker *pWalker, Expr *pExpr){
153607153743
int op = pExpr->op;
153608153744
if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){
153609153745
renumberCursorDoMapping(pWalker, &pExpr->iTable);
153610153746
}
153611
- if( ExprHasProperty(pExpr, EP_OuterON) ){
153747
+ if( ExprHasProperty(pExpr, (EP_OuterON|EP_InnerON)) ){
153748
+ testcase( ExprHasProperty(pExpr, EP_OuterON) );
153749
+ testcase( ExprHasProperty(pExpr, EP_InnerON) );
153612153750
renumberCursorDoMapping(pWalker, &pExpr->w.iJoin);
153613153751
}
153614153752
return WRC_Continue;
153615153753
}
153616153754
@@ -154486,11 +154624,11 @@
154486154624
/*
154487154625
** The WHERE-clause constant propagation optimization.
154488154626
**
154489154627
** If the WHERE clause contains terms of the form COLUMN=CONSTANT or
154490154628
** CONSTANT=COLUMN that are top-level AND-connected terms that are not
154491
-** part of a ON clause from a LEFT JOIN, then throughout the query
154629
+** part of a ON clause from an OUTER JOIN, then throughout the query
154492154630
** replace all other occurrences of COLUMN with CONSTANT.
154493154631
**
154494154632
** For example, the query:
154495154633
**
154496154634
** SELECT * FROM t1, t2, t3 WHERE t1.a=39 AND t2.b=t1.a AND t3.c=t2.b
@@ -164036,10 +164174,11 @@
164036164174
int addrBrk; /* Jump here to break out of the loop */
164037164175
int addrHalt; /* Abort the query due to empty table or similar */
164038164176
int addrNxt; /* Jump here to start the next IN combination */
164039164177
int addrSkip; /* Jump here for next iteration of skip-scan */
164040164178
int addrCont; /* Jump here to continue with the next loop cycle */
164179
+ int addrDeleteCont; /* Delete auto-index entry then same as addrCont */
164041164180
int addrFirst; /* First instruction of interior of the loop */
164042164181
int addrBody; /* Beginning of the body of this loop */
164043164182
int regBignull; /* big-null flag reg. True if a NULL-scan is needed */
164044164183
int addrBignull; /* Jump here for next part of big-null scan */
164045164184
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
@@ -166119,10 +166258,131 @@
166119166258
}
166120166259
}
166121166260
}
166122166261
return 1;
166123166262
}
166263
+
166264
+/*
166265
+** Find the best address for an inner loop to jump to if its join
166266
+** constraint matches no rows.
166267
+**
166268
+** This is an optimization. The default behavior is to continue with
166269
+** the inner-most of the outer loops. But if the join constraint is not
166270
+** influenced by the inner-most outer loop, we might as well skip that
166271
+** loop too, and continue with the second inner-most outer loop. And
166272
+** so forth through subsequent outer loops.
166273
+**
166274
+** Return 0 to use the default behavior (continue with the inner-most
166275
+** outer loop. Or return an optimized address to jump to instead if
166276
+** we can do better.
166277
+**
166278
+** Conditions for returning non-zero:
166279
+**
166280
+** 1. The SQLITE_JoinMiss optimization must be enabled.
166281
+**
166282
+** 2. The iLevel loop must have at least two outer loops, otherwise
166283
+** this optimization is pointless.
166284
+**
166285
+** 3. We are not attempting to do one-pass
166286
+**
166287
+** 4. The join constraints may not contain subqueries
166288
+**
166289
+** If the inner-most outer loop that influences iLevel is also the
166290
+** only loop that influences iLevel, and if that loop uses an
166291
+** automatic index, then also arrange to delete the currently used
166292
+** entry from that automatic index, since we know that it can never
166293
+** be successful.
166294
+**
166295
+** This optimization inspired by the paper: "TreeTracker Join: Simple,
166296
+** Optimal, Fast" by Hu, Wang, and Miranker, 2025.
166297
+*/
166298
+static int findNoMatchContinuation(
166299
+ WhereInfo *pWInfo, /* WHERE clause */
166300
+ int iLevel /* Which loop we are talking about */
166301
+){
166302
+ WhereLoop *pLoop; /* Description of this loop */
166303
+ WhereLevel *pParent; /* Controlling parent loop */
166304
+ SrcList *pTabList; /* Complete FROM clause */
166305
+ Bitmask mKey; /* Mask of dependent tables */
166306
+ int iParent; /* Inner-most loop affecting the key to iLevel */
166307
+ int i; /* Loop counter */
166308
+
166309
+ if( iLevel<2 ){
166310
+ /* If there are less than two outer loops, this optimization is no help */
166311
+ return 0;
166312
+ }
166313
+
166314
+ /* The OP_SeekGE and OP_SeekLE opcodes only work right for this
166315
+ ** optimization on a pure equality constraint, so skip the optimization
166316
+ ** for anything else.
166317
+ */
166318
+ pLoop = pWInfo->a[iLevel].pWLoop;
166319
+ if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=WHERE_COLUMN_EQ ) return 0;
166320
+ if( pLoop->wsFlags & WHERE_SKIPSCAN ) return 0;
166321
+ if( pLoop->wsFlags & WHERE_BIGNULL_SORT ) return 0;
166322
+ assert( (pLoop->wsFlags & (WHERE_VIRTUALTABLE|WHERE_MULTI_OR))==0 );
166323
+ assert( pLoop->u.btree.nEq>0 );
166324
+
166325
+ /* Find a mask of all outer tables that influence the key. At the same
166326
+ ** time, check to see if any keys values are computed from subqueries and
166327
+ ** fail out (return 0) if there are any. */
166328
+ mKey = 0;
166329
+ for(i=0; i<pLoop->nLTerm; i++){
166330
+ if( sqlite3ExprContainsSubquery(pLoop->aLTerm[i]->pExpr) ){
166331
+ return 0;
166332
+ }
166333
+ mKey |= pLoop->aLTerm[i]->prereqRight;
166334
+ }
166335
+
166336
+ /* Look back through outer loops. Find the inner-most outer loop
166337
+ ** that influences the key. Make iParent be the index of that inner-most
166338
+ ** outer loop.
166339
+ */
166340
+ pTabList = pWInfo->pTabList;
166341
+ iParent = iLevel-1;
166342
+ while( iParent>0 && (pWInfo->a[iParent].pWLoop->maskSelf & mKey)==0 ){
166343
+ iParent--;
166344
+ }
166345
+ assert( iParent>=0 && iParent<=iLevel );
166346
+
166347
+ /* Everything needs to be an INNER join. Fail if there are any
166348
+ ** OUTER joins in between iParent and iLevel. */
166349
+ for(i=iParent; i<=iLevel; i++){
166350
+ if( pTabList->a[pWInfo->a[i].iFrom].fg.jointype & JT_OUTER ) return 0;
166351
+ }
166352
+
166353
+ /* If we reach this point, that means the conditions of the optimization
166354
+ ** have been met. Even so, disallow the optimization if it is disabled.
166355
+ */
166356
+ if( OptimizationDisabled(pWInfo->pParse->db, SQLITE_JoinMiss) ){
166357
+ return 0;
166358
+ }
166359
+
166360
+ /* If the inner-most outer loop that influences the key for iLevel
166361
+ ** is controlled by an automatic index and if the automatic index is
166362
+ ** the only outer loop that influences the key, then arrange to delete
166363
+ ** the automatic index entry if there is no match on the key.
166364
+ */
166365
+ pParent = &pWInfo->a[iParent];
166366
+ if( (pParent->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0
166367
+ && (mKey & (mKey-1))==0
166368
+ ){
166369
+ for(i=0; i<pLoop->nLTerm; i++){
166370
+ Expr *pX = pLoop->aLTerm[i]->pExpr;
166371
+ if( !sqlite3ExprIsTableConstant(pX->pRight,pParent->iTabCur,0) ) break;
166372
+ }
166373
+ if( i==pLoop->nLTerm ){
166374
+ if( pParent->addrDeleteCont==0 ){
166375
+ pParent->addrDeleteCont = sqlite3VdbeMakeLabel(pWInfo->pParse);
166376
+ }
166377
+ return pParent->addrDeleteCont;
166378
+ }
166379
+ }
166380
+
166381
+ testcase( iParent<iLevel-1 );
166382
+ return pParent->addrCont;
166383
+}
166124166384
166125166385
/*
166126166386
** Generate code for the start of the iLevel-th loop in the WHERE clause
166127166387
** implementation described by pWInfo.
166128166388
*/
@@ -166138,15 +166398,16 @@
166138166398
int iCur; /* The VDBE cursor for the table */
166139166399
int addrNxt; /* Where to jump to continue with the next IN case */
166140166400
int bRev; /* True if we need to scan in reverse order */
166141166401
WhereLoop *pLoop; /* The WhereLoop object being coded */
166142166402
WhereClause *pWC; /* Decomposition of the entire WHERE clause */
166143
- WhereTerm *pTerm; /* A WHERE clause term */
166144
- sqlite3 *db; /* Database connection */
166145
- SrcItem *pTabItem; /* FROM clause term being coded */
166146
- int addrBrk; /* Jump here to break out of the loop */
166147
- int addrCont; /* Jump here to continue with next cycle */
166403
+ WhereTerm *pTerm; /* A WHERE clause term */
166404
+ sqlite3 *db; /* Database connection */
166405
+ SrcItem *pTabItem; /* FROM clause term being coded */
166406
+ int addrBrk; /* Jump here to break out of the loop */
166407
+ int addrCont; /* Jump here to continue with next cycle */
166408
+ int addrMiss; /* addrCont enhanced for no-matching rows */
166148166409
int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
166149166410
int iReleaseReg = 0; /* Temp register to free before returning */
166150166411
Index *pIdx = 0; /* Index used by loop (if any) */
166151166412
int iLoop; /* Iteration of constraint generator loop */
166152166413
@@ -166187,10 +166448,11 @@
166187166448
** there are no IN operators in the constraints, the "addrNxt" label
166188166449
** is the same as "addrBrk".
166189166450
*/
166190166451
addrBrk = pLevel->addrNxt = pLevel->addrBrk;
166191166452
addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(pParse);
166453
+ addrMiss = findNoMatchContinuation(pWInfo, iLevel);
166192166454
166193166455
/* If this is the right table of a LEFT OUTER JOIN, allocate and
166194166456
** initialize a memory cell that records if this table matches any
166195166457
** row of the left table of the join.
166196166458
*/
@@ -166362,19 +166624,20 @@
166362166624
testcase( pTerm->wtFlags & TERM_VIRTUAL );
166363166625
iReleaseReg = ++pParse->nMem;
166364166626
iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
166365166627
if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg);
166366166628
addrNxt = pLevel->addrNxt;
166629
+ if( addrMiss==0 ) addrMiss = addrNxt;
166367166630
if( pLevel->regFilter ){
166368
- sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt);
166631
+ sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrMiss);
166369166632
VdbeCoverage(v);
166370
- sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrNxt,
166633
+ sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrMiss,
166371166634
iRowidReg, 1);
166372166635
VdbeCoverage(v);
166373166636
filterPullDown(pParse, pWInfo, iLevel, addrNxt, notReady);
166374166637
}
166375
- sqlite3VdbeAddOp3(v, OP_SeekRowid, iCur, addrNxt, iRowidReg);
166638
+ sqlite3VdbeAddOp3(v, OP_SeekRowid, iCur, addrMiss, iRowidReg);
166376166639
VdbeCoverage(v);
166377166640
pLevel->op = OP_Noop;
166378166641
}else if( (pLoop->wsFlags & WHERE_IPK)!=0
166379166642
&& (pLoop->wsFlags & WHERE_COLUMN_RANGE)!=0
166380166643
){
@@ -166573,13 +166836,10 @@
166573166836
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
166574166837
if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
166575166838
assert( pRangeStart!=0 ); /* LIKE opt constraints */
166576166839
assert( pRangeStart->wtFlags & TERM_LIKEOPT ); /* occur in pairs */
166577166840
pLevel->iLikeRepCntr = (u32)++pParse->nMem;
166578
- sqlite3VdbeAddOp2(v, OP_Integer, 1, (int)pLevel->iLikeRepCntr);
166579
- VdbeComment((v, "LIKE loop counter"));
166580
- pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
166581166841
/* iLikeRepCntr actually stores 2x the counter register number. The
166582166842
** bottom bit indicates whether the search order is ASC or DESC. */
166583166843
testcase( bRev );
166584166844
testcase( pIdx->aSortOrder[nEq]==SQLITE_SO_DESC );
166585166845
assert( (bRev & ~1)==0 );
@@ -166639,14 +166899,29 @@
166639166899
** starting at regBase.
166640166900
*/
166641166901
codeCursorHint(pTabItem, pWInfo, pLevel, pRangeEnd);
166642166902
regBase = codeAllEqualityTerms(pParse,pLevel,bRev,nExtraReg,&zStartAff);
166643166903
assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
166904
+#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
166905
+ if( pLevel->iLikeRepCntr ){
166906
+ /* The LIKE optimization loop must be the innermost of any IN(...)
166907
+ ** or skip-scan loops. Otherwise rows may not be visited in index
166908
+ ** order. This means it needs an addrNxt label for the same reason
166909
+ ** IN(...) scans do. */
166910
+ if( pLevel->addrNxt==pLevel->addrBrk ){
166911
+ pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
166912
+ }
166913
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, (int)(pLevel->iLikeRepCntr>>1));
166914
+ VdbeComment((v, "LIKE loop counter"));
166915
+ pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
166916
+ }
166917
+#endif
166644166918
if( zStartAff && nTop ){
166645166919
zEndAff = sqlite3DbStrDup(db, &zStartAff[nEq]);
166646166920
}
166647166921
addrNxt = (regBignull ? pLevel->addrBignull : pLevel->addrNxt);
166922
+ if( addrMiss==0 ) addrMiss = addrNxt;
166648166923
166649166924
testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
166650166925
testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
166651166926
testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
166652166927
testcase( pRangeEnd && (pRangeEnd->eOperator & WO_GE)!=0 );
@@ -166697,11 +166972,11 @@
166697166972
sqlite3VdbeAddOp2(v, OP_Integer, 1, regBignull);
166698166973
VdbeComment((v, "NULL-scan pass ctr"));
166699166974
}
166700166975
if( pLevel->regFilter ){
166701166976
assert( sqlite3WhereLoopBloomable(pLoop) );
166702
- sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrNxt,
166977
+ sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrMiss,
166703166978
regBase, nEq);
166704166979
VdbeCoverage(v);
166705166980
filterPullDown(pParse, pWInfo, iLevel, addrNxt, notReady);
166706166981
}
166707166982
@@ -166724,11 +166999,11 @@
166724166999
sqlite3VdbeChangeP2(v, addrSeekScan, sqlite3VdbeCurrentAddr(v)+1);
166725167000
addrSeekScan = 0;
166726167001
}
166727167002
VdbeCoverage(v);
166728167003
}
166729
- sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
167004
+ sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrMiss, regBase, nConstraint);
166730167005
VdbeCoverage(v);
166731167006
VdbeCoverageIf(v, op==OP_Rewind); testcase( op==OP_Rewind );
166732167007
VdbeCoverageIf(v, op==OP_Last); testcase( op==OP_Last );
166733167008
VdbeCoverageIf(v, op==OP_SeekGT); testcase( op==OP_SeekGT );
166734167009
VdbeCoverageIf(v, op==OP_SeekGE); testcase( op==OP_SeekGE );
@@ -169965,16 +170240,20 @@
169965170240
Expr *pX = pTerm->pExpr;
169966170241
Expr inexpr;
169967170242
169968170243
assert( pTerm->eOperator & WO_IN );
169969170244
169970
- if( sqlite3ExprIsVector(pX->pLeft) ){
169971
- int iField = pTerm->u.x.iField - 1;
170245
+ if( ExprUseXSelect(pX) ){
170246
+ int iField = 0;
169972170247
inexpr.flags = 0;
169973170248
inexpr.op = TK_EQ;
169974
- inexpr.pLeft = pX->pLeft->x.pList->a[iField].pExpr;
169975
- assert( ExprUseXSelect(pX) );
170249
+ if( sqlite3ExprIsVector(pX->pLeft) ){
170250
+ iField = pTerm->u.x.iField - 1;
170251
+ inexpr.pLeft = pX->pLeft->x.pList->a[iField].pExpr;
170252
+ }else{
170253
+ inexpr.pLeft = pX->pLeft;
170254
+ }
169976170255
inexpr.pRight = pX->x.pSelect->pEList->a[iField].pExpr;
169977170256
pX = &inexpr;
169978170257
}
169979170258
169980170259
if( sqlite3IndexAffinityOk(pX, idxaff) ){
@@ -173573,39 +173852,55 @@
173573173852
}
173574173853
173575173854
if( (pPart->op==TK_EQ || pPart->op==TK_IS) ){
173576173855
Expr *pLeft = pPart->pLeft;
173577173856
Expr *pRight = pPart->pRight;
173578
- u8 aff;
173857
+ Table *pLeftTab; /* Table of the left operand */
173858
+ Column *pLeftCol; /* Column of the left operand */
173859
+ u8 affRight, affLeft;
173579173860
173580173861
if( pLeft->op!=TK_COLUMN ) return;
173581173862
if( !sqlite3ExprIsConstant(0, pRight) ) return;
173582173863
if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pParse, pPart)) ) return;
173583173864
if( pLeft->iColumn<0 ) return;
173584
- aff = pIdx->pTable->aCol[pLeft->iColumn].affinity;
173585
- if( aff>=SQLITE_AFF_TEXT ){
173586
- if( pItem ){
173587
- sqlite3 *db = pParse->db;
173588
- IndexedExpr *p = (IndexedExpr*)sqlite3DbMallocRaw(db, sizeof(*p));
173589
- if( p ){
173590
- int bNullRow = (pItem->fg.jointype&(JT_LEFT|JT_LTORJ))!=0;
173591
- p->pExpr = sqlite3ExprDup(db, pRight, 0);
173592
- p->iDataCur = pItem->iCursor;
173593
- p->iIdxCur = iIdxCur;
173594
- p->iIdxCol = pLeft->iColumn;
173595
- p->bMaybeNullRow = bNullRow;
173596
- p->pIENext = pParse->pIdxPartExpr;
173597
- p->aff = aff;
173598
- pParse->pIdxPartExpr = p;
173599
- if( p->pIENext==0 ){
173600
- void *pArg = (void*)&pParse->pIdxPartExpr;
173601
- sqlite3ParserAddCleanup(pParse, whereIndexedExprCleanup, pArg);
173602
- }
173603
- }
173604
- }else if( pLeft->iColumn<(BMS-1) ){
173605
- *pMask &= ~((Bitmask)1 << pLeft->iColumn);
173606
- }
173865
+ pLeftTab = pIdx->pTable;
173866
+ pLeftCol = &pLeftTab->aCol[pLeft->iColumn];
173867
+ affLeft = pLeftCol->affinity;
173868
+ assert( SQLITE_AFF_BLOB<SQLITE_AFF_TEXT );
173869
+ if( affLeft<SQLITE_AFF_TEXT ) return;
173870
+ affRight = sqlite3ExprAffinity(pRight);
173871
+ if( affRight!=0 && affRight!=affLeft ) return;
173872
+ if( pItem ){
173873
+ sqlite3 *db = pParse->db;
173874
+ IndexedExpr *p = (IndexedExpr*)sqlite3DbMallocRaw(db, sizeof(*p));
173875
+ if( p ){
173876
+ int bNullRow = (pItem->fg.jointype&(JT_LEFT|JT_LTORJ))!=0;
173877
+ pRight = sqlite3ExprDup(db, pRight, 0);
173878
+ if( (pLeftTab->tabFlags & TF_Strict)!=0 ){
173879
+ Token t;
173880
+ t.z = sqlite3ColumnType(pLeftCol, 0);
173881
+ assert( t.z!=0 ); /* Because affLeft>=SQLITE_AFF_TEXT */
173882
+ t.n = (int)strlen(t.z);
173883
+ p->pExpr = sqlite3ExprAlloc(db, TK_CAST, &t, 1);
173884
+ sqlite3ExprAttachSubtrees(db, p->pExpr, pRight, 0);
173885
+ }else{
173886
+ p->pExpr = pRight;
173887
+ }
173888
+ p->iDataCur = pItem->iCursor;
173889
+ p->iIdxCur = iIdxCur;
173890
+ p->iIdxCol = pLeft->iColumn;
173891
+ p->bMaybeNullRow = bNullRow;
173892
+ p->pIENext = pParse->pIdxPartExpr;
173893
+ p->aff = affLeft;
173894
+ pParse->pIdxPartExpr = p;
173895
+ if( p->pIENext==0 ){
173896
+ void *pArg = (void*)&pParse->pIdxPartExpr;
173897
+ sqlite3ParserAddCleanup(pParse, whereIndexedExprCleanup, pArg);
173898
+ }
173899
+ }
173900
+ }else if( pLeft->iColumn<(BMS-1) ){
173901
+ *pMask &= ~((Bitmask)1 << pLeft->iColumn);
173607173902
}
173608173903
}
173609173904
}
173610173905
173611173906
@@ -173834,11 +174129,13 @@
173834174129
if( pProbe->isCovering ){
173835174130
m = 0;
173836174131
pNew->wsFlags = WHERE_IDX_ONLY | WHERE_INDEXED;
173837174132
}else{
173838174133
m = pSrc->colUsed & pProbe->colNotIdxed;
173839
- if( pProbe->pPartIdxWhere ){
174134
+ if( pProbe->pPartIdxWhere
174135
+ && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0
174136
+ ){
173840174137
wherePartIdxExpr(
173841174138
pWInfo->pParse, pProbe, pProbe->pPartIdxWhere, &m, 0, 0
173842174139
);
173843174140
}
173844174141
pNew->wsFlags = WHERE_INDEXED;
@@ -174718,17 +175015,17 @@
174718175015
** long as the subquery is materialized. If the subquery is
174719175016
** implemented as a co-routine, the sort orders must be in the same
174720175017
** direction because there is no way to run a co-routine backwards.
174721175018
*/
174722175019
static SQLITE_NOINLINE int wherePathMatchSubqueryOB(
174723
- WhereInfo *pWInfo, /* The WHERE clause */
174724175020
WhereLoop *pLoop, /* The nested loop term that is a subquery */
174725175021
int iLoop, /* Which level of the nested loop. 0==outermost */
174726175022
int iCur, /* Cursor used by the this loop */
174727175023
ExprList *pOrderBy, /* The ORDER BY clause on the whole query */
174728175024
Bitmask *pRevMask, /* When loops need to go in reverse order */
174729
- Bitmask *pOBSat /* Which terms of pOrderBy are satisfied so far */
175025
+ Bitmask *pOBSat, /* Which terms of pOrderBy are satisfied so far */
175026
+ u16 wctrlFlags /* WHERE_GROUPBY or _DISTINCTBY or _ORDERBY_LIMIT */
174730175027
){
174731175028
int iOB; /* Index into pOrderBy->a[] */
174732175029
int jSub; /* Index into pSubOB->a[] */
174733175030
u8 rev = 0; /* True if iOB and jSub sort in opposite directions */
174734175031
u8 revIdx = 0; /* Sort direction for jSub */
@@ -174742,11 +175039,11 @@
174742175039
if( pSubOB->a[jSub].u.x.iOrderByCol==0 ) break;
174743175040
pOBExpr = pOrderBy->a[iOB].pExpr;
174744175041
if( pOBExpr->op!=TK_COLUMN && pOBExpr->op!=TK_AGG_COLUMN ) break;
174745175042
if( pOBExpr->iTable!=iCur ) break;
174746175043
if( pOBExpr->iColumn!=pSubOB->a[jSub].u.x.iOrderByCol-1 ) break;
174747
- if( (pWInfo->wctrlFlags & WHERE_GROUPBY)==0 ){
175044
+ if( (wctrlFlags & WHERE_GROUPBY)==0 ){
174748175045
u8 sfOB = pOrderBy->a[iOB].fg.sortFlags; /* sortFlags for iOB */
174749175046
u8 sfSub = pSubOB->a[jSub].fg.sortFlags; /* sortFlags for jSub */
174750175047
if( (sfSub & KEYINFO_ORDER_BIGNULL) != (sfOB & KEYINFO_ORDER_BIGNULL) ){
174751175048
break;
174752175049
}
@@ -174924,20 +175221,20 @@
174924175221
174925175222
if( (pLoop->wsFlags & WHERE_ONEROW)==0 ){
174926175223
if( pLoop->wsFlags & WHERE_IPK ){
174927175224
if( pLoop->u.btree.pOrderBy
174928175225
&& OptimizationEnabled(db, SQLITE_OrderBySubq)
174929
- && wherePathMatchSubqueryOB(pWInfo,pLoop,iLoop,iCur,
174930
- pOrderBy,pRevMask, &obSat)
175226
+ && wherePathMatchSubqueryOB(pLoop,iLoop,iCur,
175227
+ pOrderBy,pRevMask, &obSat, wctrlFlags)
174931175228
){
174932175229
nColumn = 0;
174933175230
isOrderDistinct = 0;
174934175231
}else{
174935175232
nColumn = 1;
174936175233
}
174937175234
pIndex = 0;
174938
- nKeyCol = 0;
175235
+ nKeyCol = 1;
174939175236
}else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
174940175237
return 0;
174941175238
}else{
174942175239
nKeyCol = pIndex->nKeyCol;
174943175240
nColumn = pIndex->nColumn;
@@ -175074,11 +175371,18 @@
175074175371
if( rev ) *pRevMask |= MASKBIT(iLoop);
175075175372
revSet = 1;
175076175373
}
175077175374
}
175078175375
if( isMatch && (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL) ){
175079
- if( j==pLoop->u.btree.nEq ){
175376
+ if( j==pLoop->u.btree.nEq
175377
+ && (j<nKeyCol||HasRowid(pIndex->pTable)||!IsPrimaryKeyIndex(pIndex))
175378
+ ){
175379
+ /* If this is the PK of a WITHOUT ROWID table, do not use any
175380
+ ** field past nKeyCol for a NULLS LAST sort. If ALTER TABLE has
175381
+ ** been used to add columns to the table, this field may not
175382
+ ** be present in all records, which causes problems for the seeks
175383
+ ** used by NULLS LAST sorts. */
175080175384
pLoop->wsFlags |= WHERE_BIGNULL_SORT;
175081175385
}else{
175082175386
isMatch = 0;
175083175387
}
175084175388
}
@@ -175088,11 +175392,12 @@
175088175392
distinctColumns = 1;
175089175393
}
175090175394
obSat |= MASKBIT(i);
175091175395
}else{
175092175396
/* No match found */
175093
- if( j==0 || j<nKeyCol ){
175397
+ assert( nKeyCol>0 );
175398
+ if( j<nKeyCol ){
175094175399
testcase( isOrderDistinct!=0 );
175095175400
isOrderDistinct = 0;
175096175401
}
175097175402
break;
175098175403
}
@@ -177249,10 +177554,21 @@
177249177554
if( pTabList->a[pLevel->iFrom].fg.fromExists ){
177250177555
/* This is an EXISTS-to-JOIN optimization loop. If this loop sees a
177251177556
** successful row, it should break out of itself. */
177252177557
sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrBrk);
177253177558
VdbeComment((v, "EXISTS break %d", i));
177559
+ }else if( pLevel->addrDeleteCont ){
177560
+ /* An inner loop matched no rows on this auto-index driven loop and
177561
+ ** there are outer loops. So delete the auto-index entry to avoid
177562
+ ** future unnecessary work. */
177563
+ int iBypass = sqlite3VdbeAddOp0(v, OP_Goto);
177564
+ assert( pLoop->wsFlags & WHERE_AUTO_INDEX );
177565
+ sqlite3VdbeResolveLabel(v, pLevel->addrDeleteCont);
177566
+ sqlite3VdbeAddOp1(v, OP_Delete, pLevel->iIdxCur);
177567
+ sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
177568
+ VdbeComment((v, "delete useless auto-index entry"));
177569
+ sqlite3VdbeJumpHere(v, iBypass);
177254177570
}
177255177571
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
177256177572
if( pLevel->op!=OP_Noop ){
177257177573
sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
177258177574
sqlite3VdbeChangeP5(v, pLevel->p5);
@@ -177270,14 +177586,35 @@
177270177586
sqlite3VdbeResolveLabel(v, pLevel->addrBignull);
177271177587
sqlite3VdbeAddOp2(v, OP_DecrJumpZero, pLevel->regBignull, pLevel->p2-1);
177272177588
VdbeCoverage(v);
177273177589
}
177274177590
}
177591
+ if( pLevel->addrNxt!=pLevel->addrBrk ){
177592
+ /* This occurs in three cases - (a) for a LIKE/GLOB scan that must visit
177593
+ ** ranges of text and blob values separately, and (b) when there is
177594
+ ** an IN(...) constraint driving the index, and (c) when a prior error
177595
+ ** such as an OOM has left us in an unusual state. This is asserted()
177596
+ ** in the next block, inside the #ifndef. */
177597
+ sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
177598
+ }
177599
+#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
177600
+ assert( (pLevel->addrNxt==pLevel->addrBrk)
177601
+ || (pLevel->addrLikeRep) /* (a) */
177602
+ || ((pLoop->wsFlags & WHERE_IN_ABLE) && pLevel->u.in.nIn>0) /* (b) */
177603
+ || pWInfo->pParse->nErr>0 /* (c) */
177604
+ );
177605
+ if( pLevel->addrLikeRep ){
177606
+ /* The LIKE optimization loop is nested inside any IN(...) and
177607
+ ** skip-scan loops, so it is closed here, before either of those. */
177608
+ sqlite3VdbeAddOp2(v, OP_DecrJumpZero, (int)(pLevel->iLikeRepCntr>>1),
177609
+ pLevel->addrLikeRep);
177610
+ VdbeCoverage(v);
177611
+ }
177612
+#endif
177275177613
if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){
177276177614
struct InLoop *pIn;
177277177615
int j;
177278
- sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
177279177616
for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
177280177617
assert( sqlite3VdbeGetOp(v, pIn->addrInTop+1)->opcode==OP_IsNull
177281177618
|| pParse->db->mallocFailed );
177282177619
sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
177283177620
if( pIn->eEndLoopOp!=OP_Noop ){
@@ -177325,17 +177662,10 @@
177325177662
sqlite3VdbeGoto(v, pLevel->addrSkip);
177326177663
VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
177327177664
sqlite3VdbeJumpHere(v, pLevel->addrSkip);
177328177665
sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
177329177666
}
177330
-#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
177331
- if( pLevel->addrLikeRep ){
177332
- sqlite3VdbeAddOp2(v, OP_DecrJumpZero, (int)(pLevel->iLikeRepCntr>>1),
177333
- pLevel->addrLikeRep);
177334
- VdbeCoverage(v);
177335
- }
177336
-#endif
177337177667
if( pLevel->iLeftJoin ){
177338177668
int ws = pLoop->wsFlags;
177339177669
addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
177340177670
assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 );
177341177671
if( (ws & WHERE_IDX_ONLY)==0 ){
@@ -212949,17 +213279,15 @@
212949213279
/* #include <string.h> */
212950213280
212951213281
/* #include "fts3_tokenizer.h" */
212952213282
212953213283
/*
212954
-** The following two macros - READ_UTF8 and WRITE_UTF8 - have been copied
212955
-** from the sqlite3 source file utf.c. If this file is compiled as part
212956
-** of the amalgamation, they are not required.
213284
+** The following two macros - FTS3_READ_UTF8 and FTS3_WRITE_UTF8 - have
213285
+** been copied from the sqlite3 source file utf.c.
212957213286
*/
212958
-#ifndef SQLITE_AMALGAMATION
212959213287
212960
-static const unsigned char sqlite3Utf8Trans1[] = {
213288
+static const unsigned char fts3Utf8Trans1[] = {
212961213289
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
212962213290
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
212963213291
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
212964213292
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
212965213293
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -212966,43 +213294,41 @@
212966213294
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
212967213295
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
212968213296
0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
212969213297
};
212970213298
212971
-#define READ_UTF8(zIn, zTerm, c) \
213299
+#define FTS3_READ_UTF8(zIn, zTerm, c) \
212972213300
c = *(zIn++); \
212973213301
if( c>=0xc0 ){ \
212974
- c = sqlite3Utf8Trans1[c-0xc0]; \
213302
+ c = fts3Utf8Trans1[c-0xc0]; \
212975213303
while( zIn!=zTerm && (*zIn & 0xc0)==0x80 ){ \
212976213304
c = (c<<6) + (0x3f & *(zIn++)); \
212977213305
} \
212978213306
if( c<0x80 \
212979213307
|| (c&0xFFFFF800)==0xD800 \
212980213308
|| (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
212981213309
}
212982213310
212983
-#define WRITE_UTF8(zOut, c) { \
212984
- if( c<0x00080 ){ \
212985
- *zOut++ = (u8)(c&0xFF); \
212986
- } \
212987
- else if( c<0x00800 ){ \
212988
- *zOut++ = 0xC0 + (u8)((c>>6)&0x1F); \
212989
- *zOut++ = 0x80 + (u8)(c & 0x3F); \
212990
- } \
212991
- else if( c<0x10000 ){ \
212992
- *zOut++ = 0xE0 + (u8)((c>>12)&0x0F); \
212993
- *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
212994
- *zOut++ = 0x80 + (u8)(c & 0x3F); \
212995
- }else{ \
212996
- *zOut++ = 0xF0 + (u8)((c>>18) & 0x07); \
212997
- *zOut++ = 0x80 + (u8)((c>>12) & 0x3F); \
212998
- *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
212999
- *zOut++ = 0x80 + (u8)(c & 0x3F); \
213000
- } \
213001
-}
213002
-
213003
-#endif /* ifndef SQLITE_AMALGAMATION */
213311
+#define FTS3_WRITE_UTF8(zOut, c) { \
213312
+ if( c<0x00080 ){ \
213313
+ *zOut++ = (u8)(c&0xFF); \
213314
+ } \
213315
+ else if( c<0x00800 ){ \
213316
+ *zOut++ = 0xC0 + (u8)((c>>6)&0x1F); \
213317
+ *zOut++ = 0x80 + (u8)(c & 0x3F); \
213318
+ } \
213319
+ else if( c<0x10000 ){ \
213320
+ *zOut++ = 0xE0 + (u8)((c>>12)&0x0F); \
213321
+ *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
213322
+ *zOut++ = 0x80 + (u8)(c & 0x3F); \
213323
+ }else{ \
213324
+ *zOut++ = 0xF0 + (u8)((c>>18) & 0x07); \
213325
+ *zOut++ = 0x80 + (u8)((c>>12) & 0x3F); \
213326
+ *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
213327
+ *zOut++ = 0x80 + (u8)(c & 0x3F); \
213328
+ } \
213329
+}
213004213330
213005213331
typedef struct unicode_tokenizer unicode_tokenizer;
213006213332
typedef struct unicode_cursor unicode_cursor;
213007213333
213008213334
struct unicode_tokenizer {
@@ -213065,11 +213391,11 @@
213065213391
int nEntry = 0;
213066213392
213067213393
assert( bAlnum==0 || bAlnum==1 );
213068213394
213069213395
while( z<zTerm ){
213070
- READ_UTF8(z, zTerm, iCode);
213396
+ FTS3_READ_UTF8(z, zTerm, iCode);
213071213397
assert( (sqlite3FtsUnicodeIsalnum((int)iCode) & 0xFFFFFFFE)==0 );
213072213398
if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum
213073213399
&& sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
213074213400
){
213075213401
nEntry++;
@@ -213084,11 +213410,11 @@
213084213410
if( aNew==0 ) return SQLITE_NOMEM;
213085213411
nNew = p->nException;
213086213412
213087213413
z = (const unsigned char *)zIn;
213088213414
while( z<zTerm ){
213089
- READ_UTF8(z, zTerm, iCode);
213415
+ FTS3_READ_UTF8(z, zTerm, iCode);
213090213416
if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum
213091213417
&& sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
213092213418
){
213093213419
int i, j;
213094213420
for(i=0; i<nNew && aNew[i]<(int)iCode; i++);
@@ -213256,11 +213582,11 @@
213256213582
213257213583
/* Scan past any delimiter characters before the start of the next token.
213258213584
** Return SQLITE_DONE early if this takes us all the way to the end of
213259213585
** the input. */
213260213586
while( z<zTerm ){
213261
- READ_UTF8(z, zTerm, iCode);
213587
+ FTS3_READ_UTF8(z, zTerm, iCode);
213262213588
if( unicodeIsAlnum(p, (int)iCode) ) break;
213263213589
zStart = z;
213264213590
}
213265213591
if( zStart>=zTerm ) return SQLITE_DONE;
213266213592
@@ -213279,16 +213605,16 @@
213279213605
213280213606
/* Write the folded case of the last character read to the output */
213281213607
zEnd = z;
213282213608
iOut = sqlite3FtsUnicodeFold((int)iCode, p->eRemoveDiacritic);
213283213609
if( iOut ){
213284
- WRITE_UTF8(zOut, iOut);
213610
+ FTS3_WRITE_UTF8(zOut, iOut);
213285213611
}
213286213612
213287213613
/* If the cursor is not at EOF, read the next character */
213288213614
if( z>=zTerm ) break;
213289
- READ_UTF8(z, zTerm, iCode);
213615
+ FTS3_READ_UTF8(z, zTerm, iCode);
213290213616
}while( unicodeIsAlnum(p, (int)iCode)
213291213617
|| sqlite3FtsUnicodeIsdiacritic((int)iCode)
213292213618
);
213293213619
213294213620
/* Set the output variables and return. */
@@ -214107,10 +214433,11 @@
214107214433
/*
214108214434
** Allowed values for the flgs argument to jsonParseFuncArg();
214109214435
*/
214110214436
#define JSON_EDITABLE 0x01 /* Generate a writable JsonParse object */
214111214437
#define JSON_KEEPERROR 0x02 /* Return non-NULL even if there is an error */
214438
+#define JSON_NOCACHE 0x04 /* Do not use the JSON cache */
214112214439
214113214440
/**************************************************************************
214114214441
** Forward references
214115214442
**************************************************************************/
214116214443
static void jsonReturnStringAsBlob(JsonString*);
@@ -217550,11 +217877,13 @@
217550217877
assert( ctx!=0 );
217551217878
eType = sqlite3_value_type(pArg);
217552217879
if( eType==SQLITE_NULL ){
217553217880
return 0;
217554217881
}
217555
- pFromCache = jsonCacheSearch(ctx, pArg);
217882
+ if( (flgs & JSON_NOCACHE)==0 ){
217883
+ pFromCache = jsonCacheSearch(ctx, pArg);
217884
+ }
217556217885
if( pFromCache ){
217557217886
pFromCache->nJPRef++;
217558217887
if( (flgs & JSON_EDITABLE)==0 ){
217559217888
return pFromCache;
217560217889
}
@@ -218625,11 +218954,11 @@
218625218954
default: {
218626218955
JsonParse px;
218627218956
if( (flags & 0x3)==0 ) break;
218628218957
memset(&px, 0, sizeof(px));
218629218958
218630
- p = jsonParseFuncArg(ctx, argv[0], JSON_KEEPERROR);
218959
+ p = jsonParseFuncArg(ctx, argv[0], JSON_KEEPERROR|JSON_NOCACHE);
218631218960
if( p ){
218632218961
if( p->oom ){
218633218962
sqlite3_result_error_nomem(ctx);
218634218963
}else if( p->nErr ){
218635218964
/* no-op */
@@ -219218,21 +219547,20 @@
219218219547
*/
219219219548
static int jsonEachPathLength(JsonEachCursor *p){
219220219549
u32 n = p->path.nUsed;
219221219550
char *z = p->path.zBuf;
219222219551
if( p->iRowid==0 && p->bRecursive && n>=2 ){
219223
- while( n>1 ){
219552
+ while( ALWAYS(n>1) ){
219224219553
n--;
219225219554
if( z[n]=='[' || z[n]=='.' ){
219226
- u32 x, sz = 0;
219555
+ u32 x;
219227219556
char cSaved = z[n];
219228219557
z[n] = 0;
219229219558
assert( p->sParse.eEdit==0 );
219230219559
x = jsonLookupStep(&p->sParse, 0, z+1, 0);
219231219560
z[n] = cSaved;
219232
- if( JSON_LOOKUP_ISERROR(x) ) continue;
219233
- if( x + jsonbPayloadSize(&p->sParse, x, &sz) == p->i ) break;
219561
+ if( !JSON_LOOKUP_ISERROR(x) ) break;
219234219562
}
219235219563
}
219236219564
}
219237219565
return n;
219238219566
}
@@ -246043,11 +246371,26 @@
246043246371
}
246044246372
246045246373
return rc;
246046246374
}
246047246375
246048
-
246376
+/*
246377
+** Load error code rc into the context handle pCtx. Except, if
246378
+** rc==SQLITE_ERROR and there is an error message in the associated db
246379
+** handle, return that error message as well.
246380
+*/
246381
+static void fts5AuxResultError(sqlite3_context *pCtx, int rc){
246382
+ if( rc==SQLITE_ERROR ){
246383
+ sqlite3 *db = sqlite3_context_db_handle(pCtx);
246384
+ if( sqlite3_errcode(db)==SQLITE_ERROR ){
246385
+ const char *zErr = sqlite3_errmsg(db);
246386
+ sqlite3_result_error(pCtx, zErr, -1);
246387
+ return;
246388
+ }
246389
+ }
246390
+ sqlite3_result_error_code(pCtx, rc);
246391
+}
246049246392
246050246393
/*************************************************************************
246051246394
** Start of highlight() implementation.
246052246395
*/
246053246396
typedef struct HighlightContext HighlightContext;
@@ -246232,11 +246575,11 @@
246232246575
sqlite3_result_text(pCtx, (const char*)ctx.zOut, -1, SQLITE_TRANSIENT);
246233246576
}
246234246577
sqlite3_free(ctx.zOut);
246235246578
}
246236246579
if( rc!=SQLITE_OK ){
246237
- sqlite3_result_error_code(pCtx, rc);
246580
+ fts5AuxResultError(pCtx, rc);
246238246581
}
246239246582
}
246240246583
/*
246241246584
** End of highlight() implementation.
246242246585
**************************************************************************/
@@ -246526,11 +246869,11 @@
246526246869
}
246527246870
}
246528246871
if( rc==SQLITE_OK ){
246529246872
sqlite3_result_text(pCtx, (const char*)ctx.zOut, -1, SQLITE_TRANSIENT);
246530246873
}else{
246531
- sqlite3_result_error_code(pCtx, rc);
246874
+ fts5AuxResultError(pCtx, rc);
246532246875
}
246533246876
sqlite3_free(ctx.zOut);
246534246877
sqlite3_free(aSeen);
246535246878
sqlite3_free(sFinder.aFirst);
246536246879
}
@@ -246692,11 +247035,11 @@
246692247035
( aFreq[i] + k1 * (1 - b + b * D / pData->avgdl) )
246693247036
);
246694247037
}
246695247038
sqlite3_result_double(pCtx, -1.0 * score);
246696247039
}else{
246697
- sqlite3_result_error_code(pCtx, rc);
247040
+ fts5AuxResultError(pCtx, rc);
246698247041
}
246699247042
}
246700247043
246701247044
/*
246702247045
** Implementation of fts5_get_locale() function.
@@ -246730,17 +247073,17 @@
246730247073
return;
246731247074
}
246732247075
246733247076
iCol = fts5ValueClampedInt(apVal[0]);
246734247077
if( iCol<0 || iCol>=pApi->xColumnCount(pFts) ){
246735
- sqlite3_result_error_code(pCtx, SQLITE_RANGE);
247078
+ fts5AuxResultError(pCtx, SQLITE_RANGE);
246736247079
return;
246737247080
}
246738247081
246739247082
rc = pApi->xColumnLocale(pFts, iCol, &zLocale, &nLocale);
246740247083
if( rc!=SQLITE_OK ){
246741
- sqlite3_result_error_code(pCtx, rc);
247084
+ fts5AuxResultError(pCtx, rc);
246742247085
return;
246743247086
}
246744247087
246745247088
sqlite3_result_text(pCtx, zLocale, nLocale, SQLITE_TRANSIENT);
246746247089
}
@@ -265407,11 +265750,11 @@
265407265750
int nArg, /* Number of args */
265408265751
sqlite3_value **apUnused /* Function arguments */
265409265752
){
265410265753
assert( nArg==0 );
265411265754
UNUSED_PARAM2(nArg, apUnused);
265412
- sqlite3_result_text(pCtx, "fts5: 2026-10-09 11:47:51 a3332bd623d997921c3186433cd1eab0c9413aa0f68d93b1731cf80128ec3a36", -1, SQLITE_TRANSIENT);
265755
+ sqlite3_result_text(pCtx, "fts5: 2026-10-16 14:31:53 668541c592b89d32716420615450d55d9faf89da8a8e389c673973d8383cca98", -1, SQLITE_TRANSIENT);
265413265756
}
265414265757
265415265758
/*
265416265759
** Implementation of fts5_locale(LOCALE, TEXT) function.
265417265760
**
@@ -265886,17 +266229,17 @@
265886266229
if( eStmt>FTS5_STMT_LOOKUP2 ) f |= SQLITE_PREPARE_NO_VTAB;
265887266230
p->pConfig->bLock++;
265888266231
rc = sqlite3_prepare_v3(pC->db, zSql, -1, f, &p->aStmt[eStmt], 0);
265889266232
p->pConfig->bLock--;
265890266233
sqlite3_free(zSql);
265891
- if( rc!=SQLITE_OK && pzErrMsg ){
265892
- *pzErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pC->db));
265893
- }
265894266234
if( rc==SQLITE_ERROR && eStmt>FTS5_STMT_LOOKUP2 && eStmt<FTS5_STMT_SCAN ){
265895266235
/* One of the internal tables - not the %_content table - is missing.
265896266236
** This counts as a corrupted table. */
265897
- rc = SQLITE_CORRUPT;
266237
+ rc = SQLITE_CORRUPT_VTAB;
266238
+ }else if( rc!=SQLITE_OK && p->pConfig->pzErrmsg ){
266239
+ assert( *p->pConfig->pzErrmsg==0 );
266240
+ *p->pConfig->pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(pC->db));
265898266241
}
265899266242
}
265900266243
}
265901266244
265902266245
*ppStmt = p->aStmt[eStmt];
@@ -267411,17 +267754,14 @@
267411267754
** Start of unicode61 tokenizer implementation.
267412267755
*/
267413267756
267414267757
267415267758
/*
267416
-** The following two macros - READ_UTF8 and WRITE_UTF8 - have been copied
267417
-** from the sqlite3 source file utf.c. If this file is compiled as part
267418
-** of the amalgamation, they are not required.
267759
+** The following two macros - FTS5_READ_UTF8 and FTS5_WRITE_UTF8 - have
267760
+** been copied from the sqlite3 source file utf.c.
267419267761
*/
267420
-#ifndef SQLITE_AMALGAMATION
267421
-
267422
-static const unsigned char sqlite3Utf8Trans1[] = {
267762
+static const unsigned char fts5Utf8Trans1[] = {
267423267763
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
267424267764
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
267425267765
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
267426267766
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
267427267767
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -267428,49 +267768,47 @@
267428267768
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
267429267769
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
267430267770
0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
267431267771
};
267432267772
267433
-#define READ_UTF8(zIn, zTerm, c) \
267773
+#define FTS5_READ_UTF8(zIn, zTerm, c) \
267434267774
c = *(zIn++); \
267435267775
if( c>=0xc0 ){ \
267436
- c = sqlite3Utf8Trans1[c-0xc0]; \
267776
+ c = fts5Utf8Trans1[c-0xc0]; \
267437267777
while( zIn<zTerm && (*zIn & 0xc0)==0x80 ){ \
267438267778
c = (c<<6) + (0x3f & *(zIn++)); \
267439267779
} \
267440267780
if( c<0x80 \
267441
- || (c&0xFFFFF800)==0xD800 \
267442
- || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
267443
- }
267444
-
267445
-
267446
-#define WRITE_UTF8(zOut, c) { \
267447
- if( c<0x00080 ){ \
267448
- *zOut++ = (unsigned char)(c&0xFF); \
267449
- } \
267450
- else if( c<0x00800 ){ \
267451
- *zOut++ = 0xC0 + (unsigned char)((c>>6)&0x1F); \
267452
- *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
267453
- } \
267454
- else if( c<0x10000 ){ \
267455
- *zOut++ = 0xE0 + (unsigned char)((c>>12)&0x0F); \
267456
- *zOut++ = 0x80 + (unsigned char)((c>>6) & 0x3F); \
267457
- *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
267458
- }else{ \
267459
- *zOut++ = 0xF0 + (unsigned char)((c>>18) & 0x07); \
267460
- *zOut++ = 0x80 + (unsigned char)((c>>12) & 0x3F); \
267461
- *zOut++ = 0x80 + (unsigned char)((c>>6) & 0x3F); \
267462
- *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
267463
- } \
267464
-}
267465
-
267466
-#endif /* ifndef SQLITE_AMALGAMATION */
267467
-
267468
-#define FTS5_SKIP_UTF8(zIn) { \
267469
- if( ((unsigned char)(*(zIn++)))>=0xc0 ){ \
267470
- while( (((unsigned char)*zIn) & 0xc0)==0x80 ){ zIn++; } \
267471
- } \
267781
+ || (c&0xFFFFF800)==0xD800 \
267782
+ || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
267783
+ }
267784
+
267785
+
267786
+#define FTS5_WRITE_UTF8(zOut, c) { \
267787
+ if( c<0x00080 ){ \
267788
+ *zOut++ = (unsigned char)(c&0xFF); \
267789
+ } \
267790
+ else if( c<0x00800 ){ \
267791
+ *zOut++ = 0xC0 + (unsigned char)((c>>6)&0x1F); \
267792
+ *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
267793
+ } \
267794
+ else if( c<0x10000 ){ \
267795
+ *zOut++ = 0xE0 + (unsigned char)((c>>12)&0x0F); \
267796
+ *zOut++ = 0x80 + (unsigned char)((c>>6) & 0x3F); \
267797
+ *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
267798
+ }else{ \
267799
+ *zOut++ = 0xF0 + (unsigned char)((c>>18) & 0x07); \
267800
+ *zOut++ = 0x80 + (unsigned char)((c>>12) & 0x3F); \
267801
+ *zOut++ = 0x80 + (unsigned char)((c>>6) & 0x3F); \
267802
+ *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
267803
+ } \
267804
+}
267805
+
267806
+#define FTS5_SKIP_UTF8(zIn) { \
267807
+ if( ((unsigned char)(*(zIn++)))>=0xc0 ){ \
267808
+ while( (((unsigned char)*zIn) & 0xc0)==0x80 ){zIn++;} \
267809
+ } \
267472267810
}
267473267811
267474267812
typedef struct Unicode61Tokenizer Unicode61Tokenizer;
267475267813
struct Unicode61Tokenizer {
267476267814
unsigned char aTokenChar[128]; /* ASCII range token characters */
@@ -267505,11 +267843,11 @@
267505267843
const unsigned char *zCsr = (const unsigned char*)z;
267506267844
const unsigned char *zTerm = (const unsigned char*)&z[n];
267507267845
while( zCsr<zTerm ){
267508267846
u32 iCode;
267509267847
int bToken;
267510
- READ_UTF8(zCsr, zTerm, iCode);
267848
+ FTS5_READ_UTF8(zCsr, zTerm, iCode);
267511267849
if( iCode<128 ){
267512267850
p->aTokenChar[iCode] = (unsigned char)bTokenChars;
267513267851
}else{
267514267852
bToken = p->aCategory[sqlite3Fts5UnicodeCategory(iCode)];
267515267853
assert( (bToken==0 || bToken==1) );
@@ -267709,11 +268047,11 @@
267709268047
if( zCsr>=zTerm ) goto tokenize_done;
267710268048
if( *zCsr & 0x80 ) {
267711268049
/* A character outside of the ascii range. Skip past it if it is
267712268050
** a separator character. Or break out of the loop if it is not. */
267713268051
is = zCsr - (unsigned char*)pText;
267714
- READ_UTF8(zCsr, zTerm, iCode);
268052
+ FTS5_READ_UTF8(zCsr, zTerm, iCode);
267715268053
if( fts5UnicodeIsAlnum(p, iCode) ){
267716268054
goto non_ascii_tokenchar;
267717268055
}
267718268056
}else{
267719268057
if( a[*zCsr] ){
@@ -267745,15 +268083,15 @@
267745268083
}
267746268084
267747268085
if( *zCsr & 0x80 ){
267748268086
/* An non-ascii-range character. Fold it into the output buffer if
267749268087
** it is a token character, or break out of the loop if it is not. */
267750
- READ_UTF8(zCsr, zTerm, iCode);
268088
+ FTS5_READ_UTF8(zCsr, zTerm, iCode);
267751268089
if( fts5UnicodeIsAlnum(p,iCode)||sqlite3Fts5UnicodeIsdiacritic(iCode) ){
267752268090
non_ascii_tokenchar:
267753268091
iCode = sqlite3Fts5UnicodeFold(iCode, p->eRemoveDiacritic);
267754
- if( iCode ) WRITE_UTF8(zOut, iCode);
268092
+ if( iCode ) FTS5_WRITE_UTF8(zOut, iCode);
267755268093
}else{
267756268094
break;
267757268095
}
267758268096
}else if( a[*zCsr]==0 ){
267759268097
/* An ascii-range separator character. End of token. */
@@ -268604,14 +268942,14 @@
268604268942
/* Populate aBuf[] with the characters for the first trigram. */
268605268943
for(ii=0; ii<3; ii++){
268606268944
do {
268607268945
aStart[ii] = zIn - (const unsigned char*)pText;
268608268946
if( zIn>=zEof ) return SQLITE_OK;
268609
- READ_UTF8(zIn, zEof, iCode);
268947
+ FTS5_READ_UTF8(zIn, zEof, iCode);
268610268948
if( p->bFold ) iCode = sqlite3Fts5UnicodeFold(iCode, p->iFoldParam);
268611268949
}while( iCode==0 );
268612
- WRITE_UTF8(zOut, iCode);
268950
+ FTS5_WRITE_UTF8(zOut, iCode);
268613268951
}
268614268952
268615268953
/* At the start of each iteration of this loop:
268616268954
**
268617268955
** aBuf: Contains 3 characters. The 3 characters of the next trigram.
@@ -268629,11 +268967,11 @@
268629268967
iNext = zIn - (const unsigned char*)pText;
268630268968
if( zIn>=zEof ){
268631268969
iCode = 0;
268632268970
break;
268633268971
}
268634
- READ_UTF8(zIn, zEof, iCode);
268972
+ FTS5_READ_UTF8(zIn, zEof, iCode);
268635268973
if( p->bFold ) iCode = sqlite3Fts5UnicodeFold(iCode, p->iFoldParam);
268636268974
}while( iCode==0 );
268637268975
268638268976
/* Pass the current trigram back to fts5 */
268639268977
rc = xToken(pCtx, 0, aBuf, zOut-aBuf, aStart[0], iNext);
@@ -268643,11 +268981,11 @@
268643268981
** with codepoint iCode. */
268644268982
z1 = aBuf;
268645268983
FTS5_SKIP_UTF8(z1);
268646268984
memmove(aBuf, z1, zOut - z1);
268647268985
zOut -= (z1 - aBuf);
268648
- WRITE_UTF8(zOut, iCode);
268986
+ FTS5_WRITE_UTF8(zOut, iCode);
268649268987
268650268988
/* Update the aStart[] array */
268651268989
aStart[0] = aStart[1];
268652268990
aStart[1] = aStart[2];
268653268991
aStart[2] = iNext;
268654268992
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.54.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** a3332bd623d997921c3186433cd1eab0c941 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -465,16 +465,16 @@
465 **
466 ** See also: [sqlite3_libversion()],
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-10-09 11:47:51 a3332bd623d997921c3186433cd1eab0c9413aa0f68d93b1731cf80128ec3a36"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-10-09T11:47:51.732Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -4399,11 +4399,11 @@
4399 ** parameter on F or if the value of P does not match any of the
4400 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4401 **
4402 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4403 ** 64-bit signed integer and returns that integer, or D if P does not
4404 ** exist or ff the value of P is something other than an integer.
4405 **
4406 ** The sqlite3_uri_key(F,N) returns a pointer to the name (not
4407 ** the value) of the N-th query parameter for filename F, or a NULL
4408 ** pointer if N is less than zero or greater than the number of query
4409 ** parameters minus 1. The N value is zero-based so N should be 0 to obtain
@@ -18876,11 +18876,10 @@
18876 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
18877 int errCode; /* Most recent error code (SQLITE_*) */
18878 int errByteOffset; /* Byte offset of error in SQL statement */
18879 int errMask; /* & result codes with this before returning */
18880 int iSysErrno; /* Errno value from last system error */
18881 u32 dbOptFlags; /* Flags to enable/disable optimizations */
18882 u8 enc; /* Text encoding */
18883 u8 autoCommit; /* The auto-commit flag. */
18884 u8 temp_store; /* 1: file 2: memory 0: default */
18885 u8 mallocFailed; /* True if we have seen a malloc failure */
18886 u8 bBenignMalloc; /* Do not require OOMs if true */
@@ -18895,10 +18894,11 @@
18895 u8 eOpenState; /* Current condition of the connection */
18896 u8 nFpDigit; /* Significant digits to keep on double->text */
18897 int nextPagesize; /* Pagesize after VACUUM if >0 */
18898 i64 nChange; /* Value returned by sqlite3_changes() */
18899 i64 nTotalChange; /* Value returned by sqlite3_total_changes() */
 
18900 int aLimit[SQLITE_N_LIMIT]; /* Limits */
18901 int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */
18902 struct sqlite3InitInfo { /* Information used during initialization */
18903 Pgno newTnum; /* Rootpage of table being initialized */
18904 u8 iDb; /* Which db file is being initialized */
@@ -19094,55 +19094,53 @@
19094 #define DBFLAG_EncodingFixed 0x0040 /* No longer possible to change enc. */
19095
19096 /*
19097 ** Bits of the sqlite3.dbOptFlags field that are used by the
19098 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
19099 ** selectively disable various optimizations.
 
 
 
19100 */
19101 #define SQLITE_QueryFlattener 0x00000001 /* Query flattening */
19102 #define SQLITE_WindowFunc 0x00000002 /* Use xInverse for window functions */
19103 #define SQLITE_GroupByOrder 0x00000004 /* GROUPBY cover of ORDERBY */
19104 /* 0x00000008 -- Available for reuse */
19105 #define SQLITE_DistinctOpt 0x00000010 /* DISTINCT using indexes */
19106 #define SQLITE_CoverIdxScan 0x00000020 /* Covering index scans */
19107 #define SQLITE_OrderByIdxJoin 0x00000040 /* ORDER BY of joins via index */
19108 #define SQLITE_Transitive 0x00000080 /* Transitive constraints */
19109 #define SQLITE_OmitNoopJoin 0x00000100 /* Omit unused tables in joins */
19110 #define SQLITE_CountOfView 0x00000200 /* The count-of-view optimization */
19111 #define SQLITE_CursorHints 0x00000400 /* Add OP_CursorHint opcodes */
19112 #define SQLITE_Stat4 0x00000800 /* Use STAT4 data */
19113 /* TH3 expects this value ^^^^^^^^^^ */
19114 #define SQLITE_PushDown 0x00001000 /* WHERE-clause push-down opt */
19115 #define SQLITE_SimplifyJoin 0x00002000 /* Convert LEFT JOIN to JOIN */
19116 #define SQLITE_SkipScan 0x00004000 /* Skip-scans */
19117 #define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */
19118 #define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */
19119 #define SQLITE_SeekScan 0x00020000 /* The OP_SeekScan optimization */
19120 #define SQLITE_OmitOrderBy 0x00040000 /* Omit pointless ORDER BY */
19121 /* TH3 expects this value ^^^^^^^^^^ */
19122 #define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filters */
19123 /* TH3 expects this value ^^^^^^^^^^ */
19124 /* 0x00100000 -- Available for reuse */
19125 #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
19126 #define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
19127 #define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
19128 /* TH3 expects this value ^^^^^^^^^^ */
19129 #define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
19130 #define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
19131 #define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
19132 #define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
19133 #define SQLITE_OrderBySubq 0x10000000 /* ORDER BY in subquery helps outer */
19134 #define SQLITE_StarQuery 0x20000000 /* Heurists for star queries */
19135 #define SQLITE_ExistsToJoin 0x40000000 /* The EXISTS-to-JOIN optimization */
19136 #define SQLITE_UnionLimit 0x80000000 /* Optimizations for UNION + LIMIT */
19137 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
19138
19139 /*
19140 ** Macros for testing whether or not optimizations are enabled or disabled.
19141 */
19142 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0)
19143 #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0)
19144
19145 /*
19146 ** Return true if it OK to factor constant expressions into the initialization
19147 ** code. The argument is a Parse object for the code generator.
19148 */
@@ -21119,10 +21117,11 @@
21119 int nRangeReg; /* Size of the temporary register block */
21120 int iRangeReg; /* First register in temporary register block */
21121 int nErr; /* Number of errors seen */
21122 int nTab; /* Number of previously allocated VDBE cursors */
21123 int nMem; /* Number of memory cells used so far */
 
21124 int iSelfTab; /* Table associated with an index on expr, or negative
21125 ** of the base register during check-constraint eval */
21126 int nNestSel; /* Number of nested SELECT statements and/or VIEWs */
21127 int nLabel; /* The *negative* of the number of labels used */
21128 int nLabelAlloc; /* Number of slots in aLabel */
@@ -22448,15 +22447,14 @@
22448 SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr*);
22449 SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*);
22450 SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse*,Expr*);
22451 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
22452 SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
 
22453 SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int,int);
22454 SQLITE_PRIVATE int sqlite3ExprListIsConstant(Parse *pParse, ExprList *pList, int bNoIs);
22455 #ifdef SQLITE_ENABLE_CURSOR_HINTS
22456 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
22457 #endif
22458 SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*, Parse*, int);
22459 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
22460 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
22461 SQLITE_PRIVATE int sqlite3ExprIsLikeOperator(const Expr*);
22462 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
@@ -26055,36 +26053,39 @@
26055 p->isUtc = 1;
26056 p->isLocal = 0;
26057 }
26058 }
26059 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26060
26061 /*
26062 ** Given the YYYY-MM-DD information current in p, determine if there
26063 ** is day-of-month overflow and set nFloor to the number of days that
26064 ** would need to be subtracted from the date in order to bring the
26065 ** date back to the end of the month.
26066 */
26067 static void computeFloor(DateTime *p){
 
26068 assert( p->validYMD || p->isError );
26069 assert( p->D>=0 && p->D<=31 );
26070 assert( p->M>=0 && p->M<=12 );
26071 if( p->validHMS && p->h==24 ){
26072 p->h = 0;
26073 p->D++;
26074 }
26075 if( p->D<=28 ){
26076 p->nFloor = 0;
26077 }else if( (1<<p->M) & 0x15aa ){
26078 p->nFloor = 0;
26079 }else if( p->M!=2 ){
26080 p->nFloor = (p->D==31);
26081 }else if( p->Y%4!=0 || (p->Y%100==0 && p->Y%400!=0) ){
26082 p->nFloor = p->D - 28;
26083 }else{
26084 p->nFloor = p->D - 29;
26085 }
26086 }
26087
26088 /*
26089 ** Parse dates of the form
26090 **
@@ -26110,11 +26111,23 @@
26110 return 1;
26111 }
26112 zDate += 10;
26113 while( sqlite3Isspace(*zDate) || 'T'==*(u8*)zDate ){ zDate++; }
26114 if( parseHhMmSs(zDate, p)==0 ){
26115 /* We got the time */
 
 
 
 
 
 
 
 
 
 
 
 
26116 }else if( *zDate==0 ){
26117 p->validHMS = 0;
26118 }else{
26119 return 1;
26120 }
@@ -46240,32 +46253,39 @@
46240 #ifdef SQLITE_MMAP_READWRITE
46241 if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE;
46242 #endif
46243
46244 if( pOrig ){
 
 
 
 
 
 
 
 
 
 
46245 #if HAVE_MREMAP
46246 i64 nReuse = pFd->mmapSize;
46247 pNew = osMremap(pOrig, nReuse, nNew, MREMAP_MAYMOVE);
46248 zErr = "mremap";
46249 #else
46250 const int szSyspage = osGetpagesize();
46251 i64 nReuse = (pFd->mmapSize & ~(szSyspage-1));
46252 u8 *pReq = &pOrig[nReuse];
46253 pNew = osMmap(pReq, nNew-nReuse, flags, MAP_SHARED, h, nReuse);
46254 if( pNew!=MAP_FAILED ){
46255 if( pNew!=pReq ){
46256 osMunmap(pNew, nNew - nReuse);
46257 pNew = 0;
46258 }else{
46259 pNew = pOrig;
46260 }
46261 }
46262 #endif
46263
46264 /* The attempt to extend the existing mapping failed. Free it. */
46265 if( pNew==MAP_FAILED || pNew==0 ){
46266 osMunmap(pOrig, nReuse);
 
46267 }
46268 }
46269
46270 /* If pNew is still NULL, try to create an entirely new mapping. */
46271 if( pNew==0 ){
@@ -72669,16 +72689,22 @@
72669 SQLITE_PRIVATE void sqlite3BtreeEnter(Btree *p){
72670 p->pBt->db = p->db;
72671 }
72672 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
72673 int i;
 
 
 
 
72674 for(i=0; i<db->nDb; i++){
72675 Btree *p = db->aDb[i].pBt;
72676 if( p ){
72677 p->pBt->db = p->db;
 
72678 }
72679 }
 
72680 }
72681 #endif /* if SQLITE_THREADSAFE */
72682
72683 #ifndef SQLITE_OMIT_INCRBLOB
72684 /*
@@ -80129,11 +80155,11 @@
80129 ** the source page. Make sure this does not cause problems by not
80130 ** reading the first 4 bytes */
80131 memcpy(&data[idx+4], pCell+4, sz-4);
80132 put4byte(&data[idx], iChild);
80133 pIns = pPage->aCellIdx + i*2;
80134 memmove(pIns+2, pIns, 2*(pPage->nCell - i));
80135 put2byte(pIns, idx);
80136 pPage->nCell++;
80137 /* increment the cell count */
80138 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
80139 assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
@@ -80213,11 +80239,11 @@
80213 assert( idx >= pPage->cellOffset+2*pPage->nCell+2 || CORRUPT_DB );
80214 assert( idx+sz <= (int)pPage->pBt->usableSize );
80215 pPage->nFree -= (u16)(2 + sz);
80216 memcpy(&data[idx], pCell, sz);
80217 pIns = pPage->aCellIdx + i*2;
80218 memmove(pIns+2, pIns, 2*(pPage->nCell - i));
80219 put2byte(pIns, idx);
80220 pPage->nCell++;
80221 /* increment the cell count */
80222 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
80223 assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
@@ -81166,10 +81192,11 @@
81166 int limit = pOld->nCell;
81167 u8 *aData = pOld->aData;
81168 u16 maskPage = pOld->maskPage;
81169 u8 *piCell = aData + pOld->cellOffset;
81170 u8 *piEnd;
 
81171 VVA_ONLY( int nCellAtStart = b.nCell; )
81172
81173 /* Verify that all sibling pages are of the same "type" (table-leaf,
81174 ** table-interior, index-leaf, or index-interior).
81175 */
@@ -81201,27 +81228,29 @@
81201 rc = SQLITE_CORRUPT_PAGE(pOld);
81202 goto balance_cleanup;
81203 }
81204 limit = pOld->aiOvfl[0];
81205 for(j=0; j<limit; j++){
81206 b.apCell[b.nCell] = aData + (maskPage & get2byteAligned(piCell));
81207 piCell += 2;
81208 b.nCell++;
81209 }
 
81210 for(k=0; k<pOld->nOverflow; k++){
81211 assert( k==0 || pOld->aiOvfl[k-1]+1==pOld->aiOvfl[k] );/* NOTE 1 */
81212 b.apCell[b.nCell] = pOld->apOvfl[k];
81213 b.nCell++;
81214 }
81215 }
81216 piEnd = aData + pOld->cellOffset + 2*pOld->nCell;
 
 
81217 while( piCell<piEnd ){
81218 assert( b.nCell<nMaxCells );
81219 b.apCell[b.nCell] = aData + (maskPage & get2byteAligned(piCell));
81220 piCell += 2;
81221 b.nCell++;
81222 }
 
81223 assert( (b.nCell-nCellAtStart)==(pOld->nCell+pOld->nOverflow) );
81224
81225 cntOld[i] = b.nCell;
81226 if( i<nOld-1 && !leafData){
81227 u16 sz = (u16)szNew[i];
@@ -87092,10 +87121,11 @@
87092 zVal = &pExpr->u.zToken[2];
87093 nVal = sqlite3Strlen30(zVal)-1;
87094 assert( zVal[nVal]=='\'' );
87095 sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
87096 0, SQLITE_DYNAMIC);
 
87097 }
87098 #endif
87099 #ifdef SQLITE_ENABLE_STAT4
87100 else if( op==TK_FUNCTION && pCtx!=0 ){
87101 rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
@@ -87486,10 +87516,11 @@
87486 p->pParse = pParse;
87487 pParse->pVdbe = p;
87488 assert( pParse->aLabel==0 );
87489 assert( pParse->nLabel==0 );
87490 assert( p->nOpAlloc==0 );
 
87491 sqlite3VdbeAddOp2(p, OP_Init, 0, 1);
87492 return p;
87493 }
87494
87495 /*
@@ -87516,10 +87547,11 @@
87516 SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n, u8 prepFlags){
87517 if( p==0 ) return;
87518 p->prepFlags = prepFlags;
87519 if( (prepFlags & SQLITE_PREPARE_SAVESQL)==0 ){
87520 p->expmask = 0;
 
87521 }
87522 assert( p->zSql==0 );
87523 p->zSql = sqlite3DbStrNDup(p->db, z, n);
87524 }
87525
@@ -87636,11 +87668,12 @@
87636
87637 assert( nOp<=(int)(1024/sizeof(Op)) );
87638 assert( nNew>=(v->nOpAlloc+nOp) );
87639 pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
87640 if( pNew ){
87641 v->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
 
87642 v->aOp = pNew;
87643 }
87644 return (pNew ? SQLITE_OK : SQLITE_NOMEM_BKPT);
87645 }
87646
@@ -90143,11 +90176,11 @@
90143 ** of the prepared statement.
90144 */
90145 n = ROUND8P(sizeof(Op)*p->nOp); /* Bytes of opcode memory used */
90146 x.pSpace = &((u8*)p->aOp)[n]; /* Unused opcode memory */
90147 assert( EIGHT_BYTE_ALIGNMENT(x.pSpace) );
90148 x.nFree = ROUNDDOWN8((p->nOpAlloc-p->nOp)*sizeof(Op)); /* Bytes unused mem */
90149 assert( x.nFree>=0 );
90150 assert( EIGHT_BYTE_ALIGNMENT(&x.pSpace[x.nFree]) );
90151
90152 resolveP2Values(p, &nArg);
90153 p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
@@ -92794,14 +92827,16 @@
92794 assert( iVar>0 );
92795 assert( (v->db->flags & SQLITE_EnableQPSG)==0
92796 || (v->db->mDbFlags & DBFLAG_InternalFunc)!=0 );
92797
92798 m = (iVar>=32) ? 0x80000000 : ((u32)1 << (iVar-1));
92799 v->expmask |= m;
92800 if( bSmallint ){
92801 v->smimask |= m;
 
 
92802 }
 
92803
92804 /* smimask is always a subset of expmask */
92805 assert( (v->smimask & v->expmask) == v->smimask );
92806 }
92807
@@ -94950,14 +94985,12 @@
94950 if( i>=(unsigned int)p->nVar ){
94951 sqlite3Error(p->db, SQLITE_RANGE);
94952 sqlite3_mutex_leave(p->db->mutex);
94953 return SQLITE_RANGE;
94954 }
 
94955 pVar = &p->aVar[i];
94956 sqlite3VdbeMemRelease(pVar);
94957 pVar->flags = MEM_Null;
94958 p->db->errCode = SQLITE_OK;
94959
94960 /* If the bit corresponding to this variable in Vdbe.expmask is set, then
94961 ** binding a new value to this variable invalidates the current query plan.
94962 **
94963 ** IMPLEMENTATION-OF: R-57496-20354 If the specific value bound to a host
@@ -94967,15 +95000,24 @@
94967 ** following any change to the bindings of that parameter.
94968 */
94969 assert( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || p->expmask==0 );
94970 assert( (p->expmask & p->smimask)==p->smimask );
94971 if( p->expmask!=0 && (p->expmask & (i>=31 ? 0x80000000 : (u32)1<<i))!=0 ){
94972 /* We might avoid a reprepare here if p->smimask is set and the old
94973 ** value is an integer other than (0,1). But that is such a corner
94974 ** case that it does not seem worth the extra code to implement. */
94975 p->expired = 1;
 
 
 
 
94976 }
 
 
 
 
 
94977 return SQLITE_OK;
94978 }
94979
94980 /*
94981 ** Bind a text or BLOB value.
@@ -95099,12 +95141,12 @@
95099 int sm1 = (pVar->flags & MEM_Int)!=0 && pVar->u.i>=0 && pVar->u.i<=1;
95100 int sm2 = iValue>=0 && iValue<=1;
95101 if( sm1!=sm2 ){
95102 p->expired = 1;
95103 }
95104 }else if( (pVar->flags & MEM_Int)==0 || pVar->u.i!=iValue ){
95105 /* Always expire if the value really is changing */
95106 p->expired = 1;
95107 }
95108 }
95109 }
95110 sqlite3VdbeMemSetInt64(pVar, iValue);
@@ -98405,11 +98447,22 @@
98405 ** raise an SQLITE_MISMATCH exception.
98406 */
98407 case OP_MustBeInt: { /* jump0, in1 */
98408 pIn1 = &aMem[pOp->p1];
98409 if( (pIn1->flags & MEM_Int)==0 ){
98410 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
 
 
 
 
 
 
 
 
 
 
 
98411 if( (pIn1->flags & MEM_Int)==0 ){
98412 VdbeBranchTaken(1, 2);
98413 if( pOp->p2==0 ){
98414 rc = SQLITE_MISMATCH;
98415 goto abort_due_to_error;
@@ -100995,10 +101048,13 @@
100995 assert( !sqlite3BtreeClosesWithCursor(pCx->ub.pBtx, pCx->uc.pCursor) );
100996 sqlite3BtreeClose(pCx->ub.pBtx);
100997 p->apCsr[pOp->p1] = 0; /* Not required; helps with static analysis */
100998 }else{
100999 assert( sqlite3BtreeClosesWithCursor(pCx->ub.pBtx, pCx->uc.pCursor) );
 
 
 
101000 }
101001 }
101002 }
101003 if( rc ) goto abort_due_to_error;
101004 pCx->nullRow = 1;
@@ -101129,15 +101185,26 @@
101129 ** greater than or equal to the key and P2 is not zero, then jump to P2.
101130 **
101131 ** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
101132 ** opcode will either land on a record that exactly matches the key, or
101133 ** else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ,
101134 ** this opcode must be followed by an IdxLE opcode with the same arguments.
 
101135 ** The IdxGT opcode will be skipped if this opcode succeeds, but the
101136 ** IdxGT opcode will be used on subsequent loop iterations. The
101137 ** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
101138 ** is an equality search.
 
 
 
 
 
 
 
 
 
 
101139 **
101140 ** This opcode leaves the cursor configured to move in forward order,
101141 ** from the beginning toward the end. In other words, the cursor is
101142 ** configured to use Next, not Prev.
101143 **
@@ -101196,15 +101263,26 @@
101196 ** configured to use Prev, not Next.
101197 **
101198 ** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
101199 ** opcode will either land on a record that exactly matches the key, or
101200 ** else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ,
101201 ** this opcode must be followed by an IdxLE opcode with the same arguments.
 
101202 ** The IdxGE opcode will be skipped if this opcode succeeds, but the
101203 ** IdxGE opcode will be used on subsequent loop iterations. The
101204 ** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
101205 ** is an equality search.
 
 
 
 
 
 
 
 
 
 
101206 **
101207 ** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
101208 */
101209 case OP_SeekLT: /* jump0, in3, group, ncycle */
101210 case OP_SeekLE: /* jump0, in3, group, ncycle */
@@ -101310,11 +101388,13 @@
101310 assert( pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE );
101311 assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT );
101312 assert( pOp->opcode==OP_SeekGE || pOp[1].opcode==OP_IdxLT );
101313 assert( pOp->opcode==OP_SeekLE || pOp[1].opcode==OP_IdxGT );
101314 assert( pOp[1].p1==pOp[0].p1 );
101315 assert( pOp[1].p2==pOp[0].p2 );
 
 
101316 assert( pOp[1].p3==pOp[0].p3 );
101317 assert( pOp[1].p4.i==pOp[0].p4.i );
101318 }
101319
101320 nField = pOp->p4.i;
@@ -113193,15 +113273,14 @@
113193 char aff;
113194 assert( pExpr->op==TK_EQ || pExpr->op==TK_IN || pExpr->op==TK_LT ||
113195 pExpr->op==TK_GT || pExpr->op==TK_GE || pExpr->op==TK_LE ||
113196 pExpr->op==TK_NE || pExpr->op==TK_IS || pExpr->op==TK_ISNOT );
113197 assert( pExpr->pLeft );
 
113198 aff = sqlite3ExprAffinity(pExpr->pLeft);
113199 if( pExpr->pRight ){
113200 aff = sqlite3CompareAffinity(pExpr->pRight, aff);
113201 }else if( ExprUseXSelect(pExpr) ){
113202 aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff);
113203 }else if( aff==0 ){
113204 aff = SQLITE_AFF_BLOB;
113205 }
113206 return aff;
113207 }
@@ -115560,11 +115639,11 @@
115560 ** table other than iCur.
115561 **
115562 ** Consider uncorrelated subqueries to be constants if the bAllowSubq
115563 ** parameter is true.
115564 */
115565 static int sqlite3ExprIsTableConstant(Expr *p, int iCur, int bAllowSubq){
115566 Walker w;
115567 w.eCode = 3;
115568 w.pParse = 0;
115569 w.xExprCallback = exprNodeIsConstant;
115570 if( bAllowSubq ){
@@ -115740,11 +115819,10 @@
115740 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){
115741 assert( isInit==0 || isInit==1 );
115742 return exprIsConst(0, p, 4+isInit);
115743 }
115744
115745 #ifdef SQLITE_ENABLE_CURSOR_HINTS
115746 /*
115747 ** Walk an expression tree. Return 1 if the expression contains a
115748 ** subquery of some kind. Return 0 if there are no subqueries.
115749 */
115750 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr *p){
@@ -115756,11 +115834,10 @@
115756 w.xSelectCallback2 = sqlite3SelectWalkAssert2;
115757 #endif
115758 sqlite3WalkExpr(&w, p);
115759 return w.eCode==0;
115760 }
115761 #endif
115762
115763 /*
115764 ** If the expression p codes a constant integer between 0 and 0x7fffffff,
115765 ** then return 1 and put the value of the integer in *pValue. If the
115766 ** expression is not an integer or if it is an integer that is out side
@@ -115775,14 +115852,11 @@
115775 **
115776 ** If pParse is not NULL and expression p is a variable, then the variable
115777 ** is marked so as to cause the statement to be reprepared each time a new
115778 ** value is bound to it. Except, if parameter bRSI is true, then the statement
115779 ** will only be reprepared if the rebind changes the value to or from a
115780 ** "small integer" (either 0 or 1). Note that if p is a variable then
115781 ** reprepare is always enabled for that variable, regardless of its current
115782 ** binding. The RSI is only enabled if the current binding is a small
115783 ** integer. "RSI" stands for "Reprepare Small Integers".
115784 */
115785 SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr *p, int *pValue, Parse *pParse, int bRSI){
115786 int iSign = 1; /* Either +1 or -1. */
115787 while( 1/*exit-by-break*/ ){
115788 if( NEVER(p==0) ) return 0;
@@ -115801,11 +115875,10 @@
115801 pParse = 0;
115802 continue;
115803 }
115804 if( p->op==TK_VARIABLE && pParse!=0 ){
115805 sqlite3_value *pVal; /* The variable */
115806 int isSmall = 0; /* Only reprepare if change to/from small integer */
115807 int rc = 0; /* 1 if successful, 0 if failed */
115808 assert( iSign==1 );
115809 if( NEVER(pParse->pVdbe==0) ) break;
115810 if( (pParse->db->flags & SQLITE_EnableQPSG)!=0 ) break;
115811 pVal = sqlite3VdbeGetBoundValue(pParse->pReprepare, p->iColumn,
@@ -115815,18 +115888,15 @@
115815 if( sqlite3_value_type(pVal)==SQLITE_INTEGER
115816 && (vv = sqlite3_value_int64(pVal))>=0
115817 && vv<=0x7fffffff
115818 ){
115819 *pValue = (int)vv;
115820 if( bRSI ){
115821 isSmall = vv<=1;
115822 }
115823 rc = 1;
115824 }
115825 sqlite3ValueFree(pVal);
115826 }
115827 sqlite3VdbeReprepareOnBind(pParse->pVdbe, p->iColumn, isSmall);
115828 return rc;
115829 }
115830 break;
115831 }
115832 return 0;
@@ -116862,10 +116932,16 @@
116862 ExprSetVVAProperty(pExpr, EP_NoReduce);
116863 if( addrOnce ){
116864 sqlite3VdbeJumpHere(v, addrOnce);
116865 }
116866 sqlite3VdbeScanStatusRange(v, addrExplain, addrExplain, -1);
 
 
 
 
 
 
116867
116868 /* Subroutine return */
116869 assert( ExprUseYSub(pExpr) );
116870 assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn
116871 || pParse->nErr );
@@ -117082,11 +117158,10 @@
117082 rLhs = sqlite3GetTempRange(pParse, nVector);
117083 for(i=0; i<nVector; i++){
117084 testcase( aiMap[i]!=i );
117085 sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0);
117086 }
117087 sqlite3ReleaseTempReg(pParse, rLhsOrig);
117088 }
117089 }
117090
117091
117092 /* Step 2: Check to see if the LHS contains any NULL columns. If the
@@ -117618,11 +117693,11 @@
117618 ** pExpr is able to return a subtype, set pWalker->eCode and abort
117619 ** the search. If pExpr can never return a subtype, prune search.
117620 **
117621 ** The only expressions that can return a subtype are:
117622 **
117623 ** 1. A function
117624 ** 2. The no-op "+" operator
117625 ** 3. A CASE...END expression
117626 ** 4. A CAST() expression
117627 ** 5. A "expr COLLATE colseq" expression.
117628 **
@@ -117643,18 +117718,23 @@
117643 if( pExpr->op==TK_CASE || pExpr->op==TK_UPLUS
117644 || pExpr->op==TK_COLLATE || pExpr->op==TK_CAST
117645 ){
117646 return WRC_Continue;
117647 }
117648 if( pExpr->op!=TK_FUNCTION ){
117649 return WRC_Prune;
117650 }
117651 assert( ExprUseXList(pExpr) );
117652 db = pWalker->pParse->db;
117653 n = pExpr->x.pList ? pExpr->x.pList->nExpr : 0;
117654 pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
117655 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
 
 
 
 
 
117656 pWalker->eCode = 1;
117657 return WRC_Abort;
117658 }
117659 return WRC_Continue;
117660 }
@@ -117720,14 +117800,20 @@
117720 continue;
117721 }
117722
117723 v = pParse->pVdbe;
117724 assert( v!=0 );
117725 if( p->bMaybeNullRow ){
117726 /* If the index is on a NULL row due to an outer join, then we
117727 ** cannot extract the value from the index. The value must be
117728 ** computed using the original expression. */
 
 
 
 
 
 
117729 int addr = sqlite3VdbeCurrentAddr(v);
117730 sqlite3VdbeAddOp3(v, OP_IfNullRow, p->iIdxCur, addr+3, target);
117731 VdbeCoverage(v);
117732 sqlite3VdbeAddOp3(v, OP_Column, p->iIdxCur, p->iIdxCol, target);
117733 VdbeComment((v, "%s expr-column %d", p->zIdxName, p->iIdxCol));
@@ -120450,11 +120536,11 @@
120450 assert( pOBList->nExpr>0 );
120451 assert( pItem->bOBUnique==0 );
120452 if( pOBList->nExpr==1
120453 && nArg==1
120454 && sqlite3ExprCompare(0,pOBList->a[0].pExpr,
120455 pExpr->x.pList->a[0].pExpr,0)==0
120456 ){
120457 pItem->bOBPayload = 0;
120458 pItem->bOBUnique = ExprHasProperty(pExpr, EP_Distinct);
120459 }else{
120460 pItem->bOBPayload = 1;
@@ -120538,10 +120624,17 @@
120538 ** Deallocate a register, making available for reuse for some other
120539 ** purpose.
120540 */
120541 SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){
120542 if( iReg ){
 
 
 
 
 
 
 
120543 sqlite3VdbeReleaseRegisters(pParse, iReg, 1, 0, 0);
120544 if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){
120545 pParse->aTempReg[pParse->nTempReg++] = iReg;
120546 }
120547 }
@@ -127356,10 +127449,11 @@
127356
127357 if( db->nSchemaLock==0 ){
127358 for(i=0; i<db->nDb; i++){
127359 if( DbHasProperty(db, i, DB_ResetWanted) ){
127360 sqlite3SchemaClear(db->aDb[i].pSchema);
 
127361 }
127362 }
127363 }
127364 }
127365
@@ -134158,19 +134252,22 @@
134158 }
134159 nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
134160 regBase = sqlite3GetTempRange(pParse, nCol);
134161 if( pPrior && (regBase!=regPrior || pPrior->pPartIdxWhere) ) pPrior = 0;
134162 for(j=0; j<nCol; j++){
 
134163 if( pPrior
134164 && pPrior->aiColumn[j]==pIdx->aiColumn[j]
134165 && pPrior->aiColumn[j]!=XN_EXPR
134166 ){
134167 /* This column was already computed by the previous index */
134168 continue;
134169 }
134170 sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iDataCur, j, regBase+j);
134171 if( pIdx->aiColumn[j]>=0 ){
 
 
134172 /* If the column affinity is REAL but the number is an integer, then it
134173 ** might be stored in the table as an integer (using a compact
134174 ** representation) then converted to REAL by an OP_RealAffinity opcode.
134175 ** But we are getting ready to store this value back into an index, where
134176 ** it should be converted by to INTEGER again. So omit the
@@ -134530,10 +134627,18 @@
134530 str.printfFlags = SQLITE_PRINTF_SQLFUNC;
134531 sqlite3_str_appendf(&str, zFormat, &x);
134532 sqlite3_result_str(context, &str, SQLITE_XFER);
134533 }
134534 }
 
 
 
 
 
 
 
 
134535
134536 /*
134537 ** Implementation of the substr() function.
134538 **
134539 ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1.
@@ -134614,10 +134719,24 @@
134614 }
134615 p1 -= p2;
134616 }
134617 assert( p1>=0 && p2>=0 );
134618 if( p0type!=SQLITE_BLOB ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134619 for( ; p1>0; p1--){
134620 /* vvvvvv---- See tag-20260418-01 */
134621 if( (u8)(z[0]-1)<(0x80-1) ){
134622 z++;
134623 }else if( z[0]==0 ){
@@ -134991,22 +135110,33 @@
134991 ** c or cx.
134992 */
134993 if( c<0x80 ){
134994 char zStop[3];
134995 int bMatch;
 
 
 
 
 
 
 
 
134996 if( noCase ){
134997 zStop[0] = sqlite3Toupper(c);
134998 zStop[1] = sqlite3Tolower(c);
134999 zStop[2] = 0;
 
 
135000 }else{
135001 zStop[0] = c;
135002 zStop[1] = 0;
135003 }
135004 while(1){
135005 zString += strcspn((const char*)zString, zStop);
135006 if( zString[0]==0 ) break;
135007 zString++;
 
135008 bMatch = patternCompare(zPattern,zString,pInfo,matchOther);
135009 if( bMatch!=SQLITE_NOMATCH ) return bMatch;
135010 }
135011 }else{
135012 int bMatch;
@@ -135280,18 +135410,24 @@
135280 static void compileoptiongetFunc(
135281 sqlite3_context *context,
135282 int argc,
135283 sqlite3_value **argv
135284 ){
135285 int n;
 
135286 assert( argc==1 );
135287 UNUSED_PARAMETER(argc);
135288 /* IMP: R-04922-24076 The sqlite_compileoption_get() SQL function
135289 ** is a wrapper around the sqlite3_compileoption_get() C/C++ function.
135290 */
135291 n = sqlite3_value_int(argv[0]);
135292 sqlite3_result_text(context, sqlite3_compileoption_get(n), -1, SQLITE_STATIC);
 
 
 
 
 
135293 }
135294 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
135295
135296 /* Array for converting from half-bytes (nybbles) into ASCII hex
135297 ** digits. */
@@ -153606,11 +153742,13 @@
153606 static int renumberCursorsCb(Walker *pWalker, Expr *pExpr){
153607 int op = pExpr->op;
153608 if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){
153609 renumberCursorDoMapping(pWalker, &pExpr->iTable);
153610 }
153611 if( ExprHasProperty(pExpr, EP_OuterON) ){
 
 
153612 renumberCursorDoMapping(pWalker, &pExpr->w.iJoin);
153613 }
153614 return WRC_Continue;
153615 }
153616
@@ -154486,11 +154624,11 @@
154486 /*
154487 ** The WHERE-clause constant propagation optimization.
154488 **
154489 ** If the WHERE clause contains terms of the form COLUMN=CONSTANT or
154490 ** CONSTANT=COLUMN that are top-level AND-connected terms that are not
154491 ** part of a ON clause from a LEFT JOIN, then throughout the query
154492 ** replace all other occurrences of COLUMN with CONSTANT.
154493 **
154494 ** For example, the query:
154495 **
154496 ** SELECT * FROM t1, t2, t3 WHERE t1.a=39 AND t2.b=t1.a AND t3.c=t2.b
@@ -164036,10 +164174,11 @@
164036 int addrBrk; /* Jump here to break out of the loop */
164037 int addrHalt; /* Abort the query due to empty table or similar */
164038 int addrNxt; /* Jump here to start the next IN combination */
164039 int addrSkip; /* Jump here for next iteration of skip-scan */
164040 int addrCont; /* Jump here to continue with the next loop cycle */
 
164041 int addrFirst; /* First instruction of interior of the loop */
164042 int addrBody; /* Beginning of the body of this loop */
164043 int regBignull; /* big-null flag reg. True if a NULL-scan is needed */
164044 int addrBignull; /* Jump here for next part of big-null scan */
164045 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
@@ -166119,10 +166258,131 @@
166119 }
166120 }
166121 }
166122 return 1;
166123 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166124
166125 /*
166126 ** Generate code for the start of the iLevel-th loop in the WHERE clause
166127 ** implementation described by pWInfo.
166128 */
@@ -166138,15 +166398,16 @@
166138 int iCur; /* The VDBE cursor for the table */
166139 int addrNxt; /* Where to jump to continue with the next IN case */
166140 int bRev; /* True if we need to scan in reverse order */
166141 WhereLoop *pLoop; /* The WhereLoop object being coded */
166142 WhereClause *pWC; /* Decomposition of the entire WHERE clause */
166143 WhereTerm *pTerm; /* A WHERE clause term */
166144 sqlite3 *db; /* Database connection */
166145 SrcItem *pTabItem; /* FROM clause term being coded */
166146 int addrBrk; /* Jump here to break out of the loop */
166147 int addrCont; /* Jump here to continue with next cycle */
 
166148 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
166149 int iReleaseReg = 0; /* Temp register to free before returning */
166150 Index *pIdx = 0; /* Index used by loop (if any) */
166151 int iLoop; /* Iteration of constraint generator loop */
166152
@@ -166187,10 +166448,11 @@
166187 ** there are no IN operators in the constraints, the "addrNxt" label
166188 ** is the same as "addrBrk".
166189 */
166190 addrBrk = pLevel->addrNxt = pLevel->addrBrk;
166191 addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(pParse);
 
166192
166193 /* If this is the right table of a LEFT OUTER JOIN, allocate and
166194 ** initialize a memory cell that records if this table matches any
166195 ** row of the left table of the join.
166196 */
@@ -166362,19 +166624,20 @@
166362 testcase( pTerm->wtFlags & TERM_VIRTUAL );
166363 iReleaseReg = ++pParse->nMem;
166364 iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
166365 if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg);
166366 addrNxt = pLevel->addrNxt;
 
166367 if( pLevel->regFilter ){
166368 sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt);
166369 VdbeCoverage(v);
166370 sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrNxt,
166371 iRowidReg, 1);
166372 VdbeCoverage(v);
166373 filterPullDown(pParse, pWInfo, iLevel, addrNxt, notReady);
166374 }
166375 sqlite3VdbeAddOp3(v, OP_SeekRowid, iCur, addrNxt, iRowidReg);
166376 VdbeCoverage(v);
166377 pLevel->op = OP_Noop;
166378 }else if( (pLoop->wsFlags & WHERE_IPK)!=0
166379 && (pLoop->wsFlags & WHERE_COLUMN_RANGE)!=0
166380 ){
@@ -166573,13 +166836,10 @@
166573 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
166574 if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
166575 assert( pRangeStart!=0 ); /* LIKE opt constraints */
166576 assert( pRangeStart->wtFlags & TERM_LIKEOPT ); /* occur in pairs */
166577 pLevel->iLikeRepCntr = (u32)++pParse->nMem;
166578 sqlite3VdbeAddOp2(v, OP_Integer, 1, (int)pLevel->iLikeRepCntr);
166579 VdbeComment((v, "LIKE loop counter"));
166580 pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
166581 /* iLikeRepCntr actually stores 2x the counter register number. The
166582 ** bottom bit indicates whether the search order is ASC or DESC. */
166583 testcase( bRev );
166584 testcase( pIdx->aSortOrder[nEq]==SQLITE_SO_DESC );
166585 assert( (bRev & ~1)==0 );
@@ -166639,14 +166899,29 @@
166639 ** starting at regBase.
166640 */
166641 codeCursorHint(pTabItem, pWInfo, pLevel, pRangeEnd);
166642 regBase = codeAllEqualityTerms(pParse,pLevel,bRev,nExtraReg,&zStartAff);
166643 assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166644 if( zStartAff && nTop ){
166645 zEndAff = sqlite3DbStrDup(db, &zStartAff[nEq]);
166646 }
166647 addrNxt = (regBignull ? pLevel->addrBignull : pLevel->addrNxt);
 
166648
166649 testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
166650 testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
166651 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
166652 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_GE)!=0 );
@@ -166697,11 +166972,11 @@
166697 sqlite3VdbeAddOp2(v, OP_Integer, 1, regBignull);
166698 VdbeComment((v, "NULL-scan pass ctr"));
166699 }
166700 if( pLevel->regFilter ){
166701 assert( sqlite3WhereLoopBloomable(pLoop) );
166702 sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrNxt,
166703 regBase, nEq);
166704 VdbeCoverage(v);
166705 filterPullDown(pParse, pWInfo, iLevel, addrNxt, notReady);
166706 }
166707
@@ -166724,11 +166999,11 @@
166724 sqlite3VdbeChangeP2(v, addrSeekScan, sqlite3VdbeCurrentAddr(v)+1);
166725 addrSeekScan = 0;
166726 }
166727 VdbeCoverage(v);
166728 }
166729 sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
166730 VdbeCoverage(v);
166731 VdbeCoverageIf(v, op==OP_Rewind); testcase( op==OP_Rewind );
166732 VdbeCoverageIf(v, op==OP_Last); testcase( op==OP_Last );
166733 VdbeCoverageIf(v, op==OP_SeekGT); testcase( op==OP_SeekGT );
166734 VdbeCoverageIf(v, op==OP_SeekGE); testcase( op==OP_SeekGE );
@@ -169965,16 +170240,20 @@
169965 Expr *pX = pTerm->pExpr;
169966 Expr inexpr;
169967
169968 assert( pTerm->eOperator & WO_IN );
169969
169970 if( sqlite3ExprIsVector(pX->pLeft) ){
169971 int iField = pTerm->u.x.iField - 1;
169972 inexpr.flags = 0;
169973 inexpr.op = TK_EQ;
169974 inexpr.pLeft = pX->pLeft->x.pList->a[iField].pExpr;
169975 assert( ExprUseXSelect(pX) );
 
 
 
 
169976 inexpr.pRight = pX->x.pSelect->pEList->a[iField].pExpr;
169977 pX = &inexpr;
169978 }
169979
169980 if( sqlite3IndexAffinityOk(pX, idxaff) ){
@@ -173573,39 +173852,55 @@
173573 }
173574
173575 if( (pPart->op==TK_EQ || pPart->op==TK_IS) ){
173576 Expr *pLeft = pPart->pLeft;
173577 Expr *pRight = pPart->pRight;
173578 u8 aff;
 
 
173579
173580 if( pLeft->op!=TK_COLUMN ) return;
173581 if( !sqlite3ExprIsConstant(0, pRight) ) return;
173582 if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pParse, pPart)) ) return;
173583 if( pLeft->iColumn<0 ) return;
173584 aff = pIdx->pTable->aCol[pLeft->iColumn].affinity;
173585 if( aff>=SQLITE_AFF_TEXT ){
173586 if( pItem ){
173587 sqlite3 *db = pParse->db;
173588 IndexedExpr *p = (IndexedExpr*)sqlite3DbMallocRaw(db, sizeof(*p));
173589 if( p ){
173590 int bNullRow = (pItem->fg.jointype&(JT_LEFT|JT_LTORJ))!=0;
173591 p->pExpr = sqlite3ExprDup(db, pRight, 0);
173592 p->iDataCur = pItem->iCursor;
173593 p->iIdxCur = iIdxCur;
173594 p->iIdxCol = pLeft->iColumn;
173595 p->bMaybeNullRow = bNullRow;
173596 p->pIENext = pParse->pIdxPartExpr;
173597 p->aff = aff;
173598 pParse->pIdxPartExpr = p;
173599 if( p->pIENext==0 ){
173600 void *pArg = (void*)&pParse->pIdxPartExpr;
173601 sqlite3ParserAddCleanup(pParse, whereIndexedExprCleanup, pArg);
173602 }
173603 }
173604 }else if( pLeft->iColumn<(BMS-1) ){
173605 *pMask &= ~((Bitmask)1 << pLeft->iColumn);
173606 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173607 }
173608 }
173609 }
173610
173611
@@ -173834,11 +174129,13 @@
173834 if( pProbe->isCovering ){
173835 m = 0;
173836 pNew->wsFlags = WHERE_IDX_ONLY | WHERE_INDEXED;
173837 }else{
173838 m = pSrc->colUsed & pProbe->colNotIdxed;
173839 if( pProbe->pPartIdxWhere ){
 
 
173840 wherePartIdxExpr(
173841 pWInfo->pParse, pProbe, pProbe->pPartIdxWhere, &m, 0, 0
173842 );
173843 }
173844 pNew->wsFlags = WHERE_INDEXED;
@@ -174718,17 +175015,17 @@
174718 ** long as the subquery is materialized. If the subquery is
174719 ** implemented as a co-routine, the sort orders must be in the same
174720 ** direction because there is no way to run a co-routine backwards.
174721 */
174722 static SQLITE_NOINLINE int wherePathMatchSubqueryOB(
174723 WhereInfo *pWInfo, /* The WHERE clause */
174724 WhereLoop *pLoop, /* The nested loop term that is a subquery */
174725 int iLoop, /* Which level of the nested loop. 0==outermost */
174726 int iCur, /* Cursor used by the this loop */
174727 ExprList *pOrderBy, /* The ORDER BY clause on the whole query */
174728 Bitmask *pRevMask, /* When loops need to go in reverse order */
174729 Bitmask *pOBSat /* Which terms of pOrderBy are satisfied so far */
 
174730 ){
174731 int iOB; /* Index into pOrderBy->a[] */
174732 int jSub; /* Index into pSubOB->a[] */
174733 u8 rev = 0; /* True if iOB and jSub sort in opposite directions */
174734 u8 revIdx = 0; /* Sort direction for jSub */
@@ -174742,11 +175039,11 @@
174742 if( pSubOB->a[jSub].u.x.iOrderByCol==0 ) break;
174743 pOBExpr = pOrderBy->a[iOB].pExpr;
174744 if( pOBExpr->op!=TK_COLUMN && pOBExpr->op!=TK_AGG_COLUMN ) break;
174745 if( pOBExpr->iTable!=iCur ) break;
174746 if( pOBExpr->iColumn!=pSubOB->a[jSub].u.x.iOrderByCol-1 ) break;
174747 if( (pWInfo->wctrlFlags & WHERE_GROUPBY)==0 ){
174748 u8 sfOB = pOrderBy->a[iOB].fg.sortFlags; /* sortFlags for iOB */
174749 u8 sfSub = pSubOB->a[jSub].fg.sortFlags; /* sortFlags for jSub */
174750 if( (sfSub & KEYINFO_ORDER_BIGNULL) != (sfOB & KEYINFO_ORDER_BIGNULL) ){
174751 break;
174752 }
@@ -174924,20 +175221,20 @@
174924
174925 if( (pLoop->wsFlags & WHERE_ONEROW)==0 ){
174926 if( pLoop->wsFlags & WHERE_IPK ){
174927 if( pLoop->u.btree.pOrderBy
174928 && OptimizationEnabled(db, SQLITE_OrderBySubq)
174929 && wherePathMatchSubqueryOB(pWInfo,pLoop,iLoop,iCur,
174930 pOrderBy,pRevMask, &obSat)
174931 ){
174932 nColumn = 0;
174933 isOrderDistinct = 0;
174934 }else{
174935 nColumn = 1;
174936 }
174937 pIndex = 0;
174938 nKeyCol = 0;
174939 }else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
174940 return 0;
174941 }else{
174942 nKeyCol = pIndex->nKeyCol;
174943 nColumn = pIndex->nColumn;
@@ -175074,11 +175371,18 @@
175074 if( rev ) *pRevMask |= MASKBIT(iLoop);
175075 revSet = 1;
175076 }
175077 }
175078 if( isMatch && (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL) ){
175079 if( j==pLoop->u.btree.nEq ){
 
 
 
 
 
 
 
175080 pLoop->wsFlags |= WHERE_BIGNULL_SORT;
175081 }else{
175082 isMatch = 0;
175083 }
175084 }
@@ -175088,11 +175392,12 @@
175088 distinctColumns = 1;
175089 }
175090 obSat |= MASKBIT(i);
175091 }else{
175092 /* No match found */
175093 if( j==0 || j<nKeyCol ){
 
175094 testcase( isOrderDistinct!=0 );
175095 isOrderDistinct = 0;
175096 }
175097 break;
175098 }
@@ -177249,10 +177554,21 @@
177249 if( pTabList->a[pLevel->iFrom].fg.fromExists ){
177250 /* This is an EXISTS-to-JOIN optimization loop. If this loop sees a
177251 ** successful row, it should break out of itself. */
177252 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrBrk);
177253 VdbeComment((v, "EXISTS break %d", i));
 
 
 
 
 
 
 
 
 
 
 
177254 }
177255 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
177256 if( pLevel->op!=OP_Noop ){
177257 sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
177258 sqlite3VdbeChangeP5(v, pLevel->p5);
@@ -177270,14 +177586,35 @@
177270 sqlite3VdbeResolveLabel(v, pLevel->addrBignull);
177271 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, pLevel->regBignull, pLevel->p2-1);
177272 VdbeCoverage(v);
177273 }
177274 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177275 if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){
177276 struct InLoop *pIn;
177277 int j;
177278 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
177279 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
177280 assert( sqlite3VdbeGetOp(v, pIn->addrInTop+1)->opcode==OP_IsNull
177281 || pParse->db->mallocFailed );
177282 sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
177283 if( pIn->eEndLoopOp!=OP_Noop ){
@@ -177325,17 +177662,10 @@
177325 sqlite3VdbeGoto(v, pLevel->addrSkip);
177326 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
177327 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
177328 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
177329 }
177330 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
177331 if( pLevel->addrLikeRep ){
177332 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, (int)(pLevel->iLikeRepCntr>>1),
177333 pLevel->addrLikeRep);
177334 VdbeCoverage(v);
177335 }
177336 #endif
177337 if( pLevel->iLeftJoin ){
177338 int ws = pLoop->wsFlags;
177339 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
177340 assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 );
177341 if( (ws & WHERE_IDX_ONLY)==0 ){
@@ -212949,17 +213279,15 @@
212949 /* #include <string.h> */
212950
212951 /* #include "fts3_tokenizer.h" */
212952
212953 /*
212954 ** The following two macros - READ_UTF8 and WRITE_UTF8 - have been copied
212955 ** from the sqlite3 source file utf.c. If this file is compiled as part
212956 ** of the amalgamation, they are not required.
212957 */
212958 #ifndef SQLITE_AMALGAMATION
212959
212960 static const unsigned char sqlite3Utf8Trans1[] = {
212961 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
212962 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
212963 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
212964 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
212965 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -212966,43 +213294,41 @@
212966 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
212967 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
212968 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
212969 };
212970
212971 #define READ_UTF8(zIn, zTerm, c) \
212972 c = *(zIn++); \
212973 if( c>=0xc0 ){ \
212974 c = sqlite3Utf8Trans1[c-0xc0]; \
212975 while( zIn!=zTerm && (*zIn & 0xc0)==0x80 ){ \
212976 c = (c<<6) + (0x3f & *(zIn++)); \
212977 } \
212978 if( c<0x80 \
212979 || (c&0xFFFFF800)==0xD800 \
212980 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
212981 }
212982
212983 #define WRITE_UTF8(zOut, c) { \
212984 if( c<0x00080 ){ \
212985 *zOut++ = (u8)(c&0xFF); \
212986 } \
212987 else if( c<0x00800 ){ \
212988 *zOut++ = 0xC0 + (u8)((c>>6)&0x1F); \
212989 *zOut++ = 0x80 + (u8)(c & 0x3F); \
212990 } \
212991 else if( c<0x10000 ){ \
212992 *zOut++ = 0xE0 + (u8)((c>>12)&0x0F); \
212993 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
212994 *zOut++ = 0x80 + (u8)(c & 0x3F); \
212995 }else{ \
212996 *zOut++ = 0xF0 + (u8)((c>>18) & 0x07); \
212997 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F); \
212998 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
212999 *zOut++ = 0x80 + (u8)(c & 0x3F); \
213000 } \
213001 }
213002
213003 #endif /* ifndef SQLITE_AMALGAMATION */
213004
213005 typedef struct unicode_tokenizer unicode_tokenizer;
213006 typedef struct unicode_cursor unicode_cursor;
213007
213008 struct unicode_tokenizer {
@@ -213065,11 +213391,11 @@
213065 int nEntry = 0;
213066
213067 assert( bAlnum==0 || bAlnum==1 );
213068
213069 while( z<zTerm ){
213070 READ_UTF8(z, zTerm, iCode);
213071 assert( (sqlite3FtsUnicodeIsalnum((int)iCode) & 0xFFFFFFFE)==0 );
213072 if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum
213073 && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
213074 ){
213075 nEntry++;
@@ -213084,11 +213410,11 @@
213084 if( aNew==0 ) return SQLITE_NOMEM;
213085 nNew = p->nException;
213086
213087 z = (const unsigned char *)zIn;
213088 while( z<zTerm ){
213089 READ_UTF8(z, zTerm, iCode);
213090 if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum
213091 && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
213092 ){
213093 int i, j;
213094 for(i=0; i<nNew && aNew[i]<(int)iCode; i++);
@@ -213256,11 +213582,11 @@
213256
213257 /* Scan past any delimiter characters before the start of the next token.
213258 ** Return SQLITE_DONE early if this takes us all the way to the end of
213259 ** the input. */
213260 while( z<zTerm ){
213261 READ_UTF8(z, zTerm, iCode);
213262 if( unicodeIsAlnum(p, (int)iCode) ) break;
213263 zStart = z;
213264 }
213265 if( zStart>=zTerm ) return SQLITE_DONE;
213266
@@ -213279,16 +213605,16 @@
213279
213280 /* Write the folded case of the last character read to the output */
213281 zEnd = z;
213282 iOut = sqlite3FtsUnicodeFold((int)iCode, p->eRemoveDiacritic);
213283 if( iOut ){
213284 WRITE_UTF8(zOut, iOut);
213285 }
213286
213287 /* If the cursor is not at EOF, read the next character */
213288 if( z>=zTerm ) break;
213289 READ_UTF8(z, zTerm, iCode);
213290 }while( unicodeIsAlnum(p, (int)iCode)
213291 || sqlite3FtsUnicodeIsdiacritic((int)iCode)
213292 );
213293
213294 /* Set the output variables and return. */
@@ -214107,10 +214433,11 @@
214107 /*
214108 ** Allowed values for the flgs argument to jsonParseFuncArg();
214109 */
214110 #define JSON_EDITABLE 0x01 /* Generate a writable JsonParse object */
214111 #define JSON_KEEPERROR 0x02 /* Return non-NULL even if there is an error */
 
214112
214113 /**************************************************************************
214114 ** Forward references
214115 **************************************************************************/
214116 static void jsonReturnStringAsBlob(JsonString*);
@@ -217550,11 +217877,13 @@
217550 assert( ctx!=0 );
217551 eType = sqlite3_value_type(pArg);
217552 if( eType==SQLITE_NULL ){
217553 return 0;
217554 }
217555 pFromCache = jsonCacheSearch(ctx, pArg);
 
 
217556 if( pFromCache ){
217557 pFromCache->nJPRef++;
217558 if( (flgs & JSON_EDITABLE)==0 ){
217559 return pFromCache;
217560 }
@@ -218625,11 +218954,11 @@
218625 default: {
218626 JsonParse px;
218627 if( (flags & 0x3)==0 ) break;
218628 memset(&px, 0, sizeof(px));
218629
218630 p = jsonParseFuncArg(ctx, argv[0], JSON_KEEPERROR);
218631 if( p ){
218632 if( p->oom ){
218633 sqlite3_result_error_nomem(ctx);
218634 }else if( p->nErr ){
218635 /* no-op */
@@ -219218,21 +219547,20 @@
219218 */
219219 static int jsonEachPathLength(JsonEachCursor *p){
219220 u32 n = p->path.nUsed;
219221 char *z = p->path.zBuf;
219222 if( p->iRowid==0 && p->bRecursive && n>=2 ){
219223 while( n>1 ){
219224 n--;
219225 if( z[n]=='[' || z[n]=='.' ){
219226 u32 x, sz = 0;
219227 char cSaved = z[n];
219228 z[n] = 0;
219229 assert( p->sParse.eEdit==0 );
219230 x = jsonLookupStep(&p->sParse, 0, z+1, 0);
219231 z[n] = cSaved;
219232 if( JSON_LOOKUP_ISERROR(x) ) continue;
219233 if( x + jsonbPayloadSize(&p->sParse, x, &sz) == p->i ) break;
219234 }
219235 }
219236 }
219237 return n;
219238 }
@@ -246043,11 +246371,26 @@
246043 }
246044
246045 return rc;
246046 }
246047
246048
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246049
246050 /*************************************************************************
246051 ** Start of highlight() implementation.
246052 */
246053 typedef struct HighlightContext HighlightContext;
@@ -246232,11 +246575,11 @@
246232 sqlite3_result_text(pCtx, (const char*)ctx.zOut, -1, SQLITE_TRANSIENT);
246233 }
246234 sqlite3_free(ctx.zOut);
246235 }
246236 if( rc!=SQLITE_OK ){
246237 sqlite3_result_error_code(pCtx, rc);
246238 }
246239 }
246240 /*
246241 ** End of highlight() implementation.
246242 **************************************************************************/
@@ -246526,11 +246869,11 @@
246526 }
246527 }
246528 if( rc==SQLITE_OK ){
246529 sqlite3_result_text(pCtx, (const char*)ctx.zOut, -1, SQLITE_TRANSIENT);
246530 }else{
246531 sqlite3_result_error_code(pCtx, rc);
246532 }
246533 sqlite3_free(ctx.zOut);
246534 sqlite3_free(aSeen);
246535 sqlite3_free(sFinder.aFirst);
246536 }
@@ -246692,11 +247035,11 @@
246692 ( aFreq[i] + k1 * (1 - b + b * D / pData->avgdl) )
246693 );
246694 }
246695 sqlite3_result_double(pCtx, -1.0 * score);
246696 }else{
246697 sqlite3_result_error_code(pCtx, rc);
246698 }
246699 }
246700
246701 /*
246702 ** Implementation of fts5_get_locale() function.
@@ -246730,17 +247073,17 @@
246730 return;
246731 }
246732
246733 iCol = fts5ValueClampedInt(apVal[0]);
246734 if( iCol<0 || iCol>=pApi->xColumnCount(pFts) ){
246735 sqlite3_result_error_code(pCtx, SQLITE_RANGE);
246736 return;
246737 }
246738
246739 rc = pApi->xColumnLocale(pFts, iCol, &zLocale, &nLocale);
246740 if( rc!=SQLITE_OK ){
246741 sqlite3_result_error_code(pCtx, rc);
246742 return;
246743 }
246744
246745 sqlite3_result_text(pCtx, zLocale, nLocale, SQLITE_TRANSIENT);
246746 }
@@ -265407,11 +265750,11 @@
265407 int nArg, /* Number of args */
265408 sqlite3_value **apUnused /* Function arguments */
265409 ){
265410 assert( nArg==0 );
265411 UNUSED_PARAM2(nArg, apUnused);
265412 sqlite3_result_text(pCtx, "fts5: 2026-10-09 11:47:51 a3332bd623d997921c3186433cd1eab0c9413aa0f68d93b1731cf80128ec3a36", -1, SQLITE_TRANSIENT);
265413 }
265414
265415 /*
265416 ** Implementation of fts5_locale(LOCALE, TEXT) function.
265417 **
@@ -265886,17 +266229,17 @@
265886 if( eStmt>FTS5_STMT_LOOKUP2 ) f |= SQLITE_PREPARE_NO_VTAB;
265887 p->pConfig->bLock++;
265888 rc = sqlite3_prepare_v3(pC->db, zSql, -1, f, &p->aStmt[eStmt], 0);
265889 p->pConfig->bLock--;
265890 sqlite3_free(zSql);
265891 if( rc!=SQLITE_OK && pzErrMsg ){
265892 *pzErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pC->db));
265893 }
265894 if( rc==SQLITE_ERROR && eStmt>FTS5_STMT_LOOKUP2 && eStmt<FTS5_STMT_SCAN ){
265895 /* One of the internal tables - not the %_content table - is missing.
265896 ** This counts as a corrupted table. */
265897 rc = SQLITE_CORRUPT;
 
 
 
265898 }
265899 }
265900 }
265901
265902 *ppStmt = p->aStmt[eStmt];
@@ -267411,17 +267754,14 @@
267411 ** Start of unicode61 tokenizer implementation.
267412 */
267413
267414
267415 /*
267416 ** The following two macros - READ_UTF8 and WRITE_UTF8 - have been copied
267417 ** from the sqlite3 source file utf.c. If this file is compiled as part
267418 ** of the amalgamation, they are not required.
267419 */
267420 #ifndef SQLITE_AMALGAMATION
267421
267422 static const unsigned char sqlite3Utf8Trans1[] = {
267423 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
267424 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
267425 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
267426 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
267427 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -267428,49 +267768,47 @@
267428 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
267429 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
267430 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
267431 };
267432
267433 #define READ_UTF8(zIn, zTerm, c) \
267434 c = *(zIn++); \
267435 if( c>=0xc0 ){ \
267436 c = sqlite3Utf8Trans1[c-0xc0]; \
267437 while( zIn<zTerm && (*zIn & 0xc0)==0x80 ){ \
267438 c = (c<<6) + (0x3f & *(zIn++)); \
267439 } \
267440 if( c<0x80 \
267441 || (c&0xFFFFF800)==0xD800 \
267442 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
267443 }
267444
267445
267446 #define WRITE_UTF8(zOut, c) { \
267447 if( c<0x00080 ){ \
267448 *zOut++ = (unsigned char)(c&0xFF); \
267449 } \
267450 else if( c<0x00800 ){ \
267451 *zOut++ = 0xC0 + (unsigned char)((c>>6)&0x1F); \
267452 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
267453 } \
267454 else if( c<0x10000 ){ \
267455 *zOut++ = 0xE0 + (unsigned char)((c>>12)&0x0F); \
267456 *zOut++ = 0x80 + (unsigned char)((c>>6) & 0x3F); \
267457 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
267458 }else{ \
267459 *zOut++ = 0xF0 + (unsigned char)((c>>18) & 0x07); \
267460 *zOut++ = 0x80 + (unsigned char)((c>>12) & 0x3F); \
267461 *zOut++ = 0x80 + (unsigned char)((c>>6) & 0x3F); \
267462 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
267463 } \
267464 }
267465
267466 #endif /* ifndef SQLITE_AMALGAMATION */
267467
267468 #define FTS5_SKIP_UTF8(zIn) { \
267469 if( ((unsigned char)(*(zIn++)))>=0xc0 ){ \
267470 while( (((unsigned char)*zIn) & 0xc0)==0x80 ){ zIn++; } \
267471 } \
267472 }
267473
267474 typedef struct Unicode61Tokenizer Unicode61Tokenizer;
267475 struct Unicode61Tokenizer {
267476 unsigned char aTokenChar[128]; /* ASCII range token characters */
@@ -267505,11 +267843,11 @@
267505 const unsigned char *zCsr = (const unsigned char*)z;
267506 const unsigned char *zTerm = (const unsigned char*)&z[n];
267507 while( zCsr<zTerm ){
267508 u32 iCode;
267509 int bToken;
267510 READ_UTF8(zCsr, zTerm, iCode);
267511 if( iCode<128 ){
267512 p->aTokenChar[iCode] = (unsigned char)bTokenChars;
267513 }else{
267514 bToken = p->aCategory[sqlite3Fts5UnicodeCategory(iCode)];
267515 assert( (bToken==0 || bToken==1) );
@@ -267709,11 +268047,11 @@
267709 if( zCsr>=zTerm ) goto tokenize_done;
267710 if( *zCsr & 0x80 ) {
267711 /* A character outside of the ascii range. Skip past it if it is
267712 ** a separator character. Or break out of the loop if it is not. */
267713 is = zCsr - (unsigned char*)pText;
267714 READ_UTF8(zCsr, zTerm, iCode);
267715 if( fts5UnicodeIsAlnum(p, iCode) ){
267716 goto non_ascii_tokenchar;
267717 }
267718 }else{
267719 if( a[*zCsr] ){
@@ -267745,15 +268083,15 @@
267745 }
267746
267747 if( *zCsr & 0x80 ){
267748 /* An non-ascii-range character. Fold it into the output buffer if
267749 ** it is a token character, or break out of the loop if it is not. */
267750 READ_UTF8(zCsr, zTerm, iCode);
267751 if( fts5UnicodeIsAlnum(p,iCode)||sqlite3Fts5UnicodeIsdiacritic(iCode) ){
267752 non_ascii_tokenchar:
267753 iCode = sqlite3Fts5UnicodeFold(iCode, p->eRemoveDiacritic);
267754 if( iCode ) WRITE_UTF8(zOut, iCode);
267755 }else{
267756 break;
267757 }
267758 }else if( a[*zCsr]==0 ){
267759 /* An ascii-range separator character. End of token. */
@@ -268604,14 +268942,14 @@
268604 /* Populate aBuf[] with the characters for the first trigram. */
268605 for(ii=0; ii<3; ii++){
268606 do {
268607 aStart[ii] = zIn - (const unsigned char*)pText;
268608 if( zIn>=zEof ) return SQLITE_OK;
268609 READ_UTF8(zIn, zEof, iCode);
268610 if( p->bFold ) iCode = sqlite3Fts5UnicodeFold(iCode, p->iFoldParam);
268611 }while( iCode==0 );
268612 WRITE_UTF8(zOut, iCode);
268613 }
268614
268615 /* At the start of each iteration of this loop:
268616 **
268617 ** aBuf: Contains 3 characters. The 3 characters of the next trigram.
@@ -268629,11 +268967,11 @@
268629 iNext = zIn - (const unsigned char*)pText;
268630 if( zIn>=zEof ){
268631 iCode = 0;
268632 break;
268633 }
268634 READ_UTF8(zIn, zEof, iCode);
268635 if( p->bFold ) iCode = sqlite3Fts5UnicodeFold(iCode, p->iFoldParam);
268636 }while( iCode==0 );
268637
268638 /* Pass the current trigram back to fts5 */
268639 rc = xToken(pCtx, 0, aBuf, zOut-aBuf, aStart[0], iNext);
@@ -268643,11 +268981,11 @@
268643 ** with codepoint iCode. */
268644 z1 = aBuf;
268645 FTS5_SKIP_UTF8(z1);
268646 memmove(aBuf, z1, zOut - z1);
268647 zOut -= (z1 - aBuf);
268648 WRITE_UTF8(zOut, iCode);
268649
268650 /* Update the aStart[] array */
268651 aStart[0] = aStart[1];
268652 aStart[1] = aStart[2];
268653 aStart[2] = iNext;
268654
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.55.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 668541c592b89d32716420615450d55d9faf with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -465,16 +465,16 @@
465 **
466 ** See also: [sqlite3_libversion()],
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.55.0"
471 #define SQLITE_VERSION_NUMBER 3055000
472 #define SQLITE_SOURCE_ID "2026-10-16 14:31:53 668541c592b89d32716420615450d55d9faf89da8a8e389c673973d8383cca98"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-10-16T14:31:53.543Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -4399,11 +4399,11 @@
4399 ** parameter on F or if the value of P does not match any of the
4400 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4401 **
4402 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4403 ** 64-bit signed integer and returns that integer, or D if P does not
4404 ** exist or if the value of P is something other than an integer.
4405 **
4406 ** The sqlite3_uri_key(F,N) returns a pointer to the name (not
4407 ** the value) of the N-th query parameter for filename F, or a NULL
4408 ** pointer if N is less than zero or greater than the number of query
4409 ** parameters minus 1. The N value is zero-based so N should be 0 to obtain
@@ -18876,11 +18876,10 @@
18876 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
18877 int errCode; /* Most recent error code (SQLITE_*) */
18878 int errByteOffset; /* Byte offset of error in SQL statement */
18879 int errMask; /* & result codes with this before returning */
18880 int iSysErrno; /* Errno value from last system error */
 
18881 u8 enc; /* Text encoding */
18882 u8 autoCommit; /* The auto-commit flag. */
18883 u8 temp_store; /* 1: file 2: memory 0: default */
18884 u8 mallocFailed; /* True if we have seen a malloc failure */
18885 u8 bBenignMalloc; /* Do not require OOMs if true */
@@ -18895,10 +18894,11 @@
18894 u8 eOpenState; /* Current condition of the connection */
18895 u8 nFpDigit; /* Significant digits to keep on double->text */
18896 int nextPagesize; /* Pagesize after VACUUM if >0 */
18897 i64 nChange; /* Value returned by sqlite3_changes() */
18898 i64 nTotalChange; /* Value returned by sqlite3_total_changes() */
18899 u32 dbOptFlags; /* Flags to enable/disable optimizations */
18900 int aLimit[SQLITE_N_LIMIT]; /* Limits */
18901 int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */
18902 struct sqlite3InitInfo { /* Information used during initialization */
18903 Pgno newTnum; /* Rootpage of table being initialized */
18904 u8 iDb; /* Which db file is being initialized */
@@ -19094,55 +19094,53 @@
19094 #define DBFLAG_EncodingFixed 0x0040 /* No longer possible to change enc. */
19095
19096 /*
19097 ** Bits of the sqlite3.dbOptFlags field that are used by the
19098 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
19099 ** selectively disable various optimizations. The numbers in each macro
19100 ** are the one-based bit position (for improved readability).
19101 **
19102 ** Keep these values in sync with the ext/misc/optname.c extension.
19103 */
19104 #define SQLITE_QueryFlattener 1 /* Query flattening */
19105 #define SQLITE_WindowFunc 2 /* Use xInverse for window functions */
19106 #define SQLITE_GroupByOrder 3 /* GROUPBY cover of ORDERBY */
19107 #define SQLITE_JoinMiss 4 /* Unwind join loops on a lookup miss*/
19108 #define SQLITE_DistinctOpt 5 /* DISTINCT using indexes */
19109 #define SQLITE_CoverIdxScan 6 /* Covering index scans */
19110 #define SQLITE_OrderByIdxJoin 7 /* ORDER BY of joins via index */
19111 #define SQLITE_Transitive 8 /* Transitive constraints */
19112 #define SQLITE_OmitNoopJoin 9 /* Omit unused tables in joins */
19113 #define SQLITE_CountOfView 10 /* The count-of-view optimization */
19114 #define SQLITE_CursorHints 11 /* Add OP_CursorHint opcodes */
19115 #define SQLITE_Stat4 12 /* Use STAT4 data */
19116 #define SQLITE_PushDown 13 /* WHERE-clause push-down opt */
19117 #define SQLITE_SimplifyJoin 14 /* Convert LEFT JOIN to JOIN */
19118 #define SQLITE_SkipScan 15 /* Skip-scans */
19119 #define SQLITE_PropagateConst 16 /* The constant propagation opt */
19120 #define SQLITE_MinMaxOpt 17 /* The min/max optimization */
19121 #define SQLITE_SeekScan 18 /* The OP_SeekScan optimization */
19122 #define SQLITE_OmitOrderBy 19 /* Omit pointless ORDER BY */
19123 #define SQLITE_BloomFilter 20 /* Use a Bloom filters */
19124 /* 21 -- Available for reuse */
19125 #define SQLITE_BalancedMerge 22 /* Balance multi-way merges */
19126 #define SQLITE_ReleaseReg 23 /* Use OP_ReleaseReg for testing */
19127 #define SQLITE_FlttnUnionAll 24 /* Disable the UNION ALL flattener */
19128 #define SQLITE_IndexedExpr 25 /* Pull exprs from index when able */
19129 #define SQLITE_Coroutines 26 /* Co-routines for subqueries */
19130 #define SQLITE_NullUnusedCols 27 /* NULL unused columns in subqueries */
19131 #define SQLITE_OnePass 28 /* Single-pass DELETE and UPDATE */
19132 #define SQLITE_OrderBySubq 29 /* ORDER BY in subquery helps outer */
19133 #define SQLITE_StarQuery 30 /* Heurists for star queries */
19134 #define SQLITE_ExistsToJoin 31 /* The EXISTS-to-JOIN optimization */
19135 #define SQLITE_UnionLimit 32 /* Optimizations for UNION + LIMIT */
 
 
 
 
 
19136
19137 /*
19138 ** Macros for testing whether or not optimizations are enabled or disabled.
19139 */
19140 #define OptimizationDisabled(D,M) (((D)->dbOptFlags&(1ul<<((M)-1)))!=0)
19141 #define OptimizationEnabled(D,M) (((D)->dbOptFlags&(1ul<<((M)-1)))==0)
19142
19143 /*
19144 ** Return true if it OK to factor constant expressions into the initialization
19145 ** code. The argument is a Parse object for the code generator.
19146 */
@@ -21119,10 +21117,11 @@
21117 int nRangeReg; /* Size of the temporary register block */
21118 int iRangeReg; /* First register in temporary register block */
21119 int nErr; /* Number of errors seen */
21120 int nTab; /* Number of previously allocated VDBE cursors */
21121 int nMem; /* Number of memory cells used so far */
21122 int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */
21123 int iSelfTab; /* Table associated with an index on expr, or negative
21124 ** of the base register during check-constraint eval */
21125 int nNestSel; /* Number of nested SELECT statements and/or VIEWs */
21126 int nLabel; /* The *negative* of the number of labels used */
21127 int nLabelAlloc; /* Number of slots in aLabel */
@@ -22448,15 +22447,14 @@
22447 SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr*);
22448 SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*);
22449 SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse*,Expr*);
22450 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
22451 SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
22452 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int,int);
22453 SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int,int);
22454 SQLITE_PRIVATE int sqlite3ExprListIsConstant(Parse *pParse, ExprList *pList, int bNoIs);
 
22455 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
 
22456 SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*, Parse*, int);
22457 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
22458 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
22459 SQLITE_PRIVATE int sqlite3ExprIsLikeOperator(const Expr*);
22460 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
@@ -26055,36 +26053,39 @@
26053 p->isUtc = 1;
26054 p->isLocal = 0;
26055 }
26056 }
26057 }
26058
26059 /*
26060 ** Return the number of dates in a specific month.
26061 */
26062 static int daysOfMonth(int Y, int M){
26063 if( (1<<M) & 0x15aa ){
26064 return 31;
26065 }else if( M!=2 ){
26066 return 30;
26067 }else if( Y%4==0 && (Y%100!=0 || Y%400==0) ){
26068 return 29;
26069 }else{
26070 return 28;
26071 }
26072 }
26073
26074 /*
26075 ** Given the YYYY-MM-DD information current in p, determine if there
26076 ** is day-of-month overflow and set nFloor to the number of days that
26077 ** would need to be subtracted from the date in order to bring the
26078 ** date back to the end of the month.
26079 */
26080 static void computeFloor(DateTime *p){
26081 int mxD; /* Maximum day number for the current month */
26082 assert( p->validYMD || p->isError );
26083 assert( p->D>=0 && p->D<=32 );
26084 assert( p->M>=0 && p->M<=12 );
26085 mxD = daysOfMonth(p->Y, p->M);
26086 p->nFloor = p->D>mxD ? p->D - mxD : 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
26087 }
26088
26089 /*
26090 ** Parse dates of the form
26091 **
@@ -26110,11 +26111,23 @@
26111 return 1;
26112 }
26113 zDate += 10;
26114 while( sqlite3Isspace(*zDate) || 'T'==*(u8*)zDate ){ zDate++; }
26115 if( parseHhMmSs(zDate, p)==0 ){
26116 if( p->h==24 ){
26117 int mxD = daysOfMonth(Y,M);
26118 p->h = 0;
26119 D++;
26120 if( D>mxD ){
26121 D -= mxD;
26122 M++;
26123 if( M>12 ){
26124 M = 1;
26125 Y++;
26126 }
26127 }
26128 }
26129 }else if( *zDate==0 ){
26130 p->validHMS = 0;
26131 }else{
26132 return 1;
26133 }
@@ -46240,32 +46253,39 @@
46253 #ifdef SQLITE_MMAP_READWRITE
46254 if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE;
46255 #endif
46256
46257 if( pOrig ){
46258 i64 nReuse = pFd->mmapSize & ~((int)osGetpagesize()-1);
46259
46260 /* Unmap any part of the current mapping that will not be reused */
46261 if( nReuse<pFd->mmapSizeActual ){
46262 osMunmap(&pOrig[nReuse], pFd->mmapSizeActual - nReuse);
46263 }
46264
46265 /* If nReuse is now zero, then the entire mapping was unmapped by the
46266 ** call above. In this case do not attempt to extend pOrig. */
46267 if( nReuse>0 ){
46268 #if HAVE_MREMAP
46269 pNew = osMremap(pOrig, nReuse, nNew, MREMAP_MAYMOVE);
46270 zErr = "mremap";
 
46271 #else
46272 pNew = osMmap(&pOrig[nReuse], nNew-nReuse, flags, MAP_SHARED, h, nReuse);
46273 if( pNew!=MAP_FAILED ){
46274 if( pNew!=&pOrig[nReuse] ){
46275 osMunmap(pNew, nNew - nReuse);
46276 pNew = 0;
46277 }else{
46278 pNew = pOrig;
46279 }
46280 }
 
 
 
46281 #endif
46282
46283 /* The attempt to extend the existing mapping failed. Free it. */
46284 if( pNew==MAP_FAILED || pNew==0 ){
46285 osMunmap(pOrig, nReuse);
46286 }
46287 }
46288 }
46289
46290 /* If pNew is still NULL, try to create an entirely new mapping. */
46291 if( pNew==0 ){
@@ -72669,16 +72689,22 @@
72689 SQLITE_PRIVATE void sqlite3BtreeEnter(Btree *p){
72690 p->pBt->db = p->db;
72691 }
72692 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
72693 int i;
72694 u8 skipOk = 1;
72695 /* As in the threadsafe build: set db->noSharedCache when no attached
72696 ** Btree is sharable, so that schema and table-lock checks are skipped */
72697 if( db->noSharedCache ) return;
72698 for(i=0; i<db->nDb; i++){
72699 Btree *p = db->aDb[i].pBt;
72700 if( p ){
72701 p->pBt->db = p->db;
72702 if( p->sharable ) skipOk = 0;
72703 }
72704 }
72705 db->noSharedCache = skipOk;
72706 }
72707 #endif /* if SQLITE_THREADSAFE */
72708
72709 #ifndef SQLITE_OMIT_INCRBLOB
72710 /*
@@ -80129,11 +80155,11 @@
80155 ** the source page. Make sure this does not cause problems by not
80156 ** reading the first 4 bytes */
80157 memcpy(&data[idx+4], pCell+4, sz-4);
80158 put4byte(&data[idx], iChild);
80159 pIns = pPage->aCellIdx + i*2;
80160 if( i<pPage->nCell ) memmove(pIns+2, pIns, 2*(pPage->nCell - i));
80161 put2byte(pIns, idx);
80162 pPage->nCell++;
80163 /* increment the cell count */
80164 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
80165 assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
@@ -80213,11 +80239,11 @@
80239 assert( idx >= pPage->cellOffset+2*pPage->nCell+2 || CORRUPT_DB );
80240 assert( idx+sz <= (int)pPage->pBt->usableSize );
80241 pPage->nFree -= (u16)(2 + sz);
80242 memcpy(&data[idx], pCell, sz);
80243 pIns = pPage->aCellIdx + i*2;
80244 if( i<pPage->nCell ) memmove(pIns+2, pIns, 2*(pPage->nCell - i));
80245 put2byte(pIns, idx);
80246 pPage->nCell++;
80247 /* increment the cell count */
80248 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
80249 assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
@@ -81166,10 +81192,11 @@
81192 int limit = pOld->nCell;
81193 u8 *aData = pOld->aData;
81194 u16 maskPage = pOld->maskPage;
81195 u8 *piCell = aData + pOld->cellOffset;
81196 u8 *piEnd;
81197 u8 **ppCell;
81198 VVA_ONLY( int nCellAtStart = b.nCell; )
81199
81200 /* Verify that all sibling pages are of the same "type" (table-leaf,
81201 ** table-interior, index-leaf, or index-interior).
81202 */
@@ -81201,27 +81228,29 @@
81228 rc = SQLITE_CORRUPT_PAGE(pOld);
81229 goto balance_cleanup;
81230 }
81231 limit = pOld->aiOvfl[0];
81232 for(j=0; j<limit; j++){
81233 b.apCell[b.nCell+j] = aData + (maskPage & get2byteAligned(piCell));
81234 piCell += 2;
 
81235 }
81236 b.nCell += limit;
81237 for(k=0; k<pOld->nOverflow; k++){
81238 assert( k==0 || pOld->aiOvfl[k-1]+1==pOld->aiOvfl[k] );/* NOTE 1 */
81239 b.apCell[b.nCell] = pOld->apOvfl[k];
81240 b.nCell++;
81241 }
81242 }
81243 piEnd = aData + pOld->cellOffset + 2*pOld->nCell;
81244 /* Collect cell pointers before updating the cell count. */
81245 ppCell = &b.apCell[b.nCell];
81246 while( piCell<piEnd ){
81247 assert( ppCell<&b.apCell[nMaxCells] );
81248 *ppCell++ = aData + (maskPage & get2byteAligned(piCell));
81249 piCell += 2;
 
81250 }
81251 b.nCell = (int)(ppCell - b.apCell);
81252 assert( (b.nCell-nCellAtStart)==(pOld->nCell+pOld->nOverflow) );
81253
81254 cntOld[i] = b.nCell;
81255 if( i<nOld-1 && !leafData){
81256 u16 sz = (u16)szNew[i];
@@ -87092,10 +87121,11 @@
87121 zVal = &pExpr->u.zToken[2];
87122 nVal = sqlite3Strlen30(zVal)-1;
87123 assert( zVal[nVal]=='\'' );
87124 sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
87125 0, SQLITE_DYNAMIC);
87126 pVal->enc = enc;
87127 }
87128 #endif
87129 #ifdef SQLITE_ENABLE_STAT4
87130 else if( op==TK_FUNCTION && pCtx!=0 ){
87131 rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
@@ -87486,10 +87516,11 @@
87516 p->pParse = pParse;
87517 pParse->pVdbe = p;
87518 assert( pParse->aLabel==0 );
87519 assert( pParse->nLabel==0 );
87520 assert( p->nOpAlloc==0 );
87521 assert( pParse->szOpAlloc==0 );
87522 sqlite3VdbeAddOp2(p, OP_Init, 0, 1);
87523 return p;
87524 }
87525
87526 /*
@@ -87516,10 +87547,11 @@
87547 SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n, u8 prepFlags){
87548 if( p==0 ) return;
87549 p->prepFlags = prepFlags;
87550 if( (prepFlags & SQLITE_PREPARE_SAVESQL)==0 ){
87551 p->expmask = 0;
87552 p->smimask = 0;
87553 }
87554 assert( p->zSql==0 );
87555 p->zSql = sqlite3DbStrNDup(p->db, z, n);
87556 }
87557
@@ -87636,11 +87668,12 @@
87668
87669 assert( nOp<=(int)(1024/sizeof(Op)) );
87670 assert( nNew>=(v->nOpAlloc+nOp) );
87671 pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
87672 if( pNew ){
87673 p->szOpAlloc = sqlite3DbMallocSize(p->db, pNew);
87674 v->nOpAlloc = p->szOpAlloc/sizeof(Op);
87675 v->aOp = pNew;
87676 }
87677 return (pNew ? SQLITE_OK : SQLITE_NOMEM_BKPT);
87678 }
87679
@@ -90143,11 +90176,11 @@
90176 ** of the prepared statement.
90177 */
90178 n = ROUND8P(sizeof(Op)*p->nOp); /* Bytes of opcode memory used */
90179 x.pSpace = &((u8*)p->aOp)[n]; /* Unused opcode memory */
90180 assert( EIGHT_BYTE_ALIGNMENT(x.pSpace) );
90181 x.nFree = ROUNDDOWN8(pParse->szOpAlloc - n); /* Bytes unused memory */
90182 assert( x.nFree>=0 );
90183 assert( EIGHT_BYTE_ALIGNMENT(&x.pSpace[x.nFree]) );
90184
90185 resolveP2Values(p, &nArg);
90186 p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
@@ -92794,14 +92827,16 @@
92827 assert( iVar>0 );
92828 assert( (v->db->flags & SQLITE_EnableQPSG)==0
92829 || (v->db->mDbFlags & DBFLAG_InternalFunc)!=0 );
92830
92831 m = (iVar>=32) ? 0x80000000 : ((u32)1 << (iVar-1));
 
92832 if( bSmallint ){
92833 if( (v->expmask & m)==0 ) v->smimask |= m;
92834 }else{
92835 v->smimask &= ~m;
92836 }
92837 v->expmask |= m;
92838
92839 /* smimask is always a subset of expmask */
92840 assert( (v->smimask & v->expmask) == v->smimask );
92841 }
92842
@@ -94950,14 +94985,12 @@
94985 if( i>=(unsigned int)p->nVar ){
94986 sqlite3Error(p->db, SQLITE_RANGE);
94987 sqlite3_mutex_leave(p->db->mutex);
94988 return SQLITE_RANGE;
94989 }
94990
94991 pVar = &p->aVar[i];
 
 
 
94992
94993 /* If the bit corresponding to this variable in Vdbe.expmask is set, then
94994 ** binding a new value to this variable invalidates the current query plan.
94995 **
94996 ** IMPLEMENTATION-OF: R-57496-20354 If the specific value bound to a host
@@ -94967,15 +95000,24 @@
95000 ** following any change to the bindings of that parameter.
95001 */
95002 assert( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 || p->expmask==0 );
95003 assert( (p->expmask & p->smimask)==p->smimask );
95004 if( p->expmask!=0 && (p->expmask & (i>=31 ? 0x80000000 : (u32)1<<i))!=0 ){
95005 /* If the p->smimask bit is also set, then only expire the statement if
95006 ** the value being clobbered was integer value 0 or 1. */
95007 if( (p->smimask==0)
95008 || (p->smimask & (i>=31 ? 0x80000000 : (u32)1<<i))==0
95009 || ((pVar->flags & MEM_Int)!=0 && pVar->u.i>=0 && pVar->u.i<=1)
95010 ){
95011 p->expired = 1;
95012 }
95013 }
95014
95015 sqlite3VdbeMemRelease(pVar);
95016 pVar->flags = MEM_Null;
95017 p->db->errCode = SQLITE_OK;
95018
95019 return SQLITE_OK;
95020 }
95021
95022 /*
95023 ** Bind a text or BLOB value.
@@ -95099,12 +95141,12 @@
95141 int sm1 = (pVar->flags & MEM_Int)!=0 && pVar->u.i>=0 && pVar->u.i<=1;
95142 int sm2 = iValue>=0 && iValue<=1;
95143 if( sm1!=sm2 ){
95144 p->expired = 1;
95145 }
95146 }else if( (pVar->flags & MEM_Int)==0 || iValue!=pVar->u.i ){
95147 /* Always expire if the smimask bit is clear */
95148 p->expired = 1;
95149 }
95150 }
95151 }
95152 sqlite3VdbeMemSetInt64(pVar, iValue);
@@ -98405,11 +98447,22 @@
98447 ** raise an SQLITE_MISMATCH exception.
98448 */
98449 case OP_MustBeInt: { /* jump0, in1 */
98450 pIn1 = &aMem[pOp->p1];
98451 if( (pIn1->flags & MEM_Int)==0 ){
98452 if( (pIn1->flags & MEM_Real)!=0 ){
98453 sqlite3_int64 ix;
98454 if( pIn1->u.r>=-9223372036854775808.0
98455 && pIn1->u.r<+9223372036854775808.0
98456 && (double)(ix = sqlite3RealToI64(pIn1->u.r))==pIn1->u.r
98457 ){
98458 pIn1->u.i = ix;
98459 MemSetTypeFlag(pIn1, MEM_Int);
98460 }
98461 }else{
98462 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
98463 }
98464 if( (pIn1->flags & MEM_Int)==0 ){
98465 VdbeBranchTaken(1, 2);
98466 if( pOp->p2==0 ){
98467 rc = SQLITE_MISMATCH;
98468 goto abort_due_to_error;
@@ -100995,10 +101048,13 @@
101048 assert( !sqlite3BtreeClosesWithCursor(pCx->ub.pBtx, pCx->uc.pCursor) );
101049 sqlite3BtreeClose(pCx->ub.pBtx);
101050 p->apCsr[pOp->p1] = 0; /* Not required; helps with static analysis */
101051 }else{
101052 assert( sqlite3BtreeClosesWithCursor(pCx->ub.pBtx, pCx->uc.pCursor) );
101053 if( pOp->opcode==OP_OpenAutoindex ){
101054 sqlite3BtreeCursorHintFlags(pCx->uc.pCursor, BTREE_SEEK_EQ);
101055 }
101056 }
101057 }
101058 }
101059 if( rc ) goto abort_due_to_error;
101060 pCx->nullRow = 1;
@@ -101129,15 +101185,26 @@
101185 ** greater than or equal to the key and P2 is not zero, then jump to P2.
101186 **
101187 ** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
101188 ** opcode will either land on a record that exactly matches the key, or
101189 ** else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ,
101190 ** this opcode must be followed by an IdxLE opcode with the same arguments,
101191 ** except that the P2 argument (the jump destination) can be different.
101192 ** The IdxGT opcode will be skipped if this opcode succeeds, but the
101193 ** IdxGT opcode will be used on subsequent loop iterations. The
101194 ** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
101195 ** is an equality search.
101196 **
101197 ** The P2 of the IdxLE might be less than the P2 of this opcode. The P2
101198 ** of the IdxLE will be the location to jump to if there are one or more
101199 ** matching rows and is the location to continue with the next row of the
101200 ** first containing loop. The P2 of this opcode will be the location to
101201 ** jump to if zero rows of cursor P1 match the key, and that will be the
101202 ** continuation address of the first outer loop that contributes to the
101203 ** key. The P2 of this opcode might be greater than the P2 of the
101204 ** subsequent IdxLE if the first outer loop that influences the key is
101205 ** outer to the immediately next outer loop.
101206 **
101207 ** This opcode leaves the cursor configured to move in forward order,
101208 ** from the beginning toward the end. In other words, the cursor is
101209 ** configured to use Next, not Prev.
101210 **
@@ -101196,15 +101263,26 @@
101263 ** configured to use Prev, not Next.
101264 **
101265 ** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
101266 ** opcode will either land on a record that exactly matches the key, or
101267 ** else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ,
101268 ** this opcode must be followed by an IdxGE opcode with the same arguments
101269 ** except the P2 of IdxGE might be less than the P2 of this opcode.
101270 ** The IdxGE opcode will be skipped if this opcode succeeds, but the
101271 ** IdxGE opcode will be used on subsequent loop iterations. The
101272 ** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
101273 ** is an equality search.
101274 **
101275 ** The P2 of the IdxGE might be less than the P2 of this opcode. The P2
101276 ** of the IdxGE will be the location to jump to if there are one or more
101277 ** matching rows and is the location to continue with the next row of the
101278 ** first containing loop. The P2 of this opcode will be the location to
101279 ** jump to if no rows of cursor P1 match the key, and that will be the
101280 ** continuation address of the first outer loop that contributes to the
101281 ** key. The P2 of this opcode might be greater than the P2 of the
101282 ** subsequent IdxLE if the first outer loop that influences the key is
101283 ** outer to the immediately next outer loop.
101284 **
101285 ** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
101286 */
101287 case OP_SeekLT: /* jump0, in3, group, ncycle */
101288 case OP_SeekLE: /* jump0, in3, group, ncycle */
@@ -101310,11 +101388,13 @@
101388 assert( pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE );
101389 assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT );
101390 assert( pOp->opcode==OP_SeekGE || pOp[1].opcode==OP_IdxLT );
101391 assert( pOp->opcode==OP_SeekLE || pOp[1].opcode==OP_IdxGT );
101392 assert( pOp[1].p1==pOp[0].p1 );
101393 assert( pOp[1].p2<=pOp[0].p2 );
101394 testcase( pOp->opcode==OP_SeekGE && pOp[1].p2<pOp[0].p2 );
101395 testcase( pOp->opcode==OP_SeekLE && pOp[1].p2<pOp[0].p2 );
101396 assert( pOp[1].p3==pOp[0].p3 );
101397 assert( pOp[1].p4.i==pOp[0].p4.i );
101398 }
101399
101400 nField = pOp->p4.i;
@@ -113193,15 +113273,14 @@
113273 char aff;
113274 assert( pExpr->op==TK_EQ || pExpr->op==TK_IN || pExpr->op==TK_LT ||
113275 pExpr->op==TK_GT || pExpr->op==TK_GE || pExpr->op==TK_LE ||
113276 pExpr->op==TK_NE || pExpr->op==TK_IS || pExpr->op==TK_ISNOT );
113277 assert( pExpr->pLeft );
113278 assert( !ExprUseXSelect(pExpr) );
113279 aff = sqlite3ExprAffinity(pExpr->pLeft);
113280 if( pExpr->pRight ){
113281 aff = sqlite3CompareAffinity(pExpr->pRight, aff);
 
 
113282 }else if( aff==0 ){
113283 aff = SQLITE_AFF_BLOB;
113284 }
113285 return aff;
113286 }
@@ -115560,11 +115639,11 @@
115639 ** table other than iCur.
115640 **
115641 ** Consider uncorrelated subqueries to be constants if the bAllowSubq
115642 ** parameter is true.
115643 */
115644 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur, int bAllowSubq){
115645 Walker w;
115646 w.eCode = 3;
115647 w.pParse = 0;
115648 w.xExprCallback = exprNodeIsConstant;
115649 if( bAllowSubq ){
@@ -115740,11 +115819,10 @@
115819 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){
115820 assert( isInit==0 || isInit==1 );
115821 return exprIsConst(0, p, 4+isInit);
115822 }
115823
 
115824 /*
115825 ** Walk an expression tree. Return 1 if the expression contains a
115826 ** subquery of some kind. Return 0 if there are no subqueries.
115827 */
115828 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr *p){
@@ -115756,11 +115834,10 @@
115834 w.xSelectCallback2 = sqlite3SelectWalkAssert2;
115835 #endif
115836 sqlite3WalkExpr(&w, p);
115837 return w.eCode==0;
115838 }
 
115839
115840 /*
115841 ** If the expression p codes a constant integer between 0 and 0x7fffffff,
115842 ** then return 1 and put the value of the integer in *pValue. If the
115843 ** expression is not an integer or if it is an integer that is out side
@@ -115775,14 +115852,11 @@
115852 **
115853 ** If pParse is not NULL and expression p is a variable, then the variable
115854 ** is marked so as to cause the statement to be reprepared each time a new
115855 ** value is bound to it. Except, if parameter bRSI is true, then the statement
115856 ** will only be reprepared if the rebind changes the value to or from a
115857 ** "small integer" (either 0 or 1).
 
 
 
115858 */
115859 SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr *p, int *pValue, Parse *pParse, int bRSI){
115860 int iSign = 1; /* Either +1 or -1. */
115861 while( 1/*exit-by-break*/ ){
115862 if( NEVER(p==0) ) return 0;
@@ -115801,11 +115875,10 @@
115875 pParse = 0;
115876 continue;
115877 }
115878 if( p->op==TK_VARIABLE && pParse!=0 ){
115879 sqlite3_value *pVal; /* The variable */
 
115880 int rc = 0; /* 1 if successful, 0 if failed */
115881 assert( iSign==1 );
115882 if( NEVER(pParse->pVdbe==0) ) break;
115883 if( (pParse->db->flags & SQLITE_EnableQPSG)!=0 ) break;
115884 pVal = sqlite3VdbeGetBoundValue(pParse->pReprepare, p->iColumn,
@@ -115815,18 +115888,15 @@
115888 if( sqlite3_value_type(pVal)==SQLITE_INTEGER
115889 && (vv = sqlite3_value_int64(pVal))>=0
115890 && vv<=0x7fffffff
115891 ){
115892 *pValue = (int)vv;
 
 
 
115893 rc = 1;
115894 }
115895 sqlite3ValueFree(pVal);
115896 }
115897 sqlite3VdbeReprepareOnBind(pParse->pVdbe, p->iColumn, bRSI);
115898 return rc;
115899 }
115900 break;
115901 }
115902 return 0;
@@ -116862,10 +116932,16 @@
116932 ExprSetVVAProperty(pExpr, EP_NoReduce);
116933 if( addrOnce ){
116934 sqlite3VdbeJumpHere(v, addrOnce);
116935 }
116936 sqlite3VdbeScanStatusRange(v, addrExplain, addrExplain, -1);
116937
116938 if( dest.eDest==SRT_Mem
116939 && sqlite3ExprCanReturnSubtype(pParse, pSel->pEList->a[0].pExpr)
116940 ){
116941 sqlite3VdbeAddOp1(v, OP_ClrSubtype, rReg);
116942 }
116943
116944 /* Subroutine return */
116945 assert( ExprUseYSub(pExpr) );
116946 assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn
116947 || pParse->nErr );
@@ -117082,11 +117158,10 @@
117158 rLhs = sqlite3GetTempRange(pParse, nVector);
117159 for(i=0; i<nVector; i++){
117160 testcase( aiMap[i]!=i );
117161 sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0);
117162 }
 
117163 }
117164 }
117165
117166
117167 /* Step 2: Check to see if the LHS contains any NULL columns. If the
@@ -117618,11 +117693,11 @@
117693 ** pExpr is able to return a subtype, set pWalker->eCode and abort
117694 ** the search. If pExpr can never return a subtype, prune search.
117695 **
117696 ** The only expressions that can return a subtype are:
117697 **
117698 ** 1. A function, including an aggregate function
117699 ** 2. The no-op "+" operator
117700 ** 3. A CASE...END expression
117701 ** 4. A CAST() expression
117702 ** 5. A "expr COLLATE colseq" expression.
117703 **
@@ -117643,18 +117718,23 @@
117718 if( pExpr->op==TK_CASE || pExpr->op==TK_UPLUS
117719 || pExpr->op==TK_COLLATE || pExpr->op==TK_CAST
117720 ){
117721 return WRC_Continue;
117722 }
117723 if( pExpr->op!=TK_FUNCTION && pExpr->op!=TK_AGG_FUNCTION ){
117724 return WRC_Prune;
117725 }
117726 assert( ExprUseXList(pExpr) );
117727 db = pWalker->pParse->db;
117728 n = pExpr->x.pList ? pExpr->x.pList->nExpr : 0;
117729 pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
117730 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
117731 if( pDef==0 ) return WRC_Continue;
117732 #else
117733 assert( pDef!=0 );
117734 #endif
117735 if( (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
117736 pWalker->eCode = 1;
117737 return WRC_Abort;
117738 }
117739 return WRC_Continue;
117740 }
@@ -117720,14 +117800,20 @@
117800 continue;
117801 }
117802
117803 v = pParse->pVdbe;
117804 assert( v!=0 );
117805 if( p->bMaybeNullRow || sqlite3ExprIsConstant(pParse, pExpr) ){
117806 /* The value of pExpr should be computed from the original expression,
117807 ** not from the index, if either:
117808 **
117809 ** 1. The index might be on a NULL row due to an outer join.
117810 **
117811 ** 2. The expression is a constant. This prevents an attempt to
117812 ** use an index value outside of the loop that positions the
117813 ** index. (Bug 2026-10-11T19:26:40Z).
117814 */
117815 int addr = sqlite3VdbeCurrentAddr(v);
117816 sqlite3VdbeAddOp3(v, OP_IfNullRow, p->iIdxCur, addr+3, target);
117817 VdbeCoverage(v);
117818 sqlite3VdbeAddOp3(v, OP_Column, p->iIdxCur, p->iIdxCol, target);
117819 VdbeComment((v, "%s expr-column %d", p->zIdxName, p->iIdxCol));
@@ -120450,11 +120536,11 @@
120536 assert( pOBList->nExpr>0 );
120537 assert( pItem->bOBUnique==0 );
120538 if( pOBList->nExpr==1
120539 && nArg==1
120540 && sqlite3ExprCompare(0,pOBList->a[0].pExpr,
120541 pExpr->x.pList->a[0].pExpr,-1)==0
120542 ){
120543 pItem->bOBPayload = 0;
120544 pItem->bOBUnique = ExprHasProperty(pExpr, EP_Distinct);
120545 }else{
120546 pItem->bOBPayload = 1;
@@ -120538,10 +120624,17 @@
120624 ** Deallocate a register, making available for reuse for some other
120625 ** purpose.
120626 */
120627 SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){
120628 if( iReg ){
120629 #ifdef SQLITE_DEBUG
120630 /* Verify that iReg is not already on the unused register list */
120631 int kk;
120632 for(kk=0; kk<pParse->nTempReg; kk++){
120633 assert( pParse->aTempReg[kk]!=iReg );
120634 }
120635 #endif
120636 sqlite3VdbeReleaseRegisters(pParse, iReg, 1, 0, 0);
120637 if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){
120638 pParse->aTempReg[pParse->nTempReg++] = iReg;
120639 }
120640 }
@@ -127356,10 +127449,11 @@
127449
127450 if( db->nSchemaLock==0 ){
127451 for(i=0; i<db->nDb; i++){
127452 if( DbHasProperty(db, i, DB_ResetWanted) ){
127453 sqlite3SchemaClear(db->aDb[i].pSchema);
127454 db->mDbFlags &= ~DBFLAG_SchemaKnownOk;
127455 }
127456 }
127457 }
127458 }
127459
@@ -134158,19 +134252,22 @@
134252 }
134253 nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
134254 regBase = sqlite3GetTempRange(pParse, nCol);
134255 if( pPrior && (regBase!=regPrior || pPrior->pPartIdxWhere) ) pPrior = 0;
134256 for(j=0; j<nCol; j++){
134257 int iTabCol;
134258 if( pPrior
134259 && pPrior->aiColumn[j]==pIdx->aiColumn[j]
134260 && pPrior->aiColumn[j]!=XN_EXPR
134261 ){
134262 /* This column was already computed by the previous index */
134263 continue;
134264 }
134265 sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iDataCur, j, regBase+j);
134266 if( (iTabCol = pIdx->aiColumn[j])>=0
134267 && (pIdx->pTable->aCol[iTabCol].colFlags & COLFLAG_VIRTUAL)==0
134268 ){
134269 /* If the column affinity is REAL but the number is an integer, then it
134270 ** might be stored in the table as an integer (using a compact
134271 ** representation) then converted to REAL by an OP_RealAffinity opcode.
134272 ** But we are getting ready to store this value back into an index, where
134273 ** it should be converted by to INTEGER again. So omit the
@@ -134530,10 +134627,18 @@
134627 str.printfFlags = SQLITE_PRINTF_SQLFUNC;
134628 sqlite3_str_appendf(&str, zFormat, &x);
134629 sqlite3_result_str(context, &str, SQLITE_XFER);
134630 }
134631 }
134632
134633 /* Return true if any of the eight bytes in word is NUL or non-ASCII. */
134634 static SQLITE_INLINE int containsNulOrNonAscii(u64 word){
134635 const u64 byteOnes = UINT64_C(0x0101010101010101);
134636 const u64 byteHighBits = UINT64_C(0x8080808080808080);
134637 /* NUL causes a borrow into a high bit; non-ASCII already has one set. */
134638 return ((word | (word - byteOnes)) & byteHighBits)!=0;
134639 }
134640
134641 /*
134642 ** Implementation of the substr() function.
134643 **
134644 ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1.
@@ -134614,10 +134719,24 @@
134719 }
134720 p1 -= p2;
134721 }
134722 assert( p1>=0 && p2>=0 );
134723 if( p0type!=SQLITE_BLOB ){
134724 if( p1>=8 ){
134725 /* Skip 8 characters at a time while all 8 bytes are in 0x01..0x7f */
134726 const unsigned char *zEnd = z + sqlite3_value_bytes(argv[0]);
134727 while( p1>=8 && zEnd-z>=8 ){
134728 u64 word;
134729 memcpy(&word, z, sizeof(word));
134730 /* Handle NUL and UTF-8 with the scalar loop below. */
134731 if( containsNulOrNonAscii(word) ){
134732 break;
134733 }
134734 z += 8;
134735 p1 -= 8;
134736 }
134737 }
134738 for( ; p1>0; p1--){
134739 /* vvvvvv---- See tag-20260418-01 */
134740 if( (u8)(z[0]-1)<(0x80-1) ){
134741 z++;
134742 }else if( z[0]==0 ){
@@ -134991,22 +135110,33 @@
135110 ** c or cx.
135111 */
135112 if( c<0x80 ){
135113 char zStop[3];
135114 int bMatch;
135115 /* If the next pattern character is an ordinary ASCII character,
135116 ** then a candidate position can only match if the next input
135117 ** character is nx or ny. Check that inline, to avoid most of the
135118 ** recursive calls. nx==0 disables this check. */
135119 u8 nx = zPattern[0], ny = nx;
135120 if( nx>=0x80 || nx==matchAll || nx==matchOne || nx==matchOther ){
135121 nx = 0;
135122 }
135123 if( noCase ){
135124 zStop[0] = sqlite3Toupper(c);
135125 zStop[1] = sqlite3Tolower(c);
135126 zStop[2] = 0;
135127 nx = sqlite3Toupper(nx);
135128 ny = sqlite3Tolower(ny);
135129 }else{
135130 zStop[0] = c;
135131 zStop[1] = 0;
135132 }
135133 while(1){
135134 zString += strcspn((const char*)zString, zStop);
135135 if( zString[0]==0 ) break;
135136 zString++;
135137 if( nx && zString[0]!=nx && zString[0]!=ny ) continue;
135138 bMatch = patternCompare(zPattern,zString,pInfo,matchOther);
135139 if( bMatch!=SQLITE_NOMATCH ) return bMatch;
135140 }
135141 }else{
135142 int bMatch;
@@ -135280,18 +135410,24 @@
135410 static void compileoptiongetFunc(
135411 sqlite3_context *context,
135412 int argc,
135413 sqlite3_value **argv
135414 ){
135415 i64 n;
135416 const char *zRes;
135417 assert( argc==1 );
135418 UNUSED_PARAMETER(argc);
135419 /* IMP: R-04922-24076 The sqlite_compileoption_get() SQL function
135420 ** is a wrapper around the sqlite3_compileoption_get() C/C++ function.
135421 */
135422 n = sqlite3_value_int64(argv[0]);
135423 /* Use a negative lower bound to assist testing of the
135424 ** sqlite3_compileoption_get() C-language interface and its handling
135425 ** of negative inputs.
135426 ** vvvvv */
135427 zRes = (n>=(-10) && n<10000) ? sqlite3_compileoption_get((int)n) : 0;
135428 sqlite3_result_text(context, zRes, -1, SQLITE_STATIC);
135429 }
135430 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
135431
135432 /* Array for converting from half-bytes (nybbles) into ASCII hex
135433 ** digits. */
@@ -153606,11 +153742,13 @@
153742 static int renumberCursorsCb(Walker *pWalker, Expr *pExpr){
153743 int op = pExpr->op;
153744 if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){
153745 renumberCursorDoMapping(pWalker, &pExpr->iTable);
153746 }
153747 if( ExprHasProperty(pExpr, (EP_OuterON|EP_InnerON)) ){
153748 testcase( ExprHasProperty(pExpr, EP_OuterON) );
153749 testcase( ExprHasProperty(pExpr, EP_InnerON) );
153750 renumberCursorDoMapping(pWalker, &pExpr->w.iJoin);
153751 }
153752 return WRC_Continue;
153753 }
153754
@@ -154486,11 +154624,11 @@
154624 /*
154625 ** The WHERE-clause constant propagation optimization.
154626 **
154627 ** If the WHERE clause contains terms of the form COLUMN=CONSTANT or
154628 ** CONSTANT=COLUMN that are top-level AND-connected terms that are not
154629 ** part of a ON clause from an OUTER JOIN, then throughout the query
154630 ** replace all other occurrences of COLUMN with CONSTANT.
154631 **
154632 ** For example, the query:
154633 **
154634 ** SELECT * FROM t1, t2, t3 WHERE t1.a=39 AND t2.b=t1.a AND t3.c=t2.b
@@ -164036,10 +164174,11 @@
164174 int addrBrk; /* Jump here to break out of the loop */
164175 int addrHalt; /* Abort the query due to empty table or similar */
164176 int addrNxt; /* Jump here to start the next IN combination */
164177 int addrSkip; /* Jump here for next iteration of skip-scan */
164178 int addrCont; /* Jump here to continue with the next loop cycle */
164179 int addrDeleteCont; /* Delete auto-index entry then same as addrCont */
164180 int addrFirst; /* First instruction of interior of the loop */
164181 int addrBody; /* Beginning of the body of this loop */
164182 int regBignull; /* big-null flag reg. True if a NULL-scan is needed */
164183 int addrBignull; /* Jump here for next part of big-null scan */
164184 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
@@ -166119,10 +166258,131 @@
166258 }
166259 }
166260 }
166261 return 1;
166262 }
166263
166264 /*
166265 ** Find the best address for an inner loop to jump to if its join
166266 ** constraint matches no rows.
166267 **
166268 ** This is an optimization. The default behavior is to continue with
166269 ** the inner-most of the outer loops. But if the join constraint is not
166270 ** influenced by the inner-most outer loop, we might as well skip that
166271 ** loop too, and continue with the second inner-most outer loop. And
166272 ** so forth through subsequent outer loops.
166273 **
166274 ** Return 0 to use the default behavior (continue with the inner-most
166275 ** outer loop. Or return an optimized address to jump to instead if
166276 ** we can do better.
166277 **
166278 ** Conditions for returning non-zero:
166279 **
166280 ** 1. The SQLITE_JoinMiss optimization must be enabled.
166281 **
166282 ** 2. The iLevel loop must have at least two outer loops, otherwise
166283 ** this optimization is pointless.
166284 **
166285 ** 3. We are not attempting to do one-pass
166286 **
166287 ** 4. The join constraints may not contain subqueries
166288 **
166289 ** If the inner-most outer loop that influences iLevel is also the
166290 ** only loop that influences iLevel, and if that loop uses an
166291 ** automatic index, then also arrange to delete the currently used
166292 ** entry from that automatic index, since we know that it can never
166293 ** be successful.
166294 **
166295 ** This optimization inspired by the paper: "TreeTracker Join: Simple,
166296 ** Optimal, Fast" by Hu, Wang, and Miranker, 2025.
166297 */
166298 static int findNoMatchContinuation(
166299 WhereInfo *pWInfo, /* WHERE clause */
166300 int iLevel /* Which loop we are talking about */
166301 ){
166302 WhereLoop *pLoop; /* Description of this loop */
166303 WhereLevel *pParent; /* Controlling parent loop */
166304 SrcList *pTabList; /* Complete FROM clause */
166305 Bitmask mKey; /* Mask of dependent tables */
166306 int iParent; /* Inner-most loop affecting the key to iLevel */
166307 int i; /* Loop counter */
166308
166309 if( iLevel<2 ){
166310 /* If there are less than two outer loops, this optimization is no help */
166311 return 0;
166312 }
166313
166314 /* The OP_SeekGE and OP_SeekLE opcodes only work right for this
166315 ** optimization on a pure equality constraint, so skip the optimization
166316 ** for anything else.
166317 */
166318 pLoop = pWInfo->a[iLevel].pWLoop;
166319 if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=WHERE_COLUMN_EQ ) return 0;
166320 if( pLoop->wsFlags & WHERE_SKIPSCAN ) return 0;
166321 if( pLoop->wsFlags & WHERE_BIGNULL_SORT ) return 0;
166322 assert( (pLoop->wsFlags & (WHERE_VIRTUALTABLE|WHERE_MULTI_OR))==0 );
166323 assert( pLoop->u.btree.nEq>0 );
166324
166325 /* Find a mask of all outer tables that influence the key. At the same
166326 ** time, check to see if any keys values are computed from subqueries and
166327 ** fail out (return 0) if there are any. */
166328 mKey = 0;
166329 for(i=0; i<pLoop->nLTerm; i++){
166330 if( sqlite3ExprContainsSubquery(pLoop->aLTerm[i]->pExpr) ){
166331 return 0;
166332 }
166333 mKey |= pLoop->aLTerm[i]->prereqRight;
166334 }
166335
166336 /* Look back through outer loops. Find the inner-most outer loop
166337 ** that influences the key. Make iParent be the index of that inner-most
166338 ** outer loop.
166339 */
166340 pTabList = pWInfo->pTabList;
166341 iParent = iLevel-1;
166342 while( iParent>0 && (pWInfo->a[iParent].pWLoop->maskSelf & mKey)==0 ){
166343 iParent--;
166344 }
166345 assert( iParent>=0 && iParent<=iLevel );
166346
166347 /* Everything needs to be an INNER join. Fail if there are any
166348 ** OUTER joins in between iParent and iLevel. */
166349 for(i=iParent; i<=iLevel; i++){
166350 if( pTabList->a[pWInfo->a[i].iFrom].fg.jointype & JT_OUTER ) return 0;
166351 }
166352
166353 /* If we reach this point, that means the conditions of the optimization
166354 ** have been met. Even so, disallow the optimization if it is disabled.
166355 */
166356 if( OptimizationDisabled(pWInfo->pParse->db, SQLITE_JoinMiss) ){
166357 return 0;
166358 }
166359
166360 /* If the inner-most outer loop that influences the key for iLevel
166361 ** is controlled by an automatic index and if the automatic index is
166362 ** the only outer loop that influences the key, then arrange to delete
166363 ** the automatic index entry if there is no match on the key.
166364 */
166365 pParent = &pWInfo->a[iParent];
166366 if( (pParent->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0
166367 && (mKey & (mKey-1))==0
166368 ){
166369 for(i=0; i<pLoop->nLTerm; i++){
166370 Expr *pX = pLoop->aLTerm[i]->pExpr;
166371 if( !sqlite3ExprIsTableConstant(pX->pRight,pParent->iTabCur,0) ) break;
166372 }
166373 if( i==pLoop->nLTerm ){
166374 if( pParent->addrDeleteCont==0 ){
166375 pParent->addrDeleteCont = sqlite3VdbeMakeLabel(pWInfo->pParse);
166376 }
166377 return pParent->addrDeleteCont;
166378 }
166379 }
166380
166381 testcase( iParent<iLevel-1 );
166382 return pParent->addrCont;
166383 }
166384
166385 /*
166386 ** Generate code for the start of the iLevel-th loop in the WHERE clause
166387 ** implementation described by pWInfo.
166388 */
@@ -166138,15 +166398,16 @@
166398 int iCur; /* The VDBE cursor for the table */
166399 int addrNxt; /* Where to jump to continue with the next IN case */
166400 int bRev; /* True if we need to scan in reverse order */
166401 WhereLoop *pLoop; /* The WhereLoop object being coded */
166402 WhereClause *pWC; /* Decomposition of the entire WHERE clause */
166403 WhereTerm *pTerm; /* A WHERE clause term */
166404 sqlite3 *db; /* Database connection */
166405 SrcItem *pTabItem; /* FROM clause term being coded */
166406 int addrBrk; /* Jump here to break out of the loop */
166407 int addrCont; /* Jump here to continue with next cycle */
166408 int addrMiss; /* addrCont enhanced for no-matching rows */
166409 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
166410 int iReleaseReg = 0; /* Temp register to free before returning */
166411 Index *pIdx = 0; /* Index used by loop (if any) */
166412 int iLoop; /* Iteration of constraint generator loop */
166413
@@ -166187,10 +166448,11 @@
166448 ** there are no IN operators in the constraints, the "addrNxt" label
166449 ** is the same as "addrBrk".
166450 */
166451 addrBrk = pLevel->addrNxt = pLevel->addrBrk;
166452 addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(pParse);
166453 addrMiss = findNoMatchContinuation(pWInfo, iLevel);
166454
166455 /* If this is the right table of a LEFT OUTER JOIN, allocate and
166456 ** initialize a memory cell that records if this table matches any
166457 ** row of the left table of the join.
166458 */
@@ -166362,19 +166624,20 @@
166624 testcase( pTerm->wtFlags & TERM_VIRTUAL );
166625 iReleaseReg = ++pParse->nMem;
166626 iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
166627 if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg);
166628 addrNxt = pLevel->addrNxt;
166629 if( addrMiss==0 ) addrMiss = addrNxt;
166630 if( pLevel->regFilter ){
166631 sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrMiss);
166632 VdbeCoverage(v);
166633 sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrMiss,
166634 iRowidReg, 1);
166635 VdbeCoverage(v);
166636 filterPullDown(pParse, pWInfo, iLevel, addrNxt, notReady);
166637 }
166638 sqlite3VdbeAddOp3(v, OP_SeekRowid, iCur, addrMiss, iRowidReg);
166639 VdbeCoverage(v);
166640 pLevel->op = OP_Noop;
166641 }else if( (pLoop->wsFlags & WHERE_IPK)!=0
166642 && (pLoop->wsFlags & WHERE_COLUMN_RANGE)!=0
166643 ){
@@ -166573,13 +166836,10 @@
166836 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
166837 if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
166838 assert( pRangeStart!=0 ); /* LIKE opt constraints */
166839 assert( pRangeStart->wtFlags & TERM_LIKEOPT ); /* occur in pairs */
166840 pLevel->iLikeRepCntr = (u32)++pParse->nMem;
 
 
 
166841 /* iLikeRepCntr actually stores 2x the counter register number. The
166842 ** bottom bit indicates whether the search order is ASC or DESC. */
166843 testcase( bRev );
166844 testcase( pIdx->aSortOrder[nEq]==SQLITE_SO_DESC );
166845 assert( (bRev & ~1)==0 );
@@ -166639,14 +166899,29 @@
166899 ** starting at regBase.
166900 */
166901 codeCursorHint(pTabItem, pWInfo, pLevel, pRangeEnd);
166902 regBase = codeAllEqualityTerms(pParse,pLevel,bRev,nExtraReg,&zStartAff);
166903 assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
166904 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
166905 if( pLevel->iLikeRepCntr ){
166906 /* The LIKE optimization loop must be the innermost of any IN(...)
166907 ** or skip-scan loops. Otherwise rows may not be visited in index
166908 ** order. This means it needs an addrNxt label for the same reason
166909 ** IN(...) scans do. */
166910 if( pLevel->addrNxt==pLevel->addrBrk ){
166911 pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
166912 }
166913 sqlite3VdbeAddOp2(v, OP_Integer, 1, (int)(pLevel->iLikeRepCntr>>1));
166914 VdbeComment((v, "LIKE loop counter"));
166915 pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
166916 }
166917 #endif
166918 if( zStartAff && nTop ){
166919 zEndAff = sqlite3DbStrDup(db, &zStartAff[nEq]);
166920 }
166921 addrNxt = (regBignull ? pLevel->addrBignull : pLevel->addrNxt);
166922 if( addrMiss==0 ) addrMiss = addrNxt;
166923
166924 testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
166925 testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
166926 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
166927 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_GE)!=0 );
@@ -166697,11 +166972,11 @@
166972 sqlite3VdbeAddOp2(v, OP_Integer, 1, regBignull);
166973 VdbeComment((v, "NULL-scan pass ctr"));
166974 }
166975 if( pLevel->regFilter ){
166976 assert( sqlite3WhereLoopBloomable(pLoop) );
166977 sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrMiss,
166978 regBase, nEq);
166979 VdbeCoverage(v);
166980 filterPullDown(pParse, pWInfo, iLevel, addrNxt, notReady);
166981 }
166982
@@ -166724,11 +166999,11 @@
166999 sqlite3VdbeChangeP2(v, addrSeekScan, sqlite3VdbeCurrentAddr(v)+1);
167000 addrSeekScan = 0;
167001 }
167002 VdbeCoverage(v);
167003 }
167004 sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrMiss, regBase, nConstraint);
167005 VdbeCoverage(v);
167006 VdbeCoverageIf(v, op==OP_Rewind); testcase( op==OP_Rewind );
167007 VdbeCoverageIf(v, op==OP_Last); testcase( op==OP_Last );
167008 VdbeCoverageIf(v, op==OP_SeekGT); testcase( op==OP_SeekGT );
167009 VdbeCoverageIf(v, op==OP_SeekGE); testcase( op==OP_SeekGE );
@@ -169965,16 +170240,20 @@
170240 Expr *pX = pTerm->pExpr;
170241 Expr inexpr;
170242
170243 assert( pTerm->eOperator & WO_IN );
170244
170245 if( ExprUseXSelect(pX) ){
170246 int iField = 0;
170247 inexpr.flags = 0;
170248 inexpr.op = TK_EQ;
170249 if( sqlite3ExprIsVector(pX->pLeft) ){
170250 iField = pTerm->u.x.iField - 1;
170251 inexpr.pLeft = pX->pLeft->x.pList->a[iField].pExpr;
170252 }else{
170253 inexpr.pLeft = pX->pLeft;
170254 }
170255 inexpr.pRight = pX->x.pSelect->pEList->a[iField].pExpr;
170256 pX = &inexpr;
170257 }
170258
170259 if( sqlite3IndexAffinityOk(pX, idxaff) ){
@@ -173573,39 +173852,55 @@
173852 }
173853
173854 if( (pPart->op==TK_EQ || pPart->op==TK_IS) ){
173855 Expr *pLeft = pPart->pLeft;
173856 Expr *pRight = pPart->pRight;
173857 Table *pLeftTab; /* Table of the left operand */
173858 Column *pLeftCol; /* Column of the left operand */
173859 u8 affRight, affLeft;
173860
173861 if( pLeft->op!=TK_COLUMN ) return;
173862 if( !sqlite3ExprIsConstant(0, pRight) ) return;
173863 if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pParse, pPart)) ) return;
173864 if( pLeft->iColumn<0 ) return;
173865 pLeftTab = pIdx->pTable;
173866 pLeftCol = &pLeftTab->aCol[pLeft->iColumn];
173867 affLeft = pLeftCol->affinity;
173868 assert( SQLITE_AFF_BLOB<SQLITE_AFF_TEXT );
173869 if( affLeft<SQLITE_AFF_TEXT ) return;
173870 affRight = sqlite3ExprAffinity(pRight);
173871 if( affRight!=0 && affRight!=affLeft ) return;
173872 if( pItem ){
173873 sqlite3 *db = pParse->db;
173874 IndexedExpr *p = (IndexedExpr*)sqlite3DbMallocRaw(db, sizeof(*p));
173875 if( p ){
173876 int bNullRow = (pItem->fg.jointype&(JT_LEFT|JT_LTORJ))!=0;
173877 pRight = sqlite3ExprDup(db, pRight, 0);
173878 if( (pLeftTab->tabFlags & TF_Strict)!=0 ){
173879 Token t;
173880 t.z = sqlite3ColumnType(pLeftCol, 0);
173881 assert( t.z!=0 ); /* Because affLeft>=SQLITE_AFF_TEXT */
173882 t.n = (int)strlen(t.z);
173883 p->pExpr = sqlite3ExprAlloc(db, TK_CAST, &t, 1);
173884 sqlite3ExprAttachSubtrees(db, p->pExpr, pRight, 0);
173885 }else{
173886 p->pExpr = pRight;
173887 }
173888 p->iDataCur = pItem->iCursor;
173889 p->iIdxCur = iIdxCur;
173890 p->iIdxCol = pLeft->iColumn;
173891 p->bMaybeNullRow = bNullRow;
173892 p->pIENext = pParse->pIdxPartExpr;
173893 p->aff = affLeft;
173894 pParse->pIdxPartExpr = p;
173895 if( p->pIENext==0 ){
173896 void *pArg = (void*)&pParse->pIdxPartExpr;
173897 sqlite3ParserAddCleanup(pParse, whereIndexedExprCleanup, pArg);
173898 }
173899 }
173900 }else if( pLeft->iColumn<(BMS-1) ){
173901 *pMask &= ~((Bitmask)1 << pLeft->iColumn);
173902 }
173903 }
173904 }
173905
173906
@@ -173834,11 +174129,13 @@
174129 if( pProbe->isCovering ){
174130 m = 0;
174131 pNew->wsFlags = WHERE_IDX_ONLY | WHERE_INDEXED;
174132 }else{
174133 m = pSrc->colUsed & pProbe->colNotIdxed;
174134 if( pProbe->pPartIdxWhere
174135 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0
174136 ){
174137 wherePartIdxExpr(
174138 pWInfo->pParse, pProbe, pProbe->pPartIdxWhere, &m, 0, 0
174139 );
174140 }
174141 pNew->wsFlags = WHERE_INDEXED;
@@ -174718,17 +175015,17 @@
175015 ** long as the subquery is materialized. If the subquery is
175016 ** implemented as a co-routine, the sort orders must be in the same
175017 ** direction because there is no way to run a co-routine backwards.
175018 */
175019 static SQLITE_NOINLINE int wherePathMatchSubqueryOB(
 
175020 WhereLoop *pLoop, /* The nested loop term that is a subquery */
175021 int iLoop, /* Which level of the nested loop. 0==outermost */
175022 int iCur, /* Cursor used by the this loop */
175023 ExprList *pOrderBy, /* The ORDER BY clause on the whole query */
175024 Bitmask *pRevMask, /* When loops need to go in reverse order */
175025 Bitmask *pOBSat, /* Which terms of pOrderBy are satisfied so far */
175026 u16 wctrlFlags /* WHERE_GROUPBY or _DISTINCTBY or _ORDERBY_LIMIT */
175027 ){
175028 int iOB; /* Index into pOrderBy->a[] */
175029 int jSub; /* Index into pSubOB->a[] */
175030 u8 rev = 0; /* True if iOB and jSub sort in opposite directions */
175031 u8 revIdx = 0; /* Sort direction for jSub */
@@ -174742,11 +175039,11 @@
175039 if( pSubOB->a[jSub].u.x.iOrderByCol==0 ) break;
175040 pOBExpr = pOrderBy->a[iOB].pExpr;
175041 if( pOBExpr->op!=TK_COLUMN && pOBExpr->op!=TK_AGG_COLUMN ) break;
175042 if( pOBExpr->iTable!=iCur ) break;
175043 if( pOBExpr->iColumn!=pSubOB->a[jSub].u.x.iOrderByCol-1 ) break;
175044 if( (wctrlFlags & WHERE_GROUPBY)==0 ){
175045 u8 sfOB = pOrderBy->a[iOB].fg.sortFlags; /* sortFlags for iOB */
175046 u8 sfSub = pSubOB->a[jSub].fg.sortFlags; /* sortFlags for jSub */
175047 if( (sfSub & KEYINFO_ORDER_BIGNULL) != (sfOB & KEYINFO_ORDER_BIGNULL) ){
175048 break;
175049 }
@@ -174924,20 +175221,20 @@
175221
175222 if( (pLoop->wsFlags & WHERE_ONEROW)==0 ){
175223 if( pLoop->wsFlags & WHERE_IPK ){
175224 if( pLoop->u.btree.pOrderBy
175225 && OptimizationEnabled(db, SQLITE_OrderBySubq)
175226 && wherePathMatchSubqueryOB(pLoop,iLoop,iCur,
175227 pOrderBy,pRevMask, &obSat, wctrlFlags)
175228 ){
175229 nColumn = 0;
175230 isOrderDistinct = 0;
175231 }else{
175232 nColumn = 1;
175233 }
175234 pIndex = 0;
175235 nKeyCol = 1;
175236 }else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
175237 return 0;
175238 }else{
175239 nKeyCol = pIndex->nKeyCol;
175240 nColumn = pIndex->nColumn;
@@ -175074,11 +175371,18 @@
175371 if( rev ) *pRevMask |= MASKBIT(iLoop);
175372 revSet = 1;
175373 }
175374 }
175375 if( isMatch && (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL) ){
175376 if( j==pLoop->u.btree.nEq
175377 && (j<nKeyCol||HasRowid(pIndex->pTable)||!IsPrimaryKeyIndex(pIndex))
175378 ){
175379 /* If this is the PK of a WITHOUT ROWID table, do not use any
175380 ** field past nKeyCol for a NULLS LAST sort. If ALTER TABLE has
175381 ** been used to add columns to the table, this field may not
175382 ** be present in all records, which causes problems for the seeks
175383 ** used by NULLS LAST sorts. */
175384 pLoop->wsFlags |= WHERE_BIGNULL_SORT;
175385 }else{
175386 isMatch = 0;
175387 }
175388 }
@@ -175088,11 +175392,12 @@
175392 distinctColumns = 1;
175393 }
175394 obSat |= MASKBIT(i);
175395 }else{
175396 /* No match found */
175397 assert( nKeyCol>0 );
175398 if( j<nKeyCol ){
175399 testcase( isOrderDistinct!=0 );
175400 isOrderDistinct = 0;
175401 }
175402 break;
175403 }
@@ -177249,10 +177554,21 @@
177554 if( pTabList->a[pLevel->iFrom].fg.fromExists ){
177555 /* This is an EXISTS-to-JOIN optimization loop. If this loop sees a
177556 ** successful row, it should break out of itself. */
177557 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrBrk);
177558 VdbeComment((v, "EXISTS break %d", i));
177559 }else if( pLevel->addrDeleteCont ){
177560 /* An inner loop matched no rows on this auto-index driven loop and
177561 ** there are outer loops. So delete the auto-index entry to avoid
177562 ** future unnecessary work. */
177563 int iBypass = sqlite3VdbeAddOp0(v, OP_Goto);
177564 assert( pLoop->wsFlags & WHERE_AUTO_INDEX );
177565 sqlite3VdbeResolveLabel(v, pLevel->addrDeleteCont);
177566 sqlite3VdbeAddOp1(v, OP_Delete, pLevel->iIdxCur);
177567 sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
177568 VdbeComment((v, "delete useless auto-index entry"));
177569 sqlite3VdbeJumpHere(v, iBypass);
177570 }
177571 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
177572 if( pLevel->op!=OP_Noop ){
177573 sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
177574 sqlite3VdbeChangeP5(v, pLevel->p5);
@@ -177270,14 +177586,35 @@
177586 sqlite3VdbeResolveLabel(v, pLevel->addrBignull);
177587 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, pLevel->regBignull, pLevel->p2-1);
177588 VdbeCoverage(v);
177589 }
177590 }
177591 if( pLevel->addrNxt!=pLevel->addrBrk ){
177592 /* This occurs in three cases - (a) for a LIKE/GLOB scan that must visit
177593 ** ranges of text and blob values separately, and (b) when there is
177594 ** an IN(...) constraint driving the index, and (c) when a prior error
177595 ** such as an OOM has left us in an unusual state. This is asserted()
177596 ** in the next block, inside the #ifndef. */
177597 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
177598 }
177599 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
177600 assert( (pLevel->addrNxt==pLevel->addrBrk)
177601 || (pLevel->addrLikeRep) /* (a) */
177602 || ((pLoop->wsFlags & WHERE_IN_ABLE) && pLevel->u.in.nIn>0) /* (b) */
177603 || pWInfo->pParse->nErr>0 /* (c) */
177604 );
177605 if( pLevel->addrLikeRep ){
177606 /* The LIKE optimization loop is nested inside any IN(...) and
177607 ** skip-scan loops, so it is closed here, before either of those. */
177608 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, (int)(pLevel->iLikeRepCntr>>1),
177609 pLevel->addrLikeRep);
177610 VdbeCoverage(v);
177611 }
177612 #endif
177613 if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){
177614 struct InLoop *pIn;
177615 int j;
 
177616 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
177617 assert( sqlite3VdbeGetOp(v, pIn->addrInTop+1)->opcode==OP_IsNull
177618 || pParse->db->mallocFailed );
177619 sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
177620 if( pIn->eEndLoopOp!=OP_Noop ){
@@ -177325,17 +177662,10 @@
177662 sqlite3VdbeGoto(v, pLevel->addrSkip);
177663 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
177664 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
177665 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
177666 }
 
 
 
 
 
 
 
177667 if( pLevel->iLeftJoin ){
177668 int ws = pLoop->wsFlags;
177669 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
177670 assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 );
177671 if( (ws & WHERE_IDX_ONLY)==0 ){
@@ -212949,17 +213279,15 @@
213279 /* #include <string.h> */
213280
213281 /* #include "fts3_tokenizer.h" */
213282
213283 /*
213284 ** The following two macros - FTS3_READ_UTF8 and FTS3_WRITE_UTF8 - have
213285 ** been copied from the sqlite3 source file utf.c.
 
213286 */
 
213287
213288 static const unsigned char fts3Utf8Trans1[] = {
213289 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
213290 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
213291 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
213292 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
213293 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -212966,43 +213294,41 @@
213294 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
213295 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
213296 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
213297 };
213298
213299 #define FTS3_READ_UTF8(zIn, zTerm, c) \
213300 c = *(zIn++); \
213301 if( c>=0xc0 ){ \
213302 c = fts3Utf8Trans1[c-0xc0]; \
213303 while( zIn!=zTerm && (*zIn & 0xc0)==0x80 ){ \
213304 c = (c<<6) + (0x3f & *(zIn++)); \
213305 } \
213306 if( c<0x80 \
213307 || (c&0xFFFFF800)==0xD800 \
213308 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
213309 }
213310
213311 #define FTS3_WRITE_UTF8(zOut, c) { \
213312 if( c<0x00080 ){ \
213313 *zOut++ = (u8)(c&0xFF); \
213314 } \
213315 else if( c<0x00800 ){ \
213316 *zOut++ = 0xC0 + (u8)((c>>6)&0x1F); \
213317 *zOut++ = 0x80 + (u8)(c & 0x3F); \
213318 } \
213319 else if( c<0x10000 ){ \
213320 *zOut++ = 0xE0 + (u8)((c>>12)&0x0F); \
213321 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
213322 *zOut++ = 0x80 + (u8)(c & 0x3F); \
213323 }else{ \
213324 *zOut++ = 0xF0 + (u8)((c>>18) & 0x07); \
213325 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F); \
213326 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F); \
213327 *zOut++ = 0x80 + (u8)(c & 0x3F); \
213328 } \
213329 }
 
 
213330
213331 typedef struct unicode_tokenizer unicode_tokenizer;
213332 typedef struct unicode_cursor unicode_cursor;
213333
213334 struct unicode_tokenizer {
@@ -213065,11 +213391,11 @@
213391 int nEntry = 0;
213392
213393 assert( bAlnum==0 || bAlnum==1 );
213394
213395 while( z<zTerm ){
213396 FTS3_READ_UTF8(z, zTerm, iCode);
213397 assert( (sqlite3FtsUnicodeIsalnum((int)iCode) & 0xFFFFFFFE)==0 );
213398 if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum
213399 && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
213400 ){
213401 nEntry++;
@@ -213084,11 +213410,11 @@
213410 if( aNew==0 ) return SQLITE_NOMEM;
213411 nNew = p->nException;
213412
213413 z = (const unsigned char *)zIn;
213414 while( z<zTerm ){
213415 FTS3_READ_UTF8(z, zTerm, iCode);
213416 if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum
213417 && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
213418 ){
213419 int i, j;
213420 for(i=0; i<nNew && aNew[i]<(int)iCode; i++);
@@ -213256,11 +213582,11 @@
213582
213583 /* Scan past any delimiter characters before the start of the next token.
213584 ** Return SQLITE_DONE early if this takes us all the way to the end of
213585 ** the input. */
213586 while( z<zTerm ){
213587 FTS3_READ_UTF8(z, zTerm, iCode);
213588 if( unicodeIsAlnum(p, (int)iCode) ) break;
213589 zStart = z;
213590 }
213591 if( zStart>=zTerm ) return SQLITE_DONE;
213592
@@ -213279,16 +213605,16 @@
213605
213606 /* Write the folded case of the last character read to the output */
213607 zEnd = z;
213608 iOut = sqlite3FtsUnicodeFold((int)iCode, p->eRemoveDiacritic);
213609 if( iOut ){
213610 FTS3_WRITE_UTF8(zOut, iOut);
213611 }
213612
213613 /* If the cursor is not at EOF, read the next character */
213614 if( z>=zTerm ) break;
213615 FTS3_READ_UTF8(z, zTerm, iCode);
213616 }while( unicodeIsAlnum(p, (int)iCode)
213617 || sqlite3FtsUnicodeIsdiacritic((int)iCode)
213618 );
213619
213620 /* Set the output variables and return. */
@@ -214107,10 +214433,11 @@
214433 /*
214434 ** Allowed values for the flgs argument to jsonParseFuncArg();
214435 */
214436 #define JSON_EDITABLE 0x01 /* Generate a writable JsonParse object */
214437 #define JSON_KEEPERROR 0x02 /* Return non-NULL even if there is an error */
214438 #define JSON_NOCACHE 0x04 /* Do not use the JSON cache */
214439
214440 /**************************************************************************
214441 ** Forward references
214442 **************************************************************************/
214443 static void jsonReturnStringAsBlob(JsonString*);
@@ -217550,11 +217877,13 @@
217877 assert( ctx!=0 );
217878 eType = sqlite3_value_type(pArg);
217879 if( eType==SQLITE_NULL ){
217880 return 0;
217881 }
217882 if( (flgs & JSON_NOCACHE)==0 ){
217883 pFromCache = jsonCacheSearch(ctx, pArg);
217884 }
217885 if( pFromCache ){
217886 pFromCache->nJPRef++;
217887 if( (flgs & JSON_EDITABLE)==0 ){
217888 return pFromCache;
217889 }
@@ -218625,11 +218954,11 @@
218954 default: {
218955 JsonParse px;
218956 if( (flags & 0x3)==0 ) break;
218957 memset(&px, 0, sizeof(px));
218958
218959 p = jsonParseFuncArg(ctx, argv[0], JSON_KEEPERROR|JSON_NOCACHE);
218960 if( p ){
218961 if( p->oom ){
218962 sqlite3_result_error_nomem(ctx);
218963 }else if( p->nErr ){
218964 /* no-op */
@@ -219218,21 +219547,20 @@
219547 */
219548 static int jsonEachPathLength(JsonEachCursor *p){
219549 u32 n = p->path.nUsed;
219550 char *z = p->path.zBuf;
219551 if( p->iRowid==0 && p->bRecursive && n>=2 ){
219552 while( ALWAYS(n>1) ){
219553 n--;
219554 if( z[n]=='[' || z[n]=='.' ){
219555 u32 x;
219556 char cSaved = z[n];
219557 z[n] = 0;
219558 assert( p->sParse.eEdit==0 );
219559 x = jsonLookupStep(&p->sParse, 0, z+1, 0);
219560 z[n] = cSaved;
219561 if( !JSON_LOOKUP_ISERROR(x) ) break;
 
219562 }
219563 }
219564 }
219565 return n;
219566 }
@@ -246043,11 +246371,26 @@
246371 }
246372
246373 return rc;
246374 }
246375
246376 /*
246377 ** Load error code rc into the context handle pCtx. Except, if
246378 ** rc==SQLITE_ERROR and there is an error message in the associated db
246379 ** handle, return that error message as well.
246380 */
246381 static void fts5AuxResultError(sqlite3_context *pCtx, int rc){
246382 if( rc==SQLITE_ERROR ){
246383 sqlite3 *db = sqlite3_context_db_handle(pCtx);
246384 if( sqlite3_errcode(db)==SQLITE_ERROR ){
246385 const char *zErr = sqlite3_errmsg(db);
246386 sqlite3_result_error(pCtx, zErr, -1);
246387 return;
246388 }
246389 }
246390 sqlite3_result_error_code(pCtx, rc);
246391 }
246392
246393 /*************************************************************************
246394 ** Start of highlight() implementation.
246395 */
246396 typedef struct HighlightContext HighlightContext;
@@ -246232,11 +246575,11 @@
246575 sqlite3_result_text(pCtx, (const char*)ctx.zOut, -1, SQLITE_TRANSIENT);
246576 }
246577 sqlite3_free(ctx.zOut);
246578 }
246579 if( rc!=SQLITE_OK ){
246580 fts5AuxResultError(pCtx, rc);
246581 }
246582 }
246583 /*
246584 ** End of highlight() implementation.
246585 **************************************************************************/
@@ -246526,11 +246869,11 @@
246869 }
246870 }
246871 if( rc==SQLITE_OK ){
246872 sqlite3_result_text(pCtx, (const char*)ctx.zOut, -1, SQLITE_TRANSIENT);
246873 }else{
246874 fts5AuxResultError(pCtx, rc);
246875 }
246876 sqlite3_free(ctx.zOut);
246877 sqlite3_free(aSeen);
246878 sqlite3_free(sFinder.aFirst);
246879 }
@@ -246692,11 +247035,11 @@
247035 ( aFreq[i] + k1 * (1 - b + b * D / pData->avgdl) )
247036 );
247037 }
247038 sqlite3_result_double(pCtx, -1.0 * score);
247039 }else{
247040 fts5AuxResultError(pCtx, rc);
247041 }
247042 }
247043
247044 /*
247045 ** Implementation of fts5_get_locale() function.
@@ -246730,17 +247073,17 @@
247073 return;
247074 }
247075
247076 iCol = fts5ValueClampedInt(apVal[0]);
247077 if( iCol<0 || iCol>=pApi->xColumnCount(pFts) ){
247078 fts5AuxResultError(pCtx, SQLITE_RANGE);
247079 return;
247080 }
247081
247082 rc = pApi->xColumnLocale(pFts, iCol, &zLocale, &nLocale);
247083 if( rc!=SQLITE_OK ){
247084 fts5AuxResultError(pCtx, rc);
247085 return;
247086 }
247087
247088 sqlite3_result_text(pCtx, zLocale, nLocale, SQLITE_TRANSIENT);
247089 }
@@ -265407,11 +265750,11 @@
265750 int nArg, /* Number of args */
265751 sqlite3_value **apUnused /* Function arguments */
265752 ){
265753 assert( nArg==0 );
265754 UNUSED_PARAM2(nArg, apUnused);
265755 sqlite3_result_text(pCtx, "fts5: 2026-10-16 14:31:53 668541c592b89d32716420615450d55d9faf89da8a8e389c673973d8383cca98", -1, SQLITE_TRANSIENT);
265756 }
265757
265758 /*
265759 ** Implementation of fts5_locale(LOCALE, TEXT) function.
265760 **
@@ -265886,17 +266229,17 @@
266229 if( eStmt>FTS5_STMT_LOOKUP2 ) f |= SQLITE_PREPARE_NO_VTAB;
266230 p->pConfig->bLock++;
266231 rc = sqlite3_prepare_v3(pC->db, zSql, -1, f, &p->aStmt[eStmt], 0);
266232 p->pConfig->bLock--;
266233 sqlite3_free(zSql);
 
 
 
266234 if( rc==SQLITE_ERROR && eStmt>FTS5_STMT_LOOKUP2 && eStmt<FTS5_STMT_SCAN ){
266235 /* One of the internal tables - not the %_content table - is missing.
266236 ** This counts as a corrupted table. */
266237 rc = SQLITE_CORRUPT_VTAB;
266238 }else if( rc!=SQLITE_OK && p->pConfig->pzErrmsg ){
266239 assert( *p->pConfig->pzErrmsg==0 );
266240 *p->pConfig->pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(pC->db));
266241 }
266242 }
266243 }
266244
266245 *ppStmt = p->aStmt[eStmt];
@@ -267411,17 +267754,14 @@
267754 ** Start of unicode61 tokenizer implementation.
267755 */
267756
267757
267758 /*
267759 ** The following two macros - FTS5_READ_UTF8 and FTS5_WRITE_UTF8 - have
267760 ** been copied from the sqlite3 source file utf.c.
 
267761 */
267762 static const unsigned char fts5Utf8Trans1[] = {
 
 
267763 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
267764 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
267765 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
267766 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
267767 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -267428,49 +267768,47 @@
267768 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
267769 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
267770 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
267771 };
267772
267773 #define FTS5_READ_UTF8(zIn, zTerm, c) \
267774 c = *(zIn++); \
267775 if( c>=0xc0 ){ \
267776 c = fts5Utf8Trans1[c-0xc0]; \
267777 while( zIn<zTerm && (*zIn & 0xc0)==0x80 ){ \
267778 c = (c<<6) + (0x3f & *(zIn++)); \
267779 } \
267780 if( c<0x80 \
267781 || (c&0xFFFFF800)==0xD800 \
267782 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
267783 }
267784
267785
267786 #define FTS5_WRITE_UTF8(zOut, c) { \
267787 if( c<0x00080 ){ \
267788 *zOut++ = (unsigned char)(c&0xFF); \
267789 } \
267790 else if( c<0x00800 ){ \
267791 *zOut++ = 0xC0 + (unsigned char)((c>>6)&0x1F); \
267792 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
267793 } \
267794 else if( c<0x10000 ){ \
267795 *zOut++ = 0xE0 + (unsigned char)((c>>12)&0x0F); \
267796 *zOut++ = 0x80 + (unsigned char)((c>>6) & 0x3F); \
267797 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
267798 }else{ \
267799 *zOut++ = 0xF0 + (unsigned char)((c>>18) & 0x07); \
267800 *zOut++ = 0x80 + (unsigned char)((c>>12) & 0x3F); \
267801 *zOut++ = 0x80 + (unsigned char)((c>>6) & 0x3F); \
267802 *zOut++ = 0x80 + (unsigned char)(c & 0x3F); \
267803 } \
267804 }
267805
267806 #define FTS5_SKIP_UTF8(zIn) { \
267807 if( ((unsigned char)(*(zIn++)))>=0xc0 ){ \
267808 while( (((unsigned char)*zIn) & 0xc0)==0x80 ){zIn++;} \
267809 } \
 
 
267810 }
267811
267812 typedef struct Unicode61Tokenizer Unicode61Tokenizer;
267813 struct Unicode61Tokenizer {
267814 unsigned char aTokenChar[128]; /* ASCII range token characters */
@@ -267505,11 +267843,11 @@
267843 const unsigned char *zCsr = (const unsigned char*)z;
267844 const unsigned char *zTerm = (const unsigned char*)&z[n];
267845 while( zCsr<zTerm ){
267846 u32 iCode;
267847 int bToken;
267848 FTS5_READ_UTF8(zCsr, zTerm, iCode);
267849 if( iCode<128 ){
267850 p->aTokenChar[iCode] = (unsigned char)bTokenChars;
267851 }else{
267852 bToken = p->aCategory[sqlite3Fts5UnicodeCategory(iCode)];
267853 assert( (bToken==0 || bToken==1) );
@@ -267709,11 +268047,11 @@
268047 if( zCsr>=zTerm ) goto tokenize_done;
268048 if( *zCsr & 0x80 ) {
268049 /* A character outside of the ascii range. Skip past it if it is
268050 ** a separator character. Or break out of the loop if it is not. */
268051 is = zCsr - (unsigned char*)pText;
268052 FTS5_READ_UTF8(zCsr, zTerm, iCode);
268053 if( fts5UnicodeIsAlnum(p, iCode) ){
268054 goto non_ascii_tokenchar;
268055 }
268056 }else{
268057 if( a[*zCsr] ){
@@ -267745,15 +268083,15 @@
268083 }
268084
268085 if( *zCsr & 0x80 ){
268086 /* An non-ascii-range character. Fold it into the output buffer if
268087 ** it is a token character, or break out of the loop if it is not. */
268088 FTS5_READ_UTF8(zCsr, zTerm, iCode);
268089 if( fts5UnicodeIsAlnum(p,iCode)||sqlite3Fts5UnicodeIsdiacritic(iCode) ){
268090 non_ascii_tokenchar:
268091 iCode = sqlite3Fts5UnicodeFold(iCode, p->eRemoveDiacritic);
268092 if( iCode ) FTS5_WRITE_UTF8(zOut, iCode);
268093 }else{
268094 break;
268095 }
268096 }else if( a[*zCsr]==0 ){
268097 /* An ascii-range separator character. End of token. */
@@ -268604,14 +268942,14 @@
268942 /* Populate aBuf[] with the characters for the first trigram. */
268943 for(ii=0; ii<3; ii++){
268944 do {
268945 aStart[ii] = zIn - (const unsigned char*)pText;
268946 if( zIn>=zEof ) return SQLITE_OK;
268947 FTS5_READ_UTF8(zIn, zEof, iCode);
268948 if( p->bFold ) iCode = sqlite3Fts5UnicodeFold(iCode, p->iFoldParam);
268949 }while( iCode==0 );
268950 FTS5_WRITE_UTF8(zOut, iCode);
268951 }
268952
268953 /* At the start of each iteration of this loop:
268954 **
268955 ** aBuf: Contains 3 characters. The 3 characters of the next trigram.
@@ -268629,11 +268967,11 @@
268967 iNext = zIn - (const unsigned char*)pText;
268968 if( zIn>=zEof ){
268969 iCode = 0;
268970 break;
268971 }
268972 FTS5_READ_UTF8(zIn, zEof, iCode);
268973 if( p->bFold ) iCode = sqlite3Fts5UnicodeFold(iCode, p->iFoldParam);
268974 }while( iCode==0 );
268975
268976 /* Pass the current trigram back to fts5 */
268977 rc = xToken(pCtx, 0, aBuf, zOut-aBuf, aStart[0], iNext);
@@ -268643,11 +268981,11 @@
268981 ** with codepoint iCode. */
268982 z1 = aBuf;
268983 FTS5_SKIP_UTF8(z1);
268984 memmove(aBuf, z1, zOut - z1);
268985 zOut -= (z1 - aBuf);
268986 FTS5_WRITE_UTF8(zOut, iCode);
268987
268988 /* Update the aStart[] array */
268989 aStart[0] = aStart[1];
268990 aStart[1] = aStart[2];
268991 aStart[2] = iNext;
268992
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,16 +144,16 @@
144144
**
145145
** See also: [sqlite3_libversion()],
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149
-#define SQLITE_VERSION "3.54.0"
150
-#define SQLITE_VERSION_NUMBER 3054000
151
-#define SQLITE_SOURCE_ID "2026-10-09 11:47:51 a3332bd623d997921c3186433cd1eab0c9413aa0f68d93b1731cf80128ec3a36"
149
+#define SQLITE_VERSION "3.55.0"
150
+#define SQLITE_VERSION_NUMBER 3055000
151
+#define SQLITE_SOURCE_ID "2026-10-16 14:31:53 668541c592b89d32716420615450d55d9faf89da8a8e389c673973d8383cca98"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2026-10-09T11:47:51.732Z"
154
+#define SQLITE_SCM_DATETIME "2026-10-16T14:31:53.543Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
@@ -4078,11 +4078,11 @@
40784078
** parameter on F or if the value of P does not match any of the
40794079
** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
40804080
**
40814081
** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
40824082
** 64-bit signed integer and returns that integer, or D if P does not
4083
-** exist or ff the value of P is something other than an integer.
4083
+** exist or if the value of P is something other than an integer.
40844084
**
40854085
** The sqlite3_uri_key(F,N) returns a pointer to the name (not
40864086
** the value) of the N-th query parameter for filename F, or a NULL
40874087
** pointer if N is less than zero or greater than the number of query
40884088
** parameters minus 1. The N value is zero-based so N should be 0 to obtain
40894089
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,16 +144,16 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-10-09 11:47:51 a3332bd623d997921c3186433cd1eab0c9413aa0f68d93b1731cf80128ec3a36"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-10-09T11:47:51.732Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -4078,11 +4078,11 @@
4078 ** parameter on F or if the value of P does not match any of the
4079 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4080 **
4081 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4082 ** 64-bit signed integer and returns that integer, or D if P does not
4083 ** exist or ff the value of P is something other than an integer.
4084 **
4085 ** The sqlite3_uri_key(F,N) returns a pointer to the name (not
4086 ** the value) of the N-th query parameter for filename F, or a NULL
4087 ** pointer if N is less than zero or greater than the number of query
4088 ** parameters minus 1. The N value is zero-based so N should be 0 to obtain
4089
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,16 +144,16 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.55.0"
150 #define SQLITE_VERSION_NUMBER 3055000
151 #define SQLITE_SOURCE_ID "2026-10-16 14:31:53 668541c592b89d32716420615450d55d9faf89da8a8e389c673973d8383cca98"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-10-16T14:31:53.543Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -4078,11 +4078,11 @@
4078 ** parameter on F or if the value of P does not match any of the
4079 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4080 **
4081 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4082 ** 64-bit signed integer and returns that integer, or D if P does not
4083 ** exist or if the value of P is something other than an integer.
4084 **
4085 ** The sqlite3_uri_key(F,N) returns a pointer to the name (not
4086 ** the value) of the N-th query parameter for filename F, or a NULL
4087 ** pointer if N is less than zero or greater than the number of query
4088 ** parameters minus 1. The N value is zero-based so N should be 0 to obtain
4089

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button