Fossil SCM

Merge with trunk.

isaac.jurado 2013-07-14 22:25 git-better-import merge
Commit 3c777c4b6a9b5413d54d3cfa660c290d620ad1b7
+1 -1
--- src/browse.c
+++ src/browse.c
@@ -411,11 +411,11 @@
411411
baseTime = db_double(0.0, "SELECT mtime FROM event WHERE objid=%d", rid);
412412
zBaseTime = db_text("","SELECT datetime(%.20g,'localtime')", baseTime);
413413
@ <h2>File Ages For Check-in
414414
@ %z(href("%R/info?name=%T",zName))%h(zName)</a></h2>
415415
@
416
- @ <p>The times given are relative
416
+ @ <p>The times given are relative to
417417
@ %z(href("%R/timeline?c=%T",zBaseTime))%s(zBaseTime)</a>, which is the
418418
@ check-in time for
419419
@ %z(href("%R/info?name=%T",zName))%h(zName)</a></p>
420420
@
421421
@ <table border=0 cellspacing=0 cellpadding=0>
422422
--- src/browse.c
+++ src/browse.c
@@ -411,11 +411,11 @@
411 baseTime = db_double(0.0, "SELECT mtime FROM event WHERE objid=%d", rid);
412 zBaseTime = db_text("","SELECT datetime(%.20g,'localtime')", baseTime);
413 @ <h2>File Ages For Check-in
414 @ %z(href("%R/info?name=%T",zName))%h(zName)</a></h2>
415 @
416 @ <p>The times given are relative
417 @ %z(href("%R/timeline?c=%T",zBaseTime))%s(zBaseTime)</a>, which is the
418 @ check-in time for
419 @ %z(href("%R/info?name=%T",zName))%h(zName)</a></p>
420 @
421 @ <table border=0 cellspacing=0 cellpadding=0>
422
--- src/browse.c
+++ src/browse.c
@@ -411,11 +411,11 @@
411 baseTime = db_double(0.0, "SELECT mtime FROM event WHERE objid=%d", rid);
412 zBaseTime = db_text("","SELECT datetime(%.20g,'localtime')", baseTime);
413 @ <h2>File Ages For Check-in
414 @ %z(href("%R/info?name=%T",zName))%h(zName)</a></h2>
415 @
416 @ <p>The times given are relative to
417 @ %z(href("%R/timeline?c=%T",zBaseTime))%s(zBaseTime)</a>, which is the
418 @ check-in time for
419 @ %z(href("%R/info?name=%T",zName))%h(zName)</a></p>
420 @
421 @ <table border=0 cellspacing=0 cellpadding=0>
422
+32 -38
--- src/checkin.c
+++ src/checkin.c
@@ -315,30 +315,34 @@
315315
int isDeleted = db_column_int(&q, 1);
316316
int isNew = db_column_int(&q,2)==0;
317317
int chnged = db_column_int(&q,3);
318318
int renamed = db_column_int(&q,4);
319319
char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
320
- if( showAge ){
321
- fossil_print("%s %s\n", db_column_text(&q, 5), zPathname);
322
- }else if( !verboseFlag ){
323
- fossil_print("%s\n", zPathname);
324
- }else if( isNew ){
325
- fossil_print("ADDED %s\n", zPathname);
326
- }else if( isDeleted ){
327
- fossil_print("DELETED %s\n", zPathname);
328
- }else if( !file_wd_isfile_or_link(zFullName) ){
329
- if( file_access(zFullName, 0)==0 ){
330
- fossil_print("NOT_A_FILE %s\n", zPathname);
331
- }else{
332
- fossil_print("MISSING %s\n", zPathname);
333
- }
334
- }else if( chnged ){
335
- fossil_print("EDITED %s\n", zPathname);
336
- }else if( renamed ){
337
- fossil_print("RENAMED %s\n", zPathname);
338
- }else{
339
- fossil_print("UNCHANGED %s\n", zPathname);
320
+ const char *type = "";
321
+ if( verboseFlag ){
322
+ if( isNew ){
323
+ type = "ADDED ";
324
+ }else if( isDeleted ){
325
+ type = "DELETED ";
326
+ }else if( !file_wd_isfile_or_link(zFullName) ){
327
+ if( file_access(zFullName, 0)==0 ){
328
+ type = "NOT_A_FILE ";
329
+ }else{
330
+ type = "MISSING ";
331
+ }
332
+ }else if( chnged ){
333
+ type = "EDITED ";
334
+ }else if( renamed ){
335
+ type = "RENAMED ";
336
+ }else{
337
+ type = "UNCHANGED ";
338
+ }
339
+ }
340
+ if( showAge ){
341
+ fossil_print("%s%s %s\n", type, db_column_text(&q, 5), zPathname);
342
+ }else{
343
+ fossil_print("%s%s\n", type, zPathname);
340344
}
341345
free(zFullName);
342346
}
343347
db_finalize(&q);
344348
}
@@ -745,11 +749,10 @@
745749
int result = 0;
746750
assert( g.aCommitFile==0 );
747751
if( g.argc>2 ){
748752
int ii, jj=0;
749753
Blob fname;
750
- int isDir;
751754
Stmt q;
752755
const char *zCollate;
753756
Bag toCommit;
754757
755758
zCollate = filename_collation();
@@ -760,24 +763,15 @@
760763
file_tree_name(g.argv[ii], &fname, 1);
761764
if( fossil_strcmp(blob_str(&fname),".")==0 ){
762765
bag_clear(&toCommit);
763766
return result;
764767
}
765
- isDir = file_isdir(g.argv[ii]);
766
- if( isDir==1 ){
767
- db_prepare(&q,
768
- "SELECT id FROM vfile WHERE pathname>'%q/' %s AND pathname<'%q0'",
769
- blob_str(&fname), zCollate, blob_str(&fname), zCollate);
770
- }else if( isDir==2 ){
771
- db_prepare(&q,
772
- "SELECT id FROM vfile WHERE pathname=%Q",
773
- blob_str(&fname), zCollate);
774
- }else{
775
- fossil_warning("not found: %s", g.argv[ii]);
776
- result = 1;
777
- continue;
778
- }
768
+ db_prepare(&q,
769
+ "SELECT id FROM vfile WHERE pathname=%Q %s"
770
+ " OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
771
+ blob_str(&fname), zCollate, blob_str(&fname),
772
+ zCollate, blob_str(&fname), zCollate);
779773
while( db_step(&q)==SQLITE_ROW ){
780774
cnt++;
781775
bag_insert(&toCommit, db_column_int(&q, 0));
782776
}
783777
db_finalize(&q);
@@ -995,11 +989,11 @@
995989
blob_appendf(pOut, "N %F\n", p->zMimetype);
996990
}
997991
blob_appendf(pOut, "P %s", zParentUuid);
998992
if( p->verifyDate ) checkin_verify_younger(vid, zParentUuid, zDate);
999993
free(zParentUuid);
1000
- db_prepare(&q2, "SELECT merge FROM vmerge WHERE id=0");
994
+ db_prepare(&q2, "SELECT merge FROM vmerge WHERE id=0 OR id<-2");
1001995
while( db_step(&q2)==SQLITE_ROW ){
1002996
char *zMergeUuid;
1003997
int mid = db_column_int(&q2, 0);
1004998
if( !g.markPrivate && content_is_private(mid) ) continue;
1005999
zMergeUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", mid);
@@ -1014,11 +1008,11 @@
10141008
blob_appendf(pOut, "\n");
10151009
10161010
db_prepare(&q2,
10171011
"SELECT CASE vmerge.id WHEN -1 THEN '+' ELSE '-' END || blob.uuid"
10181012
" FROM vmerge, blob"
1019
- " WHERE vmerge.id<0"
1013
+ " WHERE (vmerge.id=-1 OR vmerge.id=-2)"
10201014
" AND blob.rid=vmerge.merge"
10211015
" ORDER BY 1");
10221016
while( db_step(&q2)==SQLITE_ROW ){
10231017
const char *zCherrypickUuid = db_column_text(&q2, 0);
10241018
blob_appendf(pOut, "Q %s\n", zCherrypickUuid);
@@ -1429,11 +1423,11 @@
14291423
blob_zero(&ans);
14301424
prompt_user("continue (y/N)? ", &ans);
14311425
cReply = blob_str(&ans)[0];
14321426
if( cReply!='y' && cReply!='Y' ) fossil_exit(1);;
14331427
}
1434
- isAMerge = db_exists("SELECT 1 FROM vmerge WHERE id=0");
1428
+ isAMerge = db_exists("SELECT 1 FROM vmerge WHERE id=0 OR id<-2");
14351429
if( g.aCommitFile && isAMerge ){
14361430
fossil_fatal("cannot do a partial commit of a merge");
14371431
}
14381432
14391433
/* Doing "fossil mv fileA fileB; fossil add fileA; fossil commit fileA"
14401434
--- src/checkin.c
+++ src/checkin.c
@@ -315,30 +315,34 @@
315 int isDeleted = db_column_int(&q, 1);
316 int isNew = db_column_int(&q,2)==0;
317 int chnged = db_column_int(&q,3);
318 int renamed = db_column_int(&q,4);
319 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
320 if( showAge ){
321 fossil_print("%s %s\n", db_column_text(&q, 5), zPathname);
322 }else if( !verboseFlag ){
323 fossil_print("%s\n", zPathname);
324 }else if( isNew ){
325 fossil_print("ADDED %s\n", zPathname);
326 }else if( isDeleted ){
327 fossil_print("DELETED %s\n", zPathname);
328 }else if( !file_wd_isfile_or_link(zFullName) ){
329 if( file_access(zFullName, 0)==0 ){
330 fossil_print("NOT_A_FILE %s\n", zPathname);
331 }else{
332 fossil_print("MISSING %s\n", zPathname);
333 }
334 }else if( chnged ){
335 fossil_print("EDITED %s\n", zPathname);
336 }else if( renamed ){
337 fossil_print("RENAMED %s\n", zPathname);
338 }else{
339 fossil_print("UNCHANGED %s\n", zPathname);
 
 
 
 
340 }
341 free(zFullName);
342 }
343 db_finalize(&q);
344 }
@@ -745,11 +749,10 @@
745 int result = 0;
746 assert( g.aCommitFile==0 );
747 if( g.argc>2 ){
748 int ii, jj=0;
749 Blob fname;
750 int isDir;
751 Stmt q;
752 const char *zCollate;
753 Bag toCommit;
754
755 zCollate = filename_collation();
@@ -760,24 +763,15 @@
760 file_tree_name(g.argv[ii], &fname, 1);
761 if( fossil_strcmp(blob_str(&fname),".")==0 ){
762 bag_clear(&toCommit);
763 return result;
764 }
765 isDir = file_isdir(g.argv[ii]);
766 if( isDir==1 ){
767 db_prepare(&q,
768 "SELECT id FROM vfile WHERE pathname>'%q/' %s AND pathname<'%q0'",
769 blob_str(&fname), zCollate, blob_str(&fname), zCollate);
770 }else if( isDir==2 ){
771 db_prepare(&q,
772 "SELECT id FROM vfile WHERE pathname=%Q",
773 blob_str(&fname), zCollate);
774 }else{
775 fossil_warning("not found: %s", g.argv[ii]);
776 result = 1;
777 continue;
778 }
779 while( db_step(&q)==SQLITE_ROW ){
780 cnt++;
781 bag_insert(&toCommit, db_column_int(&q, 0));
782 }
783 db_finalize(&q);
@@ -995,11 +989,11 @@
995 blob_appendf(pOut, "N %F\n", p->zMimetype);
996 }
997 blob_appendf(pOut, "P %s", zParentUuid);
998 if( p->verifyDate ) checkin_verify_younger(vid, zParentUuid, zDate);
999 free(zParentUuid);
1000 db_prepare(&q2, "SELECT merge FROM vmerge WHERE id=0");
1001 while( db_step(&q2)==SQLITE_ROW ){
1002 char *zMergeUuid;
1003 int mid = db_column_int(&q2, 0);
1004 if( !g.markPrivate && content_is_private(mid) ) continue;
1005 zMergeUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", mid);
@@ -1014,11 +1008,11 @@
1014 blob_appendf(pOut, "\n");
1015
1016 db_prepare(&q2,
1017 "SELECT CASE vmerge.id WHEN -1 THEN '+' ELSE '-' END || blob.uuid"
1018 " FROM vmerge, blob"
1019 " WHERE vmerge.id<0"
1020 " AND blob.rid=vmerge.merge"
1021 " ORDER BY 1");
1022 while( db_step(&q2)==SQLITE_ROW ){
1023 const char *zCherrypickUuid = db_column_text(&q2, 0);
1024 blob_appendf(pOut, "Q %s\n", zCherrypickUuid);
@@ -1429,11 +1423,11 @@
1429 blob_zero(&ans);
1430 prompt_user("continue (y/N)? ", &ans);
1431 cReply = blob_str(&ans)[0];
1432 if( cReply!='y' && cReply!='Y' ) fossil_exit(1);;
1433 }
1434 isAMerge = db_exists("SELECT 1 FROM vmerge WHERE id=0");
1435 if( g.aCommitFile && isAMerge ){
1436 fossil_fatal("cannot do a partial commit of a merge");
1437 }
1438
1439 /* Doing "fossil mv fileA fileB; fossil add fileA; fossil commit fileA"
1440
--- src/checkin.c
+++ src/checkin.c
@@ -315,30 +315,34 @@
315 int isDeleted = db_column_int(&q, 1);
316 int isNew = db_column_int(&q,2)==0;
317 int chnged = db_column_int(&q,3);
318 int renamed = db_column_int(&q,4);
319 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
320 const char *type = "";
321 if( verboseFlag ){
322 if( isNew ){
323 type = "ADDED ";
324 }else if( isDeleted ){
325 type = "DELETED ";
326 }else if( !file_wd_isfile_or_link(zFullName) ){
327 if( file_access(zFullName, 0)==0 ){
328 type = "NOT_A_FILE ";
329 }else{
330 type = "MISSING ";
331 }
332 }else if( chnged ){
333 type = "EDITED ";
334 }else if( renamed ){
335 type = "RENAMED ";
336 }else{
337 type = "UNCHANGED ";
338 }
339 }
340 if( showAge ){
341 fossil_print("%s%s %s\n", type, db_column_text(&q, 5), zPathname);
342 }else{
343 fossil_print("%s%s\n", type, zPathname);
344 }
345 free(zFullName);
346 }
347 db_finalize(&q);
348 }
@@ -745,11 +749,10 @@
749 int result = 0;
750 assert( g.aCommitFile==0 );
751 if( g.argc>2 ){
752 int ii, jj=0;
753 Blob fname;
 
754 Stmt q;
755 const char *zCollate;
756 Bag toCommit;
757
758 zCollate = filename_collation();
@@ -760,24 +763,15 @@
763 file_tree_name(g.argv[ii], &fname, 1);
764 if( fossil_strcmp(blob_str(&fname),".")==0 ){
765 bag_clear(&toCommit);
766 return result;
767 }
768 db_prepare(&q,
769 "SELECT id FROM vfile WHERE pathname=%Q %s"
770 " OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
771 blob_str(&fname), zCollate, blob_str(&fname),
772 zCollate, blob_str(&fname), zCollate);
 
 
 
 
 
 
 
 
 
773 while( db_step(&q)==SQLITE_ROW ){
774 cnt++;
775 bag_insert(&toCommit, db_column_int(&q, 0));
776 }
777 db_finalize(&q);
@@ -995,11 +989,11 @@
989 blob_appendf(pOut, "N %F\n", p->zMimetype);
990 }
991 blob_appendf(pOut, "P %s", zParentUuid);
992 if( p->verifyDate ) checkin_verify_younger(vid, zParentUuid, zDate);
993 free(zParentUuid);
994 db_prepare(&q2, "SELECT merge FROM vmerge WHERE id=0 OR id<-2");
995 while( db_step(&q2)==SQLITE_ROW ){
996 char *zMergeUuid;
997 int mid = db_column_int(&q2, 0);
998 if( !g.markPrivate && content_is_private(mid) ) continue;
999 zMergeUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", mid);
@@ -1014,11 +1008,11 @@
1008 blob_appendf(pOut, "\n");
1009
1010 db_prepare(&q2,
1011 "SELECT CASE vmerge.id WHEN -1 THEN '+' ELSE '-' END || blob.uuid"
1012 " FROM vmerge, blob"
1013 " WHERE (vmerge.id=-1 OR vmerge.id=-2)"
1014 " AND blob.rid=vmerge.merge"
1015 " ORDER BY 1");
1016 while( db_step(&q2)==SQLITE_ROW ){
1017 const char *zCherrypickUuid = db_column_text(&q2, 0);
1018 blob_appendf(pOut, "Q %s\n", zCherrypickUuid);
@@ -1429,11 +1423,11 @@
1423 blob_zero(&ans);
1424 prompt_user("continue (y/N)? ", &ans);
1425 cReply = blob_str(&ans)[0];
1426 if( cReply!='y' && cReply!='Y' ) fossil_exit(1);;
1427 }
1428 isAMerge = db_exists("SELECT 1 FROM vmerge WHERE id=0 OR id<-2");
1429 if( g.aCommitFile && isAMerge ){
1430 fossil_fatal("cannot do a partial commit of a merge");
1431 }
1432
1433 /* Doing "fossil mv fileA fileB; fossil add fileA; fossil commit fileA"
1434
+1 -1
--- src/db.c
+++ src/db.c
@@ -2387,11 +2387,11 @@
23872387
}
23882388
if( isManifest && g.localOpen ){
23892389
manifest_to_disk(db_lget_int("checkout", 0));
23902390
}
23912391
}else{
2392
- usage("?PROPERTY? ?VALUE?");
2392
+ usage("?PROPERTY? ?VALUE? ?-global?");
23932393
}
23942394
}
23952395
23962396
/*
23972397
** The input in a timespan measured in days. Return a string which
23982398
--- src/db.c
+++ src/db.c
@@ -2387,11 +2387,11 @@
2387 }
2388 if( isManifest && g.localOpen ){
2389 manifest_to_disk(db_lget_int("checkout", 0));
2390 }
2391 }else{
2392 usage("?PROPERTY? ?VALUE?");
2393 }
2394 }
2395
2396 /*
2397 ** The input in a timespan measured in days. Return a string which
2398
--- src/db.c
+++ src/db.c
@@ -2387,11 +2387,11 @@
2387 }
2388 if( isManifest && g.localOpen ){
2389 manifest_to_disk(db_lget_int("checkout", 0));
2390 }
2391 }else{
2392 usage("?PROPERTY? ?VALUE? ?-global?");
2393 }
2394 }
2395
2396 /*
2397 ** The input in a timespan measured in days. Return a string which
2398
+6 -1
--- src/finfo.c
+++ src/finfo.c
@@ -463,11 +463,16 @@
463463
@ %z(href("%R/annotate?checkin=%S&filename=%h",zCkin,z))
464464
@ [annotate]</a>
465465
@ %z(href("%R/timeline?n=200&uf=%S",zUuid))[checkins&nbsp;using]</a>
466466
}
467467
if( fDebug & FINFO_DEBUG_MLINK ){
468
- @ fid=%d(frid), pid=%d(fpid), mid=%d(fmid)
468
+ int srcid = db_int(0, "SELECT srcid FROM delta WHERE rid=%d", frid);
469
+ int sz = db_int(0, "SELECT length(content) FROM blob WHERE rid=%d", frid);
470
+ @ <br>fid=%d(frid) pid=%d(fpid) mid=%d(fmid) sz=%d(sz)
471
+ if( srcid ){
472
+ @ srcid=%d(srcid)
473
+ }
469474
}
470475
@ </td></tr>
471476
}
472477
db_finalize(&q);
473478
if( pGraph ){
474479
--- src/finfo.c
+++ src/finfo.c
@@ -463,11 +463,16 @@
463 @ %z(href("%R/annotate?checkin=%S&filename=%h",zCkin,z))
464 @ [annotate]</a>
465 @ %z(href("%R/timeline?n=200&uf=%S",zUuid))[checkins&nbsp;using]</a>
466 }
467 if( fDebug & FINFO_DEBUG_MLINK ){
468 @ fid=%d(frid), pid=%d(fpid), mid=%d(fmid)
 
 
 
 
 
469 }
470 @ </td></tr>
471 }
472 db_finalize(&q);
473 if( pGraph ){
474
--- src/finfo.c
+++ src/finfo.c
@@ -463,11 +463,16 @@
463 @ %z(href("%R/annotate?checkin=%S&filename=%h",zCkin,z))
464 @ [annotate]</a>
465 @ %z(href("%R/timeline?n=200&uf=%S",zUuid))[checkins&nbsp;using]</a>
466 }
467 if( fDebug & FINFO_DEBUG_MLINK ){
468 int srcid = db_int(0, "SELECT srcid FROM delta WHERE rid=%d", frid);
469 int sz = db_int(0, "SELECT length(content) FROM blob WHERE rid=%d", frid);
470 @ <br>fid=%d(frid) pid=%d(fpid) mid=%d(fmid) sz=%d(sz)
471 if( srcid ){
472 @ srcid=%d(srcid)
473 }
474 }
475 @ </td></tr>
476 }
477 db_finalize(&q);
478 if( pGraph ){
479
+2 -2
--- src/manifest.c
+++ src/manifest.c
@@ -1715,12 +1715,12 @@
17151715
/* If this is a delta-manifest, record the fact that this repository
17161716
** contains delta manifests, to free the "commit" logic to generate
17171717
** new delta manifests.
17181718
*/
17191719
if( p->zBaseline!=0 ){
1720
- static int once = 0;
1721
- if( !once ){
1720
+ static int once = 1;
1721
+ if( once ){
17221722
db_set_int("seen-delta-manifest", 1, 0);
17231723
once = 0;
17241724
}
17251725
}
17261726
}
17271727
--- src/manifest.c
+++ src/manifest.c
@@ -1715,12 +1715,12 @@
1715 /* If this is a delta-manifest, record the fact that this repository
1716 ** contains delta manifests, to free the "commit" logic to generate
1717 ** new delta manifests.
1718 */
1719 if( p->zBaseline!=0 ){
1720 static int once = 0;
1721 if( !once ){
1722 db_set_int("seen-delta-manifest", 1, 0);
1723 once = 0;
1724 }
1725 }
1726 }
1727
--- src/manifest.c
+++ src/manifest.c
@@ -1715,12 +1715,12 @@
1715 /* If this is a delta-manifest, record the fact that this repository
1716 ** contains delta manifests, to free the "commit" logic to generate
1717 ** new delta manifests.
1718 */
1719 if( p->zBaseline!=0 ){
1720 static int once = 1;
1721 if( once ){
1722 db_set_int("seen-delta-manifest", 1, 0);
1723 once = 0;
1724 }
1725 }
1726 }
1727
+214 -81
--- src/shell.c
+++ src/shell.c
@@ -65,11 +65,11 @@
6565
#define isatty(h) _isatty(h)
6666
#define access(f,m) _access((f),(m))
6767
#undef popen
6868
#define popen(a,b) _popen((a),(b))
6969
#undef pclose
70
-#define pclose(x) _pclose(x)
70
+#define pclose _pclose
7171
#else
7272
/* Make sure isatty() has a prototype.
7373
*/
7474
extern int isatty(int);
7575
#endif
@@ -1107,10 +1107,12 @@
11071107
fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
11081108
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
11091109
fprintf(pArg->out, "Sort Operations: %d\n", iCur);
11101110
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, bReset);
11111111
fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
1112
+ iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
1113
+ fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
11121114
}
11131115
11141116
return 0;
11151117
}
11161118
@@ -1488,10 +1490,11 @@
14881490
** Do C-language style dequoting.
14891491
**
14901492
** \t -> tab
14911493
** \n -> newline
14921494
** \r -> carriage return
1495
+** \" -> "
14931496
** \NNN -> ascii character NNN in octal
14941497
** \\ -> backslash
14951498
*/
14961499
static void resolve_backslashes(char *z){
14971500
int i, j;
@@ -1503,10 +1506,12 @@
15031506
c = '\n';
15041507
}else if( c=='t' ){
15051508
c = '\t';
15061509
}else if( c=='r' ){
15071510
c = '\r';
1511
+ }else if( c=='\\' ){
1512
+ c = '\\';
15081513
}else if( c>='0' && c<='7' ){
15091514
c -= '0';
15101515
if( z[i+1]>='0' && z[i+1]<='7' ){
15111516
i++;
15121517
c = (c<<3) + z[i] - '0';
@@ -1645,10 +1650,111 @@
16451650
*/
16461651
static void test_breakpoint(void){
16471652
static int nCall = 0;
16481653
nCall++;
16491654
}
1655
+
1656
+/*
1657
+** An object used to read a CSV file
1658
+*/
1659
+typedef struct CSVReader CSVReader;
1660
+struct CSVReader {
1661
+ const char *zFile; /* Name of the input file */
1662
+ FILE *in; /* Read the CSV text from this input stream */
1663
+ char *z; /* Accumulated text for a field */
1664
+ int n; /* Number of bytes in z */
1665
+ int nAlloc; /* Space allocated for z[] */
1666
+ int nLine; /* Current line number */
1667
+ int cTerm; /* Character that terminated the most recent field */
1668
+ int cSeparator; /* The separator character. (Usually ",") */
1669
+};
1670
+
1671
+/* Append a single byte to z[] */
1672
+static void csv_append_char(CSVReader *p, int c){
1673
+ if( p->n+1>=p->nAlloc ){
1674
+ p->nAlloc += p->nAlloc + 100;
1675
+ p->z = sqlite3_realloc(p->z, p->nAlloc);
1676
+ if( p->z==0 ){
1677
+ fprintf(stderr, "out of memory\n");
1678
+ exit(1);
1679
+ }
1680
+ }
1681
+ p->z[p->n++] = (char)c;
1682
+}
1683
+
1684
+/* Read a single field of CSV text. Compatible with rfc4180 and extended
1685
+** with the option of having a separator other than ",".
1686
+**
1687
+** + Input comes from p->in.
1688
+** + Store results in p->z of length p->n. Space to hold p->z comes
1689
+** from sqlite3_malloc().
1690
+** + Use p->cSep as the separator. The default is ",".
1691
+** + Keep track of the line number in p->nLine.
1692
+** + Store the character that terminates the field in p->cTerm. Store
1693
+** EOF on end-of-file.
1694
+** + Report syntax errors on stderr
1695
+*/
1696
+static char *csv_read_one_field(CSVReader *p){
1697
+ int c, pc;
1698
+ int cSep = p->cSeparator;
1699
+ p->n = 0;
1700
+ c = fgetc(p->in);
1701
+ if( c==EOF || seenInterrupt ){
1702
+ p->cTerm = EOF;
1703
+ return 0;
1704
+ }
1705
+ if( c=='"' ){
1706
+ int startLine = p->nLine;
1707
+ int cQuote = c;
1708
+ pc = 0;
1709
+ while( 1 ){
1710
+ c = fgetc(p->in);
1711
+ if( c=='\n' ) p->nLine++;
1712
+ if( c==cQuote ){
1713
+ if( pc==cQuote ){
1714
+ pc = 0;
1715
+ continue;
1716
+ }
1717
+ }
1718
+ if( (c==cSep && pc==cQuote)
1719
+ || (c=='\n' && pc==cQuote)
1720
+ || (c=='\n' && pc=='\r' && p->n>2 && p->z[p->n-2]==cQuote)
1721
+ || (c==EOF && pc==cQuote)
1722
+ ){
1723
+ do{ p->n--; }while( p->z[p->n]!=cQuote );
1724
+ p->z[p->n] = 0;
1725
+ p->cTerm = c;
1726
+ break;
1727
+ }
1728
+ if( pc==cQuote && c!='\r' ){
1729
+ fprintf(stderr, "%s:%d: unescaped %c character\n",
1730
+ p->zFile, p->nLine, cQuote);
1731
+ }
1732
+ if( c==EOF ){
1733
+ fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
1734
+ p->zFile, startLine, cQuote);
1735
+ p->z[p->n] = 0;
1736
+ p->cTerm = EOF;
1737
+ break;
1738
+ }
1739
+ csv_append_char(p, c);
1740
+ pc = c;
1741
+ }
1742
+ }else{
1743
+ while( c!=EOF && c!=cSep && c!='\n' ){
1744
+ csv_append_char(p, c);
1745
+ c = fgetc(p->in);
1746
+ }
1747
+ if( c=='\n' ){
1748
+ p->nLine++;
1749
+ if( p->n>1 && p->z[p->n-1]=='\r' ) p->n--;
1750
+ }
1751
+ p->z[p->n] = 0;
1752
+ p->cTerm = c;
1753
+ }
1754
+ return p->z;
1755
+}
16501756
16511757
/*
16521758
** If an input line begins with "." then invoke this routine to
16531759
** process that line.
16541760
**
@@ -1667,11 +1773,14 @@
16671773
while( IsSpace(zLine[i]) ){ i++; }
16681774
if( zLine[i]==0 ) break;
16691775
if( zLine[i]=='\'' || zLine[i]=='"' ){
16701776
int delim = zLine[i++];
16711777
azArg[nArg++] = &zLine[i];
1672
- while( zLine[i] && zLine[i]!=delim ){ i++; }
1778
+ while( zLine[i] && zLine[i]!=delim ){
1779
+ if( zLine[i]=='\\' && delim=='"' && zLine[i+1]!=0 ) i++;
1780
+ i++;
1781
+ }
16731782
if( zLine[i]==delim ){
16741783
zLine[i++] = 0;
16751784
}
16761785
if( delim=='"' ) resolve_backslashes(azArg[nArg-1]);
16771786
}else{
@@ -1884,133 +1993,153 @@
18841993
}
18851994
}else
18861995
18871996
if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg==3 ){
18881997
char *zTable = azArg[2]; /* Insert data into this table */
1889
- char *zFile = azArg[1]; /* The file from which to extract data */
1998
+ char *zFile = azArg[1]; /* Name of file to extra content from */
18901999
sqlite3_stmt *pStmt = NULL; /* A statement */
18912000
int nCol; /* Number of columns in the table */
18922001
int nByte; /* Number of bytes in an SQL string */
18932002
int i, j; /* Loop counters */
18942003
int nSep; /* Number of bytes in p->separator[] */
18952004
char *zSql; /* An SQL statement */
1896
- char *zLine; /* A single line of input from the file */
1897
- char **azCol; /* zLine[] broken up into columns */
1898
- char *zCommit; /* How to commit changes */
1899
- FILE *in; /* The input file */
1900
- int lineno = 0; /* Line number of input file */
2005
+ CSVReader sCsv; /* Reader context */
2006
+ int (*xCloser)(FILE*); /* Procedure to close th3 connection */
19012007
2008
+ seenInterrupt = 0;
2009
+ memset(&sCsv, 0, sizeof(sCsv));
19022010
open_db(p);
19032011
nSep = strlen30(p->separator);
19042012
if( nSep==0 ){
19052013
fprintf(stderr, "Error: non-null separator required for import\n");
19062014
return 1;
19072015
}
2016
+ if( nSep>1 ){
2017
+ fprintf(stderr, "Error: multi-character separators not allowed"
2018
+ " for import\n");
2019
+ return 1;
2020
+ }
2021
+ sCsv.zFile = zFile;
2022
+ sCsv.nLine = 1;
2023
+ if( sCsv.zFile[0]=='|' ){
2024
+ sCsv.in = popen(sCsv.zFile+1, "r");
2025
+ sCsv.zFile = "<pipe>";
2026
+ xCloser = pclose;
2027
+ }else{
2028
+ sCsv.in = fopen(sCsv.zFile, "rb");
2029
+ xCloser = fclose;
2030
+ }
2031
+ if( sCsv.in==0 ){
2032
+ fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
2033
+ return 1;
2034
+ }
2035
+ sCsv.cSeparator = p->separator[0];
19082036
zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
19092037
if( zSql==0 ){
19102038
fprintf(stderr, "Error: out of memory\n");
2039
+ xCloser(sCsv.in);
19112040
return 1;
19122041
}
19132042
nByte = strlen30(zSql);
19142043
rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
2044
+ if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
2045
+ char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
2046
+ char cSep = '(';
2047
+ while( csv_read_one_field(&sCsv) ){
2048
+ zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCsv.z);
2049
+ cSep = ',';
2050
+ if( sCsv.cTerm!=sCsv.cSeparator ) break;
2051
+ }
2052
+ if( cSep=='(' ){
2053
+ sqlite3_free(zCreate);
2054
+ sqlite3_free(sCsv.z);
2055
+ xCloser(sCsv.in);
2056
+ fprintf(stderr,"%s: empty file\n", sCsv.zFile);
2057
+ return 1;
2058
+ }
2059
+ zCreate = sqlite3_mprintf("%z\n)", zCreate);
2060
+ rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
2061
+ sqlite3_free(zCreate);
2062
+ if( rc ){
2063
+ fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
2064
+ sqlite3_errmsg(db));
2065
+ sqlite3_free(sCsv.z);
2066
+ xCloser(sCsv.in);
2067
+ return 1;
2068
+ }
2069
+ rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
2070
+ }
19152071
sqlite3_free(zSql);
19162072
if( rc ){
19172073
if (pStmt) sqlite3_finalize(pStmt);
19182074
fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
2075
+ xCloser(sCsv.in);
19192076
return 1;
19202077
}
19212078
nCol = sqlite3_column_count(pStmt);
19222079
sqlite3_finalize(pStmt);
19232080
pStmt = 0;
19242081
if( nCol==0 ) return 0; /* no columns, no error */
1925
- zSql = malloc( nByte + 20 + nCol*2 );
2082
+ zSql = sqlite3_malloc( nByte*2 + 20 + nCol*2 );
19262083
if( zSql==0 ){
19272084
fprintf(stderr, "Error: out of memory\n");
2085
+ xCloser(sCsv.in);
19282086
return 1;
19292087
}
1930
- sqlite3_snprintf(nByte+20, zSql, "INSERT INTO %s VALUES(?", zTable);
2088
+ sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
19312089
j = strlen30(zSql);
19322090
for(i=1; i<nCol; i++){
19332091
zSql[j++] = ',';
19342092
zSql[j++] = '?';
19352093
}
19362094
zSql[j++] = ')';
19372095
zSql[j] = 0;
19382096
rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
1939
- free(zSql);
2097
+ sqlite3_free(zSql);
19402098
if( rc ){
19412099
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
19422100
if (pStmt) sqlite3_finalize(pStmt);
1943
- return 1;
1944
- }
1945
- in = fopen(zFile, "rb");
1946
- if( in==0 ){
1947
- fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
1948
- sqlite3_finalize(pStmt);
1949
- return 1;
1950
- }
1951
- azCol = malloc( sizeof(azCol[0])*(nCol+1) );
1952
- if( azCol==0 ){
1953
- fprintf(stderr, "Error: out of memory\n");
1954
- fclose(in);
1955
- sqlite3_finalize(pStmt);
1956
- return 1;
1957
- }
1958
- sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
1959
- zCommit = "COMMIT";
1960
- while( (zLine = local_getline(0, in, 1))!=0 ){
1961
- char *z, c;
1962
- int inQuote = 0;
1963
- lineno++;
1964
- azCol[0] = zLine;
1965
- for(i=0, z=zLine; (c = *z)!=0; z++){
1966
- if( c=='"' ) inQuote = !inQuote;
1967
- if( c=='\n' ) lineno++;
1968
- if( !inQuote && c==p->separator[0] && strncmp(z,p->separator,nSep)==0 ){
1969
- *z = 0;
1970
- i++;
1971
- if( i<nCol ){
1972
- azCol[i] = &z[nSep];
1973
- z += nSep-1;
1974
- }
1975
- }
1976
- } /* end for */
1977
- *z = 0;
1978
- if( i+1!=nCol ){
1979
- fprintf(stderr,
1980
- "Error: %s line %d: expected %d columns of data but found %d\n",
1981
- zFile, lineno, nCol, i+1);
1982
- zCommit = "ROLLBACK";
1983
- free(zLine);
1984
- rc = 1;
1985
- break; /* from while */
1986
- }
1987
- for(i=0; i<nCol; i++){
1988
- if( azCol[i][0]=='"' ){
1989
- int k;
1990
- for(z=azCol[i], j=1, k=0; z[j]; j++){
1991
- if( z[j]=='"' ){ j++; if( z[j]==0 ) break; }
1992
- z[k++] = z[j];
1993
- }
1994
- z[k] = 0;
1995
- }
1996
- sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC);
1997
- }
1998
- sqlite3_step(pStmt);
1999
- rc = sqlite3_reset(pStmt);
2000
- free(zLine);
2001
- if( rc!=SQLITE_OK ){
2002
- fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
2003
- zCommit = "ROLLBACK";
2004
- rc = 1;
2005
- break; /* from while */
2006
- }
2007
- } /* end while */
2008
- free(azCol);
2009
- fclose(in);
2010
- sqlite3_finalize(pStmt);
2011
- sqlite3_exec(p->db, zCommit, 0, 0, 0);
2101
+ xCloser(sCsv.in);
2102
+ return 1;
2103
+ }
2104
+ do{
2105
+ int startLine = sCsv.nLine;
2106
+ for(i=0; i<nCol; i++){
2107
+ char *z = csv_read_one_field(&sCsv);
2108
+ if( z==0 && i==0 ) break;
2109
+ sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
2110
+ if( i<nCol-1 && sCsv.cTerm!=sCsv.cSeparator ){
2111
+ fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2112
+ "filling the rest with NULL\n",
2113
+ sCsv.zFile, startLine, nCol, i+1);
2114
+ i++;
2115
+ while( i<nCol ){ sqlite3_bind_null(pStmt, i); i++; }
2116
+ }
2117
+ }
2118
+ if( sCsv.cTerm==sCsv.cSeparator ){
2119
+ do{
2120
+ csv_read_one_field(&sCsv);
2121
+ i++;
2122
+ }while( sCsv.cTerm==sCsv.cSeparator );
2123
+ fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2124
+ "extras ignored\n",
2125
+ sCsv.zFile, startLine, nCol, i);
2126
+ }
2127
+ if( i>=nCol ){
2128
+ sqlite3_step(pStmt);
2129
+ rc = sqlite3_reset(pStmt);
2130
+ if( rc!=SQLITE_OK ){
2131
+ fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCsv.zFile, startLine,
2132
+ sqlite3_errmsg(db));
2133
+ }
2134
+ }
2135
+ }while( sCsv.cTerm!=EOF );
2136
+
2137
+ xCloser(sCsv.in);
2138
+ sqlite3_free(sCsv.z);
2139
+ sqlite3_finalize(pStmt);
2140
+ sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
20122141
}else
20132142
20142143
if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
20152144
struct callback_data data;
20162145
char *zErrMsg = 0;
@@ -2328,10 +2457,11 @@
23282457
}else{
23292458
rc = 0;
23302459
}
23312460
}else
23322461
2462
+#ifdef SQLITE_DEBUG
23332463
/* Undocumented commands for internal testing. Subject to change
23342464
** without notice. */
23352465
if( c=='s' && n>=10 && strncmp(azArg[0], "selftest-", 9)==0 ){
23362466
if( strncmp(azArg[0]+9, "boolean", n-9)==0 ){
23372467
int i, v;
@@ -2341,15 +2471,18 @@
23412471
}
23422472
}
23432473
if( strncmp(azArg[0]+9, "integer", n-9)==0 ){
23442474
int i; sqlite3_int64 v;
23452475
for(i=1; i<nArg; i++){
2476
+ char zBuf[200];
23462477
v = integerValue(azArg[i]);
2347
- fprintf(p->out, "%s: %lld 0x%llx\n", azArg[i], v, v);
2478
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%s: %lld 0x%llx\n", azArg[i], v, v);
2479
+ fprintf(p->out, "%s", zBuf);
23482480
}
23492481
}
23502482
}else
2483
+#endif
23512484
23522485
if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){
23532486
sqlite3_snprintf(sizeof(p->separator), p->separator,
23542487
"%.*s", (int)sizeof(p->separator)-1, azArg[1]);
23552488
}else
23562489
--- src/shell.c
+++ src/shell.c
@@ -65,11 +65,11 @@
65 #define isatty(h) _isatty(h)
66 #define access(f,m) _access((f),(m))
67 #undef popen
68 #define popen(a,b) _popen((a),(b))
69 #undef pclose
70 #define pclose(x) _pclose(x)
71 #else
72 /* Make sure isatty() has a prototype.
73 */
74 extern int isatty(int);
75 #endif
@@ -1107,10 +1107,12 @@
1107 fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
1108 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
1109 fprintf(pArg->out, "Sort Operations: %d\n", iCur);
1110 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, bReset);
1111 fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
 
 
1112 }
1113
1114 return 0;
1115 }
1116
@@ -1488,10 +1490,11 @@
1488 ** Do C-language style dequoting.
1489 **
1490 ** \t -> tab
1491 ** \n -> newline
1492 ** \r -> carriage return
 
1493 ** \NNN -> ascii character NNN in octal
1494 ** \\ -> backslash
1495 */
1496 static void resolve_backslashes(char *z){
1497 int i, j;
@@ -1503,10 +1506,12 @@
1503 c = '\n';
1504 }else if( c=='t' ){
1505 c = '\t';
1506 }else if( c=='r' ){
1507 c = '\r';
 
 
1508 }else if( c>='0' && c<='7' ){
1509 c -= '0';
1510 if( z[i+1]>='0' && z[i+1]<='7' ){
1511 i++;
1512 c = (c<<3) + z[i] - '0';
@@ -1645,10 +1650,111 @@
1645 */
1646 static void test_breakpoint(void){
1647 static int nCall = 0;
1648 nCall++;
1649 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1650
1651 /*
1652 ** If an input line begins with "." then invoke this routine to
1653 ** process that line.
1654 **
@@ -1667,11 +1773,14 @@
1667 while( IsSpace(zLine[i]) ){ i++; }
1668 if( zLine[i]==0 ) break;
1669 if( zLine[i]=='\'' || zLine[i]=='"' ){
1670 int delim = zLine[i++];
1671 azArg[nArg++] = &zLine[i];
1672 while( zLine[i] && zLine[i]!=delim ){ i++; }
 
 
 
1673 if( zLine[i]==delim ){
1674 zLine[i++] = 0;
1675 }
1676 if( delim=='"' ) resolve_backslashes(azArg[nArg-1]);
1677 }else{
@@ -1884,133 +1993,153 @@
1884 }
1885 }else
1886
1887 if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg==3 ){
1888 char *zTable = azArg[2]; /* Insert data into this table */
1889 char *zFile = azArg[1]; /* The file from which to extract data */
1890 sqlite3_stmt *pStmt = NULL; /* A statement */
1891 int nCol; /* Number of columns in the table */
1892 int nByte; /* Number of bytes in an SQL string */
1893 int i, j; /* Loop counters */
1894 int nSep; /* Number of bytes in p->separator[] */
1895 char *zSql; /* An SQL statement */
1896 char *zLine; /* A single line of input from the file */
1897 char **azCol; /* zLine[] broken up into columns */
1898 char *zCommit; /* How to commit changes */
1899 FILE *in; /* The input file */
1900 int lineno = 0; /* Line number of input file */
1901
 
 
1902 open_db(p);
1903 nSep = strlen30(p->separator);
1904 if( nSep==0 ){
1905 fprintf(stderr, "Error: non-null separator required for import\n");
1906 return 1;
1907 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1908 zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
1909 if( zSql==0 ){
1910 fprintf(stderr, "Error: out of memory\n");
 
1911 return 1;
1912 }
1913 nByte = strlen30(zSql);
1914 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1915 sqlite3_free(zSql);
1916 if( rc ){
1917 if (pStmt) sqlite3_finalize(pStmt);
1918 fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
 
1919 return 1;
1920 }
1921 nCol = sqlite3_column_count(pStmt);
1922 sqlite3_finalize(pStmt);
1923 pStmt = 0;
1924 if( nCol==0 ) return 0; /* no columns, no error */
1925 zSql = malloc( nByte + 20 + nCol*2 );
1926 if( zSql==0 ){
1927 fprintf(stderr, "Error: out of memory\n");
 
1928 return 1;
1929 }
1930 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO %s VALUES(?", zTable);
1931 j = strlen30(zSql);
1932 for(i=1; i<nCol; i++){
1933 zSql[j++] = ',';
1934 zSql[j++] = '?';
1935 }
1936 zSql[j++] = ')';
1937 zSql[j] = 0;
1938 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
1939 free(zSql);
1940 if( rc ){
1941 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
1942 if (pStmt) sqlite3_finalize(pStmt);
1943 return 1;
1944 }
1945 in = fopen(zFile, "rb");
1946 if( in==0 ){
1947 fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
1948 sqlite3_finalize(pStmt);
1949 return 1;
1950 }
1951 azCol = malloc( sizeof(azCol[0])*(nCol+1) );
1952 if( azCol==0 ){
1953 fprintf(stderr, "Error: out of memory\n");
1954 fclose(in);
1955 sqlite3_finalize(pStmt);
1956 return 1;
1957 }
1958 sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
1959 zCommit = "COMMIT";
1960 while( (zLine = local_getline(0, in, 1))!=0 ){
1961 char *z, c;
1962 int inQuote = 0;
1963 lineno++;
1964 azCol[0] = zLine;
1965 for(i=0, z=zLine; (c = *z)!=0; z++){
1966 if( c=='"' ) inQuote = !inQuote;
1967 if( c=='\n' ) lineno++;
1968 if( !inQuote && c==p->separator[0] && strncmp(z,p->separator,nSep)==0 ){
1969 *z = 0;
1970 i++;
1971 if( i<nCol ){
1972 azCol[i] = &z[nSep];
1973 z += nSep-1;
1974 }
1975 }
1976 } /* end for */
1977 *z = 0;
1978 if( i+1!=nCol ){
1979 fprintf(stderr,
1980 "Error: %s line %d: expected %d columns of data but found %d\n",
1981 zFile, lineno, nCol, i+1);
1982 zCommit = "ROLLBACK";
1983 free(zLine);
1984 rc = 1;
1985 break; /* from while */
1986 }
1987 for(i=0; i<nCol; i++){
1988 if( azCol[i][0]=='"' ){
1989 int k;
1990 for(z=azCol[i], j=1, k=0; z[j]; j++){
1991 if( z[j]=='"' ){ j++; if( z[j]==0 ) break; }
1992 z[k++] = z[j];
1993 }
1994 z[k] = 0;
1995 }
1996 sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC);
1997 }
1998 sqlite3_step(pStmt);
1999 rc = sqlite3_reset(pStmt);
2000 free(zLine);
2001 if( rc!=SQLITE_OK ){
2002 fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
2003 zCommit = "ROLLBACK";
2004 rc = 1;
2005 break; /* from while */
2006 }
2007 } /* end while */
2008 free(azCol);
2009 fclose(in);
2010 sqlite3_finalize(pStmt);
2011 sqlite3_exec(p->db, zCommit, 0, 0, 0);
2012 }else
2013
2014 if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
2015 struct callback_data data;
2016 char *zErrMsg = 0;
@@ -2328,10 +2457,11 @@
2328 }else{
2329 rc = 0;
2330 }
2331 }else
2332
 
2333 /* Undocumented commands for internal testing. Subject to change
2334 ** without notice. */
2335 if( c=='s' && n>=10 && strncmp(azArg[0], "selftest-", 9)==0 ){
2336 if( strncmp(azArg[0]+9, "boolean", n-9)==0 ){
2337 int i, v;
@@ -2341,15 +2471,18 @@
2341 }
2342 }
2343 if( strncmp(azArg[0]+9, "integer", n-9)==0 ){
2344 int i; sqlite3_int64 v;
2345 for(i=1; i<nArg; i++){
 
2346 v = integerValue(azArg[i]);
2347 fprintf(p->out, "%s: %lld 0x%llx\n", azArg[i], v, v);
 
2348 }
2349 }
2350 }else
 
2351
2352 if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){
2353 sqlite3_snprintf(sizeof(p->separator), p->separator,
2354 "%.*s", (int)sizeof(p->separator)-1, azArg[1]);
2355 }else
2356
--- src/shell.c
+++ src/shell.c
@@ -65,11 +65,11 @@
65 #define isatty(h) _isatty(h)
66 #define access(f,m) _access((f),(m))
67 #undef popen
68 #define popen(a,b) _popen((a),(b))
69 #undef pclose
70 #define pclose _pclose
71 #else
72 /* Make sure isatty() has a prototype.
73 */
74 extern int isatty(int);
75 #endif
@@ -1107,10 +1107,12 @@
1107 fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
1108 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
1109 fprintf(pArg->out, "Sort Operations: %d\n", iCur);
1110 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, bReset);
1111 fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
1112 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
1113 fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1114 }
1115
1116 return 0;
1117 }
1118
@@ -1488,10 +1490,11 @@
1490 ** Do C-language style dequoting.
1491 **
1492 ** \t -> tab
1493 ** \n -> newline
1494 ** \r -> carriage return
1495 ** \" -> "
1496 ** \NNN -> ascii character NNN in octal
1497 ** \\ -> backslash
1498 */
1499 static void resolve_backslashes(char *z){
1500 int i, j;
@@ -1503,10 +1506,12 @@
1506 c = '\n';
1507 }else if( c=='t' ){
1508 c = '\t';
1509 }else if( c=='r' ){
1510 c = '\r';
1511 }else if( c=='\\' ){
1512 c = '\\';
1513 }else if( c>='0' && c<='7' ){
1514 c -= '0';
1515 if( z[i+1]>='0' && z[i+1]<='7' ){
1516 i++;
1517 c = (c<<3) + z[i] - '0';
@@ -1645,10 +1650,111 @@
1650 */
1651 static void test_breakpoint(void){
1652 static int nCall = 0;
1653 nCall++;
1654 }
1655
1656 /*
1657 ** An object used to read a CSV file
1658 */
1659 typedef struct CSVReader CSVReader;
1660 struct CSVReader {
1661 const char *zFile; /* Name of the input file */
1662 FILE *in; /* Read the CSV text from this input stream */
1663 char *z; /* Accumulated text for a field */
1664 int n; /* Number of bytes in z */
1665 int nAlloc; /* Space allocated for z[] */
1666 int nLine; /* Current line number */
1667 int cTerm; /* Character that terminated the most recent field */
1668 int cSeparator; /* The separator character. (Usually ",") */
1669 };
1670
1671 /* Append a single byte to z[] */
1672 static void csv_append_char(CSVReader *p, int c){
1673 if( p->n+1>=p->nAlloc ){
1674 p->nAlloc += p->nAlloc + 100;
1675 p->z = sqlite3_realloc(p->z, p->nAlloc);
1676 if( p->z==0 ){
1677 fprintf(stderr, "out of memory\n");
1678 exit(1);
1679 }
1680 }
1681 p->z[p->n++] = (char)c;
1682 }
1683
1684 /* Read a single field of CSV text. Compatible with rfc4180 and extended
1685 ** with the option of having a separator other than ",".
1686 **
1687 ** + Input comes from p->in.
1688 ** + Store results in p->z of length p->n. Space to hold p->z comes
1689 ** from sqlite3_malloc().
1690 ** + Use p->cSep as the separator. The default is ",".
1691 ** + Keep track of the line number in p->nLine.
1692 ** + Store the character that terminates the field in p->cTerm. Store
1693 ** EOF on end-of-file.
1694 ** + Report syntax errors on stderr
1695 */
1696 static char *csv_read_one_field(CSVReader *p){
1697 int c, pc;
1698 int cSep = p->cSeparator;
1699 p->n = 0;
1700 c = fgetc(p->in);
1701 if( c==EOF || seenInterrupt ){
1702 p->cTerm = EOF;
1703 return 0;
1704 }
1705 if( c=='"' ){
1706 int startLine = p->nLine;
1707 int cQuote = c;
1708 pc = 0;
1709 while( 1 ){
1710 c = fgetc(p->in);
1711 if( c=='\n' ) p->nLine++;
1712 if( c==cQuote ){
1713 if( pc==cQuote ){
1714 pc = 0;
1715 continue;
1716 }
1717 }
1718 if( (c==cSep && pc==cQuote)
1719 || (c=='\n' && pc==cQuote)
1720 || (c=='\n' && pc=='\r' && p->n>2 && p->z[p->n-2]==cQuote)
1721 || (c==EOF && pc==cQuote)
1722 ){
1723 do{ p->n--; }while( p->z[p->n]!=cQuote );
1724 p->z[p->n] = 0;
1725 p->cTerm = c;
1726 break;
1727 }
1728 if( pc==cQuote && c!='\r' ){
1729 fprintf(stderr, "%s:%d: unescaped %c character\n",
1730 p->zFile, p->nLine, cQuote);
1731 }
1732 if( c==EOF ){
1733 fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
1734 p->zFile, startLine, cQuote);
1735 p->z[p->n] = 0;
1736 p->cTerm = EOF;
1737 break;
1738 }
1739 csv_append_char(p, c);
1740 pc = c;
1741 }
1742 }else{
1743 while( c!=EOF && c!=cSep && c!='\n' ){
1744 csv_append_char(p, c);
1745 c = fgetc(p->in);
1746 }
1747 if( c=='\n' ){
1748 p->nLine++;
1749 if( p->n>1 && p->z[p->n-1]=='\r' ) p->n--;
1750 }
1751 p->z[p->n] = 0;
1752 p->cTerm = c;
1753 }
1754 return p->z;
1755 }
1756
1757 /*
1758 ** If an input line begins with "." then invoke this routine to
1759 ** process that line.
1760 **
@@ -1667,11 +1773,14 @@
1773 while( IsSpace(zLine[i]) ){ i++; }
1774 if( zLine[i]==0 ) break;
1775 if( zLine[i]=='\'' || zLine[i]=='"' ){
1776 int delim = zLine[i++];
1777 azArg[nArg++] = &zLine[i];
1778 while( zLine[i] && zLine[i]!=delim ){
1779 if( zLine[i]=='\\' && delim=='"' && zLine[i+1]!=0 ) i++;
1780 i++;
1781 }
1782 if( zLine[i]==delim ){
1783 zLine[i++] = 0;
1784 }
1785 if( delim=='"' ) resolve_backslashes(azArg[nArg-1]);
1786 }else{
@@ -1884,133 +1993,153 @@
1993 }
1994 }else
1995
1996 if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg==3 ){
1997 char *zTable = azArg[2]; /* Insert data into this table */
1998 char *zFile = azArg[1]; /* Name of file to extra content from */
1999 sqlite3_stmt *pStmt = NULL; /* A statement */
2000 int nCol; /* Number of columns in the table */
2001 int nByte; /* Number of bytes in an SQL string */
2002 int i, j; /* Loop counters */
2003 int nSep; /* Number of bytes in p->separator[] */
2004 char *zSql; /* An SQL statement */
2005 CSVReader sCsv; /* Reader context */
2006 int (*xCloser)(FILE*); /* Procedure to close th3 connection */
 
 
 
2007
2008 seenInterrupt = 0;
2009 memset(&sCsv, 0, sizeof(sCsv));
2010 open_db(p);
2011 nSep = strlen30(p->separator);
2012 if( nSep==0 ){
2013 fprintf(stderr, "Error: non-null separator required for import\n");
2014 return 1;
2015 }
2016 if( nSep>1 ){
2017 fprintf(stderr, "Error: multi-character separators not allowed"
2018 " for import\n");
2019 return 1;
2020 }
2021 sCsv.zFile = zFile;
2022 sCsv.nLine = 1;
2023 if( sCsv.zFile[0]=='|' ){
2024 sCsv.in = popen(sCsv.zFile+1, "r");
2025 sCsv.zFile = "<pipe>";
2026 xCloser = pclose;
2027 }else{
2028 sCsv.in = fopen(sCsv.zFile, "rb");
2029 xCloser = fclose;
2030 }
2031 if( sCsv.in==0 ){
2032 fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
2033 return 1;
2034 }
2035 sCsv.cSeparator = p->separator[0];
2036 zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
2037 if( zSql==0 ){
2038 fprintf(stderr, "Error: out of memory\n");
2039 xCloser(sCsv.in);
2040 return 1;
2041 }
2042 nByte = strlen30(zSql);
2043 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
2044 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
2045 char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
2046 char cSep = '(';
2047 while( csv_read_one_field(&sCsv) ){
2048 zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCsv.z);
2049 cSep = ',';
2050 if( sCsv.cTerm!=sCsv.cSeparator ) break;
2051 }
2052 if( cSep=='(' ){
2053 sqlite3_free(zCreate);
2054 sqlite3_free(sCsv.z);
2055 xCloser(sCsv.in);
2056 fprintf(stderr,"%s: empty file\n", sCsv.zFile);
2057 return 1;
2058 }
2059 zCreate = sqlite3_mprintf("%z\n)", zCreate);
2060 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
2061 sqlite3_free(zCreate);
2062 if( rc ){
2063 fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
2064 sqlite3_errmsg(db));
2065 sqlite3_free(sCsv.z);
2066 xCloser(sCsv.in);
2067 return 1;
2068 }
2069 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
2070 }
2071 sqlite3_free(zSql);
2072 if( rc ){
2073 if (pStmt) sqlite3_finalize(pStmt);
2074 fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
2075 xCloser(sCsv.in);
2076 return 1;
2077 }
2078 nCol = sqlite3_column_count(pStmt);
2079 sqlite3_finalize(pStmt);
2080 pStmt = 0;
2081 if( nCol==0 ) return 0; /* no columns, no error */
2082 zSql = sqlite3_malloc( nByte*2 + 20 + nCol*2 );
2083 if( zSql==0 ){
2084 fprintf(stderr, "Error: out of memory\n");
2085 xCloser(sCsv.in);
2086 return 1;
2087 }
2088 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
2089 j = strlen30(zSql);
2090 for(i=1; i<nCol; i++){
2091 zSql[j++] = ',';
2092 zSql[j++] = '?';
2093 }
2094 zSql[j++] = ')';
2095 zSql[j] = 0;
2096 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
2097 sqlite3_free(zSql);
2098 if( rc ){
2099 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
2100 if (pStmt) sqlite3_finalize(pStmt);
2101 xCloser(sCsv.in);
2102 return 1;
2103 }
2104 do{
2105 int startLine = sCsv.nLine;
2106 for(i=0; i<nCol; i++){
2107 char *z = csv_read_one_field(&sCsv);
2108 if( z==0 && i==0 ) break;
2109 sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
2110 if( i<nCol-1 && sCsv.cTerm!=sCsv.cSeparator ){
2111 fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2112 "filling the rest with NULL\n",
2113 sCsv.zFile, startLine, nCol, i+1);
2114 i++;
2115 while( i<nCol ){ sqlite3_bind_null(pStmt, i); i++; }
2116 }
2117 }
2118 if( sCsv.cTerm==sCsv.cSeparator ){
2119 do{
2120 csv_read_one_field(&sCsv);
2121 i++;
2122 }while( sCsv.cTerm==sCsv.cSeparator );
2123 fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2124 "extras ignored\n",
2125 sCsv.zFile, startLine, nCol, i);
2126 }
2127 if( i>=nCol ){
2128 sqlite3_step(pStmt);
2129 rc = sqlite3_reset(pStmt);
2130 if( rc!=SQLITE_OK ){
2131 fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCsv.zFile, startLine,
2132 sqlite3_errmsg(db));
2133 }
2134 }
2135 }while( sCsv.cTerm!=EOF );
2136
2137 xCloser(sCsv.in);
2138 sqlite3_free(sCsv.z);
2139 sqlite3_finalize(pStmt);
2140 sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2141 }else
2142
2143 if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
2144 struct callback_data data;
2145 char *zErrMsg = 0;
@@ -2328,10 +2457,11 @@
2457 }else{
2458 rc = 0;
2459 }
2460 }else
2461
2462 #ifdef SQLITE_DEBUG
2463 /* Undocumented commands for internal testing. Subject to change
2464 ** without notice. */
2465 if( c=='s' && n>=10 && strncmp(azArg[0], "selftest-", 9)==0 ){
2466 if( strncmp(azArg[0]+9, "boolean", n-9)==0 ){
2467 int i, v;
@@ -2341,15 +2471,18 @@
2471 }
2472 }
2473 if( strncmp(azArg[0]+9, "integer", n-9)==0 ){
2474 int i; sqlite3_int64 v;
2475 for(i=1; i<nArg; i++){
2476 char zBuf[200];
2477 v = integerValue(azArg[i]);
2478 sqlite3_snprintf(sizeof(zBuf), zBuf, "%s: %lld 0x%llx\n", azArg[i], v, v);
2479 fprintf(p->out, "%s", zBuf);
2480 }
2481 }
2482 }else
2483 #endif
2484
2485 if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){
2486 sqlite3_snprintf(sizeof(p->separator), p->separator,
2487 "%.*s", (int)sizeof(p->separator)-1, azArg[1]);
2488 }else
2489
+359 -175
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.7.17. By combining all the individual C code files into this
3
+** version 3.8.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -668,13 +668,13 @@
668668
**
669669
** See also: [sqlite3_libversion()],
670670
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671671
** [sqlite_version()] and [sqlite_source_id()].
672672
*/
673
-#define SQLITE_VERSION "3.7.17"
674
-#define SQLITE_VERSION_NUMBER 3007017
675
-#define SQLITE_SOURCE_ID "2013-06-20 14:17:39 d94db3fd921890ab1d6414ab629410ae50779686"
673
+#define SQLITE_VERSION "3.8.0"
674
+#define SQLITE_VERSION_NUMBER 3008000
675
+#define SQLITE_SOURCE_ID "2013-07-09 03:04:32 52a49cbc1621094b2fe2b021209b768d29e0426b"
676676
677677
/*
678678
** CAPI3REF: Run-Time Library Version Numbers
679679
** KEYWORDS: sqlite3_version, sqlite3_sourceid
680680
**
@@ -1041,10 +1041,11 @@
10411041
#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
10421042
#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
10431043
#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
10441044
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
10451045
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
1046
+#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
10461047
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
10471048
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
10481049
#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
10491050
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
10501051
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
@@ -1060,10 +1061,11 @@
10601061
#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
10611062
#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
10621063
#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
10631064
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
10641065
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
1066
+#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
10651067
10661068
/*
10671069
** CAPI3REF: Flags For File Open Operations
10681070
**
10691071
** These bit values are intended for use in the
@@ -6869,15 +6871,25 @@
68696871
** <dd>^This is the number of rows inserted into transient indices that
68706872
** were created automatically in order to help joins run faster.
68716873
** A non-zero value in this counter may indicate an opportunity to
68726874
** improvement performance by adding permanent indices that do not
68736875
** need to be reinitialized each time the statement is run.</dd>
6876
+**
6877
+** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
6878
+** <dd>^This is the number of virtual machine operations executed
6879
+** by the prepared statement if that number is less than or equal
6880
+** to 2147483647. The number of virtual machine operations can be
6881
+** used as a proxy for the total work done by the prepared statement.
6882
+** If the number of virtual machine operations exceeds 2147483647
6883
+** then the value returned by this statement status code is undefined.
6884
+** </dd>
68746885
** </dl>
68756886
*/
68766887
#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
68776888
#define SQLITE_STMTSTATUS_SORT 2
68786889
#define SQLITE_STMTSTATUS_AUTOINDEX 3
6890
+#define SQLITE_STMTSTATUS_VM_STEP 4
68796891
68806892
/*
68816893
** CAPI3REF: Custom Page Cache Object
68826894
**
68836895
** The sqlite3_pcache type is opaque. It is implemented by
@@ -10066,13 +10078,14 @@
1006610078
int newTnum; /* Rootpage of table being initialized */
1006710079
u8 iDb; /* Which db file is being initialized */
1006810080
u8 busy; /* TRUE if currently initializing */
1006910081
u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */
1007010082
} init;
10071
- int activeVdbeCnt; /* Number of VDBEs currently executing */
10072
- int writeVdbeCnt; /* Number of active VDBEs that are writing */
10073
- int vdbeExecCnt; /* Number of nested calls to VdbeExec() */
10083
+ int nVdbeActive; /* Number of VDBEs currently running */
10084
+ int nVdbeRead; /* Number of active VDBEs that read or write */
10085
+ int nVdbeWrite; /* Number of active VDBEs that read and write */
10086
+ int nVdbeExec; /* Number of nested calls to VdbeExec() */
1007410087
int nExtension; /* Number of loaded extensions */
1007510088
void **aExtension; /* Array of shared library handles */
1007610089
void (*xTrace)(void*,const char*); /* Trace function */
1007710090
void *pTraceArg; /* Argument to the trace function */
1007810091
void (*xProfile)(void*,const char*,u64); /* Profiling function */
@@ -10193,10 +10206,12 @@
1019310206
#define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
1019410207
#define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
1019510208
#define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
1019610209
#define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
1019710210
#define SQLITE_Transitive 0x0200 /* Transitive constraints */
10211
+#define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
10212
+#define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */
1019810213
#define SQLITE_AllOpts 0xffff /* All optimizations */
1019910214
1020010215
/*
1020110216
** Macros for testing whether or not optimizations are enabled or disabled.
1020210217
*/
@@ -11143,10 +11158,11 @@
1114311158
#define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
1114411159
#define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
1114511160
#define WHERE_AND_ONLY 0x0080 /* Don't use indices for OR terms */
1114611161
#define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
1114711162
#define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
11163
+#define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
1114811164
1114911165
/* Allowed return values from sqlite3WhereIsDistinct()
1115011166
*/
1115111167
#define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
1115211168
#define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */
@@ -13500,18 +13516,19 @@
1350013516
bft inVtabMethod:2; /* See comments above */
1350113517
bft changeCntOn:1; /* True to update the change-counter */
1350213518
bft expired:1; /* True if the VM needs to be recompiled */
1350313519
bft runOnlyOnce:1; /* Automatically expire on reset */
1350413520
bft usesStmtJournal:1; /* True if uses a statement journal */
13505
- bft readOnly:1; /* True for read-only statements */
13521
+ bft readOnly:1; /* True for statements that do not write */
13522
+ bft bIsReader:1; /* True for statements that read */
1350613523
bft isPrepareV2:1; /* True if prepared with prepare_v2() */
1350713524
bft doingRerun:1; /* True if rerunning after an auto-reprepare */
1350813525
int nChange; /* Number of db changes made since last reset */
1350913526
yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
1351013527
yDbMask lockMask; /* Subset of btreeMask that requires a lock */
1351113528
int iStatement; /* Statement number (or 0 if has not opened stmt) */
13512
- int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
13529
+ int aCounter[4]; /* Counters used by sqlite3_stmt_status() */
1351313530
#ifndef SQLITE_OMIT_TRACE
1351413531
i64 startTime; /* Time when query started - used for profiling */
1351513532
#endif
1351613533
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
1351713534
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
@@ -19937,12 +19954,12 @@
1993719954
if( xtype==etEXP ){
1993819955
e2 = 0;
1993919956
}else{
1994019957
e2 = exp;
1994119958
}
19942
- if( e2+precision+width > etBUFSIZE - 15 ){
19943
- bufpt = zExtra = sqlite3Malloc( e2+precision+width+15 );
19959
+ if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){
19960
+ bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 );
1994419961
if( bufpt==0 ){
1994519962
pAccum->mallocFailed = 1;
1994619963
return;
1994719964
}
1994819965
}
@@ -40058,10 +40075,11 @@
4005840075
assert( !MEMDB );
4005940076
pager_reset(pPager);
4006040077
pPager->changeCountDone = pPager->tempFile;
4006140078
pPager->eState = PAGER_OPEN;
4006240079
pPager->errCode = SQLITE_OK;
40080
+ if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
4006340081
}
4006440082
4006540083
pPager->journalOff = 0;
4006640084
pPager->journalHdr = 0;
4006740085
pPager->setMaster = 0;
@@ -41624,14 +41642,14 @@
4162441642
** Invoke SQLITE_FCNTL_MMAP_SIZE based on the current value of szMmap.
4162541643
*/
4162641644
static void pagerFixMaplimit(Pager *pPager){
4162741645
#if SQLITE_MAX_MMAP_SIZE>0
4162841646
sqlite3_file *fd = pPager->fd;
41629
- if( isOpen(fd) ){
41647
+ if( isOpen(fd) && fd->pMethods->iVersion>=3 ){
4163041648
sqlite3_int64 sz;
41631
- pPager->bUseFetch = (fd->pMethods->iVersion>=3) && pPager->szMmap>0;
4163241649
sz = pPager->szMmap;
41650
+ pPager->bUseFetch = (sz>0);
4163341651
sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_SIZE, &sz);
4163441652
}
4163541653
#endif
4163641654
}
4163741655
@@ -47879,11 +47897,11 @@
4787947897
** the write is disallowed.
4788047898
*/
4788147899
if( memcmp(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr))!=0 ){
4788247900
walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1);
4788347901
pWal->writeLock = 0;
47884
- rc = SQLITE_BUSY;
47902
+ rc = SQLITE_BUSY_SNAPSHOT;
4788547903
}
4788647904
4788747905
return rc;
4788847906
}
4788947907
@@ -52739,16 +52757,17 @@
5273952757
** This function is called from both BtreeCommitPhaseTwo() and BtreeRollback()
5274052758
** at the conclusion of a transaction.
5274152759
*/
5274252760
static void btreeEndTransaction(Btree *p){
5274352761
BtShared *pBt = p->pBt;
52762
+ sqlite3 *db = p->db;
5274452763
assert( sqlite3BtreeHoldsMutex(p) );
5274552764
5274652765
#ifndef SQLITE_OMIT_AUTOVACUUM
5274752766
pBt->bDoTruncate = 0;
5274852767
#endif
52749
- if( p->inTrans>TRANS_NONE && p->db->activeVdbeCnt>1 ){
52768
+ if( p->inTrans>TRANS_NONE && db->nVdbeRead>1 ){
5275052769
/* If there are other active statements that belong to this database
5275152770
** handle, downgrade to a read-only transaction. The other statements
5275252771
** may still be reading from the database. */
5275352772
downgradeAllSharedCacheTableLocks(p);
5275452773
p->inTrans = TRANS_READ;
@@ -60265,18 +60284,30 @@
6026560284
int i;
6026660285
int nMaxArgs = *pMaxFuncArgs;
6026760286
Op *pOp;
6026860287
int *aLabel = p->aLabel;
6026960288
p->readOnly = 1;
60289
+ p->bIsReader = 0;
6027060290
for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
6027160291
u8 opcode = pOp->opcode;
6027260292
6027360293
pOp->opflags = sqlite3OpcodeProperty[opcode];
6027460294
if( opcode==OP_Function || opcode==OP_AggStep ){
6027560295
if( pOp->p5>nMaxArgs ) nMaxArgs = pOp->p5;
60276
- }else if( (opcode==OP_Transaction && pOp->p2!=0) || opcode==OP_Vacuum ){
60296
+ }else if( opcode==OP_Transaction ){
60297
+ if( pOp->p2!=0 ) p->readOnly = 0;
60298
+ p->bIsReader = 1;
60299
+ }else if( opcode==OP_AutoCommit || opcode==OP_Savepoint ){
60300
+ p->bIsReader = 1;
60301
+ }else if( opcode==OP_Vacuum
60302
+ || opcode==OP_JournalMode
60303
+#ifndef SQLITE_OMIT_WAL
60304
+ || opcode==OP_Checkpoint
60305
+#endif
60306
+ ){
6027760307
p->readOnly = 0;
60308
+ p->bIsReader = 1;
6027860309
#ifndef SQLITE_OMIT_VIRTUALTABLE
6027960310
}else if( opcode==OP_VUpdate ){
6028060311
if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
6028160312
}else if( opcode==OP_VFilter ){
6028260313
int n;
@@ -60298,12 +60329,12 @@
6029860329
pOp->p2 = aLabel[-1-pOp->p2];
6029960330
}
6030060331
}
6030160332
sqlite3DbFree(p->db, p->aLabel);
6030260333
p->aLabel = 0;
60303
-
6030460334
*pMaxFuncArgs = nMaxArgs;
60335
+ assert( p->bIsReader!=0 || p->btreeMask==0 );
6030560336
}
6030660337
6030760338
/*
6030860339
** Return the address of the next instruction to be inserted.
6030960340
*/
@@ -61825,11 +61856,11 @@
6182561856
6182661857
return rc;
6182761858
}
6182861859
6182961860
/*
61830
-** This routine checks that the sqlite3.activeVdbeCnt count variable
61861
+** This routine checks that the sqlite3.nVdbeActive count variable
6183161862
** matches the number of vdbe's in the list sqlite3.pVdbe that are
6183261863
** currently active. An assertion fails if the two counts do not match.
6183361864
** This is an internal self-check only - it is not an essential processing
6183461865
** step.
6183561866
**
@@ -61838,20 +61869,23 @@
6183861869
#ifndef NDEBUG
6183961870
static void checkActiveVdbeCnt(sqlite3 *db){
6184061871
Vdbe *p;
6184161872
int cnt = 0;
6184261873
int nWrite = 0;
61874
+ int nRead = 0;
6184361875
p = db->pVdbe;
6184461876
while( p ){
6184561877
if( p->magic==VDBE_MAGIC_RUN && p->pc>=0 ){
6184661878
cnt++;
6184761879
if( p->readOnly==0 ) nWrite++;
61880
+ if( p->bIsReader ) nRead++;
6184861881
}
6184961882
p = p->pNext;
6185061883
}
61851
- assert( cnt==db->activeVdbeCnt );
61852
- assert( nWrite==db->writeVdbeCnt );
61884
+ assert( cnt==db->nVdbeActive );
61885
+ assert( nWrite==db->nVdbeWrite );
61886
+ assert( nRead==db->nVdbeRead );
6185361887
}
6185461888
#else
6185561889
#define checkActiveVdbeCnt(x)
6185661890
#endif
6185761891
@@ -61983,12 +62017,13 @@
6198362017
if( p->magic!=VDBE_MAGIC_RUN ){
6198462018
return SQLITE_OK;
6198562019
}
6198662020
checkActiveVdbeCnt(db);
6198762021
61988
- /* No commit or rollback needed if the program never started */
61989
- if( p->pc>=0 ){
62022
+ /* No commit or rollback needed if the program never started or if the
62023
+ ** SQL statement does not read or write a database file. */
62024
+ if( p->pc>=0 && p->bIsReader ){
6199062025
int mrc; /* Primary error code from p->rc */
6199162026
int eStatementOp = 0;
6199262027
int isSpecialError; /* Set to true if a 'special' error */
6199362028
6199462029
/* Lock all btrees used by the statement */
@@ -62037,11 +62072,11 @@
6203762072
** Note: This block also runs if one of the special errors handled
6203862073
** above has occurred.
6203962074
*/
6204062075
if( !sqlite3VtabInSync(db)
6204162076
&& db->autoCommit
62042
- && db->writeVdbeCnt==(p->readOnly==0)
62077
+ && db->nVdbeWrite==(p->readOnly==0)
6204362078
){
6204462079
if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){
6204562080
rc = sqlite3VdbeCheckFk(p, 1);
6204662081
if( rc!=SQLITE_OK ){
6204762082
if( NEVER(p->readOnly) ){
@@ -62118,15 +62153,16 @@
6211862153
sqlite3VdbeLeave(p);
6211962154
}
6212062155
6212162156
/* We have successfully halted and closed the VM. Record this fact. */
6212262157
if( p->pc>=0 ){
62123
- db->activeVdbeCnt--;
62124
- if( !p->readOnly ){
62125
- db->writeVdbeCnt--;
62126
- }
62127
- assert( db->activeVdbeCnt>=db->writeVdbeCnt );
62158
+ db->nVdbeActive--;
62159
+ if( !p->readOnly ) db->nVdbeWrite--;
62160
+ if( p->bIsReader ) db->nVdbeRead--;
62161
+ assert( db->nVdbeActive>=db->nVdbeRead );
62162
+ assert( db->nVdbeRead>=db->nVdbeWrite );
62163
+ assert( db->nVdbeWrite>=0 );
6212862164
}
6212962165
p->magic = VDBE_MAGIC_HALT;
6213062166
checkActiveVdbeCnt(db);
6213162167
if( p->db->mallocFailed ){
6213262168
p->rc = SQLITE_NOMEM;
@@ -62138,11 +62174,11 @@
6213862174
*/
6213962175
if( db->autoCommit ){
6214062176
sqlite3ConnectionUnlocked(db);
6214162177
}
6214262178
62143
- assert( db->activeVdbeCnt>0 || db->autoCommit==0 || db->nStatement==0 );
62179
+ assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 );
6214462180
return (p->rc==SQLITE_BUSY ? SQLITE_BUSY : SQLITE_OK);
6214562181
}
6214662182
6214762183
6214862184
/*
@@ -63496,35 +63532,36 @@
6349663532
if( p->pc<0 ){
6349763533
/* If there are no other statements currently running, then
6349863534
** reset the interrupt flag. This prevents a call to sqlite3_interrupt
6349963535
** from interrupting a statement that has not yet started.
6350063536
*/
63501
- if( db->activeVdbeCnt==0 ){
63537
+ if( db->nVdbeActive==0 ){
6350263538
db->u1.isInterrupted = 0;
6350363539
}
6350463540
63505
- assert( db->writeVdbeCnt>0 || db->autoCommit==0 || db->nDeferredCons==0 );
63541
+ assert( db->nVdbeWrite>0 || db->autoCommit==0 || db->nDeferredCons==0 );
6350663542
6350763543
#ifndef SQLITE_OMIT_TRACE
6350863544
if( db->xProfile && !db->init.busy ){
6350963545
sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
6351063546
}
6351163547
#endif
6351263548
63513
- db->activeVdbeCnt++;
63514
- if( p->readOnly==0 ) db->writeVdbeCnt++;
63549
+ db->nVdbeActive++;
63550
+ if( p->readOnly==0 ) db->nVdbeWrite++;
63551
+ if( p->bIsReader ) db->nVdbeRead++;
6351563552
p->pc = 0;
6351663553
}
6351763554
#ifndef SQLITE_OMIT_EXPLAIN
6351863555
if( p->explain ){
6351963556
rc = sqlite3VdbeList(p);
6352063557
}else
6352163558
#endif /* SQLITE_OMIT_EXPLAIN */
6352263559
{
63523
- db->vdbeExecCnt++;
63560
+ db->nVdbeExec++;
6352463561
rc = sqlite3VdbeExec(p);
63525
- db->vdbeExecCnt--;
63562
+ db->nVdbeExec--;
6352663563
}
6352763564
6352863565
#ifndef SQLITE_OMIT_TRACE
6352963566
/* Invoke the profile callback if there is one
6353063567
*/
@@ -64457,13 +64494,13 @@
6445764494
return nTotal;
6445864495
}
6445964496
6446064497
/*
6446164498
** This function returns a pointer to a nul-terminated string in memory
64462
-** obtained from sqlite3DbMalloc(). If sqlite3.vdbeExecCnt is 1, then the
64499
+** obtained from sqlite3DbMalloc(). If sqlite3.nVdbeExec is 1, then the
6446364500
** string contains a copy of zRawSql but with host parameters expanded to
64464
-** their current bindings. Or, if sqlite3.vdbeExecCnt is greater than 1,
64501
+** their current bindings. Or, if sqlite3.nVdbeExec is greater than 1,
6446564502
** then the returned string holds a copy of zRawSql with "-- " prepended
6446664503
** to each line of text.
6446764504
**
6446864505
** If the SQLITE_TRACE_SIZE_LIMIT macro is defined to an integer, then
6446964506
** then long strings and blobs are truncated to that many bytes. This
@@ -64497,11 +64534,11 @@
6449764534
6449864535
db = p->db;
6449964536
sqlite3StrAccumInit(&out, zBase, sizeof(zBase),
6450064537
db->aLimit[SQLITE_LIMIT_LENGTH]);
6450164538
out.db = db;
64502
- if( db->vdbeExecCnt>1 ){
64539
+ if( db->nVdbeExec>1 ){
6450364540
while( *zRawSql ){
6450464541
const char *zStart = zRawSql;
6450564542
while( *(zRawSql++)!='\n' && *zRawSql );
6450664543
sqlite3StrAccumAppend(&out, "-- ", 3);
6450764544
sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
@@ -65351,16 +65388,17 @@
6535165388
u8 encoding = ENC(db); /* The database encoding */
6535265389
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
6535365390
int checkProgress; /* True if progress callbacks are enabled */
6535465391
int nProgressOps = 0; /* Opcodes executed since progress callback. */
6535565392
#endif
65393
+ int iCompare = 0; /* Result of last OP_Compare operation */
65394
+ unsigned nVmStep = 0; /* Number of virtual machine steps */
6535665395
Mem *aMem = p->aMem; /* Copy of p->aMem */
6535765396
Mem *pIn1 = 0; /* 1st input operand */
6535865397
Mem *pIn2 = 0; /* 2nd input operand */
6535965398
Mem *pIn3 = 0; /* 3rd input operand */
6536065399
Mem *pOut = 0; /* Output operand */
65361
- int iCompare = 0; /* Result of last OP_Compare operation */
6536265400
int *aPermute = 0; /* Permutation of columns for OP_Compare */
6536365401
i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
6536465402
#ifdef VDBE_PROFILE
6536565403
u64 start; /* CPU clock count at start of opcode */
6536665404
int origPc; /* Program counter at start of opcode */
@@ -65802,10 +65840,11 @@
6580265840
/* This happens if a malloc() inside a call to sqlite3_column_text() or
6580365841
** sqlite3_column_text16() failed. */
6580465842
goto no_mem;
6580565843
}
6580665844
assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY );
65845
+ assert( p->bIsReader || p->readOnly!=0 );
6580765846
p->rc = SQLITE_OK;
6580865847
assert( p->explain==0 );
6580965848
p->pResultSet = 0;
6581065849
db->busyHandler.nBusy = 0;
6581165850
CHECK_FOR_INTERRUPT;
@@ -65830,10 +65869,11 @@
6583065869
if( db->mallocFailed ) goto no_mem;
6583165870
#ifdef VDBE_PROFILE
6583265871
origPc = pc;
6583365872
start = sqlite3Hwtime();
6583465873
#endif
65874
+ nVmStep++;
6583565875
pOp = &aOp[pc];
6583665876
6583765877
/* Only allow tracing if SQLITE_DEBUG is defined.
6583865878
*/
6583965879
#ifdef SQLITE_DEBUG
@@ -67945,13 +67985,14 @@
6794567985
*/
6794667986
assert( db->pSavepoint==0 || db->autoCommit==0 );
6794767987
assert( u.as.p1==SAVEPOINT_BEGIN||u.as.p1==SAVEPOINT_RELEASE||u.as.p1==SAVEPOINT_ROLLBACK );
6794867988
assert( db->pSavepoint || db->isTransactionSavepoint==0 );
6794967989
assert( checkSavepointCount(db) );
67990
+ assert( p->bIsReader );
6795067991
6795167992
if( u.as.p1==SAVEPOINT_BEGIN ){
67952
- if( db->writeVdbeCnt>0 ){
67993
+ if( db->nVdbeWrite>0 ){
6795367994
/* A new savepoint cannot be created if there are active write
6795467995
** statements (i.e. open read/write incremental blob handles).
6795567996
*/
6795667997
sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
6795767998
"SQL statements in progress");
@@ -68004,11 +68045,11 @@
6800468045
u.as.iSavepoint++;
6800568046
}
6800668047
if( !u.as.pSavepoint ){
6800768048
sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.as.zName);
6800868049
rc = SQLITE_ERROR;
68009
- }else if( db->writeVdbeCnt>0 && u.as.p1==SAVEPOINT_RELEASE ){
68050
+ }else if( db->nVdbeWrite>0 && u.as.p1==SAVEPOINT_RELEASE ){
6801068051
/* It is not possible to release (commit) a savepoint if there are
6801168052
** active write statements.
6801268053
*/
6801368054
sqlite3SetString(&p->zErrMsg, db,
6801468055
"cannot release savepoint - SQL statements in progress"
@@ -68107,24 +68148,25 @@
6810768148
u.at.desiredAutoCommit = pOp->p1;
6810868149
u.at.iRollback = pOp->p2;
6810968150
u.at.turnOnAC = u.at.desiredAutoCommit && !db->autoCommit;
6811068151
assert( u.at.desiredAutoCommit==1 || u.at.desiredAutoCommit==0 );
6811168152
assert( u.at.desiredAutoCommit==1 || u.at.iRollback==0 );
68112
- assert( db->activeVdbeCnt>0 ); /* At least this one VM is active */
68153
+ assert( db->nVdbeActive>0 ); /* At least this one VM is active */
68154
+ assert( p->bIsReader );
6811368155
6811468156
#if 0
68115
- if( u.at.turnOnAC && u.at.iRollback && db->activeVdbeCnt>1 ){
68157
+ if( u.at.turnOnAC && u.at.iRollback && db->nVdbeActive>1 ){
6811668158
/* If this instruction implements a ROLLBACK and other VMs are
6811768159
** still running, and a transaction is active, return an error indicating
6811868160
** that the other VMs must complete first.
6811968161
*/
6812068162
sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
6812168163
"SQL statements in progress");
6812268164
rc = SQLITE_BUSY;
6812368165
}else
6812468166
#endif
68125
- if( u.at.turnOnAC && !u.at.iRollback && db->writeVdbeCnt>0 ){
68167
+ if( u.at.turnOnAC && !u.at.iRollback && db->nVdbeWrite>0 ){
6812668168
/* If this instruction implements a COMMIT and other VMs are writing
6812768169
** return an error indicating that the other VMs must complete first.
6812868170
*/
6812968171
sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
6813068172
"SQL statements in progress");
@@ -68198,10 +68240,12 @@
6819868240
case OP_Transaction: {
6819968241
#if 0 /* local variables moved into u.au */
6820068242
Btree *pBt;
6820168243
#endif /* local variables moved into u.au */
6820268244
68245
+ assert( p->bIsReader );
68246
+ assert( p->readOnly==0 || pOp->p2==0 );
6820368247
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6820468248
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6820568249
u.au.pBt = db->aDb[pOp->p1].pBt;
6820668250
6820768251
if( u.au.pBt ){
@@ -68214,11 +68258,11 @@
6821468258
if( rc!=SQLITE_OK ){
6821568259
goto abort_due_to_error;
6821668260
}
6821768261
6821868262
if( pOp->p2 && p->usesStmtJournal
68219
- && (db->autoCommit==0 || db->activeVdbeCnt>1)
68263
+ && (db->autoCommit==0 || db->nVdbeRead>1)
6822068264
){
6822168265
assert( sqlite3BtreeIsInTrans(u.au.pBt) );
6822268266
if( p->iStatement==0 ){
6822368267
assert( db->nStatement>=0 && db->nSavepoint>=0 );
6822468268
db->nStatement++;
@@ -68256,10 +68300,11 @@
6825668300
int iMeta;
6825768301
int iDb;
6825868302
int iCookie;
6825968303
#endif /* local variables moved into u.av */
6826068304
68305
+ assert( p->bIsReader );
6826168306
u.av.iDb = pOp->p1;
6826268307
u.av.iCookie = pOp->p3;
6826368308
assert( pOp->p3<SQLITE_N_BTREE_META );
6826468309
assert( u.av.iDb>=0 && u.av.iDb<db->nDb );
6826568310
assert( db->aDb[u.av.iDb].pBt!=0 );
@@ -68285,10 +68330,11 @@
6828568330
Db *pDb;
6828668331
#endif /* local variables moved into u.aw */
6828768332
assert( pOp->p2<SQLITE_N_BTREE_META );
6828868333
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6828968334
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
68335
+ assert( p->readOnly==0 );
6829068336
u.aw.pDb = &db->aDb[pOp->p1];
6829168337
assert( u.aw.pDb->pBt!=0 );
6829268338
assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
6829368339
pIn3 = &aMem[pOp->p3];
6829468340
sqlite3VdbeMemIntegerify(pIn3);
@@ -68337,10 +68383,11 @@
6833768383
#endif /* local variables moved into u.ax */
6833868384
6833968385
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6834068386
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6834168387
assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
68388
+ assert( p->bIsReader );
6834268389
u.ax.pBt = db->aDb[pOp->p1].pBt;
6834368390
if( u.ax.pBt ){
6834468391
sqlite3BtreeGetMeta(u.ax.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ax.iMeta);
6834568392
u.ax.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
6834668393
}else{
@@ -68434,10 +68481,12 @@
6843468481
Db *pDb;
6843568482
#endif /* local variables moved into u.ay */
6843668483
6843768484
assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
6843868485
assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
68486
+ assert( p->bIsReader );
68487
+ assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
6843968488
6844068489
if( p->expired ){
6844168490
rc = SQLITE_ABORT;
6844268491
break;
6844368492
}
@@ -70052,19 +70101,22 @@
7005270101
int iCnt;
7005370102
Vdbe *pVdbe;
7005470103
int iDb;
7005570104
#endif /* local variables moved into u.bw */
7005670105
70106
+ assert( p->readOnly==0 );
7005770107
#ifndef SQLITE_OMIT_VIRTUALTABLE
7005870108
u.bw.iCnt = 0;
7005970109
for(u.bw.pVdbe=db->pVdbe; u.bw.pVdbe; u.bw.pVdbe = u.bw.pVdbe->pNext){
70060
- if( u.bw.pVdbe->magic==VDBE_MAGIC_RUN && u.bw.pVdbe->inVtabMethod<2 && u.bw.pVdbe->pc>=0 ){
70110
+ if( u.bw.pVdbe->magic==VDBE_MAGIC_RUN && u.bw.pVdbe->bIsReader
70111
+ && u.bw.pVdbe->inVtabMethod<2 && u.bw.pVdbe->pc>=0
70112
+ ){
7006170113
u.bw.iCnt++;
7006270114
}
7006370115
}
7006470116
#else
70065
- u.bw.iCnt = db->activeVdbeCnt;
70117
+ u.bw.iCnt = db->nVdbeRead;
7006670118
#endif
7006770119
pOut->flags = MEM_Null;
7006870120
if( u.bw.iCnt>1 ){
7006970121
rc = SQLITE_LOCKED;
7007070122
p->errorAction = OE_Abort;
@@ -70109,10 +70161,11 @@
7010970161
#if 0 /* local variables moved into u.bx */
7011070162
int nChange;
7011170163
#endif /* local variables moved into u.bx */
7011270164
7011370165
u.bx.nChange = 0;
70166
+ assert( p->readOnly==0 );
7011470167
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
7011570168
rc = sqlite3BtreeClearTable(
7011670169
db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bx.nChange : 0)
7011770170
);
7011870171
if( pOp->p3 ){
@@ -70157,10 +70210,11 @@
7015770210
#endif /* local variables moved into u.by */
7015870211
7015970212
u.by.pgno = 0;
7016070213
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7016170214
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
70215
+ assert( p->readOnly==0 );
7016270216
u.by.pDb = &db->aDb[pOp->p1];
7016370217
assert( u.by.pDb->pBt!=0 );
7016470218
if( pOp->opcode==OP_CreateTable ){
7016570219
/* u.by.flags = BTREE_INTKEY; */
7016670220
u.by.flags = BTREE_INTKEY;
@@ -70309,10 +70363,11 @@
7030970363
int nErr; /* Number of errors reported */
7031070364
char *z; /* Text of the error report */
7031170365
Mem *pnErr; /* Register keeping track of errors remaining */
7031270366
#endif /* local variables moved into u.ca */
7031370367
70368
+ assert( p->bIsReader );
7031470369
u.ca.nRoot = pOp->p2;
7031570370
assert( u.ca.nRoot>0 );
7031670371
u.ca.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.ca.nRoot+1) );
7031770372
if( u.ca.aRoot==0 ) goto no_mem;
7031870373
assert( pOp->p3>0 && pOp->p3<=p->nMem );
@@ -70830,10 +70885,11 @@
7083070885
int i; /* Loop counter */
7083170886
int aRes[3]; /* Results */
7083270887
Mem *pMem; /* Write results here */
7083370888
#endif /* local variables moved into u.ci */
7083470889
70890
+ assert( p->readOnly==0 );
7083570891
u.ci.aRes[0] = 0;
7083670892
u.ci.aRes[1] = u.ci.aRes[2] = -1;
7083770893
assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
7083870894
|| pOp->p2==SQLITE_CHECKPOINT_FULL
7083970895
|| pOp->p2==SQLITE_CHECKPOINT_RESTART
@@ -70881,10 +70937,11 @@
7088170937
|| u.cj.eNew==PAGER_JOURNALMODE_MEMORY
7088270938
|| u.cj.eNew==PAGER_JOURNALMODE_WAL
7088370939
|| u.cj.eNew==PAGER_JOURNALMODE_QUERY
7088470940
);
7088570941
assert( pOp->p1>=0 && pOp->p1<db->nDb );
70942
+ assert( p->readOnly==0 );
7088670943
7088770944
u.cj.pBt = db->aDb[pOp->p1].pBt;
7088870945
u.cj.pPager = sqlite3BtreePager(u.cj.pBt);
7088970946
u.cj.eOld = sqlite3PagerGetJournalMode(u.cj.pPager);
7089070947
if( u.cj.eNew==PAGER_JOURNALMODE_QUERY ) u.cj.eNew = u.cj.eOld;
@@ -70904,11 +70961,11 @@
7090470961
}
7090570962
7090670963
if( (u.cj.eNew!=u.cj.eOld)
7090770964
&& (u.cj.eOld==PAGER_JOURNALMODE_WAL || u.cj.eNew==PAGER_JOURNALMODE_WAL)
7090870965
){
70909
- if( !db->autoCommit || db->activeVdbeCnt>1 ){
70966
+ if( !db->autoCommit || db->nVdbeRead>1 ){
7091070967
rc = SQLITE_ERROR;
7091170968
sqlite3SetString(&p->zErrMsg, db,
7091270969
"cannot change %s wal mode from within a transaction",
7091370970
(u.cj.eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of")
7091470971
);
@@ -70963,10 +71020,11 @@
7096371020
** Vacuum the entire database. This opcode will cause other virtual
7096471021
** machines to be created and run. It may not be called from within
7096571022
** a transaction.
7096671023
*/
7096771024
case OP_Vacuum: {
71025
+ assert( p->readOnly==0 );
7096871026
rc = sqlite3RunVacuum(&p->zErrMsg, db);
7096971027
break;
7097071028
}
7097171029
#endif
7097271030
@@ -70982,10 +71040,11 @@
7098271040
Btree *pBt;
7098371041
#endif /* local variables moved into u.ck */
7098471042
7098571043
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7098671044
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
71045
+ assert( p->readOnly==0 );
7098771046
u.ck.pBt = db->aDb[pOp->p1].pBt;
7098871047
rc = sqlite3BtreeIncrVacuum(u.ck.pBt);
7098971048
if( rc==SQLITE_DONE ){
7099071049
pc = pOp->p2 - 1;
7099171050
rc = SQLITE_OK;
@@ -71104,10 +71163,11 @@
7110471163
sqlite3_vtab_cursor *pVtabCursor;
7110571164
sqlite3_vtab *pVtab;
7110671165
sqlite3_module *pModule;
7110771166
#endif /* local variables moved into u.cm */
7110871167
71168
+ assert( p->bIsReader );
7110971169
u.cm.pCur = 0;
7111071170
u.cm.pVtabCursor = 0;
7111171171
u.cm.pVtab = pOp->p4.pVtab->pVtab;
7111271172
u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule;
7111371173
assert(u.cm.pVtab && u.cm.pModule);
@@ -71328,10 +71388,11 @@
7132871388
7132971389
u.cq.pVtab = pOp->p4.pVtab->pVtab;
7133071390
u.cq.pName = &aMem[pOp->p1];
7133171391
assert( u.cq.pVtab->pModule->xRename );
7133271392
assert( memIsValid(u.cq.pName) );
71393
+ assert( p->readOnly==0 );
7133371394
REGISTER_TRACE(pOp->p1, u.cq.pName);
7133471395
assert( u.cq.pName->flags & MEM_Str );
7133571396
testcase( u.cq.pName->enc==SQLITE_UTF8 );
7133671397
testcase( u.cq.pName->enc==SQLITE_UTF16BE );
7133771398
testcase( u.cq.pName->enc==SQLITE_UTF16LE );
@@ -71381,10 +71442,11 @@
7138171442
#endif /* local variables moved into u.cr */
7138271443
7138371444
assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
7138471445
|| pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
7138571446
);
71447
+ assert( p->readOnly==0 );
7138671448
u.cr.pVtab = pOp->p4.pVtab->pVtab;
7138771449
u.cr.pModule = (sqlite3_module *)u.cr.pVtab->pModule;
7138871450
u.cr.nArg = pOp->p2;
7138971451
assert( pOp->p4type==P4_VTAB );
7139071452
if( ALWAYS(u.cr.pModule->xUpdate) ){
@@ -71566,10 +71628,11 @@
7156671628
/* This is the only way out of this procedure. We have to
7156771629
** release the mutexes on btrees that were acquired at the
7156871630
** top. */
7156971631
vdbe_return:
7157071632
db->lastRowid = lastRowid;
71633
+ p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1] += (int)nVmStep;
7157171634
sqlite3VdbeLeave(p);
7157271635
return rc;
7157371636
7157471637
/* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
7157571638
** is encountered.
@@ -76044,10 +76107,11 @@
7604476107
pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
7604576108
pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
7604676109
pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
7604776110
pItem->sortOrder = pOldItem->sortOrder;
7604876111
pItem->done = 0;
76112
+ pItem->bSpanIsTab = pOldItem->bSpanIsTab;
7604976113
pItem->iOrderByCol = pOldItem->iOrderByCol;
7605076114
pItem->iAlias = pOldItem->iAlias;
7605176115
}
7605276116
return pNew;
7605376117
}
@@ -100236,19 +100300,20 @@
100236100300
sDistinct.eTnctType = WHERE_DISTINCT_NOOP;
100237100301
}
100238100302
100239100303
if( !isAgg && pGroupBy==0 ){
100240100304
/* No aggregate functions and no GROUP BY clause */
100241
- ExprList *pDist = (sDistinct.isTnct ? p->pEList : 0);
100305
+ u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0);
100242100306
100243100307
/* Begin the database scan. */
100244
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pOrderBy, pDist, 0,0);
100308
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pOrderBy, p->pEList,
100309
+ wctrlFlags, 0);
100245100310
if( pWInfo==0 ) goto select_end;
100246100311
if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
100247100312
p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
100248100313
}
100249
- if( sqlite3WhereIsDistinct(pWInfo) ){
100314
+ if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){
100250100315
sDistinct.eTnctType = sqlite3WhereIsDistinct(pWInfo);
100251100316
}
100252100317
if( pOrderBy && sqlite3WhereIsOrdered(pWInfo) ) pOrderBy = 0;
100253100318
100254100319
/* If sorting index that was created by a prior OP_OpenEphemeral
@@ -102940,11 +103005,11 @@
102940103005
102941103006
if( !db->autoCommit ){
102942103007
sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
102943103008
return SQLITE_ERROR;
102944103009
}
102945
- if( db->activeVdbeCnt>1 ){
103010
+ if( db->nVdbeActive>1 ){
102946103011
sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
102947103012
return SQLITE_ERROR;
102948103013
}
102949103014
102950103015
/* Save the current value of the database flags so that it can be
@@ -104440,11 +104505,11 @@
104440104505
104441104506
/*
104442104507
** Each instance of this object holds a sequence of WhereLoop objects
104443104508
** that implement some or all of a query plan.
104444104509
**
104445
-** Think of each WhereLoop objects as a node in a graph, which arcs
104510
+** Think of each WhereLoop object as a node in a graph with arcs
104446104511
** showing dependences and costs for travelling between nodes. (That is
104447104512
** not a completely accurate description because WhereLoop costs are a
104448104513
** vector, not a scalar, and because dependences are many-to-one, not
104449104514
** one-to-one as are graph nodes. But it is a useful visualization aid.)
104450104515
** Then a WherePath object is a path through the graph that visits some
@@ -104664,23 +104729,23 @@
104664104729
*/
104665104730
struct WhereInfo {
104666104731
Parse *pParse; /* Parsing and code generating context */
104667104732
SrcList *pTabList; /* List of tables in the join */
104668104733
ExprList *pOrderBy; /* The ORDER BY clause or NULL */
104669
- ExprList *pDistinct; /* DISTINCT ON values, or NULL */
104734
+ ExprList *pResultSet; /* Result set. DISTINCT operates on these */
104670104735
WhereLoop *pLoops; /* List of all WhereLoop objects */
104671104736
Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
104672104737
WhereCost nRowOut; /* Estimated number of output rows */
104673104738
u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
104674104739
u8 bOBSat; /* ORDER BY satisfied by indices */
104675104740
u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE/DELETE */
104676104741
u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */
104677104742
u8 eDistinct; /* One of the WHERE_DISTINCT_* values below */
104743
+ u8 nLevel; /* Number of nested loop */
104678104744
int iTop; /* The very beginning of the WHERE loop */
104679104745
int iContinue; /* Jump here to continue with next record */
104680104746
int iBreak; /* Jump here to break out of the loop */
104681
- int nLevel; /* Number of nested loop */
104682104747
int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
104683104748
WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
104684104749
WhereClause sWC; /* Decomposition of the WHERE clause */
104685104750
WhereLevel a[1]; /* Information about each nest loop in WHERE */
104686104751
};
@@ -104710,11 +104775,11 @@
104710104775
/*
104711104776
** These are definitions of bits in the WhereLoop.wsFlags field.
104712104777
** The particular combination of bits in each WhereLoop help to
104713104778
** determine the algorithm that WhereLoop represents.
104714104779
*/
104715
-#define WHERE_COLUMN_EQ 0x00000001 /* x=EXPR or x IN (...) or x IS NULL */
104780
+#define WHERE_COLUMN_EQ 0x00000001 /* x=EXPR */
104716104781
#define WHERE_COLUMN_RANGE 0x00000002 /* x<EXPR and/or x>EXPR */
104717104782
#define WHERE_COLUMN_IN 0x00000004 /* x IN (...) */
104718104783
#define WHERE_COLUMN_NULL 0x00000008 /* x IS NULL */
104719104784
#define WHERE_CONSTRAINT 0x0000000f /* Any of the WHERE_COLUMN_xxx values */
104720104785
#define WHERE_TOP_LIMIT 0x00000010 /* x<EXPR or x<=EXPR constraint */
@@ -104725,11 +104790,11 @@
104725104790
#define WHERE_INDEXED 0x00000200 /* WhereLoop.u.btree.pIndex is valid */
104726104791
#define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */
104727104792
#define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
104728104793
#define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
104729104794
#define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
104730
-#define WHERE_TEMP_INDEX 0x00004000 /* Uses an ephemeral index */
104795
+#define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
104731104796
104732104797
104733104798
/* Convert a WhereCost value (10 times log2(X)) into its integer value X.
104734104799
** A rough approximation is used. The value returned is not exact.
104735104800
*/
@@ -105103,11 +105168,11 @@
105103105168
/*
105104105169
** Advance to the next WhereTerm that matches according to the criteria
105105105170
** established when the pScan object was initialized by whereScanInit().
105106105171
** Return NULL if there are no more matching WhereTerms.
105107105172
*/
105108
-WhereTerm *whereScanNext(WhereScan *pScan){
105173
+static WhereTerm *whereScanNext(WhereScan *pScan){
105109105174
int iCur; /* The cursor on the LHS of the term */
105110105175
int iColumn; /* The column on the LHS of the term. -1 for IPK */
105111105176
Expr *pX; /* An expression being tested */
105112105177
WhereClause *pWC; /* Shorthand for pScan->pWC */
105113105178
WhereTerm *pTerm; /* The term being tested */
@@ -105190,11 +105255,11 @@
105190105255
** but is enough to handle most commonly occurring SQL statements.
105191105256
**
105192105257
** If X is not the INTEGER PRIMARY KEY then X must be compatible with
105193105258
** index pIdx.
105194105259
*/
105195
-WhereTerm *whereScanInit(
105260
+static WhereTerm *whereScanInit(
105196105261
WhereScan *pScan, /* The WhereScan object being initialized */
105197105262
WhereClause *pWC, /* The WHERE clause to be scanned */
105198105263
int iCur, /* Cursor to scan for */
105199105264
int iColumn, /* Column to scan for */
105200105265
u32 opMask, /* Operator(s) to scan for */
@@ -106019,10 +106084,11 @@
106019106084
** the start of the loop will prevent any results from being returned.
106020106085
*/
106021106086
if( pExpr->op==TK_NOTNULL
106022106087
&& pExpr->pLeft->op==TK_COLUMN
106023106088
&& pExpr->pLeft->iColumn>=0
106089
+ && OptimizationEnabled(db, SQLITE_Stat3)
106024106090
){
106025106091
Expr *pNewExpr;
106026106092
Expr *pLeft = pExpr->pLeft;
106027106093
int idxNew;
106028106094
WhereTerm *pNewTerm;
@@ -106322,10 +106388,11 @@
106322106388
int mxBitCol; /* Maximum column in pSrc->colUsed */
106323106389
CollSeq *pColl; /* Collating sequence to on a column */
106324106390
WhereLoop *pLoop; /* The Loop object */
106325106391
Bitmask idxCols; /* Bitmap of columns used for indexing */
106326106392
Bitmask extraCols; /* Bitmap of additional columns */
106393
+ u8 sentWarning = 0; /* True if a warnning has been issued */
106327106394
106328106395
/* Generate code to skip over the creation and initialization of the
106329106396
** transient index on 2nd and subsequent iterations of the loop. */
106330106397
v = pParse->pVdbe;
106331106398
assert( v!=0 );
@@ -106342,10 +106409,16 @@
106342106409
if( termCanDriveIndex(pTerm, pSrc, notReady) ){
106343106410
int iCol = pTerm->u.leftColumn;
106344106411
Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
106345106412
testcase( iCol==BMS );
106346106413
testcase( iCol==BMS-1 );
106414
+ if( !sentWarning ){
106415
+ sqlite3_log(SQLITE_WARNING_AUTOINDEX,
106416
+ "automatic index on %s(%s)", pTable->zName,
106417
+ pTable->aCol[iCol].zName);
106418
+ sentWarning = 1;
106419
+ }
106347106420
if( (idxCols & cMask)==0 ){
106348106421
if( whereLoopResize(pParse->db, pLoop, nColumn+1) ) return;
106349106422
pLoop->aLTerm[nColumn++] = pTerm;
106350106423
idxCols |= cMask;
106351106424
}
@@ -106352,11 +106425,11 @@
106352106425
}
106353106426
}
106354106427
assert( nColumn>0 );
106355106428
pLoop->u.btree.nEq = pLoop->nLTerm = nColumn;
106356106429
pLoop->wsFlags = WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WHERE_INDEXED
106357
- | WHERE_TEMP_INDEX;
106430
+ | WHERE_AUTO_INDEX;
106358106431
106359106432
/* Count the number of additional columns needed to create a
106360106433
** covering index. A "covering index" is an index that contains all
106361106434
** columns that are needed by the query. With a covering index, the
106362106435
** original table never needs to be accessed. Automatic indices must
@@ -106690,13 +106763,14 @@
106690106763
z = (const u8 *)sqlite3_value_blob(pVal);
106691106764
pColl = db->pDfltColl;
106692106765
assert( pColl->enc==SQLITE_UTF8 );
106693106766
}else{
106694106767
pColl = sqlite3GetCollSeq(pParse, SQLITE_UTF8, 0, *pIdx->azColl);
106695
- if( pColl==0 ){
106696
- return SQLITE_ERROR;
106697
- }
106768
+ /* If the collating sequence was unavailable, we should have failed
106769
+ ** long ago and never reached this point. But we'll check just to
106770
+ ** be doubly sure. */
106771
+ if( NEVER(pColl==0) ) return SQLITE_ERROR;
106698106772
z = (const u8 *)sqlite3ValueText(pVal, pColl->enc);
106699106773
if( !z ){
106700106774
return SQLITE_NOMEM;
106701106775
}
106702106776
assert( z && pColl && pColl->xCmp );
@@ -106851,11 +106925,11 @@
106851106925
){
106852106926
int rc = SQLITE_OK;
106853106927
106854106928
#ifdef SQLITE_ENABLE_STAT3
106855106929
106856
- if( nEq==0 && p->nSample ){
106930
+ if( nEq==0 && p->nSample && OptimizationEnabled(pParse->db, SQLITE_Stat3) ){
106857106931
sqlite3_value *pRangeVal;
106858106932
tRowcnt iLower = 0;
106859106933
tRowcnt iUpper = p->aiRowEst[0];
106860106934
tRowcnt a[2];
106861106935
u8 aff = p->pTable->aCol[p->aiColumn[0]].affinity;
@@ -107397,17 +107471,16 @@
107397107471
}
107398107472
if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0
107399107473
&& ALWAYS(pLoop->u.btree.pIndex!=0)
107400107474
){
107401107475
char *zWhere = explainIndexRange(db, pLoop, pItem->pTab);
107402
- zMsg = sqlite3MAppendf(db, zMsg, "%s USING %s%sINDEX%s%s%s", zMsg,
107403
- ((flags & WHERE_TEMP_INDEX)?"AUTOMATIC ":""),
107404
- ((flags & WHERE_IDX_ONLY)?"COVERING ":""),
107405
- ((flags & WHERE_TEMP_INDEX)?"":" "),
107406
- ((flags & WHERE_TEMP_INDEX)?"": pLoop->u.btree.pIndex->zName),
107407
- zWhere
107408
- );
107476
+ zMsg = sqlite3MAppendf(db, zMsg,
107477
+ ((flags & WHERE_AUTO_INDEX) ?
107478
+ "%s USING AUTOMATIC %sINDEX%.0s%s" :
107479
+ "%s USING %sINDEX %s%s"),
107480
+ zMsg, ((flags & WHERE_IDX_ONLY) ? "COVERING " : ""),
107481
+ pLoop->u.btree.pIndex->zName, zWhere);
107409107482
sqlite3DbFree(db, zWhere);
107410107483
}else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
107411107484
zMsg = sqlite3MAppendf(db, zMsg, "%s USING INTEGER PRIMARY KEY", zMsg);
107412107485
107413107486
if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
@@ -107608,14 +107681,15 @@
107608107681
};
107609107682
assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
107610107683
assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
107611107684
assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
107612107685
107686
+ assert( (pStart->wtFlags & TERM_VNULL)==0 );
107613107687
testcase( pStart->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
107614107688
pX = pStart->pExpr;
107615107689
assert( pX!=0 );
107616
- assert( pStart->leftCursor==iCur );
107690
+ testcase( pStart->leftCursor!=iCur ); /* transitive constraints */
107617107691
r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
107618107692
sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
107619107693
VdbeComment((v, "pk"));
107620107694
sqlite3ExprCacheAffinityChange(pParse, r1, 1);
107621107695
sqlite3ReleaseTempReg(pParse, rTemp);
@@ -107625,11 +107699,12 @@
107625107699
}
107626107700
if( pEnd ){
107627107701
Expr *pX;
107628107702
pX = pEnd->pExpr;
107629107703
assert( pX!=0 );
107630
- assert( pEnd->leftCursor==iCur );
107704
+ assert( (pEnd->wtFlags & TERM_VNULL)==0 );
107705
+ testcase( pEnd->leftCursor!=iCur ); /* Transitive constraints */
107631107706
testcase( pEnd->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
107632107707
memEndValue = ++pParse->nMem;
107633107708
sqlite3ExprCode(pParse, pX->pRight, memEndValue);
107634107709
if( pX->op==TK_LT || pX->op==TK_GT ){
107635107710
testOp = bRev ? OP_Le : OP_Ge;
@@ -108074,11 +108149,11 @@
108074108149
** terms, set pCov to the candidate covering index. Otherwise, set
108075108150
** pCov to NULL to indicate that no candidate covering index will
108076108151
** be available.
108077108152
*/
108078108153
pSubLoop = pSubWInfo->a[0].pWLoop;
108079
- assert( (pSubLoop->wsFlags & WHERE_TEMP_INDEX)==0 );
108154
+ assert( (pSubLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
108080108155
if( (pSubLoop->wsFlags & WHERE_INDEXED)!=0
108081108156
&& (ii==0 || pSubLoop->u.btree.pIndex==pCov)
108082108157
){
108083108158
assert( pSubWInfo->a[0].iIdxCur==iCovCur );
108084108159
pCov = pSubLoop->u.btree.pIndex;
@@ -108160,10 +108235,11 @@
108160108235
WhereTerm *pAlt;
108161108236
Expr sEq;
108162108237
if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
108163108238
if( pTerm->eOperator!=(WO_EQUIV|WO_EQ) ) continue;
108164108239
if( pTerm->leftCursor!=iCur ) continue;
108240
+ if( pLevel->iLeftJoin ) continue;
108165108241
pE = pTerm->pExpr;
108166108242
assert( !ExprHasProperty(pE, EP_FromJoin) );
108167108243
assert( (pTerm->prereqRight & newNotReady)!=0 );
108168108244
pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
108169108245
if( pAlt==0 ) continue;
@@ -108208,13 +108284,13 @@
108208108284
*/
108209108285
static void whereLoopPrint(WhereLoop *p, SrcList *pTabList){
108210108286
int nb = 1+(pTabList->nSrc+7)/8;
108211108287
struct SrcList_item *pItem = pTabList->a + p->iTab;
108212108288
Table *pTab = pItem->pTab;
108213
- sqlite3DebugPrintf("%c %2d.%0*llx.%0*llx", p->cId,
108289
+ sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
108214108290
p->iTab, nb, p->maskSelf, nb, p->prereq);
108215
- sqlite3DebugPrintf(" %8s",
108291
+ sqlite3DebugPrintf(" %12s",
108216108292
pItem->zAlias ? pItem->zAlias : pTab->zName);
108217108293
if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
108218108294
if( p->u.btree.pIndex ){
108219108295
const char *zName = p->u.btree.pIndex->zName;
108220108296
if( zName==0 ) zName = "ipk";
@@ -108221,26 +108297,26 @@
108221108297
if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
108222108298
int i = sqlite3Strlen30(zName) - 1;
108223108299
while( zName[i]!='_' ) i--;
108224108300
zName += i;
108225108301
}
108226
- sqlite3DebugPrintf(".%-12s %2d", zName, p->u.btree.nEq);
108302
+ sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);
108227108303
}else{
108228
- sqlite3DebugPrintf("%16s","");
108304
+ sqlite3DebugPrintf("%20s","");
108229108305
}
108230108306
}else{
108231108307
char *z;
108232108308
if( p->u.vtab.idxStr ){
108233108309
z = sqlite3_mprintf("(%d,\"%s\",%x)",
108234108310
p->u.vtab.idxNum, p->u.vtab.idxStr, p->u.vtab.omitMask);
108235108311
}else{
108236108312
z = sqlite3_mprintf("(%d,%x)", p->u.vtab.idxNum, p->u.vtab.omitMask);
108237108313
}
108238
- sqlite3DebugPrintf(" %-15s", z);
108314
+ sqlite3DebugPrintf(" %-19s", z);
108239108315
sqlite3_free(z);
108240108316
}
108241
- sqlite3DebugPrintf(" fg %05x N %d", p->wsFlags, p->nLTerm);
108317
+ sqlite3DebugPrintf(" f %04x N %d", p->wsFlags, p->nLTerm);
108242108318
sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
108243108319
}
108244108320
#endif
108245108321
108246108322
/*
@@ -108256,16 +108332,16 @@
108256108332
108257108333
/*
108258108334
** Clear the WhereLoop.u union. Leave WhereLoop.pLTerm intact.
108259108335
*/
108260108336
static void whereLoopClearUnion(sqlite3 *db, WhereLoop *p){
108261
- if( p->wsFlags & (WHERE_VIRTUALTABLE|WHERE_TEMP_INDEX) ){
108337
+ if( p->wsFlags & (WHERE_VIRTUALTABLE|WHERE_AUTO_INDEX) ){
108262108338
if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 && p->u.vtab.needFree ){
108263108339
sqlite3_free(p->u.vtab.idxStr);
108264108340
p->u.vtab.needFree = 0;
108265108341
p->u.vtab.idxStr = 0;
108266
- }else if( (p->wsFlags & WHERE_TEMP_INDEX)!=0 && p->u.btree.pIndex!=0 ){
108342
+ }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
108267108343
sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
108268108344
sqlite3DbFree(db, p->u.btree.pIndex);
108269108345
p->u.btree.pIndex = 0;
108270108346
}
108271108347
}
@@ -108304,11 +108380,11 @@
108304108380
whereLoopClearUnion(db, pTo);
108305108381
memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
108306108382
memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
108307108383
if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
108308108384
pFrom->u.vtab.needFree = 0;
108309
- }else if( (pFrom->wsFlags & WHERE_TEMP_INDEX)!=0 ){
108385
+ }else if( (pFrom->wsFlags & WHERE_AUTO_INDEX)!=0 ){
108310108386
pFrom->u.btree.pIndex = 0;
108311108387
}
108312108388
return SQLITE_OK;
108313108389
}
108314108390
@@ -108554,10 +108630,15 @@
108554108630
pNew->rSetup = 0;
108555108631
rLogSize = estLog(whereCost(pProbe->aiRowEst[0]));
108556108632
for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
108557108633
int nIn = 0;
108558108634
if( pTerm->prereqRight & pNew->maskSelf ) continue;
108635
+#ifdef SQLITE_ENABLE_STAT3
108636
+ if( (pTerm->wtFlags & TERM_VNULL)!=0 && pSrc->pTab->aCol[iCol].notNull ){
108637
+ continue; /* skip IS NOT NULL constraints on a NOT NULL column */
108638
+ }
108639
+#endif
108559108640
pNew->wsFlags = saved_wsFlags;
108560108641
pNew->u.btree.nEq = saved_nEq;
108561108642
pNew->nLTerm = saved_nLTerm;
108562108643
if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
108563108644
pNew->aLTerm[pNew->nLTerm++] = pTerm;
@@ -108616,11 +108697,12 @@
108616108697
whereRangeScanEst(pParse, pProbe, pNew->u.btree.nEq,
108617108698
pBtm, pTop, &rDiv);
108618108699
pNew->nOut = saved_nOut>rDiv+10 ? saved_nOut - rDiv : 10;
108619108700
}
108620108701
#ifdef SQLITE_ENABLE_STAT3
108621
- if( pNew->u.btree.nEq==1 && pProbe->nSample ){
108702
+ if( pNew->u.btree.nEq==1 && pProbe->nSample
108703
+ && OptimizationEnabled(db, SQLITE_Stat3) ){
108622108704
tRowcnt nOut = 0;
108623108705
if( (pTerm->eOperator & (WO_EQ|WO_ISNULL))!=0 ){
108624108706
testcase( pTerm->eOperator & WO_EQ );
108625108707
testcase( pTerm->eOperator & WO_ISNULL );
108626108708
rc = whereEqualScanEst(pParse, pProbe, pTerm->pExpr->pRight, &nOut);
@@ -108700,11 +108782,11 @@
108700108782
return m;
108701108783
}
108702108784
108703108785
108704108786
/*
108705
-** Add all WhereLoop objects a single table of the join were the table
108787
+** Add all WhereLoop objects for a single table of the join where the table
108706108788
** is idenfied by pBuilder->pNew->iTab. That table is guaranteed to be
108707108789
** a b-tree table, not a virtual table.
108708108790
*/
108709108791
static int whereLoopAddBtree(
108710108792
WhereLoopBuilder *pBuilder, /* WHERE clause information */
@@ -108776,17 +108858,20 @@
108776108858
pNew->u.btree.nEq = 1;
108777108859
pNew->u.btree.pIndex = 0;
108778108860
pNew->nLTerm = 1;
108779108861
pNew->aLTerm[0] = pTerm;
108780108862
/* TUNING: One-time cost for computing the automatic index is
108781
- ** approximately 6*N*log2(N) where N is the number of rows in
108863
+ ** approximately 7*N*log2(N) where N is the number of rows in
108782108864
** the table being indexed. */
108783
- pNew->rSetup = rLogSize + rSize + 26; assert( 26==whereCost(6) );
108784
- /* TUNING: Each index lookup yields 10 rows in the table */
108785
- pNew->nOut = 33; assert( 33==whereCost(10) );
108865
+ pNew->rSetup = rLogSize + rSize + 28; assert( 28==whereCost(7) );
108866
+ /* TUNING: Each index lookup yields 20 rows in the table. This
108867
+ ** is more than the usual guess of 10 rows, since we have no way
108868
+ ** of knowning how selective the index will ultimately be. It would
108869
+ ** not be unreasonable to make this value much larger. */
108870
+ pNew->nOut = 43; assert( 43==whereCost(20) );
108786108871
pNew->rRun = whereCostAdd(rLogSize,pNew->nOut);
108787
- pNew->wsFlags = WHERE_TEMP_INDEX;
108872
+ pNew->wsFlags = WHERE_AUTO_INDEX;
108788108873
pNew->prereq = mExtra | pTerm->prereqRight;
108789108874
rc = whereLoopInsert(pBuilder, pNew);
108790108875
}
108791108876
}
108792108877
}
@@ -109161,16 +109246,23 @@
109161109246
}
109162109247
109163109248
/*
109164109249
** Examine a WherePath (with the addition of the extra WhereLoop of the 5th
109165109250
** parameters) to see if it outputs rows in the requested ORDER BY
109166
-** (or GROUP BY) without requiring a separate source operation. Return:
109251
+** (or GROUP BY) without requiring a separate sort operation. Return:
109167109252
**
109168109253
** 0: ORDER BY is not satisfied. Sorting required
109169109254
** 1: ORDER BY is satisfied. Omit sorting
109170109255
** -1: Unknown at this time
109171109256
**
109257
+** Note that processing for WHERE_GROUPBY and WHERE_DISTINCTBY is not as
109258
+** strict. With GROUP BY and DISTINCT the only requirement is that
109259
+** equivalent rows appear immediately adjacent to one another. GROUP BY
109260
+** and DISTINT do not require rows to appear in any particular order as long
109261
+** as equivelent rows are grouped together. Thus for GROUP BY and DISTINCT
109262
+** the pOrderBy terms can be matched in any order. With ORDER BY, the
109263
+** pOrderBy terms must be matched in strict left-to-right order.
109172109264
*/
109173109265
static int wherePathSatisfiesOrderBy(
109174109266
WhereInfo *pWInfo, /* The WHERE clause */
109175109267
ExprList *pOrderBy, /* ORDER BY or GROUP BY or DISTINCT clause to check */
109176109268
WherePath *pPath, /* The WherePath to check */
@@ -109414,11 +109506,11 @@
109414109506
}
109415109507
#endif
109416109508
109417109509
109418109510
/*
109419
-** Given the list of WhereLoop objects on pWInfo->pLoops, this routine
109511
+** Given the list of WhereLoop objects at pWInfo->pLoops, this routine
109420109512
** attempts to find the lowest cost path that visits each WhereLoop
109421109513
** once. This path is then loaded into the pWInfo->a[].pWLoop fields.
109422109514
**
109423109515
** Assume that the total number of output rows that will need to be sorted
109424109516
** will be nRowEst (in the 10*log2 representation). Or, ignore sorting
@@ -109650,16 +109742,17 @@
109650109742
WhereLevel *pLevel = pWInfo->a + iLoop;
109651109743
pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
109652109744
pLevel->iFrom = pWLoop->iTab;
109653109745
pLevel->iTabCur = pWInfo->pTabList->a[pLevel->iFrom].iCursor;
109654109746
}
109655
- if( (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
109656
- && pWInfo->pDistinct
109747
+ if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0
109748
+ && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
109749
+ && pWInfo->eDistinct==WHERE_DISTINCT_NOOP
109657109750
&& nRowEst
109658109751
){
109659109752
Bitmask notUsed;
109660
- int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pDistinct, pFrom,
109753
+ int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pResultSet, pFrom,
109661109754
WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
109662109755
if( rc==1 ) pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
109663109756
}
109664109757
if( pFrom->isOrdered ){
109665109758
if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -109744,11 +109837,13 @@
109744109837
pWInfo->a[0].pWLoop = pLoop;
109745109838
pLoop->maskSelf = getMask(&pWInfo->sMaskSet, iCur);
109746109839
pWInfo->a[0].iTabCur = iCur;
109747109840
pWInfo->nRowOut = 1;
109748109841
if( pWInfo->pOrderBy ) pWInfo->bOBSat = 1;
109749
- if( pWInfo->pDistinct ) pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
109842
+ if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){
109843
+ pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
109844
+ }
109750109845
#ifdef SQLITE_DEBUG
109751109846
pLoop->cId = '0';
109752109847
#endif
109753109848
return 1;
109754109849
}
@@ -109828,20 +109923,21 @@
109828109923
** fi
109829109924
** end
109830109925
**
109831109926
** ORDER BY CLAUSE PROCESSING
109832109927
**
109833
-** pOrderBy is a pointer to the ORDER BY clause of a SELECT statement,
109928
+** pOrderBy is a pointer to the ORDER BY clause (or the GROUP BY clause
109929
+** if the WHERE_GROUPBY flag is set in wctrlFlags) of a SELECT statement
109834109930
** if there is one. If there is no ORDER BY clause or if this routine
109835109931
** is called from an UPDATE or DELETE statement, then pOrderBy is NULL.
109836109932
*/
109837109933
SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
109838109934
Parse *pParse, /* The parser context */
109839
- SrcList *pTabList, /* A list of all tables to be scanned */
109935
+ SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
109840109936
Expr *pWhere, /* The WHERE clause */
109841109937
ExprList *pOrderBy, /* An ORDER BY clause, or NULL */
109842
- ExprList *pDistinct, /* The select-list for DISTINCT queries - or NULL */
109938
+ ExprList *pResultSet, /* Result set of the query */
109843109939
u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
109844109940
int iIdxCur /* If WHERE_ONETABLE_ONLY is set, index cursor number */
109845109941
){
109846109942
int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
109847109943
int nTabList; /* Number of elements in pTabList */
@@ -109849,18 +109945,26 @@
109849109945
Vdbe *v = pParse->pVdbe; /* The virtual database engine */
109850109946
Bitmask notReady; /* Cursors that are not yet positioned */
109851109947
WhereLoopBuilder sWLB; /* The WhereLoop builder */
109852109948
WhereMaskSet *pMaskSet; /* The expression mask set */
109853109949
WhereLevel *pLevel; /* A single level in pWInfo->a[] */
109950
+ WhereLoop *pLoop; /* Pointer to a single WhereLoop object */
109854109951
int ii; /* Loop counter */
109855109952
sqlite3 *db; /* Database connection */
109856109953
int rc; /* Return code */
109857109954
109858109955
109859109956
/* Variable initialization */
109957
+ db = pParse->db;
109860109958
memset(&sWLB, 0, sizeof(sWLB));
109861109959
sWLB.pOrderBy = pOrderBy;
109960
+
109961
+ /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
109962
+ ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */
109963
+ if( OptimizationDisabled(db, SQLITE_DistinctOpt) ){
109964
+ wctrlFlags &= ~WHERE_WANT_DISTINCT;
109965
+ }
109862109966
109863109967
/* The number of tables in the FROM clause is limited by the number of
109864109968
** bits in a Bitmask
109865109969
*/
109866109970
testcase( pTabList->nSrc==BMS );
@@ -109881,11 +109985,10 @@
109881109985
** struct, the contents of WhereInfo.a[], the WhereClause structure
109882109986
** and the WhereMaskSet structure. Since WhereClause contains an 8-byte
109883109987
** field (type Bitmask) it must be aligned on an 8-byte boundary on
109884109988
** some architectures. Hence the ROUND8() below.
109885109989
*/
109886
- db = pParse->db;
109887109990
nByteWInfo = ROUND8(sizeof(WhereInfo)+(nTabList-1)*sizeof(WhereLevel));
109888109991
pWInfo = sqlite3DbMallocZero(db, nByteWInfo + sizeof(WhereLoop));
109889109992
if( db->mallocFailed ){
109890109993
sqlite3DbFree(db, pWInfo);
109891109994
pWInfo = 0;
@@ -109893,11 +109996,11 @@
109893109996
}
109894109997
pWInfo->nLevel = nTabList;
109895109998
pWInfo->pParse = pParse;
109896109999
pWInfo->pTabList = pTabList;
109897110000
pWInfo->pOrderBy = pOrderBy;
109898
- pWInfo->pDistinct = pDistinct;
110001
+ pWInfo->pResultSet = pResultSet;
109899110002
pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
109900110003
pWInfo->wctrlFlags = wctrlFlags;
109901110004
pWInfo->savedNQueryLoop = pParse->nQueryLoop;
109902110005
pMaskSet = &pWInfo->sMaskSet;
109903110006
sWLB.pWInfo = pWInfo;
@@ -109906,21 +110009,18 @@
109906110009
whereLoopInit(sWLB.pNew);
109907110010
#ifdef SQLITE_DEBUG
109908110011
sWLB.pNew->cId = '*';
109909110012
#endif
109910110013
109911
- /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
109912
- ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */
109913
- if( OptimizationDisabled(db, SQLITE_DistinctOpt) ) pDistinct = 0;
109914
-
109915110014
/* Split the WHERE clause into separate subexpressions where each
109916110015
** subexpression is separated by an AND operator.
109917110016
*/
109918110017
initMaskSet(pMaskSet);
109919110018
whereClauseInit(&pWInfo->sWC, pWInfo);
109920110019
sqlite3ExprCodeConstants(pParse, pWhere);
109921110020
whereSplit(&pWInfo->sWC, pWhere, TK_AND); /* IMP: R-15842-53296 */
110021
+ sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
109922110022
109923110023
/* Special case: a WHERE clause that is constant. Evaluate the
109924110024
** expression and either jump over all of the code or fall thru.
109925110025
*/
109926110026
if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){
@@ -109930,11 +110030,13 @@
109930110030
109931110031
/* Special case: No FROM clause
109932110032
*/
109933110033
if( nTabList==0 ){
109934110034
if( pOrderBy ) pWInfo->bOBSat = 1;
109935
- if( pDistinct ) pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
110035
+ if( wctrlFlags & WHERE_WANT_DISTINCT ){
110036
+ pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
110037
+ }
109936110038
}
109937110039
109938110040
/* Assign a bit from the bitmask to every term in the FROM clause.
109939110041
**
109940110042
** When assigning bitmask values to FROM clause cursors, it must be
@@ -109977,11 +110079,11 @@
109977110079
109978110080
/* If the ORDER BY (or GROUP BY) clause contains references to general
109979110081
** expressions, then we won't be able to satisfy it using indices, so
109980110082
** go ahead and disable it now.
109981110083
*/
109982
- if( pOrderBy && pDistinct ){
110084
+ if( pOrderBy && (wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
109983110085
for(ii=0; ii<pOrderBy->nExpr; ii++){
109984110086
Expr *pExpr = sqlite3ExprSkipCollate(pOrderBy->a[ii].pExpr);
109985110087
if( pExpr->op!=TK_COLUMN ){
109986110088
pWInfo->pOrderBy = pOrderBy = 0;
109987110089
break;
@@ -109989,21 +110091,18 @@
109989110091
break;
109990110092
}
109991110093
}
109992110094
}
109993110095
109994
- /* Check if the DISTINCT qualifier, if there is one, is redundant.
109995
- ** If it is, then set pDistinct to NULL and WhereInfo.eDistinct to
109996
- ** WHERE_DISTINCT_UNIQUE to tell the caller to ignore the DISTINCT.
109997
- */
109998
- if( pDistinct ){
109999
- if( isDistinctRedundant(pParse,pTabList,&pWInfo->sWC,pDistinct) ){
110000
- pDistinct = 0;
110096
+ if( wctrlFlags & WHERE_WANT_DISTINCT ){
110097
+ if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
110098
+ /* The DISTINCT marking is pointless. Ignore it. */
110001110099
pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
110002110100
}else if( pOrderBy==0 ){
110101
+ /* Try to ORDER BY the result set to make distinct processing easier */
110003110102
pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
110004
- pWInfo->pOrderBy = pDistinct;
110103
+ pWInfo->pOrderBy = pResultSet;
110005110104
}
110006110105
}
110007110106
110008110107
/* Construct the WhereLoop objects */
110009110108
WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
@@ -110013,15 +110112,15 @@
110013110112
110014110113
/* Display all of the WhereLoop objects if wheretrace is enabled */
110015110114
#ifdef WHERETRACE_ENABLED
110016110115
if( sqlite3WhereTrace ){
110017110116
WhereLoop *p;
110018
- int i = 0;
110117
+ int i;
110019110118
static char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
110020110119
"ABCDEFGHIJKLMNOPQRSTUVWYXZ";
110021
- for(p=pWInfo->pLoops; p; p=p->pNextLoop){
110022
- p->cId = zLabel[(i++)%sizeof(zLabel)];
110120
+ for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
110121
+ p->cId = zLabel[i%sizeof(zLabel)];
110023110122
whereLoopPrint(p, pTabList);
110024110123
}
110025110124
}
110026110125
#endif
110027110126
@@ -110058,15 +110157,46 @@
110058110157
sqlite3DebugPrintf(" DISTINCT=unordered");
110059110158
break;
110060110159
}
110061110160
}
110062110161
sqlite3DebugPrintf("\n");
110063
- for(ii=0; ii<nTabList; ii++){
110162
+ for(ii=0; ii<pWInfo->nLevel; ii++){
110064110163
whereLoopPrint(pWInfo->a[ii].pWLoop, pTabList);
110065110164
}
110066110165
}
110067110166
#endif
110167
+ /* Attempt to omit tables from the join that do not effect the result */
110168
+ if( pWInfo->nLevel>=2
110169
+ && pResultSet!=0
110170
+ && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
110171
+ ){
110172
+ Bitmask tabUsed = exprListTableUsage(pMaskSet, pResultSet);
110173
+ if( pOrderBy ) tabUsed |= exprListTableUsage(pMaskSet, pOrderBy);
110174
+ while( pWInfo->nLevel>=2 ){
110175
+ WhereTerm *pTerm, *pEnd;
110176
+ pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop;
110177
+ if( (pWInfo->pTabList->a[pLoop->iTab].jointype & JT_LEFT)==0 ) break;
110178
+ if( (wctrlFlags & WHERE_WANT_DISTINCT)==0
110179
+ && (pLoop->wsFlags & WHERE_ONEROW)==0
110180
+ ){
110181
+ break;
110182
+ }
110183
+ if( (tabUsed & pLoop->maskSelf)!=0 ) break;
110184
+ pEnd = sWLB.pWC->a + sWLB.pWC->nTerm;
110185
+ for(pTerm=sWLB.pWC->a; pTerm<pEnd; pTerm++){
110186
+ if( (pTerm->prereqAll & pLoop->maskSelf)!=0
110187
+ && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
110188
+ ){
110189
+ break;
110190
+ }
110191
+ }
110192
+ if( pTerm<pEnd ) break;
110193
+ WHERETRACE(0xffff, ("-> drop loop %c not used\n", pLoop->cId));
110194
+ pWInfo->nLevel--;
110195
+ nTabList--;
110196
+ }
110197
+ }
110068110198
WHERETRACE(0xffff,("*** Optimizer Finished ***\n"));
110069110199
pWInfo->pParse->nQueryLoop += pWInfo->nRowOut;
110070110200
110071110201
/* If the caller is an UPDATE or DELETE statement that is requesting
110072110202
** to use a one-pass algorithm, determine if this is appropriate.
@@ -110081,17 +110211,15 @@
110081110211
}
110082110212
110083110213
/* Open all tables in the pTabList and any indices selected for
110084110214
** searching those tables.
110085110215
*/
110086
- sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
110087110216
notReady = ~(Bitmask)0;
110088110217
for(ii=0, pLevel=pWInfo->a; ii<nTabList; ii++, pLevel++){
110089110218
Table *pTab; /* Table to open */
110090110219
int iDb; /* Index of database containing table/index */
110091110220
struct SrcList_item *pTabItem;
110092
- WhereLoop *pLoop;
110093110221
110094110222
pTabItem = &pTabList->a[pLevel->iFrom];
110095110223
pTab = pTabItem->pTab;
110096110224
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
110097110225
pLoop = pLevel->pWLoop;
@@ -110123,11 +110251,11 @@
110123110251
}
110124110252
}else{
110125110253
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
110126110254
}
110127110255
#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
110128
- if( (pLoop->wsFlags & WHERE_TEMP_INDEX)!=0 ){
110256
+ if( (pLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){
110129110257
constructAutomaticIndex(pParse, &pWInfo->sWC, pTabItem, notReady, pLevel);
110130110258
}else
110131110259
#endif
110132110260
if( pLoop->wsFlags & WHERE_INDEXED ){
110133110261
Index *pIx = pLoop->u.btree.pIndex;
@@ -110231,11 +110359,11 @@
110231110359
*/
110232110360
sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
110233110361
110234110362
/* Close all of the cursors that were opened by sqlite3WhereBegin.
110235110363
*/
110236
- assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc );
110364
+ assert( pWInfo->nLevel<=pTabList->nSrc );
110237110365
for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
110238110366
Index *pIdx = 0;
110239110367
struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
110240110368
Table *pTab = pTabItem->pTab;
110241110369
assert( pTab!=0 );
@@ -110246,11 +110374,11 @@
110246110374
){
110247110375
int ws = pLoop->wsFlags;
110248110376
if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
110249110377
sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
110250110378
}
110251
- if( (ws & WHERE_INDEXED)!=0 && (ws & (WHERE_IPK|WHERE_TEMP_INDEX))==0 ){
110379
+ if( (ws & WHERE_INDEXED)!=0 && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0 ){
110252110380
sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
110253110381
}
110254110382
}
110255110383
110256110384
/* If this scan uses an index, make VDBE code substitutions to read data
@@ -114457,11 +114585,11 @@
114457114585
sqlite3 *db = pParse->db; /* The database connection */
114458114586
int mxSqlLen; /* Max length of an SQL string */
114459114587
114460114588
114461114589
mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
114462
- if( db->activeVdbeCnt==0 ){
114590
+ if( db->nVdbeActive==0 ){
114463114591
db->u1.isInterrupted = 0;
114464114592
}
114465114593
pParse->rc = SQLITE_OK;
114466114594
pParse->zTail = zSql;
114467114595
i = 0;
@@ -116025,10 +116153,11 @@
116025116153
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
116026116154
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
116027116155
case SQLITE_ABORT_ROLLBACK: zName = "SQLITE_ABORT_ROLLBACK"; break;
116028116156
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
116029116157
case SQLITE_BUSY_RECOVERY: zName = "SQLITE_BUSY_RECOVERY"; break;
116158
+ case SQLITE_BUSY_SNAPSHOT: zName = "SQLITE_BUSY_SNAPSHOT"; break;
116030116159
case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break;
116031116160
case SQLITE_LOCKED_SHAREDCACHE: zName = "SQLITE_LOCKED_SHAREDCACHE";break;
116032116161
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
116033116162
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
116034116163
case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
@@ -116098,10 +116227,11 @@
116098116227
case SQLITE_NOTICE: zName = "SQLITE_NOTICE"; break;
116099116228
case SQLITE_NOTICE_RECOVER_WAL: zName = "SQLITE_NOTICE_RECOVER_WAL";break;
116100116229
case SQLITE_NOTICE_RECOVER_ROLLBACK:
116101116230
zName = "SQLITE_NOTICE_RECOVER_ROLLBACK"; break;
116102116231
case SQLITE_WARNING: zName = "SQLITE_WARNING"; break;
116232
+ case SQLITE_WARNING_AUTOINDEX: zName = "SQLITE_WARNING_AUTOINDEX"; break;
116103116233
case SQLITE_DONE: zName = "SQLITE_DONE"; break;
116104116234
}
116105116235
}
116106116236
if( zName==0 ){
116107116237
static char zBuf[50];
@@ -116356,11 +116486,11 @@
116356116486
** is being overridden/deleted but there are no active VMs, allow the
116357116487
** operation to continue but invalidate all precompiled statements.
116358116488
*/
116359116489
p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
116360116490
if( p && p->iPrefEnc==enc && p->nArg==nArg ){
116361
- if( db->activeVdbeCnt ){
116491
+ if( db->nVdbeActive ){
116362116492
sqlite3Error(db, SQLITE_BUSY,
116363116493
"unable to delete/modify user-function due to active statements");
116364116494
assert( !db->mallocFailed );
116365116495
return SQLITE_BUSY;
116366116496
}else{
@@ -116937,11 +117067,11 @@
116937117067
** sequence. If so, and there are active VMs, return busy. If there
116938117068
** are no active VMs, invalidate any pre-compiled statements.
116939117069
*/
116940117070
pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
116941117071
if( pColl && pColl->xCmp ){
116942
- if( db->activeVdbeCnt ){
117072
+ if( db->nVdbeActive ){
116943117073
sqlite3Error(db, SQLITE_BUSY,
116944117074
"unable to delete/modify collation sequence due to active statements");
116945117075
return SQLITE_BUSY;
116946117076
}
116947117077
sqlite3ExpirePreparedStatements(db);
@@ -117412,11 +117542,14 @@
117412117542
memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
117413117543
db->autoCommit = 1;
117414117544
db->nextAutovac = -1;
117415117545
db->szMmap = sqlite3GlobalConfig.szMmap;
117416117546
db->nextPagesize = 0;
117417
- db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex | SQLITE_EnableTrigger
117547
+ db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger
117548
+#if !defined(SQLITE_DEAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
117549
+ | SQLITE_AutoIndex
117550
+#endif
117418117551
#if SQLITE_DEFAULT_FILE_FORMAT<4
117419117552
| SQLITE_LegacyFileFmt
117420117553
#endif
117421117554
#ifdef SQLITE_ENABLE_LOAD_EXTENSION
117422117555
| SQLITE_LoadExtension
@@ -119407,10 +119540,11 @@
119407119540
sqlite3 *db; /* The database connection */
119408119541
const char *zDb; /* logical database name */
119409119542
const char *zName; /* virtual table name */
119410119543
int nColumn; /* number of named columns in virtual table */
119411119544
char **azColumn; /* column names. malloced */
119545
+ u8 *abNotindexed; /* True for 'notindexed' columns */
119412119546
sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */
119413119547
char *zContentTbl; /* content=xxx option, or NULL */
119414119548
char *zLanguageid; /* languageid=xxx option, or NULL */
119415119549
u8 bAutoincrmerge; /* True if automerge=1 */
119416119550
u32 nLeafAdd; /* Number of leaf blocks added this trans */
@@ -119634,11 +119768,10 @@
119634119768
sqlite3_int64, sqlite3_int64, const char *, int, Fts3SegReader**);
119635119769
SQLITE_PRIVATE int sqlite3Fts3SegReaderPending(
119636119770
Fts3Table*,int,const char*,int,int,Fts3SegReader**);
119637119771
SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *);
119638119772
SQLITE_PRIVATE int sqlite3Fts3AllSegdirs(Fts3Table*, int, int, int, sqlite3_stmt **);
119639
-SQLITE_PRIVATE int sqlite3Fts3ReadLock(Fts3Table *);
119640119773
SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*);
119641119774
119642119775
SQLITE_PRIVATE int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **);
119643119776
SQLITE_PRIVATE int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **);
119644119777
@@ -120567,22 +120700,34 @@
120567120700
char *zPrefix = 0; /* Prefix parameter value (or NULL) */
120568120701
char *zCompress = 0; /* compress=? parameter (or NULL) */
120569120702
char *zUncompress = 0; /* uncompress=? parameter (or NULL) */
120570120703
char *zContent = 0; /* content=? parameter (or NULL) */
120571120704
char *zLanguageid = 0; /* languageid=? parameter (or NULL) */
120705
+ char **azNotindexed = 0; /* The set of notindexed= columns */
120706
+ int nNotindexed = 0; /* Size of azNotindexed[] array */
120572120707
120573120708
assert( strlen(argv[0])==4 );
120574120709
assert( (sqlite3_strnicmp(argv[0], "fts4", 4)==0 && isFts4)
120575120710
|| (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4)
120576120711
);
120577120712
120578120713
nDb = (int)strlen(argv[1]) + 1;
120579120714
nName = (int)strlen(argv[2]) + 1;
120580120715
120581
- aCol = (const char **)sqlite3_malloc(sizeof(const char *) * (argc-2) );
120582
- if( !aCol ) return SQLITE_NOMEM;
120583
- memset((void *)aCol, 0, sizeof(const char *) * (argc-2));
120716
+ nByte = sizeof(const char *) * (argc-2);
120717
+ aCol = (const char **)sqlite3_malloc(nByte);
120718
+ if( aCol ){
120719
+ memset((void*)aCol, 0, nByte);
120720
+ azNotindexed = (char **)sqlite3_malloc(nByte);
120721
+ }
120722
+ if( azNotindexed ){
120723
+ memset(azNotindexed, 0, nByte);
120724
+ }
120725
+ if( !aCol || !azNotindexed ){
120726
+ rc = SQLITE_NOMEM;
120727
+ goto fts3_init_out;
120728
+ }
120584120729
120585120730
/* Loop through all of the arguments passed by the user to the FTS3/4
120586120731
** module (i.e. all the column names and special arguments). This loop
120587120732
** does the following:
120588120733
**
@@ -120617,11 +120762,12 @@
120617120762
{ "prefix", 6 }, /* 1 -> PREFIX */
120618120763
{ "compress", 8 }, /* 2 -> COMPRESS */
120619120764
{ "uncompress", 10 }, /* 3 -> UNCOMPRESS */
120620120765
{ "order", 5 }, /* 4 -> ORDER */
120621120766
{ "content", 7 }, /* 5 -> CONTENT */
120622
- { "languageid", 10 } /* 6 -> LANGUAGEID */
120767
+ { "languageid", 10 }, /* 6 -> LANGUAGEID */
120768
+ { "notindexed", 10 } /* 7 -> NOTINDEXED */
120623120769
};
120624120770
120625120771
int iOpt;
120626120772
if( !zVal ){
120627120773
rc = SQLITE_NOMEM;
@@ -120683,10 +120829,15 @@
120683120829
assert( iOpt==6 );
120684120830
sqlite3_free(zLanguageid);
120685120831
zLanguageid = zVal;
120686120832
zVal = 0;
120687120833
break;
120834
+
120835
+ case 7: /* NOTINDEXED */
120836
+ azNotindexed[nNotindexed++] = zVal;
120837
+ zVal = 0;
120838
+ break;
120688120839
}
120689120840
}
120690120841
sqlite3_free(zVal);
120691120842
}
120692120843
}
@@ -120754,10 +120905,11 @@
120754120905
120755120906
/* Allocate and populate the Fts3Table structure. */
120756120907
nByte = sizeof(Fts3Table) + /* Fts3Table */
120757120908
nCol * sizeof(char *) + /* azColumn */
120758120909
nIndex * sizeof(struct Fts3Index) + /* aIndex */
120910
+ nCol * sizeof(u8) + /* abNotindexed */
120759120911
nName + /* zName */
120760120912
nDb + /* zDb */
120761120913
nString; /* Space for azColumn strings */
120762120914
p = (Fts3Table*)sqlite3_malloc(nByte);
120763120915
if( p==0 ){
@@ -120787,13 +120939,14 @@
120787120939
memcpy(p->aIndex, aIndex, sizeof(struct Fts3Index) * nIndex);
120788120940
p->nIndex = nIndex;
120789120941
for(i=0; i<nIndex; i++){
120790120942
fts3HashInit(&p->aIndex[i].hPending, FTS3_HASH_STRING, 1);
120791120943
}
120944
+ p->abNotindexed = (u8 *)&p->aIndex[nIndex];
120792120945
120793120946
/* Fill in the zName and zDb fields of the vtab structure. */
120794
- zCsr = (char *)&p->aIndex[nIndex];
120947
+ zCsr = (char *)&p->abNotindexed[nCol];
120795120948
p->zName = zCsr;
120796120949
memcpy(zCsr, argv[2], nName);
120797120950
zCsr += nName;
120798120951
p->zDb = zCsr;
120799120952
memcpy(zCsr, argv[1], nDb);
@@ -120810,11 +120963,30 @@
120810120963
p->azColumn[iCol] = zCsr;
120811120964
zCsr += n+1;
120812120965
assert( zCsr <= &((char *)p)[nByte] );
120813120966
}
120814120967
120815
- if( (zCompress==0)!=(zUncompress==0) ){
120968
+ /* Fill in the abNotindexed array */
120969
+ for(iCol=0; iCol<nCol; iCol++){
120970
+ int n = (int)strlen(p->azColumn[iCol]);
120971
+ for(i=0; i<nNotindexed; i++){
120972
+ char *zNot = azNotindexed[i];
120973
+ if( zNot && 0==sqlite3_strnicmp(p->azColumn[iCol], zNot, n) ){
120974
+ p->abNotindexed[iCol] = 1;
120975
+ sqlite3_free(zNot);
120976
+ azNotindexed[i] = 0;
120977
+ }
120978
+ }
120979
+ }
120980
+ for(i=0; i<nNotindexed; i++){
120981
+ if( azNotindexed[i] ){
120982
+ *pzErr = sqlite3_mprintf("no such column: %s", azNotindexed[i]);
120983
+ rc = SQLITE_ERROR;
120984
+ }
120985
+ }
120986
+
120987
+ if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
120816120988
char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
120817120989
rc = SQLITE_ERROR;
120818120990
*pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
120819120991
}
120820120992
p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
@@ -120851,11 +121023,13 @@
120851121023
sqlite3_free(aIndex);
120852121024
sqlite3_free(zCompress);
120853121025
sqlite3_free(zUncompress);
120854121026
sqlite3_free(zContent);
120855121027
sqlite3_free(zLanguageid);
121028
+ for(i=0; i<nNotindexed; i++) sqlite3_free(azNotindexed[i]);
120856121029
sqlite3_free((void *)aCol);
121030
+ sqlite3_free((void *)azNotindexed);
120857121031
if( rc!=SQLITE_OK ){
120858121032
if( p ){
120859121033
fts3DisconnectMethod((sqlite3_vtab *)p);
120860121034
}else if( pTokenizer ){
120861121035
pTokenizer->pModule->xDestroy(pTokenizer);
@@ -129717,16 +129891,19 @@
129717129891
sqlite3_value **apVal,
129718129892
u32 *aSz
129719129893
){
129720129894
int i; /* Iterator variable */
129721129895
for(i=2; i<p->nColumn+2; i++){
129722
- const char *zText = (const char *)sqlite3_value_text(apVal[i]);
129723
- int rc = fts3PendingTermsAdd(p, iLangid, zText, i-2, &aSz[i-2]);
129724
- if( rc!=SQLITE_OK ){
129725
- return rc;
129896
+ int iCol = i-2;
129897
+ if( p->abNotindexed[iCol]==0 ){
129898
+ const char *zText = (const char *)sqlite3_value_text(apVal[i]);
129899
+ int rc = fts3PendingTermsAdd(p, iLangid, zText, iCol, &aSz[iCol]);
129900
+ if( rc!=SQLITE_OK ){
129901
+ return rc;
129902
+ }
129903
+ aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]);
129726129904
}
129727
- aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]);
129728129905
}
129729129906
return SQLITE_OK;
129730129907
}
129731129908
129732129909
/*
@@ -129869,13 +130046,16 @@
129869130046
if( SQLITE_ROW==sqlite3_step(pSelect) ){
129870130047
int i;
129871130048
int iLangid = langidFromSelect(p, pSelect);
129872130049
rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pSelect, 0));
129873130050
for(i=1; rc==SQLITE_OK && i<=p->nColumn; i++){
129874
- const char *zText = (const char *)sqlite3_column_text(pSelect, i);
129875
- rc = fts3PendingTermsAdd(p, iLangid, zText, -1, &aSz[i-1]);
129876
- aSz[p->nColumn] += sqlite3_column_bytes(pSelect, i);
130051
+ int iCol = i-1;
130052
+ if( p->abNotindexed[iCol]==0 ){
130053
+ const char *zText = (const char *)sqlite3_column_text(pSelect, i);
130054
+ rc = fts3PendingTermsAdd(p, iLangid, zText, -1, &aSz[iCol]);
130055
+ aSz[p->nColumn] += sqlite3_column_bytes(pSelect, i);
130056
+ }
129877130057
}
129878130058
if( rc!=SQLITE_OK ){
129879130059
sqlite3_reset(pSelect);
129880130060
*pRC = rc;
129881130061
return;
@@ -132113,13 +132293,15 @@
132113132293
int iCol;
132114132294
int iLangid = langidFromSelect(p, pStmt);
132115132295
rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pStmt, 0));
132116132296
memset(aSz, 0, sizeof(aSz[0]) * (p->nColumn+1));
132117132297
for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){
132118
- const char *z = (const char *) sqlite3_column_text(pStmt, iCol+1);
132119
- rc = fts3PendingTermsAdd(p, iLangid, z, iCol, &aSz[iCol]);
132120
- aSz[p->nColumn] += sqlite3_column_bytes(pStmt, iCol+1);
132298
+ if( p->abNotindexed[iCol]==0 ){
132299
+ const char *z = (const char *) sqlite3_column_text(pStmt, iCol+1);
132300
+ rc = fts3PendingTermsAdd(p, iLangid, z, iCol, &aSz[iCol]);
132301
+ aSz[p->nColumn] += sqlite3_column_bytes(pStmt, iCol+1);
132302
+ }
132121132303
}
132122132304
if( p->bHasDocsize ){
132123132305
fts3InsertDocsize(&rc, p, aSz);
132124132306
}
132125132307
if( rc!=SQLITE_OK ){
@@ -133918,39 +134100,41 @@
133918134100
133919134101
assert( pCsr->isRequireSeek==0 );
133920134102
iDocid = sqlite3_column_int64(pCsr->pStmt, 0);
133921134103
133922134104
for(i=0; i<p->nColumn && rc==SQLITE_OK; i++){
133923
- const char *zText = (const char *)sqlite3_column_text(pCsr->pStmt, i+1);
133924
- sqlite3_tokenizer_cursor *pTC = 0;
133925
-
133926
- rc = sqlite3Fts3OpenTokenizer(pT, pCsr->iLangid, zText, -1, &pTC);
133927
- while( rc==SQLITE_OK ){
133928
- char const *zToken; /* Buffer containing token */
133929
- int nToken = 0; /* Number of bytes in token */
133930
- int iDum1 = 0, iDum2 = 0; /* Dummy variables */
133931
- int iPos = 0; /* Position of token in zText */
133932
-
133933
- rc = pModule->xNext(pTC, &zToken, &nToken, &iDum1, &iDum2, &iPos);
133934
- for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
133935
- Fts3PhraseToken *pPT = pDef->pToken;
133936
- if( (pDef->iCol>=p->nColumn || pDef->iCol==i)
133937
- && (pPT->bFirst==0 || iPos==0)
133938
- && (pPT->n==nToken || (pPT->isPrefix && pPT->n<nToken))
133939
- && (0==memcmp(zToken, pPT->z, pPT->n))
133940
- ){
133941
- fts3PendingListAppend(&pDef->pList, iDocid, i, iPos, &rc);
133942
- }
133943
- }
133944
- }
133945
- if( pTC ) pModule->xClose(pTC);
133946
- if( rc==SQLITE_DONE ) rc = SQLITE_OK;
133947
- }
133948
-
133949
- for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
133950
- if( pDef->pList ){
133951
- rc = fts3PendingListAppendVarint(&pDef->pList, 0);
134105
+ if( p->abNotindexed[i]==0 ){
134106
+ const char *zText = (const char *)sqlite3_column_text(pCsr->pStmt, i+1);
134107
+ sqlite3_tokenizer_cursor *pTC = 0;
134108
+
134109
+ rc = sqlite3Fts3OpenTokenizer(pT, pCsr->iLangid, zText, -1, &pTC);
134110
+ while( rc==SQLITE_OK ){
134111
+ char const *zToken; /* Buffer containing token */
134112
+ int nToken = 0; /* Number of bytes in token */
134113
+ int iDum1 = 0, iDum2 = 0; /* Dummy variables */
134114
+ int iPos = 0; /* Position of token in zText */
134115
+
134116
+ rc = pModule->xNext(pTC, &zToken, &nToken, &iDum1, &iDum2, &iPos);
134117
+ for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
134118
+ Fts3PhraseToken *pPT = pDef->pToken;
134119
+ if( (pDef->iCol>=p->nColumn || pDef->iCol==i)
134120
+ && (pPT->bFirst==0 || iPos==0)
134121
+ && (pPT->n==nToken || (pPT->isPrefix && pPT->n<nToken))
134122
+ && (0==memcmp(zToken, pPT->z, pPT->n))
134123
+ ){
134124
+ fts3PendingListAppend(&pDef->pList, iDocid, i, iPos, &rc);
134125
+ }
134126
+ }
134127
+ }
134128
+ if( pTC ) pModule->xClose(pTC);
134129
+ if( rc==SQLITE_DONE ) rc = SQLITE_OK;
134130
+ }
134131
+
134132
+ for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
134133
+ if( pDef->pList ){
134134
+ rc = fts3PendingListAppendVarint(&pDef->pList, 0);
134135
+ }
133952134136
}
133953134137
}
133954134138
}
133955134139
133956134140
return rc;
133957134141
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.7.17. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -668,13 +668,13 @@
668 **
669 ** See also: [sqlite3_libversion()],
670 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671 ** [sqlite_version()] and [sqlite_source_id()].
672 */
673 #define SQLITE_VERSION "3.7.17"
674 #define SQLITE_VERSION_NUMBER 3007017
675 #define SQLITE_SOURCE_ID "2013-06-20 14:17:39 d94db3fd921890ab1d6414ab629410ae50779686"
676
677 /*
678 ** CAPI3REF: Run-Time Library Version Numbers
679 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
680 **
@@ -1041,10 +1041,11 @@
1041 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
1042 #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
1043 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
1044 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
1045 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
 
1046 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
1047 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
1048 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
1049 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
1050 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
@@ -1060,10 +1061,11 @@
1060 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
1061 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
1062 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
1063 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
1064 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
 
1065
1066 /*
1067 ** CAPI3REF: Flags For File Open Operations
1068 **
1069 ** These bit values are intended for use in the
@@ -6869,15 +6871,25 @@
6869 ** <dd>^This is the number of rows inserted into transient indices that
6870 ** were created automatically in order to help joins run faster.
6871 ** A non-zero value in this counter may indicate an opportunity to
6872 ** improvement performance by adding permanent indices that do not
6873 ** need to be reinitialized each time the statement is run.</dd>
 
 
 
 
 
 
 
 
 
6874 ** </dl>
6875 */
6876 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
6877 #define SQLITE_STMTSTATUS_SORT 2
6878 #define SQLITE_STMTSTATUS_AUTOINDEX 3
 
6879
6880 /*
6881 ** CAPI3REF: Custom Page Cache Object
6882 **
6883 ** The sqlite3_pcache type is opaque. It is implemented by
@@ -10066,13 +10078,14 @@
10066 int newTnum; /* Rootpage of table being initialized */
10067 u8 iDb; /* Which db file is being initialized */
10068 u8 busy; /* TRUE if currently initializing */
10069 u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */
10070 } init;
10071 int activeVdbeCnt; /* Number of VDBEs currently executing */
10072 int writeVdbeCnt; /* Number of active VDBEs that are writing */
10073 int vdbeExecCnt; /* Number of nested calls to VdbeExec() */
 
10074 int nExtension; /* Number of loaded extensions */
10075 void **aExtension; /* Array of shared library handles */
10076 void (*xTrace)(void*,const char*); /* Trace function */
10077 void *pTraceArg; /* Argument to the trace function */
10078 void (*xProfile)(void*,const char*,u64); /* Profiling function */
@@ -10193,10 +10206,12 @@
10193 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
10194 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
10195 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10196 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10197 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
 
 
10198 #define SQLITE_AllOpts 0xffff /* All optimizations */
10199
10200 /*
10201 ** Macros for testing whether or not optimizations are enabled or disabled.
10202 */
@@ -11143,10 +11158,11 @@
11143 #define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
11144 #define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
11145 #define WHERE_AND_ONLY 0x0080 /* Don't use indices for OR terms */
11146 #define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
11147 #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
 
11148
11149 /* Allowed return values from sqlite3WhereIsDistinct()
11150 */
11151 #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
11152 #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */
@@ -13500,18 +13516,19 @@
13500 bft inVtabMethod:2; /* See comments above */
13501 bft changeCntOn:1; /* True to update the change-counter */
13502 bft expired:1; /* True if the VM needs to be recompiled */
13503 bft runOnlyOnce:1; /* Automatically expire on reset */
13504 bft usesStmtJournal:1; /* True if uses a statement journal */
13505 bft readOnly:1; /* True for read-only statements */
 
13506 bft isPrepareV2:1; /* True if prepared with prepare_v2() */
13507 bft doingRerun:1; /* True if rerunning after an auto-reprepare */
13508 int nChange; /* Number of db changes made since last reset */
13509 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
13510 yDbMask lockMask; /* Subset of btreeMask that requires a lock */
13511 int iStatement; /* Statement number (or 0 if has not opened stmt) */
13512 int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
13513 #ifndef SQLITE_OMIT_TRACE
13514 i64 startTime; /* Time when query started - used for profiling */
13515 #endif
13516 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
13517 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
@@ -19937,12 +19954,12 @@
19937 if( xtype==etEXP ){
19938 e2 = 0;
19939 }else{
19940 e2 = exp;
19941 }
19942 if( e2+precision+width > etBUFSIZE - 15 ){
19943 bufpt = zExtra = sqlite3Malloc( e2+precision+width+15 );
19944 if( bufpt==0 ){
19945 pAccum->mallocFailed = 1;
19946 return;
19947 }
19948 }
@@ -40058,10 +40075,11 @@
40058 assert( !MEMDB );
40059 pager_reset(pPager);
40060 pPager->changeCountDone = pPager->tempFile;
40061 pPager->eState = PAGER_OPEN;
40062 pPager->errCode = SQLITE_OK;
 
40063 }
40064
40065 pPager->journalOff = 0;
40066 pPager->journalHdr = 0;
40067 pPager->setMaster = 0;
@@ -41624,14 +41642,14 @@
41624 ** Invoke SQLITE_FCNTL_MMAP_SIZE based on the current value of szMmap.
41625 */
41626 static void pagerFixMaplimit(Pager *pPager){
41627 #if SQLITE_MAX_MMAP_SIZE>0
41628 sqlite3_file *fd = pPager->fd;
41629 if( isOpen(fd) ){
41630 sqlite3_int64 sz;
41631 pPager->bUseFetch = (fd->pMethods->iVersion>=3) && pPager->szMmap>0;
41632 sz = pPager->szMmap;
 
41633 sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_SIZE, &sz);
41634 }
41635 #endif
41636 }
41637
@@ -47879,11 +47897,11 @@
47879 ** the write is disallowed.
47880 */
47881 if( memcmp(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr))!=0 ){
47882 walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1);
47883 pWal->writeLock = 0;
47884 rc = SQLITE_BUSY;
47885 }
47886
47887 return rc;
47888 }
47889
@@ -52739,16 +52757,17 @@
52739 ** This function is called from both BtreeCommitPhaseTwo() and BtreeRollback()
52740 ** at the conclusion of a transaction.
52741 */
52742 static void btreeEndTransaction(Btree *p){
52743 BtShared *pBt = p->pBt;
 
52744 assert( sqlite3BtreeHoldsMutex(p) );
52745
52746 #ifndef SQLITE_OMIT_AUTOVACUUM
52747 pBt->bDoTruncate = 0;
52748 #endif
52749 if( p->inTrans>TRANS_NONE && p->db->activeVdbeCnt>1 ){
52750 /* If there are other active statements that belong to this database
52751 ** handle, downgrade to a read-only transaction. The other statements
52752 ** may still be reading from the database. */
52753 downgradeAllSharedCacheTableLocks(p);
52754 p->inTrans = TRANS_READ;
@@ -60265,18 +60284,30 @@
60265 int i;
60266 int nMaxArgs = *pMaxFuncArgs;
60267 Op *pOp;
60268 int *aLabel = p->aLabel;
60269 p->readOnly = 1;
 
60270 for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
60271 u8 opcode = pOp->opcode;
60272
60273 pOp->opflags = sqlite3OpcodeProperty[opcode];
60274 if( opcode==OP_Function || opcode==OP_AggStep ){
60275 if( pOp->p5>nMaxArgs ) nMaxArgs = pOp->p5;
60276 }else if( (opcode==OP_Transaction && pOp->p2!=0) || opcode==OP_Vacuum ){
 
 
 
 
 
 
 
 
 
 
60277 p->readOnly = 0;
 
60278 #ifndef SQLITE_OMIT_VIRTUALTABLE
60279 }else if( opcode==OP_VUpdate ){
60280 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
60281 }else if( opcode==OP_VFilter ){
60282 int n;
@@ -60298,12 +60329,12 @@
60298 pOp->p2 = aLabel[-1-pOp->p2];
60299 }
60300 }
60301 sqlite3DbFree(p->db, p->aLabel);
60302 p->aLabel = 0;
60303
60304 *pMaxFuncArgs = nMaxArgs;
 
60305 }
60306
60307 /*
60308 ** Return the address of the next instruction to be inserted.
60309 */
@@ -61825,11 +61856,11 @@
61825
61826 return rc;
61827 }
61828
61829 /*
61830 ** This routine checks that the sqlite3.activeVdbeCnt count variable
61831 ** matches the number of vdbe's in the list sqlite3.pVdbe that are
61832 ** currently active. An assertion fails if the two counts do not match.
61833 ** This is an internal self-check only - it is not an essential processing
61834 ** step.
61835 **
@@ -61838,20 +61869,23 @@
61838 #ifndef NDEBUG
61839 static void checkActiveVdbeCnt(sqlite3 *db){
61840 Vdbe *p;
61841 int cnt = 0;
61842 int nWrite = 0;
 
61843 p = db->pVdbe;
61844 while( p ){
61845 if( p->magic==VDBE_MAGIC_RUN && p->pc>=0 ){
61846 cnt++;
61847 if( p->readOnly==0 ) nWrite++;
 
61848 }
61849 p = p->pNext;
61850 }
61851 assert( cnt==db->activeVdbeCnt );
61852 assert( nWrite==db->writeVdbeCnt );
 
61853 }
61854 #else
61855 #define checkActiveVdbeCnt(x)
61856 #endif
61857
@@ -61983,12 +62017,13 @@
61983 if( p->magic!=VDBE_MAGIC_RUN ){
61984 return SQLITE_OK;
61985 }
61986 checkActiveVdbeCnt(db);
61987
61988 /* No commit or rollback needed if the program never started */
61989 if( p->pc>=0 ){
 
61990 int mrc; /* Primary error code from p->rc */
61991 int eStatementOp = 0;
61992 int isSpecialError; /* Set to true if a 'special' error */
61993
61994 /* Lock all btrees used by the statement */
@@ -62037,11 +62072,11 @@
62037 ** Note: This block also runs if one of the special errors handled
62038 ** above has occurred.
62039 */
62040 if( !sqlite3VtabInSync(db)
62041 && db->autoCommit
62042 && db->writeVdbeCnt==(p->readOnly==0)
62043 ){
62044 if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){
62045 rc = sqlite3VdbeCheckFk(p, 1);
62046 if( rc!=SQLITE_OK ){
62047 if( NEVER(p->readOnly) ){
@@ -62118,15 +62153,16 @@
62118 sqlite3VdbeLeave(p);
62119 }
62120
62121 /* We have successfully halted and closed the VM. Record this fact. */
62122 if( p->pc>=0 ){
62123 db->activeVdbeCnt--;
62124 if( !p->readOnly ){
62125 db->writeVdbeCnt--;
62126 }
62127 assert( db->activeVdbeCnt>=db->writeVdbeCnt );
 
62128 }
62129 p->magic = VDBE_MAGIC_HALT;
62130 checkActiveVdbeCnt(db);
62131 if( p->db->mallocFailed ){
62132 p->rc = SQLITE_NOMEM;
@@ -62138,11 +62174,11 @@
62138 */
62139 if( db->autoCommit ){
62140 sqlite3ConnectionUnlocked(db);
62141 }
62142
62143 assert( db->activeVdbeCnt>0 || db->autoCommit==0 || db->nStatement==0 );
62144 return (p->rc==SQLITE_BUSY ? SQLITE_BUSY : SQLITE_OK);
62145 }
62146
62147
62148 /*
@@ -63496,35 +63532,36 @@
63496 if( p->pc<0 ){
63497 /* If there are no other statements currently running, then
63498 ** reset the interrupt flag. This prevents a call to sqlite3_interrupt
63499 ** from interrupting a statement that has not yet started.
63500 */
63501 if( db->activeVdbeCnt==0 ){
63502 db->u1.isInterrupted = 0;
63503 }
63504
63505 assert( db->writeVdbeCnt>0 || db->autoCommit==0 || db->nDeferredCons==0 );
63506
63507 #ifndef SQLITE_OMIT_TRACE
63508 if( db->xProfile && !db->init.busy ){
63509 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
63510 }
63511 #endif
63512
63513 db->activeVdbeCnt++;
63514 if( p->readOnly==0 ) db->writeVdbeCnt++;
 
63515 p->pc = 0;
63516 }
63517 #ifndef SQLITE_OMIT_EXPLAIN
63518 if( p->explain ){
63519 rc = sqlite3VdbeList(p);
63520 }else
63521 #endif /* SQLITE_OMIT_EXPLAIN */
63522 {
63523 db->vdbeExecCnt++;
63524 rc = sqlite3VdbeExec(p);
63525 db->vdbeExecCnt--;
63526 }
63527
63528 #ifndef SQLITE_OMIT_TRACE
63529 /* Invoke the profile callback if there is one
63530 */
@@ -64457,13 +64494,13 @@
64457 return nTotal;
64458 }
64459
64460 /*
64461 ** This function returns a pointer to a nul-terminated string in memory
64462 ** obtained from sqlite3DbMalloc(). If sqlite3.vdbeExecCnt is 1, then the
64463 ** string contains a copy of zRawSql but with host parameters expanded to
64464 ** their current bindings. Or, if sqlite3.vdbeExecCnt is greater than 1,
64465 ** then the returned string holds a copy of zRawSql with "-- " prepended
64466 ** to each line of text.
64467 **
64468 ** If the SQLITE_TRACE_SIZE_LIMIT macro is defined to an integer, then
64469 ** then long strings and blobs are truncated to that many bytes. This
@@ -64497,11 +64534,11 @@
64497
64498 db = p->db;
64499 sqlite3StrAccumInit(&out, zBase, sizeof(zBase),
64500 db->aLimit[SQLITE_LIMIT_LENGTH]);
64501 out.db = db;
64502 if( db->vdbeExecCnt>1 ){
64503 while( *zRawSql ){
64504 const char *zStart = zRawSql;
64505 while( *(zRawSql++)!='\n' && *zRawSql );
64506 sqlite3StrAccumAppend(&out, "-- ", 3);
64507 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
@@ -65351,16 +65388,17 @@
65351 u8 encoding = ENC(db); /* The database encoding */
65352 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65353 int checkProgress; /* True if progress callbacks are enabled */
65354 int nProgressOps = 0; /* Opcodes executed since progress callback. */
65355 #endif
 
 
65356 Mem *aMem = p->aMem; /* Copy of p->aMem */
65357 Mem *pIn1 = 0; /* 1st input operand */
65358 Mem *pIn2 = 0; /* 2nd input operand */
65359 Mem *pIn3 = 0; /* 3rd input operand */
65360 Mem *pOut = 0; /* Output operand */
65361 int iCompare = 0; /* Result of last OP_Compare operation */
65362 int *aPermute = 0; /* Permutation of columns for OP_Compare */
65363 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
65364 #ifdef VDBE_PROFILE
65365 u64 start; /* CPU clock count at start of opcode */
65366 int origPc; /* Program counter at start of opcode */
@@ -65802,10 +65840,11 @@
65802 /* This happens if a malloc() inside a call to sqlite3_column_text() or
65803 ** sqlite3_column_text16() failed. */
65804 goto no_mem;
65805 }
65806 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY );
 
65807 p->rc = SQLITE_OK;
65808 assert( p->explain==0 );
65809 p->pResultSet = 0;
65810 db->busyHandler.nBusy = 0;
65811 CHECK_FOR_INTERRUPT;
@@ -65830,10 +65869,11 @@
65830 if( db->mallocFailed ) goto no_mem;
65831 #ifdef VDBE_PROFILE
65832 origPc = pc;
65833 start = sqlite3Hwtime();
65834 #endif
 
65835 pOp = &aOp[pc];
65836
65837 /* Only allow tracing if SQLITE_DEBUG is defined.
65838 */
65839 #ifdef SQLITE_DEBUG
@@ -67945,13 +67985,14 @@
67945 */
67946 assert( db->pSavepoint==0 || db->autoCommit==0 );
67947 assert( u.as.p1==SAVEPOINT_BEGIN||u.as.p1==SAVEPOINT_RELEASE||u.as.p1==SAVEPOINT_ROLLBACK );
67948 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
67949 assert( checkSavepointCount(db) );
 
67950
67951 if( u.as.p1==SAVEPOINT_BEGIN ){
67952 if( db->writeVdbeCnt>0 ){
67953 /* A new savepoint cannot be created if there are active write
67954 ** statements (i.e. open read/write incremental blob handles).
67955 */
67956 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
67957 "SQL statements in progress");
@@ -68004,11 +68045,11 @@
68004 u.as.iSavepoint++;
68005 }
68006 if( !u.as.pSavepoint ){
68007 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.as.zName);
68008 rc = SQLITE_ERROR;
68009 }else if( db->writeVdbeCnt>0 && u.as.p1==SAVEPOINT_RELEASE ){
68010 /* It is not possible to release (commit) a savepoint if there are
68011 ** active write statements.
68012 */
68013 sqlite3SetString(&p->zErrMsg, db,
68014 "cannot release savepoint - SQL statements in progress"
@@ -68107,24 +68148,25 @@
68107 u.at.desiredAutoCommit = pOp->p1;
68108 u.at.iRollback = pOp->p2;
68109 u.at.turnOnAC = u.at.desiredAutoCommit && !db->autoCommit;
68110 assert( u.at.desiredAutoCommit==1 || u.at.desiredAutoCommit==0 );
68111 assert( u.at.desiredAutoCommit==1 || u.at.iRollback==0 );
68112 assert( db->activeVdbeCnt>0 ); /* At least this one VM is active */
 
68113
68114 #if 0
68115 if( u.at.turnOnAC && u.at.iRollback && db->activeVdbeCnt>1 ){
68116 /* If this instruction implements a ROLLBACK and other VMs are
68117 ** still running, and a transaction is active, return an error indicating
68118 ** that the other VMs must complete first.
68119 */
68120 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
68121 "SQL statements in progress");
68122 rc = SQLITE_BUSY;
68123 }else
68124 #endif
68125 if( u.at.turnOnAC && !u.at.iRollback && db->writeVdbeCnt>0 ){
68126 /* If this instruction implements a COMMIT and other VMs are writing
68127 ** return an error indicating that the other VMs must complete first.
68128 */
68129 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
68130 "SQL statements in progress");
@@ -68198,10 +68240,12 @@
68198 case OP_Transaction: {
68199 #if 0 /* local variables moved into u.au */
68200 Btree *pBt;
68201 #endif /* local variables moved into u.au */
68202
 
 
68203 assert( pOp->p1>=0 && pOp->p1<db->nDb );
68204 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
68205 u.au.pBt = db->aDb[pOp->p1].pBt;
68206
68207 if( u.au.pBt ){
@@ -68214,11 +68258,11 @@
68214 if( rc!=SQLITE_OK ){
68215 goto abort_due_to_error;
68216 }
68217
68218 if( pOp->p2 && p->usesStmtJournal
68219 && (db->autoCommit==0 || db->activeVdbeCnt>1)
68220 ){
68221 assert( sqlite3BtreeIsInTrans(u.au.pBt) );
68222 if( p->iStatement==0 ){
68223 assert( db->nStatement>=0 && db->nSavepoint>=0 );
68224 db->nStatement++;
@@ -68256,10 +68300,11 @@
68256 int iMeta;
68257 int iDb;
68258 int iCookie;
68259 #endif /* local variables moved into u.av */
68260
 
68261 u.av.iDb = pOp->p1;
68262 u.av.iCookie = pOp->p3;
68263 assert( pOp->p3<SQLITE_N_BTREE_META );
68264 assert( u.av.iDb>=0 && u.av.iDb<db->nDb );
68265 assert( db->aDb[u.av.iDb].pBt!=0 );
@@ -68285,10 +68330,11 @@
68285 Db *pDb;
68286 #endif /* local variables moved into u.aw */
68287 assert( pOp->p2<SQLITE_N_BTREE_META );
68288 assert( pOp->p1>=0 && pOp->p1<db->nDb );
68289 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
 
68290 u.aw.pDb = &db->aDb[pOp->p1];
68291 assert( u.aw.pDb->pBt!=0 );
68292 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
68293 pIn3 = &aMem[pOp->p3];
68294 sqlite3VdbeMemIntegerify(pIn3);
@@ -68337,10 +68383,11 @@
68337 #endif /* local variables moved into u.ax */
68338
68339 assert( pOp->p1>=0 && pOp->p1<db->nDb );
68340 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
68341 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
 
68342 u.ax.pBt = db->aDb[pOp->p1].pBt;
68343 if( u.ax.pBt ){
68344 sqlite3BtreeGetMeta(u.ax.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ax.iMeta);
68345 u.ax.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
68346 }else{
@@ -68434,10 +68481,12 @@
68434 Db *pDb;
68435 #endif /* local variables moved into u.ay */
68436
68437 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
68438 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
 
 
68439
68440 if( p->expired ){
68441 rc = SQLITE_ABORT;
68442 break;
68443 }
@@ -70052,19 +70101,22 @@
70052 int iCnt;
70053 Vdbe *pVdbe;
70054 int iDb;
70055 #endif /* local variables moved into u.bw */
70056
 
70057 #ifndef SQLITE_OMIT_VIRTUALTABLE
70058 u.bw.iCnt = 0;
70059 for(u.bw.pVdbe=db->pVdbe; u.bw.pVdbe; u.bw.pVdbe = u.bw.pVdbe->pNext){
70060 if( u.bw.pVdbe->magic==VDBE_MAGIC_RUN && u.bw.pVdbe->inVtabMethod<2 && u.bw.pVdbe->pc>=0 ){
 
 
70061 u.bw.iCnt++;
70062 }
70063 }
70064 #else
70065 u.bw.iCnt = db->activeVdbeCnt;
70066 #endif
70067 pOut->flags = MEM_Null;
70068 if( u.bw.iCnt>1 ){
70069 rc = SQLITE_LOCKED;
70070 p->errorAction = OE_Abort;
@@ -70109,10 +70161,11 @@
70109 #if 0 /* local variables moved into u.bx */
70110 int nChange;
70111 #endif /* local variables moved into u.bx */
70112
70113 u.bx.nChange = 0;
 
70114 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
70115 rc = sqlite3BtreeClearTable(
70116 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bx.nChange : 0)
70117 );
70118 if( pOp->p3 ){
@@ -70157,10 +70210,11 @@
70157 #endif /* local variables moved into u.by */
70158
70159 u.by.pgno = 0;
70160 assert( pOp->p1>=0 && pOp->p1<db->nDb );
70161 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
 
70162 u.by.pDb = &db->aDb[pOp->p1];
70163 assert( u.by.pDb->pBt!=0 );
70164 if( pOp->opcode==OP_CreateTable ){
70165 /* u.by.flags = BTREE_INTKEY; */
70166 u.by.flags = BTREE_INTKEY;
@@ -70309,10 +70363,11 @@
70309 int nErr; /* Number of errors reported */
70310 char *z; /* Text of the error report */
70311 Mem *pnErr; /* Register keeping track of errors remaining */
70312 #endif /* local variables moved into u.ca */
70313
 
70314 u.ca.nRoot = pOp->p2;
70315 assert( u.ca.nRoot>0 );
70316 u.ca.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.ca.nRoot+1) );
70317 if( u.ca.aRoot==0 ) goto no_mem;
70318 assert( pOp->p3>0 && pOp->p3<=p->nMem );
@@ -70830,10 +70885,11 @@
70830 int i; /* Loop counter */
70831 int aRes[3]; /* Results */
70832 Mem *pMem; /* Write results here */
70833 #endif /* local variables moved into u.ci */
70834
 
70835 u.ci.aRes[0] = 0;
70836 u.ci.aRes[1] = u.ci.aRes[2] = -1;
70837 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
70838 || pOp->p2==SQLITE_CHECKPOINT_FULL
70839 || pOp->p2==SQLITE_CHECKPOINT_RESTART
@@ -70881,10 +70937,11 @@
70881 || u.cj.eNew==PAGER_JOURNALMODE_MEMORY
70882 || u.cj.eNew==PAGER_JOURNALMODE_WAL
70883 || u.cj.eNew==PAGER_JOURNALMODE_QUERY
70884 );
70885 assert( pOp->p1>=0 && pOp->p1<db->nDb );
 
70886
70887 u.cj.pBt = db->aDb[pOp->p1].pBt;
70888 u.cj.pPager = sqlite3BtreePager(u.cj.pBt);
70889 u.cj.eOld = sqlite3PagerGetJournalMode(u.cj.pPager);
70890 if( u.cj.eNew==PAGER_JOURNALMODE_QUERY ) u.cj.eNew = u.cj.eOld;
@@ -70904,11 +70961,11 @@
70904 }
70905
70906 if( (u.cj.eNew!=u.cj.eOld)
70907 && (u.cj.eOld==PAGER_JOURNALMODE_WAL || u.cj.eNew==PAGER_JOURNALMODE_WAL)
70908 ){
70909 if( !db->autoCommit || db->activeVdbeCnt>1 ){
70910 rc = SQLITE_ERROR;
70911 sqlite3SetString(&p->zErrMsg, db,
70912 "cannot change %s wal mode from within a transaction",
70913 (u.cj.eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of")
70914 );
@@ -70963,10 +71020,11 @@
70963 ** Vacuum the entire database. This opcode will cause other virtual
70964 ** machines to be created and run. It may not be called from within
70965 ** a transaction.
70966 */
70967 case OP_Vacuum: {
 
70968 rc = sqlite3RunVacuum(&p->zErrMsg, db);
70969 break;
70970 }
70971 #endif
70972
@@ -70982,10 +71040,11 @@
70982 Btree *pBt;
70983 #endif /* local variables moved into u.ck */
70984
70985 assert( pOp->p1>=0 && pOp->p1<db->nDb );
70986 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
 
70987 u.ck.pBt = db->aDb[pOp->p1].pBt;
70988 rc = sqlite3BtreeIncrVacuum(u.ck.pBt);
70989 if( rc==SQLITE_DONE ){
70990 pc = pOp->p2 - 1;
70991 rc = SQLITE_OK;
@@ -71104,10 +71163,11 @@
71104 sqlite3_vtab_cursor *pVtabCursor;
71105 sqlite3_vtab *pVtab;
71106 sqlite3_module *pModule;
71107 #endif /* local variables moved into u.cm */
71108
 
71109 u.cm.pCur = 0;
71110 u.cm.pVtabCursor = 0;
71111 u.cm.pVtab = pOp->p4.pVtab->pVtab;
71112 u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule;
71113 assert(u.cm.pVtab && u.cm.pModule);
@@ -71328,10 +71388,11 @@
71328
71329 u.cq.pVtab = pOp->p4.pVtab->pVtab;
71330 u.cq.pName = &aMem[pOp->p1];
71331 assert( u.cq.pVtab->pModule->xRename );
71332 assert( memIsValid(u.cq.pName) );
 
71333 REGISTER_TRACE(pOp->p1, u.cq.pName);
71334 assert( u.cq.pName->flags & MEM_Str );
71335 testcase( u.cq.pName->enc==SQLITE_UTF8 );
71336 testcase( u.cq.pName->enc==SQLITE_UTF16BE );
71337 testcase( u.cq.pName->enc==SQLITE_UTF16LE );
@@ -71381,10 +71442,11 @@
71381 #endif /* local variables moved into u.cr */
71382
71383 assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
71384 || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
71385 );
 
71386 u.cr.pVtab = pOp->p4.pVtab->pVtab;
71387 u.cr.pModule = (sqlite3_module *)u.cr.pVtab->pModule;
71388 u.cr.nArg = pOp->p2;
71389 assert( pOp->p4type==P4_VTAB );
71390 if( ALWAYS(u.cr.pModule->xUpdate) ){
@@ -71566,10 +71628,11 @@
71566 /* This is the only way out of this procedure. We have to
71567 ** release the mutexes on btrees that were acquired at the
71568 ** top. */
71569 vdbe_return:
71570 db->lastRowid = lastRowid;
 
71571 sqlite3VdbeLeave(p);
71572 return rc;
71573
71574 /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
71575 ** is encountered.
@@ -76044,10 +76107,11 @@
76044 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
76045 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
76046 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
76047 pItem->sortOrder = pOldItem->sortOrder;
76048 pItem->done = 0;
 
76049 pItem->iOrderByCol = pOldItem->iOrderByCol;
76050 pItem->iAlias = pOldItem->iAlias;
76051 }
76052 return pNew;
76053 }
@@ -100236,19 +100300,20 @@
100236 sDistinct.eTnctType = WHERE_DISTINCT_NOOP;
100237 }
100238
100239 if( !isAgg && pGroupBy==0 ){
100240 /* No aggregate functions and no GROUP BY clause */
100241 ExprList *pDist = (sDistinct.isTnct ? p->pEList : 0);
100242
100243 /* Begin the database scan. */
100244 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pOrderBy, pDist, 0,0);
 
100245 if( pWInfo==0 ) goto select_end;
100246 if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
100247 p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
100248 }
100249 if( sqlite3WhereIsDistinct(pWInfo) ){
100250 sDistinct.eTnctType = sqlite3WhereIsDistinct(pWInfo);
100251 }
100252 if( pOrderBy && sqlite3WhereIsOrdered(pWInfo) ) pOrderBy = 0;
100253
100254 /* If sorting index that was created by a prior OP_OpenEphemeral
@@ -102940,11 +103005,11 @@
102940
102941 if( !db->autoCommit ){
102942 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
102943 return SQLITE_ERROR;
102944 }
102945 if( db->activeVdbeCnt>1 ){
102946 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
102947 return SQLITE_ERROR;
102948 }
102949
102950 /* Save the current value of the database flags so that it can be
@@ -104440,11 +104505,11 @@
104440
104441 /*
104442 ** Each instance of this object holds a sequence of WhereLoop objects
104443 ** that implement some or all of a query plan.
104444 **
104445 ** Think of each WhereLoop objects as a node in a graph, which arcs
104446 ** showing dependences and costs for travelling between nodes. (That is
104447 ** not a completely accurate description because WhereLoop costs are a
104448 ** vector, not a scalar, and because dependences are many-to-one, not
104449 ** one-to-one as are graph nodes. But it is a useful visualization aid.)
104450 ** Then a WherePath object is a path through the graph that visits some
@@ -104664,23 +104729,23 @@
104664 */
104665 struct WhereInfo {
104666 Parse *pParse; /* Parsing and code generating context */
104667 SrcList *pTabList; /* List of tables in the join */
104668 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
104669 ExprList *pDistinct; /* DISTINCT ON values, or NULL */
104670 WhereLoop *pLoops; /* List of all WhereLoop objects */
104671 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
104672 WhereCost nRowOut; /* Estimated number of output rows */
104673 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
104674 u8 bOBSat; /* ORDER BY satisfied by indices */
104675 u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE/DELETE */
104676 u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */
104677 u8 eDistinct; /* One of the WHERE_DISTINCT_* values below */
 
104678 int iTop; /* The very beginning of the WHERE loop */
104679 int iContinue; /* Jump here to continue with next record */
104680 int iBreak; /* Jump here to break out of the loop */
104681 int nLevel; /* Number of nested loop */
104682 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
104683 WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
104684 WhereClause sWC; /* Decomposition of the WHERE clause */
104685 WhereLevel a[1]; /* Information about each nest loop in WHERE */
104686 };
@@ -104710,11 +104775,11 @@
104710 /*
104711 ** These are definitions of bits in the WhereLoop.wsFlags field.
104712 ** The particular combination of bits in each WhereLoop help to
104713 ** determine the algorithm that WhereLoop represents.
104714 */
104715 #define WHERE_COLUMN_EQ 0x00000001 /* x=EXPR or x IN (...) or x IS NULL */
104716 #define WHERE_COLUMN_RANGE 0x00000002 /* x<EXPR and/or x>EXPR */
104717 #define WHERE_COLUMN_IN 0x00000004 /* x IN (...) */
104718 #define WHERE_COLUMN_NULL 0x00000008 /* x IS NULL */
104719 #define WHERE_CONSTRAINT 0x0000000f /* Any of the WHERE_COLUMN_xxx values */
104720 #define WHERE_TOP_LIMIT 0x00000010 /* x<EXPR or x<=EXPR constraint */
@@ -104725,11 +104790,11 @@
104725 #define WHERE_INDEXED 0x00000200 /* WhereLoop.u.btree.pIndex is valid */
104726 #define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */
104727 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
104728 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
104729 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
104730 #define WHERE_TEMP_INDEX 0x00004000 /* Uses an ephemeral index */
104731
104732
104733 /* Convert a WhereCost value (10 times log2(X)) into its integer value X.
104734 ** A rough approximation is used. The value returned is not exact.
104735 */
@@ -105103,11 +105168,11 @@
105103 /*
105104 ** Advance to the next WhereTerm that matches according to the criteria
105105 ** established when the pScan object was initialized by whereScanInit().
105106 ** Return NULL if there are no more matching WhereTerms.
105107 */
105108 WhereTerm *whereScanNext(WhereScan *pScan){
105109 int iCur; /* The cursor on the LHS of the term */
105110 int iColumn; /* The column on the LHS of the term. -1 for IPK */
105111 Expr *pX; /* An expression being tested */
105112 WhereClause *pWC; /* Shorthand for pScan->pWC */
105113 WhereTerm *pTerm; /* The term being tested */
@@ -105190,11 +105255,11 @@
105190 ** but is enough to handle most commonly occurring SQL statements.
105191 **
105192 ** If X is not the INTEGER PRIMARY KEY then X must be compatible with
105193 ** index pIdx.
105194 */
105195 WhereTerm *whereScanInit(
105196 WhereScan *pScan, /* The WhereScan object being initialized */
105197 WhereClause *pWC, /* The WHERE clause to be scanned */
105198 int iCur, /* Cursor to scan for */
105199 int iColumn, /* Column to scan for */
105200 u32 opMask, /* Operator(s) to scan for */
@@ -106019,10 +106084,11 @@
106019 ** the start of the loop will prevent any results from being returned.
106020 */
106021 if( pExpr->op==TK_NOTNULL
106022 && pExpr->pLeft->op==TK_COLUMN
106023 && pExpr->pLeft->iColumn>=0
 
106024 ){
106025 Expr *pNewExpr;
106026 Expr *pLeft = pExpr->pLeft;
106027 int idxNew;
106028 WhereTerm *pNewTerm;
@@ -106322,10 +106388,11 @@
106322 int mxBitCol; /* Maximum column in pSrc->colUsed */
106323 CollSeq *pColl; /* Collating sequence to on a column */
106324 WhereLoop *pLoop; /* The Loop object */
106325 Bitmask idxCols; /* Bitmap of columns used for indexing */
106326 Bitmask extraCols; /* Bitmap of additional columns */
 
106327
106328 /* Generate code to skip over the creation and initialization of the
106329 ** transient index on 2nd and subsequent iterations of the loop. */
106330 v = pParse->pVdbe;
106331 assert( v!=0 );
@@ -106342,10 +106409,16 @@
106342 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
106343 int iCol = pTerm->u.leftColumn;
106344 Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
106345 testcase( iCol==BMS );
106346 testcase( iCol==BMS-1 );
 
 
 
 
 
 
106347 if( (idxCols & cMask)==0 ){
106348 if( whereLoopResize(pParse->db, pLoop, nColumn+1) ) return;
106349 pLoop->aLTerm[nColumn++] = pTerm;
106350 idxCols |= cMask;
106351 }
@@ -106352,11 +106425,11 @@
106352 }
106353 }
106354 assert( nColumn>0 );
106355 pLoop->u.btree.nEq = pLoop->nLTerm = nColumn;
106356 pLoop->wsFlags = WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WHERE_INDEXED
106357 | WHERE_TEMP_INDEX;
106358
106359 /* Count the number of additional columns needed to create a
106360 ** covering index. A "covering index" is an index that contains all
106361 ** columns that are needed by the query. With a covering index, the
106362 ** original table never needs to be accessed. Automatic indices must
@@ -106690,13 +106763,14 @@
106690 z = (const u8 *)sqlite3_value_blob(pVal);
106691 pColl = db->pDfltColl;
106692 assert( pColl->enc==SQLITE_UTF8 );
106693 }else{
106694 pColl = sqlite3GetCollSeq(pParse, SQLITE_UTF8, 0, *pIdx->azColl);
106695 if( pColl==0 ){
106696 return SQLITE_ERROR;
106697 }
 
106698 z = (const u8 *)sqlite3ValueText(pVal, pColl->enc);
106699 if( !z ){
106700 return SQLITE_NOMEM;
106701 }
106702 assert( z && pColl && pColl->xCmp );
@@ -106851,11 +106925,11 @@
106851 ){
106852 int rc = SQLITE_OK;
106853
106854 #ifdef SQLITE_ENABLE_STAT3
106855
106856 if( nEq==0 && p->nSample ){
106857 sqlite3_value *pRangeVal;
106858 tRowcnt iLower = 0;
106859 tRowcnt iUpper = p->aiRowEst[0];
106860 tRowcnt a[2];
106861 u8 aff = p->pTable->aCol[p->aiColumn[0]].affinity;
@@ -107397,17 +107471,16 @@
107397 }
107398 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0
107399 && ALWAYS(pLoop->u.btree.pIndex!=0)
107400 ){
107401 char *zWhere = explainIndexRange(db, pLoop, pItem->pTab);
107402 zMsg = sqlite3MAppendf(db, zMsg, "%s USING %s%sINDEX%s%s%s", zMsg,
107403 ((flags & WHERE_TEMP_INDEX)?"AUTOMATIC ":""),
107404 ((flags & WHERE_IDX_ONLY)?"COVERING ":""),
107405 ((flags & WHERE_TEMP_INDEX)?"":" "),
107406 ((flags & WHERE_TEMP_INDEX)?"": pLoop->u.btree.pIndex->zName),
107407 zWhere
107408 );
107409 sqlite3DbFree(db, zWhere);
107410 }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
107411 zMsg = sqlite3MAppendf(db, zMsg, "%s USING INTEGER PRIMARY KEY", zMsg);
107412
107413 if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
@@ -107608,14 +107681,15 @@
107608 };
107609 assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
107610 assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
107611 assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
107612
 
107613 testcase( pStart->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
107614 pX = pStart->pExpr;
107615 assert( pX!=0 );
107616 assert( pStart->leftCursor==iCur );
107617 r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
107618 sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
107619 VdbeComment((v, "pk"));
107620 sqlite3ExprCacheAffinityChange(pParse, r1, 1);
107621 sqlite3ReleaseTempReg(pParse, rTemp);
@@ -107625,11 +107699,12 @@
107625 }
107626 if( pEnd ){
107627 Expr *pX;
107628 pX = pEnd->pExpr;
107629 assert( pX!=0 );
107630 assert( pEnd->leftCursor==iCur );
 
107631 testcase( pEnd->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
107632 memEndValue = ++pParse->nMem;
107633 sqlite3ExprCode(pParse, pX->pRight, memEndValue);
107634 if( pX->op==TK_LT || pX->op==TK_GT ){
107635 testOp = bRev ? OP_Le : OP_Ge;
@@ -108074,11 +108149,11 @@
108074 ** terms, set pCov to the candidate covering index. Otherwise, set
108075 ** pCov to NULL to indicate that no candidate covering index will
108076 ** be available.
108077 */
108078 pSubLoop = pSubWInfo->a[0].pWLoop;
108079 assert( (pSubLoop->wsFlags & WHERE_TEMP_INDEX)==0 );
108080 if( (pSubLoop->wsFlags & WHERE_INDEXED)!=0
108081 && (ii==0 || pSubLoop->u.btree.pIndex==pCov)
108082 ){
108083 assert( pSubWInfo->a[0].iIdxCur==iCovCur );
108084 pCov = pSubLoop->u.btree.pIndex;
@@ -108160,10 +108235,11 @@
108160 WhereTerm *pAlt;
108161 Expr sEq;
108162 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
108163 if( pTerm->eOperator!=(WO_EQUIV|WO_EQ) ) continue;
108164 if( pTerm->leftCursor!=iCur ) continue;
 
108165 pE = pTerm->pExpr;
108166 assert( !ExprHasProperty(pE, EP_FromJoin) );
108167 assert( (pTerm->prereqRight & newNotReady)!=0 );
108168 pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
108169 if( pAlt==0 ) continue;
@@ -108208,13 +108284,13 @@
108208 */
108209 static void whereLoopPrint(WhereLoop *p, SrcList *pTabList){
108210 int nb = 1+(pTabList->nSrc+7)/8;
108211 struct SrcList_item *pItem = pTabList->a + p->iTab;
108212 Table *pTab = pItem->pTab;
108213 sqlite3DebugPrintf("%c %2d.%0*llx.%0*llx", p->cId,
108214 p->iTab, nb, p->maskSelf, nb, p->prereq);
108215 sqlite3DebugPrintf(" %8s",
108216 pItem->zAlias ? pItem->zAlias : pTab->zName);
108217 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
108218 if( p->u.btree.pIndex ){
108219 const char *zName = p->u.btree.pIndex->zName;
108220 if( zName==0 ) zName = "ipk";
@@ -108221,26 +108297,26 @@
108221 if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
108222 int i = sqlite3Strlen30(zName) - 1;
108223 while( zName[i]!='_' ) i--;
108224 zName += i;
108225 }
108226 sqlite3DebugPrintf(".%-12s %2d", zName, p->u.btree.nEq);
108227 }else{
108228 sqlite3DebugPrintf("%16s","");
108229 }
108230 }else{
108231 char *z;
108232 if( p->u.vtab.idxStr ){
108233 z = sqlite3_mprintf("(%d,\"%s\",%x)",
108234 p->u.vtab.idxNum, p->u.vtab.idxStr, p->u.vtab.omitMask);
108235 }else{
108236 z = sqlite3_mprintf("(%d,%x)", p->u.vtab.idxNum, p->u.vtab.omitMask);
108237 }
108238 sqlite3DebugPrintf(" %-15s", z);
108239 sqlite3_free(z);
108240 }
108241 sqlite3DebugPrintf(" fg %05x N %d", p->wsFlags, p->nLTerm);
108242 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
108243 }
108244 #endif
108245
108246 /*
@@ -108256,16 +108332,16 @@
108256
108257 /*
108258 ** Clear the WhereLoop.u union. Leave WhereLoop.pLTerm intact.
108259 */
108260 static void whereLoopClearUnion(sqlite3 *db, WhereLoop *p){
108261 if( p->wsFlags & (WHERE_VIRTUALTABLE|WHERE_TEMP_INDEX) ){
108262 if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 && p->u.vtab.needFree ){
108263 sqlite3_free(p->u.vtab.idxStr);
108264 p->u.vtab.needFree = 0;
108265 p->u.vtab.idxStr = 0;
108266 }else if( (p->wsFlags & WHERE_TEMP_INDEX)!=0 && p->u.btree.pIndex!=0 ){
108267 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
108268 sqlite3DbFree(db, p->u.btree.pIndex);
108269 p->u.btree.pIndex = 0;
108270 }
108271 }
@@ -108304,11 +108380,11 @@
108304 whereLoopClearUnion(db, pTo);
108305 memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
108306 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
108307 if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
108308 pFrom->u.vtab.needFree = 0;
108309 }else if( (pFrom->wsFlags & WHERE_TEMP_INDEX)!=0 ){
108310 pFrom->u.btree.pIndex = 0;
108311 }
108312 return SQLITE_OK;
108313 }
108314
@@ -108554,10 +108630,15 @@
108554 pNew->rSetup = 0;
108555 rLogSize = estLog(whereCost(pProbe->aiRowEst[0]));
108556 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
108557 int nIn = 0;
108558 if( pTerm->prereqRight & pNew->maskSelf ) continue;
 
 
 
 
 
108559 pNew->wsFlags = saved_wsFlags;
108560 pNew->u.btree.nEq = saved_nEq;
108561 pNew->nLTerm = saved_nLTerm;
108562 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
108563 pNew->aLTerm[pNew->nLTerm++] = pTerm;
@@ -108616,11 +108697,12 @@
108616 whereRangeScanEst(pParse, pProbe, pNew->u.btree.nEq,
108617 pBtm, pTop, &rDiv);
108618 pNew->nOut = saved_nOut>rDiv+10 ? saved_nOut - rDiv : 10;
108619 }
108620 #ifdef SQLITE_ENABLE_STAT3
108621 if( pNew->u.btree.nEq==1 && pProbe->nSample ){
 
108622 tRowcnt nOut = 0;
108623 if( (pTerm->eOperator & (WO_EQ|WO_ISNULL))!=0 ){
108624 testcase( pTerm->eOperator & WO_EQ );
108625 testcase( pTerm->eOperator & WO_ISNULL );
108626 rc = whereEqualScanEst(pParse, pProbe, pTerm->pExpr->pRight, &nOut);
@@ -108700,11 +108782,11 @@
108700 return m;
108701 }
108702
108703
108704 /*
108705 ** Add all WhereLoop objects a single table of the join were the table
108706 ** is idenfied by pBuilder->pNew->iTab. That table is guaranteed to be
108707 ** a b-tree table, not a virtual table.
108708 */
108709 static int whereLoopAddBtree(
108710 WhereLoopBuilder *pBuilder, /* WHERE clause information */
@@ -108776,17 +108858,20 @@
108776 pNew->u.btree.nEq = 1;
108777 pNew->u.btree.pIndex = 0;
108778 pNew->nLTerm = 1;
108779 pNew->aLTerm[0] = pTerm;
108780 /* TUNING: One-time cost for computing the automatic index is
108781 ** approximately 6*N*log2(N) where N is the number of rows in
108782 ** the table being indexed. */
108783 pNew->rSetup = rLogSize + rSize + 26; assert( 26==whereCost(6) );
108784 /* TUNING: Each index lookup yields 10 rows in the table */
108785 pNew->nOut = 33; assert( 33==whereCost(10) );
 
 
 
108786 pNew->rRun = whereCostAdd(rLogSize,pNew->nOut);
108787 pNew->wsFlags = WHERE_TEMP_INDEX;
108788 pNew->prereq = mExtra | pTerm->prereqRight;
108789 rc = whereLoopInsert(pBuilder, pNew);
108790 }
108791 }
108792 }
@@ -109161,16 +109246,23 @@
109161 }
109162
109163 /*
109164 ** Examine a WherePath (with the addition of the extra WhereLoop of the 5th
109165 ** parameters) to see if it outputs rows in the requested ORDER BY
109166 ** (or GROUP BY) without requiring a separate source operation. Return:
109167 **
109168 ** 0: ORDER BY is not satisfied. Sorting required
109169 ** 1: ORDER BY is satisfied. Omit sorting
109170 ** -1: Unknown at this time
109171 **
 
 
 
 
 
 
 
109172 */
109173 static int wherePathSatisfiesOrderBy(
109174 WhereInfo *pWInfo, /* The WHERE clause */
109175 ExprList *pOrderBy, /* ORDER BY or GROUP BY or DISTINCT clause to check */
109176 WherePath *pPath, /* The WherePath to check */
@@ -109414,11 +109506,11 @@
109414 }
109415 #endif
109416
109417
109418 /*
109419 ** Given the list of WhereLoop objects on pWInfo->pLoops, this routine
109420 ** attempts to find the lowest cost path that visits each WhereLoop
109421 ** once. This path is then loaded into the pWInfo->a[].pWLoop fields.
109422 **
109423 ** Assume that the total number of output rows that will need to be sorted
109424 ** will be nRowEst (in the 10*log2 representation). Or, ignore sorting
@@ -109650,16 +109742,17 @@
109650 WhereLevel *pLevel = pWInfo->a + iLoop;
109651 pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
109652 pLevel->iFrom = pWLoop->iTab;
109653 pLevel->iTabCur = pWInfo->pTabList->a[pLevel->iFrom].iCursor;
109654 }
109655 if( (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
109656 && pWInfo->pDistinct
 
109657 && nRowEst
109658 ){
109659 Bitmask notUsed;
109660 int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pDistinct, pFrom,
109661 WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
109662 if( rc==1 ) pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
109663 }
109664 if( pFrom->isOrdered ){
109665 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -109744,11 +109837,13 @@
109744 pWInfo->a[0].pWLoop = pLoop;
109745 pLoop->maskSelf = getMask(&pWInfo->sMaskSet, iCur);
109746 pWInfo->a[0].iTabCur = iCur;
109747 pWInfo->nRowOut = 1;
109748 if( pWInfo->pOrderBy ) pWInfo->bOBSat = 1;
109749 if( pWInfo->pDistinct ) pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
 
 
109750 #ifdef SQLITE_DEBUG
109751 pLoop->cId = '0';
109752 #endif
109753 return 1;
109754 }
@@ -109828,20 +109923,21 @@
109828 ** fi
109829 ** end
109830 **
109831 ** ORDER BY CLAUSE PROCESSING
109832 **
109833 ** pOrderBy is a pointer to the ORDER BY clause of a SELECT statement,
 
109834 ** if there is one. If there is no ORDER BY clause or if this routine
109835 ** is called from an UPDATE or DELETE statement, then pOrderBy is NULL.
109836 */
109837 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
109838 Parse *pParse, /* The parser context */
109839 SrcList *pTabList, /* A list of all tables to be scanned */
109840 Expr *pWhere, /* The WHERE clause */
109841 ExprList *pOrderBy, /* An ORDER BY clause, or NULL */
109842 ExprList *pDistinct, /* The select-list for DISTINCT queries - or NULL */
109843 u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
109844 int iIdxCur /* If WHERE_ONETABLE_ONLY is set, index cursor number */
109845 ){
109846 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
109847 int nTabList; /* Number of elements in pTabList */
@@ -109849,18 +109945,26 @@
109849 Vdbe *v = pParse->pVdbe; /* The virtual database engine */
109850 Bitmask notReady; /* Cursors that are not yet positioned */
109851 WhereLoopBuilder sWLB; /* The WhereLoop builder */
109852 WhereMaskSet *pMaskSet; /* The expression mask set */
109853 WhereLevel *pLevel; /* A single level in pWInfo->a[] */
 
109854 int ii; /* Loop counter */
109855 sqlite3 *db; /* Database connection */
109856 int rc; /* Return code */
109857
109858
109859 /* Variable initialization */
 
109860 memset(&sWLB, 0, sizeof(sWLB));
109861 sWLB.pOrderBy = pOrderBy;
 
 
 
 
 
 
109862
109863 /* The number of tables in the FROM clause is limited by the number of
109864 ** bits in a Bitmask
109865 */
109866 testcase( pTabList->nSrc==BMS );
@@ -109881,11 +109985,10 @@
109881 ** struct, the contents of WhereInfo.a[], the WhereClause structure
109882 ** and the WhereMaskSet structure. Since WhereClause contains an 8-byte
109883 ** field (type Bitmask) it must be aligned on an 8-byte boundary on
109884 ** some architectures. Hence the ROUND8() below.
109885 */
109886 db = pParse->db;
109887 nByteWInfo = ROUND8(sizeof(WhereInfo)+(nTabList-1)*sizeof(WhereLevel));
109888 pWInfo = sqlite3DbMallocZero(db, nByteWInfo + sizeof(WhereLoop));
109889 if( db->mallocFailed ){
109890 sqlite3DbFree(db, pWInfo);
109891 pWInfo = 0;
@@ -109893,11 +109996,11 @@
109893 }
109894 pWInfo->nLevel = nTabList;
109895 pWInfo->pParse = pParse;
109896 pWInfo->pTabList = pTabList;
109897 pWInfo->pOrderBy = pOrderBy;
109898 pWInfo->pDistinct = pDistinct;
109899 pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
109900 pWInfo->wctrlFlags = wctrlFlags;
109901 pWInfo->savedNQueryLoop = pParse->nQueryLoop;
109902 pMaskSet = &pWInfo->sMaskSet;
109903 sWLB.pWInfo = pWInfo;
@@ -109906,21 +110009,18 @@
109906 whereLoopInit(sWLB.pNew);
109907 #ifdef SQLITE_DEBUG
109908 sWLB.pNew->cId = '*';
109909 #endif
109910
109911 /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
109912 ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */
109913 if( OptimizationDisabled(db, SQLITE_DistinctOpt) ) pDistinct = 0;
109914
109915 /* Split the WHERE clause into separate subexpressions where each
109916 ** subexpression is separated by an AND operator.
109917 */
109918 initMaskSet(pMaskSet);
109919 whereClauseInit(&pWInfo->sWC, pWInfo);
109920 sqlite3ExprCodeConstants(pParse, pWhere);
109921 whereSplit(&pWInfo->sWC, pWhere, TK_AND); /* IMP: R-15842-53296 */
 
109922
109923 /* Special case: a WHERE clause that is constant. Evaluate the
109924 ** expression and either jump over all of the code or fall thru.
109925 */
109926 if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){
@@ -109930,11 +110030,13 @@
109930
109931 /* Special case: No FROM clause
109932 */
109933 if( nTabList==0 ){
109934 if( pOrderBy ) pWInfo->bOBSat = 1;
109935 if( pDistinct ) pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
 
 
109936 }
109937
109938 /* Assign a bit from the bitmask to every term in the FROM clause.
109939 **
109940 ** When assigning bitmask values to FROM clause cursors, it must be
@@ -109977,11 +110079,11 @@
109977
109978 /* If the ORDER BY (or GROUP BY) clause contains references to general
109979 ** expressions, then we won't be able to satisfy it using indices, so
109980 ** go ahead and disable it now.
109981 */
109982 if( pOrderBy && pDistinct ){
109983 for(ii=0; ii<pOrderBy->nExpr; ii++){
109984 Expr *pExpr = sqlite3ExprSkipCollate(pOrderBy->a[ii].pExpr);
109985 if( pExpr->op!=TK_COLUMN ){
109986 pWInfo->pOrderBy = pOrderBy = 0;
109987 break;
@@ -109989,21 +110091,18 @@
109989 break;
109990 }
109991 }
109992 }
109993
109994 /* Check if the DISTINCT qualifier, if there is one, is redundant.
109995 ** If it is, then set pDistinct to NULL and WhereInfo.eDistinct to
109996 ** WHERE_DISTINCT_UNIQUE to tell the caller to ignore the DISTINCT.
109997 */
109998 if( pDistinct ){
109999 if( isDistinctRedundant(pParse,pTabList,&pWInfo->sWC,pDistinct) ){
110000 pDistinct = 0;
110001 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
110002 }else if( pOrderBy==0 ){
 
110003 pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
110004 pWInfo->pOrderBy = pDistinct;
110005 }
110006 }
110007
110008 /* Construct the WhereLoop objects */
110009 WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
@@ -110013,15 +110112,15 @@
110013
110014 /* Display all of the WhereLoop objects if wheretrace is enabled */
110015 #ifdef WHERETRACE_ENABLED
110016 if( sqlite3WhereTrace ){
110017 WhereLoop *p;
110018 int i = 0;
110019 static char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
110020 "ABCDEFGHIJKLMNOPQRSTUVWYXZ";
110021 for(p=pWInfo->pLoops; p; p=p->pNextLoop){
110022 p->cId = zLabel[(i++)%sizeof(zLabel)];
110023 whereLoopPrint(p, pTabList);
110024 }
110025 }
110026 #endif
110027
@@ -110058,15 +110157,46 @@
110058 sqlite3DebugPrintf(" DISTINCT=unordered");
110059 break;
110060 }
110061 }
110062 sqlite3DebugPrintf("\n");
110063 for(ii=0; ii<nTabList; ii++){
110064 whereLoopPrint(pWInfo->a[ii].pWLoop, pTabList);
110065 }
110066 }
110067 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110068 WHERETRACE(0xffff,("*** Optimizer Finished ***\n"));
110069 pWInfo->pParse->nQueryLoop += pWInfo->nRowOut;
110070
110071 /* If the caller is an UPDATE or DELETE statement that is requesting
110072 ** to use a one-pass algorithm, determine if this is appropriate.
@@ -110081,17 +110211,15 @@
110081 }
110082
110083 /* Open all tables in the pTabList and any indices selected for
110084 ** searching those tables.
110085 */
110086 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
110087 notReady = ~(Bitmask)0;
110088 for(ii=0, pLevel=pWInfo->a; ii<nTabList; ii++, pLevel++){
110089 Table *pTab; /* Table to open */
110090 int iDb; /* Index of database containing table/index */
110091 struct SrcList_item *pTabItem;
110092 WhereLoop *pLoop;
110093
110094 pTabItem = &pTabList->a[pLevel->iFrom];
110095 pTab = pTabItem->pTab;
110096 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
110097 pLoop = pLevel->pWLoop;
@@ -110123,11 +110251,11 @@
110123 }
110124 }else{
110125 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
110126 }
110127 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
110128 if( (pLoop->wsFlags & WHERE_TEMP_INDEX)!=0 ){
110129 constructAutomaticIndex(pParse, &pWInfo->sWC, pTabItem, notReady, pLevel);
110130 }else
110131 #endif
110132 if( pLoop->wsFlags & WHERE_INDEXED ){
110133 Index *pIx = pLoop->u.btree.pIndex;
@@ -110231,11 +110359,11 @@
110231 */
110232 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
110233
110234 /* Close all of the cursors that were opened by sqlite3WhereBegin.
110235 */
110236 assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc );
110237 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
110238 Index *pIdx = 0;
110239 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
110240 Table *pTab = pTabItem->pTab;
110241 assert( pTab!=0 );
@@ -110246,11 +110374,11 @@
110246 ){
110247 int ws = pLoop->wsFlags;
110248 if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
110249 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
110250 }
110251 if( (ws & WHERE_INDEXED)!=0 && (ws & (WHERE_IPK|WHERE_TEMP_INDEX))==0 ){
110252 sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
110253 }
110254 }
110255
110256 /* If this scan uses an index, make VDBE code substitutions to read data
@@ -114457,11 +114585,11 @@
114457 sqlite3 *db = pParse->db; /* The database connection */
114458 int mxSqlLen; /* Max length of an SQL string */
114459
114460
114461 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
114462 if( db->activeVdbeCnt==0 ){
114463 db->u1.isInterrupted = 0;
114464 }
114465 pParse->rc = SQLITE_OK;
114466 pParse->zTail = zSql;
114467 i = 0;
@@ -116025,10 +116153,11 @@
116025 case SQLITE_PERM: zName = "SQLITE_PERM"; break;
116026 case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
116027 case SQLITE_ABORT_ROLLBACK: zName = "SQLITE_ABORT_ROLLBACK"; break;
116028 case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
116029 case SQLITE_BUSY_RECOVERY: zName = "SQLITE_BUSY_RECOVERY"; break;
 
116030 case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break;
116031 case SQLITE_LOCKED_SHAREDCACHE: zName = "SQLITE_LOCKED_SHAREDCACHE";break;
116032 case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
116033 case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
116034 case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
@@ -116098,10 +116227,11 @@
116098 case SQLITE_NOTICE: zName = "SQLITE_NOTICE"; break;
116099 case SQLITE_NOTICE_RECOVER_WAL: zName = "SQLITE_NOTICE_RECOVER_WAL";break;
116100 case SQLITE_NOTICE_RECOVER_ROLLBACK:
116101 zName = "SQLITE_NOTICE_RECOVER_ROLLBACK"; break;
116102 case SQLITE_WARNING: zName = "SQLITE_WARNING"; break;
 
116103 case SQLITE_DONE: zName = "SQLITE_DONE"; break;
116104 }
116105 }
116106 if( zName==0 ){
116107 static char zBuf[50];
@@ -116356,11 +116486,11 @@
116356 ** is being overridden/deleted but there are no active VMs, allow the
116357 ** operation to continue but invalidate all precompiled statements.
116358 */
116359 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
116360 if( p && p->iPrefEnc==enc && p->nArg==nArg ){
116361 if( db->activeVdbeCnt ){
116362 sqlite3Error(db, SQLITE_BUSY,
116363 "unable to delete/modify user-function due to active statements");
116364 assert( !db->mallocFailed );
116365 return SQLITE_BUSY;
116366 }else{
@@ -116937,11 +117067,11 @@
116937 ** sequence. If so, and there are active VMs, return busy. If there
116938 ** are no active VMs, invalidate any pre-compiled statements.
116939 */
116940 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
116941 if( pColl && pColl->xCmp ){
116942 if( db->activeVdbeCnt ){
116943 sqlite3Error(db, SQLITE_BUSY,
116944 "unable to delete/modify collation sequence due to active statements");
116945 return SQLITE_BUSY;
116946 }
116947 sqlite3ExpirePreparedStatements(db);
@@ -117412,11 +117542,14 @@
117412 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
117413 db->autoCommit = 1;
117414 db->nextAutovac = -1;
117415 db->szMmap = sqlite3GlobalConfig.szMmap;
117416 db->nextPagesize = 0;
117417 db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex | SQLITE_EnableTrigger
 
 
 
117418 #if SQLITE_DEFAULT_FILE_FORMAT<4
117419 | SQLITE_LegacyFileFmt
117420 #endif
117421 #ifdef SQLITE_ENABLE_LOAD_EXTENSION
117422 | SQLITE_LoadExtension
@@ -119407,10 +119540,11 @@
119407 sqlite3 *db; /* The database connection */
119408 const char *zDb; /* logical database name */
119409 const char *zName; /* virtual table name */
119410 int nColumn; /* number of named columns in virtual table */
119411 char **azColumn; /* column names. malloced */
 
119412 sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */
119413 char *zContentTbl; /* content=xxx option, or NULL */
119414 char *zLanguageid; /* languageid=xxx option, or NULL */
119415 u8 bAutoincrmerge; /* True if automerge=1 */
119416 u32 nLeafAdd; /* Number of leaf blocks added this trans */
@@ -119634,11 +119768,10 @@
119634 sqlite3_int64, sqlite3_int64, const char *, int, Fts3SegReader**);
119635 SQLITE_PRIVATE int sqlite3Fts3SegReaderPending(
119636 Fts3Table*,int,const char*,int,int,Fts3SegReader**);
119637 SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *);
119638 SQLITE_PRIVATE int sqlite3Fts3AllSegdirs(Fts3Table*, int, int, int, sqlite3_stmt **);
119639 SQLITE_PRIVATE int sqlite3Fts3ReadLock(Fts3Table *);
119640 SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*);
119641
119642 SQLITE_PRIVATE int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **);
119643 SQLITE_PRIVATE int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **);
119644
@@ -120567,22 +120700,34 @@
120567 char *zPrefix = 0; /* Prefix parameter value (or NULL) */
120568 char *zCompress = 0; /* compress=? parameter (or NULL) */
120569 char *zUncompress = 0; /* uncompress=? parameter (or NULL) */
120570 char *zContent = 0; /* content=? parameter (or NULL) */
120571 char *zLanguageid = 0; /* languageid=? parameter (or NULL) */
 
 
120572
120573 assert( strlen(argv[0])==4 );
120574 assert( (sqlite3_strnicmp(argv[0], "fts4", 4)==0 && isFts4)
120575 || (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4)
120576 );
120577
120578 nDb = (int)strlen(argv[1]) + 1;
120579 nName = (int)strlen(argv[2]) + 1;
120580
120581 aCol = (const char **)sqlite3_malloc(sizeof(const char *) * (argc-2) );
120582 if( !aCol ) return SQLITE_NOMEM;
120583 memset((void *)aCol, 0, sizeof(const char *) * (argc-2));
 
 
 
 
 
 
 
 
 
 
120584
120585 /* Loop through all of the arguments passed by the user to the FTS3/4
120586 ** module (i.e. all the column names and special arguments). This loop
120587 ** does the following:
120588 **
@@ -120617,11 +120762,12 @@
120617 { "prefix", 6 }, /* 1 -> PREFIX */
120618 { "compress", 8 }, /* 2 -> COMPRESS */
120619 { "uncompress", 10 }, /* 3 -> UNCOMPRESS */
120620 { "order", 5 }, /* 4 -> ORDER */
120621 { "content", 7 }, /* 5 -> CONTENT */
120622 { "languageid", 10 } /* 6 -> LANGUAGEID */
 
120623 };
120624
120625 int iOpt;
120626 if( !zVal ){
120627 rc = SQLITE_NOMEM;
@@ -120683,10 +120829,15 @@
120683 assert( iOpt==6 );
120684 sqlite3_free(zLanguageid);
120685 zLanguageid = zVal;
120686 zVal = 0;
120687 break;
 
 
 
 
 
120688 }
120689 }
120690 sqlite3_free(zVal);
120691 }
120692 }
@@ -120754,10 +120905,11 @@
120754
120755 /* Allocate and populate the Fts3Table structure. */
120756 nByte = sizeof(Fts3Table) + /* Fts3Table */
120757 nCol * sizeof(char *) + /* azColumn */
120758 nIndex * sizeof(struct Fts3Index) + /* aIndex */
 
120759 nName + /* zName */
120760 nDb + /* zDb */
120761 nString; /* Space for azColumn strings */
120762 p = (Fts3Table*)sqlite3_malloc(nByte);
120763 if( p==0 ){
@@ -120787,13 +120939,14 @@
120787 memcpy(p->aIndex, aIndex, sizeof(struct Fts3Index) * nIndex);
120788 p->nIndex = nIndex;
120789 for(i=0; i<nIndex; i++){
120790 fts3HashInit(&p->aIndex[i].hPending, FTS3_HASH_STRING, 1);
120791 }
 
120792
120793 /* Fill in the zName and zDb fields of the vtab structure. */
120794 zCsr = (char *)&p->aIndex[nIndex];
120795 p->zName = zCsr;
120796 memcpy(zCsr, argv[2], nName);
120797 zCsr += nName;
120798 p->zDb = zCsr;
120799 memcpy(zCsr, argv[1], nDb);
@@ -120810,11 +120963,30 @@
120810 p->azColumn[iCol] = zCsr;
120811 zCsr += n+1;
120812 assert( zCsr <= &((char *)p)[nByte] );
120813 }
120814
120815 if( (zCompress==0)!=(zUncompress==0) ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120816 char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
120817 rc = SQLITE_ERROR;
120818 *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
120819 }
120820 p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
@@ -120851,11 +121023,13 @@
120851 sqlite3_free(aIndex);
120852 sqlite3_free(zCompress);
120853 sqlite3_free(zUncompress);
120854 sqlite3_free(zContent);
120855 sqlite3_free(zLanguageid);
 
120856 sqlite3_free((void *)aCol);
 
120857 if( rc!=SQLITE_OK ){
120858 if( p ){
120859 fts3DisconnectMethod((sqlite3_vtab *)p);
120860 }else if( pTokenizer ){
120861 pTokenizer->pModule->xDestroy(pTokenizer);
@@ -129717,16 +129891,19 @@
129717 sqlite3_value **apVal,
129718 u32 *aSz
129719 ){
129720 int i; /* Iterator variable */
129721 for(i=2; i<p->nColumn+2; i++){
129722 const char *zText = (const char *)sqlite3_value_text(apVal[i]);
129723 int rc = fts3PendingTermsAdd(p, iLangid, zText, i-2, &aSz[i-2]);
129724 if( rc!=SQLITE_OK ){
129725 return rc;
 
 
 
 
129726 }
129727 aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]);
129728 }
129729 return SQLITE_OK;
129730 }
129731
129732 /*
@@ -129869,13 +130046,16 @@
129869 if( SQLITE_ROW==sqlite3_step(pSelect) ){
129870 int i;
129871 int iLangid = langidFromSelect(p, pSelect);
129872 rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pSelect, 0));
129873 for(i=1; rc==SQLITE_OK && i<=p->nColumn; i++){
129874 const char *zText = (const char *)sqlite3_column_text(pSelect, i);
129875 rc = fts3PendingTermsAdd(p, iLangid, zText, -1, &aSz[i-1]);
129876 aSz[p->nColumn] += sqlite3_column_bytes(pSelect, i);
 
 
 
129877 }
129878 if( rc!=SQLITE_OK ){
129879 sqlite3_reset(pSelect);
129880 *pRC = rc;
129881 return;
@@ -132113,13 +132293,15 @@
132113 int iCol;
132114 int iLangid = langidFromSelect(p, pStmt);
132115 rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pStmt, 0));
132116 memset(aSz, 0, sizeof(aSz[0]) * (p->nColumn+1));
132117 for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){
132118 const char *z = (const char *) sqlite3_column_text(pStmt, iCol+1);
132119 rc = fts3PendingTermsAdd(p, iLangid, z, iCol, &aSz[iCol]);
132120 aSz[p->nColumn] += sqlite3_column_bytes(pStmt, iCol+1);
 
 
132121 }
132122 if( p->bHasDocsize ){
132123 fts3InsertDocsize(&rc, p, aSz);
132124 }
132125 if( rc!=SQLITE_OK ){
@@ -133918,39 +134100,41 @@
133918
133919 assert( pCsr->isRequireSeek==0 );
133920 iDocid = sqlite3_column_int64(pCsr->pStmt, 0);
133921
133922 for(i=0; i<p->nColumn && rc==SQLITE_OK; i++){
133923 const char *zText = (const char *)sqlite3_column_text(pCsr->pStmt, i+1);
133924 sqlite3_tokenizer_cursor *pTC = 0;
133925
133926 rc = sqlite3Fts3OpenTokenizer(pT, pCsr->iLangid, zText, -1, &pTC);
133927 while( rc==SQLITE_OK ){
133928 char const *zToken; /* Buffer containing token */
133929 int nToken = 0; /* Number of bytes in token */
133930 int iDum1 = 0, iDum2 = 0; /* Dummy variables */
133931 int iPos = 0; /* Position of token in zText */
133932
133933 rc = pModule->xNext(pTC, &zToken, &nToken, &iDum1, &iDum2, &iPos);
133934 for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
133935 Fts3PhraseToken *pPT = pDef->pToken;
133936 if( (pDef->iCol>=p->nColumn || pDef->iCol==i)
133937 && (pPT->bFirst==0 || iPos==0)
133938 && (pPT->n==nToken || (pPT->isPrefix && pPT->n<nToken))
133939 && (0==memcmp(zToken, pPT->z, pPT->n))
133940 ){
133941 fts3PendingListAppend(&pDef->pList, iDocid, i, iPos, &rc);
133942 }
133943 }
133944 }
133945 if( pTC ) pModule->xClose(pTC);
133946 if( rc==SQLITE_DONE ) rc = SQLITE_OK;
133947 }
133948
133949 for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
133950 if( pDef->pList ){
133951 rc = fts3PendingListAppendVarint(&pDef->pList, 0);
 
 
133952 }
133953 }
133954 }
133955
133956 return rc;
133957
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -668,13 +668,13 @@
668 **
669 ** See also: [sqlite3_libversion()],
670 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671 ** [sqlite_version()] and [sqlite_source_id()].
672 */
673 #define SQLITE_VERSION "3.8.0"
674 #define SQLITE_VERSION_NUMBER 3008000
675 #define SQLITE_SOURCE_ID "2013-07-09 03:04:32 52a49cbc1621094b2fe2b021209b768d29e0426b"
676
677 /*
678 ** CAPI3REF: Run-Time Library Version Numbers
679 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
680 **
@@ -1041,10 +1041,11 @@
1041 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
1042 #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
1043 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
1044 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
1045 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
1046 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
1047 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
1048 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
1049 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
1050 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
1051 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
@@ -1060,10 +1061,11 @@
1061 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
1062 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
1063 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
1064 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
1065 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
1066 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
1067
1068 /*
1069 ** CAPI3REF: Flags For File Open Operations
1070 **
1071 ** These bit values are intended for use in the
@@ -6869,15 +6871,25 @@
6871 ** <dd>^This is the number of rows inserted into transient indices that
6872 ** were created automatically in order to help joins run faster.
6873 ** A non-zero value in this counter may indicate an opportunity to
6874 ** improvement performance by adding permanent indices that do not
6875 ** need to be reinitialized each time the statement is run.</dd>
6876 **
6877 ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
6878 ** <dd>^This is the number of virtual machine operations executed
6879 ** by the prepared statement if that number is less than or equal
6880 ** to 2147483647. The number of virtual machine operations can be
6881 ** used as a proxy for the total work done by the prepared statement.
6882 ** If the number of virtual machine operations exceeds 2147483647
6883 ** then the value returned by this statement status code is undefined.
6884 ** </dd>
6885 ** </dl>
6886 */
6887 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
6888 #define SQLITE_STMTSTATUS_SORT 2
6889 #define SQLITE_STMTSTATUS_AUTOINDEX 3
6890 #define SQLITE_STMTSTATUS_VM_STEP 4
6891
6892 /*
6893 ** CAPI3REF: Custom Page Cache Object
6894 **
6895 ** The sqlite3_pcache type is opaque. It is implemented by
@@ -10066,13 +10078,14 @@
10078 int newTnum; /* Rootpage of table being initialized */
10079 u8 iDb; /* Which db file is being initialized */
10080 u8 busy; /* TRUE if currently initializing */
10081 u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */
10082 } init;
10083 int nVdbeActive; /* Number of VDBEs currently running */
10084 int nVdbeRead; /* Number of active VDBEs that read or write */
10085 int nVdbeWrite; /* Number of active VDBEs that read and write */
10086 int nVdbeExec; /* Number of nested calls to VdbeExec() */
10087 int nExtension; /* Number of loaded extensions */
10088 void **aExtension; /* Array of shared library handles */
10089 void (*xTrace)(void*,const char*); /* Trace function */
10090 void *pTraceArg; /* Argument to the trace function */
10091 void (*xProfile)(void*,const char*,u64); /* Profiling function */
@@ -10193,10 +10206,12 @@
10206 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
10207 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
10208 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10209 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10210 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
10211 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
10212 #define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */
10213 #define SQLITE_AllOpts 0xffff /* All optimizations */
10214
10215 /*
10216 ** Macros for testing whether or not optimizations are enabled or disabled.
10217 */
@@ -11143,10 +11158,11 @@
11158 #define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
11159 #define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
11160 #define WHERE_AND_ONLY 0x0080 /* Don't use indices for OR terms */
11161 #define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
11162 #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
11163 #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
11164
11165 /* Allowed return values from sqlite3WhereIsDistinct()
11166 */
11167 #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
11168 #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */
@@ -13500,18 +13516,19 @@
13516 bft inVtabMethod:2; /* See comments above */
13517 bft changeCntOn:1; /* True to update the change-counter */
13518 bft expired:1; /* True if the VM needs to be recompiled */
13519 bft runOnlyOnce:1; /* Automatically expire on reset */
13520 bft usesStmtJournal:1; /* True if uses a statement journal */
13521 bft readOnly:1; /* True for statements that do not write */
13522 bft bIsReader:1; /* True for statements that read */
13523 bft isPrepareV2:1; /* True if prepared with prepare_v2() */
13524 bft doingRerun:1; /* True if rerunning after an auto-reprepare */
13525 int nChange; /* Number of db changes made since last reset */
13526 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
13527 yDbMask lockMask; /* Subset of btreeMask that requires a lock */
13528 int iStatement; /* Statement number (or 0 if has not opened stmt) */
13529 int aCounter[4]; /* Counters used by sqlite3_stmt_status() */
13530 #ifndef SQLITE_OMIT_TRACE
13531 i64 startTime; /* Time when query started - used for profiling */
13532 #endif
13533 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
13534 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
@@ -19937,12 +19954,12 @@
19954 if( xtype==etEXP ){
19955 e2 = 0;
19956 }else{
19957 e2 = exp;
19958 }
19959 if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){
19960 bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 );
19961 if( bufpt==0 ){
19962 pAccum->mallocFailed = 1;
19963 return;
19964 }
19965 }
@@ -40058,10 +40075,11 @@
40075 assert( !MEMDB );
40076 pager_reset(pPager);
40077 pPager->changeCountDone = pPager->tempFile;
40078 pPager->eState = PAGER_OPEN;
40079 pPager->errCode = SQLITE_OK;
40080 if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
40081 }
40082
40083 pPager->journalOff = 0;
40084 pPager->journalHdr = 0;
40085 pPager->setMaster = 0;
@@ -41624,14 +41642,14 @@
41642 ** Invoke SQLITE_FCNTL_MMAP_SIZE based on the current value of szMmap.
41643 */
41644 static void pagerFixMaplimit(Pager *pPager){
41645 #if SQLITE_MAX_MMAP_SIZE>0
41646 sqlite3_file *fd = pPager->fd;
41647 if( isOpen(fd) && fd->pMethods->iVersion>=3 ){
41648 sqlite3_int64 sz;
 
41649 sz = pPager->szMmap;
41650 pPager->bUseFetch = (sz>0);
41651 sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_SIZE, &sz);
41652 }
41653 #endif
41654 }
41655
@@ -47879,11 +47897,11 @@
47897 ** the write is disallowed.
47898 */
47899 if( memcmp(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr))!=0 ){
47900 walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1);
47901 pWal->writeLock = 0;
47902 rc = SQLITE_BUSY_SNAPSHOT;
47903 }
47904
47905 return rc;
47906 }
47907
@@ -52739,16 +52757,17 @@
52757 ** This function is called from both BtreeCommitPhaseTwo() and BtreeRollback()
52758 ** at the conclusion of a transaction.
52759 */
52760 static void btreeEndTransaction(Btree *p){
52761 BtShared *pBt = p->pBt;
52762 sqlite3 *db = p->db;
52763 assert( sqlite3BtreeHoldsMutex(p) );
52764
52765 #ifndef SQLITE_OMIT_AUTOVACUUM
52766 pBt->bDoTruncate = 0;
52767 #endif
52768 if( p->inTrans>TRANS_NONE && db->nVdbeRead>1 ){
52769 /* If there are other active statements that belong to this database
52770 ** handle, downgrade to a read-only transaction. The other statements
52771 ** may still be reading from the database. */
52772 downgradeAllSharedCacheTableLocks(p);
52773 p->inTrans = TRANS_READ;
@@ -60265,18 +60284,30 @@
60284 int i;
60285 int nMaxArgs = *pMaxFuncArgs;
60286 Op *pOp;
60287 int *aLabel = p->aLabel;
60288 p->readOnly = 1;
60289 p->bIsReader = 0;
60290 for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
60291 u8 opcode = pOp->opcode;
60292
60293 pOp->opflags = sqlite3OpcodeProperty[opcode];
60294 if( opcode==OP_Function || opcode==OP_AggStep ){
60295 if( pOp->p5>nMaxArgs ) nMaxArgs = pOp->p5;
60296 }else if( opcode==OP_Transaction ){
60297 if( pOp->p2!=0 ) p->readOnly = 0;
60298 p->bIsReader = 1;
60299 }else if( opcode==OP_AutoCommit || opcode==OP_Savepoint ){
60300 p->bIsReader = 1;
60301 }else if( opcode==OP_Vacuum
60302 || opcode==OP_JournalMode
60303 #ifndef SQLITE_OMIT_WAL
60304 || opcode==OP_Checkpoint
60305 #endif
60306 ){
60307 p->readOnly = 0;
60308 p->bIsReader = 1;
60309 #ifndef SQLITE_OMIT_VIRTUALTABLE
60310 }else if( opcode==OP_VUpdate ){
60311 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
60312 }else if( opcode==OP_VFilter ){
60313 int n;
@@ -60298,12 +60329,12 @@
60329 pOp->p2 = aLabel[-1-pOp->p2];
60330 }
60331 }
60332 sqlite3DbFree(p->db, p->aLabel);
60333 p->aLabel = 0;
 
60334 *pMaxFuncArgs = nMaxArgs;
60335 assert( p->bIsReader!=0 || p->btreeMask==0 );
60336 }
60337
60338 /*
60339 ** Return the address of the next instruction to be inserted.
60340 */
@@ -61825,11 +61856,11 @@
61856
61857 return rc;
61858 }
61859
61860 /*
61861 ** This routine checks that the sqlite3.nVdbeActive count variable
61862 ** matches the number of vdbe's in the list sqlite3.pVdbe that are
61863 ** currently active. An assertion fails if the two counts do not match.
61864 ** This is an internal self-check only - it is not an essential processing
61865 ** step.
61866 **
@@ -61838,20 +61869,23 @@
61869 #ifndef NDEBUG
61870 static void checkActiveVdbeCnt(sqlite3 *db){
61871 Vdbe *p;
61872 int cnt = 0;
61873 int nWrite = 0;
61874 int nRead = 0;
61875 p = db->pVdbe;
61876 while( p ){
61877 if( p->magic==VDBE_MAGIC_RUN && p->pc>=0 ){
61878 cnt++;
61879 if( p->readOnly==0 ) nWrite++;
61880 if( p->bIsReader ) nRead++;
61881 }
61882 p = p->pNext;
61883 }
61884 assert( cnt==db->nVdbeActive );
61885 assert( nWrite==db->nVdbeWrite );
61886 assert( nRead==db->nVdbeRead );
61887 }
61888 #else
61889 #define checkActiveVdbeCnt(x)
61890 #endif
61891
@@ -61983,12 +62017,13 @@
62017 if( p->magic!=VDBE_MAGIC_RUN ){
62018 return SQLITE_OK;
62019 }
62020 checkActiveVdbeCnt(db);
62021
62022 /* No commit or rollback needed if the program never started or if the
62023 ** SQL statement does not read or write a database file. */
62024 if( p->pc>=0 && p->bIsReader ){
62025 int mrc; /* Primary error code from p->rc */
62026 int eStatementOp = 0;
62027 int isSpecialError; /* Set to true if a 'special' error */
62028
62029 /* Lock all btrees used by the statement */
@@ -62037,11 +62072,11 @@
62072 ** Note: This block also runs if one of the special errors handled
62073 ** above has occurred.
62074 */
62075 if( !sqlite3VtabInSync(db)
62076 && db->autoCommit
62077 && db->nVdbeWrite==(p->readOnly==0)
62078 ){
62079 if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){
62080 rc = sqlite3VdbeCheckFk(p, 1);
62081 if( rc!=SQLITE_OK ){
62082 if( NEVER(p->readOnly) ){
@@ -62118,15 +62153,16 @@
62153 sqlite3VdbeLeave(p);
62154 }
62155
62156 /* We have successfully halted and closed the VM. Record this fact. */
62157 if( p->pc>=0 ){
62158 db->nVdbeActive--;
62159 if( !p->readOnly ) db->nVdbeWrite--;
62160 if( p->bIsReader ) db->nVdbeRead--;
62161 assert( db->nVdbeActive>=db->nVdbeRead );
62162 assert( db->nVdbeRead>=db->nVdbeWrite );
62163 assert( db->nVdbeWrite>=0 );
62164 }
62165 p->magic = VDBE_MAGIC_HALT;
62166 checkActiveVdbeCnt(db);
62167 if( p->db->mallocFailed ){
62168 p->rc = SQLITE_NOMEM;
@@ -62138,11 +62174,11 @@
62174 */
62175 if( db->autoCommit ){
62176 sqlite3ConnectionUnlocked(db);
62177 }
62178
62179 assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 );
62180 return (p->rc==SQLITE_BUSY ? SQLITE_BUSY : SQLITE_OK);
62181 }
62182
62183
62184 /*
@@ -63496,35 +63532,36 @@
63532 if( p->pc<0 ){
63533 /* If there are no other statements currently running, then
63534 ** reset the interrupt flag. This prevents a call to sqlite3_interrupt
63535 ** from interrupting a statement that has not yet started.
63536 */
63537 if( db->nVdbeActive==0 ){
63538 db->u1.isInterrupted = 0;
63539 }
63540
63541 assert( db->nVdbeWrite>0 || db->autoCommit==0 || db->nDeferredCons==0 );
63542
63543 #ifndef SQLITE_OMIT_TRACE
63544 if( db->xProfile && !db->init.busy ){
63545 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
63546 }
63547 #endif
63548
63549 db->nVdbeActive++;
63550 if( p->readOnly==0 ) db->nVdbeWrite++;
63551 if( p->bIsReader ) db->nVdbeRead++;
63552 p->pc = 0;
63553 }
63554 #ifndef SQLITE_OMIT_EXPLAIN
63555 if( p->explain ){
63556 rc = sqlite3VdbeList(p);
63557 }else
63558 #endif /* SQLITE_OMIT_EXPLAIN */
63559 {
63560 db->nVdbeExec++;
63561 rc = sqlite3VdbeExec(p);
63562 db->nVdbeExec--;
63563 }
63564
63565 #ifndef SQLITE_OMIT_TRACE
63566 /* Invoke the profile callback if there is one
63567 */
@@ -64457,13 +64494,13 @@
64494 return nTotal;
64495 }
64496
64497 /*
64498 ** This function returns a pointer to a nul-terminated string in memory
64499 ** obtained from sqlite3DbMalloc(). If sqlite3.nVdbeExec is 1, then the
64500 ** string contains a copy of zRawSql but with host parameters expanded to
64501 ** their current bindings. Or, if sqlite3.nVdbeExec is greater than 1,
64502 ** then the returned string holds a copy of zRawSql with "-- " prepended
64503 ** to each line of text.
64504 **
64505 ** If the SQLITE_TRACE_SIZE_LIMIT macro is defined to an integer, then
64506 ** then long strings and blobs are truncated to that many bytes. This
@@ -64497,11 +64534,11 @@
64534
64535 db = p->db;
64536 sqlite3StrAccumInit(&out, zBase, sizeof(zBase),
64537 db->aLimit[SQLITE_LIMIT_LENGTH]);
64538 out.db = db;
64539 if( db->nVdbeExec>1 ){
64540 while( *zRawSql ){
64541 const char *zStart = zRawSql;
64542 while( *(zRawSql++)!='\n' && *zRawSql );
64543 sqlite3StrAccumAppend(&out, "-- ", 3);
64544 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
@@ -65351,16 +65388,17 @@
65388 u8 encoding = ENC(db); /* The database encoding */
65389 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65390 int checkProgress; /* True if progress callbacks are enabled */
65391 int nProgressOps = 0; /* Opcodes executed since progress callback. */
65392 #endif
65393 int iCompare = 0; /* Result of last OP_Compare operation */
65394 unsigned nVmStep = 0; /* Number of virtual machine steps */
65395 Mem *aMem = p->aMem; /* Copy of p->aMem */
65396 Mem *pIn1 = 0; /* 1st input operand */
65397 Mem *pIn2 = 0; /* 2nd input operand */
65398 Mem *pIn3 = 0; /* 3rd input operand */
65399 Mem *pOut = 0; /* Output operand */
 
65400 int *aPermute = 0; /* Permutation of columns for OP_Compare */
65401 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
65402 #ifdef VDBE_PROFILE
65403 u64 start; /* CPU clock count at start of opcode */
65404 int origPc; /* Program counter at start of opcode */
@@ -65802,10 +65840,11 @@
65840 /* This happens if a malloc() inside a call to sqlite3_column_text() or
65841 ** sqlite3_column_text16() failed. */
65842 goto no_mem;
65843 }
65844 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY );
65845 assert( p->bIsReader || p->readOnly!=0 );
65846 p->rc = SQLITE_OK;
65847 assert( p->explain==0 );
65848 p->pResultSet = 0;
65849 db->busyHandler.nBusy = 0;
65850 CHECK_FOR_INTERRUPT;
@@ -65830,10 +65869,11 @@
65869 if( db->mallocFailed ) goto no_mem;
65870 #ifdef VDBE_PROFILE
65871 origPc = pc;
65872 start = sqlite3Hwtime();
65873 #endif
65874 nVmStep++;
65875 pOp = &aOp[pc];
65876
65877 /* Only allow tracing if SQLITE_DEBUG is defined.
65878 */
65879 #ifdef SQLITE_DEBUG
@@ -67945,13 +67985,14 @@
67985 */
67986 assert( db->pSavepoint==0 || db->autoCommit==0 );
67987 assert( u.as.p1==SAVEPOINT_BEGIN||u.as.p1==SAVEPOINT_RELEASE||u.as.p1==SAVEPOINT_ROLLBACK );
67988 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
67989 assert( checkSavepointCount(db) );
67990 assert( p->bIsReader );
67991
67992 if( u.as.p1==SAVEPOINT_BEGIN ){
67993 if( db->nVdbeWrite>0 ){
67994 /* A new savepoint cannot be created if there are active write
67995 ** statements (i.e. open read/write incremental blob handles).
67996 */
67997 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
67998 "SQL statements in progress");
@@ -68004,11 +68045,11 @@
68045 u.as.iSavepoint++;
68046 }
68047 if( !u.as.pSavepoint ){
68048 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.as.zName);
68049 rc = SQLITE_ERROR;
68050 }else if( db->nVdbeWrite>0 && u.as.p1==SAVEPOINT_RELEASE ){
68051 /* It is not possible to release (commit) a savepoint if there are
68052 ** active write statements.
68053 */
68054 sqlite3SetString(&p->zErrMsg, db,
68055 "cannot release savepoint - SQL statements in progress"
@@ -68107,24 +68148,25 @@
68148 u.at.desiredAutoCommit = pOp->p1;
68149 u.at.iRollback = pOp->p2;
68150 u.at.turnOnAC = u.at.desiredAutoCommit && !db->autoCommit;
68151 assert( u.at.desiredAutoCommit==1 || u.at.desiredAutoCommit==0 );
68152 assert( u.at.desiredAutoCommit==1 || u.at.iRollback==0 );
68153 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
68154 assert( p->bIsReader );
68155
68156 #if 0
68157 if( u.at.turnOnAC && u.at.iRollback && db->nVdbeActive>1 ){
68158 /* If this instruction implements a ROLLBACK and other VMs are
68159 ** still running, and a transaction is active, return an error indicating
68160 ** that the other VMs must complete first.
68161 */
68162 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
68163 "SQL statements in progress");
68164 rc = SQLITE_BUSY;
68165 }else
68166 #endif
68167 if( u.at.turnOnAC && !u.at.iRollback && db->nVdbeWrite>0 ){
68168 /* If this instruction implements a COMMIT and other VMs are writing
68169 ** return an error indicating that the other VMs must complete first.
68170 */
68171 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
68172 "SQL statements in progress");
@@ -68198,10 +68240,12 @@
68240 case OP_Transaction: {
68241 #if 0 /* local variables moved into u.au */
68242 Btree *pBt;
68243 #endif /* local variables moved into u.au */
68244
68245 assert( p->bIsReader );
68246 assert( p->readOnly==0 || pOp->p2==0 );
68247 assert( pOp->p1>=0 && pOp->p1<db->nDb );
68248 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
68249 u.au.pBt = db->aDb[pOp->p1].pBt;
68250
68251 if( u.au.pBt ){
@@ -68214,11 +68258,11 @@
68258 if( rc!=SQLITE_OK ){
68259 goto abort_due_to_error;
68260 }
68261
68262 if( pOp->p2 && p->usesStmtJournal
68263 && (db->autoCommit==0 || db->nVdbeRead>1)
68264 ){
68265 assert( sqlite3BtreeIsInTrans(u.au.pBt) );
68266 if( p->iStatement==0 ){
68267 assert( db->nStatement>=0 && db->nSavepoint>=0 );
68268 db->nStatement++;
@@ -68256,10 +68300,11 @@
68300 int iMeta;
68301 int iDb;
68302 int iCookie;
68303 #endif /* local variables moved into u.av */
68304
68305 assert( p->bIsReader );
68306 u.av.iDb = pOp->p1;
68307 u.av.iCookie = pOp->p3;
68308 assert( pOp->p3<SQLITE_N_BTREE_META );
68309 assert( u.av.iDb>=0 && u.av.iDb<db->nDb );
68310 assert( db->aDb[u.av.iDb].pBt!=0 );
@@ -68285,10 +68330,11 @@
68330 Db *pDb;
68331 #endif /* local variables moved into u.aw */
68332 assert( pOp->p2<SQLITE_N_BTREE_META );
68333 assert( pOp->p1>=0 && pOp->p1<db->nDb );
68334 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
68335 assert( p->readOnly==0 );
68336 u.aw.pDb = &db->aDb[pOp->p1];
68337 assert( u.aw.pDb->pBt!=0 );
68338 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
68339 pIn3 = &aMem[pOp->p3];
68340 sqlite3VdbeMemIntegerify(pIn3);
@@ -68337,10 +68383,11 @@
68383 #endif /* local variables moved into u.ax */
68384
68385 assert( pOp->p1>=0 && pOp->p1<db->nDb );
68386 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
68387 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
68388 assert( p->bIsReader );
68389 u.ax.pBt = db->aDb[pOp->p1].pBt;
68390 if( u.ax.pBt ){
68391 sqlite3BtreeGetMeta(u.ax.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ax.iMeta);
68392 u.ax.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
68393 }else{
@@ -68434,10 +68481,12 @@
68481 Db *pDb;
68482 #endif /* local variables moved into u.ay */
68483
68484 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
68485 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
68486 assert( p->bIsReader );
68487 assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
68488
68489 if( p->expired ){
68490 rc = SQLITE_ABORT;
68491 break;
68492 }
@@ -70052,19 +70101,22 @@
70101 int iCnt;
70102 Vdbe *pVdbe;
70103 int iDb;
70104 #endif /* local variables moved into u.bw */
70105
70106 assert( p->readOnly==0 );
70107 #ifndef SQLITE_OMIT_VIRTUALTABLE
70108 u.bw.iCnt = 0;
70109 for(u.bw.pVdbe=db->pVdbe; u.bw.pVdbe; u.bw.pVdbe = u.bw.pVdbe->pNext){
70110 if( u.bw.pVdbe->magic==VDBE_MAGIC_RUN && u.bw.pVdbe->bIsReader
70111 && u.bw.pVdbe->inVtabMethod<2 && u.bw.pVdbe->pc>=0
70112 ){
70113 u.bw.iCnt++;
70114 }
70115 }
70116 #else
70117 u.bw.iCnt = db->nVdbeRead;
70118 #endif
70119 pOut->flags = MEM_Null;
70120 if( u.bw.iCnt>1 ){
70121 rc = SQLITE_LOCKED;
70122 p->errorAction = OE_Abort;
@@ -70109,10 +70161,11 @@
70161 #if 0 /* local variables moved into u.bx */
70162 int nChange;
70163 #endif /* local variables moved into u.bx */
70164
70165 u.bx.nChange = 0;
70166 assert( p->readOnly==0 );
70167 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
70168 rc = sqlite3BtreeClearTable(
70169 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bx.nChange : 0)
70170 );
70171 if( pOp->p3 ){
@@ -70157,10 +70210,11 @@
70210 #endif /* local variables moved into u.by */
70211
70212 u.by.pgno = 0;
70213 assert( pOp->p1>=0 && pOp->p1<db->nDb );
70214 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
70215 assert( p->readOnly==0 );
70216 u.by.pDb = &db->aDb[pOp->p1];
70217 assert( u.by.pDb->pBt!=0 );
70218 if( pOp->opcode==OP_CreateTable ){
70219 /* u.by.flags = BTREE_INTKEY; */
70220 u.by.flags = BTREE_INTKEY;
@@ -70309,10 +70363,11 @@
70363 int nErr; /* Number of errors reported */
70364 char *z; /* Text of the error report */
70365 Mem *pnErr; /* Register keeping track of errors remaining */
70366 #endif /* local variables moved into u.ca */
70367
70368 assert( p->bIsReader );
70369 u.ca.nRoot = pOp->p2;
70370 assert( u.ca.nRoot>0 );
70371 u.ca.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.ca.nRoot+1) );
70372 if( u.ca.aRoot==0 ) goto no_mem;
70373 assert( pOp->p3>0 && pOp->p3<=p->nMem );
@@ -70830,10 +70885,11 @@
70885 int i; /* Loop counter */
70886 int aRes[3]; /* Results */
70887 Mem *pMem; /* Write results here */
70888 #endif /* local variables moved into u.ci */
70889
70890 assert( p->readOnly==0 );
70891 u.ci.aRes[0] = 0;
70892 u.ci.aRes[1] = u.ci.aRes[2] = -1;
70893 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
70894 || pOp->p2==SQLITE_CHECKPOINT_FULL
70895 || pOp->p2==SQLITE_CHECKPOINT_RESTART
@@ -70881,10 +70937,11 @@
70937 || u.cj.eNew==PAGER_JOURNALMODE_MEMORY
70938 || u.cj.eNew==PAGER_JOURNALMODE_WAL
70939 || u.cj.eNew==PAGER_JOURNALMODE_QUERY
70940 );
70941 assert( pOp->p1>=0 && pOp->p1<db->nDb );
70942 assert( p->readOnly==0 );
70943
70944 u.cj.pBt = db->aDb[pOp->p1].pBt;
70945 u.cj.pPager = sqlite3BtreePager(u.cj.pBt);
70946 u.cj.eOld = sqlite3PagerGetJournalMode(u.cj.pPager);
70947 if( u.cj.eNew==PAGER_JOURNALMODE_QUERY ) u.cj.eNew = u.cj.eOld;
@@ -70904,11 +70961,11 @@
70961 }
70962
70963 if( (u.cj.eNew!=u.cj.eOld)
70964 && (u.cj.eOld==PAGER_JOURNALMODE_WAL || u.cj.eNew==PAGER_JOURNALMODE_WAL)
70965 ){
70966 if( !db->autoCommit || db->nVdbeRead>1 ){
70967 rc = SQLITE_ERROR;
70968 sqlite3SetString(&p->zErrMsg, db,
70969 "cannot change %s wal mode from within a transaction",
70970 (u.cj.eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of")
70971 );
@@ -70963,10 +71020,11 @@
71020 ** Vacuum the entire database. This opcode will cause other virtual
71021 ** machines to be created and run. It may not be called from within
71022 ** a transaction.
71023 */
71024 case OP_Vacuum: {
71025 assert( p->readOnly==0 );
71026 rc = sqlite3RunVacuum(&p->zErrMsg, db);
71027 break;
71028 }
71029 #endif
71030
@@ -70982,10 +71040,11 @@
71040 Btree *pBt;
71041 #endif /* local variables moved into u.ck */
71042
71043 assert( pOp->p1>=0 && pOp->p1<db->nDb );
71044 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
71045 assert( p->readOnly==0 );
71046 u.ck.pBt = db->aDb[pOp->p1].pBt;
71047 rc = sqlite3BtreeIncrVacuum(u.ck.pBt);
71048 if( rc==SQLITE_DONE ){
71049 pc = pOp->p2 - 1;
71050 rc = SQLITE_OK;
@@ -71104,10 +71163,11 @@
71163 sqlite3_vtab_cursor *pVtabCursor;
71164 sqlite3_vtab *pVtab;
71165 sqlite3_module *pModule;
71166 #endif /* local variables moved into u.cm */
71167
71168 assert( p->bIsReader );
71169 u.cm.pCur = 0;
71170 u.cm.pVtabCursor = 0;
71171 u.cm.pVtab = pOp->p4.pVtab->pVtab;
71172 u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule;
71173 assert(u.cm.pVtab && u.cm.pModule);
@@ -71328,10 +71388,11 @@
71388
71389 u.cq.pVtab = pOp->p4.pVtab->pVtab;
71390 u.cq.pName = &aMem[pOp->p1];
71391 assert( u.cq.pVtab->pModule->xRename );
71392 assert( memIsValid(u.cq.pName) );
71393 assert( p->readOnly==0 );
71394 REGISTER_TRACE(pOp->p1, u.cq.pName);
71395 assert( u.cq.pName->flags & MEM_Str );
71396 testcase( u.cq.pName->enc==SQLITE_UTF8 );
71397 testcase( u.cq.pName->enc==SQLITE_UTF16BE );
71398 testcase( u.cq.pName->enc==SQLITE_UTF16LE );
@@ -71381,10 +71442,11 @@
71442 #endif /* local variables moved into u.cr */
71443
71444 assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
71445 || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
71446 );
71447 assert( p->readOnly==0 );
71448 u.cr.pVtab = pOp->p4.pVtab->pVtab;
71449 u.cr.pModule = (sqlite3_module *)u.cr.pVtab->pModule;
71450 u.cr.nArg = pOp->p2;
71451 assert( pOp->p4type==P4_VTAB );
71452 if( ALWAYS(u.cr.pModule->xUpdate) ){
@@ -71566,10 +71628,11 @@
71628 /* This is the only way out of this procedure. We have to
71629 ** release the mutexes on btrees that were acquired at the
71630 ** top. */
71631 vdbe_return:
71632 db->lastRowid = lastRowid;
71633 p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1] += (int)nVmStep;
71634 sqlite3VdbeLeave(p);
71635 return rc;
71636
71637 /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
71638 ** is encountered.
@@ -76044,10 +76107,11 @@
76107 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
76108 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
76109 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
76110 pItem->sortOrder = pOldItem->sortOrder;
76111 pItem->done = 0;
76112 pItem->bSpanIsTab = pOldItem->bSpanIsTab;
76113 pItem->iOrderByCol = pOldItem->iOrderByCol;
76114 pItem->iAlias = pOldItem->iAlias;
76115 }
76116 return pNew;
76117 }
@@ -100236,19 +100300,20 @@
100300 sDistinct.eTnctType = WHERE_DISTINCT_NOOP;
100301 }
100302
100303 if( !isAgg && pGroupBy==0 ){
100304 /* No aggregate functions and no GROUP BY clause */
100305 u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0);
100306
100307 /* Begin the database scan. */
100308 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pOrderBy, p->pEList,
100309 wctrlFlags, 0);
100310 if( pWInfo==0 ) goto select_end;
100311 if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
100312 p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
100313 }
100314 if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){
100315 sDistinct.eTnctType = sqlite3WhereIsDistinct(pWInfo);
100316 }
100317 if( pOrderBy && sqlite3WhereIsOrdered(pWInfo) ) pOrderBy = 0;
100318
100319 /* If sorting index that was created by a prior OP_OpenEphemeral
@@ -102940,11 +103005,11 @@
103005
103006 if( !db->autoCommit ){
103007 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
103008 return SQLITE_ERROR;
103009 }
103010 if( db->nVdbeActive>1 ){
103011 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
103012 return SQLITE_ERROR;
103013 }
103014
103015 /* Save the current value of the database flags so that it can be
@@ -104440,11 +104505,11 @@
104505
104506 /*
104507 ** Each instance of this object holds a sequence of WhereLoop objects
104508 ** that implement some or all of a query plan.
104509 **
104510 ** Think of each WhereLoop object as a node in a graph with arcs
104511 ** showing dependences and costs for travelling between nodes. (That is
104512 ** not a completely accurate description because WhereLoop costs are a
104513 ** vector, not a scalar, and because dependences are many-to-one, not
104514 ** one-to-one as are graph nodes. But it is a useful visualization aid.)
104515 ** Then a WherePath object is a path through the graph that visits some
@@ -104664,23 +104729,23 @@
104729 */
104730 struct WhereInfo {
104731 Parse *pParse; /* Parsing and code generating context */
104732 SrcList *pTabList; /* List of tables in the join */
104733 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
104734 ExprList *pResultSet; /* Result set. DISTINCT operates on these */
104735 WhereLoop *pLoops; /* List of all WhereLoop objects */
104736 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
104737 WhereCost nRowOut; /* Estimated number of output rows */
104738 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
104739 u8 bOBSat; /* ORDER BY satisfied by indices */
104740 u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE/DELETE */
104741 u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */
104742 u8 eDistinct; /* One of the WHERE_DISTINCT_* values below */
104743 u8 nLevel; /* Number of nested loop */
104744 int iTop; /* The very beginning of the WHERE loop */
104745 int iContinue; /* Jump here to continue with next record */
104746 int iBreak; /* Jump here to break out of the loop */
 
104747 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
104748 WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
104749 WhereClause sWC; /* Decomposition of the WHERE clause */
104750 WhereLevel a[1]; /* Information about each nest loop in WHERE */
104751 };
@@ -104710,11 +104775,11 @@
104775 /*
104776 ** These are definitions of bits in the WhereLoop.wsFlags field.
104777 ** The particular combination of bits in each WhereLoop help to
104778 ** determine the algorithm that WhereLoop represents.
104779 */
104780 #define WHERE_COLUMN_EQ 0x00000001 /* x=EXPR */
104781 #define WHERE_COLUMN_RANGE 0x00000002 /* x<EXPR and/or x>EXPR */
104782 #define WHERE_COLUMN_IN 0x00000004 /* x IN (...) */
104783 #define WHERE_COLUMN_NULL 0x00000008 /* x IS NULL */
104784 #define WHERE_CONSTRAINT 0x0000000f /* Any of the WHERE_COLUMN_xxx values */
104785 #define WHERE_TOP_LIMIT 0x00000010 /* x<EXPR or x<=EXPR constraint */
@@ -104725,11 +104790,11 @@
104790 #define WHERE_INDEXED 0x00000200 /* WhereLoop.u.btree.pIndex is valid */
104791 #define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */
104792 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
104793 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
104794 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
104795 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
104796
104797
104798 /* Convert a WhereCost value (10 times log2(X)) into its integer value X.
104799 ** A rough approximation is used. The value returned is not exact.
104800 */
@@ -105103,11 +105168,11 @@
105168 /*
105169 ** Advance to the next WhereTerm that matches according to the criteria
105170 ** established when the pScan object was initialized by whereScanInit().
105171 ** Return NULL if there are no more matching WhereTerms.
105172 */
105173 static WhereTerm *whereScanNext(WhereScan *pScan){
105174 int iCur; /* The cursor on the LHS of the term */
105175 int iColumn; /* The column on the LHS of the term. -1 for IPK */
105176 Expr *pX; /* An expression being tested */
105177 WhereClause *pWC; /* Shorthand for pScan->pWC */
105178 WhereTerm *pTerm; /* The term being tested */
@@ -105190,11 +105255,11 @@
105255 ** but is enough to handle most commonly occurring SQL statements.
105256 **
105257 ** If X is not the INTEGER PRIMARY KEY then X must be compatible with
105258 ** index pIdx.
105259 */
105260 static WhereTerm *whereScanInit(
105261 WhereScan *pScan, /* The WhereScan object being initialized */
105262 WhereClause *pWC, /* The WHERE clause to be scanned */
105263 int iCur, /* Cursor to scan for */
105264 int iColumn, /* Column to scan for */
105265 u32 opMask, /* Operator(s) to scan for */
@@ -106019,10 +106084,11 @@
106084 ** the start of the loop will prevent any results from being returned.
106085 */
106086 if( pExpr->op==TK_NOTNULL
106087 && pExpr->pLeft->op==TK_COLUMN
106088 && pExpr->pLeft->iColumn>=0
106089 && OptimizationEnabled(db, SQLITE_Stat3)
106090 ){
106091 Expr *pNewExpr;
106092 Expr *pLeft = pExpr->pLeft;
106093 int idxNew;
106094 WhereTerm *pNewTerm;
@@ -106322,10 +106388,11 @@
106388 int mxBitCol; /* Maximum column in pSrc->colUsed */
106389 CollSeq *pColl; /* Collating sequence to on a column */
106390 WhereLoop *pLoop; /* The Loop object */
106391 Bitmask idxCols; /* Bitmap of columns used for indexing */
106392 Bitmask extraCols; /* Bitmap of additional columns */
106393 u8 sentWarning = 0; /* True if a warnning has been issued */
106394
106395 /* Generate code to skip over the creation and initialization of the
106396 ** transient index on 2nd and subsequent iterations of the loop. */
106397 v = pParse->pVdbe;
106398 assert( v!=0 );
@@ -106342,10 +106409,16 @@
106409 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
106410 int iCol = pTerm->u.leftColumn;
106411 Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
106412 testcase( iCol==BMS );
106413 testcase( iCol==BMS-1 );
106414 if( !sentWarning ){
106415 sqlite3_log(SQLITE_WARNING_AUTOINDEX,
106416 "automatic index on %s(%s)", pTable->zName,
106417 pTable->aCol[iCol].zName);
106418 sentWarning = 1;
106419 }
106420 if( (idxCols & cMask)==0 ){
106421 if( whereLoopResize(pParse->db, pLoop, nColumn+1) ) return;
106422 pLoop->aLTerm[nColumn++] = pTerm;
106423 idxCols |= cMask;
106424 }
@@ -106352,11 +106425,11 @@
106425 }
106426 }
106427 assert( nColumn>0 );
106428 pLoop->u.btree.nEq = pLoop->nLTerm = nColumn;
106429 pLoop->wsFlags = WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WHERE_INDEXED
106430 | WHERE_AUTO_INDEX;
106431
106432 /* Count the number of additional columns needed to create a
106433 ** covering index. A "covering index" is an index that contains all
106434 ** columns that are needed by the query. With a covering index, the
106435 ** original table never needs to be accessed. Automatic indices must
@@ -106690,13 +106763,14 @@
106763 z = (const u8 *)sqlite3_value_blob(pVal);
106764 pColl = db->pDfltColl;
106765 assert( pColl->enc==SQLITE_UTF8 );
106766 }else{
106767 pColl = sqlite3GetCollSeq(pParse, SQLITE_UTF8, 0, *pIdx->azColl);
106768 /* If the collating sequence was unavailable, we should have failed
106769 ** long ago and never reached this point. But we'll check just to
106770 ** be doubly sure. */
106771 if( NEVER(pColl==0) ) return SQLITE_ERROR;
106772 z = (const u8 *)sqlite3ValueText(pVal, pColl->enc);
106773 if( !z ){
106774 return SQLITE_NOMEM;
106775 }
106776 assert( z && pColl && pColl->xCmp );
@@ -106851,11 +106925,11 @@
106925 ){
106926 int rc = SQLITE_OK;
106927
106928 #ifdef SQLITE_ENABLE_STAT3
106929
106930 if( nEq==0 && p->nSample && OptimizationEnabled(pParse->db, SQLITE_Stat3) ){
106931 sqlite3_value *pRangeVal;
106932 tRowcnt iLower = 0;
106933 tRowcnt iUpper = p->aiRowEst[0];
106934 tRowcnt a[2];
106935 u8 aff = p->pTable->aCol[p->aiColumn[0]].affinity;
@@ -107397,17 +107471,16 @@
107471 }
107472 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0
107473 && ALWAYS(pLoop->u.btree.pIndex!=0)
107474 ){
107475 char *zWhere = explainIndexRange(db, pLoop, pItem->pTab);
107476 zMsg = sqlite3MAppendf(db, zMsg,
107477 ((flags & WHERE_AUTO_INDEX) ?
107478 "%s USING AUTOMATIC %sINDEX%.0s%s" :
107479 "%s USING %sINDEX %s%s"),
107480 zMsg, ((flags & WHERE_IDX_ONLY) ? "COVERING " : ""),
107481 pLoop->u.btree.pIndex->zName, zWhere);
 
107482 sqlite3DbFree(db, zWhere);
107483 }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
107484 zMsg = sqlite3MAppendf(db, zMsg, "%s USING INTEGER PRIMARY KEY", zMsg);
107485
107486 if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
@@ -107608,14 +107681,15 @@
107681 };
107682 assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
107683 assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
107684 assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
107685
107686 assert( (pStart->wtFlags & TERM_VNULL)==0 );
107687 testcase( pStart->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
107688 pX = pStart->pExpr;
107689 assert( pX!=0 );
107690 testcase( pStart->leftCursor!=iCur ); /* transitive constraints */
107691 r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
107692 sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
107693 VdbeComment((v, "pk"));
107694 sqlite3ExprCacheAffinityChange(pParse, r1, 1);
107695 sqlite3ReleaseTempReg(pParse, rTemp);
@@ -107625,11 +107699,12 @@
107699 }
107700 if( pEnd ){
107701 Expr *pX;
107702 pX = pEnd->pExpr;
107703 assert( pX!=0 );
107704 assert( (pEnd->wtFlags & TERM_VNULL)==0 );
107705 testcase( pEnd->leftCursor!=iCur ); /* Transitive constraints */
107706 testcase( pEnd->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
107707 memEndValue = ++pParse->nMem;
107708 sqlite3ExprCode(pParse, pX->pRight, memEndValue);
107709 if( pX->op==TK_LT || pX->op==TK_GT ){
107710 testOp = bRev ? OP_Le : OP_Ge;
@@ -108074,11 +108149,11 @@
108149 ** terms, set pCov to the candidate covering index. Otherwise, set
108150 ** pCov to NULL to indicate that no candidate covering index will
108151 ** be available.
108152 */
108153 pSubLoop = pSubWInfo->a[0].pWLoop;
108154 assert( (pSubLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
108155 if( (pSubLoop->wsFlags & WHERE_INDEXED)!=0
108156 && (ii==0 || pSubLoop->u.btree.pIndex==pCov)
108157 ){
108158 assert( pSubWInfo->a[0].iIdxCur==iCovCur );
108159 pCov = pSubLoop->u.btree.pIndex;
@@ -108160,10 +108235,11 @@
108235 WhereTerm *pAlt;
108236 Expr sEq;
108237 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
108238 if( pTerm->eOperator!=(WO_EQUIV|WO_EQ) ) continue;
108239 if( pTerm->leftCursor!=iCur ) continue;
108240 if( pLevel->iLeftJoin ) continue;
108241 pE = pTerm->pExpr;
108242 assert( !ExprHasProperty(pE, EP_FromJoin) );
108243 assert( (pTerm->prereqRight & newNotReady)!=0 );
108244 pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
108245 if( pAlt==0 ) continue;
@@ -108208,13 +108284,13 @@
108284 */
108285 static void whereLoopPrint(WhereLoop *p, SrcList *pTabList){
108286 int nb = 1+(pTabList->nSrc+7)/8;
108287 struct SrcList_item *pItem = pTabList->a + p->iTab;
108288 Table *pTab = pItem->pTab;
108289 sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
108290 p->iTab, nb, p->maskSelf, nb, p->prereq);
108291 sqlite3DebugPrintf(" %12s",
108292 pItem->zAlias ? pItem->zAlias : pTab->zName);
108293 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
108294 if( p->u.btree.pIndex ){
108295 const char *zName = p->u.btree.pIndex->zName;
108296 if( zName==0 ) zName = "ipk";
@@ -108221,26 +108297,26 @@
108297 if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
108298 int i = sqlite3Strlen30(zName) - 1;
108299 while( zName[i]!='_' ) i--;
108300 zName += i;
108301 }
108302 sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);
108303 }else{
108304 sqlite3DebugPrintf("%20s","");
108305 }
108306 }else{
108307 char *z;
108308 if( p->u.vtab.idxStr ){
108309 z = sqlite3_mprintf("(%d,\"%s\",%x)",
108310 p->u.vtab.idxNum, p->u.vtab.idxStr, p->u.vtab.omitMask);
108311 }else{
108312 z = sqlite3_mprintf("(%d,%x)", p->u.vtab.idxNum, p->u.vtab.omitMask);
108313 }
108314 sqlite3DebugPrintf(" %-19s", z);
108315 sqlite3_free(z);
108316 }
108317 sqlite3DebugPrintf(" f %04x N %d", p->wsFlags, p->nLTerm);
108318 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
108319 }
108320 #endif
108321
108322 /*
@@ -108256,16 +108332,16 @@
108332
108333 /*
108334 ** Clear the WhereLoop.u union. Leave WhereLoop.pLTerm intact.
108335 */
108336 static void whereLoopClearUnion(sqlite3 *db, WhereLoop *p){
108337 if( p->wsFlags & (WHERE_VIRTUALTABLE|WHERE_AUTO_INDEX) ){
108338 if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 && p->u.vtab.needFree ){
108339 sqlite3_free(p->u.vtab.idxStr);
108340 p->u.vtab.needFree = 0;
108341 p->u.vtab.idxStr = 0;
108342 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
108343 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
108344 sqlite3DbFree(db, p->u.btree.pIndex);
108345 p->u.btree.pIndex = 0;
108346 }
108347 }
@@ -108304,11 +108380,11 @@
108380 whereLoopClearUnion(db, pTo);
108381 memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
108382 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
108383 if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
108384 pFrom->u.vtab.needFree = 0;
108385 }else if( (pFrom->wsFlags & WHERE_AUTO_INDEX)!=0 ){
108386 pFrom->u.btree.pIndex = 0;
108387 }
108388 return SQLITE_OK;
108389 }
108390
@@ -108554,10 +108630,15 @@
108630 pNew->rSetup = 0;
108631 rLogSize = estLog(whereCost(pProbe->aiRowEst[0]));
108632 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
108633 int nIn = 0;
108634 if( pTerm->prereqRight & pNew->maskSelf ) continue;
108635 #ifdef SQLITE_ENABLE_STAT3
108636 if( (pTerm->wtFlags & TERM_VNULL)!=0 && pSrc->pTab->aCol[iCol].notNull ){
108637 continue; /* skip IS NOT NULL constraints on a NOT NULL column */
108638 }
108639 #endif
108640 pNew->wsFlags = saved_wsFlags;
108641 pNew->u.btree.nEq = saved_nEq;
108642 pNew->nLTerm = saved_nLTerm;
108643 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
108644 pNew->aLTerm[pNew->nLTerm++] = pTerm;
@@ -108616,11 +108697,12 @@
108697 whereRangeScanEst(pParse, pProbe, pNew->u.btree.nEq,
108698 pBtm, pTop, &rDiv);
108699 pNew->nOut = saved_nOut>rDiv+10 ? saved_nOut - rDiv : 10;
108700 }
108701 #ifdef SQLITE_ENABLE_STAT3
108702 if( pNew->u.btree.nEq==1 && pProbe->nSample
108703 && OptimizationEnabled(db, SQLITE_Stat3) ){
108704 tRowcnt nOut = 0;
108705 if( (pTerm->eOperator & (WO_EQ|WO_ISNULL))!=0 ){
108706 testcase( pTerm->eOperator & WO_EQ );
108707 testcase( pTerm->eOperator & WO_ISNULL );
108708 rc = whereEqualScanEst(pParse, pProbe, pTerm->pExpr->pRight, &nOut);
@@ -108700,11 +108782,11 @@
108782 return m;
108783 }
108784
108785
108786 /*
108787 ** Add all WhereLoop objects for a single table of the join where the table
108788 ** is idenfied by pBuilder->pNew->iTab. That table is guaranteed to be
108789 ** a b-tree table, not a virtual table.
108790 */
108791 static int whereLoopAddBtree(
108792 WhereLoopBuilder *pBuilder, /* WHERE clause information */
@@ -108776,17 +108858,20 @@
108858 pNew->u.btree.nEq = 1;
108859 pNew->u.btree.pIndex = 0;
108860 pNew->nLTerm = 1;
108861 pNew->aLTerm[0] = pTerm;
108862 /* TUNING: One-time cost for computing the automatic index is
108863 ** approximately 7*N*log2(N) where N is the number of rows in
108864 ** the table being indexed. */
108865 pNew->rSetup = rLogSize + rSize + 28; assert( 28==whereCost(7) );
108866 /* TUNING: Each index lookup yields 20 rows in the table. This
108867 ** is more than the usual guess of 10 rows, since we have no way
108868 ** of knowning how selective the index will ultimately be. It would
108869 ** not be unreasonable to make this value much larger. */
108870 pNew->nOut = 43; assert( 43==whereCost(20) );
108871 pNew->rRun = whereCostAdd(rLogSize,pNew->nOut);
108872 pNew->wsFlags = WHERE_AUTO_INDEX;
108873 pNew->prereq = mExtra | pTerm->prereqRight;
108874 rc = whereLoopInsert(pBuilder, pNew);
108875 }
108876 }
108877 }
@@ -109161,16 +109246,23 @@
109246 }
109247
109248 /*
109249 ** Examine a WherePath (with the addition of the extra WhereLoop of the 5th
109250 ** parameters) to see if it outputs rows in the requested ORDER BY
109251 ** (or GROUP BY) without requiring a separate sort operation. Return:
109252 **
109253 ** 0: ORDER BY is not satisfied. Sorting required
109254 ** 1: ORDER BY is satisfied. Omit sorting
109255 ** -1: Unknown at this time
109256 **
109257 ** Note that processing for WHERE_GROUPBY and WHERE_DISTINCTBY is not as
109258 ** strict. With GROUP BY and DISTINCT the only requirement is that
109259 ** equivalent rows appear immediately adjacent to one another. GROUP BY
109260 ** and DISTINT do not require rows to appear in any particular order as long
109261 ** as equivelent rows are grouped together. Thus for GROUP BY and DISTINCT
109262 ** the pOrderBy terms can be matched in any order. With ORDER BY, the
109263 ** pOrderBy terms must be matched in strict left-to-right order.
109264 */
109265 static int wherePathSatisfiesOrderBy(
109266 WhereInfo *pWInfo, /* The WHERE clause */
109267 ExprList *pOrderBy, /* ORDER BY or GROUP BY or DISTINCT clause to check */
109268 WherePath *pPath, /* The WherePath to check */
@@ -109414,11 +109506,11 @@
109506 }
109507 #endif
109508
109509
109510 /*
109511 ** Given the list of WhereLoop objects at pWInfo->pLoops, this routine
109512 ** attempts to find the lowest cost path that visits each WhereLoop
109513 ** once. This path is then loaded into the pWInfo->a[].pWLoop fields.
109514 **
109515 ** Assume that the total number of output rows that will need to be sorted
109516 ** will be nRowEst (in the 10*log2 representation). Or, ignore sorting
@@ -109650,16 +109742,17 @@
109742 WhereLevel *pLevel = pWInfo->a + iLoop;
109743 pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
109744 pLevel->iFrom = pWLoop->iTab;
109745 pLevel->iTabCur = pWInfo->pTabList->a[pLevel->iFrom].iCursor;
109746 }
109747 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0
109748 && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
109749 && pWInfo->eDistinct==WHERE_DISTINCT_NOOP
109750 && nRowEst
109751 ){
109752 Bitmask notUsed;
109753 int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pResultSet, pFrom,
109754 WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
109755 if( rc==1 ) pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
109756 }
109757 if( pFrom->isOrdered ){
109758 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -109744,11 +109837,13 @@
109837 pWInfo->a[0].pWLoop = pLoop;
109838 pLoop->maskSelf = getMask(&pWInfo->sMaskSet, iCur);
109839 pWInfo->a[0].iTabCur = iCur;
109840 pWInfo->nRowOut = 1;
109841 if( pWInfo->pOrderBy ) pWInfo->bOBSat = 1;
109842 if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){
109843 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
109844 }
109845 #ifdef SQLITE_DEBUG
109846 pLoop->cId = '0';
109847 #endif
109848 return 1;
109849 }
@@ -109828,20 +109923,21 @@
109923 ** fi
109924 ** end
109925 **
109926 ** ORDER BY CLAUSE PROCESSING
109927 **
109928 ** pOrderBy is a pointer to the ORDER BY clause (or the GROUP BY clause
109929 ** if the WHERE_GROUPBY flag is set in wctrlFlags) of a SELECT statement
109930 ** if there is one. If there is no ORDER BY clause or if this routine
109931 ** is called from an UPDATE or DELETE statement, then pOrderBy is NULL.
109932 */
109933 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
109934 Parse *pParse, /* The parser context */
109935 SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
109936 Expr *pWhere, /* The WHERE clause */
109937 ExprList *pOrderBy, /* An ORDER BY clause, or NULL */
109938 ExprList *pResultSet, /* Result set of the query */
109939 u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
109940 int iIdxCur /* If WHERE_ONETABLE_ONLY is set, index cursor number */
109941 ){
109942 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
109943 int nTabList; /* Number of elements in pTabList */
@@ -109849,18 +109945,26 @@
109945 Vdbe *v = pParse->pVdbe; /* The virtual database engine */
109946 Bitmask notReady; /* Cursors that are not yet positioned */
109947 WhereLoopBuilder sWLB; /* The WhereLoop builder */
109948 WhereMaskSet *pMaskSet; /* The expression mask set */
109949 WhereLevel *pLevel; /* A single level in pWInfo->a[] */
109950 WhereLoop *pLoop; /* Pointer to a single WhereLoop object */
109951 int ii; /* Loop counter */
109952 sqlite3 *db; /* Database connection */
109953 int rc; /* Return code */
109954
109955
109956 /* Variable initialization */
109957 db = pParse->db;
109958 memset(&sWLB, 0, sizeof(sWLB));
109959 sWLB.pOrderBy = pOrderBy;
109960
109961 /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
109962 ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */
109963 if( OptimizationDisabled(db, SQLITE_DistinctOpt) ){
109964 wctrlFlags &= ~WHERE_WANT_DISTINCT;
109965 }
109966
109967 /* The number of tables in the FROM clause is limited by the number of
109968 ** bits in a Bitmask
109969 */
109970 testcase( pTabList->nSrc==BMS );
@@ -109881,11 +109985,10 @@
109985 ** struct, the contents of WhereInfo.a[], the WhereClause structure
109986 ** and the WhereMaskSet structure. Since WhereClause contains an 8-byte
109987 ** field (type Bitmask) it must be aligned on an 8-byte boundary on
109988 ** some architectures. Hence the ROUND8() below.
109989 */
 
109990 nByteWInfo = ROUND8(sizeof(WhereInfo)+(nTabList-1)*sizeof(WhereLevel));
109991 pWInfo = sqlite3DbMallocZero(db, nByteWInfo + sizeof(WhereLoop));
109992 if( db->mallocFailed ){
109993 sqlite3DbFree(db, pWInfo);
109994 pWInfo = 0;
@@ -109893,11 +109996,11 @@
109996 }
109997 pWInfo->nLevel = nTabList;
109998 pWInfo->pParse = pParse;
109999 pWInfo->pTabList = pTabList;
110000 pWInfo->pOrderBy = pOrderBy;
110001 pWInfo->pResultSet = pResultSet;
110002 pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
110003 pWInfo->wctrlFlags = wctrlFlags;
110004 pWInfo->savedNQueryLoop = pParse->nQueryLoop;
110005 pMaskSet = &pWInfo->sMaskSet;
110006 sWLB.pWInfo = pWInfo;
@@ -109906,21 +110009,18 @@
110009 whereLoopInit(sWLB.pNew);
110010 #ifdef SQLITE_DEBUG
110011 sWLB.pNew->cId = '*';
110012 #endif
110013
 
 
 
 
110014 /* Split the WHERE clause into separate subexpressions where each
110015 ** subexpression is separated by an AND operator.
110016 */
110017 initMaskSet(pMaskSet);
110018 whereClauseInit(&pWInfo->sWC, pWInfo);
110019 sqlite3ExprCodeConstants(pParse, pWhere);
110020 whereSplit(&pWInfo->sWC, pWhere, TK_AND); /* IMP: R-15842-53296 */
110021 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
110022
110023 /* Special case: a WHERE clause that is constant. Evaluate the
110024 ** expression and either jump over all of the code or fall thru.
110025 */
110026 if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){
@@ -109930,11 +110030,13 @@
110030
110031 /* Special case: No FROM clause
110032 */
110033 if( nTabList==0 ){
110034 if( pOrderBy ) pWInfo->bOBSat = 1;
110035 if( wctrlFlags & WHERE_WANT_DISTINCT ){
110036 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
110037 }
110038 }
110039
110040 /* Assign a bit from the bitmask to every term in the FROM clause.
110041 **
110042 ** When assigning bitmask values to FROM clause cursors, it must be
@@ -109977,11 +110079,11 @@
110079
110080 /* If the ORDER BY (or GROUP BY) clause contains references to general
110081 ** expressions, then we won't be able to satisfy it using indices, so
110082 ** go ahead and disable it now.
110083 */
110084 if( pOrderBy && (wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
110085 for(ii=0; ii<pOrderBy->nExpr; ii++){
110086 Expr *pExpr = sqlite3ExprSkipCollate(pOrderBy->a[ii].pExpr);
110087 if( pExpr->op!=TK_COLUMN ){
110088 pWInfo->pOrderBy = pOrderBy = 0;
110089 break;
@@ -109989,21 +110091,18 @@
110091 break;
110092 }
110093 }
110094 }
110095
110096 if( wctrlFlags & WHERE_WANT_DISTINCT ){
110097 if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
110098 /* The DISTINCT marking is pointless. Ignore it. */
 
 
 
 
110099 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
110100 }else if( pOrderBy==0 ){
110101 /* Try to ORDER BY the result set to make distinct processing easier */
110102 pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
110103 pWInfo->pOrderBy = pResultSet;
110104 }
110105 }
110106
110107 /* Construct the WhereLoop objects */
110108 WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
@@ -110013,15 +110112,15 @@
110112
110113 /* Display all of the WhereLoop objects if wheretrace is enabled */
110114 #ifdef WHERETRACE_ENABLED
110115 if( sqlite3WhereTrace ){
110116 WhereLoop *p;
110117 int i;
110118 static char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
110119 "ABCDEFGHIJKLMNOPQRSTUVWYXZ";
110120 for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
110121 p->cId = zLabel[i%sizeof(zLabel)];
110122 whereLoopPrint(p, pTabList);
110123 }
110124 }
110125 #endif
110126
@@ -110058,15 +110157,46 @@
110157 sqlite3DebugPrintf(" DISTINCT=unordered");
110158 break;
110159 }
110160 }
110161 sqlite3DebugPrintf("\n");
110162 for(ii=0; ii<pWInfo->nLevel; ii++){
110163 whereLoopPrint(pWInfo->a[ii].pWLoop, pTabList);
110164 }
110165 }
110166 #endif
110167 /* Attempt to omit tables from the join that do not effect the result */
110168 if( pWInfo->nLevel>=2
110169 && pResultSet!=0
110170 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
110171 ){
110172 Bitmask tabUsed = exprListTableUsage(pMaskSet, pResultSet);
110173 if( pOrderBy ) tabUsed |= exprListTableUsage(pMaskSet, pOrderBy);
110174 while( pWInfo->nLevel>=2 ){
110175 WhereTerm *pTerm, *pEnd;
110176 pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop;
110177 if( (pWInfo->pTabList->a[pLoop->iTab].jointype & JT_LEFT)==0 ) break;
110178 if( (wctrlFlags & WHERE_WANT_DISTINCT)==0
110179 && (pLoop->wsFlags & WHERE_ONEROW)==0
110180 ){
110181 break;
110182 }
110183 if( (tabUsed & pLoop->maskSelf)!=0 ) break;
110184 pEnd = sWLB.pWC->a + sWLB.pWC->nTerm;
110185 for(pTerm=sWLB.pWC->a; pTerm<pEnd; pTerm++){
110186 if( (pTerm->prereqAll & pLoop->maskSelf)!=0
110187 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
110188 ){
110189 break;
110190 }
110191 }
110192 if( pTerm<pEnd ) break;
110193 WHERETRACE(0xffff, ("-> drop loop %c not used\n", pLoop->cId));
110194 pWInfo->nLevel--;
110195 nTabList--;
110196 }
110197 }
110198 WHERETRACE(0xffff,("*** Optimizer Finished ***\n"));
110199 pWInfo->pParse->nQueryLoop += pWInfo->nRowOut;
110200
110201 /* If the caller is an UPDATE or DELETE statement that is requesting
110202 ** to use a one-pass algorithm, determine if this is appropriate.
@@ -110081,17 +110211,15 @@
110211 }
110212
110213 /* Open all tables in the pTabList and any indices selected for
110214 ** searching those tables.
110215 */
 
110216 notReady = ~(Bitmask)0;
110217 for(ii=0, pLevel=pWInfo->a; ii<nTabList; ii++, pLevel++){
110218 Table *pTab; /* Table to open */
110219 int iDb; /* Index of database containing table/index */
110220 struct SrcList_item *pTabItem;
 
110221
110222 pTabItem = &pTabList->a[pLevel->iFrom];
110223 pTab = pTabItem->pTab;
110224 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
110225 pLoop = pLevel->pWLoop;
@@ -110123,11 +110251,11 @@
110251 }
110252 }else{
110253 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
110254 }
110255 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
110256 if( (pLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){
110257 constructAutomaticIndex(pParse, &pWInfo->sWC, pTabItem, notReady, pLevel);
110258 }else
110259 #endif
110260 if( pLoop->wsFlags & WHERE_INDEXED ){
110261 Index *pIx = pLoop->u.btree.pIndex;
@@ -110231,11 +110359,11 @@
110359 */
110360 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
110361
110362 /* Close all of the cursors that were opened by sqlite3WhereBegin.
110363 */
110364 assert( pWInfo->nLevel<=pTabList->nSrc );
110365 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
110366 Index *pIdx = 0;
110367 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
110368 Table *pTab = pTabItem->pTab;
110369 assert( pTab!=0 );
@@ -110246,11 +110374,11 @@
110374 ){
110375 int ws = pLoop->wsFlags;
110376 if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
110377 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
110378 }
110379 if( (ws & WHERE_INDEXED)!=0 && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0 ){
110380 sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
110381 }
110382 }
110383
110384 /* If this scan uses an index, make VDBE code substitutions to read data
@@ -114457,11 +114585,11 @@
114585 sqlite3 *db = pParse->db; /* The database connection */
114586 int mxSqlLen; /* Max length of an SQL string */
114587
114588
114589 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
114590 if( db->nVdbeActive==0 ){
114591 db->u1.isInterrupted = 0;
114592 }
114593 pParse->rc = SQLITE_OK;
114594 pParse->zTail = zSql;
114595 i = 0;
@@ -116025,10 +116153,11 @@
116153 case SQLITE_PERM: zName = "SQLITE_PERM"; break;
116154 case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
116155 case SQLITE_ABORT_ROLLBACK: zName = "SQLITE_ABORT_ROLLBACK"; break;
116156 case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
116157 case SQLITE_BUSY_RECOVERY: zName = "SQLITE_BUSY_RECOVERY"; break;
116158 case SQLITE_BUSY_SNAPSHOT: zName = "SQLITE_BUSY_SNAPSHOT"; break;
116159 case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break;
116160 case SQLITE_LOCKED_SHAREDCACHE: zName = "SQLITE_LOCKED_SHAREDCACHE";break;
116161 case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
116162 case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
116163 case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
@@ -116098,10 +116227,11 @@
116227 case SQLITE_NOTICE: zName = "SQLITE_NOTICE"; break;
116228 case SQLITE_NOTICE_RECOVER_WAL: zName = "SQLITE_NOTICE_RECOVER_WAL";break;
116229 case SQLITE_NOTICE_RECOVER_ROLLBACK:
116230 zName = "SQLITE_NOTICE_RECOVER_ROLLBACK"; break;
116231 case SQLITE_WARNING: zName = "SQLITE_WARNING"; break;
116232 case SQLITE_WARNING_AUTOINDEX: zName = "SQLITE_WARNING_AUTOINDEX"; break;
116233 case SQLITE_DONE: zName = "SQLITE_DONE"; break;
116234 }
116235 }
116236 if( zName==0 ){
116237 static char zBuf[50];
@@ -116356,11 +116486,11 @@
116486 ** is being overridden/deleted but there are no active VMs, allow the
116487 ** operation to continue but invalidate all precompiled statements.
116488 */
116489 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
116490 if( p && p->iPrefEnc==enc && p->nArg==nArg ){
116491 if( db->nVdbeActive ){
116492 sqlite3Error(db, SQLITE_BUSY,
116493 "unable to delete/modify user-function due to active statements");
116494 assert( !db->mallocFailed );
116495 return SQLITE_BUSY;
116496 }else{
@@ -116937,11 +117067,11 @@
117067 ** sequence. If so, and there are active VMs, return busy. If there
117068 ** are no active VMs, invalidate any pre-compiled statements.
117069 */
117070 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
117071 if( pColl && pColl->xCmp ){
117072 if( db->nVdbeActive ){
117073 sqlite3Error(db, SQLITE_BUSY,
117074 "unable to delete/modify collation sequence due to active statements");
117075 return SQLITE_BUSY;
117076 }
117077 sqlite3ExpirePreparedStatements(db);
@@ -117412,11 +117542,14 @@
117542 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
117543 db->autoCommit = 1;
117544 db->nextAutovac = -1;
117545 db->szMmap = sqlite3GlobalConfig.szMmap;
117546 db->nextPagesize = 0;
117547 db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger
117548 #if !defined(SQLITE_DEAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
117549 | SQLITE_AutoIndex
117550 #endif
117551 #if SQLITE_DEFAULT_FILE_FORMAT<4
117552 | SQLITE_LegacyFileFmt
117553 #endif
117554 #ifdef SQLITE_ENABLE_LOAD_EXTENSION
117555 | SQLITE_LoadExtension
@@ -119407,10 +119540,11 @@
119540 sqlite3 *db; /* The database connection */
119541 const char *zDb; /* logical database name */
119542 const char *zName; /* virtual table name */
119543 int nColumn; /* number of named columns in virtual table */
119544 char **azColumn; /* column names. malloced */
119545 u8 *abNotindexed; /* True for 'notindexed' columns */
119546 sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */
119547 char *zContentTbl; /* content=xxx option, or NULL */
119548 char *zLanguageid; /* languageid=xxx option, or NULL */
119549 u8 bAutoincrmerge; /* True if automerge=1 */
119550 u32 nLeafAdd; /* Number of leaf blocks added this trans */
@@ -119634,11 +119768,10 @@
119768 sqlite3_int64, sqlite3_int64, const char *, int, Fts3SegReader**);
119769 SQLITE_PRIVATE int sqlite3Fts3SegReaderPending(
119770 Fts3Table*,int,const char*,int,int,Fts3SegReader**);
119771 SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *);
119772 SQLITE_PRIVATE int sqlite3Fts3AllSegdirs(Fts3Table*, int, int, int, sqlite3_stmt **);
 
119773 SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*);
119774
119775 SQLITE_PRIVATE int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **);
119776 SQLITE_PRIVATE int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **);
119777
@@ -120567,22 +120700,34 @@
120700 char *zPrefix = 0; /* Prefix parameter value (or NULL) */
120701 char *zCompress = 0; /* compress=? parameter (or NULL) */
120702 char *zUncompress = 0; /* uncompress=? parameter (or NULL) */
120703 char *zContent = 0; /* content=? parameter (or NULL) */
120704 char *zLanguageid = 0; /* languageid=? parameter (or NULL) */
120705 char **azNotindexed = 0; /* The set of notindexed= columns */
120706 int nNotindexed = 0; /* Size of azNotindexed[] array */
120707
120708 assert( strlen(argv[0])==4 );
120709 assert( (sqlite3_strnicmp(argv[0], "fts4", 4)==0 && isFts4)
120710 || (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4)
120711 );
120712
120713 nDb = (int)strlen(argv[1]) + 1;
120714 nName = (int)strlen(argv[2]) + 1;
120715
120716 nByte = sizeof(const char *) * (argc-2);
120717 aCol = (const char **)sqlite3_malloc(nByte);
120718 if( aCol ){
120719 memset((void*)aCol, 0, nByte);
120720 azNotindexed = (char **)sqlite3_malloc(nByte);
120721 }
120722 if( azNotindexed ){
120723 memset(azNotindexed, 0, nByte);
120724 }
120725 if( !aCol || !azNotindexed ){
120726 rc = SQLITE_NOMEM;
120727 goto fts3_init_out;
120728 }
120729
120730 /* Loop through all of the arguments passed by the user to the FTS3/4
120731 ** module (i.e. all the column names and special arguments). This loop
120732 ** does the following:
120733 **
@@ -120617,11 +120762,12 @@
120762 { "prefix", 6 }, /* 1 -> PREFIX */
120763 { "compress", 8 }, /* 2 -> COMPRESS */
120764 { "uncompress", 10 }, /* 3 -> UNCOMPRESS */
120765 { "order", 5 }, /* 4 -> ORDER */
120766 { "content", 7 }, /* 5 -> CONTENT */
120767 { "languageid", 10 }, /* 6 -> LANGUAGEID */
120768 { "notindexed", 10 } /* 7 -> NOTINDEXED */
120769 };
120770
120771 int iOpt;
120772 if( !zVal ){
120773 rc = SQLITE_NOMEM;
@@ -120683,10 +120829,15 @@
120829 assert( iOpt==6 );
120830 sqlite3_free(zLanguageid);
120831 zLanguageid = zVal;
120832 zVal = 0;
120833 break;
120834
120835 case 7: /* NOTINDEXED */
120836 azNotindexed[nNotindexed++] = zVal;
120837 zVal = 0;
120838 break;
120839 }
120840 }
120841 sqlite3_free(zVal);
120842 }
120843 }
@@ -120754,10 +120905,11 @@
120905
120906 /* Allocate and populate the Fts3Table structure. */
120907 nByte = sizeof(Fts3Table) + /* Fts3Table */
120908 nCol * sizeof(char *) + /* azColumn */
120909 nIndex * sizeof(struct Fts3Index) + /* aIndex */
120910 nCol * sizeof(u8) + /* abNotindexed */
120911 nName + /* zName */
120912 nDb + /* zDb */
120913 nString; /* Space for azColumn strings */
120914 p = (Fts3Table*)sqlite3_malloc(nByte);
120915 if( p==0 ){
@@ -120787,13 +120939,14 @@
120939 memcpy(p->aIndex, aIndex, sizeof(struct Fts3Index) * nIndex);
120940 p->nIndex = nIndex;
120941 for(i=0; i<nIndex; i++){
120942 fts3HashInit(&p->aIndex[i].hPending, FTS3_HASH_STRING, 1);
120943 }
120944 p->abNotindexed = (u8 *)&p->aIndex[nIndex];
120945
120946 /* Fill in the zName and zDb fields of the vtab structure. */
120947 zCsr = (char *)&p->abNotindexed[nCol];
120948 p->zName = zCsr;
120949 memcpy(zCsr, argv[2], nName);
120950 zCsr += nName;
120951 p->zDb = zCsr;
120952 memcpy(zCsr, argv[1], nDb);
@@ -120810,11 +120963,30 @@
120963 p->azColumn[iCol] = zCsr;
120964 zCsr += n+1;
120965 assert( zCsr <= &((char *)p)[nByte] );
120966 }
120967
120968 /* Fill in the abNotindexed array */
120969 for(iCol=0; iCol<nCol; iCol++){
120970 int n = (int)strlen(p->azColumn[iCol]);
120971 for(i=0; i<nNotindexed; i++){
120972 char *zNot = azNotindexed[i];
120973 if( zNot && 0==sqlite3_strnicmp(p->azColumn[iCol], zNot, n) ){
120974 p->abNotindexed[iCol] = 1;
120975 sqlite3_free(zNot);
120976 azNotindexed[i] = 0;
120977 }
120978 }
120979 }
120980 for(i=0; i<nNotindexed; i++){
120981 if( azNotindexed[i] ){
120982 *pzErr = sqlite3_mprintf("no such column: %s", azNotindexed[i]);
120983 rc = SQLITE_ERROR;
120984 }
120985 }
120986
120987 if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
120988 char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
120989 rc = SQLITE_ERROR;
120990 *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
120991 }
120992 p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
@@ -120851,11 +121023,13 @@
121023 sqlite3_free(aIndex);
121024 sqlite3_free(zCompress);
121025 sqlite3_free(zUncompress);
121026 sqlite3_free(zContent);
121027 sqlite3_free(zLanguageid);
121028 for(i=0; i<nNotindexed; i++) sqlite3_free(azNotindexed[i]);
121029 sqlite3_free((void *)aCol);
121030 sqlite3_free((void *)azNotindexed);
121031 if( rc!=SQLITE_OK ){
121032 if( p ){
121033 fts3DisconnectMethod((sqlite3_vtab *)p);
121034 }else if( pTokenizer ){
121035 pTokenizer->pModule->xDestroy(pTokenizer);
@@ -129717,16 +129891,19 @@
129891 sqlite3_value **apVal,
129892 u32 *aSz
129893 ){
129894 int i; /* Iterator variable */
129895 for(i=2; i<p->nColumn+2; i++){
129896 int iCol = i-2;
129897 if( p->abNotindexed[iCol]==0 ){
129898 const char *zText = (const char *)sqlite3_value_text(apVal[i]);
129899 int rc = fts3PendingTermsAdd(p, iLangid, zText, iCol, &aSz[iCol]);
129900 if( rc!=SQLITE_OK ){
129901 return rc;
129902 }
129903 aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]);
129904 }
 
129905 }
129906 return SQLITE_OK;
129907 }
129908
129909 /*
@@ -129869,13 +130046,16 @@
130046 if( SQLITE_ROW==sqlite3_step(pSelect) ){
130047 int i;
130048 int iLangid = langidFromSelect(p, pSelect);
130049 rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pSelect, 0));
130050 for(i=1; rc==SQLITE_OK && i<=p->nColumn; i++){
130051 int iCol = i-1;
130052 if( p->abNotindexed[iCol]==0 ){
130053 const char *zText = (const char *)sqlite3_column_text(pSelect, i);
130054 rc = fts3PendingTermsAdd(p, iLangid, zText, -1, &aSz[iCol]);
130055 aSz[p->nColumn] += sqlite3_column_bytes(pSelect, i);
130056 }
130057 }
130058 if( rc!=SQLITE_OK ){
130059 sqlite3_reset(pSelect);
130060 *pRC = rc;
130061 return;
@@ -132113,13 +132293,15 @@
132293 int iCol;
132294 int iLangid = langidFromSelect(p, pStmt);
132295 rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pStmt, 0));
132296 memset(aSz, 0, sizeof(aSz[0]) * (p->nColumn+1));
132297 for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){
132298 if( p->abNotindexed[iCol]==0 ){
132299 const char *z = (const char *) sqlite3_column_text(pStmt, iCol+1);
132300 rc = fts3PendingTermsAdd(p, iLangid, z, iCol, &aSz[iCol]);
132301 aSz[p->nColumn] += sqlite3_column_bytes(pStmt, iCol+1);
132302 }
132303 }
132304 if( p->bHasDocsize ){
132305 fts3InsertDocsize(&rc, p, aSz);
132306 }
132307 if( rc!=SQLITE_OK ){
@@ -133918,39 +134100,41 @@
134100
134101 assert( pCsr->isRequireSeek==0 );
134102 iDocid = sqlite3_column_int64(pCsr->pStmt, 0);
134103
134104 for(i=0; i<p->nColumn && rc==SQLITE_OK; i++){
134105 if( p->abNotindexed[i]==0 ){
134106 const char *zText = (const char *)sqlite3_column_text(pCsr->pStmt, i+1);
134107 sqlite3_tokenizer_cursor *pTC = 0;
134108
134109 rc = sqlite3Fts3OpenTokenizer(pT, pCsr->iLangid, zText, -1, &pTC);
134110 while( rc==SQLITE_OK ){
134111 char const *zToken; /* Buffer containing token */
134112 int nToken = 0; /* Number of bytes in token */
134113 int iDum1 = 0, iDum2 = 0; /* Dummy variables */
134114 int iPos = 0; /* Position of token in zText */
134115
134116 rc = pModule->xNext(pTC, &zToken, &nToken, &iDum1, &iDum2, &iPos);
134117 for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
134118 Fts3PhraseToken *pPT = pDef->pToken;
134119 if( (pDef->iCol>=p->nColumn || pDef->iCol==i)
134120 && (pPT->bFirst==0 || iPos==0)
134121 && (pPT->n==nToken || (pPT->isPrefix && pPT->n<nToken))
134122 && (0==memcmp(zToken, pPT->z, pPT->n))
134123 ){
134124 fts3PendingListAppend(&pDef->pList, iDocid, i, iPos, &rc);
134125 }
134126 }
134127 }
134128 if( pTC ) pModule->xClose(pTC);
134129 if( rc==SQLITE_DONE ) rc = SQLITE_OK;
134130 }
134131
134132 for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
134133 if( pDef->pList ){
134134 rc = fts3PendingListAppendVarint(&pDef->pList, 0);
134135 }
134136 }
134137 }
134138 }
134139
134140 return rc;
134141
+15 -3
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.7.17"
111
-#define SQLITE_VERSION_NUMBER 3007017
112
-#define SQLITE_SOURCE_ID "2013-06-20 14:17:39 d94db3fd921890ab1d6414ab629410ae50779686"
110
+#define SQLITE_VERSION "3.8.0"
111
+#define SQLITE_VERSION_NUMBER 3008000
112
+#define SQLITE_SOURCE_ID "2013-07-09 03:04:32 52a49cbc1621094b2fe2b021209b768d29e0426b"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -478,10 +478,11 @@
478478
#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
479479
#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
480480
#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
481481
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
482482
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
483
+#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
483484
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
484485
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
485486
#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
486487
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
487488
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
@@ -497,10 +498,11 @@
497498
#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
498499
#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
499500
#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
500501
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
501502
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
503
+#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
502504
503505
/*
504506
** CAPI3REF: Flags For File Open Operations
505507
**
506508
** These bit values are intended for use in the
@@ -6306,15 +6308,25 @@
63066308
** <dd>^This is the number of rows inserted into transient indices that
63076309
** were created automatically in order to help joins run faster.
63086310
** A non-zero value in this counter may indicate an opportunity to
63096311
** improvement performance by adding permanent indices that do not
63106312
** need to be reinitialized each time the statement is run.</dd>
6313
+**
6314
+** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
6315
+** <dd>^This is the number of virtual machine operations executed
6316
+** by the prepared statement if that number is less than or equal
6317
+** to 2147483647. The number of virtual machine operations can be
6318
+** used as a proxy for the total work done by the prepared statement.
6319
+** If the number of virtual machine operations exceeds 2147483647
6320
+** then the value returned by this statement status code is undefined.
6321
+** </dd>
63116322
** </dl>
63126323
*/
63136324
#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
63146325
#define SQLITE_STMTSTATUS_SORT 2
63156326
#define SQLITE_STMTSTATUS_AUTOINDEX 3
6327
+#define SQLITE_STMTSTATUS_VM_STEP 4
63166328
63176329
/*
63186330
** CAPI3REF: Custom Page Cache Object
63196331
**
63206332
** The sqlite3_pcache type is opaque. It is implemented by
63216333
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.17"
111 #define SQLITE_VERSION_NUMBER 3007017
112 #define SQLITE_SOURCE_ID "2013-06-20 14:17:39 d94db3fd921890ab1d6414ab629410ae50779686"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -478,10 +478,11 @@
478 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
479 #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
480 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
481 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
482 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
 
483 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
484 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
485 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
486 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
487 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
@@ -497,10 +498,11 @@
497 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
498 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
499 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
500 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
501 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
 
502
503 /*
504 ** CAPI3REF: Flags For File Open Operations
505 **
506 ** These bit values are intended for use in the
@@ -6306,15 +6308,25 @@
6306 ** <dd>^This is the number of rows inserted into transient indices that
6307 ** were created automatically in order to help joins run faster.
6308 ** A non-zero value in this counter may indicate an opportunity to
6309 ** improvement performance by adding permanent indices that do not
6310 ** need to be reinitialized each time the statement is run.</dd>
 
 
 
 
 
 
 
 
 
6311 ** </dl>
6312 */
6313 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
6314 #define SQLITE_STMTSTATUS_SORT 2
6315 #define SQLITE_STMTSTATUS_AUTOINDEX 3
 
6316
6317 /*
6318 ** CAPI3REF: Custom Page Cache Object
6319 **
6320 ** The sqlite3_pcache type is opaque. It is implemented by
6321
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.0"
111 #define SQLITE_VERSION_NUMBER 3008000
112 #define SQLITE_SOURCE_ID "2013-07-09 03:04:32 52a49cbc1621094b2fe2b021209b768d29e0426b"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -478,10 +478,11 @@
478 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
479 #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
480 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
481 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
482 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
483 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
484 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
485 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
486 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
487 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
488 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
@@ -497,10 +498,11 @@
498 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
499 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
500 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
501 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
502 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
503 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
504
505 /*
506 ** CAPI3REF: Flags For File Open Operations
507 **
508 ** These bit values are intended for use in the
@@ -6306,15 +6308,25 @@
6308 ** <dd>^This is the number of rows inserted into transient indices that
6309 ** were created automatically in order to help joins run faster.
6310 ** A non-zero value in this counter may indicate an opportunity to
6311 ** improvement performance by adding permanent indices that do not
6312 ** need to be reinitialized each time the statement is run.</dd>
6313 **
6314 ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
6315 ** <dd>^This is the number of virtual machine operations executed
6316 ** by the prepared statement if that number is less than or equal
6317 ** to 2147483647. The number of virtual machine operations can be
6318 ** used as a proxy for the total work done by the prepared statement.
6319 ** If the number of virtual machine operations exceeds 2147483647
6320 ** then the value returned by this statement status code is undefined.
6321 ** </dd>
6322 ** </dl>
6323 */
6324 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
6325 #define SQLITE_STMTSTATUS_SORT 2
6326 #define SQLITE_STMTSTATUS_AUTOINDEX 3
6327 #define SQLITE_STMTSTATUS_VM_STEP 4
6328
6329 /*
6330 ** CAPI3REF: Custom Page Cache Object
6331 **
6332 ** The sqlite3_pcache type is opaque. It is implemented by
6333
+3 -3
--- src/tkt.c
+++ src/tkt.c
@@ -1028,11 +1028,11 @@
10281028
** ?-q|--quote?
10291029
** ?-R|--repository FILE?
10301030
**
10311031
** Run the ticket report, identified by the report format title
10321032
** used in the gui. The data is written as flat file on stdout,
1033
-** using "," as separator. The separator "," can be changed using
1033
+** using TAB as separator. The separator can be changed using
10341034
** the -l or --limit option.
10351035
**
10361036
** If TICKETFILTER is given on the commandline, the query is
10371037
** limited with a new WHERE-condition.
10381038
** example: Report lists a column # with the uuid
@@ -1111,16 +1111,16 @@
11111111
if( !db_exists("SELECT 1 FROM user WHERE login=%Q", zUser) ){
11121112
fossil_fatal("no such user: %s", zUser);
11131113
}
11141114
11151115
if( g.argc<3 ){
1116
- usage("add|fieldlist|set|show|history");
1116
+ usage("add|change|list|set|show|history");
11171117
}
11181118
n = strlen(g.argv[2]);
11191119
if( n==1 && g.argv[2][0]=='s' ){
11201120
/* set/show cannot be distinguished, so show the usage */
1121
- usage("add|fieldlist|set|show|history");
1121
+ usage("add|change|list|set|show|history");
11221122
}
11231123
if( strncmp(g.argv[2],"list",n)==0 ){
11241124
if( g.argc==3 ){
11251125
usage("list fields|reports");
11261126
}else{
11271127
--- src/tkt.c
+++ src/tkt.c
@@ -1028,11 +1028,11 @@
1028 ** ?-q|--quote?
1029 ** ?-R|--repository FILE?
1030 **
1031 ** Run the ticket report, identified by the report format title
1032 ** used in the gui. The data is written as flat file on stdout,
1033 ** using "," as separator. The separator "," can be changed using
1034 ** the -l or --limit option.
1035 **
1036 ** If TICKETFILTER is given on the commandline, the query is
1037 ** limited with a new WHERE-condition.
1038 ** example: Report lists a column # with the uuid
@@ -1111,16 +1111,16 @@
1111 if( !db_exists("SELECT 1 FROM user WHERE login=%Q", zUser) ){
1112 fossil_fatal("no such user: %s", zUser);
1113 }
1114
1115 if( g.argc<3 ){
1116 usage("add|fieldlist|set|show|history");
1117 }
1118 n = strlen(g.argv[2]);
1119 if( n==1 && g.argv[2][0]=='s' ){
1120 /* set/show cannot be distinguished, so show the usage */
1121 usage("add|fieldlist|set|show|history");
1122 }
1123 if( strncmp(g.argv[2],"list",n)==0 ){
1124 if( g.argc==3 ){
1125 usage("list fields|reports");
1126 }else{
1127
--- src/tkt.c
+++ src/tkt.c
@@ -1028,11 +1028,11 @@
1028 ** ?-q|--quote?
1029 ** ?-R|--repository FILE?
1030 **
1031 ** Run the ticket report, identified by the report format title
1032 ** used in the gui. The data is written as flat file on stdout,
1033 ** using TAB as separator. The separator can be changed using
1034 ** the -l or --limit option.
1035 **
1036 ** If TICKETFILTER is given on the commandline, the query is
1037 ** limited with a new WHERE-condition.
1038 ** example: Report lists a column # with the uuid
@@ -1111,16 +1111,16 @@
1111 if( !db_exists("SELECT 1 FROM user WHERE login=%Q", zUser) ){
1112 fossil_fatal("no such user: %s", zUser);
1113 }
1114
1115 if( g.argc<3 ){
1116 usage("add|change|list|set|show|history");
1117 }
1118 n = strlen(g.argv[2]);
1119 if( n==1 && g.argv[2][0]=='s' ){
1120 /* set/show cannot be distinguished, so show the usage */
1121 usage("add|change|list|set|show|history");
1122 }
1123 if( strncmp(g.argv[2],"list",n)==0 ){
1124 if( g.argc==3 ){
1125 usage("list fields|reports");
1126 }else{
1127
--- www/theory1.wiki
+++ www/theory1.wiki
@@ -95,11 +95,11 @@
9595
as its scripting language.
9696
9797
This misunderstanding likely arises because people fail
9898
to appreciate that SQL is a programming language. People are taught that SQL
9999
is a "query language" as if that were somehow different from a
100
-"programming language". But they really are two different favors of the
100
+"programming language". But they really are two different flavors of the
101101
same thing. I find that people do better with SQL if they think of
102102
SQL as a programming language and each statement
103103
of SQL is a separate program. SQL is a peculiar programming language
104104
in that one uses SQL to specify <i>what</i> to compute whereas in
105105
most other programming languages one specifies <i>how</i>
106106
--- www/theory1.wiki
+++ www/theory1.wiki
@@ -95,11 +95,11 @@
95 as its scripting language.
96
97 This misunderstanding likely arises because people fail
98 to appreciate that SQL is a programming language. People are taught that SQL
99 is a "query language" as if that were somehow different from a
100 "programming language". But they really are two different favors of the
101 same thing. I find that people do better with SQL if they think of
102 SQL as a programming language and each statement
103 of SQL is a separate program. SQL is a peculiar programming language
104 in that one uses SQL to specify <i>what</i> to compute whereas in
105 most other programming languages one specifies <i>how</i>
106
--- www/theory1.wiki
+++ www/theory1.wiki
@@ -95,11 +95,11 @@
95 as its scripting language.
96
97 This misunderstanding likely arises because people fail
98 to appreciate that SQL is a programming language. People are taught that SQL
99 is a "query language" as if that were somehow different from a
100 "programming language". But they really are two different flavors of the
101 same thing. I find that people do better with SQL if they think of
102 SQL as a programming language and each statement
103 of SQL is a separate program. SQL is a peculiar programming language
104 in that one uses SQL to specify <i>what</i> to compute whereas in
105 most other programming languages one specifies <i>how</i>
106

Keyboard Shortcuts

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