Fossil SCM

Update the latest SQLite to the latest 3.37.0 beta, to test SQLite.

drh 2021-11-03 19:10 trunk
Commit 51bb976fb971819e7def4e75f9841b1c05c9632b8612f0fc6f6b1fe3f7b1dcba
3 files changed +94 -29 +286 -76 +67 -1
+94 -29
--- src/shell.c
+++ src/shell.c
@@ -13662,21 +13662,20 @@
1366213662
}
1366313663
return rc;
1366413664
}
1366513665
1366613666
/*
13667
-** Allocate space and save off current error string.
13667
+** Allocate space and save off string indicating current error.
1366813668
*/
1366913669
static char *save_err_msg(
13670
- sqlite3 *db /* Database to query */
13670
+ sqlite3 *db, /* Database to query */
13671
+ const char *zWhen, /* Qualifier (format) wrapper */
13672
+ int rc /* Error code returned from API */
1367113673
){
13672
- int nErrMsg = 1+strlen30(sqlite3_errmsg(db));
13673
- char *zErrMsg = sqlite3_malloc64(nErrMsg);
13674
- if( zErrMsg ){
13675
- memcpy(zErrMsg, sqlite3_errmsg(db), nErrMsg);
13676
- }
13677
- return zErrMsg;
13674
+ if( zWhen==0 )
13675
+ zWhen = "%s (%d)";
13676
+ return sqlite3_mprintf(zWhen, sqlite3_errmsg(db), rc);
1367813677
}
1367913678
1368013679
#ifdef __linux__
1368113680
/*
1368213681
** Attempt to display I/O stats on Linux using /proc/PID/io
@@ -14594,11 +14593,11 @@
1459414593
while( zSql[0] && (SQLITE_OK == rc) ){
1459514594
static const char *zStmtSql;
1459614595
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
1459714596
if( SQLITE_OK != rc ){
1459814597
if( pzErrMsg ){
14599
- *pzErrMsg = save_err_msg(db);
14598
+ *pzErrMsg = save_err_msg(db, "in prepare, %s (%d)", rc);
1460014599
}
1460114600
}else{
1460214601
if( !pStmt ){
1460314602
/* this happens for a comment or white-space */
1460414603
zSql = zLeftover;
@@ -14708,11 +14707,11 @@
1470814707
if( rc!=SQLITE_NOMEM ) rc = rc2;
1470914708
if( rc==SQLITE_OK ){
1471014709
zSql = zLeftover;
1471114710
while( IsSpace(zSql[0]) ) zSql++;
1471214711
}else if( pzErrMsg ){
14713
- *pzErrMsg = save_err_msg(db);
14712
+ *pzErrMsg = save_err_msg(db, "stepping, %s (%d)", rc);
1471414713
}
1471514714
1471614715
/* clear saved stmt handle */
1471714716
if( pArg ){
1471814717
pArg->pStmt = NULL;
@@ -15022,17 +15021,19 @@
1502215021
".archive ... Manage SQL archives",
1502315022
" Each command must have exactly one of the following options:",
1502415023
" -c, --create Create a new archive",
1502515024
" -u, --update Add or update files with changed mtime",
1502615025
" -i, --insert Like -u but always add even if unchanged",
15026
+ " -r, --remove Remove files from archive",
1502715027
" -t, --list List contents of archive",
1502815028
" -x, --extract Extract files from archive",
1502915029
" Optional arguments:",
1503015030
" -v, --verbose Print each filename as it is processed",
1503115031
" -f FILE, --file FILE Use archive FILE (default is current db)",
1503215032
" -a FILE, --append FILE Open FILE using the apndvfs VFS",
1503315033
" -C DIR, --directory DIR Read/extract files from directory DIR",
15034
+ " -g, --glob Use glob matching for names in archive",
1503415035
" -n, --dryrun Show the SQL that would have occurred",
1503515036
" Examples:",
1503615037
" .ar -cf ARCHIVE foo bar # Create ARCHIVE from files foo and bar",
1503715038
" .ar -tf ARCHIVE # List members of ARCHIVE",
1503815039
" .ar -xvf ARCHIVE # Verbosely extract files from ARCHIVE",
@@ -17189,10 +17190,11 @@
1718917190
u8 eCmd; /* An AR_CMD_* value */
1719017191
u8 bVerbose; /* True if --verbose */
1719117192
u8 bZip; /* True if the archive is a ZIP */
1719217193
u8 bDryRun; /* True if --dry-run */
1719317194
u8 bAppend; /* True if --append */
17195
+ u8 bGlob; /* True if --glob */
1719417196
u8 fromCmdLine; /* Run from -A instead of .archive */
1719517197
int nArg; /* Number of command arguments */
1719617198
char *zSrcTable; /* "sqlar", "zipfile($file)" or "zip" */
1719717199
const char *zFile; /* --file argument, or NULL */
1719817200
const char *zDir; /* --directory argument, or NULL */
@@ -17236,25 +17238,28 @@
1723617238
#define AR_CMD_UPDATE 2
1723717239
#define AR_CMD_INSERT 3
1723817240
#define AR_CMD_EXTRACT 4
1723917241
#define AR_CMD_LIST 5
1724017242
#define AR_CMD_HELP 6
17243
+#define AR_CMD_REMOVE 7
1724117244
1724217245
/*
1724317246
** Other (non-command) switches.
1724417247
*/
17245
-#define AR_SWITCH_VERBOSE 7
17246
-#define AR_SWITCH_FILE 8
17247
-#define AR_SWITCH_DIRECTORY 9
17248
-#define AR_SWITCH_APPEND 10
17249
-#define AR_SWITCH_DRYRUN 11
17248
+#define AR_SWITCH_VERBOSE 8
17249
+#define AR_SWITCH_FILE 9
17250
+#define AR_SWITCH_DIRECTORY 10
17251
+#define AR_SWITCH_APPEND 11
17252
+#define AR_SWITCH_DRYRUN 12
17253
+#define AR_SWITCH_GLOB 13
1725017254
1725117255
static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
1725217256
switch( eSwitch ){
1725317257
case AR_CMD_CREATE:
1725417258
case AR_CMD_EXTRACT:
1725517259
case AR_CMD_LIST:
17260
+ case AR_CMD_REMOVE:
1725617261
case AR_CMD_UPDATE:
1725717262
case AR_CMD_INSERT:
1725817263
case AR_CMD_HELP:
1725917264
if( pAr->eCmd ){
1726017265
return arErrorMsg(pAr, "multiple command options");
@@ -17262,10 +17267,13 @@
1726217267
pAr->eCmd = eSwitch;
1726317268
break;
1726417269
1726517270
case AR_SWITCH_DRYRUN:
1726617271
pAr->bDryRun = 1;
17272
+ break;
17273
+ case AR_SWITCH_GLOB:
17274
+ pAr->bGlob = 1;
1726717275
break;
1726817276
case AR_SWITCH_VERBOSE:
1726917277
pAr->bVerbose = 1;
1727017278
break;
1727117279
case AR_SWITCH_APPEND:
@@ -17301,17 +17309,19 @@
1730117309
} aSwitch[] = {
1730217310
{ "create", 'c', AR_CMD_CREATE, 0 },
1730317311
{ "extract", 'x', AR_CMD_EXTRACT, 0 },
1730417312
{ "insert", 'i', AR_CMD_INSERT, 0 },
1730517313
{ "list", 't', AR_CMD_LIST, 0 },
17314
+ { "remove", 'r', AR_CMD_REMOVE, 0 },
1730617315
{ "update", 'u', AR_CMD_UPDATE, 0 },
1730717316
{ "help", 'h', AR_CMD_HELP, 0 },
1730817317
{ "verbose", 'v', AR_SWITCH_VERBOSE, 0 },
1730917318
{ "file", 'f', AR_SWITCH_FILE, 1 },
1731017319
{ "append", 'a', AR_SWITCH_APPEND, 1 },
1731117320
{ "directory", 'C', AR_SWITCH_DIRECTORY, 1 },
1731217321
{ "dryrun", 'n', AR_SWITCH_DRYRUN, 0 },
17322
+ { "glob", 'g', AR_SWITCH_GLOB, 0 },
1731317323
};
1731417324
int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch);
1731517325
struct ArSwitch *pEnd = &aSwitch[nSwitch];
1731617326
1731717327
if( nArg<=1 ){
@@ -17424,15 +17434,17 @@
1742417434
return SQLITE_OK;
1742517435
}
1742617436
1742717437
/*
1742817438
** This function assumes that all arguments within the ArCommand.azArg[]
17429
-** array refer to archive members, as for the --extract or --list commands.
17430
-** It checks that each of them are present. If any specified file is not
17431
-** present in the archive, an error is printed to stderr and an error
17432
-** code returned. Otherwise, if all specified arguments are present in
17433
-** the archive, SQLITE_OK is returned.
17439
+** array refer to archive members, as for the --extract, --list or --remove
17440
+** commands. It checks that each of them are "present". If any specified
17441
+** file is not present in the archive, an error is printed to stderr and an
17442
+** error code returned. Otherwise, if all specified arguments are present
17443
+** in the archive, SQLITE_OK is returned. Here, "present" means either an
17444
+** exact equality when pAr->bGlob is false or a "name GLOB pattern" match
17445
+** when pAr->bGlob is true.
1743417446
**
1743517447
** This function strips any trailing '/' characters from each argument.
1743617448
** This is consistent with the way the [tar] command seems to work on
1743717449
** Linux.
1743817450
*/
@@ -17439,15 +17451,15 @@
1743917451
static int arCheckEntries(ArCommand *pAr){
1744017452
int rc = SQLITE_OK;
1744117453
if( pAr->nArg ){
1744217454
int i, j;
1744317455
sqlite3_stmt *pTest = 0;
17456
+ const char *zSel = (pAr->bGlob)
17457
+ ? "SELECT name FROM %s WHERE glob($name,name)"
17458
+ : "SELECT name FROM %s WHERE name=$name";
1744417459
17445
- shellPreparePrintf(pAr->db, &rc, &pTest,
17446
- "SELECT name FROM %s WHERE name=$name",
17447
- pAr->zSrcTable
17448
- );
17460
+ shellPreparePrintf(pAr->db, &rc, &pTest, zSel, pAr->zSrcTable);
1744917461
j = sqlite3_bind_parameter_index(pTest, "$name");
1745017462
for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
1745117463
char *z = pAr->azArg[i];
1745217464
int n = strlen30(z);
1745317465
int bOk = 0;
@@ -17471,29 +17483,31 @@
1747117483
/*
1747217484
** Format a WHERE clause that can be used against the "sqlar" table to
1747317485
** identify all archive members that match the command arguments held
1747417486
** in (*pAr). Leave this WHERE clause in (*pzWhere) before returning.
1747517487
** The caller is responsible for eventually calling sqlite3_free() on
17476
-** any non-NULL (*pzWhere) value.
17488
+** any non-NULL (*pzWhere) value. Here, "match" means strict equality
17489
+** when pAr->bGlob is false and GLOB match when pAr->bGlob is true.
1747717490
*/
1747817491
static void arWhereClause(
1747917492
int *pRc,
17480
- ArCommand *pAr,
17493
+ ArCommand *pAr,
1748117494
char **pzWhere /* OUT: New WHERE clause */
1748217495
){
1748317496
char *zWhere = 0;
17497
+ const char *zSameOp = (pAr->bGlob)? "GLOB" : "=";
1748417498
if( *pRc==SQLITE_OK ){
1748517499
if( pAr->nArg==0 ){
1748617500
zWhere = sqlite3_mprintf("1");
1748717501
}else{
1748817502
int i;
1748917503
const char *zSep = "";
1749017504
for(i=0; i<pAr->nArg; i++){
1749117505
const char *z = pAr->azArg[i];
1749217506
zWhere = sqlite3_mprintf(
17493
- "%z%s name = '%q' OR substr(name,1,%d) = '%q/'",
17494
- zWhere, zSep, z, strlen30(z)+1, z
17507
+ "%z%s name %s '%q' OR substr(name,1,%d) %s '%q/'",
17508
+ zWhere, zSep, zSameOp, z, strlen30(z)+1, zSameOp, z
1749517509
);
1749617510
if( zWhere==0 ){
1749717511
*pRc = SQLITE_NOMEM;
1749817512
break;
1749917513
}
@@ -17542,10 +17556,51 @@
1754217556
shellFinalize(&rc, pSql);
1754317557
sqlite3_free(zWhere);
1754417558
return rc;
1754517559
}
1754617560
17561
+
17562
+/*
17563
+** Implementation of .ar "Remove" command.
17564
+*/
17565
+static int arRemoveCommand(ArCommand *pAr){
17566
+ int rc = 0;
17567
+ char *zSql = 0;
17568
+ char *zWhere = 0;
17569
+
17570
+ if( pAr->nArg ){
17571
+ /* Verify that args actually exist within the archive before proceeding.
17572
+ ** And formulate a WHERE clause to match them. */
17573
+ rc = arCheckEntries(pAr);
17574
+ arWhereClause(&rc, pAr, &zWhere);
17575
+ }
17576
+ if( rc==SQLITE_OK ){
17577
+ zSql = sqlite3_mprintf("DELETE FROM %s WHERE %s;",
17578
+ pAr->zSrcTable, zWhere);
17579
+ if( pAr->bDryRun ){
17580
+ utf8_printf(pAr->p->out, "%s\n", zSql);
17581
+ }else{
17582
+ char *zErr = 0;
17583
+ rc = sqlite3_exec(pAr->db, "SAVEPOINT ar;", 0, 0, 0);
17584
+ if( rc==SQLITE_OK ){
17585
+ rc = sqlite3_exec(pAr->db, zSql, 0, 0, &zErr);
17586
+ if( rc!=SQLITE_OK ){
17587
+ sqlite3_exec(pAr->db, "ROLLBACK TO ar; RELEASE ar;", 0, 0, 0);
17588
+ }else{
17589
+ rc = sqlite3_exec(pAr->db, "RELEASE ar;", 0, 0, 0);
17590
+ }
17591
+ }
17592
+ if( zErr ){
17593
+ utf8_printf(stdout, "ERROR: %s\n", zErr);
17594
+ sqlite3_free(zErr);
17595
+ }
17596
+ }
17597
+ }
17598
+ sqlite3_free(zWhere);
17599
+ sqlite3_free(zSql);
17600
+ return rc;
17601
+}
1754717602
1754817603
/*
1754917604
** Implementation of .ar "eXtract" command.
1755017605
*/
1755117606
static int arExtractCommand(ArCommand *pAr){
@@ -17795,11 +17850,11 @@
1779517850
cmd.bZip = 1;
1779617851
}else if( cmd.zFile ){
1779717852
int flags;
1779817853
if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
1779917854
if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
17800
- || cmd.eCmd==AR_CMD_UPDATE ){
17855
+ || cmd.eCmd==AR_CMD_REMOVE || cmd.eCmd==AR_CMD_UPDATE ){
1780117856
flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
1780217857
}else{
1780317858
flags = SQLITE_OPEN_READONLY;
1780417859
}
1780517860
cmd.db = 0;
@@ -17850,10 +17905,14 @@
1785017905
break;
1785117906
1785217907
case AR_CMD_INSERT:
1785317908
rc = arCreateOrUpdateCommand(&cmd, 1, 0);
1785417909
break;
17910
+
17911
+ case AR_CMD_REMOVE:
17912
+ rc = arRemoveCommand(&cmd);
17913
+ break;
1785517914
1785617915
default:
1785717916
assert( cmd.eCmd==AR_CMD_UPDATE );
1785817917
rc = arCreateOrUpdateCommand(&cmd, 1, 1);
1785917918
break;
@@ -19339,10 +19398,15 @@
1933919398
int nSkip = 0; /* Initial lines to skip */
1934019399
int useOutputMode = 1; /* Use output mode to determine separators */
1934119400
1934219401
failIfSafeMode(p, "cannot run .import in safe mode");
1934319402
memset(&sCtx, 0, sizeof(sCtx));
19403
+ sCtx.z = sqlite3_malloc64(120);
19404
+ if( sCtx.z==0 ){
19405
+ import_cleanup(&sCtx);
19406
+ shell_out_of_memory();
19407
+ }
1934419408
if( p->mode==MODE_Ascii ){
1934519409
xRead = ascii_read_one_field;
1934619410
}else{
1934719411
xRead = csv_read_one_field;
1934819412
}
@@ -19448,10 +19512,11 @@
1944819512
sCtx.xCloser = fclose;
1944919513
}
1945019514
if( sCtx.in==0 ){
1945119515
utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
1945219516
rc = 1;
19517
+ import_cleanup(&sCtx);
1945319518
goto meta_command_exit;
1945419519
}
1945519520
if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
1945619521
char zSep[2];
1945719522
zSep[1] = 0;
1945819523
--- src/shell.c
+++ src/shell.c
@@ -13662,21 +13662,20 @@
13662 }
13663 return rc;
13664 }
13665
13666 /*
13667 ** Allocate space and save off current error string.
13668 */
13669 static char *save_err_msg(
13670 sqlite3 *db /* Database to query */
 
 
13671 ){
13672 int nErrMsg = 1+strlen30(sqlite3_errmsg(db));
13673 char *zErrMsg = sqlite3_malloc64(nErrMsg);
13674 if( zErrMsg ){
13675 memcpy(zErrMsg, sqlite3_errmsg(db), nErrMsg);
13676 }
13677 return zErrMsg;
13678 }
13679
13680 #ifdef __linux__
13681 /*
13682 ** Attempt to display I/O stats on Linux using /proc/PID/io
@@ -14594,11 +14593,11 @@
14594 while( zSql[0] && (SQLITE_OK == rc) ){
14595 static const char *zStmtSql;
14596 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
14597 if( SQLITE_OK != rc ){
14598 if( pzErrMsg ){
14599 *pzErrMsg = save_err_msg(db);
14600 }
14601 }else{
14602 if( !pStmt ){
14603 /* this happens for a comment or white-space */
14604 zSql = zLeftover;
@@ -14708,11 +14707,11 @@
14708 if( rc!=SQLITE_NOMEM ) rc = rc2;
14709 if( rc==SQLITE_OK ){
14710 zSql = zLeftover;
14711 while( IsSpace(zSql[0]) ) zSql++;
14712 }else if( pzErrMsg ){
14713 *pzErrMsg = save_err_msg(db);
14714 }
14715
14716 /* clear saved stmt handle */
14717 if( pArg ){
14718 pArg->pStmt = NULL;
@@ -15022,17 +15021,19 @@
15022 ".archive ... Manage SQL archives",
15023 " Each command must have exactly one of the following options:",
15024 " -c, --create Create a new archive",
15025 " -u, --update Add or update files with changed mtime",
15026 " -i, --insert Like -u but always add even if unchanged",
 
15027 " -t, --list List contents of archive",
15028 " -x, --extract Extract files from archive",
15029 " Optional arguments:",
15030 " -v, --verbose Print each filename as it is processed",
15031 " -f FILE, --file FILE Use archive FILE (default is current db)",
15032 " -a FILE, --append FILE Open FILE using the apndvfs VFS",
15033 " -C DIR, --directory DIR Read/extract files from directory DIR",
 
15034 " -n, --dryrun Show the SQL that would have occurred",
15035 " Examples:",
15036 " .ar -cf ARCHIVE foo bar # Create ARCHIVE from files foo and bar",
15037 " .ar -tf ARCHIVE # List members of ARCHIVE",
15038 " .ar -xvf ARCHIVE # Verbosely extract files from ARCHIVE",
@@ -17189,10 +17190,11 @@
17189 u8 eCmd; /* An AR_CMD_* value */
17190 u8 bVerbose; /* True if --verbose */
17191 u8 bZip; /* True if the archive is a ZIP */
17192 u8 bDryRun; /* True if --dry-run */
17193 u8 bAppend; /* True if --append */
 
17194 u8 fromCmdLine; /* Run from -A instead of .archive */
17195 int nArg; /* Number of command arguments */
17196 char *zSrcTable; /* "sqlar", "zipfile($file)" or "zip" */
17197 const char *zFile; /* --file argument, or NULL */
17198 const char *zDir; /* --directory argument, or NULL */
@@ -17236,25 +17238,28 @@
17236 #define AR_CMD_UPDATE 2
17237 #define AR_CMD_INSERT 3
17238 #define AR_CMD_EXTRACT 4
17239 #define AR_CMD_LIST 5
17240 #define AR_CMD_HELP 6
 
17241
17242 /*
17243 ** Other (non-command) switches.
17244 */
17245 #define AR_SWITCH_VERBOSE 7
17246 #define AR_SWITCH_FILE 8
17247 #define AR_SWITCH_DIRECTORY 9
17248 #define AR_SWITCH_APPEND 10
17249 #define AR_SWITCH_DRYRUN 11
 
17250
17251 static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
17252 switch( eSwitch ){
17253 case AR_CMD_CREATE:
17254 case AR_CMD_EXTRACT:
17255 case AR_CMD_LIST:
 
17256 case AR_CMD_UPDATE:
17257 case AR_CMD_INSERT:
17258 case AR_CMD_HELP:
17259 if( pAr->eCmd ){
17260 return arErrorMsg(pAr, "multiple command options");
@@ -17262,10 +17267,13 @@
17262 pAr->eCmd = eSwitch;
17263 break;
17264
17265 case AR_SWITCH_DRYRUN:
17266 pAr->bDryRun = 1;
 
 
 
17267 break;
17268 case AR_SWITCH_VERBOSE:
17269 pAr->bVerbose = 1;
17270 break;
17271 case AR_SWITCH_APPEND:
@@ -17301,17 +17309,19 @@
17301 } aSwitch[] = {
17302 { "create", 'c', AR_CMD_CREATE, 0 },
17303 { "extract", 'x', AR_CMD_EXTRACT, 0 },
17304 { "insert", 'i', AR_CMD_INSERT, 0 },
17305 { "list", 't', AR_CMD_LIST, 0 },
 
17306 { "update", 'u', AR_CMD_UPDATE, 0 },
17307 { "help", 'h', AR_CMD_HELP, 0 },
17308 { "verbose", 'v', AR_SWITCH_VERBOSE, 0 },
17309 { "file", 'f', AR_SWITCH_FILE, 1 },
17310 { "append", 'a', AR_SWITCH_APPEND, 1 },
17311 { "directory", 'C', AR_SWITCH_DIRECTORY, 1 },
17312 { "dryrun", 'n', AR_SWITCH_DRYRUN, 0 },
 
17313 };
17314 int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch);
17315 struct ArSwitch *pEnd = &aSwitch[nSwitch];
17316
17317 if( nArg<=1 ){
@@ -17424,15 +17434,17 @@
17424 return SQLITE_OK;
17425 }
17426
17427 /*
17428 ** This function assumes that all arguments within the ArCommand.azArg[]
17429 ** array refer to archive members, as for the --extract or --list commands.
17430 ** It checks that each of them are present. If any specified file is not
17431 ** present in the archive, an error is printed to stderr and an error
17432 ** code returned. Otherwise, if all specified arguments are present in
17433 ** the archive, SQLITE_OK is returned.
 
 
17434 **
17435 ** This function strips any trailing '/' characters from each argument.
17436 ** This is consistent with the way the [tar] command seems to work on
17437 ** Linux.
17438 */
@@ -17439,15 +17451,15 @@
17439 static int arCheckEntries(ArCommand *pAr){
17440 int rc = SQLITE_OK;
17441 if( pAr->nArg ){
17442 int i, j;
17443 sqlite3_stmt *pTest = 0;
 
 
 
17444
17445 shellPreparePrintf(pAr->db, &rc, &pTest,
17446 "SELECT name FROM %s WHERE name=$name",
17447 pAr->zSrcTable
17448 );
17449 j = sqlite3_bind_parameter_index(pTest, "$name");
17450 for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
17451 char *z = pAr->azArg[i];
17452 int n = strlen30(z);
17453 int bOk = 0;
@@ -17471,29 +17483,31 @@
17471 /*
17472 ** Format a WHERE clause that can be used against the "sqlar" table to
17473 ** identify all archive members that match the command arguments held
17474 ** in (*pAr). Leave this WHERE clause in (*pzWhere) before returning.
17475 ** The caller is responsible for eventually calling sqlite3_free() on
17476 ** any non-NULL (*pzWhere) value.
 
17477 */
17478 static void arWhereClause(
17479 int *pRc,
17480 ArCommand *pAr,
17481 char **pzWhere /* OUT: New WHERE clause */
17482 ){
17483 char *zWhere = 0;
 
17484 if( *pRc==SQLITE_OK ){
17485 if( pAr->nArg==0 ){
17486 zWhere = sqlite3_mprintf("1");
17487 }else{
17488 int i;
17489 const char *zSep = "";
17490 for(i=0; i<pAr->nArg; i++){
17491 const char *z = pAr->azArg[i];
17492 zWhere = sqlite3_mprintf(
17493 "%z%s name = '%q' OR substr(name,1,%d) = '%q/'",
17494 zWhere, zSep, z, strlen30(z)+1, z
17495 );
17496 if( zWhere==0 ){
17497 *pRc = SQLITE_NOMEM;
17498 break;
17499 }
@@ -17542,10 +17556,51 @@
17542 shellFinalize(&rc, pSql);
17543 sqlite3_free(zWhere);
17544 return rc;
17545 }
17546
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17547
17548 /*
17549 ** Implementation of .ar "eXtract" command.
17550 */
17551 static int arExtractCommand(ArCommand *pAr){
@@ -17795,11 +17850,11 @@
17795 cmd.bZip = 1;
17796 }else if( cmd.zFile ){
17797 int flags;
17798 if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
17799 if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
17800 || cmd.eCmd==AR_CMD_UPDATE ){
17801 flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
17802 }else{
17803 flags = SQLITE_OPEN_READONLY;
17804 }
17805 cmd.db = 0;
@@ -17850,10 +17905,14 @@
17850 break;
17851
17852 case AR_CMD_INSERT:
17853 rc = arCreateOrUpdateCommand(&cmd, 1, 0);
17854 break;
 
 
 
 
17855
17856 default:
17857 assert( cmd.eCmd==AR_CMD_UPDATE );
17858 rc = arCreateOrUpdateCommand(&cmd, 1, 1);
17859 break;
@@ -19339,10 +19398,15 @@
19339 int nSkip = 0; /* Initial lines to skip */
19340 int useOutputMode = 1; /* Use output mode to determine separators */
19341
19342 failIfSafeMode(p, "cannot run .import in safe mode");
19343 memset(&sCtx, 0, sizeof(sCtx));
 
 
 
 
 
19344 if( p->mode==MODE_Ascii ){
19345 xRead = ascii_read_one_field;
19346 }else{
19347 xRead = csv_read_one_field;
19348 }
@@ -19448,10 +19512,11 @@
19448 sCtx.xCloser = fclose;
19449 }
19450 if( sCtx.in==0 ){
19451 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
19452 rc = 1;
 
19453 goto meta_command_exit;
19454 }
19455 if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
19456 char zSep[2];
19457 zSep[1] = 0;
19458
--- src/shell.c
+++ src/shell.c
@@ -13662,21 +13662,20 @@
13662 }
13663 return rc;
13664 }
13665
13666 /*
13667 ** Allocate space and save off string indicating current error.
13668 */
13669 static char *save_err_msg(
13670 sqlite3 *db, /* Database to query */
13671 const char *zWhen, /* Qualifier (format) wrapper */
13672 int rc /* Error code returned from API */
13673 ){
13674 if( zWhen==0 )
13675 zWhen = "%s (%d)";
13676 return sqlite3_mprintf(zWhen, sqlite3_errmsg(db), rc);
 
 
 
13677 }
13678
13679 #ifdef __linux__
13680 /*
13681 ** Attempt to display I/O stats on Linux using /proc/PID/io
@@ -14594,11 +14593,11 @@
14593 while( zSql[0] && (SQLITE_OK == rc) ){
14594 static const char *zStmtSql;
14595 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
14596 if( SQLITE_OK != rc ){
14597 if( pzErrMsg ){
14598 *pzErrMsg = save_err_msg(db, "in prepare, %s (%d)", rc);
14599 }
14600 }else{
14601 if( !pStmt ){
14602 /* this happens for a comment or white-space */
14603 zSql = zLeftover;
@@ -14708,11 +14707,11 @@
14707 if( rc!=SQLITE_NOMEM ) rc = rc2;
14708 if( rc==SQLITE_OK ){
14709 zSql = zLeftover;
14710 while( IsSpace(zSql[0]) ) zSql++;
14711 }else if( pzErrMsg ){
14712 *pzErrMsg = save_err_msg(db, "stepping, %s (%d)", rc);
14713 }
14714
14715 /* clear saved stmt handle */
14716 if( pArg ){
14717 pArg->pStmt = NULL;
@@ -15022,17 +15021,19 @@
15021 ".archive ... Manage SQL archives",
15022 " Each command must have exactly one of the following options:",
15023 " -c, --create Create a new archive",
15024 " -u, --update Add or update files with changed mtime",
15025 " -i, --insert Like -u but always add even if unchanged",
15026 " -r, --remove Remove files from archive",
15027 " -t, --list List contents of archive",
15028 " -x, --extract Extract files from archive",
15029 " Optional arguments:",
15030 " -v, --verbose Print each filename as it is processed",
15031 " -f FILE, --file FILE Use archive FILE (default is current db)",
15032 " -a FILE, --append FILE Open FILE using the apndvfs VFS",
15033 " -C DIR, --directory DIR Read/extract files from directory DIR",
15034 " -g, --glob Use glob matching for names in archive",
15035 " -n, --dryrun Show the SQL that would have occurred",
15036 " Examples:",
15037 " .ar -cf ARCHIVE foo bar # Create ARCHIVE from files foo and bar",
15038 " .ar -tf ARCHIVE # List members of ARCHIVE",
15039 " .ar -xvf ARCHIVE # Verbosely extract files from ARCHIVE",
@@ -17189,10 +17190,11 @@
17190 u8 eCmd; /* An AR_CMD_* value */
17191 u8 bVerbose; /* True if --verbose */
17192 u8 bZip; /* True if the archive is a ZIP */
17193 u8 bDryRun; /* True if --dry-run */
17194 u8 bAppend; /* True if --append */
17195 u8 bGlob; /* True if --glob */
17196 u8 fromCmdLine; /* Run from -A instead of .archive */
17197 int nArg; /* Number of command arguments */
17198 char *zSrcTable; /* "sqlar", "zipfile($file)" or "zip" */
17199 const char *zFile; /* --file argument, or NULL */
17200 const char *zDir; /* --directory argument, or NULL */
@@ -17236,25 +17238,28 @@
17238 #define AR_CMD_UPDATE 2
17239 #define AR_CMD_INSERT 3
17240 #define AR_CMD_EXTRACT 4
17241 #define AR_CMD_LIST 5
17242 #define AR_CMD_HELP 6
17243 #define AR_CMD_REMOVE 7
17244
17245 /*
17246 ** Other (non-command) switches.
17247 */
17248 #define AR_SWITCH_VERBOSE 8
17249 #define AR_SWITCH_FILE 9
17250 #define AR_SWITCH_DIRECTORY 10
17251 #define AR_SWITCH_APPEND 11
17252 #define AR_SWITCH_DRYRUN 12
17253 #define AR_SWITCH_GLOB 13
17254
17255 static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
17256 switch( eSwitch ){
17257 case AR_CMD_CREATE:
17258 case AR_CMD_EXTRACT:
17259 case AR_CMD_LIST:
17260 case AR_CMD_REMOVE:
17261 case AR_CMD_UPDATE:
17262 case AR_CMD_INSERT:
17263 case AR_CMD_HELP:
17264 if( pAr->eCmd ){
17265 return arErrorMsg(pAr, "multiple command options");
@@ -17262,10 +17267,13 @@
17267 pAr->eCmd = eSwitch;
17268 break;
17269
17270 case AR_SWITCH_DRYRUN:
17271 pAr->bDryRun = 1;
17272 break;
17273 case AR_SWITCH_GLOB:
17274 pAr->bGlob = 1;
17275 break;
17276 case AR_SWITCH_VERBOSE:
17277 pAr->bVerbose = 1;
17278 break;
17279 case AR_SWITCH_APPEND:
@@ -17301,17 +17309,19 @@
17309 } aSwitch[] = {
17310 { "create", 'c', AR_CMD_CREATE, 0 },
17311 { "extract", 'x', AR_CMD_EXTRACT, 0 },
17312 { "insert", 'i', AR_CMD_INSERT, 0 },
17313 { "list", 't', AR_CMD_LIST, 0 },
17314 { "remove", 'r', AR_CMD_REMOVE, 0 },
17315 { "update", 'u', AR_CMD_UPDATE, 0 },
17316 { "help", 'h', AR_CMD_HELP, 0 },
17317 { "verbose", 'v', AR_SWITCH_VERBOSE, 0 },
17318 { "file", 'f', AR_SWITCH_FILE, 1 },
17319 { "append", 'a', AR_SWITCH_APPEND, 1 },
17320 { "directory", 'C', AR_SWITCH_DIRECTORY, 1 },
17321 { "dryrun", 'n', AR_SWITCH_DRYRUN, 0 },
17322 { "glob", 'g', AR_SWITCH_GLOB, 0 },
17323 };
17324 int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch);
17325 struct ArSwitch *pEnd = &aSwitch[nSwitch];
17326
17327 if( nArg<=1 ){
@@ -17424,15 +17434,17 @@
17434 return SQLITE_OK;
17435 }
17436
17437 /*
17438 ** This function assumes that all arguments within the ArCommand.azArg[]
17439 ** array refer to archive members, as for the --extract, --list or --remove
17440 ** commands. It checks that each of them are "present". If any specified
17441 ** file is not present in the archive, an error is printed to stderr and an
17442 ** error code returned. Otherwise, if all specified arguments are present
17443 ** in the archive, SQLITE_OK is returned. Here, "present" means either an
17444 ** exact equality when pAr->bGlob is false or a "name GLOB pattern" match
17445 ** when pAr->bGlob is true.
17446 **
17447 ** This function strips any trailing '/' characters from each argument.
17448 ** This is consistent with the way the [tar] command seems to work on
17449 ** Linux.
17450 */
@@ -17439,15 +17451,15 @@
17451 static int arCheckEntries(ArCommand *pAr){
17452 int rc = SQLITE_OK;
17453 if( pAr->nArg ){
17454 int i, j;
17455 sqlite3_stmt *pTest = 0;
17456 const char *zSel = (pAr->bGlob)
17457 ? "SELECT name FROM %s WHERE glob($name,name)"
17458 : "SELECT name FROM %s WHERE name=$name";
17459
17460 shellPreparePrintf(pAr->db, &rc, &pTest, zSel, pAr->zSrcTable);
 
 
 
17461 j = sqlite3_bind_parameter_index(pTest, "$name");
17462 for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
17463 char *z = pAr->azArg[i];
17464 int n = strlen30(z);
17465 int bOk = 0;
@@ -17471,29 +17483,31 @@
17483 /*
17484 ** Format a WHERE clause that can be used against the "sqlar" table to
17485 ** identify all archive members that match the command arguments held
17486 ** in (*pAr). Leave this WHERE clause in (*pzWhere) before returning.
17487 ** The caller is responsible for eventually calling sqlite3_free() on
17488 ** any non-NULL (*pzWhere) value. Here, "match" means strict equality
17489 ** when pAr->bGlob is false and GLOB match when pAr->bGlob is true.
17490 */
17491 static void arWhereClause(
17492 int *pRc,
17493 ArCommand *pAr,
17494 char **pzWhere /* OUT: New WHERE clause */
17495 ){
17496 char *zWhere = 0;
17497 const char *zSameOp = (pAr->bGlob)? "GLOB" : "=";
17498 if( *pRc==SQLITE_OK ){
17499 if( pAr->nArg==0 ){
17500 zWhere = sqlite3_mprintf("1");
17501 }else{
17502 int i;
17503 const char *zSep = "";
17504 for(i=0; i<pAr->nArg; i++){
17505 const char *z = pAr->azArg[i];
17506 zWhere = sqlite3_mprintf(
17507 "%z%s name %s '%q' OR substr(name,1,%d) %s '%q/'",
17508 zWhere, zSep, zSameOp, z, strlen30(z)+1, zSameOp, z
17509 );
17510 if( zWhere==0 ){
17511 *pRc = SQLITE_NOMEM;
17512 break;
17513 }
@@ -17542,10 +17556,51 @@
17556 shellFinalize(&rc, pSql);
17557 sqlite3_free(zWhere);
17558 return rc;
17559 }
17560
17561
17562 /*
17563 ** Implementation of .ar "Remove" command.
17564 */
17565 static int arRemoveCommand(ArCommand *pAr){
17566 int rc = 0;
17567 char *zSql = 0;
17568 char *zWhere = 0;
17569
17570 if( pAr->nArg ){
17571 /* Verify that args actually exist within the archive before proceeding.
17572 ** And formulate a WHERE clause to match them. */
17573 rc = arCheckEntries(pAr);
17574 arWhereClause(&rc, pAr, &zWhere);
17575 }
17576 if( rc==SQLITE_OK ){
17577 zSql = sqlite3_mprintf("DELETE FROM %s WHERE %s;",
17578 pAr->zSrcTable, zWhere);
17579 if( pAr->bDryRun ){
17580 utf8_printf(pAr->p->out, "%s\n", zSql);
17581 }else{
17582 char *zErr = 0;
17583 rc = sqlite3_exec(pAr->db, "SAVEPOINT ar;", 0, 0, 0);
17584 if( rc==SQLITE_OK ){
17585 rc = sqlite3_exec(pAr->db, zSql, 0, 0, &zErr);
17586 if( rc!=SQLITE_OK ){
17587 sqlite3_exec(pAr->db, "ROLLBACK TO ar; RELEASE ar;", 0, 0, 0);
17588 }else{
17589 rc = sqlite3_exec(pAr->db, "RELEASE ar;", 0, 0, 0);
17590 }
17591 }
17592 if( zErr ){
17593 utf8_printf(stdout, "ERROR: %s\n", zErr);
17594 sqlite3_free(zErr);
17595 }
17596 }
17597 }
17598 sqlite3_free(zWhere);
17599 sqlite3_free(zSql);
17600 return rc;
17601 }
17602
17603 /*
17604 ** Implementation of .ar "eXtract" command.
17605 */
17606 static int arExtractCommand(ArCommand *pAr){
@@ -17795,11 +17850,11 @@
17850 cmd.bZip = 1;
17851 }else if( cmd.zFile ){
17852 int flags;
17853 if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
17854 if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
17855 || cmd.eCmd==AR_CMD_REMOVE || cmd.eCmd==AR_CMD_UPDATE ){
17856 flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
17857 }else{
17858 flags = SQLITE_OPEN_READONLY;
17859 }
17860 cmd.db = 0;
@@ -17850,10 +17905,14 @@
17905 break;
17906
17907 case AR_CMD_INSERT:
17908 rc = arCreateOrUpdateCommand(&cmd, 1, 0);
17909 break;
17910
17911 case AR_CMD_REMOVE:
17912 rc = arRemoveCommand(&cmd);
17913 break;
17914
17915 default:
17916 assert( cmd.eCmd==AR_CMD_UPDATE );
17917 rc = arCreateOrUpdateCommand(&cmd, 1, 1);
17918 break;
@@ -19339,10 +19398,15 @@
19398 int nSkip = 0; /* Initial lines to skip */
19399 int useOutputMode = 1; /* Use output mode to determine separators */
19400
19401 failIfSafeMode(p, "cannot run .import in safe mode");
19402 memset(&sCtx, 0, sizeof(sCtx));
19403 sCtx.z = sqlite3_malloc64(120);
19404 if( sCtx.z==0 ){
19405 import_cleanup(&sCtx);
19406 shell_out_of_memory();
19407 }
19408 if( p->mode==MODE_Ascii ){
19409 xRead = ascii_read_one_field;
19410 }else{
19411 xRead = csv_read_one_field;
19412 }
@@ -19448,10 +19512,11 @@
19512 sCtx.xCloser = fclose;
19513 }
19514 if( sCtx.in==0 ){
19515 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
19516 rc = 1;
19517 import_cleanup(&sCtx);
19518 goto meta_command_exit;
19519 }
19520 if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
19521 char zSep[2];
19522 zSep[1] = 0;
19523
+286 -76
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.37.0"
456456
#define SQLITE_VERSION_NUMBER 3037000
457
-#define SQLITE_SOURCE_ID "2021-10-26 09:53:51 4b41535b096dec4b15a85e657102a72d4288728da6103f3fdcbe0e6f244c673a"
457
+#define SQLITE_SOURCE_ID "2021-11-03 16:35:23 3206edff947b9edb485466f05b2baadf725d798229630c7e83e88c0b9ae278ca"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -6709,10 +6709,76 @@
67096709
**
67106710
** See also the [sqlite3_update_hook()] interface.
67116711
*/
67126712
SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
67136713
SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
6714
+
6715
+/*
6716
+** CAPI3REF: Autovacuum Compaction Amount Callback
6717
+** METHOD: sqlite3
6718
+**
6719
+** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback
6720
+** function C that is invoked prior to each autovacuum of the database
6721
+** file. ^The callback is passed a copy of the generic data pointer (P),
6722
+** the schema-name of the attached database that is being autovacuumed,
6723
+** the the size of the database file in pages, the number of free pages,
6724
+** and the number of bytes per page, respectively. The callback should
6725
+** return the number of free pages that should be removed by the
6726
+** autovacuum. ^If the callback returns zero, then no autovacuum happens.
6727
+** ^If the value returned is greater than or equal to the number of
6728
+** free pages, then a complete autovacuum happens.
6729
+**
6730
+** <p>^If there are multiple ATTACH-ed database files that are being
6731
+** modified as part of a transaction commit, then the autovacuum pages
6732
+** callback is invoked separately for each file.
6733
+**
6734
+** <p><b>The callback is not reentrant.</b> The callback function should
6735
+** not attempt to invoke any other SQLite interface. If it does, bad
6736
+** things may happen, including segmentation faults and corrupt database
6737
+** files. The callback function should be a simple function that
6738
+** does some arithmetic on its input parameters and returns a result.
6739
+**
6740
+** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional
6741
+** destructor for the P parameter. ^If X is not NULL, then X(P) is
6742
+** invoked whenever the database connection closes or when the callback
6743
+** is overwritten by another invocation of sqlite3_autovacuum_pages().
6744
+**
6745
+** <p>^There is only one autovacuum pages callback per database connection.
6746
+** ^Each call to the sqlite3_autovacuum_pages() interface overrides all
6747
+** previous invocations for that database connection. ^If the callback
6748
+** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,
6749
+** then the autovacuum steps callback is cancelled. The return value
6750
+** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might
6751
+** be some other error code if something goes wrong. The current
6752
+** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other
6753
+** return codes might be added in future releases.
6754
+**
6755
+** <p>If no autovacuum pages callback is specified (the usual case) or
6756
+** a NULL pointer is provided for the callback,
6757
+** then the default behavior is to vacuum all free pages. So, in other
6758
+** words, the default behavior is the same as if the callback function
6759
+** were something like this:
6760
+**
6761
+** <blockquote><pre>
6762
+** &nbsp; unsigned int demonstration_autovac_pages_callback(
6763
+** &nbsp; void *pClientData,
6764
+** &nbsp; const char *zSchema,
6765
+** &nbsp; unsigned int nDbPage,
6766
+** &nbsp; unsigned int nFreePage,
6767
+** &nbsp; unsigned int nBytePerPage
6768
+** &nbsp; ){
6769
+** &nbsp; return nFreePage;
6770
+** &nbsp; }
6771
+** </pre></blockquote>
6772
+*/
6773
+SQLITE_API int sqlite3_autovacuum_pages(
6774
+ sqlite3 *db,
6775
+ unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
6776
+ void*,
6777
+ void(*)(void*)
6778
+);
6779
+
67146780
67156781
/*
67166782
** CAPI3REF: Data Change Notification Callbacks
67176783
** METHOD: sqlite3
67186784
**
@@ -16437,10 +16503,13 @@
1643716503
int (*xCommitCallback)(void*); /* Invoked at every commit. */
1643816504
void *pRollbackArg; /* Argument to xRollbackCallback() */
1643916505
void (*xRollbackCallback)(void*); /* Invoked at every commit. */
1644016506
void *pUpdateArg;
1644116507
void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
16508
+ void *pAutovacPagesArg; /* Client argument to autovac_pages */
16509
+ void (*xAutovacDestr)(void*); /* Destructor for pAutovacPAgesArg */
16510
+ unsigned int (*xAutovacPages)(void*,const char*,u32,u32,u32);
1644216511
Parse *pParse; /* Current parse */
1644316512
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
1644416513
void *pPreUpdateArg; /* First argument to xPreUpdateCallback */
1644516514
void (*xPreUpdateCallback)( /* Registered using sqlite3_preupdate_hook() */
1644616515
void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64
@@ -18694,12 +18763,14 @@
1869418763
} InitData;
1869518764
1869618765
/*
1869718766
** Allowed values for mInitFlags
1869818767
*/
18768
+#define INITFLAG_AlterMask 0x0003 /* Types of ALTER */
1869918769
#define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */
1870018770
#define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */
18771
+#define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */
1870118772
1870218773
/* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled
1870318774
** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning
1870418775
** parameters are for temporary use during development, to help find
1870518776
** optimial values for parameters in the query planner. The should not
@@ -24126,16 +24197,19 @@
2412624197
pFile = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile);
2412724198
if( pFile ){
2412824199
rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, pOutFlags);
2412924200
if( rc!=SQLITE_OK ){
2413024201
sqlite3_free(pFile);
24202
+ *ppFile = 0;
2413124203
}else{
2413224204
*ppFile = pFile;
2413324205
}
2413424206
}else{
24207
+ *ppFile = 0;
2413524208
rc = SQLITE_NOMEM_BKPT;
2413624209
}
24210
+ assert( *ppFile!=0 || rc!=SQLITE_OK );
2413724211
return rc;
2413824212
}
2413924213
SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *pFile){
2414024214
assert( pFile );
2414124215
sqlite3OsClose(pFile);
@@ -38079,11 +38153,13 @@
3807938153
}
3808038154
}
3808138155
3808238156
/* Forward declaration */
3808338157
static int unixGetTempname(int nBuf, char *zBuf);
38084
-static int unixFcntlExternalReader(unixFile*, int*);
38158
+#ifndef SQLITE_OMIT_WAL
38159
+ static int unixFcntlExternalReader(unixFile*, int*);
38160
+#endif
3808538161
3808638162
/*
3808738163
** Information and control of an open file handle.
3808838164
*/
3808938165
static int unixFileControl(sqlite3_file *id, int op, void *pArg){
@@ -38198,11 +38274,16 @@
3819838274
return proxyFileControl(id,op,pArg);
3819938275
}
3820038276
#endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
3820138277
3820238278
case SQLITE_FCNTL_EXTERNAL_READER: {
38279
+#ifndef SQLITE_OMIT_WAL
3820338280
return unixFcntlExternalReader((unixFile*)id, (int*)pArg);
38281
+#else
38282
+ *(int*)pArg = 0;
38283
+ return SQLITE_OK;
38284
+#endif
3820438285
}
3820538286
}
3820638287
return SQLITE_NOTFOUND;
3820738288
}
3820838289
@@ -48902,10 +48983,11 @@
4890248983
int *pOutFlags
4890348984
){
4890448985
MemFile *pFile = (MemFile*)pFd;
4890548986
MemStore *p = 0;
4890648987
int szName;
48988
+ UNUSED_PARAMETER(pVfs);
4890748989
4890848990
memset(pFile, 0, sizeof(*pFile));
4890948991
szName = sqlite3Strlen30(zName);
4891048992
if( szName>1 && zName[0]=='/' ){
4891148993
int i;
@@ -60864,13 +60946,17 @@
6086460946
** If the wal-index is currently smaller the iPage pages then the size
6086560947
** of the wal-index might be increased, but only if it is safe to do
6086660948
** so. It is safe to enlarge the wal-index if pWal->writeLock is true
6086760949
** or pWal->exclusiveMode==WAL_HEAPMEMORY_MODE.
6086860950
**
60869
-** If this call is successful, *ppPage is set to point to the wal-index
60870
-** page and SQLITE_OK is returned. If an error (an OOM or VFS error) occurs,
60871
-** then an SQLite error code is returned and *ppPage is set to 0.
60951
+** Three possible result scenarios:
60952
+**
60953
+** (1) rc==SQLITE_OK and *ppPage==Requested-Wal-Index-Page
60954
+** (2) rc>=SQLITE_ERROR and *ppPage==NULL
60955
+** (3) rc==SQLITE_OK and *ppPage==NULL // only if iPage==0
60956
+**
60957
+** Scenario (3) can only occur when pWal->writeLock is false and iPage==0
6087260958
*/
6087360959
static SQLITE_NOINLINE int walIndexPageRealloc(
6087460960
Wal *pWal, /* The WAL context */
6087560961
int iPage, /* The page we seek */
6087660962
volatile u32 **ppPage /* Write the page pointer here */
@@ -60899,11 +60985,13 @@
6089960985
if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM_BKPT;
6090060986
}else{
6090160987
rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ,
6090260988
pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
6090360989
);
60904
- assert( pWal->apWiData[iPage]!=0 || rc!=SQLITE_OK || pWal->writeLock==0 );
60990
+ assert( pWal->apWiData[iPage]!=0
60991
+ || rc!=SQLITE_OK
60992
+ || (pWal->writeLock==0 && iPage==0) );
6090560993
testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK );
6090660994
if( rc==SQLITE_OK ){
6090760995
if( iPage>0 && sqlite3FaultSim(600) ) rc = SQLITE_NOMEM;
6090860996
}else if( (rc&0xff)==SQLITE_READONLY ){
6090960997
pWal->readOnly |= WAL_SHM_RDONLY;
@@ -61238,12 +61326,12 @@
6123861326
** in the wal-index file. Set pLoc->iZero to one less than the frame
6123961327
** number of the first frame indexed by this hash table. If a
6124061328
** slot in the hash table is set to N, it refers to frame number
6124161329
** (pLoc->iZero+N) in the log.
6124261330
**
61243
-** Finally, set pLoc->aPgno so that pLoc->aPgno[1] is the page number of the
61244
-** first frame indexed by the hash table, frame (pLoc->iZero+1).
61331
+** Finally, set pLoc->aPgno so that pLoc->aPgno[0] is the page number of the
61332
+** first frame indexed by the hash table, frame (pLoc->iZero).
6124561333
*/
6124661334
static int walHashGet(
6124761335
Wal *pWal, /* WAL handle */
6124861336
int iHash, /* Find the iHash'th table */
6124961337
WalHashLoc *pLoc /* OUT: Hash table location */
@@ -61251,19 +61339,20 @@
6125161339
int rc; /* Return code */
6125261340
6125361341
rc = walIndexPage(pWal, iHash, &pLoc->aPgno);
6125461342
assert( rc==SQLITE_OK || iHash>0 );
6125561343
61256
- if( rc==SQLITE_OK ){
61344
+ if( pLoc->aPgno ){
6125761345
pLoc->aHash = (volatile ht_slot *)&pLoc->aPgno[HASHTABLE_NPAGE];
6125861346
if( iHash==0 ){
6125961347
pLoc->aPgno = &pLoc->aPgno[WALINDEX_HDR_SIZE/sizeof(u32)];
6126061348
pLoc->iZero = 0;
6126161349
}else{
6126261350
pLoc->iZero = HASHTABLE_NPAGE_ONE + (iHash-1)*HASHTABLE_NPAGE;
6126361351
}
61264
- pLoc->aPgno = &pLoc->aPgno[-1];
61352
+ }else if( NEVER(rc==SQLITE_OK) ){
61353
+ rc = SQLITE_ERROR;
6126561354
}
6126661355
return rc;
6126761356
}
6126861357
6126961358
/*
@@ -61341,25 +61430,26 @@
6134161430
}
6134261431
6134361432
/* Zero the entries in the aPgno array that correspond to frames with
6134461433
** frame numbers greater than pWal->hdr.mxFrame.
6134561434
*/
61346
- nByte = (int)((char *)sLoc.aHash - (char *)&sLoc.aPgno[iLimit+1]);
61347
- memset((void *)&sLoc.aPgno[iLimit+1], 0, nByte);
61435
+ nByte = (int)((char *)sLoc.aHash - (char *)&sLoc.aPgno[iLimit]);
61436
+ assert( nByte>=0 );
61437
+ memset((void *)&sLoc.aPgno[iLimit], 0, nByte);
6134861438
6134961439
#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
6135061440
/* Verify that the every entry in the mapping region is still reachable
6135161441
** via the hash table even after the cleanup.
6135261442
*/
6135361443
if( iLimit ){
6135461444
int j; /* Loop counter */
6135561445
int iKey; /* Hash key */
61356
- for(j=1; j<=iLimit; j++){
61446
+ for(j=0; j<iLimit; j++){
6135761447
for(iKey=walHash(sLoc.aPgno[j]);sLoc.aHash[iKey];iKey=walNextHash(iKey)){
61358
- if( sLoc.aHash[iKey]==j ) break;
61448
+ if( sLoc.aHash[iKey]==j+1 ) break;
6135961449
}
61360
- assert( sLoc.aHash[iKey]==j );
61450
+ assert( sLoc.aHash[iKey]==j+1 );
6136161451
}
6136261452
}
6136361453
#endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */
6136461454
}
6136561455
@@ -61387,32 +61477,32 @@
6138761477
6138861478
/* If this is the first entry to be added to this hash-table, zero the
6138961479
** entire hash table and aPgno[] array before proceeding.
6139061480
*/
6139161481
if( idx==1 ){
61392
- int nByte = (int)((u8 *)&sLoc.aHash[HASHTABLE_NSLOT]
61393
- - (u8 *)&sLoc.aPgno[1]);
61394
- memset((void*)&sLoc.aPgno[1], 0, nByte);
61482
+ int nByte = (int)((u8*)&sLoc.aHash[HASHTABLE_NSLOT] - (u8*)sLoc.aPgno);
61483
+ assert( nByte>=0 );
61484
+ memset((void*)sLoc.aPgno, 0, nByte);
6139561485
}
6139661486
6139761487
/* If the entry in aPgno[] is already set, then the previous writer
6139861488
** must have exited unexpectedly in the middle of a transaction (after
6139961489
** writing one or more dirty pages to the WAL to free up memory).
6140061490
** Remove the remnants of that writers uncommitted transaction from
6140161491
** the hash-table before writing any new entries.
6140261492
*/
61403
- if( sLoc.aPgno[idx] ){
61493
+ if( sLoc.aPgno[idx-1] ){
6140461494
walCleanupHash(pWal);
61405
- assert( !sLoc.aPgno[idx] );
61495
+ assert( !sLoc.aPgno[idx-1] );
6140661496
}
6140761497
6140861498
/* Write the aPgno[] array entry and the hash-table slot. */
6140961499
nCollide = idx;
6141061500
for(iKey=walHash(iPage); sLoc.aHash[iKey]; iKey=walNextHash(iKey)){
6141161501
if( (nCollide--)==0 ) return SQLITE_CORRUPT_BKPT;
6141261502
}
61413
- sLoc.aPgno[idx] = iPage;
61503
+ sLoc.aPgno[idx-1] = iPage;
6141461504
AtomicStore(&sLoc.aHash[iKey], (ht_slot)idx);
6141561505
6141661506
#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
6141761507
/* Verify that the number of entries in the hash table exactly equals
6141861508
** the number of entries in the mapping region.
@@ -61429,22 +61519,21 @@
6142961519
** thing to check, so only do this occasionally - not on every
6143061520
** iteration.
6143161521
*/
6143261522
if( (idx&0x3ff)==0 ){
6143361523
int i; /* Loop counter */
61434
- for(i=1; i<=idx; i++){
61524
+ for(i=0; i<idx; i++){
6143561525
for(iKey=walHash(sLoc.aPgno[i]);
6143661526
sLoc.aHash[iKey];
6143761527
iKey=walNextHash(iKey)){
61438
- if( sLoc.aHash[iKey]==i ) break;
61528
+ if( sLoc.aHash[iKey]==i+1 ) break;
6143961529
}
61440
- assert( sLoc.aHash[iKey]==i );
61530
+ assert( sLoc.aHash[iKey]==i+1 );
6144161531
}
6144261532
}
6144361533
#endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */
6144461534
}
61445
-
6144661535
6144761536
return rc;
6144861537
}
6144961538
6145061539
@@ -61562,11 +61651,12 @@
6156261651
u32 iFrame; /* Index of last frame read */
6156361652
u32 iLast = MIN(iLastFrame, HASHTABLE_NPAGE_ONE+iPg*HASHTABLE_NPAGE);
6156461653
u32 iFirst = 1 + (iPg==0?0:HASHTABLE_NPAGE_ONE+(iPg-1)*HASHTABLE_NPAGE);
6156561654
u32 nHdr, nHdr32;
6156661655
rc = walIndexPage(pWal, iPg, (volatile u32**)&aShare);
61567
- if( rc ) break;
61656
+ assert( aShare!=0 || rc!=SQLITE_OK );
61657
+ if( aShare==0 ) break;
6156861658
pWal->apWiData[iPg] = aPrivate;
6156961659
6157061660
for(iFrame=iFirst; iFrame<=iLast; iFrame++){
6157161661
i64 iOffset = walFrameOffset(iFrame, szPage);
6157261662
u32 pgno; /* Database page number for frame */
@@ -62059,11 +62149,10 @@
6205962149
if( rc==SQLITE_OK ){
6206062150
int j; /* Counter variable */
6206162151
int nEntry; /* Number of entries in this segment */
6206262152
ht_slot *aIndex; /* Sorted index for this segment */
6206362153
62064
- sLoc.aPgno++;
6206562154
if( (i+1)==nSegment ){
6206662155
nEntry = (int)(iLast - sLoc.iZero);
6206762156
}else{
6206862157
nEntry = (int)((u32*)sLoc.aHash - (u32*)sLoc.aPgno);
6206962158
}
@@ -63198,11 +63287,12 @@
6319863287
i64 iDbOff; /* Offset of db file entry */
6319963288
i64 iWalOff; /* Offset of wal file entry */
6320063289
6320163290
rc = walHashGet(pWal, walFramePage(i), &sLoc);
6320263291
if( rc!=SQLITE_OK ) break;
63203
- pgno = sLoc.aPgno[i-sLoc.iZero];
63292
+ assert( i - sLoc.iZero - 1 >=0 );
63293
+ pgno = sLoc.aPgno[i-sLoc.iZero-1];
6320463294
iDbOff = (i64)(pgno-1) * szPage;
6320563295
6320663296
if( iDbOff+szPage<=szDb ){
6320763297
iWalOff = walFrameOffset(i, szPage) + WAL_FRAME_HDRSIZE;
6320863298
rc = sqlite3OsRead(pWal->pWalFd, pBuf1, szPage, iWalOff);
@@ -63431,11 +63521,11 @@
6343163521
}
6343263522
nCollide = HASHTABLE_NSLOT;
6343363523
iKey = walHash(pgno);
6343463524
while( (iH = AtomicLoad(&sLoc.aHash[iKey]))!=0 ){
6343563525
u32 iFrame = iH + sLoc.iZero;
63436
- if( iFrame<=iLast && iFrame>=pWal->minFrame && sLoc.aPgno[iH]==pgno ){
63526
+ if( iFrame<=iLast && iFrame>=pWal->minFrame && sLoc.aPgno[iH-1]==pgno ){
6343763527
assert( iFrame>iRead || CORRUPT_DB );
6343863528
iRead = iFrame;
6343963529
}
6344063530
if( (nCollide--)==0 ){
6344163531
return SQLITE_CORRUPT_BKPT;
@@ -69375,27 +69465,30 @@
6937569465
}
6937669466
6937769467
/*
6937869468
** This routine is called prior to sqlite3PagerCommit when a transaction
6937969469
** is committed for an auto-vacuum database.
69380
-**
69381
-** If SQLITE_OK is returned, then *pnTrunc is set to the number of pages
69382
-** the database file should be truncated to during the commit process.
69383
-** i.e. the database has been reorganized so that only the first *pnTrunc
69384
-** pages are in use.
6938569470
*/
69386
-static int autoVacuumCommit(BtShared *pBt){
69471
+static int autoVacuumCommit(Btree *p){
6938769472
int rc = SQLITE_OK;
69388
- Pager *pPager = pBt->pPager;
69389
- VVA_ONLY( int nRef = sqlite3PagerRefcount(pPager); )
69473
+ Pager *pPager;
69474
+ BtShared *pBt;
69475
+ sqlite3 *db;
69476
+ VVA_ONLY( int nRef );
69477
+
69478
+ assert( p!=0 );
69479
+ pBt = p->pBt;
69480
+ pPager = pBt->pPager;
69481
+ VVA_ONLY( nRef = sqlite3PagerRefcount(pPager); )
6939069482
6939169483
assert( sqlite3_mutex_held(pBt->mutex) );
6939269484
invalidateAllOverflowCache(pBt);
6939369485
assert(pBt->autoVacuum);
6939469486
if( !pBt->incrVacuum ){
6939569487
Pgno nFin; /* Number of pages in database after autovacuuming */
6939669488
Pgno nFree; /* Number of pages on the freelist initially */
69489
+ Pgno nVac; /* Number of pages to vacuum */
6939769490
Pgno iFree; /* The next page to be freed */
6939869491
Pgno nOrig; /* Database size before freeing */
6939969492
6940069493
nOrig = btreePagecount(pBt);
6940169494
if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){
@@ -69405,22 +69498,46 @@
6940569498
*/
6940669499
return SQLITE_CORRUPT_BKPT;
6940769500
}
6940869501
6940969502
nFree = get4byte(&pBt->pPage1->aData[36]);
69410
- nFin = finalDbSize(pBt, nOrig, nFree);
69503
+ db = p->db;
69504
+ if( db->xAutovacPages ){
69505
+ int iDb;
69506
+ for(iDb=0; ALWAYS(iDb<db->nDb); iDb++){
69507
+ if( db->aDb[iDb].pBt==p ) break;
69508
+ }
69509
+ nVac = db->xAutovacPages(
69510
+ db->pAutovacPagesArg,
69511
+ db->aDb[iDb].zDbSName,
69512
+ nOrig,
69513
+ nFree,
69514
+ pBt->pageSize
69515
+ );
69516
+ if( nVac>nFree ){
69517
+ nVac = nFree;
69518
+ }
69519
+ if( nVac==0 ){
69520
+ return SQLITE_OK;
69521
+ }
69522
+ }else{
69523
+ nVac = nFree;
69524
+ }
69525
+ nFin = finalDbSize(pBt, nOrig, nVac);
6941169526
if( nFin>nOrig ) return SQLITE_CORRUPT_BKPT;
6941269527
if( nFin<nOrig ){
6941369528
rc = saveAllCursors(pBt, 0, 0);
6941469529
}
6941569530
for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){
69416
- rc = incrVacuumStep(pBt, nFin, iFree, 1);
69531
+ rc = incrVacuumStep(pBt, nFin, iFree, nVac==nFree);
6941769532
}
6941869533
if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
6941969534
rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
69420
- put4byte(&pBt->pPage1->aData[32], 0);
69421
- put4byte(&pBt->pPage1->aData[36], 0);
69535
+ if( nVac==nFree ){
69536
+ put4byte(&pBt->pPage1->aData[32], 0);
69537
+ put4byte(&pBt->pPage1->aData[36], 0);
69538
+ }
6942269539
put4byte(&pBt->pPage1->aData[28], nFin);
6942369540
pBt->bDoTruncate = 1;
6942469541
pBt->nPage = nFin;
6942569542
}
6942669543
if( rc!=SQLITE_OK ){
@@ -69467,11 +69584,11 @@
6946769584
if( p->inTrans==TRANS_WRITE ){
6946869585
BtShared *pBt = p->pBt;
6946969586
sqlite3BtreeEnter(p);
6947069587
#ifndef SQLITE_OMIT_AUTOVACUUM
6947169588
if( pBt->autoVacuum ){
69472
- rc = autoVacuumCommit(pBt);
69589
+ rc = autoVacuumCommit(p);
6947369590
if( rc!=SQLITE_OK ){
6947469591
sqlite3BtreeLeave(p);
6947569592
return rc;
6947669593
}
6947769594
}
@@ -77429,10 +77546,12 @@
7742977546
nByte = 1;
7743077547
}
7743177548
if( sqlite3VdbeMemGrow(pMem, nByte, 1) ){
7743277549
return SQLITE_NOMEM_BKPT;
7743377550
}
77551
+ assert( pMem->z!=0 );
77552
+ assert( sqlite3DbMallocSize(pMem->db,pMem->z) >= nByte );
7743477553
7743577554
memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
7743677555
pMem->n += pMem->u.nZero;
7743777556
pMem->flags &= ~(MEM_Zero|MEM_Term);
7743877557
return SQLITE_OK;
@@ -89396,20 +89515,25 @@
8939689515
rc = SQLITE_CORRUPT_BKPT;
8939789516
goto abort_due_to_error;
8939889517
}
8939989518
}
8940089519
89401
-/* Opcode: TypeCheck P1 P2 * P4 *
89520
+/* Opcode: TypeCheck P1 P2 P3 P4 *
8940289521
** Synopsis: typecheck(r[P1@P2])
8940389522
**
8940489523
** Apply affinities to the range of P2 registers beginning with P1.
8940589524
** Take the affinities from the Table object in P4. If any value
8940689525
** cannot be coerced into the correct type, then raise an error.
8940789526
**
8940889527
** This opcode is similar to OP_Affinity except that this opcode
8940989528
** forces the register type to the Table column type. This is used
8941089529
** to implement "strict affinity".
89530
+**
89531
+** GENERATED ALWAYS AS ... STATIC columns are only checked if P3
89532
+** is zero. When P3 is non-zero, no type checking occurs for
89533
+** static generated columns. Virtual columns are computed at query time
89534
+** and so they are never checked.
8941189535
**
8941289536
** Preconditions:
8941389537
**
8941489538
** <ul>
8941589539
** <li> P2 should be the number of non-virtual columns in the
@@ -89429,11 +89553,14 @@
8942989553
assert( pTab->tabFlags & TF_Strict );
8943089554
assert( pTab->nNVCol==pOp->p2 );
8943189555
aCol = pTab->aCol;
8943289556
pIn1 = &aMem[pOp->p1];
8943389557
for(i=0; i<pTab->nCol; i++){
89434
- if( aCol[i].colFlags & COLFLAG_VIRTUAL ) continue;
89558
+ if( aCol[i].colFlags & COLFLAG_GENERATED ){
89559
+ if( aCol[i].colFlags & COLFLAG_VIRTUAL ) continue;
89560
+ if( pOp->p3 ){ pIn1++; continue; }
89561
+ }
8943589562
assert( pIn1 < &aMem[pOp->p1+pOp->p2] );
8943689563
applyAffinity(pIn1, aCol[i].affinity, encoding);
8943789564
if( (pIn1->flags & MEM_Null)==0 ){
8943889565
switch( aCol[i].eCType ){
8943989566
case COLTYPE_BLOB: {
@@ -90153,10 +90280,11 @@
9015390280
assert( p->bIsReader );
9015490281
assert( p->readOnly==0 || pOp->p2==0 );
9015590282
assert( pOp->p2>=0 && pOp->p2<=2 );
9015690283
assert( pOp->p1>=0 && pOp->p1<db->nDb );
9015790284
assert( DbMaskTest(p->btreeMask, pOp->p1) );
90285
+ assert( rc==SQLITE_OK );
9015890286
if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
9015990287
rc = SQLITE_READONLY;
9016090288
goto abort_due_to_error;
9016190289
}
9016290290
pBt = db->aDb[pOp->p1].pBt;
@@ -90196,11 +90324,12 @@
9019690324
p->nStmtDefCons = db->nDeferredCons;
9019790325
p->nStmtDefImmCons = db->nDeferredImmCons;
9019890326
}
9019990327
}
9020090328
assert( pOp->p5==0 || pOp->p4type==P4_INT32 );
90201
- if( pOp->p5
90329
+ if( rc==SQLITE_OK
90330
+ && pOp->p5
9020290331
&& (iMeta!=pOp->p3
9020390332
|| db->aDb[pOp->p1].pSchema->iGeneration!=pOp->p4.i)
9020490333
){
9020590334
/*
9020690335
** IMPLEMENTATION-OF: R-03189-51135 As each SQL statement runs, the schema
@@ -97454,10 +97583,11 @@
9745497583
pTask->file2.iEof += pIncr->mxSz;
9745597584
}else{
9745697585
vdbeMergeEngineFree(pMerger);
9745797586
rc = SQLITE_NOMEM_BKPT;
9745897587
}
97588
+ assert( *ppOut!=0 || rc!=SQLITE_OK );
9745997589
return rc;
9746097590
}
9746197591
9746297592
#if SQLITE_MAX_WORKER_THREADS>0
9746397593
/*
@@ -103136,11 +103266,11 @@
103136103266
}
103137103267
103138103268
return pRet;
103139103269
}
103140103270
#else
103141
-SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
103271
+SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, const Select *p, int flags){
103142103272
assert( p==0 );
103143103273
return 0;
103144103274
}
103145103275
#endif
103146103276
@@ -108142,11 +108272,11 @@
108142108272
VdbeCoverage(v);
108143108273
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, 3);
108144108274
sqlite3ReleaseTempReg(pParse, r1);
108145108275
108146108276
/* Reload the table definition */
108147
- renameReloadSchema(pParse, iDb, INITFLAG_AlterRename);
108277
+ renameReloadSchema(pParse, iDb, INITFLAG_AlterAdd);
108148108278
108149108279
/* Verify that constraints are still satisfied */
108150108280
if( pNew->pCheck!=0
108151108281
|| (pCol->notNull && (pCol->colFlags & COLFLAG_GENERATED)!=0)
108152108282
){
@@ -109035,10 +109165,13 @@
109035109165
}else{
109036109166
p->pTab->nTabRef++;
109037109167
rc = sqlite3ViewGetColumnNames(pParse, p->pTab);
109038109168
}
109039109169
}
109170
+ }
109171
+ if( rc==SQLITE_OK && db->mallocFailed ){
109172
+ rc = SQLITE_NOMEM;
109040109173
}
109041109174
sNC.pSrcList = pSrc;
109042109175
if( rc==SQLITE_OK && pStep->pWhere ){
109043109176
rc = sqlite3ResolveExprNames(&sNC, pStep->pWhere);
109044109177
}
@@ -123938,28 +124071,34 @@
123938124071
123939124072
/* Before computing generated columns, first go through and make sure
123940124073
** that appropriate affinity has been applied to the regular columns
123941124074
*/
123942124075
sqlite3TableAffinity(pParse->pVdbe, pTab, iRegStore);
123943
- if( (pTab->tabFlags & TF_HasStored)!=0
123944
- && (pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1))->opcode==OP_Affinity
123945
- ){
123946
- /* Change the OP_Affinity argument to '@' (NONE) for all stored
123947
- ** columns. '@' is the no-op affinity and those columns have not
123948
- ** yet been computed. */
123949
- int ii, jj;
123950
- char *zP4 = pOp->p4.z;
123951
- assert( zP4!=0 );
123952
- assert( pOp->p4type==P4_DYNAMIC );
123953
- for(ii=jj=0; zP4[jj]; ii++){
123954
- if( pTab->aCol[ii].colFlags & COLFLAG_VIRTUAL ){
123955
- continue;
123956
- }
123957
- if( pTab->aCol[ii].colFlags & COLFLAG_STORED ){
123958
- zP4[jj] = SQLITE_AFF_NONE;
123959
- }
123960
- jj++;
124076
+ if( (pTab->tabFlags & TF_HasStored)!=0 ){
124077
+ pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1);
124078
+ if( pOp->opcode==OP_Affinity ){
124079
+ /* Change the OP_Affinity argument to '@' (NONE) for all stored
124080
+ ** columns. '@' is the no-op affinity and those columns have not
124081
+ ** yet been computed. */
124082
+ int ii, jj;
124083
+ char *zP4 = pOp->p4.z;
124084
+ assert( zP4!=0 );
124085
+ assert( pOp->p4type==P4_DYNAMIC );
124086
+ for(ii=jj=0; zP4[jj]; ii++){
124087
+ if( pTab->aCol[ii].colFlags & COLFLAG_VIRTUAL ){
124088
+ continue;
124089
+ }
124090
+ if( pTab->aCol[ii].colFlags & COLFLAG_STORED ){
124091
+ zP4[jj] = SQLITE_AFF_NONE;
124092
+ }
124093
+ jj++;
124094
+ }
124095
+ }else if( pOp->opcode==OP_TypeCheck ){
124096
+ /* If an OP_TypeCheck was generated because the table is STRICT,
124097
+ ** then set the P3 operand to indicate that generated columns should
124098
+ ** not be checked */
124099
+ pOp->p3 = 1;
123961124100
}
123962124101
}
123963124102
123964124103
/* Because there can be multiple generated columns that refer to one another,
123965124104
** this is a two-pass algorithm. On the first pass, mark all generated
@@ -125983,11 +126122,12 @@
125983126122
default: {
125984126123
int nConflictCk; /* Number of opcodes in conflict check logic */
125985126124
125986126125
assert( onError==OE_Replace );
125987126126
nConflictCk = sqlite3VdbeCurrentAddr(v) - addrConflictCk;
125988
- assert( nConflictCk>0 );
126127
+ assert( nConflictCk>0 || db->mallocFailed );
126128
+ testcase( nConflictCk<=0 );
125989126129
testcase( nConflictCk>1 );
125990126130
if( regTrigCnt ){
125991126131
sqlite3MultiWrite(pParse);
125992126132
nReplaceTrig++;
125993126133
}
@@ -126269,12 +126409,13 @@
126269126409
126270126410
assert( op==OP_OpenRead || op==OP_OpenWrite );
126271126411
assert( op==OP_OpenWrite || p5==0 );
126272126412
if( IsVirtual(pTab) ){
126273126413
/* This routine is a no-op for virtual tables. Leave the output
126274
- ** variables *piDataCur and *piIdxCur uninitialized so that valgrind
126275
- ** can detect if they are used by mistake in the caller. */
126414
+ ** variables *piDataCur and *piIdxCur set to illegal cursor numbers
126415
+ ** for improved error detection. */
126416
+ *piDataCur = *piIdxCur = -999;
126276126417
return 0;
126277126418
}
126278126419
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
126279126420
v = pParse->pVdbe;
126280126421
assert( v!=0 );
@@ -127281,10 +127422,14 @@
127281127422
/* Version 3.34.0 and later */
127282127423
int (*txn_state)(sqlite3*,const char*);
127283127424
/* Version 3.36.1 and later */
127284127425
sqlite3_int64 (*changes64)(sqlite3*);
127285127426
sqlite3_int64 (*total_changes64)(sqlite3*);
127427
+ /* Version 3.37.0 and later */
127428
+ int (*autovacuum_pages)(sqlite3*,
127429
+ unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
127430
+ void*, void(*)(void*));
127286127431
};
127287127432
127288127433
/*
127289127434
** This is the function signature used for all extension entry points. It
127290127435
** is also defined in the file "loadext.c".
@@ -127587,10 +127732,15 @@
127587127732
#define sqlite3_create_filename sqlite3_api->create_filename
127588127733
#define sqlite3_free_filename sqlite3_api->free_filename
127589127734
#define sqlite3_database_file_object sqlite3_api->database_file_object
127590127735
/* Version 3.34.0 and later */
127591127736
#define sqlite3_txn_state sqlite3_api->txn_state
127737
+/* Version 3.36.1 and later */
127738
+#define sqlite3_changes64 sqlite3_api->changes64
127739
+#define sqlite3_total_changes64 sqlite3_api->total_changes64
127740
+* Version 3.37.0 and later */
127741
+#define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
127592127742
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
127593127743
127594127744
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
127595127745
/* This case when the file really is being compiled as a loadable
127596127746
** extension */
@@ -128074,10 +128224,12 @@
128074128224
/* Version 3.34.0 and later */
128075128225
sqlite3_txn_state,
128076128226
/* Version 3.36.1 and later */
128077128227
sqlite3_changes64,
128078128228
sqlite3_total_changes64,
128229
+ /* Version 3.37.0 and later */
128230
+ sqlite3_autovacuum_pages,
128079128231
};
128080128232
128081128233
/* True if x is the directory separator character
128082128234
*/
128083128235
#if SQLITE_OS_WIN
@@ -130911,11 +131063,11 @@
130911131063
if( pCol->notNull ){
130912131064
jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
130913131065
zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
130914131066
pCol->zCnName);
130915131067
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
130916
- if( bStrict ){
131068
+ if( bStrict && pCol->eCType!=COLTYPE_ANY ){
130917131069
sqlite3VdbeGoto(v, doError);
130918131070
}else{
130919131071
integrityCheckResultRow(v);
130920131072
}
130921131073
sqlite3VdbeJumpHere(v, jmp2);
@@ -131872,14 +132024,19 @@
131872132024
sqlite3 *db = pData->db;
131873132025
if( db->mallocFailed ){
131874132026
pData->rc = SQLITE_NOMEM_BKPT;
131875132027
}else if( pData->pzErrMsg[0]!=0 ){
131876132028
/* A error message has already been generated. Do not overwrite it */
131877
- }else if( pData->mInitFlags & (INITFLAG_AlterRename|INITFLAG_AlterDrop) ){
132029
+ }else if( pData->mInitFlags & (INITFLAG_AlterMask) ){
132030
+ static const char *azAlterType[] = {
132031
+ "rename",
132032
+ "drop column",
132033
+ "add column"
132034
+ };
131878132035
*pData->pzErrMsg = sqlite3MPrintf(db,
131879132036
"error in %s %s after %s: %s", azObj[0], azObj[1],
131880
- (pData->mInitFlags & INITFLAG_AlterRename) ? "rename" : "drop column",
132037
+ azAlterType[(pData->mInitFlags&INITFLAG_AlterMask)-1],
131881132038
zExtra
131882132039
);
131883132040
pData->rc = SQLITE_ERROR;
131884132041
}else if( db->flags & SQLITE_WriteSchema ){
131885132042
pData->rc = SQLITE_CORRUPT_BKPT;
@@ -143906,11 +144063,13 @@
143906144063
rc = sqlite3BtreeBeginTrans(pMain, pOut==0 ? 2 : 0, 0);
143907144064
if( rc!=SQLITE_OK ) goto end_of_vacuum;
143908144065
143909144066
/* Do not attempt to change the page size for a WAL database */
143910144067
if( sqlite3PagerGetJournalMode(sqlite3BtreePager(pMain))
143911
- ==PAGER_JOURNALMODE_WAL ){
144068
+ ==PAGER_JOURNALMODE_WAL
144069
+ && pOut==0
144070
+ ){
143912144071
db->nextPagesize = 0;
143913144072
}
143914144073
143915144074
if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes, 0)
143916144075
|| (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
@@ -147905,12 +148064,23 @@
147905148064
147906148065
/* Load the value for the inequality constraint at the end of the
147907148066
** range (if any).
147908148067
*/
147909148068
nConstraint = nEq;
148069
+ assert( pLevel->p2==0 );
147910148070
if( pRangeEnd ){
147911148071
Expr *pRight = pRangeEnd->pExpr->pRight;
148072
+ if( addrSeekScan ){
148073
+ /* For a seek-scan that has a range on the lowest term of the index,
148074
+ ** we have to make the top of the loop be code that sets the end
148075
+ ** condition of the range. Otherwise, the OP_SeekScan might jump
148076
+ ** over that initialization, leaving the range-end value set to the
148077
+ ** range-start value, resulting in a wrong answer.
148078
+ ** See ticket 5981a8c041a3c2f3 (2021-11-02).
148079
+ */
148080
+ pLevel->p2 = sqlite3VdbeCurrentAddr(v);
148081
+ }
147912148082
codeExprOrVector(pParse, pRight, regBase+nEq, nTop);
147913148083
whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd);
147914148084
if( (pRangeEnd->wtFlags & TERM_VNULL)==0
147915148085
&& sqlite3ExprCanBeNull(pRight)
147916148086
){
@@ -147940,11 +148110,11 @@
147940148110
}
147941148111
sqlite3DbFree(db, zStartAff);
147942148112
sqlite3DbFree(db, zEndAff);
147943148113
147944148114
/* Top of the loop body */
147945
- pLevel->p2 = sqlite3VdbeCurrentAddr(v);
148115
+ if( pLevel->p2==0 ) pLevel->p2 = sqlite3VdbeCurrentAddr(v);
147946148116
147947148117
/* Check if the index cursor is past the end of the range. */
147948148118
if( nConstraint ){
147949148119
if( regBignull ){
147950148120
/* Except, skip the end-of-range check while doing the NULL-scan */
@@ -167564,10 +167734,13 @@
167564167734
** So it needs to be freed here. Todo: Why not roll the temp schema into
167565167735
** the same sqliteMalloc() as the one that allocates the database
167566167736
** structure?
167567167737
*/
167568167738
sqlite3DbFree(db, db->aDb[1].pSchema);
167739
+ if( db->xAutovacDestr ){
167740
+ db->xAutovacDestr(db->pAutovacPagesArg);
167741
+ }
167569167742
sqlite3_mutex_leave(db->mutex);
167570167743
db->eOpenState = SQLITE_STATE_CLOSED;
167571167744
sqlite3_mutex_free(db->mutex);
167572167745
assert( sqlite3LookasideUsed(db,0)==0 );
167573167746
if( db->lookaside.bMalloced ){
@@ -168464,10 +168637,38 @@
168464168637
db->pPreUpdateArg = pArg;
168465168638
sqlite3_mutex_leave(db->mutex);
168466168639
return pRet;
168467168640
}
168468168641
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
168642
+
168643
+/*
168644
+** Register a function to be invoked prior to each autovacuum that
168645
+** determines the number of pages to vacuum.
168646
+*/
168647
+SQLITE_API int sqlite3_autovacuum_pages(
168648
+ sqlite3 *db, /* Attach the hook to this database */
168649
+ unsigned int (*xCallback)(void*,const char*,u32,u32,u32),
168650
+ void *pArg, /* Argument to the function */
168651
+ void (*xDestructor)(void*) /* Destructor for pArg */
168652
+){
168653
+#ifdef SQLITE_ENABLE_API_ARMOR
168654
+ if( !sqlite3SafetyCheckOk(db) ){
168655
+ if( xDestructor ) xDestructor(pArg);
168656
+ return SQLITE_MISUSE_BKPT;
168657
+ }
168658
+#endif
168659
+ sqlite3_mutex_enter(db->mutex);
168660
+ if( db->xAutovacDestr ){
168661
+ db->xAutovacDestr(db->pAutovacPagesArg);
168662
+ }
168663
+ db->xAutovacPages = xCallback;
168664
+ db->pAutovacPagesArg = pArg;
168665
+ db->xAutovacDestr = xDestructor;
168666
+ sqlite3_mutex_leave(db->mutex);
168667
+ return SQLITE_OK;
168668
+}
168669
+
168469168670
168470168671
#ifndef SQLITE_OMIT_WAL
168471168672
/*
168472168673
** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint().
168473168674
** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
@@ -190861,11 +191062,11 @@
190861191062
# define ALWAYS(X) (X)
190862191063
# define NEVER(X) (X)
190863191064
# endif
190864191065
# define testcase(X)
190865191066
#endif
190866
-#if defined(NDEBUG)
191067
+#if !defined(SQLITE_DEBUG) && !defined(SQLITE_COVERAGE_TEST)
190867191068
# define VVA(X)
190868191069
#else
190869191070
# define VVA(X) X
190870191071
#endif
190871191072
@@ -221613,20 +221814,29 @@
221613221814
Fts5PoslistWriter writer;
221614221815
int bOk; /* True if ok to populate */
221615221816
int bMiss;
221616221817
};
221617221818
221819
+/*
221820
+** Clear the position lists associated with all phrases in the expression
221821
+** passed as the first argument. Argument bLive is true if the expression
221822
+** might be pointing to a real entry, otherwise it has just been reset.
221823
+**
221824
+** At present this function is only used for detail=col and detail=none
221825
+** fts5 tables. This implies that all phrases must be at most 1 token
221826
+** in size, as phrase matches are not supported without detail=full.
221827
+*/
221618221828
static Fts5PoslistPopulator *sqlite3Fts5ExprClearPoslists(Fts5Expr *pExpr, int bLive){
221619221829
Fts5PoslistPopulator *pRet;
221620221830
pRet = sqlite3_malloc64(sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
221621221831
if( pRet ){
221622221832
int i;
221623221833
memset(pRet, 0, sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
221624221834
for(i=0; i<pExpr->nPhrase; i++){
221625221835
Fts5Buffer *pBuf = &pExpr->apExprPhrase[i]->poslist;
221626221836
Fts5ExprNode *pNode = pExpr->apExprPhrase[i]->pNode;
221627
- assert( pExpr->apExprPhrase[i]->nTerm==1 );
221837
+ assert( pExpr->apExprPhrase[i]->nTerm<=1 );
221628221838
if( bLive &&
221629221839
(pBuf->n==0 || pNode->iRowid!=pExpr->pRoot->iRowid || pNode->bEof)
221630221840
){
221631221841
pRet[i].bMiss = 1;
221632221842
}else{
@@ -231987,11 +232197,11 @@
231987232197
int nArg, /* Number of args */
231988232198
sqlite3_value **apUnused /* Function arguments */
231989232199
){
231990232200
assert( nArg==0 );
231991232201
UNUSED_PARAM2(nArg, apUnused);
231992
- sqlite3_result_text(pCtx, "fts5: 2021-10-26 09:53:51 4b41535b096dec4b15a85e657102a72d4288728da6103f3fdcbe0e6f244c673a", -1, SQLITE_TRANSIENT);
232202
+ sqlite3_result_text(pCtx, "fts5: 2021-11-02 17:55:01 1d9004cd015073853ce0ca811a68ea5411733eedee993b97a38a42ba139d7590", -1, SQLITE_TRANSIENT);
231993232203
}
231994232204
231995232205
/*
231996232206
** Return true if zName is the extension on one of the shadow tables used
231997232207
** by this module.
231998232208
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.37.0"
456 #define SQLITE_VERSION_NUMBER 3037000
457 #define SQLITE_SOURCE_ID "2021-10-26 09:53:51 4b41535b096dec4b15a85e657102a72d4288728da6103f3fdcbe0e6f244c673a"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -6709,10 +6709,76 @@
6709 **
6710 ** See also the [sqlite3_update_hook()] interface.
6711 */
6712 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
6713 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6714
6715 /*
6716 ** CAPI3REF: Data Change Notification Callbacks
6717 ** METHOD: sqlite3
6718 **
@@ -16437,10 +16503,13 @@
16437 int (*xCommitCallback)(void*); /* Invoked at every commit. */
16438 void *pRollbackArg; /* Argument to xRollbackCallback() */
16439 void (*xRollbackCallback)(void*); /* Invoked at every commit. */
16440 void *pUpdateArg;
16441 void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
 
 
 
16442 Parse *pParse; /* Current parse */
16443 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
16444 void *pPreUpdateArg; /* First argument to xPreUpdateCallback */
16445 void (*xPreUpdateCallback)( /* Registered using sqlite3_preupdate_hook() */
16446 void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64
@@ -18694,12 +18763,14 @@
18694 } InitData;
18695
18696 /*
18697 ** Allowed values for mInitFlags
18698 */
 
18699 #define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */
18700 #define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */
 
18701
18702 /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled
18703 ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning
18704 ** parameters are for temporary use during development, to help find
18705 ** optimial values for parameters in the query planner. The should not
@@ -24126,16 +24197,19 @@
24126 pFile = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile);
24127 if( pFile ){
24128 rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, pOutFlags);
24129 if( rc!=SQLITE_OK ){
24130 sqlite3_free(pFile);
 
24131 }else{
24132 *ppFile = pFile;
24133 }
24134 }else{
 
24135 rc = SQLITE_NOMEM_BKPT;
24136 }
 
24137 return rc;
24138 }
24139 SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *pFile){
24140 assert( pFile );
24141 sqlite3OsClose(pFile);
@@ -38079,11 +38153,13 @@
38079 }
38080 }
38081
38082 /* Forward declaration */
38083 static int unixGetTempname(int nBuf, char *zBuf);
38084 static int unixFcntlExternalReader(unixFile*, int*);
 
 
38085
38086 /*
38087 ** Information and control of an open file handle.
38088 */
38089 static int unixFileControl(sqlite3_file *id, int op, void *pArg){
@@ -38198,11 +38274,16 @@
38198 return proxyFileControl(id,op,pArg);
38199 }
38200 #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
38201
38202 case SQLITE_FCNTL_EXTERNAL_READER: {
 
38203 return unixFcntlExternalReader((unixFile*)id, (int*)pArg);
 
 
 
 
38204 }
38205 }
38206 return SQLITE_NOTFOUND;
38207 }
38208
@@ -48902,10 +48983,11 @@
48902 int *pOutFlags
48903 ){
48904 MemFile *pFile = (MemFile*)pFd;
48905 MemStore *p = 0;
48906 int szName;
 
48907
48908 memset(pFile, 0, sizeof(*pFile));
48909 szName = sqlite3Strlen30(zName);
48910 if( szName>1 && zName[0]=='/' ){
48911 int i;
@@ -60864,13 +60946,17 @@
60864 ** If the wal-index is currently smaller the iPage pages then the size
60865 ** of the wal-index might be increased, but only if it is safe to do
60866 ** so. It is safe to enlarge the wal-index if pWal->writeLock is true
60867 ** or pWal->exclusiveMode==WAL_HEAPMEMORY_MODE.
60868 **
60869 ** If this call is successful, *ppPage is set to point to the wal-index
60870 ** page and SQLITE_OK is returned. If an error (an OOM or VFS error) occurs,
60871 ** then an SQLite error code is returned and *ppPage is set to 0.
 
 
 
 
60872 */
60873 static SQLITE_NOINLINE int walIndexPageRealloc(
60874 Wal *pWal, /* The WAL context */
60875 int iPage, /* The page we seek */
60876 volatile u32 **ppPage /* Write the page pointer here */
@@ -60899,11 +60985,13 @@
60899 if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM_BKPT;
60900 }else{
60901 rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ,
60902 pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
60903 );
60904 assert( pWal->apWiData[iPage]!=0 || rc!=SQLITE_OK || pWal->writeLock==0 );
 
 
60905 testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK );
60906 if( rc==SQLITE_OK ){
60907 if( iPage>0 && sqlite3FaultSim(600) ) rc = SQLITE_NOMEM;
60908 }else if( (rc&0xff)==SQLITE_READONLY ){
60909 pWal->readOnly |= WAL_SHM_RDONLY;
@@ -61238,12 +61326,12 @@
61238 ** in the wal-index file. Set pLoc->iZero to one less than the frame
61239 ** number of the first frame indexed by this hash table. If a
61240 ** slot in the hash table is set to N, it refers to frame number
61241 ** (pLoc->iZero+N) in the log.
61242 **
61243 ** Finally, set pLoc->aPgno so that pLoc->aPgno[1] is the page number of the
61244 ** first frame indexed by the hash table, frame (pLoc->iZero+1).
61245 */
61246 static int walHashGet(
61247 Wal *pWal, /* WAL handle */
61248 int iHash, /* Find the iHash'th table */
61249 WalHashLoc *pLoc /* OUT: Hash table location */
@@ -61251,19 +61339,20 @@
61251 int rc; /* Return code */
61252
61253 rc = walIndexPage(pWal, iHash, &pLoc->aPgno);
61254 assert( rc==SQLITE_OK || iHash>0 );
61255
61256 if( rc==SQLITE_OK ){
61257 pLoc->aHash = (volatile ht_slot *)&pLoc->aPgno[HASHTABLE_NPAGE];
61258 if( iHash==0 ){
61259 pLoc->aPgno = &pLoc->aPgno[WALINDEX_HDR_SIZE/sizeof(u32)];
61260 pLoc->iZero = 0;
61261 }else{
61262 pLoc->iZero = HASHTABLE_NPAGE_ONE + (iHash-1)*HASHTABLE_NPAGE;
61263 }
61264 pLoc->aPgno = &pLoc->aPgno[-1];
 
61265 }
61266 return rc;
61267 }
61268
61269 /*
@@ -61341,25 +61430,26 @@
61341 }
61342
61343 /* Zero the entries in the aPgno array that correspond to frames with
61344 ** frame numbers greater than pWal->hdr.mxFrame.
61345 */
61346 nByte = (int)((char *)sLoc.aHash - (char *)&sLoc.aPgno[iLimit+1]);
61347 memset((void *)&sLoc.aPgno[iLimit+1], 0, nByte);
 
61348
61349 #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
61350 /* Verify that the every entry in the mapping region is still reachable
61351 ** via the hash table even after the cleanup.
61352 */
61353 if( iLimit ){
61354 int j; /* Loop counter */
61355 int iKey; /* Hash key */
61356 for(j=1; j<=iLimit; j++){
61357 for(iKey=walHash(sLoc.aPgno[j]);sLoc.aHash[iKey];iKey=walNextHash(iKey)){
61358 if( sLoc.aHash[iKey]==j ) break;
61359 }
61360 assert( sLoc.aHash[iKey]==j );
61361 }
61362 }
61363 #endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */
61364 }
61365
@@ -61387,32 +61477,32 @@
61387
61388 /* If this is the first entry to be added to this hash-table, zero the
61389 ** entire hash table and aPgno[] array before proceeding.
61390 */
61391 if( idx==1 ){
61392 int nByte = (int)((u8 *)&sLoc.aHash[HASHTABLE_NSLOT]
61393 - (u8 *)&sLoc.aPgno[1]);
61394 memset((void*)&sLoc.aPgno[1], 0, nByte);
61395 }
61396
61397 /* If the entry in aPgno[] is already set, then the previous writer
61398 ** must have exited unexpectedly in the middle of a transaction (after
61399 ** writing one or more dirty pages to the WAL to free up memory).
61400 ** Remove the remnants of that writers uncommitted transaction from
61401 ** the hash-table before writing any new entries.
61402 */
61403 if( sLoc.aPgno[idx] ){
61404 walCleanupHash(pWal);
61405 assert( !sLoc.aPgno[idx] );
61406 }
61407
61408 /* Write the aPgno[] array entry and the hash-table slot. */
61409 nCollide = idx;
61410 for(iKey=walHash(iPage); sLoc.aHash[iKey]; iKey=walNextHash(iKey)){
61411 if( (nCollide--)==0 ) return SQLITE_CORRUPT_BKPT;
61412 }
61413 sLoc.aPgno[idx] = iPage;
61414 AtomicStore(&sLoc.aHash[iKey], (ht_slot)idx);
61415
61416 #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
61417 /* Verify that the number of entries in the hash table exactly equals
61418 ** the number of entries in the mapping region.
@@ -61429,22 +61519,21 @@
61429 ** thing to check, so only do this occasionally - not on every
61430 ** iteration.
61431 */
61432 if( (idx&0x3ff)==0 ){
61433 int i; /* Loop counter */
61434 for(i=1; i<=idx; i++){
61435 for(iKey=walHash(sLoc.aPgno[i]);
61436 sLoc.aHash[iKey];
61437 iKey=walNextHash(iKey)){
61438 if( sLoc.aHash[iKey]==i ) break;
61439 }
61440 assert( sLoc.aHash[iKey]==i );
61441 }
61442 }
61443 #endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */
61444 }
61445
61446
61447 return rc;
61448 }
61449
61450
@@ -61562,11 +61651,12 @@
61562 u32 iFrame; /* Index of last frame read */
61563 u32 iLast = MIN(iLastFrame, HASHTABLE_NPAGE_ONE+iPg*HASHTABLE_NPAGE);
61564 u32 iFirst = 1 + (iPg==0?0:HASHTABLE_NPAGE_ONE+(iPg-1)*HASHTABLE_NPAGE);
61565 u32 nHdr, nHdr32;
61566 rc = walIndexPage(pWal, iPg, (volatile u32**)&aShare);
61567 if( rc ) break;
 
61568 pWal->apWiData[iPg] = aPrivate;
61569
61570 for(iFrame=iFirst; iFrame<=iLast; iFrame++){
61571 i64 iOffset = walFrameOffset(iFrame, szPage);
61572 u32 pgno; /* Database page number for frame */
@@ -62059,11 +62149,10 @@
62059 if( rc==SQLITE_OK ){
62060 int j; /* Counter variable */
62061 int nEntry; /* Number of entries in this segment */
62062 ht_slot *aIndex; /* Sorted index for this segment */
62063
62064 sLoc.aPgno++;
62065 if( (i+1)==nSegment ){
62066 nEntry = (int)(iLast - sLoc.iZero);
62067 }else{
62068 nEntry = (int)((u32*)sLoc.aHash - (u32*)sLoc.aPgno);
62069 }
@@ -63198,11 +63287,12 @@
63198 i64 iDbOff; /* Offset of db file entry */
63199 i64 iWalOff; /* Offset of wal file entry */
63200
63201 rc = walHashGet(pWal, walFramePage(i), &sLoc);
63202 if( rc!=SQLITE_OK ) break;
63203 pgno = sLoc.aPgno[i-sLoc.iZero];
 
63204 iDbOff = (i64)(pgno-1) * szPage;
63205
63206 if( iDbOff+szPage<=szDb ){
63207 iWalOff = walFrameOffset(i, szPage) + WAL_FRAME_HDRSIZE;
63208 rc = sqlite3OsRead(pWal->pWalFd, pBuf1, szPage, iWalOff);
@@ -63431,11 +63521,11 @@
63431 }
63432 nCollide = HASHTABLE_NSLOT;
63433 iKey = walHash(pgno);
63434 while( (iH = AtomicLoad(&sLoc.aHash[iKey]))!=0 ){
63435 u32 iFrame = iH + sLoc.iZero;
63436 if( iFrame<=iLast && iFrame>=pWal->minFrame && sLoc.aPgno[iH]==pgno ){
63437 assert( iFrame>iRead || CORRUPT_DB );
63438 iRead = iFrame;
63439 }
63440 if( (nCollide--)==0 ){
63441 return SQLITE_CORRUPT_BKPT;
@@ -69375,27 +69465,30 @@
69375 }
69376
69377 /*
69378 ** This routine is called prior to sqlite3PagerCommit when a transaction
69379 ** is committed for an auto-vacuum database.
69380 **
69381 ** If SQLITE_OK is returned, then *pnTrunc is set to the number of pages
69382 ** the database file should be truncated to during the commit process.
69383 ** i.e. the database has been reorganized so that only the first *pnTrunc
69384 ** pages are in use.
69385 */
69386 static int autoVacuumCommit(BtShared *pBt){
69387 int rc = SQLITE_OK;
69388 Pager *pPager = pBt->pPager;
69389 VVA_ONLY( int nRef = sqlite3PagerRefcount(pPager); )
 
 
 
 
 
 
 
69390
69391 assert( sqlite3_mutex_held(pBt->mutex) );
69392 invalidateAllOverflowCache(pBt);
69393 assert(pBt->autoVacuum);
69394 if( !pBt->incrVacuum ){
69395 Pgno nFin; /* Number of pages in database after autovacuuming */
69396 Pgno nFree; /* Number of pages on the freelist initially */
 
69397 Pgno iFree; /* The next page to be freed */
69398 Pgno nOrig; /* Database size before freeing */
69399
69400 nOrig = btreePagecount(pBt);
69401 if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){
@@ -69405,22 +69498,46 @@
69405 */
69406 return SQLITE_CORRUPT_BKPT;
69407 }
69408
69409 nFree = get4byte(&pBt->pPage1->aData[36]);
69410 nFin = finalDbSize(pBt, nOrig, nFree);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69411 if( nFin>nOrig ) return SQLITE_CORRUPT_BKPT;
69412 if( nFin<nOrig ){
69413 rc = saveAllCursors(pBt, 0, 0);
69414 }
69415 for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){
69416 rc = incrVacuumStep(pBt, nFin, iFree, 1);
69417 }
69418 if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
69419 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
69420 put4byte(&pBt->pPage1->aData[32], 0);
69421 put4byte(&pBt->pPage1->aData[36], 0);
 
 
69422 put4byte(&pBt->pPage1->aData[28], nFin);
69423 pBt->bDoTruncate = 1;
69424 pBt->nPage = nFin;
69425 }
69426 if( rc!=SQLITE_OK ){
@@ -69467,11 +69584,11 @@
69467 if( p->inTrans==TRANS_WRITE ){
69468 BtShared *pBt = p->pBt;
69469 sqlite3BtreeEnter(p);
69470 #ifndef SQLITE_OMIT_AUTOVACUUM
69471 if( pBt->autoVacuum ){
69472 rc = autoVacuumCommit(pBt);
69473 if( rc!=SQLITE_OK ){
69474 sqlite3BtreeLeave(p);
69475 return rc;
69476 }
69477 }
@@ -77429,10 +77546,12 @@
77429 nByte = 1;
77430 }
77431 if( sqlite3VdbeMemGrow(pMem, nByte, 1) ){
77432 return SQLITE_NOMEM_BKPT;
77433 }
 
 
77434
77435 memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
77436 pMem->n += pMem->u.nZero;
77437 pMem->flags &= ~(MEM_Zero|MEM_Term);
77438 return SQLITE_OK;
@@ -89396,20 +89515,25 @@
89396 rc = SQLITE_CORRUPT_BKPT;
89397 goto abort_due_to_error;
89398 }
89399 }
89400
89401 /* Opcode: TypeCheck P1 P2 * P4 *
89402 ** Synopsis: typecheck(r[P1@P2])
89403 **
89404 ** Apply affinities to the range of P2 registers beginning with P1.
89405 ** Take the affinities from the Table object in P4. If any value
89406 ** cannot be coerced into the correct type, then raise an error.
89407 **
89408 ** This opcode is similar to OP_Affinity except that this opcode
89409 ** forces the register type to the Table column type. This is used
89410 ** to implement "strict affinity".
 
 
 
 
 
89411 **
89412 ** Preconditions:
89413 **
89414 ** <ul>
89415 ** <li> P2 should be the number of non-virtual columns in the
@@ -89429,11 +89553,14 @@
89429 assert( pTab->tabFlags & TF_Strict );
89430 assert( pTab->nNVCol==pOp->p2 );
89431 aCol = pTab->aCol;
89432 pIn1 = &aMem[pOp->p1];
89433 for(i=0; i<pTab->nCol; i++){
89434 if( aCol[i].colFlags & COLFLAG_VIRTUAL ) continue;
 
 
 
89435 assert( pIn1 < &aMem[pOp->p1+pOp->p2] );
89436 applyAffinity(pIn1, aCol[i].affinity, encoding);
89437 if( (pIn1->flags & MEM_Null)==0 ){
89438 switch( aCol[i].eCType ){
89439 case COLTYPE_BLOB: {
@@ -90153,10 +90280,11 @@
90153 assert( p->bIsReader );
90154 assert( p->readOnly==0 || pOp->p2==0 );
90155 assert( pOp->p2>=0 && pOp->p2<=2 );
90156 assert( pOp->p1>=0 && pOp->p1<db->nDb );
90157 assert( DbMaskTest(p->btreeMask, pOp->p1) );
 
90158 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
90159 rc = SQLITE_READONLY;
90160 goto abort_due_to_error;
90161 }
90162 pBt = db->aDb[pOp->p1].pBt;
@@ -90196,11 +90324,12 @@
90196 p->nStmtDefCons = db->nDeferredCons;
90197 p->nStmtDefImmCons = db->nDeferredImmCons;
90198 }
90199 }
90200 assert( pOp->p5==0 || pOp->p4type==P4_INT32 );
90201 if( pOp->p5
 
90202 && (iMeta!=pOp->p3
90203 || db->aDb[pOp->p1].pSchema->iGeneration!=pOp->p4.i)
90204 ){
90205 /*
90206 ** IMPLEMENTATION-OF: R-03189-51135 As each SQL statement runs, the schema
@@ -97454,10 +97583,11 @@
97454 pTask->file2.iEof += pIncr->mxSz;
97455 }else{
97456 vdbeMergeEngineFree(pMerger);
97457 rc = SQLITE_NOMEM_BKPT;
97458 }
 
97459 return rc;
97460 }
97461
97462 #if SQLITE_MAX_WORKER_THREADS>0
97463 /*
@@ -103136,11 +103266,11 @@
103136 }
103137
103138 return pRet;
103139 }
103140 #else
103141 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
103142 assert( p==0 );
103143 return 0;
103144 }
103145 #endif
103146
@@ -108142,11 +108272,11 @@
108142 VdbeCoverage(v);
108143 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, 3);
108144 sqlite3ReleaseTempReg(pParse, r1);
108145
108146 /* Reload the table definition */
108147 renameReloadSchema(pParse, iDb, INITFLAG_AlterRename);
108148
108149 /* Verify that constraints are still satisfied */
108150 if( pNew->pCheck!=0
108151 || (pCol->notNull && (pCol->colFlags & COLFLAG_GENERATED)!=0)
108152 ){
@@ -109035,10 +109165,13 @@
109035 }else{
109036 p->pTab->nTabRef++;
109037 rc = sqlite3ViewGetColumnNames(pParse, p->pTab);
109038 }
109039 }
 
 
 
109040 }
109041 sNC.pSrcList = pSrc;
109042 if( rc==SQLITE_OK && pStep->pWhere ){
109043 rc = sqlite3ResolveExprNames(&sNC, pStep->pWhere);
109044 }
@@ -123938,28 +124071,34 @@
123938
123939 /* Before computing generated columns, first go through and make sure
123940 ** that appropriate affinity has been applied to the regular columns
123941 */
123942 sqlite3TableAffinity(pParse->pVdbe, pTab, iRegStore);
123943 if( (pTab->tabFlags & TF_HasStored)!=0
123944 && (pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1))->opcode==OP_Affinity
123945 ){
123946 /* Change the OP_Affinity argument to '@' (NONE) for all stored
123947 ** columns. '@' is the no-op affinity and those columns have not
123948 ** yet been computed. */
123949 int ii, jj;
123950 char *zP4 = pOp->p4.z;
123951 assert( zP4!=0 );
123952 assert( pOp->p4type==P4_DYNAMIC );
123953 for(ii=jj=0; zP4[jj]; ii++){
123954 if( pTab->aCol[ii].colFlags & COLFLAG_VIRTUAL ){
123955 continue;
123956 }
123957 if( pTab->aCol[ii].colFlags & COLFLAG_STORED ){
123958 zP4[jj] = SQLITE_AFF_NONE;
123959 }
123960 jj++;
 
 
 
 
 
 
123961 }
123962 }
123963
123964 /* Because there can be multiple generated columns that refer to one another,
123965 ** this is a two-pass algorithm. On the first pass, mark all generated
@@ -125983,11 +126122,12 @@
125983 default: {
125984 int nConflictCk; /* Number of opcodes in conflict check logic */
125985
125986 assert( onError==OE_Replace );
125987 nConflictCk = sqlite3VdbeCurrentAddr(v) - addrConflictCk;
125988 assert( nConflictCk>0 );
 
125989 testcase( nConflictCk>1 );
125990 if( regTrigCnt ){
125991 sqlite3MultiWrite(pParse);
125992 nReplaceTrig++;
125993 }
@@ -126269,12 +126409,13 @@
126269
126270 assert( op==OP_OpenRead || op==OP_OpenWrite );
126271 assert( op==OP_OpenWrite || p5==0 );
126272 if( IsVirtual(pTab) ){
126273 /* This routine is a no-op for virtual tables. Leave the output
126274 ** variables *piDataCur and *piIdxCur uninitialized so that valgrind
126275 ** can detect if they are used by mistake in the caller. */
 
126276 return 0;
126277 }
126278 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
126279 v = pParse->pVdbe;
126280 assert( v!=0 );
@@ -127281,10 +127422,14 @@
127281 /* Version 3.34.0 and later */
127282 int (*txn_state)(sqlite3*,const char*);
127283 /* Version 3.36.1 and later */
127284 sqlite3_int64 (*changes64)(sqlite3*);
127285 sqlite3_int64 (*total_changes64)(sqlite3*);
 
 
 
 
127286 };
127287
127288 /*
127289 ** This is the function signature used for all extension entry points. It
127290 ** is also defined in the file "loadext.c".
@@ -127587,10 +127732,15 @@
127587 #define sqlite3_create_filename sqlite3_api->create_filename
127588 #define sqlite3_free_filename sqlite3_api->free_filename
127589 #define sqlite3_database_file_object sqlite3_api->database_file_object
127590 /* Version 3.34.0 and later */
127591 #define sqlite3_txn_state sqlite3_api->txn_state
 
 
 
 
 
127592 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
127593
127594 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
127595 /* This case when the file really is being compiled as a loadable
127596 ** extension */
@@ -128074,10 +128224,12 @@
128074 /* Version 3.34.0 and later */
128075 sqlite3_txn_state,
128076 /* Version 3.36.1 and later */
128077 sqlite3_changes64,
128078 sqlite3_total_changes64,
 
 
128079 };
128080
128081 /* True if x is the directory separator character
128082 */
128083 #if SQLITE_OS_WIN
@@ -130911,11 +131063,11 @@
130911 if( pCol->notNull ){
130912 jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
130913 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
130914 pCol->zCnName);
130915 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
130916 if( bStrict ){
130917 sqlite3VdbeGoto(v, doError);
130918 }else{
130919 integrityCheckResultRow(v);
130920 }
130921 sqlite3VdbeJumpHere(v, jmp2);
@@ -131872,14 +132024,19 @@
131872 sqlite3 *db = pData->db;
131873 if( db->mallocFailed ){
131874 pData->rc = SQLITE_NOMEM_BKPT;
131875 }else if( pData->pzErrMsg[0]!=0 ){
131876 /* A error message has already been generated. Do not overwrite it */
131877 }else if( pData->mInitFlags & (INITFLAG_AlterRename|INITFLAG_AlterDrop) ){
 
 
 
 
 
131878 *pData->pzErrMsg = sqlite3MPrintf(db,
131879 "error in %s %s after %s: %s", azObj[0], azObj[1],
131880 (pData->mInitFlags & INITFLAG_AlterRename) ? "rename" : "drop column",
131881 zExtra
131882 );
131883 pData->rc = SQLITE_ERROR;
131884 }else if( db->flags & SQLITE_WriteSchema ){
131885 pData->rc = SQLITE_CORRUPT_BKPT;
@@ -143906,11 +144063,13 @@
143906 rc = sqlite3BtreeBeginTrans(pMain, pOut==0 ? 2 : 0, 0);
143907 if( rc!=SQLITE_OK ) goto end_of_vacuum;
143908
143909 /* Do not attempt to change the page size for a WAL database */
143910 if( sqlite3PagerGetJournalMode(sqlite3BtreePager(pMain))
143911 ==PAGER_JOURNALMODE_WAL ){
 
 
143912 db->nextPagesize = 0;
143913 }
143914
143915 if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes, 0)
143916 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
@@ -147905,12 +148064,23 @@
147905
147906 /* Load the value for the inequality constraint at the end of the
147907 ** range (if any).
147908 */
147909 nConstraint = nEq;
 
147910 if( pRangeEnd ){
147911 Expr *pRight = pRangeEnd->pExpr->pRight;
 
 
 
 
 
 
 
 
 
 
147912 codeExprOrVector(pParse, pRight, regBase+nEq, nTop);
147913 whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd);
147914 if( (pRangeEnd->wtFlags & TERM_VNULL)==0
147915 && sqlite3ExprCanBeNull(pRight)
147916 ){
@@ -147940,11 +148110,11 @@
147940 }
147941 sqlite3DbFree(db, zStartAff);
147942 sqlite3DbFree(db, zEndAff);
147943
147944 /* Top of the loop body */
147945 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
147946
147947 /* Check if the index cursor is past the end of the range. */
147948 if( nConstraint ){
147949 if( regBignull ){
147950 /* Except, skip the end-of-range check while doing the NULL-scan */
@@ -167564,10 +167734,13 @@
167564 ** So it needs to be freed here. Todo: Why not roll the temp schema into
167565 ** the same sqliteMalloc() as the one that allocates the database
167566 ** structure?
167567 */
167568 sqlite3DbFree(db, db->aDb[1].pSchema);
 
 
 
167569 sqlite3_mutex_leave(db->mutex);
167570 db->eOpenState = SQLITE_STATE_CLOSED;
167571 sqlite3_mutex_free(db->mutex);
167572 assert( sqlite3LookasideUsed(db,0)==0 );
167573 if( db->lookaside.bMalloced ){
@@ -168464,10 +168637,38 @@
168464 db->pPreUpdateArg = pArg;
168465 sqlite3_mutex_leave(db->mutex);
168466 return pRet;
168467 }
168468 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168469
168470 #ifndef SQLITE_OMIT_WAL
168471 /*
168472 ** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint().
168473 ** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
@@ -190861,11 +191062,11 @@
190861 # define ALWAYS(X) (X)
190862 # define NEVER(X) (X)
190863 # endif
190864 # define testcase(X)
190865 #endif
190866 #if defined(NDEBUG)
190867 # define VVA(X)
190868 #else
190869 # define VVA(X) X
190870 #endif
190871
@@ -221613,20 +221814,29 @@
221613 Fts5PoslistWriter writer;
221614 int bOk; /* True if ok to populate */
221615 int bMiss;
221616 };
221617
 
 
 
 
 
 
 
 
 
221618 static Fts5PoslistPopulator *sqlite3Fts5ExprClearPoslists(Fts5Expr *pExpr, int bLive){
221619 Fts5PoslistPopulator *pRet;
221620 pRet = sqlite3_malloc64(sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
221621 if( pRet ){
221622 int i;
221623 memset(pRet, 0, sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
221624 for(i=0; i<pExpr->nPhrase; i++){
221625 Fts5Buffer *pBuf = &pExpr->apExprPhrase[i]->poslist;
221626 Fts5ExprNode *pNode = pExpr->apExprPhrase[i]->pNode;
221627 assert( pExpr->apExprPhrase[i]->nTerm==1 );
221628 if( bLive &&
221629 (pBuf->n==0 || pNode->iRowid!=pExpr->pRoot->iRowid || pNode->bEof)
221630 ){
221631 pRet[i].bMiss = 1;
221632 }else{
@@ -231987,11 +232197,11 @@
231987 int nArg, /* Number of args */
231988 sqlite3_value **apUnused /* Function arguments */
231989 ){
231990 assert( nArg==0 );
231991 UNUSED_PARAM2(nArg, apUnused);
231992 sqlite3_result_text(pCtx, "fts5: 2021-10-26 09:53:51 4b41535b096dec4b15a85e657102a72d4288728da6103f3fdcbe0e6f244c673a", -1, SQLITE_TRANSIENT);
231993 }
231994
231995 /*
231996 ** Return true if zName is the extension on one of the shadow tables used
231997 ** by this module.
231998
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.37.0"
456 #define SQLITE_VERSION_NUMBER 3037000
457 #define SQLITE_SOURCE_ID "2021-11-03 16:35:23 3206edff947b9edb485466f05b2baadf725d798229630c7e83e88c0b9ae278ca"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -6709,10 +6709,76 @@
6709 **
6710 ** See also the [sqlite3_update_hook()] interface.
6711 */
6712 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
6713 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
6714
6715 /*
6716 ** CAPI3REF: Autovacuum Compaction Amount Callback
6717 ** METHOD: sqlite3
6718 **
6719 ** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback
6720 ** function C that is invoked prior to each autovacuum of the database
6721 ** file. ^The callback is passed a copy of the generic data pointer (P),
6722 ** the schema-name of the attached database that is being autovacuumed,
6723 ** the the size of the database file in pages, the number of free pages,
6724 ** and the number of bytes per page, respectively. The callback should
6725 ** return the number of free pages that should be removed by the
6726 ** autovacuum. ^If the callback returns zero, then no autovacuum happens.
6727 ** ^If the value returned is greater than or equal to the number of
6728 ** free pages, then a complete autovacuum happens.
6729 **
6730 ** <p>^If there are multiple ATTACH-ed database files that are being
6731 ** modified as part of a transaction commit, then the autovacuum pages
6732 ** callback is invoked separately for each file.
6733 **
6734 ** <p><b>The callback is not reentrant.</b> The callback function should
6735 ** not attempt to invoke any other SQLite interface. If it does, bad
6736 ** things may happen, including segmentation faults and corrupt database
6737 ** files. The callback function should be a simple function that
6738 ** does some arithmetic on its input parameters and returns a result.
6739 **
6740 ** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional
6741 ** destructor for the P parameter. ^If X is not NULL, then X(P) is
6742 ** invoked whenever the database connection closes or when the callback
6743 ** is overwritten by another invocation of sqlite3_autovacuum_pages().
6744 **
6745 ** <p>^There is only one autovacuum pages callback per database connection.
6746 ** ^Each call to the sqlite3_autovacuum_pages() interface overrides all
6747 ** previous invocations for that database connection. ^If the callback
6748 ** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,
6749 ** then the autovacuum steps callback is cancelled. The return value
6750 ** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might
6751 ** be some other error code if something goes wrong. The current
6752 ** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other
6753 ** return codes might be added in future releases.
6754 **
6755 ** <p>If no autovacuum pages callback is specified (the usual case) or
6756 ** a NULL pointer is provided for the callback,
6757 ** then the default behavior is to vacuum all free pages. So, in other
6758 ** words, the default behavior is the same as if the callback function
6759 ** were something like this:
6760 **
6761 ** <blockquote><pre>
6762 ** &nbsp; unsigned int demonstration_autovac_pages_callback(
6763 ** &nbsp; void *pClientData,
6764 ** &nbsp; const char *zSchema,
6765 ** &nbsp; unsigned int nDbPage,
6766 ** &nbsp; unsigned int nFreePage,
6767 ** &nbsp; unsigned int nBytePerPage
6768 ** &nbsp; ){
6769 ** &nbsp; return nFreePage;
6770 ** &nbsp; }
6771 ** </pre></blockquote>
6772 */
6773 SQLITE_API int sqlite3_autovacuum_pages(
6774 sqlite3 *db,
6775 unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
6776 void*,
6777 void(*)(void*)
6778 );
6779
6780
6781 /*
6782 ** CAPI3REF: Data Change Notification Callbacks
6783 ** METHOD: sqlite3
6784 **
@@ -16437,10 +16503,13 @@
16503 int (*xCommitCallback)(void*); /* Invoked at every commit. */
16504 void *pRollbackArg; /* Argument to xRollbackCallback() */
16505 void (*xRollbackCallback)(void*); /* Invoked at every commit. */
16506 void *pUpdateArg;
16507 void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
16508 void *pAutovacPagesArg; /* Client argument to autovac_pages */
16509 void (*xAutovacDestr)(void*); /* Destructor for pAutovacPAgesArg */
16510 unsigned int (*xAutovacPages)(void*,const char*,u32,u32,u32);
16511 Parse *pParse; /* Current parse */
16512 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
16513 void *pPreUpdateArg; /* First argument to xPreUpdateCallback */
16514 void (*xPreUpdateCallback)( /* Registered using sqlite3_preupdate_hook() */
16515 void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64
@@ -18694,12 +18763,14 @@
18763 } InitData;
18764
18765 /*
18766 ** Allowed values for mInitFlags
18767 */
18768 #define INITFLAG_AlterMask 0x0003 /* Types of ALTER */
18769 #define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */
18770 #define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */
18771 #define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */
18772
18773 /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled
18774 ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning
18775 ** parameters are for temporary use during development, to help find
18776 ** optimial values for parameters in the query planner. The should not
@@ -24126,16 +24197,19 @@
24197 pFile = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile);
24198 if( pFile ){
24199 rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, pOutFlags);
24200 if( rc!=SQLITE_OK ){
24201 sqlite3_free(pFile);
24202 *ppFile = 0;
24203 }else{
24204 *ppFile = pFile;
24205 }
24206 }else{
24207 *ppFile = 0;
24208 rc = SQLITE_NOMEM_BKPT;
24209 }
24210 assert( *ppFile!=0 || rc!=SQLITE_OK );
24211 return rc;
24212 }
24213 SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *pFile){
24214 assert( pFile );
24215 sqlite3OsClose(pFile);
@@ -38079,11 +38153,13 @@
38153 }
38154 }
38155
38156 /* Forward declaration */
38157 static int unixGetTempname(int nBuf, char *zBuf);
38158 #ifndef SQLITE_OMIT_WAL
38159 static int unixFcntlExternalReader(unixFile*, int*);
38160 #endif
38161
38162 /*
38163 ** Information and control of an open file handle.
38164 */
38165 static int unixFileControl(sqlite3_file *id, int op, void *pArg){
@@ -38198,11 +38274,16 @@
38274 return proxyFileControl(id,op,pArg);
38275 }
38276 #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
38277
38278 case SQLITE_FCNTL_EXTERNAL_READER: {
38279 #ifndef SQLITE_OMIT_WAL
38280 return unixFcntlExternalReader((unixFile*)id, (int*)pArg);
38281 #else
38282 *(int*)pArg = 0;
38283 return SQLITE_OK;
38284 #endif
38285 }
38286 }
38287 return SQLITE_NOTFOUND;
38288 }
38289
@@ -48902,10 +48983,11 @@
48983 int *pOutFlags
48984 ){
48985 MemFile *pFile = (MemFile*)pFd;
48986 MemStore *p = 0;
48987 int szName;
48988 UNUSED_PARAMETER(pVfs);
48989
48990 memset(pFile, 0, sizeof(*pFile));
48991 szName = sqlite3Strlen30(zName);
48992 if( szName>1 && zName[0]=='/' ){
48993 int i;
@@ -60864,13 +60946,17 @@
60946 ** If the wal-index is currently smaller the iPage pages then the size
60947 ** of the wal-index might be increased, but only if it is safe to do
60948 ** so. It is safe to enlarge the wal-index if pWal->writeLock is true
60949 ** or pWal->exclusiveMode==WAL_HEAPMEMORY_MODE.
60950 **
60951 ** Three possible result scenarios:
60952 **
60953 ** (1) rc==SQLITE_OK and *ppPage==Requested-Wal-Index-Page
60954 ** (2) rc>=SQLITE_ERROR and *ppPage==NULL
60955 ** (3) rc==SQLITE_OK and *ppPage==NULL // only if iPage==0
60956 **
60957 ** Scenario (3) can only occur when pWal->writeLock is false and iPage==0
60958 */
60959 static SQLITE_NOINLINE int walIndexPageRealloc(
60960 Wal *pWal, /* The WAL context */
60961 int iPage, /* The page we seek */
60962 volatile u32 **ppPage /* Write the page pointer here */
@@ -60899,11 +60985,13 @@
60985 if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM_BKPT;
60986 }else{
60987 rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ,
60988 pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
60989 );
60990 assert( pWal->apWiData[iPage]!=0
60991 || rc!=SQLITE_OK
60992 || (pWal->writeLock==0 && iPage==0) );
60993 testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK );
60994 if( rc==SQLITE_OK ){
60995 if( iPage>0 && sqlite3FaultSim(600) ) rc = SQLITE_NOMEM;
60996 }else if( (rc&0xff)==SQLITE_READONLY ){
60997 pWal->readOnly |= WAL_SHM_RDONLY;
@@ -61238,12 +61326,12 @@
61326 ** in the wal-index file. Set pLoc->iZero to one less than the frame
61327 ** number of the first frame indexed by this hash table. If a
61328 ** slot in the hash table is set to N, it refers to frame number
61329 ** (pLoc->iZero+N) in the log.
61330 **
61331 ** Finally, set pLoc->aPgno so that pLoc->aPgno[0] is the page number of the
61332 ** first frame indexed by the hash table, frame (pLoc->iZero).
61333 */
61334 static int walHashGet(
61335 Wal *pWal, /* WAL handle */
61336 int iHash, /* Find the iHash'th table */
61337 WalHashLoc *pLoc /* OUT: Hash table location */
@@ -61251,19 +61339,20 @@
61339 int rc; /* Return code */
61340
61341 rc = walIndexPage(pWal, iHash, &pLoc->aPgno);
61342 assert( rc==SQLITE_OK || iHash>0 );
61343
61344 if( pLoc->aPgno ){
61345 pLoc->aHash = (volatile ht_slot *)&pLoc->aPgno[HASHTABLE_NPAGE];
61346 if( iHash==0 ){
61347 pLoc->aPgno = &pLoc->aPgno[WALINDEX_HDR_SIZE/sizeof(u32)];
61348 pLoc->iZero = 0;
61349 }else{
61350 pLoc->iZero = HASHTABLE_NPAGE_ONE + (iHash-1)*HASHTABLE_NPAGE;
61351 }
61352 }else if( NEVER(rc==SQLITE_OK) ){
61353 rc = SQLITE_ERROR;
61354 }
61355 return rc;
61356 }
61357
61358 /*
@@ -61341,25 +61430,26 @@
61430 }
61431
61432 /* Zero the entries in the aPgno array that correspond to frames with
61433 ** frame numbers greater than pWal->hdr.mxFrame.
61434 */
61435 nByte = (int)((char *)sLoc.aHash - (char *)&sLoc.aPgno[iLimit]);
61436 assert( nByte>=0 );
61437 memset((void *)&sLoc.aPgno[iLimit], 0, nByte);
61438
61439 #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
61440 /* Verify that the every entry in the mapping region is still reachable
61441 ** via the hash table even after the cleanup.
61442 */
61443 if( iLimit ){
61444 int j; /* Loop counter */
61445 int iKey; /* Hash key */
61446 for(j=0; j<iLimit; j++){
61447 for(iKey=walHash(sLoc.aPgno[j]);sLoc.aHash[iKey];iKey=walNextHash(iKey)){
61448 if( sLoc.aHash[iKey]==j+1 ) break;
61449 }
61450 assert( sLoc.aHash[iKey]==j+1 );
61451 }
61452 }
61453 #endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */
61454 }
61455
@@ -61387,32 +61477,32 @@
61477
61478 /* If this is the first entry to be added to this hash-table, zero the
61479 ** entire hash table and aPgno[] array before proceeding.
61480 */
61481 if( idx==1 ){
61482 int nByte = (int)((u8*)&sLoc.aHash[HASHTABLE_NSLOT] - (u8*)sLoc.aPgno);
61483 assert( nByte>=0 );
61484 memset((void*)sLoc.aPgno, 0, nByte);
61485 }
61486
61487 /* If the entry in aPgno[] is already set, then the previous writer
61488 ** must have exited unexpectedly in the middle of a transaction (after
61489 ** writing one or more dirty pages to the WAL to free up memory).
61490 ** Remove the remnants of that writers uncommitted transaction from
61491 ** the hash-table before writing any new entries.
61492 */
61493 if( sLoc.aPgno[idx-1] ){
61494 walCleanupHash(pWal);
61495 assert( !sLoc.aPgno[idx-1] );
61496 }
61497
61498 /* Write the aPgno[] array entry and the hash-table slot. */
61499 nCollide = idx;
61500 for(iKey=walHash(iPage); sLoc.aHash[iKey]; iKey=walNextHash(iKey)){
61501 if( (nCollide--)==0 ) return SQLITE_CORRUPT_BKPT;
61502 }
61503 sLoc.aPgno[idx-1] = iPage;
61504 AtomicStore(&sLoc.aHash[iKey], (ht_slot)idx);
61505
61506 #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
61507 /* Verify that the number of entries in the hash table exactly equals
61508 ** the number of entries in the mapping region.
@@ -61429,22 +61519,21 @@
61519 ** thing to check, so only do this occasionally - not on every
61520 ** iteration.
61521 */
61522 if( (idx&0x3ff)==0 ){
61523 int i; /* Loop counter */
61524 for(i=0; i<idx; i++){
61525 for(iKey=walHash(sLoc.aPgno[i]);
61526 sLoc.aHash[iKey];
61527 iKey=walNextHash(iKey)){
61528 if( sLoc.aHash[iKey]==i+1 ) break;
61529 }
61530 assert( sLoc.aHash[iKey]==i+1 );
61531 }
61532 }
61533 #endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */
61534 }
 
61535
61536 return rc;
61537 }
61538
61539
@@ -61562,11 +61651,12 @@
61651 u32 iFrame; /* Index of last frame read */
61652 u32 iLast = MIN(iLastFrame, HASHTABLE_NPAGE_ONE+iPg*HASHTABLE_NPAGE);
61653 u32 iFirst = 1 + (iPg==0?0:HASHTABLE_NPAGE_ONE+(iPg-1)*HASHTABLE_NPAGE);
61654 u32 nHdr, nHdr32;
61655 rc = walIndexPage(pWal, iPg, (volatile u32**)&aShare);
61656 assert( aShare!=0 || rc!=SQLITE_OK );
61657 if( aShare==0 ) break;
61658 pWal->apWiData[iPg] = aPrivate;
61659
61660 for(iFrame=iFirst; iFrame<=iLast; iFrame++){
61661 i64 iOffset = walFrameOffset(iFrame, szPage);
61662 u32 pgno; /* Database page number for frame */
@@ -62059,11 +62149,10 @@
62149 if( rc==SQLITE_OK ){
62150 int j; /* Counter variable */
62151 int nEntry; /* Number of entries in this segment */
62152 ht_slot *aIndex; /* Sorted index for this segment */
62153
 
62154 if( (i+1)==nSegment ){
62155 nEntry = (int)(iLast - sLoc.iZero);
62156 }else{
62157 nEntry = (int)((u32*)sLoc.aHash - (u32*)sLoc.aPgno);
62158 }
@@ -63198,11 +63287,12 @@
63287 i64 iDbOff; /* Offset of db file entry */
63288 i64 iWalOff; /* Offset of wal file entry */
63289
63290 rc = walHashGet(pWal, walFramePage(i), &sLoc);
63291 if( rc!=SQLITE_OK ) break;
63292 assert( i - sLoc.iZero - 1 >=0 );
63293 pgno = sLoc.aPgno[i-sLoc.iZero-1];
63294 iDbOff = (i64)(pgno-1) * szPage;
63295
63296 if( iDbOff+szPage<=szDb ){
63297 iWalOff = walFrameOffset(i, szPage) + WAL_FRAME_HDRSIZE;
63298 rc = sqlite3OsRead(pWal->pWalFd, pBuf1, szPage, iWalOff);
@@ -63431,11 +63521,11 @@
63521 }
63522 nCollide = HASHTABLE_NSLOT;
63523 iKey = walHash(pgno);
63524 while( (iH = AtomicLoad(&sLoc.aHash[iKey]))!=0 ){
63525 u32 iFrame = iH + sLoc.iZero;
63526 if( iFrame<=iLast && iFrame>=pWal->minFrame && sLoc.aPgno[iH-1]==pgno ){
63527 assert( iFrame>iRead || CORRUPT_DB );
63528 iRead = iFrame;
63529 }
63530 if( (nCollide--)==0 ){
63531 return SQLITE_CORRUPT_BKPT;
@@ -69375,27 +69465,30 @@
69465 }
69466
69467 /*
69468 ** This routine is called prior to sqlite3PagerCommit when a transaction
69469 ** is committed for an auto-vacuum database.
 
 
 
 
 
69470 */
69471 static int autoVacuumCommit(Btree *p){
69472 int rc = SQLITE_OK;
69473 Pager *pPager;
69474 BtShared *pBt;
69475 sqlite3 *db;
69476 VVA_ONLY( int nRef );
69477
69478 assert( p!=0 );
69479 pBt = p->pBt;
69480 pPager = pBt->pPager;
69481 VVA_ONLY( nRef = sqlite3PagerRefcount(pPager); )
69482
69483 assert( sqlite3_mutex_held(pBt->mutex) );
69484 invalidateAllOverflowCache(pBt);
69485 assert(pBt->autoVacuum);
69486 if( !pBt->incrVacuum ){
69487 Pgno nFin; /* Number of pages in database after autovacuuming */
69488 Pgno nFree; /* Number of pages on the freelist initially */
69489 Pgno nVac; /* Number of pages to vacuum */
69490 Pgno iFree; /* The next page to be freed */
69491 Pgno nOrig; /* Database size before freeing */
69492
69493 nOrig = btreePagecount(pBt);
69494 if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){
@@ -69405,22 +69498,46 @@
69498 */
69499 return SQLITE_CORRUPT_BKPT;
69500 }
69501
69502 nFree = get4byte(&pBt->pPage1->aData[36]);
69503 db = p->db;
69504 if( db->xAutovacPages ){
69505 int iDb;
69506 for(iDb=0; ALWAYS(iDb<db->nDb); iDb++){
69507 if( db->aDb[iDb].pBt==p ) break;
69508 }
69509 nVac = db->xAutovacPages(
69510 db->pAutovacPagesArg,
69511 db->aDb[iDb].zDbSName,
69512 nOrig,
69513 nFree,
69514 pBt->pageSize
69515 );
69516 if( nVac>nFree ){
69517 nVac = nFree;
69518 }
69519 if( nVac==0 ){
69520 return SQLITE_OK;
69521 }
69522 }else{
69523 nVac = nFree;
69524 }
69525 nFin = finalDbSize(pBt, nOrig, nVac);
69526 if( nFin>nOrig ) return SQLITE_CORRUPT_BKPT;
69527 if( nFin<nOrig ){
69528 rc = saveAllCursors(pBt, 0, 0);
69529 }
69530 for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){
69531 rc = incrVacuumStep(pBt, nFin, iFree, nVac==nFree);
69532 }
69533 if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
69534 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
69535 if( nVac==nFree ){
69536 put4byte(&pBt->pPage1->aData[32], 0);
69537 put4byte(&pBt->pPage1->aData[36], 0);
69538 }
69539 put4byte(&pBt->pPage1->aData[28], nFin);
69540 pBt->bDoTruncate = 1;
69541 pBt->nPage = nFin;
69542 }
69543 if( rc!=SQLITE_OK ){
@@ -69467,11 +69584,11 @@
69584 if( p->inTrans==TRANS_WRITE ){
69585 BtShared *pBt = p->pBt;
69586 sqlite3BtreeEnter(p);
69587 #ifndef SQLITE_OMIT_AUTOVACUUM
69588 if( pBt->autoVacuum ){
69589 rc = autoVacuumCommit(p);
69590 if( rc!=SQLITE_OK ){
69591 sqlite3BtreeLeave(p);
69592 return rc;
69593 }
69594 }
@@ -77429,10 +77546,12 @@
77546 nByte = 1;
77547 }
77548 if( sqlite3VdbeMemGrow(pMem, nByte, 1) ){
77549 return SQLITE_NOMEM_BKPT;
77550 }
77551 assert( pMem->z!=0 );
77552 assert( sqlite3DbMallocSize(pMem->db,pMem->z) >= nByte );
77553
77554 memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
77555 pMem->n += pMem->u.nZero;
77556 pMem->flags &= ~(MEM_Zero|MEM_Term);
77557 return SQLITE_OK;
@@ -89396,20 +89515,25 @@
89515 rc = SQLITE_CORRUPT_BKPT;
89516 goto abort_due_to_error;
89517 }
89518 }
89519
89520 /* Opcode: TypeCheck P1 P2 P3 P4 *
89521 ** Synopsis: typecheck(r[P1@P2])
89522 **
89523 ** Apply affinities to the range of P2 registers beginning with P1.
89524 ** Take the affinities from the Table object in P4. If any value
89525 ** cannot be coerced into the correct type, then raise an error.
89526 **
89527 ** This opcode is similar to OP_Affinity except that this opcode
89528 ** forces the register type to the Table column type. This is used
89529 ** to implement "strict affinity".
89530 **
89531 ** GENERATED ALWAYS AS ... STATIC columns are only checked if P3
89532 ** is zero. When P3 is non-zero, no type checking occurs for
89533 ** static generated columns. Virtual columns are computed at query time
89534 ** and so they are never checked.
89535 **
89536 ** Preconditions:
89537 **
89538 ** <ul>
89539 ** <li> P2 should be the number of non-virtual columns in the
@@ -89429,11 +89553,14 @@
89553 assert( pTab->tabFlags & TF_Strict );
89554 assert( pTab->nNVCol==pOp->p2 );
89555 aCol = pTab->aCol;
89556 pIn1 = &aMem[pOp->p1];
89557 for(i=0; i<pTab->nCol; i++){
89558 if( aCol[i].colFlags & COLFLAG_GENERATED ){
89559 if( aCol[i].colFlags & COLFLAG_VIRTUAL ) continue;
89560 if( pOp->p3 ){ pIn1++; continue; }
89561 }
89562 assert( pIn1 < &aMem[pOp->p1+pOp->p2] );
89563 applyAffinity(pIn1, aCol[i].affinity, encoding);
89564 if( (pIn1->flags & MEM_Null)==0 ){
89565 switch( aCol[i].eCType ){
89566 case COLTYPE_BLOB: {
@@ -90153,10 +90280,11 @@
90280 assert( p->bIsReader );
90281 assert( p->readOnly==0 || pOp->p2==0 );
90282 assert( pOp->p2>=0 && pOp->p2<=2 );
90283 assert( pOp->p1>=0 && pOp->p1<db->nDb );
90284 assert( DbMaskTest(p->btreeMask, pOp->p1) );
90285 assert( rc==SQLITE_OK );
90286 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
90287 rc = SQLITE_READONLY;
90288 goto abort_due_to_error;
90289 }
90290 pBt = db->aDb[pOp->p1].pBt;
@@ -90196,11 +90324,12 @@
90324 p->nStmtDefCons = db->nDeferredCons;
90325 p->nStmtDefImmCons = db->nDeferredImmCons;
90326 }
90327 }
90328 assert( pOp->p5==0 || pOp->p4type==P4_INT32 );
90329 if( rc==SQLITE_OK
90330 && pOp->p5
90331 && (iMeta!=pOp->p3
90332 || db->aDb[pOp->p1].pSchema->iGeneration!=pOp->p4.i)
90333 ){
90334 /*
90335 ** IMPLEMENTATION-OF: R-03189-51135 As each SQL statement runs, the schema
@@ -97454,10 +97583,11 @@
97583 pTask->file2.iEof += pIncr->mxSz;
97584 }else{
97585 vdbeMergeEngineFree(pMerger);
97586 rc = SQLITE_NOMEM_BKPT;
97587 }
97588 assert( *ppOut!=0 || rc!=SQLITE_OK );
97589 return rc;
97590 }
97591
97592 #if SQLITE_MAX_WORKER_THREADS>0
97593 /*
@@ -103136,11 +103266,11 @@
103266 }
103267
103268 return pRet;
103269 }
103270 #else
103271 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, const Select *p, int flags){
103272 assert( p==0 );
103273 return 0;
103274 }
103275 #endif
103276
@@ -108142,11 +108272,11 @@
108272 VdbeCoverage(v);
108273 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, 3);
108274 sqlite3ReleaseTempReg(pParse, r1);
108275
108276 /* Reload the table definition */
108277 renameReloadSchema(pParse, iDb, INITFLAG_AlterAdd);
108278
108279 /* Verify that constraints are still satisfied */
108280 if( pNew->pCheck!=0
108281 || (pCol->notNull && (pCol->colFlags & COLFLAG_GENERATED)!=0)
108282 ){
@@ -109035,10 +109165,13 @@
109165 }else{
109166 p->pTab->nTabRef++;
109167 rc = sqlite3ViewGetColumnNames(pParse, p->pTab);
109168 }
109169 }
109170 }
109171 if( rc==SQLITE_OK && db->mallocFailed ){
109172 rc = SQLITE_NOMEM;
109173 }
109174 sNC.pSrcList = pSrc;
109175 if( rc==SQLITE_OK && pStep->pWhere ){
109176 rc = sqlite3ResolveExprNames(&sNC, pStep->pWhere);
109177 }
@@ -123938,28 +124071,34 @@
124071
124072 /* Before computing generated columns, first go through and make sure
124073 ** that appropriate affinity has been applied to the regular columns
124074 */
124075 sqlite3TableAffinity(pParse->pVdbe, pTab, iRegStore);
124076 if( (pTab->tabFlags & TF_HasStored)!=0 ){
124077 pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1);
124078 if( pOp->opcode==OP_Affinity ){
124079 /* Change the OP_Affinity argument to '@' (NONE) for all stored
124080 ** columns. '@' is the no-op affinity and those columns have not
124081 ** yet been computed. */
124082 int ii, jj;
124083 char *zP4 = pOp->p4.z;
124084 assert( zP4!=0 );
124085 assert( pOp->p4type==P4_DYNAMIC );
124086 for(ii=jj=0; zP4[jj]; ii++){
124087 if( pTab->aCol[ii].colFlags & COLFLAG_VIRTUAL ){
124088 continue;
124089 }
124090 if( pTab->aCol[ii].colFlags & COLFLAG_STORED ){
124091 zP4[jj] = SQLITE_AFF_NONE;
124092 }
124093 jj++;
124094 }
124095 }else if( pOp->opcode==OP_TypeCheck ){
124096 /* If an OP_TypeCheck was generated because the table is STRICT,
124097 ** then set the P3 operand to indicate that generated columns should
124098 ** not be checked */
124099 pOp->p3 = 1;
124100 }
124101 }
124102
124103 /* Because there can be multiple generated columns that refer to one another,
124104 ** this is a two-pass algorithm. On the first pass, mark all generated
@@ -125983,11 +126122,12 @@
126122 default: {
126123 int nConflictCk; /* Number of opcodes in conflict check logic */
126124
126125 assert( onError==OE_Replace );
126126 nConflictCk = sqlite3VdbeCurrentAddr(v) - addrConflictCk;
126127 assert( nConflictCk>0 || db->mallocFailed );
126128 testcase( nConflictCk<=0 );
126129 testcase( nConflictCk>1 );
126130 if( regTrigCnt ){
126131 sqlite3MultiWrite(pParse);
126132 nReplaceTrig++;
126133 }
@@ -126269,12 +126409,13 @@
126409
126410 assert( op==OP_OpenRead || op==OP_OpenWrite );
126411 assert( op==OP_OpenWrite || p5==0 );
126412 if( IsVirtual(pTab) ){
126413 /* This routine is a no-op for virtual tables. Leave the output
126414 ** variables *piDataCur and *piIdxCur set to illegal cursor numbers
126415 ** for improved error detection. */
126416 *piDataCur = *piIdxCur = -999;
126417 return 0;
126418 }
126419 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
126420 v = pParse->pVdbe;
126421 assert( v!=0 );
@@ -127281,10 +127422,14 @@
127422 /* Version 3.34.0 and later */
127423 int (*txn_state)(sqlite3*,const char*);
127424 /* Version 3.36.1 and later */
127425 sqlite3_int64 (*changes64)(sqlite3*);
127426 sqlite3_int64 (*total_changes64)(sqlite3*);
127427 /* Version 3.37.0 and later */
127428 int (*autovacuum_pages)(sqlite3*,
127429 unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
127430 void*, void(*)(void*));
127431 };
127432
127433 /*
127434 ** This is the function signature used for all extension entry points. It
127435 ** is also defined in the file "loadext.c".
@@ -127587,10 +127732,15 @@
127732 #define sqlite3_create_filename sqlite3_api->create_filename
127733 #define sqlite3_free_filename sqlite3_api->free_filename
127734 #define sqlite3_database_file_object sqlite3_api->database_file_object
127735 /* Version 3.34.0 and later */
127736 #define sqlite3_txn_state sqlite3_api->txn_state
127737 /* Version 3.36.1 and later */
127738 #define sqlite3_changes64 sqlite3_api->changes64
127739 #define sqlite3_total_changes64 sqlite3_api->total_changes64
127740 * Version 3.37.0 and later */
127741 #define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
127742 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
127743
127744 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
127745 /* This case when the file really is being compiled as a loadable
127746 ** extension */
@@ -128074,10 +128224,12 @@
128224 /* Version 3.34.0 and later */
128225 sqlite3_txn_state,
128226 /* Version 3.36.1 and later */
128227 sqlite3_changes64,
128228 sqlite3_total_changes64,
128229 /* Version 3.37.0 and later */
128230 sqlite3_autovacuum_pages,
128231 };
128232
128233 /* True if x is the directory separator character
128234 */
128235 #if SQLITE_OS_WIN
@@ -130911,11 +131063,11 @@
131063 if( pCol->notNull ){
131064 jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
131065 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
131066 pCol->zCnName);
131067 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
131068 if( bStrict && pCol->eCType!=COLTYPE_ANY ){
131069 sqlite3VdbeGoto(v, doError);
131070 }else{
131071 integrityCheckResultRow(v);
131072 }
131073 sqlite3VdbeJumpHere(v, jmp2);
@@ -131872,14 +132024,19 @@
132024 sqlite3 *db = pData->db;
132025 if( db->mallocFailed ){
132026 pData->rc = SQLITE_NOMEM_BKPT;
132027 }else if( pData->pzErrMsg[0]!=0 ){
132028 /* A error message has already been generated. Do not overwrite it */
132029 }else if( pData->mInitFlags & (INITFLAG_AlterMask) ){
132030 static const char *azAlterType[] = {
132031 "rename",
132032 "drop column",
132033 "add column"
132034 };
132035 *pData->pzErrMsg = sqlite3MPrintf(db,
132036 "error in %s %s after %s: %s", azObj[0], azObj[1],
132037 azAlterType[(pData->mInitFlags&INITFLAG_AlterMask)-1],
132038 zExtra
132039 );
132040 pData->rc = SQLITE_ERROR;
132041 }else if( db->flags & SQLITE_WriteSchema ){
132042 pData->rc = SQLITE_CORRUPT_BKPT;
@@ -143906,11 +144063,13 @@
144063 rc = sqlite3BtreeBeginTrans(pMain, pOut==0 ? 2 : 0, 0);
144064 if( rc!=SQLITE_OK ) goto end_of_vacuum;
144065
144066 /* Do not attempt to change the page size for a WAL database */
144067 if( sqlite3PagerGetJournalMode(sqlite3BtreePager(pMain))
144068 ==PAGER_JOURNALMODE_WAL
144069 && pOut==0
144070 ){
144071 db->nextPagesize = 0;
144072 }
144073
144074 if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes, 0)
144075 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
@@ -147905,12 +148064,23 @@
148064
148065 /* Load the value for the inequality constraint at the end of the
148066 ** range (if any).
148067 */
148068 nConstraint = nEq;
148069 assert( pLevel->p2==0 );
148070 if( pRangeEnd ){
148071 Expr *pRight = pRangeEnd->pExpr->pRight;
148072 if( addrSeekScan ){
148073 /* For a seek-scan that has a range on the lowest term of the index,
148074 ** we have to make the top of the loop be code that sets the end
148075 ** condition of the range. Otherwise, the OP_SeekScan might jump
148076 ** over that initialization, leaving the range-end value set to the
148077 ** range-start value, resulting in a wrong answer.
148078 ** See ticket 5981a8c041a3c2f3 (2021-11-02).
148079 */
148080 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
148081 }
148082 codeExprOrVector(pParse, pRight, regBase+nEq, nTop);
148083 whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd);
148084 if( (pRangeEnd->wtFlags & TERM_VNULL)==0
148085 && sqlite3ExprCanBeNull(pRight)
148086 ){
@@ -147940,11 +148110,11 @@
148110 }
148111 sqlite3DbFree(db, zStartAff);
148112 sqlite3DbFree(db, zEndAff);
148113
148114 /* Top of the loop body */
148115 if( pLevel->p2==0 ) pLevel->p2 = sqlite3VdbeCurrentAddr(v);
148116
148117 /* Check if the index cursor is past the end of the range. */
148118 if( nConstraint ){
148119 if( regBignull ){
148120 /* Except, skip the end-of-range check while doing the NULL-scan */
@@ -167564,10 +167734,13 @@
167734 ** So it needs to be freed here. Todo: Why not roll the temp schema into
167735 ** the same sqliteMalloc() as the one that allocates the database
167736 ** structure?
167737 */
167738 sqlite3DbFree(db, db->aDb[1].pSchema);
167739 if( db->xAutovacDestr ){
167740 db->xAutovacDestr(db->pAutovacPagesArg);
167741 }
167742 sqlite3_mutex_leave(db->mutex);
167743 db->eOpenState = SQLITE_STATE_CLOSED;
167744 sqlite3_mutex_free(db->mutex);
167745 assert( sqlite3LookasideUsed(db,0)==0 );
167746 if( db->lookaside.bMalloced ){
@@ -168464,10 +168637,38 @@
168637 db->pPreUpdateArg = pArg;
168638 sqlite3_mutex_leave(db->mutex);
168639 return pRet;
168640 }
168641 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
168642
168643 /*
168644 ** Register a function to be invoked prior to each autovacuum that
168645 ** determines the number of pages to vacuum.
168646 */
168647 SQLITE_API int sqlite3_autovacuum_pages(
168648 sqlite3 *db, /* Attach the hook to this database */
168649 unsigned int (*xCallback)(void*,const char*,u32,u32,u32),
168650 void *pArg, /* Argument to the function */
168651 void (*xDestructor)(void*) /* Destructor for pArg */
168652 ){
168653 #ifdef SQLITE_ENABLE_API_ARMOR
168654 if( !sqlite3SafetyCheckOk(db) ){
168655 if( xDestructor ) xDestructor(pArg);
168656 return SQLITE_MISUSE_BKPT;
168657 }
168658 #endif
168659 sqlite3_mutex_enter(db->mutex);
168660 if( db->xAutovacDestr ){
168661 db->xAutovacDestr(db->pAutovacPagesArg);
168662 }
168663 db->xAutovacPages = xCallback;
168664 db->pAutovacPagesArg = pArg;
168665 db->xAutovacDestr = xDestructor;
168666 sqlite3_mutex_leave(db->mutex);
168667 return SQLITE_OK;
168668 }
168669
168670
168671 #ifndef SQLITE_OMIT_WAL
168672 /*
168673 ** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint().
168674 ** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
@@ -190861,11 +191062,11 @@
191062 # define ALWAYS(X) (X)
191063 # define NEVER(X) (X)
191064 # endif
191065 # define testcase(X)
191066 #endif
191067 #if !defined(SQLITE_DEBUG) && !defined(SQLITE_COVERAGE_TEST)
191068 # define VVA(X)
191069 #else
191070 # define VVA(X) X
191071 #endif
191072
@@ -221613,20 +221814,29 @@
221814 Fts5PoslistWriter writer;
221815 int bOk; /* True if ok to populate */
221816 int bMiss;
221817 };
221818
221819 /*
221820 ** Clear the position lists associated with all phrases in the expression
221821 ** passed as the first argument. Argument bLive is true if the expression
221822 ** might be pointing to a real entry, otherwise it has just been reset.
221823 **
221824 ** At present this function is only used for detail=col and detail=none
221825 ** fts5 tables. This implies that all phrases must be at most 1 token
221826 ** in size, as phrase matches are not supported without detail=full.
221827 */
221828 static Fts5PoslistPopulator *sqlite3Fts5ExprClearPoslists(Fts5Expr *pExpr, int bLive){
221829 Fts5PoslistPopulator *pRet;
221830 pRet = sqlite3_malloc64(sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
221831 if( pRet ){
221832 int i;
221833 memset(pRet, 0, sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
221834 for(i=0; i<pExpr->nPhrase; i++){
221835 Fts5Buffer *pBuf = &pExpr->apExprPhrase[i]->poslist;
221836 Fts5ExprNode *pNode = pExpr->apExprPhrase[i]->pNode;
221837 assert( pExpr->apExprPhrase[i]->nTerm<=1 );
221838 if( bLive &&
221839 (pBuf->n==0 || pNode->iRowid!=pExpr->pRoot->iRowid || pNode->bEof)
221840 ){
221841 pRet[i].bMiss = 1;
221842 }else{
@@ -231987,11 +232197,11 @@
232197 int nArg, /* Number of args */
232198 sqlite3_value **apUnused /* Function arguments */
232199 ){
232200 assert( nArg==0 );
232201 UNUSED_PARAM2(nArg, apUnused);
232202 sqlite3_result_text(pCtx, "fts5: 2021-11-02 17:55:01 1d9004cd015073853ce0ca811a68ea5411733eedee993b97a38a42ba139d7590", -1, SQLITE_TRANSIENT);
232203 }
232204
232205 /*
232206 ** Return true if zName is the extension on one of the shadow tables used
232207 ** by this module.
232208
+67 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.37.0"
150150
#define SQLITE_VERSION_NUMBER 3037000
151
-#define SQLITE_SOURCE_ID "2021-10-26 09:53:51 4b41535b096dec4b15a85e657102a72d4288728da6103f3fdcbe0e6f244c673a"
151
+#define SQLITE_SOURCE_ID "2021-11-03 16:35:23 3206edff947b9edb485466f05b2baadf725d798229630c7e83e88c0b9ae278ca"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -6403,10 +6403,76 @@
64036403
**
64046404
** See also the [sqlite3_update_hook()] interface.
64056405
*/
64066406
SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
64076407
SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
6408
+
6409
+/*
6410
+** CAPI3REF: Autovacuum Compaction Amount Callback
6411
+** METHOD: sqlite3
6412
+**
6413
+** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback
6414
+** function C that is invoked prior to each autovacuum of the database
6415
+** file. ^The callback is passed a copy of the generic data pointer (P),
6416
+** the schema-name of the attached database that is being autovacuumed,
6417
+** the the size of the database file in pages, the number of free pages,
6418
+** and the number of bytes per page, respectively. The callback should
6419
+** return the number of free pages that should be removed by the
6420
+** autovacuum. ^If the callback returns zero, then no autovacuum happens.
6421
+** ^If the value returned is greater than or equal to the number of
6422
+** free pages, then a complete autovacuum happens.
6423
+**
6424
+** <p>^If there are multiple ATTACH-ed database files that are being
6425
+** modified as part of a transaction commit, then the autovacuum pages
6426
+** callback is invoked separately for each file.
6427
+**
6428
+** <p><b>The callback is not reentrant.</b> The callback function should
6429
+** not attempt to invoke any other SQLite interface. If it does, bad
6430
+** things may happen, including segmentation faults and corrupt database
6431
+** files. The callback function should be a simple function that
6432
+** does some arithmetic on its input parameters and returns a result.
6433
+**
6434
+** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional
6435
+** destructor for the P parameter. ^If X is not NULL, then X(P) is
6436
+** invoked whenever the database connection closes or when the callback
6437
+** is overwritten by another invocation of sqlite3_autovacuum_pages().
6438
+**
6439
+** <p>^There is only one autovacuum pages callback per database connection.
6440
+** ^Each call to the sqlite3_autovacuum_pages() interface overrides all
6441
+** previous invocations for that database connection. ^If the callback
6442
+** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,
6443
+** then the autovacuum steps callback is cancelled. The return value
6444
+** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might
6445
+** be some other error code if something goes wrong. The current
6446
+** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other
6447
+** return codes might be added in future releases.
6448
+**
6449
+** <p>If no autovacuum pages callback is specified (the usual case) or
6450
+** a NULL pointer is provided for the callback,
6451
+** then the default behavior is to vacuum all free pages. So, in other
6452
+** words, the default behavior is the same as if the callback function
6453
+** were something like this:
6454
+**
6455
+** <blockquote><pre>
6456
+** &nbsp; unsigned int demonstration_autovac_pages_callback(
6457
+** &nbsp; void *pClientData,
6458
+** &nbsp; const char *zSchema,
6459
+** &nbsp; unsigned int nDbPage,
6460
+** &nbsp; unsigned int nFreePage,
6461
+** &nbsp; unsigned int nBytePerPage
6462
+** &nbsp; ){
6463
+** &nbsp; return nFreePage;
6464
+** &nbsp; }
6465
+** </pre></blockquote>
6466
+*/
6467
+SQLITE_API int sqlite3_autovacuum_pages(
6468
+ sqlite3 *db,
6469
+ unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
6470
+ void*,
6471
+ void(*)(void*)
6472
+);
6473
+
64086474
64096475
/*
64106476
** CAPI3REF: Data Change Notification Callbacks
64116477
** METHOD: sqlite3
64126478
**
64136479
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.37.0"
150 #define SQLITE_VERSION_NUMBER 3037000
151 #define SQLITE_SOURCE_ID "2021-10-26 09:53:51 4b41535b096dec4b15a85e657102a72d4288728da6103f3fdcbe0e6f244c673a"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -6403,10 +6403,76 @@
6403 **
6404 ** See also the [sqlite3_update_hook()] interface.
6405 */
6406 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
6407 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6408
6409 /*
6410 ** CAPI3REF: Data Change Notification Callbacks
6411 ** METHOD: sqlite3
6412 **
6413
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.37.0"
150 #define SQLITE_VERSION_NUMBER 3037000
151 #define SQLITE_SOURCE_ID "2021-11-03 16:35:23 3206edff947b9edb485466f05b2baadf725d798229630c7e83e88c0b9ae278ca"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -6403,10 +6403,76 @@
6403 **
6404 ** See also the [sqlite3_update_hook()] interface.
6405 */
6406 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
6407 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
6408
6409 /*
6410 ** CAPI3REF: Autovacuum Compaction Amount Callback
6411 ** METHOD: sqlite3
6412 **
6413 ** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback
6414 ** function C that is invoked prior to each autovacuum of the database
6415 ** file. ^The callback is passed a copy of the generic data pointer (P),
6416 ** the schema-name of the attached database that is being autovacuumed,
6417 ** the the size of the database file in pages, the number of free pages,
6418 ** and the number of bytes per page, respectively. The callback should
6419 ** return the number of free pages that should be removed by the
6420 ** autovacuum. ^If the callback returns zero, then no autovacuum happens.
6421 ** ^If the value returned is greater than or equal to the number of
6422 ** free pages, then a complete autovacuum happens.
6423 **
6424 ** <p>^If there are multiple ATTACH-ed database files that are being
6425 ** modified as part of a transaction commit, then the autovacuum pages
6426 ** callback is invoked separately for each file.
6427 **
6428 ** <p><b>The callback is not reentrant.</b> The callback function should
6429 ** not attempt to invoke any other SQLite interface. If it does, bad
6430 ** things may happen, including segmentation faults and corrupt database
6431 ** files. The callback function should be a simple function that
6432 ** does some arithmetic on its input parameters and returns a result.
6433 **
6434 ** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional
6435 ** destructor for the P parameter. ^If X is not NULL, then X(P) is
6436 ** invoked whenever the database connection closes or when the callback
6437 ** is overwritten by another invocation of sqlite3_autovacuum_pages().
6438 **
6439 ** <p>^There is only one autovacuum pages callback per database connection.
6440 ** ^Each call to the sqlite3_autovacuum_pages() interface overrides all
6441 ** previous invocations for that database connection. ^If the callback
6442 ** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,
6443 ** then the autovacuum steps callback is cancelled. The return value
6444 ** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might
6445 ** be some other error code if something goes wrong. The current
6446 ** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other
6447 ** return codes might be added in future releases.
6448 **
6449 ** <p>If no autovacuum pages callback is specified (the usual case) or
6450 ** a NULL pointer is provided for the callback,
6451 ** then the default behavior is to vacuum all free pages. So, in other
6452 ** words, the default behavior is the same as if the callback function
6453 ** were something like this:
6454 **
6455 ** <blockquote><pre>
6456 ** &nbsp; unsigned int demonstration_autovac_pages_callback(
6457 ** &nbsp; void *pClientData,
6458 ** &nbsp; const char *zSchema,
6459 ** &nbsp; unsigned int nDbPage,
6460 ** &nbsp; unsigned int nFreePage,
6461 ** &nbsp; unsigned int nBytePerPage
6462 ** &nbsp; ){
6463 ** &nbsp; return nFreePage;
6464 ** &nbsp; }
6465 ** </pre></blockquote>
6466 */
6467 SQLITE_API int sqlite3_autovacuum_pages(
6468 sqlite3 *db,
6469 unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
6470 void*,
6471 void(*)(void*)
6472 );
6473
6474
6475 /*
6476 ** CAPI3REF: Data Change Notification Callbacks
6477 ** METHOD: sqlite3
6478 **
6479

Keyboard Shortcuts

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