Fossil SCM

Import the latest trunk version of SQLite from upstream, for beta testing.

drh 2026-08-20 14:48 UTC trunk
Commit 471d617347aebb6b1964e9538ede8dd0d51b502813a69c0a7aa32fc69ec8a097
+14
--- extsrc/qrf.h
+++ extsrc/qrf.h
@@ -57,10 +57,12 @@
5757
void *pRenderArg; /* First argument to the xRender callback */
5858
void *pWriteArg; /* First argument to the xWrite callback */
5959
char **pzOutput; /* Storage location for output string */
6060
/* The following are available in iVersion 2 and later */
6161
unsigned char bRowCount; /* Show the number of rows at end of each query */
62
+ char *zIFmt; /* Format string for integers */
63
+ char *zFpFmt; /* Format string for floating point */
6264
/* Additional fields may be added in the future */
6365
};
6466
6567
/*
6668
** Interfaces
@@ -198,10 +200,22 @@
198200
** determined as for sqlite3_qrf_wcwidth(). VT100 escape code sequences
199201
** are assigned a width of zero.
200202
*/
201203
size_t sqlite3_qrf_wcswidth(const char*);
202204
205
+/*
206
+** The argument is a proposed format string for the zIFmt or zFpFmt
207
+** parameters. Return value indicates:
208
+**
209
+** 0 The input is not a valid format string. If this string
210
+** appears in either zIFmt or zFpFmt, it will be ignored.
211
+**
212
+** 1 The input is a valid format string for integers.
213
+**
214
+** 2 The input is a valid format string for floating point.
215
+*/
216
+int sqlite3_qrf_ckformat(const char*);
203217
204218
#ifdef __cplusplus
205219
}
206220
#endif
207221
#endif /* !defined(SQLITE_QRF_H) */
208222
--- extsrc/qrf.h
+++ extsrc/qrf.h
@@ -57,10 +57,12 @@
57 void *pRenderArg; /* First argument to the xRender callback */
58 void *pWriteArg; /* First argument to the xWrite callback */
59 char **pzOutput; /* Storage location for output string */
60 /* The following are available in iVersion 2 and later */
61 unsigned char bRowCount; /* Show the number of rows at end of each query */
 
 
62 /* Additional fields may be added in the future */
63 };
64
65 /*
66 ** Interfaces
@@ -198,10 +200,22 @@
198 ** determined as for sqlite3_qrf_wcwidth(). VT100 escape code sequences
199 ** are assigned a width of zero.
200 */
201 size_t sqlite3_qrf_wcswidth(const char*);
202
 
 
 
 
 
 
 
 
 
 
 
 
203
204 #ifdef __cplusplus
205 }
206 #endif
207 #endif /* !defined(SQLITE_QRF_H) */
208
--- extsrc/qrf.h
+++ extsrc/qrf.h
@@ -57,10 +57,12 @@
57 void *pRenderArg; /* First argument to the xRender callback */
58 void *pWriteArg; /* First argument to the xWrite callback */
59 char **pzOutput; /* Storage location for output string */
60 /* The following are available in iVersion 2 and later */
61 unsigned char bRowCount; /* Show the number of rows at end of each query */
62 char *zIFmt; /* Format string for integers */
63 char *zFpFmt; /* Format string for floating point */
64 /* Additional fields may be added in the future */
65 };
66
67 /*
68 ** Interfaces
@@ -198,10 +200,22 @@
200 ** determined as for sqlite3_qrf_wcwidth(). VT100 escape code sequences
201 ** are assigned a width of zero.
202 */
203 size_t sqlite3_qrf_wcswidth(const char*);
204
205 /*
206 ** The argument is a proposed format string for the zIFmt or zFpFmt
207 ** parameters. Return value indicates:
208 **
209 ** 0 The input is not a valid format string. If this string
210 ** appears in either zIFmt or zFpFmt, it will be ignored.
211 **
212 ** 1 The input is a valid format string for integers.
213 **
214 ** 2 The input is a valid format string for floating point.
215 */
216 int sqlite3_qrf_ckformat(const char*);
217
218 #ifdef __cplusplus
219 }
220 #endif
221 #endif /* !defined(SQLITE_QRF_H) */
222
+143 -8
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -746,10 +746,12 @@
746746
void *pRenderArg; /* First argument to the xRender callback */
747747
void *pWriteArg; /* First argument to the xWrite callback */
748748
char **pzOutput; /* Storage location for output string */
749749
/* The following are available in iVersion 2 and later */
750750
unsigned char bRowCount; /* Show the number of rows at end of each query */
751
+ char *zIFmt; /* Format string for integers */
752
+ char *zFpFmt; /* Format string for floating point */
751753
/* Additional fields may be added in the future */
752754
};
753755
754756
/*
755757
** Interfaces
@@ -887,10 +889,22 @@
887889
** determined as for sqlite3_qrf_wcwidth(). VT100 escape code sequences
888890
** are assigned a width of zero.
889891
*/
890892
size_t sqlite3_qrf_wcswidth(const char*);
891893
894
+/*
895
+** The argument is a proposed format string for the zIFmt or zFpFmt
896
+** parameters. Return value indicates:
897
+**
898
+** 0 The input is not a valid format string. If this string
899
+** appears in either zIFmt or zFpFmt, it will be ignored.
900
+**
901
+** 1 The input is a valid format string for integers.
902
+**
903
+** 2 The input is a valid format string for floating point.
904
+*/
905
+int sqlite3_qrf_ckformat(const char*);
892906
893907
#ifdef __cplusplus
894908
}
895909
#endif
896910
#endif /* !defined(SQLITE_QRF_H) */
@@ -969,10 +983,11 @@
969983
} sExpln;
970984
unsigned int nIns; /* Bytes used for current INSERT stmt */
971985
} u;
972986
sqlite3_int64 nRow; /* Number of rows handled so far */
973987
int *actualWidth; /* Actual width of each column */
988
+ char zFmt[24]; /* Space to hold the true integer rendering fmt */
974989
sqlite3_qrf_spec spec; /* Copy of the original spec */
975990
};
976991
977992
/*
978993
** Data for substitute ctype.h functions. Used for x-platform
@@ -1012,10 +1027,48 @@
10121027
# define deliberate_fall_through __attribute__((fallthrough));
10131028
# else
10141029
# define deliberate_fall_through
10151030
# endif
10161031
#endif
1032
+
1033
+/*
1034
+** The argument is a proposed format string for the zIFmt or zFpFmt
1035
+** parameters. Return value indicates:
1036
+**
1037
+** 0 The input is not a valid format string. If this string
1038
+** appears in either zIFmt or zFpFmt, it will be ignored.
1039
+**
1040
+** 1 The input is a valid format string for integers.
1041
+**
1042
+** 2 The input is a valid format string for floating point.
1043
+*/
1044
+int sqlite3_qrf_ckformat(const char *z){
1045
+ size_t n;
1046
+ if( z==0 ) return 0;
1047
+ if( z[0]!='%' ) return 0;
1048
+ z++;
1049
+ n = strspn(z,"+-,#0");
1050
+ if( n>5 ) return 0;
1051
+ z += n;
1052
+ if( z[0]>='1' && z[0]<='9' ){
1053
+ n = strspn(z,"0123456789");
1054
+ if( n>3 ) return 0;
1055
+ z += n;
1056
+ }
1057
+ if( z[0]=='.' ){
1058
+ z++;
1059
+ n = strspn(z,"0123456789");
1060
+ if( n>3 ) return 0;
1061
+ z += n;
1062
+ }
1063
+ n = strspn(z,"eEgGf");
1064
+ if( n==1 && z[1]==0 ) return 2;
1065
+ n = strspn(z,"dxXo");
1066
+ if( n==1 && z[1]==0 ) return 1;
1067
+ return 0;
1068
+}
1069
+
10171070
10181071
/*
10191072
** Set an error code and error message.
10201073
*/
10211074
static void qrfError(
@@ -2000,16 +2053,22 @@
20002053
return;
20012054
}
20022055
}
20032056
switch( sqlite3_column_type(p->pStmt,iCol) ){
20042057
case SQLITE_INTEGER: {
2005
- sqlite3_str_appendf(pOut, "%lld", sqlite3_column_int64(p->pStmt,iCol));
2058
+ sqlite3_str_appendf(pOut, p->spec.zIFmt,
2059
+ sqlite3_column_int64(p->pStmt,iCol));
20062060
break;
20072061
}
20082062
case SQLITE_FLOAT: {
2009
- const char *zTxt = (const char*)sqlite3_column_text(p->pStmt,iCol);
2010
- sqlite3_str_appendall(pOut, zTxt);
2063
+ if( p->spec.zFpFmt ){
2064
+ double r = sqlite3_column_double(p->pStmt,iCol);
2065
+ sqlite3_str_appendf(pOut,p->spec.zFpFmt,r);
2066
+ }else{
2067
+ const char *zTxt = (const char*)sqlite3_column_text(p->pStmt,iCol);
2068
+ sqlite3_str_appendall(pOut, zTxt);
2069
+ }
20112070
break;
20122071
}
20132072
case SQLITE_BLOB: {
20142073
if( p->spec.bTextJsonb==QRF_Yes ){
20152074
const char *zJson = qrfJsonbToJson(p, iCol);
@@ -3728,11 +3787,15 @@
37283787
return;
37293788
}
37303789
p->iErr = SQLITE_OK;
37313790
p->nCol = sqlite3_column_count(p->pStmt);
37323791
p->nRow = 0;
3733
- sz = sizeof(sqlite3_qrf_spec);
3792
+ switch( pSpec->iVersion ){
3793
+ case 0: sz = offsetof(sqlite3_qrf_spec, bRowCount); break;
3794
+ case 1: sz = offsetof(sqlite3_qrf_spec, bRowCount); break;
3795
+ default: sz = sizeof(sqlite3_qrf_spec); break;
3796
+ }
37343797
memcpy(&p->spec, pSpec, sz);
37353798
if( p->spec.zNull==0 ) p->spec.zNull = "";
37363799
p->mxWidth = p->spec.nScreenWidth;
37373800
if( p->mxWidth<=0 ) p->mxWidth = 2147483647;
37383801
p->mxHeight = p->spec.nLineLimit;
@@ -3740,13 +3803,10 @@
37403803
if( p->spec.eStyle>QRF_STYLE_Table ) p->spec.eStyle = QRF_Auto;
37413804
if( p->spec.eEsc>QRF_ESC_Symbol ) p->spec.eEsc = QRF_Auto;
37423805
if( p->spec.eText>QRF_TEXT_Relaxed ) p->spec.eText = QRF_Auto;
37433806
if( p->spec.eTitle>QRF_TEXT_Relaxed ) p->spec.eTitle = QRF_Auto;
37443807
if( p->spec.eBlob>QRF_BLOB_Size ) p->spec.eBlob = QRF_Auto;
3745
- if( pSpec->iVersion<=1 ){
3746
- p->spec.bRowCount = 0;
3747
- }
37483808
qrf_reinit:
37493809
switch( p->spec.eStyle ){
37503810
case QRF_Auto: {
37513811
switch( sqlite3_stmt_isexplain(pStmt) ){
37523812
case 0: p->spec.eStyle = QRF_STYLE_Box; break;
@@ -3867,10 +3927,24 @@
38673927
if( p->spec.bTextJsonb==QRF_Auto ){
38683928
p->spec.bTextJsonb = QRF_No;
38693929
}
38703930
if( p->spec.zColumnSep==0 ) p->spec.zColumnSep = ",";
38713931
if( p->spec.zRowSep==0 ) p->spec.zRowSep = "\n";
3932
+ if( p->spec.zIFmt==0 || sqlite3_qrf_ckformat(p->spec.zIFmt)!=1 ){
3933
+ p->spec.zIFmt = "%lld";
3934
+ }else{
3935
+ size_t n = strlen(p->spec.zIFmt);
3936
+ memcpy(p->zFmt, p->spec.zIFmt, n-1);
3937
+ p->zFmt[n-1] = 'l';
3938
+ p->zFmt[n] = 'l';
3939
+ p->zFmt[n+1] = p->spec.zIFmt[n-1];
3940
+ p->zFmt[n+2] = 0;
3941
+ p->spec.zIFmt = p->zFmt;
3942
+ }
3943
+ if( p->spec.zFpFmt && sqlite3_qrf_ckformat(p->spec.zFpFmt)!=2 ){
3944
+ p->spec.zFpFmt = 0;
3945
+ }
38723946
}
38733947
38743948
/*
38753949
** Finish rendering the results
38763950
*/
@@ -14064,14 +14138,14 @@
1406414138
if( zUpdate && zipfileComparePath(zUpdate, zDelete, nDelete)!=0 ){
1406514139
bUpdate = 1;
1406614140
}
1406714141
}
1406814142
for(pOld=pTab->pFirstEntry; 1; pOld=pOld->pNext){
14143
+ if( pOld==0 ) return SQLITE_OK;
1406914144
if( zipfileComparePath(pOld->cds.zFile, zDelete, nDelete)==0 ){
1407014145
break;
1407114146
}
14072
- assert( pOld->pNext );
1407314147
}
1407414148
}
1407514149
1407614150
if( nVal>1 ){
1407714151
/* Check that "sz" and "rawdata" are both NULL: */
@@ -24936,10 +25010,12 @@
2493625010
u8 autoEQPtrace; /* autoEQP is in trace mode */
2493725011
u8 scanstatsOn; /* True to display scan stats before each finalize */
2493825012
u8 bAutoScreenWidth; /* Using the TTY to determine screen width */
2493925013
u8 mFlags; /* MFLG_ECHO, MFLG_CRLF, etc. */
2494025014
u8 eMode; /* One of the MODE_ values */
25015
+ char zIFmt[24]; /* Space to hold the --ifmt value */
25016
+ char zFpFmt[24]; /* Space to hold the --fpfmt value */
2494125017
sqlite3_qrf_spec spec; /* Spec to be passed into QRF */
2494225018
} Mode;
2494325019
2494425020
/* Flags for Mode.mFlags */
2494525021
#define MFLG_ECHO 0x01 /* Echo inputs to output */
@@ -26679,10 +26755,18 @@
2667926755
pDest->spec.zTableName = strdup(pSrc->spec.zTableName);
2668026756
}
2668126757
if( pDest->spec.zNull ){
2668226758
pDest->spec.zNull = strdup(pSrc->spec.zNull);
2668326759
}
26760
+ if( pDest->spec.zFpFmt ){
26761
+ assert( pDest->spec.zFpFmt==pSrc->zFpFmt );
26762
+ pDest->spec.zFpFmt = pDest->zFpFmt;
26763
+ }
26764
+ if( pDest->spec.zIFmt ){
26765
+ assert( pDest->spec.zIFmt==pSrc->zIFmt );
26766
+ pDest->spec.zIFmt = pDest->zIFmt;
26767
+ }
2668426768
}
2668526769
2668626770
/*
2668726771
** Set a string value to a copy of the zNew string in memory
2668826772
** obtained from system malloc().
@@ -29146,10 +29230,14 @@
2914629230
" truncated. Zero means \"no limit\".\n"
2914729231
" --colsep STRING Use STRING as the column separator\n"
2914829232
" --escape ESC Enable/disable escaping of control characters\n"
2914929233
" found in the output. ESC can be \"off\", \"ascii\",\n"
2915029234
" or \"symbol\".\n"
29235
+" --fpfmt STRING String is a printf-style format string used to\n"
29236
+" render floating-point values.\n"
29237
+" --ifmt STRING String is a printf-style format string used to\n"
29238
+" render integer values.\n"
2915129239
" --linelimit N Set the maximum number of output lines to show for\n"
2915229240
" any single SQL value to N. Longer values are\n"
2915329241
" truncated. Zero means \"no limit\". Only works\n"
2915429242
" in \"line\" mode and in columnar modes.\n"
2915529243
" --limits L,C,T Shorthand for \"--linelimit L --charlimit C\n"
@@ -33425,10 +33513,14 @@
3342533513
** truncated. Zero means "no limit".
3342633514
** --colsep STRING Use STRING as the column separator
3342733515
** --escape ESC Enable/disable escaping of control characters
3342833516
** found in the output. ESC can be "off", "ascii",
3342933517
** or "symbol".
33518
+** --fpfmt STRING String is a printf-style format string used to
33519
+** render floating-point values.
33520
+** --ifmt STRING String is a printf-style format string used to
33521
+** render integer values.
3343033522
** --linelimit N Set the maximum number of output lines to show for
3343133523
** any single SQL value to N. Longer values are
3343233524
** truncated. Zero means "no limit". Only works
3343333525
** in "line" mode and in columnar modes.
3343433526
** --limits L,C,T Shorthand for "--linelimit L --charlimit C
@@ -33680,10 +33772,44 @@
3368033772
break;
3368133773
default: /* off */
3368233774
p->mode.spec.eText = QRF_TEXT_Plain;
3368333775
break;
3368433776
}
33777
+ chng = 1;
33778
+ }else if( optionMatch(z,"ifmt") ){
33779
+ if( i+1>=nArg ){
33780
+ dotCmdError(p, i, "missing argument", 0);
33781
+ return 1;
33782
+ }
33783
+ i++;
33784
+ if( azArg[i][0]==0 || cli_strcmp(azArg[i],"auto")==0 ){
33785
+ p->mode.spec.zIFmt = 0;
33786
+ }else if( sqlite3_qrf_ckformat(azArg[i])!=1 ){
33787
+ dotCmdError(p, i, "not a valid integer format", 0);
33788
+ return 1;
33789
+ }else{
33790
+ assert( strlen(azArg[i])<sizeof(p->mode.zIFmt)-1 );
33791
+ memcpy(p->mode.zIFmt, azArg[i], strlen(azArg[i])+1);
33792
+ p->mode.spec.zIFmt = p->mode.zIFmt;
33793
+ }
33794
+ chng = 1;
33795
+ }else if( optionMatch(z,"fpfmt") ){
33796
+ if( i+1>=nArg ){
33797
+ dotCmdError(p, i, "missing argument", 0);
33798
+ return 1;
33799
+ }
33800
+ i++;
33801
+ if( azArg[i][0]==0 || cli_strcmp(azArg[i],"auto")==0 ){
33802
+ p->mode.spec.zFpFmt = 0;
33803
+ }else if( sqlite3_qrf_ckformat(azArg[i])!=2 ){
33804
+ dotCmdError(p, i, "not a valid floating-point format", 0);
33805
+ return 1;
33806
+ }else{
33807
+ assert( strlen(azArg[i])<sizeof(p->mode.zFpFmt)-1 );
33808
+ memcpy(p->mode.zFpFmt, azArg[i], strlen(azArg[i])+1);
33809
+ p->mode.spec.zFpFmt = p->mode.zFpFmt;
33810
+ }
3368533811
chng = 1;
3368633812
}else if( optionMatch(z,"reset") ){
3368733813
int saved_eMode = p->mode.eMode;
3368833814
modeFree(&p->mode);
3368933815
modeChange(p, saved_eMode);
@@ -33915,10 +34041,18 @@
3391534041
append_c_string(pDesc, p->mode.spec.zColumnSep);
3391634042
}
3391734043
if( bAll || p->mode.spec.eEsc!=QRF_Auto ){
3391834044
sqlite3_str_appendf(pDesc, " --escape %s",qrfEscNames[p->mode.spec.eEsc]);
3391934045
}
34046
+ if( bAll || p->mode.spec.zFpFmt!=0 ){
34047
+ const char *z = p->mode.spec.zFpFmt;
34048
+ sqlite3_str_appendf(pDesc, " --fpfmt %s", z ? z : "auto");
34049
+ }
34050
+ if( bAll || p->mode.spec.zIFmt!=0 ){
34051
+ const char *z = p->mode.spec.zIFmt;
34052
+ sqlite3_str_appendf(pDesc, " --ifmt %s", z ? z : "auto");
34053
+ }
3392034054
if( bAll
3392134055
|| (p->mode.spec.nLineLimit>0 && pI->eCx>0)
3392234056
|| p->mode.spec.nCharLimit>0
3392334057
|| (p->mode.spec.nTitleLimit>0 && pI->eCx>0)
3392434058
){
@@ -35596,10 +35730,11 @@
3559635730
{ "like_pattern_length", SQLITE_LIMIT_LIKE_PATTERN_LENGTH },
3559735731
{ "variable_number", SQLITE_LIMIT_VARIABLE_NUMBER },
3559835732
{ "trigger_depth", SQLITE_LIMIT_TRIGGER_DEPTH },
3559935733
{ "worker_threads", SQLITE_LIMIT_WORKER_THREADS },
3560035734
{ "schema", SQLITE_LIMIT_SCHEMA },
35735
+ { "trigger_steps", SQLITE_LIMIT_TRIGGER_STEPS },
3560135736
};
3560235737
int i, n2;
3560335738
open_db(p, 0);
3560435739
if( nArg==1 ){
3560535740
for(i=0; i<ArraySize(aLimit); i++){
3560635741
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -746,10 +746,12 @@
746 void *pRenderArg; /* First argument to the xRender callback */
747 void *pWriteArg; /* First argument to the xWrite callback */
748 char **pzOutput; /* Storage location for output string */
749 /* The following are available in iVersion 2 and later */
750 unsigned char bRowCount; /* Show the number of rows at end of each query */
 
 
751 /* Additional fields may be added in the future */
752 };
753
754 /*
755 ** Interfaces
@@ -887,10 +889,22 @@
887 ** determined as for sqlite3_qrf_wcwidth(). VT100 escape code sequences
888 ** are assigned a width of zero.
889 */
890 size_t sqlite3_qrf_wcswidth(const char*);
891
 
 
 
 
 
 
 
 
 
 
 
 
892
893 #ifdef __cplusplus
894 }
895 #endif
896 #endif /* !defined(SQLITE_QRF_H) */
@@ -969,10 +983,11 @@
969 } sExpln;
970 unsigned int nIns; /* Bytes used for current INSERT stmt */
971 } u;
972 sqlite3_int64 nRow; /* Number of rows handled so far */
973 int *actualWidth; /* Actual width of each column */
 
974 sqlite3_qrf_spec spec; /* Copy of the original spec */
975 };
976
977 /*
978 ** Data for substitute ctype.h functions. Used for x-platform
@@ -1012,10 +1027,48 @@
1012 # define deliberate_fall_through __attribute__((fallthrough));
1013 # else
1014 # define deliberate_fall_through
1015 # endif
1016 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1017
1018 /*
1019 ** Set an error code and error message.
1020 */
1021 static void qrfError(
@@ -2000,16 +2053,22 @@
2000 return;
2001 }
2002 }
2003 switch( sqlite3_column_type(p->pStmt,iCol) ){
2004 case SQLITE_INTEGER: {
2005 sqlite3_str_appendf(pOut, "%lld", sqlite3_column_int64(p->pStmt,iCol));
 
2006 break;
2007 }
2008 case SQLITE_FLOAT: {
2009 const char *zTxt = (const char*)sqlite3_column_text(p->pStmt,iCol);
2010 sqlite3_str_appendall(pOut, zTxt);
 
 
 
 
 
2011 break;
2012 }
2013 case SQLITE_BLOB: {
2014 if( p->spec.bTextJsonb==QRF_Yes ){
2015 const char *zJson = qrfJsonbToJson(p, iCol);
@@ -3728,11 +3787,15 @@
3728 return;
3729 }
3730 p->iErr = SQLITE_OK;
3731 p->nCol = sqlite3_column_count(p->pStmt);
3732 p->nRow = 0;
3733 sz = sizeof(sqlite3_qrf_spec);
 
 
 
 
3734 memcpy(&p->spec, pSpec, sz);
3735 if( p->spec.zNull==0 ) p->spec.zNull = "";
3736 p->mxWidth = p->spec.nScreenWidth;
3737 if( p->mxWidth<=0 ) p->mxWidth = 2147483647;
3738 p->mxHeight = p->spec.nLineLimit;
@@ -3740,13 +3803,10 @@
3740 if( p->spec.eStyle>QRF_STYLE_Table ) p->spec.eStyle = QRF_Auto;
3741 if( p->spec.eEsc>QRF_ESC_Symbol ) p->spec.eEsc = QRF_Auto;
3742 if( p->spec.eText>QRF_TEXT_Relaxed ) p->spec.eText = QRF_Auto;
3743 if( p->spec.eTitle>QRF_TEXT_Relaxed ) p->spec.eTitle = QRF_Auto;
3744 if( p->spec.eBlob>QRF_BLOB_Size ) p->spec.eBlob = QRF_Auto;
3745 if( pSpec->iVersion<=1 ){
3746 p->spec.bRowCount = 0;
3747 }
3748 qrf_reinit:
3749 switch( p->spec.eStyle ){
3750 case QRF_Auto: {
3751 switch( sqlite3_stmt_isexplain(pStmt) ){
3752 case 0: p->spec.eStyle = QRF_STYLE_Box; break;
@@ -3867,10 +3927,24 @@
3867 if( p->spec.bTextJsonb==QRF_Auto ){
3868 p->spec.bTextJsonb = QRF_No;
3869 }
3870 if( p->spec.zColumnSep==0 ) p->spec.zColumnSep = ",";
3871 if( p->spec.zRowSep==0 ) p->spec.zRowSep = "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3872 }
3873
3874 /*
3875 ** Finish rendering the results
3876 */
@@ -14064,14 +14138,14 @@
14064 if( zUpdate && zipfileComparePath(zUpdate, zDelete, nDelete)!=0 ){
14065 bUpdate = 1;
14066 }
14067 }
14068 for(pOld=pTab->pFirstEntry; 1; pOld=pOld->pNext){
 
14069 if( zipfileComparePath(pOld->cds.zFile, zDelete, nDelete)==0 ){
14070 break;
14071 }
14072 assert( pOld->pNext );
14073 }
14074 }
14075
14076 if( nVal>1 ){
14077 /* Check that "sz" and "rawdata" are both NULL: */
@@ -24936,10 +25010,12 @@
24936 u8 autoEQPtrace; /* autoEQP is in trace mode */
24937 u8 scanstatsOn; /* True to display scan stats before each finalize */
24938 u8 bAutoScreenWidth; /* Using the TTY to determine screen width */
24939 u8 mFlags; /* MFLG_ECHO, MFLG_CRLF, etc. */
24940 u8 eMode; /* One of the MODE_ values */
 
 
24941 sqlite3_qrf_spec spec; /* Spec to be passed into QRF */
24942 } Mode;
24943
24944 /* Flags for Mode.mFlags */
24945 #define MFLG_ECHO 0x01 /* Echo inputs to output */
@@ -26679,10 +26755,18 @@
26679 pDest->spec.zTableName = strdup(pSrc->spec.zTableName);
26680 }
26681 if( pDest->spec.zNull ){
26682 pDest->spec.zNull = strdup(pSrc->spec.zNull);
26683 }
 
 
 
 
 
 
 
 
26684 }
26685
26686 /*
26687 ** Set a string value to a copy of the zNew string in memory
26688 ** obtained from system malloc().
@@ -29146,10 +29230,14 @@
29146 " truncated. Zero means \"no limit\".\n"
29147 " --colsep STRING Use STRING as the column separator\n"
29148 " --escape ESC Enable/disable escaping of control characters\n"
29149 " found in the output. ESC can be \"off\", \"ascii\",\n"
29150 " or \"symbol\".\n"
 
 
 
 
29151 " --linelimit N Set the maximum number of output lines to show for\n"
29152 " any single SQL value to N. Longer values are\n"
29153 " truncated. Zero means \"no limit\". Only works\n"
29154 " in \"line\" mode and in columnar modes.\n"
29155 " --limits L,C,T Shorthand for \"--linelimit L --charlimit C\n"
@@ -33425,10 +33513,14 @@
33425 ** truncated. Zero means "no limit".
33426 ** --colsep STRING Use STRING as the column separator
33427 ** --escape ESC Enable/disable escaping of control characters
33428 ** found in the output. ESC can be "off", "ascii",
33429 ** or "symbol".
 
 
 
 
33430 ** --linelimit N Set the maximum number of output lines to show for
33431 ** any single SQL value to N. Longer values are
33432 ** truncated. Zero means "no limit". Only works
33433 ** in "line" mode and in columnar modes.
33434 ** --limits L,C,T Shorthand for "--linelimit L --charlimit C
@@ -33680,10 +33772,44 @@
33680 break;
33681 default: /* off */
33682 p->mode.spec.eText = QRF_TEXT_Plain;
33683 break;
33684 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33685 chng = 1;
33686 }else if( optionMatch(z,"reset") ){
33687 int saved_eMode = p->mode.eMode;
33688 modeFree(&p->mode);
33689 modeChange(p, saved_eMode);
@@ -33915,10 +34041,18 @@
33915 append_c_string(pDesc, p->mode.spec.zColumnSep);
33916 }
33917 if( bAll || p->mode.spec.eEsc!=QRF_Auto ){
33918 sqlite3_str_appendf(pDesc, " --escape %s",qrfEscNames[p->mode.spec.eEsc]);
33919 }
 
 
 
 
 
 
 
 
33920 if( bAll
33921 || (p->mode.spec.nLineLimit>0 && pI->eCx>0)
33922 || p->mode.spec.nCharLimit>0
33923 || (p->mode.spec.nTitleLimit>0 && pI->eCx>0)
33924 ){
@@ -35596,10 +35730,11 @@
35596 { "like_pattern_length", SQLITE_LIMIT_LIKE_PATTERN_LENGTH },
35597 { "variable_number", SQLITE_LIMIT_VARIABLE_NUMBER },
35598 { "trigger_depth", SQLITE_LIMIT_TRIGGER_DEPTH },
35599 { "worker_threads", SQLITE_LIMIT_WORKER_THREADS },
35600 { "schema", SQLITE_LIMIT_SCHEMA },
 
35601 };
35602 int i, n2;
35603 open_db(p, 0);
35604 if( nArg==1 ){
35605 for(i=0; i<ArraySize(aLimit); i++){
35606
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -746,10 +746,12 @@
746 void *pRenderArg; /* First argument to the xRender callback */
747 void *pWriteArg; /* First argument to the xWrite callback */
748 char **pzOutput; /* Storage location for output string */
749 /* The following are available in iVersion 2 and later */
750 unsigned char bRowCount; /* Show the number of rows at end of each query */
751 char *zIFmt; /* Format string for integers */
752 char *zFpFmt; /* Format string for floating point */
753 /* Additional fields may be added in the future */
754 };
755
756 /*
757 ** Interfaces
@@ -887,10 +889,22 @@
889 ** determined as for sqlite3_qrf_wcwidth(). VT100 escape code sequences
890 ** are assigned a width of zero.
891 */
892 size_t sqlite3_qrf_wcswidth(const char*);
893
894 /*
895 ** The argument is a proposed format string for the zIFmt or zFpFmt
896 ** parameters. Return value indicates:
897 **
898 ** 0 The input is not a valid format string. If this string
899 ** appears in either zIFmt or zFpFmt, it will be ignored.
900 **
901 ** 1 The input is a valid format string for integers.
902 **
903 ** 2 The input is a valid format string for floating point.
904 */
905 int sqlite3_qrf_ckformat(const char*);
906
907 #ifdef __cplusplus
908 }
909 #endif
910 #endif /* !defined(SQLITE_QRF_H) */
@@ -969,10 +983,11 @@
983 } sExpln;
984 unsigned int nIns; /* Bytes used for current INSERT stmt */
985 } u;
986 sqlite3_int64 nRow; /* Number of rows handled so far */
987 int *actualWidth; /* Actual width of each column */
988 char zFmt[24]; /* Space to hold the true integer rendering fmt */
989 sqlite3_qrf_spec spec; /* Copy of the original spec */
990 };
991
992 /*
993 ** Data for substitute ctype.h functions. Used for x-platform
@@ -1012,10 +1027,48 @@
1027 # define deliberate_fall_through __attribute__((fallthrough));
1028 # else
1029 # define deliberate_fall_through
1030 # endif
1031 #endif
1032
1033 /*
1034 ** The argument is a proposed format string for the zIFmt or zFpFmt
1035 ** parameters. Return value indicates:
1036 **
1037 ** 0 The input is not a valid format string. If this string
1038 ** appears in either zIFmt or zFpFmt, it will be ignored.
1039 **
1040 ** 1 The input is a valid format string for integers.
1041 **
1042 ** 2 The input is a valid format string for floating point.
1043 */
1044 int sqlite3_qrf_ckformat(const char *z){
1045 size_t n;
1046 if( z==0 ) return 0;
1047 if( z[0]!='%' ) return 0;
1048 z++;
1049 n = strspn(z,"+-,#0");
1050 if( n>5 ) return 0;
1051 z += n;
1052 if( z[0]>='1' && z[0]<='9' ){
1053 n = strspn(z,"0123456789");
1054 if( n>3 ) return 0;
1055 z += n;
1056 }
1057 if( z[0]=='.' ){
1058 z++;
1059 n = strspn(z,"0123456789");
1060 if( n>3 ) return 0;
1061 z += n;
1062 }
1063 n = strspn(z,"eEgGf");
1064 if( n==1 && z[1]==0 ) return 2;
1065 n = strspn(z,"dxXo");
1066 if( n==1 && z[1]==0 ) return 1;
1067 return 0;
1068 }
1069
1070
1071 /*
1072 ** Set an error code and error message.
1073 */
1074 static void qrfError(
@@ -2000,16 +2053,22 @@
2053 return;
2054 }
2055 }
2056 switch( sqlite3_column_type(p->pStmt,iCol) ){
2057 case SQLITE_INTEGER: {
2058 sqlite3_str_appendf(pOut, p->spec.zIFmt,
2059 sqlite3_column_int64(p->pStmt,iCol));
2060 break;
2061 }
2062 case SQLITE_FLOAT: {
2063 if( p->spec.zFpFmt ){
2064 double r = sqlite3_column_double(p->pStmt,iCol);
2065 sqlite3_str_appendf(pOut,p->spec.zFpFmt,r);
2066 }else{
2067 const char *zTxt = (const char*)sqlite3_column_text(p->pStmt,iCol);
2068 sqlite3_str_appendall(pOut, zTxt);
2069 }
2070 break;
2071 }
2072 case SQLITE_BLOB: {
2073 if( p->spec.bTextJsonb==QRF_Yes ){
2074 const char *zJson = qrfJsonbToJson(p, iCol);
@@ -3728,11 +3787,15 @@
3787 return;
3788 }
3789 p->iErr = SQLITE_OK;
3790 p->nCol = sqlite3_column_count(p->pStmt);
3791 p->nRow = 0;
3792 switch( pSpec->iVersion ){
3793 case 0: sz = offsetof(sqlite3_qrf_spec, bRowCount); break;
3794 case 1: sz = offsetof(sqlite3_qrf_spec, bRowCount); break;
3795 default: sz = sizeof(sqlite3_qrf_spec); break;
3796 }
3797 memcpy(&p->spec, pSpec, sz);
3798 if( p->spec.zNull==0 ) p->spec.zNull = "";
3799 p->mxWidth = p->spec.nScreenWidth;
3800 if( p->mxWidth<=0 ) p->mxWidth = 2147483647;
3801 p->mxHeight = p->spec.nLineLimit;
@@ -3740,13 +3803,10 @@
3803 if( p->spec.eStyle>QRF_STYLE_Table ) p->spec.eStyle = QRF_Auto;
3804 if( p->spec.eEsc>QRF_ESC_Symbol ) p->spec.eEsc = QRF_Auto;
3805 if( p->spec.eText>QRF_TEXT_Relaxed ) p->spec.eText = QRF_Auto;
3806 if( p->spec.eTitle>QRF_TEXT_Relaxed ) p->spec.eTitle = QRF_Auto;
3807 if( p->spec.eBlob>QRF_BLOB_Size ) p->spec.eBlob = QRF_Auto;
 
 
 
3808 qrf_reinit:
3809 switch( p->spec.eStyle ){
3810 case QRF_Auto: {
3811 switch( sqlite3_stmt_isexplain(pStmt) ){
3812 case 0: p->spec.eStyle = QRF_STYLE_Box; break;
@@ -3867,10 +3927,24 @@
3927 if( p->spec.bTextJsonb==QRF_Auto ){
3928 p->spec.bTextJsonb = QRF_No;
3929 }
3930 if( p->spec.zColumnSep==0 ) p->spec.zColumnSep = ",";
3931 if( p->spec.zRowSep==0 ) p->spec.zRowSep = "\n";
3932 if( p->spec.zIFmt==0 || sqlite3_qrf_ckformat(p->spec.zIFmt)!=1 ){
3933 p->spec.zIFmt = "%lld";
3934 }else{
3935 size_t n = strlen(p->spec.zIFmt);
3936 memcpy(p->zFmt, p->spec.zIFmt, n-1);
3937 p->zFmt[n-1] = 'l';
3938 p->zFmt[n] = 'l';
3939 p->zFmt[n+1] = p->spec.zIFmt[n-1];
3940 p->zFmt[n+2] = 0;
3941 p->spec.zIFmt = p->zFmt;
3942 }
3943 if( p->spec.zFpFmt && sqlite3_qrf_ckformat(p->spec.zFpFmt)!=2 ){
3944 p->spec.zFpFmt = 0;
3945 }
3946 }
3947
3948 /*
3949 ** Finish rendering the results
3950 */
@@ -14064,14 +14138,14 @@
14138 if( zUpdate && zipfileComparePath(zUpdate, zDelete, nDelete)!=0 ){
14139 bUpdate = 1;
14140 }
14141 }
14142 for(pOld=pTab->pFirstEntry; 1; pOld=pOld->pNext){
14143 if( pOld==0 ) return SQLITE_OK;
14144 if( zipfileComparePath(pOld->cds.zFile, zDelete, nDelete)==0 ){
14145 break;
14146 }
 
14147 }
14148 }
14149
14150 if( nVal>1 ){
14151 /* Check that "sz" and "rawdata" are both NULL: */
@@ -24936,10 +25010,12 @@
25010 u8 autoEQPtrace; /* autoEQP is in trace mode */
25011 u8 scanstatsOn; /* True to display scan stats before each finalize */
25012 u8 bAutoScreenWidth; /* Using the TTY to determine screen width */
25013 u8 mFlags; /* MFLG_ECHO, MFLG_CRLF, etc. */
25014 u8 eMode; /* One of the MODE_ values */
25015 char zIFmt[24]; /* Space to hold the --ifmt value */
25016 char zFpFmt[24]; /* Space to hold the --fpfmt value */
25017 sqlite3_qrf_spec spec; /* Spec to be passed into QRF */
25018 } Mode;
25019
25020 /* Flags for Mode.mFlags */
25021 #define MFLG_ECHO 0x01 /* Echo inputs to output */
@@ -26679,10 +26755,18 @@
26755 pDest->spec.zTableName = strdup(pSrc->spec.zTableName);
26756 }
26757 if( pDest->spec.zNull ){
26758 pDest->spec.zNull = strdup(pSrc->spec.zNull);
26759 }
26760 if( pDest->spec.zFpFmt ){
26761 assert( pDest->spec.zFpFmt==pSrc->zFpFmt );
26762 pDest->spec.zFpFmt = pDest->zFpFmt;
26763 }
26764 if( pDest->spec.zIFmt ){
26765 assert( pDest->spec.zIFmt==pSrc->zIFmt );
26766 pDest->spec.zIFmt = pDest->zIFmt;
26767 }
26768 }
26769
26770 /*
26771 ** Set a string value to a copy of the zNew string in memory
26772 ** obtained from system malloc().
@@ -29146,10 +29230,14 @@
29230 " truncated. Zero means \"no limit\".\n"
29231 " --colsep STRING Use STRING as the column separator\n"
29232 " --escape ESC Enable/disable escaping of control characters\n"
29233 " found in the output. ESC can be \"off\", \"ascii\",\n"
29234 " or \"symbol\".\n"
29235 " --fpfmt STRING String is a printf-style format string used to\n"
29236 " render floating-point values.\n"
29237 " --ifmt STRING String is a printf-style format string used to\n"
29238 " render integer values.\n"
29239 " --linelimit N Set the maximum number of output lines to show for\n"
29240 " any single SQL value to N. Longer values are\n"
29241 " truncated. Zero means \"no limit\". Only works\n"
29242 " in \"line\" mode and in columnar modes.\n"
29243 " --limits L,C,T Shorthand for \"--linelimit L --charlimit C\n"
@@ -33425,10 +33513,14 @@
33513 ** truncated. Zero means "no limit".
33514 ** --colsep STRING Use STRING as the column separator
33515 ** --escape ESC Enable/disable escaping of control characters
33516 ** found in the output. ESC can be "off", "ascii",
33517 ** or "symbol".
33518 ** --fpfmt STRING String is a printf-style format string used to
33519 ** render floating-point values.
33520 ** --ifmt STRING String is a printf-style format string used to
33521 ** render integer values.
33522 ** --linelimit N Set the maximum number of output lines to show for
33523 ** any single SQL value to N. Longer values are
33524 ** truncated. Zero means "no limit". Only works
33525 ** in "line" mode and in columnar modes.
33526 ** --limits L,C,T Shorthand for "--linelimit L --charlimit C
@@ -33680,10 +33772,44 @@
33772 break;
33773 default: /* off */
33774 p->mode.spec.eText = QRF_TEXT_Plain;
33775 break;
33776 }
33777 chng = 1;
33778 }else if( optionMatch(z,"ifmt") ){
33779 if( i+1>=nArg ){
33780 dotCmdError(p, i, "missing argument", 0);
33781 return 1;
33782 }
33783 i++;
33784 if( azArg[i][0]==0 || cli_strcmp(azArg[i],"auto")==0 ){
33785 p->mode.spec.zIFmt = 0;
33786 }else if( sqlite3_qrf_ckformat(azArg[i])!=1 ){
33787 dotCmdError(p, i, "not a valid integer format", 0);
33788 return 1;
33789 }else{
33790 assert( strlen(azArg[i])<sizeof(p->mode.zIFmt)-1 );
33791 memcpy(p->mode.zIFmt, azArg[i], strlen(azArg[i])+1);
33792 p->mode.spec.zIFmt = p->mode.zIFmt;
33793 }
33794 chng = 1;
33795 }else if( optionMatch(z,"fpfmt") ){
33796 if( i+1>=nArg ){
33797 dotCmdError(p, i, "missing argument", 0);
33798 return 1;
33799 }
33800 i++;
33801 if( azArg[i][0]==0 || cli_strcmp(azArg[i],"auto")==0 ){
33802 p->mode.spec.zFpFmt = 0;
33803 }else if( sqlite3_qrf_ckformat(azArg[i])!=2 ){
33804 dotCmdError(p, i, "not a valid floating-point format", 0);
33805 return 1;
33806 }else{
33807 assert( strlen(azArg[i])<sizeof(p->mode.zFpFmt)-1 );
33808 memcpy(p->mode.zFpFmt, azArg[i], strlen(azArg[i])+1);
33809 p->mode.spec.zFpFmt = p->mode.zFpFmt;
33810 }
33811 chng = 1;
33812 }else if( optionMatch(z,"reset") ){
33813 int saved_eMode = p->mode.eMode;
33814 modeFree(&p->mode);
33815 modeChange(p, saved_eMode);
@@ -33915,10 +34041,18 @@
34041 append_c_string(pDesc, p->mode.spec.zColumnSep);
34042 }
34043 if( bAll || p->mode.spec.eEsc!=QRF_Auto ){
34044 sqlite3_str_appendf(pDesc, " --escape %s",qrfEscNames[p->mode.spec.eEsc]);
34045 }
34046 if( bAll || p->mode.spec.zFpFmt!=0 ){
34047 const char *z = p->mode.spec.zFpFmt;
34048 sqlite3_str_appendf(pDesc, " --fpfmt %s", z ? z : "auto");
34049 }
34050 if( bAll || p->mode.spec.zIFmt!=0 ){
34051 const char *z = p->mode.spec.zIFmt;
34052 sqlite3_str_appendf(pDesc, " --ifmt %s", z ? z : "auto");
34053 }
34054 if( bAll
34055 || (p->mode.spec.nLineLimit>0 && pI->eCx>0)
34056 || p->mode.spec.nCharLimit>0
34057 || (p->mode.spec.nTitleLimit>0 && pI->eCx>0)
34058 ){
@@ -35596,10 +35730,11 @@
35730 { "like_pattern_length", SQLITE_LIMIT_LIKE_PATTERN_LENGTH },
35731 { "variable_number", SQLITE_LIMIT_VARIABLE_NUMBER },
35732 { "trigger_depth", SQLITE_LIMIT_TRIGGER_DEPTH },
35733 { "worker_threads", SQLITE_LIMIT_WORKER_THREADS },
35734 { "schema", SQLITE_LIMIT_SCHEMA },
35735 { "trigger_steps", SQLITE_LIMIT_TRIGGER_STEPS },
35736 };
35737 int i, n2;
35738 open_db(p, 0);
35739 if( nArg==1 ){
35740 for(i=0; i<ArraySize(aLimit); i++){
35741
+637 -351
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -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
-** fee71cd6f7294ffd02784d26811a9d11d80e with changes in files:
21
+** 3bd5456e50ef321f2cafcf67261d556a7606 with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470470
#define SQLITE_VERSION "3.54.0"
471471
#define SQLITE_VERSION_NUMBER 3054000
472
-#define SQLITE_SOURCE_ID "2026-08-11 10:46:12 fee71cd6f7294ffd02784d26811a9d11d80e83d4075e1233b8ec0289519bb891"
472
+#define SQLITE_SOURCE_ID "2026-08-20 13:25:12 3bd5456e50ef321f2cafcf67261d556a760624ce0caab430ed9454cebec233e7"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2026-08-11T10:46:12.896Z"
475
+#define SQLITE_SCM_DATETIME "2026-08-20T13:25:12.207Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -4755,10 +4755,14 @@
47554755
** [prepared statement] may start.</dd>)^
47564756
**
47574757
** [[SQLITE_LIMIT_SCHEMA]] ^(<dt>SQLITE_LIMIT_SCHEMA</dt>
47584758
** <dd>The maximum number of objects (tables, indexes, triggers, and views)
47594759
** defined by the database schema.</dd>)^
4760
+**
4761
+** [[SQLITE_LIMIT_TRIGGER_STEPS]] ^(<dt>SQLITE_LIMIT_TRIGGER_STEPS</dt>
4762
+** <dd>The maximum number of SQL statements that can be contained within
4763
+** a single trigger.</dd>)^
47604764
** </dl>
47614765
*/
47624766
#define SQLITE_LIMIT_LENGTH 0
47634767
#define SQLITE_LIMIT_SQL_LENGTH 1
47644768
#define SQLITE_LIMIT_COLUMN 2
@@ -4771,10 +4775,11 @@
47714775
#define SQLITE_LIMIT_VARIABLE_NUMBER 9
47724776
#define SQLITE_LIMIT_TRIGGER_DEPTH 10
47734777
#define SQLITE_LIMIT_WORKER_THREADS 11
47744778
#define SQLITE_LIMIT_PARSER_DEPTH 12
47754779
#define SQLITE_LIMIT_SCHEMA 13
4780
+#define SQLITE_LIMIT_TRIGGER_STEPS 14
47764781
47774782
/*
47784783
** CAPI3REF: Prepare Flags
47794784
**
47804785
** These constants define various flags that can be passed into the
@@ -15067,10 +15072,18 @@
1506715072
*/
1506815073
#ifndef SQLITE_MAX_SCHEMA
1506915074
# define SQLITE_MAX_SCHEMA 10000000
1507015075
#endif
1507115076
15077
+/*
15078
+** Maximum number of SQL statements allowed in the body of a single
15079
+** trigger.
15080
+*/
15081
+#ifndef SQLITE_MAX_TRIGGER_STEPS
15082
+# define SQLITE_MAX_TRIGGER_STEPS 65000
15083
+#endif
15084
+
1507215085
/************** End of sqliteLimit.h *****************************************/
1507315086
/************** Continuing where we left off in sqliteInt.h ******************/
1507415087
1507515088
/* Disable nuisance warnings on Borland compilers */
1507615089
#if defined(__BORLANDC__)
@@ -15143,29 +15156,42 @@
1514315156
**
1514415157
** SQLITE_INLINE Strive to in-line this function
1514515158
**
1514615159
** SQLITE_OPT_INLINE In-line this function if building the
1514715160
** amalgamation.
15161
+**
15162
+** SQLITE_USES_INLINE Set to 1 or 0 according to whether or not
15163
+** inline functions are supported.
1514815164
*/
15149
-#if defined(__GNUC__)
15165
+#if defined(SQLITE_DISABLE_INLINE)
15166
+# define SQLITE_NOINLINE
15167
+# define SQLITE_INLINE
15168
+# define SQLITE_OPT_INLINE
15169
+# define SQLITE_USES_INLINE 0
15170
+#elif defined(__GNUC__)
1515015171
# define SQLITE_NOINLINE __attribute__((noinline))
1515115172
# define SQLITE_INLINE __attribute__((always_inline)) inline
1515215173
# define SQLITE_OPT_INLINE __attribute__((always_inline)) inline
15174
+# define SQLITE_USES_INLINE 1
1515315175
#elif defined(_MSC_VER) && _MSC_VER>=1310
1515415176
# define SQLITE_NOINLINE __declspec(noinline)
1515515177
# define SQLITE_INLINE __forceinline
1515615178
# define SQLITE_OPT_INLINE __forceinline
15179
+# define SQLITE_USES_INLINE 1
1515715180
#else
1515815181
# define SQLITE_NOINLINE
1515915182
# define SQLITE_INLINE
1516015183
# define SQLITE_OPT_INLINE
15184
+# define SQLITE_USES_INLINE 0
1516115185
#endif
1516215186
#if defined(SQLITE_COVERAGE_TEST) || defined(__STRICT_ANSI__)
1516315187
# undef SQLITE_INLINE
1516415188
# define SQLITE_INLINE
1516515189
# undef SQLITE_OPT_INLINE
1516615190
# define SQLITE_OPT_INLINE
15191
+# undef SQLITE_USES_INLINE
15192
+# define SQLITE_USES_INLINE 0
1516715193
#endif
1516815194
#if !defined(SQLITE_AMALGAMATION)
1516915195
# undef SQLITE_OPT_INLINE
1517015196
# define SQLITE_OPT_INLINE
1517115197
#endif
@@ -17694,12 +17720,10 @@
1769417720
int p3; /* The third parameter */
1769517721
union p4union { /* fourth parameter */
1769617722
int i; /* Integer value if p4type==P4_INT32 */
1769717723
void *p; /* Generic pointer */
1769817724
char *z; /* Pointer to data for string (char array) types */
17699
- i64 *pI64; /* Used when p4type is P4_INT64 */
17700
- double *pReal; /* Used when p4type is P4_REAL */
1770117725
FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */
1770217726
sqlite3_context *pCtx; /* Used when p4type is P4_FUNCCTX */
1770317727
CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
1770417728
Mem *pMem; /* Used when p4type is P4_MEM */
1770517729
VTable *pVtab; /* Used when p4type is P4_VTAB */
@@ -17750,10 +17774,23 @@
1775017774
signed char p1; /* First operand */
1775117775
signed char p2; /* Second parameter (often the jump destination) */
1775217776
signed char p3; /* Third parameter */
1775317777
};
1775417778
typedef struct VdbeOpList VdbeOpList;
17779
+
17780
+/*
17781
+** Combine two int32 values into a single int64. The least significant
17782
+** term comes first.
17783
+*/
17784
+#define INT32_TO_64(a,b) (i64)(((u64)(u32)(b)<<32)|(u32)(a))
17785
+
17786
+/*
17787
+** Return an int32 that is the lower or upper 32-bits of an int64.
17788
+*/
17789
+#define LOWER32(x) (int)(((u64)(x))&0xffffffff)
17790
+#define UPPER32(x) (int)(((u64)(x))>>32)
17791
+
1775517792
1775617793
/*
1775717794
** Allowed values of VdbeOp.p4type
1775817795
*/
1775917796
#define P4_NOTUSED 0 /* The P4 parameter is not used */
@@ -17770,16 +17807,14 @@
1777017807
#define P4_FUNCDEF (-8) /* P4 is a pointer to a FuncDef structure */
1777117808
#define P4_KEYINFO (-9) /* P4 is a pointer to a KeyInfo structure */
1777217809
#define P4_EXPR (-10) /* P4 is a pointer to an Expr tree */
1777317810
#define P4_MEM (-11) /* P4 is a pointer to a Mem* structure */
1777417811
#define P4_VTAB (-12) /* P4 is a pointer to an sqlite3_vtab structure */
17775
-#define P4_REAL (-13) /* P4 is a 64-bit floating point value */
17776
-#define P4_INT64 (-14) /* P4 is a 64-bit signed integer */
17777
-#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
17778
-#define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */
17779
-#define P4_TABLEREF (-17) /* Like P4_TABLE, but reference counted */
17780
-#define P4_SUBRTNSIG (-18) /* P4 is a SubrtnSig pointer */
17812
+#define P4_INTARRAY (-13) /* P4 is a vector of 32-bit integers */
17813
+#define P4_FUNCCTX (-14) /* P4 is a pointer to an sqlite3_context object */
17814
+#define P4_TABLEREF (-15) /* Like P4_TABLE, but reference counted */
17815
+#define P4_SUBRTNSIG (-16) /* P4 is a SubrtnSig pointer */
1778117816
1778217817
/* Error message codes for OP_Halt */
1778317818
#define P5_ConstraintNotNull 1
1778417819
#define P5_ConstraintUnique 2
1778517820
#define P5_ConstraintCheck 3
@@ -17891,11 +17926,11 @@
1789117926
#define OP_Return 69
1789217927
#define OP_EndCoroutine 70
1789317928
#define OP_HaltIfNull 71 /* synopsis: if r[P3]=null halt */
1789417929
#define OP_Halt 72
1789517930
#define OP_Integer 73 /* synopsis: r[P2]=P1 */
17896
-#define OP_Int64 74 /* synopsis: r[P2]=P4 */
17931
+#define OP_Int64 74 /* synopsis: r[P2]=PINT13 */
1789717932
#define OP_String 75 /* synopsis: r[P2]='P4' (len=P1) */
1789817933
#define OP_BeginSubrtn 76 /* synopsis: r[P2]=NULL */
1789917934
#define OP_Null 77 /* synopsis: r[P2..P3]=NULL */
1790017935
#define OP_SoftNull 78 /* synopsis: r[P1]=NULL */
1790117936
#define OP_Blob 79 /* synopsis: r[P2]=P4 (len=P1) */
@@ -17942,11 +17977,11 @@
1794217977
#define OP_OpenEphemeral 120 /* synopsis: nColumn=P2 */
1794317978
#define OP_SorterOpen 121
1794417979
#define OP_SequenceTest 122 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
1794517980
#define OP_OpenPseudo 123 /* synopsis: P3 columns in r[P2] */
1794617981
#define OP_Close 124
17947
-#define OP_ColumnsUsed 125
17982
+#define OP_ColumnsUsed 125 /* synopsis: Cursor P1 uses columns PHEX23 */
1794817983
#define OP_SeekScan 126 /* synopsis: Scan-ahead up to P1 rows */
1794917984
#define OP_SeekHit 127 /* synopsis: set P2<=seekHit<=P3 */
1795017985
#define OP_Sequence 128 /* synopsis: r[P2]=cursor[P1].ctr++ */
1795117986
#define OP_NewRowid 129 /* synopsis: r[P2]=rowid */
1795217987
#define OP_Insert 130 /* synopsis: intkey=r[P3] data=r[P2] */
@@ -17971,11 +18006,11 @@
1797118006
#define OP_CreateBtree 149 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
1797218007
#define OP_SqlExec 150
1797318008
#define OP_ParseSchema 151
1797418009
#define OP_LoadAnalysis 152
1797518010
#define OP_DropTable 153
17976
-#define OP_Real 154 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
18011
+#define OP_Real 154 /* same as TK_FLOAT, synopsis: r[P2]=PDBL13 */
1797718012
#define OP_DropIndex 155
1797818013
#define OP_DropTrigger 156
1797918014
#define OP_IntegrityCk 157
1798018015
#define OP_RowSetAdd 158 /* synopsis: rowset(P1)=r[P2] */
1798118016
#define OP_Param 159
@@ -18079,12 +18114,13 @@
1807918114
SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
1808018115
SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe*,int);
1808118116
SQLITE_PRIVATE int sqlite3VdbeLoadString(Vdbe*,int,const char*);
1808218117
SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...);
1808318118
SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
18119
+SQLITE_PRIVATE int sqlite3VdbeAddInt64(Vdbe*,int,i64);
18120
+SQLITE_PRIVATE int sqlite3VdbeAddDouble(Vdbe*,int,double);
1808418121
SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
18085
-SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int);
1808618122
SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
1808718123
SQLITE_PRIVATE int sqlite3VdbeAddFunctionCall(Parse*,int,int,int,int,const FuncDef*,int);
1808818124
SQLITE_PRIVATE void sqlite3VdbeEndCoroutine(Vdbe*,int);
1808918125
#if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS)
1809018126
SQLITE_PRIVATE void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N);
@@ -18331,10 +18367,11 @@
1833118367
** This header file defines the interface that the sqlite page cache
1833218368
** subsystem.
1833318369
*/
1833418370
1833518371
#ifndef _PCACHE_H_
18372
+#define _PCACHE_H_
1833618373
1833718374
typedef struct PgHdr PgHdr;
1833818375
typedef struct PCache PCache;
1833918376
1834018377
/*
@@ -18689,11 +18726,11 @@
1868918726
1869018727
/*
1869118728
** The number of different kinds of things that can be limited
1869218729
** using the sqlite3_limit() interface.
1869318730
*/
18694
-#define SQLITE_N_LIMIT (SQLITE_LIMIT_SCHEMA+1)
18731
+#define SQLITE_N_LIMIT (SQLITE_LIMIT_TRIGGER_STEPS+1)
1869518732
1869618733
/*
1869718734
** Lookaside malloc is a set of fixed-size buffers that can be used
1869818735
** to satisfy small transient memory allocation requests for objects
1869918736
** associated with a particular database connection. The use of
@@ -21008,10 +21045,17 @@
2100821045
ParseCleanup *pNext; /* Next cleanup task */
2100921046
void *pPtr; /* Pointer to object to deallocate */
2101021047
void (*xCleanup)(sqlite3*,void*); /* Deallocation routine */
2101121048
};
2101221049
21050
+/*
21051
+** Number of 64-bit entried in the variable number bitmap cache (VNBMC).
21052
+*/
21053
+#ifndef SQLITE_VNBMC
21054
+# define SQLITE_VNBMC 2
21055
+#endif
21056
+
2101321057
/*
2101421058
** An SQL parser context. A copy of this structure is passed through
2101521059
** the parser and down into all the parser action routine in order to
2101621060
** carry around information that is global to the entire parse.
2101721061
**
@@ -21126,10 +21170,11 @@
2112621170
** first field in the recursive region.
2112721171
************************************************************************/
2112821172
2112921173
Token sLastToken; /* The last token parsed */
2113021174
ynVar nVar; /* Number of '?' variables seen in the SQL so far */
21175
+ u64 aVnbmc[SQLITE_VNBMC]; /* Varible Number Bitmap Cache */
2113121176
u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
2113221177
u8 explain; /* True if the EXPLAIN flag is found on the query */
2113321178
u8 eParseMode; /* PARSE_MODE_XXX constant */
2113421179
#ifndef SQLITE_OMIT_VIRTUALTABLE
2113521180
int nVtabLock; /* Number of virtual tables to lock */
@@ -22165,10 +22210,11 @@
2216522210
SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int,int);
2216622211
SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,const Token*,int);
2216722212
SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);
2216822213
SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
2216922214
SQLITE_PRIVATE void sqlite3ExprListDeleteGeneric(sqlite3*,void*);
22215
+SQLITE_PRIVATE int sqlite3ExprCanReturnSubtype(Parse*,Expr*);
2217022216
SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
2217122217
SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage(Index*);
2217222218
SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
2217322219
SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
2217422220
SQLITE_PRIVATE int sqlite3InitOne(sqlite3*, int, char**, u32);
@@ -22389,10 +22435,11 @@
2238922435
SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*);
2239022436
SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse*,Expr*);
2239122437
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
2239222438
SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
2239322439
SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int,int);
22440
+SQLITE_PRIVATE int sqlite3ExprListIsConstant(Parse *pParse, ExprList *pList, int bNoIs);
2239422441
#ifdef SQLITE_ENABLE_CURSOR_HINTS
2239522442
SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
2239622443
#endif
2239722444
SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*, Parse*);
2239822445
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
@@ -22544,10 +22591,11 @@
2254422591
** be defined locally, but now we use the varint routines in the util.c
2254522592
** file.
2254622593
*/
2254722594
SQLITE_PRIVATE int sqlite3PutVarint(unsigned char*, u64);
2254822595
SQLITE_PRIVATE u8 sqlite3GetVarint(const unsigned char *, u64 *);
22596
+SQLITE_PRIVATE i64 sqlite3VarintValue(const unsigned char*);
2254922597
SQLITE_PRIVATE u8 sqlite3GetVarint32(const unsigned char *, u32 *);
2255022598
SQLITE_PRIVATE int sqlite3VarintLen(u64 v);
2255122599
2255222600
/*
2255322601
** The common case is for a varint to be a single byte. They following
@@ -22559,13 +22607,10 @@
2255922607
#define getVarint32NR(A,B) \
2256022608
B=(u32)*(A);if(B>=0x80)sqlite3GetVarint32((A),(u32*)&(B))
2256122609
#define putVarint32(A,B) \
2256222610
(u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\
2256322611
sqlite3PutVarint((A),(B)))
22564
-#define getVarint sqlite3GetVarint
22565
-#define putVarint sqlite3PutVarint
22566
-
2256722612
2256822613
SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3*, Index*);
2256922614
SQLITE_PRIVATE char *sqlite3TableAffinityStr(sqlite3*,const Table*);
2257022615
SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
2257122616
SQLITE_PRIVATE char sqlite3CompareAffinity(const Expr *pExpr, char aff2);
@@ -38343,176 +38388,88 @@
3834338388
p[1] = v&0x7f;
3834438389
return 2;
3834538390
}
3834638391
return putVarint64(p,v);
3834738392
}
38348
-
38349
-/*
38350
-** Bitmasks used by sqlite3GetVarint(). These precomputed constants
38351
-** are defined here rather than simply putting the constant expressions
38352
-** inline in order to work around bugs in the RVT compiler.
38353
-**
38354
-** SLOT_2_0 A mask for (0x7f<<14) | 0x7f
38355
-**
38356
-** SLOT_4_2_0 A mask for (0x7f<<28) | SLOT_2_0
38357
-*/
38358
-#define SLOT_2_0 0x001fc07f
38359
-#define SLOT_4_2_0 0xf01fc07f
38360
-
3836138393
3836238394
/*
3836338395
** Read a 64-bit variable-length integer from memory starting at p[0].
3836438396
** Return the number of bytes read. The value is stored in *v.
3836538397
*/
3836638398
SQLITE_PRIVATE u8 sqlite3GetVarint(const unsigned char *p, u64 *v){
38367
- u32 a,b,s;
38368
-
38369
- if( ((signed char*)p)[0]>=0 ){
38370
- *v = *p;
38371
- return 1;
38372
- }
38373
- if( ((signed char*)p)[1]>=0 ){
38374
- *v = ((u32)(p[0]&0x7f)<<7) | p[1];
38375
- return 2;
38376
- }
38377
-
38378
- /* Verify that constants are precomputed correctly */
38379
- assert( SLOT_2_0 == ((0x7f<<14) | (0x7f)) );
38380
- assert( SLOT_4_2_0 == ((0xfU<<28) | (0x7f<<14) | (0x7f)) );
38381
-
38382
- a = ((u32)p[0])<<14;
38383
- b = p[1];
38384
- p += 2;
38385
- a |= *p;
38386
- /* a: p0<<14 | p2 (unmasked) */
38387
- if (!(a&0x80))
38388
- {
38389
- a &= SLOT_2_0;
38390
- b &= 0x7f;
38391
- b = b<<7;
38392
- a |= b;
38393
- *v = a;
38394
- return 3;
38395
- }
38396
-
38397
- /* CSE1 from below */
38398
- a &= SLOT_2_0;
38399
- p++;
38400
- b = b<<14;
38401
- b |= *p;
38402
- /* b: p1<<14 | p3 (unmasked) */
38403
- if (!(b&0x80))
38404
- {
38405
- b &= SLOT_2_0;
38406
- /* moved CSE1 up */
38407
- /* a &= (0x7f<<14)|(0x7f); */
38408
- a = a<<7;
38409
- a |= b;
38410
- *v = a;
38411
- return 4;
38412
- }
38413
-
38414
- /* a: p0<<14 | p2 (masked) */
38415
- /* b: p1<<14 | p3 (unmasked) */
38416
- /* 1:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
38417
- /* moved CSE1 up */
38418
- /* a &= (0x7f<<14)|(0x7f); */
38419
- b &= SLOT_2_0;
38420
- s = a;
38421
- /* s: p0<<14 | p2 (masked) */
38422
-
38423
- p++;
38424
- a = a<<14;
38425
- a |= *p;
38426
- /* a: p0<<28 | p2<<14 | p4 (unmasked) */
38427
- if (!(a&0x80))
38428
- {
38429
- /* we can skip these cause they were (effectively) done above
38430
- ** while calculating s */
38431
- /* a &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
38432
- /* b &= (0x7f<<14)|(0x7f); */
38433
- b = b<<7;
38434
- a |= b;
38435
- s = s>>18;
38436
- *v = ((u64)s)<<32 | a;
38437
- return 5;
38438
- }
38439
-
38440
- /* 2:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
38441
- s = s<<7;
38442
- s |= b;
38443
- /* s: p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
38444
-
38445
- p++;
38446
- b = b<<14;
38447
- b |= *p;
38448
- /* b: p1<<28 | p3<<14 | p5 (unmasked) */
38449
- if (!(b&0x80))
38450
- {
38451
- /* we can skip this cause it was (effectively) done above in calc'ing s */
38452
- /* b &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
38453
- a &= SLOT_2_0;
38454
- a = a<<7;
38455
- a |= b;
38456
- s = s>>18;
38457
- *v = ((u64)s)<<32 | a;
38458
- return 6;
38459
- }
38460
-
38461
- p++;
38462
- a = a<<14;
38463
- a |= *p;
38464
- /* a: p2<<28 | p4<<14 | p6 (unmasked) */
38465
- if (!(a&0x80))
38466
- {
38467
- a &= SLOT_4_2_0;
38468
- b &= SLOT_2_0;
38469
- b = b<<7;
38470
- a |= b;
38471
- s = s>>11;
38472
- *v = ((u64)s)<<32 | a;
38473
- return 7;
38474
- }
38475
-
38476
- /* CSE2 from below */
38477
- a &= SLOT_2_0;
38478
- p++;
38479
- b = b<<14;
38480
- b |= *p;
38481
- /* b: p3<<28 | p5<<14 | p7 (unmasked) */
38482
- if (!(b&0x80))
38483
- {
38484
- b &= SLOT_4_2_0;
38485
- /* moved CSE2 up */
38486
- /* a &= (0x7f<<14)|(0x7f); */
38487
- a = a<<7;
38488
- a |= b;
38489
- s = s>>4;
38490
- *v = ((u64)s)<<32 | a;
38491
- return 8;
38492
- }
38493
-
38494
- p++;
38495
- a = a<<15;
38496
- a |= *p;
38497
- /* a: p4<<29 | p6<<15 | p8 (unmasked) */
38498
-
38499
- /* moved CSE2 up */
38500
- /* a &= (0x7f<<29)|(0x7f<<15)|(0xff); */
38501
- b &= SLOT_2_0;
38502
- b = b<<8;
38503
- a |= b;
38504
-
38505
- s = s<<4;
38506
- b = p[-4];
38507
- b &= 0x7f;
38508
- b = b>>3;
38509
- s |= b;
38510
-
38511
- *v = ((u64)s)<<32 | a;
38512
-
38513
- return 9;
38399
+ u64 iKey = p[0];
38400
+ const u8 *pStart = p;
38401
+ if( iKey>=0x80 ){
38402
+ u8 x;
38403
+ iKey = (iKey<<7) ^ (x = *++p);
38404
+ if( x>=0x80 ){
38405
+ iKey = (iKey<<7) ^ (x = *++p);
38406
+ if( x>=0x80 ){
38407
+ iKey = (iKey<<7) ^ 0x10204000 ^ (x = *++p);
38408
+ if( x>=0x80 ){
38409
+ iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38410
+ if( x>=0x80 ){
38411
+ iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38412
+ if( x>=0x80 ){
38413
+ iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38414
+ if( x>=0x80 ){
38415
+ iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38416
+ if( x>=0x80 ){
38417
+ iKey = (iKey<<8) ^ 0x8000 ^ (*++p);
38418
+ }
38419
+ }
38420
+ }
38421
+ }
38422
+ }
38423
+ }else{
38424
+ iKey ^= 0x204000;
38425
+ }
38426
+ }else{
38427
+ iKey ^= 0x4000;
38428
+ }
38429
+ }
38430
+ *v = iKey;
38431
+ return (u8)(p - pStart) + 1;
38432
+}
38433
+
38434
+/*
38435
+** Return the value of a variable-length integer without computing
38436
+** its length. This is an optimization on sqlite3GetVarint() for the
38437
+** cases when the return value of sqlite3GetVarint() is not needed.
38438
+*/
38439
+SQLITE_PRIVATE i64 sqlite3VarintValue(const unsigned char *p){
38440
+ u64 iKey = p[0];
38441
+ if( iKey>=0x80 ){
38442
+ u8 x;
38443
+ iKey = (iKey<<7) ^ (x = *++p);
38444
+ if( x>=0x80 ){
38445
+ iKey = (iKey<<7) ^ (x = *++p);
38446
+ if( x>=0x80 ){
38447
+ iKey = (iKey<<7) ^ 0x10204000 ^ (x = *++p);
38448
+ if( x>=0x80 ){
38449
+ iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38450
+ if( x>=0x80 ){
38451
+ iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38452
+ if( x>=0x80 ){
38453
+ iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38454
+ if( x>=0x80 ){
38455
+ iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38456
+ if( x>=0x80 ){
38457
+ iKey = (iKey<<8) ^ 0x8000 ^ (*++p);
38458
+ }
38459
+ }
38460
+ }
38461
+ }
38462
+ }
38463
+ }else{
38464
+ iKey ^= 0x204000;
38465
+ }
38466
+ }else{
38467
+ iKey ^= 0x4000;
38468
+ }
38469
+ }
38470
+ return *(i64*)&iKey;
3851438471
}
3851538472
3851638473
/*
3851738474
** Read a 32-bit variable-length integer from memory starting at p[0].
3851838475
** Return the number of bytes read. The value is stored in *v.
@@ -39405,11 +39362,11 @@
3940539362
/* 69 */ "Return" OpHelp(""),
3940639363
/* 70 */ "EndCoroutine" OpHelp(""),
3940739364
/* 71 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
3940839365
/* 72 */ "Halt" OpHelp(""),
3940939366
/* 73 */ "Integer" OpHelp("r[P2]=P1"),
39410
- /* 74 */ "Int64" OpHelp("r[P2]=P4"),
39367
+ /* 74 */ "Int64" OpHelp("r[P2]=PINT13"),
3941139368
/* 75 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
3941239369
/* 76 */ "BeginSubrtn" OpHelp("r[P2]=NULL"),
3941339370
/* 77 */ "Null" OpHelp("r[P2..P3]=NULL"),
3941439371
/* 78 */ "SoftNull" OpHelp("r[P1]=NULL"),
3941539372
/* 79 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
@@ -39456,11 +39413,11 @@
3945639413
/* 120 */ "OpenEphemeral" OpHelp("nColumn=P2"),
3945739414
/* 121 */ "SorterOpen" OpHelp(""),
3945839415
/* 122 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
3945939416
/* 123 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
3946039417
/* 124 */ "Close" OpHelp(""),
39461
- /* 125 */ "ColumnsUsed" OpHelp(""),
39418
+ /* 125 */ "ColumnsUsed" OpHelp("Cursor P1 uses columns PHEX23"),
3946239419
/* 126 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"),
3946339420
/* 127 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"),
3946439421
/* 128 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
3946539422
/* 129 */ "NewRowid" OpHelp("r[P2]=rowid"),
3946639423
/* 130 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
@@ -39485,11 +39442,11 @@
3948539442
/* 149 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
3948639443
/* 150 */ "SqlExec" OpHelp(""),
3948739444
/* 151 */ "ParseSchema" OpHelp(""),
3948839445
/* 152 */ "LoadAnalysis" OpHelp(""),
3948939446
/* 153 */ "DropTable" OpHelp(""),
39490
- /* 154 */ "Real" OpHelp("r[P2]=P4"),
39447
+ /* 154 */ "Real" OpHelp("r[P2]=PDBL13"),
3949139448
/* 155 */ "DropIndex" OpHelp(""),
3949239449
/* 156 */ "DropTrigger" OpHelp(""),
3949339450
/* 157 */ "IntegrityCk" OpHelp(""),
3949439451
/* 158 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
3949539452
/* 159 */ "Param" OpHelp(""),
@@ -57486,10 +57443,11 @@
5748657443
5748757444
nNew = 2*(u64)p->nHash;
5748857445
if( nNew<256 ){
5748957446
nNew = 256;
5749057447
}
57448
+ assert( (nNew & (nNew-1))==0 ); /* nNew is always a power of two */
5749157449
5749257450
pcache1LeaveMutex(p->pGroup);
5749357451
if( p->nHash ){ sqlite3BeginBenignMalloc(); }
5749457452
apNew = (PgHdr1 **)sqlite3MallocZero(sizeof(PgHdr1 *)*nNew);
5749557453
if( p->nHash ){ sqlite3EndBenignMalloc(); }
@@ -57497,11 +57455,11 @@
5749757455
if( apNew ){
5749857456
for(i=0; i<p->nHash; i++){
5749957457
PgHdr1 *pPage;
5750057458
PgHdr1 *pNext = p->apHash[i];
5750157459
while( (pPage = pNext)!=0 ){
57502
- unsigned int h = pPage->iKey % nNew;
57460
+ unsigned int h = (unsigned int)(pPage->iKey & (nNew-1));
5750357461
pNext = pPage->pNext;
5750457462
pPage->pNext = apNew[h];
5750557463
apNew[h] = pPage;
5750657464
}
5750757465
}
@@ -57547,11 +57505,12 @@
5754757505
unsigned int h;
5754857506
PCache1 *pCache = pPage->pCache;
5754957507
PgHdr1 **pp;
5755057508
5755157509
assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
57552
- h = pPage->iKey % pCache->nHash;
57510
+ assert( pCache->nHash>0 && (pCache->nHash & (pCache->nHash-1))==0 );
57511
+ h = pPage->iKey & (pCache->nHash-1);
5755357512
for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
5755457513
*pp = (*pp)->pNext;
5755557514
5755657515
pCache->nPage--;
5755757516
if( freeFlag ) pcache1FreePage(pPage);
@@ -57592,18 +57551,18 @@
5759257551
){
5759357552
TESTONLY( int nPage = 0; ) /* To assert pCache->nPage is correct */
5759457553
unsigned int h, iStop;
5759557554
assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
5759657555
assert( pCache->iMaxKey >= iLimit );
57597
- assert( pCache->nHash > 0 );
57556
+ assert( pCache->nHash>0 && (pCache->nHash & (pCache->nHash-1))==0 );
5759857557
if( pCache->iMaxKey - iLimit < pCache->nHash ){
5759957558
/* If we are just shaving the last few pages off the end of the
5760057559
** cache, then there is no point in scanning the entire hash table.
5760157560
** Only scan those hash slots that might contain pages that need to
5760257561
** be removed. */
57603
- h = iLimit % pCache->nHash;
57604
- iStop = pCache->iMaxKey % pCache->nHash;
57562
+ h = iLimit & (pCache->nHash-1);
57563
+ iStop = pCache->iMaxKey & (pCache->nHash-1);
5760557564
TESTONLY( nPage = -10; ) /* Disable the pCache->nPage validity check */
5760657565
}else{
5760757566
/* This is the general case where many pages are being removed.
5760857567
** It is necessary to scan the entire hash table */
5760957568
h = pCache->nHash/2;
@@ -57624,11 +57583,11 @@
5762457583
pp = &pPage->pNext;
5762557584
TESTONLY( if( nPage>=0 ) nPage++; )
5762657585
}
5762757586
}
5762857587
if( h==iStop ) break;
57629
- h = (h+1) % pCache->nHash;
57588
+ h = (h+1) & (pCache->nHash-1);
5763057589
}
5763157590
assert( nPage<0 || pCache->nPage==(unsigned)nPage );
5763257591
}
5763357592
5763457593
/******************************************************************************/
@@ -57836,10 +57795,11 @@
5783657795
return 0;
5783757796
}
5783857797
5783957798
if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
5784057799
assert( pCache->nHash>0 && pCache->apHash );
57800
+ assert( (pCache->nHash & (pCache->nHash-1))==0 );
5784157801
5784257802
/* Step 4. Try to recycle a page. */
5784357803
if( pCache->bPurgeable
5784457804
&& !pGroup->lru.pLruPrev->isAnchor
5784557805
&& ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
@@ -57864,11 +57824,11 @@
5786457824
if( !pPage ){
5786557825
pPage = pcache1AllocPage(pCache, createFlag==1);
5786657826
}
5786757827
5786857828
if( pPage ){
57869
- unsigned int h = iKey % pCache->nHash;
57829
+ unsigned int h = iKey & (pCache->nHash-1);
5787057830
pCache->nPage++;
5787157831
pPage->iKey = iKey;
5787257832
pPage->pNext = pCache->apHash[h];
5787357833
pPage->pCache = pCache;
5787457834
pPage->pLruNext = 0;
@@ -58071,19 +58031,20 @@
5807158031
assert( iOld!=iNew ); /* The page number really is changing */
5807258032
5807358033
pcache1EnterMutex(pCache->pGroup);
5807458034
5807558035
assert( pcache1FetchNoMutex(p, iOld, 0)==pPage ); /* pPg really is iOld */
58076
- hOld = iOld%pCache->nHash;
58036
+ assert( pCache->nHash>0 && (pCache->nHash & (pCache->nHash-1))==0 );
58037
+ hOld = iOld & (pCache->nHash-1);
5807758038
pp = &pCache->apHash[hOld];
5807858039
while( (*pp)!=pPage ){
5807958040
pp = &(*pp)->pNext;
5808058041
}
5808158042
*pp = pPage->pNext;
5808258043
5808358044
assert( pcache1FetchNoMutex(p, iNew, 0)==0 ); /* iNew not in cache */
58084
- hNew = iNew%pCache->nHash;
58045
+ hNew = iNew & (pCache->nHash-1);
5808558046
pPage->iKey = iNew;
5808658047
pPage->pNext = pCache->apHash[hNew];
5808758048
pCache->apHash[hNew] = pPage;
5808858049
if( iNew>pCache->iMaxKey ){
5808958050
pCache->iMaxKey = iNew;
@@ -63895,11 +63856,19 @@
6389563856
6389663857
/* Open the pager file.
6389763858
*/
6389863859
if( zFilename && zFilename[0] ){
6389963860
int fout = 0; /* VFS flags returned by xOpen() */
63861
+ int bImmutable = sqlite3_uri_boolean(pPager->zFilename, "immutable", 0);
63862
+ if( bImmutable ){
63863
+ vfsFlags |= SQLITE_OPEN_READONLY;
63864
+ vfsFlags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
63865
+ }
6390063866
rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
63867
+ if( bImmutable ){
63868
+ goto act_like_temp_file;
63869
+ }
6390163870
assert( !memDb );
6390263871
pPager->memVfs = memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
6390363872
readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
6390463873
6390563874
/* If the file was successfully opened for read/write access,
@@ -63935,14 +63904,13 @@
6393563904
}
6393663905
}
6393763906
#endif
6393863907
}
6393963908
pPager->noLock = sqlite3_uri_boolean(pPager->zFilename, "nolock", 0);
63940
- if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0
63941
- || sqlite3_uri_boolean(pPager->zFilename, "immutable", 0) ){
63942
- vfsFlags |= SQLITE_OPEN_READONLY;
63943
- goto act_like_temp_file;
63909
+ if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0 ){
63910
+ vfsFlags |= SQLITE_OPEN_READONLY;
63911
+ goto act_like_temp_file;
6394463912
}
6394563913
}
6394663914
}else{
6394763915
/* If a temporary file is requested, it is not opened immediately.
6394863916
** In this case we accept the default page size and delay actually
@@ -63958,10 +63926,11 @@
6395863926
tempFile = 1;
6395963927
pPager->eState = PAGER_READER; /* Pretend we already have a lock */
6396063928
pPager->eLock = EXCLUSIVE_LOCK; /* Pretend we are in EXCLUSIVE mode */
6396163929
pPager->noLock = 1; /* Do no locking */
6396263930
readOnly = (vfsFlags&SQLITE_OPEN_READONLY);
63931
+ assert( readOnly==0 || readOnly==1 );
6396363932
}
6396463933
6396563934
/* The following call to PagerSetPagesize() serves to set the value of
6396663935
** Pager.pageSize and to allocate the Pager.pTmpSpace buffer.
6396763936
*/
@@ -70452,15 +70421,19 @@
7045270421
){
7045370422
int sz;
7045470423
i64 iOffset;
7045570424
sz = pWal->hdr.szPage;
7045670425
sz = (sz&0xfe00) + ((sz&0x0001)<<16);
70426
+ if( nOut>sz ){
70427
+ memset(pOut+sz, 0, nOut-sz);
70428
+ nOut = sz;
70429
+ }
7045770430
testcase( sz<=32768 );
7045870431
testcase( sz>=65536 );
7045970432
iOffset = walFrameOffset(iRead, sz) + WAL_FRAME_HDRSIZE;
7046070433
/* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
70461
- return sqlite3OsRead(pWal->pWalFd, pOut, (nOut>sz ? sz : nOut), iOffset);
70434
+ return sqlite3OsRead(pWal->pWalFd, pOut, nOut, iOffset);
7046270435
}
7046370436
7046470437
/*
7046570438
** Return the size of the database in pages (or zero, if unknown).
7046670439
*/
@@ -72163,10 +72136,11 @@
7216372136
Pgno nCkPage; /* Pages in the database. 0 for partial check */
7216472137
int mxErr; /* Stop accumulating errors when this reaches zero */
7216572138
int nErr; /* Number of messages written to zErrMsg so far */
7216672139
int rc; /* SQLITE_OK, SQLITE_NOMEM, or SQLITE_INTERRUPT */
7216772140
u32 nStep; /* Number of steps into the integrity_check process */
72141
+ u8 nAbove; /* Current btree recursion depth */
7216872142
const char *zPfx; /* Error message prefix */
7216972143
Pgno v0; /* Value for first %u substitution in zPfx (root page) */
7217072144
Pgno v1; /* Value for second %u substitution in zPfx (current pg) */
7217172145
int v2; /* Value for third %d substitution in zPfx */
7217272146
StrAccum errMsg; /* Accumulate the error message text here */
@@ -73774,11 +73748,11 @@
7377473748
assert( pPage->leaf==0 );
7377573749
assert( pPage->childPtrSize==4 );
7377673750
#ifndef SQLITE_DEBUG
7377773751
UNUSED_PARAMETER(pPage);
7377873752
#endif
73779
- pInfo->nSize = 4 + getVarint(&pCell[4], (u64*)&pInfo->nKey);
73753
+ pInfo->nSize = 4 + sqlite3GetVarint(&pCell[4], (u64*)&pInfo->nKey);
7378073754
pInfo->nPayload = 0;
7378173755
pInfo->nLocal = 0;
7378273756
pInfo->pPayload = 0;
7378373757
return;
7378473758
}
@@ -73814,11 +73788,11 @@
7381473788
}
7381573789
pIter++;
7381673790
7381773791
/* The next block of code is equivalent to:
7381873792
**
73819
- ** pIter += getVarint(pIter, (u64*)&pInfo->nKey);
73793
+ ** pIter += sqlite3GetVarint(pIter, (u64*)&pInfo->nKey);
7382073794
**
7382173795
** The code is inlined and the loop is unrolled for performance.
7382273796
** This routine is a high-runner.
7382373797
*/
7382473798
iKey = *pIter;
@@ -78425,11 +78399,11 @@
7842578399
if( pCell>=pPage->aDataEnd ){
7842678400
return SQLITE_CORRUPT_PAGE(pPage);
7842778401
}
7842878402
}
7842978403
}
78430
- getVarint(pCell, (u64*)&nCellKey);
78404
+ nCellKey = sqlite3VarintValue(pCell);
7843178405
if( nCellKey<intKey ){
7843278406
lwr = idx+1;
7843378407
if( lwr>upr ){ c = -1; break; }
7843478408
}else if( nCellKey>intKey ){
7843578409
upr = idx-1;
@@ -79632,11 +79606,11 @@
7963279606
nPayload = pX->nData + pX->nZero;
7963379607
pSrc = pX->pData;
7963479608
nSrc = pX->nData;
7963579609
assert( pPage->intKeyLeaf ); /* fillInCell() only called for leaves */
7963679610
nHeader += putVarint32(&pCell[nHeader], nPayload);
79637
- nHeader += putVarint(&pCell[nHeader], *(u64*)&pX->nKey);
79611
+ nHeader += sqlite3PutVarint(&pCell[nHeader], *(u64*)&pX->nKey);
7963879612
}else{
7963979613
assert( pX->nKey<=0x7fffffff && pX->pKey!=0 );
7964079614
nSrc = nPayload = (int)pX->nKey;
7964179615
pSrc = pX->pKey;
7964279616
nHeader += putVarint32(&pCell[nHeader], nPayload);
@@ -81381,11 +81355,11 @@
8138181355
*/
8138281356
CellInfo info;
8138381357
j--;
8138481358
pNew->xParseCell(pNew, b.apCell[j], &info);
8138581359
pCell = pTemp;
81386
- sz = 4 + putVarint(&pCell[4], info.nKey);
81360
+ sz = 4 + sqlite3PutVarint(&pCell[4], info.nKey);
8138781361
pTemp = 0;
8138881362
}else{
8138981363
pCell -= 4;
8139081364
/* Obscure case for non-leaf-data trees: If the cell at pCell was
8139181365
** previously stored on a leaf node, and its reported size was 4
@@ -82266,11 +82240,11 @@
8226682240
if( pSrc->info.nPayload<0x80 ){
8226782241
*(aOut++) = (u8)pSrc->info.nPayload;
8226882242
}else{
8226982243
aOut += sqlite3PutVarint(aOut, pSrc->info.nPayload);
8227082244
}
82271
- if( pDest->pKeyInfo==0 ) aOut += putVarint(aOut, iKey);
82245
+ if( pDest->pKeyInfo==0 ) aOut += sqlite3PutVarint(aOut, iKey);
8227282246
nIn = pSrc->info.nLocal;
8227382247
aIn = pSrc->info.pPayload;
8227482248
if( aIn+nIn>pSrc->pPage->aDataEnd ){
8227582249
return SQLITE_CORRUPT_PAGE(pSrc->pPage);
8227682250
}
@@ -82736,15 +82710,24 @@
8273682710
}
8273782711
8273882712
/*
8273982713
** Erase the given database page and all its children. Return
8274082714
** the page to the freelist.
82715
+**
82716
+** The freePageFlag parameter serves a double role:
82717
+**
82718
+** * Bit 0 (freePageFlag&1) means that the page should be freed
82719
+** after it is cleared.
82720
+**
82721
+** * Bits 1-31 (freePageFlag>>1) is the depth of recursion. Use this
82722
+** to prevent a corrupt database file from recursing too deeply and
82723
+** overflowing the CPU stack.
8274182724
*/
8274282725
static int clearDatabasePage(
8274382726
BtShared *pBt, /* The BTree that contains the table */
8274482727
Pgno pgno, /* Page number to clear */
82745
- int freePageFlag, /* Deallocate page if true */
82728
+ int freePageFlag, /* bit 0: Deallocate page. Bits 1-31: depth */
8274682729
i64 *pnChange /* Add number of Cells freed to this counter */
8274782730
){
8274882731
MemPage *pPage;
8274982732
int rc;
8275082733
unsigned char *pCell;
@@ -82753,10 +82736,13 @@
8275382736
CellInfo info;
8275482737
8275582738
assert( sqlite3_mutex_held(pBt->mutex) );
8275682739
if( pgno>btreePagecount(pBt) ){
8275782740
return SQLITE_CORRUPT_PGNO(pgno);
82741
+ }
82742
+ if( (freePageFlag>>1) > BTCURSOR_MAX_DEPTH ){
82743
+ return SQLITE_CORRUPT_PGNO(pgno);
8275882744
}
8275982745
rc = getAndInitPage(pBt, pgno, &pPage, 0);
8276082746
if( rc ) return rc;
8276182747
if( (pBt->openFlags & BTREE_SINGLE)==0
8276282748
&& sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1))
@@ -82766,26 +82752,28 @@
8276682752
}
8276782753
hdr = pPage->hdrOffset;
8276882754
for(i=0; i<pPage->nCell; i++){
8276982755
pCell = findCell(pPage, i);
8277082756
if( !pPage->leaf ){
82771
- rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
82757
+ rc = clearDatabasePage(pBt, get4byte(pCell),
82758
+ (freePageFlag+2)|1, pnChange);
8277282759
if( rc ) goto cleardatabasepage_out;
8277382760
}
8277482761
BTREE_CLEAR_CELL(rc, pPage, pCell, info);
8277582762
if( rc ) goto cleardatabasepage_out;
8277682763
}
8277782764
if( !pPage->leaf ){
82778
- rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
82765
+ rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]),
82766
+ (freePageFlag+2)|1, pnChange);
8277982767
if( rc ) goto cleardatabasepage_out;
8278082768
if( pPage->intKey ) pnChange = 0;
8278182769
}
8278282770
if( pnChange ){
8278382771
testcase( !pPage->intKey );
8278482772
*pnChange += pPage->nCell;
8278582773
}
82786
- if( freePageFlag ){
82774
+ if( (freePageFlag&1)!=0 ){
8278782775
freePage(pPage, &rc);
8278882776
}else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
8278982777
zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF);
8279082778
}
8279182779
@@ -83416,22 +83404,27 @@
8341683404
u8 savedIsInit = 0;
8341783405
8341883406
/* Check that the page exists
8341983407
*/
8342083408
checkProgress(pCheck);
83421
- if( pCheck->mxErr==0 ) goto end_of_check;
83409
+ if( pCheck->mxErr==0 ) return 0;
8342283410
pBt = pCheck->pBt;
8342383411
usableSize = pBt->usableSize;
8342483412
if( iPage==0 ) return 0;
8342583413
if( checkRef(pCheck, iPage) ) return 0;
8342683414
pCheck->zPfx = "Tree %u page %u: ";
8342783415
pCheck->v1 = iPage;
83416
+ pCheck->nAbove++;
8342883417
if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
8342983418
checkAppendMsg(pCheck,
8343083419
"unable to get the page. error code=%d", rc);
8343183420
if( rc==SQLITE_IOERR_NOMEM ) pCheck->rc = SQLITE_NOMEM;
8343283421
goto end_of_check;
83422
+ }
83423
+ if( pCheck->nAbove > BTCURSOR_MAX_DEPTH ){
83424
+ checkAppendMsg(pCheck,"btree depth exceeds %d",BTCURSOR_MAX_DEPTH);
83425
+ goto end_of_check;
8343383426
}
8343483427
8343583428
/* Clear MemPage.isInit to make sure the corruption detection code in
8343683429
** btreeInitPage() is executed. */
8343783430
savedIsInit = pPage->isInit;
@@ -83648,10 +83641,11 @@
8364883641
if( !doCoverageCheck ) pPage->isInit = savedIsInit;
8364983642
releasePage(pPage);
8365083643
pCheck->zPfx = saved_zPfx;
8365183644
pCheck->v1 = saved_v1;
8365283645
pCheck->v2 = saved_v2;
83646
+ pCheck->nAbove--;
8365383647
return depth+1;
8365483648
}
8365583649
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
8365683650
8365783651
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
@@ -83780,11 +83774,13 @@
8378083774
if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){
8378183775
checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
8378283776
}
8378383777
#endif
8378483778
sCheck.v0 = aRoot[i];
83779
+ assert( sCheck.nAbove==0 );
8378583780
checkTreePage(&sCheck, aRoot[i], &notUsed, LARGEST_INT64);
83781
+ assert( sCheck.nAbove==0 );
8378683782
}
8378783783
sqlite3MemSetArrayInt64(aCnt, i, sCheck.nRow);
8378883784
}
8378983785
pBt->db->flags = savedDbFlags;
8379083786
@@ -87553,10 +87549,24 @@
8755387549
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8755487550
** Replicate in sqlite3VdbeAddOp3() */
8755587551
8755687552
return i;
8755787553
}
87554
+
87555
+/* Generate an opcode that loads a 64-bit integer into register iDest
87556
+*/
87557
+SQLITE_PRIVATE int sqlite3VdbeAddInt64(Vdbe *p, int iDest, i64 iVal){
87558
+ return sqlite3VdbeAddOp3(p, OP_Int64, LOWER32(iVal), iDest, UPPER32(iVal));
87559
+}
87560
+
87561
+/* Generate an opcode that loads a 64-floating point value into register iDest.
87562
+*/
87563
+SQLITE_PRIVATE int sqlite3VdbeAddDouble(Vdbe *p, int iDest, double rVal){
87564
+ i64 iVal;
87565
+ memcpy(&iVal,&rVal,8);
87566
+ return sqlite3VdbeAddOp3(p, OP_Real, LOWER32(iVal), iDest, UPPER32(iVal));
87567
+}
8755887568
8755987569
/* Generate code for an unconditional jump to instruction iDest
8756087570
*/
8756187571
SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe *p, int iDest){
8756287572
return sqlite3VdbeAddOp3(p, OP_Goto, 0, iDest, 0);
@@ -87657,28 +87667,10 @@
8765787667
sqlite3VdbeChangeP5(v, eCallCtx & NC_SelfRef);
8765887668
sqlite3MayAbort(pParse);
8765987669
return addr;
8766087670
}
8766187671
87662
-/*
87663
-** Add an opcode that includes the p4 value with a P4_INT64 or
87664
-** P4_REAL type.
87665
-*/
87666
-SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(
87667
- Vdbe *p, /* Add the opcode to this VM */
87668
- int op, /* The new opcode */
87669
- int p1, /* The P1 operand */
87670
- int p2, /* The P2 operand */
87671
- int p3, /* The P3 operand */
87672
- const u8 *zP4, /* The P4 operand */
87673
- int p4type /* P4 operand type */
87674
-){
87675
- char *p4copy = sqlite3DbMallocRawNN(sqlite3VdbeDb(p), 8);
87676
- if( p4copy ) memcpy(p4copy, zP4, 8);
87677
- return sqlite3VdbeAddOp4(p, op, p1, p2, p3, p4copy, p4type);
87678
-}
87679
-
8768087672
#ifndef SQLITE_OMIT_EXPLAIN
8768187673
/*
8768287674
** Return the address of the current EXPLAIN QUERY PLAN baseline.
8768387675
** 0 means "none".
8768487676
*/
@@ -88581,12 +88573,10 @@
8858188573
switch( p4type ){
8858288574
case P4_FUNCCTX: {
8858388575
freeP4FuncCtx(db, (sqlite3_context*)p4);
8858488576
break;
8858588577
}
88586
- case P4_REAL:
88587
- case P4_INT64:
8858888578
case P4_DYNAMIC:
8858988579
case P4_INTARRAY: {
8859088580
if( p4 ) sqlite3DbNNFreeNN(db, p4);
8859188581
break;
8859288582
}
@@ -88936,10 +88926,13 @@
8893688926
**
8893788927
** "PX" -> "r[X]"
8893888928
** "PX@PY" -> "r[X..X+Y-1]" or "r[x]" if y is 0 or 1
8893988929
** "PX@PY+1" -> "r[X..X+Y]" or "r[x]" if y is 0
8894088930
** "PY..PY" -> "r[X..Y]" or "r[x]" if y<=x
88931
+** "PINT13" -> int(P1|P3<<32)
88932
+** "PDBL13" -> real(P1|P3<<32)
88933
+** "PHEX23" -> hex(P2|P3<<32)
8894188934
*/
8894288935
SQLITE_PRIVATE char *sqlite3VdbeDisplayComment(
8894388936
sqlite3 *db, /* Optional - Oom error reporting only */
8894488937
const Op *pOp, /* The opcode to be commented */
8894588938
const char *zP4 /* Previously obtained value for P4 */
@@ -88971,10 +88964,24 @@
8897188964
if( pOp->zComment && pOp->zComment[0] ){
8897288965
sqlite3_str_appendall(&x, pOp->zComment);
8897388966
seenCom = 1;
8897488967
break;
8897588968
}
88969
+ }else if( strncmp(&zSynopsis[ii],"INT13",5)==0 ){
88970
+ sqlite3_str_appendf(&x,"%lld",INT32_TO_64(pOp->p1,pOp->p3));
88971
+ ii += 4;
88972
+#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
88973
+ }else if( strncmp(&zSynopsis[ii],"HEX23",5)==0 ){
88974
+ sqlite3_str_appendf(&x,"0x%llx",INT32_TO_64(pOp->p2,pOp->p3));
88975
+ ii += 4;
88976
+#endif
88977
+ }else if( strncmp(&zSynopsis[ii],"DBL13",5)==0 ){
88978
+ i64 iVal = INT32_TO_64(pOp->p1,pOp->p3);
88979
+ double r;
88980
+ memcpy(&r, &iVal, 8);
88981
+ sqlite3_str_appendf(&x,"%.17g",r);
88982
+ ii += 4;
8897688983
}else{
8897788984
int v1 = translateP(c, pOp);
8897888985
int v2;
8897988986
if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
8898088987
ii += 3;
@@ -89148,22 +89155,14 @@
8914889155
case P4_FUNCCTX: {
8914989156
FuncDef *pDef = pOp->p4.pCtx->pFunc;
8915089157
sqlite3_str_appendf(&x, "%s(%d)", pDef->zName, pDef->nArg);
8915189158
break;
8915289159
}
89153
- case P4_INT64: {
89154
- sqlite3_str_appendf(&x, "%lld", *pOp->p4.pI64);
89155
- break;
89156
- }
8915789160
case P4_INT32: {
8915889161
sqlite3_str_appendf(&x, "%d", pOp->p4.i);
8915989162
break;
8916089163
}
89161
- case P4_REAL: {
89162
- sqlite3_str_appendf(&x, "%.16g", *pOp->p4.pReal);
89163
- break;
89164
- }
8916589164
case P4_MEM: {
8916689165
Mem *pMem = pOp->p4.pMem;
8916789166
if( pMem->flags & MEM_Str ){
8916889167
zP4 = pMem->z;
8916989168
}else if( pMem->flags & (MEM_Int|MEM_IntReal) ){
@@ -97360,35 +97359,39 @@
9736097359
pOut = out2Prerelease(p, pOp);
9736197360
pOut->u.i = pOp->p1;
9736297361
break;
9736397362
}
9736497363
97365
-/* Opcode: Int64 * P2 * P4 *
97366
-** Synopsis: r[P2]=P4
97364
+/* Opcode: Int64 P1 P2 P3 * *
97365
+** Synopsis: r[P2]=PINT13
9736797366
**
97368
-** P4 is a pointer to a 64-bit integer value.
97369
-** Write that value into register P2.
97367
+** Combine P1 and P3 into a signed 64-bit integer. P1 is the least
97368
+** significant 32 bits and P3 is the most significant. Store the
97369
+** result in register P2.
9737097370
*/
9737197371
case OP_Int64: { /* out2 */
9737297372
pOut = out2Prerelease(p, pOp);
97373
- assert( pOp->p4.pI64!=0 );
97374
- pOut->u.i = *pOp->p4.pI64;
97373
+ pOut->u.i = INT32_TO_64(pOp->p1,pOp->p3);
9737597374
break;
9737697375
}
9737797376
9737897377
#ifndef SQLITE_OMIT_FLOATING_POINT
97379
-/* Opcode: Real * P2 * P4 *
97380
-** Synopsis: r[P2]=P4
97378
+/* Opcode: Real P1 P2 P3 * *
97379
+** Synopsis: r[P2]=PDBL13
9738197380
**
97382
-** P4 is a pointer to a 64-bit floating point value.
97383
-** Write that value into register P2.
97381
+** P1 and P3 are combined to 64 bits with P1 being the lower the P3
97382
+** the upper. The result is interpreted as a 64-bit floating-point
97383
+** and stored in register P2.
9738497384
*/
9738597385
case OP_Real: { /* same as TK_FLOAT, out2 */
97386
+ u64 ii;
9738697387
pOut = out2Prerelease(p, pOp);
9738797388
pOut->flags = MEM_Real;
97388
- assert( !sqlite3IsNaN(*pOp->p4.pReal) );
97389
- pOut->u.r = *pOp->p4.pReal;
97389
+ ii = (u64)INT32_TO_64(pOp->p1,pOp->p3);
97390
+ swapMixedEndianFloat(ii);
97391
+ memcpy(&pOut->u.r, &ii, 8);
97392
+ assert( !sqlite3IsNaN(pOut->u.r) );
9739097393
break;
9739197394
}
9739297395
#endif
9739397396
9739497397
/* Opcode: String8 * P2 * P4 *
@@ -99461,26 +99464,13 @@
9946199464
while( 1 /*exit-by-break*/ ){
9946299465
assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
9946399466
assert( zAffinity[0]==SQLITE_AFF_NONE || memIsValid(pIn1) );
9946499467
applyAffinity(pIn1, zAffinity[0], encoding);
9946599468
if( zAffinity[0]==SQLITE_AFF_REAL && (pIn1->flags & MEM_Int)!=0 ){
99466
- /* When applying REAL affinity, if the result is still an MEM_Int
99467
- ** that will fit in 6 bytes, then change the type to MEM_IntReal
99468
- ** so that we keep the high-resolution integer value but know that
99469
- ** the type really wants to be REAL. */
99470
- testcase( pIn1->u.i==140737488355328LL );
99471
- testcase( pIn1->u.i==140737488355327LL );
99472
- testcase( pIn1->u.i==-140737488355328LL );
99473
- testcase( pIn1->u.i==-140737488355329LL );
99474
- if( pIn1->u.i<=140737488355327LL && pIn1->u.i>=-140737488355328LL ){
99475
- pIn1->flags |= MEM_IntReal;
99476
- pIn1->flags &= ~MEM_Int;
99477
- }else{
99478
- pIn1->u.r = (double)pIn1->u.i;
99479
- pIn1->flags |= MEM_Real;
99480
- pIn1->flags &= ~(MEM_Int|MEM_Str);
99481
- }
99469
+ pIn1->u.r = (double)pIn1->u.i;
99470
+ pIn1->flags |= MEM_Real;
99471
+ pIn1->flags &= ~(MEM_Int|MEM_Str);
9948299472
}
9948399473
REGISTER_TRACE((int)(pIn1-aMem), pIn1);
9948499474
zAffinity++;
9948599475
if( zAffinity[0]==0 ) break;
9948699476
pIn1++;
@@ -100794,25 +100784,25 @@
100794100784
p->apCsr[pOp->p1] = 0;
100795100785
break;
100796100786
}
100797100787
100798100788
#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
100799
-/* Opcode: ColumnsUsed P1 * * P4 *
100789
+/* Opcode: ColumnsUsed P1 P2 P3 * *
100790
+** Synopsis: Cursor P1 uses columns PHEX23
100800100791
**
100801100792
** This opcode (which only exists if SQLite was compiled with
100802100793
** SQLITE_ENABLE_COLUMN_USED_MASK) identifies which columns of the
100803
-** table or index for cursor P1 are used. P4 is a 64-bit integer
100804
-** (P4_INT64) in which the first 63 bits are one for each of the
100805
-** first 63 columns of the table or index that are actually used
100806
-** by the cursor. The high-order bit is set if any column after
100807
-** the 64th is used.
100794
+** table or index for cursor P1 are used. P2 and P3 combine to give
100795
+** a 64-bit unsigned integer mask. P2 stores the lower 32 bits and
100796
+** P3 stores the upper 32 bits. If the high-order bit of P3 is set
100797
+** that means that and 64-th or some later column is used.
100808100798
*/
100809100799
case OP_ColumnsUsed: {
100810100800
VdbeCursor *pC;
100811100801
pC = p->apCsr[pOp->p1];
100812100802
assert( pC->eCurType==CURTYPE_BTREE );
100813
- pC->maskUsed = *(u64*)pOp->p4.pI64;
100803
+ pC->maskUsed = INT32_TO_64(pOp->p2,pOp->p3);
100814100804
break;
100815100805
}
100816100806
#endif
100817100807
100818100808
/* Opcode: SeekGE P1 P2 P3 P4 *
@@ -113899,10 +113889,12 @@
113899113889
}
113900113890
x = (ynVar)i;
113901113891
if( x>pParse->nVar ){
113902113892
pParse->nVar = (int)x;
113903113893
doAdd = 1;
113894
+ }else if( x<SQLITE_VNBMC*64 ){
113895
+ doAdd = (pParse->aVnbmc[x>>6] & MASKBIT64(x&63))==0;
113904113896
}else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){
113905113897
doAdd = 1;
113906113898
}
113907113899
}else{
113908113900
/* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable
@@ -113915,10 +113907,13 @@
113915113907
doAdd = 1;
113916113908
}
113917113909
}
113918113910
if( doAdd ){
113919113911
pParse->pVList = sqlite3VListAdd(db, pParse->pVList, z, n, x);
113912
+ if( pParse->pVList!=0 && x<SQLITE_VNBMC*64 ){
113913
+ pParse->aVnbmc[x>>6] |= MASKBIT64(x&63);
113914
+ }
113920113915
}
113921113916
}
113922113917
pExpr->iColumn = x;
113923113918
if( x>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
113924113919
sqlite3ErrorMsg(pParse, "too many SQL variables");
@@ -115067,10 +115062,11 @@
115067115062
**
115068115063
** sqlite3ExprIsConstant() pWalker->eCode==1
115069115064
** sqlite3ExprIsConstantNotJoin() pWalker->eCode==2
115070115065
** sqlite3ExprIsTableConstant() pWalker->eCode==3
115071115066
** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5
115067
+** sqlite3ExprListIsConstant() pWalker->eCode==1 or 6
115072115068
**
115073115069
** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
115074115070
** is found to not be a constant.
115075115071
**
115076115072
** The sqlite3ExprIsConstantOrFunction() is used for evaluating DEFAULT
@@ -115139,10 +115135,17 @@
115139115135
testcase( pExpr->op==TK_IF_NULL_ROW );
115140115136
testcase( pExpr->op==TK_DOT );
115141115137
testcase( pExpr->op==TK_RAISE );
115142115138
pWalker->eCode = 0;
115143115139
return WRC_Abort;
115140
+ case TK_IS:
115141
+ case TK_ISNOT:
115142
+ if( pWalker->eCode==6 ){
115143
+ pWalker->eCode = 0;
115144
+ return WRC_Abort;
115145
+ }
115146
+ return WRC_Continue;
115144115147
case TK_VARIABLE:
115145115148
if( pWalker->eCode==5 ){
115146115149
/* Silently convert bound parameters that appear inside of CREATE
115147115150
** statements into a NULL when parsing the CREATE statement text out
115148115151
** of the sqlite_schema table */
@@ -115188,10 +115191,26 @@
115188115191
** function and on its parameters.
115189115192
*/
115190115193
SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse *pParse, Expr *p){
115191115194
return exprIsConst(pParse, p, 1);
115192115195
}
115196
+
115197
+/*
115198
+** Return true if all expressions in pList are constant. If parameter bNoIs
115199
+** is true, do not consider expressions that contain "IS" operators to be
115200
+** constant. IS operators are not always considered constant as expressions
115201
+** like "x IS TRUE" need to be transformed to TK_TRUTH expression nodes,
115202
+** which happens at the same time as column name resolution.
115203
+*/
115204
+SQLITE_PRIVATE int sqlite3ExprListIsConstant(Parse *pParse, ExprList *pList, int bNoIs){
115205
+ const int iInit = bNoIs ? 6 : 1;
115206
+ int ii;
115207
+ for(ii=0; ii<pList->nExpr; ii++){
115208
+ if( 0==exprIsConst(pParse, pList->a[ii].pExpr, iInit) ) return 0;
115209
+ }
115210
+ return 1;
115211
+}
115193115212
115194115213
/*
115195115214
** Walk an expression tree. Return non-zero if
115196115215
**
115197115216
** (1) the expression is constant, and
@@ -115922,13 +115941,13 @@
115922115941
assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
115923115942
eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
115924115943
115925115944
if( prRhsHasNull ){
115926115945
#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
115927
- i64 mask = (1<<nExpr)-1;
115928
- sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed,
115929
- iTab, 0, 0, (u8*)&mask, P4_INT64);
115946
+ u64 mask = (1<<nExpr)-1;
115947
+ sqlite3VdbeAddOp3(v, OP_ColumnsUsed,
115948
+ iTab, LOWER32(mask), UPPER32(mask));
115930115949
#endif
115931115950
*prRhsHasNull = ++pParse->nMem;
115932115951
if( nExpr==1 ){
115933115952
sqlite3SetHasNullFlag(v, iTab, *prRhsHasNull);
115934115953
}
@@ -116878,11 +116897,11 @@
116878116897
if( ALWAYS(z!=0) ){
116879116898
double value;
116880116899
sqlite3AtoF(z, &value);
116881116900
assert( !sqlite3IsNaN(value) ); /* The new AtoF never returns NaN */
116882116901
if( negateFlag ) value = -value;
116883
- sqlite3VdbeAddOp4Dup8(v, OP_Real, 0, iMem, 0, (u8*)&value, P4_REAL);
116902
+ sqlite3VdbeAddDouble(v, iMem, value);
116884116903
}
116885116904
}
116886116905
#endif
116887116906
116888116907
@@ -116919,11 +116938,11 @@
116919116938
codeReal(v, z, negFlag, iMem);
116920116939
}
116921116940
#endif
116922116941
}else{
116923116942
if( negFlag ){ value = c==3 ? SMALLEST_INT64 : -value; }
116924
- sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64);
116943
+ sqlite3VdbeAddInt64(v, iMem, value);
116925116944
}
116926116945
}
116927116946
}
116928116947
116929116948
@@ -117310,11 +117329,11 @@
117310117329
** A TRUE return does not guarantee that a subtype will be returned.
117311117330
** It only indicates that a subtype return is possible. False positives
117312117331
** are acceptable as they only disable an optimization. False negatives,
117313117332
** on the other hand, can lead to incorrect answers.
117314117333
*/
117315
-static int sqlite3ExprCanReturnSubtype(Parse *pParse, Expr *pExpr){
117334
+SQLITE_PRIVATE int sqlite3ExprCanReturnSubtype(Parse *pParse, Expr *pExpr){
117316117335
Walker w;
117317117336
memset(&w, 0, sizeof(w));
117318117337
w.pParse = pParse;
117319117338
w.xExprCallback = exprNodeCanReturnSubtype;
117320117339
sqlite3WalkExpr(&w, pExpr);
@@ -139361,29 +139380,17 @@
139361139380
sqlite3VdbeJumpHere(pParse->pVdbe, pItem->u4.pSubq->addrFillSub - 1);
139362139381
}
139363139382
}
139364139383
}
139365139384
139366
-/*
139367
-** Return true if all expressions in the expression-list passed as the
139368
-** only argument are constant.
139369
-*/
139370
-static int exprListIsConstant(Parse *pParse, ExprList *pRow){
139371
- int ii;
139372
- for(ii=0; ii<pRow->nExpr; ii++){
139373
- if( 0==sqlite3ExprIsConstant(pParse, pRow->a[ii].pExpr) ) return 0;
139374
- }
139375
- return 1;
139376
-}
139377
-
139378139385
/*
139379139386
** Return true if all expressions in the expression-list passed as the
139380139387
** only argument are both constant and have no affinity.
139381139388
*/
139382139389
static int exprListIsNoAffinity(Parse *pParse, ExprList *pRow){
139383139390
int ii;
139384
- if( exprListIsConstant(pParse,pRow)==0 ) return 0;
139391
+ if( sqlite3ExprListIsConstant(pParse, pRow, 0)==0 ) return 0;
139385139392
for(ii=0; ii<pRow->nExpr; ii++){
139386139393
Expr *pExpr = pRow->a[ii].pExpr;
139387139394
assert( pExpr->op!=TK_RAISE );
139388139395
assert( pExpr->affExpr==0 );
139389139396
if( 0!=sqlite3ExprAffinity(pExpr) ) return 0;
@@ -139445,11 +139452,11 @@
139445139452
*/
139446139453
SQLITE_PRIVATE Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){
139447139454
139448139455
if( pParse->bHasWith /* condition (a) above */
139449139456
|| pParse->db->init.busy /* condition (b) above */
139450
- || exprListIsConstant(pParse,pRow)==0 /* condition (c) above */
139457
+ || sqlite3ExprListIsConstant(pParse, pRow, 1)==0 /* condition (c) above */
139451139458
|| (pLeft->pSrc->nSrc==0 &&
139452139459
exprListIsNoAffinity(pParse,pLeft->pEList)==0) /* condition (d) above */
139453139460
|| IN_SPECIAL_PARSE
139454139461
){
139455139462
/* The co-routine method cannot be used. Fall back to UNION ALL. */
@@ -144968,11 +144975,11 @@
144968144975
144969144976
/*
144970144977
** Generate code to return a single integer value.
144971144978
*/
144972144979
static void returnSingleInt(Vdbe *v, i64 value){
144973
- sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64);
144980
+ sqlite3VdbeAddInt64(v, 1, value);
144974144981
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
144975144982
}
144976144983
144977144984
/*
144978144985
** Generate code to return a single text value.
@@ -153756,16 +153763,25 @@
153756153763
** Either EP_OuterON or EP_InnerON|EP_OuterON */
153757153764
Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */
153758153765
};
153759153766
153760153767
/*
153761
-** Add a new entry to the pConst object. Except, do not add duplicate
153762
-** pColumn entries. Also, do not add if doing so would not be appropriate.
153768
+** Add a new entry to the pConst object, if appropriate.
153763153769
**
153764
-** The caller guarantees the pColumn is a column and pValue is a constant.
153765
-** This routine has to do some additional checks before completing the
153766
-** insert.
153770
+** * Do not add if pValue is not constant. (This is enforced by
153771
+** the caller)
153772
+**
153773
+** * Do not add duplicate pColumn entries
153774
+**
153775
+** * Do not add if pValue has an affinity
153776
+**
153777
+** * Do not add if the comparison uses a collating sequence other
153778
+** than binary.
153779
+**
153780
+** * Do not add if pValue is a function that might return a subtype
153781
+**
153782
+** The caller guarantees the pColumn is a column.
153767153783
*/
153768153784
static void constInsert(
153769153785
WhereConst *pConst, /* The WhereConst into which we are inserting */
153770153786
Expr *pColumn, /* The COLUMN part of the constraint */
153771153787
Expr *pValue, /* The VALUE part of the constraint */
@@ -153772,16 +153788,16 @@
153772153788
Expr *pExpr /* Overall expression: COLUMN=VALUE or VALUE=COLUMN */
153773153789
){
153774153790
int i;
153775153791
assert( pColumn->op==TK_COLUMN );
153776153792
assert( sqlite3ExprIsConstant(pConst->pParse, pValue) );
153777
-
153778153793
if( ExprHasProperty(pColumn, EP_FixedCol) ) return;
153779153794
if( sqlite3ExprAffinity(pValue)!=0 ) return;
153780153795
if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) ){
153781153796
return;
153782153797
}
153798
+ if( sqlite3ExprCanReturnSubtype(pConst->pParse, pValue) ) return;
153783153799
153784153800
/* 2018-10-25 ticket [cf5ed20f]
153785153801
** Make sure the same pColumn is not inserted more than once */
153786153802
for(i=0; i<pConst->nConst; i++){
153787153803
const Expr *pE2 = pConst->apExpr[i*2];
@@ -158538,20 +158554,25 @@
158538158554
char *zName; /* Name of trigger */
158539158555
sqlite3 *db = pParse->db; /* The database */
158540158556
DbFixer sFix; /* Fixer object */
158541158557
int iDb; /* Database containing the trigger */
158542158558
Token nameToken; /* Trigger name for error reporting */
158559
+ i64 n; /* Number of steps */
158543158560
158544158561
pParse->pNewTrigger = 0;
158545158562
if( NEVER(pParse->nErr) || !pTrig ) goto triggerfinish_cleanup;
158546158563
zName = pTrig->zName;
158547158564
iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
158548158565
assert( iDb>=00 && iDb<db->nDb );
158549158566
pTrig->step_list = pStepList;
158550
- while( pStepList ){
158567
+ for(n=0; pStepList; n++){
158551158568
pStepList->pTrig = pTrig;
158552158569
pStepList = pStepList->pNext;
158570
+ }
158571
+ if( n>pParse->db->aLimit[SQLITE_LIMIT_TRIGGER_STEPS] ){
158572
+ sqlite3ErrorMsg(pParse, "trigger \"%w\" contains too many steps", zName);
158573
+ goto triggerfinish_cleanup;
158553158574
}
158554158575
sqlite3TokenInit(&nameToken, pTrig->zName);
158555158576
sqlite3FixInit(&sFix, pParse, iDb, "trigger", &nameToken);
158556158577
if( sqlite3FixTriggerStep(&sFix, pTrig->step_list)
158557158578
|| sqlite3FixExpr(&sFix, pTrig->pWhen)
@@ -164681,10 +164702,21 @@
164681164702
if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
164682164703
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
164683164704
}else{
164684164705
sqlite3 *db = pParse->db;
164685164706
Expr *pXMod = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
164707
+ if( nEq>1 ){
164708
+ /* If this IN(SELECT ...) expression drives more than one column of
164709
+ ** the index, disable the seek-scan optimization. The reasons for this
164710
+ ** are that (a) it is only possible to make this happen by populating
164711
+ ** the sqlite_stat1 table with inconsistent information, and (b) it
164712
+ ** would require sqlite3FindInIndex() to find an index that is not
164713
+ ** only unique for the columns in question, but also delivers them
164714
+ ** in sorted order (requires checking asc/desc, and rejecting cases
164715
+ ** where the indexed columns are not in the right order). */
164716
+ pLoop->wsFlags &= ~WHERE_IN_SEEKSCAN;
164717
+ }
164686164718
if( !db->mallocFailed ){
164687164719
aiMap = (int*)sqlite3DbMallocZero(db, sizeof(int)*nEq);
164688164720
eType = sqlite3FindInIndex(pParse, pXMod, IN_INDEX_LOOP, 0, aiMap, &iTab);
164689164721
}
164690164722
sqlite3ExprDelete(db, pXMod);
@@ -166895,21 +166927,29 @@
166895166927
pFrom = &uSrc.sSrc;
166896166928
pFrom->nSrc = 1;
166897166929
pFrom->nAlloc = 1;
166898166930
memcpy(&pFrom->a[0], pTabItem, sizeof(SrcItem));
166899166931
pFrom->a[0].fg.jointype = 0;
166900
- assert( pParse->withinRJSubrtn < 100 );
166932
+ if( pParse->withinRJSubrtn >= 100 ){
166933
+ /* This limit --------------^^^
166934
+ ** is based on an historical assert(). It is not compile-time or
166935
+ ** run-time configurable. It could perhaps be raised as high as 254,
166936
+ ** but only an attack robot would ever do even 100 RIGHT JOINS within
166937
+ ** a single query, so we'll just leave it as it is. */
166938
+ sqlite3ErrorMsg(pParse, "too many RIGHT JOINs");
166939
+ return;
166940
+ }
166901166941
pParse->withinRJSubrtn++;
166902166942
pSubWInfo = sqlite3WhereBegin(pParse, pFrom, pSubWhere, 0, 0, 0,
166903166943
WHERE_RIGHT_JOIN, 0);
166904166944
if( pSubWInfo ){
166905
- int iCur = pLevel->iTabCur;
166906
- int r = ++pParse->nMem;
166907
- int nPk;
166908
- int jmp = 0;
166945
+ int iCur = pLevel->iTabCur; /* Table on RHS of RIGHT JOIN &*/
166946
+ int r = ++pParse->nMem; /* Register range to hold primary key */
166947
+ int nPk; /* Number of values in the primary key */
166948
+ int r2; /* Register holding record for primary key */
166909166949
int addrCont = sqlite3WhereContinueLabel(pSubWInfo);
166910
- Table *pTab = pTabItem->pSTab;
166950
+ Table *pTab = pTabItem->pSTab; /* Table on RHS of RIGHT JOIN */
166911166951
if( HasRowid(pTab) ){
166912166952
sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, -1, r);
166913166953
nPk = 1;
166914166954
}else{
166915166955
int iPk;
@@ -166919,17 +166959,35 @@
166919166959
for(iPk=0; iPk<nPk; iPk++){
166920166960
int iCol = pPk->aiColumn[iPk];
166921166961
sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol,r+iPk);
166922166962
}
166923166963
}
166964
+
166965
+ /* Generate code that checks to see if the current row of the RHS table
166966
+ ** has appeared in any prior output row. */
166924166967
if( pRJ->regBloom ){
166925
- jmp = sqlite3VdbeAddOp4Int(v, OP_Filter, pRJ->regBloom, 0, r, nPk);
166968
+ sqlite3VdbeAddOp4Int(v, OP_Filter, pRJ->regBloom,
166969
+ sqlite3VdbeCurrentAddr(v)+2, r, nPk);
166926166970
VdbeCoverage(v);
166927166971
}
166928166972
sqlite3VdbeAddOp4Int(v, OP_Found, pRJ->iMatch, addrCont, r, nPk);
166929166973
VdbeCoverage(v);
166930
- if( jmp ) sqlite3VdbeJumpHere(v, jmp);
166974
+ r2 = sqlite3GetTempReg(pParse);
166975
+
166976
+ /* Generate code that inserts the PK of the RHS table into the
166977
+ ** pRH->iMatch index to indicate that the current row has appeared
166978
+ ** in the output set. */
166979
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, r, nPk, r2);
166980
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pRJ->iMatch, r2, r, nPk);
166981
+ sqlite3ReleaseTempReg(pParse, r2);
166982
+ if( pRJ->regBloom ){
166983
+ sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pRJ->regBloom, 0, r, nPk);
166984
+ sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
166985
+ }
166986
+
166987
+ /* Invoke the subroutine that actually puts the current RHS table row
166988
+ ** into the output set, with NULLs for the LHS. */
166931166989
sqlite3VdbeAddOp2(v, OP_Gosub, pRJ->regReturn, pRJ->addrSubrtn);
166932166990
sqlite3WhereEnd(pSubWInfo);
166933166991
}
166934166992
sqlite3ExprDelete(pParse->db, pSubWhere);
166935166993
ExplainQueryPlanPop(pParse);
@@ -176241,12 +176299,12 @@
176241176299
#endif
176242176300
{
176243176301
sqlite3VdbeChangeP5(v, bFordelete);
176244176302
}
176245176303
#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
176246
- sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, pTabItem->iCursor, 0, 0,
176247
- (const u8*)&pTabItem->colUsed, P4_INT64);
176304
+ sqlite3VdbeAddOp3(v, OP_ColumnsUsed, pTabItem->iCursor,
176305
+ LOWER32(pTabItem->colUsed), UPPER32(pTabItem->colUsed));
176248176306
#endif
176249176307
if( ii>=2
176250176308
&& (pTabItem[0].fg.jointype & (JT_LTORJ|JT_LEFT))==0
176251176309
&& pLevel->addrHalt==pWInfo->a[0].addrHalt
176252176310
){
@@ -176319,12 +176377,12 @@
176319176377
if( jj<0 ) continue;
176320176378
if( jj>63 ) jj = 63;
176321176379
if( (pTabItem->colUsed & MASKBIT(jj))==0 ) continue;
176322176380
colUsed |= ((u64)1)<<(ii<63 ? ii : 63);
176323176381
}
176324
- sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, iIndexCur, 0, 0,
176325
- (u8*)&colUsed, P4_INT64);
176382
+ sqlite3VdbeAddOp3(v, OP_ColumnsUsed, iIndexCur,
176383
+ LOWER32(colUsed),UPPER32(colUsed));
176326176384
}
176327176385
#endif /* SQLITE_ENABLE_COLUMN_USED_MASK */
176328176386
#ifdef SQLITE_ENABLE_CURSOR_HINTS
176329176387
if( HasRowid(pTab) ){
176330176388
sqlite3VdbeAddOp3(v, OP_CursorHint, iIndexCur, 0, pTabItem->iCursor);
@@ -190540,10 +190598,11 @@
190540190598
SQLITE_MAX_VARIABLE_NUMBER, /* IMP: R-38091-32352 */
190541190599
SQLITE_MAX_TRIGGER_DEPTH,
190542190600
SQLITE_MAX_WORKER_THREADS,
190543190601
SQLITE_MAX_PARSER_DEPTH,
190544190602
SQLITE_MAX_SCHEMA,
190603
+ SQLITE_MAX_TRIGGER_STEPS,
190545190604
};
190546190605
190547190606
/*
190548190607
** Make sure the hard limits are set to reasonable values
190549190608
*/
@@ -190580,10 +190639,13 @@
190580190639
#if SQLITE_MAX_TRIGGER_DEPTH<1
190581190640
# error SQLITE_MAX_TRIGGER_DEPTH must be at least 1
190582190641
#endif
190583190642
#if SQLITE_MAX_WORKER_THREADS<0 || SQLITE_MAX_WORKER_THREADS>50
190584190643
# error SQLITE_MAX_WORKER_THREADS must be between 0 and 50
190644
+#endif
190645
+#if SQLITE_MAX_TRIGGER_STEPS<0 || SQLITE_MAX_TRIGGER_STEPS>65535
190646
+# error SQLITE_MAX_TRIGGER_STEPS must be between 0 and 65535
190585190647
#endif
190586190648
190587190649
190588190650
/*
190589190651
** Change the value of a limit. Report the old value.
@@ -190623,11 +190685,12 @@
190623190685
SQLITE_MAX_LIKE_PATTERN_LENGTH );
190624190686
assert( aHardLimit[SQLITE_LIMIT_VARIABLE_NUMBER]==SQLITE_MAX_VARIABLE_NUMBER);
190625190687
assert( aHardLimit[SQLITE_LIMIT_TRIGGER_DEPTH]==SQLITE_MAX_TRIGGER_DEPTH );
190626190688
assert( aHardLimit[SQLITE_LIMIT_WORKER_THREADS]==SQLITE_MAX_WORKER_THREADS );
190627190689
assert( aHardLimit[SQLITE_LIMIT_SCHEMA]==SQLITE_MAX_SCHEMA );
190628
- assert( SQLITE_LIMIT_SCHEMA==(SQLITE_N_LIMIT-1) );
190690
+ assert( aHardLimit[SQLITE_LIMIT_TRIGGER_STEPS]==SQLITE_MAX_TRIGGER_STEPS );
190691
+ assert( SQLITE_LIMIT_TRIGGER_STEPS==(SQLITE_N_LIMIT-1) );
190629190692
190630190693
190631190694
if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
190632190695
return -1;
190633190696
}
@@ -200499,10 +200562,18 @@
200499200562
}
200500200563
200501200564
#define FTS4AUX_EQ_CONSTRAINT 1
200502200565
#define FTS4AUX_GE_CONSTRAINT 2
200503200566
#define FTS4AUX_LE_CONSTRAINT 4
200567
+
200568
+/*
200569
+** Return true if constraint iCons of pInfo uses the "binary" collation
200570
+** sequence. Or false it it uses anything else.
200571
+*/
200572
+static int fts3auxIsBinary(sqlite3_index_info *pInfo, int iCons){
200573
+ return 0==sqlite3_stricmp("binary", sqlite3_vtab_collation(pInfo, iCons));
200574
+}
200504200575
200505200576
/*
200506200577
** xBestIndex - Analyze a WHERE and ORDER BY clause.
200507200578
*/
200508200579
static int fts3auxBestIndexMethod(
@@ -200527,11 +200598,11 @@
200527200598
}
200528200599
200529200600
/* Search for equality and range constraints on the "term" column.
200530200601
** And equality constraints on the hidden "languageid" column. */
200531200602
for(i=0; i<pInfo->nConstraint; i++){
200532
- if( pInfo->aConstraint[i].usable ){
200603
+ if( pInfo->aConstraint[i].usable && fts3auxIsBinary(pInfo, i) ){
200533200604
int op = pInfo->aConstraint[i].op;
200534200605
int iCol = pInfo->aConstraint[i].iColumn;
200535200606
200536200607
if( iCol==0 ){
200537200608
if( op==SQLITE_INDEX_CONSTRAINT_EQ ) iEq = i;
@@ -200698,11 +200769,11 @@
200698200769
break;
200699200770
200700200771
/* State 3. The integer just read is a column number. */
200701200772
default: assert( eState==3 );
200702200773
iCol = (int)v;
200703
- if( iCol<1 || iCol>(pFts3->nColumn+1) ){
200774
+ if( iCol<1 || iCol>32767 ){
200704200775
rc = SQLITE_CORRUPT_VTAB;
200705200776
break;
200706200777
}
200707200778
if( fts3auxGrowStatArray(pCsr, iCol+2) ) return SQLITE_NOMEM;
200708200779
pCsr->aStat[iCol+1].nDoc++;
@@ -200773,21 +200844,21 @@
200773200844
memset(&pCsr->csr, 0, ((u8*)&pCsr[1]) - (u8*)&pCsr->csr);
200774200845
200775200846
pCsr->filter.flags = FTS3_SEGMENT_REQUIRE_POS|FTS3_SEGMENT_IGNORE_EMPTY;
200776200847
if( isScan ) pCsr->filter.flags |= FTS3_SEGMENT_SCAN;
200777200848
200778
- if( iEq>=0 || iGe>=0 ){
200849
+ if( (iEq>=0 || iGe>=0) && sqlite3_value_type(apVal[0])==SQLITE_TEXT ){
200779200850
const unsigned char *zStr = sqlite3_value_text(apVal[0]);
200780200851
assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) );
200781200852
if( zStr ){
200782200853
pCsr->filter.zTerm = sqlite3_mprintf("%s", zStr);
200783200854
if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM;
200784200855
pCsr->filter.nTerm = (int)strlen(pCsr->filter.zTerm);
200785200856
}
200786200857
}
200787200858
200788
- if( iLe>=0 ){
200859
+ if( iLe>=0 && sqlite3_value_type(apVal[0])==SQLITE_TEXT ){
200789200860
pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iLe]));
200790200861
if( pCsr->zStop==0 ) return SQLITE_NOMEM;
200791200862
pCsr->nStop = (int)strlen(pCsr->zStop);
200792200863
}
200793200864
@@ -210899,10 +210970,11 @@
210899210970
int nList; /* Number of phrases in expression */
210900210971
SnippetIter sIter; /* Iterates through snippet candidates */
210901210972
sqlite3_int64 nByte; /* Number of bytes of space to allocate */
210902210973
int iBestScore = -1; /* Best snippet score found so far */
210903210974
int i; /* Loop counter */
210975
+ Fts3Expr *pExpr = pCsr->pExpr;
210904210976
210905210977
memset(&sIter, 0, sizeof(sIter));
210906210978
210907210979
/* Iterate through the phrases in the expression to count them. The same
210908210980
** callback makes sure the doclists are loaded for each phrase.
@@ -210927,13 +210999,16 @@
210927210999
sIter.pCsr = pCsr;
210928211000
sIter.iCol = iCol;
210929211001
sIter.nSnippet = nSnippet;
210930211002
sIter.nPhrase = nList;
210931211003
sIter.iCurrent = -1;
210932
- rc = sqlite3Fts3ExprIterate(
210933
- pCsr->pExpr, fts3SnippetFindPositions, (void*)&sIter
210934
- );
211004
+ rc = sqlite3Fts3ExprIterate(pExpr, fts3SnippetFindPositions, (void*)&sIter);
211005
+ if( rc==SQLITE_OK ){
211006
+ /* Iterate through the expression twice, in case pointers garnered during
211007
+ ** the first iteration are invalidated by a call to fts5EvalRestart(). */
211008
+ rc = sqlite3Fts3ExprIterate(pExpr, fts3SnippetFindPositions, (void*)&sIter);
211009
+ }
210935211010
if( rc==SQLITE_OK ){
210936211011
210937211012
/* Set the *pmSeen output variable. */
210938211013
for(i=0; i<nList; i++){
210939211014
if( sIter.aPhrase[i].pHead ){
@@ -215052,16 +215127,129 @@
215052215127
assert( !px.bReadOnly );
215053215128
sqlite3_result_blob(pStr->pCtx, px.aBlob, px.nBlob, SQLITE_DYNAMIC);
215054215129
}
215055215130
}
215056215131
215057
-/* The byte at index i is a node type-code. This routine
215132
+/*
215133
+** This a helper routine for jsonbPayloadSize() and
215134
+** jsonbPayloadSizeSemiInline(). This routine is called using tail
215135
+** recursion to handle the (relatively uncommon) cases where the
215136
+** the payload size is a 2, 4, or 8 byte integer.
215137
+*/
215138
+static u32 jsonbPayloadSizeWide(
215139
+ const JsonParse *pParse, /* JSON parsing context */
215140
+ u32 i, /* Index of the node type-code */
215141
+ u32 *pSz, /* Write payload size here */
215142
+ u8 x /* pParse->aBlob[i]>>4 */
215143
+){
215144
+ u32 sz;
215145
+ u32 n;
215146
+ assert( i<pParse->nBlob );
215147
+ assert( x==(pParse->aBlob[i]>>4) );
215148
+ assert( x>=13 );
215149
+ if( x==13 ){
215150
+ if( i+2>=pParse->nBlob ){
215151
+ *pSz = 0;
215152
+ return 0;
215153
+ }
215154
+ sz = (pParse->aBlob[i+1]<<8) + pParse->aBlob[i+2];
215155
+ n = 3;
215156
+ }else if( x==14 ){
215157
+ if( i+4>=pParse->nBlob ){
215158
+ *pSz = 0;
215159
+ return 0;
215160
+ }
215161
+ sz = ((u32)pParse->aBlob[i+1]<<24) + (pParse->aBlob[i+2]<<16) +
215162
+ (pParse->aBlob[i+3]<<8) + pParse->aBlob[i+4];
215163
+ n = 5;
215164
+ }else{
215165
+ if( i+8>=pParse->nBlob
215166
+ || pParse->aBlob[i+1]!=0
215167
+ || pParse->aBlob[i+2]!=0
215168
+ || pParse->aBlob[i+3]!=0
215169
+ || pParse->aBlob[i+4]!=0
215170
+ ){
215171
+ *pSz = 0;
215172
+ return 0;
215173
+ }
215174
+ sz = ((u32)pParse->aBlob[i+5]<<24) + (pParse->aBlob[i+6]<<16) +
215175
+ (pParse->aBlob[i+7]<<8) + pParse->aBlob[i+8];
215176
+ n = 9;
215177
+ }
215178
+ testcase( (i64)i+sz+n > pParse->nBlob );
215179
+ testcase( (i64)i+sz+n > pParse->nBlob-pParse->delta
215180
+ && (i64)i+sz+n > pParse->nBlob );
215181
+ testcase( pParse->delta>0 );
215182
+ testcase( pParse->delta<0 );
215183
+ /* Quirks with -Os and gcov cause the NO_TEST line below to show up as
215184
+ ** false-positive coverage miss. The testcases() macros above are
215185
+ ** sufficient to prove that the branch is in fact covered */
215186
+ if( (i64)i+sz+n > pParse->nBlob
215187
+ && (i64)i+sz+n > pParse->nBlob-pParse->delta /*NO_TEST*/
215188
+ ){
215189
+ *pSz = 0;
215190
+ return 0;
215191
+ }
215192
+ *pSz = sz;
215193
+ return n;
215194
+}
215195
+
215196
+/*
215197
+** This is the main routine for determining the size of a node in JSONB.
215198
+** The jsonbPayloadSizeWide() above is a helper. The two routines
215199
+** jsonbPayloadSizeInline() and jsonbPayloadSizeSemiInline() below are
215200
+** optional optimizations. It is important to keep all these routines in
215201
+** sync. Agents reading this code: Help us humans to remember that!
215202
+**
215203
+** The byte at index i is a node type-code. This routine
215058215204
** determines the payload size for that node and writes that
215059215205
** payload size in to *pSz. It returns the offset from i to the
215060215206
** beginning of the payload. Return 0 on error.
215061215207
*/
215062
-static u32 jsonbPayloadSize(const JsonParse *pParse, u32 i, u32 *pSz){
215208
+static u32 jsonbPayloadSize(
215209
+ const JsonParse *pParse, /* JSON parsing context */
215210
+ u32 i, /* Index of the node type-code */
215211
+ u32 *pSz /* Write payload size here */
215212
+){
215213
+ u8 x;
215214
+ u32 sz;
215215
+ u32 n;
215216
+ if( i>=pParse->nBlob ){
215217
+ *pSz = 0;
215218
+ return 0;
215219
+ }else if( (x = pParse->aBlob[i]>>4)<=11 ){
215220
+ sz = x;
215221
+ n = 1;
215222
+ }else if( x==12 ){
215223
+ if( i+1>=pParse->nBlob ){
215224
+ *pSz = 0;
215225
+ return 0;
215226
+ }
215227
+ sz = pParse->aBlob[i+1];
215228
+ n = 2;
215229
+ }else{
215230
+ return jsonbPayloadSizeWide(pParse, i, pSz, x);
215231
+ }
215232
+ if( (i64)i+sz+n > pParse->nBlob
215233
+ && (i64)i+sz+n > pParse->nBlob-pParse->delta
215234
+ ){
215235
+ *pSz = 0;
215236
+ return 0;
215237
+ }
215238
+ *pSz = sz;
215239
+ return n;
215240
+}
215241
+
215242
+#if SQLITE_USES_INLINE
215243
+/* A separate inline version of jsonbPayloadSize(), used in one particulary
215244
+** performance-critical place.
215245
+*/
215246
+static SQLITE_INLINE u32 jsonbPayloadSizeInline(
215247
+ const JsonParse *pParse, /* JSON parsing context */
215248
+ u32 i, /* Index of the node type-code */
215249
+ u32 *pSz /* Write payload size here */
215250
+){
215063215251
u8 x;
215064215252
u32 sz;
215065215253
u32 n;
215066215254
if( i>=pParse->nBlob ){
215067215255
*pSz = 0;
@@ -215112,11 +215300,65 @@
215112215300
return 0;
215113215301
}
215114215302
*pSz = sz;
215115215303
return n;
215116215304
}
215305
+#else /* if !SQLITE_USES_INLINE */
215306
+ /* On compilers that do not support in-lining, just call the original
215307
+ ** jsonbPayloadSize(). It's slower, but it gets the right answer. */
215308
+# define jsonbPayloadSizeInline(a,b,c) jsonbPayloadSize(a,b,c)
215309
+#endif
215117215310
215311
+
215312
+#if SQLITE_USES_INLINE
215313
+/* A separate inline version of jsonbPayloadSize() that implements the more
215314
+** common paths inline but then calls out to a subroutine for the uncommon
215315
+** paths.
215316
+**
215317
+** * It is guaranteed that the i parameter is a valid index for
215318
+** pParse->aBlob[]. There is no possibility of running of the end
215319
+** of the allocation.
215320
+**
215321
+** * Large sizes (greater than 255) are uncommon and are handled
215322
+** by a subroutine call to the jsonbPayloadSizeWide().
215323
+*/
215324
+static SQLITE_INLINE u32 jsonbPayloadSizeSemiInline(
215325
+ const JsonParse *pParse, /* JSON parsing context */
215326
+ u32 i, /* Index of the node type-code */
215327
+ u32 *pSz /* Write payload size here */
215328
+){
215329
+ u8 x;
215330
+ u32 sz;
215331
+ u32 n;
215332
+ assert( i<pParse->nBlob );
215333
+ if( (x = pParse->aBlob[i]>>4)<=11 ){
215334
+ sz = x;
215335
+ n = 1;
215336
+ }else if( x==12 ){
215337
+ if( i+1>=pParse->nBlob ){
215338
+ *pSz = 0;
215339
+ return 0;
215340
+ }
215341
+ sz = pParse->aBlob[i+1];
215342
+ n = 2;
215343
+ }else{
215344
+ return jsonbPayloadSizeWide(pParse,i,pSz,x);
215345
+ }
215346
+ if( (i64)i+sz+n > pParse->nBlob
215347
+ && (i64)i+sz+n > pParse->nBlob-pParse->delta
215348
+ ){
215349
+ *pSz = 0;
215350
+ return 0;
215351
+ }
215352
+ *pSz = sz;
215353
+ return n;
215354
+}
215355
+#else /* if !SQLITE_USES_INLINE */
215356
+ /* On compilers that do not support in-lining, just call the original
215357
+ ** jsonbPayloadSize(). It's slower, but it gets the right answer. */
215358
+# define jsonbPayloadSizeSemiInline(a,b,c) jsonbPayloadSize(a,b,c)
215359
+#endif
215118215360
215119215361
/*
215120215362
** Translate the binary JSONB representation of JSON beginning at
215121215363
** pParse->aBlob[i] into a JSON text string. Append the JSON
215122215364
** text onto the end of pOut. Return the index in pParse->aBlob[]
@@ -215134,11 +215376,11 @@
215134215376
u32 i, /* Start rendering at this index */
215135215377
JsonString *pOut /* Write JSON here */
215136215378
){
215137215379
u32 sz, n, j, iEnd;
215138215380
215139
- n = jsonbPayloadSize(pParse, i, &sz);
215381
+ n = jsonbPayloadSizeInline(pParse, i, &sz);
215140215382
if( n==0 ){
215141215383
pOut->eErr |= JSTRING_MALFORMED;
215142215384
return pParse->nBlob+1;
215143215385
}
215144215386
switch( pParse->aBlob[i] & 0x0f ){
@@ -215474,11 +215716,11 @@
215474215716
u32 n, sz, i, iEnd;
215475215717
u32 k = 0;
215476215718
n = jsonbPayloadSize(pParse, iRoot, &sz);
215477215719
iEnd = iRoot+n+sz;
215478215720
for(i=iRoot+n; n>0 && i<iEnd; i+=sz+n, k++){
215479
- n = jsonbPayloadSize(pParse, i, &sz);
215721
+ n = jsonbPayloadSizeSemiInline(pParse, i, &sz);
215480215722
}
215481215723
return k;
215482215724
}
215483215725
215484215726
/*
@@ -215984,11 +216226,11 @@
215984216226
while( j<iEnd ){
215985216227
int rawLabel;
215986216228
const char *zLabel;
215987216229
x = pParse->aBlob[j] & 0x0f;
215988216230
if( x<JSONB_TEXT || x>JSONB_TEXTRAW ) return JSON_LOOKUP_ERROR;
215989
- n = jsonbPayloadSize(pParse, j, &sz);
216231
+ n = jsonbPayloadSizeSemiInline(pParse, j, &sz);
215990216232
if( n==0 ) return JSON_LOOKUP_ERROR;
215991216233
k = j+n; /* k is the index of the label text */
215992216234
if( k+sz>=iEnd ) return JSON_LOOKUP_ERROR;
215993216235
zLabel = (const char*)&pParse->aBlob[k];
215994216236
rawLabel = x==JSONB_TEXT || x==JSONB_TEXTRAW;
@@ -216006,11 +216248,11 @@
216006216248
if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
216007216249
return rc;
216008216250
}
216009216251
j = k+sz;
216010216252
if( ((pParse->aBlob[j])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
216011
- n = jsonbPayloadSize(pParse, j, &sz);
216253
+ n = jsonbPayloadSizeSemiInline(pParse, j, &sz);
216012216254
if( n==0 ) return JSON_LOOKUP_ERROR;
216013216255
j += n+sz;
216014216256
}
216015216257
if( j>iEnd ) return JSON_LOOKUP_ERROR;
216016216258
if( pParse->eEdit>=JEDIT_INS ){
@@ -216095,11 +216337,11 @@
216095216337
pParse->iDepth--;
216096216338
if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
216097216339
return rc;
216098216340
}
216099216341
kk--;
216100
- n = jsonbPayloadSize(pParse, j, &sz);
216342
+ n = jsonbPayloadSizeSemiInline(pParse, j, &sz);
216101216343
if( n==0 ) return JSON_LOOKUP_ERROR;
216102216344
j += n+sz;
216103216345
}
216104216346
if( j>iEnd ) return JSON_LOOKUP_ERROR;
216105216347
if( kk>0 ) return JSON_LOOKUP_NOTFOUND;
@@ -223583,10 +223825,12 @@
223583223825
/*
223584223826
** Function: geopoly_regular(X,Y,R,N)
223585223827
**
223586223828
** Construct a simple, convex, regular polygon centered at X, Y
223587223829
** with circumradius R and with N sides.
223830
+**
223831
+** Maximum N is 1000. Maximum R is 1.0e+300.
223588223832
*/
223589223833
static void geopolyRegularFunc(
223590223834
sqlite3_context *context,
223591223835
int argc,
223592223836
sqlite3_value **argv
@@ -223597,11 +223841,11 @@
223597223841
int n = sqlite3_value_int(argv[3]);
223598223842
int i;
223599223843
GeoPoly *p;
223600223844
(void)argc;
223601223845
223602
- if( n<3 || r<=0.0 ) return;
223846
+ if( n<3 || r<=0.0 || r>=1e300 ) return;
223603223847
if( n>1000 ) n = 1000;
223604223848
p = sqlite3_malloc64( sizeof(*p) + (n-1)*2*sizeof(GeoCoord) );
223605223849
if( p==0 ){
223606223850
sqlite3_result_error_nomem(context);
223607223851
return;
@@ -233626,12 +233870,18 @@
233626233870
return SQLITE_OK;
233627233871
}
233628233872
default: {
233629233873
const struct iovec *p = (struct iovec*)pCur->pPtr;
233630233874
assert( pCur->eType==CARRAY_BLOB );
233631
- sqlite3_result_blob(ctx, p[pCur->iRowid-1].iov_base,
233632
- (int)p[pCur->iRowid-1].iov_len, SQLITE_TRANSIENT);
233875
+ p += pCur->iRowid-1;
233876
+ if( p->iov_len>0x7fffffff ){
233877
+ sqlite3_result_error_toobig(ctx);
233878
+ return SQLITE_TOOBIG;
233879
+ }else{
233880
+ sqlite3_result_blob(ctx, p->iov_base, (int)p->iov_len,
233881
+ SQLITE_TRANSIENT);
233882
+ }
233633233883
return SQLITE_OK;
233634233884
}
233635233885
}
233636233886
}
233637233887
}
@@ -239561,14 +239811,14 @@
239561239811
int flags /* SESSION_APPLY_XXX flags */
239562239812
){
239563239813
int schemaMismatch = 0;
239564239814
int rc = SQLITE_OK; /* Return code */
239565239815
const char *zTab = 0; /* Name of current table */
239566
- int nTab = 0; /* Result of sqlite3Strlen30(zTab) */
239567239816
SessionApplyCtx sApply; /* changeset_apply() context object */
239568239817
int bPatchset;
239569239818
u64 savedFlag = db->flags & SQLITE_FkNoAction;
239819
+ int bNew = 0; /* True for first entry of new table */
239570239820
239571239821
assert( xConflict!=0 );
239572239822
239573239823
sqlite3_mutex_enter(sqlite3_db_mutex(db));
239574239824
if( flags & SQLITE_CHANGESETAPPLY_FKNOACTION ){
@@ -239586,19 +239836,20 @@
239586239836
rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0);
239587239837
}
239588239838
if( rc==SQLITE_OK ){
239589239839
rc = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 1", 0, 0, 0);
239590239840
}
239591
- while( rc==SQLITE_OK && SQLITE_ROW==sqlite3changeset_next(pIter) ){
239841
+ while( rc==SQLITE_OK && SQLITE_ROW==sessionChangesetNext(pIter, 0, 0,&bNew) ){
239592239842
int nCol;
239593239843
int op;
239594239844
const char *zNew;
239595239845
239596239846
sqlite3changeset_op(pIter, &zNew, &nCol, &op, 0);
239597239847
239598
- if( zTab==0 || sqlite3_strnicmp(zNew, zTab, nTab+1) ){
239848
+ if( bNew ){
239599239849
u8 *abPK;
239850
+ bNew = 0;
239600239851
239601239852
rc = sessionRetryConstraints(
239602239853
db, pIter->bPatchset, zTab, &sApply, xConflict, pCtx
239603239854
);
239604239855
if( rc!=SQLITE_OK ) break;
@@ -239629,11 +239880,10 @@
239629239880
zTab = sqlite3_mprintf("%s", zNew);
239630239881
if( zTab==0 ){
239631239882
rc = SQLITE_NOMEM;
239632239883
break;
239633239884
}
239634
- nTab = (int)strlen(zTab);
239635239885
sApply.azCol = (const char **)zTab;
239636239886
}else{
239637239887
int nMinCol = 0;
239638239888
int i;
239639239889
@@ -239682,11 +239932,10 @@
239682239932
break;
239683239933
}
239684239934
sApply.bStat1 = 0;
239685239935
}
239686239936
}
239687
- nTab = sqlite3Strlen30(zTab);
239688239937
}
239689239938
}
239690239939
239691239940
/* If there is a schema mismatch on the current table, proceed to the
239692239941
** next change. A log message has already been issued. */
@@ -251353,11 +251602,16 @@
251353251602
** sequentially starting from 1.
251354251603
*/
251355251604
#define FTS5_DATA_ID_B 16 /* Max seg id number 65535 */
251356251605
#define FTS5_DATA_DLI_B 1 /* Doclist-index flag (1 bit) */
251357251606
#define FTS5_DATA_HEIGHT_B 5 /* Max dlidx tree height of 32 */
251358
-#define FTS5_DATA_PAGE_B 31 /* Max page number of 2147483648 */
251607
+#define FTS5_DATA_PAGE_B 31 /* 31-bit page numbers */
251608
+
251609
+/* Maximum page number within a segment. Declare any structure read from
251610
+** the database with a page number greater than this corrupt. It is not
251611
+** actually possible to create a database this large. */
251612
+#define FTS5_MAX_PGNO 0x7FFFFF00
251359251613
251360251614
#define fts5_dri(segid, dlidx, height, pgno) ( \
251361251615
((i64)(segid) << (FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B)) + \
251362251616
((i64)(dlidx) << (FTS5_DATA_PAGE_B + FTS5_DATA_HEIGHT_B)) + \
251363251617
((i64)(height) << (FTS5_DATA_PAGE_B)) + \
@@ -252266,11 +252520,11 @@
252266252520
i += fts5GetVarint32(&pData[i], pSeg->nPgTombstone);
252267252521
i += fts5GetVarint(&pData[i], &pSeg->nEntryTombstone);
252268252522
i += fts5GetVarint(&pData[i], &pSeg->nEntry);
252269252523
nOriginCntr = MAX(nOriginCntr, pSeg->iOrigin2);
252270252524
}
252271
- if( pSeg->pgnoLast<pSeg->pgnoFirst ){
252525
+ if( pSeg->pgnoLast<pSeg->pgnoFirst || pSeg->pgnoLast>FTS5_MAX_PGNO ){
252272252526
rc = FTS5_CORRUPT;
252273252527
break;
252274252528
}
252275252529
}
252276252530
if( iLvl>0 && pLvl[-1].nMerge && nTotal==0 ) rc = FTS5_CORRUPT;
@@ -252862,10 +253116,13 @@
252862253116
pLvl->pData = fts5DataRead(p, iRowid);
252863253117
if( pLvl->pData && (pLvl->pData->p[0] & 0x0001)==0 ){
252864253118
bDone = 1;
252865253119
}
252866253120
pIter->nLvl = i+1;
253121
+ if( pIter->nLvl > (1<<FTS5_DATA_HEIGHT_B) ){
253122
+ p->rc = FTS5_CORRUPT;
253123
+ }
252867253124
}
252868253125
}
252869253126
252870253127
if( p->rc==SQLITE_OK ){
252871253128
pIter->iSegid = iSegid;
@@ -256583,38 +256840,42 @@
256583256840
** iNextOff: Offset to move data from
256584256841
*/
256585256842
if( p->rc==SQLITE_OK ){
256586256843
const int nMove = nPg - iNextOff; /* Number of bytes to move */
256587256844
int nShift = iNextOff - iOff; /* Distance to move them */
256588
-
256845
+ int nNewPg = 0;
256589256846
int iPrevKeyOut = 0;
256590
- int iKeyIn = 0;
256847
+ i64 iKeyIn = 0;
256591256848
256592256849
if( nMove>0 ){
256593256850
memmove(&aPg[iOff], &aPg[iNextOff], nMove);
256594256851
}
256595256852
iPgIdx -= nShift;
256596
- nPg = iPgIdx;
256853
+ nNewPg = iPgIdx;
256597256854
fts5PutU16(&aPg[2], iPgIdx);
256598256855
256599256856
for(iIdx=0; iIdx<nIdx; /* no-op */){
256600256857
u32 iVal = 0;
256601256858
iIdx += fts5GetVarint32(&aIdx[iIdx], iVal);
256602256859
iKeyIn += iVal;
256860
+ if( iKeyIn>nPg ){
256861
+ FTS5_CORRUPT_IDX(p);
256862
+ break;
256863
+ }
256603256864
if( iKeyIn!=iDelKeyOff ){
256604256865
int iKeyOut = (iKeyIn - (iKeyIn>iOff ? nShift : 0));
256605
- nPg += sqlite3Fts5PutVarint(&aPg[nPg], iKeyOut - iPrevKeyOut);
256866
+ nNewPg += sqlite3Fts5PutVarint(&aPg[nNewPg], iKeyOut - iPrevKeyOut);
256606256867
iPrevKeyOut = iKeyOut;
256607256868
}
256608256869
}
256609256870
256610
- if( iPgIdx==nPg && nIdx>0 && pSeg->iLeafPgno!=1 ){
256871
+ if( p->rc==SQLITE_OK && iPgIdx==nNewPg && nIdx>0 && pSeg->iLeafPgno!=1 ){
256611256872
fts5SecureDeleteIdxEntry(p, iSegid, pSeg->iLeafPgno);
256612256873
}
256613256874
256614
- assert_nc( nPg>4 || fts5GetU16(aPg)==0 );
256615
- fts5DataWrite(p, FTS5_SEGMENT_ROWID(iSegid,pSeg->iLeafPgno), aPg, nPg);
256875
+ assert_nc( nNewPg>4 || fts5GetU16(aPg)==0 );
256876
+ fts5DataWrite(p, FTS5_SEGMENT_ROWID(iSegid,pSeg->iLeafPgno), aPg, nNewPg);
256616256877
}
256617256878
sqlite3_free(aIdx);
256618256879
}
256619256880
256620256881
/*
@@ -264272,11 +264533,11 @@
264272264533
int nArg, /* Number of args */
264273264534
sqlite3_value **apUnused /* Function arguments */
264274264535
){
264275264536
assert( nArg==0 );
264276264537
UNUSED_PARAM2(nArg, apUnused);
264277
- sqlite3_result_text(pCtx, "fts5: 2026-08-11 10:46:12 fee71cd6f7294ffd02784d26811a9d11d80e83d4075e1233b8ec0289519bb891", -1, SQLITE_TRANSIENT);
264538
+ sqlite3_result_text(pCtx, "fts5: 2026-08-20 13:25:12 3bd5456e50ef321f2cafcf67261d556a760624ce0caab430ed9454cebec233e7", -1, SQLITE_TRANSIENT);
264278264539
}
264279264540
264280264541
/*
264281264542
** Implementation of fts5_locale(LOCALE, TEXT) function.
264282264543
**
@@ -268951,10 +269212,18 @@
268951269212
sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */
268952269213
char **pzErr /* OUT: sqlite3_malloc'd error message */
268953269214
){
268954269215
return fts5VocabInitVtab(db, pAux, argc, argv, ppVtab, pzErr);
268955269216
}
269217
+
269218
+/*
269219
+** Return true if constraint iCons of pInfo uses the "binary" collation
269220
+** sequence. Or false it it uses anything else.
269221
+*/
269222
+static int fts5VocabIsBinary(sqlite3_index_info *pInfo, int iCons){
269223
+ return 0==sqlite3_stricmp("binary", sqlite3_vtab_collation(pInfo, iCons));
269224
+}
268956269225
268957269226
/*
268958269227
** Implementation of the xBestIndex method.
268959269228
**
268960269229
** Only constraints of the form:
@@ -268982,11 +269251,11 @@
268982269251
assert( (pInfo->colUsed & FTS5_VOCAB_COLUSED_MASK)==pInfo->colUsed );
268983269252
268984269253
for(i=0; i<pInfo->nConstraint; i++){
268985269254
struct sqlite3_index_constraint *p = &pInfo->aConstraint[i];
268986269255
if( p->usable==0 ) continue;
268987
- if( p->iColumn==0 ){ /* term column */
269256
+ if( p->iColumn==0 && fts5VocabIsBinary(pInfo, i) ){ /* term column */
268988269257
if( p->op==SQLITE_INDEX_CONSTRAINT_EQ ) iTermEq = i;
268989269258
if( p->op==SQLITE_INDEX_CONSTRAINT_LE ) iTermLe = i;
268990269259
if( p->op==SQLITE_INDEX_CONSTRAINT_LT ) iTermLe = i;
268991269260
if( p->op==SQLITE_INDEX_CONSTRAINT_GE ) iTermGe = i;
268992269261
if( p->op==SQLITE_INDEX_CONSTRAINT_GT ) iTermGe = i;
@@ -269320,10 +269589,30 @@
269320269589
rc = FTS5_CORRUPT;
269321269590
}
269322269591
}
269323269592
return rc;
269324269593
}
269594
+
269595
+/*
269596
+** If value pVal is an SQLITE_TEXT value, return a pointer to a buffer
269597
+** containing the UTF-8 representation of the value, and set output
269598
+** parameter (*pnText) to the size of the buffer contents in bytes. Or,
269599
+** if pVal is some other type of value, return NULL and set (*pnText)
269600
+** to 0 before returning.
269601
+*/
269602
+static const char *fts5VocabValueText(sqlite3_value *pVal, int *pnText){
269603
+ const char *zRet = 0;
269604
+ int nRet = 0;
269605
+
269606
+ if( sqlite3_value_type(pVal)==SQLITE_TEXT ){
269607
+ zRet = (const char*)sqlite3_value_text(pVal);
269608
+ nRet = sqlite3_value_bytes(pVal);
269609
+ }
269610
+
269611
+ *pnText = nRet;
269612
+ return zRet;
269613
+}
269325269614
269326269615
/*
269327269616
** This is the xFilter implementation for the virtual table.
269328269617
*/
269329269618
static int fts5VocabFilterMethod(
@@ -269354,22 +269643,19 @@
269354269643
if( idxNum & FTS5_VOCAB_TERM_GE ) pGe = apVal[iVal++];
269355269644
if( idxNum & FTS5_VOCAB_TERM_LE ) pLe = apVal[iVal++];
269356269645
pCsr->colUsed = (idxNum & FTS5_VOCAB_COLUSED_MASK);
269357269646
269358269647
if( pEq ){
269359
- zTerm = (const char *)sqlite3_value_text(pEq);
269360
- nTerm = sqlite3_value_bytes(pEq);
269648
+ zTerm = fts5VocabValueText(pEq, &nTerm);
269361269649
f = FTS5INDEX_QUERY_NOTOKENDATA;
269362269650
}else{
269363269651
if( pGe ){
269364
- zTerm = (const char *)sqlite3_value_text(pGe);
269365
- nTerm = sqlite3_value_bytes(pGe);
269652
+ zTerm = fts5VocabValueText(pGe, &nTerm);
269366269653
}
269367269654
if( pLe ){
269368
- const char *zCopy = (const char *)sqlite3_value_text(pLe);
269655
+ const char *zCopy = fts5VocabValueText(pLe, &pCsr->nLeTerm);
269369269656
if( zCopy==0 ) zCopy = "";
269370
- pCsr->nLeTerm = sqlite3_value_bytes(pLe);
269371269657
pCsr->zLeTerm = sqlite3_malloc64((i64)pCsr->nLeTerm+1);
269372269658
if( pCsr->zLeTerm==0 ){
269373269659
rc = SQLITE_NOMEM;
269374269660
}else{
269375269661
memcpy(pCsr->zLeTerm, zCopy, pCsr->nLeTerm+1);
269376269662
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -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 ** fee71cd6f7294ffd02784d26811a9d11d80e with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
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-08-11 10:46:12 fee71cd6f7294ffd02784d26811a9d11d80e83d4075e1233b8ec0289519bb891"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-08-11T10:46:12.896Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -4755,10 +4755,14 @@
4755 ** [prepared statement] may start.</dd>)^
4756 **
4757 ** [[SQLITE_LIMIT_SCHEMA]] ^(<dt>SQLITE_LIMIT_SCHEMA</dt>
4758 ** <dd>The maximum number of objects (tables, indexes, triggers, and views)
4759 ** defined by the database schema.</dd>)^
 
 
 
 
4760 ** </dl>
4761 */
4762 #define SQLITE_LIMIT_LENGTH 0
4763 #define SQLITE_LIMIT_SQL_LENGTH 1
4764 #define SQLITE_LIMIT_COLUMN 2
@@ -4771,10 +4775,11 @@
4771 #define SQLITE_LIMIT_VARIABLE_NUMBER 9
4772 #define SQLITE_LIMIT_TRIGGER_DEPTH 10
4773 #define SQLITE_LIMIT_WORKER_THREADS 11
4774 #define SQLITE_LIMIT_PARSER_DEPTH 12
4775 #define SQLITE_LIMIT_SCHEMA 13
 
4776
4777 /*
4778 ** CAPI3REF: Prepare Flags
4779 **
4780 ** These constants define various flags that can be passed into the
@@ -15067,10 +15072,18 @@
15067 */
15068 #ifndef SQLITE_MAX_SCHEMA
15069 # define SQLITE_MAX_SCHEMA 10000000
15070 #endif
15071
 
 
 
 
 
 
 
 
15072 /************** End of sqliteLimit.h *****************************************/
15073 /************** Continuing where we left off in sqliteInt.h ******************/
15074
15075 /* Disable nuisance warnings on Borland compilers */
15076 #if defined(__BORLANDC__)
@@ -15143,29 +15156,42 @@
15143 **
15144 ** SQLITE_INLINE Strive to in-line this function
15145 **
15146 ** SQLITE_OPT_INLINE In-line this function if building the
15147 ** amalgamation.
 
 
 
15148 */
15149 #if defined(__GNUC__)
 
 
 
 
 
15150 # define SQLITE_NOINLINE __attribute__((noinline))
15151 # define SQLITE_INLINE __attribute__((always_inline)) inline
15152 # define SQLITE_OPT_INLINE __attribute__((always_inline)) inline
 
15153 #elif defined(_MSC_VER) && _MSC_VER>=1310
15154 # define SQLITE_NOINLINE __declspec(noinline)
15155 # define SQLITE_INLINE __forceinline
15156 # define SQLITE_OPT_INLINE __forceinline
 
15157 #else
15158 # define SQLITE_NOINLINE
15159 # define SQLITE_INLINE
15160 # define SQLITE_OPT_INLINE
 
15161 #endif
15162 #if defined(SQLITE_COVERAGE_TEST) || defined(__STRICT_ANSI__)
15163 # undef SQLITE_INLINE
15164 # define SQLITE_INLINE
15165 # undef SQLITE_OPT_INLINE
15166 # define SQLITE_OPT_INLINE
 
 
15167 #endif
15168 #if !defined(SQLITE_AMALGAMATION)
15169 # undef SQLITE_OPT_INLINE
15170 # define SQLITE_OPT_INLINE
15171 #endif
@@ -17694,12 +17720,10 @@
17694 int p3; /* The third parameter */
17695 union p4union { /* fourth parameter */
17696 int i; /* Integer value if p4type==P4_INT32 */
17697 void *p; /* Generic pointer */
17698 char *z; /* Pointer to data for string (char array) types */
17699 i64 *pI64; /* Used when p4type is P4_INT64 */
17700 double *pReal; /* Used when p4type is P4_REAL */
17701 FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */
17702 sqlite3_context *pCtx; /* Used when p4type is P4_FUNCCTX */
17703 CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
17704 Mem *pMem; /* Used when p4type is P4_MEM */
17705 VTable *pVtab; /* Used when p4type is P4_VTAB */
@@ -17750,10 +17774,23 @@
17750 signed char p1; /* First operand */
17751 signed char p2; /* Second parameter (often the jump destination) */
17752 signed char p3; /* Third parameter */
17753 };
17754 typedef struct VdbeOpList VdbeOpList;
 
 
 
 
 
 
 
 
 
 
 
 
 
17755
17756 /*
17757 ** Allowed values of VdbeOp.p4type
17758 */
17759 #define P4_NOTUSED 0 /* The P4 parameter is not used */
@@ -17770,16 +17807,14 @@
17770 #define P4_FUNCDEF (-8) /* P4 is a pointer to a FuncDef structure */
17771 #define P4_KEYINFO (-9) /* P4 is a pointer to a KeyInfo structure */
17772 #define P4_EXPR (-10) /* P4 is a pointer to an Expr tree */
17773 #define P4_MEM (-11) /* P4 is a pointer to a Mem* structure */
17774 #define P4_VTAB (-12) /* P4 is a pointer to an sqlite3_vtab structure */
17775 #define P4_REAL (-13) /* P4 is a 64-bit floating point value */
17776 #define P4_INT64 (-14) /* P4 is a 64-bit signed integer */
17777 #define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
17778 #define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */
17779 #define P4_TABLEREF (-17) /* Like P4_TABLE, but reference counted */
17780 #define P4_SUBRTNSIG (-18) /* P4 is a SubrtnSig pointer */
17781
17782 /* Error message codes for OP_Halt */
17783 #define P5_ConstraintNotNull 1
17784 #define P5_ConstraintUnique 2
17785 #define P5_ConstraintCheck 3
@@ -17891,11 +17926,11 @@
17891 #define OP_Return 69
17892 #define OP_EndCoroutine 70
17893 #define OP_HaltIfNull 71 /* synopsis: if r[P3]=null halt */
17894 #define OP_Halt 72
17895 #define OP_Integer 73 /* synopsis: r[P2]=P1 */
17896 #define OP_Int64 74 /* synopsis: r[P2]=P4 */
17897 #define OP_String 75 /* synopsis: r[P2]='P4' (len=P1) */
17898 #define OP_BeginSubrtn 76 /* synopsis: r[P2]=NULL */
17899 #define OP_Null 77 /* synopsis: r[P2..P3]=NULL */
17900 #define OP_SoftNull 78 /* synopsis: r[P1]=NULL */
17901 #define OP_Blob 79 /* synopsis: r[P2]=P4 (len=P1) */
@@ -17942,11 +17977,11 @@
17942 #define OP_OpenEphemeral 120 /* synopsis: nColumn=P2 */
17943 #define OP_SorterOpen 121
17944 #define OP_SequenceTest 122 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
17945 #define OP_OpenPseudo 123 /* synopsis: P3 columns in r[P2] */
17946 #define OP_Close 124
17947 #define OP_ColumnsUsed 125
17948 #define OP_SeekScan 126 /* synopsis: Scan-ahead up to P1 rows */
17949 #define OP_SeekHit 127 /* synopsis: set P2<=seekHit<=P3 */
17950 #define OP_Sequence 128 /* synopsis: r[P2]=cursor[P1].ctr++ */
17951 #define OP_NewRowid 129 /* synopsis: r[P2]=rowid */
17952 #define OP_Insert 130 /* synopsis: intkey=r[P3] data=r[P2] */
@@ -17971,11 +18006,11 @@
17971 #define OP_CreateBtree 149 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
17972 #define OP_SqlExec 150
17973 #define OP_ParseSchema 151
17974 #define OP_LoadAnalysis 152
17975 #define OP_DropTable 153
17976 #define OP_Real 154 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
17977 #define OP_DropIndex 155
17978 #define OP_DropTrigger 156
17979 #define OP_IntegrityCk 157
17980 #define OP_RowSetAdd 158 /* synopsis: rowset(P1)=r[P2] */
17981 #define OP_Param 159
@@ -18079,12 +18114,13 @@
18079 SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
18080 SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe*,int);
18081 SQLITE_PRIVATE int sqlite3VdbeLoadString(Vdbe*,int,const char*);
18082 SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...);
18083 SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
 
 
18084 SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
18085 SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int);
18086 SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
18087 SQLITE_PRIVATE int sqlite3VdbeAddFunctionCall(Parse*,int,int,int,int,const FuncDef*,int);
18088 SQLITE_PRIVATE void sqlite3VdbeEndCoroutine(Vdbe*,int);
18089 #if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS)
18090 SQLITE_PRIVATE void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N);
@@ -18331,10 +18367,11 @@
18331 ** This header file defines the interface that the sqlite page cache
18332 ** subsystem.
18333 */
18334
18335 #ifndef _PCACHE_H_
 
18336
18337 typedef struct PgHdr PgHdr;
18338 typedef struct PCache PCache;
18339
18340 /*
@@ -18689,11 +18726,11 @@
18689
18690 /*
18691 ** The number of different kinds of things that can be limited
18692 ** using the sqlite3_limit() interface.
18693 */
18694 #define SQLITE_N_LIMIT (SQLITE_LIMIT_SCHEMA+1)
18695
18696 /*
18697 ** Lookaside malloc is a set of fixed-size buffers that can be used
18698 ** to satisfy small transient memory allocation requests for objects
18699 ** associated with a particular database connection. The use of
@@ -21008,10 +21045,17 @@
21008 ParseCleanup *pNext; /* Next cleanup task */
21009 void *pPtr; /* Pointer to object to deallocate */
21010 void (*xCleanup)(sqlite3*,void*); /* Deallocation routine */
21011 };
21012
 
 
 
 
 
 
 
21013 /*
21014 ** An SQL parser context. A copy of this structure is passed through
21015 ** the parser and down into all the parser action routine in order to
21016 ** carry around information that is global to the entire parse.
21017 **
@@ -21126,10 +21170,11 @@
21126 ** first field in the recursive region.
21127 ************************************************************************/
21128
21129 Token sLastToken; /* The last token parsed */
21130 ynVar nVar; /* Number of '?' variables seen in the SQL so far */
 
21131 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
21132 u8 explain; /* True if the EXPLAIN flag is found on the query */
21133 u8 eParseMode; /* PARSE_MODE_XXX constant */
21134 #ifndef SQLITE_OMIT_VIRTUALTABLE
21135 int nVtabLock; /* Number of virtual tables to lock */
@@ -22165,10 +22210,11 @@
22165 SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int,int);
22166 SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,const Token*,int);
22167 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);
22168 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
22169 SQLITE_PRIVATE void sqlite3ExprListDeleteGeneric(sqlite3*,void*);
 
22170 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
22171 SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage(Index*);
22172 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
22173 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
22174 SQLITE_PRIVATE int sqlite3InitOne(sqlite3*, int, char**, u32);
@@ -22389,10 +22435,11 @@
22389 SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*);
22390 SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse*,Expr*);
22391 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
22392 SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
22393 SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int,int);
 
22394 #ifdef SQLITE_ENABLE_CURSOR_HINTS
22395 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
22396 #endif
22397 SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*, Parse*);
22398 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
@@ -22544,10 +22591,11 @@
22544 ** be defined locally, but now we use the varint routines in the util.c
22545 ** file.
22546 */
22547 SQLITE_PRIVATE int sqlite3PutVarint(unsigned char*, u64);
22548 SQLITE_PRIVATE u8 sqlite3GetVarint(const unsigned char *, u64 *);
 
22549 SQLITE_PRIVATE u8 sqlite3GetVarint32(const unsigned char *, u32 *);
22550 SQLITE_PRIVATE int sqlite3VarintLen(u64 v);
22551
22552 /*
22553 ** The common case is for a varint to be a single byte. They following
@@ -22559,13 +22607,10 @@
22559 #define getVarint32NR(A,B) \
22560 B=(u32)*(A);if(B>=0x80)sqlite3GetVarint32((A),(u32*)&(B))
22561 #define putVarint32(A,B) \
22562 (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\
22563 sqlite3PutVarint((A),(B)))
22564 #define getVarint sqlite3GetVarint
22565 #define putVarint sqlite3PutVarint
22566
22567
22568 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3*, Index*);
22569 SQLITE_PRIVATE char *sqlite3TableAffinityStr(sqlite3*,const Table*);
22570 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
22571 SQLITE_PRIVATE char sqlite3CompareAffinity(const Expr *pExpr, char aff2);
@@ -38343,176 +38388,88 @@
38343 p[1] = v&0x7f;
38344 return 2;
38345 }
38346 return putVarint64(p,v);
38347 }
38348
38349 /*
38350 ** Bitmasks used by sqlite3GetVarint(). These precomputed constants
38351 ** are defined here rather than simply putting the constant expressions
38352 ** inline in order to work around bugs in the RVT compiler.
38353 **
38354 ** SLOT_2_0 A mask for (0x7f<<14) | 0x7f
38355 **
38356 ** SLOT_4_2_0 A mask for (0x7f<<28) | SLOT_2_0
38357 */
38358 #define SLOT_2_0 0x001fc07f
38359 #define SLOT_4_2_0 0xf01fc07f
38360
38361
38362 /*
38363 ** Read a 64-bit variable-length integer from memory starting at p[0].
38364 ** Return the number of bytes read. The value is stored in *v.
38365 */
38366 SQLITE_PRIVATE u8 sqlite3GetVarint(const unsigned char *p, u64 *v){
38367 u32 a,b,s;
38368
38369 if( ((signed char*)p)[0]>=0 ){
38370 *v = *p;
38371 return 1;
38372 }
38373 if( ((signed char*)p)[1]>=0 ){
38374 *v = ((u32)(p[0]&0x7f)<<7) | p[1];
38375 return 2;
38376 }
38377
38378 /* Verify that constants are precomputed correctly */
38379 assert( SLOT_2_0 == ((0x7f<<14) | (0x7f)) );
38380 assert( SLOT_4_2_0 == ((0xfU<<28) | (0x7f<<14) | (0x7f)) );
38381
38382 a = ((u32)p[0])<<14;
38383 b = p[1];
38384 p += 2;
38385 a |= *p;
38386 /* a: p0<<14 | p2 (unmasked) */
38387 if (!(a&0x80))
38388 {
38389 a &= SLOT_2_0;
38390 b &= 0x7f;
38391 b = b<<7;
38392 a |= b;
38393 *v = a;
38394 return 3;
38395 }
38396
38397 /* CSE1 from below */
38398 a &= SLOT_2_0;
38399 p++;
38400 b = b<<14;
38401 b |= *p;
38402 /* b: p1<<14 | p3 (unmasked) */
38403 if (!(b&0x80))
38404 {
38405 b &= SLOT_2_0;
38406 /* moved CSE1 up */
38407 /* a &= (0x7f<<14)|(0x7f); */
38408 a = a<<7;
38409 a |= b;
38410 *v = a;
38411 return 4;
38412 }
38413
38414 /* a: p0<<14 | p2 (masked) */
38415 /* b: p1<<14 | p3 (unmasked) */
38416 /* 1:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
38417 /* moved CSE1 up */
38418 /* a &= (0x7f<<14)|(0x7f); */
38419 b &= SLOT_2_0;
38420 s = a;
38421 /* s: p0<<14 | p2 (masked) */
38422
38423 p++;
38424 a = a<<14;
38425 a |= *p;
38426 /* a: p0<<28 | p2<<14 | p4 (unmasked) */
38427 if (!(a&0x80))
38428 {
38429 /* we can skip these cause they were (effectively) done above
38430 ** while calculating s */
38431 /* a &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
38432 /* b &= (0x7f<<14)|(0x7f); */
38433 b = b<<7;
38434 a |= b;
38435 s = s>>18;
38436 *v = ((u64)s)<<32 | a;
38437 return 5;
38438 }
38439
38440 /* 2:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
38441 s = s<<7;
38442 s |= b;
38443 /* s: p0<<21 | p1<<14 | p2<<7 | p3 (masked) */
38444
38445 p++;
38446 b = b<<14;
38447 b |= *p;
38448 /* b: p1<<28 | p3<<14 | p5 (unmasked) */
38449 if (!(b&0x80))
38450 {
38451 /* we can skip this cause it was (effectively) done above in calc'ing s */
38452 /* b &= (0x7f<<28)|(0x7f<<14)|(0x7f); */
38453 a &= SLOT_2_0;
38454 a = a<<7;
38455 a |= b;
38456 s = s>>18;
38457 *v = ((u64)s)<<32 | a;
38458 return 6;
38459 }
38460
38461 p++;
38462 a = a<<14;
38463 a |= *p;
38464 /* a: p2<<28 | p4<<14 | p6 (unmasked) */
38465 if (!(a&0x80))
38466 {
38467 a &= SLOT_4_2_0;
38468 b &= SLOT_2_0;
38469 b = b<<7;
38470 a |= b;
38471 s = s>>11;
38472 *v = ((u64)s)<<32 | a;
38473 return 7;
38474 }
38475
38476 /* CSE2 from below */
38477 a &= SLOT_2_0;
38478 p++;
38479 b = b<<14;
38480 b |= *p;
38481 /* b: p3<<28 | p5<<14 | p7 (unmasked) */
38482 if (!(b&0x80))
38483 {
38484 b &= SLOT_4_2_0;
38485 /* moved CSE2 up */
38486 /* a &= (0x7f<<14)|(0x7f); */
38487 a = a<<7;
38488 a |= b;
38489 s = s>>4;
38490 *v = ((u64)s)<<32 | a;
38491 return 8;
38492 }
38493
38494 p++;
38495 a = a<<15;
38496 a |= *p;
38497 /* a: p4<<29 | p6<<15 | p8 (unmasked) */
38498
38499 /* moved CSE2 up */
38500 /* a &= (0x7f<<29)|(0x7f<<15)|(0xff); */
38501 b &= SLOT_2_0;
38502 b = b<<8;
38503 a |= b;
38504
38505 s = s<<4;
38506 b = p[-4];
38507 b &= 0x7f;
38508 b = b>>3;
38509 s |= b;
38510
38511 *v = ((u64)s)<<32 | a;
38512
38513 return 9;
38514 }
38515
38516 /*
38517 ** Read a 32-bit variable-length integer from memory starting at p[0].
38518 ** Return the number of bytes read. The value is stored in *v.
@@ -39405,11 +39362,11 @@
39405 /* 69 */ "Return" OpHelp(""),
39406 /* 70 */ "EndCoroutine" OpHelp(""),
39407 /* 71 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
39408 /* 72 */ "Halt" OpHelp(""),
39409 /* 73 */ "Integer" OpHelp("r[P2]=P1"),
39410 /* 74 */ "Int64" OpHelp("r[P2]=P4"),
39411 /* 75 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
39412 /* 76 */ "BeginSubrtn" OpHelp("r[P2]=NULL"),
39413 /* 77 */ "Null" OpHelp("r[P2..P3]=NULL"),
39414 /* 78 */ "SoftNull" OpHelp("r[P1]=NULL"),
39415 /* 79 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
@@ -39456,11 +39413,11 @@
39456 /* 120 */ "OpenEphemeral" OpHelp("nColumn=P2"),
39457 /* 121 */ "SorterOpen" OpHelp(""),
39458 /* 122 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
39459 /* 123 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
39460 /* 124 */ "Close" OpHelp(""),
39461 /* 125 */ "ColumnsUsed" OpHelp(""),
39462 /* 126 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"),
39463 /* 127 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"),
39464 /* 128 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
39465 /* 129 */ "NewRowid" OpHelp("r[P2]=rowid"),
39466 /* 130 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
@@ -39485,11 +39442,11 @@
39485 /* 149 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
39486 /* 150 */ "SqlExec" OpHelp(""),
39487 /* 151 */ "ParseSchema" OpHelp(""),
39488 /* 152 */ "LoadAnalysis" OpHelp(""),
39489 /* 153 */ "DropTable" OpHelp(""),
39490 /* 154 */ "Real" OpHelp("r[P2]=P4"),
39491 /* 155 */ "DropIndex" OpHelp(""),
39492 /* 156 */ "DropTrigger" OpHelp(""),
39493 /* 157 */ "IntegrityCk" OpHelp(""),
39494 /* 158 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
39495 /* 159 */ "Param" OpHelp(""),
@@ -57486,10 +57443,11 @@
57486
57487 nNew = 2*(u64)p->nHash;
57488 if( nNew<256 ){
57489 nNew = 256;
57490 }
 
57491
57492 pcache1LeaveMutex(p->pGroup);
57493 if( p->nHash ){ sqlite3BeginBenignMalloc(); }
57494 apNew = (PgHdr1 **)sqlite3MallocZero(sizeof(PgHdr1 *)*nNew);
57495 if( p->nHash ){ sqlite3EndBenignMalloc(); }
@@ -57497,11 +57455,11 @@
57497 if( apNew ){
57498 for(i=0; i<p->nHash; i++){
57499 PgHdr1 *pPage;
57500 PgHdr1 *pNext = p->apHash[i];
57501 while( (pPage = pNext)!=0 ){
57502 unsigned int h = pPage->iKey % nNew;
57503 pNext = pPage->pNext;
57504 pPage->pNext = apNew[h];
57505 apNew[h] = pPage;
57506 }
57507 }
@@ -57547,11 +57505,12 @@
57547 unsigned int h;
57548 PCache1 *pCache = pPage->pCache;
57549 PgHdr1 **pp;
57550
57551 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
57552 h = pPage->iKey % pCache->nHash;
 
57553 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
57554 *pp = (*pp)->pNext;
57555
57556 pCache->nPage--;
57557 if( freeFlag ) pcache1FreePage(pPage);
@@ -57592,18 +57551,18 @@
57592 ){
57593 TESTONLY( int nPage = 0; ) /* To assert pCache->nPage is correct */
57594 unsigned int h, iStop;
57595 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
57596 assert( pCache->iMaxKey >= iLimit );
57597 assert( pCache->nHash > 0 );
57598 if( pCache->iMaxKey - iLimit < pCache->nHash ){
57599 /* If we are just shaving the last few pages off the end of the
57600 ** cache, then there is no point in scanning the entire hash table.
57601 ** Only scan those hash slots that might contain pages that need to
57602 ** be removed. */
57603 h = iLimit % pCache->nHash;
57604 iStop = pCache->iMaxKey % pCache->nHash;
57605 TESTONLY( nPage = -10; ) /* Disable the pCache->nPage validity check */
57606 }else{
57607 /* This is the general case where many pages are being removed.
57608 ** It is necessary to scan the entire hash table */
57609 h = pCache->nHash/2;
@@ -57624,11 +57583,11 @@
57624 pp = &pPage->pNext;
57625 TESTONLY( if( nPage>=0 ) nPage++; )
57626 }
57627 }
57628 if( h==iStop ) break;
57629 h = (h+1) % pCache->nHash;
57630 }
57631 assert( nPage<0 || pCache->nPage==(unsigned)nPage );
57632 }
57633
57634 /******************************************************************************/
@@ -57836,10 +57795,11 @@
57836 return 0;
57837 }
57838
57839 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
57840 assert( pCache->nHash>0 && pCache->apHash );
 
57841
57842 /* Step 4. Try to recycle a page. */
57843 if( pCache->bPurgeable
57844 && !pGroup->lru.pLruPrev->isAnchor
57845 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
@@ -57864,11 +57824,11 @@
57864 if( !pPage ){
57865 pPage = pcache1AllocPage(pCache, createFlag==1);
57866 }
57867
57868 if( pPage ){
57869 unsigned int h = iKey % pCache->nHash;
57870 pCache->nPage++;
57871 pPage->iKey = iKey;
57872 pPage->pNext = pCache->apHash[h];
57873 pPage->pCache = pCache;
57874 pPage->pLruNext = 0;
@@ -58071,19 +58031,20 @@
58071 assert( iOld!=iNew ); /* The page number really is changing */
58072
58073 pcache1EnterMutex(pCache->pGroup);
58074
58075 assert( pcache1FetchNoMutex(p, iOld, 0)==pPage ); /* pPg really is iOld */
58076 hOld = iOld%pCache->nHash;
 
58077 pp = &pCache->apHash[hOld];
58078 while( (*pp)!=pPage ){
58079 pp = &(*pp)->pNext;
58080 }
58081 *pp = pPage->pNext;
58082
58083 assert( pcache1FetchNoMutex(p, iNew, 0)==0 ); /* iNew not in cache */
58084 hNew = iNew%pCache->nHash;
58085 pPage->iKey = iNew;
58086 pPage->pNext = pCache->apHash[hNew];
58087 pCache->apHash[hNew] = pPage;
58088 if( iNew>pCache->iMaxKey ){
58089 pCache->iMaxKey = iNew;
@@ -63895,11 +63856,19 @@
63895
63896 /* Open the pager file.
63897 */
63898 if( zFilename && zFilename[0] ){
63899 int fout = 0; /* VFS flags returned by xOpen() */
 
 
 
 
 
63900 rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
 
 
 
63901 assert( !memDb );
63902 pPager->memVfs = memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
63903 readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
63904
63905 /* If the file was successfully opened for read/write access,
@@ -63935,14 +63904,13 @@
63935 }
63936 }
63937 #endif
63938 }
63939 pPager->noLock = sqlite3_uri_boolean(pPager->zFilename, "nolock", 0);
63940 if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0
63941 || sqlite3_uri_boolean(pPager->zFilename, "immutable", 0) ){
63942 vfsFlags |= SQLITE_OPEN_READONLY;
63943 goto act_like_temp_file;
63944 }
63945 }
63946 }else{
63947 /* If a temporary file is requested, it is not opened immediately.
63948 ** In this case we accept the default page size and delay actually
@@ -63958,10 +63926,11 @@
63958 tempFile = 1;
63959 pPager->eState = PAGER_READER; /* Pretend we already have a lock */
63960 pPager->eLock = EXCLUSIVE_LOCK; /* Pretend we are in EXCLUSIVE mode */
63961 pPager->noLock = 1; /* Do no locking */
63962 readOnly = (vfsFlags&SQLITE_OPEN_READONLY);
 
63963 }
63964
63965 /* The following call to PagerSetPagesize() serves to set the value of
63966 ** Pager.pageSize and to allocate the Pager.pTmpSpace buffer.
63967 */
@@ -70452,15 +70421,19 @@
70452 ){
70453 int sz;
70454 i64 iOffset;
70455 sz = pWal->hdr.szPage;
70456 sz = (sz&0xfe00) + ((sz&0x0001)<<16);
 
 
 
 
70457 testcase( sz<=32768 );
70458 testcase( sz>=65536 );
70459 iOffset = walFrameOffset(iRead, sz) + WAL_FRAME_HDRSIZE;
70460 /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
70461 return sqlite3OsRead(pWal->pWalFd, pOut, (nOut>sz ? sz : nOut), iOffset);
70462 }
70463
70464 /*
70465 ** Return the size of the database in pages (or zero, if unknown).
70466 */
@@ -72163,10 +72136,11 @@
72163 Pgno nCkPage; /* Pages in the database. 0 for partial check */
72164 int mxErr; /* Stop accumulating errors when this reaches zero */
72165 int nErr; /* Number of messages written to zErrMsg so far */
72166 int rc; /* SQLITE_OK, SQLITE_NOMEM, or SQLITE_INTERRUPT */
72167 u32 nStep; /* Number of steps into the integrity_check process */
 
72168 const char *zPfx; /* Error message prefix */
72169 Pgno v0; /* Value for first %u substitution in zPfx (root page) */
72170 Pgno v1; /* Value for second %u substitution in zPfx (current pg) */
72171 int v2; /* Value for third %d substitution in zPfx */
72172 StrAccum errMsg; /* Accumulate the error message text here */
@@ -73774,11 +73748,11 @@
73774 assert( pPage->leaf==0 );
73775 assert( pPage->childPtrSize==4 );
73776 #ifndef SQLITE_DEBUG
73777 UNUSED_PARAMETER(pPage);
73778 #endif
73779 pInfo->nSize = 4 + getVarint(&pCell[4], (u64*)&pInfo->nKey);
73780 pInfo->nPayload = 0;
73781 pInfo->nLocal = 0;
73782 pInfo->pPayload = 0;
73783 return;
73784 }
@@ -73814,11 +73788,11 @@
73814 }
73815 pIter++;
73816
73817 /* The next block of code is equivalent to:
73818 **
73819 ** pIter += getVarint(pIter, (u64*)&pInfo->nKey);
73820 **
73821 ** The code is inlined and the loop is unrolled for performance.
73822 ** This routine is a high-runner.
73823 */
73824 iKey = *pIter;
@@ -78425,11 +78399,11 @@
78425 if( pCell>=pPage->aDataEnd ){
78426 return SQLITE_CORRUPT_PAGE(pPage);
78427 }
78428 }
78429 }
78430 getVarint(pCell, (u64*)&nCellKey);
78431 if( nCellKey<intKey ){
78432 lwr = idx+1;
78433 if( lwr>upr ){ c = -1; break; }
78434 }else if( nCellKey>intKey ){
78435 upr = idx-1;
@@ -79632,11 +79606,11 @@
79632 nPayload = pX->nData + pX->nZero;
79633 pSrc = pX->pData;
79634 nSrc = pX->nData;
79635 assert( pPage->intKeyLeaf ); /* fillInCell() only called for leaves */
79636 nHeader += putVarint32(&pCell[nHeader], nPayload);
79637 nHeader += putVarint(&pCell[nHeader], *(u64*)&pX->nKey);
79638 }else{
79639 assert( pX->nKey<=0x7fffffff && pX->pKey!=0 );
79640 nSrc = nPayload = (int)pX->nKey;
79641 pSrc = pX->pKey;
79642 nHeader += putVarint32(&pCell[nHeader], nPayload);
@@ -81381,11 +81355,11 @@
81381 */
81382 CellInfo info;
81383 j--;
81384 pNew->xParseCell(pNew, b.apCell[j], &info);
81385 pCell = pTemp;
81386 sz = 4 + putVarint(&pCell[4], info.nKey);
81387 pTemp = 0;
81388 }else{
81389 pCell -= 4;
81390 /* Obscure case for non-leaf-data trees: If the cell at pCell was
81391 ** previously stored on a leaf node, and its reported size was 4
@@ -82266,11 +82240,11 @@
82266 if( pSrc->info.nPayload<0x80 ){
82267 *(aOut++) = (u8)pSrc->info.nPayload;
82268 }else{
82269 aOut += sqlite3PutVarint(aOut, pSrc->info.nPayload);
82270 }
82271 if( pDest->pKeyInfo==0 ) aOut += putVarint(aOut, iKey);
82272 nIn = pSrc->info.nLocal;
82273 aIn = pSrc->info.pPayload;
82274 if( aIn+nIn>pSrc->pPage->aDataEnd ){
82275 return SQLITE_CORRUPT_PAGE(pSrc->pPage);
82276 }
@@ -82736,15 +82710,24 @@
82736 }
82737
82738 /*
82739 ** Erase the given database page and all its children. Return
82740 ** the page to the freelist.
 
 
 
 
 
 
 
 
 
82741 */
82742 static int clearDatabasePage(
82743 BtShared *pBt, /* The BTree that contains the table */
82744 Pgno pgno, /* Page number to clear */
82745 int freePageFlag, /* Deallocate page if true */
82746 i64 *pnChange /* Add number of Cells freed to this counter */
82747 ){
82748 MemPage *pPage;
82749 int rc;
82750 unsigned char *pCell;
@@ -82753,10 +82736,13 @@
82753 CellInfo info;
82754
82755 assert( sqlite3_mutex_held(pBt->mutex) );
82756 if( pgno>btreePagecount(pBt) ){
82757 return SQLITE_CORRUPT_PGNO(pgno);
 
 
 
82758 }
82759 rc = getAndInitPage(pBt, pgno, &pPage, 0);
82760 if( rc ) return rc;
82761 if( (pBt->openFlags & BTREE_SINGLE)==0
82762 && sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1))
@@ -82766,26 +82752,28 @@
82766 }
82767 hdr = pPage->hdrOffset;
82768 for(i=0; i<pPage->nCell; i++){
82769 pCell = findCell(pPage, i);
82770 if( !pPage->leaf ){
82771 rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
 
82772 if( rc ) goto cleardatabasepage_out;
82773 }
82774 BTREE_CLEAR_CELL(rc, pPage, pCell, info);
82775 if( rc ) goto cleardatabasepage_out;
82776 }
82777 if( !pPage->leaf ){
82778 rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
 
82779 if( rc ) goto cleardatabasepage_out;
82780 if( pPage->intKey ) pnChange = 0;
82781 }
82782 if( pnChange ){
82783 testcase( !pPage->intKey );
82784 *pnChange += pPage->nCell;
82785 }
82786 if( freePageFlag ){
82787 freePage(pPage, &rc);
82788 }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
82789 zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF);
82790 }
82791
@@ -83416,22 +83404,27 @@
83416 u8 savedIsInit = 0;
83417
83418 /* Check that the page exists
83419 */
83420 checkProgress(pCheck);
83421 if( pCheck->mxErr==0 ) goto end_of_check;
83422 pBt = pCheck->pBt;
83423 usableSize = pBt->usableSize;
83424 if( iPage==0 ) return 0;
83425 if( checkRef(pCheck, iPage) ) return 0;
83426 pCheck->zPfx = "Tree %u page %u: ";
83427 pCheck->v1 = iPage;
 
83428 if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
83429 checkAppendMsg(pCheck,
83430 "unable to get the page. error code=%d", rc);
83431 if( rc==SQLITE_IOERR_NOMEM ) pCheck->rc = SQLITE_NOMEM;
83432 goto end_of_check;
 
 
 
 
83433 }
83434
83435 /* Clear MemPage.isInit to make sure the corruption detection code in
83436 ** btreeInitPage() is executed. */
83437 savedIsInit = pPage->isInit;
@@ -83648,10 +83641,11 @@
83648 if( !doCoverageCheck ) pPage->isInit = savedIsInit;
83649 releasePage(pPage);
83650 pCheck->zPfx = saved_zPfx;
83651 pCheck->v1 = saved_v1;
83652 pCheck->v2 = saved_v2;
 
83653 return depth+1;
83654 }
83655 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
83656
83657 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
@@ -83780,11 +83774,13 @@
83780 if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){
83781 checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
83782 }
83783 #endif
83784 sCheck.v0 = aRoot[i];
 
83785 checkTreePage(&sCheck, aRoot[i], &notUsed, LARGEST_INT64);
 
83786 }
83787 sqlite3MemSetArrayInt64(aCnt, i, sCheck.nRow);
83788 }
83789 pBt->db->flags = savedDbFlags;
83790
@@ -87553,10 +87549,24 @@
87553 /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87554 ** Replicate in sqlite3VdbeAddOp3() */
87555
87556 return i;
87557 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87558
87559 /* Generate code for an unconditional jump to instruction iDest
87560 */
87561 SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe *p, int iDest){
87562 return sqlite3VdbeAddOp3(p, OP_Goto, 0, iDest, 0);
@@ -87657,28 +87667,10 @@
87657 sqlite3VdbeChangeP5(v, eCallCtx & NC_SelfRef);
87658 sqlite3MayAbort(pParse);
87659 return addr;
87660 }
87661
87662 /*
87663 ** Add an opcode that includes the p4 value with a P4_INT64 or
87664 ** P4_REAL type.
87665 */
87666 SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(
87667 Vdbe *p, /* Add the opcode to this VM */
87668 int op, /* The new opcode */
87669 int p1, /* The P1 operand */
87670 int p2, /* The P2 operand */
87671 int p3, /* The P3 operand */
87672 const u8 *zP4, /* The P4 operand */
87673 int p4type /* P4 operand type */
87674 ){
87675 char *p4copy = sqlite3DbMallocRawNN(sqlite3VdbeDb(p), 8);
87676 if( p4copy ) memcpy(p4copy, zP4, 8);
87677 return sqlite3VdbeAddOp4(p, op, p1, p2, p3, p4copy, p4type);
87678 }
87679
87680 #ifndef SQLITE_OMIT_EXPLAIN
87681 /*
87682 ** Return the address of the current EXPLAIN QUERY PLAN baseline.
87683 ** 0 means "none".
87684 */
@@ -88581,12 +88573,10 @@
88581 switch( p4type ){
88582 case P4_FUNCCTX: {
88583 freeP4FuncCtx(db, (sqlite3_context*)p4);
88584 break;
88585 }
88586 case P4_REAL:
88587 case P4_INT64:
88588 case P4_DYNAMIC:
88589 case P4_INTARRAY: {
88590 if( p4 ) sqlite3DbNNFreeNN(db, p4);
88591 break;
88592 }
@@ -88936,10 +88926,13 @@
88936 **
88937 ** "PX" -> "r[X]"
88938 ** "PX@PY" -> "r[X..X+Y-1]" or "r[x]" if y is 0 or 1
88939 ** "PX@PY+1" -> "r[X..X+Y]" or "r[x]" if y is 0
88940 ** "PY..PY" -> "r[X..Y]" or "r[x]" if y<=x
 
 
 
88941 */
88942 SQLITE_PRIVATE char *sqlite3VdbeDisplayComment(
88943 sqlite3 *db, /* Optional - Oom error reporting only */
88944 const Op *pOp, /* The opcode to be commented */
88945 const char *zP4 /* Previously obtained value for P4 */
@@ -88971,10 +88964,24 @@
88971 if( pOp->zComment && pOp->zComment[0] ){
88972 sqlite3_str_appendall(&x, pOp->zComment);
88973 seenCom = 1;
88974 break;
88975 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88976 }else{
88977 int v1 = translateP(c, pOp);
88978 int v2;
88979 if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
88980 ii += 3;
@@ -89148,22 +89155,14 @@
89148 case P4_FUNCCTX: {
89149 FuncDef *pDef = pOp->p4.pCtx->pFunc;
89150 sqlite3_str_appendf(&x, "%s(%d)", pDef->zName, pDef->nArg);
89151 break;
89152 }
89153 case P4_INT64: {
89154 sqlite3_str_appendf(&x, "%lld", *pOp->p4.pI64);
89155 break;
89156 }
89157 case P4_INT32: {
89158 sqlite3_str_appendf(&x, "%d", pOp->p4.i);
89159 break;
89160 }
89161 case P4_REAL: {
89162 sqlite3_str_appendf(&x, "%.16g", *pOp->p4.pReal);
89163 break;
89164 }
89165 case P4_MEM: {
89166 Mem *pMem = pOp->p4.pMem;
89167 if( pMem->flags & MEM_Str ){
89168 zP4 = pMem->z;
89169 }else if( pMem->flags & (MEM_Int|MEM_IntReal) ){
@@ -97360,35 +97359,39 @@
97360 pOut = out2Prerelease(p, pOp);
97361 pOut->u.i = pOp->p1;
97362 break;
97363 }
97364
97365 /* Opcode: Int64 * P2 * P4 *
97366 ** Synopsis: r[P2]=P4
97367 **
97368 ** P4 is a pointer to a 64-bit integer value.
97369 ** Write that value into register P2.
 
97370 */
97371 case OP_Int64: { /* out2 */
97372 pOut = out2Prerelease(p, pOp);
97373 assert( pOp->p4.pI64!=0 );
97374 pOut->u.i = *pOp->p4.pI64;
97375 break;
97376 }
97377
97378 #ifndef SQLITE_OMIT_FLOATING_POINT
97379 /* Opcode: Real * P2 * P4 *
97380 ** Synopsis: r[P2]=P4
97381 **
97382 ** P4 is a pointer to a 64-bit floating point value.
97383 ** Write that value into register P2.
 
97384 */
97385 case OP_Real: { /* same as TK_FLOAT, out2 */
 
97386 pOut = out2Prerelease(p, pOp);
97387 pOut->flags = MEM_Real;
97388 assert( !sqlite3IsNaN(*pOp->p4.pReal) );
97389 pOut->u.r = *pOp->p4.pReal;
 
 
97390 break;
97391 }
97392 #endif
97393
97394 /* Opcode: String8 * P2 * P4 *
@@ -99461,26 +99464,13 @@
99461 while( 1 /*exit-by-break*/ ){
99462 assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
99463 assert( zAffinity[0]==SQLITE_AFF_NONE || memIsValid(pIn1) );
99464 applyAffinity(pIn1, zAffinity[0], encoding);
99465 if( zAffinity[0]==SQLITE_AFF_REAL && (pIn1->flags & MEM_Int)!=0 ){
99466 /* When applying REAL affinity, if the result is still an MEM_Int
99467 ** that will fit in 6 bytes, then change the type to MEM_IntReal
99468 ** so that we keep the high-resolution integer value but know that
99469 ** the type really wants to be REAL. */
99470 testcase( pIn1->u.i==140737488355328LL );
99471 testcase( pIn1->u.i==140737488355327LL );
99472 testcase( pIn1->u.i==-140737488355328LL );
99473 testcase( pIn1->u.i==-140737488355329LL );
99474 if( pIn1->u.i<=140737488355327LL && pIn1->u.i>=-140737488355328LL ){
99475 pIn1->flags |= MEM_IntReal;
99476 pIn1->flags &= ~MEM_Int;
99477 }else{
99478 pIn1->u.r = (double)pIn1->u.i;
99479 pIn1->flags |= MEM_Real;
99480 pIn1->flags &= ~(MEM_Int|MEM_Str);
99481 }
99482 }
99483 REGISTER_TRACE((int)(pIn1-aMem), pIn1);
99484 zAffinity++;
99485 if( zAffinity[0]==0 ) break;
99486 pIn1++;
@@ -100794,25 +100784,25 @@
100794 p->apCsr[pOp->p1] = 0;
100795 break;
100796 }
100797
100798 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
100799 /* Opcode: ColumnsUsed P1 * * P4 *
 
100800 **
100801 ** This opcode (which only exists if SQLite was compiled with
100802 ** SQLITE_ENABLE_COLUMN_USED_MASK) identifies which columns of the
100803 ** table or index for cursor P1 are used. P4 is a 64-bit integer
100804 ** (P4_INT64) in which the first 63 bits are one for each of the
100805 ** first 63 columns of the table or index that are actually used
100806 ** by the cursor. The high-order bit is set if any column after
100807 ** the 64th is used.
100808 */
100809 case OP_ColumnsUsed: {
100810 VdbeCursor *pC;
100811 pC = p->apCsr[pOp->p1];
100812 assert( pC->eCurType==CURTYPE_BTREE );
100813 pC->maskUsed = *(u64*)pOp->p4.pI64;
100814 break;
100815 }
100816 #endif
100817
100818 /* Opcode: SeekGE P1 P2 P3 P4 *
@@ -113899,10 +113889,12 @@
113899 }
113900 x = (ynVar)i;
113901 if( x>pParse->nVar ){
113902 pParse->nVar = (int)x;
113903 doAdd = 1;
 
 
113904 }else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){
113905 doAdd = 1;
113906 }
113907 }else{
113908 /* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable
@@ -113915,10 +113907,13 @@
113915 doAdd = 1;
113916 }
113917 }
113918 if( doAdd ){
113919 pParse->pVList = sqlite3VListAdd(db, pParse->pVList, z, n, x);
 
 
 
113920 }
113921 }
113922 pExpr->iColumn = x;
113923 if( x>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
113924 sqlite3ErrorMsg(pParse, "too many SQL variables");
@@ -115067,10 +115062,11 @@
115067 **
115068 ** sqlite3ExprIsConstant() pWalker->eCode==1
115069 ** sqlite3ExprIsConstantNotJoin() pWalker->eCode==2
115070 ** sqlite3ExprIsTableConstant() pWalker->eCode==3
115071 ** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5
 
115072 **
115073 ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
115074 ** is found to not be a constant.
115075 **
115076 ** The sqlite3ExprIsConstantOrFunction() is used for evaluating DEFAULT
@@ -115139,10 +115135,17 @@
115139 testcase( pExpr->op==TK_IF_NULL_ROW );
115140 testcase( pExpr->op==TK_DOT );
115141 testcase( pExpr->op==TK_RAISE );
115142 pWalker->eCode = 0;
115143 return WRC_Abort;
 
 
 
 
 
 
 
115144 case TK_VARIABLE:
115145 if( pWalker->eCode==5 ){
115146 /* Silently convert bound parameters that appear inside of CREATE
115147 ** statements into a NULL when parsing the CREATE statement text out
115148 ** of the sqlite_schema table */
@@ -115188,10 +115191,26 @@
115188 ** function and on its parameters.
115189 */
115190 SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse *pParse, Expr *p){
115191 return exprIsConst(pParse, p, 1);
115192 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115193
115194 /*
115195 ** Walk an expression tree. Return non-zero if
115196 **
115197 ** (1) the expression is constant, and
@@ -115922,13 +115941,13 @@
115922 assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
115923 eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
115924
115925 if( prRhsHasNull ){
115926 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
115927 i64 mask = (1<<nExpr)-1;
115928 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed,
115929 iTab, 0, 0, (u8*)&mask, P4_INT64);
115930 #endif
115931 *prRhsHasNull = ++pParse->nMem;
115932 if( nExpr==1 ){
115933 sqlite3SetHasNullFlag(v, iTab, *prRhsHasNull);
115934 }
@@ -116878,11 +116897,11 @@
116878 if( ALWAYS(z!=0) ){
116879 double value;
116880 sqlite3AtoF(z, &value);
116881 assert( !sqlite3IsNaN(value) ); /* The new AtoF never returns NaN */
116882 if( negateFlag ) value = -value;
116883 sqlite3VdbeAddOp4Dup8(v, OP_Real, 0, iMem, 0, (u8*)&value, P4_REAL);
116884 }
116885 }
116886 #endif
116887
116888
@@ -116919,11 +116938,11 @@
116919 codeReal(v, z, negFlag, iMem);
116920 }
116921 #endif
116922 }else{
116923 if( negFlag ){ value = c==3 ? SMALLEST_INT64 : -value; }
116924 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64);
116925 }
116926 }
116927 }
116928
116929
@@ -117310,11 +117329,11 @@
117310 ** A TRUE return does not guarantee that a subtype will be returned.
117311 ** It only indicates that a subtype return is possible. False positives
117312 ** are acceptable as they only disable an optimization. False negatives,
117313 ** on the other hand, can lead to incorrect answers.
117314 */
117315 static int sqlite3ExprCanReturnSubtype(Parse *pParse, Expr *pExpr){
117316 Walker w;
117317 memset(&w, 0, sizeof(w));
117318 w.pParse = pParse;
117319 w.xExprCallback = exprNodeCanReturnSubtype;
117320 sqlite3WalkExpr(&w, pExpr);
@@ -139361,29 +139380,17 @@
139361 sqlite3VdbeJumpHere(pParse->pVdbe, pItem->u4.pSubq->addrFillSub - 1);
139362 }
139363 }
139364 }
139365
139366 /*
139367 ** Return true if all expressions in the expression-list passed as the
139368 ** only argument are constant.
139369 */
139370 static int exprListIsConstant(Parse *pParse, ExprList *pRow){
139371 int ii;
139372 for(ii=0; ii<pRow->nExpr; ii++){
139373 if( 0==sqlite3ExprIsConstant(pParse, pRow->a[ii].pExpr) ) return 0;
139374 }
139375 return 1;
139376 }
139377
139378 /*
139379 ** Return true if all expressions in the expression-list passed as the
139380 ** only argument are both constant and have no affinity.
139381 */
139382 static int exprListIsNoAffinity(Parse *pParse, ExprList *pRow){
139383 int ii;
139384 if( exprListIsConstant(pParse,pRow)==0 ) return 0;
139385 for(ii=0; ii<pRow->nExpr; ii++){
139386 Expr *pExpr = pRow->a[ii].pExpr;
139387 assert( pExpr->op!=TK_RAISE );
139388 assert( pExpr->affExpr==0 );
139389 if( 0!=sqlite3ExprAffinity(pExpr) ) return 0;
@@ -139445,11 +139452,11 @@
139445 */
139446 SQLITE_PRIVATE Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){
139447
139448 if( pParse->bHasWith /* condition (a) above */
139449 || pParse->db->init.busy /* condition (b) above */
139450 || exprListIsConstant(pParse,pRow)==0 /* condition (c) above */
139451 || (pLeft->pSrc->nSrc==0 &&
139452 exprListIsNoAffinity(pParse,pLeft->pEList)==0) /* condition (d) above */
139453 || IN_SPECIAL_PARSE
139454 ){
139455 /* The co-routine method cannot be used. Fall back to UNION ALL. */
@@ -144968,11 +144975,11 @@
144968
144969 /*
144970 ** Generate code to return a single integer value.
144971 */
144972 static void returnSingleInt(Vdbe *v, i64 value){
144973 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64);
144974 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
144975 }
144976
144977 /*
144978 ** Generate code to return a single text value.
@@ -153756,16 +153763,25 @@
153756 ** Either EP_OuterON or EP_InnerON|EP_OuterON */
153757 Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */
153758 };
153759
153760 /*
153761 ** Add a new entry to the pConst object. Except, do not add duplicate
153762 ** pColumn entries. Also, do not add if doing so would not be appropriate.
153763 **
153764 ** The caller guarantees the pColumn is a column and pValue is a constant.
153765 ** This routine has to do some additional checks before completing the
153766 ** insert.
 
 
 
 
 
 
 
 
 
 
153767 */
153768 static void constInsert(
153769 WhereConst *pConst, /* The WhereConst into which we are inserting */
153770 Expr *pColumn, /* The COLUMN part of the constraint */
153771 Expr *pValue, /* The VALUE part of the constraint */
@@ -153772,16 +153788,16 @@
153772 Expr *pExpr /* Overall expression: COLUMN=VALUE or VALUE=COLUMN */
153773 ){
153774 int i;
153775 assert( pColumn->op==TK_COLUMN );
153776 assert( sqlite3ExprIsConstant(pConst->pParse, pValue) );
153777
153778 if( ExprHasProperty(pColumn, EP_FixedCol) ) return;
153779 if( sqlite3ExprAffinity(pValue)!=0 ) return;
153780 if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) ){
153781 return;
153782 }
 
153783
153784 /* 2018-10-25 ticket [cf5ed20f]
153785 ** Make sure the same pColumn is not inserted more than once */
153786 for(i=0; i<pConst->nConst; i++){
153787 const Expr *pE2 = pConst->apExpr[i*2];
@@ -158538,20 +158554,25 @@
158538 char *zName; /* Name of trigger */
158539 sqlite3 *db = pParse->db; /* The database */
158540 DbFixer sFix; /* Fixer object */
158541 int iDb; /* Database containing the trigger */
158542 Token nameToken; /* Trigger name for error reporting */
 
158543
158544 pParse->pNewTrigger = 0;
158545 if( NEVER(pParse->nErr) || !pTrig ) goto triggerfinish_cleanup;
158546 zName = pTrig->zName;
158547 iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
158548 assert( iDb>=00 && iDb<db->nDb );
158549 pTrig->step_list = pStepList;
158550 while( pStepList ){
158551 pStepList->pTrig = pTrig;
158552 pStepList = pStepList->pNext;
 
 
 
 
158553 }
158554 sqlite3TokenInit(&nameToken, pTrig->zName);
158555 sqlite3FixInit(&sFix, pParse, iDb, "trigger", &nameToken);
158556 if( sqlite3FixTriggerStep(&sFix, pTrig->step_list)
158557 || sqlite3FixExpr(&sFix, pTrig->pWhen)
@@ -164681,10 +164702,21 @@
164681 if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
164682 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
164683 }else{
164684 sqlite3 *db = pParse->db;
164685 Expr *pXMod = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
 
 
 
 
 
 
 
 
 
 
 
164686 if( !db->mallocFailed ){
164687 aiMap = (int*)sqlite3DbMallocZero(db, sizeof(int)*nEq);
164688 eType = sqlite3FindInIndex(pParse, pXMod, IN_INDEX_LOOP, 0, aiMap, &iTab);
164689 }
164690 sqlite3ExprDelete(db, pXMod);
@@ -166895,21 +166927,29 @@
166895 pFrom = &uSrc.sSrc;
166896 pFrom->nSrc = 1;
166897 pFrom->nAlloc = 1;
166898 memcpy(&pFrom->a[0], pTabItem, sizeof(SrcItem));
166899 pFrom->a[0].fg.jointype = 0;
166900 assert( pParse->withinRJSubrtn < 100 );
 
 
 
 
 
 
 
 
166901 pParse->withinRJSubrtn++;
166902 pSubWInfo = sqlite3WhereBegin(pParse, pFrom, pSubWhere, 0, 0, 0,
166903 WHERE_RIGHT_JOIN, 0);
166904 if( pSubWInfo ){
166905 int iCur = pLevel->iTabCur;
166906 int r = ++pParse->nMem;
166907 int nPk;
166908 int jmp = 0;
166909 int addrCont = sqlite3WhereContinueLabel(pSubWInfo);
166910 Table *pTab = pTabItem->pSTab;
166911 if( HasRowid(pTab) ){
166912 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, -1, r);
166913 nPk = 1;
166914 }else{
166915 int iPk;
@@ -166919,17 +166959,35 @@
166919 for(iPk=0; iPk<nPk; iPk++){
166920 int iCol = pPk->aiColumn[iPk];
166921 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol,r+iPk);
166922 }
166923 }
 
 
 
166924 if( pRJ->regBloom ){
166925 jmp = sqlite3VdbeAddOp4Int(v, OP_Filter, pRJ->regBloom, 0, r, nPk);
 
166926 VdbeCoverage(v);
166927 }
166928 sqlite3VdbeAddOp4Int(v, OP_Found, pRJ->iMatch, addrCont, r, nPk);
166929 VdbeCoverage(v);
166930 if( jmp ) sqlite3VdbeJumpHere(v, jmp);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166931 sqlite3VdbeAddOp2(v, OP_Gosub, pRJ->regReturn, pRJ->addrSubrtn);
166932 sqlite3WhereEnd(pSubWInfo);
166933 }
166934 sqlite3ExprDelete(pParse->db, pSubWhere);
166935 ExplainQueryPlanPop(pParse);
@@ -176241,12 +176299,12 @@
176241 #endif
176242 {
176243 sqlite3VdbeChangeP5(v, bFordelete);
176244 }
176245 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
176246 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, pTabItem->iCursor, 0, 0,
176247 (const u8*)&pTabItem->colUsed, P4_INT64);
176248 #endif
176249 if( ii>=2
176250 && (pTabItem[0].fg.jointype & (JT_LTORJ|JT_LEFT))==0
176251 && pLevel->addrHalt==pWInfo->a[0].addrHalt
176252 ){
@@ -176319,12 +176377,12 @@
176319 if( jj<0 ) continue;
176320 if( jj>63 ) jj = 63;
176321 if( (pTabItem->colUsed & MASKBIT(jj))==0 ) continue;
176322 colUsed |= ((u64)1)<<(ii<63 ? ii : 63);
176323 }
176324 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, iIndexCur, 0, 0,
176325 (u8*)&colUsed, P4_INT64);
176326 }
176327 #endif /* SQLITE_ENABLE_COLUMN_USED_MASK */
176328 #ifdef SQLITE_ENABLE_CURSOR_HINTS
176329 if( HasRowid(pTab) ){
176330 sqlite3VdbeAddOp3(v, OP_CursorHint, iIndexCur, 0, pTabItem->iCursor);
@@ -190540,10 +190598,11 @@
190540 SQLITE_MAX_VARIABLE_NUMBER, /* IMP: R-38091-32352 */
190541 SQLITE_MAX_TRIGGER_DEPTH,
190542 SQLITE_MAX_WORKER_THREADS,
190543 SQLITE_MAX_PARSER_DEPTH,
190544 SQLITE_MAX_SCHEMA,
 
190545 };
190546
190547 /*
190548 ** Make sure the hard limits are set to reasonable values
190549 */
@@ -190580,10 +190639,13 @@
190580 #if SQLITE_MAX_TRIGGER_DEPTH<1
190581 # error SQLITE_MAX_TRIGGER_DEPTH must be at least 1
190582 #endif
190583 #if SQLITE_MAX_WORKER_THREADS<0 || SQLITE_MAX_WORKER_THREADS>50
190584 # error SQLITE_MAX_WORKER_THREADS must be between 0 and 50
 
 
 
190585 #endif
190586
190587
190588 /*
190589 ** Change the value of a limit. Report the old value.
@@ -190623,11 +190685,12 @@
190623 SQLITE_MAX_LIKE_PATTERN_LENGTH );
190624 assert( aHardLimit[SQLITE_LIMIT_VARIABLE_NUMBER]==SQLITE_MAX_VARIABLE_NUMBER);
190625 assert( aHardLimit[SQLITE_LIMIT_TRIGGER_DEPTH]==SQLITE_MAX_TRIGGER_DEPTH );
190626 assert( aHardLimit[SQLITE_LIMIT_WORKER_THREADS]==SQLITE_MAX_WORKER_THREADS );
190627 assert( aHardLimit[SQLITE_LIMIT_SCHEMA]==SQLITE_MAX_SCHEMA );
190628 assert( SQLITE_LIMIT_SCHEMA==(SQLITE_N_LIMIT-1) );
 
190629
190630
190631 if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
190632 return -1;
190633 }
@@ -200499,10 +200562,18 @@
200499 }
200500
200501 #define FTS4AUX_EQ_CONSTRAINT 1
200502 #define FTS4AUX_GE_CONSTRAINT 2
200503 #define FTS4AUX_LE_CONSTRAINT 4
 
 
 
 
 
 
 
 
200504
200505 /*
200506 ** xBestIndex - Analyze a WHERE and ORDER BY clause.
200507 */
200508 static int fts3auxBestIndexMethod(
@@ -200527,11 +200598,11 @@
200527 }
200528
200529 /* Search for equality and range constraints on the "term" column.
200530 ** And equality constraints on the hidden "languageid" column. */
200531 for(i=0; i<pInfo->nConstraint; i++){
200532 if( pInfo->aConstraint[i].usable ){
200533 int op = pInfo->aConstraint[i].op;
200534 int iCol = pInfo->aConstraint[i].iColumn;
200535
200536 if( iCol==0 ){
200537 if( op==SQLITE_INDEX_CONSTRAINT_EQ ) iEq = i;
@@ -200698,11 +200769,11 @@
200698 break;
200699
200700 /* State 3. The integer just read is a column number. */
200701 default: assert( eState==3 );
200702 iCol = (int)v;
200703 if( iCol<1 || iCol>(pFts3->nColumn+1) ){
200704 rc = SQLITE_CORRUPT_VTAB;
200705 break;
200706 }
200707 if( fts3auxGrowStatArray(pCsr, iCol+2) ) return SQLITE_NOMEM;
200708 pCsr->aStat[iCol+1].nDoc++;
@@ -200773,21 +200844,21 @@
200773 memset(&pCsr->csr, 0, ((u8*)&pCsr[1]) - (u8*)&pCsr->csr);
200774
200775 pCsr->filter.flags = FTS3_SEGMENT_REQUIRE_POS|FTS3_SEGMENT_IGNORE_EMPTY;
200776 if( isScan ) pCsr->filter.flags |= FTS3_SEGMENT_SCAN;
200777
200778 if( iEq>=0 || iGe>=0 ){
200779 const unsigned char *zStr = sqlite3_value_text(apVal[0]);
200780 assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) );
200781 if( zStr ){
200782 pCsr->filter.zTerm = sqlite3_mprintf("%s", zStr);
200783 if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM;
200784 pCsr->filter.nTerm = (int)strlen(pCsr->filter.zTerm);
200785 }
200786 }
200787
200788 if( iLe>=0 ){
200789 pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iLe]));
200790 if( pCsr->zStop==0 ) return SQLITE_NOMEM;
200791 pCsr->nStop = (int)strlen(pCsr->zStop);
200792 }
200793
@@ -210899,10 +210970,11 @@
210899 int nList; /* Number of phrases in expression */
210900 SnippetIter sIter; /* Iterates through snippet candidates */
210901 sqlite3_int64 nByte; /* Number of bytes of space to allocate */
210902 int iBestScore = -1; /* Best snippet score found so far */
210903 int i; /* Loop counter */
 
210904
210905 memset(&sIter, 0, sizeof(sIter));
210906
210907 /* Iterate through the phrases in the expression to count them. The same
210908 ** callback makes sure the doclists are loaded for each phrase.
@@ -210927,13 +210999,16 @@
210927 sIter.pCsr = pCsr;
210928 sIter.iCol = iCol;
210929 sIter.nSnippet = nSnippet;
210930 sIter.nPhrase = nList;
210931 sIter.iCurrent = -1;
210932 rc = sqlite3Fts3ExprIterate(
210933 pCsr->pExpr, fts3SnippetFindPositions, (void*)&sIter
210934 );
 
 
 
210935 if( rc==SQLITE_OK ){
210936
210937 /* Set the *pmSeen output variable. */
210938 for(i=0; i<nList; i++){
210939 if( sIter.aPhrase[i].pHead ){
@@ -215052,16 +215127,129 @@
215052 assert( !px.bReadOnly );
215053 sqlite3_result_blob(pStr->pCtx, px.aBlob, px.nBlob, SQLITE_DYNAMIC);
215054 }
215055 }
215056
215057 /* The byte at index i is a node type-code. This routine
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215058 ** determines the payload size for that node and writes that
215059 ** payload size in to *pSz. It returns the offset from i to the
215060 ** beginning of the payload. Return 0 on error.
215061 */
215062 static u32 jsonbPayloadSize(const JsonParse *pParse, u32 i, u32 *pSz){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215063 u8 x;
215064 u32 sz;
215065 u32 n;
215066 if( i>=pParse->nBlob ){
215067 *pSz = 0;
@@ -215112,11 +215300,65 @@
215112 return 0;
215113 }
215114 *pSz = sz;
215115 return n;
215116 }
 
 
 
 
 
215117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215118
215119 /*
215120 ** Translate the binary JSONB representation of JSON beginning at
215121 ** pParse->aBlob[i] into a JSON text string. Append the JSON
215122 ** text onto the end of pOut. Return the index in pParse->aBlob[]
@@ -215134,11 +215376,11 @@
215134 u32 i, /* Start rendering at this index */
215135 JsonString *pOut /* Write JSON here */
215136 ){
215137 u32 sz, n, j, iEnd;
215138
215139 n = jsonbPayloadSize(pParse, i, &sz);
215140 if( n==0 ){
215141 pOut->eErr |= JSTRING_MALFORMED;
215142 return pParse->nBlob+1;
215143 }
215144 switch( pParse->aBlob[i] & 0x0f ){
@@ -215474,11 +215716,11 @@
215474 u32 n, sz, i, iEnd;
215475 u32 k = 0;
215476 n = jsonbPayloadSize(pParse, iRoot, &sz);
215477 iEnd = iRoot+n+sz;
215478 for(i=iRoot+n; n>0 && i<iEnd; i+=sz+n, k++){
215479 n = jsonbPayloadSize(pParse, i, &sz);
215480 }
215481 return k;
215482 }
215483
215484 /*
@@ -215984,11 +216226,11 @@
215984 while( j<iEnd ){
215985 int rawLabel;
215986 const char *zLabel;
215987 x = pParse->aBlob[j] & 0x0f;
215988 if( x<JSONB_TEXT || x>JSONB_TEXTRAW ) return JSON_LOOKUP_ERROR;
215989 n = jsonbPayloadSize(pParse, j, &sz);
215990 if( n==0 ) return JSON_LOOKUP_ERROR;
215991 k = j+n; /* k is the index of the label text */
215992 if( k+sz>=iEnd ) return JSON_LOOKUP_ERROR;
215993 zLabel = (const char*)&pParse->aBlob[k];
215994 rawLabel = x==JSONB_TEXT || x==JSONB_TEXTRAW;
@@ -216006,11 +216248,11 @@
216006 if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
216007 return rc;
216008 }
216009 j = k+sz;
216010 if( ((pParse->aBlob[j])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
216011 n = jsonbPayloadSize(pParse, j, &sz);
216012 if( n==0 ) return JSON_LOOKUP_ERROR;
216013 j += n+sz;
216014 }
216015 if( j>iEnd ) return JSON_LOOKUP_ERROR;
216016 if( pParse->eEdit>=JEDIT_INS ){
@@ -216095,11 +216337,11 @@
216095 pParse->iDepth--;
216096 if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
216097 return rc;
216098 }
216099 kk--;
216100 n = jsonbPayloadSize(pParse, j, &sz);
216101 if( n==0 ) return JSON_LOOKUP_ERROR;
216102 j += n+sz;
216103 }
216104 if( j>iEnd ) return JSON_LOOKUP_ERROR;
216105 if( kk>0 ) return JSON_LOOKUP_NOTFOUND;
@@ -223583,10 +223825,12 @@
223583 /*
223584 ** Function: geopoly_regular(X,Y,R,N)
223585 **
223586 ** Construct a simple, convex, regular polygon centered at X, Y
223587 ** with circumradius R and with N sides.
 
 
223588 */
223589 static void geopolyRegularFunc(
223590 sqlite3_context *context,
223591 int argc,
223592 sqlite3_value **argv
@@ -223597,11 +223841,11 @@
223597 int n = sqlite3_value_int(argv[3]);
223598 int i;
223599 GeoPoly *p;
223600 (void)argc;
223601
223602 if( n<3 || r<=0.0 ) return;
223603 if( n>1000 ) n = 1000;
223604 p = sqlite3_malloc64( sizeof(*p) + (n-1)*2*sizeof(GeoCoord) );
223605 if( p==0 ){
223606 sqlite3_result_error_nomem(context);
223607 return;
@@ -233626,12 +233870,18 @@
233626 return SQLITE_OK;
233627 }
233628 default: {
233629 const struct iovec *p = (struct iovec*)pCur->pPtr;
233630 assert( pCur->eType==CARRAY_BLOB );
233631 sqlite3_result_blob(ctx, p[pCur->iRowid-1].iov_base,
233632 (int)p[pCur->iRowid-1].iov_len, SQLITE_TRANSIENT);
 
 
 
 
 
 
233633 return SQLITE_OK;
233634 }
233635 }
233636 }
233637 }
@@ -239561,14 +239811,14 @@
239561 int flags /* SESSION_APPLY_XXX flags */
239562 ){
239563 int schemaMismatch = 0;
239564 int rc = SQLITE_OK; /* Return code */
239565 const char *zTab = 0; /* Name of current table */
239566 int nTab = 0; /* Result of sqlite3Strlen30(zTab) */
239567 SessionApplyCtx sApply; /* changeset_apply() context object */
239568 int bPatchset;
239569 u64 savedFlag = db->flags & SQLITE_FkNoAction;
 
239570
239571 assert( xConflict!=0 );
239572
239573 sqlite3_mutex_enter(sqlite3_db_mutex(db));
239574 if( flags & SQLITE_CHANGESETAPPLY_FKNOACTION ){
@@ -239586,19 +239836,20 @@
239586 rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0);
239587 }
239588 if( rc==SQLITE_OK ){
239589 rc = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 1", 0, 0, 0);
239590 }
239591 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3changeset_next(pIter) ){
239592 int nCol;
239593 int op;
239594 const char *zNew;
239595
239596 sqlite3changeset_op(pIter, &zNew, &nCol, &op, 0);
239597
239598 if( zTab==0 || sqlite3_strnicmp(zNew, zTab, nTab+1) ){
239599 u8 *abPK;
 
239600
239601 rc = sessionRetryConstraints(
239602 db, pIter->bPatchset, zTab, &sApply, xConflict, pCtx
239603 );
239604 if( rc!=SQLITE_OK ) break;
@@ -239629,11 +239880,10 @@
239629 zTab = sqlite3_mprintf("%s", zNew);
239630 if( zTab==0 ){
239631 rc = SQLITE_NOMEM;
239632 break;
239633 }
239634 nTab = (int)strlen(zTab);
239635 sApply.azCol = (const char **)zTab;
239636 }else{
239637 int nMinCol = 0;
239638 int i;
239639
@@ -239682,11 +239932,10 @@
239682 break;
239683 }
239684 sApply.bStat1 = 0;
239685 }
239686 }
239687 nTab = sqlite3Strlen30(zTab);
239688 }
239689 }
239690
239691 /* If there is a schema mismatch on the current table, proceed to the
239692 ** next change. A log message has already been issued. */
@@ -251353,11 +251602,16 @@
251353 ** sequentially starting from 1.
251354 */
251355 #define FTS5_DATA_ID_B 16 /* Max seg id number 65535 */
251356 #define FTS5_DATA_DLI_B 1 /* Doclist-index flag (1 bit) */
251357 #define FTS5_DATA_HEIGHT_B 5 /* Max dlidx tree height of 32 */
251358 #define FTS5_DATA_PAGE_B 31 /* Max page number of 2147483648 */
 
 
 
 
 
251359
251360 #define fts5_dri(segid, dlidx, height, pgno) ( \
251361 ((i64)(segid) << (FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B)) + \
251362 ((i64)(dlidx) << (FTS5_DATA_PAGE_B + FTS5_DATA_HEIGHT_B)) + \
251363 ((i64)(height) << (FTS5_DATA_PAGE_B)) + \
@@ -252266,11 +252520,11 @@
252266 i += fts5GetVarint32(&pData[i], pSeg->nPgTombstone);
252267 i += fts5GetVarint(&pData[i], &pSeg->nEntryTombstone);
252268 i += fts5GetVarint(&pData[i], &pSeg->nEntry);
252269 nOriginCntr = MAX(nOriginCntr, pSeg->iOrigin2);
252270 }
252271 if( pSeg->pgnoLast<pSeg->pgnoFirst ){
252272 rc = FTS5_CORRUPT;
252273 break;
252274 }
252275 }
252276 if( iLvl>0 && pLvl[-1].nMerge && nTotal==0 ) rc = FTS5_CORRUPT;
@@ -252862,10 +253116,13 @@
252862 pLvl->pData = fts5DataRead(p, iRowid);
252863 if( pLvl->pData && (pLvl->pData->p[0] & 0x0001)==0 ){
252864 bDone = 1;
252865 }
252866 pIter->nLvl = i+1;
 
 
 
252867 }
252868 }
252869
252870 if( p->rc==SQLITE_OK ){
252871 pIter->iSegid = iSegid;
@@ -256583,38 +256840,42 @@
256583 ** iNextOff: Offset to move data from
256584 */
256585 if( p->rc==SQLITE_OK ){
256586 const int nMove = nPg - iNextOff; /* Number of bytes to move */
256587 int nShift = iNextOff - iOff; /* Distance to move them */
256588
256589 int iPrevKeyOut = 0;
256590 int iKeyIn = 0;
256591
256592 if( nMove>0 ){
256593 memmove(&aPg[iOff], &aPg[iNextOff], nMove);
256594 }
256595 iPgIdx -= nShift;
256596 nPg = iPgIdx;
256597 fts5PutU16(&aPg[2], iPgIdx);
256598
256599 for(iIdx=0; iIdx<nIdx; /* no-op */){
256600 u32 iVal = 0;
256601 iIdx += fts5GetVarint32(&aIdx[iIdx], iVal);
256602 iKeyIn += iVal;
 
 
 
 
256603 if( iKeyIn!=iDelKeyOff ){
256604 int iKeyOut = (iKeyIn - (iKeyIn>iOff ? nShift : 0));
256605 nPg += sqlite3Fts5PutVarint(&aPg[nPg], iKeyOut - iPrevKeyOut);
256606 iPrevKeyOut = iKeyOut;
256607 }
256608 }
256609
256610 if( iPgIdx==nPg && nIdx>0 && pSeg->iLeafPgno!=1 ){
256611 fts5SecureDeleteIdxEntry(p, iSegid, pSeg->iLeafPgno);
256612 }
256613
256614 assert_nc( nPg>4 || fts5GetU16(aPg)==0 );
256615 fts5DataWrite(p, FTS5_SEGMENT_ROWID(iSegid,pSeg->iLeafPgno), aPg, nPg);
256616 }
256617 sqlite3_free(aIdx);
256618 }
256619
256620 /*
@@ -264272,11 +264533,11 @@
264272 int nArg, /* Number of args */
264273 sqlite3_value **apUnused /* Function arguments */
264274 ){
264275 assert( nArg==0 );
264276 UNUSED_PARAM2(nArg, apUnused);
264277 sqlite3_result_text(pCtx, "fts5: 2026-08-11 10:46:12 fee71cd6f7294ffd02784d26811a9d11d80e83d4075e1233b8ec0289519bb891", -1, SQLITE_TRANSIENT);
264278 }
264279
264280 /*
264281 ** Implementation of fts5_locale(LOCALE, TEXT) function.
264282 **
@@ -268951,10 +269212,18 @@
268951 sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */
268952 char **pzErr /* OUT: sqlite3_malloc'd error message */
268953 ){
268954 return fts5VocabInitVtab(db, pAux, argc, argv, ppVtab, pzErr);
268955 }
 
 
 
 
 
 
 
 
268956
268957 /*
268958 ** Implementation of the xBestIndex method.
268959 **
268960 ** Only constraints of the form:
@@ -268982,11 +269251,11 @@
268982 assert( (pInfo->colUsed & FTS5_VOCAB_COLUSED_MASK)==pInfo->colUsed );
268983
268984 for(i=0; i<pInfo->nConstraint; i++){
268985 struct sqlite3_index_constraint *p = &pInfo->aConstraint[i];
268986 if( p->usable==0 ) continue;
268987 if( p->iColumn==0 ){ /* term column */
268988 if( p->op==SQLITE_INDEX_CONSTRAINT_EQ ) iTermEq = i;
268989 if( p->op==SQLITE_INDEX_CONSTRAINT_LE ) iTermLe = i;
268990 if( p->op==SQLITE_INDEX_CONSTRAINT_LT ) iTermLe = i;
268991 if( p->op==SQLITE_INDEX_CONSTRAINT_GE ) iTermGe = i;
268992 if( p->op==SQLITE_INDEX_CONSTRAINT_GT ) iTermGe = i;
@@ -269320,10 +269589,30 @@
269320 rc = FTS5_CORRUPT;
269321 }
269322 }
269323 return rc;
269324 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269325
269326 /*
269327 ** This is the xFilter implementation for the virtual table.
269328 */
269329 static int fts5VocabFilterMethod(
@@ -269354,22 +269643,19 @@
269354 if( idxNum & FTS5_VOCAB_TERM_GE ) pGe = apVal[iVal++];
269355 if( idxNum & FTS5_VOCAB_TERM_LE ) pLe = apVal[iVal++];
269356 pCsr->colUsed = (idxNum & FTS5_VOCAB_COLUSED_MASK);
269357
269358 if( pEq ){
269359 zTerm = (const char *)sqlite3_value_text(pEq);
269360 nTerm = sqlite3_value_bytes(pEq);
269361 f = FTS5INDEX_QUERY_NOTOKENDATA;
269362 }else{
269363 if( pGe ){
269364 zTerm = (const char *)sqlite3_value_text(pGe);
269365 nTerm = sqlite3_value_bytes(pGe);
269366 }
269367 if( pLe ){
269368 const char *zCopy = (const char *)sqlite3_value_text(pLe);
269369 if( zCopy==0 ) zCopy = "";
269370 pCsr->nLeTerm = sqlite3_value_bytes(pLe);
269371 pCsr->zLeTerm = sqlite3_malloc64((i64)pCsr->nLeTerm+1);
269372 if( pCsr->zLeTerm==0 ){
269373 rc = SQLITE_NOMEM;
269374 }else{
269375 memcpy(pCsr->zLeTerm, zCopy, pCsr->nLeTerm+1);
269376
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -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 ** 3bd5456e50ef321f2cafcf67261d556a7606 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
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-08-20 13:25:12 3bd5456e50ef321f2cafcf67261d556a760624ce0caab430ed9454cebec233e7"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-08-20T13:25:12.207Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -4755,10 +4755,14 @@
4755 ** [prepared statement] may start.</dd>)^
4756 **
4757 ** [[SQLITE_LIMIT_SCHEMA]] ^(<dt>SQLITE_LIMIT_SCHEMA</dt>
4758 ** <dd>The maximum number of objects (tables, indexes, triggers, and views)
4759 ** defined by the database schema.</dd>)^
4760 **
4761 ** [[SQLITE_LIMIT_TRIGGER_STEPS]] ^(<dt>SQLITE_LIMIT_TRIGGER_STEPS</dt>
4762 ** <dd>The maximum number of SQL statements that can be contained within
4763 ** a single trigger.</dd>)^
4764 ** </dl>
4765 */
4766 #define SQLITE_LIMIT_LENGTH 0
4767 #define SQLITE_LIMIT_SQL_LENGTH 1
4768 #define SQLITE_LIMIT_COLUMN 2
@@ -4771,10 +4775,11 @@
4775 #define SQLITE_LIMIT_VARIABLE_NUMBER 9
4776 #define SQLITE_LIMIT_TRIGGER_DEPTH 10
4777 #define SQLITE_LIMIT_WORKER_THREADS 11
4778 #define SQLITE_LIMIT_PARSER_DEPTH 12
4779 #define SQLITE_LIMIT_SCHEMA 13
4780 #define SQLITE_LIMIT_TRIGGER_STEPS 14
4781
4782 /*
4783 ** CAPI3REF: Prepare Flags
4784 **
4785 ** These constants define various flags that can be passed into the
@@ -15067,10 +15072,18 @@
15072 */
15073 #ifndef SQLITE_MAX_SCHEMA
15074 # define SQLITE_MAX_SCHEMA 10000000
15075 #endif
15076
15077 /*
15078 ** Maximum number of SQL statements allowed in the body of a single
15079 ** trigger.
15080 */
15081 #ifndef SQLITE_MAX_TRIGGER_STEPS
15082 # define SQLITE_MAX_TRIGGER_STEPS 65000
15083 #endif
15084
15085 /************** End of sqliteLimit.h *****************************************/
15086 /************** Continuing where we left off in sqliteInt.h ******************/
15087
15088 /* Disable nuisance warnings on Borland compilers */
15089 #if defined(__BORLANDC__)
@@ -15143,29 +15156,42 @@
15156 **
15157 ** SQLITE_INLINE Strive to in-line this function
15158 **
15159 ** SQLITE_OPT_INLINE In-line this function if building the
15160 ** amalgamation.
15161 **
15162 ** SQLITE_USES_INLINE Set to 1 or 0 according to whether or not
15163 ** inline functions are supported.
15164 */
15165 #if defined(SQLITE_DISABLE_INLINE)
15166 # define SQLITE_NOINLINE
15167 # define SQLITE_INLINE
15168 # define SQLITE_OPT_INLINE
15169 # define SQLITE_USES_INLINE 0
15170 #elif defined(__GNUC__)
15171 # define SQLITE_NOINLINE __attribute__((noinline))
15172 # define SQLITE_INLINE __attribute__((always_inline)) inline
15173 # define SQLITE_OPT_INLINE __attribute__((always_inline)) inline
15174 # define SQLITE_USES_INLINE 1
15175 #elif defined(_MSC_VER) && _MSC_VER>=1310
15176 # define SQLITE_NOINLINE __declspec(noinline)
15177 # define SQLITE_INLINE __forceinline
15178 # define SQLITE_OPT_INLINE __forceinline
15179 # define SQLITE_USES_INLINE 1
15180 #else
15181 # define SQLITE_NOINLINE
15182 # define SQLITE_INLINE
15183 # define SQLITE_OPT_INLINE
15184 # define SQLITE_USES_INLINE 0
15185 #endif
15186 #if defined(SQLITE_COVERAGE_TEST) || defined(__STRICT_ANSI__)
15187 # undef SQLITE_INLINE
15188 # define SQLITE_INLINE
15189 # undef SQLITE_OPT_INLINE
15190 # define SQLITE_OPT_INLINE
15191 # undef SQLITE_USES_INLINE
15192 # define SQLITE_USES_INLINE 0
15193 #endif
15194 #if !defined(SQLITE_AMALGAMATION)
15195 # undef SQLITE_OPT_INLINE
15196 # define SQLITE_OPT_INLINE
15197 #endif
@@ -17694,12 +17720,10 @@
17720 int p3; /* The third parameter */
17721 union p4union { /* fourth parameter */
17722 int i; /* Integer value if p4type==P4_INT32 */
17723 void *p; /* Generic pointer */
17724 char *z; /* Pointer to data for string (char array) types */
 
 
17725 FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */
17726 sqlite3_context *pCtx; /* Used when p4type is P4_FUNCCTX */
17727 CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
17728 Mem *pMem; /* Used when p4type is P4_MEM */
17729 VTable *pVtab; /* Used when p4type is P4_VTAB */
@@ -17750,10 +17774,23 @@
17774 signed char p1; /* First operand */
17775 signed char p2; /* Second parameter (often the jump destination) */
17776 signed char p3; /* Third parameter */
17777 };
17778 typedef struct VdbeOpList VdbeOpList;
17779
17780 /*
17781 ** Combine two int32 values into a single int64. The least significant
17782 ** term comes first.
17783 */
17784 #define INT32_TO_64(a,b) (i64)(((u64)(u32)(b)<<32)|(u32)(a))
17785
17786 /*
17787 ** Return an int32 that is the lower or upper 32-bits of an int64.
17788 */
17789 #define LOWER32(x) (int)(((u64)(x))&0xffffffff)
17790 #define UPPER32(x) (int)(((u64)(x))>>32)
17791
17792
17793 /*
17794 ** Allowed values of VdbeOp.p4type
17795 */
17796 #define P4_NOTUSED 0 /* The P4 parameter is not used */
@@ -17770,16 +17807,14 @@
17807 #define P4_FUNCDEF (-8) /* P4 is a pointer to a FuncDef structure */
17808 #define P4_KEYINFO (-9) /* P4 is a pointer to a KeyInfo structure */
17809 #define P4_EXPR (-10) /* P4 is a pointer to an Expr tree */
17810 #define P4_MEM (-11) /* P4 is a pointer to a Mem* structure */
17811 #define P4_VTAB (-12) /* P4 is a pointer to an sqlite3_vtab structure */
17812 #define P4_INTARRAY (-13) /* P4 is a vector of 32-bit integers */
17813 #define P4_FUNCCTX (-14) /* P4 is a pointer to an sqlite3_context object */
17814 #define P4_TABLEREF (-15) /* Like P4_TABLE, but reference counted */
17815 #define P4_SUBRTNSIG (-16) /* P4 is a SubrtnSig pointer */
 
 
17816
17817 /* Error message codes for OP_Halt */
17818 #define P5_ConstraintNotNull 1
17819 #define P5_ConstraintUnique 2
17820 #define P5_ConstraintCheck 3
@@ -17891,11 +17926,11 @@
17926 #define OP_Return 69
17927 #define OP_EndCoroutine 70
17928 #define OP_HaltIfNull 71 /* synopsis: if r[P3]=null halt */
17929 #define OP_Halt 72
17930 #define OP_Integer 73 /* synopsis: r[P2]=P1 */
17931 #define OP_Int64 74 /* synopsis: r[P2]=PINT13 */
17932 #define OP_String 75 /* synopsis: r[P2]='P4' (len=P1) */
17933 #define OP_BeginSubrtn 76 /* synopsis: r[P2]=NULL */
17934 #define OP_Null 77 /* synopsis: r[P2..P3]=NULL */
17935 #define OP_SoftNull 78 /* synopsis: r[P1]=NULL */
17936 #define OP_Blob 79 /* synopsis: r[P2]=P4 (len=P1) */
@@ -17942,11 +17977,11 @@
17977 #define OP_OpenEphemeral 120 /* synopsis: nColumn=P2 */
17978 #define OP_SorterOpen 121
17979 #define OP_SequenceTest 122 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
17980 #define OP_OpenPseudo 123 /* synopsis: P3 columns in r[P2] */
17981 #define OP_Close 124
17982 #define OP_ColumnsUsed 125 /* synopsis: Cursor P1 uses columns PHEX23 */
17983 #define OP_SeekScan 126 /* synopsis: Scan-ahead up to P1 rows */
17984 #define OP_SeekHit 127 /* synopsis: set P2<=seekHit<=P3 */
17985 #define OP_Sequence 128 /* synopsis: r[P2]=cursor[P1].ctr++ */
17986 #define OP_NewRowid 129 /* synopsis: r[P2]=rowid */
17987 #define OP_Insert 130 /* synopsis: intkey=r[P3] data=r[P2] */
@@ -17971,11 +18006,11 @@
18006 #define OP_CreateBtree 149 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
18007 #define OP_SqlExec 150
18008 #define OP_ParseSchema 151
18009 #define OP_LoadAnalysis 152
18010 #define OP_DropTable 153
18011 #define OP_Real 154 /* same as TK_FLOAT, synopsis: r[P2]=PDBL13 */
18012 #define OP_DropIndex 155
18013 #define OP_DropTrigger 156
18014 #define OP_IntegrityCk 157
18015 #define OP_RowSetAdd 158 /* synopsis: rowset(P1)=r[P2] */
18016 #define OP_Param 159
@@ -18079,12 +18114,13 @@
18114 SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
18115 SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe*,int);
18116 SQLITE_PRIVATE int sqlite3VdbeLoadString(Vdbe*,int,const char*);
18117 SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...);
18118 SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
18119 SQLITE_PRIVATE int sqlite3VdbeAddInt64(Vdbe*,int,i64);
18120 SQLITE_PRIVATE int sqlite3VdbeAddDouble(Vdbe*,int,double);
18121 SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
 
18122 SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
18123 SQLITE_PRIVATE int sqlite3VdbeAddFunctionCall(Parse*,int,int,int,int,const FuncDef*,int);
18124 SQLITE_PRIVATE void sqlite3VdbeEndCoroutine(Vdbe*,int);
18125 #if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS)
18126 SQLITE_PRIVATE void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N);
@@ -18331,10 +18367,11 @@
18367 ** This header file defines the interface that the sqlite page cache
18368 ** subsystem.
18369 */
18370
18371 #ifndef _PCACHE_H_
18372 #define _PCACHE_H_
18373
18374 typedef struct PgHdr PgHdr;
18375 typedef struct PCache PCache;
18376
18377 /*
@@ -18689,11 +18726,11 @@
18726
18727 /*
18728 ** The number of different kinds of things that can be limited
18729 ** using the sqlite3_limit() interface.
18730 */
18731 #define SQLITE_N_LIMIT (SQLITE_LIMIT_TRIGGER_STEPS+1)
18732
18733 /*
18734 ** Lookaside malloc is a set of fixed-size buffers that can be used
18735 ** to satisfy small transient memory allocation requests for objects
18736 ** associated with a particular database connection. The use of
@@ -21008,10 +21045,17 @@
21045 ParseCleanup *pNext; /* Next cleanup task */
21046 void *pPtr; /* Pointer to object to deallocate */
21047 void (*xCleanup)(sqlite3*,void*); /* Deallocation routine */
21048 };
21049
21050 /*
21051 ** Number of 64-bit entried in the variable number bitmap cache (VNBMC).
21052 */
21053 #ifndef SQLITE_VNBMC
21054 # define SQLITE_VNBMC 2
21055 #endif
21056
21057 /*
21058 ** An SQL parser context. A copy of this structure is passed through
21059 ** the parser and down into all the parser action routine in order to
21060 ** carry around information that is global to the entire parse.
21061 **
@@ -21126,10 +21170,11 @@
21170 ** first field in the recursive region.
21171 ************************************************************************/
21172
21173 Token sLastToken; /* The last token parsed */
21174 ynVar nVar; /* Number of '?' variables seen in the SQL so far */
21175 u64 aVnbmc[SQLITE_VNBMC]; /* Varible Number Bitmap Cache */
21176 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
21177 u8 explain; /* True if the EXPLAIN flag is found on the query */
21178 u8 eParseMode; /* PARSE_MODE_XXX constant */
21179 #ifndef SQLITE_OMIT_VIRTUALTABLE
21180 int nVtabLock; /* Number of virtual tables to lock */
@@ -22165,10 +22210,11 @@
22210 SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int,int);
22211 SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,const Token*,int);
22212 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);
22213 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
22214 SQLITE_PRIVATE void sqlite3ExprListDeleteGeneric(sqlite3*,void*);
22215 SQLITE_PRIVATE int sqlite3ExprCanReturnSubtype(Parse*,Expr*);
22216 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
22217 SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage(Index*);
22218 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
22219 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
22220 SQLITE_PRIVATE int sqlite3InitOne(sqlite3*, int, char**, u32);
@@ -22389,10 +22435,11 @@
22435 SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*);
22436 SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse*,Expr*);
22437 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
22438 SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
22439 SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int,int);
22440 SQLITE_PRIVATE int sqlite3ExprListIsConstant(Parse *pParse, ExprList *pList, int bNoIs);
22441 #ifdef SQLITE_ENABLE_CURSOR_HINTS
22442 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
22443 #endif
22444 SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*, Parse*);
22445 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
@@ -22544,10 +22591,11 @@
22591 ** be defined locally, but now we use the varint routines in the util.c
22592 ** file.
22593 */
22594 SQLITE_PRIVATE int sqlite3PutVarint(unsigned char*, u64);
22595 SQLITE_PRIVATE u8 sqlite3GetVarint(const unsigned char *, u64 *);
22596 SQLITE_PRIVATE i64 sqlite3VarintValue(const unsigned char*);
22597 SQLITE_PRIVATE u8 sqlite3GetVarint32(const unsigned char *, u32 *);
22598 SQLITE_PRIVATE int sqlite3VarintLen(u64 v);
22599
22600 /*
22601 ** The common case is for a varint to be a single byte. They following
@@ -22559,13 +22607,10 @@
22607 #define getVarint32NR(A,B) \
22608 B=(u32)*(A);if(B>=0x80)sqlite3GetVarint32((A),(u32*)&(B))
22609 #define putVarint32(A,B) \
22610 (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\
22611 sqlite3PutVarint((A),(B)))
 
 
 
22612
22613 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3*, Index*);
22614 SQLITE_PRIVATE char *sqlite3TableAffinityStr(sqlite3*,const Table*);
22615 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
22616 SQLITE_PRIVATE char sqlite3CompareAffinity(const Expr *pExpr, char aff2);
@@ -38343,176 +38388,88 @@
38388 p[1] = v&0x7f;
38389 return 2;
38390 }
38391 return putVarint64(p,v);
38392 }
 
 
 
 
 
 
 
 
 
 
 
 
 
38393
38394 /*
38395 ** Read a 64-bit variable-length integer from memory starting at p[0].
38396 ** Return the number of bytes read. The value is stored in *v.
38397 */
38398 SQLITE_PRIVATE u8 sqlite3GetVarint(const unsigned char *p, u64 *v){
38399 u64 iKey = p[0];
38400 const u8 *pStart = p;
38401 if( iKey>=0x80 ){
38402 u8 x;
38403 iKey = (iKey<<7) ^ (x = *++p);
38404 if( x>=0x80 ){
38405 iKey = (iKey<<7) ^ (x = *++p);
38406 if( x>=0x80 ){
38407 iKey = (iKey<<7) ^ 0x10204000 ^ (x = *++p);
38408 if( x>=0x80 ){
38409 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38410 if( x>=0x80 ){
38411 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38412 if( x>=0x80 ){
38413 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38414 if( x>=0x80 ){
38415 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38416 if( x>=0x80 ){
38417 iKey = (iKey<<8) ^ 0x8000 ^ (*++p);
38418 }
38419 }
38420 }
38421 }
38422 }
38423 }else{
38424 iKey ^= 0x204000;
38425 }
38426 }else{
38427 iKey ^= 0x4000;
38428 }
38429 }
38430 *v = iKey;
38431 return (u8)(p - pStart) + 1;
38432 }
38433
38434 /*
38435 ** Return the value of a variable-length integer without computing
38436 ** its length. This is an optimization on sqlite3GetVarint() for the
38437 ** cases when the return value of sqlite3GetVarint() is not needed.
38438 */
38439 SQLITE_PRIVATE i64 sqlite3VarintValue(const unsigned char *p){
38440 u64 iKey = p[0];
38441 if( iKey>=0x80 ){
38442 u8 x;
38443 iKey = (iKey<<7) ^ (x = *++p);
38444 if( x>=0x80 ){
38445 iKey = (iKey<<7) ^ (x = *++p);
38446 if( x>=0x80 ){
38447 iKey = (iKey<<7) ^ 0x10204000 ^ (x = *++p);
38448 if( x>=0x80 ){
38449 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38450 if( x>=0x80 ){
38451 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38452 if( x>=0x80 ){
38453 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38454 if( x>=0x80 ){
38455 iKey = (iKey<<7) ^ 0x4000 ^ (x = *++p);
38456 if( x>=0x80 ){
38457 iKey = (iKey<<8) ^ 0x8000 ^ (*++p);
38458 }
38459 }
38460 }
38461 }
38462 }
38463 }else{
38464 iKey ^= 0x204000;
38465 }
38466 }else{
38467 iKey ^= 0x4000;
38468 }
38469 }
38470 return *(i64*)&iKey;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38471 }
38472
38473 /*
38474 ** Read a 32-bit variable-length integer from memory starting at p[0].
38475 ** Return the number of bytes read. The value is stored in *v.
@@ -39405,11 +39362,11 @@
39362 /* 69 */ "Return" OpHelp(""),
39363 /* 70 */ "EndCoroutine" OpHelp(""),
39364 /* 71 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
39365 /* 72 */ "Halt" OpHelp(""),
39366 /* 73 */ "Integer" OpHelp("r[P2]=P1"),
39367 /* 74 */ "Int64" OpHelp("r[P2]=PINT13"),
39368 /* 75 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
39369 /* 76 */ "BeginSubrtn" OpHelp("r[P2]=NULL"),
39370 /* 77 */ "Null" OpHelp("r[P2..P3]=NULL"),
39371 /* 78 */ "SoftNull" OpHelp("r[P1]=NULL"),
39372 /* 79 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
@@ -39456,11 +39413,11 @@
39413 /* 120 */ "OpenEphemeral" OpHelp("nColumn=P2"),
39414 /* 121 */ "SorterOpen" OpHelp(""),
39415 /* 122 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
39416 /* 123 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
39417 /* 124 */ "Close" OpHelp(""),
39418 /* 125 */ "ColumnsUsed" OpHelp("Cursor P1 uses columns PHEX23"),
39419 /* 126 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"),
39420 /* 127 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"),
39421 /* 128 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
39422 /* 129 */ "NewRowid" OpHelp("r[P2]=rowid"),
39423 /* 130 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
@@ -39485,11 +39442,11 @@
39442 /* 149 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
39443 /* 150 */ "SqlExec" OpHelp(""),
39444 /* 151 */ "ParseSchema" OpHelp(""),
39445 /* 152 */ "LoadAnalysis" OpHelp(""),
39446 /* 153 */ "DropTable" OpHelp(""),
39447 /* 154 */ "Real" OpHelp("r[P2]=PDBL13"),
39448 /* 155 */ "DropIndex" OpHelp(""),
39449 /* 156 */ "DropTrigger" OpHelp(""),
39450 /* 157 */ "IntegrityCk" OpHelp(""),
39451 /* 158 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
39452 /* 159 */ "Param" OpHelp(""),
@@ -57486,10 +57443,11 @@
57443
57444 nNew = 2*(u64)p->nHash;
57445 if( nNew<256 ){
57446 nNew = 256;
57447 }
57448 assert( (nNew & (nNew-1))==0 ); /* nNew is always a power of two */
57449
57450 pcache1LeaveMutex(p->pGroup);
57451 if( p->nHash ){ sqlite3BeginBenignMalloc(); }
57452 apNew = (PgHdr1 **)sqlite3MallocZero(sizeof(PgHdr1 *)*nNew);
57453 if( p->nHash ){ sqlite3EndBenignMalloc(); }
@@ -57497,11 +57455,11 @@
57455 if( apNew ){
57456 for(i=0; i<p->nHash; i++){
57457 PgHdr1 *pPage;
57458 PgHdr1 *pNext = p->apHash[i];
57459 while( (pPage = pNext)!=0 ){
57460 unsigned int h = (unsigned int)(pPage->iKey & (nNew-1));
57461 pNext = pPage->pNext;
57462 pPage->pNext = apNew[h];
57463 apNew[h] = pPage;
57464 }
57465 }
@@ -57547,11 +57505,12 @@
57505 unsigned int h;
57506 PCache1 *pCache = pPage->pCache;
57507 PgHdr1 **pp;
57508
57509 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
57510 assert( pCache->nHash>0 && (pCache->nHash & (pCache->nHash-1))==0 );
57511 h = pPage->iKey & (pCache->nHash-1);
57512 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
57513 *pp = (*pp)->pNext;
57514
57515 pCache->nPage--;
57516 if( freeFlag ) pcache1FreePage(pPage);
@@ -57592,18 +57551,18 @@
57551 ){
57552 TESTONLY( int nPage = 0; ) /* To assert pCache->nPage is correct */
57553 unsigned int h, iStop;
57554 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
57555 assert( pCache->iMaxKey >= iLimit );
57556 assert( pCache->nHash>0 && (pCache->nHash & (pCache->nHash-1))==0 );
57557 if( pCache->iMaxKey - iLimit < pCache->nHash ){
57558 /* If we are just shaving the last few pages off the end of the
57559 ** cache, then there is no point in scanning the entire hash table.
57560 ** Only scan those hash slots that might contain pages that need to
57561 ** be removed. */
57562 h = iLimit & (pCache->nHash-1);
57563 iStop = pCache->iMaxKey & (pCache->nHash-1);
57564 TESTONLY( nPage = -10; ) /* Disable the pCache->nPage validity check */
57565 }else{
57566 /* This is the general case where many pages are being removed.
57567 ** It is necessary to scan the entire hash table */
57568 h = pCache->nHash/2;
@@ -57624,11 +57583,11 @@
57583 pp = &pPage->pNext;
57584 TESTONLY( if( nPage>=0 ) nPage++; )
57585 }
57586 }
57587 if( h==iStop ) break;
57588 h = (h+1) & (pCache->nHash-1);
57589 }
57590 assert( nPage<0 || pCache->nPage==(unsigned)nPage );
57591 }
57592
57593 /******************************************************************************/
@@ -57836,10 +57795,11 @@
57795 return 0;
57796 }
57797
57798 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
57799 assert( pCache->nHash>0 && pCache->apHash );
57800 assert( (pCache->nHash & (pCache->nHash-1))==0 );
57801
57802 /* Step 4. Try to recycle a page. */
57803 if( pCache->bPurgeable
57804 && !pGroup->lru.pLruPrev->isAnchor
57805 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
@@ -57864,11 +57824,11 @@
57824 if( !pPage ){
57825 pPage = pcache1AllocPage(pCache, createFlag==1);
57826 }
57827
57828 if( pPage ){
57829 unsigned int h = iKey & (pCache->nHash-1);
57830 pCache->nPage++;
57831 pPage->iKey = iKey;
57832 pPage->pNext = pCache->apHash[h];
57833 pPage->pCache = pCache;
57834 pPage->pLruNext = 0;
@@ -58071,19 +58031,20 @@
58031 assert( iOld!=iNew ); /* The page number really is changing */
58032
58033 pcache1EnterMutex(pCache->pGroup);
58034
58035 assert( pcache1FetchNoMutex(p, iOld, 0)==pPage ); /* pPg really is iOld */
58036 assert( pCache->nHash>0 && (pCache->nHash & (pCache->nHash-1))==0 );
58037 hOld = iOld & (pCache->nHash-1);
58038 pp = &pCache->apHash[hOld];
58039 while( (*pp)!=pPage ){
58040 pp = &(*pp)->pNext;
58041 }
58042 *pp = pPage->pNext;
58043
58044 assert( pcache1FetchNoMutex(p, iNew, 0)==0 ); /* iNew not in cache */
58045 hNew = iNew & (pCache->nHash-1);
58046 pPage->iKey = iNew;
58047 pPage->pNext = pCache->apHash[hNew];
58048 pCache->apHash[hNew] = pPage;
58049 if( iNew>pCache->iMaxKey ){
58050 pCache->iMaxKey = iNew;
@@ -63895,11 +63856,19 @@
63856
63857 /* Open the pager file.
63858 */
63859 if( zFilename && zFilename[0] ){
63860 int fout = 0; /* VFS flags returned by xOpen() */
63861 int bImmutable = sqlite3_uri_boolean(pPager->zFilename, "immutable", 0);
63862 if( bImmutable ){
63863 vfsFlags |= SQLITE_OPEN_READONLY;
63864 vfsFlags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
63865 }
63866 rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
63867 if( bImmutable ){
63868 goto act_like_temp_file;
63869 }
63870 assert( !memDb );
63871 pPager->memVfs = memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
63872 readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
63873
63874 /* If the file was successfully opened for read/write access,
@@ -63935,14 +63904,13 @@
63904 }
63905 }
63906 #endif
63907 }
63908 pPager->noLock = sqlite3_uri_boolean(pPager->zFilename, "nolock", 0);
63909 if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0 ){
63910 vfsFlags |= SQLITE_OPEN_READONLY;
63911 goto act_like_temp_file;
 
63912 }
63913 }
63914 }else{
63915 /* If a temporary file is requested, it is not opened immediately.
63916 ** In this case we accept the default page size and delay actually
@@ -63958,10 +63926,11 @@
63926 tempFile = 1;
63927 pPager->eState = PAGER_READER; /* Pretend we already have a lock */
63928 pPager->eLock = EXCLUSIVE_LOCK; /* Pretend we are in EXCLUSIVE mode */
63929 pPager->noLock = 1; /* Do no locking */
63930 readOnly = (vfsFlags&SQLITE_OPEN_READONLY);
63931 assert( readOnly==0 || readOnly==1 );
63932 }
63933
63934 /* The following call to PagerSetPagesize() serves to set the value of
63935 ** Pager.pageSize and to allocate the Pager.pTmpSpace buffer.
63936 */
@@ -70452,15 +70421,19 @@
70421 ){
70422 int sz;
70423 i64 iOffset;
70424 sz = pWal->hdr.szPage;
70425 sz = (sz&0xfe00) + ((sz&0x0001)<<16);
70426 if( nOut>sz ){
70427 memset(pOut+sz, 0, nOut-sz);
70428 nOut = sz;
70429 }
70430 testcase( sz<=32768 );
70431 testcase( sz>=65536 );
70432 iOffset = walFrameOffset(iRead, sz) + WAL_FRAME_HDRSIZE;
70433 /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
70434 return sqlite3OsRead(pWal->pWalFd, pOut, nOut, iOffset);
70435 }
70436
70437 /*
70438 ** Return the size of the database in pages (or zero, if unknown).
70439 */
@@ -72163,10 +72136,11 @@
72136 Pgno nCkPage; /* Pages in the database. 0 for partial check */
72137 int mxErr; /* Stop accumulating errors when this reaches zero */
72138 int nErr; /* Number of messages written to zErrMsg so far */
72139 int rc; /* SQLITE_OK, SQLITE_NOMEM, or SQLITE_INTERRUPT */
72140 u32 nStep; /* Number of steps into the integrity_check process */
72141 u8 nAbove; /* Current btree recursion depth */
72142 const char *zPfx; /* Error message prefix */
72143 Pgno v0; /* Value for first %u substitution in zPfx (root page) */
72144 Pgno v1; /* Value for second %u substitution in zPfx (current pg) */
72145 int v2; /* Value for third %d substitution in zPfx */
72146 StrAccum errMsg; /* Accumulate the error message text here */
@@ -73774,11 +73748,11 @@
73748 assert( pPage->leaf==0 );
73749 assert( pPage->childPtrSize==4 );
73750 #ifndef SQLITE_DEBUG
73751 UNUSED_PARAMETER(pPage);
73752 #endif
73753 pInfo->nSize = 4 + sqlite3GetVarint(&pCell[4], (u64*)&pInfo->nKey);
73754 pInfo->nPayload = 0;
73755 pInfo->nLocal = 0;
73756 pInfo->pPayload = 0;
73757 return;
73758 }
@@ -73814,11 +73788,11 @@
73788 }
73789 pIter++;
73790
73791 /* The next block of code is equivalent to:
73792 **
73793 ** pIter += sqlite3GetVarint(pIter, (u64*)&pInfo->nKey);
73794 **
73795 ** The code is inlined and the loop is unrolled for performance.
73796 ** This routine is a high-runner.
73797 */
73798 iKey = *pIter;
@@ -78425,11 +78399,11 @@
78399 if( pCell>=pPage->aDataEnd ){
78400 return SQLITE_CORRUPT_PAGE(pPage);
78401 }
78402 }
78403 }
78404 nCellKey = sqlite3VarintValue(pCell);
78405 if( nCellKey<intKey ){
78406 lwr = idx+1;
78407 if( lwr>upr ){ c = -1; break; }
78408 }else if( nCellKey>intKey ){
78409 upr = idx-1;
@@ -79632,11 +79606,11 @@
79606 nPayload = pX->nData + pX->nZero;
79607 pSrc = pX->pData;
79608 nSrc = pX->nData;
79609 assert( pPage->intKeyLeaf ); /* fillInCell() only called for leaves */
79610 nHeader += putVarint32(&pCell[nHeader], nPayload);
79611 nHeader += sqlite3PutVarint(&pCell[nHeader], *(u64*)&pX->nKey);
79612 }else{
79613 assert( pX->nKey<=0x7fffffff && pX->pKey!=0 );
79614 nSrc = nPayload = (int)pX->nKey;
79615 pSrc = pX->pKey;
79616 nHeader += putVarint32(&pCell[nHeader], nPayload);
@@ -81381,11 +81355,11 @@
81355 */
81356 CellInfo info;
81357 j--;
81358 pNew->xParseCell(pNew, b.apCell[j], &info);
81359 pCell = pTemp;
81360 sz = 4 + sqlite3PutVarint(&pCell[4], info.nKey);
81361 pTemp = 0;
81362 }else{
81363 pCell -= 4;
81364 /* Obscure case for non-leaf-data trees: If the cell at pCell was
81365 ** previously stored on a leaf node, and its reported size was 4
@@ -82266,11 +82240,11 @@
82240 if( pSrc->info.nPayload<0x80 ){
82241 *(aOut++) = (u8)pSrc->info.nPayload;
82242 }else{
82243 aOut += sqlite3PutVarint(aOut, pSrc->info.nPayload);
82244 }
82245 if( pDest->pKeyInfo==0 ) aOut += sqlite3PutVarint(aOut, iKey);
82246 nIn = pSrc->info.nLocal;
82247 aIn = pSrc->info.pPayload;
82248 if( aIn+nIn>pSrc->pPage->aDataEnd ){
82249 return SQLITE_CORRUPT_PAGE(pSrc->pPage);
82250 }
@@ -82736,15 +82710,24 @@
82710 }
82711
82712 /*
82713 ** Erase the given database page and all its children. Return
82714 ** the page to the freelist.
82715 **
82716 ** The freePageFlag parameter serves a double role:
82717 **
82718 ** * Bit 0 (freePageFlag&1) means that the page should be freed
82719 ** after it is cleared.
82720 **
82721 ** * Bits 1-31 (freePageFlag>>1) is the depth of recursion. Use this
82722 ** to prevent a corrupt database file from recursing too deeply and
82723 ** overflowing the CPU stack.
82724 */
82725 static int clearDatabasePage(
82726 BtShared *pBt, /* The BTree that contains the table */
82727 Pgno pgno, /* Page number to clear */
82728 int freePageFlag, /* bit 0: Deallocate page. Bits 1-31: depth */
82729 i64 *pnChange /* Add number of Cells freed to this counter */
82730 ){
82731 MemPage *pPage;
82732 int rc;
82733 unsigned char *pCell;
@@ -82753,10 +82736,13 @@
82736 CellInfo info;
82737
82738 assert( sqlite3_mutex_held(pBt->mutex) );
82739 if( pgno>btreePagecount(pBt) ){
82740 return SQLITE_CORRUPT_PGNO(pgno);
82741 }
82742 if( (freePageFlag>>1) > BTCURSOR_MAX_DEPTH ){
82743 return SQLITE_CORRUPT_PGNO(pgno);
82744 }
82745 rc = getAndInitPage(pBt, pgno, &pPage, 0);
82746 if( rc ) return rc;
82747 if( (pBt->openFlags & BTREE_SINGLE)==0
82748 && sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1))
@@ -82766,26 +82752,28 @@
82752 }
82753 hdr = pPage->hdrOffset;
82754 for(i=0; i<pPage->nCell; i++){
82755 pCell = findCell(pPage, i);
82756 if( !pPage->leaf ){
82757 rc = clearDatabasePage(pBt, get4byte(pCell),
82758 (freePageFlag+2)|1, pnChange);
82759 if( rc ) goto cleardatabasepage_out;
82760 }
82761 BTREE_CLEAR_CELL(rc, pPage, pCell, info);
82762 if( rc ) goto cleardatabasepage_out;
82763 }
82764 if( !pPage->leaf ){
82765 rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]),
82766 (freePageFlag+2)|1, pnChange);
82767 if( rc ) goto cleardatabasepage_out;
82768 if( pPage->intKey ) pnChange = 0;
82769 }
82770 if( pnChange ){
82771 testcase( !pPage->intKey );
82772 *pnChange += pPage->nCell;
82773 }
82774 if( (freePageFlag&1)!=0 ){
82775 freePage(pPage, &rc);
82776 }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
82777 zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF);
82778 }
82779
@@ -83416,22 +83404,27 @@
83404 u8 savedIsInit = 0;
83405
83406 /* Check that the page exists
83407 */
83408 checkProgress(pCheck);
83409 if( pCheck->mxErr==0 ) return 0;
83410 pBt = pCheck->pBt;
83411 usableSize = pBt->usableSize;
83412 if( iPage==0 ) return 0;
83413 if( checkRef(pCheck, iPage) ) return 0;
83414 pCheck->zPfx = "Tree %u page %u: ";
83415 pCheck->v1 = iPage;
83416 pCheck->nAbove++;
83417 if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
83418 checkAppendMsg(pCheck,
83419 "unable to get the page. error code=%d", rc);
83420 if( rc==SQLITE_IOERR_NOMEM ) pCheck->rc = SQLITE_NOMEM;
83421 goto end_of_check;
83422 }
83423 if( pCheck->nAbove > BTCURSOR_MAX_DEPTH ){
83424 checkAppendMsg(pCheck,"btree depth exceeds %d",BTCURSOR_MAX_DEPTH);
83425 goto end_of_check;
83426 }
83427
83428 /* Clear MemPage.isInit to make sure the corruption detection code in
83429 ** btreeInitPage() is executed. */
83430 savedIsInit = pPage->isInit;
@@ -83648,10 +83641,11 @@
83641 if( !doCoverageCheck ) pPage->isInit = savedIsInit;
83642 releasePage(pPage);
83643 pCheck->zPfx = saved_zPfx;
83644 pCheck->v1 = saved_v1;
83645 pCheck->v2 = saved_v2;
83646 pCheck->nAbove--;
83647 return depth+1;
83648 }
83649 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
83650
83651 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
@@ -83780,11 +83774,13 @@
83774 if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){
83775 checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
83776 }
83777 #endif
83778 sCheck.v0 = aRoot[i];
83779 assert( sCheck.nAbove==0 );
83780 checkTreePage(&sCheck, aRoot[i], &notUsed, LARGEST_INT64);
83781 assert( sCheck.nAbove==0 );
83782 }
83783 sqlite3MemSetArrayInt64(aCnt, i, sCheck.nRow);
83784 }
83785 pBt->db->flags = savedDbFlags;
83786
@@ -87553,10 +87549,24 @@
87549 /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87550 ** Replicate in sqlite3VdbeAddOp3() */
87551
87552 return i;
87553 }
87554
87555 /* Generate an opcode that loads a 64-bit integer into register iDest
87556 */
87557 SQLITE_PRIVATE int sqlite3VdbeAddInt64(Vdbe *p, int iDest, i64 iVal){
87558 return sqlite3VdbeAddOp3(p, OP_Int64, LOWER32(iVal), iDest, UPPER32(iVal));
87559 }
87560
87561 /* Generate an opcode that loads a 64-floating point value into register iDest.
87562 */
87563 SQLITE_PRIVATE int sqlite3VdbeAddDouble(Vdbe *p, int iDest, double rVal){
87564 i64 iVal;
87565 memcpy(&iVal,&rVal,8);
87566 return sqlite3VdbeAddOp3(p, OP_Real, LOWER32(iVal), iDest, UPPER32(iVal));
87567 }
87568
87569 /* Generate code for an unconditional jump to instruction iDest
87570 */
87571 SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe *p, int iDest){
87572 return sqlite3VdbeAddOp3(p, OP_Goto, 0, iDest, 0);
@@ -87657,28 +87667,10 @@
87667 sqlite3VdbeChangeP5(v, eCallCtx & NC_SelfRef);
87668 sqlite3MayAbort(pParse);
87669 return addr;
87670 }
87671
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87672 #ifndef SQLITE_OMIT_EXPLAIN
87673 /*
87674 ** Return the address of the current EXPLAIN QUERY PLAN baseline.
87675 ** 0 means "none".
87676 */
@@ -88581,12 +88573,10 @@
88573 switch( p4type ){
88574 case P4_FUNCCTX: {
88575 freeP4FuncCtx(db, (sqlite3_context*)p4);
88576 break;
88577 }
 
 
88578 case P4_DYNAMIC:
88579 case P4_INTARRAY: {
88580 if( p4 ) sqlite3DbNNFreeNN(db, p4);
88581 break;
88582 }
@@ -88936,10 +88926,13 @@
88926 **
88927 ** "PX" -> "r[X]"
88928 ** "PX@PY" -> "r[X..X+Y-1]" or "r[x]" if y is 0 or 1
88929 ** "PX@PY+1" -> "r[X..X+Y]" or "r[x]" if y is 0
88930 ** "PY..PY" -> "r[X..Y]" or "r[x]" if y<=x
88931 ** "PINT13" -> int(P1|P3<<32)
88932 ** "PDBL13" -> real(P1|P3<<32)
88933 ** "PHEX23" -> hex(P2|P3<<32)
88934 */
88935 SQLITE_PRIVATE char *sqlite3VdbeDisplayComment(
88936 sqlite3 *db, /* Optional - Oom error reporting only */
88937 const Op *pOp, /* The opcode to be commented */
88938 const char *zP4 /* Previously obtained value for P4 */
@@ -88971,10 +88964,24 @@
88964 if( pOp->zComment && pOp->zComment[0] ){
88965 sqlite3_str_appendall(&x, pOp->zComment);
88966 seenCom = 1;
88967 break;
88968 }
88969 }else if( strncmp(&zSynopsis[ii],"INT13",5)==0 ){
88970 sqlite3_str_appendf(&x,"%lld",INT32_TO_64(pOp->p1,pOp->p3));
88971 ii += 4;
88972 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
88973 }else if( strncmp(&zSynopsis[ii],"HEX23",5)==0 ){
88974 sqlite3_str_appendf(&x,"0x%llx",INT32_TO_64(pOp->p2,pOp->p3));
88975 ii += 4;
88976 #endif
88977 }else if( strncmp(&zSynopsis[ii],"DBL13",5)==0 ){
88978 i64 iVal = INT32_TO_64(pOp->p1,pOp->p3);
88979 double r;
88980 memcpy(&r, &iVal, 8);
88981 sqlite3_str_appendf(&x,"%.17g",r);
88982 ii += 4;
88983 }else{
88984 int v1 = translateP(c, pOp);
88985 int v2;
88986 if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
88987 ii += 3;
@@ -89148,22 +89155,14 @@
89155 case P4_FUNCCTX: {
89156 FuncDef *pDef = pOp->p4.pCtx->pFunc;
89157 sqlite3_str_appendf(&x, "%s(%d)", pDef->zName, pDef->nArg);
89158 break;
89159 }
 
 
 
 
89160 case P4_INT32: {
89161 sqlite3_str_appendf(&x, "%d", pOp->p4.i);
89162 break;
89163 }
 
 
 
 
89164 case P4_MEM: {
89165 Mem *pMem = pOp->p4.pMem;
89166 if( pMem->flags & MEM_Str ){
89167 zP4 = pMem->z;
89168 }else if( pMem->flags & (MEM_Int|MEM_IntReal) ){
@@ -97360,35 +97359,39 @@
97359 pOut = out2Prerelease(p, pOp);
97360 pOut->u.i = pOp->p1;
97361 break;
97362 }
97363
97364 /* Opcode: Int64 P1 P2 P3 * *
97365 ** Synopsis: r[P2]=PINT13
97366 **
97367 ** Combine P1 and P3 into a signed 64-bit integer. P1 is the least
97368 ** significant 32 bits and P3 is the most significant. Store the
97369 ** result in register P2.
97370 */
97371 case OP_Int64: { /* out2 */
97372 pOut = out2Prerelease(p, pOp);
97373 pOut->u.i = INT32_TO_64(pOp->p1,pOp->p3);
 
97374 break;
97375 }
97376
97377 #ifndef SQLITE_OMIT_FLOATING_POINT
97378 /* Opcode: Real P1 P2 P3 * *
97379 ** Synopsis: r[P2]=PDBL13
97380 **
97381 ** P1 and P3 are combined to 64 bits with P1 being the lower the P3
97382 ** the upper. The result is interpreted as a 64-bit floating-point
97383 ** and stored in register P2.
97384 */
97385 case OP_Real: { /* same as TK_FLOAT, out2 */
97386 u64 ii;
97387 pOut = out2Prerelease(p, pOp);
97388 pOut->flags = MEM_Real;
97389 ii = (u64)INT32_TO_64(pOp->p1,pOp->p3);
97390 swapMixedEndianFloat(ii);
97391 memcpy(&pOut->u.r, &ii, 8);
97392 assert( !sqlite3IsNaN(pOut->u.r) );
97393 break;
97394 }
97395 #endif
97396
97397 /* Opcode: String8 * P2 * P4 *
@@ -99461,26 +99464,13 @@
99464 while( 1 /*exit-by-break*/ ){
99465 assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
99466 assert( zAffinity[0]==SQLITE_AFF_NONE || memIsValid(pIn1) );
99467 applyAffinity(pIn1, zAffinity[0], encoding);
99468 if( zAffinity[0]==SQLITE_AFF_REAL && (pIn1->flags & MEM_Int)!=0 ){
99469 pIn1->u.r = (double)pIn1->u.i;
99470 pIn1->flags |= MEM_Real;
99471 pIn1->flags &= ~(MEM_Int|MEM_Str);
 
 
 
 
 
 
 
 
 
 
 
 
 
99472 }
99473 REGISTER_TRACE((int)(pIn1-aMem), pIn1);
99474 zAffinity++;
99475 if( zAffinity[0]==0 ) break;
99476 pIn1++;
@@ -100794,25 +100784,25 @@
100784 p->apCsr[pOp->p1] = 0;
100785 break;
100786 }
100787
100788 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
100789 /* Opcode: ColumnsUsed P1 P2 P3 * *
100790 ** Synopsis: Cursor P1 uses columns PHEX23
100791 **
100792 ** This opcode (which only exists if SQLite was compiled with
100793 ** SQLITE_ENABLE_COLUMN_USED_MASK) identifies which columns of the
100794 ** table or index for cursor P1 are used. P2 and P3 combine to give
100795 ** a 64-bit unsigned integer mask. P2 stores the lower 32 bits and
100796 ** P3 stores the upper 32 bits. If the high-order bit of P3 is set
100797 ** that means that and 64-th or some later column is used.
 
100798 */
100799 case OP_ColumnsUsed: {
100800 VdbeCursor *pC;
100801 pC = p->apCsr[pOp->p1];
100802 assert( pC->eCurType==CURTYPE_BTREE );
100803 pC->maskUsed = INT32_TO_64(pOp->p2,pOp->p3);
100804 break;
100805 }
100806 #endif
100807
100808 /* Opcode: SeekGE P1 P2 P3 P4 *
@@ -113899,10 +113889,12 @@
113889 }
113890 x = (ynVar)i;
113891 if( x>pParse->nVar ){
113892 pParse->nVar = (int)x;
113893 doAdd = 1;
113894 }else if( x<SQLITE_VNBMC*64 ){
113895 doAdd = (pParse->aVnbmc[x>>6] & MASKBIT64(x&63))==0;
113896 }else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){
113897 doAdd = 1;
113898 }
113899 }else{
113900 /* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable
@@ -113915,10 +113907,13 @@
113907 doAdd = 1;
113908 }
113909 }
113910 if( doAdd ){
113911 pParse->pVList = sqlite3VListAdd(db, pParse->pVList, z, n, x);
113912 if( pParse->pVList!=0 && x<SQLITE_VNBMC*64 ){
113913 pParse->aVnbmc[x>>6] |= MASKBIT64(x&63);
113914 }
113915 }
113916 }
113917 pExpr->iColumn = x;
113918 if( x>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
113919 sqlite3ErrorMsg(pParse, "too many SQL variables");
@@ -115067,10 +115062,11 @@
115062 **
115063 ** sqlite3ExprIsConstant() pWalker->eCode==1
115064 ** sqlite3ExprIsConstantNotJoin() pWalker->eCode==2
115065 ** sqlite3ExprIsTableConstant() pWalker->eCode==3
115066 ** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5
115067 ** sqlite3ExprListIsConstant() pWalker->eCode==1 or 6
115068 **
115069 ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
115070 ** is found to not be a constant.
115071 **
115072 ** The sqlite3ExprIsConstantOrFunction() is used for evaluating DEFAULT
@@ -115139,10 +115135,17 @@
115135 testcase( pExpr->op==TK_IF_NULL_ROW );
115136 testcase( pExpr->op==TK_DOT );
115137 testcase( pExpr->op==TK_RAISE );
115138 pWalker->eCode = 0;
115139 return WRC_Abort;
115140 case TK_IS:
115141 case TK_ISNOT:
115142 if( pWalker->eCode==6 ){
115143 pWalker->eCode = 0;
115144 return WRC_Abort;
115145 }
115146 return WRC_Continue;
115147 case TK_VARIABLE:
115148 if( pWalker->eCode==5 ){
115149 /* Silently convert bound parameters that appear inside of CREATE
115150 ** statements into a NULL when parsing the CREATE statement text out
115151 ** of the sqlite_schema table */
@@ -115188,10 +115191,26 @@
115191 ** function and on its parameters.
115192 */
115193 SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse *pParse, Expr *p){
115194 return exprIsConst(pParse, p, 1);
115195 }
115196
115197 /*
115198 ** Return true if all expressions in pList are constant. If parameter bNoIs
115199 ** is true, do not consider expressions that contain "IS" operators to be
115200 ** constant. IS operators are not always considered constant as expressions
115201 ** like "x IS TRUE" need to be transformed to TK_TRUTH expression nodes,
115202 ** which happens at the same time as column name resolution.
115203 */
115204 SQLITE_PRIVATE int sqlite3ExprListIsConstant(Parse *pParse, ExprList *pList, int bNoIs){
115205 const int iInit = bNoIs ? 6 : 1;
115206 int ii;
115207 for(ii=0; ii<pList->nExpr; ii++){
115208 if( 0==exprIsConst(pParse, pList->a[ii].pExpr, iInit) ) return 0;
115209 }
115210 return 1;
115211 }
115212
115213 /*
115214 ** Walk an expression tree. Return non-zero if
115215 **
115216 ** (1) the expression is constant, and
@@ -115922,13 +115941,13 @@
115941 assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
115942 eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
115943
115944 if( prRhsHasNull ){
115945 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
115946 u64 mask = (1<<nExpr)-1;
115947 sqlite3VdbeAddOp3(v, OP_ColumnsUsed,
115948 iTab, LOWER32(mask), UPPER32(mask));
115949 #endif
115950 *prRhsHasNull = ++pParse->nMem;
115951 if( nExpr==1 ){
115952 sqlite3SetHasNullFlag(v, iTab, *prRhsHasNull);
115953 }
@@ -116878,11 +116897,11 @@
116897 if( ALWAYS(z!=0) ){
116898 double value;
116899 sqlite3AtoF(z, &value);
116900 assert( !sqlite3IsNaN(value) ); /* The new AtoF never returns NaN */
116901 if( negateFlag ) value = -value;
116902 sqlite3VdbeAddDouble(v, iMem, value);
116903 }
116904 }
116905 #endif
116906
116907
@@ -116919,11 +116938,11 @@
116938 codeReal(v, z, negFlag, iMem);
116939 }
116940 #endif
116941 }else{
116942 if( negFlag ){ value = c==3 ? SMALLEST_INT64 : -value; }
116943 sqlite3VdbeAddInt64(v, iMem, value);
116944 }
116945 }
116946 }
116947
116948
@@ -117310,11 +117329,11 @@
117329 ** A TRUE return does not guarantee that a subtype will be returned.
117330 ** It only indicates that a subtype return is possible. False positives
117331 ** are acceptable as they only disable an optimization. False negatives,
117332 ** on the other hand, can lead to incorrect answers.
117333 */
117334 SQLITE_PRIVATE int sqlite3ExprCanReturnSubtype(Parse *pParse, Expr *pExpr){
117335 Walker w;
117336 memset(&w, 0, sizeof(w));
117337 w.pParse = pParse;
117338 w.xExprCallback = exprNodeCanReturnSubtype;
117339 sqlite3WalkExpr(&w, pExpr);
@@ -139361,29 +139380,17 @@
139380 sqlite3VdbeJumpHere(pParse->pVdbe, pItem->u4.pSubq->addrFillSub - 1);
139381 }
139382 }
139383 }
139384
 
 
 
 
 
 
 
 
 
 
 
 
139385 /*
139386 ** Return true if all expressions in the expression-list passed as the
139387 ** only argument are both constant and have no affinity.
139388 */
139389 static int exprListIsNoAffinity(Parse *pParse, ExprList *pRow){
139390 int ii;
139391 if( sqlite3ExprListIsConstant(pParse, pRow, 0)==0 ) return 0;
139392 for(ii=0; ii<pRow->nExpr; ii++){
139393 Expr *pExpr = pRow->a[ii].pExpr;
139394 assert( pExpr->op!=TK_RAISE );
139395 assert( pExpr->affExpr==0 );
139396 if( 0!=sqlite3ExprAffinity(pExpr) ) return 0;
@@ -139445,11 +139452,11 @@
139452 */
139453 SQLITE_PRIVATE Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){
139454
139455 if( pParse->bHasWith /* condition (a) above */
139456 || pParse->db->init.busy /* condition (b) above */
139457 || sqlite3ExprListIsConstant(pParse, pRow, 1)==0 /* condition (c) above */
139458 || (pLeft->pSrc->nSrc==0 &&
139459 exprListIsNoAffinity(pParse,pLeft->pEList)==0) /* condition (d) above */
139460 || IN_SPECIAL_PARSE
139461 ){
139462 /* The co-routine method cannot be used. Fall back to UNION ALL. */
@@ -144968,11 +144975,11 @@
144975
144976 /*
144977 ** Generate code to return a single integer value.
144978 */
144979 static void returnSingleInt(Vdbe *v, i64 value){
144980 sqlite3VdbeAddInt64(v, 1, value);
144981 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
144982 }
144983
144984 /*
144985 ** Generate code to return a single text value.
@@ -153756,16 +153763,25 @@
153763 ** Either EP_OuterON or EP_InnerON|EP_OuterON */
153764 Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */
153765 };
153766
153767 /*
153768 ** Add a new entry to the pConst object, if appropriate.
 
153769 **
153770 ** * Do not add if pValue is not constant. (This is enforced by
153771 ** the caller)
153772 **
153773 ** * Do not add duplicate pColumn entries
153774 **
153775 ** * Do not add if pValue has an affinity
153776 **
153777 ** * Do not add if the comparison uses a collating sequence other
153778 ** than binary.
153779 **
153780 ** * Do not add if pValue is a function that might return a subtype
153781 **
153782 ** The caller guarantees the pColumn is a column.
153783 */
153784 static void constInsert(
153785 WhereConst *pConst, /* The WhereConst into which we are inserting */
153786 Expr *pColumn, /* The COLUMN part of the constraint */
153787 Expr *pValue, /* The VALUE part of the constraint */
@@ -153772,16 +153788,16 @@
153788 Expr *pExpr /* Overall expression: COLUMN=VALUE or VALUE=COLUMN */
153789 ){
153790 int i;
153791 assert( pColumn->op==TK_COLUMN );
153792 assert( sqlite3ExprIsConstant(pConst->pParse, pValue) );
 
153793 if( ExprHasProperty(pColumn, EP_FixedCol) ) return;
153794 if( sqlite3ExprAffinity(pValue)!=0 ) return;
153795 if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) ){
153796 return;
153797 }
153798 if( sqlite3ExprCanReturnSubtype(pConst->pParse, pValue) ) return;
153799
153800 /* 2018-10-25 ticket [cf5ed20f]
153801 ** Make sure the same pColumn is not inserted more than once */
153802 for(i=0; i<pConst->nConst; i++){
153803 const Expr *pE2 = pConst->apExpr[i*2];
@@ -158538,20 +158554,25 @@
158554 char *zName; /* Name of trigger */
158555 sqlite3 *db = pParse->db; /* The database */
158556 DbFixer sFix; /* Fixer object */
158557 int iDb; /* Database containing the trigger */
158558 Token nameToken; /* Trigger name for error reporting */
158559 i64 n; /* Number of steps */
158560
158561 pParse->pNewTrigger = 0;
158562 if( NEVER(pParse->nErr) || !pTrig ) goto triggerfinish_cleanup;
158563 zName = pTrig->zName;
158564 iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
158565 assert( iDb>=00 && iDb<db->nDb );
158566 pTrig->step_list = pStepList;
158567 for(n=0; pStepList; n++){
158568 pStepList->pTrig = pTrig;
158569 pStepList = pStepList->pNext;
158570 }
158571 if( n>pParse->db->aLimit[SQLITE_LIMIT_TRIGGER_STEPS] ){
158572 sqlite3ErrorMsg(pParse, "trigger \"%w\" contains too many steps", zName);
158573 goto triggerfinish_cleanup;
158574 }
158575 sqlite3TokenInit(&nameToken, pTrig->zName);
158576 sqlite3FixInit(&sFix, pParse, iDb, "trigger", &nameToken);
158577 if( sqlite3FixTriggerStep(&sFix, pTrig->step_list)
158578 || sqlite3FixExpr(&sFix, pTrig->pWhen)
@@ -164681,10 +164702,21 @@
164702 if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
164703 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
164704 }else{
164705 sqlite3 *db = pParse->db;
164706 Expr *pXMod = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
164707 if( nEq>1 ){
164708 /* If this IN(SELECT ...) expression drives more than one column of
164709 ** the index, disable the seek-scan optimization. The reasons for this
164710 ** are that (a) it is only possible to make this happen by populating
164711 ** the sqlite_stat1 table with inconsistent information, and (b) it
164712 ** would require sqlite3FindInIndex() to find an index that is not
164713 ** only unique for the columns in question, but also delivers them
164714 ** in sorted order (requires checking asc/desc, and rejecting cases
164715 ** where the indexed columns are not in the right order). */
164716 pLoop->wsFlags &= ~WHERE_IN_SEEKSCAN;
164717 }
164718 if( !db->mallocFailed ){
164719 aiMap = (int*)sqlite3DbMallocZero(db, sizeof(int)*nEq);
164720 eType = sqlite3FindInIndex(pParse, pXMod, IN_INDEX_LOOP, 0, aiMap, &iTab);
164721 }
164722 sqlite3ExprDelete(db, pXMod);
@@ -166895,21 +166927,29 @@
166927 pFrom = &uSrc.sSrc;
166928 pFrom->nSrc = 1;
166929 pFrom->nAlloc = 1;
166930 memcpy(&pFrom->a[0], pTabItem, sizeof(SrcItem));
166931 pFrom->a[0].fg.jointype = 0;
166932 if( pParse->withinRJSubrtn >= 100 ){
166933 /* This limit --------------^^^
166934 ** is based on an historical assert(). It is not compile-time or
166935 ** run-time configurable. It could perhaps be raised as high as 254,
166936 ** but only an attack robot would ever do even 100 RIGHT JOINS within
166937 ** a single query, so we'll just leave it as it is. */
166938 sqlite3ErrorMsg(pParse, "too many RIGHT JOINs");
166939 return;
166940 }
166941 pParse->withinRJSubrtn++;
166942 pSubWInfo = sqlite3WhereBegin(pParse, pFrom, pSubWhere, 0, 0, 0,
166943 WHERE_RIGHT_JOIN, 0);
166944 if( pSubWInfo ){
166945 int iCur = pLevel->iTabCur; /* Table on RHS of RIGHT JOIN &*/
166946 int r = ++pParse->nMem; /* Register range to hold primary key */
166947 int nPk; /* Number of values in the primary key */
166948 int r2; /* Register holding record for primary key */
166949 int addrCont = sqlite3WhereContinueLabel(pSubWInfo);
166950 Table *pTab = pTabItem->pSTab; /* Table on RHS of RIGHT JOIN */
166951 if( HasRowid(pTab) ){
166952 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, -1, r);
166953 nPk = 1;
166954 }else{
166955 int iPk;
@@ -166919,17 +166959,35 @@
166959 for(iPk=0; iPk<nPk; iPk++){
166960 int iCol = pPk->aiColumn[iPk];
166961 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol,r+iPk);
166962 }
166963 }
166964
166965 /* Generate code that checks to see if the current row of the RHS table
166966 ** has appeared in any prior output row. */
166967 if( pRJ->regBloom ){
166968 sqlite3VdbeAddOp4Int(v, OP_Filter, pRJ->regBloom,
166969 sqlite3VdbeCurrentAddr(v)+2, r, nPk);
166970 VdbeCoverage(v);
166971 }
166972 sqlite3VdbeAddOp4Int(v, OP_Found, pRJ->iMatch, addrCont, r, nPk);
166973 VdbeCoverage(v);
166974 r2 = sqlite3GetTempReg(pParse);
166975
166976 /* Generate code that inserts the PK of the RHS table into the
166977 ** pRH->iMatch index to indicate that the current row has appeared
166978 ** in the output set. */
166979 sqlite3VdbeAddOp3(v, OP_MakeRecord, r, nPk, r2);
166980 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pRJ->iMatch, r2, r, nPk);
166981 sqlite3ReleaseTempReg(pParse, r2);
166982 if( pRJ->regBloom ){
166983 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pRJ->regBloom, 0, r, nPk);
166984 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
166985 }
166986
166987 /* Invoke the subroutine that actually puts the current RHS table row
166988 ** into the output set, with NULLs for the LHS. */
166989 sqlite3VdbeAddOp2(v, OP_Gosub, pRJ->regReturn, pRJ->addrSubrtn);
166990 sqlite3WhereEnd(pSubWInfo);
166991 }
166992 sqlite3ExprDelete(pParse->db, pSubWhere);
166993 ExplainQueryPlanPop(pParse);
@@ -176241,12 +176299,12 @@
176299 #endif
176300 {
176301 sqlite3VdbeChangeP5(v, bFordelete);
176302 }
176303 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
176304 sqlite3VdbeAddOp3(v, OP_ColumnsUsed, pTabItem->iCursor,
176305 LOWER32(pTabItem->colUsed), UPPER32(pTabItem->colUsed));
176306 #endif
176307 if( ii>=2
176308 && (pTabItem[0].fg.jointype & (JT_LTORJ|JT_LEFT))==0
176309 && pLevel->addrHalt==pWInfo->a[0].addrHalt
176310 ){
@@ -176319,12 +176377,12 @@
176377 if( jj<0 ) continue;
176378 if( jj>63 ) jj = 63;
176379 if( (pTabItem->colUsed & MASKBIT(jj))==0 ) continue;
176380 colUsed |= ((u64)1)<<(ii<63 ? ii : 63);
176381 }
176382 sqlite3VdbeAddOp3(v, OP_ColumnsUsed, iIndexCur,
176383 LOWER32(colUsed),UPPER32(colUsed));
176384 }
176385 #endif /* SQLITE_ENABLE_COLUMN_USED_MASK */
176386 #ifdef SQLITE_ENABLE_CURSOR_HINTS
176387 if( HasRowid(pTab) ){
176388 sqlite3VdbeAddOp3(v, OP_CursorHint, iIndexCur, 0, pTabItem->iCursor);
@@ -190540,10 +190598,11 @@
190598 SQLITE_MAX_VARIABLE_NUMBER, /* IMP: R-38091-32352 */
190599 SQLITE_MAX_TRIGGER_DEPTH,
190600 SQLITE_MAX_WORKER_THREADS,
190601 SQLITE_MAX_PARSER_DEPTH,
190602 SQLITE_MAX_SCHEMA,
190603 SQLITE_MAX_TRIGGER_STEPS,
190604 };
190605
190606 /*
190607 ** Make sure the hard limits are set to reasonable values
190608 */
@@ -190580,10 +190639,13 @@
190639 #if SQLITE_MAX_TRIGGER_DEPTH<1
190640 # error SQLITE_MAX_TRIGGER_DEPTH must be at least 1
190641 #endif
190642 #if SQLITE_MAX_WORKER_THREADS<0 || SQLITE_MAX_WORKER_THREADS>50
190643 # error SQLITE_MAX_WORKER_THREADS must be between 0 and 50
190644 #endif
190645 #if SQLITE_MAX_TRIGGER_STEPS<0 || SQLITE_MAX_TRIGGER_STEPS>65535
190646 # error SQLITE_MAX_TRIGGER_STEPS must be between 0 and 65535
190647 #endif
190648
190649
190650 /*
190651 ** Change the value of a limit. Report the old value.
@@ -190623,11 +190685,12 @@
190685 SQLITE_MAX_LIKE_PATTERN_LENGTH );
190686 assert( aHardLimit[SQLITE_LIMIT_VARIABLE_NUMBER]==SQLITE_MAX_VARIABLE_NUMBER);
190687 assert( aHardLimit[SQLITE_LIMIT_TRIGGER_DEPTH]==SQLITE_MAX_TRIGGER_DEPTH );
190688 assert( aHardLimit[SQLITE_LIMIT_WORKER_THREADS]==SQLITE_MAX_WORKER_THREADS );
190689 assert( aHardLimit[SQLITE_LIMIT_SCHEMA]==SQLITE_MAX_SCHEMA );
190690 assert( aHardLimit[SQLITE_LIMIT_TRIGGER_STEPS]==SQLITE_MAX_TRIGGER_STEPS );
190691 assert( SQLITE_LIMIT_TRIGGER_STEPS==(SQLITE_N_LIMIT-1) );
190692
190693
190694 if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
190695 return -1;
190696 }
@@ -200499,10 +200562,18 @@
200562 }
200563
200564 #define FTS4AUX_EQ_CONSTRAINT 1
200565 #define FTS4AUX_GE_CONSTRAINT 2
200566 #define FTS4AUX_LE_CONSTRAINT 4
200567
200568 /*
200569 ** Return true if constraint iCons of pInfo uses the "binary" collation
200570 ** sequence. Or false it it uses anything else.
200571 */
200572 static int fts3auxIsBinary(sqlite3_index_info *pInfo, int iCons){
200573 return 0==sqlite3_stricmp("binary", sqlite3_vtab_collation(pInfo, iCons));
200574 }
200575
200576 /*
200577 ** xBestIndex - Analyze a WHERE and ORDER BY clause.
200578 */
200579 static int fts3auxBestIndexMethod(
@@ -200527,11 +200598,11 @@
200598 }
200599
200600 /* Search for equality and range constraints on the "term" column.
200601 ** And equality constraints on the hidden "languageid" column. */
200602 for(i=0; i<pInfo->nConstraint; i++){
200603 if( pInfo->aConstraint[i].usable && fts3auxIsBinary(pInfo, i) ){
200604 int op = pInfo->aConstraint[i].op;
200605 int iCol = pInfo->aConstraint[i].iColumn;
200606
200607 if( iCol==0 ){
200608 if( op==SQLITE_INDEX_CONSTRAINT_EQ ) iEq = i;
@@ -200698,11 +200769,11 @@
200769 break;
200770
200771 /* State 3. The integer just read is a column number. */
200772 default: assert( eState==3 );
200773 iCol = (int)v;
200774 if( iCol<1 || iCol>32767 ){
200775 rc = SQLITE_CORRUPT_VTAB;
200776 break;
200777 }
200778 if( fts3auxGrowStatArray(pCsr, iCol+2) ) return SQLITE_NOMEM;
200779 pCsr->aStat[iCol+1].nDoc++;
@@ -200773,21 +200844,21 @@
200844 memset(&pCsr->csr, 0, ((u8*)&pCsr[1]) - (u8*)&pCsr->csr);
200845
200846 pCsr->filter.flags = FTS3_SEGMENT_REQUIRE_POS|FTS3_SEGMENT_IGNORE_EMPTY;
200847 if( isScan ) pCsr->filter.flags |= FTS3_SEGMENT_SCAN;
200848
200849 if( (iEq>=0 || iGe>=0) && sqlite3_value_type(apVal[0])==SQLITE_TEXT ){
200850 const unsigned char *zStr = sqlite3_value_text(apVal[0]);
200851 assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) );
200852 if( zStr ){
200853 pCsr->filter.zTerm = sqlite3_mprintf("%s", zStr);
200854 if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM;
200855 pCsr->filter.nTerm = (int)strlen(pCsr->filter.zTerm);
200856 }
200857 }
200858
200859 if( iLe>=0 && sqlite3_value_type(apVal[0])==SQLITE_TEXT ){
200860 pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iLe]));
200861 if( pCsr->zStop==0 ) return SQLITE_NOMEM;
200862 pCsr->nStop = (int)strlen(pCsr->zStop);
200863 }
200864
@@ -210899,10 +210970,11 @@
210970 int nList; /* Number of phrases in expression */
210971 SnippetIter sIter; /* Iterates through snippet candidates */
210972 sqlite3_int64 nByte; /* Number of bytes of space to allocate */
210973 int iBestScore = -1; /* Best snippet score found so far */
210974 int i; /* Loop counter */
210975 Fts3Expr *pExpr = pCsr->pExpr;
210976
210977 memset(&sIter, 0, sizeof(sIter));
210978
210979 /* Iterate through the phrases in the expression to count them. The same
210980 ** callback makes sure the doclists are loaded for each phrase.
@@ -210927,13 +210999,16 @@
210999 sIter.pCsr = pCsr;
211000 sIter.iCol = iCol;
211001 sIter.nSnippet = nSnippet;
211002 sIter.nPhrase = nList;
211003 sIter.iCurrent = -1;
211004 rc = sqlite3Fts3ExprIterate(pExpr, fts3SnippetFindPositions, (void*)&sIter);
211005 if( rc==SQLITE_OK ){
211006 /* Iterate through the expression twice, in case pointers garnered during
211007 ** the first iteration are invalidated by a call to fts5EvalRestart(). */
211008 rc = sqlite3Fts3ExprIterate(pExpr, fts3SnippetFindPositions, (void*)&sIter);
211009 }
211010 if( rc==SQLITE_OK ){
211011
211012 /* Set the *pmSeen output variable. */
211013 for(i=0; i<nList; i++){
211014 if( sIter.aPhrase[i].pHead ){
@@ -215052,16 +215127,129 @@
215127 assert( !px.bReadOnly );
215128 sqlite3_result_blob(pStr->pCtx, px.aBlob, px.nBlob, SQLITE_DYNAMIC);
215129 }
215130 }
215131
215132 /*
215133 ** This a helper routine for jsonbPayloadSize() and
215134 ** jsonbPayloadSizeSemiInline(). This routine is called using tail
215135 ** recursion to handle the (relatively uncommon) cases where the
215136 ** the payload size is a 2, 4, or 8 byte integer.
215137 */
215138 static u32 jsonbPayloadSizeWide(
215139 const JsonParse *pParse, /* JSON parsing context */
215140 u32 i, /* Index of the node type-code */
215141 u32 *pSz, /* Write payload size here */
215142 u8 x /* pParse->aBlob[i]>>4 */
215143 ){
215144 u32 sz;
215145 u32 n;
215146 assert( i<pParse->nBlob );
215147 assert( x==(pParse->aBlob[i]>>4) );
215148 assert( x>=13 );
215149 if( x==13 ){
215150 if( i+2>=pParse->nBlob ){
215151 *pSz = 0;
215152 return 0;
215153 }
215154 sz = (pParse->aBlob[i+1]<<8) + pParse->aBlob[i+2];
215155 n = 3;
215156 }else if( x==14 ){
215157 if( i+4>=pParse->nBlob ){
215158 *pSz = 0;
215159 return 0;
215160 }
215161 sz = ((u32)pParse->aBlob[i+1]<<24) + (pParse->aBlob[i+2]<<16) +
215162 (pParse->aBlob[i+3]<<8) + pParse->aBlob[i+4];
215163 n = 5;
215164 }else{
215165 if( i+8>=pParse->nBlob
215166 || pParse->aBlob[i+1]!=0
215167 || pParse->aBlob[i+2]!=0
215168 || pParse->aBlob[i+3]!=0
215169 || pParse->aBlob[i+4]!=0
215170 ){
215171 *pSz = 0;
215172 return 0;
215173 }
215174 sz = ((u32)pParse->aBlob[i+5]<<24) + (pParse->aBlob[i+6]<<16) +
215175 (pParse->aBlob[i+7]<<8) + pParse->aBlob[i+8];
215176 n = 9;
215177 }
215178 testcase( (i64)i+sz+n > pParse->nBlob );
215179 testcase( (i64)i+sz+n > pParse->nBlob-pParse->delta
215180 && (i64)i+sz+n > pParse->nBlob );
215181 testcase( pParse->delta>0 );
215182 testcase( pParse->delta<0 );
215183 /* Quirks with -Os and gcov cause the NO_TEST line below to show up as
215184 ** false-positive coverage miss. The testcases() macros above are
215185 ** sufficient to prove that the branch is in fact covered */
215186 if( (i64)i+sz+n > pParse->nBlob
215187 && (i64)i+sz+n > pParse->nBlob-pParse->delta /*NO_TEST*/
215188 ){
215189 *pSz = 0;
215190 return 0;
215191 }
215192 *pSz = sz;
215193 return n;
215194 }
215195
215196 /*
215197 ** This is the main routine for determining the size of a node in JSONB.
215198 ** The jsonbPayloadSizeWide() above is a helper. The two routines
215199 ** jsonbPayloadSizeInline() and jsonbPayloadSizeSemiInline() below are
215200 ** optional optimizations. It is important to keep all these routines in
215201 ** sync. Agents reading this code: Help us humans to remember that!
215202 **
215203 ** The byte at index i is a node type-code. This routine
215204 ** determines the payload size for that node and writes that
215205 ** payload size in to *pSz. It returns the offset from i to the
215206 ** beginning of the payload. Return 0 on error.
215207 */
215208 static u32 jsonbPayloadSize(
215209 const JsonParse *pParse, /* JSON parsing context */
215210 u32 i, /* Index of the node type-code */
215211 u32 *pSz /* Write payload size here */
215212 ){
215213 u8 x;
215214 u32 sz;
215215 u32 n;
215216 if( i>=pParse->nBlob ){
215217 *pSz = 0;
215218 return 0;
215219 }else if( (x = pParse->aBlob[i]>>4)<=11 ){
215220 sz = x;
215221 n = 1;
215222 }else if( x==12 ){
215223 if( i+1>=pParse->nBlob ){
215224 *pSz = 0;
215225 return 0;
215226 }
215227 sz = pParse->aBlob[i+1];
215228 n = 2;
215229 }else{
215230 return jsonbPayloadSizeWide(pParse, i, pSz, x);
215231 }
215232 if( (i64)i+sz+n > pParse->nBlob
215233 && (i64)i+sz+n > pParse->nBlob-pParse->delta
215234 ){
215235 *pSz = 0;
215236 return 0;
215237 }
215238 *pSz = sz;
215239 return n;
215240 }
215241
215242 #if SQLITE_USES_INLINE
215243 /* A separate inline version of jsonbPayloadSize(), used in one particulary
215244 ** performance-critical place.
215245 */
215246 static SQLITE_INLINE u32 jsonbPayloadSizeInline(
215247 const JsonParse *pParse, /* JSON parsing context */
215248 u32 i, /* Index of the node type-code */
215249 u32 *pSz /* Write payload size here */
215250 ){
215251 u8 x;
215252 u32 sz;
215253 u32 n;
215254 if( i>=pParse->nBlob ){
215255 *pSz = 0;
@@ -215112,11 +215300,65 @@
215300 return 0;
215301 }
215302 *pSz = sz;
215303 return n;
215304 }
215305 #else /* if !SQLITE_USES_INLINE */
215306 /* On compilers that do not support in-lining, just call the original
215307 ** jsonbPayloadSize(). It's slower, but it gets the right answer. */
215308 # define jsonbPayloadSizeInline(a,b,c) jsonbPayloadSize(a,b,c)
215309 #endif
215310
215311
215312 #if SQLITE_USES_INLINE
215313 /* A separate inline version of jsonbPayloadSize() that implements the more
215314 ** common paths inline but then calls out to a subroutine for the uncommon
215315 ** paths.
215316 **
215317 ** * It is guaranteed that the i parameter is a valid index for
215318 ** pParse->aBlob[]. There is no possibility of running of the end
215319 ** of the allocation.
215320 **
215321 ** * Large sizes (greater than 255) are uncommon and are handled
215322 ** by a subroutine call to the jsonbPayloadSizeWide().
215323 */
215324 static SQLITE_INLINE u32 jsonbPayloadSizeSemiInline(
215325 const JsonParse *pParse, /* JSON parsing context */
215326 u32 i, /* Index of the node type-code */
215327 u32 *pSz /* Write payload size here */
215328 ){
215329 u8 x;
215330 u32 sz;
215331 u32 n;
215332 assert( i<pParse->nBlob );
215333 if( (x = pParse->aBlob[i]>>4)<=11 ){
215334 sz = x;
215335 n = 1;
215336 }else if( x==12 ){
215337 if( i+1>=pParse->nBlob ){
215338 *pSz = 0;
215339 return 0;
215340 }
215341 sz = pParse->aBlob[i+1];
215342 n = 2;
215343 }else{
215344 return jsonbPayloadSizeWide(pParse,i,pSz,x);
215345 }
215346 if( (i64)i+sz+n > pParse->nBlob
215347 && (i64)i+sz+n > pParse->nBlob-pParse->delta
215348 ){
215349 *pSz = 0;
215350 return 0;
215351 }
215352 *pSz = sz;
215353 return n;
215354 }
215355 #else /* if !SQLITE_USES_INLINE */
215356 /* On compilers that do not support in-lining, just call the original
215357 ** jsonbPayloadSize(). It's slower, but it gets the right answer. */
215358 # define jsonbPayloadSizeSemiInline(a,b,c) jsonbPayloadSize(a,b,c)
215359 #endif
215360
215361 /*
215362 ** Translate the binary JSONB representation of JSON beginning at
215363 ** pParse->aBlob[i] into a JSON text string. Append the JSON
215364 ** text onto the end of pOut. Return the index in pParse->aBlob[]
@@ -215134,11 +215376,11 @@
215376 u32 i, /* Start rendering at this index */
215377 JsonString *pOut /* Write JSON here */
215378 ){
215379 u32 sz, n, j, iEnd;
215380
215381 n = jsonbPayloadSizeInline(pParse, i, &sz);
215382 if( n==0 ){
215383 pOut->eErr |= JSTRING_MALFORMED;
215384 return pParse->nBlob+1;
215385 }
215386 switch( pParse->aBlob[i] & 0x0f ){
@@ -215474,11 +215716,11 @@
215716 u32 n, sz, i, iEnd;
215717 u32 k = 0;
215718 n = jsonbPayloadSize(pParse, iRoot, &sz);
215719 iEnd = iRoot+n+sz;
215720 for(i=iRoot+n; n>0 && i<iEnd; i+=sz+n, k++){
215721 n = jsonbPayloadSizeSemiInline(pParse, i, &sz);
215722 }
215723 return k;
215724 }
215725
215726 /*
@@ -215984,11 +216226,11 @@
216226 while( j<iEnd ){
216227 int rawLabel;
216228 const char *zLabel;
216229 x = pParse->aBlob[j] & 0x0f;
216230 if( x<JSONB_TEXT || x>JSONB_TEXTRAW ) return JSON_LOOKUP_ERROR;
216231 n = jsonbPayloadSizeSemiInline(pParse, j, &sz);
216232 if( n==0 ) return JSON_LOOKUP_ERROR;
216233 k = j+n; /* k is the index of the label text */
216234 if( k+sz>=iEnd ) return JSON_LOOKUP_ERROR;
216235 zLabel = (const char*)&pParse->aBlob[k];
216236 rawLabel = x==JSONB_TEXT || x==JSONB_TEXTRAW;
@@ -216006,11 +216248,11 @@
216248 if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
216249 return rc;
216250 }
216251 j = k+sz;
216252 if( ((pParse->aBlob[j])&0x0f)>JSONB_OBJECT ) return JSON_LOOKUP_ERROR;
216253 n = jsonbPayloadSizeSemiInline(pParse, j, &sz);
216254 if( n==0 ) return JSON_LOOKUP_ERROR;
216255 j += n+sz;
216256 }
216257 if( j>iEnd ) return JSON_LOOKUP_ERROR;
216258 if( pParse->eEdit>=JEDIT_INS ){
@@ -216095,11 +216337,11 @@
216337 pParse->iDepth--;
216338 if( pParse->delta ) jsonAfterEditSizeAdjust(pParse, iRoot);
216339 return rc;
216340 }
216341 kk--;
216342 n = jsonbPayloadSizeSemiInline(pParse, j, &sz);
216343 if( n==0 ) return JSON_LOOKUP_ERROR;
216344 j += n+sz;
216345 }
216346 if( j>iEnd ) return JSON_LOOKUP_ERROR;
216347 if( kk>0 ) return JSON_LOOKUP_NOTFOUND;
@@ -223583,10 +223825,12 @@
223825 /*
223826 ** Function: geopoly_regular(X,Y,R,N)
223827 **
223828 ** Construct a simple, convex, regular polygon centered at X, Y
223829 ** with circumradius R and with N sides.
223830 **
223831 ** Maximum N is 1000. Maximum R is 1.0e+300.
223832 */
223833 static void geopolyRegularFunc(
223834 sqlite3_context *context,
223835 int argc,
223836 sqlite3_value **argv
@@ -223597,11 +223841,11 @@
223841 int n = sqlite3_value_int(argv[3]);
223842 int i;
223843 GeoPoly *p;
223844 (void)argc;
223845
223846 if( n<3 || r<=0.0 || r>=1e300 ) return;
223847 if( n>1000 ) n = 1000;
223848 p = sqlite3_malloc64( sizeof(*p) + (n-1)*2*sizeof(GeoCoord) );
223849 if( p==0 ){
223850 sqlite3_result_error_nomem(context);
223851 return;
@@ -233626,12 +233870,18 @@
233870 return SQLITE_OK;
233871 }
233872 default: {
233873 const struct iovec *p = (struct iovec*)pCur->pPtr;
233874 assert( pCur->eType==CARRAY_BLOB );
233875 p += pCur->iRowid-1;
233876 if( p->iov_len>0x7fffffff ){
233877 sqlite3_result_error_toobig(ctx);
233878 return SQLITE_TOOBIG;
233879 }else{
233880 sqlite3_result_blob(ctx, p->iov_base, (int)p->iov_len,
233881 SQLITE_TRANSIENT);
233882 }
233883 return SQLITE_OK;
233884 }
233885 }
233886 }
233887 }
@@ -239561,14 +239811,14 @@
239811 int flags /* SESSION_APPLY_XXX flags */
239812 ){
239813 int schemaMismatch = 0;
239814 int rc = SQLITE_OK; /* Return code */
239815 const char *zTab = 0; /* Name of current table */
 
239816 SessionApplyCtx sApply; /* changeset_apply() context object */
239817 int bPatchset;
239818 u64 savedFlag = db->flags & SQLITE_FkNoAction;
239819 int bNew = 0; /* True for first entry of new table */
239820
239821 assert( xConflict!=0 );
239822
239823 sqlite3_mutex_enter(sqlite3_db_mutex(db));
239824 if( flags & SQLITE_CHANGESETAPPLY_FKNOACTION ){
@@ -239586,19 +239836,20 @@
239836 rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0);
239837 }
239838 if( rc==SQLITE_OK ){
239839 rc = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 1", 0, 0, 0);
239840 }
239841 while( rc==SQLITE_OK && SQLITE_ROW==sessionChangesetNext(pIter, 0, 0,&bNew) ){
239842 int nCol;
239843 int op;
239844 const char *zNew;
239845
239846 sqlite3changeset_op(pIter, &zNew, &nCol, &op, 0);
239847
239848 if( bNew ){
239849 u8 *abPK;
239850 bNew = 0;
239851
239852 rc = sessionRetryConstraints(
239853 db, pIter->bPatchset, zTab, &sApply, xConflict, pCtx
239854 );
239855 if( rc!=SQLITE_OK ) break;
@@ -239629,11 +239880,10 @@
239880 zTab = sqlite3_mprintf("%s", zNew);
239881 if( zTab==0 ){
239882 rc = SQLITE_NOMEM;
239883 break;
239884 }
 
239885 sApply.azCol = (const char **)zTab;
239886 }else{
239887 int nMinCol = 0;
239888 int i;
239889
@@ -239682,11 +239932,10 @@
239932 break;
239933 }
239934 sApply.bStat1 = 0;
239935 }
239936 }
 
239937 }
239938 }
239939
239940 /* If there is a schema mismatch on the current table, proceed to the
239941 ** next change. A log message has already been issued. */
@@ -251353,11 +251602,16 @@
251602 ** sequentially starting from 1.
251603 */
251604 #define FTS5_DATA_ID_B 16 /* Max seg id number 65535 */
251605 #define FTS5_DATA_DLI_B 1 /* Doclist-index flag (1 bit) */
251606 #define FTS5_DATA_HEIGHT_B 5 /* Max dlidx tree height of 32 */
251607 #define FTS5_DATA_PAGE_B 31 /* 31-bit page numbers */
251608
251609 /* Maximum page number within a segment. Declare any structure read from
251610 ** the database with a page number greater than this corrupt. It is not
251611 ** actually possible to create a database this large. */
251612 #define FTS5_MAX_PGNO 0x7FFFFF00
251613
251614 #define fts5_dri(segid, dlidx, height, pgno) ( \
251615 ((i64)(segid) << (FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B)) + \
251616 ((i64)(dlidx) << (FTS5_DATA_PAGE_B + FTS5_DATA_HEIGHT_B)) + \
251617 ((i64)(height) << (FTS5_DATA_PAGE_B)) + \
@@ -252266,11 +252520,11 @@
252520 i += fts5GetVarint32(&pData[i], pSeg->nPgTombstone);
252521 i += fts5GetVarint(&pData[i], &pSeg->nEntryTombstone);
252522 i += fts5GetVarint(&pData[i], &pSeg->nEntry);
252523 nOriginCntr = MAX(nOriginCntr, pSeg->iOrigin2);
252524 }
252525 if( pSeg->pgnoLast<pSeg->pgnoFirst || pSeg->pgnoLast>FTS5_MAX_PGNO ){
252526 rc = FTS5_CORRUPT;
252527 break;
252528 }
252529 }
252530 if( iLvl>0 && pLvl[-1].nMerge && nTotal==0 ) rc = FTS5_CORRUPT;
@@ -252862,10 +253116,13 @@
253116 pLvl->pData = fts5DataRead(p, iRowid);
253117 if( pLvl->pData && (pLvl->pData->p[0] & 0x0001)==0 ){
253118 bDone = 1;
253119 }
253120 pIter->nLvl = i+1;
253121 if( pIter->nLvl > (1<<FTS5_DATA_HEIGHT_B) ){
253122 p->rc = FTS5_CORRUPT;
253123 }
253124 }
253125 }
253126
253127 if( p->rc==SQLITE_OK ){
253128 pIter->iSegid = iSegid;
@@ -256583,38 +256840,42 @@
256840 ** iNextOff: Offset to move data from
256841 */
256842 if( p->rc==SQLITE_OK ){
256843 const int nMove = nPg - iNextOff; /* Number of bytes to move */
256844 int nShift = iNextOff - iOff; /* Distance to move them */
256845 int nNewPg = 0;
256846 int iPrevKeyOut = 0;
256847 i64 iKeyIn = 0;
256848
256849 if( nMove>0 ){
256850 memmove(&aPg[iOff], &aPg[iNextOff], nMove);
256851 }
256852 iPgIdx -= nShift;
256853 nNewPg = iPgIdx;
256854 fts5PutU16(&aPg[2], iPgIdx);
256855
256856 for(iIdx=0; iIdx<nIdx; /* no-op */){
256857 u32 iVal = 0;
256858 iIdx += fts5GetVarint32(&aIdx[iIdx], iVal);
256859 iKeyIn += iVal;
256860 if( iKeyIn>nPg ){
256861 FTS5_CORRUPT_IDX(p);
256862 break;
256863 }
256864 if( iKeyIn!=iDelKeyOff ){
256865 int iKeyOut = (iKeyIn - (iKeyIn>iOff ? nShift : 0));
256866 nNewPg += sqlite3Fts5PutVarint(&aPg[nNewPg], iKeyOut - iPrevKeyOut);
256867 iPrevKeyOut = iKeyOut;
256868 }
256869 }
256870
256871 if( p->rc==SQLITE_OK && iPgIdx==nNewPg && nIdx>0 && pSeg->iLeafPgno!=1 ){
256872 fts5SecureDeleteIdxEntry(p, iSegid, pSeg->iLeafPgno);
256873 }
256874
256875 assert_nc( nNewPg>4 || fts5GetU16(aPg)==0 );
256876 fts5DataWrite(p, FTS5_SEGMENT_ROWID(iSegid,pSeg->iLeafPgno), aPg, nNewPg);
256877 }
256878 sqlite3_free(aIdx);
256879 }
256880
256881 /*
@@ -264272,11 +264533,11 @@
264533 int nArg, /* Number of args */
264534 sqlite3_value **apUnused /* Function arguments */
264535 ){
264536 assert( nArg==0 );
264537 UNUSED_PARAM2(nArg, apUnused);
264538 sqlite3_result_text(pCtx, "fts5: 2026-08-20 13:25:12 3bd5456e50ef321f2cafcf67261d556a760624ce0caab430ed9454cebec233e7", -1, SQLITE_TRANSIENT);
264539 }
264540
264541 /*
264542 ** Implementation of fts5_locale(LOCALE, TEXT) function.
264543 **
@@ -268951,10 +269212,18 @@
269212 sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */
269213 char **pzErr /* OUT: sqlite3_malloc'd error message */
269214 ){
269215 return fts5VocabInitVtab(db, pAux, argc, argv, ppVtab, pzErr);
269216 }
269217
269218 /*
269219 ** Return true if constraint iCons of pInfo uses the "binary" collation
269220 ** sequence. Or false it it uses anything else.
269221 */
269222 static int fts5VocabIsBinary(sqlite3_index_info *pInfo, int iCons){
269223 return 0==sqlite3_stricmp("binary", sqlite3_vtab_collation(pInfo, iCons));
269224 }
269225
269226 /*
269227 ** Implementation of the xBestIndex method.
269228 **
269229 ** Only constraints of the form:
@@ -268982,11 +269251,11 @@
269251 assert( (pInfo->colUsed & FTS5_VOCAB_COLUSED_MASK)==pInfo->colUsed );
269252
269253 for(i=0; i<pInfo->nConstraint; i++){
269254 struct sqlite3_index_constraint *p = &pInfo->aConstraint[i];
269255 if( p->usable==0 ) continue;
269256 if( p->iColumn==0 && fts5VocabIsBinary(pInfo, i) ){ /* term column */
269257 if( p->op==SQLITE_INDEX_CONSTRAINT_EQ ) iTermEq = i;
269258 if( p->op==SQLITE_INDEX_CONSTRAINT_LE ) iTermLe = i;
269259 if( p->op==SQLITE_INDEX_CONSTRAINT_LT ) iTermLe = i;
269260 if( p->op==SQLITE_INDEX_CONSTRAINT_GE ) iTermGe = i;
269261 if( p->op==SQLITE_INDEX_CONSTRAINT_GT ) iTermGe = i;
@@ -269320,10 +269589,30 @@
269589 rc = FTS5_CORRUPT;
269590 }
269591 }
269592 return rc;
269593 }
269594
269595 /*
269596 ** If value pVal is an SQLITE_TEXT value, return a pointer to a buffer
269597 ** containing the UTF-8 representation of the value, and set output
269598 ** parameter (*pnText) to the size of the buffer contents in bytes. Or,
269599 ** if pVal is some other type of value, return NULL and set (*pnText)
269600 ** to 0 before returning.
269601 */
269602 static const char *fts5VocabValueText(sqlite3_value *pVal, int *pnText){
269603 const char *zRet = 0;
269604 int nRet = 0;
269605
269606 if( sqlite3_value_type(pVal)==SQLITE_TEXT ){
269607 zRet = (const char*)sqlite3_value_text(pVal);
269608 nRet = sqlite3_value_bytes(pVal);
269609 }
269610
269611 *pnText = nRet;
269612 return zRet;
269613 }
269614
269615 /*
269616 ** This is the xFilter implementation for the virtual table.
269617 */
269618 static int fts5VocabFilterMethod(
@@ -269354,22 +269643,19 @@
269643 if( idxNum & FTS5_VOCAB_TERM_GE ) pGe = apVal[iVal++];
269644 if( idxNum & FTS5_VOCAB_TERM_LE ) pLe = apVal[iVal++];
269645 pCsr->colUsed = (idxNum & FTS5_VOCAB_COLUSED_MASK);
269646
269647 if( pEq ){
269648 zTerm = fts5VocabValueText(pEq, &nTerm);
 
269649 f = FTS5INDEX_QUERY_NOTOKENDATA;
269650 }else{
269651 if( pGe ){
269652 zTerm = fts5VocabValueText(pGe, &nTerm);
 
269653 }
269654 if( pLe ){
269655 const char *zCopy = fts5VocabValueText(pLe, &pCsr->nLeTerm);
269656 if( zCopy==0 ) zCopy = "";
 
269657 pCsr->zLeTerm = sqlite3_malloc64((i64)pCsr->nLeTerm+1);
269658 if( pCsr->zLeTerm==0 ){
269659 rc = SQLITE_NOMEM;
269660 }else{
269661 memcpy(pCsr->zLeTerm, zCopy, pCsr->nLeTerm+1);
269662
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.54.0"
150150
#define SQLITE_VERSION_NUMBER 3054000
151
-#define SQLITE_SOURCE_ID "2026-08-11 10:46:12 fee71cd6f7294ffd02784d26811a9d11d80e83d4075e1233b8ec0289519bb891"
151
+#define SQLITE_SOURCE_ID "2026-08-20 13:25:12 3bd5456e50ef321f2cafcf67261d556a760624ce0caab430ed9454cebec233e7"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2026-08-11T10:46:12.896Z"
154
+#define SQLITE_SCM_DATETIME "2026-08-20T13:25:12.207Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
@@ -4434,10 +4434,14 @@
44344434
** [prepared statement] may start.</dd>)^
44354435
**
44364436
** [[SQLITE_LIMIT_SCHEMA]] ^(<dt>SQLITE_LIMIT_SCHEMA</dt>
44374437
** <dd>The maximum number of objects (tables, indexes, triggers, and views)
44384438
** defined by the database schema.</dd>)^
4439
+**
4440
+** [[SQLITE_LIMIT_TRIGGER_STEPS]] ^(<dt>SQLITE_LIMIT_TRIGGER_STEPS</dt>
4441
+** <dd>The maximum number of SQL statements that can be contained within
4442
+** a single trigger.</dd>)^
44394443
** </dl>
44404444
*/
44414445
#define SQLITE_LIMIT_LENGTH 0
44424446
#define SQLITE_LIMIT_SQL_LENGTH 1
44434447
#define SQLITE_LIMIT_COLUMN 2
@@ -4450,10 +4454,11 @@
44504454
#define SQLITE_LIMIT_VARIABLE_NUMBER 9
44514455
#define SQLITE_LIMIT_TRIGGER_DEPTH 10
44524456
#define SQLITE_LIMIT_WORKER_THREADS 11
44534457
#define SQLITE_LIMIT_PARSER_DEPTH 12
44544458
#define SQLITE_LIMIT_SCHEMA 13
4459
+#define SQLITE_LIMIT_TRIGGER_STEPS 14
44554460
44564461
/*
44574462
** CAPI3REF: Prepare Flags
44584463
**
44594464
** These constants define various flags that can be passed into the
44604465
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
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-08-11 10:46:12 fee71cd6f7294ffd02784d26811a9d11d80e83d4075e1233b8ec0289519bb891"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-08-11T10:46:12.896Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -4434,10 +4434,14 @@
4434 ** [prepared statement] may start.</dd>)^
4435 **
4436 ** [[SQLITE_LIMIT_SCHEMA]] ^(<dt>SQLITE_LIMIT_SCHEMA</dt>
4437 ** <dd>The maximum number of objects (tables, indexes, triggers, and views)
4438 ** defined by the database schema.</dd>)^
 
 
 
 
4439 ** </dl>
4440 */
4441 #define SQLITE_LIMIT_LENGTH 0
4442 #define SQLITE_LIMIT_SQL_LENGTH 1
4443 #define SQLITE_LIMIT_COLUMN 2
@@ -4450,10 +4454,11 @@
4450 #define SQLITE_LIMIT_VARIABLE_NUMBER 9
4451 #define SQLITE_LIMIT_TRIGGER_DEPTH 10
4452 #define SQLITE_LIMIT_WORKER_THREADS 11
4453 #define SQLITE_LIMIT_PARSER_DEPTH 12
4454 #define SQLITE_LIMIT_SCHEMA 13
 
4455
4456 /*
4457 ** CAPI3REF: Prepare Flags
4458 **
4459 ** These constants define various flags that can be passed into the
4460
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
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-08-20 13:25:12 3bd5456e50ef321f2cafcf67261d556a760624ce0caab430ed9454cebec233e7"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-08-20T13:25:12.207Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -4434,10 +4434,14 @@
4434 ** [prepared statement] may start.</dd>)^
4435 **
4436 ** [[SQLITE_LIMIT_SCHEMA]] ^(<dt>SQLITE_LIMIT_SCHEMA</dt>
4437 ** <dd>The maximum number of objects (tables, indexes, triggers, and views)
4438 ** defined by the database schema.</dd>)^
4439 **
4440 ** [[SQLITE_LIMIT_TRIGGER_STEPS]] ^(<dt>SQLITE_LIMIT_TRIGGER_STEPS</dt>
4441 ** <dd>The maximum number of SQL statements that can be contained within
4442 ** a single trigger.</dd>)^
4443 ** </dl>
4444 */
4445 #define SQLITE_LIMIT_LENGTH 0
4446 #define SQLITE_LIMIT_SQL_LENGTH 1
4447 #define SQLITE_LIMIT_COLUMN 2
@@ -4450,10 +4454,11 @@
4454 #define SQLITE_LIMIT_VARIABLE_NUMBER 9
4455 #define SQLITE_LIMIT_TRIGGER_DEPTH 10
4456 #define SQLITE_LIMIT_WORKER_THREADS 11
4457 #define SQLITE_LIMIT_PARSER_DEPTH 12
4458 #define SQLITE_LIMIT_SCHEMA 13
4459 #define SQLITE_LIMIT_TRIGGER_STEPS 14
4460
4461 /*
4462 ** CAPI3REF: Prepare Flags
4463 **
4464 ** These constants define various flags that can be passed into the
4465

Keyboard Shortcuts

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