Fossil SCM

Change the built-in SQLite to the 3.8.7.2 beta for testing.

drh 2014-11-18 13:52 trunk
Commit 27cd09c44de66fffd241572d0d2d168bf34f1a88
3 files changed +33 -144 +843 -1911 +182 -308
+33 -144
--- src/shell.c
+++ src/shell.c
@@ -170,12 +170,11 @@
170170
/* Saved resource information for the beginning of an operation */
171171
static HANDLE hProcess;
172172
static FILETIME ftKernelBegin;
173173
static FILETIME ftUserBegin;
174174
static sqlite3_int64 ftWallBegin;
175
-typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME,
176
- LPFILETIME, LPFILETIME);
175
+typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME, LPFILETIME, LPFILETIME);
177176
static GETPROCTIMES getProcessTimesAddr = NULL;
178177
179178
/*
180179
** Check to see if we have timer support. Return 1 if necessary
181180
** support found (or found previously).
@@ -182,20 +181,19 @@
182181
*/
183182
static int hasTimer(void){
184183
if( getProcessTimesAddr ){
185184
return 1;
186185
} else {
187
- /* GetProcessTimes() isn't supported in WIN95 and some other Windows
188
- ** versions. See if the version we are running on has it, and if it
189
- ** does, save off a pointer to it and the current process handle.
186
+ /* GetProcessTimes() isn't supported in WIN95 and some other Windows versions.
187
+ ** See if the version we are running on has it, and if it does, save off
188
+ ** a pointer to it and the current process handle.
190189
*/
191190
hProcess = GetCurrentProcess();
192191
if( hProcess ){
193192
HINSTANCE hinstLib = LoadLibrary(TEXT("Kernel32.dll"));
194193
if( NULL != hinstLib ){
195
- getProcessTimesAddr =
196
- (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes");
194
+ getProcessTimesAddr = (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes");
197195
if( NULL != getProcessTimesAddr ){
198196
return 1;
199197
}
200198
FreeLibrary(hinstLib);
201199
}
@@ -208,12 +206,11 @@
208206
** Begin timing an operation
209207
*/
210208
static void beginTimer(void){
211209
if( enableTimer && getProcessTimesAddr ){
212210
FILETIME ftCreation, ftExit;
213
- getProcessTimesAddr(hProcess,&ftCreation,&ftExit,
214
- &ftKernelBegin,&ftUserBegin);
211
+ getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelBegin, &ftUserBegin);
215212
ftWallBegin = timeOfDay();
216213
}
217214
}
218215
219216
/* Return the difference of two FILETIME structs in seconds */
@@ -228,11 +225,11 @@
228225
*/
229226
static void endTimer(void){
230227
if( enableTimer && getProcessTimesAddr){
231228
FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
232229
sqlite3_int64 ftWallEnd = timeOfDay();
233
- getProcessTimesAddr(hProcess,&ftCreation,&ftExit,&ftKernelEnd,&ftUserEnd);
230
+ getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelEnd, &ftUserEnd);
234231
printf("Run Time: real %.3f user %f sys %f\n",
235232
(ftWallEnd - ftWallBegin)*0.001,
236233
timeDiff(&ftUserBegin, &ftUserEnd),
237234
timeDiff(&ftKernelBegin, &ftKernelEnd));
238235
}
@@ -458,11 +455,10 @@
458455
struct ShellState {
459456
sqlite3 *db; /* The database */
460457
int echoOn; /* True to echo input commands */
461458
int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
462459
int statsOn; /* True to display memory stats before each finalize */
463
- int scanstatsOn; /* True to display scan stats before each finalize */
464460
int outCount; /* Revert to stdout when reaching zero */
465461
int cnt; /* Number of records displayed so far */
466462
FILE *out; /* Write results here */
467463
FILE *traceOut; /* Output for sqlite3_trace() */
468464
int nErr; /* Number of errors seen */
@@ -727,17 +723,11 @@
727723
728724
/*
729725
** This is the callback routine that the shell
730726
** invokes for each row of a query result.
731727
*/
732
-static int shell_callback(
733
- void *pArg,
734
- int nArg, /* Number of result columns */
735
- char **azArg, /* Text of each result column */
736
- char **azCol, /* Column names */
737
- int *aiType /* Column types */
738
-){
728
+static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int *aiType){
739729
int i;
740730
ShellState *p = (ShellState*)pArg;
741731
742732
switch( p->mode ){
743733
case MODE_Line: {
@@ -890,11 +880,11 @@
890880
for(i=0; i<nArg; i++){
891881
output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
892882
}
893883
fprintf(p->out,"%s",p->newline);
894884
}
895
- if( nArg>0 ){
885
+ if( azArg>0 ){
896886
for(i=0; i<nArg; i++){
897887
output_csv(p, azArg[i], i<nArg-1);
898888
}
899889
fprintf(p->out,"%s",p->newline);
900890
}
@@ -1112,81 +1102,61 @@
11121102
11131103
if( pArg && pArg->out ){
11141104
11151105
iHiwtr = iCur = -1;
11161106
sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset);
1117
- fprintf(pArg->out,
1118
- "Memory Used: %d (max %d) bytes\n",
1119
- iCur, iHiwtr);
1107
+ fprintf(pArg->out, "Memory Used: %d (max %d) bytes\n", iCur, iHiwtr);
11201108
iHiwtr = iCur = -1;
11211109
sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset);
1122
- fprintf(pArg->out, "Number of Outstanding Allocations: %d (max %d)\n",
1123
- iCur, iHiwtr);
1110
+ fprintf(pArg->out, "Number of Outstanding Allocations: %d (max %d)\n", iCur, iHiwtr);
11241111
if( pArg->shellFlgs & SHFLG_Pagecache ){
11251112
iHiwtr = iCur = -1;
11261113
sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &iCur, &iHiwtr, bReset);
1127
- fprintf(pArg->out,
1128
- "Number of Pcache Pages Used: %d (max %d) pages\n",
1129
- iCur, iHiwtr);
1114
+ fprintf(pArg->out, "Number of Pcache Pages Used: %d (max %d) pages\n", iCur, iHiwtr);
11301115
}
11311116
iHiwtr = iCur = -1;
11321117
sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, bReset);
1133
- fprintf(pArg->out,
1134
- "Number of Pcache Overflow Bytes: %d (max %d) bytes\n",
1135
- iCur, iHiwtr);
1118
+ fprintf(pArg->out, "Number of Pcache Overflow Bytes: %d (max %d) bytes\n", iCur, iHiwtr);
11361119
if( pArg->shellFlgs & SHFLG_Scratch ){
11371120
iHiwtr = iCur = -1;
11381121
sqlite3_status(SQLITE_STATUS_SCRATCH_USED, &iCur, &iHiwtr, bReset);
1139
- fprintf(pArg->out, "Number of Scratch Allocations Used: %d (max %d)\n",
1140
- iCur, iHiwtr);
1122
+ fprintf(pArg->out, "Number of Scratch Allocations Used: %d (max %d)\n", iCur, iHiwtr);
11411123
}
11421124
iHiwtr = iCur = -1;
11431125
sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, bReset);
1144
- fprintf(pArg->out,
1145
- "Number of Scratch Overflow Bytes: %d (max %d) bytes\n",
1146
- iCur, iHiwtr);
1126
+ fprintf(pArg->out, "Number of Scratch Overflow Bytes: %d (max %d) bytes\n", iCur, iHiwtr);
11471127
iHiwtr = iCur = -1;
11481128
sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, bReset);
1149
- fprintf(pArg->out, "Largest Allocation: %d bytes\n",
1150
- iHiwtr);
1129
+ fprintf(pArg->out, "Largest Allocation: %d bytes\n", iHiwtr);
11511130
iHiwtr = iCur = -1;
11521131
sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, bReset);
1153
- fprintf(pArg->out, "Largest Pcache Allocation: %d bytes\n",
1154
- iHiwtr);
1132
+ fprintf(pArg->out, "Largest Pcache Allocation: %d bytes\n", iHiwtr);
11551133
iHiwtr = iCur = -1;
11561134
sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, bReset);
1157
- fprintf(pArg->out, "Largest Scratch Allocation: %d bytes\n",
1158
- iHiwtr);
1135
+ fprintf(pArg->out, "Largest Scratch Allocation: %d bytes\n", iHiwtr);
11591136
#ifdef YYTRACKMAXSTACKDEPTH
11601137
iHiwtr = iCur = -1;
11611138
sqlite3_status(SQLITE_STATUS_PARSER_STACK, &iCur, &iHiwtr, bReset);
1162
- fprintf(pArg->out, "Deepest Parser Stack: %d (max %d)\n",
1163
- iCur, iHiwtr);
1139
+ fprintf(pArg->out, "Deepest Parser Stack: %d (max %d)\n", iCur, iHiwtr);
11641140
#endif
11651141
}
11661142
11671143
if( pArg && pArg->out && db ){
11681144
if( pArg->shellFlgs & SHFLG_Lookaside ){
11691145
iHiwtr = iCur = -1;
1170
- sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED,
1171
- &iCur, &iHiwtr, bReset);
1172
- fprintf(pArg->out, "Lookaside Slots Used: %d (max %d)\n",
1173
- iCur, iHiwtr);
1174
- sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT,
1175
- &iCur, &iHiwtr, bReset);
1146
+ sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED, &iCur, &iHiwtr, bReset);
1147
+ fprintf(pArg->out, "Lookaside Slots Used: %d (max %d)\n", iCur, iHiwtr);
1148
+ sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &iCur, &iHiwtr, bReset);
11761149
fprintf(pArg->out, "Successful lookaside attempts: %d\n", iHiwtr);
1177
- sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE,
1178
- &iCur, &iHiwtr, bReset);
1150
+ sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, &iCur, &iHiwtr, bReset);
11791151
fprintf(pArg->out, "Lookaside failures due to size: %d\n", iHiwtr);
1180
- sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL,
1181
- &iCur, &iHiwtr, bReset);
1152
+ sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, &iCur, &iHiwtr, bReset);
11821153
fprintf(pArg->out, "Lookaside failures due to OOM: %d\n", iHiwtr);
11831154
}
11841155
iHiwtr = iCur = -1;
11851156
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset);
1186
- fprintf(pArg->out, "Pager Heap Usage: %d bytes\n",iCur);
1187
- iHiwtr = iCur = -1;
1157
+ fprintf(pArg->out, "Pager Heap Usage: %d bytes\n", iCur); iHiwtr = iCur = -1;
11881158
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
11891159
fprintf(pArg->out, "Page cache hits: %d\n", iCur);
11901160
iHiwtr = iCur = -1;
11911161
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
11921162
fprintf(pArg->out, "Page cache misses: %d\n", iCur);
@@ -1193,76 +1163,30 @@
11931163
iHiwtr = iCur = -1;
11941164
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
11951165
fprintf(pArg->out, "Page cache writes: %d\n", iCur);
11961166
iHiwtr = iCur = -1;
11971167
sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
1198
- fprintf(pArg->out, "Schema Heap Usage: %d bytes\n",iCur);
1168
+ fprintf(pArg->out, "Schema Heap Usage: %d bytes\n", iCur);
11991169
iHiwtr = iCur = -1;
12001170
sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset);
1201
- fprintf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n",iCur);
1171
+ fprintf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n", iCur);
12021172
}
12031173
12041174
if( pArg && pArg->out && db && pArg->pStmt ){
1205
- iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP,
1206
- bReset);
1175
+ iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, bReset);
12071176
fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
12081177
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
12091178
fprintf(pArg->out, "Sort Operations: %d\n", iCur);
1210
- iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset);
1179
+ iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, bReset);
12111180
fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
12121181
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
12131182
fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
12141183
}
12151184
12161185
return 0;
12171186
}
12181187
1219
-/*
1220
-** Display scan stats.
1221
-*/
1222
-static void display_scanstats(
1223
- sqlite3 *db, /* Database to query */
1224
- ShellState *pArg /* Pointer to ShellState */
1225
-){
1226
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
1227
- int i, k, n, mx;
1228
- fprintf(pArg->out, "-------- scanstats --------\n");
1229
- mx = 0;
1230
- for(k=0; k<=mx; k++){
1231
- double rEstLoop = 1.0;
1232
- for(i=n=0; 1; i++){
1233
- sqlite3_stmt *p = pArg->pStmt;
1234
- sqlite3_int64 nLoop, nVisit;
1235
- double rEst;
1236
- int iSid;
1237
- const char *zExplain;
1238
- if( sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NLOOP, (void*)&nLoop) ){
1239
- break;
1240
- }
1241
- sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_SELECTID, (void*)&iSid);
1242
- if( iSid>mx ) mx = iSid;
1243
- if( iSid!=k ) continue;
1244
- if( n==0 ){
1245
- rEstLoop = (double)nLoop;
1246
- if( k>0 ) fprintf(pArg->out, "-------- subquery %d -------\n", k);
1247
- }
1248
- n++;
1249
- sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NVISIT, (void*)&nVisit);
1250
- sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EST, (void*)&rEst);
1251
- sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EXPLAIN, (void*)&zExplain);
1252
- fprintf(pArg->out, "Loop %2d: %s\n", n, zExplain);
1253
- rEstLoop *= rEst;
1254
- fprintf(pArg->out,
1255
- " nLoop=%-8lld nRow=%-8lld estRow=%-8lld estRow/Loop=%-8g\n",
1256
- nLoop, nVisit, (sqlite3_int64)(rEstLoop+0.5), rEst
1257
- );
1258
- }
1259
- }
1260
- fprintf(pArg->out, "---------------------------\n");
1261
-#endif
1262
-}
1263
-
12641188
/*
12651189
** Parameter azArray points to a zero-terminated array of strings. zStr
12661190
** points to a single nul-terminated string. Return non-zero if zStr
12671191
** is equal, according to strcmp(), to any of the strings in the array.
12681192
** Otherwise, return zero.
@@ -1300,12 +1224,11 @@
13001224
int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */
13011225
int iOp; /* Index of operation in p->aiIndent[] */
13021226
13031227
const char *azNext[] = { "Next", "Prev", "VPrev", "VNext", "SorterNext",
13041228
"NextIfOpen", "PrevIfOpen", 0 };
1305
- const char *azYield[] = { "Yield", "SeekLT", "SeekGT", "RowSetRead",
1306
- "Rewind", 0 };
1229
+ const char *azYield[] = { "Yield", "SeekLT", "SeekGT", "RowSetRead", "Rewind", 0 };
13071230
const char *azGoto[] = { "Goto", 0 };
13081231
13091232
/* Try to figure out if this is really an EXPLAIN statement. If this
13101233
** cannot be verified, return early. */
13111234
zSql = sqlite3_sql(pSql);
@@ -1414,12 +1337,11 @@
14141337
}
14151338
14161339
/* Show the EXPLAIN QUERY PLAN if .eqp is on */
14171340
if( pArg && pArg->autoEQP ){
14181341
sqlite3_stmt *pExplain;
1419
- char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s",
1420
- sqlite3_sql(pStmt));
1342
+ char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", sqlite3_sql(pStmt));
14211343
rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
14221344
if( rc==SQLITE_OK ){
14231345
while( sqlite3_step(pExplain)==SQLITE_ROW ){
14241346
fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0));
14251347
fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
@@ -1429,21 +1351,10 @@
14291351
}
14301352
sqlite3_finalize(pExplain);
14311353
sqlite3_free(zEQP);
14321354
}
14331355
1434
-#if USE_SYSTEM_SQLITE+0==1
1435
- /* Output TESTCTRL_EXPLAIN text of requested */
1436
- if( pArg && pArg->mode==MODE_Explain && sqlite3_libversion_number()<3008007 ){
1437
- const char *zExplain = 0;
1438
- sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
1439
- if( zExplain && zExplain[0] ){
1440
- fprintf(pArg->out, "%s", zExplain);
1441
- }
1442
- }
1443
-#endif
1444
-
14451356
/* If the shell is currently in ".explain" mode, gather the extra
14461357
** data required to add indents to the output.*/
14471358
if( pArg && pArg->mode==MODE_Explain ){
14481359
explain_data_prepare(pArg, pStmt);
14491360
}
@@ -1510,15 +1421,10 @@
15101421
/* print usage stats if stats on */
15111422
if( pArg && pArg->statsOn ){
15121423
display_stats(db, pArg, 0);
15131424
}
15141425
1515
- /* print loop-counters if required */
1516
- if( pArg && pArg->scanstatsOn ){
1517
- display_scanstats(db, pArg);
1518
- }
1519
-
15201426
/* Finalize the statement just executed. If this fails, save a
15211427
** copy of the error message. Otherwise, set zSql to point to the
15221428
** next statement to execute. */
15231429
rc2 = sqlite3_finalize(pStmt);
15241430
if( rc!=SQLITE_NOMEM ) rc = rc2;
@@ -1725,11 +1631,10 @@
17251631
".prompt MAIN CONTINUE Replace the standard prompts\n"
17261632
".quit Exit this program\n"
17271633
".read FILENAME Execute SQL in FILENAME\n"
17281634
".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
17291635
".save FILE Write in-memory database into FILE\n"
1730
- ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
17311636
".schema ?TABLE? Show the CREATE statements\n"
17321637
" If TABLE specified, only show tables matching\n"
17331638
" LIKE pattern TABLE.\n"
17341639
".separator STRING ?NL? Change separator used by output mode and .import\n"
17351640
" NL is the end-of-line mark for CSV\n"
@@ -3107,23 +3012,10 @@
31073012
rc = 1;
31083013
}
31093014
sqlite3_close(pSrc);
31103015
}else
31113016
3112
-
3113
- if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
3114
- if( nArg==2 ){
3115
- p->scanstatsOn = booleanValue(azArg[1]);
3116
-#ifndef SQLITE_ENABLE_STMT_SCANSTATUS
3117
- fprintf(stderr, "Warning: .scanstats not available in this build.\n");
3118
-#endif
3119
- }else{
3120
- fprintf(stderr, "Usage: .scanstats on|off\n");
3121
- rc = 1;
3122
- }
3123
- }else
3124
-
31253017
if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
31263018
ShellState data;
31273019
char *zErrMsg = 0;
31283020
open_db(p, 0);
31293021
memcpy(&data, p, sizeof(data));
@@ -3377,11 +3269,11 @@
33773269
if( nPrintCol<1 ) nPrintCol = 1;
33783270
nPrintRow = (nRow + nPrintCol - 1)/nPrintCol;
33793271
for(i=0; i<nPrintRow; i++){
33803272
for(j=i; j<nRow; j+=nPrintRow){
33813273
char *zSp = j<nPrintRow ? "" : " ";
3382
- fprintf(p->out, "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j]:"");
3274
+ fprintf(p->out, "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j] : "");
33833275
}
33843276
fprintf(p->out, "\n");
33853277
}
33863278
}
33873279
for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
@@ -3847,12 +3739,11 @@
38473739
*/
38483740
static char *find_home_dir(void){
38493741
static char *home_dir = NULL;
38503742
if( home_dir ) return home_dir;
38513743
3852
-#if !defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) \
3853
- && !defined(__RTP__) && !defined(_WRS_KERNEL)
3744
+#if !defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) && !defined(__RTP__) && !defined(_WRS_KERNEL)
38543745
{
38553746
struct passwd *pwent;
38563747
uid_t uid = getuid();
38573748
if( (pwent=getpwuid(uid)) != NULL) {
38583749
home_dir = pwent->pw_dir;
@@ -4247,12 +4138,10 @@
42474138
data.echoOn = 1;
42484139
}else if( strcmp(z,"-eqp")==0 ){
42494140
data.autoEQP = 1;
42504141
}else if( strcmp(z,"-stats")==0 ){
42514142
data.statsOn = 1;
4252
- }else if( strcmp(z,"-scanstats")==0 ){
4253
- data.scanstatsOn = 1;
42544143
}else if( strcmp(z,"-bail")==0 ){
42554144
bail_on_error = 1;
42564145
}else if( strcmp(z,"-version")==0 ){
42574146
printf("%s %s\n", sqlite3_libversion(), sqlite3_sourceid());
42584147
return 0;
42594148
--- src/shell.c
+++ src/shell.c
@@ -170,12 +170,11 @@
170 /* Saved resource information for the beginning of an operation */
171 static HANDLE hProcess;
172 static FILETIME ftKernelBegin;
173 static FILETIME ftUserBegin;
174 static sqlite3_int64 ftWallBegin;
175 typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME,
176 LPFILETIME, LPFILETIME);
177 static GETPROCTIMES getProcessTimesAddr = NULL;
178
179 /*
180 ** Check to see if we have timer support. Return 1 if necessary
181 ** support found (or found previously).
@@ -182,20 +181,19 @@
182 */
183 static int hasTimer(void){
184 if( getProcessTimesAddr ){
185 return 1;
186 } else {
187 /* GetProcessTimes() isn't supported in WIN95 and some other Windows
188 ** versions. See if the version we are running on has it, and if it
189 ** does, save off a pointer to it and the current process handle.
190 */
191 hProcess = GetCurrentProcess();
192 if( hProcess ){
193 HINSTANCE hinstLib = LoadLibrary(TEXT("Kernel32.dll"));
194 if( NULL != hinstLib ){
195 getProcessTimesAddr =
196 (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes");
197 if( NULL != getProcessTimesAddr ){
198 return 1;
199 }
200 FreeLibrary(hinstLib);
201 }
@@ -208,12 +206,11 @@
208 ** Begin timing an operation
209 */
210 static void beginTimer(void){
211 if( enableTimer && getProcessTimesAddr ){
212 FILETIME ftCreation, ftExit;
213 getProcessTimesAddr(hProcess,&ftCreation,&ftExit,
214 &ftKernelBegin,&ftUserBegin);
215 ftWallBegin = timeOfDay();
216 }
217 }
218
219 /* Return the difference of two FILETIME structs in seconds */
@@ -228,11 +225,11 @@
228 */
229 static void endTimer(void){
230 if( enableTimer && getProcessTimesAddr){
231 FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
232 sqlite3_int64 ftWallEnd = timeOfDay();
233 getProcessTimesAddr(hProcess,&ftCreation,&ftExit,&ftKernelEnd,&ftUserEnd);
234 printf("Run Time: real %.3f user %f sys %f\n",
235 (ftWallEnd - ftWallBegin)*0.001,
236 timeDiff(&ftUserBegin, &ftUserEnd),
237 timeDiff(&ftKernelBegin, &ftKernelEnd));
238 }
@@ -458,11 +455,10 @@
458 struct ShellState {
459 sqlite3 *db; /* The database */
460 int echoOn; /* True to echo input commands */
461 int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
462 int statsOn; /* True to display memory stats before each finalize */
463 int scanstatsOn; /* True to display scan stats before each finalize */
464 int outCount; /* Revert to stdout when reaching zero */
465 int cnt; /* Number of records displayed so far */
466 FILE *out; /* Write results here */
467 FILE *traceOut; /* Output for sqlite3_trace() */
468 int nErr; /* Number of errors seen */
@@ -727,17 +723,11 @@
727
728 /*
729 ** This is the callback routine that the shell
730 ** invokes for each row of a query result.
731 */
732 static int shell_callback(
733 void *pArg,
734 int nArg, /* Number of result columns */
735 char **azArg, /* Text of each result column */
736 char **azCol, /* Column names */
737 int *aiType /* Column types */
738 ){
739 int i;
740 ShellState *p = (ShellState*)pArg;
741
742 switch( p->mode ){
743 case MODE_Line: {
@@ -890,11 +880,11 @@
890 for(i=0; i<nArg; i++){
891 output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
892 }
893 fprintf(p->out,"%s",p->newline);
894 }
895 if( nArg>0 ){
896 for(i=0; i<nArg; i++){
897 output_csv(p, azArg[i], i<nArg-1);
898 }
899 fprintf(p->out,"%s",p->newline);
900 }
@@ -1112,81 +1102,61 @@
1112
1113 if( pArg && pArg->out ){
1114
1115 iHiwtr = iCur = -1;
1116 sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset);
1117 fprintf(pArg->out,
1118 "Memory Used: %d (max %d) bytes\n",
1119 iCur, iHiwtr);
1120 iHiwtr = iCur = -1;
1121 sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset);
1122 fprintf(pArg->out, "Number of Outstanding Allocations: %d (max %d)\n",
1123 iCur, iHiwtr);
1124 if( pArg->shellFlgs & SHFLG_Pagecache ){
1125 iHiwtr = iCur = -1;
1126 sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &iCur, &iHiwtr, bReset);
1127 fprintf(pArg->out,
1128 "Number of Pcache Pages Used: %d (max %d) pages\n",
1129 iCur, iHiwtr);
1130 }
1131 iHiwtr = iCur = -1;
1132 sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, bReset);
1133 fprintf(pArg->out,
1134 "Number of Pcache Overflow Bytes: %d (max %d) bytes\n",
1135 iCur, iHiwtr);
1136 if( pArg->shellFlgs & SHFLG_Scratch ){
1137 iHiwtr = iCur = -1;
1138 sqlite3_status(SQLITE_STATUS_SCRATCH_USED, &iCur, &iHiwtr, bReset);
1139 fprintf(pArg->out, "Number of Scratch Allocations Used: %d (max %d)\n",
1140 iCur, iHiwtr);
1141 }
1142 iHiwtr = iCur = -1;
1143 sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, bReset);
1144 fprintf(pArg->out,
1145 "Number of Scratch Overflow Bytes: %d (max %d) bytes\n",
1146 iCur, iHiwtr);
1147 iHiwtr = iCur = -1;
1148 sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, bReset);
1149 fprintf(pArg->out, "Largest Allocation: %d bytes\n",
1150 iHiwtr);
1151 iHiwtr = iCur = -1;
1152 sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, bReset);
1153 fprintf(pArg->out, "Largest Pcache Allocation: %d bytes\n",
1154 iHiwtr);
1155 iHiwtr = iCur = -1;
1156 sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, bReset);
1157 fprintf(pArg->out, "Largest Scratch Allocation: %d bytes\n",
1158 iHiwtr);
1159 #ifdef YYTRACKMAXSTACKDEPTH
1160 iHiwtr = iCur = -1;
1161 sqlite3_status(SQLITE_STATUS_PARSER_STACK, &iCur, &iHiwtr, bReset);
1162 fprintf(pArg->out, "Deepest Parser Stack: %d (max %d)\n",
1163 iCur, iHiwtr);
1164 #endif
1165 }
1166
1167 if( pArg && pArg->out && db ){
1168 if( pArg->shellFlgs & SHFLG_Lookaside ){
1169 iHiwtr = iCur = -1;
1170 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED,
1171 &iCur, &iHiwtr, bReset);
1172 fprintf(pArg->out, "Lookaside Slots Used: %d (max %d)\n",
1173 iCur, iHiwtr);
1174 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT,
1175 &iCur, &iHiwtr, bReset);
1176 fprintf(pArg->out, "Successful lookaside attempts: %d\n", iHiwtr);
1177 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE,
1178 &iCur, &iHiwtr, bReset);
1179 fprintf(pArg->out, "Lookaside failures due to size: %d\n", iHiwtr);
1180 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL,
1181 &iCur, &iHiwtr, bReset);
1182 fprintf(pArg->out, "Lookaside failures due to OOM: %d\n", iHiwtr);
1183 }
1184 iHiwtr = iCur = -1;
1185 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset);
1186 fprintf(pArg->out, "Pager Heap Usage: %d bytes\n",iCur);
1187 iHiwtr = iCur = -1;
1188 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
1189 fprintf(pArg->out, "Page cache hits: %d\n", iCur);
1190 iHiwtr = iCur = -1;
1191 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
1192 fprintf(pArg->out, "Page cache misses: %d\n", iCur);
@@ -1193,76 +1163,30 @@
1193 iHiwtr = iCur = -1;
1194 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
1195 fprintf(pArg->out, "Page cache writes: %d\n", iCur);
1196 iHiwtr = iCur = -1;
1197 sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
1198 fprintf(pArg->out, "Schema Heap Usage: %d bytes\n",iCur);
1199 iHiwtr = iCur = -1;
1200 sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset);
1201 fprintf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n",iCur);
1202 }
1203
1204 if( pArg && pArg->out && db && pArg->pStmt ){
1205 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP,
1206 bReset);
1207 fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
1208 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
1209 fprintf(pArg->out, "Sort Operations: %d\n", iCur);
1210 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset);
1211 fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
1212 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
1213 fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1214 }
1215
1216 return 0;
1217 }
1218
1219 /*
1220 ** Display scan stats.
1221 */
1222 static void display_scanstats(
1223 sqlite3 *db, /* Database to query */
1224 ShellState *pArg /* Pointer to ShellState */
1225 ){
1226 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
1227 int i, k, n, mx;
1228 fprintf(pArg->out, "-------- scanstats --------\n");
1229 mx = 0;
1230 for(k=0; k<=mx; k++){
1231 double rEstLoop = 1.0;
1232 for(i=n=0; 1; i++){
1233 sqlite3_stmt *p = pArg->pStmt;
1234 sqlite3_int64 nLoop, nVisit;
1235 double rEst;
1236 int iSid;
1237 const char *zExplain;
1238 if( sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NLOOP, (void*)&nLoop) ){
1239 break;
1240 }
1241 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_SELECTID, (void*)&iSid);
1242 if( iSid>mx ) mx = iSid;
1243 if( iSid!=k ) continue;
1244 if( n==0 ){
1245 rEstLoop = (double)nLoop;
1246 if( k>0 ) fprintf(pArg->out, "-------- subquery %d -------\n", k);
1247 }
1248 n++;
1249 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NVISIT, (void*)&nVisit);
1250 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EST, (void*)&rEst);
1251 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EXPLAIN, (void*)&zExplain);
1252 fprintf(pArg->out, "Loop %2d: %s\n", n, zExplain);
1253 rEstLoop *= rEst;
1254 fprintf(pArg->out,
1255 " nLoop=%-8lld nRow=%-8lld estRow=%-8lld estRow/Loop=%-8g\n",
1256 nLoop, nVisit, (sqlite3_int64)(rEstLoop+0.5), rEst
1257 );
1258 }
1259 }
1260 fprintf(pArg->out, "---------------------------\n");
1261 #endif
1262 }
1263
1264 /*
1265 ** Parameter azArray points to a zero-terminated array of strings. zStr
1266 ** points to a single nul-terminated string. Return non-zero if zStr
1267 ** is equal, according to strcmp(), to any of the strings in the array.
1268 ** Otherwise, return zero.
@@ -1300,12 +1224,11 @@
1300 int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */
1301 int iOp; /* Index of operation in p->aiIndent[] */
1302
1303 const char *azNext[] = { "Next", "Prev", "VPrev", "VNext", "SorterNext",
1304 "NextIfOpen", "PrevIfOpen", 0 };
1305 const char *azYield[] = { "Yield", "SeekLT", "SeekGT", "RowSetRead",
1306 "Rewind", 0 };
1307 const char *azGoto[] = { "Goto", 0 };
1308
1309 /* Try to figure out if this is really an EXPLAIN statement. If this
1310 ** cannot be verified, return early. */
1311 zSql = sqlite3_sql(pSql);
@@ -1414,12 +1337,11 @@
1414 }
1415
1416 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
1417 if( pArg && pArg->autoEQP ){
1418 sqlite3_stmt *pExplain;
1419 char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s",
1420 sqlite3_sql(pStmt));
1421 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1422 if( rc==SQLITE_OK ){
1423 while( sqlite3_step(pExplain)==SQLITE_ROW ){
1424 fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0));
1425 fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
@@ -1429,21 +1351,10 @@
1429 }
1430 sqlite3_finalize(pExplain);
1431 sqlite3_free(zEQP);
1432 }
1433
1434 #if USE_SYSTEM_SQLITE+0==1
1435 /* Output TESTCTRL_EXPLAIN text of requested */
1436 if( pArg && pArg->mode==MODE_Explain && sqlite3_libversion_number()<3008007 ){
1437 const char *zExplain = 0;
1438 sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
1439 if( zExplain && zExplain[0] ){
1440 fprintf(pArg->out, "%s", zExplain);
1441 }
1442 }
1443 #endif
1444
1445 /* If the shell is currently in ".explain" mode, gather the extra
1446 ** data required to add indents to the output.*/
1447 if( pArg && pArg->mode==MODE_Explain ){
1448 explain_data_prepare(pArg, pStmt);
1449 }
@@ -1510,15 +1421,10 @@
1510 /* print usage stats if stats on */
1511 if( pArg && pArg->statsOn ){
1512 display_stats(db, pArg, 0);
1513 }
1514
1515 /* print loop-counters if required */
1516 if( pArg && pArg->scanstatsOn ){
1517 display_scanstats(db, pArg);
1518 }
1519
1520 /* Finalize the statement just executed. If this fails, save a
1521 ** copy of the error message. Otherwise, set zSql to point to the
1522 ** next statement to execute. */
1523 rc2 = sqlite3_finalize(pStmt);
1524 if( rc!=SQLITE_NOMEM ) rc = rc2;
@@ -1725,11 +1631,10 @@
1725 ".prompt MAIN CONTINUE Replace the standard prompts\n"
1726 ".quit Exit this program\n"
1727 ".read FILENAME Execute SQL in FILENAME\n"
1728 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
1729 ".save FILE Write in-memory database into FILE\n"
1730 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
1731 ".schema ?TABLE? Show the CREATE statements\n"
1732 " If TABLE specified, only show tables matching\n"
1733 " LIKE pattern TABLE.\n"
1734 ".separator STRING ?NL? Change separator used by output mode and .import\n"
1735 " NL is the end-of-line mark for CSV\n"
@@ -3107,23 +3012,10 @@
3107 rc = 1;
3108 }
3109 sqlite3_close(pSrc);
3110 }else
3111
3112
3113 if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
3114 if( nArg==2 ){
3115 p->scanstatsOn = booleanValue(azArg[1]);
3116 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
3117 fprintf(stderr, "Warning: .scanstats not available in this build.\n");
3118 #endif
3119 }else{
3120 fprintf(stderr, "Usage: .scanstats on|off\n");
3121 rc = 1;
3122 }
3123 }else
3124
3125 if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
3126 ShellState data;
3127 char *zErrMsg = 0;
3128 open_db(p, 0);
3129 memcpy(&data, p, sizeof(data));
@@ -3377,11 +3269,11 @@
3377 if( nPrintCol<1 ) nPrintCol = 1;
3378 nPrintRow = (nRow + nPrintCol - 1)/nPrintCol;
3379 for(i=0; i<nPrintRow; i++){
3380 for(j=i; j<nRow; j+=nPrintRow){
3381 char *zSp = j<nPrintRow ? "" : " ";
3382 fprintf(p->out, "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j]:"");
3383 }
3384 fprintf(p->out, "\n");
3385 }
3386 }
3387 for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
@@ -3847,12 +3739,11 @@
3847 */
3848 static char *find_home_dir(void){
3849 static char *home_dir = NULL;
3850 if( home_dir ) return home_dir;
3851
3852 #if !defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) \
3853 && !defined(__RTP__) && !defined(_WRS_KERNEL)
3854 {
3855 struct passwd *pwent;
3856 uid_t uid = getuid();
3857 if( (pwent=getpwuid(uid)) != NULL) {
3858 home_dir = pwent->pw_dir;
@@ -4247,12 +4138,10 @@
4247 data.echoOn = 1;
4248 }else if( strcmp(z,"-eqp")==0 ){
4249 data.autoEQP = 1;
4250 }else if( strcmp(z,"-stats")==0 ){
4251 data.statsOn = 1;
4252 }else if( strcmp(z,"-scanstats")==0 ){
4253 data.scanstatsOn = 1;
4254 }else if( strcmp(z,"-bail")==0 ){
4255 bail_on_error = 1;
4256 }else if( strcmp(z,"-version")==0 ){
4257 printf("%s %s\n", sqlite3_libversion(), sqlite3_sourceid());
4258 return 0;
4259
--- src/shell.c
+++ src/shell.c
@@ -170,12 +170,11 @@
170 /* Saved resource information for the beginning of an operation */
171 static HANDLE hProcess;
172 static FILETIME ftKernelBegin;
173 static FILETIME ftUserBegin;
174 static sqlite3_int64 ftWallBegin;
175 typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME, LPFILETIME, LPFILETIME);
 
176 static GETPROCTIMES getProcessTimesAddr = NULL;
177
178 /*
179 ** Check to see if we have timer support. Return 1 if necessary
180 ** support found (or found previously).
@@ -182,20 +181,19 @@
181 */
182 static int hasTimer(void){
183 if( getProcessTimesAddr ){
184 return 1;
185 } else {
186 /* GetProcessTimes() isn't supported in WIN95 and some other Windows versions.
187 ** See if the version we are running on has it, and if it does, save off
188 ** a pointer to it and the current process handle.
189 */
190 hProcess = GetCurrentProcess();
191 if( hProcess ){
192 HINSTANCE hinstLib = LoadLibrary(TEXT("Kernel32.dll"));
193 if( NULL != hinstLib ){
194 getProcessTimesAddr = (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes");
 
195 if( NULL != getProcessTimesAddr ){
196 return 1;
197 }
198 FreeLibrary(hinstLib);
199 }
@@ -208,12 +206,11 @@
206 ** Begin timing an operation
207 */
208 static void beginTimer(void){
209 if( enableTimer && getProcessTimesAddr ){
210 FILETIME ftCreation, ftExit;
211 getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelBegin, &ftUserBegin);
 
212 ftWallBegin = timeOfDay();
213 }
214 }
215
216 /* Return the difference of two FILETIME structs in seconds */
@@ -228,11 +225,11 @@
225 */
226 static void endTimer(void){
227 if( enableTimer && getProcessTimesAddr){
228 FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
229 sqlite3_int64 ftWallEnd = timeOfDay();
230 getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelEnd, &ftUserEnd);
231 printf("Run Time: real %.3f user %f sys %f\n",
232 (ftWallEnd - ftWallBegin)*0.001,
233 timeDiff(&ftUserBegin, &ftUserEnd),
234 timeDiff(&ftKernelBegin, &ftKernelEnd));
235 }
@@ -458,11 +455,10 @@
455 struct ShellState {
456 sqlite3 *db; /* The database */
457 int echoOn; /* True to echo input commands */
458 int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
459 int statsOn; /* True to display memory stats before each finalize */
 
460 int outCount; /* Revert to stdout when reaching zero */
461 int cnt; /* Number of records displayed so far */
462 FILE *out; /* Write results here */
463 FILE *traceOut; /* Output for sqlite3_trace() */
464 int nErr; /* Number of errors seen */
@@ -727,17 +723,11 @@
723
724 /*
725 ** This is the callback routine that the shell
726 ** invokes for each row of a query result.
727 */
728 static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int *aiType){
 
 
 
 
 
 
729 int i;
730 ShellState *p = (ShellState*)pArg;
731
732 switch( p->mode ){
733 case MODE_Line: {
@@ -890,11 +880,11 @@
880 for(i=0; i<nArg; i++){
881 output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
882 }
883 fprintf(p->out,"%s",p->newline);
884 }
885 if( azArg>0 ){
886 for(i=0; i<nArg; i++){
887 output_csv(p, azArg[i], i<nArg-1);
888 }
889 fprintf(p->out,"%s",p->newline);
890 }
@@ -1112,81 +1102,61 @@
1102
1103 if( pArg && pArg->out ){
1104
1105 iHiwtr = iCur = -1;
1106 sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset);
1107 fprintf(pArg->out, "Memory Used: %d (max %d) bytes\n", iCur, iHiwtr);
 
 
1108 iHiwtr = iCur = -1;
1109 sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset);
1110 fprintf(pArg->out, "Number of Outstanding Allocations: %d (max %d)\n", iCur, iHiwtr);
 
1111 if( pArg->shellFlgs & SHFLG_Pagecache ){
1112 iHiwtr = iCur = -1;
1113 sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &iCur, &iHiwtr, bReset);
1114 fprintf(pArg->out, "Number of Pcache Pages Used: %d (max %d) pages\n", iCur, iHiwtr);
 
 
1115 }
1116 iHiwtr = iCur = -1;
1117 sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, bReset);
1118 fprintf(pArg->out, "Number of Pcache Overflow Bytes: %d (max %d) bytes\n", iCur, iHiwtr);
 
 
1119 if( pArg->shellFlgs & SHFLG_Scratch ){
1120 iHiwtr = iCur = -1;
1121 sqlite3_status(SQLITE_STATUS_SCRATCH_USED, &iCur, &iHiwtr, bReset);
1122 fprintf(pArg->out, "Number of Scratch Allocations Used: %d (max %d)\n", iCur, iHiwtr);
 
1123 }
1124 iHiwtr = iCur = -1;
1125 sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, bReset);
1126 fprintf(pArg->out, "Number of Scratch Overflow Bytes: %d (max %d) bytes\n", iCur, iHiwtr);
 
 
1127 iHiwtr = iCur = -1;
1128 sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, bReset);
1129 fprintf(pArg->out, "Largest Allocation: %d bytes\n", iHiwtr);
 
1130 iHiwtr = iCur = -1;
1131 sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, bReset);
1132 fprintf(pArg->out, "Largest Pcache Allocation: %d bytes\n", iHiwtr);
 
1133 iHiwtr = iCur = -1;
1134 sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, bReset);
1135 fprintf(pArg->out, "Largest Scratch Allocation: %d bytes\n", iHiwtr);
 
1136 #ifdef YYTRACKMAXSTACKDEPTH
1137 iHiwtr = iCur = -1;
1138 sqlite3_status(SQLITE_STATUS_PARSER_STACK, &iCur, &iHiwtr, bReset);
1139 fprintf(pArg->out, "Deepest Parser Stack: %d (max %d)\n", iCur, iHiwtr);
 
1140 #endif
1141 }
1142
1143 if( pArg && pArg->out && db ){
1144 if( pArg->shellFlgs & SHFLG_Lookaside ){
1145 iHiwtr = iCur = -1;
1146 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED, &iCur, &iHiwtr, bReset);
1147 fprintf(pArg->out, "Lookaside Slots Used: %d (max %d)\n", iCur, iHiwtr);
1148 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &iCur, &iHiwtr, bReset);
 
 
 
1149 fprintf(pArg->out, "Successful lookaside attempts: %d\n", iHiwtr);
1150 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, &iCur, &iHiwtr, bReset);
 
1151 fprintf(pArg->out, "Lookaside failures due to size: %d\n", iHiwtr);
1152 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, &iCur, &iHiwtr, bReset);
 
1153 fprintf(pArg->out, "Lookaside failures due to OOM: %d\n", iHiwtr);
1154 }
1155 iHiwtr = iCur = -1;
1156 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset);
1157 fprintf(pArg->out, "Pager Heap Usage: %d bytes\n", iCur); iHiwtr = iCur = -1;
 
1158 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
1159 fprintf(pArg->out, "Page cache hits: %d\n", iCur);
1160 iHiwtr = iCur = -1;
1161 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
1162 fprintf(pArg->out, "Page cache misses: %d\n", iCur);
@@ -1193,76 +1163,30 @@
1163 iHiwtr = iCur = -1;
1164 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
1165 fprintf(pArg->out, "Page cache writes: %d\n", iCur);
1166 iHiwtr = iCur = -1;
1167 sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
1168 fprintf(pArg->out, "Schema Heap Usage: %d bytes\n", iCur);
1169 iHiwtr = iCur = -1;
1170 sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset);
1171 fprintf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n", iCur);
1172 }
1173
1174 if( pArg && pArg->out && db && pArg->pStmt ){
1175 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, bReset);
 
1176 fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
1177 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
1178 fprintf(pArg->out, "Sort Operations: %d\n", iCur);
1179 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, bReset);
1180 fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
1181 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
1182 fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1183 }
1184
1185 return 0;
1186 }
1187
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1188 /*
1189 ** Parameter azArray points to a zero-terminated array of strings. zStr
1190 ** points to a single nul-terminated string. Return non-zero if zStr
1191 ** is equal, according to strcmp(), to any of the strings in the array.
1192 ** Otherwise, return zero.
@@ -1300,12 +1224,11 @@
1224 int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */
1225 int iOp; /* Index of operation in p->aiIndent[] */
1226
1227 const char *azNext[] = { "Next", "Prev", "VPrev", "VNext", "SorterNext",
1228 "NextIfOpen", "PrevIfOpen", 0 };
1229 const char *azYield[] = { "Yield", "SeekLT", "SeekGT", "RowSetRead", "Rewind", 0 };
 
1230 const char *azGoto[] = { "Goto", 0 };
1231
1232 /* Try to figure out if this is really an EXPLAIN statement. If this
1233 ** cannot be verified, return early. */
1234 zSql = sqlite3_sql(pSql);
@@ -1414,12 +1337,11 @@
1337 }
1338
1339 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
1340 if( pArg && pArg->autoEQP ){
1341 sqlite3_stmt *pExplain;
1342 char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", sqlite3_sql(pStmt));
 
1343 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1344 if( rc==SQLITE_OK ){
1345 while( sqlite3_step(pExplain)==SQLITE_ROW ){
1346 fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0));
1347 fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
@@ -1429,21 +1351,10 @@
1351 }
1352 sqlite3_finalize(pExplain);
1353 sqlite3_free(zEQP);
1354 }
1355
 
 
 
 
 
 
 
 
 
 
 
1356 /* If the shell is currently in ".explain" mode, gather the extra
1357 ** data required to add indents to the output.*/
1358 if( pArg && pArg->mode==MODE_Explain ){
1359 explain_data_prepare(pArg, pStmt);
1360 }
@@ -1510,15 +1421,10 @@
1421 /* print usage stats if stats on */
1422 if( pArg && pArg->statsOn ){
1423 display_stats(db, pArg, 0);
1424 }
1425
 
 
 
 
 
1426 /* Finalize the statement just executed. If this fails, save a
1427 ** copy of the error message. Otherwise, set zSql to point to the
1428 ** next statement to execute. */
1429 rc2 = sqlite3_finalize(pStmt);
1430 if( rc!=SQLITE_NOMEM ) rc = rc2;
@@ -1725,11 +1631,10 @@
1631 ".prompt MAIN CONTINUE Replace the standard prompts\n"
1632 ".quit Exit this program\n"
1633 ".read FILENAME Execute SQL in FILENAME\n"
1634 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
1635 ".save FILE Write in-memory database into FILE\n"
 
1636 ".schema ?TABLE? Show the CREATE statements\n"
1637 " If TABLE specified, only show tables matching\n"
1638 " LIKE pattern TABLE.\n"
1639 ".separator STRING ?NL? Change separator used by output mode and .import\n"
1640 " NL is the end-of-line mark for CSV\n"
@@ -3107,23 +3012,10 @@
3012 rc = 1;
3013 }
3014 sqlite3_close(pSrc);
3015 }else
3016
 
 
 
 
 
 
 
 
 
 
 
 
 
3017 if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
3018 ShellState data;
3019 char *zErrMsg = 0;
3020 open_db(p, 0);
3021 memcpy(&data, p, sizeof(data));
@@ -3377,11 +3269,11 @@
3269 if( nPrintCol<1 ) nPrintCol = 1;
3270 nPrintRow = (nRow + nPrintCol - 1)/nPrintCol;
3271 for(i=0; i<nPrintRow; i++){
3272 for(j=i; j<nRow; j+=nPrintRow){
3273 char *zSp = j<nPrintRow ? "" : " ";
3274 fprintf(p->out, "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j] : "");
3275 }
3276 fprintf(p->out, "\n");
3277 }
3278 }
3279 for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
@@ -3847,12 +3739,11 @@
3739 */
3740 static char *find_home_dir(void){
3741 static char *home_dir = NULL;
3742 if( home_dir ) return home_dir;
3743
3744 #if !defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) && !defined(__RTP__) && !defined(_WRS_KERNEL)
 
3745 {
3746 struct passwd *pwent;
3747 uid_t uid = getuid();
3748 if( (pwent=getpwuid(uid)) != NULL) {
3749 home_dir = pwent->pw_dir;
@@ -4247,12 +4138,10 @@
4138 data.echoOn = 1;
4139 }else if( strcmp(z,"-eqp")==0 ){
4140 data.autoEQP = 1;
4141 }else if( strcmp(z,"-stats")==0 ){
4142 data.statsOn = 1;
 
 
4143 }else if( strcmp(z,"-bail")==0 ){
4144 bail_on_error = 1;
4145 }else if( strcmp(z,"-version")==0 ){
4146 printf("%s %s\n", sqlite3_libversion(), sqlite3_sourceid());
4147 return 0;
4148
+843 -1911
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.8.8. By combining all the individual C code files into this
3
+** version 3.8.7.2. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -179,11 +179,11 @@
179179
180180
181181
/*
182182
** These no-op macros are used in front of interfaces to mark those
183183
** interfaces as either deprecated or experimental. New applications
184
-** should not use deprecated interfaces - they are supported for backwards
184
+** should not use deprecated interfaces - they are support for backwards
185185
** compatibility only. Application writers should be aware that
186186
** experimental interfaces are subject to change in point releases.
187187
**
188188
** These macros used to resolve to various kinds of compiler magic that
189189
** would generate warning messages when they were used. But that
@@ -229,13 +229,13 @@
229229
**
230230
** See also: [sqlite3_libversion()],
231231
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232232
** [sqlite_version()] and [sqlite_source_id()].
233233
*/
234
-#define SQLITE_VERSION "3.8.8"
235
-#define SQLITE_VERSION_NUMBER 3008008
236
-#define SQLITE_SOURCE_ID "2014-11-11 19:07:56 1412fcc480799ecbd68d44dd18d5bad40e20ccf1"
234
+#define SQLITE_VERSION "3.8.7.2"
235
+#define SQLITE_VERSION_NUMBER 3008007
236
+#define SQLITE_SOURCE_ID "2014-11-18 12:28:52 945a9e687fdfee5f7103d85d131024e85d594ac3"
237237
238238
/*
239239
** CAPI3REF: Run-Time Library Version Numbers
240240
** KEYWORDS: sqlite3_version, sqlite3_sourceid
241241
**
@@ -1626,31 +1626,29 @@
16261626
** it is not possible to set the Serialized [threading mode] and
16271627
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
16281628
** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
16291629
**
16301630
** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1631
-** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
1632
-** a pointer to an instance of the [sqlite3_mem_methods] structure.
1633
-** The argument specifies
1631
+** <dd> ^(This option takes a single argument which is a pointer to an
1632
+** instance of the [sqlite3_mem_methods] structure. The argument specifies
16341633
** alternative low-level memory allocation routines to be used in place of
16351634
** the memory allocation routines built into SQLite.)^ ^SQLite makes
16361635
** its own private copy of the content of the [sqlite3_mem_methods] structure
16371636
** before the [sqlite3_config()] call returns.</dd>
16381637
**
16391638
** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1640
-** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
1641
-** is a pointer to an instance of the [sqlite3_mem_methods] structure.
1642
-** The [sqlite3_mem_methods]
1639
+** <dd> ^(This option takes a single argument which is a pointer to an
1640
+** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
16431641
** structure is filled with the currently defined memory allocation routines.)^
16441642
** This option can be used to overload the default memory allocation
16451643
** routines with a wrapper that simulations memory allocation failure or
16461644
** tracks memory usage, for example. </dd>
16471645
**
16481646
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1649
-** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1650
-** interpreted as a boolean, which enables or disables the collection of
1651
-** memory allocation statistics. ^(When memory allocation statistics are disabled, the
1647
+** <dd> ^This option takes single argument of type int, interpreted as a
1648
+** boolean, which enables or disables the collection of memory allocation
1649
+** statistics. ^(When memory allocation statistics are disabled, the
16521650
** following SQLite interfaces become non-operational:
16531651
** <ul>
16541652
** <li> [sqlite3_memory_used()]
16551653
** <li> [sqlite3_memory_highwater()]
16561654
** <li> [sqlite3_soft_heap_limit64()]
@@ -1660,90 +1658,78 @@
16601658
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
16611659
** allocation statistics are disabled by default.
16621660
** </dd>
16631661
**
16641662
** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1665
-** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
1666
-** that SQLite can use for scratch memory. ^(There are three arguments
1667
-** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
1663
+** <dd> ^This option specifies a static memory buffer that SQLite can use for
1664
+** scratch memory. There are three arguments: A pointer an 8-byte
16681665
** aligned memory buffer from which the scratch allocations will be
16691666
** drawn, the size of each scratch allocation (sz),
1670
-** and the maximum number of scratch allocations (N).)^
1667
+** and the maximum number of scratch allocations (N). The sz
1668
+** argument must be a multiple of 16.
16711669
** The first argument must be a pointer to an 8-byte aligned buffer
16721670
** of at least sz*N bytes of memory.
1673
-** ^SQLite will not use more than one scratch buffers per thread.
1674
-** ^SQLite will never request a scratch buffer that is more than 6
1675
-** times the database page size.
1676
-** ^If SQLite needs needs additional
1671
+** ^SQLite will use no more than two scratch buffers per thread. So
1672
+** N should be set to twice the expected maximum number of threads.
1673
+** ^SQLite will never require a scratch buffer that is more than 6
1674
+** times the database page size. ^If SQLite needs needs additional
16771675
** scratch memory beyond what is provided by this configuration option, then
1678
-** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
1679
-** ^When the application provides any amount of scratch memory using
1680
-** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
1681
-** [sqlite3_malloc|heap allocations].
1682
-** This can help [Robson proof|prevent memory allocation failures] due to heap
1683
-** fragmentation in low-memory embedded systems.
1684
-** </dd>
1676
+** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
16851677
**
16861678
** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1687
-** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a static memory buffer
1688
-** that SQLite can use for the database page cache with the default page
1689
-** cache implementation.
1679
+** <dd> ^This option specifies a static memory buffer that SQLite can use for
1680
+** the database page cache with the default page cache implementation.
16901681
** This configuration should not be used if an application-define page
1691
-** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]
1692
-** configuration option.
1693
-** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned
1682
+** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option.
1683
+** There are three arguments to this option: A pointer to 8-byte aligned
16941684
** memory, the size of each page buffer (sz), and the number of pages (N).
16951685
** The sz argument should be the size of the largest database page
1696
-** (a power of two between 512 and 32768) plus some extra bytes for each
1697
-** page header. ^The number of extra bytes needed by the page header
1698
-** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1699
-** to [sqlite3_config()].
1700
-** ^It is harmless, apart from the wasted memory,
1701
-** for the sz parameter to be larger than necessary. The first
1702
-** argument should pointer to an 8-byte aligned block of memory that
1703
-** is at least sz*N bytes of memory, otherwise subsequent behavior is
1704
-** undefined.
1686
+** (a power of two between 512 and 32768) plus a little extra for each
1687
+** page header. ^The page header size is 20 to 40 bytes depending on
1688
+** the host architecture. ^It is harmless, apart from the wasted memory,
1689
+** to make sz a little too large. The first
1690
+** argument should point to an allocation of at least sz*N bytes of memory.
17051691
** ^SQLite will use the memory provided by the first argument to satisfy its
17061692
** memory needs for the first N pages that it adds to cache. ^If additional
17071693
** page cache memory is needed beyond what is provided by this option, then
1708
-** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd>
1694
+** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1695
+** The pointer in the first argument must
1696
+** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1697
+** will be undefined.</dd>
17091698
**
17101699
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1711
-** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
1712
-** that SQLite will use for all of its dynamic memory allocation needs
1713
-** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1714
-** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
1715
-** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
1716
-** [SQLITE_ERROR] if invoked otherwise.
1717
-** ^There are three arguments to SQLITE_CONFIG_HEAP:
1718
-** An 8-byte aligned pointer to the memory,
1700
+** <dd> ^This option specifies a static memory buffer that SQLite will use
1701
+** for all of its dynamic memory allocation needs beyond those provided
1702
+** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1703
+** There are three arguments: An 8-byte aligned pointer to the memory,
17191704
** the number of bytes in the memory buffer, and the minimum allocation size.
17201705
** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
17211706
** to using its default memory allocator (the system malloc() implementation),
17221707
** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1723
-** memory pointer is not NULL then the alternative memory
1708
+** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1709
+** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
17241710
** allocator is engaged to handle all of SQLites memory allocation needs.
17251711
** The first pointer (the memory pointer) must be aligned to an 8-byte
17261712
** boundary or subsequent behavior of SQLite will be undefined.
17271713
** The minimum allocation size is capped at 2**12. Reasonable values
17281714
** for the minimum allocation size are 2**5 through 2**8.</dd>
17291715
**
17301716
** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1731
-** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
1732
-** pointer to an instance of the [sqlite3_mutex_methods] structure.
1733
-** The argument specifies alternative low-level mutex routines to be used in place
1717
+** <dd> ^(This option takes a single argument which is a pointer to an
1718
+** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1719
+** alternative low-level mutex routines to be used in place
17341720
** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
17351721
** content of the [sqlite3_mutex_methods] structure before the call to
17361722
** [sqlite3_config()] returns. ^If SQLite is compiled with
17371723
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
17381724
** the entire mutexing subsystem is omitted from the build and hence calls to
17391725
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
17401726
** return [SQLITE_ERROR].</dd>
17411727
**
17421728
** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1743
-** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
1744
-** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
1729
+** <dd> ^(This option takes a single argument which is a pointer to an
1730
+** instance of the [sqlite3_mutex_methods] structure. The
17451731
** [sqlite3_mutex_methods]
17461732
** structure is filled with the currently defined mutex routines.)^
17471733
** This option can be used to overload the default mutex allocation
17481734
** routines with a wrapper used to track mutex usage for performance
17491735
** profiling or testing, for example. ^If SQLite is compiled with
@@ -1751,28 +1737,28 @@
17511737
** the entire mutexing subsystem is omitted from the build and hence calls to
17521738
** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
17531739
** return [SQLITE_ERROR].</dd>
17541740
**
17551741
** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1756
-** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
1757
-** the default size of lookaside memory on each [database connection].
1758
-** The first argument is the
1742
+** <dd> ^(This option takes two arguments that determine the default
1743
+** memory allocation for the lookaside memory allocator on each
1744
+** [database connection]. The first argument is the
17591745
** size of each lookaside buffer slot and the second is the number of
1760
-** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
1761
-** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1762
-** option to [sqlite3_db_config()] can be used to change the lookaside
1746
+** slots allocated to each database connection.)^ ^(This option sets the
1747
+** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1748
+** verb to [sqlite3_db_config()] can be used to change the lookaside
17631749
** configuration on individual connections.)^ </dd>
17641750
**
17651751
** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1766
-** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
1767
-** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
1768
-** the interface to a custom page cache implementation.)^
1769
-** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
1752
+** <dd> ^(This option takes a single argument which is a pointer to
1753
+** an [sqlite3_pcache_methods2] object. This object specifies the interface
1754
+** to a custom page cache implementation.)^ ^SQLite makes a copy of the
1755
+** object and uses it for page cache memory allocations.</dd>
17701756
**
17711757
** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1772
-** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
1773
-** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of the current
1758
+** <dd> ^(This option takes a single argument which is a pointer to an
1759
+** [sqlite3_pcache_methods2] object. SQLite copies of the current
17741760
** page cache implementation into that object.)^ </dd>
17751761
**
17761762
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
17771763
** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
17781764
** global [error log].
@@ -1792,27 +1778,26 @@
17921778
** supplied by the application must not invoke any SQLite interface.
17931779
** In a multi-threaded application, the application-defined logger
17941780
** function must be threadsafe. </dd>
17951781
**
17961782
** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1797
-** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
1798
-** If non-zero, then URI handling is globally enabled. If the parameter is zero,
1799
-** then URI handling is globally disabled.)^ ^If URI handling is globally enabled,
1800
-** all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
1783
+** <dd>^(This option takes a single argument of type int. If non-zero, then
1784
+** URI handling is globally enabled. If the parameter is zero, then URI handling
1785
+** is globally disabled.)^ ^If URI handling is globally enabled, all filenames
1786
+** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
18011787
** specified as part of [ATTACH] commands are interpreted as URIs, regardless
18021788
** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
18031789
** connection is opened. ^If it is globally disabled, filenames are
18041790
** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
18051791
** database connection is opened. ^(By default, URI handling is globally
18061792
** disabled. The default value may be changed by compiling with the
18071793
** [SQLITE_USE_URI] symbol defined.)^
18081794
**
18091795
** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1810
-** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
1811
-** argument which is interpreted as a boolean in order to enable or disable
1812
-** the use of covering indices for full table scans in the query optimizer.
1813
-** ^The default setting is determined
1796
+** <dd>^This option takes a single integer argument which is interpreted as
1797
+** a boolean in order to enable or disable the use of covering indices for
1798
+** full table scans in the query optimizer. ^The default setting is determined
18141799
** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
18151800
** if that compile-time option is omitted.
18161801
** The ability to disable the use of covering indices for full table scans
18171802
** is because some incorrectly coded legacy applications might malfunction
18181803
** when the optimization is enabled. Providing the ability to
@@ -1848,32 +1833,23 @@
18481833
** that are the default mmap size limit (the default setting for
18491834
** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
18501835
** ^The default setting can be overridden by each database connection using
18511836
** either the [PRAGMA mmap_size] command, or by using the
18521837
** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
1853
-** will be silently truncated if necessary so that it does not exceed the
1854
-** compile-time maximum mmap size set by the
1838
+** cannot be changed at run-time. Nor may the maximum allowed mmap size
1839
+** exceed the compile-time maximum mmap size set by the
18551840
** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
18561841
** ^If either argument to this option is negative, then that argument is
18571842
** changed to its compile-time default.
18581843
**
18591844
** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
18601845
** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1861
-** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
1862
-** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1863
-** ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1846
+** <dd>^This option is only available if SQLite is compiled for Windows
1847
+** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1848
+** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
18641849
** that specifies the maximum size of the created heap.
18651850
** </dl>
1866
-**
1867
-** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
1868
-** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
1869
-** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1870
-** is a pointer to an integer and writes into that integer the number of extra
1871
-** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. The amount of
1872
-** extra space required can change depending on the compiler,
1873
-** target platform, and SQLite version.
1874
-** </dl>
18751851
*/
18761852
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
18771853
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
18781854
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
18791855
#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
@@ -1894,11 +1870,10 @@
18941870
#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
18951871
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
18961872
#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
18971873
#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
18981874
#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1899
-#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
19001875
19011876
/*
19021877
** CAPI3REF: Database Connection Configuration Options
19031878
**
19041879
** These constants are the available integer configuration options that
@@ -2022,49 +1997,51 @@
20221997
SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
20231998
20241999
/*
20252000
** CAPI3REF: Count The Number Of Rows Modified
20262001
**
2027
-** ^This function returns the number of rows modified, inserted or
2028
-** deleted by the most recently completed INSERT, UPDATE or DELETE
2029
-** statement on the database connection specified by the only parameter.
2030
-** ^Executing any other type of SQL statement does not modify the value
2031
-** returned by this function.
2032
-**
2033
-** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
2034
-** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
2035
-** [foreign key actions] or [REPLACE] constraint resolution are not counted.
2036
-**
2037
-** Changes to a view that are intercepted by
2038
-** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
2039
-** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
2040
-** DELETE statement run on a view is always zero. Only changes made to real
2041
-** tables are counted.
2042
-**
2043
-** Things are more complicated if the sqlite3_changes() function is
2044
-** executed while a trigger program is running. This may happen if the
2045
-** program uses the [changes() SQL function], or if some other callback
2046
-** function invokes sqlite3_changes() directly. Essentially:
2047
-**
2048
-** <ul>
2049
-** <li> ^(Before entering a trigger program the value returned by
2050
-** sqlite3_changes() function is saved. After the trigger program
2051
-** has finished, the original value is restored.)^
2052
-**
2053
-** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
2054
-** statement sets the value returned by sqlite3_changes()
2055
-** upon completion as normal. Of course, this value will not include
2056
-** any changes performed by sub-triggers, as the sqlite3_changes()
2057
-** value will be saved and restored after each sub-trigger has run.)^
2058
-** </ul>
2059
-**
2060
-** ^This means that if the changes() SQL function (or similar) is used
2061
-** by the first INSERT, UPDATE or DELETE statement within a trigger, it
2062
-** returns the value as set when the calling statement began executing.
2063
-** ^If it is used by the second or subsequent such statement within a trigger
2064
-** program, the value returned reflects the number of rows modified by the
2065
-** previous INSERT, UPDATE or DELETE statement within the same trigger.
2002
+** ^This function returns the number of database rows that were changed
2003
+** or inserted or deleted by the most recently completed SQL statement
2004
+** on the [database connection] specified by the first parameter.
2005
+** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
2006
+** or [DELETE] statement are counted. Auxiliary changes caused by
2007
+** triggers or [foreign key actions] are not counted.)^ Use the
2008
+** [sqlite3_total_changes()] function to find the total number of changes
2009
+** including changes caused by triggers and foreign key actions.
2010
+**
2011
+** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
2012
+** are not counted. Only real table changes are counted.
2013
+**
2014
+** ^(A "row change" is a change to a single row of a single table
2015
+** caused by an INSERT, DELETE, or UPDATE statement. Rows that
2016
+** are changed as side effects of [REPLACE] constraint resolution,
2017
+** rollback, ABORT processing, [DROP TABLE], or by any other
2018
+** mechanisms do not count as direct row changes.)^
2019
+**
2020
+** A "trigger context" is a scope of execution that begins and
2021
+** ends with the script of a [CREATE TRIGGER | trigger].
2022
+** Most SQL statements are
2023
+** evaluated outside of any trigger. This is the "top level"
2024
+** trigger context. If a trigger fires from the top level, a
2025
+** new trigger context is entered for the duration of that one
2026
+** trigger. Subtriggers create subcontexts for their duration.
2027
+**
2028
+** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
2029
+** not create a new trigger context.
2030
+**
2031
+** ^This function returns the number of direct row changes in the
2032
+** most recent INSERT, UPDATE, or DELETE statement within the same
2033
+** trigger context.
2034
+**
2035
+** ^Thus, when called from the top level, this function returns the
2036
+** number of changes in the most recent INSERT, UPDATE, or DELETE
2037
+** that also occurred at the top level. ^(Within the body of a trigger,
2038
+** the sqlite3_changes() interface can be called to find the number of
2039
+** changes in the most recently completed INSERT, UPDATE, or DELETE
2040
+** statement within the body of the same trigger.
2041
+** However, the number returned does not include changes
2042
+** caused by subtriggers since those have their own context.)^
20662043
**
20672044
** See also the [sqlite3_total_changes()] interface, the
20682045
** [count_changes pragma], and the [changes() SQL function].
20692046
**
20702047
** If a separate thread makes changes on the same database connection
@@ -2074,21 +2051,24 @@
20742051
SQLITE_API int sqlite3_changes(sqlite3*);
20752052
20762053
/*
20772054
** CAPI3REF: Total Number Of Rows Modified
20782055
**
2079
-** ^This function returns the total number of rows inserted, modified or
2080
-** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2081
-** since the database connection was opened, including those executed as
2082
-** part of trigger programs. ^Executing any other type of SQL statement
2083
-** does not affect the value returned by sqlite3_total_changes().
2084
-**
2085
-** ^Changes made as part of [foreign key actions] are included in the
2086
-** count, but those made as part of REPLACE constraint resolution are
2087
-** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
2088
-** are not counted.
2089
-**
2056
+** ^This function returns the number of row changes caused by [INSERT],
2057
+** [UPDATE] or [DELETE] statements since the [database connection] was opened.
2058
+** ^(The count returned by sqlite3_total_changes() includes all changes
2059
+** from all [CREATE TRIGGER | trigger] contexts and changes made by
2060
+** [foreign key actions]. However,
2061
+** the count does not include changes used to implement [REPLACE] constraints,
2062
+** do rollbacks or ABORT processing, or [DROP TABLE] processing. The
2063
+** count does not include rows of views that fire an [INSTEAD OF trigger],
2064
+** though if the INSTEAD OF trigger makes changes of its own, those changes
2065
+** are counted.)^
2066
+** ^The sqlite3_total_changes() function counts the changes as soon as
2067
+** the statement that makes them is completed (when the statement handle
2068
+** is passed to [sqlite3_reset()] or [sqlite3_finalize()]).
2069
+**
20902070
** See also the [sqlite3_changes()] interface, the
20912071
** [count_changes pragma], and the [total_changes() SQL function].
20922072
**
20932073
** If a separate thread makes changes on the same database connection
20942074
** while [sqlite3_total_changes()] is running then the value
@@ -2562,18 +2542,17 @@
25622542
** already uses the largest possible [ROWID]. The PRNG is also used for
25632543
** the build-in random() and randomblob() SQL functions. This interface allows
25642544
** applications to access the same PRNG for other purposes.
25652545
**
25662546
** ^A call to this routine stores N bytes of randomness into buffer P.
2567
-** ^The P parameter can be a NULL pointer.
2547
+** ^If N is less than one, then P can be a NULL pointer.
25682548
**
25692549
** ^If this routine has not been previously called or if the previous
2570
-** call had N less than one or a NULL pointer for P, then the PRNG is
2571
-** seeded using randomness obtained from the xRandomness method of
2572
-** the default [sqlite3_vfs] object.
2573
-** ^If the previous call to this routine had an N of 1 or more and a
2574
-** non-NULL P then the pseudo-randomness is generated
2550
+** call had N less than one, then the PRNG is seeded using randomness
2551
+** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2552
+** ^If the previous call to this routine had an N of 1 or more then
2553
+** the pseudo-randomness is generated
25752554
** internally and without recourse to the [sqlite3_vfs] xRandomness
25762555
** method.
25772556
*/
25782557
SQLITE_API void sqlite3_randomness(int N, void *P);
25792558
@@ -5784,46 +5763,30 @@
57845763
**
57855764
** <pre>
57865765
** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
57875766
** </pre>)^
57885767
**
5789
-** ^(Parameter zDb is not the filename that contains the database, but
5790
-** rather the symbolic name of the database. For attached databases, this is
5791
-** the name that appears after the AS keyword in the [ATTACH] statement.
5792
-** For the main database file, the database name is "main". For TEMP
5793
-** tables, the database name is "temp".)^
5794
-**
57955768
** ^If the flags parameter is non-zero, then the BLOB is opened for read
5796
-** and write access. ^If the flags parameter is zero, the BLOB is opened for
5797
-** read-only access.
5798
-**
5799
-** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
5800
-** in *ppBlob. Otherwise an [error code] is returned and, unless the error
5801
-** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
5802
-** the API is not misused, it is always safe to call [sqlite3_blob_close()]
5803
-** on *ppBlob after this function it returns.
5804
-**
5805
-** This function fails with SQLITE_ERROR if any of the following are true:
5806
-** <ul>
5807
-** <li> ^(Database zDb does not exist)^,
5808
-** <li> ^(Table zTable does not exist within database zDb)^,
5809
-** <li> ^(Table zTable is a WITHOUT ROWID table)^,
5810
-** <li> ^(Column zColumn does not exist)^,
5811
-** <li> ^(Row iRow is not present in the table)^,
5812
-** <li> ^(The specified column of row iRow contains a value that is not
5813
-** a TEXT or BLOB value)^,
5814
-** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
5815
-** constraint and the blob is being opened for read/write access)^,
5816
-** <li> ^([foreign key constraints | Foreign key constraints] are enabled,
5817
-** column zColumn is part of a [child key] definition and the blob is
5818
-** being opened for read/write access)^.
5819
-** </ul>
5820
-**
5821
-** ^Unless it returns SQLITE_MISUSE, this function sets the
5822
-** [database connection] error code and message accessible via
5823
-** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
5824
-**
5769
+** and write access. ^If it is zero, the BLOB is opened for read access.
5770
+** ^It is not possible to open a column that is part of an index or primary
5771
+** key for writing. ^If [foreign key constraints] are enabled, it is
5772
+** not possible to open a column that is part of a [child key] for writing.
5773
+**
5774
+** ^Note that the database name is not the filename that contains
5775
+** the database but rather the symbolic name of the database that
5776
+** appears after the AS keyword when the database is connected using [ATTACH].
5777
+** ^For the main database file, the database name is "main".
5778
+** ^For TEMP tables, the database name is "temp".
5779
+**
5780
+** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
5781
+** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set
5782
+** to be a null pointer.)^
5783
+** ^This function sets the [database connection] error code and message
5784
+** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related
5785
+** functions. ^Note that the *ppBlob variable is always initialized in a
5786
+** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob
5787
+** regardless of the success or failure of this routine.
58255788
**
58265789
** ^(If the row that a BLOB handle points to is modified by an
58275790
** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
58285791
** then the BLOB handle is marked as "expired".
58295792
** This is true if any column of the row is changed, even a column
@@ -5837,13 +5800,17 @@
58375800
** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
58385801
** the opened blob. ^The size of a blob may not be changed by this
58395802
** interface. Use the [UPDATE] SQL command to change the size of a
58405803
** blob.
58415804
**
5805
+** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
5806
+** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
5807
+**
58425808
** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5843
-** and the built-in [zeroblob] SQL function may be used to create a
5844
-** zero-filled blob to read or write using the incremental-blob interface.
5809
+** and the built-in [zeroblob] SQL function can be used, if desired,
5810
+** to create an empty, zero-filled blob in which to read or write using
5811
+** this interface.
58455812
**
58465813
** To avoid a resource leak, every open [BLOB handle] should eventually
58475814
** be released by a call to [sqlite3_blob_close()].
58485815
*/
58495816
SQLITE_API int sqlite3_blob_open(
@@ -5881,26 +5848,28 @@
58815848
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
58825849
58835850
/*
58845851
** CAPI3REF: Close A BLOB Handle
58855852
**
5886
-** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
5887
-** unconditionally. Even if this routine returns an error code, the
5888
-** handle is still closed.)^
5889
-**
5890
-** ^If the blob handle being closed was opened for read-write access, and if
5891
-** the database is in auto-commit mode and there are no other open read-write
5892
-** blob handles or active write statements, the current transaction is
5893
-** committed. ^If an error occurs while committing the transaction, an error
5894
-** code is returned and the transaction rolled back.
5895
-**
5896
-** Calling this function with an argument that is not a NULL pointer or an
5897
-** open blob handle results in undefined behaviour. ^Calling this routine
5898
-** with a null pointer (such as would be returned by a failed call to
5899
-** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
5900
-** is passed a valid open blob handle, the values returned by the
5901
-** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
5853
+** ^Closes an open [BLOB handle].
5854
+**
5855
+** ^Closing a BLOB shall cause the current transaction to commit
5856
+** if there are no other BLOBs, no pending prepared statements, and the
5857
+** database connection is in [autocommit mode].
5858
+** ^If any writes were made to the BLOB, they might be held in cache
5859
+** until the close operation if they will fit.
5860
+**
5861
+** ^(Closing the BLOB often forces the changes
5862
+** out to disk and so if any I/O errors occur, they will likely occur
5863
+** at the time when the BLOB is closed. Any errors that occur during
5864
+** closing are reported as a non-zero return value.)^
5865
+**
5866
+** ^(The BLOB is closed unconditionally. Even if this routine returns
5867
+** an error code, the BLOB is still closed.)^
5868
+**
5869
+** ^Calling this routine with a null pointer (such as would be returned
5870
+** by a failed call to [sqlite3_blob_open()]) is a harmless no-op.
59025871
*/
59035872
SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
59045873
59055874
/*
59065875
** CAPI3REF: Return The Size Of An Open BLOB
@@ -5946,39 +5915,36 @@
59465915
SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
59475916
59485917
/*
59495918
** CAPI3REF: Write Data Into A BLOB Incrementally
59505919
**
5951
-** ^(This function is used to write data into an open [BLOB handle] from a
5952
-** caller-supplied buffer. N bytes of data are copied from the buffer Z
5953
-** into the open BLOB, starting at offset iOffset.)^
5954
-**
5955
-** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5956
-** Otherwise, an [error code] or an [extended error code] is returned.)^
5957
-** ^Unless SQLITE_MISUSE is returned, this function sets the
5958
-** [database connection] error code and message accessible via
5959
-** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
5920
+** ^This function is used to write data into an open [BLOB handle] from a
5921
+** caller-supplied buffer. ^N bytes of data are copied from the buffer Z
5922
+** into the open BLOB, starting at offset iOffset.
59605923
**
59615924
** ^If the [BLOB handle] passed as the first argument was not opened for
59625925
** writing (the flags parameter to [sqlite3_blob_open()] was zero),
59635926
** this function returns [SQLITE_READONLY].
59645927
**
5965
-** This function may only modify the contents of the BLOB; it is
5928
+** ^This function may only modify the contents of the BLOB; it is
59665929
** not possible to increase the size of a BLOB using this API.
59675930
** ^If offset iOffset is less than N bytes from the end of the BLOB,
5968
-** [SQLITE_ERROR] is returned and no data is written. The size of the
5969
-** BLOB (and hence the maximum value of N+iOffset) can be determined
5970
-** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
5971
-** than zero [SQLITE_ERROR] is returned and no data is written.
5931
+** [SQLITE_ERROR] is returned and no data is written. ^If N is
5932
+** less than zero [SQLITE_ERROR] is returned and no data is written.
5933
+** The size of the BLOB (and hence the maximum value of N+iOffset)
5934
+** can be determined using the [sqlite3_blob_bytes()] interface.
59725935
**
59735936
** ^An attempt to write to an expired [BLOB handle] fails with an
59745937
** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
59755938
** before the [BLOB handle] expired are not rolled back by the
59765939
** expiration of the handle, though of course those changes might
59775940
** have been overwritten by the statement that expired the BLOB handle
59785941
** or by other independent statements.
59795942
**
5943
+** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5944
+** Otherwise, an [error code] or an [extended error code] is returned.)^
5945
+**
59805946
** This routine only works on a [BLOB handle] which has been created
59815947
** by a prior successful call to [sqlite3_blob_open()] and which has not
59825948
** been closed by [sqlite3_blob_close()]. Passing any other pointer in
59835949
** to this routine results in undefined and probably undesirable behavior.
59845950
**
@@ -7567,102 +7533,10 @@
75677533
/* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
75687534
#define SQLITE_FAIL 3
75697535
/* #define SQLITE_ABORT 4 // Also an error code */
75707536
#define SQLITE_REPLACE 5
75717537
7572
-/*
7573
-** CAPI3REF: Prepared Statement Scan Status Opcodes
7574
-** KEYWORDS: {scanstatus options}
7575
-**
7576
-** The following constants can be used for the T parameter to the
7577
-** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7578
-** different metric for sqlite3_stmt_scanstatus() to return.
7579
-**
7580
-** <dl>
7581
-** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7582
-** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the
7583
-** total number of times that the X-th loop has run.</dd>
7584
-**
7585
-** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
7586
-** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the
7587
-** total number of rows examined by all iterations of the X-th loop.</dd>
7588
-**
7589
-** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
7590
-** <dd>^The "double" variable pointed to by the T parameter will be set to the
7591
-** query planner's estimate for the average number of rows output from each
7592
-** iteration of the X-th loop. If the query planner's estimates was accurate,
7593
-** then this value will approximate the quotient NVISIT/NLOOP and the
7594
-** product of this value for all prior loops with the same SELECTID will
7595
-** be the NLOOP value for the current loop.
7596
-**
7597
-** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
7598
-** <dd>^The "const char *" variable pointed to by the T parameter will be set to
7599
-** a zero-terminated UTF-8 string containing the name of the index or table used
7600
-** for the X-th loop.
7601
-**
7602
-** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
7603
-** <dd>^The "const char *" variable pointed to by the T parameter will be set to
7604
-** a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] description
7605
-** for the X-th loop.
7606
-**
7607
-** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
7608
-** <dd>^The "int" variable pointed to by the T parameter will be set to the
7609
-** "select-id" for the X-th loop. The select-id identifies which query or
7610
-** subquery the loop is part of. The main query has a select-id of zero.
7611
-** The select-id is the same value as is output in the first column
7612
-** of an [EXPLAIN QUERY PLAN] query.
7613
-** </dl>
7614
-*/
7615
-#define SQLITE_SCANSTAT_NLOOP 0
7616
-#define SQLITE_SCANSTAT_NVISIT 1
7617
-#define SQLITE_SCANSTAT_EST 2
7618
-#define SQLITE_SCANSTAT_NAME 3
7619
-#define SQLITE_SCANSTAT_EXPLAIN 4
7620
-#define SQLITE_SCANSTAT_SELECTID 5
7621
-
7622
-/*
7623
-** CAPI3REF: Prepared Statement Scan Status
7624
-**
7625
-** Return status data for a single loop within query pStmt.
7626
-**
7627
-** The "iScanStatusOp" parameter determines which status information to return.
7628
-** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior of
7629
-** this interface is undefined.
7630
-** ^The requested measurement is written into a variable pointed to by
7631
-** the "pOut" parameter.
7632
-** Parameter "idx" identifies the specific loop to retrieve statistics for.
7633
-** Loops are numbered starting from zero. ^If idx is out of range - less than
7634
-** zero or greater than or equal to the total number of loops used to implement
7635
-** the statement - a non-zero value is returned and the variable that pOut
7636
-** points to is unchanged.
7637
-**
7638
-** ^Statistics might not be available for all loops in all statements. ^In cases
7639
-** where there exist loops with no available statistics, this function behaves
7640
-** as if the loop did not exist - it returns non-zero and leave the variable
7641
-** that pOut points to unchanged.
7642
-**
7643
-** This API is only available if the library is built with pre-processor
7644
-** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7645
-**
7646
-** See also: [sqlite3_stmt_scanstatus_reset()]
7647
-*/
7648
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7649
- sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7650
- int idx, /* Index of loop to report on */
7651
- int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
7652
- void *pOut /* Result written here */
7653
-);
7654
-
7655
-/*
7656
-** CAPI3REF: Zero Scan-Status Counters
7657
-**
7658
-** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7659
-**
7660
-** This API is only available if the library is built with pre-processor
7661
-** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7662
-*/
7663
-SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
76647538
76657539
76667540
/*
76677541
** Undo the hack that converts floating point types to integer for
76687542
** builds on processors without floating point support.
@@ -8104,13 +7978,14 @@
81047978
#ifndef SQLITE_POWERSAFE_OVERWRITE
81057979
# define SQLITE_POWERSAFE_OVERWRITE 1
81067980
#endif
81077981
81087982
/*
8109
-** EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by
8110
-** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in
8111
-** which case memory allocation statistics are disabled by default.
7983
+** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
7984
+** It determines whether or not the features related to
7985
+** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can
7986
+** be overridden at runtime using the sqlite3_config() API.
81127987
*/
81137988
#if !defined(SQLITE_DEFAULT_MEMSTATUS)
81147989
# define SQLITE_DEFAULT_MEMSTATUS 1
81157990
#endif
81167991
@@ -8736,11 +8611,11 @@
87368611
** Estimated quantities used for query planning are stored as 16-bit
87378612
** logarithms. For quantity X, the value stored is 10*log2(X). This
87388613
** gives a possible range of values of approximately 1.0e986 to 1e-986.
87398614
** But the allowed values are "grainy". Not every value is representable.
87408615
** For example, quantities 16 and 17 are both represented by a LogEst
8741
-** of 40. However, since LogEst quantities are suppose to be estimates,
8616
+** of 40. However, since LogEst quantaties are suppose to be estimates,
87428617
** not exact values, this imprecision is not a problem.
87438618
**
87448619
** "LogEst" is short for "Logarithmic Estimate".
87458620
**
87468621
** Examples:
@@ -9169,11 +9044,11 @@
91699044
#define BTREE_BLOBKEY 2 /* Table has keys only - no data */
91709045
91719046
SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*);
91729047
SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*);
91739048
SQLITE_PRIVATE int sqlite3BtreeClearTableOfCursor(BtCursor*);
9174
-SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree*, int, int);
9049
+SQLITE_PRIVATE int sqlite3BtreeTripAllCursors(Btree*, int, int);
91759050
91769051
SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue);
91779052
SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
91789053
91799054
SQLITE_PRIVATE int sqlite3BtreeNewDb(Btree *p);
@@ -9249,11 +9124,10 @@
92499124
SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
92509125
SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
92519126
SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
92529127
SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask);
92539128
SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt);
9254
-SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void);
92559129
92569130
#ifndef NDEBUG
92579131
SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
92589132
#endif
92599133
@@ -9792,16 +9666,10 @@
97929666
# define VdbeCoverageAlwaysTaken(v)
97939667
# define VdbeCoverageNeverTaken(v)
97949668
# define VDBE_OFFSET_LINENO(x) 0
97959669
#endif
97969670
9797
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
9798
-SQLITE_PRIVATE void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*);
9799
-#else
9800
-# define sqlite3VdbeScanStatus(a,b,c,d,e)
9801
-#endif
9802
-
98039671
#endif
98049672
98059673
/************** End of vdbe.h ************************************************/
98069674
/************** Continuing where we left off in sqliteInt.h ******************/
98079675
/************** Include pager.h in the middle of sqliteInt.h *****************/
@@ -9994,12 +9862,10 @@
99949862
SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
99959863
99969864
/* Functions used to truncate the database file. */
99979865
SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
99989866
9999
-SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16);
10000
-
100019867
#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL)
100029868
SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *);
100039869
#endif
100049870
100059871
/* Functions to support testing and debugging. */
@@ -10183,14 +10049,10 @@
1018310049
SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*);
1018410050
#endif
1018510051
1018610052
SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
1018710053
10188
-/* Return the header size */
10189
-SQLITE_PRIVATE int sqlite3HeaderSizePcache(void);
10190
-SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void);
10191
-
1019210054
#endif /* _PCACHE_H_ */
1019310055
1019410056
/************** End of pcache.h **********************************************/
1019510057
/************** Continuing where we left off in sqliteInt.h ******************/
1019610058
@@ -10873,11 +10735,11 @@
1087310735
#define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
1087410736
#define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
1087510737
#define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
1087610738
#define SQLITE_Transitive 0x0200 /* Transitive constraints */
1087710739
#define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
10878
-#define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */
10740
+#define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */
1087910741
#define SQLITE_AllOpts 0xffff /* All optimizations */
1088010742
1088110743
/*
1088210744
** Macros for testing whether or not optimizations are enabled or disabled.
1088310745
*/
@@ -11460,12 +11322,11 @@
1146011322
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
1146111323
int nSample; /* Number of elements in aSample[] */
1146211324
int nSampleCol; /* Size of IndexSample.anEq[] and so on */
1146311325
tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
1146411326
IndexSample *aSample; /* Samples of the left-most key */
11465
- tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this index */
11466
- tRowcnt nRowEst0; /* Non-logarithmic number of rows in the index */
11327
+ tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this table */
1146711328
#endif
1146811329
};
1146911330
1147011331
/*
1147111332
** Allowed values for Index.idxType
@@ -11659,11 +11520,11 @@
1165911520
int nHeight; /* Height of the tree headed by this node */
1166011521
#endif
1166111522
int iTable; /* TK_COLUMN: cursor number of table holding column
1166211523
** TK_REGISTER: register number
1166311524
** TK_TRIGGER: 1 -> new, 0 -> old
11664
- ** EP_Unlikely: 134217728 times likelihood */
11525
+ ** EP_Unlikely: 1000 times likelihood */
1166511526
ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
1166611527
** TK_VARIABLE: variable number (always >= 1). */
1166711528
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
1166811529
i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
1166911530
u8 op2; /* TK_REGISTER: original value of Expr.op
@@ -12551,15 +12412,13 @@
1255112412
int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
1255212413
int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
1255312414
void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
1255412415
Parse *pParse; /* Parser context. */
1255512416
int walkerDepth; /* Number of subqueries */
12556
- u8 eCode; /* A small processing code */
1255712417
union { /* Extra data for callback */
1255812418
NameContext *pNC; /* Naming context */
12559
- int n; /* A counter */
12560
- int iCur; /* A cursor number */
12419
+ int i; /* Integer value */
1256112420
SrcList *pSrcList; /* FROM clause */
1256212421
struct SrcCount *pSrcCount; /* Counting column references */
1256312422
} u;
1256412423
};
1256512424
@@ -12956,11 +12815,10 @@
1295612815
SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
1295712816
SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
1295812817
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
1295912818
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
1296012819
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
12961
-SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
1296212820
SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
1296312821
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
1296412822
SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
1296512823
SQLITE_PRIVATE int sqlite3IsRowid(const char*);
1296612824
SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
@@ -13614,23 +13472,15 @@
1361413472
** compatibility for legacy applications, the URI filename capability is
1361513473
** disabled by default.
1361613474
**
1361713475
** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
1361813476
** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
13619
-**
13620
-** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
13621
-** disabled. The default value may be changed by compiling with the
13622
-** SQLITE_USE_URI symbol defined.
1362313477
*/
1362413478
#ifndef SQLITE_USE_URI
1362513479
# define SQLITE_USE_URI 0
1362613480
#endif
1362713481
13628
-/* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
13629
-** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
13630
-** that compile-time option is omitted.
13631
-*/
1363213482
#ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
1363313483
# define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
1363413484
#endif
1363513485
1363613486
/*
@@ -13716,12 +13566,12 @@
1371613566
** than 1 GiB. The sqlite3_test_control() interface can be used to
1371713567
** move the pending byte.
1371813568
**
1371913569
** IMPORTANT: Changing the pending byte to any value other than
1372013570
** 0x40000000 results in an incompatible database file format!
13721
-** Changing the pending byte during operation will result in undefined
13722
-** and incorrect behavior.
13571
+** Changing the pending byte during operating results in undefined
13572
+** and dileterious behavior.
1372313573
*/
1372413574
#ifndef SQLITE_OMIT_WSD
1372513575
SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
1372613576
#endif
1372713577
@@ -13797,13 +13647,10 @@
1379713647
"DISABLE_DIRSYNC",
1379813648
#endif
1379913649
#ifdef SQLITE_DISABLE_LFS
1380013650
"DISABLE_LFS",
1380113651
#endif
13802
-#ifdef SQLITE_ENABLE_API_ARMOR
13803
- "ENABLE_API_ARMOR",
13804
-#endif
1380513652
#ifdef SQLITE_ENABLE_ATOMIC_WRITE
1380613653
"ENABLE_ATOMIC_WRITE",
1380713654
#endif
1380813655
#ifdef SQLITE_ENABLE_CEROD
1380913656
"ENABLE_CEROD",
@@ -14125,17 +13972,10 @@
1412513972
** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
1412613973
** is not required for a match.
1412713974
*/
1412813975
SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
1412913976
int i, n;
14130
-
14131
-#ifdef SQLITE_ENABLE_API_ARMOR
14132
- if( zOptName==0 ){
14133
- (void)SQLITE_MISUSE_BKPT;
14134
- return 0;
14135
- }
14136
-#endif
1413713977
if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7;
1413813978
n = sqlite3Strlen30(zOptName);
1413913979
1414013980
/* Since ArraySize(azCompileOpt) is normally in single digits, a
1414113981
** linear search is adequate. No need for a binary search. */
@@ -14313,11 +14153,10 @@
1431314153
typedef struct VdbeFrame VdbeFrame;
1431414154
struct VdbeFrame {
1431514155
Vdbe *v; /* VM this frame belongs to */
1431614156
VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */
1431714157
Op *aOp; /* Program instructions for parent frame */
14318
- i64 *anExec; /* Event counters from parent frame */
1431914158
Mem *aMem; /* Array of memory cells for parent frame */
1432014159
u8 *aOnceFlag; /* Array of OP_Once flags for parent frame */
1432114160
VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */
1432214161
void *token; /* Copy of SubProgram.token */
1432314162
i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
@@ -14326,12 +14165,11 @@
1432614165
int nOp; /* Size of aOp array */
1432714166
int nMem; /* Number of entries in aMem */
1432814167
int nOnceFlag; /* Number of entries in aOnceFlag */
1432914168
int nChildMem; /* Number of memory cells for child frame */
1433014169
int nChildCsr; /* Number of cursors for child frame */
14331
- int nChange; /* Statement changes (Vdbe.nChange) */
14332
- int nDbChange; /* Value of db->nChange */
14170
+ int nChange; /* Statement changes (Vdbe.nChanges) */
1433314171
};
1433414172
1433514173
#define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
1433614174
1433714175
/*
@@ -14478,20 +14316,10 @@
1447814316
/* A bitfield type for use inside of structures. Always follow with :N where
1447914317
** N is the number of bits.
1448014318
*/
1448114319
typedef unsigned bft; /* Bit Field Type */
1448214320
14483
-typedef struct ScanStatus ScanStatus;
14484
-struct ScanStatus {
14485
- int addrExplain; /* OP_Explain for loop */
14486
- int addrLoop; /* Address of "loops" counter */
14487
- int addrVisit; /* Address of "rows visited" counter */
14488
- int iSelectID; /* The "Select-ID" for this loop */
14489
- LogEst nEst; /* Estimated output rows per loop */
14490
- char *zName; /* Name of table or index */
14491
-};
14492
-
1449314321
/*
1449414322
** An instance of the virtual machine. This structure contains the complete
1449514323
** state of the virtual machine.
1449614324
**
1449714325
** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
@@ -14560,15 +14388,10 @@
1456014388
u32 expmask; /* Binding to these vars invalidates VM */
1456114389
SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
1456214390
int nOnceFlag; /* Size of array aOnceFlag[] */
1456314391
u8 *aOnceFlag; /* Flags for OP_Once */
1456414392
AuxData *pAuxData; /* Linked list of auxdata allocations */
14565
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
14566
- i64 *anExec; /* Number of times each op has been executed */
14567
- int nScan; /* Entries in aScan[] */
14568
- ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
14569
-#endif
1457014393
};
1457114394
1457214395
/*
1457314396
** The following are allowed values for Vdbe.magic
1457414397
*/
@@ -14754,13 +14577,10 @@
1475414577
SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
1475514578
wsdStatInit;
1475614579
if( op<0 || op>=ArraySize(wsdStat.nowValue) ){
1475714580
return SQLITE_MISUSE_BKPT;
1475814581
}
14759
-#ifdef SQLITE_ENABLE_API_ARMOR
14760
- if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
14761
-#endif
1476214582
*pCurrent = wsdStat.nowValue[op];
1476314583
*pHighwater = wsdStat.mxValue[op];
1476414584
if( resetFlag ){
1476514585
wsdStat.mxValue[op] = wsdStat.nowValue[op];
1476614586
}
@@ -14776,15 +14596,10 @@
1477614596
int *pCurrent, /* Write current value here */
1477714597
int *pHighwater, /* Write high-water mark here */
1477814598
int resetFlag /* Reset high-water mark if true */
1477914599
){
1478014600
int rc = SQLITE_OK; /* Return code */
14781
-#ifdef SQLITE_ENABLE_API_ARMOR
14782
- if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){
14783
- return SQLITE_MISUSE_BKPT;
14784
- }
14785
-#endif
1478614601
sqlite3_mutex_enter(db->mutex);
1478714602
switch( op ){
1478814603
case SQLITE_DBSTATUS_LOOKASIDE_USED: {
1478914604
*pCurrent = db->lookaside.nOut;
1479014605
*pHighwater = db->lookaside.mxOut;
@@ -14959,11 +14774,11 @@
1495914774
**
1496014775
** There is only one exported symbol in this file - the function
1496114776
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
1496214777
** All other code has file scope.
1496314778
**
14964
-** SQLite processes all times and dates as julian day numbers. The
14779
+** SQLite processes all times and dates as Julian Day numbers. The
1496514780
** dates and times are stored as the number of days since noon
1496614781
** in Greenwich on November 24, 4714 B.C. according to the Gregorian
1496714782
** calendar system.
1496814783
**
1496914784
** 1970-01-01 00:00:00 is JD 2440587.5
@@ -14974,11 +14789,11 @@
1497414789
** be represented, even though julian day numbers allow a much wider
1497514790
** range of dates.
1497614791
**
1497714792
** The Gregorian calendar system is used for all dates and times,
1497814793
** even those that predate the Gregorian calendar. Historians usually
14979
-** use the julian calendar for dates prior to 1582-10-15 and for some
14794
+** use the Julian calendar for dates prior to 1582-10-15 and for some
1498014795
** dates afterwards, depending on locale. Beware of this difference.
1498114796
**
1498214797
** The conversion algorithms are implemented based on descriptions
1498314798
** in the following text:
1498414799
**
@@ -15246,11 +15061,11 @@
1524615061
return 1;
1524715062
}
1524815063
}
1524915064
1525015065
/*
15251
-** Attempt to parse the given string into a julian day number. Return
15066
+** Attempt to parse the given string into a Julian Day Number. Return
1525215067
** the number of errors.
1525315068
**
1525415069
** The following are acceptable forms for the input string:
1525515070
**
1525615071
** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM
@@ -15817,11 +15632,11 @@
1581715632
**
1581815633
** %d day of month
1581915634
** %f ** fractional seconds SS.SSS
1582015635
** %H hour 00-24
1582115636
** %j day of year 000-366
15822
-** %J ** julian day number
15637
+** %J ** Julian day number
1582315638
** %m month 01-12
1582415639
** %M minute 00-59
1582515640
** %s seconds since 1970-01-01
1582615641
** %S seconds 00-59
1582715642
** %w day of week 0-6 sunday==0
@@ -16442,14 +16257,10 @@
1644216257
MUTEX_LOGIC(sqlite3_mutex *mutex;)
1644316258
#ifndef SQLITE_OMIT_AUTOINIT
1644416259
int rc = sqlite3_initialize();
1644516260
if( rc ) return rc;
1644616261
#endif
16447
-#ifdef SQLITE_ENABLE_API_ARMOR
16448
- if( pVfs==0 ) return SQLITE_MISUSE_BKPT;
16449
-#endif
16450
-
1645116262
MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
1645216263
sqlite3_mutex_enter(mutex);
1645316264
vfsUnlink(pVfs);
1645416265
if( makeDflt || vfsList==0 ){
1645516266
pVfs->pNext = vfsList;
@@ -18803,11 +18614,10 @@
1880318614
** Retrieve a pointer to a static mutex or allocate a new dynamic one.
1880418615
*/
1880518616
SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){
1880618617
#ifndef SQLITE_OMIT_AUTOINIT
1880718618
if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
18808
- if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0;
1880918619
#endif
1881018620
return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
1881118621
}
1881218622
1881318623
SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){
@@ -19260,16 +19070,12 @@
1926019070
pthread_mutex_init(&p->mutex, 0);
1926119071
}
1926219072
break;
1926319073
}
1926419074
default: {
19265
-#ifdef SQLITE_ENABLE_API_ARMOR
19266
- if( iType-2<0 || iType-2>=ArraySize(staticMutexes) ){
19267
- (void)SQLITE_MISUSE_BKPT;
19268
- return 0;
19269
- }
19270
-#endif
19075
+ assert( iType-2 >= 0 );
19076
+ assert( iType-2 < ArraySize(staticMutexes) );
1927119077
p = &staticMutexes[iType-2];
1927219078
#if SQLITE_MUTEX_NREF
1927319079
p->id = iType;
1927419080
#endif
1927519081
break;
@@ -20487,16 +20293,15 @@
2048720293
}
2048820294
assert( sqlite3_mutex_notheld(mem0.mutex) );
2048920295
2049020296
2049120297
#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
20492
- /* EVIDENCE-OF: R-12970-05880 SQLite will not use more than one scratch
20493
- ** buffers per thread.
20494
- **
20495
- ** This can only be checked in single-threaded mode.
20496
- */
20497
- assert( scratchAllocOut==0 );
20298
+ /* Verify that no more than two scratch allocations per thread
20299
+ ** are outstanding at one time. (This is only checked in the
20300
+ ** single-threaded case since checking in the multi-threaded case
20301
+ ** would be much more complicated.) */
20302
+ assert( scratchAllocOut<=1 );
2049820303
if( p ) scratchAllocOut++;
2049920304
#endif
2050020305
2050120306
return p;
2050220307
}
@@ -21151,17 +20956,10 @@
2115120956
etByte flag_rtz; /* True if trailing zeros should be removed */
2115220957
#endif
2115320958
PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
2115420959
char buf[etBUFSIZE]; /* Conversion buffer */
2115520960
21156
-#ifdef SQLITE_ENABLE_API_ARMOR
21157
- if( ap==0 ){
21158
- (void)SQLITE_MISUSE_BKPT;
21159
- sqlite3StrAccumReset(pAccum);
21160
- return;
21161
- }
21162
-#endif
2116320961
bufpt = 0;
2116420962
if( bFlags ){
2116520963
if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
2116620964
pArgList = va_arg(ap, PrintfArguments*);
2116720965
}
@@ -21698,15 +21496,10 @@
2169821496
return N;
2169921497
}else{
2170021498
char *zOld = (p->zText==p->zBase ? 0 : p->zText);
2170121499
i64 szNew = p->nChar;
2170221500
szNew += N + 1;
21703
- if( szNew+p->nChar<=p->mxAlloc ){
21704
- /* Force exponential buffer size growth as long as it does not overflow,
21705
- ** to avoid having to call this routine too often */
21706
- szNew += p->nChar;
21707
- }
2170821501
if( szNew > p->mxAlloc ){
2170921502
sqlite3StrAccumReset(p);
2171021503
setStrAccumError(p, STRACCUM_TOOBIG);
2171121504
return 0;
2171221505
}else{
@@ -21719,11 +21512,10 @@
2171921512
}
2172021513
if( zNew ){
2172121514
assert( p->zText!=0 || p->nChar==0 );
2172221515
if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
2172321516
p->zText = zNew;
21724
- p->nAlloc = sqlite3DbMallocSize(p->db, zNew);
2172521517
}else{
2172621518
sqlite3StrAccumReset(p);
2172721519
setStrAccumError(p, STRACCUM_NOMEM);
2172821520
return 0;
2172921521
}
@@ -21889,17 +21681,10 @@
2188921681
*/
2189021682
SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){
2189121683
char *z;
2189221684
char zBase[SQLITE_PRINT_BUF_SIZE];
2189321685
StrAccum acc;
21894
-
21895
-#ifdef SQLITE_ENABLE_API_ARMOR
21896
- if( zFormat==0 ){
21897
- (void)SQLITE_MISUSE_BKPT;
21898
- return 0;
21899
- }
21900
-#endif
2190121686
#ifndef SQLITE_OMIT_AUTOINIT
2190221687
if( sqlite3_initialize() ) return 0;
2190321688
#endif
2190421689
sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
2190521690
acc.useMalloc = 2;
@@ -21938,17 +21723,10 @@
2193821723
** sqlite3_vsnprintf() is the varargs version.
2193921724
*/
2194021725
SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
2194121726
StrAccum acc;
2194221727
if( n<=0 ) return zBuf;
21943
-#ifdef SQLITE_ENABLE_API_ARMOR
21944
- if( zBuf==0 || zFormat==0 ) {
21945
- (void)SQLITE_MISUSE_BKPT;
21946
- if( zBuf && n>0 ) zBuf[0] = 0;
21947
- return zBuf;
21948
- }
21949
-#endif
2195021728
sqlite3StrAccumInit(&acc, zBuf, n, 0);
2195121729
acc.useMalloc = 0;
2195221730
sqlite3VXPrintf(&acc, 0, zFormat, ap);
2195321731
return sqlite3StrAccumFinish(&acc);
2195421732
}
@@ -22136,23 +21914,15 @@
2213621914
#else
2213721915
# define wsdPrng sqlite3Prng
2213821916
#endif
2213921917
2214021918
#if SQLITE_THREADSAFE
22141
- sqlite3_mutex *mutex;
22142
-#endif
22143
-
22144
-#ifndef SQLITE_OMIT_AUTOINIT
22145
- if( sqlite3_initialize() ) return;
22146
-#endif
22147
-
22148
-#if SQLITE_THREADSAFE
22149
- mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
22150
-#endif
22151
-
21919
+ sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
2215221920
sqlite3_mutex_enter(mutex);
22153
- if( N<=0 || pBuf==0 ){
21921
+#endif
21922
+
21923
+ if( N<=0 ){
2215421924
wsdPrng.isInit = 0;
2215521925
sqlite3_mutex_leave(mutex);
2215621926
return;
2215721927
}
2215821928
@@ -23270,27 +23040,17 @@
2327023040
** case-independent fashion, using the same definition of "case
2327123041
** independence" that SQLite uses internally when comparing identifiers.
2327223042
*/
2327323043
SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){
2327423044
register unsigned char *a, *b;
23275
- if( zLeft==0 ){
23276
- return zRight ? -1 : 0;
23277
- }else if( zRight==0 ){
23278
- return 1;
23279
- }
2328023045
a = (unsigned char *)zLeft;
2328123046
b = (unsigned char *)zRight;
2328223047
while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
2328323048
return UpperToLower[*a] - UpperToLower[*b];
2328423049
}
2328523050
SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
2328623051
register unsigned char *a, *b;
23287
- if( zLeft==0 ){
23288
- return zRight ? -1 : 0;
23289
- }else if( zRight==0 ){
23290
- return 1;
23291
- }
2329223052
a = (unsigned char *)zLeft;
2329323053
b = (unsigned char *)zRight;
2329423054
while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
2329523055
return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
2329623056
}
@@ -32819,15 +32579,10 @@
3281932579
#if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL)
3282032580
# error "WAL mode requires support from the Windows NT kernel, compile\
3282132581
with SQLITE_OMIT_WAL."
3282232582
#endif
3282332583
32824
-#if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0
32825
-# error "Memory mapped files require support from the Windows NT kernel,\
32826
- compile with SQLITE_MAX_MMAP_SIZE=0."
32827
-#endif
32828
-
3282932584
/*
3283032585
** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions
3283132586
** based on the sub-platform)?
3283232587
*/
3283332588
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI)
@@ -32953,15 +32708,14 @@
3295332708
# define winGetDirSep() '\\'
3295432709
#endif
3295532710
3295632711
/*
3295732712
** Do we need to manually define the Win32 file mapping APIs for use with WAL
32958
-** mode or memory mapped files (e.g. these APIs are available in the Windows
32959
-** CE SDK; however, they are not present in the header file)?
32713
+** mode (e.g. these APIs are available in the Windows CE SDK; however, they
32714
+** are not present in the header file)?
3296032715
*/
32961
-#if SQLITE_WIN32_FILEMAPPING_API && \
32962
- (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
32716
+#if SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL)
3296332717
/*
3296432718
** Two of the file mapping APIs are different under WinRT. Figure out which
3296532719
** set we need.
3296632720
*/
3296732721
#if SQLITE_OS_WINRT
@@ -32985,11 +32739,11 @@
3298532739
3298632740
/*
3298732741
** This file mapping API is common to both Win32 and WinRT.
3298832742
*/
3298932743
WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID);
32990
-#endif /* SQLITE_WIN32_FILEMAPPING_API */
32744
+#endif /* SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL) */
3299132745
3299232746
/*
3299332747
** Some Microsoft compilers lack this definition.
3299432748
*/
3299532749
#ifndef INVALID_FILE_ATTRIBUTES
@@ -33278,21 +33032,21 @@
3327833032
3327933033
#define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
3328033034
LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
3328133035
3328233036
#if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \
33283
- (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
33037
+ !defined(SQLITE_OMIT_WAL))
3328433038
{ "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
3328533039
#else
3328633040
{ "CreateFileMappingA", (SYSCALL)0, 0 },
3328733041
#endif
3328833042
3328933043
#define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
3329033044
DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent)
3329133045
3329233046
#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
33293
- (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
33047
+ !defined(SQLITE_OMIT_WAL))
3329433048
{ "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
3329533049
#else
3329633050
{ "CreateFileMappingW", (SYSCALL)0, 0 },
3329733051
#endif
3329833052
@@ -33628,12 +33382,11 @@
3362833382
#ifndef osLockFileEx
3362933383
#define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
3363033384
LPOVERLAPPED))aSyscall[48].pCurrent)
3363133385
#endif
3363233386
33633
-#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && \
33634
- (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
33387
+#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
3363533388
{ "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
3363633389
#else
3363733390
{ "MapViewOfFile", (SYSCALL)0, 0 },
3363833391
#endif
3363933392
@@ -33699,11 +33452,11 @@
3369933452
#endif
3370033453
3370133454
#define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
3370233455
LPOVERLAPPED))aSyscall[58].pCurrent)
3370333456
33704
-#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
33457
+#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
3370533458
{ "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
3370633459
#else
3370733460
{ "UnmapViewOfFile", (SYSCALL)0, 0 },
3370833461
#endif
3370933462
@@ -33762,11 +33515,11 @@
3376233515
#endif
3376333516
3376433517
#define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
3376533518
FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent)
3376633519
33767
-#if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
33520
+#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
3376833521
{ "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
3376933522
#else
3377033523
{ "MapViewOfFileFromApp", (SYSCALL)0, 0 },
3377133524
#endif
3377233525
@@ -33826,11 +33579,11 @@
3382633579
3382733580
{ "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
3382833581
3382933582
#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent)
3383033583
33831
-#if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
33584
+#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
3383233585
{ "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
3383333586
#else
3383433587
{ "CreateFileMappingFromApp", (SYSCALL)0, 0 },
3383533588
#endif
3383633589
@@ -39402,17 +39155,10 @@
3940239155
*/
3940339156
SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
3940439157
assert( pCache->pCache!=0 );
3940539158
sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
3940639159
}
39407
-
39408
-/*
39409
-** Return the size of the header added by this middleware layer
39410
-** in the page-cache hierarchy.
39411
-*/
39412
-SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); }
39413
-
3941439160
3941539161
#if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
3941639162
/*
3941739163
** For all dirty pages currently in the cache, invoke the specified
3941839164
** callback. This is only used if the SQLITE_CHECK_PAGES macro is
@@ -40408,15 +40154,10 @@
4040840154
pcache1Shrink /* xShrink */
4040940155
};
4041040156
sqlite3_config(SQLITE_CONFIG_PCACHE2, &defaultMethods);
4041140157
}
4041240158
40413
-/*
40414
-** Return the size of the header on each page of this PCACHE implementation.
40415
-*/
40416
-SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); }
40417
-
4041840159
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
4041940160
/*
4042040161
** This function is called to free superfluous dynamically allocated memory
4042140162
** held by the pager system. Memory in use by any SQLite pager allocated
4042240163
** by the current thread may be sqlite3_free()ed.
@@ -47970,22 +47711,10 @@
4797047711
4797147712
return SQLITE_OK;
4797247713
}
4797347714
#endif
4797447715
47975
-/*
47976
-** The page handle passed as the first argument refers to a dirty page
47977
-** with a page number other than iNew. This function changes the page's
47978
-** page number to iNew and sets the value of the PgHdr.flags field to
47979
-** the value passed as the third parameter.
47980
-*/
47981
-SQLITE_PRIVATE void sqlite3PagerRekey(DbPage *pPg, Pgno iNew, u16 flags){
47982
- assert( pPg->pgno!=iNew );
47983
- pPg->flags = flags;
47984
- sqlite3PcacheMove(pPg, iNew);
47985
-}
47986
-
4798747716
/*
4798847717
** Return a pointer to the data for the specified page.
4798947718
*/
4799047719
SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *pPg){
4799147720
assert( pPg->nRef>0 || pPg->pPager->memDb );
@@ -48379,11 +48108,10 @@
4837948108
SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){
4838048109
assert( pPager->eState>=PAGER_READER );
4838148110
return sqlite3WalFramesize(pPager->pWal);
4838248111
}
4838348112
#endif
48384
-
4838548113
4838648114
#endif /* SQLITE_OMIT_DISKIO */
4838748115
4838848116
/************** End of pager.c ***********************************************/
4838948117
/************** Begin file wal.c *********************************************/
@@ -49890,11 +49618,11 @@
4989049618
4989149619
/*
4989249620
** Free an iterator allocated by walIteratorInit().
4989349621
*/
4989449622
static void walIteratorFree(WalIterator *p){
49895
- sqlite3_free(p);
49623
+ sqlite3ScratchFree(p);
4989649624
}
4989749625
4989849626
/*
4989949627
** Construct a WalInterator object that can be used to loop over all
4990049628
** pages in the WAL in ascending order. The caller must hold the checkpoint
@@ -49925,21 +49653,21 @@
4992549653
/* Allocate space for the WalIterator object. */
4992649654
nSegment = walFramePage(iLast) + 1;
4992749655
nByte = sizeof(WalIterator)
4992849656
+ (nSegment-1)*sizeof(struct WalSegment)
4992949657
+ iLast*sizeof(ht_slot);
49930
- p = (WalIterator *)sqlite3_malloc(nByte);
49658
+ p = (WalIterator *)sqlite3ScratchMalloc(nByte);
4993149659
if( !p ){
4993249660
return SQLITE_NOMEM;
4993349661
}
4993449662
memset(p, 0, nByte);
4993549663
p->nSegment = nSegment;
4993649664
4993749665
/* Allocate temporary space used by the merge-sort routine. This block
4993849666
** of memory will be freed before this function returns.
4993949667
*/
49940
- aTmp = (ht_slot *)sqlite3_malloc(
49668
+ aTmp = (ht_slot *)sqlite3ScratchMalloc(
4994149669
sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
4994249670
);
4994349671
if( !aTmp ){
4994449672
rc = SQLITE_NOMEM;
4994549673
}
@@ -49972,11 +49700,11 @@
4997249700
p->aSegment[i].nEntry = nEntry;
4997349701
p->aSegment[i].aIndex = aIndex;
4997449702
p->aSegment[i].aPgno = (u32 *)aPgno;
4997549703
}
4997649704
}
49977
- sqlite3_free(aTmp);
49705
+ sqlite3ScratchFree(aTmp);
4997849706
4997949707
if( rc!=SQLITE_OK ){
4998049708
walIteratorFree(p);
4998149709
}
4998249710
*pp = p;
@@ -50892,11 +50620,11 @@
5089250620
** was in before the client began writing to the database.
5089350621
*/
5089450622
memcpy(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr));
5089550623
5089650624
for(iFrame=pWal->hdr.mxFrame+1;
50897
- rc==SQLITE_OK && iFrame<=iMax;
50625
+ ALWAYS(rc==SQLITE_OK) && iFrame<=iMax;
5089850626
iFrame++
5089950627
){
5090050628
/* This call cannot fail. Unless the page for which the page number
5090150629
** is passed as the second argument is (a) in the cache and
5090250630
** (b) has an outstanding reference, then xUndo is either a no-op
@@ -51989,10 +51717,15 @@
5198951717
** but cursors cannot be shared. Each cursor is associated with a
5199051718
** particular database connection identified BtCursor.pBtree.db.
5199151719
**
5199251720
** Fields in this structure are accessed under the BtShared.mutex
5199351721
** found at self->pBt->mutex.
51722
+**
51723
+** skipNext meaning:
51724
+** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op.
51725
+** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op.
51726
+** eState==FAULT: Cursor fault with skipNext as error code.
5199451727
*/
5199551728
struct BtCursor {
5199651729
Btree *pBtree; /* The Btree to which this cursor belongs */
5199751730
BtShared *pBt; /* The BtShared this cursor points to */
5199851731
BtCursor *pNext, *pPrev; /* Forms a linked list of all cursors */
@@ -52001,11 +51734,12 @@
5200151734
CellInfo info; /* A parse of the cell we are pointing at */
5200251735
i64 nKey; /* Size of pKey, or last integer key */
5200351736
void *pKey; /* Saved key that was cursor last known position */
5200451737
Pgno pgnoRoot; /* The root page of this tree */
5200551738
int nOvflAlloc; /* Allocated size of aOverflow[] array */
52006
- int skipNext; /* Prev() is noop if negative. Next() is noop if positive */
51739
+ int skipNext; /* Prev() is noop if negative. Next() is noop if positive.
51740
+ ** Error code if eState==CURSOR_FAULT */
5200751741
u8 curFlags; /* zero or more BTCF_* flags defined below */
5200851742
u8 eState; /* One of the CURSOR_XXX constants (see below) */
5200951743
u8 hints; /* As configured by CursorSetHints() */
5201051744
i16 iPage; /* Index of current page in apPage */
5201151745
u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
@@ -52047,11 +51781,11 @@
5204751781
** CURSOR_FAULT:
5204851782
** An unrecoverable error (an I/O error or a malloc failure) has occurred
5204951783
** on a different connection that shares the BtShared cache with this
5205051784
** cursor. The error has left the cache in an inconsistent state.
5205151785
** Do nothing else with this cursor. Any attempt to use the cursor
52052
-** should return the error code stored in BtCursor.skip
51786
+** should return the error code stored in BtCursor.skipNext
5205351787
*/
5205451788
#define CURSOR_INVALID 0
5205551789
#define CURSOR_VALID 1
5205651790
#define CURSOR_SKIPNEXT 2
5205751791
#define CURSOR_REQUIRESEEK 3
@@ -53609,27 +53343,28 @@
5360953343
int cellOffset; /* Offset to the cell pointer array */
5361053344
int cbrk; /* Offset to the cell content area */
5361153345
int nCell; /* Number of cells on the page */
5361253346
unsigned char *data; /* The page data */
5361353347
unsigned char *temp; /* Temp area for cell content */
53614
- unsigned char *src; /* Source of content */
5361553348
int iCellFirst; /* First allowable cell index */
5361653349
int iCellLast; /* Last possible cell index */
5361753350
5361853351
5361953352
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
5362053353
assert( pPage->pBt!=0 );
5362153354
assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
5362253355
assert( pPage->nOverflow==0 );
5362353356
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53624
- temp = 0;
53625
- src = data = pPage->aData;
53357
+ temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
53358
+ data = pPage->aData;
5362653359
hdr = pPage->hdrOffset;
5362753360
cellOffset = pPage->cellOffset;
5362853361
nCell = pPage->nCell;
5362953362
assert( nCell==get2byte(&data[hdr+3]) );
5363053363
usableSize = pPage->pBt->usableSize;
53364
+ cbrk = get2byte(&data[hdr+5]);
53365
+ memcpy(&temp[cbrk], &data[cbrk], usableSize - cbrk);
5363153366
cbrk = usableSize;
5363253367
iCellFirst = cellOffset + 2*nCell;
5363353368
iCellLast = usableSize - 4;
5363453369
for(i=0; i<nCell; i++){
5363553370
u8 *pAddr; /* The i-th cell pointer */
@@ -53644,11 +53379,11 @@
5364453379
if( pc<iCellFirst || pc>iCellLast ){
5364553380
return SQLITE_CORRUPT_BKPT;
5364653381
}
5364753382
#endif
5364853383
assert( pc>=iCellFirst && pc<=iCellLast );
53649
- size = cellSizePtr(pPage, &src[pc]);
53384
+ size = cellSizePtr(pPage, &temp[pc]);
5365053385
cbrk -= size;
5365153386
#if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
5365253387
if( cbrk<iCellFirst ){
5365353388
return SQLITE_CORRUPT_BKPT;
5365453389
}
@@ -53658,20 +53393,12 @@
5365853393
}
5365953394
#endif
5366053395
assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
5366153396
testcase( cbrk+size==usableSize );
5366253397
testcase( pc+size==usableSize );
53398
+ memcpy(&data[cbrk], &temp[pc], size);
5366353399
put2byte(pAddr, cbrk);
53664
- if( temp==0 ){
53665
- int x;
53666
- if( cbrk==pc ) continue;
53667
- temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
53668
- x = get2byte(&data[hdr+5]);
53669
- memcpy(&temp[x], &data[x], (cbrk+size) - x);
53670
- src = temp;
53671
- }
53672
- memcpy(&data[cbrk], &src[pc], size);
5367353400
}
5367453401
assert( cbrk>=iCellFirst );
5367553402
put2byte(&data[hdr+5], cbrk);
5367653403
data[hdr+1] = 0;
5367753404
data[hdr+2] = 0;
@@ -53682,66 +53409,10 @@
5368253409
return SQLITE_CORRUPT_BKPT;
5368353410
}
5368453411
return SQLITE_OK;
5368553412
}
5368653413
53687
-/*
53688
-** Search the free-list on page pPg for space to store a cell nByte bytes in
53689
-** size. If one can be found, return a pointer to the space and remove it
53690
-** from the free-list.
53691
-**
53692
-** If no suitable space can be found on the free-list, return NULL.
53693
-**
53694
-** This function may detect corruption within pPg. If corruption is
53695
-** detected then *pRc is set to SQLITE_CORRUPT and NULL is returned.
53696
-**
53697
-** If a slot of at least nByte bytes is found but cannot be used because
53698
-** there are already at least 60 fragmented bytes on the page, return NULL.
53699
-** In this case, if pbDefrag parameter is not NULL, set *pbDefrag to true.
53700
-*/
53701
-static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc, int *pbDefrag){
53702
- const int hdr = pPg->hdrOffset;
53703
- u8 * const aData = pPg->aData;
53704
- int iAddr;
53705
- int pc;
53706
- int usableSize = pPg->pBt->usableSize;
53707
-
53708
- for(iAddr=hdr+1; (pc = get2byte(&aData[iAddr]))>0; iAddr=pc){
53709
- int size; /* Size of the free slot */
53710
- if( pc>usableSize-4 || pc<iAddr+4 ){
53711
- *pRc = SQLITE_CORRUPT_BKPT;
53712
- return 0;
53713
- }
53714
- size = get2byte(&aData[pc+2]);
53715
- if( size>=nByte ){
53716
- int x = size - nByte;
53717
- testcase( x==4 );
53718
- testcase( x==3 );
53719
- if( x<4 ){
53720
- if( aData[hdr+7]>=60 ){
53721
- if( pbDefrag ) *pbDefrag = 1;
53722
- return 0;
53723
- }
53724
- /* Remove the slot from the free-list. Update the number of
53725
- ** fragmented bytes within the page. */
53726
- memcpy(&aData[iAddr], &aData[pc], 2);
53727
- aData[hdr+7] += (u8)x;
53728
- }else if( size+pc > usableSize ){
53729
- *pRc = SQLITE_CORRUPT_BKPT;
53730
- return 0;
53731
- }else{
53732
- /* The slot remains on the free-list. Reduce its size to account
53733
- ** for the portion used by the new allocation. */
53734
- put2byte(&aData[pc+2], x);
53735
- }
53736
- return &aData[pc + x];
53737
- }
53738
- }
53739
-
53740
- return 0;
53741
-}
53742
-
5374353414
/*
5374453415
** Allocate nByte bytes of space from within the B-Tree page passed
5374553416
** as the first argument. Write into *pIdx the index into pPage->aData[]
5374653417
** of the first byte of allocated space. Return either SQLITE_OK or
5374753418
** an error code (usually SQLITE_CORRUPT).
@@ -53755,20 +53426,22 @@
5375553426
*/
5375653427
static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
5375753428
const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */
5375853429
u8 * const data = pPage->aData; /* Local cache of pPage->aData */
5375953430
int top; /* First byte of cell content area */
53760
- int rc = SQLITE_OK; /* Integer return code */
5376153431
int gap; /* First byte of gap between cell pointers and cell content */
53432
+ int rc; /* Integer return code */
53433
+ int usableSize; /* Usable size of the page */
5376253434
5376353435
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
5376453436
assert( pPage->pBt );
5376553437
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
5376653438
assert( nByte>=0 ); /* Minimum cell size is 4 */
5376753439
assert( pPage->nFree>=nByte );
5376853440
assert( pPage->nOverflow==0 );
53769
- assert( nByte < (int)(pPage->pBt->usableSize-8) );
53441
+ usableSize = pPage->pBt->usableSize;
53442
+ assert( nByte < usableSize-8 );
5377053443
5377153444
assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf );
5377253445
gap = pPage->cellOffset + 2*pPage->nCell;
5377353446
assert( gap<=65536 );
5377453447
top = get2byte(&data[hdr+5]);
@@ -53786,27 +53459,46 @@
5378653459
*/
5378753460
testcase( gap+2==top );
5378853461
testcase( gap+1==top );
5378953462
testcase( gap==top );
5379053463
if( gap+2<=top && (data[hdr+1] || data[hdr+2]) ){
53791
- int bDefrag = 0;
53792
- u8 *pSpace = pageFindSlot(pPage, nByte, &rc, &bDefrag);
53793
- if( rc ) return rc;
53794
- if( bDefrag ) goto defragment_page;
53795
- if( pSpace ){
53796
- assert( pSpace>=data && (pSpace - data)<65536 );
53797
- *pIdx = (int)(pSpace - data);
53798
- return SQLITE_OK;
53464
+ int pc, addr;
53465
+ for(addr=hdr+1; (pc = get2byte(&data[addr]))>0; addr=pc){
53466
+ int size; /* Size of the free slot */
53467
+ if( pc>usableSize-4 || pc<addr+4 ){
53468
+ return SQLITE_CORRUPT_BKPT;
53469
+ }
53470
+ size = get2byte(&data[pc+2]);
53471
+ if( size>=nByte ){
53472
+ int x = size - nByte;
53473
+ testcase( x==4 );
53474
+ testcase( x==3 );
53475
+ if( x<4 ){
53476
+ if( data[hdr+7]>=60 ) goto defragment_page;
53477
+ /* Remove the slot from the free-list. Update the number of
53478
+ ** fragmented bytes within the page. */
53479
+ memcpy(&data[addr], &data[pc], 2);
53480
+ data[hdr+7] += (u8)x;
53481
+ }else if( size+pc > usableSize ){
53482
+ return SQLITE_CORRUPT_BKPT;
53483
+ }else{
53484
+ /* The slot remains on the free-list. Reduce its size to account
53485
+ ** for the portion used by the new allocation. */
53486
+ put2byte(&data[pc+2], x);
53487
+ }
53488
+ *pIdx = pc + x;
53489
+ return SQLITE_OK;
53490
+ }
5379953491
}
5380053492
}
5380153493
5380253494
/* The request could not be fulfilled using a freelist slot. Check
5380353495
** to see if defragmentation is necessary.
5380453496
*/
5380553497
testcase( gap+2+nByte==top );
5380653498
if( gap+2+nByte>top ){
53807
- defragment_page:
53499
+defragment_page:
5380853500
testcase( pPage->nCell==0 );
5380953501
rc = defragmentPage(pPage);
5381053502
if( rc ) return rc;
5381153503
top = get2byteNotZero(&data[hdr+5]);
5381253504
assert( gap+nByte<=top );
@@ -53850,11 +53542,11 @@
5385053542
unsigned char *data = pPage->aData; /* Page content */
5385153543
5385253544
assert( pPage->pBt!=0 );
5385353545
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
5385453546
assert( iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
53855
- assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize );
53547
+ assert( iEnd <= pPage->pBt->usableSize );
5385653548
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
5385753549
assert( iSize>=4 ); /* Minimum cell size is 4 */
5385853550
assert( iStart<=iLast );
5385953551
5386053552
/* Overwrite deleted information with zeros when the secure_delete
@@ -55972,33 +55664,56 @@
5597255664
**
5597355665
** Every cursor is a candidate to be tripped, including cursors
5597455666
** that belong to other database connections that happen to be
5597555667
** sharing the cache with pBtree.
5597655668
**
55977
-** This routine gets called when a rollback occurs. The writeOnly
55978
-** flag is set to 1 if the transaction did not make any schema
55979
-** changes, in which case the read cursors can continue operating.
55980
-** If schema changes did occur in the transaction, then both read
55981
-** and write cursors must both be tripped.
55669
+** This routine gets called when a rollback occurs. If the writeOnly
55670
+** flag is true, then only write-cursors need be tripped - read-only
55671
+** cursors save their current positions so that they may continue
55672
+** following the rollback. Or, if writeOnly is false, all cursors are
55673
+** tripped. In general, writeOnly is false if the transaction being
55674
+** rolled back modified the database schema. In this case b-tree root
55675
+** pages may be moved or deleted from the database altogether, making
55676
+** it unsafe for read cursors to continue.
55677
+**
55678
+** If the writeOnly flag is true and an error is encountered while
55679
+** saving the current position of a read-only cursor, all cursors,
55680
+** including all read-cursors are tripped.
55681
+**
55682
+** SQLITE_OK is returned if successful, or if an error occurs while
55683
+** saving a cursor position, an SQLite error code.
5598255684
*/
55983
-SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode, int writeOnly){
55685
+SQLITE_PRIVATE int sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode, int writeOnly){
5598455686
BtCursor *p;
55687
+ int rc = SQLITE_OK;
55688
+
5598555689
assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 );
55986
- if( pBtree==0 ) return;
55987
- sqlite3BtreeEnter(pBtree);
55988
- for(p=pBtree->pBt->pCursor; p; p=p->pNext){
55989
- int i;
55990
- if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ) continue;
55991
- sqlite3BtreeClearCursor(p);
55992
- p->eState = CURSOR_FAULT;
55993
- p->skipNext = errCode;
55994
- for(i=0; i<=p->iPage; i++){
55995
- releasePage(p->apPage[i]);
55996
- p->apPage[i] = 0;
55997
- }
55998
- }
55999
- sqlite3BtreeLeave(pBtree);
55690
+ if( pBtree ){
55691
+ sqlite3BtreeEnter(pBtree);
55692
+ for(p=pBtree->pBt->pCursor; p; p=p->pNext){
55693
+ int i;
55694
+ if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){
55695
+ if( p->eState==CURSOR_VALID ){
55696
+ rc = saveCursorPosition(p);
55697
+ if( rc!=SQLITE_OK ){
55698
+ (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0);
55699
+ break;
55700
+ }
55701
+ }
55702
+ }else{
55703
+ sqlite3BtreeClearCursor(p);
55704
+ p->eState = CURSOR_FAULT;
55705
+ p->skipNext = errCode;
55706
+ }
55707
+ for(i=0; i<=p->iPage; i++){
55708
+ releasePage(p->apPage[i]);
55709
+ p->apPage[i] = 0;
55710
+ }
55711
+ }
55712
+ sqlite3BtreeLeave(pBtree);
55713
+ }
55714
+ return rc;
5600055715
}
5600155716
5600255717
/*
5600355718
** Rollback the transaction in progress.
5600455719
**
@@ -56023,11 +55738,13 @@
5602355738
if( rc ) writeOnly = 0;
5602455739
}else{
5602555740
rc = SQLITE_OK;
5602655741
}
5602755742
if( tripCode ){
56028
- sqlite3BtreeTripAllCursors(p, tripCode, writeOnly);
55743
+ int rc2 = sqlite3BtreeTripAllCursors(p, tripCode, writeOnly);
55744
+ assert( rc==SQLITE_OK || (writeOnly==0 && rc2==SQLITE_OK) );
55745
+ if( rc2!=SQLITE_OK ) rc = rc2;
5602955746
}
5603055747
btreeIntegrity(p);
5603155748
5603255749
if( p->inTrans==TRANS_WRITE ){
5603355750
int rc2;
@@ -56358,17 +56075,13 @@
5635856075
**
5635956076
** This routine cannot fail. It always returns SQLITE_OK.
5636056077
*/
5636156078
SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){
5636256079
assert( cursorHoldsMutex(pCur) );
56363
- assert( pCur->eState==CURSOR_INVALID || pCur->eState==CURSOR_VALID );
56364
- if( pCur->eState!=CURSOR_VALID ){
56365
- *pSize = 0;
56366
- }else{
56367
- getCellInfo(pCur);
56368
- *pSize = pCur->info.nKey;
56369
- }
56080
+ assert( pCur->eState==CURSOR_VALID );
56081
+ getCellInfo(pCur);
56082
+ *pSize = pCur->info.nKey;
5637056083
return SQLITE_OK;
5637156084
}
5637256085
5637356086
/*
5637456087
** Set *pSize to the number of bytes of data in the entry the
@@ -58444,266 +58157,49 @@
5844458157
#endif
5844558158
}
5844658159
}
5844758160
5844858161
/*
58449
-** Array apCell[] contains pointers to nCell b-tree page cells. The
58450
-** szCell[] array contains the size in bytes of each cell. This function
58451
-** replaces the current contents of page pPg with the contents of the cell
58452
-** array.
58453
-**
58454
-** Some of the cells in apCell[] may currently be stored in pPg. This
58455
-** function works around problems caused by this by making a copy of any
58456
-** such cells before overwriting the page data.
58457
-**
58458
-** The MemPage.nFree field is invalidated by this function. It is the
58459
-** responsibility of the caller to set it correctly.
58460
-*/
58461
-static void rebuildPage(
58462
- MemPage *pPg, /* Edit this page */
58463
- int nCell, /* Final number of cells on page */
58464
- u8 **apCell, /* Array of cells */
58465
- u16 *szCell /* Array of cell sizes */
58466
-){
58467
- const int hdr = pPg->hdrOffset; /* Offset of header on pPg */
58468
- u8 * const aData = pPg->aData; /* Pointer to data for pPg */
58469
- const int usableSize = pPg->pBt->usableSize;
58470
- u8 * const pEnd = &aData[usableSize];
58471
- int i;
58472
- u8 *pCellptr = pPg->aCellIdx;
58473
- u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
58474
- u8 *pData;
58475
-
58476
- i = get2byte(&aData[hdr+5]);
58477
- memcpy(&pTmp[i], &aData[i], usableSize - i);
58478
-
58479
- pData = pEnd;
58480
- for(i=0; i<nCell; i++){
58481
- u8 *pCell = apCell[i];
58482
- if( pCell>aData && pCell<pEnd ){
58483
- pCell = &pTmp[pCell - aData];
58484
- }
58485
- pData -= szCell[i];
58486
- memcpy(pData, pCell, szCell[i]);
58487
- put2byte(pCellptr, (pData - aData));
58488
- pCellptr += 2;
58489
- assert( szCell[i]==cellSizePtr(pPg, pCell) );
58490
- }
58491
-
58492
- /* The pPg->nFree field is now set incorrectly. The caller will fix it. */
58493
- pPg->nCell = nCell;
58494
- pPg->nOverflow = 0;
58495
-
58496
- put2byte(&aData[hdr+1], 0);
58497
- put2byte(&aData[hdr+3], pPg->nCell);
58498
- put2byte(&aData[hdr+5], pData - aData);
58499
- aData[hdr+7] = 0x00;
58500
-}
58501
-
58502
-/*
58503
-** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
58504
-** contains the size in bytes of each such cell. This function attempts to
58505
-** add the cells stored in the array to page pPg. If it cannot (because
58506
-** the page needs to be defragmented before the cells will fit), non-zero
58507
-** is returned. Otherwise, if the cells are added successfully, zero is
58508
-** returned.
58509
-**
58510
-** Argument pCellptr points to the first entry in the cell-pointer array
58511
-** (part of page pPg) to populate. After cell apCell[0] is written to the
58512
-** page body, a 16-bit offset is written to pCellptr. And so on, for each
58513
-** cell in the array. It is the responsibility of the caller to ensure
58514
-** that it is safe to overwrite this part of the cell-pointer array.
58515
-**
58516
-** When this function is called, *ppData points to the start of the
58517
-** content area on page pPg. If the size of the content area is extended,
58518
-** *ppData is updated to point to the new start of the content area
58519
-** before returning.
58520
-**
58521
-** Finally, argument pBegin points to the byte immediately following the
58522
-** end of the space required by this page for the cell-pointer area (for
58523
-** all cells - not just those inserted by the current call). If the content
58524
-** area must be extended to before this point in order to accomodate all
58525
-** cells in apCell[], then the cells do not fit and non-zero is returned.
58526
-*/
58527
-static int pageInsertArray(
58528
- MemPage *pPg, /* Page to add cells to */
58529
- u8 *pBegin, /* End of cell-pointer array */
58530
- u8 **ppData, /* IN/OUT: Page content -area pointer */
58531
- u8 *pCellptr, /* Pointer to cell-pointer area */
58532
- int nCell, /* Number of cells to add to pPg */
58533
- u8 **apCell, /* Array of cells */
58534
- u16 *szCell /* Array of cell sizes */
58535
-){
58536
- int i;
58537
- u8 *aData = pPg->aData;
58538
- u8 *pData = *ppData;
58539
- const int bFreelist = aData[1] || aData[2];
58540
- assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
58541
- for(i=0; i<nCell; i++){
58542
- int sz = szCell[i];
58543
- int rc;
58544
- u8 *pSlot;
58545
- if( bFreelist==0 || (pSlot = pageFindSlot(pPg, sz, &rc, 0))==0 ){
58546
- pData -= sz;
58547
- if( pData<pBegin ) return 1;
58548
- pSlot = pData;
58549
- }
58550
- memcpy(pSlot, apCell[i], sz);
58551
- put2byte(pCellptr, (pSlot - aData));
58552
- pCellptr += 2;
58553
- }
58554
- *ppData = pData;
58555
- return 0;
58556
-}
58557
-
58558
-/*
58559
-** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
58560
-** contains the size in bytes of each such cell. This function adds the
58561
-** space associated with each cell in the array that is currently stored
58562
-** within the body of pPg to the pPg free-list. The cell-pointers and other
58563
-** fields of the page are not updated.
58564
-**
58565
-** This function returns the total number of cells added to the free-list.
58566
-*/
58567
-static int pageFreeArray(
58568
- MemPage *pPg, /* Page to edit */
58569
- int nCell, /* Cells to delete */
58570
- u8 **apCell, /* Array of cells */
58571
- u16 *szCell /* Array of cell sizes */
58572
-){
58573
- u8 * const aData = pPg->aData;
58574
- u8 * const pEnd = &aData[pPg->pBt->usableSize];
58575
- u8 * const pStart = &aData[pPg->hdrOffset + 8 + pPg->childPtrSize];
58576
- int nRet = 0;
58577
- int i;
58578
- u8 *pFree = 0;
58579
- int szFree = 0;
58580
-
58581
- for(i=0; i<nCell; i++){
58582
- u8 *pCell = apCell[i];
58583
- if( pCell>=pStart && pCell<pEnd ){
58584
- int sz = szCell[i];
58585
- if( pFree!=(pCell + sz) ){
58586
- if( pFree ){
58587
- assert( pFree>aData && (pFree - aData)<65536 );
58588
- freeSpace(pPg, (u16)(pFree - aData), szFree);
58589
- }
58590
- pFree = pCell;
58591
- szFree = sz;
58592
- if( pFree+sz>pEnd ) return 0;
58593
- }else{
58594
- pFree = pCell;
58595
- szFree += sz;
58596
- }
58597
- nRet++;
58598
- }
58599
- }
58600
- if( pFree ){
58601
- assert( pFree>aData && (pFree - aData)<65536 );
58602
- freeSpace(pPg, (u16)(pFree - aData), szFree);
58603
- }
58604
- return nRet;
58605
-}
58606
-
58607
-/*
58608
-** The pPg->nFree field is invalid when this function returns. It is the
58609
-** responsibility of the caller to set it correctly.
58610
-*/
58611
-static void editPage(
58612
- MemPage *pPg, /* Edit this page */
58613
- int iOld, /* Index of first cell currently on page */
58614
- int iNew, /* Index of new first cell on page */
58615
- int nNew, /* Final number of cells on page */
58616
- u8 **apCell, /* Array of cells */
58617
- u16 *szCell /* Array of cell sizes */
58618
-){
58619
- u8 * const aData = pPg->aData;
58620
- const int hdr = pPg->hdrOffset;
58621
- u8 *pBegin = &pPg->aCellIdx[nNew * 2];
58622
- int nCell = pPg->nCell; /* Cells stored on pPg */
58623
- u8 *pData;
58624
- u8 *pCellptr;
58625
- int i;
58626
- int iOldEnd = iOld + pPg->nCell + pPg->nOverflow;
58627
- int iNewEnd = iNew + nNew;
58628
-
58629
-#ifdef SQLITE_DEBUG
58630
- u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
58631
- memcpy(pTmp, aData, pPg->pBt->usableSize);
58632
-#endif
58633
-
58634
- /* Remove cells from the start and end of the page */
58635
- if( iOld<iNew ){
58636
- int nShift = pageFreeArray(
58637
- pPg, iNew-iOld, &apCell[iOld], &szCell[iOld]
58638
- );
58639
- memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
58640
- nCell -= nShift;
58641
- }
58642
- if( iNewEnd < iOldEnd ){
58643
- nCell -= pageFreeArray(
58644
- pPg, iOldEnd-iNewEnd, &apCell[iNewEnd], &szCell[iNewEnd]
58645
- );
58646
- }
58647
-
58648
- pData = &aData[get2byte(&aData[hdr+5])];
58649
- if( pData<pBegin ) goto editpage_fail;
58650
-
58651
- /* Add cells to the start of the page */
58652
- if( iNew<iOld ){
58653
- int nAdd = iOld-iNew;
58654
- pCellptr = pPg->aCellIdx;
58655
- memmove(&pCellptr[nAdd*2], pCellptr, nCell*2);
58656
- if( pageInsertArray(
58657
- pPg, pBegin, &pData, pCellptr,
58658
- nAdd, &apCell[iNew], &szCell[iNew]
58659
- ) ) goto editpage_fail;
58660
- nCell += nAdd;
58661
- }
58662
-
58663
- /* Add any overflow cells */
58664
- for(i=0; i<pPg->nOverflow; i++){
58665
- int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
58666
- if( iCell>=0 && iCell<nNew ){
58667
- pCellptr = &pPg->aCellIdx[iCell * 2];
58668
- memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
58669
- nCell++;
58670
- if( pageInsertArray(
58671
- pPg, pBegin, &pData, pCellptr,
58672
- 1, &apCell[iCell + iNew], &szCell[iCell + iNew]
58673
- ) ) goto editpage_fail;
58674
- }
58675
- }
58676
-
58677
- /* Append cells to the end of the page */
58678
- pCellptr = &pPg->aCellIdx[nCell*2];
58679
- if( pageInsertArray(
58680
- pPg, pBegin, &pData, pCellptr,
58681
- nNew-nCell, &apCell[iNew+nCell], &szCell[iNew+nCell]
58682
- ) ) goto editpage_fail;
58683
-
58684
- pPg->nCell = nNew;
58685
- pPg->nOverflow = 0;
58686
-
58687
- put2byte(&aData[hdr+3], pPg->nCell);
58688
- put2byte(&aData[hdr+5], pData - aData);
58689
-
58690
-#ifdef SQLITE_DEBUG
58691
- for(i=0; i<nNew && !CORRUPT_DB; i++){
58692
- u8 *pCell = apCell[i+iNew];
58693
- int iOff = get2byte(&pPg->aCellIdx[i*2]);
58694
- if( pCell>=aData && pCell<&aData[pPg->pBt->usableSize] ){
58695
- pCell = &pTmp[pCell - aData];
58696
- }
58697
- assert( 0==memcmp(pCell, &aData[iOff], szCell[i+iNew]) );
58698
- }
58699
-#endif
58700
-
58701
- return;
58702
- editpage_fail:
58703
- /* Unable to edit this page. Rebuild it from scratch instead. */
58704
- rebuildPage(pPg, nNew, &apCell[iNew], &szCell[iNew]);
58162
+** Add a list of cells to a page. The page should be initially empty.
58163
+** The cells are guaranteed to fit on the page.
58164
+*/
58165
+static void assemblePage(
58166
+ MemPage *pPage, /* The page to be assembled */
58167
+ int nCell, /* The number of cells to add to this page */
58168
+ u8 **apCell, /* Pointers to cell bodies */
58169
+ u16 *aSize /* Sizes of the cells */
58170
+){
58171
+ int i; /* Loop counter */
58172
+ u8 *pCellptr; /* Address of next cell pointer */
58173
+ int cellbody; /* Address of next cell body */
58174
+ u8 * const data = pPage->aData; /* Pointer to data for pPage */
58175
+ const int hdr = pPage->hdrOffset; /* Offset of header on pPage */
58176
+ const int nUsable = pPage->pBt->usableSize; /* Usable size of page */
58177
+
58178
+ assert( pPage->nOverflow==0 );
58179
+ assert( sqlite3_mutex_held(pPage->pBt->mutex) );
58180
+ assert( nCell>=0 && nCell<=(int)MX_CELL(pPage->pBt)
58181
+ && (int)MX_CELL(pPage->pBt)<=10921);
58182
+ assert( sqlite3PagerIswriteable(pPage->pDbPage) );
58183
+
58184
+ /* Check that the page has just been zeroed by zeroPage() */
58185
+ assert( pPage->nCell==0 );
58186
+ assert( get2byteNotZero(&data[hdr+5])==nUsable );
58187
+
58188
+ pCellptr = &pPage->aCellIdx[nCell*2];
58189
+ cellbody = nUsable;
58190
+ for(i=nCell-1; i>=0; i--){
58191
+ u16 sz = aSize[i];
58192
+ pCellptr -= 2;
58193
+ cellbody -= sz;
58194
+ put2byte(pCellptr, cellbody);
58195
+ memcpy(&data[cellbody], apCell[i], sz);
58196
+ }
58197
+ put2byte(&data[hdr+3], nCell);
58198
+ put2byte(&data[hdr+5], cellbody);
58199
+ pPage->nFree -= (nCell*2 + nUsable - cellbody);
58200
+ pPage->nCell = (u16)nCell;
5870558201
}
5870658202
5870758203
/*
5870858204
** The following parameters determine how many adjacent pages get involved
5870958205
** in a balancing operation. NN is the number of neighbors on either side
@@ -58771,12 +58267,11 @@
5877158267
u8 *pStop;
5877258268
5877358269
assert( sqlite3PagerIswriteable(pNew->pDbPage) );
5877458270
assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
5877558271
zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF);
58776
- rebuildPage(pNew, 1, &pCell, &szCell);
58777
- pNew->nFree = pBt->usableSize - pNew->cellOffset - 2 - szCell;
58272
+ assemblePage(pNew, 1, &pCell, &szCell);
5877858273
5877958274
/* If this is an auto-vacuum database, update the pointer map
5878058275
** with entries for the new page, and any pointer from the
5878158276
** cell on the page to an overflow page. If either of these
5878258277
** operations fails, the return code is set, but the contents
@@ -58991,26 +58486,21 @@
5899158486
int subtotal; /* Subtotal of bytes in cells on one page */
5899258487
int iSpace1 = 0; /* First unused byte of aSpace1[] */
5899358488
int iOvflSpace = 0; /* First unused byte of aOvflSpace[] */
5899458489
int szScratch; /* Size of scratch memory requested */
5899558490
MemPage *apOld[NB]; /* pPage and up to two siblings */
58491
+ MemPage *apCopy[NB]; /* Private copies of apOld[] pages */
5899658492
MemPage *apNew[NB+2]; /* pPage and up to NB siblings after balancing */
5899758493
u8 *pRight; /* Location in parent of right-sibling pointer */
5899858494
u8 *apDiv[NB-1]; /* Divider cells in pParent */
5899958495
int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */
59000
- int cntOld[NB+2]; /* Old index in aCell[] after i-th page */
59001
- int szNew[NB+2]; /* Combined size of cells placed on i-th page */
58496
+ int szNew[NB+2]; /* Combined size of cells place on i-th page */
5900258497
u8 **apCell = 0; /* All cells begin balanced */
5900358498
u16 *szCell; /* Local size of all cells in apCell[] */
5900458499
u8 *aSpace1; /* Space for copies of dividers cells */
5900558500
Pgno pgno; /* Temp var to store a page number in */
59006
- u8 abDone[NB+2]; /* True after i'th new page is populated */
59007
- Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */
59008
- Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */
59009
- u16 aPgFlags[NB+2]; /* flags field of new pages before shuffling */
5901058501
59011
- memset(abDone, 0, sizeof(abDone));
5901258502
pBt = pParent->pBt;
5901358503
assert( sqlite3_mutex_held(pBt->mutex) );
5901458504
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
5901558505
5901658506
#if 0
@@ -59115,18 +58605,16 @@
5911558605
nMaxCells = (nMaxCells + 3)&~3;
5911658606
5911758607
/*
5911858608
** Allocate space for memory structures
5911958609
*/
58610
+ k = pBt->pageSize + ROUND8(sizeof(MemPage));
5912058611
szScratch =
5912158612
nMaxCells*sizeof(u8*) /* apCell */
5912258613
+ nMaxCells*sizeof(u16) /* szCell */
59123
- + pBt->pageSize; /* aSpace1 */
59124
-
59125
- /* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer
59126
- ** that is more than 6 times the database page size. */
59127
- assert( szScratch<=6*pBt->pageSize );
58614
+ + pBt->pageSize /* aSpace1 */
58615
+ + k*nOld; /* Page copies (apCopy) */
5912858616
apCell = sqlite3ScratchMalloc( szScratch );
5912958617
if( apCell==0 ){
5913058618
rc = SQLITE_NOMEM;
5913158619
goto balance_cleanup;
5913258620
}
@@ -59135,12 +58623,12 @@
5913558623
assert( EIGHT_BYTE_ALIGNMENT(aSpace1) );
5913658624
5913758625
/*
5913858626
** Load pointers to all cells on sibling pages and the divider cells
5913958627
** into the local apCell[] array. Make copies of the divider cells
59140
- ** into space obtained from aSpace1[]. The divider cells have already
59141
- ** been removed from pParent.
58628
+ ** into space obtained from aSpace1[] and remove the divider cells
58629
+ ** from pParent.
5914258630
**
5914358631
** If the siblings are on leaf pages, then the child pointers of the
5914458632
** divider cells are stripped from the cells before they are copied
5914558633
** into aSpace1[]. In this way, all cells in apCell[] are without
5914658634
** child pointers. If siblings are not leaves, then all cell in
@@ -59152,11 +58640,19 @@
5915258640
*/
5915358641
leafCorrection = apOld[0]->leaf*4;
5915458642
leafData = apOld[0]->intKeyLeaf;
5915558643
for(i=0; i<nOld; i++){
5915658644
int limit;
59157
- MemPage *pOld = apOld[i];
58645
+
58646
+ /* Before doing anything else, take a copy of the i'th original sibling
58647
+ ** The rest of this function will use data from the copies rather
58648
+ ** that the original pages since the original pages will be in the
58649
+ ** process of being overwritten. */
58650
+ MemPage *pOld = apCopy[i] = (MemPage*)&aSpace1[pBt->pageSize + k*i];
58651
+ memcpy(pOld, apOld[i], sizeof(MemPage));
58652
+ pOld->aData = (void*)&pOld[1];
58653
+ memcpy(pOld->aData, apOld[i]->aData, pBt->pageSize);
5915858654
5915958655
limit = pOld->nCell+pOld->nOverflow;
5916058656
if( pOld->nOverflow>0 ){
5916158657
for(j=0; j<limit; j++){
5916258658
assert( nCell<nMaxCells );
@@ -59173,11 +58669,10 @@
5917358669
apCell[nCell] = findCellv2(aData, maskPage, cellOffset, j);
5917458670
szCell[nCell] = cellSizePtr(pOld, apCell[nCell]);
5917558671
nCell++;
5917658672
}
5917758673
}
59178
- cntOld[i] = nCell;
5917958674
if( i<nOld-1 && !leafData){
5918058675
u16 sz = (u16)szNew[i];
5918158676
u8 *pTemp;
5918258677
assert( nCell<nMaxCells );
5918358678
szCell[nCell] = sz;
@@ -59225,11 +58720,11 @@
5922558720
usableSpace = pBt->usableSize - 12 + leafCorrection;
5922658721
for(subtotal=k=i=0; i<nCell; i++){
5922758722
assert( i<nMaxCells );
5922858723
subtotal += szCell[i] + 2;
5922958724
if( subtotal > usableSpace ){
59230
- szNew[k] = subtotal - szCell[i] - 2;
58725
+ szNew[k] = subtotal - szCell[i];
5923158726
cntNew[k] = i;
5923258727
if( leafData ){ i--; }
5923358728
subtotal = 0;
5923458729
k++;
5923558730
if( k>NB+1 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; }
@@ -59239,14 +58734,13 @@
5923958734
cntNew[k] = nCell;
5924058735
k++;
5924158736
5924258737
/*
5924358738
** The packing computed by the previous block is biased toward the siblings
59244
- ** on the left side (siblings with smaller keys). The left siblings are
59245
- ** always nearly full, while the right-most sibling might be nearly empty.
59246
- ** The next block of code attempts to adjust the packing of siblings to
59247
- ** get a better balance.
58739
+ ** on the left side. The left siblings are always nearly full, while the
58740
+ ** right-most sibling might be nearly empty. This block of code attempts
58741
+ ** to adjust the packing of siblings to get a better balance.
5924858742
**
5924958743
** This adjustment is more than an optimization. The packing above might
5925058744
** be so out of balance as to be illegal. For example, the right-most
5925158745
** sibling might be completely empty. This adjustment is not optional.
5925258746
*/
@@ -59271,22 +58765,26 @@
5927158765
}
5927258766
szNew[i] = szRight;
5927358767
szNew[i-1] = szLeft;
5927458768
}
5927558769
59276
- /* Sanity check: For a non-corrupt database file one of the follwing
59277
- ** must be true:
59278
- ** (1) We found one or more cells (cntNew[0])>0), or
59279
- ** (2) pPage is a virtual root page. A virtual root page is when
59280
- ** the real root page is page 1 and we are the only child of
59281
- ** that page.
58770
+ /* Either we found one or more cells (cntnew[0])>0) or pPage is
58771
+ ** a virtual root page. A virtual root page is when the real root
58772
+ ** page is page 1 and we are the only child of that page.
58773
+ **
58774
+ ** UPDATE: The assert() below is not necessarily true if the database
58775
+ ** file is corrupt. The corruption will be detected and reported later
58776
+ ** in this procedure so there is no need to act upon it now.
5928258777
*/
59283
- assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) || CORRUPT_DB);
59284
- TRACE(("BALANCE: old: %d(nc=%d) %d(nc=%d) %d(nc=%d)\n",
59285
- apOld[0]->pgno, apOld[0]->nCell,
59286
- nOld>=2 ? apOld[1]->pgno : 0, nOld>=2 ? apOld[1]->nCell : 0,
59287
- nOld>=3 ? apOld[2]->pgno : 0, nOld>=3 ? apOld[2]->nCell : 0
58778
+#if 0
58779
+ assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) );
58780
+#endif
58781
+
58782
+ TRACE(("BALANCE: old: %d %d %d ",
58783
+ apOld[0]->pgno,
58784
+ nOld>=2 ? apOld[1]->pgno : 0,
58785
+ nOld>=3 ? apOld[2]->pgno : 0
5928858786
));
5928958787
5929058788
/*
5929158789
** Allocate k new pages. Reuse old pages where possible.
5929258790
*/
@@ -59305,14 +58803,12 @@
5930558803
if( rc ) goto balance_cleanup;
5930658804
}else{
5930758805
assert( i>0 );
5930858806
rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0);
5930958807
if( rc ) goto balance_cleanup;
59310
- zeroPage(pNew, pageFlags);
5931158808
apNew[i] = pNew;
5931258809
nNew++;
59313
- cntOld[i] = nCell;
5931458810
5931558811
/* Set the pointer-map entry for the new sibling page. */
5931658812
if( ISAUTOVACUUM ){
5931758813
ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc);
5931858814
if( rc!=SQLITE_OK ){
@@ -59319,248 +58815,140 @@
5931958815
goto balance_cleanup;
5932058816
}
5932158817
}
5932258818
}
5932358819
}
58820
+
58821
+ /* Free any old pages that were not reused as new pages.
58822
+ */
58823
+ while( i<nOld ){
58824
+ freePage(apOld[i], &rc);
58825
+ if( rc ) goto balance_cleanup;
58826
+ releasePage(apOld[i]);
58827
+ apOld[i] = 0;
58828
+ i++;
58829
+ }
5932458830
5932558831
/*
59326
- ** Reassign page numbers so that the new pages are in ascending order.
59327
- ** This helps to keep entries in the disk file in order so that a scan
59328
- ** of the table is closer to a linear scan through the file. That in turn
59329
- ** helps the operating system to deliver pages from the disk more rapidly.
59330
- **
59331
- ** An O(n^2) insertion sort algorithm is used, but since n is never more
59332
- ** than (NB+2) (a small constant), that should not be a problem.
59333
- **
59334
- ** When NB==3, this one optimization makes the database about 25% faster
59335
- ** for large insertions and deletions.
59336
- */
59337
- for(i=0; i<nNew; i++){
59338
- aPgOrder[i] = aPgno[i] = apNew[i]->pgno;
59339
- aPgFlags[i] = apNew[i]->pDbPage->flags;
59340
- for(j=0; j<i; j++){
59341
- if( aPgno[j]==aPgno[i] ){
59342
- /* This branch is taken if the set of sibling pages somehow contains
59343
- ** duplicate entries. This can happen if the database is corrupt.
59344
- ** It would be simpler to detect this as part of the loop below, but
59345
- ** we do the detection here in order to avoid populating the pager
59346
- ** cache with two separate objects associated with the same
59347
- ** page number. */
59348
- assert( CORRUPT_DB );
59349
- rc = SQLITE_CORRUPT_BKPT;
59350
- goto balance_cleanup;
59351
- }
59352
- }
59353
- }
59354
- for(i=0; i<nNew; i++){
59355
- int iBest = 0; /* aPgno[] index of page number to use */
59356
- for(j=1; j<nNew; j++){
59357
- if( aPgOrder[j]<aPgOrder[iBest] ) iBest = j;
59358
- }
59359
- pgno = aPgOrder[iBest];
59360
- aPgOrder[iBest] = 0xffffffff;
59361
- if( iBest!=i ){
59362
- if( iBest>i ){
59363
- sqlite3PagerRekey(apNew[iBest]->pDbPage, pBt->nPage+iBest+1, 0);
59364
- }
59365
- sqlite3PagerRekey(apNew[i]->pDbPage, pgno, aPgFlags[iBest]);
59366
- apNew[i]->pgno = pgno;
59367
- }
59368
- }
59369
-
59370
- TRACE(("BALANCE: new: %d(%d nc=%d) %d(%d nc=%d) %d(%d nc=%d) "
59371
- "%d(%d nc=%d) %d(%d nc=%d)\n",
59372
- apNew[0]->pgno, szNew[0], cntNew[0],
58832
+ ** Put the new pages in ascending order. This helps to
58833
+ ** keep entries in the disk file in order so that a scan
58834
+ ** of the table is a linear scan through the file. That
58835
+ ** in turn helps the operating system to deliver pages
58836
+ ** from the disk more rapidly.
58837
+ **
58838
+ ** An O(n^2) insertion sort algorithm is used, but since
58839
+ ** n is never more than NB (a small constant), that should
58840
+ ** not be a problem.
58841
+ **
58842
+ ** When NB==3, this one optimization makes the database
58843
+ ** about 25% faster for large insertions and deletions.
58844
+ */
58845
+ for(i=0; i<k-1; i++){
58846
+ int minV = apNew[i]->pgno;
58847
+ int minI = i;
58848
+ for(j=i+1; j<k; j++){
58849
+ if( apNew[j]->pgno<(unsigned)minV ){
58850
+ minI = j;
58851
+ minV = apNew[j]->pgno;
58852
+ }
58853
+ }
58854
+ if( minI>i ){
58855
+ MemPage *pT;
58856
+ pT = apNew[i];
58857
+ apNew[i] = apNew[minI];
58858
+ apNew[minI] = pT;
58859
+ }
58860
+ }
58861
+ TRACE(("new: %d(%d) %d(%d) %d(%d) %d(%d) %d(%d)\n",
58862
+ apNew[0]->pgno, szNew[0],
5937358863
nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0,
59374
- nNew>=2 ? cntNew[1] - cntNew[0] - !leafData : 0,
5937558864
nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0,
59376
- nNew>=3 ? cntNew[2] - cntNew[1] - !leafData : 0,
5937758865
nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0,
59378
- nNew>=4 ? cntNew[3] - cntNew[2] - !leafData : 0,
59379
- nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0,
59380
- nNew>=5 ? cntNew[4] - cntNew[3] - !leafData : 0
59381
- ));
58866
+ nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0));
5938258867
5938358868
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
5938458869
put4byte(pRight, apNew[nNew-1]->pgno);
5938558870
59386
- /* If the sibling pages are not leaves, ensure that the right-child pointer
59387
- ** of the right-most new sibling page is set to the value that was
59388
- ** originally in the same field of the right-most old sibling page. */
59389
- if( (pageFlags & PTF_LEAF)==0 && nOld!=nNew ){
59390
- MemPage *pOld = (nNew>nOld ? apNew : apOld)[nOld-1];
59391
- memcpy(&apNew[nNew-1]->aData[8], &pOld->aData[8], 4);
59392
- }
59393
-
59394
- /* Make any required updates to pointer map entries associated with
59395
- ** cells stored on sibling pages following the balance operation. Pointer
59396
- ** map entries associated with divider cells are set by the insertCell()
59397
- ** routine. The associated pointer map entries are:
59398
- **
59399
- ** a) if the cell contains a reference to an overflow chain, the
59400
- ** entry associated with the first page in the overflow chain, and
59401
- **
59402
- ** b) if the sibling pages are not leaves, the child page associated
59403
- ** with the cell.
59404
- **
59405
- ** If the sibling pages are not leaves, then the pointer map entry
59406
- ** associated with the right-child of each sibling may also need to be
59407
- ** updated. This happens below, after the sibling pages have been
59408
- ** populated, not here.
58871
+ /*
58872
+ ** Evenly distribute the data in apCell[] across the new pages.
58873
+ ** Insert divider cells into pParent as necessary.
5940958874
*/
59410
- if( ISAUTOVACUUM ){
59411
- MemPage *pNew = apNew[0];
59412
- u8 *aOld = pNew->aData;
59413
- int cntOldNext = pNew->nCell + pNew->nOverflow;
59414
- int usableSize = pBt->usableSize;
59415
- int iNew = 0;
59416
- int iOld = 0;
59417
-
59418
- for(i=0; i<nCell; i++){
59419
- u8 *pCell = apCell[i];
59420
- if( i==cntOldNext ){
59421
- MemPage *pOld = (++iOld)<nNew ? apNew[iOld] : apOld[iOld];
59422
- cntOldNext += pOld->nCell + pOld->nOverflow + !leafData;
59423
- aOld = pOld->aData;
59424
- }
59425
- if( i==cntNew[iNew] ){
59426
- pNew = apNew[++iNew];
59427
- if( !leafData ) continue;
59428
- }
59429
-
59430
- /* Cell pCell is destined for new sibling page pNew. Originally, it
59431
- ** was either part of sibling page iOld (possibly an overflow cell),
59432
- ** or else the divider cell to the left of sibling page iOld. So,
59433
- ** if sibling page iOld had the same page number as pNew, and if
59434
- ** pCell really was a part of sibling page iOld (not a divider or
59435
- ** overflow cell), we can skip updating the pointer map entries. */
59436
- if( pNew->pgno!=aPgno[iOld] || pCell<aOld || pCell>=&aOld[usableSize] ){
59437
- if( !leafCorrection ){
59438
- ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
59439
- }
59440
- if( szCell[i]>pNew->minLocal ){
59441
- ptrmapPutOvflPtr(pNew, pCell, &rc);
59442
- }
59443
- }
59444
- }
59445
- }
59446
-
59447
- /* Insert new divider cells into pParent. */
59448
- for(i=0; i<nNew-1; i++){
59449
- u8 *pCell;
59450
- u8 *pTemp;
59451
- int sz;
58875
+ j = 0;
58876
+ for(i=0; i<nNew; i++){
58877
+ /* Assemble the new sibling page. */
5945258878
MemPage *pNew = apNew[i];
58879
+ assert( j<nMaxCells );
58880
+ zeroPage(pNew, pageFlags);
58881
+ assemblePage(pNew, cntNew[i]-j, &apCell[j], &szCell[j]);
58882
+ assert( pNew->nCell>0 || (nNew==1 && cntNew[0]==0) );
58883
+ assert( pNew->nOverflow==0 );
58884
+
5945358885
j = cntNew[i];
5945458886
59455
- assert( j<nMaxCells );
59456
- pCell = apCell[j];
59457
- sz = szCell[j] + leafCorrection;
59458
- pTemp = &aOvflSpace[iOvflSpace];
59459
- if( !pNew->leaf ){
59460
- memcpy(&pNew->aData[8], pCell, 4);
59461
- }else if( leafData ){
59462
- /* If the tree is a leaf-data tree, and the siblings are leaves,
59463
- ** then there is no divider cell in apCell[]. Instead, the divider
59464
- ** cell consists of the integer key for the right-most cell of
59465
- ** the sibling-page assembled above only.
59466
- */
59467
- CellInfo info;
59468
- j--;
59469
- btreeParseCellPtr(pNew, apCell[j], &info);
59470
- pCell = pTemp;
59471
- sz = 4 + putVarint(&pCell[4], info.nKey);
59472
- pTemp = 0;
59473
- }else{
59474
- pCell -= 4;
59475
- /* Obscure case for non-leaf-data trees: If the cell at pCell was
59476
- ** previously stored on a leaf node, and its reported size was 4
59477
- ** bytes, then it may actually be smaller than this
59478
- ** (see btreeParseCellPtr(), 4 bytes is the minimum size of
59479
- ** any cell). But it is important to pass the correct size to
59480
- ** insertCell(), so reparse the cell now.
59481
- **
59482
- ** Note that this can never happen in an SQLite data file, as all
59483
- ** cells are at least 4 bytes. It only happens in b-trees used
59484
- ** to evaluate "IN (SELECT ...)" and similar clauses.
59485
- */
59486
- if( szCell[j]==4 ){
59487
- assert(leafCorrection==4);
59488
- sz = cellSizePtr(pParent, pCell);
59489
- }
59490
- }
59491
- iOvflSpace += sz;
59492
- assert( sz<=pBt->maxLocal+23 );
59493
- assert( iOvflSpace <= (int)pBt->pageSize );
59494
- insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc);
59495
- if( rc!=SQLITE_OK ) goto balance_cleanup;
59496
- assert( sqlite3PagerIswriteable(pParent->pDbPage) );
59497
- }
59498
-
59499
- /* Now update the actual sibling pages. The order in which they are updated
59500
- ** is important, as this code needs to avoid disrupting any page from which
59501
- ** cells may still to be read. In practice, this means:
59502
- **
59503
- ** (1) If cells are moving left (from apNew[iPg] to apNew[iPg-1])
59504
- ** then it is not safe to update page apNew[iPg] until after
59505
- ** the left-hand sibling apNew[iPg-1] has been updated.
59506
- **
59507
- ** (2) If cells are moving right (from apNew[iPg] to apNew[iPg+1])
59508
- ** then it is not safe to update page apNew[iPg] until after
59509
- ** the right-hand sibling apNew[iPg+1] has been updated.
59510
- **
59511
- ** If neither of the above apply, the page is safe to update.
59512
- **
59513
- ** The iPg value in the following loop starts at nNew-1 goes down
59514
- ** to 0, then back up to nNew-1 again, thus making two passes over
59515
- ** the pages. On the initial downward pass, only condition (1) above
59516
- ** needs to be tested because (2) will always be true from the previous
59517
- ** step. On the upward pass, both conditions are always true, so the
59518
- ** upwards pass simply processes pages that were missed on the downward
59519
- ** pass.
59520
- */
59521
- for(i=1-nNew; i<nNew; i++){
59522
- int iPg = i<0 ? -i : i;
59523
- assert( iPg>=0 && iPg<nNew );
59524
- if( abDone[iPg] ) continue; /* Skip pages already processed */
59525
- if( i>=0 /* On the upwards pass, or... */
59526
- || cntOld[iPg-1]>=cntNew[iPg-1] /* Condition (1) is true */
59527
- ){
59528
- int iNew;
59529
- int iOld;
59530
- int nNewCell;
59531
-
59532
- /* Verify condition (1): If cells are moving left, update iPg
59533
- ** only after iPg-1 has already been updated. */
59534
- assert( iPg==0 || cntOld[iPg-1]>=cntNew[iPg-1] || abDone[iPg-1] );
59535
-
59536
- /* Verify condition (2): If cells are moving right, update iPg
59537
- ** only after iPg+1 has already been updated. */
59538
- assert( cntNew[iPg]>=cntOld[iPg] || abDone[iPg+1] );
59539
-
59540
- if( iPg==0 ){
59541
- iNew = iOld = 0;
59542
- nNewCell = cntNew[0];
59543
- }else{
59544
- iOld = iPg<nOld ? (cntOld[iPg-1] + !leafData) : nCell;
59545
- iNew = cntNew[iPg-1] + !leafData;
59546
- nNewCell = cntNew[iPg] - iNew;
59547
- }
59548
-
59549
- editPage(apNew[iPg], iOld, iNew, nNewCell, apCell, szCell);
59550
- abDone[iPg]++;
59551
- apNew[iPg]->nFree = usableSpace-szNew[iPg];
59552
- assert( apNew[iPg]->nOverflow==0 );
59553
- assert( apNew[iPg]->nCell==nNewCell );
59554
- }
59555
- }
59556
-
59557
- /* All pages have been processed exactly once */
59558
- assert( memcmp(abDone, "\01\01\01\01\01", nNew)==0 );
59559
-
58887
+ /* If the sibling page assembled above was not the right-most sibling,
58888
+ ** insert a divider cell into the parent page.
58889
+ */
58890
+ assert( i<nNew-1 || j==nCell );
58891
+ if( j<nCell ){
58892
+ u8 *pCell;
58893
+ u8 *pTemp;
58894
+ int sz;
58895
+
58896
+ assert( j<nMaxCells );
58897
+ pCell = apCell[j];
58898
+ sz = szCell[j] + leafCorrection;
58899
+ pTemp = &aOvflSpace[iOvflSpace];
58900
+ if( !pNew->leaf ){
58901
+ memcpy(&pNew->aData[8], pCell, 4);
58902
+ }else if( leafData ){
58903
+ /* If the tree is a leaf-data tree, and the siblings are leaves,
58904
+ ** then there is no divider cell in apCell[]. Instead, the divider
58905
+ ** cell consists of the integer key for the right-most cell of
58906
+ ** the sibling-page assembled above only.
58907
+ */
58908
+ CellInfo info;
58909
+ j--;
58910
+ btreeParseCellPtr(pNew, apCell[j], &info);
58911
+ pCell = pTemp;
58912
+ sz = 4 + putVarint(&pCell[4], info.nKey);
58913
+ pTemp = 0;
58914
+ }else{
58915
+ pCell -= 4;
58916
+ /* Obscure case for non-leaf-data trees: If the cell at pCell was
58917
+ ** previously stored on a leaf node, and its reported size was 4
58918
+ ** bytes, then it may actually be smaller than this
58919
+ ** (see btreeParseCellPtr(), 4 bytes is the minimum size of
58920
+ ** any cell). But it is important to pass the correct size to
58921
+ ** insertCell(), so reparse the cell now.
58922
+ **
58923
+ ** Note that this can never happen in an SQLite data file, as all
58924
+ ** cells are at least 4 bytes. It only happens in b-trees used
58925
+ ** to evaluate "IN (SELECT ...)" and similar clauses.
58926
+ */
58927
+ if( szCell[j]==4 ){
58928
+ assert(leafCorrection==4);
58929
+ sz = cellSizePtr(pParent, pCell);
58930
+ }
58931
+ }
58932
+ iOvflSpace += sz;
58933
+ assert( sz<=pBt->maxLocal+23 );
58934
+ assert( iOvflSpace <= (int)pBt->pageSize );
58935
+ insertCell(pParent, nxDiv, pCell, sz, pTemp, pNew->pgno, &rc);
58936
+ if( rc!=SQLITE_OK ) goto balance_cleanup;
58937
+ assert( sqlite3PagerIswriteable(pParent->pDbPage) );
58938
+
58939
+ j++;
58940
+ nxDiv++;
58941
+ }
58942
+ }
58943
+ assert( j==nCell );
5956058944
assert( nOld>0 );
5956158945
assert( nNew>0 );
58946
+ if( (pageFlags & PTF_LEAF)==0 ){
58947
+ u8 *zChild = &apCopy[nOld-1]->aData[8];
58948
+ memcpy(&apNew[nNew-1]->aData[8], zChild, 4);
58949
+ }
5956258950
5956358951
if( isRoot && pParent->nCell==0 && pParent->hdrOffset<=apNew[0]->nFree ){
5956458952
/* The root page of the b-tree now contains no cells. The only sibling
5956558953
** page is the right-child of the parent. Copy the contents of the
5956658954
** child page into the parent, decreasing the overall height of the
@@ -59569,54 +58957,130 @@
5956958957
**
5957058958
** If this is an auto-vacuum database, the call to copyNodeContent()
5957158959
** sets all pointer-map entries corresponding to database image pages
5957258960
** for which the pointer is stored within the content being copied.
5957358961
**
59574
- ** It is critical that the child page be defragmented before being
59575
- ** copied into the parent, because if the parent is page 1 then it will
59576
- ** by smaller than the child due to the database header, and so all the
59577
- ** free space needs to be up front.
59578
- */
58962
+ ** The second assert below verifies that the child page is defragmented
58963
+ ** (it must be, as it was just reconstructed using assemblePage()). This
58964
+ ** is important if the parent page happens to be page 1 of the database
58965
+ ** image. */
5957958966
assert( nNew==1 );
59580
- rc = defragmentPage(apNew[0]);
59581
- testcase( rc!=SQLITE_OK );
5958258967
assert( apNew[0]->nFree ==
59583
- (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
59584
- || rc!=SQLITE_OK
58968
+ (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
5958558969
);
5958658970
copyNodeContent(apNew[0], pParent, &rc);
5958758971
freePage(apNew[0], &rc);
59588
- }else if( ISAUTOVACUUM && !leafCorrection ){
59589
- /* Fix the pointer map entries associated with the right-child of each
59590
- ** sibling page. All other pointer map entries have already been taken
59591
- ** care of. */
59592
- for(i=0; i<nNew; i++){
59593
- u32 key = get4byte(&apNew[i]->aData[8]);
59594
- ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc);
59595
- }
59596
- }
59597
-
59598
- assert( pParent->isInit );
59599
- TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n",
59600
- nOld, nNew, nCell));
59601
-
59602
- /* Free any old pages that were not reused as new pages.
59603
- */
59604
- for(i=nNew; i<nOld; i++){
59605
- freePage(apOld[i], &rc);
59606
- }
58972
+ }else if( ISAUTOVACUUM ){
58973
+ /* Fix the pointer-map entries for all the cells that were shifted around.
58974
+ ** There are several different types of pointer-map entries that need to
58975
+ ** be dealt with by this routine. Some of these have been set already, but
58976
+ ** many have not. The following is a summary:
58977
+ **
58978
+ ** 1) The entries associated with new sibling pages that were not
58979
+ ** siblings when this function was called. These have already
58980
+ ** been set. We don't need to worry about old siblings that were
58981
+ ** moved to the free-list - the freePage() code has taken care
58982
+ ** of those.
58983
+ **
58984
+ ** 2) The pointer-map entries associated with the first overflow
58985
+ ** page in any overflow chains used by new divider cells. These
58986
+ ** have also already been taken care of by the insertCell() code.
58987
+ **
58988
+ ** 3) If the sibling pages are not leaves, then the child pages of
58989
+ ** cells stored on the sibling pages may need to be updated.
58990
+ **
58991
+ ** 4) If the sibling pages are not internal intkey nodes, then any
58992
+ ** overflow pages used by these cells may need to be updated
58993
+ ** (internal intkey nodes never contain pointers to overflow pages).
58994
+ **
58995
+ ** 5) If the sibling pages are not leaves, then the pointer-map
58996
+ ** entries for the right-child pages of each sibling may need
58997
+ ** to be updated.
58998
+ **
58999
+ ** Cases 1 and 2 are dealt with above by other code. The next
59000
+ ** block deals with cases 3 and 4 and the one after that, case 5. Since
59001
+ ** setting a pointer map entry is a relatively expensive operation, this
59002
+ ** code only sets pointer map entries for child or overflow pages that have
59003
+ ** actually moved between pages. */
59004
+ MemPage *pNew = apNew[0];
59005
+ MemPage *pOld = apCopy[0];
59006
+ int nOverflow = pOld->nOverflow;
59007
+ int iNextOld = pOld->nCell + nOverflow;
59008
+ int iOverflow = (nOverflow ? pOld->aiOvfl[0] : -1);
59009
+ j = 0; /* Current 'old' sibling page */
59010
+ k = 0; /* Current 'new' sibling page */
59011
+ for(i=0; i<nCell; i++){
59012
+ int isDivider = 0;
59013
+ while( i==iNextOld ){
59014
+ /* Cell i is the cell immediately following the last cell on old
59015
+ ** sibling page j. If the siblings are not leaf pages of an
59016
+ ** intkey b-tree, then cell i was a divider cell. */
59017
+ assert( j+1 < ArraySize(apCopy) );
59018
+ assert( j+1 < nOld );
59019
+ pOld = apCopy[++j];
59020
+ iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow;
59021
+ if( pOld->nOverflow ){
59022
+ nOverflow = pOld->nOverflow;
59023
+ iOverflow = i + !leafData + pOld->aiOvfl[0];
59024
+ }
59025
+ isDivider = !leafData;
59026
+ }
59027
+
59028
+ assert(nOverflow>0 || iOverflow<i );
59029
+ assert(nOverflow<2 || pOld->aiOvfl[0]==pOld->aiOvfl[1]-1);
59030
+ assert(nOverflow<3 || pOld->aiOvfl[1]==pOld->aiOvfl[2]-1);
59031
+ if( i==iOverflow ){
59032
+ isDivider = 1;
59033
+ if( (--nOverflow)>0 ){
59034
+ iOverflow++;
59035
+ }
59036
+ }
59037
+
59038
+ if( i==cntNew[k] ){
59039
+ /* Cell i is the cell immediately following the last cell on new
59040
+ ** sibling page k. If the siblings are not leaf pages of an
59041
+ ** intkey b-tree, then cell i is a divider cell. */
59042
+ pNew = apNew[++k];
59043
+ if( !leafData ) continue;
59044
+ }
59045
+ assert( j<nOld );
59046
+ assert( k<nNew );
59047
+
59048
+ /* If the cell was originally divider cell (and is not now) or
59049
+ ** an overflow cell, or if the cell was located on a different sibling
59050
+ ** page before the balancing, then the pointer map entries associated
59051
+ ** with any child or overflow pages need to be updated. */
59052
+ if( isDivider || pOld->pgno!=pNew->pgno ){
59053
+ if( !leafCorrection ){
59054
+ ptrmapPut(pBt, get4byte(apCell[i]), PTRMAP_BTREE, pNew->pgno, &rc);
59055
+ }
59056
+ if( szCell[i]>pNew->minLocal ){
59057
+ ptrmapPutOvflPtr(pNew, apCell[i], &rc);
59058
+ }
59059
+ }
59060
+ }
59061
+
59062
+ if( !leafCorrection ){
59063
+ for(i=0; i<nNew; i++){
59064
+ u32 key = get4byte(&apNew[i]->aData[8]);
59065
+ ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc);
59066
+ }
59067
+ }
5960759068
5960859069
#if 0
59609
- if( ISAUTOVACUUM && rc==SQLITE_OK && apNew[0]->isInit ){
5961059070
/* The ptrmapCheckPages() contains assert() statements that verify that
5961159071
** all pointer map pages are set correctly. This is helpful while
5961259072
** debugging. This is usually disabled because a corrupt database may
5961359073
** cause an assert() statement to fail. */
5961459074
ptrmapCheckPages(apNew, nNew);
5961559075
ptrmapCheckPages(&pParent, 1);
59076
+#endif
5961659077
}
59617
-#endif
59078
+
59079
+ assert( pParent->isInit );
59080
+ TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n",
59081
+ nOld, nNew, nCell));
5961859082
5961959083
/*
5962059084
** Cleanup before returning.
5962159085
*/
5962259086
balance_cleanup:
@@ -61438,15 +60902,10 @@
6143860902
*/
6143960903
SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){
6144060904
return (p->pBt->btsFlags & BTS_READ_ONLY)!=0;
6144160905
}
6144260906
61443
-/*
61444
-** Return the size of the header added to each page by this module.
61445
-*/
61446
-SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); }
61447
-
6144860907
/************** End of btree.c ***********************************************/
6144960908
/************** Begin file backup.c ******************************************/
6145060909
/*
6145160910
** 2009 January 28
6145260911
**
@@ -61583,17 +61042,10 @@
6158361042
sqlite3* pSrcDb, /* Database connection to read from */
6158461043
const char *zSrcDb /* Name of database within pSrcDb */
6158561044
){
6158661045
sqlite3_backup *p; /* Value to return */
6158761046
61588
-#ifdef SQLITE_ENABLE_API_ARMOR
61589
- if( !sqlite3SafetyCheckOk(pSrcDb)||!sqlite3SafetyCheckOk(pDestDb) ){
61590
- (void)SQLITE_MISUSE_BKPT;
61591
- return 0;
61592
- }
61593
-#endif
61594
-
6159561047
/* Lock the source database handle. The destination database
6159661048
** handle is not locked in this routine, but it is locked in
6159761049
** sqlite3_backup_step(). The user is required to ensure that no
6159861050
** other thread accesses the destination handle for the duration
6159961051
** of the backup operation. Any attempt to use the destination
@@ -61786,13 +61238,10 @@
6178661238
int rc;
6178761239
int destMode; /* Destination journal mode */
6178861240
int pgszSrc = 0; /* Source page size */
6178961241
int pgszDest = 0; /* Destination page size */
6179061242
61791
-#ifdef SQLITE_ENABLE_API_ARMOR
61792
- if( p==0 ) return SQLITE_MISUSE_BKPT;
61793
-#endif
6179461243
sqlite3_mutex_enter(p->pSrcDb->mutex);
6179561244
sqlite3BtreeEnter(p->pSrc);
6179661245
if( p->pDestDb ){
6179761246
sqlite3_mutex_enter(p->pDestDb->mutex);
6179861247
}
@@ -62078,30 +61527,18 @@
6207861527
/*
6207961528
** Return the number of pages still to be backed up as of the most recent
6208061529
** call to sqlite3_backup_step().
6208161530
*/
6208261531
SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p){
62083
-#ifdef SQLITE_ENABLE_API_ARMOR
62084
- if( p==0 ){
62085
- (void)SQLITE_MISUSE_BKPT;
62086
- return 0;
62087
- }
62088
-#endif
6208961532
return p->nRemaining;
6209061533
}
6209161534
6209261535
/*
6209361536
** Return the total number of pages in the source database as of the most
6209461537
** recent call to sqlite3_backup_step().
6209561538
*/
6209661539
SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p){
62097
-#ifdef SQLITE_ENABLE_API_ARMOR
62098
- if( p==0 ){
62099
- (void)SQLITE_MISUSE_BKPT;
62100
- return 0;
62101
- }
62102
-#endif
6210361540
return p->nPagecount;
6210461541
}
6210561542
6210661543
/*
6210761544
** This function is called after the contents of page iPage of the
@@ -64388,38 +63825,10 @@
6438863825
}
6438963826
p->nOp += nOp;
6439063827
}
6439163828
return addr;
6439263829
}
64393
-
64394
-#if defined(SQLITE_ENABLE_STMT_SCANSTATUS)
64395
-/*
64396
-** Add an entry to the array of counters managed by sqlite3_stmt_scanstatus().
64397
-*/
64398
-SQLITE_PRIVATE void sqlite3VdbeScanStatus(
64399
- Vdbe *p, /* VM to add scanstatus() to */
64400
- int addrExplain, /* Address of OP_Explain (or 0) */
64401
- int addrLoop, /* Address of loop counter */
64402
- int addrVisit, /* Address of rows visited counter */
64403
- LogEst nEst, /* Estimated number of output rows */
64404
- const char *zName /* Name of table or index being scanned */
64405
-){
64406
- int nByte = (p->nScan+1) * sizeof(ScanStatus);
64407
- ScanStatus *aNew;
64408
- aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
64409
- if( aNew ){
64410
- ScanStatus *pNew = &aNew[p->nScan++];
64411
- pNew->addrExplain = addrExplain;
64412
- pNew->addrLoop = addrLoop;
64413
- pNew->addrVisit = addrVisit;
64414
- pNew->nEst = nEst;
64415
- pNew->zName = sqlite3DbStrDup(p->db, zName);
64416
- p->aScan = aNew;
64417
- }
64418
-}
64419
-#endif
64420
-
6442163830
6442263831
/*
6442363832
** Change the value of the P1 operand for a specific instruction.
6442463833
** This routine is useful when a large program is loaded from a
6442563834
** static array using sqlite3VdbeAddOpList but we want to make a
@@ -65515,13 +64924,10 @@
6551564924
p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte);
6551664925
p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte);
6551764926
p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*),
6551864927
&zCsr, zEnd, &nByte);
6551964928
p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, &zCsr, zEnd, &nByte);
65520
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
65521
- p->anExec = allocSpace(p->anExec, p->nOp*sizeof(i64), &zCsr, zEnd, &nByte);
65522
-#endif
6552364929
if( nByte ){
6552464930
p->pFree = sqlite3DbMallocZero(db, nByte);
6552564931
}
6552664932
zCsr = p->pFree;
6552764933
zEnd = &zCsr[nByte];
@@ -65585,13 +64991,10 @@
6558564991
** is used, for example, when a trigger sub-program is halted to restore
6558664992
** control to the main program.
6558764993
*/
6558864994
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
6558964995
Vdbe *v = pFrame->v;
65590
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
65591
- v->anExec = pFrame->anExec;
65592
-#endif
6559364996
v->aOnceFlag = pFrame->aOnceFlag;
6559464997
v->nOnceFlag = pFrame->nOnceFlag;
6559564998
v->aOp = pFrame->aOp;
6559664999
v->nOp = pFrame->nOp;
6559765000
v->aMem = pFrame->aMem;
@@ -65598,11 +65001,10 @@
6559865001
v->nMem = pFrame->nMem;
6559965002
v->apCsr = pFrame->apCsr;
6560065003
v->nCursor = pFrame->nCursor;
6560165004
v->db->lastRowid = pFrame->lastRowid;
6560265005
v->nChange = pFrame->nChange;
65603
- v->db->nChange = pFrame->nDbChange;
6560465006
return pFrame->pc;
6560565007
}
6560665008
6560765009
/*
6560865010
** Close all cursors.
@@ -66166,11 +65568,10 @@
6616665568
** so, abort any other statements this handle currently has active.
6616765569
*/
6616865570
sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
6616965571
sqlite3CloseSavepoints(db);
6617065572
db->autoCommit = 1;
66171
- p->nChange = 0;
6617265573
}
6617365574
}
6617465575
}
6617565576
6617665577
/* Check for immediate foreign key violations. */
@@ -66207,20 +65608,18 @@
6620765608
sqlite3VdbeLeave(p);
6620865609
return SQLITE_BUSY;
6620965610
}else if( rc!=SQLITE_OK ){
6621065611
p->rc = rc;
6621165612
sqlite3RollbackAll(db, SQLITE_OK);
66212
- p->nChange = 0;
6621365613
}else{
6621465614
db->nDeferredCons = 0;
6621565615
db->nDeferredImmCons = 0;
6621665616
db->flags &= ~SQLITE_DeferFKs;
6621765617
sqlite3CommitInternalChanges(db);
6621865618
}
6621965619
}else{
6622065620
sqlite3RollbackAll(db, SQLITE_OK);
66221
- p->nChange = 0;
6622265621
}
6622365622
db->nStatement = 0;
6622465623
}else if( eStatementOp==0 ){
6622565624
if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){
6622665625
eStatementOp = SAVEPOINT_RELEASE;
@@ -66228,11 +65627,10 @@
6622865627
eStatementOp = SAVEPOINT_ROLLBACK;
6622965628
}else{
6623065629
sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
6623165630
sqlite3CloseSavepoints(db);
6623265631
db->autoCommit = 1;
66233
- p->nChange = 0;
6623465632
}
6623565633
}
6623665634
6623765635
/* If eStatementOp is non-zero, then a statement transaction needs to
6623865636
** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
@@ -66249,11 +65647,10 @@
6624965647
p->zErrMsg = 0;
6625065648
}
6625165649
sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
6625265650
sqlite3CloseSavepoints(db);
6625365651
db->autoCommit = 1;
66254
- p->nChange = 0;
6625565652
}
6625665653
}
6625765654
6625865655
/* If this was an INSERT, UPDATE or DELETE and no statement transaction
6625965656
** has been rolled back, update the database connection change-counter.
@@ -66511,16 +65908,10 @@
6651165908
for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
6651265909
vdbeFreeOpArray(db, p->aOp, p->nOp);
6651365910
sqlite3DbFree(db, p->aColName);
6651465911
sqlite3DbFree(db, p->zSql);
6651565912
sqlite3DbFree(db, p->pFree);
66516
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
66517
- for(i=0; i<p->nScan; i++){
66518
- sqlite3DbFree(db, p->aScan[i].zName);
66519
- }
66520
- sqlite3DbFree(db, p->aScan);
66521
-#endif
6652265913
}
6652365914
6652465915
/*
6652565916
** Delete an entire VDBE.
6652665917
*/
@@ -68884,23 +68275,15 @@
6888468275
sqlite3_stmt *pStmt,
6888568276
int N,
6888668277
const void *(*xFunc)(Mem*),
6888768278
int useType
6888868279
){
68889
- const void *ret;
68890
- Vdbe *p;
68280
+ const void *ret = 0;
68281
+ Vdbe *p = (Vdbe *)pStmt;
6889168282
int n;
68892
- sqlite3 *db;
68893
-#ifdef SQLITE_ENABLE_API_ARMOR
68894
- if( pStmt==0 ){
68895
- (void)SQLITE_MISUSE_BKPT;
68896
- return 0;
68897
- }
68898
-#endif
68899
- ret = 0;
68900
- p = (Vdbe *)pStmt;
68901
- db = p->db;
68283
+ sqlite3 *db = p->db;
68284
+
6890268285
assert( db!=0 );
6890368286
n = sqlite3_column_count(pStmt);
6890468287
if( N<n && N>=0 ){
6890568288
N += useType*n;
6890668289
sqlite3_mutex_enter(db->mutex);
@@ -69361,16 +68744,10 @@
6936168744
** prepared statement for the database connection. Return NULL if there
6936268745
** are no more.
6936368746
*/
6936468747
SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){
6936568748
sqlite3_stmt *pNext;
69366
-#ifdef SQLITE_ENABLE_API_ARMOR
69367
- if( !sqlite3SafetyCheckOk(pDb) ){
69368
- (void)SQLITE_MISUSE_BKPT;
69369
- return 0;
69370
- }
69371
-#endif
6937268749
sqlite3_mutex_enter(pDb->mutex);
6937368750
if( pStmt==0 ){
6937468751
pNext = (sqlite3_stmt*)pDb->pVdbe;
6937568752
}else{
6937668753
pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pNext;
@@ -69382,91 +68759,15 @@
6938268759
/*
6938368760
** Return the value of a status counter for a prepared statement
6938468761
*/
6938568762
SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){
6938668763
Vdbe *pVdbe = (Vdbe*)pStmt;
69387
- u32 v;
69388
-#ifdef SQLITE_ENABLE_API_ARMOR
69389
- if( !pStmt ){
69390
- (void)SQLITE_MISUSE_BKPT;
69391
- return 0;
69392
- }
69393
-#endif
69394
- v = pVdbe->aCounter[op];
68764
+ u32 v = pVdbe->aCounter[op];
6939568765
if( resetFlag ) pVdbe->aCounter[op] = 0;
6939668766
return (int)v;
6939768767
}
6939868768
69399
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
69400
-/*
69401
-** Return status data for a single loop within query pStmt.
69402
-*/
69403
-SQLITE_API int sqlite3_stmt_scanstatus(
69404
- sqlite3_stmt *pStmt, /* Prepared statement being queried */
69405
- int idx, /* Index of loop to report on */
69406
- int iScanStatusOp, /* Which metric to return */
69407
- void *pOut /* OUT: Write the answer here */
69408
-){
69409
- Vdbe *p = (Vdbe*)pStmt;
69410
- ScanStatus *pScan;
69411
- if( idx<0 || idx>=p->nScan ) return 1;
69412
- pScan = &p->aScan[idx];
69413
- switch( iScanStatusOp ){
69414
- case SQLITE_SCANSTAT_NLOOP: {
69415
- *(sqlite3_int64*)pOut = p->anExec[pScan->addrLoop];
69416
- break;
69417
- }
69418
- case SQLITE_SCANSTAT_NVISIT: {
69419
- *(sqlite3_int64*)pOut = p->anExec[pScan->addrVisit];
69420
- break;
69421
- }
69422
- case SQLITE_SCANSTAT_EST: {
69423
- double r = 1.0;
69424
- LogEst x = pScan->nEst;
69425
- while( x<100 ){
69426
- x += 10;
69427
- r *= 0.5;
69428
- }
69429
- *(double*)pOut = r*sqlite3LogEstToInt(x);
69430
- break;
69431
- }
69432
- case SQLITE_SCANSTAT_NAME: {
69433
- *(const char**)pOut = pScan->zName;
69434
- break;
69435
- }
69436
- case SQLITE_SCANSTAT_EXPLAIN: {
69437
- if( pScan->addrExplain ){
69438
- *(const char**)pOut = p->aOp[ pScan->addrExplain ].p4.z;
69439
- }else{
69440
- *(const char**)pOut = 0;
69441
- }
69442
- break;
69443
- }
69444
- case SQLITE_SCANSTAT_SELECTID: {
69445
- if( pScan->addrExplain ){
69446
- *(int*)pOut = p->aOp[ pScan->addrExplain ].p1;
69447
- }else{
69448
- *(int*)pOut = -1;
69449
- }
69450
- break;
69451
- }
69452
- default: {
69453
- return 1;
69454
- }
69455
- }
69456
- return 0;
69457
-}
69458
-
69459
-/*
69460
-** Zero all counters associated with the sqlite3_stmt_scanstatus() data.
69461
-*/
69462
-SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){
69463
- Vdbe *p = (Vdbe*)pStmt;
69464
- memset(p->anExec, 0, p->nOp * sizeof(i64));
69465
-}
69466
-#endif /* SQLITE_ENABLE_STMT_SCANSTATUS */
69467
-
6946868769
/************** End of vdbeapi.c *********************************************/
6946968770
/************** Begin file vdbetrace.c ***************************************/
6947068771
/*
6947168772
** 2009 November 25
6947268773
**
@@ -70348,13 +69649,10 @@
7034869649
#ifdef VDBE_PROFILE
7034969650
start = sqlite3Hwtime();
7035069651
#endif
7035169652
nVmStep++;
7035269653
pOp = &aOp[pc];
70353
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
70354
- if( p->anExec ) p->anExec[pc]++;
70355
-#endif
7035669654
7035769655
/* Only allow tracing if SQLITE_DEBUG is defined.
7035869656
*/
7035969657
#ifdef SQLITE_DEBUG
7036069658
if( db->flags & SQLITE_VdbeTrace ){
@@ -72570,12 +71868,14 @@
7257071868
int isSchemaChange;
7257171869
iSavepoint = db->nSavepoint - iSavepoint - 1;
7257271870
if( p1==SAVEPOINT_ROLLBACK ){
7257371871
isSchemaChange = (db->flags & SQLITE_InternChanges)!=0;
7257471872
for(ii=0; ii<db->nDb; ii++){
72575
- sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT,
71873
+ rc = sqlite3BtreeTripAllCursors(db->aDb[ii].pBt,
71874
+ SQLITE_ABORT_ROLLBACK,
7257671875
isSchemaChange==0);
71876
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
7257771877
}
7257871878
}else{
7257971879
isSchemaChange = 0;
7258071880
}
7258171881
for(ii=0; ii<db->nDb; ii++){
@@ -73543,15 +72843,14 @@
7354372843
}
7354472844
pIdxKey = &r;
7354572845
}else{
7354672846
pIdxKey = sqlite3VdbeAllocUnpackedRecord(
7354772847
pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
73548
- );
72848
+ );
7354972849
if( pIdxKey==0 ) goto no_mem;
7355072850
assert( pIn3->flags & MEM_Blob );
73551
- /* assert( (pIn3->flags & MEM_Zero)==0 ); // zeroblobs already expanded */
73552
- ExpandBlob(pIn3);
72851
+ assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
7355372852
sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
7355472853
}
7355572854
pIdxKey->default_rc = 0;
7355672855
if( pOp->opcode==OP_NoConflict ){
7355772856
/* For the OP_NoConflict opcode, take the jump if any of the
@@ -74147,10 +73446,14 @@
7414773446
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7414873447
}else{
7414973448
assert( pC->pCursor!=0 );
7415073449
rc = sqlite3VdbeCursorRestore(pC);
7415173450
if( rc ) goto abort_due_to_error;
73451
+ if( pC->nullRow ){
73452
+ pOut->flags = MEM_Null;
73453
+ break;
73454
+ }
7415273455
rc = sqlite3BtreeKeySize(pC->pCursor, &v);
7415373456
assert( rc==SQLITE_OK ); /* Always so because of CursorRestore() above */
7415473457
}
7415573458
pOut->u.i = v;
7415673459
break;
@@ -74237,13 +73540,13 @@
7423773540
}
7423873541
/* Opcode: Rewind P1 P2 * * *
7423973542
**
7424073543
** The next use of the Rowid or Column or Next instruction for P1
7424173544
** will refer to the first entry in the database table or index.
74242
-** If the table or index is empty, jump immediately to P2.
74243
-** If the table or index is not empty, fall through to the following
74244
-** instruction.
73545
+** If the table or index is empty and P2>0, then jump immediately to P2.
73546
+** If P2 is 0 or if the table or index is not empty, fall through
73547
+** to the following instruction.
7424573548
**
7424673549
** This opcode leaves the cursor configured to move in forward order,
7424773550
** from the beginning toward the end. In other words, the cursor is
7424873551
** configured to use Next, not Prev.
7424973552
*/
@@ -75155,13 +74458,10 @@
7515574458
pFrame->aOp = p->aOp;
7515674459
pFrame->nOp = p->nOp;
7515774460
pFrame->token = pProgram->token;
7515874461
pFrame->aOnceFlag = p->aOnceFlag;
7515974462
pFrame->nOnceFlag = p->nOnceFlag;
75160
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
75161
- pFrame->anExec = p->anExec;
75162
-#endif
7516374463
7516474464
pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
7516574465
for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
7516674466
pMem->flags = MEM_Undefined;
7516774467
pMem->db = db;
@@ -75175,11 +74475,10 @@
7517574475
7517674476
p->nFrame++;
7517774477
pFrame->pParent = p->pFrame;
7517874478
pFrame->lastRowid = lastRowid;
7517974479
pFrame->nChange = p->nChange;
75180
- pFrame->nDbChange = p->db->nChange;
7518174480
p->nChange = 0;
7518274481
p->pFrame = pFrame;
7518374482
p->aMem = aMem = &VdbeFrameMem(pFrame)[-1];
7518474483
p->nMem = pFrame->nChildMem;
7518574484
p->nCursor = (u16)pFrame->nChildCsr;
@@ -75186,13 +74485,10 @@
7518674485
p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
7518774486
p->aOp = aOp = pProgram->aOp;
7518874487
p->nOp = pProgram->nOp;
7518974488
p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
7519074489
p->nOnceFlag = pProgram->nOnce;
75191
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
75192
- p->anExec = 0;
75193
-#endif
7519474490
pc = -1;
7519574491
memset(p->aOnceFlag, 0, p->nOnceFlag);
7519674492
7519774493
break;
7519874494
}
@@ -76377,15 +75673,10 @@
7637775673
char *zErr = 0;
7637875674
Table *pTab;
7637975675
Parse *pParse = 0;
7638075676
Incrblob *pBlob = 0;
7638175677
76382
-#ifdef SQLITE_ENABLE_API_ARMOR
76383
- if( !sqlite3SafetyCheckOk(db) || ppBlob==0 || zTable==0 ){
76384
- return SQLITE_MISUSE_BKPT;
76385
- }
76386
-#endif
7638775678
flags = !!flags; /* flags = (flags ? 1 : 0); */
7638875679
*ppBlob = 0;
7638975680
7639075681
sqlite3_mutex_enter(db->mutex);
7639175682
@@ -76600,10 +75891,11 @@
7660075891
v = (Vdbe*)p->pStmt;
7660175892
7660275893
if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){
7660375894
/* Request is out of range. Return a transient error. */
7660475895
rc = SQLITE_ERROR;
75896
+ sqlite3Error(db, SQLITE_ERROR);
7660575897
}else if( v==0 ){
7660675898
/* If there is no statement handle, then the blob-handle has
7660775899
** already been invalidated. Return SQLITE_ABORT in this case.
7660875900
*/
7660975901
rc = SQLITE_ABORT;
@@ -76617,14 +75909,14 @@
7661775909
sqlite3BtreeLeaveCursor(p->pCsr);
7661875910
if( rc==SQLITE_ABORT ){
7661975911
sqlite3VdbeFinalize(v);
7662075912
p->pStmt = 0;
7662175913
}else{
75914
+ db->errCode = rc;
7662275915
v->rc = rc;
7662375916
}
7662475917
}
76625
- sqlite3Error(db, rc);
7662675918
rc = sqlite3ApiExit(db, rc);
7662775919
sqlite3_mutex_leave(db->mutex);
7662875920
return rc;
7662975921
}
7663075922
@@ -76797,11 +76089,11 @@
7679776089
** itself.
7679876090
**
7679976091
** The sorter is running in multi-threaded mode if (a) the library was built
7680076092
** with pre-processor symbol SQLITE_MAX_WORKER_THREADS set to a value greater
7680176093
** than zero, and (b) worker threads have been enabled at runtime by calling
76802
-** "PRAGMA threads=N" with some value of N greater than 0.
76094
+** sqlite3_config(SQLITE_CONFIG_WORKER_THREADS, ...).
7680376095
**
7680476096
** When Rewind() is called, any data remaining in memory is flushed to a
7680576097
** final PMA. So at this point the data is stored in some number of sorted
7680676098
** PMAs within temporary files on disk.
7680776099
**
@@ -77542,13 +76834,15 @@
7754276834
pSorter->mnPmaSize = SORTER_MIN_WORKING * pgsz;
7754376835
mxCache = db->aDb[0].pSchema->cache_size;
7754476836
if( mxCache<SORTER_MIN_WORKING ) mxCache = SORTER_MIN_WORKING;
7754576837
pSorter->mxPmaSize = mxCache * pgsz;
7754676838
77547
- /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
77548
- ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
77549
- ** large heap allocations.
76839
+ /* If the application has not configure scratch memory using
76840
+ ** SQLITE_CONFIG_SCRATCH then we assume it is OK to do large memory
76841
+ ** allocations. If scratch memory has been configured, then assume
76842
+ ** large memory allocations should be avoided to prevent heap
76843
+ ** fragmentation.
7755076844
*/
7755176845
if( sqlite3GlobalConfig.pScratch==0 ){
7755276846
assert( pSorter->iMemory==0 );
7755376847
pSorter->nMemory = pgsz;
7755476848
pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
@@ -79916,19 +79210,19 @@
7991679210
**
7991779211
** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..)
7991879212
** is a helper function - a callback for the tree walker.
7991979213
*/
7992079214
static int incrAggDepth(Walker *pWalker, Expr *pExpr){
79921
- if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.n;
79215
+ if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.i;
7992279216
return WRC_Continue;
7992379217
}
7992479218
static void incrAggFunctionDepth(Expr *pExpr, int N){
7992579219
if( N>0 ){
7992679220
Walker w;
7992779221
memset(&w, 0, sizeof(w));
7992879222
w.xExprCallback = incrAggDepth;
79929
- w.u.n = N;
79223
+ w.u.i = N;
7993079224
sqlite3WalkExpr(&w, pExpr);
7993179225
}
7993279226
}
7993379227
7993479228
/*
@@ -80472,11 +79766,11 @@
8047279766
double r = -1.0;
8047379767
if( p->op!=TK_FLOAT ) return -1;
8047479768
sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
8047579769
assert( r>=0.0 );
8047679770
if( r>1.0 ) return -1;
80477
- return (int)(r*134217728.0);
79771
+ return (int)(r*1000.0);
8047879772
}
8047979773
8048079774
/*
8048179775
** This routine is callback for sqlite3WalkExpr().
8048279776
**
@@ -80604,11 +79898,11 @@
8060479898
** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand for
8060579899
** likelihood(X,0.9375).
8060679900
** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent to
8060779901
** likelihood(X,0.9375). */
8060879902
/* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
80609
- pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120;
79903
+ pExpr->iTable = pDef->zName[0]=='u' ? 62 : 938;
8061079904
}
8061179905
}
8061279906
#ifndef SQLITE_OMIT_AUTHORIZATION
8061379907
auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
8061479908
if( auth!=SQLITE_OK ){
@@ -82561,79 +81855,69 @@
8256181855
sqlite3DbFree(db, pList->a);
8256281856
sqlite3DbFree(db, pList);
8256381857
}
8256481858
8256581859
/*
82566
-** These routines are Walker callbacks used to check expressions to
82567
-** see if they are "constant" for some definition of constant. The
82568
-** Walker.eCode value determines the type of "constant" we are looking
82569
-** for.
81860
+** These routines are Walker callbacks. Walker.u.pi is a pointer
81861
+** to an integer. These routines are checking an expression to see
81862
+** if it is a constant. Set *Walker.u.i to 0 if the expression is
81863
+** not constant.
8257081864
**
8257181865
** These callback routines are used to implement the following:
8257281866
**
82573
-** sqlite3ExprIsConstant() pWalker->eCode==1
82574
-** sqlite3ExprIsConstantNotJoin() pWalker->eCode==2
82575
-** sqlite3ExprRefOneTableOnly() pWalker->eCode==3
82576
-** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5
82577
-**
82578
-** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
82579
-** is found to not be a constant.
81867
+** sqlite3ExprIsConstant() pWalker->u.i==1
81868
+** sqlite3ExprIsConstantNotJoin() pWalker->u.i==2
81869
+** sqlite3ExprIsConstantOrFunction() pWalker->u.i==3 or 4
8258081870
**
8258181871
** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions
82582
-** in a CREATE TABLE statement. The Walker.eCode value is 5 when parsing
82583
-** an existing schema and 4 when processing a new statement. A bound
81872
+** in a CREATE TABLE statement. The Walker.u.i value is 4 when parsing
81873
+** an existing schema and 3 when processing a new statement. A bound
8258481874
** parameter raises an error for new statements, but is silently converted
8258581875
** to NULL for existing schemas. This allows sqlite_master tables that
8258681876
** contain a bound parameter because they were generated by older versions
8258781877
** of SQLite to be parsed by newer versions of SQLite without raising a
8258881878
** malformed schema error.
8258981879
*/
8259081880
static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
8259181881
82592
- /* If pWalker->eCode is 2 then any term of the expression that comes from
82593
- ** the ON or USING clauses of a left join disqualifies the expression
81882
+ /* If pWalker->u.i is 2 then any term of the expression that comes from
81883
+ ** the ON or USING clauses of a join disqualifies the expression
8259481884
** from being considered constant. */
82595
- if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
82596
- pWalker->eCode = 0;
81885
+ if( pWalker->u.i==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
81886
+ pWalker->u.i = 0;
8259781887
return WRC_Abort;
8259881888
}
8259981889
8260081890
switch( pExpr->op ){
8260181891
/* Consider functions to be constant if all their arguments are constant
82602
- ** and either pWalker->eCode==4 or 5 or the function has the
82603
- ** SQLITE_FUNC_CONST flag. */
81892
+ ** and either pWalker->u.i==3 or 4 or the function as the SQLITE_FUNC_CONST
81893
+ ** flag. */
8260481894
case TK_FUNCTION:
82605
- if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_Constant) ){
81895
+ if( pWalker->u.i>=3 || ExprHasProperty(pExpr,EP_Constant) ){
8260681896
return WRC_Continue;
82607
- }else{
82608
- pWalker->eCode = 0;
82609
- return WRC_Abort;
8261081897
}
81898
+ /* Fall through */
8261181899
case TK_ID:
8261281900
case TK_COLUMN:
8261381901
case TK_AGG_FUNCTION:
8261481902
case TK_AGG_COLUMN:
8261581903
testcase( pExpr->op==TK_ID );
8261681904
testcase( pExpr->op==TK_COLUMN );
8261781905
testcase( pExpr->op==TK_AGG_FUNCTION );
8261881906
testcase( pExpr->op==TK_AGG_COLUMN );
82619
- if( pWalker->eCode==3 && pExpr->iTable==pWalker->u.iCur ){
82620
- return WRC_Continue;
82621
- }else{
82622
- pWalker->eCode = 0;
82623
- return WRC_Abort;
82624
- }
81907
+ pWalker->u.i = 0;
81908
+ return WRC_Abort;
8262581909
case TK_VARIABLE:
82626
- if( pWalker->eCode==5 ){
81910
+ if( pWalker->u.i==4 ){
8262781911
/* Silently convert bound parameters that appear inside of CREATE
8262881912
** statements into a NULL when parsing the CREATE statement text out
8262981913
** of the sqlite_master table */
8263081914
pExpr->op = TK_NULL;
82631
- }else if( pWalker->eCode==4 ){
81915
+ }else if( pWalker->u.i==3 ){
8263281916
/* A bound parameter in a CREATE statement that originates from
8263381917
** sqlite3_prepare() causes an error */
82634
- pWalker->eCode = 0;
81918
+ pWalker->u.i = 0;
8263581919
return WRC_Abort;
8263681920
}
8263781921
/* Fall through */
8263881922
default:
8263981923
testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */
@@ -82641,68 +81925,57 @@
8264181925
return WRC_Continue;
8264281926
}
8264381927
}
8264481928
static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){
8264581929
UNUSED_PARAMETER(NotUsed);
82646
- pWalker->eCode = 0;
81930
+ pWalker->u.i = 0;
8264781931
return WRC_Abort;
8264881932
}
82649
-static int exprIsConst(Expr *p, int initFlag, int iCur){
81933
+static int exprIsConst(Expr *p, int initFlag){
8265081934
Walker w;
8265181935
memset(&w, 0, sizeof(w));
82652
- w.eCode = initFlag;
81936
+ w.u.i = initFlag;
8265381937
w.xExprCallback = exprNodeIsConstant;
8265481938
w.xSelectCallback = selectNodeIsConstant;
82655
- w.u.iCur = iCur;
8265681939
sqlite3WalkExpr(&w, p);
82657
- return w.eCode;
81940
+ return w.u.i;
8265881941
}
8265981942
8266081943
/*
82661
-** Walk an expression tree. Return non-zero if the expression is constant
81944
+** Walk an expression tree. Return 1 if the expression is constant
8266281945
** and 0 if it involves variables or function calls.
8266381946
**
8266481947
** For the purposes of this function, a double-quoted string (ex: "abc")
8266581948
** is considered a variable but a single-quoted string (ex: 'abc') is
8266681949
** a constant.
8266781950
*/
8266881951
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr *p){
82669
- return exprIsConst(p, 1, 0);
81952
+ return exprIsConst(p, 1);
8267081953
}
8267181954
8267281955
/*
82673
-** Walk an expression tree. Return non-zero if the expression is constant
81956
+** Walk an expression tree. Return 1 if the expression is constant
8267481957
** that does no originate from the ON or USING clauses of a join.
8267581958
** Return 0 if it involves variables or function calls or terms from
8267681959
** an ON or USING clause.
8267781960
*/
8267881961
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *p){
82679
- return exprIsConst(p, 2, 0);
81962
+ return exprIsConst(p, 2);
8268081963
}
8268181964
8268281965
/*
82683
-** Walk an expression tree. Return non-zero if the expression constant
82684
-** for any single row of the table with cursor iCur. In other words, the
82685
-** expression must not refer to any non-deterministic function nor any
82686
-** table other than iCur.
82687
-*/
82688
-SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
82689
- return exprIsConst(p, 3, iCur);
82690
-}
82691
-
82692
-/*
82693
-** Walk an expression tree. Return non-zero if the expression is constant
81966
+** Walk an expression tree. Return 1 if the expression is constant
8269481967
** or a function call with constant arguments. Return and 0 if there
8269581968
** are any variables.
8269681969
**
8269781970
** For the purposes of this function, a double-quoted string (ex: "abc")
8269881971
** is considered a variable but a single-quoted string (ex: 'abc') is
8269981972
** a constant.
8270081973
*/
8270181974
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){
8270281975
assert( isInit==0 || isInit==1 );
82703
- return exprIsConst(p, 4+isInit, 0);
81976
+ return exprIsConst(p, 3+isInit);
8270481977
}
8270581978
8270681979
/*
8270781980
** If the expression p codes a constant integer that is small enough
8270881981
** to fit in a 32-bit integer, return 1 and put the value of the integer
@@ -83208,11 +82481,10 @@
8320882481
sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
8320982482
dest.affSdst = (u8)affinity;
8321082483
assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
8321182484
pSelect->iLimit = 0;
8321282485
testcase( pSelect->selFlags & SF_Distinct );
83213
- pSelect->selFlags &= ~SF_Distinct;
8321482486
testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
8321582487
if( sqlite3Select(pParse, pSelect, &dest) ){
8321682488
sqlite3KeyInfoUnref(pKeyInfo);
8321782489
return 0;
8321882490
}
@@ -88149,11 +87421,10 @@
8814987421
nSample--;
8815087422
}else{
8815187423
nRow = pIdx->aiRowEst[0];
8815287424
nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
8815387425
}
88154
- pIdx->nRowEst0 = nRow;
8815587426
8815687427
/* Set nSum to the number of distinct (iCol+1) field prefixes that
8815787428
** occur in the stat4 table for this index. Set sumEq to the sum of
8815887429
** the nEq values for column iCol for the same set (adding the value
8815987430
** only once where there exist duplicate prefixes). */
@@ -88411,11 +87682,11 @@
8841187682
}
8841287683
8841387684
8841487685
/* Load the statistics from the sqlite_stat4 table. */
8841587686
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
88416
- if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){
87687
+ if( rc==SQLITE_OK ){
8841787688
int lookasideEnabled = db->lookaside.bEnabled;
8841887689
db->lookaside.bEnabled = 0;
8841987690
rc = loadStat4(db, sInfo.zDatabase);
8842087691
db->lookaside.bEnabled = lookasideEnabled;
8842187692
}
@@ -89093,13 +88364,10 @@
8909388364
SQLITE_API int sqlite3_set_authorizer(
8909488365
sqlite3 *db,
8909588366
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
8909688367
void *pArg
8909788368
){
89098
-#ifdef SQLITE_ENABLE_API_ARMOR
89099
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
89100
-#endif
8910188369
sqlite3_mutex_enter(db->mutex);
8910288370
db->xAuth = (sqlite3_xauth)xAuth;
8910388371
db->pAuthArg = pArg;
8910488372
sqlite3ExpirePreparedStatements(db);
8910588373
sqlite3_mutex_leave(db->mutex);
@@ -89590,15 +88858,11 @@
8959088858
** See also sqlite3LocateTable().
8959188859
*/
8959288860
SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
8959388861
Table *p = 0;
8959488862
int i;
89595
-
89596
-#ifdef SQLITE_ENABLE_API_ARMOR
89597
- if( !sqlite3SafetyCheckOk(db) || zName==0 ) return 0;
89598
-#endif
89599
-
88863
+ assert( zName!=0 );
8960088864
/* All mutexes are required for schema access. Make sure we hold them. */
8960188865
assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
8960288866
#if SQLITE_USER_AUTHENTICATION
8960388867
/* Only the admin user is allowed to know that the sqlite_user table
8960488868
** exists */
@@ -104617,16 +103881,13 @@
104617103881
Vdbe *pOld, /* VM being reprepared */
104618103882
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
104619103883
const char **pzTail /* OUT: End of parsed string */
104620103884
){
104621103885
int rc;
104622
-
104623
-#ifdef SQLITE_ENABLE_API_ARMOR
104624
- if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
104625
-#endif
103886
+ assert( ppStmt!=0 );
104626103887
*ppStmt = 0;
104627
- if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
103888
+ if( !sqlite3SafetyCheckOk(db) ){
104628103889
return SQLITE_MISUSE_BKPT;
104629103890
}
104630103891
sqlite3_mutex_enter(db->mutex);
104631103892
sqlite3BtreeEnterAll(db);
104632103893
rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
@@ -104729,15 +103990,13 @@
104729103990
*/
104730103991
char *zSql8;
104731103992
const char *zTail8 = 0;
104732103993
int rc = SQLITE_OK;
104733103994
104734
-#ifdef SQLITE_ENABLE_API_ARMOR
104735
- if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
104736
-#endif
103995
+ assert( ppStmt );
104737103996
*ppStmt = 0;
104738
- if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
103997
+ if( !sqlite3SafetyCheckOk(db) ){
104739103998
return SQLITE_MISUSE_BKPT;
104740103999
}
104741104000
if( nBytes>=0 ){
104742104001
int sz;
104743104002
const char *z = (const char*)zSql;
@@ -110446,13 +109705,10 @@
110446109705
char **pzErrMsg /* Write error messages here */
110447109706
){
110448109707
int rc;
110449109708
TabResult res;
110450109709
110451
-#ifdef SQLITE_ENABLE_API_ARMOR
110452
- if( pazResult==0 ) return SQLITE_MISUSE_BKPT;
110453
-#endif
110454109710
*pazResult = 0;
110455109711
if( pnColumn ) *pnColumn = 0;
110456109712
if( pnRow ) *pnRow = 0;
110457109713
if( pzErrMsg ) *pzErrMsg = 0;
110458109714
res.zErrMsg = 0;
@@ -112512,11 +111768,11 @@
112512111768
** Two writes per page are required in step (3) because the original
112513111769
** database content must be written into the rollback journal prior to
112514111770
** overwriting the database with the vacuumed content.
112515111771
**
112516111772
** Only 1x temporary space and only 1x writes would be required if
112517
-** the copy of step (3) were replaced by deleting the original database
111773
+** the copy of step (3) were replace by deleting the original database
112518111774
** and renaming the transient database as the original. But that will
112519111775
** not work if other processes are attached to the original database.
112520111776
** And a power loss in between deleting the original and renaming the
112521111777
** transient would cause the database file to appear to be deleted
112522111778
** following reboot.
@@ -112870,13 +112126,10 @@
112870112126
sqlite3 *db, /* Database in which module is registered */
112871112127
const char *zName, /* Name assigned to this module */
112872112128
const sqlite3_module *pModule, /* The definition of the module */
112873112129
void *pAux /* Context pointer for xCreate/xConnect */
112874112130
){
112875
-#ifdef SQLITE_ENABLE_API_ARMOR
112876
- if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
112877
-#endif
112878112131
return createModule(db, zName, pModule, pAux, 0);
112879112132
}
112880112133
112881112134
/*
112882112135
** External API function used to create a new virtual-table module.
@@ -112886,13 +112139,10 @@
112886112139
const char *zName, /* Name assigned to this module */
112887112140
const sqlite3_module *pModule, /* The definition of the module */
112888112141
void *pAux, /* Context pointer for xCreate/xConnect */
112889112142
void (*xDestroy)(void *) /* Module destructor function */
112890112143
){
112891
-#ifdef SQLITE_ENABLE_API_ARMOR
112892
- if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
112893
-#endif
112894112144
return createModule(db, zName, pModule, pAux, xDestroy);
112895112145
}
112896112146
112897112147
/*
112898112148
** Lock the virtual table so that it cannot be disconnected.
@@ -113493,13 +112743,10 @@
113493112743
113494112744
int rc = SQLITE_OK;
113495112745
Table *pTab;
113496112746
char *zErr = 0;
113497112747
113498
-#ifdef SQLITE_ENABLE_API_ARMOR
113499
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
113500
-#endif
113501112748
sqlite3_mutex_enter(db->mutex);
113502112749
if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
113503112750
sqlite3Error(db, SQLITE_MISUSE);
113504112751
sqlite3_mutex_leave(db->mutex);
113505112752
return SQLITE_MISUSE_BKPT;
@@ -113852,13 +113099,10 @@
113852113099
*/
113853113100
SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){
113854113101
static const unsigned char aMap[] = {
113855113102
SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE
113856113103
};
113857
-#ifdef SQLITE_ENABLE_API_ARMOR
113858
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
113859
-#endif
113860113104
assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 );
113861113105
assert( OE_Ignore==4 && OE_Replace==5 );
113862113106
assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 );
113863113107
return (int)aMap[db->vtabOnConflict-1];
113864113108
}
@@ -113870,14 +113114,12 @@
113870113114
*/
113871113115
SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){
113872113116
va_list ap;
113873113117
int rc = SQLITE_OK;
113874113118
113875
-#ifdef SQLITE_ENABLE_API_ARMOR
113876
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
113877
-#endif
113878113119
sqlite3_mutex_enter(db->mutex);
113120
+
113879113121
va_start(ap, op);
113880113122
switch( op ){
113881113123
case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
113882113124
VtabCtx *p = db->pVtabCtx;
113883113125
if( !p ){
@@ -114008,13 +113250,10 @@
114008113250
} in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
114009113251
Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
114010113252
} u;
114011113253
struct WhereLoop *pWLoop; /* The selected WhereLoop object */
114012113254
Bitmask notReady; /* FROM entries not usable at this level */
114013
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
114014
- int addrVisit; /* Address at which row is visited */
114015
-#endif
114016113255
};
114017113256
114018113257
/*
114019113258
** Each instance of this object represents an algorithm for evaluating one
114020113259
** term of a join. Every term of the FROM clause will have at least
@@ -114041,10 +113280,11 @@
114041113280
LogEst rRun; /* Cost of running each loop */
114042113281
LogEst nOut; /* Estimated number of output rows */
114043113282
union {
114044113283
struct { /* Information for internal btree tables */
114045113284
u16 nEq; /* Number of equality constraints */
113285
+ u16 nSkip; /* Number of initial index columns to skip */
114046113286
Index *pIndex; /* Index used, or NULL */
114047113287
} btree;
114048113288
struct { /* Information for virtual tables */
114049113289
int idxNum; /* Index number */
114050113290
u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -114053,17 +113293,16 @@
114053113293
char *idxStr; /* Index identifier string */
114054113294
} vtab;
114055113295
} u;
114056113296
u32 wsFlags; /* WHERE_* flags describing the plan */
114057113297
u16 nLTerm; /* Number of entries in aLTerm[] */
114058
- u16 nSkip; /* Number of NULL aLTerm[] entries */
114059113298
/**** whereLoopXfer() copies fields above ***********************/
114060113299
# define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot)
114061113300
u16 nLSlot; /* Number of slots allocated for aLTerm[] */
114062113301
WhereTerm **aLTerm; /* WhereTerms used */
114063113302
WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
114064
- WhereTerm *aLTermSpace[3]; /* Initial aLTerm[] space */
113303
+ WhereTerm *aLTermSpace[4]; /* Initial aLTerm[] space */
114065113304
};
114066113305
114067113306
/* This object holds the prerequisites and the cost of running a
114068113307
** subquery on one operand of an OR operator in the WHERE clause.
114069113308
** See WhereOrSet for additional information
@@ -114385,11 +113624,10 @@
114385113624
#define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
114386113625
#define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
114387113626
#define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
114388113627
#define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
114389113628
#define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
114390
-#define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */
114391113629
114392113630
/************** End of whereInt.h ********************************************/
114393113631
/************** Continuing where we left off in where.c **********************/
114394113632
114395113633
/*
@@ -114596,11 +113834,11 @@
114596113834
}
114597113835
pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
114598113836
}
114599113837
pTerm = &pWC->a[idx = pWC->nTerm++];
114600113838
if( p && ExprHasProperty(p, EP_Unlikely) ){
114601
- pTerm->truthProb = sqlite3LogEst(p->iTable) - 270;
113839
+ pTerm->truthProb = sqlite3LogEst(p->iTable) - 99;
114602113840
}else{
114603113841
pTerm->truthProb = 1;
114604113842
}
114605113843
pTerm->pExpr = sqlite3ExprSkipCollate(p);
114606113844
pTerm->wtFlags = wtFlags;
@@ -115127,19 +114365,10 @@
115127114365
pDerived->flags |= pBase->flags & EP_FromJoin;
115128114366
pDerived->iRightJoinTable = pBase->iRightJoinTable;
115129114367
}
115130114368
}
115131114369
115132
-/*
115133
-** Mark term iChild as being a child of term iParent
115134
-*/
115135
-static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){
115136
- pWC->a[iChild].iParent = iParent;
115137
- pWC->a[iChild].truthProb = pWC->a[iParent].truthProb;
115138
- pWC->a[iParent].nChild++;
115139
-}
115140
-
115141114370
#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
115142114371
/*
115143114372
** Analyze a term that consists of two or more OR-connected
115144114373
** subterms. So in:
115145114374
**
@@ -115433,11 +114662,12 @@
115433114662
pNew->x.pList = pList;
115434114663
idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
115435114664
testcase( idxNew==0 );
115436114665
exprAnalyze(pSrc, pWC, idxNew);
115437114666
pTerm = &pWC->a[idxTerm];
115438
- markTermAsChild(pWC, idxNew, idxTerm);
114667
+ pWC->a[idxNew].iParent = idxTerm;
114668
+ pTerm->nChild = 1;
115439114669
}else{
115440114670
sqlite3ExprListDelete(db, pList);
115441114671
}
115442114672
pTerm->eOperator = WO_NOOP; /* case 1 trumps case 2 */
115443114673
}
@@ -115535,12 +114765,13 @@
115535114765
return;
115536114766
}
115537114767
idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);
115538114768
if( idxNew==0 ) return;
115539114769
pNew = &pWC->a[idxNew];
115540
- markTermAsChild(pWC, idxNew, idxTerm);
114770
+ pNew->iParent = idxTerm;
115541114771
pTerm = &pWC->a[idxTerm];
114772
+ pTerm->nChild = 1;
115542114773
pTerm->wtFlags |= TERM_COPIED;
115543114774
if( pExpr->op==TK_EQ
115544114775
&& !ExprHasProperty(pExpr, EP_FromJoin)
115545114776
&& OptimizationEnabled(db, SQLITE_Transitive)
115546114777
){
@@ -115593,12 +114824,13 @@
115593114824
transferJoinMarkings(pNewExpr, pExpr);
115594114825
idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
115595114826
testcase( idxNew==0 );
115596114827
exprAnalyze(pSrc, pWC, idxNew);
115597114828
pTerm = &pWC->a[idxTerm];
115598
- markTermAsChild(pWC, idxNew, idxTerm);
114829
+ pWC->a[idxNew].iParent = idxTerm;
115599114830
}
114831
+ pTerm->nChild = 2;
115600114832
}
115601114833
#endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */
115602114834
115603114835
#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
115604114836
/* Analyze a term that is composed of two or more subterms connected by
@@ -115669,12 +114901,13 @@
115669114901
idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC);
115670114902
testcase( idxNew2==0 );
115671114903
exprAnalyze(pSrc, pWC, idxNew2);
115672114904
pTerm = &pWC->a[idxTerm];
115673114905
if( isComplete ){
115674
- markTermAsChild(pWC, idxNew1, idxTerm);
115675
- markTermAsChild(pWC, idxNew2, idxTerm);
114906
+ pWC->a[idxNew1].iParent = idxTerm;
114907
+ pWC->a[idxNew2].iParent = idxTerm;
114908
+ pTerm->nChild = 2;
115676114909
}
115677114910
}
115678114911
#endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
115679114912
115680114913
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -115703,12 +114936,13 @@
115703114936
pNewTerm = &pWC->a[idxNew];
115704114937
pNewTerm->prereqRight = prereqExpr;
115705114938
pNewTerm->leftCursor = pLeft->iTable;
115706114939
pNewTerm->u.leftColumn = pLeft->iColumn;
115707114940
pNewTerm->eOperator = WO_MATCH;
115708
- markTermAsChild(pWC, idxNew, idxTerm);
114941
+ pNewTerm->iParent = idxTerm;
115709114942
pTerm = &pWC->a[idxTerm];
114943
+ pTerm->nChild = 1;
115710114944
pTerm->wtFlags |= TERM_COPIED;
115711114945
pNewTerm->prereqAll = pTerm->prereqAll;
115712114946
}
115713114947
}
115714114948
#endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -115725,11 +114959,11 @@
115725114959
** the start of the loop will prevent any results from being returned.
115726114960
*/
115727114961
if( pExpr->op==TK_NOTNULL
115728114962
&& pExpr->pLeft->op==TK_COLUMN
115729114963
&& pExpr->pLeft->iColumn>=0
115730
- && OptimizationEnabled(db, SQLITE_Stat34)
114964
+ && OptimizationEnabled(db, SQLITE_Stat3)
115731114965
){
115732114966
Expr *pNewExpr;
115733114967
Expr *pLeft = pExpr->pLeft;
115734114968
int idxNew;
115735114969
WhereTerm *pNewTerm;
@@ -115744,12 +114978,13 @@
115744114978
pNewTerm = &pWC->a[idxNew];
115745114979
pNewTerm->prereqRight = 0;
115746114980
pNewTerm->leftCursor = pLeft->iTable;
115747114981
pNewTerm->u.leftColumn = pLeft->iColumn;
115748114982
pNewTerm->eOperator = WO_GT;
115749
- markTermAsChild(pWC, idxNew, idxTerm);
114983
+ pNewTerm->iParent = idxTerm;
115750114984
pTerm = &pWC->a[idxTerm];
114985
+ pTerm->nChild = 1;
115751114986
pTerm->wtFlags |= TERM_COPIED;
115752114987
pNewTerm->prereqAll = pTerm->prereqAll;
115753114988
}
115754114989
}
115755114990
#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
@@ -115965,12 +115200,10 @@
115965115200
WhereLoop *pLoop; /* The Loop object */
115966115201
char *zNotUsed; /* Extra space on the end of pIdx */
115967115202
Bitmask idxCols; /* Bitmap of columns used for indexing */
115968115203
Bitmask extraCols; /* Bitmap of additional columns */
115969115204
u8 sentWarning = 0; /* True if a warnning has been issued */
115970
- Expr *pPartial = 0; /* Partial Index Expression */
115971
- int iContinue = 0; /* Jump here to skip excluded rows */
115972115205
115973115206
/* Generate code to skip over the creation and initialization of the
115974115207
** transient index on 2nd and subsequent iterations of the loop. */
115975115208
v = pParse->pVdbe;
115976115209
assert( v!=0 );
@@ -115982,16 +115215,10 @@
115982115215
pTable = pSrc->pTab;
115983115216
pWCEnd = &pWC->a[pWC->nTerm];
115984115217
pLoop = pLevel->pWLoop;
115985115218
idxCols = 0;
115986115219
for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
115987
- if( pLoop->prereq==0
115988
- && (pTerm->wtFlags & TERM_VIRTUAL)==0
115989
- && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){
115990
- pPartial = sqlite3ExprAnd(pParse->db, pPartial,
115991
- sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
115992
- }
115993115220
if( termCanDriveIndex(pTerm, pSrc, notReady) ){
115994115221
int iCol = pTerm->u.leftColumn;
115995115222
Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
115996115223
testcase( iCol==BMS );
115997115224
testcase( iCol==BMS-1 );
@@ -116000,13 +115227,11 @@
116000115227
"automatic index on %s(%s)", pTable->zName,
116001115228
pTable->aCol[iCol].zName);
116002115229
sentWarning = 1;
116003115230
}
116004115231
if( (idxCols & cMask)==0 ){
116005
- if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){
116006
- goto end_auto_index_create;
116007
- }
115232
+ if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ) return;
116008115233
pLoop->aLTerm[nKeyCol++] = pTerm;
116009115234
idxCols |= cMask;
116010115235
}
116011115236
}
116012115237
}
@@ -116022,23 +115247,24 @@
116022115247
** be a covering index because the index will not be updated if the
116023115248
** original table changes and the index and table cannot both be used
116024115249
** if they go out of sync.
116025115250
*/
116026115251
extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
116027
- mxBitCol = MIN(BMS-1,pTable->nCol);
115252
+ mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol;
116028115253
testcase( pTable->nCol==BMS-1 );
116029115254
testcase( pTable->nCol==BMS-2 );
116030115255
for(i=0; i<mxBitCol; i++){
116031115256
if( extraCols & MASKBIT(i) ) nKeyCol++;
116032115257
}
116033115258
if( pSrc->colUsed & MASKBIT(BMS-1) ){
116034115259
nKeyCol += pTable->nCol - BMS + 1;
116035115260
}
115261
+ pLoop->wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY;
116036115262
116037115263
/* Construct the Index object to describe this index */
116038115264
pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
116039
- if( pIdx==0 ) goto end_auto_index_create;
115265
+ if( pIdx==0 ) return;
116040115266
pLoop->u.btree.pIndex = pIdx;
116041115267
pIdx->zName = "auto-index";
116042115268
pIdx->pTable = pTable;
116043115269
n = 0;
116044115270
idxCols = 0;
@@ -116086,33 +115312,22 @@
116086115312
sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
116087115313
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
116088115314
VdbeComment((v, "for %s", pTable->zName));
116089115315
116090115316
/* Fill the automatic index with content */
116091
- sqlite3ExprCachePush(pParse);
116092115317
addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
116093
- if( pPartial ){
116094
- iContinue = sqlite3VdbeMakeLabel(v);
116095
- sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL);
116096
- pLoop->wsFlags |= WHERE_PARTIALIDX;
116097
- }
116098115318
regRecord = sqlite3GetTempReg(pParse);
116099115319
sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
116100115320
sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
116101115321
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
116102
- if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
116103115322
sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
116104115323
sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
116105115324
sqlite3VdbeJumpHere(v, addrTop);
116106115325
sqlite3ReleaseTempReg(pParse, regRecord);
116107
- sqlite3ExprCachePop(pParse);
116108115326
116109115327
/* Jump here when skipping the initialization */
116110115328
sqlite3VdbeJumpHere(v, addrInit);
116111
-
116112
-end_auto_index_create:
116113
- sqlite3ExprDelete(pParse->db, pPartial);
116114115329
}
116115115330
#endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
116116115331
116117115332
#ifndef SQLITE_OMIT_VIRTUALTABLE
116118115333
/*
@@ -116267,23 +115482,23 @@
116267115482
}
116268115483
116269115484
return pParse->nErr;
116270115485
}
116271115486
#endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */
115487
+
116272115488
116273115489
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
116274115490
/*
116275115491
** Estimate the location of a particular key among all keys in an
116276115492
** index. Store the results in aStat as follows:
116277115493
**
116278115494
** aStat[0] Est. number of rows less than pVal
116279115495
** aStat[1] Est. number of rows equal to pVal
116280115496
**
116281
-** Return the index of the sample that is the smallest sample that
116282
-** is greater than or equal to pRec.
115497
+** Return SQLITE_OK on success.
116283115498
*/
116284
-static int whereKeyStats(
115499
+static void whereKeyStats(
116285115500
Parse *pParse, /* Database connection */
116286115501
Index *pIdx, /* Index to consider domain of */
116287115502
UnpackedRecord *pRec, /* Vector of values to consider */
116288115503
int roundUp, /* Round up if true. Round down if false */
116289115504
tRowcnt *aStat /* OUT: stats written here */
@@ -116361,11 +115576,10 @@
116361115576
}else{
116362115577
iGap = iGap/3;
116363115578
}
116364115579
aStat[0] = iLower + iGap;
116365115580
}
116366
- return i;
116367115581
}
116368115582
#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
116369115583
116370115584
/*
116371115585
** If it is not NULL, pTerm is a term that provides an upper or lower
@@ -116512,11 +115726,11 @@
116512115726
** pLower pUpper
116513115727
**
116514115728
** If either of the upper or lower bound is not present, then NULL is passed in
116515115729
** place of the corresponding WhereTerm.
116516115730
**
116517
-** The value in (pBuilder->pNew->u.btree.nEq) is the number of the index
115731
+** The value in (pBuilder->pNew->u.btree.nEq) is the index of the index
116518115732
** column subject to the range constraint. Or, equivalently, the number of
116519115733
** equality constraints optimized by the proposed index scan. For example,
116520115734
** assuming index p is on t1(a, b), and the SQL query is:
116521115735
**
116522115736
** ... FROM t1 WHERE a = ? AND b > ? AND b < ? ...
@@ -116528,11 +115742,11 @@
116528115742
**
116529115743
** then nEq is set to 0.
116530115744
**
116531115745
** When this function is called, *pnOut is set to the sqlite3LogEst() of the
116532115746
** number of rows that the index scan is expected to visit without
116533
-** considering the range constraints. If nEq is 0, then *pnOut is the number of
115747
+** considering the range constraints. If nEq is 0, this is the number of
116534115748
** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
116535115749
** to account for the range constraints pLower and pUpper.
116536115750
**
116537115751
** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be
116538115752
** used, a single range inequality reduces the search space by a factor of 4.
@@ -116552,11 +115766,14 @@
116552115766
116553115767
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
116554115768
Index *p = pLoop->u.btree.pIndex;
116555115769
int nEq = pLoop->u.btree.nEq;
116556115770
116557
- if( p->nSample>0 && nEq<p->nSampleCol ){
115771
+ if( p->nSample>0
115772
+ && nEq<p->nSampleCol
115773
+ && OptimizationEnabled(pParse->db, SQLITE_Stat3)
115774
+ ){
116558115775
if( nEq==pBuilder->nRecValid ){
116559115776
UnpackedRecord *pRec = pBuilder->pRec;
116560115777
tRowcnt a[2];
116561115778
u8 aff;
116562115779
@@ -116568,23 +115785,19 @@
116568115785
**
116569115786
** Or, if pLower is NULL or $L cannot be extracted from it (because it
116570115787
** is not a simple variable or literal value), the lower bound of the
116571115788
** range is $P. Due to a quirk in the way whereKeyStats() works, even
116572115789
** if $L is available, whereKeyStats() is called for both ($P) and
116573
- ** ($P:$L) and the larger of the two returned values is used.
115790
+ ** ($P:$L) and the larger of the two returned values used.
116574115791
**
116575115792
** Similarly, iUpper is to be set to the estimate of the number of rows
116576115793
** less than the upper bound of the range query. Where the upper bound
116577115794
** is either ($P) or ($P:$U). Again, even if $U is available, both values
116578115795
** of iUpper are requested of whereKeyStats() and the smaller used.
116579
- **
116580
- ** The number of rows between the two bounds is then just iUpper-iLower.
116581115796
*/
116582
- tRowcnt iLower; /* Rows less than the lower bound */
116583
- tRowcnt iUpper; /* Rows less than the upper bound */
116584
- int iLwrIdx = -2; /* aSample[] for the lower bound */
116585
- int iUprIdx = -1; /* aSample[] for the upper bound */
115797
+ tRowcnt iLower;
115798
+ tRowcnt iUpper;
116586115799
116587115800
if( pRec ){
116588115801
testcase( pRec->nField!=pBuilder->nRecValid );
116589115802
pRec->nField = pBuilder->nRecValid;
116590115803
}
@@ -116594,11 +115807,11 @@
116594115807
aff = p->pTable->aCol[p->aiColumn[nEq]].affinity;
116595115808
}
116596115809
/* Determine iLower and iUpper using ($P) only. */
116597115810
if( nEq==0 ){
116598115811
iLower = 0;
116599
- iUpper = p->nRowEst0;
115812
+ iUpper = sqlite3LogEstToInt(p->aiRowLogEst[0]);
116600115813
}else{
116601115814
/* Note: this call could be optimized away - since the same values must
116602115815
** have been requested when testing key $P in whereEqualScanEst(). */
116603115816
whereKeyStats(pParse, p, pRec, 0, a);
116604115817
iLower = a[0];
@@ -116618,11 +115831,11 @@
116618115831
int bOk; /* True if value is extracted from pExpr */
116619115832
Expr *pExpr = pLower->pExpr->pRight;
116620115833
rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
116621115834
if( rc==SQLITE_OK && bOk ){
116622115835
tRowcnt iNew;
116623
- iLwrIdx = whereKeyStats(pParse, p, pRec, 0, a);
115836
+ whereKeyStats(pParse, p, pRec, 0, a);
116624115837
iNew = a[0] + ((pLower->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
116625115838
if( iNew>iLower ) iLower = iNew;
116626115839
nOut--;
116627115840
pLower = 0;
116628115841
}
@@ -116633,11 +115846,11 @@
116633115846
int bOk; /* True if value is extracted from pExpr */
116634115847
Expr *pExpr = pUpper->pExpr->pRight;
116635115848
rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
116636115849
if( rc==SQLITE_OK && bOk ){
116637115850
tRowcnt iNew;
116638
- iUprIdx = whereKeyStats(pParse, p, pRec, 1, a);
115851
+ whereKeyStats(pParse, p, pRec, 1, a);
116639115852
iNew = a[0] + ((pUpper->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
116640115853
if( iNew<iUpper ) iUpper = iNew;
116641115854
nOut--;
116642115855
pUpper = 0;
116643115856
}
@@ -116645,15 +115858,10 @@
116645115858
116646115859
pBuilder->pRec = pRec;
116647115860
if( rc==SQLITE_OK ){
116648115861
if( iUpper>iLower ){
116649115862
nNew = sqlite3LogEst(iUpper - iLower);
116650
- /* TUNING: If both iUpper and iLower are derived from the same
116651
- ** sample, then assume they are 4x more selective. This brings
116652
- ** the estimated selectivity more in line with what it would be
116653
- ** if estimated without the use of STAT3/4 tables. */
116654
- if( iLwrIdx==iUprIdx ) nNew -= 20; assert( 20==sqlite3LogEst(4) );
116655115863
}else{
116656115864
nNew = 10; assert( 10==sqlite3LogEst(2) );
116657115865
}
116658115866
if( nNew<nOut ){
116659115867
nOut = nNew;
@@ -116674,19 +115882,16 @@
116674115882
#endif
116675115883
assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 );
116676115884
nNew = whereRangeAdjust(pLower, nOut);
116677115885
nNew = whereRangeAdjust(pUpper, nNew);
116678115886
116679
- /* TUNING: If there is both an upper and lower limit and neither limit
116680
- ** has an application-defined likelihood(), assume the range is
115887
+ /* TUNING: If there is both an upper and lower limit, assume the range is
116681115888
** reduced by an additional 75%. This means that, by default, an open-ended
116682115889
** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the
116683115890
** index. While a closed range (e.g. col BETWEEN ? AND ?) is estimated to
116684115891
** match 1/64 of the index. */
116685
- if( pLower && pLower->truthProb>0 && pUpper && pUpper->truthProb>0 ){
116686
- nNew -= 20;
116687
- }
115892
+ if( pLower && pUpper ) nNew -= 20;
116688115893
116689115894
nOut -= (pLower!=0) + (pUpper!=0);
116690115895
if( nNew<10 ) nNew = 10;
116691115896
if( nNew<nOut ) nOut = nNew;
116692115897
#if defined(WHERETRACE_ENABLED)
@@ -117042,11 +116247,11 @@
117042116247
117043116248
/* This module is only called on query plans that use an index. */
117044116249
pLoop = pLevel->pWLoop;
117045116250
assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
117046116251
nEq = pLoop->u.btree.nEq;
117047
- nSkip = pLoop->nSkip;
116252
+ nSkip = pLoop->u.btree.nSkip;
117048116253
pIdx = pLoop->u.btree.pIndex;
117049116254
assert( pIdx!=0 );
117050116255
117051116256
/* Figure out how many memory cells we will need then allocate them.
117052116257
*/
@@ -117156,11 +116361,11 @@
117156116361
** "a=? AND b>?"
117157116362
*/
117158116363
static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
117159116364
Index *pIndex = pLoop->u.btree.pIndex;
117160116365
u16 nEq = pLoop->u.btree.nEq;
117161
- u16 nSkip = pLoop->nSkip;
116366
+ u16 nSkip = pLoop->u.btree.nSkip;
117162116367
int i, j;
117163116368
Column *aCol = pTab->aCol;
117164116369
i16 *aiColumn = pIndex->aiColumn;
117165116370
117166116371
if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
@@ -117187,27 +116392,23 @@
117187116392
sqlite3StrAccumAppend(pStr, ")", 1);
117188116393
}
117189116394
117190116395
/*
117191116396
** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
117192
-** command, or if either SQLITE_DEBUG or SQLITE_ENABLE_STMT_SCANSTATUS was
117193
-** defined at compile-time. If it is not a no-op, a single OP_Explain opcode
117194
-** is added to the output to describe the table scan strategy in pLevel.
117195
-**
117196
-** If an OP_Explain opcode is added to the VM, its address is returned.
117197
-** Otherwise, if no OP_Explain is coded, zero is returned.
116397
+** command. If the query being compiled is an EXPLAIN QUERY PLAN, a single
116398
+** record is added to the output to describe the table scan strategy in
116399
+** pLevel.
117198116400
*/
117199
-static int explainOneScan(
116401
+static void explainOneScan(
117200116402
Parse *pParse, /* Parse context */
117201116403
SrcList *pTabList, /* Table list this loop refers to */
117202116404
WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
117203116405
int iLevel, /* Value for "level" column of output */
117204116406
int iFrom, /* Value for "from" column of output */
117205116407
u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
117206116408
){
117207
- int ret = 0;
117208
-#if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
116409
+#ifndef SQLITE_DEBUG
117209116410
if( pParse->explain==2 )
117210116411
#endif
117211116412
{
117212116413
struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
117213116414
Vdbe *v = pParse->pVdbe; /* VM being constructed */
@@ -117220,11 +116421,11 @@
117220116421
StrAccum str; /* EQP output string */
117221116422
char zBuf[100]; /* Initial space for EQP output string */
117222116423
117223116424
pLoop = pLevel->pWLoop;
117224116425
flags = pLoop->wsFlags;
117225
- if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return 0;
116426
+ if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return;
117226116427
117227116428
isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
117228116429
|| ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
117229116430
|| (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
117230116431
@@ -117249,12 +116450,10 @@
117249116450
assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
117250116451
if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
117251116452
if( isSearch ){
117252116453
zFmt = "PRIMARY KEY";
117253116454
}
117254
- }else if( flags & WHERE_PARTIALIDX ){
117255
- zFmt = "AUTOMATIC PARTIAL COVERING INDEX";
117256116455
}else if( flags & WHERE_AUTO_INDEX ){
117257116456
zFmt = "AUTOMATIC COVERING INDEX";
117258116457
}else if( flags & WHERE_IDX_ONLY ){
117259116458
zFmt = "COVERING INDEX %s";
117260116459
}else{
@@ -117292,49 +116491,16 @@
117292116491
}else{
117293116492
sqlite3StrAccumAppend(&str, " (~1 row)", 9);
117294116493
}
117295116494
#endif
117296116495
zMsg = sqlite3StrAccumFinish(&str);
117297
- ret = sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg,P4_DYNAMIC);
117298
- }
117299
- return ret;
117300
-}
117301
-#else
117302
-# define explainOneScan(u,v,w,x,y,z) 0
117303
-#endif /* SQLITE_OMIT_EXPLAIN */
117304
-
117305
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
117306
-/*
117307
-** Configure the VM passed as the first argument with an
117308
-** sqlite3_stmt_scanstatus() entry corresponding to the scan used to
117309
-** implement level pLvl. Argument pSrclist is a pointer to the FROM
117310
-** clause that the scan reads data from.
117311
-**
117312
-** If argument addrExplain is not 0, it must be the address of an
117313
-** OP_Explain instruction that describes the same loop.
117314
-*/
117315
-static void addScanStatus(
117316
- Vdbe *v, /* Vdbe to add scanstatus entry to */
117317
- SrcList *pSrclist, /* FROM clause pLvl reads data from */
117318
- WhereLevel *pLvl, /* Level to add scanstatus() entry for */
117319
- int addrExplain /* Address of OP_Explain (or 0) */
117320
-){
117321
- const char *zObj = 0;
117322
- WhereLoop *pLoop = pLvl->pWLoop;
117323
- if( (pLoop->wsFlags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
117324
- zObj = pLoop->u.btree.pIndex->zName;
117325
- }else{
117326
- zObj = pSrclist->a[pLvl->iFrom].zName;
117327
- }
117328
- sqlite3VdbeScanStatus(
117329
- v, addrExplain, pLvl->addrBody, pLvl->addrVisit, pLoop->nOut, zObj
117330
- );
117331
-}
117332
-#else
117333
-# define addScanStatus(a, b, c, d) ((void)d)
117334
-#endif
117335
-
116496
+ sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg, P4_DYNAMIC);
116497
+ }
116498
+}
116499
+#else
116500
+# define explainOneScan(u,v,w,x,y,z)
116501
+#endif /* SQLITE_OMIT_EXPLAIN */
117336116502
117337116503
117338116504
/*
117339116505
** Generate code for the start of the iLevel-th loop in the WHERE clause
117340116506
** implementation described by pWInfo.
@@ -117632,11 +116798,11 @@
117632116798
u8 bSeekPastNull = 0; /* True to seek past initial nulls */
117633116799
u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */
117634116800
117635116801
pIdx = pLoop->u.btree.pIndex;
117636116802
iIdxCur = pLevel->iIdxCur;
117637
- assert( nEq>=pLoop->nSkip );
116803
+ assert( nEq>=pLoop->u.btree.nSkip );
117638116804
117639116805
/* If this loop satisfies a sort order (pOrderBy) request that
117640116806
** was passed to this function to implement a "SELECT min(x) ..."
117641116807
** query, then the caller will only allow the loop to run for
117642116808
** a single iteration. This means that the first row returned
@@ -117649,11 +116815,11 @@
117649116815
|| (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0 );
117650116816
if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
117651116817
&& pWInfo->nOBSat>0
117652116818
&& (pIdx->nKeyCol>nEq)
117653116819
){
117654
- assert( pLoop->nSkip==0 );
116820
+ assert( pLoop->u.btree.nSkip==0 );
117655116821
bSeekPastNull = 1;
117656116822
nExtraReg = 1;
117657116823
}
117658116824
117659116825
/* Find any inequality constraint terms for the start and end
@@ -117998,15 +117164,13 @@
117998117164
pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
117999117165
wctrlFlags, iCovCur);
118000117166
assert( pSubWInfo || pParse->nErr || db->mallocFailed );
118001117167
if( pSubWInfo ){
118002117168
WhereLoop *pSubLoop;
118003
- int addrExplain = explainOneScan(
117169
+ explainOneScan(
118004117170
pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
118005117171
);
118006
- addScanStatus(v, pOrTab, &pSubWInfo->a[0], addrExplain);
118007
-
118008117172
/* This is the sub-WHERE clause body. First skip over
118009117173
** duplicate rows from prior sub-WHERE clauses, and record the
118010117174
** rowid (or PRIMARY KEY) for the current row so that the same
118011117175
** row will be skipped in subsequent sub-WHERE clauses.
118012117176
*/
@@ -118133,14 +117297,10 @@
118133117297
VdbeCoverageIf(v, bRev!=0);
118134117298
pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
118135117299
}
118136117300
}
118137117301
118138
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
118139
- pLevel->addrVisit = sqlite3VdbeCurrentAddr(v);
118140
-#endif
118141
-
118142117302
/* Insert code to test every subexpression that can be completely
118143117303
** computed using the current set of tables.
118144117304
*/
118145117305
for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
118146117306
Expr *pE;
@@ -118276,11 +117436,11 @@
118276117436
}
118277117437
sqlite3DebugPrintf(" %-19s", z);
118278117438
sqlite3_free(z);
118279117439
}
118280117440
if( p->wsFlags & WHERE_SKIPSCAN ){
118281
- sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->nSkip);
117441
+ sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->u.btree.nSkip);
118282117442
}else{
118283117443
sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm);
118284117444
}
118285117445
sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
118286117446
if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){
@@ -118387,41 +117547,34 @@
118387117547
sqlite3DbFree(db, pWInfo);
118388117548
}
118389117549
}
118390117550
118391117551
/*
118392
-** Return TRUE if all of the following are true:
117552
+** Return TRUE if both of the following are true:
118393117553
**
118394117554
** (1) X has the same or lower cost that Y
118395117555
** (2) X is a proper subset of Y
118396
-** (3) X skips at least as many columns as Y
118397117556
**
118398117557
** By "proper subset" we mean that X uses fewer WHERE clause terms
118399117558
** than Y and that every WHERE clause term used by X is also used
118400117559
** by Y.
118401117560
**
118402117561
** If X is a proper subset of Y then Y is a better choice and ought
118403117562
** to have a lower cost. This routine returns TRUE when that cost
118404
-** relationship is inverted and needs to be adjusted. The third rule
118405
-** was added because if X uses skip-scan less than Y it still might
118406
-** deserve a lower cost even if it is a proper subset of Y.
117563
+** relationship is inverted and needs to be adjusted.
118407117564
*/
118408117565
static int whereLoopCheaperProperSubset(
118409117566
const WhereLoop *pX, /* First WhereLoop to compare */
118410117567
const WhereLoop *pY /* Compare against this WhereLoop */
118411117568
){
118412117569
int i, j;
118413
- if( pX->nLTerm-pX->nSkip >= pY->nLTerm-pY->nSkip ){
118414
- return 0; /* X is not a subset of Y */
118415
- }
118416
- if( pY->nSkip > pX->nSkip ) return 0;
117570
+ if( pX->nLTerm >= pY->nLTerm ) return 0; /* X is not a subset of Y */
118417117571
if( pX->rRun >= pY->rRun ){
118418117572
if( pX->rRun > pY->rRun ) return 0; /* X costs more than Y */
118419117573
if( pX->nOut > pY->nOut ) return 0; /* X costs more than Y */
118420117574
}
118421117575
for(i=pX->nLTerm-1; i>=0; i--){
118422
- if( pX->aLTerm[i]==0 ) continue;
118423117576
for(j=pY->nLTerm-1; j>=0; j--){
118424117577
if( pY->aLTerm[j]==pX->aLTerm[i] ) break;
118425117578
}
118426117579
if( j<0 ) return 0; /* X not a subset of Y since term X[i] not used by Y */
118427117580
}
@@ -118439,28 +117592,37 @@
118439117592
** is a proper subset.
118440117593
**
118441117594
** To say "WhereLoop X is a proper subset of Y" means that X uses fewer
118442117595
** WHERE clause terms than Y and that every WHERE clause term used by X is
118443117596
** also used by Y.
117597
+**
117598
+** This adjustment is omitted for SKIPSCAN loops. In a SKIPSCAN loop, the
117599
+** WhereLoop.nLTerm field is not an accurate measure of the number of WHERE
117600
+** clause terms covered, since some of the first nLTerm entries in aLTerm[]
117601
+** will be NULL (because they are skipped). That makes it more difficult
117602
+** to compare the loops. We could add extra code to do the comparison, and
117603
+** perhaps we will someday. But SKIPSCAN is sufficiently uncommon, and this
117604
+** adjustment is sufficient minor, that it is very difficult to construct
117605
+** a test case where the extra code would improve the query plan. Better
117606
+** to avoid the added complexity and just omit cost adjustments to SKIPSCAN
117607
+** loops.
118444117608
*/
118445117609
static void whereLoopAdjustCost(const WhereLoop *p, WhereLoop *pTemplate){
118446117610
if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return;
117611
+ if( (pTemplate->wsFlags & WHERE_SKIPSCAN)!=0 ) return;
118447117612
for(; p; p=p->pNextLoop){
118448117613
if( p->iTab!=pTemplate->iTab ) continue;
118449117614
if( (p->wsFlags & WHERE_INDEXED)==0 ) continue;
117615
+ if( (p->wsFlags & WHERE_SKIPSCAN)!=0 ) continue;
118450117616
if( whereLoopCheaperProperSubset(p, pTemplate) ){
118451117617
/* Adjust pTemplate cost downward so that it is cheaper than its
118452
- ** subset p. */
118453
- WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
118454
- pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut-1));
117618
+ ** subset p */
118455117619
pTemplate->rRun = p->rRun;
118456117620
pTemplate->nOut = p->nOut - 1;
118457117621
}else if( whereLoopCheaperProperSubset(pTemplate, p) ){
118458117622
/* Adjust pTemplate cost upward so that it is costlier than p since
118459117623
** pTemplate is a proper subset of p */
118460
- WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
118461
- pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut+1));
118462117624
pTemplate->rRun = p->rRun;
118463117625
pTemplate->nOut = p->nOut + 1;
118464117626
}
118465117627
}
118466117628
}
@@ -118742,11 +117904,11 @@
118742117904
int opMask; /* Valid operators for constraints */
118743117905
WhereScan scan; /* Iterator for WHERE terms */
118744117906
Bitmask saved_prereq; /* Original value of pNew->prereq */
118745117907
u16 saved_nLTerm; /* Original value of pNew->nLTerm */
118746117908
u16 saved_nEq; /* Original value of pNew->u.btree.nEq */
118747
- u16 saved_nSkip; /* Original value of pNew->nSkip */
117909
+ u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */
118748117910
u32 saved_wsFlags; /* Original value of pNew->wsFlags */
118749117911
LogEst saved_nOut; /* Original value of pNew->nOut */
118750117912
int iCol; /* Index of the column in the table */
118751117913
int rc = SQLITE_OK; /* Return code */
118752117914
LogEst rSize; /* Number of rows in the table */
@@ -118771,18 +117933,56 @@
118771117933
iCol = pProbe->aiColumn[pNew->u.btree.nEq];
118772117934
118773117935
pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
118774117936
opMask, pProbe);
118775117937
saved_nEq = pNew->u.btree.nEq;
118776
- saved_nSkip = pNew->nSkip;
117938
+ saved_nSkip = pNew->u.btree.nSkip;
118777117939
saved_nLTerm = pNew->nLTerm;
118778117940
saved_wsFlags = pNew->wsFlags;
118779117941
saved_prereq = pNew->prereq;
118780117942
saved_nOut = pNew->nOut;
118781117943
pNew->rSetup = 0;
118782117944
rSize = pProbe->aiRowLogEst[0];
118783117945
rLogSize = estLog(rSize);
117946
+
117947
+ /* Consider using a skip-scan if there are no WHERE clause constraints
117948
+ ** available for the left-most terms of the index, and if the average
117949
+ ** number of repeats in the left-most terms is at least 18.
117950
+ **
117951
+ ** The magic number 18 is selected on the basis that scanning 17 rows
117952
+ ** is almost always quicker than an index seek (even though if the index
117953
+ ** contains fewer than 2^17 rows we assume otherwise in other parts of
117954
+ ** the code). And, even if it is not, it should not be too much slower.
117955
+ ** On the other hand, the extra seeks could end up being significantly
117956
+ ** more expensive. */
117957
+ assert( 42==sqlite3LogEst(18) );
117958
+ if( saved_nEq==saved_nSkip
117959
+ && saved_nEq+1<pProbe->nKeyCol
117960
+ && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
117961
+ && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
117962
+ ){
117963
+ LogEst nIter;
117964
+ pNew->u.btree.nEq++;
117965
+ pNew->u.btree.nSkip++;
117966
+ pNew->aLTerm[pNew->nLTerm++] = 0;
117967
+ pNew->wsFlags |= WHERE_SKIPSCAN;
117968
+ nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1];
117969
+ if( pTerm ){
117970
+ /* TUNING: When estimating skip-scan for a term that is also indexable,
117971
+ ** multiply the cost of the skip-scan by 2.0, to make it a little less
117972
+ ** desirable than the regular index lookup. */
117973
+ nIter += 10; assert( 10==sqlite3LogEst(2) );
117974
+ }
117975
+ pNew->nOut -= nIter;
117976
+ /* TUNING: Because uncertainties in the estimates for skip-scan queries,
117977
+ ** add a 1.375 fudge factor to make skip-scan slightly less likely. */
117978
+ nIter += 5;
117979
+ whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul);
117980
+ pNew->nOut = saved_nOut;
117981
+ pNew->u.btree.nEq = saved_nEq;
117982
+ pNew->u.btree.nSkip = saved_nSkip;
117983
+ }
118784117984
for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
118785117985
u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */
118786117986
LogEst rCostIdx;
118787117987
LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */
118788117988
int nIn = 0;
@@ -118873,10 +118073,11 @@
118873118073
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
118874118074
tRowcnt nOut = 0;
118875118075
if( nInMul==0
118876118076
&& pProbe->nSample
118877118077
&& pNew->u.btree.nEq<=pProbe->nSampleCol
118078
+ && OptimizationEnabled(db, SQLITE_Stat3)
118878118079
&& ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect))
118879118080
){
118880118081
Expr *pExpr = pTerm->pExpr;
118881118082
if( (eOp & (WO_EQ|WO_ISNULL))!=0 ){
118882118083
testcase( eOp & WO_EQ );
@@ -118940,48 +118141,14 @@
118940118141
pBuilder->nRecValid = nRecValid;
118941118142
#endif
118942118143
}
118943118144
pNew->prereq = saved_prereq;
118944118145
pNew->u.btree.nEq = saved_nEq;
118945
- pNew->nSkip = saved_nSkip;
118146
+ pNew->u.btree.nSkip = saved_nSkip;
118946118147
pNew->wsFlags = saved_wsFlags;
118947118148
pNew->nOut = saved_nOut;
118948118149
pNew->nLTerm = saved_nLTerm;
118949
-
118950
- /* Consider using a skip-scan if there are no WHERE clause constraints
118951
- ** available for the left-most terms of the index, and if the average
118952
- ** number of repeats in the left-most terms is at least 18.
118953
- **
118954
- ** The magic number 18 is selected on the basis that scanning 17 rows
118955
- ** is almost always quicker than an index seek (even though if the index
118956
- ** contains fewer than 2^17 rows we assume otherwise in other parts of
118957
- ** the code). And, even if it is not, it should not be too much slower.
118958
- ** On the other hand, the extra seeks could end up being significantly
118959
- ** more expensive. */
118960
- assert( 42==sqlite3LogEst(18) );
118961
- if( saved_nEq==saved_nSkip
118962
- && saved_nEq+1<pProbe->nKeyCol
118963
- && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
118964
- && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
118965
- ){
118966
- LogEst nIter;
118967
- pNew->u.btree.nEq++;
118968
- pNew->nSkip++;
118969
- pNew->aLTerm[pNew->nLTerm++] = 0;
118970
- pNew->wsFlags |= WHERE_SKIPSCAN;
118971
- nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1];
118972
- pNew->nOut -= nIter;
118973
- /* TUNING: Because uncertainties in the estimates for skip-scan queries,
118974
- ** add a 1.375 fudge factor to make skip-scan slightly less likely. */
118975
- nIter += 5;
118976
- whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul);
118977
- pNew->nOut = saved_nOut;
118978
- pNew->u.btree.nEq = saved_nEq;
118979
- pNew->nSkip = saved_nSkip;
118980
- pNew->wsFlags = saved_wsFlags;
118981
- }
118982
-
118983118150
return rc;
118984118151
}
118985118152
118986118153
/*
118987118154
** Return True if it is possible that pIndex might be useful in
@@ -119156,11 +118323,11 @@
119156118323
WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
119157118324
for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
119158118325
if( pTerm->prereqRight & pNew->maskSelf ) continue;
119159118326
if( termCanDriveIndex(pTerm, pSrc, 0) ){
119160118327
pNew->u.btree.nEq = 1;
119161
- pNew->nSkip = 0;
118328
+ pNew->u.btree.nSkip = 0;
119162118329
pNew->u.btree.pIndex = 0;
119163118330
pNew->nLTerm = 1;
119164118331
pNew->aLTerm[0] = pTerm;
119165118332
/* TUNING: One-time cost for computing the automatic index is
119166118333
** estimated to be X*N*log2(N) where N is the number of rows in
@@ -119197,11 +118364,11 @@
119197118364
testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
119198118365
continue; /* Partial index inappropriate for this query */
119199118366
}
119200118367
rSize = pProbe->aiRowLogEst[0];
119201118368
pNew->u.btree.nEq = 0;
119202
- pNew->nSkip = 0;
118369
+ pNew->u.btree.nSkip = 0;
119203118370
pNew->nLTerm = 0;
119204118371
pNew->iSortIdx = 0;
119205118372
pNew->rSetup = 0;
119206118373
pNew->prereq = mExtra;
119207118374
pNew->nOut = rSize;
@@ -119747,11 +118914,11 @@
119747118914
for(j=0; j<nColumn; j++){
119748118915
u8 bOnce; /* True to run the ORDER BY search loop */
119749118916
119750118917
/* Skip over == and IS NULL terms */
119751118918
if( j<pLoop->u.btree.nEq
119752
- && pLoop->nSkip==0
118919
+ && pLoop->u.btree.nSkip==0
119753118920
&& ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
119754118921
){
119755118922
if( i & WO_ISNULL ){
119756118923
testcase( isOrderDistinct );
119757118924
isOrderDistinct = 0;
@@ -120201,11 +119368,11 @@
120201119368
}
120202119369
}
120203119370
}
120204119371
120205119372
#ifdef WHERETRACE_ENABLED /* >=2 */
120206
- if( sqlite3WhereTrace & 0x02 ){
119373
+ if( sqlite3WhereTrace>=2 ){
120207119374
sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
120208119375
for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
120209119376
sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c",
120210119377
wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
120211119378
pTo->isOrdered>=0 ? (pTo->isOrdered+'0') : '?');
@@ -120320,11 +119487,11 @@
120320119487
if( pItem->zIndex ) return 0;
120321119488
iCur = pItem->iCursor;
120322119489
pWC = &pWInfo->sWC;
120323119490
pLoop = pBuilder->pNew;
120324119491
pLoop->wsFlags = 0;
120325
- pLoop->nSkip = 0;
119492
+ pLoop->u.btree.nSkip = 0;
120326119493
pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0);
120327119494
if( pTerm ){
120328119495
pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW;
120329119496
pLoop->aLTerm[0] = pTerm;
120330119497
pLoop->nLTerm = 1;
@@ -120332,10 +119499,11 @@
120332119499
/* TUNING: Cost of a rowid lookup is 10 */
120333119500
pLoop->rRun = 33; /* 33==sqlite3LogEst(10) */
120334119501
}else{
120335119502
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
120336119503
assert( pLoop->aLTermSpace==pLoop->aLTerm );
119504
+ assert( ArraySize(pLoop->aLTermSpace)==4 );
120337119505
if( !IsUniqueIndex(pIdx)
120338119506
|| pIdx->pPartIdxWhere!=0
120339119507
|| pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace)
120340119508
) continue;
120341119509
for(j=0; j<pIdx->nKeyCol; j++){
@@ -120840,30 +120008,22 @@
120840120008
** loop below generates code for a single nested loop of the VM
120841120009
** program.
120842120010
*/
120843120011
notReady = ~(Bitmask)0;
120844120012
for(ii=0; ii<nTabList; ii++){
120845
- int addrExplain;
120846
- int wsFlags;
120847120013
pLevel = &pWInfo->a[ii];
120848
- wsFlags = pLevel->pWLoop->wsFlags;
120849120014
#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
120850120015
if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){
120851120016
constructAutomaticIndex(pParse, &pWInfo->sWC,
120852120017
&pTabList->a[pLevel->iFrom], notReady, pLevel);
120853120018
if( db->mallocFailed ) goto whereBeginError;
120854120019
}
120855120020
#endif
120856
- addrExplain = explainOneScan(
120857
- pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags
120858
- );
120021
+ explainOneScan(pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags);
120859120022
pLevel->addrBody = sqlite3VdbeCurrentAddr(v);
120860120023
notReady = codeOneLoopStart(pWInfo, ii, notReady);
120861120024
pWInfo->iContinue = pLevel->addrCont;
120862
- if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_ONETABLE_ONLY)==0 ){
120863
- addScanStatus(v, pTabList, pLevel, addrExplain);
120864
- }
120865120025
}
120866120026
120867120027
/* Done. */
120868120028
VdbeModuleComment((v, "Begin WHERE-core"));
120869120029
return pWInfo;
@@ -125528,17 +124688,10 @@
125528124688
*/
125529124689
SQLITE_API int sqlite3_complete(const char *zSql){
125530124690
u8 state = 0; /* Current state, using numbers defined in header comment */
125531124691
u8 token; /* Value of the next token */
125532124692
125533
-#ifdef SQLITE_ENABLE_API_ARMOR
125534
- if( zSql==0 ){
125535
- (void)SQLITE_MISUSE_BKPT;
125536
- return 0;
125537
- }
125538
-#endif
125539
-
125540124693
#ifndef SQLITE_OMIT_TRIGGER
125541124694
/* A complex statement machine used to detect the end of a CREATE TRIGGER
125542124695
** statement. This is the normal case.
125543124696
*/
125544124697
static const u8 trans[8][8] = {
@@ -126132,107 +125285,75 @@
126132125285
126133125286
va_start(ap, op);
126134125287
switch( op ){
126135125288
126136125289
/* Mutex configuration options are only available in a threadsafe
126137
- ** compile.
125290
+ ** compile.
126138125291
*/
126139
-#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */
125292
+#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0
126140125293
case SQLITE_CONFIG_SINGLETHREAD: {
126141125294
/* Disable all mutexing */
126142125295
sqlite3GlobalConfig.bCoreMutex = 0;
126143125296
sqlite3GlobalConfig.bFullMutex = 0;
126144125297
break;
126145125298
}
126146
-#endif
126147
-#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */
126148125299
case SQLITE_CONFIG_MULTITHREAD: {
126149125300
/* Disable mutexing of database connections */
126150125301
/* Enable mutexing of core data structures */
126151125302
sqlite3GlobalConfig.bCoreMutex = 1;
126152125303
sqlite3GlobalConfig.bFullMutex = 0;
126153125304
break;
126154125305
}
126155
-#endif
126156
-#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */
126157125306
case SQLITE_CONFIG_SERIALIZED: {
126158125307
/* Enable all mutexing */
126159125308
sqlite3GlobalConfig.bCoreMutex = 1;
126160125309
sqlite3GlobalConfig.bFullMutex = 1;
126161125310
break;
126162125311
}
126163
-#endif
126164
-#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */
126165125312
case SQLITE_CONFIG_MUTEX: {
126166125313
/* Specify an alternative mutex implementation */
126167125314
sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
126168125315
break;
126169125316
}
126170
-#endif
126171
-#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */
126172125317
case SQLITE_CONFIG_GETMUTEX: {
126173125318
/* Retrieve the current mutex implementation */
126174125319
*va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
126175125320
break;
126176125321
}
126177125322
#endif
125323
+
126178125324
126179125325
case SQLITE_CONFIG_MALLOC: {
126180
- /* EVIDENCE-OF: R-55594-21030 The SQLITE_CONFIG_MALLOC option takes a
126181
- ** single argument which is a pointer to an instance of the
126182
- ** sqlite3_mem_methods structure. The argument specifies alternative
126183
- ** low-level memory allocation routines to be used in place of the memory
126184
- ** allocation routines built into SQLite. */
125326
+ /* Specify an alternative malloc implementation */
126185125327
sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*);
126186125328
break;
126187125329
}
126188125330
case SQLITE_CONFIG_GETMALLOC: {
126189
- /* EVIDENCE-OF: R-51213-46414 The SQLITE_CONFIG_GETMALLOC option takes a
126190
- ** single argument which is a pointer to an instance of the
126191
- ** sqlite3_mem_methods structure. The sqlite3_mem_methods structure is
126192
- ** filled with the currently defined memory allocation routines. */
125331
+ /* Retrieve the current malloc() implementation */
126193125332
if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault();
126194125333
*va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m;
126195125334
break;
126196125335
}
126197125336
case SQLITE_CONFIG_MEMSTATUS: {
126198
- /* EVIDENCE-OF: R-61275-35157 The SQLITE_CONFIG_MEMSTATUS option takes
126199
- ** single argument of type int, interpreted as a boolean, which enables
126200
- ** or disables the collection of memory allocation statistics. */
125337
+ /* Enable or disable the malloc status collection */
126201125338
sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
126202125339
break;
126203125340
}
126204125341
case SQLITE_CONFIG_SCRATCH: {
126205
- /* EVIDENCE-OF: R-08404-60887 There are three arguments to
126206
- ** SQLITE_CONFIG_SCRATCH: A pointer an 8-byte aligned memory buffer from
126207
- ** which the scratch allocations will be drawn, the size of each scratch
126208
- ** allocation (sz), and the maximum number of scratch allocations (N). */
125342
+ /* Designate a buffer for scratch memory space */
126209125343
sqlite3GlobalConfig.pScratch = va_arg(ap, void*);
126210125344
sqlite3GlobalConfig.szScratch = va_arg(ap, int);
126211125345
sqlite3GlobalConfig.nScratch = va_arg(ap, int);
126212125346
break;
126213125347
}
126214125348
case SQLITE_CONFIG_PAGECACHE: {
126215
- /* EVIDENCE-OF: R-31408-40510 There are three arguments to
126216
- ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory, the size
126217
- ** of each page buffer (sz), and the number of pages (N). */
125349
+ /* Designate a buffer for page cache memory space */
126218125350
sqlite3GlobalConfig.pPage = va_arg(ap, void*);
126219125351
sqlite3GlobalConfig.szPage = va_arg(ap, int);
126220125352
sqlite3GlobalConfig.nPage = va_arg(ap, int);
126221125353
break;
126222125354
}
126223
- case SQLITE_CONFIG_PCACHE_HDRSZ: {
126224
- /* EVIDENCE-OF: R-39100-27317 The SQLITE_CONFIG_PCACHE_HDRSZ option takes
126225
- ** a single parameter which is a pointer to an integer and writes into
126226
- ** that integer the number of extra bytes per page required for each page
126227
- ** in SQLITE_CONFIG_PAGECACHE. */
126228
- *va_arg(ap, int*) =
126229
- sqlite3HeaderSizeBtree() +
126230
- sqlite3HeaderSizePcache() +
126231
- sqlite3HeaderSizePcache1();
126232
- break;
126233
- }
126234125355
126235125356
case SQLITE_CONFIG_PCACHE: {
126236125357
/* no-op */
126237125358
break;
126238125359
}
@@ -126241,37 +125362,25 @@
126241125362
rc = SQLITE_ERROR;
126242125363
break;
126243125364
}
126244125365
126245125366
case SQLITE_CONFIG_PCACHE2: {
126246
- /* EVIDENCE-OF: R-63325-48378 The SQLITE_CONFIG_PCACHE2 option takes a
126247
- ** single argument which is a pointer to an sqlite3_pcache_methods2
126248
- ** object. This object specifies the interface to a custom page cache
126249
- ** implementation. */
125367
+ /* Specify an alternative page cache implementation */
126250125368
sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*);
126251125369
break;
126252125370
}
126253125371
case SQLITE_CONFIG_GETPCACHE2: {
126254
- /* EVIDENCE-OF: R-22035-46182 The SQLITE_CONFIG_GETPCACHE2 option takes a
126255
- ** single argument which is a pointer to an sqlite3_pcache_methods2
126256
- ** object. SQLite copies of the current page cache implementation into
126257
- ** that object. */
126258125372
if( sqlite3GlobalConfig.pcache2.xInit==0 ){
126259125373
sqlite3PCacheSetDefault();
126260125374
}
126261125375
*va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2;
126262125376
break;
126263125377
}
126264125378
126265
-/* EVIDENCE-OF: R-06626-12911 The SQLITE_CONFIG_HEAP option is only
126266
-** available if SQLite is compiled with either SQLITE_ENABLE_MEMSYS3 or
126267
-** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */
126268125379
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
126269125380
case SQLITE_CONFIG_HEAP: {
126270
- /* EVIDENCE-OF: R-19854-42126 There are three arguments to
126271
- ** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the
126272
- ** number of bytes in the memory buffer, and the minimum allocation size. */
125381
+ /* Designate a buffer for heap memory space */
126273125382
sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
126274125383
sqlite3GlobalConfig.nHeap = va_arg(ap, int);
126275125384
sqlite3GlobalConfig.mnReq = va_arg(ap, int);
126276125385
126277125386
if( sqlite3GlobalConfig.mnReq<1 ){
@@ -126280,23 +125389,21 @@
126280125389
/* cap min request size at 2^12 */
126281125390
sqlite3GlobalConfig.mnReq = (1<<12);
126282125391
}
126283125392
126284125393
if( sqlite3GlobalConfig.pHeap==0 ){
126285
- /* EVIDENCE-OF: R-49920-60189 If the first pointer (the memory pointer)
126286
- ** is NULL, then SQLite reverts to using its default memory allocator
126287
- ** (the system malloc() implementation), undoing any prior invocation of
126288
- ** SQLITE_CONFIG_MALLOC.
126289
- **
126290
- ** Setting sqlite3GlobalConfig.m to all zeros will cause malloc to
126291
- ** revert to its default implementation when sqlite3_initialize() is run
125394
+ /* If the heap pointer is NULL, then restore the malloc implementation
125395
+ ** back to NULL pointers too. This will cause the malloc to go
125396
+ ** back to its default implementation when sqlite3_initialize() is
125397
+ ** run.
126292125398
*/
126293125399
memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
126294125400
}else{
126295
- /* EVIDENCE-OF: R-61006-08918 If the memory pointer is not NULL then the
126296
- ** alternative memory allocator is engaged to handle all of SQLites
126297
- ** memory allocation needs. */
125401
+ /* The heap pointer is not NULL, then install one of the
125402
+ ** mem5.c/mem3.c methods. The enclosing #if guarantees at
125403
+ ** least one of these methods is currently enabled.
125404
+ */
126298125405
#ifdef SQLITE_ENABLE_MEMSYS3
126299125406
sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3();
126300125407
#endif
126301125408
#ifdef SQLITE_ENABLE_MEMSYS5
126302125409
sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5();
@@ -126331,23 +125438,15 @@
126331125438
** can be changed at start-time using the
126332125439
** sqlite3_config(SQLITE_CONFIG_URI,1) or
126333125440
** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
126334125441
*/
126335125442
case SQLITE_CONFIG_URI: {
126336
- /* EVIDENCE-OF: R-25451-61125 The SQLITE_CONFIG_URI option takes a single
126337
- ** argument of type int. If non-zero, then URI handling is globally
126338
- ** enabled. If the parameter is zero, then URI handling is globally
126339
- ** disabled. */
126340125443
sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
126341125444
break;
126342125445
}
126343125446
126344125447
case SQLITE_CONFIG_COVERING_INDEX_SCAN: {
126345
- /* EVIDENCE-OF: R-36592-02772 The SQLITE_CONFIG_COVERING_INDEX_SCAN
126346
- ** option takes a single integer argument which is interpreted as a
126347
- ** boolean in order to enable or disable the use of covering indices for
126348
- ** full table scans in the query optimizer. */
126349125448
sqlite3GlobalConfig.bUseCis = va_arg(ap, int);
126350125449
break;
126351125450
}
126352125451
126353125452
#ifdef SQLITE_ENABLE_SQLLOG
@@ -126358,37 +125457,24 @@
126358125457
break;
126359125458
}
126360125459
#endif
126361125460
126362125461
case SQLITE_CONFIG_MMAP_SIZE: {
126363
- /* EVIDENCE-OF: R-58063-38258 SQLITE_CONFIG_MMAP_SIZE takes two 64-bit
126364
- ** integer (sqlite3_int64) values that are the default mmap size limit
126365
- ** (the default setting for PRAGMA mmap_size) and the maximum allowed
126366
- ** mmap size limit. */
126367125462
sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64);
126368125463
sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64);
126369
- /* EVIDENCE-OF: R-53367-43190 If either argument to this option is
126370
- ** negative, then that argument is changed to its compile-time default.
126371
- **
126372
- ** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be
126373
- ** silently truncated if necessary so that it does not exceed the
126374
- ** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE
126375
- ** compile-time option.
126376
- */
126377
- if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ) mxMmap = SQLITE_MAX_MMAP_SIZE;
125464
+ if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){
125465
+ mxMmap = SQLITE_MAX_MMAP_SIZE;
125466
+ }
125467
+ sqlite3GlobalConfig.mxMmap = mxMmap;
126378125468
if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
126379125469
if( szMmap>mxMmap) szMmap = mxMmap;
126380
- sqlite3GlobalConfig.mxMmap = mxMmap;
126381125470
sqlite3GlobalConfig.szMmap = szMmap;
126382125471
break;
126383125472
}
126384125473
126385
-#if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC) /* IMP: R-04780-55815 */
125474
+#if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC)
126386125475
case SQLITE_CONFIG_WIN32_HEAPSIZE: {
126387
- /* EVIDENCE-OF: R-34926-03360 SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit
126388
- ** unsigned integer value that specifies the maximum size of the created
126389
- ** heap. */
126390125476
sqlite3GlobalConfig.nHeap = va_arg(ap, int);
126391125477
break;
126392125478
}
126393125479
#endif
126394125480
@@ -126468,29 +125554,19 @@
126468125554
126469125555
/*
126470125556
** Return the mutex associated with a database connection.
126471125557
*/
126472125558
SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
126473
-#ifdef SQLITE_ENABLE_API_ARMOR
126474
- if( !sqlite3SafetyCheckOk(db) ){
126475
- (void)SQLITE_MISUSE_BKPT;
126476
- return 0;
126477
- }
126478
-#endif
126479125559
return db->mutex;
126480125560
}
126481125561
126482125562
/*
126483125563
** Free up as much memory as we can from the given database
126484125564
** connection.
126485125565
*/
126486125566
SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){
126487125567
int i;
126488
-
126489
-#ifdef SQLITE_ENABLE_API_ARMOR
126490
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
126491
-#endif
126492125568
sqlite3_mutex_enter(db->mutex);
126493125569
sqlite3BtreeEnterAll(db);
126494125570
for(i=0; i<db->nDb; i++){
126495125571
Btree *pBt = db->aDb[i].pBt;
126496125572
if( pBt ){
@@ -126617,42 +125693,24 @@
126617125693
126618125694
/*
126619125695
** Return the ROWID of the most recent insert
126620125696
*/
126621125697
SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
126622
-#ifdef SQLITE_ENABLE_API_ARMOR
126623
- if( !sqlite3SafetyCheckOk(db) ){
126624
- (void)SQLITE_MISUSE_BKPT;
126625
- return 0;
126626
- }
126627
-#endif
126628125698
return db->lastRowid;
126629125699
}
126630125700
126631125701
/*
126632125702
** Return the number of changes in the most recent call to sqlite3_exec().
126633125703
*/
126634125704
SQLITE_API int sqlite3_changes(sqlite3 *db){
126635
-#ifdef SQLITE_ENABLE_API_ARMOR
126636
- if( !sqlite3SafetyCheckOk(db) ){
126637
- (void)SQLITE_MISUSE_BKPT;
126638
- return 0;
126639
- }
126640
-#endif
126641125705
return db->nChange;
126642125706
}
126643125707
126644125708
/*
126645125709
** Return the number of changes since the database handle was opened.
126646125710
*/
126647125711
SQLITE_API int sqlite3_total_changes(sqlite3 *db){
126648
-#ifdef SQLITE_ENABLE_API_ARMOR
126649
- if( !sqlite3SafetyCheckOk(db) ){
126650
- (void)SQLITE_MISUSE_BKPT;
126651
- return 0;
126652
- }
126653
-#endif
126654125712
return db->nTotalChange;
126655125713
}
126656125714
126657125715
/*
126658125716
** Close all open savepoints. This function only manipulates fields of the
@@ -127197,13 +126255,10 @@
127197126255
SQLITE_API int sqlite3_busy_handler(
127198126256
sqlite3 *db,
127199126257
int (*xBusy)(void*,int),
127200126258
void *pArg
127201126259
){
127202
-#ifdef SQLITE_ENABLE_API_ARMOR
127203
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE;
127204
-#endif
127205126260
sqlite3_mutex_enter(db->mutex);
127206126261
db->busyHandler.xFunc = xBusy;
127207126262
db->busyHandler.pArg = pArg;
127208126263
db->busyHandler.nBusy = 0;
127209126264
db->busyTimeout = 0;
@@ -127221,16 +126276,10 @@
127221126276
sqlite3 *db,
127222126277
int nOps,
127223126278
int (*xProgress)(void*),
127224126279
void *pArg
127225126280
){
127226
-#ifdef SQLITE_ENABLE_API_ARMOR
127227
- if( !sqlite3SafetyCheckOk(db) ){
127228
- (void)SQLITE_MISUSE_BKPT;
127229
- return;
127230
- }
127231
-#endif
127232126281
sqlite3_mutex_enter(db->mutex);
127233126282
if( nOps>0 ){
127234126283
db->xProgress = xProgress;
127235126284
db->nProgressOps = (unsigned)nOps;
127236126285
db->pProgressArg = pArg;
@@ -127247,13 +126296,10 @@
127247126296
/*
127248126297
** This routine installs a default busy handler that waits for the
127249126298
** specified number of milliseconds before returning 0.
127250126299
*/
127251126300
SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
127252
-#ifdef SQLITE_ENABLE_API_ARMOR
127253
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
127254
-#endif
127255126301
if( ms>0 ){
127256126302
sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
127257126303
db->busyTimeout = ms;
127258126304
}else{
127259126305
sqlite3_busy_handler(db, 0, 0);
@@ -127263,16 +126309,10 @@
127263126309
127264126310
/*
127265126311
** Cause any pending operation to stop at its earliest opportunity.
127266126312
*/
127267126313
SQLITE_API void sqlite3_interrupt(sqlite3 *db){
127268
-#ifdef SQLITE_ENABLE_API_ARMOR
127269
- if( !sqlite3SafetyCheckOk(db) ){
127270
- (void)SQLITE_MISUSE_BKPT;
127271
- return;
127272
- }
127273
-#endif
127274126314
db->u1.isInterrupted = 1;
127275126315
}
127276126316
127277126317
127278126318
/*
@@ -127406,16 +126446,10 @@
127406126446
void (*xFinal)(sqlite3_context*),
127407126447
void (*xDestroy)(void *)
127408126448
){
127409126449
int rc = SQLITE_ERROR;
127410126450
FuncDestructor *pArg = 0;
127411
-
127412
-#ifdef SQLITE_ENABLE_API_ARMOR
127413
- if( !sqlite3SafetyCheckOk(db) ){
127414
- return SQLITE_MISUSE_BKPT;
127415
- }
127416
-#endif
127417126451
sqlite3_mutex_enter(db->mutex);
127418126452
if( xDestroy ){
127419126453
pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
127420126454
if( !pArg ){
127421126455
xDestroy(p);
@@ -127448,14 +126482,10 @@
127448126482
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
127449126483
void (*xFinal)(sqlite3_context*)
127450126484
){
127451126485
int rc;
127452126486
char *zFunc8;
127453
-
127454
-#ifdef SQLITE_ENABLE_API_ARMOR
127455
- if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT;
127456
-#endif
127457126487
sqlite3_mutex_enter(db->mutex);
127458126488
assert( !db->mallocFailed );
127459126489
zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
127460126490
rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
127461126491
sqlite3DbFree(db, zFunc8);
@@ -127483,16 +126513,10 @@
127483126513
const char *zName,
127484126514
int nArg
127485126515
){
127486126516
int nName = sqlite3Strlen30(zName);
127487126517
int rc = SQLITE_OK;
127488
-
127489
-#ifdef SQLITE_ENABLE_API_ARMOR
127490
- if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){
127491
- return SQLITE_MISUSE_BKPT;
127492
- }
127493
-#endif
127494126518
sqlite3_mutex_enter(db->mutex);
127495126519
if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
127496126520
rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
127497126521
0, sqlite3InvalidFunction, 0, 0, 0);
127498126522
}
@@ -127510,17 +126534,10 @@
127510126534
** trace is a pointer to a function that is invoked at the start of each
127511126535
** SQL statement.
127512126536
*/
127513126537
SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
127514126538
void *pOld;
127515
-
127516
-#ifdef SQLITE_ENABLE_API_ARMOR
127517
- if( !sqlite3SafetyCheckOk(db) ){
127518
- (void)SQLITE_MISUSE_BKPT;
127519
- return 0;
127520
- }
127521
-#endif
127522126539
sqlite3_mutex_enter(db->mutex);
127523126540
pOld = db->pTraceArg;
127524126541
db->xTrace = xTrace;
127525126542
db->pTraceArg = pArg;
127526126543
sqlite3_mutex_leave(db->mutex);
@@ -127538,17 +126555,10 @@
127538126555
sqlite3 *db,
127539126556
void (*xProfile)(void*,const char*,sqlite_uint64),
127540126557
void *pArg
127541126558
){
127542126559
void *pOld;
127543
-
127544
-#ifdef SQLITE_ENABLE_API_ARMOR
127545
- if( !sqlite3SafetyCheckOk(db) ){
127546
- (void)SQLITE_MISUSE_BKPT;
127547
- return 0;
127548
- }
127549
-#endif
127550126560
sqlite3_mutex_enter(db->mutex);
127551126561
pOld = db->pProfileArg;
127552126562
db->xProfile = xProfile;
127553126563
db->pProfileArg = pArg;
127554126564
sqlite3_mutex_leave(db->mutex);
@@ -127565,17 +126575,10 @@
127565126575
sqlite3 *db, /* Attach the hook to this database */
127566126576
int (*xCallback)(void*), /* Function to invoke on each commit */
127567126577
void *pArg /* Argument to the function */
127568126578
){
127569126579
void *pOld;
127570
-
127571
-#ifdef SQLITE_ENABLE_API_ARMOR
127572
- if( !sqlite3SafetyCheckOk(db) ){
127573
- (void)SQLITE_MISUSE_BKPT;
127574
- return 0;
127575
- }
127576
-#endif
127577126580
sqlite3_mutex_enter(db->mutex);
127578126581
pOld = db->pCommitArg;
127579126582
db->xCommitCallback = xCallback;
127580126583
db->pCommitArg = pArg;
127581126584
sqlite3_mutex_leave(db->mutex);
@@ -127590,17 +126593,10 @@
127590126593
sqlite3 *db, /* Attach the hook to this database */
127591126594
void (*xCallback)(void*,int,char const *,char const *,sqlite_int64),
127592126595
void *pArg /* Argument to the function */
127593126596
){
127594126597
void *pRet;
127595
-
127596
-#ifdef SQLITE_ENABLE_API_ARMOR
127597
- if( !sqlite3SafetyCheckOk(db) ){
127598
- (void)SQLITE_MISUSE_BKPT;
127599
- return 0;
127600
- }
127601
-#endif
127602126598
sqlite3_mutex_enter(db->mutex);
127603126599
pRet = db->pUpdateArg;
127604126600
db->xUpdateCallback = xCallback;
127605126601
db->pUpdateArg = pArg;
127606126602
sqlite3_mutex_leave(db->mutex);
@@ -127615,17 +126611,10 @@
127615126611
sqlite3 *db, /* Attach the hook to this database */
127616126612
void (*xCallback)(void*), /* Callback function */
127617126613
void *pArg /* Argument to the function */
127618126614
){
127619126615
void *pRet;
127620
-
127621
-#ifdef SQLITE_ENABLE_API_ARMOR
127622
- if( !sqlite3SafetyCheckOk(db) ){
127623
- (void)SQLITE_MISUSE_BKPT;
127624
- return 0;
127625
- }
127626
-#endif
127627126616
sqlite3_mutex_enter(db->mutex);
127628126617
pRet = db->pRollbackArg;
127629126618
db->xRollbackCallback = xCallback;
127630126619
db->pRollbackArg = pArg;
127631126620
sqlite3_mutex_leave(db->mutex);
@@ -127668,13 +126657,10 @@
127668126657
SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
127669126658
#ifdef SQLITE_OMIT_WAL
127670126659
UNUSED_PARAMETER(db);
127671126660
UNUSED_PARAMETER(nFrame);
127672126661
#else
127673
-#ifdef SQLITE_ENABLE_API_ARMOR
127674
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
127675
-#endif
127676126662
if( nFrame>0 ){
127677126663
sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
127678126664
}else{
127679126665
sqlite3_wal_hook(db, 0, 0);
127680126666
}
@@ -127691,16 +126677,10 @@
127691126677
int(*xCallback)(void *, sqlite3*, const char*, int),
127692126678
void *pArg /* First argument passed to xCallback() */
127693126679
){
127694126680
#ifndef SQLITE_OMIT_WAL
127695126681
void *pRet;
127696
-#ifdef SQLITE_ENABLE_API_ARMOR
127697
- if( !sqlite3SafetyCheckOk(db) ){
127698
- (void)SQLITE_MISUSE_BKPT;
127699
- return 0;
127700
- }
127701
-#endif
127702126682
sqlite3_mutex_enter(db->mutex);
127703126683
pRet = db->pWalArg;
127704126684
db->xWalCallback = xCallback;
127705126685
db->pWalArg = pArg;
127706126686
sqlite3_mutex_leave(db->mutex);
@@ -127724,14 +126704,10 @@
127724126704
return SQLITE_OK;
127725126705
#else
127726126706
int rc; /* Return code */
127727126707
int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
127728126708
127729
-#ifdef SQLITE_ENABLE_API_ARMOR
127730
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
127731
-#endif
127732
-
127733126709
/* Initialize the output variables to -1 in case an error occurs. */
127734126710
if( pnLog ) *pnLog = -1;
127735126711
if( pnCkpt ) *pnCkpt = -1;
127736126712
127737126713
assert( SQLITE_CHECKPOINT_FULL>SQLITE_CHECKPOINT_PASSIVE );
@@ -128124,16 +127100,10 @@
128124127100
** from forming.
128125127101
*/
128126127102
SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
128127127103
int oldLimit;
128128127104
128129
-#ifdef SQLITE_ENABLE_API_ARMOR
128130
- if( !sqlite3SafetyCheckOk(db) ){
128131
- (void)SQLITE_MISUSE_BKPT;
128132
- return -1;
128133
- }
128134
-#endif
128135127105
128136127106
/* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME
128137127107
** there is a hard upper bound set at compile-time by a C preprocessor
128138127108
** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
128139127109
** "_MAX_".)
@@ -128206,12 +127176,11 @@
128206127176
char c;
128207127177
int nUri = sqlite3Strlen30(zUri);
128208127178
128209127179
assert( *pzErrMsg==0 );
128210127180
128211
- if( ((flags & SQLITE_OPEN_URI) /* IMP: R-48725-32206 */
128212
- || sqlite3GlobalConfig.bOpenUri) /* IMP: R-51689-46548 */
127181
+ if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri)
128213127182
&& nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
128214127183
){
128215127184
char *zOpt;
128216127185
int eState; /* Parser state when parsing URI */
128217127186
int iIn; /* Input character index */
@@ -128416,13 +127385,10 @@
128416127385
int rc; /* Return code */
128417127386
int isThreadsafe; /* True for threadsafe connections */
128418127387
char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */
128419127388
char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */
128420127389
128421
-#ifdef SQLITE_ENABLE_API_ARMOR
128422
- if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
128423
-#endif
128424127390
*ppDb = 0;
128425127391
#ifndef SQLITE_OMIT_AUTOINIT
128426127392
rc = sqlite3_initialize();
128427127393
if( rc ) return rc;
128428127394
#endif
@@ -128708,19 +127674,17 @@
128708127674
){
128709127675
char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
128710127676
sqlite3_value *pVal;
128711127677
int rc;
128712127678
128713
-#ifdef SQLITE_ENABLE_API_ARMOR
128714
- if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
128715
-#endif
127679
+ assert( zFilename );
127680
+ assert( ppDb );
128716127681
*ppDb = 0;
128717127682
#ifndef SQLITE_OMIT_AUTOINIT
128718127683
rc = sqlite3_initialize();
128719127684
if( rc ) return rc;
128720127685
#endif
128721
- if( zFilename==0 ) zFilename = "\000\000";
128722127686
pVal = sqlite3ValueNew(0);
128723127687
sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC);
128724127688
zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8);
128725127689
if( zFilename8 ){
128726127690
rc = openDatabase(zFilename8, ppDb,
@@ -128746,11 +127710,17 @@
128746127710
const char *zName,
128747127711
int enc,
128748127712
void* pCtx,
128749127713
int(*xCompare)(void*,int,const void*,int,const void*)
128750127714
){
128751
- return sqlite3_create_collation_v2(db, zName, enc, pCtx, xCompare, 0);
127715
+ int rc;
127716
+ sqlite3_mutex_enter(db->mutex);
127717
+ assert( !db->mallocFailed );
127718
+ rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, 0);
127719
+ rc = sqlite3ApiExit(db, rc);
127720
+ sqlite3_mutex_leave(db->mutex);
127721
+ return rc;
128752127722
}
128753127723
128754127724
/*
128755127725
** Register a new collation sequence with the database handle db.
128756127726
*/
@@ -128761,14 +127731,10 @@
128761127731
void* pCtx,
128762127732
int(*xCompare)(void*,int,const void*,int,const void*),
128763127733
void(*xDel)(void*)
128764127734
){
128765127735
int rc;
128766
-
128767
-#ifdef SQLITE_ENABLE_API_ARMOR
128768
- if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
128769
-#endif
128770127736
sqlite3_mutex_enter(db->mutex);
128771127737
assert( !db->mallocFailed );
128772127738
rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel);
128773127739
rc = sqlite3ApiExit(db, rc);
128774127740
sqlite3_mutex_leave(db->mutex);
@@ -128786,14 +127752,10 @@
128786127752
void* pCtx,
128787127753
int(*xCompare)(void*,int,const void*,int,const void*)
128788127754
){
128789127755
int rc = SQLITE_OK;
128790127756
char *zName8;
128791
-
128792
-#ifdef SQLITE_ENABLE_API_ARMOR
128793
- if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
128794
-#endif
128795127757
sqlite3_mutex_enter(db->mutex);
128796127758
assert( !db->mallocFailed );
128797127759
zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
128798127760
if( zName8 ){
128799127761
rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
@@ -128812,13 +127774,10 @@
128812127774
SQLITE_API int sqlite3_collation_needed(
128813127775
sqlite3 *db,
128814127776
void *pCollNeededArg,
128815127777
void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*)
128816127778
){
128817
-#ifdef SQLITE_ENABLE_API_ARMOR
128818
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
128819
-#endif
128820127779
sqlite3_mutex_enter(db->mutex);
128821127780
db->xCollNeeded = xCollNeeded;
128822127781
db->xCollNeeded16 = 0;
128823127782
db->pCollNeededArg = pCollNeededArg;
128824127783
sqlite3_mutex_leave(db->mutex);
@@ -128833,13 +127792,10 @@
128833127792
SQLITE_API int sqlite3_collation_needed16(
128834127793
sqlite3 *db,
128835127794
void *pCollNeededArg,
128836127795
void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*)
128837127796
){
128838
-#ifdef SQLITE_ENABLE_API_ARMOR
128839
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
128840
-#endif
128841127797
sqlite3_mutex_enter(db->mutex);
128842127798
db->xCollNeeded = 0;
128843127799
db->xCollNeeded16 = xCollNeeded16;
128844127800
db->pCollNeededArg = pCollNeededArg;
128845127801
sqlite3_mutex_leave(db->mutex);
@@ -128862,16 +127818,10 @@
128862127818
** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
128863127819
** by default. Autocommit is disabled by a BEGIN statement and reenabled
128864127820
** by the next COMMIT or ROLLBACK.
128865127821
*/
128866127822
SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
128867
-#ifdef SQLITE_ENABLE_API_ARMOR
128868
- if( !sqlite3SafetyCheckOk(db) ){
128869
- (void)SQLITE_MISUSE_BKPT;
128870
- return 0;
128871
- }
128872
-#endif
128873127823
return db->autoCommit;
128874127824
}
128875127825
128876127826
/*
128877127827
** The following routines are substitutes for constants SQLITE_CORRUPT,
@@ -129050,13 +128000,10 @@
129050128000
129051128001
/*
129052128002
** Enable or disable the extended result codes.
129053128003
*/
129054128004
SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
129055
-#ifdef SQLITE_ENABLE_API_ARMOR
129056
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
129057
-#endif
129058128005
sqlite3_mutex_enter(db->mutex);
129059128006
db->errMask = onoff ? 0xffffffff : 0xff;
129060128007
sqlite3_mutex_leave(db->mutex);
129061128008
return SQLITE_OK;
129062128009
}
@@ -129066,13 +128013,10 @@
129066128013
*/
129067128014
SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
129068128015
int rc = SQLITE_ERROR;
129069128016
Btree *pBtree;
129070128017
129071
-#ifdef SQLITE_ENABLE_API_ARMOR
129072
- if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
129073
-#endif
129074128018
sqlite3_mutex_enter(db->mutex);
129075128019
pBtree = sqlite3DbNameToBtree(db, zDbName);
129076128020
if( pBtree ){
129077128021
Pager *pPager;
129078128022
sqlite3_file *fd;
@@ -129411,11 +128355,11 @@
129411128355
** query parameter we seek. This routine returns the value of the zParam
129412128356
** parameter if it exists. If the parameter does not exist, this routine
129413128357
** returns a NULL pointer.
129414128358
*/
129415128359
SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){
129416
- if( zFilename==0 || zParam==0 ) return 0;
128360
+ if( zFilename==0 ) return 0;
129417128361
zFilename += sqlite3Strlen30(zFilename) + 1;
129418128362
while( zFilename[0] ){
129419128363
int x = strcmp(zFilename, zParam);
129420128364
zFilename += sqlite3Strlen30(zFilename) + 1;
129421128365
if( x==0 ) return zFilename;
@@ -129467,31 +128411,19 @@
129467128411
/*
129468128412
** Return the filename of the database associated with a database
129469128413
** connection.
129470128414
*/
129471128415
SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
129472
-#ifdef SQLITE_ENABLE_API_ARMOR
129473
- if( !sqlite3SafetyCheckOk(db) ){
129474
- (void)SQLITE_MISUSE_BKPT;
129475
- return 0;
129476
- }
129477
-#endif
129478128416
Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
129479128417
return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
129480128418
}
129481128419
129482128420
/*
129483128421
** Return 1 if database is read-only or 0 if read/write. Return -1 if
129484128422
** no such database exists.
129485128423
*/
129486128424
SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
129487
-#ifdef SQLITE_ENABLE_API_ARMOR
129488
- if( !sqlite3SafetyCheckOk(db) ){
129489
- (void)SQLITE_MISUSE_BKPT;
129490
- return -1;
129491
- }
129492
-#endif
129493128425
Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
129494128426
return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
129495128427
}
129496128428
129497128429
/************** End of main.c ************************************************/
129498128430
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.8. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -179,11 +179,11 @@
179
180
181 /*
182 ** These no-op macros are used in front of interfaces to mark those
183 ** interfaces as either deprecated or experimental. New applications
184 ** should not use deprecated interfaces - they are supported for backwards
185 ** compatibility only. Application writers should be aware that
186 ** experimental interfaces are subject to change in point releases.
187 **
188 ** These macros used to resolve to various kinds of compiler magic that
189 ** would generate warning messages when they were used. But that
@@ -229,13 +229,13 @@
229 **
230 ** See also: [sqlite3_libversion()],
231 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232 ** [sqlite_version()] and [sqlite_source_id()].
233 */
234 #define SQLITE_VERSION "3.8.8"
235 #define SQLITE_VERSION_NUMBER 3008008
236 #define SQLITE_SOURCE_ID "2014-11-11 19:07:56 1412fcc480799ecbd68d44dd18d5bad40e20ccf1"
237
238 /*
239 ** CAPI3REF: Run-Time Library Version Numbers
240 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
241 **
@@ -1626,31 +1626,29 @@
1626 ** it is not possible to set the Serialized [threading mode] and
1627 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1628 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1629 **
1630 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1631 ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
1632 ** a pointer to an instance of the [sqlite3_mem_methods] structure.
1633 ** The argument specifies
1634 ** alternative low-level memory allocation routines to be used in place of
1635 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1636 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1637 ** before the [sqlite3_config()] call returns.</dd>
1638 **
1639 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1640 ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
1641 ** is a pointer to an instance of the [sqlite3_mem_methods] structure.
1642 ** The [sqlite3_mem_methods]
1643 ** structure is filled with the currently defined memory allocation routines.)^
1644 ** This option can be used to overload the default memory allocation
1645 ** routines with a wrapper that simulations memory allocation failure or
1646 ** tracks memory usage, for example. </dd>
1647 **
1648 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1649 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1650 ** interpreted as a boolean, which enables or disables the collection of
1651 ** memory allocation statistics. ^(When memory allocation statistics are disabled, the
1652 ** following SQLite interfaces become non-operational:
1653 ** <ul>
1654 ** <li> [sqlite3_memory_used()]
1655 ** <li> [sqlite3_memory_highwater()]
1656 ** <li> [sqlite3_soft_heap_limit64()]
@@ -1660,90 +1658,78 @@
1660 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1661 ** allocation statistics are disabled by default.
1662 ** </dd>
1663 **
1664 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1665 ** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
1666 ** that SQLite can use for scratch memory. ^(There are three arguments
1667 ** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
1668 ** aligned memory buffer from which the scratch allocations will be
1669 ** drawn, the size of each scratch allocation (sz),
1670 ** and the maximum number of scratch allocations (N).)^
 
1671 ** The first argument must be a pointer to an 8-byte aligned buffer
1672 ** of at least sz*N bytes of memory.
1673 ** ^SQLite will not use more than one scratch buffers per thread.
1674 ** ^SQLite will never request a scratch buffer that is more than 6
1675 ** times the database page size.
1676 ** ^If SQLite needs needs additional
1677 ** scratch memory beyond what is provided by this configuration option, then
1678 ** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
1679 ** ^When the application provides any amount of scratch memory using
1680 ** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
1681 ** [sqlite3_malloc|heap allocations].
1682 ** This can help [Robson proof|prevent memory allocation failures] due to heap
1683 ** fragmentation in low-memory embedded systems.
1684 ** </dd>
1685 **
1686 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1687 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a static memory buffer
1688 ** that SQLite can use for the database page cache with the default page
1689 ** cache implementation.
1690 ** This configuration should not be used if an application-define page
1691 ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]
1692 ** configuration option.
1693 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned
1694 ** memory, the size of each page buffer (sz), and the number of pages (N).
1695 ** The sz argument should be the size of the largest database page
1696 ** (a power of two between 512 and 32768) plus some extra bytes for each
1697 ** page header. ^The number of extra bytes needed by the page header
1698 ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1699 ** to [sqlite3_config()].
1700 ** ^It is harmless, apart from the wasted memory,
1701 ** for the sz parameter to be larger than necessary. The first
1702 ** argument should pointer to an 8-byte aligned block of memory that
1703 ** is at least sz*N bytes of memory, otherwise subsequent behavior is
1704 ** undefined.
1705 ** ^SQLite will use the memory provided by the first argument to satisfy its
1706 ** memory needs for the first N pages that it adds to cache. ^If additional
1707 ** page cache memory is needed beyond what is provided by this option, then
1708 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd>
 
 
 
1709 **
1710 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1711 ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
1712 ** that SQLite will use for all of its dynamic memory allocation needs
1713 ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1714 ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
1715 ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
1716 ** [SQLITE_ERROR] if invoked otherwise.
1717 ** ^There are three arguments to SQLITE_CONFIG_HEAP:
1718 ** An 8-byte aligned pointer to the memory,
1719 ** the number of bytes in the memory buffer, and the minimum allocation size.
1720 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1721 ** to using its default memory allocator (the system malloc() implementation),
1722 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1723 ** memory pointer is not NULL then the alternative memory
 
1724 ** allocator is engaged to handle all of SQLites memory allocation needs.
1725 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1726 ** boundary or subsequent behavior of SQLite will be undefined.
1727 ** The minimum allocation size is capped at 2**12. Reasonable values
1728 ** for the minimum allocation size are 2**5 through 2**8.</dd>
1729 **
1730 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1731 ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
1732 ** pointer to an instance of the [sqlite3_mutex_methods] structure.
1733 ** The argument specifies alternative low-level mutex routines to be used in place
1734 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
1735 ** content of the [sqlite3_mutex_methods] structure before the call to
1736 ** [sqlite3_config()] returns. ^If SQLite is compiled with
1737 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1738 ** the entire mutexing subsystem is omitted from the build and hence calls to
1739 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1740 ** return [SQLITE_ERROR].</dd>
1741 **
1742 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1743 ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
1744 ** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
1745 ** [sqlite3_mutex_methods]
1746 ** structure is filled with the currently defined mutex routines.)^
1747 ** This option can be used to overload the default mutex allocation
1748 ** routines with a wrapper used to track mutex usage for performance
1749 ** profiling or testing, for example. ^If SQLite is compiled with
@@ -1751,28 +1737,28 @@
1751 ** the entire mutexing subsystem is omitted from the build and hence calls to
1752 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1753 ** return [SQLITE_ERROR].</dd>
1754 **
1755 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1756 ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
1757 ** the default size of lookaside memory on each [database connection].
1758 ** The first argument is the
1759 ** size of each lookaside buffer slot and the second is the number of
1760 ** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
1761 ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1762 ** option to [sqlite3_db_config()] can be used to change the lookaside
1763 ** configuration on individual connections.)^ </dd>
1764 **
1765 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1766 ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
1767 ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
1768 ** the interface to a custom page cache implementation.)^
1769 ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
1770 **
1771 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1772 ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
1773 ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of the current
1774 ** page cache implementation into that object.)^ </dd>
1775 **
1776 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1777 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
1778 ** global [error log].
@@ -1792,27 +1778,26 @@
1792 ** supplied by the application must not invoke any SQLite interface.
1793 ** In a multi-threaded application, the application-defined logger
1794 ** function must be threadsafe. </dd>
1795 **
1796 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1797 ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
1798 ** If non-zero, then URI handling is globally enabled. If the parameter is zero,
1799 ** then URI handling is globally disabled.)^ ^If URI handling is globally enabled,
1800 ** all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
1801 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1802 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1803 ** connection is opened. ^If it is globally disabled, filenames are
1804 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1805 ** database connection is opened. ^(By default, URI handling is globally
1806 ** disabled. The default value may be changed by compiling with the
1807 ** [SQLITE_USE_URI] symbol defined.)^
1808 **
1809 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1810 ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
1811 ** argument which is interpreted as a boolean in order to enable or disable
1812 ** the use of covering indices for full table scans in the query optimizer.
1813 ** ^The default setting is determined
1814 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
1815 ** if that compile-time option is omitted.
1816 ** The ability to disable the use of covering indices for full table scans
1817 ** is because some incorrectly coded legacy applications might malfunction
1818 ** when the optimization is enabled. Providing the ability to
@@ -1848,32 +1833,23 @@
1848 ** that are the default mmap size limit (the default setting for
1849 ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
1850 ** ^The default setting can be overridden by each database connection using
1851 ** either the [PRAGMA mmap_size] command, or by using the
1852 ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
1853 ** will be silently truncated if necessary so that it does not exceed the
1854 ** compile-time maximum mmap size set by the
1855 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
1856 ** ^If either argument to this option is negative, then that argument is
1857 ** changed to its compile-time default.
1858 **
1859 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
1860 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1861 ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
1862 ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1863 ** ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1864 ** that specifies the maximum size of the created heap.
1865 ** </dl>
1866 **
1867 ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
1868 ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
1869 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1870 ** is a pointer to an integer and writes into that integer the number of extra
1871 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. The amount of
1872 ** extra space required can change depending on the compiler,
1873 ** target platform, and SQLite version.
1874 ** </dl>
1875 */
1876 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1877 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1878 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
1879 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
@@ -1894,11 +1870,10 @@
1894 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1895 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1896 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1897 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1898 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1899 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
1900
1901 /*
1902 ** CAPI3REF: Database Connection Configuration Options
1903 **
1904 ** These constants are the available integer configuration options that
@@ -2022,49 +1997,51 @@
2022 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
2023
2024 /*
2025 ** CAPI3REF: Count The Number Of Rows Modified
2026 **
2027 ** ^This function returns the number of rows modified, inserted or
2028 ** deleted by the most recently completed INSERT, UPDATE or DELETE
2029 ** statement on the database connection specified by the only parameter.
2030 ** ^Executing any other type of SQL statement does not modify the value
2031 ** returned by this function.
2032 **
2033 ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
2034 ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
2035 ** [foreign key actions] or [REPLACE] constraint resolution are not counted.
2036 **
2037 ** Changes to a view that are intercepted by
2038 ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
2039 ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
2040 ** DELETE statement run on a view is always zero. Only changes made to real
2041 ** tables are counted.
2042 **
2043 ** Things are more complicated if the sqlite3_changes() function is
2044 ** executed while a trigger program is running. This may happen if the
2045 ** program uses the [changes() SQL function], or if some other callback
2046 ** function invokes sqlite3_changes() directly. Essentially:
2047 **
2048 ** <ul>
2049 ** <li> ^(Before entering a trigger program the value returned by
2050 ** sqlite3_changes() function is saved. After the trigger program
2051 ** has finished, the original value is restored.)^
2052 **
2053 ** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
2054 ** statement sets the value returned by sqlite3_changes()
2055 ** upon completion as normal. Of course, this value will not include
2056 ** any changes performed by sub-triggers, as the sqlite3_changes()
2057 ** value will be saved and restored after each sub-trigger has run.)^
2058 ** </ul>
2059 **
2060 ** ^This means that if the changes() SQL function (or similar) is used
2061 ** by the first INSERT, UPDATE or DELETE statement within a trigger, it
2062 ** returns the value as set when the calling statement began executing.
2063 ** ^If it is used by the second or subsequent such statement within a trigger
2064 ** program, the value returned reflects the number of rows modified by the
2065 ** previous INSERT, UPDATE or DELETE statement within the same trigger.
 
 
2066 **
2067 ** See also the [sqlite3_total_changes()] interface, the
2068 ** [count_changes pragma], and the [changes() SQL function].
2069 **
2070 ** If a separate thread makes changes on the same database connection
@@ -2074,21 +2051,24 @@
2074 SQLITE_API int sqlite3_changes(sqlite3*);
2075
2076 /*
2077 ** CAPI3REF: Total Number Of Rows Modified
2078 **
2079 ** ^This function returns the total number of rows inserted, modified or
2080 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2081 ** since the database connection was opened, including those executed as
2082 ** part of trigger programs. ^Executing any other type of SQL statement
2083 ** does not affect the value returned by sqlite3_total_changes().
2084 **
2085 ** ^Changes made as part of [foreign key actions] are included in the
2086 ** count, but those made as part of REPLACE constraint resolution are
2087 ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
2088 ** are not counted.
2089 **
 
 
 
2090 ** See also the [sqlite3_changes()] interface, the
2091 ** [count_changes pragma], and the [total_changes() SQL function].
2092 **
2093 ** If a separate thread makes changes on the same database connection
2094 ** while [sqlite3_total_changes()] is running then the value
@@ -2562,18 +2542,17 @@
2562 ** already uses the largest possible [ROWID]. The PRNG is also used for
2563 ** the build-in random() and randomblob() SQL functions. This interface allows
2564 ** applications to access the same PRNG for other purposes.
2565 **
2566 ** ^A call to this routine stores N bytes of randomness into buffer P.
2567 ** ^The P parameter can be a NULL pointer.
2568 **
2569 ** ^If this routine has not been previously called or if the previous
2570 ** call had N less than one or a NULL pointer for P, then the PRNG is
2571 ** seeded using randomness obtained from the xRandomness method of
2572 ** the default [sqlite3_vfs] object.
2573 ** ^If the previous call to this routine had an N of 1 or more and a
2574 ** non-NULL P then the pseudo-randomness is generated
2575 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2576 ** method.
2577 */
2578 SQLITE_API void sqlite3_randomness(int N, void *P);
2579
@@ -5784,46 +5763,30 @@
5784 **
5785 ** <pre>
5786 ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
5787 ** </pre>)^
5788 **
5789 ** ^(Parameter zDb is not the filename that contains the database, but
5790 ** rather the symbolic name of the database. For attached databases, this is
5791 ** the name that appears after the AS keyword in the [ATTACH] statement.
5792 ** For the main database file, the database name is "main". For TEMP
5793 ** tables, the database name is "temp".)^
5794 **
5795 ** ^If the flags parameter is non-zero, then the BLOB is opened for read
5796 ** and write access. ^If the flags parameter is zero, the BLOB is opened for
5797 ** read-only access.
5798 **
5799 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
5800 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
5801 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
5802 ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
5803 ** on *ppBlob after this function it returns.
5804 **
5805 ** This function fails with SQLITE_ERROR if any of the following are true:
5806 ** <ul>
5807 ** <li> ^(Database zDb does not exist)^,
5808 ** <li> ^(Table zTable does not exist within database zDb)^,
5809 ** <li> ^(Table zTable is a WITHOUT ROWID table)^,
5810 ** <li> ^(Column zColumn does not exist)^,
5811 ** <li> ^(Row iRow is not present in the table)^,
5812 ** <li> ^(The specified column of row iRow contains a value that is not
5813 ** a TEXT or BLOB value)^,
5814 ** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
5815 ** constraint and the blob is being opened for read/write access)^,
5816 ** <li> ^([foreign key constraints | Foreign key constraints] are enabled,
5817 ** column zColumn is part of a [child key] definition and the blob is
5818 ** being opened for read/write access)^.
5819 ** </ul>
5820 **
5821 ** ^Unless it returns SQLITE_MISUSE, this function sets the
5822 ** [database connection] error code and message accessible via
5823 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
5824 **
5825 **
5826 ** ^(If the row that a BLOB handle points to is modified by an
5827 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
5828 ** then the BLOB handle is marked as "expired".
5829 ** This is true if any column of the row is changed, even a column
@@ -5837,13 +5800,17 @@
5837 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
5838 ** the opened blob. ^The size of a blob may not be changed by this
5839 ** interface. Use the [UPDATE] SQL command to change the size of a
5840 ** blob.
5841 **
 
 
 
5842 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5843 ** and the built-in [zeroblob] SQL function may be used to create a
5844 ** zero-filled blob to read or write using the incremental-blob interface.
 
5845 **
5846 ** To avoid a resource leak, every open [BLOB handle] should eventually
5847 ** be released by a call to [sqlite3_blob_close()].
5848 */
5849 SQLITE_API int sqlite3_blob_open(
@@ -5881,26 +5848,28 @@
5881 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5882
5883 /*
5884 ** CAPI3REF: Close A BLOB Handle
5885 **
5886 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
5887 ** unconditionally. Even if this routine returns an error code, the
5888 ** handle is still closed.)^
5889 **
5890 ** ^If the blob handle being closed was opened for read-write access, and if
5891 ** the database is in auto-commit mode and there are no other open read-write
5892 ** blob handles or active write statements, the current transaction is
5893 ** committed. ^If an error occurs while committing the transaction, an error
5894 ** code is returned and the transaction rolled back.
5895 **
5896 ** Calling this function with an argument that is not a NULL pointer or an
5897 ** open blob handle results in undefined behaviour. ^Calling this routine
5898 ** with a null pointer (such as would be returned by a failed call to
5899 ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
5900 ** is passed a valid open blob handle, the values returned by the
5901 ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
 
 
5902 */
5903 SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
5904
5905 /*
5906 ** CAPI3REF: Return The Size Of An Open BLOB
@@ -5946,39 +5915,36 @@
5946 SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5947
5948 /*
5949 ** CAPI3REF: Write Data Into A BLOB Incrementally
5950 **
5951 ** ^(This function is used to write data into an open [BLOB handle] from a
5952 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
5953 ** into the open BLOB, starting at offset iOffset.)^
5954 **
5955 ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5956 ** Otherwise, an [error code] or an [extended error code] is returned.)^
5957 ** ^Unless SQLITE_MISUSE is returned, this function sets the
5958 ** [database connection] error code and message accessible via
5959 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
5960 **
5961 ** ^If the [BLOB handle] passed as the first argument was not opened for
5962 ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
5963 ** this function returns [SQLITE_READONLY].
5964 **
5965 ** This function may only modify the contents of the BLOB; it is
5966 ** not possible to increase the size of a BLOB using this API.
5967 ** ^If offset iOffset is less than N bytes from the end of the BLOB,
5968 ** [SQLITE_ERROR] is returned and no data is written. The size of the
5969 ** BLOB (and hence the maximum value of N+iOffset) can be determined
5970 ** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
5971 ** than zero [SQLITE_ERROR] is returned and no data is written.
5972 **
5973 ** ^An attempt to write to an expired [BLOB handle] fails with an
5974 ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
5975 ** before the [BLOB handle] expired are not rolled back by the
5976 ** expiration of the handle, though of course those changes might
5977 ** have been overwritten by the statement that expired the BLOB handle
5978 ** or by other independent statements.
5979 **
 
 
 
5980 ** This routine only works on a [BLOB handle] which has been created
5981 ** by a prior successful call to [sqlite3_blob_open()] and which has not
5982 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
5983 ** to this routine results in undefined and probably undesirable behavior.
5984 **
@@ -7567,102 +7533,10 @@
7567 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
7568 #define SQLITE_FAIL 3
7569 /* #define SQLITE_ABORT 4 // Also an error code */
7570 #define SQLITE_REPLACE 5
7571
7572 /*
7573 ** CAPI3REF: Prepared Statement Scan Status Opcodes
7574 ** KEYWORDS: {scanstatus options}
7575 **
7576 ** The following constants can be used for the T parameter to the
7577 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7578 ** different metric for sqlite3_stmt_scanstatus() to return.
7579 **
7580 ** <dl>
7581 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7582 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the
7583 ** total number of times that the X-th loop has run.</dd>
7584 **
7585 ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
7586 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the
7587 ** total number of rows examined by all iterations of the X-th loop.</dd>
7588 **
7589 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
7590 ** <dd>^The "double" variable pointed to by the T parameter will be set to the
7591 ** query planner's estimate for the average number of rows output from each
7592 ** iteration of the X-th loop. If the query planner's estimates was accurate,
7593 ** then this value will approximate the quotient NVISIT/NLOOP and the
7594 ** product of this value for all prior loops with the same SELECTID will
7595 ** be the NLOOP value for the current loop.
7596 **
7597 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
7598 ** <dd>^The "const char *" variable pointed to by the T parameter will be set to
7599 ** a zero-terminated UTF-8 string containing the name of the index or table used
7600 ** for the X-th loop.
7601 **
7602 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
7603 ** <dd>^The "const char *" variable pointed to by the T parameter will be set to
7604 ** a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] description
7605 ** for the X-th loop.
7606 **
7607 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
7608 ** <dd>^The "int" variable pointed to by the T parameter will be set to the
7609 ** "select-id" for the X-th loop. The select-id identifies which query or
7610 ** subquery the loop is part of. The main query has a select-id of zero.
7611 ** The select-id is the same value as is output in the first column
7612 ** of an [EXPLAIN QUERY PLAN] query.
7613 ** </dl>
7614 */
7615 #define SQLITE_SCANSTAT_NLOOP 0
7616 #define SQLITE_SCANSTAT_NVISIT 1
7617 #define SQLITE_SCANSTAT_EST 2
7618 #define SQLITE_SCANSTAT_NAME 3
7619 #define SQLITE_SCANSTAT_EXPLAIN 4
7620 #define SQLITE_SCANSTAT_SELECTID 5
7621
7622 /*
7623 ** CAPI3REF: Prepared Statement Scan Status
7624 **
7625 ** Return status data for a single loop within query pStmt.
7626 **
7627 ** The "iScanStatusOp" parameter determines which status information to return.
7628 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior of
7629 ** this interface is undefined.
7630 ** ^The requested measurement is written into a variable pointed to by
7631 ** the "pOut" parameter.
7632 ** Parameter "idx" identifies the specific loop to retrieve statistics for.
7633 ** Loops are numbered starting from zero. ^If idx is out of range - less than
7634 ** zero or greater than or equal to the total number of loops used to implement
7635 ** the statement - a non-zero value is returned and the variable that pOut
7636 ** points to is unchanged.
7637 **
7638 ** ^Statistics might not be available for all loops in all statements. ^In cases
7639 ** where there exist loops with no available statistics, this function behaves
7640 ** as if the loop did not exist - it returns non-zero and leave the variable
7641 ** that pOut points to unchanged.
7642 **
7643 ** This API is only available if the library is built with pre-processor
7644 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7645 **
7646 ** See also: [sqlite3_stmt_scanstatus_reset()]
7647 */
7648 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7649 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7650 int idx, /* Index of loop to report on */
7651 int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
7652 void *pOut /* Result written here */
7653 );
7654
7655 /*
7656 ** CAPI3REF: Zero Scan-Status Counters
7657 **
7658 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7659 **
7660 ** This API is only available if the library is built with pre-processor
7661 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7662 */
7663 SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
7664
7665
7666 /*
7667 ** Undo the hack that converts floating point types to integer for
7668 ** builds on processors without floating point support.
@@ -8104,13 +7978,14 @@
8104 #ifndef SQLITE_POWERSAFE_OVERWRITE
8105 # define SQLITE_POWERSAFE_OVERWRITE 1
8106 #endif
8107
8108 /*
8109 ** EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by
8110 ** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in
8111 ** which case memory allocation statistics are disabled by default.
 
8112 */
8113 #if !defined(SQLITE_DEFAULT_MEMSTATUS)
8114 # define SQLITE_DEFAULT_MEMSTATUS 1
8115 #endif
8116
@@ -8736,11 +8611,11 @@
8736 ** Estimated quantities used for query planning are stored as 16-bit
8737 ** logarithms. For quantity X, the value stored is 10*log2(X). This
8738 ** gives a possible range of values of approximately 1.0e986 to 1e-986.
8739 ** But the allowed values are "grainy". Not every value is representable.
8740 ** For example, quantities 16 and 17 are both represented by a LogEst
8741 ** of 40. However, since LogEst quantities are suppose to be estimates,
8742 ** not exact values, this imprecision is not a problem.
8743 **
8744 ** "LogEst" is short for "Logarithmic Estimate".
8745 **
8746 ** Examples:
@@ -9169,11 +9044,11 @@
9169 #define BTREE_BLOBKEY 2 /* Table has keys only - no data */
9170
9171 SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*);
9172 SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*);
9173 SQLITE_PRIVATE int sqlite3BtreeClearTableOfCursor(BtCursor*);
9174 SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree*, int, int);
9175
9176 SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue);
9177 SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
9178
9179 SQLITE_PRIVATE int sqlite3BtreeNewDb(Btree *p);
@@ -9249,11 +9124,10 @@
9249 SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
9250 SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
9251 SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
9252 SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask);
9253 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt);
9254 SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void);
9255
9256 #ifndef NDEBUG
9257 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
9258 #endif
9259
@@ -9792,16 +9666,10 @@
9792 # define VdbeCoverageAlwaysTaken(v)
9793 # define VdbeCoverageNeverTaken(v)
9794 # define VDBE_OFFSET_LINENO(x) 0
9795 #endif
9796
9797 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
9798 SQLITE_PRIVATE void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*);
9799 #else
9800 # define sqlite3VdbeScanStatus(a,b,c,d,e)
9801 #endif
9802
9803 #endif
9804
9805 /************** End of vdbe.h ************************************************/
9806 /************** Continuing where we left off in sqliteInt.h ******************/
9807 /************** Include pager.h in the middle of sqliteInt.h *****************/
@@ -9994,12 +9862,10 @@
9994 SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
9995
9996 /* Functions used to truncate the database file. */
9997 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
9998
9999 SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16);
10000
10001 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL)
10002 SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *);
10003 #endif
10004
10005 /* Functions to support testing and debugging. */
@@ -10183,14 +10049,10 @@
10183 SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*);
10184 #endif
10185
10186 SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
10187
10188 /* Return the header size */
10189 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void);
10190 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void);
10191
10192 #endif /* _PCACHE_H_ */
10193
10194 /************** End of pcache.h **********************************************/
10195 /************** Continuing where we left off in sqliteInt.h ******************/
10196
@@ -10873,11 +10735,11 @@
10873 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
10874 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10875 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10876 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
10877 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
10878 #define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */
10879 #define SQLITE_AllOpts 0xffff /* All optimizations */
10880
10881 /*
10882 ** Macros for testing whether or not optimizations are enabled or disabled.
10883 */
@@ -11460,12 +11322,11 @@
11460 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
11461 int nSample; /* Number of elements in aSample[] */
11462 int nSampleCol; /* Size of IndexSample.anEq[] and so on */
11463 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
11464 IndexSample *aSample; /* Samples of the left-most key */
11465 tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this index */
11466 tRowcnt nRowEst0; /* Non-logarithmic number of rows in the index */
11467 #endif
11468 };
11469
11470 /*
11471 ** Allowed values for Index.idxType
@@ -11659,11 +11520,11 @@
11659 int nHeight; /* Height of the tree headed by this node */
11660 #endif
11661 int iTable; /* TK_COLUMN: cursor number of table holding column
11662 ** TK_REGISTER: register number
11663 ** TK_TRIGGER: 1 -> new, 0 -> old
11664 ** EP_Unlikely: 134217728 times likelihood */
11665 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
11666 ** TK_VARIABLE: variable number (always >= 1). */
11667 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
11668 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
11669 u8 op2; /* TK_REGISTER: original value of Expr.op
@@ -12551,15 +12412,13 @@
12551 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
12552 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
12553 void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
12554 Parse *pParse; /* Parser context. */
12555 int walkerDepth; /* Number of subqueries */
12556 u8 eCode; /* A small processing code */
12557 union { /* Extra data for callback */
12558 NameContext *pNC; /* Naming context */
12559 int n; /* A counter */
12560 int iCur; /* A cursor number */
12561 SrcList *pSrcList; /* FROM clause */
12562 struct SrcCount *pSrcCount; /* Counting column references */
12563 } u;
12564 };
12565
@@ -12956,11 +12815,10 @@
12956 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
12957 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
12958 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
12959 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
12960 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
12961 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
12962 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
12963 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
12964 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
12965 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
12966 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
@@ -13614,23 +13472,15 @@
13614 ** compatibility for legacy applications, the URI filename capability is
13615 ** disabled by default.
13616 **
13617 ** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
13618 ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
13619 **
13620 ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
13621 ** disabled. The default value may be changed by compiling with the
13622 ** SQLITE_USE_URI symbol defined.
13623 */
13624 #ifndef SQLITE_USE_URI
13625 # define SQLITE_USE_URI 0
13626 #endif
13627
13628 /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
13629 ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
13630 ** that compile-time option is omitted.
13631 */
13632 #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
13633 # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
13634 #endif
13635
13636 /*
@@ -13716,12 +13566,12 @@
13716 ** than 1 GiB. The sqlite3_test_control() interface can be used to
13717 ** move the pending byte.
13718 **
13719 ** IMPORTANT: Changing the pending byte to any value other than
13720 ** 0x40000000 results in an incompatible database file format!
13721 ** Changing the pending byte during operation will result in undefined
13722 ** and incorrect behavior.
13723 */
13724 #ifndef SQLITE_OMIT_WSD
13725 SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
13726 #endif
13727
@@ -13797,13 +13647,10 @@
13797 "DISABLE_DIRSYNC",
13798 #endif
13799 #ifdef SQLITE_DISABLE_LFS
13800 "DISABLE_LFS",
13801 #endif
13802 #ifdef SQLITE_ENABLE_API_ARMOR
13803 "ENABLE_API_ARMOR",
13804 #endif
13805 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
13806 "ENABLE_ATOMIC_WRITE",
13807 #endif
13808 #ifdef SQLITE_ENABLE_CEROD
13809 "ENABLE_CEROD",
@@ -14125,17 +13972,10 @@
14125 ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
14126 ** is not required for a match.
14127 */
14128 SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
14129 int i, n;
14130
14131 #ifdef SQLITE_ENABLE_API_ARMOR
14132 if( zOptName==0 ){
14133 (void)SQLITE_MISUSE_BKPT;
14134 return 0;
14135 }
14136 #endif
14137 if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7;
14138 n = sqlite3Strlen30(zOptName);
14139
14140 /* Since ArraySize(azCompileOpt) is normally in single digits, a
14141 ** linear search is adequate. No need for a binary search. */
@@ -14313,11 +14153,10 @@
14313 typedef struct VdbeFrame VdbeFrame;
14314 struct VdbeFrame {
14315 Vdbe *v; /* VM this frame belongs to */
14316 VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */
14317 Op *aOp; /* Program instructions for parent frame */
14318 i64 *anExec; /* Event counters from parent frame */
14319 Mem *aMem; /* Array of memory cells for parent frame */
14320 u8 *aOnceFlag; /* Array of OP_Once flags for parent frame */
14321 VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */
14322 void *token; /* Copy of SubProgram.token */
14323 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
@@ -14326,12 +14165,11 @@
14326 int nOp; /* Size of aOp array */
14327 int nMem; /* Number of entries in aMem */
14328 int nOnceFlag; /* Number of entries in aOnceFlag */
14329 int nChildMem; /* Number of memory cells for child frame */
14330 int nChildCsr; /* Number of cursors for child frame */
14331 int nChange; /* Statement changes (Vdbe.nChange) */
14332 int nDbChange; /* Value of db->nChange */
14333 };
14334
14335 #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
14336
14337 /*
@@ -14478,20 +14316,10 @@
14478 /* A bitfield type for use inside of structures. Always follow with :N where
14479 ** N is the number of bits.
14480 */
14481 typedef unsigned bft; /* Bit Field Type */
14482
14483 typedef struct ScanStatus ScanStatus;
14484 struct ScanStatus {
14485 int addrExplain; /* OP_Explain for loop */
14486 int addrLoop; /* Address of "loops" counter */
14487 int addrVisit; /* Address of "rows visited" counter */
14488 int iSelectID; /* The "Select-ID" for this loop */
14489 LogEst nEst; /* Estimated output rows per loop */
14490 char *zName; /* Name of table or index */
14491 };
14492
14493 /*
14494 ** An instance of the virtual machine. This structure contains the complete
14495 ** state of the virtual machine.
14496 **
14497 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
@@ -14560,15 +14388,10 @@
14560 u32 expmask; /* Binding to these vars invalidates VM */
14561 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
14562 int nOnceFlag; /* Size of array aOnceFlag[] */
14563 u8 *aOnceFlag; /* Flags for OP_Once */
14564 AuxData *pAuxData; /* Linked list of auxdata allocations */
14565 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
14566 i64 *anExec; /* Number of times each op has been executed */
14567 int nScan; /* Entries in aScan[] */
14568 ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
14569 #endif
14570 };
14571
14572 /*
14573 ** The following are allowed values for Vdbe.magic
14574 */
@@ -14754,13 +14577,10 @@
14754 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
14755 wsdStatInit;
14756 if( op<0 || op>=ArraySize(wsdStat.nowValue) ){
14757 return SQLITE_MISUSE_BKPT;
14758 }
14759 #ifdef SQLITE_ENABLE_API_ARMOR
14760 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
14761 #endif
14762 *pCurrent = wsdStat.nowValue[op];
14763 *pHighwater = wsdStat.mxValue[op];
14764 if( resetFlag ){
14765 wsdStat.mxValue[op] = wsdStat.nowValue[op];
14766 }
@@ -14776,15 +14596,10 @@
14776 int *pCurrent, /* Write current value here */
14777 int *pHighwater, /* Write high-water mark here */
14778 int resetFlag /* Reset high-water mark if true */
14779 ){
14780 int rc = SQLITE_OK; /* Return code */
14781 #ifdef SQLITE_ENABLE_API_ARMOR
14782 if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){
14783 return SQLITE_MISUSE_BKPT;
14784 }
14785 #endif
14786 sqlite3_mutex_enter(db->mutex);
14787 switch( op ){
14788 case SQLITE_DBSTATUS_LOOKASIDE_USED: {
14789 *pCurrent = db->lookaside.nOut;
14790 *pHighwater = db->lookaside.mxOut;
@@ -14959,11 +14774,11 @@
14959 **
14960 ** There is only one exported symbol in this file - the function
14961 ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
14962 ** All other code has file scope.
14963 **
14964 ** SQLite processes all times and dates as julian day numbers. The
14965 ** dates and times are stored as the number of days since noon
14966 ** in Greenwich on November 24, 4714 B.C. according to the Gregorian
14967 ** calendar system.
14968 **
14969 ** 1970-01-01 00:00:00 is JD 2440587.5
@@ -14974,11 +14789,11 @@
14974 ** be represented, even though julian day numbers allow a much wider
14975 ** range of dates.
14976 **
14977 ** The Gregorian calendar system is used for all dates and times,
14978 ** even those that predate the Gregorian calendar. Historians usually
14979 ** use the julian calendar for dates prior to 1582-10-15 and for some
14980 ** dates afterwards, depending on locale. Beware of this difference.
14981 **
14982 ** The conversion algorithms are implemented based on descriptions
14983 ** in the following text:
14984 **
@@ -15246,11 +15061,11 @@
15246 return 1;
15247 }
15248 }
15249
15250 /*
15251 ** Attempt to parse the given string into a julian day number. Return
15252 ** the number of errors.
15253 **
15254 ** The following are acceptable forms for the input string:
15255 **
15256 ** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM
@@ -15817,11 +15632,11 @@
15817 **
15818 ** %d day of month
15819 ** %f ** fractional seconds SS.SSS
15820 ** %H hour 00-24
15821 ** %j day of year 000-366
15822 ** %J ** julian day number
15823 ** %m month 01-12
15824 ** %M minute 00-59
15825 ** %s seconds since 1970-01-01
15826 ** %S seconds 00-59
15827 ** %w day of week 0-6 sunday==0
@@ -16442,14 +16257,10 @@
16442 MUTEX_LOGIC(sqlite3_mutex *mutex;)
16443 #ifndef SQLITE_OMIT_AUTOINIT
16444 int rc = sqlite3_initialize();
16445 if( rc ) return rc;
16446 #endif
16447 #ifdef SQLITE_ENABLE_API_ARMOR
16448 if( pVfs==0 ) return SQLITE_MISUSE_BKPT;
16449 #endif
16450
16451 MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
16452 sqlite3_mutex_enter(mutex);
16453 vfsUnlink(pVfs);
16454 if( makeDflt || vfsList==0 ){
16455 pVfs->pNext = vfsList;
@@ -18803,11 +18614,10 @@
18803 ** Retrieve a pointer to a static mutex or allocate a new dynamic one.
18804 */
18805 SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){
18806 #ifndef SQLITE_OMIT_AUTOINIT
18807 if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
18808 if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0;
18809 #endif
18810 return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
18811 }
18812
18813 SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){
@@ -19260,16 +19070,12 @@
19260 pthread_mutex_init(&p->mutex, 0);
19261 }
19262 break;
19263 }
19264 default: {
19265 #ifdef SQLITE_ENABLE_API_ARMOR
19266 if( iType-2<0 || iType-2>=ArraySize(staticMutexes) ){
19267 (void)SQLITE_MISUSE_BKPT;
19268 return 0;
19269 }
19270 #endif
19271 p = &staticMutexes[iType-2];
19272 #if SQLITE_MUTEX_NREF
19273 p->id = iType;
19274 #endif
19275 break;
@@ -20487,16 +20293,15 @@
20487 }
20488 assert( sqlite3_mutex_notheld(mem0.mutex) );
20489
20490
20491 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
20492 /* EVIDENCE-OF: R-12970-05880 SQLite will not use more than one scratch
20493 ** buffers per thread.
20494 **
20495 ** This can only be checked in single-threaded mode.
20496 */
20497 assert( scratchAllocOut==0 );
20498 if( p ) scratchAllocOut++;
20499 #endif
20500
20501 return p;
20502 }
@@ -21151,17 +20956,10 @@
21151 etByte flag_rtz; /* True if trailing zeros should be removed */
21152 #endif
21153 PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
21154 char buf[etBUFSIZE]; /* Conversion buffer */
21155
21156 #ifdef SQLITE_ENABLE_API_ARMOR
21157 if( ap==0 ){
21158 (void)SQLITE_MISUSE_BKPT;
21159 sqlite3StrAccumReset(pAccum);
21160 return;
21161 }
21162 #endif
21163 bufpt = 0;
21164 if( bFlags ){
21165 if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
21166 pArgList = va_arg(ap, PrintfArguments*);
21167 }
@@ -21698,15 +21496,10 @@
21698 return N;
21699 }else{
21700 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
21701 i64 szNew = p->nChar;
21702 szNew += N + 1;
21703 if( szNew+p->nChar<=p->mxAlloc ){
21704 /* Force exponential buffer size growth as long as it does not overflow,
21705 ** to avoid having to call this routine too often */
21706 szNew += p->nChar;
21707 }
21708 if( szNew > p->mxAlloc ){
21709 sqlite3StrAccumReset(p);
21710 setStrAccumError(p, STRACCUM_TOOBIG);
21711 return 0;
21712 }else{
@@ -21719,11 +21512,10 @@
21719 }
21720 if( zNew ){
21721 assert( p->zText!=0 || p->nChar==0 );
21722 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
21723 p->zText = zNew;
21724 p->nAlloc = sqlite3DbMallocSize(p->db, zNew);
21725 }else{
21726 sqlite3StrAccumReset(p);
21727 setStrAccumError(p, STRACCUM_NOMEM);
21728 return 0;
21729 }
@@ -21889,17 +21681,10 @@
21889 */
21890 SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){
21891 char *z;
21892 char zBase[SQLITE_PRINT_BUF_SIZE];
21893 StrAccum acc;
21894
21895 #ifdef SQLITE_ENABLE_API_ARMOR
21896 if( zFormat==0 ){
21897 (void)SQLITE_MISUSE_BKPT;
21898 return 0;
21899 }
21900 #endif
21901 #ifndef SQLITE_OMIT_AUTOINIT
21902 if( sqlite3_initialize() ) return 0;
21903 #endif
21904 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
21905 acc.useMalloc = 2;
@@ -21938,17 +21723,10 @@
21938 ** sqlite3_vsnprintf() is the varargs version.
21939 */
21940 SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
21941 StrAccum acc;
21942 if( n<=0 ) return zBuf;
21943 #ifdef SQLITE_ENABLE_API_ARMOR
21944 if( zBuf==0 || zFormat==0 ) {
21945 (void)SQLITE_MISUSE_BKPT;
21946 if( zBuf && n>0 ) zBuf[0] = 0;
21947 return zBuf;
21948 }
21949 #endif
21950 sqlite3StrAccumInit(&acc, zBuf, n, 0);
21951 acc.useMalloc = 0;
21952 sqlite3VXPrintf(&acc, 0, zFormat, ap);
21953 return sqlite3StrAccumFinish(&acc);
21954 }
@@ -22136,23 +21914,15 @@
22136 #else
22137 # define wsdPrng sqlite3Prng
22138 #endif
22139
22140 #if SQLITE_THREADSAFE
22141 sqlite3_mutex *mutex;
22142 #endif
22143
22144 #ifndef SQLITE_OMIT_AUTOINIT
22145 if( sqlite3_initialize() ) return;
22146 #endif
22147
22148 #if SQLITE_THREADSAFE
22149 mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
22150 #endif
22151
22152 sqlite3_mutex_enter(mutex);
22153 if( N<=0 || pBuf==0 ){
 
 
22154 wsdPrng.isInit = 0;
22155 sqlite3_mutex_leave(mutex);
22156 return;
22157 }
22158
@@ -23270,27 +23040,17 @@
23270 ** case-independent fashion, using the same definition of "case
23271 ** independence" that SQLite uses internally when comparing identifiers.
23272 */
23273 SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){
23274 register unsigned char *a, *b;
23275 if( zLeft==0 ){
23276 return zRight ? -1 : 0;
23277 }else if( zRight==0 ){
23278 return 1;
23279 }
23280 a = (unsigned char *)zLeft;
23281 b = (unsigned char *)zRight;
23282 while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
23283 return UpperToLower[*a] - UpperToLower[*b];
23284 }
23285 SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
23286 register unsigned char *a, *b;
23287 if( zLeft==0 ){
23288 return zRight ? -1 : 0;
23289 }else if( zRight==0 ){
23290 return 1;
23291 }
23292 a = (unsigned char *)zLeft;
23293 b = (unsigned char *)zRight;
23294 while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
23295 return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
23296 }
@@ -32819,15 +32579,10 @@
32819 #if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL)
32820 # error "WAL mode requires support from the Windows NT kernel, compile\
32821 with SQLITE_OMIT_WAL."
32822 #endif
32823
32824 #if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0
32825 # error "Memory mapped files require support from the Windows NT kernel,\
32826 compile with SQLITE_MAX_MMAP_SIZE=0."
32827 #endif
32828
32829 /*
32830 ** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions
32831 ** based on the sub-platform)?
32832 */
32833 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI)
@@ -32953,15 +32708,14 @@
32953 # define winGetDirSep() '\\'
32954 #endif
32955
32956 /*
32957 ** Do we need to manually define the Win32 file mapping APIs for use with WAL
32958 ** mode or memory mapped files (e.g. these APIs are available in the Windows
32959 ** CE SDK; however, they are not present in the header file)?
32960 */
32961 #if SQLITE_WIN32_FILEMAPPING_API && \
32962 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
32963 /*
32964 ** Two of the file mapping APIs are different under WinRT. Figure out which
32965 ** set we need.
32966 */
32967 #if SQLITE_OS_WINRT
@@ -32985,11 +32739,11 @@
32985
32986 /*
32987 ** This file mapping API is common to both Win32 and WinRT.
32988 */
32989 WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID);
32990 #endif /* SQLITE_WIN32_FILEMAPPING_API */
32991
32992 /*
32993 ** Some Microsoft compilers lack this definition.
32994 */
32995 #ifndef INVALID_FILE_ATTRIBUTES
@@ -33278,21 +33032,21 @@
33278
33279 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
33280 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
33281
33282 #if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \
33283 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
33284 { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
33285 #else
33286 { "CreateFileMappingA", (SYSCALL)0, 0 },
33287 #endif
33288
33289 #define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
33290 DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent)
33291
33292 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
33293 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
33294 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
33295 #else
33296 { "CreateFileMappingW", (SYSCALL)0, 0 },
33297 #endif
33298
@@ -33628,12 +33382,11 @@
33628 #ifndef osLockFileEx
33629 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
33630 LPOVERLAPPED))aSyscall[48].pCurrent)
33631 #endif
33632
33633 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && \
33634 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
33635 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
33636 #else
33637 { "MapViewOfFile", (SYSCALL)0, 0 },
33638 #endif
33639
@@ -33699,11 +33452,11 @@
33699 #endif
33700
33701 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
33702 LPOVERLAPPED))aSyscall[58].pCurrent)
33703
33704 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
33705 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
33706 #else
33707 { "UnmapViewOfFile", (SYSCALL)0, 0 },
33708 #endif
33709
@@ -33762,11 +33515,11 @@
33762 #endif
33763
33764 #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
33765 FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent)
33766
33767 #if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
33768 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
33769 #else
33770 { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
33771 #endif
33772
@@ -33826,11 +33579,11 @@
33826
33827 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
33828
33829 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent)
33830
33831 #if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
33832 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
33833 #else
33834 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
33835 #endif
33836
@@ -39402,17 +39155,10 @@
39402 */
39403 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
39404 assert( pCache->pCache!=0 );
39405 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
39406 }
39407
39408 /*
39409 ** Return the size of the header added by this middleware layer
39410 ** in the page-cache hierarchy.
39411 */
39412 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); }
39413
39414
39415 #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
39416 /*
39417 ** For all dirty pages currently in the cache, invoke the specified
39418 ** callback. This is only used if the SQLITE_CHECK_PAGES macro is
@@ -40408,15 +40154,10 @@
40408 pcache1Shrink /* xShrink */
40409 };
40410 sqlite3_config(SQLITE_CONFIG_PCACHE2, &defaultMethods);
40411 }
40412
40413 /*
40414 ** Return the size of the header on each page of this PCACHE implementation.
40415 */
40416 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); }
40417
40418 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40419 /*
40420 ** This function is called to free superfluous dynamically allocated memory
40421 ** held by the pager system. Memory in use by any SQLite pager allocated
40422 ** by the current thread may be sqlite3_free()ed.
@@ -47970,22 +47711,10 @@
47970
47971 return SQLITE_OK;
47972 }
47973 #endif
47974
47975 /*
47976 ** The page handle passed as the first argument refers to a dirty page
47977 ** with a page number other than iNew. This function changes the page's
47978 ** page number to iNew and sets the value of the PgHdr.flags field to
47979 ** the value passed as the third parameter.
47980 */
47981 SQLITE_PRIVATE void sqlite3PagerRekey(DbPage *pPg, Pgno iNew, u16 flags){
47982 assert( pPg->pgno!=iNew );
47983 pPg->flags = flags;
47984 sqlite3PcacheMove(pPg, iNew);
47985 }
47986
47987 /*
47988 ** Return a pointer to the data for the specified page.
47989 */
47990 SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *pPg){
47991 assert( pPg->nRef>0 || pPg->pPager->memDb );
@@ -48379,11 +48108,10 @@
48379 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){
48380 assert( pPager->eState>=PAGER_READER );
48381 return sqlite3WalFramesize(pPager->pWal);
48382 }
48383 #endif
48384
48385
48386 #endif /* SQLITE_OMIT_DISKIO */
48387
48388 /************** End of pager.c ***********************************************/
48389 /************** Begin file wal.c *********************************************/
@@ -49890,11 +49618,11 @@
49890
49891 /*
49892 ** Free an iterator allocated by walIteratorInit().
49893 */
49894 static void walIteratorFree(WalIterator *p){
49895 sqlite3_free(p);
49896 }
49897
49898 /*
49899 ** Construct a WalInterator object that can be used to loop over all
49900 ** pages in the WAL in ascending order. The caller must hold the checkpoint
@@ -49925,21 +49653,21 @@
49925 /* Allocate space for the WalIterator object. */
49926 nSegment = walFramePage(iLast) + 1;
49927 nByte = sizeof(WalIterator)
49928 + (nSegment-1)*sizeof(struct WalSegment)
49929 + iLast*sizeof(ht_slot);
49930 p = (WalIterator *)sqlite3_malloc(nByte);
49931 if( !p ){
49932 return SQLITE_NOMEM;
49933 }
49934 memset(p, 0, nByte);
49935 p->nSegment = nSegment;
49936
49937 /* Allocate temporary space used by the merge-sort routine. This block
49938 ** of memory will be freed before this function returns.
49939 */
49940 aTmp = (ht_slot *)sqlite3_malloc(
49941 sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
49942 );
49943 if( !aTmp ){
49944 rc = SQLITE_NOMEM;
49945 }
@@ -49972,11 +49700,11 @@
49972 p->aSegment[i].nEntry = nEntry;
49973 p->aSegment[i].aIndex = aIndex;
49974 p->aSegment[i].aPgno = (u32 *)aPgno;
49975 }
49976 }
49977 sqlite3_free(aTmp);
49978
49979 if( rc!=SQLITE_OK ){
49980 walIteratorFree(p);
49981 }
49982 *pp = p;
@@ -50892,11 +50620,11 @@
50892 ** was in before the client began writing to the database.
50893 */
50894 memcpy(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr));
50895
50896 for(iFrame=pWal->hdr.mxFrame+1;
50897 rc==SQLITE_OK && iFrame<=iMax;
50898 iFrame++
50899 ){
50900 /* This call cannot fail. Unless the page for which the page number
50901 ** is passed as the second argument is (a) in the cache and
50902 ** (b) has an outstanding reference, then xUndo is either a no-op
@@ -51989,10 +51717,15 @@
51989 ** but cursors cannot be shared. Each cursor is associated with a
51990 ** particular database connection identified BtCursor.pBtree.db.
51991 **
51992 ** Fields in this structure are accessed under the BtShared.mutex
51993 ** found at self->pBt->mutex.
 
 
 
 
 
51994 */
51995 struct BtCursor {
51996 Btree *pBtree; /* The Btree to which this cursor belongs */
51997 BtShared *pBt; /* The BtShared this cursor points to */
51998 BtCursor *pNext, *pPrev; /* Forms a linked list of all cursors */
@@ -52001,11 +51734,12 @@
52001 CellInfo info; /* A parse of the cell we are pointing at */
52002 i64 nKey; /* Size of pKey, or last integer key */
52003 void *pKey; /* Saved key that was cursor last known position */
52004 Pgno pgnoRoot; /* The root page of this tree */
52005 int nOvflAlloc; /* Allocated size of aOverflow[] array */
52006 int skipNext; /* Prev() is noop if negative. Next() is noop if positive */
 
52007 u8 curFlags; /* zero or more BTCF_* flags defined below */
52008 u8 eState; /* One of the CURSOR_XXX constants (see below) */
52009 u8 hints; /* As configured by CursorSetHints() */
52010 i16 iPage; /* Index of current page in apPage */
52011 u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
@@ -52047,11 +51781,11 @@
52047 ** CURSOR_FAULT:
52048 ** An unrecoverable error (an I/O error or a malloc failure) has occurred
52049 ** on a different connection that shares the BtShared cache with this
52050 ** cursor. The error has left the cache in an inconsistent state.
52051 ** Do nothing else with this cursor. Any attempt to use the cursor
52052 ** should return the error code stored in BtCursor.skip
52053 */
52054 #define CURSOR_INVALID 0
52055 #define CURSOR_VALID 1
52056 #define CURSOR_SKIPNEXT 2
52057 #define CURSOR_REQUIRESEEK 3
@@ -53609,27 +53343,28 @@
53609 int cellOffset; /* Offset to the cell pointer array */
53610 int cbrk; /* Offset to the cell content area */
53611 int nCell; /* Number of cells on the page */
53612 unsigned char *data; /* The page data */
53613 unsigned char *temp; /* Temp area for cell content */
53614 unsigned char *src; /* Source of content */
53615 int iCellFirst; /* First allowable cell index */
53616 int iCellLast; /* Last possible cell index */
53617
53618
53619 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
53620 assert( pPage->pBt!=0 );
53621 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
53622 assert( pPage->nOverflow==0 );
53623 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53624 temp = 0;
53625 src = data = pPage->aData;
53626 hdr = pPage->hdrOffset;
53627 cellOffset = pPage->cellOffset;
53628 nCell = pPage->nCell;
53629 assert( nCell==get2byte(&data[hdr+3]) );
53630 usableSize = pPage->pBt->usableSize;
 
 
53631 cbrk = usableSize;
53632 iCellFirst = cellOffset + 2*nCell;
53633 iCellLast = usableSize - 4;
53634 for(i=0; i<nCell; i++){
53635 u8 *pAddr; /* The i-th cell pointer */
@@ -53644,11 +53379,11 @@
53644 if( pc<iCellFirst || pc>iCellLast ){
53645 return SQLITE_CORRUPT_BKPT;
53646 }
53647 #endif
53648 assert( pc>=iCellFirst && pc<=iCellLast );
53649 size = cellSizePtr(pPage, &src[pc]);
53650 cbrk -= size;
53651 #if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
53652 if( cbrk<iCellFirst ){
53653 return SQLITE_CORRUPT_BKPT;
53654 }
@@ -53658,20 +53393,12 @@
53658 }
53659 #endif
53660 assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
53661 testcase( cbrk+size==usableSize );
53662 testcase( pc+size==usableSize );
 
53663 put2byte(pAddr, cbrk);
53664 if( temp==0 ){
53665 int x;
53666 if( cbrk==pc ) continue;
53667 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
53668 x = get2byte(&data[hdr+5]);
53669 memcpy(&temp[x], &data[x], (cbrk+size) - x);
53670 src = temp;
53671 }
53672 memcpy(&data[cbrk], &src[pc], size);
53673 }
53674 assert( cbrk>=iCellFirst );
53675 put2byte(&data[hdr+5], cbrk);
53676 data[hdr+1] = 0;
53677 data[hdr+2] = 0;
@@ -53682,66 +53409,10 @@
53682 return SQLITE_CORRUPT_BKPT;
53683 }
53684 return SQLITE_OK;
53685 }
53686
53687 /*
53688 ** Search the free-list on page pPg for space to store a cell nByte bytes in
53689 ** size. If one can be found, return a pointer to the space and remove it
53690 ** from the free-list.
53691 **
53692 ** If no suitable space can be found on the free-list, return NULL.
53693 **
53694 ** This function may detect corruption within pPg. If corruption is
53695 ** detected then *pRc is set to SQLITE_CORRUPT and NULL is returned.
53696 **
53697 ** If a slot of at least nByte bytes is found but cannot be used because
53698 ** there are already at least 60 fragmented bytes on the page, return NULL.
53699 ** In this case, if pbDefrag parameter is not NULL, set *pbDefrag to true.
53700 */
53701 static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc, int *pbDefrag){
53702 const int hdr = pPg->hdrOffset;
53703 u8 * const aData = pPg->aData;
53704 int iAddr;
53705 int pc;
53706 int usableSize = pPg->pBt->usableSize;
53707
53708 for(iAddr=hdr+1; (pc = get2byte(&aData[iAddr]))>0; iAddr=pc){
53709 int size; /* Size of the free slot */
53710 if( pc>usableSize-4 || pc<iAddr+4 ){
53711 *pRc = SQLITE_CORRUPT_BKPT;
53712 return 0;
53713 }
53714 size = get2byte(&aData[pc+2]);
53715 if( size>=nByte ){
53716 int x = size - nByte;
53717 testcase( x==4 );
53718 testcase( x==3 );
53719 if( x<4 ){
53720 if( aData[hdr+7]>=60 ){
53721 if( pbDefrag ) *pbDefrag = 1;
53722 return 0;
53723 }
53724 /* Remove the slot from the free-list. Update the number of
53725 ** fragmented bytes within the page. */
53726 memcpy(&aData[iAddr], &aData[pc], 2);
53727 aData[hdr+7] += (u8)x;
53728 }else if( size+pc > usableSize ){
53729 *pRc = SQLITE_CORRUPT_BKPT;
53730 return 0;
53731 }else{
53732 /* The slot remains on the free-list. Reduce its size to account
53733 ** for the portion used by the new allocation. */
53734 put2byte(&aData[pc+2], x);
53735 }
53736 return &aData[pc + x];
53737 }
53738 }
53739
53740 return 0;
53741 }
53742
53743 /*
53744 ** Allocate nByte bytes of space from within the B-Tree page passed
53745 ** as the first argument. Write into *pIdx the index into pPage->aData[]
53746 ** of the first byte of allocated space. Return either SQLITE_OK or
53747 ** an error code (usually SQLITE_CORRUPT).
@@ -53755,20 +53426,22 @@
53755 */
53756 static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
53757 const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */
53758 u8 * const data = pPage->aData; /* Local cache of pPage->aData */
53759 int top; /* First byte of cell content area */
53760 int rc = SQLITE_OK; /* Integer return code */
53761 int gap; /* First byte of gap between cell pointers and cell content */
 
 
53762
53763 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
53764 assert( pPage->pBt );
53765 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53766 assert( nByte>=0 ); /* Minimum cell size is 4 */
53767 assert( pPage->nFree>=nByte );
53768 assert( pPage->nOverflow==0 );
53769 assert( nByte < (int)(pPage->pBt->usableSize-8) );
 
53770
53771 assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf );
53772 gap = pPage->cellOffset + 2*pPage->nCell;
53773 assert( gap<=65536 );
53774 top = get2byte(&data[hdr+5]);
@@ -53786,27 +53459,46 @@
53786 */
53787 testcase( gap+2==top );
53788 testcase( gap+1==top );
53789 testcase( gap==top );
53790 if( gap+2<=top && (data[hdr+1] || data[hdr+2]) ){
53791 int bDefrag = 0;
53792 u8 *pSpace = pageFindSlot(pPage, nByte, &rc, &bDefrag);
53793 if( rc ) return rc;
53794 if( bDefrag ) goto defragment_page;
53795 if( pSpace ){
53796 assert( pSpace>=data && (pSpace - data)<65536 );
53797 *pIdx = (int)(pSpace - data);
53798 return SQLITE_OK;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53799 }
53800 }
53801
53802 /* The request could not be fulfilled using a freelist slot. Check
53803 ** to see if defragmentation is necessary.
53804 */
53805 testcase( gap+2+nByte==top );
53806 if( gap+2+nByte>top ){
53807 defragment_page:
53808 testcase( pPage->nCell==0 );
53809 rc = defragmentPage(pPage);
53810 if( rc ) return rc;
53811 top = get2byteNotZero(&data[hdr+5]);
53812 assert( gap+nByte<=top );
@@ -53850,11 +53542,11 @@
53850 unsigned char *data = pPage->aData; /* Page content */
53851
53852 assert( pPage->pBt!=0 );
53853 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
53854 assert( iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
53855 assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize );
53856 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53857 assert( iSize>=4 ); /* Minimum cell size is 4 */
53858 assert( iStart<=iLast );
53859
53860 /* Overwrite deleted information with zeros when the secure_delete
@@ -55972,33 +55664,56 @@
55972 **
55973 ** Every cursor is a candidate to be tripped, including cursors
55974 ** that belong to other database connections that happen to be
55975 ** sharing the cache with pBtree.
55976 **
55977 ** This routine gets called when a rollback occurs. The writeOnly
55978 ** flag is set to 1 if the transaction did not make any schema
55979 ** changes, in which case the read cursors can continue operating.
55980 ** If schema changes did occur in the transaction, then both read
55981 ** and write cursors must both be tripped.
 
 
 
 
 
 
 
 
 
 
55982 */
55983 SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode, int writeOnly){
55984 BtCursor *p;
 
 
55985 assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 );
55986 if( pBtree==0 ) return;
55987 sqlite3BtreeEnter(pBtree);
55988 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
55989 int i;
55990 if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ) continue;
55991 sqlite3BtreeClearCursor(p);
55992 p->eState = CURSOR_FAULT;
55993 p->skipNext = errCode;
55994 for(i=0; i<=p->iPage; i++){
55995 releasePage(p->apPage[i]);
55996 p->apPage[i] = 0;
55997 }
55998 }
55999 sqlite3BtreeLeave(pBtree);
 
 
 
 
 
 
 
 
 
 
 
56000 }
56001
56002 /*
56003 ** Rollback the transaction in progress.
56004 **
@@ -56023,11 +55738,13 @@
56023 if( rc ) writeOnly = 0;
56024 }else{
56025 rc = SQLITE_OK;
56026 }
56027 if( tripCode ){
56028 sqlite3BtreeTripAllCursors(p, tripCode, writeOnly);
 
 
56029 }
56030 btreeIntegrity(p);
56031
56032 if( p->inTrans==TRANS_WRITE ){
56033 int rc2;
@@ -56358,17 +56075,13 @@
56358 **
56359 ** This routine cannot fail. It always returns SQLITE_OK.
56360 */
56361 SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){
56362 assert( cursorHoldsMutex(pCur) );
56363 assert( pCur->eState==CURSOR_INVALID || pCur->eState==CURSOR_VALID );
56364 if( pCur->eState!=CURSOR_VALID ){
56365 *pSize = 0;
56366 }else{
56367 getCellInfo(pCur);
56368 *pSize = pCur->info.nKey;
56369 }
56370 return SQLITE_OK;
56371 }
56372
56373 /*
56374 ** Set *pSize to the number of bytes of data in the entry the
@@ -58444,266 +58157,49 @@
58444 #endif
58445 }
58446 }
58447
58448 /*
58449 ** Array apCell[] contains pointers to nCell b-tree page cells. The
58450 ** szCell[] array contains the size in bytes of each cell. This function
58451 ** replaces the current contents of page pPg with the contents of the cell
58452 ** array.
58453 **
58454 ** Some of the cells in apCell[] may currently be stored in pPg. This
58455 ** function works around problems caused by this by making a copy of any
58456 ** such cells before overwriting the page data.
58457 **
58458 ** The MemPage.nFree field is invalidated by this function. It is the
58459 ** responsibility of the caller to set it correctly.
58460 */
58461 static void rebuildPage(
58462 MemPage *pPg, /* Edit this page */
58463 int nCell, /* Final number of cells on page */
58464 u8 **apCell, /* Array of cells */
58465 u16 *szCell /* Array of cell sizes */
58466 ){
58467 const int hdr = pPg->hdrOffset; /* Offset of header on pPg */
58468 u8 * const aData = pPg->aData; /* Pointer to data for pPg */
58469 const int usableSize = pPg->pBt->usableSize;
58470 u8 * const pEnd = &aData[usableSize];
58471 int i;
58472 u8 *pCellptr = pPg->aCellIdx;
58473 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
58474 u8 *pData;
58475
58476 i = get2byte(&aData[hdr+5]);
58477 memcpy(&pTmp[i], &aData[i], usableSize - i);
58478
58479 pData = pEnd;
58480 for(i=0; i<nCell; i++){
58481 u8 *pCell = apCell[i];
58482 if( pCell>aData && pCell<pEnd ){
58483 pCell = &pTmp[pCell - aData];
58484 }
58485 pData -= szCell[i];
58486 memcpy(pData, pCell, szCell[i]);
58487 put2byte(pCellptr, (pData - aData));
58488 pCellptr += 2;
58489 assert( szCell[i]==cellSizePtr(pPg, pCell) );
58490 }
58491
58492 /* The pPg->nFree field is now set incorrectly. The caller will fix it. */
58493 pPg->nCell = nCell;
58494 pPg->nOverflow = 0;
58495
58496 put2byte(&aData[hdr+1], 0);
58497 put2byte(&aData[hdr+3], pPg->nCell);
58498 put2byte(&aData[hdr+5], pData - aData);
58499 aData[hdr+7] = 0x00;
58500 }
58501
58502 /*
58503 ** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
58504 ** contains the size in bytes of each such cell. This function attempts to
58505 ** add the cells stored in the array to page pPg. If it cannot (because
58506 ** the page needs to be defragmented before the cells will fit), non-zero
58507 ** is returned. Otherwise, if the cells are added successfully, zero is
58508 ** returned.
58509 **
58510 ** Argument pCellptr points to the first entry in the cell-pointer array
58511 ** (part of page pPg) to populate. After cell apCell[0] is written to the
58512 ** page body, a 16-bit offset is written to pCellptr. And so on, for each
58513 ** cell in the array. It is the responsibility of the caller to ensure
58514 ** that it is safe to overwrite this part of the cell-pointer array.
58515 **
58516 ** When this function is called, *ppData points to the start of the
58517 ** content area on page pPg. If the size of the content area is extended,
58518 ** *ppData is updated to point to the new start of the content area
58519 ** before returning.
58520 **
58521 ** Finally, argument pBegin points to the byte immediately following the
58522 ** end of the space required by this page for the cell-pointer area (for
58523 ** all cells - not just those inserted by the current call). If the content
58524 ** area must be extended to before this point in order to accomodate all
58525 ** cells in apCell[], then the cells do not fit and non-zero is returned.
58526 */
58527 static int pageInsertArray(
58528 MemPage *pPg, /* Page to add cells to */
58529 u8 *pBegin, /* End of cell-pointer array */
58530 u8 **ppData, /* IN/OUT: Page content -area pointer */
58531 u8 *pCellptr, /* Pointer to cell-pointer area */
58532 int nCell, /* Number of cells to add to pPg */
58533 u8 **apCell, /* Array of cells */
58534 u16 *szCell /* Array of cell sizes */
58535 ){
58536 int i;
58537 u8 *aData = pPg->aData;
58538 u8 *pData = *ppData;
58539 const int bFreelist = aData[1] || aData[2];
58540 assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
58541 for(i=0; i<nCell; i++){
58542 int sz = szCell[i];
58543 int rc;
58544 u8 *pSlot;
58545 if( bFreelist==0 || (pSlot = pageFindSlot(pPg, sz, &rc, 0))==0 ){
58546 pData -= sz;
58547 if( pData<pBegin ) return 1;
58548 pSlot = pData;
58549 }
58550 memcpy(pSlot, apCell[i], sz);
58551 put2byte(pCellptr, (pSlot - aData));
58552 pCellptr += 2;
58553 }
58554 *ppData = pData;
58555 return 0;
58556 }
58557
58558 /*
58559 ** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
58560 ** contains the size in bytes of each such cell. This function adds the
58561 ** space associated with each cell in the array that is currently stored
58562 ** within the body of pPg to the pPg free-list. The cell-pointers and other
58563 ** fields of the page are not updated.
58564 **
58565 ** This function returns the total number of cells added to the free-list.
58566 */
58567 static int pageFreeArray(
58568 MemPage *pPg, /* Page to edit */
58569 int nCell, /* Cells to delete */
58570 u8 **apCell, /* Array of cells */
58571 u16 *szCell /* Array of cell sizes */
58572 ){
58573 u8 * const aData = pPg->aData;
58574 u8 * const pEnd = &aData[pPg->pBt->usableSize];
58575 u8 * const pStart = &aData[pPg->hdrOffset + 8 + pPg->childPtrSize];
58576 int nRet = 0;
58577 int i;
58578 u8 *pFree = 0;
58579 int szFree = 0;
58580
58581 for(i=0; i<nCell; i++){
58582 u8 *pCell = apCell[i];
58583 if( pCell>=pStart && pCell<pEnd ){
58584 int sz = szCell[i];
58585 if( pFree!=(pCell + sz) ){
58586 if( pFree ){
58587 assert( pFree>aData && (pFree - aData)<65536 );
58588 freeSpace(pPg, (u16)(pFree - aData), szFree);
58589 }
58590 pFree = pCell;
58591 szFree = sz;
58592 if( pFree+sz>pEnd ) return 0;
58593 }else{
58594 pFree = pCell;
58595 szFree += sz;
58596 }
58597 nRet++;
58598 }
58599 }
58600 if( pFree ){
58601 assert( pFree>aData && (pFree - aData)<65536 );
58602 freeSpace(pPg, (u16)(pFree - aData), szFree);
58603 }
58604 return nRet;
58605 }
58606
58607 /*
58608 ** The pPg->nFree field is invalid when this function returns. It is the
58609 ** responsibility of the caller to set it correctly.
58610 */
58611 static void editPage(
58612 MemPage *pPg, /* Edit this page */
58613 int iOld, /* Index of first cell currently on page */
58614 int iNew, /* Index of new first cell on page */
58615 int nNew, /* Final number of cells on page */
58616 u8 **apCell, /* Array of cells */
58617 u16 *szCell /* Array of cell sizes */
58618 ){
58619 u8 * const aData = pPg->aData;
58620 const int hdr = pPg->hdrOffset;
58621 u8 *pBegin = &pPg->aCellIdx[nNew * 2];
58622 int nCell = pPg->nCell; /* Cells stored on pPg */
58623 u8 *pData;
58624 u8 *pCellptr;
58625 int i;
58626 int iOldEnd = iOld + pPg->nCell + pPg->nOverflow;
58627 int iNewEnd = iNew + nNew;
58628
58629 #ifdef SQLITE_DEBUG
58630 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
58631 memcpy(pTmp, aData, pPg->pBt->usableSize);
58632 #endif
58633
58634 /* Remove cells from the start and end of the page */
58635 if( iOld<iNew ){
58636 int nShift = pageFreeArray(
58637 pPg, iNew-iOld, &apCell[iOld], &szCell[iOld]
58638 );
58639 memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
58640 nCell -= nShift;
58641 }
58642 if( iNewEnd < iOldEnd ){
58643 nCell -= pageFreeArray(
58644 pPg, iOldEnd-iNewEnd, &apCell[iNewEnd], &szCell[iNewEnd]
58645 );
58646 }
58647
58648 pData = &aData[get2byte(&aData[hdr+5])];
58649 if( pData<pBegin ) goto editpage_fail;
58650
58651 /* Add cells to the start of the page */
58652 if( iNew<iOld ){
58653 int nAdd = iOld-iNew;
58654 pCellptr = pPg->aCellIdx;
58655 memmove(&pCellptr[nAdd*2], pCellptr, nCell*2);
58656 if( pageInsertArray(
58657 pPg, pBegin, &pData, pCellptr,
58658 nAdd, &apCell[iNew], &szCell[iNew]
58659 ) ) goto editpage_fail;
58660 nCell += nAdd;
58661 }
58662
58663 /* Add any overflow cells */
58664 for(i=0; i<pPg->nOverflow; i++){
58665 int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
58666 if( iCell>=0 && iCell<nNew ){
58667 pCellptr = &pPg->aCellIdx[iCell * 2];
58668 memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
58669 nCell++;
58670 if( pageInsertArray(
58671 pPg, pBegin, &pData, pCellptr,
58672 1, &apCell[iCell + iNew], &szCell[iCell + iNew]
58673 ) ) goto editpage_fail;
58674 }
58675 }
58676
58677 /* Append cells to the end of the page */
58678 pCellptr = &pPg->aCellIdx[nCell*2];
58679 if( pageInsertArray(
58680 pPg, pBegin, &pData, pCellptr,
58681 nNew-nCell, &apCell[iNew+nCell], &szCell[iNew+nCell]
58682 ) ) goto editpage_fail;
58683
58684 pPg->nCell = nNew;
58685 pPg->nOverflow = 0;
58686
58687 put2byte(&aData[hdr+3], pPg->nCell);
58688 put2byte(&aData[hdr+5], pData - aData);
58689
58690 #ifdef SQLITE_DEBUG
58691 for(i=0; i<nNew && !CORRUPT_DB; i++){
58692 u8 *pCell = apCell[i+iNew];
58693 int iOff = get2byte(&pPg->aCellIdx[i*2]);
58694 if( pCell>=aData && pCell<&aData[pPg->pBt->usableSize] ){
58695 pCell = &pTmp[pCell - aData];
58696 }
58697 assert( 0==memcmp(pCell, &aData[iOff], szCell[i+iNew]) );
58698 }
58699 #endif
58700
58701 return;
58702 editpage_fail:
58703 /* Unable to edit this page. Rebuild it from scratch instead. */
58704 rebuildPage(pPg, nNew, &apCell[iNew], &szCell[iNew]);
58705 }
58706
58707 /*
58708 ** The following parameters determine how many adjacent pages get involved
58709 ** in a balancing operation. NN is the number of neighbors on either side
@@ -58771,12 +58267,11 @@
58771 u8 *pStop;
58772
58773 assert( sqlite3PagerIswriteable(pNew->pDbPage) );
58774 assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
58775 zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF);
58776 rebuildPage(pNew, 1, &pCell, &szCell);
58777 pNew->nFree = pBt->usableSize - pNew->cellOffset - 2 - szCell;
58778
58779 /* If this is an auto-vacuum database, update the pointer map
58780 ** with entries for the new page, and any pointer from the
58781 ** cell on the page to an overflow page. If either of these
58782 ** operations fails, the return code is set, but the contents
@@ -58991,26 +58486,21 @@
58991 int subtotal; /* Subtotal of bytes in cells on one page */
58992 int iSpace1 = 0; /* First unused byte of aSpace1[] */
58993 int iOvflSpace = 0; /* First unused byte of aOvflSpace[] */
58994 int szScratch; /* Size of scratch memory requested */
58995 MemPage *apOld[NB]; /* pPage and up to two siblings */
 
58996 MemPage *apNew[NB+2]; /* pPage and up to NB siblings after balancing */
58997 u8 *pRight; /* Location in parent of right-sibling pointer */
58998 u8 *apDiv[NB-1]; /* Divider cells in pParent */
58999 int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */
59000 int cntOld[NB+2]; /* Old index in aCell[] after i-th page */
59001 int szNew[NB+2]; /* Combined size of cells placed on i-th page */
59002 u8 **apCell = 0; /* All cells begin balanced */
59003 u16 *szCell; /* Local size of all cells in apCell[] */
59004 u8 *aSpace1; /* Space for copies of dividers cells */
59005 Pgno pgno; /* Temp var to store a page number in */
59006 u8 abDone[NB+2]; /* True after i'th new page is populated */
59007 Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */
59008 Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */
59009 u16 aPgFlags[NB+2]; /* flags field of new pages before shuffling */
59010
59011 memset(abDone, 0, sizeof(abDone));
59012 pBt = pParent->pBt;
59013 assert( sqlite3_mutex_held(pBt->mutex) );
59014 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
59015
59016 #if 0
@@ -59115,18 +58605,16 @@
59115 nMaxCells = (nMaxCells + 3)&~3;
59116
59117 /*
59118 ** Allocate space for memory structures
59119 */
 
59120 szScratch =
59121 nMaxCells*sizeof(u8*) /* apCell */
59122 + nMaxCells*sizeof(u16) /* szCell */
59123 + pBt->pageSize; /* aSpace1 */
59124
59125 /* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer
59126 ** that is more than 6 times the database page size. */
59127 assert( szScratch<=6*pBt->pageSize );
59128 apCell = sqlite3ScratchMalloc( szScratch );
59129 if( apCell==0 ){
59130 rc = SQLITE_NOMEM;
59131 goto balance_cleanup;
59132 }
@@ -59135,12 +58623,12 @@
59135 assert( EIGHT_BYTE_ALIGNMENT(aSpace1) );
59136
59137 /*
59138 ** Load pointers to all cells on sibling pages and the divider cells
59139 ** into the local apCell[] array. Make copies of the divider cells
59140 ** into space obtained from aSpace1[]. The divider cells have already
59141 ** been removed from pParent.
59142 **
59143 ** If the siblings are on leaf pages, then the child pointers of the
59144 ** divider cells are stripped from the cells before they are copied
59145 ** into aSpace1[]. In this way, all cells in apCell[] are without
59146 ** child pointers. If siblings are not leaves, then all cell in
@@ -59152,11 +58640,19 @@
59152 */
59153 leafCorrection = apOld[0]->leaf*4;
59154 leafData = apOld[0]->intKeyLeaf;
59155 for(i=0; i<nOld; i++){
59156 int limit;
59157 MemPage *pOld = apOld[i];
 
 
 
 
 
 
 
 
59158
59159 limit = pOld->nCell+pOld->nOverflow;
59160 if( pOld->nOverflow>0 ){
59161 for(j=0; j<limit; j++){
59162 assert( nCell<nMaxCells );
@@ -59173,11 +58669,10 @@
59173 apCell[nCell] = findCellv2(aData, maskPage, cellOffset, j);
59174 szCell[nCell] = cellSizePtr(pOld, apCell[nCell]);
59175 nCell++;
59176 }
59177 }
59178 cntOld[i] = nCell;
59179 if( i<nOld-1 && !leafData){
59180 u16 sz = (u16)szNew[i];
59181 u8 *pTemp;
59182 assert( nCell<nMaxCells );
59183 szCell[nCell] = sz;
@@ -59225,11 +58720,11 @@
59225 usableSpace = pBt->usableSize - 12 + leafCorrection;
59226 for(subtotal=k=i=0; i<nCell; i++){
59227 assert( i<nMaxCells );
59228 subtotal += szCell[i] + 2;
59229 if( subtotal > usableSpace ){
59230 szNew[k] = subtotal - szCell[i] - 2;
59231 cntNew[k] = i;
59232 if( leafData ){ i--; }
59233 subtotal = 0;
59234 k++;
59235 if( k>NB+1 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; }
@@ -59239,14 +58734,13 @@
59239 cntNew[k] = nCell;
59240 k++;
59241
59242 /*
59243 ** The packing computed by the previous block is biased toward the siblings
59244 ** on the left side (siblings with smaller keys). The left siblings are
59245 ** always nearly full, while the right-most sibling might be nearly empty.
59246 ** The next block of code attempts to adjust the packing of siblings to
59247 ** get a better balance.
59248 **
59249 ** This adjustment is more than an optimization. The packing above might
59250 ** be so out of balance as to be illegal. For example, the right-most
59251 ** sibling might be completely empty. This adjustment is not optional.
59252 */
@@ -59271,22 +58765,26 @@
59271 }
59272 szNew[i] = szRight;
59273 szNew[i-1] = szLeft;
59274 }
59275
59276 /* Sanity check: For a non-corrupt database file one of the follwing
59277 ** must be true:
59278 ** (1) We found one or more cells (cntNew[0])>0), or
59279 ** (2) pPage is a virtual root page. A virtual root page is when
59280 ** the real root page is page 1 and we are the only child of
59281 ** that page.
 
59282 */
59283 assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) || CORRUPT_DB);
59284 TRACE(("BALANCE: old: %d(nc=%d) %d(nc=%d) %d(nc=%d)\n",
59285 apOld[0]->pgno, apOld[0]->nCell,
59286 nOld>=2 ? apOld[1]->pgno : 0, nOld>=2 ? apOld[1]->nCell : 0,
59287 nOld>=3 ? apOld[2]->pgno : 0, nOld>=3 ? apOld[2]->nCell : 0
 
 
 
59288 ));
59289
59290 /*
59291 ** Allocate k new pages. Reuse old pages where possible.
59292 */
@@ -59305,14 +58803,12 @@
59305 if( rc ) goto balance_cleanup;
59306 }else{
59307 assert( i>0 );
59308 rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0);
59309 if( rc ) goto balance_cleanup;
59310 zeroPage(pNew, pageFlags);
59311 apNew[i] = pNew;
59312 nNew++;
59313 cntOld[i] = nCell;
59314
59315 /* Set the pointer-map entry for the new sibling page. */
59316 if( ISAUTOVACUUM ){
59317 ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc);
59318 if( rc!=SQLITE_OK ){
@@ -59319,248 +58815,140 @@
59319 goto balance_cleanup;
59320 }
59321 }
59322 }
59323 }
 
 
 
 
 
 
 
 
 
 
59324
59325 /*
59326 ** Reassign page numbers so that the new pages are in ascending order.
59327 ** This helps to keep entries in the disk file in order so that a scan
59328 ** of the table is closer to a linear scan through the file. That in turn
59329 ** helps the operating system to deliver pages from the disk more rapidly.
59330 **
59331 ** An O(n^2) insertion sort algorithm is used, but since n is never more
59332 ** than (NB+2) (a small constant), that should not be a problem.
59333 **
59334 ** When NB==3, this one optimization makes the database about 25% faster
59335 ** for large insertions and deletions.
59336 */
59337 for(i=0; i<nNew; i++){
59338 aPgOrder[i] = aPgno[i] = apNew[i]->pgno;
59339 aPgFlags[i] = apNew[i]->pDbPage->flags;
59340 for(j=0; j<i; j++){
59341 if( aPgno[j]==aPgno[i] ){
59342 /* This branch is taken if the set of sibling pages somehow contains
59343 ** duplicate entries. This can happen if the database is corrupt.
59344 ** It would be simpler to detect this as part of the loop below, but
59345 ** we do the detection here in order to avoid populating the pager
59346 ** cache with two separate objects associated with the same
59347 ** page number. */
59348 assert( CORRUPT_DB );
59349 rc = SQLITE_CORRUPT_BKPT;
59350 goto balance_cleanup;
59351 }
59352 }
59353 }
59354 for(i=0; i<nNew; i++){
59355 int iBest = 0; /* aPgno[] index of page number to use */
59356 for(j=1; j<nNew; j++){
59357 if( aPgOrder[j]<aPgOrder[iBest] ) iBest = j;
59358 }
59359 pgno = aPgOrder[iBest];
59360 aPgOrder[iBest] = 0xffffffff;
59361 if( iBest!=i ){
59362 if( iBest>i ){
59363 sqlite3PagerRekey(apNew[iBest]->pDbPage, pBt->nPage+iBest+1, 0);
59364 }
59365 sqlite3PagerRekey(apNew[i]->pDbPage, pgno, aPgFlags[iBest]);
59366 apNew[i]->pgno = pgno;
59367 }
59368 }
59369
59370 TRACE(("BALANCE: new: %d(%d nc=%d) %d(%d nc=%d) %d(%d nc=%d) "
59371 "%d(%d nc=%d) %d(%d nc=%d)\n",
59372 apNew[0]->pgno, szNew[0], cntNew[0],
59373 nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0,
59374 nNew>=2 ? cntNew[1] - cntNew[0] - !leafData : 0,
59375 nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0,
59376 nNew>=3 ? cntNew[2] - cntNew[1] - !leafData : 0,
59377 nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0,
59378 nNew>=4 ? cntNew[3] - cntNew[2] - !leafData : 0,
59379 nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0,
59380 nNew>=5 ? cntNew[4] - cntNew[3] - !leafData : 0
59381 ));
59382
59383 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
59384 put4byte(pRight, apNew[nNew-1]->pgno);
59385
59386 /* If the sibling pages are not leaves, ensure that the right-child pointer
59387 ** of the right-most new sibling page is set to the value that was
59388 ** originally in the same field of the right-most old sibling page. */
59389 if( (pageFlags & PTF_LEAF)==0 && nOld!=nNew ){
59390 MemPage *pOld = (nNew>nOld ? apNew : apOld)[nOld-1];
59391 memcpy(&apNew[nNew-1]->aData[8], &pOld->aData[8], 4);
59392 }
59393
59394 /* Make any required updates to pointer map entries associated with
59395 ** cells stored on sibling pages following the balance operation. Pointer
59396 ** map entries associated with divider cells are set by the insertCell()
59397 ** routine. The associated pointer map entries are:
59398 **
59399 ** a) if the cell contains a reference to an overflow chain, the
59400 ** entry associated with the first page in the overflow chain, and
59401 **
59402 ** b) if the sibling pages are not leaves, the child page associated
59403 ** with the cell.
59404 **
59405 ** If the sibling pages are not leaves, then the pointer map entry
59406 ** associated with the right-child of each sibling may also need to be
59407 ** updated. This happens below, after the sibling pages have been
59408 ** populated, not here.
59409 */
59410 if( ISAUTOVACUUM ){
59411 MemPage *pNew = apNew[0];
59412 u8 *aOld = pNew->aData;
59413 int cntOldNext = pNew->nCell + pNew->nOverflow;
59414 int usableSize = pBt->usableSize;
59415 int iNew = 0;
59416 int iOld = 0;
59417
59418 for(i=0; i<nCell; i++){
59419 u8 *pCell = apCell[i];
59420 if( i==cntOldNext ){
59421 MemPage *pOld = (++iOld)<nNew ? apNew[iOld] : apOld[iOld];
59422 cntOldNext += pOld->nCell + pOld->nOverflow + !leafData;
59423 aOld = pOld->aData;
59424 }
59425 if( i==cntNew[iNew] ){
59426 pNew = apNew[++iNew];
59427 if( !leafData ) continue;
59428 }
59429
59430 /* Cell pCell is destined for new sibling page pNew. Originally, it
59431 ** was either part of sibling page iOld (possibly an overflow cell),
59432 ** or else the divider cell to the left of sibling page iOld. So,
59433 ** if sibling page iOld had the same page number as pNew, and if
59434 ** pCell really was a part of sibling page iOld (not a divider or
59435 ** overflow cell), we can skip updating the pointer map entries. */
59436 if( pNew->pgno!=aPgno[iOld] || pCell<aOld || pCell>=&aOld[usableSize] ){
59437 if( !leafCorrection ){
59438 ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
59439 }
59440 if( szCell[i]>pNew->minLocal ){
59441 ptrmapPutOvflPtr(pNew, pCell, &rc);
59442 }
59443 }
59444 }
59445 }
59446
59447 /* Insert new divider cells into pParent. */
59448 for(i=0; i<nNew-1; i++){
59449 u8 *pCell;
59450 u8 *pTemp;
59451 int sz;
59452 MemPage *pNew = apNew[i];
 
 
 
 
 
 
59453 j = cntNew[i];
59454
59455 assert( j<nMaxCells );
59456 pCell = apCell[j];
59457 sz = szCell[j] + leafCorrection;
59458 pTemp = &aOvflSpace[iOvflSpace];
59459 if( !pNew->leaf ){
59460 memcpy(&pNew->aData[8], pCell, 4);
59461 }else if( leafData ){
59462 /* If the tree is a leaf-data tree, and the siblings are leaves,
59463 ** then there is no divider cell in apCell[]. Instead, the divider
59464 ** cell consists of the integer key for the right-most cell of
59465 ** the sibling-page assembled above only.
59466 */
59467 CellInfo info;
59468 j--;
59469 btreeParseCellPtr(pNew, apCell[j], &info);
59470 pCell = pTemp;
59471 sz = 4 + putVarint(&pCell[4], info.nKey);
59472 pTemp = 0;
59473 }else{
59474 pCell -= 4;
59475 /* Obscure case for non-leaf-data trees: If the cell at pCell was
59476 ** previously stored on a leaf node, and its reported size was 4
59477 ** bytes, then it may actually be smaller than this
59478 ** (see btreeParseCellPtr(), 4 bytes is the minimum size of
59479 ** any cell). But it is important to pass the correct size to
59480 ** insertCell(), so reparse the cell now.
59481 **
59482 ** Note that this can never happen in an SQLite data file, as all
59483 ** cells are at least 4 bytes. It only happens in b-trees used
59484 ** to evaluate "IN (SELECT ...)" and similar clauses.
59485 */
59486 if( szCell[j]==4 ){
59487 assert(leafCorrection==4);
59488 sz = cellSizePtr(pParent, pCell);
59489 }
59490 }
59491 iOvflSpace += sz;
59492 assert( sz<=pBt->maxLocal+23 );
59493 assert( iOvflSpace <= (int)pBt->pageSize );
59494 insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc);
59495 if( rc!=SQLITE_OK ) goto balance_cleanup;
59496 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
59497 }
59498
59499 /* Now update the actual sibling pages. The order in which they are updated
59500 ** is important, as this code needs to avoid disrupting any page from which
59501 ** cells may still to be read. In practice, this means:
59502 **
59503 ** (1) If cells are moving left (from apNew[iPg] to apNew[iPg-1])
59504 ** then it is not safe to update page apNew[iPg] until after
59505 ** the left-hand sibling apNew[iPg-1] has been updated.
59506 **
59507 ** (2) If cells are moving right (from apNew[iPg] to apNew[iPg+1])
59508 ** then it is not safe to update page apNew[iPg] until after
59509 ** the right-hand sibling apNew[iPg+1] has been updated.
59510 **
59511 ** If neither of the above apply, the page is safe to update.
59512 **
59513 ** The iPg value in the following loop starts at nNew-1 goes down
59514 ** to 0, then back up to nNew-1 again, thus making two passes over
59515 ** the pages. On the initial downward pass, only condition (1) above
59516 ** needs to be tested because (2) will always be true from the previous
59517 ** step. On the upward pass, both conditions are always true, so the
59518 ** upwards pass simply processes pages that were missed on the downward
59519 ** pass.
59520 */
59521 for(i=1-nNew; i<nNew; i++){
59522 int iPg = i<0 ? -i : i;
59523 assert( iPg>=0 && iPg<nNew );
59524 if( abDone[iPg] ) continue; /* Skip pages already processed */
59525 if( i>=0 /* On the upwards pass, or... */
59526 || cntOld[iPg-1]>=cntNew[iPg-1] /* Condition (1) is true */
59527 ){
59528 int iNew;
59529 int iOld;
59530 int nNewCell;
59531
59532 /* Verify condition (1): If cells are moving left, update iPg
59533 ** only after iPg-1 has already been updated. */
59534 assert( iPg==0 || cntOld[iPg-1]>=cntNew[iPg-1] || abDone[iPg-1] );
59535
59536 /* Verify condition (2): If cells are moving right, update iPg
59537 ** only after iPg+1 has already been updated. */
59538 assert( cntNew[iPg]>=cntOld[iPg] || abDone[iPg+1] );
59539
59540 if( iPg==0 ){
59541 iNew = iOld = 0;
59542 nNewCell = cntNew[0];
59543 }else{
59544 iOld = iPg<nOld ? (cntOld[iPg-1] + !leafData) : nCell;
59545 iNew = cntNew[iPg-1] + !leafData;
59546 nNewCell = cntNew[iPg] - iNew;
59547 }
59548
59549 editPage(apNew[iPg], iOld, iNew, nNewCell, apCell, szCell);
59550 abDone[iPg]++;
59551 apNew[iPg]->nFree = usableSpace-szNew[iPg];
59552 assert( apNew[iPg]->nOverflow==0 );
59553 assert( apNew[iPg]->nCell==nNewCell );
59554 }
59555 }
59556
59557 /* All pages have been processed exactly once */
59558 assert( memcmp(abDone, "\01\01\01\01\01", nNew)==0 );
59559
59560 assert( nOld>0 );
59561 assert( nNew>0 );
 
 
 
 
59562
59563 if( isRoot && pParent->nCell==0 && pParent->hdrOffset<=apNew[0]->nFree ){
59564 /* The root page of the b-tree now contains no cells. The only sibling
59565 ** page is the right-child of the parent. Copy the contents of the
59566 ** child page into the parent, decreasing the overall height of the
@@ -59569,54 +58957,130 @@
59569 **
59570 ** If this is an auto-vacuum database, the call to copyNodeContent()
59571 ** sets all pointer-map entries corresponding to database image pages
59572 ** for which the pointer is stored within the content being copied.
59573 **
59574 ** It is critical that the child page be defragmented before being
59575 ** copied into the parent, because if the parent is page 1 then it will
59576 ** by smaller than the child due to the database header, and so all the
59577 ** free space needs to be up front.
59578 */
59579 assert( nNew==1 );
59580 rc = defragmentPage(apNew[0]);
59581 testcase( rc!=SQLITE_OK );
59582 assert( apNew[0]->nFree ==
59583 (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
59584 || rc!=SQLITE_OK
59585 );
59586 copyNodeContent(apNew[0], pParent, &rc);
59587 freePage(apNew[0], &rc);
59588 }else if( ISAUTOVACUUM && !leafCorrection ){
59589 /* Fix the pointer map entries associated with the right-child of each
59590 ** sibling page. All other pointer map entries have already been taken
59591 ** care of. */
59592 for(i=0; i<nNew; i++){
59593 u32 key = get4byte(&apNew[i]->aData[8]);
59594 ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc);
59595 }
59596 }
59597
59598 assert( pParent->isInit );
59599 TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n",
59600 nOld, nNew, nCell));
59601
59602 /* Free any old pages that were not reused as new pages.
59603 */
59604 for(i=nNew; i<nOld; i++){
59605 freePage(apOld[i], &rc);
59606 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59607
59608 #if 0
59609 if( ISAUTOVACUUM && rc==SQLITE_OK && apNew[0]->isInit ){
59610 /* The ptrmapCheckPages() contains assert() statements that verify that
59611 ** all pointer map pages are set correctly. This is helpful while
59612 ** debugging. This is usually disabled because a corrupt database may
59613 ** cause an assert() statement to fail. */
59614 ptrmapCheckPages(apNew, nNew);
59615 ptrmapCheckPages(&pParent, 1);
 
59616 }
59617 #endif
 
 
 
59618
59619 /*
59620 ** Cleanup before returning.
59621 */
59622 balance_cleanup:
@@ -61438,15 +60902,10 @@
61438 */
61439 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){
61440 return (p->pBt->btsFlags & BTS_READ_ONLY)!=0;
61441 }
61442
61443 /*
61444 ** Return the size of the header added to each page by this module.
61445 */
61446 SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); }
61447
61448 /************** End of btree.c ***********************************************/
61449 /************** Begin file backup.c ******************************************/
61450 /*
61451 ** 2009 January 28
61452 **
@@ -61583,17 +61042,10 @@
61583 sqlite3* pSrcDb, /* Database connection to read from */
61584 const char *zSrcDb /* Name of database within pSrcDb */
61585 ){
61586 sqlite3_backup *p; /* Value to return */
61587
61588 #ifdef SQLITE_ENABLE_API_ARMOR
61589 if( !sqlite3SafetyCheckOk(pSrcDb)||!sqlite3SafetyCheckOk(pDestDb) ){
61590 (void)SQLITE_MISUSE_BKPT;
61591 return 0;
61592 }
61593 #endif
61594
61595 /* Lock the source database handle. The destination database
61596 ** handle is not locked in this routine, but it is locked in
61597 ** sqlite3_backup_step(). The user is required to ensure that no
61598 ** other thread accesses the destination handle for the duration
61599 ** of the backup operation. Any attempt to use the destination
@@ -61786,13 +61238,10 @@
61786 int rc;
61787 int destMode; /* Destination journal mode */
61788 int pgszSrc = 0; /* Source page size */
61789 int pgszDest = 0; /* Destination page size */
61790
61791 #ifdef SQLITE_ENABLE_API_ARMOR
61792 if( p==0 ) return SQLITE_MISUSE_BKPT;
61793 #endif
61794 sqlite3_mutex_enter(p->pSrcDb->mutex);
61795 sqlite3BtreeEnter(p->pSrc);
61796 if( p->pDestDb ){
61797 sqlite3_mutex_enter(p->pDestDb->mutex);
61798 }
@@ -62078,30 +61527,18 @@
62078 /*
62079 ** Return the number of pages still to be backed up as of the most recent
62080 ** call to sqlite3_backup_step().
62081 */
62082 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p){
62083 #ifdef SQLITE_ENABLE_API_ARMOR
62084 if( p==0 ){
62085 (void)SQLITE_MISUSE_BKPT;
62086 return 0;
62087 }
62088 #endif
62089 return p->nRemaining;
62090 }
62091
62092 /*
62093 ** Return the total number of pages in the source database as of the most
62094 ** recent call to sqlite3_backup_step().
62095 */
62096 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p){
62097 #ifdef SQLITE_ENABLE_API_ARMOR
62098 if( p==0 ){
62099 (void)SQLITE_MISUSE_BKPT;
62100 return 0;
62101 }
62102 #endif
62103 return p->nPagecount;
62104 }
62105
62106 /*
62107 ** This function is called after the contents of page iPage of the
@@ -64388,38 +63825,10 @@
64388 }
64389 p->nOp += nOp;
64390 }
64391 return addr;
64392 }
64393
64394 #if defined(SQLITE_ENABLE_STMT_SCANSTATUS)
64395 /*
64396 ** Add an entry to the array of counters managed by sqlite3_stmt_scanstatus().
64397 */
64398 SQLITE_PRIVATE void sqlite3VdbeScanStatus(
64399 Vdbe *p, /* VM to add scanstatus() to */
64400 int addrExplain, /* Address of OP_Explain (or 0) */
64401 int addrLoop, /* Address of loop counter */
64402 int addrVisit, /* Address of rows visited counter */
64403 LogEst nEst, /* Estimated number of output rows */
64404 const char *zName /* Name of table or index being scanned */
64405 ){
64406 int nByte = (p->nScan+1) * sizeof(ScanStatus);
64407 ScanStatus *aNew;
64408 aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
64409 if( aNew ){
64410 ScanStatus *pNew = &aNew[p->nScan++];
64411 pNew->addrExplain = addrExplain;
64412 pNew->addrLoop = addrLoop;
64413 pNew->addrVisit = addrVisit;
64414 pNew->nEst = nEst;
64415 pNew->zName = sqlite3DbStrDup(p->db, zName);
64416 p->aScan = aNew;
64417 }
64418 }
64419 #endif
64420
64421
64422 /*
64423 ** Change the value of the P1 operand for a specific instruction.
64424 ** This routine is useful when a large program is loaded from a
64425 ** static array using sqlite3VdbeAddOpList but we want to make a
@@ -65515,13 +64924,10 @@
65515 p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte);
65516 p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte);
65517 p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*),
65518 &zCsr, zEnd, &nByte);
65519 p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, &zCsr, zEnd, &nByte);
65520 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
65521 p->anExec = allocSpace(p->anExec, p->nOp*sizeof(i64), &zCsr, zEnd, &nByte);
65522 #endif
65523 if( nByte ){
65524 p->pFree = sqlite3DbMallocZero(db, nByte);
65525 }
65526 zCsr = p->pFree;
65527 zEnd = &zCsr[nByte];
@@ -65585,13 +64991,10 @@
65585 ** is used, for example, when a trigger sub-program is halted to restore
65586 ** control to the main program.
65587 */
65588 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
65589 Vdbe *v = pFrame->v;
65590 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
65591 v->anExec = pFrame->anExec;
65592 #endif
65593 v->aOnceFlag = pFrame->aOnceFlag;
65594 v->nOnceFlag = pFrame->nOnceFlag;
65595 v->aOp = pFrame->aOp;
65596 v->nOp = pFrame->nOp;
65597 v->aMem = pFrame->aMem;
@@ -65598,11 +65001,10 @@
65598 v->nMem = pFrame->nMem;
65599 v->apCsr = pFrame->apCsr;
65600 v->nCursor = pFrame->nCursor;
65601 v->db->lastRowid = pFrame->lastRowid;
65602 v->nChange = pFrame->nChange;
65603 v->db->nChange = pFrame->nDbChange;
65604 return pFrame->pc;
65605 }
65606
65607 /*
65608 ** Close all cursors.
@@ -66166,11 +65568,10 @@
66166 ** so, abort any other statements this handle currently has active.
66167 */
66168 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
66169 sqlite3CloseSavepoints(db);
66170 db->autoCommit = 1;
66171 p->nChange = 0;
66172 }
66173 }
66174 }
66175
66176 /* Check for immediate foreign key violations. */
@@ -66207,20 +65608,18 @@
66207 sqlite3VdbeLeave(p);
66208 return SQLITE_BUSY;
66209 }else if( rc!=SQLITE_OK ){
66210 p->rc = rc;
66211 sqlite3RollbackAll(db, SQLITE_OK);
66212 p->nChange = 0;
66213 }else{
66214 db->nDeferredCons = 0;
66215 db->nDeferredImmCons = 0;
66216 db->flags &= ~SQLITE_DeferFKs;
66217 sqlite3CommitInternalChanges(db);
66218 }
66219 }else{
66220 sqlite3RollbackAll(db, SQLITE_OK);
66221 p->nChange = 0;
66222 }
66223 db->nStatement = 0;
66224 }else if( eStatementOp==0 ){
66225 if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){
66226 eStatementOp = SAVEPOINT_RELEASE;
@@ -66228,11 +65627,10 @@
66228 eStatementOp = SAVEPOINT_ROLLBACK;
66229 }else{
66230 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
66231 sqlite3CloseSavepoints(db);
66232 db->autoCommit = 1;
66233 p->nChange = 0;
66234 }
66235 }
66236
66237 /* If eStatementOp is non-zero, then a statement transaction needs to
66238 ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
@@ -66249,11 +65647,10 @@
66249 p->zErrMsg = 0;
66250 }
66251 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
66252 sqlite3CloseSavepoints(db);
66253 db->autoCommit = 1;
66254 p->nChange = 0;
66255 }
66256 }
66257
66258 /* If this was an INSERT, UPDATE or DELETE and no statement transaction
66259 ** has been rolled back, update the database connection change-counter.
@@ -66511,16 +65908,10 @@
66511 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
66512 vdbeFreeOpArray(db, p->aOp, p->nOp);
66513 sqlite3DbFree(db, p->aColName);
66514 sqlite3DbFree(db, p->zSql);
66515 sqlite3DbFree(db, p->pFree);
66516 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
66517 for(i=0; i<p->nScan; i++){
66518 sqlite3DbFree(db, p->aScan[i].zName);
66519 }
66520 sqlite3DbFree(db, p->aScan);
66521 #endif
66522 }
66523
66524 /*
66525 ** Delete an entire VDBE.
66526 */
@@ -68884,23 +68275,15 @@
68884 sqlite3_stmt *pStmt,
68885 int N,
68886 const void *(*xFunc)(Mem*),
68887 int useType
68888 ){
68889 const void *ret;
68890 Vdbe *p;
68891 int n;
68892 sqlite3 *db;
68893 #ifdef SQLITE_ENABLE_API_ARMOR
68894 if( pStmt==0 ){
68895 (void)SQLITE_MISUSE_BKPT;
68896 return 0;
68897 }
68898 #endif
68899 ret = 0;
68900 p = (Vdbe *)pStmt;
68901 db = p->db;
68902 assert( db!=0 );
68903 n = sqlite3_column_count(pStmt);
68904 if( N<n && N>=0 ){
68905 N += useType*n;
68906 sqlite3_mutex_enter(db->mutex);
@@ -69361,16 +68744,10 @@
69361 ** prepared statement for the database connection. Return NULL if there
69362 ** are no more.
69363 */
69364 SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){
69365 sqlite3_stmt *pNext;
69366 #ifdef SQLITE_ENABLE_API_ARMOR
69367 if( !sqlite3SafetyCheckOk(pDb) ){
69368 (void)SQLITE_MISUSE_BKPT;
69369 return 0;
69370 }
69371 #endif
69372 sqlite3_mutex_enter(pDb->mutex);
69373 if( pStmt==0 ){
69374 pNext = (sqlite3_stmt*)pDb->pVdbe;
69375 }else{
69376 pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pNext;
@@ -69382,91 +68759,15 @@
69382 /*
69383 ** Return the value of a status counter for a prepared statement
69384 */
69385 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){
69386 Vdbe *pVdbe = (Vdbe*)pStmt;
69387 u32 v;
69388 #ifdef SQLITE_ENABLE_API_ARMOR
69389 if( !pStmt ){
69390 (void)SQLITE_MISUSE_BKPT;
69391 return 0;
69392 }
69393 #endif
69394 v = pVdbe->aCounter[op];
69395 if( resetFlag ) pVdbe->aCounter[op] = 0;
69396 return (int)v;
69397 }
69398
69399 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
69400 /*
69401 ** Return status data for a single loop within query pStmt.
69402 */
69403 SQLITE_API int sqlite3_stmt_scanstatus(
69404 sqlite3_stmt *pStmt, /* Prepared statement being queried */
69405 int idx, /* Index of loop to report on */
69406 int iScanStatusOp, /* Which metric to return */
69407 void *pOut /* OUT: Write the answer here */
69408 ){
69409 Vdbe *p = (Vdbe*)pStmt;
69410 ScanStatus *pScan;
69411 if( idx<0 || idx>=p->nScan ) return 1;
69412 pScan = &p->aScan[idx];
69413 switch( iScanStatusOp ){
69414 case SQLITE_SCANSTAT_NLOOP: {
69415 *(sqlite3_int64*)pOut = p->anExec[pScan->addrLoop];
69416 break;
69417 }
69418 case SQLITE_SCANSTAT_NVISIT: {
69419 *(sqlite3_int64*)pOut = p->anExec[pScan->addrVisit];
69420 break;
69421 }
69422 case SQLITE_SCANSTAT_EST: {
69423 double r = 1.0;
69424 LogEst x = pScan->nEst;
69425 while( x<100 ){
69426 x += 10;
69427 r *= 0.5;
69428 }
69429 *(double*)pOut = r*sqlite3LogEstToInt(x);
69430 break;
69431 }
69432 case SQLITE_SCANSTAT_NAME: {
69433 *(const char**)pOut = pScan->zName;
69434 break;
69435 }
69436 case SQLITE_SCANSTAT_EXPLAIN: {
69437 if( pScan->addrExplain ){
69438 *(const char**)pOut = p->aOp[ pScan->addrExplain ].p4.z;
69439 }else{
69440 *(const char**)pOut = 0;
69441 }
69442 break;
69443 }
69444 case SQLITE_SCANSTAT_SELECTID: {
69445 if( pScan->addrExplain ){
69446 *(int*)pOut = p->aOp[ pScan->addrExplain ].p1;
69447 }else{
69448 *(int*)pOut = -1;
69449 }
69450 break;
69451 }
69452 default: {
69453 return 1;
69454 }
69455 }
69456 return 0;
69457 }
69458
69459 /*
69460 ** Zero all counters associated with the sqlite3_stmt_scanstatus() data.
69461 */
69462 SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){
69463 Vdbe *p = (Vdbe*)pStmt;
69464 memset(p->anExec, 0, p->nOp * sizeof(i64));
69465 }
69466 #endif /* SQLITE_ENABLE_STMT_SCANSTATUS */
69467
69468 /************** End of vdbeapi.c *********************************************/
69469 /************** Begin file vdbetrace.c ***************************************/
69470 /*
69471 ** 2009 November 25
69472 **
@@ -70348,13 +69649,10 @@
70348 #ifdef VDBE_PROFILE
70349 start = sqlite3Hwtime();
70350 #endif
70351 nVmStep++;
70352 pOp = &aOp[pc];
70353 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
70354 if( p->anExec ) p->anExec[pc]++;
70355 #endif
70356
70357 /* Only allow tracing if SQLITE_DEBUG is defined.
70358 */
70359 #ifdef SQLITE_DEBUG
70360 if( db->flags & SQLITE_VdbeTrace ){
@@ -72570,12 +71868,14 @@
72570 int isSchemaChange;
72571 iSavepoint = db->nSavepoint - iSavepoint - 1;
72572 if( p1==SAVEPOINT_ROLLBACK ){
72573 isSchemaChange = (db->flags & SQLITE_InternChanges)!=0;
72574 for(ii=0; ii<db->nDb; ii++){
72575 sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT,
 
72576 isSchemaChange==0);
 
72577 }
72578 }else{
72579 isSchemaChange = 0;
72580 }
72581 for(ii=0; ii<db->nDb; ii++){
@@ -73543,15 +72843,14 @@
73543 }
73544 pIdxKey = &r;
73545 }else{
73546 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
73547 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
73548 );
73549 if( pIdxKey==0 ) goto no_mem;
73550 assert( pIn3->flags & MEM_Blob );
73551 /* assert( (pIn3->flags & MEM_Zero)==0 ); // zeroblobs already expanded */
73552 ExpandBlob(pIn3);
73553 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
73554 }
73555 pIdxKey->default_rc = 0;
73556 if( pOp->opcode==OP_NoConflict ){
73557 /* For the OP_NoConflict opcode, take the jump if any of the
@@ -74147,10 +73446,14 @@
74147 #endif /* SQLITE_OMIT_VIRTUALTABLE */
74148 }else{
74149 assert( pC->pCursor!=0 );
74150 rc = sqlite3VdbeCursorRestore(pC);
74151 if( rc ) goto abort_due_to_error;
 
 
 
 
74152 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
74153 assert( rc==SQLITE_OK ); /* Always so because of CursorRestore() above */
74154 }
74155 pOut->u.i = v;
74156 break;
@@ -74237,13 +73540,13 @@
74237 }
74238 /* Opcode: Rewind P1 P2 * * *
74239 **
74240 ** The next use of the Rowid or Column or Next instruction for P1
74241 ** will refer to the first entry in the database table or index.
74242 ** If the table or index is empty, jump immediately to P2.
74243 ** If the table or index is not empty, fall through to the following
74244 ** instruction.
74245 **
74246 ** This opcode leaves the cursor configured to move in forward order,
74247 ** from the beginning toward the end. In other words, the cursor is
74248 ** configured to use Next, not Prev.
74249 */
@@ -75155,13 +74458,10 @@
75155 pFrame->aOp = p->aOp;
75156 pFrame->nOp = p->nOp;
75157 pFrame->token = pProgram->token;
75158 pFrame->aOnceFlag = p->aOnceFlag;
75159 pFrame->nOnceFlag = p->nOnceFlag;
75160 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
75161 pFrame->anExec = p->anExec;
75162 #endif
75163
75164 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
75165 for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
75166 pMem->flags = MEM_Undefined;
75167 pMem->db = db;
@@ -75175,11 +74475,10 @@
75175
75176 p->nFrame++;
75177 pFrame->pParent = p->pFrame;
75178 pFrame->lastRowid = lastRowid;
75179 pFrame->nChange = p->nChange;
75180 pFrame->nDbChange = p->db->nChange;
75181 p->nChange = 0;
75182 p->pFrame = pFrame;
75183 p->aMem = aMem = &VdbeFrameMem(pFrame)[-1];
75184 p->nMem = pFrame->nChildMem;
75185 p->nCursor = (u16)pFrame->nChildCsr;
@@ -75186,13 +74485,10 @@
75186 p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
75187 p->aOp = aOp = pProgram->aOp;
75188 p->nOp = pProgram->nOp;
75189 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
75190 p->nOnceFlag = pProgram->nOnce;
75191 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
75192 p->anExec = 0;
75193 #endif
75194 pc = -1;
75195 memset(p->aOnceFlag, 0, p->nOnceFlag);
75196
75197 break;
75198 }
@@ -76377,15 +75673,10 @@
76377 char *zErr = 0;
76378 Table *pTab;
76379 Parse *pParse = 0;
76380 Incrblob *pBlob = 0;
76381
76382 #ifdef SQLITE_ENABLE_API_ARMOR
76383 if( !sqlite3SafetyCheckOk(db) || ppBlob==0 || zTable==0 ){
76384 return SQLITE_MISUSE_BKPT;
76385 }
76386 #endif
76387 flags = !!flags; /* flags = (flags ? 1 : 0); */
76388 *ppBlob = 0;
76389
76390 sqlite3_mutex_enter(db->mutex);
76391
@@ -76600,10 +75891,11 @@
76600 v = (Vdbe*)p->pStmt;
76601
76602 if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){
76603 /* Request is out of range. Return a transient error. */
76604 rc = SQLITE_ERROR;
 
76605 }else if( v==0 ){
76606 /* If there is no statement handle, then the blob-handle has
76607 ** already been invalidated. Return SQLITE_ABORT in this case.
76608 */
76609 rc = SQLITE_ABORT;
@@ -76617,14 +75909,14 @@
76617 sqlite3BtreeLeaveCursor(p->pCsr);
76618 if( rc==SQLITE_ABORT ){
76619 sqlite3VdbeFinalize(v);
76620 p->pStmt = 0;
76621 }else{
 
76622 v->rc = rc;
76623 }
76624 }
76625 sqlite3Error(db, rc);
76626 rc = sqlite3ApiExit(db, rc);
76627 sqlite3_mutex_leave(db->mutex);
76628 return rc;
76629 }
76630
@@ -76797,11 +76089,11 @@
76797 ** itself.
76798 **
76799 ** The sorter is running in multi-threaded mode if (a) the library was built
76800 ** with pre-processor symbol SQLITE_MAX_WORKER_THREADS set to a value greater
76801 ** than zero, and (b) worker threads have been enabled at runtime by calling
76802 ** "PRAGMA threads=N" with some value of N greater than 0.
76803 **
76804 ** When Rewind() is called, any data remaining in memory is flushed to a
76805 ** final PMA. So at this point the data is stored in some number of sorted
76806 ** PMAs within temporary files on disk.
76807 **
@@ -77542,13 +76834,15 @@
77542 pSorter->mnPmaSize = SORTER_MIN_WORKING * pgsz;
77543 mxCache = db->aDb[0].pSchema->cache_size;
77544 if( mxCache<SORTER_MIN_WORKING ) mxCache = SORTER_MIN_WORKING;
77545 pSorter->mxPmaSize = mxCache * pgsz;
77546
77547 /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
77548 ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
77549 ** large heap allocations.
 
 
77550 */
77551 if( sqlite3GlobalConfig.pScratch==0 ){
77552 assert( pSorter->iMemory==0 );
77553 pSorter->nMemory = pgsz;
77554 pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
@@ -79916,19 +79210,19 @@
79916 **
79917 ** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..)
79918 ** is a helper function - a callback for the tree walker.
79919 */
79920 static int incrAggDepth(Walker *pWalker, Expr *pExpr){
79921 if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.n;
79922 return WRC_Continue;
79923 }
79924 static void incrAggFunctionDepth(Expr *pExpr, int N){
79925 if( N>0 ){
79926 Walker w;
79927 memset(&w, 0, sizeof(w));
79928 w.xExprCallback = incrAggDepth;
79929 w.u.n = N;
79930 sqlite3WalkExpr(&w, pExpr);
79931 }
79932 }
79933
79934 /*
@@ -80472,11 +79766,11 @@
80472 double r = -1.0;
80473 if( p->op!=TK_FLOAT ) return -1;
80474 sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
80475 assert( r>=0.0 );
80476 if( r>1.0 ) return -1;
80477 return (int)(r*134217728.0);
80478 }
80479
80480 /*
80481 ** This routine is callback for sqlite3WalkExpr().
80482 **
@@ -80604,11 +79898,11 @@
80604 ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand for
80605 ** likelihood(X,0.9375).
80606 ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent to
80607 ** likelihood(X,0.9375). */
80608 /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
80609 pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120;
80610 }
80611 }
80612 #ifndef SQLITE_OMIT_AUTHORIZATION
80613 auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
80614 if( auth!=SQLITE_OK ){
@@ -82561,79 +81855,69 @@
82561 sqlite3DbFree(db, pList->a);
82562 sqlite3DbFree(db, pList);
82563 }
82564
82565 /*
82566 ** These routines are Walker callbacks used to check expressions to
82567 ** see if they are "constant" for some definition of constant. The
82568 ** Walker.eCode value determines the type of "constant" we are looking
82569 ** for.
82570 **
82571 ** These callback routines are used to implement the following:
82572 **
82573 ** sqlite3ExprIsConstant() pWalker->eCode==1
82574 ** sqlite3ExprIsConstantNotJoin() pWalker->eCode==2
82575 ** sqlite3ExprRefOneTableOnly() pWalker->eCode==3
82576 ** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5
82577 **
82578 ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
82579 ** is found to not be a constant.
82580 **
82581 ** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions
82582 ** in a CREATE TABLE statement. The Walker.eCode value is 5 when parsing
82583 ** an existing schema and 4 when processing a new statement. A bound
82584 ** parameter raises an error for new statements, but is silently converted
82585 ** to NULL for existing schemas. This allows sqlite_master tables that
82586 ** contain a bound parameter because they were generated by older versions
82587 ** of SQLite to be parsed by newer versions of SQLite without raising a
82588 ** malformed schema error.
82589 */
82590 static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
82591
82592 /* If pWalker->eCode is 2 then any term of the expression that comes from
82593 ** the ON or USING clauses of a left join disqualifies the expression
82594 ** from being considered constant. */
82595 if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
82596 pWalker->eCode = 0;
82597 return WRC_Abort;
82598 }
82599
82600 switch( pExpr->op ){
82601 /* Consider functions to be constant if all their arguments are constant
82602 ** and either pWalker->eCode==4 or 5 or the function has the
82603 ** SQLITE_FUNC_CONST flag. */
82604 case TK_FUNCTION:
82605 if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_Constant) ){
82606 return WRC_Continue;
82607 }else{
82608 pWalker->eCode = 0;
82609 return WRC_Abort;
82610 }
 
82611 case TK_ID:
82612 case TK_COLUMN:
82613 case TK_AGG_FUNCTION:
82614 case TK_AGG_COLUMN:
82615 testcase( pExpr->op==TK_ID );
82616 testcase( pExpr->op==TK_COLUMN );
82617 testcase( pExpr->op==TK_AGG_FUNCTION );
82618 testcase( pExpr->op==TK_AGG_COLUMN );
82619 if( pWalker->eCode==3 && pExpr->iTable==pWalker->u.iCur ){
82620 return WRC_Continue;
82621 }else{
82622 pWalker->eCode = 0;
82623 return WRC_Abort;
82624 }
82625 case TK_VARIABLE:
82626 if( pWalker->eCode==5 ){
82627 /* Silently convert bound parameters that appear inside of CREATE
82628 ** statements into a NULL when parsing the CREATE statement text out
82629 ** of the sqlite_master table */
82630 pExpr->op = TK_NULL;
82631 }else if( pWalker->eCode==4 ){
82632 /* A bound parameter in a CREATE statement that originates from
82633 ** sqlite3_prepare() causes an error */
82634 pWalker->eCode = 0;
82635 return WRC_Abort;
82636 }
82637 /* Fall through */
82638 default:
82639 testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */
@@ -82641,68 +81925,57 @@
82641 return WRC_Continue;
82642 }
82643 }
82644 static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){
82645 UNUSED_PARAMETER(NotUsed);
82646 pWalker->eCode = 0;
82647 return WRC_Abort;
82648 }
82649 static int exprIsConst(Expr *p, int initFlag, int iCur){
82650 Walker w;
82651 memset(&w, 0, sizeof(w));
82652 w.eCode = initFlag;
82653 w.xExprCallback = exprNodeIsConstant;
82654 w.xSelectCallback = selectNodeIsConstant;
82655 w.u.iCur = iCur;
82656 sqlite3WalkExpr(&w, p);
82657 return w.eCode;
82658 }
82659
82660 /*
82661 ** Walk an expression tree. Return non-zero if the expression is constant
82662 ** and 0 if it involves variables or function calls.
82663 **
82664 ** For the purposes of this function, a double-quoted string (ex: "abc")
82665 ** is considered a variable but a single-quoted string (ex: 'abc') is
82666 ** a constant.
82667 */
82668 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr *p){
82669 return exprIsConst(p, 1, 0);
82670 }
82671
82672 /*
82673 ** Walk an expression tree. Return non-zero if the expression is constant
82674 ** that does no originate from the ON or USING clauses of a join.
82675 ** Return 0 if it involves variables or function calls or terms from
82676 ** an ON or USING clause.
82677 */
82678 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *p){
82679 return exprIsConst(p, 2, 0);
82680 }
82681
82682 /*
82683 ** Walk an expression tree. Return non-zero if the expression constant
82684 ** for any single row of the table with cursor iCur. In other words, the
82685 ** expression must not refer to any non-deterministic function nor any
82686 ** table other than iCur.
82687 */
82688 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
82689 return exprIsConst(p, 3, iCur);
82690 }
82691
82692 /*
82693 ** Walk an expression tree. Return non-zero if the expression is constant
82694 ** or a function call with constant arguments. Return and 0 if there
82695 ** are any variables.
82696 **
82697 ** For the purposes of this function, a double-quoted string (ex: "abc")
82698 ** is considered a variable but a single-quoted string (ex: 'abc') is
82699 ** a constant.
82700 */
82701 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){
82702 assert( isInit==0 || isInit==1 );
82703 return exprIsConst(p, 4+isInit, 0);
82704 }
82705
82706 /*
82707 ** If the expression p codes a constant integer that is small enough
82708 ** to fit in a 32-bit integer, return 1 and put the value of the integer
@@ -83208,11 +82481,10 @@
83208 sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
83209 dest.affSdst = (u8)affinity;
83210 assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
83211 pSelect->iLimit = 0;
83212 testcase( pSelect->selFlags & SF_Distinct );
83213 pSelect->selFlags &= ~SF_Distinct;
83214 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
83215 if( sqlite3Select(pParse, pSelect, &dest) ){
83216 sqlite3KeyInfoUnref(pKeyInfo);
83217 return 0;
83218 }
@@ -88149,11 +87421,10 @@
88149 nSample--;
88150 }else{
88151 nRow = pIdx->aiRowEst[0];
88152 nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
88153 }
88154 pIdx->nRowEst0 = nRow;
88155
88156 /* Set nSum to the number of distinct (iCol+1) field prefixes that
88157 ** occur in the stat4 table for this index. Set sumEq to the sum of
88158 ** the nEq values for column iCol for the same set (adding the value
88159 ** only once where there exist duplicate prefixes). */
@@ -88411,11 +87682,11 @@
88411 }
88412
88413
88414 /* Load the statistics from the sqlite_stat4 table. */
88415 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
88416 if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){
88417 int lookasideEnabled = db->lookaside.bEnabled;
88418 db->lookaside.bEnabled = 0;
88419 rc = loadStat4(db, sInfo.zDatabase);
88420 db->lookaside.bEnabled = lookasideEnabled;
88421 }
@@ -89093,13 +88364,10 @@
89093 SQLITE_API int sqlite3_set_authorizer(
89094 sqlite3 *db,
89095 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
89096 void *pArg
89097 ){
89098 #ifdef SQLITE_ENABLE_API_ARMOR
89099 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
89100 #endif
89101 sqlite3_mutex_enter(db->mutex);
89102 db->xAuth = (sqlite3_xauth)xAuth;
89103 db->pAuthArg = pArg;
89104 sqlite3ExpirePreparedStatements(db);
89105 sqlite3_mutex_leave(db->mutex);
@@ -89590,15 +88858,11 @@
89590 ** See also sqlite3LocateTable().
89591 */
89592 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
89593 Table *p = 0;
89594 int i;
89595
89596 #ifdef SQLITE_ENABLE_API_ARMOR
89597 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return 0;
89598 #endif
89599
89600 /* All mutexes are required for schema access. Make sure we hold them. */
89601 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
89602 #if SQLITE_USER_AUTHENTICATION
89603 /* Only the admin user is allowed to know that the sqlite_user table
89604 ** exists */
@@ -104617,16 +103881,13 @@
104617 Vdbe *pOld, /* VM being reprepared */
104618 sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
104619 const char **pzTail /* OUT: End of parsed string */
104620 ){
104621 int rc;
104622
104623 #ifdef SQLITE_ENABLE_API_ARMOR
104624 if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
104625 #endif
104626 *ppStmt = 0;
104627 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
104628 return SQLITE_MISUSE_BKPT;
104629 }
104630 sqlite3_mutex_enter(db->mutex);
104631 sqlite3BtreeEnterAll(db);
104632 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
@@ -104729,15 +103990,13 @@
104729 */
104730 char *zSql8;
104731 const char *zTail8 = 0;
104732 int rc = SQLITE_OK;
104733
104734 #ifdef SQLITE_ENABLE_API_ARMOR
104735 if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
104736 #endif
104737 *ppStmt = 0;
104738 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
104739 return SQLITE_MISUSE_BKPT;
104740 }
104741 if( nBytes>=0 ){
104742 int sz;
104743 const char *z = (const char*)zSql;
@@ -110446,13 +109705,10 @@
110446 char **pzErrMsg /* Write error messages here */
110447 ){
110448 int rc;
110449 TabResult res;
110450
110451 #ifdef SQLITE_ENABLE_API_ARMOR
110452 if( pazResult==0 ) return SQLITE_MISUSE_BKPT;
110453 #endif
110454 *pazResult = 0;
110455 if( pnColumn ) *pnColumn = 0;
110456 if( pnRow ) *pnRow = 0;
110457 if( pzErrMsg ) *pzErrMsg = 0;
110458 res.zErrMsg = 0;
@@ -112512,11 +111768,11 @@
112512 ** Two writes per page are required in step (3) because the original
112513 ** database content must be written into the rollback journal prior to
112514 ** overwriting the database with the vacuumed content.
112515 **
112516 ** Only 1x temporary space and only 1x writes would be required if
112517 ** the copy of step (3) were replaced by deleting the original database
112518 ** and renaming the transient database as the original. But that will
112519 ** not work if other processes are attached to the original database.
112520 ** And a power loss in between deleting the original and renaming the
112521 ** transient would cause the database file to appear to be deleted
112522 ** following reboot.
@@ -112870,13 +112126,10 @@
112870 sqlite3 *db, /* Database in which module is registered */
112871 const char *zName, /* Name assigned to this module */
112872 const sqlite3_module *pModule, /* The definition of the module */
112873 void *pAux /* Context pointer for xCreate/xConnect */
112874 ){
112875 #ifdef SQLITE_ENABLE_API_ARMOR
112876 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
112877 #endif
112878 return createModule(db, zName, pModule, pAux, 0);
112879 }
112880
112881 /*
112882 ** External API function used to create a new virtual-table module.
@@ -112886,13 +112139,10 @@
112886 const char *zName, /* Name assigned to this module */
112887 const sqlite3_module *pModule, /* The definition of the module */
112888 void *pAux, /* Context pointer for xCreate/xConnect */
112889 void (*xDestroy)(void *) /* Module destructor function */
112890 ){
112891 #ifdef SQLITE_ENABLE_API_ARMOR
112892 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
112893 #endif
112894 return createModule(db, zName, pModule, pAux, xDestroy);
112895 }
112896
112897 /*
112898 ** Lock the virtual table so that it cannot be disconnected.
@@ -113493,13 +112743,10 @@
113493
113494 int rc = SQLITE_OK;
113495 Table *pTab;
113496 char *zErr = 0;
113497
113498 #ifdef SQLITE_ENABLE_API_ARMOR
113499 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
113500 #endif
113501 sqlite3_mutex_enter(db->mutex);
113502 if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
113503 sqlite3Error(db, SQLITE_MISUSE);
113504 sqlite3_mutex_leave(db->mutex);
113505 return SQLITE_MISUSE_BKPT;
@@ -113852,13 +113099,10 @@
113852 */
113853 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){
113854 static const unsigned char aMap[] = {
113855 SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE
113856 };
113857 #ifdef SQLITE_ENABLE_API_ARMOR
113858 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
113859 #endif
113860 assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 );
113861 assert( OE_Ignore==4 && OE_Replace==5 );
113862 assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 );
113863 return (int)aMap[db->vtabOnConflict-1];
113864 }
@@ -113870,14 +113114,12 @@
113870 */
113871 SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){
113872 va_list ap;
113873 int rc = SQLITE_OK;
113874
113875 #ifdef SQLITE_ENABLE_API_ARMOR
113876 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
113877 #endif
113878 sqlite3_mutex_enter(db->mutex);
 
113879 va_start(ap, op);
113880 switch( op ){
113881 case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
113882 VtabCtx *p = db->pVtabCtx;
113883 if( !p ){
@@ -114008,13 +113250,10 @@
114008 } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
114009 Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
114010 } u;
114011 struct WhereLoop *pWLoop; /* The selected WhereLoop object */
114012 Bitmask notReady; /* FROM entries not usable at this level */
114013 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
114014 int addrVisit; /* Address at which row is visited */
114015 #endif
114016 };
114017
114018 /*
114019 ** Each instance of this object represents an algorithm for evaluating one
114020 ** term of a join. Every term of the FROM clause will have at least
@@ -114041,10 +113280,11 @@
114041 LogEst rRun; /* Cost of running each loop */
114042 LogEst nOut; /* Estimated number of output rows */
114043 union {
114044 struct { /* Information for internal btree tables */
114045 u16 nEq; /* Number of equality constraints */
 
114046 Index *pIndex; /* Index used, or NULL */
114047 } btree;
114048 struct { /* Information for virtual tables */
114049 int idxNum; /* Index number */
114050 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -114053,17 +113293,16 @@
114053 char *idxStr; /* Index identifier string */
114054 } vtab;
114055 } u;
114056 u32 wsFlags; /* WHERE_* flags describing the plan */
114057 u16 nLTerm; /* Number of entries in aLTerm[] */
114058 u16 nSkip; /* Number of NULL aLTerm[] entries */
114059 /**** whereLoopXfer() copies fields above ***********************/
114060 # define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot)
114061 u16 nLSlot; /* Number of slots allocated for aLTerm[] */
114062 WhereTerm **aLTerm; /* WhereTerms used */
114063 WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
114064 WhereTerm *aLTermSpace[3]; /* Initial aLTerm[] space */
114065 };
114066
114067 /* This object holds the prerequisites and the cost of running a
114068 ** subquery on one operand of an OR operator in the WHERE clause.
114069 ** See WhereOrSet for additional information
@@ -114385,11 +113624,10 @@
114385 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
114386 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
114387 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
114388 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
114389 #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
114390 #define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */
114391
114392 /************** End of whereInt.h ********************************************/
114393 /************** Continuing where we left off in where.c **********************/
114394
114395 /*
@@ -114596,11 +113834,11 @@
114596 }
114597 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
114598 }
114599 pTerm = &pWC->a[idx = pWC->nTerm++];
114600 if( p && ExprHasProperty(p, EP_Unlikely) ){
114601 pTerm->truthProb = sqlite3LogEst(p->iTable) - 270;
114602 }else{
114603 pTerm->truthProb = 1;
114604 }
114605 pTerm->pExpr = sqlite3ExprSkipCollate(p);
114606 pTerm->wtFlags = wtFlags;
@@ -115127,19 +114365,10 @@
115127 pDerived->flags |= pBase->flags & EP_FromJoin;
115128 pDerived->iRightJoinTable = pBase->iRightJoinTable;
115129 }
115130 }
115131
115132 /*
115133 ** Mark term iChild as being a child of term iParent
115134 */
115135 static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){
115136 pWC->a[iChild].iParent = iParent;
115137 pWC->a[iChild].truthProb = pWC->a[iParent].truthProb;
115138 pWC->a[iParent].nChild++;
115139 }
115140
115141 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
115142 /*
115143 ** Analyze a term that consists of two or more OR-connected
115144 ** subterms. So in:
115145 **
@@ -115433,11 +114662,12 @@
115433 pNew->x.pList = pList;
115434 idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
115435 testcase( idxNew==0 );
115436 exprAnalyze(pSrc, pWC, idxNew);
115437 pTerm = &pWC->a[idxTerm];
115438 markTermAsChild(pWC, idxNew, idxTerm);
 
115439 }else{
115440 sqlite3ExprListDelete(db, pList);
115441 }
115442 pTerm->eOperator = WO_NOOP; /* case 1 trumps case 2 */
115443 }
@@ -115535,12 +114765,13 @@
115535 return;
115536 }
115537 idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);
115538 if( idxNew==0 ) return;
115539 pNew = &pWC->a[idxNew];
115540 markTermAsChild(pWC, idxNew, idxTerm);
115541 pTerm = &pWC->a[idxTerm];
 
115542 pTerm->wtFlags |= TERM_COPIED;
115543 if( pExpr->op==TK_EQ
115544 && !ExprHasProperty(pExpr, EP_FromJoin)
115545 && OptimizationEnabled(db, SQLITE_Transitive)
115546 ){
@@ -115593,12 +114824,13 @@
115593 transferJoinMarkings(pNewExpr, pExpr);
115594 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
115595 testcase( idxNew==0 );
115596 exprAnalyze(pSrc, pWC, idxNew);
115597 pTerm = &pWC->a[idxTerm];
115598 markTermAsChild(pWC, idxNew, idxTerm);
115599 }
 
115600 }
115601 #endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */
115602
115603 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
115604 /* Analyze a term that is composed of two or more subterms connected by
@@ -115669,12 +114901,13 @@
115669 idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC);
115670 testcase( idxNew2==0 );
115671 exprAnalyze(pSrc, pWC, idxNew2);
115672 pTerm = &pWC->a[idxTerm];
115673 if( isComplete ){
115674 markTermAsChild(pWC, idxNew1, idxTerm);
115675 markTermAsChild(pWC, idxNew2, idxTerm);
 
115676 }
115677 }
115678 #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
115679
115680 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -115703,12 +114936,13 @@
115703 pNewTerm = &pWC->a[idxNew];
115704 pNewTerm->prereqRight = prereqExpr;
115705 pNewTerm->leftCursor = pLeft->iTable;
115706 pNewTerm->u.leftColumn = pLeft->iColumn;
115707 pNewTerm->eOperator = WO_MATCH;
115708 markTermAsChild(pWC, idxNew, idxTerm);
115709 pTerm = &pWC->a[idxTerm];
 
115710 pTerm->wtFlags |= TERM_COPIED;
115711 pNewTerm->prereqAll = pTerm->prereqAll;
115712 }
115713 }
115714 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -115725,11 +114959,11 @@
115725 ** the start of the loop will prevent any results from being returned.
115726 */
115727 if( pExpr->op==TK_NOTNULL
115728 && pExpr->pLeft->op==TK_COLUMN
115729 && pExpr->pLeft->iColumn>=0
115730 && OptimizationEnabled(db, SQLITE_Stat34)
115731 ){
115732 Expr *pNewExpr;
115733 Expr *pLeft = pExpr->pLeft;
115734 int idxNew;
115735 WhereTerm *pNewTerm;
@@ -115744,12 +114978,13 @@
115744 pNewTerm = &pWC->a[idxNew];
115745 pNewTerm->prereqRight = 0;
115746 pNewTerm->leftCursor = pLeft->iTable;
115747 pNewTerm->u.leftColumn = pLeft->iColumn;
115748 pNewTerm->eOperator = WO_GT;
115749 markTermAsChild(pWC, idxNew, idxTerm);
115750 pTerm = &pWC->a[idxTerm];
 
115751 pTerm->wtFlags |= TERM_COPIED;
115752 pNewTerm->prereqAll = pTerm->prereqAll;
115753 }
115754 }
115755 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
@@ -115965,12 +115200,10 @@
115965 WhereLoop *pLoop; /* The Loop object */
115966 char *zNotUsed; /* Extra space on the end of pIdx */
115967 Bitmask idxCols; /* Bitmap of columns used for indexing */
115968 Bitmask extraCols; /* Bitmap of additional columns */
115969 u8 sentWarning = 0; /* True if a warnning has been issued */
115970 Expr *pPartial = 0; /* Partial Index Expression */
115971 int iContinue = 0; /* Jump here to skip excluded rows */
115972
115973 /* Generate code to skip over the creation and initialization of the
115974 ** transient index on 2nd and subsequent iterations of the loop. */
115975 v = pParse->pVdbe;
115976 assert( v!=0 );
@@ -115982,16 +115215,10 @@
115982 pTable = pSrc->pTab;
115983 pWCEnd = &pWC->a[pWC->nTerm];
115984 pLoop = pLevel->pWLoop;
115985 idxCols = 0;
115986 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
115987 if( pLoop->prereq==0
115988 && (pTerm->wtFlags & TERM_VIRTUAL)==0
115989 && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){
115990 pPartial = sqlite3ExprAnd(pParse->db, pPartial,
115991 sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
115992 }
115993 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
115994 int iCol = pTerm->u.leftColumn;
115995 Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
115996 testcase( iCol==BMS );
115997 testcase( iCol==BMS-1 );
@@ -116000,13 +115227,11 @@
116000 "automatic index on %s(%s)", pTable->zName,
116001 pTable->aCol[iCol].zName);
116002 sentWarning = 1;
116003 }
116004 if( (idxCols & cMask)==0 ){
116005 if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){
116006 goto end_auto_index_create;
116007 }
116008 pLoop->aLTerm[nKeyCol++] = pTerm;
116009 idxCols |= cMask;
116010 }
116011 }
116012 }
@@ -116022,23 +115247,24 @@
116022 ** be a covering index because the index will not be updated if the
116023 ** original table changes and the index and table cannot both be used
116024 ** if they go out of sync.
116025 */
116026 extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
116027 mxBitCol = MIN(BMS-1,pTable->nCol);
116028 testcase( pTable->nCol==BMS-1 );
116029 testcase( pTable->nCol==BMS-2 );
116030 for(i=0; i<mxBitCol; i++){
116031 if( extraCols & MASKBIT(i) ) nKeyCol++;
116032 }
116033 if( pSrc->colUsed & MASKBIT(BMS-1) ){
116034 nKeyCol += pTable->nCol - BMS + 1;
116035 }
 
116036
116037 /* Construct the Index object to describe this index */
116038 pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
116039 if( pIdx==0 ) goto end_auto_index_create;
116040 pLoop->u.btree.pIndex = pIdx;
116041 pIdx->zName = "auto-index";
116042 pIdx->pTable = pTable;
116043 n = 0;
116044 idxCols = 0;
@@ -116086,33 +115312,22 @@
116086 sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
116087 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
116088 VdbeComment((v, "for %s", pTable->zName));
116089
116090 /* Fill the automatic index with content */
116091 sqlite3ExprCachePush(pParse);
116092 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
116093 if( pPartial ){
116094 iContinue = sqlite3VdbeMakeLabel(v);
116095 sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL);
116096 pLoop->wsFlags |= WHERE_PARTIALIDX;
116097 }
116098 regRecord = sqlite3GetTempReg(pParse);
116099 sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
116100 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
116101 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
116102 if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
116103 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
116104 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
116105 sqlite3VdbeJumpHere(v, addrTop);
116106 sqlite3ReleaseTempReg(pParse, regRecord);
116107 sqlite3ExprCachePop(pParse);
116108
116109 /* Jump here when skipping the initialization */
116110 sqlite3VdbeJumpHere(v, addrInit);
116111
116112 end_auto_index_create:
116113 sqlite3ExprDelete(pParse->db, pPartial);
116114 }
116115 #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
116116
116117 #ifndef SQLITE_OMIT_VIRTUALTABLE
116118 /*
@@ -116267,23 +115482,23 @@
116267 }
116268
116269 return pParse->nErr;
116270 }
116271 #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */
 
116272
116273 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
116274 /*
116275 ** Estimate the location of a particular key among all keys in an
116276 ** index. Store the results in aStat as follows:
116277 **
116278 ** aStat[0] Est. number of rows less than pVal
116279 ** aStat[1] Est. number of rows equal to pVal
116280 **
116281 ** Return the index of the sample that is the smallest sample that
116282 ** is greater than or equal to pRec.
116283 */
116284 static int whereKeyStats(
116285 Parse *pParse, /* Database connection */
116286 Index *pIdx, /* Index to consider domain of */
116287 UnpackedRecord *pRec, /* Vector of values to consider */
116288 int roundUp, /* Round up if true. Round down if false */
116289 tRowcnt *aStat /* OUT: stats written here */
@@ -116361,11 +115576,10 @@
116361 }else{
116362 iGap = iGap/3;
116363 }
116364 aStat[0] = iLower + iGap;
116365 }
116366 return i;
116367 }
116368 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
116369
116370 /*
116371 ** If it is not NULL, pTerm is a term that provides an upper or lower
@@ -116512,11 +115726,11 @@
116512 ** pLower pUpper
116513 **
116514 ** If either of the upper or lower bound is not present, then NULL is passed in
116515 ** place of the corresponding WhereTerm.
116516 **
116517 ** The value in (pBuilder->pNew->u.btree.nEq) is the number of the index
116518 ** column subject to the range constraint. Or, equivalently, the number of
116519 ** equality constraints optimized by the proposed index scan. For example,
116520 ** assuming index p is on t1(a, b), and the SQL query is:
116521 **
116522 ** ... FROM t1 WHERE a = ? AND b > ? AND b < ? ...
@@ -116528,11 +115742,11 @@
116528 **
116529 ** then nEq is set to 0.
116530 **
116531 ** When this function is called, *pnOut is set to the sqlite3LogEst() of the
116532 ** number of rows that the index scan is expected to visit without
116533 ** considering the range constraints. If nEq is 0, then *pnOut is the number of
116534 ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
116535 ** to account for the range constraints pLower and pUpper.
116536 **
116537 ** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be
116538 ** used, a single range inequality reduces the search space by a factor of 4.
@@ -116552,11 +115766,14 @@
116552
116553 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
116554 Index *p = pLoop->u.btree.pIndex;
116555 int nEq = pLoop->u.btree.nEq;
116556
116557 if( p->nSample>0 && nEq<p->nSampleCol ){
 
 
 
116558 if( nEq==pBuilder->nRecValid ){
116559 UnpackedRecord *pRec = pBuilder->pRec;
116560 tRowcnt a[2];
116561 u8 aff;
116562
@@ -116568,23 +115785,19 @@
116568 **
116569 ** Or, if pLower is NULL or $L cannot be extracted from it (because it
116570 ** is not a simple variable or literal value), the lower bound of the
116571 ** range is $P. Due to a quirk in the way whereKeyStats() works, even
116572 ** if $L is available, whereKeyStats() is called for both ($P) and
116573 ** ($P:$L) and the larger of the two returned values is used.
116574 **
116575 ** Similarly, iUpper is to be set to the estimate of the number of rows
116576 ** less than the upper bound of the range query. Where the upper bound
116577 ** is either ($P) or ($P:$U). Again, even if $U is available, both values
116578 ** of iUpper are requested of whereKeyStats() and the smaller used.
116579 **
116580 ** The number of rows between the two bounds is then just iUpper-iLower.
116581 */
116582 tRowcnt iLower; /* Rows less than the lower bound */
116583 tRowcnt iUpper; /* Rows less than the upper bound */
116584 int iLwrIdx = -2; /* aSample[] for the lower bound */
116585 int iUprIdx = -1; /* aSample[] for the upper bound */
116586
116587 if( pRec ){
116588 testcase( pRec->nField!=pBuilder->nRecValid );
116589 pRec->nField = pBuilder->nRecValid;
116590 }
@@ -116594,11 +115807,11 @@
116594 aff = p->pTable->aCol[p->aiColumn[nEq]].affinity;
116595 }
116596 /* Determine iLower and iUpper using ($P) only. */
116597 if( nEq==0 ){
116598 iLower = 0;
116599 iUpper = p->nRowEst0;
116600 }else{
116601 /* Note: this call could be optimized away - since the same values must
116602 ** have been requested when testing key $P in whereEqualScanEst(). */
116603 whereKeyStats(pParse, p, pRec, 0, a);
116604 iLower = a[0];
@@ -116618,11 +115831,11 @@
116618 int bOk; /* True if value is extracted from pExpr */
116619 Expr *pExpr = pLower->pExpr->pRight;
116620 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
116621 if( rc==SQLITE_OK && bOk ){
116622 tRowcnt iNew;
116623 iLwrIdx = whereKeyStats(pParse, p, pRec, 0, a);
116624 iNew = a[0] + ((pLower->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
116625 if( iNew>iLower ) iLower = iNew;
116626 nOut--;
116627 pLower = 0;
116628 }
@@ -116633,11 +115846,11 @@
116633 int bOk; /* True if value is extracted from pExpr */
116634 Expr *pExpr = pUpper->pExpr->pRight;
116635 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
116636 if( rc==SQLITE_OK && bOk ){
116637 tRowcnt iNew;
116638 iUprIdx = whereKeyStats(pParse, p, pRec, 1, a);
116639 iNew = a[0] + ((pUpper->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
116640 if( iNew<iUpper ) iUpper = iNew;
116641 nOut--;
116642 pUpper = 0;
116643 }
@@ -116645,15 +115858,10 @@
116645
116646 pBuilder->pRec = pRec;
116647 if( rc==SQLITE_OK ){
116648 if( iUpper>iLower ){
116649 nNew = sqlite3LogEst(iUpper - iLower);
116650 /* TUNING: If both iUpper and iLower are derived from the same
116651 ** sample, then assume they are 4x more selective. This brings
116652 ** the estimated selectivity more in line with what it would be
116653 ** if estimated without the use of STAT3/4 tables. */
116654 if( iLwrIdx==iUprIdx ) nNew -= 20; assert( 20==sqlite3LogEst(4) );
116655 }else{
116656 nNew = 10; assert( 10==sqlite3LogEst(2) );
116657 }
116658 if( nNew<nOut ){
116659 nOut = nNew;
@@ -116674,19 +115882,16 @@
116674 #endif
116675 assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 );
116676 nNew = whereRangeAdjust(pLower, nOut);
116677 nNew = whereRangeAdjust(pUpper, nNew);
116678
116679 /* TUNING: If there is both an upper and lower limit and neither limit
116680 ** has an application-defined likelihood(), assume the range is
116681 ** reduced by an additional 75%. This means that, by default, an open-ended
116682 ** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the
116683 ** index. While a closed range (e.g. col BETWEEN ? AND ?) is estimated to
116684 ** match 1/64 of the index. */
116685 if( pLower && pLower->truthProb>0 && pUpper && pUpper->truthProb>0 ){
116686 nNew -= 20;
116687 }
116688
116689 nOut -= (pLower!=0) + (pUpper!=0);
116690 if( nNew<10 ) nNew = 10;
116691 if( nNew<nOut ) nOut = nNew;
116692 #if defined(WHERETRACE_ENABLED)
@@ -117042,11 +116247,11 @@
117042
117043 /* This module is only called on query plans that use an index. */
117044 pLoop = pLevel->pWLoop;
117045 assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
117046 nEq = pLoop->u.btree.nEq;
117047 nSkip = pLoop->nSkip;
117048 pIdx = pLoop->u.btree.pIndex;
117049 assert( pIdx!=0 );
117050
117051 /* Figure out how many memory cells we will need then allocate them.
117052 */
@@ -117156,11 +116361,11 @@
117156 ** "a=? AND b>?"
117157 */
117158 static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
117159 Index *pIndex = pLoop->u.btree.pIndex;
117160 u16 nEq = pLoop->u.btree.nEq;
117161 u16 nSkip = pLoop->nSkip;
117162 int i, j;
117163 Column *aCol = pTab->aCol;
117164 i16 *aiColumn = pIndex->aiColumn;
117165
117166 if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
@@ -117187,27 +116392,23 @@
117187 sqlite3StrAccumAppend(pStr, ")", 1);
117188 }
117189
117190 /*
117191 ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
117192 ** command, or if either SQLITE_DEBUG or SQLITE_ENABLE_STMT_SCANSTATUS was
117193 ** defined at compile-time. If it is not a no-op, a single OP_Explain opcode
117194 ** is added to the output to describe the table scan strategy in pLevel.
117195 **
117196 ** If an OP_Explain opcode is added to the VM, its address is returned.
117197 ** Otherwise, if no OP_Explain is coded, zero is returned.
117198 */
117199 static int explainOneScan(
117200 Parse *pParse, /* Parse context */
117201 SrcList *pTabList, /* Table list this loop refers to */
117202 WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
117203 int iLevel, /* Value for "level" column of output */
117204 int iFrom, /* Value for "from" column of output */
117205 u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
117206 ){
117207 int ret = 0;
117208 #if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
117209 if( pParse->explain==2 )
117210 #endif
117211 {
117212 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
117213 Vdbe *v = pParse->pVdbe; /* VM being constructed */
@@ -117220,11 +116421,11 @@
117220 StrAccum str; /* EQP output string */
117221 char zBuf[100]; /* Initial space for EQP output string */
117222
117223 pLoop = pLevel->pWLoop;
117224 flags = pLoop->wsFlags;
117225 if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return 0;
117226
117227 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
117228 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
117229 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
117230
@@ -117249,12 +116450,10 @@
117249 assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
117250 if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
117251 if( isSearch ){
117252 zFmt = "PRIMARY KEY";
117253 }
117254 }else if( flags & WHERE_PARTIALIDX ){
117255 zFmt = "AUTOMATIC PARTIAL COVERING INDEX";
117256 }else if( flags & WHERE_AUTO_INDEX ){
117257 zFmt = "AUTOMATIC COVERING INDEX";
117258 }else if( flags & WHERE_IDX_ONLY ){
117259 zFmt = "COVERING INDEX %s";
117260 }else{
@@ -117292,49 +116491,16 @@
117292 }else{
117293 sqlite3StrAccumAppend(&str, " (~1 row)", 9);
117294 }
117295 #endif
117296 zMsg = sqlite3StrAccumFinish(&str);
117297 ret = sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg,P4_DYNAMIC);
117298 }
117299 return ret;
117300 }
117301 #else
117302 # define explainOneScan(u,v,w,x,y,z) 0
117303 #endif /* SQLITE_OMIT_EXPLAIN */
117304
117305 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
117306 /*
117307 ** Configure the VM passed as the first argument with an
117308 ** sqlite3_stmt_scanstatus() entry corresponding to the scan used to
117309 ** implement level pLvl. Argument pSrclist is a pointer to the FROM
117310 ** clause that the scan reads data from.
117311 **
117312 ** If argument addrExplain is not 0, it must be the address of an
117313 ** OP_Explain instruction that describes the same loop.
117314 */
117315 static void addScanStatus(
117316 Vdbe *v, /* Vdbe to add scanstatus entry to */
117317 SrcList *pSrclist, /* FROM clause pLvl reads data from */
117318 WhereLevel *pLvl, /* Level to add scanstatus() entry for */
117319 int addrExplain /* Address of OP_Explain (or 0) */
117320 ){
117321 const char *zObj = 0;
117322 WhereLoop *pLoop = pLvl->pWLoop;
117323 if( (pLoop->wsFlags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
117324 zObj = pLoop->u.btree.pIndex->zName;
117325 }else{
117326 zObj = pSrclist->a[pLvl->iFrom].zName;
117327 }
117328 sqlite3VdbeScanStatus(
117329 v, addrExplain, pLvl->addrBody, pLvl->addrVisit, pLoop->nOut, zObj
117330 );
117331 }
117332 #else
117333 # define addScanStatus(a, b, c, d) ((void)d)
117334 #endif
117335
117336
117337
117338 /*
117339 ** Generate code for the start of the iLevel-th loop in the WHERE clause
117340 ** implementation described by pWInfo.
@@ -117632,11 +116798,11 @@
117632 u8 bSeekPastNull = 0; /* True to seek past initial nulls */
117633 u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */
117634
117635 pIdx = pLoop->u.btree.pIndex;
117636 iIdxCur = pLevel->iIdxCur;
117637 assert( nEq>=pLoop->nSkip );
117638
117639 /* If this loop satisfies a sort order (pOrderBy) request that
117640 ** was passed to this function to implement a "SELECT min(x) ..."
117641 ** query, then the caller will only allow the loop to run for
117642 ** a single iteration. This means that the first row returned
@@ -117649,11 +116815,11 @@
117649 || (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0 );
117650 if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
117651 && pWInfo->nOBSat>0
117652 && (pIdx->nKeyCol>nEq)
117653 ){
117654 assert( pLoop->nSkip==0 );
117655 bSeekPastNull = 1;
117656 nExtraReg = 1;
117657 }
117658
117659 /* Find any inequality constraint terms for the start and end
@@ -117998,15 +117164,13 @@
117998 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
117999 wctrlFlags, iCovCur);
118000 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
118001 if( pSubWInfo ){
118002 WhereLoop *pSubLoop;
118003 int addrExplain = explainOneScan(
118004 pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
118005 );
118006 addScanStatus(v, pOrTab, &pSubWInfo->a[0], addrExplain);
118007
118008 /* This is the sub-WHERE clause body. First skip over
118009 ** duplicate rows from prior sub-WHERE clauses, and record the
118010 ** rowid (or PRIMARY KEY) for the current row so that the same
118011 ** row will be skipped in subsequent sub-WHERE clauses.
118012 */
@@ -118133,14 +117297,10 @@
118133 VdbeCoverageIf(v, bRev!=0);
118134 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
118135 }
118136 }
118137
118138 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
118139 pLevel->addrVisit = sqlite3VdbeCurrentAddr(v);
118140 #endif
118141
118142 /* Insert code to test every subexpression that can be completely
118143 ** computed using the current set of tables.
118144 */
118145 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
118146 Expr *pE;
@@ -118276,11 +117436,11 @@
118276 }
118277 sqlite3DebugPrintf(" %-19s", z);
118278 sqlite3_free(z);
118279 }
118280 if( p->wsFlags & WHERE_SKIPSCAN ){
118281 sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->nSkip);
118282 }else{
118283 sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm);
118284 }
118285 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
118286 if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){
@@ -118387,41 +117547,34 @@
118387 sqlite3DbFree(db, pWInfo);
118388 }
118389 }
118390
118391 /*
118392 ** Return TRUE if all of the following are true:
118393 **
118394 ** (1) X has the same or lower cost that Y
118395 ** (2) X is a proper subset of Y
118396 ** (3) X skips at least as many columns as Y
118397 **
118398 ** By "proper subset" we mean that X uses fewer WHERE clause terms
118399 ** than Y and that every WHERE clause term used by X is also used
118400 ** by Y.
118401 **
118402 ** If X is a proper subset of Y then Y is a better choice and ought
118403 ** to have a lower cost. This routine returns TRUE when that cost
118404 ** relationship is inverted and needs to be adjusted. The third rule
118405 ** was added because if X uses skip-scan less than Y it still might
118406 ** deserve a lower cost even if it is a proper subset of Y.
118407 */
118408 static int whereLoopCheaperProperSubset(
118409 const WhereLoop *pX, /* First WhereLoop to compare */
118410 const WhereLoop *pY /* Compare against this WhereLoop */
118411 ){
118412 int i, j;
118413 if( pX->nLTerm-pX->nSkip >= pY->nLTerm-pY->nSkip ){
118414 return 0; /* X is not a subset of Y */
118415 }
118416 if( pY->nSkip > pX->nSkip ) return 0;
118417 if( pX->rRun >= pY->rRun ){
118418 if( pX->rRun > pY->rRun ) return 0; /* X costs more than Y */
118419 if( pX->nOut > pY->nOut ) return 0; /* X costs more than Y */
118420 }
118421 for(i=pX->nLTerm-1; i>=0; i--){
118422 if( pX->aLTerm[i]==0 ) continue;
118423 for(j=pY->nLTerm-1; j>=0; j--){
118424 if( pY->aLTerm[j]==pX->aLTerm[i] ) break;
118425 }
118426 if( j<0 ) return 0; /* X not a subset of Y since term X[i] not used by Y */
118427 }
@@ -118439,28 +117592,37 @@
118439 ** is a proper subset.
118440 **
118441 ** To say "WhereLoop X is a proper subset of Y" means that X uses fewer
118442 ** WHERE clause terms than Y and that every WHERE clause term used by X is
118443 ** also used by Y.
 
 
 
 
 
 
 
 
 
 
 
118444 */
118445 static void whereLoopAdjustCost(const WhereLoop *p, WhereLoop *pTemplate){
118446 if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return;
 
118447 for(; p; p=p->pNextLoop){
118448 if( p->iTab!=pTemplate->iTab ) continue;
118449 if( (p->wsFlags & WHERE_INDEXED)==0 ) continue;
 
118450 if( whereLoopCheaperProperSubset(p, pTemplate) ){
118451 /* Adjust pTemplate cost downward so that it is cheaper than its
118452 ** subset p. */
118453 WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
118454 pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut-1));
118455 pTemplate->rRun = p->rRun;
118456 pTemplate->nOut = p->nOut - 1;
118457 }else if( whereLoopCheaperProperSubset(pTemplate, p) ){
118458 /* Adjust pTemplate cost upward so that it is costlier than p since
118459 ** pTemplate is a proper subset of p */
118460 WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
118461 pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut+1));
118462 pTemplate->rRun = p->rRun;
118463 pTemplate->nOut = p->nOut + 1;
118464 }
118465 }
118466 }
@@ -118742,11 +117904,11 @@
118742 int opMask; /* Valid operators for constraints */
118743 WhereScan scan; /* Iterator for WHERE terms */
118744 Bitmask saved_prereq; /* Original value of pNew->prereq */
118745 u16 saved_nLTerm; /* Original value of pNew->nLTerm */
118746 u16 saved_nEq; /* Original value of pNew->u.btree.nEq */
118747 u16 saved_nSkip; /* Original value of pNew->nSkip */
118748 u32 saved_wsFlags; /* Original value of pNew->wsFlags */
118749 LogEst saved_nOut; /* Original value of pNew->nOut */
118750 int iCol; /* Index of the column in the table */
118751 int rc = SQLITE_OK; /* Return code */
118752 LogEst rSize; /* Number of rows in the table */
@@ -118771,18 +117933,56 @@
118771 iCol = pProbe->aiColumn[pNew->u.btree.nEq];
118772
118773 pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
118774 opMask, pProbe);
118775 saved_nEq = pNew->u.btree.nEq;
118776 saved_nSkip = pNew->nSkip;
118777 saved_nLTerm = pNew->nLTerm;
118778 saved_wsFlags = pNew->wsFlags;
118779 saved_prereq = pNew->prereq;
118780 saved_nOut = pNew->nOut;
118781 pNew->rSetup = 0;
118782 rSize = pProbe->aiRowLogEst[0];
118783 rLogSize = estLog(rSize);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118784 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
118785 u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */
118786 LogEst rCostIdx;
118787 LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */
118788 int nIn = 0;
@@ -118873,10 +118073,11 @@
118873 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
118874 tRowcnt nOut = 0;
118875 if( nInMul==0
118876 && pProbe->nSample
118877 && pNew->u.btree.nEq<=pProbe->nSampleCol
 
118878 && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect))
118879 ){
118880 Expr *pExpr = pTerm->pExpr;
118881 if( (eOp & (WO_EQ|WO_ISNULL))!=0 ){
118882 testcase( eOp & WO_EQ );
@@ -118940,48 +118141,14 @@
118940 pBuilder->nRecValid = nRecValid;
118941 #endif
118942 }
118943 pNew->prereq = saved_prereq;
118944 pNew->u.btree.nEq = saved_nEq;
118945 pNew->nSkip = saved_nSkip;
118946 pNew->wsFlags = saved_wsFlags;
118947 pNew->nOut = saved_nOut;
118948 pNew->nLTerm = saved_nLTerm;
118949
118950 /* Consider using a skip-scan if there are no WHERE clause constraints
118951 ** available for the left-most terms of the index, and if the average
118952 ** number of repeats in the left-most terms is at least 18.
118953 **
118954 ** The magic number 18 is selected on the basis that scanning 17 rows
118955 ** is almost always quicker than an index seek (even though if the index
118956 ** contains fewer than 2^17 rows we assume otherwise in other parts of
118957 ** the code). And, even if it is not, it should not be too much slower.
118958 ** On the other hand, the extra seeks could end up being significantly
118959 ** more expensive. */
118960 assert( 42==sqlite3LogEst(18) );
118961 if( saved_nEq==saved_nSkip
118962 && saved_nEq+1<pProbe->nKeyCol
118963 && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
118964 && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
118965 ){
118966 LogEst nIter;
118967 pNew->u.btree.nEq++;
118968 pNew->nSkip++;
118969 pNew->aLTerm[pNew->nLTerm++] = 0;
118970 pNew->wsFlags |= WHERE_SKIPSCAN;
118971 nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1];
118972 pNew->nOut -= nIter;
118973 /* TUNING: Because uncertainties in the estimates for skip-scan queries,
118974 ** add a 1.375 fudge factor to make skip-scan slightly less likely. */
118975 nIter += 5;
118976 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul);
118977 pNew->nOut = saved_nOut;
118978 pNew->u.btree.nEq = saved_nEq;
118979 pNew->nSkip = saved_nSkip;
118980 pNew->wsFlags = saved_wsFlags;
118981 }
118982
118983 return rc;
118984 }
118985
118986 /*
118987 ** Return True if it is possible that pIndex might be useful in
@@ -119156,11 +118323,11 @@
119156 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
119157 for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
119158 if( pTerm->prereqRight & pNew->maskSelf ) continue;
119159 if( termCanDriveIndex(pTerm, pSrc, 0) ){
119160 pNew->u.btree.nEq = 1;
119161 pNew->nSkip = 0;
119162 pNew->u.btree.pIndex = 0;
119163 pNew->nLTerm = 1;
119164 pNew->aLTerm[0] = pTerm;
119165 /* TUNING: One-time cost for computing the automatic index is
119166 ** estimated to be X*N*log2(N) where N is the number of rows in
@@ -119197,11 +118364,11 @@
119197 testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
119198 continue; /* Partial index inappropriate for this query */
119199 }
119200 rSize = pProbe->aiRowLogEst[0];
119201 pNew->u.btree.nEq = 0;
119202 pNew->nSkip = 0;
119203 pNew->nLTerm = 0;
119204 pNew->iSortIdx = 0;
119205 pNew->rSetup = 0;
119206 pNew->prereq = mExtra;
119207 pNew->nOut = rSize;
@@ -119747,11 +118914,11 @@
119747 for(j=0; j<nColumn; j++){
119748 u8 bOnce; /* True to run the ORDER BY search loop */
119749
119750 /* Skip over == and IS NULL terms */
119751 if( j<pLoop->u.btree.nEq
119752 && pLoop->nSkip==0
119753 && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
119754 ){
119755 if( i & WO_ISNULL ){
119756 testcase( isOrderDistinct );
119757 isOrderDistinct = 0;
@@ -120201,11 +119368,11 @@
120201 }
120202 }
120203 }
120204
120205 #ifdef WHERETRACE_ENABLED /* >=2 */
120206 if( sqlite3WhereTrace & 0x02 ){
120207 sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
120208 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
120209 sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c",
120210 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
120211 pTo->isOrdered>=0 ? (pTo->isOrdered+'0') : '?');
@@ -120320,11 +119487,11 @@
120320 if( pItem->zIndex ) return 0;
120321 iCur = pItem->iCursor;
120322 pWC = &pWInfo->sWC;
120323 pLoop = pBuilder->pNew;
120324 pLoop->wsFlags = 0;
120325 pLoop->nSkip = 0;
120326 pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0);
120327 if( pTerm ){
120328 pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW;
120329 pLoop->aLTerm[0] = pTerm;
120330 pLoop->nLTerm = 1;
@@ -120332,10 +119499,11 @@
120332 /* TUNING: Cost of a rowid lookup is 10 */
120333 pLoop->rRun = 33; /* 33==sqlite3LogEst(10) */
120334 }else{
120335 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
120336 assert( pLoop->aLTermSpace==pLoop->aLTerm );
 
120337 if( !IsUniqueIndex(pIdx)
120338 || pIdx->pPartIdxWhere!=0
120339 || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace)
120340 ) continue;
120341 for(j=0; j<pIdx->nKeyCol; j++){
@@ -120840,30 +120008,22 @@
120840 ** loop below generates code for a single nested loop of the VM
120841 ** program.
120842 */
120843 notReady = ~(Bitmask)0;
120844 for(ii=0; ii<nTabList; ii++){
120845 int addrExplain;
120846 int wsFlags;
120847 pLevel = &pWInfo->a[ii];
120848 wsFlags = pLevel->pWLoop->wsFlags;
120849 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
120850 if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){
120851 constructAutomaticIndex(pParse, &pWInfo->sWC,
120852 &pTabList->a[pLevel->iFrom], notReady, pLevel);
120853 if( db->mallocFailed ) goto whereBeginError;
120854 }
120855 #endif
120856 addrExplain = explainOneScan(
120857 pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags
120858 );
120859 pLevel->addrBody = sqlite3VdbeCurrentAddr(v);
120860 notReady = codeOneLoopStart(pWInfo, ii, notReady);
120861 pWInfo->iContinue = pLevel->addrCont;
120862 if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_ONETABLE_ONLY)==0 ){
120863 addScanStatus(v, pTabList, pLevel, addrExplain);
120864 }
120865 }
120866
120867 /* Done. */
120868 VdbeModuleComment((v, "Begin WHERE-core"));
120869 return pWInfo;
@@ -125528,17 +124688,10 @@
125528 */
125529 SQLITE_API int sqlite3_complete(const char *zSql){
125530 u8 state = 0; /* Current state, using numbers defined in header comment */
125531 u8 token; /* Value of the next token */
125532
125533 #ifdef SQLITE_ENABLE_API_ARMOR
125534 if( zSql==0 ){
125535 (void)SQLITE_MISUSE_BKPT;
125536 return 0;
125537 }
125538 #endif
125539
125540 #ifndef SQLITE_OMIT_TRIGGER
125541 /* A complex statement machine used to detect the end of a CREATE TRIGGER
125542 ** statement. This is the normal case.
125543 */
125544 static const u8 trans[8][8] = {
@@ -126132,107 +125285,75 @@
126132
126133 va_start(ap, op);
126134 switch( op ){
126135
126136 /* Mutex configuration options are only available in a threadsafe
126137 ** compile.
126138 */
126139 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */
126140 case SQLITE_CONFIG_SINGLETHREAD: {
126141 /* Disable all mutexing */
126142 sqlite3GlobalConfig.bCoreMutex = 0;
126143 sqlite3GlobalConfig.bFullMutex = 0;
126144 break;
126145 }
126146 #endif
126147 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */
126148 case SQLITE_CONFIG_MULTITHREAD: {
126149 /* Disable mutexing of database connections */
126150 /* Enable mutexing of core data structures */
126151 sqlite3GlobalConfig.bCoreMutex = 1;
126152 sqlite3GlobalConfig.bFullMutex = 0;
126153 break;
126154 }
126155 #endif
126156 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */
126157 case SQLITE_CONFIG_SERIALIZED: {
126158 /* Enable all mutexing */
126159 sqlite3GlobalConfig.bCoreMutex = 1;
126160 sqlite3GlobalConfig.bFullMutex = 1;
126161 break;
126162 }
126163 #endif
126164 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */
126165 case SQLITE_CONFIG_MUTEX: {
126166 /* Specify an alternative mutex implementation */
126167 sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
126168 break;
126169 }
126170 #endif
126171 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */
126172 case SQLITE_CONFIG_GETMUTEX: {
126173 /* Retrieve the current mutex implementation */
126174 *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
126175 break;
126176 }
126177 #endif
 
126178
126179 case SQLITE_CONFIG_MALLOC: {
126180 /* EVIDENCE-OF: R-55594-21030 The SQLITE_CONFIG_MALLOC option takes a
126181 ** single argument which is a pointer to an instance of the
126182 ** sqlite3_mem_methods structure. The argument specifies alternative
126183 ** low-level memory allocation routines to be used in place of the memory
126184 ** allocation routines built into SQLite. */
126185 sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*);
126186 break;
126187 }
126188 case SQLITE_CONFIG_GETMALLOC: {
126189 /* EVIDENCE-OF: R-51213-46414 The SQLITE_CONFIG_GETMALLOC option takes a
126190 ** single argument which is a pointer to an instance of the
126191 ** sqlite3_mem_methods structure. The sqlite3_mem_methods structure is
126192 ** filled with the currently defined memory allocation routines. */
126193 if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault();
126194 *va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m;
126195 break;
126196 }
126197 case SQLITE_CONFIG_MEMSTATUS: {
126198 /* EVIDENCE-OF: R-61275-35157 The SQLITE_CONFIG_MEMSTATUS option takes
126199 ** single argument of type int, interpreted as a boolean, which enables
126200 ** or disables the collection of memory allocation statistics. */
126201 sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
126202 break;
126203 }
126204 case SQLITE_CONFIG_SCRATCH: {
126205 /* EVIDENCE-OF: R-08404-60887 There are three arguments to
126206 ** SQLITE_CONFIG_SCRATCH: A pointer an 8-byte aligned memory buffer from
126207 ** which the scratch allocations will be drawn, the size of each scratch
126208 ** allocation (sz), and the maximum number of scratch allocations (N). */
126209 sqlite3GlobalConfig.pScratch = va_arg(ap, void*);
126210 sqlite3GlobalConfig.szScratch = va_arg(ap, int);
126211 sqlite3GlobalConfig.nScratch = va_arg(ap, int);
126212 break;
126213 }
126214 case SQLITE_CONFIG_PAGECACHE: {
126215 /* EVIDENCE-OF: R-31408-40510 There are three arguments to
126216 ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory, the size
126217 ** of each page buffer (sz), and the number of pages (N). */
126218 sqlite3GlobalConfig.pPage = va_arg(ap, void*);
126219 sqlite3GlobalConfig.szPage = va_arg(ap, int);
126220 sqlite3GlobalConfig.nPage = va_arg(ap, int);
126221 break;
126222 }
126223 case SQLITE_CONFIG_PCACHE_HDRSZ: {
126224 /* EVIDENCE-OF: R-39100-27317 The SQLITE_CONFIG_PCACHE_HDRSZ option takes
126225 ** a single parameter which is a pointer to an integer and writes into
126226 ** that integer the number of extra bytes per page required for each page
126227 ** in SQLITE_CONFIG_PAGECACHE. */
126228 *va_arg(ap, int*) =
126229 sqlite3HeaderSizeBtree() +
126230 sqlite3HeaderSizePcache() +
126231 sqlite3HeaderSizePcache1();
126232 break;
126233 }
126234
126235 case SQLITE_CONFIG_PCACHE: {
126236 /* no-op */
126237 break;
126238 }
@@ -126241,37 +125362,25 @@
126241 rc = SQLITE_ERROR;
126242 break;
126243 }
126244
126245 case SQLITE_CONFIG_PCACHE2: {
126246 /* EVIDENCE-OF: R-63325-48378 The SQLITE_CONFIG_PCACHE2 option takes a
126247 ** single argument which is a pointer to an sqlite3_pcache_methods2
126248 ** object. This object specifies the interface to a custom page cache
126249 ** implementation. */
126250 sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*);
126251 break;
126252 }
126253 case SQLITE_CONFIG_GETPCACHE2: {
126254 /* EVIDENCE-OF: R-22035-46182 The SQLITE_CONFIG_GETPCACHE2 option takes a
126255 ** single argument which is a pointer to an sqlite3_pcache_methods2
126256 ** object. SQLite copies of the current page cache implementation into
126257 ** that object. */
126258 if( sqlite3GlobalConfig.pcache2.xInit==0 ){
126259 sqlite3PCacheSetDefault();
126260 }
126261 *va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2;
126262 break;
126263 }
126264
126265 /* EVIDENCE-OF: R-06626-12911 The SQLITE_CONFIG_HEAP option is only
126266 ** available if SQLite is compiled with either SQLITE_ENABLE_MEMSYS3 or
126267 ** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */
126268 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
126269 case SQLITE_CONFIG_HEAP: {
126270 /* EVIDENCE-OF: R-19854-42126 There are three arguments to
126271 ** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the
126272 ** number of bytes in the memory buffer, and the minimum allocation size. */
126273 sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
126274 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
126275 sqlite3GlobalConfig.mnReq = va_arg(ap, int);
126276
126277 if( sqlite3GlobalConfig.mnReq<1 ){
@@ -126280,23 +125389,21 @@
126280 /* cap min request size at 2^12 */
126281 sqlite3GlobalConfig.mnReq = (1<<12);
126282 }
126283
126284 if( sqlite3GlobalConfig.pHeap==0 ){
126285 /* EVIDENCE-OF: R-49920-60189 If the first pointer (the memory pointer)
126286 ** is NULL, then SQLite reverts to using its default memory allocator
126287 ** (the system malloc() implementation), undoing any prior invocation of
126288 ** SQLITE_CONFIG_MALLOC.
126289 **
126290 ** Setting sqlite3GlobalConfig.m to all zeros will cause malloc to
126291 ** revert to its default implementation when sqlite3_initialize() is run
126292 */
126293 memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
126294 }else{
126295 /* EVIDENCE-OF: R-61006-08918 If the memory pointer is not NULL then the
126296 ** alternative memory allocator is engaged to handle all of SQLites
126297 ** memory allocation needs. */
 
126298 #ifdef SQLITE_ENABLE_MEMSYS3
126299 sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3();
126300 #endif
126301 #ifdef SQLITE_ENABLE_MEMSYS5
126302 sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5();
@@ -126331,23 +125438,15 @@
126331 ** can be changed at start-time using the
126332 ** sqlite3_config(SQLITE_CONFIG_URI,1) or
126333 ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
126334 */
126335 case SQLITE_CONFIG_URI: {
126336 /* EVIDENCE-OF: R-25451-61125 The SQLITE_CONFIG_URI option takes a single
126337 ** argument of type int. If non-zero, then URI handling is globally
126338 ** enabled. If the parameter is zero, then URI handling is globally
126339 ** disabled. */
126340 sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
126341 break;
126342 }
126343
126344 case SQLITE_CONFIG_COVERING_INDEX_SCAN: {
126345 /* EVIDENCE-OF: R-36592-02772 The SQLITE_CONFIG_COVERING_INDEX_SCAN
126346 ** option takes a single integer argument which is interpreted as a
126347 ** boolean in order to enable or disable the use of covering indices for
126348 ** full table scans in the query optimizer. */
126349 sqlite3GlobalConfig.bUseCis = va_arg(ap, int);
126350 break;
126351 }
126352
126353 #ifdef SQLITE_ENABLE_SQLLOG
@@ -126358,37 +125457,24 @@
126358 break;
126359 }
126360 #endif
126361
126362 case SQLITE_CONFIG_MMAP_SIZE: {
126363 /* EVIDENCE-OF: R-58063-38258 SQLITE_CONFIG_MMAP_SIZE takes two 64-bit
126364 ** integer (sqlite3_int64) values that are the default mmap size limit
126365 ** (the default setting for PRAGMA mmap_size) and the maximum allowed
126366 ** mmap size limit. */
126367 sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64);
126368 sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64);
126369 /* EVIDENCE-OF: R-53367-43190 If either argument to this option is
126370 ** negative, then that argument is changed to its compile-time default.
126371 **
126372 ** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be
126373 ** silently truncated if necessary so that it does not exceed the
126374 ** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE
126375 ** compile-time option.
126376 */
126377 if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ) mxMmap = SQLITE_MAX_MMAP_SIZE;
126378 if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
126379 if( szMmap>mxMmap) szMmap = mxMmap;
126380 sqlite3GlobalConfig.mxMmap = mxMmap;
126381 sqlite3GlobalConfig.szMmap = szMmap;
126382 break;
126383 }
126384
126385 #if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC) /* IMP: R-04780-55815 */
126386 case SQLITE_CONFIG_WIN32_HEAPSIZE: {
126387 /* EVIDENCE-OF: R-34926-03360 SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit
126388 ** unsigned integer value that specifies the maximum size of the created
126389 ** heap. */
126390 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
126391 break;
126392 }
126393 #endif
126394
@@ -126468,29 +125554,19 @@
126468
126469 /*
126470 ** Return the mutex associated with a database connection.
126471 */
126472 SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
126473 #ifdef SQLITE_ENABLE_API_ARMOR
126474 if( !sqlite3SafetyCheckOk(db) ){
126475 (void)SQLITE_MISUSE_BKPT;
126476 return 0;
126477 }
126478 #endif
126479 return db->mutex;
126480 }
126481
126482 /*
126483 ** Free up as much memory as we can from the given database
126484 ** connection.
126485 */
126486 SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){
126487 int i;
126488
126489 #ifdef SQLITE_ENABLE_API_ARMOR
126490 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
126491 #endif
126492 sqlite3_mutex_enter(db->mutex);
126493 sqlite3BtreeEnterAll(db);
126494 for(i=0; i<db->nDb; i++){
126495 Btree *pBt = db->aDb[i].pBt;
126496 if( pBt ){
@@ -126617,42 +125693,24 @@
126617
126618 /*
126619 ** Return the ROWID of the most recent insert
126620 */
126621 SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
126622 #ifdef SQLITE_ENABLE_API_ARMOR
126623 if( !sqlite3SafetyCheckOk(db) ){
126624 (void)SQLITE_MISUSE_BKPT;
126625 return 0;
126626 }
126627 #endif
126628 return db->lastRowid;
126629 }
126630
126631 /*
126632 ** Return the number of changes in the most recent call to sqlite3_exec().
126633 */
126634 SQLITE_API int sqlite3_changes(sqlite3 *db){
126635 #ifdef SQLITE_ENABLE_API_ARMOR
126636 if( !sqlite3SafetyCheckOk(db) ){
126637 (void)SQLITE_MISUSE_BKPT;
126638 return 0;
126639 }
126640 #endif
126641 return db->nChange;
126642 }
126643
126644 /*
126645 ** Return the number of changes since the database handle was opened.
126646 */
126647 SQLITE_API int sqlite3_total_changes(sqlite3 *db){
126648 #ifdef SQLITE_ENABLE_API_ARMOR
126649 if( !sqlite3SafetyCheckOk(db) ){
126650 (void)SQLITE_MISUSE_BKPT;
126651 return 0;
126652 }
126653 #endif
126654 return db->nTotalChange;
126655 }
126656
126657 /*
126658 ** Close all open savepoints. This function only manipulates fields of the
@@ -127197,13 +126255,10 @@
127197 SQLITE_API int sqlite3_busy_handler(
127198 sqlite3 *db,
127199 int (*xBusy)(void*,int),
127200 void *pArg
127201 ){
127202 #ifdef SQLITE_ENABLE_API_ARMOR
127203 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE;
127204 #endif
127205 sqlite3_mutex_enter(db->mutex);
127206 db->busyHandler.xFunc = xBusy;
127207 db->busyHandler.pArg = pArg;
127208 db->busyHandler.nBusy = 0;
127209 db->busyTimeout = 0;
@@ -127221,16 +126276,10 @@
127221 sqlite3 *db,
127222 int nOps,
127223 int (*xProgress)(void*),
127224 void *pArg
127225 ){
127226 #ifdef SQLITE_ENABLE_API_ARMOR
127227 if( !sqlite3SafetyCheckOk(db) ){
127228 (void)SQLITE_MISUSE_BKPT;
127229 return;
127230 }
127231 #endif
127232 sqlite3_mutex_enter(db->mutex);
127233 if( nOps>0 ){
127234 db->xProgress = xProgress;
127235 db->nProgressOps = (unsigned)nOps;
127236 db->pProgressArg = pArg;
@@ -127247,13 +126296,10 @@
127247 /*
127248 ** This routine installs a default busy handler that waits for the
127249 ** specified number of milliseconds before returning 0.
127250 */
127251 SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
127252 #ifdef SQLITE_ENABLE_API_ARMOR
127253 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
127254 #endif
127255 if( ms>0 ){
127256 sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
127257 db->busyTimeout = ms;
127258 }else{
127259 sqlite3_busy_handler(db, 0, 0);
@@ -127263,16 +126309,10 @@
127263
127264 /*
127265 ** Cause any pending operation to stop at its earliest opportunity.
127266 */
127267 SQLITE_API void sqlite3_interrupt(sqlite3 *db){
127268 #ifdef SQLITE_ENABLE_API_ARMOR
127269 if( !sqlite3SafetyCheckOk(db) ){
127270 (void)SQLITE_MISUSE_BKPT;
127271 return;
127272 }
127273 #endif
127274 db->u1.isInterrupted = 1;
127275 }
127276
127277
127278 /*
@@ -127406,16 +126446,10 @@
127406 void (*xFinal)(sqlite3_context*),
127407 void (*xDestroy)(void *)
127408 ){
127409 int rc = SQLITE_ERROR;
127410 FuncDestructor *pArg = 0;
127411
127412 #ifdef SQLITE_ENABLE_API_ARMOR
127413 if( !sqlite3SafetyCheckOk(db) ){
127414 return SQLITE_MISUSE_BKPT;
127415 }
127416 #endif
127417 sqlite3_mutex_enter(db->mutex);
127418 if( xDestroy ){
127419 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
127420 if( !pArg ){
127421 xDestroy(p);
@@ -127448,14 +126482,10 @@
127448 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
127449 void (*xFinal)(sqlite3_context*)
127450 ){
127451 int rc;
127452 char *zFunc8;
127453
127454 #ifdef SQLITE_ENABLE_API_ARMOR
127455 if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT;
127456 #endif
127457 sqlite3_mutex_enter(db->mutex);
127458 assert( !db->mallocFailed );
127459 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
127460 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
127461 sqlite3DbFree(db, zFunc8);
@@ -127483,16 +126513,10 @@
127483 const char *zName,
127484 int nArg
127485 ){
127486 int nName = sqlite3Strlen30(zName);
127487 int rc = SQLITE_OK;
127488
127489 #ifdef SQLITE_ENABLE_API_ARMOR
127490 if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){
127491 return SQLITE_MISUSE_BKPT;
127492 }
127493 #endif
127494 sqlite3_mutex_enter(db->mutex);
127495 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
127496 rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
127497 0, sqlite3InvalidFunction, 0, 0, 0);
127498 }
@@ -127510,17 +126534,10 @@
127510 ** trace is a pointer to a function that is invoked at the start of each
127511 ** SQL statement.
127512 */
127513 SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
127514 void *pOld;
127515
127516 #ifdef SQLITE_ENABLE_API_ARMOR
127517 if( !sqlite3SafetyCheckOk(db) ){
127518 (void)SQLITE_MISUSE_BKPT;
127519 return 0;
127520 }
127521 #endif
127522 sqlite3_mutex_enter(db->mutex);
127523 pOld = db->pTraceArg;
127524 db->xTrace = xTrace;
127525 db->pTraceArg = pArg;
127526 sqlite3_mutex_leave(db->mutex);
@@ -127538,17 +126555,10 @@
127538 sqlite3 *db,
127539 void (*xProfile)(void*,const char*,sqlite_uint64),
127540 void *pArg
127541 ){
127542 void *pOld;
127543
127544 #ifdef SQLITE_ENABLE_API_ARMOR
127545 if( !sqlite3SafetyCheckOk(db) ){
127546 (void)SQLITE_MISUSE_BKPT;
127547 return 0;
127548 }
127549 #endif
127550 sqlite3_mutex_enter(db->mutex);
127551 pOld = db->pProfileArg;
127552 db->xProfile = xProfile;
127553 db->pProfileArg = pArg;
127554 sqlite3_mutex_leave(db->mutex);
@@ -127565,17 +126575,10 @@
127565 sqlite3 *db, /* Attach the hook to this database */
127566 int (*xCallback)(void*), /* Function to invoke on each commit */
127567 void *pArg /* Argument to the function */
127568 ){
127569 void *pOld;
127570
127571 #ifdef SQLITE_ENABLE_API_ARMOR
127572 if( !sqlite3SafetyCheckOk(db) ){
127573 (void)SQLITE_MISUSE_BKPT;
127574 return 0;
127575 }
127576 #endif
127577 sqlite3_mutex_enter(db->mutex);
127578 pOld = db->pCommitArg;
127579 db->xCommitCallback = xCallback;
127580 db->pCommitArg = pArg;
127581 sqlite3_mutex_leave(db->mutex);
@@ -127590,17 +126593,10 @@
127590 sqlite3 *db, /* Attach the hook to this database */
127591 void (*xCallback)(void*,int,char const *,char const *,sqlite_int64),
127592 void *pArg /* Argument to the function */
127593 ){
127594 void *pRet;
127595
127596 #ifdef SQLITE_ENABLE_API_ARMOR
127597 if( !sqlite3SafetyCheckOk(db) ){
127598 (void)SQLITE_MISUSE_BKPT;
127599 return 0;
127600 }
127601 #endif
127602 sqlite3_mutex_enter(db->mutex);
127603 pRet = db->pUpdateArg;
127604 db->xUpdateCallback = xCallback;
127605 db->pUpdateArg = pArg;
127606 sqlite3_mutex_leave(db->mutex);
@@ -127615,17 +126611,10 @@
127615 sqlite3 *db, /* Attach the hook to this database */
127616 void (*xCallback)(void*), /* Callback function */
127617 void *pArg /* Argument to the function */
127618 ){
127619 void *pRet;
127620
127621 #ifdef SQLITE_ENABLE_API_ARMOR
127622 if( !sqlite3SafetyCheckOk(db) ){
127623 (void)SQLITE_MISUSE_BKPT;
127624 return 0;
127625 }
127626 #endif
127627 sqlite3_mutex_enter(db->mutex);
127628 pRet = db->pRollbackArg;
127629 db->xRollbackCallback = xCallback;
127630 db->pRollbackArg = pArg;
127631 sqlite3_mutex_leave(db->mutex);
@@ -127668,13 +126657,10 @@
127668 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
127669 #ifdef SQLITE_OMIT_WAL
127670 UNUSED_PARAMETER(db);
127671 UNUSED_PARAMETER(nFrame);
127672 #else
127673 #ifdef SQLITE_ENABLE_API_ARMOR
127674 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
127675 #endif
127676 if( nFrame>0 ){
127677 sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
127678 }else{
127679 sqlite3_wal_hook(db, 0, 0);
127680 }
@@ -127691,16 +126677,10 @@
127691 int(*xCallback)(void *, sqlite3*, const char*, int),
127692 void *pArg /* First argument passed to xCallback() */
127693 ){
127694 #ifndef SQLITE_OMIT_WAL
127695 void *pRet;
127696 #ifdef SQLITE_ENABLE_API_ARMOR
127697 if( !sqlite3SafetyCheckOk(db) ){
127698 (void)SQLITE_MISUSE_BKPT;
127699 return 0;
127700 }
127701 #endif
127702 sqlite3_mutex_enter(db->mutex);
127703 pRet = db->pWalArg;
127704 db->xWalCallback = xCallback;
127705 db->pWalArg = pArg;
127706 sqlite3_mutex_leave(db->mutex);
@@ -127724,14 +126704,10 @@
127724 return SQLITE_OK;
127725 #else
127726 int rc; /* Return code */
127727 int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
127728
127729 #ifdef SQLITE_ENABLE_API_ARMOR
127730 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
127731 #endif
127732
127733 /* Initialize the output variables to -1 in case an error occurs. */
127734 if( pnLog ) *pnLog = -1;
127735 if( pnCkpt ) *pnCkpt = -1;
127736
127737 assert( SQLITE_CHECKPOINT_FULL>SQLITE_CHECKPOINT_PASSIVE );
@@ -128124,16 +127100,10 @@
128124 ** from forming.
128125 */
128126 SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
128127 int oldLimit;
128128
128129 #ifdef SQLITE_ENABLE_API_ARMOR
128130 if( !sqlite3SafetyCheckOk(db) ){
128131 (void)SQLITE_MISUSE_BKPT;
128132 return -1;
128133 }
128134 #endif
128135
128136 /* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME
128137 ** there is a hard upper bound set at compile-time by a C preprocessor
128138 ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
128139 ** "_MAX_".)
@@ -128206,12 +127176,11 @@
128206 char c;
128207 int nUri = sqlite3Strlen30(zUri);
128208
128209 assert( *pzErrMsg==0 );
128210
128211 if( ((flags & SQLITE_OPEN_URI) /* IMP: R-48725-32206 */
128212 || sqlite3GlobalConfig.bOpenUri) /* IMP: R-51689-46548 */
128213 && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
128214 ){
128215 char *zOpt;
128216 int eState; /* Parser state when parsing URI */
128217 int iIn; /* Input character index */
@@ -128416,13 +127385,10 @@
128416 int rc; /* Return code */
128417 int isThreadsafe; /* True for threadsafe connections */
128418 char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */
128419 char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */
128420
128421 #ifdef SQLITE_ENABLE_API_ARMOR
128422 if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
128423 #endif
128424 *ppDb = 0;
128425 #ifndef SQLITE_OMIT_AUTOINIT
128426 rc = sqlite3_initialize();
128427 if( rc ) return rc;
128428 #endif
@@ -128708,19 +127674,17 @@
128708 ){
128709 char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
128710 sqlite3_value *pVal;
128711 int rc;
128712
128713 #ifdef SQLITE_ENABLE_API_ARMOR
128714 if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
128715 #endif
128716 *ppDb = 0;
128717 #ifndef SQLITE_OMIT_AUTOINIT
128718 rc = sqlite3_initialize();
128719 if( rc ) return rc;
128720 #endif
128721 if( zFilename==0 ) zFilename = "\000\000";
128722 pVal = sqlite3ValueNew(0);
128723 sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC);
128724 zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8);
128725 if( zFilename8 ){
128726 rc = openDatabase(zFilename8, ppDb,
@@ -128746,11 +127710,17 @@
128746 const char *zName,
128747 int enc,
128748 void* pCtx,
128749 int(*xCompare)(void*,int,const void*,int,const void*)
128750 ){
128751 return sqlite3_create_collation_v2(db, zName, enc, pCtx, xCompare, 0);
 
 
 
 
 
 
128752 }
128753
128754 /*
128755 ** Register a new collation sequence with the database handle db.
128756 */
@@ -128761,14 +127731,10 @@
128761 void* pCtx,
128762 int(*xCompare)(void*,int,const void*,int,const void*),
128763 void(*xDel)(void*)
128764 ){
128765 int rc;
128766
128767 #ifdef SQLITE_ENABLE_API_ARMOR
128768 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
128769 #endif
128770 sqlite3_mutex_enter(db->mutex);
128771 assert( !db->mallocFailed );
128772 rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel);
128773 rc = sqlite3ApiExit(db, rc);
128774 sqlite3_mutex_leave(db->mutex);
@@ -128786,14 +127752,10 @@
128786 void* pCtx,
128787 int(*xCompare)(void*,int,const void*,int,const void*)
128788 ){
128789 int rc = SQLITE_OK;
128790 char *zName8;
128791
128792 #ifdef SQLITE_ENABLE_API_ARMOR
128793 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
128794 #endif
128795 sqlite3_mutex_enter(db->mutex);
128796 assert( !db->mallocFailed );
128797 zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
128798 if( zName8 ){
128799 rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
@@ -128812,13 +127774,10 @@
128812 SQLITE_API int sqlite3_collation_needed(
128813 sqlite3 *db,
128814 void *pCollNeededArg,
128815 void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*)
128816 ){
128817 #ifdef SQLITE_ENABLE_API_ARMOR
128818 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
128819 #endif
128820 sqlite3_mutex_enter(db->mutex);
128821 db->xCollNeeded = xCollNeeded;
128822 db->xCollNeeded16 = 0;
128823 db->pCollNeededArg = pCollNeededArg;
128824 sqlite3_mutex_leave(db->mutex);
@@ -128833,13 +127792,10 @@
128833 SQLITE_API int sqlite3_collation_needed16(
128834 sqlite3 *db,
128835 void *pCollNeededArg,
128836 void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*)
128837 ){
128838 #ifdef SQLITE_ENABLE_API_ARMOR
128839 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
128840 #endif
128841 sqlite3_mutex_enter(db->mutex);
128842 db->xCollNeeded = 0;
128843 db->xCollNeeded16 = xCollNeeded16;
128844 db->pCollNeededArg = pCollNeededArg;
128845 sqlite3_mutex_leave(db->mutex);
@@ -128862,16 +127818,10 @@
128862 ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
128863 ** by default. Autocommit is disabled by a BEGIN statement and reenabled
128864 ** by the next COMMIT or ROLLBACK.
128865 */
128866 SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
128867 #ifdef SQLITE_ENABLE_API_ARMOR
128868 if( !sqlite3SafetyCheckOk(db) ){
128869 (void)SQLITE_MISUSE_BKPT;
128870 return 0;
128871 }
128872 #endif
128873 return db->autoCommit;
128874 }
128875
128876 /*
128877 ** The following routines are substitutes for constants SQLITE_CORRUPT,
@@ -129050,13 +128000,10 @@
129050
129051 /*
129052 ** Enable or disable the extended result codes.
129053 */
129054 SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
129055 #ifdef SQLITE_ENABLE_API_ARMOR
129056 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
129057 #endif
129058 sqlite3_mutex_enter(db->mutex);
129059 db->errMask = onoff ? 0xffffffff : 0xff;
129060 sqlite3_mutex_leave(db->mutex);
129061 return SQLITE_OK;
129062 }
@@ -129066,13 +128013,10 @@
129066 */
129067 SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
129068 int rc = SQLITE_ERROR;
129069 Btree *pBtree;
129070
129071 #ifdef SQLITE_ENABLE_API_ARMOR
129072 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
129073 #endif
129074 sqlite3_mutex_enter(db->mutex);
129075 pBtree = sqlite3DbNameToBtree(db, zDbName);
129076 if( pBtree ){
129077 Pager *pPager;
129078 sqlite3_file *fd;
@@ -129411,11 +128355,11 @@
129411 ** query parameter we seek. This routine returns the value of the zParam
129412 ** parameter if it exists. If the parameter does not exist, this routine
129413 ** returns a NULL pointer.
129414 */
129415 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){
129416 if( zFilename==0 || zParam==0 ) return 0;
129417 zFilename += sqlite3Strlen30(zFilename) + 1;
129418 while( zFilename[0] ){
129419 int x = strcmp(zFilename, zParam);
129420 zFilename += sqlite3Strlen30(zFilename) + 1;
129421 if( x==0 ) return zFilename;
@@ -129467,31 +128411,19 @@
129467 /*
129468 ** Return the filename of the database associated with a database
129469 ** connection.
129470 */
129471 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
129472 #ifdef SQLITE_ENABLE_API_ARMOR
129473 if( !sqlite3SafetyCheckOk(db) ){
129474 (void)SQLITE_MISUSE_BKPT;
129475 return 0;
129476 }
129477 #endif
129478 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
129479 return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
129480 }
129481
129482 /*
129483 ** Return 1 if database is read-only or 0 if read/write. Return -1 if
129484 ** no such database exists.
129485 */
129486 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
129487 #ifdef SQLITE_ENABLE_API_ARMOR
129488 if( !sqlite3SafetyCheckOk(db) ){
129489 (void)SQLITE_MISUSE_BKPT;
129490 return -1;
129491 }
129492 #endif
129493 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
129494 return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
129495 }
129496
129497 /************** End of main.c ************************************************/
129498
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.7.2. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -179,11 +179,11 @@
179
180
181 /*
182 ** These no-op macros are used in front of interfaces to mark those
183 ** interfaces as either deprecated or experimental. New applications
184 ** should not use deprecated interfaces - they are support for backwards
185 ** compatibility only. Application writers should be aware that
186 ** experimental interfaces are subject to change in point releases.
187 **
188 ** These macros used to resolve to various kinds of compiler magic that
189 ** would generate warning messages when they were used. But that
@@ -229,13 +229,13 @@
229 **
230 ** See also: [sqlite3_libversion()],
231 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232 ** [sqlite_version()] and [sqlite_source_id()].
233 */
234 #define SQLITE_VERSION "3.8.7.2"
235 #define SQLITE_VERSION_NUMBER 3008007
236 #define SQLITE_SOURCE_ID "2014-11-18 12:28:52 945a9e687fdfee5f7103d85d131024e85d594ac3"
237
238 /*
239 ** CAPI3REF: Run-Time Library Version Numbers
240 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
241 **
@@ -1626,31 +1626,29 @@
1626 ** it is not possible to set the Serialized [threading mode] and
1627 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1628 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1629 **
1630 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1631 ** <dd> ^(This option takes a single argument which is a pointer to an
1632 ** instance of the [sqlite3_mem_methods] structure. The argument specifies
 
1633 ** alternative low-level memory allocation routines to be used in place of
1634 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1635 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1636 ** before the [sqlite3_config()] call returns.</dd>
1637 **
1638 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1639 ** <dd> ^(This option takes a single argument which is a pointer to an
1640 ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
 
1641 ** structure is filled with the currently defined memory allocation routines.)^
1642 ** This option can be used to overload the default memory allocation
1643 ** routines with a wrapper that simulations memory allocation failure or
1644 ** tracks memory usage, for example. </dd>
1645 **
1646 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1647 ** <dd> ^This option takes single argument of type int, interpreted as a
1648 ** boolean, which enables or disables the collection of memory allocation
1649 ** statistics. ^(When memory allocation statistics are disabled, the
1650 ** following SQLite interfaces become non-operational:
1651 ** <ul>
1652 ** <li> [sqlite3_memory_used()]
1653 ** <li> [sqlite3_memory_highwater()]
1654 ** <li> [sqlite3_soft_heap_limit64()]
@@ -1660,90 +1658,78 @@
1658 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1659 ** allocation statistics are disabled by default.
1660 ** </dd>
1661 **
1662 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1663 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1664 ** scratch memory. There are three arguments: A pointer an 8-byte
 
1665 ** aligned memory buffer from which the scratch allocations will be
1666 ** drawn, the size of each scratch allocation (sz),
1667 ** and the maximum number of scratch allocations (N). The sz
1668 ** argument must be a multiple of 16.
1669 ** The first argument must be a pointer to an 8-byte aligned buffer
1670 ** of at least sz*N bytes of memory.
1671 ** ^SQLite will use no more than two scratch buffers per thread. So
1672 ** N should be set to twice the expected maximum number of threads.
1673 ** ^SQLite will never require a scratch buffer that is more than 6
1674 ** times the database page size. ^If SQLite needs needs additional
1675 ** scratch memory beyond what is provided by this configuration option, then
1676 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
 
 
 
 
 
 
1677 **
1678 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1679 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1680 ** the database page cache with the default page cache implementation.
 
1681 ** This configuration should not be used if an application-define page
1682 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option.
1683 ** There are three arguments to this option: A pointer to 8-byte aligned
 
1684 ** memory, the size of each page buffer (sz), and the number of pages (N).
1685 ** The sz argument should be the size of the largest database page
1686 ** (a power of two between 512 and 32768) plus a little extra for each
1687 ** page header. ^The page header size is 20 to 40 bytes depending on
1688 ** the host architecture. ^It is harmless, apart from the wasted memory,
1689 ** to make sz a little too large. The first
1690 ** argument should point to an allocation of at least sz*N bytes of memory.
 
 
 
 
1691 ** ^SQLite will use the memory provided by the first argument to satisfy its
1692 ** memory needs for the first N pages that it adds to cache. ^If additional
1693 ** page cache memory is needed beyond what is provided by this option, then
1694 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1695 ** The pointer in the first argument must
1696 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1697 ** will be undefined.</dd>
1698 **
1699 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1700 ** <dd> ^This option specifies a static memory buffer that SQLite will use
1701 ** for all of its dynamic memory allocation needs beyond those provided
1702 ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1703 ** There are three arguments: An 8-byte aligned pointer to the memory,
 
 
 
 
1704 ** the number of bytes in the memory buffer, and the minimum allocation size.
1705 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1706 ** to using its default memory allocator (the system malloc() implementation),
1707 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1708 ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1709 ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1710 ** allocator is engaged to handle all of SQLites memory allocation needs.
1711 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1712 ** boundary or subsequent behavior of SQLite will be undefined.
1713 ** The minimum allocation size is capped at 2**12. Reasonable values
1714 ** for the minimum allocation size are 2**5 through 2**8.</dd>
1715 **
1716 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1717 ** <dd> ^(This option takes a single argument which is a pointer to an
1718 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1719 ** alternative low-level mutex routines to be used in place
1720 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
1721 ** content of the [sqlite3_mutex_methods] structure before the call to
1722 ** [sqlite3_config()] returns. ^If SQLite is compiled with
1723 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1724 ** the entire mutexing subsystem is omitted from the build and hence calls to
1725 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1726 ** return [SQLITE_ERROR].</dd>
1727 **
1728 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1729 ** <dd> ^(This option takes a single argument which is a pointer to an
1730 ** instance of the [sqlite3_mutex_methods] structure. The
1731 ** [sqlite3_mutex_methods]
1732 ** structure is filled with the currently defined mutex routines.)^
1733 ** This option can be used to overload the default mutex allocation
1734 ** routines with a wrapper used to track mutex usage for performance
1735 ** profiling or testing, for example. ^If SQLite is compiled with
@@ -1751,28 +1737,28 @@
1737 ** the entire mutexing subsystem is omitted from the build and hence calls to
1738 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1739 ** return [SQLITE_ERROR].</dd>
1740 **
1741 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1742 ** <dd> ^(This option takes two arguments that determine the default
1743 ** memory allocation for the lookaside memory allocator on each
1744 ** [database connection]. The first argument is the
1745 ** size of each lookaside buffer slot and the second is the number of
1746 ** slots allocated to each database connection.)^ ^(This option sets the
1747 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1748 ** verb to [sqlite3_db_config()] can be used to change the lookaside
1749 ** configuration on individual connections.)^ </dd>
1750 **
1751 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1752 ** <dd> ^(This option takes a single argument which is a pointer to
1753 ** an [sqlite3_pcache_methods2] object. This object specifies the interface
1754 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the
1755 ** object and uses it for page cache memory allocations.</dd>
1756 **
1757 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1758 ** <dd> ^(This option takes a single argument which is a pointer to an
1759 ** [sqlite3_pcache_methods2] object. SQLite copies of the current
1760 ** page cache implementation into that object.)^ </dd>
1761 **
1762 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1763 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
1764 ** global [error log].
@@ -1792,27 +1778,26 @@
1778 ** supplied by the application must not invoke any SQLite interface.
1779 ** In a multi-threaded application, the application-defined logger
1780 ** function must be threadsafe. </dd>
1781 **
1782 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1783 ** <dd>^(This option takes a single argument of type int. If non-zero, then
1784 ** URI handling is globally enabled. If the parameter is zero, then URI handling
1785 ** is globally disabled.)^ ^If URI handling is globally enabled, all filenames
1786 ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
1787 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1788 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1789 ** connection is opened. ^If it is globally disabled, filenames are
1790 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1791 ** database connection is opened. ^(By default, URI handling is globally
1792 ** disabled. The default value may be changed by compiling with the
1793 ** [SQLITE_USE_URI] symbol defined.)^
1794 **
1795 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1796 ** <dd>^This option takes a single integer argument which is interpreted as
1797 ** a boolean in order to enable or disable the use of covering indices for
1798 ** full table scans in the query optimizer. ^The default setting is determined
 
1799 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
1800 ** if that compile-time option is omitted.
1801 ** The ability to disable the use of covering indices for full table scans
1802 ** is because some incorrectly coded legacy applications might malfunction
1803 ** when the optimization is enabled. Providing the ability to
@@ -1848,32 +1833,23 @@
1833 ** that are the default mmap size limit (the default setting for
1834 ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
1835 ** ^The default setting can be overridden by each database connection using
1836 ** either the [PRAGMA mmap_size] command, or by using the
1837 ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
1838 ** cannot be changed at run-time. Nor may the maximum allowed mmap size
1839 ** exceed the compile-time maximum mmap size set by the
1840 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
1841 ** ^If either argument to this option is negative, then that argument is
1842 ** changed to its compile-time default.
1843 **
1844 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
1845 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1846 ** <dd>^This option is only available if SQLite is compiled for Windows
1847 ** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1848 ** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1849 ** that specifies the maximum size of the created heap.
1850 ** </dl>
 
 
 
 
 
 
 
 
 
1851 */
1852 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1853 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1854 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
1855 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
@@ -1894,11 +1870,10 @@
1870 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1871 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1872 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1873 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1874 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
 
1875
1876 /*
1877 ** CAPI3REF: Database Connection Configuration Options
1878 **
1879 ** These constants are the available integer configuration options that
@@ -2022,49 +1997,51 @@
1997 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
1998
1999 /*
2000 ** CAPI3REF: Count The Number Of Rows Modified
2001 **
2002 ** ^This function returns the number of database rows that were changed
2003 ** or inserted or deleted by the most recently completed SQL statement
2004 ** on the [database connection] specified by the first parameter.
2005 ** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
2006 ** or [DELETE] statement are counted. Auxiliary changes caused by
2007 ** triggers or [foreign key actions] are not counted.)^ Use the
2008 ** [sqlite3_total_changes()] function to find the total number of changes
2009 ** including changes caused by triggers and foreign key actions.
2010 **
2011 ** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
2012 ** are not counted. Only real table changes are counted.
2013 **
2014 ** ^(A "row change" is a change to a single row of a single table
2015 ** caused by an INSERT, DELETE, or UPDATE statement. Rows that
2016 ** are changed as side effects of [REPLACE] constraint resolution,
2017 ** rollback, ABORT processing, [DROP TABLE], or by any other
2018 ** mechanisms do not count as direct row changes.)^
2019 **
2020 ** A "trigger context" is a scope of execution that begins and
2021 ** ends with the script of a [CREATE TRIGGER | trigger].
2022 ** Most SQL statements are
2023 ** evaluated outside of any trigger. This is the "top level"
2024 ** trigger context. If a trigger fires from the top level, a
2025 ** new trigger context is entered for the duration of that one
2026 ** trigger. Subtriggers create subcontexts for their duration.
2027 **
2028 ** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
2029 ** not create a new trigger context.
2030 **
2031 ** ^This function returns the number of direct row changes in the
2032 ** most recent INSERT, UPDATE, or DELETE statement within the same
2033 ** trigger context.
2034 **
2035 ** ^Thus, when called from the top level, this function returns the
2036 ** number of changes in the most recent INSERT, UPDATE, or DELETE
2037 ** that also occurred at the top level. ^(Within the body of a trigger,
2038 ** the sqlite3_changes() interface can be called to find the number of
2039 ** changes in the most recently completed INSERT, UPDATE, or DELETE
2040 ** statement within the body of the same trigger.
2041 ** However, the number returned does not include changes
2042 ** caused by subtriggers since those have their own context.)^
2043 **
2044 ** See also the [sqlite3_total_changes()] interface, the
2045 ** [count_changes pragma], and the [changes() SQL function].
2046 **
2047 ** If a separate thread makes changes on the same database connection
@@ -2074,21 +2051,24 @@
2051 SQLITE_API int sqlite3_changes(sqlite3*);
2052
2053 /*
2054 ** CAPI3REF: Total Number Of Rows Modified
2055 **
2056 ** ^This function returns the number of row changes caused by [INSERT],
2057 ** [UPDATE] or [DELETE] statements since the [database connection] was opened.
2058 ** ^(The count returned by sqlite3_total_changes() includes all changes
2059 ** from all [CREATE TRIGGER | trigger] contexts and changes made by
2060 ** [foreign key actions]. However,
2061 ** the count does not include changes used to implement [REPLACE] constraints,
2062 ** do rollbacks or ABORT processing, or [DROP TABLE] processing. The
2063 ** count does not include rows of views that fire an [INSTEAD OF trigger],
2064 ** though if the INSTEAD OF trigger makes changes of its own, those changes
2065 ** are counted.)^
2066 ** ^The sqlite3_total_changes() function counts the changes as soon as
2067 ** the statement that makes them is completed (when the statement handle
2068 ** is passed to [sqlite3_reset()] or [sqlite3_finalize()]).
2069 **
2070 ** See also the [sqlite3_changes()] interface, the
2071 ** [count_changes pragma], and the [total_changes() SQL function].
2072 **
2073 ** If a separate thread makes changes on the same database connection
2074 ** while [sqlite3_total_changes()] is running then the value
@@ -2562,18 +2542,17 @@
2542 ** already uses the largest possible [ROWID]. The PRNG is also used for
2543 ** the build-in random() and randomblob() SQL functions. This interface allows
2544 ** applications to access the same PRNG for other purposes.
2545 **
2546 ** ^A call to this routine stores N bytes of randomness into buffer P.
2547 ** ^If N is less than one, then P can be a NULL pointer.
2548 **
2549 ** ^If this routine has not been previously called or if the previous
2550 ** call had N less than one, then the PRNG is seeded using randomness
2551 ** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2552 ** ^If the previous call to this routine had an N of 1 or more then
2553 ** the pseudo-randomness is generated
 
2554 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2555 ** method.
2556 */
2557 SQLITE_API void sqlite3_randomness(int N, void *P);
2558
@@ -5784,46 +5763,30 @@
5763 **
5764 ** <pre>
5765 ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
5766 ** </pre>)^
5767 **
 
 
 
 
 
 
5768 ** ^If the flags parameter is non-zero, then the BLOB is opened for read
5769 ** and write access. ^If it is zero, the BLOB is opened for read access.
5770 ** ^It is not possible to open a column that is part of an index or primary
5771 ** key for writing. ^If [foreign key constraints] are enabled, it is
5772 ** not possible to open a column that is part of a [child key] for writing.
5773 **
5774 ** ^Note that the database name is not the filename that contains
5775 ** the database but rather the symbolic name of the database that
5776 ** appears after the AS keyword when the database is connected using [ATTACH].
5777 ** ^For the main database file, the database name is "main".
5778 ** ^For TEMP tables, the database name is "temp".
5779 **
5780 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
5781 ** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set
5782 ** to be a null pointer.)^
5783 ** ^This function sets the [database connection] error code and message
5784 ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related
5785 ** functions. ^Note that the *ppBlob variable is always initialized in a
5786 ** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob
5787 ** regardless of the success or failure of this routine.
 
 
 
 
 
 
 
 
 
 
5788 **
5789 ** ^(If the row that a BLOB handle points to is modified by an
5790 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
5791 ** then the BLOB handle is marked as "expired".
5792 ** This is true if any column of the row is changed, even a column
@@ -5837,13 +5800,17 @@
5800 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
5801 ** the opened blob. ^The size of a blob may not be changed by this
5802 ** interface. Use the [UPDATE] SQL command to change the size of a
5803 ** blob.
5804 **
5805 ** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
5806 ** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
5807 **
5808 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5809 ** and the built-in [zeroblob] SQL function can be used, if desired,
5810 ** to create an empty, zero-filled blob in which to read or write using
5811 ** this interface.
5812 **
5813 ** To avoid a resource leak, every open [BLOB handle] should eventually
5814 ** be released by a call to [sqlite3_blob_close()].
5815 */
5816 SQLITE_API int sqlite3_blob_open(
@@ -5881,26 +5848,28 @@
5848 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5849
5850 /*
5851 ** CAPI3REF: Close A BLOB Handle
5852 **
5853 ** ^Closes an open [BLOB handle].
5854 **
5855 ** ^Closing a BLOB shall cause the current transaction to commit
5856 ** if there are no other BLOBs, no pending prepared statements, and the
5857 ** database connection is in [autocommit mode].
5858 ** ^If any writes were made to the BLOB, they might be held in cache
5859 ** until the close operation if they will fit.
5860 **
5861 ** ^(Closing the BLOB often forces the changes
5862 ** out to disk and so if any I/O errors occur, they will likely occur
5863 ** at the time when the BLOB is closed. Any errors that occur during
5864 ** closing are reported as a non-zero return value.)^
5865 **
5866 ** ^(The BLOB is closed unconditionally. Even if this routine returns
5867 ** an error code, the BLOB is still closed.)^
5868 **
5869 ** ^Calling this routine with a null pointer (such as would be returned
5870 ** by a failed call to [sqlite3_blob_open()]) is a harmless no-op.
5871 */
5872 SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
5873
5874 /*
5875 ** CAPI3REF: Return The Size Of An Open BLOB
@@ -5946,39 +5915,36 @@
5915 SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5916
5917 /*
5918 ** CAPI3REF: Write Data Into A BLOB Incrementally
5919 **
5920 ** ^This function is used to write data into an open [BLOB handle] from a
5921 ** caller-supplied buffer. ^N bytes of data are copied from the buffer Z
5922 ** into the open BLOB, starting at offset iOffset.
 
 
 
 
 
 
5923 **
5924 ** ^If the [BLOB handle] passed as the first argument was not opened for
5925 ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
5926 ** this function returns [SQLITE_READONLY].
5927 **
5928 ** ^This function may only modify the contents of the BLOB; it is
5929 ** not possible to increase the size of a BLOB using this API.
5930 ** ^If offset iOffset is less than N bytes from the end of the BLOB,
5931 ** [SQLITE_ERROR] is returned and no data is written. ^If N is
5932 ** less than zero [SQLITE_ERROR] is returned and no data is written.
5933 ** The size of the BLOB (and hence the maximum value of N+iOffset)
5934 ** can be determined using the [sqlite3_blob_bytes()] interface.
5935 **
5936 ** ^An attempt to write to an expired [BLOB handle] fails with an
5937 ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
5938 ** before the [BLOB handle] expired are not rolled back by the
5939 ** expiration of the handle, though of course those changes might
5940 ** have been overwritten by the statement that expired the BLOB handle
5941 ** or by other independent statements.
5942 **
5943 ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5944 ** Otherwise, an [error code] or an [extended error code] is returned.)^
5945 **
5946 ** This routine only works on a [BLOB handle] which has been created
5947 ** by a prior successful call to [sqlite3_blob_open()] and which has not
5948 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
5949 ** to this routine results in undefined and probably undesirable behavior.
5950 **
@@ -7567,102 +7533,10 @@
7533 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
7534 #define SQLITE_FAIL 3
7535 /* #define SQLITE_ABORT 4 // Also an error code */
7536 #define SQLITE_REPLACE 5
7537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7538
7539
7540 /*
7541 ** Undo the hack that converts floating point types to integer for
7542 ** builds on processors without floating point support.
@@ -8104,13 +7978,14 @@
7978 #ifndef SQLITE_POWERSAFE_OVERWRITE
7979 # define SQLITE_POWERSAFE_OVERWRITE 1
7980 #endif
7981
7982 /*
7983 ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
7984 ** It determines whether or not the features related to
7985 ** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can
7986 ** be overridden at runtime using the sqlite3_config() API.
7987 */
7988 #if !defined(SQLITE_DEFAULT_MEMSTATUS)
7989 # define SQLITE_DEFAULT_MEMSTATUS 1
7990 #endif
7991
@@ -8736,11 +8611,11 @@
8611 ** Estimated quantities used for query planning are stored as 16-bit
8612 ** logarithms. For quantity X, the value stored is 10*log2(X). This
8613 ** gives a possible range of values of approximately 1.0e986 to 1e-986.
8614 ** But the allowed values are "grainy". Not every value is representable.
8615 ** For example, quantities 16 and 17 are both represented by a LogEst
8616 ** of 40. However, since LogEst quantaties are suppose to be estimates,
8617 ** not exact values, this imprecision is not a problem.
8618 **
8619 ** "LogEst" is short for "Logarithmic Estimate".
8620 **
8621 ** Examples:
@@ -9169,11 +9044,11 @@
9044 #define BTREE_BLOBKEY 2 /* Table has keys only - no data */
9045
9046 SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*);
9047 SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*);
9048 SQLITE_PRIVATE int sqlite3BtreeClearTableOfCursor(BtCursor*);
9049 SQLITE_PRIVATE int sqlite3BtreeTripAllCursors(Btree*, int, int);
9050
9051 SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue);
9052 SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
9053
9054 SQLITE_PRIVATE int sqlite3BtreeNewDb(Btree *p);
@@ -9249,11 +9124,10 @@
9124 SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
9125 SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
9126 SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
9127 SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask);
9128 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt);
 
9129
9130 #ifndef NDEBUG
9131 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
9132 #endif
9133
@@ -9792,16 +9666,10 @@
9666 # define VdbeCoverageAlwaysTaken(v)
9667 # define VdbeCoverageNeverTaken(v)
9668 # define VDBE_OFFSET_LINENO(x) 0
9669 #endif
9670
 
 
 
 
 
 
9671 #endif
9672
9673 /************** End of vdbe.h ************************************************/
9674 /************** Continuing where we left off in sqliteInt.h ******************/
9675 /************** Include pager.h in the middle of sqliteInt.h *****************/
@@ -9994,12 +9862,10 @@
9862 SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
9863
9864 /* Functions used to truncate the database file. */
9865 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
9866
 
 
9867 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL)
9868 SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *);
9869 #endif
9870
9871 /* Functions to support testing and debugging. */
@@ -10183,14 +10049,10 @@
10049 SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*);
10050 #endif
10051
10052 SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
10053
 
 
 
 
10054 #endif /* _PCACHE_H_ */
10055
10056 /************** End of pcache.h **********************************************/
10057 /************** Continuing where we left off in sqliteInt.h ******************/
10058
@@ -10873,11 +10735,11 @@
10735 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
10736 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10737 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10738 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
10739 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
10740 #define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */
10741 #define SQLITE_AllOpts 0xffff /* All optimizations */
10742
10743 /*
10744 ** Macros for testing whether or not optimizations are enabled or disabled.
10745 */
@@ -11460,12 +11322,11 @@
11322 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
11323 int nSample; /* Number of elements in aSample[] */
11324 int nSampleCol; /* Size of IndexSample.anEq[] and so on */
11325 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
11326 IndexSample *aSample; /* Samples of the left-most key */
11327 tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this table */
 
11328 #endif
11329 };
11330
11331 /*
11332 ** Allowed values for Index.idxType
@@ -11659,11 +11520,11 @@
11520 int nHeight; /* Height of the tree headed by this node */
11521 #endif
11522 int iTable; /* TK_COLUMN: cursor number of table holding column
11523 ** TK_REGISTER: register number
11524 ** TK_TRIGGER: 1 -> new, 0 -> old
11525 ** EP_Unlikely: 1000 times likelihood */
11526 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
11527 ** TK_VARIABLE: variable number (always >= 1). */
11528 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
11529 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
11530 u8 op2; /* TK_REGISTER: original value of Expr.op
@@ -12551,15 +12412,13 @@
12412 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
12413 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
12414 void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
12415 Parse *pParse; /* Parser context. */
12416 int walkerDepth; /* Number of subqueries */
 
12417 union { /* Extra data for callback */
12418 NameContext *pNC; /* Naming context */
12419 int i; /* Integer value */
 
12420 SrcList *pSrcList; /* FROM clause */
12421 struct SrcCount *pSrcCount; /* Counting column references */
12422 } u;
12423 };
12424
@@ -12956,11 +12815,10 @@
12815 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
12816 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
12817 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
12818 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
12819 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
 
12820 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
12821 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
12822 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
12823 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
12824 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
@@ -13614,23 +13472,15 @@
13472 ** compatibility for legacy applications, the URI filename capability is
13473 ** disabled by default.
13474 **
13475 ** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
13476 ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
 
 
 
 
13477 */
13478 #ifndef SQLITE_USE_URI
13479 # define SQLITE_USE_URI 0
13480 #endif
13481
 
 
 
 
13482 #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
13483 # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
13484 #endif
13485
13486 /*
@@ -13716,12 +13566,12 @@
13566 ** than 1 GiB. The sqlite3_test_control() interface can be used to
13567 ** move the pending byte.
13568 **
13569 ** IMPORTANT: Changing the pending byte to any value other than
13570 ** 0x40000000 results in an incompatible database file format!
13571 ** Changing the pending byte during operating results in undefined
13572 ** and dileterious behavior.
13573 */
13574 #ifndef SQLITE_OMIT_WSD
13575 SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
13576 #endif
13577
@@ -13797,13 +13647,10 @@
13647 "DISABLE_DIRSYNC",
13648 #endif
13649 #ifdef SQLITE_DISABLE_LFS
13650 "DISABLE_LFS",
13651 #endif
 
 
 
13652 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
13653 "ENABLE_ATOMIC_WRITE",
13654 #endif
13655 #ifdef SQLITE_ENABLE_CEROD
13656 "ENABLE_CEROD",
@@ -14125,17 +13972,10 @@
13972 ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
13973 ** is not required for a match.
13974 */
13975 SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
13976 int i, n;
 
 
 
 
 
 
 
13977 if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7;
13978 n = sqlite3Strlen30(zOptName);
13979
13980 /* Since ArraySize(azCompileOpt) is normally in single digits, a
13981 ** linear search is adequate. No need for a binary search. */
@@ -14313,11 +14153,10 @@
14153 typedef struct VdbeFrame VdbeFrame;
14154 struct VdbeFrame {
14155 Vdbe *v; /* VM this frame belongs to */
14156 VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */
14157 Op *aOp; /* Program instructions for parent frame */
 
14158 Mem *aMem; /* Array of memory cells for parent frame */
14159 u8 *aOnceFlag; /* Array of OP_Once flags for parent frame */
14160 VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */
14161 void *token; /* Copy of SubProgram.token */
14162 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
@@ -14326,12 +14165,11 @@
14165 int nOp; /* Size of aOp array */
14166 int nMem; /* Number of entries in aMem */
14167 int nOnceFlag; /* Number of entries in aOnceFlag */
14168 int nChildMem; /* Number of memory cells for child frame */
14169 int nChildCsr; /* Number of cursors for child frame */
14170 int nChange; /* Statement changes (Vdbe.nChanges) */
 
14171 };
14172
14173 #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
14174
14175 /*
@@ -14478,20 +14316,10 @@
14316 /* A bitfield type for use inside of structures. Always follow with :N where
14317 ** N is the number of bits.
14318 */
14319 typedef unsigned bft; /* Bit Field Type */
14320
 
 
 
 
 
 
 
 
 
 
14321 /*
14322 ** An instance of the virtual machine. This structure contains the complete
14323 ** state of the virtual machine.
14324 **
14325 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
@@ -14560,15 +14388,10 @@
14388 u32 expmask; /* Binding to these vars invalidates VM */
14389 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
14390 int nOnceFlag; /* Size of array aOnceFlag[] */
14391 u8 *aOnceFlag; /* Flags for OP_Once */
14392 AuxData *pAuxData; /* Linked list of auxdata allocations */
 
 
 
 
 
14393 };
14394
14395 /*
14396 ** The following are allowed values for Vdbe.magic
14397 */
@@ -14754,13 +14577,10 @@
14577 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
14578 wsdStatInit;
14579 if( op<0 || op>=ArraySize(wsdStat.nowValue) ){
14580 return SQLITE_MISUSE_BKPT;
14581 }
 
 
 
14582 *pCurrent = wsdStat.nowValue[op];
14583 *pHighwater = wsdStat.mxValue[op];
14584 if( resetFlag ){
14585 wsdStat.mxValue[op] = wsdStat.nowValue[op];
14586 }
@@ -14776,15 +14596,10 @@
14596 int *pCurrent, /* Write current value here */
14597 int *pHighwater, /* Write high-water mark here */
14598 int resetFlag /* Reset high-water mark if true */
14599 ){
14600 int rc = SQLITE_OK; /* Return code */
 
 
 
 
 
14601 sqlite3_mutex_enter(db->mutex);
14602 switch( op ){
14603 case SQLITE_DBSTATUS_LOOKASIDE_USED: {
14604 *pCurrent = db->lookaside.nOut;
14605 *pHighwater = db->lookaside.mxOut;
@@ -14959,11 +14774,11 @@
14774 **
14775 ** There is only one exported symbol in this file - the function
14776 ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
14777 ** All other code has file scope.
14778 **
14779 ** SQLite processes all times and dates as Julian Day numbers. The
14780 ** dates and times are stored as the number of days since noon
14781 ** in Greenwich on November 24, 4714 B.C. according to the Gregorian
14782 ** calendar system.
14783 **
14784 ** 1970-01-01 00:00:00 is JD 2440587.5
@@ -14974,11 +14789,11 @@
14789 ** be represented, even though julian day numbers allow a much wider
14790 ** range of dates.
14791 **
14792 ** The Gregorian calendar system is used for all dates and times,
14793 ** even those that predate the Gregorian calendar. Historians usually
14794 ** use the Julian calendar for dates prior to 1582-10-15 and for some
14795 ** dates afterwards, depending on locale. Beware of this difference.
14796 **
14797 ** The conversion algorithms are implemented based on descriptions
14798 ** in the following text:
14799 **
@@ -15246,11 +15061,11 @@
15061 return 1;
15062 }
15063 }
15064
15065 /*
15066 ** Attempt to parse the given string into a Julian Day Number. Return
15067 ** the number of errors.
15068 **
15069 ** The following are acceptable forms for the input string:
15070 **
15071 ** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM
@@ -15817,11 +15632,11 @@
15632 **
15633 ** %d day of month
15634 ** %f ** fractional seconds SS.SSS
15635 ** %H hour 00-24
15636 ** %j day of year 000-366
15637 ** %J ** Julian day number
15638 ** %m month 01-12
15639 ** %M minute 00-59
15640 ** %s seconds since 1970-01-01
15641 ** %S seconds 00-59
15642 ** %w day of week 0-6 sunday==0
@@ -16442,14 +16257,10 @@
16257 MUTEX_LOGIC(sqlite3_mutex *mutex;)
16258 #ifndef SQLITE_OMIT_AUTOINIT
16259 int rc = sqlite3_initialize();
16260 if( rc ) return rc;
16261 #endif
 
 
 
 
16262 MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
16263 sqlite3_mutex_enter(mutex);
16264 vfsUnlink(pVfs);
16265 if( makeDflt || vfsList==0 ){
16266 pVfs->pNext = vfsList;
@@ -18803,11 +18614,10 @@
18614 ** Retrieve a pointer to a static mutex or allocate a new dynamic one.
18615 */
18616 SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){
18617 #ifndef SQLITE_OMIT_AUTOINIT
18618 if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
 
18619 #endif
18620 return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
18621 }
18622
18623 SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){
@@ -19260,16 +19070,12 @@
19070 pthread_mutex_init(&p->mutex, 0);
19071 }
19072 break;
19073 }
19074 default: {
19075 assert( iType-2 >= 0 );
19076 assert( iType-2 < ArraySize(staticMutexes) );
 
 
 
 
19077 p = &staticMutexes[iType-2];
19078 #if SQLITE_MUTEX_NREF
19079 p->id = iType;
19080 #endif
19081 break;
@@ -20487,16 +20293,15 @@
20293 }
20294 assert( sqlite3_mutex_notheld(mem0.mutex) );
20295
20296
20297 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
20298 /* Verify that no more than two scratch allocations per thread
20299 ** are outstanding at one time. (This is only checked in the
20300 ** single-threaded case since checking in the multi-threaded case
20301 ** would be much more complicated.) */
20302 assert( scratchAllocOut<=1 );
 
20303 if( p ) scratchAllocOut++;
20304 #endif
20305
20306 return p;
20307 }
@@ -21151,17 +20956,10 @@
20956 etByte flag_rtz; /* True if trailing zeros should be removed */
20957 #endif
20958 PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
20959 char buf[etBUFSIZE]; /* Conversion buffer */
20960
 
 
 
 
 
 
 
20961 bufpt = 0;
20962 if( bFlags ){
20963 if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
20964 pArgList = va_arg(ap, PrintfArguments*);
20965 }
@@ -21698,15 +21496,10 @@
21496 return N;
21497 }else{
21498 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
21499 i64 szNew = p->nChar;
21500 szNew += N + 1;
 
 
 
 
 
21501 if( szNew > p->mxAlloc ){
21502 sqlite3StrAccumReset(p);
21503 setStrAccumError(p, STRACCUM_TOOBIG);
21504 return 0;
21505 }else{
@@ -21719,11 +21512,10 @@
21512 }
21513 if( zNew ){
21514 assert( p->zText!=0 || p->nChar==0 );
21515 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
21516 p->zText = zNew;
 
21517 }else{
21518 sqlite3StrAccumReset(p);
21519 setStrAccumError(p, STRACCUM_NOMEM);
21520 return 0;
21521 }
@@ -21889,17 +21681,10 @@
21681 */
21682 SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){
21683 char *z;
21684 char zBase[SQLITE_PRINT_BUF_SIZE];
21685 StrAccum acc;
 
 
 
 
 
 
 
21686 #ifndef SQLITE_OMIT_AUTOINIT
21687 if( sqlite3_initialize() ) return 0;
21688 #endif
21689 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
21690 acc.useMalloc = 2;
@@ -21938,17 +21723,10 @@
21723 ** sqlite3_vsnprintf() is the varargs version.
21724 */
21725 SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
21726 StrAccum acc;
21727 if( n<=0 ) return zBuf;
 
 
 
 
 
 
 
21728 sqlite3StrAccumInit(&acc, zBuf, n, 0);
21729 acc.useMalloc = 0;
21730 sqlite3VXPrintf(&acc, 0, zFormat, ap);
21731 return sqlite3StrAccumFinish(&acc);
21732 }
@@ -22136,23 +21914,15 @@
21914 #else
21915 # define wsdPrng sqlite3Prng
21916 #endif
21917
21918 #if SQLITE_THREADSAFE
21919 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
 
 
 
 
 
 
 
 
 
 
21920 sqlite3_mutex_enter(mutex);
21921 #endif
21922
21923 if( N<=0 ){
21924 wsdPrng.isInit = 0;
21925 sqlite3_mutex_leave(mutex);
21926 return;
21927 }
21928
@@ -23270,27 +23040,17 @@
23040 ** case-independent fashion, using the same definition of "case
23041 ** independence" that SQLite uses internally when comparing identifiers.
23042 */
23043 SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){
23044 register unsigned char *a, *b;
 
 
 
 
 
23045 a = (unsigned char *)zLeft;
23046 b = (unsigned char *)zRight;
23047 while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
23048 return UpperToLower[*a] - UpperToLower[*b];
23049 }
23050 SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
23051 register unsigned char *a, *b;
 
 
 
 
 
23052 a = (unsigned char *)zLeft;
23053 b = (unsigned char *)zRight;
23054 while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
23055 return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
23056 }
@@ -32819,15 +32579,10 @@
32579 #if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL)
32580 # error "WAL mode requires support from the Windows NT kernel, compile\
32581 with SQLITE_OMIT_WAL."
32582 #endif
32583
 
 
 
 
 
32584 /*
32585 ** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions
32586 ** based on the sub-platform)?
32587 */
32588 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI)
@@ -32953,15 +32708,14 @@
32708 # define winGetDirSep() '\\'
32709 #endif
32710
32711 /*
32712 ** Do we need to manually define the Win32 file mapping APIs for use with WAL
32713 ** mode (e.g. these APIs are available in the Windows CE SDK; however, they
32714 ** are not present in the header file)?
32715 */
32716 #if SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL)
 
32717 /*
32718 ** Two of the file mapping APIs are different under WinRT. Figure out which
32719 ** set we need.
32720 */
32721 #if SQLITE_OS_WINRT
@@ -32985,11 +32739,11 @@
32739
32740 /*
32741 ** This file mapping API is common to both Win32 and WinRT.
32742 */
32743 WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID);
32744 #endif /* SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL) */
32745
32746 /*
32747 ** Some Microsoft compilers lack this definition.
32748 */
32749 #ifndef INVALID_FILE_ATTRIBUTES
@@ -33278,21 +33032,21 @@
33032
33033 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
33034 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
33035
33036 #if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \
33037 !defined(SQLITE_OMIT_WAL))
33038 { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
33039 #else
33040 { "CreateFileMappingA", (SYSCALL)0, 0 },
33041 #endif
33042
33043 #define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
33044 DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent)
33045
33046 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
33047 !defined(SQLITE_OMIT_WAL))
33048 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
33049 #else
33050 { "CreateFileMappingW", (SYSCALL)0, 0 },
33051 #endif
33052
@@ -33628,12 +33382,11 @@
33382 #ifndef osLockFileEx
33383 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
33384 LPOVERLAPPED))aSyscall[48].pCurrent)
33385 #endif
33386
33387 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
 
33388 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
33389 #else
33390 { "MapViewOfFile", (SYSCALL)0, 0 },
33391 #endif
33392
@@ -33699,11 +33452,11 @@
33452 #endif
33453
33454 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
33455 LPOVERLAPPED))aSyscall[58].pCurrent)
33456
33457 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
33458 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
33459 #else
33460 { "UnmapViewOfFile", (SYSCALL)0, 0 },
33461 #endif
33462
@@ -33762,11 +33515,11 @@
33515 #endif
33516
33517 #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
33518 FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent)
33519
33520 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
33521 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
33522 #else
33523 { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
33524 #endif
33525
@@ -33826,11 +33579,11 @@
33579
33580 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
33581
33582 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent)
33583
33584 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
33585 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
33586 #else
33587 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
33588 #endif
33589
@@ -39402,17 +39155,10 @@
39155 */
39156 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
39157 assert( pCache->pCache!=0 );
39158 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
39159 }
 
 
 
 
 
 
 
39160
39161 #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
39162 /*
39163 ** For all dirty pages currently in the cache, invoke the specified
39164 ** callback. This is only used if the SQLITE_CHECK_PAGES macro is
@@ -40408,15 +40154,10 @@
40154 pcache1Shrink /* xShrink */
40155 };
40156 sqlite3_config(SQLITE_CONFIG_PCACHE2, &defaultMethods);
40157 }
40158
 
 
 
 
 
40159 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40160 /*
40161 ** This function is called to free superfluous dynamically allocated memory
40162 ** held by the pager system. Memory in use by any SQLite pager allocated
40163 ** by the current thread may be sqlite3_free()ed.
@@ -47970,22 +47711,10 @@
47711
47712 return SQLITE_OK;
47713 }
47714 #endif
47715
 
 
 
 
 
 
 
 
 
 
 
 
47716 /*
47717 ** Return a pointer to the data for the specified page.
47718 */
47719 SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *pPg){
47720 assert( pPg->nRef>0 || pPg->pPager->memDb );
@@ -48379,11 +48108,10 @@
48108 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){
48109 assert( pPager->eState>=PAGER_READER );
48110 return sqlite3WalFramesize(pPager->pWal);
48111 }
48112 #endif
 
48113
48114 #endif /* SQLITE_OMIT_DISKIO */
48115
48116 /************** End of pager.c ***********************************************/
48117 /************** Begin file wal.c *********************************************/
@@ -49890,11 +49618,11 @@
49618
49619 /*
49620 ** Free an iterator allocated by walIteratorInit().
49621 */
49622 static void walIteratorFree(WalIterator *p){
49623 sqlite3ScratchFree(p);
49624 }
49625
49626 /*
49627 ** Construct a WalInterator object that can be used to loop over all
49628 ** pages in the WAL in ascending order. The caller must hold the checkpoint
@@ -49925,21 +49653,21 @@
49653 /* Allocate space for the WalIterator object. */
49654 nSegment = walFramePage(iLast) + 1;
49655 nByte = sizeof(WalIterator)
49656 + (nSegment-1)*sizeof(struct WalSegment)
49657 + iLast*sizeof(ht_slot);
49658 p = (WalIterator *)sqlite3ScratchMalloc(nByte);
49659 if( !p ){
49660 return SQLITE_NOMEM;
49661 }
49662 memset(p, 0, nByte);
49663 p->nSegment = nSegment;
49664
49665 /* Allocate temporary space used by the merge-sort routine. This block
49666 ** of memory will be freed before this function returns.
49667 */
49668 aTmp = (ht_slot *)sqlite3ScratchMalloc(
49669 sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
49670 );
49671 if( !aTmp ){
49672 rc = SQLITE_NOMEM;
49673 }
@@ -49972,11 +49700,11 @@
49700 p->aSegment[i].nEntry = nEntry;
49701 p->aSegment[i].aIndex = aIndex;
49702 p->aSegment[i].aPgno = (u32 *)aPgno;
49703 }
49704 }
49705 sqlite3ScratchFree(aTmp);
49706
49707 if( rc!=SQLITE_OK ){
49708 walIteratorFree(p);
49709 }
49710 *pp = p;
@@ -50892,11 +50620,11 @@
50620 ** was in before the client began writing to the database.
50621 */
50622 memcpy(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr));
50623
50624 for(iFrame=pWal->hdr.mxFrame+1;
50625 ALWAYS(rc==SQLITE_OK) && iFrame<=iMax;
50626 iFrame++
50627 ){
50628 /* This call cannot fail. Unless the page for which the page number
50629 ** is passed as the second argument is (a) in the cache and
50630 ** (b) has an outstanding reference, then xUndo is either a no-op
@@ -51989,10 +51717,15 @@
51717 ** but cursors cannot be shared. Each cursor is associated with a
51718 ** particular database connection identified BtCursor.pBtree.db.
51719 **
51720 ** Fields in this structure are accessed under the BtShared.mutex
51721 ** found at self->pBt->mutex.
51722 **
51723 ** skipNext meaning:
51724 ** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op.
51725 ** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op.
51726 ** eState==FAULT: Cursor fault with skipNext as error code.
51727 */
51728 struct BtCursor {
51729 Btree *pBtree; /* The Btree to which this cursor belongs */
51730 BtShared *pBt; /* The BtShared this cursor points to */
51731 BtCursor *pNext, *pPrev; /* Forms a linked list of all cursors */
@@ -52001,11 +51734,12 @@
51734 CellInfo info; /* A parse of the cell we are pointing at */
51735 i64 nKey; /* Size of pKey, or last integer key */
51736 void *pKey; /* Saved key that was cursor last known position */
51737 Pgno pgnoRoot; /* The root page of this tree */
51738 int nOvflAlloc; /* Allocated size of aOverflow[] array */
51739 int skipNext; /* Prev() is noop if negative. Next() is noop if positive.
51740 ** Error code if eState==CURSOR_FAULT */
51741 u8 curFlags; /* zero or more BTCF_* flags defined below */
51742 u8 eState; /* One of the CURSOR_XXX constants (see below) */
51743 u8 hints; /* As configured by CursorSetHints() */
51744 i16 iPage; /* Index of current page in apPage */
51745 u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
@@ -52047,11 +51781,11 @@
51781 ** CURSOR_FAULT:
51782 ** An unrecoverable error (an I/O error or a malloc failure) has occurred
51783 ** on a different connection that shares the BtShared cache with this
51784 ** cursor. The error has left the cache in an inconsistent state.
51785 ** Do nothing else with this cursor. Any attempt to use the cursor
51786 ** should return the error code stored in BtCursor.skipNext
51787 */
51788 #define CURSOR_INVALID 0
51789 #define CURSOR_VALID 1
51790 #define CURSOR_SKIPNEXT 2
51791 #define CURSOR_REQUIRESEEK 3
@@ -53609,27 +53343,28 @@
53343 int cellOffset; /* Offset to the cell pointer array */
53344 int cbrk; /* Offset to the cell content area */
53345 int nCell; /* Number of cells on the page */
53346 unsigned char *data; /* The page data */
53347 unsigned char *temp; /* Temp area for cell content */
 
53348 int iCellFirst; /* First allowable cell index */
53349 int iCellLast; /* Last possible cell index */
53350
53351
53352 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
53353 assert( pPage->pBt!=0 );
53354 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
53355 assert( pPage->nOverflow==0 );
53356 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53357 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
53358 data = pPage->aData;
53359 hdr = pPage->hdrOffset;
53360 cellOffset = pPage->cellOffset;
53361 nCell = pPage->nCell;
53362 assert( nCell==get2byte(&data[hdr+3]) );
53363 usableSize = pPage->pBt->usableSize;
53364 cbrk = get2byte(&data[hdr+5]);
53365 memcpy(&temp[cbrk], &data[cbrk], usableSize - cbrk);
53366 cbrk = usableSize;
53367 iCellFirst = cellOffset + 2*nCell;
53368 iCellLast = usableSize - 4;
53369 for(i=0; i<nCell; i++){
53370 u8 *pAddr; /* The i-th cell pointer */
@@ -53644,11 +53379,11 @@
53379 if( pc<iCellFirst || pc>iCellLast ){
53380 return SQLITE_CORRUPT_BKPT;
53381 }
53382 #endif
53383 assert( pc>=iCellFirst && pc<=iCellLast );
53384 size = cellSizePtr(pPage, &temp[pc]);
53385 cbrk -= size;
53386 #if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
53387 if( cbrk<iCellFirst ){
53388 return SQLITE_CORRUPT_BKPT;
53389 }
@@ -53658,20 +53393,12 @@
53393 }
53394 #endif
53395 assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
53396 testcase( cbrk+size==usableSize );
53397 testcase( pc+size==usableSize );
53398 memcpy(&data[cbrk], &temp[pc], size);
53399 put2byte(pAddr, cbrk);
 
 
 
 
 
 
 
 
 
53400 }
53401 assert( cbrk>=iCellFirst );
53402 put2byte(&data[hdr+5], cbrk);
53403 data[hdr+1] = 0;
53404 data[hdr+2] = 0;
@@ -53682,66 +53409,10 @@
53409 return SQLITE_CORRUPT_BKPT;
53410 }
53411 return SQLITE_OK;
53412 }
53413
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53414 /*
53415 ** Allocate nByte bytes of space from within the B-Tree page passed
53416 ** as the first argument. Write into *pIdx the index into pPage->aData[]
53417 ** of the first byte of allocated space. Return either SQLITE_OK or
53418 ** an error code (usually SQLITE_CORRUPT).
@@ -53755,20 +53426,22 @@
53426 */
53427 static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
53428 const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */
53429 u8 * const data = pPage->aData; /* Local cache of pPage->aData */
53430 int top; /* First byte of cell content area */
 
53431 int gap; /* First byte of gap between cell pointers and cell content */
53432 int rc; /* Integer return code */
53433 int usableSize; /* Usable size of the page */
53434
53435 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
53436 assert( pPage->pBt );
53437 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53438 assert( nByte>=0 ); /* Minimum cell size is 4 */
53439 assert( pPage->nFree>=nByte );
53440 assert( pPage->nOverflow==0 );
53441 usableSize = pPage->pBt->usableSize;
53442 assert( nByte < usableSize-8 );
53443
53444 assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf );
53445 gap = pPage->cellOffset + 2*pPage->nCell;
53446 assert( gap<=65536 );
53447 top = get2byte(&data[hdr+5]);
@@ -53786,27 +53459,46 @@
53459 */
53460 testcase( gap+2==top );
53461 testcase( gap+1==top );
53462 testcase( gap==top );
53463 if( gap+2<=top && (data[hdr+1] || data[hdr+2]) ){
53464 int pc, addr;
53465 for(addr=hdr+1; (pc = get2byte(&data[addr]))>0; addr=pc){
53466 int size; /* Size of the free slot */
53467 if( pc>usableSize-4 || pc<addr+4 ){
53468 return SQLITE_CORRUPT_BKPT;
53469 }
53470 size = get2byte(&data[pc+2]);
53471 if( size>=nByte ){
53472 int x = size - nByte;
53473 testcase( x==4 );
53474 testcase( x==3 );
53475 if( x<4 ){
53476 if( data[hdr+7]>=60 ) goto defragment_page;
53477 /* Remove the slot from the free-list. Update the number of
53478 ** fragmented bytes within the page. */
53479 memcpy(&data[addr], &data[pc], 2);
53480 data[hdr+7] += (u8)x;
53481 }else if( size+pc > usableSize ){
53482 return SQLITE_CORRUPT_BKPT;
53483 }else{
53484 /* The slot remains on the free-list. Reduce its size to account
53485 ** for the portion used by the new allocation. */
53486 put2byte(&data[pc+2], x);
53487 }
53488 *pIdx = pc + x;
53489 return SQLITE_OK;
53490 }
53491 }
53492 }
53493
53494 /* The request could not be fulfilled using a freelist slot. Check
53495 ** to see if defragmentation is necessary.
53496 */
53497 testcase( gap+2+nByte==top );
53498 if( gap+2+nByte>top ){
53499 defragment_page:
53500 testcase( pPage->nCell==0 );
53501 rc = defragmentPage(pPage);
53502 if( rc ) return rc;
53503 top = get2byteNotZero(&data[hdr+5]);
53504 assert( gap+nByte<=top );
@@ -53850,11 +53542,11 @@
53542 unsigned char *data = pPage->aData; /* Page content */
53543
53544 assert( pPage->pBt!=0 );
53545 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
53546 assert( iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
53547 assert( iEnd <= pPage->pBt->usableSize );
53548 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53549 assert( iSize>=4 ); /* Minimum cell size is 4 */
53550 assert( iStart<=iLast );
53551
53552 /* Overwrite deleted information with zeros when the secure_delete
@@ -55972,33 +55664,56 @@
55664 **
55665 ** Every cursor is a candidate to be tripped, including cursors
55666 ** that belong to other database connections that happen to be
55667 ** sharing the cache with pBtree.
55668 **
55669 ** This routine gets called when a rollback occurs. If the writeOnly
55670 ** flag is true, then only write-cursors need be tripped - read-only
55671 ** cursors save their current positions so that they may continue
55672 ** following the rollback. Or, if writeOnly is false, all cursors are
55673 ** tripped. In general, writeOnly is false if the transaction being
55674 ** rolled back modified the database schema. In this case b-tree root
55675 ** pages may be moved or deleted from the database altogether, making
55676 ** it unsafe for read cursors to continue.
55677 **
55678 ** If the writeOnly flag is true and an error is encountered while
55679 ** saving the current position of a read-only cursor, all cursors,
55680 ** including all read-cursors are tripped.
55681 **
55682 ** SQLITE_OK is returned if successful, or if an error occurs while
55683 ** saving a cursor position, an SQLite error code.
55684 */
55685 SQLITE_PRIVATE int sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode, int writeOnly){
55686 BtCursor *p;
55687 int rc = SQLITE_OK;
55688
55689 assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 );
55690 if( pBtree ){
55691 sqlite3BtreeEnter(pBtree);
55692 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
55693 int i;
55694 if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){
55695 if( p->eState==CURSOR_VALID ){
55696 rc = saveCursorPosition(p);
55697 if( rc!=SQLITE_OK ){
55698 (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0);
55699 break;
55700 }
55701 }
55702 }else{
55703 sqlite3BtreeClearCursor(p);
55704 p->eState = CURSOR_FAULT;
55705 p->skipNext = errCode;
55706 }
55707 for(i=0; i<=p->iPage; i++){
55708 releasePage(p->apPage[i]);
55709 p->apPage[i] = 0;
55710 }
55711 }
55712 sqlite3BtreeLeave(pBtree);
55713 }
55714 return rc;
55715 }
55716
55717 /*
55718 ** Rollback the transaction in progress.
55719 **
@@ -56023,11 +55738,13 @@
55738 if( rc ) writeOnly = 0;
55739 }else{
55740 rc = SQLITE_OK;
55741 }
55742 if( tripCode ){
55743 int rc2 = sqlite3BtreeTripAllCursors(p, tripCode, writeOnly);
55744 assert( rc==SQLITE_OK || (writeOnly==0 && rc2==SQLITE_OK) );
55745 if( rc2!=SQLITE_OK ) rc = rc2;
55746 }
55747 btreeIntegrity(p);
55748
55749 if( p->inTrans==TRANS_WRITE ){
55750 int rc2;
@@ -56358,17 +56075,13 @@
56075 **
56076 ** This routine cannot fail. It always returns SQLITE_OK.
56077 */
56078 SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){
56079 assert( cursorHoldsMutex(pCur) );
56080 assert( pCur->eState==CURSOR_VALID );
56081 getCellInfo(pCur);
56082 *pSize = pCur->info.nKey;
 
 
 
 
56083 return SQLITE_OK;
56084 }
56085
56086 /*
56087 ** Set *pSize to the number of bytes of data in the entry the
@@ -58444,266 +58157,49 @@
58157 #endif
58158 }
58159 }
58160
58161 /*
58162 ** Add a list of cells to a page. The page should be initially empty.
58163 ** The cells are guaranteed to fit on the page.
58164 */
58165 static void assemblePage(
58166 MemPage *pPage, /* The page to be assembled */
58167 int nCell, /* The number of cells to add to this page */
58168 u8 **apCell, /* Pointers to cell bodies */
58169 u16 *aSize /* Sizes of the cells */
58170 ){
58171 int i; /* Loop counter */
58172 u8 *pCellptr; /* Address of next cell pointer */
58173 int cellbody; /* Address of next cell body */
58174 u8 * const data = pPage->aData; /* Pointer to data for pPage */
58175 const int hdr = pPage->hdrOffset; /* Offset of header on pPage */
58176 const int nUsable = pPage->pBt->usableSize; /* Usable size of page */
58177
58178 assert( pPage->nOverflow==0 );
58179 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
58180 assert( nCell>=0 && nCell<=(int)MX_CELL(pPage->pBt)
58181 && (int)MX_CELL(pPage->pBt)<=10921);
58182 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
58183
58184 /* Check that the page has just been zeroed by zeroPage() */
58185 assert( pPage->nCell==0 );
58186 assert( get2byteNotZero(&data[hdr+5])==nUsable );
58187
58188 pCellptr = &pPage->aCellIdx[nCell*2];
58189 cellbody = nUsable;
58190 for(i=nCell-1; i>=0; i--){
58191 u16 sz = aSize[i];
58192 pCellptr -= 2;
58193 cellbody -= sz;
58194 put2byte(pCellptr, cellbody);
58195 memcpy(&data[cellbody], apCell[i], sz);
58196 }
58197 put2byte(&data[hdr+3], nCell);
58198 put2byte(&data[hdr+5], cellbody);
58199 pPage->nFree -= (nCell*2 + nUsable - cellbody);
58200 pPage->nCell = (u16)nCell;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58201 }
58202
58203 /*
58204 ** The following parameters determine how many adjacent pages get involved
58205 ** in a balancing operation. NN is the number of neighbors on either side
@@ -58771,12 +58267,11 @@
58267 u8 *pStop;
58268
58269 assert( sqlite3PagerIswriteable(pNew->pDbPage) );
58270 assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
58271 zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF);
58272 assemblePage(pNew, 1, &pCell, &szCell);
 
58273
58274 /* If this is an auto-vacuum database, update the pointer map
58275 ** with entries for the new page, and any pointer from the
58276 ** cell on the page to an overflow page. If either of these
58277 ** operations fails, the return code is set, but the contents
@@ -58991,26 +58486,21 @@
58486 int subtotal; /* Subtotal of bytes in cells on one page */
58487 int iSpace1 = 0; /* First unused byte of aSpace1[] */
58488 int iOvflSpace = 0; /* First unused byte of aOvflSpace[] */
58489 int szScratch; /* Size of scratch memory requested */
58490 MemPage *apOld[NB]; /* pPage and up to two siblings */
58491 MemPage *apCopy[NB]; /* Private copies of apOld[] pages */
58492 MemPage *apNew[NB+2]; /* pPage and up to NB siblings after balancing */
58493 u8 *pRight; /* Location in parent of right-sibling pointer */
58494 u8 *apDiv[NB-1]; /* Divider cells in pParent */
58495 int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */
58496 int szNew[NB+2]; /* Combined size of cells place on i-th page */
 
58497 u8 **apCell = 0; /* All cells begin balanced */
58498 u16 *szCell; /* Local size of all cells in apCell[] */
58499 u8 *aSpace1; /* Space for copies of dividers cells */
58500 Pgno pgno; /* Temp var to store a page number in */
 
 
 
 
58501
 
58502 pBt = pParent->pBt;
58503 assert( sqlite3_mutex_held(pBt->mutex) );
58504 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
58505
58506 #if 0
@@ -59115,18 +58605,16 @@
58605 nMaxCells = (nMaxCells + 3)&~3;
58606
58607 /*
58608 ** Allocate space for memory structures
58609 */
58610 k = pBt->pageSize + ROUND8(sizeof(MemPage));
58611 szScratch =
58612 nMaxCells*sizeof(u8*) /* apCell */
58613 + nMaxCells*sizeof(u16) /* szCell */
58614 + pBt->pageSize /* aSpace1 */
58615 + k*nOld; /* Page copies (apCopy) */
 
 
 
58616 apCell = sqlite3ScratchMalloc( szScratch );
58617 if( apCell==0 ){
58618 rc = SQLITE_NOMEM;
58619 goto balance_cleanup;
58620 }
@@ -59135,12 +58623,12 @@
58623 assert( EIGHT_BYTE_ALIGNMENT(aSpace1) );
58624
58625 /*
58626 ** Load pointers to all cells on sibling pages and the divider cells
58627 ** into the local apCell[] array. Make copies of the divider cells
58628 ** into space obtained from aSpace1[] and remove the divider cells
58629 ** from pParent.
58630 **
58631 ** If the siblings are on leaf pages, then the child pointers of the
58632 ** divider cells are stripped from the cells before they are copied
58633 ** into aSpace1[]. In this way, all cells in apCell[] are without
58634 ** child pointers. If siblings are not leaves, then all cell in
@@ -59152,11 +58640,19 @@
58640 */
58641 leafCorrection = apOld[0]->leaf*4;
58642 leafData = apOld[0]->intKeyLeaf;
58643 for(i=0; i<nOld; i++){
58644 int limit;
58645
58646 /* Before doing anything else, take a copy of the i'th original sibling
58647 ** The rest of this function will use data from the copies rather
58648 ** that the original pages since the original pages will be in the
58649 ** process of being overwritten. */
58650 MemPage *pOld = apCopy[i] = (MemPage*)&aSpace1[pBt->pageSize + k*i];
58651 memcpy(pOld, apOld[i], sizeof(MemPage));
58652 pOld->aData = (void*)&pOld[1];
58653 memcpy(pOld->aData, apOld[i]->aData, pBt->pageSize);
58654
58655 limit = pOld->nCell+pOld->nOverflow;
58656 if( pOld->nOverflow>0 ){
58657 for(j=0; j<limit; j++){
58658 assert( nCell<nMaxCells );
@@ -59173,11 +58669,10 @@
58669 apCell[nCell] = findCellv2(aData, maskPage, cellOffset, j);
58670 szCell[nCell] = cellSizePtr(pOld, apCell[nCell]);
58671 nCell++;
58672 }
58673 }
 
58674 if( i<nOld-1 && !leafData){
58675 u16 sz = (u16)szNew[i];
58676 u8 *pTemp;
58677 assert( nCell<nMaxCells );
58678 szCell[nCell] = sz;
@@ -59225,11 +58720,11 @@
58720 usableSpace = pBt->usableSize - 12 + leafCorrection;
58721 for(subtotal=k=i=0; i<nCell; i++){
58722 assert( i<nMaxCells );
58723 subtotal += szCell[i] + 2;
58724 if( subtotal > usableSpace ){
58725 szNew[k] = subtotal - szCell[i];
58726 cntNew[k] = i;
58727 if( leafData ){ i--; }
58728 subtotal = 0;
58729 k++;
58730 if( k>NB+1 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; }
@@ -59239,14 +58734,13 @@
58734 cntNew[k] = nCell;
58735 k++;
58736
58737 /*
58738 ** The packing computed by the previous block is biased toward the siblings
58739 ** on the left side. The left siblings are always nearly full, while the
58740 ** right-most sibling might be nearly empty. This block of code attempts
58741 ** to adjust the packing of siblings to get a better balance.
 
58742 **
58743 ** This adjustment is more than an optimization. The packing above might
58744 ** be so out of balance as to be illegal. For example, the right-most
58745 ** sibling might be completely empty. This adjustment is not optional.
58746 */
@@ -59271,22 +58765,26 @@
58765 }
58766 szNew[i] = szRight;
58767 szNew[i-1] = szLeft;
58768 }
58769
58770 /* Either we found one or more cells (cntnew[0])>0) or pPage is
58771 ** a virtual root page. A virtual root page is when the real root
58772 ** page is page 1 and we are the only child of that page.
58773 **
58774 ** UPDATE: The assert() below is not necessarily true if the database
58775 ** file is corrupt. The corruption will be detected and reported later
58776 ** in this procedure so there is no need to act upon it now.
58777 */
58778 #if 0
58779 assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) );
58780 #endif
58781
58782 TRACE(("BALANCE: old: %d %d %d ",
58783 apOld[0]->pgno,
58784 nOld>=2 ? apOld[1]->pgno : 0,
58785 nOld>=3 ? apOld[2]->pgno : 0
58786 ));
58787
58788 /*
58789 ** Allocate k new pages. Reuse old pages where possible.
58790 */
@@ -59305,14 +58803,12 @@
58803 if( rc ) goto balance_cleanup;
58804 }else{
58805 assert( i>0 );
58806 rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0);
58807 if( rc ) goto balance_cleanup;
 
58808 apNew[i] = pNew;
58809 nNew++;
 
58810
58811 /* Set the pointer-map entry for the new sibling page. */
58812 if( ISAUTOVACUUM ){
58813 ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc);
58814 if( rc!=SQLITE_OK ){
@@ -59319,248 +58815,140 @@
58815 goto balance_cleanup;
58816 }
58817 }
58818 }
58819 }
58820
58821 /* Free any old pages that were not reused as new pages.
58822 */
58823 while( i<nOld ){
58824 freePage(apOld[i], &rc);
58825 if( rc ) goto balance_cleanup;
58826 releasePage(apOld[i]);
58827 apOld[i] = 0;
58828 i++;
58829 }
58830
58831 /*
58832 ** Put the new pages in ascending order. This helps to
58833 ** keep entries in the disk file in order so that a scan
58834 ** of the table is a linear scan through the file. That
58835 ** in turn helps the operating system to deliver pages
58836 ** from the disk more rapidly.
58837 **
58838 ** An O(n^2) insertion sort algorithm is used, but since
58839 ** n is never more than NB (a small constant), that should
58840 ** not be a problem.
58841 **
58842 ** When NB==3, this one optimization makes the database
58843 ** about 25% faster for large insertions and deletions.
58844 */
58845 for(i=0; i<k-1; i++){
58846 int minV = apNew[i]->pgno;
58847 int minI = i;
58848 for(j=i+1; j<k; j++){
58849 if( apNew[j]->pgno<(unsigned)minV ){
58850 minI = j;
58851 minV = apNew[j]->pgno;
58852 }
58853 }
58854 if( minI>i ){
58855 MemPage *pT;
58856 pT = apNew[i];
58857 apNew[i] = apNew[minI];
58858 apNew[minI] = pT;
58859 }
58860 }
58861 TRACE(("new: %d(%d) %d(%d) %d(%d) %d(%d) %d(%d)\n",
58862 apNew[0]->pgno, szNew[0],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58863 nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0,
 
58864 nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0,
 
58865 nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0,
58866 nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0));
 
 
 
58867
58868 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
58869 put4byte(pRight, apNew[nNew-1]->pgno);
58870
58871 /*
58872 ** Evenly distribute the data in apCell[] across the new pages.
58873 ** Insert divider cells into pParent as necessary.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58874 */
58875 j = 0;
58876 for(i=0; i<nNew; i++){
58877 /* Assemble the new sibling page. */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58878 MemPage *pNew = apNew[i];
58879 assert( j<nMaxCells );
58880 zeroPage(pNew, pageFlags);
58881 assemblePage(pNew, cntNew[i]-j, &apCell[j], &szCell[j]);
58882 assert( pNew->nCell>0 || (nNew==1 && cntNew[0]==0) );
58883 assert( pNew->nOverflow==0 );
58884
58885 j = cntNew[i];
58886
58887 /* If the sibling page assembled above was not the right-most sibling,
58888 ** insert a divider cell into the parent page.
58889 */
58890 assert( i<nNew-1 || j==nCell );
58891 if( j<nCell ){
58892 u8 *pCell;
58893 u8 *pTemp;
58894 int sz;
58895
58896 assert( j<nMaxCells );
58897 pCell = apCell[j];
58898 sz = szCell[j] + leafCorrection;
58899 pTemp = &aOvflSpace[iOvflSpace];
58900 if( !pNew->leaf ){
58901 memcpy(&pNew->aData[8], pCell, 4);
58902 }else if( leafData ){
58903 /* If the tree is a leaf-data tree, and the siblings are leaves,
58904 ** then there is no divider cell in apCell[]. Instead, the divider
58905 ** cell consists of the integer key for the right-most cell of
58906 ** the sibling-page assembled above only.
58907 */
58908 CellInfo info;
58909 j--;
58910 btreeParseCellPtr(pNew, apCell[j], &info);
58911 pCell = pTemp;
58912 sz = 4 + putVarint(&pCell[4], info.nKey);
58913 pTemp = 0;
58914 }else{
58915 pCell -= 4;
58916 /* Obscure case for non-leaf-data trees: If the cell at pCell was
58917 ** previously stored on a leaf node, and its reported size was 4
58918 ** bytes, then it may actually be smaller than this
58919 ** (see btreeParseCellPtr(), 4 bytes is the minimum size of
58920 ** any cell). But it is important to pass the correct size to
58921 ** insertCell(), so reparse the cell now.
58922 **
58923 ** Note that this can never happen in an SQLite data file, as all
58924 ** cells are at least 4 bytes. It only happens in b-trees used
58925 ** to evaluate "IN (SELECT ...)" and similar clauses.
58926 */
58927 if( szCell[j]==4 ){
58928 assert(leafCorrection==4);
58929 sz = cellSizePtr(pParent, pCell);
58930 }
58931 }
58932 iOvflSpace += sz;
58933 assert( sz<=pBt->maxLocal+23 );
58934 assert( iOvflSpace <= (int)pBt->pageSize );
58935 insertCell(pParent, nxDiv, pCell, sz, pTemp, pNew->pgno, &rc);
58936 if( rc!=SQLITE_OK ) goto balance_cleanup;
58937 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
58938
58939 j++;
58940 nxDiv++;
58941 }
58942 }
58943 assert( j==nCell );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58944 assert( nOld>0 );
58945 assert( nNew>0 );
58946 if( (pageFlags & PTF_LEAF)==0 ){
58947 u8 *zChild = &apCopy[nOld-1]->aData[8];
58948 memcpy(&apNew[nNew-1]->aData[8], zChild, 4);
58949 }
58950
58951 if( isRoot && pParent->nCell==0 && pParent->hdrOffset<=apNew[0]->nFree ){
58952 /* The root page of the b-tree now contains no cells. The only sibling
58953 ** page is the right-child of the parent. Copy the contents of the
58954 ** child page into the parent, decreasing the overall height of the
@@ -59569,54 +58957,130 @@
58957 **
58958 ** If this is an auto-vacuum database, the call to copyNodeContent()
58959 ** sets all pointer-map entries corresponding to database image pages
58960 ** for which the pointer is stored within the content being copied.
58961 **
58962 ** The second assert below verifies that the child page is defragmented
58963 ** (it must be, as it was just reconstructed using assemblePage()). This
58964 ** is important if the parent page happens to be page 1 of the database
58965 ** image. */
 
58966 assert( nNew==1 );
 
 
58967 assert( apNew[0]->nFree ==
58968 (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
 
58969 );
58970 copyNodeContent(apNew[0], pParent, &rc);
58971 freePage(apNew[0], &rc);
58972 }else if( ISAUTOVACUUM ){
58973 /* Fix the pointer-map entries for all the cells that were shifted around.
58974 ** There are several different types of pointer-map entries that need to
58975 ** be dealt with by this routine. Some of these have been set already, but
58976 ** many have not. The following is a summary:
58977 **
58978 ** 1) The entries associated with new sibling pages that were not
58979 ** siblings when this function was called. These have already
58980 ** been set. We don't need to worry about old siblings that were
58981 ** moved to the free-list - the freePage() code has taken care
58982 ** of those.
58983 **
58984 ** 2) The pointer-map entries associated with the first overflow
58985 ** page in any overflow chains used by new divider cells. These
58986 ** have also already been taken care of by the insertCell() code.
58987 **
58988 ** 3) If the sibling pages are not leaves, then the child pages of
58989 ** cells stored on the sibling pages may need to be updated.
58990 **
58991 ** 4) If the sibling pages are not internal intkey nodes, then any
58992 ** overflow pages used by these cells may need to be updated
58993 ** (internal intkey nodes never contain pointers to overflow pages).
58994 **
58995 ** 5) If the sibling pages are not leaves, then the pointer-map
58996 ** entries for the right-child pages of each sibling may need
58997 ** to be updated.
58998 **
58999 ** Cases 1 and 2 are dealt with above by other code. The next
59000 ** block deals with cases 3 and 4 and the one after that, case 5. Since
59001 ** setting a pointer map entry is a relatively expensive operation, this
59002 ** code only sets pointer map entries for child or overflow pages that have
59003 ** actually moved between pages. */
59004 MemPage *pNew = apNew[0];
59005 MemPage *pOld = apCopy[0];
59006 int nOverflow = pOld->nOverflow;
59007 int iNextOld = pOld->nCell + nOverflow;
59008 int iOverflow = (nOverflow ? pOld->aiOvfl[0] : -1);
59009 j = 0; /* Current 'old' sibling page */
59010 k = 0; /* Current 'new' sibling page */
59011 for(i=0; i<nCell; i++){
59012 int isDivider = 0;
59013 while( i==iNextOld ){
59014 /* Cell i is the cell immediately following the last cell on old
59015 ** sibling page j. If the siblings are not leaf pages of an
59016 ** intkey b-tree, then cell i was a divider cell. */
59017 assert( j+1 < ArraySize(apCopy) );
59018 assert( j+1 < nOld );
59019 pOld = apCopy[++j];
59020 iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow;
59021 if( pOld->nOverflow ){
59022 nOverflow = pOld->nOverflow;
59023 iOverflow = i + !leafData + pOld->aiOvfl[0];
59024 }
59025 isDivider = !leafData;
59026 }
59027
59028 assert(nOverflow>0 || iOverflow<i );
59029 assert(nOverflow<2 || pOld->aiOvfl[0]==pOld->aiOvfl[1]-1);
59030 assert(nOverflow<3 || pOld->aiOvfl[1]==pOld->aiOvfl[2]-1);
59031 if( i==iOverflow ){
59032 isDivider = 1;
59033 if( (--nOverflow)>0 ){
59034 iOverflow++;
59035 }
59036 }
59037
59038 if( i==cntNew[k] ){
59039 /* Cell i is the cell immediately following the last cell on new
59040 ** sibling page k. If the siblings are not leaf pages of an
59041 ** intkey b-tree, then cell i is a divider cell. */
59042 pNew = apNew[++k];
59043 if( !leafData ) continue;
59044 }
59045 assert( j<nOld );
59046 assert( k<nNew );
59047
59048 /* If the cell was originally divider cell (and is not now) or
59049 ** an overflow cell, or if the cell was located on a different sibling
59050 ** page before the balancing, then the pointer map entries associated
59051 ** with any child or overflow pages need to be updated. */
59052 if( isDivider || pOld->pgno!=pNew->pgno ){
59053 if( !leafCorrection ){
59054 ptrmapPut(pBt, get4byte(apCell[i]), PTRMAP_BTREE, pNew->pgno, &rc);
59055 }
59056 if( szCell[i]>pNew->minLocal ){
59057 ptrmapPutOvflPtr(pNew, apCell[i], &rc);
59058 }
59059 }
59060 }
59061
59062 if( !leafCorrection ){
59063 for(i=0; i<nNew; i++){
59064 u32 key = get4byte(&apNew[i]->aData[8]);
59065 ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc);
59066 }
59067 }
59068
59069 #if 0
 
59070 /* The ptrmapCheckPages() contains assert() statements that verify that
59071 ** all pointer map pages are set correctly. This is helpful while
59072 ** debugging. This is usually disabled because a corrupt database may
59073 ** cause an assert() statement to fail. */
59074 ptrmapCheckPages(apNew, nNew);
59075 ptrmapCheckPages(&pParent, 1);
59076 #endif
59077 }
59078
59079 assert( pParent->isInit );
59080 TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n",
59081 nOld, nNew, nCell));
59082
59083 /*
59084 ** Cleanup before returning.
59085 */
59086 balance_cleanup:
@@ -61438,15 +60902,10 @@
60902 */
60903 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){
60904 return (p->pBt->btsFlags & BTS_READ_ONLY)!=0;
60905 }
60906
 
 
 
 
 
60907 /************** End of btree.c ***********************************************/
60908 /************** Begin file backup.c ******************************************/
60909 /*
60910 ** 2009 January 28
60911 **
@@ -61583,17 +61042,10 @@
61042 sqlite3* pSrcDb, /* Database connection to read from */
61043 const char *zSrcDb /* Name of database within pSrcDb */
61044 ){
61045 sqlite3_backup *p; /* Value to return */
61046
 
 
 
 
 
 
 
61047 /* Lock the source database handle. The destination database
61048 ** handle is not locked in this routine, but it is locked in
61049 ** sqlite3_backup_step(). The user is required to ensure that no
61050 ** other thread accesses the destination handle for the duration
61051 ** of the backup operation. Any attempt to use the destination
@@ -61786,13 +61238,10 @@
61238 int rc;
61239 int destMode; /* Destination journal mode */
61240 int pgszSrc = 0; /* Source page size */
61241 int pgszDest = 0; /* Destination page size */
61242
 
 
 
61243 sqlite3_mutex_enter(p->pSrcDb->mutex);
61244 sqlite3BtreeEnter(p->pSrc);
61245 if( p->pDestDb ){
61246 sqlite3_mutex_enter(p->pDestDb->mutex);
61247 }
@@ -62078,30 +61527,18 @@
61527 /*
61528 ** Return the number of pages still to be backed up as of the most recent
61529 ** call to sqlite3_backup_step().
61530 */
61531 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p){
 
 
 
 
 
 
61532 return p->nRemaining;
61533 }
61534
61535 /*
61536 ** Return the total number of pages in the source database as of the most
61537 ** recent call to sqlite3_backup_step().
61538 */
61539 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p){
 
 
 
 
 
 
61540 return p->nPagecount;
61541 }
61542
61543 /*
61544 ** This function is called after the contents of page iPage of the
@@ -64388,38 +63825,10 @@
63825 }
63826 p->nOp += nOp;
63827 }
63828 return addr;
63829 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63830
63831 /*
63832 ** Change the value of the P1 operand for a specific instruction.
63833 ** This routine is useful when a large program is loaded from a
63834 ** static array using sqlite3VdbeAddOpList but we want to make a
@@ -65515,13 +64924,10 @@
64924 p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte);
64925 p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte);
64926 p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*),
64927 &zCsr, zEnd, &nByte);
64928 p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, &zCsr, zEnd, &nByte);
 
 
 
64929 if( nByte ){
64930 p->pFree = sqlite3DbMallocZero(db, nByte);
64931 }
64932 zCsr = p->pFree;
64933 zEnd = &zCsr[nByte];
@@ -65585,13 +64991,10 @@
64991 ** is used, for example, when a trigger sub-program is halted to restore
64992 ** control to the main program.
64993 */
64994 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
64995 Vdbe *v = pFrame->v;
 
 
 
64996 v->aOnceFlag = pFrame->aOnceFlag;
64997 v->nOnceFlag = pFrame->nOnceFlag;
64998 v->aOp = pFrame->aOp;
64999 v->nOp = pFrame->nOp;
65000 v->aMem = pFrame->aMem;
@@ -65598,11 +65001,10 @@
65001 v->nMem = pFrame->nMem;
65002 v->apCsr = pFrame->apCsr;
65003 v->nCursor = pFrame->nCursor;
65004 v->db->lastRowid = pFrame->lastRowid;
65005 v->nChange = pFrame->nChange;
 
65006 return pFrame->pc;
65007 }
65008
65009 /*
65010 ** Close all cursors.
@@ -66166,11 +65568,10 @@
65568 ** so, abort any other statements this handle currently has active.
65569 */
65570 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
65571 sqlite3CloseSavepoints(db);
65572 db->autoCommit = 1;
 
65573 }
65574 }
65575 }
65576
65577 /* Check for immediate foreign key violations. */
@@ -66207,20 +65608,18 @@
65608 sqlite3VdbeLeave(p);
65609 return SQLITE_BUSY;
65610 }else if( rc!=SQLITE_OK ){
65611 p->rc = rc;
65612 sqlite3RollbackAll(db, SQLITE_OK);
 
65613 }else{
65614 db->nDeferredCons = 0;
65615 db->nDeferredImmCons = 0;
65616 db->flags &= ~SQLITE_DeferFKs;
65617 sqlite3CommitInternalChanges(db);
65618 }
65619 }else{
65620 sqlite3RollbackAll(db, SQLITE_OK);
 
65621 }
65622 db->nStatement = 0;
65623 }else if( eStatementOp==0 ){
65624 if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){
65625 eStatementOp = SAVEPOINT_RELEASE;
@@ -66228,11 +65627,10 @@
65627 eStatementOp = SAVEPOINT_ROLLBACK;
65628 }else{
65629 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
65630 sqlite3CloseSavepoints(db);
65631 db->autoCommit = 1;
 
65632 }
65633 }
65634
65635 /* If eStatementOp is non-zero, then a statement transaction needs to
65636 ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
@@ -66249,11 +65647,10 @@
65647 p->zErrMsg = 0;
65648 }
65649 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
65650 sqlite3CloseSavepoints(db);
65651 db->autoCommit = 1;
 
65652 }
65653 }
65654
65655 /* If this was an INSERT, UPDATE or DELETE and no statement transaction
65656 ** has been rolled back, update the database connection change-counter.
@@ -66511,16 +65908,10 @@
65908 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
65909 vdbeFreeOpArray(db, p->aOp, p->nOp);
65910 sqlite3DbFree(db, p->aColName);
65911 sqlite3DbFree(db, p->zSql);
65912 sqlite3DbFree(db, p->pFree);
 
 
 
 
 
 
65913 }
65914
65915 /*
65916 ** Delete an entire VDBE.
65917 */
@@ -68884,23 +68275,15 @@
68275 sqlite3_stmt *pStmt,
68276 int N,
68277 const void *(*xFunc)(Mem*),
68278 int useType
68279 ){
68280 const void *ret = 0;
68281 Vdbe *p = (Vdbe *)pStmt;
68282 int n;
68283 sqlite3 *db = p->db;
68284
 
 
 
 
 
 
 
 
68285 assert( db!=0 );
68286 n = sqlite3_column_count(pStmt);
68287 if( N<n && N>=0 ){
68288 N += useType*n;
68289 sqlite3_mutex_enter(db->mutex);
@@ -69361,16 +68744,10 @@
68744 ** prepared statement for the database connection. Return NULL if there
68745 ** are no more.
68746 */
68747 SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){
68748 sqlite3_stmt *pNext;
 
 
 
 
 
 
68749 sqlite3_mutex_enter(pDb->mutex);
68750 if( pStmt==0 ){
68751 pNext = (sqlite3_stmt*)pDb->pVdbe;
68752 }else{
68753 pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pNext;
@@ -69382,91 +68759,15 @@
68759 /*
68760 ** Return the value of a status counter for a prepared statement
68761 */
68762 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){
68763 Vdbe *pVdbe = (Vdbe*)pStmt;
68764 u32 v = pVdbe->aCounter[op];
 
 
 
 
 
 
 
68765 if( resetFlag ) pVdbe->aCounter[op] = 0;
68766 return (int)v;
68767 }
68768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68769 /************** End of vdbeapi.c *********************************************/
68770 /************** Begin file vdbetrace.c ***************************************/
68771 /*
68772 ** 2009 November 25
68773 **
@@ -70348,13 +69649,10 @@
69649 #ifdef VDBE_PROFILE
69650 start = sqlite3Hwtime();
69651 #endif
69652 nVmStep++;
69653 pOp = &aOp[pc];
 
 
 
69654
69655 /* Only allow tracing if SQLITE_DEBUG is defined.
69656 */
69657 #ifdef SQLITE_DEBUG
69658 if( db->flags & SQLITE_VdbeTrace ){
@@ -72570,12 +71868,14 @@
71868 int isSchemaChange;
71869 iSavepoint = db->nSavepoint - iSavepoint - 1;
71870 if( p1==SAVEPOINT_ROLLBACK ){
71871 isSchemaChange = (db->flags & SQLITE_InternChanges)!=0;
71872 for(ii=0; ii<db->nDb; ii++){
71873 rc = sqlite3BtreeTripAllCursors(db->aDb[ii].pBt,
71874 SQLITE_ABORT_ROLLBACK,
71875 isSchemaChange==0);
71876 if( rc!=SQLITE_OK ) goto abort_due_to_error;
71877 }
71878 }else{
71879 isSchemaChange = 0;
71880 }
71881 for(ii=0; ii<db->nDb; ii++){
@@ -73543,15 +72843,14 @@
72843 }
72844 pIdxKey = &r;
72845 }else{
72846 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
72847 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
72848 );
72849 if( pIdxKey==0 ) goto no_mem;
72850 assert( pIn3->flags & MEM_Blob );
72851 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
 
72852 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
72853 }
72854 pIdxKey->default_rc = 0;
72855 if( pOp->opcode==OP_NoConflict ){
72856 /* For the OP_NoConflict opcode, take the jump if any of the
@@ -74147,10 +73446,14 @@
73446 #endif /* SQLITE_OMIT_VIRTUALTABLE */
73447 }else{
73448 assert( pC->pCursor!=0 );
73449 rc = sqlite3VdbeCursorRestore(pC);
73450 if( rc ) goto abort_due_to_error;
73451 if( pC->nullRow ){
73452 pOut->flags = MEM_Null;
73453 break;
73454 }
73455 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
73456 assert( rc==SQLITE_OK ); /* Always so because of CursorRestore() above */
73457 }
73458 pOut->u.i = v;
73459 break;
@@ -74237,13 +73540,13 @@
73540 }
73541 /* Opcode: Rewind P1 P2 * * *
73542 **
73543 ** The next use of the Rowid or Column or Next instruction for P1
73544 ** will refer to the first entry in the database table or index.
73545 ** If the table or index is empty and P2>0, then jump immediately to P2.
73546 ** If P2 is 0 or if the table or index is not empty, fall through
73547 ** to the following instruction.
73548 **
73549 ** This opcode leaves the cursor configured to move in forward order,
73550 ** from the beginning toward the end. In other words, the cursor is
73551 ** configured to use Next, not Prev.
73552 */
@@ -75155,13 +74458,10 @@
74458 pFrame->aOp = p->aOp;
74459 pFrame->nOp = p->nOp;
74460 pFrame->token = pProgram->token;
74461 pFrame->aOnceFlag = p->aOnceFlag;
74462 pFrame->nOnceFlag = p->nOnceFlag;
 
 
 
74463
74464 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
74465 for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
74466 pMem->flags = MEM_Undefined;
74467 pMem->db = db;
@@ -75175,11 +74475,10 @@
74475
74476 p->nFrame++;
74477 pFrame->pParent = p->pFrame;
74478 pFrame->lastRowid = lastRowid;
74479 pFrame->nChange = p->nChange;
 
74480 p->nChange = 0;
74481 p->pFrame = pFrame;
74482 p->aMem = aMem = &VdbeFrameMem(pFrame)[-1];
74483 p->nMem = pFrame->nChildMem;
74484 p->nCursor = (u16)pFrame->nChildCsr;
@@ -75186,13 +74485,10 @@
74485 p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
74486 p->aOp = aOp = pProgram->aOp;
74487 p->nOp = pProgram->nOp;
74488 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
74489 p->nOnceFlag = pProgram->nOnce;
 
 
 
74490 pc = -1;
74491 memset(p->aOnceFlag, 0, p->nOnceFlag);
74492
74493 break;
74494 }
@@ -76377,15 +75673,10 @@
75673 char *zErr = 0;
75674 Table *pTab;
75675 Parse *pParse = 0;
75676 Incrblob *pBlob = 0;
75677
 
 
 
 
 
75678 flags = !!flags; /* flags = (flags ? 1 : 0); */
75679 *ppBlob = 0;
75680
75681 sqlite3_mutex_enter(db->mutex);
75682
@@ -76600,10 +75891,11 @@
75891 v = (Vdbe*)p->pStmt;
75892
75893 if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){
75894 /* Request is out of range. Return a transient error. */
75895 rc = SQLITE_ERROR;
75896 sqlite3Error(db, SQLITE_ERROR);
75897 }else if( v==0 ){
75898 /* If there is no statement handle, then the blob-handle has
75899 ** already been invalidated. Return SQLITE_ABORT in this case.
75900 */
75901 rc = SQLITE_ABORT;
@@ -76617,14 +75909,14 @@
75909 sqlite3BtreeLeaveCursor(p->pCsr);
75910 if( rc==SQLITE_ABORT ){
75911 sqlite3VdbeFinalize(v);
75912 p->pStmt = 0;
75913 }else{
75914 db->errCode = rc;
75915 v->rc = rc;
75916 }
75917 }
 
75918 rc = sqlite3ApiExit(db, rc);
75919 sqlite3_mutex_leave(db->mutex);
75920 return rc;
75921 }
75922
@@ -76797,11 +76089,11 @@
76089 ** itself.
76090 **
76091 ** The sorter is running in multi-threaded mode if (a) the library was built
76092 ** with pre-processor symbol SQLITE_MAX_WORKER_THREADS set to a value greater
76093 ** than zero, and (b) worker threads have been enabled at runtime by calling
76094 ** sqlite3_config(SQLITE_CONFIG_WORKER_THREADS, ...).
76095 **
76096 ** When Rewind() is called, any data remaining in memory is flushed to a
76097 ** final PMA. So at this point the data is stored in some number of sorted
76098 ** PMAs within temporary files on disk.
76099 **
@@ -77542,13 +76834,15 @@
76834 pSorter->mnPmaSize = SORTER_MIN_WORKING * pgsz;
76835 mxCache = db->aDb[0].pSchema->cache_size;
76836 if( mxCache<SORTER_MIN_WORKING ) mxCache = SORTER_MIN_WORKING;
76837 pSorter->mxPmaSize = mxCache * pgsz;
76838
76839 /* If the application has not configure scratch memory using
76840 ** SQLITE_CONFIG_SCRATCH then we assume it is OK to do large memory
76841 ** allocations. If scratch memory has been configured, then assume
76842 ** large memory allocations should be avoided to prevent heap
76843 ** fragmentation.
76844 */
76845 if( sqlite3GlobalConfig.pScratch==0 ){
76846 assert( pSorter->iMemory==0 );
76847 pSorter->nMemory = pgsz;
76848 pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
@@ -79916,19 +79210,19 @@
79210 **
79211 ** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..)
79212 ** is a helper function - a callback for the tree walker.
79213 */
79214 static int incrAggDepth(Walker *pWalker, Expr *pExpr){
79215 if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.i;
79216 return WRC_Continue;
79217 }
79218 static void incrAggFunctionDepth(Expr *pExpr, int N){
79219 if( N>0 ){
79220 Walker w;
79221 memset(&w, 0, sizeof(w));
79222 w.xExprCallback = incrAggDepth;
79223 w.u.i = N;
79224 sqlite3WalkExpr(&w, pExpr);
79225 }
79226 }
79227
79228 /*
@@ -80472,11 +79766,11 @@
79766 double r = -1.0;
79767 if( p->op!=TK_FLOAT ) return -1;
79768 sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
79769 assert( r>=0.0 );
79770 if( r>1.0 ) return -1;
79771 return (int)(r*1000.0);
79772 }
79773
79774 /*
79775 ** This routine is callback for sqlite3WalkExpr().
79776 **
@@ -80604,11 +79898,11 @@
79898 ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand for
79899 ** likelihood(X,0.9375).
79900 ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent to
79901 ** likelihood(X,0.9375). */
79902 /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
79903 pExpr->iTable = pDef->zName[0]=='u' ? 62 : 938;
79904 }
79905 }
79906 #ifndef SQLITE_OMIT_AUTHORIZATION
79907 auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
79908 if( auth!=SQLITE_OK ){
@@ -82561,79 +81855,69 @@
81855 sqlite3DbFree(db, pList->a);
81856 sqlite3DbFree(db, pList);
81857 }
81858
81859 /*
81860 ** These routines are Walker callbacks. Walker.u.pi is a pointer
81861 ** to an integer. These routines are checking an expression to see
81862 ** if it is a constant. Set *Walker.u.i to 0 if the expression is
81863 ** not constant.
81864 **
81865 ** These callback routines are used to implement the following:
81866 **
81867 ** sqlite3ExprIsConstant() pWalker->u.i==1
81868 ** sqlite3ExprIsConstantNotJoin() pWalker->u.i==2
81869 ** sqlite3ExprIsConstantOrFunction() pWalker->u.i==3 or 4
 
 
 
 
81870 **
81871 ** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions
81872 ** in a CREATE TABLE statement. The Walker.u.i value is 4 when parsing
81873 ** an existing schema and 3 when processing a new statement. A bound
81874 ** parameter raises an error for new statements, but is silently converted
81875 ** to NULL for existing schemas. This allows sqlite_master tables that
81876 ** contain a bound parameter because they were generated by older versions
81877 ** of SQLite to be parsed by newer versions of SQLite without raising a
81878 ** malformed schema error.
81879 */
81880 static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
81881
81882 /* If pWalker->u.i is 2 then any term of the expression that comes from
81883 ** the ON or USING clauses of a join disqualifies the expression
81884 ** from being considered constant. */
81885 if( pWalker->u.i==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
81886 pWalker->u.i = 0;
81887 return WRC_Abort;
81888 }
81889
81890 switch( pExpr->op ){
81891 /* Consider functions to be constant if all their arguments are constant
81892 ** and either pWalker->u.i==3 or 4 or the function as the SQLITE_FUNC_CONST
81893 ** flag. */
81894 case TK_FUNCTION:
81895 if( pWalker->u.i>=3 || ExprHasProperty(pExpr,EP_Constant) ){
81896 return WRC_Continue;
 
 
 
81897 }
81898 /* Fall through */
81899 case TK_ID:
81900 case TK_COLUMN:
81901 case TK_AGG_FUNCTION:
81902 case TK_AGG_COLUMN:
81903 testcase( pExpr->op==TK_ID );
81904 testcase( pExpr->op==TK_COLUMN );
81905 testcase( pExpr->op==TK_AGG_FUNCTION );
81906 testcase( pExpr->op==TK_AGG_COLUMN );
81907 pWalker->u.i = 0;
81908 return WRC_Abort;
 
 
 
 
81909 case TK_VARIABLE:
81910 if( pWalker->u.i==4 ){
81911 /* Silently convert bound parameters that appear inside of CREATE
81912 ** statements into a NULL when parsing the CREATE statement text out
81913 ** of the sqlite_master table */
81914 pExpr->op = TK_NULL;
81915 }else if( pWalker->u.i==3 ){
81916 /* A bound parameter in a CREATE statement that originates from
81917 ** sqlite3_prepare() causes an error */
81918 pWalker->u.i = 0;
81919 return WRC_Abort;
81920 }
81921 /* Fall through */
81922 default:
81923 testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */
@@ -82641,68 +81925,57 @@
81925 return WRC_Continue;
81926 }
81927 }
81928 static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){
81929 UNUSED_PARAMETER(NotUsed);
81930 pWalker->u.i = 0;
81931 return WRC_Abort;
81932 }
81933 static int exprIsConst(Expr *p, int initFlag){
81934 Walker w;
81935 memset(&w, 0, sizeof(w));
81936 w.u.i = initFlag;
81937 w.xExprCallback = exprNodeIsConstant;
81938 w.xSelectCallback = selectNodeIsConstant;
 
81939 sqlite3WalkExpr(&w, p);
81940 return w.u.i;
81941 }
81942
81943 /*
81944 ** Walk an expression tree. Return 1 if the expression is constant
81945 ** and 0 if it involves variables or function calls.
81946 **
81947 ** For the purposes of this function, a double-quoted string (ex: "abc")
81948 ** is considered a variable but a single-quoted string (ex: 'abc') is
81949 ** a constant.
81950 */
81951 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr *p){
81952 return exprIsConst(p, 1);
81953 }
81954
81955 /*
81956 ** Walk an expression tree. Return 1 if the expression is constant
81957 ** that does no originate from the ON or USING clauses of a join.
81958 ** Return 0 if it involves variables or function calls or terms from
81959 ** an ON or USING clause.
81960 */
81961 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *p){
81962 return exprIsConst(p, 2);
81963 }
81964
81965 /*
81966 ** Walk an expression tree. Return 1 if the expression is constant
 
 
 
 
 
 
 
 
 
 
81967 ** or a function call with constant arguments. Return and 0 if there
81968 ** are any variables.
81969 **
81970 ** For the purposes of this function, a double-quoted string (ex: "abc")
81971 ** is considered a variable but a single-quoted string (ex: 'abc') is
81972 ** a constant.
81973 */
81974 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){
81975 assert( isInit==0 || isInit==1 );
81976 return exprIsConst(p, 3+isInit);
81977 }
81978
81979 /*
81980 ** If the expression p codes a constant integer that is small enough
81981 ** to fit in a 32-bit integer, return 1 and put the value of the integer
@@ -83208,11 +82481,10 @@
82481 sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
82482 dest.affSdst = (u8)affinity;
82483 assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
82484 pSelect->iLimit = 0;
82485 testcase( pSelect->selFlags & SF_Distinct );
 
82486 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
82487 if( sqlite3Select(pParse, pSelect, &dest) ){
82488 sqlite3KeyInfoUnref(pKeyInfo);
82489 return 0;
82490 }
@@ -88149,11 +87421,10 @@
87421 nSample--;
87422 }else{
87423 nRow = pIdx->aiRowEst[0];
87424 nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
87425 }
 
87426
87427 /* Set nSum to the number of distinct (iCol+1) field prefixes that
87428 ** occur in the stat4 table for this index. Set sumEq to the sum of
87429 ** the nEq values for column iCol for the same set (adding the value
87430 ** only once where there exist duplicate prefixes). */
@@ -88411,11 +87682,11 @@
87682 }
87683
87684
87685 /* Load the statistics from the sqlite_stat4 table. */
87686 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87687 if( rc==SQLITE_OK ){
87688 int lookasideEnabled = db->lookaside.bEnabled;
87689 db->lookaside.bEnabled = 0;
87690 rc = loadStat4(db, sInfo.zDatabase);
87691 db->lookaside.bEnabled = lookasideEnabled;
87692 }
@@ -89093,13 +88364,10 @@
88364 SQLITE_API int sqlite3_set_authorizer(
88365 sqlite3 *db,
88366 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
88367 void *pArg
88368 ){
 
 
 
88369 sqlite3_mutex_enter(db->mutex);
88370 db->xAuth = (sqlite3_xauth)xAuth;
88371 db->pAuthArg = pArg;
88372 sqlite3ExpirePreparedStatements(db);
88373 sqlite3_mutex_leave(db->mutex);
@@ -89590,15 +88858,11 @@
88858 ** See also sqlite3LocateTable().
88859 */
88860 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
88861 Table *p = 0;
88862 int i;
88863 assert( zName!=0 );
 
 
 
 
88864 /* All mutexes are required for schema access. Make sure we hold them. */
88865 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
88866 #if SQLITE_USER_AUTHENTICATION
88867 /* Only the admin user is allowed to know that the sqlite_user table
88868 ** exists */
@@ -104617,16 +103881,13 @@
103881 Vdbe *pOld, /* VM being reprepared */
103882 sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
103883 const char **pzTail /* OUT: End of parsed string */
103884 ){
103885 int rc;
103886 assert( ppStmt!=0 );
 
 
 
103887 *ppStmt = 0;
103888 if( !sqlite3SafetyCheckOk(db) ){
103889 return SQLITE_MISUSE_BKPT;
103890 }
103891 sqlite3_mutex_enter(db->mutex);
103892 sqlite3BtreeEnterAll(db);
103893 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
@@ -104729,15 +103990,13 @@
103990 */
103991 char *zSql8;
103992 const char *zTail8 = 0;
103993 int rc = SQLITE_OK;
103994
103995 assert( ppStmt );
 
 
103996 *ppStmt = 0;
103997 if( !sqlite3SafetyCheckOk(db) ){
103998 return SQLITE_MISUSE_BKPT;
103999 }
104000 if( nBytes>=0 ){
104001 int sz;
104002 const char *z = (const char*)zSql;
@@ -110446,13 +109705,10 @@
109705 char **pzErrMsg /* Write error messages here */
109706 ){
109707 int rc;
109708 TabResult res;
109709
 
 
 
109710 *pazResult = 0;
109711 if( pnColumn ) *pnColumn = 0;
109712 if( pnRow ) *pnRow = 0;
109713 if( pzErrMsg ) *pzErrMsg = 0;
109714 res.zErrMsg = 0;
@@ -112512,11 +111768,11 @@
111768 ** Two writes per page are required in step (3) because the original
111769 ** database content must be written into the rollback journal prior to
111770 ** overwriting the database with the vacuumed content.
111771 **
111772 ** Only 1x temporary space and only 1x writes would be required if
111773 ** the copy of step (3) were replace by deleting the original database
111774 ** and renaming the transient database as the original. But that will
111775 ** not work if other processes are attached to the original database.
111776 ** And a power loss in between deleting the original and renaming the
111777 ** transient would cause the database file to appear to be deleted
111778 ** following reboot.
@@ -112870,13 +112126,10 @@
112126 sqlite3 *db, /* Database in which module is registered */
112127 const char *zName, /* Name assigned to this module */
112128 const sqlite3_module *pModule, /* The definition of the module */
112129 void *pAux /* Context pointer for xCreate/xConnect */
112130 ){
 
 
 
112131 return createModule(db, zName, pModule, pAux, 0);
112132 }
112133
112134 /*
112135 ** External API function used to create a new virtual-table module.
@@ -112886,13 +112139,10 @@
112139 const char *zName, /* Name assigned to this module */
112140 const sqlite3_module *pModule, /* The definition of the module */
112141 void *pAux, /* Context pointer for xCreate/xConnect */
112142 void (*xDestroy)(void *) /* Module destructor function */
112143 ){
 
 
 
112144 return createModule(db, zName, pModule, pAux, xDestroy);
112145 }
112146
112147 /*
112148 ** Lock the virtual table so that it cannot be disconnected.
@@ -113493,13 +112743,10 @@
112743
112744 int rc = SQLITE_OK;
112745 Table *pTab;
112746 char *zErr = 0;
112747
 
 
 
112748 sqlite3_mutex_enter(db->mutex);
112749 if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
112750 sqlite3Error(db, SQLITE_MISUSE);
112751 sqlite3_mutex_leave(db->mutex);
112752 return SQLITE_MISUSE_BKPT;
@@ -113852,13 +113099,10 @@
113099 */
113100 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){
113101 static const unsigned char aMap[] = {
113102 SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE
113103 };
 
 
 
113104 assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 );
113105 assert( OE_Ignore==4 && OE_Replace==5 );
113106 assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 );
113107 return (int)aMap[db->vtabOnConflict-1];
113108 }
@@ -113870,14 +113114,12 @@
113114 */
113115 SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){
113116 va_list ap;
113117 int rc = SQLITE_OK;
113118
 
 
 
113119 sqlite3_mutex_enter(db->mutex);
113120
113121 va_start(ap, op);
113122 switch( op ){
113123 case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
113124 VtabCtx *p = db->pVtabCtx;
113125 if( !p ){
@@ -114008,13 +113250,10 @@
113250 } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
113251 Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
113252 } u;
113253 struct WhereLoop *pWLoop; /* The selected WhereLoop object */
113254 Bitmask notReady; /* FROM entries not usable at this level */
 
 
 
113255 };
113256
113257 /*
113258 ** Each instance of this object represents an algorithm for evaluating one
113259 ** term of a join. Every term of the FROM clause will have at least
@@ -114041,10 +113280,11 @@
113280 LogEst rRun; /* Cost of running each loop */
113281 LogEst nOut; /* Estimated number of output rows */
113282 union {
113283 struct { /* Information for internal btree tables */
113284 u16 nEq; /* Number of equality constraints */
113285 u16 nSkip; /* Number of initial index columns to skip */
113286 Index *pIndex; /* Index used, or NULL */
113287 } btree;
113288 struct { /* Information for virtual tables */
113289 int idxNum; /* Index number */
113290 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -114053,17 +113293,16 @@
113293 char *idxStr; /* Index identifier string */
113294 } vtab;
113295 } u;
113296 u32 wsFlags; /* WHERE_* flags describing the plan */
113297 u16 nLTerm; /* Number of entries in aLTerm[] */
 
113298 /**** whereLoopXfer() copies fields above ***********************/
113299 # define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot)
113300 u16 nLSlot; /* Number of slots allocated for aLTerm[] */
113301 WhereTerm **aLTerm; /* WhereTerms used */
113302 WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
113303 WhereTerm *aLTermSpace[4]; /* Initial aLTerm[] space */
113304 };
113305
113306 /* This object holds the prerequisites and the cost of running a
113307 ** subquery on one operand of an OR operator in the WHERE clause.
113308 ** See WhereOrSet for additional information
@@ -114385,11 +113624,10 @@
113624 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
113625 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
113626 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
113627 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
113628 #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
 
113629
113630 /************** End of whereInt.h ********************************************/
113631 /************** Continuing where we left off in where.c **********************/
113632
113633 /*
@@ -114596,11 +113834,11 @@
113834 }
113835 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
113836 }
113837 pTerm = &pWC->a[idx = pWC->nTerm++];
113838 if( p && ExprHasProperty(p, EP_Unlikely) ){
113839 pTerm->truthProb = sqlite3LogEst(p->iTable) - 99;
113840 }else{
113841 pTerm->truthProb = 1;
113842 }
113843 pTerm->pExpr = sqlite3ExprSkipCollate(p);
113844 pTerm->wtFlags = wtFlags;
@@ -115127,19 +114365,10 @@
114365 pDerived->flags |= pBase->flags & EP_FromJoin;
114366 pDerived->iRightJoinTable = pBase->iRightJoinTable;
114367 }
114368 }
114369
 
 
 
 
 
 
 
 
 
114370 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
114371 /*
114372 ** Analyze a term that consists of two or more OR-connected
114373 ** subterms. So in:
114374 **
@@ -115433,11 +114662,12 @@
114662 pNew->x.pList = pList;
114663 idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
114664 testcase( idxNew==0 );
114665 exprAnalyze(pSrc, pWC, idxNew);
114666 pTerm = &pWC->a[idxTerm];
114667 pWC->a[idxNew].iParent = idxTerm;
114668 pTerm->nChild = 1;
114669 }else{
114670 sqlite3ExprListDelete(db, pList);
114671 }
114672 pTerm->eOperator = WO_NOOP; /* case 1 trumps case 2 */
114673 }
@@ -115535,12 +114765,13 @@
114765 return;
114766 }
114767 idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);
114768 if( idxNew==0 ) return;
114769 pNew = &pWC->a[idxNew];
114770 pNew->iParent = idxTerm;
114771 pTerm = &pWC->a[idxTerm];
114772 pTerm->nChild = 1;
114773 pTerm->wtFlags |= TERM_COPIED;
114774 if( pExpr->op==TK_EQ
114775 && !ExprHasProperty(pExpr, EP_FromJoin)
114776 && OptimizationEnabled(db, SQLITE_Transitive)
114777 ){
@@ -115593,12 +114824,13 @@
114824 transferJoinMarkings(pNewExpr, pExpr);
114825 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
114826 testcase( idxNew==0 );
114827 exprAnalyze(pSrc, pWC, idxNew);
114828 pTerm = &pWC->a[idxTerm];
114829 pWC->a[idxNew].iParent = idxTerm;
114830 }
114831 pTerm->nChild = 2;
114832 }
114833 #endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */
114834
114835 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
114836 /* Analyze a term that is composed of two or more subterms connected by
@@ -115669,12 +114901,13 @@
114901 idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC);
114902 testcase( idxNew2==0 );
114903 exprAnalyze(pSrc, pWC, idxNew2);
114904 pTerm = &pWC->a[idxTerm];
114905 if( isComplete ){
114906 pWC->a[idxNew1].iParent = idxTerm;
114907 pWC->a[idxNew2].iParent = idxTerm;
114908 pTerm->nChild = 2;
114909 }
114910 }
114911 #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
114912
114913 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -115703,12 +114936,13 @@
114936 pNewTerm = &pWC->a[idxNew];
114937 pNewTerm->prereqRight = prereqExpr;
114938 pNewTerm->leftCursor = pLeft->iTable;
114939 pNewTerm->u.leftColumn = pLeft->iColumn;
114940 pNewTerm->eOperator = WO_MATCH;
114941 pNewTerm->iParent = idxTerm;
114942 pTerm = &pWC->a[idxTerm];
114943 pTerm->nChild = 1;
114944 pTerm->wtFlags |= TERM_COPIED;
114945 pNewTerm->prereqAll = pTerm->prereqAll;
114946 }
114947 }
114948 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -115725,11 +114959,11 @@
114959 ** the start of the loop will prevent any results from being returned.
114960 */
114961 if( pExpr->op==TK_NOTNULL
114962 && pExpr->pLeft->op==TK_COLUMN
114963 && pExpr->pLeft->iColumn>=0
114964 && OptimizationEnabled(db, SQLITE_Stat3)
114965 ){
114966 Expr *pNewExpr;
114967 Expr *pLeft = pExpr->pLeft;
114968 int idxNew;
114969 WhereTerm *pNewTerm;
@@ -115744,12 +114978,13 @@
114978 pNewTerm = &pWC->a[idxNew];
114979 pNewTerm->prereqRight = 0;
114980 pNewTerm->leftCursor = pLeft->iTable;
114981 pNewTerm->u.leftColumn = pLeft->iColumn;
114982 pNewTerm->eOperator = WO_GT;
114983 pNewTerm->iParent = idxTerm;
114984 pTerm = &pWC->a[idxTerm];
114985 pTerm->nChild = 1;
114986 pTerm->wtFlags |= TERM_COPIED;
114987 pNewTerm->prereqAll = pTerm->prereqAll;
114988 }
114989 }
114990 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
@@ -115965,12 +115200,10 @@
115200 WhereLoop *pLoop; /* The Loop object */
115201 char *zNotUsed; /* Extra space on the end of pIdx */
115202 Bitmask idxCols; /* Bitmap of columns used for indexing */
115203 Bitmask extraCols; /* Bitmap of additional columns */
115204 u8 sentWarning = 0; /* True if a warnning has been issued */
 
 
115205
115206 /* Generate code to skip over the creation and initialization of the
115207 ** transient index on 2nd and subsequent iterations of the loop. */
115208 v = pParse->pVdbe;
115209 assert( v!=0 );
@@ -115982,16 +115215,10 @@
115215 pTable = pSrc->pTab;
115216 pWCEnd = &pWC->a[pWC->nTerm];
115217 pLoop = pLevel->pWLoop;
115218 idxCols = 0;
115219 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
 
 
 
 
 
 
115220 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
115221 int iCol = pTerm->u.leftColumn;
115222 Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
115223 testcase( iCol==BMS );
115224 testcase( iCol==BMS-1 );
@@ -116000,13 +115227,11 @@
115227 "automatic index on %s(%s)", pTable->zName,
115228 pTable->aCol[iCol].zName);
115229 sentWarning = 1;
115230 }
115231 if( (idxCols & cMask)==0 ){
115232 if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ) return;
 
 
115233 pLoop->aLTerm[nKeyCol++] = pTerm;
115234 idxCols |= cMask;
115235 }
115236 }
115237 }
@@ -116022,23 +115247,24 @@
115247 ** be a covering index because the index will not be updated if the
115248 ** original table changes and the index and table cannot both be used
115249 ** if they go out of sync.
115250 */
115251 extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
115252 mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol;
115253 testcase( pTable->nCol==BMS-1 );
115254 testcase( pTable->nCol==BMS-2 );
115255 for(i=0; i<mxBitCol; i++){
115256 if( extraCols & MASKBIT(i) ) nKeyCol++;
115257 }
115258 if( pSrc->colUsed & MASKBIT(BMS-1) ){
115259 nKeyCol += pTable->nCol - BMS + 1;
115260 }
115261 pLoop->wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY;
115262
115263 /* Construct the Index object to describe this index */
115264 pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
115265 if( pIdx==0 ) return;
115266 pLoop->u.btree.pIndex = pIdx;
115267 pIdx->zName = "auto-index";
115268 pIdx->pTable = pTable;
115269 n = 0;
115270 idxCols = 0;
@@ -116086,33 +115312,22 @@
115312 sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
115313 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
115314 VdbeComment((v, "for %s", pTable->zName));
115315
115316 /* Fill the automatic index with content */
 
115317 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
 
 
 
 
 
115318 regRecord = sqlite3GetTempReg(pParse);
115319 sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
115320 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
115321 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
 
115322 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
115323 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
115324 sqlite3VdbeJumpHere(v, addrTop);
115325 sqlite3ReleaseTempReg(pParse, regRecord);
 
115326
115327 /* Jump here when skipping the initialization */
115328 sqlite3VdbeJumpHere(v, addrInit);
 
 
 
115329 }
115330 #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
115331
115332 #ifndef SQLITE_OMIT_VIRTUALTABLE
115333 /*
@@ -116267,23 +115482,23 @@
115482 }
115483
115484 return pParse->nErr;
115485 }
115486 #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */
115487
115488
115489 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
115490 /*
115491 ** Estimate the location of a particular key among all keys in an
115492 ** index. Store the results in aStat as follows:
115493 **
115494 ** aStat[0] Est. number of rows less than pVal
115495 ** aStat[1] Est. number of rows equal to pVal
115496 **
115497 ** Return SQLITE_OK on success.
 
115498 */
115499 static void whereKeyStats(
115500 Parse *pParse, /* Database connection */
115501 Index *pIdx, /* Index to consider domain of */
115502 UnpackedRecord *pRec, /* Vector of values to consider */
115503 int roundUp, /* Round up if true. Round down if false */
115504 tRowcnt *aStat /* OUT: stats written here */
@@ -116361,11 +115576,10 @@
115576 }else{
115577 iGap = iGap/3;
115578 }
115579 aStat[0] = iLower + iGap;
115580 }
 
115581 }
115582 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
115583
115584 /*
115585 ** If it is not NULL, pTerm is a term that provides an upper or lower
@@ -116512,11 +115726,11 @@
115726 ** pLower pUpper
115727 **
115728 ** If either of the upper or lower bound is not present, then NULL is passed in
115729 ** place of the corresponding WhereTerm.
115730 **
115731 ** The value in (pBuilder->pNew->u.btree.nEq) is the index of the index
115732 ** column subject to the range constraint. Or, equivalently, the number of
115733 ** equality constraints optimized by the proposed index scan. For example,
115734 ** assuming index p is on t1(a, b), and the SQL query is:
115735 **
115736 ** ... FROM t1 WHERE a = ? AND b > ? AND b < ? ...
@@ -116528,11 +115742,11 @@
115742 **
115743 ** then nEq is set to 0.
115744 **
115745 ** When this function is called, *pnOut is set to the sqlite3LogEst() of the
115746 ** number of rows that the index scan is expected to visit without
115747 ** considering the range constraints. If nEq is 0, this is the number of
115748 ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
115749 ** to account for the range constraints pLower and pUpper.
115750 **
115751 ** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be
115752 ** used, a single range inequality reduces the search space by a factor of 4.
@@ -116552,11 +115766,14 @@
115766
115767 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
115768 Index *p = pLoop->u.btree.pIndex;
115769 int nEq = pLoop->u.btree.nEq;
115770
115771 if( p->nSample>0
115772 && nEq<p->nSampleCol
115773 && OptimizationEnabled(pParse->db, SQLITE_Stat3)
115774 ){
115775 if( nEq==pBuilder->nRecValid ){
115776 UnpackedRecord *pRec = pBuilder->pRec;
115777 tRowcnt a[2];
115778 u8 aff;
115779
@@ -116568,23 +115785,19 @@
115785 **
115786 ** Or, if pLower is NULL or $L cannot be extracted from it (because it
115787 ** is not a simple variable or literal value), the lower bound of the
115788 ** range is $P. Due to a quirk in the way whereKeyStats() works, even
115789 ** if $L is available, whereKeyStats() is called for both ($P) and
115790 ** ($P:$L) and the larger of the two returned values used.
115791 **
115792 ** Similarly, iUpper is to be set to the estimate of the number of rows
115793 ** less than the upper bound of the range query. Where the upper bound
115794 ** is either ($P) or ($P:$U). Again, even if $U is available, both values
115795 ** of iUpper are requested of whereKeyStats() and the smaller used.
 
 
115796 */
115797 tRowcnt iLower;
115798 tRowcnt iUpper;
 
 
115799
115800 if( pRec ){
115801 testcase( pRec->nField!=pBuilder->nRecValid );
115802 pRec->nField = pBuilder->nRecValid;
115803 }
@@ -116594,11 +115807,11 @@
115807 aff = p->pTable->aCol[p->aiColumn[nEq]].affinity;
115808 }
115809 /* Determine iLower and iUpper using ($P) only. */
115810 if( nEq==0 ){
115811 iLower = 0;
115812 iUpper = sqlite3LogEstToInt(p->aiRowLogEst[0]);
115813 }else{
115814 /* Note: this call could be optimized away - since the same values must
115815 ** have been requested when testing key $P in whereEqualScanEst(). */
115816 whereKeyStats(pParse, p, pRec, 0, a);
115817 iLower = a[0];
@@ -116618,11 +115831,11 @@
115831 int bOk; /* True if value is extracted from pExpr */
115832 Expr *pExpr = pLower->pExpr->pRight;
115833 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115834 if( rc==SQLITE_OK && bOk ){
115835 tRowcnt iNew;
115836 whereKeyStats(pParse, p, pRec, 0, a);
115837 iNew = a[0] + ((pLower->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
115838 if( iNew>iLower ) iLower = iNew;
115839 nOut--;
115840 pLower = 0;
115841 }
@@ -116633,11 +115846,11 @@
115846 int bOk; /* True if value is extracted from pExpr */
115847 Expr *pExpr = pUpper->pExpr->pRight;
115848 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115849 if( rc==SQLITE_OK && bOk ){
115850 tRowcnt iNew;
115851 whereKeyStats(pParse, p, pRec, 1, a);
115852 iNew = a[0] + ((pUpper->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
115853 if( iNew<iUpper ) iUpper = iNew;
115854 nOut--;
115855 pUpper = 0;
115856 }
@@ -116645,15 +115858,10 @@
115858
115859 pBuilder->pRec = pRec;
115860 if( rc==SQLITE_OK ){
115861 if( iUpper>iLower ){
115862 nNew = sqlite3LogEst(iUpper - iLower);
 
 
 
 
 
115863 }else{
115864 nNew = 10; assert( 10==sqlite3LogEst(2) );
115865 }
115866 if( nNew<nOut ){
115867 nOut = nNew;
@@ -116674,19 +115882,16 @@
115882 #endif
115883 assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 );
115884 nNew = whereRangeAdjust(pLower, nOut);
115885 nNew = whereRangeAdjust(pUpper, nNew);
115886
115887 /* TUNING: If there is both an upper and lower limit, assume the range is
 
115888 ** reduced by an additional 75%. This means that, by default, an open-ended
115889 ** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the
115890 ** index. While a closed range (e.g. col BETWEEN ? AND ?) is estimated to
115891 ** match 1/64 of the index. */
115892 if( pLower && pUpper ) nNew -= 20;
 
 
115893
115894 nOut -= (pLower!=0) + (pUpper!=0);
115895 if( nNew<10 ) nNew = 10;
115896 if( nNew<nOut ) nOut = nNew;
115897 #if defined(WHERETRACE_ENABLED)
@@ -117042,11 +116247,11 @@
116247
116248 /* This module is only called on query plans that use an index. */
116249 pLoop = pLevel->pWLoop;
116250 assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
116251 nEq = pLoop->u.btree.nEq;
116252 nSkip = pLoop->u.btree.nSkip;
116253 pIdx = pLoop->u.btree.pIndex;
116254 assert( pIdx!=0 );
116255
116256 /* Figure out how many memory cells we will need then allocate them.
116257 */
@@ -117156,11 +116361,11 @@
116361 ** "a=? AND b>?"
116362 */
116363 static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
116364 Index *pIndex = pLoop->u.btree.pIndex;
116365 u16 nEq = pLoop->u.btree.nEq;
116366 u16 nSkip = pLoop->u.btree.nSkip;
116367 int i, j;
116368 Column *aCol = pTab->aCol;
116369 i16 *aiColumn = pIndex->aiColumn;
116370
116371 if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
@@ -117187,27 +116392,23 @@
116392 sqlite3StrAccumAppend(pStr, ")", 1);
116393 }
116394
116395 /*
116396 ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
116397 ** command. If the query being compiled is an EXPLAIN QUERY PLAN, a single
116398 ** record is added to the output to describe the table scan strategy in
116399 ** pLevel.
 
 
 
116400 */
116401 static void explainOneScan(
116402 Parse *pParse, /* Parse context */
116403 SrcList *pTabList, /* Table list this loop refers to */
116404 WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
116405 int iLevel, /* Value for "level" column of output */
116406 int iFrom, /* Value for "from" column of output */
116407 u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
116408 ){
116409 #ifndef SQLITE_DEBUG
 
116410 if( pParse->explain==2 )
116411 #endif
116412 {
116413 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
116414 Vdbe *v = pParse->pVdbe; /* VM being constructed */
@@ -117220,11 +116421,11 @@
116421 StrAccum str; /* EQP output string */
116422 char zBuf[100]; /* Initial space for EQP output string */
116423
116424 pLoop = pLevel->pWLoop;
116425 flags = pLoop->wsFlags;
116426 if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return;
116427
116428 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
116429 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
116430 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
116431
@@ -117249,12 +116450,10 @@
116450 assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
116451 if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
116452 if( isSearch ){
116453 zFmt = "PRIMARY KEY";
116454 }
 
 
116455 }else if( flags & WHERE_AUTO_INDEX ){
116456 zFmt = "AUTOMATIC COVERING INDEX";
116457 }else if( flags & WHERE_IDX_ONLY ){
116458 zFmt = "COVERING INDEX %s";
116459 }else{
@@ -117292,49 +116491,16 @@
116491 }else{
116492 sqlite3StrAccumAppend(&str, " (~1 row)", 9);
116493 }
116494 #endif
116495 zMsg = sqlite3StrAccumFinish(&str);
116496 sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg, P4_DYNAMIC);
116497 }
116498 }
116499 #else
116500 # define explainOneScan(u,v,w,x,y,z)
116501 #endif /* SQLITE_OMIT_EXPLAIN */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116502
116503
116504 /*
116505 ** Generate code for the start of the iLevel-th loop in the WHERE clause
116506 ** implementation described by pWInfo.
@@ -117632,11 +116798,11 @@
116798 u8 bSeekPastNull = 0; /* True to seek past initial nulls */
116799 u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */
116800
116801 pIdx = pLoop->u.btree.pIndex;
116802 iIdxCur = pLevel->iIdxCur;
116803 assert( nEq>=pLoop->u.btree.nSkip );
116804
116805 /* If this loop satisfies a sort order (pOrderBy) request that
116806 ** was passed to this function to implement a "SELECT min(x) ..."
116807 ** query, then the caller will only allow the loop to run for
116808 ** a single iteration. This means that the first row returned
@@ -117649,11 +116815,11 @@
116815 || (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0 );
116816 if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
116817 && pWInfo->nOBSat>0
116818 && (pIdx->nKeyCol>nEq)
116819 ){
116820 assert( pLoop->u.btree.nSkip==0 );
116821 bSeekPastNull = 1;
116822 nExtraReg = 1;
116823 }
116824
116825 /* Find any inequality constraint terms for the start and end
@@ -117998,15 +117164,13 @@
117164 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
117165 wctrlFlags, iCovCur);
117166 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
117167 if( pSubWInfo ){
117168 WhereLoop *pSubLoop;
117169 explainOneScan(
117170 pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
117171 );
 
 
117172 /* This is the sub-WHERE clause body. First skip over
117173 ** duplicate rows from prior sub-WHERE clauses, and record the
117174 ** rowid (or PRIMARY KEY) for the current row so that the same
117175 ** row will be skipped in subsequent sub-WHERE clauses.
117176 */
@@ -118133,14 +117297,10 @@
117297 VdbeCoverageIf(v, bRev!=0);
117298 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
117299 }
117300 }
117301
 
 
 
 
117302 /* Insert code to test every subexpression that can be completely
117303 ** computed using the current set of tables.
117304 */
117305 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
117306 Expr *pE;
@@ -118276,11 +117436,11 @@
117436 }
117437 sqlite3DebugPrintf(" %-19s", z);
117438 sqlite3_free(z);
117439 }
117440 if( p->wsFlags & WHERE_SKIPSCAN ){
117441 sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->u.btree.nSkip);
117442 }else{
117443 sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm);
117444 }
117445 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
117446 if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){
@@ -118387,41 +117547,34 @@
117547 sqlite3DbFree(db, pWInfo);
117548 }
117549 }
117550
117551 /*
117552 ** Return TRUE if both of the following are true:
117553 **
117554 ** (1) X has the same or lower cost that Y
117555 ** (2) X is a proper subset of Y
 
117556 **
117557 ** By "proper subset" we mean that X uses fewer WHERE clause terms
117558 ** than Y and that every WHERE clause term used by X is also used
117559 ** by Y.
117560 **
117561 ** If X is a proper subset of Y then Y is a better choice and ought
117562 ** to have a lower cost. This routine returns TRUE when that cost
117563 ** relationship is inverted and needs to be adjusted.
 
 
117564 */
117565 static int whereLoopCheaperProperSubset(
117566 const WhereLoop *pX, /* First WhereLoop to compare */
117567 const WhereLoop *pY /* Compare against this WhereLoop */
117568 ){
117569 int i, j;
117570 if( pX->nLTerm >= pY->nLTerm ) return 0; /* X is not a subset of Y */
 
 
 
117571 if( pX->rRun >= pY->rRun ){
117572 if( pX->rRun > pY->rRun ) return 0; /* X costs more than Y */
117573 if( pX->nOut > pY->nOut ) return 0; /* X costs more than Y */
117574 }
117575 for(i=pX->nLTerm-1; i>=0; i--){
 
117576 for(j=pY->nLTerm-1; j>=0; j--){
117577 if( pY->aLTerm[j]==pX->aLTerm[i] ) break;
117578 }
117579 if( j<0 ) return 0; /* X not a subset of Y since term X[i] not used by Y */
117580 }
@@ -118439,28 +117592,37 @@
117592 ** is a proper subset.
117593 **
117594 ** To say "WhereLoop X is a proper subset of Y" means that X uses fewer
117595 ** WHERE clause terms than Y and that every WHERE clause term used by X is
117596 ** also used by Y.
117597 **
117598 ** This adjustment is omitted for SKIPSCAN loops. In a SKIPSCAN loop, the
117599 ** WhereLoop.nLTerm field is not an accurate measure of the number of WHERE
117600 ** clause terms covered, since some of the first nLTerm entries in aLTerm[]
117601 ** will be NULL (because they are skipped). That makes it more difficult
117602 ** to compare the loops. We could add extra code to do the comparison, and
117603 ** perhaps we will someday. But SKIPSCAN is sufficiently uncommon, and this
117604 ** adjustment is sufficient minor, that it is very difficult to construct
117605 ** a test case where the extra code would improve the query plan. Better
117606 ** to avoid the added complexity and just omit cost adjustments to SKIPSCAN
117607 ** loops.
117608 */
117609 static void whereLoopAdjustCost(const WhereLoop *p, WhereLoop *pTemplate){
117610 if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return;
117611 if( (pTemplate->wsFlags & WHERE_SKIPSCAN)!=0 ) return;
117612 for(; p; p=p->pNextLoop){
117613 if( p->iTab!=pTemplate->iTab ) continue;
117614 if( (p->wsFlags & WHERE_INDEXED)==0 ) continue;
117615 if( (p->wsFlags & WHERE_SKIPSCAN)!=0 ) continue;
117616 if( whereLoopCheaperProperSubset(p, pTemplate) ){
117617 /* Adjust pTemplate cost downward so that it is cheaper than its
117618 ** subset p */
 
 
117619 pTemplate->rRun = p->rRun;
117620 pTemplate->nOut = p->nOut - 1;
117621 }else if( whereLoopCheaperProperSubset(pTemplate, p) ){
117622 /* Adjust pTemplate cost upward so that it is costlier than p since
117623 ** pTemplate is a proper subset of p */
 
 
117624 pTemplate->rRun = p->rRun;
117625 pTemplate->nOut = p->nOut + 1;
117626 }
117627 }
117628 }
@@ -118742,11 +117904,11 @@
117904 int opMask; /* Valid operators for constraints */
117905 WhereScan scan; /* Iterator for WHERE terms */
117906 Bitmask saved_prereq; /* Original value of pNew->prereq */
117907 u16 saved_nLTerm; /* Original value of pNew->nLTerm */
117908 u16 saved_nEq; /* Original value of pNew->u.btree.nEq */
117909 u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */
117910 u32 saved_wsFlags; /* Original value of pNew->wsFlags */
117911 LogEst saved_nOut; /* Original value of pNew->nOut */
117912 int iCol; /* Index of the column in the table */
117913 int rc = SQLITE_OK; /* Return code */
117914 LogEst rSize; /* Number of rows in the table */
@@ -118771,18 +117933,56 @@
117933 iCol = pProbe->aiColumn[pNew->u.btree.nEq];
117934
117935 pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
117936 opMask, pProbe);
117937 saved_nEq = pNew->u.btree.nEq;
117938 saved_nSkip = pNew->u.btree.nSkip;
117939 saved_nLTerm = pNew->nLTerm;
117940 saved_wsFlags = pNew->wsFlags;
117941 saved_prereq = pNew->prereq;
117942 saved_nOut = pNew->nOut;
117943 pNew->rSetup = 0;
117944 rSize = pProbe->aiRowLogEst[0];
117945 rLogSize = estLog(rSize);
117946
117947 /* Consider using a skip-scan if there are no WHERE clause constraints
117948 ** available for the left-most terms of the index, and if the average
117949 ** number of repeats in the left-most terms is at least 18.
117950 **
117951 ** The magic number 18 is selected on the basis that scanning 17 rows
117952 ** is almost always quicker than an index seek (even though if the index
117953 ** contains fewer than 2^17 rows we assume otherwise in other parts of
117954 ** the code). And, even if it is not, it should not be too much slower.
117955 ** On the other hand, the extra seeks could end up being significantly
117956 ** more expensive. */
117957 assert( 42==sqlite3LogEst(18) );
117958 if( saved_nEq==saved_nSkip
117959 && saved_nEq+1<pProbe->nKeyCol
117960 && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
117961 && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
117962 ){
117963 LogEst nIter;
117964 pNew->u.btree.nEq++;
117965 pNew->u.btree.nSkip++;
117966 pNew->aLTerm[pNew->nLTerm++] = 0;
117967 pNew->wsFlags |= WHERE_SKIPSCAN;
117968 nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1];
117969 if( pTerm ){
117970 /* TUNING: When estimating skip-scan for a term that is also indexable,
117971 ** multiply the cost of the skip-scan by 2.0, to make it a little less
117972 ** desirable than the regular index lookup. */
117973 nIter += 10; assert( 10==sqlite3LogEst(2) );
117974 }
117975 pNew->nOut -= nIter;
117976 /* TUNING: Because uncertainties in the estimates for skip-scan queries,
117977 ** add a 1.375 fudge factor to make skip-scan slightly less likely. */
117978 nIter += 5;
117979 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul);
117980 pNew->nOut = saved_nOut;
117981 pNew->u.btree.nEq = saved_nEq;
117982 pNew->u.btree.nSkip = saved_nSkip;
117983 }
117984 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
117985 u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */
117986 LogEst rCostIdx;
117987 LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */
117988 int nIn = 0;
@@ -118873,10 +118073,11 @@
118073 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
118074 tRowcnt nOut = 0;
118075 if( nInMul==0
118076 && pProbe->nSample
118077 && pNew->u.btree.nEq<=pProbe->nSampleCol
118078 && OptimizationEnabled(db, SQLITE_Stat3)
118079 && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect))
118080 ){
118081 Expr *pExpr = pTerm->pExpr;
118082 if( (eOp & (WO_EQ|WO_ISNULL))!=0 ){
118083 testcase( eOp & WO_EQ );
@@ -118940,48 +118141,14 @@
118141 pBuilder->nRecValid = nRecValid;
118142 #endif
118143 }
118144 pNew->prereq = saved_prereq;
118145 pNew->u.btree.nEq = saved_nEq;
118146 pNew->u.btree.nSkip = saved_nSkip;
118147 pNew->wsFlags = saved_wsFlags;
118148 pNew->nOut = saved_nOut;
118149 pNew->nLTerm = saved_nLTerm;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118150 return rc;
118151 }
118152
118153 /*
118154 ** Return True if it is possible that pIndex might be useful in
@@ -119156,11 +118323,11 @@
118323 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
118324 for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
118325 if( pTerm->prereqRight & pNew->maskSelf ) continue;
118326 if( termCanDriveIndex(pTerm, pSrc, 0) ){
118327 pNew->u.btree.nEq = 1;
118328 pNew->u.btree.nSkip = 0;
118329 pNew->u.btree.pIndex = 0;
118330 pNew->nLTerm = 1;
118331 pNew->aLTerm[0] = pTerm;
118332 /* TUNING: One-time cost for computing the automatic index is
118333 ** estimated to be X*N*log2(N) where N is the number of rows in
@@ -119197,11 +118364,11 @@
118364 testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
118365 continue; /* Partial index inappropriate for this query */
118366 }
118367 rSize = pProbe->aiRowLogEst[0];
118368 pNew->u.btree.nEq = 0;
118369 pNew->u.btree.nSkip = 0;
118370 pNew->nLTerm = 0;
118371 pNew->iSortIdx = 0;
118372 pNew->rSetup = 0;
118373 pNew->prereq = mExtra;
118374 pNew->nOut = rSize;
@@ -119747,11 +118914,11 @@
118914 for(j=0; j<nColumn; j++){
118915 u8 bOnce; /* True to run the ORDER BY search loop */
118916
118917 /* Skip over == and IS NULL terms */
118918 if( j<pLoop->u.btree.nEq
118919 && pLoop->u.btree.nSkip==0
118920 && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
118921 ){
118922 if( i & WO_ISNULL ){
118923 testcase( isOrderDistinct );
118924 isOrderDistinct = 0;
@@ -120201,11 +119368,11 @@
119368 }
119369 }
119370 }
119371
119372 #ifdef WHERETRACE_ENABLED /* >=2 */
119373 if( sqlite3WhereTrace>=2 ){
119374 sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
119375 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
119376 sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c",
119377 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
119378 pTo->isOrdered>=0 ? (pTo->isOrdered+'0') : '?');
@@ -120320,11 +119487,11 @@
119487 if( pItem->zIndex ) return 0;
119488 iCur = pItem->iCursor;
119489 pWC = &pWInfo->sWC;
119490 pLoop = pBuilder->pNew;
119491 pLoop->wsFlags = 0;
119492 pLoop->u.btree.nSkip = 0;
119493 pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0);
119494 if( pTerm ){
119495 pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW;
119496 pLoop->aLTerm[0] = pTerm;
119497 pLoop->nLTerm = 1;
@@ -120332,10 +119499,11 @@
119499 /* TUNING: Cost of a rowid lookup is 10 */
119500 pLoop->rRun = 33; /* 33==sqlite3LogEst(10) */
119501 }else{
119502 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
119503 assert( pLoop->aLTermSpace==pLoop->aLTerm );
119504 assert( ArraySize(pLoop->aLTermSpace)==4 );
119505 if( !IsUniqueIndex(pIdx)
119506 || pIdx->pPartIdxWhere!=0
119507 || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace)
119508 ) continue;
119509 for(j=0; j<pIdx->nKeyCol; j++){
@@ -120840,30 +120008,22 @@
120008 ** loop below generates code for a single nested loop of the VM
120009 ** program.
120010 */
120011 notReady = ~(Bitmask)0;
120012 for(ii=0; ii<nTabList; ii++){
 
 
120013 pLevel = &pWInfo->a[ii];
 
120014 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
120015 if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){
120016 constructAutomaticIndex(pParse, &pWInfo->sWC,
120017 &pTabList->a[pLevel->iFrom], notReady, pLevel);
120018 if( db->mallocFailed ) goto whereBeginError;
120019 }
120020 #endif
120021 explainOneScan(pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags);
 
 
120022 pLevel->addrBody = sqlite3VdbeCurrentAddr(v);
120023 notReady = codeOneLoopStart(pWInfo, ii, notReady);
120024 pWInfo->iContinue = pLevel->addrCont;
 
 
 
120025 }
120026
120027 /* Done. */
120028 VdbeModuleComment((v, "Begin WHERE-core"));
120029 return pWInfo;
@@ -125528,17 +124688,10 @@
124688 */
124689 SQLITE_API int sqlite3_complete(const char *zSql){
124690 u8 state = 0; /* Current state, using numbers defined in header comment */
124691 u8 token; /* Value of the next token */
124692
 
 
 
 
 
 
 
124693 #ifndef SQLITE_OMIT_TRIGGER
124694 /* A complex statement machine used to detect the end of a CREATE TRIGGER
124695 ** statement. This is the normal case.
124696 */
124697 static const u8 trans[8][8] = {
@@ -126132,107 +125285,75 @@
125285
125286 va_start(ap, op);
125287 switch( op ){
125288
125289 /* Mutex configuration options are only available in a threadsafe
125290 ** compile.
125291 */
125292 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0
125293 case SQLITE_CONFIG_SINGLETHREAD: {
125294 /* Disable all mutexing */
125295 sqlite3GlobalConfig.bCoreMutex = 0;
125296 sqlite3GlobalConfig.bFullMutex = 0;
125297 break;
125298 }
 
 
125299 case SQLITE_CONFIG_MULTITHREAD: {
125300 /* Disable mutexing of database connections */
125301 /* Enable mutexing of core data structures */
125302 sqlite3GlobalConfig.bCoreMutex = 1;
125303 sqlite3GlobalConfig.bFullMutex = 0;
125304 break;
125305 }
 
 
125306 case SQLITE_CONFIG_SERIALIZED: {
125307 /* Enable all mutexing */
125308 sqlite3GlobalConfig.bCoreMutex = 1;
125309 sqlite3GlobalConfig.bFullMutex = 1;
125310 break;
125311 }
 
 
125312 case SQLITE_CONFIG_MUTEX: {
125313 /* Specify an alternative mutex implementation */
125314 sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
125315 break;
125316 }
 
 
125317 case SQLITE_CONFIG_GETMUTEX: {
125318 /* Retrieve the current mutex implementation */
125319 *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
125320 break;
125321 }
125322 #endif
125323
125324
125325 case SQLITE_CONFIG_MALLOC: {
125326 /* Specify an alternative malloc implementation */
 
 
 
 
125327 sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*);
125328 break;
125329 }
125330 case SQLITE_CONFIG_GETMALLOC: {
125331 /* Retrieve the current malloc() implementation */
 
 
 
125332 if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault();
125333 *va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m;
125334 break;
125335 }
125336 case SQLITE_CONFIG_MEMSTATUS: {
125337 /* Enable or disable the malloc status collection */
 
 
125338 sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
125339 break;
125340 }
125341 case SQLITE_CONFIG_SCRATCH: {
125342 /* Designate a buffer for scratch memory space */
 
 
 
125343 sqlite3GlobalConfig.pScratch = va_arg(ap, void*);
125344 sqlite3GlobalConfig.szScratch = va_arg(ap, int);
125345 sqlite3GlobalConfig.nScratch = va_arg(ap, int);
125346 break;
125347 }
125348 case SQLITE_CONFIG_PAGECACHE: {
125349 /* Designate a buffer for page cache memory space */
 
 
125350 sqlite3GlobalConfig.pPage = va_arg(ap, void*);
125351 sqlite3GlobalConfig.szPage = va_arg(ap, int);
125352 sqlite3GlobalConfig.nPage = va_arg(ap, int);
125353 break;
125354 }
 
 
 
 
 
 
 
 
 
 
 
125355
125356 case SQLITE_CONFIG_PCACHE: {
125357 /* no-op */
125358 break;
125359 }
@@ -126241,37 +125362,25 @@
125362 rc = SQLITE_ERROR;
125363 break;
125364 }
125365
125366 case SQLITE_CONFIG_PCACHE2: {
125367 /* Specify an alternative page cache implementation */
 
 
 
125368 sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*);
125369 break;
125370 }
125371 case SQLITE_CONFIG_GETPCACHE2: {
 
 
 
 
125372 if( sqlite3GlobalConfig.pcache2.xInit==0 ){
125373 sqlite3PCacheSetDefault();
125374 }
125375 *va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2;
125376 break;
125377 }
125378
 
 
 
125379 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
125380 case SQLITE_CONFIG_HEAP: {
125381 /* Designate a buffer for heap memory space */
 
 
125382 sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
125383 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
125384 sqlite3GlobalConfig.mnReq = va_arg(ap, int);
125385
125386 if( sqlite3GlobalConfig.mnReq<1 ){
@@ -126280,23 +125389,21 @@
125389 /* cap min request size at 2^12 */
125390 sqlite3GlobalConfig.mnReq = (1<<12);
125391 }
125392
125393 if( sqlite3GlobalConfig.pHeap==0 ){
125394 /* If the heap pointer is NULL, then restore the malloc implementation
125395 ** back to NULL pointers too. This will cause the malloc to go
125396 ** back to its default implementation when sqlite3_initialize() is
125397 ** run.
 
 
 
125398 */
125399 memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
125400 }else{
125401 /* The heap pointer is not NULL, then install one of the
125402 ** mem5.c/mem3.c methods. The enclosing #if guarantees at
125403 ** least one of these methods is currently enabled.
125404 */
125405 #ifdef SQLITE_ENABLE_MEMSYS3
125406 sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3();
125407 #endif
125408 #ifdef SQLITE_ENABLE_MEMSYS5
125409 sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5();
@@ -126331,23 +125438,15 @@
125438 ** can be changed at start-time using the
125439 ** sqlite3_config(SQLITE_CONFIG_URI,1) or
125440 ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
125441 */
125442 case SQLITE_CONFIG_URI: {
 
 
 
 
125443 sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
125444 break;
125445 }
125446
125447 case SQLITE_CONFIG_COVERING_INDEX_SCAN: {
 
 
 
 
125448 sqlite3GlobalConfig.bUseCis = va_arg(ap, int);
125449 break;
125450 }
125451
125452 #ifdef SQLITE_ENABLE_SQLLOG
@@ -126358,37 +125457,24 @@
125457 break;
125458 }
125459 #endif
125460
125461 case SQLITE_CONFIG_MMAP_SIZE: {
 
 
 
 
125462 sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64);
125463 sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64);
125464 if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){
125465 mxMmap = SQLITE_MAX_MMAP_SIZE;
125466 }
125467 sqlite3GlobalConfig.mxMmap = mxMmap;
 
 
 
 
 
125468 if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
125469 if( szMmap>mxMmap) szMmap = mxMmap;
 
125470 sqlite3GlobalConfig.szMmap = szMmap;
125471 break;
125472 }
125473
125474 #if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC)
125475 case SQLITE_CONFIG_WIN32_HEAPSIZE: {
 
 
 
125476 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
125477 break;
125478 }
125479 #endif
125480
@@ -126468,29 +125554,19 @@
125554
125555 /*
125556 ** Return the mutex associated with a database connection.
125557 */
125558 SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
 
 
 
 
 
 
125559 return db->mutex;
125560 }
125561
125562 /*
125563 ** Free up as much memory as we can from the given database
125564 ** connection.
125565 */
125566 SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){
125567 int i;
 
 
 
 
125568 sqlite3_mutex_enter(db->mutex);
125569 sqlite3BtreeEnterAll(db);
125570 for(i=0; i<db->nDb; i++){
125571 Btree *pBt = db->aDb[i].pBt;
125572 if( pBt ){
@@ -126617,42 +125693,24 @@
125693
125694 /*
125695 ** Return the ROWID of the most recent insert
125696 */
125697 SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
 
 
 
 
 
 
125698 return db->lastRowid;
125699 }
125700
125701 /*
125702 ** Return the number of changes in the most recent call to sqlite3_exec().
125703 */
125704 SQLITE_API int sqlite3_changes(sqlite3 *db){
 
 
 
 
 
 
125705 return db->nChange;
125706 }
125707
125708 /*
125709 ** Return the number of changes since the database handle was opened.
125710 */
125711 SQLITE_API int sqlite3_total_changes(sqlite3 *db){
 
 
 
 
 
 
125712 return db->nTotalChange;
125713 }
125714
125715 /*
125716 ** Close all open savepoints. This function only manipulates fields of the
@@ -127197,13 +126255,10 @@
126255 SQLITE_API int sqlite3_busy_handler(
126256 sqlite3 *db,
126257 int (*xBusy)(void*,int),
126258 void *pArg
126259 ){
 
 
 
126260 sqlite3_mutex_enter(db->mutex);
126261 db->busyHandler.xFunc = xBusy;
126262 db->busyHandler.pArg = pArg;
126263 db->busyHandler.nBusy = 0;
126264 db->busyTimeout = 0;
@@ -127221,16 +126276,10 @@
126276 sqlite3 *db,
126277 int nOps,
126278 int (*xProgress)(void*),
126279 void *pArg
126280 ){
 
 
 
 
 
 
126281 sqlite3_mutex_enter(db->mutex);
126282 if( nOps>0 ){
126283 db->xProgress = xProgress;
126284 db->nProgressOps = (unsigned)nOps;
126285 db->pProgressArg = pArg;
@@ -127247,13 +126296,10 @@
126296 /*
126297 ** This routine installs a default busy handler that waits for the
126298 ** specified number of milliseconds before returning 0.
126299 */
126300 SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
 
 
 
126301 if( ms>0 ){
126302 sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
126303 db->busyTimeout = ms;
126304 }else{
126305 sqlite3_busy_handler(db, 0, 0);
@@ -127263,16 +126309,10 @@
126309
126310 /*
126311 ** Cause any pending operation to stop at its earliest opportunity.
126312 */
126313 SQLITE_API void sqlite3_interrupt(sqlite3 *db){
 
 
 
 
 
 
126314 db->u1.isInterrupted = 1;
126315 }
126316
126317
126318 /*
@@ -127406,16 +126446,10 @@
126446 void (*xFinal)(sqlite3_context*),
126447 void (*xDestroy)(void *)
126448 ){
126449 int rc = SQLITE_ERROR;
126450 FuncDestructor *pArg = 0;
 
 
 
 
 
 
126451 sqlite3_mutex_enter(db->mutex);
126452 if( xDestroy ){
126453 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
126454 if( !pArg ){
126455 xDestroy(p);
@@ -127448,14 +126482,10 @@
126482 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
126483 void (*xFinal)(sqlite3_context*)
126484 ){
126485 int rc;
126486 char *zFunc8;
 
 
 
 
126487 sqlite3_mutex_enter(db->mutex);
126488 assert( !db->mallocFailed );
126489 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
126490 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
126491 sqlite3DbFree(db, zFunc8);
@@ -127483,16 +126513,10 @@
126513 const char *zName,
126514 int nArg
126515 ){
126516 int nName = sqlite3Strlen30(zName);
126517 int rc = SQLITE_OK;
 
 
 
 
 
 
126518 sqlite3_mutex_enter(db->mutex);
126519 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
126520 rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
126521 0, sqlite3InvalidFunction, 0, 0, 0);
126522 }
@@ -127510,17 +126534,10 @@
126534 ** trace is a pointer to a function that is invoked at the start of each
126535 ** SQL statement.
126536 */
126537 SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
126538 void *pOld;
 
 
 
 
 
 
 
126539 sqlite3_mutex_enter(db->mutex);
126540 pOld = db->pTraceArg;
126541 db->xTrace = xTrace;
126542 db->pTraceArg = pArg;
126543 sqlite3_mutex_leave(db->mutex);
@@ -127538,17 +126555,10 @@
126555 sqlite3 *db,
126556 void (*xProfile)(void*,const char*,sqlite_uint64),
126557 void *pArg
126558 ){
126559 void *pOld;
 
 
 
 
 
 
 
126560 sqlite3_mutex_enter(db->mutex);
126561 pOld = db->pProfileArg;
126562 db->xProfile = xProfile;
126563 db->pProfileArg = pArg;
126564 sqlite3_mutex_leave(db->mutex);
@@ -127565,17 +126575,10 @@
126575 sqlite3 *db, /* Attach the hook to this database */
126576 int (*xCallback)(void*), /* Function to invoke on each commit */
126577 void *pArg /* Argument to the function */
126578 ){
126579 void *pOld;
 
 
 
 
 
 
 
126580 sqlite3_mutex_enter(db->mutex);
126581 pOld = db->pCommitArg;
126582 db->xCommitCallback = xCallback;
126583 db->pCommitArg = pArg;
126584 sqlite3_mutex_leave(db->mutex);
@@ -127590,17 +126593,10 @@
126593 sqlite3 *db, /* Attach the hook to this database */
126594 void (*xCallback)(void*,int,char const *,char const *,sqlite_int64),
126595 void *pArg /* Argument to the function */
126596 ){
126597 void *pRet;
 
 
 
 
 
 
 
126598 sqlite3_mutex_enter(db->mutex);
126599 pRet = db->pUpdateArg;
126600 db->xUpdateCallback = xCallback;
126601 db->pUpdateArg = pArg;
126602 sqlite3_mutex_leave(db->mutex);
@@ -127615,17 +126611,10 @@
126611 sqlite3 *db, /* Attach the hook to this database */
126612 void (*xCallback)(void*), /* Callback function */
126613 void *pArg /* Argument to the function */
126614 ){
126615 void *pRet;
 
 
 
 
 
 
 
126616 sqlite3_mutex_enter(db->mutex);
126617 pRet = db->pRollbackArg;
126618 db->xRollbackCallback = xCallback;
126619 db->pRollbackArg = pArg;
126620 sqlite3_mutex_leave(db->mutex);
@@ -127668,13 +126657,10 @@
126657 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
126658 #ifdef SQLITE_OMIT_WAL
126659 UNUSED_PARAMETER(db);
126660 UNUSED_PARAMETER(nFrame);
126661 #else
 
 
 
126662 if( nFrame>0 ){
126663 sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
126664 }else{
126665 sqlite3_wal_hook(db, 0, 0);
126666 }
@@ -127691,16 +126677,10 @@
126677 int(*xCallback)(void *, sqlite3*, const char*, int),
126678 void *pArg /* First argument passed to xCallback() */
126679 ){
126680 #ifndef SQLITE_OMIT_WAL
126681 void *pRet;
 
 
 
 
 
 
126682 sqlite3_mutex_enter(db->mutex);
126683 pRet = db->pWalArg;
126684 db->xWalCallback = xCallback;
126685 db->pWalArg = pArg;
126686 sqlite3_mutex_leave(db->mutex);
@@ -127724,14 +126704,10 @@
126704 return SQLITE_OK;
126705 #else
126706 int rc; /* Return code */
126707 int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
126708
 
 
 
 
126709 /* Initialize the output variables to -1 in case an error occurs. */
126710 if( pnLog ) *pnLog = -1;
126711 if( pnCkpt ) *pnCkpt = -1;
126712
126713 assert( SQLITE_CHECKPOINT_FULL>SQLITE_CHECKPOINT_PASSIVE );
@@ -128124,16 +127100,10 @@
127100 ** from forming.
127101 */
127102 SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
127103 int oldLimit;
127104
 
 
 
 
 
 
127105
127106 /* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME
127107 ** there is a hard upper bound set at compile-time by a C preprocessor
127108 ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
127109 ** "_MAX_".)
@@ -128206,12 +127176,11 @@
127176 char c;
127177 int nUri = sqlite3Strlen30(zUri);
127178
127179 assert( *pzErrMsg==0 );
127180
127181 if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri)
 
127182 && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
127183 ){
127184 char *zOpt;
127185 int eState; /* Parser state when parsing URI */
127186 int iIn; /* Input character index */
@@ -128416,13 +127385,10 @@
127385 int rc; /* Return code */
127386 int isThreadsafe; /* True for threadsafe connections */
127387 char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */
127388 char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */
127389
 
 
 
127390 *ppDb = 0;
127391 #ifndef SQLITE_OMIT_AUTOINIT
127392 rc = sqlite3_initialize();
127393 if( rc ) return rc;
127394 #endif
@@ -128708,19 +127674,17 @@
127674 ){
127675 char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
127676 sqlite3_value *pVal;
127677 int rc;
127678
127679 assert( zFilename );
127680 assert( ppDb );
 
127681 *ppDb = 0;
127682 #ifndef SQLITE_OMIT_AUTOINIT
127683 rc = sqlite3_initialize();
127684 if( rc ) return rc;
127685 #endif
 
127686 pVal = sqlite3ValueNew(0);
127687 sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC);
127688 zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8);
127689 if( zFilename8 ){
127690 rc = openDatabase(zFilename8, ppDb,
@@ -128746,11 +127710,17 @@
127710 const char *zName,
127711 int enc,
127712 void* pCtx,
127713 int(*xCompare)(void*,int,const void*,int,const void*)
127714 ){
127715 int rc;
127716 sqlite3_mutex_enter(db->mutex);
127717 assert( !db->mallocFailed );
127718 rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, 0);
127719 rc = sqlite3ApiExit(db, rc);
127720 sqlite3_mutex_leave(db->mutex);
127721 return rc;
127722 }
127723
127724 /*
127725 ** Register a new collation sequence with the database handle db.
127726 */
@@ -128761,14 +127731,10 @@
127731 void* pCtx,
127732 int(*xCompare)(void*,int,const void*,int,const void*),
127733 void(*xDel)(void*)
127734 ){
127735 int rc;
 
 
 
 
127736 sqlite3_mutex_enter(db->mutex);
127737 assert( !db->mallocFailed );
127738 rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel);
127739 rc = sqlite3ApiExit(db, rc);
127740 sqlite3_mutex_leave(db->mutex);
@@ -128786,14 +127752,10 @@
127752 void* pCtx,
127753 int(*xCompare)(void*,int,const void*,int,const void*)
127754 ){
127755 int rc = SQLITE_OK;
127756 char *zName8;
 
 
 
 
127757 sqlite3_mutex_enter(db->mutex);
127758 assert( !db->mallocFailed );
127759 zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
127760 if( zName8 ){
127761 rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
@@ -128812,13 +127774,10 @@
127774 SQLITE_API int sqlite3_collation_needed(
127775 sqlite3 *db,
127776 void *pCollNeededArg,
127777 void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*)
127778 ){
 
 
 
127779 sqlite3_mutex_enter(db->mutex);
127780 db->xCollNeeded = xCollNeeded;
127781 db->xCollNeeded16 = 0;
127782 db->pCollNeededArg = pCollNeededArg;
127783 sqlite3_mutex_leave(db->mutex);
@@ -128833,13 +127792,10 @@
127792 SQLITE_API int sqlite3_collation_needed16(
127793 sqlite3 *db,
127794 void *pCollNeededArg,
127795 void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*)
127796 ){
 
 
 
127797 sqlite3_mutex_enter(db->mutex);
127798 db->xCollNeeded = 0;
127799 db->xCollNeeded16 = xCollNeeded16;
127800 db->pCollNeededArg = pCollNeededArg;
127801 sqlite3_mutex_leave(db->mutex);
@@ -128862,16 +127818,10 @@
127818 ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
127819 ** by default. Autocommit is disabled by a BEGIN statement and reenabled
127820 ** by the next COMMIT or ROLLBACK.
127821 */
127822 SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
 
 
 
 
 
 
127823 return db->autoCommit;
127824 }
127825
127826 /*
127827 ** The following routines are substitutes for constants SQLITE_CORRUPT,
@@ -129050,13 +128000,10 @@
128000
128001 /*
128002 ** Enable or disable the extended result codes.
128003 */
128004 SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
 
 
 
128005 sqlite3_mutex_enter(db->mutex);
128006 db->errMask = onoff ? 0xffffffff : 0xff;
128007 sqlite3_mutex_leave(db->mutex);
128008 return SQLITE_OK;
128009 }
@@ -129066,13 +128013,10 @@
128013 */
128014 SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
128015 int rc = SQLITE_ERROR;
128016 Btree *pBtree;
128017
 
 
 
128018 sqlite3_mutex_enter(db->mutex);
128019 pBtree = sqlite3DbNameToBtree(db, zDbName);
128020 if( pBtree ){
128021 Pager *pPager;
128022 sqlite3_file *fd;
@@ -129411,11 +128355,11 @@
128355 ** query parameter we seek. This routine returns the value of the zParam
128356 ** parameter if it exists. If the parameter does not exist, this routine
128357 ** returns a NULL pointer.
128358 */
128359 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){
128360 if( zFilename==0 ) return 0;
128361 zFilename += sqlite3Strlen30(zFilename) + 1;
128362 while( zFilename[0] ){
128363 int x = strcmp(zFilename, zParam);
128364 zFilename += sqlite3Strlen30(zFilename) + 1;
128365 if( x==0 ) return zFilename;
@@ -129467,31 +128411,19 @@
128411 /*
128412 ** Return the filename of the database associated with a database
128413 ** connection.
128414 */
128415 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
 
 
 
 
 
 
128416 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
128417 return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
128418 }
128419
128420 /*
128421 ** Return 1 if database is read-only or 0 if read/write. Return -1 if
128422 ** no such database exists.
128423 */
128424 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
 
 
 
 
 
 
128425 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
128426 return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
128427 }
128428
128429 /************** End of main.c ************************************************/
128430
+182 -308
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -55,11 +55,11 @@
5555
5656
5757
/*
5858
** These no-op macros are used in front of interfaces to mark those
5959
** interfaces as either deprecated or experimental. New applications
60
-** should not use deprecated interfaces - they are supported for backwards
60
+** should not use deprecated interfaces - they are support for backwards
6161
** compatibility only. Application writers should be aware that
6262
** experimental interfaces are subject to change in point releases.
6363
**
6464
** These macros used to resolve to various kinds of compiler magic that
6565
** would generate warning messages when they were used. But that
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.8.8"
111
-#define SQLITE_VERSION_NUMBER 3008008
112
-#define SQLITE_SOURCE_ID "2014-11-11 19:07:56 1412fcc480799ecbd68d44dd18d5bad40e20ccf1"
110
+#define SQLITE_VERSION "3.8.7.2"
111
+#define SQLITE_VERSION_NUMBER 3008007
112
+#define SQLITE_SOURCE_ID "2014-11-18 12:28:52 945a9e687fdfee5f7103d85d131024e85d594ac3"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -1502,31 +1502,29 @@
15021502
** it is not possible to set the Serialized [threading mode] and
15031503
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
15041504
** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
15051505
**
15061506
** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1507
-** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
1508
-** a pointer to an instance of the [sqlite3_mem_methods] structure.
1509
-** The argument specifies
1507
+** <dd> ^(This option takes a single argument which is a pointer to an
1508
+** instance of the [sqlite3_mem_methods] structure. The argument specifies
15101509
** alternative low-level memory allocation routines to be used in place of
15111510
** the memory allocation routines built into SQLite.)^ ^SQLite makes
15121511
** its own private copy of the content of the [sqlite3_mem_methods] structure
15131512
** before the [sqlite3_config()] call returns.</dd>
15141513
**
15151514
** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1516
-** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
1517
-** is a pointer to an instance of the [sqlite3_mem_methods] structure.
1518
-** The [sqlite3_mem_methods]
1515
+** <dd> ^(This option takes a single argument which is a pointer to an
1516
+** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
15191517
** structure is filled with the currently defined memory allocation routines.)^
15201518
** This option can be used to overload the default memory allocation
15211519
** routines with a wrapper that simulations memory allocation failure or
15221520
** tracks memory usage, for example. </dd>
15231521
**
15241522
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1525
-** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1526
-** interpreted as a boolean, which enables or disables the collection of
1527
-** memory allocation statistics. ^(When memory allocation statistics are disabled, the
1523
+** <dd> ^This option takes single argument of type int, interpreted as a
1524
+** boolean, which enables or disables the collection of memory allocation
1525
+** statistics. ^(When memory allocation statistics are disabled, the
15281526
** following SQLite interfaces become non-operational:
15291527
** <ul>
15301528
** <li> [sqlite3_memory_used()]
15311529
** <li> [sqlite3_memory_highwater()]
15321530
** <li> [sqlite3_soft_heap_limit64()]
@@ -1536,90 +1534,78 @@
15361534
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
15371535
** allocation statistics are disabled by default.
15381536
** </dd>
15391537
**
15401538
** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1541
-** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
1542
-** that SQLite can use for scratch memory. ^(There are three arguments
1543
-** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
1539
+** <dd> ^This option specifies a static memory buffer that SQLite can use for
1540
+** scratch memory. There are three arguments: A pointer an 8-byte
15441541
** aligned memory buffer from which the scratch allocations will be
15451542
** drawn, the size of each scratch allocation (sz),
1546
-** and the maximum number of scratch allocations (N).)^
1543
+** and the maximum number of scratch allocations (N). The sz
1544
+** argument must be a multiple of 16.
15471545
** The first argument must be a pointer to an 8-byte aligned buffer
15481546
** of at least sz*N bytes of memory.
1549
-** ^SQLite will not use more than one scratch buffers per thread.
1550
-** ^SQLite will never request a scratch buffer that is more than 6
1551
-** times the database page size.
1552
-** ^If SQLite needs needs additional
1547
+** ^SQLite will use no more than two scratch buffers per thread. So
1548
+** N should be set to twice the expected maximum number of threads.
1549
+** ^SQLite will never require a scratch buffer that is more than 6
1550
+** times the database page size. ^If SQLite needs needs additional
15531551
** scratch memory beyond what is provided by this configuration option, then
1554
-** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
1555
-** ^When the application provides any amount of scratch memory using
1556
-** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
1557
-** [sqlite3_malloc|heap allocations].
1558
-** This can help [Robson proof|prevent memory allocation failures] due to heap
1559
-** fragmentation in low-memory embedded systems.
1560
-** </dd>
1552
+** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
15611553
**
15621554
** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1563
-** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a static memory buffer
1564
-** that SQLite can use for the database page cache with the default page
1565
-** cache implementation.
1555
+** <dd> ^This option specifies a static memory buffer that SQLite can use for
1556
+** the database page cache with the default page cache implementation.
15661557
** This configuration should not be used if an application-define page
1567
-** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]
1568
-** configuration option.
1569
-** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned
1558
+** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option.
1559
+** There are three arguments to this option: A pointer to 8-byte aligned
15701560
** memory, the size of each page buffer (sz), and the number of pages (N).
15711561
** The sz argument should be the size of the largest database page
1572
-** (a power of two between 512 and 32768) plus some extra bytes for each
1573
-** page header. ^The number of extra bytes needed by the page header
1574
-** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1575
-** to [sqlite3_config()].
1576
-** ^It is harmless, apart from the wasted memory,
1577
-** for the sz parameter to be larger than necessary. The first
1578
-** argument should pointer to an 8-byte aligned block of memory that
1579
-** is at least sz*N bytes of memory, otherwise subsequent behavior is
1580
-** undefined.
1562
+** (a power of two between 512 and 32768) plus a little extra for each
1563
+** page header. ^The page header size is 20 to 40 bytes depending on
1564
+** the host architecture. ^It is harmless, apart from the wasted memory,
1565
+** to make sz a little too large. The first
1566
+** argument should point to an allocation of at least sz*N bytes of memory.
15811567
** ^SQLite will use the memory provided by the first argument to satisfy its
15821568
** memory needs for the first N pages that it adds to cache. ^If additional
15831569
** page cache memory is needed beyond what is provided by this option, then
1584
-** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd>
1570
+** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1571
+** The pointer in the first argument must
1572
+** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1573
+** will be undefined.</dd>
15851574
**
15861575
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1587
-** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
1588
-** that SQLite will use for all of its dynamic memory allocation needs
1589
-** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1590
-** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
1591
-** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
1592
-** [SQLITE_ERROR] if invoked otherwise.
1593
-** ^There are three arguments to SQLITE_CONFIG_HEAP:
1594
-** An 8-byte aligned pointer to the memory,
1576
+** <dd> ^This option specifies a static memory buffer that SQLite will use
1577
+** for all of its dynamic memory allocation needs beyond those provided
1578
+** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1579
+** There are three arguments: An 8-byte aligned pointer to the memory,
15951580
** the number of bytes in the memory buffer, and the minimum allocation size.
15961581
** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
15971582
** to using its default memory allocator (the system malloc() implementation),
15981583
** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1599
-** memory pointer is not NULL then the alternative memory
1584
+** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1585
+** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
16001586
** allocator is engaged to handle all of SQLites memory allocation needs.
16011587
** The first pointer (the memory pointer) must be aligned to an 8-byte
16021588
** boundary or subsequent behavior of SQLite will be undefined.
16031589
** The minimum allocation size is capped at 2**12. Reasonable values
16041590
** for the minimum allocation size are 2**5 through 2**8.</dd>
16051591
**
16061592
** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1607
-** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
1608
-** pointer to an instance of the [sqlite3_mutex_methods] structure.
1609
-** The argument specifies alternative low-level mutex routines to be used in place
1593
+** <dd> ^(This option takes a single argument which is a pointer to an
1594
+** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1595
+** alternative low-level mutex routines to be used in place
16101596
** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
16111597
** content of the [sqlite3_mutex_methods] structure before the call to
16121598
** [sqlite3_config()] returns. ^If SQLite is compiled with
16131599
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
16141600
** the entire mutexing subsystem is omitted from the build and hence calls to
16151601
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
16161602
** return [SQLITE_ERROR].</dd>
16171603
**
16181604
** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1619
-** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
1620
-** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
1605
+** <dd> ^(This option takes a single argument which is a pointer to an
1606
+** instance of the [sqlite3_mutex_methods] structure. The
16211607
** [sqlite3_mutex_methods]
16221608
** structure is filled with the currently defined mutex routines.)^
16231609
** This option can be used to overload the default mutex allocation
16241610
** routines with a wrapper used to track mutex usage for performance
16251611
** profiling or testing, for example. ^If SQLite is compiled with
@@ -1627,28 +1613,28 @@
16271613
** the entire mutexing subsystem is omitted from the build and hence calls to
16281614
** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
16291615
** return [SQLITE_ERROR].</dd>
16301616
**
16311617
** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1632
-** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
1633
-** the default size of lookaside memory on each [database connection].
1634
-** The first argument is the
1618
+** <dd> ^(This option takes two arguments that determine the default
1619
+** memory allocation for the lookaside memory allocator on each
1620
+** [database connection]. The first argument is the
16351621
** size of each lookaside buffer slot and the second is the number of
1636
-** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
1637
-** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1638
-** option to [sqlite3_db_config()] can be used to change the lookaside
1622
+** slots allocated to each database connection.)^ ^(This option sets the
1623
+** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1624
+** verb to [sqlite3_db_config()] can be used to change the lookaside
16391625
** configuration on individual connections.)^ </dd>
16401626
**
16411627
** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1642
-** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
1643
-** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
1644
-** the interface to a custom page cache implementation.)^
1645
-** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
1628
+** <dd> ^(This option takes a single argument which is a pointer to
1629
+** an [sqlite3_pcache_methods2] object. This object specifies the interface
1630
+** to a custom page cache implementation.)^ ^SQLite makes a copy of the
1631
+** object and uses it for page cache memory allocations.</dd>
16461632
**
16471633
** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1648
-** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
1649
-** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of the current
1634
+** <dd> ^(This option takes a single argument which is a pointer to an
1635
+** [sqlite3_pcache_methods2] object. SQLite copies of the current
16501636
** page cache implementation into that object.)^ </dd>
16511637
**
16521638
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
16531639
** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
16541640
** global [error log].
@@ -1668,27 +1654,26 @@
16681654
** supplied by the application must not invoke any SQLite interface.
16691655
** In a multi-threaded application, the application-defined logger
16701656
** function must be threadsafe. </dd>
16711657
**
16721658
** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1673
-** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
1674
-** If non-zero, then URI handling is globally enabled. If the parameter is zero,
1675
-** then URI handling is globally disabled.)^ ^If URI handling is globally enabled,
1676
-** all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
1659
+** <dd>^(This option takes a single argument of type int. If non-zero, then
1660
+** URI handling is globally enabled. If the parameter is zero, then URI handling
1661
+** is globally disabled.)^ ^If URI handling is globally enabled, all filenames
1662
+** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
16771663
** specified as part of [ATTACH] commands are interpreted as URIs, regardless
16781664
** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
16791665
** connection is opened. ^If it is globally disabled, filenames are
16801666
** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
16811667
** database connection is opened. ^(By default, URI handling is globally
16821668
** disabled. The default value may be changed by compiling with the
16831669
** [SQLITE_USE_URI] symbol defined.)^
16841670
**
16851671
** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1686
-** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
1687
-** argument which is interpreted as a boolean in order to enable or disable
1688
-** the use of covering indices for full table scans in the query optimizer.
1689
-** ^The default setting is determined
1672
+** <dd>^This option takes a single integer argument which is interpreted as
1673
+** a boolean in order to enable or disable the use of covering indices for
1674
+** full table scans in the query optimizer. ^The default setting is determined
16901675
** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
16911676
** if that compile-time option is omitted.
16921677
** The ability to disable the use of covering indices for full table scans
16931678
** is because some incorrectly coded legacy applications might malfunction
16941679
** when the optimization is enabled. Providing the ability to
@@ -1724,32 +1709,23 @@
17241709
** that are the default mmap size limit (the default setting for
17251710
** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
17261711
** ^The default setting can be overridden by each database connection using
17271712
** either the [PRAGMA mmap_size] command, or by using the
17281713
** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
1729
-** will be silently truncated if necessary so that it does not exceed the
1730
-** compile-time maximum mmap size set by the
1714
+** cannot be changed at run-time. Nor may the maximum allowed mmap size
1715
+** exceed the compile-time maximum mmap size set by the
17311716
** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
17321717
** ^If either argument to this option is negative, then that argument is
17331718
** changed to its compile-time default.
17341719
**
17351720
** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
17361721
** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1737
-** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
1738
-** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1739
-** ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1722
+** <dd>^This option is only available if SQLite is compiled for Windows
1723
+** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1724
+** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
17401725
** that specifies the maximum size of the created heap.
17411726
** </dl>
1742
-**
1743
-** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
1744
-** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
1745
-** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1746
-** is a pointer to an integer and writes into that integer the number of extra
1747
-** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. The amount of
1748
-** extra space required can change depending on the compiler,
1749
-** target platform, and SQLite version.
1750
-** </dl>
17511727
*/
17521728
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
17531729
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
17541730
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
17551731
#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
@@ -1770,11 +1746,10 @@
17701746
#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
17711747
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
17721748
#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
17731749
#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
17741750
#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1775
-#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
17761751
17771752
/*
17781753
** CAPI3REF: Database Connection Configuration Options
17791754
**
17801755
** These constants are the available integer configuration options that
@@ -1898,49 +1873,51 @@
18981873
SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
18991874
19001875
/*
19011876
** CAPI3REF: Count The Number Of Rows Modified
19021877
**
1903
-** ^This function returns the number of rows modified, inserted or
1904
-** deleted by the most recently completed INSERT, UPDATE or DELETE
1905
-** statement on the database connection specified by the only parameter.
1906
-** ^Executing any other type of SQL statement does not modify the value
1907
-** returned by this function.
1908
-**
1909
-** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
1910
-** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
1911
-** [foreign key actions] or [REPLACE] constraint resolution are not counted.
1912
-**
1913
-** Changes to a view that are intercepted by
1914
-** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
1915
-** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
1916
-** DELETE statement run on a view is always zero. Only changes made to real
1917
-** tables are counted.
1918
-**
1919
-** Things are more complicated if the sqlite3_changes() function is
1920
-** executed while a trigger program is running. This may happen if the
1921
-** program uses the [changes() SQL function], or if some other callback
1922
-** function invokes sqlite3_changes() directly. Essentially:
1923
-**
1924
-** <ul>
1925
-** <li> ^(Before entering a trigger program the value returned by
1926
-** sqlite3_changes() function is saved. After the trigger program
1927
-** has finished, the original value is restored.)^
1928
-**
1929
-** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
1930
-** statement sets the value returned by sqlite3_changes()
1931
-** upon completion as normal. Of course, this value will not include
1932
-** any changes performed by sub-triggers, as the sqlite3_changes()
1933
-** value will be saved and restored after each sub-trigger has run.)^
1934
-** </ul>
1935
-**
1936
-** ^This means that if the changes() SQL function (or similar) is used
1937
-** by the first INSERT, UPDATE or DELETE statement within a trigger, it
1938
-** returns the value as set when the calling statement began executing.
1939
-** ^If it is used by the second or subsequent such statement within a trigger
1940
-** program, the value returned reflects the number of rows modified by the
1941
-** previous INSERT, UPDATE or DELETE statement within the same trigger.
1878
+** ^This function returns the number of database rows that were changed
1879
+** or inserted or deleted by the most recently completed SQL statement
1880
+** on the [database connection] specified by the first parameter.
1881
+** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
1882
+** or [DELETE] statement are counted. Auxiliary changes caused by
1883
+** triggers or [foreign key actions] are not counted.)^ Use the
1884
+** [sqlite3_total_changes()] function to find the total number of changes
1885
+** including changes caused by triggers and foreign key actions.
1886
+**
1887
+** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
1888
+** are not counted. Only real table changes are counted.
1889
+**
1890
+** ^(A "row change" is a change to a single row of a single table
1891
+** caused by an INSERT, DELETE, or UPDATE statement. Rows that
1892
+** are changed as side effects of [REPLACE] constraint resolution,
1893
+** rollback, ABORT processing, [DROP TABLE], or by any other
1894
+** mechanisms do not count as direct row changes.)^
1895
+**
1896
+** A "trigger context" is a scope of execution that begins and
1897
+** ends with the script of a [CREATE TRIGGER | trigger].
1898
+** Most SQL statements are
1899
+** evaluated outside of any trigger. This is the "top level"
1900
+** trigger context. If a trigger fires from the top level, a
1901
+** new trigger context is entered for the duration of that one
1902
+** trigger. Subtriggers create subcontexts for their duration.
1903
+**
1904
+** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
1905
+** not create a new trigger context.
1906
+**
1907
+** ^This function returns the number of direct row changes in the
1908
+** most recent INSERT, UPDATE, or DELETE statement within the same
1909
+** trigger context.
1910
+**
1911
+** ^Thus, when called from the top level, this function returns the
1912
+** number of changes in the most recent INSERT, UPDATE, or DELETE
1913
+** that also occurred at the top level. ^(Within the body of a trigger,
1914
+** the sqlite3_changes() interface can be called to find the number of
1915
+** changes in the most recently completed INSERT, UPDATE, or DELETE
1916
+** statement within the body of the same trigger.
1917
+** However, the number returned does not include changes
1918
+** caused by subtriggers since those have their own context.)^
19421919
**
19431920
** See also the [sqlite3_total_changes()] interface, the
19441921
** [count_changes pragma], and the [changes() SQL function].
19451922
**
19461923
** If a separate thread makes changes on the same database connection
@@ -1950,21 +1927,24 @@
19501927
SQLITE_API int sqlite3_changes(sqlite3*);
19511928
19521929
/*
19531930
** CAPI3REF: Total Number Of Rows Modified
19541931
**
1955
-** ^This function returns the total number of rows inserted, modified or
1956
-** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
1957
-** since the database connection was opened, including those executed as
1958
-** part of trigger programs. ^Executing any other type of SQL statement
1959
-** does not affect the value returned by sqlite3_total_changes().
1960
-**
1961
-** ^Changes made as part of [foreign key actions] are included in the
1962
-** count, but those made as part of REPLACE constraint resolution are
1963
-** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
1964
-** are not counted.
1965
-**
1932
+** ^This function returns the number of row changes caused by [INSERT],
1933
+** [UPDATE] or [DELETE] statements since the [database connection] was opened.
1934
+** ^(The count returned by sqlite3_total_changes() includes all changes
1935
+** from all [CREATE TRIGGER | trigger] contexts and changes made by
1936
+** [foreign key actions]. However,
1937
+** the count does not include changes used to implement [REPLACE] constraints,
1938
+** do rollbacks or ABORT processing, or [DROP TABLE] processing. The
1939
+** count does not include rows of views that fire an [INSTEAD OF trigger],
1940
+** though if the INSTEAD OF trigger makes changes of its own, those changes
1941
+** are counted.)^
1942
+** ^The sqlite3_total_changes() function counts the changes as soon as
1943
+** the statement that makes them is completed (when the statement handle
1944
+** is passed to [sqlite3_reset()] or [sqlite3_finalize()]).
1945
+**
19661946
** See also the [sqlite3_changes()] interface, the
19671947
** [count_changes pragma], and the [total_changes() SQL function].
19681948
**
19691949
** If a separate thread makes changes on the same database connection
19701950
** while [sqlite3_total_changes()] is running then the value
@@ -2438,18 +2418,17 @@
24382418
** already uses the largest possible [ROWID]. The PRNG is also used for
24392419
** the build-in random() and randomblob() SQL functions. This interface allows
24402420
** applications to access the same PRNG for other purposes.
24412421
**
24422422
** ^A call to this routine stores N bytes of randomness into buffer P.
2443
-** ^The P parameter can be a NULL pointer.
2423
+** ^If N is less than one, then P can be a NULL pointer.
24442424
**
24452425
** ^If this routine has not been previously called or if the previous
2446
-** call had N less than one or a NULL pointer for P, then the PRNG is
2447
-** seeded using randomness obtained from the xRandomness method of
2448
-** the default [sqlite3_vfs] object.
2449
-** ^If the previous call to this routine had an N of 1 or more and a
2450
-** non-NULL P then the pseudo-randomness is generated
2426
+** call had N less than one, then the PRNG is seeded using randomness
2427
+** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2428
+** ^If the previous call to this routine had an N of 1 or more then
2429
+** the pseudo-randomness is generated
24512430
** internally and without recourse to the [sqlite3_vfs] xRandomness
24522431
** method.
24532432
*/
24542433
SQLITE_API void sqlite3_randomness(int N, void *P);
24552434
@@ -5660,46 +5639,30 @@
56605639
**
56615640
** <pre>
56625641
** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
56635642
** </pre>)^
56645643
**
5665
-** ^(Parameter zDb is not the filename that contains the database, but
5666
-** rather the symbolic name of the database. For attached databases, this is
5667
-** the name that appears after the AS keyword in the [ATTACH] statement.
5668
-** For the main database file, the database name is "main". For TEMP
5669
-** tables, the database name is "temp".)^
5670
-**
56715644
** ^If the flags parameter is non-zero, then the BLOB is opened for read
5672
-** and write access. ^If the flags parameter is zero, the BLOB is opened for
5673
-** read-only access.
5674
-**
5675
-** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
5676
-** in *ppBlob. Otherwise an [error code] is returned and, unless the error
5677
-** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
5678
-** the API is not misused, it is always safe to call [sqlite3_blob_close()]
5679
-** on *ppBlob after this function it returns.
5680
-**
5681
-** This function fails with SQLITE_ERROR if any of the following are true:
5682
-** <ul>
5683
-** <li> ^(Database zDb does not exist)^,
5684
-** <li> ^(Table zTable does not exist within database zDb)^,
5685
-** <li> ^(Table zTable is a WITHOUT ROWID table)^,
5686
-** <li> ^(Column zColumn does not exist)^,
5687
-** <li> ^(Row iRow is not present in the table)^,
5688
-** <li> ^(The specified column of row iRow contains a value that is not
5689
-** a TEXT or BLOB value)^,
5690
-** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
5691
-** constraint and the blob is being opened for read/write access)^,
5692
-** <li> ^([foreign key constraints | Foreign key constraints] are enabled,
5693
-** column zColumn is part of a [child key] definition and the blob is
5694
-** being opened for read/write access)^.
5695
-** </ul>
5696
-**
5697
-** ^Unless it returns SQLITE_MISUSE, this function sets the
5698
-** [database connection] error code and message accessible via
5699
-** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
5700
-**
5645
+** and write access. ^If it is zero, the BLOB is opened for read access.
5646
+** ^It is not possible to open a column that is part of an index or primary
5647
+** key for writing. ^If [foreign key constraints] are enabled, it is
5648
+** not possible to open a column that is part of a [child key] for writing.
5649
+**
5650
+** ^Note that the database name is not the filename that contains
5651
+** the database but rather the symbolic name of the database that
5652
+** appears after the AS keyword when the database is connected using [ATTACH].
5653
+** ^For the main database file, the database name is "main".
5654
+** ^For TEMP tables, the database name is "temp".
5655
+**
5656
+** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
5657
+** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set
5658
+** to be a null pointer.)^
5659
+** ^This function sets the [database connection] error code and message
5660
+** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related
5661
+** functions. ^Note that the *ppBlob variable is always initialized in a
5662
+** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob
5663
+** regardless of the success or failure of this routine.
57015664
**
57025665
** ^(If the row that a BLOB handle points to is modified by an
57035666
** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
57045667
** then the BLOB handle is marked as "expired".
57055668
** This is true if any column of the row is changed, even a column
@@ -5713,13 +5676,17 @@
57135676
** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
57145677
** the opened blob. ^The size of a blob may not be changed by this
57155678
** interface. Use the [UPDATE] SQL command to change the size of a
57165679
** blob.
57175680
**
5681
+** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
5682
+** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
5683
+**
57185684
** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5719
-** and the built-in [zeroblob] SQL function may be used to create a
5720
-** zero-filled blob to read or write using the incremental-blob interface.
5685
+** and the built-in [zeroblob] SQL function can be used, if desired,
5686
+** to create an empty, zero-filled blob in which to read or write using
5687
+** this interface.
57215688
**
57225689
** To avoid a resource leak, every open [BLOB handle] should eventually
57235690
** be released by a call to [sqlite3_blob_close()].
57245691
*/
57255692
SQLITE_API int sqlite3_blob_open(
@@ -5757,26 +5724,28 @@
57575724
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
57585725
57595726
/*
57605727
** CAPI3REF: Close A BLOB Handle
57615728
**
5762
-** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
5763
-** unconditionally. Even if this routine returns an error code, the
5764
-** handle is still closed.)^
5765
-**
5766
-** ^If the blob handle being closed was opened for read-write access, and if
5767
-** the database is in auto-commit mode and there are no other open read-write
5768
-** blob handles or active write statements, the current transaction is
5769
-** committed. ^If an error occurs while committing the transaction, an error
5770
-** code is returned and the transaction rolled back.
5771
-**
5772
-** Calling this function with an argument that is not a NULL pointer or an
5773
-** open blob handle results in undefined behaviour. ^Calling this routine
5774
-** with a null pointer (such as would be returned by a failed call to
5775
-** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
5776
-** is passed a valid open blob handle, the values returned by the
5777
-** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
5729
+** ^Closes an open [BLOB handle].
5730
+**
5731
+** ^Closing a BLOB shall cause the current transaction to commit
5732
+** if there are no other BLOBs, no pending prepared statements, and the
5733
+** database connection is in [autocommit mode].
5734
+** ^If any writes were made to the BLOB, they might be held in cache
5735
+** until the close operation if they will fit.
5736
+**
5737
+** ^(Closing the BLOB often forces the changes
5738
+** out to disk and so if any I/O errors occur, they will likely occur
5739
+** at the time when the BLOB is closed. Any errors that occur during
5740
+** closing are reported as a non-zero return value.)^
5741
+**
5742
+** ^(The BLOB is closed unconditionally. Even if this routine returns
5743
+** an error code, the BLOB is still closed.)^
5744
+**
5745
+** ^Calling this routine with a null pointer (such as would be returned
5746
+** by a failed call to [sqlite3_blob_open()]) is a harmless no-op.
57785747
*/
57795748
SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
57805749
57815750
/*
57825751
** CAPI3REF: Return The Size Of An Open BLOB
@@ -5822,39 +5791,36 @@
58225791
SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
58235792
58245793
/*
58255794
** CAPI3REF: Write Data Into A BLOB Incrementally
58265795
**
5827
-** ^(This function is used to write data into an open [BLOB handle] from a
5828
-** caller-supplied buffer. N bytes of data are copied from the buffer Z
5829
-** into the open BLOB, starting at offset iOffset.)^
5830
-**
5831
-** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5832
-** Otherwise, an [error code] or an [extended error code] is returned.)^
5833
-** ^Unless SQLITE_MISUSE is returned, this function sets the
5834
-** [database connection] error code and message accessible via
5835
-** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
5796
+** ^This function is used to write data into an open [BLOB handle] from a
5797
+** caller-supplied buffer. ^N bytes of data are copied from the buffer Z
5798
+** into the open BLOB, starting at offset iOffset.
58365799
**
58375800
** ^If the [BLOB handle] passed as the first argument was not opened for
58385801
** writing (the flags parameter to [sqlite3_blob_open()] was zero),
58395802
** this function returns [SQLITE_READONLY].
58405803
**
5841
-** This function may only modify the contents of the BLOB; it is
5804
+** ^This function may only modify the contents of the BLOB; it is
58425805
** not possible to increase the size of a BLOB using this API.
58435806
** ^If offset iOffset is less than N bytes from the end of the BLOB,
5844
-** [SQLITE_ERROR] is returned and no data is written. The size of the
5845
-** BLOB (and hence the maximum value of N+iOffset) can be determined
5846
-** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
5847
-** than zero [SQLITE_ERROR] is returned and no data is written.
5807
+** [SQLITE_ERROR] is returned and no data is written. ^If N is
5808
+** less than zero [SQLITE_ERROR] is returned and no data is written.
5809
+** The size of the BLOB (and hence the maximum value of N+iOffset)
5810
+** can be determined using the [sqlite3_blob_bytes()] interface.
58485811
**
58495812
** ^An attempt to write to an expired [BLOB handle] fails with an
58505813
** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
58515814
** before the [BLOB handle] expired are not rolled back by the
58525815
** expiration of the handle, though of course those changes might
58535816
** have been overwritten by the statement that expired the BLOB handle
58545817
** or by other independent statements.
58555818
**
5819
+** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5820
+** Otherwise, an [error code] or an [extended error code] is returned.)^
5821
+**
58565822
** This routine only works on a [BLOB handle] which has been created
58575823
** by a prior successful call to [sqlite3_blob_open()] and which has not
58585824
** been closed by [sqlite3_blob_close()]. Passing any other pointer in
58595825
** to this routine results in undefined and probably undesirable behavior.
58605826
**
@@ -7443,102 +7409,10 @@
74437409
/* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
74447410
#define SQLITE_FAIL 3
74457411
/* #define SQLITE_ABORT 4 // Also an error code */
74467412
#define SQLITE_REPLACE 5
74477413
7448
-/*
7449
-** CAPI3REF: Prepared Statement Scan Status Opcodes
7450
-** KEYWORDS: {scanstatus options}
7451
-**
7452
-** The following constants can be used for the T parameter to the
7453
-** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7454
-** different metric for sqlite3_stmt_scanstatus() to return.
7455
-**
7456
-** <dl>
7457
-** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7458
-** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the
7459
-** total number of times that the X-th loop has run.</dd>
7460
-**
7461
-** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
7462
-** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the
7463
-** total number of rows examined by all iterations of the X-th loop.</dd>
7464
-**
7465
-** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
7466
-** <dd>^The "double" variable pointed to by the T parameter will be set to the
7467
-** query planner's estimate for the average number of rows output from each
7468
-** iteration of the X-th loop. If the query planner's estimates was accurate,
7469
-** then this value will approximate the quotient NVISIT/NLOOP and the
7470
-** product of this value for all prior loops with the same SELECTID will
7471
-** be the NLOOP value for the current loop.
7472
-**
7473
-** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
7474
-** <dd>^The "const char *" variable pointed to by the T parameter will be set to
7475
-** a zero-terminated UTF-8 string containing the name of the index or table used
7476
-** for the X-th loop.
7477
-**
7478
-** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
7479
-** <dd>^The "const char *" variable pointed to by the T parameter will be set to
7480
-** a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] description
7481
-** for the X-th loop.
7482
-**
7483
-** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
7484
-** <dd>^The "int" variable pointed to by the T parameter will be set to the
7485
-** "select-id" for the X-th loop. The select-id identifies which query or
7486
-** subquery the loop is part of. The main query has a select-id of zero.
7487
-** The select-id is the same value as is output in the first column
7488
-** of an [EXPLAIN QUERY PLAN] query.
7489
-** </dl>
7490
-*/
7491
-#define SQLITE_SCANSTAT_NLOOP 0
7492
-#define SQLITE_SCANSTAT_NVISIT 1
7493
-#define SQLITE_SCANSTAT_EST 2
7494
-#define SQLITE_SCANSTAT_NAME 3
7495
-#define SQLITE_SCANSTAT_EXPLAIN 4
7496
-#define SQLITE_SCANSTAT_SELECTID 5
7497
-
7498
-/*
7499
-** CAPI3REF: Prepared Statement Scan Status
7500
-**
7501
-** Return status data for a single loop within query pStmt.
7502
-**
7503
-** The "iScanStatusOp" parameter determines which status information to return.
7504
-** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior of
7505
-** this interface is undefined.
7506
-** ^The requested measurement is written into a variable pointed to by
7507
-** the "pOut" parameter.
7508
-** Parameter "idx" identifies the specific loop to retrieve statistics for.
7509
-** Loops are numbered starting from zero. ^If idx is out of range - less than
7510
-** zero or greater than or equal to the total number of loops used to implement
7511
-** the statement - a non-zero value is returned and the variable that pOut
7512
-** points to is unchanged.
7513
-**
7514
-** ^Statistics might not be available for all loops in all statements. ^In cases
7515
-** where there exist loops with no available statistics, this function behaves
7516
-** as if the loop did not exist - it returns non-zero and leave the variable
7517
-** that pOut points to unchanged.
7518
-**
7519
-** This API is only available if the library is built with pre-processor
7520
-** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7521
-**
7522
-** See also: [sqlite3_stmt_scanstatus_reset()]
7523
-*/
7524
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7525
- sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7526
- int idx, /* Index of loop to report on */
7527
- int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
7528
- void *pOut /* Result written here */
7529
-);
7530
-
7531
-/*
7532
-** CAPI3REF: Zero Scan-Status Counters
7533
-**
7534
-** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7535
-**
7536
-** This API is only available if the library is built with pre-processor
7537
-** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7538
-*/
7539
-SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
75407414
75417415
75427416
/*
75437417
** Undo the hack that converts floating point types to integer for
75447418
** builds on processors without floating point support.
75457419
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -55,11 +55,11 @@
55
56
57 /*
58 ** These no-op macros are used in front of interfaces to mark those
59 ** interfaces as either deprecated or experimental. New applications
60 ** should not use deprecated interfaces - they are supported for backwards
61 ** compatibility only. Application writers should be aware that
62 ** experimental interfaces are subject to change in point releases.
63 **
64 ** These macros used to resolve to various kinds of compiler magic that
65 ** would generate warning messages when they were used. But that
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.8"
111 #define SQLITE_VERSION_NUMBER 3008008
112 #define SQLITE_SOURCE_ID "2014-11-11 19:07:56 1412fcc480799ecbd68d44dd18d5bad40e20ccf1"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -1502,31 +1502,29 @@
1502 ** it is not possible to set the Serialized [threading mode] and
1503 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1504 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1505 **
1506 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1507 ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
1508 ** a pointer to an instance of the [sqlite3_mem_methods] structure.
1509 ** The argument specifies
1510 ** alternative low-level memory allocation routines to be used in place of
1511 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1512 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1513 ** before the [sqlite3_config()] call returns.</dd>
1514 **
1515 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1516 ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
1517 ** is a pointer to an instance of the [sqlite3_mem_methods] structure.
1518 ** The [sqlite3_mem_methods]
1519 ** structure is filled with the currently defined memory allocation routines.)^
1520 ** This option can be used to overload the default memory allocation
1521 ** routines with a wrapper that simulations memory allocation failure or
1522 ** tracks memory usage, for example. </dd>
1523 **
1524 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1525 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1526 ** interpreted as a boolean, which enables or disables the collection of
1527 ** memory allocation statistics. ^(When memory allocation statistics are disabled, the
1528 ** following SQLite interfaces become non-operational:
1529 ** <ul>
1530 ** <li> [sqlite3_memory_used()]
1531 ** <li> [sqlite3_memory_highwater()]
1532 ** <li> [sqlite3_soft_heap_limit64()]
@@ -1536,90 +1534,78 @@
1536 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1537 ** allocation statistics are disabled by default.
1538 ** </dd>
1539 **
1540 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1541 ** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
1542 ** that SQLite can use for scratch memory. ^(There are three arguments
1543 ** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
1544 ** aligned memory buffer from which the scratch allocations will be
1545 ** drawn, the size of each scratch allocation (sz),
1546 ** and the maximum number of scratch allocations (N).)^
 
1547 ** The first argument must be a pointer to an 8-byte aligned buffer
1548 ** of at least sz*N bytes of memory.
1549 ** ^SQLite will not use more than one scratch buffers per thread.
1550 ** ^SQLite will never request a scratch buffer that is more than 6
1551 ** times the database page size.
1552 ** ^If SQLite needs needs additional
1553 ** scratch memory beyond what is provided by this configuration option, then
1554 ** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
1555 ** ^When the application provides any amount of scratch memory using
1556 ** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
1557 ** [sqlite3_malloc|heap allocations].
1558 ** This can help [Robson proof|prevent memory allocation failures] due to heap
1559 ** fragmentation in low-memory embedded systems.
1560 ** </dd>
1561 **
1562 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1563 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a static memory buffer
1564 ** that SQLite can use for the database page cache with the default page
1565 ** cache implementation.
1566 ** This configuration should not be used if an application-define page
1567 ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]
1568 ** configuration option.
1569 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned
1570 ** memory, the size of each page buffer (sz), and the number of pages (N).
1571 ** The sz argument should be the size of the largest database page
1572 ** (a power of two between 512 and 32768) plus some extra bytes for each
1573 ** page header. ^The number of extra bytes needed by the page header
1574 ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1575 ** to [sqlite3_config()].
1576 ** ^It is harmless, apart from the wasted memory,
1577 ** for the sz parameter to be larger than necessary. The first
1578 ** argument should pointer to an 8-byte aligned block of memory that
1579 ** is at least sz*N bytes of memory, otherwise subsequent behavior is
1580 ** undefined.
1581 ** ^SQLite will use the memory provided by the first argument to satisfy its
1582 ** memory needs for the first N pages that it adds to cache. ^If additional
1583 ** page cache memory is needed beyond what is provided by this option, then
1584 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd>
 
 
 
1585 **
1586 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1587 ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
1588 ** that SQLite will use for all of its dynamic memory allocation needs
1589 ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1590 ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
1591 ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
1592 ** [SQLITE_ERROR] if invoked otherwise.
1593 ** ^There are three arguments to SQLITE_CONFIG_HEAP:
1594 ** An 8-byte aligned pointer to the memory,
1595 ** the number of bytes in the memory buffer, and the minimum allocation size.
1596 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1597 ** to using its default memory allocator (the system malloc() implementation),
1598 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1599 ** memory pointer is not NULL then the alternative memory
 
1600 ** allocator is engaged to handle all of SQLites memory allocation needs.
1601 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1602 ** boundary or subsequent behavior of SQLite will be undefined.
1603 ** The minimum allocation size is capped at 2**12. Reasonable values
1604 ** for the minimum allocation size are 2**5 through 2**8.</dd>
1605 **
1606 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1607 ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
1608 ** pointer to an instance of the [sqlite3_mutex_methods] structure.
1609 ** The argument specifies alternative low-level mutex routines to be used in place
1610 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
1611 ** content of the [sqlite3_mutex_methods] structure before the call to
1612 ** [sqlite3_config()] returns. ^If SQLite is compiled with
1613 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1614 ** the entire mutexing subsystem is omitted from the build and hence calls to
1615 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1616 ** return [SQLITE_ERROR].</dd>
1617 **
1618 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1619 ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
1620 ** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
1621 ** [sqlite3_mutex_methods]
1622 ** structure is filled with the currently defined mutex routines.)^
1623 ** This option can be used to overload the default mutex allocation
1624 ** routines with a wrapper used to track mutex usage for performance
1625 ** profiling or testing, for example. ^If SQLite is compiled with
@@ -1627,28 +1613,28 @@
1627 ** the entire mutexing subsystem is omitted from the build and hence calls to
1628 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1629 ** return [SQLITE_ERROR].</dd>
1630 **
1631 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1632 ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
1633 ** the default size of lookaside memory on each [database connection].
1634 ** The first argument is the
1635 ** size of each lookaside buffer slot and the second is the number of
1636 ** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
1637 ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1638 ** option to [sqlite3_db_config()] can be used to change the lookaside
1639 ** configuration on individual connections.)^ </dd>
1640 **
1641 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1642 ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
1643 ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
1644 ** the interface to a custom page cache implementation.)^
1645 ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
1646 **
1647 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1648 ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
1649 ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of the current
1650 ** page cache implementation into that object.)^ </dd>
1651 **
1652 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1653 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
1654 ** global [error log].
@@ -1668,27 +1654,26 @@
1668 ** supplied by the application must not invoke any SQLite interface.
1669 ** In a multi-threaded application, the application-defined logger
1670 ** function must be threadsafe. </dd>
1671 **
1672 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1673 ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
1674 ** If non-zero, then URI handling is globally enabled. If the parameter is zero,
1675 ** then URI handling is globally disabled.)^ ^If URI handling is globally enabled,
1676 ** all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
1677 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1678 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1679 ** connection is opened. ^If it is globally disabled, filenames are
1680 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1681 ** database connection is opened. ^(By default, URI handling is globally
1682 ** disabled. The default value may be changed by compiling with the
1683 ** [SQLITE_USE_URI] symbol defined.)^
1684 **
1685 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1686 ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
1687 ** argument which is interpreted as a boolean in order to enable or disable
1688 ** the use of covering indices for full table scans in the query optimizer.
1689 ** ^The default setting is determined
1690 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
1691 ** if that compile-time option is omitted.
1692 ** The ability to disable the use of covering indices for full table scans
1693 ** is because some incorrectly coded legacy applications might malfunction
1694 ** when the optimization is enabled. Providing the ability to
@@ -1724,32 +1709,23 @@
1724 ** that are the default mmap size limit (the default setting for
1725 ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
1726 ** ^The default setting can be overridden by each database connection using
1727 ** either the [PRAGMA mmap_size] command, or by using the
1728 ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
1729 ** will be silently truncated if necessary so that it does not exceed the
1730 ** compile-time maximum mmap size set by the
1731 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
1732 ** ^If either argument to this option is negative, then that argument is
1733 ** changed to its compile-time default.
1734 **
1735 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
1736 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1737 ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
1738 ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1739 ** ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1740 ** that specifies the maximum size of the created heap.
1741 ** </dl>
1742 **
1743 ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
1744 ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
1745 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1746 ** is a pointer to an integer and writes into that integer the number of extra
1747 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. The amount of
1748 ** extra space required can change depending on the compiler,
1749 ** target platform, and SQLite version.
1750 ** </dl>
1751 */
1752 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1753 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1754 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
1755 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
@@ -1770,11 +1746,10 @@
1770 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1771 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1772 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1773 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1774 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1775 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
1776
1777 /*
1778 ** CAPI3REF: Database Connection Configuration Options
1779 **
1780 ** These constants are the available integer configuration options that
@@ -1898,49 +1873,51 @@
1898 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
1899
1900 /*
1901 ** CAPI3REF: Count The Number Of Rows Modified
1902 **
1903 ** ^This function returns the number of rows modified, inserted or
1904 ** deleted by the most recently completed INSERT, UPDATE or DELETE
1905 ** statement on the database connection specified by the only parameter.
1906 ** ^Executing any other type of SQL statement does not modify the value
1907 ** returned by this function.
1908 **
1909 ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
1910 ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
1911 ** [foreign key actions] or [REPLACE] constraint resolution are not counted.
1912 **
1913 ** Changes to a view that are intercepted by
1914 ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
1915 ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
1916 ** DELETE statement run on a view is always zero. Only changes made to real
1917 ** tables are counted.
1918 **
1919 ** Things are more complicated if the sqlite3_changes() function is
1920 ** executed while a trigger program is running. This may happen if the
1921 ** program uses the [changes() SQL function], or if some other callback
1922 ** function invokes sqlite3_changes() directly. Essentially:
1923 **
1924 ** <ul>
1925 ** <li> ^(Before entering a trigger program the value returned by
1926 ** sqlite3_changes() function is saved. After the trigger program
1927 ** has finished, the original value is restored.)^
1928 **
1929 ** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
1930 ** statement sets the value returned by sqlite3_changes()
1931 ** upon completion as normal. Of course, this value will not include
1932 ** any changes performed by sub-triggers, as the sqlite3_changes()
1933 ** value will be saved and restored after each sub-trigger has run.)^
1934 ** </ul>
1935 **
1936 ** ^This means that if the changes() SQL function (or similar) is used
1937 ** by the first INSERT, UPDATE or DELETE statement within a trigger, it
1938 ** returns the value as set when the calling statement began executing.
1939 ** ^If it is used by the second or subsequent such statement within a trigger
1940 ** program, the value returned reflects the number of rows modified by the
1941 ** previous INSERT, UPDATE or DELETE statement within the same trigger.
 
 
1942 **
1943 ** See also the [sqlite3_total_changes()] interface, the
1944 ** [count_changes pragma], and the [changes() SQL function].
1945 **
1946 ** If a separate thread makes changes on the same database connection
@@ -1950,21 +1927,24 @@
1950 SQLITE_API int sqlite3_changes(sqlite3*);
1951
1952 /*
1953 ** CAPI3REF: Total Number Of Rows Modified
1954 **
1955 ** ^This function returns the total number of rows inserted, modified or
1956 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
1957 ** since the database connection was opened, including those executed as
1958 ** part of trigger programs. ^Executing any other type of SQL statement
1959 ** does not affect the value returned by sqlite3_total_changes().
1960 **
1961 ** ^Changes made as part of [foreign key actions] are included in the
1962 ** count, but those made as part of REPLACE constraint resolution are
1963 ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
1964 ** are not counted.
1965 **
 
 
 
1966 ** See also the [sqlite3_changes()] interface, the
1967 ** [count_changes pragma], and the [total_changes() SQL function].
1968 **
1969 ** If a separate thread makes changes on the same database connection
1970 ** while [sqlite3_total_changes()] is running then the value
@@ -2438,18 +2418,17 @@
2438 ** already uses the largest possible [ROWID]. The PRNG is also used for
2439 ** the build-in random() and randomblob() SQL functions. This interface allows
2440 ** applications to access the same PRNG for other purposes.
2441 **
2442 ** ^A call to this routine stores N bytes of randomness into buffer P.
2443 ** ^The P parameter can be a NULL pointer.
2444 **
2445 ** ^If this routine has not been previously called or if the previous
2446 ** call had N less than one or a NULL pointer for P, then the PRNG is
2447 ** seeded using randomness obtained from the xRandomness method of
2448 ** the default [sqlite3_vfs] object.
2449 ** ^If the previous call to this routine had an N of 1 or more and a
2450 ** non-NULL P then the pseudo-randomness is generated
2451 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2452 ** method.
2453 */
2454 SQLITE_API void sqlite3_randomness(int N, void *P);
2455
@@ -5660,46 +5639,30 @@
5660 **
5661 ** <pre>
5662 ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
5663 ** </pre>)^
5664 **
5665 ** ^(Parameter zDb is not the filename that contains the database, but
5666 ** rather the symbolic name of the database. For attached databases, this is
5667 ** the name that appears after the AS keyword in the [ATTACH] statement.
5668 ** For the main database file, the database name is "main". For TEMP
5669 ** tables, the database name is "temp".)^
5670 **
5671 ** ^If the flags parameter is non-zero, then the BLOB is opened for read
5672 ** and write access. ^If the flags parameter is zero, the BLOB is opened for
5673 ** read-only access.
5674 **
5675 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
5676 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
5677 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
5678 ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
5679 ** on *ppBlob after this function it returns.
5680 **
5681 ** This function fails with SQLITE_ERROR if any of the following are true:
5682 ** <ul>
5683 ** <li> ^(Database zDb does not exist)^,
5684 ** <li> ^(Table zTable does not exist within database zDb)^,
5685 ** <li> ^(Table zTable is a WITHOUT ROWID table)^,
5686 ** <li> ^(Column zColumn does not exist)^,
5687 ** <li> ^(Row iRow is not present in the table)^,
5688 ** <li> ^(The specified column of row iRow contains a value that is not
5689 ** a TEXT or BLOB value)^,
5690 ** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
5691 ** constraint and the blob is being opened for read/write access)^,
5692 ** <li> ^([foreign key constraints | Foreign key constraints] are enabled,
5693 ** column zColumn is part of a [child key] definition and the blob is
5694 ** being opened for read/write access)^.
5695 ** </ul>
5696 **
5697 ** ^Unless it returns SQLITE_MISUSE, this function sets the
5698 ** [database connection] error code and message accessible via
5699 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
5700 **
5701 **
5702 ** ^(If the row that a BLOB handle points to is modified by an
5703 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
5704 ** then the BLOB handle is marked as "expired".
5705 ** This is true if any column of the row is changed, even a column
@@ -5713,13 +5676,17 @@
5713 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
5714 ** the opened blob. ^The size of a blob may not be changed by this
5715 ** interface. Use the [UPDATE] SQL command to change the size of a
5716 ** blob.
5717 **
 
 
 
5718 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5719 ** and the built-in [zeroblob] SQL function may be used to create a
5720 ** zero-filled blob to read or write using the incremental-blob interface.
 
5721 **
5722 ** To avoid a resource leak, every open [BLOB handle] should eventually
5723 ** be released by a call to [sqlite3_blob_close()].
5724 */
5725 SQLITE_API int sqlite3_blob_open(
@@ -5757,26 +5724,28 @@
5757 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5758
5759 /*
5760 ** CAPI3REF: Close A BLOB Handle
5761 **
5762 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
5763 ** unconditionally. Even if this routine returns an error code, the
5764 ** handle is still closed.)^
5765 **
5766 ** ^If the blob handle being closed was opened for read-write access, and if
5767 ** the database is in auto-commit mode and there are no other open read-write
5768 ** blob handles or active write statements, the current transaction is
5769 ** committed. ^If an error occurs while committing the transaction, an error
5770 ** code is returned and the transaction rolled back.
5771 **
5772 ** Calling this function with an argument that is not a NULL pointer or an
5773 ** open blob handle results in undefined behaviour. ^Calling this routine
5774 ** with a null pointer (such as would be returned by a failed call to
5775 ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
5776 ** is passed a valid open blob handle, the values returned by the
5777 ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
 
 
5778 */
5779 SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
5780
5781 /*
5782 ** CAPI3REF: Return The Size Of An Open BLOB
@@ -5822,39 +5791,36 @@
5822 SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5823
5824 /*
5825 ** CAPI3REF: Write Data Into A BLOB Incrementally
5826 **
5827 ** ^(This function is used to write data into an open [BLOB handle] from a
5828 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
5829 ** into the open BLOB, starting at offset iOffset.)^
5830 **
5831 ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5832 ** Otherwise, an [error code] or an [extended error code] is returned.)^
5833 ** ^Unless SQLITE_MISUSE is returned, this function sets the
5834 ** [database connection] error code and message accessible via
5835 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
5836 **
5837 ** ^If the [BLOB handle] passed as the first argument was not opened for
5838 ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
5839 ** this function returns [SQLITE_READONLY].
5840 **
5841 ** This function may only modify the contents of the BLOB; it is
5842 ** not possible to increase the size of a BLOB using this API.
5843 ** ^If offset iOffset is less than N bytes from the end of the BLOB,
5844 ** [SQLITE_ERROR] is returned and no data is written. The size of the
5845 ** BLOB (and hence the maximum value of N+iOffset) can be determined
5846 ** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
5847 ** than zero [SQLITE_ERROR] is returned and no data is written.
5848 **
5849 ** ^An attempt to write to an expired [BLOB handle] fails with an
5850 ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
5851 ** before the [BLOB handle] expired are not rolled back by the
5852 ** expiration of the handle, though of course those changes might
5853 ** have been overwritten by the statement that expired the BLOB handle
5854 ** or by other independent statements.
5855 **
 
 
 
5856 ** This routine only works on a [BLOB handle] which has been created
5857 ** by a prior successful call to [sqlite3_blob_open()] and which has not
5858 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
5859 ** to this routine results in undefined and probably undesirable behavior.
5860 **
@@ -7443,102 +7409,10 @@
7443 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
7444 #define SQLITE_FAIL 3
7445 /* #define SQLITE_ABORT 4 // Also an error code */
7446 #define SQLITE_REPLACE 5
7447
7448 /*
7449 ** CAPI3REF: Prepared Statement Scan Status Opcodes
7450 ** KEYWORDS: {scanstatus options}
7451 **
7452 ** The following constants can be used for the T parameter to the
7453 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7454 ** different metric for sqlite3_stmt_scanstatus() to return.
7455 **
7456 ** <dl>
7457 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7458 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the
7459 ** total number of times that the X-th loop has run.</dd>
7460 **
7461 ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
7462 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the
7463 ** total number of rows examined by all iterations of the X-th loop.</dd>
7464 **
7465 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
7466 ** <dd>^The "double" variable pointed to by the T parameter will be set to the
7467 ** query planner's estimate for the average number of rows output from each
7468 ** iteration of the X-th loop. If the query planner's estimates was accurate,
7469 ** then this value will approximate the quotient NVISIT/NLOOP and the
7470 ** product of this value for all prior loops with the same SELECTID will
7471 ** be the NLOOP value for the current loop.
7472 **
7473 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
7474 ** <dd>^The "const char *" variable pointed to by the T parameter will be set to
7475 ** a zero-terminated UTF-8 string containing the name of the index or table used
7476 ** for the X-th loop.
7477 **
7478 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
7479 ** <dd>^The "const char *" variable pointed to by the T parameter will be set to
7480 ** a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] description
7481 ** for the X-th loop.
7482 **
7483 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
7484 ** <dd>^The "int" variable pointed to by the T parameter will be set to the
7485 ** "select-id" for the X-th loop. The select-id identifies which query or
7486 ** subquery the loop is part of. The main query has a select-id of zero.
7487 ** The select-id is the same value as is output in the first column
7488 ** of an [EXPLAIN QUERY PLAN] query.
7489 ** </dl>
7490 */
7491 #define SQLITE_SCANSTAT_NLOOP 0
7492 #define SQLITE_SCANSTAT_NVISIT 1
7493 #define SQLITE_SCANSTAT_EST 2
7494 #define SQLITE_SCANSTAT_NAME 3
7495 #define SQLITE_SCANSTAT_EXPLAIN 4
7496 #define SQLITE_SCANSTAT_SELECTID 5
7497
7498 /*
7499 ** CAPI3REF: Prepared Statement Scan Status
7500 **
7501 ** Return status data for a single loop within query pStmt.
7502 **
7503 ** The "iScanStatusOp" parameter determines which status information to return.
7504 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior of
7505 ** this interface is undefined.
7506 ** ^The requested measurement is written into a variable pointed to by
7507 ** the "pOut" parameter.
7508 ** Parameter "idx" identifies the specific loop to retrieve statistics for.
7509 ** Loops are numbered starting from zero. ^If idx is out of range - less than
7510 ** zero or greater than or equal to the total number of loops used to implement
7511 ** the statement - a non-zero value is returned and the variable that pOut
7512 ** points to is unchanged.
7513 **
7514 ** ^Statistics might not be available for all loops in all statements. ^In cases
7515 ** where there exist loops with no available statistics, this function behaves
7516 ** as if the loop did not exist - it returns non-zero and leave the variable
7517 ** that pOut points to unchanged.
7518 **
7519 ** This API is only available if the library is built with pre-processor
7520 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7521 **
7522 ** See also: [sqlite3_stmt_scanstatus_reset()]
7523 */
7524 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7525 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7526 int idx, /* Index of loop to report on */
7527 int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
7528 void *pOut /* Result written here */
7529 );
7530
7531 /*
7532 ** CAPI3REF: Zero Scan-Status Counters
7533 **
7534 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7535 **
7536 ** This API is only available if the library is built with pre-processor
7537 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7538 */
7539 SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
7540
7541
7542 /*
7543 ** Undo the hack that converts floating point types to integer for
7544 ** builds on processors without floating point support.
7545
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -55,11 +55,11 @@
55
56
57 /*
58 ** These no-op macros are used in front of interfaces to mark those
59 ** interfaces as either deprecated or experimental. New applications
60 ** should not use deprecated interfaces - they are support for backwards
61 ** compatibility only. Application writers should be aware that
62 ** experimental interfaces are subject to change in point releases.
63 **
64 ** These macros used to resolve to various kinds of compiler magic that
65 ** would generate warning messages when they were used. But that
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.7.2"
111 #define SQLITE_VERSION_NUMBER 3008007
112 #define SQLITE_SOURCE_ID "2014-11-18 12:28:52 945a9e687fdfee5f7103d85d131024e85d594ac3"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -1502,31 +1502,29 @@
1502 ** it is not possible to set the Serialized [threading mode] and
1503 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1504 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1505 **
1506 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1507 ** <dd> ^(This option takes a single argument which is a pointer to an
1508 ** instance of the [sqlite3_mem_methods] structure. The argument specifies
 
1509 ** alternative low-level memory allocation routines to be used in place of
1510 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1511 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1512 ** before the [sqlite3_config()] call returns.</dd>
1513 **
1514 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1515 ** <dd> ^(This option takes a single argument which is a pointer to an
1516 ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
 
1517 ** structure is filled with the currently defined memory allocation routines.)^
1518 ** This option can be used to overload the default memory allocation
1519 ** routines with a wrapper that simulations memory allocation failure or
1520 ** tracks memory usage, for example. </dd>
1521 **
1522 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1523 ** <dd> ^This option takes single argument of type int, interpreted as a
1524 ** boolean, which enables or disables the collection of memory allocation
1525 ** statistics. ^(When memory allocation statistics are disabled, the
1526 ** following SQLite interfaces become non-operational:
1527 ** <ul>
1528 ** <li> [sqlite3_memory_used()]
1529 ** <li> [sqlite3_memory_highwater()]
1530 ** <li> [sqlite3_soft_heap_limit64()]
@@ -1536,90 +1534,78 @@
1534 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1535 ** allocation statistics are disabled by default.
1536 ** </dd>
1537 **
1538 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1539 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1540 ** scratch memory. There are three arguments: A pointer an 8-byte
 
1541 ** aligned memory buffer from which the scratch allocations will be
1542 ** drawn, the size of each scratch allocation (sz),
1543 ** and the maximum number of scratch allocations (N). The sz
1544 ** argument must be a multiple of 16.
1545 ** The first argument must be a pointer to an 8-byte aligned buffer
1546 ** of at least sz*N bytes of memory.
1547 ** ^SQLite will use no more than two scratch buffers per thread. So
1548 ** N should be set to twice the expected maximum number of threads.
1549 ** ^SQLite will never require a scratch buffer that is more than 6
1550 ** times the database page size. ^If SQLite needs needs additional
1551 ** scratch memory beyond what is provided by this configuration option, then
1552 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
 
 
 
 
 
 
1553 **
1554 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1555 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1556 ** the database page cache with the default page cache implementation.
 
1557 ** This configuration should not be used if an application-define page
1558 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option.
1559 ** There are three arguments to this option: A pointer to 8-byte aligned
 
1560 ** memory, the size of each page buffer (sz), and the number of pages (N).
1561 ** The sz argument should be the size of the largest database page
1562 ** (a power of two between 512 and 32768) plus a little extra for each
1563 ** page header. ^The page header size is 20 to 40 bytes depending on
1564 ** the host architecture. ^It is harmless, apart from the wasted memory,
1565 ** to make sz a little too large. The first
1566 ** argument should point to an allocation of at least sz*N bytes of memory.
 
 
 
 
1567 ** ^SQLite will use the memory provided by the first argument to satisfy its
1568 ** memory needs for the first N pages that it adds to cache. ^If additional
1569 ** page cache memory is needed beyond what is provided by this option, then
1570 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1571 ** The pointer in the first argument must
1572 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1573 ** will be undefined.</dd>
1574 **
1575 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1576 ** <dd> ^This option specifies a static memory buffer that SQLite will use
1577 ** for all of its dynamic memory allocation needs beyond those provided
1578 ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1579 ** There are three arguments: An 8-byte aligned pointer to the memory,
 
 
 
 
1580 ** the number of bytes in the memory buffer, and the minimum allocation size.
1581 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1582 ** to using its default memory allocator (the system malloc() implementation),
1583 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1584 ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1585 ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1586 ** allocator is engaged to handle all of SQLites memory allocation needs.
1587 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1588 ** boundary or subsequent behavior of SQLite will be undefined.
1589 ** The minimum allocation size is capped at 2**12. Reasonable values
1590 ** for the minimum allocation size are 2**5 through 2**8.</dd>
1591 **
1592 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1593 ** <dd> ^(This option takes a single argument which is a pointer to an
1594 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1595 ** alternative low-level mutex routines to be used in place
1596 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
1597 ** content of the [sqlite3_mutex_methods] structure before the call to
1598 ** [sqlite3_config()] returns. ^If SQLite is compiled with
1599 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1600 ** the entire mutexing subsystem is omitted from the build and hence calls to
1601 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1602 ** return [SQLITE_ERROR].</dd>
1603 **
1604 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1605 ** <dd> ^(This option takes a single argument which is a pointer to an
1606 ** instance of the [sqlite3_mutex_methods] structure. The
1607 ** [sqlite3_mutex_methods]
1608 ** structure is filled with the currently defined mutex routines.)^
1609 ** This option can be used to overload the default mutex allocation
1610 ** routines with a wrapper used to track mutex usage for performance
1611 ** profiling or testing, for example. ^If SQLite is compiled with
@@ -1627,28 +1613,28 @@
1613 ** the entire mutexing subsystem is omitted from the build and hence calls to
1614 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1615 ** return [SQLITE_ERROR].</dd>
1616 **
1617 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1618 ** <dd> ^(This option takes two arguments that determine the default
1619 ** memory allocation for the lookaside memory allocator on each
1620 ** [database connection]. The first argument is the
1621 ** size of each lookaside buffer slot and the second is the number of
1622 ** slots allocated to each database connection.)^ ^(This option sets the
1623 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1624 ** verb to [sqlite3_db_config()] can be used to change the lookaside
1625 ** configuration on individual connections.)^ </dd>
1626 **
1627 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1628 ** <dd> ^(This option takes a single argument which is a pointer to
1629 ** an [sqlite3_pcache_methods2] object. This object specifies the interface
1630 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the
1631 ** object and uses it for page cache memory allocations.</dd>
1632 **
1633 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1634 ** <dd> ^(This option takes a single argument which is a pointer to an
1635 ** [sqlite3_pcache_methods2] object. SQLite copies of the current
1636 ** page cache implementation into that object.)^ </dd>
1637 **
1638 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1639 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
1640 ** global [error log].
@@ -1668,27 +1654,26 @@
1654 ** supplied by the application must not invoke any SQLite interface.
1655 ** In a multi-threaded application, the application-defined logger
1656 ** function must be threadsafe. </dd>
1657 **
1658 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1659 ** <dd>^(This option takes a single argument of type int. If non-zero, then
1660 ** URI handling is globally enabled. If the parameter is zero, then URI handling
1661 ** is globally disabled.)^ ^If URI handling is globally enabled, all filenames
1662 ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
1663 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1664 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1665 ** connection is opened. ^If it is globally disabled, filenames are
1666 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1667 ** database connection is opened. ^(By default, URI handling is globally
1668 ** disabled. The default value may be changed by compiling with the
1669 ** [SQLITE_USE_URI] symbol defined.)^
1670 **
1671 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1672 ** <dd>^This option takes a single integer argument which is interpreted as
1673 ** a boolean in order to enable or disable the use of covering indices for
1674 ** full table scans in the query optimizer. ^The default setting is determined
 
1675 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
1676 ** if that compile-time option is omitted.
1677 ** The ability to disable the use of covering indices for full table scans
1678 ** is because some incorrectly coded legacy applications might malfunction
1679 ** when the optimization is enabled. Providing the ability to
@@ -1724,32 +1709,23 @@
1709 ** that are the default mmap size limit (the default setting for
1710 ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
1711 ** ^The default setting can be overridden by each database connection using
1712 ** either the [PRAGMA mmap_size] command, or by using the
1713 ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
1714 ** cannot be changed at run-time. Nor may the maximum allowed mmap size
1715 ** exceed the compile-time maximum mmap size set by the
1716 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
1717 ** ^If either argument to this option is negative, then that argument is
1718 ** changed to its compile-time default.
1719 **
1720 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
1721 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1722 ** <dd>^This option is only available if SQLite is compiled for Windows
1723 ** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1724 ** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1725 ** that specifies the maximum size of the created heap.
1726 ** </dl>
 
 
 
 
 
 
 
 
 
1727 */
1728 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1729 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1730 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
1731 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
@@ -1770,11 +1746,10 @@
1746 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1747 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1748 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1749 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1750 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
 
1751
1752 /*
1753 ** CAPI3REF: Database Connection Configuration Options
1754 **
1755 ** These constants are the available integer configuration options that
@@ -1898,49 +1873,51 @@
1873 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
1874
1875 /*
1876 ** CAPI3REF: Count The Number Of Rows Modified
1877 **
1878 ** ^This function returns the number of database rows that were changed
1879 ** or inserted or deleted by the most recently completed SQL statement
1880 ** on the [database connection] specified by the first parameter.
1881 ** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
1882 ** or [DELETE] statement are counted. Auxiliary changes caused by
1883 ** triggers or [foreign key actions] are not counted.)^ Use the
1884 ** [sqlite3_total_changes()] function to find the total number of changes
1885 ** including changes caused by triggers and foreign key actions.
1886 **
1887 ** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
1888 ** are not counted. Only real table changes are counted.
1889 **
1890 ** ^(A "row change" is a change to a single row of a single table
1891 ** caused by an INSERT, DELETE, or UPDATE statement. Rows that
1892 ** are changed as side effects of [REPLACE] constraint resolution,
1893 ** rollback, ABORT processing, [DROP TABLE], or by any other
1894 ** mechanisms do not count as direct row changes.)^
1895 **
1896 ** A "trigger context" is a scope of execution that begins and
1897 ** ends with the script of a [CREATE TRIGGER | trigger].
1898 ** Most SQL statements are
1899 ** evaluated outside of any trigger. This is the "top level"
1900 ** trigger context. If a trigger fires from the top level, a
1901 ** new trigger context is entered for the duration of that one
1902 ** trigger. Subtriggers create subcontexts for their duration.
1903 **
1904 ** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
1905 ** not create a new trigger context.
1906 **
1907 ** ^This function returns the number of direct row changes in the
1908 ** most recent INSERT, UPDATE, or DELETE statement within the same
1909 ** trigger context.
1910 **
1911 ** ^Thus, when called from the top level, this function returns the
1912 ** number of changes in the most recent INSERT, UPDATE, or DELETE
1913 ** that also occurred at the top level. ^(Within the body of a trigger,
1914 ** the sqlite3_changes() interface can be called to find the number of
1915 ** changes in the most recently completed INSERT, UPDATE, or DELETE
1916 ** statement within the body of the same trigger.
1917 ** However, the number returned does not include changes
1918 ** caused by subtriggers since those have their own context.)^
1919 **
1920 ** See also the [sqlite3_total_changes()] interface, the
1921 ** [count_changes pragma], and the [changes() SQL function].
1922 **
1923 ** If a separate thread makes changes on the same database connection
@@ -1950,21 +1927,24 @@
1927 SQLITE_API int sqlite3_changes(sqlite3*);
1928
1929 /*
1930 ** CAPI3REF: Total Number Of Rows Modified
1931 **
1932 ** ^This function returns the number of row changes caused by [INSERT],
1933 ** [UPDATE] or [DELETE] statements since the [database connection] was opened.
1934 ** ^(The count returned by sqlite3_total_changes() includes all changes
1935 ** from all [CREATE TRIGGER | trigger] contexts and changes made by
1936 ** [foreign key actions]. However,
1937 ** the count does not include changes used to implement [REPLACE] constraints,
1938 ** do rollbacks or ABORT processing, or [DROP TABLE] processing. The
1939 ** count does not include rows of views that fire an [INSTEAD OF trigger],
1940 ** though if the INSTEAD OF trigger makes changes of its own, those changes
1941 ** are counted.)^
1942 ** ^The sqlite3_total_changes() function counts the changes as soon as
1943 ** the statement that makes them is completed (when the statement handle
1944 ** is passed to [sqlite3_reset()] or [sqlite3_finalize()]).
1945 **
1946 ** See also the [sqlite3_changes()] interface, the
1947 ** [count_changes pragma], and the [total_changes() SQL function].
1948 **
1949 ** If a separate thread makes changes on the same database connection
1950 ** while [sqlite3_total_changes()] is running then the value
@@ -2438,18 +2418,17 @@
2418 ** already uses the largest possible [ROWID]. The PRNG is also used for
2419 ** the build-in random() and randomblob() SQL functions. This interface allows
2420 ** applications to access the same PRNG for other purposes.
2421 **
2422 ** ^A call to this routine stores N bytes of randomness into buffer P.
2423 ** ^If N is less than one, then P can be a NULL pointer.
2424 **
2425 ** ^If this routine has not been previously called or if the previous
2426 ** call had N less than one, then the PRNG is seeded using randomness
2427 ** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2428 ** ^If the previous call to this routine had an N of 1 or more then
2429 ** the pseudo-randomness is generated
 
2430 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2431 ** method.
2432 */
2433 SQLITE_API void sqlite3_randomness(int N, void *P);
2434
@@ -5660,46 +5639,30 @@
5639 **
5640 ** <pre>
5641 ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
5642 ** </pre>)^
5643 **
 
 
 
 
 
 
5644 ** ^If the flags parameter is non-zero, then the BLOB is opened for read
5645 ** and write access. ^If it is zero, the BLOB is opened for read access.
5646 ** ^It is not possible to open a column that is part of an index or primary
5647 ** key for writing. ^If [foreign key constraints] are enabled, it is
5648 ** not possible to open a column that is part of a [child key] for writing.
5649 **
5650 ** ^Note that the database name is not the filename that contains
5651 ** the database but rather the symbolic name of the database that
5652 ** appears after the AS keyword when the database is connected using [ATTACH].
5653 ** ^For the main database file, the database name is "main".
5654 ** ^For TEMP tables, the database name is "temp".
5655 **
5656 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
5657 ** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set
5658 ** to be a null pointer.)^
5659 ** ^This function sets the [database connection] error code and message
5660 ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related
5661 ** functions. ^Note that the *ppBlob variable is always initialized in a
5662 ** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob
5663 ** regardless of the success or failure of this routine.
 
 
 
 
 
 
 
 
 
 
5664 **
5665 ** ^(If the row that a BLOB handle points to is modified by an
5666 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
5667 ** then the BLOB handle is marked as "expired".
5668 ** This is true if any column of the row is changed, even a column
@@ -5713,13 +5676,17 @@
5676 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
5677 ** the opened blob. ^The size of a blob may not be changed by this
5678 ** interface. Use the [UPDATE] SQL command to change the size of a
5679 ** blob.
5680 **
5681 ** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
5682 ** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
5683 **
5684 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5685 ** and the built-in [zeroblob] SQL function can be used, if desired,
5686 ** to create an empty, zero-filled blob in which to read or write using
5687 ** this interface.
5688 **
5689 ** To avoid a resource leak, every open [BLOB handle] should eventually
5690 ** be released by a call to [sqlite3_blob_close()].
5691 */
5692 SQLITE_API int sqlite3_blob_open(
@@ -5757,26 +5724,28 @@
5724 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5725
5726 /*
5727 ** CAPI3REF: Close A BLOB Handle
5728 **
5729 ** ^Closes an open [BLOB handle].
5730 **
5731 ** ^Closing a BLOB shall cause the current transaction to commit
5732 ** if there are no other BLOBs, no pending prepared statements, and the
5733 ** database connection is in [autocommit mode].
5734 ** ^If any writes were made to the BLOB, they might be held in cache
5735 ** until the close operation if they will fit.
5736 **
5737 ** ^(Closing the BLOB often forces the changes
5738 ** out to disk and so if any I/O errors occur, they will likely occur
5739 ** at the time when the BLOB is closed. Any errors that occur during
5740 ** closing are reported as a non-zero return value.)^
5741 **
5742 ** ^(The BLOB is closed unconditionally. Even if this routine returns
5743 ** an error code, the BLOB is still closed.)^
5744 **
5745 ** ^Calling this routine with a null pointer (such as would be returned
5746 ** by a failed call to [sqlite3_blob_open()]) is a harmless no-op.
5747 */
5748 SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
5749
5750 /*
5751 ** CAPI3REF: Return The Size Of An Open BLOB
@@ -5822,39 +5791,36 @@
5791 SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5792
5793 /*
5794 ** CAPI3REF: Write Data Into A BLOB Incrementally
5795 **
5796 ** ^This function is used to write data into an open [BLOB handle] from a
5797 ** caller-supplied buffer. ^N bytes of data are copied from the buffer Z
5798 ** into the open BLOB, starting at offset iOffset.
 
 
 
 
 
 
5799 **
5800 ** ^If the [BLOB handle] passed as the first argument was not opened for
5801 ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
5802 ** this function returns [SQLITE_READONLY].
5803 **
5804 ** ^This function may only modify the contents of the BLOB; it is
5805 ** not possible to increase the size of a BLOB using this API.
5806 ** ^If offset iOffset is less than N bytes from the end of the BLOB,
5807 ** [SQLITE_ERROR] is returned and no data is written. ^If N is
5808 ** less than zero [SQLITE_ERROR] is returned and no data is written.
5809 ** The size of the BLOB (and hence the maximum value of N+iOffset)
5810 ** can be determined using the [sqlite3_blob_bytes()] interface.
5811 **
5812 ** ^An attempt to write to an expired [BLOB handle] fails with an
5813 ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
5814 ** before the [BLOB handle] expired are not rolled back by the
5815 ** expiration of the handle, though of course those changes might
5816 ** have been overwritten by the statement that expired the BLOB handle
5817 ** or by other independent statements.
5818 **
5819 ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5820 ** Otherwise, an [error code] or an [extended error code] is returned.)^
5821 **
5822 ** This routine only works on a [BLOB handle] which has been created
5823 ** by a prior successful call to [sqlite3_blob_open()] and which has not
5824 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
5825 ** to this routine results in undefined and probably undesirable behavior.
5826 **
@@ -7443,102 +7409,10 @@
7409 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
7410 #define SQLITE_FAIL 3
7411 /* #define SQLITE_ABORT 4 // Also an error code */
7412 #define SQLITE_REPLACE 5
7413
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7414
7415
7416 /*
7417 ** Undo the hack that converts floating point types to integer for
7418 ** builds on processors without floating point support.
7419

Keyboard Shortcuts

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