Fossil SCM

Merge the latest trunk changes into the search-with-fts4 branch.

drh 2015-01-14 12:55 UTC search-using-fts4 merge
Commit b429d53031de1ad262c07755d87e2fb0f26f87c9
+153 -38
--- src/branch.c
+++ src/branch.c
@@ -179,47 +179,67 @@
179179
180180
/* Do an autosync push, if requested */
181181
if( !isPrivate ) autosync_loop(SYNC_PUSH, db_get_int("autosync-tries", 1));
182182
}
183183
184
+#if INTERFACE
185
+/*
186
+** Allows bits in the mBplqFlags parameter to branch_prepare_list_query().
187
+*/
188
+#define BRL_CLOSED_ONLY 0x001 /* Show only closed branches */
189
+#define BRL_OPEN_ONLY 0x002 /* Show only open branches */
190
+#define BRL_BOTH 0x003 /* Show both open and closed branches */
191
+#define BRL_OPEN_CLOSED_MASK 0x003
192
+#define BRL_MTIME 0x004 /* Include lastest check-in time */
193
+#dfeine BRL_ORDERBY_MTIME 0x008 /* Sort by MTIME. (otherwise sort by name)*/
194
+
195
+#endif /* INTERFACE */
196
+
184197
/*
185198
** Prepare a query that will list branches.
186199
**
187200
** If (which<0) then the query pulls only closed branches. If
188201
** (which>0) then the query pulls all (closed and opened)
189202
** branches. Else the query pulls currently-opened branches.
190203
*/
191
-void branch_prepare_list_query(Stmt *pQuery, int which ){
192
- if( which < 0 ){
193
- db_prepare(pQuery,
194
- "SELECT value FROM tagxref"
195
- " WHERE tagid=%d AND value NOT NULL "
196
- "EXCEPT "
197
- "SELECT value FROM tagxref"
198
- " WHERE tagid=%d"
199
- " AND rid IN leaf"
200
- " AND NOT %z"
201
- " ORDER BY value COLLATE nocase /*sort*/",
202
- TAG_BRANCH, TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
203
- );
204
- }else if( which>0 ){
205
- db_prepare(pQuery,
206
- "SELECT DISTINCT value FROM tagxref"
207
- " WHERE tagid=%d AND value NOT NULL"
208
- " AND rid IN leaf"
209
- " ORDER BY value COLLATE nocase /*sort*/",
210
- TAG_BRANCH
211
- );
212
- }else{
213
- db_prepare(pQuery,
214
- "SELECT DISTINCT value FROM tagxref"
215
- " WHERE tagid=%d AND value NOT NULL"
216
- " AND rid IN leaf"
217
- " AND NOT %z"
218
- " ORDER BY value COLLATE nocase /*sort*/",
219
- TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
220
- );
204
+void branch_prepare_list_query(Stmt *pQuery, int brFlags){
205
+ switch( brFlags & BRL_OPEN_CLOSED_MASK ){
206
+ case BRL_CLOSED_ONLY: {
207
+ db_prepare(pQuery,
208
+ "SELECT value FROM tagxref"
209
+ " WHERE tagid=%d AND value NOT NULL "
210
+ "EXCEPT "
211
+ "SELECT value FROM tagxref"
212
+ " WHERE tagid=%d"
213
+ " AND rid IN leaf"
214
+ " AND NOT %z"
215
+ " ORDER BY value COLLATE nocase /*sort*/",
216
+ TAG_BRANCH, TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
217
+ );
218
+ break;
219
+ }
220
+ case BRL_BOTH: {
221
+ db_prepare(pQuery,
222
+ "SELECT DISTINCT value FROM tagxref"
223
+ " WHERE tagid=%d AND value NOT NULL"
224
+ " AND rid IN leaf"
225
+ " ORDER BY value COLLATE nocase /*sort*/",
226
+ TAG_BRANCH
227
+ );
228
+ break;
229
+ }
230
+ case BRL_OPEN_ONLY: {
231
+ db_prepare(pQuery,
232
+ "SELECT DISTINCT value FROM tagxref"
233
+ " WHERE tagid=%d AND value NOT NULL"
234
+ " AND rid IN leaf"
235
+ " AND NOT %z"
236
+ " ORDER BY value COLLATE nocase /*sort*/",
237
+ TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
238
+ );
239
+ break;
240
+ }
221241
}
222242
}
223243
224244
225245
/*
@@ -260,19 +280,20 @@
260280
branch_new();
261281
}else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){
262282
Stmt q;
263283
int vid;
264284
char *zCurrent = 0;
265
- int showAll = find_option("all","a",0)!=0;
266
- int showClosed = find_option("closed","c",0)!=0;
285
+ int brFlags = BRL_OPEN_ONLY;
286
+ if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH;
287
+ if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY;
267288
268289
if( g.localOpen ){
269290
vid = db_lget_int("checkout", 0);
270291
zCurrent = db_text(0, "SELECT value FROM tagxref"
271292
" WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
272293
}
273
- branch_prepare_list_query(&q, showAll?1:(showClosed?-1:0));
294
+ branch_prepare_list_query(&q, brFlags);
274295
while( db_step(&q)==SQLITE_ROW ){
275296
const char *zBr = db_column_text(&q, 0);
276297
int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
277298
fossil_print("%s%s\n", (isCur ? "* " : " "), zBr);
278299
}
@@ -280,36 +301,130 @@
280301
}else{
281302
fossil_fatal("branch subcommand should be one of: "
282303
"new list ls");
283304
}
284305
}
306
+
307
+static char brlistQuery[] =
308
+@ SELECT
309
+@ tagxref.value,
310
+@ max(event.mtime),
311
+@ EXISTS(SELECT 1 FROM tagxref AS tx
312
+@ WHERE tx.rid=tagxref.rid
313
+@ AND tx.tagid=(SELECT tagid FROM tag WHERE tagname='closed')
314
+@ AND tx.tagtype>0),
315
+@ (SELECT tagxref.value
316
+@ FROM plink CROSS JOIN tagxref
317
+@ WHERE plink.pid=event.objid
318
+@ AND tagxref.rid=plink.cid
319
+@ AND tagxref.tagid=(SELECT tagid FROM tag WHERE tagname='branch')
320
+@ AND tagtype>0),
321
+@ count(*),
322
+@ (SELECT uuid FROM blob WHERE rid=tagxref.rid)
323
+@ FROM tagxref, tag, event
324
+@ WHERE tagxref.tagid=tag.tagid
325
+@ AND tagxref.tagtype>0
326
+@ AND tag.tagname='branch'
327
+@ AND event.objid=tagxref.rid
328
+@ GROUP BY 1
329
+@ ORDER BY 2 DESC;
330
+;
331
+
332
+/*
333
+** This is the new-style branch-list page that shows the branch names
334
+** together with their ages (time of last check-in) and whether or not
335
+** they are closed or merged to another branch.
336
+**
337
+** Control jumps to this routine from brlist_page() (the /brlist handler)
338
+** if there are no query parameters.
339
+*/
340
+static void new_brlist_page(void){
341
+ Stmt q;
342
+ double rNow;
343
+ login_check_credentials();
344
+ if( !g.perm.Read ){ login_needed(); return; }
345
+ style_header("Branches");
346
+ login_anonymous_available();
347
+
348
+ db_prepare(&q, brlistQuery/*works-like:""*/);
349
+ rNow = db_double(0.0, "SELECT julianday('now')");
350
+ @ <div class="brlist"><table id="branchlisttable">
351
+ @ <thead><tr>
352
+ @ <th>Branch Name</th>
353
+ @ <th>Age</th>
354
+ @ <th>Checkins</th>
355
+ @ <th>Status</th>
356
+ @ <th>Resolution</th>
357
+ @ </tr></thead><tbody>
358
+ while( db_step(&q)==SQLITE_ROW ){
359
+ const char *zBranch = db_column_text(&q, 0);
360
+ double rMtime = db_column_double(&q, 1);
361
+ int isClosed = db_column_int(&q, 2);
362
+ const char *zMergeTo = db_column_text(&q, 3);
363
+ int nCkin = db_column_int(&q, 4);
364
+ const char *zLastCkin = db_column_text(&q, 5);
365
+ char *zAge = human_readable_age(rNow - rMtime);
366
+ sqlite3_int64 iMtime = (sqlite3_int64)(rMtime*86400.0);
367
+ if( zMergeTo && zMergeTo[0]==0 ) zMergeTo = 0;
368
+ @ <tr>
369
+ @ <td>%z(href("%R/timeline?n=100&r=%T",zBranch))%h(zBranch)</a></td>
370
+ @ <td data-sortkey="%016llx(-iMtime)">%s(zAge)</td>
371
+ @ <td data-sortkey="%08x(-nCkin)">%d(nCkin)</td>
372
+ fossil_free(zAge);
373
+ @ <td>%s(isClosed?"closed":"")</td>
374
+ if( zMergeTo ){
375
+ @ <td>merged into
376
+ @ %z(href("%R/timeline?f=%s",zLastCkin))%h(zMergeTo)</a></td>
377
+ }else{
378
+ @ <td></td>
379
+ }
380
+ @ </tr>
381
+ }
382
+ @ </tbody></table></div>
383
+ db_finalize(&q);
384
+ output_table_sorting_javascript("branchlisttable","tkktt",2);
385
+ style_footer();
386
+}
285387
286388
/*
287389
** WEBPAGE: brlist
390
+** Show a list of branches
391
+** Query parameters:
288392
**
289
-** Show a timeline of all branches
393
+** all Show all branches
394
+** closed Show only closed branches
395
+** open Show only open branches (default behavior)
396
+** colortest Show all branches with automatic color
290397
*/
291398
void brlist_page(void){
292399
Stmt q;
293400
int cnt;
294401
int showClosed = P("closed")!=0;
295402
int showAll = P("all")!=0;
403
+ int showOpen = P("open")!=0;
296404
int colorTest = P("colortest")!=0;
405
+ int brFlags = BRL_OPEN_ONLY;
297406
407
+ if( showClosed==0 && showAll==0 && showOpen==0 && colorTest==0 ){
408
+ new_brlist_page();
409
+ return;
410
+ }
298411
login_check_credentials();
299412
if( !g.perm.Read ){ login_needed(); return; }
300413
if( colorTest ){
301414
showClosed = 0;
302415
showAll = 1;
303416
}
417
+ if( showAll ) brFlags = BRL_BOTH;
418
+ if( showClosed ) brFlags = BRL_CLOSED_ONLY;
304419
305420
style_header("%s", showClosed ? "Closed Branches" :
306421
showAll ? "All Branches" : "Open Branches");
307422
style_submenu_element("Timeline", "Timeline", "brtimeline");
308423
if( showClosed ){
309424
style_submenu_element("All", "All", "brlist?all");
310
- style_submenu_element("Open","Open","brlist");
425
+ style_submenu_element("Open","Open","brlist?open");
311426
}else if( showAll ){
312427
style_submenu_element("Closed", "Closed", "brlist?closed");
313428
style_submenu_element("Open","Open","brlist");
314429
}else{
315430
style_submenu_element("All", "All", "brlist?all");
@@ -335,21 +450,21 @@
335450
@ Closed branches are fixed and do not change (unless they are first
336451
@ reopened).</li>
337452
@ </ol>
338453
style_sidebox_end();
339454
340
- branch_prepare_list_query(&q, showAll?1:(showClosed?-1:0));
455
+ branch_prepare_list_query(&q, brFlags);
341456
cnt = 0;
342457
while( db_step(&q)==SQLITE_ROW ){
343458
const char *zBr = db_column_text(&q, 0);
344459
if( cnt==0 ){
345460
if( colorTest ){
346461
@ <h2>Default background colors for all branches:</h2>
462
+ }else if( showClosed ){
463
+ @ <h2>Closed Branches:</h2>
347464
}else if( showAll ){
348465
@ <h2>All Branches:</h2>
349
- }else if( showClosed ){
350
- @ <h2>Closed Branches:</h2>
351466
}else{
352467
@ <h2>Open Branches:</h2>
353468
}
354469
@ <ul>
355470
cnt++;
356471
--- src/branch.c
+++ src/branch.c
@@ -179,47 +179,67 @@
179
180 /* Do an autosync push, if requested */
181 if( !isPrivate ) autosync_loop(SYNC_PUSH, db_get_int("autosync-tries", 1));
182 }
183
 
 
 
 
 
 
 
 
 
 
 
 
 
184 /*
185 ** Prepare a query that will list branches.
186 **
187 ** If (which<0) then the query pulls only closed branches. If
188 ** (which>0) then the query pulls all (closed and opened)
189 ** branches. Else the query pulls currently-opened branches.
190 */
191 void branch_prepare_list_query(Stmt *pQuery, int which ){
192 if( which < 0 ){
193 db_prepare(pQuery,
194 "SELECT value FROM tagxref"
195 " WHERE tagid=%d AND value NOT NULL "
196 "EXCEPT "
197 "SELECT value FROM tagxref"
198 " WHERE tagid=%d"
199 " AND rid IN leaf"
200 " AND NOT %z"
201 " ORDER BY value COLLATE nocase /*sort*/",
202 TAG_BRANCH, TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
203 );
204 }else if( which>0 ){
205 db_prepare(pQuery,
206 "SELECT DISTINCT value FROM tagxref"
207 " WHERE tagid=%d AND value NOT NULL"
208 " AND rid IN leaf"
209 " ORDER BY value COLLATE nocase /*sort*/",
210 TAG_BRANCH
211 );
212 }else{
213 db_prepare(pQuery,
214 "SELECT DISTINCT value FROM tagxref"
215 " WHERE tagid=%d AND value NOT NULL"
216 " AND rid IN leaf"
217 " AND NOT %z"
218 " ORDER BY value COLLATE nocase /*sort*/",
219 TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
220 );
 
 
 
 
 
 
 
221 }
222 }
223
224
225 /*
@@ -260,19 +280,20 @@
260 branch_new();
261 }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){
262 Stmt q;
263 int vid;
264 char *zCurrent = 0;
265 int showAll = find_option("all","a",0)!=0;
266 int showClosed = find_option("closed","c",0)!=0;
 
267
268 if( g.localOpen ){
269 vid = db_lget_int("checkout", 0);
270 zCurrent = db_text(0, "SELECT value FROM tagxref"
271 " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
272 }
273 branch_prepare_list_query(&q, showAll?1:(showClosed?-1:0));
274 while( db_step(&q)==SQLITE_ROW ){
275 const char *zBr = db_column_text(&q, 0);
276 int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
277 fossil_print("%s%s\n", (isCur ? "* " : " "), zBr);
278 }
@@ -280,36 +301,130 @@
280 }else{
281 fossil_fatal("branch subcommand should be one of: "
282 "new list ls");
283 }
284 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
286 /*
287 ** WEBPAGE: brlist
 
 
288 **
289 ** Show a timeline of all branches
 
 
 
290 */
291 void brlist_page(void){
292 Stmt q;
293 int cnt;
294 int showClosed = P("closed")!=0;
295 int showAll = P("all")!=0;
 
296 int colorTest = P("colortest")!=0;
 
297
 
 
 
 
298 login_check_credentials();
299 if( !g.perm.Read ){ login_needed(); return; }
300 if( colorTest ){
301 showClosed = 0;
302 showAll = 1;
303 }
 
 
304
305 style_header("%s", showClosed ? "Closed Branches" :
306 showAll ? "All Branches" : "Open Branches");
307 style_submenu_element("Timeline", "Timeline", "brtimeline");
308 if( showClosed ){
309 style_submenu_element("All", "All", "brlist?all");
310 style_submenu_element("Open","Open","brlist");
311 }else if( showAll ){
312 style_submenu_element("Closed", "Closed", "brlist?closed");
313 style_submenu_element("Open","Open","brlist");
314 }else{
315 style_submenu_element("All", "All", "brlist?all");
@@ -335,21 +450,21 @@
335 @ Closed branches are fixed and do not change (unless they are first
336 @ reopened).</li>
337 @ </ol>
338 style_sidebox_end();
339
340 branch_prepare_list_query(&q, showAll?1:(showClosed?-1:0));
341 cnt = 0;
342 while( db_step(&q)==SQLITE_ROW ){
343 const char *zBr = db_column_text(&q, 0);
344 if( cnt==0 ){
345 if( colorTest ){
346 @ <h2>Default background colors for all branches:</h2>
 
 
347 }else if( showAll ){
348 @ <h2>All Branches:</h2>
349 }else if( showClosed ){
350 @ <h2>Closed Branches:</h2>
351 }else{
352 @ <h2>Open Branches:</h2>
353 }
354 @ <ul>
355 cnt++;
356
--- src/branch.c
+++ src/branch.c
@@ -179,47 +179,67 @@
179
180 /* Do an autosync push, if requested */
181 if( !isPrivate ) autosync_loop(SYNC_PUSH, db_get_int("autosync-tries", 1));
182 }
183
184 #if INTERFACE
185 /*
186 ** Allows bits in the mBplqFlags parameter to branch_prepare_list_query().
187 */
188 #define BRL_CLOSED_ONLY 0x001 /* Show only closed branches */
189 #define BRL_OPEN_ONLY 0x002 /* Show only open branches */
190 #define BRL_BOTH 0x003 /* Show both open and closed branches */
191 #define BRL_OPEN_CLOSED_MASK 0x003
192 #define BRL_MTIME 0x004 /* Include lastest check-in time */
193 #dfeine BRL_ORDERBY_MTIME 0x008 /* Sort by MTIME. (otherwise sort by name)*/
194
195 #endif /* INTERFACE */
196
197 /*
198 ** Prepare a query that will list branches.
199 **
200 ** If (which<0) then the query pulls only closed branches. If
201 ** (which>0) then the query pulls all (closed and opened)
202 ** branches. Else the query pulls currently-opened branches.
203 */
204 void branch_prepare_list_query(Stmt *pQuery, int brFlags){
205 switch( brFlags & BRL_OPEN_CLOSED_MASK ){
206 case BRL_CLOSED_ONLY: {
207 db_prepare(pQuery,
208 "SELECT value FROM tagxref"
209 " WHERE tagid=%d AND value NOT NULL "
210 "EXCEPT "
211 "SELECT value FROM tagxref"
212 " WHERE tagid=%d"
213 " AND rid IN leaf"
214 " AND NOT %z"
215 " ORDER BY value COLLATE nocase /*sort*/",
216 TAG_BRANCH, TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
217 );
218 break;
219 }
220 case BRL_BOTH: {
221 db_prepare(pQuery,
222 "SELECT DISTINCT value FROM tagxref"
223 " WHERE tagid=%d AND value NOT NULL"
224 " AND rid IN leaf"
225 " ORDER BY value COLLATE nocase /*sort*/",
226 TAG_BRANCH
227 );
228 break;
229 }
230 case BRL_OPEN_ONLY: {
231 db_prepare(pQuery,
232 "SELECT DISTINCT value FROM tagxref"
233 " WHERE tagid=%d AND value NOT NULL"
234 " AND rid IN leaf"
235 " AND NOT %z"
236 " ORDER BY value COLLATE nocase /*sort*/",
237 TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
238 );
239 break;
240 }
241 }
242 }
243
244
245 /*
@@ -260,19 +280,20 @@
280 branch_new();
281 }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){
282 Stmt q;
283 int vid;
284 char *zCurrent = 0;
285 int brFlags = BRL_OPEN_ONLY;
286 if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH;
287 if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY;
288
289 if( g.localOpen ){
290 vid = db_lget_int("checkout", 0);
291 zCurrent = db_text(0, "SELECT value FROM tagxref"
292 " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
293 }
294 branch_prepare_list_query(&q, brFlags);
295 while( db_step(&q)==SQLITE_ROW ){
296 const char *zBr = db_column_text(&q, 0);
297 int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
298 fossil_print("%s%s\n", (isCur ? "* " : " "), zBr);
299 }
@@ -280,36 +301,130 @@
301 }else{
302 fossil_fatal("branch subcommand should be one of: "
303 "new list ls");
304 }
305 }
306
307 static char brlistQuery[] =
308 @ SELECT
309 @ tagxref.value,
310 @ max(event.mtime),
311 @ EXISTS(SELECT 1 FROM tagxref AS tx
312 @ WHERE tx.rid=tagxref.rid
313 @ AND tx.tagid=(SELECT tagid FROM tag WHERE tagname='closed')
314 @ AND tx.tagtype>0),
315 @ (SELECT tagxref.value
316 @ FROM plink CROSS JOIN tagxref
317 @ WHERE plink.pid=event.objid
318 @ AND tagxref.rid=plink.cid
319 @ AND tagxref.tagid=(SELECT tagid FROM tag WHERE tagname='branch')
320 @ AND tagtype>0),
321 @ count(*),
322 @ (SELECT uuid FROM blob WHERE rid=tagxref.rid)
323 @ FROM tagxref, tag, event
324 @ WHERE tagxref.tagid=tag.tagid
325 @ AND tagxref.tagtype>0
326 @ AND tag.tagname='branch'
327 @ AND event.objid=tagxref.rid
328 @ GROUP BY 1
329 @ ORDER BY 2 DESC;
330 ;
331
332 /*
333 ** This is the new-style branch-list page that shows the branch names
334 ** together with their ages (time of last check-in) and whether or not
335 ** they are closed or merged to another branch.
336 **
337 ** Control jumps to this routine from brlist_page() (the /brlist handler)
338 ** if there are no query parameters.
339 */
340 static void new_brlist_page(void){
341 Stmt q;
342 double rNow;
343 login_check_credentials();
344 if( !g.perm.Read ){ login_needed(); return; }
345 style_header("Branches");
346 login_anonymous_available();
347
348 db_prepare(&q, brlistQuery/*works-like:""*/);
349 rNow = db_double(0.0, "SELECT julianday('now')");
350 @ <div class="brlist"><table id="branchlisttable">
351 @ <thead><tr>
352 @ <th>Branch Name</th>
353 @ <th>Age</th>
354 @ <th>Checkins</th>
355 @ <th>Status</th>
356 @ <th>Resolution</th>
357 @ </tr></thead><tbody>
358 while( db_step(&q)==SQLITE_ROW ){
359 const char *zBranch = db_column_text(&q, 0);
360 double rMtime = db_column_double(&q, 1);
361 int isClosed = db_column_int(&q, 2);
362 const char *zMergeTo = db_column_text(&q, 3);
363 int nCkin = db_column_int(&q, 4);
364 const char *zLastCkin = db_column_text(&q, 5);
365 char *zAge = human_readable_age(rNow - rMtime);
366 sqlite3_int64 iMtime = (sqlite3_int64)(rMtime*86400.0);
367 if( zMergeTo && zMergeTo[0]==0 ) zMergeTo = 0;
368 @ <tr>
369 @ <td>%z(href("%R/timeline?n=100&r=%T",zBranch))%h(zBranch)</a></td>
370 @ <td data-sortkey="%016llx(-iMtime)">%s(zAge)</td>
371 @ <td data-sortkey="%08x(-nCkin)">%d(nCkin)</td>
372 fossil_free(zAge);
373 @ <td>%s(isClosed?"closed":"")</td>
374 if( zMergeTo ){
375 @ <td>merged into
376 @ %z(href("%R/timeline?f=%s",zLastCkin))%h(zMergeTo)</a></td>
377 }else{
378 @ <td></td>
379 }
380 @ </tr>
381 }
382 @ </tbody></table></div>
383 db_finalize(&q);
384 output_table_sorting_javascript("branchlisttable","tkktt",2);
385 style_footer();
386 }
387
388 /*
389 ** WEBPAGE: brlist
390 ** Show a list of branches
391 ** Query parameters:
392 **
393 ** all Show all branches
394 ** closed Show only closed branches
395 ** open Show only open branches (default behavior)
396 ** colortest Show all branches with automatic color
397 */
398 void brlist_page(void){
399 Stmt q;
400 int cnt;
401 int showClosed = P("closed")!=0;
402 int showAll = P("all")!=0;
403 int showOpen = P("open")!=0;
404 int colorTest = P("colortest")!=0;
405 int brFlags = BRL_OPEN_ONLY;
406
407 if( showClosed==0 && showAll==0 && showOpen==0 && colorTest==0 ){
408 new_brlist_page();
409 return;
410 }
411 login_check_credentials();
412 if( !g.perm.Read ){ login_needed(); return; }
413 if( colorTest ){
414 showClosed = 0;
415 showAll = 1;
416 }
417 if( showAll ) brFlags = BRL_BOTH;
418 if( showClosed ) brFlags = BRL_CLOSED_ONLY;
419
420 style_header("%s", showClosed ? "Closed Branches" :
421 showAll ? "All Branches" : "Open Branches");
422 style_submenu_element("Timeline", "Timeline", "brtimeline");
423 if( showClosed ){
424 style_submenu_element("All", "All", "brlist?all");
425 style_submenu_element("Open","Open","brlist?open");
426 }else if( showAll ){
427 style_submenu_element("Closed", "Closed", "brlist?closed");
428 style_submenu_element("Open","Open","brlist");
429 }else{
430 style_submenu_element("All", "All", "brlist?all");
@@ -335,21 +450,21 @@
450 @ Closed branches are fixed and do not change (unless they are first
451 @ reopened).</li>
452 @ </ol>
453 style_sidebox_end();
454
455 branch_prepare_list_query(&q, brFlags);
456 cnt = 0;
457 while( db_step(&q)==SQLITE_ROW ){
458 const char *zBr = db_column_text(&q, 0);
459 if( cnt==0 ){
460 if( colorTest ){
461 @ <h2>Default background colors for all branches:</h2>
462 }else if( showClosed ){
463 @ <h2>Closed Branches:</h2>
464 }else if( showAll ){
465 @ <h2>All Branches:</h2>
 
 
466 }else{
467 @ <h2>Open Branches:</h2>
468 }
469 @ <ul>
470 cnt++;
471
--- src/checkin.c
+++ src/checkin.c
@@ -498,10 +498,11 @@
498498
" ORDER BY 1",
499499
fossil_all_reserved_names(0)
500500
);
501501
db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
502502
blob_zero(&rewrittenPathname);
503
+ g.allowSymlinks = 1; /* Report on symbolic links */
503504
while( db_step(&q)==SQLITE_ROW ){
504505
zDisplayName = zPathname = db_column_text(&q, 0);
505506
if( cwdRelative ) {
506507
char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
507508
file_relative_name(zFullName, &rewrittenPathname, 0);
@@ -563,10 +564,11 @@
563564
** argument. Matching files, if any, are removed
564565
** prior to checking for any empty directories;
565566
** therefore, directories that contain only files
566567
** that were removed will be removed as well.
567568
** -f|--force Remove files without prompting.
569
+** --verily Shorthand for: -f --emptydirs --dotfiles
568570
** --clean <CSG> Never prompt for files matching this
569571
** comma separated list of glob patterns.
570572
** --ignore <CSG> Ignore files matching patterns from the
571573
** comma separated list of glob patterns.
572574
** --keep <CSG> Keep files matching this comma separated
@@ -601,10 +603,15 @@
601603
zIgnoreFlag = find_option("ignore",0,1);
602604
verboseFlag = find_option("verbose","v",0)!=0;
603605
zKeepFlag = find_option("keep",0,1);
604606
zCleanFlag = find_option("clean",0,1);
605607
db_must_be_within_tree();
608
+ if( find_option("verily",0,0)!=0 ){
609
+ allFileFlag = allDirFlag = 1;
610
+ emptyDirsFlag = 1;
611
+ scanFlags |= SCAN_ALL;
612
+ }
606613
if( zIgnoreFlag==0 ){
607614
zIgnoreFlag = db_get("ignore-glob", 0);
608615
}
609616
if( zKeepFlag==0 ){
610617
zKeepFlag = db_get("keep-glob", 0);
@@ -615,10 +622,11 @@
615622
verify_all_options();
616623
pIgnore = glob_create(zIgnoreFlag);
617624
pKeep = glob_create(zKeepFlag);
618625
pClean = glob_create(zCleanFlag);
619626
nRoot = (int)strlen(g.zLocalRoot);
627
+ g.allowSymlinks = 1; /* Find symlinks too */
620628
if( !dirsOnlyFlag ){
621629
Stmt q;
622630
Blob repo;
623631
locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore, 0);
624632
db_prepare(&q,
625633
--- src/checkin.c
+++ src/checkin.c
@@ -498,10 +498,11 @@
498 " ORDER BY 1",
499 fossil_all_reserved_names(0)
500 );
501 db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
502 blob_zero(&rewrittenPathname);
 
503 while( db_step(&q)==SQLITE_ROW ){
504 zDisplayName = zPathname = db_column_text(&q, 0);
505 if( cwdRelative ) {
506 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
507 file_relative_name(zFullName, &rewrittenPathname, 0);
@@ -563,10 +564,11 @@
563 ** argument. Matching files, if any, are removed
564 ** prior to checking for any empty directories;
565 ** therefore, directories that contain only files
566 ** that were removed will be removed as well.
567 ** -f|--force Remove files without prompting.
 
568 ** --clean <CSG> Never prompt for files matching this
569 ** comma separated list of glob patterns.
570 ** --ignore <CSG> Ignore files matching patterns from the
571 ** comma separated list of glob patterns.
572 ** --keep <CSG> Keep files matching this comma separated
@@ -601,10 +603,15 @@
601 zIgnoreFlag = find_option("ignore",0,1);
602 verboseFlag = find_option("verbose","v",0)!=0;
603 zKeepFlag = find_option("keep",0,1);
604 zCleanFlag = find_option("clean",0,1);
605 db_must_be_within_tree();
 
 
 
 
 
606 if( zIgnoreFlag==0 ){
607 zIgnoreFlag = db_get("ignore-glob", 0);
608 }
609 if( zKeepFlag==0 ){
610 zKeepFlag = db_get("keep-glob", 0);
@@ -615,10 +622,11 @@
615 verify_all_options();
616 pIgnore = glob_create(zIgnoreFlag);
617 pKeep = glob_create(zKeepFlag);
618 pClean = glob_create(zCleanFlag);
619 nRoot = (int)strlen(g.zLocalRoot);
 
620 if( !dirsOnlyFlag ){
621 Stmt q;
622 Blob repo;
623 locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore, 0);
624 db_prepare(&q,
625
--- src/checkin.c
+++ src/checkin.c
@@ -498,10 +498,11 @@
498 " ORDER BY 1",
499 fossil_all_reserved_names(0)
500 );
501 db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
502 blob_zero(&rewrittenPathname);
503 g.allowSymlinks = 1; /* Report on symbolic links */
504 while( db_step(&q)==SQLITE_ROW ){
505 zDisplayName = zPathname = db_column_text(&q, 0);
506 if( cwdRelative ) {
507 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
508 file_relative_name(zFullName, &rewrittenPathname, 0);
@@ -563,10 +564,11 @@
564 ** argument. Matching files, if any, are removed
565 ** prior to checking for any empty directories;
566 ** therefore, directories that contain only files
567 ** that were removed will be removed as well.
568 ** -f|--force Remove files without prompting.
569 ** --verily Shorthand for: -f --emptydirs --dotfiles
570 ** --clean <CSG> Never prompt for files matching this
571 ** comma separated list of glob patterns.
572 ** --ignore <CSG> Ignore files matching patterns from the
573 ** comma separated list of glob patterns.
574 ** --keep <CSG> Keep files matching this comma separated
@@ -601,10 +603,15 @@
603 zIgnoreFlag = find_option("ignore",0,1);
604 verboseFlag = find_option("verbose","v",0)!=0;
605 zKeepFlag = find_option("keep",0,1);
606 zCleanFlag = find_option("clean",0,1);
607 db_must_be_within_tree();
608 if( find_option("verily",0,0)!=0 ){
609 allFileFlag = allDirFlag = 1;
610 emptyDirsFlag = 1;
611 scanFlags |= SCAN_ALL;
612 }
613 if( zIgnoreFlag==0 ){
614 zIgnoreFlag = db_get("ignore-glob", 0);
615 }
616 if( zKeepFlag==0 ){
617 zKeepFlag = db_get("keep-glob", 0);
@@ -615,10 +622,11 @@
622 verify_all_options();
623 pIgnore = glob_create(zIgnoreFlag);
624 pKeep = glob_create(zKeepFlag);
625 pClean = glob_create(zCleanFlag);
626 nRoot = (int)strlen(g.zLocalRoot);
627 g.allowSymlinks = 1; /* Find symlinks too */
628 if( !dirsOnlyFlag ){
629 Stmt q;
630 Blob repo;
631 locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore, 0);
632 db_prepare(&q,
633
+7 -4
--- src/clone.c
+++ src/clone.c
@@ -110,23 +110,26 @@
110110
** --once Don't save url.
111111
** --private Also clone private branches
112112
** --ssl-identity=filename Use the SSL identity if requested by the server
113113
** --ssh-command|-c 'command' Use this SSH command
114114
** --httpauth|-B 'user:pass' Add HTTP Basic Authorization to requests
115
+** --verbose Show more statistics in output
115116
**
116117
** See also: init
117118
*/
118119
void clone_cmd(void){
119120
char *zPassword;
120121
const char *zDefaultUser; /* Optional name of the default user */
121122
const char *zHttpAuth; /* HTTP Authorization user:pass information */
122123
int nErr = 0;
123
- int bPrivate = 0; /* Also clone private branches */
124124
int urlFlags = URL_PROMPT_PW | URL_REMEMBER;
125
+ int syncFlags = SYNC_CLONE;
125126
126
- if( find_option("private",0,0)!=0 ) bPrivate = SYNC_PRIVATE;
127
+ /* Also clone private branches */
128
+ if( find_option("private",0,0)!=0 ) syncFlags |= SYNC_PRIVATE;
127129
if( find_option("once",0,0)!=0) urlFlags &= ~URL_REMEMBER;
130
+ if( find_option("verbose",0,0)!=0) syncFlags |= SYNC_VERBOSE;
128131
zHttpAuth = find_option("httpauth","B",1);
129132
zDefaultUser = find_option("admin-user","A",1);
130133
clone_ssh_find_options();
131134
url_proxy_options();
132135
@@ -147,11 +150,11 @@
147150
file_copy(g.url.name, g.argv[3]);
148151
db_close(1);
149152
db_open_repository(g.argv[3]);
150153
db_record_repository_filename(g.argv[3]);
151154
url_remember();
152
- if( !bPrivate ) delete_private_content();
155
+ if( !(syncFlags & SYNC_PRIVATE) ) delete_private_content();
153156
shun_artifacts();
154157
db_create_default_users(1, zDefaultUser);
155158
if( zDefaultUser ){
156159
g.zLogin = zDefaultUser;
157160
}else{
@@ -184,11 +187,11 @@
184187
);
185188
url_enable_proxy(0);
186189
clone_ssh_db_set_options();
187190
url_get_password_if_needed();
188191
g.xlinkClusterOnly = 1;
189
- nErr = client_sync(SYNC_CLONE | bPrivate,CONFIGSET_ALL,0);
192
+ nErr = client_sync(syncFlags,CONFIGSET_ALL,0);
190193
g.xlinkClusterOnly = 0;
191194
verify_cancel();
192195
db_end_transaction(0);
193196
db_close(1);
194197
if( nErr ){
195198
--- src/clone.c
+++ src/clone.c
@@ -110,23 +110,26 @@
110 ** --once Don't save url.
111 ** --private Also clone private branches
112 ** --ssl-identity=filename Use the SSL identity if requested by the server
113 ** --ssh-command|-c 'command' Use this SSH command
114 ** --httpauth|-B 'user:pass' Add HTTP Basic Authorization to requests
 
115 **
116 ** See also: init
117 */
118 void clone_cmd(void){
119 char *zPassword;
120 const char *zDefaultUser; /* Optional name of the default user */
121 const char *zHttpAuth; /* HTTP Authorization user:pass information */
122 int nErr = 0;
123 int bPrivate = 0; /* Also clone private branches */
124 int urlFlags = URL_PROMPT_PW | URL_REMEMBER;
 
125
126 if( find_option("private",0,0)!=0 ) bPrivate = SYNC_PRIVATE;
 
127 if( find_option("once",0,0)!=0) urlFlags &= ~URL_REMEMBER;
 
128 zHttpAuth = find_option("httpauth","B",1);
129 zDefaultUser = find_option("admin-user","A",1);
130 clone_ssh_find_options();
131 url_proxy_options();
132
@@ -147,11 +150,11 @@
147 file_copy(g.url.name, g.argv[3]);
148 db_close(1);
149 db_open_repository(g.argv[3]);
150 db_record_repository_filename(g.argv[3]);
151 url_remember();
152 if( !bPrivate ) delete_private_content();
153 shun_artifacts();
154 db_create_default_users(1, zDefaultUser);
155 if( zDefaultUser ){
156 g.zLogin = zDefaultUser;
157 }else{
@@ -184,11 +187,11 @@
184 );
185 url_enable_proxy(0);
186 clone_ssh_db_set_options();
187 url_get_password_if_needed();
188 g.xlinkClusterOnly = 1;
189 nErr = client_sync(SYNC_CLONE | bPrivate,CONFIGSET_ALL,0);
190 g.xlinkClusterOnly = 0;
191 verify_cancel();
192 db_end_transaction(0);
193 db_close(1);
194 if( nErr ){
195
--- src/clone.c
+++ src/clone.c
@@ -110,23 +110,26 @@
110 ** --once Don't save url.
111 ** --private Also clone private branches
112 ** --ssl-identity=filename Use the SSL identity if requested by the server
113 ** --ssh-command|-c 'command' Use this SSH command
114 ** --httpauth|-B 'user:pass' Add HTTP Basic Authorization to requests
115 ** --verbose Show more statistics in output
116 **
117 ** See also: init
118 */
119 void clone_cmd(void){
120 char *zPassword;
121 const char *zDefaultUser; /* Optional name of the default user */
122 const char *zHttpAuth; /* HTTP Authorization user:pass information */
123 int nErr = 0;
 
124 int urlFlags = URL_PROMPT_PW | URL_REMEMBER;
125 int syncFlags = SYNC_CLONE;
126
127 /* Also clone private branches */
128 if( find_option("private",0,0)!=0 ) syncFlags |= SYNC_PRIVATE;
129 if( find_option("once",0,0)!=0) urlFlags &= ~URL_REMEMBER;
130 if( find_option("verbose",0,0)!=0) syncFlags |= SYNC_VERBOSE;
131 zHttpAuth = find_option("httpauth","B",1);
132 zDefaultUser = find_option("admin-user","A",1);
133 clone_ssh_find_options();
134 url_proxy_options();
135
@@ -147,11 +150,11 @@
150 file_copy(g.url.name, g.argv[3]);
151 db_close(1);
152 db_open_repository(g.argv[3]);
153 db_record_repository_filename(g.argv[3]);
154 url_remember();
155 if( !(syncFlags & SYNC_PRIVATE) ) delete_private_content();
156 shun_artifacts();
157 db_create_default_users(1, zDefaultUser);
158 if( zDefaultUser ){
159 g.zLogin = zDefaultUser;
160 }else{
@@ -184,11 +187,11 @@
187 );
188 url_enable_proxy(0);
189 clone_ssh_db_set_options();
190 url_get_password_if_needed();
191 g.xlinkClusterOnly = 1;
192 nErr = client_sync(syncFlags,CONFIGSET_ALL,0);
193 g.xlinkClusterOnly = 0;
194 verify_cancel();
195 db_end_transaction(0);
196 db_close(1);
197 if( nErr ){
198
+7 -2
--- src/http.c
+++ src/http.c
@@ -205,11 +205,12 @@
205205
int http_exchange(Blob *pSend, Blob *pReply, int useLogin, int maxRedirect){
206206
Blob login; /* The login card */
207207
Blob payload; /* The complete payload including login card */
208208
Blob hdr; /* The HTTP request header */
209209
int closeConnection; /* True to close the connection when done */
210
- int iLength; /* Length of the reply payload */
210
+ int iLength; /* Expected length of the reply payload */
211
+ int iRecvLen; /* Received length of the reply payload */
211212
int rc = 0; /* Result code */
212213
int iHttpVersion; /* Which version of HTTP protocol server uses */
213214
char *zLine; /* A single line of the reply header */
214215
int i; /* Loop counter */
215216
int isError = 0; /* True if the reply is an error message */
@@ -370,11 +371,15 @@
370371
/*
371372
** Extract the reply payload that follows the header
372373
*/
373374
blob_zero(pReply);
374375
blob_resize(pReply, iLength);
375
- iLength = transport_receive(&g.url, blob_buffer(pReply), iLength);
376
+ iRecvLen = transport_receive(&g.url, blob_buffer(pReply), iLength);
377
+ if( iRecvLen != iLength ){
378
+ fossil_warning("response truncated: got %d bytes of %d", iRecvLen, iLength);
379
+ goto write_err;
380
+ }
376381
blob_resize(pReply, iLength);
377382
if( isError ){
378383
char *z;
379384
int i, j;
380385
z = blob_str(pReply);
381386
--- src/http.c
+++ src/http.c
@@ -205,11 +205,12 @@
205 int http_exchange(Blob *pSend, Blob *pReply, int useLogin, int maxRedirect){
206 Blob login; /* The login card */
207 Blob payload; /* The complete payload including login card */
208 Blob hdr; /* The HTTP request header */
209 int closeConnection; /* True to close the connection when done */
210 int iLength; /* Length of the reply payload */
 
211 int rc = 0; /* Result code */
212 int iHttpVersion; /* Which version of HTTP protocol server uses */
213 char *zLine; /* A single line of the reply header */
214 int i; /* Loop counter */
215 int isError = 0; /* True if the reply is an error message */
@@ -370,11 +371,15 @@
370 /*
371 ** Extract the reply payload that follows the header
372 */
373 blob_zero(pReply);
374 blob_resize(pReply, iLength);
375 iLength = transport_receive(&g.url, blob_buffer(pReply), iLength);
 
 
 
 
376 blob_resize(pReply, iLength);
377 if( isError ){
378 char *z;
379 int i, j;
380 z = blob_str(pReply);
381
--- src/http.c
+++ src/http.c
@@ -205,11 +205,12 @@
205 int http_exchange(Blob *pSend, Blob *pReply, int useLogin, int maxRedirect){
206 Blob login; /* The login card */
207 Blob payload; /* The complete payload including login card */
208 Blob hdr; /* The HTTP request header */
209 int closeConnection; /* True to close the connection when done */
210 int iLength; /* Expected length of the reply payload */
211 int iRecvLen; /* Received length of the reply payload */
212 int rc = 0; /* Result code */
213 int iHttpVersion; /* Which version of HTTP protocol server uses */
214 char *zLine; /* A single line of the reply header */
215 int i; /* Loop counter */
216 int isError = 0; /* True if the reply is an error message */
@@ -370,11 +371,15 @@
371 /*
372 ** Extract the reply payload that follows the header
373 */
374 blob_zero(pReply);
375 blob_resize(pReply, iLength);
376 iRecvLen = transport_receive(&g.url, blob_buffer(pReply), iLength);
377 if( iRecvLen != iLength ){
378 fossil_warning("response truncated: got %d bytes of %d", iRecvLen, iLength);
379 goto write_err;
380 }
381 blob_resize(pReply, iLength);
382 if( isError ){
383 char *z;
384 int i, j;
385 z = blob_str(pReply);
386
--- src/json_branch.c
+++ src/json_branch.c
@@ -66,11 +66,11 @@
6666
cson_value * payV;
6767
cson_object * pay;
6868
cson_value * listV;
6969
cson_array * list;
7070
char const * range = NULL;
71
- int which = 0;
71
+ int branchListFlags = BRL_OPEN_ONLY;
7272
char * sawConversionError = NULL;
7373
Stmt q;
7474
if( !g.perm.Read ){
7575
json_set_err(FSL_JSON_E_DENIED,
7676
"Requires 'o' permissions.");
@@ -102,19 +102,19 @@
102102
}
103103
/* Normalize range values... */
104104
switch(*range){
105105
case 'c':
106106
range = "closed";
107
- which = -1;
107
+ branchListFlags = BRL_CLOSED_ONLY;
108108
break;
109109
case 'a':
110110
range = "all";
111
- which = 1;
111
+ branchListFlags = BRL_BOTH;
112112
break;
113113
default:
114114
range = "open";
115
- which = 0;
115
+ branchListFlags = BRL_OPEN_ONLY;
116116
break;
117117
};
118118
cson_object_set(pay,"range",json_new_string(range));
119119
120120
if( g.localOpen ){ /* add "current" property (branch name). */
@@ -128,11 +128,11 @@
128128
cson_object_set(pay,"current",json_new_string(zCurrent));
129129
}
130130
}
131131
132132
133
- branch_prepare_list_query(&q, which);
133
+ branch_prepare_list_query(&q, branchListFlags);
134134
cson_object_set(pay,"branches",listV);
135135
while((SQLITE_ROW==db_step(&q))){
136136
cson_value * v = cson_sqlite3_column_to_value(q.pStmt,0);
137137
if(v){
138138
cson_array_append(list,v);
139139
--- src/json_branch.c
+++ src/json_branch.c
@@ -66,11 +66,11 @@
66 cson_value * payV;
67 cson_object * pay;
68 cson_value * listV;
69 cson_array * list;
70 char const * range = NULL;
71 int which = 0;
72 char * sawConversionError = NULL;
73 Stmt q;
74 if( !g.perm.Read ){
75 json_set_err(FSL_JSON_E_DENIED,
76 "Requires 'o' permissions.");
@@ -102,19 +102,19 @@
102 }
103 /* Normalize range values... */
104 switch(*range){
105 case 'c':
106 range = "closed";
107 which = -1;
108 break;
109 case 'a':
110 range = "all";
111 which = 1;
112 break;
113 default:
114 range = "open";
115 which = 0;
116 break;
117 };
118 cson_object_set(pay,"range",json_new_string(range));
119
120 if( g.localOpen ){ /* add "current" property (branch name). */
@@ -128,11 +128,11 @@
128 cson_object_set(pay,"current",json_new_string(zCurrent));
129 }
130 }
131
132
133 branch_prepare_list_query(&q, which);
134 cson_object_set(pay,"branches",listV);
135 while((SQLITE_ROW==db_step(&q))){
136 cson_value * v = cson_sqlite3_column_to_value(q.pStmt,0);
137 if(v){
138 cson_array_append(list,v);
139
--- src/json_branch.c
+++ src/json_branch.c
@@ -66,11 +66,11 @@
66 cson_value * payV;
67 cson_object * pay;
68 cson_value * listV;
69 cson_array * list;
70 char const * range = NULL;
71 int branchListFlags = BRL_OPEN_ONLY;
72 char * sawConversionError = NULL;
73 Stmt q;
74 if( !g.perm.Read ){
75 json_set_err(FSL_JSON_E_DENIED,
76 "Requires 'o' permissions.");
@@ -102,19 +102,19 @@
102 }
103 /* Normalize range values... */
104 switch(*range){
105 case 'c':
106 range = "closed";
107 branchListFlags = BRL_CLOSED_ONLY;
108 break;
109 case 'a':
110 range = "all";
111 branchListFlags = BRL_BOTH;
112 break;
113 default:
114 range = "open";
115 branchListFlags = BRL_OPEN_ONLY;
116 break;
117 };
118 cson_object_set(pay,"range",json_new_string(range));
119
120 if( g.localOpen ){ /* add "current" property (branch name). */
@@ -128,11 +128,11 @@
128 cson_object_set(pay,"current",json_new_string(zCurrent));
129 }
130 }
131
132
133 branch_prepare_list_query(&q, branchListFlags);
134 cson_object_set(pay,"branches",listV);
135 while((SQLITE_ROW==db_step(&q))){
136 cson_value * v = cson_sqlite3_column_to_value(q.pStmt,0);
137 if(v){
138 cson_array_append(list,v);
139
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -572,12 +572,12 @@
572572
#### The directories where the OpenSSL include and library files are located.
573573
# The recommended usage here is to use the Sysinternals junction tool
574574
# to create a hard link between an "openssl-1.x" sub-directory of the
575575
# Fossil source code directory and the target OpenSSL source directory.
576576
#
577
-OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
578
-OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
577
+OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1k/include
578
+OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1k
579579
580580
#### Either the directory where the Tcl library is installed or the Tcl
581581
# source code directory resides (depending on the value of the macro
582582
# FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
583583
# this directory must have "include" and "lib" sub-directories. If
@@ -1304,11 +1304,11 @@
13041304
13051305
# Uncomment to enable Tcl support
13061306
# FOSSIL_ENABLE_TCL = 1
13071307
13081308
!ifdef FOSSIL_ENABLE_SSL
1309
-SSLDIR = $(B)\compat\openssl-1.0.1j
1309
+SSLDIR = $(B)\compat\openssl-1.0.1k
13101310
SSLINCDIR = $(SSLDIR)\inc32
13111311
SSLLIBDIR = $(SSLDIR)\out32
13121312
SSLLFLAGS = /nologo /opt:ref /debug
13131313
SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
13141314
!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
13151315
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -572,12 +572,12 @@
572 #### The directories where the OpenSSL include and library files are located.
573 # The recommended usage here is to use the Sysinternals junction tool
574 # to create a hard link between an "openssl-1.x" sub-directory of the
575 # Fossil source code directory and the target OpenSSL source directory.
576 #
577 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
578 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
579
580 #### Either the directory where the Tcl library is installed or the Tcl
581 # source code directory resides (depending on the value of the macro
582 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
583 # this directory must have "include" and "lib" sub-directories. If
@@ -1304,11 +1304,11 @@
1304
1305 # Uncomment to enable Tcl support
1306 # FOSSIL_ENABLE_TCL = 1
1307
1308 !ifdef FOSSIL_ENABLE_SSL
1309 SSLDIR = $(B)\compat\openssl-1.0.1j
1310 SSLINCDIR = $(SSLDIR)\inc32
1311 SSLLIBDIR = $(SSLDIR)\out32
1312 SSLLFLAGS = /nologo /opt:ref /debug
1313 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
1314 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1315
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -572,12 +572,12 @@
572 #### The directories where the OpenSSL include and library files are located.
573 # The recommended usage here is to use the Sysinternals junction tool
574 # to create a hard link between an "openssl-1.x" sub-directory of the
575 # Fossil source code directory and the target OpenSSL source directory.
576 #
577 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1k/include
578 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1k
579
580 #### Either the directory where the Tcl library is installed or the Tcl
581 # source code directory resides (depending on the value of the macro
582 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
583 # this directory must have "include" and "lib" sub-directories. If
@@ -1304,11 +1304,11 @@
1304
1305 # Uncomment to enable Tcl support
1306 # FOSSIL_ENABLE_TCL = 1
1307
1308 !ifdef FOSSIL_ENABLE_SSL
1309 SSLDIR = $(B)\compat\openssl-1.0.1k
1310 SSLINCDIR = $(SSLDIR)\inc32
1311 SSLLIBDIR = $(SSLDIR)\out32
1312 SSLLFLAGS = /nologo /opt:ref /debug
1313 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
1314 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1315
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -572,12 +572,12 @@
572572
#### The directories where the OpenSSL include and library files are located.
573573
# The recommended usage here is to use the Sysinternals junction tool
574574
# to create a hard link between an "openssl-1.x" sub-directory of the
575575
# Fossil source code directory and the target OpenSSL source directory.
576576
#
577
-OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
578
-OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
577
+OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1k/include
578
+OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1k
579579
580580
#### Either the directory where the Tcl library is installed or the Tcl
581581
# source code directory resides (depending on the value of the macro
582582
# FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
583583
# this directory must have "include" and "lib" sub-directories. If
@@ -1304,11 +1304,11 @@
13041304
13051305
# Uncomment to enable Tcl support
13061306
# FOSSIL_ENABLE_TCL = 1
13071307
13081308
!ifdef FOSSIL_ENABLE_SSL
1309
-SSLDIR = $(B)\compat\openssl-1.0.1j
1309
+SSLDIR = $(B)\compat\openssl-1.0.1k
13101310
SSLINCDIR = $(SSLDIR)\inc32
13111311
SSLLIBDIR = $(SSLDIR)\out32
13121312
SSLLFLAGS = /nologo /opt:ref /debug
13131313
SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
13141314
!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
13151315
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -572,12 +572,12 @@
572 #### The directories where the OpenSSL include and library files are located.
573 # The recommended usage here is to use the Sysinternals junction tool
574 # to create a hard link between an "openssl-1.x" sub-directory of the
575 # Fossil source code directory and the target OpenSSL source directory.
576 #
577 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
578 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
579
580 #### Either the directory where the Tcl library is installed or the Tcl
581 # source code directory resides (depending on the value of the macro
582 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
583 # this directory must have "include" and "lib" sub-directories. If
@@ -1304,11 +1304,11 @@
1304
1305 # Uncomment to enable Tcl support
1306 # FOSSIL_ENABLE_TCL = 1
1307
1308 !ifdef FOSSIL_ENABLE_SSL
1309 SSLDIR = $(B)\compat\openssl-1.0.1j
1310 SSLINCDIR = $(SSLDIR)\inc32
1311 SSLLIBDIR = $(SSLDIR)\out32
1312 SSLLFLAGS = /nologo /opt:ref /debug
1313 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
1314 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1315
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -572,12 +572,12 @@
572 #### The directories where the OpenSSL include and library files are located.
573 # The recommended usage here is to use the Sysinternals junction tool
574 # to create a hard link between an "openssl-1.x" sub-directory of the
575 # Fossil source code directory and the target OpenSSL source directory.
576 #
577 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1k/include
578 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1k
579
580 #### Either the directory where the Tcl library is installed or the Tcl
581 # source code directory resides (depending on the value of the macro
582 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
583 # this directory must have "include" and "lib" sub-directories. If
@@ -1304,11 +1304,11 @@
1304
1305 # Uncomment to enable Tcl support
1306 # FOSSIL_ENABLE_TCL = 1
1307
1308 !ifdef FOSSIL_ENABLE_SSL
1309 SSLDIR = $(B)\compat\openssl-1.0.1k
1310 SSLINCDIR = $(SSLDIR)\inc32
1311 SSLLIBDIR = $(SSLDIR)\out32
1312 SSLLFLAGS = /nologo /opt:ref /debug
1313 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
1314 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1315
+77 -21
--- src/report.c
+++ src/report.c
@@ -922,42 +922,85 @@
922922
923923
/*
924924
** Output Javascript code that will enables sorting of the table with
925925
** the id zTableId by clicking.
926926
**
927
-** The javascript is derived from:
927
+** The javascript was originally derived from:
928928
**
929929
** http://www.webtoolkit.info/sortable-html-table.html
930
+**
931
+** But there have been extensive modifications.
930932
**
931933
** This variation allows column types to be expressed using the second
932934
** argument. Each character of the second argument represent a column.
933
-** "t" means sort as text. "n" means sort numerically. "x" means do not
934
-** sort on this column. If there are fewer characters in zColumnTypes[] than
935
-** their are columns, the all extra columns assume type "t" (text).
935
+**
936
+** t Sort by text
937
+** n Sort numerically
938
+** k Sort by the data-sortkey property
939
+** x This column is not sortable
940
+**
941
+** If there are fewer characters in zColumnTypes[] than their are columns,
942
+** the all extra columns assume type "t" (text).
943
+**
944
+** The third parameter is the column that was initially sorted (using 1-based
945
+** column numbers, like SQL). Make this value 0 if none of the columns are
946
+** initially sorted. Make the value negative if the column is initially sorted
947
+** in reverse order.
948
+**
949
+** Clicking on the same column header twice in a row inverts the sort.
936950
*/
937
-void output_table_sorting_javascript(const char *zTableId, const char *zColumnTypes){
951
+void output_table_sorting_javascript(
952
+ const char *zTableId, /* ID of table to sort */
953
+ const char *zColumnTypes, /* String for column types */
954
+ int iInitSort /* Initially sorted column. Leftmost is 1. 0 for NONE */
955
+){
938956
@ <script>
939
- @ function SortableTable(tableEl,columnTypes){
957
+ @ function SortableTable(tableEl,columnTypes,initSort){
940958
@ this.tbody = tableEl.getElementsByTagName('tbody');
959
+ @ this.columnTypes = columnTypes;
941960
@ this.sort = function (cell) {
942961
@ var column = cell.cellIndex;
943
- @ var sortFn = cell.sortType=="n" ? this.sortNumeric : this.sortText;
962
+ @ var sortFn;
963
+ @ switch( cell.sortType ){
964
+ @ case "n": sortFn = this.sortNumeric; break;
965
+ @ case "t": sortFn = this.sortText; break;
966
+ @ case "k": sortFn = this.sortKey; break;
967
+ @ case "x": return;
968
+ @ }
944969
@ this.sortIndex = column;
945970
@ var newRows = new Array();
946971
@ for (j = 0; j < this.tbody[0].rows.length; j++) {
947972
@ newRows[j] = this.tbody[0].rows[j];
948973
@ }
949
- @ newRows.sort(sortFn);
950
- @ if (cell.getAttribute("sortdir") == 'down') {
951
- @ newRows.reverse();
952
- @ cell.setAttribute('sortdir','up');
953
- @ } else {
954
- @ cell.setAttribute('sortdir','down');
974
+ @ if( this.sortIndex==Math.abs(this.prevColumn)-1 ){
975
+ @ newRows.reverse();
976
+ @ this.prevColumn = -this.prevColumn;
977
+ @ }else{
978
+ @ newRows.sort(sortFn);
979
+ @ this.prevColumn = this.sortIndex+1;
955980
@ }
956981
@ for (i=0;i<newRows.length;i++) {
957982
@ this.tbody[0].appendChild(newRows[i]);
958983
@ }
984
+ @ this.setHdrIcons();
985
+ @ }
986
+ @ this.setHdrIcons = function() {
987
+ @ for (var i=0; i<this.hdrRow.cells.length; i++) {
988
+ @ if( this.columnTypes[i]=='x' ) continue;
989
+ @ var sortType;
990
+ @ if( this.prevColumn==i+1 ){
991
+ @ sortType = 'asc';
992
+ @ }else if( this.prevColumn==(-1-i) ){
993
+ @ sortType = 'desc'
994
+ @ }else{
995
+ @ sortType = 'none';
996
+ @ }
997
+ @ var hdrCell = this.hdrRow.cells[i];
998
+ @ var clsName = hdrCell.className.replace(/\s*\bsort\s*\w+/, '');
999
+ @ clsName += ' sort ' + sortType;
1000
+ @ hdrCell.className = clsName;
1001
+ @ }
9591002
@ }
9601003
@ this.sortText = function(a,b) {
9611004
@ var i = thisObject.sortIndex;
9621005
@ aa = a.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
9631006
@ bb = b.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
@@ -971,30 +1014,43 @@
9711014
@ if (isNaN(aa)) aa = 0;
9721015
@ bb = parseFloat(b.cells[i].textContent);
9731016
@ if (isNaN(bb)) bb = 0;
9741017
@ return aa-bb;
9751018
@ }
976
- @ var thisObject = this;
1019
+ @ this.sortKey = function(a,b) {
1020
+ @ var i = thisObject.sortIndex;
1021
+ @ aa = a.cells[i].getAttribute("data-sortkey");
1022
+ @ bb = b.cells[i].getAttribute("data-sortkey");
1023
+ @ if(aa==bb) return 0;
1024
+ @ if(aa<bb) return -1;
1025
+ @ return 1;
1026
+ @ }
9771027
@ var x = tableEl.getElementsByTagName('thead');
9781028
@ if(!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length>0)){
9791029
@ return;
9801030
@ }
9811031
@ if(x && x[0].rows && x[0].rows.length > 0) {
982
- @ var sortRow = x[0].rows[0];
1032
+ @ this.hdrRow = x[0].rows[0];
9831033
@ } else {
9841034
@ return;
9851035
@ }
986
- @ for (var i=0; i<sortRow.cells.length; i++) {
987
- @ sortRow.cells[i].sTable = this;
988
- @ sortRow.cells[i].sortType = columnTypes[i] || 't';
989
- @ sortRow.cells[i].onclick = function () {
1036
+ @ var thisObject = this;
1037
+ @ this.prevColumn = initSort;
1038
+ @ for (var i=0; i<this.hdrRow.cells.length; i++) {
1039
+ @ if( columnTypes[i]=='x' ) continue;
1040
+ @ var hdrcell = this.hdrRow.cells[i];
1041
+ @ hdrcell.sTable = this;
1042
+ @ hdrcell.style.cursor = "pointer";
1043
+ @ hdrcell.sortType = columnTypes[i] || 't';
1044
+ @ hdrcell.onclick = function () {
9901045
@ this.sTable.sort(this);
9911046
@ return false;
9921047
@ }
9931048
@ }
1049
+ @ this.setHdrIcons()
9941050
@ }
995
- @ var t = new SortableTable(gebi("%s(zTableId)"),"%s(zColumnTypes)");
1051
+ @ var t = new SortableTable(gebi("%s(zTableId)"),"%s(zColumnTypes)",%d(iInitSort));
9961052
@ </script>
9971053
}
9981054
9991055
10001056
/*
@@ -1086,11 +1142,11 @@
10861142
if( zErr1 ){
10871143
@ <p class="reportError">Error: %h(zErr1)</p>
10881144
}else if( zErr2 ){
10891145
@ <p class="reportError">Error: %h(zErr2)</p>
10901146
}
1091
- output_table_sorting_javascript("reportTable","");
1147
+ output_table_sorting_javascript("reportTable","",0);
10921148
style_footer();
10931149
}else{
10941150
report_restrict_sql(&zErr1);
10951151
db_exec_readonly(g.db, zSql, output_tab_separated, &count, &zErr2);
10961152
report_unrestrict_sql();
10971153
--- src/report.c
+++ src/report.c
@@ -922,42 +922,85 @@
922
923 /*
924 ** Output Javascript code that will enables sorting of the table with
925 ** the id zTableId by clicking.
926 **
927 ** The javascript is derived from:
928 **
929 ** http://www.webtoolkit.info/sortable-html-table.html
 
 
930 **
931 ** This variation allows column types to be expressed using the second
932 ** argument. Each character of the second argument represent a column.
933 ** "t" means sort as text. "n" means sort numerically. "x" means do not
934 ** sort on this column. If there are fewer characters in zColumnTypes[] than
935 ** their are columns, the all extra columns assume type "t" (text).
 
 
 
 
 
 
 
 
 
 
 
 
936 */
937 void output_table_sorting_javascript(const char *zTableId, const char *zColumnTypes){
 
 
 
 
938 @ <script>
939 @ function SortableTable(tableEl,columnTypes){
940 @ this.tbody = tableEl.getElementsByTagName('tbody');
 
941 @ this.sort = function (cell) {
942 @ var column = cell.cellIndex;
943 @ var sortFn = cell.sortType=="n" ? this.sortNumeric : this.sortText;
 
 
 
 
 
 
944 @ this.sortIndex = column;
945 @ var newRows = new Array();
946 @ for (j = 0; j < this.tbody[0].rows.length; j++) {
947 @ newRows[j] = this.tbody[0].rows[j];
948 @ }
949 @ newRows.sort(sortFn);
950 @ if (cell.getAttribute("sortdir") == 'down') {
951 @ newRows.reverse();
952 @ cell.setAttribute('sortdir','up');
953 @ } else {
954 @ cell.setAttribute('sortdir','down');
955 @ }
956 @ for (i=0;i<newRows.length;i++) {
957 @ this.tbody[0].appendChild(newRows[i]);
958 @ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
959 @ }
960 @ this.sortText = function(a,b) {
961 @ var i = thisObject.sortIndex;
962 @ aa = a.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
963 @ bb = b.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
@@ -971,30 +1014,43 @@
971 @ if (isNaN(aa)) aa = 0;
972 @ bb = parseFloat(b.cells[i].textContent);
973 @ if (isNaN(bb)) bb = 0;
974 @ return aa-bb;
975 @ }
976 @ var thisObject = this;
 
 
 
 
 
 
 
977 @ var x = tableEl.getElementsByTagName('thead');
978 @ if(!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length>0)){
979 @ return;
980 @ }
981 @ if(x && x[0].rows && x[0].rows.length > 0) {
982 @ var sortRow = x[0].rows[0];
983 @ } else {
984 @ return;
985 @ }
986 @ for (var i=0; i<sortRow.cells.length; i++) {
987 @ sortRow.cells[i].sTable = this;
988 @ sortRow.cells[i].sortType = columnTypes[i] || 't';
989 @ sortRow.cells[i].onclick = function () {
 
 
 
 
 
990 @ this.sTable.sort(this);
991 @ return false;
992 @ }
993 @ }
 
994 @ }
995 @ var t = new SortableTable(gebi("%s(zTableId)"),"%s(zColumnTypes)");
996 @ </script>
997 }
998
999
1000 /*
@@ -1086,11 +1142,11 @@
1086 if( zErr1 ){
1087 @ <p class="reportError">Error: %h(zErr1)</p>
1088 }else if( zErr2 ){
1089 @ <p class="reportError">Error: %h(zErr2)</p>
1090 }
1091 output_table_sorting_javascript("reportTable","");
1092 style_footer();
1093 }else{
1094 report_restrict_sql(&zErr1);
1095 db_exec_readonly(g.db, zSql, output_tab_separated, &count, &zErr2);
1096 report_unrestrict_sql();
1097
--- src/report.c
+++ src/report.c
@@ -922,42 +922,85 @@
922
923 /*
924 ** Output Javascript code that will enables sorting of the table with
925 ** the id zTableId by clicking.
926 **
927 ** The javascript was originally derived from:
928 **
929 ** http://www.webtoolkit.info/sortable-html-table.html
930 **
931 ** But there have been extensive modifications.
932 **
933 ** This variation allows column types to be expressed using the second
934 ** argument. Each character of the second argument represent a column.
935 **
936 ** t Sort by text
937 ** n Sort numerically
938 ** k Sort by the data-sortkey property
939 ** x This column is not sortable
940 **
941 ** If there are fewer characters in zColumnTypes[] than their are columns,
942 ** the all extra columns assume type "t" (text).
943 **
944 ** The third parameter is the column that was initially sorted (using 1-based
945 ** column numbers, like SQL). Make this value 0 if none of the columns are
946 ** initially sorted. Make the value negative if the column is initially sorted
947 ** in reverse order.
948 **
949 ** Clicking on the same column header twice in a row inverts the sort.
950 */
951 void output_table_sorting_javascript(
952 const char *zTableId, /* ID of table to sort */
953 const char *zColumnTypes, /* String for column types */
954 int iInitSort /* Initially sorted column. Leftmost is 1. 0 for NONE */
955 ){
956 @ <script>
957 @ function SortableTable(tableEl,columnTypes,initSort){
958 @ this.tbody = tableEl.getElementsByTagName('tbody');
959 @ this.columnTypes = columnTypes;
960 @ this.sort = function (cell) {
961 @ var column = cell.cellIndex;
962 @ var sortFn;
963 @ switch( cell.sortType ){
964 @ case "n": sortFn = this.sortNumeric; break;
965 @ case "t": sortFn = this.sortText; break;
966 @ case "k": sortFn = this.sortKey; break;
967 @ case "x": return;
968 @ }
969 @ this.sortIndex = column;
970 @ var newRows = new Array();
971 @ for (j = 0; j < this.tbody[0].rows.length; j++) {
972 @ newRows[j] = this.tbody[0].rows[j];
973 @ }
974 @ if( this.sortIndex==Math.abs(this.prevColumn)-1 ){
975 @ newRows.reverse();
976 @ this.prevColumn = -this.prevColumn;
977 @ }else{
978 @ newRows.sort(sortFn);
979 @ this.prevColumn = this.sortIndex+1;
980 @ }
981 @ for (i=0;i<newRows.length;i++) {
982 @ this.tbody[0].appendChild(newRows[i]);
983 @ }
984 @ this.setHdrIcons();
985 @ }
986 @ this.setHdrIcons = function() {
987 @ for (var i=0; i<this.hdrRow.cells.length; i++) {
988 @ if( this.columnTypes[i]=='x' ) continue;
989 @ var sortType;
990 @ if( this.prevColumn==i+1 ){
991 @ sortType = 'asc';
992 @ }else if( this.prevColumn==(-1-i) ){
993 @ sortType = 'desc'
994 @ }else{
995 @ sortType = 'none';
996 @ }
997 @ var hdrCell = this.hdrRow.cells[i];
998 @ var clsName = hdrCell.className.replace(/\s*\bsort\s*\w+/, '');
999 @ clsName += ' sort ' + sortType;
1000 @ hdrCell.className = clsName;
1001 @ }
1002 @ }
1003 @ this.sortText = function(a,b) {
1004 @ var i = thisObject.sortIndex;
1005 @ aa = a.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
1006 @ bb = b.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
@@ -971,30 +1014,43 @@
1014 @ if (isNaN(aa)) aa = 0;
1015 @ bb = parseFloat(b.cells[i].textContent);
1016 @ if (isNaN(bb)) bb = 0;
1017 @ return aa-bb;
1018 @ }
1019 @ this.sortKey = function(a,b) {
1020 @ var i = thisObject.sortIndex;
1021 @ aa = a.cells[i].getAttribute("data-sortkey");
1022 @ bb = b.cells[i].getAttribute("data-sortkey");
1023 @ if(aa==bb) return 0;
1024 @ if(aa<bb) return -1;
1025 @ return 1;
1026 @ }
1027 @ var x = tableEl.getElementsByTagName('thead');
1028 @ if(!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length>0)){
1029 @ return;
1030 @ }
1031 @ if(x && x[0].rows && x[0].rows.length > 0) {
1032 @ this.hdrRow = x[0].rows[0];
1033 @ } else {
1034 @ return;
1035 @ }
1036 @ var thisObject = this;
1037 @ this.prevColumn = initSort;
1038 @ for (var i=0; i<this.hdrRow.cells.length; i++) {
1039 @ if( columnTypes[i]=='x' ) continue;
1040 @ var hdrcell = this.hdrRow.cells[i];
1041 @ hdrcell.sTable = this;
1042 @ hdrcell.style.cursor = "pointer";
1043 @ hdrcell.sortType = columnTypes[i] || 't';
1044 @ hdrcell.onclick = function () {
1045 @ this.sTable.sort(this);
1046 @ return false;
1047 @ }
1048 @ }
1049 @ this.setHdrIcons()
1050 @ }
1051 @ var t = new SortableTable(gebi("%s(zTableId)"),"%s(zColumnTypes)",%d(iInitSort));
1052 @ </script>
1053 }
1054
1055
1056 /*
@@ -1086,11 +1142,11 @@
1142 if( zErr1 ){
1143 @ <p class="reportError">Error: %h(zErr1)</p>
1144 }else if( zErr2 ){
1145 @ <p class="reportError">Error: %h(zErr2)</p>
1146 }
1147 output_table_sorting_javascript("reportTable","",0);
1148 style_footer();
1149 }else{
1150 report_restrict_sql(&zErr1);
1151 db_exec_readonly(g.db, zSql, output_tab_separated, &count, &zErr2);
1152 report_unrestrict_sql();
1153
+1 -1
--- src/setup.c
+++ src/setup.c
@@ -151,11 +151,11 @@
151151
"SELECT uid, login, cap, info, 1 FROM user"
152152
" WHERE login IN ('anonymous','nobody','developer','reader') "
153153
" UNION ALL "
154154
"SELECT uid, login, cap, info, 2 FROM user"
155155
" WHERE login NOT IN ('anonymous','nobody','developer','reader') "
156
- "ORDER BY 5, 2"
156
+ "ORDER BY 5, 2 COLLATE nocase"
157157
);
158158
while( db_step(&s)==SQLITE_ROW ){
159159
int iLevel = db_column_int(&s, 4);
160160
const char *zCap = db_column_text(&s, 2);
161161
const char *zLogin = db_column_text(&s, 1);
162162
--- src/setup.c
+++ src/setup.c
@@ -151,11 +151,11 @@
151 "SELECT uid, login, cap, info, 1 FROM user"
152 " WHERE login IN ('anonymous','nobody','developer','reader') "
153 " UNION ALL "
154 "SELECT uid, login, cap, info, 2 FROM user"
155 " WHERE login NOT IN ('anonymous','nobody','developer','reader') "
156 "ORDER BY 5, 2"
157 );
158 while( db_step(&s)==SQLITE_ROW ){
159 int iLevel = db_column_int(&s, 4);
160 const char *zCap = db_column_text(&s, 2);
161 const char *zLogin = db_column_text(&s, 1);
162
--- src/setup.c
+++ src/setup.c
@@ -151,11 +151,11 @@
151 "SELECT uid, login, cap, info, 1 FROM user"
152 " WHERE login IN ('anonymous','nobody','developer','reader') "
153 " UNION ALL "
154 "SELECT uid, login, cap, info, 2 FROM user"
155 " WHERE login NOT IN ('anonymous','nobody','developer','reader') "
156 "ORDER BY 5, 2 COLLATE nocase"
157 );
158 while( db_step(&s)==SQLITE_ROW ){
159 int iLevel = db_column_int(&s, 4);
160 const char *zCap = db_column_text(&s, 2);
161 const char *zLogin = db_column_text(&s, 1);
162
+259 -129
--- src/shell.c
+++ src/shell.c
@@ -15,10 +15,17 @@
1515
#if (defined(_WIN32) || defined(WIN32)) && !defined(_CRT_SECURE_NO_WARNINGS)
1616
/* This needs to come before any includes for MSVC compiler */
1717
#define _CRT_SECURE_NO_WARNINGS
1818
#endif
1919
20
+/*
21
+** If requested, include the SQLite compiler options file for MSVC.
22
+*/
23
+#if defined(INCLUDE_MSVC_H)
24
+#include "msvc.h"
25
+#endif
26
+
2027
/*
2128
** Enable large-file support for fopen() and friends on unix.
2229
*/
2330
#ifndef SQLITE_DISABLE_LFS
2431
# define _LARGE_FILE 1
@@ -46,21 +53,20 @@
4653
# endif
4754
# include <unistd.h>
4855
# include <sys/types.h>
4956
#endif
5057
51
-#if defined(HAVE_READLINE) && HAVE_READLINE!=0
58
+#if HAVE_READLINE
5259
# include <readline/readline.h>
5360
# include <readline/history.h>
54
-#else
55
-# undef HAVE_READLINE
5661
#endif
57
-#if defined(HAVE_EDITLINE) && !defined(HAVE_READLINE)
62
+#if HAVE_EDITLINE
63
+# undef HAVE_READLINE
5864
# define HAVE_READLINE 1
5965
# include <editline/readline.h>
6066
#endif
61
-#if !defined(HAVE_READLINE)
67
+#if !HAVE_READLINE
6268
# define add_history(X)
6369
# define read_history(X)
6470
# define write_history(X)
6571
# define stifle_history(X)
6672
#endif
@@ -423,11 +429,11 @@
423429
char *zResult;
424430
if( in!=0 ){
425431
zResult = local_getline(zPrior, in);
426432
}else{
427433
zPrompt = isContinuation ? continuePrompt : mainPrompt;
428
-#if defined(HAVE_READLINE)
434
+#if HAVE_READLINE
429435
free(zPrior);
430436
zResult = readline(zPrompt);
431437
if( zResult && *zResult ) add_history(zResult);
432438
#else
433439
printf("%s", zPrompt);
@@ -469,15 +475,15 @@
469475
int mode; /* An output mode setting */
470476
int writableSchema; /* True if PRAGMA writable_schema=ON */
471477
int showHeader; /* True to show column names in List or Column mode */
472478
unsigned shellFlgs; /* Various flags */
473479
char *zDestTable; /* Name of destination table when MODE_Insert */
474
- char separator[20]; /* Separator character for MODE_List */
475
- char newline[20]; /* Record separator in MODE_Csv */
480
+ char colSeparator[20]; /* Column separator character for several modes */
481
+ char rowSeparator[20]; /* Row separator character for MODE_Ascii */
476482
int colWidth[100]; /* Requested width of each column when in column mode*/
477483
int actualWidth[100]; /* Actual width of each column */
478
- char nullvalue[20]; /* The text to print when a NULL comes back from
484
+ char nullValue[20]; /* The text to print when a NULL comes back from
479485
** the database */
480486
SavedModeInfo normalMode;/* Holds the mode just before .explain ON */
481487
char outfile[FILENAME_MAX]; /* Filename for *out */
482488
const char *zDbFilename; /* name of the database file */
483489
char *zFreeOnClose; /* Filename to free when closing */
@@ -506,10 +512,11 @@
506512
#define MODE_Html 4 /* Generate an XHTML table */
507513
#define MODE_Insert 5 /* Generate SQL "insert" statements */
508514
#define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */
509515
#define MODE_Csv 7 /* Quote strings, numbers are plain */
510516
#define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */
517
+#define MODE_Ascii 9 /* Use ASCII unit and record separators (0x1F/0x1E) */
511518
512519
static const char *modeDescr[] = {
513520
"line",
514521
"column",
515522
"list",
@@ -517,12 +524,26 @@
517524
"html",
518525
"insert",
519526
"tcl",
520527
"csv",
521528
"explain",
529
+ "ascii",
522530
};
523531
532
+/*
533
+** These are the column/row/line separators used by the various
534
+** import/export modes.
535
+*/
536
+#define SEP_Column "|"
537
+#define SEP_Row "\n"
538
+#define SEP_Tab "\t"
539
+#define SEP_Space " "
540
+#define SEP_Comma ","
541
+#define SEP_CrLf "\r\n"
542
+#define SEP_Unit "\x1F"
543
+#define SEP_Record "\x1E"
544
+
524545
/*
525546
** Number of elements in an array
526547
*/
527548
#define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
528549
@@ -675,26 +696,26 @@
675696
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
676697
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
677698
};
678699
679700
/*
680
-** Output a single term of CSV. Actually, p->separator is used for
681
-** the separator, which may or may not be a comma. p->nullvalue is
701
+** Output a single term of CSV. Actually, p->colSeparator is used for
702
+** the separator, which may or may not be a comma. p->nullValue is
682703
** the null value. Strings are quoted if necessary. The separator
683704
** is only issued if bSep is true.
684705
*/
685706
static void output_csv(ShellState *p, const char *z, int bSep){
686707
FILE *out = p->out;
687708
if( z==0 ){
688
- fprintf(out,"%s",p->nullvalue);
709
+ fprintf(out,"%s",p->nullValue);
689710
}else{
690711
int i;
691
- int nSep = strlen30(p->separator);
712
+ int nSep = strlen30(p->colSeparator);
692713
for(i=0; z[i]; i++){
693714
if( needCsvQuote[((unsigned char*)z)[i]]
694
- || (z[i]==p->separator[0] &&
695
- (nSep==1 || memcmp(z, p->separator, nSep)==0)) ){
715
+ || (z[i]==p->colSeparator[0] &&
716
+ (nSep==1 || memcmp(z, p->colSeparator, nSep)==0)) ){
696717
i = 0;
697718
break;
698719
}
699720
}
700721
if( i==0 ){
@@ -707,11 +728,11 @@
707728
}else{
708729
fprintf(out, "%s", z);
709730
}
710731
}
711732
if( bSep ){
712
- fprintf(p->out, "%s", p->separator);
733
+ fprintf(p->out, "%s", p->colSeparator);
713734
}
714735
}
715736
716737
#ifdef SIGINT
717738
/*
@@ -745,14 +766,14 @@
745766
if( azArg==0 ) break;
746767
for(i=0; i<nArg; i++){
747768
int len = strlen30(azCol[i] ? azCol[i] : "");
748769
if( len>w ) w = len;
749770
}
750
- if( p->cnt++>0 ) fprintf(p->out,"\n");
771
+ if( p->cnt++>0 ) fprintf(p->out, "%s", p->rowSeparator);
751772
for(i=0; i<nArg; i++){
752
- fprintf(p->out,"%*s = %s\n", w, azCol[i],
753
- azArg[i] ? azArg[i] : p->nullvalue);
773
+ fprintf(p->out,"%*s = %s%s", w, azCol[i],
774
+ azArg[i] ? azArg[i] : p->nullValue, p->rowSeparator);
754775
}
755776
break;
756777
}
757778
case MODE_Explain:
758779
case MODE_Column: {
@@ -765,21 +786,23 @@
765786
w = 0;
766787
}
767788
if( w==0 ){
768789
w = strlen30(azCol[i] ? azCol[i] : "");
769790
if( w<10 ) w = 10;
770
- n = strlen30(azArg && azArg[i] ? azArg[i] : p->nullvalue);
791
+ n = strlen30(azArg && azArg[i] ? azArg[i] : p->nullValue);
771792
if( w<n ) w = n;
772793
}
773794
if( i<ArraySize(p->actualWidth) ){
774795
p->actualWidth[i] = w;
775796
}
776797
if( p->showHeader ){
777798
if( w<0 ){
778
- fprintf(p->out,"%*.*s%s",-w,-w,azCol[i], i==nArg-1 ? "\n": " ");
799
+ fprintf(p->out,"%*.*s%s",-w,-w,azCol[i],
800
+ i==nArg-1 ? p->rowSeparator : " ");
779801
}else{
780
- fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": " ");
802
+ fprintf(p->out,"%-*.*s%s",w,w,azCol[i],
803
+ i==nArg-1 ? p->rowSeparator : " ");
781804
}
782805
}
783806
}
784807
if( p->showHeader ){
785808
for(i=0; i<nArg; i++){
@@ -790,11 +813,11 @@
790813
}else{
791814
w = 10;
792815
}
793816
fprintf(p->out,"%-*.*s%s",w,w,"-----------------------------------"
794817
"----------------------------------------------------------",
795
- i==nArg-1 ? "\n": " ");
818
+ i==nArg-1 ? p->rowSeparator : " ");
796819
}
797820
}
798821
}
799822
if( azArg==0 ) break;
800823
for(i=0; i<nArg; i++){
@@ -813,36 +836,39 @@
813836
}
814837
p->iIndent++;
815838
}
816839
if( w<0 ){
817840
fprintf(p->out,"%*.*s%s",-w,-w,
818
- azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
841
+ azArg[i] ? azArg[i] : p->nullValue,
842
+ i==nArg-1 ? p->rowSeparator : " ");
819843
}else{
820844
fprintf(p->out,"%-*.*s%s",w,w,
821
- azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
845
+ azArg[i] ? azArg[i] : p->nullValue,
846
+ i==nArg-1 ? p->rowSeparator : " ");
822847
}
823848
}
824849
break;
825850
}
826851
case MODE_Semi:
827852
case MODE_List: {
828853
if( p->cnt++==0 && p->showHeader ){
829854
for(i=0; i<nArg; i++){
830
- fprintf(p->out,"%s%s",azCol[i], i==nArg-1 ? "\n" : p->separator);
855
+ fprintf(p->out,"%s%s",azCol[i],
856
+ i==nArg-1 ? p->rowSeparator : p->colSeparator);
831857
}
832858
}
833859
if( azArg==0 ) break;
834860
for(i=0; i<nArg; i++){
835861
char *z = azArg[i];
836
- if( z==0 ) z = p->nullvalue;
862
+ if( z==0 ) z = p->nullValue;
837863
fprintf(p->out, "%s", z);
838864
if( i<nArg-1 ){
839
- fprintf(p->out, "%s", p->separator);
865
+ fprintf(p->out, "%s", p->colSeparator);
840866
}else if( p->mode==MODE_Semi ){
841
- fprintf(p->out, ";\n");
867
+ fprintf(p->out, ";%s", p->rowSeparator);
842868
}else{
843
- fprintf(p->out, "\n");
869
+ fprintf(p->out, "%s", p->rowSeparator);
844870
}
845871
}
846872
break;
847873
}
848874
case MODE_Html: {
@@ -857,30 +883,30 @@
857883
}
858884
if( azArg==0 ) break;
859885
fprintf(p->out,"<TR>");
860886
for(i=0; i<nArg; i++){
861887
fprintf(p->out,"<TD>");
862
- output_html_string(p->out, azArg[i] ? azArg[i] : p->nullvalue);
888
+ output_html_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
863889
fprintf(p->out,"</TD>\n");
864890
}
865891
fprintf(p->out,"</TR>\n");
866892
break;
867893
}
868894
case MODE_Tcl: {
869895
if( p->cnt++==0 && p->showHeader ){
870896
for(i=0; i<nArg; i++){
871897
output_c_string(p->out,azCol[i] ? azCol[i] : "");
872
- if(i<nArg-1) fprintf(p->out, "%s", p->separator);
898
+ if(i<nArg-1) fprintf(p->out, "%s", p->colSeparator);
873899
}
874
- fprintf(p->out,"\n");
900
+ fprintf(p->out, "%s", p->rowSeparator);
875901
}
876902
if( azArg==0 ) break;
877903
for(i=0; i<nArg; i++){
878
- output_c_string(p->out, azArg[i] ? azArg[i] : p->nullvalue);
879
- if(i<nArg-1) fprintf(p->out, "%s", p->separator);
904
+ output_c_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
905
+ if(i<nArg-1) fprintf(p->out, "%s", p->colSeparator);
880906
}
881
- fprintf(p->out,"\n");
907
+ fprintf(p->out, "%s", p->rowSeparator);
882908
break;
883909
}
884910
case MODE_Csv: {
885911
#if defined(WIN32) || defined(_WIN32)
886912
fflush(p->out);
@@ -888,17 +914,17 @@
888914
#endif
889915
if( p->cnt++==0 && p->showHeader ){
890916
for(i=0; i<nArg; i++){
891917
output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
892918
}
893
- fprintf(p->out,"%s",p->newline);
919
+ fprintf(p->out, "%s", p->rowSeparator);
894920
}
895921
if( nArg>0 ){
896922
for(i=0; i<nArg; i++){
897923
output_csv(p, azArg[i], i<nArg-1);
898924
}
899
- fprintf(p->out,"%s",p->newline);
925
+ fprintf(p->out, "%s", p->rowSeparator);
900926
}
901927
#if defined(WIN32) || defined(_WIN32)
902928
fflush(p->out);
903929
_setmode(_fileno(p->out), _O_TEXT);
904930
#endif
@@ -930,10 +956,26 @@
930956
output_quoted_string(p->out, azArg[i]);
931957
}
932958
}
933959
fprintf(p->out,");\n");
934960
break;
961
+ }
962
+ case MODE_Ascii: {
963
+ if( p->cnt++==0 && p->showHeader ){
964
+ for(i=0; i<nArg; i++){
965
+ if( i>0 ) fprintf(p->out, "%s", p->colSeparator);
966
+ fprintf(p->out,"%s",azCol[i] ? azCol[i] : "");
967
+ }
968
+ fprintf(p->out, "%s", p->rowSeparator);
969
+ }
970
+ if( azArg==0 ) break;
971
+ for(i=0; i<nArg; i++){
972
+ if( i>0 ) fprintf(p->out, "%s", p->colSeparator);
973
+ fprintf(p->out,"%s",azArg[i] ? azArg[i] : p->nullValue);
974
+ }
975
+ fprintf(p->out, "%s", p->rowSeparator);
976
+ break;
935977
}
936978
}
937979
return 0;
938980
}
939981
@@ -1696,16 +1738,17 @@
16961738
#ifndef SQLITE_OMIT_LOAD_EXTENSION
16971739
".load FILE ?ENTRY? Load an extension library\n"
16981740
#endif
16991741
".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
17001742
".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
1743
+ " ascii Columns/rows delimited by 0x1F and 0x1E\n"
17011744
" csv Comma-separated values\n"
17021745
" column Left-aligned columns. (See .width)\n"
17031746
" html HTML <table> code\n"
17041747
" insert SQL insert statements for TABLE\n"
17051748
" line One value per line\n"
1706
- " list Values delimited by .separator string\n"
1749
+ " list Values delimited by .separator strings\n"
17071750
" tabs Tab-separated values\n"
17081751
" tcl TCL list elements\n"
17091752
".nullvalue STRING Use STRING in place of NULL values\n"
17101753
".once FILENAME Output for the next SQL command only to FILENAME\n"
17111754
".open ?FILENAME? Close existing database and reopen FILENAME\n"
@@ -1718,12 +1761,12 @@
17181761
".save FILE Write in-memory database into FILE\n"
17191762
".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
17201763
".schema ?TABLE? Show the CREATE statements\n"
17211764
" If TABLE specified, only show tables matching\n"
17221765
" LIKE pattern TABLE.\n"
1723
- ".separator STRING ?NL? Change separator used by output mode and .import\n"
1724
- " NL is the end-of-line mark for CSV\n"
1766
+ ".separator COL ?ROW? Change the column separator and optionally the row\n"
1767
+ " separator for both the output mode and .import\n"
17251768
".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
17261769
".show Show the current values for various settings\n"
17271770
".stats on|off Turn stats on or off\n"
17281771
".system CMD ARGS... Run CMD ARGS... in a system shell\n"
17291772
".tables ?TABLE? List names of tables\n"
@@ -2000,26 +2043,27 @@
20002043
static int nCall = 0;
20012044
nCall++;
20022045
}
20032046
20042047
/*
2005
-** An object used to read a CSV file
2048
+** An object used to read a CSV and other files for import.
20062049
*/
2007
-typedef struct CSVReader CSVReader;
2008
-struct CSVReader {
2050
+typedef struct ImportCtx ImportCtx;
2051
+struct ImportCtx {
20092052
const char *zFile; /* Name of the input file */
20102053
FILE *in; /* Read the CSV text from this input stream */
20112054
char *z; /* Accumulated text for a field */
20122055
int n; /* Number of bytes in z */
20132056
int nAlloc; /* Space allocated for z[] */
20142057
int nLine; /* Current line number */
20152058
int cTerm; /* Character that terminated the most recent field */
2016
- int cSeparator; /* The separator character. (Usually ",") */
2059
+ int cColSep; /* The column separator character. (Usually ",") */
2060
+ int cRowSep; /* The row separator character. (Usually "\n") */
20172061
};
20182062
20192063
/* Append a single byte to z[] */
2020
-static void csv_append_char(CSVReader *p, int c){
2064
+static void import_append_char(ImportCtx *p, int c){
20212065
if( p->n+1>=p->nAlloc ){
20222066
p->nAlloc += p->nAlloc + 100;
20232067
p->z = sqlite3_realloc(p->z, p->nAlloc);
20242068
if( p->z==0 ){
20252069
fprintf(stderr, "out of memory\n");
@@ -2033,41 +2077,44 @@
20332077
** with the option of having a separator other than ",".
20342078
**
20352079
** + Input comes from p->in.
20362080
** + Store results in p->z of length p->n. Space to hold p->z comes
20372081
** from sqlite3_malloc().
2038
-** + Use p->cSep as the separator. The default is ",".
2082
+** + Use p->cSep as the column separator. The default is ",".
2083
+** + Use p->rSep as the row separator. The default is "\n".
20392084
** + Keep track of the line number in p->nLine.
20402085
** + Store the character that terminates the field in p->cTerm. Store
20412086
** EOF on end-of-file.
20422087
** + Report syntax errors on stderr
20432088
*/
2044
-static char *csv_read_one_field(CSVReader *p){
2045
- int c, pc, ppc;
2046
- int cSep = p->cSeparator;
2089
+static char *csv_read_one_field(ImportCtx *p){
2090
+ int c;
2091
+ int cSep = p->cColSep;
2092
+ int rSep = p->cRowSep;
20472093
p->n = 0;
20482094
c = fgetc(p->in);
20492095
if( c==EOF || seenInterrupt ){
20502096
p->cTerm = EOF;
20512097
return 0;
20522098
}
20532099
if( c=='"' ){
2100
+ int pc, ppc;
20542101
int startLine = p->nLine;
20552102
int cQuote = c;
20562103
pc = ppc = 0;
20572104
while( 1 ){
20582105
c = fgetc(p->in);
2059
- if( c=='\n' ) p->nLine++;
2106
+ if( c==rSep ) p->nLine++;
20602107
if( c==cQuote ){
20612108
if( pc==cQuote ){
20622109
pc = 0;
20632110
continue;
20642111
}
20652112
}
20662113
if( (c==cSep && pc==cQuote)
2067
- || (c=='\n' && pc==cQuote)
2068
- || (c=='\n' && pc=='\r' && ppc==cQuote)
2114
+ || (c==rSep && pc==cQuote)
2115
+ || (c==rSep && pc=='\r' && ppc==cQuote)
20692116
|| (c==EOF && pc==cQuote)
20702117
){
20712118
do{ p->n--; }while( p->z[p->n]!=cQuote );
20722119
p->cTerm = c;
20732120
break;
@@ -2077,31 +2124,65 @@
20772124
p->zFile, p->nLine, cQuote);
20782125
}
20792126
if( c==EOF ){
20802127
fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
20812128
p->zFile, startLine, cQuote);
2082
- p->cTerm = EOF;
2129
+ p->cTerm = c;
20832130
break;
20842131
}
2085
- csv_append_char(p, c);
2132
+ import_append_char(p, c);
20862133
ppc = pc;
20872134
pc = c;
20882135
}
20892136
}else{
2090
- while( c!=EOF && c!=cSep && c!='\n' ){
2091
- csv_append_char(p, c);
2137
+ while( c!=EOF && c!=cSep && c!=rSep ){
2138
+ import_append_char(p, c);
20922139
c = fgetc(p->in);
20932140
}
2094
- if( c=='\n' ){
2141
+ if( c==rSep ){
20952142
p->nLine++;
20962143
if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--;
20972144
}
20982145
p->cTerm = c;
20992146
}
21002147
if( p->z ) p->z[p->n] = 0;
21012148
return p->z;
21022149
}
2150
+
2151
+/* Read a single field of ASCII delimited text.
2152
+**
2153
+** + Input comes from p->in.
2154
+** + Store results in p->z of length p->n. Space to hold p->z comes
2155
+** from sqlite3_malloc().
2156
+** + Use p->cSep as the column separator. The default is "\x1F".
2157
+** + Use p->rSep as the row separator. The default is "\x1E".
2158
+** + Keep track of the row number in p->nLine.
2159
+** + Store the character that terminates the field in p->cTerm. Store
2160
+** EOF on end-of-file.
2161
+** + Report syntax errors on stderr
2162
+*/
2163
+static char *ascii_read_one_field(ImportCtx *p){
2164
+ int c;
2165
+ int cSep = p->cColSep;
2166
+ int rSep = p->cRowSep;
2167
+ p->n = 0;
2168
+ c = fgetc(p->in);
2169
+ if( c==EOF || seenInterrupt ){
2170
+ p->cTerm = EOF;
2171
+ return 0;
2172
+ }
2173
+ while( c!=EOF && c!=cSep && c!=rSep ){
2174
+ import_append_char(p, c);
2175
+ c = fgetc(p->in);
2176
+ }
2177
+ if( c==rSep ){
2178
+ p->nLine++;
2179
+ }
2180
+ p->cTerm = c;
2181
+ if( p->z ) p->z[p->n] = 0;
2182
+ return p->z;
2183
+}
21032184
21042185
/*
21052186
** Try to transfer data for table zTable. If an error is seen while
21062187
** moving forward, try to go backwards. The backwards movement won't
21072188
** work for WITHOUT ROWID tables.
@@ -2653,100 +2734,125 @@
26532734
sqlite3_stmt *pStmt = NULL; /* A statement */
26542735
int nCol; /* Number of columns in the table */
26552736
int nByte; /* Number of bytes in an SQL string */
26562737
int i, j; /* Loop counters */
26572738
int needCommit; /* True to COMMIT or ROLLBACK at end */
2658
- int nSep; /* Number of bytes in p->separator[] */
2739
+ int nSep; /* Number of bytes in p->colSeparator[] */
26592740
char *zSql; /* An SQL statement */
2660
- CSVReader sCsv; /* Reader context */
2741
+ ImportCtx sCtx; /* Reader context */
2742
+ char *(*xRead)(ImportCtx*); /* Procedure to read one value */
26612743
int (*xCloser)(FILE*); /* Procedure to close th3 connection */
26622744
26632745
if( nArg!=3 ){
26642746
fprintf(stderr, "Usage: .import FILE TABLE\n");
26652747
goto meta_command_exit;
26662748
}
26672749
zFile = azArg[1];
26682750
zTable = azArg[2];
26692751
seenInterrupt = 0;
2670
- memset(&sCsv, 0, sizeof(sCsv));
2752
+ memset(&sCtx, 0, sizeof(sCtx));
26712753
open_db(p, 0);
2672
- nSep = strlen30(p->separator);
2754
+ nSep = strlen30(p->colSeparator);
2755
+ if( nSep==0 ){
2756
+ fprintf(stderr, "Error: non-null column separator required for import\n");
2757
+ return 1;
2758
+ }
2759
+ if( nSep>1 ){
2760
+ fprintf(stderr, "Error: multi-character column separators not allowed"
2761
+ " for import\n");
2762
+ return 1;
2763
+ }
2764
+ nSep = strlen30(p->rowSeparator);
26732765
if( nSep==0 ){
2674
- fprintf(stderr, "Error: non-null separator required for import\n");
2766
+ fprintf(stderr, "Error: non-null row separator required for import\n");
26752767
return 1;
2768
+ }
2769
+ if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator, SEP_CrLf)==0 ){
2770
+ /* When importing CSV (only), if the row separator is set to the
2771
+ ** default output row separator, change it to the default input
2772
+ ** row separator. This avoids having to maintain different input
2773
+ ** and output row separators. */
2774
+ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
2775
+ nSep = strlen30(p->rowSeparator);
26762776
}
26772777
if( nSep>1 ){
2678
- fprintf(stderr, "Error: multi-character separators not allowed"
2778
+ fprintf(stderr, "Error: multi-character row separators not allowed"
26792779
" for import\n");
26802780
return 1;
26812781
}
2682
- sCsv.zFile = zFile;
2683
- sCsv.nLine = 1;
2684
- if( sCsv.zFile[0]=='|' ){
2685
- sCsv.in = popen(sCsv.zFile+1, "r");
2686
- sCsv.zFile = "<pipe>";
2782
+ sCtx.zFile = zFile;
2783
+ sCtx.nLine = 1;
2784
+ if( sCtx.zFile[0]=='|' ){
2785
+ sCtx.in = popen(sCtx.zFile+1, "r");
2786
+ sCtx.zFile = "<pipe>";
26872787
xCloser = pclose;
26882788
}else{
2689
- sCsv.in = fopen(sCsv.zFile, "rb");
2789
+ sCtx.in = fopen(sCtx.zFile, "rb");
26902790
xCloser = fclose;
26912791
}
2692
- if( sCsv.in==0 ){
2792
+ if( p->mode==MODE_Ascii ){
2793
+ xRead = ascii_read_one_field;
2794
+ }else{
2795
+ xRead = csv_read_one_field;
2796
+ }
2797
+ if( sCtx.in==0 ){
26932798
fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
26942799
return 1;
26952800
}
2696
- sCsv.cSeparator = p->separator[0];
2801
+ sCtx.cColSep = p->colSeparator[0];
2802
+ sCtx.cRowSep = p->rowSeparator[0];
26972803
zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
26982804
if( zSql==0 ){
26992805
fprintf(stderr, "Error: out of memory\n");
2700
- xCloser(sCsv.in);
2806
+ xCloser(sCtx.in);
27012807
return 1;
27022808
}
27032809
nByte = strlen30(zSql);
27042810
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2705
- csv_append_char(&sCsv, 0); /* To ensure sCsv.z is allocated */
2811
+ import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
27062812
if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
27072813
char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
27082814
char cSep = '(';
2709
- while( csv_read_one_field(&sCsv) ){
2710
- zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCsv.z);
2815
+ while( xRead(&sCtx) ){
2816
+ zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCtx.z);
27112817
cSep = ',';
2712
- if( sCsv.cTerm!=sCsv.cSeparator ) break;
2818
+ if( sCtx.cTerm!=sCtx.cColSep ) break;
27132819
}
27142820
if( cSep=='(' ){
27152821
sqlite3_free(zCreate);
2716
- sqlite3_free(sCsv.z);
2717
- xCloser(sCsv.in);
2718
- fprintf(stderr,"%s: empty file\n", sCsv.zFile);
2822
+ sqlite3_free(sCtx.z);
2823
+ xCloser(sCtx.in);
2824
+ fprintf(stderr,"%s: empty file\n", sCtx.zFile);
27192825
return 1;
27202826
}
27212827
zCreate = sqlite3_mprintf("%z\n)", zCreate);
27222828
rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
27232829
sqlite3_free(zCreate);
27242830
if( rc ){
27252831
fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
27262832
sqlite3_errmsg(db));
2727
- sqlite3_free(sCsv.z);
2728
- xCloser(sCsv.in);
2833
+ sqlite3_free(sCtx.z);
2834
+ xCloser(sCtx.in);
27292835
return 1;
27302836
}
27312837
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
27322838
}
27332839
sqlite3_free(zSql);
27342840
if( rc ){
27352841
if (pStmt) sqlite3_finalize(pStmt);
27362842
fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
2737
- xCloser(sCsv.in);
2843
+ xCloser(sCtx.in);
27382844
return 1;
27392845
}
27402846
nCol = sqlite3_column_count(pStmt);
27412847
sqlite3_finalize(pStmt);
27422848
pStmt = 0;
27432849
if( nCol==0 ) return 0; /* no columns, no error */
27442850
zSql = sqlite3_malloc( nByte*2 + 20 + nCol*2 );
27452851
if( zSql==0 ){
27462852
fprintf(stderr, "Error: out of memory\n");
2747
- xCloser(sCsv.in);
2853
+ xCloser(sCtx.in);
27482854
return 1;
27492855
}
27502856
sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
27512857
j = strlen30(zSql);
27522858
for(i=1; i<nCol; i++){
@@ -2758,50 +2864,60 @@
27582864
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
27592865
sqlite3_free(zSql);
27602866
if( rc ){
27612867
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
27622868
if (pStmt) sqlite3_finalize(pStmt);
2763
- xCloser(sCsv.in);
2869
+ xCloser(sCtx.in);
27642870
return 1;
27652871
}
27662872
needCommit = sqlite3_get_autocommit(db);
27672873
if( needCommit ) sqlite3_exec(db, "BEGIN", 0, 0, 0);
27682874
do{
2769
- int startLine = sCsv.nLine;
2875
+ int startLine = sCtx.nLine;
27702876
for(i=0; i<nCol; i++){
2771
- char *z = csv_read_one_field(&sCsv);
2877
+ char *z = xRead(&sCtx);
2878
+ /*
2879
+ ** Did we reach end-of-file before finding any columns?
2880
+ ** If so, stop instead of NULL filling the remaining columns.
2881
+ */
27722882
if( z==0 && i==0 ) break;
2883
+ /*
2884
+ ** Did we reach end-of-file OR end-of-line before finding any
2885
+ ** columns in ASCII mode? If so, stop instead of NULL filling
2886
+ ** the remaining columns.
2887
+ */
2888
+ if( p->mode==MODE_Ascii && (z==0 || z[0]==0) && i==0 ) break;
27732889
sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
2774
- if( i<nCol-1 && sCsv.cTerm!=sCsv.cSeparator ){
2890
+ if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
27752891
fprintf(stderr, "%s:%d: expected %d columns but found %d - "
27762892
"filling the rest with NULL\n",
2777
- sCsv.zFile, startLine, nCol, i+1);
2893
+ sCtx.zFile, startLine, nCol, i+1);
27782894
i++;
27792895
while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
27802896
}
27812897
}
2782
- if( sCsv.cTerm==sCsv.cSeparator ){
2898
+ if( sCtx.cTerm==sCtx.cColSep ){
27832899
do{
2784
- csv_read_one_field(&sCsv);
2900
+ xRead(&sCtx);
27852901
i++;
2786
- }while( sCsv.cTerm==sCsv.cSeparator );
2902
+ }while( sCtx.cTerm==sCtx.cColSep );
27872903
fprintf(stderr, "%s:%d: expected %d columns but found %d - "
27882904
"extras ignored\n",
2789
- sCsv.zFile, startLine, nCol, i);
2905
+ sCtx.zFile, startLine, nCol, i);
27902906
}
27912907
if( i>=nCol ){
27922908
sqlite3_step(pStmt);
27932909
rc = sqlite3_reset(pStmt);
27942910
if( rc!=SQLITE_OK ){
2795
- fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCsv.zFile, startLine,
2911
+ fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile, startLine,
27962912
sqlite3_errmsg(db));
27972913
}
27982914
}
2799
- }while( sCsv.cTerm!=EOF );
2915
+ }while( sCtx.cTerm!=EOF );
28002916
2801
- xCloser(sCsv.in);
2802
- sqlite3_free(sCsv.z);
2917
+ xCloser(sCtx.in);
2918
+ sqlite3_free(sCtx.z);
28032919
sqlite3_finalize(pStmt);
28042920
if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
28052921
}else
28062922
28072923
if( c=='i' && strncmp(azArg[0], "indices", n)==0 ){
@@ -2915,32 +3031,36 @@
29153031
p->mode = MODE_List;
29163032
}else if( c2=='h' && strncmp(azArg[1],"html",n2)==0 ){
29173033
p->mode = MODE_Html;
29183034
}else if( c2=='t' && strncmp(azArg[1],"tcl",n2)==0 ){
29193035
p->mode = MODE_Tcl;
2920
- sqlite3_snprintf(sizeof(p->separator), p->separator, " ");
3036
+ sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Space);
29213037
}else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
29223038
p->mode = MODE_Csv;
2923
- sqlite3_snprintf(sizeof(p->separator), p->separator, ",");
2924
- sqlite3_snprintf(sizeof(p->newline), p->newline, "\r\n");
3039
+ sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
3040
+ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
29253041
}else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
29263042
p->mode = MODE_List;
2927
- sqlite3_snprintf(sizeof(p->separator), p->separator, "\t");
3043
+ sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Tab);
29283044
}else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
29293045
p->mode = MODE_Insert;
29303046
set_table_name(p, nArg>=3 ? azArg[2] : "table");
3047
+ }else if( c2=='a' && strncmp(azArg[1],"ascii",n2)==0 ){
3048
+ p->mode = MODE_Ascii;
3049
+ sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
3050
+ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
29313051
}else {
29323052
fprintf(stderr,"Error: mode should be one of: "
2933
- "column csv html insert line list tabs tcl\n");
3053
+ "ascii column csv html insert line list tabs tcl\n");
29343054
rc = 1;
29353055
}
29363056
}else
29373057
29383058
if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
29393059
if( nArg==2 ){
2940
- sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue,
2941
- "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
3060
+ sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
3061
+ "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
29423062
}else{
29433063
fprintf(stderr, "Usage: .nullvalue STRING\n");
29443064
rc = 1;
29453065
}
29463066
}else
@@ -3221,18 +3341,20 @@
32213341
}else
32223342
#endif
32233343
32243344
if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
32253345
if( nArg<2 || nArg>3 ){
3226
- fprintf(stderr, "Usage: .separator SEPARATOR ?NEWLINE?\n");
3346
+ fprintf(stderr, "Usage: .separator COL ?ROW?\n");
32273347
rc = 1;
32283348
}
32293349
if( nArg>=2 ){
3230
- sqlite3_snprintf(sizeof(p->separator), p->separator, azArg[1]);
3350
+ sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator,
3351
+ "%.*s", (int)ArraySize(p->colSeparator)-1, azArg[1]);
32313352
}
32323353
if( nArg>=3 ){
3233
- sqlite3_snprintf(sizeof(p->newline), p->newline, azArg[2]);
3354
+ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator,
3355
+ "%.*s", (int)ArraySize(p->rowSeparator)-1, azArg[2]);
32343356
}
32353357
}else
32363358
32373359
if( c=='s'
32383360
&& (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
@@ -3259,27 +3381,28 @@
32593381
if( nArg!=1 ){
32603382
fprintf(stderr, "Usage: .show\n");
32613383
rc = 1;
32623384
goto meta_command_exit;
32633385
}
3264
- fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
3265
- fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
3386
+ fprintf(p->out,"%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
3387
+ fprintf(p->out,"%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
32663388
fprintf(p->out,"%9.9s: %s\n","explain", p->normalMode.valid ? "on" :"off");
3267
- fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
3268
- fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
3269
- fprintf(p->out,"%9.9s: ", "nullvalue");
3270
- output_c_string(p->out, p->nullvalue);
3389
+ fprintf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
3390
+ fprintf(p->out,"%12.12s: %s\n","mode", modeDescr[p->mode]);
3391
+ fprintf(p->out,"%12.12s: ", "nullvalue");
3392
+ output_c_string(p->out, p->nullValue);
32713393
fprintf(p->out, "\n");
3272
- fprintf(p->out,"%9.9s: %s\n","output",
3394
+ fprintf(p->out,"%12.12s: %s\n","output",
32733395
strlen30(p->outfile) ? p->outfile : "stdout");
3274
- fprintf(p->out,"%9.9s: ", "separator");
3275
- output_c_string(p->out, p->separator);
3276
- fprintf(p->out," ");
3277
- output_c_string(p->out, p->newline);
3396
+ fprintf(p->out,"%12.12s: ", "colseparator");
3397
+ output_c_string(p->out, p->colSeparator);
3398
+ fprintf(p->out, "\n");
3399
+ fprintf(p->out,"%12.12s: ", "rowseparator");
3400
+ output_c_string(p->out, p->rowSeparator);
32783401
fprintf(p->out, "\n");
3279
- fprintf(p->out,"%9.9s: %s\n","stats", p->statsOn ? "on" : "off");
3280
- fprintf(p->out,"%9.9s: ","width");
3402
+ fprintf(p->out,"%12.12s: %s\n","stats", p->statsOn ? "on" : "off");
3403
+ fprintf(p->out,"%12.12s: ","width");
32813404
for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
32823405
fprintf(p->out,"%d ",p->colWidth[i]);
32833406
}
32843407
fprintf(p->out,"\n");
32853408
}else
@@ -3936,10 +4059,11 @@
39364059
39374060
/*
39384061
** Show available command line options
39394062
*/
39404063
static const char zOptions[] =
4064
+ " -ascii set output mode to 'ascii'\n"
39414065
" -bail stop after hitting an error\n"
39424066
" -batch force batch I/O\n"
39434067
" -column set output mode to 'column'\n"
39444068
" -cmd COMMAND run \"COMMAND\" before reading stdin\n"
39454069
" -csv set output mode to 'csv'\n"
@@ -3957,15 +4081,15 @@
39574081
" -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
39584082
" -mmap N default mmap size set to N\n"
39594083
#ifdef SQLITE_ENABLE_MULTIPLEX
39604084
" -multiplex enable the multiplexor VFS\n"
39614085
#endif
3962
- " -newline SEP set newline character(s) for CSV\n"
4086
+ " -newline SEP set output row separator. Default: '\\n'\n"
39634087
" -nullvalue TEXT set text string for NULL values. Default ''\n"
39644088
" -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
39654089
" -scratch SIZE N use N slots of SZ bytes each for scratch memory\n"
3966
- " -separator SEP set output field separator. Default: '|'\n"
4090
+ " -separator SEP set output column separator. Default: '|'\n"
39674091
" -stats print memory stats before each finalize\n"
39684092
" -version show SQLite version\n"
39694093
" -vfs NAME use NAME as the default VFS\n"
39704094
#ifdef SQLITE_ENABLE_VFSTRACE
39714095
" -vfstrace enable tracing of all VFS calls\n"
@@ -3988,12 +4112,12 @@
39884112
** Initialize the state information in data
39894113
*/
39904114
static void main_init(ShellState *data) {
39914115
memset(data, 0, sizeof(*data));
39924116
data->mode = MODE_List;
3993
- memcpy(data->separator,"|", 2);
3994
- memcpy(data->newline,"\r\n", 3);
4117
+ memcpy(data->colSeparator,SEP_Column, 2);
4118
+ memcpy(data->rowSeparator,SEP_Row, 2);
39954119
data->showHeader = 0;
39964120
data->shellFlgs = SHFLG_Lookaside;
39974121
sqlite3_config(SQLITE_CONFIG_URI, 1);
39984122
sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
39994123
sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
@@ -4228,19 +4352,25 @@
42284352
data.mode = MODE_Line;
42294353
}else if( strcmp(z,"-column")==0 ){
42304354
data.mode = MODE_Column;
42314355
}else if( strcmp(z,"-csv")==0 ){
42324356
data.mode = MODE_Csv;
4233
- memcpy(data.separator,",",2);
4357
+ memcpy(data.colSeparator,",",2);
4358
+ }else if( strcmp(z,"-ascii")==0 ){
4359
+ data.mode = MODE_Ascii;
4360
+ sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
4361
+ SEP_Unit);
4362
+ sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
4363
+ SEP_Record);
42344364
}else if( strcmp(z,"-separator")==0 ){
4235
- sqlite3_snprintf(sizeof(data.separator), data.separator,
4365
+ sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
42364366
"%s",cmdline_option_value(argc,argv,++i));
42374367
}else if( strcmp(z,"-newline")==0 ){
4238
- sqlite3_snprintf(sizeof(data.newline), data.newline,
4368
+ sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
42394369
"%s",cmdline_option_value(argc,argv,++i));
42404370
}else if( strcmp(z,"-nullvalue")==0 ){
4241
- sqlite3_snprintf(sizeof(data.nullvalue), data.nullvalue,
4371
+ sqlite3_snprintf(sizeof(data.nullValue), data.nullValue,
42424372
"%s",cmdline_option_value(argc,argv,++i));
42434373
}else if( strcmp(z,"-header")==0 ){
42444374
data.showHeader = 1;
42454375
}else if( strcmp(z,"-noheader")==0 ){
42464376
data.showHeader = 0;
@@ -4356,11 +4486,11 @@
43564486
nHistory = strlen30(zHome) + 20;
43574487
if( (zHistory = malloc(nHistory))!=0 ){
43584488
sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
43594489
}
43604490
}
4361
-#if defined(HAVE_READLINE)
4491
+#if HAVE_READLINE
43624492
if( zHistory ) read_history(zHistory);
43634493
#endif
43644494
rc = process_input(&data, 0);
43654495
if( zHistory ){
43664496
stifle_history(100);
43674497
--- src/shell.c
+++ src/shell.c
@@ -15,10 +15,17 @@
15 #if (defined(_WIN32) || defined(WIN32)) && !defined(_CRT_SECURE_NO_WARNINGS)
16 /* This needs to come before any includes for MSVC compiler */
17 #define _CRT_SECURE_NO_WARNINGS
18 #endif
19
 
 
 
 
 
 
 
20 /*
21 ** Enable large-file support for fopen() and friends on unix.
22 */
23 #ifndef SQLITE_DISABLE_LFS
24 # define _LARGE_FILE 1
@@ -46,21 +53,20 @@
46 # endif
47 # include <unistd.h>
48 # include <sys/types.h>
49 #endif
50
51 #if defined(HAVE_READLINE) && HAVE_READLINE!=0
52 # include <readline/readline.h>
53 # include <readline/history.h>
54 #else
55 # undef HAVE_READLINE
56 #endif
57 #if defined(HAVE_EDITLINE) && !defined(HAVE_READLINE)
 
58 # define HAVE_READLINE 1
59 # include <editline/readline.h>
60 #endif
61 #if !defined(HAVE_READLINE)
62 # define add_history(X)
63 # define read_history(X)
64 # define write_history(X)
65 # define stifle_history(X)
66 #endif
@@ -423,11 +429,11 @@
423 char *zResult;
424 if( in!=0 ){
425 zResult = local_getline(zPrior, in);
426 }else{
427 zPrompt = isContinuation ? continuePrompt : mainPrompt;
428 #if defined(HAVE_READLINE)
429 free(zPrior);
430 zResult = readline(zPrompt);
431 if( zResult && *zResult ) add_history(zResult);
432 #else
433 printf("%s", zPrompt);
@@ -469,15 +475,15 @@
469 int mode; /* An output mode setting */
470 int writableSchema; /* True if PRAGMA writable_schema=ON */
471 int showHeader; /* True to show column names in List or Column mode */
472 unsigned shellFlgs; /* Various flags */
473 char *zDestTable; /* Name of destination table when MODE_Insert */
474 char separator[20]; /* Separator character for MODE_List */
475 char newline[20]; /* Record separator in MODE_Csv */
476 int colWidth[100]; /* Requested width of each column when in column mode*/
477 int actualWidth[100]; /* Actual width of each column */
478 char nullvalue[20]; /* The text to print when a NULL comes back from
479 ** the database */
480 SavedModeInfo normalMode;/* Holds the mode just before .explain ON */
481 char outfile[FILENAME_MAX]; /* Filename for *out */
482 const char *zDbFilename; /* name of the database file */
483 char *zFreeOnClose; /* Filename to free when closing */
@@ -506,10 +512,11 @@
506 #define MODE_Html 4 /* Generate an XHTML table */
507 #define MODE_Insert 5 /* Generate SQL "insert" statements */
508 #define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */
509 #define MODE_Csv 7 /* Quote strings, numbers are plain */
510 #define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */
 
511
512 static const char *modeDescr[] = {
513 "line",
514 "column",
515 "list",
@@ -517,12 +524,26 @@
517 "html",
518 "insert",
519 "tcl",
520 "csv",
521 "explain",
 
522 };
523
 
 
 
 
 
 
 
 
 
 
 
 
 
524 /*
525 ** Number of elements in an array
526 */
527 #define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
528
@@ -675,26 +696,26 @@
675 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
676 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
677 };
678
679 /*
680 ** Output a single term of CSV. Actually, p->separator is used for
681 ** the separator, which may or may not be a comma. p->nullvalue is
682 ** the null value. Strings are quoted if necessary. The separator
683 ** is only issued if bSep is true.
684 */
685 static void output_csv(ShellState *p, const char *z, int bSep){
686 FILE *out = p->out;
687 if( z==0 ){
688 fprintf(out,"%s",p->nullvalue);
689 }else{
690 int i;
691 int nSep = strlen30(p->separator);
692 for(i=0; z[i]; i++){
693 if( needCsvQuote[((unsigned char*)z)[i]]
694 || (z[i]==p->separator[0] &&
695 (nSep==1 || memcmp(z, p->separator, nSep)==0)) ){
696 i = 0;
697 break;
698 }
699 }
700 if( i==0 ){
@@ -707,11 +728,11 @@
707 }else{
708 fprintf(out, "%s", z);
709 }
710 }
711 if( bSep ){
712 fprintf(p->out, "%s", p->separator);
713 }
714 }
715
716 #ifdef SIGINT
717 /*
@@ -745,14 +766,14 @@
745 if( azArg==0 ) break;
746 for(i=0; i<nArg; i++){
747 int len = strlen30(azCol[i] ? azCol[i] : "");
748 if( len>w ) w = len;
749 }
750 if( p->cnt++>0 ) fprintf(p->out,"\n");
751 for(i=0; i<nArg; i++){
752 fprintf(p->out,"%*s = %s\n", w, azCol[i],
753 azArg[i] ? azArg[i] : p->nullvalue);
754 }
755 break;
756 }
757 case MODE_Explain:
758 case MODE_Column: {
@@ -765,21 +786,23 @@
765 w = 0;
766 }
767 if( w==0 ){
768 w = strlen30(azCol[i] ? azCol[i] : "");
769 if( w<10 ) w = 10;
770 n = strlen30(azArg && azArg[i] ? azArg[i] : p->nullvalue);
771 if( w<n ) w = n;
772 }
773 if( i<ArraySize(p->actualWidth) ){
774 p->actualWidth[i] = w;
775 }
776 if( p->showHeader ){
777 if( w<0 ){
778 fprintf(p->out,"%*.*s%s",-w,-w,azCol[i], i==nArg-1 ? "\n": " ");
 
779 }else{
780 fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": " ");
 
781 }
782 }
783 }
784 if( p->showHeader ){
785 for(i=0; i<nArg; i++){
@@ -790,11 +813,11 @@
790 }else{
791 w = 10;
792 }
793 fprintf(p->out,"%-*.*s%s",w,w,"-----------------------------------"
794 "----------------------------------------------------------",
795 i==nArg-1 ? "\n": " ");
796 }
797 }
798 }
799 if( azArg==0 ) break;
800 for(i=0; i<nArg; i++){
@@ -813,36 +836,39 @@
813 }
814 p->iIndent++;
815 }
816 if( w<0 ){
817 fprintf(p->out,"%*.*s%s",-w,-w,
818 azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
 
819 }else{
820 fprintf(p->out,"%-*.*s%s",w,w,
821 azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
 
822 }
823 }
824 break;
825 }
826 case MODE_Semi:
827 case MODE_List: {
828 if( p->cnt++==0 && p->showHeader ){
829 for(i=0; i<nArg; i++){
830 fprintf(p->out,"%s%s",azCol[i], i==nArg-1 ? "\n" : p->separator);
 
831 }
832 }
833 if( azArg==0 ) break;
834 for(i=0; i<nArg; i++){
835 char *z = azArg[i];
836 if( z==0 ) z = p->nullvalue;
837 fprintf(p->out, "%s", z);
838 if( i<nArg-1 ){
839 fprintf(p->out, "%s", p->separator);
840 }else if( p->mode==MODE_Semi ){
841 fprintf(p->out, ";\n");
842 }else{
843 fprintf(p->out, "\n");
844 }
845 }
846 break;
847 }
848 case MODE_Html: {
@@ -857,30 +883,30 @@
857 }
858 if( azArg==0 ) break;
859 fprintf(p->out,"<TR>");
860 for(i=0; i<nArg; i++){
861 fprintf(p->out,"<TD>");
862 output_html_string(p->out, azArg[i] ? azArg[i] : p->nullvalue);
863 fprintf(p->out,"</TD>\n");
864 }
865 fprintf(p->out,"</TR>\n");
866 break;
867 }
868 case MODE_Tcl: {
869 if( p->cnt++==0 && p->showHeader ){
870 for(i=0; i<nArg; i++){
871 output_c_string(p->out,azCol[i] ? azCol[i] : "");
872 if(i<nArg-1) fprintf(p->out, "%s", p->separator);
873 }
874 fprintf(p->out,"\n");
875 }
876 if( azArg==0 ) break;
877 for(i=0; i<nArg; i++){
878 output_c_string(p->out, azArg[i] ? azArg[i] : p->nullvalue);
879 if(i<nArg-1) fprintf(p->out, "%s", p->separator);
880 }
881 fprintf(p->out,"\n");
882 break;
883 }
884 case MODE_Csv: {
885 #if defined(WIN32) || defined(_WIN32)
886 fflush(p->out);
@@ -888,17 +914,17 @@
888 #endif
889 if( p->cnt++==0 && p->showHeader ){
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 }
901 #if defined(WIN32) || defined(_WIN32)
902 fflush(p->out);
903 _setmode(_fileno(p->out), _O_TEXT);
904 #endif
@@ -930,10 +956,26 @@
930 output_quoted_string(p->out, azArg[i]);
931 }
932 }
933 fprintf(p->out,");\n");
934 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
935 }
936 }
937 return 0;
938 }
939
@@ -1696,16 +1738,17 @@
1696 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1697 ".load FILE ?ENTRY? Load an extension library\n"
1698 #endif
1699 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
1700 ".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
 
1701 " csv Comma-separated values\n"
1702 " column Left-aligned columns. (See .width)\n"
1703 " html HTML <table> code\n"
1704 " insert SQL insert statements for TABLE\n"
1705 " line One value per line\n"
1706 " list Values delimited by .separator string\n"
1707 " tabs Tab-separated values\n"
1708 " tcl TCL list elements\n"
1709 ".nullvalue STRING Use STRING in place of NULL values\n"
1710 ".once FILENAME Output for the next SQL command only to FILENAME\n"
1711 ".open ?FILENAME? Close existing database and reopen FILENAME\n"
@@ -1718,12 +1761,12 @@
1718 ".save FILE Write in-memory database into FILE\n"
1719 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
1720 ".schema ?TABLE? Show the CREATE statements\n"
1721 " If TABLE specified, only show tables matching\n"
1722 " LIKE pattern TABLE.\n"
1723 ".separator STRING ?NL? Change separator used by output mode and .import\n"
1724 " NL is the end-of-line mark for CSV\n"
1725 ".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
1726 ".show Show the current values for various settings\n"
1727 ".stats on|off Turn stats on or off\n"
1728 ".system CMD ARGS... Run CMD ARGS... in a system shell\n"
1729 ".tables ?TABLE? List names of tables\n"
@@ -2000,26 +2043,27 @@
2000 static int nCall = 0;
2001 nCall++;
2002 }
2003
2004 /*
2005 ** An object used to read a CSV file
2006 */
2007 typedef struct CSVReader CSVReader;
2008 struct CSVReader {
2009 const char *zFile; /* Name of the input file */
2010 FILE *in; /* Read the CSV text from this input stream */
2011 char *z; /* Accumulated text for a field */
2012 int n; /* Number of bytes in z */
2013 int nAlloc; /* Space allocated for z[] */
2014 int nLine; /* Current line number */
2015 int cTerm; /* Character that terminated the most recent field */
2016 int cSeparator; /* The separator character. (Usually ",") */
 
2017 };
2018
2019 /* Append a single byte to z[] */
2020 static void csv_append_char(CSVReader *p, int c){
2021 if( p->n+1>=p->nAlloc ){
2022 p->nAlloc += p->nAlloc + 100;
2023 p->z = sqlite3_realloc(p->z, p->nAlloc);
2024 if( p->z==0 ){
2025 fprintf(stderr, "out of memory\n");
@@ -2033,41 +2077,44 @@
2033 ** with the option of having a separator other than ",".
2034 **
2035 ** + Input comes from p->in.
2036 ** + Store results in p->z of length p->n. Space to hold p->z comes
2037 ** from sqlite3_malloc().
2038 ** + Use p->cSep as the separator. The default is ",".
 
2039 ** + Keep track of the line number in p->nLine.
2040 ** + Store the character that terminates the field in p->cTerm. Store
2041 ** EOF on end-of-file.
2042 ** + Report syntax errors on stderr
2043 */
2044 static char *csv_read_one_field(CSVReader *p){
2045 int c, pc, ppc;
2046 int cSep = p->cSeparator;
 
2047 p->n = 0;
2048 c = fgetc(p->in);
2049 if( c==EOF || seenInterrupt ){
2050 p->cTerm = EOF;
2051 return 0;
2052 }
2053 if( c=='"' ){
 
2054 int startLine = p->nLine;
2055 int cQuote = c;
2056 pc = ppc = 0;
2057 while( 1 ){
2058 c = fgetc(p->in);
2059 if( c=='\n' ) p->nLine++;
2060 if( c==cQuote ){
2061 if( pc==cQuote ){
2062 pc = 0;
2063 continue;
2064 }
2065 }
2066 if( (c==cSep && pc==cQuote)
2067 || (c=='\n' && pc==cQuote)
2068 || (c=='\n' && pc=='\r' && ppc==cQuote)
2069 || (c==EOF && pc==cQuote)
2070 ){
2071 do{ p->n--; }while( p->z[p->n]!=cQuote );
2072 p->cTerm = c;
2073 break;
@@ -2077,31 +2124,65 @@
2077 p->zFile, p->nLine, cQuote);
2078 }
2079 if( c==EOF ){
2080 fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
2081 p->zFile, startLine, cQuote);
2082 p->cTerm = EOF;
2083 break;
2084 }
2085 csv_append_char(p, c);
2086 ppc = pc;
2087 pc = c;
2088 }
2089 }else{
2090 while( c!=EOF && c!=cSep && c!='\n' ){
2091 csv_append_char(p, c);
2092 c = fgetc(p->in);
2093 }
2094 if( c=='\n' ){
2095 p->nLine++;
2096 if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--;
2097 }
2098 p->cTerm = c;
2099 }
2100 if( p->z ) p->z[p->n] = 0;
2101 return p->z;
2102 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2103
2104 /*
2105 ** Try to transfer data for table zTable. If an error is seen while
2106 ** moving forward, try to go backwards. The backwards movement won't
2107 ** work for WITHOUT ROWID tables.
@@ -2653,100 +2734,125 @@
2653 sqlite3_stmt *pStmt = NULL; /* A statement */
2654 int nCol; /* Number of columns in the table */
2655 int nByte; /* Number of bytes in an SQL string */
2656 int i, j; /* Loop counters */
2657 int needCommit; /* True to COMMIT or ROLLBACK at end */
2658 int nSep; /* Number of bytes in p->separator[] */
2659 char *zSql; /* An SQL statement */
2660 CSVReader sCsv; /* Reader context */
 
2661 int (*xCloser)(FILE*); /* Procedure to close th3 connection */
2662
2663 if( nArg!=3 ){
2664 fprintf(stderr, "Usage: .import FILE TABLE\n");
2665 goto meta_command_exit;
2666 }
2667 zFile = azArg[1];
2668 zTable = azArg[2];
2669 seenInterrupt = 0;
2670 memset(&sCsv, 0, sizeof(sCsv));
2671 open_db(p, 0);
2672 nSep = strlen30(p->separator);
 
 
 
 
 
 
 
 
 
 
2673 if( nSep==0 ){
2674 fprintf(stderr, "Error: non-null separator required for import\n");
2675 return 1;
 
 
 
 
 
 
 
 
2676 }
2677 if( nSep>1 ){
2678 fprintf(stderr, "Error: multi-character separators not allowed"
2679 " for import\n");
2680 return 1;
2681 }
2682 sCsv.zFile = zFile;
2683 sCsv.nLine = 1;
2684 if( sCsv.zFile[0]=='|' ){
2685 sCsv.in = popen(sCsv.zFile+1, "r");
2686 sCsv.zFile = "<pipe>";
2687 xCloser = pclose;
2688 }else{
2689 sCsv.in = fopen(sCsv.zFile, "rb");
2690 xCloser = fclose;
2691 }
2692 if( sCsv.in==0 ){
 
 
 
 
 
2693 fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
2694 return 1;
2695 }
2696 sCsv.cSeparator = p->separator[0];
 
2697 zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
2698 if( zSql==0 ){
2699 fprintf(stderr, "Error: out of memory\n");
2700 xCloser(sCsv.in);
2701 return 1;
2702 }
2703 nByte = strlen30(zSql);
2704 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2705 csv_append_char(&sCsv, 0); /* To ensure sCsv.z is allocated */
2706 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
2707 char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
2708 char cSep = '(';
2709 while( csv_read_one_field(&sCsv) ){
2710 zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCsv.z);
2711 cSep = ',';
2712 if( sCsv.cTerm!=sCsv.cSeparator ) break;
2713 }
2714 if( cSep=='(' ){
2715 sqlite3_free(zCreate);
2716 sqlite3_free(sCsv.z);
2717 xCloser(sCsv.in);
2718 fprintf(stderr,"%s: empty file\n", sCsv.zFile);
2719 return 1;
2720 }
2721 zCreate = sqlite3_mprintf("%z\n)", zCreate);
2722 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
2723 sqlite3_free(zCreate);
2724 if( rc ){
2725 fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
2726 sqlite3_errmsg(db));
2727 sqlite3_free(sCsv.z);
2728 xCloser(sCsv.in);
2729 return 1;
2730 }
2731 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2732 }
2733 sqlite3_free(zSql);
2734 if( rc ){
2735 if (pStmt) sqlite3_finalize(pStmt);
2736 fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
2737 xCloser(sCsv.in);
2738 return 1;
2739 }
2740 nCol = sqlite3_column_count(pStmt);
2741 sqlite3_finalize(pStmt);
2742 pStmt = 0;
2743 if( nCol==0 ) return 0; /* no columns, no error */
2744 zSql = sqlite3_malloc( nByte*2 + 20 + nCol*2 );
2745 if( zSql==0 ){
2746 fprintf(stderr, "Error: out of memory\n");
2747 xCloser(sCsv.in);
2748 return 1;
2749 }
2750 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
2751 j = strlen30(zSql);
2752 for(i=1; i<nCol; i++){
@@ -2758,50 +2864,60 @@
2758 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2759 sqlite3_free(zSql);
2760 if( rc ){
2761 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
2762 if (pStmt) sqlite3_finalize(pStmt);
2763 xCloser(sCsv.in);
2764 return 1;
2765 }
2766 needCommit = sqlite3_get_autocommit(db);
2767 if( needCommit ) sqlite3_exec(db, "BEGIN", 0, 0, 0);
2768 do{
2769 int startLine = sCsv.nLine;
2770 for(i=0; i<nCol; i++){
2771 char *z = csv_read_one_field(&sCsv);
 
 
 
 
2772 if( z==0 && i==0 ) break;
 
 
 
 
 
 
2773 sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
2774 if( i<nCol-1 && sCsv.cTerm!=sCsv.cSeparator ){
2775 fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2776 "filling the rest with NULL\n",
2777 sCsv.zFile, startLine, nCol, i+1);
2778 i++;
2779 while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
2780 }
2781 }
2782 if( sCsv.cTerm==sCsv.cSeparator ){
2783 do{
2784 csv_read_one_field(&sCsv);
2785 i++;
2786 }while( sCsv.cTerm==sCsv.cSeparator );
2787 fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2788 "extras ignored\n",
2789 sCsv.zFile, startLine, nCol, i);
2790 }
2791 if( i>=nCol ){
2792 sqlite3_step(pStmt);
2793 rc = sqlite3_reset(pStmt);
2794 if( rc!=SQLITE_OK ){
2795 fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCsv.zFile, startLine,
2796 sqlite3_errmsg(db));
2797 }
2798 }
2799 }while( sCsv.cTerm!=EOF );
2800
2801 xCloser(sCsv.in);
2802 sqlite3_free(sCsv.z);
2803 sqlite3_finalize(pStmt);
2804 if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
2805 }else
2806
2807 if( c=='i' && strncmp(azArg[0], "indices", n)==0 ){
@@ -2915,32 +3031,36 @@
2915 p->mode = MODE_List;
2916 }else if( c2=='h' && strncmp(azArg[1],"html",n2)==0 ){
2917 p->mode = MODE_Html;
2918 }else if( c2=='t' && strncmp(azArg[1],"tcl",n2)==0 ){
2919 p->mode = MODE_Tcl;
2920 sqlite3_snprintf(sizeof(p->separator), p->separator, " ");
2921 }else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
2922 p->mode = MODE_Csv;
2923 sqlite3_snprintf(sizeof(p->separator), p->separator, ",");
2924 sqlite3_snprintf(sizeof(p->newline), p->newline, "\r\n");
2925 }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
2926 p->mode = MODE_List;
2927 sqlite3_snprintf(sizeof(p->separator), p->separator, "\t");
2928 }else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
2929 p->mode = MODE_Insert;
2930 set_table_name(p, nArg>=3 ? azArg[2] : "table");
 
 
 
 
2931 }else {
2932 fprintf(stderr,"Error: mode should be one of: "
2933 "column csv html insert line list tabs tcl\n");
2934 rc = 1;
2935 }
2936 }else
2937
2938 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
2939 if( nArg==2 ){
2940 sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue,
2941 "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
2942 }else{
2943 fprintf(stderr, "Usage: .nullvalue STRING\n");
2944 rc = 1;
2945 }
2946 }else
@@ -3221,18 +3341,20 @@
3221 }else
3222 #endif
3223
3224 if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
3225 if( nArg<2 || nArg>3 ){
3226 fprintf(stderr, "Usage: .separator SEPARATOR ?NEWLINE?\n");
3227 rc = 1;
3228 }
3229 if( nArg>=2 ){
3230 sqlite3_snprintf(sizeof(p->separator), p->separator, azArg[1]);
 
3231 }
3232 if( nArg>=3 ){
3233 sqlite3_snprintf(sizeof(p->newline), p->newline, azArg[2]);
 
3234 }
3235 }else
3236
3237 if( c=='s'
3238 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
@@ -3259,27 +3381,28 @@
3259 if( nArg!=1 ){
3260 fprintf(stderr, "Usage: .show\n");
3261 rc = 1;
3262 goto meta_command_exit;
3263 }
3264 fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
3265 fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
3266 fprintf(p->out,"%9.9s: %s\n","explain", p->normalMode.valid ? "on" :"off");
3267 fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
3268 fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
3269 fprintf(p->out,"%9.9s: ", "nullvalue");
3270 output_c_string(p->out, p->nullvalue);
3271 fprintf(p->out, "\n");
3272 fprintf(p->out,"%9.9s: %s\n","output",
3273 strlen30(p->outfile) ? p->outfile : "stdout");
3274 fprintf(p->out,"%9.9s: ", "separator");
3275 output_c_string(p->out, p->separator);
3276 fprintf(p->out," ");
3277 output_c_string(p->out, p->newline);
 
3278 fprintf(p->out, "\n");
3279 fprintf(p->out,"%9.9s: %s\n","stats", p->statsOn ? "on" : "off");
3280 fprintf(p->out,"%9.9s: ","width");
3281 for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
3282 fprintf(p->out,"%d ",p->colWidth[i]);
3283 }
3284 fprintf(p->out,"\n");
3285 }else
@@ -3936,10 +4059,11 @@
3936
3937 /*
3938 ** Show available command line options
3939 */
3940 static const char zOptions[] =
 
3941 " -bail stop after hitting an error\n"
3942 " -batch force batch I/O\n"
3943 " -column set output mode to 'column'\n"
3944 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
3945 " -csv set output mode to 'csv'\n"
@@ -3957,15 +4081,15 @@
3957 " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
3958 " -mmap N default mmap size set to N\n"
3959 #ifdef SQLITE_ENABLE_MULTIPLEX
3960 " -multiplex enable the multiplexor VFS\n"
3961 #endif
3962 " -newline SEP set newline character(s) for CSV\n"
3963 " -nullvalue TEXT set text string for NULL values. Default ''\n"
3964 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
3965 " -scratch SIZE N use N slots of SZ bytes each for scratch memory\n"
3966 " -separator SEP set output field separator. Default: '|'\n"
3967 " -stats print memory stats before each finalize\n"
3968 " -version show SQLite version\n"
3969 " -vfs NAME use NAME as the default VFS\n"
3970 #ifdef SQLITE_ENABLE_VFSTRACE
3971 " -vfstrace enable tracing of all VFS calls\n"
@@ -3988,12 +4112,12 @@
3988 ** Initialize the state information in data
3989 */
3990 static void main_init(ShellState *data) {
3991 memset(data, 0, sizeof(*data));
3992 data->mode = MODE_List;
3993 memcpy(data->separator,"|", 2);
3994 memcpy(data->newline,"\r\n", 3);
3995 data->showHeader = 0;
3996 data->shellFlgs = SHFLG_Lookaside;
3997 sqlite3_config(SQLITE_CONFIG_URI, 1);
3998 sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
3999 sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
@@ -4228,19 +4352,25 @@
4228 data.mode = MODE_Line;
4229 }else if( strcmp(z,"-column")==0 ){
4230 data.mode = MODE_Column;
4231 }else if( strcmp(z,"-csv")==0 ){
4232 data.mode = MODE_Csv;
4233 memcpy(data.separator,",",2);
 
 
 
 
 
 
4234 }else if( strcmp(z,"-separator")==0 ){
4235 sqlite3_snprintf(sizeof(data.separator), data.separator,
4236 "%s",cmdline_option_value(argc,argv,++i));
4237 }else if( strcmp(z,"-newline")==0 ){
4238 sqlite3_snprintf(sizeof(data.newline), data.newline,
4239 "%s",cmdline_option_value(argc,argv,++i));
4240 }else if( strcmp(z,"-nullvalue")==0 ){
4241 sqlite3_snprintf(sizeof(data.nullvalue), data.nullvalue,
4242 "%s",cmdline_option_value(argc,argv,++i));
4243 }else if( strcmp(z,"-header")==0 ){
4244 data.showHeader = 1;
4245 }else if( strcmp(z,"-noheader")==0 ){
4246 data.showHeader = 0;
@@ -4356,11 +4486,11 @@
4356 nHistory = strlen30(zHome) + 20;
4357 if( (zHistory = malloc(nHistory))!=0 ){
4358 sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
4359 }
4360 }
4361 #if defined(HAVE_READLINE)
4362 if( zHistory ) read_history(zHistory);
4363 #endif
4364 rc = process_input(&data, 0);
4365 if( zHistory ){
4366 stifle_history(100);
4367
--- src/shell.c
+++ src/shell.c
@@ -15,10 +15,17 @@
15 #if (defined(_WIN32) || defined(WIN32)) && !defined(_CRT_SECURE_NO_WARNINGS)
16 /* This needs to come before any includes for MSVC compiler */
17 #define _CRT_SECURE_NO_WARNINGS
18 #endif
19
20 /*
21 ** If requested, include the SQLite compiler options file for MSVC.
22 */
23 #if defined(INCLUDE_MSVC_H)
24 #include "msvc.h"
25 #endif
26
27 /*
28 ** Enable large-file support for fopen() and friends on unix.
29 */
30 #ifndef SQLITE_DISABLE_LFS
31 # define _LARGE_FILE 1
@@ -46,21 +53,20 @@
53 # endif
54 # include <unistd.h>
55 # include <sys/types.h>
56 #endif
57
58 #if HAVE_READLINE
59 # include <readline/readline.h>
60 # include <readline/history.h>
 
 
61 #endif
62 #if HAVE_EDITLINE
63 # undef HAVE_READLINE
64 # define HAVE_READLINE 1
65 # include <editline/readline.h>
66 #endif
67 #if !HAVE_READLINE
68 # define add_history(X)
69 # define read_history(X)
70 # define write_history(X)
71 # define stifle_history(X)
72 #endif
@@ -423,11 +429,11 @@
429 char *zResult;
430 if( in!=0 ){
431 zResult = local_getline(zPrior, in);
432 }else{
433 zPrompt = isContinuation ? continuePrompt : mainPrompt;
434 #if HAVE_READLINE
435 free(zPrior);
436 zResult = readline(zPrompt);
437 if( zResult && *zResult ) add_history(zResult);
438 #else
439 printf("%s", zPrompt);
@@ -469,15 +475,15 @@
475 int mode; /* An output mode setting */
476 int writableSchema; /* True if PRAGMA writable_schema=ON */
477 int showHeader; /* True to show column names in List or Column mode */
478 unsigned shellFlgs; /* Various flags */
479 char *zDestTable; /* Name of destination table when MODE_Insert */
480 char colSeparator[20]; /* Column separator character for several modes */
481 char rowSeparator[20]; /* Row separator character for MODE_Ascii */
482 int colWidth[100]; /* Requested width of each column when in column mode*/
483 int actualWidth[100]; /* Actual width of each column */
484 char nullValue[20]; /* The text to print when a NULL comes back from
485 ** the database */
486 SavedModeInfo normalMode;/* Holds the mode just before .explain ON */
487 char outfile[FILENAME_MAX]; /* Filename for *out */
488 const char *zDbFilename; /* name of the database file */
489 char *zFreeOnClose; /* Filename to free when closing */
@@ -506,10 +512,11 @@
512 #define MODE_Html 4 /* Generate an XHTML table */
513 #define MODE_Insert 5 /* Generate SQL "insert" statements */
514 #define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */
515 #define MODE_Csv 7 /* Quote strings, numbers are plain */
516 #define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */
517 #define MODE_Ascii 9 /* Use ASCII unit and record separators (0x1F/0x1E) */
518
519 static const char *modeDescr[] = {
520 "line",
521 "column",
522 "list",
@@ -517,12 +524,26 @@
524 "html",
525 "insert",
526 "tcl",
527 "csv",
528 "explain",
529 "ascii",
530 };
531
532 /*
533 ** These are the column/row/line separators used by the various
534 ** import/export modes.
535 */
536 #define SEP_Column "|"
537 #define SEP_Row "\n"
538 #define SEP_Tab "\t"
539 #define SEP_Space " "
540 #define SEP_Comma ","
541 #define SEP_CrLf "\r\n"
542 #define SEP_Unit "\x1F"
543 #define SEP_Record "\x1E"
544
545 /*
546 ** Number of elements in an array
547 */
548 #define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
549
@@ -675,26 +696,26 @@
696 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
697 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
698 };
699
700 /*
701 ** Output a single term of CSV. Actually, p->colSeparator is used for
702 ** the separator, which may or may not be a comma. p->nullValue is
703 ** the null value. Strings are quoted if necessary. The separator
704 ** is only issued if bSep is true.
705 */
706 static void output_csv(ShellState *p, const char *z, int bSep){
707 FILE *out = p->out;
708 if( z==0 ){
709 fprintf(out,"%s",p->nullValue);
710 }else{
711 int i;
712 int nSep = strlen30(p->colSeparator);
713 for(i=0; z[i]; i++){
714 if( needCsvQuote[((unsigned char*)z)[i]]
715 || (z[i]==p->colSeparator[0] &&
716 (nSep==1 || memcmp(z, p->colSeparator, nSep)==0)) ){
717 i = 0;
718 break;
719 }
720 }
721 if( i==0 ){
@@ -707,11 +728,11 @@
728 }else{
729 fprintf(out, "%s", z);
730 }
731 }
732 if( bSep ){
733 fprintf(p->out, "%s", p->colSeparator);
734 }
735 }
736
737 #ifdef SIGINT
738 /*
@@ -745,14 +766,14 @@
766 if( azArg==0 ) break;
767 for(i=0; i<nArg; i++){
768 int len = strlen30(azCol[i] ? azCol[i] : "");
769 if( len>w ) w = len;
770 }
771 if( p->cnt++>0 ) fprintf(p->out, "%s", p->rowSeparator);
772 for(i=0; i<nArg; i++){
773 fprintf(p->out,"%*s = %s%s", w, azCol[i],
774 azArg[i] ? azArg[i] : p->nullValue, p->rowSeparator);
775 }
776 break;
777 }
778 case MODE_Explain:
779 case MODE_Column: {
@@ -765,21 +786,23 @@
786 w = 0;
787 }
788 if( w==0 ){
789 w = strlen30(azCol[i] ? azCol[i] : "");
790 if( w<10 ) w = 10;
791 n = strlen30(azArg && azArg[i] ? azArg[i] : p->nullValue);
792 if( w<n ) w = n;
793 }
794 if( i<ArraySize(p->actualWidth) ){
795 p->actualWidth[i] = w;
796 }
797 if( p->showHeader ){
798 if( w<0 ){
799 fprintf(p->out,"%*.*s%s",-w,-w,azCol[i],
800 i==nArg-1 ? p->rowSeparator : " ");
801 }else{
802 fprintf(p->out,"%-*.*s%s",w,w,azCol[i],
803 i==nArg-1 ? p->rowSeparator : " ");
804 }
805 }
806 }
807 if( p->showHeader ){
808 for(i=0; i<nArg; i++){
@@ -790,11 +813,11 @@
813 }else{
814 w = 10;
815 }
816 fprintf(p->out,"%-*.*s%s",w,w,"-----------------------------------"
817 "----------------------------------------------------------",
818 i==nArg-1 ? p->rowSeparator : " ");
819 }
820 }
821 }
822 if( azArg==0 ) break;
823 for(i=0; i<nArg; i++){
@@ -813,36 +836,39 @@
836 }
837 p->iIndent++;
838 }
839 if( w<0 ){
840 fprintf(p->out,"%*.*s%s",-w,-w,
841 azArg[i] ? azArg[i] : p->nullValue,
842 i==nArg-1 ? p->rowSeparator : " ");
843 }else{
844 fprintf(p->out,"%-*.*s%s",w,w,
845 azArg[i] ? azArg[i] : p->nullValue,
846 i==nArg-1 ? p->rowSeparator : " ");
847 }
848 }
849 break;
850 }
851 case MODE_Semi:
852 case MODE_List: {
853 if( p->cnt++==0 && p->showHeader ){
854 for(i=0; i<nArg; i++){
855 fprintf(p->out,"%s%s",azCol[i],
856 i==nArg-1 ? p->rowSeparator : p->colSeparator);
857 }
858 }
859 if( azArg==0 ) break;
860 for(i=0; i<nArg; i++){
861 char *z = azArg[i];
862 if( z==0 ) z = p->nullValue;
863 fprintf(p->out, "%s", z);
864 if( i<nArg-1 ){
865 fprintf(p->out, "%s", p->colSeparator);
866 }else if( p->mode==MODE_Semi ){
867 fprintf(p->out, ";%s", p->rowSeparator);
868 }else{
869 fprintf(p->out, "%s", p->rowSeparator);
870 }
871 }
872 break;
873 }
874 case MODE_Html: {
@@ -857,30 +883,30 @@
883 }
884 if( azArg==0 ) break;
885 fprintf(p->out,"<TR>");
886 for(i=0; i<nArg; i++){
887 fprintf(p->out,"<TD>");
888 output_html_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
889 fprintf(p->out,"</TD>\n");
890 }
891 fprintf(p->out,"</TR>\n");
892 break;
893 }
894 case MODE_Tcl: {
895 if( p->cnt++==0 && p->showHeader ){
896 for(i=0; i<nArg; i++){
897 output_c_string(p->out,azCol[i] ? azCol[i] : "");
898 if(i<nArg-1) fprintf(p->out, "%s", p->colSeparator);
899 }
900 fprintf(p->out, "%s", p->rowSeparator);
901 }
902 if( azArg==0 ) break;
903 for(i=0; i<nArg; i++){
904 output_c_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
905 if(i<nArg-1) fprintf(p->out, "%s", p->colSeparator);
906 }
907 fprintf(p->out, "%s", p->rowSeparator);
908 break;
909 }
910 case MODE_Csv: {
911 #if defined(WIN32) || defined(_WIN32)
912 fflush(p->out);
@@ -888,17 +914,17 @@
914 #endif
915 if( p->cnt++==0 && p->showHeader ){
916 for(i=0; i<nArg; i++){
917 output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
918 }
919 fprintf(p->out, "%s", p->rowSeparator);
920 }
921 if( nArg>0 ){
922 for(i=0; i<nArg; i++){
923 output_csv(p, azArg[i], i<nArg-1);
924 }
925 fprintf(p->out, "%s", p->rowSeparator);
926 }
927 #if defined(WIN32) || defined(_WIN32)
928 fflush(p->out);
929 _setmode(_fileno(p->out), _O_TEXT);
930 #endif
@@ -930,10 +956,26 @@
956 output_quoted_string(p->out, azArg[i]);
957 }
958 }
959 fprintf(p->out,");\n");
960 break;
961 }
962 case MODE_Ascii: {
963 if( p->cnt++==0 && p->showHeader ){
964 for(i=0; i<nArg; i++){
965 if( i>0 ) fprintf(p->out, "%s", p->colSeparator);
966 fprintf(p->out,"%s",azCol[i] ? azCol[i] : "");
967 }
968 fprintf(p->out, "%s", p->rowSeparator);
969 }
970 if( azArg==0 ) break;
971 for(i=0; i<nArg; i++){
972 if( i>0 ) fprintf(p->out, "%s", p->colSeparator);
973 fprintf(p->out,"%s",azArg[i] ? azArg[i] : p->nullValue);
974 }
975 fprintf(p->out, "%s", p->rowSeparator);
976 break;
977 }
978 }
979 return 0;
980 }
981
@@ -1696,16 +1738,17 @@
1738 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1739 ".load FILE ?ENTRY? Load an extension library\n"
1740 #endif
1741 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
1742 ".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
1743 " ascii Columns/rows delimited by 0x1F and 0x1E\n"
1744 " csv Comma-separated values\n"
1745 " column Left-aligned columns. (See .width)\n"
1746 " html HTML <table> code\n"
1747 " insert SQL insert statements for TABLE\n"
1748 " line One value per line\n"
1749 " list Values delimited by .separator strings\n"
1750 " tabs Tab-separated values\n"
1751 " tcl TCL list elements\n"
1752 ".nullvalue STRING Use STRING in place of NULL values\n"
1753 ".once FILENAME Output for the next SQL command only to FILENAME\n"
1754 ".open ?FILENAME? Close existing database and reopen FILENAME\n"
@@ -1718,12 +1761,12 @@
1761 ".save FILE Write in-memory database into FILE\n"
1762 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
1763 ".schema ?TABLE? Show the CREATE statements\n"
1764 " If TABLE specified, only show tables matching\n"
1765 " LIKE pattern TABLE.\n"
1766 ".separator COL ?ROW? Change the column separator and optionally the row\n"
1767 " separator for both the output mode and .import\n"
1768 ".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
1769 ".show Show the current values for various settings\n"
1770 ".stats on|off Turn stats on or off\n"
1771 ".system CMD ARGS... Run CMD ARGS... in a system shell\n"
1772 ".tables ?TABLE? List names of tables\n"
@@ -2000,26 +2043,27 @@
2043 static int nCall = 0;
2044 nCall++;
2045 }
2046
2047 /*
2048 ** An object used to read a CSV and other files for import.
2049 */
2050 typedef struct ImportCtx ImportCtx;
2051 struct ImportCtx {
2052 const char *zFile; /* Name of the input file */
2053 FILE *in; /* Read the CSV text from this input stream */
2054 char *z; /* Accumulated text for a field */
2055 int n; /* Number of bytes in z */
2056 int nAlloc; /* Space allocated for z[] */
2057 int nLine; /* Current line number */
2058 int cTerm; /* Character that terminated the most recent field */
2059 int cColSep; /* The column separator character. (Usually ",") */
2060 int cRowSep; /* The row separator character. (Usually "\n") */
2061 };
2062
2063 /* Append a single byte to z[] */
2064 static void import_append_char(ImportCtx *p, int c){
2065 if( p->n+1>=p->nAlloc ){
2066 p->nAlloc += p->nAlloc + 100;
2067 p->z = sqlite3_realloc(p->z, p->nAlloc);
2068 if( p->z==0 ){
2069 fprintf(stderr, "out of memory\n");
@@ -2033,41 +2077,44 @@
2077 ** with the option of having a separator other than ",".
2078 **
2079 ** + Input comes from p->in.
2080 ** + Store results in p->z of length p->n. Space to hold p->z comes
2081 ** from sqlite3_malloc().
2082 ** + Use p->cSep as the column separator. The default is ",".
2083 ** + Use p->rSep as the row separator. The default is "\n".
2084 ** + Keep track of the line number in p->nLine.
2085 ** + Store the character that terminates the field in p->cTerm. Store
2086 ** EOF on end-of-file.
2087 ** + Report syntax errors on stderr
2088 */
2089 static char *csv_read_one_field(ImportCtx *p){
2090 int c;
2091 int cSep = p->cColSep;
2092 int rSep = p->cRowSep;
2093 p->n = 0;
2094 c = fgetc(p->in);
2095 if( c==EOF || seenInterrupt ){
2096 p->cTerm = EOF;
2097 return 0;
2098 }
2099 if( c=='"' ){
2100 int pc, ppc;
2101 int startLine = p->nLine;
2102 int cQuote = c;
2103 pc = ppc = 0;
2104 while( 1 ){
2105 c = fgetc(p->in);
2106 if( c==rSep ) p->nLine++;
2107 if( c==cQuote ){
2108 if( pc==cQuote ){
2109 pc = 0;
2110 continue;
2111 }
2112 }
2113 if( (c==cSep && pc==cQuote)
2114 || (c==rSep && pc==cQuote)
2115 || (c==rSep && pc=='\r' && ppc==cQuote)
2116 || (c==EOF && pc==cQuote)
2117 ){
2118 do{ p->n--; }while( p->z[p->n]!=cQuote );
2119 p->cTerm = c;
2120 break;
@@ -2077,31 +2124,65 @@
2124 p->zFile, p->nLine, cQuote);
2125 }
2126 if( c==EOF ){
2127 fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
2128 p->zFile, startLine, cQuote);
2129 p->cTerm = c;
2130 break;
2131 }
2132 import_append_char(p, c);
2133 ppc = pc;
2134 pc = c;
2135 }
2136 }else{
2137 while( c!=EOF && c!=cSep && c!=rSep ){
2138 import_append_char(p, c);
2139 c = fgetc(p->in);
2140 }
2141 if( c==rSep ){
2142 p->nLine++;
2143 if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--;
2144 }
2145 p->cTerm = c;
2146 }
2147 if( p->z ) p->z[p->n] = 0;
2148 return p->z;
2149 }
2150
2151 /* Read a single field of ASCII delimited text.
2152 **
2153 ** + Input comes from p->in.
2154 ** + Store results in p->z of length p->n. Space to hold p->z comes
2155 ** from sqlite3_malloc().
2156 ** + Use p->cSep as the column separator. The default is "\x1F".
2157 ** + Use p->rSep as the row separator. The default is "\x1E".
2158 ** + Keep track of the row number in p->nLine.
2159 ** + Store the character that terminates the field in p->cTerm. Store
2160 ** EOF on end-of-file.
2161 ** + Report syntax errors on stderr
2162 */
2163 static char *ascii_read_one_field(ImportCtx *p){
2164 int c;
2165 int cSep = p->cColSep;
2166 int rSep = p->cRowSep;
2167 p->n = 0;
2168 c = fgetc(p->in);
2169 if( c==EOF || seenInterrupt ){
2170 p->cTerm = EOF;
2171 return 0;
2172 }
2173 while( c!=EOF && c!=cSep && c!=rSep ){
2174 import_append_char(p, c);
2175 c = fgetc(p->in);
2176 }
2177 if( c==rSep ){
2178 p->nLine++;
2179 }
2180 p->cTerm = c;
2181 if( p->z ) p->z[p->n] = 0;
2182 return p->z;
2183 }
2184
2185 /*
2186 ** Try to transfer data for table zTable. If an error is seen while
2187 ** moving forward, try to go backwards. The backwards movement won't
2188 ** work for WITHOUT ROWID tables.
@@ -2653,100 +2734,125 @@
2734 sqlite3_stmt *pStmt = NULL; /* A statement */
2735 int nCol; /* Number of columns in the table */
2736 int nByte; /* Number of bytes in an SQL string */
2737 int i, j; /* Loop counters */
2738 int needCommit; /* True to COMMIT or ROLLBACK at end */
2739 int nSep; /* Number of bytes in p->colSeparator[] */
2740 char *zSql; /* An SQL statement */
2741 ImportCtx sCtx; /* Reader context */
2742 char *(*xRead)(ImportCtx*); /* Procedure to read one value */
2743 int (*xCloser)(FILE*); /* Procedure to close th3 connection */
2744
2745 if( nArg!=3 ){
2746 fprintf(stderr, "Usage: .import FILE TABLE\n");
2747 goto meta_command_exit;
2748 }
2749 zFile = azArg[1];
2750 zTable = azArg[2];
2751 seenInterrupt = 0;
2752 memset(&sCtx, 0, sizeof(sCtx));
2753 open_db(p, 0);
2754 nSep = strlen30(p->colSeparator);
2755 if( nSep==0 ){
2756 fprintf(stderr, "Error: non-null column separator required for import\n");
2757 return 1;
2758 }
2759 if( nSep>1 ){
2760 fprintf(stderr, "Error: multi-character column separators not allowed"
2761 " for import\n");
2762 return 1;
2763 }
2764 nSep = strlen30(p->rowSeparator);
2765 if( nSep==0 ){
2766 fprintf(stderr, "Error: non-null row separator required for import\n");
2767 return 1;
2768 }
2769 if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator, SEP_CrLf)==0 ){
2770 /* When importing CSV (only), if the row separator is set to the
2771 ** default output row separator, change it to the default input
2772 ** row separator. This avoids having to maintain different input
2773 ** and output row separators. */
2774 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
2775 nSep = strlen30(p->rowSeparator);
2776 }
2777 if( nSep>1 ){
2778 fprintf(stderr, "Error: multi-character row separators not allowed"
2779 " for import\n");
2780 return 1;
2781 }
2782 sCtx.zFile = zFile;
2783 sCtx.nLine = 1;
2784 if( sCtx.zFile[0]=='|' ){
2785 sCtx.in = popen(sCtx.zFile+1, "r");
2786 sCtx.zFile = "<pipe>";
2787 xCloser = pclose;
2788 }else{
2789 sCtx.in = fopen(sCtx.zFile, "rb");
2790 xCloser = fclose;
2791 }
2792 if( p->mode==MODE_Ascii ){
2793 xRead = ascii_read_one_field;
2794 }else{
2795 xRead = csv_read_one_field;
2796 }
2797 if( sCtx.in==0 ){
2798 fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
2799 return 1;
2800 }
2801 sCtx.cColSep = p->colSeparator[0];
2802 sCtx.cRowSep = p->rowSeparator[0];
2803 zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
2804 if( zSql==0 ){
2805 fprintf(stderr, "Error: out of memory\n");
2806 xCloser(sCtx.in);
2807 return 1;
2808 }
2809 nByte = strlen30(zSql);
2810 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2811 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
2812 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
2813 char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
2814 char cSep = '(';
2815 while( xRead(&sCtx) ){
2816 zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCtx.z);
2817 cSep = ',';
2818 if( sCtx.cTerm!=sCtx.cColSep ) break;
2819 }
2820 if( cSep=='(' ){
2821 sqlite3_free(zCreate);
2822 sqlite3_free(sCtx.z);
2823 xCloser(sCtx.in);
2824 fprintf(stderr,"%s: empty file\n", sCtx.zFile);
2825 return 1;
2826 }
2827 zCreate = sqlite3_mprintf("%z\n)", zCreate);
2828 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
2829 sqlite3_free(zCreate);
2830 if( rc ){
2831 fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
2832 sqlite3_errmsg(db));
2833 sqlite3_free(sCtx.z);
2834 xCloser(sCtx.in);
2835 return 1;
2836 }
2837 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2838 }
2839 sqlite3_free(zSql);
2840 if( rc ){
2841 if (pStmt) sqlite3_finalize(pStmt);
2842 fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
2843 xCloser(sCtx.in);
2844 return 1;
2845 }
2846 nCol = sqlite3_column_count(pStmt);
2847 sqlite3_finalize(pStmt);
2848 pStmt = 0;
2849 if( nCol==0 ) return 0; /* no columns, no error */
2850 zSql = sqlite3_malloc( nByte*2 + 20 + nCol*2 );
2851 if( zSql==0 ){
2852 fprintf(stderr, "Error: out of memory\n");
2853 xCloser(sCtx.in);
2854 return 1;
2855 }
2856 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
2857 j = strlen30(zSql);
2858 for(i=1; i<nCol; i++){
@@ -2758,50 +2864,60 @@
2864 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2865 sqlite3_free(zSql);
2866 if( rc ){
2867 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
2868 if (pStmt) sqlite3_finalize(pStmt);
2869 xCloser(sCtx.in);
2870 return 1;
2871 }
2872 needCommit = sqlite3_get_autocommit(db);
2873 if( needCommit ) sqlite3_exec(db, "BEGIN", 0, 0, 0);
2874 do{
2875 int startLine = sCtx.nLine;
2876 for(i=0; i<nCol; i++){
2877 char *z = xRead(&sCtx);
2878 /*
2879 ** Did we reach end-of-file before finding any columns?
2880 ** If so, stop instead of NULL filling the remaining columns.
2881 */
2882 if( z==0 && i==0 ) break;
2883 /*
2884 ** Did we reach end-of-file OR end-of-line before finding any
2885 ** columns in ASCII mode? If so, stop instead of NULL filling
2886 ** the remaining columns.
2887 */
2888 if( p->mode==MODE_Ascii && (z==0 || z[0]==0) && i==0 ) break;
2889 sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
2890 if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
2891 fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2892 "filling the rest with NULL\n",
2893 sCtx.zFile, startLine, nCol, i+1);
2894 i++;
2895 while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
2896 }
2897 }
2898 if( sCtx.cTerm==sCtx.cColSep ){
2899 do{
2900 xRead(&sCtx);
2901 i++;
2902 }while( sCtx.cTerm==sCtx.cColSep );
2903 fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2904 "extras ignored\n",
2905 sCtx.zFile, startLine, nCol, i);
2906 }
2907 if( i>=nCol ){
2908 sqlite3_step(pStmt);
2909 rc = sqlite3_reset(pStmt);
2910 if( rc!=SQLITE_OK ){
2911 fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile, startLine,
2912 sqlite3_errmsg(db));
2913 }
2914 }
2915 }while( sCtx.cTerm!=EOF );
2916
2917 xCloser(sCtx.in);
2918 sqlite3_free(sCtx.z);
2919 sqlite3_finalize(pStmt);
2920 if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
2921 }else
2922
2923 if( c=='i' && strncmp(azArg[0], "indices", n)==0 ){
@@ -2915,32 +3031,36 @@
3031 p->mode = MODE_List;
3032 }else if( c2=='h' && strncmp(azArg[1],"html",n2)==0 ){
3033 p->mode = MODE_Html;
3034 }else if( c2=='t' && strncmp(azArg[1],"tcl",n2)==0 ){
3035 p->mode = MODE_Tcl;
3036 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Space);
3037 }else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
3038 p->mode = MODE_Csv;
3039 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
3040 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
3041 }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
3042 p->mode = MODE_List;
3043 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Tab);
3044 }else if( c2=='i' && strncmp(azArg[1],"insert",n2)==0 ){
3045 p->mode = MODE_Insert;
3046 set_table_name(p, nArg>=3 ? azArg[2] : "table");
3047 }else if( c2=='a' && strncmp(azArg[1],"ascii",n2)==0 ){
3048 p->mode = MODE_Ascii;
3049 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
3050 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
3051 }else {
3052 fprintf(stderr,"Error: mode should be one of: "
3053 "ascii column csv html insert line list tabs tcl\n");
3054 rc = 1;
3055 }
3056 }else
3057
3058 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
3059 if( nArg==2 ){
3060 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
3061 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
3062 }else{
3063 fprintf(stderr, "Usage: .nullvalue STRING\n");
3064 rc = 1;
3065 }
3066 }else
@@ -3221,18 +3341,20 @@
3341 }else
3342 #endif
3343
3344 if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
3345 if( nArg<2 || nArg>3 ){
3346 fprintf(stderr, "Usage: .separator COL ?ROW?\n");
3347 rc = 1;
3348 }
3349 if( nArg>=2 ){
3350 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator,
3351 "%.*s", (int)ArraySize(p->colSeparator)-1, azArg[1]);
3352 }
3353 if( nArg>=3 ){
3354 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator,
3355 "%.*s", (int)ArraySize(p->rowSeparator)-1, azArg[2]);
3356 }
3357 }else
3358
3359 if( c=='s'
3360 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
@@ -3259,27 +3381,28 @@
3381 if( nArg!=1 ){
3382 fprintf(stderr, "Usage: .show\n");
3383 rc = 1;
3384 goto meta_command_exit;
3385 }
3386 fprintf(p->out,"%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
3387 fprintf(p->out,"%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
3388 fprintf(p->out,"%9.9s: %s\n","explain", p->normalMode.valid ? "on" :"off");
3389 fprintf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
3390 fprintf(p->out,"%12.12s: %s\n","mode", modeDescr[p->mode]);
3391 fprintf(p->out,"%12.12s: ", "nullvalue");
3392 output_c_string(p->out, p->nullValue);
3393 fprintf(p->out, "\n");
3394 fprintf(p->out,"%12.12s: %s\n","output",
3395 strlen30(p->outfile) ? p->outfile : "stdout");
3396 fprintf(p->out,"%12.12s: ", "colseparator");
3397 output_c_string(p->out, p->colSeparator);
3398 fprintf(p->out, "\n");
3399 fprintf(p->out,"%12.12s: ", "rowseparator");
3400 output_c_string(p->out, p->rowSeparator);
3401 fprintf(p->out, "\n");
3402 fprintf(p->out,"%12.12s: %s\n","stats", p->statsOn ? "on" : "off");
3403 fprintf(p->out,"%12.12s: ","width");
3404 for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
3405 fprintf(p->out,"%d ",p->colWidth[i]);
3406 }
3407 fprintf(p->out,"\n");
3408 }else
@@ -3936,10 +4059,11 @@
4059
4060 /*
4061 ** Show available command line options
4062 */
4063 static const char zOptions[] =
4064 " -ascii set output mode to 'ascii'\n"
4065 " -bail stop after hitting an error\n"
4066 " -batch force batch I/O\n"
4067 " -column set output mode to 'column'\n"
4068 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
4069 " -csv set output mode to 'csv'\n"
@@ -3957,15 +4081,15 @@
4081 " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
4082 " -mmap N default mmap size set to N\n"
4083 #ifdef SQLITE_ENABLE_MULTIPLEX
4084 " -multiplex enable the multiplexor VFS\n"
4085 #endif
4086 " -newline SEP set output row separator. Default: '\\n'\n"
4087 " -nullvalue TEXT set text string for NULL values. Default ''\n"
4088 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
4089 " -scratch SIZE N use N slots of SZ bytes each for scratch memory\n"
4090 " -separator SEP set output column separator. Default: '|'\n"
4091 " -stats print memory stats before each finalize\n"
4092 " -version show SQLite version\n"
4093 " -vfs NAME use NAME as the default VFS\n"
4094 #ifdef SQLITE_ENABLE_VFSTRACE
4095 " -vfstrace enable tracing of all VFS calls\n"
@@ -3988,12 +4112,12 @@
4112 ** Initialize the state information in data
4113 */
4114 static void main_init(ShellState *data) {
4115 memset(data, 0, sizeof(*data));
4116 data->mode = MODE_List;
4117 memcpy(data->colSeparator,SEP_Column, 2);
4118 memcpy(data->rowSeparator,SEP_Row, 2);
4119 data->showHeader = 0;
4120 data->shellFlgs = SHFLG_Lookaside;
4121 sqlite3_config(SQLITE_CONFIG_URI, 1);
4122 sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
4123 sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
@@ -4228,19 +4352,25 @@
4352 data.mode = MODE_Line;
4353 }else if( strcmp(z,"-column")==0 ){
4354 data.mode = MODE_Column;
4355 }else if( strcmp(z,"-csv")==0 ){
4356 data.mode = MODE_Csv;
4357 memcpy(data.colSeparator,",",2);
4358 }else if( strcmp(z,"-ascii")==0 ){
4359 data.mode = MODE_Ascii;
4360 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
4361 SEP_Unit);
4362 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
4363 SEP_Record);
4364 }else if( strcmp(z,"-separator")==0 ){
4365 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
4366 "%s",cmdline_option_value(argc,argv,++i));
4367 }else if( strcmp(z,"-newline")==0 ){
4368 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
4369 "%s",cmdline_option_value(argc,argv,++i));
4370 }else if( strcmp(z,"-nullvalue")==0 ){
4371 sqlite3_snprintf(sizeof(data.nullValue), data.nullValue,
4372 "%s",cmdline_option_value(argc,argv,++i));
4373 }else if( strcmp(z,"-header")==0 ){
4374 data.showHeader = 1;
4375 }else if( strcmp(z,"-noheader")==0 ){
4376 data.showHeader = 0;
@@ -4356,11 +4486,11 @@
4486 nHistory = strlen30(zHome) + 20;
4487 if( (zHistory = malloc(nHistory))!=0 ){
4488 sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
4489 }
4490 }
4491 #if HAVE_READLINE
4492 if( zHistory ) read_history(zHistory);
4493 #endif
4494 rc = process_input(&data, 0);
4495 if( zHistory ){
4496 stifle_history(100);
4497
+605 -409
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -41,10 +41,57 @@
4141
**
4242
*/
4343
#ifndef _SQLITEINT_H_
4444
#define _SQLITEINT_H_
4545
46
+/*
47
+** Include the header file used to customize the compiler options for MSVC.
48
+** This should be done first so that it can successfully prevent spurious
49
+** compiler warnings due to subsequent content in this file and other files
50
+** that are included by this file.
51
+*/
52
+/************** Include msvc.h in the middle of sqliteInt.h ******************/
53
+/************** Begin file msvc.h ********************************************/
54
+/*
55
+** 2015 January 12
56
+**
57
+** The author disclaims copyright to this source code. In place of
58
+** a legal notice, here is a blessing:
59
+**
60
+** May you do good and not evil.
61
+** May you find forgiveness for yourself and forgive others.
62
+** May you share freely, never taking more than you give.
63
+**
64
+******************************************************************************
65
+**
66
+** This file contains code that is specific to MSVC.
67
+*/
68
+#ifndef _MSVC_H_
69
+#define _MSVC_H_
70
+
71
+#if defined(_MSC_VER)
72
+#pragma warning(disable : 4054)
73
+#pragma warning(disable : 4055)
74
+#pragma warning(disable : 4100)
75
+#pragma warning(disable : 4127)
76
+#pragma warning(disable : 4152)
77
+#pragma warning(disable : 4189)
78
+#pragma warning(disable : 4206)
79
+#pragma warning(disable : 4210)
80
+#pragma warning(disable : 4232)
81
+#pragma warning(disable : 4244)
82
+#pragma warning(disable : 4305)
83
+#pragma warning(disable : 4306)
84
+#pragma warning(disable : 4702)
85
+#pragma warning(disable : 4706)
86
+#endif /* defined(_MSC_VER) */
87
+
88
+#endif /* _MSVC_H_ */
89
+
90
+/************** End of msvc.h ************************************************/
91
+/************** Continuing where we left off in sqliteInt.h ******************/
92
+
4693
/*
4794
** These #defines should enable >2GB file support on POSIX if the
4895
** underlying operating system supports it. If the OS lacks
4996
** large file support, or if the OS is windows, these should be no-ops.
5097
**
@@ -231,11 +278,11 @@
231278
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232279
** [sqlite_version()] and [sqlite_source_id()].
233280
*/
234281
#define SQLITE_VERSION "3.8.8"
235282
#define SQLITE_VERSION_NUMBER 3008008
236
-#define SQLITE_SOURCE_ID "2014-12-10 04:58:43 3528f8dd39acace8eeb7337994c8617313f4b04b"
283
+#define SQLITE_SOURCE_ID "2015-01-12 21:43:00 e693e11d1b9265974c32bddba873ea30a4d0b708"
237284
238285
/*
239286
** CAPI3REF: Run-Time Library Version Numbers
240287
** KEYWORDS: sqlite3_version, sqlite3_sourceid
241288
**
@@ -323,11 +370,11 @@
323370
** This interface only reports on the compile-time mutex setting
324371
** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
325372
** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
326373
** can be fully or partially disabled using a call to [sqlite3_config()]
327374
** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
328
-** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the
375
+** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
329376
** sqlite3_threadsafe() function shows only the compile-time setting of
330377
** thread safety, not any run-time changes to that setting made by
331378
** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
332379
** is unchanged by calls to sqlite3_config().)^
333380
**
@@ -1692,11 +1739,11 @@
16921739
** configuration option.
16931740
** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
16941741
** 8-byte aligned
16951742
** memory, the size of each page buffer (sz), and the number of pages (N).
16961743
** The sz argument should be the size of the largest database page
1697
-** (a power of two between 512 and 32768) plus some extra bytes for each
1744
+** (a power of two between 512 and 65536) plus some extra bytes for each
16981745
** page header. ^The number of extra bytes needed by the page header
16991746
** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
17001747
** to [sqlite3_config()].
17011748
** ^It is harmless, apart from the wasted memory,
17021749
** for the sz parameter to be larger than necessary. The first
@@ -1872,10 +1919,21 @@
18721919
** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
18731920
** is a pointer to an integer and writes into that integer the number of extra
18741921
** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
18751922
** The amount of extra space required can change depending on the compiler,
18761923
** target platform, and SQLite version.
1924
+**
1925
+** [[SQLITE_CONFIG_PMASZ]]
1926
+** <dt>SQLITE_CONFIG_PMASZ
1927
+** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
1928
+** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
1929
+** sorter to that integer. The default minimum PMA Size is set by the
1930
+** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
1931
+** to help with sort operations when multithreaded sorting
1932
+** is enabled (using the [PRAGMA threads] command) and the amount of content
1933
+** to be sorted exceeds the page size times the minimum of the
1934
+** [PRAGMA cache_size] setting and this value.
18771935
** </dl>
18781936
*/
18791937
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
18801938
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
18811939
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1898,10 +1956,11 @@
18981956
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
18991957
#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
19001958
#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
19011959
#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
19021960
#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
1961
+#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
19031962
19041963
/*
19051964
** CAPI3REF: Database Connection Configuration Options
19061965
**
19071966
** These constants are the available integer configuration options that
@@ -7307,16 +7366,14 @@
73077366
73087367
/*
73097368
** CAPI3REF: Write-Ahead Log Commit Hook
73107369
**
73117370
** ^The [sqlite3_wal_hook()] function is used to register a callback that
7312
-** will be invoked each time a database connection commits data to a
7313
-** [write-ahead log] (i.e. whenever a transaction is committed in
7314
-** [journal_mode | journal_mode=WAL mode]).
7371
+** is invoked each time data is committed to a database in wal mode.
73157372
**
7316
-** ^The callback is invoked by SQLite after the commit has taken place and
7317
-** the associated write-lock on the database released, so the implementation
7373
+** ^(The callback is invoked by SQLite after the commit has taken place and
7374
+** the associated write-lock on the database released)^, so the implementation
73187375
** may read, write or [checkpoint] the database as required.
73197376
**
73207377
** ^The first parameter passed to the callback function when it is invoked
73217378
** is a copy of the third parameter passed to sqlite3_wal_hook() when
73227379
** registering the callback. ^The second is a copy of the database handle.
@@ -7603,10 +7660,14 @@
76037660
**
76047661
** The following constants can be used for the T parameter to the
76057662
** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
76067663
** different metric for sqlite3_stmt_scanstatus() to return.
76077664
**
7665
+** When the value returned to V is a string, space to hold that string is
7666
+** managed by the prepared statement S and will be automatically freed when
7667
+** S is finalized.
7668
+**
76087669
** <dl>
76097670
** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
76107671
** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
76117672
** set to the total number of times that the X-th loop has run.</dd>
76127673
**
@@ -7648,11 +7709,18 @@
76487709
#define SQLITE_SCANSTAT_SELECTID 5
76497710
76507711
/*
76517712
** CAPI3REF: Prepared Statement Scan Status
76527713
**
7653
-** Return status data for a single loop within query pStmt.
7714
+** This interface returns information about the predicted and measured
7715
+** performance for pStmt. Advanced applications can use this
7716
+** interface to compare the predicted and the measured performance and
7717
+** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
7718
+**
7719
+** Since this interface is expected to be rarely used, it is only
7720
+** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
7721
+** compile-time option.
76547722
**
76557723
** The "iScanStatusOp" parameter determines which status information to return.
76567724
** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
76577725
** of this interface is undefined.
76587726
** ^The requested measurement is written into a variable pointed to by
@@ -7666,13 +7734,10 @@
76667734
** ^Statistics might not be available for all loops in all statements. ^In cases
76677735
** where there exist loops with no available statistics, this function behaves
76687736
** as if the loop did not exist - it returns non-zero and leave the variable
76697737
** that pOut points to unchanged.
76707738
**
7671
-** This API is only available if the library is built with pre-processor
7672
-** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7673
-**
76747739
** See also: [sqlite3_stmt_scanstatus_reset()]
76757740
*/
76767741
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
76777742
sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
76787743
int idx, /* Index of loop to report on */
@@ -9100,11 +9165,11 @@
91009165
#define _BTREE_H_
91019166
91029167
/* TODO: This definition is just included so other modules compile. It
91039168
** needs to be revisited.
91049169
*/
9105
-#define SQLITE_N_BTREE_META 10
9170
+#define SQLITE_N_BTREE_META 16
91069171
91079172
/*
91089173
** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
91099174
** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
91109175
*/
@@ -9215,10 +9280,15 @@
92159280
** offset = 36 + (idx * 4)
92169281
**
92179282
** For example, the free-page-count field is located at byte offset 36 of
92189283
** the database file header. The incr-vacuum-flag field is located at
92199284
** byte offset 64 (== 36+4*7).
9285
+**
9286
+** The BTREE_DATA_VERSION value is not really a value stored in the header.
9287
+** It is a read-only number computed by the pager. But we merge it with
9288
+** the header value access routines since its access pattern is the same.
9289
+** Call it a "virtual meta value".
92209290
*/
92219291
#define BTREE_FREE_PAGE_COUNT 0
92229292
#define BTREE_SCHEMA_VERSION 1
92239293
#define BTREE_FILE_FORMAT 2
92249294
#define BTREE_DEFAULT_CACHE_SIZE 3
@@ -9225,10 +9295,11 @@
92259295
#define BTREE_LARGEST_ROOT_PAGE 4
92269296
#define BTREE_TEXT_ENCODING 5
92279297
#define BTREE_USER_VERSION 6
92289298
#define BTREE_INCR_VACUUM 7
92299299
#define BTREE_APPLICATION_ID 8
9300
+#define BTREE_DATA_VERSION 15 /* A virtual meta-value */
92309301
92319302
/*
92329303
** Values that may be OR'd together to form the second argument of an
92339304
** sqlite3BtreeCursorHints() call.
92349305
*/
@@ -10006,10 +10077,11 @@
1000610077
SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager);
1000710078
#endif
1000810079
1000910080
/* Functions used to query pager state and configuration. */
1001010081
SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
10082
+SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*);
1001110083
SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
1001210084
SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
1001310085
SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int);
1001410086
SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
1001510087
SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
@@ -10747,10 +10819,11 @@
1074710819
i64 szMmap; /* Default mmap_size setting */
1074810820
unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
1074910821
int errCode; /* Most recent error code (SQLITE_*) */
1075010822
int errMask; /* & result codes with this before returning */
1075110823
u16 dbOptFlags; /* Flags to enable/disable optimizations */
10824
+ u8 enc; /* Text encoding */
1075210825
u8 autoCommit; /* The auto-commit flag. */
1075310826
u8 temp_store; /* 1: file 2: memory 0: default */
1075410827
u8 mallocFailed; /* True if we have seen a malloc failure */
1075510828
u8 dfltLockMode; /* Default locking-mode for attached dbs */
1075610829
signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
@@ -10848,11 +10921,12 @@
1084810921
};
1084910922
1085010923
/*
1085110924
** A macro to discover the encoding of a database.
1085210925
*/
10853
-#define ENC(db) ((db)->aDb[0].pSchema->enc)
10926
+#define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
10927
+#define ENC(db) ((db)->enc)
1085410928
1085510929
/*
1085610930
** Possible values for the sqlite3.flags.
1085710931
*/
1085810932
#define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
@@ -11472,11 +11546,10 @@
1147211546
Index *pNext; /* The next index associated with the same table */
1147311547
Schema *pSchema; /* Schema containing this index */
1147411548
u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
1147511549
char **azColl; /* Array of collation sequence names for index */
1147611550
Expr *pPartIdxWhere; /* WHERE clause for partial indices */
11477
- KeyInfo *pKeyInfo; /* A KeyInfo object suitable for this index */
1147811551
int tnum; /* DB Page containing root of this index */
1147911552
LogEst szIdxRow; /* Estimated average row size in bytes */
1148011553
u16 nKeyCol; /* Number of columns forming the key */
1148111554
u16 nColumn; /* Number of columns stored in the index */
1148211555
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
@@ -12036,11 +12109,11 @@
1203612109
#define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
1203712110
#define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
1203812111
#define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
1203912112
#define SF_Compound 0x0040 /* Part of a compound query */
1204012113
#define SF_Values 0x0080 /* Synthesized from VALUES clause */
12041
- /* 0x0100 NOT USED */
12114
+#define SF_AllValues 0x0100 /* All terms of compound are VALUES */
1204212115
#define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
1204312116
#define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
1204412117
#define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
1204512118
#define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
1204612119
@@ -12526,10 +12599,11 @@
1252612599
void *pPage; /* Page cache memory */
1252712600
int szPage; /* Size of each page in pPage[] */
1252812601
int nPage; /* Number of pages in pPage[] */
1252912602
int mxParserStack; /* maximum depth of the parser stack */
1253012603
int sharedCacheEnabled; /* true if shared-cache mode enabled */
12604
+ u32 szPma; /* Maximum Sorter PMA size */
1253112605
/* The above might be initialized to non-zero. The following need to always
1253212606
** initially be zero, however. */
1253312607
int isInit; /* True after initialization has finished */
1253412608
int inProgress; /* True while initialization in progress */
1253512609
int isMutexInit; /* True after mutexes are initialized */
@@ -12663,11 +12737,11 @@
1266312737
** FTS4 is really an extension for FTS3. It is enabled using the
1266412738
** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call
1266512739
** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3.
1266612740
*/
1266712741
#if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3)
12668
-# define SQLITE_ENABLE_FTS3
12742
+# define SQLITE_ENABLE_FTS3 1
1266912743
#endif
1267012744
1267112745
/*
1267212746
** The ctype.h header is needed for non-ASCII systems. It is also
1267312747
** needed by FTS3 when FTS3 is included in the amalgamation.
@@ -13448,11 +13522,11 @@
1344813522
** print I/O tracing messages.
1344913523
*/
1345013524
#ifdef SQLITE_ENABLE_IOTRACE
1345113525
# define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; }
1345213526
SQLITE_PRIVATE void sqlite3VdbeIOTraceSql(Vdbe*);
13453
-SQLITE_PRIVATE void (*sqlite3IoTrace)(const char*,...);
13527
+void (*sqlite3IoTrace)(const char*,...);
1345413528
#else
1345513529
# define IOTRACE(A)
1345613530
# define sqlite3VdbeIOTraceSql(X)
1345713531
#endif
1345813532
@@ -13661,10 +13735,17 @@
1366113735
*/
1366213736
#ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
1366313737
# define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
1366413738
#endif
1366513739
13740
+/* The minimum PMA size is set to this value multiplied by the database
13741
+** page size in bytes.
13742
+*/
13743
+#ifndef SQLITE_SORTER_PMASZ
13744
+# define SQLITE_SORTER_PMASZ 250
13745
+#endif
13746
+
1366613747
/*
1366713748
** The following singleton contains the global configuration for
1366813749
** the SQLite library.
1366913750
*/
1367013751
SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
@@ -13691,10 +13772,11 @@
1369113772
(void*)0, /* pPage */
1369213773
0, /* szPage */
1369313774
0, /* nPage */
1369413775
0, /* mxParserStack */
1369513776
0, /* sharedCacheEnabled */
13777
+ SQLITE_SORTER_PMASZ, /* szPma */
1369613778
/* All the rest should always be initialized to zero */
1369713779
0, /* isInit */
1369813780
0, /* inProgress */
1369913781
0, /* isMutexInit */
1370013782
0, /* isMallocInit */
@@ -13797,355 +13879,355 @@
1379713879
/* These macros are provided to "stringify" the value of the define
1379813880
** for those options in which the value is meaningful. */
1379913881
#define CTIMEOPT_VAL_(opt) #opt
1380013882
#define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt)
1380113883
13802
-#ifdef SQLITE_32BIT_ROWID
13884
+#if SQLITE_32BIT_ROWID
1380313885
"32BIT_ROWID",
1380413886
#endif
13805
-#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
13887
+#if SQLITE_4_BYTE_ALIGNED_MALLOC
1380613888
"4_BYTE_ALIGNED_MALLOC",
1380713889
#endif
13808
-#ifdef SQLITE_CASE_SENSITIVE_LIKE
13890
+#if SQLITE_CASE_SENSITIVE_LIKE
1380913891
"CASE_SENSITIVE_LIKE",
1381013892
#endif
13811
-#ifdef SQLITE_CHECK_PAGES
13893
+#if SQLITE_CHECK_PAGES
1381213894
"CHECK_PAGES",
1381313895
#endif
13814
-#ifdef SQLITE_COVERAGE_TEST
13896
+#if SQLITE_COVERAGE_TEST
1381513897
"COVERAGE_TEST",
1381613898
#endif
13817
-#ifdef SQLITE_DEBUG
13899
+#if SQLITE_DEBUG
1381813900
"DEBUG",
1381913901
#endif
13820
-#ifdef SQLITE_DEFAULT_LOCKING_MODE
13902
+#if SQLITE_DEFAULT_LOCKING_MODE
1382113903
"DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
1382213904
#endif
1382313905
#if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc)
1382413906
"DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
1382513907
#endif
13826
-#ifdef SQLITE_DISABLE_DIRSYNC
13908
+#if SQLITE_DISABLE_DIRSYNC
1382713909
"DISABLE_DIRSYNC",
1382813910
#endif
13829
-#ifdef SQLITE_DISABLE_LFS
13911
+#if SQLITE_DISABLE_LFS
1383013912
"DISABLE_LFS",
1383113913
#endif
13832
-#ifdef SQLITE_ENABLE_API_ARMOR
13914
+#if SQLITE_ENABLE_API_ARMOR
1383313915
"ENABLE_API_ARMOR",
1383413916
#endif
13835
-#ifdef SQLITE_ENABLE_ATOMIC_WRITE
13917
+#if SQLITE_ENABLE_ATOMIC_WRITE
1383613918
"ENABLE_ATOMIC_WRITE",
1383713919
#endif
13838
-#ifdef SQLITE_ENABLE_CEROD
13920
+#if SQLITE_ENABLE_CEROD
1383913921
"ENABLE_CEROD",
1384013922
#endif
13841
-#ifdef SQLITE_ENABLE_COLUMN_METADATA
13923
+#if SQLITE_ENABLE_COLUMN_METADATA
1384213924
"ENABLE_COLUMN_METADATA",
1384313925
#endif
13844
-#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
13926
+#if SQLITE_ENABLE_EXPENSIVE_ASSERT
1384513927
"ENABLE_EXPENSIVE_ASSERT",
1384613928
#endif
13847
-#ifdef SQLITE_ENABLE_FTS1
13929
+#if SQLITE_ENABLE_FTS1
1384813930
"ENABLE_FTS1",
1384913931
#endif
13850
-#ifdef SQLITE_ENABLE_FTS2
13932
+#if SQLITE_ENABLE_FTS2
1385113933
"ENABLE_FTS2",
1385213934
#endif
13853
-#ifdef SQLITE_ENABLE_FTS3
13935
+#if SQLITE_ENABLE_FTS3
1385413936
"ENABLE_FTS3",
1385513937
#endif
13856
-#ifdef SQLITE_ENABLE_FTS3_PARENTHESIS
13938
+#if SQLITE_ENABLE_FTS3_PARENTHESIS
1385713939
"ENABLE_FTS3_PARENTHESIS",
1385813940
#endif
13859
-#ifdef SQLITE_ENABLE_FTS4
13941
+#if SQLITE_ENABLE_FTS4
1386013942
"ENABLE_FTS4",
1386113943
#endif
13862
-#ifdef SQLITE_ENABLE_ICU
13944
+#if SQLITE_ENABLE_ICU
1386313945
"ENABLE_ICU",
1386413946
#endif
13865
-#ifdef SQLITE_ENABLE_IOTRACE
13947
+#if SQLITE_ENABLE_IOTRACE
1386613948
"ENABLE_IOTRACE",
1386713949
#endif
13868
-#ifdef SQLITE_ENABLE_LOAD_EXTENSION
13950
+#if SQLITE_ENABLE_LOAD_EXTENSION
1386913951
"ENABLE_LOAD_EXTENSION",
1387013952
#endif
13871
-#ifdef SQLITE_ENABLE_LOCKING_STYLE
13953
+#if SQLITE_ENABLE_LOCKING_STYLE
1387213954
"ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE),
1387313955
#endif
13874
-#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
13956
+#if SQLITE_ENABLE_MEMORY_MANAGEMENT
1387513957
"ENABLE_MEMORY_MANAGEMENT",
1387613958
#endif
13877
-#ifdef SQLITE_ENABLE_MEMSYS3
13959
+#if SQLITE_ENABLE_MEMSYS3
1387813960
"ENABLE_MEMSYS3",
1387913961
#endif
13880
-#ifdef SQLITE_ENABLE_MEMSYS5
13962
+#if SQLITE_ENABLE_MEMSYS5
1388113963
"ENABLE_MEMSYS5",
1388213964
#endif
13883
-#ifdef SQLITE_ENABLE_OVERSIZE_CELL_CHECK
13965
+#if SQLITE_ENABLE_OVERSIZE_CELL_CHECK
1388413966
"ENABLE_OVERSIZE_CELL_CHECK",
1388513967
#endif
13886
-#ifdef SQLITE_ENABLE_RTREE
13968
+#if SQLITE_ENABLE_RTREE
1388713969
"ENABLE_RTREE",
1388813970
#endif
1388913971
#if defined(SQLITE_ENABLE_STAT4)
1389013972
"ENABLE_STAT4",
1389113973
#elif defined(SQLITE_ENABLE_STAT3)
1389213974
"ENABLE_STAT3",
1389313975
#endif
13894
-#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
13976
+#if SQLITE_ENABLE_UNLOCK_NOTIFY
1389513977
"ENABLE_UNLOCK_NOTIFY",
1389613978
#endif
13897
-#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
13979
+#if SQLITE_ENABLE_UPDATE_DELETE_LIMIT
1389813980
"ENABLE_UPDATE_DELETE_LIMIT",
1389913981
#endif
13900
-#ifdef SQLITE_HAS_CODEC
13982
+#if SQLITE_HAS_CODEC
1390113983
"HAS_CODEC",
1390213984
#endif
13903
-#ifdef SQLITE_HAVE_ISNAN
13985
+#if HAVE_ISNAN || SQLITE_HAVE_ISNAN
1390413986
"HAVE_ISNAN",
1390513987
#endif
13906
-#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
13988
+#if SQLITE_HOMEGROWN_RECURSIVE_MUTEX
1390713989
"HOMEGROWN_RECURSIVE_MUTEX",
1390813990
#endif
13909
-#ifdef SQLITE_IGNORE_AFP_LOCK_ERRORS
13991
+#if SQLITE_IGNORE_AFP_LOCK_ERRORS
1391013992
"IGNORE_AFP_LOCK_ERRORS",
1391113993
#endif
13912
-#ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
13994
+#if SQLITE_IGNORE_FLOCK_LOCK_ERRORS
1391313995
"IGNORE_FLOCK_LOCK_ERRORS",
1391413996
#endif
1391513997
#ifdef SQLITE_INT64_TYPE
1391613998
"INT64_TYPE",
1391713999
#endif
13918
-#ifdef SQLITE_LOCK_TRACE
14000
+#if SQLITE_LOCK_TRACE
1391914001
"LOCK_TRACE",
1392014002
#endif
1392114003
#if defined(SQLITE_MAX_MMAP_SIZE) && !defined(SQLITE_MAX_MMAP_SIZE_xc)
1392214004
"MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE),
1392314005
#endif
1392414006
#ifdef SQLITE_MAX_SCHEMA_RETRY
1392514007
"MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
1392614008
#endif
13927
-#ifdef SQLITE_MEMDEBUG
14009
+#if SQLITE_MEMDEBUG
1392814010
"MEMDEBUG",
1392914011
#endif
13930
-#ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
14012
+#if SQLITE_MIXED_ENDIAN_64BIT_FLOAT
1393114013
"MIXED_ENDIAN_64BIT_FLOAT",
1393214014
#endif
13933
-#ifdef SQLITE_NO_SYNC
14015
+#if SQLITE_NO_SYNC
1393414016
"NO_SYNC",
1393514017
#endif
13936
-#ifdef SQLITE_OMIT_ALTERTABLE
14018
+#if SQLITE_OMIT_ALTERTABLE
1393714019
"OMIT_ALTERTABLE",
1393814020
#endif
13939
-#ifdef SQLITE_OMIT_ANALYZE
14021
+#if SQLITE_OMIT_ANALYZE
1394014022
"OMIT_ANALYZE",
1394114023
#endif
13942
-#ifdef SQLITE_OMIT_ATTACH
14024
+#if SQLITE_OMIT_ATTACH
1394314025
"OMIT_ATTACH",
1394414026
#endif
13945
-#ifdef SQLITE_OMIT_AUTHORIZATION
14027
+#if SQLITE_OMIT_AUTHORIZATION
1394614028
"OMIT_AUTHORIZATION",
1394714029
#endif
13948
-#ifdef SQLITE_OMIT_AUTOINCREMENT
14030
+#if SQLITE_OMIT_AUTOINCREMENT
1394914031
"OMIT_AUTOINCREMENT",
1395014032
#endif
13951
-#ifdef SQLITE_OMIT_AUTOINIT
14033
+#if SQLITE_OMIT_AUTOINIT
1395214034
"OMIT_AUTOINIT",
1395314035
#endif
13954
-#ifdef SQLITE_OMIT_AUTOMATIC_INDEX
14036
+#if SQLITE_OMIT_AUTOMATIC_INDEX
1395514037
"OMIT_AUTOMATIC_INDEX",
1395614038
#endif
13957
-#ifdef SQLITE_OMIT_AUTORESET
14039
+#if SQLITE_OMIT_AUTORESET
1395814040
"OMIT_AUTORESET",
1395914041
#endif
13960
-#ifdef SQLITE_OMIT_AUTOVACUUM
14042
+#if SQLITE_OMIT_AUTOVACUUM
1396114043
"OMIT_AUTOVACUUM",
1396214044
#endif
13963
-#ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
14045
+#if SQLITE_OMIT_BETWEEN_OPTIMIZATION
1396414046
"OMIT_BETWEEN_OPTIMIZATION",
1396514047
#endif
13966
-#ifdef SQLITE_OMIT_BLOB_LITERAL
14048
+#if SQLITE_OMIT_BLOB_LITERAL
1396714049
"OMIT_BLOB_LITERAL",
1396814050
#endif
13969
-#ifdef SQLITE_OMIT_BTREECOUNT
14051
+#if SQLITE_OMIT_BTREECOUNT
1397014052
"OMIT_BTREECOUNT",
1397114053
#endif
13972
-#ifdef SQLITE_OMIT_BUILTIN_TEST
14054
+#if SQLITE_OMIT_BUILTIN_TEST
1397314055
"OMIT_BUILTIN_TEST",
1397414056
#endif
13975
-#ifdef SQLITE_OMIT_CAST
14057
+#if SQLITE_OMIT_CAST
1397614058
"OMIT_CAST",
1397714059
#endif
13978
-#ifdef SQLITE_OMIT_CHECK
14060
+#if SQLITE_OMIT_CHECK
1397914061
"OMIT_CHECK",
1398014062
#endif
13981
-#ifdef SQLITE_OMIT_COMPLETE
14063
+#if SQLITE_OMIT_COMPLETE
1398214064
"OMIT_COMPLETE",
1398314065
#endif
13984
-#ifdef SQLITE_OMIT_COMPOUND_SELECT
14066
+#if SQLITE_OMIT_COMPOUND_SELECT
1398514067
"OMIT_COMPOUND_SELECT",
1398614068
#endif
13987
-#ifdef SQLITE_OMIT_CTE
14069
+#if SQLITE_OMIT_CTE
1398814070
"OMIT_CTE",
1398914071
#endif
13990
-#ifdef SQLITE_OMIT_DATETIME_FUNCS
14072
+#if SQLITE_OMIT_DATETIME_FUNCS
1399114073
"OMIT_DATETIME_FUNCS",
1399214074
#endif
13993
-#ifdef SQLITE_OMIT_DECLTYPE
14075
+#if SQLITE_OMIT_DECLTYPE
1399414076
"OMIT_DECLTYPE",
1399514077
#endif
13996
-#ifdef SQLITE_OMIT_DEPRECATED
14078
+#if SQLITE_OMIT_DEPRECATED
1399714079
"OMIT_DEPRECATED",
1399814080
#endif
13999
-#ifdef SQLITE_OMIT_DISKIO
14081
+#if SQLITE_OMIT_DISKIO
1400014082
"OMIT_DISKIO",
1400114083
#endif
14002
-#ifdef SQLITE_OMIT_EXPLAIN
14084
+#if SQLITE_OMIT_EXPLAIN
1400314085
"OMIT_EXPLAIN",
1400414086
#endif
14005
-#ifdef SQLITE_OMIT_FLAG_PRAGMAS
14087
+#if SQLITE_OMIT_FLAG_PRAGMAS
1400614088
"OMIT_FLAG_PRAGMAS",
1400714089
#endif
14008
-#ifdef SQLITE_OMIT_FLOATING_POINT
14090
+#if SQLITE_OMIT_FLOATING_POINT
1400914091
"OMIT_FLOATING_POINT",
1401014092
#endif
14011
-#ifdef SQLITE_OMIT_FOREIGN_KEY
14093
+#if SQLITE_OMIT_FOREIGN_KEY
1401214094
"OMIT_FOREIGN_KEY",
1401314095
#endif
14014
-#ifdef SQLITE_OMIT_GET_TABLE
14096
+#if SQLITE_OMIT_GET_TABLE
1401514097
"OMIT_GET_TABLE",
1401614098
#endif
14017
-#ifdef SQLITE_OMIT_INCRBLOB
14099
+#if SQLITE_OMIT_INCRBLOB
1401814100
"OMIT_INCRBLOB",
1401914101
#endif
14020
-#ifdef SQLITE_OMIT_INTEGRITY_CHECK
14102
+#if SQLITE_OMIT_INTEGRITY_CHECK
1402114103
"OMIT_INTEGRITY_CHECK",
1402214104
#endif
14023
-#ifdef SQLITE_OMIT_LIKE_OPTIMIZATION
14105
+#if SQLITE_OMIT_LIKE_OPTIMIZATION
1402414106
"OMIT_LIKE_OPTIMIZATION",
1402514107
#endif
14026
-#ifdef SQLITE_OMIT_LOAD_EXTENSION
14108
+#if SQLITE_OMIT_LOAD_EXTENSION
1402714109
"OMIT_LOAD_EXTENSION",
1402814110
#endif
14029
-#ifdef SQLITE_OMIT_LOCALTIME
14111
+#if SQLITE_OMIT_LOCALTIME
1403014112
"OMIT_LOCALTIME",
1403114113
#endif
14032
-#ifdef SQLITE_OMIT_LOOKASIDE
14114
+#if SQLITE_OMIT_LOOKASIDE
1403314115
"OMIT_LOOKASIDE",
1403414116
#endif
14035
-#ifdef SQLITE_OMIT_MEMORYDB
14117
+#if SQLITE_OMIT_MEMORYDB
1403614118
"OMIT_MEMORYDB",
1403714119
#endif
14038
-#ifdef SQLITE_OMIT_OR_OPTIMIZATION
14120
+#if SQLITE_OMIT_OR_OPTIMIZATION
1403914121
"OMIT_OR_OPTIMIZATION",
1404014122
#endif
14041
-#ifdef SQLITE_OMIT_PAGER_PRAGMAS
14123
+#if SQLITE_OMIT_PAGER_PRAGMAS
1404214124
"OMIT_PAGER_PRAGMAS",
1404314125
#endif
14044
-#ifdef SQLITE_OMIT_PRAGMA
14126
+#if SQLITE_OMIT_PRAGMA
1404514127
"OMIT_PRAGMA",
1404614128
#endif
14047
-#ifdef SQLITE_OMIT_PROGRESS_CALLBACK
14129
+#if SQLITE_OMIT_PROGRESS_CALLBACK
1404814130
"OMIT_PROGRESS_CALLBACK",
1404914131
#endif
14050
-#ifdef SQLITE_OMIT_QUICKBALANCE
14132
+#if SQLITE_OMIT_QUICKBALANCE
1405114133
"OMIT_QUICKBALANCE",
1405214134
#endif
14053
-#ifdef SQLITE_OMIT_REINDEX
14135
+#if SQLITE_OMIT_REINDEX
1405414136
"OMIT_REINDEX",
1405514137
#endif
14056
-#ifdef SQLITE_OMIT_SCHEMA_PRAGMAS
14138
+#if SQLITE_OMIT_SCHEMA_PRAGMAS
1405714139
"OMIT_SCHEMA_PRAGMAS",
1405814140
#endif
14059
-#ifdef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
14141
+#if SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
1406014142
"OMIT_SCHEMA_VERSION_PRAGMAS",
1406114143
#endif
14062
-#ifdef SQLITE_OMIT_SHARED_CACHE
14144
+#if SQLITE_OMIT_SHARED_CACHE
1406314145
"OMIT_SHARED_CACHE",
1406414146
#endif
14065
-#ifdef SQLITE_OMIT_SUBQUERY
14147
+#if SQLITE_OMIT_SUBQUERY
1406614148
"OMIT_SUBQUERY",
1406714149
#endif
14068
-#ifdef SQLITE_OMIT_TCL_VARIABLE
14150
+#if SQLITE_OMIT_TCL_VARIABLE
1406914151
"OMIT_TCL_VARIABLE",
1407014152
#endif
14071
-#ifdef SQLITE_OMIT_TEMPDB
14153
+#if SQLITE_OMIT_TEMPDB
1407214154
"OMIT_TEMPDB",
1407314155
#endif
14074
-#ifdef SQLITE_OMIT_TRACE
14156
+#if SQLITE_OMIT_TRACE
1407514157
"OMIT_TRACE",
1407614158
#endif
14077
-#ifdef SQLITE_OMIT_TRIGGER
14159
+#if SQLITE_OMIT_TRIGGER
1407814160
"OMIT_TRIGGER",
1407914161
#endif
14080
-#ifdef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
14162
+#if SQLITE_OMIT_TRUNCATE_OPTIMIZATION
1408114163
"OMIT_TRUNCATE_OPTIMIZATION",
1408214164
#endif
14083
-#ifdef SQLITE_OMIT_UTF16
14165
+#if SQLITE_OMIT_UTF16
1408414166
"OMIT_UTF16",
1408514167
#endif
14086
-#ifdef SQLITE_OMIT_VACUUM
14168
+#if SQLITE_OMIT_VACUUM
1408714169
"OMIT_VACUUM",
1408814170
#endif
14089
-#ifdef SQLITE_OMIT_VIEW
14171
+#if SQLITE_OMIT_VIEW
1409014172
"OMIT_VIEW",
1409114173
#endif
14092
-#ifdef SQLITE_OMIT_VIRTUALTABLE
14174
+#if SQLITE_OMIT_VIRTUALTABLE
1409314175
"OMIT_VIRTUALTABLE",
1409414176
#endif
14095
-#ifdef SQLITE_OMIT_WAL
14177
+#if SQLITE_OMIT_WAL
1409614178
"OMIT_WAL",
1409714179
#endif
14098
-#ifdef SQLITE_OMIT_WSD
14180
+#if SQLITE_OMIT_WSD
1409914181
"OMIT_WSD",
1410014182
#endif
14101
-#ifdef SQLITE_OMIT_XFER_OPT
14183
+#if SQLITE_OMIT_XFER_OPT
1410214184
"OMIT_XFER_OPT",
1410314185
#endif
14104
-#ifdef SQLITE_PERFORMANCE_TRACE
14186
+#if SQLITE_PERFORMANCE_TRACE
1410514187
"PERFORMANCE_TRACE",
1410614188
#endif
14107
-#ifdef SQLITE_PROXY_DEBUG
14189
+#if SQLITE_PROXY_DEBUG
1410814190
"PROXY_DEBUG",
1410914191
#endif
14110
-#ifdef SQLITE_RTREE_INT_ONLY
14192
+#if SQLITE_RTREE_INT_ONLY
1411114193
"RTREE_INT_ONLY",
1411214194
#endif
14113
-#ifdef SQLITE_SECURE_DELETE
14195
+#if SQLITE_SECURE_DELETE
1411414196
"SECURE_DELETE",
1411514197
#endif
14116
-#ifdef SQLITE_SMALL_STACK
14198
+#if SQLITE_SMALL_STACK
1411714199
"SMALL_STACK",
1411814200
#endif
14119
-#ifdef SQLITE_SOUNDEX
14201
+#if SQLITE_SOUNDEX
1412014202
"SOUNDEX",
1412114203
#endif
14122
-#ifdef SQLITE_SYSTEM_MALLOC
14204
+#if SQLITE_SYSTEM_MALLOC
1412314205
"SYSTEM_MALLOC",
1412414206
#endif
14125
-#ifdef SQLITE_TCL
14207
+#if SQLITE_TCL
1412614208
"TCL",
1412714209
#endif
1412814210
#if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc)
1412914211
"TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
1413014212
#endif
14131
-#ifdef SQLITE_TEST
14213
+#if SQLITE_TEST
1413214214
"TEST",
1413314215
#endif
1413414216
#if defined(SQLITE_THREADSAFE)
1413514217
"THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
1413614218
#endif
14137
-#ifdef SQLITE_USE_ALLOCA
14219
+#if SQLITE_USE_ALLOCA
1413814220
"USE_ALLOCA",
1413914221
#endif
14140
-#ifdef SQLITE_USER_AUTHENTICATION
14222
+#if SQLITE_USER_AUTHENTICATION
1414114223
"USER_AUTHENTICATION",
1414214224
#endif
14143
-#ifdef SQLITE_WIN32_MALLOC
14225
+#if SQLITE_WIN32_MALLOC
1414414226
"WIN32_MALLOC",
1414514227
#endif
14146
-#ifdef SQLITE_ZERO_MALLOC
14228
+#if SQLITE_ZERO_MALLOC
1414714229
"ZERO_MALLOC"
1414814230
#endif
1414914231
};
1415014232
1415114233
/*
@@ -14156,11 +14238,11 @@
1415614238
** is not required for a match.
1415714239
*/
1415814240
SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
1415914241
int i, n;
1416014242
14161
-#ifdef SQLITE_ENABLE_API_ARMOR
14243
+#if SQLITE_ENABLE_API_ARMOR
1416214244
if( zOptName==0 ){
1416314245
(void)SQLITE_MISUSE_BKPT;
1416414246
return 0;
1416514247
}
1416614248
#endif
@@ -15384,12 +15466,13 @@
1538415466
**
1538515467
** If the user has not indicated to use localtime_r() or localtime_s()
1538615468
** already, check for an MSVC build environment that provides
1538715469
** localtime_s().
1538815470
*/
15389
-#if !defined(HAVE_LOCALTIME_R) && !defined(HAVE_LOCALTIME_S) && \
15390
- defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
15471
+#if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S \
15472
+ && defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
15473
+#undef HAVE_LOCALTIME_S
1539115474
#define HAVE_LOCALTIME_S 1
1539215475
#endif
1539315476
1539415477
#ifndef SQLITE_OMIT_LOCALTIME
1539515478
/*
@@ -15405,12 +15488,11 @@
1540515488
** library function localtime_r() is used to assist in the calculation of
1540615489
** local time.
1540715490
*/
1540815491
static int osLocaltime(time_t *t, struct tm *pTm){
1540915492
int rc;
15410
-#if (!defined(HAVE_LOCALTIME_R) || !HAVE_LOCALTIME_R) \
15411
- && (!defined(HAVE_LOCALTIME_S) || !HAVE_LOCALTIME_S)
15493
+#if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S
1541215494
struct tm *pX;
1541315495
#if SQLITE_THREADSAFE>0
1541415496
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
1541515497
#endif
1541615498
sqlite3_mutex_enter(mutex);
@@ -15423,11 +15505,11 @@
1542315505
rc = pX==0;
1542415506
#else
1542515507
#ifndef SQLITE_OMIT_BUILTIN_TEST
1542615508
if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
1542715509
#endif
15428
-#if defined(HAVE_LOCALTIME_R) && HAVE_LOCALTIME_R
15510
+#if HAVE_LOCALTIME_R
1542915511
rc = localtime_r(t, pTm)==0;
1543015512
#else
1543115513
rc = localtime_s(pTm, t);
1543215514
#endif /* HAVE_LOCALTIME_R */
1543315515
#endif /* HAVE_LOCALTIME_R || HAVE_LOCALTIME_S */
@@ -15867,12 +15949,14 @@
1586715949
DateTime x;
1586815950
u64 n;
1586915951
size_t i,j;
1587015952
char *z;
1587115953
sqlite3 *db;
15872
- const char *zFmt = (const char*)sqlite3_value_text(argv[0]);
15954
+ const char *zFmt;
1587315955
char zBuf[100];
15956
+ if( argc==0 ) return;
15957
+ zFmt = (const char*)sqlite3_value_text(argv[0]);
1587415958
if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return;
1587515959
db = sqlite3_context_db_handle(context);
1587615960
for(i=0, n=1; zFmt[i]; i++, n++){
1587715961
if( zFmt[i]=='%' ){
1587815962
switch( zFmt[i+1] ){
@@ -16062,11 +16146,11 @@
1606216146
UNUSED_PARAMETER(argv);
1606316147
1606416148
iT = sqlite3StmtCurrentTime(context);
1606516149
if( iT<=0 ) return;
1606616150
t = iT/1000 - 10000*(sqlite3_int64)21086676;
16067
-#ifdef HAVE_GMTIME_R
16151
+#if HAVE_GMTIME_R
1606816152
pTm = gmtime_r(&t, &sNow);
1606916153
#else
1607016154
sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
1607116155
pTm = gmtime(&t);
1607216156
if( pTm ) memcpy(&sNow, pTm, sizeof(sNow));
@@ -16736,13 +16820,13 @@
1673616820
1673716821
/*
1673816822
** The malloc.h header file is needed for malloc_usable_size() function
1673916823
** on some systems (e.g. Linux).
1674016824
*/
16741
-#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE)
16742
-# define SQLITE_USE_MALLOC_H
16743
-# define SQLITE_USE_MALLOC_USABLE_SIZE
16825
+#if HAVE_MALLOC_H && HAVE_MALLOC_USABLE_SIZE
16826
+# define SQLITE_USE_MALLOC_H 1
16827
+# define SQLITE_USE_MALLOC_USABLE_SIZE 1
1674416828
/*
1674516829
** The MSVCRT has malloc_usable_size(), but it is called _msize(). The
1674616830
** use of _msize() is automatic, but can be disabled by compiling with
1674716831
** -DSQLITE_WITHOUT_MSIZE. Using the _msize() function also requires
1674816832
** the malloc.h header file.
@@ -19976,10 +20060,16 @@
1997620060
#endif
1997720061
}
1997820062
break;
1997920063
}
1998020064
default: {
20065
+#ifdef SQLITE_ENABLE_API_ARMOR
20066
+ if( iType-2<0 || iType-2>=ArraySize(winMutex_staticMutexes) ){
20067
+ (void)SQLITE_MISUSE_BKPT;
20068
+ return 0;
20069
+ }
20070
+#endif
1998120071
assert( iType-2 >= 0 );
1998220072
assert( iType-2 < ArraySize(winMutex_staticMutexes) );
1998320073
assert( winMutex_isInit==1 );
1998420074
p = &winMutex_staticMutexes[iType-2];
1998520075
#ifdef SQLITE_DEBUG
@@ -20971,21 +21061,10 @@
2097121061
** This file contains code for a set of "printf"-like routines. These
2097221062
** routines format strings much like the printf() from the standard C
2097321063
** library, though the implementation here has enhancements to support
2097421064
** SQLlite.
2097521065
*/
20976
-
20977
-/*
20978
-** If the strchrnul() library function is available, then set
20979
-** HAVE_STRCHRNUL. If that routine is not available, this module
20980
-** will supply its own. The built-in version is slower than
20981
-** the glibc version so the glibc version is definitely preferred.
20982
-*/
20983
-#if !defined(HAVE_STRCHRNUL)
20984
-# define HAVE_STRCHRNUL 0
20985
-#endif
20986
-
2098721066
2098821067
/*
2098921068
** Conversion types fall into various categories as defined by the
2099021069
** following enumeration.
2099121070
*/
@@ -22280,10 +22359,12 @@
2228022359
** single threaded systems. Nothing in SQLite requires multiple threads.
2228122360
** This interface exists so that applications that want to take advantage
2228222361
** of multiple cores can do so, while also allowing applications to stay
2228322362
** single-threaded if desired.
2228422363
*/
22364
+#if SQLITE_OS_WIN
22365
+#endif
2228522366
2228622367
#if SQLITE_MAX_WORKER_THREADS>0
2228722368
2228822369
/********************************* Unix Pthreads ****************************/
2228922370
#if SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) && SQLITE_THREADSAFE>0
@@ -23066,11 +23147,11 @@
2306623147
** This file contains functions for allocating memory, comparing
2306723148
** strings, and stuff like that.
2306823149
**
2306923150
*/
2307023151
/* #include <stdarg.h> */
23071
-#ifdef SQLITE_HAVE_ISNAN
23152
+#if HAVE_ISNAN || SQLITE_HAVE_ISNAN
2307223153
# include <math.h>
2307323154
#endif
2307423155
2307523156
/*
2307623157
** Routine needed to support the testcase() macro.
@@ -23107,11 +23188,11 @@
2310723188
** Use the math library isnan() function if compiled with SQLITE_HAVE_ISNAN.
2310823189
** Otherwise, we have our own implementation that works on most systems.
2310923190
*/
2311023191
SQLITE_PRIVATE int sqlite3IsNaN(double x){
2311123192
int rc; /* The value return */
23112
-#if !defined(SQLITE_HAVE_ISNAN)
23193
+#if !SQLITE_HAVE_ISNAN && !HAVE_ISNAN
2311323194
/*
2311423195
** Systems that support the isnan() library function should probably
2311523196
** make use of it by compiling with -DSQLITE_HAVE_ISNAN. But we have
2311623197
** found that many systems do not have a working isnan() function so
2311723198
** this implementation is provided as an alternative.
@@ -23137,13 +23218,13 @@
2313723218
# error SQLite will not work correctly with the -ffast-math option of GCC.
2313823219
#endif
2313923220
volatile double y = x;
2314023221
volatile double z = y;
2314123222
rc = (y!=z);
23142
-#else /* if defined(SQLITE_HAVE_ISNAN) */
23223
+#else /* if HAVE_ISNAN */
2314323224
rc = isnan(x);
23144
-#endif /* SQLITE_HAVE_ISNAN */
23225
+#endif /* HAVE_ISNAN */
2314523226
testcase( rc );
2314623227
return rc;
2314723228
}
2314823229
#endif /* SQLITE_OMIT_FLOATING_POINT */
2314923230
@@ -28460,13 +28541,13 @@
2846028541
2846128542
/*
2846228543
** We do not trust systems to provide a working fdatasync(). Some do.
2846328544
** Others do no. To be safe, we will stick with the (slightly slower)
2846428545
** fsync(). If you know that your system does support fdatasync() correctly,
28465
-** then simply compile with -Dfdatasync=fdatasync
28546
+** then simply compile with -Dfdatasync=fdatasync or -DHAVE_FDATASYNC
2846628547
*/
28467
-#if !defined(fdatasync)
28548
+#if !defined(fdatasync) && !HAVE_FDATASYNC
2846828549
# define fdatasync fsync
2846928550
#endif
2847028551
2847128552
/*
2847228553
** Define HAVE_FULLFSYNC to 0 or 1 depending on whether or not
@@ -28783,28 +28864,32 @@
2878328864
do{
2878428865
err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size);
2878528866
}while( err==EINTR );
2878628867
if( err ) return SQLITE_IOERR_WRITE;
2878728868
#else
28788
- /* If the OS does not have posix_fallocate(), fake it. First use
28789
- ** ftruncate() to set the file size, then write a single byte to
28790
- ** the last byte in each block within the extended region. This
28791
- ** is the same technique used by glibc to implement posix_fallocate()
28792
- ** on systems that do not have a real fallocate() system call.
28869
+ /* If the OS does not have posix_fallocate(), fake it. Write a
28870
+ ** single byte to the last byte in each block that falls entirely
28871
+ ** within the extended region. Then, if required, a single byte
28872
+ ** at offset (nSize-1), to set the size of the file correctly.
28873
+ ** This is a similar technique to that used by glibc on systems
28874
+ ** that do not have a real fallocate() call.
2879328875
*/
2879428876
int nBlk = buf.st_blksize; /* File-system block size */
28877
+ int nWrite = 0; /* Number of bytes written by seekAndWrite */
2879528878
i64 iWrite; /* Next offset to write to */
2879628879
28797
- if( robust_ftruncate(pFile->h, nSize) ){
28798
- pFile->lastErrno = errno;
28799
- return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
28800
- }
2880128880
iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
28802
- while( iWrite<nSize ){
28803
- int nWrite = seekAndWrite(pFile, iWrite, "", 1);
28881
+ assert( iWrite>=buf.st_size );
28882
+ assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) );
28883
+ assert( ((iWrite+1)%nBlk)==0 );
28884
+ for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){
28885
+ nWrite = seekAndWrite(pFile, iWrite, "", 1);
2880428886
if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
28805
- iWrite += nBlk;
28887
+ }
28888
+ if( nWrite==0 || (nSize%nBlk) ){
28889
+ nWrite = seekAndWrite(pFile, nSize-1, "", 1);
28890
+ if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
2880628891
}
2880728892
#endif
2880828893
}
2880928894
}
2881028895
@@ -34018,12 +34103,12 @@
3401834103
*/
3401934104
SQLITE_API int sqlite3_win32_reset_heap(){
3402034105
int rc;
3402134106
MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
3402234107
MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
34023
- MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
34024
- MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
34108
+ MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); )
34109
+ MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); )
3402534110
sqlite3_mutex_enter(pMaster);
3402634111
sqlite3_mutex_enter(pMem);
3402734112
winMemAssertMagic();
3402834113
if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
3402934114
/*
@@ -35294,11 +35379,11 @@
3529435379
sqlite3_file *id, /* File to read from */
3529535380
void *pBuf, /* Write content into this buffer */
3529635381
int amt, /* Number of bytes to read */
3529735382
sqlite3_int64 offset /* Begin reading at this offset */
3529835383
){
35299
-#if !SQLITE_OS_WINCE
35384
+#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
3530035385
OVERLAPPED overlapped; /* The offset for ReadFile. */
3530135386
#endif
3530235387
winFile *pFile = (winFile*)id; /* file handle */
3530335388
DWORD nRead; /* Number of bytes actually read from file */
3530435389
int nRetry = 0; /* Number of retrys */
@@ -35326,11 +35411,11 @@
3532635411
offset += nCopy;
3532735412
}
3532835413
}
3532935414
#endif
3533035415
35331
-#if SQLITE_OS_WINCE
35416
+#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
3533235417
if( winSeekFile(pFile, offset) ){
3533335418
OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h));
3533435419
return SQLITE_FULL;
3533535420
}
3533635421
while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
@@ -35398,32 +35483,32 @@
3539835483
offset += nCopy;
3539935484
}
3540035485
}
3540135486
#endif
3540235487
35403
-#if SQLITE_OS_WINCE
35488
+#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
3540435489
rc = winSeekFile(pFile, offset);
3540535490
if( rc==0 ){
3540635491
#else
3540735492
{
3540835493
#endif
35409
-#if !SQLITE_OS_WINCE
35494
+#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
3541035495
OVERLAPPED overlapped; /* The offset for WriteFile. */
3541135496
#endif
3541235497
u8 *aRem = (u8 *)pBuf; /* Data yet to be written */
3541335498
int nRem = amt; /* Number of bytes yet to be written */
3541435499
DWORD nWrite; /* Bytes written by each WriteFile() call */
3541535500
DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */
3541635501
35417
-#if !SQLITE_OS_WINCE
35502
+#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
3541835503
memset(&overlapped, 0, sizeof(OVERLAPPED));
3541935504
overlapped.Offset = (LONG)(offset & 0xffffffff);
3542035505
overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
3542135506
#endif
3542235507
3542335508
while( nRem>0 ){
35424
-#if SQLITE_OS_WINCE
35509
+#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
3542535510
if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
3542635511
#else
3542735512
if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){
3542835513
#endif
3542935514
if( winRetryIoerr(&nRetry, &lastErrno) ) continue;
@@ -35432,11 +35517,11 @@
3543235517
assert( nWrite==0 || nWrite<=(DWORD)nRem );
3543335518
if( nWrite==0 || nWrite>(DWORD)nRem ){
3543435519
lastErrno = osGetLastError();
3543535520
break;
3543635521
}
35437
-#if !SQLITE_OS_WINCE
35522
+#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
3543835523
offset += nWrite;
3543935524
overlapped.Offset = (LONG)(offset & 0xffffffff);
3544035525
overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
3544135526
#endif
3544235527
aRem += nWrite;
@@ -38813,22 +38898,10 @@
3881338898
void *pStress; /* Argument to xStress */
3881438899
sqlite3_pcache *pCache; /* Pluggable cache module */
3881538900
PgHdr *pPage1; /* Reference to page 1 */
3881638901
};
3881738902
38818
-/*
38819
-** Some of the assert() macros in this code are too expensive to run
38820
-** even during normal debugging. Use them only rarely on long-running
38821
-** tests. Enable the expensive asserts using the
38822
-** -DSQLITE_ENABLE_EXPENSIVE_ASSERT=1 compile-time option.
38823
-*/
38824
-#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
38825
-# define expensive_assert(X) assert(X)
38826
-#else
38827
-# define expensive_assert(X)
38828
-#endif
38829
-
3883038903
/********************************** Linked List Management ********************/
3883138904
3883238905
/* Allowed values for second argument to pcacheManageDirtyList() */
3883338906
#define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
3883438907
#define PCACHE_DIRTYLIST_ADD 2 /* Add pPage to the dirty list */
@@ -38978,11 +39051,12 @@
3897839051
SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
3897939052
assert( pCache->nRef==0 && pCache->pDirty==0 );
3898039053
if( pCache->szPage ){
3898139054
sqlite3_pcache *pNew;
3898239055
pNew = sqlite3GlobalConfig.pcache2.xCreate(
38983
- szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
39056
+ szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
39057
+ pCache->bPurgeable
3898439058
);
3898539059
if( pNew==0 ) return SQLITE_NOMEM;
3898639060
sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
3898739061
if( pCache->pCache ){
3898839062
sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
@@ -39437,11 +39511,11 @@
3943739511
3943839512
/*
3943939513
** Return the size of the header added by this middleware layer
3944039514
** in the page-cache hierarchy.
3944139515
*/
39442
-SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); }
39516
+SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); }
3944339517
3944439518
3944539519
#if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
3944639520
/*
3944739521
** For all dirty pages currently in the cache, invoke the specified
@@ -39753,11 +39827,11 @@
3975339827
pcache1Free(pPg);
3975439828
sqlite3_free(p);
3975539829
pPg = 0;
3975639830
}
3975739831
#else
39758
- pPg = pcache1Alloc(sizeof(PgHdr1) + pCache->szPage + pCache->szExtra);
39832
+ pPg = pcache1Alloc(ROUND8(sizeof(PgHdr1)) + pCache->szPage + pCache->szExtra);
3975939833
p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
3976039834
#endif
3976139835
pcache1EnterMutex(pCache->pGroup);
3976239836
3976339837
if( pPg ){
@@ -40441,11 +40515,11 @@
4044140515
}
4044240516
4044340517
/*
4044440518
** Return the size of the header on each page of this PCACHE implementation.
4044540519
*/
40446
-SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); }
40520
+SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return ROUND8(sizeof(PgHdr1)); }
4044740521
4044840522
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
4044940523
/*
4045040524
** This function is called to free superfluous dynamically allocated memory
4045140525
** held by the pager system. Memory in use by any SQLite pager allocated
@@ -41799,10 +41873,12 @@
4179941873
u8 eLock; /* Current lock held on database file */
4180041874
u8 changeCountDone; /* Set after incrementing the change-counter */
4180141875
u8 setMaster; /* True if a m-j name has been written to jrnl */
4180241876
u8 doNotSpill; /* Do not spill the cache when non-zero */
4180341877
u8 subjInMemory; /* True to use in-memory sub-journals */
41878
+ u8 bUseFetch; /* True to use xFetch() */
41879
+ u8 hasBeenUsed; /* True if any content previously read from this pager*/
4180441880
Pgno dbSize; /* Number of pages in the database */
4180541881
Pgno dbOrigSize; /* dbSize before the current transaction */
4180641882
Pgno dbFileSize; /* Number of pages in the database file */
4180741883
Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */
4180841884
int errCode; /* One of several kinds of errors */
@@ -41816,13 +41892,13 @@
4181641892
i64 journalOff; /* Current write offset in the journal file */
4181741893
i64 journalHdr; /* Byte offset to previous journal header */
4181841894
sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
4181941895
PagerSavepoint *aSavepoint; /* Array of active savepoints */
4182041896
int nSavepoint; /* Number of elements in aSavepoint[] */
41897
+ u32 iDataVersion; /* Changes whenever database content changes */
4182141898
char dbFileVers[16]; /* Changes whenever database file changes */
4182241899
41823
- u8 bUseFetch; /* True to use xFetch() */
4182441900
int nMmapOut; /* Number of mmap pages currently outstanding */
4182541901
sqlite3_int64 szMmap; /* Desired maximum mmap size */
4182641902
PgHdr *pMmapFreelist; /* List of free mmap page headers (pDirty) */
4182741903
/*
4182841904
** End of the routinely-changing class members
@@ -42834,13 +42910,22 @@
4283442910
4283542911
/*
4283642912
** Discard the entire contents of the in-memory page-cache.
4283742913
*/
4283842914
static void pager_reset(Pager *pPager){
42915
+ pPager->iDataVersion++;
4283942916
sqlite3BackupRestart(pPager->pBackup);
4284042917
sqlite3PcacheClear(pPager->pPCache);
4284142918
}
42919
+
42920
+/*
42921
+** Return the pPager->iDataVersion value
42922
+*/
42923
+SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager *pPager){
42924
+ assert( pPager->eState>PAGER_OPEN );
42925
+ return pPager->iDataVersion;
42926
+}
4284242927
4284342928
/*
4284442929
** Free all structures in the Pager.aSavepoint[] array and set both
4284542930
** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
4284642931
** if it is open and the pager is not in exclusive mode.
@@ -45040,11 +45125,11 @@
4504045125
Pgno pgno, /* Page number */
4504145126
void *pData, /* xFetch()'d data for this page */
4504245127
PgHdr **ppPage /* OUT: Acquired page object */
4504345128
){
4504445129
PgHdr *p; /* Memory mapped page to return */
45045
-
45130
+
4504645131
if( pPager->pMmapFreelist ){
4504745132
*ppPage = p = pPager->pMmapFreelist;
4504845133
pPager->pMmapFreelist = p->pDirty;
4504945134
p->pDirty = 0;
4505045135
memset(p->pExtra, 0, pPager->nExtra);
@@ -46271,20 +46356,16 @@
4627146356
assert( (pPager->eLock==SHARED_LOCK)
4627246357
|| (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK)
4627346358
);
4627446359
}
4627546360
46276
- if( !pPager->tempFile && (
46277
- pPager->pBackup
46278
- || sqlite3PcachePagecount(pPager->pPCache)>0
46279
- || USEFETCH(pPager)
46280
- )){
46281
- /* The shared-lock has just been acquired on the database file
46282
- ** and there are already pages in the cache (from a previous
46283
- ** read or write transaction). Check to see if the database
46284
- ** has been modified. If the database has changed, flush the
46285
- ** cache.
46361
+ if( !pPager->tempFile && pPager->hasBeenUsed ){
46362
+ /* The shared-lock has just been acquired then check to
46363
+ ** see if the database has been modified. If the database has changed,
46364
+ ** flush the cache. The pPager->hasBeenUsed flag prevents this from
46365
+ ** occurring on the very first access to a file, in order to save a
46366
+ ** single unnecessary sqlite3OsRead() call at the start-up.
4628646367
**
4628746368
** Database changes is detected by looking at 15 bytes beginning
4628846369
** at offset 24 into the file. The first 4 of these 16 bytes are
4628946370
** a 32-bit counter that is incremented with each change. The
4629046371
** other bytes change randomly with each file change when
@@ -46445,10 +46526,11 @@
4644546526
assert( noContent==0 || bMmapOk==0 );
4644646527
4644746528
if( pgno==0 ){
4644846529
return SQLITE_CORRUPT_BKPT;
4644946530
}
46531
+ pPager->hasBeenUsed = 1;
4645046532
4645146533
/* If the pager is in the error state, return an error immediately.
4645246534
** Otherwise, request the page from the PCache layer. */
4645346535
if( pPager->errCode!=SQLITE_OK ){
4645446536
rc = pPager->errCode;
@@ -46594,10 +46676,11 @@
4659446676
sqlite3_pcache_page *pPage;
4659546677
assert( pPager!=0 );
4659646678
assert( pgno!=0 );
4659746679
assert( pPager->pPCache!=0 );
4659846680
pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
46681
+ assert( pPage==0 || pPager->hasBeenUsed );
4659946682
return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
4660046683
}
4660146684
4660246685
/*
4660346686
** Release a page reference.
@@ -47460,10 +47543,11 @@
4746047543
pPager->eState = PAGER_READER;
4746147544
return SQLITE_OK;
4746247545
}
4746347546
4746447547
PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
47548
+ pPager->iDataVersion++;
4746547549
rc = pager_end_transaction(pPager, pPager->setMaster, 1);
4746647550
return pager_error(pPager, rc);
4746747551
}
4746847552
4746947553
/*
@@ -50829,11 +50913,11 @@
5082950913
}
5083050914
nCollide = HASHTABLE_NSLOT;
5083150915
for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
5083250916
u32 iFrame = aHash[iKey] + iZero;
5083350917
if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
50834
- /* assert( iFrame>iRead ); -- not true if there is corruption */
50918
+ assert( iFrame>iRead || CORRUPT_DB );
5083550919
iRead = iFrame;
5083650920
}
5083750921
if( (nCollide--)==0 ){
5083850922
return SQLITE_CORRUPT_BKPT;
5083950923
}
@@ -51935,10 +52019,11 @@
5193552019
u8 inTrans; /* TRANS_NONE, TRANS_READ or TRANS_WRITE */
5193652020
u8 sharable; /* True if we can share pBt with another db */
5193752021
u8 locked; /* True if db currently has pBt locked */
5193852022
int wantToLock; /* Number of nested calls to sqlite3BtreeEnter() */
5193952023
int nBackup; /* Number of backup operations reading this btree */
52024
+ u32 iDataVersion; /* Combines with pBt->pPager->iDataVersion */
5194052025
Btree *pNext; /* List of other sharable Btrees from the same db */
5194152026
Btree *pPrev; /* Back pointer of the same list */
5194252027
#ifndef SQLITE_OMIT_SHARED_CACHE
5194352028
BtLock lock; /* Object used to lock page 1 */
5194452029
#endif
@@ -56098,10 +56183,11 @@
5609856183
rc = sqlite3PagerCommitPhaseTwo(pBt->pPager);
5609956184
if( rc!=SQLITE_OK && bCleanup==0 ){
5610056185
sqlite3BtreeLeave(p);
5610156186
return rc;
5610256187
}
56188
+ p->iDataVersion--; /* Compensate for pPager->iDataVersion++; */
5610356189
pBt->inTransaction = TRANS_READ;
5610456190
btreeClearHasContent(pBt);
5610556191
}
5610656192
5610756193
btreeEndTransaction(p);
@@ -56461,11 +56547,11 @@
5646156547
}
5646256548
for(i=0; i<=pCur->iPage; i++){
5646356549
releasePage(pCur->apPage[i]);
5646456550
}
5646556551
unlockBtreeIfUnused(pBt);
56466
- sqlite3DbFree(pBtree->db, pCur->aOverflow);
56552
+ sqlite3_free(pCur->aOverflow);
5646756553
/* sqlite3_free(pCur); */
5646856554
sqlite3BtreeLeave(pBtree);
5646956555
}
5647056556
return SQLITE_OK;
5647156557
}
@@ -56755,10 +56841,11 @@
5675556841
pBuf += a;
5675656842
amt -= a;
5675756843
}else{
5675856844
offset -= pCur->info.nLocal;
5675956845
}
56846
+
5676056847
5676156848
if( rc==SQLITE_OK && amt>0 ){
5676256849
const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */
5676356850
Pgno nextPage;
5676456851
@@ -56773,12 +56860,12 @@
5677356860
** means "not yet known" (the cache is lazily populated).
5677456861
*/
5677556862
if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){
5677656863
int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
5677756864
if( nOvfl>pCur->nOvflAlloc ){
56778
- Pgno *aNew = (Pgno*)sqlite3DbRealloc(
56779
- pCur->pBtree->db, pCur->aOverflow, nOvfl*2*sizeof(Pgno)
56865
+ Pgno *aNew = (Pgno*)sqlite3Realloc(
56866
+ pCur->aOverflow, nOvfl*2*sizeof(Pgno)
5678056867
);
5678156868
if( aNew==0 ){
5678256869
rc = SQLITE_NOMEM;
5678356870
}else{
5678456871
pCur->nOvflAlloc = nOvfl*2;
@@ -56821,10 +56908,11 @@
5682156908
** Note that the aOverflow[] array must be allocated because eOp!=2
5682256909
** here. If eOp==2, then offset==0 and this branch is never taken.
5682356910
*/
5682456911
assert( eOp!=2 );
5682556912
assert( pCur->curFlags & BTCF_ValidOvfl );
56913
+ assert( pCur->pBtree->db==pBt->db );
5682656914
if( pCur->aOverflow[iIdx+1] ){
5682756915
nextPage = pCur->aOverflow[iIdx+1];
5682856916
}else{
5682956917
rc = getOverflowPage(pBt, nextPage, 0, &nextPage);
5683056918
}
@@ -59410,12 +59498,12 @@
5941059498
assert( leafCorrection==4 );
5941159499
if( szCell[nCell]<4 ){
5941259500
/* Do not allow any cells smaller than 4 bytes. If a smaller cell
5941359501
** does exist, pad it with 0x00 bytes. */
5941459502
assert( szCell[nCell]==3 );
59415
- assert( apCell[nCell]==&pTemp[iSpace1-3] );
59416
- pTemp[iSpace1++] = 0x00;
59503
+ assert( apCell[nCell]==&aSpace1[iSpace1-3] );
59504
+ aSpace1[iSpace1++] = 0x00;
5941759505
szCell[nCell] = 4;
5941859506
}
5941959507
}
5942059508
nCell++;
5942159509
}
@@ -60723,10 +60811,17 @@
6072360811
** is read-only, the others are read/write.
6072460812
**
6072560813
** The schema layer numbers meta values differently. At the schema
6072660814
** layer (and the SetCookie and ReadCookie opcodes) the number of
6072760815
** free pages is not visible. So Cookie[0] is the same as Meta[1].
60816
+**
60817
+** This routine treats Meta[BTREE_DATA_VERSION] as a special case. Instead
60818
+** of reading the value out of the header, it instead loads the "DataVersion"
60819
+** from the pager. The BTREE_DATA_VERSION value is not actually stored in the
60820
+** database file. It is a number computed by the pager. But its access
60821
+** pattern is the same as header meta values, and so it is convenient to
60822
+** read it from this routine.
6072860823
*/
6072960824
SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
6073060825
BtShared *pBt = p->pBt;
6073160826
6073260827
sqlite3BtreeEnter(p);
@@ -60733,11 +60828,15 @@
6073360828
assert( p->inTrans>TRANS_NONE );
6073460829
assert( SQLITE_OK==querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK) );
6073560830
assert( pBt->pPage1 );
6073660831
assert( idx>=0 && idx<=15 );
6073760832
60738
- *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
60833
+ if( idx==BTREE_DATA_VERSION ){
60834
+ *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion;
60835
+ }else{
60836
+ *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
60837
+ }
6073960838
6074060839
/* If auto-vacuum is disabled in this build and this is an auto-vacuum
6074160840
** database, mark the database as read-only. */
6074260841
#ifdef SQLITE_OMIT_AUTOVACUUM
6074360842
if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){
@@ -60824,11 +60923,11 @@
6082460923
if( pPage->leaf ){
6082560924
do {
6082660925
if( pCur->iPage==0 ){
6082760926
/* All pages of the b-tree have been visited. Return successfully. */
6082860927
*pnEntry = nEntry;
60829
- return SQLITE_OK;
60928
+ return moveToRoot(pCur);
6083060929
}
6083160930
moveToParent(pCur);
6083260931
}while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
6083360932
6083460933
pCur->aiIdx[pCur->iPage]++;
@@ -61680,11 +61779,11 @@
6168061779
}
6168161780
6168261781
/*
6168361782
** Return the size of the header added to each page by this module.
6168461783
*/
61685
-SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); }
61784
+SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return ROUND8(sizeof(MemPage)); }
6168661785
6168761786
/************** End of btree.c ***********************************************/
6168861787
/************** Begin file backup.c ******************************************/
6168961788
/*
6169061789
** 2009 January 28
@@ -64444,36 +64543,39 @@
6444464543
**
6444564544
** assert( sqlite3VdbeAssertMayAbort(pParse->pVdbe, pParse->mayAbort) );
6444664545
*/
6444764546
SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
6444864547
int hasAbort = 0;
64548
+ int hasFkCounter = 0;
6444964549
Op *pOp;
6445064550
VdbeOpIter sIter;
6445164551
memset(&sIter, 0, sizeof(sIter));
6445264552
sIter.v = v;
6445364553
6445464554
while( (pOp = opIterNext(&sIter))!=0 ){
6445564555
int opcode = pOp->opcode;
6445664556
if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
64457
-#ifndef SQLITE_OMIT_FOREIGN_KEY
64458
- || (opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1)
64459
-#endif
6446064557
|| ((opcode==OP_Halt || opcode==OP_HaltIfNull)
6446164558
&& ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
6446264559
){
6446364560
hasAbort = 1;
6446464561
break;
6446564562
}
64563
+#ifndef SQLITE_OMIT_FOREIGN_KEY
64564
+ if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){
64565
+ hasFkCounter = 1;
64566
+ }
64567
+#endif
6446664568
}
6446764569
sqlite3DbFree(v->db, sIter.apSub);
6446864570
6446964571
/* Return true if hasAbort==mayAbort. Or if a malloc failure occurred.
6447064572
** If malloc failed, then the while() loop above may not have iterated
6447164573
** through all opcodes and hasAbort may be set incorrectly. Return
6447264574
** true for this case to prevent the assert() in the callers frame
6447364575
** from failing. */
64474
- return ( v->db->mallocFailed || hasAbort==mayAbort );
64576
+ return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter );
6447564577
}
6447664578
#endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */
6447764579
6447864580
/*
6447964581
** Loop through the program looking for P2 values that are negative
@@ -68593,11 +68695,14 @@
6859368695
#ifndef SQLITE_OMIT_WAL
6859468696
int i;
6859568697
for(i=0; i<db->nDb; i++){
6859668698
Btree *pBt = db->aDb[i].pBt;
6859768699
if( pBt ){
68598
- int nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
68700
+ int nEntry;
68701
+ sqlite3BtreeEnter(pBt);
68702
+ nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
68703
+ sqlite3BtreeLeave(pBt);
6859968704
if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
6860068705
rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
6860168706
}
6860268707
}
6860368708
}
@@ -68773,11 +68878,10 @@
6877368878
** program counter to 0 to ensure that when the statement is
6877468879
** finalized or reset the parser error message is available via
6877568880
** sqlite3_errmsg() and sqlite3_errcode().
6877668881
*/
6877768882
const char *zErr = (const char *)sqlite3_value_text(db->pErr);
68778
- assert( zErr!=0 || db->mallocFailed );
6877968883
sqlite3DbFree(db, v->zErrMsg);
6878068884
if( !db->mallocFailed ){
6878168885
v->zErrMsg = sqlite3DbStrDup(db, zErr);
6878268886
v->rc = rc2;
6878368887
} else {
@@ -73838,12 +73942,12 @@
7383873942
pIdxKey->default_rc = 0;
7383973943
if( pOp->opcode==OP_NoConflict ){
7384073944
/* For the OP_NoConflict opcode, take the jump if any of the
7384173945
** input fields are NULL, since any key with a NULL will not
7384273946
** conflict */
73843
- for(ii=0; ii<r.nField; ii++){
73844
- if( r.aMem[ii].flags & MEM_Null ){
73947
+ for(ii=0; ii<pIdxKey->nField; ii++){
73948
+ if( pIdxKey->aMem[ii].flags & MEM_Null ){
7384573949
pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
7384673950
break;
7384773951
}
7384873952
}
7384973953
}
@@ -77135,11 +77239,11 @@
7713577239
/*
7713677240
** Hard-coded maximum amount of data to accumulate in memory before flushing
7713777241
** to a level 0 PMA. The purpose of this limit is to prevent various integer
7713877242
** overflows. 512MiB.
7713977243
*/
77140
-#define SQLITE_MAX_MXPMASIZE (1<<29)
77244
+#define SQLITE_MAX_PMASZ (1<<29)
7714177245
7714277246
/*
7714377247
** Private objects used by the sorter
7714477248
*/
7714577249
typedef struct MergeEngine MergeEngine; /* Merge PMAs together */
@@ -77431,15 +77535,10 @@
7743177535
**
7743277536
** void *SRVAL(SorterRecord *p) { return (void*)&p[1]; }
7743377537
*/
7743477538
#define SRVAL(p) ((void*)((SorterRecord*)(p) + 1))
7743577539
77436
-/* The minimum PMA size is set to this value multiplied by the database
77437
-** page size in bytes. */
77438
-#ifndef SQLITE_SORTER_PMASZ
77439
-# define SQLITE_SORTER_PMASZ 10
77440
-#endif
7744177540
7744277541
/* Maximum number of PMAs that a single MergeEngine can merge */
7744377542
#define SORTER_MAX_MERGE_COUNT 16
7744477543
7744577544
static int vdbeIncrSwap(IncrMerger*);
@@ -77834,14 +77933,15 @@
7783477933
SortSubtask *pTask = &pSorter->aTask[i];
7783577934
pTask->pSorter = pSorter;
7783677935
}
7783777936
7783877937
if( !sqlite3TempInMemory(db) ){
77839
- pSorter->mnPmaSize = SQLITE_SORTER_PMASZ * pgsz;
77938
+ u32 szPma = sqlite3GlobalConfig.szPma;
77939
+ pSorter->mnPmaSize = szPma * pgsz;
7784077940
mxCache = db->aDb[0].pSchema->cache_size;
77841
- if( mxCache<SQLITE_SORTER_PMASZ ) mxCache = SQLITE_SORTER_PMASZ;
77842
- pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_MXPMASIZE);
77941
+ if( mxCache<(int)szPma ) mxCache = (int)szPma;
77942
+ pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_PMASZ);
7784377943
7784477944
/* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
7784577945
** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
7784677946
** large heap allocations.
7784777947
*/
@@ -78115,16 +78215,16 @@
7811578215
** Whether or not the file does end up memory mapped of course depends on
7811678216
** the specific VFS implementation.
7811778217
*/
7811878218
static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){
7811978219
if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){
78120
- int rc = sqlite3OsTruncate(pFd, nByte);
78121
- if( rc==SQLITE_OK ){
78122
- void *p = 0;
78123
- sqlite3OsFetch(pFd, 0, (int)nByte, &p);
78124
- sqlite3OsUnfetch(pFd, 0, p);
78125
- }
78220
+ void *p = 0;
78221
+ int chunksize = 4*1024;
78222
+ sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize);
78223
+ sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte);
78224
+ sqlite3OsFetch(pFd, 0, (int)nByte, &p);
78225
+ sqlite3OsUnfetch(pFd, 0, p);
7812678226
}
7812778227
}
7812878228
#else
7812978229
# define vdbeSorterExtendFile(x,y,z)
7813078230
#endif
@@ -79401,10 +79501,11 @@
7940179501
rc = vdbePmaReaderNext(pSorter->pReader);
7940279502
*pbEof = (pSorter->pReader->pFd==0);
7940379503
}else
7940479504
#endif
7940579505
/*if( !pSorter->bUseThreads )*/ {
79506
+ assert( pSorter->pMerger!=0 );
7940679507
assert( pSorter->pMerger->pTask==(&pSorter->aTask[0]) );
7940779508
rc = vdbeMergeEngineStep(pSorter->pMerger, pbEof);
7940879509
}
7940979510
}else{
7941079511
SorterRecord *pFree = pSorter->list.pList;
@@ -82167,11 +82268,11 @@
8216782268
Expr *pLeft, /* Left operand */
8216882269
Expr *pRight, /* Right operand */
8216982270
const Token *pToken /* Argument token */
8217082271
){
8217182272
Expr *p;
82172
- if( op==TK_AND && pLeft && pRight ){
82273
+ if( op==TK_AND && pLeft && pRight && pParse->nErr==0 ){
8217382274
/* Take advantage of short-circuit false optimization for AND */
8217482275
p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
8217582276
}else{
8217682277
p = sqlite3ExprAlloc(pParse->db, op, pToken, 1);
8217782278
sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
@@ -85721,14 +85822,15 @@
8572185822
** NEVER() will need to be removed. */
8572285823
if( pExpr->op==TK_COLUMN || NEVER(pExpr->op==TK_AGG_COLUMN) ){
8572385824
int i;
8572485825
struct SrcCount *p = pWalker->u.pSrcCount;
8572585826
SrcList *pSrc = p->pSrc;
85726
- for(i=0; i<pSrc->nSrc; i++){
85827
+ int nSrc = pSrc ? pSrc->nSrc : 0;
85828
+ for(i=0; i<nSrc; i++){
8572785829
if( pExpr->iTable==pSrc->a[i].iCursor ) break;
8572885830
}
85729
- if( i<pSrc->nSrc ){
85831
+ if( i<nSrc ){
8573085832
p->nThis++;
8573185833
}else{
8573285834
p->nOther++;
8573385835
}
8573485836
}
@@ -87302,11 +87404,11 @@
8730287404
8730387405
p->iGet = -1;
8730487406
p->mxSample = mxSample;
8730587407
p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[2])/(mxSample/3+1) + 1);
8730687408
p->current.anLt = &p->current.anEq[nColUp];
87307
- p->iPrn = nCol*0x689e962d ^ sqlite3_value_int(argv[2])*0xd0944565;
87409
+ p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]);
8730887410
8730987411
/* Set up the Stat4Accum.a[] and aBest[] arrays */
8731087412
p->a = (struct Stat4Sample*)&p->current.anLt[nColUp];
8731187413
p->aBest = &p->a[mxSample];
8731287414
pSpace = (u8*)(&p->a[mxSample+nCol]);
@@ -88895,17 +88997,19 @@
8889588997
}else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
8889688998
zErrDyn = sqlite3MPrintf(db,
8889788999
"attached databases must use the same text encoding as main database");
8889889000
rc = SQLITE_ERROR;
8889989001
}
89002
+ sqlite3BtreeEnter(aNew->pBt);
8890089003
pPager = sqlite3BtreePager(aNew->pBt);
8890189004
sqlite3PagerLockingMode(pPager, db->dfltLockMode);
8890289005
sqlite3BtreeSecureDelete(aNew->pBt,
8890389006
sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
8890489007
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
8890589008
sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK));
8890689009
#endif
89010
+ sqlite3BtreeLeave(aNew->pBt);
8890789011
}
8890889012
aNew->safety_level = 3;
8890989013
aNew->zName = sqlite3DbStrDup(db, zName);
8891089014
if( rc==SQLITE_OK && aNew->zName==0 ){
8891189015
rc = SQLITE_NOMEM;
@@ -90027,11 +90131,10 @@
9002790131
*/
9002890132
static void freeIndex(sqlite3 *db, Index *p){
9002990133
#ifndef SQLITE_OMIT_ANALYZE
9003090134
sqlite3DeleteIndexSamples(db, p);
9003190135
#endif
90032
- if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo);
9003390136
sqlite3ExprDelete(db, p->pPartIdxWhere);
9003490137
sqlite3DbFree(db, p->zColAff);
9003590138
if( p->isResized ) sqlite3DbFree(db, p->azColl);
9003690139
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
9003790140
sqlite3_free(p->aiRowEst);
@@ -91306,10 +91409,23 @@
9130691409
if( pPk==0 ) return;
9130791410
pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
9130891411
pTab->iPKey = -1;
9130991412
}else{
9131091413
pPk = sqlite3PrimaryKeyIndex(pTab);
91414
+ /*
91415
+ ** Remove all redundant columns from the PRIMARY KEY. For example, change
91416
+ ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
91417
+ ** code assumes the PRIMARY KEY contains no repeated columns.
91418
+ */
91419
+ for(i=j=1; i<pPk->nKeyCol; i++){
91420
+ if( hasColumn(pPk->aiColumn, j, pPk->aiColumn[i]) ){
91421
+ pPk->nColumn--;
91422
+ }else{
91423
+ pPk->aiColumn[j++] = pPk->aiColumn[i];
91424
+ }
91425
+ }
91426
+ pPk->nKeyCol = j;
9131191427
}
9131291428
pPk->isCovering = 1;
9131391429
assert( pPk!=0 );
9131491430
nPk = pPk->nKeyCol;
9131591431
@@ -93782,44 +93898,35 @@
9378293898
**
9378393899
** The caller should invoke sqlite3KeyInfoUnref() on the returned object
9378493900
** when it has finished using it.
9378593901
*/
9378693902
SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
93903
+ int i;
93904
+ int nCol = pIdx->nColumn;
93905
+ int nKey = pIdx->nKeyCol;
93906
+ KeyInfo *pKey;
9378793907
if( pParse->nErr ) return 0;
93788
-#ifndef SQLITE_OMIT_SHARED_CACHE
93789
- if( pIdx->pKeyInfo && pIdx->pKeyInfo->db!=pParse->db ){
93790
- sqlite3KeyInfoUnref(pIdx->pKeyInfo);
93791
- pIdx->pKeyInfo = 0;
93792
- }
93793
-#endif
93794
- if( pIdx->pKeyInfo==0 ){
93795
- int i;
93796
- int nCol = pIdx->nColumn;
93797
- int nKey = pIdx->nKeyCol;
93798
- KeyInfo *pKey;
93799
- if( pIdx->uniqNotNull ){
93800
- pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
93801
- }else{
93802
- pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
93803
- }
93804
- if( pKey ){
93805
- assert( sqlite3KeyInfoIsWriteable(pKey) );
93806
- for(i=0; i<nCol; i++){
93807
- char *zColl = pIdx->azColl[i];
93808
- assert( zColl!=0 );
93809
- pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 :
93810
- sqlite3LocateCollSeq(pParse, zColl);
93811
- pKey->aSortOrder[i] = pIdx->aSortOrder[i];
93812
- }
93813
- if( pParse->nErr ){
93814
- sqlite3KeyInfoUnref(pKey);
93815
- }else{
93816
- pIdx->pKeyInfo = pKey;
93817
- }
93818
- }
93819
- }
93820
- return sqlite3KeyInfoRef(pIdx->pKeyInfo);
93908
+ if( pIdx->uniqNotNull ){
93909
+ pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
93910
+ }else{
93911
+ pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
93912
+ }
93913
+ if( pKey ){
93914
+ assert( sqlite3KeyInfoIsWriteable(pKey) );
93915
+ for(i=0; i<nCol; i++){
93916
+ char *zColl = pIdx->azColl[i];
93917
+ assert( zColl!=0 );
93918
+ pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 :
93919
+ sqlite3LocateCollSeq(pParse, zColl);
93920
+ pKey->aSortOrder[i] = pIdx->aSortOrder[i];
93921
+ }
93922
+ if( pParse->nErr ){
93923
+ sqlite3KeyInfoUnref(pKey);
93924
+ pKey = 0;
93925
+ }
93926
+ }
93927
+ return pKey;
9382193928
}
9382293929
9382393930
#ifndef SQLITE_OMIT_CTE
9382493931
/*
9382593932
** This routine is invoked once per CTE by the parser while parsing a
@@ -94596,12 +94703,12 @@
9459694703
const char *zDb; /* Name of database holding pTab */
9459794704
int i; /* Loop counter */
9459894705
WhereInfo *pWInfo; /* Information about the WHERE clause */
9459994706
Index *pIdx; /* For looping over indices of the table */
9460094707
int iTabCur; /* Cursor number for the table */
94601
- int iDataCur; /* VDBE cursor for the canonical data source */
94602
- int iIdxCur; /* Cursor number of the first index */
94708
+ int iDataCur = 0; /* VDBE cursor for the canonical data source */
94709
+ int iIdxCur = 0; /* Cursor number of the first index */
9460394710
int nIdx; /* Number of indices */
9460494711
sqlite3 *db; /* Main database structure */
9460594712
AuthContext sContext; /* Authorization context */
9460694713
NameContext sNC; /* Name context to resolve expressions in */
9460794714
int iDb; /* Database number */
@@ -97436,11 +97543,11 @@
9743697543
assert( nIncr==1 );
9743797544
sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
9743897545
OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
9743997546
}else{
9744097547
if( nIncr>0 && pFKey->isDeferred==0 ){
97441
- sqlite3ParseToplevel(pParse)->mayAbort = 1;
97548
+ sqlite3MayAbort(pParse);
9744297549
}
9744397550
sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
9744497551
}
9744597552
9744697553
sqlite3VdbeResolveLabel(v, iOk);
@@ -97507,10 +97614,14 @@
9750797614
** This function is called to generate code executed when a row is deleted
9750897615
** from the parent table of foreign key constraint pFKey and, if pFKey is
9750997616
** deferred, when a row is inserted into the same table. When generating
9751097617
** code for an SQL UPDATE operation, this function may be called twice -
9751197618
** once to "delete" the old row and once to "insert" the new row.
97619
+**
97620
+** Parameter nIncr is passed -1 when inserting a row (as this may decrease
97621
+** the number of FK violations in the db) or +1 when deleting one (as this
97622
+** may increase the number of FK constraint problems).
9751297623
**
9751397624
** The code generated by this function scans through the rows in the child
9751497625
** table that correspond to the parent table row being deleted or inserted.
9751597626
** For each child row found, one of the following actions is taken:
9751697627
**
@@ -97624,17 +97735,13 @@
9762497735
sNameContext.pSrcList = pSrc;
9762597736
sNameContext.pParse = pParse;
9762697737
sqlite3ResolveExprNames(&sNameContext, pWhere);
9762797738
9762897739
/* Create VDBE to loop through the entries in pSrc that match the WHERE
97629
- ** clause. If the constraint is not deferred, throw an exception for
97630
- ** each row found. Otherwise, for deferred constraints, increment the
97631
- ** deferred constraint counter by nIncr for each row selected. */
97740
+ ** clause. For each row found, increment either the deferred or immediate
97741
+ ** foreign key constraint counter. */
9763297742
pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
97633
- if( nIncr>0 && pFKey->isDeferred==0 ){
97634
- sqlite3ParseToplevel(pParse)->mayAbort = 1;
97635
- }
9763697743
sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
9763797744
if( pWInfo ){
9763897745
sqlite3WhereEnd(pWInfo);
9763997746
}
9764097747
@@ -97808,10 +97915,28 @@
9780897915
}
9780997916
}
9781097917
}
9781197918
return 0;
9781297919
}
97920
+
97921
+/*
97922
+** Return true if the parser passed as the first argument is being
97923
+** used to code a trigger that is really a "SET NULL" action belonging
97924
+** to trigger pFKey.
97925
+*/
97926
+static int isSetNullAction(Parse *pParse, FKey *pFKey){
97927
+ Parse *pTop = sqlite3ParseToplevel(pParse);
97928
+ if( pTop->pTriggerPrg ){
97929
+ Trigger *p = pTop->pTriggerPrg->pTrigger;
97930
+ if( (p==pFKey->apTrigger[0] && pFKey->aAction[0]==OE_SetNull)
97931
+ || (p==pFKey->apTrigger[1] && pFKey->aAction[1]==OE_SetNull)
97932
+ ){
97933
+ return 1;
97934
+ }
97935
+ }
97936
+ return 0;
97937
+}
9781397938
9781497939
/*
9781597940
** This function is called when inserting, deleting or updating a row of
9781697941
** table pTab to generate VDBE code to perform foreign key constraint
9781797942
** processing for the operation.
@@ -97861,11 +97986,11 @@
9786197986
Index *pIdx = 0; /* Index on key columns in pTo */
9786297987
int *aiFree = 0;
9786397988
int *aiCol;
9786497989
int iCol;
9786597990
int i;
97866
- int isIgnore = 0;
97991
+ int bIgnore = 0;
9786797992
9786897993
if( aChange
9786997994
&& sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
9787097995
&& fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
9787197996
){
@@ -97920,11 +98045,11 @@
9792098045
** values read from the parent table are NULL. */
9792198046
if( db->xAuth ){
9792298047
int rcauth;
9792398048
char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName;
9792498049
rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb);
97925
- isIgnore = (rcauth==SQLITE_IGNORE);
98050
+ bIgnore = (rcauth==SQLITE_IGNORE);
9792698051
}
9792798052
#endif
9792898053
}
9792998054
9793098055
/* Take a shared-cache advisory read-lock on the parent table. Allocate
@@ -97935,16 +98060,22 @@
9793598060
9793698061
if( regOld!=0 ){
9793798062
/* A row is being removed from the child table. Search for the parent.
9793898063
** If the parent does not exist, removing the child row resolves an
9793998064
** outstanding foreign key constraint violation. */
97940
- fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1,isIgnore);
98065
+ fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1, bIgnore);
9794198066
}
97942
- if( regNew!=0 ){
98067
+ if( regNew!=0 && !isSetNullAction(pParse, pFKey) ){
9794398068
/* A row is being added to the child table. If a parent row cannot
97944
- ** be found, adding the child row has violated the FK constraint. */
97945
- fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1,isIgnore);
98069
+ ** be found, adding the child row has violated the FK constraint.
98070
+ **
98071
+ ** If this operation is being performed as part of a trigger program
98072
+ ** that is actually a "SET NULL" action belonging to this very
98073
+ ** foreign key, then omit this scan altogether. As all child key
98074
+ ** values are guaranteed to be NULL, it is not possible for adding
98075
+ ** this row to cause an FK violation. */
98076
+ fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1, bIgnore);
9794698077
}
9794798078
9794898079
sqlite3DbFree(db, aiFree);
9794998080
}
9795098081
@@ -97961,12 +98092,12 @@
9796198092
9796298093
if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
9796398094
&& !pParse->pToplevel && !pParse->isMultiWrite
9796498095
){
9796598096
assert( regOld==0 && regNew!=0 );
97966
- /* Inserting a single row into a parent table cannot cause an immediate
97967
- ** foreign key violation. So do nothing in this case. */
98097
+ /* Inserting a single row into a parent table cannot cause (or fix)
98098
+ ** an immediate foreign key violation. So do nothing in this case. */
9796898099
continue;
9796998100
}
9797098101
9797198102
if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ){
9797298103
if( !isIgnoreErrors || db->mallocFailed ) return;
@@ -97986,17 +98117,32 @@
9798698117
9798798118
if( regNew!=0 ){
9798898119
fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1);
9798998120
}
9799098121
if( regOld!=0 ){
97991
- /* If there is a RESTRICT action configured for the current operation
97992
- ** on the parent table of this FK, then throw an exception
97993
- ** immediately if the FK constraint is violated, even if this is a
97994
- ** deferred trigger. That's what RESTRICT means. To defer checking
97995
- ** the constraint, the FK should specify NO ACTION (represented
97996
- ** using OE_None). NO ACTION is the default. */
98122
+ int eAction = pFKey->aAction[aChange!=0];
9799798123
fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regOld, 1);
98124
+ /* If this is a deferred FK constraint, or a CASCADE or SET NULL
98125
+ ** action applies, then any foreign key violations caused by
98126
+ ** removing the parent key will be rectified by the action trigger.
98127
+ ** So do not set the "may-abort" flag in this case.
98128
+ **
98129
+ ** Note 1: If the FK is declared "ON UPDATE CASCADE", then the
98130
+ ** may-abort flag will eventually be set on this statement anyway
98131
+ ** (when this function is called as part of processing the UPDATE
98132
+ ** within the action trigger).
98133
+ **
98134
+ ** Note 2: At first glance it may seem like SQLite could simply omit
98135
+ ** all OP_FkCounter related scans when either CASCADE or SET NULL
98136
+ ** applies. The trouble starts if the CASCADE or SET NULL action
98137
+ ** trigger causes other triggers or action rules attached to the
98138
+ ** child table to fire. In these cases the fk constraint counters
98139
+ ** might be set incorrectly if any OP_FkCounter related scans are
98140
+ ** omitted. */
98141
+ if( !pFKey->isDeferred && eAction!=OE_Cascade && eAction!=OE_SetNull ){
98142
+ sqlite3MayAbort(pParse);
98143
+ }
9799898144
}
9799998145
pItem->zName = 0;
9800098146
sqlite3SrcListDelete(db, pSrc);
9800198147
}
9800298148
sqlite3DbFree(db, aiCol);
@@ -101895,10 +102041,11 @@
101895102041
#define PragTyp_KEY 38
101896102042
#define PragTyp_REKEY 39
101897102043
#define PragTyp_LOCK_STATUS 40
101898102044
#define PragTyp_PARSER_TRACE 41
101899102045
#define PragFlag_NeedSchema 0x01
102046
+#define PragFlag_ReadOnly 0x02
101900102047
static const struct sPragmaNames {
101901102048
const char *const zName; /* Name of pragma */
101902102049
u8 ePragTyp; /* PragTyp_XXX value */
101903102050
u8 mPragFlag; /* Zero or more PragFlag_XXX values */
101904102051
u32 iArg; /* Extra argument */
@@ -101911,11 +102058,11 @@
101911102058
#endif
101912102059
#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
101913102060
{ /* zName: */ "application_id",
101914102061
/* ePragTyp: */ PragTyp_HEADER_VALUE,
101915102062
/* ePragFlag: */ 0,
101916
- /* iArg: */ 0 },
102063
+ /* iArg: */ BTREE_APPLICATION_ID },
101917102064
#endif
101918102065
#if !defined(SQLITE_OMIT_AUTOVACUUM)
101919102066
{ /* zName: */ "auto_vacuum",
101920102067
/* ePragTyp: */ PragTyp_AUTO_VACUUM,
101921102068
/* ePragFlag: */ PragFlag_NeedSchema,
@@ -101977,10 +102124,16 @@
101977102124
{ /* zName: */ "data_store_directory",
101978102125
/* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
101979102126
/* ePragFlag: */ 0,
101980102127
/* iArg: */ 0 },
101981102128
#endif
102129
+#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102130
+ { /* zName: */ "data_version",
102131
+ /* ePragTyp: */ PragTyp_HEADER_VALUE,
102132
+ /* ePragFlag: */ PragFlag_ReadOnly,
102133
+ /* iArg: */ BTREE_DATA_VERSION },
102134
+#endif
101982102135
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
101983102136
{ /* zName: */ "database_list",
101984102137
/* ePragTyp: */ PragTyp_DATABASE_LIST,
101985102138
/* ePragFlag: */ PragFlag_NeedSchema,
101986102139
/* iArg: */ 0 },
@@ -102032,12 +102185,12 @@
102032102185
#endif
102033102186
#endif
102034102187
#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102035102188
{ /* zName: */ "freelist_count",
102036102189
/* ePragTyp: */ PragTyp_HEADER_VALUE,
102037
- /* ePragFlag: */ 0,
102038
- /* iArg: */ 0 },
102190
+ /* ePragFlag: */ PragFlag_ReadOnly,
102191
+ /* iArg: */ BTREE_FREE_PAGE_COUNT },
102039102192
#endif
102040102193
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
102041102194
{ /* zName: */ "full_column_names",
102042102195
/* ePragTyp: */ PragTyp_FLAG,
102043102196
/* ePragFlag: */ 0,
@@ -102185,11 +102338,11 @@
102185102338
#endif
102186102339
#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102187102340
{ /* zName: */ "schema_version",
102188102341
/* ePragTyp: */ PragTyp_HEADER_VALUE,
102189102342
/* ePragFlag: */ 0,
102190
- /* iArg: */ 0 },
102343
+ /* iArg: */ BTREE_SCHEMA_VERSION },
102191102344
#endif
102192102345
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
102193102346
{ /* zName: */ "secure_delete",
102194102347
/* ePragTyp: */ PragTyp_SECURE_DELETE,
102195102348
/* ePragFlag: */ 0,
@@ -102251,11 +102404,11 @@
102251102404
/* iArg: */ 0 },
102252102405
#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102253102406
{ /* zName: */ "user_version",
102254102407
/* ePragTyp: */ PragTyp_HEADER_VALUE,
102255102408
/* ePragFlag: */ 0,
102256
- /* iArg: */ 0 },
102409
+ /* iArg: */ BTREE_USER_VERSION },
102257102410
#endif
102258102411
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
102259102412
#if defined(SQLITE_DEBUG)
102260102413
{ /* zName: */ "vdbe_addoptrace",
102261102414
/* ePragTyp: */ PragTyp_FLAG,
@@ -102294,11 +102447,11 @@
102294102447
/* ePragTyp: */ PragTyp_FLAG,
102295102448
/* ePragFlag: */ 0,
102296102449
/* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
102297102450
#endif
102298102451
};
102299
-/* Number of pragmas: 57 on by default, 70 total. */
102452
+/* Number of pragmas: 58 on by default, 71 total. */
102300102453
/* End of the automatically generated pragma table.
102301102454
***************************************************************************/
102302102455
102303102456
/*
102304102457
** Interpret the given string as a safety level. Return 0 for OFF,
@@ -102544,11 +102697,11 @@
102544102697
char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
102545102698
const char *zDb = 0; /* The database name */
102546102699
Token *pId; /* Pointer to <id> token */
102547102700
char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */
102548102701
int iDb; /* Database index for <database> */
102549
- int lwr, upr, mid; /* Binary search bounds */
102702
+ int lwr, upr, mid = 0; /* Binary search bounds */
102550102703
int rc; /* return value form SQLITE_FCNTL_PRAGMA */
102551102704
sqlite3 *db = pParse->db; /* The database connection */
102552102705
Db *pDb; /* The specific database being pragmaed */
102553102706
Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
102554102707
@@ -103904,11 +104057,12 @@
103904104057
!(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
103905104058
DbHasProperty(db, 0, DB_Empty)
103906104059
){
103907104060
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
103908104061
if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
103909
- ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
104062
+ SCHEMA_ENC(db) = ENC(db) =
104063
+ pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
103910104064
break;
103911104065
}
103912104066
}
103913104067
if( !pEnc->zName ){
103914104068
sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
@@ -103949,28 +104103,13 @@
103949104103
**
103950104104
** The user-version is not used internally by SQLite. It may be used by
103951104105
** applications for any purpose.
103952104106
*/
103953104107
case PragTyp_HEADER_VALUE: {
103954
- int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
104108
+ int iCookie = aPragmaNames[mid].iArg; /* Which cookie to read or write */
103955104109
sqlite3VdbeUsesBtree(v, iDb);
103956
- switch( zLeft[0] ){
103957
- case 'a': case 'A':
103958
- iCookie = BTREE_APPLICATION_ID;
103959
- break;
103960
- case 'f': case 'F':
103961
- iCookie = BTREE_FREE_PAGE_COUNT;
103962
- break;
103963
- case 's': case 'S':
103964
- iCookie = BTREE_SCHEMA_VERSION;
103965
- break;
103966
- default:
103967
- iCookie = BTREE_USER_VERSION;
103968
- break;
103969
- }
103970
-
103971
- if( zRight && iCookie!=BTREE_FREE_PAGE_COUNT ){
104110
+ if( zRight && (aPragmaNames[mid].mPragFlag & PragFlag_ReadOnly)==0 ){
103972104111
/* Write the specified cookie value */
103973104112
static const VdbeOpList setCookie[] = {
103974104113
{ OP_Transaction, 0, 1, 0}, /* 0 */
103975104114
{ OP_Integer, 0, 1, 0}, /* 1 */
103976104115
{ OP_SetCookie, 0, 0, 1}, /* 2 */
@@ -104612,13 +104751,15 @@
104612104751
SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
104613104752
int i, rc;
104614104753
int commit_internal = !(db->flags&SQLITE_InternChanges);
104615104754
104616104755
assert( sqlite3_mutex_held(db->mutex) );
104756
+ assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
104617104757
assert( db->init.busy==0 );
104618104758
rc = SQLITE_OK;
104619104759
db->init.busy = 1;
104760
+ ENC(db) = SCHEMA_ENC(db);
104620104761
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
104621104762
if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
104622104763
rc = sqlite3InitOne(db, i, pzErrMsg);
104623104764
if( rc ){
104624104765
sqlite3ResetOneSchema(db, i);
@@ -105169,24 +105310,29 @@
105169105310
u8 sortFlags; /* Zero or more SORTFLAG_* bits */
105170105311
};
105171105312
#define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
105172105313
105173105314
/*
105174
-** Delete all the content of a Select structure but do not deallocate
105175
-** the select structure itself.
105315
+** Delete all the content of a Select structure. Deallocate the structure
105316
+** itself only if bFree is true.
105176105317
*/
105177
-static void clearSelect(sqlite3 *db, Select *p){
105178
- sqlite3ExprListDelete(db, p->pEList);
105179
- sqlite3SrcListDelete(db, p->pSrc);
105180
- sqlite3ExprDelete(db, p->pWhere);
105181
- sqlite3ExprListDelete(db, p->pGroupBy);
105182
- sqlite3ExprDelete(db, p->pHaving);
105183
- sqlite3ExprListDelete(db, p->pOrderBy);
105184
- sqlite3SelectDelete(db, p->pPrior);
105185
- sqlite3ExprDelete(db, p->pLimit);
105186
- sqlite3ExprDelete(db, p->pOffset);
105187
- sqlite3WithDelete(db, p->pWith);
105318
+static void clearSelect(sqlite3 *db, Select *p, int bFree){
105319
+ while( p ){
105320
+ Select *pPrior = p->pPrior;
105321
+ sqlite3ExprListDelete(db, p->pEList);
105322
+ sqlite3SrcListDelete(db, p->pSrc);
105323
+ sqlite3ExprDelete(db, p->pWhere);
105324
+ sqlite3ExprListDelete(db, p->pGroupBy);
105325
+ sqlite3ExprDelete(db, p->pHaving);
105326
+ sqlite3ExprListDelete(db, p->pOrderBy);
105327
+ sqlite3ExprDelete(db, p->pLimit);
105328
+ sqlite3ExprDelete(db, p->pOffset);
105329
+ sqlite3WithDelete(db, p->pWith);
105330
+ if( bFree ) sqlite3DbFree(db, p);
105331
+ p = pPrior;
105332
+ bFree = 1;
105333
+ }
105188105334
}
105189105335
105190105336
/*
105191105337
** Initialize a SelectDest structure.
105192105338
*/
@@ -105241,12 +105387,11 @@
105241105387
pNew->pOffset = pOffset;
105242105388
assert( pOffset==0 || pLimit!=0 );
105243105389
pNew->addrOpenEphm[0] = -1;
105244105390
pNew->addrOpenEphm[1] = -1;
105245105391
if( db->mallocFailed ) {
105246
- clearSelect(db, pNew);
105247
- if( pNew!=&standin ) sqlite3DbFree(db, pNew);
105392
+ clearSelect(db, pNew, pNew!=&standin);
105248105393
pNew = 0;
105249105394
}else{
105250105395
assert( pNew->pSrc!=0 || pParse->nErr>0 );
105251105396
}
105252105397
assert( pNew!=&standin );
@@ -105267,14 +105412,11 @@
105267105412
105268105413
/*
105269105414
** Delete the given Select structure and all of its substructures.
105270105415
*/
105271105416
SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
105272
- if( p ){
105273
- clearSelect(db, p);
105274
- sqlite3DbFree(db, p);
105275
- }
105417
+ clearSelect(db, p, 1);
105276105418
}
105277105419
105278105420
/*
105279105421
** Return a pointer to the right-most SELECT statement in a compound.
105280105422
*/
@@ -107186,10 +107328,70 @@
107186107328
Parse *pParse, /* Parsing context */
107187107329
Select *p, /* The right-most of SELECTs to be coded */
107188107330
SelectDest *pDest /* What to do with query results */
107189107331
);
107190107332
107333
+/*
107334
+** Error message for when two or more terms of a compound select have different
107335
+** size result sets.
107336
+*/
107337
+static void selectWrongNumTermsError(Parse *pParse, Select *p){
107338
+ if( p->selFlags & SF_Values ){
107339
+ sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
107340
+ }else{
107341
+ sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
107342
+ " do not have the same number of result columns", selectOpName(p->op));
107343
+ }
107344
+}
107345
+
107346
+/*
107347
+** Handle the special case of a compound-select that originates from a
107348
+** VALUES clause. By handling this as a special case, we avoid deep
107349
+** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
107350
+** on a VALUES clause.
107351
+**
107352
+** Because the Select object originates from a VALUES clause:
107353
+** (1) It has no LIMIT or OFFSET
107354
+** (2) All terms are UNION ALL
107355
+** (3) There is no ORDER BY clause
107356
+*/
107357
+static int multiSelectValues(
107358
+ Parse *pParse, /* Parsing context */
107359
+ Select *p, /* The right-most of SELECTs to be coded */
107360
+ SelectDest *pDest /* What to do with query results */
107361
+){
107362
+ Select *pPrior;
107363
+ int nExpr = p->pEList->nExpr;
107364
+ int nRow = 1;
107365
+ int rc = 0;
107366
+ assert( p->pNext==0 );
107367
+ assert( p->selFlags & SF_AllValues );
107368
+ do{
107369
+ assert( p->selFlags & SF_Values );
107370
+ assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
107371
+ assert( p->pLimit==0 );
107372
+ assert( p->pOffset==0 );
107373
+ if( p->pEList->nExpr!=nExpr ){
107374
+ selectWrongNumTermsError(pParse, p);
107375
+ return 1;
107376
+ }
107377
+ if( p->pPrior==0 ) break;
107378
+ assert( p->pPrior->pNext==p );
107379
+ p = p->pPrior;
107380
+ nRow++;
107381
+ }while(1);
107382
+ while( p ){
107383
+ pPrior = p->pPrior;
107384
+ p->pPrior = 0;
107385
+ rc = sqlite3Select(pParse, p, pDest);
107386
+ p->pPrior = pPrior;
107387
+ if( rc ) break;
107388
+ p->nSelectRow = nRow;
107389
+ p = p->pNext;
107390
+ }
107391
+ return rc;
107392
+}
107191107393
107192107394
/*
107193107395
** This routine is called to process a compound query form from
107194107396
** two or more separate queries using UNION, UNION ALL, EXCEPT, or
107195107397
** INTERSECT
@@ -107266,22 +107468,24 @@
107266107468
assert( p->pEList );
107267107469
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, dest.iSDParm, p->pEList->nExpr);
107268107470
sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
107269107471
dest.eDest = SRT_Table;
107270107472
}
107473
+
107474
+ /* Special handling for a compound-select that originates as a VALUES clause.
107475
+ */
107476
+ if( p->selFlags & SF_AllValues ){
107477
+ rc = multiSelectValues(pParse, p, &dest);
107478
+ goto multi_select_end;
107479
+ }
107271107480
107272107481
/* Make sure all SELECTs in the statement have the same number of elements
107273107482
** in their result sets.
107274107483
*/
107275107484
assert( p->pEList && pPrior->pEList );
107276107485
if( p->pEList->nExpr!=pPrior->pEList->nExpr ){
107277
- if( p->selFlags & SF_Values ){
107278
- sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
107279
- }else{
107280
- sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
107281
- " do not have the same number of result columns", selectOpName(p->op));
107282
- }
107486
+ selectWrongNumTermsError(pParse, p);
107283107487
rc = 1;
107284107488
goto multi_select_end;
107285107489
}
107286107490
107287107491
#ifndef SQLITE_OMIT_CTE
@@ -109163,11 +109367,13 @@
109163109367
if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
109164109368
return WRC_Prune;
109165109369
}
109166109370
pTabList = p->pSrc;
109167109371
pEList = p->pEList;
109168
- sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
109372
+ if( pWalker->xSelectCallback2==selectPopWith ){
109373
+ sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
109374
+ }
109169109375
109170109376
/* Make sure cursor numbers have been assigned to all entries in
109171109377
** the FROM clause of the SELECT statement.
109172109378
*/
109173109379
sqlite3SrcListAssignCursors(pParse, pTabList);
@@ -109454,11 +109660,13 @@
109454109660
if( pParse->hasCompound ){
109455109661
w.xSelectCallback = convertCompoundSelectToSubquery;
109456109662
sqlite3WalkSelect(&w, pSelect);
109457109663
}
109458109664
w.xSelectCallback = selectExpander;
109459
- w.xSelectCallback2 = selectPopWith;
109665
+ if( (pSelect->selFlags & SF_AllValues)==0 ){
109666
+ w.xSelectCallback2 = selectPopWith;
109667
+ }
109460109668
sqlite3WalkSelect(&w, pSelect);
109461109669
}
109462109670
109463109671
109464109672
#ifndef SQLITE_OMIT_SUBQUERY
@@ -110756,11 +110964,11 @@
110756110964
){
110757110965
int rc;
110758110966
TabResult res;
110759110967
110760110968
#ifdef SQLITE_ENABLE_API_ARMOR
110761
- if( pazResult==0 ) return SQLITE_MISUSE_BKPT;
110969
+ if( !sqlite3SafetyCheckOk(db) || pazResult==0 ) return SQLITE_MISUSE_BKPT;
110762110970
#endif
110763110971
*pazResult = 0;
110764110972
if( pnColumn ) *pnColumn = 0;
110765110973
if( pnRow ) *pnRow = 0;
110766110974
if( pzErrMsg ) *pzErrMsg = 0;
@@ -118626,11 +118834,10 @@
118626118834
sqlite3_free(p->u.vtab.idxStr);
118627118835
p->u.vtab.needFree = 0;
118628118836
p->u.vtab.idxStr = 0;
118629118837
}else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
118630118838
sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
118631
- sqlite3KeyInfoUnref(p->u.btree.pIndex->pKeyInfo);
118632118839
sqlite3DbFree(db, p->u.btree.pIndex);
118633118840
p->u.btree.pIndex = 0;
118634118841
}
118635118842
}
118636118843
}
@@ -123783,17 +123990,23 @@
123783123990
Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
123784123991
if( p ){
123785123992
int cnt = 0, mxSelect;
123786123993
p->pWith = yymsp[-1].minor.yy59;
123787123994
if( p->pPrior ){
123995
+ u16 allValues = SF_Values;
123788123996
pNext = 0;
123789123997
for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
123790123998
pLoop->pNext = pNext;
123791123999
pLoop->selFlags |= SF_Compound;
124000
+ allValues &= pLoop->selFlags;
123792124001
}
123793
- mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
123794
- if( mxSelect && cnt>mxSelect ){
124002
+ if( allValues ){
124003
+ p->selFlags |= SF_AllValues;
124004
+ }else if(
124005
+ (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0
124006
+ && cnt>mxSelect
124007
+ ){
123795124008
sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
123796124009
}
123797124010
}
123798124011
}else{
123799124012
sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
@@ -125633,10 +125846,13 @@
125633125846
u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
125634125847
sqlite3 *db = pParse->db; /* The database connection */
125635125848
int mxSqlLen; /* Max length of an SQL string */
125636125849
125637125850
125851
+#ifdef SQLITE_ENABLE_API_ARMOR
125852
+ if( zSql==0 || pzErrMsg==0 ) return SQLITE_MISUSE_BKPT;
125853
+#endif
125638125854
mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
125639125855
if( db->nVdbeActive==0 ){
125640125856
db->u1.isInterrupted = 0;
125641125857
}
125642125858
pParse->rc = SQLITE_OK;
@@ -125871,17 +126087,10 @@
125871126087
*/
125872126088
SQLITE_API int sqlite3_complete(const char *zSql){
125873126089
u8 state = 0; /* Current state, using numbers defined in header comment */
125874126090
u8 token; /* Value of the next token */
125875126091
125876
-#ifdef SQLITE_ENABLE_API_ARMOR
125877
- if( zSql==0 ){
125878
- (void)SQLITE_MISUSE_BKPT;
125879
- return 0;
125880
- }
125881
-#endif
125882
-
125883126092
#ifndef SQLITE_OMIT_TRIGGER
125884126093
/* A complex statement machine used to detect the end of a CREATE TRIGGER
125885126094
** statement. This is the normal case.
125886126095
*/
125887126096
static const u8 trans[8][8] = {
@@ -125906,10 +126115,17 @@
125906126115
/* 0 INVALID: */ { 1, 0, 2, },
125907126116
/* 1 START: */ { 1, 1, 2, },
125908126117
/* 2 NORMAL: */ { 1, 2, 2, },
125909126118
};
125910126119
#endif /* SQLITE_OMIT_TRIGGER */
126120
+
126121
+#ifdef SQLITE_ENABLE_API_ARMOR
126122
+ if( zSql==0 ){
126123
+ (void)SQLITE_MISUSE_BKPT;
126124
+ return 0;
126125
+ }
126126
+#endif
125911126127
125912126128
while( *zSql ){
125913126129
switch( *zSql ){
125914126130
case ';': { /* A semicolon */
125915126131
token = tkSEMI;
@@ -126208,11 +126424,11 @@
126208126424
** If the following function pointer is not NULL and if
126209126425
** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
126210126426
** I/O active are written using this function. These messages
126211126427
** are intended for debugging activity only.
126212126428
*/
126213
-SQLITE_PRIVATE void (*sqlite3IoTrace)(const char*, ...) = 0;
126429
+/* not-private */ void (*sqlite3IoTrace)(const char*, ...) = 0;
126214126430
#endif
126215126431
126216126432
/*
126217126433
** If the following global variable points to a string which is the
126218126434
** name of a directory, then that directory will be used to store
@@ -126417,10 +126633,17 @@
126417126633
** routine is not threadsafe. But it is safe to invoke this routine
126418126634
** on when SQLite is already shut down. If SQLite is already shut down
126419126635
** when this routine is invoked, then this routine is a harmless no-op.
126420126636
*/
126421126637
SQLITE_API int sqlite3_shutdown(void){
126638
+#ifdef SQLITE_OMIT_WSD
126639
+ int rc = sqlite3_wsd_init(4096, 24);
126640
+ if( rc!=SQLITE_OK ){
126641
+ return rc;
126642
+ }
126643
+#endif
126644
+
126422126645
if( sqlite3GlobalConfig.isInit ){
126423126646
#ifdef SQLITE_EXTRA_SHUTDOWN
126424126647
void SQLITE_EXTRA_SHUTDOWN(void);
126425126648
SQLITE_EXTRA_SHUTDOWN();
126426126649
#endif
@@ -126732,10 +126955,15 @@
126732126955
** heap. */
126733126956
sqlite3GlobalConfig.nHeap = va_arg(ap, int);
126734126957
break;
126735126958
}
126736126959
#endif
126960
+
126961
+ case SQLITE_CONFIG_PMASZ: {
126962
+ sqlite3GlobalConfig.szPma = va_arg(ap, unsigned int);
126963
+ break;
126964
+ }
126737126965
126738126966
default: {
126739126967
rc = SQLITE_ERROR;
126740126968
break;
126741126969
}
@@ -127178,20 +127406,10 @@
127178127406
127179127407
/* Close all database connections */
127180127408
for(j=0; j<db->nDb; j++){
127181127409
struct Db *pDb = &db->aDb[j];
127182127410
if( pDb->pBt ){
127183
- if( pDb->pSchema ){
127184
- /* Must clear the KeyInfo cache. See ticket [e4a18565a36884b00edf] */
127185
- sqlite3BtreeEnter(pDb->pBt);
127186
- for(i=sqliteHashFirst(&pDb->pSchema->idxHash); i; i=sqliteHashNext(i)){
127187
- Index *pIdx = sqliteHashData(i);
127188
- sqlite3KeyInfoUnref(pIdx->pKeyInfo);
127189
- pIdx->pKeyInfo = 0;
127190
- }
127191
- sqlite3BtreeLeave(pDb->pBt);
127192
- }
127193127411
sqlite3BtreeClose(pDb->pBt);
127194127412
pDb->pBt = 0;
127195127413
if( j!=1 ){
127196127414
pDb->pSchema = 0;
127197127415
}
@@ -127494,11 +127712,11 @@
127494127712
*/
127495127713
static int sqliteDefaultBusyCallback(
127496127714
void *ptr, /* Database connection */
127497127715
int count /* Number of times table has been busy */
127498127716
){
127499
-#if SQLITE_OS_WIN || (defined(HAVE_USLEEP) && HAVE_USLEEP)
127717
+#if SQLITE_OS_WIN || HAVE_USLEEP
127500127718
static const u8 delays[] =
127501127719
{ 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 };
127502127720
static const u8 totals[] =
127503127721
{ 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
127504127722
# define NDELAY ArraySize(delays)
@@ -128315,36 +128533,10 @@
128315128533
*/
128316128534
SQLITE_API const char *sqlite3_errstr(int rc){
128317128535
return sqlite3ErrStr(rc);
128318128536
}
128319128537
128320
-/*
128321
-** Invalidate all cached KeyInfo objects for database connection "db"
128322
-*/
128323
-static void invalidateCachedKeyInfo(sqlite3 *db){
128324
- Db *pDb; /* A single database */
128325
- int iDb; /* The database index number */
128326
- HashElem *k; /* For looping over tables in pDb */
128327
- Table *pTab; /* A table in the database */
128328
- Index *pIdx; /* Each index */
128329
-
128330
- for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
128331
- if( pDb->pBt==0 ) continue;
128332
- sqlite3BtreeEnter(pDb->pBt);
128333
- for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){
128334
- pTab = (Table*)sqliteHashData(k);
128335
- for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
128336
- if( pIdx->pKeyInfo && pIdx->pKeyInfo->db==db ){
128337
- sqlite3KeyInfoUnref(pIdx->pKeyInfo);
128338
- pIdx->pKeyInfo = 0;
128339
- }
128340
- }
128341
- }
128342
- sqlite3BtreeLeave(pDb->pBt);
128343
- }
128344
-}
128345
-
128346128538
/*
128347128539
** Create a new collating function for database "db". The name is zName
128348128540
** and the encoding is enc.
128349128541
*/
128350128542
static int createCollation(
@@ -128384,11 +128576,10 @@
128384128576
sqlite3ErrorWithMsg(db, SQLITE_BUSY,
128385128577
"unable to delete/modify collation sequence due to active statements");
128386128578
return SQLITE_BUSY;
128387128579
}
128388128580
sqlite3ExpirePreparedStatements(db);
128389
- invalidateCachedKeyInfo(db);
128390128581
128391128582
/* If collation sequence pColl was created directly by a call to
128392128583
** sqlite3_create_collation, and not generated by synthCollSeq(),
128393128584
** then any copies made by synthCollSeq() need to be invalidated.
128394128585
** Also, collation destructor - CollSeq.xDel() - function may need
@@ -128941,10 +129132,11 @@
128941129132
sqlite3Error(db, rc);
128942129133
goto opendb_out;
128943129134
}
128944129135
sqlite3BtreeEnter(db->aDb[0].pBt);
128945129136
db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
129137
+ if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db);
128946129138
sqlite3BtreeLeave(db->aDb[0].pBt);
128947129139
db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
128948129140
128949129141
/* The default safety_level for the main database is 'full'; for the temp
128950129142
** database it is 'NONE'. This matches the pager layer defaults.
@@ -129099,11 +129291,11 @@
129099129291
if( zFilename8 ){
129100129292
rc = openDatabase(zFilename8, ppDb,
129101129293
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
129102129294
assert( *ppDb || rc==SQLITE_NOMEM );
129103129295
if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){
129104
- ENC(*ppDb) = SQLITE_UTF16NATIVE;
129296
+ SCHEMA_ENC(*ppDb) = ENC(*ppDb) = SQLITE_UTF16NATIVE;
129105129297
}
129106129298
}else{
129107129299
rc = SQLITE_NOMEM;
129108129300
}
129109129301
sqlite3ValueFree(pVal);
@@ -129310,11 +129502,11 @@
129310129502
){
129311129503
int rc;
129312129504
char *zErrMsg = 0;
129313129505
Table *pTab = 0;
129314129506
Column *pCol = 0;
129315
- int iCol;
129507
+ int iCol = 0;
129316129508
129317129509
char const *zDataType = 0;
129318129510
char const *zCollSeq = 0;
129319129511
int notnull = 0;
129320129512
int primarykey = 0;
@@ -129841,32 +130033,34 @@
129841130033
/*
129842130034
** Return the filename of the database associated with a database
129843130035
** connection.
129844130036
*/
129845130037
SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
130038
+ Btree *pBt;
129846130039
#ifdef SQLITE_ENABLE_API_ARMOR
129847130040
if( !sqlite3SafetyCheckOk(db) ){
129848130041
(void)SQLITE_MISUSE_BKPT;
129849130042
return 0;
129850130043
}
129851130044
#endif
129852
- Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
130045
+ pBt = sqlite3DbNameToBtree(db, zDbName);
129853130046
return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
129854130047
}
129855130048
129856130049
/*
129857130050
** Return 1 if database is read-only or 0 if read/write. Return -1 if
129858130051
** no such database exists.
129859130052
*/
129860130053
SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
130054
+ Btree *pBt;
129861130055
#ifdef SQLITE_ENABLE_API_ARMOR
129862130056
if( !sqlite3SafetyCheckOk(db) ){
129863130057
(void)SQLITE_MISUSE_BKPT;
129864130058
return -1;
129865130059
}
129866130060
#endif
129867
- Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
130061
+ pBt = sqlite3DbNameToBtree(db, zDbName);
129868130062
return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
129869130063
}
129870130064
129871130065
/************** End of main.c ************************************************/
129872130066
/************** Begin file notify.c ******************************************/
@@ -132931,11 +133125,11 @@
132931133125
const char *zNode, /* Buffer containing segment interior node */
132932133126
int nNode, /* Size of buffer at zNode */
132933133127
sqlite3_int64 *piLeaf, /* Selected leaf node */
132934133128
sqlite3_int64 *piLeaf2 /* Selected leaf node */
132935133129
){
132936
- int rc; /* Return code */
133130
+ int rc = SQLITE_OK; /* Return code */
132937133131
int iHeight; /* Height of this node in tree */
132938133132
132939133133
assert( piLeaf || piLeaf2 );
132940133134
132941133135
fts3GetVarint32(zNode, &iHeight);
@@ -132942,11 +133136,11 @@
132942133136
rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
132943133137
assert( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
132944133138
132945133139
if( rc==SQLITE_OK && iHeight>1 ){
132946133140
char *zBlob = 0; /* Blob read from %_segments table */
132947
- int nBlob; /* Size of zBlob in bytes */
133141
+ int nBlob = 0; /* Size of zBlob in bytes */
132948133142
132949133143
if( piLeaf && piLeaf2 && (*piLeaf!=*piLeaf2) ){
132950133144
rc = sqlite3Fts3ReadBlock(p, *piLeaf, &zBlob, &nBlob, 0);
132951133145
if( rc==SQLITE_OK ){
132952133146
rc = fts3SelectLeaf(p, zTerm, nTerm, zBlob, nBlob, piLeaf, 0);
@@ -134164,11 +134358,11 @@
134164134358
int idxNum, /* Strategy index */
134165134359
const char *idxStr, /* Unused */
134166134360
int nVal, /* Number of elements in apVal */
134167134361
sqlite3_value **apVal /* Arguments for the indexing scheme */
134168134362
){
134169
- int rc;
134363
+ int rc = SQLITE_OK;
134170134364
char *zSql; /* SQL statement used to access %_content */
134171134365
int eSearch;
134172134366
Fts3Table *p = (Fts3Table *)pCursor->pVtab;
134173134367
Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
134174134368
@@ -140652,11 +140846,11 @@
140652140846
int argc, /* Number of elements in argv array */
140653140847
const char * const *argv, /* xCreate/xConnect argument array */
140654140848
sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */
140655140849
char **pzErr /* OUT: sqlite3_malloc'd error message */
140656140850
){
140657
- Fts3tokTable *pTab;
140851
+ Fts3tokTable *pTab = 0;
140658140852
const sqlite3_tokenizer_module *pMod = 0;
140659140853
sqlite3_tokenizer *pTok = 0;
140660140854
int rc;
140661140855
char **azDequote = 0;
140662140856
int nDequote;
@@ -144027,12 +144221,12 @@
144027144221
}
144028144222
rc = sqlite3_reset(pRange);
144029144223
144030144224
if( bOk ){
144031144225
int iIdx = 0;
144032
- sqlite3_stmt *pUpdate1;
144033
- sqlite3_stmt *pUpdate2;
144226
+ sqlite3_stmt *pUpdate1 = 0;
144227
+ sqlite3_stmt *pUpdate2 = 0;
144034144228
144035144229
if( rc==SQLITE_OK ){
144036144230
rc = fts3SqlStmt(p, SQL_UPDATE_LEVEL_IDX, &pUpdate1, 0);
144037144231
}
144038144232
if( rc==SQLITE_OK ){
@@ -150073,11 +150267,11 @@
150073150267
}
150074150268
i = pCur->nPoint++;
150075150269
pNew = pCur->aPoint + i;
150076150270
pNew->rScore = rScore;
150077150271
pNew->iLevel = iLevel;
150078
- assert( iLevel>=0 && iLevel<=RTREE_MAX_DEPTH );
150272
+ assert( iLevel<=RTREE_MAX_DEPTH );
150079150273
while( i>0 ){
150080150274
RtreeSearchPoint *pParent;
150081150275
j = (i-1)/2;
150082150276
pParent = pCur->aPoint + j;
150083150277
if( rtreeSearchPointCompare(pNew, pParent)>=0 ) break;
@@ -151696,10 +151890,12 @@
151696151890
RtreeCell cell; /* New cell to insert if nData>1 */
151697151891
int bHaveRowid = 0; /* Set to 1 after new rowid is determined */
151698151892
151699151893
rtreeReference(pRtree);
151700151894
assert(nData>=1);
151895
+
151896
+ cell.iRowid = 0; /* Used only to suppress a compiler warning */
151701151897
151702151898
/* Constraint handling. A write operation on an r-tree table may return
151703151899
** SQLITE_CONSTRAINT for two reasons:
151704151900
**
151705151901
** 1. A duplicate rowid value, or
151706151902
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -41,10 +41,57 @@
41 **
42 */
43 #ifndef _SQLITEINT_H_
44 #define _SQLITEINT_H_
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46 /*
47 ** These #defines should enable >2GB file support on POSIX if the
48 ** underlying operating system supports it. If the OS lacks
49 ** large file support, or if the OS is windows, these should be no-ops.
50 **
@@ -231,11 +278,11 @@
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-12-10 04:58:43 3528f8dd39acace8eeb7337994c8617313f4b04b"
237
238 /*
239 ** CAPI3REF: Run-Time Library Version Numbers
240 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
241 **
@@ -323,11 +370,11 @@
323 ** This interface only reports on the compile-time mutex setting
324 ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
325 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
326 ** can be fully or partially disabled using a call to [sqlite3_config()]
327 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
328 ** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the
329 ** sqlite3_threadsafe() function shows only the compile-time setting of
330 ** thread safety, not any run-time changes to that setting made by
331 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
332 ** is unchanged by calls to sqlite3_config().)^
333 **
@@ -1692,11 +1739,11 @@
1692 ** configuration option.
1693 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1694 ** 8-byte aligned
1695 ** memory, the size of each page buffer (sz), and the number of pages (N).
1696 ** The sz argument should be the size of the largest database page
1697 ** (a power of two between 512 and 32768) plus some extra bytes for each
1698 ** page header. ^The number of extra bytes needed by the page header
1699 ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1700 ** to [sqlite3_config()].
1701 ** ^It is harmless, apart from the wasted memory,
1702 ** for the sz parameter to be larger than necessary. The first
@@ -1872,10 +1919,21 @@
1872 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1873 ** is a pointer to an integer and writes into that integer the number of extra
1874 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
1875 ** The amount of extra space required can change depending on the compiler,
1876 ** target platform, and SQLite version.
 
 
 
 
 
 
 
 
 
 
 
1877 ** </dl>
1878 */
1879 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1880 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1881 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1898,10 +1956,11 @@
1898 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1899 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1900 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1901 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1902 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
 
1903
1904 /*
1905 ** CAPI3REF: Database Connection Configuration Options
1906 **
1907 ** These constants are the available integer configuration options that
@@ -7307,16 +7366,14 @@
7307
7308 /*
7309 ** CAPI3REF: Write-Ahead Log Commit Hook
7310 **
7311 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7312 ** will be invoked each time a database connection commits data to a
7313 ** [write-ahead log] (i.e. whenever a transaction is committed in
7314 ** [journal_mode | journal_mode=WAL mode]).
7315 **
7316 ** ^The callback is invoked by SQLite after the commit has taken place and
7317 ** the associated write-lock on the database released, so the implementation
7318 ** may read, write or [checkpoint] the database as required.
7319 **
7320 ** ^The first parameter passed to the callback function when it is invoked
7321 ** is a copy of the third parameter passed to sqlite3_wal_hook() when
7322 ** registering the callback. ^The second is a copy of the database handle.
@@ -7603,10 +7660,14 @@
7603 **
7604 ** The following constants can be used for the T parameter to the
7605 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7606 ** different metric for sqlite3_stmt_scanstatus() to return.
7607 **
 
 
 
 
7608 ** <dl>
7609 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7610 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
7611 ** set to the total number of times that the X-th loop has run.</dd>
7612 **
@@ -7648,11 +7709,18 @@
7648 #define SQLITE_SCANSTAT_SELECTID 5
7649
7650 /*
7651 ** CAPI3REF: Prepared Statement Scan Status
7652 **
7653 ** Return status data for a single loop within query pStmt.
 
 
 
 
 
 
 
7654 **
7655 ** The "iScanStatusOp" parameter determines which status information to return.
7656 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
7657 ** of this interface is undefined.
7658 ** ^The requested measurement is written into a variable pointed to by
@@ -7666,13 +7734,10 @@
7666 ** ^Statistics might not be available for all loops in all statements. ^In cases
7667 ** where there exist loops with no available statistics, this function behaves
7668 ** as if the loop did not exist - it returns non-zero and leave the variable
7669 ** that pOut points to unchanged.
7670 **
7671 ** This API is only available if the library is built with pre-processor
7672 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7673 **
7674 ** See also: [sqlite3_stmt_scanstatus_reset()]
7675 */
7676 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7677 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7678 int idx, /* Index of loop to report on */
@@ -9100,11 +9165,11 @@
9100 #define _BTREE_H_
9101
9102 /* TODO: This definition is just included so other modules compile. It
9103 ** needs to be revisited.
9104 */
9105 #define SQLITE_N_BTREE_META 10
9106
9107 /*
9108 ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
9109 ** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
9110 */
@@ -9215,10 +9280,15 @@
9215 ** offset = 36 + (idx * 4)
9216 **
9217 ** For example, the free-page-count field is located at byte offset 36 of
9218 ** the database file header. The incr-vacuum-flag field is located at
9219 ** byte offset 64 (== 36+4*7).
 
 
 
 
 
9220 */
9221 #define BTREE_FREE_PAGE_COUNT 0
9222 #define BTREE_SCHEMA_VERSION 1
9223 #define BTREE_FILE_FORMAT 2
9224 #define BTREE_DEFAULT_CACHE_SIZE 3
@@ -9225,10 +9295,11 @@
9225 #define BTREE_LARGEST_ROOT_PAGE 4
9226 #define BTREE_TEXT_ENCODING 5
9227 #define BTREE_USER_VERSION 6
9228 #define BTREE_INCR_VACUUM 7
9229 #define BTREE_APPLICATION_ID 8
 
9230
9231 /*
9232 ** Values that may be OR'd together to form the second argument of an
9233 ** sqlite3BtreeCursorHints() call.
9234 */
@@ -10006,10 +10077,11 @@
10006 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager);
10007 #endif
10008
10009 /* Functions used to query pager state and configuration. */
10010 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
 
10011 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
10012 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
10013 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int);
10014 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
10015 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
@@ -10747,10 +10819,11 @@
10747 i64 szMmap; /* Default mmap_size setting */
10748 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
10749 int errCode; /* Most recent error code (SQLITE_*) */
10750 int errMask; /* & result codes with this before returning */
10751 u16 dbOptFlags; /* Flags to enable/disable optimizations */
 
10752 u8 autoCommit; /* The auto-commit flag. */
10753 u8 temp_store; /* 1: file 2: memory 0: default */
10754 u8 mallocFailed; /* True if we have seen a malloc failure */
10755 u8 dfltLockMode; /* Default locking-mode for attached dbs */
10756 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
@@ -10848,11 +10921,12 @@
10848 };
10849
10850 /*
10851 ** A macro to discover the encoding of a database.
10852 */
10853 #define ENC(db) ((db)->aDb[0].pSchema->enc)
 
10854
10855 /*
10856 ** Possible values for the sqlite3.flags.
10857 */
10858 #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
@@ -11472,11 +11546,10 @@
11472 Index *pNext; /* The next index associated with the same table */
11473 Schema *pSchema; /* Schema containing this index */
11474 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
11475 char **azColl; /* Array of collation sequence names for index */
11476 Expr *pPartIdxWhere; /* WHERE clause for partial indices */
11477 KeyInfo *pKeyInfo; /* A KeyInfo object suitable for this index */
11478 int tnum; /* DB Page containing root of this index */
11479 LogEst szIdxRow; /* Estimated average row size in bytes */
11480 u16 nKeyCol; /* Number of columns forming the key */
11481 u16 nColumn; /* Number of columns stored in the index */
11482 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
@@ -12036,11 +12109,11 @@
12036 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
12037 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
12038 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
12039 #define SF_Compound 0x0040 /* Part of a compound query */
12040 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
12041 /* 0x0100 NOT USED */
12042 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
12043 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
12044 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
12045 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
12046
@@ -12526,10 +12599,11 @@
12526 void *pPage; /* Page cache memory */
12527 int szPage; /* Size of each page in pPage[] */
12528 int nPage; /* Number of pages in pPage[] */
12529 int mxParserStack; /* maximum depth of the parser stack */
12530 int sharedCacheEnabled; /* true if shared-cache mode enabled */
 
12531 /* The above might be initialized to non-zero. The following need to always
12532 ** initially be zero, however. */
12533 int isInit; /* True after initialization has finished */
12534 int inProgress; /* True while initialization in progress */
12535 int isMutexInit; /* True after mutexes are initialized */
@@ -12663,11 +12737,11 @@
12663 ** FTS4 is really an extension for FTS3. It is enabled using the
12664 ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call
12665 ** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3.
12666 */
12667 #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3)
12668 # define SQLITE_ENABLE_FTS3
12669 #endif
12670
12671 /*
12672 ** The ctype.h header is needed for non-ASCII systems. It is also
12673 ** needed by FTS3 when FTS3 is included in the amalgamation.
@@ -13448,11 +13522,11 @@
13448 ** print I/O tracing messages.
13449 */
13450 #ifdef SQLITE_ENABLE_IOTRACE
13451 # define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; }
13452 SQLITE_PRIVATE void sqlite3VdbeIOTraceSql(Vdbe*);
13453 SQLITE_PRIVATE void (*sqlite3IoTrace)(const char*,...);
13454 #else
13455 # define IOTRACE(A)
13456 # define sqlite3VdbeIOTraceSql(X)
13457 #endif
13458
@@ -13661,10 +13735,17 @@
13661 */
13662 #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
13663 # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
13664 #endif
13665
 
 
 
 
 
 
 
13666 /*
13667 ** The following singleton contains the global configuration for
13668 ** the SQLite library.
13669 */
13670 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
@@ -13691,10 +13772,11 @@
13691 (void*)0, /* pPage */
13692 0, /* szPage */
13693 0, /* nPage */
13694 0, /* mxParserStack */
13695 0, /* sharedCacheEnabled */
 
13696 /* All the rest should always be initialized to zero */
13697 0, /* isInit */
13698 0, /* inProgress */
13699 0, /* isMutexInit */
13700 0, /* isMallocInit */
@@ -13797,355 +13879,355 @@
13797 /* These macros are provided to "stringify" the value of the define
13798 ** for those options in which the value is meaningful. */
13799 #define CTIMEOPT_VAL_(opt) #opt
13800 #define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt)
13801
13802 #ifdef SQLITE_32BIT_ROWID
13803 "32BIT_ROWID",
13804 #endif
13805 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
13806 "4_BYTE_ALIGNED_MALLOC",
13807 #endif
13808 #ifdef SQLITE_CASE_SENSITIVE_LIKE
13809 "CASE_SENSITIVE_LIKE",
13810 #endif
13811 #ifdef SQLITE_CHECK_PAGES
13812 "CHECK_PAGES",
13813 #endif
13814 #ifdef SQLITE_COVERAGE_TEST
13815 "COVERAGE_TEST",
13816 #endif
13817 #ifdef SQLITE_DEBUG
13818 "DEBUG",
13819 #endif
13820 #ifdef SQLITE_DEFAULT_LOCKING_MODE
13821 "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
13822 #endif
13823 #if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc)
13824 "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
13825 #endif
13826 #ifdef SQLITE_DISABLE_DIRSYNC
13827 "DISABLE_DIRSYNC",
13828 #endif
13829 #ifdef SQLITE_DISABLE_LFS
13830 "DISABLE_LFS",
13831 #endif
13832 #ifdef SQLITE_ENABLE_API_ARMOR
13833 "ENABLE_API_ARMOR",
13834 #endif
13835 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
13836 "ENABLE_ATOMIC_WRITE",
13837 #endif
13838 #ifdef SQLITE_ENABLE_CEROD
13839 "ENABLE_CEROD",
13840 #endif
13841 #ifdef SQLITE_ENABLE_COLUMN_METADATA
13842 "ENABLE_COLUMN_METADATA",
13843 #endif
13844 #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
13845 "ENABLE_EXPENSIVE_ASSERT",
13846 #endif
13847 #ifdef SQLITE_ENABLE_FTS1
13848 "ENABLE_FTS1",
13849 #endif
13850 #ifdef SQLITE_ENABLE_FTS2
13851 "ENABLE_FTS2",
13852 #endif
13853 #ifdef SQLITE_ENABLE_FTS3
13854 "ENABLE_FTS3",
13855 #endif
13856 #ifdef SQLITE_ENABLE_FTS3_PARENTHESIS
13857 "ENABLE_FTS3_PARENTHESIS",
13858 #endif
13859 #ifdef SQLITE_ENABLE_FTS4
13860 "ENABLE_FTS4",
13861 #endif
13862 #ifdef SQLITE_ENABLE_ICU
13863 "ENABLE_ICU",
13864 #endif
13865 #ifdef SQLITE_ENABLE_IOTRACE
13866 "ENABLE_IOTRACE",
13867 #endif
13868 #ifdef SQLITE_ENABLE_LOAD_EXTENSION
13869 "ENABLE_LOAD_EXTENSION",
13870 #endif
13871 #ifdef SQLITE_ENABLE_LOCKING_STYLE
13872 "ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE),
13873 #endif
13874 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
13875 "ENABLE_MEMORY_MANAGEMENT",
13876 #endif
13877 #ifdef SQLITE_ENABLE_MEMSYS3
13878 "ENABLE_MEMSYS3",
13879 #endif
13880 #ifdef SQLITE_ENABLE_MEMSYS5
13881 "ENABLE_MEMSYS5",
13882 #endif
13883 #ifdef SQLITE_ENABLE_OVERSIZE_CELL_CHECK
13884 "ENABLE_OVERSIZE_CELL_CHECK",
13885 #endif
13886 #ifdef SQLITE_ENABLE_RTREE
13887 "ENABLE_RTREE",
13888 #endif
13889 #if defined(SQLITE_ENABLE_STAT4)
13890 "ENABLE_STAT4",
13891 #elif defined(SQLITE_ENABLE_STAT3)
13892 "ENABLE_STAT3",
13893 #endif
13894 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
13895 "ENABLE_UNLOCK_NOTIFY",
13896 #endif
13897 #ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
13898 "ENABLE_UPDATE_DELETE_LIMIT",
13899 #endif
13900 #ifdef SQLITE_HAS_CODEC
13901 "HAS_CODEC",
13902 #endif
13903 #ifdef SQLITE_HAVE_ISNAN
13904 "HAVE_ISNAN",
13905 #endif
13906 #ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
13907 "HOMEGROWN_RECURSIVE_MUTEX",
13908 #endif
13909 #ifdef SQLITE_IGNORE_AFP_LOCK_ERRORS
13910 "IGNORE_AFP_LOCK_ERRORS",
13911 #endif
13912 #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
13913 "IGNORE_FLOCK_LOCK_ERRORS",
13914 #endif
13915 #ifdef SQLITE_INT64_TYPE
13916 "INT64_TYPE",
13917 #endif
13918 #ifdef SQLITE_LOCK_TRACE
13919 "LOCK_TRACE",
13920 #endif
13921 #if defined(SQLITE_MAX_MMAP_SIZE) && !defined(SQLITE_MAX_MMAP_SIZE_xc)
13922 "MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE),
13923 #endif
13924 #ifdef SQLITE_MAX_SCHEMA_RETRY
13925 "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
13926 #endif
13927 #ifdef SQLITE_MEMDEBUG
13928 "MEMDEBUG",
13929 #endif
13930 #ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
13931 "MIXED_ENDIAN_64BIT_FLOAT",
13932 #endif
13933 #ifdef SQLITE_NO_SYNC
13934 "NO_SYNC",
13935 #endif
13936 #ifdef SQLITE_OMIT_ALTERTABLE
13937 "OMIT_ALTERTABLE",
13938 #endif
13939 #ifdef SQLITE_OMIT_ANALYZE
13940 "OMIT_ANALYZE",
13941 #endif
13942 #ifdef SQLITE_OMIT_ATTACH
13943 "OMIT_ATTACH",
13944 #endif
13945 #ifdef SQLITE_OMIT_AUTHORIZATION
13946 "OMIT_AUTHORIZATION",
13947 #endif
13948 #ifdef SQLITE_OMIT_AUTOINCREMENT
13949 "OMIT_AUTOINCREMENT",
13950 #endif
13951 #ifdef SQLITE_OMIT_AUTOINIT
13952 "OMIT_AUTOINIT",
13953 #endif
13954 #ifdef SQLITE_OMIT_AUTOMATIC_INDEX
13955 "OMIT_AUTOMATIC_INDEX",
13956 #endif
13957 #ifdef SQLITE_OMIT_AUTORESET
13958 "OMIT_AUTORESET",
13959 #endif
13960 #ifdef SQLITE_OMIT_AUTOVACUUM
13961 "OMIT_AUTOVACUUM",
13962 #endif
13963 #ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
13964 "OMIT_BETWEEN_OPTIMIZATION",
13965 #endif
13966 #ifdef SQLITE_OMIT_BLOB_LITERAL
13967 "OMIT_BLOB_LITERAL",
13968 #endif
13969 #ifdef SQLITE_OMIT_BTREECOUNT
13970 "OMIT_BTREECOUNT",
13971 #endif
13972 #ifdef SQLITE_OMIT_BUILTIN_TEST
13973 "OMIT_BUILTIN_TEST",
13974 #endif
13975 #ifdef SQLITE_OMIT_CAST
13976 "OMIT_CAST",
13977 #endif
13978 #ifdef SQLITE_OMIT_CHECK
13979 "OMIT_CHECK",
13980 #endif
13981 #ifdef SQLITE_OMIT_COMPLETE
13982 "OMIT_COMPLETE",
13983 #endif
13984 #ifdef SQLITE_OMIT_COMPOUND_SELECT
13985 "OMIT_COMPOUND_SELECT",
13986 #endif
13987 #ifdef SQLITE_OMIT_CTE
13988 "OMIT_CTE",
13989 #endif
13990 #ifdef SQLITE_OMIT_DATETIME_FUNCS
13991 "OMIT_DATETIME_FUNCS",
13992 #endif
13993 #ifdef SQLITE_OMIT_DECLTYPE
13994 "OMIT_DECLTYPE",
13995 #endif
13996 #ifdef SQLITE_OMIT_DEPRECATED
13997 "OMIT_DEPRECATED",
13998 #endif
13999 #ifdef SQLITE_OMIT_DISKIO
14000 "OMIT_DISKIO",
14001 #endif
14002 #ifdef SQLITE_OMIT_EXPLAIN
14003 "OMIT_EXPLAIN",
14004 #endif
14005 #ifdef SQLITE_OMIT_FLAG_PRAGMAS
14006 "OMIT_FLAG_PRAGMAS",
14007 #endif
14008 #ifdef SQLITE_OMIT_FLOATING_POINT
14009 "OMIT_FLOATING_POINT",
14010 #endif
14011 #ifdef SQLITE_OMIT_FOREIGN_KEY
14012 "OMIT_FOREIGN_KEY",
14013 #endif
14014 #ifdef SQLITE_OMIT_GET_TABLE
14015 "OMIT_GET_TABLE",
14016 #endif
14017 #ifdef SQLITE_OMIT_INCRBLOB
14018 "OMIT_INCRBLOB",
14019 #endif
14020 #ifdef SQLITE_OMIT_INTEGRITY_CHECK
14021 "OMIT_INTEGRITY_CHECK",
14022 #endif
14023 #ifdef SQLITE_OMIT_LIKE_OPTIMIZATION
14024 "OMIT_LIKE_OPTIMIZATION",
14025 #endif
14026 #ifdef SQLITE_OMIT_LOAD_EXTENSION
14027 "OMIT_LOAD_EXTENSION",
14028 #endif
14029 #ifdef SQLITE_OMIT_LOCALTIME
14030 "OMIT_LOCALTIME",
14031 #endif
14032 #ifdef SQLITE_OMIT_LOOKASIDE
14033 "OMIT_LOOKASIDE",
14034 #endif
14035 #ifdef SQLITE_OMIT_MEMORYDB
14036 "OMIT_MEMORYDB",
14037 #endif
14038 #ifdef SQLITE_OMIT_OR_OPTIMIZATION
14039 "OMIT_OR_OPTIMIZATION",
14040 #endif
14041 #ifdef SQLITE_OMIT_PAGER_PRAGMAS
14042 "OMIT_PAGER_PRAGMAS",
14043 #endif
14044 #ifdef SQLITE_OMIT_PRAGMA
14045 "OMIT_PRAGMA",
14046 #endif
14047 #ifdef SQLITE_OMIT_PROGRESS_CALLBACK
14048 "OMIT_PROGRESS_CALLBACK",
14049 #endif
14050 #ifdef SQLITE_OMIT_QUICKBALANCE
14051 "OMIT_QUICKBALANCE",
14052 #endif
14053 #ifdef SQLITE_OMIT_REINDEX
14054 "OMIT_REINDEX",
14055 #endif
14056 #ifdef SQLITE_OMIT_SCHEMA_PRAGMAS
14057 "OMIT_SCHEMA_PRAGMAS",
14058 #endif
14059 #ifdef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
14060 "OMIT_SCHEMA_VERSION_PRAGMAS",
14061 #endif
14062 #ifdef SQLITE_OMIT_SHARED_CACHE
14063 "OMIT_SHARED_CACHE",
14064 #endif
14065 #ifdef SQLITE_OMIT_SUBQUERY
14066 "OMIT_SUBQUERY",
14067 #endif
14068 #ifdef SQLITE_OMIT_TCL_VARIABLE
14069 "OMIT_TCL_VARIABLE",
14070 #endif
14071 #ifdef SQLITE_OMIT_TEMPDB
14072 "OMIT_TEMPDB",
14073 #endif
14074 #ifdef SQLITE_OMIT_TRACE
14075 "OMIT_TRACE",
14076 #endif
14077 #ifdef SQLITE_OMIT_TRIGGER
14078 "OMIT_TRIGGER",
14079 #endif
14080 #ifdef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
14081 "OMIT_TRUNCATE_OPTIMIZATION",
14082 #endif
14083 #ifdef SQLITE_OMIT_UTF16
14084 "OMIT_UTF16",
14085 #endif
14086 #ifdef SQLITE_OMIT_VACUUM
14087 "OMIT_VACUUM",
14088 #endif
14089 #ifdef SQLITE_OMIT_VIEW
14090 "OMIT_VIEW",
14091 #endif
14092 #ifdef SQLITE_OMIT_VIRTUALTABLE
14093 "OMIT_VIRTUALTABLE",
14094 #endif
14095 #ifdef SQLITE_OMIT_WAL
14096 "OMIT_WAL",
14097 #endif
14098 #ifdef SQLITE_OMIT_WSD
14099 "OMIT_WSD",
14100 #endif
14101 #ifdef SQLITE_OMIT_XFER_OPT
14102 "OMIT_XFER_OPT",
14103 #endif
14104 #ifdef SQLITE_PERFORMANCE_TRACE
14105 "PERFORMANCE_TRACE",
14106 #endif
14107 #ifdef SQLITE_PROXY_DEBUG
14108 "PROXY_DEBUG",
14109 #endif
14110 #ifdef SQLITE_RTREE_INT_ONLY
14111 "RTREE_INT_ONLY",
14112 #endif
14113 #ifdef SQLITE_SECURE_DELETE
14114 "SECURE_DELETE",
14115 #endif
14116 #ifdef SQLITE_SMALL_STACK
14117 "SMALL_STACK",
14118 #endif
14119 #ifdef SQLITE_SOUNDEX
14120 "SOUNDEX",
14121 #endif
14122 #ifdef SQLITE_SYSTEM_MALLOC
14123 "SYSTEM_MALLOC",
14124 #endif
14125 #ifdef SQLITE_TCL
14126 "TCL",
14127 #endif
14128 #if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc)
14129 "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
14130 #endif
14131 #ifdef SQLITE_TEST
14132 "TEST",
14133 #endif
14134 #if defined(SQLITE_THREADSAFE)
14135 "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
14136 #endif
14137 #ifdef SQLITE_USE_ALLOCA
14138 "USE_ALLOCA",
14139 #endif
14140 #ifdef SQLITE_USER_AUTHENTICATION
14141 "USER_AUTHENTICATION",
14142 #endif
14143 #ifdef SQLITE_WIN32_MALLOC
14144 "WIN32_MALLOC",
14145 #endif
14146 #ifdef SQLITE_ZERO_MALLOC
14147 "ZERO_MALLOC"
14148 #endif
14149 };
14150
14151 /*
@@ -14156,11 +14238,11 @@
14156 ** is not required for a match.
14157 */
14158 SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
14159 int i, n;
14160
14161 #ifdef SQLITE_ENABLE_API_ARMOR
14162 if( zOptName==0 ){
14163 (void)SQLITE_MISUSE_BKPT;
14164 return 0;
14165 }
14166 #endif
@@ -15384,12 +15466,13 @@
15384 **
15385 ** If the user has not indicated to use localtime_r() or localtime_s()
15386 ** already, check for an MSVC build environment that provides
15387 ** localtime_s().
15388 */
15389 #if !defined(HAVE_LOCALTIME_R) && !defined(HAVE_LOCALTIME_S) && \
15390 defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
 
15391 #define HAVE_LOCALTIME_S 1
15392 #endif
15393
15394 #ifndef SQLITE_OMIT_LOCALTIME
15395 /*
@@ -15405,12 +15488,11 @@
15405 ** library function localtime_r() is used to assist in the calculation of
15406 ** local time.
15407 */
15408 static int osLocaltime(time_t *t, struct tm *pTm){
15409 int rc;
15410 #if (!defined(HAVE_LOCALTIME_R) || !HAVE_LOCALTIME_R) \
15411 && (!defined(HAVE_LOCALTIME_S) || !HAVE_LOCALTIME_S)
15412 struct tm *pX;
15413 #if SQLITE_THREADSAFE>0
15414 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
15415 #endif
15416 sqlite3_mutex_enter(mutex);
@@ -15423,11 +15505,11 @@
15423 rc = pX==0;
15424 #else
15425 #ifndef SQLITE_OMIT_BUILTIN_TEST
15426 if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
15427 #endif
15428 #if defined(HAVE_LOCALTIME_R) && HAVE_LOCALTIME_R
15429 rc = localtime_r(t, pTm)==0;
15430 #else
15431 rc = localtime_s(pTm, t);
15432 #endif /* HAVE_LOCALTIME_R */
15433 #endif /* HAVE_LOCALTIME_R || HAVE_LOCALTIME_S */
@@ -15867,12 +15949,14 @@
15867 DateTime x;
15868 u64 n;
15869 size_t i,j;
15870 char *z;
15871 sqlite3 *db;
15872 const char *zFmt = (const char*)sqlite3_value_text(argv[0]);
15873 char zBuf[100];
 
 
15874 if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return;
15875 db = sqlite3_context_db_handle(context);
15876 for(i=0, n=1; zFmt[i]; i++, n++){
15877 if( zFmt[i]=='%' ){
15878 switch( zFmt[i+1] ){
@@ -16062,11 +16146,11 @@
16062 UNUSED_PARAMETER(argv);
16063
16064 iT = sqlite3StmtCurrentTime(context);
16065 if( iT<=0 ) return;
16066 t = iT/1000 - 10000*(sqlite3_int64)21086676;
16067 #ifdef HAVE_GMTIME_R
16068 pTm = gmtime_r(&t, &sNow);
16069 #else
16070 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
16071 pTm = gmtime(&t);
16072 if( pTm ) memcpy(&sNow, pTm, sizeof(sNow));
@@ -16736,13 +16820,13 @@
16736
16737 /*
16738 ** The malloc.h header file is needed for malloc_usable_size() function
16739 ** on some systems (e.g. Linux).
16740 */
16741 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE)
16742 # define SQLITE_USE_MALLOC_H
16743 # define SQLITE_USE_MALLOC_USABLE_SIZE
16744 /*
16745 ** The MSVCRT has malloc_usable_size(), but it is called _msize(). The
16746 ** use of _msize() is automatic, but can be disabled by compiling with
16747 ** -DSQLITE_WITHOUT_MSIZE. Using the _msize() function also requires
16748 ** the malloc.h header file.
@@ -19976,10 +20060,16 @@
19976 #endif
19977 }
19978 break;
19979 }
19980 default: {
 
 
 
 
 
 
19981 assert( iType-2 >= 0 );
19982 assert( iType-2 < ArraySize(winMutex_staticMutexes) );
19983 assert( winMutex_isInit==1 );
19984 p = &winMutex_staticMutexes[iType-2];
19985 #ifdef SQLITE_DEBUG
@@ -20971,21 +21061,10 @@
20971 ** This file contains code for a set of "printf"-like routines. These
20972 ** routines format strings much like the printf() from the standard C
20973 ** library, though the implementation here has enhancements to support
20974 ** SQLlite.
20975 */
20976
20977 /*
20978 ** If the strchrnul() library function is available, then set
20979 ** HAVE_STRCHRNUL. If that routine is not available, this module
20980 ** will supply its own. The built-in version is slower than
20981 ** the glibc version so the glibc version is definitely preferred.
20982 */
20983 #if !defined(HAVE_STRCHRNUL)
20984 # define HAVE_STRCHRNUL 0
20985 #endif
20986
20987
20988 /*
20989 ** Conversion types fall into various categories as defined by the
20990 ** following enumeration.
20991 */
@@ -22280,10 +22359,12 @@
22280 ** single threaded systems. Nothing in SQLite requires multiple threads.
22281 ** This interface exists so that applications that want to take advantage
22282 ** of multiple cores can do so, while also allowing applications to stay
22283 ** single-threaded if desired.
22284 */
 
 
22285
22286 #if SQLITE_MAX_WORKER_THREADS>0
22287
22288 /********************************* Unix Pthreads ****************************/
22289 #if SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) && SQLITE_THREADSAFE>0
@@ -23066,11 +23147,11 @@
23066 ** This file contains functions for allocating memory, comparing
23067 ** strings, and stuff like that.
23068 **
23069 */
23070 /* #include <stdarg.h> */
23071 #ifdef SQLITE_HAVE_ISNAN
23072 # include <math.h>
23073 #endif
23074
23075 /*
23076 ** Routine needed to support the testcase() macro.
@@ -23107,11 +23188,11 @@
23107 ** Use the math library isnan() function if compiled with SQLITE_HAVE_ISNAN.
23108 ** Otherwise, we have our own implementation that works on most systems.
23109 */
23110 SQLITE_PRIVATE int sqlite3IsNaN(double x){
23111 int rc; /* The value return */
23112 #if !defined(SQLITE_HAVE_ISNAN)
23113 /*
23114 ** Systems that support the isnan() library function should probably
23115 ** make use of it by compiling with -DSQLITE_HAVE_ISNAN. But we have
23116 ** found that many systems do not have a working isnan() function so
23117 ** this implementation is provided as an alternative.
@@ -23137,13 +23218,13 @@
23137 # error SQLite will not work correctly with the -ffast-math option of GCC.
23138 #endif
23139 volatile double y = x;
23140 volatile double z = y;
23141 rc = (y!=z);
23142 #else /* if defined(SQLITE_HAVE_ISNAN) */
23143 rc = isnan(x);
23144 #endif /* SQLITE_HAVE_ISNAN */
23145 testcase( rc );
23146 return rc;
23147 }
23148 #endif /* SQLITE_OMIT_FLOATING_POINT */
23149
@@ -28460,13 +28541,13 @@
28460
28461 /*
28462 ** We do not trust systems to provide a working fdatasync(). Some do.
28463 ** Others do no. To be safe, we will stick with the (slightly slower)
28464 ** fsync(). If you know that your system does support fdatasync() correctly,
28465 ** then simply compile with -Dfdatasync=fdatasync
28466 */
28467 #if !defined(fdatasync)
28468 # define fdatasync fsync
28469 #endif
28470
28471 /*
28472 ** Define HAVE_FULLFSYNC to 0 or 1 depending on whether or not
@@ -28783,28 +28864,32 @@
28783 do{
28784 err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size);
28785 }while( err==EINTR );
28786 if( err ) return SQLITE_IOERR_WRITE;
28787 #else
28788 /* If the OS does not have posix_fallocate(), fake it. First use
28789 ** ftruncate() to set the file size, then write a single byte to
28790 ** the last byte in each block within the extended region. This
28791 ** is the same technique used by glibc to implement posix_fallocate()
28792 ** on systems that do not have a real fallocate() system call.
 
28793 */
28794 int nBlk = buf.st_blksize; /* File-system block size */
 
28795 i64 iWrite; /* Next offset to write to */
28796
28797 if( robust_ftruncate(pFile->h, nSize) ){
28798 pFile->lastErrno = errno;
28799 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
28800 }
28801 iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
28802 while( iWrite<nSize ){
28803 int nWrite = seekAndWrite(pFile, iWrite, "", 1);
 
 
 
28804 if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
28805 iWrite += nBlk;
 
 
 
28806 }
28807 #endif
28808 }
28809 }
28810
@@ -34018,12 +34103,12 @@
34018 */
34019 SQLITE_API int sqlite3_win32_reset_heap(){
34020 int rc;
34021 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
34022 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
34023 MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
34024 MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
34025 sqlite3_mutex_enter(pMaster);
34026 sqlite3_mutex_enter(pMem);
34027 winMemAssertMagic();
34028 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
34029 /*
@@ -35294,11 +35379,11 @@
35294 sqlite3_file *id, /* File to read from */
35295 void *pBuf, /* Write content into this buffer */
35296 int amt, /* Number of bytes to read */
35297 sqlite3_int64 offset /* Begin reading at this offset */
35298 ){
35299 #if !SQLITE_OS_WINCE
35300 OVERLAPPED overlapped; /* The offset for ReadFile. */
35301 #endif
35302 winFile *pFile = (winFile*)id; /* file handle */
35303 DWORD nRead; /* Number of bytes actually read from file */
35304 int nRetry = 0; /* Number of retrys */
@@ -35326,11 +35411,11 @@
35326 offset += nCopy;
35327 }
35328 }
35329 #endif
35330
35331 #if SQLITE_OS_WINCE
35332 if( winSeekFile(pFile, offset) ){
35333 OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h));
35334 return SQLITE_FULL;
35335 }
35336 while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
@@ -35398,32 +35483,32 @@
35398 offset += nCopy;
35399 }
35400 }
35401 #endif
35402
35403 #if SQLITE_OS_WINCE
35404 rc = winSeekFile(pFile, offset);
35405 if( rc==0 ){
35406 #else
35407 {
35408 #endif
35409 #if !SQLITE_OS_WINCE
35410 OVERLAPPED overlapped; /* The offset for WriteFile. */
35411 #endif
35412 u8 *aRem = (u8 *)pBuf; /* Data yet to be written */
35413 int nRem = amt; /* Number of bytes yet to be written */
35414 DWORD nWrite; /* Bytes written by each WriteFile() call */
35415 DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */
35416
35417 #if !SQLITE_OS_WINCE
35418 memset(&overlapped, 0, sizeof(OVERLAPPED));
35419 overlapped.Offset = (LONG)(offset & 0xffffffff);
35420 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
35421 #endif
35422
35423 while( nRem>0 ){
35424 #if SQLITE_OS_WINCE
35425 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
35426 #else
35427 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){
35428 #endif
35429 if( winRetryIoerr(&nRetry, &lastErrno) ) continue;
@@ -35432,11 +35517,11 @@
35432 assert( nWrite==0 || nWrite<=(DWORD)nRem );
35433 if( nWrite==0 || nWrite>(DWORD)nRem ){
35434 lastErrno = osGetLastError();
35435 break;
35436 }
35437 #if !SQLITE_OS_WINCE
35438 offset += nWrite;
35439 overlapped.Offset = (LONG)(offset & 0xffffffff);
35440 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
35441 #endif
35442 aRem += nWrite;
@@ -38813,22 +38898,10 @@
38813 void *pStress; /* Argument to xStress */
38814 sqlite3_pcache *pCache; /* Pluggable cache module */
38815 PgHdr *pPage1; /* Reference to page 1 */
38816 };
38817
38818 /*
38819 ** Some of the assert() macros in this code are too expensive to run
38820 ** even during normal debugging. Use them only rarely on long-running
38821 ** tests. Enable the expensive asserts using the
38822 ** -DSQLITE_ENABLE_EXPENSIVE_ASSERT=1 compile-time option.
38823 */
38824 #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
38825 # define expensive_assert(X) assert(X)
38826 #else
38827 # define expensive_assert(X)
38828 #endif
38829
38830 /********************************** Linked List Management ********************/
38831
38832 /* Allowed values for second argument to pcacheManageDirtyList() */
38833 #define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
38834 #define PCACHE_DIRTYLIST_ADD 2 /* Add pPage to the dirty list */
@@ -38978,11 +39051,12 @@
38978 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
38979 assert( pCache->nRef==0 && pCache->pDirty==0 );
38980 if( pCache->szPage ){
38981 sqlite3_pcache *pNew;
38982 pNew = sqlite3GlobalConfig.pcache2.xCreate(
38983 szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
 
38984 );
38985 if( pNew==0 ) return SQLITE_NOMEM;
38986 sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
38987 if( pCache->pCache ){
38988 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
@@ -39437,11 +39511,11 @@
39437
39438 /*
39439 ** Return the size of the header added by this middleware layer
39440 ** in the page-cache hierarchy.
39441 */
39442 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); }
39443
39444
39445 #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
39446 /*
39447 ** For all dirty pages currently in the cache, invoke the specified
@@ -39753,11 +39827,11 @@
39753 pcache1Free(pPg);
39754 sqlite3_free(p);
39755 pPg = 0;
39756 }
39757 #else
39758 pPg = pcache1Alloc(sizeof(PgHdr1) + pCache->szPage + pCache->szExtra);
39759 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
39760 #endif
39761 pcache1EnterMutex(pCache->pGroup);
39762
39763 if( pPg ){
@@ -40441,11 +40515,11 @@
40441 }
40442
40443 /*
40444 ** Return the size of the header on each page of this PCACHE implementation.
40445 */
40446 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); }
40447
40448 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40449 /*
40450 ** This function is called to free superfluous dynamically allocated memory
40451 ** held by the pager system. Memory in use by any SQLite pager allocated
@@ -41799,10 +41873,12 @@
41799 u8 eLock; /* Current lock held on database file */
41800 u8 changeCountDone; /* Set after incrementing the change-counter */
41801 u8 setMaster; /* True if a m-j name has been written to jrnl */
41802 u8 doNotSpill; /* Do not spill the cache when non-zero */
41803 u8 subjInMemory; /* True to use in-memory sub-journals */
 
 
41804 Pgno dbSize; /* Number of pages in the database */
41805 Pgno dbOrigSize; /* dbSize before the current transaction */
41806 Pgno dbFileSize; /* Number of pages in the database file */
41807 Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */
41808 int errCode; /* One of several kinds of errors */
@@ -41816,13 +41892,13 @@
41816 i64 journalOff; /* Current write offset in the journal file */
41817 i64 journalHdr; /* Byte offset to previous journal header */
41818 sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
41819 PagerSavepoint *aSavepoint; /* Array of active savepoints */
41820 int nSavepoint; /* Number of elements in aSavepoint[] */
 
41821 char dbFileVers[16]; /* Changes whenever database file changes */
41822
41823 u8 bUseFetch; /* True to use xFetch() */
41824 int nMmapOut; /* Number of mmap pages currently outstanding */
41825 sqlite3_int64 szMmap; /* Desired maximum mmap size */
41826 PgHdr *pMmapFreelist; /* List of free mmap page headers (pDirty) */
41827 /*
41828 ** End of the routinely-changing class members
@@ -42834,13 +42910,22 @@
42834
42835 /*
42836 ** Discard the entire contents of the in-memory page-cache.
42837 */
42838 static void pager_reset(Pager *pPager){
 
42839 sqlite3BackupRestart(pPager->pBackup);
42840 sqlite3PcacheClear(pPager->pPCache);
42841 }
 
 
 
 
 
 
 
 
42842
42843 /*
42844 ** Free all structures in the Pager.aSavepoint[] array and set both
42845 ** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
42846 ** if it is open and the pager is not in exclusive mode.
@@ -45040,11 +45125,11 @@
45040 Pgno pgno, /* Page number */
45041 void *pData, /* xFetch()'d data for this page */
45042 PgHdr **ppPage /* OUT: Acquired page object */
45043 ){
45044 PgHdr *p; /* Memory mapped page to return */
45045
45046 if( pPager->pMmapFreelist ){
45047 *ppPage = p = pPager->pMmapFreelist;
45048 pPager->pMmapFreelist = p->pDirty;
45049 p->pDirty = 0;
45050 memset(p->pExtra, 0, pPager->nExtra);
@@ -46271,20 +46356,16 @@
46271 assert( (pPager->eLock==SHARED_LOCK)
46272 || (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK)
46273 );
46274 }
46275
46276 if( !pPager->tempFile && (
46277 pPager->pBackup
46278 || sqlite3PcachePagecount(pPager->pPCache)>0
46279 || USEFETCH(pPager)
46280 )){
46281 /* The shared-lock has just been acquired on the database file
46282 ** and there are already pages in the cache (from a previous
46283 ** read or write transaction). Check to see if the database
46284 ** has been modified. If the database has changed, flush the
46285 ** cache.
46286 **
46287 ** Database changes is detected by looking at 15 bytes beginning
46288 ** at offset 24 into the file. The first 4 of these 16 bytes are
46289 ** a 32-bit counter that is incremented with each change. The
46290 ** other bytes change randomly with each file change when
@@ -46445,10 +46526,11 @@
46445 assert( noContent==0 || bMmapOk==0 );
46446
46447 if( pgno==0 ){
46448 return SQLITE_CORRUPT_BKPT;
46449 }
 
46450
46451 /* If the pager is in the error state, return an error immediately.
46452 ** Otherwise, request the page from the PCache layer. */
46453 if( pPager->errCode!=SQLITE_OK ){
46454 rc = pPager->errCode;
@@ -46594,10 +46676,11 @@
46594 sqlite3_pcache_page *pPage;
46595 assert( pPager!=0 );
46596 assert( pgno!=0 );
46597 assert( pPager->pPCache!=0 );
46598 pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
 
46599 return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
46600 }
46601
46602 /*
46603 ** Release a page reference.
@@ -47460,10 +47543,11 @@
47460 pPager->eState = PAGER_READER;
47461 return SQLITE_OK;
47462 }
47463
47464 PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
 
47465 rc = pager_end_transaction(pPager, pPager->setMaster, 1);
47466 return pager_error(pPager, rc);
47467 }
47468
47469 /*
@@ -50829,11 +50913,11 @@
50829 }
50830 nCollide = HASHTABLE_NSLOT;
50831 for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
50832 u32 iFrame = aHash[iKey] + iZero;
50833 if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
50834 /* assert( iFrame>iRead ); -- not true if there is corruption */
50835 iRead = iFrame;
50836 }
50837 if( (nCollide--)==0 ){
50838 return SQLITE_CORRUPT_BKPT;
50839 }
@@ -51935,10 +52019,11 @@
51935 u8 inTrans; /* TRANS_NONE, TRANS_READ or TRANS_WRITE */
51936 u8 sharable; /* True if we can share pBt with another db */
51937 u8 locked; /* True if db currently has pBt locked */
51938 int wantToLock; /* Number of nested calls to sqlite3BtreeEnter() */
51939 int nBackup; /* Number of backup operations reading this btree */
 
51940 Btree *pNext; /* List of other sharable Btrees from the same db */
51941 Btree *pPrev; /* Back pointer of the same list */
51942 #ifndef SQLITE_OMIT_SHARED_CACHE
51943 BtLock lock; /* Object used to lock page 1 */
51944 #endif
@@ -56098,10 +56183,11 @@
56098 rc = sqlite3PagerCommitPhaseTwo(pBt->pPager);
56099 if( rc!=SQLITE_OK && bCleanup==0 ){
56100 sqlite3BtreeLeave(p);
56101 return rc;
56102 }
 
56103 pBt->inTransaction = TRANS_READ;
56104 btreeClearHasContent(pBt);
56105 }
56106
56107 btreeEndTransaction(p);
@@ -56461,11 +56547,11 @@
56461 }
56462 for(i=0; i<=pCur->iPage; i++){
56463 releasePage(pCur->apPage[i]);
56464 }
56465 unlockBtreeIfUnused(pBt);
56466 sqlite3DbFree(pBtree->db, pCur->aOverflow);
56467 /* sqlite3_free(pCur); */
56468 sqlite3BtreeLeave(pBtree);
56469 }
56470 return SQLITE_OK;
56471 }
@@ -56755,10 +56841,11 @@
56755 pBuf += a;
56756 amt -= a;
56757 }else{
56758 offset -= pCur->info.nLocal;
56759 }
 
56760
56761 if( rc==SQLITE_OK && amt>0 ){
56762 const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */
56763 Pgno nextPage;
56764
@@ -56773,12 +56860,12 @@
56773 ** means "not yet known" (the cache is lazily populated).
56774 */
56775 if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){
56776 int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
56777 if( nOvfl>pCur->nOvflAlloc ){
56778 Pgno *aNew = (Pgno*)sqlite3DbRealloc(
56779 pCur->pBtree->db, pCur->aOverflow, nOvfl*2*sizeof(Pgno)
56780 );
56781 if( aNew==0 ){
56782 rc = SQLITE_NOMEM;
56783 }else{
56784 pCur->nOvflAlloc = nOvfl*2;
@@ -56821,10 +56908,11 @@
56821 ** Note that the aOverflow[] array must be allocated because eOp!=2
56822 ** here. If eOp==2, then offset==0 and this branch is never taken.
56823 */
56824 assert( eOp!=2 );
56825 assert( pCur->curFlags & BTCF_ValidOvfl );
 
56826 if( pCur->aOverflow[iIdx+1] ){
56827 nextPage = pCur->aOverflow[iIdx+1];
56828 }else{
56829 rc = getOverflowPage(pBt, nextPage, 0, &nextPage);
56830 }
@@ -59410,12 +59498,12 @@
59410 assert( leafCorrection==4 );
59411 if( szCell[nCell]<4 ){
59412 /* Do not allow any cells smaller than 4 bytes. If a smaller cell
59413 ** does exist, pad it with 0x00 bytes. */
59414 assert( szCell[nCell]==3 );
59415 assert( apCell[nCell]==&pTemp[iSpace1-3] );
59416 pTemp[iSpace1++] = 0x00;
59417 szCell[nCell] = 4;
59418 }
59419 }
59420 nCell++;
59421 }
@@ -60723,10 +60811,17 @@
60723 ** is read-only, the others are read/write.
60724 **
60725 ** The schema layer numbers meta values differently. At the schema
60726 ** layer (and the SetCookie and ReadCookie opcodes) the number of
60727 ** free pages is not visible. So Cookie[0] is the same as Meta[1].
 
 
 
 
 
 
 
60728 */
60729 SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
60730 BtShared *pBt = p->pBt;
60731
60732 sqlite3BtreeEnter(p);
@@ -60733,11 +60828,15 @@
60733 assert( p->inTrans>TRANS_NONE );
60734 assert( SQLITE_OK==querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK) );
60735 assert( pBt->pPage1 );
60736 assert( idx>=0 && idx<=15 );
60737
60738 *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
 
 
 
 
60739
60740 /* If auto-vacuum is disabled in this build and this is an auto-vacuum
60741 ** database, mark the database as read-only. */
60742 #ifdef SQLITE_OMIT_AUTOVACUUM
60743 if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){
@@ -60824,11 +60923,11 @@
60824 if( pPage->leaf ){
60825 do {
60826 if( pCur->iPage==0 ){
60827 /* All pages of the b-tree have been visited. Return successfully. */
60828 *pnEntry = nEntry;
60829 return SQLITE_OK;
60830 }
60831 moveToParent(pCur);
60832 }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
60833
60834 pCur->aiIdx[pCur->iPage]++;
@@ -61680,11 +61779,11 @@
61680 }
61681
61682 /*
61683 ** Return the size of the header added to each page by this module.
61684 */
61685 SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); }
61686
61687 /************** End of btree.c ***********************************************/
61688 /************** Begin file backup.c ******************************************/
61689 /*
61690 ** 2009 January 28
@@ -64444,36 +64543,39 @@
64444 **
64445 ** assert( sqlite3VdbeAssertMayAbort(pParse->pVdbe, pParse->mayAbort) );
64446 */
64447 SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
64448 int hasAbort = 0;
 
64449 Op *pOp;
64450 VdbeOpIter sIter;
64451 memset(&sIter, 0, sizeof(sIter));
64452 sIter.v = v;
64453
64454 while( (pOp = opIterNext(&sIter))!=0 ){
64455 int opcode = pOp->opcode;
64456 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
64457 #ifndef SQLITE_OMIT_FOREIGN_KEY
64458 || (opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1)
64459 #endif
64460 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
64461 && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
64462 ){
64463 hasAbort = 1;
64464 break;
64465 }
 
 
 
 
 
64466 }
64467 sqlite3DbFree(v->db, sIter.apSub);
64468
64469 /* Return true if hasAbort==mayAbort. Or if a malloc failure occurred.
64470 ** If malloc failed, then the while() loop above may not have iterated
64471 ** through all opcodes and hasAbort may be set incorrectly. Return
64472 ** true for this case to prevent the assert() in the callers frame
64473 ** from failing. */
64474 return ( v->db->mallocFailed || hasAbort==mayAbort );
64475 }
64476 #endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */
64477
64478 /*
64479 ** Loop through the program looking for P2 values that are negative
@@ -68593,11 +68695,14 @@
68593 #ifndef SQLITE_OMIT_WAL
68594 int i;
68595 for(i=0; i<db->nDb; i++){
68596 Btree *pBt = db->aDb[i].pBt;
68597 if( pBt ){
68598 int nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
 
 
 
68599 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
68600 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
68601 }
68602 }
68603 }
@@ -68773,11 +68878,10 @@
68773 ** program counter to 0 to ensure that when the statement is
68774 ** finalized or reset the parser error message is available via
68775 ** sqlite3_errmsg() and sqlite3_errcode().
68776 */
68777 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
68778 assert( zErr!=0 || db->mallocFailed );
68779 sqlite3DbFree(db, v->zErrMsg);
68780 if( !db->mallocFailed ){
68781 v->zErrMsg = sqlite3DbStrDup(db, zErr);
68782 v->rc = rc2;
68783 } else {
@@ -73838,12 +73942,12 @@
73838 pIdxKey->default_rc = 0;
73839 if( pOp->opcode==OP_NoConflict ){
73840 /* For the OP_NoConflict opcode, take the jump if any of the
73841 ** input fields are NULL, since any key with a NULL will not
73842 ** conflict */
73843 for(ii=0; ii<r.nField; ii++){
73844 if( r.aMem[ii].flags & MEM_Null ){
73845 pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
73846 break;
73847 }
73848 }
73849 }
@@ -77135,11 +77239,11 @@
77135 /*
77136 ** Hard-coded maximum amount of data to accumulate in memory before flushing
77137 ** to a level 0 PMA. The purpose of this limit is to prevent various integer
77138 ** overflows. 512MiB.
77139 */
77140 #define SQLITE_MAX_MXPMASIZE (1<<29)
77141
77142 /*
77143 ** Private objects used by the sorter
77144 */
77145 typedef struct MergeEngine MergeEngine; /* Merge PMAs together */
@@ -77431,15 +77535,10 @@
77431 **
77432 ** void *SRVAL(SorterRecord *p) { return (void*)&p[1]; }
77433 */
77434 #define SRVAL(p) ((void*)((SorterRecord*)(p) + 1))
77435
77436 /* The minimum PMA size is set to this value multiplied by the database
77437 ** page size in bytes. */
77438 #ifndef SQLITE_SORTER_PMASZ
77439 # define SQLITE_SORTER_PMASZ 10
77440 #endif
77441
77442 /* Maximum number of PMAs that a single MergeEngine can merge */
77443 #define SORTER_MAX_MERGE_COUNT 16
77444
77445 static int vdbeIncrSwap(IncrMerger*);
@@ -77834,14 +77933,15 @@
77834 SortSubtask *pTask = &pSorter->aTask[i];
77835 pTask->pSorter = pSorter;
77836 }
77837
77838 if( !sqlite3TempInMemory(db) ){
77839 pSorter->mnPmaSize = SQLITE_SORTER_PMASZ * pgsz;
 
77840 mxCache = db->aDb[0].pSchema->cache_size;
77841 if( mxCache<SQLITE_SORTER_PMASZ ) mxCache = SQLITE_SORTER_PMASZ;
77842 pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_MXPMASIZE);
77843
77844 /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
77845 ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
77846 ** large heap allocations.
77847 */
@@ -78115,16 +78215,16 @@
78115 ** Whether or not the file does end up memory mapped of course depends on
78116 ** the specific VFS implementation.
78117 */
78118 static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){
78119 if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){
78120 int rc = sqlite3OsTruncate(pFd, nByte);
78121 if( rc==SQLITE_OK ){
78122 void *p = 0;
78123 sqlite3OsFetch(pFd, 0, (int)nByte, &p);
78124 sqlite3OsUnfetch(pFd, 0, p);
78125 }
78126 }
78127 }
78128 #else
78129 # define vdbeSorterExtendFile(x,y,z)
78130 #endif
@@ -79401,10 +79501,11 @@
79401 rc = vdbePmaReaderNext(pSorter->pReader);
79402 *pbEof = (pSorter->pReader->pFd==0);
79403 }else
79404 #endif
79405 /*if( !pSorter->bUseThreads )*/ {
 
79406 assert( pSorter->pMerger->pTask==(&pSorter->aTask[0]) );
79407 rc = vdbeMergeEngineStep(pSorter->pMerger, pbEof);
79408 }
79409 }else{
79410 SorterRecord *pFree = pSorter->list.pList;
@@ -82167,11 +82268,11 @@
82167 Expr *pLeft, /* Left operand */
82168 Expr *pRight, /* Right operand */
82169 const Token *pToken /* Argument token */
82170 ){
82171 Expr *p;
82172 if( op==TK_AND && pLeft && pRight ){
82173 /* Take advantage of short-circuit false optimization for AND */
82174 p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
82175 }else{
82176 p = sqlite3ExprAlloc(pParse->db, op, pToken, 1);
82177 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
@@ -85721,14 +85822,15 @@
85721 ** NEVER() will need to be removed. */
85722 if( pExpr->op==TK_COLUMN || NEVER(pExpr->op==TK_AGG_COLUMN) ){
85723 int i;
85724 struct SrcCount *p = pWalker->u.pSrcCount;
85725 SrcList *pSrc = p->pSrc;
85726 for(i=0; i<pSrc->nSrc; i++){
 
85727 if( pExpr->iTable==pSrc->a[i].iCursor ) break;
85728 }
85729 if( i<pSrc->nSrc ){
85730 p->nThis++;
85731 }else{
85732 p->nOther++;
85733 }
85734 }
@@ -87302,11 +87404,11 @@
87302
87303 p->iGet = -1;
87304 p->mxSample = mxSample;
87305 p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[2])/(mxSample/3+1) + 1);
87306 p->current.anLt = &p->current.anEq[nColUp];
87307 p->iPrn = nCol*0x689e962d ^ sqlite3_value_int(argv[2])*0xd0944565;
87308
87309 /* Set up the Stat4Accum.a[] and aBest[] arrays */
87310 p->a = (struct Stat4Sample*)&p->current.anLt[nColUp];
87311 p->aBest = &p->a[mxSample];
87312 pSpace = (u8*)(&p->a[mxSample+nCol]);
@@ -88895,17 +88997,19 @@
88895 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
88896 zErrDyn = sqlite3MPrintf(db,
88897 "attached databases must use the same text encoding as main database");
88898 rc = SQLITE_ERROR;
88899 }
 
88900 pPager = sqlite3BtreePager(aNew->pBt);
88901 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
88902 sqlite3BtreeSecureDelete(aNew->pBt,
88903 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
88904 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
88905 sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK));
88906 #endif
 
88907 }
88908 aNew->safety_level = 3;
88909 aNew->zName = sqlite3DbStrDup(db, zName);
88910 if( rc==SQLITE_OK && aNew->zName==0 ){
88911 rc = SQLITE_NOMEM;
@@ -90027,11 +90131,10 @@
90027 */
90028 static void freeIndex(sqlite3 *db, Index *p){
90029 #ifndef SQLITE_OMIT_ANALYZE
90030 sqlite3DeleteIndexSamples(db, p);
90031 #endif
90032 if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo);
90033 sqlite3ExprDelete(db, p->pPartIdxWhere);
90034 sqlite3DbFree(db, p->zColAff);
90035 if( p->isResized ) sqlite3DbFree(db, p->azColl);
90036 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
90037 sqlite3_free(p->aiRowEst);
@@ -91306,10 +91409,23 @@
91306 if( pPk==0 ) return;
91307 pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
91308 pTab->iPKey = -1;
91309 }else{
91310 pPk = sqlite3PrimaryKeyIndex(pTab);
 
 
 
 
 
 
 
 
 
 
 
 
 
91311 }
91312 pPk->isCovering = 1;
91313 assert( pPk!=0 );
91314 nPk = pPk->nKeyCol;
91315
@@ -93782,44 +93898,35 @@
93782 **
93783 ** The caller should invoke sqlite3KeyInfoUnref() on the returned object
93784 ** when it has finished using it.
93785 */
93786 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
 
 
 
 
93787 if( pParse->nErr ) return 0;
93788 #ifndef SQLITE_OMIT_SHARED_CACHE
93789 if( pIdx->pKeyInfo && pIdx->pKeyInfo->db!=pParse->db ){
93790 sqlite3KeyInfoUnref(pIdx->pKeyInfo);
93791 pIdx->pKeyInfo = 0;
93792 }
93793 #endif
93794 if( pIdx->pKeyInfo==0 ){
93795 int i;
93796 int nCol = pIdx->nColumn;
93797 int nKey = pIdx->nKeyCol;
93798 KeyInfo *pKey;
93799 if( pIdx->uniqNotNull ){
93800 pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
93801 }else{
93802 pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
93803 }
93804 if( pKey ){
93805 assert( sqlite3KeyInfoIsWriteable(pKey) );
93806 for(i=0; i<nCol; i++){
93807 char *zColl = pIdx->azColl[i];
93808 assert( zColl!=0 );
93809 pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 :
93810 sqlite3LocateCollSeq(pParse, zColl);
93811 pKey->aSortOrder[i] = pIdx->aSortOrder[i];
93812 }
93813 if( pParse->nErr ){
93814 sqlite3KeyInfoUnref(pKey);
93815 }else{
93816 pIdx->pKeyInfo = pKey;
93817 }
93818 }
93819 }
93820 return sqlite3KeyInfoRef(pIdx->pKeyInfo);
93821 }
93822
93823 #ifndef SQLITE_OMIT_CTE
93824 /*
93825 ** This routine is invoked once per CTE by the parser while parsing a
@@ -94596,12 +94703,12 @@
94596 const char *zDb; /* Name of database holding pTab */
94597 int i; /* Loop counter */
94598 WhereInfo *pWInfo; /* Information about the WHERE clause */
94599 Index *pIdx; /* For looping over indices of the table */
94600 int iTabCur; /* Cursor number for the table */
94601 int iDataCur; /* VDBE cursor for the canonical data source */
94602 int iIdxCur; /* Cursor number of the first index */
94603 int nIdx; /* Number of indices */
94604 sqlite3 *db; /* Main database structure */
94605 AuthContext sContext; /* Authorization context */
94606 NameContext sNC; /* Name context to resolve expressions in */
94607 int iDb; /* Database number */
@@ -97436,11 +97543,11 @@
97436 assert( nIncr==1 );
97437 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
97438 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
97439 }else{
97440 if( nIncr>0 && pFKey->isDeferred==0 ){
97441 sqlite3ParseToplevel(pParse)->mayAbort = 1;
97442 }
97443 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
97444 }
97445
97446 sqlite3VdbeResolveLabel(v, iOk);
@@ -97507,10 +97614,14 @@
97507 ** This function is called to generate code executed when a row is deleted
97508 ** from the parent table of foreign key constraint pFKey and, if pFKey is
97509 ** deferred, when a row is inserted into the same table. When generating
97510 ** code for an SQL UPDATE operation, this function may be called twice -
97511 ** once to "delete" the old row and once to "insert" the new row.
 
 
 
 
97512 **
97513 ** The code generated by this function scans through the rows in the child
97514 ** table that correspond to the parent table row being deleted or inserted.
97515 ** For each child row found, one of the following actions is taken:
97516 **
@@ -97624,17 +97735,13 @@
97624 sNameContext.pSrcList = pSrc;
97625 sNameContext.pParse = pParse;
97626 sqlite3ResolveExprNames(&sNameContext, pWhere);
97627
97628 /* Create VDBE to loop through the entries in pSrc that match the WHERE
97629 ** clause. If the constraint is not deferred, throw an exception for
97630 ** each row found. Otherwise, for deferred constraints, increment the
97631 ** deferred constraint counter by nIncr for each row selected. */
97632 pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
97633 if( nIncr>0 && pFKey->isDeferred==0 ){
97634 sqlite3ParseToplevel(pParse)->mayAbort = 1;
97635 }
97636 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
97637 if( pWInfo ){
97638 sqlite3WhereEnd(pWInfo);
97639 }
97640
@@ -97808,10 +97915,28 @@
97808 }
97809 }
97810 }
97811 return 0;
97812 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97813
97814 /*
97815 ** This function is called when inserting, deleting or updating a row of
97816 ** table pTab to generate VDBE code to perform foreign key constraint
97817 ** processing for the operation.
@@ -97861,11 +97986,11 @@
97861 Index *pIdx = 0; /* Index on key columns in pTo */
97862 int *aiFree = 0;
97863 int *aiCol;
97864 int iCol;
97865 int i;
97866 int isIgnore = 0;
97867
97868 if( aChange
97869 && sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
97870 && fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
97871 ){
@@ -97920,11 +98045,11 @@
97920 ** values read from the parent table are NULL. */
97921 if( db->xAuth ){
97922 int rcauth;
97923 char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName;
97924 rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb);
97925 isIgnore = (rcauth==SQLITE_IGNORE);
97926 }
97927 #endif
97928 }
97929
97930 /* Take a shared-cache advisory read-lock on the parent table. Allocate
@@ -97935,16 +98060,22 @@
97935
97936 if( regOld!=0 ){
97937 /* A row is being removed from the child table. Search for the parent.
97938 ** If the parent does not exist, removing the child row resolves an
97939 ** outstanding foreign key constraint violation. */
97940 fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1,isIgnore);
97941 }
97942 if( regNew!=0 ){
97943 /* A row is being added to the child table. If a parent row cannot
97944 ** be found, adding the child row has violated the FK constraint. */
97945 fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1,isIgnore);
 
 
 
 
 
 
97946 }
97947
97948 sqlite3DbFree(db, aiFree);
97949 }
97950
@@ -97961,12 +98092,12 @@
97961
97962 if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
97963 && !pParse->pToplevel && !pParse->isMultiWrite
97964 ){
97965 assert( regOld==0 && regNew!=0 );
97966 /* Inserting a single row into a parent table cannot cause an immediate
97967 ** foreign key violation. So do nothing in this case. */
97968 continue;
97969 }
97970
97971 if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ){
97972 if( !isIgnoreErrors || db->mallocFailed ) return;
@@ -97986,17 +98117,32 @@
97986
97987 if( regNew!=0 ){
97988 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1);
97989 }
97990 if( regOld!=0 ){
97991 /* If there is a RESTRICT action configured for the current operation
97992 ** on the parent table of this FK, then throw an exception
97993 ** immediately if the FK constraint is violated, even if this is a
97994 ** deferred trigger. That's what RESTRICT means. To defer checking
97995 ** the constraint, the FK should specify NO ACTION (represented
97996 ** using OE_None). NO ACTION is the default. */
97997 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regOld, 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97998 }
97999 pItem->zName = 0;
98000 sqlite3SrcListDelete(db, pSrc);
98001 }
98002 sqlite3DbFree(db, aiCol);
@@ -101895,10 +102041,11 @@
101895 #define PragTyp_KEY 38
101896 #define PragTyp_REKEY 39
101897 #define PragTyp_LOCK_STATUS 40
101898 #define PragTyp_PARSER_TRACE 41
101899 #define PragFlag_NeedSchema 0x01
 
101900 static const struct sPragmaNames {
101901 const char *const zName; /* Name of pragma */
101902 u8 ePragTyp; /* PragTyp_XXX value */
101903 u8 mPragFlag; /* Zero or more PragFlag_XXX values */
101904 u32 iArg; /* Extra argument */
@@ -101911,11 +102058,11 @@
101911 #endif
101912 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
101913 { /* zName: */ "application_id",
101914 /* ePragTyp: */ PragTyp_HEADER_VALUE,
101915 /* ePragFlag: */ 0,
101916 /* iArg: */ 0 },
101917 #endif
101918 #if !defined(SQLITE_OMIT_AUTOVACUUM)
101919 { /* zName: */ "auto_vacuum",
101920 /* ePragTyp: */ PragTyp_AUTO_VACUUM,
101921 /* ePragFlag: */ PragFlag_NeedSchema,
@@ -101977,10 +102124,16 @@
101977 { /* zName: */ "data_store_directory",
101978 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
101979 /* ePragFlag: */ 0,
101980 /* iArg: */ 0 },
101981 #endif
 
 
 
 
 
 
101982 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
101983 { /* zName: */ "database_list",
101984 /* ePragTyp: */ PragTyp_DATABASE_LIST,
101985 /* ePragFlag: */ PragFlag_NeedSchema,
101986 /* iArg: */ 0 },
@@ -102032,12 +102185,12 @@
102032 #endif
102033 #endif
102034 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102035 { /* zName: */ "freelist_count",
102036 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102037 /* ePragFlag: */ 0,
102038 /* iArg: */ 0 },
102039 #endif
102040 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
102041 { /* zName: */ "full_column_names",
102042 /* ePragTyp: */ PragTyp_FLAG,
102043 /* ePragFlag: */ 0,
@@ -102185,11 +102338,11 @@
102185 #endif
102186 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102187 { /* zName: */ "schema_version",
102188 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102189 /* ePragFlag: */ 0,
102190 /* iArg: */ 0 },
102191 #endif
102192 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
102193 { /* zName: */ "secure_delete",
102194 /* ePragTyp: */ PragTyp_SECURE_DELETE,
102195 /* ePragFlag: */ 0,
@@ -102251,11 +102404,11 @@
102251 /* iArg: */ 0 },
102252 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102253 { /* zName: */ "user_version",
102254 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102255 /* ePragFlag: */ 0,
102256 /* iArg: */ 0 },
102257 #endif
102258 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
102259 #if defined(SQLITE_DEBUG)
102260 { /* zName: */ "vdbe_addoptrace",
102261 /* ePragTyp: */ PragTyp_FLAG,
@@ -102294,11 +102447,11 @@
102294 /* ePragTyp: */ PragTyp_FLAG,
102295 /* ePragFlag: */ 0,
102296 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
102297 #endif
102298 };
102299 /* Number of pragmas: 57 on by default, 70 total. */
102300 /* End of the automatically generated pragma table.
102301 ***************************************************************************/
102302
102303 /*
102304 ** Interpret the given string as a safety level. Return 0 for OFF,
@@ -102544,11 +102697,11 @@
102544 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
102545 const char *zDb = 0; /* The database name */
102546 Token *pId; /* Pointer to <id> token */
102547 char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */
102548 int iDb; /* Database index for <database> */
102549 int lwr, upr, mid; /* Binary search bounds */
102550 int rc; /* return value form SQLITE_FCNTL_PRAGMA */
102551 sqlite3 *db = pParse->db; /* The database connection */
102552 Db *pDb; /* The specific database being pragmaed */
102553 Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
102554
@@ -103904,11 +104057,12 @@
103904 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
103905 DbHasProperty(db, 0, DB_Empty)
103906 ){
103907 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
103908 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
103909 ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
 
103910 break;
103911 }
103912 }
103913 if( !pEnc->zName ){
103914 sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
@@ -103949,28 +104103,13 @@
103949 **
103950 ** The user-version is not used internally by SQLite. It may be used by
103951 ** applications for any purpose.
103952 */
103953 case PragTyp_HEADER_VALUE: {
103954 int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
103955 sqlite3VdbeUsesBtree(v, iDb);
103956 switch( zLeft[0] ){
103957 case 'a': case 'A':
103958 iCookie = BTREE_APPLICATION_ID;
103959 break;
103960 case 'f': case 'F':
103961 iCookie = BTREE_FREE_PAGE_COUNT;
103962 break;
103963 case 's': case 'S':
103964 iCookie = BTREE_SCHEMA_VERSION;
103965 break;
103966 default:
103967 iCookie = BTREE_USER_VERSION;
103968 break;
103969 }
103970
103971 if( zRight && iCookie!=BTREE_FREE_PAGE_COUNT ){
103972 /* Write the specified cookie value */
103973 static const VdbeOpList setCookie[] = {
103974 { OP_Transaction, 0, 1, 0}, /* 0 */
103975 { OP_Integer, 0, 1, 0}, /* 1 */
103976 { OP_SetCookie, 0, 0, 1}, /* 2 */
@@ -104612,13 +104751,15 @@
104612 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
104613 int i, rc;
104614 int commit_internal = !(db->flags&SQLITE_InternChanges);
104615
104616 assert( sqlite3_mutex_held(db->mutex) );
 
104617 assert( db->init.busy==0 );
104618 rc = SQLITE_OK;
104619 db->init.busy = 1;
 
104620 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
104621 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
104622 rc = sqlite3InitOne(db, i, pzErrMsg);
104623 if( rc ){
104624 sqlite3ResetOneSchema(db, i);
@@ -105169,24 +105310,29 @@
105169 u8 sortFlags; /* Zero or more SORTFLAG_* bits */
105170 };
105171 #define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
105172
105173 /*
105174 ** Delete all the content of a Select structure but do not deallocate
105175 ** the select structure itself.
105176 */
105177 static void clearSelect(sqlite3 *db, Select *p){
105178 sqlite3ExprListDelete(db, p->pEList);
105179 sqlite3SrcListDelete(db, p->pSrc);
105180 sqlite3ExprDelete(db, p->pWhere);
105181 sqlite3ExprListDelete(db, p->pGroupBy);
105182 sqlite3ExprDelete(db, p->pHaving);
105183 sqlite3ExprListDelete(db, p->pOrderBy);
105184 sqlite3SelectDelete(db, p->pPrior);
105185 sqlite3ExprDelete(db, p->pLimit);
105186 sqlite3ExprDelete(db, p->pOffset);
105187 sqlite3WithDelete(db, p->pWith);
 
 
 
 
 
105188 }
105189
105190 /*
105191 ** Initialize a SelectDest structure.
105192 */
@@ -105241,12 +105387,11 @@
105241 pNew->pOffset = pOffset;
105242 assert( pOffset==0 || pLimit!=0 );
105243 pNew->addrOpenEphm[0] = -1;
105244 pNew->addrOpenEphm[1] = -1;
105245 if( db->mallocFailed ) {
105246 clearSelect(db, pNew);
105247 if( pNew!=&standin ) sqlite3DbFree(db, pNew);
105248 pNew = 0;
105249 }else{
105250 assert( pNew->pSrc!=0 || pParse->nErr>0 );
105251 }
105252 assert( pNew!=&standin );
@@ -105267,14 +105412,11 @@
105267
105268 /*
105269 ** Delete the given Select structure and all of its substructures.
105270 */
105271 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
105272 if( p ){
105273 clearSelect(db, p);
105274 sqlite3DbFree(db, p);
105275 }
105276 }
105277
105278 /*
105279 ** Return a pointer to the right-most SELECT statement in a compound.
105280 */
@@ -107186,10 +107328,70 @@
107186 Parse *pParse, /* Parsing context */
107187 Select *p, /* The right-most of SELECTs to be coded */
107188 SelectDest *pDest /* What to do with query results */
107189 );
107190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107191
107192 /*
107193 ** This routine is called to process a compound query form from
107194 ** two or more separate queries using UNION, UNION ALL, EXCEPT, or
107195 ** INTERSECT
@@ -107266,22 +107468,24 @@
107266 assert( p->pEList );
107267 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, dest.iSDParm, p->pEList->nExpr);
107268 sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
107269 dest.eDest = SRT_Table;
107270 }
 
 
 
 
 
 
 
107271
107272 /* Make sure all SELECTs in the statement have the same number of elements
107273 ** in their result sets.
107274 */
107275 assert( p->pEList && pPrior->pEList );
107276 if( p->pEList->nExpr!=pPrior->pEList->nExpr ){
107277 if( p->selFlags & SF_Values ){
107278 sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
107279 }else{
107280 sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
107281 " do not have the same number of result columns", selectOpName(p->op));
107282 }
107283 rc = 1;
107284 goto multi_select_end;
107285 }
107286
107287 #ifndef SQLITE_OMIT_CTE
@@ -109163,11 +109367,13 @@
109163 if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
109164 return WRC_Prune;
109165 }
109166 pTabList = p->pSrc;
109167 pEList = p->pEList;
109168 sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
 
 
109169
109170 /* Make sure cursor numbers have been assigned to all entries in
109171 ** the FROM clause of the SELECT statement.
109172 */
109173 sqlite3SrcListAssignCursors(pParse, pTabList);
@@ -109454,11 +109660,13 @@
109454 if( pParse->hasCompound ){
109455 w.xSelectCallback = convertCompoundSelectToSubquery;
109456 sqlite3WalkSelect(&w, pSelect);
109457 }
109458 w.xSelectCallback = selectExpander;
109459 w.xSelectCallback2 = selectPopWith;
 
 
109460 sqlite3WalkSelect(&w, pSelect);
109461 }
109462
109463
109464 #ifndef SQLITE_OMIT_SUBQUERY
@@ -110756,11 +110964,11 @@
110756 ){
110757 int rc;
110758 TabResult res;
110759
110760 #ifdef SQLITE_ENABLE_API_ARMOR
110761 if( pazResult==0 ) return SQLITE_MISUSE_BKPT;
110762 #endif
110763 *pazResult = 0;
110764 if( pnColumn ) *pnColumn = 0;
110765 if( pnRow ) *pnRow = 0;
110766 if( pzErrMsg ) *pzErrMsg = 0;
@@ -118626,11 +118834,10 @@
118626 sqlite3_free(p->u.vtab.idxStr);
118627 p->u.vtab.needFree = 0;
118628 p->u.vtab.idxStr = 0;
118629 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
118630 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
118631 sqlite3KeyInfoUnref(p->u.btree.pIndex->pKeyInfo);
118632 sqlite3DbFree(db, p->u.btree.pIndex);
118633 p->u.btree.pIndex = 0;
118634 }
118635 }
118636 }
@@ -123783,17 +123990,23 @@
123783 Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
123784 if( p ){
123785 int cnt = 0, mxSelect;
123786 p->pWith = yymsp[-1].minor.yy59;
123787 if( p->pPrior ){
 
123788 pNext = 0;
123789 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
123790 pLoop->pNext = pNext;
123791 pLoop->selFlags |= SF_Compound;
 
123792 }
123793 mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
123794 if( mxSelect && cnt>mxSelect ){
 
 
 
 
123795 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
123796 }
123797 }
123798 }else{
123799 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
@@ -125633,10 +125846,13 @@
125633 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
125634 sqlite3 *db = pParse->db; /* The database connection */
125635 int mxSqlLen; /* Max length of an SQL string */
125636
125637
 
 
 
125638 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
125639 if( db->nVdbeActive==0 ){
125640 db->u1.isInterrupted = 0;
125641 }
125642 pParse->rc = SQLITE_OK;
@@ -125871,17 +126087,10 @@
125871 */
125872 SQLITE_API int sqlite3_complete(const char *zSql){
125873 u8 state = 0; /* Current state, using numbers defined in header comment */
125874 u8 token; /* Value of the next token */
125875
125876 #ifdef SQLITE_ENABLE_API_ARMOR
125877 if( zSql==0 ){
125878 (void)SQLITE_MISUSE_BKPT;
125879 return 0;
125880 }
125881 #endif
125882
125883 #ifndef SQLITE_OMIT_TRIGGER
125884 /* A complex statement machine used to detect the end of a CREATE TRIGGER
125885 ** statement. This is the normal case.
125886 */
125887 static const u8 trans[8][8] = {
@@ -125906,10 +126115,17 @@
125906 /* 0 INVALID: */ { 1, 0, 2, },
125907 /* 1 START: */ { 1, 1, 2, },
125908 /* 2 NORMAL: */ { 1, 2, 2, },
125909 };
125910 #endif /* SQLITE_OMIT_TRIGGER */
 
 
 
 
 
 
 
125911
125912 while( *zSql ){
125913 switch( *zSql ){
125914 case ';': { /* A semicolon */
125915 token = tkSEMI;
@@ -126208,11 +126424,11 @@
126208 ** If the following function pointer is not NULL and if
126209 ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
126210 ** I/O active are written using this function. These messages
126211 ** are intended for debugging activity only.
126212 */
126213 SQLITE_PRIVATE void (*sqlite3IoTrace)(const char*, ...) = 0;
126214 #endif
126215
126216 /*
126217 ** If the following global variable points to a string which is the
126218 ** name of a directory, then that directory will be used to store
@@ -126417,10 +126633,17 @@
126417 ** routine is not threadsafe. But it is safe to invoke this routine
126418 ** on when SQLite is already shut down. If SQLite is already shut down
126419 ** when this routine is invoked, then this routine is a harmless no-op.
126420 */
126421 SQLITE_API int sqlite3_shutdown(void){
 
 
 
 
 
 
 
126422 if( sqlite3GlobalConfig.isInit ){
126423 #ifdef SQLITE_EXTRA_SHUTDOWN
126424 void SQLITE_EXTRA_SHUTDOWN(void);
126425 SQLITE_EXTRA_SHUTDOWN();
126426 #endif
@@ -126732,10 +126955,15 @@
126732 ** heap. */
126733 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
126734 break;
126735 }
126736 #endif
 
 
 
 
 
126737
126738 default: {
126739 rc = SQLITE_ERROR;
126740 break;
126741 }
@@ -127178,20 +127406,10 @@
127178
127179 /* Close all database connections */
127180 for(j=0; j<db->nDb; j++){
127181 struct Db *pDb = &db->aDb[j];
127182 if( pDb->pBt ){
127183 if( pDb->pSchema ){
127184 /* Must clear the KeyInfo cache. See ticket [e4a18565a36884b00edf] */
127185 sqlite3BtreeEnter(pDb->pBt);
127186 for(i=sqliteHashFirst(&pDb->pSchema->idxHash); i; i=sqliteHashNext(i)){
127187 Index *pIdx = sqliteHashData(i);
127188 sqlite3KeyInfoUnref(pIdx->pKeyInfo);
127189 pIdx->pKeyInfo = 0;
127190 }
127191 sqlite3BtreeLeave(pDb->pBt);
127192 }
127193 sqlite3BtreeClose(pDb->pBt);
127194 pDb->pBt = 0;
127195 if( j!=1 ){
127196 pDb->pSchema = 0;
127197 }
@@ -127494,11 +127712,11 @@
127494 */
127495 static int sqliteDefaultBusyCallback(
127496 void *ptr, /* Database connection */
127497 int count /* Number of times table has been busy */
127498 ){
127499 #if SQLITE_OS_WIN || (defined(HAVE_USLEEP) && HAVE_USLEEP)
127500 static const u8 delays[] =
127501 { 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 };
127502 static const u8 totals[] =
127503 { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
127504 # define NDELAY ArraySize(delays)
@@ -128315,36 +128533,10 @@
128315 */
128316 SQLITE_API const char *sqlite3_errstr(int rc){
128317 return sqlite3ErrStr(rc);
128318 }
128319
128320 /*
128321 ** Invalidate all cached KeyInfo objects for database connection "db"
128322 */
128323 static void invalidateCachedKeyInfo(sqlite3 *db){
128324 Db *pDb; /* A single database */
128325 int iDb; /* The database index number */
128326 HashElem *k; /* For looping over tables in pDb */
128327 Table *pTab; /* A table in the database */
128328 Index *pIdx; /* Each index */
128329
128330 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
128331 if( pDb->pBt==0 ) continue;
128332 sqlite3BtreeEnter(pDb->pBt);
128333 for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){
128334 pTab = (Table*)sqliteHashData(k);
128335 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
128336 if( pIdx->pKeyInfo && pIdx->pKeyInfo->db==db ){
128337 sqlite3KeyInfoUnref(pIdx->pKeyInfo);
128338 pIdx->pKeyInfo = 0;
128339 }
128340 }
128341 }
128342 sqlite3BtreeLeave(pDb->pBt);
128343 }
128344 }
128345
128346 /*
128347 ** Create a new collating function for database "db". The name is zName
128348 ** and the encoding is enc.
128349 */
128350 static int createCollation(
@@ -128384,11 +128576,10 @@
128384 sqlite3ErrorWithMsg(db, SQLITE_BUSY,
128385 "unable to delete/modify collation sequence due to active statements");
128386 return SQLITE_BUSY;
128387 }
128388 sqlite3ExpirePreparedStatements(db);
128389 invalidateCachedKeyInfo(db);
128390
128391 /* If collation sequence pColl was created directly by a call to
128392 ** sqlite3_create_collation, and not generated by synthCollSeq(),
128393 ** then any copies made by synthCollSeq() need to be invalidated.
128394 ** Also, collation destructor - CollSeq.xDel() - function may need
@@ -128941,10 +129132,11 @@
128941 sqlite3Error(db, rc);
128942 goto opendb_out;
128943 }
128944 sqlite3BtreeEnter(db->aDb[0].pBt);
128945 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
 
128946 sqlite3BtreeLeave(db->aDb[0].pBt);
128947 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
128948
128949 /* The default safety_level for the main database is 'full'; for the temp
128950 ** database it is 'NONE'. This matches the pager layer defaults.
@@ -129099,11 +129291,11 @@
129099 if( zFilename8 ){
129100 rc = openDatabase(zFilename8, ppDb,
129101 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
129102 assert( *ppDb || rc==SQLITE_NOMEM );
129103 if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){
129104 ENC(*ppDb) = SQLITE_UTF16NATIVE;
129105 }
129106 }else{
129107 rc = SQLITE_NOMEM;
129108 }
129109 sqlite3ValueFree(pVal);
@@ -129310,11 +129502,11 @@
129310 ){
129311 int rc;
129312 char *zErrMsg = 0;
129313 Table *pTab = 0;
129314 Column *pCol = 0;
129315 int iCol;
129316
129317 char const *zDataType = 0;
129318 char const *zCollSeq = 0;
129319 int notnull = 0;
129320 int primarykey = 0;
@@ -129841,32 +130033,34 @@
129841 /*
129842 ** Return the filename of the database associated with a database
129843 ** connection.
129844 */
129845 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
 
129846 #ifdef SQLITE_ENABLE_API_ARMOR
129847 if( !sqlite3SafetyCheckOk(db) ){
129848 (void)SQLITE_MISUSE_BKPT;
129849 return 0;
129850 }
129851 #endif
129852 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
129853 return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
129854 }
129855
129856 /*
129857 ** Return 1 if database is read-only or 0 if read/write. Return -1 if
129858 ** no such database exists.
129859 */
129860 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
 
129861 #ifdef SQLITE_ENABLE_API_ARMOR
129862 if( !sqlite3SafetyCheckOk(db) ){
129863 (void)SQLITE_MISUSE_BKPT;
129864 return -1;
129865 }
129866 #endif
129867 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
129868 return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
129869 }
129870
129871 /************** End of main.c ************************************************/
129872 /************** Begin file notify.c ******************************************/
@@ -132931,11 +133125,11 @@
132931 const char *zNode, /* Buffer containing segment interior node */
132932 int nNode, /* Size of buffer at zNode */
132933 sqlite3_int64 *piLeaf, /* Selected leaf node */
132934 sqlite3_int64 *piLeaf2 /* Selected leaf node */
132935 ){
132936 int rc; /* Return code */
132937 int iHeight; /* Height of this node in tree */
132938
132939 assert( piLeaf || piLeaf2 );
132940
132941 fts3GetVarint32(zNode, &iHeight);
@@ -132942,11 +133136,11 @@
132942 rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
132943 assert( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
132944
132945 if( rc==SQLITE_OK && iHeight>1 ){
132946 char *zBlob = 0; /* Blob read from %_segments table */
132947 int nBlob; /* Size of zBlob in bytes */
132948
132949 if( piLeaf && piLeaf2 && (*piLeaf!=*piLeaf2) ){
132950 rc = sqlite3Fts3ReadBlock(p, *piLeaf, &zBlob, &nBlob, 0);
132951 if( rc==SQLITE_OK ){
132952 rc = fts3SelectLeaf(p, zTerm, nTerm, zBlob, nBlob, piLeaf, 0);
@@ -134164,11 +134358,11 @@
134164 int idxNum, /* Strategy index */
134165 const char *idxStr, /* Unused */
134166 int nVal, /* Number of elements in apVal */
134167 sqlite3_value **apVal /* Arguments for the indexing scheme */
134168 ){
134169 int rc;
134170 char *zSql; /* SQL statement used to access %_content */
134171 int eSearch;
134172 Fts3Table *p = (Fts3Table *)pCursor->pVtab;
134173 Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
134174
@@ -140652,11 +140846,11 @@
140652 int argc, /* Number of elements in argv array */
140653 const char * const *argv, /* xCreate/xConnect argument array */
140654 sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */
140655 char **pzErr /* OUT: sqlite3_malloc'd error message */
140656 ){
140657 Fts3tokTable *pTab;
140658 const sqlite3_tokenizer_module *pMod = 0;
140659 sqlite3_tokenizer *pTok = 0;
140660 int rc;
140661 char **azDequote = 0;
140662 int nDequote;
@@ -144027,12 +144221,12 @@
144027 }
144028 rc = sqlite3_reset(pRange);
144029
144030 if( bOk ){
144031 int iIdx = 0;
144032 sqlite3_stmt *pUpdate1;
144033 sqlite3_stmt *pUpdate2;
144034
144035 if( rc==SQLITE_OK ){
144036 rc = fts3SqlStmt(p, SQL_UPDATE_LEVEL_IDX, &pUpdate1, 0);
144037 }
144038 if( rc==SQLITE_OK ){
@@ -150073,11 +150267,11 @@
150073 }
150074 i = pCur->nPoint++;
150075 pNew = pCur->aPoint + i;
150076 pNew->rScore = rScore;
150077 pNew->iLevel = iLevel;
150078 assert( iLevel>=0 && iLevel<=RTREE_MAX_DEPTH );
150079 while( i>0 ){
150080 RtreeSearchPoint *pParent;
150081 j = (i-1)/2;
150082 pParent = pCur->aPoint + j;
150083 if( rtreeSearchPointCompare(pNew, pParent)>=0 ) break;
@@ -151696,10 +151890,12 @@
151696 RtreeCell cell; /* New cell to insert if nData>1 */
151697 int bHaveRowid = 0; /* Set to 1 after new rowid is determined */
151698
151699 rtreeReference(pRtree);
151700 assert(nData>=1);
 
 
151701
151702 /* Constraint handling. A write operation on an r-tree table may return
151703 ** SQLITE_CONSTRAINT for two reasons:
151704 **
151705 ** 1. A duplicate rowid value, or
151706
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -41,10 +41,57 @@
41 **
42 */
43 #ifndef _SQLITEINT_H_
44 #define _SQLITEINT_H_
45
46 /*
47 ** Include the header file used to customize the compiler options for MSVC.
48 ** This should be done first so that it can successfully prevent spurious
49 ** compiler warnings due to subsequent content in this file and other files
50 ** that are included by this file.
51 */
52 /************** Include msvc.h in the middle of sqliteInt.h ******************/
53 /************** Begin file msvc.h ********************************************/
54 /*
55 ** 2015 January 12
56 **
57 ** The author disclaims copyright to this source code. In place of
58 ** a legal notice, here is a blessing:
59 **
60 ** May you do good and not evil.
61 ** May you find forgiveness for yourself and forgive others.
62 ** May you share freely, never taking more than you give.
63 **
64 ******************************************************************************
65 **
66 ** This file contains code that is specific to MSVC.
67 */
68 #ifndef _MSVC_H_
69 #define _MSVC_H_
70
71 #if defined(_MSC_VER)
72 #pragma warning(disable : 4054)
73 #pragma warning(disable : 4055)
74 #pragma warning(disable : 4100)
75 #pragma warning(disable : 4127)
76 #pragma warning(disable : 4152)
77 #pragma warning(disable : 4189)
78 #pragma warning(disable : 4206)
79 #pragma warning(disable : 4210)
80 #pragma warning(disable : 4232)
81 #pragma warning(disable : 4244)
82 #pragma warning(disable : 4305)
83 #pragma warning(disable : 4306)
84 #pragma warning(disable : 4702)
85 #pragma warning(disable : 4706)
86 #endif /* defined(_MSC_VER) */
87
88 #endif /* _MSVC_H_ */
89
90 /************** End of msvc.h ************************************************/
91 /************** Continuing where we left off in sqliteInt.h ******************/
92
93 /*
94 ** These #defines should enable >2GB file support on POSIX if the
95 ** underlying operating system supports it. If the OS lacks
96 ** large file support, or if the OS is windows, these should be no-ops.
97 **
@@ -231,11 +278,11 @@
278 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
279 ** [sqlite_version()] and [sqlite_source_id()].
280 */
281 #define SQLITE_VERSION "3.8.8"
282 #define SQLITE_VERSION_NUMBER 3008008
283 #define SQLITE_SOURCE_ID "2015-01-12 21:43:00 e693e11d1b9265974c32bddba873ea30a4d0b708"
284
285 /*
286 ** CAPI3REF: Run-Time Library Version Numbers
287 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
288 **
@@ -323,11 +370,11 @@
370 ** This interface only reports on the compile-time mutex setting
371 ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
372 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
373 ** can be fully or partially disabled using a call to [sqlite3_config()]
374 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
375 ** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
376 ** sqlite3_threadsafe() function shows only the compile-time setting of
377 ** thread safety, not any run-time changes to that setting made by
378 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
379 ** is unchanged by calls to sqlite3_config().)^
380 **
@@ -1692,11 +1739,11 @@
1739 ** configuration option.
1740 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1741 ** 8-byte aligned
1742 ** memory, the size of each page buffer (sz), and the number of pages (N).
1743 ** The sz argument should be the size of the largest database page
1744 ** (a power of two between 512 and 65536) plus some extra bytes for each
1745 ** page header. ^The number of extra bytes needed by the page header
1746 ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1747 ** to [sqlite3_config()].
1748 ** ^It is harmless, apart from the wasted memory,
1749 ** for the sz parameter to be larger than necessary. The first
@@ -1872,10 +1919,21 @@
1919 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1920 ** is a pointer to an integer and writes into that integer the number of extra
1921 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
1922 ** The amount of extra space required can change depending on the compiler,
1923 ** target platform, and SQLite version.
1924 **
1925 ** [[SQLITE_CONFIG_PMASZ]]
1926 ** <dt>SQLITE_CONFIG_PMASZ
1927 ** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
1928 ** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
1929 ** sorter to that integer. The default minimum PMA Size is set by the
1930 ** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
1931 ** to help with sort operations when multithreaded sorting
1932 ** is enabled (using the [PRAGMA threads] command) and the amount of content
1933 ** to be sorted exceeds the page size times the minimum of the
1934 ** [PRAGMA cache_size] setting and this value.
1935 ** </dl>
1936 */
1937 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1938 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1939 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1898,10 +1956,11 @@
1956 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1957 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1958 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1959 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1960 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
1961 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
1962
1963 /*
1964 ** CAPI3REF: Database Connection Configuration Options
1965 **
1966 ** These constants are the available integer configuration options that
@@ -7307,16 +7366,14 @@
7366
7367 /*
7368 ** CAPI3REF: Write-Ahead Log Commit Hook
7369 **
7370 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7371 ** is invoked each time data is committed to a database in wal mode.
 
 
7372 **
7373 ** ^(The callback is invoked by SQLite after the commit has taken place and
7374 ** the associated write-lock on the database released)^, so the implementation
7375 ** may read, write or [checkpoint] the database as required.
7376 **
7377 ** ^The first parameter passed to the callback function when it is invoked
7378 ** is a copy of the third parameter passed to sqlite3_wal_hook() when
7379 ** registering the callback. ^The second is a copy of the database handle.
@@ -7603,10 +7660,14 @@
7660 **
7661 ** The following constants can be used for the T parameter to the
7662 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7663 ** different metric for sqlite3_stmt_scanstatus() to return.
7664 **
7665 ** When the value returned to V is a string, space to hold that string is
7666 ** managed by the prepared statement S and will be automatically freed when
7667 ** S is finalized.
7668 **
7669 ** <dl>
7670 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7671 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
7672 ** set to the total number of times that the X-th loop has run.</dd>
7673 **
@@ -7648,11 +7709,18 @@
7709 #define SQLITE_SCANSTAT_SELECTID 5
7710
7711 /*
7712 ** CAPI3REF: Prepared Statement Scan Status
7713 **
7714 ** This interface returns information about the predicted and measured
7715 ** performance for pStmt. Advanced applications can use this
7716 ** interface to compare the predicted and the measured performance and
7717 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
7718 **
7719 ** Since this interface is expected to be rarely used, it is only
7720 ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
7721 ** compile-time option.
7722 **
7723 ** The "iScanStatusOp" parameter determines which status information to return.
7724 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
7725 ** of this interface is undefined.
7726 ** ^The requested measurement is written into a variable pointed to by
@@ -7666,13 +7734,10 @@
7734 ** ^Statistics might not be available for all loops in all statements. ^In cases
7735 ** where there exist loops with no available statistics, this function behaves
7736 ** as if the loop did not exist - it returns non-zero and leave the variable
7737 ** that pOut points to unchanged.
7738 **
 
 
 
7739 ** See also: [sqlite3_stmt_scanstatus_reset()]
7740 */
7741 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7742 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7743 int idx, /* Index of loop to report on */
@@ -9100,11 +9165,11 @@
9165 #define _BTREE_H_
9166
9167 /* TODO: This definition is just included so other modules compile. It
9168 ** needs to be revisited.
9169 */
9170 #define SQLITE_N_BTREE_META 16
9171
9172 /*
9173 ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
9174 ** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
9175 */
@@ -9215,10 +9280,15 @@
9280 ** offset = 36 + (idx * 4)
9281 **
9282 ** For example, the free-page-count field is located at byte offset 36 of
9283 ** the database file header. The incr-vacuum-flag field is located at
9284 ** byte offset 64 (== 36+4*7).
9285 **
9286 ** The BTREE_DATA_VERSION value is not really a value stored in the header.
9287 ** It is a read-only number computed by the pager. But we merge it with
9288 ** the header value access routines since its access pattern is the same.
9289 ** Call it a "virtual meta value".
9290 */
9291 #define BTREE_FREE_PAGE_COUNT 0
9292 #define BTREE_SCHEMA_VERSION 1
9293 #define BTREE_FILE_FORMAT 2
9294 #define BTREE_DEFAULT_CACHE_SIZE 3
@@ -9225,10 +9295,11 @@
9295 #define BTREE_LARGEST_ROOT_PAGE 4
9296 #define BTREE_TEXT_ENCODING 5
9297 #define BTREE_USER_VERSION 6
9298 #define BTREE_INCR_VACUUM 7
9299 #define BTREE_APPLICATION_ID 8
9300 #define BTREE_DATA_VERSION 15 /* A virtual meta-value */
9301
9302 /*
9303 ** Values that may be OR'd together to form the second argument of an
9304 ** sqlite3BtreeCursorHints() call.
9305 */
@@ -10006,10 +10077,11 @@
10077 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager);
10078 #endif
10079
10080 /* Functions used to query pager state and configuration. */
10081 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
10082 SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*);
10083 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
10084 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
10085 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int);
10086 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
10087 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
@@ -10747,10 +10819,11 @@
10819 i64 szMmap; /* Default mmap_size setting */
10820 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
10821 int errCode; /* Most recent error code (SQLITE_*) */
10822 int errMask; /* & result codes with this before returning */
10823 u16 dbOptFlags; /* Flags to enable/disable optimizations */
10824 u8 enc; /* Text encoding */
10825 u8 autoCommit; /* The auto-commit flag. */
10826 u8 temp_store; /* 1: file 2: memory 0: default */
10827 u8 mallocFailed; /* True if we have seen a malloc failure */
10828 u8 dfltLockMode; /* Default locking-mode for attached dbs */
10829 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
@@ -10848,11 +10921,12 @@
10921 };
10922
10923 /*
10924 ** A macro to discover the encoding of a database.
10925 */
10926 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
10927 #define ENC(db) ((db)->enc)
10928
10929 /*
10930 ** Possible values for the sqlite3.flags.
10931 */
10932 #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
@@ -11472,11 +11546,10 @@
11546 Index *pNext; /* The next index associated with the same table */
11547 Schema *pSchema; /* Schema containing this index */
11548 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
11549 char **azColl; /* Array of collation sequence names for index */
11550 Expr *pPartIdxWhere; /* WHERE clause for partial indices */
 
11551 int tnum; /* DB Page containing root of this index */
11552 LogEst szIdxRow; /* Estimated average row size in bytes */
11553 u16 nKeyCol; /* Number of columns forming the key */
11554 u16 nColumn; /* Number of columns stored in the index */
11555 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
@@ -12036,11 +12109,11 @@
12109 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
12110 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
12111 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
12112 #define SF_Compound 0x0040 /* Part of a compound query */
12113 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
12114 #define SF_AllValues 0x0100 /* All terms of compound are VALUES */
12115 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
12116 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
12117 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
12118 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
12119
@@ -12526,10 +12599,11 @@
12599 void *pPage; /* Page cache memory */
12600 int szPage; /* Size of each page in pPage[] */
12601 int nPage; /* Number of pages in pPage[] */
12602 int mxParserStack; /* maximum depth of the parser stack */
12603 int sharedCacheEnabled; /* true if shared-cache mode enabled */
12604 u32 szPma; /* Maximum Sorter PMA size */
12605 /* The above might be initialized to non-zero. The following need to always
12606 ** initially be zero, however. */
12607 int isInit; /* True after initialization has finished */
12608 int inProgress; /* True while initialization in progress */
12609 int isMutexInit; /* True after mutexes are initialized */
@@ -12663,11 +12737,11 @@
12737 ** FTS4 is really an extension for FTS3. It is enabled using the
12738 ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call
12739 ** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3.
12740 */
12741 #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3)
12742 # define SQLITE_ENABLE_FTS3 1
12743 #endif
12744
12745 /*
12746 ** The ctype.h header is needed for non-ASCII systems. It is also
12747 ** needed by FTS3 when FTS3 is included in the amalgamation.
@@ -13448,11 +13522,11 @@
13522 ** print I/O tracing messages.
13523 */
13524 #ifdef SQLITE_ENABLE_IOTRACE
13525 # define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; }
13526 SQLITE_PRIVATE void sqlite3VdbeIOTraceSql(Vdbe*);
13527 void (*sqlite3IoTrace)(const char*,...);
13528 #else
13529 # define IOTRACE(A)
13530 # define sqlite3VdbeIOTraceSql(X)
13531 #endif
13532
@@ -13661,10 +13735,17 @@
13735 */
13736 #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
13737 # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
13738 #endif
13739
13740 /* The minimum PMA size is set to this value multiplied by the database
13741 ** page size in bytes.
13742 */
13743 #ifndef SQLITE_SORTER_PMASZ
13744 # define SQLITE_SORTER_PMASZ 250
13745 #endif
13746
13747 /*
13748 ** The following singleton contains the global configuration for
13749 ** the SQLite library.
13750 */
13751 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
@@ -13691,10 +13772,11 @@
13772 (void*)0, /* pPage */
13773 0, /* szPage */
13774 0, /* nPage */
13775 0, /* mxParserStack */
13776 0, /* sharedCacheEnabled */
13777 SQLITE_SORTER_PMASZ, /* szPma */
13778 /* All the rest should always be initialized to zero */
13779 0, /* isInit */
13780 0, /* inProgress */
13781 0, /* isMutexInit */
13782 0, /* isMallocInit */
@@ -13797,355 +13879,355 @@
13879 /* These macros are provided to "stringify" the value of the define
13880 ** for those options in which the value is meaningful. */
13881 #define CTIMEOPT_VAL_(opt) #opt
13882 #define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt)
13883
13884 #if SQLITE_32BIT_ROWID
13885 "32BIT_ROWID",
13886 #endif
13887 #if SQLITE_4_BYTE_ALIGNED_MALLOC
13888 "4_BYTE_ALIGNED_MALLOC",
13889 #endif
13890 #if SQLITE_CASE_SENSITIVE_LIKE
13891 "CASE_SENSITIVE_LIKE",
13892 #endif
13893 #if SQLITE_CHECK_PAGES
13894 "CHECK_PAGES",
13895 #endif
13896 #if SQLITE_COVERAGE_TEST
13897 "COVERAGE_TEST",
13898 #endif
13899 #if SQLITE_DEBUG
13900 "DEBUG",
13901 #endif
13902 #if SQLITE_DEFAULT_LOCKING_MODE
13903 "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
13904 #endif
13905 #if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc)
13906 "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
13907 #endif
13908 #if SQLITE_DISABLE_DIRSYNC
13909 "DISABLE_DIRSYNC",
13910 #endif
13911 #if SQLITE_DISABLE_LFS
13912 "DISABLE_LFS",
13913 #endif
13914 #if SQLITE_ENABLE_API_ARMOR
13915 "ENABLE_API_ARMOR",
13916 #endif
13917 #if SQLITE_ENABLE_ATOMIC_WRITE
13918 "ENABLE_ATOMIC_WRITE",
13919 #endif
13920 #if SQLITE_ENABLE_CEROD
13921 "ENABLE_CEROD",
13922 #endif
13923 #if SQLITE_ENABLE_COLUMN_METADATA
13924 "ENABLE_COLUMN_METADATA",
13925 #endif
13926 #if SQLITE_ENABLE_EXPENSIVE_ASSERT
13927 "ENABLE_EXPENSIVE_ASSERT",
13928 #endif
13929 #if SQLITE_ENABLE_FTS1
13930 "ENABLE_FTS1",
13931 #endif
13932 #if SQLITE_ENABLE_FTS2
13933 "ENABLE_FTS2",
13934 #endif
13935 #if SQLITE_ENABLE_FTS3
13936 "ENABLE_FTS3",
13937 #endif
13938 #if SQLITE_ENABLE_FTS3_PARENTHESIS
13939 "ENABLE_FTS3_PARENTHESIS",
13940 #endif
13941 #if SQLITE_ENABLE_FTS4
13942 "ENABLE_FTS4",
13943 #endif
13944 #if SQLITE_ENABLE_ICU
13945 "ENABLE_ICU",
13946 #endif
13947 #if SQLITE_ENABLE_IOTRACE
13948 "ENABLE_IOTRACE",
13949 #endif
13950 #if SQLITE_ENABLE_LOAD_EXTENSION
13951 "ENABLE_LOAD_EXTENSION",
13952 #endif
13953 #if SQLITE_ENABLE_LOCKING_STYLE
13954 "ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE),
13955 #endif
13956 #if SQLITE_ENABLE_MEMORY_MANAGEMENT
13957 "ENABLE_MEMORY_MANAGEMENT",
13958 #endif
13959 #if SQLITE_ENABLE_MEMSYS3
13960 "ENABLE_MEMSYS3",
13961 #endif
13962 #if SQLITE_ENABLE_MEMSYS5
13963 "ENABLE_MEMSYS5",
13964 #endif
13965 #if SQLITE_ENABLE_OVERSIZE_CELL_CHECK
13966 "ENABLE_OVERSIZE_CELL_CHECK",
13967 #endif
13968 #if SQLITE_ENABLE_RTREE
13969 "ENABLE_RTREE",
13970 #endif
13971 #if defined(SQLITE_ENABLE_STAT4)
13972 "ENABLE_STAT4",
13973 #elif defined(SQLITE_ENABLE_STAT3)
13974 "ENABLE_STAT3",
13975 #endif
13976 #if SQLITE_ENABLE_UNLOCK_NOTIFY
13977 "ENABLE_UNLOCK_NOTIFY",
13978 #endif
13979 #if SQLITE_ENABLE_UPDATE_DELETE_LIMIT
13980 "ENABLE_UPDATE_DELETE_LIMIT",
13981 #endif
13982 #if SQLITE_HAS_CODEC
13983 "HAS_CODEC",
13984 #endif
13985 #if HAVE_ISNAN || SQLITE_HAVE_ISNAN
13986 "HAVE_ISNAN",
13987 #endif
13988 #if SQLITE_HOMEGROWN_RECURSIVE_MUTEX
13989 "HOMEGROWN_RECURSIVE_MUTEX",
13990 #endif
13991 #if SQLITE_IGNORE_AFP_LOCK_ERRORS
13992 "IGNORE_AFP_LOCK_ERRORS",
13993 #endif
13994 #if SQLITE_IGNORE_FLOCK_LOCK_ERRORS
13995 "IGNORE_FLOCK_LOCK_ERRORS",
13996 #endif
13997 #ifdef SQLITE_INT64_TYPE
13998 "INT64_TYPE",
13999 #endif
14000 #if SQLITE_LOCK_TRACE
14001 "LOCK_TRACE",
14002 #endif
14003 #if defined(SQLITE_MAX_MMAP_SIZE) && !defined(SQLITE_MAX_MMAP_SIZE_xc)
14004 "MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE),
14005 #endif
14006 #ifdef SQLITE_MAX_SCHEMA_RETRY
14007 "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
14008 #endif
14009 #if SQLITE_MEMDEBUG
14010 "MEMDEBUG",
14011 #endif
14012 #if SQLITE_MIXED_ENDIAN_64BIT_FLOAT
14013 "MIXED_ENDIAN_64BIT_FLOAT",
14014 #endif
14015 #if SQLITE_NO_SYNC
14016 "NO_SYNC",
14017 #endif
14018 #if SQLITE_OMIT_ALTERTABLE
14019 "OMIT_ALTERTABLE",
14020 #endif
14021 #if SQLITE_OMIT_ANALYZE
14022 "OMIT_ANALYZE",
14023 #endif
14024 #if SQLITE_OMIT_ATTACH
14025 "OMIT_ATTACH",
14026 #endif
14027 #if SQLITE_OMIT_AUTHORIZATION
14028 "OMIT_AUTHORIZATION",
14029 #endif
14030 #if SQLITE_OMIT_AUTOINCREMENT
14031 "OMIT_AUTOINCREMENT",
14032 #endif
14033 #if SQLITE_OMIT_AUTOINIT
14034 "OMIT_AUTOINIT",
14035 #endif
14036 #if SQLITE_OMIT_AUTOMATIC_INDEX
14037 "OMIT_AUTOMATIC_INDEX",
14038 #endif
14039 #if SQLITE_OMIT_AUTORESET
14040 "OMIT_AUTORESET",
14041 #endif
14042 #if SQLITE_OMIT_AUTOVACUUM
14043 "OMIT_AUTOVACUUM",
14044 #endif
14045 #if SQLITE_OMIT_BETWEEN_OPTIMIZATION
14046 "OMIT_BETWEEN_OPTIMIZATION",
14047 #endif
14048 #if SQLITE_OMIT_BLOB_LITERAL
14049 "OMIT_BLOB_LITERAL",
14050 #endif
14051 #if SQLITE_OMIT_BTREECOUNT
14052 "OMIT_BTREECOUNT",
14053 #endif
14054 #if SQLITE_OMIT_BUILTIN_TEST
14055 "OMIT_BUILTIN_TEST",
14056 #endif
14057 #if SQLITE_OMIT_CAST
14058 "OMIT_CAST",
14059 #endif
14060 #if SQLITE_OMIT_CHECK
14061 "OMIT_CHECK",
14062 #endif
14063 #if SQLITE_OMIT_COMPLETE
14064 "OMIT_COMPLETE",
14065 #endif
14066 #if SQLITE_OMIT_COMPOUND_SELECT
14067 "OMIT_COMPOUND_SELECT",
14068 #endif
14069 #if SQLITE_OMIT_CTE
14070 "OMIT_CTE",
14071 #endif
14072 #if SQLITE_OMIT_DATETIME_FUNCS
14073 "OMIT_DATETIME_FUNCS",
14074 #endif
14075 #if SQLITE_OMIT_DECLTYPE
14076 "OMIT_DECLTYPE",
14077 #endif
14078 #if SQLITE_OMIT_DEPRECATED
14079 "OMIT_DEPRECATED",
14080 #endif
14081 #if SQLITE_OMIT_DISKIO
14082 "OMIT_DISKIO",
14083 #endif
14084 #if SQLITE_OMIT_EXPLAIN
14085 "OMIT_EXPLAIN",
14086 #endif
14087 #if SQLITE_OMIT_FLAG_PRAGMAS
14088 "OMIT_FLAG_PRAGMAS",
14089 #endif
14090 #if SQLITE_OMIT_FLOATING_POINT
14091 "OMIT_FLOATING_POINT",
14092 #endif
14093 #if SQLITE_OMIT_FOREIGN_KEY
14094 "OMIT_FOREIGN_KEY",
14095 #endif
14096 #if SQLITE_OMIT_GET_TABLE
14097 "OMIT_GET_TABLE",
14098 #endif
14099 #if SQLITE_OMIT_INCRBLOB
14100 "OMIT_INCRBLOB",
14101 #endif
14102 #if SQLITE_OMIT_INTEGRITY_CHECK
14103 "OMIT_INTEGRITY_CHECK",
14104 #endif
14105 #if SQLITE_OMIT_LIKE_OPTIMIZATION
14106 "OMIT_LIKE_OPTIMIZATION",
14107 #endif
14108 #if SQLITE_OMIT_LOAD_EXTENSION
14109 "OMIT_LOAD_EXTENSION",
14110 #endif
14111 #if SQLITE_OMIT_LOCALTIME
14112 "OMIT_LOCALTIME",
14113 #endif
14114 #if SQLITE_OMIT_LOOKASIDE
14115 "OMIT_LOOKASIDE",
14116 #endif
14117 #if SQLITE_OMIT_MEMORYDB
14118 "OMIT_MEMORYDB",
14119 #endif
14120 #if SQLITE_OMIT_OR_OPTIMIZATION
14121 "OMIT_OR_OPTIMIZATION",
14122 #endif
14123 #if SQLITE_OMIT_PAGER_PRAGMAS
14124 "OMIT_PAGER_PRAGMAS",
14125 #endif
14126 #if SQLITE_OMIT_PRAGMA
14127 "OMIT_PRAGMA",
14128 #endif
14129 #if SQLITE_OMIT_PROGRESS_CALLBACK
14130 "OMIT_PROGRESS_CALLBACK",
14131 #endif
14132 #if SQLITE_OMIT_QUICKBALANCE
14133 "OMIT_QUICKBALANCE",
14134 #endif
14135 #if SQLITE_OMIT_REINDEX
14136 "OMIT_REINDEX",
14137 #endif
14138 #if SQLITE_OMIT_SCHEMA_PRAGMAS
14139 "OMIT_SCHEMA_PRAGMAS",
14140 #endif
14141 #if SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
14142 "OMIT_SCHEMA_VERSION_PRAGMAS",
14143 #endif
14144 #if SQLITE_OMIT_SHARED_CACHE
14145 "OMIT_SHARED_CACHE",
14146 #endif
14147 #if SQLITE_OMIT_SUBQUERY
14148 "OMIT_SUBQUERY",
14149 #endif
14150 #if SQLITE_OMIT_TCL_VARIABLE
14151 "OMIT_TCL_VARIABLE",
14152 #endif
14153 #if SQLITE_OMIT_TEMPDB
14154 "OMIT_TEMPDB",
14155 #endif
14156 #if SQLITE_OMIT_TRACE
14157 "OMIT_TRACE",
14158 #endif
14159 #if SQLITE_OMIT_TRIGGER
14160 "OMIT_TRIGGER",
14161 #endif
14162 #if SQLITE_OMIT_TRUNCATE_OPTIMIZATION
14163 "OMIT_TRUNCATE_OPTIMIZATION",
14164 #endif
14165 #if SQLITE_OMIT_UTF16
14166 "OMIT_UTF16",
14167 #endif
14168 #if SQLITE_OMIT_VACUUM
14169 "OMIT_VACUUM",
14170 #endif
14171 #if SQLITE_OMIT_VIEW
14172 "OMIT_VIEW",
14173 #endif
14174 #if SQLITE_OMIT_VIRTUALTABLE
14175 "OMIT_VIRTUALTABLE",
14176 #endif
14177 #if SQLITE_OMIT_WAL
14178 "OMIT_WAL",
14179 #endif
14180 #if SQLITE_OMIT_WSD
14181 "OMIT_WSD",
14182 #endif
14183 #if SQLITE_OMIT_XFER_OPT
14184 "OMIT_XFER_OPT",
14185 #endif
14186 #if SQLITE_PERFORMANCE_TRACE
14187 "PERFORMANCE_TRACE",
14188 #endif
14189 #if SQLITE_PROXY_DEBUG
14190 "PROXY_DEBUG",
14191 #endif
14192 #if SQLITE_RTREE_INT_ONLY
14193 "RTREE_INT_ONLY",
14194 #endif
14195 #if SQLITE_SECURE_DELETE
14196 "SECURE_DELETE",
14197 #endif
14198 #if SQLITE_SMALL_STACK
14199 "SMALL_STACK",
14200 #endif
14201 #if SQLITE_SOUNDEX
14202 "SOUNDEX",
14203 #endif
14204 #if SQLITE_SYSTEM_MALLOC
14205 "SYSTEM_MALLOC",
14206 #endif
14207 #if SQLITE_TCL
14208 "TCL",
14209 #endif
14210 #if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc)
14211 "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
14212 #endif
14213 #if SQLITE_TEST
14214 "TEST",
14215 #endif
14216 #if defined(SQLITE_THREADSAFE)
14217 "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
14218 #endif
14219 #if SQLITE_USE_ALLOCA
14220 "USE_ALLOCA",
14221 #endif
14222 #if SQLITE_USER_AUTHENTICATION
14223 "USER_AUTHENTICATION",
14224 #endif
14225 #if SQLITE_WIN32_MALLOC
14226 "WIN32_MALLOC",
14227 #endif
14228 #if SQLITE_ZERO_MALLOC
14229 "ZERO_MALLOC"
14230 #endif
14231 };
14232
14233 /*
@@ -14156,11 +14238,11 @@
14238 ** is not required for a match.
14239 */
14240 SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
14241 int i, n;
14242
14243 #if SQLITE_ENABLE_API_ARMOR
14244 if( zOptName==0 ){
14245 (void)SQLITE_MISUSE_BKPT;
14246 return 0;
14247 }
14248 #endif
@@ -15384,12 +15466,13 @@
15466 **
15467 ** If the user has not indicated to use localtime_r() or localtime_s()
15468 ** already, check for an MSVC build environment that provides
15469 ** localtime_s().
15470 */
15471 #if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S \
15472 && defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
15473 #undef HAVE_LOCALTIME_S
15474 #define HAVE_LOCALTIME_S 1
15475 #endif
15476
15477 #ifndef SQLITE_OMIT_LOCALTIME
15478 /*
@@ -15405,12 +15488,11 @@
15488 ** library function localtime_r() is used to assist in the calculation of
15489 ** local time.
15490 */
15491 static int osLocaltime(time_t *t, struct tm *pTm){
15492 int rc;
15493 #if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S
 
15494 struct tm *pX;
15495 #if SQLITE_THREADSAFE>0
15496 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
15497 #endif
15498 sqlite3_mutex_enter(mutex);
@@ -15423,11 +15505,11 @@
15505 rc = pX==0;
15506 #else
15507 #ifndef SQLITE_OMIT_BUILTIN_TEST
15508 if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
15509 #endif
15510 #if HAVE_LOCALTIME_R
15511 rc = localtime_r(t, pTm)==0;
15512 #else
15513 rc = localtime_s(pTm, t);
15514 #endif /* HAVE_LOCALTIME_R */
15515 #endif /* HAVE_LOCALTIME_R || HAVE_LOCALTIME_S */
@@ -15867,12 +15949,14 @@
15949 DateTime x;
15950 u64 n;
15951 size_t i,j;
15952 char *z;
15953 sqlite3 *db;
15954 const char *zFmt;
15955 char zBuf[100];
15956 if( argc==0 ) return;
15957 zFmt = (const char*)sqlite3_value_text(argv[0]);
15958 if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return;
15959 db = sqlite3_context_db_handle(context);
15960 for(i=0, n=1; zFmt[i]; i++, n++){
15961 if( zFmt[i]=='%' ){
15962 switch( zFmt[i+1] ){
@@ -16062,11 +16146,11 @@
16146 UNUSED_PARAMETER(argv);
16147
16148 iT = sqlite3StmtCurrentTime(context);
16149 if( iT<=0 ) return;
16150 t = iT/1000 - 10000*(sqlite3_int64)21086676;
16151 #if HAVE_GMTIME_R
16152 pTm = gmtime_r(&t, &sNow);
16153 #else
16154 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
16155 pTm = gmtime(&t);
16156 if( pTm ) memcpy(&sNow, pTm, sizeof(sNow));
@@ -16736,13 +16820,13 @@
16820
16821 /*
16822 ** The malloc.h header file is needed for malloc_usable_size() function
16823 ** on some systems (e.g. Linux).
16824 */
16825 #if HAVE_MALLOC_H && HAVE_MALLOC_USABLE_SIZE
16826 # define SQLITE_USE_MALLOC_H 1
16827 # define SQLITE_USE_MALLOC_USABLE_SIZE 1
16828 /*
16829 ** The MSVCRT has malloc_usable_size(), but it is called _msize(). The
16830 ** use of _msize() is automatic, but can be disabled by compiling with
16831 ** -DSQLITE_WITHOUT_MSIZE. Using the _msize() function also requires
16832 ** the malloc.h header file.
@@ -19976,10 +20060,16 @@
20060 #endif
20061 }
20062 break;
20063 }
20064 default: {
20065 #ifdef SQLITE_ENABLE_API_ARMOR
20066 if( iType-2<0 || iType-2>=ArraySize(winMutex_staticMutexes) ){
20067 (void)SQLITE_MISUSE_BKPT;
20068 return 0;
20069 }
20070 #endif
20071 assert( iType-2 >= 0 );
20072 assert( iType-2 < ArraySize(winMutex_staticMutexes) );
20073 assert( winMutex_isInit==1 );
20074 p = &winMutex_staticMutexes[iType-2];
20075 #ifdef SQLITE_DEBUG
@@ -20971,21 +21061,10 @@
21061 ** This file contains code for a set of "printf"-like routines. These
21062 ** routines format strings much like the printf() from the standard C
21063 ** library, though the implementation here has enhancements to support
21064 ** SQLlite.
21065 */
 
 
 
 
 
 
 
 
 
 
 
21066
21067 /*
21068 ** Conversion types fall into various categories as defined by the
21069 ** following enumeration.
21070 */
@@ -22280,10 +22359,12 @@
22359 ** single threaded systems. Nothing in SQLite requires multiple threads.
22360 ** This interface exists so that applications that want to take advantage
22361 ** of multiple cores can do so, while also allowing applications to stay
22362 ** single-threaded if desired.
22363 */
22364 #if SQLITE_OS_WIN
22365 #endif
22366
22367 #if SQLITE_MAX_WORKER_THREADS>0
22368
22369 /********************************* Unix Pthreads ****************************/
22370 #if SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) && SQLITE_THREADSAFE>0
@@ -23066,11 +23147,11 @@
23147 ** This file contains functions for allocating memory, comparing
23148 ** strings, and stuff like that.
23149 **
23150 */
23151 /* #include <stdarg.h> */
23152 #if HAVE_ISNAN || SQLITE_HAVE_ISNAN
23153 # include <math.h>
23154 #endif
23155
23156 /*
23157 ** Routine needed to support the testcase() macro.
@@ -23107,11 +23188,11 @@
23188 ** Use the math library isnan() function if compiled with SQLITE_HAVE_ISNAN.
23189 ** Otherwise, we have our own implementation that works on most systems.
23190 */
23191 SQLITE_PRIVATE int sqlite3IsNaN(double x){
23192 int rc; /* The value return */
23193 #if !SQLITE_HAVE_ISNAN && !HAVE_ISNAN
23194 /*
23195 ** Systems that support the isnan() library function should probably
23196 ** make use of it by compiling with -DSQLITE_HAVE_ISNAN. But we have
23197 ** found that many systems do not have a working isnan() function so
23198 ** this implementation is provided as an alternative.
@@ -23137,13 +23218,13 @@
23218 # error SQLite will not work correctly with the -ffast-math option of GCC.
23219 #endif
23220 volatile double y = x;
23221 volatile double z = y;
23222 rc = (y!=z);
23223 #else /* if HAVE_ISNAN */
23224 rc = isnan(x);
23225 #endif /* HAVE_ISNAN */
23226 testcase( rc );
23227 return rc;
23228 }
23229 #endif /* SQLITE_OMIT_FLOATING_POINT */
23230
@@ -28460,13 +28541,13 @@
28541
28542 /*
28543 ** We do not trust systems to provide a working fdatasync(). Some do.
28544 ** Others do no. To be safe, we will stick with the (slightly slower)
28545 ** fsync(). If you know that your system does support fdatasync() correctly,
28546 ** then simply compile with -Dfdatasync=fdatasync or -DHAVE_FDATASYNC
28547 */
28548 #if !defined(fdatasync) && !HAVE_FDATASYNC
28549 # define fdatasync fsync
28550 #endif
28551
28552 /*
28553 ** Define HAVE_FULLFSYNC to 0 or 1 depending on whether or not
@@ -28783,28 +28864,32 @@
28864 do{
28865 err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size);
28866 }while( err==EINTR );
28867 if( err ) return SQLITE_IOERR_WRITE;
28868 #else
28869 /* If the OS does not have posix_fallocate(), fake it. Write a
28870 ** single byte to the last byte in each block that falls entirely
28871 ** within the extended region. Then, if required, a single byte
28872 ** at offset (nSize-1), to set the size of the file correctly.
28873 ** This is a similar technique to that used by glibc on systems
28874 ** that do not have a real fallocate() call.
28875 */
28876 int nBlk = buf.st_blksize; /* File-system block size */
28877 int nWrite = 0; /* Number of bytes written by seekAndWrite */
28878 i64 iWrite; /* Next offset to write to */
28879
 
 
 
 
28880 iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
28881 assert( iWrite>=buf.st_size );
28882 assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) );
28883 assert( ((iWrite+1)%nBlk)==0 );
28884 for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){
28885 nWrite = seekAndWrite(pFile, iWrite, "", 1);
28886 if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
28887 }
28888 if( nWrite==0 || (nSize%nBlk) ){
28889 nWrite = seekAndWrite(pFile, nSize-1, "", 1);
28890 if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
28891 }
28892 #endif
28893 }
28894 }
28895
@@ -34018,12 +34103,12 @@
34103 */
34104 SQLITE_API int sqlite3_win32_reset_heap(){
34105 int rc;
34106 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
34107 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
34108 MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); )
34109 MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); )
34110 sqlite3_mutex_enter(pMaster);
34111 sqlite3_mutex_enter(pMem);
34112 winMemAssertMagic();
34113 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
34114 /*
@@ -35294,11 +35379,11 @@
35379 sqlite3_file *id, /* File to read from */
35380 void *pBuf, /* Write content into this buffer */
35381 int amt, /* Number of bytes to read */
35382 sqlite3_int64 offset /* Begin reading at this offset */
35383 ){
35384 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
35385 OVERLAPPED overlapped; /* The offset for ReadFile. */
35386 #endif
35387 winFile *pFile = (winFile*)id; /* file handle */
35388 DWORD nRead; /* Number of bytes actually read from file */
35389 int nRetry = 0; /* Number of retrys */
@@ -35326,11 +35411,11 @@
35411 offset += nCopy;
35412 }
35413 }
35414 #endif
35415
35416 #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
35417 if( winSeekFile(pFile, offset) ){
35418 OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h));
35419 return SQLITE_FULL;
35420 }
35421 while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
@@ -35398,32 +35483,32 @@
35483 offset += nCopy;
35484 }
35485 }
35486 #endif
35487
35488 #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
35489 rc = winSeekFile(pFile, offset);
35490 if( rc==0 ){
35491 #else
35492 {
35493 #endif
35494 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
35495 OVERLAPPED overlapped; /* The offset for WriteFile. */
35496 #endif
35497 u8 *aRem = (u8 *)pBuf; /* Data yet to be written */
35498 int nRem = amt; /* Number of bytes yet to be written */
35499 DWORD nWrite; /* Bytes written by each WriteFile() call */
35500 DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */
35501
35502 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
35503 memset(&overlapped, 0, sizeof(OVERLAPPED));
35504 overlapped.Offset = (LONG)(offset & 0xffffffff);
35505 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
35506 #endif
35507
35508 while( nRem>0 ){
35509 #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
35510 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
35511 #else
35512 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){
35513 #endif
35514 if( winRetryIoerr(&nRetry, &lastErrno) ) continue;
@@ -35432,11 +35517,11 @@
35517 assert( nWrite==0 || nWrite<=(DWORD)nRem );
35518 if( nWrite==0 || nWrite>(DWORD)nRem ){
35519 lastErrno = osGetLastError();
35520 break;
35521 }
35522 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
35523 offset += nWrite;
35524 overlapped.Offset = (LONG)(offset & 0xffffffff);
35525 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
35526 #endif
35527 aRem += nWrite;
@@ -38813,22 +38898,10 @@
38898 void *pStress; /* Argument to xStress */
38899 sqlite3_pcache *pCache; /* Pluggable cache module */
38900 PgHdr *pPage1; /* Reference to page 1 */
38901 };
38902
 
 
 
 
 
 
 
 
 
 
 
 
38903 /********************************** Linked List Management ********************/
38904
38905 /* Allowed values for second argument to pcacheManageDirtyList() */
38906 #define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
38907 #define PCACHE_DIRTYLIST_ADD 2 /* Add pPage to the dirty list */
@@ -38978,11 +39051,12 @@
39051 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
39052 assert( pCache->nRef==0 && pCache->pDirty==0 );
39053 if( pCache->szPage ){
39054 sqlite3_pcache *pNew;
39055 pNew = sqlite3GlobalConfig.pcache2.xCreate(
39056 szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
39057 pCache->bPurgeable
39058 );
39059 if( pNew==0 ) return SQLITE_NOMEM;
39060 sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
39061 if( pCache->pCache ){
39062 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
@@ -39437,11 +39511,11 @@
39511
39512 /*
39513 ** Return the size of the header added by this middleware layer
39514 ** in the page-cache hierarchy.
39515 */
39516 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); }
39517
39518
39519 #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
39520 /*
39521 ** For all dirty pages currently in the cache, invoke the specified
@@ -39753,11 +39827,11 @@
39827 pcache1Free(pPg);
39828 sqlite3_free(p);
39829 pPg = 0;
39830 }
39831 #else
39832 pPg = pcache1Alloc(ROUND8(sizeof(PgHdr1)) + pCache->szPage + pCache->szExtra);
39833 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
39834 #endif
39835 pcache1EnterMutex(pCache->pGroup);
39836
39837 if( pPg ){
@@ -40441,11 +40515,11 @@
40515 }
40516
40517 /*
40518 ** Return the size of the header on each page of this PCACHE implementation.
40519 */
40520 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return ROUND8(sizeof(PgHdr1)); }
40521
40522 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40523 /*
40524 ** This function is called to free superfluous dynamically allocated memory
40525 ** held by the pager system. Memory in use by any SQLite pager allocated
@@ -41799,10 +41873,12 @@
41873 u8 eLock; /* Current lock held on database file */
41874 u8 changeCountDone; /* Set after incrementing the change-counter */
41875 u8 setMaster; /* True if a m-j name has been written to jrnl */
41876 u8 doNotSpill; /* Do not spill the cache when non-zero */
41877 u8 subjInMemory; /* True to use in-memory sub-journals */
41878 u8 bUseFetch; /* True to use xFetch() */
41879 u8 hasBeenUsed; /* True if any content previously read from this pager*/
41880 Pgno dbSize; /* Number of pages in the database */
41881 Pgno dbOrigSize; /* dbSize before the current transaction */
41882 Pgno dbFileSize; /* Number of pages in the database file */
41883 Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */
41884 int errCode; /* One of several kinds of errors */
@@ -41816,13 +41892,13 @@
41892 i64 journalOff; /* Current write offset in the journal file */
41893 i64 journalHdr; /* Byte offset to previous journal header */
41894 sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
41895 PagerSavepoint *aSavepoint; /* Array of active savepoints */
41896 int nSavepoint; /* Number of elements in aSavepoint[] */
41897 u32 iDataVersion; /* Changes whenever database content changes */
41898 char dbFileVers[16]; /* Changes whenever database file changes */
41899
 
41900 int nMmapOut; /* Number of mmap pages currently outstanding */
41901 sqlite3_int64 szMmap; /* Desired maximum mmap size */
41902 PgHdr *pMmapFreelist; /* List of free mmap page headers (pDirty) */
41903 /*
41904 ** End of the routinely-changing class members
@@ -42834,13 +42910,22 @@
42910
42911 /*
42912 ** Discard the entire contents of the in-memory page-cache.
42913 */
42914 static void pager_reset(Pager *pPager){
42915 pPager->iDataVersion++;
42916 sqlite3BackupRestart(pPager->pBackup);
42917 sqlite3PcacheClear(pPager->pPCache);
42918 }
42919
42920 /*
42921 ** Return the pPager->iDataVersion value
42922 */
42923 SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager *pPager){
42924 assert( pPager->eState>PAGER_OPEN );
42925 return pPager->iDataVersion;
42926 }
42927
42928 /*
42929 ** Free all structures in the Pager.aSavepoint[] array and set both
42930 ** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
42931 ** if it is open and the pager is not in exclusive mode.
@@ -45040,11 +45125,11 @@
45125 Pgno pgno, /* Page number */
45126 void *pData, /* xFetch()'d data for this page */
45127 PgHdr **ppPage /* OUT: Acquired page object */
45128 ){
45129 PgHdr *p; /* Memory mapped page to return */
45130
45131 if( pPager->pMmapFreelist ){
45132 *ppPage = p = pPager->pMmapFreelist;
45133 pPager->pMmapFreelist = p->pDirty;
45134 p->pDirty = 0;
45135 memset(p->pExtra, 0, pPager->nExtra);
@@ -46271,20 +46356,16 @@
46356 assert( (pPager->eLock==SHARED_LOCK)
46357 || (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK)
46358 );
46359 }
46360
46361 if( !pPager->tempFile && pPager->hasBeenUsed ){
46362 /* The shared-lock has just been acquired then check to
46363 ** see if the database has been modified. If the database has changed,
46364 ** flush the cache. The pPager->hasBeenUsed flag prevents this from
46365 ** occurring on the very first access to a file, in order to save a
46366 ** single unnecessary sqlite3OsRead() call at the start-up.
 
 
 
 
46367 **
46368 ** Database changes is detected by looking at 15 bytes beginning
46369 ** at offset 24 into the file. The first 4 of these 16 bytes are
46370 ** a 32-bit counter that is incremented with each change. The
46371 ** other bytes change randomly with each file change when
@@ -46445,10 +46526,11 @@
46526 assert( noContent==0 || bMmapOk==0 );
46527
46528 if( pgno==0 ){
46529 return SQLITE_CORRUPT_BKPT;
46530 }
46531 pPager->hasBeenUsed = 1;
46532
46533 /* If the pager is in the error state, return an error immediately.
46534 ** Otherwise, request the page from the PCache layer. */
46535 if( pPager->errCode!=SQLITE_OK ){
46536 rc = pPager->errCode;
@@ -46594,10 +46676,11 @@
46676 sqlite3_pcache_page *pPage;
46677 assert( pPager!=0 );
46678 assert( pgno!=0 );
46679 assert( pPager->pPCache!=0 );
46680 pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
46681 assert( pPage==0 || pPager->hasBeenUsed );
46682 return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
46683 }
46684
46685 /*
46686 ** Release a page reference.
@@ -47460,10 +47543,11 @@
47543 pPager->eState = PAGER_READER;
47544 return SQLITE_OK;
47545 }
47546
47547 PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
47548 pPager->iDataVersion++;
47549 rc = pager_end_transaction(pPager, pPager->setMaster, 1);
47550 return pager_error(pPager, rc);
47551 }
47552
47553 /*
@@ -50829,11 +50913,11 @@
50913 }
50914 nCollide = HASHTABLE_NSLOT;
50915 for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
50916 u32 iFrame = aHash[iKey] + iZero;
50917 if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
50918 assert( iFrame>iRead || CORRUPT_DB );
50919 iRead = iFrame;
50920 }
50921 if( (nCollide--)==0 ){
50922 return SQLITE_CORRUPT_BKPT;
50923 }
@@ -51935,10 +52019,11 @@
52019 u8 inTrans; /* TRANS_NONE, TRANS_READ or TRANS_WRITE */
52020 u8 sharable; /* True if we can share pBt with another db */
52021 u8 locked; /* True if db currently has pBt locked */
52022 int wantToLock; /* Number of nested calls to sqlite3BtreeEnter() */
52023 int nBackup; /* Number of backup operations reading this btree */
52024 u32 iDataVersion; /* Combines with pBt->pPager->iDataVersion */
52025 Btree *pNext; /* List of other sharable Btrees from the same db */
52026 Btree *pPrev; /* Back pointer of the same list */
52027 #ifndef SQLITE_OMIT_SHARED_CACHE
52028 BtLock lock; /* Object used to lock page 1 */
52029 #endif
@@ -56098,10 +56183,11 @@
56183 rc = sqlite3PagerCommitPhaseTwo(pBt->pPager);
56184 if( rc!=SQLITE_OK && bCleanup==0 ){
56185 sqlite3BtreeLeave(p);
56186 return rc;
56187 }
56188 p->iDataVersion--; /* Compensate for pPager->iDataVersion++; */
56189 pBt->inTransaction = TRANS_READ;
56190 btreeClearHasContent(pBt);
56191 }
56192
56193 btreeEndTransaction(p);
@@ -56461,11 +56547,11 @@
56547 }
56548 for(i=0; i<=pCur->iPage; i++){
56549 releasePage(pCur->apPage[i]);
56550 }
56551 unlockBtreeIfUnused(pBt);
56552 sqlite3_free(pCur->aOverflow);
56553 /* sqlite3_free(pCur); */
56554 sqlite3BtreeLeave(pBtree);
56555 }
56556 return SQLITE_OK;
56557 }
@@ -56755,10 +56841,11 @@
56841 pBuf += a;
56842 amt -= a;
56843 }else{
56844 offset -= pCur->info.nLocal;
56845 }
56846
56847
56848 if( rc==SQLITE_OK && amt>0 ){
56849 const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */
56850 Pgno nextPage;
56851
@@ -56773,12 +56860,12 @@
56860 ** means "not yet known" (the cache is lazily populated).
56861 */
56862 if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){
56863 int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
56864 if( nOvfl>pCur->nOvflAlloc ){
56865 Pgno *aNew = (Pgno*)sqlite3Realloc(
56866 pCur->aOverflow, nOvfl*2*sizeof(Pgno)
56867 );
56868 if( aNew==0 ){
56869 rc = SQLITE_NOMEM;
56870 }else{
56871 pCur->nOvflAlloc = nOvfl*2;
@@ -56821,10 +56908,11 @@
56908 ** Note that the aOverflow[] array must be allocated because eOp!=2
56909 ** here. If eOp==2, then offset==0 and this branch is never taken.
56910 */
56911 assert( eOp!=2 );
56912 assert( pCur->curFlags & BTCF_ValidOvfl );
56913 assert( pCur->pBtree->db==pBt->db );
56914 if( pCur->aOverflow[iIdx+1] ){
56915 nextPage = pCur->aOverflow[iIdx+1];
56916 }else{
56917 rc = getOverflowPage(pBt, nextPage, 0, &nextPage);
56918 }
@@ -59410,12 +59498,12 @@
59498 assert( leafCorrection==4 );
59499 if( szCell[nCell]<4 ){
59500 /* Do not allow any cells smaller than 4 bytes. If a smaller cell
59501 ** does exist, pad it with 0x00 bytes. */
59502 assert( szCell[nCell]==3 );
59503 assert( apCell[nCell]==&aSpace1[iSpace1-3] );
59504 aSpace1[iSpace1++] = 0x00;
59505 szCell[nCell] = 4;
59506 }
59507 }
59508 nCell++;
59509 }
@@ -60723,10 +60811,17 @@
60811 ** is read-only, the others are read/write.
60812 **
60813 ** The schema layer numbers meta values differently. At the schema
60814 ** layer (and the SetCookie and ReadCookie opcodes) the number of
60815 ** free pages is not visible. So Cookie[0] is the same as Meta[1].
60816 **
60817 ** This routine treats Meta[BTREE_DATA_VERSION] as a special case. Instead
60818 ** of reading the value out of the header, it instead loads the "DataVersion"
60819 ** from the pager. The BTREE_DATA_VERSION value is not actually stored in the
60820 ** database file. It is a number computed by the pager. But its access
60821 ** pattern is the same as header meta values, and so it is convenient to
60822 ** read it from this routine.
60823 */
60824 SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
60825 BtShared *pBt = p->pBt;
60826
60827 sqlite3BtreeEnter(p);
@@ -60733,11 +60828,15 @@
60828 assert( p->inTrans>TRANS_NONE );
60829 assert( SQLITE_OK==querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK) );
60830 assert( pBt->pPage1 );
60831 assert( idx>=0 && idx<=15 );
60832
60833 if( idx==BTREE_DATA_VERSION ){
60834 *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion;
60835 }else{
60836 *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
60837 }
60838
60839 /* If auto-vacuum is disabled in this build and this is an auto-vacuum
60840 ** database, mark the database as read-only. */
60841 #ifdef SQLITE_OMIT_AUTOVACUUM
60842 if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){
@@ -60824,11 +60923,11 @@
60923 if( pPage->leaf ){
60924 do {
60925 if( pCur->iPage==0 ){
60926 /* All pages of the b-tree have been visited. Return successfully. */
60927 *pnEntry = nEntry;
60928 return moveToRoot(pCur);
60929 }
60930 moveToParent(pCur);
60931 }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
60932
60933 pCur->aiIdx[pCur->iPage]++;
@@ -61680,11 +61779,11 @@
61779 }
61780
61781 /*
61782 ** Return the size of the header added to each page by this module.
61783 */
61784 SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return ROUND8(sizeof(MemPage)); }
61785
61786 /************** End of btree.c ***********************************************/
61787 /************** Begin file backup.c ******************************************/
61788 /*
61789 ** 2009 January 28
@@ -64444,36 +64543,39 @@
64543 **
64544 ** assert( sqlite3VdbeAssertMayAbort(pParse->pVdbe, pParse->mayAbort) );
64545 */
64546 SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
64547 int hasAbort = 0;
64548 int hasFkCounter = 0;
64549 Op *pOp;
64550 VdbeOpIter sIter;
64551 memset(&sIter, 0, sizeof(sIter));
64552 sIter.v = v;
64553
64554 while( (pOp = opIterNext(&sIter))!=0 ){
64555 int opcode = pOp->opcode;
64556 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
 
 
 
64557 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
64558 && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
64559 ){
64560 hasAbort = 1;
64561 break;
64562 }
64563 #ifndef SQLITE_OMIT_FOREIGN_KEY
64564 if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){
64565 hasFkCounter = 1;
64566 }
64567 #endif
64568 }
64569 sqlite3DbFree(v->db, sIter.apSub);
64570
64571 /* Return true if hasAbort==mayAbort. Or if a malloc failure occurred.
64572 ** If malloc failed, then the while() loop above may not have iterated
64573 ** through all opcodes and hasAbort may be set incorrectly. Return
64574 ** true for this case to prevent the assert() in the callers frame
64575 ** from failing. */
64576 return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter );
64577 }
64578 #endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */
64579
64580 /*
64581 ** Loop through the program looking for P2 values that are negative
@@ -68593,11 +68695,14 @@
68695 #ifndef SQLITE_OMIT_WAL
68696 int i;
68697 for(i=0; i<db->nDb; i++){
68698 Btree *pBt = db->aDb[i].pBt;
68699 if( pBt ){
68700 int nEntry;
68701 sqlite3BtreeEnter(pBt);
68702 nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
68703 sqlite3BtreeLeave(pBt);
68704 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
68705 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
68706 }
68707 }
68708 }
@@ -68773,11 +68878,10 @@
68878 ** program counter to 0 to ensure that when the statement is
68879 ** finalized or reset the parser error message is available via
68880 ** sqlite3_errmsg() and sqlite3_errcode().
68881 */
68882 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
 
68883 sqlite3DbFree(db, v->zErrMsg);
68884 if( !db->mallocFailed ){
68885 v->zErrMsg = sqlite3DbStrDup(db, zErr);
68886 v->rc = rc2;
68887 } else {
@@ -73838,12 +73942,12 @@
73942 pIdxKey->default_rc = 0;
73943 if( pOp->opcode==OP_NoConflict ){
73944 /* For the OP_NoConflict opcode, take the jump if any of the
73945 ** input fields are NULL, since any key with a NULL will not
73946 ** conflict */
73947 for(ii=0; ii<pIdxKey->nField; ii++){
73948 if( pIdxKey->aMem[ii].flags & MEM_Null ){
73949 pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
73950 break;
73951 }
73952 }
73953 }
@@ -77135,11 +77239,11 @@
77239 /*
77240 ** Hard-coded maximum amount of data to accumulate in memory before flushing
77241 ** to a level 0 PMA. The purpose of this limit is to prevent various integer
77242 ** overflows. 512MiB.
77243 */
77244 #define SQLITE_MAX_PMASZ (1<<29)
77245
77246 /*
77247 ** Private objects used by the sorter
77248 */
77249 typedef struct MergeEngine MergeEngine; /* Merge PMAs together */
@@ -77431,15 +77535,10 @@
77535 **
77536 ** void *SRVAL(SorterRecord *p) { return (void*)&p[1]; }
77537 */
77538 #define SRVAL(p) ((void*)((SorterRecord*)(p) + 1))
77539
 
 
 
 
 
77540
77541 /* Maximum number of PMAs that a single MergeEngine can merge */
77542 #define SORTER_MAX_MERGE_COUNT 16
77543
77544 static int vdbeIncrSwap(IncrMerger*);
@@ -77834,14 +77933,15 @@
77933 SortSubtask *pTask = &pSorter->aTask[i];
77934 pTask->pSorter = pSorter;
77935 }
77936
77937 if( !sqlite3TempInMemory(db) ){
77938 u32 szPma = sqlite3GlobalConfig.szPma;
77939 pSorter->mnPmaSize = szPma * pgsz;
77940 mxCache = db->aDb[0].pSchema->cache_size;
77941 if( mxCache<(int)szPma ) mxCache = (int)szPma;
77942 pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_PMASZ);
77943
77944 /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
77945 ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
77946 ** large heap allocations.
77947 */
@@ -78115,16 +78215,16 @@
78215 ** Whether or not the file does end up memory mapped of course depends on
78216 ** the specific VFS implementation.
78217 */
78218 static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){
78219 if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){
78220 void *p = 0;
78221 int chunksize = 4*1024;
78222 sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize);
78223 sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte);
78224 sqlite3OsFetch(pFd, 0, (int)nByte, &p);
78225 sqlite3OsUnfetch(pFd, 0, p);
78226 }
78227 }
78228 #else
78229 # define vdbeSorterExtendFile(x,y,z)
78230 #endif
@@ -79401,10 +79501,11 @@
79501 rc = vdbePmaReaderNext(pSorter->pReader);
79502 *pbEof = (pSorter->pReader->pFd==0);
79503 }else
79504 #endif
79505 /*if( !pSorter->bUseThreads )*/ {
79506 assert( pSorter->pMerger!=0 );
79507 assert( pSorter->pMerger->pTask==(&pSorter->aTask[0]) );
79508 rc = vdbeMergeEngineStep(pSorter->pMerger, pbEof);
79509 }
79510 }else{
79511 SorterRecord *pFree = pSorter->list.pList;
@@ -82167,11 +82268,11 @@
82268 Expr *pLeft, /* Left operand */
82269 Expr *pRight, /* Right operand */
82270 const Token *pToken /* Argument token */
82271 ){
82272 Expr *p;
82273 if( op==TK_AND && pLeft && pRight && pParse->nErr==0 ){
82274 /* Take advantage of short-circuit false optimization for AND */
82275 p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
82276 }else{
82277 p = sqlite3ExprAlloc(pParse->db, op, pToken, 1);
82278 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
@@ -85721,14 +85822,15 @@
85822 ** NEVER() will need to be removed. */
85823 if( pExpr->op==TK_COLUMN || NEVER(pExpr->op==TK_AGG_COLUMN) ){
85824 int i;
85825 struct SrcCount *p = pWalker->u.pSrcCount;
85826 SrcList *pSrc = p->pSrc;
85827 int nSrc = pSrc ? pSrc->nSrc : 0;
85828 for(i=0; i<nSrc; i++){
85829 if( pExpr->iTable==pSrc->a[i].iCursor ) break;
85830 }
85831 if( i<nSrc ){
85832 p->nThis++;
85833 }else{
85834 p->nOther++;
85835 }
85836 }
@@ -87302,11 +87404,11 @@
87404
87405 p->iGet = -1;
87406 p->mxSample = mxSample;
87407 p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[2])/(mxSample/3+1) + 1);
87408 p->current.anLt = &p->current.anEq[nColUp];
87409 p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]);
87410
87411 /* Set up the Stat4Accum.a[] and aBest[] arrays */
87412 p->a = (struct Stat4Sample*)&p->current.anLt[nColUp];
87413 p->aBest = &p->a[mxSample];
87414 pSpace = (u8*)(&p->a[mxSample+nCol]);
@@ -88895,17 +88997,19 @@
88997 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
88998 zErrDyn = sqlite3MPrintf(db,
88999 "attached databases must use the same text encoding as main database");
89000 rc = SQLITE_ERROR;
89001 }
89002 sqlite3BtreeEnter(aNew->pBt);
89003 pPager = sqlite3BtreePager(aNew->pBt);
89004 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
89005 sqlite3BtreeSecureDelete(aNew->pBt,
89006 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
89007 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
89008 sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK));
89009 #endif
89010 sqlite3BtreeLeave(aNew->pBt);
89011 }
89012 aNew->safety_level = 3;
89013 aNew->zName = sqlite3DbStrDup(db, zName);
89014 if( rc==SQLITE_OK && aNew->zName==0 ){
89015 rc = SQLITE_NOMEM;
@@ -90027,11 +90131,10 @@
90131 */
90132 static void freeIndex(sqlite3 *db, Index *p){
90133 #ifndef SQLITE_OMIT_ANALYZE
90134 sqlite3DeleteIndexSamples(db, p);
90135 #endif
 
90136 sqlite3ExprDelete(db, p->pPartIdxWhere);
90137 sqlite3DbFree(db, p->zColAff);
90138 if( p->isResized ) sqlite3DbFree(db, p->azColl);
90139 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
90140 sqlite3_free(p->aiRowEst);
@@ -91306,10 +91409,23 @@
91409 if( pPk==0 ) return;
91410 pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
91411 pTab->iPKey = -1;
91412 }else{
91413 pPk = sqlite3PrimaryKeyIndex(pTab);
91414 /*
91415 ** Remove all redundant columns from the PRIMARY KEY. For example, change
91416 ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
91417 ** code assumes the PRIMARY KEY contains no repeated columns.
91418 */
91419 for(i=j=1; i<pPk->nKeyCol; i++){
91420 if( hasColumn(pPk->aiColumn, j, pPk->aiColumn[i]) ){
91421 pPk->nColumn--;
91422 }else{
91423 pPk->aiColumn[j++] = pPk->aiColumn[i];
91424 }
91425 }
91426 pPk->nKeyCol = j;
91427 }
91428 pPk->isCovering = 1;
91429 assert( pPk!=0 );
91430 nPk = pPk->nKeyCol;
91431
@@ -93782,44 +93898,35 @@
93898 **
93899 ** The caller should invoke sqlite3KeyInfoUnref() on the returned object
93900 ** when it has finished using it.
93901 */
93902 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
93903 int i;
93904 int nCol = pIdx->nColumn;
93905 int nKey = pIdx->nKeyCol;
93906 KeyInfo *pKey;
93907 if( pParse->nErr ) return 0;
93908 if( pIdx->uniqNotNull ){
93909 pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
93910 }else{
93911 pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
93912 }
93913 if( pKey ){
93914 assert( sqlite3KeyInfoIsWriteable(pKey) );
93915 for(i=0; i<nCol; i++){
93916 char *zColl = pIdx->azColl[i];
93917 assert( zColl!=0 );
93918 pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 :
93919 sqlite3LocateCollSeq(pParse, zColl);
93920 pKey->aSortOrder[i] = pIdx->aSortOrder[i];
93921 }
93922 if( pParse->nErr ){
93923 sqlite3KeyInfoUnref(pKey);
93924 pKey = 0;
93925 }
93926 }
93927 return pKey;
 
 
 
 
 
 
 
 
 
 
 
 
 
93928 }
93929
93930 #ifndef SQLITE_OMIT_CTE
93931 /*
93932 ** This routine is invoked once per CTE by the parser while parsing a
@@ -94596,12 +94703,12 @@
94703 const char *zDb; /* Name of database holding pTab */
94704 int i; /* Loop counter */
94705 WhereInfo *pWInfo; /* Information about the WHERE clause */
94706 Index *pIdx; /* For looping over indices of the table */
94707 int iTabCur; /* Cursor number for the table */
94708 int iDataCur = 0; /* VDBE cursor for the canonical data source */
94709 int iIdxCur = 0; /* Cursor number of the first index */
94710 int nIdx; /* Number of indices */
94711 sqlite3 *db; /* Main database structure */
94712 AuthContext sContext; /* Authorization context */
94713 NameContext sNC; /* Name context to resolve expressions in */
94714 int iDb; /* Database number */
@@ -97436,11 +97543,11 @@
97543 assert( nIncr==1 );
97544 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
97545 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
97546 }else{
97547 if( nIncr>0 && pFKey->isDeferred==0 ){
97548 sqlite3MayAbort(pParse);
97549 }
97550 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
97551 }
97552
97553 sqlite3VdbeResolveLabel(v, iOk);
@@ -97507,10 +97614,14 @@
97614 ** This function is called to generate code executed when a row is deleted
97615 ** from the parent table of foreign key constraint pFKey and, if pFKey is
97616 ** deferred, when a row is inserted into the same table. When generating
97617 ** code for an SQL UPDATE operation, this function may be called twice -
97618 ** once to "delete" the old row and once to "insert" the new row.
97619 **
97620 ** Parameter nIncr is passed -1 when inserting a row (as this may decrease
97621 ** the number of FK violations in the db) or +1 when deleting one (as this
97622 ** may increase the number of FK constraint problems).
97623 **
97624 ** The code generated by this function scans through the rows in the child
97625 ** table that correspond to the parent table row being deleted or inserted.
97626 ** For each child row found, one of the following actions is taken:
97627 **
@@ -97624,17 +97735,13 @@
97735 sNameContext.pSrcList = pSrc;
97736 sNameContext.pParse = pParse;
97737 sqlite3ResolveExprNames(&sNameContext, pWhere);
97738
97739 /* Create VDBE to loop through the entries in pSrc that match the WHERE
97740 ** clause. For each row found, increment either the deferred or immediate
97741 ** foreign key constraint counter. */
 
97742 pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
 
 
 
97743 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
97744 if( pWInfo ){
97745 sqlite3WhereEnd(pWInfo);
97746 }
97747
@@ -97808,10 +97915,28 @@
97915 }
97916 }
97917 }
97918 return 0;
97919 }
97920
97921 /*
97922 ** Return true if the parser passed as the first argument is being
97923 ** used to code a trigger that is really a "SET NULL" action belonging
97924 ** to trigger pFKey.
97925 */
97926 static int isSetNullAction(Parse *pParse, FKey *pFKey){
97927 Parse *pTop = sqlite3ParseToplevel(pParse);
97928 if( pTop->pTriggerPrg ){
97929 Trigger *p = pTop->pTriggerPrg->pTrigger;
97930 if( (p==pFKey->apTrigger[0] && pFKey->aAction[0]==OE_SetNull)
97931 || (p==pFKey->apTrigger[1] && pFKey->aAction[1]==OE_SetNull)
97932 ){
97933 return 1;
97934 }
97935 }
97936 return 0;
97937 }
97938
97939 /*
97940 ** This function is called when inserting, deleting or updating a row of
97941 ** table pTab to generate VDBE code to perform foreign key constraint
97942 ** processing for the operation.
@@ -97861,11 +97986,11 @@
97986 Index *pIdx = 0; /* Index on key columns in pTo */
97987 int *aiFree = 0;
97988 int *aiCol;
97989 int iCol;
97990 int i;
97991 int bIgnore = 0;
97992
97993 if( aChange
97994 && sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
97995 && fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
97996 ){
@@ -97920,11 +98045,11 @@
98045 ** values read from the parent table are NULL. */
98046 if( db->xAuth ){
98047 int rcauth;
98048 char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName;
98049 rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb);
98050 bIgnore = (rcauth==SQLITE_IGNORE);
98051 }
98052 #endif
98053 }
98054
98055 /* Take a shared-cache advisory read-lock on the parent table. Allocate
@@ -97935,16 +98060,22 @@
98060
98061 if( regOld!=0 ){
98062 /* A row is being removed from the child table. Search for the parent.
98063 ** If the parent does not exist, removing the child row resolves an
98064 ** outstanding foreign key constraint violation. */
98065 fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1, bIgnore);
98066 }
98067 if( regNew!=0 && !isSetNullAction(pParse, pFKey) ){
98068 /* A row is being added to the child table. If a parent row cannot
98069 ** be found, adding the child row has violated the FK constraint.
98070 **
98071 ** If this operation is being performed as part of a trigger program
98072 ** that is actually a "SET NULL" action belonging to this very
98073 ** foreign key, then omit this scan altogether. As all child key
98074 ** values are guaranteed to be NULL, it is not possible for adding
98075 ** this row to cause an FK violation. */
98076 fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1, bIgnore);
98077 }
98078
98079 sqlite3DbFree(db, aiFree);
98080 }
98081
@@ -97961,12 +98092,12 @@
98092
98093 if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
98094 && !pParse->pToplevel && !pParse->isMultiWrite
98095 ){
98096 assert( regOld==0 && regNew!=0 );
98097 /* Inserting a single row into a parent table cannot cause (or fix)
98098 ** an immediate foreign key violation. So do nothing in this case. */
98099 continue;
98100 }
98101
98102 if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ){
98103 if( !isIgnoreErrors || db->mallocFailed ) return;
@@ -97986,17 +98117,32 @@
98117
98118 if( regNew!=0 ){
98119 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1);
98120 }
98121 if( regOld!=0 ){
98122 int eAction = pFKey->aAction[aChange!=0];
 
 
 
 
 
98123 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regOld, 1);
98124 /* If this is a deferred FK constraint, or a CASCADE or SET NULL
98125 ** action applies, then any foreign key violations caused by
98126 ** removing the parent key will be rectified by the action trigger.
98127 ** So do not set the "may-abort" flag in this case.
98128 **
98129 ** Note 1: If the FK is declared "ON UPDATE CASCADE", then the
98130 ** may-abort flag will eventually be set on this statement anyway
98131 ** (when this function is called as part of processing the UPDATE
98132 ** within the action trigger).
98133 **
98134 ** Note 2: At first glance it may seem like SQLite could simply omit
98135 ** all OP_FkCounter related scans when either CASCADE or SET NULL
98136 ** applies. The trouble starts if the CASCADE or SET NULL action
98137 ** trigger causes other triggers or action rules attached to the
98138 ** child table to fire. In these cases the fk constraint counters
98139 ** might be set incorrectly if any OP_FkCounter related scans are
98140 ** omitted. */
98141 if( !pFKey->isDeferred && eAction!=OE_Cascade && eAction!=OE_SetNull ){
98142 sqlite3MayAbort(pParse);
98143 }
98144 }
98145 pItem->zName = 0;
98146 sqlite3SrcListDelete(db, pSrc);
98147 }
98148 sqlite3DbFree(db, aiCol);
@@ -101895,10 +102041,11 @@
102041 #define PragTyp_KEY 38
102042 #define PragTyp_REKEY 39
102043 #define PragTyp_LOCK_STATUS 40
102044 #define PragTyp_PARSER_TRACE 41
102045 #define PragFlag_NeedSchema 0x01
102046 #define PragFlag_ReadOnly 0x02
102047 static const struct sPragmaNames {
102048 const char *const zName; /* Name of pragma */
102049 u8 ePragTyp; /* PragTyp_XXX value */
102050 u8 mPragFlag; /* Zero or more PragFlag_XXX values */
102051 u32 iArg; /* Extra argument */
@@ -101911,11 +102058,11 @@
102058 #endif
102059 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102060 { /* zName: */ "application_id",
102061 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102062 /* ePragFlag: */ 0,
102063 /* iArg: */ BTREE_APPLICATION_ID },
102064 #endif
102065 #if !defined(SQLITE_OMIT_AUTOVACUUM)
102066 { /* zName: */ "auto_vacuum",
102067 /* ePragTyp: */ PragTyp_AUTO_VACUUM,
102068 /* ePragFlag: */ PragFlag_NeedSchema,
@@ -101977,10 +102124,16 @@
102124 { /* zName: */ "data_store_directory",
102125 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
102126 /* ePragFlag: */ 0,
102127 /* iArg: */ 0 },
102128 #endif
102129 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102130 { /* zName: */ "data_version",
102131 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102132 /* ePragFlag: */ PragFlag_ReadOnly,
102133 /* iArg: */ BTREE_DATA_VERSION },
102134 #endif
102135 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
102136 { /* zName: */ "database_list",
102137 /* ePragTyp: */ PragTyp_DATABASE_LIST,
102138 /* ePragFlag: */ PragFlag_NeedSchema,
102139 /* iArg: */ 0 },
@@ -102032,12 +102185,12 @@
102185 #endif
102186 #endif
102187 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102188 { /* zName: */ "freelist_count",
102189 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102190 /* ePragFlag: */ PragFlag_ReadOnly,
102191 /* iArg: */ BTREE_FREE_PAGE_COUNT },
102192 #endif
102193 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
102194 { /* zName: */ "full_column_names",
102195 /* ePragTyp: */ PragTyp_FLAG,
102196 /* ePragFlag: */ 0,
@@ -102185,11 +102338,11 @@
102338 #endif
102339 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102340 { /* zName: */ "schema_version",
102341 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102342 /* ePragFlag: */ 0,
102343 /* iArg: */ BTREE_SCHEMA_VERSION },
102344 #endif
102345 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
102346 { /* zName: */ "secure_delete",
102347 /* ePragTyp: */ PragTyp_SECURE_DELETE,
102348 /* ePragFlag: */ 0,
@@ -102251,11 +102404,11 @@
102404 /* iArg: */ 0 },
102405 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
102406 { /* zName: */ "user_version",
102407 /* ePragTyp: */ PragTyp_HEADER_VALUE,
102408 /* ePragFlag: */ 0,
102409 /* iArg: */ BTREE_USER_VERSION },
102410 #endif
102411 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
102412 #if defined(SQLITE_DEBUG)
102413 { /* zName: */ "vdbe_addoptrace",
102414 /* ePragTyp: */ PragTyp_FLAG,
@@ -102294,11 +102447,11 @@
102447 /* ePragTyp: */ PragTyp_FLAG,
102448 /* ePragFlag: */ 0,
102449 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
102450 #endif
102451 };
102452 /* Number of pragmas: 58 on by default, 71 total. */
102453 /* End of the automatically generated pragma table.
102454 ***************************************************************************/
102455
102456 /*
102457 ** Interpret the given string as a safety level. Return 0 for OFF,
@@ -102544,11 +102697,11 @@
102697 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
102698 const char *zDb = 0; /* The database name */
102699 Token *pId; /* Pointer to <id> token */
102700 char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */
102701 int iDb; /* Database index for <database> */
102702 int lwr, upr, mid = 0; /* Binary search bounds */
102703 int rc; /* return value form SQLITE_FCNTL_PRAGMA */
102704 sqlite3 *db = pParse->db; /* The database connection */
102705 Db *pDb; /* The specific database being pragmaed */
102706 Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
102707
@@ -103904,11 +104057,12 @@
104057 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
104058 DbHasProperty(db, 0, DB_Empty)
104059 ){
104060 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
104061 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
104062 SCHEMA_ENC(db) = ENC(db) =
104063 pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
104064 break;
104065 }
104066 }
104067 if( !pEnc->zName ){
104068 sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
@@ -103949,28 +104103,13 @@
104103 **
104104 ** The user-version is not used internally by SQLite. It may be used by
104105 ** applications for any purpose.
104106 */
104107 case PragTyp_HEADER_VALUE: {
104108 int iCookie = aPragmaNames[mid].iArg; /* Which cookie to read or write */
104109 sqlite3VdbeUsesBtree(v, iDb);
104110 if( zRight && (aPragmaNames[mid].mPragFlag & PragFlag_ReadOnly)==0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104111 /* Write the specified cookie value */
104112 static const VdbeOpList setCookie[] = {
104113 { OP_Transaction, 0, 1, 0}, /* 0 */
104114 { OP_Integer, 0, 1, 0}, /* 1 */
104115 { OP_SetCookie, 0, 0, 1}, /* 2 */
@@ -104612,13 +104751,15 @@
104751 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
104752 int i, rc;
104753 int commit_internal = !(db->flags&SQLITE_InternChanges);
104754
104755 assert( sqlite3_mutex_held(db->mutex) );
104756 assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
104757 assert( db->init.busy==0 );
104758 rc = SQLITE_OK;
104759 db->init.busy = 1;
104760 ENC(db) = SCHEMA_ENC(db);
104761 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
104762 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
104763 rc = sqlite3InitOne(db, i, pzErrMsg);
104764 if( rc ){
104765 sqlite3ResetOneSchema(db, i);
@@ -105169,24 +105310,29 @@
105310 u8 sortFlags; /* Zero or more SORTFLAG_* bits */
105311 };
105312 #define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
105313
105314 /*
105315 ** Delete all the content of a Select structure. Deallocate the structure
105316 ** itself only if bFree is true.
105317 */
105318 static void clearSelect(sqlite3 *db, Select *p, int bFree){
105319 while( p ){
105320 Select *pPrior = p->pPrior;
105321 sqlite3ExprListDelete(db, p->pEList);
105322 sqlite3SrcListDelete(db, p->pSrc);
105323 sqlite3ExprDelete(db, p->pWhere);
105324 sqlite3ExprListDelete(db, p->pGroupBy);
105325 sqlite3ExprDelete(db, p->pHaving);
105326 sqlite3ExprListDelete(db, p->pOrderBy);
105327 sqlite3ExprDelete(db, p->pLimit);
105328 sqlite3ExprDelete(db, p->pOffset);
105329 sqlite3WithDelete(db, p->pWith);
105330 if( bFree ) sqlite3DbFree(db, p);
105331 p = pPrior;
105332 bFree = 1;
105333 }
105334 }
105335
105336 /*
105337 ** Initialize a SelectDest structure.
105338 */
@@ -105241,12 +105387,11 @@
105387 pNew->pOffset = pOffset;
105388 assert( pOffset==0 || pLimit!=0 );
105389 pNew->addrOpenEphm[0] = -1;
105390 pNew->addrOpenEphm[1] = -1;
105391 if( db->mallocFailed ) {
105392 clearSelect(db, pNew, pNew!=&standin);
 
105393 pNew = 0;
105394 }else{
105395 assert( pNew->pSrc!=0 || pParse->nErr>0 );
105396 }
105397 assert( pNew!=&standin );
@@ -105267,14 +105412,11 @@
105412
105413 /*
105414 ** Delete the given Select structure and all of its substructures.
105415 */
105416 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
105417 clearSelect(db, p, 1);
 
 
 
105418 }
105419
105420 /*
105421 ** Return a pointer to the right-most SELECT statement in a compound.
105422 */
@@ -107186,10 +107328,70 @@
107328 Parse *pParse, /* Parsing context */
107329 Select *p, /* The right-most of SELECTs to be coded */
107330 SelectDest *pDest /* What to do with query results */
107331 );
107332
107333 /*
107334 ** Error message for when two or more terms of a compound select have different
107335 ** size result sets.
107336 */
107337 static void selectWrongNumTermsError(Parse *pParse, Select *p){
107338 if( p->selFlags & SF_Values ){
107339 sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
107340 }else{
107341 sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
107342 " do not have the same number of result columns", selectOpName(p->op));
107343 }
107344 }
107345
107346 /*
107347 ** Handle the special case of a compound-select that originates from a
107348 ** VALUES clause. By handling this as a special case, we avoid deep
107349 ** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
107350 ** on a VALUES clause.
107351 **
107352 ** Because the Select object originates from a VALUES clause:
107353 ** (1) It has no LIMIT or OFFSET
107354 ** (2) All terms are UNION ALL
107355 ** (3) There is no ORDER BY clause
107356 */
107357 static int multiSelectValues(
107358 Parse *pParse, /* Parsing context */
107359 Select *p, /* The right-most of SELECTs to be coded */
107360 SelectDest *pDest /* What to do with query results */
107361 ){
107362 Select *pPrior;
107363 int nExpr = p->pEList->nExpr;
107364 int nRow = 1;
107365 int rc = 0;
107366 assert( p->pNext==0 );
107367 assert( p->selFlags & SF_AllValues );
107368 do{
107369 assert( p->selFlags & SF_Values );
107370 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
107371 assert( p->pLimit==0 );
107372 assert( p->pOffset==0 );
107373 if( p->pEList->nExpr!=nExpr ){
107374 selectWrongNumTermsError(pParse, p);
107375 return 1;
107376 }
107377 if( p->pPrior==0 ) break;
107378 assert( p->pPrior->pNext==p );
107379 p = p->pPrior;
107380 nRow++;
107381 }while(1);
107382 while( p ){
107383 pPrior = p->pPrior;
107384 p->pPrior = 0;
107385 rc = sqlite3Select(pParse, p, pDest);
107386 p->pPrior = pPrior;
107387 if( rc ) break;
107388 p->nSelectRow = nRow;
107389 p = p->pNext;
107390 }
107391 return rc;
107392 }
107393
107394 /*
107395 ** This routine is called to process a compound query form from
107396 ** two or more separate queries using UNION, UNION ALL, EXCEPT, or
107397 ** INTERSECT
@@ -107266,22 +107468,24 @@
107468 assert( p->pEList );
107469 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, dest.iSDParm, p->pEList->nExpr);
107470 sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
107471 dest.eDest = SRT_Table;
107472 }
107473
107474 /* Special handling for a compound-select that originates as a VALUES clause.
107475 */
107476 if( p->selFlags & SF_AllValues ){
107477 rc = multiSelectValues(pParse, p, &dest);
107478 goto multi_select_end;
107479 }
107480
107481 /* Make sure all SELECTs in the statement have the same number of elements
107482 ** in their result sets.
107483 */
107484 assert( p->pEList && pPrior->pEList );
107485 if( p->pEList->nExpr!=pPrior->pEList->nExpr ){
107486 selectWrongNumTermsError(pParse, p);
 
 
 
 
 
107487 rc = 1;
107488 goto multi_select_end;
107489 }
107490
107491 #ifndef SQLITE_OMIT_CTE
@@ -109163,11 +109367,13 @@
109367 if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
109368 return WRC_Prune;
109369 }
109370 pTabList = p->pSrc;
109371 pEList = p->pEList;
109372 if( pWalker->xSelectCallback2==selectPopWith ){
109373 sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
109374 }
109375
109376 /* Make sure cursor numbers have been assigned to all entries in
109377 ** the FROM clause of the SELECT statement.
109378 */
109379 sqlite3SrcListAssignCursors(pParse, pTabList);
@@ -109454,11 +109660,13 @@
109660 if( pParse->hasCompound ){
109661 w.xSelectCallback = convertCompoundSelectToSubquery;
109662 sqlite3WalkSelect(&w, pSelect);
109663 }
109664 w.xSelectCallback = selectExpander;
109665 if( (pSelect->selFlags & SF_AllValues)==0 ){
109666 w.xSelectCallback2 = selectPopWith;
109667 }
109668 sqlite3WalkSelect(&w, pSelect);
109669 }
109670
109671
109672 #ifndef SQLITE_OMIT_SUBQUERY
@@ -110756,11 +110964,11 @@
110964 ){
110965 int rc;
110966 TabResult res;
110967
110968 #ifdef SQLITE_ENABLE_API_ARMOR
110969 if( !sqlite3SafetyCheckOk(db) || pazResult==0 ) return SQLITE_MISUSE_BKPT;
110970 #endif
110971 *pazResult = 0;
110972 if( pnColumn ) *pnColumn = 0;
110973 if( pnRow ) *pnRow = 0;
110974 if( pzErrMsg ) *pzErrMsg = 0;
@@ -118626,11 +118834,10 @@
118834 sqlite3_free(p->u.vtab.idxStr);
118835 p->u.vtab.needFree = 0;
118836 p->u.vtab.idxStr = 0;
118837 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
118838 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
 
118839 sqlite3DbFree(db, p->u.btree.pIndex);
118840 p->u.btree.pIndex = 0;
118841 }
118842 }
118843 }
@@ -123783,17 +123990,23 @@
123990 Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
123991 if( p ){
123992 int cnt = 0, mxSelect;
123993 p->pWith = yymsp[-1].minor.yy59;
123994 if( p->pPrior ){
123995 u16 allValues = SF_Values;
123996 pNext = 0;
123997 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
123998 pLoop->pNext = pNext;
123999 pLoop->selFlags |= SF_Compound;
124000 allValues &= pLoop->selFlags;
124001 }
124002 if( allValues ){
124003 p->selFlags |= SF_AllValues;
124004 }else if(
124005 (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0
124006 && cnt>mxSelect
124007 ){
124008 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
124009 }
124010 }
124011 }else{
124012 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
@@ -125633,10 +125846,13 @@
125846 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
125847 sqlite3 *db = pParse->db; /* The database connection */
125848 int mxSqlLen; /* Max length of an SQL string */
125849
125850
125851 #ifdef SQLITE_ENABLE_API_ARMOR
125852 if( zSql==0 || pzErrMsg==0 ) return SQLITE_MISUSE_BKPT;
125853 #endif
125854 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
125855 if( db->nVdbeActive==0 ){
125856 db->u1.isInterrupted = 0;
125857 }
125858 pParse->rc = SQLITE_OK;
@@ -125871,17 +126087,10 @@
126087 */
126088 SQLITE_API int sqlite3_complete(const char *zSql){
126089 u8 state = 0; /* Current state, using numbers defined in header comment */
126090 u8 token; /* Value of the next token */
126091
 
 
 
 
 
 
 
126092 #ifndef SQLITE_OMIT_TRIGGER
126093 /* A complex statement machine used to detect the end of a CREATE TRIGGER
126094 ** statement. This is the normal case.
126095 */
126096 static const u8 trans[8][8] = {
@@ -125906,10 +126115,17 @@
126115 /* 0 INVALID: */ { 1, 0, 2, },
126116 /* 1 START: */ { 1, 1, 2, },
126117 /* 2 NORMAL: */ { 1, 2, 2, },
126118 };
126119 #endif /* SQLITE_OMIT_TRIGGER */
126120
126121 #ifdef SQLITE_ENABLE_API_ARMOR
126122 if( zSql==0 ){
126123 (void)SQLITE_MISUSE_BKPT;
126124 return 0;
126125 }
126126 #endif
126127
126128 while( *zSql ){
126129 switch( *zSql ){
126130 case ';': { /* A semicolon */
126131 token = tkSEMI;
@@ -126208,11 +126424,11 @@
126424 ** If the following function pointer is not NULL and if
126425 ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
126426 ** I/O active are written using this function. These messages
126427 ** are intended for debugging activity only.
126428 */
126429 /* not-private */ void (*sqlite3IoTrace)(const char*, ...) = 0;
126430 #endif
126431
126432 /*
126433 ** If the following global variable points to a string which is the
126434 ** name of a directory, then that directory will be used to store
@@ -126417,10 +126633,17 @@
126633 ** routine is not threadsafe. But it is safe to invoke this routine
126634 ** on when SQLite is already shut down. If SQLite is already shut down
126635 ** when this routine is invoked, then this routine is a harmless no-op.
126636 */
126637 SQLITE_API int sqlite3_shutdown(void){
126638 #ifdef SQLITE_OMIT_WSD
126639 int rc = sqlite3_wsd_init(4096, 24);
126640 if( rc!=SQLITE_OK ){
126641 return rc;
126642 }
126643 #endif
126644
126645 if( sqlite3GlobalConfig.isInit ){
126646 #ifdef SQLITE_EXTRA_SHUTDOWN
126647 void SQLITE_EXTRA_SHUTDOWN(void);
126648 SQLITE_EXTRA_SHUTDOWN();
126649 #endif
@@ -126732,10 +126955,15 @@
126955 ** heap. */
126956 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
126957 break;
126958 }
126959 #endif
126960
126961 case SQLITE_CONFIG_PMASZ: {
126962 sqlite3GlobalConfig.szPma = va_arg(ap, unsigned int);
126963 break;
126964 }
126965
126966 default: {
126967 rc = SQLITE_ERROR;
126968 break;
126969 }
@@ -127178,20 +127406,10 @@
127406
127407 /* Close all database connections */
127408 for(j=0; j<db->nDb; j++){
127409 struct Db *pDb = &db->aDb[j];
127410 if( pDb->pBt ){
 
 
 
 
 
 
 
 
 
 
127411 sqlite3BtreeClose(pDb->pBt);
127412 pDb->pBt = 0;
127413 if( j!=1 ){
127414 pDb->pSchema = 0;
127415 }
@@ -127494,11 +127712,11 @@
127712 */
127713 static int sqliteDefaultBusyCallback(
127714 void *ptr, /* Database connection */
127715 int count /* Number of times table has been busy */
127716 ){
127717 #if SQLITE_OS_WIN || HAVE_USLEEP
127718 static const u8 delays[] =
127719 { 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 };
127720 static const u8 totals[] =
127721 { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
127722 # define NDELAY ArraySize(delays)
@@ -128315,36 +128533,10 @@
128533 */
128534 SQLITE_API const char *sqlite3_errstr(int rc){
128535 return sqlite3ErrStr(rc);
128536 }
128537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128538 /*
128539 ** Create a new collating function for database "db". The name is zName
128540 ** and the encoding is enc.
128541 */
128542 static int createCollation(
@@ -128384,11 +128576,10 @@
128576 sqlite3ErrorWithMsg(db, SQLITE_BUSY,
128577 "unable to delete/modify collation sequence due to active statements");
128578 return SQLITE_BUSY;
128579 }
128580 sqlite3ExpirePreparedStatements(db);
 
128581
128582 /* If collation sequence pColl was created directly by a call to
128583 ** sqlite3_create_collation, and not generated by synthCollSeq(),
128584 ** then any copies made by synthCollSeq() need to be invalidated.
128585 ** Also, collation destructor - CollSeq.xDel() - function may need
@@ -128941,10 +129132,11 @@
129132 sqlite3Error(db, rc);
129133 goto opendb_out;
129134 }
129135 sqlite3BtreeEnter(db->aDb[0].pBt);
129136 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
129137 if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db);
129138 sqlite3BtreeLeave(db->aDb[0].pBt);
129139 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
129140
129141 /* The default safety_level for the main database is 'full'; for the temp
129142 ** database it is 'NONE'. This matches the pager layer defaults.
@@ -129099,11 +129291,11 @@
129291 if( zFilename8 ){
129292 rc = openDatabase(zFilename8, ppDb,
129293 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
129294 assert( *ppDb || rc==SQLITE_NOMEM );
129295 if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){
129296 SCHEMA_ENC(*ppDb) = ENC(*ppDb) = SQLITE_UTF16NATIVE;
129297 }
129298 }else{
129299 rc = SQLITE_NOMEM;
129300 }
129301 sqlite3ValueFree(pVal);
@@ -129310,11 +129502,11 @@
129502 ){
129503 int rc;
129504 char *zErrMsg = 0;
129505 Table *pTab = 0;
129506 Column *pCol = 0;
129507 int iCol = 0;
129508
129509 char const *zDataType = 0;
129510 char const *zCollSeq = 0;
129511 int notnull = 0;
129512 int primarykey = 0;
@@ -129841,32 +130033,34 @@
130033 /*
130034 ** Return the filename of the database associated with a database
130035 ** connection.
130036 */
130037 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
130038 Btree *pBt;
130039 #ifdef SQLITE_ENABLE_API_ARMOR
130040 if( !sqlite3SafetyCheckOk(db) ){
130041 (void)SQLITE_MISUSE_BKPT;
130042 return 0;
130043 }
130044 #endif
130045 pBt = sqlite3DbNameToBtree(db, zDbName);
130046 return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
130047 }
130048
130049 /*
130050 ** Return 1 if database is read-only or 0 if read/write. Return -1 if
130051 ** no such database exists.
130052 */
130053 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
130054 Btree *pBt;
130055 #ifdef SQLITE_ENABLE_API_ARMOR
130056 if( !sqlite3SafetyCheckOk(db) ){
130057 (void)SQLITE_MISUSE_BKPT;
130058 return -1;
130059 }
130060 #endif
130061 pBt = sqlite3DbNameToBtree(db, zDbName);
130062 return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
130063 }
130064
130065 /************** End of main.c ************************************************/
130066 /************** Begin file notify.c ******************************************/
@@ -132931,11 +133125,11 @@
133125 const char *zNode, /* Buffer containing segment interior node */
133126 int nNode, /* Size of buffer at zNode */
133127 sqlite3_int64 *piLeaf, /* Selected leaf node */
133128 sqlite3_int64 *piLeaf2 /* Selected leaf node */
133129 ){
133130 int rc = SQLITE_OK; /* Return code */
133131 int iHeight; /* Height of this node in tree */
133132
133133 assert( piLeaf || piLeaf2 );
133134
133135 fts3GetVarint32(zNode, &iHeight);
@@ -132942,11 +133136,11 @@
133136 rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
133137 assert( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
133138
133139 if( rc==SQLITE_OK && iHeight>1 ){
133140 char *zBlob = 0; /* Blob read from %_segments table */
133141 int nBlob = 0; /* Size of zBlob in bytes */
133142
133143 if( piLeaf && piLeaf2 && (*piLeaf!=*piLeaf2) ){
133144 rc = sqlite3Fts3ReadBlock(p, *piLeaf, &zBlob, &nBlob, 0);
133145 if( rc==SQLITE_OK ){
133146 rc = fts3SelectLeaf(p, zTerm, nTerm, zBlob, nBlob, piLeaf, 0);
@@ -134164,11 +134358,11 @@
134358 int idxNum, /* Strategy index */
134359 const char *idxStr, /* Unused */
134360 int nVal, /* Number of elements in apVal */
134361 sqlite3_value **apVal /* Arguments for the indexing scheme */
134362 ){
134363 int rc = SQLITE_OK;
134364 char *zSql; /* SQL statement used to access %_content */
134365 int eSearch;
134366 Fts3Table *p = (Fts3Table *)pCursor->pVtab;
134367 Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
134368
@@ -140652,11 +140846,11 @@
140846 int argc, /* Number of elements in argv array */
140847 const char * const *argv, /* xCreate/xConnect argument array */
140848 sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */
140849 char **pzErr /* OUT: sqlite3_malloc'd error message */
140850 ){
140851 Fts3tokTable *pTab = 0;
140852 const sqlite3_tokenizer_module *pMod = 0;
140853 sqlite3_tokenizer *pTok = 0;
140854 int rc;
140855 char **azDequote = 0;
140856 int nDequote;
@@ -144027,12 +144221,12 @@
144221 }
144222 rc = sqlite3_reset(pRange);
144223
144224 if( bOk ){
144225 int iIdx = 0;
144226 sqlite3_stmt *pUpdate1 = 0;
144227 sqlite3_stmt *pUpdate2 = 0;
144228
144229 if( rc==SQLITE_OK ){
144230 rc = fts3SqlStmt(p, SQL_UPDATE_LEVEL_IDX, &pUpdate1, 0);
144231 }
144232 if( rc==SQLITE_OK ){
@@ -150073,11 +150267,11 @@
150267 }
150268 i = pCur->nPoint++;
150269 pNew = pCur->aPoint + i;
150270 pNew->rScore = rScore;
150271 pNew->iLevel = iLevel;
150272 assert( iLevel<=RTREE_MAX_DEPTH );
150273 while( i>0 ){
150274 RtreeSearchPoint *pParent;
150275 j = (i-1)/2;
150276 pParent = pCur->aPoint + j;
150277 if( rtreeSearchPointCompare(pNew, pParent)>=0 ) break;
@@ -151696,10 +151890,12 @@
151890 RtreeCell cell; /* New cell to insert if nData>1 */
151891 int bHaveRowid = 0; /* Set to 1 after new rowid is determined */
151892
151893 rtreeReference(pRtree);
151894 assert(nData>=1);
151895
151896 cell.iRowid = 0; /* Used only to suppress a compiler warning */
151897
151898 /* Constraint handling. A write operation on an r-tree table may return
151899 ** SQLITE_CONSTRAINT for two reasons:
151900 **
151901 ** 1. A duplicate rowid value, or
151902
+30 -12
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.8"
111111
#define SQLITE_VERSION_NUMBER 3008008
112
-#define SQLITE_SOURCE_ID "2014-12-10 04:58:43 3528f8dd39acace8eeb7337994c8617313f4b04b"
112
+#define SQLITE_SOURCE_ID "2015-01-12 21:43:00 e693e11d1b9265974c32bddba873ea30a4d0b708"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -199,11 +199,11 @@
199199
** This interface only reports on the compile-time mutex setting
200200
** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
201201
** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
202202
** can be fully or partially disabled using a call to [sqlite3_config()]
203203
** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
204
-** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the
204
+** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
205205
** sqlite3_threadsafe() function shows only the compile-time setting of
206206
** thread safety, not any run-time changes to that setting made by
207207
** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
208208
** is unchanged by calls to sqlite3_config().)^
209209
**
@@ -1568,11 +1568,11 @@
15681568
** configuration option.
15691569
** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
15701570
** 8-byte aligned
15711571
** memory, the size of each page buffer (sz), and the number of pages (N).
15721572
** The sz argument should be the size of the largest database page
1573
-** (a power of two between 512 and 32768) plus some extra bytes for each
1573
+** (a power of two between 512 and 65536) plus some extra bytes for each
15741574
** page header. ^The number of extra bytes needed by the page header
15751575
** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
15761576
** to [sqlite3_config()].
15771577
** ^It is harmless, apart from the wasted memory,
15781578
** for the sz parameter to be larger than necessary. The first
@@ -1748,10 +1748,21 @@
17481748
** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
17491749
** is a pointer to an integer and writes into that integer the number of extra
17501750
** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
17511751
** The amount of extra space required can change depending on the compiler,
17521752
** target platform, and SQLite version.
1753
+**
1754
+** [[SQLITE_CONFIG_PMASZ]]
1755
+** <dt>SQLITE_CONFIG_PMASZ
1756
+** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
1757
+** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
1758
+** sorter to that integer. The default minimum PMA Size is set by the
1759
+** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
1760
+** to help with sort operations when multithreaded sorting
1761
+** is enabled (using the [PRAGMA threads] command) and the amount of content
1762
+** to be sorted exceeds the page size times the minimum of the
1763
+** [PRAGMA cache_size] setting and this value.
17531764
** </dl>
17541765
*/
17551766
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
17561767
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
17571768
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1774,10 +1785,11 @@
17741785
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
17751786
#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
17761787
#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
17771788
#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
17781789
#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
1790
+#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
17791791
17801792
/*
17811793
** CAPI3REF: Database Connection Configuration Options
17821794
**
17831795
** These constants are the available integer configuration options that
@@ -7183,16 +7195,14 @@
71837195
71847196
/*
71857197
** CAPI3REF: Write-Ahead Log Commit Hook
71867198
**
71877199
** ^The [sqlite3_wal_hook()] function is used to register a callback that
7188
-** will be invoked each time a database connection commits data to a
7189
-** [write-ahead log] (i.e. whenever a transaction is committed in
7190
-** [journal_mode | journal_mode=WAL mode]).
7200
+** is invoked each time data is committed to a database in wal mode.
71917201
**
7192
-** ^The callback is invoked by SQLite after the commit has taken place and
7193
-** the associated write-lock on the database released, so the implementation
7202
+** ^(The callback is invoked by SQLite after the commit has taken place and
7203
+** the associated write-lock on the database released)^, so the implementation
71947204
** may read, write or [checkpoint] the database as required.
71957205
**
71967206
** ^The first parameter passed to the callback function when it is invoked
71977207
** is a copy of the third parameter passed to sqlite3_wal_hook() when
71987208
** registering the callback. ^The second is a copy of the database handle.
@@ -7479,10 +7489,14 @@
74797489
**
74807490
** The following constants can be used for the T parameter to the
74817491
** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
74827492
** different metric for sqlite3_stmt_scanstatus() to return.
74837493
**
7494
+** When the value returned to V is a string, space to hold that string is
7495
+** managed by the prepared statement S and will be automatically freed when
7496
+** S is finalized.
7497
+**
74847498
** <dl>
74857499
** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
74867500
** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
74877501
** set to the total number of times that the X-th loop has run.</dd>
74887502
**
@@ -7524,11 +7538,18 @@
75247538
#define SQLITE_SCANSTAT_SELECTID 5
75257539
75267540
/*
75277541
** CAPI3REF: Prepared Statement Scan Status
75287542
**
7529
-** Return status data for a single loop within query pStmt.
7543
+** This interface returns information about the predicted and measured
7544
+** performance for pStmt. Advanced applications can use this
7545
+** interface to compare the predicted and the measured performance and
7546
+** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
7547
+**
7548
+** Since this interface is expected to be rarely used, it is only
7549
+** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
7550
+** compile-time option.
75307551
**
75317552
** The "iScanStatusOp" parameter determines which status information to return.
75327553
** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
75337554
** of this interface is undefined.
75347555
** ^The requested measurement is written into a variable pointed to by
@@ -7542,13 +7563,10 @@
75427563
** ^Statistics might not be available for all loops in all statements. ^In cases
75437564
** where there exist loops with no available statistics, this function behaves
75447565
** as if the loop did not exist - it returns non-zero and leave the variable
75457566
** that pOut points to unchanged.
75467567
**
7547
-** This API is only available if the library is built with pre-processor
7548
-** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7549
-**
75507568
** See also: [sqlite3_stmt_scanstatus_reset()]
75517569
*/
75527570
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
75537571
sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
75547572
int idx, /* Index of loop to report on */
75557573
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
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-12-10 04:58:43 3528f8dd39acace8eeb7337994c8617313f4b04b"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -199,11 +199,11 @@
199 ** This interface only reports on the compile-time mutex setting
200 ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
201 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
202 ** can be fully or partially disabled using a call to [sqlite3_config()]
203 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
204 ** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the
205 ** sqlite3_threadsafe() function shows only the compile-time setting of
206 ** thread safety, not any run-time changes to that setting made by
207 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
208 ** is unchanged by calls to sqlite3_config().)^
209 **
@@ -1568,11 +1568,11 @@
1568 ** configuration option.
1569 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1570 ** 8-byte aligned
1571 ** memory, the size of each page buffer (sz), and the number of pages (N).
1572 ** The sz argument should be the size of the largest database page
1573 ** (a power of two between 512 and 32768) plus some extra bytes for each
1574 ** page header. ^The number of extra bytes needed by the page header
1575 ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1576 ** to [sqlite3_config()].
1577 ** ^It is harmless, apart from the wasted memory,
1578 ** for the sz parameter to be larger than necessary. The first
@@ -1748,10 +1748,21 @@
1748 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1749 ** is a pointer to an integer and writes into that integer the number of extra
1750 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
1751 ** The amount of extra space required can change depending on the compiler,
1752 ** target platform, and SQLite version.
 
 
 
 
 
 
 
 
 
 
 
1753 ** </dl>
1754 */
1755 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1756 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1757 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1774,10 +1785,11 @@
1774 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1775 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1776 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1777 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1778 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
 
1779
1780 /*
1781 ** CAPI3REF: Database Connection Configuration Options
1782 **
1783 ** These constants are the available integer configuration options that
@@ -7183,16 +7195,14 @@
7183
7184 /*
7185 ** CAPI3REF: Write-Ahead Log Commit Hook
7186 **
7187 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7188 ** will be invoked each time a database connection commits data to a
7189 ** [write-ahead log] (i.e. whenever a transaction is committed in
7190 ** [journal_mode | journal_mode=WAL mode]).
7191 **
7192 ** ^The callback is invoked by SQLite after the commit has taken place and
7193 ** the associated write-lock on the database released, so the implementation
7194 ** may read, write or [checkpoint] the database as required.
7195 **
7196 ** ^The first parameter passed to the callback function when it is invoked
7197 ** is a copy of the third parameter passed to sqlite3_wal_hook() when
7198 ** registering the callback. ^The second is a copy of the database handle.
@@ -7479,10 +7489,14 @@
7479 **
7480 ** The following constants can be used for the T parameter to the
7481 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7482 ** different metric for sqlite3_stmt_scanstatus() to return.
7483 **
 
 
 
 
7484 ** <dl>
7485 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7486 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
7487 ** set to the total number of times that the X-th loop has run.</dd>
7488 **
@@ -7524,11 +7538,18 @@
7524 #define SQLITE_SCANSTAT_SELECTID 5
7525
7526 /*
7527 ** CAPI3REF: Prepared Statement Scan Status
7528 **
7529 ** Return status data for a single loop within query pStmt.
 
 
 
 
 
 
 
7530 **
7531 ** The "iScanStatusOp" parameter determines which status information to return.
7532 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
7533 ** of this interface is undefined.
7534 ** ^The requested measurement is written into a variable pointed to by
@@ -7542,13 +7563,10 @@
7542 ** ^Statistics might not be available for all loops in all statements. ^In cases
7543 ** where there exist loops with no available statistics, this function behaves
7544 ** as if the loop did not exist - it returns non-zero and leave the variable
7545 ** that pOut points to unchanged.
7546 **
7547 ** This API is only available if the library is built with pre-processor
7548 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7549 **
7550 ** See also: [sqlite3_stmt_scanstatus_reset()]
7551 */
7552 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7553 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7554 int idx, /* Index of loop to report on */
7555
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
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 "2015-01-12 21:43:00 e693e11d1b9265974c32bddba873ea30a4d0b708"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -199,11 +199,11 @@
199 ** This interface only reports on the compile-time mutex setting
200 ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
201 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
202 ** can be fully or partially disabled using a call to [sqlite3_config()]
203 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
204 ** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
205 ** sqlite3_threadsafe() function shows only the compile-time setting of
206 ** thread safety, not any run-time changes to that setting made by
207 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
208 ** is unchanged by calls to sqlite3_config().)^
209 **
@@ -1568,11 +1568,11 @@
1568 ** configuration option.
1569 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1570 ** 8-byte aligned
1571 ** memory, the size of each page buffer (sz), and the number of pages (N).
1572 ** The sz argument should be the size of the largest database page
1573 ** (a power of two between 512 and 65536) plus some extra bytes for each
1574 ** page header. ^The number of extra bytes needed by the page header
1575 ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1576 ** to [sqlite3_config()].
1577 ** ^It is harmless, apart from the wasted memory,
1578 ** for the sz parameter to be larger than necessary. The first
@@ -1748,10 +1748,21 @@
1748 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1749 ** is a pointer to an integer and writes into that integer the number of extra
1750 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
1751 ** The amount of extra space required can change depending on the compiler,
1752 ** target platform, and SQLite version.
1753 **
1754 ** [[SQLITE_CONFIG_PMASZ]]
1755 ** <dt>SQLITE_CONFIG_PMASZ
1756 ** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
1757 ** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
1758 ** sorter to that integer. The default minimum PMA Size is set by the
1759 ** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
1760 ** to help with sort operations when multithreaded sorting
1761 ** is enabled (using the [PRAGMA threads] command) and the amount of content
1762 ** to be sorted exceeds the page size times the minimum of the
1763 ** [PRAGMA cache_size] setting and this value.
1764 ** </dl>
1765 */
1766 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1767 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1768 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1774,10 +1785,11 @@
1785 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1786 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1787 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1788 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1789 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
1790 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
1791
1792 /*
1793 ** CAPI3REF: Database Connection Configuration Options
1794 **
1795 ** These constants are the available integer configuration options that
@@ -7183,16 +7195,14 @@
7195
7196 /*
7197 ** CAPI3REF: Write-Ahead Log Commit Hook
7198 **
7199 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7200 ** is invoked each time data is committed to a database in wal mode.
 
 
7201 **
7202 ** ^(The callback is invoked by SQLite after the commit has taken place and
7203 ** the associated write-lock on the database released)^, so the implementation
7204 ** may read, write or [checkpoint] the database as required.
7205 **
7206 ** ^The first parameter passed to the callback function when it is invoked
7207 ** is a copy of the third parameter passed to sqlite3_wal_hook() when
7208 ** registering the callback. ^The second is a copy of the database handle.
@@ -7479,10 +7489,14 @@
7489 **
7490 ** The following constants can be used for the T parameter to the
7491 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7492 ** different metric for sqlite3_stmt_scanstatus() to return.
7493 **
7494 ** When the value returned to V is a string, space to hold that string is
7495 ** managed by the prepared statement S and will be automatically freed when
7496 ** S is finalized.
7497 **
7498 ** <dl>
7499 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7500 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
7501 ** set to the total number of times that the X-th loop has run.</dd>
7502 **
@@ -7524,11 +7538,18 @@
7538 #define SQLITE_SCANSTAT_SELECTID 5
7539
7540 /*
7541 ** CAPI3REF: Prepared Statement Scan Status
7542 **
7543 ** This interface returns information about the predicted and measured
7544 ** performance for pStmt. Advanced applications can use this
7545 ** interface to compare the predicted and the measured performance and
7546 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
7547 **
7548 ** Since this interface is expected to be rarely used, it is only
7549 ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
7550 ** compile-time option.
7551 **
7552 ** The "iScanStatusOp" parameter determines which status information to return.
7553 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
7554 ** of this interface is undefined.
7555 ** ^The requested measurement is written into a variable pointed to by
@@ -7542,13 +7563,10 @@
7563 ** ^Statistics might not be available for all loops in all statements. ^In cases
7564 ** where there exist loops with no available statistics, this function behaves
7565 ** as if the loop did not exist - it returns non-zero and leave the variable
7566 ** that pOut points to unchanged.
7567 **
 
 
 
7568 ** See also: [sqlite3_stmt_scanstatus_reset()]
7569 */
7570 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7571 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7572 int idx, /* Index of loop to report on */
7573
+28
--- src/style.c
+++ src/style.c
@@ -1269,10 +1269,38 @@
12691269
{ ".fileage td:nth-child(3)",
12701270
"fileage third column (the check-in comment)",
12711271
@ word-break: break-all;
12721272
@ word-wrap: break-word;
12731273
@ max-width: 50%;
1274
+ },
1275
+ { ".brlist table", "The list of branches",
1276
+ @ border-spacing: 0;
1277
+ },
1278
+ { ".brlist table th", "Branch list table headers",
1279
+ @ text-align: left;
1280
+ @ padding: 0px 1em 0.5ex 0px;
1281
+ },
1282
+ { ".brlist table td", "Branch list table headers",
1283
+ @ padding: 0px 2em 0px 0px;
1284
+ },
1285
+ { "th.sort:after",
1286
+ "General styles for sortable column marker",
1287
+ @ margin-left: .4em;
1288
+ @ cursor: pointer;
1289
+ @ text-shadow: 0 0 0 #000; /* Makes arrow darker */
1290
+ },
1291
+ { "th.sort.none:after",
1292
+ "None sort column marker",
1293
+ @ content: '\2666';
1294
+ },
1295
+ { "th.sort.asc:after",
1296
+ "Ascending sort column marker",
1297
+ @ content: '\2193';
1298
+ },
1299
+ { "th.sort.desc:after",
1300
+ "Descending sort column marker",
1301
+ @ content: '\2191';
12741302
},
12751303
{ 0,
12761304
0,
12771305
0
12781306
}
12791307
--- src/style.c
+++ src/style.c
@@ -1269,10 +1269,38 @@
1269 { ".fileage td:nth-child(3)",
1270 "fileage third column (the check-in comment)",
1271 @ word-break: break-all;
1272 @ word-wrap: break-word;
1273 @ max-width: 50%;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1274 },
1275 { 0,
1276 0,
1277 0
1278 }
1279
--- src/style.c
+++ src/style.c
@@ -1269,10 +1269,38 @@
1269 { ".fileage td:nth-child(3)",
1270 "fileage third column (the check-in comment)",
1271 @ word-break: break-all;
1272 @ word-wrap: break-word;
1273 @ max-width: 50%;
1274 },
1275 { ".brlist table", "The list of branches",
1276 @ border-spacing: 0;
1277 },
1278 { ".brlist table th", "Branch list table headers",
1279 @ text-align: left;
1280 @ padding: 0px 1em 0.5ex 0px;
1281 },
1282 { ".brlist table td", "Branch list table headers",
1283 @ padding: 0px 2em 0px 0px;
1284 },
1285 { "th.sort:after",
1286 "General styles for sortable column marker",
1287 @ margin-left: .4em;
1288 @ cursor: pointer;
1289 @ text-shadow: 0 0 0 #000; /* Makes arrow darker */
1290 },
1291 { "th.sort.none:after",
1292 "None sort column marker",
1293 @ content: '\2666';
1294 },
1295 { "th.sort.asc:after",
1296 "Ascending sort column marker",
1297 @ content: '\2193';
1298 },
1299 { "th.sort.desc:after",
1300 "Descending sort column marker",
1301 @ content: '\2191';
1302 },
1303 { 0,
1304 0,
1305 0
1306 }
1307
+7 -7
--- src/timeline.c
+++ src/timeline.c
@@ -608,12 +608,12 @@
608608
** for the upward portion of a merge arrow. The merge arrow goes up
609609
** to the row identified by mu:. If this value is zero then
610610
** node has no merge children and no merge-out line is drawn.
611611
** mu: The id of the row which is the top of the merge-out arrow.
612612
** u: Draw a thick child-line out of the top of this node and up to
613
- ** the node with an id equal to this value. 0 if there is no
614
- ** thick-line riser.
613
+ ** the node with an id equal to this value. 0 if it is straight to
614
+ ** the top of the page, -1 if there is no thick-line riser.
615615
** f: 0x01: a leaf node.
616616
** au: An array of integers that define thick-line risers for branches.
617617
** The integers are in pairs. For each pair, the first integer is
618618
** is the rail on which the riser should run and the second integer
619619
** is the id of the node upto which the riser should run.
@@ -2399,11 +2399,11 @@
23992399
@ <br><div>Total events: %d(nEventTotal)
24002400
@ <br>Average per active %s(zAvgLabel): %d(nAvg)
24012401
@ </div>
24022402
}
24032403
if( !includeMonth ){
2404
- output_table_sorting_javascript("statsTable","tnx");
2404
+ output_table_sorting_javascript("statsTable","tnx",-1);
24052405
}
24062406
}
24072407
24082408
/*
24092409
** Implements the "byuser" view for /reports.
@@ -2450,11 +2450,11 @@
24502450
rowClass = ++nRowNumber % 2;
24512451
nEventTotal += nCount;
24522452
@<tr class='row%d(rowClass)'>
24532453
@ <td>
24542454
@ <a href="?view=bymonth&user=%h(zUser)&type=%c((char)statsReportType)">%h(zUser)</a>
2455
- @ </td><td>%d(nCount)</td>
2455
+ @ </td><td data-sortkey='%08x(-nCount)'>%d(nCount)</td>
24562456
@ <td>
24572457
@ <div class='statistics-report-graph-line'
24582458
@ style='width:%d(nSize)%%;'>&nbsp;</div>
24592459
@ </td>
24602460
@</tr>
@@ -2463,11 +2463,11 @@
24632463
use percent-based graph bars.
24642464
*/
24652465
}
24662466
@ </tbody></table>
24672467
db_finalize(&query);
2468
- output_table_sorting_javascript("statsTable","tnx");
2468
+ output_table_sorting_javascript("statsTable","tkx",2);
24692469
}
24702470
24712471
/*
24722472
** Implements the "byweekday" view for /reports.
24732473
*/
@@ -2528,11 +2528,11 @@
25282528
@ </td>
25292529
@</tr>
25302530
}
25312531
@ </tbody></table>
25322532
db_finalize(&query);
2533
- output_table_sorting_javascript("statsTable","ntnx");
2533
+ output_table_sorting_javascript("statsTable","ntnx",1);
25342534
}
25352535
25362536
25372537
/*
25382538
** Helper for stats_report_by_month_year(), which generates a list of
@@ -2661,11 +2661,11 @@
26612661
int nAvg = iterations ? (total/iterations) : 0;
26622662
cgi_printf("<br><div>Total events: %d<br>"
26632663
"Average per active week: %d</div>",
26642664
total, nAvg);
26652665
}
2666
- output_table_sorting_javascript("statsTable","tnx");
2666
+ output_table_sorting_javascript("statsTable","tnx",-1);
26672667
}
26682668
}
26692669
26702670
/*
26712671
** WEBPAGE: reports
26722672
--- src/timeline.c
+++ src/timeline.c
@@ -608,12 +608,12 @@
608 ** for the upward portion of a merge arrow. The merge arrow goes up
609 ** to the row identified by mu:. If this value is zero then
610 ** node has no merge children and no merge-out line is drawn.
611 ** mu: The id of the row which is the top of the merge-out arrow.
612 ** u: Draw a thick child-line out of the top of this node and up to
613 ** the node with an id equal to this value. 0 if there is no
614 ** thick-line riser.
615 ** f: 0x01: a leaf node.
616 ** au: An array of integers that define thick-line risers for branches.
617 ** The integers are in pairs. For each pair, the first integer is
618 ** is the rail on which the riser should run and the second integer
619 ** is the id of the node upto which the riser should run.
@@ -2399,11 +2399,11 @@
2399 @ <br><div>Total events: %d(nEventTotal)
2400 @ <br>Average per active %s(zAvgLabel): %d(nAvg)
2401 @ </div>
2402 }
2403 if( !includeMonth ){
2404 output_table_sorting_javascript("statsTable","tnx");
2405 }
2406 }
2407
2408 /*
2409 ** Implements the "byuser" view for /reports.
@@ -2450,11 +2450,11 @@
2450 rowClass = ++nRowNumber % 2;
2451 nEventTotal += nCount;
2452 @<tr class='row%d(rowClass)'>
2453 @ <td>
2454 @ <a href="?view=bymonth&user=%h(zUser)&type=%c((char)statsReportType)">%h(zUser)</a>
2455 @ </td><td>%d(nCount)</td>
2456 @ <td>
2457 @ <div class='statistics-report-graph-line'
2458 @ style='width:%d(nSize)%%;'>&nbsp;</div>
2459 @ </td>
2460 @</tr>
@@ -2463,11 +2463,11 @@
2463 use percent-based graph bars.
2464 */
2465 }
2466 @ </tbody></table>
2467 db_finalize(&query);
2468 output_table_sorting_javascript("statsTable","tnx");
2469 }
2470
2471 /*
2472 ** Implements the "byweekday" view for /reports.
2473 */
@@ -2528,11 +2528,11 @@
2528 @ </td>
2529 @</tr>
2530 }
2531 @ </tbody></table>
2532 db_finalize(&query);
2533 output_table_sorting_javascript("statsTable","ntnx");
2534 }
2535
2536
2537 /*
2538 ** Helper for stats_report_by_month_year(), which generates a list of
@@ -2661,11 +2661,11 @@
2661 int nAvg = iterations ? (total/iterations) : 0;
2662 cgi_printf("<br><div>Total events: %d<br>"
2663 "Average per active week: %d</div>",
2664 total, nAvg);
2665 }
2666 output_table_sorting_javascript("statsTable","tnx");
2667 }
2668 }
2669
2670 /*
2671 ** WEBPAGE: reports
2672
--- src/timeline.c
+++ src/timeline.c
@@ -608,12 +608,12 @@
608 ** for the upward portion of a merge arrow. The merge arrow goes up
609 ** to the row identified by mu:. If this value is zero then
610 ** node has no merge children and no merge-out line is drawn.
611 ** mu: The id of the row which is the top of the merge-out arrow.
612 ** u: Draw a thick child-line out of the top of this node and up to
613 ** the node with an id equal to this value. 0 if it is straight to
614 ** the top of the page, -1 if there is no thick-line riser.
615 ** f: 0x01: a leaf node.
616 ** au: An array of integers that define thick-line risers for branches.
617 ** The integers are in pairs. For each pair, the first integer is
618 ** is the rail on which the riser should run and the second integer
619 ** is the id of the node upto which the riser should run.
@@ -2399,11 +2399,11 @@
2399 @ <br><div>Total events: %d(nEventTotal)
2400 @ <br>Average per active %s(zAvgLabel): %d(nAvg)
2401 @ </div>
2402 }
2403 if( !includeMonth ){
2404 output_table_sorting_javascript("statsTable","tnx",-1);
2405 }
2406 }
2407
2408 /*
2409 ** Implements the "byuser" view for /reports.
@@ -2450,11 +2450,11 @@
2450 rowClass = ++nRowNumber % 2;
2451 nEventTotal += nCount;
2452 @<tr class='row%d(rowClass)'>
2453 @ <td>
2454 @ <a href="?view=bymonth&user=%h(zUser)&type=%c((char)statsReportType)">%h(zUser)</a>
2455 @ </td><td data-sortkey='%08x(-nCount)'>%d(nCount)</td>
2456 @ <td>
2457 @ <div class='statistics-report-graph-line'
2458 @ style='width:%d(nSize)%%;'>&nbsp;</div>
2459 @ </td>
2460 @</tr>
@@ -2463,11 +2463,11 @@
2463 use percent-based graph bars.
2464 */
2465 }
2466 @ </tbody></table>
2467 db_finalize(&query);
2468 output_table_sorting_javascript("statsTable","tkx",2);
2469 }
2470
2471 /*
2472 ** Implements the "byweekday" view for /reports.
2473 */
@@ -2528,11 +2528,11 @@
2528 @ </td>
2529 @</tr>
2530 }
2531 @ </tbody></table>
2532 db_finalize(&query);
2533 output_table_sorting_javascript("statsTable","ntnx",1);
2534 }
2535
2536
2537 /*
2538 ** Helper for stats_report_by_month_year(), which generates a list of
@@ -2661,11 +2661,11 @@
2661 int nAvg = iterations ? (total/iterations) : 0;
2662 cgi_printf("<br><div>Total events: %d<br>"
2663 "Average per active week: %d</div>",
2664 total, nAvg);
2665 }
2666 output_table_sorting_javascript("statsTable","tnx",-1);
2667 }
2668 }
2669
2670 /*
2671 ** WEBPAGE: reports
2672
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -146,12 +146,12 @@
146146
#### The directories where the OpenSSL include and library files are located.
147147
# The recommended usage here is to use the Sysinternals junction tool
148148
# to create a hard link between an "openssl-1.x" sub-directory of the
149149
# Fossil source code directory and the target OpenSSL source directory.
150150
#
151
-OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
152
-OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
151
+OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1k/include
152
+OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1k
153153
154154
#### Either the directory where the Tcl library is installed or the Tcl
155155
# source code directory resides (depending on the value of the macro
156156
# FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
157157
# this directory must have "include" and "lib" sub-directories. If
158158
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -146,12 +146,12 @@
146 #### The directories where the OpenSSL include and library files are located.
147 # The recommended usage here is to use the Sysinternals junction tool
148 # to create a hard link between an "openssl-1.x" sub-directory of the
149 # Fossil source code directory and the target OpenSSL source directory.
150 #
151 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
152 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
153
154 #### Either the directory where the Tcl library is installed or the Tcl
155 # source code directory resides (depending on the value of the macro
156 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
157 # this directory must have "include" and "lib" sub-directories. If
158
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -146,12 +146,12 @@
146 #### The directories where the OpenSSL include and library files are located.
147 # The recommended usage here is to use the Sysinternals junction tool
148 # to create a hard link between an "openssl-1.x" sub-directory of the
149 # Fossil source code directory and the target OpenSSL source directory.
150 #
151 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1k/include
152 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1k
153
154 #### Either the directory where the Tcl library is installed or the Tcl
155 # source code directory resides (depending on the value of the macro
156 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
157 # this directory must have "include" and "lib" sub-directories. If
158
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -146,12 +146,12 @@
146146
#### The directories where the OpenSSL include and library files are located.
147147
# The recommended usage here is to use the Sysinternals junction tool
148148
# to create a hard link between an "openssl-1.x" sub-directory of the
149149
# Fossil source code directory and the target OpenSSL source directory.
150150
#
151
-OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
152
-OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
151
+OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1k/include
152
+OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1k
153153
154154
#### Either the directory where the Tcl library is installed or the Tcl
155155
# source code directory resides (depending on the value of the macro
156156
# FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
157157
# this directory must have "include" and "lib" sub-directories. If
158158
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -146,12 +146,12 @@
146 #### The directories where the OpenSSL include and library files are located.
147 # The recommended usage here is to use the Sysinternals junction tool
148 # to create a hard link between an "openssl-1.x" sub-directory of the
149 # Fossil source code directory and the target OpenSSL source directory.
150 #
151 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
152 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
153
154 #### Either the directory where the Tcl library is installed or the Tcl
155 # source code directory resides (depending on the value of the macro
156 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
157 # this directory must have "include" and "lib" sub-directories. If
158
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -146,12 +146,12 @@
146 #### The directories where the OpenSSL include and library files are located.
147 # The recommended usage here is to use the Sysinternals junction tool
148 # to create a hard link between an "openssl-1.x" sub-directory of the
149 # Fossil source code directory and the target OpenSSL source directory.
150 #
151 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1k/include
152 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1k
153
154 #### Either the directory where the Tcl library is installed or the Tcl
155 # source code directory resides (depending on the value of the macro
156 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
157 # this directory must have "include" and "lib" sub-directories. If
158
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -146,12 +146,12 @@
146146
#### The directories where the OpenSSL include and library files are located.
147147
# The recommended usage here is to use the Sysinternals junction tool
148148
# to create a hard link between an "openssl-1.x" sub-directory of the
149149
# Fossil source code directory and the target OpenSSL source directory.
150150
#
151
-OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
152
-OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
151
+OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1k/include
152
+OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1k
153153
154154
#### Either the directory where the Tcl library is installed or the Tcl
155155
# source code directory resides (depending on the value of the macro
156156
# FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
157157
# this directory must have "include" and "lib" sub-directories. If
158158
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -146,12 +146,12 @@
146 #### The directories where the OpenSSL include and library files are located.
147 # The recommended usage here is to use the Sysinternals junction tool
148 # to create a hard link between an "openssl-1.x" sub-directory of the
149 # Fossil source code directory and the target OpenSSL source directory.
150 #
151 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
152 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
153
154 #### Either the directory where the Tcl library is installed or the Tcl
155 # source code directory resides (depending on the value of the macro
156 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
157 # this directory must have "include" and "lib" sub-directories. If
158
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -146,12 +146,12 @@
146 #### The directories where the OpenSSL include and library files are located.
147 # The recommended usage here is to use the Sysinternals junction tool
148 # to create a hard link between an "openssl-1.x" sub-directory of the
149 # Fossil source code directory and the target OpenSSL source directory.
150 #
151 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1k/include
152 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1k
153
154 #### Either the directory where the Tcl library is installed or the Tcl
155 # source code directory resides (depending on the value of the macro
156 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
157 # this directory must have "include" and "lib" sub-directories. If
158
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -55,11 +55,11 @@
5555
5656
# Uncomment to enable Tcl support
5757
# FOSSIL_ENABLE_TCL = 1
5858
5959
!ifdef FOSSIL_ENABLE_SSL
60
-SSLDIR = $(B)\compat\openssl-1.0.1j
60
+SSLDIR = $(B)\compat\openssl-1.0.1k
6161
SSLINCDIR = $(SSLDIR)\inc32
6262
SSLLIBDIR = $(SSLDIR)\out32
6363
SSLLFLAGS = /nologo /opt:ref /debug
6464
SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
6565
!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
6666
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -55,11 +55,11 @@
55
56 # Uncomment to enable Tcl support
57 # FOSSIL_ENABLE_TCL = 1
58
59 !ifdef FOSSIL_ENABLE_SSL
60 SSLDIR = $(B)\compat\openssl-1.0.1j
61 SSLINCDIR = $(SSLDIR)\inc32
62 SSLLIBDIR = $(SSLDIR)\out32
63 SSLLFLAGS = /nologo /opt:ref /debug
64 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
65 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
66
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -55,11 +55,11 @@
55
56 # Uncomment to enable Tcl support
57 # FOSSIL_ENABLE_TCL = 1
58
59 !ifdef FOSSIL_ENABLE_SSL
60 SSLDIR = $(B)\compat\openssl-1.0.1k
61 SSLINCDIR = $(SSLDIR)\inc32
62 SSLLIBDIR = $(SSLDIR)\out32
63 SSLLFLAGS = /nologo /opt:ref /debug
64 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
65 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
66
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -55,11 +55,11 @@
5555
5656
# Uncomment to enable Tcl support
5757
# FOSSIL_ENABLE_TCL = 1
5858
5959
!ifdef FOSSIL_ENABLE_SSL
60
-SSLDIR = $(B)\compat\openssl-1.0.1j
60
+SSLDIR = $(B)\compat\openssl-1.0.1k
6161
SSLINCDIR = $(SSLDIR)\inc32
6262
SSLLIBDIR = $(SSLDIR)\out32
6363
SSLLFLAGS = /nologo /opt:ref /debug
6464
SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
6565
!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
6666
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -55,11 +55,11 @@
55
56 # Uncomment to enable Tcl support
57 # FOSSIL_ENABLE_TCL = 1
58
59 !ifdef FOSSIL_ENABLE_SSL
60 SSLDIR = $(B)\compat\openssl-1.0.1j
61 SSLINCDIR = $(SSLDIR)\inc32
62 SSLLIBDIR = $(SSLDIR)\out32
63 SSLLFLAGS = /nologo /opt:ref /debug
64 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
65 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
66
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -55,11 +55,11 @@
55
56 # Uncomment to enable Tcl support
57 # FOSSIL_ENABLE_TCL = 1
58
59 !ifdef FOSSIL_ENABLE_SSL
60 SSLDIR = $(B)\compat\openssl-1.0.1k
61 SSLINCDIR = $(SSLDIR)\inc32
62 SSLLIBDIR = $(SSLDIR)\out32
63 SSLLFLAGS = /nologo /opt:ref /debug
64 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
65 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
66
+1 -1
--- www/build.wiki
+++ www/build.wiki
@@ -122,11 +122,11 @@
122122
the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
123123
first <a href="https://www.openssl.org/source/">download the official
124124
source code for OpenSSL</a> and extract it to an appropriately named
125125
"<b>openssl-X.Y.ZA</b>" subdirectory within the local
126126
[/tree?ci=trunk&name=compat | compat] directory (e.g.
127
-"<b>compat/openssl-1.0.1j</b>"), then make sure that some recent
127
+"<b>compat/openssl-1.0.1k</b>"), then make sure that some recent
128128
<a href="http://www.perl.org/">Perl</a> binaries are installed locally,
129129
and finally run one of the following commands:
130130
<blockquote><pre>
131131
nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
132132
</pre></blockquote>
133133
--- www/build.wiki
+++ www/build.wiki
@@ -122,11 +122,11 @@
122 the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
123 first <a href="https://www.openssl.org/source/">download the official
124 source code for OpenSSL</a> and extract it to an appropriately named
125 "<b>openssl-X.Y.ZA</b>" subdirectory within the local
126 [/tree?ci=trunk&name=compat | compat] directory (e.g.
127 "<b>compat/openssl-1.0.1j</b>"), then make sure that some recent
128 <a href="http://www.perl.org/">Perl</a> binaries are installed locally,
129 and finally run one of the following commands:
130 <blockquote><pre>
131 nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
132 </pre></blockquote>
133
--- www/build.wiki
+++ www/build.wiki
@@ -122,11 +122,11 @@
122 the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
123 first <a href="https://www.openssl.org/source/">download the official
124 source code for OpenSSL</a> and extract it to an appropriately named
125 "<b>openssl-X.Y.ZA</b>" subdirectory within the local
126 [/tree?ci=trunk&name=compat | compat] directory (e.g.
127 "<b>compat/openssl-1.0.1k</b>"), then make sure that some recent
128 <a href="http://www.perl.org/">Perl</a> binaries are installed locally,
129 and finally run one of the following commands:
130 <blockquote><pre>
131 nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
132 </pre></blockquote>
133
--- www/delta_format.wiki
+++ www/delta_format.wiki
@@ -66,11 +66,11 @@
6666
<a name="slist"></a><h3>1.3 Segment-List</h3>
6767
<img src="delta2.gif" align="left" hspace="10">
6868
6969
<p>The segment-list of a delta describes how to create the target from
7070
the original by a combination of inserting literal byte-sequences and
71
-copying ranges of bytes from the original. This is there the
71
+copying ranges of bytes from the original. This is where the
7272
compression takes place, by encoding the large common parts of
7373
original and target in small copy instructions.</p>
7474
7575
<p>The target is constructed from beginning to end, with the data
7676
generated by each instruction appended after the data of all previous
@@ -213,11 +213,11 @@
213213
<ul>
214214
<li>Pure text files generate a pure text delta.
215215
</li>
216216
<li>Binary files generate a delta that may contain some binary data.
217217
</li>
218
-<li>The delta encoding does not attempt to compress the content
218
+<li>The delta encoding does not attempt to compress the content.
219219
It was considered to be much
220220
more sensible to do compression using a separate general-purpose
221221
compression library, like <a href="http://www.zlib.net">zlib</a>.
222222
</li>
223223
</ul>
224224
--- www/delta_format.wiki
+++ www/delta_format.wiki
@@ -66,11 +66,11 @@
66 <a name="slist"></a><h3>1.3 Segment-List</h3>
67 <img src="delta2.gif" align="left" hspace="10">
68
69 <p>The segment-list of a delta describes how to create the target from
70 the original by a combination of inserting literal byte-sequences and
71 copying ranges of bytes from the original. This is there the
72 compression takes place, by encoding the large common parts of
73 original and target in small copy instructions.</p>
74
75 <p>The target is constructed from beginning to end, with the data
76 generated by each instruction appended after the data of all previous
@@ -213,11 +213,11 @@
213 <ul>
214 <li>Pure text files generate a pure text delta.
215 </li>
216 <li>Binary files generate a delta that may contain some binary data.
217 </li>
218 <li>The delta encoding does not attempt to compress the content
219 It was considered to be much
220 more sensible to do compression using a separate general-purpose
221 compression library, like <a href="http://www.zlib.net">zlib</a>.
222 </li>
223 </ul>
224
--- www/delta_format.wiki
+++ www/delta_format.wiki
@@ -66,11 +66,11 @@
66 <a name="slist"></a><h3>1.3 Segment-List</h3>
67 <img src="delta2.gif" align="left" hspace="10">
68
69 <p>The segment-list of a delta describes how to create the target from
70 the original by a combination of inserting literal byte-sequences and
71 copying ranges of bytes from the original. This is where the
72 compression takes place, by encoding the large common parts of
73 original and target in small copy instructions.</p>
74
75 <p>The target is constructed from beginning to end, with the data
76 generated by each instruction appended after the data of all previous
@@ -213,11 +213,11 @@
213 <ul>
214 <li>Pure text files generate a pure text delta.
215 </li>
216 <li>Binary files generate a delta that may contain some binary data.
217 </li>
218 <li>The delta encoding does not attempt to compress the content.
219 It was considered to be much
220 more sensible to do compression using a separate general-purpose
221 compression library, like <a href="http://www.zlib.net">zlib</a>.
222 </li>
223 </ul>
224
--- www/fileformat.wiki
+++ www/fileformat.wiki
@@ -49,11 +49,11 @@
4949
</ul>
5050
5151
These seven artifact types are described in the following sections.
5252
5353
In the current implementation (as of 2009-01-25) the artifacts that
54
-make up a fossil repository are stored in in as delta- and zlib-compressed
54
+make up a fossil repository are stored as delta- and zlib-compressed
5555
blobs in an <a href="http://www.sqlite.org/">SQLite</a> database. This
5656
is an implementation detail and might change in a future release. For
5757
the purpose of this article "file format" means the format of the artifacts,
5858
not how the artifacts are stored on disk. It is the artifact format that
5959
is intended to be enduring. The specifics of how artifacts are stored on
@@ -184,11 +184,11 @@
184184
ancestor, the Q-card is used to identify a single check-in or a small
185185
range of check-ins which were cherry-picked for inclusion in or
186186
exclusion from the current manifest. The first argument of
187187
the Q-card is the artifact ID of another manifest (the "target")
188188
which has had its changes included or excluded in the current manifest.
189
-The target is preceeded by "+" or "-" to show inclusion or
189
+The target is preceded by "+" or "-" to show inclusion or
190190
exclusion, respectively. The optional second argument to the
191191
Q-card is another manifest artifact ID which is the "baseline"
192192
for the cherry-pick. If omitted, the baseline is the primary
193193
parent of the target. The
194194
changes included or excluded consist of all changes moving from
@@ -315,11 +315,11 @@
315315
is either "+", "-", or "*". The "+" means the tag should be added
316316
to the artifact. The "-" means the tag should be removed.
317317
The "*" character means the tag should be added to the artifact
318318
and all direct descendants (but not descendents through a merge) down
319319
to but not including the first descendant that contains a
320
-more recent "-" or "+" tag with the same name.
320
+more recent "-", "*", or "+" tag with the same name.
321321
The optional third argument is the value of the tag. A tag
322322
without a value is a boolean.
323323
324324
When two or more tags with the same name are applied to the
325325
same artifact, the tag with the latest (most recent) date is
@@ -362,11 +362,11 @@
362362
gives the name of the wiki page. The optional N card specifies
363363
the mimetype of the wiki text. If the N card is omitted, the
364364
mimetype is assumed to be text/x-fossil-wiki.
365365
The U card specifies the login
366366
of the user who made this edit to the wiki page. The Z card is
367
-the usual checksum over the either artifact and is required.
367
+the usual checksum over the entire artifact and is required.
368368
369369
The W card is used to specify the text of the wiki page. The
370370
argument to the W card is an integer which is the number of bytes
371371
of text in the wiki page. That text follows the newline character
372372
that terminates the W card. The wiki text is always followed by one
@@ -453,11 +453,11 @@
453453
454454
There may be zero or one N cards. The N card specifies the mimetype of the
455455
comment text provided in the C card. If the N card is omitted, the C card
456456
mimetype is taken to be text/plain.
457457
458
-A single U card gives the name of the user to added the attachment.
458
+A single U card gives the name of the user who added the attachment.
459459
If an attachment is added anonymously, then the U card may be omitted.
460460
461461
The Z card is the usual checksum over the rest of the attachment artifact.
462462
The Z card is required.
463463
464464
--- www/fileformat.wiki
+++ www/fileformat.wiki
@@ -49,11 +49,11 @@
49 </ul>
50
51 These seven artifact types are described in the following sections.
52
53 In the current implementation (as of 2009-01-25) the artifacts that
54 make up a fossil repository are stored in in as delta- and zlib-compressed
55 blobs in an <a href="http://www.sqlite.org/">SQLite</a> database. This
56 is an implementation detail and might change in a future release. For
57 the purpose of this article "file format" means the format of the artifacts,
58 not how the artifacts are stored on disk. It is the artifact format that
59 is intended to be enduring. The specifics of how artifacts are stored on
@@ -184,11 +184,11 @@
184 ancestor, the Q-card is used to identify a single check-in or a small
185 range of check-ins which were cherry-picked for inclusion in or
186 exclusion from the current manifest. The first argument of
187 the Q-card is the artifact ID of another manifest (the "target")
188 which has had its changes included or excluded in the current manifest.
189 The target is preceeded by "+" or "-" to show inclusion or
190 exclusion, respectively. The optional second argument to the
191 Q-card is another manifest artifact ID which is the "baseline"
192 for the cherry-pick. If omitted, the baseline is the primary
193 parent of the target. The
194 changes included or excluded consist of all changes moving from
@@ -315,11 +315,11 @@
315 is either "+", "-", or "*". The "+" means the tag should be added
316 to the artifact. The "-" means the tag should be removed.
317 The "*" character means the tag should be added to the artifact
318 and all direct descendants (but not descendents through a merge) down
319 to but not including the first descendant that contains a
320 more recent "-" or "+" tag with the same name.
321 The optional third argument is the value of the tag. A tag
322 without a value is a boolean.
323
324 When two or more tags with the same name are applied to the
325 same artifact, the tag with the latest (most recent) date is
@@ -362,11 +362,11 @@
362 gives the name of the wiki page. The optional N card specifies
363 the mimetype of the wiki text. If the N card is omitted, the
364 mimetype is assumed to be text/x-fossil-wiki.
365 The U card specifies the login
366 of the user who made this edit to the wiki page. The Z card is
367 the usual checksum over the either artifact and is required.
368
369 The W card is used to specify the text of the wiki page. The
370 argument to the W card is an integer which is the number of bytes
371 of text in the wiki page. That text follows the newline character
372 that terminates the W card. The wiki text is always followed by one
@@ -453,11 +453,11 @@
453
454 There may be zero or one N cards. The N card specifies the mimetype of the
455 comment text provided in the C card. If the N card is omitted, the C card
456 mimetype is taken to be text/plain.
457
458 A single U card gives the name of the user to added the attachment.
459 If an attachment is added anonymously, then the U card may be omitted.
460
461 The Z card is the usual checksum over the rest of the attachment artifact.
462 The Z card is required.
463
464
--- www/fileformat.wiki
+++ www/fileformat.wiki
@@ -49,11 +49,11 @@
49 </ul>
50
51 These seven artifact types are described in the following sections.
52
53 In the current implementation (as of 2009-01-25) the artifacts that
54 make up a fossil repository are stored as delta- and zlib-compressed
55 blobs in an <a href="http://www.sqlite.org/">SQLite</a> database. This
56 is an implementation detail and might change in a future release. For
57 the purpose of this article "file format" means the format of the artifacts,
58 not how the artifacts are stored on disk. It is the artifact format that
59 is intended to be enduring. The specifics of how artifacts are stored on
@@ -184,11 +184,11 @@
184 ancestor, the Q-card is used to identify a single check-in or a small
185 range of check-ins which were cherry-picked for inclusion in or
186 exclusion from the current manifest. The first argument of
187 the Q-card is the artifact ID of another manifest (the "target")
188 which has had its changes included or excluded in the current manifest.
189 The target is preceded by "+" or "-" to show inclusion or
190 exclusion, respectively. The optional second argument to the
191 Q-card is another manifest artifact ID which is the "baseline"
192 for the cherry-pick. If omitted, the baseline is the primary
193 parent of the target. The
194 changes included or excluded consist of all changes moving from
@@ -315,11 +315,11 @@
315 is either "+", "-", or "*". The "+" means the tag should be added
316 to the artifact. The "-" means the tag should be removed.
317 The "*" character means the tag should be added to the artifact
318 and all direct descendants (but not descendents through a merge) down
319 to but not including the first descendant that contains a
320 more recent "-", "*", or "+" tag with the same name.
321 The optional third argument is the value of the tag. A tag
322 without a value is a boolean.
323
324 When two or more tags with the same name are applied to the
325 same artifact, the tag with the latest (most recent) date is
@@ -362,11 +362,11 @@
362 gives the name of the wiki page. The optional N card specifies
363 the mimetype of the wiki text. If the N card is omitted, the
364 mimetype is assumed to be text/x-fossil-wiki.
365 The U card specifies the login
366 of the user who made this edit to the wiki page. The Z card is
367 the usual checksum over the entire artifact and is required.
368
369 The W card is used to specify the text of the wiki page. The
370 argument to the W card is an integer which is the number of bytes
371 of text in the wiki page. That text follows the newline character
372 that terminates the W card. The wiki text is always followed by one
@@ -453,11 +453,11 @@
453
454 There may be zero or one N cards. The N card specifies the mimetype of the
455 comment text provided in the C card. If the N card is omitted, the C card
456 mimetype is taken to be text/plain.
457
458 A single U card gives the name of the user who added the attachment.
459 If an attachment is added anonymously, then the U card may be omitted.
460
461 The Z card is the usual checksum over the rest of the attachment artifact.
462 The Z card is required.
463
464
+2 -1
--- www/hints.wiki
+++ www/hints.wiki
@@ -9,11 +9,12 @@
99
window is run as a separate Tcl/Tk process, so you will need to
1010
have Tcl/Tk installed on your machine for this to work. Visit
1111
[http://www.activestate.com/activetcl] to for a quick download of
1212
Tcl/Tk if you do not already have it on your system.)
1313
14
- 3. The "[/help?cmd=clean | fossil clean -f]" command makes a great
14
+ 3. The "[/help/clean | fossil clean -f]" or
15
+ "[/help/clean | fossil clean --verily]" command is a great
1516
alternative to "make clean".
1617
1718
4. Use "[/help?cmd=all | fossil all changes]" to look for any uncommitted
1819
edits in any of your Fossil projects. Use
1920
"[/help?cmd=all | fossil all pull]" on your laptop
2021
--- www/hints.wiki
+++ www/hints.wiki
@@ -9,11 +9,12 @@
9 window is run as a separate Tcl/Tk process, so you will need to
10 have Tcl/Tk installed on your machine for this to work. Visit
11 [http://www.activestate.com/activetcl] to for a quick download of
12 Tcl/Tk if you do not already have it on your system.)
13
14 3. The "[/help?cmd=clean | fossil clean -f]" command makes a great
 
15 alternative to "make clean".
16
17 4. Use "[/help?cmd=all | fossil all changes]" to look for any uncommitted
18 edits in any of your Fossil projects. Use
19 "[/help?cmd=all | fossil all pull]" on your laptop
20
--- www/hints.wiki
+++ www/hints.wiki
@@ -9,11 +9,12 @@
9 window is run as a separate Tcl/Tk process, so you will need to
10 have Tcl/Tk installed on your machine for this to work. Visit
11 [http://www.activestate.com/activetcl] to for a quick download of
12 Tcl/Tk if you do not already have it on your system.)
13
14 3. The "[/help/clean | fossil clean -f]" or
15 "[/help/clean | fossil clean --verily]" command is a great
16 alternative to "make clean".
17
18 4. Use "[/help?cmd=all | fossil all changes]" to look for any uncommitted
19 edits in any of your Fossil projects. Use
20 "[/help?cmd=all | fossil all pull]" on your laptop
21
+3 -1
--- www/qandc.wiki
+++ www/qandc.wiki
@@ -146,11 +146,13 @@
146146
You do not need any other packages
147147
(diff, patch, merge, cvs, svn, rcs, git, python, perl, tcl, apache,
148148
sqlite, and so forth)
149149
in order to run fossil. Fossil runs just fine in a chroot jail all
150150
by itself. And the self-contained fossil
151
-executable is much less than 1MB in size.
151
+executable is much less than 1MB in size. (Update 2015-01-12: Fossil has
152
+grown in the years since the previous sentence was written but is still
153
+much less than 2MB according to "size" when compiled using -Os on x64 Linux.)
152154
Fossil is the very opposite of bloat.</p>
153155
</blockquote>
154156
155157
156158
</nowiki>
157159
--- www/qandc.wiki
+++ www/qandc.wiki
@@ -146,11 +146,13 @@
146 You do not need any other packages
147 (diff, patch, merge, cvs, svn, rcs, git, python, perl, tcl, apache,
148 sqlite, and so forth)
149 in order to run fossil. Fossil runs just fine in a chroot jail all
150 by itself. And the self-contained fossil
151 executable is much less than 1MB in size.
 
 
152 Fossil is the very opposite of bloat.</p>
153 </blockquote>
154
155
156 </nowiki>
157
--- www/qandc.wiki
+++ www/qandc.wiki
@@ -146,11 +146,13 @@
146 You do not need any other packages
147 (diff, patch, merge, cvs, svn, rcs, git, python, perl, tcl, apache,
148 sqlite, and so forth)
149 in order to run fossil. Fossil runs just fine in a chroot jail all
150 by itself. And the self-contained fossil
151 executable is much less than 1MB in size. (Update 2015-01-12: Fossil has
152 grown in the years since the previous sentence was written but is still
153 much less than 2MB according to "size" when compiled using -Os on x64 Linux.)
154 Fossil is the very opposite of bloat.</p>
155 </blockquote>
156
157
158 </nowiki>
159

Keyboard Shortcuts

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