Fossil SCM

Update the built-in SQLite to the latest trunk version.

drh 2026-06-16 16:45 UTC trunk
Commit ba00a4350442f6bb30153fb018de5cce6527edc6f186890f89a2646f54e2aa3c
3 files changed +96 -31 +300 -145 +19 -6
+96 -31
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -5424,11 +5424,11 @@
54245424
}
54255425
j = 0;
54265426
}else{
54275427
i = 0;
54285428
}
5429
- (void)memcpy(&p->buffer[j], &data[i], len - i);
5429
+ if( len-i>0 ) (void)memcpy(&p->buffer[j], &data[i], len - i);
54305430
}
54315431
54325432
/* Compute a string using sqlite3_vsnprintf() and hash it */
54335433
static void hash_step_vformat(
54345434
SHA1Context *p, /* Add content to this context */
@@ -6071,32 +6071,41 @@
60716071
}
60726072
z[i] = 0;
60736073
sqlite3_result_text(pCtx, z, i, sqlite3_free);
60746074
}
60756075
6076
+/* Forward declaration */
6077
+static void decimal_expand(Decimal *p, int nDigit, int nFrac);
6078
+
60766079
/*
60776080
** Round a decimal value to N significant digits. N must be positive.
60786081
*/
60796082
static void decimal_round(Decimal *p, int N){
60806083
int i;
6081
- int nZero;
6084
+ int nZero; /* Number of leading zeros */
60826085
if( N<1 ) return;
60836086
if( p==0 ) return;
60846087
if( p->nDigit<=N ) return;
60856088
for(nZero=0; nZero<p->nDigit && p->a[nZero]==0; nZero++){}
60866089
N += nZero;
60876090
if( p->nDigit<=N ) return;
6088
- if( p->a[N]>4 ){
6091
+ if( p->a[N]>=5 ){
6092
+ /* If all leading digits are 9, increase the number of digits
6093
+ ** by adding a new 0 to the front */
6094
+ for(i=0; i<N && p->a[i]==9; i++){}
6095
+ if( i==N ){
6096
+ decimal_expand(p, p->nDigit+1, 0);
6097
+ if( p->oom ) return;
6098
+ }
6099
+
6100
+ /* Do the rounding */
60896101
p->a[N-1]++;
60906102
for(i=N-1; i>0 && p->a[i]>9; i--){
60916103
p->a[i] = 0;
60926104
p->a[i-1]++;
60936105
}
6094
- if( p->a[0]>9 ){
6095
- p->a[0] = 1;
6096
- p->nFrac--;
6097
- }
6106
+ assert( p->a[0]<=9 );
60986107
}
60996108
memset(&p->a[N], 0, p->nDigit - N);
61006109
}
61016110
61026111
/*
@@ -8378,19 +8387,26 @@
83788387
}
83798388
}else{
83808389
iMin = iMax = sqlite3_value_int64(argv[iArg++]);
83818390
}
83828391
}else{
8383
- if( idxNum & 0x0300 ){ /* value>X or value>=X */
8392
+ if( idxNum & 0x0300 ){ /* value>X (0x200) or value>=X (0x100) */
83848393
if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
83858394
double r = sqlite3_value_double(argv[iArg++]);
8386
- if( r<(double)SMALLEST_INT64 ){
8395
+ if( r<=(double)SMALLEST_INT64 ){
83878396
iMin = SMALLEST_INT64;
8388
- }else if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){
8389
- iMin = (sqlite3_int64)seriesCeil(r)+1;
8397
+ }else if( r>(double)LARGEST_INT64 ){
8398
+ goto series_no_rows;
83908399
}else{
83918400
iMin = (sqlite3_int64)seriesCeil(r);
8401
+ if( iMin<0 && r>0.0 ){
8402
+ iMin = LARGEST_INT64;
8403
+ }
8404
+ if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){
8405
+ if( iMin==LARGEST_INT64 ) goto series_no_rows;
8406
+ iMin++;
8407
+ }
83928408
}
83938409
}else{
83948410
iMin = sqlite3_value_int64(argv[iArg++]);
83958411
if( (idxNum & 0x0200)!=0 ){
83968412
if( iMin==LARGEST_INT64 ){
@@ -8399,19 +8415,25 @@
83998415
iMin++;
84008416
}
84018417
}
84028418
}
84038419
}
8404
- if( idxNum & 0x3000 ){ /* value<X or value<=X */
8420
+ if( idxNum & 0x3000 ){ /* value<X (0x2000) or value<=X (0x1000) */
84058421
if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
84068422
double r = sqlite3_value_double(argv[iArg++]);
8407
- if( r>(double)LARGEST_INT64 ){
8423
+ if( r>=(double)LARGEST_INT64 ){
84088424
iMax = LARGEST_INT64;
8409
- }else if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){
8410
- iMax = ((sqlite3_int64)r)-1;
8425
+ }else if( r<=(double)SMALLEST_INT64 ){
8426
+ goto series_no_rows;
84118427
}else{
84128428
iMax = (sqlite3_int64)seriesFloor(r);
8429
+ if( iMax<0 && r>0.0 ){
8430
+ iMax = LARGEST_INT64;
8431
+ }else if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){
8432
+ if( iMax==SMALLEST_INT64 ) goto series_no_rows;
8433
+ iMax--;
8434
+ }
84138435
}
84148436
}else{
84158437
iMax = sqlite3_value_int64(argv[iArg++]);
84168438
if( idxNum & 0x2000 ){
84178439
if( iMax==SMALLEST_INT64 ){
@@ -10884,10 +10906,13 @@
1088410906
** Return NULL if unable.
1088510907
**
1088610908
** The file or directory X is not required to exist. The answer is formed
1088710909
** by calling system realpath() on the prefix of X that does exist and
1088810910
** appending the tail of X that does not (yet) exist.
10911
+**
10912
+** FIXME: This routine sometimes returns NULL rather than raising
10913
+** an SQLITE_NOMEM error if an OOM is encountered.
1088910914
*/
1089010915
static void realpathFunc(
1089110916
sqlite3_context *context,
1089210917
int argc,
1089310918
sqlite3_value **argv
@@ -10906,10 +10931,11 @@
1090610931
(void)argc;
1090710932
zPath = (const char*)sqlite3_value_text(argv[0]);
1090810933
if( zPath==0 ) return;
1090910934
if( zPath[0]==0 ) zPath = ".";
1091010935
zCopy = sqlite3_mprintf("%s",zPath);
10936
+ if( zCopy==0 ) return;
1091110937
len = strlen(zCopy);
1091210938
while( len>1 && (zCopy[len-1]=='/' || (isWin && zCopy[len-1]=='\\')) ){
1091310939
len--;
1091410940
}
1091510941
zCopy[len] = 0;
@@ -31323,11 +31349,11 @@
3132331349
typedef struct ArCommand ArCommand;
3132431350
struct ArCommand {
3132531351
u8 eCmd; /* An AR_CMD_* value */
3132631352
u8 bVerbose; /* True if --verbose */
3132731353
u8 bZip; /* True if the archive is a ZIP */
31328
- u8 bDryRun; /* True if --dry-run */
31354
+ u8 bDryRun; /* 1 for --dry-run, 2 for --debug */
3132931355
u8 bAppend; /* True if --append */
3133031356
u8 bGlob; /* True if --glob */
3133131357
u8 fromCmdLine; /* Run from -A instead of .archive */
3133231358
int nArg; /* Number of command arguments */
3133331359
char *zSrcTable; /* "sqlar", "zipfile($file)" or "zip" */
@@ -31385,10 +31411,11 @@
3138531411
#define AR_SWITCH_FILE 9
3138631412
#define AR_SWITCH_DIRECTORY 10
3138731413
#define AR_SWITCH_APPEND 11
3138831414
#define AR_SWITCH_DRYRUN 12
3138931415
#define AR_SWITCH_GLOB 13
31416
+#define AR_SWITCH_DEBUG 14
3139031417
3139131418
static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
3139231419
switch( eSwitch ){
3139331420
case AR_CMD_CREATE:
3139431421
case AR_CMD_EXTRACT:
@@ -31402,11 +31429,14 @@
3140231429
}
3140331430
pAr->eCmd = eSwitch;
3140431431
break;
3140531432
3140631433
case AR_SWITCH_DRYRUN:
31407
- pAr->bDryRun = 1;
31434
+ if( pAr->bDryRun<2 ) pAr->bDryRun = 1;
31435
+ break;
31436
+ case AR_SWITCH_DEBUG:
31437
+ pAr->bDryRun = 2;
3140831438
break;
3140931439
case AR_SWITCH_GLOB:
3141031440
pAr->bGlob = 1;
3141131441
break;
3141231442
case AR_SWITCH_VERBOSE:
@@ -31453,10 +31483,11 @@
3145331483
{ "verbose", 'v', AR_SWITCH_VERBOSE, 0 },
3145431484
{ "file", 'f', AR_SWITCH_FILE, 1 },
3145531485
{ "append", 'a', AR_SWITCH_APPEND, 1 },
3145631486
{ "directory", 'C', AR_SWITCH_DIRECTORY, 1 },
3145731487
{ "dryrun", 'n', AR_SWITCH_DRYRUN, 0 },
31488
+ { "debug", 0, AR_SWITCH_DEBUG, 0 },
3145831489
{ "glob", 'g', AR_SWITCH_GLOB, 0 },
3145931490
};
3146031491
int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch);
3146131492
struct ArSwitch *pEnd = &aSwitch[nSwitch];
3146231493
@@ -31753,18 +31784,41 @@
3175331784
3175431785
/*
3175531786
** Implementation of .ar "eXtract" command.
3175631787
*/
3175731788
static int arExtractCommand(ArCommand *pAr){
31789
+ /* The zSql1[] string is a template for the query that does the
31790
+ ** extraction. Notes:
31791
+ **
31792
+ ** * $dir is the directory into which the archive is to be extracted
31793
+ ** * $pass is the integer pass number: 0, 1, or 2
31794
+ ** * The dest CTE is created so that realpath($dir) only needs
31795
+ ** to be called once.
31796
+ */
3175831797
const char *zSql1 =
31759
- "WITH dest(dpath,dlen) AS (SELECT realpath($dir),length(realpath($dir)))\n"
31760
- "SELECT ($dir || name),\n"
31761
- " CASE WHEN $dryrun THEN 0\n"
31762
- " ELSE writefile($dir||name, %s, mode, mtime) END\n"
31798
+ "WITH dest(dpath,dlen) AS (\n"
31799
+#ifdef _WIN32
31800
+ " SELECT realpath($dir) || '\\',\n"
31801
+#else
31802
+ " SELECT realpath($dir) || '/',\n"
31803
+#endif
31804
+ " 1+length(realpath($dir))\n"
31805
+ ")\n"
31806
+ "SELECT\n"
31807
+ " ($dir || name),\n"
31808
+ " CASE $dryrun\n" /* vv--- azExtraArg */
31809
+ " WHEN 0 THEN writefile($dir||name, %s, mode, mtime)\n"
31810
+ " WHEN 1 THEN 0\n"
31811
+ " ELSE shell_putsnl(format('writefile(%%Q,%%s,%%0o,%%d)',"
31812
+ "$dir||name,quote(%s),mode,mtime)) IS NULL\n"
31813
+ " END\n" /* ^^--- azExtraArg */
3176331814
" FROM dest CROSS JOIN %s\n"
31764
- " WHERE (%s)\n"
31765
- " AND (data IS NULL OR $pass==0)\n" /* Dirs both passes */
31815
+ " WHERE (%s)\n" /* ^^-- pAr->zSrcTable */
31816
+ /* ^^--- zWhere */
31817
+ " AND (CASE $pass WHEN 0 THEN (mode&0xf000)<>0xa000\n"
31818
+ " WHEN 1 THEN (mode&0xf000)=0xa000\n"
31819
+ " ELSE data IS NULL END)\n"
3176631820
" AND dpath=substr(realpath($dir||name),1,dlen)\n" /* No escapes */
3176731821
" AND name NOT GLOB '*..[/\\]*'\n"; /* No /../ in paths */
3176831822
3176931823
const char *azExtraArg[] = {
3177031824
"sqlar_uncompress(data, sz)",
@@ -31791,39 +31845,48 @@
3179131845
}
3179231846
if( zDir==0 ) rc = SQLITE_NOMEM;
3179331847
}
3179431848
3179531849
shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
31796
- azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere
31850
+ azExtraArg[pAr->bZip],
31851
+ azExtraArg[pAr->bZip],
31852
+ pAr->zSrcTable,
31853
+ zWhere
3179731854
);
3179831855
3179931856
if( rc==SQLITE_OK ){
3180031857
j = sqlite3_bind_parameter_index(pSql, "$dir");
3180131858
sqlite3_bind_text(pSql, j, zDir, -1, SQLITE_STATIC);
3180231859
j = sqlite3_bind_parameter_index(pSql, "$dryrun");
3180331860
sqlite3_bind_int(pSql, j, pAr->bDryRun);
3180431861
3180531862
/* Run the SELECT statement twice
31806
- ** (0) writefile() all files and directories
31807
- ** (1) writefile() for directory again
31808
- ** The second pass is so that the timestamps for extracted directories
31863
+ ** (0) writefile() files and directories
31864
+ ** (1) writefile() symlinks
31865
+ ** (2) writefile() for directory again
31866
+ ** The third pass is so that the timestamps for extracted directories
3180931867
** will be reset to the value in the archive, since populating them
3181031868
** in the first pass will have changed the timestamp. */
31811
- for(i=0; i<2; i++){
31869
+ for(i=0; i<3; i++){
31870
+ if( pAr->bDryRun>=2 ){
31871
+ cli_printf(pAr->out, "*** BEGIN PASS %d ***\n", i+1);
31872
+ }
3181231873
j = sqlite3_bind_parameter_index(pSql, "$pass");
3181331874
sqlite3_bind_int(pSql, j, i);
31814
- if( pAr->bDryRun ){
31875
+ if( pAr->bDryRun && i==0 ){
3181531876
cli_printf(pAr->out, "%s\n", sqlite3_sql(pSql));
31816
- if( pAr->bVerbose==0 ) break;
3181731877
}
3181831878
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
3181931879
if( i==0 && pAr->bVerbose ){
3182031880
cli_printf(pAr->out, "%s\n", sqlite3_column_text(pSql, 0));
3182131881
}
3182231882
}
31823
- if( pAr->bDryRun ) break;
31883
+ if( pAr->bDryRun==1 ) break;
3182431884
shellReset(&rc, pSql);
31885
+ if( pAr->bDryRun>=2 ){
31886
+ cli_printf(pAr->out, "*** END PASS %d ***\n", i+1);
31887
+ }
3182531888
}
3182631889
shellFinalize(&rc, pSql);
3182731890
}
3182831891
3182931892
sqlite3_free(zDir);
@@ -38505,12 +38568,14 @@
3850538568
}else if( cli_strcmp(z,"-nullvalue")==0 ){
3850638569
modeSetStr(&data.mode.spec.zNull,
3850738570
cmdline_option_value(argc,argv,++i));
3850838571
}else if( cli_strcmp(z,"-header")==0 ){
3850938572
data.mode.spec.bTitles = QRF_Yes;
38573
+ data.mode.mFlags |= MFLG_HDR;
3851038574
}else if( cli_strcmp(z,"-noheader")==0 ){
3851138575
data.mode.spec.bTitles = QRF_No;
38576
+ data.mode.mFlags |= MFLG_HDR;
3851238577
}else if( cli_strcmp(z,"-echo")==0 ){
3851338578
data.mode.mFlags |= MFLG_ECHO;
3851438579
}else if( cli_strcmp(z,"-eqp")==0 ){
3851538580
data.mode.autoEQP = AUTOEQP_on;
3851638581
}else if( cli_strcmp(z,"-eqpfull")==0 ){
3851738582
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -5424,11 +5424,11 @@
5424 }
5425 j = 0;
5426 }else{
5427 i = 0;
5428 }
5429 (void)memcpy(&p->buffer[j], &data[i], len - i);
5430 }
5431
5432 /* Compute a string using sqlite3_vsnprintf() and hash it */
5433 static void hash_step_vformat(
5434 SHA1Context *p, /* Add content to this context */
@@ -6071,32 +6071,41 @@
6071 }
6072 z[i] = 0;
6073 sqlite3_result_text(pCtx, z, i, sqlite3_free);
6074 }
6075
 
 
 
6076 /*
6077 ** Round a decimal value to N significant digits. N must be positive.
6078 */
6079 static void decimal_round(Decimal *p, int N){
6080 int i;
6081 int nZero;
6082 if( N<1 ) return;
6083 if( p==0 ) return;
6084 if( p->nDigit<=N ) return;
6085 for(nZero=0; nZero<p->nDigit && p->a[nZero]==0; nZero++){}
6086 N += nZero;
6087 if( p->nDigit<=N ) return;
6088 if( p->a[N]>4 ){
 
 
 
 
 
 
 
 
 
6089 p->a[N-1]++;
6090 for(i=N-1; i>0 && p->a[i]>9; i--){
6091 p->a[i] = 0;
6092 p->a[i-1]++;
6093 }
6094 if( p->a[0]>9 ){
6095 p->a[0] = 1;
6096 p->nFrac--;
6097 }
6098 }
6099 memset(&p->a[N], 0, p->nDigit - N);
6100 }
6101
6102 /*
@@ -8378,19 +8387,26 @@
8378 }
8379 }else{
8380 iMin = iMax = sqlite3_value_int64(argv[iArg++]);
8381 }
8382 }else{
8383 if( idxNum & 0x0300 ){ /* value>X or value>=X */
8384 if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
8385 double r = sqlite3_value_double(argv[iArg++]);
8386 if( r<(double)SMALLEST_INT64 ){
8387 iMin = SMALLEST_INT64;
8388 }else if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){
8389 iMin = (sqlite3_int64)seriesCeil(r)+1;
8390 }else{
8391 iMin = (sqlite3_int64)seriesCeil(r);
 
 
 
 
 
 
 
8392 }
8393 }else{
8394 iMin = sqlite3_value_int64(argv[iArg++]);
8395 if( (idxNum & 0x0200)!=0 ){
8396 if( iMin==LARGEST_INT64 ){
@@ -8399,19 +8415,25 @@
8399 iMin++;
8400 }
8401 }
8402 }
8403 }
8404 if( idxNum & 0x3000 ){ /* value<X or value<=X */
8405 if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
8406 double r = sqlite3_value_double(argv[iArg++]);
8407 if( r>(double)LARGEST_INT64 ){
8408 iMax = LARGEST_INT64;
8409 }else if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){
8410 iMax = ((sqlite3_int64)r)-1;
8411 }else{
8412 iMax = (sqlite3_int64)seriesFloor(r);
 
 
 
 
 
 
8413 }
8414 }else{
8415 iMax = sqlite3_value_int64(argv[iArg++]);
8416 if( idxNum & 0x2000 ){
8417 if( iMax==SMALLEST_INT64 ){
@@ -10884,10 +10906,13 @@
10884 ** Return NULL if unable.
10885 **
10886 ** The file or directory X is not required to exist. The answer is formed
10887 ** by calling system realpath() on the prefix of X that does exist and
10888 ** appending the tail of X that does not (yet) exist.
 
 
 
10889 */
10890 static void realpathFunc(
10891 sqlite3_context *context,
10892 int argc,
10893 sqlite3_value **argv
@@ -10906,10 +10931,11 @@
10906 (void)argc;
10907 zPath = (const char*)sqlite3_value_text(argv[0]);
10908 if( zPath==0 ) return;
10909 if( zPath[0]==0 ) zPath = ".";
10910 zCopy = sqlite3_mprintf("%s",zPath);
 
10911 len = strlen(zCopy);
10912 while( len>1 && (zCopy[len-1]=='/' || (isWin && zCopy[len-1]=='\\')) ){
10913 len--;
10914 }
10915 zCopy[len] = 0;
@@ -31323,11 +31349,11 @@
31323 typedef struct ArCommand ArCommand;
31324 struct ArCommand {
31325 u8 eCmd; /* An AR_CMD_* value */
31326 u8 bVerbose; /* True if --verbose */
31327 u8 bZip; /* True if the archive is a ZIP */
31328 u8 bDryRun; /* True if --dry-run */
31329 u8 bAppend; /* True if --append */
31330 u8 bGlob; /* True if --glob */
31331 u8 fromCmdLine; /* Run from -A instead of .archive */
31332 int nArg; /* Number of command arguments */
31333 char *zSrcTable; /* "sqlar", "zipfile($file)" or "zip" */
@@ -31385,10 +31411,11 @@
31385 #define AR_SWITCH_FILE 9
31386 #define AR_SWITCH_DIRECTORY 10
31387 #define AR_SWITCH_APPEND 11
31388 #define AR_SWITCH_DRYRUN 12
31389 #define AR_SWITCH_GLOB 13
 
31390
31391 static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
31392 switch( eSwitch ){
31393 case AR_CMD_CREATE:
31394 case AR_CMD_EXTRACT:
@@ -31402,11 +31429,14 @@
31402 }
31403 pAr->eCmd = eSwitch;
31404 break;
31405
31406 case AR_SWITCH_DRYRUN:
31407 pAr->bDryRun = 1;
 
 
 
31408 break;
31409 case AR_SWITCH_GLOB:
31410 pAr->bGlob = 1;
31411 break;
31412 case AR_SWITCH_VERBOSE:
@@ -31453,10 +31483,11 @@
31453 { "verbose", 'v', AR_SWITCH_VERBOSE, 0 },
31454 { "file", 'f', AR_SWITCH_FILE, 1 },
31455 { "append", 'a', AR_SWITCH_APPEND, 1 },
31456 { "directory", 'C', AR_SWITCH_DIRECTORY, 1 },
31457 { "dryrun", 'n', AR_SWITCH_DRYRUN, 0 },
 
31458 { "glob", 'g', AR_SWITCH_GLOB, 0 },
31459 };
31460 int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch);
31461 struct ArSwitch *pEnd = &aSwitch[nSwitch];
31462
@@ -31753,18 +31784,41 @@
31753
31754 /*
31755 ** Implementation of .ar "eXtract" command.
31756 */
31757 static int arExtractCommand(ArCommand *pAr){
 
 
 
 
 
 
 
 
31758 const char *zSql1 =
31759 "WITH dest(dpath,dlen) AS (SELECT realpath($dir),length(realpath($dir)))\n"
31760 "SELECT ($dir || name),\n"
31761 " CASE WHEN $dryrun THEN 0\n"
31762 " ELSE writefile($dir||name, %s, mode, mtime) END\n"
 
 
 
 
 
 
 
 
 
 
 
 
31763 " FROM dest CROSS JOIN %s\n"
31764 " WHERE (%s)\n"
31765 " AND (data IS NULL OR $pass==0)\n" /* Dirs both passes */
 
 
 
31766 " AND dpath=substr(realpath($dir||name),1,dlen)\n" /* No escapes */
31767 " AND name NOT GLOB '*..[/\\]*'\n"; /* No /../ in paths */
31768
31769 const char *azExtraArg[] = {
31770 "sqlar_uncompress(data, sz)",
@@ -31791,39 +31845,48 @@
31791 }
31792 if( zDir==0 ) rc = SQLITE_NOMEM;
31793 }
31794
31795 shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
31796 azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere
 
 
 
31797 );
31798
31799 if( rc==SQLITE_OK ){
31800 j = sqlite3_bind_parameter_index(pSql, "$dir");
31801 sqlite3_bind_text(pSql, j, zDir, -1, SQLITE_STATIC);
31802 j = sqlite3_bind_parameter_index(pSql, "$dryrun");
31803 sqlite3_bind_int(pSql, j, pAr->bDryRun);
31804
31805 /* Run the SELECT statement twice
31806 ** (0) writefile() all files and directories
31807 ** (1) writefile() for directory again
31808 ** The second pass is so that the timestamps for extracted directories
 
31809 ** will be reset to the value in the archive, since populating them
31810 ** in the first pass will have changed the timestamp. */
31811 for(i=0; i<2; i++){
 
 
 
31812 j = sqlite3_bind_parameter_index(pSql, "$pass");
31813 sqlite3_bind_int(pSql, j, i);
31814 if( pAr->bDryRun ){
31815 cli_printf(pAr->out, "%s\n", sqlite3_sql(pSql));
31816 if( pAr->bVerbose==0 ) break;
31817 }
31818 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
31819 if( i==0 && pAr->bVerbose ){
31820 cli_printf(pAr->out, "%s\n", sqlite3_column_text(pSql, 0));
31821 }
31822 }
31823 if( pAr->bDryRun ) break;
31824 shellReset(&rc, pSql);
 
 
 
31825 }
31826 shellFinalize(&rc, pSql);
31827 }
31828
31829 sqlite3_free(zDir);
@@ -38505,12 +38568,14 @@
38505 }else if( cli_strcmp(z,"-nullvalue")==0 ){
38506 modeSetStr(&data.mode.spec.zNull,
38507 cmdline_option_value(argc,argv,++i));
38508 }else if( cli_strcmp(z,"-header")==0 ){
38509 data.mode.spec.bTitles = QRF_Yes;
 
38510 }else if( cli_strcmp(z,"-noheader")==0 ){
38511 data.mode.spec.bTitles = QRF_No;
 
38512 }else if( cli_strcmp(z,"-echo")==0 ){
38513 data.mode.mFlags |= MFLG_ECHO;
38514 }else if( cli_strcmp(z,"-eqp")==0 ){
38515 data.mode.autoEQP = AUTOEQP_on;
38516 }else if( cli_strcmp(z,"-eqpfull")==0 ){
38517
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -5424,11 +5424,11 @@
5424 }
5425 j = 0;
5426 }else{
5427 i = 0;
5428 }
5429 if( len-i>0 ) (void)memcpy(&p->buffer[j], &data[i], len - i);
5430 }
5431
5432 /* Compute a string using sqlite3_vsnprintf() and hash it */
5433 static void hash_step_vformat(
5434 SHA1Context *p, /* Add content to this context */
@@ -6071,32 +6071,41 @@
6071 }
6072 z[i] = 0;
6073 sqlite3_result_text(pCtx, z, i, sqlite3_free);
6074 }
6075
6076 /* Forward declaration */
6077 static void decimal_expand(Decimal *p, int nDigit, int nFrac);
6078
6079 /*
6080 ** Round a decimal value to N significant digits. N must be positive.
6081 */
6082 static void decimal_round(Decimal *p, int N){
6083 int i;
6084 int nZero; /* Number of leading zeros */
6085 if( N<1 ) return;
6086 if( p==0 ) return;
6087 if( p->nDigit<=N ) return;
6088 for(nZero=0; nZero<p->nDigit && p->a[nZero]==0; nZero++){}
6089 N += nZero;
6090 if( p->nDigit<=N ) return;
6091 if( p->a[N]>=5 ){
6092 /* If all leading digits are 9, increase the number of digits
6093 ** by adding a new 0 to the front */
6094 for(i=0; i<N && p->a[i]==9; i++){}
6095 if( i==N ){
6096 decimal_expand(p, p->nDigit+1, 0);
6097 if( p->oom ) return;
6098 }
6099
6100 /* Do the rounding */
6101 p->a[N-1]++;
6102 for(i=N-1; i>0 && p->a[i]>9; i--){
6103 p->a[i] = 0;
6104 p->a[i-1]++;
6105 }
6106 assert( p->a[0]<=9 );
 
 
 
6107 }
6108 memset(&p->a[N], 0, p->nDigit - N);
6109 }
6110
6111 /*
@@ -8378,19 +8387,26 @@
8387 }
8388 }else{
8389 iMin = iMax = sqlite3_value_int64(argv[iArg++]);
8390 }
8391 }else{
8392 if( idxNum & 0x0300 ){ /* value>X (0x200) or value>=X (0x100) */
8393 if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
8394 double r = sqlite3_value_double(argv[iArg++]);
8395 if( r<=(double)SMALLEST_INT64 ){
8396 iMin = SMALLEST_INT64;
8397 }else if( r>(double)LARGEST_INT64 ){
8398 goto series_no_rows;
8399 }else{
8400 iMin = (sqlite3_int64)seriesCeil(r);
8401 if( iMin<0 && r>0.0 ){
8402 iMin = LARGEST_INT64;
8403 }
8404 if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){
8405 if( iMin==LARGEST_INT64 ) goto series_no_rows;
8406 iMin++;
8407 }
8408 }
8409 }else{
8410 iMin = sqlite3_value_int64(argv[iArg++]);
8411 if( (idxNum & 0x0200)!=0 ){
8412 if( iMin==LARGEST_INT64 ){
@@ -8399,19 +8415,25 @@
8415 iMin++;
8416 }
8417 }
8418 }
8419 }
8420 if( idxNum & 0x3000 ){ /* value<X (0x2000) or value<=X (0x1000) */
8421 if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
8422 double r = sqlite3_value_double(argv[iArg++]);
8423 if( r>=(double)LARGEST_INT64 ){
8424 iMax = LARGEST_INT64;
8425 }else if( r<=(double)SMALLEST_INT64 ){
8426 goto series_no_rows;
8427 }else{
8428 iMax = (sqlite3_int64)seriesFloor(r);
8429 if( iMax<0 && r>0.0 ){
8430 iMax = LARGEST_INT64;
8431 }else if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){
8432 if( iMax==SMALLEST_INT64 ) goto series_no_rows;
8433 iMax--;
8434 }
8435 }
8436 }else{
8437 iMax = sqlite3_value_int64(argv[iArg++]);
8438 if( idxNum & 0x2000 ){
8439 if( iMax==SMALLEST_INT64 ){
@@ -10884,10 +10906,13 @@
10906 ** Return NULL if unable.
10907 **
10908 ** The file or directory X is not required to exist. The answer is formed
10909 ** by calling system realpath() on the prefix of X that does exist and
10910 ** appending the tail of X that does not (yet) exist.
10911 **
10912 ** FIXME: This routine sometimes returns NULL rather than raising
10913 ** an SQLITE_NOMEM error if an OOM is encountered.
10914 */
10915 static void realpathFunc(
10916 sqlite3_context *context,
10917 int argc,
10918 sqlite3_value **argv
@@ -10906,10 +10931,11 @@
10931 (void)argc;
10932 zPath = (const char*)sqlite3_value_text(argv[0]);
10933 if( zPath==0 ) return;
10934 if( zPath[0]==0 ) zPath = ".";
10935 zCopy = sqlite3_mprintf("%s",zPath);
10936 if( zCopy==0 ) return;
10937 len = strlen(zCopy);
10938 while( len>1 && (zCopy[len-1]=='/' || (isWin && zCopy[len-1]=='\\')) ){
10939 len--;
10940 }
10941 zCopy[len] = 0;
@@ -31323,11 +31349,11 @@
31349 typedef struct ArCommand ArCommand;
31350 struct ArCommand {
31351 u8 eCmd; /* An AR_CMD_* value */
31352 u8 bVerbose; /* True if --verbose */
31353 u8 bZip; /* True if the archive is a ZIP */
31354 u8 bDryRun; /* 1 for --dry-run, 2 for --debug */
31355 u8 bAppend; /* True if --append */
31356 u8 bGlob; /* True if --glob */
31357 u8 fromCmdLine; /* Run from -A instead of .archive */
31358 int nArg; /* Number of command arguments */
31359 char *zSrcTable; /* "sqlar", "zipfile($file)" or "zip" */
@@ -31385,10 +31411,11 @@
31411 #define AR_SWITCH_FILE 9
31412 #define AR_SWITCH_DIRECTORY 10
31413 #define AR_SWITCH_APPEND 11
31414 #define AR_SWITCH_DRYRUN 12
31415 #define AR_SWITCH_GLOB 13
31416 #define AR_SWITCH_DEBUG 14
31417
31418 static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
31419 switch( eSwitch ){
31420 case AR_CMD_CREATE:
31421 case AR_CMD_EXTRACT:
@@ -31402,11 +31429,14 @@
31429 }
31430 pAr->eCmd = eSwitch;
31431 break;
31432
31433 case AR_SWITCH_DRYRUN:
31434 if( pAr->bDryRun<2 ) pAr->bDryRun = 1;
31435 break;
31436 case AR_SWITCH_DEBUG:
31437 pAr->bDryRun = 2;
31438 break;
31439 case AR_SWITCH_GLOB:
31440 pAr->bGlob = 1;
31441 break;
31442 case AR_SWITCH_VERBOSE:
@@ -31453,10 +31483,11 @@
31483 { "verbose", 'v', AR_SWITCH_VERBOSE, 0 },
31484 { "file", 'f', AR_SWITCH_FILE, 1 },
31485 { "append", 'a', AR_SWITCH_APPEND, 1 },
31486 { "directory", 'C', AR_SWITCH_DIRECTORY, 1 },
31487 { "dryrun", 'n', AR_SWITCH_DRYRUN, 0 },
31488 { "debug", 0, AR_SWITCH_DEBUG, 0 },
31489 { "glob", 'g', AR_SWITCH_GLOB, 0 },
31490 };
31491 int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch);
31492 struct ArSwitch *pEnd = &aSwitch[nSwitch];
31493
@@ -31753,18 +31784,41 @@
31784
31785 /*
31786 ** Implementation of .ar "eXtract" command.
31787 */
31788 static int arExtractCommand(ArCommand *pAr){
31789 /* The zSql1[] string is a template for the query that does the
31790 ** extraction. Notes:
31791 **
31792 ** * $dir is the directory into which the archive is to be extracted
31793 ** * $pass is the integer pass number: 0, 1, or 2
31794 ** * The dest CTE is created so that realpath($dir) only needs
31795 ** to be called once.
31796 */
31797 const char *zSql1 =
31798 "WITH dest(dpath,dlen) AS (\n"
31799 #ifdef _WIN32
31800 " SELECT realpath($dir) || '\\',\n"
31801 #else
31802 " SELECT realpath($dir) || '/',\n"
31803 #endif
31804 " 1+length(realpath($dir))\n"
31805 ")\n"
31806 "SELECT\n"
31807 " ($dir || name),\n"
31808 " CASE $dryrun\n" /* vv--- azExtraArg */
31809 " WHEN 0 THEN writefile($dir||name, %s, mode, mtime)\n"
31810 " WHEN 1 THEN 0\n"
31811 " ELSE shell_putsnl(format('writefile(%%Q,%%s,%%0o,%%d)',"
31812 "$dir||name,quote(%s),mode,mtime)) IS NULL\n"
31813 " END\n" /* ^^--- azExtraArg */
31814 " FROM dest CROSS JOIN %s\n"
31815 " WHERE (%s)\n" /* ^^-- pAr->zSrcTable */
31816 /* ^^--- zWhere */
31817 " AND (CASE $pass WHEN 0 THEN (mode&0xf000)<>0xa000\n"
31818 " WHEN 1 THEN (mode&0xf000)=0xa000\n"
31819 " ELSE data IS NULL END)\n"
31820 " AND dpath=substr(realpath($dir||name),1,dlen)\n" /* No escapes */
31821 " AND name NOT GLOB '*..[/\\]*'\n"; /* No /../ in paths */
31822
31823 const char *azExtraArg[] = {
31824 "sqlar_uncompress(data, sz)",
@@ -31791,39 +31845,48 @@
31845 }
31846 if( zDir==0 ) rc = SQLITE_NOMEM;
31847 }
31848
31849 shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
31850 azExtraArg[pAr->bZip],
31851 azExtraArg[pAr->bZip],
31852 pAr->zSrcTable,
31853 zWhere
31854 );
31855
31856 if( rc==SQLITE_OK ){
31857 j = sqlite3_bind_parameter_index(pSql, "$dir");
31858 sqlite3_bind_text(pSql, j, zDir, -1, SQLITE_STATIC);
31859 j = sqlite3_bind_parameter_index(pSql, "$dryrun");
31860 sqlite3_bind_int(pSql, j, pAr->bDryRun);
31861
31862 /* Run the SELECT statement twice
31863 ** (0) writefile() files and directories
31864 ** (1) writefile() symlinks
31865 ** (2) writefile() for directory again
31866 ** The third pass is so that the timestamps for extracted directories
31867 ** will be reset to the value in the archive, since populating them
31868 ** in the first pass will have changed the timestamp. */
31869 for(i=0; i<3; i++){
31870 if( pAr->bDryRun>=2 ){
31871 cli_printf(pAr->out, "*** BEGIN PASS %d ***\n", i+1);
31872 }
31873 j = sqlite3_bind_parameter_index(pSql, "$pass");
31874 sqlite3_bind_int(pSql, j, i);
31875 if( pAr->bDryRun && i==0 ){
31876 cli_printf(pAr->out, "%s\n", sqlite3_sql(pSql));
 
31877 }
31878 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
31879 if( i==0 && pAr->bVerbose ){
31880 cli_printf(pAr->out, "%s\n", sqlite3_column_text(pSql, 0));
31881 }
31882 }
31883 if( pAr->bDryRun==1 ) break;
31884 shellReset(&rc, pSql);
31885 if( pAr->bDryRun>=2 ){
31886 cli_printf(pAr->out, "*** END PASS %d ***\n", i+1);
31887 }
31888 }
31889 shellFinalize(&rc, pSql);
31890 }
31891
31892 sqlite3_free(zDir);
@@ -38505,12 +38568,14 @@
38568 }else if( cli_strcmp(z,"-nullvalue")==0 ){
38569 modeSetStr(&data.mode.spec.zNull,
38570 cmdline_option_value(argc,argv,++i));
38571 }else if( cli_strcmp(z,"-header")==0 ){
38572 data.mode.spec.bTitles = QRF_Yes;
38573 data.mode.mFlags |= MFLG_HDR;
38574 }else if( cli_strcmp(z,"-noheader")==0 ){
38575 data.mode.spec.bTitles = QRF_No;
38576 data.mode.mFlags |= MFLG_HDR;
38577 }else if( cli_strcmp(z,"-echo")==0 ){
38578 data.mode.mFlags |= MFLG_ECHO;
38579 }else if( cli_strcmp(z,"-eqp")==0 ){
38580 data.mode.autoEQP = AUTOEQP_on;
38581 }else if( cli_strcmp(z,"-eqpfull")==0 ){
38582
+300 -145
--- 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
-** 4cb349370daab17123770c814c71872a3e4c with changes in files:
21
+** 3f3fb9b638f59ad982beafb7c117f24ddd3d 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-06-08 18:15:27 4cb349370daab17123770c814c71872a3e4c616a3f984569b3d7f97f9c3f5ea0"
472
+#define SQLITE_SOURCE_ID "2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2026-06-08T18:15:27.790Z"
475
+#define SQLITE_SCM_DATETIME "2026-06-16T13:43:08.110Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -4696,11 +4696,12 @@
46964696
** <dd>The maximum number of columns in a table definition or in the
46974697
** result set of a [SELECT] or the maximum number of columns in an index
46984698
** or in an ORDER BY or GROUP BY clause.</dd>)^
46994699
**
47004700
** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
4701
-** <dd>The maximum depth of the parse tree on any expression.</dd>)^
4701
+** <dd>The maximum depth of the parse tree on any expression and
4702
+** the maximum nesting depth for subqueries and VIEWs</dd>)^
47024703
**
47034704
** [[SQLITE_LIMIT_PARSER_DEPTH]] ^(<dt>SQLITE_LIMIT_PARSER_DEPTH</dt>
47044705
** <dd>The maximum depth of the LALR(1) parser stack used to analyze
47054706
** input SQL statements.</dd>)^
47064707
**
@@ -4727,11 +4728,12 @@
47274728
** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
47284729
** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
47294730
** <dd>The maximum index number of any [parameter] in an SQL statement.)^
47304731
**
47314732
** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
4732
-** <dd>The maximum depth of recursion for triggers.</dd>)^
4733
+** <dd>The maximum depth of recursion for triggers, and the maximum
4734
+** nesting depth for separate triggers.</dd>)^
47334735
**
47344736
** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
47354737
** <dd>The maximum number of auxiliary worker threads that a single
47364738
** [prepared statement] may start.</dd>)^
47374739
** </dl>
@@ -11533,12 +11535,23 @@
1153311535
** reopen S as an in-memory database based on the serialization
1153411536
** contained in P. If S is a NULL pointer, the main database is
1153511537
** used. The serialized database P is N bytes in size. M is the size
1153611538
** of the buffer P, which might be larger than N. If M is larger than
1153711539
** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then
11538
-** SQLite is permitted to add content to the in-memory database as
11539
-** long as the total size does not exceed M bytes.
11540
+** SQLite is permitted to add content to the in-memory database, in
11541
+** page-sized chunks, as long as the total size does not exceed M bytes.
11542
+**
11543
+** The parameter M must be greater than or equal to N. Ideally, M
11544
+** should have a value which is N+(512&times;K)+20 where K determines how
11545
+** must extra space is available to hold new content as the database
11546
+** grows. K can be 0 if the database is read-only.
11547
+**
11548
+** If the database content in P is malformed in a malicious way then
11549
+** it is possible that SQLite might try to read a few more than N bytes
11550
+** from P. If the veracity of the database content P is uncertain,
11551
+** then applications are advised to allocate about 20 extra bytes on
11552
+** the end of the P buffer to avoid a memory error.
1154011553
**
1154111554
** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
1154211555
** invoke sqlite3_free() on the serialization buffer when the database
1154311556
** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
1154411557
** SQLite will try to increase the buffer size using sqlite3_realloc64()
@@ -15809,10 +15822,17 @@
1580915822
*/
1581015823
#ifndef offsetof
1581115824
# define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
1581215825
#endif
1581315826
15827
+/*
15828
+** sizeof64() is like sizeof(), but always returns a 64-bit value, even
15829
+** on 32-bit builds. This can help to avoid overflow by ensuring 64-bit
15830
+** arithmetic is used consistently in both 32-bit and 64-bit builds.
15831
+*/
15832
+#define sizeof64(X) ((sqlite3_int64)sizeof(X))
15833
+
1581415834
/*
1581515835
** Work around C99 "flex-array" syntax for pre-C99 compilers, so as
1581615836
** to avoid complaints from -fsanitize=strict-bounds.
1581715837
*/
1581815838
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
@@ -20928,10 +20948,11 @@
2092820948
int nTab; /* Number of previously allocated VDBE cursors */
2092920949
int nMem; /* Number of memory cells used so far */
2093020950
int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */
2093120951
int iSelfTab; /* Table associated with an index on expr, or negative
2093220952
** of the base register during check-constraint eval */
20953
+ int nNestSel; /* Number of nested SELECT statements and/or VIEWs */
2093320954
int nLabel; /* The *negative* of the number of labels used */
2093420955
int nLabelAlloc; /* Number of slots in aLabel */
2093520956
int *aLabel; /* Space to hold the labels */
2093620957
ExprList *pConstExpr;/* Constant expressions */
2093720958
IndexedExpr *pIdxEpr;/* List of expressions used by active indexes */
@@ -39255,10 +39276,26 @@
3925539276
******************************************************************************
3925639277
**
3925739278
** This file contains an experimental VFS layer that operates on a
3925839279
** Key/Value storage engine where both keys and values must be pure
3925939280
** text.
39281
+**
39282
+** DEBUG AND TEST
39283
+**
39284
+** For testing on Unix, compile using:
39285
+**
39286
+** make clean sqlite3d CFLAGS='-DSQLITE_OS_KV_OPTIONAL'
39287
+**
39288
+** Then start up a shell using something like:
39289
+**
39290
+** ./sqlite3d 'file:dbname?vfs=kvvfs'
39291
+**
39292
+** Each K/V entry is stored in a separate file in the working
39293
+** directory that has a name like "kvvfs-dbname-*". Due to limitations
39294
+** on the key size, the name of the database must be very short - just
39295
+** a few characters. If the database name is too long, the VFS will
39296
+** malfunction and you will get SQLITE_CORRUPT errors.
3926039297
*/
3926139298
/* #include <sqliteInt.h> */
3926239299
#if SQLITE_OS_KV || (SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL))
3926339300
3926439301
/*****************************************************************************
@@ -39707,16 +39744,18 @@
3970739744
}
3970839745
if( j+n>nOut ) return -1;
3970939746
memset(&aOut[j], 0, n);
3971039747
j += n;
3971139748
if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */
39712
- }else{
39749
+ }else if( j<nOut ){
3971339750
aOut[j] = c<<4;
3971439751
c = kvvfsHexValue[aIn[++i]];
3971539752
if( c<0 ) return -1 /* hex bytes are always in pairs */;
3971639753
aOut[j++] += c;
3971739754
i++;
39755
+ }else{
39756
+ return -1;
3971839757
}
3971939758
}
3972039759
return j;
3972139760
}
3972239761
@@ -40138,10 +40177,22 @@
4013840177
}else{
4013940178
pFile->isJournal = 0;
4014040179
pFile->base.pMethods = &kvvfs_db_io_methods;
4014140180
}
4014240181
if( !pFile->zClass ){
40182
+#ifdef SQLITE_WASM
40183
+ if( strlen(zName) >= (KVRECORD_KEY_SZ
40184
+ - 6 /* "kvvfs-" */
40185
+ - 11 /* "-##########" */) ){
40186
+ return SQLITE_CANTOPEN;
40187
+ }
40188
+#else
40189
+ if( 0!=strcmp(zName, "local") && 0!=strcmp(zName, "session") ){
40190
+ /* Historical naming restriction which journaling depends on. */
40191
+ return SQLITE_CANTOPEN;
40192
+ }
40193
+#endif
4014340194
pFile->zClass = zName;
4014440195
}
4014540196
pFile->aData = sqlite3_malloc64(SQLITE_KVOS_SZ);
4014640197
if( pFile->aData==0 ){
4014740198
return SQLITE_NOMEM;
@@ -52170,15 +52221,33 @@
5217052221
# define sqlite3_win_test_unc_locking 0
5217152222
#endif
5217252223
5217352224
/*
5217452225
** Return true if the string passed as the only argument is likely
52175
-** to be a UNC path. In other words, if it starts with "\\".
52226
+** to be a UNC path. Return false if note.
52227
+**
52228
+** Return true if:
52229
+**
52230
+** (1) The name begins with "\\"
52231
+** (2) But does not begin with "\\?\C:\" where C can be any alphabetic
52232
+** character.
52233
+**
52234
+** For testing, also return true in all cases if the global variable
52235
+** sqlite3_win_test_unc_locking is true.
5217652236
*/
5217752237
static int winIsUNCPath(const char *zFile){
5217852238
if( zFile[0]=='\\' && zFile[1]=='\\' ){
52179
- return 1;
52239
+ if( zFile[2]=='?'
52240
+ && zFile[3]=='\\'
52241
+ && sqlite3Isalpha(zFile[4])
52242
+ && zFile[5]==':'
52243
+ && winIsDirSep(zFile[6])
52244
+ ){
52245
+ return sqlite3_win_test_unc_locking;
52246
+ }else{
52247
+ return 1;
52248
+ }
5218052249
}
5218152250
return sqlite3_win_test_unc_locking;
5218252251
}
5218352252
5218452253
/*
@@ -59841,73 +59910,84 @@
5984159910
#define pager_set_pagehash(X)
5984259911
#define CHECK_PAGE(x)
5984359912
#endif /* SQLITE_CHECK_PAGES */
5984459913
5984559914
/*
59846
-** When this is called the journal file for pager pPager must be open.
59847
-** This function attempts to read a super-journal file name from the
59848
-** end of the file and, if successful, copies it into memory supplied
59849
-** by the caller. See comments above writeSuperJournal() for the format
59850
-** used to store a super-journal file name at the end of a journal file.
59851
-**
59852
-** zSuper must point to a buffer of at least nSuper bytes allocated by
59853
-** the caller. This should be sqlite3_vfs.mxPathname+1 (to ensure there is
59854
-** enough space to write the super-journal name). If the super-journal
59855
-** name in the journal is longer than nSuper bytes (including a
59856
-** nul-terminator), then this is handled as if no super-journal name
59857
-** were present in the journal.
59858
-**
59859
-** If a super-journal file name is present at the end of the journal
59860
-** file, then it is copied into the buffer pointed to by zSuper. A
59861
-** nul-terminator byte is appended to the buffer following the
59862
-** super-journal file name.
59863
-**
59864
-** If it is determined that no super-journal file name is present
59865
-** zSuper[0] is set to 0 and SQLITE_OK returned.
59866
-**
59867
-** If an error occurs while reading from the journal file, an SQLite
59868
-** error code is returned.
59869
-*/
59870
-static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u64 nSuper){
59915
+** Free a buffer allocated by the readSuperJournal() function.
59916
+*/
59917
+static void freeSuperJournal(char *zSuper){
59918
+ if( zSuper ){
59919
+ sqlite3_free(&zSuper[-4]);
59920
+ }
59921
+}
59922
+
59923
+/*
59924
+** Parameter pJrnl is a file-handle open on a journal file. This function
59925
+** attempts to read a super-journal file name from the end of the journal
59926
+** file. If successful, it sets output parameter (*pzSuper) to point to a
59927
+** buffer containing the super-journal name as a nul-terminated string.
59928
+** The caller is responsible for freeing the buffer using freeSuperJournal().
59929
+**
59930
+** Refer to comments above writeSuperJournal() for the format used to store
59931
+** a super-journal file name at the end of a journal file.
59932
+**
59933
+** Parameter nSuper is passed the maximum allowable size of the super journal
59934
+** name in bytes. If the super-journal name in the journal is longer than
59935
+** nSuper bytes (including a nul-terminator), then this is handled as if no
59936
+** super-journal name were present in the journal.
59937
+**
59938
+** If there is no super-journal name at the end of pJrnl, (*pzSuper) is
59939
+** set to 0 and SQLITE_OK is returned. Or, if an error occurs while reading
59940
+** the super-journal name, an SQLite error code is returned and (*pzSuper)
59941
+** is set to 0.
59942
+*/
59943
+static int readSuperJournal(sqlite3_file *pJrnl, u64 nSuper, char **pzSuper){
5987159944
int rc; /* Return code */
5987259945
u32 len; /* Length in bytes of super-journal name */
5987359946
i64 szJ; /* Total size in bytes of journal file pJrnl */
5987459947
u32 cksum; /* MJ checksum value read from journal */
59875
- u32 u; /* Unsigned loop counter */
5987659948
unsigned char aMagic[8]; /* A buffer to hold the magic header */
59877
- zSuper[0] = '\0';
59949
+ char *zOut = 0;
5987859950
59951
+ *pzSuper = 0;
5987959952
if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
5988059953
|| szJ<16
5988159954
|| SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
5988259955
|| len>=nSuper
5988359956
|| len>szJ-16
5988459957
|| len==0
5988559958
|| SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
5988659959
|| SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
5988759960
|| memcmp(aMagic, aJournalMagic, 8)
59888
- || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zSuper, len, szJ-16-len))
5988959961
){
5989059962
return rc;
5989159963
}
5989259964
59893
- /* See if the checksum matches the super-journal name */
59894
- for(u=0; u<len; u++){
59895
- cksum -= zSuper[u];
59896
- }
59897
- if( cksum ){
59898
- /* If the checksum doesn't add up, then one or more of the disk sectors
59899
- ** containing the super-journal filename is corrupted. This means
59900
- ** definitely roll back, so just return SQLITE_OK and report a (nul)
59901
- ** super-journal filename.
59902
- */
59903
- len = 0;
59904
- }
59905
- zSuper[len] = '\0';
59906
- zSuper[len+1] = '\0';
59907
-
59908
- return SQLITE_OK;
59965
+ zOut = (char*)sqlite3MallocZero(4 + len + 2);
59966
+ if( !zOut ){
59967
+ rc = SQLITE_NOMEM_BKPT;
59968
+ }else{
59969
+ zOut = &zOut[4];
59970
+ if( SQLITE_OK==(rc = sqlite3OsRead(pJrnl, zOut, len, szJ-16-len)) ){
59971
+ u32 u; /* Unsigned loop counter */
59972
+ /* See if the checksum matches the super-journal name */
59973
+ for(u=0; u<len; u++){
59974
+ cksum -= zOut[u];
59975
+ }
59976
+ }
59977
+ if( rc!=SQLITE_OK || cksum ){
59978
+ /* If the checksum doesn't add up, then one or more of the disk sectors
59979
+ ** containing the super-journal filename is corrupted. This means
59980
+ ** definitely roll back, so just return SQLITE_OK and report a (nul)
59981
+ ** super-journal filename. */
59982
+ freeSuperJournal(zOut);
59983
+ zOut = 0;
59984
+ }
59985
+ }
59986
+
59987
+ *pzSuper = zOut;
59988
+ return rc;
5990959989
}
5991059990
5991159991
/*
5991259992
** Return the offset of the sector boundary at or immediately
5991359993
** following the value in pPager->journalOff, assuming a sector
@@ -61108,13 +61188,11 @@
6110861188
sqlite3_file *pSuper; /* Malloc'd super-journal file descriptor */
6110961189
sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
6111061190
char *zSuperJournal = 0; /* Contents of super-journal file */
6111161191
i64 nSuperJournal; /* Size of super-journal file */
6111261192
char *zJournal; /* Pointer to one journal within MJ file */
61113
- char *zSuperPtr; /* Space to hold super-journal filename */
6111461193
char *zFree = 0; /* Free this buffer */
61115
- i64 nSuperPtr; /* Amount of space allocated to zSuperPtr[] */
6111661194
6111761195
/* Allocate space for both the pJournal and pSuper file descriptors.
6111861196
** If successful, open the super-journal file for reading.
6111961197
*/
6112061198
pSuper = (sqlite3_file *)sqlite3MallocZero(2 * (i64)pVfs->szOsFile);
@@ -61133,22 +61211,20 @@
6113361211
** sufficient space (in zSuperPtr) to hold the names of super-journal
6113461212
** files extracted from regular rollback-journals.
6113561213
*/
6113661214
rc = sqlite3OsFileSize(pSuper, &nSuperJournal);
6113761215
if( rc!=SQLITE_OK ) goto delsuper_out;
61138
- nSuperPtr = 1 + (i64)pVfs->mxPathname;
61139
- assert( nSuperJournal>=0 && nSuperPtr>0 );
61140
- zFree = sqlite3Malloc(4 + nSuperJournal + 2 + nSuperPtr + 2);
61216
+ assert( nSuperJournal>=0 );
61217
+ zFree = sqlite3Malloc(4 + nSuperJournal + 2);
6114161218
if( !zFree ){
6114261219
rc = SQLITE_NOMEM_BKPT;
6114361220
goto delsuper_out;
6114461221
}else{
6114561222
assert( nSuperJournal<=0x7fffffff );
6114661223
}
6114761224
zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0;
6114861225
zSuperJournal = &zFree[4];
61149
- zSuperPtr = &zSuperJournal[nSuperJournal+2];
6115061226
rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0);
6115161227
if( rc!=SQLITE_OK ) goto delsuper_out;
6115261228
zSuperJournal[nSuperJournal] = 0;
6115361229
zSuperJournal[nSuperJournal+1] = 0;
6115461230
@@ -61158,10 +61234,12 @@
6115861234
rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
6115961235
if( rc!=SQLITE_OK ){
6116061236
goto delsuper_out;
6116161237
}
6116261238
if( exists ){
61239
+ char *zSuperPtr = 0;
61240
+
6116361241
/* One of the journals pointed to by the super-journal exists.
6116461242
** Open it and check if it points at the super-journal. If
6116561243
** so, return without deleting the super-journal file.
6116661244
** NB: zJournal is really a MAIN_JOURNAL. But call it a
6116761245
** SUPER_JOURNAL here so that the VFS will not send the zJournal
@@ -61172,17 +61250,19 @@
6117261250
rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
6117361251
if( rc!=SQLITE_OK ){
6117461252
goto delsuper_out;
6117561253
}
6117661254
61177
- rc = readSuperJournal(pJournal, zSuperPtr, nSuperPtr);
61255
+ rc = readSuperJournal(pJournal, 1+(u64)pVfs->mxPathname, &zSuperPtr);
6117861256
sqlite3OsClose(pJournal);
6117961257
if( rc!=SQLITE_OK ){
61258
+ assert( zSuperPtr==0 );
6118061259
goto delsuper_out;
6118161260
}
6118261261
61183
- c = zSuperPtr[0]!=0 && strcmp(zSuperPtr, zSuper)==0;
61262
+ c = zSuperPtr!=0 && strcmp(zSuperPtr, zSuper)==0;
61263
+ freeSuperJournal(zSuperPtr);
6118461264
if( c ){
6118561265
/* We have a match. Do not delete the super-journal file. */
6118661266
goto delsuper_out;
6118761267
}
6118861268
}
@@ -61393,23 +61473,15 @@
6139361473
6139461474
/* Read the super-journal name from the journal, if it is present.
6139561475
** If a super-journal file name is specified, but the file is not
6139661476
** present on disk, then the journal is not hot and does not need to be
6139761477
** played back.
61398
- **
61399
- ** TODO: Technically the following is an error because it assumes that
61400
- ** buffer Pager.pTmpSpace is (mxPathname+1) bytes or larger. i.e. that
61401
- ** ((pPager->pageSize+8) >= pPager->pVfs->mxPathname+1). Using os_unix.c,
61402
- ** mxPathname is 512, which is the same as the minimum allowable value
61403
- ** for pageSize, and so this assumption holds. But it might not for some
61404
- ** custom VFS. */
61405
- zSuper = pPager->pTmpSpace;
61406
- rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname);
61407
- if( rc==SQLITE_OK && zSuper[0] ){
61478
+ */
61479
+ rc = readSuperJournal(pPager->jfd, 1+(i64)pPager->pVfs->mxPathname, &zSuper);
61480
+ if( rc==SQLITE_OK && zSuper ){
6140861481
rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res);
6140961482
}
61410
- zSuper = 0;
6141161483
if( rc!=SQLITE_OK || !res ){
6141261484
goto end_playback;
6141361485
}
6141461486
pPager->journalOff = 0;
6141561487
needPagerReset = isHot;
@@ -61534,34 +61606,24 @@
6153461606
** problems for other processes at some point in the future. So, just
6153561607
** in case this has happened, clear the changeCountDone flag now.
6153661608
*/
6153761609
pPager->changeCountDone = pPager->tempFile;
6153861610
61539
- if( rc==SQLITE_OK ){
61540
- /* Leave 4 bytes of space before the super-journal filename in memory.
61541
- ** This is because it may end up being passed to sqlite3OsOpen(), in
61542
- ** which case it requires 4 0x00 bytes in memory immediately before
61543
- ** the filename. */
61544
- zSuper = &pPager->pTmpSpace[4];
61545
- rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname);
61546
- testcase( rc!=SQLITE_OK );
61547
- }
6154861611
if( rc==SQLITE_OK
6154961612
&& (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
6155061613
){
6155161614
rc = sqlite3PagerSync(pPager, 0);
6155261615
}
6155361616
if( rc==SQLITE_OK ){
61554
- rc = pager_end_transaction(pPager, zSuper[0]!='\0', 0);
61617
+ rc = pager_end_transaction(pPager, zSuper!=0, 0);
6155561618
testcase( rc!=SQLITE_OK );
6155661619
}
61557
- if( rc==SQLITE_OK && zSuper[0] && res ){
61620
+ if( rc==SQLITE_OK && zSuper && res ){
6155861621
/* If there was a super-journal and this routine will return success,
6155961622
** see if it is possible to delete the super-journal.
6156061623
*/
61561
- assert( zSuper==&pPager->pTmpSpace[4] );
61562
- memset(pPager->pTmpSpace, 0, 4);
61624
+ assert( memcmp(&zSuper[-4], "\0\0\0\0", 4)==0 );
6156361625
rc = pager_delsuper(pPager, zSuper);
6156461626
testcase( rc!=SQLITE_OK );
6156561627
}
6156661628
if( isHot && nPlayback ){
6156761629
sqlite3_log(SQLITE_NOTICE_RECOVER_ROLLBACK, "recovered %d pages from %s",
@@ -61570,10 +61632,11 @@
6157061632
6157161633
/* The Pager.sectorSize variable may have been updated while rolling
6157261634
** back a journal created by a process with a different sector size
6157361635
** value. Reset it to the correct value for this process.
6157461636
*/
61637
+ freeSuperJournal(zSuper);
6157561638
setSectorSize(pPager);
6157661639
return rc;
6157761640
}
6157861641
6157961642
@@ -67428,10 +67491,16 @@
6742867491
*/
6742967492
pgno = sqlite3Get4byte(&aFrame[0]);
6743067493
if( pgno==0 ){
6743167494
return 0;
6743267495
}
67496
+
67497
+ /* Need a valid page size
67498
+ */
67499
+ if( !pWal->szPage ){
67500
+ return 0;
67501
+ }
6743367502
6743467503
/* A frame is only valid if a checksum of the WAL header,
6743567504
** all prior frames, the first 16 bytes of this frame-header,
6743667505
** and the frame-data matches the checksum in the last 8
6743767506
** bytes of this frame-header.
@@ -69283,11 +69352,11 @@
6928369352
goto begin_unreliable_shm_out;
6928469353
}
6928569354
6928669355
/* Allocate a buffer to read frames into */
6928769356
assert( (pWal->szPage & (pWal->szPage-1))==0 );
69288
- assert( pWal->szPage>=512 && pWal->szPage<=65536 );
69357
+ assert( (pWal->szPage>=512 && pWal->szPage<=65536) || pWal->szPage==0 );
6928969358
szFrame = pWal->szPage + WAL_FRAME_HDRSIZE;
6929069359
aFrame = (u8 *)sqlite3_malloc64(szFrame);
6929169360
if( aFrame==0 ){
6929269361
rc = SQLITE_NOMEM_BKPT;
6929369362
goto begin_unreliable_shm_out;
@@ -103044,11 +103113,11 @@
103044103113
if( pFrame ) break;
103045103114
}
103046103115
103047103116
if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
103048103117
rc = SQLITE_ERROR;
103049
- sqlite3VdbeError(p, "too many levels of trigger recursion");
103118
+ sqlite3VdbeError(p, "triggers nested too deep");
103050103119
goto abort_due_to_error;
103051103120
}
103052103121
103053103122
/* Register pRt is used to store the memory required to save the state
103054103123
** of the current program, and the memory required at runtime to execute
@@ -124393,21 +124462,21 @@
124393124462
}else{
124394124463
nIdxCol = pIdx->nColumn;
124395124464
}
124396124465
pIdx->nSampleCol = nIdxCol;
124397124466
pIdx->mxSample = nSample;
124398
- nByte = ROUND8(sizeof(IndexSample) * nSample);
124399
- nByte += sizeof(tRowcnt) * nIdxCol * 3 * nSample;
124400
- nByte += nIdxCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */
124467
+ nByte = ROUND8(sizeof64(IndexSample) * nSample);
124468
+ nByte += sizeof64(tRowcnt) * nIdxCol * 3 * nSample;
124469
+ nByte += nIdxCol * sizeof64(tRowcnt); /* Space for Index.aAvgEq[] */
124401124470
124402124471
pIdx->aSample = sqlite3DbMallocZero(db, nByte);
124403124472
if( pIdx->aSample==0 ){
124404124473
sqlite3_finalize(pStmt);
124405124474
return SQLITE_NOMEM_BKPT;
124406124475
}
124407124476
pPtr = (u8*)pIdx->aSample;
124408
- pPtr += ROUND8(nSample*sizeof(pIdx->aSample[0]));
124477
+ pPtr += ROUND8(nSample*sizeof64(pIdx->aSample[0]));
124409124478
pSpace = (tRowcnt*)pPtr;
124410124479
assert( EIGHT_BYTE_ALIGNMENT( pSpace ) );
124411124480
pIdx->aAvgEq = pSpace; pSpace += nIdxCol;
124412124481
pIdx->pTable->tabFlags |= TF_HasStat4;
124413124482
for(i=0; i<nSample; i++){
@@ -134442,11 +134511,11 @@
134442134511
int nStr; /* Size of zStr */
134443134512
int nPattern; /* Size of zPattern */
134444134513
int nRep; /* Size of zRep */
134445134514
i64 nOut; /* Maximum size of zOut */
134446134515
int loopLimit; /* Last zStr[] that might match zPattern[] */
134447
- int i, j; /* Loop counters */
134516
+ i64 i, j; /* Loop counters */
134448134517
unsigned cntExpand; /* Number zOut expansions */
134449134518
sqlite3 *db = sqlite3_context_db_handle(context);
134450134519
134451134520
assert( argc==3 );
134452134521
UNUSED_PARAMETER(argc);
@@ -135896,12 +135965,21 @@
135896135965
** from the standard library because:
135897135966
**
135898135967
** (1) To avoid a dependency on qsort()
135899135968
** (2) To avoid the function call to the comparison routine for each
135900135969
** comparison.
135970
+**
135971
+** If parameter iReq is non-negative, then the caller will only access
135972
+** elements a[iReq] and a[iReq+1] (if it exists) of the sorted array and
135973
+** so it is not necessary to position any other elements. Or if iReq is
135974
+** negative, then the final array must be fully sorted.
135901135975
*/
135902
-static void percentSort(double *a, unsigned int n){
135976
+static void percentSort(
135977
+ double *a, /* Array to sort */
135978
+ unsigned int n, /* Number of elements in array a[] */
135979
+ int iReq /* Element caller cares about (or -ve) */
135980
+){
135903135981
int iLt; /* Entries before a[iLt] are less than rPivot */
135904135982
int iGt; /* Entries at or after a[iGt] are greater than rPivot */
135905135983
int i; /* Loop counter */
135906135984
double rPivot; /* The pivot value */
135907135985
@@ -135934,21 +136012,45 @@
135934136012
}else{
135935136013
i++;
135936136014
}
135937136015
}while( i<iGt );
135938136016
135939
- /* Recurse on the smaller partition only. The smaller partition
135940
- ** will hold n/2 or fewer entries, which assures that the stack
135941
- ** depth will not exceed O(log(n)), even for pathological cases.
135942
- ** Loop without recursion for the larger partition. */
135943
- if( iLt>n/2 ){
135944
- if( n-iGt>=2 ) percentSort(a+iGt, n-iGt);
135945
- n = iLt;
136017
+ assert( a[iLt]==rPivot );
136018
+ assert( iGt>iLt );
136019
+
136020
+ if( iReq>=0 ){
136021
+ /* In this case, the only elements that the caller requires sorted into
136022
+ ** the correct positions are elements a[iReq] and a[iReq+1]. At this
136023
+ ** point we know that element a[iLt] is in the correct position and
136024
+ ** all elements smaller than a[iLt] are in the left-hand partition.
136025
+ ** So if (iReq<iLt), then it is only necessary to sort the left
136026
+ ** partition.
136027
+ **
136028
+ ** If (iReq>=iLt), then elements iReq and iReq+1 are either in the
136029
+ ** right partition or the equal partition (elements for which
136030
+ ** iLt<=iElem<iGt). Therefore it is always sufficient to sort only
136031
+ ** the right partition in this case. */
136032
+ if( iReq<iLt ){
136033
+ n = iLt;
136034
+ }else{
136035
+ a += iGt;
136036
+ n -= iGt;
136037
+ iReq = MAX(0, iReq-iGt);
136038
+ }
135946136039
}else{
135947
- if( iLt>=2 ) percentSort(a, iLt);
135948
- a += iGt;
135949
- n -= iGt;
136040
+ /* Recurse on the smaller partition only. The smaller partition
136041
+ ** will hold n/2 or fewer entries, which assures that the stack
136042
+ ** depth will not exceed O(log(n)), even for pathological cases.
136043
+ ** Loop without recursion for the larger partition. */
136044
+ if( iLt>(int)(n/2) ){
136045
+ if( n-iGt>=2 ) percentSort(a+iGt, n-iGt, -1);
136046
+ n = iLt;
136047
+ }else{
136048
+ if( iLt>=2 ) percentSort(a, iLt, -1);
136049
+ a += iGt;
136050
+ n -= iGt;
136051
+ }
135950136052
}
135951136053
}while( n>=2 );
135952136054
}
135953136055
135954136056
/*
@@ -135981,11 +136083,11 @@
135981136083
if( percentIsInfinity(y) ){
135982136084
return;
135983136085
}
135984136086
if( p->bSorted==0 ){
135985136087
assert( p->nUsed>1 );
135986
- percentSort(p->a, p->nUsed);
136088
+ percentSort(p->a, p->nUsed, -1);
135987136089
p->bSorted = 1;
135988136090
}
135989136091
p->bKeepSorted = 1;
135990136092
135991136093
/* Find and remove the row */
@@ -136010,17 +136112,21 @@
136010136112
double ix, vx;
136011136113
p = (Percentile*)sqlite3_aggregate_context(pCtx, 0);
136012136114
if( p==0 ) return;
136013136115
if( p->a==0 ) return;
136014136116
if( p->nUsed ){
136117
+ ix = p->rPct*(p->nUsed-1);
136118
+ i1 = (unsigned)ix;
136015136119
if( p->bSorted==0 ){
136120
+ /* In cases where bIsFinal is non-zero, setting Percentile.bSorted
136121
+ ** after the percentSort() call here is not technically correct, as
136122
+ ** the array is not fully sorted. But in this case the object will be
136123
+ ** freed below anyway, so it doesn't matter. */
136016136124
assert( p->nUsed>1 );
136017
- percentSort(p->a, p->nUsed);
136125
+ percentSort(p->a, p->nUsed, (bIsFinal ? (int)i1 : -1));
136018136126
p->bSorted = 1;
136019136127
}
136020
- ix = p->rPct*(p->nUsed-1);
136021
- i1 = (unsigned)ix;
136022136128
if( settings & 1 ){
136023136129
vx = p->a[i1];
136024136130
}else{
136025136131
i2 = ix==(double)i1 || i1==p->nUsed-1 ? i1 : i1+1;
136026136132
v1 = p->a[i1];
@@ -150530,10 +150636,17 @@
150530150636
SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect, char aff){
150531150637
Table *pTab;
150532150638
sqlite3 *db = pParse->db;
150533150639
u64 savedFlags;
150534150640
150641
+ pParse->nNestSel++;
150642
+#if SQLITE_MAX_EXPR_DEPTH>0
150643
+ if( pParse->nNestSel >= db->aLimit[SQLITE_LIMIT_EXPR_DEPTH] ){
150644
+ sqlite3ErrorMsg(pParse, "VIEWs and/or subqueries nested too deep");
150645
+ return 0;
150646
+ }
150647
+#endif
150535150648
savedFlags = db->flags;
150536150649
db->flags &= ~(u64)SQLITE_FullColNames;
150537150650
db->flags |= SQLITE_ShortColNames;
150538150651
sqlite3SelectPrep(pParse, pSelect, 0);
150539150652
db->flags = savedFlags;
@@ -150551,10 +150664,12 @@
150551150664
pTab->iPKey = -1;
150552150665
if( db->mallocFailed ){
150553150666
sqlite3DeleteTable(db, pTab);
150554150667
return 0;
150555150668
}
150669
+ pParse->nNestSel--;
150670
+ assert( pParse->nNestSel>=0 );
150556150671
return pTab;
150557150672
}
150558150673
150559150674
/*
150560150675
** Get a VDBE for the given parser context. Create a new one if necessary.
@@ -158494,22 +158609,36 @@
158494158609
Parse *pParse, /* Current parse context */
158495158610
Trigger *pTrigger, /* Trigger to code */
158496158611
Table *pTab, /* The table pTrigger is attached to */
158497158612
int orconf /* ON CONFLICT policy to code trigger program with */
158498158613
){
158499
- Parse *pTop = sqlite3ParseToplevel(pParse);
158614
+ Parse *pTop; /* Top level Parse object */
158500158615
sqlite3 *db = pParse->db; /* Database handle */
158501158616
TriggerPrg *pPrg; /* Value to return */
158502158617
Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
158503158618
Vdbe *v; /* Temporary VM */
158504158619
NameContext sNC; /* Name context for sub-vdbe */
158505158620
SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
158506158621
int iEndTrigger = 0; /* Label to jump to if WHEN is false */
158507158622
Parse sSubParse; /* Parse context for sub-vdbe */
158623
+ int nDepth; /* Trigger depth */
158508158624
158625
+ /* Ensure that triggers are not chained too deep. This test is linear
158626
+ ** in the chaining depth, but sensible code ought not be chaining
158627
+ ** triggers excessively, so that shouldn't be a problem.
158628
+ */
158629
+ pTop = pParse;
158630
+ for(nDepth=0; pTop->pOuterParse; pTop = pTop->pOuterParse, nDepth++){}
158631
+ if( nDepth>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
158632
+ sqlite3ErrorMsg(pParse, "triggers nested too deep");
158633
+ return 0;
158634
+ }
158635
+
158636
+ pTop = sqlite3ParseToplevel(pParse);
158509158637
assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
158510158638
assert( pTop->pVdbe );
158639
+
158511158640
158512158641
/* Allocate the TriggerPrg and SubProgram objects. To ensure that they
158513158642
** are freed if an error occurs, link them into the Parse.pTriggerPrg
158514158643
** list of the top-level Parse object sooner rather than later. */
158515158644
pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
@@ -160507,11 +160636,12 @@
160507160636
** So we have to make a copy before passing it down into sqlite3Update() */
160508160637
pSrc = sqlite3SrcListDup(db, pTop->pUpsertSrc, 0);
160509160638
/* excluded.* columns of type REAL need to be converted to a hard real */
160510160639
for(i=0; i<pTab->nCol; i++){
160511160640
if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
160512
- sqlite3VdbeAddOp1(v, OP_RealAffinity, pTop->regData+i);
160641
+ int iStorage = pTop->regData + sqlite3TableColumnToStorage(pTab, i);
160642
+ sqlite3VdbeAddOp1(v, OP_RealAffinity, iStorage);
160513160643
}
160514160644
}
160515160645
sqlite3Update(pParse, pSrc, sqlite3ExprListDup(db,pUpsert->pUpsertSet,0),
160516160646
sqlite3ExprDup(db,pUpsert->pUpsertWhere,0), OE_Abort, 0, 0, pUpsert);
160517160647
VdbeNoopComment((v, "End DO UPDATE of UPSERT"));
@@ -195112,12 +195242,17 @@
195112195242
char **pp, /* IN/OUT: Output pointer */
195113195243
sqlite3_int64 *piPrev, /* IN/OUT: Previous value written to list */
195114195244
sqlite3_int64 iVal /* Write this value to the list */
195115195245
){
195116195246
assert_fts3_nc( iVal-*piPrev > 0 || (*piPrev==0 && iVal==0) );
195117
- *pp += sqlite3Fts3PutVarint(*pp, iVal-*piPrev);
195118
- *piPrev = iVal;
195247
+ if( iVal-(*piPrev)>=0 ){
195248
+ /* Refuse to write a negative delta integer. This only happens with a
195249
+ ** corrupt db (see the assert above) and can cause buffer overwrites
195250
+ ** in some cases. */
195251
+ *pp += sqlite3Fts3PutVarint(*pp, iVal-*piPrev);
195252
+ *piPrev = iVal;
195253
+ }
195119195254
}
195120195255
195121195256
/*
195122195257
** When this function is called, *ppPoslist is assumed to point to the
195123195258
** start of a position-list. After it returns, *ppPoslist points to the
@@ -206533,10 +206668,14 @@
206533206668
iMul = -1;
206534206669
}
206535206670
for(/* no-op */; zText[i]>='0' && zText[i]<='9'; i++){
206536206671
iVal = iVal*10 + (zText[i] - '0');
206537206672
}
206673
+
206674
+ /* This if() clause is just to avoid an integer overflow. The record is
206675
+ ** corrupt in this case. */
206676
+ if( (i64)iVal==SMALLEST_INT64 ) iMul = 1;
206538206677
*pnByte = ((i64)iVal * (i64)iMul);
206539206678
}
206540206679
}
206541206680
206542206681
@@ -209395,14 +209534,13 @@
209395209534
*/
209396209535
209397209536
/*
209398209537
** Allocate a two-slot MatchinfoBuffer object.
209399209538
*/
209400
-static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){
209539
+static MatchinfoBuffer *fts3MIBufferNew(i64 nElem, const char *zMatchinfo){
209401209540
MatchinfoBuffer *pRet;
209402
- sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
209403
- + SZ_MATCHINFOBUFFER(1);
209541
+ sqlite3_int64 nByte = sizeof(u32) * (2*(i64)nElem+1) + SZ_MATCHINFOBUFFER(1);
209404209542
sqlite3_int64 nStr = strlen(zMatchinfo);
209405209543
209406209544
pRet = sqlite3Fts3MallocZero(nByte + nStr+1);
209407209545
if( pRet ){
209408209546
pRet->aMI[0] = (u8*)(&pRet->aMI[1]) - (u8*)pRet;
@@ -210269,12 +210407,12 @@
210269210407
}
210270210408
sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
210271210409
return SQLITE_ERROR;
210272210410
}
210273210411
210274
-static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
210275
- size_t nVal; /* Number of integers output by cArg */
210412
+static i64 fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
210413
+ i64 nVal; /* Number of integers output by cArg */
210276210414
210277210415
switch( cArg ){
210278210416
case FTS3_MATCHINFO_NDOC:
210279210417
case FTS3_MATCHINFO_NPHRASE:
210280210418
case FTS3_MATCHINFO_NCOL:
@@ -210286,20 +210424,20 @@
210286210424
case FTS3_MATCHINFO_LCS:
210287210425
nVal = pInfo->nCol;
210288210426
break;
210289210427
210290210428
case FTS3_MATCHINFO_LHITS:
210291
- nVal = (size_t)pInfo->nCol * pInfo->nPhrase;
210429
+ nVal = (i64)pInfo->nCol * pInfo->nPhrase;
210292210430
break;
210293210431
210294210432
case FTS3_MATCHINFO_LHITS_BM:
210295
- nVal = (size_t)pInfo->nPhrase * ((pInfo->nCol + 31) / 32);
210433
+ nVal = (i64)pInfo->nPhrase * ((pInfo->nCol + 31) / 32);
210296210434
break;
210297210435
210298210436
default:
210299210437
assert( cArg==FTS3_MATCHINFO_HITS );
210300
- nVal = (size_t)pInfo->nCol * pInfo->nPhrase * 3;
210438
+ nVal = (i64)pInfo->nCol * pInfo->nPhrase * 3;
210301210439
break;
210302210440
}
210303210441
210304210442
return nVal;
210305210443
}
@@ -210577,11 +210715,11 @@
210577210715
}
210578210716
break;
210579210717
210580210718
case FTS3_MATCHINFO_LHITS_BM:
210581210719
case FTS3_MATCHINFO_LHITS: {
210582
- size_t nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
210720
+ i64 nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
210583210721
memset(pInfo->aMatchinfo, 0, nZero);
210584210722
rc = fts3ExprLHitGather(pCsr->pExpr, pInfo);
210585210723
break;
210586210724
}
210587210725
@@ -210646,11 +210784,11 @@
210646210784
** matchinfo function has been called for this query. In this case
210647210785
** allocate the array used to accumulate the matchinfo data and
210648210786
** initialize those elements that are constant for every row.
210649210787
*/
210650210788
if( pCsr->pMIBuffer==0 ){
210651
- size_t nMatchinfo = 0; /* Number of u32 elements in match-info */
210789
+ i64 nMatchinfo = 0; /* Number of u32 elements in match-info */
210652210790
int i; /* Used to iterate through zArg */
210653210791
210654210792
/* Determine the number of phrases in the query */
210655210793
pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr);
210656210794
sInfo.nPhrase = pCsr->nPhrase;
@@ -218333,10 +218471,13 @@
218333218471
** be because the shadow tables hold erroneous data. */
218334218472
if( rc==SQLITE_ERROR ){
218335218473
rc = SQLITE_CORRUPT_VTAB;
218336218474
RTREE_IS_CORRUPT(pRtree);
218337218475
}
218476
+ }else if( iNode<=0 ){
218477
+ RTREE_IS_CORRUPT(pRtree);
218478
+ rc = SQLITE_CORRUPT_VTAB;
218338218479
}else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){
218339218480
pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode)+pRtree->iNodeSize);
218340218481
if( !pNode ){
218341218482
rc = SQLITE_NOMEM;
218342218483
}else{
@@ -225925,20 +226066,30 @@
225925226066
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
225926226067
-1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
225927226068
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36,
225928226069
-1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
225929226070
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1,
226071
+
226072
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226073
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226074
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226075
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226076
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226077
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226078
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226079
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
225930226080
};
225931226081
unsigned int v = 0;
225932226082
int c;
225933226083
unsigned char *z = (unsigned char*)*pz;
225934
- unsigned char *zStart = z;
225935
- while( (c = zValue[0x7f&*(z++)])>=0 ){
225936
- v = (v<<6) + c;
226084
+ unsigned char *zEnd = z + (*pLen);
226085
+ while( z<zEnd && (c = zValue[*z])>=0 ){
226086
+ v = (v<<6) + c;
226087
+ z++;
225937226088
}
225938
- z--;
225939
- *pLen -= (int)(z - zStart);
226089
+
226090
+ *pLen -= (int)(z - (unsigned char*)*pz);
225940226091
*pz = (char*)z;
225941226092
return v;
225942226093
}
225943226094
225944226095
#if RBU_ENABLE_DELTA_CKSUM
@@ -226010,23 +226161,24 @@
226010226161
#if RBU_ENABLE_DELTA_CKSUM
226011226162
char *zOrigOut = zOut;
226012226163
#endif
226013226164
226014226165
limit = rbuDeltaGetInt(&zDelta, &lenDelta);
226015
- if( *zDelta!='\n' ){
226166
+ if( lenDelta<=0 || *zDelta!='\n' ){
226016226167
/* ERROR: size integer not terminated by "\n" */
226017226168
return -1;
226018226169
}
226019226170
zDelta++; lenDelta--;
226020226171
while( *zDelta && lenDelta>0 ){
226021226172
unsigned int cnt, ofst;
226022226173
cnt = rbuDeltaGetInt(&zDelta, &lenDelta);
226174
+ if( lenDelta<=0 ) return -1;
226023226175
switch( zDelta[0] ){
226024226176
case '@': {
226025226177
zDelta++; lenDelta--;
226026226178
ofst = rbuDeltaGetInt(&zDelta, &lenDelta);
226027
- if( lenDelta>0 && zDelta[0]!=',' ){
226179
+ if( lenDelta>0 || zDelta[0]!=',' ){
226028226180
/* ERROR: copy command not terminated by ',' */
226029226181
return -1;
226030226182
}
226031226183
zDelta++; lenDelta--;
226032226184
total += cnt;
@@ -226047,11 +226199,11 @@
226047226199
total += cnt;
226048226200
if( total>limit ){
226049226201
/* ERROR: insert command gives an output larger than predicted */
226050226202
return -1;
226051226203
}
226052
- if( (int)cnt>lenDelta ){
226204
+ if( (i64)cnt>(i64)lenDelta ){
226053226205
/* ERROR: insert count exceeds size of delta */
226054226206
return -1;
226055226207
}
226056226208
memcpy(zOut, zDelta, cnt);
226057226209
zOut += cnt;
@@ -226085,11 +226237,11 @@
226085226237
}
226086226238
226087226239
static int rbuDeltaOutputSize(const char *zDelta, int lenDelta){
226088226240
int size;
226089226241
size = rbuDeltaGetInt(&zDelta, &lenDelta);
226090
- if( *zDelta!='\n' ){
226242
+ if( lenDelta<=0 || *zDelta!='\n' ){
226091226243
/* ERROR: size integer not terminated by "\n" */
226092226244
return -1;
226093226245
}
226094226246
return size;
226095226247
}
@@ -226133,11 +226285,11 @@
226133226285
if( nOut<0 ){
226134226286
sqlite3_result_error(context, "corrupt fossil delta", -1);
226135226287
return;
226136226288
}
226137226289
226138
- aOut = sqlite3_malloc(nOut+1);
226290
+ aOut = sqlite3_malloc64((i64)nOut+1);
226139226291
if( aOut==0 ){
226140226292
sqlite3_result_error_nomem(context);
226141226293
}else{
226142226294
nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut);
226143226295
if( nOut2!=nOut ){
@@ -247810,14 +247962,14 @@
247810247962
rc = SQLITE_NOMEM;
247811247963
}else{
247812247964
memset(pSyn, 0, (size_t)nByte);
247813247965
pSyn->pTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer);
247814247966
pSyn->nFullTerm = pSyn->nQueryTerm = nToken;
247967
+ memcpy(pSyn->pTerm, pToken, nToken);
247815247968
if( pCtx->pConfig->bTokendata ){
247816247969
pSyn->nQueryTerm = (int)strlen(pSyn->pTerm);
247817247970
}
247818
- memcpy(pSyn->pTerm, pToken, nToken);
247819247971
pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym;
247820247972
pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn;
247821247973
}
247822247974
}else{
247823247975
Fts5ExprTerm *pTerm;
@@ -249662,11 +249814,11 @@
249662249814
** + 1 byte for a "new column" byte,
249663249815
** + 3 bytes for a new column number (16-bit max) as a varint,
249664249816
** + 5 bytes for the new position offset (32-bit max).
249665249817
*/
249666249818
if( (p->nAlloc - p->nData) < (9 + 4 + 1 + 3 + 5) ){
249667
- sqlite3_int64 nNew = p->nAlloc * 2;
249819
+ sqlite3_int64 nNew = (i64)p->nAlloc * 2;
249668249820
Fts5HashEntry *pNew;
249669249821
Fts5HashEntry **pp;
249670249822
pNew = (Fts5HashEntry*)sqlite3_realloc64(p, nNew);
249671249823
if( pNew==0 ) return SQLITE_NOMEM;
249672249824
pNew->nAlloc = (int)nNew;
@@ -251096,11 +251248,11 @@
251096251248
}else{
251097251249
i += fts5GetVarint32(&pData[i], pLvl->nMerge);
251098251250
i += fts5GetVarint32(&pData[i], nTotal);
251099251251
if( nTotal<pLvl->nMerge ) rc = FTS5_CORRUPT;
251100251252
pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(&rc,
251101
- nTotal * sizeof(Fts5StructureSegment)
251253
+ (i64)nTotal * sizeof(Fts5StructureSegment)
251102251254
);
251103251255
nSegment -= nTotal;
251104251256
}
251105251257
251106251258
if( rc==SQLITE_OK ){
@@ -257921,12 +258073,12 @@
257921258073
int *pnOut, /* OUT: Number of output pages */
257922258074
Fts5Data ***papOut /* OUT: Output hash pages */
257923258075
){
257924258076
const int MINSLOT = 32;
257925258077
int nSlotPerPage = MAX(MINSLOT, (p->pConfig->pgsz - 8) / szKey);
257926
- int nSlot = 0; /* Number of slots in each output page */
257927
- int nOut = 0;
258078
+ i64 nSlot = 0; /* Number of slots in each output page */
258079
+ i64 nOut = 0;
257928258080
257929258081
/* Figure out how many output pages (nOut) and how many slots per
257930258082
** page (nSlot). There are three possibilities:
257931258083
**
257932258084
** 1. The hash table does not yet exist. In this case the new hash
@@ -257947,27 +258099,30 @@
257947258099
/* Case 1. */
257948258100
nOut = 1;
257949258101
nSlot = MINSLOT;
257950258102
}else if( pSeg->nPgTombstone==1 ){
257951258103
/* Case 2. */
257952
- int nElem = (int)fts5GetU32(&pData1->p[4]);
258104
+ u32 nElem = fts5GetU32(&pData1->p[4]);
257953258105
assert( pData1 && iPg1==0 );
257954
- nOut = 1;
257955
- nSlot = MAX(nElem*4, MINSLOT);
257956
- if( nSlot>nSlotPerPage ) nOut = 0;
258106
+ if( nElem>((u32)nSlotPerPage/4) ){
258107
+ nOut = 0;
258108
+ }else{
258109
+ nOut = 1;
258110
+ nSlot = MAX((i64)nElem*4, MINSLOT);
258111
+ }
257957258112
}
257958258113
if( nOut==0 ){
257959258114
/* Case 3. */
257960
- nOut = (pSeg->nPgTombstone * 2 + 1);
258115
+ nOut = ((i64)pSeg->nPgTombstone * 2 + 1);
257961258116
nSlot = nSlotPerPage;
257962258117
}
257963258118
257964258119
/* Allocate the required array and output pages */
257965258120
while( 1 ){
257966258121
int res = 0;
257967
- int ii = 0;
257968
- int szPage = 0;
258122
+ i64 ii = 0;
258123
+ i64 szPage = 0;
257969258124
Fts5Data **apOut = 0;
257970258125
257971258126
/* Allocate space for the new hash table */
257972258127
assert( nSlot>=MINSLOT );
257973258128
apOut = (Fts5Data**)sqlite3Fts5MallocZero(&p->rc, sizeof(Fts5Data*) * nOut);
@@ -263112,11 +263267,11 @@
263112263267
int nArg, /* Number of args */
263113263268
sqlite3_value **apUnused /* Function arguments */
263114263269
){
263115263270
assert( nArg==0 );
263116263271
UNUSED_PARAM2(nArg, apUnused);
263117
- sqlite3_result_text(pCtx, "fts5: 2026-06-08 18:15:27 4cb349370daab17123770c814c71872a3e4c616a3f984569b3d7f97f9c3f5ea0", -1, SQLITE_TRANSIENT);
263272
+ sqlite3_result_text(pCtx, "fts5: 2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06", -1, SQLITE_TRANSIENT);
263118263273
}
263119263274
263120263275
/*
263121263276
** Implementation of fts5_locale(LOCALE, TEXT) function.
263122263277
**
263123263278
--- 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 ** 4cb349370daab17123770c814c71872a3e4c 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-06-08 18:15:27 4cb349370daab17123770c814c71872a3e4c616a3f984569b3d7f97f9c3f5ea0"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-06-08T18:15:27.790Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -4696,11 +4696,12 @@
4696 ** <dd>The maximum number of columns in a table definition or in the
4697 ** result set of a [SELECT] or the maximum number of columns in an index
4698 ** or in an ORDER BY or GROUP BY clause.</dd>)^
4699 **
4700 ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
4701 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
 
4702 **
4703 ** [[SQLITE_LIMIT_PARSER_DEPTH]] ^(<dt>SQLITE_LIMIT_PARSER_DEPTH</dt>
4704 ** <dd>The maximum depth of the LALR(1) parser stack used to analyze
4705 ** input SQL statements.</dd>)^
4706 **
@@ -4727,11 +4728,12 @@
4727 ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
4728 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
4729 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
4730 **
4731 ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
4732 ** <dd>The maximum depth of recursion for triggers.</dd>)^
 
4733 **
4734 ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
4735 ** <dd>The maximum number of auxiliary worker threads that a single
4736 ** [prepared statement] may start.</dd>)^
4737 ** </dl>
@@ -11533,12 +11535,23 @@
11533 ** reopen S as an in-memory database based on the serialization
11534 ** contained in P. If S is a NULL pointer, the main database is
11535 ** used. The serialized database P is N bytes in size. M is the size
11536 ** of the buffer P, which might be larger than N. If M is larger than
11537 ** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then
11538 ** SQLite is permitted to add content to the in-memory database as
11539 ** long as the total size does not exceed M bytes.
 
 
 
 
 
 
 
 
 
 
 
11540 **
11541 ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
11542 ** invoke sqlite3_free() on the serialization buffer when the database
11543 ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
11544 ** SQLite will try to increase the buffer size using sqlite3_realloc64()
@@ -15809,10 +15822,17 @@
15809 */
15810 #ifndef offsetof
15811 # define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
15812 #endif
15813
 
 
 
 
 
 
 
15814 /*
15815 ** Work around C99 "flex-array" syntax for pre-C99 compilers, so as
15816 ** to avoid complaints from -fsanitize=strict-bounds.
15817 */
15818 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
@@ -20928,10 +20948,11 @@
20928 int nTab; /* Number of previously allocated VDBE cursors */
20929 int nMem; /* Number of memory cells used so far */
20930 int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */
20931 int iSelfTab; /* Table associated with an index on expr, or negative
20932 ** of the base register during check-constraint eval */
 
20933 int nLabel; /* The *negative* of the number of labels used */
20934 int nLabelAlloc; /* Number of slots in aLabel */
20935 int *aLabel; /* Space to hold the labels */
20936 ExprList *pConstExpr;/* Constant expressions */
20937 IndexedExpr *pIdxEpr;/* List of expressions used by active indexes */
@@ -39255,10 +39276,26 @@
39255 ******************************************************************************
39256 **
39257 ** This file contains an experimental VFS layer that operates on a
39258 ** Key/Value storage engine where both keys and values must be pure
39259 ** text.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39260 */
39261 /* #include <sqliteInt.h> */
39262 #if SQLITE_OS_KV || (SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL))
39263
39264 /*****************************************************************************
@@ -39707,16 +39744,18 @@
39707 }
39708 if( j+n>nOut ) return -1;
39709 memset(&aOut[j], 0, n);
39710 j += n;
39711 if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */
39712 }else{
39713 aOut[j] = c<<4;
39714 c = kvvfsHexValue[aIn[++i]];
39715 if( c<0 ) return -1 /* hex bytes are always in pairs */;
39716 aOut[j++] += c;
39717 i++;
 
 
39718 }
39719 }
39720 return j;
39721 }
39722
@@ -40138,10 +40177,22 @@
40138 }else{
40139 pFile->isJournal = 0;
40140 pFile->base.pMethods = &kvvfs_db_io_methods;
40141 }
40142 if( !pFile->zClass ){
 
 
 
 
 
 
 
 
 
 
 
 
40143 pFile->zClass = zName;
40144 }
40145 pFile->aData = sqlite3_malloc64(SQLITE_KVOS_SZ);
40146 if( pFile->aData==0 ){
40147 return SQLITE_NOMEM;
@@ -52170,15 +52221,33 @@
52170 # define sqlite3_win_test_unc_locking 0
52171 #endif
52172
52173 /*
52174 ** Return true if the string passed as the only argument is likely
52175 ** to be a UNC path. In other words, if it starts with "\\".
 
 
 
 
 
 
 
 
 
52176 */
52177 static int winIsUNCPath(const char *zFile){
52178 if( zFile[0]=='\\' && zFile[1]=='\\' ){
52179 return 1;
 
 
 
 
 
 
 
 
 
52180 }
52181 return sqlite3_win_test_unc_locking;
52182 }
52183
52184 /*
@@ -59841,73 +59910,84 @@
59841 #define pager_set_pagehash(X)
59842 #define CHECK_PAGE(x)
59843 #endif /* SQLITE_CHECK_PAGES */
59844
59845 /*
59846 ** When this is called the journal file for pager pPager must be open.
59847 ** This function attempts to read a super-journal file name from the
59848 ** end of the file and, if successful, copies it into memory supplied
59849 ** by the caller. See comments above writeSuperJournal() for the format
59850 ** used to store a super-journal file name at the end of a journal file.
59851 **
59852 ** zSuper must point to a buffer of at least nSuper bytes allocated by
59853 ** the caller. This should be sqlite3_vfs.mxPathname+1 (to ensure there is
59854 ** enough space to write the super-journal name). If the super-journal
59855 ** name in the journal is longer than nSuper bytes (including a
59856 ** nul-terminator), then this is handled as if no super-journal name
59857 ** were present in the journal.
59858 **
59859 ** If a super-journal file name is present at the end of the journal
59860 ** file, then it is copied into the buffer pointed to by zSuper. A
59861 ** nul-terminator byte is appended to the buffer following the
59862 ** super-journal file name.
59863 **
59864 ** If it is determined that no super-journal file name is present
59865 ** zSuper[0] is set to 0 and SQLITE_OK returned.
59866 **
59867 ** If an error occurs while reading from the journal file, an SQLite
59868 ** error code is returned.
59869 */
59870 static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u64 nSuper){
 
 
 
 
59871 int rc; /* Return code */
59872 u32 len; /* Length in bytes of super-journal name */
59873 i64 szJ; /* Total size in bytes of journal file pJrnl */
59874 u32 cksum; /* MJ checksum value read from journal */
59875 u32 u; /* Unsigned loop counter */
59876 unsigned char aMagic[8]; /* A buffer to hold the magic header */
59877 zSuper[0] = '\0';
59878
 
59879 if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
59880 || szJ<16
59881 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
59882 || len>=nSuper
59883 || len>szJ-16
59884 || len==0
59885 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
59886 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
59887 || memcmp(aMagic, aJournalMagic, 8)
59888 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zSuper, len, szJ-16-len))
59889 ){
59890 return rc;
59891 }
59892
59893 /* See if the checksum matches the super-journal name */
59894 for(u=0; u<len; u++){
59895 cksum -= zSuper[u];
59896 }
59897 if( cksum ){
59898 /* If the checksum doesn't add up, then one or more of the disk sectors
59899 ** containing the super-journal filename is corrupted. This means
59900 ** definitely roll back, so just return SQLITE_OK and report a (nul)
59901 ** super-journal filename.
59902 */
59903 len = 0;
59904 }
59905 zSuper[len] = '\0';
59906 zSuper[len+1] = '\0';
59907
59908 return SQLITE_OK;
 
 
 
 
 
 
 
 
59909 }
59910
59911 /*
59912 ** Return the offset of the sector boundary at or immediately
59913 ** following the value in pPager->journalOff, assuming a sector
@@ -61108,13 +61188,11 @@
61108 sqlite3_file *pSuper; /* Malloc'd super-journal file descriptor */
61109 sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
61110 char *zSuperJournal = 0; /* Contents of super-journal file */
61111 i64 nSuperJournal; /* Size of super-journal file */
61112 char *zJournal; /* Pointer to one journal within MJ file */
61113 char *zSuperPtr; /* Space to hold super-journal filename */
61114 char *zFree = 0; /* Free this buffer */
61115 i64 nSuperPtr; /* Amount of space allocated to zSuperPtr[] */
61116
61117 /* Allocate space for both the pJournal and pSuper file descriptors.
61118 ** If successful, open the super-journal file for reading.
61119 */
61120 pSuper = (sqlite3_file *)sqlite3MallocZero(2 * (i64)pVfs->szOsFile);
@@ -61133,22 +61211,20 @@
61133 ** sufficient space (in zSuperPtr) to hold the names of super-journal
61134 ** files extracted from regular rollback-journals.
61135 */
61136 rc = sqlite3OsFileSize(pSuper, &nSuperJournal);
61137 if( rc!=SQLITE_OK ) goto delsuper_out;
61138 nSuperPtr = 1 + (i64)pVfs->mxPathname;
61139 assert( nSuperJournal>=0 && nSuperPtr>0 );
61140 zFree = sqlite3Malloc(4 + nSuperJournal + 2 + nSuperPtr + 2);
61141 if( !zFree ){
61142 rc = SQLITE_NOMEM_BKPT;
61143 goto delsuper_out;
61144 }else{
61145 assert( nSuperJournal<=0x7fffffff );
61146 }
61147 zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0;
61148 zSuperJournal = &zFree[4];
61149 zSuperPtr = &zSuperJournal[nSuperJournal+2];
61150 rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0);
61151 if( rc!=SQLITE_OK ) goto delsuper_out;
61152 zSuperJournal[nSuperJournal] = 0;
61153 zSuperJournal[nSuperJournal+1] = 0;
61154
@@ -61158,10 +61234,12 @@
61158 rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
61159 if( rc!=SQLITE_OK ){
61160 goto delsuper_out;
61161 }
61162 if( exists ){
 
 
61163 /* One of the journals pointed to by the super-journal exists.
61164 ** Open it and check if it points at the super-journal. If
61165 ** so, return without deleting the super-journal file.
61166 ** NB: zJournal is really a MAIN_JOURNAL. But call it a
61167 ** SUPER_JOURNAL here so that the VFS will not send the zJournal
@@ -61172,17 +61250,19 @@
61172 rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
61173 if( rc!=SQLITE_OK ){
61174 goto delsuper_out;
61175 }
61176
61177 rc = readSuperJournal(pJournal, zSuperPtr, nSuperPtr);
61178 sqlite3OsClose(pJournal);
61179 if( rc!=SQLITE_OK ){
 
61180 goto delsuper_out;
61181 }
61182
61183 c = zSuperPtr[0]!=0 && strcmp(zSuperPtr, zSuper)==0;
 
61184 if( c ){
61185 /* We have a match. Do not delete the super-journal file. */
61186 goto delsuper_out;
61187 }
61188 }
@@ -61393,23 +61473,15 @@
61393
61394 /* Read the super-journal name from the journal, if it is present.
61395 ** If a super-journal file name is specified, but the file is not
61396 ** present on disk, then the journal is not hot and does not need to be
61397 ** played back.
61398 **
61399 ** TODO: Technically the following is an error because it assumes that
61400 ** buffer Pager.pTmpSpace is (mxPathname+1) bytes or larger. i.e. that
61401 ** ((pPager->pageSize+8) >= pPager->pVfs->mxPathname+1). Using os_unix.c,
61402 ** mxPathname is 512, which is the same as the minimum allowable value
61403 ** for pageSize, and so this assumption holds. But it might not for some
61404 ** custom VFS. */
61405 zSuper = pPager->pTmpSpace;
61406 rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname);
61407 if( rc==SQLITE_OK && zSuper[0] ){
61408 rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res);
61409 }
61410 zSuper = 0;
61411 if( rc!=SQLITE_OK || !res ){
61412 goto end_playback;
61413 }
61414 pPager->journalOff = 0;
61415 needPagerReset = isHot;
@@ -61534,34 +61606,24 @@
61534 ** problems for other processes at some point in the future. So, just
61535 ** in case this has happened, clear the changeCountDone flag now.
61536 */
61537 pPager->changeCountDone = pPager->tempFile;
61538
61539 if( rc==SQLITE_OK ){
61540 /* Leave 4 bytes of space before the super-journal filename in memory.
61541 ** This is because it may end up being passed to sqlite3OsOpen(), in
61542 ** which case it requires 4 0x00 bytes in memory immediately before
61543 ** the filename. */
61544 zSuper = &pPager->pTmpSpace[4];
61545 rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname);
61546 testcase( rc!=SQLITE_OK );
61547 }
61548 if( rc==SQLITE_OK
61549 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
61550 ){
61551 rc = sqlite3PagerSync(pPager, 0);
61552 }
61553 if( rc==SQLITE_OK ){
61554 rc = pager_end_transaction(pPager, zSuper[0]!='\0', 0);
61555 testcase( rc!=SQLITE_OK );
61556 }
61557 if( rc==SQLITE_OK && zSuper[0] && res ){
61558 /* If there was a super-journal and this routine will return success,
61559 ** see if it is possible to delete the super-journal.
61560 */
61561 assert( zSuper==&pPager->pTmpSpace[4] );
61562 memset(pPager->pTmpSpace, 0, 4);
61563 rc = pager_delsuper(pPager, zSuper);
61564 testcase( rc!=SQLITE_OK );
61565 }
61566 if( isHot && nPlayback ){
61567 sqlite3_log(SQLITE_NOTICE_RECOVER_ROLLBACK, "recovered %d pages from %s",
@@ -61570,10 +61632,11 @@
61570
61571 /* The Pager.sectorSize variable may have been updated while rolling
61572 ** back a journal created by a process with a different sector size
61573 ** value. Reset it to the correct value for this process.
61574 */
 
61575 setSectorSize(pPager);
61576 return rc;
61577 }
61578
61579
@@ -67428,10 +67491,16 @@
67428 */
67429 pgno = sqlite3Get4byte(&aFrame[0]);
67430 if( pgno==0 ){
67431 return 0;
67432 }
 
 
 
 
 
 
67433
67434 /* A frame is only valid if a checksum of the WAL header,
67435 ** all prior frames, the first 16 bytes of this frame-header,
67436 ** and the frame-data matches the checksum in the last 8
67437 ** bytes of this frame-header.
@@ -69283,11 +69352,11 @@
69283 goto begin_unreliable_shm_out;
69284 }
69285
69286 /* Allocate a buffer to read frames into */
69287 assert( (pWal->szPage & (pWal->szPage-1))==0 );
69288 assert( pWal->szPage>=512 && pWal->szPage<=65536 );
69289 szFrame = pWal->szPage + WAL_FRAME_HDRSIZE;
69290 aFrame = (u8 *)sqlite3_malloc64(szFrame);
69291 if( aFrame==0 ){
69292 rc = SQLITE_NOMEM_BKPT;
69293 goto begin_unreliable_shm_out;
@@ -103044,11 +103113,11 @@
103044 if( pFrame ) break;
103045 }
103046
103047 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
103048 rc = SQLITE_ERROR;
103049 sqlite3VdbeError(p, "too many levels of trigger recursion");
103050 goto abort_due_to_error;
103051 }
103052
103053 /* Register pRt is used to store the memory required to save the state
103054 ** of the current program, and the memory required at runtime to execute
@@ -124393,21 +124462,21 @@
124393 }else{
124394 nIdxCol = pIdx->nColumn;
124395 }
124396 pIdx->nSampleCol = nIdxCol;
124397 pIdx->mxSample = nSample;
124398 nByte = ROUND8(sizeof(IndexSample) * nSample);
124399 nByte += sizeof(tRowcnt) * nIdxCol * 3 * nSample;
124400 nByte += nIdxCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */
124401
124402 pIdx->aSample = sqlite3DbMallocZero(db, nByte);
124403 if( pIdx->aSample==0 ){
124404 sqlite3_finalize(pStmt);
124405 return SQLITE_NOMEM_BKPT;
124406 }
124407 pPtr = (u8*)pIdx->aSample;
124408 pPtr += ROUND8(nSample*sizeof(pIdx->aSample[0]));
124409 pSpace = (tRowcnt*)pPtr;
124410 assert( EIGHT_BYTE_ALIGNMENT( pSpace ) );
124411 pIdx->aAvgEq = pSpace; pSpace += nIdxCol;
124412 pIdx->pTable->tabFlags |= TF_HasStat4;
124413 for(i=0; i<nSample; i++){
@@ -134442,11 +134511,11 @@
134442 int nStr; /* Size of zStr */
134443 int nPattern; /* Size of zPattern */
134444 int nRep; /* Size of zRep */
134445 i64 nOut; /* Maximum size of zOut */
134446 int loopLimit; /* Last zStr[] that might match zPattern[] */
134447 int i, j; /* Loop counters */
134448 unsigned cntExpand; /* Number zOut expansions */
134449 sqlite3 *db = sqlite3_context_db_handle(context);
134450
134451 assert( argc==3 );
134452 UNUSED_PARAMETER(argc);
@@ -135896,12 +135965,21 @@
135896 ** from the standard library because:
135897 **
135898 ** (1) To avoid a dependency on qsort()
135899 ** (2) To avoid the function call to the comparison routine for each
135900 ** comparison.
 
 
 
 
 
135901 */
135902 static void percentSort(double *a, unsigned int n){
 
 
 
 
135903 int iLt; /* Entries before a[iLt] are less than rPivot */
135904 int iGt; /* Entries at or after a[iGt] are greater than rPivot */
135905 int i; /* Loop counter */
135906 double rPivot; /* The pivot value */
135907
@@ -135934,21 +136012,45 @@
135934 }else{
135935 i++;
135936 }
135937 }while( i<iGt );
135938
135939 /* Recurse on the smaller partition only. The smaller partition
135940 ** will hold n/2 or fewer entries, which assures that the stack
135941 ** depth will not exceed O(log(n)), even for pathological cases.
135942 ** Loop without recursion for the larger partition. */
135943 if( iLt>n/2 ){
135944 if( n-iGt>=2 ) percentSort(a+iGt, n-iGt);
135945 n = iLt;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135946 }else{
135947 if( iLt>=2 ) percentSort(a, iLt);
135948 a += iGt;
135949 n -= iGt;
 
 
 
 
 
 
 
 
 
135950 }
135951 }while( n>=2 );
135952 }
135953
135954 /*
@@ -135981,11 +136083,11 @@
135981 if( percentIsInfinity(y) ){
135982 return;
135983 }
135984 if( p->bSorted==0 ){
135985 assert( p->nUsed>1 );
135986 percentSort(p->a, p->nUsed);
135987 p->bSorted = 1;
135988 }
135989 p->bKeepSorted = 1;
135990
135991 /* Find and remove the row */
@@ -136010,17 +136112,21 @@
136010 double ix, vx;
136011 p = (Percentile*)sqlite3_aggregate_context(pCtx, 0);
136012 if( p==0 ) return;
136013 if( p->a==0 ) return;
136014 if( p->nUsed ){
 
 
136015 if( p->bSorted==0 ){
 
 
 
 
136016 assert( p->nUsed>1 );
136017 percentSort(p->a, p->nUsed);
136018 p->bSorted = 1;
136019 }
136020 ix = p->rPct*(p->nUsed-1);
136021 i1 = (unsigned)ix;
136022 if( settings & 1 ){
136023 vx = p->a[i1];
136024 }else{
136025 i2 = ix==(double)i1 || i1==p->nUsed-1 ? i1 : i1+1;
136026 v1 = p->a[i1];
@@ -150530,10 +150636,17 @@
150530 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect, char aff){
150531 Table *pTab;
150532 sqlite3 *db = pParse->db;
150533 u64 savedFlags;
150534
 
 
 
 
 
 
 
150535 savedFlags = db->flags;
150536 db->flags &= ~(u64)SQLITE_FullColNames;
150537 db->flags |= SQLITE_ShortColNames;
150538 sqlite3SelectPrep(pParse, pSelect, 0);
150539 db->flags = savedFlags;
@@ -150551,10 +150664,12 @@
150551 pTab->iPKey = -1;
150552 if( db->mallocFailed ){
150553 sqlite3DeleteTable(db, pTab);
150554 return 0;
150555 }
 
 
150556 return pTab;
150557 }
150558
150559 /*
150560 ** Get a VDBE for the given parser context. Create a new one if necessary.
@@ -158494,22 +158609,36 @@
158494 Parse *pParse, /* Current parse context */
158495 Trigger *pTrigger, /* Trigger to code */
158496 Table *pTab, /* The table pTrigger is attached to */
158497 int orconf /* ON CONFLICT policy to code trigger program with */
158498 ){
158499 Parse *pTop = sqlite3ParseToplevel(pParse);
158500 sqlite3 *db = pParse->db; /* Database handle */
158501 TriggerPrg *pPrg; /* Value to return */
158502 Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
158503 Vdbe *v; /* Temporary VM */
158504 NameContext sNC; /* Name context for sub-vdbe */
158505 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
158506 int iEndTrigger = 0; /* Label to jump to if WHEN is false */
158507 Parse sSubParse; /* Parse context for sub-vdbe */
 
158508
 
 
 
 
 
 
 
 
 
 
 
 
158509 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
158510 assert( pTop->pVdbe );
 
158511
158512 /* Allocate the TriggerPrg and SubProgram objects. To ensure that they
158513 ** are freed if an error occurs, link them into the Parse.pTriggerPrg
158514 ** list of the top-level Parse object sooner rather than later. */
158515 pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
@@ -160507,11 +160636,12 @@
160507 ** So we have to make a copy before passing it down into sqlite3Update() */
160508 pSrc = sqlite3SrcListDup(db, pTop->pUpsertSrc, 0);
160509 /* excluded.* columns of type REAL need to be converted to a hard real */
160510 for(i=0; i<pTab->nCol; i++){
160511 if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
160512 sqlite3VdbeAddOp1(v, OP_RealAffinity, pTop->regData+i);
 
160513 }
160514 }
160515 sqlite3Update(pParse, pSrc, sqlite3ExprListDup(db,pUpsert->pUpsertSet,0),
160516 sqlite3ExprDup(db,pUpsert->pUpsertWhere,0), OE_Abort, 0, 0, pUpsert);
160517 VdbeNoopComment((v, "End DO UPDATE of UPSERT"));
@@ -195112,12 +195242,17 @@
195112 char **pp, /* IN/OUT: Output pointer */
195113 sqlite3_int64 *piPrev, /* IN/OUT: Previous value written to list */
195114 sqlite3_int64 iVal /* Write this value to the list */
195115 ){
195116 assert_fts3_nc( iVal-*piPrev > 0 || (*piPrev==0 && iVal==0) );
195117 *pp += sqlite3Fts3PutVarint(*pp, iVal-*piPrev);
195118 *piPrev = iVal;
 
 
 
 
 
195119 }
195120
195121 /*
195122 ** When this function is called, *ppPoslist is assumed to point to the
195123 ** start of a position-list. After it returns, *ppPoslist points to the
@@ -206533,10 +206668,14 @@
206533 iMul = -1;
206534 }
206535 for(/* no-op */; zText[i]>='0' && zText[i]<='9'; i++){
206536 iVal = iVal*10 + (zText[i] - '0');
206537 }
 
 
 
 
206538 *pnByte = ((i64)iVal * (i64)iMul);
206539 }
206540 }
206541
206542
@@ -209395,14 +209534,13 @@
209395 */
209396
209397 /*
209398 ** Allocate a two-slot MatchinfoBuffer object.
209399 */
209400 static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){
209401 MatchinfoBuffer *pRet;
209402 sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
209403 + SZ_MATCHINFOBUFFER(1);
209404 sqlite3_int64 nStr = strlen(zMatchinfo);
209405
209406 pRet = sqlite3Fts3MallocZero(nByte + nStr+1);
209407 if( pRet ){
209408 pRet->aMI[0] = (u8*)(&pRet->aMI[1]) - (u8*)pRet;
@@ -210269,12 +210407,12 @@
210269 }
210270 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
210271 return SQLITE_ERROR;
210272 }
210273
210274 static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
210275 size_t nVal; /* Number of integers output by cArg */
210276
210277 switch( cArg ){
210278 case FTS3_MATCHINFO_NDOC:
210279 case FTS3_MATCHINFO_NPHRASE:
210280 case FTS3_MATCHINFO_NCOL:
@@ -210286,20 +210424,20 @@
210286 case FTS3_MATCHINFO_LCS:
210287 nVal = pInfo->nCol;
210288 break;
210289
210290 case FTS3_MATCHINFO_LHITS:
210291 nVal = (size_t)pInfo->nCol * pInfo->nPhrase;
210292 break;
210293
210294 case FTS3_MATCHINFO_LHITS_BM:
210295 nVal = (size_t)pInfo->nPhrase * ((pInfo->nCol + 31) / 32);
210296 break;
210297
210298 default:
210299 assert( cArg==FTS3_MATCHINFO_HITS );
210300 nVal = (size_t)pInfo->nCol * pInfo->nPhrase * 3;
210301 break;
210302 }
210303
210304 return nVal;
210305 }
@@ -210577,11 +210715,11 @@
210577 }
210578 break;
210579
210580 case FTS3_MATCHINFO_LHITS_BM:
210581 case FTS3_MATCHINFO_LHITS: {
210582 size_t nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
210583 memset(pInfo->aMatchinfo, 0, nZero);
210584 rc = fts3ExprLHitGather(pCsr->pExpr, pInfo);
210585 break;
210586 }
210587
@@ -210646,11 +210784,11 @@
210646 ** matchinfo function has been called for this query. In this case
210647 ** allocate the array used to accumulate the matchinfo data and
210648 ** initialize those elements that are constant for every row.
210649 */
210650 if( pCsr->pMIBuffer==0 ){
210651 size_t nMatchinfo = 0; /* Number of u32 elements in match-info */
210652 int i; /* Used to iterate through zArg */
210653
210654 /* Determine the number of phrases in the query */
210655 pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr);
210656 sInfo.nPhrase = pCsr->nPhrase;
@@ -218333,10 +218471,13 @@
218333 ** be because the shadow tables hold erroneous data. */
218334 if( rc==SQLITE_ERROR ){
218335 rc = SQLITE_CORRUPT_VTAB;
218336 RTREE_IS_CORRUPT(pRtree);
218337 }
 
 
 
218338 }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){
218339 pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode)+pRtree->iNodeSize);
218340 if( !pNode ){
218341 rc = SQLITE_NOMEM;
218342 }else{
@@ -225925,20 +226066,30 @@
225925 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
225926 -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
225927 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36,
225928 -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
225929 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1,
 
 
 
 
 
 
 
 
 
225930 };
225931 unsigned int v = 0;
225932 int c;
225933 unsigned char *z = (unsigned char*)*pz;
225934 unsigned char *zStart = z;
225935 while( (c = zValue[0x7f&*(z++)])>=0 ){
225936 v = (v<<6) + c;
 
225937 }
225938 z--;
225939 *pLen -= (int)(z - zStart);
225940 *pz = (char*)z;
225941 return v;
225942 }
225943
225944 #if RBU_ENABLE_DELTA_CKSUM
@@ -226010,23 +226161,24 @@
226010 #if RBU_ENABLE_DELTA_CKSUM
226011 char *zOrigOut = zOut;
226012 #endif
226013
226014 limit = rbuDeltaGetInt(&zDelta, &lenDelta);
226015 if( *zDelta!='\n' ){
226016 /* ERROR: size integer not terminated by "\n" */
226017 return -1;
226018 }
226019 zDelta++; lenDelta--;
226020 while( *zDelta && lenDelta>0 ){
226021 unsigned int cnt, ofst;
226022 cnt = rbuDeltaGetInt(&zDelta, &lenDelta);
 
226023 switch( zDelta[0] ){
226024 case '@': {
226025 zDelta++; lenDelta--;
226026 ofst = rbuDeltaGetInt(&zDelta, &lenDelta);
226027 if( lenDelta>0 && zDelta[0]!=',' ){
226028 /* ERROR: copy command not terminated by ',' */
226029 return -1;
226030 }
226031 zDelta++; lenDelta--;
226032 total += cnt;
@@ -226047,11 +226199,11 @@
226047 total += cnt;
226048 if( total>limit ){
226049 /* ERROR: insert command gives an output larger than predicted */
226050 return -1;
226051 }
226052 if( (int)cnt>lenDelta ){
226053 /* ERROR: insert count exceeds size of delta */
226054 return -1;
226055 }
226056 memcpy(zOut, zDelta, cnt);
226057 zOut += cnt;
@@ -226085,11 +226237,11 @@
226085 }
226086
226087 static int rbuDeltaOutputSize(const char *zDelta, int lenDelta){
226088 int size;
226089 size = rbuDeltaGetInt(&zDelta, &lenDelta);
226090 if( *zDelta!='\n' ){
226091 /* ERROR: size integer not terminated by "\n" */
226092 return -1;
226093 }
226094 return size;
226095 }
@@ -226133,11 +226285,11 @@
226133 if( nOut<0 ){
226134 sqlite3_result_error(context, "corrupt fossil delta", -1);
226135 return;
226136 }
226137
226138 aOut = sqlite3_malloc(nOut+1);
226139 if( aOut==0 ){
226140 sqlite3_result_error_nomem(context);
226141 }else{
226142 nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut);
226143 if( nOut2!=nOut ){
@@ -247810,14 +247962,14 @@
247810 rc = SQLITE_NOMEM;
247811 }else{
247812 memset(pSyn, 0, (size_t)nByte);
247813 pSyn->pTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer);
247814 pSyn->nFullTerm = pSyn->nQueryTerm = nToken;
 
247815 if( pCtx->pConfig->bTokendata ){
247816 pSyn->nQueryTerm = (int)strlen(pSyn->pTerm);
247817 }
247818 memcpy(pSyn->pTerm, pToken, nToken);
247819 pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym;
247820 pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn;
247821 }
247822 }else{
247823 Fts5ExprTerm *pTerm;
@@ -249662,11 +249814,11 @@
249662 ** + 1 byte for a "new column" byte,
249663 ** + 3 bytes for a new column number (16-bit max) as a varint,
249664 ** + 5 bytes for the new position offset (32-bit max).
249665 */
249666 if( (p->nAlloc - p->nData) < (9 + 4 + 1 + 3 + 5) ){
249667 sqlite3_int64 nNew = p->nAlloc * 2;
249668 Fts5HashEntry *pNew;
249669 Fts5HashEntry **pp;
249670 pNew = (Fts5HashEntry*)sqlite3_realloc64(p, nNew);
249671 if( pNew==0 ) return SQLITE_NOMEM;
249672 pNew->nAlloc = (int)nNew;
@@ -251096,11 +251248,11 @@
251096 }else{
251097 i += fts5GetVarint32(&pData[i], pLvl->nMerge);
251098 i += fts5GetVarint32(&pData[i], nTotal);
251099 if( nTotal<pLvl->nMerge ) rc = FTS5_CORRUPT;
251100 pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(&rc,
251101 nTotal * sizeof(Fts5StructureSegment)
251102 );
251103 nSegment -= nTotal;
251104 }
251105
251106 if( rc==SQLITE_OK ){
@@ -257921,12 +258073,12 @@
257921 int *pnOut, /* OUT: Number of output pages */
257922 Fts5Data ***papOut /* OUT: Output hash pages */
257923 ){
257924 const int MINSLOT = 32;
257925 int nSlotPerPage = MAX(MINSLOT, (p->pConfig->pgsz - 8) / szKey);
257926 int nSlot = 0; /* Number of slots in each output page */
257927 int nOut = 0;
257928
257929 /* Figure out how many output pages (nOut) and how many slots per
257930 ** page (nSlot). There are three possibilities:
257931 **
257932 ** 1. The hash table does not yet exist. In this case the new hash
@@ -257947,27 +258099,30 @@
257947 /* Case 1. */
257948 nOut = 1;
257949 nSlot = MINSLOT;
257950 }else if( pSeg->nPgTombstone==1 ){
257951 /* Case 2. */
257952 int nElem = (int)fts5GetU32(&pData1->p[4]);
257953 assert( pData1 && iPg1==0 );
257954 nOut = 1;
257955 nSlot = MAX(nElem*4, MINSLOT);
257956 if( nSlot>nSlotPerPage ) nOut = 0;
 
 
 
257957 }
257958 if( nOut==0 ){
257959 /* Case 3. */
257960 nOut = (pSeg->nPgTombstone * 2 + 1);
257961 nSlot = nSlotPerPage;
257962 }
257963
257964 /* Allocate the required array and output pages */
257965 while( 1 ){
257966 int res = 0;
257967 int ii = 0;
257968 int szPage = 0;
257969 Fts5Data **apOut = 0;
257970
257971 /* Allocate space for the new hash table */
257972 assert( nSlot>=MINSLOT );
257973 apOut = (Fts5Data**)sqlite3Fts5MallocZero(&p->rc, sizeof(Fts5Data*) * nOut);
@@ -263112,11 +263267,11 @@
263112 int nArg, /* Number of args */
263113 sqlite3_value **apUnused /* Function arguments */
263114 ){
263115 assert( nArg==0 );
263116 UNUSED_PARAM2(nArg, apUnused);
263117 sqlite3_result_text(pCtx, "fts5: 2026-06-08 18:15:27 4cb349370daab17123770c814c71872a3e4c616a3f984569b3d7f97f9c3f5ea0", -1, SQLITE_TRANSIENT);
263118 }
263119
263120 /*
263121 ** Implementation of fts5_locale(LOCALE, TEXT) function.
263122 **
263123
--- 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 ** 3f3fb9b638f59ad982beafb7c117f24ddd3d 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-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-06-16T13:43:08.110Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -4696,11 +4696,12 @@
4696 ** <dd>The maximum number of columns in a table definition or in the
4697 ** result set of a [SELECT] or the maximum number of columns in an index
4698 ** or in an ORDER BY or GROUP BY clause.</dd>)^
4699 **
4700 ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
4701 ** <dd>The maximum depth of the parse tree on any expression and
4702 ** the maximum nesting depth for subqueries and VIEWs</dd>)^
4703 **
4704 ** [[SQLITE_LIMIT_PARSER_DEPTH]] ^(<dt>SQLITE_LIMIT_PARSER_DEPTH</dt>
4705 ** <dd>The maximum depth of the LALR(1) parser stack used to analyze
4706 ** input SQL statements.</dd>)^
4707 **
@@ -4727,11 +4728,12 @@
4728 ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
4729 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
4730 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
4731 **
4732 ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
4733 ** <dd>The maximum depth of recursion for triggers, and the maximum
4734 ** nesting depth for separate triggers.</dd>)^
4735 **
4736 ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
4737 ** <dd>The maximum number of auxiliary worker threads that a single
4738 ** [prepared statement] may start.</dd>)^
4739 ** </dl>
@@ -11533,12 +11535,23 @@
11535 ** reopen S as an in-memory database based on the serialization
11536 ** contained in P. If S is a NULL pointer, the main database is
11537 ** used. The serialized database P is N bytes in size. M is the size
11538 ** of the buffer P, which might be larger than N. If M is larger than
11539 ** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then
11540 ** SQLite is permitted to add content to the in-memory database, in
11541 ** page-sized chunks, as long as the total size does not exceed M bytes.
11542 **
11543 ** The parameter M must be greater than or equal to N. Ideally, M
11544 ** should have a value which is N+(512&times;K)+20 where K determines how
11545 ** must extra space is available to hold new content as the database
11546 ** grows. K can be 0 if the database is read-only.
11547 **
11548 ** If the database content in P is malformed in a malicious way then
11549 ** it is possible that SQLite might try to read a few more than N bytes
11550 ** from P. If the veracity of the database content P is uncertain,
11551 ** then applications are advised to allocate about 20 extra bytes on
11552 ** the end of the P buffer to avoid a memory error.
11553 **
11554 ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
11555 ** invoke sqlite3_free() on the serialization buffer when the database
11556 ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
11557 ** SQLite will try to increase the buffer size using sqlite3_realloc64()
@@ -15809,10 +15822,17 @@
15822 */
15823 #ifndef offsetof
15824 # define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
15825 #endif
15826
15827 /*
15828 ** sizeof64() is like sizeof(), but always returns a 64-bit value, even
15829 ** on 32-bit builds. This can help to avoid overflow by ensuring 64-bit
15830 ** arithmetic is used consistently in both 32-bit and 64-bit builds.
15831 */
15832 #define sizeof64(X) ((sqlite3_int64)sizeof(X))
15833
15834 /*
15835 ** Work around C99 "flex-array" syntax for pre-C99 compilers, so as
15836 ** to avoid complaints from -fsanitize=strict-bounds.
15837 */
15838 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
@@ -20928,10 +20948,11 @@
20948 int nTab; /* Number of previously allocated VDBE cursors */
20949 int nMem; /* Number of memory cells used so far */
20950 int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */
20951 int iSelfTab; /* Table associated with an index on expr, or negative
20952 ** of the base register during check-constraint eval */
20953 int nNestSel; /* Number of nested SELECT statements and/or VIEWs */
20954 int nLabel; /* The *negative* of the number of labels used */
20955 int nLabelAlloc; /* Number of slots in aLabel */
20956 int *aLabel; /* Space to hold the labels */
20957 ExprList *pConstExpr;/* Constant expressions */
20958 IndexedExpr *pIdxEpr;/* List of expressions used by active indexes */
@@ -39255,10 +39276,26 @@
39276 ******************************************************************************
39277 **
39278 ** This file contains an experimental VFS layer that operates on a
39279 ** Key/Value storage engine where both keys and values must be pure
39280 ** text.
39281 **
39282 ** DEBUG AND TEST
39283 **
39284 ** For testing on Unix, compile using:
39285 **
39286 ** make clean sqlite3d CFLAGS='-DSQLITE_OS_KV_OPTIONAL'
39287 **
39288 ** Then start up a shell using something like:
39289 **
39290 ** ./sqlite3d 'file:dbname?vfs=kvvfs'
39291 **
39292 ** Each K/V entry is stored in a separate file in the working
39293 ** directory that has a name like "kvvfs-dbname-*". Due to limitations
39294 ** on the key size, the name of the database must be very short - just
39295 ** a few characters. If the database name is too long, the VFS will
39296 ** malfunction and you will get SQLITE_CORRUPT errors.
39297 */
39298 /* #include <sqliteInt.h> */
39299 #if SQLITE_OS_KV || (SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL))
39300
39301 /*****************************************************************************
@@ -39707,16 +39744,18 @@
39744 }
39745 if( j+n>nOut ) return -1;
39746 memset(&aOut[j], 0, n);
39747 j += n;
39748 if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */
39749 }else if( j<nOut ){
39750 aOut[j] = c<<4;
39751 c = kvvfsHexValue[aIn[++i]];
39752 if( c<0 ) return -1 /* hex bytes are always in pairs */;
39753 aOut[j++] += c;
39754 i++;
39755 }else{
39756 return -1;
39757 }
39758 }
39759 return j;
39760 }
39761
@@ -40138,10 +40177,22 @@
40177 }else{
40178 pFile->isJournal = 0;
40179 pFile->base.pMethods = &kvvfs_db_io_methods;
40180 }
40181 if( !pFile->zClass ){
40182 #ifdef SQLITE_WASM
40183 if( strlen(zName) >= (KVRECORD_KEY_SZ
40184 - 6 /* "kvvfs-" */
40185 - 11 /* "-##########" */) ){
40186 return SQLITE_CANTOPEN;
40187 }
40188 #else
40189 if( 0!=strcmp(zName, "local") && 0!=strcmp(zName, "session") ){
40190 /* Historical naming restriction which journaling depends on. */
40191 return SQLITE_CANTOPEN;
40192 }
40193 #endif
40194 pFile->zClass = zName;
40195 }
40196 pFile->aData = sqlite3_malloc64(SQLITE_KVOS_SZ);
40197 if( pFile->aData==0 ){
40198 return SQLITE_NOMEM;
@@ -52170,15 +52221,33 @@
52221 # define sqlite3_win_test_unc_locking 0
52222 #endif
52223
52224 /*
52225 ** Return true if the string passed as the only argument is likely
52226 ** to be a UNC path. Return false if note.
52227 **
52228 ** Return true if:
52229 **
52230 ** (1) The name begins with "\\"
52231 ** (2) But does not begin with "\\?\C:\" where C can be any alphabetic
52232 ** character.
52233 **
52234 ** For testing, also return true in all cases if the global variable
52235 ** sqlite3_win_test_unc_locking is true.
52236 */
52237 static int winIsUNCPath(const char *zFile){
52238 if( zFile[0]=='\\' && zFile[1]=='\\' ){
52239 if( zFile[2]=='?'
52240 && zFile[3]=='\\'
52241 && sqlite3Isalpha(zFile[4])
52242 && zFile[5]==':'
52243 && winIsDirSep(zFile[6])
52244 ){
52245 return sqlite3_win_test_unc_locking;
52246 }else{
52247 return 1;
52248 }
52249 }
52250 return sqlite3_win_test_unc_locking;
52251 }
52252
52253 /*
@@ -59841,73 +59910,84 @@
59910 #define pager_set_pagehash(X)
59911 #define CHECK_PAGE(x)
59912 #endif /* SQLITE_CHECK_PAGES */
59913
59914 /*
59915 ** Free a buffer allocated by the readSuperJournal() function.
59916 */
59917 static void freeSuperJournal(char *zSuper){
59918 if( zSuper ){
59919 sqlite3_free(&zSuper[-4]);
59920 }
59921 }
59922
59923 /*
59924 ** Parameter pJrnl is a file-handle open on a journal file. This function
59925 ** attempts to read a super-journal file name from the end of the journal
59926 ** file. If successful, it sets output parameter (*pzSuper) to point to a
59927 ** buffer containing the super-journal name as a nul-terminated string.
59928 ** The caller is responsible for freeing the buffer using freeSuperJournal().
59929 **
59930 ** Refer to comments above writeSuperJournal() for the format used to store
59931 ** a super-journal file name at the end of a journal file.
59932 **
59933 ** Parameter nSuper is passed the maximum allowable size of the super journal
59934 ** name in bytes. If the super-journal name in the journal is longer than
59935 ** nSuper bytes (including a nul-terminator), then this is handled as if no
59936 ** super-journal name were present in the journal.
59937 **
59938 ** If there is no super-journal name at the end of pJrnl, (*pzSuper) is
59939 ** set to 0 and SQLITE_OK is returned. Or, if an error occurs while reading
59940 ** the super-journal name, an SQLite error code is returned and (*pzSuper)
59941 ** is set to 0.
59942 */
59943 static int readSuperJournal(sqlite3_file *pJrnl, u64 nSuper, char **pzSuper){
59944 int rc; /* Return code */
59945 u32 len; /* Length in bytes of super-journal name */
59946 i64 szJ; /* Total size in bytes of journal file pJrnl */
59947 u32 cksum; /* MJ checksum value read from journal */
 
59948 unsigned char aMagic[8]; /* A buffer to hold the magic header */
59949 char *zOut = 0;
59950
59951 *pzSuper = 0;
59952 if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
59953 || szJ<16
59954 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
59955 || len>=nSuper
59956 || len>szJ-16
59957 || len==0
59958 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
59959 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
59960 || memcmp(aMagic, aJournalMagic, 8)
 
59961 ){
59962 return rc;
59963 }
59964
59965 zOut = (char*)sqlite3MallocZero(4 + len + 2);
59966 if( !zOut ){
59967 rc = SQLITE_NOMEM_BKPT;
59968 }else{
59969 zOut = &zOut[4];
59970 if( SQLITE_OK==(rc = sqlite3OsRead(pJrnl, zOut, len, szJ-16-len)) ){
59971 u32 u; /* Unsigned loop counter */
59972 /* See if the checksum matches the super-journal name */
59973 for(u=0; u<len; u++){
59974 cksum -= zOut[u];
59975 }
59976 }
59977 if( rc!=SQLITE_OK || cksum ){
59978 /* If the checksum doesn't add up, then one or more of the disk sectors
59979 ** containing the super-journal filename is corrupted. This means
59980 ** definitely roll back, so just return SQLITE_OK and report a (nul)
59981 ** super-journal filename. */
59982 freeSuperJournal(zOut);
59983 zOut = 0;
59984 }
59985 }
59986
59987 *pzSuper = zOut;
59988 return rc;
59989 }
59990
59991 /*
59992 ** Return the offset of the sector boundary at or immediately
59993 ** following the value in pPager->journalOff, assuming a sector
@@ -61108,13 +61188,11 @@
61188 sqlite3_file *pSuper; /* Malloc'd super-journal file descriptor */
61189 sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
61190 char *zSuperJournal = 0; /* Contents of super-journal file */
61191 i64 nSuperJournal; /* Size of super-journal file */
61192 char *zJournal; /* Pointer to one journal within MJ file */
 
61193 char *zFree = 0; /* Free this buffer */
 
61194
61195 /* Allocate space for both the pJournal and pSuper file descriptors.
61196 ** If successful, open the super-journal file for reading.
61197 */
61198 pSuper = (sqlite3_file *)sqlite3MallocZero(2 * (i64)pVfs->szOsFile);
@@ -61133,22 +61211,20 @@
61211 ** sufficient space (in zSuperPtr) to hold the names of super-journal
61212 ** files extracted from regular rollback-journals.
61213 */
61214 rc = sqlite3OsFileSize(pSuper, &nSuperJournal);
61215 if( rc!=SQLITE_OK ) goto delsuper_out;
61216 assert( nSuperJournal>=0 );
61217 zFree = sqlite3Malloc(4 + nSuperJournal + 2);
 
61218 if( !zFree ){
61219 rc = SQLITE_NOMEM_BKPT;
61220 goto delsuper_out;
61221 }else{
61222 assert( nSuperJournal<=0x7fffffff );
61223 }
61224 zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0;
61225 zSuperJournal = &zFree[4];
 
61226 rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0);
61227 if( rc!=SQLITE_OK ) goto delsuper_out;
61228 zSuperJournal[nSuperJournal] = 0;
61229 zSuperJournal[nSuperJournal+1] = 0;
61230
@@ -61158,10 +61234,12 @@
61234 rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
61235 if( rc!=SQLITE_OK ){
61236 goto delsuper_out;
61237 }
61238 if( exists ){
61239 char *zSuperPtr = 0;
61240
61241 /* One of the journals pointed to by the super-journal exists.
61242 ** Open it and check if it points at the super-journal. If
61243 ** so, return without deleting the super-journal file.
61244 ** NB: zJournal is really a MAIN_JOURNAL. But call it a
61245 ** SUPER_JOURNAL here so that the VFS will not send the zJournal
@@ -61172,17 +61250,19 @@
61250 rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
61251 if( rc!=SQLITE_OK ){
61252 goto delsuper_out;
61253 }
61254
61255 rc = readSuperJournal(pJournal, 1+(u64)pVfs->mxPathname, &zSuperPtr);
61256 sqlite3OsClose(pJournal);
61257 if( rc!=SQLITE_OK ){
61258 assert( zSuperPtr==0 );
61259 goto delsuper_out;
61260 }
61261
61262 c = zSuperPtr!=0 && strcmp(zSuperPtr, zSuper)==0;
61263 freeSuperJournal(zSuperPtr);
61264 if( c ){
61265 /* We have a match. Do not delete the super-journal file. */
61266 goto delsuper_out;
61267 }
61268 }
@@ -61393,23 +61473,15 @@
61473
61474 /* Read the super-journal name from the journal, if it is present.
61475 ** If a super-journal file name is specified, but the file is not
61476 ** present on disk, then the journal is not hot and does not need to be
61477 ** played back.
61478 */
61479 rc = readSuperJournal(pPager->jfd, 1+(i64)pPager->pVfs->mxPathname, &zSuper);
61480 if( rc==SQLITE_OK && zSuper ){
 
 
 
 
 
 
 
61481 rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res);
61482 }
 
61483 if( rc!=SQLITE_OK || !res ){
61484 goto end_playback;
61485 }
61486 pPager->journalOff = 0;
61487 needPagerReset = isHot;
@@ -61534,34 +61606,24 @@
61606 ** problems for other processes at some point in the future. So, just
61607 ** in case this has happened, clear the changeCountDone flag now.
61608 */
61609 pPager->changeCountDone = pPager->tempFile;
61610
 
 
 
 
 
 
 
 
 
61611 if( rc==SQLITE_OK
61612 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
61613 ){
61614 rc = sqlite3PagerSync(pPager, 0);
61615 }
61616 if( rc==SQLITE_OK ){
61617 rc = pager_end_transaction(pPager, zSuper!=0, 0);
61618 testcase( rc!=SQLITE_OK );
61619 }
61620 if( rc==SQLITE_OK && zSuper && res ){
61621 /* If there was a super-journal and this routine will return success,
61622 ** see if it is possible to delete the super-journal.
61623 */
61624 assert( memcmp(&zSuper[-4], "\0\0\0\0", 4)==0 );
 
61625 rc = pager_delsuper(pPager, zSuper);
61626 testcase( rc!=SQLITE_OK );
61627 }
61628 if( isHot && nPlayback ){
61629 sqlite3_log(SQLITE_NOTICE_RECOVER_ROLLBACK, "recovered %d pages from %s",
@@ -61570,10 +61632,11 @@
61632
61633 /* The Pager.sectorSize variable may have been updated while rolling
61634 ** back a journal created by a process with a different sector size
61635 ** value. Reset it to the correct value for this process.
61636 */
61637 freeSuperJournal(zSuper);
61638 setSectorSize(pPager);
61639 return rc;
61640 }
61641
61642
@@ -67428,10 +67491,16 @@
67491 */
67492 pgno = sqlite3Get4byte(&aFrame[0]);
67493 if( pgno==0 ){
67494 return 0;
67495 }
67496
67497 /* Need a valid page size
67498 */
67499 if( !pWal->szPage ){
67500 return 0;
67501 }
67502
67503 /* A frame is only valid if a checksum of the WAL header,
67504 ** all prior frames, the first 16 bytes of this frame-header,
67505 ** and the frame-data matches the checksum in the last 8
67506 ** bytes of this frame-header.
@@ -69283,11 +69352,11 @@
69352 goto begin_unreliable_shm_out;
69353 }
69354
69355 /* Allocate a buffer to read frames into */
69356 assert( (pWal->szPage & (pWal->szPage-1))==0 );
69357 assert( (pWal->szPage>=512 && pWal->szPage<=65536) || pWal->szPage==0 );
69358 szFrame = pWal->szPage + WAL_FRAME_HDRSIZE;
69359 aFrame = (u8 *)sqlite3_malloc64(szFrame);
69360 if( aFrame==0 ){
69361 rc = SQLITE_NOMEM_BKPT;
69362 goto begin_unreliable_shm_out;
@@ -103044,11 +103113,11 @@
103113 if( pFrame ) break;
103114 }
103115
103116 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
103117 rc = SQLITE_ERROR;
103118 sqlite3VdbeError(p, "triggers nested too deep");
103119 goto abort_due_to_error;
103120 }
103121
103122 /* Register pRt is used to store the memory required to save the state
103123 ** of the current program, and the memory required at runtime to execute
@@ -124393,21 +124462,21 @@
124462 }else{
124463 nIdxCol = pIdx->nColumn;
124464 }
124465 pIdx->nSampleCol = nIdxCol;
124466 pIdx->mxSample = nSample;
124467 nByte = ROUND8(sizeof64(IndexSample) * nSample);
124468 nByte += sizeof64(tRowcnt) * nIdxCol * 3 * nSample;
124469 nByte += nIdxCol * sizeof64(tRowcnt); /* Space for Index.aAvgEq[] */
124470
124471 pIdx->aSample = sqlite3DbMallocZero(db, nByte);
124472 if( pIdx->aSample==0 ){
124473 sqlite3_finalize(pStmt);
124474 return SQLITE_NOMEM_BKPT;
124475 }
124476 pPtr = (u8*)pIdx->aSample;
124477 pPtr += ROUND8(nSample*sizeof64(pIdx->aSample[0]));
124478 pSpace = (tRowcnt*)pPtr;
124479 assert( EIGHT_BYTE_ALIGNMENT( pSpace ) );
124480 pIdx->aAvgEq = pSpace; pSpace += nIdxCol;
124481 pIdx->pTable->tabFlags |= TF_HasStat4;
124482 for(i=0; i<nSample; i++){
@@ -134442,11 +134511,11 @@
134511 int nStr; /* Size of zStr */
134512 int nPattern; /* Size of zPattern */
134513 int nRep; /* Size of zRep */
134514 i64 nOut; /* Maximum size of zOut */
134515 int loopLimit; /* Last zStr[] that might match zPattern[] */
134516 i64 i, j; /* Loop counters */
134517 unsigned cntExpand; /* Number zOut expansions */
134518 sqlite3 *db = sqlite3_context_db_handle(context);
134519
134520 assert( argc==3 );
134521 UNUSED_PARAMETER(argc);
@@ -135896,12 +135965,21 @@
135965 ** from the standard library because:
135966 **
135967 ** (1) To avoid a dependency on qsort()
135968 ** (2) To avoid the function call to the comparison routine for each
135969 ** comparison.
135970 **
135971 ** If parameter iReq is non-negative, then the caller will only access
135972 ** elements a[iReq] and a[iReq+1] (if it exists) of the sorted array and
135973 ** so it is not necessary to position any other elements. Or if iReq is
135974 ** negative, then the final array must be fully sorted.
135975 */
135976 static void percentSort(
135977 double *a, /* Array to sort */
135978 unsigned int n, /* Number of elements in array a[] */
135979 int iReq /* Element caller cares about (or -ve) */
135980 ){
135981 int iLt; /* Entries before a[iLt] are less than rPivot */
135982 int iGt; /* Entries at or after a[iGt] are greater than rPivot */
135983 int i; /* Loop counter */
135984 double rPivot; /* The pivot value */
135985
@@ -135934,21 +136012,45 @@
136012 }else{
136013 i++;
136014 }
136015 }while( i<iGt );
136016
136017 assert( a[iLt]==rPivot );
136018 assert( iGt>iLt );
136019
136020 if( iReq>=0 ){
136021 /* In this case, the only elements that the caller requires sorted into
136022 ** the correct positions are elements a[iReq] and a[iReq+1]. At this
136023 ** point we know that element a[iLt] is in the correct position and
136024 ** all elements smaller than a[iLt] are in the left-hand partition.
136025 ** So if (iReq<iLt), then it is only necessary to sort the left
136026 ** partition.
136027 **
136028 ** If (iReq>=iLt), then elements iReq and iReq+1 are either in the
136029 ** right partition or the equal partition (elements for which
136030 ** iLt<=iElem<iGt). Therefore it is always sufficient to sort only
136031 ** the right partition in this case. */
136032 if( iReq<iLt ){
136033 n = iLt;
136034 }else{
136035 a += iGt;
136036 n -= iGt;
136037 iReq = MAX(0, iReq-iGt);
136038 }
136039 }else{
136040 /* Recurse on the smaller partition only. The smaller partition
136041 ** will hold n/2 or fewer entries, which assures that the stack
136042 ** depth will not exceed O(log(n)), even for pathological cases.
136043 ** Loop without recursion for the larger partition. */
136044 if( iLt>(int)(n/2) ){
136045 if( n-iGt>=2 ) percentSort(a+iGt, n-iGt, -1);
136046 n = iLt;
136047 }else{
136048 if( iLt>=2 ) percentSort(a, iLt, -1);
136049 a += iGt;
136050 n -= iGt;
136051 }
136052 }
136053 }while( n>=2 );
136054 }
136055
136056 /*
@@ -135981,11 +136083,11 @@
136083 if( percentIsInfinity(y) ){
136084 return;
136085 }
136086 if( p->bSorted==0 ){
136087 assert( p->nUsed>1 );
136088 percentSort(p->a, p->nUsed, -1);
136089 p->bSorted = 1;
136090 }
136091 p->bKeepSorted = 1;
136092
136093 /* Find and remove the row */
@@ -136010,17 +136112,21 @@
136112 double ix, vx;
136113 p = (Percentile*)sqlite3_aggregate_context(pCtx, 0);
136114 if( p==0 ) return;
136115 if( p->a==0 ) return;
136116 if( p->nUsed ){
136117 ix = p->rPct*(p->nUsed-1);
136118 i1 = (unsigned)ix;
136119 if( p->bSorted==0 ){
136120 /* In cases where bIsFinal is non-zero, setting Percentile.bSorted
136121 ** after the percentSort() call here is not technically correct, as
136122 ** the array is not fully sorted. But in this case the object will be
136123 ** freed below anyway, so it doesn't matter. */
136124 assert( p->nUsed>1 );
136125 percentSort(p->a, p->nUsed, (bIsFinal ? (int)i1 : -1));
136126 p->bSorted = 1;
136127 }
 
 
136128 if( settings & 1 ){
136129 vx = p->a[i1];
136130 }else{
136131 i2 = ix==(double)i1 || i1==p->nUsed-1 ? i1 : i1+1;
136132 v1 = p->a[i1];
@@ -150530,10 +150636,17 @@
150636 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect, char aff){
150637 Table *pTab;
150638 sqlite3 *db = pParse->db;
150639 u64 savedFlags;
150640
150641 pParse->nNestSel++;
150642 #if SQLITE_MAX_EXPR_DEPTH>0
150643 if( pParse->nNestSel >= db->aLimit[SQLITE_LIMIT_EXPR_DEPTH] ){
150644 sqlite3ErrorMsg(pParse, "VIEWs and/or subqueries nested too deep");
150645 return 0;
150646 }
150647 #endif
150648 savedFlags = db->flags;
150649 db->flags &= ~(u64)SQLITE_FullColNames;
150650 db->flags |= SQLITE_ShortColNames;
150651 sqlite3SelectPrep(pParse, pSelect, 0);
150652 db->flags = savedFlags;
@@ -150551,10 +150664,12 @@
150664 pTab->iPKey = -1;
150665 if( db->mallocFailed ){
150666 sqlite3DeleteTable(db, pTab);
150667 return 0;
150668 }
150669 pParse->nNestSel--;
150670 assert( pParse->nNestSel>=0 );
150671 return pTab;
150672 }
150673
150674 /*
150675 ** Get a VDBE for the given parser context. Create a new one if necessary.
@@ -158494,22 +158609,36 @@
158609 Parse *pParse, /* Current parse context */
158610 Trigger *pTrigger, /* Trigger to code */
158611 Table *pTab, /* The table pTrigger is attached to */
158612 int orconf /* ON CONFLICT policy to code trigger program with */
158613 ){
158614 Parse *pTop; /* Top level Parse object */
158615 sqlite3 *db = pParse->db; /* Database handle */
158616 TriggerPrg *pPrg; /* Value to return */
158617 Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
158618 Vdbe *v; /* Temporary VM */
158619 NameContext sNC; /* Name context for sub-vdbe */
158620 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
158621 int iEndTrigger = 0; /* Label to jump to if WHEN is false */
158622 Parse sSubParse; /* Parse context for sub-vdbe */
158623 int nDepth; /* Trigger depth */
158624
158625 /* Ensure that triggers are not chained too deep. This test is linear
158626 ** in the chaining depth, but sensible code ought not be chaining
158627 ** triggers excessively, so that shouldn't be a problem.
158628 */
158629 pTop = pParse;
158630 for(nDepth=0; pTop->pOuterParse; pTop = pTop->pOuterParse, nDepth++){}
158631 if( nDepth>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
158632 sqlite3ErrorMsg(pParse, "triggers nested too deep");
158633 return 0;
158634 }
158635
158636 pTop = sqlite3ParseToplevel(pParse);
158637 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
158638 assert( pTop->pVdbe );
158639
158640
158641 /* Allocate the TriggerPrg and SubProgram objects. To ensure that they
158642 ** are freed if an error occurs, link them into the Parse.pTriggerPrg
158643 ** list of the top-level Parse object sooner rather than later. */
158644 pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
@@ -160507,11 +160636,12 @@
160636 ** So we have to make a copy before passing it down into sqlite3Update() */
160637 pSrc = sqlite3SrcListDup(db, pTop->pUpsertSrc, 0);
160638 /* excluded.* columns of type REAL need to be converted to a hard real */
160639 for(i=0; i<pTab->nCol; i++){
160640 if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
160641 int iStorage = pTop->regData + sqlite3TableColumnToStorage(pTab, i);
160642 sqlite3VdbeAddOp1(v, OP_RealAffinity, iStorage);
160643 }
160644 }
160645 sqlite3Update(pParse, pSrc, sqlite3ExprListDup(db,pUpsert->pUpsertSet,0),
160646 sqlite3ExprDup(db,pUpsert->pUpsertWhere,0), OE_Abort, 0, 0, pUpsert);
160647 VdbeNoopComment((v, "End DO UPDATE of UPSERT"));
@@ -195112,12 +195242,17 @@
195242 char **pp, /* IN/OUT: Output pointer */
195243 sqlite3_int64 *piPrev, /* IN/OUT: Previous value written to list */
195244 sqlite3_int64 iVal /* Write this value to the list */
195245 ){
195246 assert_fts3_nc( iVal-*piPrev > 0 || (*piPrev==0 && iVal==0) );
195247 if( iVal-(*piPrev)>=0 ){
195248 /* Refuse to write a negative delta integer. This only happens with a
195249 ** corrupt db (see the assert above) and can cause buffer overwrites
195250 ** in some cases. */
195251 *pp += sqlite3Fts3PutVarint(*pp, iVal-*piPrev);
195252 *piPrev = iVal;
195253 }
195254 }
195255
195256 /*
195257 ** When this function is called, *ppPoslist is assumed to point to the
195258 ** start of a position-list. After it returns, *ppPoslist points to the
@@ -206533,10 +206668,14 @@
206668 iMul = -1;
206669 }
206670 for(/* no-op */; zText[i]>='0' && zText[i]<='9'; i++){
206671 iVal = iVal*10 + (zText[i] - '0');
206672 }
206673
206674 /* This if() clause is just to avoid an integer overflow. The record is
206675 ** corrupt in this case. */
206676 if( (i64)iVal==SMALLEST_INT64 ) iMul = 1;
206677 *pnByte = ((i64)iVal * (i64)iMul);
206678 }
206679 }
206680
206681
@@ -209395,14 +209534,13 @@
209534 */
209535
209536 /*
209537 ** Allocate a two-slot MatchinfoBuffer object.
209538 */
209539 static MatchinfoBuffer *fts3MIBufferNew(i64 nElem, const char *zMatchinfo){
209540 MatchinfoBuffer *pRet;
209541 sqlite3_int64 nByte = sizeof(u32) * (2*(i64)nElem+1) + SZ_MATCHINFOBUFFER(1);
 
209542 sqlite3_int64 nStr = strlen(zMatchinfo);
209543
209544 pRet = sqlite3Fts3MallocZero(nByte + nStr+1);
209545 if( pRet ){
209546 pRet->aMI[0] = (u8*)(&pRet->aMI[1]) - (u8*)pRet;
@@ -210269,12 +210407,12 @@
210407 }
210408 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
210409 return SQLITE_ERROR;
210410 }
210411
210412 static i64 fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
210413 i64 nVal; /* Number of integers output by cArg */
210414
210415 switch( cArg ){
210416 case FTS3_MATCHINFO_NDOC:
210417 case FTS3_MATCHINFO_NPHRASE:
210418 case FTS3_MATCHINFO_NCOL:
@@ -210286,20 +210424,20 @@
210424 case FTS3_MATCHINFO_LCS:
210425 nVal = pInfo->nCol;
210426 break;
210427
210428 case FTS3_MATCHINFO_LHITS:
210429 nVal = (i64)pInfo->nCol * pInfo->nPhrase;
210430 break;
210431
210432 case FTS3_MATCHINFO_LHITS_BM:
210433 nVal = (i64)pInfo->nPhrase * ((pInfo->nCol + 31) / 32);
210434 break;
210435
210436 default:
210437 assert( cArg==FTS3_MATCHINFO_HITS );
210438 nVal = (i64)pInfo->nCol * pInfo->nPhrase * 3;
210439 break;
210440 }
210441
210442 return nVal;
210443 }
@@ -210577,11 +210715,11 @@
210715 }
210716 break;
210717
210718 case FTS3_MATCHINFO_LHITS_BM:
210719 case FTS3_MATCHINFO_LHITS: {
210720 i64 nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
210721 memset(pInfo->aMatchinfo, 0, nZero);
210722 rc = fts3ExprLHitGather(pCsr->pExpr, pInfo);
210723 break;
210724 }
210725
@@ -210646,11 +210784,11 @@
210784 ** matchinfo function has been called for this query. In this case
210785 ** allocate the array used to accumulate the matchinfo data and
210786 ** initialize those elements that are constant for every row.
210787 */
210788 if( pCsr->pMIBuffer==0 ){
210789 i64 nMatchinfo = 0; /* Number of u32 elements in match-info */
210790 int i; /* Used to iterate through zArg */
210791
210792 /* Determine the number of phrases in the query */
210793 pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr);
210794 sInfo.nPhrase = pCsr->nPhrase;
@@ -218333,10 +218471,13 @@
218471 ** be because the shadow tables hold erroneous data. */
218472 if( rc==SQLITE_ERROR ){
218473 rc = SQLITE_CORRUPT_VTAB;
218474 RTREE_IS_CORRUPT(pRtree);
218475 }
218476 }else if( iNode<=0 ){
218477 RTREE_IS_CORRUPT(pRtree);
218478 rc = SQLITE_CORRUPT_VTAB;
218479 }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){
218480 pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode)+pRtree->iNodeSize);
218481 if( !pNode ){
218482 rc = SQLITE_NOMEM;
218483 }else{
@@ -225925,20 +226066,30 @@
226066 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
226067 -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
226068 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36,
226069 -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
226070 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1,
226071
226072 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226073 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226074 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226075 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226076 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226077 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226078 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226079 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226080 };
226081 unsigned int v = 0;
226082 int c;
226083 unsigned char *z = (unsigned char*)*pz;
226084 unsigned char *zEnd = z + (*pLen);
226085 while( z<zEnd && (c = zValue[*z])>=0 ){
226086 v = (v<<6) + c;
226087 z++;
226088 }
226089
226090 *pLen -= (int)(z - (unsigned char*)*pz);
226091 *pz = (char*)z;
226092 return v;
226093 }
226094
226095 #if RBU_ENABLE_DELTA_CKSUM
@@ -226010,23 +226161,24 @@
226161 #if RBU_ENABLE_DELTA_CKSUM
226162 char *zOrigOut = zOut;
226163 #endif
226164
226165 limit = rbuDeltaGetInt(&zDelta, &lenDelta);
226166 if( lenDelta<=0 || *zDelta!='\n' ){
226167 /* ERROR: size integer not terminated by "\n" */
226168 return -1;
226169 }
226170 zDelta++; lenDelta--;
226171 while( *zDelta && lenDelta>0 ){
226172 unsigned int cnt, ofst;
226173 cnt = rbuDeltaGetInt(&zDelta, &lenDelta);
226174 if( lenDelta<=0 ) return -1;
226175 switch( zDelta[0] ){
226176 case '@': {
226177 zDelta++; lenDelta--;
226178 ofst = rbuDeltaGetInt(&zDelta, &lenDelta);
226179 if( lenDelta>0 || zDelta[0]!=',' ){
226180 /* ERROR: copy command not terminated by ',' */
226181 return -1;
226182 }
226183 zDelta++; lenDelta--;
226184 total += cnt;
@@ -226047,11 +226199,11 @@
226199 total += cnt;
226200 if( total>limit ){
226201 /* ERROR: insert command gives an output larger than predicted */
226202 return -1;
226203 }
226204 if( (i64)cnt>(i64)lenDelta ){
226205 /* ERROR: insert count exceeds size of delta */
226206 return -1;
226207 }
226208 memcpy(zOut, zDelta, cnt);
226209 zOut += cnt;
@@ -226085,11 +226237,11 @@
226237 }
226238
226239 static int rbuDeltaOutputSize(const char *zDelta, int lenDelta){
226240 int size;
226241 size = rbuDeltaGetInt(&zDelta, &lenDelta);
226242 if( lenDelta<=0 || *zDelta!='\n' ){
226243 /* ERROR: size integer not terminated by "\n" */
226244 return -1;
226245 }
226246 return size;
226247 }
@@ -226133,11 +226285,11 @@
226285 if( nOut<0 ){
226286 sqlite3_result_error(context, "corrupt fossil delta", -1);
226287 return;
226288 }
226289
226290 aOut = sqlite3_malloc64((i64)nOut+1);
226291 if( aOut==0 ){
226292 sqlite3_result_error_nomem(context);
226293 }else{
226294 nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut);
226295 if( nOut2!=nOut ){
@@ -247810,14 +247962,14 @@
247962 rc = SQLITE_NOMEM;
247963 }else{
247964 memset(pSyn, 0, (size_t)nByte);
247965 pSyn->pTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer);
247966 pSyn->nFullTerm = pSyn->nQueryTerm = nToken;
247967 memcpy(pSyn->pTerm, pToken, nToken);
247968 if( pCtx->pConfig->bTokendata ){
247969 pSyn->nQueryTerm = (int)strlen(pSyn->pTerm);
247970 }
 
247971 pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym;
247972 pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn;
247973 }
247974 }else{
247975 Fts5ExprTerm *pTerm;
@@ -249662,11 +249814,11 @@
249814 ** + 1 byte for a "new column" byte,
249815 ** + 3 bytes for a new column number (16-bit max) as a varint,
249816 ** + 5 bytes for the new position offset (32-bit max).
249817 */
249818 if( (p->nAlloc - p->nData) < (9 + 4 + 1 + 3 + 5) ){
249819 sqlite3_int64 nNew = (i64)p->nAlloc * 2;
249820 Fts5HashEntry *pNew;
249821 Fts5HashEntry **pp;
249822 pNew = (Fts5HashEntry*)sqlite3_realloc64(p, nNew);
249823 if( pNew==0 ) return SQLITE_NOMEM;
249824 pNew->nAlloc = (int)nNew;
@@ -251096,11 +251248,11 @@
251248 }else{
251249 i += fts5GetVarint32(&pData[i], pLvl->nMerge);
251250 i += fts5GetVarint32(&pData[i], nTotal);
251251 if( nTotal<pLvl->nMerge ) rc = FTS5_CORRUPT;
251252 pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(&rc,
251253 (i64)nTotal * sizeof(Fts5StructureSegment)
251254 );
251255 nSegment -= nTotal;
251256 }
251257
251258 if( rc==SQLITE_OK ){
@@ -257921,12 +258073,12 @@
258073 int *pnOut, /* OUT: Number of output pages */
258074 Fts5Data ***papOut /* OUT: Output hash pages */
258075 ){
258076 const int MINSLOT = 32;
258077 int nSlotPerPage = MAX(MINSLOT, (p->pConfig->pgsz - 8) / szKey);
258078 i64 nSlot = 0; /* Number of slots in each output page */
258079 i64 nOut = 0;
258080
258081 /* Figure out how many output pages (nOut) and how many slots per
258082 ** page (nSlot). There are three possibilities:
258083 **
258084 ** 1. The hash table does not yet exist. In this case the new hash
@@ -257947,27 +258099,30 @@
258099 /* Case 1. */
258100 nOut = 1;
258101 nSlot = MINSLOT;
258102 }else if( pSeg->nPgTombstone==1 ){
258103 /* Case 2. */
258104 u32 nElem = fts5GetU32(&pData1->p[4]);
258105 assert( pData1 && iPg1==0 );
258106 if( nElem>((u32)nSlotPerPage/4) ){
258107 nOut = 0;
258108 }else{
258109 nOut = 1;
258110 nSlot = MAX((i64)nElem*4, MINSLOT);
258111 }
258112 }
258113 if( nOut==0 ){
258114 /* Case 3. */
258115 nOut = ((i64)pSeg->nPgTombstone * 2 + 1);
258116 nSlot = nSlotPerPage;
258117 }
258118
258119 /* Allocate the required array and output pages */
258120 while( 1 ){
258121 int res = 0;
258122 i64 ii = 0;
258123 i64 szPage = 0;
258124 Fts5Data **apOut = 0;
258125
258126 /* Allocate space for the new hash table */
258127 assert( nSlot>=MINSLOT );
258128 apOut = (Fts5Data**)sqlite3Fts5MallocZero(&p->rc, sizeof(Fts5Data*) * nOut);
@@ -263112,11 +263267,11 @@
263267 int nArg, /* Number of args */
263268 sqlite3_value **apUnused /* Function arguments */
263269 ){
263270 assert( nArg==0 );
263271 UNUSED_PARAM2(nArg, apUnused);
263272 sqlite3_result_text(pCtx, "fts5: 2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06", -1, SQLITE_TRANSIENT);
263273 }
263274
263275 /*
263276 ** Implementation of fts5_locale(LOCALE, TEXT) function.
263277 **
263278
+19 -6
--- 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-06-08 18:15:27 4cb349370daab17123770c814c71872a3e4c616a3f984569b3d7f97f9c3f5ea0"
151
+#define SQLITE_SOURCE_ID "2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2026-06-08T18:15:27.790Z"
154
+#define SQLITE_SCM_DATETIME "2026-06-16T13:43:08.110Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
@@ -4375,11 +4375,12 @@
43754375
** <dd>The maximum number of columns in a table definition or in the
43764376
** result set of a [SELECT] or the maximum number of columns in an index
43774377
** or in an ORDER BY or GROUP BY clause.</dd>)^
43784378
**
43794379
** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
4380
-** <dd>The maximum depth of the parse tree on any expression.</dd>)^
4380
+** <dd>The maximum depth of the parse tree on any expression and
4381
+** the maximum nesting depth for subqueries and VIEWs</dd>)^
43814382
**
43824383
** [[SQLITE_LIMIT_PARSER_DEPTH]] ^(<dt>SQLITE_LIMIT_PARSER_DEPTH</dt>
43834384
** <dd>The maximum depth of the LALR(1) parser stack used to analyze
43844385
** input SQL statements.</dd>)^
43854386
**
@@ -4406,11 +4407,12 @@
44064407
** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
44074408
** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
44084409
** <dd>The maximum index number of any [parameter] in an SQL statement.)^
44094410
**
44104411
** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
4411
-** <dd>The maximum depth of recursion for triggers.</dd>)^
4412
+** <dd>The maximum depth of recursion for triggers, and the maximum
4413
+** nesting depth for separate triggers.</dd>)^
44124414
**
44134415
** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
44144416
** <dd>The maximum number of auxiliary worker threads that a single
44154417
** [prepared statement] may start.</dd>)^
44164418
** </dl>
@@ -11212,12 +11214,23 @@
1121211214
** reopen S as an in-memory database based on the serialization
1121311215
** contained in P. If S is a NULL pointer, the main database is
1121411216
** used. The serialized database P is N bytes in size. M is the size
1121511217
** of the buffer P, which might be larger than N. If M is larger than
1121611218
** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then
11217
-** SQLite is permitted to add content to the in-memory database as
11218
-** long as the total size does not exceed M bytes.
11219
+** SQLite is permitted to add content to the in-memory database, in
11220
+** page-sized chunks, as long as the total size does not exceed M bytes.
11221
+**
11222
+** The parameter M must be greater than or equal to N. Ideally, M
11223
+** should have a value which is N+(512&times;K)+20 where K determines how
11224
+** must extra space is available to hold new content as the database
11225
+** grows. K can be 0 if the database is read-only.
11226
+**
11227
+** If the database content in P is malformed in a malicious way then
11228
+** it is possible that SQLite might try to read a few more than N bytes
11229
+** from P. If the veracity of the database content P is uncertain,
11230
+** then applications are advised to allocate about 20 extra bytes on
11231
+** the end of the P buffer to avoid a memory error.
1121911232
**
1122011233
** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
1122111234
** invoke sqlite3_free() on the serialization buffer when the database
1122211235
** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
1122311236
** SQLite will try to increase the buffer size using sqlite3_realloc64()
1122411237
--- 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-06-08 18:15:27 4cb349370daab17123770c814c71872a3e4c616a3f984569b3d7f97f9c3f5ea0"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-06-08T18:15:27.790Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -4375,11 +4375,12 @@
4375 ** <dd>The maximum number of columns in a table definition or in the
4376 ** result set of a [SELECT] or the maximum number of columns in an index
4377 ** or in an ORDER BY or GROUP BY clause.</dd>)^
4378 **
4379 ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
4380 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
 
4381 **
4382 ** [[SQLITE_LIMIT_PARSER_DEPTH]] ^(<dt>SQLITE_LIMIT_PARSER_DEPTH</dt>
4383 ** <dd>The maximum depth of the LALR(1) parser stack used to analyze
4384 ** input SQL statements.</dd>)^
4385 **
@@ -4406,11 +4407,12 @@
4406 ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
4407 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
4408 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
4409 **
4410 ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
4411 ** <dd>The maximum depth of recursion for triggers.</dd>)^
 
4412 **
4413 ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
4414 ** <dd>The maximum number of auxiliary worker threads that a single
4415 ** [prepared statement] may start.</dd>)^
4416 ** </dl>
@@ -11212,12 +11214,23 @@
11212 ** reopen S as an in-memory database based on the serialization
11213 ** contained in P. If S is a NULL pointer, the main database is
11214 ** used. The serialized database P is N bytes in size. M is the size
11215 ** of the buffer P, which might be larger than N. If M is larger than
11216 ** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then
11217 ** SQLite is permitted to add content to the in-memory database as
11218 ** long as the total size does not exceed M bytes.
 
 
 
 
 
 
 
 
 
 
 
11219 **
11220 ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
11221 ** invoke sqlite3_free() on the serialization buffer when the database
11222 ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
11223 ** SQLite will try to increase the buffer size using sqlite3_realloc64()
11224
--- 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-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-06-16T13:43:08.110Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -4375,11 +4375,12 @@
4375 ** <dd>The maximum number of columns in a table definition or in the
4376 ** result set of a [SELECT] or the maximum number of columns in an index
4377 ** or in an ORDER BY or GROUP BY clause.</dd>)^
4378 **
4379 ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
4380 ** <dd>The maximum depth of the parse tree on any expression and
4381 ** the maximum nesting depth for subqueries and VIEWs</dd>)^
4382 **
4383 ** [[SQLITE_LIMIT_PARSER_DEPTH]] ^(<dt>SQLITE_LIMIT_PARSER_DEPTH</dt>
4384 ** <dd>The maximum depth of the LALR(1) parser stack used to analyze
4385 ** input SQL statements.</dd>)^
4386 **
@@ -4406,11 +4407,12 @@
4407 ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
4408 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
4409 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
4410 **
4411 ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
4412 ** <dd>The maximum depth of recursion for triggers, and the maximum
4413 ** nesting depth for separate triggers.</dd>)^
4414 **
4415 ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
4416 ** <dd>The maximum number of auxiliary worker threads that a single
4417 ** [prepared statement] may start.</dd>)^
4418 ** </dl>
@@ -11212,12 +11214,23 @@
11214 ** reopen S as an in-memory database based on the serialization
11215 ** contained in P. If S is a NULL pointer, the main database is
11216 ** used. The serialized database P is N bytes in size. M is the size
11217 ** of the buffer P, which might be larger than N. If M is larger than
11218 ** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then
11219 ** SQLite is permitted to add content to the in-memory database, in
11220 ** page-sized chunks, as long as the total size does not exceed M bytes.
11221 **
11222 ** The parameter M must be greater than or equal to N. Ideally, M
11223 ** should have a value which is N+(512&times;K)+20 where K determines how
11224 ** must extra space is available to hold new content as the database
11225 ** grows. K can be 0 if the database is read-only.
11226 **
11227 ** If the database content in P is malformed in a malicious way then
11228 ** it is possible that SQLite might try to read a few more than N bytes
11229 ** from P. If the veracity of the database content P is uncertain,
11230 ** then applications are advised to allocate about 20 extra bytes on
11231 ** the end of the P buffer to avoid a memory error.
11232 **
11233 ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
11234 ** invoke sqlite3_free() on the serialization buffer when the database
11235 ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
11236 ** SQLite will try to increase the buffer size using sqlite3_realloc64()
11237

Keyboard Shortcuts

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