Fossil SCM

Update the built-in SQLite to the latest trunk for testing.

drh 2025-09-10 10:51 trunk
Commit dc45faa3b77789af1b829651e23dc4004eda313c89884f40ed58f987ab3cc07c
3 files changed +36 -6 +526 -231 +63 -35
+36 -6
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1329,11 +1329,11 @@
13291329
13301330
/*
13311331
** This routine reads a line of text from FILE in, stores
13321332
** the text in memory obtained from malloc() and returns a pointer
13331333
** to the text. NULL is returned at end of file, or if malloc()
1334
-** fails.
1334
+** fails, or if the length of the line is longer than about a gigabyte.
13351335
**
13361336
** If zLine is not NULL then it is a malloced buffer returned from
13371337
** a previous call to this routine that may be reused.
13381338
*/
13391339
static char *local_getline(char *zLine, FILE *in){
@@ -1340,10 +1340,14 @@
13401340
int nLine = zLine==0 ? 0 : 100;
13411341
int n = 0;
13421342
13431343
while( 1 ){
13441344
if( n+100>nLine ){
1345
+ if( nLine>=1073741773 ){
1346
+ free(zLine);
1347
+ return 0;
1348
+ }
13451349
nLine = nLine*2 + 100;
13461350
zLine = realloc(zLine, nLine);
13471351
shell_check_oom(zLine);
13481352
}
13491353
if( sqlite3_fgets(&zLine[n], nLine - n, in)==0 ){
@@ -10223,10 +10227,11 @@
1022310227
"z HIDDEN" /* 7: Name of zip file */
1022410228
") WITHOUT ROWID;";
1022510229
1022610230
#define ZIPFILE_F_COLUMN_IDX 7 /* Index of column "file" in the above */
1022710231
#define ZIPFILE_BUFFER_SIZE (64*1024)
10232
+#define ZIPFILE_MX_NAME (250) /* Windows limitation on filename size */
1022810233
1022910234
1023010235
/*
1023110236
** Magic numbers used to read and write zip files.
1023210237
**
@@ -10779,10 +10784,11 @@
1077910784
pLFH->crc32 = zipfileRead32(aRead);
1078010785
pLFH->szCompressed = zipfileRead32(aRead);
1078110786
pLFH->szUncompressed = zipfileRead32(aRead);
1078210787
pLFH->nFile = zipfileRead16(aRead);
1078310788
pLFH->nExtra = zipfileRead16(aRead);
10789
+ if( pLFH->nFile>ZIPFILE_MX_NAME ) rc = SQLITE_ERROR;
1078410790
}
1078510791
return rc;
1078610792
}
1078710793
1078810794
@@ -10992,12 +10998,16 @@
1099210998
if( rc==SQLITE_OK ) rc = zipfileReadLFH(aRead, &lfh);
1099310999
if( rc==SQLITE_OK ){
1099411000
pNew->iDataOff = pNew->cds.iOffset + ZIPFILE_LFH_FIXED_SZ;
1099511001
pNew->iDataOff += lfh.nFile + lfh.nExtra;
1099611002
if( aBlob && pNew->cds.szCompressed ){
10997
- pNew->aData = &pNew->aExtra[nExtra];
10998
- memcpy(pNew->aData, &aBlob[pNew->iDataOff], pNew->cds.szCompressed);
11003
+ if( pNew->iDataOff + pNew->cds.szCompressed > nBlob ){
11004
+ rc = SQLITE_CORRUPT;
11005
+ }else{
11006
+ pNew->aData = &pNew->aExtra[nExtra];
11007
+ memcpy(pNew->aData, &aBlob[pNew->iDataOff], pNew->cds.szCompressed);
11008
+ }
1099911009
}
1100011010
}else{
1100111011
*pzErr = sqlite3_mprintf("failed to read LFH at offset %d",
1100211012
(int)pNew->cds.iOffset
1100311013
);
@@ -11780,10 +11790,15 @@
1178011790
1178111791
if( rc==SQLITE_OK ){
1178211792
zPath = (const char*)sqlite3_value_text(apVal[2]);
1178311793
if( zPath==0 ) zPath = "";
1178411794
nPath = (int)strlen(zPath);
11795
+ if( nPath>ZIPFILE_MX_NAME ){
11796
+ zipfileTableErr(pTab, "filename too long; max: %d bytes",
11797
+ ZIPFILE_MX_NAME);
11798
+ rc = SQLITE_CONSTRAINT;
11799
+ }
1178511800
mTime = zipfileGetTime(apVal[4]);
1178611801
}
1178711802
1178811803
if( rc==SQLITE_OK && bIsDir ){
1178911804
/* For a directory, check that the last character in the path is a
@@ -12140,10 +12155,17 @@
1214012155
nName = sqlite3_value_bytes(pName);
1214112156
if( zName==0 ){
1214212157
zErr = sqlite3_mprintf("first argument to zipfile() must be non-NULL");
1214312158
rc = SQLITE_ERROR;
1214412159
goto zipfile_step_out;
12160
+ }
12161
+ if( nName>ZIPFILE_MX_NAME ){
12162
+ zErr = sqlite3_mprintf(
12163
+ "filename argument to zipfile() too big; max: %d bytes",
12164
+ ZIPFILE_MX_NAME);
12165
+ rc = SQLITE_ERROR;
12166
+ goto zipfile_step_out;
1214512167
}
1214612168
1214712169
/* Inspect the 'method' parameter. This must be either 0 (store), 8 (use
1214812170
** deflate compression) or NULL (choose automatically). */
1214912171
if( pMethod && SQLITE_NULL!=sqlite3_value_type(pMethod) ){
@@ -22033,11 +22055,11 @@
2203322055
2203422056
/*
2203522057
** Output the given string as a quoted string using SQL quoting conventions:
2203622058
**
2203722059
** (1) Single quotes (') within the string are doubled
22038
-** (2) The whle string is enclosed in '...'
22060
+** (2) The while string is enclosed in '...'
2203922061
** (3) Control characters other than \n, \t, and \r\n are escaped
2204022062
** using \u00XX notation and if such substitutions occur,
2204122063
** the whole string is enclosed in unistr('...') instead of '...'.
2204222064
**
2204322065
** Step (3) is omitted if the control-character escape mode is OFF.
@@ -22279,11 +22301,11 @@
2227922301
**
2228022302
** Escaping is needed if the string contains any control characters
2228122303
** other than \t, \n, and \r\n
2228222304
**
2228322305
** If no escaping is needed (the common case) then set *ppFree to NULL
22284
-** and return the original string. If escapingn is needed, write the
22306
+** and return the original string. If escaping is needed, write the
2228522307
** escaped string into memory obtained from sqlite3_malloc64() or the
2228622308
** equivalent, and return the new string and set *ppFree to the new string
2228722309
** as well.
2228822310
**
2228922311
** The caller is responsible for freeing *ppFree if it is non-NULL in order
@@ -33368,16 +33390,24 @@
3336833390
(void)cmdline_option_value(argc, argv, ++i);
3336933391
#endif
3337033392
}else if( cli_strcmp(z,"-pagecache")==0 ){
3337133393
sqlite3_int64 n, sz;
3337233394
sz = integerValue(cmdline_option_value(argc,argv,++i));
33373
- if( sz>70000 ) sz = 70000;
33395
+ if( sz>65536 ) sz = 65536;
3337433396
if( sz<0 ) sz = 0;
3337533397
n = integerValue(cmdline_option_value(argc,argv,++i));
3337633398
if( sz>0 && n>0 && 0xffffffffffffLL/sz<n ){
3337733399
n = 0xffffffffffffLL/sz;
3337833400
}
33401
+ if( sz>0 && (sz & (sz-1))==0 ){
33402
+ /* If SIZE is a power of two, round it up by the PCACHE_HDRSZ */
33403
+ int szHdr = 0;
33404
+ sqlite3_config(SQLITE_CONFIG_PCACHE_HDRSZ, &szHdr);
33405
+ sz += szHdr;
33406
+ sqlite3_fprintf(stdout, "Page cache size increased to %d to accommodate"
33407
+ " the %d-byte headers\n", (int)sz, szHdr);
33408
+ }
3337933409
verify_uninitialized();
3338033410
sqlite3_config(SQLITE_CONFIG_PAGECACHE,
3338133411
(n>0 && sz>0) ? malloc(n*sz) : 0, sz, n);
3338233412
data.shellFlgs |= SHFLG_Pagecache;
3338333413
}else if( cli_strcmp(z,"-lookaside")==0 ){
3338433414
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1329,11 +1329,11 @@
1329
1330 /*
1331 ** This routine reads a line of text from FILE in, stores
1332 ** the text in memory obtained from malloc() and returns a pointer
1333 ** to the text. NULL is returned at end of file, or if malloc()
1334 ** fails.
1335 **
1336 ** If zLine is not NULL then it is a malloced buffer returned from
1337 ** a previous call to this routine that may be reused.
1338 */
1339 static char *local_getline(char *zLine, FILE *in){
@@ -1340,10 +1340,14 @@
1340 int nLine = zLine==0 ? 0 : 100;
1341 int n = 0;
1342
1343 while( 1 ){
1344 if( n+100>nLine ){
 
 
 
 
1345 nLine = nLine*2 + 100;
1346 zLine = realloc(zLine, nLine);
1347 shell_check_oom(zLine);
1348 }
1349 if( sqlite3_fgets(&zLine[n], nLine - n, in)==0 ){
@@ -10223,10 +10227,11 @@
10223 "z HIDDEN" /* 7: Name of zip file */
10224 ") WITHOUT ROWID;";
10225
10226 #define ZIPFILE_F_COLUMN_IDX 7 /* Index of column "file" in the above */
10227 #define ZIPFILE_BUFFER_SIZE (64*1024)
 
10228
10229
10230 /*
10231 ** Magic numbers used to read and write zip files.
10232 **
@@ -10779,10 +10784,11 @@
10779 pLFH->crc32 = zipfileRead32(aRead);
10780 pLFH->szCompressed = zipfileRead32(aRead);
10781 pLFH->szUncompressed = zipfileRead32(aRead);
10782 pLFH->nFile = zipfileRead16(aRead);
10783 pLFH->nExtra = zipfileRead16(aRead);
 
10784 }
10785 return rc;
10786 }
10787
10788
@@ -10992,12 +10998,16 @@
10992 if( rc==SQLITE_OK ) rc = zipfileReadLFH(aRead, &lfh);
10993 if( rc==SQLITE_OK ){
10994 pNew->iDataOff = pNew->cds.iOffset + ZIPFILE_LFH_FIXED_SZ;
10995 pNew->iDataOff += lfh.nFile + lfh.nExtra;
10996 if( aBlob && pNew->cds.szCompressed ){
10997 pNew->aData = &pNew->aExtra[nExtra];
10998 memcpy(pNew->aData, &aBlob[pNew->iDataOff], pNew->cds.szCompressed);
 
 
 
 
10999 }
11000 }else{
11001 *pzErr = sqlite3_mprintf("failed to read LFH at offset %d",
11002 (int)pNew->cds.iOffset
11003 );
@@ -11780,10 +11790,15 @@
11780
11781 if( rc==SQLITE_OK ){
11782 zPath = (const char*)sqlite3_value_text(apVal[2]);
11783 if( zPath==0 ) zPath = "";
11784 nPath = (int)strlen(zPath);
 
 
 
 
 
11785 mTime = zipfileGetTime(apVal[4]);
11786 }
11787
11788 if( rc==SQLITE_OK && bIsDir ){
11789 /* For a directory, check that the last character in the path is a
@@ -12140,10 +12155,17 @@
12140 nName = sqlite3_value_bytes(pName);
12141 if( zName==0 ){
12142 zErr = sqlite3_mprintf("first argument to zipfile() must be non-NULL");
12143 rc = SQLITE_ERROR;
12144 goto zipfile_step_out;
 
 
 
 
 
 
 
12145 }
12146
12147 /* Inspect the 'method' parameter. This must be either 0 (store), 8 (use
12148 ** deflate compression) or NULL (choose automatically). */
12149 if( pMethod && SQLITE_NULL!=sqlite3_value_type(pMethod) ){
@@ -22033,11 +22055,11 @@
22033
22034 /*
22035 ** Output the given string as a quoted string using SQL quoting conventions:
22036 **
22037 ** (1) Single quotes (') within the string are doubled
22038 ** (2) The whle string is enclosed in '...'
22039 ** (3) Control characters other than \n, \t, and \r\n are escaped
22040 ** using \u00XX notation and if such substitutions occur,
22041 ** the whole string is enclosed in unistr('...') instead of '...'.
22042 **
22043 ** Step (3) is omitted if the control-character escape mode is OFF.
@@ -22279,11 +22301,11 @@
22279 **
22280 ** Escaping is needed if the string contains any control characters
22281 ** other than \t, \n, and \r\n
22282 **
22283 ** If no escaping is needed (the common case) then set *ppFree to NULL
22284 ** and return the original string. If escapingn is needed, write the
22285 ** escaped string into memory obtained from sqlite3_malloc64() or the
22286 ** equivalent, and return the new string and set *ppFree to the new string
22287 ** as well.
22288 **
22289 ** The caller is responsible for freeing *ppFree if it is non-NULL in order
@@ -33368,16 +33390,24 @@
33368 (void)cmdline_option_value(argc, argv, ++i);
33369 #endif
33370 }else if( cli_strcmp(z,"-pagecache")==0 ){
33371 sqlite3_int64 n, sz;
33372 sz = integerValue(cmdline_option_value(argc,argv,++i));
33373 if( sz>70000 ) sz = 70000;
33374 if( sz<0 ) sz = 0;
33375 n = integerValue(cmdline_option_value(argc,argv,++i));
33376 if( sz>0 && n>0 && 0xffffffffffffLL/sz<n ){
33377 n = 0xffffffffffffLL/sz;
33378 }
 
 
 
 
 
 
 
 
33379 verify_uninitialized();
33380 sqlite3_config(SQLITE_CONFIG_PAGECACHE,
33381 (n>0 && sz>0) ? malloc(n*sz) : 0, sz, n);
33382 data.shellFlgs |= SHFLG_Pagecache;
33383 }else if( cli_strcmp(z,"-lookaside")==0 ){
33384
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1329,11 +1329,11 @@
1329
1330 /*
1331 ** This routine reads a line of text from FILE in, stores
1332 ** the text in memory obtained from malloc() and returns a pointer
1333 ** to the text. NULL is returned at end of file, or if malloc()
1334 ** fails, or if the length of the line is longer than about a gigabyte.
1335 **
1336 ** If zLine is not NULL then it is a malloced buffer returned from
1337 ** a previous call to this routine that may be reused.
1338 */
1339 static char *local_getline(char *zLine, FILE *in){
@@ -1340,10 +1340,14 @@
1340 int nLine = zLine==0 ? 0 : 100;
1341 int n = 0;
1342
1343 while( 1 ){
1344 if( n+100>nLine ){
1345 if( nLine>=1073741773 ){
1346 free(zLine);
1347 return 0;
1348 }
1349 nLine = nLine*2 + 100;
1350 zLine = realloc(zLine, nLine);
1351 shell_check_oom(zLine);
1352 }
1353 if( sqlite3_fgets(&zLine[n], nLine - n, in)==0 ){
@@ -10223,10 +10227,11 @@
10227 "z HIDDEN" /* 7: Name of zip file */
10228 ") WITHOUT ROWID;";
10229
10230 #define ZIPFILE_F_COLUMN_IDX 7 /* Index of column "file" in the above */
10231 #define ZIPFILE_BUFFER_SIZE (64*1024)
10232 #define ZIPFILE_MX_NAME (250) /* Windows limitation on filename size */
10233
10234
10235 /*
10236 ** Magic numbers used to read and write zip files.
10237 **
@@ -10779,10 +10784,11 @@
10784 pLFH->crc32 = zipfileRead32(aRead);
10785 pLFH->szCompressed = zipfileRead32(aRead);
10786 pLFH->szUncompressed = zipfileRead32(aRead);
10787 pLFH->nFile = zipfileRead16(aRead);
10788 pLFH->nExtra = zipfileRead16(aRead);
10789 if( pLFH->nFile>ZIPFILE_MX_NAME ) rc = SQLITE_ERROR;
10790 }
10791 return rc;
10792 }
10793
10794
@@ -10992,12 +10998,16 @@
10998 if( rc==SQLITE_OK ) rc = zipfileReadLFH(aRead, &lfh);
10999 if( rc==SQLITE_OK ){
11000 pNew->iDataOff = pNew->cds.iOffset + ZIPFILE_LFH_FIXED_SZ;
11001 pNew->iDataOff += lfh.nFile + lfh.nExtra;
11002 if( aBlob && pNew->cds.szCompressed ){
11003 if( pNew->iDataOff + pNew->cds.szCompressed > nBlob ){
11004 rc = SQLITE_CORRUPT;
11005 }else{
11006 pNew->aData = &pNew->aExtra[nExtra];
11007 memcpy(pNew->aData, &aBlob[pNew->iDataOff], pNew->cds.szCompressed);
11008 }
11009 }
11010 }else{
11011 *pzErr = sqlite3_mprintf("failed to read LFH at offset %d",
11012 (int)pNew->cds.iOffset
11013 );
@@ -11780,10 +11790,15 @@
11790
11791 if( rc==SQLITE_OK ){
11792 zPath = (const char*)sqlite3_value_text(apVal[2]);
11793 if( zPath==0 ) zPath = "";
11794 nPath = (int)strlen(zPath);
11795 if( nPath>ZIPFILE_MX_NAME ){
11796 zipfileTableErr(pTab, "filename too long; max: %d bytes",
11797 ZIPFILE_MX_NAME);
11798 rc = SQLITE_CONSTRAINT;
11799 }
11800 mTime = zipfileGetTime(apVal[4]);
11801 }
11802
11803 if( rc==SQLITE_OK && bIsDir ){
11804 /* For a directory, check that the last character in the path is a
@@ -12140,10 +12155,17 @@
12155 nName = sqlite3_value_bytes(pName);
12156 if( zName==0 ){
12157 zErr = sqlite3_mprintf("first argument to zipfile() must be non-NULL");
12158 rc = SQLITE_ERROR;
12159 goto zipfile_step_out;
12160 }
12161 if( nName>ZIPFILE_MX_NAME ){
12162 zErr = sqlite3_mprintf(
12163 "filename argument to zipfile() too big; max: %d bytes",
12164 ZIPFILE_MX_NAME);
12165 rc = SQLITE_ERROR;
12166 goto zipfile_step_out;
12167 }
12168
12169 /* Inspect the 'method' parameter. This must be either 0 (store), 8 (use
12170 ** deflate compression) or NULL (choose automatically). */
12171 if( pMethod && SQLITE_NULL!=sqlite3_value_type(pMethod) ){
@@ -22033,11 +22055,11 @@
22055
22056 /*
22057 ** Output the given string as a quoted string using SQL quoting conventions:
22058 **
22059 ** (1) Single quotes (') within the string are doubled
22060 ** (2) The while string is enclosed in '...'
22061 ** (3) Control characters other than \n, \t, and \r\n are escaped
22062 ** using \u00XX notation and if such substitutions occur,
22063 ** the whole string is enclosed in unistr('...') instead of '...'.
22064 **
22065 ** Step (3) is omitted if the control-character escape mode is OFF.
@@ -22279,11 +22301,11 @@
22301 **
22302 ** Escaping is needed if the string contains any control characters
22303 ** other than \t, \n, and \r\n
22304 **
22305 ** If no escaping is needed (the common case) then set *ppFree to NULL
22306 ** and return the original string. If escaping is needed, write the
22307 ** escaped string into memory obtained from sqlite3_malloc64() or the
22308 ** equivalent, and return the new string and set *ppFree to the new string
22309 ** as well.
22310 **
22311 ** The caller is responsible for freeing *ppFree if it is non-NULL in order
@@ -33368,16 +33390,24 @@
33390 (void)cmdline_option_value(argc, argv, ++i);
33391 #endif
33392 }else if( cli_strcmp(z,"-pagecache")==0 ){
33393 sqlite3_int64 n, sz;
33394 sz = integerValue(cmdline_option_value(argc,argv,++i));
33395 if( sz>65536 ) sz = 65536;
33396 if( sz<0 ) sz = 0;
33397 n = integerValue(cmdline_option_value(argc,argv,++i));
33398 if( sz>0 && n>0 && 0xffffffffffffLL/sz<n ){
33399 n = 0xffffffffffffLL/sz;
33400 }
33401 if( sz>0 && (sz & (sz-1))==0 ){
33402 /* If SIZE is a power of two, round it up by the PCACHE_HDRSZ */
33403 int szHdr = 0;
33404 sqlite3_config(SQLITE_CONFIG_PCACHE_HDRSZ, &szHdr);
33405 sz += szHdr;
33406 sqlite3_fprintf(stdout, "Page cache size increased to %d to accommodate"
33407 " the %d-byte headers\n", (int)sz, szHdr);
33408 }
33409 verify_uninitialized();
33410 sqlite3_config(SQLITE_CONFIG_PAGECACHE,
33411 (n>0 && sz>0) ? malloc(n*sz) : 0, sz, n);
33412 data.shellFlgs |= SHFLG_Pagecache;
33413 }else if( cli_strcmp(z,"-lookaside")==0 ){
33414
+526 -231
--- 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
-** cf7163f82ca380958a79350473b2c5a2cebd with changes in files:
21
+** 0f31711591c56f3896fb6f092752fb82c4ea with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -465,11 +465,14 @@
465465
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466466
** [sqlite_version()] and [sqlite_source_id()].
467467
*/
468468
#define SQLITE_VERSION "3.51.0"
469469
#define SQLITE_VERSION_NUMBER 3051000
470
-#define SQLITE_SOURCE_ID "2025-07-30 16:17:14 cf7163f82ca380958a79350473b2c5a2cebda7496d6d575fa2835c362010fea1"
470
+#define SQLITE_SOURCE_ID "2025-09-09 10:28:06 0f31711591c56f3896fb6f092752fb82c4ea646bf8e5838dfbe55302994ea091"
471
+#define SQLITE_SCM_BRANCH "trunk"
472
+#define SQLITE_SCM_TAGS ""
473
+#define SQLITE_SCM_DATETIME "2025-09-09T10:28:06.692Z"
471474
472475
/*
473476
** CAPI3REF: Run-Time Library Version Numbers
474477
** KEYWORDS: sqlite3_version sqlite3_sourceid
475478
**
@@ -2657,21 +2660,24 @@
26572660
** views in the main database schema or in the schemas of ATTACH-ed
26582661
** databases.)^ </dd>
26592662
**
26602663
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
26612664
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2662
-** <dd> ^This option is used to enable or disable the
2663
-** [fts3_tokenizer()] function which is part of the
2664
-** [FTS3] full-text search engine extension.
2665
-** There must be two additional arguments.
2666
-** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2667
-** positive to enable fts3_tokenizer() or negative to leave the setting
2668
-** unchanged.
2669
-** The second parameter is a pointer to an integer into which
2670
-** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2671
-** following this call. The second parameter may be a NULL pointer, in
2672
-** which case the new setting is not reported back. </dd>
2665
+** <dd> ^This option is used to enable or disable using the
2666
+** [fts3_tokenizer()] function - part of the [FTS3] full-text search engine
2667
+** extension - without using bound parameters as the parameters. Doing so
2668
+** is disabled by default. There must be two additional arguments. The first
2669
+** argument is an integer. If it is passed 0, then using fts3_tokenizer()
2670
+** without bound parameters is disabled. If it is passed a positive value,
2671
+** then calling fts3_tokenizer without bound parameters is enabled. If it
2672
+** is passed a negative value, this setting is not modified - this can be
2673
+** used to query for the current setting. The second parameter is a pointer
2674
+** to an integer into which is written 0 or 1 to indicate the current value
2675
+** of this setting (after it is modified, if applicable). The second
2676
+** parameter may be a NULL pointer, in which case the value of the setting
2677
+** is not reported back. Refer to [FTS3] documentation for further details.
2678
+** </dd>
26732679
**
26742680
** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
26752681
** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
26762682
** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
26772683
** interface independently of the [load_extension()] SQL function.
@@ -6527,10 +6533,11 @@
65276533
** to be attached to [database connection] D using name N. Subsequent
65286534
** calls to sqlite3_get_clientdata(D,N) will return a copy of pointer P
65296535
** or a NULL pointer if there were no prior calls to
65306536
** sqlite3_set_clientdata() with the same values of D and N.
65316537
** Names are compared using strcmp() and are thus case sensitive.
6538
+** It returns 0 on success and SQLITE_NOMEM on allocation failure.
65326539
**
65336540
** If P and X are both non-NULL, then the destructor X is invoked with
65346541
** argument P on the first of the following occurrences:
65356542
** <ul>
65366543
** <li> An out-of-memory error occurs during the call to
@@ -10098,25 +10105,38 @@
1009810105
** ^The third parameter is the name of the database that was written to -
1009910106
** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
1010010107
** is the number of pages currently in the write-ahead log file,
1010110108
** including those that were just committed.
1010210109
**
10103
-** The callback function should normally return [SQLITE_OK]. ^If an error
10110
+** ^The callback function should normally return [SQLITE_OK]. ^If an error
1010410111
** code is returned, that error will propagate back up through the
1010510112
** SQLite code base to cause the statement that provoked the callback
1010610113
** to report an error, though the commit will have still occurred. If the
1010710114
** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
1010810115
** that does not correspond to any valid SQLite error code, the results
1010910116
** are undefined.
1011010117
**
10111
-** A single database handle may have at most a single write-ahead log callback
10112
-** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
10113
-** previously registered write-ahead log callback. ^The return value is
10114
-** a copy of the third parameter from the previous call, if any, or 0.
10115
-** ^Note that the [sqlite3_wal_autocheckpoint()] interface and the
10116
-** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
10117
-** overwrite any prior [sqlite3_wal_hook()] settings.
10118
+** ^A single database handle may have at most a single write-ahead log
10119
+** callback registered at one time. ^Calling [sqlite3_wal_hook()]
10120
+** replaces the default behavior or previously registered write-ahead
10121
+** log callback.
10122
+**
10123
+** ^The return value is a copy of the third parameter from the
10124
+** previous call, if any, or 0.
10125
+**
10126
+** ^The [sqlite3_wal_autocheckpoint()] interface and the
10127
+** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and
10128
+** will overwrite any prior [sqlite3_wal_hook()] settings.
10129
+**
10130
+** ^If a write-ahead log callback is set using this function then
10131
+** [sqlite3_wal_checkpoint_v2()] or [PRAGMA wal_checkpoint]
10132
+** should be invoked periodically to keep the write-ahead log file
10133
+** from growing without bound.
10134
+**
10135
+** ^Passing a NULL pointer for the callback disables automatic
10136
+** checkpointing entirely. To re-enable the default behavior, call
10137
+** sqlite3_wal_autocheckpoint(db,1000) or use [PRAGMA wal_checkpoint].
1011810138
*/
1011910139
SQLITE_API void *sqlite3_wal_hook(
1012010140
sqlite3*,
1012110141
int(*)(void *,sqlite3*,const char*,int),
1012210142
void*
@@ -10129,11 +10149,11 @@
1012910149
** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
1013010150
** [sqlite3_wal_hook()] that causes any database on [database connection] D
1013110151
** to automatically [checkpoint]
1013210152
** after committing a transaction if there are N or
1013310153
** more frames in the [write-ahead log] file. ^Passing zero or
10134
-** a negative value as the nFrame parameter disables automatic
10154
+** a negative value as the N parameter disables automatic
1013510155
** checkpoints entirely.
1013610156
**
1013710157
** ^The callback registered by this function replaces any existing callback
1013810158
** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback
1013910159
** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
@@ -10145,13 +10165,14 @@
1014510165
** ^Checkpoints initiated by this mechanism are
1014610166
** [sqlite3_wal_checkpoint_v2|PASSIVE].
1014710167
**
1014810168
** ^Every new [database connection] defaults to having the auto-checkpoint
1014910169
** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
10150
-** pages. The use of this interface
10151
-** is only necessary if the default setting is found to be suboptimal
10152
-** for a particular application.
10170
+** pages.
10171
+**
10172
+** ^The use of this interface is only necessary if the default setting
10173
+** is found to be suboptimal for a particular application.
1015310174
*/
1015410175
SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
1015510176
1015610177
/*
1015710178
** CAPI3REF: Checkpoint a database
@@ -10212,10 +10233,15 @@
1021210233
**
1021310234
** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
1021410235
** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
1021510236
** addition that it also truncates the log file to zero bytes just prior
1021610237
** to a successful return.
10238
+**
10239
+** <dt>SQLITE_CHECKPOINT_NOOP<dd>
10240
+** ^This mode always checkpoints zero frames. The only reason to invoke
10241
+** a NOOP checkpoint is to access the values returned by
10242
+** sqlite3_wal_checkpoint_v2() via output parameters *pnLog and *pnCkpt.
1021710243
** </dl>
1021810244
**
1021910245
** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
1022010246
** the log file or to -1 if the checkpoint could not run because
1022110247
** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
@@ -10282,10 +10308,11 @@
1028210308
** These constants define all valid values for the "checkpoint mode" passed
1028310309
** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
1028410310
** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
1028510311
** meaning of each of these checkpoint modes.
1028610312
*/
10313
+#define SQLITE_CHECKPOINT_NOOP -1 /* Do no work at all */
1028710314
#define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
1028810315
#define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
1028910316
#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */
1029010317
#define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
1029110318
@@ -11109,11 +11136,11 @@
1110911136
** to avoid a memory leak.
1111011137
**
1111111138
** The [sqlite3_snapshot_get()] interface is only available when the
1111211139
** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
1111311140
*/
11114
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get(
11141
+SQLITE_API int sqlite3_snapshot_get(
1111511142
sqlite3 *db,
1111611143
const char *zSchema,
1111711144
sqlite3_snapshot **ppSnapshot
1111811145
);
1111911146
@@ -11158,11 +11185,11 @@
1115811185
** database connection in order to make it ready to use snapshots.)
1115911186
**
1116011187
** The [sqlite3_snapshot_open()] interface is only available when the
1116111188
** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
1116211189
*/
11163
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open(
11190
+SQLITE_API int sqlite3_snapshot_open(
1116411191
sqlite3 *db,
1116511192
const char *zSchema,
1116611193
sqlite3_snapshot *pSnapshot
1116711194
);
1116811195
@@ -11175,11 +11202,11 @@
1117511202
** using this routine to avoid a memory leak.
1117611203
**
1117711204
** The [sqlite3_snapshot_free()] interface is only available when the
1117811205
** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
1117911206
*/
11180
-SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*);
11207
+SQLITE_API void sqlite3_snapshot_free(sqlite3_snapshot*);
1118111208
1118211209
/*
1118311210
** CAPI3REF: Compare the ages of two snapshot handles.
1118411211
** METHOD: sqlite3_snapshot
1118511212
**
@@ -11202,11 +11229,11 @@
1120211229
** snapshot, and a positive value if P1 is a newer snapshot than P2.
1120311230
**
1120411231
** This interface is only available if SQLite is compiled with the
1120511232
** [SQLITE_ENABLE_SNAPSHOT] option.
1120611233
*/
11207
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
11234
+SQLITE_API int sqlite3_snapshot_cmp(
1120811235
sqlite3_snapshot *p1,
1120911236
sqlite3_snapshot *p2
1121011237
);
1121111238
1121211239
/*
@@ -11230,11 +11257,11 @@
1123011257
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
1123111258
**
1123211259
** This interface is only available if SQLite is compiled with the
1123311260
** [SQLITE_ENABLE_SNAPSHOT] option.
1123411261
*/
11235
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
11262
+SQLITE_API int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
1123611263
1123711264
/*
1123811265
** CAPI3REF: Serialize a database
1123911266
**
1124011267
** The sqlite3_serialize(D,S,P,F) interface returns a pointer to
@@ -11304,16 +11331,17 @@
1130411331
/*
1130511332
** CAPI3REF: Deserialize a database
1130611333
**
1130711334
** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the
1130811335
** [database connection] D to disconnect from database S and then
11309
-** reopen S as an in-memory database based on the serialization contained
11310
-** in P. The serialized database P is N bytes in size. M is the size of
11311
-** the buffer P, which might be larger than N. If M is larger than N, and
11312
-** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is
11313
-** permitted to add content to the in-memory database as long as the total
11314
-** size does not exceed M bytes.
11336
+** reopen S as an in-memory database based on the serialization
11337
+** contained in P. If S is a NULL pointer, the main database is
11338
+** used. The serialized database P is N bytes in size. M is the size
11339
+** of the buffer P, which might be larger than N. If M is larger than
11340
+** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then
11341
+** SQLite is permitted to add content to the in-memory database as
11342
+** long as the total size does not exceed M bytes.
1131511343
**
1131611344
** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
1131711345
** invoke sqlite3_free() on the serialization buffer when the database
1131811346
** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
1131911347
** SQLite will try to increase the buffer size using sqlite3_realloc64()
@@ -14356,11 +14384,11 @@
1435614384
1435714385
/*
1435814386
** Maximum number of pages in one database file.
1435914387
**
1436014388
** This is really just the default value for the max_page_count pragma.
14361
-** This value can be lowered (or raised) at run-time using that the
14389
+** This value can be lowered (or raised) at run-time using the
1436214390
** max_page_count macro.
1436314391
*/
1436414392
#ifndef SQLITE_MAX_PAGE_COUNT
1436514393
# define SQLITE_MAX_PAGE_COUNT 0xfffffffe /* 4294967294 */
1436614394
#endif
@@ -20086,10 +20114,11 @@
2008620114
#define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */
2008720115
#define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */
2008820116
#define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */
2008920117
#define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */
2009020118
#define SF_Correlated 0x20000000 /* True if references the outer context */
20119
+#define SF_OnToWhere 0x40000000 /* One or more ON clauses moved to WHERE */
2009120120
2009220121
/* True if SrcItem X is a subquery that has SF_NestedFrom */
2009320122
#define IsNestedFrom(X) \
2009420123
((X)->fg.isSubquery && \
2009520124
((X)->u4.pSubq->pSelect->selFlags&SF_NestedFrom)!=0)
@@ -20839,10 +20868,11 @@
2083920868
struct Table *pTab; /* Table of generated column */
2084020869
struct CoveringIndexCheck *pCovIdxCk; /* Check for covering index */
2084120870
SrcItem *pSrcItem; /* A single FROM clause item */
2084220871
DbFixer *pFix; /* See sqlite3FixSelect() */
2084320872
Mem *aMem; /* See sqlite3BtreeCursorHint() */
20873
+ struct CheckOnCtx *pCheckOnCtx; /* See selectCheckOnClauses() */
2084420874
} u;
2084520875
};
2084620876
2084720877
/*
2084820878
** The following structure contains information used by the sqliteFix...
@@ -24209,11 +24239,14 @@
2420924239
Mem oldipk; /* Memory cell holding "old" IPK value */
2421024240
Mem *aNew; /* Array of new.* values */
2421124241
Table *pTab; /* Schema object being updated */
2421224242
Index *pPk; /* PK index if pTab is WITHOUT ROWID */
2421324243
sqlite3_value **apDflt; /* Array of default values, if required */
24214
- u8 keyinfoSpace[SZ_KEYINFO_0]; /* Space to hold pKeyinfo[0] content */
24244
+ union {
24245
+ KeyInfo sKey;
24246
+ u8 keyinfoSpace[SZ_KEYINFO_0]; /* Space to hold pKeyinfo[0] content */
24247
+ } uKey;
2421524248
};
2421624249
2421724250
/*
2421824251
** An instance of this object is used to pass an vector of values into
2421924252
** OP_VFilter, the xFilter method of a virtual table. The vector is the
@@ -33486,13 +33519,17 @@
3348633519
sqlite3StrAccumFinish(&x);
3348733520
sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
3348833521
n = 0;
3348933522
if( pItem->fg.isSubquery ) n++;
3349033523
if( pItem->fg.isTabFunc ) n++;
33491
- if( pItem->fg.isUsing ) n++;
33524
+ if( pItem->fg.isUsing || pItem->u3.pOn!=0 ) n++;
3349233525
if( pItem->fg.isUsing ){
3349333526
sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING");
33527
+ }else if( pItem->u3.pOn!=0 ){
33528
+ sqlite3TreeViewItem(pView, "ON", (--n)>0);
33529
+ sqlite3TreeViewExpr(pView, pItem->u3.pOn, 0);
33530
+ sqlite3TreeViewPop(&pView);
3349433531
}
3349533532
if( pItem->fg.isSubquery ){
3349633533
assert( n==1 );
3349733534
if( pItem->pSTab ){
3349833535
Table *pTab = pItem->pSTab;
@@ -39437,14 +39474,15 @@
3943739474
#define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off64_t))\
3943839475
aSyscall[13].pCurrent)
3943939476
3944039477
#if defined(HAVE_FCHMOD)
3944139478
{ "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
39479
+#define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
3944239480
#else
3944339481
{ "fchmod", (sqlite3_syscall_ptr)0, 0 },
39482
+#define osFchmod(FID,MODE) 0
3944439483
#endif
39445
-#define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
3944639484
3944739485
#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
3944839486
{ "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 },
3944939487
#else
3945039488
{ "fallocate", (sqlite3_syscall_ptr)0, 0 },
@@ -40391,10 +40429,14 @@
4039140429
do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR );
4039240430
if( rc!=1 ){
4039340431
storeLastErrno(pFile, errno);
4039440432
return SQLITE_IOERR;
4039540433
}
40434
+ if( fsync(fd) ){
40435
+ storeLastErrno(pFile, errno);
40436
+ return SQLITE_IOERR_FSYNC;
40437
+ }
4039640438
rc = osFstat(fd, &statbuf);
4039740439
if( rc!=0 ){
4039840440
storeLastErrno(pFile, errno);
4039940441
return SQLITE_IOERR;
4040040442
}
@@ -40560,22 +40602,46 @@
4056040602
static int osSetPosixAdvisoryLock(
4056140603
int h, /* The file descriptor on which to take the lock */
4056240604
struct flock *pLock, /* The description of the lock */
4056340605
unixFile *pFile /* Structure holding timeout value */
4056440606
){
40565
- int tm = pFile->iBusyTimeout;
40566
- int rc = osFcntl(h,F_SETLK,pLock);
40567
- while( rc<0 && tm>0 ){
40568
- /* On systems that support some kind of blocking file lock with a timeout,
40569
- ** make appropriate changes here to invoke that blocking file lock. On
40570
- ** generic posix, however, there is no such API. So we simply try the
40571
- ** lock once every millisecond until either the timeout expires, or until
40572
- ** the lock is obtained. */
40573
- unixSleep(0,1000);
40607
+ int rc = 0;
40608
+
40609
+ if( pFile->iBusyTimeout==0 ){
40610
+ /* unixFile->iBusyTimeout is set to 0. In this case, attempt a
40611
+ ** non-blocking lock. */
40612
+ rc = osFcntl(h,F_SETLK,pLock);
40613
+ }else{
40614
+ /* unixFile->iBusyTimeout is set to greater than zero. In this case,
40615
+ ** attempt a blocking-lock with a unixFile->iBusyTimeout ms timeout.
40616
+ **
40617
+ ** On systems that support some kind of blocking file lock operation,
40618
+ ** this block should be replaced by code to attempt a blocking lock
40619
+ ** with a timeout of unixFile->iBusyTimeout ms. The code below is
40620
+ ** placeholder code. If SQLITE_TEST is defined, the placeholder code
40621
+ ** retries the lock once every 1ms until it succeeds or the timeout
40622
+ ** is reached. Or, if SQLITE_TEST is not defined, the placeholder
40623
+ ** code attempts a non-blocking lock and sets unixFile->iBusyTimeout
40624
+ ** to 0. This causes the caller to return SQLITE_BUSY, instead of
40625
+ ** SQLITE_BUSY_TIMEOUT to SQLite - as required by a VFS that does not
40626
+ ** support blocking locks.
40627
+ */
40628
+#ifdef SQLITE_TEST
40629
+ int tm = pFile->iBusyTimeout;
40630
+ while( tm>0 ){
40631
+ rc = osFcntl(h,F_SETLK,pLock);
40632
+ if( rc==0 ) break;
40633
+ unixSleep(0,1000);
40634
+ tm--;
40635
+ }
40636
+#else
4057440637
rc = osFcntl(h,F_SETLK,pLock);
40575
- tm--;
40638
+ pFile->iBusyTimeout = 0;
40639
+#endif
40640
+ /* End of code to replace with real blocking-locks code. */
4057640641
}
40642
+
4057740643
return rc;
4057840644
}
4057940645
#endif /* SQLITE_ENABLE_SETLK_TIMEOUT */
4058040646
4058140647
@@ -51349,33 +51415,39 @@
5134951415
** log-summary, each thread has its own winFile object, but they all
5135051416
** point to a single instance of this object. In other words, each
5135151417
** log-summary is opened only once per process.
5135251418
**
5135351419
** winShmMutexHeld() must be true when creating or destroying
51354
-** this object or while reading or writing the following fields:
51420
+** this object, or while editing the global linked list that starts
51421
+** at winShmNodeList.
5135551422
**
51356
-** nRef
51357
-** pNext
51423
+** When reading or writing the linked list starting at winShmNode.pWinShmList,
51424
+** pShmNode->mutex must be held.
5135851425
**
51359
-** The following fields are read-only after the object is created:
51426
+** The following fields are constant after the object is created:
5136051427
**
5136151428
** zFilename
51429
+** hSharedShm
51430
+** mutex
51431
+** bUseSharedLockHandle
5136251432
**
51363
-** Either winShmNode.mutex must be held or winShmNode.nRef==0 and
51433
+** Either winShmNode.mutex must be held or winShmNode.pWinShmList==0 and
5136451434
** winShmMutexHeld() is true when reading or writing any other field
5136551435
** in this structure.
5136651436
**
51367
-** File-handle hSharedShm is used to (a) take the DMS lock, (b) truncate
51368
-** the *-shm file if the DMS-locking protocol demands it, and (c) map
51369
-** regions of the *-shm file into memory using MapViewOfFile() or
51370
-** similar. Other locks are taken by individual clients using the
51371
-** winShm.hShm handles.
51437
+** File-handle hSharedShm is always used to (a) take the DMS lock, (b)
51438
+** truncate the *-shm file if the DMS-locking protocol demands it, and
51439
+** (c) map regions of the *-shm file into memory using MapViewOfFile()
51440
+** or similar. If bUseSharedLockHandle is true, then other locks are also
51441
+** taken on hSharedShm. Or, if bUseSharedLockHandle is false, then other
51442
+** locks are taken using each connection's winShm.hShm handles.
5137251443
*/
5137351444
struct winShmNode {
5137451445
sqlite3_mutex *mutex; /* Mutex to access this object */
5137551446
char *zFilename; /* Name of the file */
5137651447
HANDLE hSharedShm; /* File handle open on zFilename */
51448
+ int bUseSharedLockHandle; /* True to use hSharedShm for everything */
5137751449
5137851450
int isUnlocked; /* DMS lock has not yet been obtained */
5137951451
int isReadonly; /* True if read-only */
5138051452
int szRegion; /* Size of shared-memory regions */
5138151453
int nRegion; /* Size of array apRegion */
@@ -51384,11 +51456,12 @@
5138451456
HANDLE hMap; /* File handle from CreateFileMapping */
5138551457
void *pMap;
5138651458
} *aRegion;
5138751459
DWORD lastErrno; /* The Windows errno from the last I/O error */
5138851460
51389
- int nRef; /* Number of winShm objects pointing to this */
51461
+ winShm *pWinShmList; /* List of winShm objects with ptrs to this */
51462
+
5139051463
winShmNode *pNext; /* Next in list of all winShmNode objects */
5139151464
#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
5139251465
u8 nextShmId; /* Next available winShm.id value */
5139351466
#endif
5139451467
};
@@ -51412,10 +51485,11 @@
5141251485
HANDLE hShm; /* File-handle on *-shm file. For locking. */
5141351486
int bReadonly; /* True if hShm is opened read-only */
5141451487
#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
5141551488
u8 id; /* Id of this connection with its winShmNode */
5141651489
#endif
51490
+ winShm *pWinShmNext; /* Next winShm object on same winShmNode */
5141751491
};
5141851492
5141951493
/*
5142051494
** Constants used for locking
5142151495
*/
@@ -51425,11 +51499,11 @@
5142551499
/* Forward references to VFS methods */
5142651500
static int winOpen(sqlite3_vfs*,const char*,sqlite3_file*,int,int*);
5142751501
static int winDelete(sqlite3_vfs *,const char*,int);
5142851502
5142951503
/*
51430
-** Purge the winShmNodeList list of all entries with winShmNode.nRef==0.
51504
+** Purge the winShmNodeList list of all entries with winShmNode.pWinShmList==0.
5143151505
**
5143251506
** This is not a VFS shared-memory method; it is a utility function called
5143351507
** by VFS shared-memory methods.
5143451508
*/
5143551509
static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
@@ -51438,11 +51512,11 @@
5143851512
assert( winShmMutexHeld() );
5143951513
OSTRACE(("SHM-PURGE pid=%lu, deleteFlag=%d\n",
5144051514
osGetCurrentProcessId(), deleteFlag));
5144151515
pp = &winShmNodeList;
5144251516
while( (p = *pp)!=0 ){
51443
- if( p->nRef==0 ){
51517
+ if( p->pWinShmList==0 ){
5144451518
int i;
5144551519
if( p->mutex ){ sqlite3_mutex_free(p->mutex); }
5144651520
for(i=0; i<p->nRegion; i++){
5144751521
BOOL bRc = osUnmapViewOfFile(p->aRegion[i].pMap);
5144851522
OSTRACE(("SHM-PURGE-UNMAP pid=%lu, region=%d, rc=%s\n",
@@ -51602,10 +51676,64 @@
5160251676
*pbReadonly = bReadonly;
5160351677
*ph = h;
5160451678
return rc;
5160551679
}
5160651680
51681
+/*
51682
+** Close pDbFd's connection to shared-memory. Delete the underlying
51683
+** *-shm file if deleteFlag is true.
51684
+*/
51685
+static int winCloseSharedMemory(winFile *pDbFd, int deleteFlag){
51686
+ winShm *p; /* The connection to be closed */
51687
+ winShm **pp; /* Iterator for pShmNode->pWinShmList */
51688
+ winShmNode *pShmNode; /* The underlying shared-memory file */
51689
+
51690
+ p = pDbFd->pShm;
51691
+ if( p==0 ) return SQLITE_OK;
51692
+ if( p->hShm!=INVALID_HANDLE_VALUE ){
51693
+ osCloseHandle(p->hShm);
51694
+ }
51695
+
51696
+ winShmEnterMutex();
51697
+ pShmNode = p->pShmNode;
51698
+
51699
+ /* Remove this connection from the winShmNode.pWinShmList list */
51700
+ sqlite3_mutex_enter(pShmNode->mutex);
51701
+ for(pp=&pShmNode->pWinShmList; *pp!=p; pp=&(*pp)->pWinShmNext){}
51702
+ *pp = p->pWinShmNext;
51703
+ sqlite3_mutex_leave(pShmNode->mutex);
51704
+
51705
+ winShmPurge(pDbFd->pVfs, deleteFlag);
51706
+ winShmLeaveMutex();
51707
+
51708
+ /* Free the connection p */
51709
+ sqlite3_free(p);
51710
+ pDbFd->pShm = 0;
51711
+ return SQLITE_OK;
51712
+}
51713
+
51714
+/*
51715
+** testfixture builds may set this global variable to true via a
51716
+** Tcl interface. This forces the VFS to use the locking normally
51717
+** only used for UNC paths for all files.
51718
+*/
51719
+#ifdef SQLITE_TEST
51720
+SQLITE_API int sqlite3_win_test_unc_locking = 0;
51721
+#else
51722
+# define sqlite3_win_test_unc_locking 0
51723
+#endif
51724
+
51725
+/*
51726
+** Return true if the string passed as the only argument is likely
51727
+** to be a UNC path. In other words, if it starts with "\\".
51728
+*/
51729
+static int winIsUNCPath(const char *zFile){
51730
+ if( zFile[0]=='\\' && zFile[1]=='\\' ){
51731
+ return 1;
51732
+ }
51733
+ return sqlite3_win_test_unc_locking;
51734
+}
5160751735
5160851736
/*
5160951737
** Open the shared-memory area associated with database file pDbFd.
5161051738
*/
5161151739
static int winOpenSharedMemory(winFile *pDbFd){
@@ -51628,19 +51756,14 @@
5162851756
return SQLITE_IOERR_NOMEM_BKPT;
5162951757
}
5163051758
pNew->zFilename = (char*)&pNew[1];
5163151759
pNew->hSharedShm = INVALID_HANDLE_VALUE;
5163251760
pNew->isUnlocked = 1;
51761
+ pNew->bUseSharedLockHandle = winIsUNCPath(pDbFd->zPath);
5163351762
sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
5163451763
sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
5163551764
51636
- /* Open a file-handle on the *-shm file for this connection. This file-handle
51637
- ** is only used for locking. The mapping of the *-shm file is created using
51638
- ** the shared file handle in winShmNode.hSharedShm. */
51639
- p->bReadonly = sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0);
51640
- rc = winHandleOpen(pNew->zFilename, &p->bReadonly, &p->hShm);
51641
-
5164251765
/* Look to see if there is an existing winShmNode that can be used.
5164351766
** If no matching winShmNode currently exists, then create a new one. */
5164451767
winShmEnterMutex();
5164551768
for(pShmNode = winShmNodeList; pShmNode; pShmNode=pShmNode->pNext){
5164651769
/* TBD need to come up with better match here. Perhaps
@@ -51657,11 +51780,11 @@
5165751780
}
5165851781
5165951782
/* Open a file-handle to use for mappings, and for the DMS lock. */
5166051783
if( rc==SQLITE_OK ){
5166151784
HANDLE h = INVALID_HANDLE_VALUE;
51662
- pShmNode->isReadonly = p->bReadonly;
51785
+ pShmNode->isReadonly = sqlite3_uri_boolean(pDbFd->zPath,"readonly_shm",0);
5166351786
rc = winHandleOpen(pNew->zFilename, &pShmNode->isReadonly, &h);
5166451787
pShmNode->hSharedShm = h;
5166551788
}
5166651789
5166751790
/* If successful, link the new winShmNode into the global list. If an
@@ -51679,24 +51802,39 @@
5167951802
}
5168051803
5168151804
/* If no error has occurred, link the winShm object to the winShmNode and
5168251805
** the winShm to pDbFd. */
5168351806
if( rc==SQLITE_OK ){
51807
+ sqlite3_mutex_enter(pShmNode->mutex);
5168451808
p->pShmNode = pShmNode;
51685
- pShmNode->nRef++;
51809
+ p->pWinShmNext = pShmNode->pWinShmList;
51810
+ pShmNode->pWinShmList = p;
5168651811
#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
5168751812
p->id = pShmNode->nextShmId++;
5168851813
#endif
5168951814
pDbFd->pShm = p;
51815
+ sqlite3_mutex_leave(pShmNode->mutex);
5169051816
}else if( p ){
51691
- winHandleClose(p->hShm);
5169251817
sqlite3_free(p);
5169351818
}
5169451819
5169551820
assert( rc!=SQLITE_OK || pShmNode->isUnlocked==0 || pShmNode->nRegion==0 );
5169651821
winShmLeaveMutex();
5169751822
sqlite3_free(pNew);
51823
+
51824
+ /* Open a file-handle on the *-shm file for this connection. This file-handle
51825
+ ** is only used for locking. The mapping of the *-shm file is created using
51826
+ ** the shared file handle in winShmNode.hSharedShm. */
51827
+ if( rc==SQLITE_OK && pShmNode->bUseSharedLockHandle==0 ){
51828
+ p->bReadonly = sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0);
51829
+ rc = winHandleOpen(pShmNode->zFilename, &p->bReadonly, &p->hShm);
51830
+ if( rc!=SQLITE_OK ){
51831
+ assert( p->hShm==INVALID_HANDLE_VALUE );
51832
+ winCloseSharedMemory(pDbFd, 0);
51833
+ }
51834
+ }
51835
+
5169851836
return rc;
5169951837
}
5170051838
5170151839
/*
5170251840
** Close a connection to shared-memory. Delete the underlying
@@ -51704,37 +51842,11 @@
5170451842
*/
5170551843
static int winShmUnmap(
5170651844
sqlite3_file *fd, /* Database holding shared memory */
5170751845
int deleteFlag /* Delete after closing if true */
5170851846
){
51709
- winFile *pDbFd; /* Database holding shared-memory */
51710
- winShm *p; /* The connection to be closed */
51711
- winShmNode *pShmNode; /* The underlying shared-memory file */
51712
-
51713
- pDbFd = (winFile*)fd;
51714
- p = pDbFd->pShm;
51715
- if( p==0 ) return SQLITE_OK;
51716
- if( p->hShm!=INVALID_HANDLE_VALUE ){
51717
- osCloseHandle(p->hShm);
51718
- }
51719
-
51720
- pShmNode = p->pShmNode;
51721
- winShmEnterMutex();
51722
-
51723
- /* If pShmNode->nRef has reached 0, then close the underlying
51724
- ** shared-memory file, too. */
51725
- assert( pShmNode->nRef>0 );
51726
- pShmNode->nRef--;
51727
- if( pShmNode->nRef==0 ){
51728
- winShmPurge(pDbFd->pVfs, deleteFlag);
51729
- }
51730
- winShmLeaveMutex();
51731
-
51732
- /* Free the connection p */
51733
- sqlite3_free(p);
51734
- pDbFd->pShm = 0;
51735
- return SQLITE_OK;
51847
+ return winCloseSharedMemory((winFile*)fd, deleteFlag);
5173651848
}
5173751849
5173851850
/*
5173951851
** Change the lock state for a shared-memory segment.
5174051852
*/
@@ -51799,29 +51911,75 @@
5179951911
);
5180051912
if( ((flags & SQLITE_SHM_UNLOCK) && ((p->exclMask|p->sharedMask) & mask))
5180151913
|| (flags==(SQLITE_SHM_SHARED|SQLITE_SHM_LOCK) && 0==(p->sharedMask & mask))
5180251914
|| (flags==(SQLITE_SHM_EXCLUSIVE|SQLITE_SHM_LOCK))
5180351915
){
51916
+ HANDLE h = p->hShm;
5180451917
5180551918
if( flags & SQLITE_SHM_UNLOCK ){
5180651919
/* Case (a) - unlock. */
5180751920
5180851921
assert( (p->exclMask & p->sharedMask)==0 );
5180951922
assert( !(flags & SQLITE_SHM_EXCLUSIVE) || (p->exclMask & mask)==mask );
5181051923
assert( !(flags & SQLITE_SHM_SHARED) || (p->sharedMask & mask)==mask );
5181151924
51812
- rc = winHandleUnlock(p->hShm, ofst+WIN_SHM_BASE, n);
51925
+ assert( !(flags & SQLITE_SHM_SHARED) || n==1 );
51926
+ if( pShmNode->bUseSharedLockHandle ){
51927
+ h = pShmNode->hSharedShm;
51928
+ if( flags & SQLITE_SHM_SHARED ){
51929
+ winShm *pShm;
51930
+ sqlite3_mutex_enter(pShmNode->mutex);
51931
+ for(pShm=pShmNode->pWinShmList; pShm; pShm=pShm->pWinShmNext){
51932
+ if( pShm!=p && (pShm->sharedMask & mask) ){
51933
+ /* Another connection within this process is also holding this
51934
+ ** SHARED lock. So do not actually release the OS lock. */
51935
+ h = INVALID_HANDLE_VALUE;
51936
+ break;
51937
+ }
51938
+ }
51939
+ sqlite3_mutex_leave(pShmNode->mutex);
51940
+ }
51941
+ }
51942
+
51943
+ if( h!=INVALID_HANDLE_VALUE ){
51944
+ rc = winHandleUnlock(h, ofst+WIN_SHM_BASE, n);
51945
+ }
5181351946
5181451947
/* If successful, also clear the bits in sharedMask/exclMask */
5181551948
if( rc==SQLITE_OK ){
5181651949
p->exclMask = (p->exclMask & ~mask);
5181751950
p->sharedMask = (p->sharedMask & ~mask);
5181851951
}
5181951952
}else{
5182051953
int bExcl = ((flags & SQLITE_SHM_EXCLUSIVE) ? 1 : 0);
5182151954
DWORD nMs = winFileBusyTimeout(pDbFd);
51822
- rc = winHandleLockTimeout(p->hShm, ofst+WIN_SHM_BASE, n, bExcl, nMs);
51955
+
51956
+ if( pShmNode->bUseSharedLockHandle ){
51957
+ winShm *pShm;
51958
+ h = pShmNode->hSharedShm;
51959
+ sqlite3_mutex_enter(pShmNode->mutex);
51960
+ for(pShm=pShmNode->pWinShmList; pShm; pShm=pShm->pWinShmNext){
51961
+ if( bExcl ){
51962
+ if( (pShm->sharedMask|pShm->exclMask) & mask ){
51963
+ rc = SQLITE_BUSY;
51964
+ h = INVALID_HANDLE_VALUE;
51965
+ }
51966
+ }else{
51967
+ if( pShm->sharedMask & mask ){
51968
+ h = INVALID_HANDLE_VALUE;
51969
+ }else if( pShm->exclMask & mask ){
51970
+ rc = SQLITE_BUSY;
51971
+ h = INVALID_HANDLE_VALUE;
51972
+ }
51973
+ }
51974
+ }
51975
+ sqlite3_mutex_leave(pShmNode->mutex);
51976
+ }
51977
+
51978
+ if( h!=INVALID_HANDLE_VALUE ){
51979
+ rc = winHandleLockTimeout(h, ofst+WIN_SHM_BASE, n, bExcl, nMs);
51980
+ }
5182351981
if( rc==SQLITE_OK ){
5182451982
if( bExcl ){
5182551983
p->exclMask = (p->exclMask | mask);
5182651984
}else{
5182751985
p->sharedMask = (p->sharedMask | mask);
@@ -65748,11 +65906,11 @@
6574865906
*/
6574965907
sqlite3_exec(db, "PRAGMA table_list",0,0,0);
6575065908
}
6575165909
if( pPager->pWal ){
6575265910
rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode,
65753
- (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
65911
+ (eMode<=SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
6575465912
pPager->pBusyHandlerArg,
6575565913
pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
6575665914
pnLog, pnCkpt
6575765915
);
6575865916
}
@@ -70353,11 +70511,12 @@
7035370511
assert( pWal->ckptLock==0 );
7035470512
assert( pWal->writeLock==0 );
7035570513
7035670514
/* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
7035770515
** in the SQLITE_CHECKPOINT_PASSIVE mode. */
70358
- assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
70516
+ assert( SQLITE_CHECKPOINT_NOOP<SQLITE_CHECKPOINT_PASSIVE );
70517
+ assert( eMode>SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
7035970518
7036070519
if( pWal->readOnly ) return SQLITE_READONLY;
7036170520
WALTRACE(("WAL%p: checkpoint begins\n", pWal));
7036270521
7036370522
/* Enable blocking locks, if possible. */
@@ -70370,35 +70529,39 @@
7037070529
** checkpoint operation at the same time, the lock cannot be obtained and
7037170530
** SQLITE_BUSY is returned.
7037270531
** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured,
7037370532
** it will not be invoked in this case.
7037470533
*/
70375
- rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
70376
- testcase( rc==SQLITE_BUSY );
70377
- testcase( rc!=SQLITE_OK && xBusy2!=0 );
70378
- if( rc==SQLITE_OK ){
70379
- pWal->ckptLock = 1;
70380
-
70381
- /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and
70382
- ** TRUNCATE modes also obtain the exclusive "writer" lock on the database
70383
- ** file.
70384
- **
70385
- ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained
70386
- ** immediately, and a busy-handler is configured, it is invoked and the
70387
- ** writer lock retried until either the busy-handler returns 0 or the
70388
- ** lock is successfully obtained.
70389
- */
70390
- if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){
70391
- rc = walBusyLock(pWal, xBusy2, pBusyArg, WAL_WRITE_LOCK, 1);
70392
- if( rc==SQLITE_OK ){
70393
- pWal->writeLock = 1;
70394
- }else if( rc==SQLITE_BUSY ){
70395
- eMode2 = SQLITE_CHECKPOINT_PASSIVE;
70396
- xBusy2 = 0;
70397
- rc = SQLITE_OK;
70398
- }
70399
- }
70534
+ if( eMode!=SQLITE_CHECKPOINT_NOOP ){
70535
+ rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
70536
+ testcase( rc==SQLITE_BUSY );
70537
+ testcase( rc!=SQLITE_OK && xBusy2!=0 );
70538
+ if( rc==SQLITE_OK ){
70539
+ pWal->ckptLock = 1;
70540
+
70541
+ /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART
70542
+ ** and TRUNCATE modes also obtain the exclusive "writer" lock on the
70543
+ ** database file.
70544
+ **
70545
+ ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained
70546
+ ** immediately, and a busy-handler is configured, it is invoked and the
70547
+ ** writer lock retried until either the busy-handler returns 0 or the
70548
+ ** lock is successfully obtained.
70549
+ */
70550
+ if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){
70551
+ rc = walBusyLock(pWal, xBusy2, pBusyArg, WAL_WRITE_LOCK, 1);
70552
+ if( rc==SQLITE_OK ){
70553
+ pWal->writeLock = 1;
70554
+ }else if( rc==SQLITE_BUSY ){
70555
+ eMode2 = SQLITE_CHECKPOINT_PASSIVE;
70556
+ xBusy2 = 0;
70557
+ rc = SQLITE_OK;
70558
+ }
70559
+ }
70560
+ }
70561
+ }else{
70562
+ rc = SQLITE_OK;
7040070563
}
7040170564
7040270565
7040370566
/* Read the wal-index header. */
7040470567
SEH_TRY {
@@ -70408,21 +70571,21 @@
7040870571
** or invoke the busy handler. The only lock such a checkpoint may
7040970572
** attempt to obtain is a lock on a read-slot, and it should give up
7041070573
** immediately and do a partial checkpoint if it cannot obtain it. */
7041170574
walDisableBlocking(pWal);
7041270575
rc = walIndexReadHdr(pWal, &isChanged);
70413
- if( eMode2!=SQLITE_CHECKPOINT_PASSIVE ) (void)walEnableBlocking(pWal);
70576
+ if( eMode2>SQLITE_CHECKPOINT_PASSIVE ) (void)walEnableBlocking(pWal);
7041470577
if( isChanged && pWal->pDbFd->pMethods->iVersion>=3 ){
7041570578
sqlite3OsUnfetch(pWal->pDbFd, 0, 0);
7041670579
}
7041770580
}
7041870581
7041970582
/* Copy data from the log to the database file. */
7042070583
if( rc==SQLITE_OK ){
7042170584
if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){
7042270585
rc = SQLITE_CORRUPT_BKPT;
70423
- }else{
70586
+ }else if( eMode2!=SQLITE_CHECKPOINT_NOOP ){
7042470587
rc = walCheckpoint(pWal, db, eMode2, xBusy2, pBusyArg, sync_flags,zBuf);
7042570588
}
7042670589
7042770590
/* If no error occurred, set the output variables. */
7042870591
if( rc==SQLITE_OK || rc==SQLITE_BUSY ){
@@ -91645,11 +91808,11 @@
9164591808
9164691809
preupdate.v = v;
9164791810
preupdate.pCsr = pCsr;
9164891811
preupdate.op = op;
9164991812
preupdate.iNewReg = iReg;
91650
- preupdate.pKeyinfo = (KeyInfo*)&preupdate.keyinfoSpace;
91813
+ preupdate.pKeyinfo = &preupdate.uKey.sKey;
9165191814
preupdate.pKeyinfo->db = db;
9165291815
preupdate.pKeyinfo->enc = ENC(db);
9165391816
preupdate.pKeyinfo->nKeyField = pTab->nCol;
9165491817
preupdate.pKeyinfo->aSortFlags = 0; /* Indicate .aColl, .nAllField uninit */
9165591818
preupdate.iKey1 = iKey1;
@@ -102528,10 +102691,11 @@
102528102691
aRes[1] = aRes[2] = -1;
102529102692
assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
102530102693
|| pOp->p2==SQLITE_CHECKPOINT_FULL
102531102694
|| pOp->p2==SQLITE_CHECKPOINT_RESTART
102532102695
|| pOp->p2==SQLITE_CHECKPOINT_TRUNCATE
102696
+ || pOp->p2==SQLITE_CHECKPOINT_NOOP
102533102697
);
102534102698
rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
102535102699
if( rc ){
102536102700
if( rc!=SQLITE_BUSY ) goto abort_due_to_error;
102537102701
rc = SQLITE_OK;
@@ -110651,18 +110815,21 @@
110651110815
ExprList *pList /* Expression list to resolve. May be NULL. */
110652110816
){
110653110817
SrcList *pSrc; /* Fake SrcList for pParse->pNewTable */
110654110818
NameContext sNC; /* Name context for pParse->pNewTable */
110655110819
int rc;
110656
- u8 srcSpace[SZ_SRCLIST_1]; /* Memory space for the fake SrcList */
110820
+ union {
110821
+ SrcList sSrc;
110822
+ u8 srcSpace[SZ_SRCLIST_1]; /* Memory space for the fake SrcList */
110823
+ } uSrc;
110657110824
110658110825
assert( type==0 || pTab!=0 );
110659110826
assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr
110660110827
|| type==NC_GenCol || pTab==0 );
110661110828
memset(&sNC, 0, sizeof(sNC));
110662
- pSrc = (SrcList*)srcSpace;
110663
- memset(pSrc, 0, SZ_SRCLIST_1);
110829
+ memset(&uSrc, 0, sizeof(uSrc));
110830
+ pSrc = &uSrc.sSrc;
110664110831
if( pTab ){
110665110832
pSrc->nSrc = 1;
110666110833
pSrc->a[0].zName = pTab->zName;
110667110834
pSrc->a[0].pSTab = pTab;
110668110835
pSrc->a[0].iCursor = -1;
@@ -111920,10 +112087,15 @@
111920112087
}
111921112088
if( IsWindowFunc(pExpr) ){
111922112089
sqlite3ExprOrderByAggregateError(pParse, pExpr);
111923112090
sqlite3ExprListDelete(db, pOrderBy);
111924112091
return;
112092
+ }
112093
+ if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
112094
+ sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
112095
+ sqlite3ExprListDelete(db, pOrderBy);
112096
+ return;
111925112097
}
111926112098
111927112099
pOB = sqlite3ExprAlloc(db, TK_ORDER, 0, 0);
111928112100
if( pOB==0 ){
111929112101
sqlite3ExprListDelete(db, pOrderBy);
@@ -114683,11 +114855,10 @@
114683114855
int destIfNull /* Jump here if the results are unknown due to NULLs */
114684114856
){
114685114857
int rRhsHasNull = 0; /* Register that is true if RHS contains NULL values */
114686114858
int eType; /* Type of the RHS */
114687114859
int rLhs; /* Register(s) holding the LHS values */
114688
- int rLhsOrig; /* LHS values prior to reordering by aiMap[] */
114689114860
Vdbe *v; /* Statement under construction */
114690114861
int *aiMap = 0; /* Map from vector field to index column */
114691114862
char *zAff = 0; /* Affinity string for comparisons */
114692114863
int nVector; /* Size of vectors for this IN operator */
114693114864
int iDummy; /* Dummy parameter to exprCodeVector() */
@@ -114746,23 +114917,12 @@
114746114917
** Avoid factoring the LHS of the IN(...) expression out of the loop,
114747114918
** even if it is constant, as OP_Affinity may be used on the register
114748114919
** by code generated below. */
114749114920
assert( pParse->okConstFactor==okConstFactor );
114750114921
pParse->okConstFactor = 0;
114751
- rLhsOrig = exprCodeVector(pParse, pLeft, &iDummy);
114922
+ rLhs = exprCodeVector(pParse, pLeft, &iDummy);
114752114923
pParse->okConstFactor = okConstFactor;
114753
- for(i=0; i<nVector && aiMap[i]==i; i++){} /* Are LHS fields reordered? */
114754
- if( i==nVector ){
114755
- /* LHS fields are not reordered */
114756
- rLhs = rLhsOrig;
114757
- }else{
114758
- /* Need to reorder the LHS fields according to aiMap */
114759
- rLhs = sqlite3GetTempRange(pParse, nVector);
114760
- for(i=0; i<nVector; i++){
114761
- sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0);
114762
- }
114763
- }
114764114924
114765114925
/* If sqlite3FindInIndex() did not find or create an index that is
114766114926
** suitable for evaluating the IN operator, then evaluate using a
114767114927
** sequence of comparisons.
114768114928
**
@@ -114773,10 +114933,11 @@
114773114933
CollSeq *pColl;
114774114934
int labelOk = sqlite3VdbeMakeLabel(pParse);
114775114935
int r2, regToFree;
114776114936
int regCkNull = 0;
114777114937
int ii;
114938
+ assert( nVector==1 );
114778114939
assert( ExprUseXList(pExpr) );
114779114940
pList = pExpr->x.pList;
114780114941
pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
114781114942
if( destIfNull!=destIfFalse ){
114782114943
regCkNull = sqlite3GetTempReg(pParse);
@@ -114813,10 +114974,30 @@
114813114974
}
114814114975
sqlite3VdbeResolveLabel(v, labelOk);
114815114976
sqlite3ReleaseTempReg(pParse, regCkNull);
114816114977
goto sqlite3ExprCodeIN_finished;
114817114978
}
114979
+
114980
+ if( eType!=IN_INDEX_ROWID ){
114981
+ /* If this IN operator will use an index, then the order of columns in the
114982
+ ** vector might be different from the order in the index. In that case,
114983
+ ** we need to reorder the LHS values to be in index order. Run Affinity
114984
+ ** before reordering the columns, so that the affinity is correct.
114985
+ */
114986
+ sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
114987
+ for(i=0; i<nVector && aiMap[i]==i; i++){} /* Are LHS fields reordered? */
114988
+ if( i!=nVector ){
114989
+ /* Need to reorder the LHS fields according to aiMap */
114990
+ int rLhsOrig = rLhs;
114991
+ rLhs = sqlite3GetTempRange(pParse, nVector);
114992
+ for(i=0; i<nVector; i++){
114993
+ sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0);
114994
+ }
114995
+ sqlite3ReleaseTempReg(pParse, rLhsOrig);
114996
+ }
114997
+ }
114998
+
114818114999
114819115000
/* Step 2: Check to see if the LHS contains any NULL columns. If the
114820115001
** LHS does contain NULLs then the result must be either FALSE or NULL.
114821115002
** We will then skip the binary search of the RHS.
114822115003
*/
@@ -114840,15 +115021,15 @@
114840115021
*/
114841115022
if( eType==IN_INDEX_ROWID ){
114842115023
/* In this case, the RHS is the ROWID of table b-tree and so we also
114843115024
** know that the RHS is non-NULL. Hence, we combine steps 3 and 4
114844115025
** into a single opcode. */
115026
+ assert( nVector==1 );
114845115027
sqlite3VdbeAddOp3(v, OP_SeekRowid, iTab, destIfFalse, rLhs);
114846115028
VdbeCoverage(v);
114847115029
addrTruthOp = sqlite3VdbeAddOp0(v, OP_Goto); /* Return True */
114848115030
}else{
114849
- sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
114850115031
if( destIfFalse==destIfNull ){
114851115032
/* Combine Step 3 and Step 5 into a single opcode */
114852115033
if( ExprHasProperty(pExpr, EP_Subrtn) ){
114853115034
const VdbeOp *pOp = sqlite3VdbeGetOp(v, pExpr->y.sub.iAddr);
114854115035
assert( pOp->opcode==OP_Once || pParse->nErr );
@@ -114922,11 +115103,10 @@
114922115103
114923115104
/* Jumps here in order to return true. */
114924115105
sqlite3VdbeJumpHere(v, addrTruthOp);
114925115106
114926115107
sqlite3ExprCodeIN_finished:
114927
- if( rLhs!=rLhsOrig ) sqlite3ReleaseTempReg(pParse, rLhs);
114928115108
VdbeComment((v, "end IN expr"));
114929115109
sqlite3ExprCodeIN_oom_error:
114930115110
sqlite3DbFree(pParse->db, aiMap);
114931115111
sqlite3DbFree(pParse->db, zAff);
114932115112
}
@@ -124573,11 +124753,11 @@
124573124753
*/
124574124754
SQLITE_PRIVATE int sqlite3TableColumnToIndex(Index *pIdx, int iCol){
124575124755
int i;
124576124756
i16 iCol16;
124577124757
assert( iCol>=(-1) && iCol<=SQLITE_MAX_COLUMN );
124578
- assert( pIdx->nColumn<=SQLITE_MAX_COLUMN+1 );
124758
+ assert( pIdx->nColumn<=SQLITE_MAX_COLUMN*2 );
124579124759
iCol16 = iCol;
124580124760
for(i=0; i<pIdx->nColumn; i++){
124581124761
if( iCol16==pIdx->aiColumn[i] ){
124582124762
return i;
124583124763
}
@@ -129165,18 +129345,23 @@
129165129345
pKey->aSortFlags[i] = pIdx->aSortOrder[i];
129166129346
assert( 0==(pKey->aSortFlags[i] & KEYINFO_ORDER_BIGNULL) );
129167129347
}
129168129348
if( pParse->nErr ){
129169129349
assert( pParse->rc==SQLITE_ERROR_MISSING_COLLSEQ );
129170
- if( pIdx->bNoQuery==0 ){
129350
+ if( pIdx->bNoQuery==0
129351
+ && sqlite3HashFind(&pIdx->pSchema->idxHash, pIdx->zName)
129352
+ ){
129171129353
/* Deactivate the index because it contains an unknown collating
129172129354
** sequence. The only way to reactive the index is to reload the
129173129355
** schema. Adding the missing collating sequence later does not
129174129356
** reactive the index. The application had the chance to register
129175129357
** the missing index using the collation-needed callback. For
129176129358
** simplicity, SQLite will not give the application a second chance.
129177
- */
129359
+ **
129360
+ ** Except, do not do this if the index is not in the schema hash
129361
+ ** table. In this case the index is currently being constructed
129362
+ ** by a CREATE INDEX statement, and retrying will not help. */
129178129363
pIdx->bNoQuery = 1;
129179129364
pParse->rc = SQLITE_ERROR_RETRY;
129180129365
}
129181129366
sqlite3KeyInfoUnref(pKey);
129182129367
pKey = 0;
@@ -143548,10 +143733,12 @@
143548143733
eMode = SQLITE_CHECKPOINT_FULL;
143549143734
}else if( sqlite3StrICmp(zRight, "restart")==0 ){
143550143735
eMode = SQLITE_CHECKPOINT_RESTART;
143551143736
}else if( sqlite3StrICmp(zRight, "truncate")==0 ){
143552143737
eMode = SQLITE_CHECKPOINT_TRUNCATE;
143738
+ }else if( sqlite3StrICmp(zRight, "noop")==0 ){
143739
+ eMode = SQLITE_CHECKPOINT_NOOP;
143553143740
}
143554143741
}
143555143742
pParse->nMem = 3;
143556143743
sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
143557143744
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
@@ -145114,13 +145301,15 @@
145114145301
** or encounters a permanent error. A schema problem after one schema
145115145302
** reset is considered a permanent error. */
145116145303
rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
145117145304
assert( rc==SQLITE_OK || *ppStmt==0 );
145118145305
if( rc==SQLITE_OK || db->mallocFailed ) break;
145119
- }while( (rc==SQLITE_ERROR_RETRY && (cnt++)<SQLITE_MAX_PREPARE_RETRY)
145120
- || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
145306
+ cnt++;
145307
+ }while( (rc==SQLITE_ERROR_RETRY && ALWAYS(cnt<=SQLITE_MAX_PREPARE_RETRY))
145308
+ || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt)==1) );
145121145309
sqlite3BtreeLeaveAll(db);
145310
+ assert( rc!=SQLITE_ERROR_RETRY );
145122145311
rc = sqlite3ApiExit(db, rc);
145123145312
assert( (rc&db->errMask)==rc );
145124145313
db->busyHandler.nBusy = 0;
145125145314
sqlite3_mutex_leave(db->mutex);
145126145315
assert( rc==SQLITE_OK || (*ppStmt)==0 );
@@ -145790,12 +145979,11 @@
145790145979
while( p ){
145791145980
ExprSetProperty(p, joinFlag);
145792145981
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
145793145982
ExprSetVVAProperty(p, EP_NoReduce);
145794145983
p->w.iJoin = iTable;
145795
- if( p->op==TK_FUNCTION ){
145796
- assert( ExprUseXList(p) );
145984
+ if( ExprUseXList(p) ){
145797145985
if( p->x.pList ){
145798145986
int i;
145799145987
for(i=0; i<p->x.pList->nExpr; i++){
145800145988
sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable, joinFlag);
145801145989
}
@@ -146007,10 +146195,11 @@
146007146195
else if( pRight->u3.pOn ){
146008146196
sqlite3SetJoinExpr(pRight->u3.pOn, pRight->iCursor, joinType);
146009146197
p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->u3.pOn);
146010146198
pRight->u3.pOn = 0;
146011146199
pRight->fg.isOn = 1;
146200
+ p->selFlags |= SF_OnToWhere;
146012146201
}
146013146202
}
146014146203
return 0;
146015146204
}
146016146205
@@ -146893,11 +147082,14 @@
146893147082
** Allocate a KeyInfo object sufficient for an index of N key columns and
146894147083
** X extra columns.
146895147084
*/
146896147085
SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
146897147086
int nExtra = (N+X)*(sizeof(CollSeq*)+1);
146898
- KeyInfo *p = sqlite3DbMallocRawNN(db, SZ_KEYINFO(0) + nExtra);
147087
+ KeyInfo *p;
147088
+ assert( X>=0 );
147089
+ if( NEVER(N+X>0xffff) ) return (KeyInfo*)sqlite3OomFault(db);
147090
+ p = sqlite3DbMallocRawNN(db, SZ_KEYINFO(0) + nExtra);
146899147091
if( p ){
146900147092
p->aSortFlags = (u8*)&p->aColl[N+X];
146901147093
p->nKeyField = (u16)N;
146902147094
p->nAllField = (u16)(N+X);
146903147095
p->enc = ENC(db);
@@ -149212,11 +149404,11 @@
149212149404
** expressions in pEList.
149213149405
**
149214149406
** ## About "isOuterJoin":
149215149407
**
149216149408
** The isOuterJoin column indicates that the replacement will occur into a
149217
-** position in the parent that NULL-able due to an OUTER JOIN. Either the
149409
+** position in the parent that is NULL-able due to an OUTER JOIN. Either the
149218149410
** target slot in the parent is the right operand of a LEFT JOIN, or one of
149219149411
** the left operands of a RIGHT JOIN. In either case, we need to potentially
149220149412
** bypass the substituted expression with OP_IfNullRow.
149221149413
**
149222149414
** Suppose the original expression is an integer constant. Even though the table
@@ -150050,21 +150242,16 @@
150050150242
** elements we are now copying in.
150051150243
*/
150052150244
pSub = pSub1;
150053150245
for(pParent=p; pParent; pParent=pParent->pPrior, pSub=pSub->pPrior){
150054150246
int nSubSrc;
150055
- u8 jointype = 0;
150056
- u8 ltorj = pSrc->a[iFrom].fg.jointype & JT_LTORJ;
150247
+ u8 jointype = pSubitem->fg.jointype;
150057150248
assert( pSub!=0 );
150058150249
pSubSrc = pSub->pSrc; /* FROM clause of subquery */
150059150250
nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
150060150251
pSrc = pParent->pSrc; /* FROM clause of the outer query */
150061150252
150062
- if( pParent==p ){
150063
- jointype = pSubitem->fg.jointype; /* First time through the loop */
150064
- }
150065
-
150066150253
/* The subquery uses a single slot of the FROM clause of the outer
150067150254
** query. If the subquery has more than one element in its FROM clause,
150068150255
** then expand the outer query to make space for it to hold all elements
150069150256
** of the subquery.
150070150257
**
@@ -150080,10 +150267,11 @@
150080150267
*/
150081150268
if( nSubSrc>1 ){
150082150269
pSrc = sqlite3SrcListEnlarge(pParse, pSrc, nSubSrc-1,iFrom+1);
150083150270
if( pSrc==0 ) break;
150084150271
pParent->pSrc = pSrc;
150272
+ pSubitem = &pSrc->a[iFrom];
150085150273
}
150086150274
150087150275
/* Transfer the FROM clause terms from the subquery into the
150088150276
** outer query.
150089150277
*/
@@ -150094,15 +150282,14 @@
150094150282
assert( pItem->fg.isSubquery
150095150283
|| pItem->fg.fixedSchema
150096150284
|| pItem->u4.zDatabase==0 );
150097150285
if( pItem->fg.isUsing ) sqlite3IdListDelete(db, pItem->u3.pUsing);
150098150286
*pItem = pSubSrc->a[i];
150099
- pItem->fg.jointype |= ltorj;
150287
+ pItem->fg.jointype |= (jointype & JT_LTORJ);
150100150288
memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
150101150289
}
150102
- pSrc->a[iFrom].fg.jointype &= JT_LTORJ;
150103
- pSrc->a[iFrom].fg.jointype |= jointype | ltorj;
150290
+ pSubitem->fg.jointype |= jointype;
150104150291
150105150292
/* Now begin substituting subquery result set expressions for
150106150293
** references to the iParent in the outer query.
150107150294
**
150108150295
** Example:
@@ -152838,10 +153025,119 @@
152838153025
existsToJoin(pParse, p, pSubWhere);
152839153026
}
152840153027
}
152841153028
}
152842153029
}
153030
+
153031
+/*
153032
+** Type used for Walker callbacks by selectCheckOnClauses().
153033
+*/
153034
+typedef struct CheckOnCtx CheckOnCtx;
153035
+struct CheckOnCtx {
153036
+ SrcList *pSrc; /* SrcList for this context */
153037
+ int iJoin; /* Cursor numbers must be =< than this */
153038
+ CheckOnCtx *pParent; /* Parent context */
153039
+};
153040
+
153041
+/*
153042
+** True if the SrcList passed as the only argument contains at least
153043
+** one RIGHT or FULL JOIN. False otherwise.
153044
+*/
153045
+#define hasRightJoin(pSrc) (((pSrc)->a[0].fg.jointype & JT_LTORJ)!=0)
153046
+
153047
+/*
153048
+** The xExpr callback for the search of invalid ON clause terms.
153049
+*/
153050
+static int selectCheckOnClausesExpr(Walker *pWalker, Expr *pExpr){
153051
+ CheckOnCtx *pCtx = pWalker->u.pCheckOnCtx;
153052
+
153053
+ /* Check if pExpr is root or near-root of an ON clause constraint that needs
153054
+ ** to be checked to ensure that it does not refer to tables in its FROM
153055
+ ** clause to the right of itself. i.e. it is either:
153056
+ **
153057
+ ** + an ON clause on an OUTER join, or
153058
+ ** + an ON clause on an INNER join within a FROM that features at
153059
+ ** least one RIGHT or FULL join.
153060
+ */
153061
+ if( (ExprHasProperty(pExpr, EP_OuterON))
153062
+ || (ExprHasProperty(pExpr, EP_InnerON) && hasRightJoin(pCtx->pSrc))
153063
+ ){
153064
+ /* If CheckOnCtx.iJoin is already set, then fall through and process
153065
+ ** this expression node as normal. Or, if CheckOnCtx.iJoin is still 0,
153066
+ ** set it to the cursor number of the RHS of the join to which this
153067
+ ** ON expression was attached and then iterate through the entire
153068
+ ** expression. */
153069
+ assert( pCtx->iJoin==0 || pCtx->iJoin==pExpr->w.iJoin );
153070
+ if( pCtx->iJoin==0 ){
153071
+ pCtx->iJoin = pExpr->w.iJoin;
153072
+ sqlite3WalkExprNN(pWalker, pExpr);
153073
+ pCtx->iJoin = 0;
153074
+ return WRC_Prune;
153075
+ }
153076
+ }
153077
+
153078
+ if( pExpr->op==TK_COLUMN ){
153079
+ /* A column expression. Find the SrcList (if any) to which it refers.
153080
+ ** Then, if CheckOnCtx.iJoin indicates that this expression is part of an
153081
+ ** ON clause from that SrcList (i.e. if iJoin is non-zero), check that it
153082
+ ** does not refer to a table to the right of CheckOnCtx.iJoin. */
153083
+ do {
153084
+ SrcList *pSrc = pCtx->pSrc;
153085
+ int iTab = pExpr->iTable;
153086
+ if( iTab>=pSrc->a[0].iCursor && iTab<=pSrc->a[pSrc->nSrc-1].iCursor ){
153087
+ if( pCtx->iJoin && iTab>pCtx->iJoin ){
153088
+ sqlite3ErrorMsg(pWalker->pParse,
153089
+ "ON clause references tables to its right");
153090
+ return WRC_Abort;
153091
+ }
153092
+ break;
153093
+ }
153094
+ pCtx = pCtx->pParent;
153095
+ }while( pCtx );
153096
+ }
153097
+ return WRC_Continue;
153098
+}
153099
+
153100
+/*
153101
+** The xSelect callback for the search of invalid ON clause terms.
153102
+*/
153103
+static int selectCheckOnClausesSelect(Walker *pWalker, Select *pSelect){
153104
+ CheckOnCtx *pCtx = pWalker->u.pCheckOnCtx;
153105
+ if( pSelect->pSrc==pCtx->pSrc || pSelect->pSrc->nSrc==0 ){
153106
+ return WRC_Continue;
153107
+ }else{
153108
+ CheckOnCtx sCtx;
153109
+ memset(&sCtx, 0, sizeof(sCtx));
153110
+ sCtx.pSrc = pSelect->pSrc;
153111
+ sCtx.pParent = pCtx;
153112
+ pWalker->u.pCheckOnCtx = &sCtx;
153113
+ sqlite3WalkSelect(pWalker, pSelect);
153114
+ pWalker->u.pCheckOnCtx = pCtx;
153115
+ pSelect->selFlags &= ~SF_OnToWhere;
153116
+ return WRC_Prune;
153117
+ }
153118
+}
153119
+
153120
+/*
153121
+** Check all ON clauses in pSelect to verify that they do not reference
153122
+** columns to the right.
153123
+*/
153124
+static void selectCheckOnClauses(Parse *pParse, Select *pSelect){
153125
+ Walker w;
153126
+ CheckOnCtx sCtx;
153127
+ assert( pSelect->selFlags & SF_OnToWhere );
153128
+ assert( pSelect->pSrc!=0 && pSelect->pSrc->nSrc>=2 );
153129
+ memset(&w, 0, sizeof(w));
153130
+ w.pParse = pParse;
153131
+ w.xExprCallback = selectCheckOnClausesExpr;
153132
+ w.xSelectCallback = selectCheckOnClausesSelect;
153133
+ w.u.pCheckOnCtx = &sCtx;
153134
+ memset(&sCtx, 0, sizeof(sCtx));
153135
+ sCtx.pSrc = pSelect->pSrc;
153136
+ sqlite3WalkExprNN(&w, pSelect->pWhere);
153137
+ pSelect->selFlags &= ~SF_OnToWhere;
153138
+}
152843153139
152844153140
/*
152845153141
** Generate byte-code for the SELECT statement given in the p argument.
152846153142
**
152847153143
** The results are returned according to the SelectDest structure.
@@ -152965,10 +153261,22 @@
152965153261
if( sqlite3TreeTrace & 0x10 ){
152966153262
TREETRACE(0x10,pParse,p, ("after name resolution:\n"));
152967153263
sqlite3TreeViewSelect(0, p, 0);
152968153264
}
152969153265
#endif
153266
+
153267
+ /* If the SELECT statement contains ON clauses that were moved into
153268
+ ** the WHERE clause, go through and verify that none of the terms
153269
+ ** in the ON clauses reference tables to the right of the ON clause.
153270
+ ** Do this now, after name resolution, but before query flattening
153271
+ */
153272
+ if( p->selFlags & SF_OnToWhere ){
153273
+ selectCheckOnClauses(pParse, p);
153274
+ if( pParse->nErr ){
153275
+ goto select_end;
153276
+ }
153277
+ }
152970153278
152971153279
/* If the SF_UFSrcCheck flag is set, then this function is being called
152972153280
** as part of populating the temp table for an UPDATE...FROM statement.
152973153281
** In this case, it is an error if the target object (pSrc->a[0]) name
152974153282
** or alias is duplicated within FROM clause (pSrc->a[1..n]).
@@ -155531,11 +155839,14 @@
155531155839
sqlite3 *db = pParse->db;
155532155840
ExprList *pNew;
155533155841
Returning *pReturning;
155534155842
Select sSelect;
155535155843
SrcList *pFrom;
155536
- u8 fromSpace[SZ_SRCLIST_1];
155844
+ union {
155845
+ SrcList sSrc;
155846
+ u8 fromSpace[SZ_SRCLIST_1];
155847
+ } uSrc;
155537155848
155538155849
assert( v!=0 );
155539155850
if( !pParse->bReturning ){
155540155851
/* This RETURNING trigger must be for a different statement as
155541155852
** this statement lacks a RETURNING clause. */
@@ -155547,12 +155858,12 @@
155547155858
if( pTrigger != &(pReturning->retTrig) ){
155548155859
/* This RETURNING trigger is for a different statement */
155549155860
return;
155550155861
}
155551155862
memset(&sSelect, 0, sizeof(sSelect));
155552
- pFrom = (SrcList*)fromSpace;
155553
- memset(pFrom, 0, SZ_SRCLIST_1);
155863
+ memset(&uSrc, 0, sizeof(uSrc));
155864
+ pFrom = &uSrc.sSrc;
155554155865
sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
155555155866
sSelect.pSrc = pFrom;
155556155867
pFrom->nSrc = 1;
155557155868
pFrom->a[0].pSTab = pTab;
155558155869
pFrom->a[0].zName = pTab->zName; /* tag-20240424-1 */
@@ -163079,11 +163390,14 @@
163079163390
WhereClause *pWC = &pWInfo->sWC;
163080163391
WhereInfo *pSubWInfo;
163081163392
WhereLoop *pLoop = pLevel->pWLoop;
163082163393
SrcItem *pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
163083163394
SrcList *pFrom;
163084
- u8 fromSpace[SZ_SRCLIST_1];
163395
+ union {
163396
+ SrcList sSrc;
163397
+ u8 fromSpace[SZ_SRCLIST_1];
163398
+ } uSrc;
163085163399
Bitmask mAll = 0;
163086163400
int k;
163087163401
163088163402
ExplainQueryPlan((pParse, 1, "RIGHT-JOIN %s", pTabItem->pSTab->zName));
163089163403
sqlite3VdbeNoJumpsOutsideSubrtn(v, pRJ->addrSubrtn, pRJ->endSubrtn,
@@ -163123,11 +163437,11 @@
163123163437
if( ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON) ) continue;
163124163438
pSubWhere = sqlite3ExprAnd(pParse, pSubWhere,
163125163439
sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
163126163440
}
163127163441
}
163128
- pFrom = (SrcList*)fromSpace;
163442
+ pFrom = &uSrc.sSrc;
163129163443
pFrom->nSrc = 1;
163130163444
pFrom->nAlloc = 1;
163131163445
memcpy(&pFrom->a[0], pTabItem, sizeof(SrcItem));
163132163446
pFrom->a[0].fg.jointype = 0;
163133163447
assert( pParse->withinRJSubrtn < 100 );
@@ -164340,25 +164654,11 @@
164340164654
Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iJoin);
164341164655
if( ExprHasProperty(pExpr, EP_OuterON) ){
164342164656
prereqAll |= x;
164343164657
extraRight = x-1; /* ON clause terms may not be used with an index
164344164658
** on left table of a LEFT JOIN. Ticket #3015 */
164345
- if( (prereqAll>>1)>=x ){
164346
- sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
164347
- return;
164348
- }
164349164659
}else if( (prereqAll>>1)>=x ){
164350
- /* The ON clause of an INNER JOIN references a table to its right.
164351
- ** Most other SQL database engines raise an error. But SQLite versions
164352
- ** 3.0 through 3.38 just put the ON clause constraint into the WHERE
164353
- ** clause and carried on. Beginning with 3.39, raise an error only
164354
- ** if there is a RIGHT or FULL JOIN in the query. This makes SQLite
164355
- ** more like other systems, and also preserves legacy. */
164356
- if( ALWAYS(pSrc->nSrc>0) && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
164357
- sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
164358
- return;
164359
- }
164360164660
ExprClearProperty(pExpr, EP_InnerON);
164361164661
}
164362164662
}
164363164663
pTerm->prereqAll = prereqAll;
164364164664
pTerm->leftCursor = -1;
@@ -184839,10 +185139,13 @@
184839185139
for(i=0; i<2 && zName==0; i++, rc &= 0xff){
184840185140
switch( rc ){
184841185141
case SQLITE_OK: zName = "SQLITE_OK"; break;
184842185142
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
184843185143
case SQLITE_ERROR_SNAPSHOT: zName = "SQLITE_ERROR_SNAPSHOT"; break;
185144
+ case SQLITE_ERROR_RETRY: zName = "SQLITE_ERROR_RETRY"; break;
185145
+ case SQLITE_ERROR_MISSING_COLLSEQ:
185146
+ zName = "SQLITE_ERROR_MISSING_COLLSEQ"; break;
184844185147
case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
184845185148
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
184846185149
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
184847185150
case SQLITE_ABORT_ROLLBACK: zName = "SQLITE_ABORT_ROLLBACK"; break;
184848185151
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
@@ -189087,21 +189390,24 @@
189087189390
**
189088189391
*/
189089189392
#ifndef _FTSINT_H
189090189393
#define _FTSINT_H
189091189394
189395
+/*
189396
+** Activate assert() only if SQLITE_TEST is enabled.
189397
+*/
189398
+#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
189399
+# define NDEBUG 1
189400
+#endif
189401
+
189092189402
/* #include <assert.h> */
189093189403
/* #include <stdlib.h> */
189094189404
/* #include <stddef.h> */
189095189405
/* #include <stdio.h> */
189096189406
/* #include <string.h> */
189097189407
/* #include <stdarg.h> */
189098189408
189099
-#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
189100
-# define NDEBUG 1
189101
-#endif
189102
-
189103189409
/* FTS3/FTS4 require virtual tables */
189104189410
#ifdef SQLITE_OMIT_VIRTUALTABLE
189105189411
# undef SQLITE_ENABLE_FTS3
189106189412
# undef SQLITE_ENABLE_FTS4
189107189413
#endif
@@ -189540,17 +189846,10 @@
189540189846
/*
189541189847
** Macro used to suppress compiler warnings for unused parameters.
189542189848
*/
189543189849
#define UNUSED_PARAMETER(x) (void)(x)
189544189850
189545
-/*
189546
-** Activate assert() only if SQLITE_TEST is enabled.
189547
-*/
189548
-#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
189549
-# define NDEBUG 1
189550
-#endif
189551
-
189552189851
/*
189553189852
** The TESTONLY macro is used to enclose variable declarations or
189554189853
** other bits of code that are needed to support the arguments
189555189854
** within testcase() and assert() macros.
189556189855
*/
@@ -203821,12 +204120,12 @@
203821204120
/*
203822204121
** An object of this type contains the state required to create or append
203823204122
** to an appendable b-tree segment.
203824204123
*/
203825204124
struct IncrmergeWriter {
203826
- int nLeafEst; /* Space allocated for leaf blocks */
203827
- int nWork; /* Number of leaf pages flushed */
204125
+ i64 nLeafEst; /* Space allocated for leaf blocks */
204126
+ i64 nWork; /* Number of leaf pages flushed */
203828204127
sqlite3_int64 iAbsLevel; /* Absolute level of input segments */
203829204128
int iIdx; /* Index of *output* segment in iAbsLevel+1 */
203830204129
sqlite3_int64 iStart; /* Block number of first allocated block */
203831204130
sqlite3_int64 iEnd; /* Block number of last allocated block */
203832204131
sqlite3_int64 nLeafData; /* Bytes of leaf page data so far */
@@ -204568,21 +204867,21 @@
204568204867
Fts3MultiSegReader *pCsr, /* Cursor that data will be read from */
204569204868
IncrmergeWriter *pWriter /* Populate this object */
204570204869
){
204571204870
int rc; /* Return Code */
204572204871
int i; /* Iterator variable */
204573
- int nLeafEst = 0; /* Blocks allocated for leaf nodes */
204872
+ i64 nLeafEst = 0; /* Blocks allocated for leaf nodes */
204574204873
sqlite3_stmt *pLeafEst = 0; /* SQL used to determine nLeafEst */
204575204874
sqlite3_stmt *pFirstBlock = 0; /* SQL used to determine first block */
204576204875
204577204876
/* Calculate nLeafEst. */
204578204877
rc = fts3SqlStmt(p, SQL_MAX_LEAF_NODE_ESTIMATE, &pLeafEst, 0);
204579204878
if( rc==SQLITE_OK ){
204580204879
sqlite3_bind_int64(pLeafEst, 1, iAbsLevel);
204581204880
sqlite3_bind_int64(pLeafEst, 2, pCsr->nSegment);
204582204881
if( SQLITE_ROW==sqlite3_step(pLeafEst) ){
204583
- nLeafEst = sqlite3_column_int(pLeafEst, 0);
204882
+ nLeafEst = sqlite3_column_int64(pLeafEst, 0);
204584204883
}
204585204884
rc = sqlite3_reset(pLeafEst);
204586204885
}
204587204886
if( rc!=SQLITE_OK ) return rc;
204588204887
@@ -228353,11 +228652,11 @@
228353228652
typedef struct DbpageTable DbpageTable;
228354228653
typedef struct DbpageCursor DbpageCursor;
228355228654
228356228655
struct DbpageCursor {
228357228656
sqlite3_vtab_cursor base; /* Base class. Must be first */
228358
- int pgno; /* Current page number */
228657
+ Pgno pgno; /* Current page number */
228359228658
int mxPgno; /* Last page to visit on this scan */
228360228659
Pager *pPager; /* Pager being read/written */
228361228660
DbPage *pPage1; /* Page 1 of the database */
228362228661
int iDb; /* Index of database to analyze */
228363228662
int szPage; /* Size of each page in bytes */
@@ -228491,11 +228790,11 @@
228491228790
if( pCsr==0 ){
228492228791
return SQLITE_NOMEM_BKPT;
228493228792
}else{
228494228793
memset(pCsr, 0, sizeof(DbpageCursor));
228495228794
pCsr->base.pVtab = pVTab;
228496
- pCsr->pgno = -1;
228795
+ pCsr->pgno = 0;
228497228796
}
228498228797
228499228798
*ppCursor = (sqlite3_vtab_cursor *)pCsr;
228500228799
return SQLITE_OK;
228501228800
}
@@ -228591,16 +228890,16 @@
228591228890
){
228592228891
DbpageCursor *pCsr = (DbpageCursor *)pCursor;
228593228892
int rc = SQLITE_OK;
228594228893
switch( i ){
228595228894
case 0: { /* pgno */
228596
- sqlite3_result_int(ctx, pCsr->pgno);
228895
+ sqlite3_result_int64(ctx, (sqlite3_int64)pCsr->pgno);
228597228896
break;
228598228897
}
228599228898
case 1: { /* data */
228600228899
DbPage *pDbPage = 0;
228601
- if( pCsr->pgno==((PENDING_BYTE/pCsr->szPage)+1) ){
228900
+ if( pCsr->pgno==(Pgno)((PENDING_BYTE/pCsr->szPage)+1) ){
228602228901
/* The pending byte page. Assume it is zeroed out. Attempting to
228603228902
** request this page from the page is an SQLITE_CORRUPT error. */
228604228903
sqlite3_result_zeroblob(ctx, pCsr->szPage);
228605228904
}else{
228606228905
rc = sqlite3PagerGet(pCsr->pPager, pCsr->pgno, (DbPage**)&pDbPage, 0);
@@ -228670,14 +228969,14 @@
228670228969
if( argc==1 ){
228671228970
zErr = "cannot delete";
228672228971
goto update_fail;
228673228972
}
228674228973
if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
228675
- pgno = (Pgno)sqlite3_value_int(argv[2]);
228974
+ pgno = (Pgno)sqlite3_value_int64(argv[2]);
228676228975
isInsert = 1;
228677228976
}else{
228678
- pgno = sqlite3_value_int(argv[0]);
228977
+ pgno = (Pgno)sqlite3_value_int64(argv[0]);
228679228978
if( (Pgno)sqlite3_value_int(argv[1])!=pgno ){
228680228979
zErr = "cannot insert";
228681228980
goto update_fail;
228682228981
}
228683228982
isInsert = 0;
@@ -233644,11 +233943,11 @@
233644233943
sqlite3_changeset_iter *pIter, /* Changeset iterator */
233645233944
int(*xConflict)(void *, int, sqlite3_changeset_iter*),
233646233945
void *pCtx, /* First argument for conflict handler */
233647233946
int *pbReplace /* OUT: Set to true if PK row is found */
233648233947
){
233649
- int res = 0; /* Value returned by conflict handler */
233948
+ int res = SQLITE_CHANGESET_OMIT;/* Value returned by conflict handler */
233650233949
int rc;
233651233950
int nCol;
233652233951
int op;
233653233952
const char *zDummy;
233654233953
@@ -233665,15 +233964,13 @@
233665233964
rc = SQLITE_OK;
233666233965
}
233667233966
233668233967
if( rc==SQLITE_ROW ){
233669233968
/* There exists another row with the new.* primary key. */
233670
- if( p->bIgnoreNoop
233671
- && sqlite3_column_int(p->pSelect, sqlite3_column_count(p->pSelect)-1)
233969
+ if( 0==p->bIgnoreNoop
233970
+ || 0==sqlite3_column_int(p->pSelect, sqlite3_column_count(p->pSelect)-1)
233672233971
){
233673
- res = SQLITE_CHANGESET_OMIT;
233674
- }else{
233675233972
pIter->pConflict = p->pSelect;
233676233973
res = xConflict(pCtx, eType, pIter);
233677233974
pIter->pConflict = 0;
233678233975
}
233679233976
rc = sqlite3_reset(p->pSelect);
@@ -233683,11 +233980,13 @@
233683233980
** to the SessionApplyCtx.constraints buffer. */
233684233981
u8 *aBlob = &pIter->in.aData[pIter->in.iCurrent];
233685233982
int nBlob = pIter->in.iNext - pIter->in.iCurrent;
233686233983
sessionAppendBlob(&p->constraints, aBlob, nBlob, &rc);
233687233984
return SQLITE_OK;
233688
- }else{
233985
+ }else if( p->bIgnoreNoop==0 || op!=SQLITE_DELETE
233986
+ || eType==SQLITE_CHANGESET_CONFLICT
233987
+ ){
233689233988
/* No other row with the new.* primary key. */
233690233989
res = xConflict(pCtx, eType+1, pIter);
233691233990
if( res==SQLITE_CHANGESET_REPLACE ) rc = SQLITE_MISUSE;
233692233991
}
233693233992
}
@@ -233781,11 +234080,11 @@
233781234080
}
233782234081
if( rc!=SQLITE_OK ) return rc;
233783234082
233784234083
sqlite3_step(p->pDelete);
233785234084
rc = sqlite3_reset(p->pDelete);
233786
- if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 && p->bIgnoreNoop==0 ){
234085
+ if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 ){
233787234086
rc = sessionConflictHandler(
233788234087
SQLITE_CHANGESET_DATA, p, pIter, xConflict, pCtx, pbRetry
233789234088
);
233790234089
}else if( (rc&0xff)==SQLITE_CONSTRAINT ){
233791234090
rc = sessionConflictHandler(
@@ -236412,25 +236711,18 @@
236412236711
** Constants for the largest and smallest possible 64-bit signed integers.
236413236712
*/
236414236713
# define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
236415236714
# define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
236416236715
236417
-/* The uptr type is an unsigned integer large enough to hold a pointer
236716
+/*
236717
+** This macro is used in a single assert() within fts5 to check that an
236718
+** allocation is aligned to an 8-byte boundary. But it is a complicated
236719
+** macro to get right for multiple platforms without generating warnings.
236720
+** So instead of reproducing the entire definition from sqliteInt.h, we
236721
+** just do without this assert() for the rare non-amalgamation builds.
236418236722
*/
236419
-#if defined(HAVE_STDINT_H)
236420
- typedef uintptr_t uptr;
236421
-#elif SQLITE_PTRSIZE==4
236422
- typedef u32 uptr;
236423
-#else
236424
- typedef u64 uptr;
236425
-#endif
236426
-
236427
-#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
236428
-# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
236429
-#else
236430
-# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
236431
-#endif
236723
+#define EIGHT_BYTE_ALIGNMENT(x) 1
236432236724
236433236725
/*
236434236726
** Macros needed to provide flexible arrays in a portable way
236435236727
*/
236436236728
#ifndef offsetof
@@ -251885,14 +252177,17 @@
251885252177
** function populates it with the initial structure objects for each index,
251886252178
** and the initial version of the "averages" record (a zero-byte blob).
251887252179
*/
251888252180
static int sqlite3Fts5IndexReinit(Fts5Index *p){
251889252181
Fts5Structure *pTmp;
251890
- u8 tmpSpace[SZ_FTS5STRUCTURE(1)];
252182
+ union {
252183
+ Fts5Structure sFts;
252184
+ u8 tmpSpace[SZ_FTS5STRUCTURE(1)];
252185
+ } uFts;
251891252186
fts5StructureInvalidate(p);
251892252187
fts5IndexDiscardData(p);
251893
- pTmp = (Fts5Structure*)tmpSpace;
252188
+ pTmp = &uFts.sFts;
251894252189
memset(pTmp, 0, SZ_FTS5STRUCTURE(1));
251895252190
if( p->pConfig->bContentlessDelete ){
251896252191
pTmp->nOriginCntr = 1;
251897252192
}
251898252193
fts5DataWrite(p, FTS5_AVERAGES_ROWID, (const u8*)"", 0);
@@ -258177,11 +258472,11 @@
258177258472
int nArg, /* Number of args */
258178258473
sqlite3_value **apUnused /* Function arguments */
258179258474
){
258180258475
assert( nArg==0 );
258181258476
UNUSED_PARAM2(nArg, apUnused);
258182
- sqlite3_result_text(pCtx, "fts5: 2025-07-30 16:17:14 cf7163f82ca380958a79350473b2c5a2cebda7496d6d575fa2835c362010fea1", -1, SQLITE_TRANSIENT);
258477
+ sqlite3_result_text(pCtx, "fts5: 2025-09-09 10:28:06 0f31711591c56f3896fb6f092752fb82c4ea646bf8e5838dfbe55302994ea091", -1, SQLITE_TRANSIENT);
258183258478
}
258184258479
258185258480
/*
258186258481
** Implementation of fts5_locale(LOCALE, TEXT) function.
258187258482
**
258188258483
--- 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 ** cf7163f82ca380958a79350473b2c5a2cebd with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -465,11 +465,14 @@
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.51.0"
469 #define SQLITE_VERSION_NUMBER 3051000
470 #define SQLITE_SOURCE_ID "2025-07-30 16:17:14 cf7163f82ca380958a79350473b2c5a2cebda7496d6d575fa2835c362010fea1"
 
 
 
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -2657,21 +2660,24 @@
2657 ** views in the main database schema or in the schemas of ATTACH-ed
2658 ** databases.)^ </dd>
2659 **
2660 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2661 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2662 ** <dd> ^This option is used to enable or disable the
2663 ** [fts3_tokenizer()] function which is part of the
2664 ** [FTS3] full-text search engine extension.
2665 ** There must be two additional arguments.
2666 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2667 ** positive to enable fts3_tokenizer() or negative to leave the setting
2668 ** unchanged.
2669 ** The second parameter is a pointer to an integer into which
2670 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2671 ** following this call. The second parameter may be a NULL pointer, in
2672 ** which case the new setting is not reported back. </dd>
 
 
 
2673 **
2674 ** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
2675 ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
2676 ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
2677 ** interface independently of the [load_extension()] SQL function.
@@ -6527,10 +6533,11 @@
6527 ** to be attached to [database connection] D using name N. Subsequent
6528 ** calls to sqlite3_get_clientdata(D,N) will return a copy of pointer P
6529 ** or a NULL pointer if there were no prior calls to
6530 ** sqlite3_set_clientdata() with the same values of D and N.
6531 ** Names are compared using strcmp() and are thus case sensitive.
 
6532 **
6533 ** If P and X are both non-NULL, then the destructor X is invoked with
6534 ** argument P on the first of the following occurrences:
6535 ** <ul>
6536 ** <li> An out-of-memory error occurs during the call to
@@ -10098,25 +10105,38 @@
10098 ** ^The third parameter is the name of the database that was written to -
10099 ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
10100 ** is the number of pages currently in the write-ahead log file,
10101 ** including those that were just committed.
10102 **
10103 ** The callback function should normally return [SQLITE_OK]. ^If an error
10104 ** code is returned, that error will propagate back up through the
10105 ** SQLite code base to cause the statement that provoked the callback
10106 ** to report an error, though the commit will have still occurred. If the
10107 ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
10108 ** that does not correspond to any valid SQLite error code, the results
10109 ** are undefined.
10110 **
10111 ** A single database handle may have at most a single write-ahead log callback
10112 ** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
10113 ** previously registered write-ahead log callback. ^The return value is
10114 ** a copy of the third parameter from the previous call, if any, or 0.
10115 ** ^Note that the [sqlite3_wal_autocheckpoint()] interface and the
10116 ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
10117 ** overwrite any prior [sqlite3_wal_hook()] settings.
 
 
 
 
 
 
 
 
 
 
 
 
 
10118 */
10119 SQLITE_API void *sqlite3_wal_hook(
10120 sqlite3*,
10121 int(*)(void *,sqlite3*,const char*,int),
10122 void*
@@ -10129,11 +10149,11 @@
10129 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
10130 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
10131 ** to automatically [checkpoint]
10132 ** after committing a transaction if there are N or
10133 ** more frames in the [write-ahead log] file. ^Passing zero or
10134 ** a negative value as the nFrame parameter disables automatic
10135 ** checkpoints entirely.
10136 **
10137 ** ^The callback registered by this function replaces any existing callback
10138 ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback
10139 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
@@ -10145,13 +10165,14 @@
10145 ** ^Checkpoints initiated by this mechanism are
10146 ** [sqlite3_wal_checkpoint_v2|PASSIVE].
10147 **
10148 ** ^Every new [database connection] defaults to having the auto-checkpoint
10149 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
10150 ** pages. The use of this interface
10151 ** is only necessary if the default setting is found to be suboptimal
10152 ** for a particular application.
 
10153 */
10154 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
10155
10156 /*
10157 ** CAPI3REF: Checkpoint a database
@@ -10212,10 +10233,15 @@
10212 **
10213 ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
10214 ** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
10215 ** addition that it also truncates the log file to zero bytes just prior
10216 ** to a successful return.
 
 
 
 
 
10217 ** </dl>
10218 **
10219 ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
10220 ** the log file or to -1 if the checkpoint could not run because
10221 ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
@@ -10282,10 +10308,11 @@
10282 ** These constants define all valid values for the "checkpoint mode" passed
10283 ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
10284 ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
10285 ** meaning of each of these checkpoint modes.
10286 */
 
10287 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
10288 #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
10289 #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */
10290 #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
10291
@@ -11109,11 +11136,11 @@
11109 ** to avoid a memory leak.
11110 **
11111 ** The [sqlite3_snapshot_get()] interface is only available when the
11112 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
11113 */
11114 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get(
11115 sqlite3 *db,
11116 const char *zSchema,
11117 sqlite3_snapshot **ppSnapshot
11118 );
11119
@@ -11158,11 +11185,11 @@
11158 ** database connection in order to make it ready to use snapshots.)
11159 **
11160 ** The [sqlite3_snapshot_open()] interface is only available when the
11161 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
11162 */
11163 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open(
11164 sqlite3 *db,
11165 const char *zSchema,
11166 sqlite3_snapshot *pSnapshot
11167 );
11168
@@ -11175,11 +11202,11 @@
11175 ** using this routine to avoid a memory leak.
11176 **
11177 ** The [sqlite3_snapshot_free()] interface is only available when the
11178 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
11179 */
11180 SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*);
11181
11182 /*
11183 ** CAPI3REF: Compare the ages of two snapshot handles.
11184 ** METHOD: sqlite3_snapshot
11185 **
@@ -11202,11 +11229,11 @@
11202 ** snapshot, and a positive value if P1 is a newer snapshot than P2.
11203 **
11204 ** This interface is only available if SQLite is compiled with the
11205 ** [SQLITE_ENABLE_SNAPSHOT] option.
11206 */
11207 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
11208 sqlite3_snapshot *p1,
11209 sqlite3_snapshot *p2
11210 );
11211
11212 /*
@@ -11230,11 +11257,11 @@
11230 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
11231 **
11232 ** This interface is only available if SQLite is compiled with the
11233 ** [SQLITE_ENABLE_SNAPSHOT] option.
11234 */
11235 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
11236
11237 /*
11238 ** CAPI3REF: Serialize a database
11239 **
11240 ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to
@@ -11304,16 +11331,17 @@
11304 /*
11305 ** CAPI3REF: Deserialize a database
11306 **
11307 ** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the
11308 ** [database connection] D to disconnect from database S and then
11309 ** reopen S as an in-memory database based on the serialization contained
11310 ** in P. The serialized database P is N bytes in size. M is the size of
11311 ** the buffer P, which might be larger than N. If M is larger than N, and
11312 ** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is
11313 ** permitted to add content to the in-memory database as long as the total
11314 ** size does not exceed M bytes.
 
11315 **
11316 ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
11317 ** invoke sqlite3_free() on the serialization buffer when the database
11318 ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
11319 ** SQLite will try to increase the buffer size using sqlite3_realloc64()
@@ -14356,11 +14384,11 @@
14356
14357 /*
14358 ** Maximum number of pages in one database file.
14359 **
14360 ** This is really just the default value for the max_page_count pragma.
14361 ** This value can be lowered (or raised) at run-time using that the
14362 ** max_page_count macro.
14363 */
14364 #ifndef SQLITE_MAX_PAGE_COUNT
14365 # define SQLITE_MAX_PAGE_COUNT 0xfffffffe /* 4294967294 */
14366 #endif
@@ -20086,10 +20114,11 @@
20086 #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */
20087 #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */
20088 #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */
20089 #define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */
20090 #define SF_Correlated 0x20000000 /* True if references the outer context */
 
20091
20092 /* True if SrcItem X is a subquery that has SF_NestedFrom */
20093 #define IsNestedFrom(X) \
20094 ((X)->fg.isSubquery && \
20095 ((X)->u4.pSubq->pSelect->selFlags&SF_NestedFrom)!=0)
@@ -20839,10 +20868,11 @@
20839 struct Table *pTab; /* Table of generated column */
20840 struct CoveringIndexCheck *pCovIdxCk; /* Check for covering index */
20841 SrcItem *pSrcItem; /* A single FROM clause item */
20842 DbFixer *pFix; /* See sqlite3FixSelect() */
20843 Mem *aMem; /* See sqlite3BtreeCursorHint() */
 
20844 } u;
20845 };
20846
20847 /*
20848 ** The following structure contains information used by the sqliteFix...
@@ -24209,11 +24239,14 @@
24209 Mem oldipk; /* Memory cell holding "old" IPK value */
24210 Mem *aNew; /* Array of new.* values */
24211 Table *pTab; /* Schema object being updated */
24212 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
24213 sqlite3_value **apDflt; /* Array of default values, if required */
24214 u8 keyinfoSpace[SZ_KEYINFO_0]; /* Space to hold pKeyinfo[0] content */
 
 
 
24215 };
24216
24217 /*
24218 ** An instance of this object is used to pass an vector of values into
24219 ** OP_VFilter, the xFilter method of a virtual table. The vector is the
@@ -33486,13 +33519,17 @@
33486 sqlite3StrAccumFinish(&x);
33487 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
33488 n = 0;
33489 if( pItem->fg.isSubquery ) n++;
33490 if( pItem->fg.isTabFunc ) n++;
33491 if( pItem->fg.isUsing ) n++;
33492 if( pItem->fg.isUsing ){
33493 sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING");
 
 
 
 
33494 }
33495 if( pItem->fg.isSubquery ){
33496 assert( n==1 );
33497 if( pItem->pSTab ){
33498 Table *pTab = pItem->pSTab;
@@ -39437,14 +39474,15 @@
39437 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off64_t))\
39438 aSyscall[13].pCurrent)
39439
39440 #if defined(HAVE_FCHMOD)
39441 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
 
39442 #else
39443 { "fchmod", (sqlite3_syscall_ptr)0, 0 },
 
39444 #endif
39445 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
39446
39447 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
39448 { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 },
39449 #else
39450 { "fallocate", (sqlite3_syscall_ptr)0, 0 },
@@ -40391,10 +40429,14 @@
40391 do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR );
40392 if( rc!=1 ){
40393 storeLastErrno(pFile, errno);
40394 return SQLITE_IOERR;
40395 }
 
 
 
 
40396 rc = osFstat(fd, &statbuf);
40397 if( rc!=0 ){
40398 storeLastErrno(pFile, errno);
40399 return SQLITE_IOERR;
40400 }
@@ -40560,22 +40602,46 @@
40560 static int osSetPosixAdvisoryLock(
40561 int h, /* The file descriptor on which to take the lock */
40562 struct flock *pLock, /* The description of the lock */
40563 unixFile *pFile /* Structure holding timeout value */
40564 ){
40565 int tm = pFile->iBusyTimeout;
40566 int rc = osFcntl(h,F_SETLK,pLock);
40567 while( rc<0 && tm>0 ){
40568 /* On systems that support some kind of blocking file lock with a timeout,
40569 ** make appropriate changes here to invoke that blocking file lock. On
40570 ** generic posix, however, there is no such API. So we simply try the
40571 ** lock once every millisecond until either the timeout expires, or until
40572 ** the lock is obtained. */
40573 unixSleep(0,1000);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40574 rc = osFcntl(h,F_SETLK,pLock);
40575 tm--;
 
 
40576 }
 
40577 return rc;
40578 }
40579 #endif /* SQLITE_ENABLE_SETLK_TIMEOUT */
40580
40581
@@ -51349,33 +51415,39 @@
51349 ** log-summary, each thread has its own winFile object, but they all
51350 ** point to a single instance of this object. In other words, each
51351 ** log-summary is opened only once per process.
51352 **
51353 ** winShmMutexHeld() must be true when creating or destroying
51354 ** this object or while reading or writing the following fields:
 
51355 **
51356 ** nRef
51357 ** pNext
51358 **
51359 ** The following fields are read-only after the object is created:
51360 **
51361 ** zFilename
 
 
 
51362 **
51363 ** Either winShmNode.mutex must be held or winShmNode.nRef==0 and
51364 ** winShmMutexHeld() is true when reading or writing any other field
51365 ** in this structure.
51366 **
51367 ** File-handle hSharedShm is used to (a) take the DMS lock, (b) truncate
51368 ** the *-shm file if the DMS-locking protocol demands it, and (c) map
51369 ** regions of the *-shm file into memory using MapViewOfFile() or
51370 ** similar. Other locks are taken by individual clients using the
51371 ** winShm.hShm handles.
 
51372 */
51373 struct winShmNode {
51374 sqlite3_mutex *mutex; /* Mutex to access this object */
51375 char *zFilename; /* Name of the file */
51376 HANDLE hSharedShm; /* File handle open on zFilename */
 
51377
51378 int isUnlocked; /* DMS lock has not yet been obtained */
51379 int isReadonly; /* True if read-only */
51380 int szRegion; /* Size of shared-memory regions */
51381 int nRegion; /* Size of array apRegion */
@@ -51384,11 +51456,12 @@
51384 HANDLE hMap; /* File handle from CreateFileMapping */
51385 void *pMap;
51386 } *aRegion;
51387 DWORD lastErrno; /* The Windows errno from the last I/O error */
51388
51389 int nRef; /* Number of winShm objects pointing to this */
 
51390 winShmNode *pNext; /* Next in list of all winShmNode objects */
51391 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
51392 u8 nextShmId; /* Next available winShm.id value */
51393 #endif
51394 };
@@ -51412,10 +51485,11 @@
51412 HANDLE hShm; /* File-handle on *-shm file. For locking. */
51413 int bReadonly; /* True if hShm is opened read-only */
51414 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
51415 u8 id; /* Id of this connection with its winShmNode */
51416 #endif
 
51417 };
51418
51419 /*
51420 ** Constants used for locking
51421 */
@@ -51425,11 +51499,11 @@
51425 /* Forward references to VFS methods */
51426 static int winOpen(sqlite3_vfs*,const char*,sqlite3_file*,int,int*);
51427 static int winDelete(sqlite3_vfs *,const char*,int);
51428
51429 /*
51430 ** Purge the winShmNodeList list of all entries with winShmNode.nRef==0.
51431 **
51432 ** This is not a VFS shared-memory method; it is a utility function called
51433 ** by VFS shared-memory methods.
51434 */
51435 static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
@@ -51438,11 +51512,11 @@
51438 assert( winShmMutexHeld() );
51439 OSTRACE(("SHM-PURGE pid=%lu, deleteFlag=%d\n",
51440 osGetCurrentProcessId(), deleteFlag));
51441 pp = &winShmNodeList;
51442 while( (p = *pp)!=0 ){
51443 if( p->nRef==0 ){
51444 int i;
51445 if( p->mutex ){ sqlite3_mutex_free(p->mutex); }
51446 for(i=0; i<p->nRegion; i++){
51447 BOOL bRc = osUnmapViewOfFile(p->aRegion[i].pMap);
51448 OSTRACE(("SHM-PURGE-UNMAP pid=%lu, region=%d, rc=%s\n",
@@ -51602,10 +51676,64 @@
51602 *pbReadonly = bReadonly;
51603 *ph = h;
51604 return rc;
51605 }
51606
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51607
51608 /*
51609 ** Open the shared-memory area associated with database file pDbFd.
51610 */
51611 static int winOpenSharedMemory(winFile *pDbFd){
@@ -51628,19 +51756,14 @@
51628 return SQLITE_IOERR_NOMEM_BKPT;
51629 }
51630 pNew->zFilename = (char*)&pNew[1];
51631 pNew->hSharedShm = INVALID_HANDLE_VALUE;
51632 pNew->isUnlocked = 1;
 
51633 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
51634 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
51635
51636 /* Open a file-handle on the *-shm file for this connection. This file-handle
51637 ** is only used for locking. The mapping of the *-shm file is created using
51638 ** the shared file handle in winShmNode.hSharedShm. */
51639 p->bReadonly = sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0);
51640 rc = winHandleOpen(pNew->zFilename, &p->bReadonly, &p->hShm);
51641
51642 /* Look to see if there is an existing winShmNode that can be used.
51643 ** If no matching winShmNode currently exists, then create a new one. */
51644 winShmEnterMutex();
51645 for(pShmNode = winShmNodeList; pShmNode; pShmNode=pShmNode->pNext){
51646 /* TBD need to come up with better match here. Perhaps
@@ -51657,11 +51780,11 @@
51657 }
51658
51659 /* Open a file-handle to use for mappings, and for the DMS lock. */
51660 if( rc==SQLITE_OK ){
51661 HANDLE h = INVALID_HANDLE_VALUE;
51662 pShmNode->isReadonly = p->bReadonly;
51663 rc = winHandleOpen(pNew->zFilename, &pShmNode->isReadonly, &h);
51664 pShmNode->hSharedShm = h;
51665 }
51666
51667 /* If successful, link the new winShmNode into the global list. If an
@@ -51679,24 +51802,39 @@
51679 }
51680
51681 /* If no error has occurred, link the winShm object to the winShmNode and
51682 ** the winShm to pDbFd. */
51683 if( rc==SQLITE_OK ){
 
51684 p->pShmNode = pShmNode;
51685 pShmNode->nRef++;
 
51686 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
51687 p->id = pShmNode->nextShmId++;
51688 #endif
51689 pDbFd->pShm = p;
 
51690 }else if( p ){
51691 winHandleClose(p->hShm);
51692 sqlite3_free(p);
51693 }
51694
51695 assert( rc!=SQLITE_OK || pShmNode->isUnlocked==0 || pShmNode->nRegion==0 );
51696 winShmLeaveMutex();
51697 sqlite3_free(pNew);
 
 
 
 
 
 
 
 
 
 
 
 
 
51698 return rc;
51699 }
51700
51701 /*
51702 ** Close a connection to shared-memory. Delete the underlying
@@ -51704,37 +51842,11 @@
51704 */
51705 static int winShmUnmap(
51706 sqlite3_file *fd, /* Database holding shared memory */
51707 int deleteFlag /* Delete after closing if true */
51708 ){
51709 winFile *pDbFd; /* Database holding shared-memory */
51710 winShm *p; /* The connection to be closed */
51711 winShmNode *pShmNode; /* The underlying shared-memory file */
51712
51713 pDbFd = (winFile*)fd;
51714 p = pDbFd->pShm;
51715 if( p==0 ) return SQLITE_OK;
51716 if( p->hShm!=INVALID_HANDLE_VALUE ){
51717 osCloseHandle(p->hShm);
51718 }
51719
51720 pShmNode = p->pShmNode;
51721 winShmEnterMutex();
51722
51723 /* If pShmNode->nRef has reached 0, then close the underlying
51724 ** shared-memory file, too. */
51725 assert( pShmNode->nRef>0 );
51726 pShmNode->nRef--;
51727 if( pShmNode->nRef==0 ){
51728 winShmPurge(pDbFd->pVfs, deleteFlag);
51729 }
51730 winShmLeaveMutex();
51731
51732 /* Free the connection p */
51733 sqlite3_free(p);
51734 pDbFd->pShm = 0;
51735 return SQLITE_OK;
51736 }
51737
51738 /*
51739 ** Change the lock state for a shared-memory segment.
51740 */
@@ -51799,29 +51911,75 @@
51799 );
51800 if( ((flags & SQLITE_SHM_UNLOCK) && ((p->exclMask|p->sharedMask) & mask))
51801 || (flags==(SQLITE_SHM_SHARED|SQLITE_SHM_LOCK) && 0==(p->sharedMask & mask))
51802 || (flags==(SQLITE_SHM_EXCLUSIVE|SQLITE_SHM_LOCK))
51803 ){
 
51804
51805 if( flags & SQLITE_SHM_UNLOCK ){
51806 /* Case (a) - unlock. */
51807
51808 assert( (p->exclMask & p->sharedMask)==0 );
51809 assert( !(flags & SQLITE_SHM_EXCLUSIVE) || (p->exclMask & mask)==mask );
51810 assert( !(flags & SQLITE_SHM_SHARED) || (p->sharedMask & mask)==mask );
51811
51812 rc = winHandleUnlock(p->hShm, ofst+WIN_SHM_BASE, n);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51813
51814 /* If successful, also clear the bits in sharedMask/exclMask */
51815 if( rc==SQLITE_OK ){
51816 p->exclMask = (p->exclMask & ~mask);
51817 p->sharedMask = (p->sharedMask & ~mask);
51818 }
51819 }else{
51820 int bExcl = ((flags & SQLITE_SHM_EXCLUSIVE) ? 1 : 0);
51821 DWORD nMs = winFileBusyTimeout(pDbFd);
51822 rc = winHandleLockTimeout(p->hShm, ofst+WIN_SHM_BASE, n, bExcl, nMs);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51823 if( rc==SQLITE_OK ){
51824 if( bExcl ){
51825 p->exclMask = (p->exclMask | mask);
51826 }else{
51827 p->sharedMask = (p->sharedMask | mask);
@@ -65748,11 +65906,11 @@
65748 */
65749 sqlite3_exec(db, "PRAGMA table_list",0,0,0);
65750 }
65751 if( pPager->pWal ){
65752 rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode,
65753 (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
65754 pPager->pBusyHandlerArg,
65755 pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
65756 pnLog, pnCkpt
65757 );
65758 }
@@ -70353,11 +70511,12 @@
70353 assert( pWal->ckptLock==0 );
70354 assert( pWal->writeLock==0 );
70355
70356 /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
70357 ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
70358 assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
 
70359
70360 if( pWal->readOnly ) return SQLITE_READONLY;
70361 WALTRACE(("WAL%p: checkpoint begins\n", pWal));
70362
70363 /* Enable blocking locks, if possible. */
@@ -70370,35 +70529,39 @@
70370 ** checkpoint operation at the same time, the lock cannot be obtained and
70371 ** SQLITE_BUSY is returned.
70372 ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured,
70373 ** it will not be invoked in this case.
70374 */
70375 rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
70376 testcase( rc==SQLITE_BUSY );
70377 testcase( rc!=SQLITE_OK && xBusy2!=0 );
70378 if( rc==SQLITE_OK ){
70379 pWal->ckptLock = 1;
70380
70381 /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and
70382 ** TRUNCATE modes also obtain the exclusive "writer" lock on the database
70383 ** file.
70384 **
70385 ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained
70386 ** immediately, and a busy-handler is configured, it is invoked and the
70387 ** writer lock retried until either the busy-handler returns 0 or the
70388 ** lock is successfully obtained.
70389 */
70390 if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){
70391 rc = walBusyLock(pWal, xBusy2, pBusyArg, WAL_WRITE_LOCK, 1);
70392 if( rc==SQLITE_OK ){
70393 pWal->writeLock = 1;
70394 }else if( rc==SQLITE_BUSY ){
70395 eMode2 = SQLITE_CHECKPOINT_PASSIVE;
70396 xBusy2 = 0;
70397 rc = SQLITE_OK;
70398 }
70399 }
 
 
 
 
70400 }
70401
70402
70403 /* Read the wal-index header. */
70404 SEH_TRY {
@@ -70408,21 +70571,21 @@
70408 ** or invoke the busy handler. The only lock such a checkpoint may
70409 ** attempt to obtain is a lock on a read-slot, and it should give up
70410 ** immediately and do a partial checkpoint if it cannot obtain it. */
70411 walDisableBlocking(pWal);
70412 rc = walIndexReadHdr(pWal, &isChanged);
70413 if( eMode2!=SQLITE_CHECKPOINT_PASSIVE ) (void)walEnableBlocking(pWal);
70414 if( isChanged && pWal->pDbFd->pMethods->iVersion>=3 ){
70415 sqlite3OsUnfetch(pWal->pDbFd, 0, 0);
70416 }
70417 }
70418
70419 /* Copy data from the log to the database file. */
70420 if( rc==SQLITE_OK ){
70421 if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){
70422 rc = SQLITE_CORRUPT_BKPT;
70423 }else{
70424 rc = walCheckpoint(pWal, db, eMode2, xBusy2, pBusyArg, sync_flags,zBuf);
70425 }
70426
70427 /* If no error occurred, set the output variables. */
70428 if( rc==SQLITE_OK || rc==SQLITE_BUSY ){
@@ -91645,11 +91808,11 @@
91645
91646 preupdate.v = v;
91647 preupdate.pCsr = pCsr;
91648 preupdate.op = op;
91649 preupdate.iNewReg = iReg;
91650 preupdate.pKeyinfo = (KeyInfo*)&preupdate.keyinfoSpace;
91651 preupdate.pKeyinfo->db = db;
91652 preupdate.pKeyinfo->enc = ENC(db);
91653 preupdate.pKeyinfo->nKeyField = pTab->nCol;
91654 preupdate.pKeyinfo->aSortFlags = 0; /* Indicate .aColl, .nAllField uninit */
91655 preupdate.iKey1 = iKey1;
@@ -102528,10 +102691,11 @@
102528 aRes[1] = aRes[2] = -1;
102529 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
102530 || pOp->p2==SQLITE_CHECKPOINT_FULL
102531 || pOp->p2==SQLITE_CHECKPOINT_RESTART
102532 || pOp->p2==SQLITE_CHECKPOINT_TRUNCATE
 
102533 );
102534 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
102535 if( rc ){
102536 if( rc!=SQLITE_BUSY ) goto abort_due_to_error;
102537 rc = SQLITE_OK;
@@ -110651,18 +110815,21 @@
110651 ExprList *pList /* Expression list to resolve. May be NULL. */
110652 ){
110653 SrcList *pSrc; /* Fake SrcList for pParse->pNewTable */
110654 NameContext sNC; /* Name context for pParse->pNewTable */
110655 int rc;
110656 u8 srcSpace[SZ_SRCLIST_1]; /* Memory space for the fake SrcList */
 
 
 
110657
110658 assert( type==0 || pTab!=0 );
110659 assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr
110660 || type==NC_GenCol || pTab==0 );
110661 memset(&sNC, 0, sizeof(sNC));
110662 pSrc = (SrcList*)srcSpace;
110663 memset(pSrc, 0, SZ_SRCLIST_1);
110664 if( pTab ){
110665 pSrc->nSrc = 1;
110666 pSrc->a[0].zName = pTab->zName;
110667 pSrc->a[0].pSTab = pTab;
110668 pSrc->a[0].iCursor = -1;
@@ -111920,10 +112087,15 @@
111920 }
111921 if( IsWindowFunc(pExpr) ){
111922 sqlite3ExprOrderByAggregateError(pParse, pExpr);
111923 sqlite3ExprListDelete(db, pOrderBy);
111924 return;
 
 
 
 
 
111925 }
111926
111927 pOB = sqlite3ExprAlloc(db, TK_ORDER, 0, 0);
111928 if( pOB==0 ){
111929 sqlite3ExprListDelete(db, pOrderBy);
@@ -114683,11 +114855,10 @@
114683 int destIfNull /* Jump here if the results are unknown due to NULLs */
114684 ){
114685 int rRhsHasNull = 0; /* Register that is true if RHS contains NULL values */
114686 int eType; /* Type of the RHS */
114687 int rLhs; /* Register(s) holding the LHS values */
114688 int rLhsOrig; /* LHS values prior to reordering by aiMap[] */
114689 Vdbe *v; /* Statement under construction */
114690 int *aiMap = 0; /* Map from vector field to index column */
114691 char *zAff = 0; /* Affinity string for comparisons */
114692 int nVector; /* Size of vectors for this IN operator */
114693 int iDummy; /* Dummy parameter to exprCodeVector() */
@@ -114746,23 +114917,12 @@
114746 ** Avoid factoring the LHS of the IN(...) expression out of the loop,
114747 ** even if it is constant, as OP_Affinity may be used on the register
114748 ** by code generated below. */
114749 assert( pParse->okConstFactor==okConstFactor );
114750 pParse->okConstFactor = 0;
114751 rLhsOrig = exprCodeVector(pParse, pLeft, &iDummy);
114752 pParse->okConstFactor = okConstFactor;
114753 for(i=0; i<nVector && aiMap[i]==i; i++){} /* Are LHS fields reordered? */
114754 if( i==nVector ){
114755 /* LHS fields are not reordered */
114756 rLhs = rLhsOrig;
114757 }else{
114758 /* Need to reorder the LHS fields according to aiMap */
114759 rLhs = sqlite3GetTempRange(pParse, nVector);
114760 for(i=0; i<nVector; i++){
114761 sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0);
114762 }
114763 }
114764
114765 /* If sqlite3FindInIndex() did not find or create an index that is
114766 ** suitable for evaluating the IN operator, then evaluate using a
114767 ** sequence of comparisons.
114768 **
@@ -114773,10 +114933,11 @@
114773 CollSeq *pColl;
114774 int labelOk = sqlite3VdbeMakeLabel(pParse);
114775 int r2, regToFree;
114776 int regCkNull = 0;
114777 int ii;
 
114778 assert( ExprUseXList(pExpr) );
114779 pList = pExpr->x.pList;
114780 pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
114781 if( destIfNull!=destIfFalse ){
114782 regCkNull = sqlite3GetTempReg(pParse);
@@ -114813,10 +114974,30 @@
114813 }
114814 sqlite3VdbeResolveLabel(v, labelOk);
114815 sqlite3ReleaseTempReg(pParse, regCkNull);
114816 goto sqlite3ExprCodeIN_finished;
114817 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114818
114819 /* Step 2: Check to see if the LHS contains any NULL columns. If the
114820 ** LHS does contain NULLs then the result must be either FALSE or NULL.
114821 ** We will then skip the binary search of the RHS.
114822 */
@@ -114840,15 +115021,15 @@
114840 */
114841 if( eType==IN_INDEX_ROWID ){
114842 /* In this case, the RHS is the ROWID of table b-tree and so we also
114843 ** know that the RHS is non-NULL. Hence, we combine steps 3 and 4
114844 ** into a single opcode. */
 
114845 sqlite3VdbeAddOp3(v, OP_SeekRowid, iTab, destIfFalse, rLhs);
114846 VdbeCoverage(v);
114847 addrTruthOp = sqlite3VdbeAddOp0(v, OP_Goto); /* Return True */
114848 }else{
114849 sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
114850 if( destIfFalse==destIfNull ){
114851 /* Combine Step 3 and Step 5 into a single opcode */
114852 if( ExprHasProperty(pExpr, EP_Subrtn) ){
114853 const VdbeOp *pOp = sqlite3VdbeGetOp(v, pExpr->y.sub.iAddr);
114854 assert( pOp->opcode==OP_Once || pParse->nErr );
@@ -114922,11 +115103,10 @@
114922
114923 /* Jumps here in order to return true. */
114924 sqlite3VdbeJumpHere(v, addrTruthOp);
114925
114926 sqlite3ExprCodeIN_finished:
114927 if( rLhs!=rLhsOrig ) sqlite3ReleaseTempReg(pParse, rLhs);
114928 VdbeComment((v, "end IN expr"));
114929 sqlite3ExprCodeIN_oom_error:
114930 sqlite3DbFree(pParse->db, aiMap);
114931 sqlite3DbFree(pParse->db, zAff);
114932 }
@@ -124573,11 +124753,11 @@
124573 */
124574 SQLITE_PRIVATE int sqlite3TableColumnToIndex(Index *pIdx, int iCol){
124575 int i;
124576 i16 iCol16;
124577 assert( iCol>=(-1) && iCol<=SQLITE_MAX_COLUMN );
124578 assert( pIdx->nColumn<=SQLITE_MAX_COLUMN+1 );
124579 iCol16 = iCol;
124580 for(i=0; i<pIdx->nColumn; i++){
124581 if( iCol16==pIdx->aiColumn[i] ){
124582 return i;
124583 }
@@ -129165,18 +129345,23 @@
129165 pKey->aSortFlags[i] = pIdx->aSortOrder[i];
129166 assert( 0==(pKey->aSortFlags[i] & KEYINFO_ORDER_BIGNULL) );
129167 }
129168 if( pParse->nErr ){
129169 assert( pParse->rc==SQLITE_ERROR_MISSING_COLLSEQ );
129170 if( pIdx->bNoQuery==0 ){
 
 
129171 /* Deactivate the index because it contains an unknown collating
129172 ** sequence. The only way to reactive the index is to reload the
129173 ** schema. Adding the missing collating sequence later does not
129174 ** reactive the index. The application had the chance to register
129175 ** the missing index using the collation-needed callback. For
129176 ** simplicity, SQLite will not give the application a second chance.
129177 */
 
 
 
129178 pIdx->bNoQuery = 1;
129179 pParse->rc = SQLITE_ERROR_RETRY;
129180 }
129181 sqlite3KeyInfoUnref(pKey);
129182 pKey = 0;
@@ -143548,10 +143733,12 @@
143548 eMode = SQLITE_CHECKPOINT_FULL;
143549 }else if( sqlite3StrICmp(zRight, "restart")==0 ){
143550 eMode = SQLITE_CHECKPOINT_RESTART;
143551 }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
143552 eMode = SQLITE_CHECKPOINT_TRUNCATE;
 
 
143553 }
143554 }
143555 pParse->nMem = 3;
143556 sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
143557 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
@@ -145114,13 +145301,15 @@
145114 ** or encounters a permanent error. A schema problem after one schema
145115 ** reset is considered a permanent error. */
145116 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
145117 assert( rc==SQLITE_OK || *ppStmt==0 );
145118 if( rc==SQLITE_OK || db->mallocFailed ) break;
145119 }while( (rc==SQLITE_ERROR_RETRY && (cnt++)<SQLITE_MAX_PREPARE_RETRY)
145120 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
 
145121 sqlite3BtreeLeaveAll(db);
 
145122 rc = sqlite3ApiExit(db, rc);
145123 assert( (rc&db->errMask)==rc );
145124 db->busyHandler.nBusy = 0;
145125 sqlite3_mutex_leave(db->mutex);
145126 assert( rc==SQLITE_OK || (*ppStmt)==0 );
@@ -145790,12 +145979,11 @@
145790 while( p ){
145791 ExprSetProperty(p, joinFlag);
145792 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
145793 ExprSetVVAProperty(p, EP_NoReduce);
145794 p->w.iJoin = iTable;
145795 if( p->op==TK_FUNCTION ){
145796 assert( ExprUseXList(p) );
145797 if( p->x.pList ){
145798 int i;
145799 for(i=0; i<p->x.pList->nExpr; i++){
145800 sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable, joinFlag);
145801 }
@@ -146007,10 +146195,11 @@
146007 else if( pRight->u3.pOn ){
146008 sqlite3SetJoinExpr(pRight->u3.pOn, pRight->iCursor, joinType);
146009 p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->u3.pOn);
146010 pRight->u3.pOn = 0;
146011 pRight->fg.isOn = 1;
 
146012 }
146013 }
146014 return 0;
146015 }
146016
@@ -146893,11 +147082,14 @@
146893 ** Allocate a KeyInfo object sufficient for an index of N key columns and
146894 ** X extra columns.
146895 */
146896 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
146897 int nExtra = (N+X)*(sizeof(CollSeq*)+1);
146898 KeyInfo *p = sqlite3DbMallocRawNN(db, SZ_KEYINFO(0) + nExtra);
 
 
 
146899 if( p ){
146900 p->aSortFlags = (u8*)&p->aColl[N+X];
146901 p->nKeyField = (u16)N;
146902 p->nAllField = (u16)(N+X);
146903 p->enc = ENC(db);
@@ -149212,11 +149404,11 @@
149212 ** expressions in pEList.
149213 **
149214 ** ## About "isOuterJoin":
149215 **
149216 ** The isOuterJoin column indicates that the replacement will occur into a
149217 ** position in the parent that NULL-able due to an OUTER JOIN. Either the
149218 ** target slot in the parent is the right operand of a LEFT JOIN, or one of
149219 ** the left operands of a RIGHT JOIN. In either case, we need to potentially
149220 ** bypass the substituted expression with OP_IfNullRow.
149221 **
149222 ** Suppose the original expression is an integer constant. Even though the table
@@ -150050,21 +150242,16 @@
150050 ** elements we are now copying in.
150051 */
150052 pSub = pSub1;
150053 for(pParent=p; pParent; pParent=pParent->pPrior, pSub=pSub->pPrior){
150054 int nSubSrc;
150055 u8 jointype = 0;
150056 u8 ltorj = pSrc->a[iFrom].fg.jointype & JT_LTORJ;
150057 assert( pSub!=0 );
150058 pSubSrc = pSub->pSrc; /* FROM clause of subquery */
150059 nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
150060 pSrc = pParent->pSrc; /* FROM clause of the outer query */
150061
150062 if( pParent==p ){
150063 jointype = pSubitem->fg.jointype; /* First time through the loop */
150064 }
150065
150066 /* The subquery uses a single slot of the FROM clause of the outer
150067 ** query. If the subquery has more than one element in its FROM clause,
150068 ** then expand the outer query to make space for it to hold all elements
150069 ** of the subquery.
150070 **
@@ -150080,10 +150267,11 @@
150080 */
150081 if( nSubSrc>1 ){
150082 pSrc = sqlite3SrcListEnlarge(pParse, pSrc, nSubSrc-1,iFrom+1);
150083 if( pSrc==0 ) break;
150084 pParent->pSrc = pSrc;
 
150085 }
150086
150087 /* Transfer the FROM clause terms from the subquery into the
150088 ** outer query.
150089 */
@@ -150094,15 +150282,14 @@
150094 assert( pItem->fg.isSubquery
150095 || pItem->fg.fixedSchema
150096 || pItem->u4.zDatabase==0 );
150097 if( pItem->fg.isUsing ) sqlite3IdListDelete(db, pItem->u3.pUsing);
150098 *pItem = pSubSrc->a[i];
150099 pItem->fg.jointype |= ltorj;
150100 memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
150101 }
150102 pSrc->a[iFrom].fg.jointype &= JT_LTORJ;
150103 pSrc->a[iFrom].fg.jointype |= jointype | ltorj;
150104
150105 /* Now begin substituting subquery result set expressions for
150106 ** references to the iParent in the outer query.
150107 **
150108 ** Example:
@@ -152838,10 +153025,119 @@
152838 existsToJoin(pParse, p, pSubWhere);
152839 }
152840 }
152841 }
152842 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152843
152844 /*
152845 ** Generate byte-code for the SELECT statement given in the p argument.
152846 **
152847 ** The results are returned according to the SelectDest structure.
@@ -152965,10 +153261,22 @@
152965 if( sqlite3TreeTrace & 0x10 ){
152966 TREETRACE(0x10,pParse,p, ("after name resolution:\n"));
152967 sqlite3TreeViewSelect(0, p, 0);
152968 }
152969 #endif
 
 
 
 
 
 
 
 
 
 
 
 
152970
152971 /* If the SF_UFSrcCheck flag is set, then this function is being called
152972 ** as part of populating the temp table for an UPDATE...FROM statement.
152973 ** In this case, it is an error if the target object (pSrc->a[0]) name
152974 ** or alias is duplicated within FROM clause (pSrc->a[1..n]).
@@ -155531,11 +155839,14 @@
155531 sqlite3 *db = pParse->db;
155532 ExprList *pNew;
155533 Returning *pReturning;
155534 Select sSelect;
155535 SrcList *pFrom;
155536 u8 fromSpace[SZ_SRCLIST_1];
 
 
 
155537
155538 assert( v!=0 );
155539 if( !pParse->bReturning ){
155540 /* This RETURNING trigger must be for a different statement as
155541 ** this statement lacks a RETURNING clause. */
@@ -155547,12 +155858,12 @@
155547 if( pTrigger != &(pReturning->retTrig) ){
155548 /* This RETURNING trigger is for a different statement */
155549 return;
155550 }
155551 memset(&sSelect, 0, sizeof(sSelect));
155552 pFrom = (SrcList*)fromSpace;
155553 memset(pFrom, 0, SZ_SRCLIST_1);
155554 sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
155555 sSelect.pSrc = pFrom;
155556 pFrom->nSrc = 1;
155557 pFrom->a[0].pSTab = pTab;
155558 pFrom->a[0].zName = pTab->zName; /* tag-20240424-1 */
@@ -163079,11 +163390,14 @@
163079 WhereClause *pWC = &pWInfo->sWC;
163080 WhereInfo *pSubWInfo;
163081 WhereLoop *pLoop = pLevel->pWLoop;
163082 SrcItem *pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
163083 SrcList *pFrom;
163084 u8 fromSpace[SZ_SRCLIST_1];
 
 
 
163085 Bitmask mAll = 0;
163086 int k;
163087
163088 ExplainQueryPlan((pParse, 1, "RIGHT-JOIN %s", pTabItem->pSTab->zName));
163089 sqlite3VdbeNoJumpsOutsideSubrtn(v, pRJ->addrSubrtn, pRJ->endSubrtn,
@@ -163123,11 +163437,11 @@
163123 if( ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON) ) continue;
163124 pSubWhere = sqlite3ExprAnd(pParse, pSubWhere,
163125 sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
163126 }
163127 }
163128 pFrom = (SrcList*)fromSpace;
163129 pFrom->nSrc = 1;
163130 pFrom->nAlloc = 1;
163131 memcpy(&pFrom->a[0], pTabItem, sizeof(SrcItem));
163132 pFrom->a[0].fg.jointype = 0;
163133 assert( pParse->withinRJSubrtn < 100 );
@@ -164340,25 +164654,11 @@
164340 Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iJoin);
164341 if( ExprHasProperty(pExpr, EP_OuterON) ){
164342 prereqAll |= x;
164343 extraRight = x-1; /* ON clause terms may not be used with an index
164344 ** on left table of a LEFT JOIN. Ticket #3015 */
164345 if( (prereqAll>>1)>=x ){
164346 sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
164347 return;
164348 }
164349 }else if( (prereqAll>>1)>=x ){
164350 /* The ON clause of an INNER JOIN references a table to its right.
164351 ** Most other SQL database engines raise an error. But SQLite versions
164352 ** 3.0 through 3.38 just put the ON clause constraint into the WHERE
164353 ** clause and carried on. Beginning with 3.39, raise an error only
164354 ** if there is a RIGHT or FULL JOIN in the query. This makes SQLite
164355 ** more like other systems, and also preserves legacy. */
164356 if( ALWAYS(pSrc->nSrc>0) && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
164357 sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
164358 return;
164359 }
164360 ExprClearProperty(pExpr, EP_InnerON);
164361 }
164362 }
164363 pTerm->prereqAll = prereqAll;
164364 pTerm->leftCursor = -1;
@@ -184839,10 +185139,13 @@
184839 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
184840 switch( rc ){
184841 case SQLITE_OK: zName = "SQLITE_OK"; break;
184842 case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
184843 case SQLITE_ERROR_SNAPSHOT: zName = "SQLITE_ERROR_SNAPSHOT"; break;
 
 
 
184844 case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
184845 case SQLITE_PERM: zName = "SQLITE_PERM"; break;
184846 case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
184847 case SQLITE_ABORT_ROLLBACK: zName = "SQLITE_ABORT_ROLLBACK"; break;
184848 case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
@@ -189087,21 +189390,24 @@
189087 **
189088 */
189089 #ifndef _FTSINT_H
189090 #define _FTSINT_H
189091
 
 
 
 
 
 
 
189092 /* #include <assert.h> */
189093 /* #include <stdlib.h> */
189094 /* #include <stddef.h> */
189095 /* #include <stdio.h> */
189096 /* #include <string.h> */
189097 /* #include <stdarg.h> */
189098
189099 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
189100 # define NDEBUG 1
189101 #endif
189102
189103 /* FTS3/FTS4 require virtual tables */
189104 #ifdef SQLITE_OMIT_VIRTUALTABLE
189105 # undef SQLITE_ENABLE_FTS3
189106 # undef SQLITE_ENABLE_FTS4
189107 #endif
@@ -189540,17 +189846,10 @@
189540 /*
189541 ** Macro used to suppress compiler warnings for unused parameters.
189542 */
189543 #define UNUSED_PARAMETER(x) (void)(x)
189544
189545 /*
189546 ** Activate assert() only if SQLITE_TEST is enabled.
189547 */
189548 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
189549 # define NDEBUG 1
189550 #endif
189551
189552 /*
189553 ** The TESTONLY macro is used to enclose variable declarations or
189554 ** other bits of code that are needed to support the arguments
189555 ** within testcase() and assert() macros.
189556 */
@@ -203821,12 +204120,12 @@
203821 /*
203822 ** An object of this type contains the state required to create or append
203823 ** to an appendable b-tree segment.
203824 */
203825 struct IncrmergeWriter {
203826 int nLeafEst; /* Space allocated for leaf blocks */
203827 int nWork; /* Number of leaf pages flushed */
203828 sqlite3_int64 iAbsLevel; /* Absolute level of input segments */
203829 int iIdx; /* Index of *output* segment in iAbsLevel+1 */
203830 sqlite3_int64 iStart; /* Block number of first allocated block */
203831 sqlite3_int64 iEnd; /* Block number of last allocated block */
203832 sqlite3_int64 nLeafData; /* Bytes of leaf page data so far */
@@ -204568,21 +204867,21 @@
204568 Fts3MultiSegReader *pCsr, /* Cursor that data will be read from */
204569 IncrmergeWriter *pWriter /* Populate this object */
204570 ){
204571 int rc; /* Return Code */
204572 int i; /* Iterator variable */
204573 int nLeafEst = 0; /* Blocks allocated for leaf nodes */
204574 sqlite3_stmt *pLeafEst = 0; /* SQL used to determine nLeafEst */
204575 sqlite3_stmt *pFirstBlock = 0; /* SQL used to determine first block */
204576
204577 /* Calculate nLeafEst. */
204578 rc = fts3SqlStmt(p, SQL_MAX_LEAF_NODE_ESTIMATE, &pLeafEst, 0);
204579 if( rc==SQLITE_OK ){
204580 sqlite3_bind_int64(pLeafEst, 1, iAbsLevel);
204581 sqlite3_bind_int64(pLeafEst, 2, pCsr->nSegment);
204582 if( SQLITE_ROW==sqlite3_step(pLeafEst) ){
204583 nLeafEst = sqlite3_column_int(pLeafEst, 0);
204584 }
204585 rc = sqlite3_reset(pLeafEst);
204586 }
204587 if( rc!=SQLITE_OK ) return rc;
204588
@@ -228353,11 +228652,11 @@
228353 typedef struct DbpageTable DbpageTable;
228354 typedef struct DbpageCursor DbpageCursor;
228355
228356 struct DbpageCursor {
228357 sqlite3_vtab_cursor base; /* Base class. Must be first */
228358 int pgno; /* Current page number */
228359 int mxPgno; /* Last page to visit on this scan */
228360 Pager *pPager; /* Pager being read/written */
228361 DbPage *pPage1; /* Page 1 of the database */
228362 int iDb; /* Index of database to analyze */
228363 int szPage; /* Size of each page in bytes */
@@ -228491,11 +228790,11 @@
228491 if( pCsr==0 ){
228492 return SQLITE_NOMEM_BKPT;
228493 }else{
228494 memset(pCsr, 0, sizeof(DbpageCursor));
228495 pCsr->base.pVtab = pVTab;
228496 pCsr->pgno = -1;
228497 }
228498
228499 *ppCursor = (sqlite3_vtab_cursor *)pCsr;
228500 return SQLITE_OK;
228501 }
@@ -228591,16 +228890,16 @@
228591 ){
228592 DbpageCursor *pCsr = (DbpageCursor *)pCursor;
228593 int rc = SQLITE_OK;
228594 switch( i ){
228595 case 0: { /* pgno */
228596 sqlite3_result_int(ctx, pCsr->pgno);
228597 break;
228598 }
228599 case 1: { /* data */
228600 DbPage *pDbPage = 0;
228601 if( pCsr->pgno==((PENDING_BYTE/pCsr->szPage)+1) ){
228602 /* The pending byte page. Assume it is zeroed out. Attempting to
228603 ** request this page from the page is an SQLITE_CORRUPT error. */
228604 sqlite3_result_zeroblob(ctx, pCsr->szPage);
228605 }else{
228606 rc = sqlite3PagerGet(pCsr->pPager, pCsr->pgno, (DbPage**)&pDbPage, 0);
@@ -228670,14 +228969,14 @@
228670 if( argc==1 ){
228671 zErr = "cannot delete";
228672 goto update_fail;
228673 }
228674 if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
228675 pgno = (Pgno)sqlite3_value_int(argv[2]);
228676 isInsert = 1;
228677 }else{
228678 pgno = sqlite3_value_int(argv[0]);
228679 if( (Pgno)sqlite3_value_int(argv[1])!=pgno ){
228680 zErr = "cannot insert";
228681 goto update_fail;
228682 }
228683 isInsert = 0;
@@ -233644,11 +233943,11 @@
233644 sqlite3_changeset_iter *pIter, /* Changeset iterator */
233645 int(*xConflict)(void *, int, sqlite3_changeset_iter*),
233646 void *pCtx, /* First argument for conflict handler */
233647 int *pbReplace /* OUT: Set to true if PK row is found */
233648 ){
233649 int res = 0; /* Value returned by conflict handler */
233650 int rc;
233651 int nCol;
233652 int op;
233653 const char *zDummy;
233654
@@ -233665,15 +233964,13 @@
233665 rc = SQLITE_OK;
233666 }
233667
233668 if( rc==SQLITE_ROW ){
233669 /* There exists another row with the new.* primary key. */
233670 if( p->bIgnoreNoop
233671 && sqlite3_column_int(p->pSelect, sqlite3_column_count(p->pSelect)-1)
233672 ){
233673 res = SQLITE_CHANGESET_OMIT;
233674 }else{
233675 pIter->pConflict = p->pSelect;
233676 res = xConflict(pCtx, eType, pIter);
233677 pIter->pConflict = 0;
233678 }
233679 rc = sqlite3_reset(p->pSelect);
@@ -233683,11 +233980,13 @@
233683 ** to the SessionApplyCtx.constraints buffer. */
233684 u8 *aBlob = &pIter->in.aData[pIter->in.iCurrent];
233685 int nBlob = pIter->in.iNext - pIter->in.iCurrent;
233686 sessionAppendBlob(&p->constraints, aBlob, nBlob, &rc);
233687 return SQLITE_OK;
233688 }else{
 
 
233689 /* No other row with the new.* primary key. */
233690 res = xConflict(pCtx, eType+1, pIter);
233691 if( res==SQLITE_CHANGESET_REPLACE ) rc = SQLITE_MISUSE;
233692 }
233693 }
@@ -233781,11 +234080,11 @@
233781 }
233782 if( rc!=SQLITE_OK ) return rc;
233783
233784 sqlite3_step(p->pDelete);
233785 rc = sqlite3_reset(p->pDelete);
233786 if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 && p->bIgnoreNoop==0 ){
233787 rc = sessionConflictHandler(
233788 SQLITE_CHANGESET_DATA, p, pIter, xConflict, pCtx, pbRetry
233789 );
233790 }else if( (rc&0xff)==SQLITE_CONSTRAINT ){
233791 rc = sessionConflictHandler(
@@ -236412,25 +236711,18 @@
236412 ** Constants for the largest and smallest possible 64-bit signed integers.
236413 */
236414 # define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
236415 # define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
236416
236417 /* The uptr type is an unsigned integer large enough to hold a pointer
 
 
 
 
 
236418 */
236419 #if defined(HAVE_STDINT_H)
236420 typedef uintptr_t uptr;
236421 #elif SQLITE_PTRSIZE==4
236422 typedef u32 uptr;
236423 #else
236424 typedef u64 uptr;
236425 #endif
236426
236427 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
236428 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
236429 #else
236430 # define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
236431 #endif
236432
236433 /*
236434 ** Macros needed to provide flexible arrays in a portable way
236435 */
236436 #ifndef offsetof
@@ -251885,14 +252177,17 @@
251885 ** function populates it with the initial structure objects for each index,
251886 ** and the initial version of the "averages" record (a zero-byte blob).
251887 */
251888 static int sqlite3Fts5IndexReinit(Fts5Index *p){
251889 Fts5Structure *pTmp;
251890 u8 tmpSpace[SZ_FTS5STRUCTURE(1)];
 
 
 
251891 fts5StructureInvalidate(p);
251892 fts5IndexDiscardData(p);
251893 pTmp = (Fts5Structure*)tmpSpace;
251894 memset(pTmp, 0, SZ_FTS5STRUCTURE(1));
251895 if( p->pConfig->bContentlessDelete ){
251896 pTmp->nOriginCntr = 1;
251897 }
251898 fts5DataWrite(p, FTS5_AVERAGES_ROWID, (const u8*)"", 0);
@@ -258177,11 +258472,11 @@
258177 int nArg, /* Number of args */
258178 sqlite3_value **apUnused /* Function arguments */
258179 ){
258180 assert( nArg==0 );
258181 UNUSED_PARAM2(nArg, apUnused);
258182 sqlite3_result_text(pCtx, "fts5: 2025-07-30 16:17:14 cf7163f82ca380958a79350473b2c5a2cebda7496d6d575fa2835c362010fea1", -1, SQLITE_TRANSIENT);
258183 }
258184
258185 /*
258186 ** Implementation of fts5_locale(LOCALE, TEXT) function.
258187 **
258188
--- 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 ** 0f31711591c56f3896fb6f092752fb82c4ea with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -465,11 +465,14 @@
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.51.0"
469 #define SQLITE_VERSION_NUMBER 3051000
470 #define SQLITE_SOURCE_ID "2025-09-09 10:28:06 0f31711591c56f3896fb6f092752fb82c4ea646bf8e5838dfbe55302994ea091"
471 #define SQLITE_SCM_BRANCH "trunk"
472 #define SQLITE_SCM_TAGS ""
473 #define SQLITE_SCM_DATETIME "2025-09-09T10:28:06.692Z"
474
475 /*
476 ** CAPI3REF: Run-Time Library Version Numbers
477 ** KEYWORDS: sqlite3_version sqlite3_sourceid
478 **
@@ -2657,21 +2660,24 @@
2660 ** views in the main database schema or in the schemas of ATTACH-ed
2661 ** databases.)^ </dd>
2662 **
2663 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2664 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2665 ** <dd> ^This option is used to enable or disable using the
2666 ** [fts3_tokenizer()] function - part of the [FTS3] full-text search engine
2667 ** extension - without using bound parameters as the parameters. Doing so
2668 ** is disabled by default. There must be two additional arguments. The first
2669 ** argument is an integer. If it is passed 0, then using fts3_tokenizer()
2670 ** without bound parameters is disabled. If it is passed a positive value,
2671 ** then calling fts3_tokenizer without bound parameters is enabled. If it
2672 ** is passed a negative value, this setting is not modified - this can be
2673 ** used to query for the current setting. The second parameter is a pointer
2674 ** to an integer into which is written 0 or 1 to indicate the current value
2675 ** of this setting (after it is modified, if applicable). The second
2676 ** parameter may be a NULL pointer, in which case the value of the setting
2677 ** is not reported back. Refer to [FTS3] documentation for further details.
2678 ** </dd>
2679 **
2680 ** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
2681 ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
2682 ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
2683 ** interface independently of the [load_extension()] SQL function.
@@ -6527,10 +6533,11 @@
6533 ** to be attached to [database connection] D using name N. Subsequent
6534 ** calls to sqlite3_get_clientdata(D,N) will return a copy of pointer P
6535 ** or a NULL pointer if there were no prior calls to
6536 ** sqlite3_set_clientdata() with the same values of D and N.
6537 ** Names are compared using strcmp() and are thus case sensitive.
6538 ** It returns 0 on success and SQLITE_NOMEM on allocation failure.
6539 **
6540 ** If P and X are both non-NULL, then the destructor X is invoked with
6541 ** argument P on the first of the following occurrences:
6542 ** <ul>
6543 ** <li> An out-of-memory error occurs during the call to
@@ -10098,25 +10105,38 @@
10105 ** ^The third parameter is the name of the database that was written to -
10106 ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
10107 ** is the number of pages currently in the write-ahead log file,
10108 ** including those that were just committed.
10109 **
10110 ** ^The callback function should normally return [SQLITE_OK]. ^If an error
10111 ** code is returned, that error will propagate back up through the
10112 ** SQLite code base to cause the statement that provoked the callback
10113 ** to report an error, though the commit will have still occurred. If the
10114 ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
10115 ** that does not correspond to any valid SQLite error code, the results
10116 ** are undefined.
10117 **
10118 ** ^A single database handle may have at most a single write-ahead log
10119 ** callback registered at one time. ^Calling [sqlite3_wal_hook()]
10120 ** replaces the default behavior or previously registered write-ahead
10121 ** log callback.
10122 **
10123 ** ^The return value is a copy of the third parameter from the
10124 ** previous call, if any, or 0.
10125 **
10126 ** ^The [sqlite3_wal_autocheckpoint()] interface and the
10127 ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and
10128 ** will overwrite any prior [sqlite3_wal_hook()] settings.
10129 **
10130 ** ^If a write-ahead log callback is set using this function then
10131 ** [sqlite3_wal_checkpoint_v2()] or [PRAGMA wal_checkpoint]
10132 ** should be invoked periodically to keep the write-ahead log file
10133 ** from growing without bound.
10134 **
10135 ** ^Passing a NULL pointer for the callback disables automatic
10136 ** checkpointing entirely. To re-enable the default behavior, call
10137 ** sqlite3_wal_autocheckpoint(db,1000) or use [PRAGMA wal_checkpoint].
10138 */
10139 SQLITE_API void *sqlite3_wal_hook(
10140 sqlite3*,
10141 int(*)(void *,sqlite3*,const char*,int),
10142 void*
@@ -10129,11 +10149,11 @@
10149 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
10150 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
10151 ** to automatically [checkpoint]
10152 ** after committing a transaction if there are N or
10153 ** more frames in the [write-ahead log] file. ^Passing zero or
10154 ** a negative value as the N parameter disables automatic
10155 ** checkpoints entirely.
10156 **
10157 ** ^The callback registered by this function replaces any existing callback
10158 ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback
10159 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
@@ -10145,13 +10165,14 @@
10165 ** ^Checkpoints initiated by this mechanism are
10166 ** [sqlite3_wal_checkpoint_v2|PASSIVE].
10167 **
10168 ** ^Every new [database connection] defaults to having the auto-checkpoint
10169 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
10170 ** pages.
10171 **
10172 ** ^The use of this interface is only necessary if the default setting
10173 ** is found to be suboptimal for a particular application.
10174 */
10175 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
10176
10177 /*
10178 ** CAPI3REF: Checkpoint a database
@@ -10212,10 +10233,15 @@
10233 **
10234 ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
10235 ** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
10236 ** addition that it also truncates the log file to zero bytes just prior
10237 ** to a successful return.
10238 **
10239 ** <dt>SQLITE_CHECKPOINT_NOOP<dd>
10240 ** ^This mode always checkpoints zero frames. The only reason to invoke
10241 ** a NOOP checkpoint is to access the values returned by
10242 ** sqlite3_wal_checkpoint_v2() via output parameters *pnLog and *pnCkpt.
10243 ** </dl>
10244 **
10245 ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
10246 ** the log file or to -1 if the checkpoint could not run because
10247 ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
@@ -10282,10 +10308,11 @@
10308 ** These constants define all valid values for the "checkpoint mode" passed
10309 ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
10310 ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
10311 ** meaning of each of these checkpoint modes.
10312 */
10313 #define SQLITE_CHECKPOINT_NOOP -1 /* Do no work at all */
10314 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
10315 #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
10316 #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */
10317 #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
10318
@@ -11109,11 +11136,11 @@
11136 ** to avoid a memory leak.
11137 **
11138 ** The [sqlite3_snapshot_get()] interface is only available when the
11139 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
11140 */
11141 SQLITE_API int sqlite3_snapshot_get(
11142 sqlite3 *db,
11143 const char *zSchema,
11144 sqlite3_snapshot **ppSnapshot
11145 );
11146
@@ -11158,11 +11185,11 @@
11185 ** database connection in order to make it ready to use snapshots.)
11186 **
11187 ** The [sqlite3_snapshot_open()] interface is only available when the
11188 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
11189 */
11190 SQLITE_API int sqlite3_snapshot_open(
11191 sqlite3 *db,
11192 const char *zSchema,
11193 sqlite3_snapshot *pSnapshot
11194 );
11195
@@ -11175,11 +11202,11 @@
11202 ** using this routine to avoid a memory leak.
11203 **
11204 ** The [sqlite3_snapshot_free()] interface is only available when the
11205 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
11206 */
11207 SQLITE_API void sqlite3_snapshot_free(sqlite3_snapshot*);
11208
11209 /*
11210 ** CAPI3REF: Compare the ages of two snapshot handles.
11211 ** METHOD: sqlite3_snapshot
11212 **
@@ -11202,11 +11229,11 @@
11229 ** snapshot, and a positive value if P1 is a newer snapshot than P2.
11230 **
11231 ** This interface is only available if SQLite is compiled with the
11232 ** [SQLITE_ENABLE_SNAPSHOT] option.
11233 */
11234 SQLITE_API int sqlite3_snapshot_cmp(
11235 sqlite3_snapshot *p1,
11236 sqlite3_snapshot *p2
11237 );
11238
11239 /*
@@ -11230,11 +11257,11 @@
11257 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
11258 **
11259 ** This interface is only available if SQLite is compiled with the
11260 ** [SQLITE_ENABLE_SNAPSHOT] option.
11261 */
11262 SQLITE_API int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
11263
11264 /*
11265 ** CAPI3REF: Serialize a database
11266 **
11267 ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to
@@ -11304,16 +11331,17 @@
11331 /*
11332 ** CAPI3REF: Deserialize a database
11333 **
11334 ** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the
11335 ** [database connection] D to disconnect from database S and then
11336 ** reopen S as an in-memory database based on the serialization
11337 ** contained in P. If S is a NULL pointer, the main database is
11338 ** used. The serialized database P is N bytes in size. M is the size
11339 ** of the buffer P, which might be larger than N. If M is larger than
11340 ** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then
11341 ** SQLite is permitted to add content to the in-memory database as
11342 ** long as the total size does not exceed M bytes.
11343 **
11344 ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
11345 ** invoke sqlite3_free() on the serialization buffer when the database
11346 ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
11347 ** SQLite will try to increase the buffer size using sqlite3_realloc64()
@@ -14356,11 +14384,11 @@
14384
14385 /*
14386 ** Maximum number of pages in one database file.
14387 **
14388 ** This is really just the default value for the max_page_count pragma.
14389 ** This value can be lowered (or raised) at run-time using the
14390 ** max_page_count macro.
14391 */
14392 #ifndef SQLITE_MAX_PAGE_COUNT
14393 # define SQLITE_MAX_PAGE_COUNT 0xfffffffe /* 4294967294 */
14394 #endif
@@ -20086,10 +20114,11 @@
20114 #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */
20115 #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */
20116 #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */
20117 #define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */
20118 #define SF_Correlated 0x20000000 /* True if references the outer context */
20119 #define SF_OnToWhere 0x40000000 /* One or more ON clauses moved to WHERE */
20120
20121 /* True if SrcItem X is a subquery that has SF_NestedFrom */
20122 #define IsNestedFrom(X) \
20123 ((X)->fg.isSubquery && \
20124 ((X)->u4.pSubq->pSelect->selFlags&SF_NestedFrom)!=0)
@@ -20839,10 +20868,11 @@
20868 struct Table *pTab; /* Table of generated column */
20869 struct CoveringIndexCheck *pCovIdxCk; /* Check for covering index */
20870 SrcItem *pSrcItem; /* A single FROM clause item */
20871 DbFixer *pFix; /* See sqlite3FixSelect() */
20872 Mem *aMem; /* See sqlite3BtreeCursorHint() */
20873 struct CheckOnCtx *pCheckOnCtx; /* See selectCheckOnClauses() */
20874 } u;
20875 };
20876
20877 /*
20878 ** The following structure contains information used by the sqliteFix...
@@ -24209,11 +24239,14 @@
24239 Mem oldipk; /* Memory cell holding "old" IPK value */
24240 Mem *aNew; /* Array of new.* values */
24241 Table *pTab; /* Schema object being updated */
24242 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
24243 sqlite3_value **apDflt; /* Array of default values, if required */
24244 union {
24245 KeyInfo sKey;
24246 u8 keyinfoSpace[SZ_KEYINFO_0]; /* Space to hold pKeyinfo[0] content */
24247 } uKey;
24248 };
24249
24250 /*
24251 ** An instance of this object is used to pass an vector of values into
24252 ** OP_VFilter, the xFilter method of a virtual table. The vector is the
@@ -33486,13 +33519,17 @@
33519 sqlite3StrAccumFinish(&x);
33520 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
33521 n = 0;
33522 if( pItem->fg.isSubquery ) n++;
33523 if( pItem->fg.isTabFunc ) n++;
33524 if( pItem->fg.isUsing || pItem->u3.pOn!=0 ) n++;
33525 if( pItem->fg.isUsing ){
33526 sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING");
33527 }else if( pItem->u3.pOn!=0 ){
33528 sqlite3TreeViewItem(pView, "ON", (--n)>0);
33529 sqlite3TreeViewExpr(pView, pItem->u3.pOn, 0);
33530 sqlite3TreeViewPop(&pView);
33531 }
33532 if( pItem->fg.isSubquery ){
33533 assert( n==1 );
33534 if( pItem->pSTab ){
33535 Table *pTab = pItem->pSTab;
@@ -39437,14 +39474,15 @@
39474 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off64_t))\
39475 aSyscall[13].pCurrent)
39476
39477 #if defined(HAVE_FCHMOD)
39478 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
39479 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
39480 #else
39481 { "fchmod", (sqlite3_syscall_ptr)0, 0 },
39482 #define osFchmod(FID,MODE) 0
39483 #endif
 
39484
39485 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
39486 { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 },
39487 #else
39488 { "fallocate", (sqlite3_syscall_ptr)0, 0 },
@@ -40391,10 +40429,14 @@
40429 do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR );
40430 if( rc!=1 ){
40431 storeLastErrno(pFile, errno);
40432 return SQLITE_IOERR;
40433 }
40434 if( fsync(fd) ){
40435 storeLastErrno(pFile, errno);
40436 return SQLITE_IOERR_FSYNC;
40437 }
40438 rc = osFstat(fd, &statbuf);
40439 if( rc!=0 ){
40440 storeLastErrno(pFile, errno);
40441 return SQLITE_IOERR;
40442 }
@@ -40560,22 +40602,46 @@
40602 static int osSetPosixAdvisoryLock(
40603 int h, /* The file descriptor on which to take the lock */
40604 struct flock *pLock, /* The description of the lock */
40605 unixFile *pFile /* Structure holding timeout value */
40606 ){
40607 int rc = 0;
40608
40609 if( pFile->iBusyTimeout==0 ){
40610 /* unixFile->iBusyTimeout is set to 0. In this case, attempt a
40611 ** non-blocking lock. */
40612 rc = osFcntl(h,F_SETLK,pLock);
40613 }else{
40614 /* unixFile->iBusyTimeout is set to greater than zero. In this case,
40615 ** attempt a blocking-lock with a unixFile->iBusyTimeout ms timeout.
40616 **
40617 ** On systems that support some kind of blocking file lock operation,
40618 ** this block should be replaced by code to attempt a blocking lock
40619 ** with a timeout of unixFile->iBusyTimeout ms. The code below is
40620 ** placeholder code. If SQLITE_TEST is defined, the placeholder code
40621 ** retries the lock once every 1ms until it succeeds or the timeout
40622 ** is reached. Or, if SQLITE_TEST is not defined, the placeholder
40623 ** code attempts a non-blocking lock and sets unixFile->iBusyTimeout
40624 ** to 0. This causes the caller to return SQLITE_BUSY, instead of
40625 ** SQLITE_BUSY_TIMEOUT to SQLite - as required by a VFS that does not
40626 ** support blocking locks.
40627 */
40628 #ifdef SQLITE_TEST
40629 int tm = pFile->iBusyTimeout;
40630 while( tm>0 ){
40631 rc = osFcntl(h,F_SETLK,pLock);
40632 if( rc==0 ) break;
40633 unixSleep(0,1000);
40634 tm--;
40635 }
40636 #else
40637 rc = osFcntl(h,F_SETLK,pLock);
40638 pFile->iBusyTimeout = 0;
40639 #endif
40640 /* End of code to replace with real blocking-locks code. */
40641 }
40642
40643 return rc;
40644 }
40645 #endif /* SQLITE_ENABLE_SETLK_TIMEOUT */
40646
40647
@@ -51349,33 +51415,39 @@
51415 ** log-summary, each thread has its own winFile object, but they all
51416 ** point to a single instance of this object. In other words, each
51417 ** log-summary is opened only once per process.
51418 **
51419 ** winShmMutexHeld() must be true when creating or destroying
51420 ** this object, or while editing the global linked list that starts
51421 ** at winShmNodeList.
51422 **
51423 ** When reading or writing the linked list starting at winShmNode.pWinShmList,
51424 ** pShmNode->mutex must be held.
51425 **
51426 ** The following fields are constant after the object is created:
51427 **
51428 ** zFilename
51429 ** hSharedShm
51430 ** mutex
51431 ** bUseSharedLockHandle
51432 **
51433 ** Either winShmNode.mutex must be held or winShmNode.pWinShmList==0 and
51434 ** winShmMutexHeld() is true when reading or writing any other field
51435 ** in this structure.
51436 **
51437 ** File-handle hSharedShm is always used to (a) take the DMS lock, (b)
51438 ** truncate the *-shm file if the DMS-locking protocol demands it, and
51439 ** (c) map regions of the *-shm file into memory using MapViewOfFile()
51440 ** or similar. If bUseSharedLockHandle is true, then other locks are also
51441 ** taken on hSharedShm. Or, if bUseSharedLockHandle is false, then other
51442 ** locks are taken using each connection's winShm.hShm handles.
51443 */
51444 struct winShmNode {
51445 sqlite3_mutex *mutex; /* Mutex to access this object */
51446 char *zFilename; /* Name of the file */
51447 HANDLE hSharedShm; /* File handle open on zFilename */
51448 int bUseSharedLockHandle; /* True to use hSharedShm for everything */
51449
51450 int isUnlocked; /* DMS lock has not yet been obtained */
51451 int isReadonly; /* True if read-only */
51452 int szRegion; /* Size of shared-memory regions */
51453 int nRegion; /* Size of array apRegion */
@@ -51384,11 +51456,12 @@
51456 HANDLE hMap; /* File handle from CreateFileMapping */
51457 void *pMap;
51458 } *aRegion;
51459 DWORD lastErrno; /* The Windows errno from the last I/O error */
51460
51461 winShm *pWinShmList; /* List of winShm objects with ptrs to this */
51462
51463 winShmNode *pNext; /* Next in list of all winShmNode objects */
51464 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
51465 u8 nextShmId; /* Next available winShm.id value */
51466 #endif
51467 };
@@ -51412,10 +51485,11 @@
51485 HANDLE hShm; /* File-handle on *-shm file. For locking. */
51486 int bReadonly; /* True if hShm is opened read-only */
51487 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
51488 u8 id; /* Id of this connection with its winShmNode */
51489 #endif
51490 winShm *pWinShmNext; /* Next winShm object on same winShmNode */
51491 };
51492
51493 /*
51494 ** Constants used for locking
51495 */
@@ -51425,11 +51499,11 @@
51499 /* Forward references to VFS methods */
51500 static int winOpen(sqlite3_vfs*,const char*,sqlite3_file*,int,int*);
51501 static int winDelete(sqlite3_vfs *,const char*,int);
51502
51503 /*
51504 ** Purge the winShmNodeList list of all entries with winShmNode.pWinShmList==0.
51505 **
51506 ** This is not a VFS shared-memory method; it is a utility function called
51507 ** by VFS shared-memory methods.
51508 */
51509 static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
@@ -51438,11 +51512,11 @@
51512 assert( winShmMutexHeld() );
51513 OSTRACE(("SHM-PURGE pid=%lu, deleteFlag=%d\n",
51514 osGetCurrentProcessId(), deleteFlag));
51515 pp = &winShmNodeList;
51516 while( (p = *pp)!=0 ){
51517 if( p->pWinShmList==0 ){
51518 int i;
51519 if( p->mutex ){ sqlite3_mutex_free(p->mutex); }
51520 for(i=0; i<p->nRegion; i++){
51521 BOOL bRc = osUnmapViewOfFile(p->aRegion[i].pMap);
51522 OSTRACE(("SHM-PURGE-UNMAP pid=%lu, region=%d, rc=%s\n",
@@ -51602,10 +51676,64 @@
51676 *pbReadonly = bReadonly;
51677 *ph = h;
51678 return rc;
51679 }
51680
51681 /*
51682 ** Close pDbFd's connection to shared-memory. Delete the underlying
51683 ** *-shm file if deleteFlag is true.
51684 */
51685 static int winCloseSharedMemory(winFile *pDbFd, int deleteFlag){
51686 winShm *p; /* The connection to be closed */
51687 winShm **pp; /* Iterator for pShmNode->pWinShmList */
51688 winShmNode *pShmNode; /* The underlying shared-memory file */
51689
51690 p = pDbFd->pShm;
51691 if( p==0 ) return SQLITE_OK;
51692 if( p->hShm!=INVALID_HANDLE_VALUE ){
51693 osCloseHandle(p->hShm);
51694 }
51695
51696 winShmEnterMutex();
51697 pShmNode = p->pShmNode;
51698
51699 /* Remove this connection from the winShmNode.pWinShmList list */
51700 sqlite3_mutex_enter(pShmNode->mutex);
51701 for(pp=&pShmNode->pWinShmList; *pp!=p; pp=&(*pp)->pWinShmNext){}
51702 *pp = p->pWinShmNext;
51703 sqlite3_mutex_leave(pShmNode->mutex);
51704
51705 winShmPurge(pDbFd->pVfs, deleteFlag);
51706 winShmLeaveMutex();
51707
51708 /* Free the connection p */
51709 sqlite3_free(p);
51710 pDbFd->pShm = 0;
51711 return SQLITE_OK;
51712 }
51713
51714 /*
51715 ** testfixture builds may set this global variable to true via a
51716 ** Tcl interface. This forces the VFS to use the locking normally
51717 ** only used for UNC paths for all files.
51718 */
51719 #ifdef SQLITE_TEST
51720 SQLITE_API int sqlite3_win_test_unc_locking = 0;
51721 #else
51722 # define sqlite3_win_test_unc_locking 0
51723 #endif
51724
51725 /*
51726 ** Return true if the string passed as the only argument is likely
51727 ** to be a UNC path. In other words, if it starts with "\\".
51728 */
51729 static int winIsUNCPath(const char *zFile){
51730 if( zFile[0]=='\\' && zFile[1]=='\\' ){
51731 return 1;
51732 }
51733 return sqlite3_win_test_unc_locking;
51734 }
51735
51736 /*
51737 ** Open the shared-memory area associated with database file pDbFd.
51738 */
51739 static int winOpenSharedMemory(winFile *pDbFd){
@@ -51628,19 +51756,14 @@
51756 return SQLITE_IOERR_NOMEM_BKPT;
51757 }
51758 pNew->zFilename = (char*)&pNew[1];
51759 pNew->hSharedShm = INVALID_HANDLE_VALUE;
51760 pNew->isUnlocked = 1;
51761 pNew->bUseSharedLockHandle = winIsUNCPath(pDbFd->zPath);
51762 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
51763 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
51764
 
 
 
 
 
 
51765 /* Look to see if there is an existing winShmNode that can be used.
51766 ** If no matching winShmNode currently exists, then create a new one. */
51767 winShmEnterMutex();
51768 for(pShmNode = winShmNodeList; pShmNode; pShmNode=pShmNode->pNext){
51769 /* TBD need to come up with better match here. Perhaps
@@ -51657,11 +51780,11 @@
51780 }
51781
51782 /* Open a file-handle to use for mappings, and for the DMS lock. */
51783 if( rc==SQLITE_OK ){
51784 HANDLE h = INVALID_HANDLE_VALUE;
51785 pShmNode->isReadonly = sqlite3_uri_boolean(pDbFd->zPath,"readonly_shm",0);
51786 rc = winHandleOpen(pNew->zFilename, &pShmNode->isReadonly, &h);
51787 pShmNode->hSharedShm = h;
51788 }
51789
51790 /* If successful, link the new winShmNode into the global list. If an
@@ -51679,24 +51802,39 @@
51802 }
51803
51804 /* If no error has occurred, link the winShm object to the winShmNode and
51805 ** the winShm to pDbFd. */
51806 if( rc==SQLITE_OK ){
51807 sqlite3_mutex_enter(pShmNode->mutex);
51808 p->pShmNode = pShmNode;
51809 p->pWinShmNext = pShmNode->pWinShmList;
51810 pShmNode->pWinShmList = p;
51811 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
51812 p->id = pShmNode->nextShmId++;
51813 #endif
51814 pDbFd->pShm = p;
51815 sqlite3_mutex_leave(pShmNode->mutex);
51816 }else if( p ){
 
51817 sqlite3_free(p);
51818 }
51819
51820 assert( rc!=SQLITE_OK || pShmNode->isUnlocked==0 || pShmNode->nRegion==0 );
51821 winShmLeaveMutex();
51822 sqlite3_free(pNew);
51823
51824 /* Open a file-handle on the *-shm file for this connection. This file-handle
51825 ** is only used for locking. The mapping of the *-shm file is created using
51826 ** the shared file handle in winShmNode.hSharedShm. */
51827 if( rc==SQLITE_OK && pShmNode->bUseSharedLockHandle==0 ){
51828 p->bReadonly = sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0);
51829 rc = winHandleOpen(pShmNode->zFilename, &p->bReadonly, &p->hShm);
51830 if( rc!=SQLITE_OK ){
51831 assert( p->hShm==INVALID_HANDLE_VALUE );
51832 winCloseSharedMemory(pDbFd, 0);
51833 }
51834 }
51835
51836 return rc;
51837 }
51838
51839 /*
51840 ** Close a connection to shared-memory. Delete the underlying
@@ -51704,37 +51842,11 @@
51842 */
51843 static int winShmUnmap(
51844 sqlite3_file *fd, /* Database holding shared memory */
51845 int deleteFlag /* Delete after closing if true */
51846 ){
51847 return winCloseSharedMemory((winFile*)fd, deleteFlag);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51848 }
51849
51850 /*
51851 ** Change the lock state for a shared-memory segment.
51852 */
@@ -51799,29 +51911,75 @@
51911 );
51912 if( ((flags & SQLITE_SHM_UNLOCK) && ((p->exclMask|p->sharedMask) & mask))
51913 || (flags==(SQLITE_SHM_SHARED|SQLITE_SHM_LOCK) && 0==(p->sharedMask & mask))
51914 || (flags==(SQLITE_SHM_EXCLUSIVE|SQLITE_SHM_LOCK))
51915 ){
51916 HANDLE h = p->hShm;
51917
51918 if( flags & SQLITE_SHM_UNLOCK ){
51919 /* Case (a) - unlock. */
51920
51921 assert( (p->exclMask & p->sharedMask)==0 );
51922 assert( !(flags & SQLITE_SHM_EXCLUSIVE) || (p->exclMask & mask)==mask );
51923 assert( !(flags & SQLITE_SHM_SHARED) || (p->sharedMask & mask)==mask );
51924
51925 assert( !(flags & SQLITE_SHM_SHARED) || n==1 );
51926 if( pShmNode->bUseSharedLockHandle ){
51927 h = pShmNode->hSharedShm;
51928 if( flags & SQLITE_SHM_SHARED ){
51929 winShm *pShm;
51930 sqlite3_mutex_enter(pShmNode->mutex);
51931 for(pShm=pShmNode->pWinShmList; pShm; pShm=pShm->pWinShmNext){
51932 if( pShm!=p && (pShm->sharedMask & mask) ){
51933 /* Another connection within this process is also holding this
51934 ** SHARED lock. So do not actually release the OS lock. */
51935 h = INVALID_HANDLE_VALUE;
51936 break;
51937 }
51938 }
51939 sqlite3_mutex_leave(pShmNode->mutex);
51940 }
51941 }
51942
51943 if( h!=INVALID_HANDLE_VALUE ){
51944 rc = winHandleUnlock(h, ofst+WIN_SHM_BASE, n);
51945 }
51946
51947 /* If successful, also clear the bits in sharedMask/exclMask */
51948 if( rc==SQLITE_OK ){
51949 p->exclMask = (p->exclMask & ~mask);
51950 p->sharedMask = (p->sharedMask & ~mask);
51951 }
51952 }else{
51953 int bExcl = ((flags & SQLITE_SHM_EXCLUSIVE) ? 1 : 0);
51954 DWORD nMs = winFileBusyTimeout(pDbFd);
51955
51956 if( pShmNode->bUseSharedLockHandle ){
51957 winShm *pShm;
51958 h = pShmNode->hSharedShm;
51959 sqlite3_mutex_enter(pShmNode->mutex);
51960 for(pShm=pShmNode->pWinShmList; pShm; pShm=pShm->pWinShmNext){
51961 if( bExcl ){
51962 if( (pShm->sharedMask|pShm->exclMask) & mask ){
51963 rc = SQLITE_BUSY;
51964 h = INVALID_HANDLE_VALUE;
51965 }
51966 }else{
51967 if( pShm->sharedMask & mask ){
51968 h = INVALID_HANDLE_VALUE;
51969 }else if( pShm->exclMask & mask ){
51970 rc = SQLITE_BUSY;
51971 h = INVALID_HANDLE_VALUE;
51972 }
51973 }
51974 }
51975 sqlite3_mutex_leave(pShmNode->mutex);
51976 }
51977
51978 if( h!=INVALID_HANDLE_VALUE ){
51979 rc = winHandleLockTimeout(h, ofst+WIN_SHM_BASE, n, bExcl, nMs);
51980 }
51981 if( rc==SQLITE_OK ){
51982 if( bExcl ){
51983 p->exclMask = (p->exclMask | mask);
51984 }else{
51985 p->sharedMask = (p->sharedMask | mask);
@@ -65748,11 +65906,11 @@
65906 */
65907 sqlite3_exec(db, "PRAGMA table_list",0,0,0);
65908 }
65909 if( pPager->pWal ){
65910 rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode,
65911 (eMode<=SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
65912 pPager->pBusyHandlerArg,
65913 pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
65914 pnLog, pnCkpt
65915 );
65916 }
@@ -70353,11 +70511,12 @@
70511 assert( pWal->ckptLock==0 );
70512 assert( pWal->writeLock==0 );
70513
70514 /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
70515 ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
70516 assert( SQLITE_CHECKPOINT_NOOP<SQLITE_CHECKPOINT_PASSIVE );
70517 assert( eMode>SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
70518
70519 if( pWal->readOnly ) return SQLITE_READONLY;
70520 WALTRACE(("WAL%p: checkpoint begins\n", pWal));
70521
70522 /* Enable blocking locks, if possible. */
@@ -70370,35 +70529,39 @@
70529 ** checkpoint operation at the same time, the lock cannot be obtained and
70530 ** SQLITE_BUSY is returned.
70531 ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured,
70532 ** it will not be invoked in this case.
70533 */
70534 if( eMode!=SQLITE_CHECKPOINT_NOOP ){
70535 rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
70536 testcase( rc==SQLITE_BUSY );
70537 testcase( rc!=SQLITE_OK && xBusy2!=0 );
70538 if( rc==SQLITE_OK ){
70539 pWal->ckptLock = 1;
70540
70541 /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART
70542 ** and TRUNCATE modes also obtain the exclusive "writer" lock on the
70543 ** database file.
70544 **
70545 ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained
70546 ** immediately, and a busy-handler is configured, it is invoked and the
70547 ** writer lock retried until either the busy-handler returns 0 or the
70548 ** lock is successfully obtained.
70549 */
70550 if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){
70551 rc = walBusyLock(pWal, xBusy2, pBusyArg, WAL_WRITE_LOCK, 1);
70552 if( rc==SQLITE_OK ){
70553 pWal->writeLock = 1;
70554 }else if( rc==SQLITE_BUSY ){
70555 eMode2 = SQLITE_CHECKPOINT_PASSIVE;
70556 xBusy2 = 0;
70557 rc = SQLITE_OK;
70558 }
70559 }
70560 }
70561 }else{
70562 rc = SQLITE_OK;
70563 }
70564
70565
70566 /* Read the wal-index header. */
70567 SEH_TRY {
@@ -70408,21 +70571,21 @@
70571 ** or invoke the busy handler. The only lock such a checkpoint may
70572 ** attempt to obtain is a lock on a read-slot, and it should give up
70573 ** immediately and do a partial checkpoint if it cannot obtain it. */
70574 walDisableBlocking(pWal);
70575 rc = walIndexReadHdr(pWal, &isChanged);
70576 if( eMode2>SQLITE_CHECKPOINT_PASSIVE ) (void)walEnableBlocking(pWal);
70577 if( isChanged && pWal->pDbFd->pMethods->iVersion>=3 ){
70578 sqlite3OsUnfetch(pWal->pDbFd, 0, 0);
70579 }
70580 }
70581
70582 /* Copy data from the log to the database file. */
70583 if( rc==SQLITE_OK ){
70584 if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){
70585 rc = SQLITE_CORRUPT_BKPT;
70586 }else if( eMode2!=SQLITE_CHECKPOINT_NOOP ){
70587 rc = walCheckpoint(pWal, db, eMode2, xBusy2, pBusyArg, sync_flags,zBuf);
70588 }
70589
70590 /* If no error occurred, set the output variables. */
70591 if( rc==SQLITE_OK || rc==SQLITE_BUSY ){
@@ -91645,11 +91808,11 @@
91808
91809 preupdate.v = v;
91810 preupdate.pCsr = pCsr;
91811 preupdate.op = op;
91812 preupdate.iNewReg = iReg;
91813 preupdate.pKeyinfo = &preupdate.uKey.sKey;
91814 preupdate.pKeyinfo->db = db;
91815 preupdate.pKeyinfo->enc = ENC(db);
91816 preupdate.pKeyinfo->nKeyField = pTab->nCol;
91817 preupdate.pKeyinfo->aSortFlags = 0; /* Indicate .aColl, .nAllField uninit */
91818 preupdate.iKey1 = iKey1;
@@ -102528,10 +102691,11 @@
102691 aRes[1] = aRes[2] = -1;
102692 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
102693 || pOp->p2==SQLITE_CHECKPOINT_FULL
102694 || pOp->p2==SQLITE_CHECKPOINT_RESTART
102695 || pOp->p2==SQLITE_CHECKPOINT_TRUNCATE
102696 || pOp->p2==SQLITE_CHECKPOINT_NOOP
102697 );
102698 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
102699 if( rc ){
102700 if( rc!=SQLITE_BUSY ) goto abort_due_to_error;
102701 rc = SQLITE_OK;
@@ -110651,18 +110815,21 @@
110815 ExprList *pList /* Expression list to resolve. May be NULL. */
110816 ){
110817 SrcList *pSrc; /* Fake SrcList for pParse->pNewTable */
110818 NameContext sNC; /* Name context for pParse->pNewTable */
110819 int rc;
110820 union {
110821 SrcList sSrc;
110822 u8 srcSpace[SZ_SRCLIST_1]; /* Memory space for the fake SrcList */
110823 } uSrc;
110824
110825 assert( type==0 || pTab!=0 );
110826 assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr
110827 || type==NC_GenCol || pTab==0 );
110828 memset(&sNC, 0, sizeof(sNC));
110829 memset(&uSrc, 0, sizeof(uSrc));
110830 pSrc = &uSrc.sSrc;
110831 if( pTab ){
110832 pSrc->nSrc = 1;
110833 pSrc->a[0].zName = pTab->zName;
110834 pSrc->a[0].pSTab = pTab;
110835 pSrc->a[0].iCursor = -1;
@@ -111920,10 +112087,15 @@
112087 }
112088 if( IsWindowFunc(pExpr) ){
112089 sqlite3ExprOrderByAggregateError(pParse, pExpr);
112090 sqlite3ExprListDelete(db, pOrderBy);
112091 return;
112092 }
112093 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
112094 sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
112095 sqlite3ExprListDelete(db, pOrderBy);
112096 return;
112097 }
112098
112099 pOB = sqlite3ExprAlloc(db, TK_ORDER, 0, 0);
112100 if( pOB==0 ){
112101 sqlite3ExprListDelete(db, pOrderBy);
@@ -114683,11 +114855,10 @@
114855 int destIfNull /* Jump here if the results are unknown due to NULLs */
114856 ){
114857 int rRhsHasNull = 0; /* Register that is true if RHS contains NULL values */
114858 int eType; /* Type of the RHS */
114859 int rLhs; /* Register(s) holding the LHS values */
 
114860 Vdbe *v; /* Statement under construction */
114861 int *aiMap = 0; /* Map from vector field to index column */
114862 char *zAff = 0; /* Affinity string for comparisons */
114863 int nVector; /* Size of vectors for this IN operator */
114864 int iDummy; /* Dummy parameter to exprCodeVector() */
@@ -114746,23 +114917,12 @@
114917 ** Avoid factoring the LHS of the IN(...) expression out of the loop,
114918 ** even if it is constant, as OP_Affinity may be used on the register
114919 ** by code generated below. */
114920 assert( pParse->okConstFactor==okConstFactor );
114921 pParse->okConstFactor = 0;
114922 rLhs = exprCodeVector(pParse, pLeft, &iDummy);
114923 pParse->okConstFactor = okConstFactor;
 
 
 
 
 
 
 
 
 
 
 
114924
114925 /* If sqlite3FindInIndex() did not find or create an index that is
114926 ** suitable for evaluating the IN operator, then evaluate using a
114927 ** sequence of comparisons.
114928 **
@@ -114773,10 +114933,11 @@
114933 CollSeq *pColl;
114934 int labelOk = sqlite3VdbeMakeLabel(pParse);
114935 int r2, regToFree;
114936 int regCkNull = 0;
114937 int ii;
114938 assert( nVector==1 );
114939 assert( ExprUseXList(pExpr) );
114940 pList = pExpr->x.pList;
114941 pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
114942 if( destIfNull!=destIfFalse ){
114943 regCkNull = sqlite3GetTempReg(pParse);
@@ -114813,10 +114974,30 @@
114974 }
114975 sqlite3VdbeResolveLabel(v, labelOk);
114976 sqlite3ReleaseTempReg(pParse, regCkNull);
114977 goto sqlite3ExprCodeIN_finished;
114978 }
114979
114980 if( eType!=IN_INDEX_ROWID ){
114981 /* If this IN operator will use an index, then the order of columns in the
114982 ** vector might be different from the order in the index. In that case,
114983 ** we need to reorder the LHS values to be in index order. Run Affinity
114984 ** before reordering the columns, so that the affinity is correct.
114985 */
114986 sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
114987 for(i=0; i<nVector && aiMap[i]==i; i++){} /* Are LHS fields reordered? */
114988 if( i!=nVector ){
114989 /* Need to reorder the LHS fields according to aiMap */
114990 int rLhsOrig = rLhs;
114991 rLhs = sqlite3GetTempRange(pParse, nVector);
114992 for(i=0; i<nVector; i++){
114993 sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0);
114994 }
114995 sqlite3ReleaseTempReg(pParse, rLhsOrig);
114996 }
114997 }
114998
114999
115000 /* Step 2: Check to see if the LHS contains any NULL columns. If the
115001 ** LHS does contain NULLs then the result must be either FALSE or NULL.
115002 ** We will then skip the binary search of the RHS.
115003 */
@@ -114840,15 +115021,15 @@
115021 */
115022 if( eType==IN_INDEX_ROWID ){
115023 /* In this case, the RHS is the ROWID of table b-tree and so we also
115024 ** know that the RHS is non-NULL. Hence, we combine steps 3 and 4
115025 ** into a single opcode. */
115026 assert( nVector==1 );
115027 sqlite3VdbeAddOp3(v, OP_SeekRowid, iTab, destIfFalse, rLhs);
115028 VdbeCoverage(v);
115029 addrTruthOp = sqlite3VdbeAddOp0(v, OP_Goto); /* Return True */
115030 }else{
 
115031 if( destIfFalse==destIfNull ){
115032 /* Combine Step 3 and Step 5 into a single opcode */
115033 if( ExprHasProperty(pExpr, EP_Subrtn) ){
115034 const VdbeOp *pOp = sqlite3VdbeGetOp(v, pExpr->y.sub.iAddr);
115035 assert( pOp->opcode==OP_Once || pParse->nErr );
@@ -114922,11 +115103,10 @@
115103
115104 /* Jumps here in order to return true. */
115105 sqlite3VdbeJumpHere(v, addrTruthOp);
115106
115107 sqlite3ExprCodeIN_finished:
 
115108 VdbeComment((v, "end IN expr"));
115109 sqlite3ExprCodeIN_oom_error:
115110 sqlite3DbFree(pParse->db, aiMap);
115111 sqlite3DbFree(pParse->db, zAff);
115112 }
@@ -124573,11 +124753,11 @@
124753 */
124754 SQLITE_PRIVATE int sqlite3TableColumnToIndex(Index *pIdx, int iCol){
124755 int i;
124756 i16 iCol16;
124757 assert( iCol>=(-1) && iCol<=SQLITE_MAX_COLUMN );
124758 assert( pIdx->nColumn<=SQLITE_MAX_COLUMN*2 );
124759 iCol16 = iCol;
124760 for(i=0; i<pIdx->nColumn; i++){
124761 if( iCol16==pIdx->aiColumn[i] ){
124762 return i;
124763 }
@@ -129165,18 +129345,23 @@
129345 pKey->aSortFlags[i] = pIdx->aSortOrder[i];
129346 assert( 0==(pKey->aSortFlags[i] & KEYINFO_ORDER_BIGNULL) );
129347 }
129348 if( pParse->nErr ){
129349 assert( pParse->rc==SQLITE_ERROR_MISSING_COLLSEQ );
129350 if( pIdx->bNoQuery==0
129351 && sqlite3HashFind(&pIdx->pSchema->idxHash, pIdx->zName)
129352 ){
129353 /* Deactivate the index because it contains an unknown collating
129354 ** sequence. The only way to reactive the index is to reload the
129355 ** schema. Adding the missing collating sequence later does not
129356 ** reactive the index. The application had the chance to register
129357 ** the missing index using the collation-needed callback. For
129358 ** simplicity, SQLite will not give the application a second chance.
129359 **
129360 ** Except, do not do this if the index is not in the schema hash
129361 ** table. In this case the index is currently being constructed
129362 ** by a CREATE INDEX statement, and retrying will not help. */
129363 pIdx->bNoQuery = 1;
129364 pParse->rc = SQLITE_ERROR_RETRY;
129365 }
129366 sqlite3KeyInfoUnref(pKey);
129367 pKey = 0;
@@ -143548,10 +143733,12 @@
143733 eMode = SQLITE_CHECKPOINT_FULL;
143734 }else if( sqlite3StrICmp(zRight, "restart")==0 ){
143735 eMode = SQLITE_CHECKPOINT_RESTART;
143736 }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
143737 eMode = SQLITE_CHECKPOINT_TRUNCATE;
143738 }else if( sqlite3StrICmp(zRight, "noop")==0 ){
143739 eMode = SQLITE_CHECKPOINT_NOOP;
143740 }
143741 }
143742 pParse->nMem = 3;
143743 sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
143744 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
@@ -145114,13 +145301,15 @@
145301 ** or encounters a permanent error. A schema problem after one schema
145302 ** reset is considered a permanent error. */
145303 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
145304 assert( rc==SQLITE_OK || *ppStmt==0 );
145305 if( rc==SQLITE_OK || db->mallocFailed ) break;
145306 cnt++;
145307 }while( (rc==SQLITE_ERROR_RETRY && ALWAYS(cnt<=SQLITE_MAX_PREPARE_RETRY))
145308 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt)==1) );
145309 sqlite3BtreeLeaveAll(db);
145310 assert( rc!=SQLITE_ERROR_RETRY );
145311 rc = sqlite3ApiExit(db, rc);
145312 assert( (rc&db->errMask)==rc );
145313 db->busyHandler.nBusy = 0;
145314 sqlite3_mutex_leave(db->mutex);
145315 assert( rc==SQLITE_OK || (*ppStmt)==0 );
@@ -145790,12 +145979,11 @@
145979 while( p ){
145980 ExprSetProperty(p, joinFlag);
145981 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
145982 ExprSetVVAProperty(p, EP_NoReduce);
145983 p->w.iJoin = iTable;
145984 if( ExprUseXList(p) ){
 
145985 if( p->x.pList ){
145986 int i;
145987 for(i=0; i<p->x.pList->nExpr; i++){
145988 sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable, joinFlag);
145989 }
@@ -146007,10 +146195,11 @@
146195 else if( pRight->u3.pOn ){
146196 sqlite3SetJoinExpr(pRight->u3.pOn, pRight->iCursor, joinType);
146197 p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->u3.pOn);
146198 pRight->u3.pOn = 0;
146199 pRight->fg.isOn = 1;
146200 p->selFlags |= SF_OnToWhere;
146201 }
146202 }
146203 return 0;
146204 }
146205
@@ -146893,11 +147082,14 @@
147082 ** Allocate a KeyInfo object sufficient for an index of N key columns and
147083 ** X extra columns.
147084 */
147085 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
147086 int nExtra = (N+X)*(sizeof(CollSeq*)+1);
147087 KeyInfo *p;
147088 assert( X>=0 );
147089 if( NEVER(N+X>0xffff) ) return (KeyInfo*)sqlite3OomFault(db);
147090 p = sqlite3DbMallocRawNN(db, SZ_KEYINFO(0) + nExtra);
147091 if( p ){
147092 p->aSortFlags = (u8*)&p->aColl[N+X];
147093 p->nKeyField = (u16)N;
147094 p->nAllField = (u16)(N+X);
147095 p->enc = ENC(db);
@@ -149212,11 +149404,11 @@
149404 ** expressions in pEList.
149405 **
149406 ** ## About "isOuterJoin":
149407 **
149408 ** The isOuterJoin column indicates that the replacement will occur into a
149409 ** position in the parent that is NULL-able due to an OUTER JOIN. Either the
149410 ** target slot in the parent is the right operand of a LEFT JOIN, or one of
149411 ** the left operands of a RIGHT JOIN. In either case, we need to potentially
149412 ** bypass the substituted expression with OP_IfNullRow.
149413 **
149414 ** Suppose the original expression is an integer constant. Even though the table
@@ -150050,21 +150242,16 @@
150242 ** elements we are now copying in.
150243 */
150244 pSub = pSub1;
150245 for(pParent=p; pParent; pParent=pParent->pPrior, pSub=pSub->pPrior){
150246 int nSubSrc;
150247 u8 jointype = pSubitem->fg.jointype;
 
150248 assert( pSub!=0 );
150249 pSubSrc = pSub->pSrc; /* FROM clause of subquery */
150250 nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
150251 pSrc = pParent->pSrc; /* FROM clause of the outer query */
150252
 
 
 
 
150253 /* The subquery uses a single slot of the FROM clause of the outer
150254 ** query. If the subquery has more than one element in its FROM clause,
150255 ** then expand the outer query to make space for it to hold all elements
150256 ** of the subquery.
150257 **
@@ -150080,10 +150267,11 @@
150267 */
150268 if( nSubSrc>1 ){
150269 pSrc = sqlite3SrcListEnlarge(pParse, pSrc, nSubSrc-1,iFrom+1);
150270 if( pSrc==0 ) break;
150271 pParent->pSrc = pSrc;
150272 pSubitem = &pSrc->a[iFrom];
150273 }
150274
150275 /* Transfer the FROM clause terms from the subquery into the
150276 ** outer query.
150277 */
@@ -150094,15 +150282,14 @@
150282 assert( pItem->fg.isSubquery
150283 || pItem->fg.fixedSchema
150284 || pItem->u4.zDatabase==0 );
150285 if( pItem->fg.isUsing ) sqlite3IdListDelete(db, pItem->u3.pUsing);
150286 *pItem = pSubSrc->a[i];
150287 pItem->fg.jointype |= (jointype & JT_LTORJ);
150288 memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
150289 }
150290 pSubitem->fg.jointype |= jointype;
 
150291
150292 /* Now begin substituting subquery result set expressions for
150293 ** references to the iParent in the outer query.
150294 **
150295 ** Example:
@@ -152838,10 +153025,119 @@
153025 existsToJoin(pParse, p, pSubWhere);
153026 }
153027 }
153028 }
153029 }
153030
153031 /*
153032 ** Type used for Walker callbacks by selectCheckOnClauses().
153033 */
153034 typedef struct CheckOnCtx CheckOnCtx;
153035 struct CheckOnCtx {
153036 SrcList *pSrc; /* SrcList for this context */
153037 int iJoin; /* Cursor numbers must be =< than this */
153038 CheckOnCtx *pParent; /* Parent context */
153039 };
153040
153041 /*
153042 ** True if the SrcList passed as the only argument contains at least
153043 ** one RIGHT or FULL JOIN. False otherwise.
153044 */
153045 #define hasRightJoin(pSrc) (((pSrc)->a[0].fg.jointype & JT_LTORJ)!=0)
153046
153047 /*
153048 ** The xExpr callback for the search of invalid ON clause terms.
153049 */
153050 static int selectCheckOnClausesExpr(Walker *pWalker, Expr *pExpr){
153051 CheckOnCtx *pCtx = pWalker->u.pCheckOnCtx;
153052
153053 /* Check if pExpr is root or near-root of an ON clause constraint that needs
153054 ** to be checked to ensure that it does not refer to tables in its FROM
153055 ** clause to the right of itself. i.e. it is either:
153056 **
153057 ** + an ON clause on an OUTER join, or
153058 ** + an ON clause on an INNER join within a FROM that features at
153059 ** least one RIGHT or FULL join.
153060 */
153061 if( (ExprHasProperty(pExpr, EP_OuterON))
153062 || (ExprHasProperty(pExpr, EP_InnerON) && hasRightJoin(pCtx->pSrc))
153063 ){
153064 /* If CheckOnCtx.iJoin is already set, then fall through and process
153065 ** this expression node as normal. Or, if CheckOnCtx.iJoin is still 0,
153066 ** set it to the cursor number of the RHS of the join to which this
153067 ** ON expression was attached and then iterate through the entire
153068 ** expression. */
153069 assert( pCtx->iJoin==0 || pCtx->iJoin==pExpr->w.iJoin );
153070 if( pCtx->iJoin==0 ){
153071 pCtx->iJoin = pExpr->w.iJoin;
153072 sqlite3WalkExprNN(pWalker, pExpr);
153073 pCtx->iJoin = 0;
153074 return WRC_Prune;
153075 }
153076 }
153077
153078 if( pExpr->op==TK_COLUMN ){
153079 /* A column expression. Find the SrcList (if any) to which it refers.
153080 ** Then, if CheckOnCtx.iJoin indicates that this expression is part of an
153081 ** ON clause from that SrcList (i.e. if iJoin is non-zero), check that it
153082 ** does not refer to a table to the right of CheckOnCtx.iJoin. */
153083 do {
153084 SrcList *pSrc = pCtx->pSrc;
153085 int iTab = pExpr->iTable;
153086 if( iTab>=pSrc->a[0].iCursor && iTab<=pSrc->a[pSrc->nSrc-1].iCursor ){
153087 if( pCtx->iJoin && iTab>pCtx->iJoin ){
153088 sqlite3ErrorMsg(pWalker->pParse,
153089 "ON clause references tables to its right");
153090 return WRC_Abort;
153091 }
153092 break;
153093 }
153094 pCtx = pCtx->pParent;
153095 }while( pCtx );
153096 }
153097 return WRC_Continue;
153098 }
153099
153100 /*
153101 ** The xSelect callback for the search of invalid ON clause terms.
153102 */
153103 static int selectCheckOnClausesSelect(Walker *pWalker, Select *pSelect){
153104 CheckOnCtx *pCtx = pWalker->u.pCheckOnCtx;
153105 if( pSelect->pSrc==pCtx->pSrc || pSelect->pSrc->nSrc==0 ){
153106 return WRC_Continue;
153107 }else{
153108 CheckOnCtx sCtx;
153109 memset(&sCtx, 0, sizeof(sCtx));
153110 sCtx.pSrc = pSelect->pSrc;
153111 sCtx.pParent = pCtx;
153112 pWalker->u.pCheckOnCtx = &sCtx;
153113 sqlite3WalkSelect(pWalker, pSelect);
153114 pWalker->u.pCheckOnCtx = pCtx;
153115 pSelect->selFlags &= ~SF_OnToWhere;
153116 return WRC_Prune;
153117 }
153118 }
153119
153120 /*
153121 ** Check all ON clauses in pSelect to verify that they do not reference
153122 ** columns to the right.
153123 */
153124 static void selectCheckOnClauses(Parse *pParse, Select *pSelect){
153125 Walker w;
153126 CheckOnCtx sCtx;
153127 assert( pSelect->selFlags & SF_OnToWhere );
153128 assert( pSelect->pSrc!=0 && pSelect->pSrc->nSrc>=2 );
153129 memset(&w, 0, sizeof(w));
153130 w.pParse = pParse;
153131 w.xExprCallback = selectCheckOnClausesExpr;
153132 w.xSelectCallback = selectCheckOnClausesSelect;
153133 w.u.pCheckOnCtx = &sCtx;
153134 memset(&sCtx, 0, sizeof(sCtx));
153135 sCtx.pSrc = pSelect->pSrc;
153136 sqlite3WalkExprNN(&w, pSelect->pWhere);
153137 pSelect->selFlags &= ~SF_OnToWhere;
153138 }
153139
153140 /*
153141 ** Generate byte-code for the SELECT statement given in the p argument.
153142 **
153143 ** The results are returned according to the SelectDest structure.
@@ -152965,10 +153261,22 @@
153261 if( sqlite3TreeTrace & 0x10 ){
153262 TREETRACE(0x10,pParse,p, ("after name resolution:\n"));
153263 sqlite3TreeViewSelect(0, p, 0);
153264 }
153265 #endif
153266
153267 /* If the SELECT statement contains ON clauses that were moved into
153268 ** the WHERE clause, go through and verify that none of the terms
153269 ** in the ON clauses reference tables to the right of the ON clause.
153270 ** Do this now, after name resolution, but before query flattening
153271 */
153272 if( p->selFlags & SF_OnToWhere ){
153273 selectCheckOnClauses(pParse, p);
153274 if( pParse->nErr ){
153275 goto select_end;
153276 }
153277 }
153278
153279 /* If the SF_UFSrcCheck flag is set, then this function is being called
153280 ** as part of populating the temp table for an UPDATE...FROM statement.
153281 ** In this case, it is an error if the target object (pSrc->a[0]) name
153282 ** or alias is duplicated within FROM clause (pSrc->a[1..n]).
@@ -155531,11 +155839,14 @@
155839 sqlite3 *db = pParse->db;
155840 ExprList *pNew;
155841 Returning *pReturning;
155842 Select sSelect;
155843 SrcList *pFrom;
155844 union {
155845 SrcList sSrc;
155846 u8 fromSpace[SZ_SRCLIST_1];
155847 } uSrc;
155848
155849 assert( v!=0 );
155850 if( !pParse->bReturning ){
155851 /* This RETURNING trigger must be for a different statement as
155852 ** this statement lacks a RETURNING clause. */
@@ -155547,12 +155858,12 @@
155858 if( pTrigger != &(pReturning->retTrig) ){
155859 /* This RETURNING trigger is for a different statement */
155860 return;
155861 }
155862 memset(&sSelect, 0, sizeof(sSelect));
155863 memset(&uSrc, 0, sizeof(uSrc));
155864 pFrom = &uSrc.sSrc;
155865 sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
155866 sSelect.pSrc = pFrom;
155867 pFrom->nSrc = 1;
155868 pFrom->a[0].pSTab = pTab;
155869 pFrom->a[0].zName = pTab->zName; /* tag-20240424-1 */
@@ -163079,11 +163390,14 @@
163390 WhereClause *pWC = &pWInfo->sWC;
163391 WhereInfo *pSubWInfo;
163392 WhereLoop *pLoop = pLevel->pWLoop;
163393 SrcItem *pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
163394 SrcList *pFrom;
163395 union {
163396 SrcList sSrc;
163397 u8 fromSpace[SZ_SRCLIST_1];
163398 } uSrc;
163399 Bitmask mAll = 0;
163400 int k;
163401
163402 ExplainQueryPlan((pParse, 1, "RIGHT-JOIN %s", pTabItem->pSTab->zName));
163403 sqlite3VdbeNoJumpsOutsideSubrtn(v, pRJ->addrSubrtn, pRJ->endSubrtn,
@@ -163123,11 +163437,11 @@
163437 if( ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON) ) continue;
163438 pSubWhere = sqlite3ExprAnd(pParse, pSubWhere,
163439 sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
163440 }
163441 }
163442 pFrom = &uSrc.sSrc;
163443 pFrom->nSrc = 1;
163444 pFrom->nAlloc = 1;
163445 memcpy(&pFrom->a[0], pTabItem, sizeof(SrcItem));
163446 pFrom->a[0].fg.jointype = 0;
163447 assert( pParse->withinRJSubrtn < 100 );
@@ -164340,25 +164654,11 @@
164654 Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iJoin);
164655 if( ExprHasProperty(pExpr, EP_OuterON) ){
164656 prereqAll |= x;
164657 extraRight = x-1; /* ON clause terms may not be used with an index
164658 ** on left table of a LEFT JOIN. Ticket #3015 */
 
 
 
 
164659 }else if( (prereqAll>>1)>=x ){
 
 
 
 
 
 
 
 
 
 
164660 ExprClearProperty(pExpr, EP_InnerON);
164661 }
164662 }
164663 pTerm->prereqAll = prereqAll;
164664 pTerm->leftCursor = -1;
@@ -184839,10 +185139,13 @@
185139 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
185140 switch( rc ){
185141 case SQLITE_OK: zName = "SQLITE_OK"; break;
185142 case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
185143 case SQLITE_ERROR_SNAPSHOT: zName = "SQLITE_ERROR_SNAPSHOT"; break;
185144 case SQLITE_ERROR_RETRY: zName = "SQLITE_ERROR_RETRY"; break;
185145 case SQLITE_ERROR_MISSING_COLLSEQ:
185146 zName = "SQLITE_ERROR_MISSING_COLLSEQ"; break;
185147 case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
185148 case SQLITE_PERM: zName = "SQLITE_PERM"; break;
185149 case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
185150 case SQLITE_ABORT_ROLLBACK: zName = "SQLITE_ABORT_ROLLBACK"; break;
185151 case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
@@ -189087,21 +189390,24 @@
189390 **
189391 */
189392 #ifndef _FTSINT_H
189393 #define _FTSINT_H
189394
189395 /*
189396 ** Activate assert() only if SQLITE_TEST is enabled.
189397 */
189398 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
189399 # define NDEBUG 1
189400 #endif
189401
189402 /* #include <assert.h> */
189403 /* #include <stdlib.h> */
189404 /* #include <stddef.h> */
189405 /* #include <stdio.h> */
189406 /* #include <string.h> */
189407 /* #include <stdarg.h> */
189408
 
 
 
 
189409 /* FTS3/FTS4 require virtual tables */
189410 #ifdef SQLITE_OMIT_VIRTUALTABLE
189411 # undef SQLITE_ENABLE_FTS3
189412 # undef SQLITE_ENABLE_FTS4
189413 #endif
@@ -189540,17 +189846,10 @@
189846 /*
189847 ** Macro used to suppress compiler warnings for unused parameters.
189848 */
189849 #define UNUSED_PARAMETER(x) (void)(x)
189850
 
 
 
 
 
 
 
189851 /*
189852 ** The TESTONLY macro is used to enclose variable declarations or
189853 ** other bits of code that are needed to support the arguments
189854 ** within testcase() and assert() macros.
189855 */
@@ -203821,12 +204120,12 @@
204120 /*
204121 ** An object of this type contains the state required to create or append
204122 ** to an appendable b-tree segment.
204123 */
204124 struct IncrmergeWriter {
204125 i64 nLeafEst; /* Space allocated for leaf blocks */
204126 i64 nWork; /* Number of leaf pages flushed */
204127 sqlite3_int64 iAbsLevel; /* Absolute level of input segments */
204128 int iIdx; /* Index of *output* segment in iAbsLevel+1 */
204129 sqlite3_int64 iStart; /* Block number of first allocated block */
204130 sqlite3_int64 iEnd; /* Block number of last allocated block */
204131 sqlite3_int64 nLeafData; /* Bytes of leaf page data so far */
@@ -204568,21 +204867,21 @@
204867 Fts3MultiSegReader *pCsr, /* Cursor that data will be read from */
204868 IncrmergeWriter *pWriter /* Populate this object */
204869 ){
204870 int rc; /* Return Code */
204871 int i; /* Iterator variable */
204872 i64 nLeafEst = 0; /* Blocks allocated for leaf nodes */
204873 sqlite3_stmt *pLeafEst = 0; /* SQL used to determine nLeafEst */
204874 sqlite3_stmt *pFirstBlock = 0; /* SQL used to determine first block */
204875
204876 /* Calculate nLeafEst. */
204877 rc = fts3SqlStmt(p, SQL_MAX_LEAF_NODE_ESTIMATE, &pLeafEst, 0);
204878 if( rc==SQLITE_OK ){
204879 sqlite3_bind_int64(pLeafEst, 1, iAbsLevel);
204880 sqlite3_bind_int64(pLeafEst, 2, pCsr->nSegment);
204881 if( SQLITE_ROW==sqlite3_step(pLeafEst) ){
204882 nLeafEst = sqlite3_column_int64(pLeafEst, 0);
204883 }
204884 rc = sqlite3_reset(pLeafEst);
204885 }
204886 if( rc!=SQLITE_OK ) return rc;
204887
@@ -228353,11 +228652,11 @@
228652 typedef struct DbpageTable DbpageTable;
228653 typedef struct DbpageCursor DbpageCursor;
228654
228655 struct DbpageCursor {
228656 sqlite3_vtab_cursor base; /* Base class. Must be first */
228657 Pgno pgno; /* Current page number */
228658 int mxPgno; /* Last page to visit on this scan */
228659 Pager *pPager; /* Pager being read/written */
228660 DbPage *pPage1; /* Page 1 of the database */
228661 int iDb; /* Index of database to analyze */
228662 int szPage; /* Size of each page in bytes */
@@ -228491,11 +228790,11 @@
228790 if( pCsr==0 ){
228791 return SQLITE_NOMEM_BKPT;
228792 }else{
228793 memset(pCsr, 0, sizeof(DbpageCursor));
228794 pCsr->base.pVtab = pVTab;
228795 pCsr->pgno = 0;
228796 }
228797
228798 *ppCursor = (sqlite3_vtab_cursor *)pCsr;
228799 return SQLITE_OK;
228800 }
@@ -228591,16 +228890,16 @@
228890 ){
228891 DbpageCursor *pCsr = (DbpageCursor *)pCursor;
228892 int rc = SQLITE_OK;
228893 switch( i ){
228894 case 0: { /* pgno */
228895 sqlite3_result_int64(ctx, (sqlite3_int64)pCsr->pgno);
228896 break;
228897 }
228898 case 1: { /* data */
228899 DbPage *pDbPage = 0;
228900 if( pCsr->pgno==(Pgno)((PENDING_BYTE/pCsr->szPage)+1) ){
228901 /* The pending byte page. Assume it is zeroed out. Attempting to
228902 ** request this page from the page is an SQLITE_CORRUPT error. */
228903 sqlite3_result_zeroblob(ctx, pCsr->szPage);
228904 }else{
228905 rc = sqlite3PagerGet(pCsr->pPager, pCsr->pgno, (DbPage**)&pDbPage, 0);
@@ -228670,14 +228969,14 @@
228969 if( argc==1 ){
228970 zErr = "cannot delete";
228971 goto update_fail;
228972 }
228973 if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
228974 pgno = (Pgno)sqlite3_value_int64(argv[2]);
228975 isInsert = 1;
228976 }else{
228977 pgno = (Pgno)sqlite3_value_int64(argv[0]);
228978 if( (Pgno)sqlite3_value_int(argv[1])!=pgno ){
228979 zErr = "cannot insert";
228980 goto update_fail;
228981 }
228982 isInsert = 0;
@@ -233644,11 +233943,11 @@
233943 sqlite3_changeset_iter *pIter, /* Changeset iterator */
233944 int(*xConflict)(void *, int, sqlite3_changeset_iter*),
233945 void *pCtx, /* First argument for conflict handler */
233946 int *pbReplace /* OUT: Set to true if PK row is found */
233947 ){
233948 int res = SQLITE_CHANGESET_OMIT;/* Value returned by conflict handler */
233949 int rc;
233950 int nCol;
233951 int op;
233952 const char *zDummy;
233953
@@ -233665,15 +233964,13 @@
233964 rc = SQLITE_OK;
233965 }
233966
233967 if( rc==SQLITE_ROW ){
233968 /* There exists another row with the new.* primary key. */
233969 if( 0==p->bIgnoreNoop
233970 || 0==sqlite3_column_int(p->pSelect, sqlite3_column_count(p->pSelect)-1)
233971 ){
 
 
233972 pIter->pConflict = p->pSelect;
233973 res = xConflict(pCtx, eType, pIter);
233974 pIter->pConflict = 0;
233975 }
233976 rc = sqlite3_reset(p->pSelect);
@@ -233683,11 +233980,13 @@
233980 ** to the SessionApplyCtx.constraints buffer. */
233981 u8 *aBlob = &pIter->in.aData[pIter->in.iCurrent];
233982 int nBlob = pIter->in.iNext - pIter->in.iCurrent;
233983 sessionAppendBlob(&p->constraints, aBlob, nBlob, &rc);
233984 return SQLITE_OK;
233985 }else if( p->bIgnoreNoop==0 || op!=SQLITE_DELETE
233986 || eType==SQLITE_CHANGESET_CONFLICT
233987 ){
233988 /* No other row with the new.* primary key. */
233989 res = xConflict(pCtx, eType+1, pIter);
233990 if( res==SQLITE_CHANGESET_REPLACE ) rc = SQLITE_MISUSE;
233991 }
233992 }
@@ -233781,11 +234080,11 @@
234080 }
234081 if( rc!=SQLITE_OK ) return rc;
234082
234083 sqlite3_step(p->pDelete);
234084 rc = sqlite3_reset(p->pDelete);
234085 if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 ){
234086 rc = sessionConflictHandler(
234087 SQLITE_CHANGESET_DATA, p, pIter, xConflict, pCtx, pbRetry
234088 );
234089 }else if( (rc&0xff)==SQLITE_CONSTRAINT ){
234090 rc = sessionConflictHandler(
@@ -236412,25 +236711,18 @@
236711 ** Constants for the largest and smallest possible 64-bit signed integers.
236712 */
236713 # define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
236714 # define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
236715
236716 /*
236717 ** This macro is used in a single assert() within fts5 to check that an
236718 ** allocation is aligned to an 8-byte boundary. But it is a complicated
236719 ** macro to get right for multiple platforms without generating warnings.
236720 ** So instead of reproducing the entire definition from sqliteInt.h, we
236721 ** just do without this assert() for the rare non-amalgamation builds.
236722 */
236723 #define EIGHT_BYTE_ALIGNMENT(x) 1
 
 
 
 
 
 
 
 
 
 
 
 
236724
236725 /*
236726 ** Macros needed to provide flexible arrays in a portable way
236727 */
236728 #ifndef offsetof
@@ -251885,14 +252177,17 @@
252177 ** function populates it with the initial structure objects for each index,
252178 ** and the initial version of the "averages" record (a zero-byte blob).
252179 */
252180 static int sqlite3Fts5IndexReinit(Fts5Index *p){
252181 Fts5Structure *pTmp;
252182 union {
252183 Fts5Structure sFts;
252184 u8 tmpSpace[SZ_FTS5STRUCTURE(1)];
252185 } uFts;
252186 fts5StructureInvalidate(p);
252187 fts5IndexDiscardData(p);
252188 pTmp = &uFts.sFts;
252189 memset(pTmp, 0, SZ_FTS5STRUCTURE(1));
252190 if( p->pConfig->bContentlessDelete ){
252191 pTmp->nOriginCntr = 1;
252192 }
252193 fts5DataWrite(p, FTS5_AVERAGES_ROWID, (const u8*)"", 0);
@@ -258177,11 +258472,11 @@
258472 int nArg, /* Number of args */
258473 sqlite3_value **apUnused /* Function arguments */
258474 ){
258475 assert( nArg==0 );
258476 UNUSED_PARAM2(nArg, apUnused);
258477 sqlite3_result_text(pCtx, "fts5: 2025-09-09 10:28:06 0f31711591c56f3896fb6f092752fb82c4ea646bf8e5838dfbe55302994ea091", -1, SQLITE_TRANSIENT);
258478 }
258479
258480 /*
258481 ** Implementation of fts5_locale(LOCALE, TEXT) function.
258482 **
258483
+63 -35
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.51.0"
150150
#define SQLITE_VERSION_NUMBER 3051000
151
-#define SQLITE_SOURCE_ID "2025-07-30 16:17:14 cf7163f82ca380958a79350473b2c5a2cebda7496d6d575fa2835c362010fea1"
151
+#define SQLITE_SOURCE_ID "2025-09-09 10:28:06 0f31711591c56f3896fb6f092752fb82c4ea646bf8e5838dfbe55302994ea091"
152
+#define SQLITE_SCM_BRANCH "trunk"
153
+#define SQLITE_SCM_TAGS ""
154
+#define SQLITE_SCM_DATETIME "2025-09-09T10:28:06.692Z"
152155
153156
/*
154157
** CAPI3REF: Run-Time Library Version Numbers
155158
** KEYWORDS: sqlite3_version sqlite3_sourceid
156159
**
@@ -2338,21 +2341,24 @@
23382341
** views in the main database schema or in the schemas of ATTACH-ed
23392342
** databases.)^ </dd>
23402343
**
23412344
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
23422345
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2343
-** <dd> ^This option is used to enable or disable the
2344
-** [fts3_tokenizer()] function which is part of the
2345
-** [FTS3] full-text search engine extension.
2346
-** There must be two additional arguments.
2347
-** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2348
-** positive to enable fts3_tokenizer() or negative to leave the setting
2349
-** unchanged.
2350
-** The second parameter is a pointer to an integer into which
2351
-** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2352
-** following this call. The second parameter may be a NULL pointer, in
2353
-** which case the new setting is not reported back. </dd>
2346
+** <dd> ^This option is used to enable or disable using the
2347
+** [fts3_tokenizer()] function - part of the [FTS3] full-text search engine
2348
+** extension - without using bound parameters as the parameters. Doing so
2349
+** is disabled by default. There must be two additional arguments. The first
2350
+** argument is an integer. If it is passed 0, then using fts3_tokenizer()
2351
+** without bound parameters is disabled. If it is passed a positive value,
2352
+** then calling fts3_tokenizer without bound parameters is enabled. If it
2353
+** is passed a negative value, this setting is not modified - this can be
2354
+** used to query for the current setting. The second parameter is a pointer
2355
+** to an integer into which is written 0 or 1 to indicate the current value
2356
+** of this setting (after it is modified, if applicable). The second
2357
+** parameter may be a NULL pointer, in which case the value of the setting
2358
+** is not reported back. Refer to [FTS3] documentation for further details.
2359
+** </dd>
23542360
**
23552361
** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
23562362
** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
23572363
** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
23582364
** interface independently of the [load_extension()] SQL function.
@@ -6208,10 +6214,11 @@
62086214
** to be attached to [database connection] D using name N. Subsequent
62096215
** calls to sqlite3_get_clientdata(D,N) will return a copy of pointer P
62106216
** or a NULL pointer if there were no prior calls to
62116217
** sqlite3_set_clientdata() with the same values of D and N.
62126218
** Names are compared using strcmp() and are thus case sensitive.
6219
+** It returns 0 on success and SQLITE_NOMEM on allocation failure.
62136220
**
62146221
** If P and X are both non-NULL, then the destructor X is invoked with
62156222
** argument P on the first of the following occurrences:
62166223
** <ul>
62176224
** <li> An out-of-memory error occurs during the call to
@@ -9779,25 +9786,38 @@
97799786
** ^The third parameter is the name of the database that was written to -
97809787
** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
97819788
** is the number of pages currently in the write-ahead log file,
97829789
** including those that were just committed.
97839790
**
9784
-** The callback function should normally return [SQLITE_OK]. ^If an error
9791
+** ^The callback function should normally return [SQLITE_OK]. ^If an error
97859792
** code is returned, that error will propagate back up through the
97869793
** SQLite code base to cause the statement that provoked the callback
97879794
** to report an error, though the commit will have still occurred. If the
97889795
** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
97899796
** that does not correspond to any valid SQLite error code, the results
97909797
** are undefined.
97919798
**
9792
-** A single database handle may have at most a single write-ahead log callback
9793
-** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
9794
-** previously registered write-ahead log callback. ^The return value is
9795
-** a copy of the third parameter from the previous call, if any, or 0.
9796
-** ^Note that the [sqlite3_wal_autocheckpoint()] interface and the
9797
-** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
9798
-** overwrite any prior [sqlite3_wal_hook()] settings.
9799
+** ^A single database handle may have at most a single write-ahead log
9800
+** callback registered at one time. ^Calling [sqlite3_wal_hook()]
9801
+** replaces the default behavior or previously registered write-ahead
9802
+** log callback.
9803
+**
9804
+** ^The return value is a copy of the third parameter from the
9805
+** previous call, if any, or 0.
9806
+**
9807
+** ^The [sqlite3_wal_autocheckpoint()] interface and the
9808
+** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and
9809
+** will overwrite any prior [sqlite3_wal_hook()] settings.
9810
+**
9811
+** ^If a write-ahead log callback is set using this function then
9812
+** [sqlite3_wal_checkpoint_v2()] or [PRAGMA wal_checkpoint]
9813
+** should be invoked periodically to keep the write-ahead log file
9814
+** from growing without bound.
9815
+**
9816
+** ^Passing a NULL pointer for the callback disables automatic
9817
+** checkpointing entirely. To re-enable the default behavior, call
9818
+** sqlite3_wal_autocheckpoint(db,1000) or use [PRAGMA wal_checkpoint].
97999819
*/
98009820
SQLITE_API void *sqlite3_wal_hook(
98019821
sqlite3*,
98029822
int(*)(void *,sqlite3*,const char*,int),
98039823
void*
@@ -9810,11 +9830,11 @@
98109830
** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
98119831
** [sqlite3_wal_hook()] that causes any database on [database connection] D
98129832
** to automatically [checkpoint]
98139833
** after committing a transaction if there are N or
98149834
** more frames in the [write-ahead log] file. ^Passing zero or
9815
-** a negative value as the nFrame parameter disables automatic
9835
+** a negative value as the N parameter disables automatic
98169836
** checkpoints entirely.
98179837
**
98189838
** ^The callback registered by this function replaces any existing callback
98199839
** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback
98209840
** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
@@ -9826,13 +9846,14 @@
98269846
** ^Checkpoints initiated by this mechanism are
98279847
** [sqlite3_wal_checkpoint_v2|PASSIVE].
98289848
**
98299849
** ^Every new [database connection] defaults to having the auto-checkpoint
98309850
** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
9831
-** pages. The use of this interface
9832
-** is only necessary if the default setting is found to be suboptimal
9833
-** for a particular application.
9851
+** pages.
9852
+**
9853
+** ^The use of this interface is only necessary if the default setting
9854
+** is found to be suboptimal for a particular application.
98349855
*/
98359856
SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
98369857
98379858
/*
98389859
** CAPI3REF: Checkpoint a database
@@ -9893,10 +9914,15 @@
98939914
**
98949915
** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
98959916
** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
98969917
** addition that it also truncates the log file to zero bytes just prior
98979918
** to a successful return.
9919
+**
9920
+** <dt>SQLITE_CHECKPOINT_NOOP<dd>
9921
+** ^This mode always checkpoints zero frames. The only reason to invoke
9922
+** a NOOP checkpoint is to access the values returned by
9923
+** sqlite3_wal_checkpoint_v2() via output parameters *pnLog and *pnCkpt.
98989924
** </dl>
98999925
**
99009926
** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
99019927
** the log file or to -1 if the checkpoint could not run because
99029928
** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
@@ -9963,10 +9989,11 @@
99639989
** These constants define all valid values for the "checkpoint mode" passed
99649990
** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
99659991
** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
99669992
** meaning of each of these checkpoint modes.
99679993
*/
9994
+#define SQLITE_CHECKPOINT_NOOP -1 /* Do no work at all */
99689995
#define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
99699996
#define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
99709997
#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */
99719998
#define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
99729999
@@ -10790,11 +10817,11 @@
1079010817
** to avoid a memory leak.
1079110818
**
1079210819
** The [sqlite3_snapshot_get()] interface is only available when the
1079310820
** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
1079410821
*/
10795
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get(
10822
+SQLITE_API int sqlite3_snapshot_get(
1079610823
sqlite3 *db,
1079710824
const char *zSchema,
1079810825
sqlite3_snapshot **ppSnapshot
1079910826
);
1080010827
@@ -10839,11 +10866,11 @@
1083910866
** database connection in order to make it ready to use snapshots.)
1084010867
**
1084110868
** The [sqlite3_snapshot_open()] interface is only available when the
1084210869
** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
1084310870
*/
10844
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open(
10871
+SQLITE_API int sqlite3_snapshot_open(
1084510872
sqlite3 *db,
1084610873
const char *zSchema,
1084710874
sqlite3_snapshot *pSnapshot
1084810875
);
1084910876
@@ -10856,11 +10883,11 @@
1085610883
** using this routine to avoid a memory leak.
1085710884
**
1085810885
** The [sqlite3_snapshot_free()] interface is only available when the
1085910886
** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
1086010887
*/
10861
-SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*);
10888
+SQLITE_API void sqlite3_snapshot_free(sqlite3_snapshot*);
1086210889
1086310890
/*
1086410891
** CAPI3REF: Compare the ages of two snapshot handles.
1086510892
** METHOD: sqlite3_snapshot
1086610893
**
@@ -10883,11 +10910,11 @@
1088310910
** snapshot, and a positive value if P1 is a newer snapshot than P2.
1088410911
**
1088510912
** This interface is only available if SQLite is compiled with the
1088610913
** [SQLITE_ENABLE_SNAPSHOT] option.
1088710914
*/
10888
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
10915
+SQLITE_API int sqlite3_snapshot_cmp(
1088910916
sqlite3_snapshot *p1,
1089010917
sqlite3_snapshot *p2
1089110918
);
1089210919
1089310920
/*
@@ -10911,11 +10938,11 @@
1091110938
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
1091210939
**
1091310940
** This interface is only available if SQLite is compiled with the
1091410941
** [SQLITE_ENABLE_SNAPSHOT] option.
1091510942
*/
10916
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
10943
+SQLITE_API int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
1091710944
1091810945
/*
1091910946
** CAPI3REF: Serialize a database
1092010947
**
1092110948
** The sqlite3_serialize(D,S,P,F) interface returns a pointer to
@@ -10985,16 +11012,17 @@
1098511012
/*
1098611013
** CAPI3REF: Deserialize a database
1098711014
**
1098811015
** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the
1098911016
** [database connection] D to disconnect from database S and then
10990
-** reopen S as an in-memory database based on the serialization contained
10991
-** in P. The serialized database P is N bytes in size. M is the size of
10992
-** the buffer P, which might be larger than N. If M is larger than N, and
10993
-** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is
10994
-** permitted to add content to the in-memory database as long as the total
10995
-** size does not exceed M bytes.
11017
+** reopen S as an in-memory database based on the serialization
11018
+** contained in P. If S is a NULL pointer, the main database is
11019
+** used. The serialized database P is N bytes in size. M is the size
11020
+** of the buffer P, which might be larger than N. If M is larger than
11021
+** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then
11022
+** SQLite is permitted to add content to the in-memory database as
11023
+** long as the total size does not exceed M bytes.
1099611024
**
1099711025
** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
1099811026
** invoke sqlite3_free() on the serialization buffer when the database
1099911027
** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
1100011028
** SQLite will try to increase the buffer size using sqlite3_realloc64()
1100111029
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.51.0"
150 #define SQLITE_VERSION_NUMBER 3051000
151 #define SQLITE_SOURCE_ID "2025-07-30 16:17:14 cf7163f82ca380958a79350473b2c5a2cebda7496d6d575fa2835c362010fea1"
 
 
 
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -2338,21 +2341,24 @@
2338 ** views in the main database schema or in the schemas of ATTACH-ed
2339 ** databases.)^ </dd>
2340 **
2341 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2342 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2343 ** <dd> ^This option is used to enable or disable the
2344 ** [fts3_tokenizer()] function which is part of the
2345 ** [FTS3] full-text search engine extension.
2346 ** There must be two additional arguments.
2347 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2348 ** positive to enable fts3_tokenizer() or negative to leave the setting
2349 ** unchanged.
2350 ** The second parameter is a pointer to an integer into which
2351 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2352 ** following this call. The second parameter may be a NULL pointer, in
2353 ** which case the new setting is not reported back. </dd>
 
 
 
2354 **
2355 ** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
2356 ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
2357 ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
2358 ** interface independently of the [load_extension()] SQL function.
@@ -6208,10 +6214,11 @@
6208 ** to be attached to [database connection] D using name N. Subsequent
6209 ** calls to sqlite3_get_clientdata(D,N) will return a copy of pointer P
6210 ** or a NULL pointer if there were no prior calls to
6211 ** sqlite3_set_clientdata() with the same values of D and N.
6212 ** Names are compared using strcmp() and are thus case sensitive.
 
6213 **
6214 ** If P and X are both non-NULL, then the destructor X is invoked with
6215 ** argument P on the first of the following occurrences:
6216 ** <ul>
6217 ** <li> An out-of-memory error occurs during the call to
@@ -9779,25 +9786,38 @@
9779 ** ^The third parameter is the name of the database that was written to -
9780 ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
9781 ** is the number of pages currently in the write-ahead log file,
9782 ** including those that were just committed.
9783 **
9784 ** The callback function should normally return [SQLITE_OK]. ^If an error
9785 ** code is returned, that error will propagate back up through the
9786 ** SQLite code base to cause the statement that provoked the callback
9787 ** to report an error, though the commit will have still occurred. If the
9788 ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
9789 ** that does not correspond to any valid SQLite error code, the results
9790 ** are undefined.
9791 **
9792 ** A single database handle may have at most a single write-ahead log callback
9793 ** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
9794 ** previously registered write-ahead log callback. ^The return value is
9795 ** a copy of the third parameter from the previous call, if any, or 0.
9796 ** ^Note that the [sqlite3_wal_autocheckpoint()] interface and the
9797 ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
9798 ** overwrite any prior [sqlite3_wal_hook()] settings.
 
 
 
 
 
 
 
 
 
 
 
 
 
9799 */
9800 SQLITE_API void *sqlite3_wal_hook(
9801 sqlite3*,
9802 int(*)(void *,sqlite3*,const char*,int),
9803 void*
@@ -9810,11 +9830,11 @@
9810 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
9811 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
9812 ** to automatically [checkpoint]
9813 ** after committing a transaction if there are N or
9814 ** more frames in the [write-ahead log] file. ^Passing zero or
9815 ** a negative value as the nFrame parameter disables automatic
9816 ** checkpoints entirely.
9817 **
9818 ** ^The callback registered by this function replaces any existing callback
9819 ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback
9820 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
@@ -9826,13 +9846,14 @@
9826 ** ^Checkpoints initiated by this mechanism are
9827 ** [sqlite3_wal_checkpoint_v2|PASSIVE].
9828 **
9829 ** ^Every new [database connection] defaults to having the auto-checkpoint
9830 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
9831 ** pages. The use of this interface
9832 ** is only necessary if the default setting is found to be suboptimal
9833 ** for a particular application.
 
9834 */
9835 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
9836
9837 /*
9838 ** CAPI3REF: Checkpoint a database
@@ -9893,10 +9914,15 @@
9893 **
9894 ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
9895 ** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
9896 ** addition that it also truncates the log file to zero bytes just prior
9897 ** to a successful return.
 
 
 
 
 
9898 ** </dl>
9899 **
9900 ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
9901 ** the log file or to -1 if the checkpoint could not run because
9902 ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
@@ -9963,10 +9989,11 @@
9963 ** These constants define all valid values for the "checkpoint mode" passed
9964 ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
9965 ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
9966 ** meaning of each of these checkpoint modes.
9967 */
 
9968 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
9969 #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
9970 #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */
9971 #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
9972
@@ -10790,11 +10817,11 @@
10790 ** to avoid a memory leak.
10791 **
10792 ** The [sqlite3_snapshot_get()] interface is only available when the
10793 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
10794 */
10795 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get(
10796 sqlite3 *db,
10797 const char *zSchema,
10798 sqlite3_snapshot **ppSnapshot
10799 );
10800
@@ -10839,11 +10866,11 @@
10839 ** database connection in order to make it ready to use snapshots.)
10840 **
10841 ** The [sqlite3_snapshot_open()] interface is only available when the
10842 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
10843 */
10844 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open(
10845 sqlite3 *db,
10846 const char *zSchema,
10847 sqlite3_snapshot *pSnapshot
10848 );
10849
@@ -10856,11 +10883,11 @@
10856 ** using this routine to avoid a memory leak.
10857 **
10858 ** The [sqlite3_snapshot_free()] interface is only available when the
10859 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
10860 */
10861 SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*);
10862
10863 /*
10864 ** CAPI3REF: Compare the ages of two snapshot handles.
10865 ** METHOD: sqlite3_snapshot
10866 **
@@ -10883,11 +10910,11 @@
10883 ** snapshot, and a positive value if P1 is a newer snapshot than P2.
10884 **
10885 ** This interface is only available if SQLite is compiled with the
10886 ** [SQLITE_ENABLE_SNAPSHOT] option.
10887 */
10888 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
10889 sqlite3_snapshot *p1,
10890 sqlite3_snapshot *p2
10891 );
10892
10893 /*
@@ -10911,11 +10938,11 @@
10911 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
10912 **
10913 ** This interface is only available if SQLite is compiled with the
10914 ** [SQLITE_ENABLE_SNAPSHOT] option.
10915 */
10916 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
10917
10918 /*
10919 ** CAPI3REF: Serialize a database
10920 **
10921 ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to
@@ -10985,16 +11012,17 @@
10985 /*
10986 ** CAPI3REF: Deserialize a database
10987 **
10988 ** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the
10989 ** [database connection] D to disconnect from database S and then
10990 ** reopen S as an in-memory database based on the serialization contained
10991 ** in P. The serialized database P is N bytes in size. M is the size of
10992 ** the buffer P, which might be larger than N. If M is larger than N, and
10993 ** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is
10994 ** permitted to add content to the in-memory database as long as the total
10995 ** size does not exceed M bytes.
 
10996 **
10997 ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
10998 ** invoke sqlite3_free() on the serialization buffer when the database
10999 ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
11000 ** SQLite will try to increase the buffer size using sqlite3_realloc64()
11001
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.51.0"
150 #define SQLITE_VERSION_NUMBER 3051000
151 #define SQLITE_SOURCE_ID "2025-09-09 10:28:06 0f31711591c56f3896fb6f092752fb82c4ea646bf8e5838dfbe55302994ea091"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2025-09-09T10:28:06.692Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -2338,21 +2341,24 @@
2341 ** views in the main database schema or in the schemas of ATTACH-ed
2342 ** databases.)^ </dd>
2343 **
2344 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2345 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2346 ** <dd> ^This option is used to enable or disable using the
2347 ** [fts3_tokenizer()] function - part of the [FTS3] full-text search engine
2348 ** extension - without using bound parameters as the parameters. Doing so
2349 ** is disabled by default. There must be two additional arguments. The first
2350 ** argument is an integer. If it is passed 0, then using fts3_tokenizer()
2351 ** without bound parameters is disabled. If it is passed a positive value,
2352 ** then calling fts3_tokenizer without bound parameters is enabled. If it
2353 ** is passed a negative value, this setting is not modified - this can be
2354 ** used to query for the current setting. The second parameter is a pointer
2355 ** to an integer into which is written 0 or 1 to indicate the current value
2356 ** of this setting (after it is modified, if applicable). The second
2357 ** parameter may be a NULL pointer, in which case the value of the setting
2358 ** is not reported back. Refer to [FTS3] documentation for further details.
2359 ** </dd>
2360 **
2361 ** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
2362 ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
2363 ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
2364 ** interface independently of the [load_extension()] SQL function.
@@ -6208,10 +6214,11 @@
6214 ** to be attached to [database connection] D using name N. Subsequent
6215 ** calls to sqlite3_get_clientdata(D,N) will return a copy of pointer P
6216 ** or a NULL pointer if there were no prior calls to
6217 ** sqlite3_set_clientdata() with the same values of D and N.
6218 ** Names are compared using strcmp() and are thus case sensitive.
6219 ** It returns 0 on success and SQLITE_NOMEM on allocation failure.
6220 **
6221 ** If P and X are both non-NULL, then the destructor X is invoked with
6222 ** argument P on the first of the following occurrences:
6223 ** <ul>
6224 ** <li> An out-of-memory error occurs during the call to
@@ -9779,25 +9786,38 @@
9786 ** ^The third parameter is the name of the database that was written to -
9787 ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
9788 ** is the number of pages currently in the write-ahead log file,
9789 ** including those that were just committed.
9790 **
9791 ** ^The callback function should normally return [SQLITE_OK]. ^If an error
9792 ** code is returned, that error will propagate back up through the
9793 ** SQLite code base to cause the statement that provoked the callback
9794 ** to report an error, though the commit will have still occurred. If the
9795 ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
9796 ** that does not correspond to any valid SQLite error code, the results
9797 ** are undefined.
9798 **
9799 ** ^A single database handle may have at most a single write-ahead log
9800 ** callback registered at one time. ^Calling [sqlite3_wal_hook()]
9801 ** replaces the default behavior or previously registered write-ahead
9802 ** log callback.
9803 **
9804 ** ^The return value is a copy of the third parameter from the
9805 ** previous call, if any, or 0.
9806 **
9807 ** ^The [sqlite3_wal_autocheckpoint()] interface and the
9808 ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and
9809 ** will overwrite any prior [sqlite3_wal_hook()] settings.
9810 **
9811 ** ^If a write-ahead log callback is set using this function then
9812 ** [sqlite3_wal_checkpoint_v2()] or [PRAGMA wal_checkpoint]
9813 ** should be invoked periodically to keep the write-ahead log file
9814 ** from growing without bound.
9815 **
9816 ** ^Passing a NULL pointer for the callback disables automatic
9817 ** checkpointing entirely. To re-enable the default behavior, call
9818 ** sqlite3_wal_autocheckpoint(db,1000) or use [PRAGMA wal_checkpoint].
9819 */
9820 SQLITE_API void *sqlite3_wal_hook(
9821 sqlite3*,
9822 int(*)(void *,sqlite3*,const char*,int),
9823 void*
@@ -9810,11 +9830,11 @@
9830 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
9831 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
9832 ** to automatically [checkpoint]
9833 ** after committing a transaction if there are N or
9834 ** more frames in the [write-ahead log] file. ^Passing zero or
9835 ** a negative value as the N parameter disables automatic
9836 ** checkpoints entirely.
9837 **
9838 ** ^The callback registered by this function replaces any existing callback
9839 ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback
9840 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
@@ -9826,13 +9846,14 @@
9846 ** ^Checkpoints initiated by this mechanism are
9847 ** [sqlite3_wal_checkpoint_v2|PASSIVE].
9848 **
9849 ** ^Every new [database connection] defaults to having the auto-checkpoint
9850 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
9851 ** pages.
9852 **
9853 ** ^The use of this interface is only necessary if the default setting
9854 ** is found to be suboptimal for a particular application.
9855 */
9856 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
9857
9858 /*
9859 ** CAPI3REF: Checkpoint a database
@@ -9893,10 +9914,15 @@
9914 **
9915 ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
9916 ** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
9917 ** addition that it also truncates the log file to zero bytes just prior
9918 ** to a successful return.
9919 **
9920 ** <dt>SQLITE_CHECKPOINT_NOOP<dd>
9921 ** ^This mode always checkpoints zero frames. The only reason to invoke
9922 ** a NOOP checkpoint is to access the values returned by
9923 ** sqlite3_wal_checkpoint_v2() via output parameters *pnLog and *pnCkpt.
9924 ** </dl>
9925 **
9926 ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
9927 ** the log file or to -1 if the checkpoint could not run because
9928 ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
@@ -9963,10 +9989,11 @@
9989 ** These constants define all valid values for the "checkpoint mode" passed
9990 ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
9991 ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
9992 ** meaning of each of these checkpoint modes.
9993 */
9994 #define SQLITE_CHECKPOINT_NOOP -1 /* Do no work at all */
9995 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
9996 #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
9997 #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */
9998 #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
9999
@@ -10790,11 +10817,11 @@
10817 ** to avoid a memory leak.
10818 **
10819 ** The [sqlite3_snapshot_get()] interface is only available when the
10820 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
10821 */
10822 SQLITE_API int sqlite3_snapshot_get(
10823 sqlite3 *db,
10824 const char *zSchema,
10825 sqlite3_snapshot **ppSnapshot
10826 );
10827
@@ -10839,11 +10866,11 @@
10866 ** database connection in order to make it ready to use snapshots.)
10867 **
10868 ** The [sqlite3_snapshot_open()] interface is only available when the
10869 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
10870 */
10871 SQLITE_API int sqlite3_snapshot_open(
10872 sqlite3 *db,
10873 const char *zSchema,
10874 sqlite3_snapshot *pSnapshot
10875 );
10876
@@ -10856,11 +10883,11 @@
10883 ** using this routine to avoid a memory leak.
10884 **
10885 ** The [sqlite3_snapshot_free()] interface is only available when the
10886 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
10887 */
10888 SQLITE_API void sqlite3_snapshot_free(sqlite3_snapshot*);
10889
10890 /*
10891 ** CAPI3REF: Compare the ages of two snapshot handles.
10892 ** METHOD: sqlite3_snapshot
10893 **
@@ -10883,11 +10910,11 @@
10910 ** snapshot, and a positive value if P1 is a newer snapshot than P2.
10911 **
10912 ** This interface is only available if SQLite is compiled with the
10913 ** [SQLITE_ENABLE_SNAPSHOT] option.
10914 */
10915 SQLITE_API int sqlite3_snapshot_cmp(
10916 sqlite3_snapshot *p1,
10917 sqlite3_snapshot *p2
10918 );
10919
10920 /*
@@ -10911,11 +10938,11 @@
10938 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
10939 **
10940 ** This interface is only available if SQLite is compiled with the
10941 ** [SQLITE_ENABLE_SNAPSHOT] option.
10942 */
10943 SQLITE_API int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
10944
10945 /*
10946 ** CAPI3REF: Serialize a database
10947 **
10948 ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to
@@ -10985,16 +11012,17 @@
11012 /*
11013 ** CAPI3REF: Deserialize a database
11014 **
11015 ** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the
11016 ** [database connection] D to disconnect from database S and then
11017 ** reopen S as an in-memory database based on the serialization
11018 ** contained in P. If S is a NULL pointer, the main database is
11019 ** used. The serialized database P is N bytes in size. M is the size
11020 ** of the buffer P, which might be larger than N. If M is larger than
11021 ** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then
11022 ** SQLite is permitted to add content to the in-memory database as
11023 ** long as the total size does not exceed M bytes.
11024 **
11025 ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
11026 ** invoke sqlite3_free() on the serialization buffer when the database
11027 ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
11028 ** SQLite will try to increase the buffer size using sqlite3_realloc64()
11029

Keyboard Shortcuts

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