Fossil SCM

merge trunk

jan.nijtmans 2014-09-26 14:04 pending-review merge
Commit 9ba4ebaa66cab9364a0d6d7d8eb26498a7077228
+1
--- a/Dockerfile
+++ b/Dockerfile
@@ -0,0 +1 @@
1
+trunk
--- a/Dockerfile
+++ b/Dockerfile
@@ -0,0 +1 @@
 
--- a/Dockerfile
+++ b/Dockerfile
@@ -0,0 +1 @@
1 trunk
+2
--- auto.def
+++ auto.def
@@ -257,13 +257,15 @@
257257
258258
if {[opt-bool lineedit]} {
259259
# Need readline-compatible line editing
260260
cc-with {-includes stdio.h} {
261261
if {[cc-check-includes readline/readline.h] && [cc-check-function-in-lib readline readline]} {
262
+ define-append EXTRA_CFLAGS -DHAVE_READLINE
262263
msg-result "Using readline for line editing"
263264
} elseif {[cc-check-includes editline/readline.h] && [cc-check-function-in-lib readline edit]} {
264265
define-feature editline
266
+ define-append EXTRA_CFLAGS -DHAVE_EDITLINE
265267
msg-result "Using editline for line editing"
266268
}
267269
}
268270
}
269271
270272
--- auto.def
+++ auto.def
@@ -257,13 +257,15 @@
257
258 if {[opt-bool lineedit]} {
259 # Need readline-compatible line editing
260 cc-with {-includes stdio.h} {
261 if {[cc-check-includes readline/readline.h] && [cc-check-function-in-lib readline readline]} {
 
262 msg-result "Using readline for line editing"
263 } elseif {[cc-check-includes editline/readline.h] && [cc-check-function-in-lib readline edit]} {
264 define-feature editline
 
265 msg-result "Using editline for line editing"
266 }
267 }
268 }
269
270
--- auto.def
+++ auto.def
@@ -257,13 +257,15 @@
257
258 if {[opt-bool lineedit]} {
259 # Need readline-compatible line editing
260 cc-with {-includes stdio.h} {
261 if {[cc-check-includes readline/readline.h] && [cc-check-function-in-lib readline readline]} {
262 define-append EXTRA_CFLAGS -DHAVE_READLINE
263 msg-result "Using readline for line editing"
264 } elseif {[cc-check-includes editline/readline.h] && [cc-check-function-in-lib readline edit]} {
265 define-feature editline
266 define-append EXTRA_CFLAGS -DHAVE_EDITLINE
267 msg-result "Using editline for line editing"
268 }
269 }
270 }
271
272
+3 -7
--- src/add.c
+++ src/add.c
@@ -260,11 +260,10 @@
260260
261261
zCleanFlag = find_option("clean",0,1);
262262
zIgnoreFlag = find_option("ignore",0,1);
263263
forceFlag = find_option("force","f",0)!=0;
264264
if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
265
- capture_case_sensitive_option();
266265
267266
/* We should be done with options.. */
268267
verify_all_options();
269268
270269
db_must_be_within_tree();
@@ -353,12 +352,10 @@
353352
*/
354353
void delete_cmd(void){
355354
int i;
356355
Stmt loop;
357356
358
- capture_case_sensitive_option();
359
-
360357
/* We should be done with options.. */
361358
verify_all_options();
362359
363360
db_must_be_within_tree();
364361
db_begin_transaction();
@@ -445,12 +442,13 @@
445442
#endif
446443
caseSensitive = db_get_boolean("case-sensitive",caseSensitive);
447444
}
448445
if( !caseSensitive && g.localOpen ){
449446
db_multi_exec(
450
- "CREATE INDEX IF NOT EXISTS vfile_nocase"
451
- " ON vfile(pathname COLLATE nocase)"
447
+ "CREATE INDEX IF NOT EXISTS %s.vfile_nocase"
448
+ " ON vfile(pathname COLLATE nocase)",
449
+ db_name("localdb")
452450
);
453451
}
454452
}
455453
return caseSensitive;
456454
}
@@ -522,11 +520,10 @@
522520
Glob *pIgnore, *pClean;
523521
524522
if( !dryRunFlag ){
525523
dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
526524
}
527
- capture_case_sensitive_option();
528525
529526
/* We should be done with options.. */
530527
verify_all_options();
531528
532529
db_must_be_within_tree();
@@ -634,11 +631,10 @@
634631
int vid;
635632
char *zDest;
636633
Blob dest;
637634
Stmt q;
638635
639
- capture_case_sensitive_option();
640636
db_must_be_within_tree();
641637
642638
/* We should be done with options.. */
643639
verify_all_options();
644640
645641
--- src/add.c
+++ src/add.c
@@ -260,11 +260,10 @@
260
261 zCleanFlag = find_option("clean",0,1);
262 zIgnoreFlag = find_option("ignore",0,1);
263 forceFlag = find_option("force","f",0)!=0;
264 if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
265 capture_case_sensitive_option();
266
267 /* We should be done with options.. */
268 verify_all_options();
269
270 db_must_be_within_tree();
@@ -353,12 +352,10 @@
353 */
354 void delete_cmd(void){
355 int i;
356 Stmt loop;
357
358 capture_case_sensitive_option();
359
360 /* We should be done with options.. */
361 verify_all_options();
362
363 db_must_be_within_tree();
364 db_begin_transaction();
@@ -445,12 +442,13 @@
445 #endif
446 caseSensitive = db_get_boolean("case-sensitive",caseSensitive);
447 }
448 if( !caseSensitive && g.localOpen ){
449 db_multi_exec(
450 "CREATE INDEX IF NOT EXISTS vfile_nocase"
451 " ON vfile(pathname COLLATE nocase)"
 
452 );
453 }
454 }
455 return caseSensitive;
456 }
@@ -522,11 +520,10 @@
522 Glob *pIgnore, *pClean;
523
524 if( !dryRunFlag ){
525 dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
526 }
527 capture_case_sensitive_option();
528
529 /* We should be done with options.. */
530 verify_all_options();
531
532 db_must_be_within_tree();
@@ -634,11 +631,10 @@
634 int vid;
635 char *zDest;
636 Blob dest;
637 Stmt q;
638
639 capture_case_sensitive_option();
640 db_must_be_within_tree();
641
642 /* We should be done with options.. */
643 verify_all_options();
644
645
--- src/add.c
+++ src/add.c
@@ -260,11 +260,10 @@
260
261 zCleanFlag = find_option("clean",0,1);
262 zIgnoreFlag = find_option("ignore",0,1);
263 forceFlag = find_option("force","f",0)!=0;
264 if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
 
265
266 /* We should be done with options.. */
267 verify_all_options();
268
269 db_must_be_within_tree();
@@ -353,12 +352,10 @@
352 */
353 void delete_cmd(void){
354 int i;
355 Stmt loop;
356
 
 
357 /* We should be done with options.. */
358 verify_all_options();
359
360 db_must_be_within_tree();
361 db_begin_transaction();
@@ -445,12 +442,13 @@
442 #endif
443 caseSensitive = db_get_boolean("case-sensitive",caseSensitive);
444 }
445 if( !caseSensitive && g.localOpen ){
446 db_multi_exec(
447 "CREATE INDEX IF NOT EXISTS %s.vfile_nocase"
448 " ON vfile(pathname COLLATE nocase)",
449 db_name("localdb")
450 );
451 }
452 }
453 return caseSensitive;
454 }
@@ -522,11 +520,10 @@
520 Glob *pIgnore, *pClean;
521
522 if( !dryRunFlag ){
523 dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
524 }
 
525
526 /* We should be done with options.. */
527 verify_all_options();
528
529 db_must_be_within_tree();
@@ -634,11 +631,10 @@
631 int vid;
632 char *zDest;
633 Blob dest;
634 Stmt q;
635
 
636 db_must_be_within_tree();
637
638 /* We should be done with options.. */
639 verify_all_options();
640
641
+2 -2
--- src/attach.c
+++ src/attach.c
@@ -288,12 +288,12 @@
288288
if( pManifest ){
289289
blob_compress(&content, &content);
290290
addCompress = 1;
291291
}
292292
needModerator =
293
- (zTkt!=0 && g.perm.ModTkt==0 && db_get_boolean("modreq-tkt",0)==1) ||
294
- (zPage!=0 && g.perm.ModWiki==0 && db_get_boolean("modreq-wiki",0)==1);
293
+ (zTkt!=0 && ticket_need_moderation(0)) ||
294
+ (zPage!=0 && wiki_need_moderation(0));
295295
rid = content_put_ex(&content, 0, 0, 0, needModerator);
296296
zUUID = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
297297
blob_zero(&manifest);
298298
for(i=n=0; zName[i]; i++){
299299
if( zName[i]=='/' || zName[i]=='\\' ) n = i;
300300
--- src/attach.c
+++ src/attach.c
@@ -288,12 +288,12 @@
288 if( pManifest ){
289 blob_compress(&content, &content);
290 addCompress = 1;
291 }
292 needModerator =
293 (zTkt!=0 && g.perm.ModTkt==0 && db_get_boolean("modreq-tkt",0)==1) ||
294 (zPage!=0 && g.perm.ModWiki==0 && db_get_boolean("modreq-wiki",0)==1);
295 rid = content_put_ex(&content, 0, 0, 0, needModerator);
296 zUUID = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
297 blob_zero(&manifest);
298 for(i=n=0; zName[i]; i++){
299 if( zName[i]=='/' || zName[i]=='\\' ) n = i;
300
--- src/attach.c
+++ src/attach.c
@@ -288,12 +288,12 @@
288 if( pManifest ){
289 blob_compress(&content, &content);
290 addCompress = 1;
291 }
292 needModerator =
293 (zTkt!=0 && ticket_need_moderation(0)) ||
294 (zPage!=0 && wiki_need_moderation(0));
295 rid = content_put_ex(&content, 0, 0, 0, needModerator);
296 zUUID = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
297 blob_zero(&manifest);
298 for(i=n=0; zName[i]; i++){
299 if( zName[i]=='/' || zName[i]=='\\' ) n = i;
300
+1 -1
--- src/bisect.c
+++ src/bisect.c
@@ -396,11 +396,11 @@
396396
}
397397
}else if( g.argc==4 || g.argc==5 ){
398398
unsigned int i;
399399
n = strlen(g.argv[3]);
400400
for(i=0; i<sizeof(aBisectOption)/sizeof(aBisectOption[0]); i++){
401
- if( memcmp(g.argv[3], aBisectOption[i].zName, n)==0 ){
401
+ if( strncmp(g.argv[3], aBisectOption[i].zName, n)==0 ){
402402
char *z = mprintf("bisect-%s", aBisectOption[i].zName);
403403
if( g.argc==5 ){
404404
db_lset(z, g.argv[4]);
405405
}
406406
fossil_print("%s\n", db_lget(z, (char*)aBisectOption[i].zDefault));
407407
--- src/bisect.c
+++ src/bisect.c
@@ -396,11 +396,11 @@
396 }
397 }else if( g.argc==4 || g.argc==5 ){
398 unsigned int i;
399 n = strlen(g.argv[3]);
400 for(i=0; i<sizeof(aBisectOption)/sizeof(aBisectOption[0]); i++){
401 if( memcmp(g.argv[3], aBisectOption[i].zName, n)==0 ){
402 char *z = mprintf("bisect-%s", aBisectOption[i].zName);
403 if( g.argc==5 ){
404 db_lset(z, g.argv[4]);
405 }
406 fossil_print("%s\n", db_lget(z, (char*)aBisectOption[i].zDefault));
407
--- src/bisect.c
+++ src/bisect.c
@@ -396,11 +396,11 @@
396 }
397 }else if( g.argc==4 || g.argc==5 ){
398 unsigned int i;
399 n = strlen(g.argv[3]);
400 for(i=0; i<sizeof(aBisectOption)/sizeof(aBisectOption[0]); i++){
401 if( strncmp(g.argv[3], aBisectOption[i].zName, n)==0 ){
402 char *z = mprintf("bisect-%s", aBisectOption[i].zName);
403 if( g.argc==5 ){
404 db_lset(z, g.argv[4]);
405 }
406 fossil_print("%s\n", db_lget(z, (char*)aBisectOption[i].zDefault));
407
+1 -1
--- src/cache.c
+++ src/cache.c
@@ -236,11 +236,11 @@
236236
** Manage the cache used for potentially expensive web pages such as
237237
** /zip and /tarball. SUBCOMMAND an be:
238238
**
239239
** clear Remove all entries from the cache.
240240
**
241
-** init Create the cache file it it does not already exists.
241
+** init Create the cache file if it does not already exists.
242242
**
243243
** list|ls List the keys and content sizes and other stats for
244244
** all entries currently in the cache
245245
**
246246
** status Show a summary of cache status.
247247
--- src/cache.c
+++ src/cache.c
@@ -236,11 +236,11 @@
236 ** Manage the cache used for potentially expensive web pages such as
237 ** /zip and /tarball. SUBCOMMAND an be:
238 **
239 ** clear Remove all entries from the cache.
240 **
241 ** init Create the cache file it it does not already exists.
242 **
243 ** list|ls List the keys and content sizes and other stats for
244 ** all entries currently in the cache
245 **
246 ** status Show a summary of cache status.
247
--- src/cache.c
+++ src/cache.c
@@ -236,11 +236,11 @@
236 ** Manage the cache used for potentially expensive web pages such as
237 ** /zip and /tarball. SUBCOMMAND an be:
238 **
239 ** clear Remove all entries from the cache.
240 **
241 ** init Create the cache file if it does not already exists.
242 **
243 ** list|ls List the keys and content sizes and other stats for
244 ** all entries currently in the cache
245 **
246 ** status Show a summary of cache status.
247
+1 -1
--- src/captcha.c
+++ src/captcha.c
@@ -517,11 +517,11 @@
517517
char c = zEntered[i];
518518
if( c>='A' && c<='F' ) c += 'a' - 'A';
519519
if( c=='O' ) c = '0';
520520
z[i] = c;
521521
}
522
- if( memcmp(zDecode,z,8)!=0 ) return 0;
522
+ if( strncmp(zDecode,z,8)!=0 ) return 0;
523523
return 1;
524524
}
525525
526526
/*
527527
** Generate a captcha display together with the necessary hidden parameter
528528
--- src/captcha.c
+++ src/captcha.c
@@ -517,11 +517,11 @@
517 char c = zEntered[i];
518 if( c>='A' && c<='F' ) c += 'a' - 'A';
519 if( c=='O' ) c = '0';
520 z[i] = c;
521 }
522 if( memcmp(zDecode,z,8)!=0 ) return 0;
523 return 1;
524 }
525
526 /*
527 ** Generate a captcha display together with the necessary hidden parameter
528
--- src/captcha.c
+++ src/captcha.c
@@ -517,11 +517,11 @@
517 char c = zEntered[i];
518 if( c>='A' && c<='F' ) c += 'a' - 'A';
519 if( c=='O' ) c = '0';
520 z[i] = c;
521 }
522 if( strncmp(zDecode,z,8)!=0 ) return 0;
523 return 1;
524 }
525
526 /*
527 ** Generate a captcha display together with the necessary hidden parameter
528
+3 -1
--- src/cgi.c
+++ src/cgi.c
@@ -1626,10 +1626,12 @@
16261626
/*
16271627
** Bitmap values for the flags parameter to cgi_http_server().
16281628
*/
16291629
#define HTTP_SERVER_LOCALHOST 0x0001 /* Bind to 127.0.0.1 only */
16301630
#define HTTP_SERVER_SCGI 0x0002 /* SCGI instead of HTTP */
1631
+#define HTTP_SERVER_HAD_REPOSITORY 0x0004 /* Was the repository open? */
1632
+#define HTTP_SERVER_HAD_CHECKOUT 0x0008 /* Was a checkout open? */
16311633
16321634
#endif /* INTERFACE */
16331635
16341636
/*
16351637
** Maximum number of child processes that we can have running
@@ -1713,11 +1715,11 @@
17131715
fflush(stdout);
17141716
if( zBrowser ){
17151717
zBrowser = mprintf(zBrowser, iPort);
17161718
#if defined(__CYGWIN__)
17171719
/* On Cygwin, we can do better than "echo" */
1718
- if( memcmp(zBrowser, "echo ", 5)==0 ){
1720
+ if( strncmp(zBrowser, "echo ", 5)==0 ){
17191721
wchar_t *wUrl = fossil_utf8_to_unicode(zBrowser+5);
17201722
wUrl[wcslen(wUrl)-2] = 0; /* Strip terminating " &" */
17211723
if( (size_t)ShellExecuteW(0, L"open", wUrl, 0, 0, 1)<33 ){
17221724
fossil_warning("cannot start browser\n");
17231725
}
17241726
--- src/cgi.c
+++ src/cgi.c
@@ -1626,10 +1626,12 @@
1626 /*
1627 ** Bitmap values for the flags parameter to cgi_http_server().
1628 */
1629 #define HTTP_SERVER_LOCALHOST 0x0001 /* Bind to 127.0.0.1 only */
1630 #define HTTP_SERVER_SCGI 0x0002 /* SCGI instead of HTTP */
 
 
1631
1632 #endif /* INTERFACE */
1633
1634 /*
1635 ** Maximum number of child processes that we can have running
@@ -1713,11 +1715,11 @@
1713 fflush(stdout);
1714 if( zBrowser ){
1715 zBrowser = mprintf(zBrowser, iPort);
1716 #if defined(__CYGWIN__)
1717 /* On Cygwin, we can do better than "echo" */
1718 if( memcmp(zBrowser, "echo ", 5)==0 ){
1719 wchar_t *wUrl = fossil_utf8_to_unicode(zBrowser+5);
1720 wUrl[wcslen(wUrl)-2] = 0; /* Strip terminating " &" */
1721 if( (size_t)ShellExecuteW(0, L"open", wUrl, 0, 0, 1)<33 ){
1722 fossil_warning("cannot start browser\n");
1723 }
1724
--- src/cgi.c
+++ src/cgi.c
@@ -1626,10 +1626,12 @@
1626 /*
1627 ** Bitmap values for the flags parameter to cgi_http_server().
1628 */
1629 #define HTTP_SERVER_LOCALHOST 0x0001 /* Bind to 127.0.0.1 only */
1630 #define HTTP_SERVER_SCGI 0x0002 /* SCGI instead of HTTP */
1631 #define HTTP_SERVER_HAD_REPOSITORY 0x0004 /* Was the repository open? */
1632 #define HTTP_SERVER_HAD_CHECKOUT 0x0008 /* Was a checkout open? */
1633
1634 #endif /* INTERFACE */
1635
1636 /*
1637 ** Maximum number of child processes that we can have running
@@ -1713,11 +1715,11 @@
1715 fflush(stdout);
1716 if( zBrowser ){
1717 zBrowser = mprintf(zBrowser, iPort);
1718 #if defined(__CYGWIN__)
1719 /* On Cygwin, we can do better than "echo" */
1720 if( strncmp(zBrowser, "echo ", 5)==0 ){
1721 wchar_t *wUrl = fossil_utf8_to_unicode(zBrowser+5);
1722 wUrl[wcslen(wUrl)-2] = 0; /* Strip terminating " &" */
1723 if( (size_t)ShellExecuteW(0, L"open", wUrl, 0, 0, 1)<33 ){
1724 fossil_warning("cannot start browser\n");
1725 }
1726
+3 -5
--- src/checkin.c
+++ src/checkin.c
@@ -83,11 +83,13 @@
8383
if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){
8484
zDisplayName += 2; /* no unnecessary ./ prefix */
8585
}
8686
}
8787
blob_append(report, zPrefix, nPrefix);
88
- if( !file_wd_isfile_or_link(zFullName) ){
88
+ if( isDeleted ){
89
+ blob_appendf(report, "DELETED %s\n", zDisplayName);
90
+ }else if( !file_wd_isfile_or_link(zFullName) ){
8991
if( file_access(zFullName, F_OK)==0 ){
9092
blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName);
9193
if( missingIsFatal ){
9294
fossil_warning("not a file: %s", zDisplayName);
9395
nErr++;
@@ -99,12 +101,10 @@
99101
nErr++;
100102
}
101103
}
102104
}else if( isNew ){
103105
blob_appendf(report, "ADDED %s\n", zDisplayName);
104
- }else if( isDeleted ){
105
- blob_appendf(report, "DELETED %s\n", zDisplayName);
106106
}else if( isChnged ){
107107
if( isChnged==2 ){
108108
blob_appendf(report, "UPDATED_BY_MERGE %s\n", zDisplayName);
109109
}else if( isChnged==3 ){
110110
blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName);
@@ -473,11 +473,10 @@
473473
Glob *pIgnore;
474474
Blob rewrittenPathname;
475475
const char *zPathname, *zDisplayName;
476476
477477
if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP;
478
- capture_case_sensitive_option();
479478
db_must_be_within_tree();
480479
cwdRelative = determine_cwd_relative_option();
481480
482481
/* We should be done with options.. */
483482
verify_all_options();
@@ -596,11 +595,10 @@
596595
if( find_option("allckouts",0,0)!=0 ) scanFlags |= SCAN_NESTED;
597596
zIgnoreFlag = find_option("ignore",0,1);
598597
verboseFlag = find_option("verbose","v",0)!=0;
599598
zKeepFlag = find_option("keep",0,1);
600599
zCleanFlag = find_option("clean",0,1);
601
- capture_case_sensitive_option();
602600
db_must_be_within_tree();
603601
if( zIgnoreFlag==0 ){
604602
zIgnoreFlag = db_get("ignore-glob", 0);
605603
}
606604
if( zKeepFlag==0 ){
607605
--- src/checkin.c
+++ src/checkin.c
@@ -83,11 +83,13 @@
83 if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){
84 zDisplayName += 2; /* no unnecessary ./ prefix */
85 }
86 }
87 blob_append(report, zPrefix, nPrefix);
88 if( !file_wd_isfile_or_link(zFullName) ){
 
 
89 if( file_access(zFullName, F_OK)==0 ){
90 blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName);
91 if( missingIsFatal ){
92 fossil_warning("not a file: %s", zDisplayName);
93 nErr++;
@@ -99,12 +101,10 @@
99 nErr++;
100 }
101 }
102 }else if( isNew ){
103 blob_appendf(report, "ADDED %s\n", zDisplayName);
104 }else if( isDeleted ){
105 blob_appendf(report, "DELETED %s\n", zDisplayName);
106 }else if( isChnged ){
107 if( isChnged==2 ){
108 blob_appendf(report, "UPDATED_BY_MERGE %s\n", zDisplayName);
109 }else if( isChnged==3 ){
110 blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName);
@@ -473,11 +473,10 @@
473 Glob *pIgnore;
474 Blob rewrittenPathname;
475 const char *zPathname, *zDisplayName;
476
477 if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP;
478 capture_case_sensitive_option();
479 db_must_be_within_tree();
480 cwdRelative = determine_cwd_relative_option();
481
482 /* We should be done with options.. */
483 verify_all_options();
@@ -596,11 +595,10 @@
596 if( find_option("allckouts",0,0)!=0 ) scanFlags |= SCAN_NESTED;
597 zIgnoreFlag = find_option("ignore",0,1);
598 verboseFlag = find_option("verbose","v",0)!=0;
599 zKeepFlag = find_option("keep",0,1);
600 zCleanFlag = find_option("clean",0,1);
601 capture_case_sensitive_option();
602 db_must_be_within_tree();
603 if( zIgnoreFlag==0 ){
604 zIgnoreFlag = db_get("ignore-glob", 0);
605 }
606 if( zKeepFlag==0 ){
607
--- src/checkin.c
+++ src/checkin.c
@@ -83,11 +83,13 @@
83 if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){
84 zDisplayName += 2; /* no unnecessary ./ prefix */
85 }
86 }
87 blob_append(report, zPrefix, nPrefix);
88 if( isDeleted ){
89 blob_appendf(report, "DELETED %s\n", zDisplayName);
90 }else if( !file_wd_isfile_or_link(zFullName) ){
91 if( file_access(zFullName, F_OK)==0 ){
92 blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName);
93 if( missingIsFatal ){
94 fossil_warning("not a file: %s", zDisplayName);
95 nErr++;
@@ -99,12 +101,10 @@
101 nErr++;
102 }
103 }
104 }else if( isNew ){
105 blob_appendf(report, "ADDED %s\n", zDisplayName);
 
 
106 }else if( isChnged ){
107 if( isChnged==2 ){
108 blob_appendf(report, "UPDATED_BY_MERGE %s\n", zDisplayName);
109 }else if( isChnged==3 ){
110 blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName);
@@ -473,11 +473,10 @@
473 Glob *pIgnore;
474 Blob rewrittenPathname;
475 const char *zPathname, *zDisplayName;
476
477 if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP;
 
478 db_must_be_within_tree();
479 cwdRelative = determine_cwd_relative_option();
480
481 /* We should be done with options.. */
482 verify_all_options();
@@ -596,11 +595,10 @@
595 if( find_option("allckouts",0,0)!=0 ) scanFlags |= SCAN_NESTED;
596 zIgnoreFlag = find_option("ignore",0,1);
597 verboseFlag = find_option("verbose","v",0)!=0;
598 zKeepFlag = find_option("keep",0,1);
599 zCleanFlag = find_option("clean",0,1);
 
600 db_must_be_within_tree();
601 if( zIgnoreFlag==0 ){
602 zIgnoreFlag = db_get("ignore-glob", 0);
603 }
604 if( zKeepFlag==0 ){
605
+3 -2
--- src/checkout.c
+++ src/checkout.c
@@ -137,14 +137,15 @@
137137
138138
if( db_get_boolean("manifest",0) ){
139139
blob_zero(&manifest);
140140
content_get(vid, &manifest);
141141
zManFile = mprintf("%smanifest", g.zLocalRoot);
142
- blob_write_to_file(&manifest, zManFile);
143
- free(zManFile);
144142
blob_zero(&hash);
145143
sha1sum_blob(&manifest, &hash);
144
+ sterilize_manifest(&manifest);
145
+ blob_write_to_file(&manifest, zManFile);
146
+ free(zManFile);
146147
zManFile = mprintf("%smanifest.uuid", g.zLocalRoot);
147148
blob_append(&hash, "\n", 1);
148149
blob_write_to_file(&hash, zManFile);
149150
free(zManFile);
150151
blob_reset(&hash);
151152
--- src/checkout.c
+++ src/checkout.c
@@ -137,14 +137,15 @@
137
138 if( db_get_boolean("manifest",0) ){
139 blob_zero(&manifest);
140 content_get(vid, &manifest);
141 zManFile = mprintf("%smanifest", g.zLocalRoot);
142 blob_write_to_file(&manifest, zManFile);
143 free(zManFile);
144 blob_zero(&hash);
145 sha1sum_blob(&manifest, &hash);
 
 
 
146 zManFile = mprintf("%smanifest.uuid", g.zLocalRoot);
147 blob_append(&hash, "\n", 1);
148 blob_write_to_file(&hash, zManFile);
149 free(zManFile);
150 blob_reset(&hash);
151
--- src/checkout.c
+++ src/checkout.c
@@ -137,14 +137,15 @@
137
138 if( db_get_boolean("manifest",0) ){
139 blob_zero(&manifest);
140 content_get(vid, &manifest);
141 zManFile = mprintf("%smanifest", g.zLocalRoot);
 
 
142 blob_zero(&hash);
143 sha1sum_blob(&manifest, &hash);
144 sterilize_manifest(&manifest);
145 blob_write_to_file(&manifest, zManFile);
146 free(zManFile);
147 zManFile = mprintf("%smanifest.uuid", g.zLocalRoot);
148 blob_append(&hash, "\n", 1);
149 blob_write_to_file(&hash, zManFile);
150 free(zManFile);
151 blob_reset(&hash);
152
+1 -1
--- src/configure.c
+++ src/configure.c
@@ -222,11 +222,11 @@
222222
if( n>2 && zName[0]=='\'' && zName[n-1]=='\'' ){
223223
zName++;
224224
n -= 2;
225225
}
226226
for(i=0; i<count(aConfig); i++){
227
- if( memcmp(zName, aConfig[i].zName, n)==0 && aConfig[i].zName[n]==0 ){
227
+ if( strncmp(zName, aConfig[i].zName, n)==0 && aConfig[i].zName[n]==0 ){
228228
int m = aConfig[i].groupMask;
229229
if( !g.perm.Admin ){
230230
m &= ~CONFIGSET_USER;
231231
}
232232
if( !g.perm.RdAddr ){
233233
--- src/configure.c
+++ src/configure.c
@@ -222,11 +222,11 @@
222 if( n>2 && zName[0]=='\'' && zName[n-1]=='\'' ){
223 zName++;
224 n -= 2;
225 }
226 for(i=0; i<count(aConfig); i++){
227 if( memcmp(zName, aConfig[i].zName, n)==0 && aConfig[i].zName[n]==0 ){
228 int m = aConfig[i].groupMask;
229 if( !g.perm.Admin ){
230 m &= ~CONFIGSET_USER;
231 }
232 if( !g.perm.RdAddr ){
233
--- src/configure.c
+++ src/configure.c
@@ -222,11 +222,11 @@
222 if( n>2 && zName[0]=='\'' && zName[n-1]=='\'' ){
223 zName++;
224 n -= 2;
225 }
226 for(i=0; i<count(aConfig); i++){
227 if( strncmp(zName, aConfig[i].zName, n)==0 && aConfig[i].zName[n]==0 ){
228 int m = aConfig[i].groupMask;
229 if( !g.perm.Admin ){
230 m &= ~CONFIGSET_USER;
231 }
232 if( !g.perm.RdAddr ){
233
+94 -21
--- src/db.c
+++ src/db.c
@@ -1317,10 +1317,42 @@
13171317
"INSERT OR IGNORE INTO user(login,pw,cap,info)"
13181318
" VALUES('reader','','kptw','Reader');"
13191319
);
13201320
}
13211321
}
1322
+
1323
+/*
1324
+** This function sets the server and project codes if they do not already
1325
+** exist. Currently, it should be called only by the db_initial_setup()
1326
+** or cmd_webserver() functions, the latter being used to facilitate more
1327
+** robust integration with "canned image" environments (e.g. Docker).
1328
+*/
1329
+void db_setup_server_and_project_codes(
1330
+ int optional
1331
+){
1332
+ if( !optional ){
1333
+ db_multi_exec(
1334
+ "INSERT INTO config(name,value,mtime)"
1335
+ " VALUES('server-code', lower(hex(randomblob(20))),now());"
1336
+ "INSERT INTO config(name,value,mtime)"
1337
+ " VALUES('project-code', lower(hex(randomblob(20))),now());"
1338
+ );
1339
+ }else{
1340
+ if( db_get("server-code", 0)==0 ) {
1341
+ db_optional_sql("repository",
1342
+ "INSERT INTO config(name,value,mtime)"
1343
+ " VALUES('server-code', lower(hex(randomblob(20))),now());"
1344
+ );
1345
+ }
1346
+ if( db_get("project-code", 0)==0 ) {
1347
+ db_optional_sql("repository",
1348
+ "INSERT INTO config(name,value,mtime)"
1349
+ " VALUES('project-code', lower(hex(randomblob(20))),now());"
1350
+ );
1351
+ }
1352
+ }
1353
+}
13221354
13231355
/*
13241356
** Return a pointer to a string that contains the RHS of an IN operator
13251357
** that will select CONFIG table names that are in the list of control
13261358
** settings.
@@ -1370,16 +1402,11 @@
13701402
13711403
db_set("content-schema", CONTENT_SCHEMA, 0);
13721404
db_set("aux-schema", AUX_SCHEMA, 0);
13731405
db_set("rebuilt", get_version(), 0);
13741406
if( makeServerCodes ){
1375
- db_multi_exec(
1376
- "INSERT INTO config(name,value,mtime)"
1377
- " VALUES('server-code', lower(hex(randomblob(20))),now());"
1378
- "INSERT INTO config(name,value,mtime)"
1379
- " VALUES('project-code', lower(hex(randomblob(20))),now());"
1380
- );
1407
+ db_setup_server_and_project_codes(0);
13811408
}
13821409
if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
13831410
if( !db_is_global("localauth") ) db_set_int("localauth", 0, 0);
13841411
if( !db_is_global("timeline-plaintext") ){
13851412
db_set_int("timeline-plaintext", 1, 0);
@@ -1475,23 +1502,25 @@
14751502
** Options:
14761503
** --template FILE copy settings from repository file
14771504
** --admin-user|-A USERNAME select given USERNAME as admin user
14781505
** --date-override DATETIME use DATETIME as time of the initial checkin
14791506
** (default: do not create an initial checkin)
1507
+** --empty create repository without project-id/server-id
14801508
**
14811509
** See also: clone
14821510
*/
14831511
void create_repository_cmd(void){
14841512
char *zPassword;
14851513
const char *zTemplate; /* Repository from which to copy settings */
14861514
const char *zDate; /* Date of the initial check-in */
14871515
const char *zDefaultUser; /* Optional name of the default user */
1516
+ int makeServerCodes;
14881517
14891518
zTemplate = find_option("template",0,1);
14901519
zDate = find_option("date-override",0,1);
14911520
zDefaultUser = find_option("admin-user","A",1);
1492
- find_option("empty", 0, 0); /* deprecated */
1521
+ makeServerCodes = find_option("empty", 0, 0)==0;
14931522
14941523
/* We should be done with options.. */
14951524
verify_all_options();
14961525
14971526
if( g.argc!=3 ){
@@ -1500,15 +1529,17 @@
15001529
db_create_repository(g.argv[2]);
15011530
db_open_repository(g.argv[2]);
15021531
db_open_config(0);
15031532
if( zTemplate ) db_attach(zTemplate, "settingSrc");
15041533
db_begin_transaction();
1505
- db_initial_setup(zTemplate, zDate, zDefaultUser, 1);
1534
+ db_initial_setup(zTemplate, zDate, zDefaultUser, makeServerCodes);
15061535
db_end_transaction(0);
15071536
if( zTemplate ) db_detach("settingSrc");
1508
- fossil_print("project-id: %s\n", db_get("project-code", 0));
1509
- fossil_print("server-id: %s\n", db_get("server-code", 0));
1537
+ if( makeServerCodes ){
1538
+ fossil_print("project-id: %s\n", db_get("project-code", 0));
1539
+ fossil_print("server-id: %s\n", db_get("server-code", 0));
1540
+ }
15101541
zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
15111542
fossil_print("admin-user: %s (initial password is \"%s\")\n",
15121543
g.zLogin, zPassword);
15131544
}
15141545
@@ -1978,36 +2009,56 @@
19782009
** ckout:%s
19792010
**
19802011
** Where %s is the checkout root. The value is the repository file.
19812012
*/
19822013
void db_record_repository_filename(const char *zName){
2014
+ const char *zCollation;
2015
+ char *zRepoSetting;
2016
+ char *zCkoutSetting;
19832017
Blob full;
19842018
if( zName==0 ){
19852019
if( !g.localOpen ) return;
19862020
zName = db_repository_filename();
19872021
}
19882022
file_canonical_name(zName, &full, 0);
2023
+ zCollation = filename_collation();
19892024
db_swap_connections();
2025
+ zRepoSetting = mprintf("repo:%q", blob_str(&full));
2026
+ db_multi_exec(
2027
+ "DELETE FROM global_config WHERE name %s = '%s';",
2028
+ zCollation, zRepoSetting
2029
+ );
19902030
db_multi_exec(
19912031
"INSERT OR IGNORE INTO global_config(name,value)"
1992
- "VALUES('repo:%q',1)",
1993
- blob_str(&full)
2032
+ "VALUES('%s',1);",
2033
+ zRepoSetting
19942034
);
2035
+ fossil_free(zRepoSetting);
19952036
if( g.localOpen && g.zLocalRoot && g.zLocalRoot[0] ){
19962037
Blob localRoot;
19972038
file_canonical_name(g.zLocalRoot, &localRoot, 1);
2039
+ zCkoutSetting = mprintf("ckout:%q", blob_str(&localRoot));
2040
+ db_multi_exec(
2041
+ "DELETE FROM global_config WHERE name %s = '%s';",
2042
+ zCollation, zCkoutSetting
2043
+ );
19982044
db_multi_exec(
19992045
"REPLACE INTO global_config(name, value)"
2000
- "VALUES('ckout:%q','%q');",
2001
- blob_str(&localRoot), blob_str(&full)
2046
+ "VALUES('%s','%q');",
2047
+ zCkoutSetting, blob_str(&full)
20022048
);
20032049
db_swap_connections();
2050
+ db_optional_sql("repository",
2051
+ "DELETE FROM config WHERE name %s = '%s';",
2052
+ zCollation, zCkoutSetting
2053
+ );
20042054
db_optional_sql("repository",
20052055
"REPLACE INTO config(name,value,mtime)"
2006
- "VALUES('ckout:%q',1,now())",
2007
- blob_str(&localRoot)
2056
+ "VALUES('%s',1,now());",
2057
+ zCkoutSetting
20082058
);
2059
+ fossil_free(zCkoutSetting);
20092060
blob_reset(&localRoot);
20102061
}else{
20112062
db_swap_connections();
20122063
}
20132064
blob_reset(&full);
@@ -2494,17 +2545,39 @@
24942545
}
24952546
isManifest = fossil_strcmp(ctrlSettings[i].name, "manifest")==0;
24962547
if( isManifest && globalFlag ){
24972548
fossil_fatal("cannot set 'manifest' globally");
24982549
}
2499
- if( unsetFlag ){
2500
- db_unset(ctrlSettings[i].name, globalFlag);
2501
- }else if( g.argc==4 ){
2502
- db_set(ctrlSettings[i].name, g.argv[3], globalFlag);
2550
+ if( unsetFlag || g.argc==4 ){
2551
+ if( ctrlSettings[i+1].name
2552
+ && strncmp(ctrlSettings[i+1].name, zName, n)==0
2553
+ && ctrlSettings[i].name[n]!=0
2554
+ ){
2555
+ fossil_print("ambiguous property prefix: %s\nMatching properties:\n",
2556
+ zName);
2557
+ while( ctrlSettings[i].name
2558
+ && strncmp(ctrlSettings[i].name, zName, n)==0
2559
+ ){
2560
+ fossil_print("%s\n", ctrlSettings[i].name);
2561
+ i++;
2562
+ }
2563
+ fossil_exit(1);
2564
+ }else{
2565
+ if( unsetFlag ){
2566
+ db_unset(ctrlSettings[i].name, globalFlag);
2567
+ }else{
2568
+ db_set(ctrlSettings[i].name, g.argv[3], globalFlag);
2569
+ }
2570
+ }
25032571
}else{
25042572
isManifest = 0;
2505
- print_setting(&ctrlSettings[i], db_open_local(0));
2573
+ while( ctrlSettings[i].name
2574
+ && strncmp(ctrlSettings[i].name, zName, n)==0
2575
+ ){
2576
+ print_setting(&ctrlSettings[i], db_open_local(0));
2577
+ i++;
2578
+ }
25062579
}
25072580
if( isManifest && g.localOpen ){
25082581
manifest_to_disk(db_lget_int("checkout", 0));
25092582
}
25102583
}else{
25112584
--- src/db.c
+++ src/db.c
@@ -1317,10 +1317,42 @@
1317 "INSERT OR IGNORE INTO user(login,pw,cap,info)"
1318 " VALUES('reader','','kptw','Reader');"
1319 );
1320 }
1321 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1322
1323 /*
1324 ** Return a pointer to a string that contains the RHS of an IN operator
1325 ** that will select CONFIG table names that are in the list of control
1326 ** settings.
@@ -1370,16 +1402,11 @@
1370
1371 db_set("content-schema", CONTENT_SCHEMA, 0);
1372 db_set("aux-schema", AUX_SCHEMA, 0);
1373 db_set("rebuilt", get_version(), 0);
1374 if( makeServerCodes ){
1375 db_multi_exec(
1376 "INSERT INTO config(name,value,mtime)"
1377 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1378 "INSERT INTO config(name,value,mtime)"
1379 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1380 );
1381 }
1382 if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
1383 if( !db_is_global("localauth") ) db_set_int("localauth", 0, 0);
1384 if( !db_is_global("timeline-plaintext") ){
1385 db_set_int("timeline-plaintext", 1, 0);
@@ -1475,23 +1502,25 @@
1475 ** Options:
1476 ** --template FILE copy settings from repository file
1477 ** --admin-user|-A USERNAME select given USERNAME as admin user
1478 ** --date-override DATETIME use DATETIME as time of the initial checkin
1479 ** (default: do not create an initial checkin)
 
1480 **
1481 ** See also: clone
1482 */
1483 void create_repository_cmd(void){
1484 char *zPassword;
1485 const char *zTemplate; /* Repository from which to copy settings */
1486 const char *zDate; /* Date of the initial check-in */
1487 const char *zDefaultUser; /* Optional name of the default user */
 
1488
1489 zTemplate = find_option("template",0,1);
1490 zDate = find_option("date-override",0,1);
1491 zDefaultUser = find_option("admin-user","A",1);
1492 find_option("empty", 0, 0); /* deprecated */
1493
1494 /* We should be done with options.. */
1495 verify_all_options();
1496
1497 if( g.argc!=3 ){
@@ -1500,15 +1529,17 @@
1500 db_create_repository(g.argv[2]);
1501 db_open_repository(g.argv[2]);
1502 db_open_config(0);
1503 if( zTemplate ) db_attach(zTemplate, "settingSrc");
1504 db_begin_transaction();
1505 db_initial_setup(zTemplate, zDate, zDefaultUser, 1);
1506 db_end_transaction(0);
1507 if( zTemplate ) db_detach("settingSrc");
1508 fossil_print("project-id: %s\n", db_get("project-code", 0));
1509 fossil_print("server-id: %s\n", db_get("server-code", 0));
 
 
1510 zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
1511 fossil_print("admin-user: %s (initial password is \"%s\")\n",
1512 g.zLogin, zPassword);
1513 }
1514
@@ -1978,36 +2009,56 @@
1978 ** ckout:%s
1979 **
1980 ** Where %s is the checkout root. The value is the repository file.
1981 */
1982 void db_record_repository_filename(const char *zName){
 
 
 
1983 Blob full;
1984 if( zName==0 ){
1985 if( !g.localOpen ) return;
1986 zName = db_repository_filename();
1987 }
1988 file_canonical_name(zName, &full, 0);
 
1989 db_swap_connections();
 
 
 
 
 
1990 db_multi_exec(
1991 "INSERT OR IGNORE INTO global_config(name,value)"
1992 "VALUES('repo:%q',1)",
1993 blob_str(&full)
1994 );
 
1995 if( g.localOpen && g.zLocalRoot && g.zLocalRoot[0] ){
1996 Blob localRoot;
1997 file_canonical_name(g.zLocalRoot, &localRoot, 1);
 
 
 
 
 
1998 db_multi_exec(
1999 "REPLACE INTO global_config(name, value)"
2000 "VALUES('ckout:%q','%q');",
2001 blob_str(&localRoot), blob_str(&full)
2002 );
2003 db_swap_connections();
 
 
 
 
2004 db_optional_sql("repository",
2005 "REPLACE INTO config(name,value,mtime)"
2006 "VALUES('ckout:%q',1,now())",
2007 blob_str(&localRoot)
2008 );
 
2009 blob_reset(&localRoot);
2010 }else{
2011 db_swap_connections();
2012 }
2013 blob_reset(&full);
@@ -2494,17 +2545,39 @@
2494 }
2495 isManifest = fossil_strcmp(ctrlSettings[i].name, "manifest")==0;
2496 if( isManifest && globalFlag ){
2497 fossil_fatal("cannot set 'manifest' globally");
2498 }
2499 if( unsetFlag ){
2500 db_unset(ctrlSettings[i].name, globalFlag);
2501 }else if( g.argc==4 ){
2502 db_set(ctrlSettings[i].name, g.argv[3], globalFlag);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2503 }else{
2504 isManifest = 0;
2505 print_setting(&ctrlSettings[i], db_open_local(0));
 
 
 
 
 
2506 }
2507 if( isManifest && g.localOpen ){
2508 manifest_to_disk(db_lget_int("checkout", 0));
2509 }
2510 }else{
2511
--- src/db.c
+++ src/db.c
@@ -1317,10 +1317,42 @@
1317 "INSERT OR IGNORE INTO user(login,pw,cap,info)"
1318 " VALUES('reader','','kptw','Reader');"
1319 );
1320 }
1321 }
1322
1323 /*
1324 ** This function sets the server and project codes if they do not already
1325 ** exist. Currently, it should be called only by the db_initial_setup()
1326 ** or cmd_webserver() functions, the latter being used to facilitate more
1327 ** robust integration with "canned image" environments (e.g. Docker).
1328 */
1329 void db_setup_server_and_project_codes(
1330 int optional
1331 ){
1332 if( !optional ){
1333 db_multi_exec(
1334 "INSERT INTO config(name,value,mtime)"
1335 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1336 "INSERT INTO config(name,value,mtime)"
1337 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1338 );
1339 }else{
1340 if( db_get("server-code", 0)==0 ) {
1341 db_optional_sql("repository",
1342 "INSERT INTO config(name,value,mtime)"
1343 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1344 );
1345 }
1346 if( db_get("project-code", 0)==0 ) {
1347 db_optional_sql("repository",
1348 "INSERT INTO config(name,value,mtime)"
1349 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1350 );
1351 }
1352 }
1353 }
1354
1355 /*
1356 ** Return a pointer to a string that contains the RHS of an IN operator
1357 ** that will select CONFIG table names that are in the list of control
1358 ** settings.
@@ -1370,16 +1402,11 @@
1402
1403 db_set("content-schema", CONTENT_SCHEMA, 0);
1404 db_set("aux-schema", AUX_SCHEMA, 0);
1405 db_set("rebuilt", get_version(), 0);
1406 if( makeServerCodes ){
1407 db_setup_server_and_project_codes(0);
 
 
 
 
 
1408 }
1409 if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
1410 if( !db_is_global("localauth") ) db_set_int("localauth", 0, 0);
1411 if( !db_is_global("timeline-plaintext") ){
1412 db_set_int("timeline-plaintext", 1, 0);
@@ -1475,23 +1502,25 @@
1502 ** Options:
1503 ** --template FILE copy settings from repository file
1504 ** --admin-user|-A USERNAME select given USERNAME as admin user
1505 ** --date-override DATETIME use DATETIME as time of the initial checkin
1506 ** (default: do not create an initial checkin)
1507 ** --empty create repository without project-id/server-id
1508 **
1509 ** See also: clone
1510 */
1511 void create_repository_cmd(void){
1512 char *zPassword;
1513 const char *zTemplate; /* Repository from which to copy settings */
1514 const char *zDate; /* Date of the initial check-in */
1515 const char *zDefaultUser; /* Optional name of the default user */
1516 int makeServerCodes;
1517
1518 zTemplate = find_option("template",0,1);
1519 zDate = find_option("date-override",0,1);
1520 zDefaultUser = find_option("admin-user","A",1);
1521 makeServerCodes = find_option("empty", 0, 0)==0;
1522
1523 /* We should be done with options.. */
1524 verify_all_options();
1525
1526 if( g.argc!=3 ){
@@ -1500,15 +1529,17 @@
1529 db_create_repository(g.argv[2]);
1530 db_open_repository(g.argv[2]);
1531 db_open_config(0);
1532 if( zTemplate ) db_attach(zTemplate, "settingSrc");
1533 db_begin_transaction();
1534 db_initial_setup(zTemplate, zDate, zDefaultUser, makeServerCodes);
1535 db_end_transaction(0);
1536 if( zTemplate ) db_detach("settingSrc");
1537 if( makeServerCodes ){
1538 fossil_print("project-id: %s\n", db_get("project-code", 0));
1539 fossil_print("server-id: %s\n", db_get("server-code", 0));
1540 }
1541 zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
1542 fossil_print("admin-user: %s (initial password is \"%s\")\n",
1543 g.zLogin, zPassword);
1544 }
1545
@@ -1978,36 +2009,56 @@
2009 ** ckout:%s
2010 **
2011 ** Where %s is the checkout root. The value is the repository file.
2012 */
2013 void db_record_repository_filename(const char *zName){
2014 const char *zCollation;
2015 char *zRepoSetting;
2016 char *zCkoutSetting;
2017 Blob full;
2018 if( zName==0 ){
2019 if( !g.localOpen ) return;
2020 zName = db_repository_filename();
2021 }
2022 file_canonical_name(zName, &full, 0);
2023 zCollation = filename_collation();
2024 db_swap_connections();
2025 zRepoSetting = mprintf("repo:%q", blob_str(&full));
2026 db_multi_exec(
2027 "DELETE FROM global_config WHERE name %s = '%s';",
2028 zCollation, zRepoSetting
2029 );
2030 db_multi_exec(
2031 "INSERT OR IGNORE INTO global_config(name,value)"
2032 "VALUES('%s',1);",
2033 zRepoSetting
2034 );
2035 fossil_free(zRepoSetting);
2036 if( g.localOpen && g.zLocalRoot && g.zLocalRoot[0] ){
2037 Blob localRoot;
2038 file_canonical_name(g.zLocalRoot, &localRoot, 1);
2039 zCkoutSetting = mprintf("ckout:%q", blob_str(&localRoot));
2040 db_multi_exec(
2041 "DELETE FROM global_config WHERE name %s = '%s';",
2042 zCollation, zCkoutSetting
2043 );
2044 db_multi_exec(
2045 "REPLACE INTO global_config(name, value)"
2046 "VALUES('%s','%q');",
2047 zCkoutSetting, blob_str(&full)
2048 );
2049 db_swap_connections();
2050 db_optional_sql("repository",
2051 "DELETE FROM config WHERE name %s = '%s';",
2052 zCollation, zCkoutSetting
2053 );
2054 db_optional_sql("repository",
2055 "REPLACE INTO config(name,value,mtime)"
2056 "VALUES('%s',1,now());",
2057 zCkoutSetting
2058 );
2059 fossil_free(zCkoutSetting);
2060 blob_reset(&localRoot);
2061 }else{
2062 db_swap_connections();
2063 }
2064 blob_reset(&full);
@@ -2494,17 +2545,39 @@
2545 }
2546 isManifest = fossil_strcmp(ctrlSettings[i].name, "manifest")==0;
2547 if( isManifest && globalFlag ){
2548 fossil_fatal("cannot set 'manifest' globally");
2549 }
2550 if( unsetFlag || g.argc==4 ){
2551 if( ctrlSettings[i+1].name
2552 && strncmp(ctrlSettings[i+1].name, zName, n)==0
2553 && ctrlSettings[i].name[n]!=0
2554 ){
2555 fossil_print("ambiguous property prefix: %s\nMatching properties:\n",
2556 zName);
2557 while( ctrlSettings[i].name
2558 && strncmp(ctrlSettings[i].name, zName, n)==0
2559 ){
2560 fossil_print("%s\n", ctrlSettings[i].name);
2561 i++;
2562 }
2563 fossil_exit(1);
2564 }else{
2565 if( unsetFlag ){
2566 db_unset(ctrlSettings[i].name, globalFlag);
2567 }else{
2568 db_set(ctrlSettings[i].name, g.argv[3], globalFlag);
2569 }
2570 }
2571 }else{
2572 isManifest = 0;
2573 while( ctrlSettings[i].name
2574 && strncmp(ctrlSettings[i].name, zName, n)==0
2575 ){
2576 print_setting(&ctrlSettings[i], db_open_local(0));
2577 i++;
2578 }
2579 }
2580 if( isManifest && g.localOpen ){
2581 manifest_to_disk(db_lget_int("checkout", 0));
2582 }
2583 }else{
2584
+94 -21
--- src/db.c
+++ src/db.c
@@ -1317,10 +1317,42 @@
13171317
"INSERT OR IGNORE INTO user(login,pw,cap,info)"
13181318
" VALUES('reader','','kptw','Reader');"
13191319
);
13201320
}
13211321
}
1322
+
1323
+/*
1324
+** This function sets the server and project codes if they do not already
1325
+** exist. Currently, it should be called only by the db_initial_setup()
1326
+** or cmd_webserver() functions, the latter being used to facilitate more
1327
+** robust integration with "canned image" environments (e.g. Docker).
1328
+*/
1329
+void db_setup_server_and_project_codes(
1330
+ int optional
1331
+){
1332
+ if( !optional ){
1333
+ db_multi_exec(
1334
+ "INSERT INTO config(name,value,mtime)"
1335
+ " VALUES('server-code', lower(hex(randomblob(20))),now());"
1336
+ "INSERT INTO config(name,value,mtime)"
1337
+ " VALUES('project-code', lower(hex(randomblob(20))),now());"
1338
+ );
1339
+ }else{
1340
+ if( db_get("server-code", 0)==0 ) {
1341
+ db_optional_sql("repository",
1342
+ "INSERT INTO config(name,value,mtime)"
1343
+ " VALUES('server-code', lower(hex(randomblob(20))),now());"
1344
+ );
1345
+ }
1346
+ if( db_get("project-code", 0)==0 ) {
1347
+ db_optional_sql("repository",
1348
+ "INSERT INTO config(name,value,mtime)"
1349
+ " VALUES('project-code', lower(hex(randomblob(20))),now());"
1350
+ );
1351
+ }
1352
+ }
1353
+}
13221354
13231355
/*
13241356
** Return a pointer to a string that contains the RHS of an IN operator
13251357
** that will select CONFIG table names that are in the list of control
13261358
** settings.
@@ -1370,16 +1402,11 @@
13701402
13711403
db_set("content-schema", CONTENT_SCHEMA, 0);
13721404
db_set("aux-schema", AUX_SCHEMA, 0);
13731405
db_set("rebuilt", get_version(), 0);
13741406
if( makeServerCodes ){
1375
- db_multi_exec(
1376
- "INSERT INTO config(name,value,mtime)"
1377
- " VALUES('server-code', lower(hex(randomblob(20))),now());"
1378
- "INSERT INTO config(name,value,mtime)"
1379
- " VALUES('project-code', lower(hex(randomblob(20))),now());"
1380
- );
1407
+ db_setup_server_and_project_codes(0);
13811408
}
13821409
if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
13831410
if( !db_is_global("localauth") ) db_set_int("localauth", 0, 0);
13841411
if( !db_is_global("timeline-plaintext") ){
13851412
db_set_int("timeline-plaintext", 1, 0);
@@ -1475,23 +1502,25 @@
14751502
** Options:
14761503
** --template FILE copy settings from repository file
14771504
** --admin-user|-A USERNAME select given USERNAME as admin user
14781505
** --date-override DATETIME use DATETIME as time of the initial checkin
14791506
** (default: do not create an initial checkin)
1507
+** --empty create repository without project-id/server-id
14801508
**
14811509
** See also: clone
14821510
*/
14831511
void create_repository_cmd(void){
14841512
char *zPassword;
14851513
const char *zTemplate; /* Repository from which to copy settings */
14861514
const char *zDate; /* Date of the initial check-in */
14871515
const char *zDefaultUser; /* Optional name of the default user */
1516
+ int makeServerCodes;
14881517
14891518
zTemplate = find_option("template",0,1);
14901519
zDate = find_option("date-override",0,1);
14911520
zDefaultUser = find_option("admin-user","A",1);
1492
- find_option("empty", 0, 0); /* deprecated */
1521
+ makeServerCodes = find_option("empty", 0, 0)==0;
14931522
14941523
/* We should be done with options.. */
14951524
verify_all_options();
14961525
14971526
if( g.argc!=3 ){
@@ -1500,15 +1529,17 @@
15001529
db_create_repository(g.argv[2]);
15011530
db_open_repository(g.argv[2]);
15021531
db_open_config(0);
15031532
if( zTemplate ) db_attach(zTemplate, "settingSrc");
15041533
db_begin_transaction();
1505
- db_initial_setup(zTemplate, zDate, zDefaultUser, 1);
1534
+ db_initial_setup(zTemplate, zDate, zDefaultUser, makeServerCodes);
15061535
db_end_transaction(0);
15071536
if( zTemplate ) db_detach("settingSrc");
1508
- fossil_print("project-id: %s\n", db_get("project-code", 0));
1509
- fossil_print("server-id: %s\n", db_get("server-code", 0));
1537
+ if( makeServerCodes ){
1538
+ fossil_print("project-id: %s\n", db_get("project-code", 0));
1539
+ fossil_print("server-id: %s\n", db_get("server-code", 0));
1540
+ }
15101541
zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
15111542
fossil_print("admin-user: %s (initial password is \"%s\")\n",
15121543
g.zLogin, zPassword);
15131544
}
15141545
@@ -1978,36 +2009,56 @@
19782009
** ckout:%s
19792010
**
19802011
** Where %s is the checkout root. The value is the repository file.
19812012
*/
19822013
void db_record_repository_filename(const char *zName){
2014
+ const char *zCollation;
2015
+ char *zRepoSetting;
2016
+ char *zCkoutSetting;
19832017
Blob full;
19842018
if( zName==0 ){
19852019
if( !g.localOpen ) return;
19862020
zName = db_repository_filename();
19872021
}
19882022
file_canonical_name(zName, &full, 0);
2023
+ zCollation = filename_collation();
19892024
db_swap_connections();
2025
+ zRepoSetting = mprintf("repo:%q", blob_str(&full));
2026
+ db_multi_exec(
2027
+ "DELETE FROM global_config WHERE name %s = '%s';",
2028
+ zCollation, zRepoSetting
2029
+ );
19902030
db_multi_exec(
19912031
"INSERT OR IGNORE INTO global_config(name,value)"
1992
- "VALUES('repo:%q',1)",
1993
- blob_str(&full)
2032
+ "VALUES('%s',1);",
2033
+ zRepoSetting
19942034
);
2035
+ fossil_free(zRepoSetting);
19952036
if( g.localOpen && g.zLocalRoot && g.zLocalRoot[0] ){
19962037
Blob localRoot;
19972038
file_canonical_name(g.zLocalRoot, &localRoot, 1);
2039
+ zCkoutSetting = mprintf("ckout:%q", blob_str(&localRoot));
2040
+ db_multi_exec(
2041
+ "DELETE FROM global_config WHERE name %s = '%s';",
2042
+ zCollation, zCkoutSetting
2043
+ );
19982044
db_multi_exec(
19992045
"REPLACE INTO global_config(name, value)"
2000
- "VALUES('ckout:%q','%q');",
2001
- blob_str(&localRoot), blob_str(&full)
2046
+ "VALUES('%s','%q');",
2047
+ zCkoutSetting, blob_str(&full)
20022048
);
20032049
db_swap_connections();
2050
+ db_optional_sql("repository",
2051
+ "DELETE FROM config WHERE name %s = '%s';",
2052
+ zCollation, zCkoutSetting
2053
+ );
20042054
db_optional_sql("repository",
20052055
"REPLACE INTO config(name,value,mtime)"
2006
- "VALUES('ckout:%q',1,now())",
2007
- blob_str(&localRoot)
2056
+ "VALUES('%s',1,now());",
2057
+ zCkoutSetting
20082058
);
2059
+ fossil_free(zCkoutSetting);
20092060
blob_reset(&localRoot);
20102061
}else{
20112062
db_swap_connections();
20122063
}
20132064
blob_reset(&full);
@@ -2494,17 +2545,39 @@
24942545
}
24952546
isManifest = fossil_strcmp(ctrlSettings[i].name, "manifest")==0;
24962547
if( isManifest && globalFlag ){
24972548
fossil_fatal("cannot set 'manifest' globally");
24982549
}
2499
- if( unsetFlag ){
2500
- db_unset(ctrlSettings[i].name, globalFlag);
2501
- }else if( g.argc==4 ){
2502
- db_set(ctrlSettings[i].name, g.argv[3], globalFlag);
2550
+ if( unsetFlag || g.argc==4 ){
2551
+ if( ctrlSettings[i+1].name
2552
+ && strncmp(ctrlSettings[i+1].name, zName, n)==0
2553
+ && ctrlSettings[i].name[n]!=0
2554
+ ){
2555
+ fossil_print("ambiguous property prefix: %s\nMatching properties:\n",
2556
+ zName);
2557
+ while( ctrlSettings[i].name
2558
+ && strncmp(ctrlSettings[i].name, zName, n)==0
2559
+ ){
2560
+ fossil_print("%s\n", ctrlSettings[i].name);
2561
+ i++;
2562
+ }
2563
+ fossil_exit(1);
2564
+ }else{
2565
+ if( unsetFlag ){
2566
+ db_unset(ctrlSettings[i].name, globalFlag);
2567
+ }else{
2568
+ db_set(ctrlSettings[i].name, g.argv[3], globalFlag);
2569
+ }
2570
+ }
25032571
}else{
25042572
isManifest = 0;
2505
- print_setting(&ctrlSettings[i], db_open_local(0));
2573
+ while( ctrlSettings[i].name
2574
+ && strncmp(ctrlSettings[i].name, zName, n)==0
2575
+ ){
2576
+ print_setting(&ctrlSettings[i], db_open_local(0));
2577
+ i++;
2578
+ }
25062579
}
25072580
if( isManifest && g.localOpen ){
25082581
manifest_to_disk(db_lget_int("checkout", 0));
25092582
}
25102583
}else{
25112584
--- src/db.c
+++ src/db.c
@@ -1317,10 +1317,42 @@
1317 "INSERT OR IGNORE INTO user(login,pw,cap,info)"
1318 " VALUES('reader','','kptw','Reader');"
1319 );
1320 }
1321 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1322
1323 /*
1324 ** Return a pointer to a string that contains the RHS of an IN operator
1325 ** that will select CONFIG table names that are in the list of control
1326 ** settings.
@@ -1370,16 +1402,11 @@
1370
1371 db_set("content-schema", CONTENT_SCHEMA, 0);
1372 db_set("aux-schema", AUX_SCHEMA, 0);
1373 db_set("rebuilt", get_version(), 0);
1374 if( makeServerCodes ){
1375 db_multi_exec(
1376 "INSERT INTO config(name,value,mtime)"
1377 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1378 "INSERT INTO config(name,value,mtime)"
1379 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1380 );
1381 }
1382 if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
1383 if( !db_is_global("localauth") ) db_set_int("localauth", 0, 0);
1384 if( !db_is_global("timeline-plaintext") ){
1385 db_set_int("timeline-plaintext", 1, 0);
@@ -1475,23 +1502,25 @@
1475 ** Options:
1476 ** --template FILE copy settings from repository file
1477 ** --admin-user|-A USERNAME select given USERNAME as admin user
1478 ** --date-override DATETIME use DATETIME as time of the initial checkin
1479 ** (default: do not create an initial checkin)
 
1480 **
1481 ** See also: clone
1482 */
1483 void create_repository_cmd(void){
1484 char *zPassword;
1485 const char *zTemplate; /* Repository from which to copy settings */
1486 const char *zDate; /* Date of the initial check-in */
1487 const char *zDefaultUser; /* Optional name of the default user */
 
1488
1489 zTemplate = find_option("template",0,1);
1490 zDate = find_option("date-override",0,1);
1491 zDefaultUser = find_option("admin-user","A",1);
1492 find_option("empty", 0, 0); /* deprecated */
1493
1494 /* We should be done with options.. */
1495 verify_all_options();
1496
1497 if( g.argc!=3 ){
@@ -1500,15 +1529,17 @@
1500 db_create_repository(g.argv[2]);
1501 db_open_repository(g.argv[2]);
1502 db_open_config(0);
1503 if( zTemplate ) db_attach(zTemplate, "settingSrc");
1504 db_begin_transaction();
1505 db_initial_setup(zTemplate, zDate, zDefaultUser, 1);
1506 db_end_transaction(0);
1507 if( zTemplate ) db_detach("settingSrc");
1508 fossil_print("project-id: %s\n", db_get("project-code", 0));
1509 fossil_print("server-id: %s\n", db_get("server-code", 0));
 
 
1510 zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
1511 fossil_print("admin-user: %s (initial password is \"%s\")\n",
1512 g.zLogin, zPassword);
1513 }
1514
@@ -1978,36 +2009,56 @@
1978 ** ckout:%s
1979 **
1980 ** Where %s is the checkout root. The value is the repository file.
1981 */
1982 void db_record_repository_filename(const char *zName){
 
 
 
1983 Blob full;
1984 if( zName==0 ){
1985 if( !g.localOpen ) return;
1986 zName = db_repository_filename();
1987 }
1988 file_canonical_name(zName, &full, 0);
 
1989 db_swap_connections();
 
 
 
 
 
1990 db_multi_exec(
1991 "INSERT OR IGNORE INTO global_config(name,value)"
1992 "VALUES('repo:%q',1)",
1993 blob_str(&full)
1994 );
 
1995 if( g.localOpen && g.zLocalRoot && g.zLocalRoot[0] ){
1996 Blob localRoot;
1997 file_canonical_name(g.zLocalRoot, &localRoot, 1);
 
 
 
 
 
1998 db_multi_exec(
1999 "REPLACE INTO global_config(name, value)"
2000 "VALUES('ckout:%q','%q');",
2001 blob_str(&localRoot), blob_str(&full)
2002 );
2003 db_swap_connections();
 
 
 
 
2004 db_optional_sql("repository",
2005 "REPLACE INTO config(name,value,mtime)"
2006 "VALUES('ckout:%q',1,now())",
2007 blob_str(&localRoot)
2008 );
 
2009 blob_reset(&localRoot);
2010 }else{
2011 db_swap_connections();
2012 }
2013 blob_reset(&full);
@@ -2494,17 +2545,39 @@
2494 }
2495 isManifest = fossil_strcmp(ctrlSettings[i].name, "manifest")==0;
2496 if( isManifest && globalFlag ){
2497 fossil_fatal("cannot set 'manifest' globally");
2498 }
2499 if( unsetFlag ){
2500 db_unset(ctrlSettings[i].name, globalFlag);
2501 }else if( g.argc==4 ){
2502 db_set(ctrlSettings[i].name, g.argv[3], globalFlag);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2503 }else{
2504 isManifest = 0;
2505 print_setting(&ctrlSettings[i], db_open_local(0));
 
 
 
 
 
2506 }
2507 if( isManifest && g.localOpen ){
2508 manifest_to_disk(db_lget_int("checkout", 0));
2509 }
2510 }else{
2511
--- src/db.c
+++ src/db.c
@@ -1317,10 +1317,42 @@
1317 "INSERT OR IGNORE INTO user(login,pw,cap,info)"
1318 " VALUES('reader','','kptw','Reader');"
1319 );
1320 }
1321 }
1322
1323 /*
1324 ** This function sets the server and project codes if they do not already
1325 ** exist. Currently, it should be called only by the db_initial_setup()
1326 ** or cmd_webserver() functions, the latter being used to facilitate more
1327 ** robust integration with "canned image" environments (e.g. Docker).
1328 */
1329 void db_setup_server_and_project_codes(
1330 int optional
1331 ){
1332 if( !optional ){
1333 db_multi_exec(
1334 "INSERT INTO config(name,value,mtime)"
1335 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1336 "INSERT INTO config(name,value,mtime)"
1337 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1338 );
1339 }else{
1340 if( db_get("server-code", 0)==0 ) {
1341 db_optional_sql("repository",
1342 "INSERT INTO config(name,value,mtime)"
1343 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1344 );
1345 }
1346 if( db_get("project-code", 0)==0 ) {
1347 db_optional_sql("repository",
1348 "INSERT INTO config(name,value,mtime)"
1349 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1350 );
1351 }
1352 }
1353 }
1354
1355 /*
1356 ** Return a pointer to a string that contains the RHS of an IN operator
1357 ** that will select CONFIG table names that are in the list of control
1358 ** settings.
@@ -1370,16 +1402,11 @@
1402
1403 db_set("content-schema", CONTENT_SCHEMA, 0);
1404 db_set("aux-schema", AUX_SCHEMA, 0);
1405 db_set("rebuilt", get_version(), 0);
1406 if( makeServerCodes ){
1407 db_setup_server_and_project_codes(0);
 
 
 
 
 
1408 }
1409 if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
1410 if( !db_is_global("localauth") ) db_set_int("localauth", 0, 0);
1411 if( !db_is_global("timeline-plaintext") ){
1412 db_set_int("timeline-plaintext", 1, 0);
@@ -1475,23 +1502,25 @@
1502 ** Options:
1503 ** --template FILE copy settings from repository file
1504 ** --admin-user|-A USERNAME select given USERNAME as admin user
1505 ** --date-override DATETIME use DATETIME as time of the initial checkin
1506 ** (default: do not create an initial checkin)
1507 ** --empty create repository without project-id/server-id
1508 **
1509 ** See also: clone
1510 */
1511 void create_repository_cmd(void){
1512 char *zPassword;
1513 const char *zTemplate; /* Repository from which to copy settings */
1514 const char *zDate; /* Date of the initial check-in */
1515 const char *zDefaultUser; /* Optional name of the default user */
1516 int makeServerCodes;
1517
1518 zTemplate = find_option("template",0,1);
1519 zDate = find_option("date-override",0,1);
1520 zDefaultUser = find_option("admin-user","A",1);
1521 makeServerCodes = find_option("empty", 0, 0)==0;
1522
1523 /* We should be done with options.. */
1524 verify_all_options();
1525
1526 if( g.argc!=3 ){
@@ -1500,15 +1529,17 @@
1529 db_create_repository(g.argv[2]);
1530 db_open_repository(g.argv[2]);
1531 db_open_config(0);
1532 if( zTemplate ) db_attach(zTemplate, "settingSrc");
1533 db_begin_transaction();
1534 db_initial_setup(zTemplate, zDate, zDefaultUser, makeServerCodes);
1535 db_end_transaction(0);
1536 if( zTemplate ) db_detach("settingSrc");
1537 if( makeServerCodes ){
1538 fossil_print("project-id: %s\n", db_get("project-code", 0));
1539 fossil_print("server-id: %s\n", db_get("server-code", 0));
1540 }
1541 zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
1542 fossil_print("admin-user: %s (initial password is \"%s\")\n",
1543 g.zLogin, zPassword);
1544 }
1545
@@ -1978,36 +2009,56 @@
2009 ** ckout:%s
2010 **
2011 ** Where %s is the checkout root. The value is the repository file.
2012 */
2013 void db_record_repository_filename(const char *zName){
2014 const char *zCollation;
2015 char *zRepoSetting;
2016 char *zCkoutSetting;
2017 Blob full;
2018 if( zName==0 ){
2019 if( !g.localOpen ) return;
2020 zName = db_repository_filename();
2021 }
2022 file_canonical_name(zName, &full, 0);
2023 zCollation = filename_collation();
2024 db_swap_connections();
2025 zRepoSetting = mprintf("repo:%q", blob_str(&full));
2026 db_multi_exec(
2027 "DELETE FROM global_config WHERE name %s = '%s';",
2028 zCollation, zRepoSetting
2029 );
2030 db_multi_exec(
2031 "INSERT OR IGNORE INTO global_config(name,value)"
2032 "VALUES('%s',1);",
2033 zRepoSetting
2034 );
2035 fossil_free(zRepoSetting);
2036 if( g.localOpen && g.zLocalRoot && g.zLocalRoot[0] ){
2037 Blob localRoot;
2038 file_canonical_name(g.zLocalRoot, &localRoot, 1);
2039 zCkoutSetting = mprintf("ckout:%q", blob_str(&localRoot));
2040 db_multi_exec(
2041 "DELETE FROM global_config WHERE name %s = '%s';",
2042 zCollation, zCkoutSetting
2043 );
2044 db_multi_exec(
2045 "REPLACE INTO global_config(name, value)"
2046 "VALUES('%s','%q');",
2047 zCkoutSetting, blob_str(&full)
2048 );
2049 db_swap_connections();
2050 db_optional_sql("repository",
2051 "DELETE FROM config WHERE name %s = '%s';",
2052 zCollation, zCkoutSetting
2053 );
2054 db_optional_sql("repository",
2055 "REPLACE INTO config(name,value,mtime)"
2056 "VALUES('%s',1,now());",
2057 zCkoutSetting
2058 );
2059 fossil_free(zCkoutSetting);
2060 blob_reset(&localRoot);
2061 }else{
2062 db_swap_connections();
2063 }
2064 blob_reset(&full);
@@ -2494,17 +2545,39 @@
2545 }
2546 isManifest = fossil_strcmp(ctrlSettings[i].name, "manifest")==0;
2547 if( isManifest && globalFlag ){
2548 fossil_fatal("cannot set 'manifest' globally");
2549 }
2550 if( unsetFlag || g.argc==4 ){
2551 if( ctrlSettings[i+1].name
2552 && strncmp(ctrlSettings[i+1].name, zName, n)==0
2553 && ctrlSettings[i].name[n]!=0
2554 ){
2555 fossil_print("ambiguous property prefix: %s\nMatching properties:\n",
2556 zName);
2557 while( ctrlSettings[i].name
2558 && strncmp(ctrlSettings[i].name, zName, n)==0
2559 ){
2560 fossil_print("%s\n", ctrlSettings[i].name);
2561 i++;
2562 }
2563 fossil_exit(1);
2564 }else{
2565 if( unsetFlag ){
2566 db_unset(ctrlSettings[i].name, globalFlag);
2567 }else{
2568 db_set(ctrlSettings[i].name, g.argv[3], globalFlag);
2569 }
2570 }
2571 }else{
2572 isManifest = 0;
2573 while( ctrlSettings[i].name
2574 && strncmp(ctrlSettings[i].name, zName, n)==0
2575 ){
2576 print_setting(&ctrlSettings[i], db_open_local(0));
2577 i++;
2578 }
2579 }
2580 if( isManifest && g.localOpen ){
2581 manifest_to_disk(db_lget_int("checkout", 0));
2582 }
2583 }else{
2584
--- src/descendants.c
+++ src/descendants.c
@@ -531,11 +531,11 @@
531531
db_step(&ins);
532532
db_reset(&ins);
533533
}
534534
}
535535
db_finalize(&q);
536
- db_prepare(&q, "SELECT cid FROM plink WHERE pid=:rid");
536
+ db_prepare(&q, "SELECT cid FROM plink WHERE pid=:rid AND isprim");
537537
538538
while( (rid = bag_first(&pending))!=0 ){
539539
bag_remove(&pending, rid);
540540
db_bind_int(&q, ":rid", rid);
541541
while( db_step(&q)==SQLITE_ROW ){
542542
--- src/descendants.c
+++ src/descendants.c
@@ -531,11 +531,11 @@
531 db_step(&ins);
532 db_reset(&ins);
533 }
534 }
535 db_finalize(&q);
536 db_prepare(&q, "SELECT cid FROM plink WHERE pid=:rid");
537
538 while( (rid = bag_first(&pending))!=0 ){
539 bag_remove(&pending, rid);
540 db_bind_int(&q, ":rid", rid);
541 while( db_step(&q)==SQLITE_ROW ){
542
--- src/descendants.c
+++ src/descendants.c
@@ -531,11 +531,11 @@
531 db_step(&ins);
532 db_reset(&ins);
533 }
534 }
535 db_finalize(&q);
536 db_prepare(&q, "SELECT cid FROM plink WHERE pid=:rid AND isprim");
537
538 while( (rid = bag_first(&pending))!=0 ){
539 bag_remove(&pending, rid);
540 db_bind_int(&q, ":rid", rid);
541 while( db_step(&q)==SQLITE_ROW ){
542
-1
--- src/file.c
+++ src/file.c
@@ -1102,11 +1102,10 @@
11021102
void cmd_test_tree_name(void){
11031103
int i;
11041104
Blob x;
11051105
db_find_and_open_repository(0,0);
11061106
blob_zero(&x);
1107
- capture_case_sensitive_option();
11081107
for(i=2; i<g.argc; i++){
11091108
if( file_tree_name(g.argv[i], &x, 1) ){
11101109
fossil_print("%s\n", blob_buffer(&x));
11111110
blob_reset(&x);
11121111
}
11131112
--- src/file.c
+++ src/file.c
@@ -1102,11 +1102,10 @@
1102 void cmd_test_tree_name(void){
1103 int i;
1104 Blob x;
1105 db_find_and_open_repository(0,0);
1106 blob_zero(&x);
1107 capture_case_sensitive_option();
1108 for(i=2; i<g.argc; i++){
1109 if( file_tree_name(g.argv[i], &x, 1) ){
1110 fossil_print("%s\n", blob_buffer(&x));
1111 blob_reset(&x);
1112 }
1113
--- src/file.c
+++ src/file.c
@@ -1102,11 +1102,10 @@
1102 void cmd_test_tree_name(void){
1103 int i;
1104 Blob x;
1105 db_find_and_open_repository(0,0);
1106 blob_zero(&x);
 
1107 for(i=2; i<g.argc; i++){
1108 if( file_tree_name(g.argv[i], &x, 1) ){
1109 fossil_print("%s\n", blob_buffer(&x));
1110 blob_reset(&x);
1111 }
1112
+1 -2
--- src/finfo.c
+++ src/finfo.c
@@ -56,11 +56,10 @@
5656
** entry).
5757
**
5858
** See also: artifact, cat, descendants, info, leaves
5959
*/
6060
void finfo_cmd(void){
61
- capture_case_sensitive_option();
6261
db_must_be_within_tree();
6362
if( find_option("status","s",0) ){
6463
Stmt q;
6564
Blob line;
6665
Blob fname;
@@ -431,11 +430,11 @@
431430
}else if( brBg || zBgClr==0 || zBgClr[0]==0 ){
432431
zBgClr = strcmp(zBr,"trunk")==0 ? "" : hash_color(zBr);
433432
}
434433
gidx = graph_add_row(pGraph, frid, fpid>0 ? 1 : 0, &fpid, zBr, zBgClr,
435434
zUuid, 0);
436
- if( memcmp(zDate, zPrevDate, 10) ){
435
+ if( strncmp(zDate, zPrevDate, 10) ){
437436
sqlite3_snprintf(sizeof(zPrevDate), zPrevDate, "%.10s", zDate);
438437
@ <tr><td>
439438
@ <div class="divider">%s(zPrevDate)</div>
440439
@ </td><td></td><td></td></tr>
441440
}
442441
--- src/finfo.c
+++ src/finfo.c
@@ -56,11 +56,10 @@
56 ** entry).
57 **
58 ** See also: artifact, cat, descendants, info, leaves
59 */
60 void finfo_cmd(void){
61 capture_case_sensitive_option();
62 db_must_be_within_tree();
63 if( find_option("status","s",0) ){
64 Stmt q;
65 Blob line;
66 Blob fname;
@@ -431,11 +430,11 @@
431 }else if( brBg || zBgClr==0 || zBgClr[0]==0 ){
432 zBgClr = strcmp(zBr,"trunk")==0 ? "" : hash_color(zBr);
433 }
434 gidx = graph_add_row(pGraph, frid, fpid>0 ? 1 : 0, &fpid, zBr, zBgClr,
435 zUuid, 0);
436 if( memcmp(zDate, zPrevDate, 10) ){
437 sqlite3_snprintf(sizeof(zPrevDate), zPrevDate, "%.10s", zDate);
438 @ <tr><td>
439 @ <div class="divider">%s(zPrevDate)</div>
440 @ </td><td></td><td></td></tr>
441 }
442
--- src/finfo.c
+++ src/finfo.c
@@ -56,11 +56,10 @@
56 ** entry).
57 **
58 ** See also: artifact, cat, descendants, info, leaves
59 */
60 void finfo_cmd(void){
 
61 db_must_be_within_tree();
62 if( find_option("status","s",0) ){
63 Stmt q;
64 Blob line;
65 Blob fname;
@@ -431,11 +430,11 @@
430 }else if( brBg || zBgClr==0 || zBgClr[0]==0 ){
431 zBgClr = strcmp(zBr,"trunk")==0 ? "" : hash_color(zBr);
432 }
433 gidx = graph_add_row(pGraph, frid, fpid>0 ? 1 : 0, &fpid, zBr, zBgClr,
434 zUuid, 0);
435 if( strncmp(zDate, zPrevDate, 10) ){
436 sqlite3_snprintf(sizeof(zPrevDate), zPrevDate, "%.10s", zDate);
437 @ <tr><td>
438 @ <div class="divider">%s(zPrevDate)</div>
439 @ </td><td></td><td></td></tr>
440 }
441
+1 -1
--- src/http.c
+++ src/http.c
@@ -79,11 +79,11 @@
7979
url_prompt_for_password();
8080
zPw = g.url.passwd;
8181
}
8282
8383
/* The login card wants the SHA1 hash of the password, so convert the
84
- ** password to its SHA1 hash it it isn't already a SHA1 hash.
84
+ ** password to its SHA1 hash if it isn't already a SHA1 hash.
8585
*/
8686
/* fossil_print("\nzPw=[%s]\n", zPw); // TESTING ONLY */
8787
if( zPw && zPw[0] ) zPw = sha1_shared_secret(zPw, zLogin, 0);
8888
8989
blob_append(&pw, zPw, -1);
9090
--- src/http.c
+++ src/http.c
@@ -79,11 +79,11 @@
79 url_prompt_for_password();
80 zPw = g.url.passwd;
81 }
82
83 /* The login card wants the SHA1 hash of the password, so convert the
84 ** password to its SHA1 hash it it isn't already a SHA1 hash.
85 */
86 /* fossil_print("\nzPw=[%s]\n", zPw); // TESTING ONLY */
87 if( zPw && zPw[0] ) zPw = sha1_shared_secret(zPw, zLogin, 0);
88
89 blob_append(&pw, zPw, -1);
90
--- src/http.c
+++ src/http.c
@@ -79,11 +79,11 @@
79 url_prompt_for_password();
80 zPw = g.url.passwd;
81 }
82
83 /* The login card wants the SHA1 hash of the password, so convert the
84 ** password to its SHA1 hash if it isn't already a SHA1 hash.
85 */
86 /* fossil_print("\nzPw=[%s]\n", zPw); // TESTING ONLY */
87 if( zPw && zPw[0] ) zPw = sha1_shared_secret(zPw, zLogin, 0);
88
89 blob_append(&pw, zPw, -1);
90
--- src/http_transport.c
+++ src/http_transport.c
@@ -257,12 +257,12 @@
257257
*/
258258
void transport_flip(UrlData *pUrlData){
259259
if( pUrlData->isFile ){
260260
char *zCmd;
261261
fclose(transport.pFile);
262
- zCmd = mprintf("\"%s\" http \"%s\" \"%s\" \"%s\" 127.0.0.1 --localauth",
263
- g.nameOfExe, pUrlData->name, transport.zOutFile, transport.zInFile
262
+ zCmd = mprintf("\"%s\" http \"%s\" \"%s\" 127.0.0.1 \"%s\" --localauth",
263
+ g.nameOfExe, transport.zOutFile, transport.zInFile, pUrlData->name
264264
);
265265
fossil_system(zCmd);
266266
free(zCmd);
267267
transport.pFile = fossil_fopen(transport.zInFile, "rb");
268268
}
269269
--- src/http_transport.c
+++ src/http_transport.c
@@ -257,12 +257,12 @@
257 */
258 void transport_flip(UrlData *pUrlData){
259 if( pUrlData->isFile ){
260 char *zCmd;
261 fclose(transport.pFile);
262 zCmd = mprintf("\"%s\" http \"%s\" \"%s\" \"%s\" 127.0.0.1 --localauth",
263 g.nameOfExe, pUrlData->name, transport.zOutFile, transport.zInFile
264 );
265 fossil_system(zCmd);
266 free(zCmd);
267 transport.pFile = fossil_fopen(transport.zInFile, "rb");
268 }
269
--- src/http_transport.c
+++ src/http_transport.c
@@ -257,12 +257,12 @@
257 */
258 void transport_flip(UrlData *pUrlData){
259 if( pUrlData->isFile ){
260 char *zCmd;
261 fclose(transport.pFile);
262 zCmd = mprintf("\"%s\" http \"%s\" \"%s\" 127.0.0.1 \"%s\" --localauth",
263 g.nameOfExe, transport.zOutFile, transport.zInFile, pUrlData->name
264 );
265 fossil_system(zCmd);
266 free(zCmd);
267 transport.pFile = fossil_fopen(transport.zInFile, "rb");
268 }
269
+24 -24
--- src/import.c
+++ src/import.c
@@ -443,11 +443,11 @@
443443
static ImportFile *import_find_file(const char *zName, int *pI, int mx){
444444
int i = *pI;
445445
int nName = strlen(zName);
446446
while( i<mx ){
447447
const char *z = gg.aFile[i].zName;
448
- if( memcmp(zName, z, nName)==0 && (z[nName]==0 || z[nName]=='/') ){
448
+ if( strncmp(zName, z, nName)==0 && (z[nName]==0 || z[nName]=='/') ){
449449
*pI = i+1;
450450
return &gg.aFile[i];
451451
}
452452
i++;
453453
}
@@ -488,15 +488,15 @@
488488
char zLine[1000];
489489
490490
gg.xFinish = finish_noop;
491491
while( fgets(zLine, sizeof(zLine), pIn) ){
492492
if( zLine[0]=='\n' || zLine[0]=='#' ) continue;
493
- if( memcmp(zLine, "blob", 4)==0 ){
493
+ if( strncmp(zLine, "blob", 4)==0 ){
494494
gg.xFinish();
495495
gg.xFinish = finish_blob;
496496
}else
497
- if( memcmp(zLine, "commit ", 7)==0 ){
497
+ if( strncmp(zLine, "commit ", 7)==0 ){
498498
gg.xFinish();
499499
gg.xFinish = finish_commit;
500500
trim_newline(&zLine[7]);
501501
z = &zLine[7];
502502
@@ -517,41 +517,41 @@
517517
**
518518
** None of the above is explained in the git-fast-export
519519
** documentation. We had to figure it out via trial and error.
520520
*/
521521
for(i=strlen(z)-1; i>=0 && z[i]!='/'; i--){}
522
- gg.tagCommit = memcmp(&z[i-4], "tags", 4)==0; /* True for pattern B */
522
+ gg.tagCommit = strncmp(&z[i-4], "tags", 4)==0; /* True for pattern B */
523523
if( z[i+1]!=0 ) z += i+1;
524524
if( fossil_strcmp(z, "master")==0 ) z = "trunk";
525525
gg.zBranch = fossil_strdup(z);
526526
gg.fromLoaded = 0;
527527
}else
528
- if( memcmp(zLine, "tag ", 4)==0 ){
528
+ if( strncmp(zLine, "tag ", 4)==0 ){
529529
gg.xFinish();
530530
gg.xFinish = finish_tag;
531531
trim_newline(&zLine[4]);
532532
gg.zTag = fossil_strdup(&zLine[4]);
533533
}else
534
- if( memcmp(zLine, "reset ", 4)==0 ){
534
+ if( strncmp(zLine, "reset ", 4)==0 ){
535
+ gg.xFinish();
536
+ }else
537
+ if( strncmp(zLine, "checkpoint", 10)==0 ){
535538
gg.xFinish();
536539
}else
537
- if( memcmp(zLine, "checkpoint", 10)==0 ){
540
+ if( strncmp(zLine, "feature", 7)==0 ){
538541
gg.xFinish();
539542
}else
540
- if( memcmp(zLine, "feature", 7)==0 ){
543
+ if( strncmp(zLine, "option", 6)==0 ){
541544
gg.xFinish();
542545
}else
543
- if( memcmp(zLine, "option", 6)==0 ){
544
- gg.xFinish();
545
- }else
546
- if( memcmp(zLine, "progress ", 9)==0 ){
546
+ if( strncmp(zLine, "progress ", 9)==0 ){
547547
gg.xFinish();
548548
trim_newline(&zLine[9]);
549549
fossil_print("%s\n", &zLine[9]);
550550
fflush(stdout);
551551
}else
552
- if( memcmp(zLine, "data ", 5)==0 ){
552
+ if( strncmp(zLine, "data ", 5)==0 ){
553553
fossil_free(gg.aData); gg.aData = 0;
554554
gg.nData = atoi(&zLine[5]);
555555
if( gg.nData ){
556556
int got;
557557
gg.aData = fossil_malloc( gg.nData+1 );
@@ -565,19 +565,19 @@
565565
gg.aData = 0;
566566
gg.nData = 0;
567567
}
568568
}
569569
}else
570
- if( memcmp(zLine, "author ", 7)==0 ){
570
+ if( strncmp(zLine, "author ", 7)==0 ){
571571
/* No-op */
572572
}else
573
- if( memcmp(zLine, "mark ", 5)==0 ){
573
+ if( strncmp(zLine, "mark ", 5)==0 ){
574574
trim_newline(&zLine[5]);
575575
fossil_free(gg.zMark);
576576
gg.zMark = fossil_strdup(&zLine[5]);
577577
}else
578
- if( memcmp(zLine, "tagger ", 7)==0 || memcmp(zLine, "committer ",10)==0 ){
578
+ if( strncmp(zLine, "tagger ", 7)==0 || strncmp(zLine, "committer ",10)==0 ){
579579
sqlite3_int64 secSince1970;
580580
for(i=0; zLine[i] && zLine[i]!='<'; i++){}
581581
if( zLine[i]==0 ) goto malformed_line;
582582
z = &zLine[i+1];
583583
for(i=i+1; zLine[i] && zLine[i]!='>'; i++){}
@@ -591,27 +591,27 @@
591591
}
592592
fossil_free(gg.zDate);
593593
gg.zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", secSince1970);
594594
gg.zDate[10] = 'T';
595595
}else
596
- if( memcmp(zLine, "from ", 5)==0 ){
596
+ if( strncmp(zLine, "from ", 5)==0 ){
597597
trim_newline(&zLine[5]);
598598
fossil_free(gg.zFromMark);
599599
gg.zFromMark = fossil_strdup(&zLine[5]);
600600
fossil_free(gg.zFrom);
601601
gg.zFrom = resolve_committish(&zLine[5]);
602602
}else
603
- if( memcmp(zLine, "merge ", 6)==0 ){
603
+ if( strncmp(zLine, "merge ", 6)==0 ){
604604
trim_newline(&zLine[6]);
605605
if( gg.nMerge>=gg.nMergeAlloc ){
606606
gg.nMergeAlloc = gg.nMergeAlloc*2 + 10;
607607
gg.azMerge = fossil_realloc(gg.azMerge, gg.nMergeAlloc*sizeof(char*));
608608
}
609609
gg.azMerge[gg.nMerge] = resolve_committish(&zLine[6]);
610610
if( gg.azMerge[gg.nMerge] ) gg.nMerge++;
611611
}else
612
- if( memcmp(zLine, "M ", 2)==0 ){
612
+ if( strncmp(zLine, "M ", 2)==0 ){
613613
import_prior_files();
614614
z = &zLine[2];
615615
zPerm = next_token(&z);
616616
zUuid = next_token(&z);
617617
zName = rest_of_line(&z);
@@ -626,11 +626,11 @@
626626
pFile->isLink = (fossil_strcmp(zPerm, "120000")==0);
627627
fossil_free(pFile->zUuid);
628628
pFile->zUuid = resolve_committish(zUuid);
629629
pFile->isFrom = 0;
630630
}else
631
- if( memcmp(zLine, "D ", 2)==0 ){
631
+ if( strncmp(zLine, "D ", 2)==0 ){
632632
import_prior_files();
633633
z = &zLine[2];
634634
zName = rest_of_line(&z);
635635
dequote_git_filename(zName);
636636
i = 0;
@@ -641,11 +641,11 @@
641641
fossil_free(pFile->zUuid);
642642
*pFile = gg.aFile[--gg.nFile];
643643
i--;
644644
}
645645
}else
646
- if( memcmp(zLine, "C ", 2)==0 ){
646
+ if( strncmp(zLine, "C ", 2)==0 ){
647647
int nFrom;
648648
import_prior_files();
649649
z = &zLine[2];
650650
zFrom = next_token(&z);
651651
zTo = rest_of_line(&z);
@@ -665,11 +665,11 @@
665665
pNew->isLink = pFile->isLink;
666666
pNew->zUuid = fossil_strdup(pFile->zUuid);
667667
pNew->isFrom = 0;
668668
}
669669
}else
670
- if( memcmp(zLine, "R ", 2)==0 ){
670
+ if( strncmp(zLine, "R ", 2)==0 ){
671671
int nFrom;
672672
import_prior_files();
673673
z = &zLine[2];
674674
zFrom = next_token(&z);
675675
zTo = rest_of_line(&z);
@@ -693,14 +693,14 @@
693693
*pFile = *pNew;
694694
memset(pNew, 0, sizeof(*pNew));
695695
}
696696
fossil_fatal("cannot handle R records, use --full-tree");
697697
}else
698
- if( memcmp(zLine, "deleteall", 9)==0 ){
698
+ if( strncmp(zLine, "deleteall", 9)==0 ){
699699
gg.fromLoaded = 1;
700700
}else
701
- if( memcmp(zLine, "N ", 2)==0 ){
701
+ if( strncmp(zLine, "N ", 2)==0 ){
702702
/* No-op */
703703
}else
704704
705705
{
706706
goto malformed_line;
707707
--- src/import.c
+++ src/import.c
@@ -443,11 +443,11 @@
443 static ImportFile *import_find_file(const char *zName, int *pI, int mx){
444 int i = *pI;
445 int nName = strlen(zName);
446 while( i<mx ){
447 const char *z = gg.aFile[i].zName;
448 if( memcmp(zName, z, nName)==0 && (z[nName]==0 || z[nName]=='/') ){
449 *pI = i+1;
450 return &gg.aFile[i];
451 }
452 i++;
453 }
@@ -488,15 +488,15 @@
488 char zLine[1000];
489
490 gg.xFinish = finish_noop;
491 while( fgets(zLine, sizeof(zLine), pIn) ){
492 if( zLine[0]=='\n' || zLine[0]=='#' ) continue;
493 if( memcmp(zLine, "blob", 4)==0 ){
494 gg.xFinish();
495 gg.xFinish = finish_blob;
496 }else
497 if( memcmp(zLine, "commit ", 7)==0 ){
498 gg.xFinish();
499 gg.xFinish = finish_commit;
500 trim_newline(&zLine[7]);
501 z = &zLine[7];
502
@@ -517,41 +517,41 @@
517 **
518 ** None of the above is explained in the git-fast-export
519 ** documentation. We had to figure it out via trial and error.
520 */
521 for(i=strlen(z)-1; i>=0 && z[i]!='/'; i--){}
522 gg.tagCommit = memcmp(&z[i-4], "tags", 4)==0; /* True for pattern B */
523 if( z[i+1]!=0 ) z += i+1;
524 if( fossil_strcmp(z, "master")==0 ) z = "trunk";
525 gg.zBranch = fossil_strdup(z);
526 gg.fromLoaded = 0;
527 }else
528 if( memcmp(zLine, "tag ", 4)==0 ){
529 gg.xFinish();
530 gg.xFinish = finish_tag;
531 trim_newline(&zLine[4]);
532 gg.zTag = fossil_strdup(&zLine[4]);
533 }else
534 if( memcmp(zLine, "reset ", 4)==0 ){
 
 
 
535 gg.xFinish();
536 }else
537 if( memcmp(zLine, "checkpoint", 10)==0 ){
538 gg.xFinish();
539 }else
540 if( memcmp(zLine, "feature", 7)==0 ){
541 gg.xFinish();
542 }else
543 if( memcmp(zLine, "option", 6)==0 ){
544 gg.xFinish();
545 }else
546 if( memcmp(zLine, "progress ", 9)==0 ){
547 gg.xFinish();
548 trim_newline(&zLine[9]);
549 fossil_print("%s\n", &zLine[9]);
550 fflush(stdout);
551 }else
552 if( memcmp(zLine, "data ", 5)==0 ){
553 fossil_free(gg.aData); gg.aData = 0;
554 gg.nData = atoi(&zLine[5]);
555 if( gg.nData ){
556 int got;
557 gg.aData = fossil_malloc( gg.nData+1 );
@@ -565,19 +565,19 @@
565 gg.aData = 0;
566 gg.nData = 0;
567 }
568 }
569 }else
570 if( memcmp(zLine, "author ", 7)==0 ){
571 /* No-op */
572 }else
573 if( memcmp(zLine, "mark ", 5)==0 ){
574 trim_newline(&zLine[5]);
575 fossil_free(gg.zMark);
576 gg.zMark = fossil_strdup(&zLine[5]);
577 }else
578 if( memcmp(zLine, "tagger ", 7)==0 || memcmp(zLine, "committer ",10)==0 ){
579 sqlite3_int64 secSince1970;
580 for(i=0; zLine[i] && zLine[i]!='<'; i++){}
581 if( zLine[i]==0 ) goto malformed_line;
582 z = &zLine[i+1];
583 for(i=i+1; zLine[i] && zLine[i]!='>'; i++){}
@@ -591,27 +591,27 @@
591 }
592 fossil_free(gg.zDate);
593 gg.zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", secSince1970);
594 gg.zDate[10] = 'T';
595 }else
596 if( memcmp(zLine, "from ", 5)==0 ){
597 trim_newline(&zLine[5]);
598 fossil_free(gg.zFromMark);
599 gg.zFromMark = fossil_strdup(&zLine[5]);
600 fossil_free(gg.zFrom);
601 gg.zFrom = resolve_committish(&zLine[5]);
602 }else
603 if( memcmp(zLine, "merge ", 6)==0 ){
604 trim_newline(&zLine[6]);
605 if( gg.nMerge>=gg.nMergeAlloc ){
606 gg.nMergeAlloc = gg.nMergeAlloc*2 + 10;
607 gg.azMerge = fossil_realloc(gg.azMerge, gg.nMergeAlloc*sizeof(char*));
608 }
609 gg.azMerge[gg.nMerge] = resolve_committish(&zLine[6]);
610 if( gg.azMerge[gg.nMerge] ) gg.nMerge++;
611 }else
612 if( memcmp(zLine, "M ", 2)==0 ){
613 import_prior_files();
614 z = &zLine[2];
615 zPerm = next_token(&z);
616 zUuid = next_token(&z);
617 zName = rest_of_line(&z);
@@ -626,11 +626,11 @@
626 pFile->isLink = (fossil_strcmp(zPerm, "120000")==0);
627 fossil_free(pFile->zUuid);
628 pFile->zUuid = resolve_committish(zUuid);
629 pFile->isFrom = 0;
630 }else
631 if( memcmp(zLine, "D ", 2)==0 ){
632 import_prior_files();
633 z = &zLine[2];
634 zName = rest_of_line(&z);
635 dequote_git_filename(zName);
636 i = 0;
@@ -641,11 +641,11 @@
641 fossil_free(pFile->zUuid);
642 *pFile = gg.aFile[--gg.nFile];
643 i--;
644 }
645 }else
646 if( memcmp(zLine, "C ", 2)==0 ){
647 int nFrom;
648 import_prior_files();
649 z = &zLine[2];
650 zFrom = next_token(&z);
651 zTo = rest_of_line(&z);
@@ -665,11 +665,11 @@
665 pNew->isLink = pFile->isLink;
666 pNew->zUuid = fossil_strdup(pFile->zUuid);
667 pNew->isFrom = 0;
668 }
669 }else
670 if( memcmp(zLine, "R ", 2)==0 ){
671 int nFrom;
672 import_prior_files();
673 z = &zLine[2];
674 zFrom = next_token(&z);
675 zTo = rest_of_line(&z);
@@ -693,14 +693,14 @@
693 *pFile = *pNew;
694 memset(pNew, 0, sizeof(*pNew));
695 }
696 fossil_fatal("cannot handle R records, use --full-tree");
697 }else
698 if( memcmp(zLine, "deleteall", 9)==0 ){
699 gg.fromLoaded = 1;
700 }else
701 if( memcmp(zLine, "N ", 2)==0 ){
702 /* No-op */
703 }else
704
705 {
706 goto malformed_line;
707
--- src/import.c
+++ src/import.c
@@ -443,11 +443,11 @@
443 static ImportFile *import_find_file(const char *zName, int *pI, int mx){
444 int i = *pI;
445 int nName = strlen(zName);
446 while( i<mx ){
447 const char *z = gg.aFile[i].zName;
448 if( strncmp(zName, z, nName)==0 && (z[nName]==0 || z[nName]=='/') ){
449 *pI = i+1;
450 return &gg.aFile[i];
451 }
452 i++;
453 }
@@ -488,15 +488,15 @@
488 char zLine[1000];
489
490 gg.xFinish = finish_noop;
491 while( fgets(zLine, sizeof(zLine), pIn) ){
492 if( zLine[0]=='\n' || zLine[0]=='#' ) continue;
493 if( strncmp(zLine, "blob", 4)==0 ){
494 gg.xFinish();
495 gg.xFinish = finish_blob;
496 }else
497 if( strncmp(zLine, "commit ", 7)==0 ){
498 gg.xFinish();
499 gg.xFinish = finish_commit;
500 trim_newline(&zLine[7]);
501 z = &zLine[7];
502
@@ -517,41 +517,41 @@
517 **
518 ** None of the above is explained in the git-fast-export
519 ** documentation. We had to figure it out via trial and error.
520 */
521 for(i=strlen(z)-1; i>=0 && z[i]!='/'; i--){}
522 gg.tagCommit = strncmp(&z[i-4], "tags", 4)==0; /* True for pattern B */
523 if( z[i+1]!=0 ) z += i+1;
524 if( fossil_strcmp(z, "master")==0 ) z = "trunk";
525 gg.zBranch = fossil_strdup(z);
526 gg.fromLoaded = 0;
527 }else
528 if( strncmp(zLine, "tag ", 4)==0 ){
529 gg.xFinish();
530 gg.xFinish = finish_tag;
531 trim_newline(&zLine[4]);
532 gg.zTag = fossil_strdup(&zLine[4]);
533 }else
534 if( strncmp(zLine, "reset ", 4)==0 ){
535 gg.xFinish();
536 }else
537 if( strncmp(zLine, "checkpoint", 10)==0 ){
538 gg.xFinish();
539 }else
540 if( strncmp(zLine, "feature", 7)==0 ){
541 gg.xFinish();
542 }else
543 if( strncmp(zLine, "option", 6)==0 ){
544 gg.xFinish();
545 }else
546 if( strncmp(zLine, "progress ", 9)==0 ){
 
 
 
547 gg.xFinish();
548 trim_newline(&zLine[9]);
549 fossil_print("%s\n", &zLine[9]);
550 fflush(stdout);
551 }else
552 if( strncmp(zLine, "data ", 5)==0 ){
553 fossil_free(gg.aData); gg.aData = 0;
554 gg.nData = atoi(&zLine[5]);
555 if( gg.nData ){
556 int got;
557 gg.aData = fossil_malloc( gg.nData+1 );
@@ -565,19 +565,19 @@
565 gg.aData = 0;
566 gg.nData = 0;
567 }
568 }
569 }else
570 if( strncmp(zLine, "author ", 7)==0 ){
571 /* No-op */
572 }else
573 if( strncmp(zLine, "mark ", 5)==0 ){
574 trim_newline(&zLine[5]);
575 fossil_free(gg.zMark);
576 gg.zMark = fossil_strdup(&zLine[5]);
577 }else
578 if( strncmp(zLine, "tagger ", 7)==0 || strncmp(zLine, "committer ",10)==0 ){
579 sqlite3_int64 secSince1970;
580 for(i=0; zLine[i] && zLine[i]!='<'; i++){}
581 if( zLine[i]==0 ) goto malformed_line;
582 z = &zLine[i+1];
583 for(i=i+1; zLine[i] && zLine[i]!='>'; i++){}
@@ -591,27 +591,27 @@
591 }
592 fossil_free(gg.zDate);
593 gg.zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", secSince1970);
594 gg.zDate[10] = 'T';
595 }else
596 if( strncmp(zLine, "from ", 5)==0 ){
597 trim_newline(&zLine[5]);
598 fossil_free(gg.zFromMark);
599 gg.zFromMark = fossil_strdup(&zLine[5]);
600 fossil_free(gg.zFrom);
601 gg.zFrom = resolve_committish(&zLine[5]);
602 }else
603 if( strncmp(zLine, "merge ", 6)==0 ){
604 trim_newline(&zLine[6]);
605 if( gg.nMerge>=gg.nMergeAlloc ){
606 gg.nMergeAlloc = gg.nMergeAlloc*2 + 10;
607 gg.azMerge = fossil_realloc(gg.azMerge, gg.nMergeAlloc*sizeof(char*));
608 }
609 gg.azMerge[gg.nMerge] = resolve_committish(&zLine[6]);
610 if( gg.azMerge[gg.nMerge] ) gg.nMerge++;
611 }else
612 if( strncmp(zLine, "M ", 2)==0 ){
613 import_prior_files();
614 z = &zLine[2];
615 zPerm = next_token(&z);
616 zUuid = next_token(&z);
617 zName = rest_of_line(&z);
@@ -626,11 +626,11 @@
626 pFile->isLink = (fossil_strcmp(zPerm, "120000")==0);
627 fossil_free(pFile->zUuid);
628 pFile->zUuid = resolve_committish(zUuid);
629 pFile->isFrom = 0;
630 }else
631 if( strncmp(zLine, "D ", 2)==0 ){
632 import_prior_files();
633 z = &zLine[2];
634 zName = rest_of_line(&z);
635 dequote_git_filename(zName);
636 i = 0;
@@ -641,11 +641,11 @@
641 fossil_free(pFile->zUuid);
642 *pFile = gg.aFile[--gg.nFile];
643 i--;
644 }
645 }else
646 if( strncmp(zLine, "C ", 2)==0 ){
647 int nFrom;
648 import_prior_files();
649 z = &zLine[2];
650 zFrom = next_token(&z);
651 zTo = rest_of_line(&z);
@@ -665,11 +665,11 @@
665 pNew->isLink = pFile->isLink;
666 pNew->zUuid = fossil_strdup(pFile->zUuid);
667 pNew->isFrom = 0;
668 }
669 }else
670 if( strncmp(zLine, "R ", 2)==0 ){
671 int nFrom;
672 import_prior_files();
673 z = &zLine[2];
674 zFrom = next_token(&z);
675 zTo = rest_of_line(&z);
@@ -693,14 +693,14 @@
693 *pFile = *pNew;
694 memset(pNew, 0, sizeof(*pNew));
695 }
696 fossil_fatal("cannot handle R records, use --full-tree");
697 }else
698 if( strncmp(zLine, "deleteall", 9)==0 ){
699 gg.fromLoaded = 1;
700 }else
701 if( strncmp(zLine, "N ", 2)==0 ){
702 /* No-op */
703 }else
704
705 {
706 goto malformed_line;
707
+25 -5
--- src/info.c
+++ src/info.c
@@ -203,12 +203,12 @@
203203
/* We should be done with options.. */
204204
verify_all_options();
205205
206206
if( g.argc==3 && (fsize = file_size(g.argv[2]))>0 && (fsize&0x1ff)==0 ){
207207
db_open_config(0);
208
- db_record_repository_filename(g.argv[2]);
209208
db_open_repository(g.argv[2]);
209
+ db_record_repository_filename(g.argv[2]);
210210
fossil_print("project-name: %s\n", db_get("project-name", "<unnamed>"));
211211
fossil_print("project-code: %s\n", db_get("project-code", "<none>"));
212212
extraRepoInfo();
213213
return;
214214
}
@@ -764,12 +764,22 @@
764764
return;
765765
}
766766
if( g.perm.ModWiki && (zModAction = P("modaction"))!=0 ){
767767
if( strcmp(zModAction,"delete")==0 ){
768768
moderation_disapprove(rid);
769
- cgi_redirectf("%R/wiki?name=%T", pWiki->zWikiTitle);
770
- /*NOTREACHED*/
769
+ /*
770
+ ** Next, check if the wiki page still exists; if not, we cannot
771
+ ** redirect to it.
772
+ */
773
+ if( db_exists("SELECT 1 FROM tagxref JOIN tag USING(tagid)"
774
+ " WHERE rid=%d AND tagname LIKE 'wiki-%%'", rid) ){
775
+ cgi_redirectf("%R/wiki?name=%T", pWiki->zWikiTitle);
776
+ /*NOTREACHED*/
777
+ }else{
778
+ cgi_redirectf("%R/modreq");
779
+ /*NOTREACHED*/
780
+ }
771781
}
772782
if( strcmp(zModAction,"approve")==0 ){
773783
moderation_approve(rid);
774784
}
775785
}
@@ -1889,12 +1899,22 @@
18891899
zDate = db_text(0, "SELECT datetime(%.12f)", pTktChng->rDate);
18901900
memcpy(zTktName, pTktChng->zTicketUuid, UUID_SIZE+1);
18911901
if( g.perm.ModTkt && (zModAction = P("modaction"))!=0 ){
18921902
if( strcmp(zModAction,"delete")==0 ){
18931903
moderation_disapprove(rid);
1894
- cgi_redirectf("%R/tktview/%s", zTktName);
1895
- /*NOTREACHED*/
1904
+ /*
1905
+ ** Next, check if the ticket still exists; if not, we cannot
1906
+ ** redirect to it.
1907
+ */
1908
+ if( db_exists("SELECT 1 FROM ticket WHERE tkt_uuid GLOB '%q*'",
1909
+ zTktName) ){
1910
+ cgi_redirectf("%R/tktview/%s", zTktName);
1911
+ /*NOTREACHED*/
1912
+ }else{
1913
+ cgi_redirectf("%R/modreq");
1914
+ /*NOTREACHED*/
1915
+ }
18961916
}
18971917
if( strcmp(zModAction,"approve")==0 ){
18981918
moderation_approve(rid);
18991919
}
19001920
}
19011921
--- src/info.c
+++ src/info.c
@@ -203,12 +203,12 @@
203 /* We should be done with options.. */
204 verify_all_options();
205
206 if( g.argc==3 && (fsize = file_size(g.argv[2]))>0 && (fsize&0x1ff)==0 ){
207 db_open_config(0);
208 db_record_repository_filename(g.argv[2]);
209 db_open_repository(g.argv[2]);
 
210 fossil_print("project-name: %s\n", db_get("project-name", "<unnamed>"));
211 fossil_print("project-code: %s\n", db_get("project-code", "<none>"));
212 extraRepoInfo();
213 return;
214 }
@@ -764,12 +764,22 @@
764 return;
765 }
766 if( g.perm.ModWiki && (zModAction = P("modaction"))!=0 ){
767 if( strcmp(zModAction,"delete")==0 ){
768 moderation_disapprove(rid);
769 cgi_redirectf("%R/wiki?name=%T", pWiki->zWikiTitle);
770 /*NOTREACHED*/
 
 
 
 
 
 
 
 
 
 
771 }
772 if( strcmp(zModAction,"approve")==0 ){
773 moderation_approve(rid);
774 }
775 }
@@ -1889,12 +1899,22 @@
1889 zDate = db_text(0, "SELECT datetime(%.12f)", pTktChng->rDate);
1890 memcpy(zTktName, pTktChng->zTicketUuid, UUID_SIZE+1);
1891 if( g.perm.ModTkt && (zModAction = P("modaction"))!=0 ){
1892 if( strcmp(zModAction,"delete")==0 ){
1893 moderation_disapprove(rid);
1894 cgi_redirectf("%R/tktview/%s", zTktName);
1895 /*NOTREACHED*/
 
 
 
 
 
 
 
 
 
 
1896 }
1897 if( strcmp(zModAction,"approve")==0 ){
1898 moderation_approve(rid);
1899 }
1900 }
1901
--- src/info.c
+++ src/info.c
@@ -203,12 +203,12 @@
203 /* We should be done with options.. */
204 verify_all_options();
205
206 if( g.argc==3 && (fsize = file_size(g.argv[2]))>0 && (fsize&0x1ff)==0 ){
207 db_open_config(0);
 
208 db_open_repository(g.argv[2]);
209 db_record_repository_filename(g.argv[2]);
210 fossil_print("project-name: %s\n", db_get("project-name", "<unnamed>"));
211 fossil_print("project-code: %s\n", db_get("project-code", "<none>"));
212 extraRepoInfo();
213 return;
214 }
@@ -764,12 +764,22 @@
764 return;
765 }
766 if( g.perm.ModWiki && (zModAction = P("modaction"))!=0 ){
767 if( strcmp(zModAction,"delete")==0 ){
768 moderation_disapprove(rid);
769 /*
770 ** Next, check if the wiki page still exists; if not, we cannot
771 ** redirect to it.
772 */
773 if( db_exists("SELECT 1 FROM tagxref JOIN tag USING(tagid)"
774 " WHERE rid=%d AND tagname LIKE 'wiki-%%'", rid) ){
775 cgi_redirectf("%R/wiki?name=%T", pWiki->zWikiTitle);
776 /*NOTREACHED*/
777 }else{
778 cgi_redirectf("%R/modreq");
779 /*NOTREACHED*/
780 }
781 }
782 if( strcmp(zModAction,"approve")==0 ){
783 moderation_approve(rid);
784 }
785 }
@@ -1889,12 +1899,22 @@
1899 zDate = db_text(0, "SELECT datetime(%.12f)", pTktChng->rDate);
1900 memcpy(zTktName, pTktChng->zTicketUuid, UUID_SIZE+1);
1901 if( g.perm.ModTkt && (zModAction = P("modaction"))!=0 ){
1902 if( strcmp(zModAction,"delete")==0 ){
1903 moderation_disapprove(rid);
1904 /*
1905 ** Next, check if the ticket still exists; if not, we cannot
1906 ** redirect to it.
1907 */
1908 if( db_exists("SELECT 1 FROM ticket WHERE tkt_uuid GLOB '%q*'",
1909 zTktName) ){
1910 cgi_redirectf("%R/tktview/%s", zTktName);
1911 /*NOTREACHED*/
1912 }else{
1913 cgi_redirectf("%R/modreq");
1914 /*NOTREACHED*/
1915 }
1916 }
1917 if( strcmp(zModAction,"approve")==0 ){
1918 moderation_approve(rid);
1919 }
1920 }
1921
+1 -1
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -375,11 +375,11 @@
375375
blob_append(&content, cson_string_cstr(jstr),contentLen);
376376
}
377377
378378
zMimeType = json_find_option_cstr("mimetype","mimetype","M");
379379
380
- wiki_cmd_commit(zPageName, 0==rid, &content, zMimeType);
380
+ wiki_cmd_commit(zPageName, 0==rid, &content, zMimeType, 0);
381381
blob_reset(&content);
382382
/*
383383
Our return value here has a race condition: if this operation
384384
is called concurrently for the same wiki page via two requests,
385385
payV could reflect the results of the other save operation.
386386
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -375,11 +375,11 @@
375 blob_append(&content, cson_string_cstr(jstr),contentLen);
376 }
377
378 zMimeType = json_find_option_cstr("mimetype","mimetype","M");
379
380 wiki_cmd_commit(zPageName, 0==rid, &content, zMimeType);
381 blob_reset(&content);
382 /*
383 Our return value here has a race condition: if this operation
384 is called concurrently for the same wiki page via two requests,
385 payV could reflect the results of the other save operation.
386
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -375,11 +375,11 @@
375 blob_append(&content, cson_string_cstr(jstr),contentLen);
376 }
377
378 zMimeType = json_find_option_cstr("mimetype","mimetype","M");
379
380 wiki_cmd_commit(zPageName, 0==rid, &content, zMimeType, 0);
381 blob_reset(&content);
382 /*
383 Our return value here has a race condition: if this operation
384 is called concurrently for the same wiki page via two requests,
385 payV could reflect the results of the other save operation.
386
+29 -21
--- src/main.c
+++ src/main.c
@@ -614,10 +614,11 @@
614614
memset(&g.tcl, 0, sizeof(TclContext));
615615
g.tcl.argc = g.argc;
616616
g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
617617
#endif
618618
g.mainTimerId = fossil_timer_start();
619
+ capture_case_sensitive_option();
619620
g.zVfsName = find_option("vfs",0,1);
620621
if( g.zVfsName==0 ){
621622
g.zVfsName = fossil_getenv("FOSSIL_VFS");
622623
}
623624
if( g.zVfsName ){
@@ -1848,52 +1849,52 @@
18481849
process_one_web_page(zNotFound, pFileGlob);
18491850
}
18501851
}
18511852
18521853
/*
1853
-** If g.argv[2] exists then it is either the name of a repository
1854
+** If g.argv[arg] exists then it is either the name of a repository
18541855
** that will be used by a server, or else it is a directory that
1855
-** contains multiple repositories that can be served. If g.argv[2]
1856
+** contains multiple repositories that can be served. If g.argv[arg]
18561857
** is a directory, the repositories it contains must be named
1857
-** "*.fossil". If g.argv[2] does not exists, then we must be within
1858
+** "*.fossil". If g.argv[arg] does not exists, then we must be within
18581859
** a check-out and the repository to be served is the repository of
18591860
** that check-out.
18601861
**
1861
-** Open the repository to be served if it is known. If g.argv[2] is
1862
+** Open the repository to be served if it is known. If g.argv[arg] is
18621863
** a directory full of repositories, then set g.zRepositoryName to
18631864
** the name of that directory and the specific repository will be
18641865
** opened later by process_one_web_page() based on the content of
18651866
** the PATH_INFO variable.
18661867
**
18671868
** If disallowDir is set, then the directory full of repositories method
18681869
** is disallowed.
18691870
*/
1870
-static void find_server_repository(int disallowDir){
1871
- if( g.argc<3 ){
1871
+static void find_server_repository(int disallowDir, int arg){
1872
+ if( g.argc<=arg ){
18721873
db_must_be_within_tree();
1873
- }else if( file_isdir(g.argv[2])==1 ){
1874
+ }else if( file_isdir(g.argv[arg])==1 ){
18741875
if( disallowDir ){
1875
- fossil_fatal("\"%s\" is a directory, not a repository file", g.argv[2]);
1876
+ fossil_fatal("\"%s\" is a directory, not a repository file", g.argv[arg]);
18761877
}else{
1877
- g.zRepositoryName = mprintf("%s", g.argv[2]);
1878
+ g.zRepositoryName = mprintf("%s", g.argv[arg]);
18781879
file_simplify_name(g.zRepositoryName, -1, 0);
18791880
}
18801881
}else{
1881
- db_open_repository(g.argv[2]);
1882
+ db_open_repository(g.argv[arg]);
18821883
}
18831884
}
18841885
18851886
/*
18861887
** undocumented format:
18871888
**
1888
-** fossil http REPOSITORY INFILE OUTFILE IPADDR
1889
+** fossil http INFILE OUTFILE IPADDR ?REPOSITORY?
18891890
**
18901891
** The argv==6 form is used by the win32 server only.
18911892
**
18921893
** COMMAND: http*
18931894
**
1894
-** Usage: %fossil http REPOSITORY ?OPTIONS?
1895
+** Usage: %fossil http ?REPOSITORY? ?OPTIONS?
18951896
**
18961897
** Handle a single HTTP request appearing on stdin. The resulting webpage
18971898
** is delivered on stdout. This method is used to launch an HTTP request
18981899
** handler from inetd, for example. The argument is the name of the
18991900
** repository.
@@ -1964,30 +1965,31 @@
19641965
g.cgiOutput = 1;
19651966
19661967
/* We should be done with options.. */
19671968
verify_all_options();
19681969
1969
- if( g.argc!=2 && g.argc!=3 && g.argc!=6 ){
1970
+ if( g.argc!=2 && g.argc!=3 && g.argc!=5 && g.argc!=6 ){
19701971
fossil_fatal("no repository specified");
19711972
}
19721973
g.fullHttpReply = 1;
1973
- if( g.argc==6 ){
1974
- g.httpIn = fossil_fopen(g.argv[3], "rb");
1975
- g.httpOut = fossil_fopen(g.argv[4], "wb");
1976
- zIpAddr = g.argv[5];
1974
+ if( g.argc>=5 ){
1975
+ g.httpIn = fossil_fopen(g.argv[2], "rb");
1976
+ g.httpOut = fossil_fopen(g.argv[3], "wb");
1977
+ zIpAddr = g.argv[4];
1978
+ find_server_repository(0, 5);
19771979
}else{
19781980
g.httpIn = stdin;
19791981
g.httpOut = stdout;
19801982
zIpAddr = 0;
1983
+ find_server_repository(0, 2);
19811984
}
19821985
if( zIpAddr==0 ){
19831986
zIpAddr = cgi_ssh_remote_addr(0);
19841987
if( zIpAddr && zIpAddr[0] ){
19851988
g.fSshClient |= CGI_SSH_CLIENT;
19861989
}
19871990
}
1988
- find_server_repository(0);
19891991
g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
19901992
if( useSCGI ){
19911993
cgi_handle_scgi_request();
19921994
}else if( g.fSshClient & CGI_SSH_CLIENT ){
19931995
ssh_request_loop(zIpAddr, glob_create(zFileGlob));
@@ -2023,11 +2025,11 @@
20232025
Th_InitTraceLog();
20242026
login_set_capabilities("sx", 0);
20252027
g.useLocalauth = 1;
20262028
g.httpIn = stdin;
20272029
g.httpOut = stdout;
2028
- find_server_repository(0);
2030
+ find_server_repository(0, 2);
20292031
g.cgiOutput = 1;
20302032
g.fullHttpReply = 1;
20312033
zIpAddr = cgi_ssh_remote_addr(0);
20322034
if( zIpAddr && zIpAddr[0] ){
20332035
g.fSshClient |= CGI_SSH_CLIENT;
@@ -2160,11 +2162,11 @@
21602162
isUiCmd = g.argv[1][0]=='u';
21612163
if( isUiCmd ){
21622164
flags |= HTTP_SERVER_LOCALHOST;
21632165
g.useLocalauth = 1;
21642166
}
2165
- find_server_repository(isUiCmd && zNotFound==0);
2167
+ find_server_repository(isUiCmd && zNotFound==0, 2);
21662168
if( zPort ){
21672169
int i;
21682170
for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
21692171
if( i>0 ){
21702172
zIpAddr = mprintf("%.*s", i, zPort);
@@ -2198,10 +2200,14 @@
21982200
if( zIpAddr ){
21992201
zBrowserCmd = mprintf("%s http://%s:%%d/ &", zBrowser, zIpAddr);
22002202
}else{
22012203
zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
22022204
}
2205
+ if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2206
+ if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2207
+ }else{
2208
+ db_setup_server_and_project_codes(1);
22032209
}
22042210
db_close(1);
22052211
if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
22062212
fossil_fatal("unable to listen on TCP socket %d", iPort);
22072213
}
@@ -2210,11 +2216,11 @@
22102216
g.httpOut = stdout;
22112217
if( g.fHttpTrace || g.fSqlTrace ){
22122218
fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
22132219
}
22142220
g.cgiOutput = 1;
2215
- find_server_repository(isUiCmd && zNotFound==0);
2221
+ find_server_repository(isUiCmd && zNotFound==0, 2);
22162222
g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
22172223
if( flags & HTTP_SERVER_SCGI ){
22182224
cgi_handle_scgi_request();
22192225
}else{
22202226
cgi_handle_http_request(0);
@@ -2227,10 +2233,12 @@
22272233
if( zIpAddr ){
22282234
zBrowserCmd = mprintf("%s http://%s:%%d/ &", zBrowser, zIpAddr);
22292235
}else{
22302236
zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
22312237
}
2238
+ if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2239
+ if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
22322240
}
22332241
db_close(1);
22342242
if( win32_http_service(iPort, zNotFound, zFileGlob, flags) ){
22352243
win32_http_server(iPort, mxPort, zBrowserCmd,
22362244
zStopperFile, zNotFound, zFileGlob, zIpAddr, flags);
22372245
--- src/main.c
+++ src/main.c
@@ -614,10 +614,11 @@
614 memset(&g.tcl, 0, sizeof(TclContext));
615 g.tcl.argc = g.argc;
616 g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
617 #endif
618 g.mainTimerId = fossil_timer_start();
 
619 g.zVfsName = find_option("vfs",0,1);
620 if( g.zVfsName==0 ){
621 g.zVfsName = fossil_getenv("FOSSIL_VFS");
622 }
623 if( g.zVfsName ){
@@ -1848,52 +1849,52 @@
1848 process_one_web_page(zNotFound, pFileGlob);
1849 }
1850 }
1851
1852 /*
1853 ** If g.argv[2] exists then it is either the name of a repository
1854 ** that will be used by a server, or else it is a directory that
1855 ** contains multiple repositories that can be served. If g.argv[2]
1856 ** is a directory, the repositories it contains must be named
1857 ** "*.fossil". If g.argv[2] does not exists, then we must be within
1858 ** a check-out and the repository to be served is the repository of
1859 ** that check-out.
1860 **
1861 ** Open the repository to be served if it is known. If g.argv[2] is
1862 ** a directory full of repositories, then set g.zRepositoryName to
1863 ** the name of that directory and the specific repository will be
1864 ** opened later by process_one_web_page() based on the content of
1865 ** the PATH_INFO variable.
1866 **
1867 ** If disallowDir is set, then the directory full of repositories method
1868 ** is disallowed.
1869 */
1870 static void find_server_repository(int disallowDir){
1871 if( g.argc<3 ){
1872 db_must_be_within_tree();
1873 }else if( file_isdir(g.argv[2])==1 ){
1874 if( disallowDir ){
1875 fossil_fatal("\"%s\" is a directory, not a repository file", g.argv[2]);
1876 }else{
1877 g.zRepositoryName = mprintf("%s", g.argv[2]);
1878 file_simplify_name(g.zRepositoryName, -1, 0);
1879 }
1880 }else{
1881 db_open_repository(g.argv[2]);
1882 }
1883 }
1884
1885 /*
1886 ** undocumented format:
1887 **
1888 ** fossil http REPOSITORY INFILE OUTFILE IPADDR
1889 **
1890 ** The argv==6 form is used by the win32 server only.
1891 **
1892 ** COMMAND: http*
1893 **
1894 ** Usage: %fossil http REPOSITORY ?OPTIONS?
1895 **
1896 ** Handle a single HTTP request appearing on stdin. The resulting webpage
1897 ** is delivered on stdout. This method is used to launch an HTTP request
1898 ** handler from inetd, for example. The argument is the name of the
1899 ** repository.
@@ -1964,30 +1965,31 @@
1964 g.cgiOutput = 1;
1965
1966 /* We should be done with options.. */
1967 verify_all_options();
1968
1969 if( g.argc!=2 && g.argc!=3 && g.argc!=6 ){
1970 fossil_fatal("no repository specified");
1971 }
1972 g.fullHttpReply = 1;
1973 if( g.argc==6 ){
1974 g.httpIn = fossil_fopen(g.argv[3], "rb");
1975 g.httpOut = fossil_fopen(g.argv[4], "wb");
1976 zIpAddr = g.argv[5];
 
1977 }else{
1978 g.httpIn = stdin;
1979 g.httpOut = stdout;
1980 zIpAddr = 0;
 
1981 }
1982 if( zIpAddr==0 ){
1983 zIpAddr = cgi_ssh_remote_addr(0);
1984 if( zIpAddr && zIpAddr[0] ){
1985 g.fSshClient |= CGI_SSH_CLIENT;
1986 }
1987 }
1988 find_server_repository(0);
1989 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
1990 if( useSCGI ){
1991 cgi_handle_scgi_request();
1992 }else if( g.fSshClient & CGI_SSH_CLIENT ){
1993 ssh_request_loop(zIpAddr, glob_create(zFileGlob));
@@ -2023,11 +2025,11 @@
2023 Th_InitTraceLog();
2024 login_set_capabilities("sx", 0);
2025 g.useLocalauth = 1;
2026 g.httpIn = stdin;
2027 g.httpOut = stdout;
2028 find_server_repository(0);
2029 g.cgiOutput = 1;
2030 g.fullHttpReply = 1;
2031 zIpAddr = cgi_ssh_remote_addr(0);
2032 if( zIpAddr && zIpAddr[0] ){
2033 g.fSshClient |= CGI_SSH_CLIENT;
@@ -2160,11 +2162,11 @@
2160 isUiCmd = g.argv[1][0]=='u';
2161 if( isUiCmd ){
2162 flags |= HTTP_SERVER_LOCALHOST;
2163 g.useLocalauth = 1;
2164 }
2165 find_server_repository(isUiCmd && zNotFound==0);
2166 if( zPort ){
2167 int i;
2168 for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
2169 if( i>0 ){
2170 zIpAddr = mprintf("%.*s", i, zPort);
@@ -2198,10 +2200,14 @@
2198 if( zIpAddr ){
2199 zBrowserCmd = mprintf("%s http://%s:%%d/ &", zBrowser, zIpAddr);
2200 }else{
2201 zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
2202 }
 
 
 
 
2203 }
2204 db_close(1);
2205 if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
2206 fossil_fatal("unable to listen on TCP socket %d", iPort);
2207 }
@@ -2210,11 +2216,11 @@
2210 g.httpOut = stdout;
2211 if( g.fHttpTrace || g.fSqlTrace ){
2212 fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
2213 }
2214 g.cgiOutput = 1;
2215 find_server_repository(isUiCmd && zNotFound==0);
2216 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
2217 if( flags & HTTP_SERVER_SCGI ){
2218 cgi_handle_scgi_request();
2219 }else{
2220 cgi_handle_http_request(0);
@@ -2227,10 +2233,12 @@
2227 if( zIpAddr ){
2228 zBrowserCmd = mprintf("%s http://%s:%%d/ &", zBrowser, zIpAddr);
2229 }else{
2230 zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
2231 }
 
 
2232 }
2233 db_close(1);
2234 if( win32_http_service(iPort, zNotFound, zFileGlob, flags) ){
2235 win32_http_server(iPort, mxPort, zBrowserCmd,
2236 zStopperFile, zNotFound, zFileGlob, zIpAddr, flags);
2237
--- src/main.c
+++ src/main.c
@@ -614,10 +614,11 @@
614 memset(&g.tcl, 0, sizeof(TclContext));
615 g.tcl.argc = g.argc;
616 g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
617 #endif
618 g.mainTimerId = fossil_timer_start();
619 capture_case_sensitive_option();
620 g.zVfsName = find_option("vfs",0,1);
621 if( g.zVfsName==0 ){
622 g.zVfsName = fossil_getenv("FOSSIL_VFS");
623 }
624 if( g.zVfsName ){
@@ -1848,52 +1849,52 @@
1849 process_one_web_page(zNotFound, pFileGlob);
1850 }
1851 }
1852
1853 /*
1854 ** If g.argv[arg] exists then it is either the name of a repository
1855 ** that will be used by a server, or else it is a directory that
1856 ** contains multiple repositories that can be served. If g.argv[arg]
1857 ** is a directory, the repositories it contains must be named
1858 ** "*.fossil". If g.argv[arg] does not exists, then we must be within
1859 ** a check-out and the repository to be served is the repository of
1860 ** that check-out.
1861 **
1862 ** Open the repository to be served if it is known. If g.argv[arg] is
1863 ** a directory full of repositories, then set g.zRepositoryName to
1864 ** the name of that directory and the specific repository will be
1865 ** opened later by process_one_web_page() based on the content of
1866 ** the PATH_INFO variable.
1867 **
1868 ** If disallowDir is set, then the directory full of repositories method
1869 ** is disallowed.
1870 */
1871 static void find_server_repository(int disallowDir, int arg){
1872 if( g.argc<=arg ){
1873 db_must_be_within_tree();
1874 }else if( file_isdir(g.argv[arg])==1 ){
1875 if( disallowDir ){
1876 fossil_fatal("\"%s\" is a directory, not a repository file", g.argv[arg]);
1877 }else{
1878 g.zRepositoryName = mprintf("%s", g.argv[arg]);
1879 file_simplify_name(g.zRepositoryName, -1, 0);
1880 }
1881 }else{
1882 db_open_repository(g.argv[arg]);
1883 }
1884 }
1885
1886 /*
1887 ** undocumented format:
1888 **
1889 ** fossil http INFILE OUTFILE IPADDR ?REPOSITORY?
1890 **
1891 ** The argv==6 form is used by the win32 server only.
1892 **
1893 ** COMMAND: http*
1894 **
1895 ** Usage: %fossil http ?REPOSITORY? ?OPTIONS?
1896 **
1897 ** Handle a single HTTP request appearing on stdin. The resulting webpage
1898 ** is delivered on stdout. This method is used to launch an HTTP request
1899 ** handler from inetd, for example. The argument is the name of the
1900 ** repository.
@@ -1964,30 +1965,31 @@
1965 g.cgiOutput = 1;
1966
1967 /* We should be done with options.. */
1968 verify_all_options();
1969
1970 if( g.argc!=2 && g.argc!=3 && g.argc!=5 && g.argc!=6 ){
1971 fossil_fatal("no repository specified");
1972 }
1973 g.fullHttpReply = 1;
1974 if( g.argc>=5 ){
1975 g.httpIn = fossil_fopen(g.argv[2], "rb");
1976 g.httpOut = fossil_fopen(g.argv[3], "wb");
1977 zIpAddr = g.argv[4];
1978 find_server_repository(0, 5);
1979 }else{
1980 g.httpIn = stdin;
1981 g.httpOut = stdout;
1982 zIpAddr = 0;
1983 find_server_repository(0, 2);
1984 }
1985 if( zIpAddr==0 ){
1986 zIpAddr = cgi_ssh_remote_addr(0);
1987 if( zIpAddr && zIpAddr[0] ){
1988 g.fSshClient |= CGI_SSH_CLIENT;
1989 }
1990 }
 
1991 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
1992 if( useSCGI ){
1993 cgi_handle_scgi_request();
1994 }else if( g.fSshClient & CGI_SSH_CLIENT ){
1995 ssh_request_loop(zIpAddr, glob_create(zFileGlob));
@@ -2023,11 +2025,11 @@
2025 Th_InitTraceLog();
2026 login_set_capabilities("sx", 0);
2027 g.useLocalauth = 1;
2028 g.httpIn = stdin;
2029 g.httpOut = stdout;
2030 find_server_repository(0, 2);
2031 g.cgiOutput = 1;
2032 g.fullHttpReply = 1;
2033 zIpAddr = cgi_ssh_remote_addr(0);
2034 if( zIpAddr && zIpAddr[0] ){
2035 g.fSshClient |= CGI_SSH_CLIENT;
@@ -2160,11 +2162,11 @@
2162 isUiCmd = g.argv[1][0]=='u';
2163 if( isUiCmd ){
2164 flags |= HTTP_SERVER_LOCALHOST;
2165 g.useLocalauth = 1;
2166 }
2167 find_server_repository(isUiCmd && zNotFound==0, 2);
2168 if( zPort ){
2169 int i;
2170 for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
2171 if( i>0 ){
2172 zIpAddr = mprintf("%.*s", i, zPort);
@@ -2198,10 +2200,14 @@
2200 if( zIpAddr ){
2201 zBrowserCmd = mprintf("%s http://%s:%%d/ &", zBrowser, zIpAddr);
2202 }else{
2203 zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
2204 }
2205 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2206 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2207 }else{
2208 db_setup_server_and_project_codes(1);
2209 }
2210 db_close(1);
2211 if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
2212 fossil_fatal("unable to listen on TCP socket %d", iPort);
2213 }
@@ -2210,11 +2216,11 @@
2216 g.httpOut = stdout;
2217 if( g.fHttpTrace || g.fSqlTrace ){
2218 fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
2219 }
2220 g.cgiOutput = 1;
2221 find_server_repository(isUiCmd && zNotFound==0, 2);
2222 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
2223 if( flags & HTTP_SERVER_SCGI ){
2224 cgi_handle_scgi_request();
2225 }else{
2226 cgi_handle_http_request(0);
@@ -2227,10 +2233,12 @@
2233 if( zIpAddr ){
2234 zBrowserCmd = mprintf("%s http://%s:%%d/ &", zBrowser, zIpAddr);
2235 }else{
2236 zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
2237 }
2238 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2239 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2240 }
2241 db_close(1);
2242 if( win32_http_service(iPort, zNotFound, zFileGlob, flags) ){
2243 win32_http_server(iPort, mxPort, zBrowserCmd,
2244 zStopperFile, zNotFound, zFileGlob, zIpAddr, flags);
2245
+29 -21
--- src/main.c
+++ src/main.c
@@ -614,10 +614,11 @@
614614
memset(&g.tcl, 0, sizeof(TclContext));
615615
g.tcl.argc = g.argc;
616616
g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
617617
#endif
618618
g.mainTimerId = fossil_timer_start();
619
+ capture_case_sensitive_option();
619620
g.zVfsName = find_option("vfs",0,1);
620621
if( g.zVfsName==0 ){
621622
g.zVfsName = fossil_getenv("FOSSIL_VFS");
622623
}
623624
if( g.zVfsName ){
@@ -1848,52 +1849,52 @@
18481849
process_one_web_page(zNotFound, pFileGlob);
18491850
}
18501851
}
18511852
18521853
/*
1853
-** If g.argv[2] exists then it is either the name of a repository
1854
+** If g.argv[arg] exists then it is either the name of a repository
18541855
** that will be used by a server, or else it is a directory that
1855
-** contains multiple repositories that can be served. If g.argv[2]
1856
+** contains multiple repositories that can be served. If g.argv[arg]
18561857
** is a directory, the repositories it contains must be named
1857
-** "*.fossil". If g.argv[2] does not exists, then we must be within
1858
+** "*.fossil". If g.argv[arg] does not exists, then we must be within
18581859
** a check-out and the repository to be served is the repository of
18591860
** that check-out.
18601861
**
1861
-** Open the repository to be served if it is known. If g.argv[2] is
1862
+** Open the repository to be served if it is known. If g.argv[arg] is
18621863
** a directory full of repositories, then set g.zRepositoryName to
18631864
** the name of that directory and the specific repository will be
18641865
** opened later by process_one_web_page() based on the content of
18651866
** the PATH_INFO variable.
18661867
**
18671868
** If disallowDir is set, then the directory full of repositories method
18681869
** is disallowed.
18691870
*/
1870
-static void find_server_repository(int disallowDir){
1871
- if( g.argc<3 ){
1871
+static void find_server_repository(int disallowDir, int arg){
1872
+ if( g.argc<=arg ){
18721873
db_must_be_within_tree();
1873
- }else if( file_isdir(g.argv[2])==1 ){
1874
+ }else if( file_isdir(g.argv[arg])==1 ){
18741875
if( disallowDir ){
1875
- fossil_fatal("\"%s\" is a directory, not a repository file", g.argv[2]);
1876
+ fossil_fatal("\"%s\" is a directory, not a repository file", g.argv[arg]);
18761877
}else{
1877
- g.zRepositoryName = mprintf("%s", g.argv[2]);
1878
+ g.zRepositoryName = mprintf("%s", g.argv[arg]);
18781879
file_simplify_name(g.zRepositoryName, -1, 0);
18791880
}
18801881
}else{
1881
- db_open_repository(g.argv[2]);
1882
+ db_open_repository(g.argv[arg]);
18821883
}
18831884
}
18841885
18851886
/*
18861887
** undocumented format:
18871888
**
1888
-** fossil http REPOSITORY INFILE OUTFILE IPADDR
1889
+** fossil http INFILE OUTFILE IPADDR ?REPOSITORY?
18891890
**
18901891
** The argv==6 form is used by the win32 server only.
18911892
**
18921893
** COMMAND: http*
18931894
**
1894
-** Usage: %fossil http REPOSITORY ?OPTIONS?
1895
+** Usage: %fossil http ?REPOSITORY? ?OPTIONS?
18951896
**
18961897
** Handle a single HTTP request appearing on stdin. The resulting webpage
18971898
** is delivered on stdout. This method is used to launch an HTTP request
18981899
** handler from inetd, for example. The argument is the name of the
18991900
** repository.
@@ -1964,30 +1965,31 @@
19641965
g.cgiOutput = 1;
19651966
19661967
/* We should be done with options.. */
19671968
verify_all_options();
19681969
1969
- if( g.argc!=2 && g.argc!=3 && g.argc!=6 ){
1970
+ if( g.argc!=2 && g.argc!=3 && g.argc!=5 && g.argc!=6 ){
19701971
fossil_fatal("no repository specified");
19711972
}
19721973
g.fullHttpReply = 1;
1973
- if( g.argc==6 ){
1974
- g.httpIn = fossil_fopen(g.argv[3], "rb");
1975
- g.httpOut = fossil_fopen(g.argv[4], "wb");
1976
- zIpAddr = g.argv[5];
1974
+ if( g.argc>=5 ){
1975
+ g.httpIn = fossil_fopen(g.argv[2], "rb");
1976
+ g.httpOut = fossil_fopen(g.argv[3], "wb");
1977
+ zIpAddr = g.argv[4];
1978
+ find_server_repository(0, 5);
19771979
}else{
19781980
g.httpIn = stdin;
19791981
g.httpOut = stdout;
19801982
zIpAddr = 0;
1983
+ find_server_repository(0, 2);
19811984
}
19821985
if( zIpAddr==0 ){
19831986
zIpAddr = cgi_ssh_remote_addr(0);
19841987
if( zIpAddr && zIpAddr[0] ){
19851988
g.fSshClient |= CGI_SSH_CLIENT;
19861989
}
19871990
}
1988
- find_server_repository(0);
19891991
g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
19901992
if( useSCGI ){
19911993
cgi_handle_scgi_request();
19921994
}else if( g.fSshClient & CGI_SSH_CLIENT ){
19931995
ssh_request_loop(zIpAddr, glob_create(zFileGlob));
@@ -2023,11 +2025,11 @@
20232025
Th_InitTraceLog();
20242026
login_set_capabilities("sx", 0);
20252027
g.useLocalauth = 1;
20262028
g.httpIn = stdin;
20272029
g.httpOut = stdout;
2028
- find_server_repository(0);
2030
+ find_server_repository(0, 2);
20292031
g.cgiOutput = 1;
20302032
g.fullHttpReply = 1;
20312033
zIpAddr = cgi_ssh_remote_addr(0);
20322034
if( zIpAddr && zIpAddr[0] ){
20332035
g.fSshClient |= CGI_SSH_CLIENT;
@@ -2160,11 +2162,11 @@
21602162
isUiCmd = g.argv[1][0]=='u';
21612163
if( isUiCmd ){
21622164
flags |= HTTP_SERVER_LOCALHOST;
21632165
g.useLocalauth = 1;
21642166
}
2165
- find_server_repository(isUiCmd && zNotFound==0);
2167
+ find_server_repository(isUiCmd && zNotFound==0, 2);
21662168
if( zPort ){
21672169
int i;
21682170
for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
21692171
if( i>0 ){
21702172
zIpAddr = mprintf("%.*s", i, zPort);
@@ -2198,10 +2200,14 @@
21982200
if( zIpAddr ){
21992201
zBrowserCmd = mprintf("%s http://%s:%%d/ &", zBrowser, zIpAddr);
22002202
}else{
22012203
zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
22022204
}
2205
+ if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2206
+ if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2207
+ }else{
2208
+ db_setup_server_and_project_codes(1);
22032209
}
22042210
db_close(1);
22052211
if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
22062212
fossil_fatal("unable to listen on TCP socket %d", iPort);
22072213
}
@@ -2210,11 +2216,11 @@
22102216
g.httpOut = stdout;
22112217
if( g.fHttpTrace || g.fSqlTrace ){
22122218
fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
22132219
}
22142220
g.cgiOutput = 1;
2215
- find_server_repository(isUiCmd && zNotFound==0);
2221
+ find_server_repository(isUiCmd && zNotFound==0, 2);
22162222
g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
22172223
if( flags & HTTP_SERVER_SCGI ){
22182224
cgi_handle_scgi_request();
22192225
}else{
22202226
cgi_handle_http_request(0);
@@ -2227,10 +2233,12 @@
22272233
if( zIpAddr ){
22282234
zBrowserCmd = mprintf("%s http://%s:%%d/ &", zBrowser, zIpAddr);
22292235
}else{
22302236
zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
22312237
}
2238
+ if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2239
+ if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
22322240
}
22332241
db_close(1);
22342242
if( win32_http_service(iPort, zNotFound, zFileGlob, flags) ){
22352243
win32_http_server(iPort, mxPort, zBrowserCmd,
22362244
zStopperFile, zNotFound, zFileGlob, zIpAddr, flags);
22372245
--- src/main.c
+++ src/main.c
@@ -614,10 +614,11 @@
614 memset(&g.tcl, 0, sizeof(TclContext));
615 g.tcl.argc = g.argc;
616 g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
617 #endif
618 g.mainTimerId = fossil_timer_start();
 
619 g.zVfsName = find_option("vfs",0,1);
620 if( g.zVfsName==0 ){
621 g.zVfsName = fossil_getenv("FOSSIL_VFS");
622 }
623 if( g.zVfsName ){
@@ -1848,52 +1849,52 @@
1848 process_one_web_page(zNotFound, pFileGlob);
1849 }
1850 }
1851
1852 /*
1853 ** If g.argv[2] exists then it is either the name of a repository
1854 ** that will be used by a server, or else it is a directory that
1855 ** contains multiple repositories that can be served. If g.argv[2]
1856 ** is a directory, the repositories it contains must be named
1857 ** "*.fossil". If g.argv[2] does not exists, then we must be within
1858 ** a check-out and the repository to be served is the repository of
1859 ** that check-out.
1860 **
1861 ** Open the repository to be served if it is known. If g.argv[2] is
1862 ** a directory full of repositories, then set g.zRepositoryName to
1863 ** the name of that directory and the specific repository will be
1864 ** opened later by process_one_web_page() based on the content of
1865 ** the PATH_INFO variable.
1866 **
1867 ** If disallowDir is set, then the directory full of repositories method
1868 ** is disallowed.
1869 */
1870 static void find_server_repository(int disallowDir){
1871 if( g.argc<3 ){
1872 db_must_be_within_tree();
1873 }else if( file_isdir(g.argv[2])==1 ){
1874 if( disallowDir ){
1875 fossil_fatal("\"%s\" is a directory, not a repository file", g.argv[2]);
1876 }else{
1877 g.zRepositoryName = mprintf("%s", g.argv[2]);
1878 file_simplify_name(g.zRepositoryName, -1, 0);
1879 }
1880 }else{
1881 db_open_repository(g.argv[2]);
1882 }
1883 }
1884
1885 /*
1886 ** undocumented format:
1887 **
1888 ** fossil http REPOSITORY INFILE OUTFILE IPADDR
1889 **
1890 ** The argv==6 form is used by the win32 server only.
1891 **
1892 ** COMMAND: http*
1893 **
1894 ** Usage: %fossil http REPOSITORY ?OPTIONS?
1895 **
1896 ** Handle a single HTTP request appearing on stdin. The resulting webpage
1897 ** is delivered on stdout. This method is used to launch an HTTP request
1898 ** handler from inetd, for example. The argument is the name of the
1899 ** repository.
@@ -1964,30 +1965,31 @@
1964 g.cgiOutput = 1;
1965
1966 /* We should be done with options.. */
1967 verify_all_options();
1968
1969 if( g.argc!=2 && g.argc!=3 && g.argc!=6 ){
1970 fossil_fatal("no repository specified");
1971 }
1972 g.fullHttpReply = 1;
1973 if( g.argc==6 ){
1974 g.httpIn = fossil_fopen(g.argv[3], "rb");
1975 g.httpOut = fossil_fopen(g.argv[4], "wb");
1976 zIpAddr = g.argv[5];
 
1977 }else{
1978 g.httpIn = stdin;
1979 g.httpOut = stdout;
1980 zIpAddr = 0;
 
1981 }
1982 if( zIpAddr==0 ){
1983 zIpAddr = cgi_ssh_remote_addr(0);
1984 if( zIpAddr && zIpAddr[0] ){
1985 g.fSshClient |= CGI_SSH_CLIENT;
1986 }
1987 }
1988 find_server_repository(0);
1989 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
1990 if( useSCGI ){
1991 cgi_handle_scgi_request();
1992 }else if( g.fSshClient & CGI_SSH_CLIENT ){
1993 ssh_request_loop(zIpAddr, glob_create(zFileGlob));
@@ -2023,11 +2025,11 @@
2023 Th_InitTraceLog();
2024 login_set_capabilities("sx", 0);
2025 g.useLocalauth = 1;
2026 g.httpIn = stdin;
2027 g.httpOut = stdout;
2028 find_server_repository(0);
2029 g.cgiOutput = 1;
2030 g.fullHttpReply = 1;
2031 zIpAddr = cgi_ssh_remote_addr(0);
2032 if( zIpAddr && zIpAddr[0] ){
2033 g.fSshClient |= CGI_SSH_CLIENT;
@@ -2160,11 +2162,11 @@
2160 isUiCmd = g.argv[1][0]=='u';
2161 if( isUiCmd ){
2162 flags |= HTTP_SERVER_LOCALHOST;
2163 g.useLocalauth = 1;
2164 }
2165 find_server_repository(isUiCmd && zNotFound==0);
2166 if( zPort ){
2167 int i;
2168 for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
2169 if( i>0 ){
2170 zIpAddr = mprintf("%.*s", i, zPort);
@@ -2198,10 +2200,14 @@
2198 if( zIpAddr ){
2199 zBrowserCmd = mprintf("%s http://%s:%%d/ &", zBrowser, zIpAddr);
2200 }else{
2201 zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
2202 }
 
 
 
 
2203 }
2204 db_close(1);
2205 if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
2206 fossil_fatal("unable to listen on TCP socket %d", iPort);
2207 }
@@ -2210,11 +2216,11 @@
2210 g.httpOut = stdout;
2211 if( g.fHttpTrace || g.fSqlTrace ){
2212 fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
2213 }
2214 g.cgiOutput = 1;
2215 find_server_repository(isUiCmd && zNotFound==0);
2216 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
2217 if( flags & HTTP_SERVER_SCGI ){
2218 cgi_handle_scgi_request();
2219 }else{
2220 cgi_handle_http_request(0);
@@ -2227,10 +2233,12 @@
2227 if( zIpAddr ){
2228 zBrowserCmd = mprintf("%s http://%s:%%d/ &", zBrowser, zIpAddr);
2229 }else{
2230 zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
2231 }
 
 
2232 }
2233 db_close(1);
2234 if( win32_http_service(iPort, zNotFound, zFileGlob, flags) ){
2235 win32_http_server(iPort, mxPort, zBrowserCmd,
2236 zStopperFile, zNotFound, zFileGlob, zIpAddr, flags);
2237
--- src/main.c
+++ src/main.c
@@ -614,10 +614,11 @@
614 memset(&g.tcl, 0, sizeof(TclContext));
615 g.tcl.argc = g.argc;
616 g.tcl.argv = copy_args(g.argc, g.argv); /* save full arguments */
617 #endif
618 g.mainTimerId = fossil_timer_start();
619 capture_case_sensitive_option();
620 g.zVfsName = find_option("vfs",0,1);
621 if( g.zVfsName==0 ){
622 g.zVfsName = fossil_getenv("FOSSIL_VFS");
623 }
624 if( g.zVfsName ){
@@ -1848,52 +1849,52 @@
1849 process_one_web_page(zNotFound, pFileGlob);
1850 }
1851 }
1852
1853 /*
1854 ** If g.argv[arg] exists then it is either the name of a repository
1855 ** that will be used by a server, or else it is a directory that
1856 ** contains multiple repositories that can be served. If g.argv[arg]
1857 ** is a directory, the repositories it contains must be named
1858 ** "*.fossil". If g.argv[arg] does not exists, then we must be within
1859 ** a check-out and the repository to be served is the repository of
1860 ** that check-out.
1861 **
1862 ** Open the repository to be served if it is known. If g.argv[arg] is
1863 ** a directory full of repositories, then set g.zRepositoryName to
1864 ** the name of that directory and the specific repository will be
1865 ** opened later by process_one_web_page() based on the content of
1866 ** the PATH_INFO variable.
1867 **
1868 ** If disallowDir is set, then the directory full of repositories method
1869 ** is disallowed.
1870 */
1871 static void find_server_repository(int disallowDir, int arg){
1872 if( g.argc<=arg ){
1873 db_must_be_within_tree();
1874 }else if( file_isdir(g.argv[arg])==1 ){
1875 if( disallowDir ){
1876 fossil_fatal("\"%s\" is a directory, not a repository file", g.argv[arg]);
1877 }else{
1878 g.zRepositoryName = mprintf("%s", g.argv[arg]);
1879 file_simplify_name(g.zRepositoryName, -1, 0);
1880 }
1881 }else{
1882 db_open_repository(g.argv[arg]);
1883 }
1884 }
1885
1886 /*
1887 ** undocumented format:
1888 **
1889 ** fossil http INFILE OUTFILE IPADDR ?REPOSITORY?
1890 **
1891 ** The argv==6 form is used by the win32 server only.
1892 **
1893 ** COMMAND: http*
1894 **
1895 ** Usage: %fossil http ?REPOSITORY? ?OPTIONS?
1896 **
1897 ** Handle a single HTTP request appearing on stdin. The resulting webpage
1898 ** is delivered on stdout. This method is used to launch an HTTP request
1899 ** handler from inetd, for example. The argument is the name of the
1900 ** repository.
@@ -1964,30 +1965,31 @@
1965 g.cgiOutput = 1;
1966
1967 /* We should be done with options.. */
1968 verify_all_options();
1969
1970 if( g.argc!=2 && g.argc!=3 && g.argc!=5 && g.argc!=6 ){
1971 fossil_fatal("no repository specified");
1972 }
1973 g.fullHttpReply = 1;
1974 if( g.argc>=5 ){
1975 g.httpIn = fossil_fopen(g.argv[2], "rb");
1976 g.httpOut = fossil_fopen(g.argv[3], "wb");
1977 zIpAddr = g.argv[4];
1978 find_server_repository(0, 5);
1979 }else{
1980 g.httpIn = stdin;
1981 g.httpOut = stdout;
1982 zIpAddr = 0;
1983 find_server_repository(0, 2);
1984 }
1985 if( zIpAddr==0 ){
1986 zIpAddr = cgi_ssh_remote_addr(0);
1987 if( zIpAddr && zIpAddr[0] ){
1988 g.fSshClient |= CGI_SSH_CLIENT;
1989 }
1990 }
 
1991 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
1992 if( useSCGI ){
1993 cgi_handle_scgi_request();
1994 }else if( g.fSshClient & CGI_SSH_CLIENT ){
1995 ssh_request_loop(zIpAddr, glob_create(zFileGlob));
@@ -2023,11 +2025,11 @@
2025 Th_InitTraceLog();
2026 login_set_capabilities("sx", 0);
2027 g.useLocalauth = 1;
2028 g.httpIn = stdin;
2029 g.httpOut = stdout;
2030 find_server_repository(0, 2);
2031 g.cgiOutput = 1;
2032 g.fullHttpReply = 1;
2033 zIpAddr = cgi_ssh_remote_addr(0);
2034 if( zIpAddr && zIpAddr[0] ){
2035 g.fSshClient |= CGI_SSH_CLIENT;
@@ -2160,11 +2162,11 @@
2162 isUiCmd = g.argv[1][0]=='u';
2163 if( isUiCmd ){
2164 flags |= HTTP_SERVER_LOCALHOST;
2165 g.useLocalauth = 1;
2166 }
2167 find_server_repository(isUiCmd && zNotFound==0, 2);
2168 if( zPort ){
2169 int i;
2170 for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
2171 if( i>0 ){
2172 zIpAddr = mprintf("%.*s", i, zPort);
@@ -2198,10 +2200,14 @@
2200 if( zIpAddr ){
2201 zBrowserCmd = mprintf("%s http://%s:%%d/ &", zBrowser, zIpAddr);
2202 }else{
2203 zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
2204 }
2205 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2206 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2207 }else{
2208 db_setup_server_and_project_codes(1);
2209 }
2210 db_close(1);
2211 if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
2212 fossil_fatal("unable to listen on TCP socket %d", iPort);
2213 }
@@ -2210,11 +2216,11 @@
2216 g.httpOut = stdout;
2217 if( g.fHttpTrace || g.fSqlTrace ){
2218 fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
2219 }
2220 g.cgiOutput = 1;
2221 find_server_repository(isUiCmd && zNotFound==0, 2);
2222 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
2223 if( flags & HTTP_SERVER_SCGI ){
2224 cgi_handle_scgi_request();
2225 }else{
2226 cgi_handle_http_request(0);
@@ -2227,10 +2233,12 @@
2233 if( zIpAddr ){
2234 zBrowserCmd = mprintf("%s http://%s:%%d/ &", zBrowser, zIpAddr);
2235 }else{
2236 zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
2237 }
2238 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2239 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2240 }
2241 db_close(1);
2242 if( win32_http_service(iPort, zNotFound, zFileGlob, flags) ){
2243 win32_http_server(iPort, mxPort, zBrowserCmd,
2244 zStopperFile, zNotFound, zFileGlob, zIpAddr, flags);
2245
+1 -1
--- src/main.mk
+++ src/main.mk
@@ -406,11 +406,11 @@
406406
-DMINIZ_NO_TIME \
407407
-DMINIZ_NO_ARCHIVE_APIS
408408
409409
# The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
410410
# to 1. If it is set to 1, then there is no need to build or link
411
-# the sqlite3.o object. Instead, the system sqlite will be linked
411
+# the sqlite3.o object. Instead, the system SQLite will be linked
412412
# using -lsqlite3.
413413
SQLITE3_OBJ.1 =
414414
SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
415415
SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
416416
417417
--- src/main.mk
+++ src/main.mk
@@ -406,11 +406,11 @@
406 -DMINIZ_NO_TIME \
407 -DMINIZ_NO_ARCHIVE_APIS
408
409 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
410 # to 1. If it is set to 1, then there is no need to build or link
411 # the sqlite3.o object. Instead, the system sqlite will be linked
412 # using -lsqlite3.
413 SQLITE3_OBJ.1 =
414 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
415 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
416
417
--- src/main.mk
+++ src/main.mk
@@ -406,11 +406,11 @@
406 -DMINIZ_NO_TIME \
407 -DMINIZ_NO_ARCHIVE_APIS
408
409 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
410 # to 1. If it is set to 1, then there is no need to build or link
411 # the sqlite3.o object. Instead, the system SQLite will be linked
412 # using -lsqlite3.
413 SQLITE3_OBJ.1 =
414 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
415 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
416
417
--- src/makeheaders.c
+++ src/makeheaders.c
@@ -37,15 +37,16 @@
3737
#include <stdlib.h>
3838
#include <ctype.h>
3939
#include <memory.h>
4040
#include <sys/stat.h>
4141
#include <assert.h>
42
+#include <string.h>
43
+
4244
#if defined( __MINGW32__) || defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
4345
# ifndef WIN32
4446
# define WIN32
4547
# endif
46
-# include <string.h>
4748
#else
4849
# include <unistd.h>
4950
#endif
5051
5152
/*
5253
--- src/makeheaders.c
+++ src/makeheaders.c
@@ -37,15 +37,16 @@
37 #include <stdlib.h>
38 #include <ctype.h>
39 #include <memory.h>
40 #include <sys/stat.h>
41 #include <assert.h>
 
 
42 #if defined( __MINGW32__) || defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
43 # ifndef WIN32
44 # define WIN32
45 # endif
46 # include <string.h>
47 #else
48 # include <unistd.h>
49 #endif
50
51 /*
52
--- src/makeheaders.c
+++ src/makeheaders.c
@@ -37,15 +37,16 @@
37 #include <stdlib.h>
38 #include <ctype.h>
39 #include <memory.h>
40 #include <sys/stat.h>
41 #include <assert.h>
42 #include <string.h>
43
44 #if defined( __MINGW32__) || defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
45 # ifndef WIN32
46 # define WIN32
47 # endif
 
48 #else
49 # include <unistd.h>
50 #endif
51
52 /*
53
+12 -8
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -278,11 +278,11 @@
278278
# Setup the options used to compile the included miniz library.
279279
MINIZ_OPTIONS = <<<MINIZ_OPTIONS>>>
280280
281281
# The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
282282
# to 1. If it is set to 1, then there is no need to build or link
283
-# the sqlite3.o object. Instead, the system sqlite will be linked
283
+# the sqlite3.o object. Instead, the system SQLite will be linked
284284
# using -lsqlite3.
285285
SQLITE3_OBJ.1 =
286286
SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
287287
SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
288288
@@ -465,11 +465,11 @@
465465
466466
#### Load Tcl using the private stubs mechanism
467467
#
468468
# FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
469469
470
-#### Use 'system' sqlite
470
+#### Use 'system' SQLite
471471
#
472472
# USE_SYSTEM_SQLITE = 1
473473
474474
#### Use the miniz compression library
475475
#
@@ -822,11 +822,11 @@
822822
$(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION)
823823
$(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
824824
825825
# The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
826826
# to 1. If it is set to 1, then there is no need to build or link
827
-# the sqlite3.o object. Instead, the system sqlite will be linked
827
+# the sqlite3.o object. Instead, the system SQLite will be linked
828828
# using -lsqlite3.
829829
SQLITE3_OBJ.1 =
830830
SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
831831
SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
832832
@@ -1153,11 +1153,15 @@
11531153
OBJDIR = .
11541154
OX = .
11551155
O = .obj
11561156
E = .exe
11571157
P = .pdb
1158
-PERLDIR =
1158
+
1159
+# Perl is only necessary if OpenSSL support is enabled and it must
1160
+# be built from source code. The PERLDIR variable should point to
1161
+# the directory containing the main Perl binary (i.e. "perl.exe").
1162
+PERLDIR = C:\Perl\bin
11591163
PERL = perl.exe
11601164
11611165
# Uncomment to enable debug symbols
11621166
# DEBUG = 1
11631167
@@ -1179,11 +1183,11 @@
11791183
# Uncomment to enable Tcl support
11801184
# FOSSIL_ENABLE_TCL = 1
11811185
11821186
!ifdef FOSSIL_ENABLE_SSL
11831187
SSLDIR = $(B)\compat\openssl-1.0.1i
1184
-SSLINCDIR = $(SSLDIR)\include
1188
+SSLINCDIR = $(SSLDIR)\inc32
11851189
SSLLIBDIR = $(SSLDIR)\out32
11861190
SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
11871191
!endif
11881192
11891193
!ifdef FOSSIL_ENABLE_TCL
@@ -1338,11 +1342,11 @@
13381342
13391343
!ifdef FOSSIL_ENABLE_SSL
13401344
APPTARGETS = $(APPTARGETS) openssl
13411345
!endif
13421346
1343
-$(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts $(APPTARGETS)
1347
+$(APPNAME) : $(APPTARGETS) translate$E mkindex$E headers $(OBJ) $(OX)\linkopts
13441348
cd $(OX)
13451349
link $(LDFLAGS) /OUT:$@ $(LIBDIR) Wsetargv.obj fossil.res @linkopts
13461350
13471351
$(OX)\linkopts: $B\win\Makefile.msc}
13481352
set redir {>}
@@ -1559,17 +1563,17 @@
15591563
# the automatically generated source files
15601564
UTILS=translate.exe mkindex.exe makeheaders.exe
15611565
UTILS_OBJ=$(UTILS:.exe=.obj)
15621566
UTILS_SRC=$(foreach uf,$(UTILS),$(SRCDIR)$(uf:.exe=.c))
15631567
1564
-# define the sqlite files, which need special flags on compile
1568
+# define the SQLite files, which need special flags on compile
15651569
SQLITESRC=sqlite3.c
15661570
ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
15671571
SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
15681572
SQLITEDEFINES=<<<SQLITE_OPTIONS>>>
15691573
1570
-# define the sqlite shell files, which need special flags on compile
1574
+# define the SQLite shell files, which need special flags on compile
15711575
SQLITESHELLSRC=shell.c
15721576
ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
15731577
SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
15741578
SQLITESHELLDEFINES=<<<SHELL_OPTIONS>>>
15751579
15761580
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -278,11 +278,11 @@
278 # Setup the options used to compile the included miniz library.
279 MINIZ_OPTIONS = <<<MINIZ_OPTIONS>>>
280
281 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
282 # to 1. If it is set to 1, then there is no need to build or link
283 # the sqlite3.o object. Instead, the system sqlite will be linked
284 # using -lsqlite3.
285 SQLITE3_OBJ.1 =
286 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
287 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
288
@@ -465,11 +465,11 @@
465
466 #### Load Tcl using the private stubs mechanism
467 #
468 # FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
469
470 #### Use 'system' sqlite
471 #
472 # USE_SYSTEM_SQLITE = 1
473
474 #### Use the miniz compression library
475 #
@@ -822,11 +822,11 @@
822 $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION)
823 $(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
824
825 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
826 # to 1. If it is set to 1, then there is no need to build or link
827 # the sqlite3.o object. Instead, the system sqlite will be linked
828 # using -lsqlite3.
829 SQLITE3_OBJ.1 =
830 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
831 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
832
@@ -1153,11 +1153,15 @@
1153 OBJDIR = .
1154 OX = .
1155 O = .obj
1156 E = .exe
1157 P = .pdb
1158 PERLDIR =
 
 
 
 
1159 PERL = perl.exe
1160
1161 # Uncomment to enable debug symbols
1162 # DEBUG = 1
1163
@@ -1179,11 +1183,11 @@
1179 # Uncomment to enable Tcl support
1180 # FOSSIL_ENABLE_TCL = 1
1181
1182 !ifdef FOSSIL_ENABLE_SSL
1183 SSLDIR = $(B)\compat\openssl-1.0.1i
1184 SSLINCDIR = $(SSLDIR)\include
1185 SSLLIBDIR = $(SSLDIR)\out32
1186 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
1187 !endif
1188
1189 !ifdef FOSSIL_ENABLE_TCL
@@ -1338,11 +1342,11 @@
1338
1339 !ifdef FOSSIL_ENABLE_SSL
1340 APPTARGETS = $(APPTARGETS) openssl
1341 !endif
1342
1343 $(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts $(APPTARGETS)
1344 cd $(OX)
1345 link $(LDFLAGS) /OUT:$@ $(LIBDIR) Wsetargv.obj fossil.res @linkopts
1346
1347 $(OX)\linkopts: $B\win\Makefile.msc}
1348 set redir {>}
@@ -1559,17 +1563,17 @@
1559 # the automatically generated source files
1560 UTILS=translate.exe mkindex.exe makeheaders.exe
1561 UTILS_OBJ=$(UTILS:.exe=.obj)
1562 UTILS_SRC=$(foreach uf,$(UTILS),$(SRCDIR)$(uf:.exe=.c))
1563
1564 # define the sqlite files, which need special flags on compile
1565 SQLITESRC=sqlite3.c
1566 ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
1567 SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
1568 SQLITEDEFINES=<<<SQLITE_OPTIONS>>>
1569
1570 # define the sqlite shell files, which need special flags on compile
1571 SQLITESHELLSRC=shell.c
1572 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
1573 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
1574 SQLITESHELLDEFINES=<<<SHELL_OPTIONS>>>
1575
1576
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -278,11 +278,11 @@
278 # Setup the options used to compile the included miniz library.
279 MINIZ_OPTIONS = <<<MINIZ_OPTIONS>>>
280
281 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
282 # to 1. If it is set to 1, then there is no need to build or link
283 # the sqlite3.o object. Instead, the system SQLite will be linked
284 # using -lsqlite3.
285 SQLITE3_OBJ.1 =
286 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
287 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
288
@@ -465,11 +465,11 @@
465
466 #### Load Tcl using the private stubs mechanism
467 #
468 # FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
469
470 #### Use 'system' SQLite
471 #
472 # USE_SYSTEM_SQLITE = 1
473
474 #### Use the miniz compression library
475 #
@@ -822,11 +822,11 @@
822 $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION)
823 $(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
824
825 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
826 # to 1. If it is set to 1, then there is no need to build or link
827 # the sqlite3.o object. Instead, the system SQLite will be linked
828 # using -lsqlite3.
829 SQLITE3_OBJ.1 =
830 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
831 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
832
@@ -1153,11 +1153,15 @@
1153 OBJDIR = .
1154 OX = .
1155 O = .obj
1156 E = .exe
1157 P = .pdb
1158
1159 # Perl is only necessary if OpenSSL support is enabled and it must
1160 # be built from source code. The PERLDIR variable should point to
1161 # the directory containing the main Perl binary (i.e. "perl.exe").
1162 PERLDIR = C:\Perl\bin
1163 PERL = perl.exe
1164
1165 # Uncomment to enable debug symbols
1166 # DEBUG = 1
1167
@@ -1179,11 +1183,11 @@
1183 # Uncomment to enable Tcl support
1184 # FOSSIL_ENABLE_TCL = 1
1185
1186 !ifdef FOSSIL_ENABLE_SSL
1187 SSLDIR = $(B)\compat\openssl-1.0.1i
1188 SSLINCDIR = $(SSLDIR)\inc32
1189 SSLLIBDIR = $(SSLDIR)\out32
1190 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
1191 !endif
1192
1193 !ifdef FOSSIL_ENABLE_TCL
@@ -1338,11 +1342,11 @@
1342
1343 !ifdef FOSSIL_ENABLE_SSL
1344 APPTARGETS = $(APPTARGETS) openssl
1345 !endif
1346
1347 $(APPNAME) : $(APPTARGETS) translate$E mkindex$E headers $(OBJ) $(OX)\linkopts
1348 cd $(OX)
1349 link $(LDFLAGS) /OUT:$@ $(LIBDIR) Wsetargv.obj fossil.res @linkopts
1350
1351 $(OX)\linkopts: $B\win\Makefile.msc}
1352 set redir {>}
@@ -1559,17 +1563,17 @@
1563 # the automatically generated source files
1564 UTILS=translate.exe mkindex.exe makeheaders.exe
1565 UTILS_OBJ=$(UTILS:.exe=.obj)
1566 UTILS_SRC=$(foreach uf,$(UTILS),$(SRCDIR)$(uf:.exe=.c))
1567
1568 # define the SQLite files, which need special flags on compile
1569 SQLITESRC=sqlite3.c
1570 ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
1571 SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
1572 SQLITEDEFINES=<<<SQLITE_OPTIONS>>>
1573
1574 # define the SQLite shell files, which need special flags on compile
1575 SQLITESHELLSRC=shell.c
1576 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
1577 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
1578 SQLITESHELLDEFINES=<<<SHELL_OPTIONS>>>
1579
1580
+40 -2
--- src/manifest.c
+++ src/manifest.c
@@ -229,18 +229,18 @@
229229
*/
230230
static void remove_pgp_signature(char **pz, int *pn){
231231
char *z = *pz;
232232
int n = *pn;
233233
int i;
234
- if( memcmp(z, "-----BEGIN PGP SIGNED MESSAGE-----", 34)!=0 ) return;
234
+ if( strncmp(z, "-----BEGIN PGP SIGNED MESSAGE-----", 34)!=0 ) return;
235235
for(i=34; i<n && !after_blank_line(z+i); i++){}
236236
if( i>=n ) return;
237237
z += i;
238238
n -= i;
239239
*pz = z;
240240
for(i=n-1; i>=0; i--){
241
- if( z[i]=='\n' && memcmp(&z[i],"\n-----BEGIN PGP SIGNATURE-", 25)==0 ){
241
+ if( z[i]=='\n' && strncmp(&z[i],"\n-----BEGIN PGP SIGNATURE-", 25)==0 ){
242242
n = i+1;
243243
break;
244244
}
245245
}
246246
*pn = n;
@@ -1641,10 +1641,48 @@
16411641
blob_str(&comment), blob_str(&brief)
16421642
);
16431643
blob_reset(&comment);
16441644
blob_reset(&brief);
16451645
}
1646
+
1647
+/*
1648
+** Add an extra line of text to the end of a manifest to prevent it being
1649
+** recognized as a valid manifest.
1650
+**
1651
+** This routine is called prior to writing out the text of a manifest as
1652
+** the "manifest" file in the root of a repository when
1653
+** "fossil setting manifest on" is enabled. That way, if the files of
1654
+** the project are imported into a different Fossil project, the manifest
1655
+** file will not be interpreted as a control artifact in that other project.
1656
+**
1657
+** Normally it is sufficient to simply append the extra line of text.
1658
+** However, if the manifest is PGP signed then the extra line has to be
1659
+** inserted before the PGP signature (thus invalidating the signature).
1660
+*/
1661
+void sterilize_manifest(Blob *p){
1662
+ char *z, *zOrig;
1663
+ int n, nOrig;
1664
+ static const char zExtraLine[] =
1665
+ "# Remove this line to create a well-formed manifest.\n";
1666
+
1667
+ z = zOrig = blob_materialize(p);
1668
+ n = nOrig = blob_size(p);
1669
+ remove_pgp_signature(&z, &n);
1670
+ if( z==zOrig ){
1671
+ blob_append(p, zExtraLine, -1);
1672
+ }else{
1673
+ int iEnd;
1674
+ Blob copy;
1675
+ memcpy(&copy, p, sizeof(copy));
1676
+ blob_init(p, 0, 0);
1677
+ iEnd = (int)(&z[n] - zOrig);
1678
+ blob_append(p, zOrig, iEnd);
1679
+ blob_append(p, zExtraLine, -1);
1680
+ blob_append(p, &zOrig[iEnd], -1);
1681
+ blob_zero(&copy);
1682
+ }
1683
+}
16461684
16471685
/*
16481686
** This is the comparison function used to sort the tag array.
16491687
*/
16501688
static int tag_compare(const void *a, const void *b){
16511689
--- src/manifest.c
+++ src/manifest.c
@@ -229,18 +229,18 @@
229 */
230 static void remove_pgp_signature(char **pz, int *pn){
231 char *z = *pz;
232 int n = *pn;
233 int i;
234 if( memcmp(z, "-----BEGIN PGP SIGNED MESSAGE-----", 34)!=0 ) return;
235 for(i=34; i<n && !after_blank_line(z+i); i++){}
236 if( i>=n ) return;
237 z += i;
238 n -= i;
239 *pz = z;
240 for(i=n-1; i>=0; i--){
241 if( z[i]=='\n' && memcmp(&z[i],"\n-----BEGIN PGP SIGNATURE-", 25)==0 ){
242 n = i+1;
243 break;
244 }
245 }
246 *pn = n;
@@ -1641,10 +1641,48 @@
1641 blob_str(&comment), blob_str(&brief)
1642 );
1643 blob_reset(&comment);
1644 blob_reset(&brief);
1645 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1646
1647 /*
1648 ** This is the comparison function used to sort the tag array.
1649 */
1650 static int tag_compare(const void *a, const void *b){
1651
--- src/manifest.c
+++ src/manifest.c
@@ -229,18 +229,18 @@
229 */
230 static void remove_pgp_signature(char **pz, int *pn){
231 char *z = *pz;
232 int n = *pn;
233 int i;
234 if( strncmp(z, "-----BEGIN PGP SIGNED MESSAGE-----", 34)!=0 ) return;
235 for(i=34; i<n && !after_blank_line(z+i); i++){}
236 if( i>=n ) return;
237 z += i;
238 n -= i;
239 *pz = z;
240 for(i=n-1; i>=0; i--){
241 if( z[i]=='\n' && strncmp(&z[i],"\n-----BEGIN PGP SIGNATURE-", 25)==0 ){
242 n = i+1;
243 break;
244 }
245 }
246 *pn = n;
@@ -1641,10 +1641,48 @@
1641 blob_str(&comment), blob_str(&brief)
1642 );
1643 blob_reset(&comment);
1644 blob_reset(&brief);
1645 }
1646
1647 /*
1648 ** Add an extra line of text to the end of a manifest to prevent it being
1649 ** recognized as a valid manifest.
1650 **
1651 ** This routine is called prior to writing out the text of a manifest as
1652 ** the "manifest" file in the root of a repository when
1653 ** "fossil setting manifest on" is enabled. That way, if the files of
1654 ** the project are imported into a different Fossil project, the manifest
1655 ** file will not be interpreted as a control artifact in that other project.
1656 **
1657 ** Normally it is sufficient to simply append the extra line of text.
1658 ** However, if the manifest is PGP signed then the extra line has to be
1659 ** inserted before the PGP signature (thus invalidating the signature).
1660 */
1661 void sterilize_manifest(Blob *p){
1662 char *z, *zOrig;
1663 int n, nOrig;
1664 static const char zExtraLine[] =
1665 "# Remove this line to create a well-formed manifest.\n";
1666
1667 z = zOrig = blob_materialize(p);
1668 n = nOrig = blob_size(p);
1669 remove_pgp_signature(&z, &n);
1670 if( z==zOrig ){
1671 blob_append(p, zExtraLine, -1);
1672 }else{
1673 int iEnd;
1674 Blob copy;
1675 memcpy(&copy, p, sizeof(copy));
1676 blob_init(p, 0, 0);
1677 iEnd = (int)(&z[n] - zOrig);
1678 blob_append(p, zOrig, iEnd);
1679 blob_append(p, zExtraLine, -1);
1680 blob_append(p, &zOrig[iEnd], -1);
1681 blob_zero(&copy);
1682 }
1683 }
1684
1685 /*
1686 ** This is the comparison function used to sort the tag array.
1687 */
1688 static int tag_compare(const void *a, const void *b){
1689
--- src/merge.c
+++ src/merge.c
@@ -145,11 +145,10 @@
145145
if( !dryRunFlag ){
146146
dryRunFlag = find_option("nochange",0,0)!=0; /* deprecated */
147147
}
148148
forceFlag = find_option("force","f",0)!=0;
149149
zPivot = find_option("baseline",0,1);
150
- capture_case_sensitive_option();
151150
verify_all_options();
152151
db_must_be_within_tree();
153152
if( zBinGlob==0 ) zBinGlob = db_get("binary-glob",0);
154153
vid = db_lget_int("checkout", 0);
155154
if( vid==0 ){
156155
--- src/merge.c
+++ src/merge.c
@@ -145,11 +145,10 @@
145 if( !dryRunFlag ){
146 dryRunFlag = find_option("nochange",0,0)!=0; /* deprecated */
147 }
148 forceFlag = find_option("force","f",0)!=0;
149 zPivot = find_option("baseline",0,1);
150 capture_case_sensitive_option();
151 verify_all_options();
152 db_must_be_within_tree();
153 if( zBinGlob==0 ) zBinGlob = db_get("binary-glob",0);
154 vid = db_lget_int("checkout", 0);
155 if( vid==0 ){
156
--- src/merge.c
+++ src/merge.c
@@ -145,11 +145,10 @@
145 if( !dryRunFlag ){
146 dryRunFlag = find_option("nochange",0,0)!=0; /* deprecated */
147 }
148 forceFlag = find_option("force","f",0)!=0;
149 zPivot = find_option("baseline",0,1);
 
150 verify_all_options();
151 db_must_be_within_tree();
152 if( zBinGlob==0 ) zBinGlob = db_get("binary-glob",0);
153 vid = db_lget_int("checkout", 0);
154 if( vid==0 ){
155
+2 -2
--- src/moderate.c
+++ src/moderate.c
@@ -26,15 +26,15 @@
2626
** Create a table to represent pending moderation requests, if the
2727
** table does not already exist.
2828
*/
2929
void moderation_table_create(void){
3030
db_multi_exec(
31
- "CREATE TABLE IF NOT EXISTS modreq(\n"
31
+ "CREATE TABLE IF NOT EXISTS %s.modreq(\n"
3232
" objid INTEGER PRIMARY KEY,\n" /* Record pending approval */
3333
" attachRid INT,\n" /* Object attached */
3434
" tktid TEXT\n" /* Associated ticket id */
35
- ");\n"
35
+ ");\n", db_name("repository")
3636
);
3737
}
3838
3939
/*
4040
** Return TRUE if the modreq table exists
4141
--- src/moderate.c
+++ src/moderate.c
@@ -26,15 +26,15 @@
26 ** Create a table to represent pending moderation requests, if the
27 ** table does not already exist.
28 */
29 void moderation_table_create(void){
30 db_multi_exec(
31 "CREATE TABLE IF NOT EXISTS modreq(\n"
32 " objid INTEGER PRIMARY KEY,\n" /* Record pending approval */
33 " attachRid INT,\n" /* Object attached */
34 " tktid TEXT\n" /* Associated ticket id */
35 ");\n"
36 );
37 }
38
39 /*
40 ** Return TRUE if the modreq table exists
41
--- src/moderate.c
+++ src/moderate.c
@@ -26,15 +26,15 @@
26 ** Create a table to represent pending moderation requests, if the
27 ** table does not already exist.
28 */
29 void moderation_table_create(void){
30 db_multi_exec(
31 "CREATE TABLE IF NOT EXISTS %s.modreq(\n"
32 " objid INTEGER PRIMARY KEY,\n" /* Record pending approval */
33 " attachRid INT,\n" /* Object attached */
34 " tktid TEXT\n" /* Associated ticket id */
35 ");\n", db_name("repository")
36 );
37 }
38
39 /*
40 ** Return TRUE if the modreq table exists
41
+68
--- src/shell.c
+++ src/shell.c
@@ -31,10 +31,13 @@
3131
#include <stdlib.h>
3232
#include <string.h>
3333
#include <stdio.h>
3434
#include <assert.h>
3535
#include "sqlite3.h"
36
+#if SQLITE_USER_AUTHENTICATION
37
+# include "sqlite3userauth.h"
38
+#endif
3639
#include <ctype.h>
3740
#include <stdarg.h>
3841
3942
#if !defined(_WIN32) && !defined(WIN32)
4043
# include <signal.h>
@@ -3433,10 +3436,75 @@
34333436
sqlite3_trace(p->db, sql_trace_callback, p->traceOut);
34343437
}
34353438
#endif
34363439
}else
34373440
3441
+#if SQLITE_USER_AUTHENTICATION
3442
+ if( c=='u' && strncmp(azArg[0], "user", n)==0 ){
3443
+ if( nArg<2 ){
3444
+ fprintf(stderr, "Usage: .user SUBCOMMAND ...\n");
3445
+ rc = 1;
3446
+ goto meta_command_exit;
3447
+ }
3448
+ open_db(p, 0);
3449
+ if( strcmp(azArg[1],"login")==0 ){
3450
+ if( nArg!=4 ){
3451
+ fprintf(stderr, "Usage: .user login USER PASSWORD\n");
3452
+ rc = 1;
3453
+ goto meta_command_exit;
3454
+ }
3455
+ rc = sqlite3_user_authenticate(p->db, azArg[2], azArg[3],
3456
+ (int)strlen(azArg[3]));
3457
+ if( rc ){
3458
+ fprintf(stderr, "Authentication failed for user %s\n", azArg[2]);
3459
+ rc = 1;
3460
+ }
3461
+ }else if( strcmp(azArg[1],"add")==0 ){
3462
+ if( nArg!=5 ){
3463
+ fprintf(stderr, "Usage: .user add USER PASSWORD ISADMIN\n");
3464
+ rc = 1;
3465
+ goto meta_command_exit;
3466
+ }
3467
+ rc = sqlite3_user_add(p->db, azArg[2],
3468
+ azArg[3], (int)strlen(azArg[3]),
3469
+ booleanValue(azArg[4]));
3470
+ if( rc ){
3471
+ fprintf(stderr, "User-Add failed: %d\n", rc);
3472
+ rc = 1;
3473
+ }
3474
+ }else if( strcmp(azArg[1],"edit")==0 ){
3475
+ if( nArg!=5 ){
3476
+ fprintf(stderr, "Usage: .user edit USER PASSWORD ISADMIN\n");
3477
+ rc = 1;
3478
+ goto meta_command_exit;
3479
+ }
3480
+ rc = sqlite3_user_change(p->db, azArg[2],
3481
+ azArg[3], (int)strlen(azArg[3]),
3482
+ booleanValue(azArg[4]));
3483
+ if( rc ){
3484
+ fprintf(stderr, "User-Edit failed: %d\n", rc);
3485
+ rc = 1;
3486
+ }
3487
+ }else if( strcmp(azArg[1],"delete")==0 ){
3488
+ if( nArg!=3 ){
3489
+ fprintf(stderr, "Usage: .user delete USER\n");
3490
+ rc = 1;
3491
+ goto meta_command_exit;
3492
+ }
3493
+ rc = sqlite3_user_delete(p->db, azArg[2]);
3494
+ if( rc ){
3495
+ fprintf(stderr, "User-Delete failed: %d\n", rc);
3496
+ rc = 1;
3497
+ }
3498
+ }else{
3499
+ fprintf(stderr, "Usage: .user login|add|edit|delete ...\n");
3500
+ rc = 1;
3501
+ goto meta_command_exit;
3502
+ }
3503
+ }else
3504
+#endif /* SQLITE_USER_AUTHENTICATION */
3505
+
34383506
if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
34393507
fprintf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
34403508
sqlite3_libversion(), sqlite3_sourceid());
34413509
}else
34423510
34433511
--- src/shell.c
+++ src/shell.c
@@ -31,10 +31,13 @@
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdio.h>
34 #include <assert.h>
35 #include "sqlite3.h"
 
 
 
36 #include <ctype.h>
37 #include <stdarg.h>
38
39 #if !defined(_WIN32) && !defined(WIN32)
40 # include <signal.h>
@@ -3433,10 +3436,75 @@
3433 sqlite3_trace(p->db, sql_trace_callback, p->traceOut);
3434 }
3435 #endif
3436 }else
3437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3438 if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
3439 fprintf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
3440 sqlite3_libversion(), sqlite3_sourceid());
3441 }else
3442
3443
--- src/shell.c
+++ src/shell.c
@@ -31,10 +31,13 @@
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdio.h>
34 #include <assert.h>
35 #include "sqlite3.h"
36 #if SQLITE_USER_AUTHENTICATION
37 # include "sqlite3userauth.h"
38 #endif
39 #include <ctype.h>
40 #include <stdarg.h>
41
42 #if !defined(_WIN32) && !defined(WIN32)
43 # include <signal.h>
@@ -3433,10 +3436,75 @@
3436 sqlite3_trace(p->db, sql_trace_callback, p->traceOut);
3437 }
3438 #endif
3439 }else
3440
3441 #if SQLITE_USER_AUTHENTICATION
3442 if( c=='u' && strncmp(azArg[0], "user", n)==0 ){
3443 if( nArg<2 ){
3444 fprintf(stderr, "Usage: .user SUBCOMMAND ...\n");
3445 rc = 1;
3446 goto meta_command_exit;
3447 }
3448 open_db(p, 0);
3449 if( strcmp(azArg[1],"login")==0 ){
3450 if( nArg!=4 ){
3451 fprintf(stderr, "Usage: .user login USER PASSWORD\n");
3452 rc = 1;
3453 goto meta_command_exit;
3454 }
3455 rc = sqlite3_user_authenticate(p->db, azArg[2], azArg[3],
3456 (int)strlen(azArg[3]));
3457 if( rc ){
3458 fprintf(stderr, "Authentication failed for user %s\n", azArg[2]);
3459 rc = 1;
3460 }
3461 }else if( strcmp(azArg[1],"add")==0 ){
3462 if( nArg!=5 ){
3463 fprintf(stderr, "Usage: .user add USER PASSWORD ISADMIN\n");
3464 rc = 1;
3465 goto meta_command_exit;
3466 }
3467 rc = sqlite3_user_add(p->db, azArg[2],
3468 azArg[3], (int)strlen(azArg[3]),
3469 booleanValue(azArg[4]));
3470 if( rc ){
3471 fprintf(stderr, "User-Add failed: %d\n", rc);
3472 rc = 1;
3473 }
3474 }else if( strcmp(azArg[1],"edit")==0 ){
3475 if( nArg!=5 ){
3476 fprintf(stderr, "Usage: .user edit USER PASSWORD ISADMIN\n");
3477 rc = 1;
3478 goto meta_command_exit;
3479 }
3480 rc = sqlite3_user_change(p->db, azArg[2],
3481 azArg[3], (int)strlen(azArg[3]),
3482 booleanValue(azArg[4]));
3483 if( rc ){
3484 fprintf(stderr, "User-Edit failed: %d\n", rc);
3485 rc = 1;
3486 }
3487 }else if( strcmp(azArg[1],"delete")==0 ){
3488 if( nArg!=3 ){
3489 fprintf(stderr, "Usage: .user delete USER\n");
3490 rc = 1;
3491 goto meta_command_exit;
3492 }
3493 rc = sqlite3_user_delete(p->db, azArg[2]);
3494 if( rc ){
3495 fprintf(stderr, "User-Delete failed: %d\n", rc);
3496 rc = 1;
3497 }
3498 }else{
3499 fprintf(stderr, "Usage: .user login|add|edit|delete ...\n");
3500 rc = 1;
3501 goto meta_command_exit;
3502 }
3503 }else
3504 #endif /* SQLITE_USER_AUTHENTICATION */
3505
3506 if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
3507 fprintf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
3508 sqlite3_libversion(), sqlite3_sourceid());
3509 }else
3510
3511
+134 -46
--- src/shun.c
+++ src/shun.c
@@ -40,12 +40,17 @@
4040
*/
4141
void shun_page(void){
4242
Stmt q;
4343
int cnt = 0;
4444
const char *zUuid = P("uuid");
45
+ const char *zShun = P("shun");
46
+ const char *zAccept = P("accept");
47
+ const char *zRcvid = P("rcvid");
48
+ int nRcvid;
4549
int nUuid;
46
- char zCanonical[UUID_SIZE+1];
50
+ int numRows = 3;
51
+ char *zCanonical = 0;
4752
4853
login_check_credentials();
4954
if( !g.perm.Admin ){
5055
login_needed();
5156
}
@@ -55,71 +60,117 @@
5560
db_begin_transaction();
5661
rebuild_db(0, 0, 0);
5762
db_end_transaction(0);
5863
}
5964
if( zUuid ){
60
- nUuid = strlen(zUuid);
61
- if( nUuid!=40 || !validate16(zUuid, nUuid) ){
62
- zUuid = 0;
63
- }else{
64
- memcpy(zCanonical, zUuid, UUID_SIZE+1);
65
- canonical16(zCanonical, UUID_SIZE);
66
- zUuid = zCanonical;
67
- }
65
+ char *p;
66
+ int i = 0;
67
+ int j = 0;
68
+ zCanonical = fossil_malloc(strlen(zUuid)+2);
69
+ while( zUuid[i] ){
70
+ if( fossil_isspace(zUuid[i]) ){
71
+ if( j && zCanonical[j-1] ){
72
+ zCanonical[j] = 0;
73
+ j++;
74
+ }
75
+ }else{
76
+ zCanonical[j] = zUuid[i];
77
+ j++;
78
+ }
79
+ i++;
80
+ }
81
+ zCanonical[j+1] = zCanonical[j] = 0;
82
+ p = zCanonical;
83
+ while( *p ){
84
+ nUuid = strlen(p);
85
+ if( nUuid!=UUID_SIZE || !validate16(p, nUuid) ){
86
+ @ <p class="generalError">Error: Bad artifact IDs.</p>
87
+ fossil_free(zCanonical);
88
+ zCanonical = 0;
89
+ break;
90
+ }else{
91
+ canonical16(p, UUID_SIZE);
92
+ p += UUID_SIZE+1;
93
+ }
94
+ }
95
+ zUuid = zCanonical;
6896
}
6997
style_header("Shunned Artifacts");
7098
if( zUuid && P("sub") ){
99
+ const char *p = zUuid;
100
+ int allExist = 1;
71101
login_verify_csrf_secret();
72
- db_multi_exec("DELETE FROM shun WHERE uuid='%s'", zUuid);
73
- if( db_exists("SELECT 1 FROM blob WHERE uuid='%s'", zUuid) ){
74
- @ <p class="noMoreShun">Artifact
75
- @ <a href="%s(g.zTop)/artifact/%s(zUuid)">%s(zUuid)</a> is no
76
- @ longer being shunned.</p>
102
+ while( *p ){
103
+ db_multi_exec("DELETE FROM shun WHERE uuid='%s'", p);
104
+ if( !db_exists("SELECT 1 FROM blob WHERE uuid='%s'", p) ){
105
+ allExist = 0;
106
+ }
107
+ p += UUID_SIZE+1;
108
+ }
109
+ if( allExist ){
110
+ @ <p class="noMoreShun">Artifact(s)<br />
111
+ for( p = zUuid ; *p ; p += UUID_SIZE+1 ){
112
+ @ <a href="%s(g.zTop)/artifact/%s(p)">%s(p)</a><br />
113
+ }
114
+ @ are no longer being shunned.</p>
77115
}else{
78
- @ <p class="noMoreShun">Artifact %s(zUuid) will no longer
79
- @ be shunned. But it does not exist in the repository. It
80
- @ may be necessary to rebuild the repository using the
116
+ @ <p class="noMoreShun">Artifact(s)<br />
117
+ for( p = zUuid ; *p ; p += UUID_SIZE+1 ){
118
+ @ %s(p)<br />
119
+ }
120
+ @ will no longer be shunned. But they may not exist in the repository.
121
+ @ It may be necessary to rebuild the repository using the
81122
@ <b>fossil rebuild</b> command-line before the artifact content
82123
@ can pulled in from other repositories.</p>
83124
}
84125
}
85126
if( zUuid && P("add") ){
127
+ const char *p = zUuid;
86128
int rid, tagid;
87129
login_verify_csrf_secret();
88
- db_multi_exec(
89
- "INSERT OR IGNORE INTO shun(uuid,mtime)"
90
- " VALUES('%s', now())", zUuid);
91
- @ <p class="shunned">Artifact
92
- @ <a href="%s(g.zTop)/artifact/%s(zUuid)">%s(zUuid)</a> has been
93
- @ shunned. It will no longer be pushed.
94
- @ It will be removed from the repository the next time the repository
95
- @ is rebuilt using the <b>fossil rebuild</b> command-line</p>
96
- db_multi_exec("DELETE FROM attachment WHERE src=%Q", zUuid);
97
- rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", zUuid);
98
- if( rid ){
99
- db_multi_exec("DELETE FROM event WHERE objid=%d", rid);
100
- }
101
- tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='tkt-%q'", zUuid);
102
- if( tagid ){
103
- db_multi_exec("DELETE FROM ticket WHERE tkt_uuid=%Q", zUuid);
104
- db_multi_exec("DELETE FROM tag WHERE tagid=%d", tagid);
105
- db_multi_exec("DELETE FROM tagxref WHERE tagid=%d", tagid);
106
- }
130
+ while( *p ){
131
+ db_multi_exec(
132
+ "INSERT OR IGNORE INTO shun(uuid,mtime)"
133
+ " VALUES('%s', now())", p);
134
+ db_multi_exec("DELETE FROM attachment WHERE src=%Q", p);
135
+ rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", p);
136
+ if( rid ){
137
+ db_multi_exec("DELETE FROM event WHERE objid=%d", rid);
138
+ }
139
+ tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='tkt-%q'", p);
140
+ if( tagid ){
141
+ db_multi_exec("DELETE FROM ticket WHERE tkt_uuid=%Q", p);
142
+ db_multi_exec("DELETE FROM tag WHERE tagid=%d", tagid);
143
+ db_multi_exec("DELETE FROM tagxref WHERE tagid=%d", tagid);
144
+ }
145
+ p += UUID_SIZE+1;
146
+ }
147
+ @ <p class="shunned">Artifact(s)<br />
148
+ for( p = zUuid ; *p ; p += UUID_SIZE+1 ){
149
+ @ <a href="%s(g.zTop)/artifact/%s(p)">%s(p)</a><br />
150
+ }
151
+ @ have been shunned. They will no longer be pushed.
152
+ @ They will be removed from the repository the next time the repository
153
+ @ is rebuilt using the <b>fossil rebuild</b> command-line</p>
154
+ }
155
+ if( zRcvid ){
156
+ nRcvid = atoi(zRcvid);
157
+ numRows = db_int(0, "SELECT min(count(), 10) FROM blob WHERE rcvid=%d", nRcvid);
107158
}
108159
@ <p>A shunned artifact will not be pushed nor accepted in a pull and the
109160
@ artifact content will be purged from the repository the next time the
110161
@ repository is rebuilt. A list of shunned artifacts can be seen at the
111162
@ bottom of this page.</p>
112163
@
113164
@ <a name="addshun"></a>
114
- @ <p>To shun an artifact, enter its artifact ID (the 40-character SHA1
115
- @ hash of the artifact) in the
116
- @ following box and press the "Shun" button. This will cause the artifact
117
- @ to be removed from the repository and will prevent the artifact from being
165
+ @ <p>To shun artifacts, enter their artifact IDs (the 40-character SHA1
166
+ @ hash of the artifacts) in the
167
+ @ following box and press the "Shun" button. This will cause the artifacts
168
+ @ to be removed from the repository and will prevent the artifacts from being
118169
@ readded to the repository by subsequent sync operation.</p>
119170
@
120
- @ <p>Note that you must enter the full 40-character artifact ID, not
171
+ @ <p>Note that you must enter the full 40-character artifact IDs, not
121172
@ an abbreviation or a symbolic tag.</p>
122173
@
123174
@ <p>Warning: Shunning should only be used to remove inappropriate content
124175
@ from the repository. Inappropriate content includes such things as
125176
@ spam added to Wiki, files that violate copyright or patent agreements,
@@ -128,26 +179,50 @@
128179
@ sight - set the "hidden" tag on such artifacts instead.</p>
129180
@
130181
@ <blockquote>
131182
@ <form method="post" action="%s(g.zTop)/%s(g.zPath)"><div>
132183
login_insert_csrf_secret();
133
- @ <input type="text" name="uuid" value="%h(PD("shun",""))" size="50" />
184
+ @ <textarea class="fullsize-text" cols="50" rows="%d(numRows)" name="uuid">
185
+ if( zShun ){
186
+ if( strlen(zShun) ){
187
+ @ %h(zShun)
188
+ }else if( zRcvid ){
189
+ db_prepare(&q, "SELECT uuid FROM blob WHERE rcvid=%d", nRcvid);
190
+ while( db_step(&q)==SQLITE_ROW ){
191
+ @ %s(db_column_text(&q, 0))
192
+ }
193
+ db_finalize(&q);
194
+ }
195
+ }
196
+ @ </textarea>
134197
@ <input type="submit" name="add" value="Shun" />
135198
@ </div></form>
136199
@ </blockquote>
137200
@
138201
@ <a name="delshun"></a>
139
- @ <p>Enter the UUID of a previous shunned artifact to cause it to be
140
- @ accepted again in the repository. The artifact content is not
202
+ @ <p>Enter the UUIDs of previously shunned artifacts to cause them to be
203
+ @ accepted again in the repository. The artifacts content is not
141204
@ restored because the content is unknown. The only change is that
142
- @ the formerly shunned artifact will be accepted on subsequent sync
205
+ @ the formerly shunned artifacts will be accepted on subsequent sync
143206
@ operations.</p>
144207
@
145208
@ <blockquote>
146209
@ <form method="post" action="%s(g.zTop)/%s(g.zPath)"><div>
147210
login_insert_csrf_secret();
148
- @ <input type="text" name="uuid" value="%h(PD("accept", ""))" size="50" />
211
+ @ <textarea class="fullsize-text" cols="50" rows="%d(numRows)" name="uuid">
212
+ if( zAccept ){
213
+ if( strlen(zAccept) ){
214
+ @ %h(zAccept)
215
+ }else if( zRcvid ){
216
+ db_prepare(&q, "SELECT uuid FROM blob WHERE rcvid=%d", nRcvid);
217
+ while( db_step(&q)==SQLITE_ROW ){
218
+ @ %s(db_column_text(&q, 0))
219
+ }
220
+ db_finalize(&q);
221
+ }
222
+ }
223
+ @ </textarea>
149224
@ <input type="submit" name="sub" value="Accept" />
150225
@ </div></form>
151226
@ </blockquote>
152227
@
153228
@ <p>Press the Rebuild button below to rebuild the repository. The
@@ -181,10 +256,11 @@
181256
@ <i>no artifacts are shunned on this server</i>
182257
}
183258
db_finalize(&q);
184259
@ </p></blockquote>
185260
style_footer();
261
+ fossil_free(zCanonical);
186262
}
187263
188264
/*
189265
** Remove from the BLOB table all artifacts that are in the SHUN table.
190266
*/
@@ -287,10 +363,22 @@
287363
login_check_credentials();
288364
if( !g.perm.Admin ){
289365
login_needed();
290366
}
291367
style_header("Content Source %d", rcvid);
368
+ if( db_exists(
369
+ "SELECT 1 FROM blob WHERE rcvid=%d AND"
370
+ " NOT EXISTS (SELECT 1 FROM shun WHERE shun.uuid=blob.uuid)", rcvid)
371
+ ){
372
+ style_submenu_element("Shun All", "Shun All", "shun?shun&rcvid=%d#addshun", rcvid);
373
+ }
374
+ if( db_exists(
375
+ "SELECT 1 FROM blob WHERE rcvid=%d AND"
376
+ " EXISTS (SELECT 1 FROM shun WHERE shun.uuid=blob.uuid)", rcvid)
377
+ ){
378
+ style_submenu_element("Unshun All", "Unshun All", "shun?accept&rcvid=%d#delshun", rcvid);
379
+ }
292380
db_prepare(&q,
293381
"SELECT login, datetime(rcvfrom.mtime), rcvfrom.ipaddr"
294382
" FROM rcvfrom LEFT JOIN user USING(uid)"
295383
" WHERE rcvid=%d",
296384
rcvid
297385
--- src/shun.c
+++ src/shun.c
@@ -40,12 +40,17 @@
40 */
41 void shun_page(void){
42 Stmt q;
43 int cnt = 0;
44 const char *zUuid = P("uuid");
 
 
 
 
45 int nUuid;
46 char zCanonical[UUID_SIZE+1];
 
47
48 login_check_credentials();
49 if( !g.perm.Admin ){
50 login_needed();
51 }
@@ -55,71 +60,117 @@
55 db_begin_transaction();
56 rebuild_db(0, 0, 0);
57 db_end_transaction(0);
58 }
59 if( zUuid ){
60 nUuid = strlen(zUuid);
61 if( nUuid!=40 || !validate16(zUuid, nUuid) ){
62 zUuid = 0;
63 }else{
64 memcpy(zCanonical, zUuid, UUID_SIZE+1);
65 canonical16(zCanonical, UUID_SIZE);
66 zUuid = zCanonical;
67 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68 }
69 style_header("Shunned Artifacts");
70 if( zUuid && P("sub") ){
 
 
71 login_verify_csrf_secret();
72 db_multi_exec("DELETE FROM shun WHERE uuid='%s'", zUuid);
73 if( db_exists("SELECT 1 FROM blob WHERE uuid='%s'", zUuid) ){
74 @ <p class="noMoreShun">Artifact
75 @ <a href="%s(g.zTop)/artifact/%s(zUuid)">%s(zUuid)</a> is no
76 @ longer being shunned.</p>
 
 
 
 
 
 
 
 
77 }else{
78 @ <p class="noMoreShun">Artifact %s(zUuid) will no longer
79 @ be shunned. But it does not exist in the repository. It
80 @ may be necessary to rebuild the repository using the
 
 
 
81 @ <b>fossil rebuild</b> command-line before the artifact content
82 @ can pulled in from other repositories.</p>
83 }
84 }
85 if( zUuid && P("add") ){
 
86 int rid, tagid;
87 login_verify_csrf_secret();
88 db_multi_exec(
89 "INSERT OR IGNORE INTO shun(uuid,mtime)"
90 " VALUES('%s', now())", zUuid);
91 @ <p class="shunned">Artifact
92 @ <a href="%s(g.zTop)/artifact/%s(zUuid)">%s(zUuid)</a> has been
93 @ shunned. It will no longer be pushed.
94 @ It will be removed from the repository the next time the repository
95 @ is rebuilt using the <b>fossil rebuild</b> command-line</p>
96 db_multi_exec("DELETE FROM attachment WHERE src=%Q", zUuid);
97 rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", zUuid);
98 if( rid ){
99 db_multi_exec("DELETE FROM event WHERE objid=%d", rid);
100 }
101 tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='tkt-%q'", zUuid);
102 if( tagid ){
103 db_multi_exec("DELETE FROM ticket WHERE tkt_uuid=%Q", zUuid);
104 db_multi_exec("DELETE FROM tag WHERE tagid=%d", tagid);
105 db_multi_exec("DELETE FROM tagxref WHERE tagid=%d", tagid);
106 }
 
 
 
 
 
 
 
 
 
107 }
108 @ <p>A shunned artifact will not be pushed nor accepted in a pull and the
109 @ artifact content will be purged from the repository the next time the
110 @ repository is rebuilt. A list of shunned artifacts can be seen at the
111 @ bottom of this page.</p>
112 @
113 @ <a name="addshun"></a>
114 @ <p>To shun an artifact, enter its artifact ID (the 40-character SHA1
115 @ hash of the artifact) in the
116 @ following box and press the "Shun" button. This will cause the artifact
117 @ to be removed from the repository and will prevent the artifact from being
118 @ readded to the repository by subsequent sync operation.</p>
119 @
120 @ <p>Note that you must enter the full 40-character artifact ID, not
121 @ an abbreviation or a symbolic tag.</p>
122 @
123 @ <p>Warning: Shunning should only be used to remove inappropriate content
124 @ from the repository. Inappropriate content includes such things as
125 @ spam added to Wiki, files that violate copyright or patent agreements,
@@ -128,26 +179,50 @@
128 @ sight - set the "hidden" tag on such artifacts instead.</p>
129 @
130 @ <blockquote>
131 @ <form method="post" action="%s(g.zTop)/%s(g.zPath)"><div>
132 login_insert_csrf_secret();
133 @ <input type="text" name="uuid" value="%h(PD("shun",""))" size="50" />
 
 
 
 
 
 
 
 
 
 
 
 
134 @ <input type="submit" name="add" value="Shun" />
135 @ </div></form>
136 @ </blockquote>
137 @
138 @ <a name="delshun"></a>
139 @ <p>Enter the UUID of a previous shunned artifact to cause it to be
140 @ accepted again in the repository. The artifact content is not
141 @ restored because the content is unknown. The only change is that
142 @ the formerly shunned artifact will be accepted on subsequent sync
143 @ operations.</p>
144 @
145 @ <blockquote>
146 @ <form method="post" action="%s(g.zTop)/%s(g.zPath)"><div>
147 login_insert_csrf_secret();
148 @ <input type="text" name="uuid" value="%h(PD("accept", ""))" size="50" />
 
 
 
 
 
 
 
 
 
 
 
 
149 @ <input type="submit" name="sub" value="Accept" />
150 @ </div></form>
151 @ </blockquote>
152 @
153 @ <p>Press the Rebuild button below to rebuild the repository. The
@@ -181,10 +256,11 @@
181 @ <i>no artifacts are shunned on this server</i>
182 }
183 db_finalize(&q);
184 @ </p></blockquote>
185 style_footer();
 
186 }
187
188 /*
189 ** Remove from the BLOB table all artifacts that are in the SHUN table.
190 */
@@ -287,10 +363,22 @@
287 login_check_credentials();
288 if( !g.perm.Admin ){
289 login_needed();
290 }
291 style_header("Content Source %d", rcvid);
 
 
 
 
 
 
 
 
 
 
 
 
292 db_prepare(&q,
293 "SELECT login, datetime(rcvfrom.mtime), rcvfrom.ipaddr"
294 " FROM rcvfrom LEFT JOIN user USING(uid)"
295 " WHERE rcvid=%d",
296 rcvid
297
--- src/shun.c
+++ src/shun.c
@@ -40,12 +40,17 @@
40 */
41 void shun_page(void){
42 Stmt q;
43 int cnt = 0;
44 const char *zUuid = P("uuid");
45 const char *zShun = P("shun");
46 const char *zAccept = P("accept");
47 const char *zRcvid = P("rcvid");
48 int nRcvid;
49 int nUuid;
50 int numRows = 3;
51 char *zCanonical = 0;
52
53 login_check_credentials();
54 if( !g.perm.Admin ){
55 login_needed();
56 }
@@ -55,71 +60,117 @@
60 db_begin_transaction();
61 rebuild_db(0, 0, 0);
62 db_end_transaction(0);
63 }
64 if( zUuid ){
65 char *p;
66 int i = 0;
67 int j = 0;
68 zCanonical = fossil_malloc(strlen(zUuid)+2);
69 while( zUuid[i] ){
70 if( fossil_isspace(zUuid[i]) ){
71 if( j && zCanonical[j-1] ){
72 zCanonical[j] = 0;
73 j++;
74 }
75 }else{
76 zCanonical[j] = zUuid[i];
77 j++;
78 }
79 i++;
80 }
81 zCanonical[j+1] = zCanonical[j] = 0;
82 p = zCanonical;
83 while( *p ){
84 nUuid = strlen(p);
85 if( nUuid!=UUID_SIZE || !validate16(p, nUuid) ){
86 @ <p class="generalError">Error: Bad artifact IDs.</p>
87 fossil_free(zCanonical);
88 zCanonical = 0;
89 break;
90 }else{
91 canonical16(p, UUID_SIZE);
92 p += UUID_SIZE+1;
93 }
94 }
95 zUuid = zCanonical;
96 }
97 style_header("Shunned Artifacts");
98 if( zUuid && P("sub") ){
99 const char *p = zUuid;
100 int allExist = 1;
101 login_verify_csrf_secret();
102 while( *p ){
103 db_multi_exec("DELETE FROM shun WHERE uuid='%s'", p);
104 if( !db_exists("SELECT 1 FROM blob WHERE uuid='%s'", p) ){
105 allExist = 0;
106 }
107 p += UUID_SIZE+1;
108 }
109 if( allExist ){
110 @ <p class="noMoreShun">Artifact(s)<br />
111 for( p = zUuid ; *p ; p += UUID_SIZE+1 ){
112 @ <a href="%s(g.zTop)/artifact/%s(p)">%s(p)</a><br />
113 }
114 @ are no longer being shunned.</p>
115 }else{
116 @ <p class="noMoreShun">Artifact(s)<br />
117 for( p = zUuid ; *p ; p += UUID_SIZE+1 ){
118 @ %s(p)<br />
119 }
120 @ will no longer be shunned. But they may not exist in the repository.
121 @ It may be necessary to rebuild the repository using the
122 @ <b>fossil rebuild</b> command-line before the artifact content
123 @ can pulled in from other repositories.</p>
124 }
125 }
126 if( zUuid && P("add") ){
127 const char *p = zUuid;
128 int rid, tagid;
129 login_verify_csrf_secret();
130 while( *p ){
131 db_multi_exec(
132 "INSERT OR IGNORE INTO shun(uuid,mtime)"
133 " VALUES('%s', now())", p);
134 db_multi_exec("DELETE FROM attachment WHERE src=%Q", p);
135 rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", p);
136 if( rid ){
137 db_multi_exec("DELETE FROM event WHERE objid=%d", rid);
138 }
139 tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='tkt-%q'", p);
140 if( tagid ){
141 db_multi_exec("DELETE FROM ticket WHERE tkt_uuid=%Q", p);
142 db_multi_exec("DELETE FROM tag WHERE tagid=%d", tagid);
143 db_multi_exec("DELETE FROM tagxref WHERE tagid=%d", tagid);
144 }
145 p += UUID_SIZE+1;
146 }
147 @ <p class="shunned">Artifact(s)<br />
148 for( p = zUuid ; *p ; p += UUID_SIZE+1 ){
149 @ <a href="%s(g.zTop)/artifact/%s(p)">%s(p)</a><br />
150 }
151 @ have been shunned. They will no longer be pushed.
152 @ They will be removed from the repository the next time the repository
153 @ is rebuilt using the <b>fossil rebuild</b> command-line</p>
154 }
155 if( zRcvid ){
156 nRcvid = atoi(zRcvid);
157 numRows = db_int(0, "SELECT min(count(), 10) FROM blob WHERE rcvid=%d", nRcvid);
158 }
159 @ <p>A shunned artifact will not be pushed nor accepted in a pull and the
160 @ artifact content will be purged from the repository the next time the
161 @ repository is rebuilt. A list of shunned artifacts can be seen at the
162 @ bottom of this page.</p>
163 @
164 @ <a name="addshun"></a>
165 @ <p>To shun artifacts, enter their artifact IDs (the 40-character SHA1
166 @ hash of the artifacts) in the
167 @ following box and press the "Shun" button. This will cause the artifacts
168 @ to be removed from the repository and will prevent the artifacts from being
169 @ readded to the repository by subsequent sync operation.</p>
170 @
171 @ <p>Note that you must enter the full 40-character artifact IDs, not
172 @ an abbreviation or a symbolic tag.</p>
173 @
174 @ <p>Warning: Shunning should only be used to remove inappropriate content
175 @ from the repository. Inappropriate content includes such things as
176 @ spam added to Wiki, files that violate copyright or patent agreements,
@@ -128,26 +179,50 @@
179 @ sight - set the "hidden" tag on such artifacts instead.</p>
180 @
181 @ <blockquote>
182 @ <form method="post" action="%s(g.zTop)/%s(g.zPath)"><div>
183 login_insert_csrf_secret();
184 @ <textarea class="fullsize-text" cols="50" rows="%d(numRows)" name="uuid">
185 if( zShun ){
186 if( strlen(zShun) ){
187 @ %h(zShun)
188 }else if( zRcvid ){
189 db_prepare(&q, "SELECT uuid FROM blob WHERE rcvid=%d", nRcvid);
190 while( db_step(&q)==SQLITE_ROW ){
191 @ %s(db_column_text(&q, 0))
192 }
193 db_finalize(&q);
194 }
195 }
196 @ </textarea>
197 @ <input type="submit" name="add" value="Shun" />
198 @ </div></form>
199 @ </blockquote>
200 @
201 @ <a name="delshun"></a>
202 @ <p>Enter the UUIDs of previously shunned artifacts to cause them to be
203 @ accepted again in the repository. The artifacts content is not
204 @ restored because the content is unknown. The only change is that
205 @ the formerly shunned artifacts will be accepted on subsequent sync
206 @ operations.</p>
207 @
208 @ <blockquote>
209 @ <form method="post" action="%s(g.zTop)/%s(g.zPath)"><div>
210 login_insert_csrf_secret();
211 @ <textarea class="fullsize-text" cols="50" rows="%d(numRows)" name="uuid">
212 if( zAccept ){
213 if( strlen(zAccept) ){
214 @ %h(zAccept)
215 }else if( zRcvid ){
216 db_prepare(&q, "SELECT uuid FROM blob WHERE rcvid=%d", nRcvid);
217 while( db_step(&q)==SQLITE_ROW ){
218 @ %s(db_column_text(&q, 0))
219 }
220 db_finalize(&q);
221 }
222 }
223 @ </textarea>
224 @ <input type="submit" name="sub" value="Accept" />
225 @ </div></form>
226 @ </blockquote>
227 @
228 @ <p>Press the Rebuild button below to rebuild the repository. The
@@ -181,10 +256,11 @@
256 @ <i>no artifacts are shunned on this server</i>
257 }
258 db_finalize(&q);
259 @ </p></blockquote>
260 style_footer();
261 fossil_free(zCanonical);
262 }
263
264 /*
265 ** Remove from the BLOB table all artifacts that are in the SHUN table.
266 */
@@ -287,10 +363,22 @@
363 login_check_credentials();
364 if( !g.perm.Admin ){
365 login_needed();
366 }
367 style_header("Content Source %d", rcvid);
368 if( db_exists(
369 "SELECT 1 FROM blob WHERE rcvid=%d AND"
370 " NOT EXISTS (SELECT 1 FROM shun WHERE shun.uuid=blob.uuid)", rcvid)
371 ){
372 style_submenu_element("Shun All", "Shun All", "shun?shun&rcvid=%d#addshun", rcvid);
373 }
374 if( db_exists(
375 "SELECT 1 FROM blob WHERE rcvid=%d AND"
376 " EXISTS (SELECT 1 FROM shun WHERE shun.uuid=blob.uuid)", rcvid)
377 ){
378 style_submenu_element("Unshun All", "Unshun All", "shun?accept&rcvid=%d#delshun", rcvid);
379 }
380 db_prepare(&q,
381 "SELECT login, datetime(rcvfrom.mtime), rcvfrom.ipaddr"
382 " FROM rcvfrom LEFT JOIN user USING(uid)"
383 " WHERE rcvid=%d",
384 rcvid
385
+5 -1
--- src/skins.c
+++ src/skins.c
@@ -770,11 +770,11 @@
770770
@ padding: 3px 10px 3px 10px;
771771
@ color: white;
772772
@ text-decoration: none;
773773
@ }
774774
@ div.submenu a, div.submenu a:visited, a.button,
775
-@ div.sectionmenu>a.button:link, div.sectinmenu>a.button:visited {
775
+@ div.sectionmenu>a.button:link, div.sectionmenu>a.button:visited {
776776
@ padding: 2px 8px;
777777
@ color: #000;
778778
@ font-family: Arial;
779779
@ text-decoration: none;
780780
@ margin:auto;
@@ -874,10 +874,14 @@
874874
@ cursor: pointer;
875875
@ }
876876
@
877877
@ textarea {
878878
@ font-size: 1em;
879
+@ }
880
+@
881
+@ .fullsize-text {
882
+@ font-size: 1.25em;
879883
@ }');
880884
@ REPLACE INTO config(name,mtime,value) VALUES('header',now(),'<html>
881885
@ <head>
882886
@ <base href="$baseurl/$current_page" />
883887
@ <title>$<project_name>: $<title></title>
884888
--- src/skins.c
+++ src/skins.c
@@ -770,11 +770,11 @@
770 @ padding: 3px 10px 3px 10px;
771 @ color: white;
772 @ text-decoration: none;
773 @ }
774 @ div.submenu a, div.submenu a:visited, a.button,
775 @ div.sectionmenu>a.button:link, div.sectinmenu>a.button:visited {
776 @ padding: 2px 8px;
777 @ color: #000;
778 @ font-family: Arial;
779 @ text-decoration: none;
780 @ margin:auto;
@@ -874,10 +874,14 @@
874 @ cursor: pointer;
875 @ }
876 @
877 @ textarea {
878 @ font-size: 1em;
 
 
 
 
879 @ }');
880 @ REPLACE INTO config(name,mtime,value) VALUES('header',now(),'<html>
881 @ <head>
882 @ <base href="$baseurl/$current_page" />
883 @ <title>$<project_name>: $<title></title>
884
--- src/skins.c
+++ src/skins.c
@@ -770,11 +770,11 @@
770 @ padding: 3px 10px 3px 10px;
771 @ color: white;
772 @ text-decoration: none;
773 @ }
774 @ div.submenu a, div.submenu a:visited, a.button,
775 @ div.sectionmenu>a.button:link, div.sectionmenu>a.button:visited {
776 @ padding: 2px 8px;
777 @ color: #000;
778 @ font-family: Arial;
779 @ text-decoration: none;
780 @ margin:auto;
@@ -874,10 +874,14 @@
874 @ cursor: pointer;
875 @ }
876 @
877 @ textarea {
878 @ font-size: 1em;
879 @ }
880 @
881 @ .fullsize-text {
882 @ font-size: 1.25em;
883 @ }');
884 @ REPLACE INTO config(name,mtime,value) VALUES('header',now(),'<html>
885 @ <head>
886 @ <base href="$baseurl/$current_page" />
887 @ <title>$<project_name>: $<title></title>
888
+1157 -709
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -73,10 +73,19 @@
7373
# define _FILE_OFFSET_BITS 64
7474
# endif
7575
# define _LARGEFILE_SOURCE 1
7676
#endif
7777
78
+/* Needed for various definitions... */
79
+#if defined(__GNUC__) && !defined(_GNU_SOURCE)
80
+# define _GNU_SOURCE
81
+#endif
82
+
83
+#if defined(__OpenBSD__) && !defined(_BSD_SOURCE)
84
+# define _BSD_SOURCE
85
+#endif
86
+
7887
/*
7988
** For MinGW, check to see if we can include the header file containing its
8089
** version information, among other things. Normally, this internal MinGW
8190
** header file would [only] be included automatically by other MinGW header
8291
** files; however, the contained version information is now required by this
@@ -222,11 +231,11 @@
222231
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223232
** [sqlite_version()] and [sqlite_source_id()].
224233
*/
225234
#define SQLITE_VERSION "3.8.7"
226235
#define SQLITE_VERSION_NUMBER 3008007
227
-#define SQLITE_SOURCE_ID "2014-09-01 18:21:27 672e7387b1bda8d007da7de4244226577d7ab2dc"
236
+#define SQLITE_SOURCE_ID "2014-09-20 00:35:05 59e2c9df02d7e988c5ad44c560ead1e5288b12e7"
228237
229238
/*
230239
** CAPI3REF: Run-Time Library Version Numbers
231240
** KEYWORDS: sqlite3_version, sqlite3_sourceid
232241
**
@@ -610,10 +619,11 @@
610619
#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
611620
#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
612621
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
613622
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
614623
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
624
+#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
615625
616626
/*
617627
** CAPI3REF: Flags For File Open Operations
618628
**
619629
** These bit values are intended for use in the
@@ -2212,11 +2222,11 @@
22122222
**
22132223
** ^Calling this routine with an argument less than or equal to zero
22142224
** turns off all busy handlers.
22152225
**
22162226
** ^(There can only be a single busy handler for a particular
2217
-** [database connection] any any given moment. If another busy handler
2227
+** [database connection] at any given moment. If another busy handler
22182228
** was defined (using [sqlite3_busy_handler()]) prior to calling
22192229
** this routine, that other busy handler is cleared.)^
22202230
**
22212231
** See also: [PRAGMA busy_timeout]
22222232
*/
@@ -2415,10 +2425,14 @@
24152425
** of memory at least N bytes in length, where N is the parameter.
24162426
** ^If sqlite3_malloc() is unable to obtain sufficient free
24172427
** memory, it returns a NULL pointer. ^If the parameter N to
24182428
** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
24192429
** a NULL pointer.
2430
+**
2431
+** ^The sqlite3_malloc64(N) routine works just like
2432
+** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
2433
+** of a signed 32-bit integer.
24202434
**
24212435
** ^Calling sqlite3_free() with a pointer previously returned
24222436
** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
24232437
** that it might be reused. ^The sqlite3_free() routine is
24242438
** a no-op if is called with a NULL pointer. Passing a NULL pointer
@@ -2427,28 +2441,42 @@
24272441
** memory might result in a segmentation fault or other severe error.
24282442
** Memory corruption, a segmentation fault, or other severe error
24292443
** might result if sqlite3_free() is called with a non-NULL pointer that
24302444
** was not obtained from sqlite3_malloc() or sqlite3_realloc().
24312445
**
2432
-** ^(The sqlite3_realloc() interface attempts to resize a
2433
-** prior memory allocation to be at least N bytes, where N is the
2434
-** second parameter. The memory allocation to be resized is the first
2435
-** parameter.)^ ^ If the first parameter to sqlite3_realloc()
2446
+** ^The sqlite3_realloc(X,N) interface attempts to resize a
2447
+** prior memory allocation X to be at least N bytes.
2448
+** ^If the X parameter to sqlite3_realloc(X,N)
24362449
** is a NULL pointer then its behavior is identical to calling
2437
-** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().
2438
-** ^If the second parameter to sqlite3_realloc() is zero or
2450
+** sqlite3_malloc(N).
2451
+** ^If the N parameter to sqlite3_realloc(X,N) is zero or
24392452
** negative then the behavior is exactly the same as calling
2440
-** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
2441
-** ^sqlite3_realloc() returns a pointer to a memory allocation
2442
-** of at least N bytes in size or NULL if sufficient memory is unavailable.
2453
+** sqlite3_free(X).
2454
+** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
2455
+** of at least N bytes in size or NULL if insufficient memory is available.
24432456
** ^If M is the size of the prior allocation, then min(N,M) bytes
24442457
** of the prior allocation are copied into the beginning of buffer returned
2445
-** by sqlite3_realloc() and the prior allocation is freed.
2446
-** ^If sqlite3_realloc() returns NULL, then the prior allocation
2447
-** is not freed.
2458
+** by sqlite3_realloc(X,N) and the prior allocation is freed.
2459
+** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
2460
+** prior allocation is not freed.
24482461
**
2449
-** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
2462
+** ^The sqlite3_realloc64(X,N) interfaces works the same as
2463
+** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
2464
+** of a 32-bit signed integer.
2465
+**
2466
+** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
2467
+** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
2468
+** sqlite3_msize(X) returns the size of that memory allocation in bytes.
2469
+** ^The value returned by sqlite3_msize(X) might be larger than the number
2470
+** of bytes requested when X was allocated. ^If X is a NULL pointer then
2471
+** sqlite3_msize(X) returns zero. If X points to something that is not
2472
+** the beginning of memory allocation, or if it points to a formerly
2473
+** valid memory allocation that has now been freed, then the behavior
2474
+** of sqlite3_msize(X) is undefined and possibly harmful.
2475
+**
2476
+** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
2477
+** sqlite3_malloc64(), and sqlite3_realloc64()
24502478
** is always aligned to at least an 8 byte boundary, or to a
24512479
** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
24522480
** option is used.
24532481
**
24542482
** In SQLite version 3.5.0 and 3.5.1, it was possible to define
@@ -2472,12 +2500,15 @@
24722500
** The application must not read or write any part of
24732501
** a block of memory after it has been released using
24742502
** [sqlite3_free()] or [sqlite3_realloc()].
24752503
*/
24762504
SQLITE_API void *sqlite3_malloc(int);
2505
+SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
24772506
SQLITE_API void *sqlite3_realloc(void*, int);
2507
+SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
24782508
SQLITE_API void sqlite3_free(void*);
2509
+SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
24792510
24802511
/*
24812512
** CAPI3REF: Memory Allocator Statistics
24822513
**
24832514
** SQLite provides these two interfaces for reporting on the status
@@ -3482,11 +3513,12 @@
34823513
** is negative, then the length of the string is
34833514
** the number of bytes up to the first zero terminator.
34843515
** If the fourth parameter to sqlite3_bind_blob() is negative, then
34853516
** the behavior is undefined.
34863517
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3487
-** or sqlite3_bind_text16() then that parameter must be the byte offset
3518
+** or sqlite3_bind_text16() or sqlite3_bind_text64() then
3519
+** that parameter must be the byte offset
34883520
** where the NUL terminator would occur assuming the string were NUL
34893521
** terminated. If any NUL characters occur at byte offsets less than
34903522
** the value of the fourth parameter then the resulting string value will
34913523
** contain embedded NULs. The result of expressions involving strings
34923524
** with embedded NULs is undefined.
@@ -3500,10 +3532,18 @@
35003532
** the special value [SQLITE_STATIC], then SQLite assumes that the
35013533
** information is in static, unmanaged space and does not need to be freed.
35023534
** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
35033535
** SQLite makes its own private copy of the data immediately, before
35043536
** the sqlite3_bind_*() routine returns.
3537
+**
3538
+** ^The sixth argument to sqlite3_bind_text64() must be one of
3539
+** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
3540
+** to specify the encoding of the text in the third parameter. If
3541
+** the sixth argument to sqlite3_bind_text64() is not how of the
3542
+** allowed values shown above, or if the text encoding is different
3543
+** from the encoding specified by the sixth parameter, then the behavior
3544
+** is undefined.
35053545
**
35063546
** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
35073547
** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
35083548
** (just an integer to hold its size) while it is being processed.
35093549
** Zeroblobs are intended to serve as placeholders for BLOBs whose
@@ -3521,23 +3561,30 @@
35213561
** ^Bindings are not cleared by the [sqlite3_reset()] routine.
35223562
** ^Unbound parameters are interpreted as NULL.
35233563
**
35243564
** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
35253565
** [error code] if anything goes wrong.
3566
+** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
3567
+** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
3568
+** [SQLITE_MAX_LENGTH].
35263569
** ^[SQLITE_RANGE] is returned if the parameter
35273570
** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
35283571
**
35293572
** See also: [sqlite3_bind_parameter_count()],
35303573
** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
35313574
*/
35323575
SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
3576
+SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
3577
+ void(*)(void*));
35333578
SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
35343579
SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
35353580
SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
35363581
SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
3537
-SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
3582
+SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
35383583
SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
3584
+SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
3585
+ void(*)(void*), unsigned char encoding);
35393586
SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
35403587
SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
35413588
35423589
/*
35433590
** CAPI3REF: Number Of SQL Parameters
@@ -4282,11 +4329,11 @@
42824329
** These routines work only with [protected sqlite3_value] objects.
42834330
** Any attempt to use these routines on an [unprotected sqlite3_value]
42844331
** object results in undefined behavior.
42854332
**
42864333
** ^These routines work just like the corresponding [column access functions]
4287
-** except that these routines take a single [protected sqlite3_value] object
4334
+** except that these routines take a single [protected sqlite3_value] object
42884335
** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
42894336
**
42904337
** ^The sqlite3_value_text16() interface extracts a UTF-16 string
42914338
** in the native byte-order of the host machine. ^The
42924339
** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
@@ -4525,14 +4572,18 @@
45254572
**
45264573
** ^The sqlite3_result_null() interface sets the return value
45274574
** of the application-defined function to be NULL.
45284575
**
45294576
** ^The sqlite3_result_text(), sqlite3_result_text16(),
4530
-** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
4577
+** sqlite3_result_text16le(), and sqlite3_result_text16be()
45314578
** set the return value of the application-defined function to be
45324579
** a text string which is represented as UTF-8, UTF-16 native byte order,
45334580
** UTF-16 little endian, or UTF-16 big endian, respectively.
4581
+** ^The sqlite3_result_text64() interface sets the return value of an
4582
+** application-defined function to be a text string in an encoding
4583
+** specified by the fifth (and last) parameter, which must be one
4584
+** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
45344585
** ^SQLite takes the text result from the application from
45354586
** the 2nd parameter of the sqlite3_result_text* interfaces.
45364587
** ^If the 3rd parameter to the sqlite3_result_text* interfaces
45374588
** is negative, then SQLite takes result text from the 2nd parameter
45384589
** through the first zero character.
@@ -4572,10 +4623,11 @@
45724623
** If these routines are called from within the different thread
45734624
** than the one containing the application-defined function that received
45744625
** the [sqlite3_context] pointer, the results are undefined.
45754626
*/
45764627
SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
4628
+SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint64,void(*)(void*));
45774629
SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
45784630
SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
45794631
SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
45804632
SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
45814633
SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
@@ -4582,10 +4634,12 @@
45824634
SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
45834635
SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
45844636
SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
45854637
SQLITE_API void sqlite3_result_null(sqlite3_context*);
45864638
SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
4639
+SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
4640
+ void(*)(void*), unsigned char encoding);
45874641
SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
45884642
SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
45894643
SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
45904644
SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
45914645
SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
@@ -6475,25 +6529,25 @@
64756529
** memory already being in use.
64766530
** Only the high-water value is meaningful;
64776531
** the current value is always zero.)^
64786532
**
64796533
** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6480
-** <dd>This parameter returns the approximate number of of bytes of heap
6534
+** <dd>This parameter returns the approximate number of bytes of heap
64816535
** memory used by all pager caches associated with the database connection.)^
64826536
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
64836537
**
64846538
** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
6485
-** <dd>This parameter returns the approximate number of of bytes of heap
6539
+** <dd>This parameter returns the approximate number of bytes of heap
64866540
** memory used to store the schema for all databases associated
64876541
** with the connection - main, temp, and any [ATTACH]-ed databases.)^
64886542
** ^The full amount of memory used by the schemas is reported, even if the
64896543
** schema memory is shared with other database connections due to
64906544
** [shared cache mode] being enabled.
64916545
** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
64926546
**
64936547
** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
6494
-** <dd>This parameter returns the approximate number of of bytes of heap
6548
+** <dd>This parameter returns the approximate number of bytes of heap
64956549
** and lookaside memory used by all prepared statements associated with
64966550
** the database connection.)^
64976551
** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
64986552
** </dd>
64996553
**
@@ -7846,19 +7900,10 @@
78467900
#pragma warn -aus /* Assigned value is never used */
78477901
#pragma warn -csu /* Comparing signed and unsigned */
78487902
#pragma warn -spa /* Suspicious pointer arithmetic */
78497903
#endif
78507904
7851
-/* Needed for various definitions... */
7852
-#ifndef _GNU_SOURCE
7853
-# define _GNU_SOURCE
7854
-#endif
7855
-
7856
-#if defined(__OpenBSD__) && !defined(_BSD_SOURCE)
7857
-# define _BSD_SOURCE
7858
-#endif
7859
-
78607905
/*
78617906
** Include standard header files as necessary
78627907
*/
78637908
#ifdef HAVE_STDINT_H
78647909
#include <stdint.h>
@@ -8093,11 +8138,11 @@
80938138
# define ALWAYS(X) (X)
80948139
# define NEVER(X) (X)
80958140
#endif
80968141
80978142
/*
8098
-** Return true (non-zero) if the input is a integer that is too large
8143
+** Return true (non-zero) if the input is an integer that is too large
80998144
** to fit in 32-bits. This macro is used inside of various testcase()
81008145
** macros to verify that we have tested SQLite for large-file support.
81018146
*/
81028147
#define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0)
81038148
@@ -8644,11 +8689,11 @@
86448689
** Assert that the pointer X is aligned to an 8-byte boundary. This
86458690
** macro is used only within assert() to verify that the code gets
86468691
** all alignment restrictions correct.
86478692
**
86488693
** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the
8649
-** underlying malloc() implemention might return us 4-byte aligned
8694
+** underlying malloc() implementation might return us 4-byte aligned
86508695
** pointers. In that case, only verify 4-byte alignment.
86518696
*/
86528697
#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
86538698
# define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&3)==0)
86548699
#else
@@ -9537,14 +9582,14 @@
95379582
SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
95389583
#endif
95399584
SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
95409585
95419586
SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
9542
-SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*,int);
9587
+SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
95439588
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
95449589
9545
-typedef int (*RecordCompare)(int,const void*,UnpackedRecord*,int);
9590
+typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
95469591
SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
95479592
95489593
#ifndef SQLITE_OMIT_TRIGGER
95499594
SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
95509595
#endif
@@ -10180,11 +10225,11 @@
1018010225
** SHARED_SIZE is the number of bytes available in the pool from which
1018110226
** a random byte is selected for a shared lock. The pool of bytes for
1018210227
** shared locks begins at SHARED_FIRST.
1018310228
**
1018410229
** The same locking strategy and
10185
-** byte ranges are used for Unix. This leaves open the possiblity of having
10230
+** byte ranges are used for Unix. This leaves open the possibility of having
1018610231
** clients on win95, winNT, and unix all talking to the same shared file
1018710232
** and all locking correctly. To do so would require that samba (or whatever
1018810233
** tool is being used for file sharing) implements locks correctly between
1018910234
** windows and unix. I'm guessing that isn't likely to happen, but by
1019010235
** using the same locking range we are at least open to the possibility.
@@ -10299,11 +10344,11 @@
1029910344
1030010345
/*
1030110346
** Figure out what version of the code to use. The choices are
1030210347
**
1030310348
** SQLITE_MUTEX_OMIT No mutex logic. Not even stubs. The
10304
-** mutexes implemention cannot be overridden
10349
+** mutexes implementation cannot be overridden
1030510350
** at start-time.
1030610351
**
1030710352
** SQLITE_MUTEX_NOOP For single-threaded applications. No
1030810353
** mutual exclusion is provided. But this
1030910354
** implementation can be overridden at
@@ -10465,10 +10510,49 @@
1046510510
** Collisions are on the FuncDef.pHash chain.
1046610511
*/
1046710512
struct FuncDefHash {
1046810513
FuncDef *a[23]; /* Hash table for functions */
1046910514
};
10515
+
10516
+#ifdef SQLITE_USER_AUTHENTICATION
10517
+/*
10518
+** Information held in the "sqlite3" database connection object and used
10519
+** to manage user authentication.
10520
+*/
10521
+typedef struct sqlite3_userauth sqlite3_userauth;
10522
+struct sqlite3_userauth {
10523
+ u8 authLevel; /* Current authentication level */
10524
+ int nAuthPW; /* Size of the zAuthPW in bytes */
10525
+ char *zAuthPW; /* Password used to authenticate */
10526
+ char *zAuthUser; /* User name used to authenticate */
10527
+};
10528
+
10529
+/* Allowed values for sqlite3_userauth.authLevel */
10530
+#define UAUTH_Unknown 0 /* Authentication not yet checked */
10531
+#define UAUTH_Fail 1 /* User authentication failed */
10532
+#define UAUTH_User 2 /* Authenticated as a normal user */
10533
+#define UAUTH_Admin 3 /* Authenticated as an administrator */
10534
+
10535
+/* Functions used only by user authorization logic */
10536
+SQLITE_PRIVATE int sqlite3UserAuthTable(const char*);
10537
+SQLITE_PRIVATE int sqlite3UserAuthCheckLogin(sqlite3*,const char*,u8*);
10538
+SQLITE_PRIVATE void sqlite3UserAuthInit(sqlite3*);
10539
+SQLITE_PRIVATE void sqlite3CryptFunc(sqlite3_context*,int,sqlite3_value**);
10540
+
10541
+#endif /* SQLITE_USER_AUTHENTICATION */
10542
+
10543
+/*
10544
+** typedef for the authorization callback function.
10545
+*/
10546
+#ifdef SQLITE_USER_AUTHENTICATION
10547
+ typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*,
10548
+ const char*, const char*);
10549
+#else
10550
+ typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*,
10551
+ const char*);
10552
+#endif
10553
+
1047010554
1047110555
/*
1047210556
** Each database connection is an instance of the following structure.
1047310557
*/
1047410558
struct sqlite3 {
@@ -10533,12 +10617,11 @@
1053310617
volatile int isInterrupted; /* True if sqlite3_interrupt has been called */
1053410618
double notUsed1; /* Spacer */
1053510619
} u1;
1053610620
Lookaside lookaside; /* Lookaside malloc configuration */
1053710621
#ifndef SQLITE_OMIT_AUTHORIZATION
10538
- int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
10539
- /* Access authorization function */
10622
+ sqlite3_xauth xAuth; /* Access authorization function */
1054010623
void *pAuthArg; /* 1st argument to the access auth function */
1054110624
#endif
1054210625
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
1054310626
int (*xProgress)(void *); /* The progress callback */
1054410627
void *pProgressArg; /* Argument to the progress callback */
@@ -10560,11 +10643,10 @@
1056010643
int nSavepoint; /* Number of non-transaction savepoints */
1056110644
int nStatement; /* Number of nested statement-transactions */
1056210645
i64 nDeferredCons; /* Net deferred constraints this transaction. */
1056310646
i64 nDeferredImmCons; /* Net deferred immediate constraints */
1056410647
int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
10565
-
1056610648
#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
1056710649
/* The following variables are all protected by the STATIC_MASTER
1056810650
** mutex, not by sqlite3.mutex. They are used by code in notify.c.
1056910651
**
1057010652
** When X.pUnlockConnection==Y, that means that X is waiting for Y to
@@ -10578,10 +10660,13 @@
1057810660
sqlite3 *pUnlockConnection; /* Connection to watch for unlock */
1057910661
void *pUnlockArg; /* Argument to xUnlockNotify */
1058010662
void (*xUnlockNotify)(void **, int); /* Unlock notify callback */
1058110663
sqlite3 *pNextBlocked; /* Next in list of all blocked connections */
1058210664
#endif
10665
+#ifdef SQLITE_USER_AUTHENTICATION
10666
+ sqlite3_userauth auth; /* User authentication information */
10667
+#endif
1058310668
};
1058410669
1058510670
/*
1058610671
** A macro to discover the encoding of a database.
1058710672
*/
@@ -10637,11 +10722,10 @@
1063710722
#define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
1063810723
#define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
1063910724
#define SQLITE_Transitive 0x0200 /* Transitive constraints */
1064010725
#define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
1064110726
#define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */
10642
-#define SQLITE_AdjustOutEst 0x1000 /* Adjust output estimates using WHERE */
1064310727
#define SQLITE_AllOpts 0xffff /* All optimizations */
1064410728
1064510729
/*
1064610730
** Macros for testing whether or not optimizations are enabled or disabled.
1064710731
*/
@@ -10724,10 +10808,11 @@
1072410808
#define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
1072510809
#define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
1072610810
#define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
1072710811
#define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
1072810812
#define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */
10813
+#define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
1072910814
1073010815
/*
1073110816
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
1073210817
** used to create the initializers for the FuncDef structures.
1073310818
**
@@ -10770,10 +10855,13 @@
1077010855
#define LIKEFUNC(zName, nArg, arg, flags) \
1077110856
{nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
1077210857
(void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
1077310858
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
1077410859
{nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
10860
+ SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
10861
+#define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \
10862
+ {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
1077510863
SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
1077610864
1077710865
/*
1077810866
** All current savepoints are stored in a linked list starting at
1077910867
** sqlite3.pSavepoint. The first element in the list is the most recently
@@ -10857,30 +10945,30 @@
1085710945
**
1085810946
** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
1085910947
** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve
1086010948
** the speed a little by numbering the values consecutively.
1086110949
**
10862
-** But rather than start with 0 or 1, we begin with 'a'. That way,
10950
+** But rather than start with 0 or 1, we begin with 'A'. That way,
1086310951
** when multiple affinity types are concatenated into a string and
1086410952
** used as the P4 operand, they will be more readable.
1086510953
**
1086610954
** Note also that the numeric types are grouped together so that testing
10867
-** for a numeric type is a single comparison.
10955
+** for a numeric type is a single comparison. And the NONE type is first.
1086810956
*/
10869
-#define SQLITE_AFF_TEXT 'a'
10870
-#define SQLITE_AFF_NONE 'b'
10871
-#define SQLITE_AFF_NUMERIC 'c'
10872
-#define SQLITE_AFF_INTEGER 'd'
10873
-#define SQLITE_AFF_REAL 'e'
10957
+#define SQLITE_AFF_NONE 'A'
10958
+#define SQLITE_AFF_TEXT 'B'
10959
+#define SQLITE_AFF_NUMERIC 'C'
10960
+#define SQLITE_AFF_INTEGER 'D'
10961
+#define SQLITE_AFF_REAL 'E'
1087410962
1087510963
#define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
1087610964
1087710965
/*
1087810966
** The SQLITE_AFF_MASK values masks off the significant bits of an
1087910967
** affinity value.
1088010968
*/
10881
-#define SQLITE_AFF_MASK 0x67
10969
+#define SQLITE_AFF_MASK 0x47
1088210970
1088310971
/*
1088410972
** Additional bit values that can be ORed with an affinity without
1088510973
** changing the affinity.
1088610974
**
@@ -10887,14 +10975,14 @@
1088710975
** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL.
1088810976
** It causes an assert() to fire if either operand to a comparison
1088910977
** operator is NULL. It is added to certain comparison operators to
1089010978
** prove that the operands are always NOT NULL.
1089110979
*/
10892
-#define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */
10893
-#define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */
10980
+#define SQLITE_JUMPIFNULL 0x10 /* jumps if either operand is NULL */
10981
+#define SQLITE_STOREP2 0x20 /* Store result in reg[P2] rather than jump */
1089410982
#define SQLITE_NULLEQ 0x80 /* NULL=NULL */
10895
-#define SQLITE_NOTNULL 0x88 /* Assert that operands are never NULL */
10983
+#define SQLITE_NOTNULL 0x90 /* Assert that operands are never NULL */
1089610984
1089710985
/*
1089810986
** An object of this type is created for each virtual table present in
1089910987
** the database schema.
1090010988
**
@@ -11693,21 +11781,26 @@
1169311781
ExprList *pEList; /* Optional list of result-set columns */
1169411782
AggInfo *pAggInfo; /* Information about aggregates at this level */
1169511783
NameContext *pNext; /* Next outer name context. NULL for outermost */
1169611784
int nRef; /* Number of names resolved by this context */
1169711785
int nErr; /* Number of errors encountered while resolving names */
11698
- u8 ncFlags; /* Zero or more NC_* flags defined below */
11786
+ u16 ncFlags; /* Zero or more NC_* flags defined below */
1169911787
};
1170011788
1170111789
/*
1170211790
** Allowed values for the NameContext, ncFlags field.
11791
+**
11792
+** Note: NC_MinMaxAgg must have the same value as SF_MinMaxAgg and
11793
+** SQLITE_FUNC_MINMAX.
11794
+**
1170311795
*/
11704
-#define NC_AllowAgg 0x01 /* Aggregate functions are allowed here */
11705
-#define NC_HasAgg 0x02 /* One or more aggregate functions seen */
11706
-#define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */
11707
-#define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */
11708
-#define NC_PartIdx 0x10 /* True if resolving a partial index WHERE */
11796
+#define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
11797
+#define NC_HasAgg 0x0002 /* One or more aggregate functions seen */
11798
+#define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
11799
+#define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */
11800
+#define NC_PartIdx 0x0010 /* True if resolving a partial index WHERE */
11801
+#define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
1170911802
1171011803
/*
1171111804
** An instance of the following structure contains all information
1171211805
** needed to generate code for a single SELECT statement.
1171311806
**
@@ -11754,17 +11847,17 @@
1175411847
#define SF_Resolved 0x0002 /* Identifiers have been resolved */
1175511848
#define SF_Aggregate 0x0004 /* Contains aggregate functions */
1175611849
#define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
1175711850
#define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
1175811851
#define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
11759
- /* 0x0040 NOT USED */
11852
+#define SF_Compound 0x0040 /* Part of a compound query */
1176011853
#define SF_Values 0x0080 /* Synthesized from VALUES clause */
1176111854
/* 0x0100 NOT USED */
1176211855
#define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
1176311856
#define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
1176411857
#define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
11765
-#define SF_Compound 0x1000 /* Part of a compound query */
11858
+#define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
1176611859
1176711860
1176811861
/*
1176911862
** The results of a SELECT can be distributed in several ways, as defined
1177011863
** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -12362,12 +12455,12 @@
1236212455
#define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__)
1236312456
1236412457
1236512458
/*
1236612459
** FTS4 is really an extension for FTS3. It is enabled using the
12367
-** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also all
12368
-** the SQLITE_ENABLE_FTS4 macro to serve as an alisse for SQLITE_ENABLE_FTS3.
12460
+** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call
12461
+** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3.
1236912462
*/
1237012463
#if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3)
1237112464
# define SQLITE_ENABLE_FTS3
1237212465
#endif
1237312466
@@ -12410,19 +12503,19 @@
1241012503
SQLITE_PRIVATE int sqlite3Strlen30(const char*);
1241112504
#define sqlite3StrNICmp sqlite3_strnicmp
1241212505
1241312506
SQLITE_PRIVATE int sqlite3MallocInit(void);
1241412507
SQLITE_PRIVATE void sqlite3MallocEnd(void);
12415
-SQLITE_PRIVATE void *sqlite3Malloc(int);
12416
-SQLITE_PRIVATE void *sqlite3MallocZero(int);
12417
-SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3*, int);
12418
-SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3*, int);
12508
+SQLITE_PRIVATE void *sqlite3Malloc(u64);
12509
+SQLITE_PRIVATE void *sqlite3MallocZero(u64);
12510
+SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3*, u64);
12511
+SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3*, u64);
1241912512
SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3*,const char*);
12420
-SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, int);
12421
-SQLITE_PRIVATE void *sqlite3Realloc(void*, int);
12422
-SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, int);
12423
-SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, int);
12513
+SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64);
12514
+SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
12515
+SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
12516
+SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
1242412517
SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
1242512518
SQLITE_PRIVATE int sqlite3MallocSize(void*);
1242612519
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
1242712520
SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
1242812521
SQLITE_PRIVATE void sqlite3ScratchFree(void*);
@@ -12959,11 +13052,11 @@
1295913052
#endif
1296013053
1296113054
/*
1296213055
** The interface to the LEMON-generated parser
1296313056
*/
12964
-SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(size_t));
13057
+SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64));
1296513058
SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*));
1296613059
SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*);
1296713060
#ifdef YYTRACKMAXSTACKDEPTH
1296813061
SQLITE_PRIVATE int sqlite3ParserStackPeak(void*);
1296913062
#endif
@@ -13228,11 +13321,11 @@
1322813321
** May you find forgiveness for yourself and forgive others.
1322913322
** May you share freely, never taking more than you give.
1323013323
**
1323113324
*************************************************************************
1323213325
**
13233
-** This file contains definitions of global variables and contants.
13326
+** This file contains definitions of global variables and constants.
1323413327
*/
1323513328
1323613329
/* An array to map all upper-case characters into their corresponding
1323713330
** lower-case character.
1323813331
**
@@ -13824,10 +13917,13 @@
1382413917
#if defined(SQLITE_THREADSAFE)
1382513918
"THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
1382613919
#endif
1382713920
#ifdef SQLITE_USE_ALLOCA
1382813921
"USE_ALLOCA",
13922
+#endif
13923
+#ifdef SQLITE_USER_AUTHENTICATION
13924
+ "USER_AUTHENTICATION",
1382913925
#endif
1383013926
#ifdef SQLITE_WIN32_MALLOC
1383113927
"WIN32_MALLOC",
1383213928
#endif
1383313929
#ifdef SQLITE_ZERO_MALLOC
@@ -14052,29 +14148,32 @@
1405214148
** Internally, the vdbe manipulates nearly all SQL values as Mem
1405314149
** structures. Each Mem struct may cache multiple representations (string,
1405414150
** integer etc.) of the same value.
1405514151
*/
1405614152
struct Mem {
14057
- sqlite3 *db; /* The associated database connection */
14058
- char *z; /* String or BLOB value */
14059
- double r; /* Real value */
14060
- union {
14153
+ union MemValue {
14154
+ double r; /* Real value used when MEM_Real is set in flags */
1406114155
i64 i; /* Integer value used when MEM_Int is set in flags */
1406214156
int nZero; /* Used when bit MEM_Zero is set in flags */
1406314157
FuncDef *pDef; /* Used only when flags==MEM_Agg */
1406414158
RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
1406514159
VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
1406614160
} u;
14067
- int n; /* Number of characters in string value, excluding '\0' */
1406814161
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
1406914162
u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
14163
+ int n; /* Number of characters in string value, excluding '\0' */
14164
+ char *z; /* String or BLOB value */
14165
+ /* ShallowCopy only needs to copy the information above */
14166
+ char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
14167
+ int szMalloc; /* Size of the zMalloc allocation */
14168
+ int iPadding1; /* Padding for 8-byte alignment */
14169
+ sqlite3 *db; /* The associated database connection */
14170
+ void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
1407014171
#ifdef SQLITE_DEBUG
1407114172
Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
1407214173
void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
1407314174
#endif
14074
- void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
14075
- char *zMalloc; /* Dynamic buffer allocated by sqlite3_malloc() */
1407614175
};
1407714176
1407814177
/* One or more of the following flags are set to indicate the validOK
1407914178
** representations of the value stored in the Mem struct.
1408014179
**
@@ -14129,11 +14228,11 @@
1412914228
#ifdef SQLITE_DEBUG
1413014229
#define memIsValid(M) ((M)->flags & MEM_Undefined)==0
1413114230
#endif
1413214231
1413314232
/*
14134
-** Each auxilliary data pointer stored by a user defined function
14233
+** Each auxiliary data pointer stored by a user defined function
1413514234
** implementation calling sqlite3_set_auxdata() is stored in an instance
1413614235
** of this structure. All such structures associated with a single VM
1413714236
** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
1413814237
** when the VM is halted (if not before).
1413914238
*/
@@ -14144,11 +14243,11 @@
1414414243
void (*xDelete)(void *); /* Destructor for the aux data */
1414514244
AuxData *pNext; /* Next element in list */
1414614245
};
1414714246
1414814247
/*
14149
-** The "context" argument for a installable function. A pointer to an
14248
+** The "context" argument for an installable function. A pointer to an
1415014249
** instance of this structure is the first argument to the routines used
1415114250
** implement the SQL functions.
1415214251
**
1415314252
** There is a typedef for this structure in sqlite.h. So all routines,
1415414253
** even the public interface to SQLite, can use a pointer to this structure.
@@ -14158,17 +14257,17 @@
1415814257
** This structure is defined inside of vdbeInt.h because it uses substructures
1415914258
** (Mem) which are only defined there.
1416014259
*/
1416114260
struct sqlite3_context {
1416214261
Mem *pOut; /* The return value is stored here */
14163
- FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
14262
+ FuncDef *pFunc; /* Pointer to function information */
1416414263
Mem *pMem; /* Memory cell used to store aggregate context */
1416514264
CollSeq *pColl; /* Collating sequence */
1416614265
Vdbe *pVdbe; /* The VM that owns this context */
1416714266
int iOp; /* Instruction number of OP_Function */
1416814267
int isError; /* Error code returned by the function. */
14169
- u8 skipFlag; /* Skip skip accumulator loading if true */
14268
+ u8 skipFlag; /* Skip accumulator loading if true */
1417014269
u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */
1417114270
};
1417214271
1417314272
/*
1417414273
** An Explain object accumulates indented output which is helpful
@@ -14287,12 +14386,12 @@
1428714386
SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
1428814387
SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
1428914388
SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
1429014389
1429114390
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
14292
-SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
14293
-SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
14391
+SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*);
14392
+SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*);
1429414393
SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
1429514394
SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
1429614395
SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
1429714396
SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *, int);
1429814397
SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem*);
@@ -14305,10 +14404,11 @@
1430514404
#ifdef SQLITE_OMIT_FLOATING_POINT
1430614405
# define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
1430714406
#else
1430814407
SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double);
1430914408
#endif
14409
+SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem*,sqlite3*,u16);
1431014410
SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*);
1431114411
SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int);
1431214412
SQLITE_PRIVATE void sqlite3VdbeMemSetRowSet(Mem*);
1431314413
SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
1431414414
SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8);
@@ -14319,18 +14419,16 @@
1431914419
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
1432014420
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
1432114421
SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8);
1432214422
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
1432314423
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
14324
-SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
1432514424
#define VdbeMemDynamic(X) \
1432614425
(((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0)
14327
-#define VdbeMemReleaseExtern(X) \
14328
- if( VdbeMemDynamic(X) ) sqlite3VdbeMemReleaseExternal(X);
1432914426
SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
1433014427
SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
1433114428
SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
14429
+SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int n);
1433214430
SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
1433314431
SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
1433414432
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
1433514433
SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
1433614434
@@ -14653,11 +14751,11 @@
1465314751
** calendar system.
1465414752
**
1465514753
** 1970-01-01 00:00:00 is JD 2440587.5
1465614754
** 2000-01-01 00:00:00 is JD 2451544.5
1465714755
**
14658
-** This implemention requires years to be expressed as a 4-digit number
14756
+** This implementation requires years to be expressed as a 4-digit number
1465914757
** which means that only dates between 0000-01-01 and 9999-12-31 can
1466014758
** be represented, even though julian day numbers allow a much wider
1466114759
** range of dates.
1466214760
**
1466314761
** The Gregorian calendar system is used for all dates and times,
@@ -16497,11 +16595,11 @@
1649716595
** Like realloc(). Resize an allocation previously obtained from
1649816596
** sqlite3MemMalloc().
1649916597
**
1650016598
** For this low-level interface, we know that pPrior!=0. Cases where
1650116599
** pPrior==0 while have been intercepted by higher-level routine and
16502
-** redirected to xMalloc. Similarly, we know that nByte>0 becauses
16600
+** redirected to xMalloc. Similarly, we know that nByte>0 because
1650316601
** cases where nByte<=0 will have been intercepted by higher-level
1650416602
** routines and redirected to xFree.
1650516603
*/
1650616604
static void *sqlite3MemRealloc(void *pPrior, int nByte){
1650716605
#ifdef SQLITE_MALLOCSIZE
@@ -17854,11 +17952,11 @@
1785417952
** This memory allocator uses the following algorithm:
1785517953
**
1785617954
** 1. All memory allocations sizes are rounded up to a power of 2.
1785717955
**
1785817956
** 2. If two adjacent free blocks are the halves of a larger block,
17859
-** then the two blocks are coalesed into the single larger block.
17957
+** then the two blocks are coalesced into the single larger block.
1786017958
**
1786117959
** 3. New memory is allocated from the first available free block.
1786217960
**
1786317961
** This algorithm is described in: J. M. Robson. "Bounds for Some Functions
1786417962
** Concerning Dynamic Storage Allocation". Journal of the Association for
@@ -20081,27 +20179,25 @@
2008120179
2008220180
/*
2008320181
** Allocate memory. This routine is like sqlite3_malloc() except that it
2008420182
** assumes the memory subsystem has already been initialized.
2008520183
*/
20086
-SQLITE_PRIVATE void *sqlite3Malloc(int n){
20184
+SQLITE_PRIVATE void *sqlite3Malloc(u64 n){
2008720185
void *p;
20088
- if( n<=0 /* IMP: R-65312-04917 */
20089
- || n>=0x7fffff00
20090
- ){
20186
+ if( n==0 || n>=0x7fffff00 ){
2009120187
/* A memory allocation of a number of bytes which is near the maximum
2009220188
** signed integer value might cause an integer overflow inside of the
2009320189
** xMalloc(). Hence we limit the maximum size to 0x7fffff00, giving
2009420190
** 255 bytes of overhead. SQLite itself will never use anything near
2009520191
** this amount. The only way to reach the limit is with sqlite3_malloc() */
2009620192
p = 0;
2009720193
}else if( sqlite3GlobalConfig.bMemstat ){
2009820194
sqlite3_mutex_enter(mem0.mutex);
20099
- mallocWithAlarm(n, &p);
20195
+ mallocWithAlarm((int)n, &p);
2010020196
sqlite3_mutex_leave(mem0.mutex);
2010120197
}else{
20102
- p = sqlite3GlobalConfig.m.xMalloc(n);
20198
+ p = sqlite3GlobalConfig.m.xMalloc((int)n);
2010320199
}
2010420200
assert( EIGHT_BYTE_ALIGNMENT(p) ); /* IMP: R-04675-44850 */
2010520201
return p;
2010620202
}
2010720203
@@ -20112,10 +20208,16 @@
2011220208
*/
2011320209
SQLITE_API void *sqlite3_malloc(int n){
2011420210
#ifndef SQLITE_OMIT_AUTOINIT
2011520211
if( sqlite3_initialize() ) return 0;
2011620212
#endif
20213
+ return n<=0 ? 0 : sqlite3Malloc(n);
20214
+}
20215
+SQLITE_API void *sqlite3_malloc64(sqlite3_uint64 n){
20216
+#ifndef SQLITE_OMIT_AUTOINIT
20217
+ if( sqlite3_initialize() ) return 0;
20218
+#endif
2011720219
return sqlite3Malloc(n);
2011820220
}
2011920221
2012020222
/*
2012120223
** Each thread may only have a single outstanding allocation from
@@ -20234,21 +20336,27 @@
2023420336
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2023520337
assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
2023620338
return sqlite3GlobalConfig.m.xSize(p);
2023720339
}
2023820340
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
20239
- assert( db!=0 );
20240
- assert( sqlite3_mutex_held(db->mutex) );
20241
- if( isLookaside(db, p) ){
20242
- return db->lookaside.sz;
20341
+ if( db==0 ){
20342
+ return sqlite3MallocSize(p);
2024320343
}else{
20244
- assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20245
- assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20246
- assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20247
- return sqlite3GlobalConfig.m.xSize(p);
20344
+ assert( sqlite3_mutex_held(db->mutex) );
20345
+ if( isLookaside(db, p) ){
20346
+ return db->lookaside.sz;
20347
+ }else{
20348
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20349
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20350
+ assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20351
+ return sqlite3GlobalConfig.m.xSize(p);
20352
+ }
2024820353
}
2024920354
}
20355
+SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
20356
+ return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p);
20357
+}
2025020358
2025120359
/*
2025220360
** Free memory previously obtained from sqlite3Malloc().
2025320361
*/
2025420362
SQLITE_API void sqlite3_free(void *p){
@@ -20306,17 +20414,17 @@
2030620414
}
2030720415
2030820416
/*
2030920417
** Change the size of an existing memory allocation
2031020418
*/
20311
-SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, int nBytes){
20419
+SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){
2031220420
int nOld, nNew, nDiff;
2031320421
void *pNew;
2031420422
if( pOld==0 ){
2031520423
return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */
2031620424
}
20317
- if( nBytes<=0 ){
20425
+ if( nBytes==0 ){
2031820426
sqlite3_free(pOld); /* IMP: R-31593-10574 */
2031920427
return 0;
2032020428
}
2032120429
if( nBytes>=0x7fffff00 ){
2032220430
/* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */
@@ -20324,26 +20432,26 @@
2032420432
}
2032520433
nOld = sqlite3MallocSize(pOld);
2032620434
/* IMPLEMENTATION-OF: R-46199-30249 SQLite guarantees that the second
2032720435
** argument to xRealloc is always a value returned by a prior call to
2032820436
** xRoundup. */
20329
- nNew = sqlite3GlobalConfig.m.xRoundup(nBytes);
20437
+ nNew = sqlite3GlobalConfig.m.xRoundup((int)nBytes);
2033020438
if( nOld==nNew ){
2033120439
pNew = pOld;
2033220440
}else if( sqlite3GlobalConfig.bMemstat ){
2033320441
sqlite3_mutex_enter(mem0.mutex);
20334
- sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
20442
+ sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes);
2033520443
nDiff = nNew - nOld;
2033620444
if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
2033720445
mem0.alarmThreshold-nDiff ){
2033820446
sqlite3MallocAlarm(nDiff);
2033920447
}
2034020448
assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
2034120449
assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
2034220450
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
2034320451
if( pNew==0 && mem0.alarmCallback ){
20344
- sqlite3MallocAlarm(nBytes);
20452
+ sqlite3MallocAlarm((int)nBytes);
2034520453
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
2034620454
}
2034720455
if( pNew ){
2034820456
nNew = sqlite3MallocSize(pNew);
2034920457
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
@@ -20362,33 +20470,40 @@
2036220470
*/
2036320471
SQLITE_API void *sqlite3_realloc(void *pOld, int n){
2036420472
#ifndef SQLITE_OMIT_AUTOINIT
2036520473
if( sqlite3_initialize() ) return 0;
2036620474
#endif
20475
+ if( n<0 ) n = 0;
20476
+ return sqlite3Realloc(pOld, n);
20477
+}
20478
+SQLITE_API void *sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
20479
+#ifndef SQLITE_OMIT_AUTOINIT
20480
+ if( sqlite3_initialize() ) return 0;
20481
+#endif
2036720482
return sqlite3Realloc(pOld, n);
2036820483
}
2036920484
2037020485
2037120486
/*
2037220487
** Allocate and zero memory.
2037320488
*/
20374
-SQLITE_PRIVATE void *sqlite3MallocZero(int n){
20489
+SQLITE_PRIVATE void *sqlite3MallocZero(u64 n){
2037520490
void *p = sqlite3Malloc(n);
2037620491
if( p ){
20377
- memset(p, 0, n);
20492
+ memset(p, 0, (size_t)n);
2037820493
}
2037920494
return p;
2038020495
}
2038120496
2038220497
/*
2038320498
** Allocate and zero memory. If the allocation fails, make
2038420499
** the mallocFailed flag in the connection pointer.
2038520500
*/
20386
-SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3 *db, int n){
20501
+SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3 *db, u64 n){
2038720502
void *p = sqlite3DbMallocRaw(db, n);
2038820503
if( p ){
20389
- memset(p, 0, n);
20504
+ memset(p, 0, (size_t)n);
2039020505
}
2039120506
return p;
2039220507
}
2039320508
2039420509
/*
@@ -20407,11 +20522,11 @@
2040720522
** if( b ) a[10] = 9;
2040820523
**
2040920524
** In other words, if a subsequent malloc (ex: "b") worked, it is assumed
2041020525
** that all prior mallocs (ex: "a") worked too.
2041120526
*/
20412
-SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, int n){
20527
+SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, u64 n){
2041320528
void *p;
2041420529
assert( db==0 || sqlite3_mutex_held(db->mutex) );
2041520530
assert( db==0 || db->pnBytesFreed==0 );
2041620531
#ifndef SQLITE_OMIT_LOOKASIDE
2041720532
if( db ){
@@ -20451,11 +20566,11 @@
2045120566
2045220567
/*
2045320568
** Resize the block of memory pointed to by p to n bytes. If the
2045420569
** resize fails, set the mallocFailed flag in the connection object.
2045520570
*/
20456
-SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
20571
+SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){
2045720572
void *pNew = 0;
2045820573
assert( db!=0 );
2045920574
assert( sqlite3_mutex_held(db->mutex) );
2046020575
if( db->mallocFailed==0 ){
2046120576
if( p==0 ){
@@ -20472,11 +20587,11 @@
2047220587
}
2047320588
}else{
2047420589
assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
2047520590
assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
2047620591
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20477
- pNew = sqlite3_realloc(p, n);
20592
+ pNew = sqlite3_realloc64(p, n);
2047820593
if( !pNew ){
2047920594
sqlite3MemdebugSetType(p, MEMTYPE_DB|MEMTYPE_HEAP);
2048020595
db->mallocFailed = 1;
2048120596
}
2048220597
sqlite3MemdebugSetType(pNew, MEMTYPE_DB |
@@ -20488,11 +20603,11 @@
2048820603
2048920604
/*
2049020605
** Attempt to reallocate p. If the reallocation fails, then free p
2049120606
** and set the mallocFailed flag in the database connection.
2049220607
*/
20493
-SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, int n){
20608
+SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, u64 n){
2049420609
void *pNew;
2049520610
pNew = sqlite3DbRealloc(db, p, n);
2049620611
if( !pNew ){
2049720612
sqlite3DbFree(db, p);
2049820613
}
@@ -20518,19 +20633,19 @@
2051820633
if( zNew ){
2051920634
memcpy(zNew, z, n);
2052020635
}
2052120636
return zNew;
2052220637
}
20523
-SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, int n){
20638
+SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, u64 n){
2052420639
char *zNew;
2052520640
if( z==0 ){
2052620641
return 0;
2052720642
}
2052820643
assert( (n&0x7fffffff)==n );
2052920644
zNew = sqlite3DbMallocRaw(db, n+1);
2053020645
if( zNew ){
20531
- memcpy(zNew, z, n);
20646
+ memcpy(zNew, z, (size_t)n);
2053220647
zNew[n] = 0;
2053320648
}
2053420649
return zNew;
2053520650
}
2053620651
@@ -20599,10 +20714,25 @@
2059920714
** This file contains code for a set of "printf"-like routines. These
2060020715
** routines format strings much like the printf() from the standard C
2060120716
** library, though the implementation here has enhancements to support
2060220717
** SQLlite.
2060320718
*/
20719
+
20720
+/*
20721
+** If the strchrnul() library function is available, then set
20722
+** HAVE_STRCHRNUL. If that routine is not available, this module
20723
+** will supply its own. The built-in version is slower than
20724
+** the glibc version so the glibc version is definitely preferred.
20725
+*/
20726
+#if !defined(HAVE_STRCHRNUL)
20727
+# if defined(linux)
20728
+# define HAVE_STRCHRNUL 1
20729
+# else
20730
+# define HAVE_STRCHRNUL 0
20731
+# endif
20732
+#endif
20733
+
2060420734
2060520735
/*
2060620736
** Conversion types fall into various categories as defined by the
2060720737
** following enumeration.
2060820738
*/
@@ -20810,13 +20940,17 @@
2081020940
bArgList = useIntern = 0;
2081120941
}
2081220942
for(; (c=(*fmt))!=0; ++fmt){
2081320943
if( c!='%' ){
2081420944
bufpt = (char *)fmt;
20815
- while( (c=(*++fmt))!='%' && c!=0 ){};
20945
+#if HAVE_STRCHRNUL
20946
+ fmt = strchrnul(fmt, '%');
20947
+#else
20948
+ do{ fmt++; }while( *fmt && *fmt != '%' );
20949
+#endif
2081620950
sqlite3StrAccumAppend(pAccum, bufpt, (int)(fmt - bufpt));
20817
- if( c==0 ) break;
20951
+ if( *fmt==0 ) break;
2081820952
}
2081920953
if( (c=(*++fmt))==0 ){
2082020954
sqlite3StrAccumAppend(pAccum, "%", 1);
2082120955
break;
2082220956
}
@@ -21490,11 +21624,11 @@
2149021624
return z;
2149121625
}
2149221626
2149321627
/*
2149421628
** Like sqlite3MPrintf(), but call sqlite3DbFree() on zStr after formatting
21495
-** the string and before returnning. This routine is intended to be used
21629
+** the string and before returning. This routine is intended to be used
2149621630
** to modify an existing string. For example:
2149721631
**
2149821632
** x = sqlite3MPrintf(db, x, "prefix %s suffix", x);
2149921633
**
2150021634
*/
@@ -22341,16 +22475,17 @@
2234122475
pMem->n = (int)(z - zOut);
2234222476
}
2234322477
*z = 0;
2234422478
assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
2234522479
22480
+ c = pMem->flags;
2234622481
sqlite3VdbeMemRelease(pMem);
22347
- pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem);
22482
+ pMem->flags = MEM_Str|MEM_Term|(c&MEM_AffMask);
2234822483
pMem->enc = desiredEnc;
22349
- pMem->flags |= (MEM_Term);
2235022484
pMem->z = (char*)zOut;
2235122485
pMem->zMalloc = pMem->z;
22486
+ pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->z);
2235222487
2235322488
translate_out:
2235422489
#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
2235522490
{
2235622491
char zBuf[100];
@@ -22762,11 +22897,11 @@
2276222897
** The return value is -1 if no dequoting occurs or the length of the
2276322898
** dequoted string, exclusive of the zero terminator, if dequoting does
2276422899
** occur.
2276522900
**
2276622901
** 2002-Feb-14: This routine is extended to remove MS-Access style
22767
-** brackets from around identifers. For example: "[a-b-c]" becomes
22902
+** brackets from around identifiers. For example: "[a-b-c]" becomes
2276822903
** "a-b-c".
2276922904
*/
2277022905
SQLITE_PRIVATE int sqlite3Dequote(char *z){
2277122906
char quote;
2277222907
int i, j;
@@ -24872,10 +25007,18 @@
2487225007
# else
2487325008
# define HAVE_MREMAP 0
2487425009
# endif
2487525010
#endif
2487625011
25012
+/*
25013
+** Explicitly call the 64-bit version of lseek() on Android. Otherwise, lseek()
25014
+** is the 32-bit version, even if _FILE_OFFSET_BITS=64 is defined.
25015
+*/
25016
+#ifdef __ANDROID__
25017
+# define lseek lseek64
25018
+#endif
25019
+
2487725020
/*
2487825021
** Different Unix systems declare open() in different ways. Same use
2487925022
** open(const char*,int,mode_t). Others use open(const char*,int,...).
2488025023
** The difference is important when using a pointer to the function.
2488125024
**
@@ -25204,11 +25347,11 @@
2520425347
2520525348
2520625349
#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
2520725350
/*
2520825351
** Helper function for printing out trace information from debugging
25209
-** binaries. This returns the string represetation of the supplied
25352
+** binaries. This returns the string representation of the supplied
2521025353
** integer lock-type.
2521125354
*/
2521225355
static const char *azFileLock(int eFileLock){
2521325356
switch( eFileLock ){
2521425357
case NO_LOCK: return "NONE";
@@ -25281,13 +25424,26 @@
2528125424
#define osFcntl lockTrace
2528225425
#endif /* SQLITE_LOCK_TRACE */
2528325426
2528425427
/*
2528525428
** Retry ftruncate() calls that fail due to EINTR
25429
+**
25430
+** All calls to ftruncate() within this file should be made through this wrapper.
25431
+** On the Android platform, bypassing the logic below could lead to a corrupt
25432
+** database.
2528625433
*/
2528725434
static int robust_ftruncate(int h, sqlite3_int64 sz){
2528825435
int rc;
25436
+#ifdef __ANDROID__
25437
+ /* On Android, ftruncate() always uses 32-bit offsets, even if
25438
+ ** _FILE_OFFSET_BITS=64 is defined. This means it is unsafe to attempt to
25439
+ ** truncate a file to any size larger than 2GiB. Silently ignore any
25440
+ ** such attempts. */
25441
+ if( sz>(sqlite3_int64)0x7FFFFFFF ){
25442
+ rc = SQLITE_OK;
25443
+ }else
25444
+#endif
2528925445
do{ rc = osFtruncate(h,sz); }while( rc<0 && errno==EINTR );
2529025446
return rc;
2529125447
}
2529225448
2529325449
/*
@@ -27671,11 +27827,11 @@
2767127827
** bytes into pBuf. Return the number of bytes actually read.
2767227828
**
2767327829
** NB: If you define USE_PREAD or USE_PREAD64, then it might also
2767427830
** be necessary to define _XOPEN_SOURCE to be 500. This varies from
2767527831
** one system to another. Since SQLite does not define USE_PREAD
27676
-** any any form by default, we will not attempt to define _XOPEN_SOURCE.
27832
+** in any form by default, we will not attempt to define _XOPEN_SOURCE.
2767727833
** See tickets #2741 and #2681.
2767827834
**
2767927835
** To avoid stomping the errno value on a failed read the lastErrno value
2768027836
** is set before returning.
2768127837
*/
@@ -28168,11 +28324,11 @@
2816828324
*/
2816928325
if( pFile->szChunk>0 ){
2817028326
nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
2817128327
}
2817228328
28173
- rc = robust_ftruncate(pFile->h, (off_t)nByte);
28329
+ rc = robust_ftruncate(pFile->h, nByte);
2817428330
if( rc ){
2817528331
pFile->lastErrno = errno;
2817628332
return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
2817728333
}else{
2817828334
#ifdef SQLITE_DEBUG
@@ -28303,11 +28459,11 @@
2830328459
2830428460
return SQLITE_OK;
2830528461
}
2830628462
2830728463
/*
28308
-** If *pArg is inititially negative then this is a query. Set *pArg to
28464
+** If *pArg is initially negative then this is a query. Set *pArg to
2830928465
** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
2831028466
**
2831128467
** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
2831228468
*/
2831328469
static void unixModeBit(unixFile *pFile, unsigned char mask, int *pArg){
@@ -28510,11 +28666,11 @@
2851028666
2851128667
/*
2851228668
** Return the device characteristics for the file.
2851328669
**
2851428670
** This VFS is set up to return SQLITE_IOCAP_POWERSAFE_OVERWRITE by default.
28515
-** However, that choice is contraversial since technically the underlying
28671
+** However, that choice is controversial since technically the underlying
2851628672
** file system does not always provide powersafe overwrites. (In other
2851728673
** words, after a power-loss event, parts of the file that were never
2851828674
** written might end up being altered.) However, non-PSOW behavior is very,
2851928675
** very rare. And asserting PSOW makes a large reduction in the amount
2852028676
** of required I/O for journaling, since a lot of padding is eliminated.
@@ -29482,11 +29638,11 @@
2948229638
** Most finder functions return a pointer to a fixed sqlite3_io_methods
2948329639
** object. The only interesting finder-function is autolockIoFinder, which
2948429640
** looks at the filesystem type and tries to guess the best locking
2948529641
** strategy from that.
2948629642
**
29487
-** For finder-funtion F, two objects are created:
29643
+** For finder-function F, two objects are created:
2948829644
**
2948929645
** (1) The real finder-function named "FImpt()".
2949029646
**
2949129647
** (2) A constant pointer to this function named just "F".
2949229648
**
@@ -29549,11 +29705,11 @@
2954929705
unixCheckReservedLock /* xCheckReservedLock method */
2955029706
)
2955129707
IOMETHODS(
2955229708
nolockIoFinder, /* Finder function name */
2955329709
nolockIoMethods, /* sqlite3_io_methods object name */
29554
- 1, /* shared memory is disabled */
29710
+ 3, /* shared memory is disabled */
2955529711
nolockClose, /* xClose method */
2955629712
nolockLock, /* xLock method */
2955729713
nolockUnlock, /* xUnlock method */
2955829714
nolockCheckReservedLock /* xCheckReservedLock method */
2955929715
)
@@ -29744,11 +29900,11 @@
2974429900
*(*const autolockIoFinder)(const char*,unixFile*) = autolockIoFinderImpl;
2974529901
2974629902
#endif /* OS_VXWORKS && SQLITE_ENABLE_LOCKING_STYLE */
2974729903
2974829904
/*
29749
-** An abstract type for a pointer to a IO method finder function:
29905
+** An abstract type for a pointer to an IO method finder function:
2975029906
*/
2975129907
typedef const sqlite3_io_methods *(*finder_type)(const char*,unixFile*);
2975229908
2975329909
2975429910
/****************************************************************************
@@ -30058,11 +30214,11 @@
3005830214
** For this reason, if an error occurs in the stat() call here, it is
3005930215
** ignored and -1 is returned. The caller will try to open a new file
3006030216
** descriptor on the same path, fail, and return an error to SQLite.
3006130217
**
3006230218
** Even if a subsequent open() call does succeed, the consequences of
30063
- ** not searching for a resusable file descriptor are not dire. */
30219
+ ** not searching for a reusable file descriptor are not dire. */
3006430220
if( 0==osStat(zPath, &sStat) ){
3006530221
unixInodeInfo *pInode;
3006630222
3006730223
unixEnterMutex();
3006830224
pInode = inodeList;
@@ -30089,11 +30245,11 @@
3008930245
** to create new files with. If no error occurs, then SQLITE_OK is returned
3009030246
** and a value suitable for passing as the third argument to open(2) is
3009130247
** written to *pMode. If an IO error occurs, an SQLite error code is
3009230248
** returned and the value of *pMode is not modified.
3009330249
**
30094
-** In most cases cases, this routine sets *pMode to 0, which will become
30250
+** In most cases, this routine sets *pMode to 0, which will become
3009530251
** an indication to robust_open() to create the file using
3009630252
** SQLITE_DEFAULT_FILE_PERMISSIONS adjusted by the umask.
3009730253
** But if the file being opened is a WAL or regular journal file, then
3009830254
** this function queries the file-system for the permissions on the
3009930255
** corresponding database file and sets *pMode to this value. Whenever
@@ -30881,11 +31037,11 @@
3088131037
** by taking an sqlite-style shared lock on the conch file, reading the
3088231038
** contents and comparing the host's unique host ID (see below) and lock
3088331039
** proxy path against the values stored in the conch. The conch file is
3088431040
** stored in the same directory as the database file and the file name
3088531041
** is patterned after the database file name as ".<databasename>-conch".
30886
-** If the conch file does not exist, or it's contents do not match the
31042
+** If the conch file does not exist, or its contents do not match the
3088731043
** host ID and/or proxy path, then the lock is escalated to an exclusive
3088831044
** lock and the conch file contents is updated with the host ID and proxy
3088931045
** path and the lock is downgraded to a shared lock again. If the conch
3089031046
** is held by another process (with a shared lock), the exclusive lock
3089131047
** will fail and SQLITE_BUSY is returned.
@@ -30933,11 +31089,11 @@
3093331089
**
3093431090
** As mentioned above, when compiled with SQLITE_PREFER_PROXY_LOCKING,
3093531091
** setting the environment variable SQLITE_FORCE_PROXY_LOCKING to 1 will
3093631092
** force proxy locking to be used for every database file opened, and 0
3093731093
** will force automatic proxy locking to be disabled for all database
30938
-** files (explicity calling the SQLITE_SET_LOCKPROXYFILE pragma or
31094
+** files (explicitly calling the SQLITE_SET_LOCKPROXYFILE pragma or
3093931095
** sqlite_file_control API is not affected by SQLITE_FORCE_PROXY_LOCKING).
3094031096
*/
3094131097
3094231098
/*
3094331099
** Proxy locking is only available on MacOSX
@@ -33571,16 +33727,18 @@
3357133727
#else
3357233728
osSleep(milliseconds);
3357333729
#endif
3357433730
}
3357533731
33732
+#if SQLITE_MAX_WORKER_THREADS>0 && !SQLITE_OS_WINRT && SQLITE_THREADSAFE>0
3357633733
SQLITE_PRIVATE DWORD sqlite3Win32Wait(HANDLE hObject){
3357733734
DWORD rc;
3357833735
while( (rc = osWaitForSingleObjectEx(hObject, INFINITE,
3357933736
TRUE))==WAIT_IO_COMPLETION ){}
3358033737
return rc;
3358133738
}
33739
+#endif
3358233740
3358333741
/*
3358433742
** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
3358533743
** or WinCE. Return false (zero) for Win95, Win98, or WinME.
3358633744
**
@@ -33605,31 +33763,40 @@
3360533763
/*
3360633764
** This function determines if the machine is running a version of Windows
3360733765
** based on the NT kernel.
3360833766
*/
3360933767
SQLITE_API int sqlite3_win32_is_nt(void){
33610
-#if defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX
33768
+#if SQLITE_OS_WINRT
33769
+ /*
33770
+ ** NOTE: The WinRT sub-platform is always assumed to be based on the NT
33771
+ ** kernel.
33772
+ */
33773
+ return 1;
33774
+#elif defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX
3361133775
if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){
33612
-#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
33613
- defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WIN8
33614
- OSVERSIONINFOW sInfo;
33615
- sInfo.dwOSVersionInfoSize = sizeof(sInfo);
33616
- osGetVersionExW(&sInfo);
33617
- osInterlockedCompareExchange(&sqlite3_os_type,
33618
- (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
33619
-#elif defined(SQLITE_WIN32_HAS_ANSI)
33776
+#if defined(SQLITE_WIN32_HAS_ANSI)
3362033777
OSVERSIONINFOA sInfo;
3362133778
sInfo.dwOSVersionInfoSize = sizeof(sInfo);
3362233779
osGetVersionExA(&sInfo);
33780
+ osInterlockedCompareExchange(&sqlite3_os_type,
33781
+ (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
33782
+#elif defined(SQLITE_WIN32_HAS_WIDE)
33783
+ OSVERSIONINFOW sInfo;
33784
+ sInfo.dwOSVersionInfoSize = sizeof(sInfo);
33785
+ osGetVersionExW(&sInfo);
3362333786
osInterlockedCompareExchange(&sqlite3_os_type,
3362433787
(sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
3362533788
#endif
3362633789
}
3362733790
return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
3362833791
#elif SQLITE_TEST
3362933792
return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
3363033793
#else
33794
+ /*
33795
+ ** NOTE: All sub-platforms where the GetVersionEx[AW] functions are
33796
+ ** deprecated are always assumed to be based on the NT kernel.
33797
+ */
3363133798
return 1;
3363233799
#endif
3363333800
}
3363433801
3363533802
#ifdef SQLITE_WIN32_MALLOC
@@ -35402,11 +35569,11 @@
3540235569
pFile->h, pFile->locktype, sqlite3ErrName(rc)));
3540335570
return rc;
3540435571
}
3540535572
3540635573
/*
35407
-** If *pArg is inititially negative then this is a query. Set *pArg to
35574
+** If *pArg is initially negative then this is a query. Set *pArg to
3540835575
** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
3540935576
**
3541035577
** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
3541135578
*/
3541235579
static void winModeBit(winFile *pFile, unsigned char mask, int *pArg){
@@ -36416,11 +36583,11 @@
3641636583
if( p ){
3641736584
pFd->nFetchOut--;
3641836585
}else{
3641936586
/* FIXME: If Windows truly always prevents truncating or deleting a
3642036587
** file while a mapping is held, then the following winUnmapfile() call
36421
- ** is unnecessary can can be omitted - potentially improving
36588
+ ** is unnecessary can be omitted - potentially improving
3642236589
** performance. */
3642336590
winUnmapfile(pFd);
3642436591
}
3642536592
3642636593
assert( pFd->nFetchOut>=0 );
@@ -38274,27 +38441,10 @@
3827438441
# define expensive_assert(X)
3827538442
#endif
3827638443
3827738444
/********************************** Linked List Management ********************/
3827838445
38279
-#if !defined(NDEBUG) && defined(SQLITE_ENABLE_EXPENSIVE_ASSERT)
38280
-/*
38281
-** Check that the pCache->pSynced variable is set correctly. If it
38282
-** is not, either fail an assert or return zero. Otherwise, return
38283
-** non-zero. This is only used in debugging builds, as follows:
38284
-**
38285
-** expensive_assert( pcacheCheckSynced(pCache) );
38286
-*/
38287
-static int pcacheCheckSynced(PCache *pCache){
38288
- PgHdr *p;
38289
- for(p=pCache->pDirtyTail; p!=pCache->pSynced; p=p->pDirtyPrev){
38290
- assert( p->nRef || (p->flags&PGHDR_NEED_SYNC) );
38291
- }
38292
- return (p==0 || p->nRef || (p->flags&PGHDR_NEED_SYNC)==0);
38293
-}
38294
-#endif /* !NDEBUG && SQLITE_ENABLE_EXPENSIVE_ASSERT */
38295
-
3829638446
/* Allowed values for second argument to pcacheManageDirtyList() */
3829738447
#define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
3829838448
#define PCACHE_DIRTYLIST_ADD 2 /* Add pPage to the dirty list */
3829938449
#define PCACHE_DIRTYLIST_FRONT 3 /* Move pPage to the front of the list */
3830038450
@@ -38336,31 +38486,29 @@
3833638486
p->eCreate = 2;
3833738487
}
3833838488
}
3833938489
pPage->pDirtyNext = 0;
3834038490
pPage->pDirtyPrev = 0;
38341
- expensive_assert( pcacheCheckSynced(p) );
3834238491
}
3834338492
if( addRemove & PCACHE_DIRTYLIST_ADD ){
3834438493
assert( pPage->pDirtyNext==0 && pPage->pDirtyPrev==0 && p->pDirty!=pPage );
3834538494
3834638495
pPage->pDirtyNext = p->pDirty;
3834738496
if( pPage->pDirtyNext ){
3834838497
assert( pPage->pDirtyNext->pDirtyPrev==0 );
3834938498
pPage->pDirtyNext->pDirtyPrev = pPage;
38350
- }else if( p->bPurgeable ){
38351
- assert( p->eCreate==2 );
38352
- p->eCreate = 1;
38353
- }
38354
- p->pDirty = pPage;
38355
- if( !p->pDirtyTail ){
38499
+ }else{
3835638500
p->pDirtyTail = pPage;
38501
+ if( p->bPurgeable ){
38502
+ assert( p->eCreate==2 );
38503
+ p->eCreate = 1;
38504
+ }
3835738505
}
38506
+ p->pDirty = pPage;
3835838507
if( !p->pSynced && 0==(pPage->flags&PGHDR_NEED_SYNC) ){
3835938508
p->pSynced = pPage;
3836038509
}
38361
- expensive_assert( pcacheCheckSynced(p) );
3836238510
}
3836338511
}
3836438512
3836538513
/*
3836638514
** Wrapper around the pluggable caches xUnpin method. If the cache is
@@ -38533,11 +38681,10 @@
3853338681
/* Find a dirty page to write-out and recycle. First try to find a
3853438682
** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
3853538683
** cleared), but if that is not possible settle for any other
3853638684
** unreferenced dirty page.
3853738685
*/
38538
- expensive_assert( pcacheCheckSynced(pCache) );
3853938686
for(pPg=pCache->pSynced;
3854038687
pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
3854138688
pPg=pPg->pDirtyPrev
3854238689
);
3854338690
pCache->pSynced = pPg;
@@ -38619,20 +38766,20 @@
3861938766
return pPgHdr;
3862038767
}
3862138768
3862238769
/*
3862338770
** Decrement the reference count on a page. If the page is clean and the
38624
-** reference count drops to 0, then it is made elible for recycling.
38771
+** reference count drops to 0, then it is made eligible for recycling.
3862538772
*/
3862638773
SQLITE_PRIVATE void SQLITE_NOINLINE sqlite3PcacheRelease(PgHdr *p){
3862738774
assert( p->nRef>0 );
3862838775
p->nRef--;
3862938776
if( p->nRef==0 ){
3863038777
p->pCache->nRef--;
3863138778
if( (p->flags&PGHDR_DIRTY)==0 ){
3863238779
pcacheUnpin(p);
38633
- }else{
38780
+ }else if( p->pDirtyPrev!=0 ){
3863438781
/* Move the page to the head of the dirty list. */
3863538782
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
3863638783
}
3863738784
}
3863838785
}
@@ -38931,11 +39078,11 @@
3893139078
*************************************************************************
3893239079
**
3893339080
** This file implements the default page cache implementation (the
3893439081
** sqlite3_pcache interface). It also contains part of the implementation
3893539082
** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features.
38936
-** If the default page cache implementation is overriden, then neither of
39083
+** If the default page cache implementation is overridden, then neither of
3893739084
** these two features are available.
3893839085
*/
3893939086
3894039087
3894139088
typedef struct PCache1 PCache1;
@@ -38942,11 +39089,11 @@
3894239089
typedef struct PgHdr1 PgHdr1;
3894339090
typedef struct PgFreeslot PgFreeslot;
3894439091
typedef struct PGroup PGroup;
3894539092
3894639093
/* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
38947
-** of one or more PCaches that are able to recycle each others unpinned
39094
+** of one or more PCaches that are able to recycle each other's unpinned
3894839095
** pages when they are under memory pressure. A PGroup is an instance of
3894939096
** the following object.
3895039097
**
3895139098
** This page cache implementation works in one of two modes:
3895239099
**
@@ -40009,11 +40156,11 @@
4000940156
** a non-zero batch number, it will see all prior INSERTs.
4001040157
**
4001140158
** No INSERTs may occurs after a SMALLEST. An assertion will fail if
4001240159
** that is attempted.
4001340160
**
40014
-** The cost of an INSERT is roughly constant. (Sometime new memory
40161
+** The cost of an INSERT is roughly constant. (Sometimes new memory
4001540162
** has to be allocated on an INSERT.) The cost of a TEST with a new
4001640163
** batch number is O(NlogN) where N is the number of elements in the RowSet.
4001740164
** The cost of a TEST using the same batch number is O(logN). The cost
4001840165
** of the first SMALLEST is O(NlogN). Second and subsequent SMALLEST
4001940166
** primitives are constant time. The cost of DESTROY is O(N).
@@ -40401,12 +40548,12 @@
4040140548
4040240549
/*
4040340550
** Check to see if element iRowid was inserted into the rowset as
4040440551
** part of any insert batch prior to iBatch. Return 1 or 0.
4040540552
**
40406
-** If this is the first test of a new batch and if there exist entires
40407
-** on pRowSet->pEntry, then sort those entires into the forest at
40553
+** If this is the first test of a new batch and if there exist entries
40554
+** on pRowSet->pEntry, then sort those entries into the forest at
4040840555
** pRowSet->pForest so that they can be tested.
4040940556
*/
4041040557
SQLITE_PRIVATE int sqlite3RowSetTest(RowSet *pRowSet, int iBatch, sqlite3_int64 iRowid){
4041140558
struct RowSetEntry *p, *pTree;
4041240559
@@ -40684,16 +40831,16 @@
4068440831
** are synced prior to the master journal being deleted.
4068540832
**
4068640833
** Definition: Two databases (or the same database at two points it time)
4068740834
** are said to be "logically equivalent" if they give the same answer to
4068840835
** all queries. Note in particular the content of freelist leaf
40689
-** pages can be changed arbitarily without effecting the logical equivalence
40836
+** pages can be changed arbitrarily without affecting the logical equivalence
4069040837
** of the database.
4069140838
**
4069240839
** (7) At any time, if any subset, including the empty set and the total set,
4069340840
** of the unsynced changes to a rollback journal are removed and the
40694
-** journal is rolled back, the resulting database file will be logical
40841
+** journal is rolled back, the resulting database file will be logically
4069540842
** equivalent to the database file at the beginning of the transaction.
4069640843
**
4069740844
** (8) When a transaction is rolled back, the xTruncate method of the VFS
4069840845
** is called to restore the database file to the same size it was at
4069940846
** the beginning of the transaction. (In some VFSes, the xTruncate
@@ -40986,11 +41133,11 @@
4098641133
** be a few redundant xLock() calls or a lock may be held for longer than
4098741134
** required, but nothing really goes wrong.
4098841135
**
4098941136
** The exception is when the database file is unlocked as the pager moves
4099041137
** from ERROR to OPEN state. At this point there may be a hot-journal file
40991
-** in the file-system that needs to be rolled back (as part of a OPEN->SHARED
41138
+** in the file-system that needs to be rolled back (as part of an OPEN->SHARED
4099241139
** transition, by the same pager or any other). If the call to xUnlock()
4099341140
** fails at this point and the pager is left holding an EXCLUSIVE lock, this
4099441141
** can confuse the call to xCheckReservedLock() call made later as part
4099541142
** of hot-journal detection.
4099641143
**
@@ -41069,11 +41216,11 @@
4106941216
#define SPILLFLAG_OFF 0x01 /* Never spill cache. Set via pragma */
4107041217
#define SPILLFLAG_ROLLBACK 0x02 /* Current rolling back, so do not spill */
4107141218
#define SPILLFLAG_NOSYNC 0x04 /* Spill is ok, but do not sync */
4107241219
4107341220
/*
41074
-** A open page cache is an instance of struct Pager. A description of
41221
+** An open page cache is an instance of struct Pager. A description of
4107541222
** some of the more important member variables follows:
4107641223
**
4107741224
** eState
4107841225
**
4107941226
** The current 'state' of the pager object. See the comment and state
@@ -41241,11 +41388,11 @@
4124141388
u8 readOnly; /* True for a read-only database */
4124241389
u8 memDb; /* True to inhibit all file I/O */
4124341390
4124441391
/**************************************************************************
4124541392
** The following block contains those class members that change during
41246
- ** routine opertion. Class members not in this block are either fixed
41393
+ ** routine operation. Class members not in this block are either fixed
4124741394
** when the pager is first created or else only change when there is a
4124841395
** significant mode change (such as changing the page_size, locking_mode,
4124941396
** or the journal_mode). From another view, these class members describe
4125041397
** the "state" of the pager, while other class members describe the
4125141398
** "configuration" of the pager.
@@ -43036,11 +43183,11 @@
4303643183
** journal files extracted from regular rollback-journals.
4303743184
*/
4303843185
rc = sqlite3OsFileSize(pMaster, &nMasterJournal);
4303943186
if( rc!=SQLITE_OK ) goto delmaster_out;
4304043187
nMasterPtr = pVfs->mxPathname+1;
43041
- zMasterJournal = sqlite3Malloc((int)nMasterJournal + nMasterPtr + 1);
43188
+ zMasterJournal = sqlite3Malloc(nMasterJournal + nMasterPtr + 1);
4304243189
if( !zMasterJournal ){
4304343190
rc = SQLITE_NOMEM;
4304443191
goto delmaster_out;
4304543192
}
4304643193
zMasterPtr = &zMasterJournal[nMasterJournal+1];
@@ -43105,11 +43252,11 @@
4310543252
** DBMOD or OPEN state, this function is a no-op. Otherwise, the size
4310643253
** of the file is changed to nPage pages (nPage*pPager->pageSize bytes).
4310743254
** If the file on disk is currently larger than nPage pages, then use the VFS
4310843255
** xTruncate() method to truncate it.
4310943256
**
43110
-** Or, it might might be the case that the file on disk is smaller than
43257
+** Or, it might be the case that the file on disk is smaller than
4311143258
** nPage pages. Some operating system implementations can get confused if
4311243259
** you try to truncate a file to some size that is larger than it
4311343260
** currently is, so detect this case and write a single zero byte to
4311443261
** the end of the new file instead.
4311543262
**
@@ -43164,11 +43311,11 @@
4316443311
}
4316543312
4316643313
/*
4316743314
** Set the value of the Pager.sectorSize variable for the given
4316843315
** pager based on the value returned by the xSectorSize method
43169
-** of the open database file. The sector size will be used used
43316
+** of the open database file. The sector size will be used
4317043317
** to determine the size and alignment of journal header and
4317143318
** master journal pointers within created journal files.
4317243319
**
4317343320
** For temporary files the effective sector size is always 512 bytes.
4317443321
**
@@ -44226,16 +44373,18 @@
4422644373
if( !pNew ) rc = SQLITE_NOMEM;
4422744374
}
4422844375
4422944376
if( rc==SQLITE_OK ){
4423044377
pager_reset(pPager);
44231
- pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
44232
- pPager->pageSize = pageSize;
4423344378
sqlite3PageFree(pPager->pTmpSpace);
4423444379
pPager->pTmpSpace = pNew;
4423544380
rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
4423644381
}
44382
+ if( rc==SQLITE_OK ){
44383
+ pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
44384
+ pPager->pageSize = pageSize;
44385
+ }
4423744386
}
4423844387
4423944388
*pPageSize = pPager->pageSize;
4424044389
if( rc==SQLITE_OK ){
4424144390
if( nReserve<0 ) nReserve = pPager->nReserve;
@@ -44364,11 +44513,11 @@
4436444513
*/
4436544514
static int pager_wait_on_lock(Pager *pPager, int locktype){
4436644515
int rc; /* Return code */
4436744516
4436844517
/* Check that this is either a no-op (because the requested lock is
44369
- ** already held, or one of the transistions that the busy-handler
44518
+ ** already held), or one of the transitions that the busy-handler
4437044519
** may be invoked during, according to the comment above
4437144520
** sqlite3PagerSetBusyhandler().
4437244521
*/
4437344522
assert( (pPager->eLock>=locktype)
4437444523
|| (pPager->eLock==NO_LOCK && locktype==SHARED_LOCK)
@@ -44992,11 +45141,11 @@
4499245141
** The doNotSpill ROLLBACK and OFF bits inhibits all cache spilling
4499345142
** regardless of whether or not a sync is required. This is set during
4499445143
** a rollback or by user request, respectively.
4499545144
**
4499645145
** Spilling is also prohibited when in an error state since that could
44997
- ** lead to database corruption. In the current implementaton it
45146
+ ** lead to database corruption. In the current implementation it
4499845147
** is impossible for sqlite3PcacheFetch() to be called with createFlag==3
4499945148
** while in the error state, hence it is impossible for this routine to
4500045149
** be called in the error state. Nevertheless, we include a NEVER()
4500145150
** test for the error state as a safeguard against future changes.
4500245151
*/
@@ -45532,11 +45681,11 @@
4553245681
sqlite3OsClose(pPager->jfd);
4553345682
}
4553445683
*pExists = (first!=0);
4553545684
}else if( rc==SQLITE_CANTOPEN ){
4553645685
/* If we cannot open the rollback journal file in order to see if
45537
- ** its has a zero header, that might be due to an I/O error, or
45686
+ ** it has a zero header, that might be due to an I/O error, or
4553845687
** it might be due to the race condition described above and in
4553945688
** ticket #3883. Either way, assume that the journal is hot.
4554045689
** This might be a false positive. But if it is, then the
4554145690
** automatic journal playback and recovery mechanism will deal
4554245691
** with it under an EXCLUSIVE lock where we do not need to
@@ -47836,11 +47985,11 @@
4783647985
** frames, return the size in bytes of the page images stored within the
4783747986
** WAL frames. Otherwise, if this is not a WAL database or the WAL file
4783847987
** is empty, return 0.
4783947988
*/
4784047989
SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){
47841
- assert( pPager->eState==PAGER_READER );
47990
+ assert( pPager->eState>=PAGER_READER );
4784247991
return sqlite3WalFramesize(pPager->pWal);
4784347992
}
4784447993
#endif
4784547994
4784647995
#endif /* SQLITE_OMIT_DISKIO */
@@ -48420,11 +48569,11 @@
4842048569
4842148570
/*
4842248571
** The argument to this macro must be of type u32. On a little-endian
4842348572
** architecture, it returns the u32 value that results from interpreting
4842448573
** the 4 bytes as a big-endian value. On a big-endian architecture, it
48425
-** returns the value that would be produced by intepreting the 4 bytes
48574
+** returns the value that would be produced by interpreting the 4 bytes
4842648575
** of the input value as a little-endian integer.
4842748576
*/
4842848577
#define BYTESWAP32(x) ( \
4842948578
(((x)&0x000000FF)<<24) + (((x)&0x0000FF00)<<8) \
4843048579
+ (((x)&0x00FF0000)>>8) + (((x)&0xFF000000)>>24) \
@@ -48834,11 +48983,11 @@
4883448983
4883548984
idx = iFrame - iZero;
4883648985
assert( idx <= HASHTABLE_NSLOT/2 + 1 );
4883748986
4883848987
/* If this is the first entry to be added to this hash-table, zero the
48839
- ** entire hash table and aPgno[] array before proceding.
48988
+ ** entire hash table and aPgno[] array before proceeding.
4884048989
*/
4884148990
if( idx==1 ){
4884248991
int nByte = (int)((u8 *)&aHash[HASHTABLE_NSLOT] - (u8 *)&aPgno[1]);
4884348992
memset((void*)&aPgno[1], 0, nByte);
4884448993
}
@@ -49492,11 +49641,11 @@
4949249641
** WAL content is copied into the database file. This second fsync makes
4949349642
** it safe to delete the WAL since the new content will persist in the
4949449643
** database file.
4949549644
**
4949649645
** This routine uses and updates the nBackfill field of the wal-index header.
49497
-** This is the only routine tha will increase the value of nBackfill.
49646
+** This is the only routine that will increase the value of nBackfill.
4949849647
** (A WAL reset or recovery will revert nBackfill to zero, but not increase
4949949648
** its value.)
4950049649
**
4950149650
** The caller must be holding sufficient locks to ensure that no other
4950249651
** checkpoint is running (in any other thread or process) at the same
@@ -49796,11 +49945,11 @@
4979649945
** Read the wal-index header from the wal-index and into pWal->hdr.
4979749946
** If the wal-header appears to be corrupt, try to reconstruct the
4979849947
** wal-index from the WAL before returning.
4979949948
**
4980049949
** Set *pChanged to 1 if the wal-index header value in pWal->hdr is
49801
-** changed by this opertion. If pWal->hdr is unchanged, set *pChanged
49950
+** changed by this operation. If pWal->hdr is unchanged, set *pChanged
4980249951
** to 0.
4980349952
**
4980449953
** If the wal-index header is successfully read, return SQLITE_OK.
4980549954
** Otherwise an SQLite error code.
4980649955
*/
@@ -50000,11 +50149,11 @@
5000050149
if( memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr)) ){
5000150150
/* It is not safe to allow the reader to continue here if frames
5000250151
** may have been appended to the log before READ_LOCK(0) was obtained.
5000350152
** When holding READ_LOCK(0), the reader ignores the entire log file,
5000450153
** which implies that the database file contains a trustworthy
50005
- ** snapshoT. Since holding READ_LOCK(0) prevents a checkpoint from
50154
+ ** snapshot. Since holding READ_LOCK(0) prevents a checkpoint from
5000650155
** happening, this is usually correct.
5000750156
**
5000850157
** However, if frames have been appended to the log (or if the log
5000950158
** is wrapped and written for that matter) before the READ_LOCK(0)
5001050159
** is obtained, that is not necessarily true. A checkpointer may
@@ -50668,11 +50817,11 @@
5066850817
/* If this is the end of a transaction, then we might need to pad
5066950818
** the transaction and/or sync the WAL file.
5067050819
**
5067150820
** Padding and syncing only occur if this set of frames complete a
5067250821
** transaction and if PRAGMA synchronous=FULL. If synchronous==NORMAL
50673
- ** or synchonous==OFF, then no padding or syncing are needed.
50822
+ ** or synchronous==OFF, then no padding or syncing are needed.
5067450823
**
5067550824
** If SQLITE_IOCAP_POWERSAFE_OVERWRITE is defined, then padding is not
5067650825
** needed and only the sync is done. If padding is needed, then the
5067750826
** final frame is repeated (with its commit mark) until the next sector
5067850827
** boundary is crossed. Only the part of the WAL prior to the last
@@ -50971,11 +51120,11 @@
5097151120
** May you do good and not evil.
5097251121
** May you find forgiveness for yourself and forgive others.
5097351122
** May you share freely, never taking more than you give.
5097451123
**
5097551124
*************************************************************************
50976
-** This file implements a external (disk-based) database using BTrees.
51125
+** This file implements an external (disk-based) database using BTrees.
5097751126
** For a detailed discussion of BTrees, refer to
5097851127
**
5097951128
** Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
5098051129
** "Sorting And Searching", pages 473-480. Addison-Wesley
5098151130
** Publishing Company, Reading, Massachusetts.
@@ -51097,11 +51246,11 @@
5109751246
** 7 1 number of fragmented free bytes
5109851247
** 8 4 Right child (the Ptr(N) value). Omitted on leaves.
5109951248
**
5110051249
** The flags define the format of this btree page. The leaf flag means that
5110151250
** this page has no children. The zerodata flag means that this page carries
51102
-** only keys and no data. The intkey flag means that the key is a integer
51251
+** only keys and no data. The intkey flag means that the key is an integer
5110351252
** which is stored in the key size entry of the cell header rather than in
5110451253
** the payload area.
5110551254
**
5110651255
** The cell pointer array begins on the first byte after the page header.
5110751256
** The cell pointer array contains zero or more 2-byte numbers which are
@@ -51505,11 +51654,11 @@
5150551654
** in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in
5150651655
** this state, restoreCursorPosition() can be called to attempt to
5150751656
** seek the cursor to the saved position.
5150851657
**
5150951658
** CURSOR_FAULT:
51510
-** A unrecoverable error (an I/O error or a malloc failure) has occurred
51659
+** An unrecoverable error (an I/O error or a malloc failure) has occurred
5151151660
** on a different connection that shares the BtShared cache with this
5151251661
** cursor. The error has left the cache in an inconsistent state.
5151351662
** Do nothing else with this cursor. Any attempt to use the cursor
5151451663
** should return the error code stored in BtCursor.skip
5151551664
*/
@@ -51722,11 +51871,11 @@
5172251871
*/
5172351872
static void SQLITE_NOINLINE btreeLockCarefully(Btree *p){
5172451873
Btree *pLater;
5172551874
5172651875
/* In most cases, we should be able to acquire the lock we
51727
- ** want without having to go throught the ascending lock
51876
+ ** want without having to go through the ascending lock
5172851877
** procedure that follows. Just be sure not to block.
5172951878
*/
5173051879
if( sqlite3_mutex_try(p->pBt->mutex)==SQLITE_OK ){
5173151880
p->pBt->db = p->db;
5173251881
p->locked = 1;
@@ -51928,11 +52077,11 @@
5192852077
** May you do good and not evil.
5192952078
** May you find forgiveness for yourself and forgive others.
5193052079
** May you share freely, never taking more than you give.
5193152080
**
5193252081
*************************************************************************
51933
-** This file implements a external (disk-based) database using BTrees.
52082
+** This file implements an external (disk-based) database using BTrees.
5193452083
** See the header comment on "btreeInt.h" for additional information.
5193552084
** Including a description of file format and an overview of operation.
5193652085
*/
5193752086
5193852087
/*
@@ -52524,11 +52673,11 @@
5252452673
** all that is required. Otherwise, if pCur is not open on an intKey
5252552674
** table, then malloc space for and store the pCur->nKey bytes of key
5252652675
** data.
5252752676
*/
5252852677
if( 0==pCur->apPage[0]->intKey ){
52529
- void *pKey = sqlite3Malloc( (int)pCur->nKey );
52678
+ void *pKey = sqlite3Malloc( pCur->nKey );
5253052679
if( pKey ){
5253152680
rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey);
5253252681
if( rc==SQLITE_OK ){
5253352682
pCur->pKey = pKey;
5253452683
}else{
@@ -53062,11 +53211,11 @@
5306253211
** big FreeBlk that occurs in between the header and cell
5306353212
** pointer array and the cell content area.
5306453213
*/
5306553214
static int defragmentPage(MemPage *pPage){
5306653215
int i; /* Loop counter */
53067
- int pc; /* Address of a i-th cell */
53216
+ int pc; /* Address of the i-th cell */
5306853217
int hdr; /* Offset to the page header */
5306953218
int size; /* Size of a cell */
5307053219
int usableSize; /* Number of usable bytes on a page */
5307153220
int cellOffset; /* Offset to the cell pointer array */
5307253221
int cbrk; /* Offset to the cell content area */
@@ -54519,11 +54668,11 @@
5451954668
**
5452054669
** Only write cursors are counted if wrOnly is true. If wrOnly is
5452154670
** false then all cursors are counted.
5452254671
**
5452354672
** For the purposes of this routine, a cursor is any cursor that
54524
-** is capable of reading or writing to the databse. Cursors that
54673
+** is capable of reading or writing to the database. Cursors that
5452554674
** have been tripped into the CURSOR_FAULT state are not counted.
5452654675
*/
5452754676
static int countValidCursors(BtShared *pBt, int wrOnly){
5452854677
BtCursor *pCur;
5452954678
int r = 0;
@@ -54983,19 +55132,19 @@
5498355132
** Perform a single step of an incremental-vacuum. If successful, return
5498455133
** SQLITE_OK. If there is no work to do (and therefore no point in
5498555134
** calling this function again), return SQLITE_DONE. Or, if an error
5498655135
** occurs, return some other error code.
5498755136
**
54988
-** More specificly, this function attempts to re-organize the database so
55137
+** More specifically, this function attempts to re-organize the database so
5498955138
** that the last page of the file currently in use is no longer in use.
5499055139
**
5499155140
** Parameter nFin is the number of pages that this database would contain
5499255141
** were this function called until it returns SQLITE_DONE.
5499355142
**
5499455143
** If the bCommit parameter is non-zero, this function assumes that the
5499555144
** caller will keep calling incrVacuumStep() until it returns SQLITE_DONE
54996
-** or an error. bCommit is passed true for an auto-vacuum-on-commmit
55145
+** or an error. bCommit is passed true for an auto-vacuum-on-commit
5499755146
** operation, or false for an incremental vacuum.
5499855147
*/
5499955148
static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg, int bCommit){
5500055149
Pgno nFreeList; /* Number of pages still on the free-list */
5500155150
int rc;
@@ -55458,11 +55607,11 @@
5545855607
sqlite3BtreeLeave(p);
5545955608
return rc;
5546055609
}
5546155610
5546255611
/*
55463
-** Start a statement subtransaction. The subtransaction can can be rolled
55612
+** Start a statement subtransaction. The subtransaction can be rolled
5546455613
** back independently of the main transaction. You must start a transaction
5546555614
** before starting a subtransaction. The subtransaction is ended automatically
5546655615
** if the main transaction commits or rolls back.
5546755616
**
5546855617
** Statement subtransactions are used around individual SQL statements
@@ -55692,11 +55841,11 @@
5569255841
**
5569355842
** 2007-06-25: There is a bug in some versions of MSVC that cause the
5569455843
** compiler to crash when getCellInfo() is implemented as a macro.
5569555844
** But there is a measureable speed advantage to using the macro on gcc
5569655845
** (when less compiler optimizations like -Os or -O0 are used and the
55697
-** compiler is not doing agressive inlining.) So we use a real function
55846
+** compiler is not doing aggressive inlining.) So we use a real function
5569855847
** for MSVC and a macro for everything else. Ticket #2457.
5569955848
*/
5570055849
#ifndef NDEBUG
5570155850
static void assertCellInfo(BtCursor *pCur){
5570255851
CellInfo info;
@@ -55909,11 +56058,11 @@
5590956058
** The content being read or written might appear on the main page
5591056059
** or be scattered out on multiple overflow pages.
5591156060
**
5591256061
** If the current cursor entry uses one or more overflow pages and the
5591356062
** eOp argument is not 2, this function may allocate space for and lazily
55914
-** popluates the overflow page-list cache array (BtCursor.aOverflow).
56063
+** populates the overflow page-list cache array (BtCursor.aOverflow).
5591556064
** Subsequent calls use this cache to make seeking to the supplied offset
5591656065
** more efficient.
5591756066
**
5591856067
** Once an overflow page-list cache has been allocated, it may be
5591956068
** invalidated if some other cursor writes to the same table, or if
@@ -56111,11 +56260,11 @@
5611156260
return rc;
5611256261
}
5611356262
5611456263
/*
5611556264
** Read part of the key associated with cursor pCur. Exactly
56116
-** "amt" bytes will be transfered into pBuf[]. The transfer
56265
+** "amt" bytes will be transferred into pBuf[]. The transfer
5611756266
** begins at "offset".
5611856267
**
5611956268
** The caller must ensure that pCur is pointing to a valid row
5612056269
** in the table.
5612156270
**
@@ -56664,18 +56813,18 @@
5666456813
if( nCell<=pPage->max1bytePayload ){
5666556814
/* This branch runs if the record-size field of the cell is a
5666656815
** single byte varint and the record fits entirely on the main
5666756816
** b-tree page. */
5666856817
testcase( pCell+nCell+1==pPage->aDataEnd );
56669
- c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey, 0);
56818
+ c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
5667056819
}else if( !(pCell[1] & 0x80)
5667156820
&& (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
5667256821
){
5667356822
/* The record-size field is a 2 byte varint and the record
5667456823
** fits entirely on the main b-tree page. */
5667556824
testcase( pCell+nCell+2==pPage->aDataEnd );
56676
- c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey, 0);
56825
+ c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
5667756826
}else{
5667856827
/* The record flows over onto one or more overflow pages. In
5667956828
** this case the whole cell needs to be parsed, a buffer allocated
5668056829
** and accessPayload() used to retrieve the record into the
5668156830
** buffer before VdbeRecordCompare() can be called. */
@@ -56692,11 +56841,11 @@
5669256841
rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 2);
5669356842
if( rc ){
5669456843
sqlite3_free(pCellKey);
5669556844
goto moveto_finish;
5669656845
}
56697
- c = xRecordCompare(nCell, pCellKey, pIdxKey, 0);
56846
+ c = xRecordCompare(nCell, pCellKey, pIdxKey);
5669856847
sqlite3_free(pCellKey);
5669956848
}
5670056849
assert(
5670156850
(pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
5670256851
&& (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
@@ -57807,11 +57956,11 @@
5780757956
/*
5780857957
** Add a list of cells to a page. The page should be initially empty.
5780957958
** The cells are guaranteed to fit on the page.
5781057959
*/
5781157960
static void assemblePage(
57812
- MemPage *pPage, /* The page to be assemblied */
57961
+ MemPage *pPage, /* The page to be assembled */
5781357962
int nCell, /* The number of cells to add to this page */
5781457963
u8 **apCell, /* Pointers to cell bodies */
5781557964
u16 *aSize /* Sizes of the cells */
5781657965
){
5781757966
int i; /* Loop counter */
@@ -58473,11 +58622,11 @@
5847358622
apOld[i] = 0;
5847458623
i++;
5847558624
}
5847658625
5847758626
/*
58478
- ** Put the new pages in accending order. This helps to
58627
+ ** Put the new pages in ascending order. This helps to
5847958628
** keep entries in the disk file in order so that a scan
5848058629
** of the table is a linear scan through the file. That
5848158630
** in turn helps the operating system to deliver pages
5848258631
** from the disk more rapidly.
5848358632
**
@@ -58868,11 +59017,11 @@
5886859017
&& pParent->nCell==iIdx
5886959018
){
5887059019
/* Call balance_quick() to create a new sibling of pPage on which
5887159020
** to store the overflow cell. balance_quick() inserts a new cell
5887259021
** into pParent, which may cause pParent overflow. If this
58873
- ** happens, the next interation of the do-loop will balance pParent
59022
+ ** happens, the next iteration of the do-loop will balance pParent
5887459023
** use either balance_nonroot() or balance_deeper(). Until this
5887559024
** happens, the overflow cell is stored in the aBalanceQuickSpace[]
5887659025
** buffer.
5887759026
**
5887859027
** The purpose of the following assert() is to check that only a
@@ -58945,11 +59094,11 @@
5894559094
**
5894659095
** If the seekResult parameter is non-zero, then a successful call to
5894759096
** MovetoUnpacked() to seek cursor pCur to (pKey, nKey) has already
5894859097
** been performed. seekResult is the search result returned (a negative
5894959098
** number if pCur points at an entry that is smaller than (pKey, nKey), or
58950
-** a positive value if pCur points at an etry that is larger than
59099
+** a positive value if pCur points at an entry that is larger than
5895159100
** (pKey, nKey)).
5895259101
**
5895359102
** If the seekResult parameter is non-zero, then the caller guarantees that
5895459103
** cursor pCur is pointing at the existing copy of a row that is to be
5895559104
** overwritten. If the seekResult parameter is 0, then cursor pCur may
@@ -59102,11 +59251,11 @@
5910259251
return rc;
5910359252
}
5910459253
5910559254
/*
5910659255
** Delete the entry that the cursor is pointing to. The cursor
59107
-** is left pointing at a arbitrary location.
59256
+** is left pointing at an arbitrary location.
5910859257
*/
5910959258
SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur){
5911059259
Btree *p = pCur->pBtree;
5911159260
BtShared *pBt = p->pBt;
5911259261
int rc; /* Return code */
@@ -59800,11 +59949,11 @@
5980059949
5980159950
5980259951
/*
5980359952
** Add 1 to the reference count for page iPage. If this is the second
5980459953
** reference to the page, add an error message to pCheck->zErrMsg.
59805
-** Return 1 if there are 2 ore more references to the page and 0 if
59954
+** Return 1 if there are 2 or more references to the page and 0 if
5980659955
** if this is the first reference to the page.
5980759956
**
5980859957
** Also check that the page number is in bounds.
5980959958
*/
5981059959
static int checkRef(IntegrityCk *pCheck, Pgno iPage, char *zContext){
@@ -61307,33 +61456,41 @@
6130761456
**
6130861457
** This routine is intended for use inside of assert() statements, like
6130961458
** this: assert( sqlite3VdbeCheckMemInvariants(pMem) );
6131061459
*/
6131161460
SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem *p){
61312
- /* The MEM_Dyn bit is set if and only if Mem.xDel is a non-NULL destructor
61313
- ** function for Mem.z
61461
+ /* If MEM_Dyn is set then Mem.xDel!=0.
61462
+ ** Mem.xDel is might not be initialized if MEM_Dyn is clear.
6131461463
*/
6131561464
assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
61316
- assert( (p->flags & MEM_Dyn)!=0 || p->xDel==0 );
61465
+
61466
+ /* MEM_Dyn may only be set if Mem.szMalloc==0 */
61467
+ assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
61468
+
61469
+ /* Cannot be both MEM_Int and MEM_Real at the same time */
61470
+ assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
61471
+
61472
+ /* The szMalloc field holds the correct memory allocation size */
61473
+ assert( p->szMalloc==0
61474
+ || p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
6131761475
6131861476
/* If p holds a string or blob, the Mem.z must point to exactly
6131961477
** one of the following:
6132061478
**
6132161479
** (1) Memory in Mem.zMalloc and managed by the Mem object
6132261480
** (2) Memory to be freed using Mem.xDel
61323
- ** (3) An ephermal string or blob
61481
+ ** (3) An ephemeral string or blob
6132461482
** (4) A static string or blob
6132561483
*/
61326
- if( (p->flags & (MEM_Str|MEM_Blob)) && p->z!=0 ){
61484
+ if( (p->flags & (MEM_Str|MEM_Blob)) && p->n>0 ){
6132761485
assert(
61328
- ((p->z==p->zMalloc)? 1 : 0) +
61486
+ ((p->szMalloc>0 && p->z==p->zMalloc)? 1 : 0) +
6132961487
((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
6133061488
((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
6133161489
((p->flags&MEM_Static)!=0 ? 1 : 0) == 1
6133261490
);
6133361491
}
61334
-
6133561492
return 1;
6133661493
}
6133761494
#endif
6133861495
6133961496
@@ -61383,33 +61540,37 @@
6138361540
** If the bPreserve argument is true, then copy of the content of
6138461541
** pMem->z into the new allocation. pMem must be either a string or
6138561542
** blob if bPreserve is true. If bPreserve is false, any prior content
6138661543
** in pMem->z is discarded.
6138761544
*/
61388
-SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
61545
+SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
6138961546
assert( sqlite3VdbeCheckMemInvariants(pMem) );
6139061547
assert( (pMem->flags&MEM_RowSet)==0 );
6139161548
6139261549
/* If the bPreserve flag is set to true, then the memory cell must already
6139361550
** contain a valid string or blob value. */
6139461551
assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
6139561552
testcase( bPreserve && pMem->z==0 );
6139661553
61397
- if( pMem->zMalloc==0 || sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
61554
+ assert( pMem->szMalloc==0
61555
+ || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
61556
+ if( pMem->szMalloc<n ){
6139861557
if( n<32 ) n = 32;
61399
- if( bPreserve && pMem->z==pMem->zMalloc ){
61558
+ if( bPreserve && pMem->szMalloc>0 && pMem->z==pMem->zMalloc ){
6140061559
pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
6140161560
bPreserve = 0;
6140261561
}else{
61403
- sqlite3DbFree(pMem->db, pMem->zMalloc);
61562
+ if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
6140461563
pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
6140561564
}
6140661565
if( pMem->zMalloc==0 ){
61407
- VdbeMemReleaseExtern(pMem);
61566
+ sqlite3VdbeMemSetNull(pMem);
6140861567
pMem->z = 0;
61409
- pMem->flags = MEM_Null;
61568
+ pMem->szMalloc = 0;
6141061569
return SQLITE_NOMEM;
61570
+ }else{
61571
+ pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
6141161572
}
6141261573
}
6141361574
6141461575
if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
6141561576
memcpy(pMem->zMalloc, pMem->z, pMem->n);
@@ -61419,29 +61580,50 @@
6141961580
pMem->xDel((void *)(pMem->z));
6142061581
}
6142161582
6142261583
pMem->z = pMem->zMalloc;
6142361584
pMem->flags &= ~(MEM_Dyn|MEM_Ephem|MEM_Static);
61424
- pMem->xDel = 0;
6142561585
return SQLITE_OK;
6142661586
}
6142761587
6142861588
/*
61429
-** Make the given Mem object MEM_Dyn. In other words, make it so
61430
-** that any TEXT or BLOB content is stored in memory obtained from
61431
-** malloc(). In this way, we know that the memory is safe to be
61432
-** overwritten or altered.
61589
+** Change the pMem->zMalloc allocation to be at least szNew bytes.
61590
+** If pMem->zMalloc already meets or exceeds the requested size, this
61591
+** routine is a no-op.
61592
+**
61593
+** Any prior string or blob content in the pMem object may be discarded.
61594
+** The pMem->xDel destructor is called, if it exists. Though MEM_Str
61595
+** and MEM_Blob values may be discarded, MEM_Int, MEM_Real, and MEM_Null
61596
+** values are preserved.
61597
+**
61598
+** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
61599
+** if unable to complete the resizing.
61600
+*/
61601
+SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
61602
+ assert( szNew>=0 );
61603
+ if( pMem->szMalloc<szNew ){
61604
+ return sqlite3VdbeMemGrow(pMem, szNew, 0);
61605
+ }
61606
+ assert( (pMem->flags & MEM_Dyn)==0 );
61607
+ pMem->z = pMem->zMalloc;
61608
+ pMem->flags &= (MEM_Null|MEM_Int|MEM_Real);
61609
+ return SQLITE_OK;
61610
+}
61611
+
61612
+/*
61613
+** Change pMem so that its MEM_Str or MEM_Blob value is stored in
61614
+** MEM.zMalloc, where it can be safely written.
6143361615
**
6143461616
** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
6143561617
*/
6143661618
SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem *pMem){
6143761619
int f;
6143861620
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
6143961621
assert( (pMem->flags&MEM_RowSet)==0 );
6144061622
ExpandBlob(pMem);
6144161623
f = pMem->flags;
61442
- if( (f&(MEM_Str|MEM_Blob)) && pMem->z!=pMem->zMalloc ){
61624
+ if( (f&(MEM_Str|MEM_Blob)) && (pMem->szMalloc==0 || pMem->z!=pMem->zMalloc) ){
6144361625
if( sqlite3VdbeMemGrow(pMem, pMem->n + 2, 1) ){
6144461626
return SQLITE_NOMEM;
6144561627
}
6144661628
pMem->z[pMem->n] = 0;
6144761629
pMem->z[pMem->n+1] = 0;
@@ -61521,11 +61703,11 @@
6152161703
**
6152261704
** A MEM_Null value will never be passed to this function. This function is
6152361705
** used for converting values to text for returning to the user (i.e. via
6152461706
** sqlite3_value_text()), or for ensuring that values to be used as btree
6152561707
** keys are strings. In the former case a NULL pointer is returned the
61526
-** user and the later is an internal programming error.
61708
+** user and the latter is an internal programming error.
6152761709
*/
6152861710
SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem *pMem, u8 enc, u8 bForce){
6152961711
int fg = pMem->flags;
6153061712
const int nByte = 32;
6153161713
@@ -61535,11 +61717,11 @@
6153561717
assert( fg&(MEM_Int|MEM_Real) );
6153661718
assert( (pMem->flags&MEM_RowSet)==0 );
6153761719
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
6153861720
6153961721
61540
- if( sqlite3VdbeMemGrow(pMem, nByte, 0) ){
61722
+ if( sqlite3VdbeMemClearAndResize(pMem, nByte) ){
6154161723
return SQLITE_NOMEM;
6154261724
}
6154361725
6154461726
/* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8
6154561727
** string representation of the value. Then, if the required encoding
@@ -61549,11 +61731,11 @@
6154961731
*/
6155061732
if( fg & MEM_Int ){
6155161733
sqlite3_snprintf(nByte, pMem->z, "%lld", pMem->u.i);
6155261734
}else{
6155361735
assert( fg & MEM_Real );
61554
- sqlite3_snprintf(nByte, pMem->z, "%!.15g", pMem->r);
61736
+ sqlite3_snprintf(nByte, pMem->z, "%!.15g", pMem->u.r);
6155561737
}
6155661738
pMem->n = sqlite3Strlen30(pMem->z);
6155761739
pMem->enc = SQLITE_UTF8;
6155861740
pMem->flags |= MEM_Str|MEM_Term;
6155961741
if( bForce ) pMem->flags &= ~(MEM_Int|MEM_Real);
@@ -61582,76 +61764,83 @@
6158261764
t.db = pMem->db;
6158361765
ctx.pOut = &t;
6158461766
ctx.pMem = pMem;
6158561767
ctx.pFunc = pFunc;
6158661768
pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
61587
- assert( 0==(pMem->flags&MEM_Dyn) && !pMem->xDel );
61588
- sqlite3DbFree(pMem->db, pMem->zMalloc);
61769
+ assert( (pMem->flags & MEM_Dyn)==0 );
61770
+ if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
6158961771
memcpy(pMem, &t, sizeof(t));
6159061772
rc = ctx.isError;
6159161773
}
6159261774
return rc;
6159361775
}
6159461776
6159561777
/*
61596
-** If the memory cell contains a string value that must be freed by
61597
-** invoking an external callback, free it now. Calling this function
61598
-** does not free any Mem.zMalloc buffer.
61778
+** If the memory cell contains a value that must be freed by
61779
+** invoking the external callback in Mem.xDel, then this routine
61780
+** will free that value. It also sets Mem.flags to MEM_Null.
6159961781
**
61600
-** The VdbeMemReleaseExtern() macro invokes this routine if only if there
61601
-** is work for this routine to do.
61782
+** This is a helper routine for sqlite3VdbeMemSetNull() and
61783
+** for sqlite3VdbeMemRelease(). Use those other routines as the
61784
+** entry point for releasing Mem resources.
6160261785
*/
61603
-SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p){
61786
+static SQLITE_NOINLINE void vdbeMemClearExternAndSetNull(Mem *p){
6160461787
assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
61788
+ assert( VdbeMemDynamic(p) );
6160561789
if( p->flags&MEM_Agg ){
6160661790
sqlite3VdbeMemFinalize(p, p->u.pDef);
6160761791
assert( (p->flags & MEM_Agg)==0 );
61608
- sqlite3VdbeMemRelease(p);
61609
- }else if( p->flags&MEM_Dyn ){
61792
+ testcase( p->flags & MEM_Dyn );
61793
+ }
61794
+ if( p->flags&MEM_Dyn ){
6161061795
assert( (p->flags&MEM_RowSet)==0 );
6161161796
assert( p->xDel!=SQLITE_DYNAMIC && p->xDel!=0 );
6161261797
p->xDel((void *)p->z);
61613
- p->xDel = 0;
6161461798
}else if( p->flags&MEM_RowSet ){
6161561799
sqlite3RowSetClear(p->u.pRowSet);
6161661800
}else if( p->flags&MEM_Frame ){
61617
- sqlite3VdbeMemSetNull(p);
61801
+ VdbeFrame *pFrame = p->u.pFrame;
61802
+ pFrame->pParent = pFrame->v->pDelFrame;
61803
+ pFrame->v->pDelFrame = pFrame;
6161861804
}
61805
+ p->flags = MEM_Null;
6161961806
}
6162061807
6162161808
/*
6162261809
** Release memory held by the Mem p, both external memory cleared
6162361810
** by p->xDel and memory in p->zMalloc.
6162461811
**
6162561812
** This is a helper routine invoked by sqlite3VdbeMemRelease() in
61626
-** the uncommon case when there really is memory in p that is
61627
-** need of freeing.
61813
+** the unusual case where there really is memory in p that needs
61814
+** to be freed.
6162861815
*/
61629
-static SQLITE_NOINLINE void vdbeMemRelease(Mem *p){
61816
+static SQLITE_NOINLINE void vdbeMemClear(Mem *p){
6163061817
if( VdbeMemDynamic(p) ){
61631
- sqlite3VdbeMemReleaseExternal(p);
61818
+ vdbeMemClearExternAndSetNull(p);
6163261819
}
61633
- if( p->zMalloc ){
61820
+ if( p->szMalloc ){
6163461821
sqlite3DbFree(p->db, p->zMalloc);
61635
- p->zMalloc = 0;
61822
+ p->szMalloc = 0;
6163661823
}
6163761824
p->z = 0;
6163861825
}
6163961826
6164061827
/*
61641
-** Release any memory held by the Mem. This may leave the Mem in an
61642
-** inconsistent state, for example with (Mem.z==0) and
61643
-** (Mem.flags==MEM_Str).
61828
+** Release any memory resources held by the Mem. Both the memory that is
61829
+** free by Mem.xDel and the Mem.zMalloc allocation are freed.
61830
+**
61831
+** Use this routine prior to clean up prior to abandoning a Mem, or to
61832
+** reset a Mem back to its minimum memory utilization.
61833
+**
61834
+** Use sqlite3VdbeMemSetNull() to release just the Mem.xDel space
61835
+** prior to inserting new content into the Mem.
6164461836
*/
6164561837
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
6164661838
assert( sqlite3VdbeCheckMemInvariants(p) );
61647
- if( VdbeMemDynamic(p) || p->zMalloc ){
61648
- vdbeMemRelease(p);
61649
- }else{
61650
- p->z = 0;
61839
+ if( VdbeMemDynamic(p) || p->szMalloc ){
61840
+ vdbeMemClear(p);
6165161841
}
61652
- assert( p->xDel==0 );
6165361842
}
6165461843
6165561844
/*
6165661845
** Convert a 64-bit IEEE double into a 64-bit signed integer.
6165761846
** If the double is out of range of a 64-bit signed integer then
@@ -61686,11 +61875,11 @@
6168661875
** Return some kind of integer value which is the best we can do
6168761876
** at representing the value that *pMem describes as an integer.
6168861877
** If pMem is an integer, then the value is exact. If pMem is
6168961878
** a floating-point then the value returned is the integer part.
6169061879
** If pMem is a string or blob, then we make an attempt to convert
61691
-** it into a integer and return that. If pMem represents an
61880
+** it into an integer and return that. If pMem represents an
6169261881
** an SQL-NULL value, return 0.
6169361882
**
6169461883
** If pMem represents a string value, its encoding might be changed.
6169561884
*/
6169661885
SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *pMem){
@@ -61699,11 +61888,11 @@
6169961888
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
6170061889
flags = pMem->flags;
6170161890
if( flags & MEM_Int ){
6170261891
return pMem->u.i;
6170361892
}else if( flags & MEM_Real ){
61704
- return doubleToInt64(pMem->r);
61893
+ return doubleToInt64(pMem->u.r);
6170561894
}else if( flags & (MEM_Str|MEM_Blob) ){
6170661895
i64 value = 0;
6170761896
assert( pMem->z || pMem->n==0 );
6170861897
sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
6170961898
return value;
@@ -61720,11 +61909,11 @@
6172061909
*/
6172161910
SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
6172261911
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
6172361912
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
6172461913
if( pMem->flags & MEM_Real ){
61725
- return pMem->r;
61914
+ return pMem->u.r;
6172661915
}else if( pMem->flags & MEM_Int ){
6172761916
return (double)pMem->u.i;
6172861917
}else if( pMem->flags & (MEM_Str|MEM_Blob) ){
6172961918
/* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
6173061919
double val = (double)0;
@@ -61739,16 +61928,17 @@
6173961928
/*
6174061929
** The MEM structure is already a MEM_Real. Try to also make it a
6174161930
** MEM_Int if we can.
6174261931
*/
6174361932
SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem *pMem){
61933
+ i64 ix;
6174461934
assert( pMem->flags & MEM_Real );
6174561935
assert( (pMem->flags & MEM_RowSet)==0 );
6174661936
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
6174761937
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
6174861938
61749
- pMem->u.i = doubleToInt64(pMem->r);
61939
+ ix = doubleToInt64(pMem->u.r);
6175061940
6175161941
/* Only mark the value as an integer if
6175261942
**
6175361943
** (1) the round-trip conversion real->int->real is a no-op, and
6175461944
** (2) The integer is neither the largest nor the smallest
@@ -61756,15 +61946,13 @@
6175661946
**
6175761947
** The second and third terms in the following conditional enforces
6175861948
** the second condition under the assumption that addition overflow causes
6175961949
** values to wrap around.
6176061950
*/
61761
- if( pMem->r==(double)pMem->u.i
61762
- && pMem->u.i>SMALLEST_INT64
61763
- && pMem->u.i<LARGEST_INT64
61764
- ){
61765
- pMem->flags |= MEM_Int;
61951
+ if( pMem->u.r==ix && ix>SMALLEST_INT64 && ix<LARGEST_INT64 ){
61952
+ pMem->u.i = ix;
61953
+ MemSetTypeFlag(pMem, MEM_Int);
6176661954
}
6176761955
}
6176861956
6176961957
/*
6177061958
** Convert pMem to type integer. Invalidate any prior representations.
@@ -61785,11 +61973,11 @@
6178561973
*/
6178661974
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem *pMem){
6178761975
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
6178861976
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
6178961977
61790
- pMem->r = sqlite3VdbeRealValue(pMem);
61978
+ pMem->u.r = sqlite3VdbeRealValue(pMem);
6179161979
MemSetTypeFlag(pMem, MEM_Real);
6179261980
return SQLITE_OK;
6179361981
}
6179461982
6179561983
/*
@@ -61805,11 +61993,11 @@
6180561993
assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
6180661994
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
6180761995
if( 0==sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc) ){
6180861996
MemSetTypeFlag(pMem, MEM_Int);
6180961997
}else{
61810
- pMem->r = sqlite3VdbeRealValue(pMem);
61998
+ pMem->u.r = sqlite3VdbeRealValue(pMem);
6181161999
MemSetTypeFlag(pMem, MEM_Real);
6181262000
sqlite3VdbeIntegerAffinity(pMem);
6181362001
}
6181462002
}
6181562003
assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))!=0 );
@@ -61859,24 +62047,41 @@
6185962047
break;
6186062048
}
6186162049
}
6186262050
}
6186362051
62052
+/*
62053
+** Initialize bulk memory to be a consistent Mem object.
62054
+**
62055
+** The minimum amount of initialization feasible is performed.
62056
+*/
62057
+SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem *pMem, sqlite3 *db, u16 flags){
62058
+ assert( (flags & ~MEM_TypeMask)==0 );
62059
+ pMem->flags = flags;
62060
+ pMem->db = db;
62061
+ pMem->szMalloc = 0;
62062
+}
62063
+
6186462064
6186562065
/*
6186662066
** Delete any previous value and set the value stored in *pMem to NULL.
62067
+**
62068
+** This routine calls the Mem.xDel destructor to dispose of values that
62069
+** require the destructor. But it preserves the Mem.zMalloc memory allocation.
62070
+** To free all resources, use sqlite3VdbeMemRelease(), which both calls this
62071
+** routine to invoke the destructor and deallocates Mem.zMalloc.
62072
+**
62073
+** Use this routine to reset the Mem prior to insert a new value.
62074
+**
62075
+** Use sqlite3VdbeMemRelease() to complete erase the Mem prior to abandoning it.
6186762076
*/
6186862077
SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem *pMem){
61869
- if( pMem->flags & MEM_Frame ){
61870
- VdbeFrame *pFrame = pMem->u.pFrame;
61871
- pFrame->pParent = pFrame->v->pDelFrame;
61872
- pFrame->v->pDelFrame = pFrame;
61873
- }
61874
- if( pMem->flags & MEM_RowSet ){
61875
- sqlite3RowSetClear(pMem->u.pRowSet);
61876
- }
61877
- MemSetTypeFlag(pMem, MEM_Null);
62078
+ if( VdbeMemDynamic(pMem) ){
62079
+ vdbeMemClearExternAndSetNull(pMem);
62080
+ }else{
62081
+ pMem->flags = MEM_Null;
62082
+ }
6187862083
}
6187962084
SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){
6188062085
sqlite3VdbeMemSetNull((Mem*)p);
6188162086
}
6188262087
@@ -61889,27 +62094,20 @@
6188962094
pMem->flags = MEM_Blob|MEM_Zero;
6189062095
pMem->n = 0;
6189162096
if( n<0 ) n = 0;
6189262097
pMem->u.nZero = n;
6189362098
pMem->enc = SQLITE_UTF8;
61894
-
61895
-#ifdef SQLITE_OMIT_INCRBLOB
61896
- sqlite3VdbeMemGrow(pMem, n, 0);
61897
- if( pMem->z ){
61898
- pMem->n = n;
61899
- memset(pMem->z, 0, n);
61900
- }
61901
-#endif
62099
+ pMem->z = 0;
6190262100
}
6190362101
6190462102
/*
6190562103
** The pMem is known to contain content that needs to be destroyed prior
6190662104
** to a value change. So invoke the destructor, then set the value to
6190762105
** a 64-bit integer.
6190862106
*/
6190962107
static SQLITE_NOINLINE void vdbeReleaseAndSetInt64(Mem *pMem, i64 val){
61910
- sqlite3VdbeMemReleaseExternal(pMem);
62108
+ sqlite3VdbeMemSetNull(pMem);
6191162109
pMem->u.i = val;
6191262110
pMem->flags = MEM_Int;
6191362111
}
6191462112
6191562113
/*
@@ -61929,15 +62127,13 @@
6192962127
/*
6193062128
** Delete any previous value and set the value stored in *pMem to val,
6193162129
** manifest type REAL.
6193262130
*/
6193362131
SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem *pMem, double val){
61934
- if( sqlite3IsNaN(val) ){
61935
- sqlite3VdbeMemSetNull(pMem);
61936
- }else{
61937
- sqlite3VdbeMemRelease(pMem);
61938
- pMem->r = val;
62132
+ sqlite3VdbeMemSetNull(pMem);
62133
+ if( !sqlite3IsNaN(val) ){
62134
+ pMem->u.r = val;
6193962135
pMem->flags = MEM_Real;
6194062136
}
6194162137
}
6194262138
#endif
6194362139
@@ -61951,14 +62147,15 @@
6195162147
assert( (pMem->flags & MEM_RowSet)==0 );
6195262148
sqlite3VdbeMemRelease(pMem);
6195362149
pMem->zMalloc = sqlite3DbMallocRaw(db, 64);
6195462150
if( db->mallocFailed ){
6195562151
pMem->flags = MEM_Null;
62152
+ pMem->szMalloc = 0;
6195662153
}else{
6195762154
assert( pMem->zMalloc );
61958
- pMem->u.pRowSet = sqlite3RowSetInit(db, pMem->zMalloc,
61959
- sqlite3DbMallocSize(db, pMem->zMalloc));
62155
+ pMem->szMalloc = sqlite3DbMallocSize(db, pMem->zMalloc);
62156
+ pMem->u.pRowSet = sqlite3RowSetInit(db, pMem->zMalloc, pMem->szMalloc);
6196062157
assert( pMem->u.pRowSet!=0 );
6196162158
pMem->flags = MEM_RowSet;
6196262159
}
6196362160
}
6196462161
@@ -61978,11 +62175,11 @@
6197862175
return 0;
6197962176
}
6198062177
6198162178
#ifdef SQLITE_DEBUG
6198262179
/*
61983
-** This routine prepares a memory cell for modication by breaking
62180
+** This routine prepares a memory cell for modification by breaking
6198462181
** its link to a shallow copy and by marking any current shallow
6198562182
** copies of this cell as invalid.
6198662183
**
6198762184
** This is used for testing and debugging only - to make sure shallow
6198862185
** copies are not misused.
@@ -62011,13 +62208,13 @@
6201162208
** pFrom->z is used, then pTo->z points to the same thing as pFrom->z
6201262209
** and flags gets srcType (either MEM_Ephem or MEM_Static).
6201362210
*/
6201462211
SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){
6201562212
assert( (pFrom->flags & MEM_RowSet)==0 );
62016
- VdbeMemReleaseExtern(pTo);
62213
+ assert( pTo->db==pFrom->db );
62214
+ if( VdbeMemDynamic(pTo) ) vdbeMemClearExternAndSetNull(pTo);
6201762215
memcpy(pTo, pFrom, MEMCELLSIZE);
62018
- pTo->xDel = 0;
6201962216
if( (pFrom->flags&MEM_Static)==0 ){
6202062217
pTo->flags &= ~(MEM_Dyn|MEM_Static|MEM_Ephem);
6202162218
assert( srcType==MEM_Ephem || srcType==MEM_Static );
6202262219
pTo->flags |= srcType;
6202362220
}
@@ -62028,16 +62225,15 @@
6202862225
** freed before the copy is made.
6202962226
*/
6203062227
SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){
6203162228
int rc = SQLITE_OK;
6203262229
62230
+ assert( pTo->db==pFrom->db );
6203362231
assert( (pFrom->flags & MEM_RowSet)==0 );
62034
- VdbeMemReleaseExtern(pTo);
62232
+ if( VdbeMemDynamic(pTo) ) vdbeMemClearExternAndSetNull(pTo);
6203562233
memcpy(pTo, pFrom, MEMCELLSIZE);
6203662234
pTo->flags &= ~MEM_Dyn;
62037
- pTo->xDel = 0;
62038
-
6203962235
if( pTo->flags&(MEM_Str|MEM_Blob) ){
6204062236
if( 0==(pFrom->flags&MEM_Static) ){
6204162237
pTo->flags |= MEM_Ephem;
6204262238
rc = sqlite3VdbeMemMakeWriteable(pTo);
6204362239
}
@@ -62058,12 +62254,11 @@
6205862254
assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db );
6205962255
6206062256
sqlite3VdbeMemRelease(pTo);
6206162257
memcpy(pTo, pFrom, sizeof(Mem));
6206262258
pFrom->flags = MEM_Null;
62063
- pFrom->xDel = 0;
62064
- pFrom->zMalloc = 0;
62259
+ pFrom->szMalloc = 0;
6206562260
}
6206662261
6206762262
/*
6206862263
** Change the value of a Mem to be a string or a BLOB.
6206962264
**
@@ -62106,11 +62301,12 @@
6210662301
}
6210762302
flags = (enc==0?MEM_Blob:MEM_Str);
6210862303
if( nByte<0 ){
6210962304
assert( enc!=0 );
6211062305
if( enc==SQLITE_UTF8 ){
62111
- for(nByte=0; nByte<=iLimit && z[nByte]; nByte++){}
62306
+ nByte = sqlite3Strlen30(z);
62307
+ if( nByte>iLimit ) nByte = iLimit+1;
6211262308
}else{
6211362309
for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
6211462310
}
6211562311
flags |= MEM_Term;
6211662312
}
@@ -62125,18 +62321,18 @@
6212562321
nAlloc += (enc==SQLITE_UTF8?1:2);
6212662322
}
6212762323
if( nByte>iLimit ){
6212862324
return SQLITE_TOOBIG;
6212962325
}
62130
- if( sqlite3VdbeMemGrow(pMem, nAlloc, 0) ){
62326
+ if( sqlite3VdbeMemClearAndResize(pMem, nAlloc) ){
6213162327
return SQLITE_NOMEM;
6213262328
}
6213362329
memcpy(pMem->z, z, nAlloc);
6213462330
}else if( xDel==SQLITE_DYNAMIC ){
6213562331
sqlite3VdbeMemRelease(pMem);
6213662332
pMem->zMalloc = pMem->z = (char *)z;
62137
- pMem->xDel = 0;
62333
+ pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
6213862334
}else{
6213962335
sqlite3VdbeMemRelease(pMem);
6214062336
pMem->z = (char *)z;
6214162337
pMem->xDel = xDel;
6214262338
flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
@@ -62164,12 +62360,15 @@
6216462360
** The data or key is taken from the entry that pCur is currently pointing
6216562361
** to. offset and amt determine what portion of the data or key to retrieve.
6216662362
** key is true to get the key or false to get data. The result is written
6216762363
** into the pMem element.
6216862364
**
62169
-** The pMem structure is assumed to be uninitialized. Any prior content
62170
-** is overwritten without being freed.
62365
+** The pMem object must have been initialized. This routine will use
62366
+** pMem->zMalloc to hold the content from the btree, if possible. New
62367
+** pMem->zMalloc space will be allocated if necessary. The calling routine
62368
+** is responsible for making sure that the pMem object is eventually
62369
+** destroyed.
6217162370
**
6217262371
** If this routine fails for any reason (malloc returns NULL or unable
6217362372
** to read from the disk) then the pMem is left in an inconsistent state.
6217462373
*/
6217562374
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
@@ -62182,10 +62381,11 @@
6218262381
char *zData; /* Data from the btree layer */
6218362382
u32 available = 0; /* Number of bytes available on the local btree page */
6218462383
int rc = SQLITE_OK; /* Return code */
6218562384
6218662385
assert( sqlite3BtreeCursorIsValid(pCur) );
62386
+ assert( !VdbeMemDynamic(pMem) );
6218762387
6218862388
/* Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
6218962389
** that both the BtShared and database handle mutexes are held. */
6219062390
assert( (pMem->flags & MEM_RowSet)==0 );
6219162391
if( key ){
@@ -62194,27 +62394,29 @@
6219462394
zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
6219562395
}
6219662396
assert( zData!=0 );
6219762397
6219862398
if( offset+amt<=available ){
62199
- sqlite3VdbeMemRelease(pMem);
6220062399
pMem->z = &zData[offset];
6220162400
pMem->flags = MEM_Blob|MEM_Ephem;
6220262401
pMem->n = (int)amt;
62203
- }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
62204
- if( key ){
62205
- rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
62206
- }else{
62207
- rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
62208
- }
62209
- if( rc==SQLITE_OK ){
62210
- pMem->z[amt] = 0;
62211
- pMem->z[amt+1] = 0;
62212
- pMem->flags = MEM_Blob|MEM_Term;
62213
- pMem->n = (int)amt;
62214
- }else{
62215
- sqlite3VdbeMemRelease(pMem);
62402
+ }else{
62403
+ pMem->flags = MEM_Null;
62404
+ if( SQLITE_OK==(rc = sqlite3VdbeMemClearAndResize(pMem, amt+2)) ){
62405
+ if( key ){
62406
+ rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
62407
+ }else{
62408
+ rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
62409
+ }
62410
+ if( rc==SQLITE_OK ){
62411
+ pMem->z[amt] = 0;
62412
+ pMem->z[amt+1] = 0;
62413
+ pMem->flags = MEM_Blob|MEM_Term;
62414
+ pMem->n = (int)amt;
62415
+ }else{
62416
+ sqlite3VdbeMemRelease(pMem);
62417
+ }
6221662418
}
6221762419
}
6221862420
6221962421
return rc;
6222062422
}
@@ -62434,18 +62636,18 @@
6243462636
/* This branch happens for multiple negative signs. Ex: -(-5) */
6243562637
if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal)
6243662638
&& pVal!=0
6243762639
){
6243862640
sqlite3VdbeMemNumerify(pVal);
62439
- if( pVal->u.i==SMALLEST_INT64 ){
62440
- pVal->flags &= ~MEM_Int;
62441
- pVal->flags |= MEM_Real;
62442
- pVal->r = (double)SMALLEST_INT64;
62641
+ if( pVal->flags & MEM_Real ){
62642
+ pVal->u.r = -pVal->u.r;
62643
+ }else if( pVal->u.i==SMALLEST_INT64 ){
62644
+ pVal->u.r = -(double)SMALLEST_INT64;
62645
+ MemSetTypeFlag(pVal, MEM_Real);
6244362646
}else{
6244462647
pVal->u.i = -pVal->u.i;
6244562648
}
62446
- pVal->r = -pVal->r;
6244762649
sqlite3ValueApplyAffinity(pVal, affinity, enc);
6244862650
}
6244962651
}else if( op==TK_NULL ){
6245062652
pVal = valueNew(db, pCtx);
6245162653
if( pVal==0 ) goto no_mem;
@@ -62749,11 +62951,11 @@
6274962951
int i;
6275062952
int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
6275162953
Mem *aMem = pRec->aMem;
6275262954
sqlite3 *db = aMem[0].db;
6275362955
for(i=0; i<nCol; i++){
62754
- sqlite3DbFree(db, aMem[i].zMalloc);
62956
+ if( aMem[i].szMalloc ) sqlite3DbFree(db, aMem[i].zMalloc);
6275562957
}
6275662958
sqlite3KeyInfoUnref(pRec->pKeyInfo);
6275762959
sqlite3DbFree(db, pRec);
6275862960
}
6275962961
}
@@ -62809,13 +63011,11 @@
6280963011
** May you find forgiveness for yourself and forgive others.
6281063012
** May you share freely, never taking more than you give.
6281163013
**
6281263014
*************************************************************************
6281363015
** This file contains code used for creating, destroying, and populating
62814
-** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.) Prior
62815
-** to version 2.8.7, all this code was combined into the vdbe.c source file.
62816
-** But that file was getting too big so this subroutines were split out.
63016
+** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.)
6281763017
*/
6281863018
6281963019
/*
6282063020
** Create a new virtual database engine.
6282163021
*/
@@ -63495,11 +63695,11 @@
6349563695
case P4_MEM: {
6349663696
if( db->pnBytesFreed==0 ){
6349763697
sqlite3ValueFree((sqlite3_value*)p4);
6349863698
}else{
6349963699
Mem *p = (Mem*)p4;
63500
- sqlite3DbFree(db, p->zMalloc);
63700
+ if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
6350163701
sqlite3DbFree(db, p);
6350263702
}
6350363703
break;
6350463704
}
6350563705
case P4_VTAB : {
@@ -63692,11 +63892,11 @@
6369263892
**
6369363893
** If a memory allocation error has occurred prior to the calling of this
6369463894
** routine, then a pointer to a dummy VdbeOp will be returned. That opcode
6369563895
** is readable but not writable, though it is cast to a writable value.
6369663896
** The return of a dummy opcode allows the call to continue functioning
63697
-** after a OOM fault without having to check to see if the return from
63897
+** after an OOM fault without having to check to see if the return from
6369863898
** this routine is a valid pointer. But because the dummy.opcode is 0,
6369963899
** dummy will never be written to. This is verified by code inspection and
6370063900
** by running with Valgrind.
6370163901
*/
6370263902
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
@@ -63873,11 +64073,11 @@
6387364073
if( pMem->flags & MEM_Str ){
6387464074
zP4 = pMem->z;
6387564075
}else if( pMem->flags & MEM_Int ){
6387664076
sqlite3_snprintf(nTemp, zTemp, "%lld", pMem->u.i);
6387764077
}else if( pMem->flags & MEM_Real ){
63878
- sqlite3_snprintf(nTemp, zTemp, "%.16g", pMem->r);
64078
+ sqlite3_snprintf(nTemp, zTemp, "%.16g", pMem->u.r);
6387964079
}else if( pMem->flags & MEM_Null ){
6388064080
sqlite3_snprintf(nTemp, zTemp, "NULL");
6388164081
}else{
6388264082
assert( pMem->flags & MEM_Blob );
6388364083
zP4 = "(blob)";
@@ -64023,20 +64223,20 @@
6402364223
/*
6402464224
** Release an array of N Mem elements
6402564225
*/
6402664226
static void releaseMemArray(Mem *p, int N){
6402764227
if( p && N ){
64028
- Mem *pEnd;
64228
+ Mem *pEnd = &p[N];
6402964229
sqlite3 *db = p->db;
6403064230
u8 malloc_failed = db->mallocFailed;
6403164231
if( db->pnBytesFreed ){
64032
- for(pEnd=&p[N]; p<pEnd; p++){
64033
- sqlite3DbFree(db, p->zMalloc);
64034
- }
64232
+ do{
64233
+ if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
64234
+ }while( (++p)<pEnd );
6403564235
return;
6403664236
}
64037
- for(pEnd=&p[N]; p<pEnd; p++){
64237
+ do{
6403864238
assert( (&p[1])==pEnd || p[0].db==p[1].db );
6403964239
assert( sqlite3VdbeCheckMemInvariants(p) );
6404064240
6404164241
/* This block is really an inlined version of sqlite3VdbeMemRelease()
6404264242
** that takes advantage of the fact that the memory cell value is
@@ -64054,17 +64254,17 @@
6405464254
testcase( p->flags & MEM_Dyn );
6405564255
testcase( p->flags & MEM_Frame );
6405664256
testcase( p->flags & MEM_RowSet );
6405764257
if( p->flags&(MEM_Agg|MEM_Dyn|MEM_Frame|MEM_RowSet) ){
6405864258
sqlite3VdbeMemRelease(p);
64059
- }else if( p->zMalloc ){
64259
+ }else if( p->szMalloc ){
6406064260
sqlite3DbFree(db, p->zMalloc);
64061
- p->zMalloc = 0;
64261
+ p->szMalloc = 0;
6406264262
}
6406364263
6406464264
p->flags = MEM_Undefined;
64065
- }
64265
+ }while( (++p)<pEnd );
6406664266
db->mallocFailed = malloc_failed;
6406764267
}
6406864268
}
6406964269
6407064270
/*
@@ -64223,11 +64423,11 @@
6422364423
6422464424
pMem->flags = MEM_Int;
6422564425
pMem->u.i = pOp->p3; /* P3 */
6422664426
pMem++;
6422764427
64228
- if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
64428
+ if( sqlite3VdbeMemClearAndResize(pMem, 32) ){ /* P4 */
6422964429
assert( p->db->mallocFailed );
6423064430
return SQLITE_ERROR;
6423164431
}
6423264432
pMem->flags = MEM_Str|MEM_Term;
6423364433
zP4 = displayP4(pOp, pMem->z, 32);
@@ -64239,11 +64439,11 @@
6423964439
pMem->enc = SQLITE_UTF8;
6424064440
}
6424164441
pMem++;
6424264442
6424364443
if( p->explain==1 ){
64244
- if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
64444
+ if( sqlite3VdbeMemClearAndResize(pMem, 4) ){
6424564445
assert( p->db->mallocFailed );
6424664446
return SQLITE_ERROR;
6424764447
}
6424864448
pMem->flags = MEM_Str|MEM_Term;
6424964449
pMem->n = 2;
@@ -64250,11 +64450,11 @@
6425064450
sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
6425164451
pMem->enc = SQLITE_UTF8;
6425264452
pMem++;
6425364453
6425464454
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
64255
- if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
64455
+ if( sqlite3VdbeMemClearAndResize(pMem, 500) ){
6425664456
assert( p->db->mallocFailed );
6425764457
return SQLITE_ERROR;
6425864458
}
6425964459
pMem->flags = MEM_Str|MEM_Term;
6426064460
pMem->n = displayComment(pOp, zP4, pMem->z, 500);
@@ -64403,17 +64603,17 @@
6440364603
}
6440464604
6440564605
/*
6440664606
** Prepare a virtual machine for execution for the first time after
6440764607
** creating the virtual machine. This involves things such
64408
-** as allocating stack space and initializing the program counter.
64608
+** as allocating registers and initializing the program counter.
6440964609
** After the VDBE has be prepped, it can be executed by one or more
6441064610
** calls to sqlite3VdbeExec().
6441164611
**
64412
-** This function may be called exact once on a each virtual machine.
64612
+** This function may be called exactly once on each virtual machine.
6441364613
** After this routine is called the VM has been "packaged" and is ready
64414
-** to run. After this routine is called, futher calls to
64614
+** to run. After this routine is called, further calls to
6441564615
** sqlite3VdbeAddOp() functions are prohibited. This routine disconnects
6441664616
** the Vdbe from the Parse object that helped generate it so that the
6441764617
** the Vdbe becomes an independent entity and the Parse object can be
6441864618
** destroyed.
6441964619
**
@@ -64615,15 +64815,11 @@
6461564815
sqlite3VdbeDeleteAuxData(p, -1, 0);
6461664816
assert( p->pAuxData==0 );
6461764817
}
6461864818
6461964819
/*
64620
-** Clean up the VM after execution.
64621
-**
64622
-** This routine will automatically close any cursors, lists, and/or
64623
-** sorters that were left open. It also deletes the values of
64624
-** variables in the aVar[] array.
64820
+** Clean up the VM after a single run.
6462564821
*/
6462664822
static void Cleanup(Vdbe *p){
6462764823
sqlite3 *db = p->db;
6462864824
6462964825
#ifdef SQLITE_DEBUG
@@ -64787,11 +64983,11 @@
6478764983
}
6478864984
}
6478964985
6479064986
/* The complex case - There is a multi-file write-transaction active.
6479164987
** This requires a master journal file to ensure the transaction is
64792
- ** committed atomicly.
64988
+ ** committed atomically.
6479364989
*/
6479464990
#ifndef SQLITE_OMIT_DISKIO
6479564991
else{
6479664992
sqlite3_vfs *pVfs = db->pVfs;
6479764993
int needSync = 0;
@@ -65435,11 +65631,11 @@
6543565631
**
6543665632
** * the associated function parameter is the 32nd or later (counting
6543765633
** from left to right), or
6543865634
**
6543965635
** * the corresponding bit in argument mask is clear (where the first
65440
-** function parameter corrsponds to bit 0 etc.).
65636
+** function parameter corresponds to bit 0 etc.).
6544165637
*/
6544265638
SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe *pVdbe, int iOp, int mask){
6544365639
AuxData **pp = &pVdbe->pAuxData;
6544465640
while( *pp ){
6544565641
AuxData *pAux = *pp;
@@ -65539,11 +65735,11 @@
6553965735
6554065736
/*
6554165737
** Something has moved cursor "p" out of place. Maybe the row it was
6554265738
** pointed to was deleted out from under it. Or maybe the btree was
6554365739
** rebalanced. Whatever the cause, try to restore "p" to the place it
65544
-** is suppose to be pointing. If the row was deleted out from under the
65740
+** is supposed to be pointing. If the row was deleted out from under the
6554565741
** cursor, set the cursor to point to a NULL row.
6554665742
*/
6554765743
static int SQLITE_NOINLINE handleMovedCursor(VdbeCursor *p){
6554865744
int isDifferentRow, rc;
6554965745
assert( p->pCursor!=0 );
@@ -65746,12 +65942,12 @@
6574665942
/* Integer and Real */
6574765943
if( serial_type<=7 && serial_type>0 ){
6574865944
u64 v;
6574965945
u32 i;
6575065946
if( serial_type==7 ){
65751
- assert( sizeof(v)==sizeof(pMem->r) );
65752
- memcpy(&v, &pMem->r, sizeof(v));
65947
+ assert( sizeof(v)==sizeof(pMem->u.r) );
65948
+ memcpy(&v, &pMem->u.r, sizeof(v));
6575365949
swapMixedEndianFloat(v);
6575465950
}else{
6575565951
v = pMem->u.i;
6575665952
}
6575765953
len = i = sqlite3VdbeSerialTypeLen(serial_type);
@@ -65817,14 +66013,14 @@
6581766013
static const double r1 = 1.0;
6581866014
u64 t2 = t1;
6581966015
swapMixedEndianFloat(t2);
6582066016
assert( sizeof(r1)==sizeof(t2) && memcmp(&r1, &t2, sizeof(r1))==0 );
6582166017
#endif
65822
- assert( sizeof(x)==8 && sizeof(pMem->r)==8 );
66018
+ assert( sizeof(x)==8 && sizeof(pMem->u.r)==8 );
6582366019
swapMixedEndianFloat(x);
65824
- memcpy(&pMem->r, &x, sizeof(x));
65825
- pMem->flags = sqlite3IsNaN(pMem->r) ? MEM_Null : MEM_Real;
66020
+ memcpy(&pMem->u.r, &x, sizeof(x));
66021
+ pMem->flags = sqlite3IsNaN(pMem->u.r) ? MEM_Null : MEM_Real;
6582666022
}
6582766023
return 8;
6582866024
}
6582966025
SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(
6583066026
const unsigned char *buf, /* Buffer to deserialize from */
@@ -65882,11 +66078,10 @@
6588266078
}
6588366079
default: {
6588466080
static const u16 aFlag[] = { MEM_Blob|MEM_Ephem, MEM_Str|MEM_Ephem };
6588566081
pMem->z = (char *)buf;
6588666082
pMem->n = (serial_type-12)/2;
65887
- pMem->xDel = 0;
6588866083
pMem->flags = aFlag[serial_type&1];
6588966084
return pMem->n;
6589066085
}
6589166086
}
6589266087
return 0;
@@ -65958,21 +66153,21 @@
6595866153
p->default_rc = 0;
6595966154
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
6596066155
idx = getVarint32(aKey, szHdr);
6596166156
d = szHdr;
6596266157
u = 0;
65963
- while( idx<szHdr && u<p->nField && d<=nKey ){
66158
+ while( idx<szHdr && d<=nKey ){
6596466159
u32 serial_type;
6596566160
6596666161
idx += getVarint32(&aKey[idx], serial_type);
6596766162
pMem->enc = pKeyInfo->enc;
6596866163
pMem->db = pKeyInfo->db;
6596966164
/* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */
65970
- pMem->zMalloc = 0;
66165
+ pMem->szMalloc = 0;
6597166166
d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
6597266167
pMem++;
65973
- u++;
66168
+ if( (++u)>=p->nField ) break;
6597466169
}
6597566170
assert( u<=pKeyInfo->nField + 1 );
6597666171
p->nField = u;
6597766172
}
6597866173
@@ -66005,11 +66200,11 @@
6600566200
pKeyInfo = pPKey2->pKeyInfo;
6600666201
if( pKeyInfo->db==0 ) return 1;
6600766202
mem1.enc = pKeyInfo->enc;
6600866203
mem1.db = pKeyInfo->db;
6600966204
/* mem1.flags = 0; // Will be initialized by sqlite3VdbeSerialGet() */
66010
- VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */
66205
+ VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
6601166206
6601266207
/* Compilers may complain that mem1.u.i is potentially uninitialized.
6601366208
** We could initialize it, as shown here, to silence those complaints.
6601466209
** But in fact, mem1.u.i will never actually be used uninitialized, and doing
6601566210
** the unnecessary initialization has a measurable negative performance
@@ -66048,11 +66243,11 @@
6604866243
6604966244
/* Do the comparison
6605066245
*/
6605166246
rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i], pKeyInfo->aColl[i]);
6605266247
if( rc!=0 ){
66053
- assert( mem1.zMalloc==0 ); /* See comment below */
66248
+ assert( mem1.szMalloc==0 ); /* See comment below */
6605466249
if( pKeyInfo->aSortOrder[i] ){
6605566250
rc = -rc; /* Invert the result for DESC sort order. */
6605666251
}
6605766252
goto debugCompareEnd;
6605866253
}
@@ -66061,14 +66256,14 @@
6606166256
6606266257
/* No memory allocation is ever used on mem1. Prove this using
6606366258
** the following assert(). If the assert() fails, it indicates a
6606466259
** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
6606566260
*/
66066
- assert( mem1.zMalloc==0 );
66261
+ assert( mem1.szMalloc==0 );
6606766262
6606866263
/* rc==0 here means that one of the keys ran out of fields and
66069
- ** all the fields up to that point were equal. Return the the default_rc
66264
+ ** all the fields up to that point were equal. Return the default_rc
6607066265
** value. */
6607166266
rc = pPKey2->default_rc;
6607266267
6607366268
debugCompareEnd:
6607466269
if( desiredResult==0 && rc==0 ) return 1;
@@ -66100,12 +66295,12 @@
6610066295
int rc;
6610166296
const void *v1, *v2;
6610266297
int n1, n2;
6610366298
Mem c1;
6610466299
Mem c2;
66105
- memset(&c1, 0, sizeof(c1));
66106
- memset(&c2, 0, sizeof(c2));
66300
+ sqlite3VdbeMemInit(&c1, pMem1->db, MEM_Null);
66301
+ sqlite3VdbeMemInit(&c2, pMem1->db, MEM_Null);
6610766302
sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
6610866303
sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
6610966304
v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
6611066305
n1 = v1==0 ? 0 : c1.n;
6611166306
v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
@@ -66115,10 +66310,22 @@
6611566310
sqlite3VdbeMemRelease(&c2);
6611666311
if( (v1==0 || v2==0) && prcErr ) *prcErr = SQLITE_NOMEM;
6611766312
return rc;
6611866313
}
6611966314
}
66315
+
66316
+/*
66317
+** Compare two blobs. Return negative, zero, or positive if the first
66318
+** is less than, equal to, or greater than the second, respectively.
66319
+** If one blob is a prefix of the other, then the shorter is the lessor.
66320
+*/
66321
+static SQLITE_NOINLINE int sqlite3BlobCompare(const Mem *pB1, const Mem *pB2){
66322
+ int c = memcmp(pB1->z, pB2->z, pB1->n>pB2->n ? pB2->n : pB1->n);
66323
+ if( c ) return c;
66324
+ return pB1->n - pB2->n;
66325
+}
66326
+
6612066327
6612166328
/*
6612266329
** Compare the values contained by the two memory cells, returning
6612366330
** negative, zero or positive if pMem1 is less than, equal to, or greater
6612466331
** than pMem2. Sorting order is NULL's first, followed by numbers (integers
@@ -66126,11 +66333,10 @@
6612666333
** sequence pColl and finally blob's ordered by memcmp().
6612766334
**
6612866335
** Two NULL values are considered equal by this function.
6612966336
*/
6613066337
SQLITE_PRIVATE int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
66131
- int rc;
6613266338
int f1, f2;
6613366339
int combined_flags;
6613466340
6613566341
f1 = pMem1->flags;
6613666342
f2 = pMem2->flags;
@@ -66154,18 +66360,18 @@
6615466360
if( pMem1->u.i < pMem2->u.i ) return -1;
6615566361
if( pMem1->u.i > pMem2->u.i ) return 1;
6615666362
return 0;
6615766363
}
6615866364
if( (f1&MEM_Real)!=0 ){
66159
- r1 = pMem1->r;
66365
+ r1 = pMem1->u.r;
6616066366
}else if( (f1&MEM_Int)!=0 ){
6616166367
r1 = (double)pMem1->u.i;
6616266368
}else{
6616366369
return 1;
6616466370
}
6616566371
if( (f2&MEM_Real)!=0 ){
66166
- r2 = pMem2->r;
66372
+ r2 = pMem2->u.r;
6616766373
}else if( (f2&MEM_Int)!=0 ){
6616866374
r2 = (double)pMem2->u.i;
6616966375
}else{
6617066376
return -1;
6617166377
}
@@ -66201,15 +66407,11 @@
6620166407
/* If a NULL pointer was passed as the collate function, fall through
6620266408
** to the blob case and use memcmp(). */
6620366409
}
6620466410
6620566411
/* Both values must be blobs. Compare using memcmp(). */
66206
- rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n);
66207
- if( rc==0 ){
66208
- rc = pMem1->n - pMem2->n;
66209
- }
66210
- return rc;
66412
+ return sqlite3BlobCompare(pMem1, pMem2);
6621166413
}
6621266414
6621366415
6621466416
/*
6621566417
** The first argument passed to this function is a serial-type that
@@ -66255,11 +66457,11 @@
6625566457
/*
6625666458
** This function compares the two table rows or index records
6625766459
** specified by {nKey1, pKey1} and pPKey2. It returns a negative, zero
6625866460
** or positive integer if key1 is less than, equal to or
6625966461
** greater than key2. The {nKey1, pKey1} key must be a blob
66260
-** created by th OP_MakeRecord opcode of the VDBE. The pPKey2
66462
+** created by the OP_MakeRecord opcode of the VDBE. The pPKey2
6626166463
** key must be a parsed key such as obtained from
6626266464
** sqlite3VdbeParseRecord.
6626366465
**
6626466466
** If argument bSkip is non-zero, it is assumed that the caller has already
6626566467
** determined that the first fields of the keys are equal.
@@ -66271,11 +66473,11 @@
6627166473
** If database corruption is discovered, set pPKey2->errCode to
6627266474
** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
6627366475
** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
6627466476
** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
6627566477
*/
66276
-SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
66478
+static int vdbeRecordCompareWithSkip(
6627766479
int nKey1, const void *pKey1, /* Left key */
6627866480
UnpackedRecord *pPKey2, /* Right key */
6627966481
int bSkip /* If true, skip the first field */
6628066482
){
6628166483
u32 d1; /* Offset into aKey[] of next data element */
@@ -66306,11 +66508,11 @@
6630666508
return 0; /* Corruption */
6630766509
}
6630866510
i = 0;
6630966511
}
6631066512
66311
- VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */
66513
+ VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
6631266514
assert( pPKey2->pKeyInfo->nField+pPKey2->pKeyInfo->nXField>=pPKey2->nField
6631366515
|| CORRUPT_DB );
6631466516
assert( pPKey2->pKeyInfo->aSortOrder!=0 );
6631566517
assert( pPKey2->pKeyInfo->nField>0 );
6631666518
assert( idx1<=szHdr1 || CORRUPT_DB );
@@ -66326,13 +66528,13 @@
6632666528
}else if( serial_type==0 ){
6632766529
rc = -1;
6632866530
}else if( serial_type==7 ){
6632966531
double rhs = (double)pRhs->u.i;
6633066532
sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
66331
- if( mem1.r<rhs ){
66533
+ if( mem1.u.r<rhs ){
6633266534
rc = -1;
66333
- }else if( mem1.r>rhs ){
66535
+ }else if( mem1.u.r>rhs ){
6633466536
rc = +1;
6633566537
}
6633666538
}else{
6633766539
i64 lhs = vdbeRecordDecodeInt(serial_type, &aKey1[d1]);
6633866540
i64 rhs = pRhs->u.i;
@@ -66350,15 +66552,15 @@
6635066552
if( serial_type>=12 ){
6635166553
rc = +1;
6635266554
}else if( serial_type==0 ){
6635366555
rc = -1;
6635466556
}else{
66355
- double rhs = pRhs->r;
66557
+ double rhs = pRhs->u.r;
6635666558
double lhs;
6635766559
sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
6635866560
if( serial_type==7 ){
66359
- lhs = mem1.r;
66561
+ lhs = mem1.u.r;
6636066562
}else{
6636166563
lhs = (double)mem1.u.i;
6636266564
}
6636366565
if( lhs<rhs ){
6636466566
rc = -1;
@@ -66429,11 +66631,11 @@
6642966631
if( rc!=0 ){
6643066632
if( pKeyInfo->aSortOrder[i] ){
6643166633
rc = -rc;
6643266634
}
6643366635
assert( vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, rc) );
66434
- assert( mem1.zMalloc==0 ); /* See comment below */
66636
+ assert( mem1.szMalloc==0 ); /* See comment below */
6643566637
return rc;
6643666638
}
6643766639
6643866640
i++;
6643966641
pRhs++;
@@ -66442,21 +66644,28 @@
6644266644
}while( idx1<(unsigned)szHdr1 && i<pPKey2->nField && d1<=(unsigned)nKey1 );
6644366645
6644466646
/* No memory allocation is ever used on mem1. Prove this using
6644566647
** the following assert(). If the assert() fails, it indicates a
6644666648
** memory leak and a need to call sqlite3VdbeMemRelease(&mem1). */
66447
- assert( mem1.zMalloc==0 );
66649
+ assert( mem1.szMalloc==0 );
6644866650
6644966651
/* rc==0 here means that one or both of the keys ran out of fields and
66450
- ** all the fields up to that point were equal. Return the the default_rc
66652
+ ** all the fields up to that point were equal. Return the default_rc
6645166653
** value. */
6645266654
assert( CORRUPT_DB
6645366655
|| vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, pPKey2->default_rc)
6645466656
|| pKeyInfo->db->mallocFailed
6645566657
);
6645666658
return pPKey2->default_rc;
6645766659
}
66660
+SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
66661
+ int nKey1, const void *pKey1, /* Left key */
66662
+ UnpackedRecord *pPKey2 /* Right key */
66663
+){
66664
+ return vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
66665
+}
66666
+
6645866667
6645966668
/*
6646066669
** This function is an optimized version of sqlite3VdbeRecordCompare()
6646166670
** that (a) the first field of pPKey2 is an integer, and (b) the
6646266671
** size-of-header varint at the start of (pKey1/nKey1) fits in a single
@@ -66465,23 +66674,20 @@
6646566674
** To avoid concerns about buffer overreads, this routine is only used
6646666675
** on schemas where the maximum valid header size is 63 bytes or less.
6646766676
*/
6646866677
static int vdbeRecordCompareInt(
6646966678
int nKey1, const void *pKey1, /* Left key */
66470
- UnpackedRecord *pPKey2, /* Right key */
66471
- int bSkip /* Ignored */
66679
+ UnpackedRecord *pPKey2 /* Right key */
6647266680
){
6647366681
const u8 *aKey = &((const u8*)pKey1)[*(const u8*)pKey1 & 0x3F];
6647466682
int serial_type = ((const u8*)pKey1)[1];
6647566683
int res;
6647666684
u32 y;
6647766685
u64 x;
6647866686
i64 v = pPKey2->aMem[0].u.i;
6647966687
i64 lhs;
66480
- UNUSED_PARAMETER(bSkip);
6648166688
66482
- assert( bSkip==0 );
6648366689
assert( (*(u8*)pKey1)<=0x3F || CORRUPT_DB );
6648466690
switch( serial_type ){
6648566691
case 1: { /* 1-byte signed integer */
6648666692
lhs = ONE_BYTE_INT(aKey);
6648766693
testcase( lhs<0 );
@@ -66527,24 +66733,24 @@
6652766733
** statement (since the range of switch targets now starts at zero and
6652866734
** is contiguous) but does not cause any duplicate code to be generated
6652966735
** (as gcc is clever enough to combine the two like cases). Other
6653066736
** compilers might be similar. */
6653166737
case 0: case 7:
66532
- return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 0);
66738
+ return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2);
6653366739
6653466740
default:
66535
- return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 0);
66741
+ return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2);
6653666742
}
6653766743
6653866744
if( v>lhs ){
6653966745
res = pPKey2->r1;
6654066746
}else if( v<lhs ){
6654166747
res = pPKey2->r2;
6654266748
}else if( pPKey2->nField>1 ){
6654366749
/* The first fields of the two keys are equal. Compare the trailing
6654466750
** fields. */
66545
- res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1);
66751
+ res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
6654666752
}else{
6654766753
/* The first fields of the two keys are equal and there are no trailing
6654866754
** fields. Return pPKey2->default_rc in this case. */
6654966755
res = pPKey2->default_rc;
6655066756
}
@@ -66559,21 +66765,17 @@
6655966765
** uses the collation sequence BINARY and (c) that the size-of-header varint
6656066766
** at the start of (pKey1/nKey1) fits in a single byte.
6656166767
*/
6656266768
static int vdbeRecordCompareString(
6656366769
int nKey1, const void *pKey1, /* Left key */
66564
- UnpackedRecord *pPKey2, /* Right key */
66565
- int bSkip
66770
+ UnpackedRecord *pPKey2 /* Right key */
6656666771
){
6656766772
const u8 *aKey1 = (const u8*)pKey1;
6656866773
int serial_type;
6656966774
int res;
66570
- UNUSED_PARAMETER(bSkip);
6657166775
66572
- assert( bSkip==0 );
6657366776
getVarint32(&aKey1[1], serial_type);
66574
-
6657566777
if( serial_type<12 ){
6657666778
res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */
6657766779
}else if( !(serial_type & 0x01) ){
6657866780
res = pPKey2->r2; /* (pKey1/nKey1) is a blob */
6657966781
}else{
@@ -66591,11 +66793,11 @@
6659166793
6659266794
if( res==0 ){
6659366795
res = nStr - pPKey2->aMem[0].n;
6659466796
if( res==0 ){
6659566797
if( pPKey2->nField>1 ){
66596
- res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1);
66798
+ res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
6659766799
}else{
6659866800
res = pPKey2->default_rc;
6659966801
}
6660066802
}else if( res>0 ){
6660166803
res = pPKey2->r2;
@@ -66673,12 +66875,10 @@
6667366875
u32 szHdr; /* Size of the header */
6667466876
u32 typeRowid; /* Serial type of the rowid */
6667566877
u32 lenRowid; /* Size of the rowid */
6667666878
Mem m, v;
6667766879
66678
- UNUSED_PARAMETER(db);
66679
-
6668066880
/* Get the size of the index entry. Only indices entries of less
6668166881
** than 2GiB are support - anything large must be database corruption.
6668266882
** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
6668366883
** this code can safely assume that nCellKey is 32-bits
6668466884
*/
@@ -66686,11 +66886,11 @@
6668666886
VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
6668766887
assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
6668866888
assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
6668966889
6669066890
/* Read in the complete content of the index entry */
66691
- memset(&m, 0, sizeof(m));
66891
+ sqlite3VdbeMemInit(&m, db, 0);
6669266892
rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
6669366893
if( rc ){
6669466894
return rc;
6669566895
}
6669666896
@@ -66729,11 +66929,11 @@
6672966929
return SQLITE_OK;
6673066930
6673166931
/* Jump here if database corruption is detected after m has been
6673266932
** allocated. Free the m object and return SQLITE_CORRUPT. */
6673366933
idx_rowid_corruption:
66734
- testcase( m.zMalloc!=0 );
66934
+ testcase( m.szMalloc!=0 );
6673566935
sqlite3VdbeMemRelease(&m);
6673666936
return SQLITE_CORRUPT_BKPT;
6673766937
}
6673866938
6673966939
/*
@@ -66746,10 +66946,11 @@
6674666946
** omits the rowid at the end. The rowid at the end of the index entry
6674766947
** is ignored as well. Hence, this routine only compares the prefixes
6674866948
** of the keys prior to the final rowid, not the entire key.
6674966949
*/
6675066950
SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(
66951
+ sqlite3 *db, /* Database connection */
6675166952
VdbeCursor *pC, /* The cursor to compare against */
6675266953
UnpackedRecord *pUnpacked, /* Unpacked version of key */
6675366954
int *res /* Write the comparison result here */
6675466955
){
6675566956
i64 nCellKey = 0;
@@ -66764,16 +66965,16 @@
6676466965
** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
6676566966
if( nCellKey<=0 || nCellKey>0x7fffffff ){
6676666967
*res = 0;
6676766968
return SQLITE_CORRUPT_BKPT;
6676866969
}
66769
- memset(&m, 0, sizeof(m));
66970
+ sqlite3VdbeMemInit(&m, db, 0);
6677066971
rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m);
6677166972
if( rc ){
6677266973
return rc;
6677366974
}
66774
- *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked, 0);
66975
+ *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
6677566976
sqlite3VdbeMemRelease(&m);
6677666977
return SQLITE_OK;
6677766978
}
6677866979
6677966980
/*
@@ -67083,13 +67284,16 @@
6708367284
6708467285
/**************************** sqlite3_result_ *******************************
6708567286
** The following routines are used by user-defined functions to specify
6708667287
** the function result.
6708767288
**
67088
-** The setStrOrError() funtion calls sqlite3VdbeMemSetStr() to store the
67289
+** The setStrOrError() function calls sqlite3VdbeMemSetStr() to store the
6708967290
** result as a string or blob but if the string or blob is too large, it
6709067291
** then sets the error code to SQLITE_TOOBIG
67292
+**
67293
+** The invokeValueDestructor(P,X) routine invokes destructor function X()
67294
+** on value P is not going to be used and need to be destroyed.
6709167295
*/
6709267296
static void setResultStrOrError(
6709367297
sqlite3_context *pCtx, /* Function context */
6709467298
const char *z, /* String pointer */
6709567299
int n, /* Bytes in string, or negative */
@@ -67097,10 +67301,26 @@
6709767301
void (*xDel)(void*) /* Destructor function */
6709867302
){
6709967303
if( sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel)==SQLITE_TOOBIG ){
6710067304
sqlite3_result_error_toobig(pCtx);
6710167305
}
67306
+}
67307
+static int invokeValueDestructor(
67308
+ const void *p, /* Value to destroy */
67309
+ void (*xDel)(void*), /* The destructor */
67310
+ sqlite3_context *pCtx /* Set a SQLITE_TOOBIG error if no NULL */
67311
+){
67312
+ assert( xDel!=SQLITE_DYNAMIC );
67313
+ if( xDel==0 ){
67314
+ /* noop */
67315
+ }else if( xDel==SQLITE_TRANSIENT ){
67316
+ /* noop */
67317
+ }else{
67318
+ xDel((void*)p);
67319
+ }
67320
+ if( pCtx ) sqlite3_result_error_toobig(pCtx);
67321
+ return SQLITE_TOOBIG;
6710267322
}
6710367323
SQLITE_API void sqlite3_result_blob(
6710467324
sqlite3_context *pCtx,
6710567325
const void *z,
6710667326
int n,
@@ -67107,10 +67327,24 @@
6710767327
void (*xDel)(void *)
6710867328
){
6710967329
assert( n>=0 );
6711067330
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
6711167331
setResultStrOrError(pCtx, z, n, 0, xDel);
67332
+}
67333
+SQLITE_API void sqlite3_result_blob64(
67334
+ sqlite3_context *pCtx,
67335
+ const void *z,
67336
+ sqlite3_uint64 n,
67337
+ void (*xDel)(void *)
67338
+){
67339
+ assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
67340
+ assert( xDel!=SQLITE_DYNAMIC );
67341
+ if( n>0x7fffffff ){
67342
+ (void)invokeValueDestructor(z, xDel, pCtx);
67343
+ }else{
67344
+ setResultStrOrError(pCtx, z, (int)n, 0, xDel);
67345
+ }
6711267346
}
6711367347
SQLITE_API void sqlite3_result_double(sqlite3_context *pCtx, double rVal){
6711467348
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
6711567349
sqlite3VdbeMemSetDouble(pCtx->pOut, rVal);
6711667350
}
@@ -67146,10 +67380,25 @@
6714667380
int n,
6714767381
void (*xDel)(void *)
6714867382
){
6714967383
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
6715067384
setResultStrOrError(pCtx, z, n, SQLITE_UTF8, xDel);
67385
+}
67386
+SQLITE_API void sqlite3_result_text64(
67387
+ sqlite3_context *pCtx,
67388
+ const char *z,
67389
+ sqlite3_uint64 n,
67390
+ void (*xDel)(void *),
67391
+ unsigned char enc
67392
+){
67393
+ assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
67394
+ assert( xDel!=SQLITE_DYNAMIC );
67395
+ if( n>0x7fffffff ){
67396
+ (void)invokeValueDestructor(z, xDel, pCtx);
67397
+ }else{
67398
+ setResultStrOrError(pCtx, z, (int)n, enc, xDel);
67399
+ }
6715167400
}
6715267401
#ifndef SQLITE_OMIT_UTF16
6715367402
SQLITE_API void sqlite3_result_text16(
6715467403
sqlite3_context *pCtx,
6715567404
const void *z,
@@ -67485,15 +67734,14 @@
6748567734
*/
6748667735
static SQLITE_NOINLINE void *createAggContext(sqlite3_context *p, int nByte){
6748767736
Mem *pMem = p->pMem;
6748867737
assert( (pMem->flags & MEM_Agg)==0 );
6748967738
if( nByte<=0 ){
67490
- sqlite3VdbeMemReleaseExternal(pMem);
67491
- pMem->flags = MEM_Null;
67739
+ sqlite3VdbeMemSetNull(pMem);
6749267740
pMem->z = 0;
6749367741
}else{
67494
- sqlite3VdbeMemGrow(pMem, nByte, 0);
67742
+ sqlite3VdbeMemClearAndResize(pMem, nByte);
6749567743
pMem->flags = MEM_Agg;
6749667744
pMem->u.pDef = p->pFunc;
6749767745
if( pMem->z ){
6749867746
memset(pMem->z, 0, nByte);
6749967747
}
@@ -67516,11 +67764,11 @@
6751667764
return (void*)p->pMem->z;
6751767765
}
6751867766
}
6751967767
6752067768
/*
67521
-** Return the auxilary data pointer, if any, for the iArg'th argument to
67769
+** Return the auxiliary data pointer, if any, for the iArg'th argument to
6752267770
** the user-function defined by pCtx.
6752367771
*/
6752467772
SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
6752567773
AuxData *pAuxData;
6752667774
@@ -67531,11 +67779,11 @@
6753167779
6753267780
return (pAuxData ? pAuxData->pAux : 0);
6753367781
}
6753467782
6753567783
/*
67536
-** Set the auxilary data pointer and delete function, for the iArg'th
67784
+** Set the auxiliary data pointer and delete function, for the iArg'th
6753767785
** argument to the user-function defined by pCtx. Any previous value is
6753867786
** deleted by calling the delete function specified when it was set.
6753967787
*/
6754067788
SQLITE_API void sqlite3_set_auxdata(
6754167789
sqlite3_context *pCtx,
@@ -67577,11 +67825,11 @@
6757767825
}
6757867826
}
6757967827
6758067828
#ifndef SQLITE_OMIT_DEPRECATED
6758167829
/*
67582
-** Return the number of times the Step function of a aggregate has been
67830
+** Return the number of times the Step function of an aggregate has been
6758367831
** called.
6758467832
**
6758567833
** This function is deprecated. Do not use it for new code. It is
6758667834
** provide only to avoid breaking legacy code. New aggregate function
6758767835
** implementations should keep their own counts within their aggregate
@@ -67626,15 +67874,26 @@
6762667874
** __attribute__((aligned(8))) macro. */
6762767875
static const Mem nullMem
6762867876
#if defined(SQLITE_DEBUG) && defined(__GNUC__)
6762967877
__attribute__((aligned(8)))
6763067878
#endif
67631
- = {0, "", (double)0, {0}, 0, MEM_Null, 0,
67879
+ = {
67880
+ /* .u = */ {0},
67881
+ /* .flags = */ MEM_Null,
67882
+ /* .enc = */ 0,
67883
+ /* .n = */ 0,
67884
+ /* .z = */ 0,
67885
+ /* .zMalloc = */ 0,
67886
+ /* .szMalloc = */ 0,
67887
+ /* .iPadding1 = */ 0,
67888
+ /* .db = */ 0,
67889
+ /* .xDel = */ 0,
6763267890
#ifdef SQLITE_DEBUG
67633
- 0, 0, /* pScopyFrom, pFiller */
67891
+ /* .pScopyFrom = */ 0,
67892
+ /* .pFiller = */ 0,
6763467893
#endif
67635
- 0, 0 };
67894
+ };
6763667895
return &nullMem;
6763767896
}
6763867897
6763967898
/*
6764067899
** Check to see if column iCol of the given statement is valid. If
@@ -67847,11 +68106,11 @@
6784768106
6784868107
#ifdef SQLITE_ENABLE_COLUMN_METADATA
6784968108
/*
6785068109
** Return the name of the database from which a result column derives.
6785168110
** NULL is returned if the result column is an expression or constant or
67852
-** anything else which is not an unabiguous reference to a database column.
68111
+** anything else which is not an unambiguous reference to a database column.
6785368112
*/
6785468113
SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
6785568114
return columnName(
6785668115
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
6785768116
}
@@ -67863,11 +68122,11 @@
6786368122
#endif /* SQLITE_OMIT_UTF16 */
6786468123
6786568124
/*
6786668125
** Return the name of the table from which a result column derives.
6786768126
** NULL is returned if the result column is an expression or constant or
67868
-** anything else which is not an unabiguous reference to a database column.
68127
+** anything else which is not an unambiguous reference to a database column.
6786968128
*/
6787068129
SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
6787168130
return columnName(
6787268131
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
6787368132
}
@@ -67879,11 +68138,11 @@
6787968138
#endif /* SQLITE_OMIT_UTF16 */
6788068139
6788168140
/*
6788268141
** Return the name of the table column from which a result column derives.
6788368142
** NULL is returned if the result column is an expression or constant or
67884
-** anything else which is not an unabiguous reference to a database column.
68143
+** anything else which is not an unambiguous reference to a database column.
6788568144
*/
6788668145
SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
6788768146
return columnName(
6788868147
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
6788968148
}
@@ -67995,10 +68254,24 @@
6799568254
const void *zData,
6799668255
int nData,
6799768256
void (*xDel)(void*)
6799868257
){
6799968258
return bindText(pStmt, i, zData, nData, xDel, 0);
68259
+}
68260
+SQLITE_API int sqlite3_bind_blob64(
68261
+ sqlite3_stmt *pStmt,
68262
+ int i,
68263
+ const void *zData,
68264
+ sqlite3_uint64 nData,
68265
+ void (*xDel)(void*)
68266
+){
68267
+ assert( xDel!=SQLITE_DYNAMIC );
68268
+ if( nData>0x7fffffff ){
68269
+ return invokeValueDestructor(zData, xDel, 0);
68270
+ }else{
68271
+ return bindText(pStmt, i, zData, (int)nData, xDel, 0);
68272
+ }
6800068273
}
6800168274
SQLITE_API int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
6800268275
int rc;
6800368276
Vdbe *p = (Vdbe *)pStmt;
6800468277
rc = vdbeUnbind(p, i);
@@ -68036,10 +68309,26 @@
6803668309
const char *zData,
6803768310
int nData,
6803868311
void (*xDel)(void*)
6803968312
){
6804068313
return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
68314
+}
68315
+SQLITE_API int sqlite3_bind_text64(
68316
+ sqlite3_stmt *pStmt,
68317
+ int i,
68318
+ const char *zData,
68319
+ sqlite3_uint64 nData,
68320
+ void (*xDel)(void*),
68321
+ unsigned char enc
68322
+){
68323
+ assert( xDel!=SQLITE_DYNAMIC );
68324
+ if( nData>0x7fffffff ){
68325
+ return invokeValueDestructor(zData, xDel, 0);
68326
+ }else{
68327
+ if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE;
68328
+ return bindText(pStmt, i, zData, (int)nData, xDel, enc);
68329
+ }
6804168330
}
6804268331
#ifndef SQLITE_OMIT_UTF16
6804368332
SQLITE_API int sqlite3_bind_text16(
6804468333
sqlite3_stmt *pStmt,
6804568334
int i,
@@ -68056,11 +68345,11 @@
6805668345
case SQLITE_INTEGER: {
6805768346
rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
6805868347
break;
6805968348
}
6806068349
case SQLITE_FLOAT: {
68061
- rc = sqlite3_bind_double(pStmt, i, pValue->r);
68350
+ rc = sqlite3_bind_double(pStmt, i, pValue->u.r);
6806268351
break;
6806368352
}
6806468353
case SQLITE_BLOB: {
6806568354
if( pValue->flags & MEM_Zero ){
6806668355
rc = sqlite3_bind_zeroblob(pStmt, i, pValue->u.nZero);
@@ -68159,11 +68448,11 @@
6815968448
#ifndef SQLITE_OMIT_DEPRECATED
6816068449
/*
6816168450
** Deprecated external interface. Internal/core SQLite code
6816268451
** should call sqlite3TransferBindings.
6816368452
**
68164
-** Is is misuse to call this routine with statements from different
68453
+** It is misuse to call this routine with statements from different
6816568454
** database connections. But as this is a deprecated interface, we
6816668455
** will not bother to check for that condition.
6816768456
**
6816868457
** If the two statements contain a different number of bindings, then
6816968458
** an SQLITE_ERROR is returned. Nothing else can go wrong, so otherwise
@@ -68303,11 +68592,11 @@
6830368592
** is eventually freed.
6830468593
**
6830568594
** ALGORITHM: Scan the input string looking for host parameters in any of
6830668595
** these forms: ?, ?N, $A, @A, :A. Take care to avoid text within
6830768596
** string literals, quoted identifier names, and comments. For text forms,
68308
-** the host parameter index is found by scanning the perpared
68597
+** the host parameter index is found by scanning the prepared
6830968598
** statement for the corresponding OP_Variable opcode. Once the host
6831068599
** parameter index is known, locate the value in p->aVar[]. Then render
6831168600
** the value as a literal in place of the host parameter name.
6831268601
*/
6831368602
SQLITE_PRIVATE char *sqlite3VdbeExpandSql(
@@ -68366,11 +68655,11 @@
6836668655
if( pVar->flags & MEM_Null ){
6836768656
sqlite3StrAccumAppend(&out, "NULL", 4);
6836868657
}else if( pVar->flags & MEM_Int ){
6836968658
sqlite3XPrintf(&out, 0, "%lld", pVar->u.i);
6837068659
}else if( pVar->flags & MEM_Real ){
68371
- sqlite3XPrintf(&out, 0, "%!.15g", pVar->r);
68660
+ sqlite3XPrintf(&out, 0, "%!.15g", pVar->u.r);
6837268661
}else if( pVar->flags & MEM_Str ){
6837368662
int nOut; /* Number of bytes of the string text to include in output */
6837468663
#ifndef SQLITE_OMIT_UTF16
6837568664
u8 enc = ENC(db);
6837668665
Mem utf8;
@@ -68749,11 +69038,11 @@
6874969038
assert( iCur<p->nCursor );
6875069039
if( p->apCsr[iCur] ){
6875169040
sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
6875269041
p->apCsr[iCur] = 0;
6875369042
}
68754
- if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){
69043
+ if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
6875569044
p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
6875669045
memset(pCx, 0, sizeof(VdbeCursor));
6875769046
pCx->iDb = iDb;
6875869047
pCx->nField = nField;
6875969048
if( isBtreeCursor ){
@@ -68782,17 +69071,17 @@
6878269071
*/
6878369072
static void applyNumericAffinity(Mem *pRec, int bTryForInt){
6878469073
double rValue;
6878569074
i64 iValue;
6878669075
u8 enc = pRec->enc;
68787
- if( (pRec->flags&MEM_Str)==0 ) return;
69076
+ assert( (pRec->flags & (MEM_Str|MEM_Int|MEM_Real))==MEM_Str );
6878869077
if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return;
6878969078
if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
6879069079
pRec->u.i = iValue;
6879169080
pRec->flags |= MEM_Int;
6879269081
}else{
68793
- pRec->r = rValue;
69082
+ pRec->u.r = rValue;
6879469083
pRec->flags |= MEM_Real;
6879569084
if( bTryForInt ) sqlite3VdbeIntegerAffinity(pRec);
6879669085
}
6879769086
}
6879869087
@@ -68817,28 +69106,28 @@
6881769106
static void applyAffinity(
6881869107
Mem *pRec, /* The value to apply affinity to */
6881969108
char affinity, /* The affinity to be applied */
6882069109
u8 enc /* Use this text encoding */
6882169110
){
68822
- if( affinity==SQLITE_AFF_TEXT ){
69111
+ if( affinity>=SQLITE_AFF_NUMERIC ){
69112
+ assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
69113
+ || affinity==SQLITE_AFF_NUMERIC );
69114
+ if( (pRec->flags & MEM_Int)==0 ){
69115
+ if( (pRec->flags & MEM_Real)==0 ){
69116
+ if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
69117
+ }else{
69118
+ sqlite3VdbeIntegerAffinity(pRec);
69119
+ }
69120
+ }
69121
+ }else if( affinity==SQLITE_AFF_TEXT ){
6882369122
/* Only attempt the conversion to TEXT if there is an integer or real
6882469123
** representation (blob and NULL do not get converted) but no string
6882569124
** representation.
6882669125
*/
6882769126
if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
6882869127
sqlite3VdbeMemStringify(pRec, enc, 1);
6882969128
}
68830
- }else if( affinity!=SQLITE_AFF_NONE ){
68831
- assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
68832
- || affinity==SQLITE_AFF_NUMERIC );
68833
- if( (pRec->flags & MEM_Int)==0 ){
68834
- if( (pRec->flags & MEM_Real)==0 ){
68835
- applyNumericAffinity(pRec,1);
68836
- }else{
68837
- sqlite3VdbeIntegerAffinity(pRec);
68838
- }
68839
- }
6884069129
}
6884169130
}
6884269131
6884369132
/*
6884469133
** Try to convert the type of a function argument or a result column
@@ -68869,17 +69158,17 @@
6886969158
}
6887069159
6887169160
/*
6887269161
** pMem currently only holds a string type (or maybe a BLOB that we can
6887369162
** interpret as a string if we want to). Compute its corresponding
68874
-** numeric type, if has one. Set the pMem->r and pMem->u.i fields
69163
+** numeric type, if has one. Set the pMem->u.r and pMem->u.i fields
6887569164
** accordingly.
6887669165
*/
6887769166
static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){
6887869167
assert( (pMem->flags & (MEM_Int|MEM_Real))==0 );
6887969168
assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
68880
- if( sqlite3AtoF(pMem->z, &pMem->r, pMem->n, pMem->enc)==0 ){
69169
+ if( sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc)==0 ){
6888169170
return 0;
6888269171
}
6888369172
if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==SQLITE_OK ){
6888469173
return MEM_Int;
6888569174
}
@@ -68889,11 +69178,11 @@
6888969178
/*
6889069179
** Return the numeric type for pMem, either MEM_Int or MEM_Real or both or
6889169180
** none.
6889269181
**
6889369182
** Unlike applyNumericAffinity(), this routine does not modify pMem->flags.
68894
-** But it does set pMem->r and pMem->u.i appropriately.
69183
+** But it does set pMem->u.r and pMem->u.i appropriately.
6889569184
*/
6889669185
static u16 numericType(Mem *pMem){
6889769186
if( pMem->flags & (MEM_Int|MEM_Real) ){
6889869187
return pMem->flags & (MEM_Int|MEM_Real);
6889969188
}
@@ -68999,11 +69288,11 @@
6899969288
printf(" si:%lld", p->u.i);
6900069289
}else if( p->flags & MEM_Int ){
6900169290
printf(" i:%lld", p->u.i);
6900269291
#ifndef SQLITE_OMIT_FLOATING_POINT
6900369292
}else if( p->flags & MEM_Real ){
69004
- printf(" r:%g", p->r);
69293
+ printf(" r:%g", p->u.r);
6900569294
#endif
6900669295
}else if( p->flags & MEM_RowSet ){
6900769296
printf(" (rowset)");
6900869297
}else{
6900969298
char zBuf[200];
@@ -69269,11 +69558,11 @@
6926969558
if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){
6927069559
assert( pOp->p2>0 );
6927169560
assert( pOp->p2<=(p->nMem-p->nCursor) );
6927269561
pOut = &aMem[pOp->p2];
6927369562
memAboutToChange(p, pOut);
69274
- VdbeMemReleaseExtern(pOut);
69563
+ if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
6927569564
pOut->flags = MEM_Int;
6927669565
}
6927769566
6927869567
/* Sanity checking on other operands */
6927969568
#ifdef SQLITE_DEBUG
@@ -69631,11 +69920,11 @@
6963169920
** Write that value into register P2.
6963269921
*/
6963369922
case OP_Real: { /* same as TK_FLOAT, out2-prerelease */
6963469923
pOut->flags = MEM_Real;
6963569924
assert( !sqlite3IsNaN(*pOp->p4.pReal) );
69636
- pOut->r = *pOp->p4.pReal;
69925
+ pOut->u.r = *pOp->p4.pReal;
6963769926
break;
6963869927
}
6963969928
#endif
6964069929
6964169930
/* Opcode: String8 * P2 * P4 *
@@ -69654,13 +69943,13 @@
6965469943
#ifndef SQLITE_OMIT_UTF16
6965569944
if( encoding!=SQLITE_UTF8 ){
6965669945
rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
6965769946
if( rc==SQLITE_TOOBIG ) goto too_big;
6965869947
if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
69659
- assert( pOut->zMalloc==pOut->z );
69948
+ assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
6966069949
assert( VdbeMemDynamic(pOut)==0 );
69661
- pOut->zMalloc = 0;
69950
+ pOut->szMalloc = 0;
6966269951
pOut->flags |= MEM_Static;
6966369952
if( pOp->p4type==P4_DYNAMIC ){
6966469953
sqlite3DbFree(db, pOp->p4.z);
6966569954
}
6966669955
pOp->p4type = P4_DYNAMIC;
@@ -69708,11 +69997,11 @@
6970869997
assert( pOp->p3<=(p->nMem-p->nCursor) );
6970969998
pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
6971069999
while( cnt>0 ){
6971170000
pOut++;
6971270001
memAboutToChange(p, pOut);
69713
- VdbeMemReleaseExtern(pOut);
70002
+ sqlite3VdbeMemSetNull(pOut);
6971470003
pOut->flags = nullFlag;
6971570004
cnt--;
6971670005
}
6971770006
break;
6971870007
}
@@ -69776,11 +70065,10 @@
6977670065
** left holding a NULL. It is an error for register ranges
6977770066
** P1..P1+P3-1 and P2..P2+P3-1 to overlap. It is an error
6977870067
** for P3 to be less than 1.
6977970068
*/
6978070069
case OP_Move: {
69781
- char *zMalloc; /* Holding variable for allocated memory */
6978270070
int n; /* Number of registers left to copy */
6978370071
int p1; /* Register to copy from */
6978470072
int p2; /* Register to copy to */
6978570073
6978670074
n = pOp->p3;
@@ -69794,21 +70082,16 @@
6979470082
do{
6979570083
assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
6979670084
assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
6979770085
assert( memIsValid(pIn1) );
6979870086
memAboutToChange(p, pOut);
69799
- sqlite3VdbeMemRelease(pOut);
69800
- zMalloc = pOut->zMalloc;
69801
- memcpy(pOut, pIn1, sizeof(Mem));
70087
+ sqlite3VdbeMemMove(pOut, pIn1);
6980270088
#ifdef SQLITE_DEBUG
6980370089
if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
6980470090
pOut->pScopyFrom += p1 - pOp->p2;
6980570091
}
6980670092
#endif
69807
- pIn1->flags = MEM_Undefined;
69808
- pIn1->xDel = 0;
69809
- pIn1->zMalloc = zMalloc;
6981070093
REGISTER_TRACE(p2++, pOut);
6981170094
pIn1++;
6981270095
pOut++;
6981370096
}while( --n );
6981470097
break;
@@ -70109,11 +70392,11 @@
7010970392
MemSetTypeFlag(pOut, MEM_Int);
7011070393
#else
7011170394
if( sqlite3IsNaN(rB) ){
7011270395
goto arithmetic_result_is_null;
7011370396
}
70114
- pOut->r = rB;
70397
+ pOut->u.r = rB;
7011570398
MemSetTypeFlag(pOut, MEM_Real);
7011670399
if( ((type1|type2)&MEM_Real)==0 && !bIntint ){
7011770400
sqlite3VdbeIntegerAffinity(pOut);
7011870401
}
7011970402
#endif
@@ -70384,11 +70667,11 @@
7038470667
** </ul>
7038570668
**
7038670669
** A NULL value is not changed by this routine. It remains NULL.
7038770670
*/
7038870671
case OP_Cast: { /* in1 */
70389
- assert( pOp->p2>=SQLITE_AFF_TEXT && pOp->p2<=SQLITE_AFF_REAL );
70672
+ assert( pOp->p2>=SQLITE_AFF_NONE && pOp->p2<=SQLITE_AFF_REAL );
7039070673
testcase( pOp->p2==SQLITE_AFF_TEXT );
7039170674
testcase( pOp->p2==SQLITE_AFF_NONE );
7039270675
testcase( pOp->p2==SQLITE_AFF_NUMERIC );
7039370676
testcase( pOp->p2==SQLITE_AFF_INTEGER );
7039470677
testcase( pOp->p2==SQLITE_AFF_REAL );
@@ -70534,19 +70817,39 @@
7053470817
break;
7053570818
}
7053670819
}else{
7053770820
/* Neither operand is NULL. Do a comparison. */
7053870821
affinity = pOp->p5 & SQLITE_AFF_MASK;
70539
- if( affinity ){
70540
- applyAffinity(pIn1, affinity, encoding);
70541
- applyAffinity(pIn3, affinity, encoding);
70542
- if( db->mallocFailed ) goto no_mem;
70822
+ if( affinity>=SQLITE_AFF_NUMERIC ){
70823
+ if( (pIn1->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
70824
+ applyNumericAffinity(pIn1,0);
70825
+ }
70826
+ if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
70827
+ applyNumericAffinity(pIn3,0);
70828
+ }
70829
+ }else if( affinity==SQLITE_AFF_TEXT ){
70830
+ if( (pIn1->flags & MEM_Str)==0 && (pIn1->flags & (MEM_Int|MEM_Real))!=0 ){
70831
+ testcase( pIn1->flags & MEM_Int );
70832
+ testcase( pIn1->flags & MEM_Real );
70833
+ sqlite3VdbeMemStringify(pIn1, encoding, 1);
70834
+ }
70835
+ if( (pIn3->flags & MEM_Str)==0 && (pIn3->flags & (MEM_Int|MEM_Real))!=0 ){
70836
+ testcase( pIn3->flags & MEM_Int );
70837
+ testcase( pIn3->flags & MEM_Real );
70838
+ sqlite3VdbeMemStringify(pIn3, encoding, 1);
70839
+ }
7054370840
}
70544
-
7054570841
assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
70546
- ExpandBlob(pIn1);
70547
- ExpandBlob(pIn3);
70842
+ if( pIn1->flags & MEM_Zero ){
70843
+ sqlite3VdbeMemExpandBlob(pIn1);
70844
+ flags1 &= ~MEM_Zero;
70845
+ }
70846
+ if( pIn3->flags & MEM_Zero ){
70847
+ sqlite3VdbeMemExpandBlob(pIn3);
70848
+ flags3 &= ~MEM_Zero;
70849
+ }
70850
+ if( db->mallocFailed ) goto no_mem;
7054870851
res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
7054970852
}
7055070853
switch( pOp->opcode ){
7055170854
case OP_Eq: res = res==0; break;
7055270855
case OP_Ne: res = res!=0; break;
@@ -70567,12 +70870,12 @@
7056770870
if( res ){
7056870871
pc = pOp->p2-1;
7056970872
}
7057070873
}
7057170874
/* Undo any changes made by applyAffinity() to the input registers. */
70572
- pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask);
70573
- pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask);
70875
+ pIn1->flags = flags1;
70876
+ pIn3->flags = flags3;
7057470877
break;
7057570878
}
7057670879
7057770880
/* Opcode: Permutation * * * P4 *
7057870881
**
@@ -70736,14 +71039,14 @@
7073671039
** NULL, then a NULL is stored in P2.
7073771040
*/
7073871041
case OP_Not: { /* same as TK_NOT, in1, out2 */
7073971042
pIn1 = &aMem[pOp->p1];
7074071043
pOut = &aMem[pOp->p2];
70741
- if( pIn1->flags & MEM_Null ){
70742
- sqlite3VdbeMemSetNull(pOut);
70743
- }else{
70744
- sqlite3VdbeMemSetInt64(pOut, !sqlite3VdbeIntValue(pIn1));
71044
+ sqlite3VdbeMemSetNull(pOut);
71045
+ if( (pIn1->flags & MEM_Null)==0 ){
71046
+ pOut->flags = MEM_Int;
71047
+ pOut->u.i = !sqlite3VdbeIntValue(pIn1);
7074571048
}
7074671049
break;
7074771050
}
7074871051
7074971052
/* Opcode: BitNot P1 P2 * * *
@@ -70754,14 +71057,14 @@
7075471057
** a NULL then store a NULL in P2.
7075571058
*/
7075671059
case OP_BitNot: { /* same as TK_BITNOT, in1, out2 */
7075771060
pIn1 = &aMem[pOp->p1];
7075871061
pOut = &aMem[pOp->p2];
70759
- if( pIn1->flags & MEM_Null ){
70760
- sqlite3VdbeMemSetNull(pOut);
70761
- }else{
70762
- sqlite3VdbeMemSetInt64(pOut, ~sqlite3VdbeIntValue(pIn1));
71062
+ sqlite3VdbeMemSetNull(pOut);
71063
+ if( (pIn1->flags & MEM_Null)==0 ){
71064
+ pOut->flags = MEM_Int;
71065
+ pOut->u.i = ~sqlite3VdbeIntValue(pIn1);
7076371066
}
7076471067
break;
7076571068
}
7076671069
7076771070
/* Opcode: Once P1 P2 * * *
@@ -70875,11 +71178,10 @@
7087571178
case OP_Column: {
7087671179
i64 payloadSize64; /* Number of bytes in the record */
7087771180
int p2; /* column number to retrieve */
7087871181
VdbeCursor *pC; /* The VDBE cursor */
7087971182
BtCursor *pCrsr; /* The BTree cursor */
70880
- u32 *aType; /* aType[i] holds the numeric type of the i-th column */
7088171183
u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
7088271184
int len; /* The length of the serialized data for the column */
7088371185
int i; /* Loop counter */
7088471186
Mem *pDest; /* Where to write the extracted value */
7088571187
Mem sMem; /* For storing the record being decoded */
@@ -70888,10 +71190,11 @@
7088871190
const u8 *zEndHdr; /* Pointer to first byte after the header */
7088971191
u32 offset; /* Offset into the data */
7089071192
u32 szField; /* Number of bytes in the content of a field */
7089171193
u32 avail; /* Number of bytes of available data */
7089271194
u32 t; /* A type code from the record header */
71195
+ u16 fx; /* pDest->flags value */
7089371196
Mem *pReg; /* PseudoTable input register */
7089471197
7089571198
p2 = pOp->p2;
7089671199
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
7089771200
pDest = &aMem[pOp->p3];
@@ -70898,12 +71201,11 @@
7089871201
memAboutToChange(p, pDest);
7089971202
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7090071203
pC = p->apCsr[pOp->p1];
7090171204
assert( pC!=0 );
7090271205
assert( p2<pC->nField );
70903
- aType = pC->aType;
70904
- aOffset = aType + pC->nField;
71206
+ aOffset = pC->aType + pC->nField;
7090571207
#ifndef SQLITE_OMIT_VIRTUALTABLE
7090671208
assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
7090771209
#endif
7090871210
pCrsr = pC->pCursor;
7090971211
assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
@@ -70980,11 +71282,11 @@
7098071282
goto op_column_error;
7098171283
}
7098271284
}
7098371285
7098471286
/* Make sure at least the first p2+1 entries of the header have been
70985
- ** parsed and valid information is in aOffset[] and aType[].
71287
+ ** parsed and valid information is in aOffset[] and pC->aType[].
7098671288
*/
7098771289
if( pC->nHdrParsed<=p2 ){
7098871290
/* If there is more header available for parsing in the record, try
7098971291
** to extract additional fields up through the p2+1-th field
7099071292
*/
@@ -71000,11 +71302,11 @@
7100071302
zData = (u8*)sMem.z;
7100171303
}else{
7100271304
zData = pC->aRow;
7100371305
}
7100471306
71005
- /* Fill in aType[i] and aOffset[i] values through the p2-th field. */
71307
+ /* Fill in pC->aType[i] and aOffset[i] values through the p2-th field. */
7100671308
i = pC->nHdrParsed;
7100771309
offset = aOffset[i];
7100871310
zHdr = zData + pC->iHdrOffset;
7100971311
zEndHdr = zData + aOffset[0];
7101071312
assert( i<=p2 && zHdr<zEndHdr );
@@ -71013,11 +71315,11 @@
7101371315
t = zHdr[0];
7101471316
zHdr++;
7101571317
}else{
7101671318
zHdr += sqlite3GetVarint32(zHdr, &t);
7101771319
}
71018
- aType[i] = t;
71320
+ pC->aType[i] = t;
7101971321
szField = sqlite3VdbeSerialTypeLen(t);
7102071322
offset += szField;
7102171323
if( offset<szField ){ /* True if offset overflows */
7102271324
zHdr = &zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
7102371325
break;
@@ -71060,65 +71362,65 @@
7106071362
goto op_column_out;
7106171363
}
7106271364
}
7106371365
7106471366
/* Extract the content for the p2+1-th column. Control can only
71065
- ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
71367
+ ** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are
7106671368
** all valid.
7106771369
*/
7106871370
assert( p2<pC->nHdrParsed );
7106971371
assert( rc==SQLITE_OK );
7107071372
assert( sqlite3VdbeCheckMemInvariants(pDest) );
71373
+ if( VdbeMemDynamic(pDest) ) sqlite3VdbeMemSetNull(pDest);
71374
+ t = pC->aType[p2];
7107171375
if( pC->szRow>=aOffset[p2+1] ){
7107271376
/* This is the common case where the desired content fits on the original
7107371377
** page - where the content is not on an overflow page */
71074
- VdbeMemReleaseExtern(pDest);
71075
- sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
71378
+ sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], t, pDest);
7107671379
}else{
7107771380
/* This branch happens only when content is on overflow pages */
71078
- t = aType[p2];
7107971381
if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
7108071382
&& ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
7108171383
|| (len = sqlite3VdbeSerialTypeLen(t))==0
7108271384
){
71083
- /* Content is irrelevant for the typeof() function and for
71084
- ** the length(X) function if X is a blob. So we might as well use
71085
- ** bogus content rather than reading content from disk. NULL works
71086
- ** for text and blob and whatever is in the payloadSize64 variable
71087
- ** will work for everything else. Content is also irrelevant if
71088
- ** the content length is 0. */
71089
- zData = t<=13 ? (u8*)&payloadSize64 : 0;
71090
- sMem.zMalloc = 0;
71385
+ /* Content is irrelevant for
71386
+ ** 1. the typeof() function,
71387
+ ** 2. the length(X) function if X is a blob, and
71388
+ ** 3. if the content length is zero.
71389
+ ** So we might as well use bogus content rather than reading
71390
+ ** content from disk. NULL will work for the value for strings
71391
+ ** and blobs and whatever is in the payloadSize64 variable
71392
+ ** will work for everything else. */
71393
+ sqlite3VdbeSerialGet(t<=13 ? (u8*)&payloadSize64 : 0, t, pDest);
7109171394
}else{
71092
- memset(&sMem, 0, sizeof(sMem));
71093
- sqlite3VdbeMemMove(&sMem, pDest);
7109471395
rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable,
71095
- &sMem);
71396
+ pDest);
7109671397
if( rc!=SQLITE_OK ){
7109771398
goto op_column_error;
7109871399
}
71099
- zData = (u8*)sMem.z;
71100
- }
71101
- sqlite3VdbeSerialGet(zData, t, pDest);
71102
- /* If we dynamically allocated space to hold the data (in the
71103
- ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
71104
- ** dynamically allocated space over to the pDest structure.
71105
- ** This prevents a memory copy. */
71106
- if( sMem.zMalloc ){
71107
- assert( sMem.z==sMem.zMalloc );
71108
- assert( VdbeMemDynamic(pDest)==0 );
71109
- assert( (pDest->flags & (MEM_Blob|MEM_Str))==0 || pDest->z==sMem.z );
71110
- pDest->flags &= ~(MEM_Ephem|MEM_Static);
71111
- pDest->flags |= MEM_Term;
71112
- pDest->z = sMem.z;
71113
- pDest->zMalloc = sMem.zMalloc;
71400
+ sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
71401
+ pDest->flags &= ~MEM_Ephem;
7111471402
}
7111571403
}
7111671404
pDest->enc = encoding;
7111771405
7111871406
op_column_out:
71119
- Deephemeralize(pDest);
71407
+ /* If the column value is an ephemeral string, go ahead and persist
71408
+ ** that string in case the cursor moves before the column value is
71409
+ ** used. The following code does the equivalent of Deephemeralize()
71410
+ ** but does it faster. */
71411
+ if( (pDest->flags & MEM_Ephem)!=0 && pDest->z ){
71412
+ fx = pDest->flags & (MEM_Str|MEM_Blob);
71413
+ assert( fx!=0 );
71414
+ zData = (const u8*)pDest->z;
71415
+ len = pDest->n;
71416
+ if( sqlite3VdbeMemClearAndResize(pDest, len+2) ) goto no_mem;
71417
+ memcpy(pDest->z, zData, len);
71418
+ pDest->z[len] = 0;
71419
+ pDest->z[len+1] = 0;
71420
+ pDest->flags = fx|MEM_Term;
71421
+ }
7112071422
op_column_error:
7112171423
UPDATE_MAX_BLOBSIZE(pDest);
7112271424
REGISTER_TRACE(pOp->p3, pDest);
7112371425
break;
7112471426
}
@@ -71189,11 +71491,11 @@
7118971491
** ------------------------------------------------------------------------
7119071492
** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
7119171493
** ------------------------------------------------------------------------
7119271494
**
7119371495
** Data(0) is taken from register P1. Data(1) comes from register P1+1
71194
- ** and so froth.
71496
+ ** and so forth.
7119571497
**
7119671498
** Each type field is a varint representing the serial type of the
7119771499
** corresponding data element (see sqlite3VdbeSerialType()). The
7119871500
** hdr-size field is also a varint which is the offset from the beginning
7119971501
** of the record to data0.
@@ -71265,13 +71567,13 @@
7126571567
}
7126671568
7126771569
/* Make sure the output register has a buffer large enough to store
7126871570
** the new record. The output register (pOp->p3) is not allowed to
7126971571
** be one of the input registers (because the following call to
71270
- ** sqlite3VdbeMemGrow() could clobber the value before it is used).
71572
+ ** sqlite3VdbeMemClearAndResize() could clobber the value before it is used).
7127171573
*/
71272
- if( sqlite3VdbeMemGrow(pOut, (int)nByte, 0) ){
71574
+ if( sqlite3VdbeMemClearAndResize(pOut, (int)nByte) ){
7127371575
goto no_mem;
7127471576
}
7127571577
zNewRecord = (u8 *)pOut->z;
7127671578
7127771579
/* Write the record */
@@ -71288,11 +71590,10 @@
7128871590
assert( j==nByte );
7128971591
7129071592
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
7129171593
pOut->n = (int)nByte;
7129271594
pOut->flags = MEM_Blob;
71293
- pOut->xDel = 0;
7129471595
if( nZero ){
7129571596
pOut->u.nZero = nZero;
7129671597
pOut->flags |= MEM_Zero;
7129771598
}
7129871599
pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
@@ -72176,13 +72477,13 @@
7217672477
pC->seekOp = pOp->opcode;
7217772478
#endif
7217872479
if( pC->isTable ){
7217972480
/* The input value in P3 might be of any type: integer, real, string,
7218072481
** blob, or NULL. But it needs to be an integer before we can do
72181
- ** the seek, so covert it. */
72482
+ ** the seek, so convert it. */
7218272483
pIn3 = &aMem[pOp->p3];
72183
- if( (pIn3->flags & (MEM_Int|MEM_Real))==0 ){
72484
+ if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
7218472485
applyNumericAffinity(pIn3, 0);
7218572486
}
7218672487
iKey = sqlite3VdbeIntValue(pIn3);
7218772488
pC->rowidIsValid = 0;
7218872489
@@ -72201,20 +72502,20 @@
7220172502
** is 4.9 and the integer approximation 5:
7220272503
**
7220372504
** (x > 4.9) -> (x >= 5)
7220472505
** (x <= 4.9) -> (x < 5)
7220572506
*/
72206
- if( pIn3->r<(double)iKey ){
72507
+ if( pIn3->u.r<(double)iKey ){
7220772508
assert( OP_SeekGE==(OP_SeekGT-1) );
7220872509
assert( OP_SeekLT==(OP_SeekLE-1) );
7220972510
assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) );
7221072511
if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--;
7221172512
}
7221272513
7221372514
/* If the approximation iKey is smaller than the actual real search
7221472515
** term, substitute <= for < and > for >=. */
72215
- else if( pIn3->r>(double)iKey ){
72516
+ else if( pIn3->u.r>(double)iKey ){
7221672517
assert( OP_SeekLE==(OP_SeekLT+1) );
7221772518
assert( OP_SeekGT==(OP_SeekGE+1) );
7221872519
assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
7221972520
if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
7222072521
}
@@ -72972,11 +73273,11 @@
7297273273
assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
7297373274
if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
7297473275
goto too_big;
7297573276
}
7297673277
}
72977
- if( sqlite3VdbeMemGrow(pOut, n, 0) ){
73278
+ if( sqlite3VdbeMemClearAndResize(pOut, n) ){
7297873279
goto no_mem;
7297973280
}
7298073281
pOut->n = n;
7298173282
MemSetTypeFlag(pOut, MEM_Blob);
7298273283
if( pC->isTable==0 ){
@@ -73482,11 +73783,11 @@
7348273783
r.aMem = &aMem[pOp->p3];
7348373784
#ifdef SQLITE_DEBUG
7348473785
{ int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
7348573786
#endif
7348673787
res = 0; /* Not needed. Only used to silence a warning. */
73487
- rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
73788
+ rc = sqlite3VdbeIdxKeyCompare(db, pC, &r, &res);
7348873789
assert( (OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1) );
7348973790
if( (pOp->opcode&1)==(OP_IdxLT&1) ){
7349073791
assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT );
7349173792
res = -res;
7349273793
}else{
@@ -74252,15 +74553,11 @@
7425274553
}
7425374554
ctx.pFunc = pOp->p4.pFunc;
7425474555
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
7425574556
ctx.pMem = pMem = &aMem[pOp->p3];
7425674557
pMem->n++;
74257
- t.flags = MEM_Null;
74258
- t.z = 0;
74259
- t.zMalloc = 0;
74260
- t.xDel = 0;
74261
- t.db = db;
74558
+ sqlite3VdbeMemInit(&t, db, MEM_Null);
7426274559
ctx.pOut = &t;
7426374560
ctx.isError = 0;
7426474561
ctx.pColl = 0;
7426574562
ctx.skipFlag = 0;
7426674563
if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
@@ -76175,12 +76472,15 @@
7617576472
** *pp is undefined in this case.
7617676473
*/
7617776474
static int vdbeSorterMapFile(SortSubtask *pTask, SorterFile *pFile, u8 **pp){
7617876475
int rc = SQLITE_OK;
7617976476
if( pFile->iEof<=(i64)(pTask->pSorter->db->nMaxSorterMmap) ){
76180
- rc = sqlite3OsFetch(pFile->pFd, 0, (int)pFile->iEof, (void**)pp);
76181
- testcase( rc!=SQLITE_OK );
76477
+ sqlite3_file *pFd = pFile->pFd;
76478
+ if( pFd->pMethods->iVersion>=3 ){
76479
+ rc = sqlite3OsFetch(pFd, 0, (int)pFile->iEof, (void**)pp);
76480
+ testcase( rc!=SQLITE_OK );
76481
+ }
7618276482
}
7618376483
return rc;
7618476484
}
7618576485
7618676486
/*
@@ -76331,11 +76631,11 @@
7633176631
){
7633276632
UnpackedRecord *r2 = pTask->pUnpacked;
7633376633
if( pKey2 ){
7633476634
sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
7633576635
}
76336
- return sqlite3VdbeRecordCompare(nKey1, pKey1, r2, 0);
76636
+ return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
7633776637
}
7633876638
7633976639
/*
7634076640
** Initialize the temporary index cursor just opened as a sorter cursor.
7634176641
**
@@ -76694,11 +76994,11 @@
7669476994
**
7669576995
** Whether or not the file does end up memory mapped of course depends on
7669676996
** the specific VFS implementation.
7669776997
*/
7669876998
static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){
76699
- if( nByte<=(i64)(db->nMaxSorterMmap) ){
76999
+ if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){
7670077000
int rc = sqlite3OsTruncate(pFd, nByte);
7670177001
if( rc==SQLITE_OK ){
7670277002
void *p = 0;
7670377003
sqlite3OsFetch(pFd, 0, (int)nByte, &p);
7670477004
sqlite3OsUnfetch(pFd, 0, p);
@@ -77632,11 +77932,11 @@
7763277932
return pRet;
7763377933
}
7763477934
7763577935
/*
7763677936
** Use a background thread to invoke vdbePmaReaderIncrMergeInit(INCRINIT_TASK)
77637
-** on the the PmaReader object passed as the first argument.
77937
+** on the PmaReader object passed as the first argument.
7763877938
**
7763977939
** This call will initialize the various fields of the pReadr->pIncr
7764077940
** structure and, if it is a multi-threaded IncrMerger, launch a
7764177941
** background thread to populate aFile[1].
7764277942
*/
@@ -78031,11 +78331,11 @@
7803178331
SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *pCsr, Mem *pOut){
7803278332
VdbeSorter *pSorter = pCsr->pSorter;
7803378333
void *pKey; int nKey; /* Sorter key to copy into pOut */
7803478334
7803578335
pKey = vdbeSorterRowkey(pSorter, &nKey);
78036
- if( sqlite3VdbeMemGrow(pOut, nKey, 0) ){
78336
+ if( sqlite3VdbeMemClearAndResize(pOut, nKey) ){
7803778337
return SQLITE_NOMEM;
7803878338
}
7803978339
pOut->n = nKey;
7804078340
MemSetTypeFlag(pOut, MEM_Blob);
7804178341
memcpy(pOut->z, pKey, nKey);
@@ -78087,11 +78387,11 @@
7808778387
*pRes = -1;
7808878388
return SQLITE_OK;
7808978389
}
7809078390
}
7809178391
78092
- *pRes = sqlite3VdbeRecordCompare(pVal->n, pVal->z, r2, 0);
78392
+ *pRes = sqlite3VdbeRecordCompare(pVal->n, pVal->z, r2);
7809378393
return SQLITE_OK;
7809478394
}
7809578395
7809678396
/************** End of vdbesort.c ********************************************/
7809778397
/************** Begin file journal.c *****************************************/
@@ -78378,11 +78678,11 @@
7837878678
/* Space to hold the rollback journal is allocated in increments of
7837978679
** this many bytes.
7838078680
**
7838178681
** The size chosen is a little less than a power of two. That way,
7838278682
** the FileChunk object will have a size that almost exactly fills
78383
-** a power-of-two allocation. This mimimizes wasted space in power-of-two
78683
+** a power-of-two allocation. This minimizes wasted space in power-of-two
7838478684
** memory allocators.
7838578685
*/
7838678686
#define JOURNAL_CHUNKSIZE ((int)(1024-sizeof(FileChunk*)))
7838778687
7838878688
/*
@@ -78628,11 +78928,11 @@
7862878928
/* #include <string.h> */
7862978929
7863078930
7863178931
/*
7863278932
** Walk an expression tree. Invoke the callback once for each node
78633
-** of the expression, while decending. (In other words, the callback
78933
+** of the expression, while descending. (In other words, the callback
7863478934
** is invoked before visiting children.)
7863578935
**
7863678936
** The return value from the callback should be one of the WRC_*
7863778937
** constants to specify how to proceed with the walk.
7863878938
**
@@ -79484,13 +79784,11 @@
7948479784
** likelihood(X,0.9375). */
7948579785
/* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
7948679786
pExpr->iTable = pDef->zName[0]=='u' ? 62 : 938;
7948779787
}
7948879788
}
79489
- }
7949079789
#ifndef SQLITE_OMIT_AUTHORIZATION
79491
- if( pDef ){
7949279790
auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
7949379791
if( auth!=SQLITE_OK ){
7949479792
if( auth==SQLITE_DENY ){
7949579793
sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
7949679794
pDef->zName);
@@ -79497,13 +79795,13 @@
7949779795
pNC->nErr++;
7949879796
}
7949979797
pExpr->op = TK_NULL;
7950079798
return WRC_Prune;
7950179799
}
79800
+#endif
7950279801
if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ) ExprSetProperty(pExpr,EP_Constant);
7950379802
}
79504
-#endif
7950579803
if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
7950679804
sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
7950779805
pNC->nErr++;
7950879806
is_agg = 0;
7950979807
}else if( no_such_func && pParse->db->init.busy==0 ){
@@ -79522,11 +79820,17 @@
7952279820
pExpr->op2 = 0;
7952379821
while( pNC2 && !sqlite3FunctionUsesThisSrc(pExpr, pNC2->pSrcList) ){
7952479822
pExpr->op2++;
7952579823
pNC2 = pNC2->pNext;
7952679824
}
79527
- if( pNC2 ) pNC2->ncFlags |= NC_HasAgg;
79825
+ assert( pDef!=0 );
79826
+ if( pNC2 ){
79827
+ assert( SQLITE_FUNC_MINMAX==NC_MinMaxAgg );
79828
+ testcase( (pDef->funcFlags & SQLITE_FUNC_MINMAX)!=0 );
79829
+ pNC2->ncFlags |= NC_HasAgg | (pDef->funcFlags & SQLITE_FUNC_MINMAX);
79830
+
79831
+ }
7952879832
pNC->ncFlags |= NC_AllowAgg;
7952979833
}
7953079834
/* FIX ME: Compute pExpr->affinity based on the expected return
7953179835
** type of the function
7953279836
*/
@@ -79883,11 +80187,11 @@
7988380187
}
7988480188
return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType);
7988580189
}
7988680190
7988780191
/*
79888
-** Resolve names in the SELECT statement p and all of its descendents.
80192
+** Resolve names in the SELECT statement p and all of its descendants.
7988980193
*/
7989080194
static int resolveSelectStep(Walker *pWalker, Select *p){
7989180195
NameContext *pOuterNC; /* Context that contains this SELECT */
7989280196
NameContext sNC; /* Name context of this SELECT */
7989380197
int isCompound; /* True if p is a compound select */
@@ -79987,11 +80291,12 @@
7998780291
** expression, do not allow aggregates in any of the other expressions.
7998880292
*/
7998980293
assert( (p->selFlags & SF_Aggregate)==0 );
7999080294
pGroupBy = p->pGroupBy;
7999180295
if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){
79992
- p->selFlags |= SF_Aggregate;
80296
+ assert( NC_MinMaxAgg==SF_MinMaxAgg );
80297
+ p->selFlags |= SF_Aggregate | (sNC.ncFlags&NC_MinMaxAgg);
7999380298
}else{
7999480299
sNC.ncFlags &= ~NC_AllowAgg;
7999580300
}
7999680301
7999780302
/* If a HAVING clause is present, then there must be a GROUP BY clause.
@@ -80115,11 +80420,11 @@
8011580420
*/
8011680421
SQLITE_PRIVATE int sqlite3ResolveExprNames(
8011780422
NameContext *pNC, /* Namespace to resolve expressions in. */
8011880423
Expr *pExpr /* The expression to be analyzed. */
8011980424
){
80120
- u8 savedHasAgg;
80425
+ u16 savedHasAgg;
8012180426
Walker w;
8012280427
8012380428
if( pExpr==0 ) return 0;
8012480429
#if SQLITE_MAX_EXPR_DEPTH>0
8012580430
{
@@ -80128,12 +80433,12 @@
8012880433
return 1;
8012980434
}
8013080435
pParse->nHeight += pExpr->nHeight;
8013180436
}
8013280437
#endif
80133
- savedHasAgg = pNC->ncFlags & NC_HasAgg;
80134
- pNC->ncFlags &= ~NC_HasAgg;
80438
+ savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg);
80439
+ pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg);
8013580440
memset(&w, 0, sizeof(w));
8013680441
w.xExprCallback = resolveExprStep;
8013780442
w.xSelectCallback = resolveSelectStep;
8013880443
w.pParse = pNC->pParse;
8013980444
w.u.pNC = pNC;
@@ -80144,13 +80449,12 @@
8014480449
if( pNC->nErr>0 || w.pParse->nErr>0 ){
8014580450
ExprSetProperty(pExpr, EP_Error);
8014680451
}
8014780452
if( pNC->ncFlags & NC_HasAgg ){
8014880453
ExprSetProperty(pExpr, EP_Agg);
80149
- }else if( savedHasAgg ){
80150
- pNC->ncFlags |= NC_HasAgg;
8015180454
}
80455
+ pNC->ncFlags |= savedHasAgg;
8015280456
return ExprHasProperty(pExpr, EP_Error);
8015380457
}
8015480458
8015580459
8015680460
/*
@@ -80246,11 +80550,11 @@
8024680550
** If pExpr is a column, a reference to a column via an 'AS' alias,
8024780551
** or a sub-select with a column as the return value, then the
8024880552
** affinity of that column is returned. Otherwise, 0x00 is returned,
8024980553
** indicating no affinity for the expression.
8025080554
**
80251
-** i.e. the WHERE clause expresssions in the following statements all
80555
+** i.e. the WHERE clause expressions in the following statements all
8025280556
** have an affinity:
8025380557
**
8025480558
** CREATE TABLE t1(a);
8025580559
** SELECT * FROM t1 WHERE a;
8025680560
** SELECT a AS b FROM t1 WHERE b;
@@ -80725,11 +81029,11 @@
8072581029
exprSetHeight(pRoot);
8072681030
}
8072781031
}
8072881032
8072981033
/*
80730
-** Allocate a Expr node which joins as many as two subtrees.
81034
+** Allocate an Expr node which joins as many as two subtrees.
8073181035
**
8073281036
** One or both of the subtrees can be NULL. Return a pointer to the new
8073381037
** Expr node. Or, if an OOM error occurs, set pParse->db->mallocFailed,
8073481038
** free the subtrees and return NULL.
8073581039
*/
@@ -80835,11 +81139,11 @@
8083581139
** sure "nnn" is not too be to avoid a denial of service attack when
8083681140
** the SQL statement comes from an external source.
8083781141
**
8083881142
** Wildcards of the form ":aaa", "@aaa", or "$aaa" are assigned the same number
8083981143
** as the previous instance of the same wildcard. Or if this is the first
80840
-** instance of the wildcard, the next sequenial variable number is
81144
+** instance of the wildcard, the next sequential variable number is
8084181145
** assigned.
8084281146
*/
8084381147
SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
8084481148
sqlite3 *db = pParse->db;
8084581149
const char *z;
@@ -80970,11 +81274,11 @@
8097081274
** Note that with flags==EXPRDUP_REDUCE, this routines works on full-size
8097181275
** (unreduced) Expr objects as they or originally constructed by the parser.
8097281276
** During expression analysis, extra information is computed and moved into
8097381277
** later parts of teh Expr object and that extra information might get chopped
8097481278
** off if the expression is reduced. Note also that it does not work to
80975
-** make a EXPRDUP_REDUCE copy of a reduced expression. It is only legal
81279
+** make an EXPRDUP_REDUCE copy of a reduced expression. It is only legal
8097681280
** to reduce a pristine expression tree from the parser. The implementation
8097781281
** of dupedExprStructSize() contain multiple assert() statements that attempt
8097881282
** to enforce this constraint.
8097981283
*/
8098081284
static int dupedExprStructSize(Expr *p, int flags){
@@ -81039,11 +81343,11 @@
8103981343
/*
8104081344
** This function is similar to sqlite3ExprDup(), except that if pzBuffer
8104181345
** is not NULL then *pzBuffer is assumed to point to a buffer large enough
8104281346
** to store the copy of expression p, the copies of p->u.zToken
8104381347
** (if applicable), and the copies of the p->pLeft and p->pRight expressions,
81044
-** if any. Before returning, *pzBuffer is set to the first byte passed the
81348
+** if any. Before returning, *pzBuffer is set to the first byte past the
8104581349
** portion of the buffer copied into by this function.
8104681350
*/
8104781351
static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
8104881352
Expr *pNew = 0; /* Value to return */
8104981353
if( p ){
@@ -81765,11 +82069,11 @@
8176582069
**
8176682070
** SELECT <column> FROM <table>
8176782071
**
8176882072
** If the RHS of the IN operator is a list or a more complex subquery, then
8176982073
** an ephemeral table might need to be generated from the RHS and then
81770
-** pX->iTable made to point to the ephermeral table instead of an
82074
+** pX->iTable made to point to the ephemeral table instead of an
8177182075
** existing table.
8177282076
**
8177382077
** The inFlags parameter must contain exactly one of the bits
8177482078
** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP. If inFlags contains
8177582079
** IN_INDEX_MEMBERSHIP, then the generated table will be used for a
@@ -81895,11 +82199,11 @@
8189582199
8189682200
/* If no preexisting index is available for the IN clause
8189782201
** and IN_INDEX_NOOP is an allowed reply
8189882202
** and the RHS of the IN operator is a list, not a subquery
8189982203
** and the RHS is not contant or has two or fewer terms,
81900
- ** then it is not worth creating an ephermeral table to evaluate
82204
+ ** then it is not worth creating an ephemeral table to evaluate
8190182205
** the IN operator so return IN_INDEX_NOOP.
8190282206
*/
8190382207
if( eType==0
8190482208
&& (inFlags & IN_INDEX_NOOP_OK)
8190582209
&& !ExprHasProperty(pX, EP_xIsSelect)
@@ -82656,20 +82960,13 @@
8265682960
/*
8265782961
** Generate code to move content from registers iFrom...iFrom+nReg-1
8265882962
** over to iTo..iTo+nReg-1. Keep the column cache up-to-date.
8265982963
*/
8266082964
SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse *pParse, int iFrom, int iTo, int nReg){
82661
- int i;
82662
- struct yColCache *p;
8266382965
assert( iFrom>=iTo+nReg || iFrom+nReg<=iTo );
8266482966
sqlite3VdbeAddOp3(pParse->pVdbe, OP_Move, iFrom, iTo, nReg);
82665
- for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
82666
- int x = p->iReg;
82667
- if( x>=iFrom && x<iFrom+nReg ){
82668
- p->iReg += iTo-iFrom;
82669
- }
82670
- }
82967
+ sqlite3ExprCacheRemove(pParse, iFrom, nReg);
8267182968
}
8267282969
8267382970
#if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
8267482971
/*
8267582972
** Return true if any register in the range iFrom..iTo (inclusive)
@@ -82982,11 +83279,11 @@
8298283279
sqlite3ErrorMsg(pParse, "unknown function: %.*s()", nId, zId);
8298383280
break;
8298483281
}
8298583282
8298683283
/* Attempt a direct implementation of the built-in COALESCE() and
82987
- ** IFNULL() functions. This avoids unnecessary evalation of
83284
+ ** IFNULL() functions. This avoids unnecessary evaluation of
8298883285
** arguments past the first non-NULL argument.
8298983286
*/
8299083287
if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
8299183288
int endCoalesce = sqlite3VdbeMakeLabel(v);
8299283289
assert( nFarg>=2 );
@@ -83421,11 +83718,11 @@
8342183718
sqlite3ExprCode(pParse, pExpr, target);
8342283719
}
8342383720
}
8342483721
8342583722
/*
83426
-** Generate code that evalutes the given expression and puts the result
83723
+** Generate code that evaluates the given expression and puts the result
8342783724
** in register target.
8342883725
**
8342983726
** Also make a copy of the expression results into another "cache" register
8343083727
** and modify the expression so that the next time it is evaluated,
8343183728
** the result is a copy of the cache register.
@@ -83776,11 +84073,11 @@
8377684073
** The above is equivalent to
8377784074
**
8377884075
** x>=y AND x<=z
8377984076
**
8378084077
** Code it as such, taking care to do the common subexpression
83781
-** elementation of x.
84078
+** elimination of x.
8378284079
*/
8378384080
static void exprCodeBetween(
8378484081
Parse *pParse, /* Parsing and code generating context */
8378584082
Expr *pExpr, /* The BETWEEN expression */
8378684083
int dest, /* Jump here if the jump is taken */
@@ -84513,11 +84810,11 @@
8451384810
/*
8451484811
** Deallocate a register, making available for reuse for some other
8451584812
** purpose.
8451684813
**
8451784814
** If a register is currently being used by the column cache, then
84518
-** the dallocation is deferred until the column cache line that uses
84815
+** the deallocation is deferred until the column cache line that uses
8451984816
** the register becomes stale.
8452084817
*/
8452184818
SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){
8452284819
if( iReg && pParse->nTempReg<ArraySize(pParse->aTempReg) ){
8452384820
int i;
@@ -84740,12 +85037,12 @@
8474085037
sqlite3 *db = sqlite3_context_db_handle(context);
8474185038
8474285039
UNUSED_PARAMETER(NotUsed);
8474385040
8474485041
/* The principle used to locate the table name in the CREATE TRIGGER
84745
- ** statement is that the table name is the first token that is immediatedly
84746
- ** preceded by either TK_ON or TK_DOT and immediatedly followed by one
85042
+ ** statement is that the table name is the first token that is immediately
85043
+ ** preceded by either TK_ON or TK_DOT and immediately followed by one
8474785044
** of TK_WHEN, TK_BEGIN or TK_FOR.
8474885045
*/
8474985046
if( zSql ){
8475085047
do {
8475185048
@@ -85432,11 +85729,11 @@
8543285729
** version of sqlite_stat3 and is only available when compiled with
8543385730
** SQLITE_ENABLE_STAT4 and in SQLite versions 3.8.1 and later. It is
8543485731
** not possible to enable both STAT3 and STAT4 at the same time. If they
8543585732
** are both enabled, then STAT4 takes precedence.
8543685733
**
85437
-** For most applications, sqlite_stat1 provides all the statisics required
85734
+** For most applications, sqlite_stat1 provides all the statistics required
8543885735
** for the query planner to make good choices.
8543985736
**
8544085737
** Format of sqlite_stat1:
8544185738
**
8544285739
** There is normally one row per index, with the index identified by the
@@ -85783,12 +86080,13 @@
8578386080
** WITHOUT ROWID tables, N=K+P where P is the number of columns in the
8578486081
** PRIMARY KEY of the table. The covering index that implements the
8578586082
** original WITHOUT ROWID table as N==K as a special case.
8578686083
**
8578786084
** This routine allocates the Stat4Accum object in heap memory. The return
85788
-** value is a pointer to the the Stat4Accum object encoded as a blob (i.e.
85789
-** the size of the blob is sizeof(void*) bytes).
86085
+** value is a pointer to the Stat4Accum object. The datatype of the
86086
+** return value is BLOB, but it is really just a pointer to the Stat4Accum
86087
+** object.
8579086088
*/
8579186089
static void statInit(
8579286090
sqlite3_context *context,
8579386091
int argc,
8579486092
sqlite3_value **argv
@@ -85862,12 +86160,15 @@
8586286160
p->aBest[i].iCol = i;
8586386161
}
8586486162
}
8586586163
#endif
8586686164
85867
- /* Return a pointer to the allocated object to the caller */
85868
- sqlite3_result_blob(context, p, sizeof(p), stat4Destructor);
86165
+ /* Return a pointer to the allocated object to the caller. Note that
86166
+ ** only the pointer (the 2nd parameter) matters. The size of the object
86167
+ ** (given by the 3rd parameter) is never used and can be any positive
86168
+ ** value. */
86169
+ sqlite3_result_blob(context, p, sizeof(*p), stat4Destructor);
8586986170
}
8587086171
static const FuncDef statInitFuncdef = {
8587186172
2+IsStat34, /* nArg */
8587286173
SQLITE_UTF8, /* funcFlags */
8587386174
0, /* pUserData */
@@ -86189,11 +86490,11 @@
8618986490
8619086491
/*
8619186492
** Implementation of the stat_get(P,J) SQL function. This routine is
8619286493
** used to query statistical information that has been gathered into
8619386494
** the Stat4Accum object by prior calls to stat_push(). The P parameter
86194
-** is a BLOB which is decoded into a pointer to the Stat4Accum objects.
86495
+** has type BLOB but it is really just a pointer to the Stat4Accum object.
8619586496
** The content to returned is determined by the parameter J
8619686497
** which is one of the STAT_GET_xxxx values defined above.
8619786498
**
8619886499
** If neither STAT3 nor STAT4 are enabled, then J is always
8619986500
** STAT_GET_STAT1 and is hence omitted and this routine becomes
@@ -86593,11 +86894,12 @@
8659386894
sqlite3VdbeChangeP5(v, 2+IsStat34);
8659486895
sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
8659586896
8659686897
/* Add the entry to the stat1 table. */
8659786898
callStatGet(v, regStat4, STAT_GET_STAT1, regStat1);
86598
- sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
86899
+ assert( "BBB"[0]==SQLITE_AFF_TEXT );
86900
+ sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
8659986901
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
8660086902
sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
8660186903
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
8660286904
8660386905
/* Add the entries to the stat3 or stat4 table. */
@@ -86656,11 +86958,12 @@
8665686958
if( pOnlyIdx==0 && needTableCnt ){
8665786959
VdbeComment((v, "%s", pTab->zName));
8665886960
sqlite3VdbeAddOp2(v, OP_Count, iTabCur, regStat1);
8665986961
jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1); VdbeCoverage(v);
8666086962
sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
86661
- sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
86963
+ assert( "BBB"[0]==SQLITE_AFF_TEXT );
86964
+ sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
8666286965
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
8666386966
sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
8666486967
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
8666586968
sqlite3VdbeJumpHere(v, jZeroRows);
8666686969
}
@@ -86975,11 +87278,11 @@
8697587278
tRowcnt nDLt = pFinal->anDLt[iCol];
8697687279
8697787280
/* Set nSum to the number of distinct (iCol+1) field prefixes that
8697887281
** occur in the stat4 table for this index before pFinal. Set
8697987282
** sumEq to the sum of the nEq values for column iCol for the same
86980
- ** set (adding the value only once where there exist dupicate
87283
+ ** set (adding the value only once where there exist duplicate
8698187284
** prefixes). */
8698287285
for(i=0; i<(pIdx->nSample-1); i++){
8698387286
if( aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol] ){
8698487287
sumEq += aSample[i].anEq[iCol];
8698587288
nSum++;
@@ -87457,10 +87760,19 @@
8745787760
if( rc==SQLITE_OK ){
8745887761
sqlite3BtreeEnterAll(db);
8745987762
rc = sqlite3Init(db, &zErrDyn);
8746087763
sqlite3BtreeLeaveAll(db);
8746187764
}
87765
+#ifdef SQLITE_USER_AUTHENTICATION
87766
+ if( rc==SQLITE_OK ){
87767
+ u8 newAuth = 0;
87768
+ rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
87769
+ if( newAuth<db->auth.authLevel ){
87770
+ rc = SQLITE_AUTH_USER;
87771
+ }
87772
+ }
87773
+#endif
8746287774
if( rc ){
8746387775
int iDb = db->nDb - 1;
8746487776
assert( iDb>=2 );
8746587777
if( db->aDb[iDb].pBt ){
8746687778
sqlite3BtreeClose(db->aDb[iDb].pBt);
@@ -87899,11 +88211,11 @@
8789988211
sqlite3 *db,
8790088212
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
8790188213
void *pArg
8790288214
){
8790388215
sqlite3_mutex_enter(db->mutex);
87904
- db->xAuth = xAuth;
88216
+ db->xAuth = (sqlite3_xauth)xAuth;
8790588217
db->pAuthArg = pArg;
8790688218
sqlite3ExpirePreparedStatements(db);
8790788219
sqlite3_mutex_leave(db->mutex);
8790888220
return SQLITE_OK;
8790988221
}
@@ -87934,11 +88246,15 @@
8793488246
){
8793588247
sqlite3 *db = pParse->db; /* Database handle */
8793688248
char *zDb = db->aDb[iDb].zName; /* Name of attached database */
8793788249
int rc; /* Auth callback return code */
8793888250
87939
- rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext);
88251
+ rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext
88252
+#ifdef SQLITE_USER_AUTHENTICATION
88253
+ ,db->auth.zAuthUser
88254
+#endif
88255
+ );
8794088256
if( rc==SQLITE_DENY ){
8794188257
if( db->nDb>2 || iDb!=0 ){
8794288258
sqlite3ErrorMsg(pParse, "access to %s.%s.%s is prohibited",zDb,zTab,zCol);
8794388259
}else{
8794488260
sqlite3ErrorMsg(pParse, "access to %s.%s is prohibited", zTab, zCol);
@@ -88034,11 +88350,15 @@
8803488350
}
8803588351
8803688352
if( db->xAuth==0 ){
8803788353
return SQLITE_OK;
8803888354
}
88039
- rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext);
88355
+ rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext
88356
+#ifdef SQLITE_USER_AUTHENTICATION
88357
+ ,db->auth.zAuthUser
88358
+#endif
88359
+ );
8804088360
if( rc==SQLITE_DENY ){
8804188361
sqlite3ErrorMsg(pParse, "not authorized");
8804288362
pParse->rc = SQLITE_AUTH;
8804388363
}else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){
8804488364
rc = SQLITE_DENY;
@@ -88232,10 +88552,21 @@
8823288552
assert( !pParse->isMultiWrite
8823388553
|| sqlite3VdbeAssertMayAbort(v, pParse->mayAbort));
8823488554
if( v ){
8823588555
while( sqlite3VdbeDeletePriorOpcode(v, OP_Close) ){}
8823688556
sqlite3VdbeAddOp0(v, OP_Halt);
88557
+
88558
+#if SQLITE_USER_AUTHENTICATION
88559
+ if( pParse->nTableLock>0 && db->init.busy==0 ){
88560
+ sqlite3UserAuthInit(db);
88561
+ if( db->auth.authLevel<UAUTH_User ){
88562
+ pParse->rc = SQLITE_AUTH_USER;
88563
+ sqlite3ErrorMsg(pParse, "user not authenticated");
88564
+ return;
88565
+ }
88566
+ }
88567
+#endif
8823788568
8823888569
/* The cookie mask contains one bit for each database file open.
8823988570
** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
8824088571
** set for each database that is used. Generate code to start a
8824188572
** transaction on each used database and to verify the schema cookie
@@ -88348,10 +88679,20 @@
8834888679
sqlite3DbFree(db, zSql);
8834988680
memcpy(&pParse->nVar, saveBuf, SAVE_SZ);
8835088681
pParse->nested--;
8835188682
}
8835288683
88684
+#if SQLITE_USER_AUTHENTICATION
88685
+/*
88686
+** Return TRUE if zTable is the name of the system table that stores the
88687
+** list of users and their access credentials.
88688
+*/
88689
+SQLITE_PRIVATE int sqlite3UserAuthTable(const char *zTable){
88690
+ return sqlite3_stricmp(zTable, "sqlite_user")==0;
88691
+}
88692
+#endif
88693
+
8835388694
/*
8835488695
** Locate the in-memory structure that describes a particular database
8835588696
** table given the name of that table and (optionally) the name of the
8835688697
** database containing the table. Return NULL if not found.
8835788698
**
@@ -88366,10 +88707,17 @@
8836688707
Table *p = 0;
8836788708
int i;
8836888709
assert( zName!=0 );
8836988710
/* All mutexes are required for schema access. Make sure we hold them. */
8837088711
assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
88712
+#if SQLITE_USER_AUTHENTICATION
88713
+ /* Only the admin user is allowed to know that the sqlite_user table
88714
+ ** exists */
88715
+ if( db->auth.authLevel<UAUTH_Admin && sqlite3UserAuthTable(zName)!=0 ){
88716
+ return 0;
88717
+ }
88718
+#endif
8837188719
for(i=OMIT_TEMPDB; i<db->nDb; i++){
8837288720
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
8837388721
if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
8837488722
assert( sqlite3SchemaMutexHeld(db, j, 0) );
8837588723
p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
@@ -88410,10 +88758,16 @@
8841088758
}else{
8841188759
sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
8841288760
}
8841388761
pParse->checkSchema = 1;
8841488762
}
88763
+#if SQLITE_USER_AUTHENICATION
88764
+ else if( pParse->db->auth.authLevel<UAUTH_User ){
88765
+ sqlite3ErrorMsg(pParse, "user not authenticated");
88766
+ p = 0;
88767
+ }
88768
+#endif
8841588769
return p;
8841688770
}
8841788771
8841888772
/*
8841988773
** Locate the table identified by *p.
@@ -89220,11 +89574,11 @@
8922089574
8922189575
/* If pszEst is not NULL, store an estimate of the field size. The
8922289576
** estimate is scaled so that the size of an integer is 1. */
8922389577
if( pszEst ){
8922489578
*pszEst = 1; /* default size is approx 4 bytes */
89225
- if( aff<=SQLITE_AFF_NONE ){
89579
+ if( aff<SQLITE_AFF_NUMERIC ){
8922689580
if( zChar ){
8922789581
while( zChar[0] ){
8922889582
if( sqlite3Isdigit(zChar[0]) ){
8922989583
int v = 0;
8923089584
sqlite3GetInt32(zChar, &v);
@@ -89591,12 +89945,12 @@
8959189945
k = sqlite3Strlen30(zStmt);
8959289946
identPut(zStmt, &k, p->zName);
8959389947
zStmt[k++] = '(';
8959489948
for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){
8959589949
static const char * const azType[] = {
89596
- /* SQLITE_AFF_TEXT */ " TEXT",
8959789950
/* SQLITE_AFF_NONE */ "",
89951
+ /* SQLITE_AFF_TEXT */ " TEXT",
8959889952
/* SQLITE_AFF_NUMERIC */ " NUM",
8959989953
/* SQLITE_AFF_INTEGER */ " INT",
8960089954
/* SQLITE_AFF_REAL */ " REAL"
8960189955
};
8960289956
int len;
@@ -89604,19 +89958,19 @@
8960489958
8960589959
sqlite3_snprintf(n-k, &zStmt[k], zSep);
8960689960
k += sqlite3Strlen30(&zStmt[k]);
8960789961
zSep = zSep2;
8960889962
identPut(zStmt, &k, pCol->zName);
89609
- assert( pCol->affinity-SQLITE_AFF_TEXT >= 0 );
89610
- assert( pCol->affinity-SQLITE_AFF_TEXT < ArraySize(azType) );
89611
- testcase( pCol->affinity==SQLITE_AFF_TEXT );
89963
+ assert( pCol->affinity-SQLITE_AFF_NONE >= 0 );
89964
+ assert( pCol->affinity-SQLITE_AFF_NONE < ArraySize(azType) );
8961289965
testcase( pCol->affinity==SQLITE_AFF_NONE );
89966
+ testcase( pCol->affinity==SQLITE_AFF_TEXT );
8961389967
testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
8961489968
testcase( pCol->affinity==SQLITE_AFF_INTEGER );
8961589969
testcase( pCol->affinity==SQLITE_AFF_REAL );
8961689970
89617
- zType = azType[pCol->affinity - SQLITE_AFF_TEXT];
89971
+ zType = azType[pCol->affinity - SQLITE_AFF_NONE];
8961889972
len = sqlite3Strlen30(zType);
8961989973
assert( pCol->affinity==SQLITE_AFF_NONE
8962089974
|| pCol->affinity==sqlite3AffinityType(zType, 0) );
8962189975
memcpy(&zStmt[k], zType, len);
8962289976
k += len;
@@ -89696,11 +90050,11 @@
8969690050
**
8969790051
** (1) Convert the OP_CreateTable into an OP_CreateIndex. There is
8969890052
** no rowid btree for a WITHOUT ROWID. Instead, the canonical
8969990053
** data storage is a covering index btree.
8970090054
** (2) Bypass the creation of the sqlite_master table entry
89701
-** for the PRIMARY KEY as the the primary key index is now
90055
+** for the PRIMARY KEY as the primary key index is now
8970290056
** identified by the sqlite_master table entry of the table itself.
8970390057
** (3) Set the Index.tnum of the PRIMARY KEY Index object in the
8970490058
** schema to the rootpage from the main table.
8970590059
** (4) Set all columns of the PRIMARY KEY schema object to be NOT NULL.
8970690060
** (5) Add all table columns to the PRIMARY KEY Index object
@@ -89717,11 +90071,11 @@
8971790071
int i, j;
8971890072
sqlite3 *db = pParse->db;
8971990073
Vdbe *v = pParse->pVdbe;
8972090074
8972190075
/* Convert the OP_CreateTable opcode that would normally create the
89722
- ** root-page for the table into a OP_CreateIndex opcode. The index
90076
+ ** root-page for the table into an OP_CreateIndex opcode. The index
8972390077
** created will become the PRIMARY KEY index.
8972490078
*/
8972590079
if( pParse->addrCrTab ){
8972690080
assert( v );
8972790081
sqlite3VdbeGetOp(v, pParse->addrCrTab)->opcode = OP_CreateIndex;
@@ -90129,11 +90483,11 @@
9012990483
Table *pSelTab; /* A fake table from which we get the result set */
9013090484
Select *pSel; /* Copy of the SELECT that implements the view */
9013190485
int nErr = 0; /* Number of errors encountered */
9013290486
int n; /* Temporarily holds the number of cursors assigned */
9013390487
sqlite3 *db = pParse->db; /* Database connection for malloc errors */
90134
- int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
90488
+ sqlite3_xauth xAuth; /* Saved xAuth pointer */
9013590489
9013690490
assert( pTable );
9013790491
9013890492
#ifndef SQLITE_OMIT_VIRTUALTABLE
9013990493
if( sqlite3VtabCallConnect(pParse, pTable) ){
@@ -90731,11 +91085,11 @@
9073191085
int addr2; /* Address to jump to for next iteration */
9073291086
int tnum; /* Root page of index */
9073391087
int iPartIdxLabel; /* Jump to this label to skip a row */
9073491088
Vdbe *v; /* Generate code into this virtual machine */
9073591089
KeyInfo *pKey; /* KeyInfo for index */
90736
- int regRecord; /* Register holding assemblied index record */
91090
+ int regRecord; /* Register holding assembled index record */
9073791091
sqlite3 *db = pParse->db; /* The database connection */
9073891092
int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
9073991093
9074091094
#ifndef SQLITE_OMIT_AUTHORIZATION
9074191095
if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
@@ -90944,10 +91298,14 @@
9094491298
pDb = &db->aDb[iDb];
9094591299
9094691300
assert( pTab!=0 );
9094791301
assert( pParse->nErr==0 );
9094891302
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
91303
+ && db->init.busy==0
91304
+#if SQLITE_USER_AUTHENTICATION
91305
+ && sqlite3UserAuthTable(pTab->zName)==0
91306
+#endif
9094991307
&& sqlite3StrNICmp(&pTab->zName[7],"altertab_",9)!=0 ){
9095091308
sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
9095191309
goto exit_create_index;
9095291310
}
9095391311
#ifndef SQLITE_OMIT_VIEW
@@ -91331,11 +91689,11 @@
9133191689
9133291690
/*
9133391691
** Fill the Index.aiRowEst[] array with default information - information
9133491692
** to be used when we have not run the ANALYZE command.
9133591693
**
91336
-** aiRowEst[0] is suppose to contain the number of elements in the index.
91694
+** aiRowEst[0] is supposed to contain the number of elements in the index.
9133791695
** Since we do not know, guess 1 million. aiRowEst[1] is an estimate of the
9133891696
** number of rows in the table that match any particular value of the
9133991697
** first column of the index. aiRowEst[2] is an estimate of the number
9134091698
** of rows that match any particular combination of the first 2 columns
9134191699
** of the index. And so forth. It must always be the case that
@@ -91710,11 +92068,11 @@
9171092068
** end of a growing FROM clause. The "p" parameter is the part of
9171192069
** the FROM clause that has already been constructed. "p" is NULL
9171292070
** if this is the first term of the FROM clause. pTable and pDatabase
9171392071
** are the name of the table and database named in the FROM clause term.
9171492072
** pDatabase is NULL if the database name qualifier is missing - the
91715
-** usual case. If the term has a alias, then pAlias points to the
92073
+** usual case. If the term has an alias, then pAlias points to the
9171692074
** alias token. If the term is a subquery, then pSubquery is the
9171792075
** SELECT statement that the subquery encodes. The pTable and
9171892076
** pDatabase parameters are NULL for subqueries. The pOn and pUsing
9171992077
** parameters are the content of the ON and USING clauses.
9172092078
**
@@ -92473,11 +92831,11 @@
9247392831
** specified by zName and nName is not found and parameter 'create' is
9247492832
** true, then create a new entry. Otherwise return NULL.
9247592833
**
9247692834
** Each pointer stored in the sqlite3.aCollSeq hash table contains an
9247792835
** array of three CollSeq structures. The first is the collation sequence
92478
-** prefferred for UTF-8, the second UTF-16le, and the third UTF-16be.
92836
+** preferred for UTF-8, the second UTF-16le, and the third UTF-16be.
9247992837
**
9248092838
** Stored immediately after the three collation sequences is a copy of
9248192839
** the collation sequence name. A pointer to this string is stored in
9248292840
** each collation sequence structure.
9248392841
*/
@@ -92900,11 +93258,11 @@
9290093258
*/
9290193259
SQLITE_PRIVATE void sqlite3MaterializeView(
9290293260
Parse *pParse, /* Parsing context */
9290393261
Table *pView, /* View definition */
9290493262
Expr *pWhere, /* Optional WHERE clause to be added */
92905
- int iCur /* Cursor number for ephemerial table */
93263
+ int iCur /* Cursor number for ephemeral table */
9290693264
){
9290793265
SelectDest dest;
9290893266
Select *pSel;
9290993267
SrcList *pFrom;
9291093268
sqlite3 *db = pParse->db;
@@ -93058,11 +93416,11 @@
9305893416
int iEphCur = 0; /* Ephemeral table holding all primary key values */
9305993417
int iRowSet = 0; /* Register for rowset of rows to delete */
9306093418
int addrBypass = 0; /* Address of jump over the delete logic */
9306193419
int addrLoop = 0; /* Top of the delete loop */
9306293420
int addrDelete = 0; /* Jump directly to the delete logic */
93063
- int addrEphOpen = 0; /* Instruction to open the Ephermeral table */
93421
+ int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
9306493422
9306593423
#ifndef SQLITE_OMIT_TRIGGER
9306693424
int isView; /* True if attempting to delete from a view */
9306793425
Trigger *pTrigger; /* List of table triggers, if required */
9306893426
#endif
@@ -93138,11 +93496,11 @@
9313893496
}
9313993497
if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
9314093498
sqlite3BeginWriteOperation(pParse, 1, iDb);
9314193499
9314293500
/* If we are trying to delete from a view, realize that view into
93143
- ** a ephemeral table.
93501
+ ** an ephemeral table.
9314493502
*/
9314593503
#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
9314693504
if( isView ){
9314793505
sqlite3MaterializeView(pParse, pTab, pWhere, iTabCur);
9314893506
iDataCur = iIdxCur = iTabCur;
@@ -93192,11 +93550,11 @@
9319293550
pPk = 0;
9319393551
nPk = 1;
9319493552
iRowSet = ++pParse->nMem;
9319593553
sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
9319693554
}else{
93197
- /* For a WITHOUT ROWID table, create an ephermeral table used to
93555
+ /* For a WITHOUT ROWID table, create an ephemeral table used to
9319893556
** hold all primary keys for rows to be deleted. */
9319993557
pPk = sqlite3PrimaryKeyIndex(pTab);
9320093558
assert( pPk!=0 );
9320193559
nPk = pPk->nKeyCol;
9320293560
iPk = pParse->nMem+1;
@@ -93367,11 +93725,11 @@
9336793725
sqlite3ExprDelete(db, pWhere);
9336893726
sqlite3DbFree(db, aToOpen);
9336993727
return;
9337093728
}
9337193729
/* Make sure "isView" and other macros defined above are undefined. Otherwise
93372
-** thely may interfere with compilation of other functions in this file
93730
+** they may interfere with compilation of other functions in this file
9337393731
** (or in another file, if this file becomes part of the amalgamation). */
9337493732
#ifdef isView
9337593733
#undef isView
9337693734
#endif
9337793735
#ifdef pTrigger
@@ -93661,11 +94019,11 @@
9366194019
** May you do good and not evil.
9366294020
** May you find forgiveness for yourself and forgive others.
9366394021
** May you share freely, never taking more than you give.
9366494022
**
9366594023
*************************************************************************
93666
-** This file contains the C-language implementions for many of the SQL
94024
+** This file contains the C-language implementations for many of the SQL
9366794025
** functions of SQLite. (Some function, and in particular the date and
9366894026
** time functions, are implemented separately.)
9366994027
*/
9367094028
/* #include <stdlib.h> */
9367194029
/* #include <assert.h> */
@@ -93975,17 +94333,18 @@
9397594333
p1--;
9397694334
}
9397794335
for(z2=z; *z2 && p2; p2--){
9397894336
SQLITE_SKIP_UTF8(z2);
9397994337
}
93980
- sqlite3_result_text(context, (char*)z, (int)(z2-z), SQLITE_TRANSIENT);
94338
+ sqlite3_result_text64(context, (char*)z, z2-z, SQLITE_TRANSIENT,
94339
+ SQLITE_UTF8);
9398194340
}else{
9398294341
if( p1+p2>len ){
9398394342
p2 = len-p1;
9398494343
if( p2<0 ) p2 = 0;
9398594344
}
93986
- sqlite3_result_blob(context, (char*)&z[p1], (int)p2, SQLITE_TRANSIENT);
94345
+ sqlite3_result_blob64(context, (char*)&z[p1], (u64)p2, SQLITE_TRANSIENT);
9398794346
}
9398894347
}
9398994348
9399094349
/*
9399194350
** Implementation of the round() function
@@ -94040,11 +94399,11 @@
9404094399
testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
9404194400
if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
9404294401
sqlite3_result_error_toobig(context);
9404394402
z = 0;
9404494403
}else{
94045
- z = sqlite3Malloc((int)nByte);
94404
+ z = sqlite3Malloc(nByte);
9404694405
if( !z ){
9404794406
sqlite3_result_error_nomem(context);
9404894407
}
9404994408
}
9405094409
return z;
@@ -94691,11 +95050,11 @@
9469195050
*zOut++ = 0x80 + (u8)((c>>12) & 0x3F);
9469295051
*zOut++ = 0x80 + (u8)((c>>6) & 0x3F);
9469395052
*zOut++ = 0x80 + (u8)(c & 0x3F);
9469495053
} \
9469595054
}
94696
- sqlite3_result_text(context, (char*)z, (int)(zOut-z), sqlite3_free);
95055
+ sqlite3_result_text64(context, (char*)z, zOut-z, sqlite3_free, SQLITE_UTF8);
9469795056
}
9469895057
9469995058
/*
9470095059
** The hex() function. Interpret the argument as a blob. Return
9470195060
** a hexadecimal rendering as text.
@@ -95141,10 +95500,11 @@
9514195500
sqlite3VdbeMemCopy(pBest, pArg);
9514295501
}else{
9514395502
sqlite3SkipAccumulatorLoad(context);
9514495503
}
9514595504
}else{
95505
+ pBest->db = sqlite3_context_db_handle(context);
9514695506
sqlite3VdbeMemCopy(pBest, pArg);
9514795507
}
9514895508
}
9514995509
static void minMaxFinalize(sqlite3_context *context){
9515095510
sqlite3_value *pRes;
@@ -95288,11 +95648,11 @@
9528895648
*pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0;
9528995649
return 1;
9529095650
}
9529195651
9529295652
/*
95293
-** All all of the FuncDef structures in the aBuiltinFunc[] array above
95653
+** All of the FuncDef structures in the aBuiltinFunc[] array above
9529495654
** to the global function hash table. This occurs at start-time (as
9529595655
** a consequence of calling sqlite3_initialize()).
9529695656
**
9529795657
** After this routine runs
9529895658
*/
@@ -95312,14 +95672,16 @@
9531295672
FUNCTION(rtrim, 2, 2, 0, trimFunc ),
9531395673
FUNCTION(trim, 1, 3, 0, trimFunc ),
9531495674
FUNCTION(trim, 2, 3, 0, trimFunc ),
9531595675
FUNCTION(min, -1, 0, 1, minmaxFunc ),
9531695676
FUNCTION(min, 0, 0, 1, 0 ),
95317
- AGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize ),
95677
+ AGGREGATE2(min, 1, 0, 1, minmaxStep, minMaxFinalize,
95678
+ SQLITE_FUNC_MINMAX ),
9531895679
FUNCTION(max, -1, 1, 1, minmaxFunc ),
9531995680
FUNCTION(max, 0, 1, 1, 0 ),
95320
- AGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize ),
95681
+ AGGREGATE2(max, 1, 1, 1, minmaxStep, minMaxFinalize,
95682
+ SQLITE_FUNC_MINMAX ),
9532195683
FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
9532295684
FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
9532395685
FUNCTION(instr, 2, 0, 0, instrFunc ),
9532495686
FUNCTION(substr, 2, 0, 0, substrFunc ),
9532595687
FUNCTION(substr, 3, 0, 0, substrFunc ),
@@ -95345,10 +95707,13 @@
9534595707
VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
9534695708
FUNCTION(nullif, 2, 0, 1, nullifFunc ),
9534795709
FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
9534895710
FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
9534995711
FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
95712
+#if SQLITE_USER_AUTHENTICATION
95713
+ FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ),
95714
+#endif
9535095715
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
9535195716
FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
9535295717
FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
9535395718
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
9535495719
FUNCTION(quote, 1, 0, 0, quoteFunc ),
@@ -95365,12 +95730,12 @@
9536595730
FUNCTION(load_extension, 2, 0, 0, loadExt ),
9536695731
#endif
9536795732
AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ),
9536895733
AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ),
9536995734
AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ),
95370
- /* AGGREGATE(count, 0, 0, 0, countStep, countFinalize ), */
95371
- {0,SQLITE_UTF8|SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0},
95735
+ AGGREGATE2(count, 0, 0, 0, countStep, countFinalize,
95736
+ SQLITE_FUNC_COUNT ),
9537295737
AGGREGATE(count, 1, 0, 0, countStep, countFinalize ),
9537395738
AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, groupConcatFinalize),
9537495739
AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, groupConcatFinalize),
9537595740
9537695741
LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
@@ -95573,11 +95938,11 @@
9557395938
** foreign key definition, and the parent table does not have a
9557495939
** PRIMARY KEY, or
9557595940
**
9557695941
** 4) No parent key columns were provided explicitly as part of the
9557795942
** foreign key definition, and the PRIMARY KEY of the parent table
95578
-** consists of a a different number of columns to the child key in
95943
+** consists of a different number of columns to the child key in
9557995944
** the child table.
9558095945
**
9558195946
** then non-zero is returned, and a "foreign key mismatch" error loaded
9558295947
** into pParse. If an OOM error occurs, non-zero is returned and the
9558395948
** pParse->db->mallocFailed flag is set.
@@ -96820,17 +97185,17 @@
9682097185
** pIdx. A column affinity string has one character for each column in
9682197186
** the table, according to the affinity of the column:
9682297187
**
9682397188
** Character Column affinity
9682497189
** ------------------------------
96825
-** 'a' TEXT
96826
-** 'b' NONE
96827
-** 'c' NUMERIC
96828
-** 'd' INTEGER
96829
-** 'e' REAL
97190
+** 'A' NONE
97191
+** 'B' TEXT
97192
+** 'C' NUMERIC
97193
+** 'D' INTEGER
97194
+** 'F' REAL
9683097195
**
96831
-** An extra 'd' is appended to the end of the string to cover the
97196
+** An extra 'D' is appended to the end of the string to cover the
9683297197
** rowid that appears as the last column in every index.
9683397198
**
9683497199
** Memory for the buffer containing the column index affinity string
9683597200
** is managed along with the rest of the Index structure. It will be
9683697201
** released when sqlite3DeleteIndex() is called.
@@ -96875,15 +97240,15 @@
9687597240
**
9687697241
** A column affinity string has one character per column:
9687797242
**
9687897243
** Character Column affinity
9687997244
** ------------------------------
96880
-** 'a' TEXT
96881
-** 'b' NONE
96882
-** 'c' NUMERIC
96883
-** 'd' INTEGER
96884
-** 'e' REAL
97245
+** 'A' NONE
97246
+** 'B' TEXT
97247
+** 'C' NUMERIC
97248
+** 'D' INTEGER
97249
+** 'E' REAL
9688597250
*/
9688697251
SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
9688797252
int i;
9688897253
char *zColAff = pTab->zColAff;
9688997254
if( zColAff==0 ){
@@ -97174,11 +97539,11 @@
9717497539
** D: cleanup
9717597540
**
9717697541
** The 4th template is used if the insert statement takes its
9717797542
** values from a SELECT but the data is being inserted into a table
9717897543
** that is also read as part of the SELECT. In the third form,
97179
-** we have to use a intermediate table to store the results of
97544
+** we have to use an intermediate table to store the results of
9718097545
** the select. The template is like this:
9718197546
**
9718297547
** X <- A
9718397548
** goto B
9718497549
** A: setup for the SELECT
@@ -97339,11 +97704,11 @@
9733997704
** sqlite_sequence table and store it in memory cell regAutoinc.
9734097705
*/
9734197706
regAutoinc = autoIncBegin(pParse, iDb, pTab);
9734297707
9734397708
/* Allocate registers for holding the rowid of the new row,
97344
- ** the content of the new row, and the assemblied row record.
97709
+ ** the content of the new row, and the assembled row record.
9734597710
*/
9734697711
regRowid = regIns = pParse->nMem+1;
9734797712
pParse->nMem += pTab->nCol + 1;
9734897713
if( IsVirtual(pTab) ){
9734997714
regRowid++;
@@ -97791,11 +98156,11 @@
9779198156
sqlite3IdListDelete(db, pColumn);
9779298157
sqlite3DbFree(db, aRegIdx);
9779398158
}
9779498159
9779598160
/* Make sure "isView" and other macros defined above are undefined. Otherwise
97796
-** thely may interfere with compilation of other functions in this file
98161
+** they may interfere with compilation of other functions in this file
9779798162
** (or in another file, if this file becomes part of the amalgamation). */
9779898163
#ifdef isView
9779998164
#undef isView
9780098165
#endif
9780198166
#ifdef pTrigger
@@ -97907,11 +98272,11 @@
9790798272
sqlite3 *db; /* Database connection */
9790898273
int i; /* loop counter */
9790998274
int ix; /* Index loop counter */
9791098275
int nCol; /* Number of columns */
9791198276
int onError; /* Conflict resolution strategy */
97912
- int j1; /* Addresss of jump instruction */
98277
+ int j1; /* Address of jump instruction */
9791398278
int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
9791498279
int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
9791598280
int ipkTop = 0; /* Top of the rowid change constraint check */
9791698281
int ipkBottom = 0; /* Bottom of the rowid change constraint check */
9791798282
u8 isUpdate; /* True if this is an UPDATE operation */
@@ -98311,11 +98676,11 @@
9831198676
){
9831298677
Vdbe *v; /* Prepared statements under construction */
9831398678
Index *pIdx; /* An index being inserted or updated */
9831498679
u8 pik_flags; /* flag values passed to the btree insert */
9831598680
int regData; /* Content registers (after the rowid) */
98316
- int regRec; /* Register holding assemblied record for the table */
98681
+ int regRec; /* Register holding assembled record for the table */
9831798682
int i; /* Loop counter */
9831898683
u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */
9831998684
9832098685
v = sqlite3GetVdbe(pParse);
9832198686
assert( v!=0 );
@@ -98436,11 +98801,11 @@
9843698801
#ifdef SQLITE_TEST
9843798802
/*
9843898803
** The following global variable is incremented whenever the
9843998804
** transfer optimization is used. This is used for testing
9844098805
** purposes only - to make sure the transfer optimization really
98441
-** is happening when it is suppose to.
98806
+** is happening when it is supposed to.
9844298807
*/
9844398808
SQLITE_API int sqlite3_xferopt_count;
9844498809
#endif /* SQLITE_TEST */
9844598810
9844698811
@@ -98503,11 +98868,11 @@
9850398868
** Attempt the transfer optimization on INSERTs of the form
9850498869
**
9850598870
** INSERT INTO tab1 SELECT * FROM tab2;
9850698871
**
9850798872
** The xfer optimization transfers raw records from tab2 over to tab1.
98508
-** Columns are not decoded and reassemblied, which greatly improves
98873
+** Columns are not decoded and reassembled, which greatly improves
9850998874
** performance. Raw index records are transferred in the same way.
9851098875
**
9851198876
** The xfer optimization is only attempted if tab1 and tab2 are compatible.
9851298877
** There are lots of rules for determining compatibility - see comments
9851398878
** embedded in the code for details.
@@ -98912,11 +99277,11 @@
9891299277
exec_out:
9891399278
if( pStmt ) sqlite3VdbeFinalize((Vdbe *)pStmt);
9891499279
sqlite3DbFree(db, azCols);
9891599280
9891699281
rc = sqlite3ApiExit(db, rc);
98917
- if( rc!=SQLITE_OK && ALWAYS(rc==sqlite3_errcode(db)) && pzErrMsg ){
99282
+ if( rc!=SQLITE_OK && pzErrMsg ){
9891899283
int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db));
9891999284
*pzErrMsg = sqlite3Malloc(nErrMsg);
9892099285
if( *pzErrMsg ){
9892199286
memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg);
9892299287
}else{
@@ -98981,11 +99346,11 @@
9898199346
** routines.
9898299347
**
9898399348
** WARNING: In order to maintain backwards compatibility, add new
9898499349
** interfaces to the end of this structure only. If you insert new
9898599350
** interfaces in the middle of this structure, then older different
98986
-** versions of SQLite will not be able to load each others' shared
99351
+** versions of SQLite will not be able to load each other's shared
9898799352
** libraries!
9898899353
*/
9898999354
struct sqlite3_api_routines {
9899099355
void * (*aggregate_context)(sqlite3_context*,int nBytes);
9899199356
int (*aggregate_count)(sqlite3_context*);
@@ -99203,15 +99568,32 @@
9920399568
int (*uri_boolean)(const char*,const char*,int);
9920499569
sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64);
9920599570
const char *(*uri_parameter)(const char*,const char*);
9920699571
char *(*vsnprintf)(int,char*,const char*,va_list);
9920799572
int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*);
99573
+ /* Version 3.8.7 and later */
99574
+ int (*auto_extension)(void(*)(void));
99575
+ int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64,
99576
+ void(*)(void*));
99577
+ int (*bind_text64)(sqlite3_stmt*,int,const char*,sqlite3_uint64,
99578
+ void(*)(void*),unsigned char);
99579
+ int (*cancel_auto_extension)(void(*)(void));
99580
+ int (*load_extension)(sqlite3*,const char*,const char*,char**);
99581
+ void *(*malloc64)(sqlite3_uint64);
99582
+ sqlite3_uint64 (*msize)(void*);
99583
+ void *(*realloc64)(void*,sqlite3_uint64);
99584
+ void (*reset_auto_extension)(void);
99585
+ void (*result_blob64)(sqlite3_context*,const void*,sqlite3_uint64,
99586
+ void(*)(void*));
99587
+ void (*result_text64)(sqlite3_context*,const char*,sqlite3_uint64,
99588
+ void(*)(void*), unsigned char);
99589
+ int (*strglob)(const char*,const char*);
9920899590
};
9920999591
9921099592
/*
9921199593
** The following macros redefine the API routines so that they are
99212
-** redirected throught the global sqlite3_api structure.
99594
+** redirected through the global sqlite3_api structure.
9921399595
**
9921499596
** This header file is also used by the loadext.c source file
9921599597
** (part of the main SQLite library - not an extension) so that
9921699598
** it can get access to the sqlite3_api_routines structure
9921799599
** definition. But the main library does not want to redefine
@@ -99420,10 +99802,23 @@
9942099802
#define sqlite3_uri_boolean sqlite3_api->uri_boolean
9942199803
#define sqlite3_uri_int64 sqlite3_api->uri_int64
9942299804
#define sqlite3_uri_parameter sqlite3_api->uri_parameter
9942399805
#define sqlite3_uri_vsnprintf sqlite3_api->vsnprintf
9942499806
#define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2
99807
+/* Version 3.8.7 and later */
99808
+#define sqlite3_auto_extension sqlite3_api->auto_extension
99809
+#define sqlite3_bind_blob64 sqlite3_api->bind_blob64
99810
+#define sqlite3_bind_text64 sqlite3_api->bind_text64
99811
+#define sqlite3_cancel_auto_extension sqlite3_api->cancel_auto_extension
99812
+#define sqlite3_load_extension sqlite3_api->load_extension
99813
+#define sqlite3_malloc64 sqlite3_api->malloc64
99814
+#define sqlite3_msize sqlite3_api->msize
99815
+#define sqlite3_realloc64 sqlite3_api->realloc64
99816
+#define sqlite3_reset_auto_extension sqlite3_api->reset_auto_extension
99817
+#define sqlite3_result_blob64 sqlite3_api->result_blob64
99818
+#define sqlite3_result_text64 sqlite3_api->result_text64
99819
+#define sqlite3_strglob sqlite3_api->strglob
9942599820
#endif /* SQLITE_CORE */
9942699821
9942799822
#ifndef SQLITE_CORE
9942899823
/* This case when the file really is being compiled as a loadable
9942999824
** extension */
@@ -99813,11 +100208,24 @@
99813100208
sqlite3_stricmp,
99814100209
sqlite3_uri_boolean,
99815100210
sqlite3_uri_int64,
99816100211
sqlite3_uri_parameter,
99817100212
sqlite3_vsnprintf,
99818
- sqlite3_wal_checkpoint_v2
100213
+ sqlite3_wal_checkpoint_v2,
100214
+ /* Version 3.8.7 and later */
100215
+ sqlite3_auto_extension,
100216
+ sqlite3_bind_blob64,
100217
+ sqlite3_bind_text64,
100218
+ sqlite3_cancel_auto_extension,
100219
+ sqlite3_load_extension,
100220
+ sqlite3_malloc64,
100221
+ sqlite3_msize,
100222
+ sqlite3_realloc64,
100223
+ sqlite3_reset_auto_extension,
100224
+ sqlite3_result_blob64,
100225
+ sqlite3_result_text64,
100226
+ sqlite3_strglob
99819100227
};
99820100228
99821100229
/*
99822100230
** Attempt to load an SQLite extension library contained in the file
99823100231
** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -101580,10 +101988,16 @@
101580101988
if( db->autoCommit==0 ){
101581101989
/* Foreign key support may not be enabled or disabled while not
101582101990
** in auto-commit mode. */
101583101991
mask &= ~(SQLITE_ForeignKeys);
101584101992
}
101993
+#if SQLITE_USER_AUTHENTICATION
101994
+ if( db->auth.authLevel==UAUTH_User ){
101995
+ /* Do not allow non-admin users to modify the schema arbitrarily */
101996
+ mask &= ~(SQLITE_WriteSchema);
101997
+ }
101998
+#endif
101585101999
101586102000
if( sqlite3GetBoolean(zRight, 0) ){
101587102001
db->flags |= mask;
101588102002
}else{
101589102003
db->flags &= ~mask;
@@ -102897,11 +103311,11 @@
102897103311
zSql = sqlite3MPrintf(db,
102898103312
"SELECT name, rootpage, sql FROM '%q'.%s ORDER BY rowid",
102899103313
db->aDb[iDb].zName, zMasterName);
102900103314
#ifndef SQLITE_OMIT_AUTHORIZATION
102901103315
{
102902
- int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
103316
+ sqlite3_xauth xAuth;
102903103317
xAuth = db->xAuth;
102904103318
db->xAuth = 0;
102905103319
#endif
102906103320
rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
102907103321
#ifndef SQLITE_OMIT_AUTHORIZATION
@@ -102963,10 +103377,11 @@
102963103377
SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
102964103378
int i, rc;
102965103379
int commit_internal = !(db->flags&SQLITE_InternChanges);
102966103380
102967103381
assert( sqlite3_mutex_held(db->mutex) );
103382
+ assert( db->init.busy==0 );
102968103383
rc = SQLITE_OK;
102969103384
db->init.busy = 1;
102970103385
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
102971103386
if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
102972103387
rc = sqlite3InitOne(db, i, pzErrMsg);
@@ -102978,12 +103393,12 @@
102978103393
/* Once all the other databases have been initialized, load the schema
102979103394
** for the TEMP database. This is loaded last, as the TEMP database
102980103395
** schema may contain references to objects in other databases.
102981103396
*/
102982103397
#ifndef SQLITE_OMIT_TEMPDB
102983
- if( rc==SQLITE_OK && ALWAYS(db->nDb>1)
102984
- && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
103398
+ assert( db->nDb>1 );
103399
+ if( rc==SQLITE_OK && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
102985103400
rc = sqlite3InitOne(db, 1, pzErrMsg);
102986103401
if( rc ){
102987103402
sqlite3ResetOneSchema(db, 1);
102988103403
}
102989103404
}
@@ -103944,11 +104359,11 @@
103944104359
sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, SQLITE_ECEL_DUP);
103945104360
if( bSeq ){
103946104361
sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
103947104362
}
103948104363
if( nPrefixReg==0 ){
103949
- sqlite3VdbeAddOp3(v, OP_Move, regData, regBase+nExpr+bSeq, nData);
104364
+ sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
103950104365
}
103951104366
103952104367
sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase+nOBSat, nBase-nOBSat, regRecord);
103953104368
if( nOBSat>0 ){
103954104369
int regPrevKey; /* The first nOBSat columns of the previous row */
@@ -103980,11 +104395,11 @@
103980104395
pSort->labelBkOut = sqlite3VdbeMakeLabel(v);
103981104396
pSort->regReturn = ++pParse->nMem;
103982104397
sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
103983104398
sqlite3VdbeAddOp1(v, OP_ResetSorter, pSort->iECursor);
103984104399
sqlite3VdbeJumpHere(v, addrFirst);
103985
- sqlite3VdbeAddOp3(v, OP_Move, regBase, regPrevKey, pSort->nOBSat);
104400
+ sqlite3ExprCodeMove(pParse, regBase, regPrevKey, pSort->nOBSat);
103986104401
sqlite3VdbeJumpHere(v, addrJmp);
103987104402
}
103988104403
if( pSort->sortFlags & SORTFLAG_UseSorter ){
103989104404
op = OP_SorterInsert;
103990104405
}else{
@@ -104466,11 +104881,11 @@
104466104881
** KeyInfo structure is appropriate for initializing a virtual index to
104467104882
** implement that clause. If the ExprList is the result set of a SELECT
104468104883
** then the KeyInfo structure is appropriate for initializing a virtual
104469104884
** index to implement a DISTINCT test.
104470104885
**
104471
-** Space to hold the KeyInfo structure is obtain from malloc. The calling
104886
+** Space to hold the KeyInfo structure is obtained from malloc. The calling
104472104887
** function is responsible for seeing that this structure is eventually
104473104888
** freed.
104474104889
*/
104475104890
static KeyInfo *keyInfoFromExprList(
104476104891
Parse *pParse, /* Parsing context */
@@ -104997,11 +105412,11 @@
104997105412
}
104998105413
generateColumnTypes(pParse, pTabList, pEList);
104999105414
}
105000105415
105001105416
/*
105002
-** Given a an expression list (which is really the list of expressions
105417
+** Given an expression list (which is really the list of expressions
105003105418
** that form the result set of a SELECT statement) compute appropriate
105004105419
** column names for a table that would hold the expression list.
105005105420
**
105006105421
** All column names will be unique.
105007105422
**
@@ -105070,11 +105485,11 @@
105070105485
sqlite3DbFree(db, zName);
105071105486
break;
105072105487
}
105073105488
105074105489
/* Make sure the column name is unique. If the name is not unique,
105075
- ** append a integer to the name so that it becomes unique.
105490
+ ** append an integer to the name so that it becomes unique.
105076105491
*/
105077105492
nName = sqlite3Strlen30(zName);
105078105493
for(j=cnt=0; j<i; j++){
105079105494
if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){
105080105495
char *zNewName;
@@ -106554,11 +106969,11 @@
106554106969
** This routine attempts to rewrite queries such as the above into
106555106970
** a single flat select, like this:
106556106971
**
106557106972
** SELECT x+y AS a FROM t1 WHERE z<100 AND a>5
106558106973
**
106559
-** The code generated for this simpification gives the same result
106974
+** The code generated for this simplification gives the same result
106560106975
** but only has to scan the data once. And because indices might
106561106976
** exist on the table t1, a complete scan of the data might be
106562106977
** avoided.
106563106978
**
106564106979
** Flattening is only attempted if all of the following are true:
@@ -106587,12 +107002,14 @@
106587107002
** (8) The subquery does not use LIMIT or the outer query is not a join.
106588107003
**
106589107004
** (9) The subquery does not use LIMIT or the outer query does not use
106590107005
** aggregates.
106591107006
**
106592
-** (10) The subquery does not use aggregates or the outer query does not
106593
-** use LIMIT.
107007
+** (**) Restriction (10) was removed from the code on 2005-02-05 but we
107008
+** accidently carried the comment forward until 2014-09-15. Original
107009
+** text: "The subquery does not use aggregates or the outer query does not
107010
+** use LIMIT."
106594107011
**
106595107012
** (11) The subquery and the outer query do not both have ORDER BY clauses.
106596107013
**
106597107014
** (**) Not implemented. Subsumed into restriction (3). Was previously
106598107015
** a separate restriction deriving from ticket #350.
@@ -106651,10 +107068,15 @@
106651107068
** (23) The parent is not a recursive CTE, or the sub-query is not a
106652107069
** compound query. This restriction is because transforming the
106653107070
** parent to a compound query confuses the code that handles
106654107071
** recursive queries in multiSelect().
106655107072
**
107073
+** (24) The subquery is not an aggregate that uses the built-in min() or
107074
+** or max() functions. (Without this restriction, a query like:
107075
+** "SELECT x FROM (SELECT max(y), x FROM t1)" would not necessarily
107076
+** return the value X for which Y was maximal.)
107077
+**
106656107078
**
106657107079
** In this routine, the "p" parameter is a pointer to the outer query.
106658107080
** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
106659107081
** uses aggregates and subqueryIsAgg is true if the subquery uses aggregates.
106660107082
**
@@ -106698,11 +107120,11 @@
106698107120
if( isAgg && subqueryIsAgg ) return 0; /* Restriction (1) */
106699107121
if( subqueryIsAgg && pSrc->nSrc>1 ) return 0; /* Restriction (2) */
106700107122
pSubSrc = pSub->pSrc;
106701107123
assert( pSubSrc );
106702107124
/* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
106703
- ** not arbitrary expresssions, we allowed some combining of LIMIT and OFFSET
107125
+ ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
106704107126
** because they could be computed at compile-time. But when LIMIT and OFFSET
106705107127
** became arbitrary expressions, we were forced to add restrictions (13)
106706107128
** and (14). */
106707107129
if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
106708107130
if( pSub->pOffset ) return 0; /* Restriction (14) */
@@ -106723,12 +107145,18 @@
106723107145
if( isAgg && pSub->pOrderBy ) return 0; /* Restriction (16) */
106724107146
if( pSub->pLimit && p->pWhere ) return 0; /* Restriction (19) */
106725107147
if( pSub->pLimit && (p->selFlags & SF_Distinct)!=0 ){
106726107148
return 0; /* Restriction (21) */
106727107149
}
106728
- if( pSub->selFlags & SF_Recursive ) return 0; /* Restriction (22) */
106729
- if( (p->selFlags & SF_Recursive) && pSub->pPrior ) return 0; /* (23) */
107150
+ testcase( pSub->selFlags & SF_Recursive );
107151
+ testcase( pSub->selFlags & SF_MinMaxAgg );
107152
+ if( pSub->selFlags & (SF_Recursive|SF_MinMaxAgg) ){
107153
+ return 0; /* Restrictions (22) and (24) */
107154
+ }
107155
+ if( (p->selFlags & SF_Recursive) && pSub->pPrior ){
107156
+ return 0; /* Restriction (23) */
107157
+ }
106730107158
106731107159
/* OBSOLETE COMMENT 1:
106732107160
** Restriction 3: If the subquery is a join, make sure the subquery is
106733107161
** not used as the right operand of an outer join. Examples of why this
106734107162
** is not allowed:
@@ -107084,11 +107512,11 @@
107084107512
return eRet;
107085107513
}
107086107514
107087107515
/*
107088107516
** The select statement passed as the first argument is an aggregate query.
107089
-** The second argment is the associated aggregate-info object. This
107517
+** The second argument is the associated aggregate-info object. This
107090107518
** function tests if the SELECT is of the form:
107091107519
**
107092107520
** SELECT count(*) FROM <tbl>
107093107521
**
107094107522
** where table is a database table, not a sub-select or view. If the query
@@ -107414,14 +107842,14 @@
107414107842
** (2) Fill in the pTabList->a[].pTab fields in the SrcList that
107415107843
** defines FROM clause. When views appear in the FROM clause,
107416107844
** fill pTabList->a[].pSelect with a copy of the SELECT statement
107417107845
** that implements the view. A copy is made of the view's SELECT
107418107846
** statement so that we can freely modify or delete that statement
107419
-** without worrying about messing up the presistent representation
107847
+** without worrying about messing up the persistent representation
107420107848
** of the view.
107421107849
**
107422
-** (3) Add terms to the WHERE clause to accomodate the NATURAL keyword
107850
+** (3) Add terms to the WHERE clause to accommodate the NATURAL keyword
107423107851
** on joins and the ON and USING clause of joins.
107424107852
**
107425107853
** (4) Scan the list of columns in the result set (pEList) looking
107426107854
** for instances of the "*" operator or the TABLE.* operator.
107427107855
** If found, expand each "*" to be every column in every table
@@ -108927,14 +109355,14 @@
108927109355
** to the callback function is uses to build the result.
108928109356
*/
108929109357
typedef struct TabResult {
108930109358
char **azResult; /* Accumulated output */
108931109359
char *zErrMsg; /* Error message text, if an error occurs */
108932
- int nAlloc; /* Slots allocated for azResult[] */
108933
- int nRow; /* Number of rows in the result */
108934
- int nColumn; /* Number of columns in the result */
108935
- int nData; /* Slots used in azResult[]. (nRow+1)*nColumn */
109360
+ u32 nAlloc; /* Slots allocated for azResult[] */
109361
+ u32 nRow; /* Number of rows in the result */
109362
+ u32 nColumn; /* Number of columns in the result */
109363
+ u32 nData; /* Slots used in azResult[]. (nRow+1)*nColumn */
108936109364
int rc; /* Return code from sqlite3_exec() */
108937109365
} TabResult;
108938109366
108939109367
/*
108940109368
** This routine is called once for each row in the result table. Its job
@@ -108956,11 +109384,11 @@
108956109384
need = nCol;
108957109385
}
108958109386
if( p->nData + need > p->nAlloc ){
108959109387
char **azNew;
108960109388
p->nAlloc = p->nAlloc*2 + need;
108961
- azNew = sqlite3_realloc( p->azResult, sizeof(char*)*p->nAlloc );
109389
+ azNew = sqlite3_realloc64( p->azResult, sizeof(char*)*p->nAlloc );
108962109390
if( azNew==0 ) goto malloc_failed;
108963109391
p->azResult = azNew;
108964109392
}
108965109393
108966109394
/* If this is the first row, then generate an extra row containing
@@ -108971,11 +109399,11 @@
108971109399
for(i=0; i<nCol; i++){
108972109400
z = sqlite3_mprintf("%s", colv[i]);
108973109401
if( z==0 ) goto malloc_failed;
108974109402
p->azResult[p->nData++] = z;
108975109403
}
108976
- }else if( p->nColumn!=nCol ){
109404
+ }else if( (int)p->nColumn!=nCol ){
108977109405
sqlite3_free(p->zErrMsg);
108978109406
p->zErrMsg = sqlite3_mprintf(
108979109407
"sqlite3_get_table() called with two or more incompatible queries"
108980109408
);
108981109409
p->rc = SQLITE_ERROR;
@@ -109080,11 +109508,11 @@
109080109508
109081109509
/*
109082109510
** This routine frees the space the sqlite3_get_table() malloced.
109083109511
*/
109084109512
SQLITE_API void sqlite3_free_table(
109085
- char **azResult /* Result returned from from sqlite3_get_table() */
109513
+ char **azResult /* Result returned from sqlite3_get_table() */
109086109514
){
109087109515
if( azResult ){
109088109516
int i, n;
109089109517
azResult--;
109090109518
assert( azResult!=0 );
@@ -109224,11 +109652,11 @@
109224109652
**
109225109653
** CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab ....
109226109654
** ^^^^^^^^
109227109655
**
109228109656
** To maintain backwards compatibility, ignore the database
109229
- ** name on pTableName if we are reparsing our of SQLITE_MASTER.
109657
+ ** name on pTableName if we are reparsing out of SQLITE_MASTER.
109230109658
*/
109231109659
if( db->init.busy && iDb!=1 ){
109232109660
sqlite3DbFree(db, pTableName->a[0].zDatabase);
109233109661
pTableName->a[0].zDatabase = 0;
109234109662
}
@@ -110545,11 +110973,11 @@
110545110973
if( isView ){
110546110974
sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
110547110975
}
110548110976
110549110977
/* If we are trying to update a view, realize that view into
110550
- ** a ephemeral table.
110978
+ ** an ephemeral table.
110551110979
*/
110552110980
#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
110553110981
if( isView ){
110554110982
sqlite3MaterializeView(pParse, pTab, pWhere, iDataCur);
110555110983
}
@@ -110706,11 +111134,11 @@
110706111134
sqlite3VdbeAddOp2(v, OP_Copy, regOldRowid, regNewRowid);
110707111135
}
110708111136
}
110709111137
110710111138
/* Populate the array of registers beginning at regNew with the new
110711
- ** row data. This array is used to check constaints, create the new
111139
+ ** row data. This array is used to check constants, create the new
110712111140
** table and index records, and as the values for any new.* references
110713111141
** made by triggers.
110714111142
**
110715111143
** If there are one or more BEFORE triggers, then do not populate the
110716111144
** registers associated with columns that are (a) not modified by
@@ -110886,11 +111314,11 @@
110886111314
sqlite3ExprListDelete(db, pChanges);
110887111315
sqlite3ExprDelete(db, pWhere);
110888111316
return;
110889111317
}
110890111318
/* Make sure "isView" and other macros defined above are undefined. Otherwise
110891
-** thely may interfere with compilation of other functions in this file
111319
+** they may interfere with compilation of other functions in this file
110892111320
** (or in another file, if this file becomes part of the amalgamation). */
110893111321
#ifdef isView
110894111322
#undef isView
110895111323
#endif
110896111324
#ifdef pTrigger
@@ -110899,19 +111327,19 @@
110899111327
110900111328
#ifndef SQLITE_OMIT_VIRTUALTABLE
110901111329
/*
110902111330
** Generate code for an UPDATE of a virtual table.
110903111331
**
110904
-** The strategy is that we create an ephemerial table that contains
111332
+** The strategy is that we create an ephemeral table that contains
110905111333
** for each row to be changed:
110906111334
**
110907111335
** (A) The original rowid of that row.
110908111336
** (B) The revised rowid for the row. (note1)
110909111337
** (C) The content of every column in the row.
110910111338
**
110911111339
** Then we loop over this ephemeral table and for each row in
110912
-** the ephermeral table call VUpdate.
111340
+** the ephemeral table call VUpdate.
110913111341
**
110914111342
** When finished, drop the ephemeral table.
110915111343
**
110916111344
** (note1) Actually, if we know in advance that (A) is always the same
110917111345
** as (B) we only store (A), then duplicate (A) when pulling
@@ -111080,11 +111508,11 @@
111080111508
** The transient database requires temporary disk space approximately
111081111509
** equal to the size of the original database. The copy operation of
111082111510
** step (3) requires additional temporary disk space approximately equal
111083111511
** to the size of the original database for the rollback journal.
111084111512
** Hence, temporary disk space that is approximately 2x the size of the
111085
-** orginal database is required. Every page of the database is written
111513
+** original database is required. Every page of the database is written
111086111514
** approximately 3 times: Once for step (2) and twice for step (3).
111087111515
** Two writes per page are required in step (3) because the original
111088111516
** database content must be written into the rollback journal prior to
111089111517
** overwriting the database with the vacuumed content.
111090111518
**
@@ -112659,11 +113087,11 @@
112659113087
**
112660113088
** The "solver" works by creating the N best WherePath objects of length
112661113089
** 1. Then using those as a basis to compute the N best WherePath objects
112662113090
** of length 2. And so forth until the length of WherePaths equals the
112663113091
** number of nodes in the FROM clause. The best (lowest cost) WherePath
112664
-** at the end is the choosen query plan.
113092
+** at the end is the chosen query plan.
112665113093
*/
112666113094
struct WherePath {
112667113095
Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */
112668113096
Bitmask revLoop; /* aLoop[]s that should be reversed for ORDER BY */
112669113097
LogEst nRow; /* Estimated number of rows generated by this path */
@@ -113628,11 +114056,11 @@
113628114056
if( *pisComplete && pRight->u.zToken[1] ){
113629114057
/* If the rhs of the LIKE expression is a variable, and the current
113630114058
** value of the variable means there is no need to invoke the LIKE
113631114059
** function, then no OP_Variable will be added to the program.
113632114060
** This causes problems for the sqlite3_bind_parameter_name()
113633
- ** API. To workaround them, add a dummy OP_Variable here.
114061
+ ** API. To work around them, add a dummy OP_Variable here.
113634114062
*/
113635114063
int r1 = sqlite3GetTempReg(pParse);
113636114064
sqlite3ExprCodeTarget(pParse, pRight, r1);
113637114065
sqlite3VdbeChangeP3(v, sqlite3VdbeCurrentAddr(v)-1, 0);
113638114066
sqlite3ReleaseTempReg(pParse, r1);
@@ -113748,11 +114176,11 @@
113748114176
** This analysis does not consider whether or not the index exists; that
113749114177
** is decided elsewhere. This analysis only looks at whether subterms
113750114178
** appropriate for indexing exist.
113751114179
**
113752114180
** All examples A through E above satisfy case 2. But if a term
113753
-** also statisfies case 1 (such as B) we know that the optimizer will
114181
+** also satisfies case 1 (such as B) we know that the optimizer will
113754114182
** always prefer case 1, so in that case we pretend that case 2 is not
113755114183
** satisfied.
113756114184
**
113757114185
** It might be the case that multiple tables are indexable. For example,
113758114186
** (E) above is indexable on tables P, Q, and R.
@@ -113906,11 +114334,11 @@
113906114334
assert( j==1 );
113907114335
continue;
113908114336
}
113909114337
if( (chngToIN & getMask(&pWInfo->sMaskSet, pOrTerm->leftCursor))==0 ){
113910114338
/* This term must be of the form t1.a==t2.b where t2 is in the
113911
- ** chngToIN set but t1 is not. This term will be either preceeded
114339
+ ** chngToIN set but t1 is not. This term will be either preceded
113912114340
** or follwed by an inverted copy (t2.b==t1.a). Skip this term
113913114341
** and use its inversion. */
113914114342
testcase( pOrTerm->wtFlags & TERM_COPIED );
113915114343
testcase( pOrTerm->wtFlags & TERM_VIRTUAL );
113916114344
assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) );
@@ -114317,11 +114745,11 @@
114317114745
*/
114318114746
pTerm->prereqRight |= extraRight;
114319114747
}
114320114748
114321114749
/*
114322
-** This function searches pList for a entry that matches the iCol-th column
114750
+** This function searches pList for an entry that matches the iCol-th column
114323114751
** of index pIdx.
114324114752
**
114325114753
** If such an expression is found, its index in pList->a[] is returned. If
114326114754
** no expression is found, -1 is returned.
114327114755
*/
@@ -114840,11 +115268,11 @@
114840115268
iCol = pRec->nField - 1;
114841115269
assert( pIdx->nSample>0 );
114842115270
assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
114843115271
do{
114844115272
iTest = (iMin+i)/2;
114845
- res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec, 0);
115273
+ res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec);
114846115274
if( res<0 ){
114847115275
iMin = iTest+1;
114848115276
}else{
114849115277
i = iTest;
114850115278
}
@@ -114855,20 +115283,20 @@
114855115283
** above found the right answer. This block serves no purpose other
114856115284
** than to invoke the asserts. */
114857115285
if( res==0 ){
114858115286
/* If (res==0) is true, then sample $i must be equal to pRec */
114859115287
assert( i<pIdx->nSample );
114860
- assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec, 0)
115288
+ assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)
114861115289
|| pParse->db->mallocFailed );
114862115290
}else{
114863115291
/* Otherwise, pRec must be smaller than sample $i and larger than
114864115292
** sample ($i-1). */
114865115293
assert( i==pIdx->nSample
114866
- || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec, 0)>0
115294
+ || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0
114867115295
|| pParse->db->mallocFailed );
114868115296
assert( i==0
114869
- || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec, 0)<0
115297
+ || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0
114870115298
|| pParse->db->mallocFailed );
114871115299
}
114872115300
#endif /* ifdef SQLITE_DEBUG */
114873115301
114874115302
/* At this point, aSample[i] is the first sample that is greater than
@@ -115067,11 +115495,11 @@
115067115495
**
115068115496
** When this function is called, *pnOut is set to the sqlite3LogEst() of the
115069115497
** number of rows that the index scan is expected to visit without
115070115498
** considering the range constraints. If nEq is 0, this is the number of
115071115499
** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
115072
-** to account for the range contraints pLower and pUpper.
115500
+** to account for the range constraints pLower and pUpper.
115073115501
**
115074115502
** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be
115075115503
** used, a single range inequality reduces the search space by a factor of 4.
115076115504
** and a pair of constraints (x>? AND x<?) reduces the expected number of
115077115505
** rows visited by a factor of 64.
@@ -116344,11 +116772,11 @@
116344116772
** Return 2 # Jump back to the Gosub
116345116773
**
116346116774
** B: <after the loop>
116347116775
**
116348116776
** Added 2014-05-26: If the table is a WITHOUT ROWID table, then
116349
- ** use an ephermeral index instead of a RowSet to record the primary
116777
+ ** use an ephemeral index instead of a RowSet to record the primary
116350116778
** keys of the rows we have already seen.
116351116779
**
116352116780
*/
116353116781
WhereClause *pOrWc; /* The OR-clause broken out into subterms */
116354116782
SrcList *pOrTab; /* Shortened table list or OR-clause generation */
@@ -116395,11 +116823,11 @@
116395116823
}else{
116396116824
pOrTab = pWInfo->pTabList;
116397116825
}
116398116826
116399116827
/* Initialize the rowset register to contain NULL. An SQL NULL is
116400
- ** equivalent to an empty rowset. Or, create an ephermeral index
116828
+ ** equivalent to an empty rowset. Or, create an ephemeral index
116401116829
** capable of holding primary keys in the case of a WITHOUT ROWID.
116402116830
**
116403116831
** Also initialize regReturn to contain the address of the instruction
116404116832
** immediately following the OP_Return at the bottom of the loop. This
116405116833
** is required in a few obscure LEFT JOIN cases where control jumps
@@ -117148,18 +117576,20 @@
117148117576
**
117149117577
** In the current implementation, the first extra WHERE clause term reduces
117150117578
** the number of output rows by a factor of 10 and each additional term
117151117579
** reduces the number of output rows by sqrt(2).
117152117580
*/
117153
-static void whereLoopOutputAdjust(WhereClause *pWC, WhereLoop *pLoop){
117581
+static void whereLoopOutputAdjust(
117582
+ WhereClause *pWC, /* The WHERE clause */
117583
+ WhereLoop *pLoop, /* The loop to adjust downward */
117584
+ LogEst nRow /* Number of rows in the entire table */
117585
+){
117154117586
WhereTerm *pTerm, *pX;
117155117587
Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf);
117156117588
int i, j;
117589
+ int nEq = 0; /* Number of = constraints not within likely()/unlikely() */
117157117590
117158
- if( !OptimizationEnabled(pWC->pWInfo->pParse->db, SQLITE_AdjustOutEst) ){
117159
- return;
117160
- }
117161117591
for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){
117162117592
if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
117163117593
if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
117164117594
if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
117165117595
for(j=pLoop->nLTerm-1; j>=0; j--){
@@ -117167,12 +117597,24 @@
117167117597
if( pX==0 ) continue;
117168117598
if( pX==pTerm ) break;
117169117599
if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
117170117600
}
117171117601
if( j<0 ){
117172
- pLoop->nOut += (pTerm->truthProb<=0 ? pTerm->truthProb : -1);
117602
+ if( pTerm->truthProb<=0 ){
117603
+ pLoop->nOut += pTerm->truthProb;
117604
+ }else{
117605
+ pLoop->nOut--;
117606
+ if( pTerm->eOperator&WO_EQ ) nEq++;
117607
+ }
117173117608
}
117609
+ }
117610
+ /* TUNING: If there is at least one equality constraint in the WHERE
117611
+ ** clause that does not have a likelihood() explicitly assigned to it
117612
+ ** then do not let the estimated number of output rows exceed half
117613
+ ** the number of rows in the table. */
117614
+ if( nEq && pLoop->nOut>nRow-10 ){
117615
+ pLoop->nOut = nRow - 10;
117174117616
}
117175117617
}
117176117618
117177117619
/*
117178117620
** Adjust the cost C by the costMult facter T. This only occurs if
@@ -117215,10 +117657,11 @@
117215117657
u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */
117216117658
u32 saved_wsFlags; /* Original value of pNew->wsFlags */
117217117659
LogEst saved_nOut; /* Original value of pNew->nOut */
117218117660
int iCol; /* Index of the column in the table */
117219117661
int rc = SQLITE_OK; /* Return code */
117662
+ LogEst rSize; /* Number of rows in the table */
117220117663
LogEst rLogSize; /* Logarithm of table size */
117221117664
WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
117222117665
117223117666
pNew = pBuilder->pNew;
117224117667
if( db->mallocFailed ) return SQLITE_NOMEM;
@@ -117244,11 +117687,12 @@
117244117687
saved_nLTerm = pNew->nLTerm;
117245117688
saved_wsFlags = pNew->wsFlags;
117246117689
saved_prereq = pNew->prereq;
117247117690
saved_nOut = pNew->nOut;
117248117691
pNew->rSetup = 0;
117249
- rLogSize = estLog(pProbe->aiRowLogEst[0]);
117692
+ rSize = pProbe->aiRowLogEst[0];
117693
+ rLogSize = estLog(rSize);
117250117694
117251117695
/* Consider using a skip-scan if there are no WHERE clause constraints
117252117696
** available for the left-most terms of the index, and if the average
117253117697
** number of repeats in the left-most terms is at least 18.
117254117698
**
@@ -117421,11 +117865,11 @@
117421117865
ApplyCostMultiplier(pNew->rRun, pProbe->pTable->costMult);
117422117866
117423117867
nOutUnadjusted = pNew->nOut;
117424117868
pNew->rRun += nInMul + nIn;
117425117869
pNew->nOut += nInMul + nIn;
117426
- whereLoopOutputAdjust(pBuilder->pWC, pNew);
117870
+ whereLoopOutputAdjust(pBuilder->pWC, pNew, rSize);
117427117871
rc = whereLoopInsert(pBuilder, pNew);
117428117872
117429117873
if( pNew->wsFlags & WHERE_COLUMN_RANGE ){
117430117874
pNew->nOut = saved_nOut;
117431117875
}else{
@@ -117471,10 +117915,11 @@
117471117915
if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
117472117916
for(ii=0; ii<pOB->nExpr; ii++){
117473117917
Expr *pExpr = sqlite3ExprSkipCollate(pOB->a[ii].pExpr);
117474117918
if( pExpr->op!=TK_COLUMN ) return 0;
117475117919
if( pExpr->iTable==iCursor ){
117920
+ if( pExpr->iColumn<0 ) return 1;
117476117921
for(jj=0; jj<pIndex->nKeyCol; jj++){
117477117922
if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1;
117478117923
}
117479117924
}
117480117925
}
@@ -117634,11 +118079,11 @@
117634118079
** the table being indexed. */
117635118080
pNew->rSetup = rLogSize + rSize + 28; assert( 28==sqlite3LogEst(7) );
117636118081
ApplyCostMultiplier(pNew->rSetup, pTab->costMult);
117637118082
/* TUNING: Each index lookup yields 20 rows in the table. This
117638118083
** is more than the usual guess of 10 rows, since we have no way
117639
- ** of knowning how selective the index will ultimately be. It would
118084
+ ** of knowing how selective the index will ultimately be. It would
117640118085
** not be unreasonable to make this value much larger. */
117641118086
pNew->nOut = 43; assert( 43==sqlite3LogEst(20) );
117642118087
pNew->rRun = sqlite3LogEstAdd(rLogSize,pNew->nOut);
117643118088
pNew->wsFlags = WHERE_AUTO_INDEX;
117644118089
pNew->prereq = mExtra | pTerm->prereqRight;
@@ -117675,11 +118120,11 @@
117675118120
/* Full table scan */
117676118121
pNew->iSortIdx = b ? iSortIdx : 0;
117677118122
/* TUNING: Cost of full table scan is (N*3.0). */
117678118123
pNew->rRun = rSize + 16;
117679118124
ApplyCostMultiplier(pNew->rRun, pTab->costMult);
117680
- whereLoopOutputAdjust(pWC, pNew);
118125
+ whereLoopOutputAdjust(pWC, pNew, rSize);
117681118126
rc = whereLoopInsert(pBuilder, pNew);
117682118127
pNew->nOut = rSize;
117683118128
if( rc ) break;
117684118129
}else{
117685118130
Bitmask m;
@@ -117711,11 +118156,11 @@
117711118156
pNew->rRun = rSize + 1 + (15*pProbe->szIdxRow)/pTab->szTabRow;
117712118157
if( m!=0 ){
117713118158
pNew->rRun = sqlite3LogEstAdd(pNew->rRun, rSize+16);
117714118159
}
117715118160
ApplyCostMultiplier(pNew->rRun, pTab->costMult);
117716
- whereLoopOutputAdjust(pWC, pNew);
118161
+ whereLoopOutputAdjust(pWC, pNew, rSize);
117717118162
rc = whereLoopInsert(pBuilder, pNew);
117718118163
pNew->nOut = rSize;
117719118164
if( rc ) break;
117720118165
}
117721118166
}
@@ -118064,11 +118509,11 @@
118064118509
**
118065118510
** Note that processing for WHERE_GROUPBY and WHERE_DISTINCTBY is not as
118066118511
** strict. With GROUP BY and DISTINCT the only requirement is that
118067118512
** equivalent rows appear immediately adjacent to one another. GROUP BY
118068118513
** and DISTINCT do not require rows to appear in any particular order as long
118069
-** as equivelent rows are grouped together. Thus for GROUP BY and DISTINCT
118514
+** as equivalent rows are grouped together. Thus for GROUP BY and DISTINCT
118070118515
** the pOrderBy terms can be matched in any order. With ORDER BY, the
118071118516
** pOrderBy terms must be matched in strict left-to-right order.
118072118517
*/
118073118518
static i8 wherePathSatisfiesOrderBy(
118074118519
WhereInfo *pWInfo, /* The WHERE clause */
@@ -120841,13 +121286,13 @@
120841121286
**
120842121287
** Outputs:
120843121288
** A pointer to a parser. This pointer is used in subsequent calls
120844121289
** to sqlite3Parser and sqlite3ParserFree.
120845121290
*/
120846
-SQLITE_PRIVATE void *sqlite3ParserAlloc(void *(*mallocProc)(size_t)){
121291
+SQLITE_PRIVATE void *sqlite3ParserAlloc(void *(*mallocProc)(u64)){
120847121292
yyParser *pParser;
120848
- pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
121293
+ pParser = (yyParser*)(*mallocProc)( (u64)sizeof(yyParser) );
120849121294
if( pParser ){
120850121295
pParser->yyidx = -1;
120851121296
#ifdef YYTRACKMAXSTACKDEPTH
120852121297
pParser->yyidxMax = 0;
120853121298
#endif
@@ -123398,11 +123843,11 @@
123398123843
**
123399123844
** For EBCDIC, the rules are more complex but have the same
123400123845
** end result.
123401123846
**
123402123847
** Ticket #1066. the SQL standard does not allow '$' in the
123403
-** middle of identfiers. But many SQL implementations do.
123848
+** middle of identifiers. But many SQL implementations do.
123404123849
** SQLite will allow '$' in identifiers for compatibility.
123405123850
** But the feature is undocumented.
123406123851
*/
123407123852
#ifdef SQLITE_ASCII
123408123853
#define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)
@@ -123719,11 +124164,11 @@
123719124164
}
123720124165
pParse->rc = SQLITE_OK;
123721124166
pParse->zTail = zSql;
123722124167
i = 0;
123723124168
assert( pzErrMsg!=0 );
123724
- pEngine = sqlite3ParserAlloc((void*(*)(size_t))sqlite3Malloc);
124169
+ pEngine = sqlite3ParserAlloc(sqlite3Malloc);
123725124170
if( pEngine==0 ){
123726124171
db->mallocFailed = 1;
123727124172
return SQLITE_NOMEM;
123728124173
}
123729124174
assert( pParse->pNewTable==0 );
@@ -123914,21 +124359,21 @@
123914124359
**
123915124360
** (3) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
123916124361
** a statement.
123917124362
**
123918124363
** (4) CREATE The keyword CREATE has been seen at the beginning of a
123919
-** statement, possibly preceeded by EXPLAIN and/or followed by
124364
+** statement, possibly preceded by EXPLAIN and/or followed by
123920124365
** TEMP or TEMPORARY
123921124366
**
123922124367
** (5) TRIGGER We are in the middle of a trigger definition that must be
123923124368
** ended by a semicolon, the keyword END, and another semicolon.
123924124369
**
123925124370
** (6) SEMI We've seen the first semicolon in the ";END;" that occurs at
123926124371
** the end of a trigger definition.
123927124372
**
123928124373
** (7) END We've seen the ";END" of the ";END;" that occurs at the end
123929
-** of a trigger difinition.
124374
+** of a trigger definition.
123930124375
**
123931124376
** Transitions between states above are determined by tokens extracted
123932124377
** from the input. The following tokens are significant:
123933124378
**
123934124379
** (0) tkSEMI A semicolon.
@@ -123967,11 +124412,11 @@
123967124412
/* 6 SEMI: */ { 6, 6, 5, 5, 5, 5, 5, 7, },
123968124413
/* 7 END: */ { 1, 7, 5, 5, 5, 5, 5, 5, },
123969124414
};
123970124415
#else
123971124416
/* If triggers are not supported by this compile then the statement machine
123972
- ** used to detect the end of a statement is much simplier
124417
+ ** used to detect the end of a statement is much simpler
123973124418
*/
123974124419
static const u8 trans[3][3] = {
123975124420
/* Token: */
123976124421
/* State: ** SEMI WS OTHER */
123977124422
/* 0 INVALID: */ { 1, 0, 2, },
@@ -125202,10 +125647,14 @@
125202125647
#endif
125203125648
125204125649
sqlite3Error(db, SQLITE_OK); /* Deallocates any cached error strings. */
125205125650
sqlite3ValueFree(db->pErr);
125206125651
sqlite3CloseExtensions(db);
125652
+#if SQLITE_USER_AUTHENTICATION
125653
+ sqlite3_free(db->auth.zAuthUser);
125654
+ sqlite3_free(db->auth.zAuthPW);
125655
+#endif
125207125656
125208125657
db->magic = SQLITE_MAGIC_ERROR;
125209125658
125210125659
/* The temp-database schema is allocated differently from the other schema
125211125660
** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
@@ -126783,11 +127232,10 @@
126783127232
goto opendb_out;
126784127233
}
126785127234
db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
126786127235
db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
126787127236
126788
-
126789127237
/* The default safety_level for the main database is 'full'; for the temp
126790127238
** database it is 'NONE'. This matches the pager layer defaults.
126791127239
*/
126792127240
db->aDb[0].zName = "main";
126793127241
db->aDb[0].safety_level = 3;
@@ -127070,13 +127518,13 @@
127070127518
SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
127071127519
return db->autoCommit;
127072127520
}
127073127521
127074127522
/*
127075
-** The following routines are subtitutes for constants SQLITE_CORRUPT,
127523
+** The following routines are substitutes for constants SQLITE_CORRUPT,
127076127524
** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_IOERR and possibly other error
127077
-** constants. They server two purposes:
127525
+** constants. They serve two purposes:
127078127526
**
127079127527
** 1. Serve as a convenient place to set a breakpoint in a debugger
127080127528
** to detect when version error conditions occurs.
127081127529
**
127082127530
** 2. Invoke sqlite3_log() to provide the source code location where
@@ -127386,11 +127834,11 @@
127386127834
** as it existing before this routine was called.
127387127835
**
127388127836
** IMPORTANT: Changing the PENDING byte from 0x40000000 results in
127389127837
** an incompatible database file format. Changing the PENDING byte
127390127838
** while any database connection is open results in undefined and
127391
- ** dileterious behavior.
127839
+ ** deleterious behavior.
127392127840
*/
127393127841
case SQLITE_TESTCTRL_PENDING_BYTE: {
127394127842
rc = PENDING_BYTE;
127395127843
#ifndef SQLITE_OMIT_WSD
127396127844
{
127397127845
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -73,10 +73,19 @@
73 # define _FILE_OFFSET_BITS 64
74 # endif
75 # define _LARGEFILE_SOURCE 1
76 #endif
77
 
 
 
 
 
 
 
 
 
78 /*
79 ** For MinGW, check to see if we can include the header file containing its
80 ** version information, among other things. Normally, this internal MinGW
81 ** header file would [only] be included automatically by other MinGW header
82 ** files; however, the contained version information is now required by this
@@ -222,11 +231,11 @@
222 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223 ** [sqlite_version()] and [sqlite_source_id()].
224 */
225 #define SQLITE_VERSION "3.8.7"
226 #define SQLITE_VERSION_NUMBER 3008007
227 #define SQLITE_SOURCE_ID "2014-09-01 18:21:27 672e7387b1bda8d007da7de4244226577d7ab2dc"
228
229 /*
230 ** CAPI3REF: Run-Time Library Version Numbers
231 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
232 **
@@ -610,10 +619,11 @@
610 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
611 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
612 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
613 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
614 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
 
615
616 /*
617 ** CAPI3REF: Flags For File Open Operations
618 **
619 ** These bit values are intended for use in the
@@ -2212,11 +2222,11 @@
2212 **
2213 ** ^Calling this routine with an argument less than or equal to zero
2214 ** turns off all busy handlers.
2215 **
2216 ** ^(There can only be a single busy handler for a particular
2217 ** [database connection] any any given moment. If another busy handler
2218 ** was defined (using [sqlite3_busy_handler()]) prior to calling
2219 ** this routine, that other busy handler is cleared.)^
2220 **
2221 ** See also: [PRAGMA busy_timeout]
2222 */
@@ -2415,10 +2425,14 @@
2415 ** of memory at least N bytes in length, where N is the parameter.
2416 ** ^If sqlite3_malloc() is unable to obtain sufficient free
2417 ** memory, it returns a NULL pointer. ^If the parameter N to
2418 ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
2419 ** a NULL pointer.
 
 
 
 
2420 **
2421 ** ^Calling sqlite3_free() with a pointer previously returned
2422 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
2423 ** that it might be reused. ^The sqlite3_free() routine is
2424 ** a no-op if is called with a NULL pointer. Passing a NULL pointer
@@ -2427,28 +2441,42 @@
2427 ** memory might result in a segmentation fault or other severe error.
2428 ** Memory corruption, a segmentation fault, or other severe error
2429 ** might result if sqlite3_free() is called with a non-NULL pointer that
2430 ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
2431 **
2432 ** ^(The sqlite3_realloc() interface attempts to resize a
2433 ** prior memory allocation to be at least N bytes, where N is the
2434 ** second parameter. The memory allocation to be resized is the first
2435 ** parameter.)^ ^ If the first parameter to sqlite3_realloc()
2436 ** is a NULL pointer then its behavior is identical to calling
2437 ** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().
2438 ** ^If the second parameter to sqlite3_realloc() is zero or
2439 ** negative then the behavior is exactly the same as calling
2440 ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
2441 ** ^sqlite3_realloc() returns a pointer to a memory allocation
2442 ** of at least N bytes in size or NULL if sufficient memory is unavailable.
2443 ** ^If M is the size of the prior allocation, then min(N,M) bytes
2444 ** of the prior allocation are copied into the beginning of buffer returned
2445 ** by sqlite3_realloc() and the prior allocation is freed.
2446 ** ^If sqlite3_realloc() returns NULL, then the prior allocation
2447 ** is not freed.
2448 **
2449 ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2450 ** is always aligned to at least an 8 byte boundary, or to a
2451 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
2452 ** option is used.
2453 **
2454 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
@@ -2472,12 +2500,15 @@
2472 ** The application must not read or write any part of
2473 ** a block of memory after it has been released using
2474 ** [sqlite3_free()] or [sqlite3_realloc()].
2475 */
2476 SQLITE_API void *sqlite3_malloc(int);
 
2477 SQLITE_API void *sqlite3_realloc(void*, int);
 
2478 SQLITE_API void sqlite3_free(void*);
 
2479
2480 /*
2481 ** CAPI3REF: Memory Allocator Statistics
2482 **
2483 ** SQLite provides these two interfaces for reporting on the status
@@ -3482,11 +3513,12 @@
3482 ** is negative, then the length of the string is
3483 ** the number of bytes up to the first zero terminator.
3484 ** If the fourth parameter to sqlite3_bind_blob() is negative, then
3485 ** the behavior is undefined.
3486 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3487 ** or sqlite3_bind_text16() then that parameter must be the byte offset
 
3488 ** where the NUL terminator would occur assuming the string were NUL
3489 ** terminated. If any NUL characters occur at byte offsets less than
3490 ** the value of the fourth parameter then the resulting string value will
3491 ** contain embedded NULs. The result of expressions involving strings
3492 ** with embedded NULs is undefined.
@@ -3500,10 +3532,18 @@
3500 ** the special value [SQLITE_STATIC], then SQLite assumes that the
3501 ** information is in static, unmanaged space and does not need to be freed.
3502 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
3503 ** SQLite makes its own private copy of the data immediately, before
3504 ** the sqlite3_bind_*() routine returns.
 
 
 
 
 
 
 
 
3505 **
3506 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
3507 ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
3508 ** (just an integer to hold its size) while it is being processed.
3509 ** Zeroblobs are intended to serve as placeholders for BLOBs whose
@@ -3521,23 +3561,30 @@
3521 ** ^Bindings are not cleared by the [sqlite3_reset()] routine.
3522 ** ^Unbound parameters are interpreted as NULL.
3523 **
3524 ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
3525 ** [error code] if anything goes wrong.
 
 
 
3526 ** ^[SQLITE_RANGE] is returned if the parameter
3527 ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
3528 **
3529 ** See also: [sqlite3_bind_parameter_count()],
3530 ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
3531 */
3532 SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
 
 
3533 SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
3534 SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
3535 SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
3536 SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
3537 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
3538 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
 
 
3539 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3540 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3541
3542 /*
3543 ** CAPI3REF: Number Of SQL Parameters
@@ -4282,11 +4329,11 @@
4282 ** These routines work only with [protected sqlite3_value] objects.
4283 ** Any attempt to use these routines on an [unprotected sqlite3_value]
4284 ** object results in undefined behavior.
4285 **
4286 ** ^These routines work just like the corresponding [column access functions]
4287 ** except that these routines take a single [protected sqlite3_value] object
4288 ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
4289 **
4290 ** ^The sqlite3_value_text16() interface extracts a UTF-16 string
4291 ** in the native byte-order of the host machine. ^The
4292 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
@@ -4525,14 +4572,18 @@
4525 **
4526 ** ^The sqlite3_result_null() interface sets the return value
4527 ** of the application-defined function to be NULL.
4528 **
4529 ** ^The sqlite3_result_text(), sqlite3_result_text16(),
4530 ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
4531 ** set the return value of the application-defined function to be
4532 ** a text string which is represented as UTF-8, UTF-16 native byte order,
4533 ** UTF-16 little endian, or UTF-16 big endian, respectively.
 
 
 
 
4534 ** ^SQLite takes the text result from the application from
4535 ** the 2nd parameter of the sqlite3_result_text* interfaces.
4536 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
4537 ** is negative, then SQLite takes result text from the 2nd parameter
4538 ** through the first zero character.
@@ -4572,10 +4623,11 @@
4572 ** If these routines are called from within the different thread
4573 ** than the one containing the application-defined function that received
4574 ** the [sqlite3_context] pointer, the results are undefined.
4575 */
4576 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
 
4577 SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
4578 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
4579 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
4580 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
4581 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
@@ -4582,10 +4634,12 @@
4582 SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
4583 SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
4584 SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
4585 SQLITE_API void sqlite3_result_null(sqlite3_context*);
4586 SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
 
 
4587 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
4588 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
4589 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
4590 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4591 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
@@ -6475,25 +6529,25 @@
6475 ** memory already being in use.
6476 ** Only the high-water value is meaningful;
6477 ** the current value is always zero.)^
6478 **
6479 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6480 ** <dd>This parameter returns the approximate number of of bytes of heap
6481 ** memory used by all pager caches associated with the database connection.)^
6482 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
6483 **
6484 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
6485 ** <dd>This parameter returns the approximate number of of bytes of heap
6486 ** memory used to store the schema for all databases associated
6487 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
6488 ** ^The full amount of memory used by the schemas is reported, even if the
6489 ** schema memory is shared with other database connections due to
6490 ** [shared cache mode] being enabled.
6491 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
6492 **
6493 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
6494 ** <dd>This parameter returns the approximate number of of bytes of heap
6495 ** and lookaside memory used by all prepared statements associated with
6496 ** the database connection.)^
6497 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
6498 ** </dd>
6499 **
@@ -7846,19 +7900,10 @@
7846 #pragma warn -aus /* Assigned value is never used */
7847 #pragma warn -csu /* Comparing signed and unsigned */
7848 #pragma warn -spa /* Suspicious pointer arithmetic */
7849 #endif
7850
7851 /* Needed for various definitions... */
7852 #ifndef _GNU_SOURCE
7853 # define _GNU_SOURCE
7854 #endif
7855
7856 #if defined(__OpenBSD__) && !defined(_BSD_SOURCE)
7857 # define _BSD_SOURCE
7858 #endif
7859
7860 /*
7861 ** Include standard header files as necessary
7862 */
7863 #ifdef HAVE_STDINT_H
7864 #include <stdint.h>
@@ -8093,11 +8138,11 @@
8093 # define ALWAYS(X) (X)
8094 # define NEVER(X) (X)
8095 #endif
8096
8097 /*
8098 ** Return true (non-zero) if the input is a integer that is too large
8099 ** to fit in 32-bits. This macro is used inside of various testcase()
8100 ** macros to verify that we have tested SQLite for large-file support.
8101 */
8102 #define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0)
8103
@@ -8644,11 +8689,11 @@
8644 ** Assert that the pointer X is aligned to an 8-byte boundary. This
8645 ** macro is used only within assert() to verify that the code gets
8646 ** all alignment restrictions correct.
8647 **
8648 ** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the
8649 ** underlying malloc() implemention might return us 4-byte aligned
8650 ** pointers. In that case, only verify 4-byte alignment.
8651 */
8652 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
8653 # define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&3)==0)
8654 #else
@@ -9537,14 +9582,14 @@
9537 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
9538 #endif
9539 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
9540
9541 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
9542 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*,int);
9543 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
9544
9545 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*,int);
9546 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
9547
9548 #ifndef SQLITE_OMIT_TRIGGER
9549 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
9550 #endif
@@ -10180,11 +10225,11 @@
10180 ** SHARED_SIZE is the number of bytes available in the pool from which
10181 ** a random byte is selected for a shared lock. The pool of bytes for
10182 ** shared locks begins at SHARED_FIRST.
10183 **
10184 ** The same locking strategy and
10185 ** byte ranges are used for Unix. This leaves open the possiblity of having
10186 ** clients on win95, winNT, and unix all talking to the same shared file
10187 ** and all locking correctly. To do so would require that samba (or whatever
10188 ** tool is being used for file sharing) implements locks correctly between
10189 ** windows and unix. I'm guessing that isn't likely to happen, but by
10190 ** using the same locking range we are at least open to the possibility.
@@ -10299,11 +10344,11 @@
10299
10300 /*
10301 ** Figure out what version of the code to use. The choices are
10302 **
10303 ** SQLITE_MUTEX_OMIT No mutex logic. Not even stubs. The
10304 ** mutexes implemention cannot be overridden
10305 ** at start-time.
10306 **
10307 ** SQLITE_MUTEX_NOOP For single-threaded applications. No
10308 ** mutual exclusion is provided. But this
10309 ** implementation can be overridden at
@@ -10465,10 +10510,49 @@
10465 ** Collisions are on the FuncDef.pHash chain.
10466 */
10467 struct FuncDefHash {
10468 FuncDef *a[23]; /* Hash table for functions */
10469 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10470
10471 /*
10472 ** Each database connection is an instance of the following structure.
10473 */
10474 struct sqlite3 {
@@ -10533,12 +10617,11 @@
10533 volatile int isInterrupted; /* True if sqlite3_interrupt has been called */
10534 double notUsed1; /* Spacer */
10535 } u1;
10536 Lookaside lookaside; /* Lookaside malloc configuration */
10537 #ifndef SQLITE_OMIT_AUTHORIZATION
10538 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
10539 /* Access authorization function */
10540 void *pAuthArg; /* 1st argument to the access auth function */
10541 #endif
10542 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
10543 int (*xProgress)(void *); /* The progress callback */
10544 void *pProgressArg; /* Argument to the progress callback */
@@ -10560,11 +10643,10 @@
10560 int nSavepoint; /* Number of non-transaction savepoints */
10561 int nStatement; /* Number of nested statement-transactions */
10562 i64 nDeferredCons; /* Net deferred constraints this transaction. */
10563 i64 nDeferredImmCons; /* Net deferred immediate constraints */
10564 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
10565
10566 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
10567 /* The following variables are all protected by the STATIC_MASTER
10568 ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
10569 **
10570 ** When X.pUnlockConnection==Y, that means that X is waiting for Y to
@@ -10578,10 +10660,13 @@
10578 sqlite3 *pUnlockConnection; /* Connection to watch for unlock */
10579 void *pUnlockArg; /* Argument to xUnlockNotify */
10580 void (*xUnlockNotify)(void **, int); /* Unlock notify callback */
10581 sqlite3 *pNextBlocked; /* Next in list of all blocked connections */
10582 #endif
 
 
 
10583 };
10584
10585 /*
10586 ** A macro to discover the encoding of a database.
10587 */
@@ -10637,11 +10722,10 @@
10637 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10638 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10639 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
10640 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
10641 #define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */
10642 #define SQLITE_AdjustOutEst 0x1000 /* Adjust output estimates using WHERE */
10643 #define SQLITE_AllOpts 0xffff /* All optimizations */
10644
10645 /*
10646 ** Macros for testing whether or not optimizations are enabled or disabled.
10647 */
@@ -10724,10 +10808,11 @@
10724 #define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
10725 #define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
10726 #define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
10727 #define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
10728 #define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */
 
10729
10730 /*
10731 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
10732 ** used to create the initializers for the FuncDef structures.
10733 **
@@ -10770,10 +10855,13 @@
10770 #define LIKEFUNC(zName, nArg, arg, flags) \
10771 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
10772 (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
10773 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
10774 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
 
 
 
10775 SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
10776
10777 /*
10778 ** All current savepoints are stored in a linked list starting at
10779 ** sqlite3.pSavepoint. The first element in the list is the most recently
@@ -10857,30 +10945,30 @@
10857 **
10858 ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
10859 ** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve
10860 ** the speed a little by numbering the values consecutively.
10861 **
10862 ** But rather than start with 0 or 1, we begin with 'a'. That way,
10863 ** when multiple affinity types are concatenated into a string and
10864 ** used as the P4 operand, they will be more readable.
10865 **
10866 ** Note also that the numeric types are grouped together so that testing
10867 ** for a numeric type is a single comparison.
10868 */
10869 #define SQLITE_AFF_TEXT 'a'
10870 #define SQLITE_AFF_NONE 'b'
10871 #define SQLITE_AFF_NUMERIC 'c'
10872 #define SQLITE_AFF_INTEGER 'd'
10873 #define SQLITE_AFF_REAL 'e'
10874
10875 #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
10876
10877 /*
10878 ** The SQLITE_AFF_MASK values masks off the significant bits of an
10879 ** affinity value.
10880 */
10881 #define SQLITE_AFF_MASK 0x67
10882
10883 /*
10884 ** Additional bit values that can be ORed with an affinity without
10885 ** changing the affinity.
10886 **
@@ -10887,14 +10975,14 @@
10887 ** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL.
10888 ** It causes an assert() to fire if either operand to a comparison
10889 ** operator is NULL. It is added to certain comparison operators to
10890 ** prove that the operands are always NOT NULL.
10891 */
10892 #define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */
10893 #define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */
10894 #define SQLITE_NULLEQ 0x80 /* NULL=NULL */
10895 #define SQLITE_NOTNULL 0x88 /* Assert that operands are never NULL */
10896
10897 /*
10898 ** An object of this type is created for each virtual table present in
10899 ** the database schema.
10900 **
@@ -11693,21 +11781,26 @@
11693 ExprList *pEList; /* Optional list of result-set columns */
11694 AggInfo *pAggInfo; /* Information about aggregates at this level */
11695 NameContext *pNext; /* Next outer name context. NULL for outermost */
11696 int nRef; /* Number of names resolved by this context */
11697 int nErr; /* Number of errors encountered while resolving names */
11698 u8 ncFlags; /* Zero or more NC_* flags defined below */
11699 };
11700
11701 /*
11702 ** Allowed values for the NameContext, ncFlags field.
 
 
 
 
11703 */
11704 #define NC_AllowAgg 0x01 /* Aggregate functions are allowed here */
11705 #define NC_HasAgg 0x02 /* One or more aggregate functions seen */
11706 #define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */
11707 #define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */
11708 #define NC_PartIdx 0x10 /* True if resolving a partial index WHERE */
 
11709
11710 /*
11711 ** An instance of the following structure contains all information
11712 ** needed to generate code for a single SELECT statement.
11713 **
@@ -11754,17 +11847,17 @@
11754 #define SF_Resolved 0x0002 /* Identifiers have been resolved */
11755 #define SF_Aggregate 0x0004 /* Contains aggregate functions */
11756 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
11757 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
11758 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
11759 /* 0x0040 NOT USED */
11760 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
11761 /* 0x0100 NOT USED */
11762 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
11763 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
11764 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
11765 #define SF_Compound 0x1000 /* Part of a compound query */
11766
11767
11768 /*
11769 ** The results of a SELECT can be distributed in several ways, as defined
11770 ** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -12362,12 +12455,12 @@
12362 #define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__)
12363
12364
12365 /*
12366 ** FTS4 is really an extension for FTS3. It is enabled using the
12367 ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also all
12368 ** the SQLITE_ENABLE_FTS4 macro to serve as an alisse for SQLITE_ENABLE_FTS3.
12369 */
12370 #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3)
12371 # define SQLITE_ENABLE_FTS3
12372 #endif
12373
@@ -12410,19 +12503,19 @@
12410 SQLITE_PRIVATE int sqlite3Strlen30(const char*);
12411 #define sqlite3StrNICmp sqlite3_strnicmp
12412
12413 SQLITE_PRIVATE int sqlite3MallocInit(void);
12414 SQLITE_PRIVATE void sqlite3MallocEnd(void);
12415 SQLITE_PRIVATE void *sqlite3Malloc(int);
12416 SQLITE_PRIVATE void *sqlite3MallocZero(int);
12417 SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3*, int);
12418 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3*, int);
12419 SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3*,const char*);
12420 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, int);
12421 SQLITE_PRIVATE void *sqlite3Realloc(void*, int);
12422 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, int);
12423 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, int);
12424 SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
12425 SQLITE_PRIVATE int sqlite3MallocSize(void*);
12426 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
12427 SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
12428 SQLITE_PRIVATE void sqlite3ScratchFree(void*);
@@ -12959,11 +13052,11 @@
12959 #endif
12960
12961 /*
12962 ** The interface to the LEMON-generated parser
12963 */
12964 SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(size_t));
12965 SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*));
12966 SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*);
12967 #ifdef YYTRACKMAXSTACKDEPTH
12968 SQLITE_PRIVATE int sqlite3ParserStackPeak(void*);
12969 #endif
@@ -13228,11 +13321,11 @@
13228 ** May you find forgiveness for yourself and forgive others.
13229 ** May you share freely, never taking more than you give.
13230 **
13231 *************************************************************************
13232 **
13233 ** This file contains definitions of global variables and contants.
13234 */
13235
13236 /* An array to map all upper-case characters into their corresponding
13237 ** lower-case character.
13238 **
@@ -13824,10 +13917,13 @@
13824 #if defined(SQLITE_THREADSAFE)
13825 "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
13826 #endif
13827 #ifdef SQLITE_USE_ALLOCA
13828 "USE_ALLOCA",
 
 
 
13829 #endif
13830 #ifdef SQLITE_WIN32_MALLOC
13831 "WIN32_MALLOC",
13832 #endif
13833 #ifdef SQLITE_ZERO_MALLOC
@@ -14052,29 +14148,32 @@
14052 ** Internally, the vdbe manipulates nearly all SQL values as Mem
14053 ** structures. Each Mem struct may cache multiple representations (string,
14054 ** integer etc.) of the same value.
14055 */
14056 struct Mem {
14057 sqlite3 *db; /* The associated database connection */
14058 char *z; /* String or BLOB value */
14059 double r; /* Real value */
14060 union {
14061 i64 i; /* Integer value used when MEM_Int is set in flags */
14062 int nZero; /* Used when bit MEM_Zero is set in flags */
14063 FuncDef *pDef; /* Used only when flags==MEM_Agg */
14064 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
14065 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
14066 } u;
14067 int n; /* Number of characters in string value, excluding '\0' */
14068 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
14069 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
 
 
 
 
 
 
 
 
14070 #ifdef SQLITE_DEBUG
14071 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
14072 void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
14073 #endif
14074 void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
14075 char *zMalloc; /* Dynamic buffer allocated by sqlite3_malloc() */
14076 };
14077
14078 /* One or more of the following flags are set to indicate the validOK
14079 ** representations of the value stored in the Mem struct.
14080 **
@@ -14129,11 +14228,11 @@
14129 #ifdef SQLITE_DEBUG
14130 #define memIsValid(M) ((M)->flags & MEM_Undefined)==0
14131 #endif
14132
14133 /*
14134 ** Each auxilliary data pointer stored by a user defined function
14135 ** implementation calling sqlite3_set_auxdata() is stored in an instance
14136 ** of this structure. All such structures associated with a single VM
14137 ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
14138 ** when the VM is halted (if not before).
14139 */
@@ -14144,11 +14243,11 @@
14144 void (*xDelete)(void *); /* Destructor for the aux data */
14145 AuxData *pNext; /* Next element in list */
14146 };
14147
14148 /*
14149 ** The "context" argument for a installable function. A pointer to an
14150 ** instance of this structure is the first argument to the routines used
14151 ** implement the SQL functions.
14152 **
14153 ** There is a typedef for this structure in sqlite.h. So all routines,
14154 ** even the public interface to SQLite, can use a pointer to this structure.
@@ -14158,17 +14257,17 @@
14158 ** This structure is defined inside of vdbeInt.h because it uses substructures
14159 ** (Mem) which are only defined there.
14160 */
14161 struct sqlite3_context {
14162 Mem *pOut; /* The return value is stored here */
14163 FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
14164 Mem *pMem; /* Memory cell used to store aggregate context */
14165 CollSeq *pColl; /* Collating sequence */
14166 Vdbe *pVdbe; /* The VM that owns this context */
14167 int iOp; /* Instruction number of OP_Function */
14168 int isError; /* Error code returned by the function. */
14169 u8 skipFlag; /* Skip skip accumulator loading if true */
14170 u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */
14171 };
14172
14173 /*
14174 ** An Explain object accumulates indented output which is helpful
@@ -14287,12 +14386,12 @@
14287 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
14288 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
14289 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
14290
14291 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
14292 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
14293 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
14294 SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
14295 SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
14296 SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
14297 SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *, int);
14298 SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem*);
@@ -14305,10 +14404,11 @@
14305 #ifdef SQLITE_OMIT_FLOATING_POINT
14306 # define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
14307 #else
14308 SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double);
14309 #endif
 
14310 SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*);
14311 SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int);
14312 SQLITE_PRIVATE void sqlite3VdbeMemSetRowSet(Mem*);
14313 SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
14314 SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8);
@@ -14319,18 +14419,16 @@
14319 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
14320 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
14321 SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8);
14322 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
14323 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
14324 SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
14325 #define VdbeMemDynamic(X) \
14326 (((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0)
14327 #define VdbeMemReleaseExtern(X) \
14328 if( VdbeMemDynamic(X) ) sqlite3VdbeMemReleaseExternal(X);
14329 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
14330 SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
14331 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
 
14332 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
14333 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
14334 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
14335 SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
14336
@@ -14653,11 +14751,11 @@
14653 ** calendar system.
14654 **
14655 ** 1970-01-01 00:00:00 is JD 2440587.5
14656 ** 2000-01-01 00:00:00 is JD 2451544.5
14657 **
14658 ** This implemention requires years to be expressed as a 4-digit number
14659 ** which means that only dates between 0000-01-01 and 9999-12-31 can
14660 ** be represented, even though julian day numbers allow a much wider
14661 ** range of dates.
14662 **
14663 ** The Gregorian calendar system is used for all dates and times,
@@ -16497,11 +16595,11 @@
16497 ** Like realloc(). Resize an allocation previously obtained from
16498 ** sqlite3MemMalloc().
16499 **
16500 ** For this low-level interface, we know that pPrior!=0. Cases where
16501 ** pPrior==0 while have been intercepted by higher-level routine and
16502 ** redirected to xMalloc. Similarly, we know that nByte>0 becauses
16503 ** cases where nByte<=0 will have been intercepted by higher-level
16504 ** routines and redirected to xFree.
16505 */
16506 static void *sqlite3MemRealloc(void *pPrior, int nByte){
16507 #ifdef SQLITE_MALLOCSIZE
@@ -17854,11 +17952,11 @@
17854 ** This memory allocator uses the following algorithm:
17855 **
17856 ** 1. All memory allocations sizes are rounded up to a power of 2.
17857 **
17858 ** 2. If two adjacent free blocks are the halves of a larger block,
17859 ** then the two blocks are coalesed into the single larger block.
17860 **
17861 ** 3. New memory is allocated from the first available free block.
17862 **
17863 ** This algorithm is described in: J. M. Robson. "Bounds for Some Functions
17864 ** Concerning Dynamic Storage Allocation". Journal of the Association for
@@ -20081,27 +20179,25 @@
20081
20082 /*
20083 ** Allocate memory. This routine is like sqlite3_malloc() except that it
20084 ** assumes the memory subsystem has already been initialized.
20085 */
20086 SQLITE_PRIVATE void *sqlite3Malloc(int n){
20087 void *p;
20088 if( n<=0 /* IMP: R-65312-04917 */
20089 || n>=0x7fffff00
20090 ){
20091 /* A memory allocation of a number of bytes which is near the maximum
20092 ** signed integer value might cause an integer overflow inside of the
20093 ** xMalloc(). Hence we limit the maximum size to 0x7fffff00, giving
20094 ** 255 bytes of overhead. SQLite itself will never use anything near
20095 ** this amount. The only way to reach the limit is with sqlite3_malloc() */
20096 p = 0;
20097 }else if( sqlite3GlobalConfig.bMemstat ){
20098 sqlite3_mutex_enter(mem0.mutex);
20099 mallocWithAlarm(n, &p);
20100 sqlite3_mutex_leave(mem0.mutex);
20101 }else{
20102 p = sqlite3GlobalConfig.m.xMalloc(n);
20103 }
20104 assert( EIGHT_BYTE_ALIGNMENT(p) ); /* IMP: R-04675-44850 */
20105 return p;
20106 }
20107
@@ -20112,10 +20208,16 @@
20112 */
20113 SQLITE_API void *sqlite3_malloc(int n){
20114 #ifndef SQLITE_OMIT_AUTOINIT
20115 if( sqlite3_initialize() ) return 0;
20116 #endif
 
 
 
 
 
 
20117 return sqlite3Malloc(n);
20118 }
20119
20120 /*
20121 ** Each thread may only have a single outstanding allocation from
@@ -20234,21 +20336,27 @@
20234 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20235 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
20236 return sqlite3GlobalConfig.m.xSize(p);
20237 }
20238 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
20239 assert( db!=0 );
20240 assert( sqlite3_mutex_held(db->mutex) );
20241 if( isLookaside(db, p) ){
20242 return db->lookaside.sz;
20243 }else{
20244 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20245 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20246 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20247 return sqlite3GlobalConfig.m.xSize(p);
 
 
 
 
 
20248 }
20249 }
 
 
 
20250
20251 /*
20252 ** Free memory previously obtained from sqlite3Malloc().
20253 */
20254 SQLITE_API void sqlite3_free(void *p){
@@ -20306,17 +20414,17 @@
20306 }
20307
20308 /*
20309 ** Change the size of an existing memory allocation
20310 */
20311 SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, int nBytes){
20312 int nOld, nNew, nDiff;
20313 void *pNew;
20314 if( pOld==0 ){
20315 return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */
20316 }
20317 if( nBytes<=0 ){
20318 sqlite3_free(pOld); /* IMP: R-31593-10574 */
20319 return 0;
20320 }
20321 if( nBytes>=0x7fffff00 ){
20322 /* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */
@@ -20324,26 +20432,26 @@
20324 }
20325 nOld = sqlite3MallocSize(pOld);
20326 /* IMPLEMENTATION-OF: R-46199-30249 SQLite guarantees that the second
20327 ** argument to xRealloc is always a value returned by a prior call to
20328 ** xRoundup. */
20329 nNew = sqlite3GlobalConfig.m.xRoundup(nBytes);
20330 if( nOld==nNew ){
20331 pNew = pOld;
20332 }else if( sqlite3GlobalConfig.bMemstat ){
20333 sqlite3_mutex_enter(mem0.mutex);
20334 sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
20335 nDiff = nNew - nOld;
20336 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
20337 mem0.alarmThreshold-nDiff ){
20338 sqlite3MallocAlarm(nDiff);
20339 }
20340 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
20341 assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
20342 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20343 if( pNew==0 && mem0.alarmCallback ){
20344 sqlite3MallocAlarm(nBytes);
20345 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20346 }
20347 if( pNew ){
20348 nNew = sqlite3MallocSize(pNew);
20349 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
@@ -20362,33 +20470,40 @@
20362 */
20363 SQLITE_API void *sqlite3_realloc(void *pOld, int n){
20364 #ifndef SQLITE_OMIT_AUTOINIT
20365 if( sqlite3_initialize() ) return 0;
20366 #endif
 
 
 
 
 
 
 
20367 return sqlite3Realloc(pOld, n);
20368 }
20369
20370
20371 /*
20372 ** Allocate and zero memory.
20373 */
20374 SQLITE_PRIVATE void *sqlite3MallocZero(int n){
20375 void *p = sqlite3Malloc(n);
20376 if( p ){
20377 memset(p, 0, n);
20378 }
20379 return p;
20380 }
20381
20382 /*
20383 ** Allocate and zero memory. If the allocation fails, make
20384 ** the mallocFailed flag in the connection pointer.
20385 */
20386 SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3 *db, int n){
20387 void *p = sqlite3DbMallocRaw(db, n);
20388 if( p ){
20389 memset(p, 0, n);
20390 }
20391 return p;
20392 }
20393
20394 /*
@@ -20407,11 +20522,11 @@
20407 ** if( b ) a[10] = 9;
20408 **
20409 ** In other words, if a subsequent malloc (ex: "b") worked, it is assumed
20410 ** that all prior mallocs (ex: "a") worked too.
20411 */
20412 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, int n){
20413 void *p;
20414 assert( db==0 || sqlite3_mutex_held(db->mutex) );
20415 assert( db==0 || db->pnBytesFreed==0 );
20416 #ifndef SQLITE_OMIT_LOOKASIDE
20417 if( db ){
@@ -20451,11 +20566,11 @@
20451
20452 /*
20453 ** Resize the block of memory pointed to by p to n bytes. If the
20454 ** resize fails, set the mallocFailed flag in the connection object.
20455 */
20456 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
20457 void *pNew = 0;
20458 assert( db!=0 );
20459 assert( sqlite3_mutex_held(db->mutex) );
20460 if( db->mallocFailed==0 ){
20461 if( p==0 ){
@@ -20472,11 +20587,11 @@
20472 }
20473 }else{
20474 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20475 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20476 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20477 pNew = sqlite3_realloc(p, n);
20478 if( !pNew ){
20479 sqlite3MemdebugSetType(p, MEMTYPE_DB|MEMTYPE_HEAP);
20480 db->mallocFailed = 1;
20481 }
20482 sqlite3MemdebugSetType(pNew, MEMTYPE_DB |
@@ -20488,11 +20603,11 @@
20488
20489 /*
20490 ** Attempt to reallocate p. If the reallocation fails, then free p
20491 ** and set the mallocFailed flag in the database connection.
20492 */
20493 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, int n){
20494 void *pNew;
20495 pNew = sqlite3DbRealloc(db, p, n);
20496 if( !pNew ){
20497 sqlite3DbFree(db, p);
20498 }
@@ -20518,19 +20633,19 @@
20518 if( zNew ){
20519 memcpy(zNew, z, n);
20520 }
20521 return zNew;
20522 }
20523 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, int n){
20524 char *zNew;
20525 if( z==0 ){
20526 return 0;
20527 }
20528 assert( (n&0x7fffffff)==n );
20529 zNew = sqlite3DbMallocRaw(db, n+1);
20530 if( zNew ){
20531 memcpy(zNew, z, n);
20532 zNew[n] = 0;
20533 }
20534 return zNew;
20535 }
20536
@@ -20599,10 +20714,25 @@
20599 ** This file contains code for a set of "printf"-like routines. These
20600 ** routines format strings much like the printf() from the standard C
20601 ** library, though the implementation here has enhancements to support
20602 ** SQLlite.
20603 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20604
20605 /*
20606 ** Conversion types fall into various categories as defined by the
20607 ** following enumeration.
20608 */
@@ -20810,13 +20940,17 @@
20810 bArgList = useIntern = 0;
20811 }
20812 for(; (c=(*fmt))!=0; ++fmt){
20813 if( c!='%' ){
20814 bufpt = (char *)fmt;
20815 while( (c=(*++fmt))!='%' && c!=0 ){};
 
 
 
 
20816 sqlite3StrAccumAppend(pAccum, bufpt, (int)(fmt - bufpt));
20817 if( c==0 ) break;
20818 }
20819 if( (c=(*++fmt))==0 ){
20820 sqlite3StrAccumAppend(pAccum, "%", 1);
20821 break;
20822 }
@@ -21490,11 +21624,11 @@
21490 return z;
21491 }
21492
21493 /*
21494 ** Like sqlite3MPrintf(), but call sqlite3DbFree() on zStr after formatting
21495 ** the string and before returnning. This routine is intended to be used
21496 ** to modify an existing string. For example:
21497 **
21498 ** x = sqlite3MPrintf(db, x, "prefix %s suffix", x);
21499 **
21500 */
@@ -22341,16 +22475,17 @@
22341 pMem->n = (int)(z - zOut);
22342 }
22343 *z = 0;
22344 assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
22345
 
22346 sqlite3VdbeMemRelease(pMem);
22347 pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem);
22348 pMem->enc = desiredEnc;
22349 pMem->flags |= (MEM_Term);
22350 pMem->z = (char*)zOut;
22351 pMem->zMalloc = pMem->z;
 
22352
22353 translate_out:
22354 #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
22355 {
22356 char zBuf[100];
@@ -22762,11 +22897,11 @@
22762 ** The return value is -1 if no dequoting occurs or the length of the
22763 ** dequoted string, exclusive of the zero terminator, if dequoting does
22764 ** occur.
22765 **
22766 ** 2002-Feb-14: This routine is extended to remove MS-Access style
22767 ** brackets from around identifers. For example: "[a-b-c]" becomes
22768 ** "a-b-c".
22769 */
22770 SQLITE_PRIVATE int sqlite3Dequote(char *z){
22771 char quote;
22772 int i, j;
@@ -24872,10 +25007,18 @@
24872 # else
24873 # define HAVE_MREMAP 0
24874 # endif
24875 #endif
24876
 
 
 
 
 
 
 
 
24877 /*
24878 ** Different Unix systems declare open() in different ways. Same use
24879 ** open(const char*,int,mode_t). Others use open(const char*,int,...).
24880 ** The difference is important when using a pointer to the function.
24881 **
@@ -25204,11 +25347,11 @@
25204
25205
25206 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
25207 /*
25208 ** Helper function for printing out trace information from debugging
25209 ** binaries. This returns the string represetation of the supplied
25210 ** integer lock-type.
25211 */
25212 static const char *azFileLock(int eFileLock){
25213 switch( eFileLock ){
25214 case NO_LOCK: return "NONE";
@@ -25281,13 +25424,26 @@
25281 #define osFcntl lockTrace
25282 #endif /* SQLITE_LOCK_TRACE */
25283
25284 /*
25285 ** Retry ftruncate() calls that fail due to EINTR
 
 
 
 
25286 */
25287 static int robust_ftruncate(int h, sqlite3_int64 sz){
25288 int rc;
 
 
 
 
 
 
 
 
 
25289 do{ rc = osFtruncate(h,sz); }while( rc<0 && errno==EINTR );
25290 return rc;
25291 }
25292
25293 /*
@@ -27671,11 +27827,11 @@
27671 ** bytes into pBuf. Return the number of bytes actually read.
27672 **
27673 ** NB: If you define USE_PREAD or USE_PREAD64, then it might also
27674 ** be necessary to define _XOPEN_SOURCE to be 500. This varies from
27675 ** one system to another. Since SQLite does not define USE_PREAD
27676 ** any any form by default, we will not attempt to define _XOPEN_SOURCE.
27677 ** See tickets #2741 and #2681.
27678 **
27679 ** To avoid stomping the errno value on a failed read the lastErrno value
27680 ** is set before returning.
27681 */
@@ -28168,11 +28324,11 @@
28168 */
28169 if( pFile->szChunk>0 ){
28170 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
28171 }
28172
28173 rc = robust_ftruncate(pFile->h, (off_t)nByte);
28174 if( rc ){
28175 pFile->lastErrno = errno;
28176 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
28177 }else{
28178 #ifdef SQLITE_DEBUG
@@ -28303,11 +28459,11 @@
28303
28304 return SQLITE_OK;
28305 }
28306
28307 /*
28308 ** If *pArg is inititially negative then this is a query. Set *pArg to
28309 ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
28310 **
28311 ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
28312 */
28313 static void unixModeBit(unixFile *pFile, unsigned char mask, int *pArg){
@@ -28510,11 +28666,11 @@
28510
28511 /*
28512 ** Return the device characteristics for the file.
28513 **
28514 ** This VFS is set up to return SQLITE_IOCAP_POWERSAFE_OVERWRITE by default.
28515 ** However, that choice is contraversial since technically the underlying
28516 ** file system does not always provide powersafe overwrites. (In other
28517 ** words, after a power-loss event, parts of the file that were never
28518 ** written might end up being altered.) However, non-PSOW behavior is very,
28519 ** very rare. And asserting PSOW makes a large reduction in the amount
28520 ** of required I/O for journaling, since a lot of padding is eliminated.
@@ -29482,11 +29638,11 @@
29482 ** Most finder functions return a pointer to a fixed sqlite3_io_methods
29483 ** object. The only interesting finder-function is autolockIoFinder, which
29484 ** looks at the filesystem type and tries to guess the best locking
29485 ** strategy from that.
29486 **
29487 ** For finder-funtion F, two objects are created:
29488 **
29489 ** (1) The real finder-function named "FImpt()".
29490 **
29491 ** (2) A constant pointer to this function named just "F".
29492 **
@@ -29549,11 +29705,11 @@
29549 unixCheckReservedLock /* xCheckReservedLock method */
29550 )
29551 IOMETHODS(
29552 nolockIoFinder, /* Finder function name */
29553 nolockIoMethods, /* sqlite3_io_methods object name */
29554 1, /* shared memory is disabled */
29555 nolockClose, /* xClose method */
29556 nolockLock, /* xLock method */
29557 nolockUnlock, /* xUnlock method */
29558 nolockCheckReservedLock /* xCheckReservedLock method */
29559 )
@@ -29744,11 +29900,11 @@
29744 *(*const autolockIoFinder)(const char*,unixFile*) = autolockIoFinderImpl;
29745
29746 #endif /* OS_VXWORKS && SQLITE_ENABLE_LOCKING_STYLE */
29747
29748 /*
29749 ** An abstract type for a pointer to a IO method finder function:
29750 */
29751 typedef const sqlite3_io_methods *(*finder_type)(const char*,unixFile*);
29752
29753
29754 /****************************************************************************
@@ -30058,11 +30214,11 @@
30058 ** For this reason, if an error occurs in the stat() call here, it is
30059 ** ignored and -1 is returned. The caller will try to open a new file
30060 ** descriptor on the same path, fail, and return an error to SQLite.
30061 **
30062 ** Even if a subsequent open() call does succeed, the consequences of
30063 ** not searching for a resusable file descriptor are not dire. */
30064 if( 0==osStat(zPath, &sStat) ){
30065 unixInodeInfo *pInode;
30066
30067 unixEnterMutex();
30068 pInode = inodeList;
@@ -30089,11 +30245,11 @@
30089 ** to create new files with. If no error occurs, then SQLITE_OK is returned
30090 ** and a value suitable for passing as the third argument to open(2) is
30091 ** written to *pMode. If an IO error occurs, an SQLite error code is
30092 ** returned and the value of *pMode is not modified.
30093 **
30094 ** In most cases cases, this routine sets *pMode to 0, which will become
30095 ** an indication to robust_open() to create the file using
30096 ** SQLITE_DEFAULT_FILE_PERMISSIONS adjusted by the umask.
30097 ** But if the file being opened is a WAL or regular journal file, then
30098 ** this function queries the file-system for the permissions on the
30099 ** corresponding database file and sets *pMode to this value. Whenever
@@ -30881,11 +31037,11 @@
30881 ** by taking an sqlite-style shared lock on the conch file, reading the
30882 ** contents and comparing the host's unique host ID (see below) and lock
30883 ** proxy path against the values stored in the conch. The conch file is
30884 ** stored in the same directory as the database file and the file name
30885 ** is patterned after the database file name as ".<databasename>-conch".
30886 ** If the conch file does not exist, or it's contents do not match the
30887 ** host ID and/or proxy path, then the lock is escalated to an exclusive
30888 ** lock and the conch file contents is updated with the host ID and proxy
30889 ** path and the lock is downgraded to a shared lock again. If the conch
30890 ** is held by another process (with a shared lock), the exclusive lock
30891 ** will fail and SQLITE_BUSY is returned.
@@ -30933,11 +31089,11 @@
30933 **
30934 ** As mentioned above, when compiled with SQLITE_PREFER_PROXY_LOCKING,
30935 ** setting the environment variable SQLITE_FORCE_PROXY_LOCKING to 1 will
30936 ** force proxy locking to be used for every database file opened, and 0
30937 ** will force automatic proxy locking to be disabled for all database
30938 ** files (explicity calling the SQLITE_SET_LOCKPROXYFILE pragma or
30939 ** sqlite_file_control API is not affected by SQLITE_FORCE_PROXY_LOCKING).
30940 */
30941
30942 /*
30943 ** Proxy locking is only available on MacOSX
@@ -33571,16 +33727,18 @@
33571 #else
33572 osSleep(milliseconds);
33573 #endif
33574 }
33575
 
33576 SQLITE_PRIVATE DWORD sqlite3Win32Wait(HANDLE hObject){
33577 DWORD rc;
33578 while( (rc = osWaitForSingleObjectEx(hObject, INFINITE,
33579 TRUE))==WAIT_IO_COMPLETION ){}
33580 return rc;
33581 }
 
33582
33583 /*
33584 ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
33585 ** or WinCE. Return false (zero) for Win95, Win98, or WinME.
33586 **
@@ -33605,31 +33763,40 @@
33605 /*
33606 ** This function determines if the machine is running a version of Windows
33607 ** based on the NT kernel.
33608 */
33609 SQLITE_API int sqlite3_win32_is_nt(void){
33610 #if defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX
 
 
 
 
 
 
33611 if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){
33612 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
33613 defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WIN8
33614 OSVERSIONINFOW sInfo;
33615 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
33616 osGetVersionExW(&sInfo);
33617 osInterlockedCompareExchange(&sqlite3_os_type,
33618 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
33619 #elif defined(SQLITE_WIN32_HAS_ANSI)
33620 OSVERSIONINFOA sInfo;
33621 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
33622 osGetVersionExA(&sInfo);
 
 
 
 
 
 
33623 osInterlockedCompareExchange(&sqlite3_os_type,
33624 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
33625 #endif
33626 }
33627 return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
33628 #elif SQLITE_TEST
33629 return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
33630 #else
 
 
 
 
33631 return 1;
33632 #endif
33633 }
33634
33635 #ifdef SQLITE_WIN32_MALLOC
@@ -35402,11 +35569,11 @@
35402 pFile->h, pFile->locktype, sqlite3ErrName(rc)));
35403 return rc;
35404 }
35405
35406 /*
35407 ** If *pArg is inititially negative then this is a query. Set *pArg to
35408 ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
35409 **
35410 ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
35411 */
35412 static void winModeBit(winFile *pFile, unsigned char mask, int *pArg){
@@ -36416,11 +36583,11 @@
36416 if( p ){
36417 pFd->nFetchOut--;
36418 }else{
36419 /* FIXME: If Windows truly always prevents truncating or deleting a
36420 ** file while a mapping is held, then the following winUnmapfile() call
36421 ** is unnecessary can can be omitted - potentially improving
36422 ** performance. */
36423 winUnmapfile(pFd);
36424 }
36425
36426 assert( pFd->nFetchOut>=0 );
@@ -38274,27 +38441,10 @@
38274 # define expensive_assert(X)
38275 #endif
38276
38277 /********************************** Linked List Management ********************/
38278
38279 #if !defined(NDEBUG) && defined(SQLITE_ENABLE_EXPENSIVE_ASSERT)
38280 /*
38281 ** Check that the pCache->pSynced variable is set correctly. If it
38282 ** is not, either fail an assert or return zero. Otherwise, return
38283 ** non-zero. This is only used in debugging builds, as follows:
38284 **
38285 ** expensive_assert( pcacheCheckSynced(pCache) );
38286 */
38287 static int pcacheCheckSynced(PCache *pCache){
38288 PgHdr *p;
38289 for(p=pCache->pDirtyTail; p!=pCache->pSynced; p=p->pDirtyPrev){
38290 assert( p->nRef || (p->flags&PGHDR_NEED_SYNC) );
38291 }
38292 return (p==0 || p->nRef || (p->flags&PGHDR_NEED_SYNC)==0);
38293 }
38294 #endif /* !NDEBUG && SQLITE_ENABLE_EXPENSIVE_ASSERT */
38295
38296 /* Allowed values for second argument to pcacheManageDirtyList() */
38297 #define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
38298 #define PCACHE_DIRTYLIST_ADD 2 /* Add pPage to the dirty list */
38299 #define PCACHE_DIRTYLIST_FRONT 3 /* Move pPage to the front of the list */
38300
@@ -38336,31 +38486,29 @@
38336 p->eCreate = 2;
38337 }
38338 }
38339 pPage->pDirtyNext = 0;
38340 pPage->pDirtyPrev = 0;
38341 expensive_assert( pcacheCheckSynced(p) );
38342 }
38343 if( addRemove & PCACHE_DIRTYLIST_ADD ){
38344 assert( pPage->pDirtyNext==0 && pPage->pDirtyPrev==0 && p->pDirty!=pPage );
38345
38346 pPage->pDirtyNext = p->pDirty;
38347 if( pPage->pDirtyNext ){
38348 assert( pPage->pDirtyNext->pDirtyPrev==0 );
38349 pPage->pDirtyNext->pDirtyPrev = pPage;
38350 }else if( p->bPurgeable ){
38351 assert( p->eCreate==2 );
38352 p->eCreate = 1;
38353 }
38354 p->pDirty = pPage;
38355 if( !p->pDirtyTail ){
38356 p->pDirtyTail = pPage;
 
 
 
 
38357 }
 
38358 if( !p->pSynced && 0==(pPage->flags&PGHDR_NEED_SYNC) ){
38359 p->pSynced = pPage;
38360 }
38361 expensive_assert( pcacheCheckSynced(p) );
38362 }
38363 }
38364
38365 /*
38366 ** Wrapper around the pluggable caches xUnpin method. If the cache is
@@ -38533,11 +38681,10 @@
38533 /* Find a dirty page to write-out and recycle. First try to find a
38534 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
38535 ** cleared), but if that is not possible settle for any other
38536 ** unreferenced dirty page.
38537 */
38538 expensive_assert( pcacheCheckSynced(pCache) );
38539 for(pPg=pCache->pSynced;
38540 pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
38541 pPg=pPg->pDirtyPrev
38542 );
38543 pCache->pSynced = pPg;
@@ -38619,20 +38766,20 @@
38619 return pPgHdr;
38620 }
38621
38622 /*
38623 ** Decrement the reference count on a page. If the page is clean and the
38624 ** reference count drops to 0, then it is made elible for recycling.
38625 */
38626 SQLITE_PRIVATE void SQLITE_NOINLINE sqlite3PcacheRelease(PgHdr *p){
38627 assert( p->nRef>0 );
38628 p->nRef--;
38629 if( p->nRef==0 ){
38630 p->pCache->nRef--;
38631 if( (p->flags&PGHDR_DIRTY)==0 ){
38632 pcacheUnpin(p);
38633 }else{
38634 /* Move the page to the head of the dirty list. */
38635 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
38636 }
38637 }
38638 }
@@ -38931,11 +39078,11 @@
38931 *************************************************************************
38932 **
38933 ** This file implements the default page cache implementation (the
38934 ** sqlite3_pcache interface). It also contains part of the implementation
38935 ** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features.
38936 ** If the default page cache implementation is overriden, then neither of
38937 ** these two features are available.
38938 */
38939
38940
38941 typedef struct PCache1 PCache1;
@@ -38942,11 +39089,11 @@
38942 typedef struct PgHdr1 PgHdr1;
38943 typedef struct PgFreeslot PgFreeslot;
38944 typedef struct PGroup PGroup;
38945
38946 /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
38947 ** of one or more PCaches that are able to recycle each others unpinned
38948 ** pages when they are under memory pressure. A PGroup is an instance of
38949 ** the following object.
38950 **
38951 ** This page cache implementation works in one of two modes:
38952 **
@@ -40009,11 +40156,11 @@
40009 ** a non-zero batch number, it will see all prior INSERTs.
40010 **
40011 ** No INSERTs may occurs after a SMALLEST. An assertion will fail if
40012 ** that is attempted.
40013 **
40014 ** The cost of an INSERT is roughly constant. (Sometime new memory
40015 ** has to be allocated on an INSERT.) The cost of a TEST with a new
40016 ** batch number is O(NlogN) where N is the number of elements in the RowSet.
40017 ** The cost of a TEST using the same batch number is O(logN). The cost
40018 ** of the first SMALLEST is O(NlogN). Second and subsequent SMALLEST
40019 ** primitives are constant time. The cost of DESTROY is O(N).
@@ -40401,12 +40548,12 @@
40401
40402 /*
40403 ** Check to see if element iRowid was inserted into the rowset as
40404 ** part of any insert batch prior to iBatch. Return 1 or 0.
40405 **
40406 ** If this is the first test of a new batch and if there exist entires
40407 ** on pRowSet->pEntry, then sort those entires into the forest at
40408 ** pRowSet->pForest so that they can be tested.
40409 */
40410 SQLITE_PRIVATE int sqlite3RowSetTest(RowSet *pRowSet, int iBatch, sqlite3_int64 iRowid){
40411 struct RowSetEntry *p, *pTree;
40412
@@ -40684,16 +40831,16 @@
40684 ** are synced prior to the master journal being deleted.
40685 **
40686 ** Definition: Two databases (or the same database at two points it time)
40687 ** are said to be "logically equivalent" if they give the same answer to
40688 ** all queries. Note in particular the content of freelist leaf
40689 ** pages can be changed arbitarily without effecting the logical equivalence
40690 ** of the database.
40691 **
40692 ** (7) At any time, if any subset, including the empty set and the total set,
40693 ** of the unsynced changes to a rollback journal are removed and the
40694 ** journal is rolled back, the resulting database file will be logical
40695 ** equivalent to the database file at the beginning of the transaction.
40696 **
40697 ** (8) When a transaction is rolled back, the xTruncate method of the VFS
40698 ** is called to restore the database file to the same size it was at
40699 ** the beginning of the transaction. (In some VFSes, the xTruncate
@@ -40986,11 +41133,11 @@
40986 ** be a few redundant xLock() calls or a lock may be held for longer than
40987 ** required, but nothing really goes wrong.
40988 **
40989 ** The exception is when the database file is unlocked as the pager moves
40990 ** from ERROR to OPEN state. At this point there may be a hot-journal file
40991 ** in the file-system that needs to be rolled back (as part of a OPEN->SHARED
40992 ** transition, by the same pager or any other). If the call to xUnlock()
40993 ** fails at this point and the pager is left holding an EXCLUSIVE lock, this
40994 ** can confuse the call to xCheckReservedLock() call made later as part
40995 ** of hot-journal detection.
40996 **
@@ -41069,11 +41216,11 @@
41069 #define SPILLFLAG_OFF 0x01 /* Never spill cache. Set via pragma */
41070 #define SPILLFLAG_ROLLBACK 0x02 /* Current rolling back, so do not spill */
41071 #define SPILLFLAG_NOSYNC 0x04 /* Spill is ok, but do not sync */
41072
41073 /*
41074 ** A open page cache is an instance of struct Pager. A description of
41075 ** some of the more important member variables follows:
41076 **
41077 ** eState
41078 **
41079 ** The current 'state' of the pager object. See the comment and state
@@ -41241,11 +41388,11 @@
41241 u8 readOnly; /* True for a read-only database */
41242 u8 memDb; /* True to inhibit all file I/O */
41243
41244 /**************************************************************************
41245 ** The following block contains those class members that change during
41246 ** routine opertion. Class members not in this block are either fixed
41247 ** when the pager is first created or else only change when there is a
41248 ** significant mode change (such as changing the page_size, locking_mode,
41249 ** or the journal_mode). From another view, these class members describe
41250 ** the "state" of the pager, while other class members describe the
41251 ** "configuration" of the pager.
@@ -43036,11 +43183,11 @@
43036 ** journal files extracted from regular rollback-journals.
43037 */
43038 rc = sqlite3OsFileSize(pMaster, &nMasterJournal);
43039 if( rc!=SQLITE_OK ) goto delmaster_out;
43040 nMasterPtr = pVfs->mxPathname+1;
43041 zMasterJournal = sqlite3Malloc((int)nMasterJournal + nMasterPtr + 1);
43042 if( !zMasterJournal ){
43043 rc = SQLITE_NOMEM;
43044 goto delmaster_out;
43045 }
43046 zMasterPtr = &zMasterJournal[nMasterJournal+1];
@@ -43105,11 +43252,11 @@
43105 ** DBMOD or OPEN state, this function is a no-op. Otherwise, the size
43106 ** of the file is changed to nPage pages (nPage*pPager->pageSize bytes).
43107 ** If the file on disk is currently larger than nPage pages, then use the VFS
43108 ** xTruncate() method to truncate it.
43109 **
43110 ** Or, it might might be the case that the file on disk is smaller than
43111 ** nPage pages. Some operating system implementations can get confused if
43112 ** you try to truncate a file to some size that is larger than it
43113 ** currently is, so detect this case and write a single zero byte to
43114 ** the end of the new file instead.
43115 **
@@ -43164,11 +43311,11 @@
43164 }
43165
43166 /*
43167 ** Set the value of the Pager.sectorSize variable for the given
43168 ** pager based on the value returned by the xSectorSize method
43169 ** of the open database file. The sector size will be used used
43170 ** to determine the size and alignment of journal header and
43171 ** master journal pointers within created journal files.
43172 **
43173 ** For temporary files the effective sector size is always 512 bytes.
43174 **
@@ -44226,16 +44373,18 @@
44226 if( !pNew ) rc = SQLITE_NOMEM;
44227 }
44228
44229 if( rc==SQLITE_OK ){
44230 pager_reset(pPager);
44231 pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
44232 pPager->pageSize = pageSize;
44233 sqlite3PageFree(pPager->pTmpSpace);
44234 pPager->pTmpSpace = pNew;
44235 rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
44236 }
 
 
 
 
44237 }
44238
44239 *pPageSize = pPager->pageSize;
44240 if( rc==SQLITE_OK ){
44241 if( nReserve<0 ) nReserve = pPager->nReserve;
@@ -44364,11 +44513,11 @@
44364 */
44365 static int pager_wait_on_lock(Pager *pPager, int locktype){
44366 int rc; /* Return code */
44367
44368 /* Check that this is either a no-op (because the requested lock is
44369 ** already held, or one of the transistions that the busy-handler
44370 ** may be invoked during, according to the comment above
44371 ** sqlite3PagerSetBusyhandler().
44372 */
44373 assert( (pPager->eLock>=locktype)
44374 || (pPager->eLock==NO_LOCK && locktype==SHARED_LOCK)
@@ -44992,11 +45141,11 @@
44992 ** The doNotSpill ROLLBACK and OFF bits inhibits all cache spilling
44993 ** regardless of whether or not a sync is required. This is set during
44994 ** a rollback or by user request, respectively.
44995 **
44996 ** Spilling is also prohibited when in an error state since that could
44997 ** lead to database corruption. In the current implementaton it
44998 ** is impossible for sqlite3PcacheFetch() to be called with createFlag==3
44999 ** while in the error state, hence it is impossible for this routine to
45000 ** be called in the error state. Nevertheless, we include a NEVER()
45001 ** test for the error state as a safeguard against future changes.
45002 */
@@ -45532,11 +45681,11 @@
45532 sqlite3OsClose(pPager->jfd);
45533 }
45534 *pExists = (first!=0);
45535 }else if( rc==SQLITE_CANTOPEN ){
45536 /* If we cannot open the rollback journal file in order to see if
45537 ** its has a zero header, that might be due to an I/O error, or
45538 ** it might be due to the race condition described above and in
45539 ** ticket #3883. Either way, assume that the journal is hot.
45540 ** This might be a false positive. But if it is, then the
45541 ** automatic journal playback and recovery mechanism will deal
45542 ** with it under an EXCLUSIVE lock where we do not need to
@@ -47836,11 +47985,11 @@
47836 ** frames, return the size in bytes of the page images stored within the
47837 ** WAL frames. Otherwise, if this is not a WAL database or the WAL file
47838 ** is empty, return 0.
47839 */
47840 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){
47841 assert( pPager->eState==PAGER_READER );
47842 return sqlite3WalFramesize(pPager->pWal);
47843 }
47844 #endif
47845
47846 #endif /* SQLITE_OMIT_DISKIO */
@@ -48420,11 +48569,11 @@
48420
48421 /*
48422 ** The argument to this macro must be of type u32. On a little-endian
48423 ** architecture, it returns the u32 value that results from interpreting
48424 ** the 4 bytes as a big-endian value. On a big-endian architecture, it
48425 ** returns the value that would be produced by intepreting the 4 bytes
48426 ** of the input value as a little-endian integer.
48427 */
48428 #define BYTESWAP32(x) ( \
48429 (((x)&0x000000FF)<<24) + (((x)&0x0000FF00)<<8) \
48430 + (((x)&0x00FF0000)>>8) + (((x)&0xFF000000)>>24) \
@@ -48834,11 +48983,11 @@
48834
48835 idx = iFrame - iZero;
48836 assert( idx <= HASHTABLE_NSLOT/2 + 1 );
48837
48838 /* If this is the first entry to be added to this hash-table, zero the
48839 ** entire hash table and aPgno[] array before proceding.
48840 */
48841 if( idx==1 ){
48842 int nByte = (int)((u8 *)&aHash[HASHTABLE_NSLOT] - (u8 *)&aPgno[1]);
48843 memset((void*)&aPgno[1], 0, nByte);
48844 }
@@ -49492,11 +49641,11 @@
49492 ** WAL content is copied into the database file. This second fsync makes
49493 ** it safe to delete the WAL since the new content will persist in the
49494 ** database file.
49495 **
49496 ** This routine uses and updates the nBackfill field of the wal-index header.
49497 ** This is the only routine tha will increase the value of nBackfill.
49498 ** (A WAL reset or recovery will revert nBackfill to zero, but not increase
49499 ** its value.)
49500 **
49501 ** The caller must be holding sufficient locks to ensure that no other
49502 ** checkpoint is running (in any other thread or process) at the same
@@ -49796,11 +49945,11 @@
49796 ** Read the wal-index header from the wal-index and into pWal->hdr.
49797 ** If the wal-header appears to be corrupt, try to reconstruct the
49798 ** wal-index from the WAL before returning.
49799 **
49800 ** Set *pChanged to 1 if the wal-index header value in pWal->hdr is
49801 ** changed by this opertion. If pWal->hdr is unchanged, set *pChanged
49802 ** to 0.
49803 **
49804 ** If the wal-index header is successfully read, return SQLITE_OK.
49805 ** Otherwise an SQLite error code.
49806 */
@@ -50000,11 +50149,11 @@
50000 if( memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr)) ){
50001 /* It is not safe to allow the reader to continue here if frames
50002 ** may have been appended to the log before READ_LOCK(0) was obtained.
50003 ** When holding READ_LOCK(0), the reader ignores the entire log file,
50004 ** which implies that the database file contains a trustworthy
50005 ** snapshoT. Since holding READ_LOCK(0) prevents a checkpoint from
50006 ** happening, this is usually correct.
50007 **
50008 ** However, if frames have been appended to the log (or if the log
50009 ** is wrapped and written for that matter) before the READ_LOCK(0)
50010 ** is obtained, that is not necessarily true. A checkpointer may
@@ -50668,11 +50817,11 @@
50668 /* If this is the end of a transaction, then we might need to pad
50669 ** the transaction and/or sync the WAL file.
50670 **
50671 ** Padding and syncing only occur if this set of frames complete a
50672 ** transaction and if PRAGMA synchronous=FULL. If synchronous==NORMAL
50673 ** or synchonous==OFF, then no padding or syncing are needed.
50674 **
50675 ** If SQLITE_IOCAP_POWERSAFE_OVERWRITE is defined, then padding is not
50676 ** needed and only the sync is done. If padding is needed, then the
50677 ** final frame is repeated (with its commit mark) until the next sector
50678 ** boundary is crossed. Only the part of the WAL prior to the last
@@ -50971,11 +51120,11 @@
50971 ** May you do good and not evil.
50972 ** May you find forgiveness for yourself and forgive others.
50973 ** May you share freely, never taking more than you give.
50974 **
50975 *************************************************************************
50976 ** This file implements a external (disk-based) database using BTrees.
50977 ** For a detailed discussion of BTrees, refer to
50978 **
50979 ** Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
50980 ** "Sorting And Searching", pages 473-480. Addison-Wesley
50981 ** Publishing Company, Reading, Massachusetts.
@@ -51097,11 +51246,11 @@
51097 ** 7 1 number of fragmented free bytes
51098 ** 8 4 Right child (the Ptr(N) value). Omitted on leaves.
51099 **
51100 ** The flags define the format of this btree page. The leaf flag means that
51101 ** this page has no children. The zerodata flag means that this page carries
51102 ** only keys and no data. The intkey flag means that the key is a integer
51103 ** which is stored in the key size entry of the cell header rather than in
51104 ** the payload area.
51105 **
51106 ** The cell pointer array begins on the first byte after the page header.
51107 ** The cell pointer array contains zero or more 2-byte numbers which are
@@ -51505,11 +51654,11 @@
51505 ** in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in
51506 ** this state, restoreCursorPosition() can be called to attempt to
51507 ** seek the cursor to the saved position.
51508 **
51509 ** CURSOR_FAULT:
51510 ** A unrecoverable error (an I/O error or a malloc failure) has occurred
51511 ** on a different connection that shares the BtShared cache with this
51512 ** cursor. The error has left the cache in an inconsistent state.
51513 ** Do nothing else with this cursor. Any attempt to use the cursor
51514 ** should return the error code stored in BtCursor.skip
51515 */
@@ -51722,11 +51871,11 @@
51722 */
51723 static void SQLITE_NOINLINE btreeLockCarefully(Btree *p){
51724 Btree *pLater;
51725
51726 /* In most cases, we should be able to acquire the lock we
51727 ** want without having to go throught the ascending lock
51728 ** procedure that follows. Just be sure not to block.
51729 */
51730 if( sqlite3_mutex_try(p->pBt->mutex)==SQLITE_OK ){
51731 p->pBt->db = p->db;
51732 p->locked = 1;
@@ -51928,11 +52077,11 @@
51928 ** May you do good and not evil.
51929 ** May you find forgiveness for yourself and forgive others.
51930 ** May you share freely, never taking more than you give.
51931 **
51932 *************************************************************************
51933 ** This file implements a external (disk-based) database using BTrees.
51934 ** See the header comment on "btreeInt.h" for additional information.
51935 ** Including a description of file format and an overview of operation.
51936 */
51937
51938 /*
@@ -52524,11 +52673,11 @@
52524 ** all that is required. Otherwise, if pCur is not open on an intKey
52525 ** table, then malloc space for and store the pCur->nKey bytes of key
52526 ** data.
52527 */
52528 if( 0==pCur->apPage[0]->intKey ){
52529 void *pKey = sqlite3Malloc( (int)pCur->nKey );
52530 if( pKey ){
52531 rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey);
52532 if( rc==SQLITE_OK ){
52533 pCur->pKey = pKey;
52534 }else{
@@ -53062,11 +53211,11 @@
53062 ** big FreeBlk that occurs in between the header and cell
53063 ** pointer array and the cell content area.
53064 */
53065 static int defragmentPage(MemPage *pPage){
53066 int i; /* Loop counter */
53067 int pc; /* Address of a i-th cell */
53068 int hdr; /* Offset to the page header */
53069 int size; /* Size of a cell */
53070 int usableSize; /* Number of usable bytes on a page */
53071 int cellOffset; /* Offset to the cell pointer array */
53072 int cbrk; /* Offset to the cell content area */
@@ -54519,11 +54668,11 @@
54519 **
54520 ** Only write cursors are counted if wrOnly is true. If wrOnly is
54521 ** false then all cursors are counted.
54522 **
54523 ** For the purposes of this routine, a cursor is any cursor that
54524 ** is capable of reading or writing to the databse. Cursors that
54525 ** have been tripped into the CURSOR_FAULT state are not counted.
54526 */
54527 static int countValidCursors(BtShared *pBt, int wrOnly){
54528 BtCursor *pCur;
54529 int r = 0;
@@ -54983,19 +55132,19 @@
54983 ** Perform a single step of an incremental-vacuum. If successful, return
54984 ** SQLITE_OK. If there is no work to do (and therefore no point in
54985 ** calling this function again), return SQLITE_DONE. Or, if an error
54986 ** occurs, return some other error code.
54987 **
54988 ** More specificly, this function attempts to re-organize the database so
54989 ** that the last page of the file currently in use is no longer in use.
54990 **
54991 ** Parameter nFin is the number of pages that this database would contain
54992 ** were this function called until it returns SQLITE_DONE.
54993 **
54994 ** If the bCommit parameter is non-zero, this function assumes that the
54995 ** caller will keep calling incrVacuumStep() until it returns SQLITE_DONE
54996 ** or an error. bCommit is passed true for an auto-vacuum-on-commmit
54997 ** operation, or false for an incremental vacuum.
54998 */
54999 static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg, int bCommit){
55000 Pgno nFreeList; /* Number of pages still on the free-list */
55001 int rc;
@@ -55458,11 +55607,11 @@
55458 sqlite3BtreeLeave(p);
55459 return rc;
55460 }
55461
55462 /*
55463 ** Start a statement subtransaction. The subtransaction can can be rolled
55464 ** back independently of the main transaction. You must start a transaction
55465 ** before starting a subtransaction. The subtransaction is ended automatically
55466 ** if the main transaction commits or rolls back.
55467 **
55468 ** Statement subtransactions are used around individual SQL statements
@@ -55692,11 +55841,11 @@
55692 **
55693 ** 2007-06-25: There is a bug in some versions of MSVC that cause the
55694 ** compiler to crash when getCellInfo() is implemented as a macro.
55695 ** But there is a measureable speed advantage to using the macro on gcc
55696 ** (when less compiler optimizations like -Os or -O0 are used and the
55697 ** compiler is not doing agressive inlining.) So we use a real function
55698 ** for MSVC and a macro for everything else. Ticket #2457.
55699 */
55700 #ifndef NDEBUG
55701 static void assertCellInfo(BtCursor *pCur){
55702 CellInfo info;
@@ -55909,11 +56058,11 @@
55909 ** The content being read or written might appear on the main page
55910 ** or be scattered out on multiple overflow pages.
55911 **
55912 ** If the current cursor entry uses one or more overflow pages and the
55913 ** eOp argument is not 2, this function may allocate space for and lazily
55914 ** popluates the overflow page-list cache array (BtCursor.aOverflow).
55915 ** Subsequent calls use this cache to make seeking to the supplied offset
55916 ** more efficient.
55917 **
55918 ** Once an overflow page-list cache has been allocated, it may be
55919 ** invalidated if some other cursor writes to the same table, or if
@@ -56111,11 +56260,11 @@
56111 return rc;
56112 }
56113
56114 /*
56115 ** Read part of the key associated with cursor pCur. Exactly
56116 ** "amt" bytes will be transfered into pBuf[]. The transfer
56117 ** begins at "offset".
56118 **
56119 ** The caller must ensure that pCur is pointing to a valid row
56120 ** in the table.
56121 **
@@ -56664,18 +56813,18 @@
56664 if( nCell<=pPage->max1bytePayload ){
56665 /* This branch runs if the record-size field of the cell is a
56666 ** single byte varint and the record fits entirely on the main
56667 ** b-tree page. */
56668 testcase( pCell+nCell+1==pPage->aDataEnd );
56669 c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey, 0);
56670 }else if( !(pCell[1] & 0x80)
56671 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
56672 ){
56673 /* The record-size field is a 2 byte varint and the record
56674 ** fits entirely on the main b-tree page. */
56675 testcase( pCell+nCell+2==pPage->aDataEnd );
56676 c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey, 0);
56677 }else{
56678 /* The record flows over onto one or more overflow pages. In
56679 ** this case the whole cell needs to be parsed, a buffer allocated
56680 ** and accessPayload() used to retrieve the record into the
56681 ** buffer before VdbeRecordCompare() can be called. */
@@ -56692,11 +56841,11 @@
56692 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 2);
56693 if( rc ){
56694 sqlite3_free(pCellKey);
56695 goto moveto_finish;
56696 }
56697 c = xRecordCompare(nCell, pCellKey, pIdxKey, 0);
56698 sqlite3_free(pCellKey);
56699 }
56700 assert(
56701 (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
56702 && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
@@ -57807,11 +57956,11 @@
57807 /*
57808 ** Add a list of cells to a page. The page should be initially empty.
57809 ** The cells are guaranteed to fit on the page.
57810 */
57811 static void assemblePage(
57812 MemPage *pPage, /* The page to be assemblied */
57813 int nCell, /* The number of cells to add to this page */
57814 u8 **apCell, /* Pointers to cell bodies */
57815 u16 *aSize /* Sizes of the cells */
57816 ){
57817 int i; /* Loop counter */
@@ -58473,11 +58622,11 @@
58473 apOld[i] = 0;
58474 i++;
58475 }
58476
58477 /*
58478 ** Put the new pages in accending order. This helps to
58479 ** keep entries in the disk file in order so that a scan
58480 ** of the table is a linear scan through the file. That
58481 ** in turn helps the operating system to deliver pages
58482 ** from the disk more rapidly.
58483 **
@@ -58868,11 +59017,11 @@
58868 && pParent->nCell==iIdx
58869 ){
58870 /* Call balance_quick() to create a new sibling of pPage on which
58871 ** to store the overflow cell. balance_quick() inserts a new cell
58872 ** into pParent, which may cause pParent overflow. If this
58873 ** happens, the next interation of the do-loop will balance pParent
58874 ** use either balance_nonroot() or balance_deeper(). Until this
58875 ** happens, the overflow cell is stored in the aBalanceQuickSpace[]
58876 ** buffer.
58877 **
58878 ** The purpose of the following assert() is to check that only a
@@ -58945,11 +59094,11 @@
58945 **
58946 ** If the seekResult parameter is non-zero, then a successful call to
58947 ** MovetoUnpacked() to seek cursor pCur to (pKey, nKey) has already
58948 ** been performed. seekResult is the search result returned (a negative
58949 ** number if pCur points at an entry that is smaller than (pKey, nKey), or
58950 ** a positive value if pCur points at an etry that is larger than
58951 ** (pKey, nKey)).
58952 **
58953 ** If the seekResult parameter is non-zero, then the caller guarantees that
58954 ** cursor pCur is pointing at the existing copy of a row that is to be
58955 ** overwritten. If the seekResult parameter is 0, then cursor pCur may
@@ -59102,11 +59251,11 @@
59102 return rc;
59103 }
59104
59105 /*
59106 ** Delete the entry that the cursor is pointing to. The cursor
59107 ** is left pointing at a arbitrary location.
59108 */
59109 SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur){
59110 Btree *p = pCur->pBtree;
59111 BtShared *pBt = p->pBt;
59112 int rc; /* Return code */
@@ -59800,11 +59949,11 @@
59800
59801
59802 /*
59803 ** Add 1 to the reference count for page iPage. If this is the second
59804 ** reference to the page, add an error message to pCheck->zErrMsg.
59805 ** Return 1 if there are 2 ore more references to the page and 0 if
59806 ** if this is the first reference to the page.
59807 **
59808 ** Also check that the page number is in bounds.
59809 */
59810 static int checkRef(IntegrityCk *pCheck, Pgno iPage, char *zContext){
@@ -61307,33 +61456,41 @@
61307 **
61308 ** This routine is intended for use inside of assert() statements, like
61309 ** this: assert( sqlite3VdbeCheckMemInvariants(pMem) );
61310 */
61311 SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem *p){
61312 /* The MEM_Dyn bit is set if and only if Mem.xDel is a non-NULL destructor
61313 ** function for Mem.z
61314 */
61315 assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
61316 assert( (p->flags & MEM_Dyn)!=0 || p->xDel==0 );
 
 
 
 
 
 
 
 
 
61317
61318 /* If p holds a string or blob, the Mem.z must point to exactly
61319 ** one of the following:
61320 **
61321 ** (1) Memory in Mem.zMalloc and managed by the Mem object
61322 ** (2) Memory to be freed using Mem.xDel
61323 ** (3) An ephermal string or blob
61324 ** (4) A static string or blob
61325 */
61326 if( (p->flags & (MEM_Str|MEM_Blob)) && p->z!=0 ){
61327 assert(
61328 ((p->z==p->zMalloc)? 1 : 0) +
61329 ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
61330 ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
61331 ((p->flags&MEM_Static)!=0 ? 1 : 0) == 1
61332 );
61333 }
61334
61335 return 1;
61336 }
61337 #endif
61338
61339
@@ -61383,33 +61540,37 @@
61383 ** If the bPreserve argument is true, then copy of the content of
61384 ** pMem->z into the new allocation. pMem must be either a string or
61385 ** blob if bPreserve is true. If bPreserve is false, any prior content
61386 ** in pMem->z is discarded.
61387 */
61388 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
61389 assert( sqlite3VdbeCheckMemInvariants(pMem) );
61390 assert( (pMem->flags&MEM_RowSet)==0 );
61391
61392 /* If the bPreserve flag is set to true, then the memory cell must already
61393 ** contain a valid string or blob value. */
61394 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
61395 testcase( bPreserve && pMem->z==0 );
61396
61397 if( pMem->zMalloc==0 || sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
 
 
61398 if( n<32 ) n = 32;
61399 if( bPreserve && pMem->z==pMem->zMalloc ){
61400 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
61401 bPreserve = 0;
61402 }else{
61403 sqlite3DbFree(pMem->db, pMem->zMalloc);
61404 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
61405 }
61406 if( pMem->zMalloc==0 ){
61407 VdbeMemReleaseExtern(pMem);
61408 pMem->z = 0;
61409 pMem->flags = MEM_Null;
61410 return SQLITE_NOMEM;
 
 
61411 }
61412 }
61413
61414 if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
61415 memcpy(pMem->zMalloc, pMem->z, pMem->n);
@@ -61419,29 +61580,50 @@
61419 pMem->xDel((void *)(pMem->z));
61420 }
61421
61422 pMem->z = pMem->zMalloc;
61423 pMem->flags &= ~(MEM_Dyn|MEM_Ephem|MEM_Static);
61424 pMem->xDel = 0;
61425 return SQLITE_OK;
61426 }
61427
61428 /*
61429 ** Make the given Mem object MEM_Dyn. In other words, make it so
61430 ** that any TEXT or BLOB content is stored in memory obtained from
61431 ** malloc(). In this way, we know that the memory is safe to be
61432 ** overwritten or altered.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61433 **
61434 ** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
61435 */
61436 SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem *pMem){
61437 int f;
61438 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61439 assert( (pMem->flags&MEM_RowSet)==0 );
61440 ExpandBlob(pMem);
61441 f = pMem->flags;
61442 if( (f&(MEM_Str|MEM_Blob)) && pMem->z!=pMem->zMalloc ){
61443 if( sqlite3VdbeMemGrow(pMem, pMem->n + 2, 1) ){
61444 return SQLITE_NOMEM;
61445 }
61446 pMem->z[pMem->n] = 0;
61447 pMem->z[pMem->n+1] = 0;
@@ -61521,11 +61703,11 @@
61521 **
61522 ** A MEM_Null value will never be passed to this function. This function is
61523 ** used for converting values to text for returning to the user (i.e. via
61524 ** sqlite3_value_text()), or for ensuring that values to be used as btree
61525 ** keys are strings. In the former case a NULL pointer is returned the
61526 ** user and the later is an internal programming error.
61527 */
61528 SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem *pMem, u8 enc, u8 bForce){
61529 int fg = pMem->flags;
61530 const int nByte = 32;
61531
@@ -61535,11 +61717,11 @@
61535 assert( fg&(MEM_Int|MEM_Real) );
61536 assert( (pMem->flags&MEM_RowSet)==0 );
61537 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
61538
61539
61540 if( sqlite3VdbeMemGrow(pMem, nByte, 0) ){
61541 return SQLITE_NOMEM;
61542 }
61543
61544 /* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8
61545 ** string representation of the value. Then, if the required encoding
@@ -61549,11 +61731,11 @@
61549 */
61550 if( fg & MEM_Int ){
61551 sqlite3_snprintf(nByte, pMem->z, "%lld", pMem->u.i);
61552 }else{
61553 assert( fg & MEM_Real );
61554 sqlite3_snprintf(nByte, pMem->z, "%!.15g", pMem->r);
61555 }
61556 pMem->n = sqlite3Strlen30(pMem->z);
61557 pMem->enc = SQLITE_UTF8;
61558 pMem->flags |= MEM_Str|MEM_Term;
61559 if( bForce ) pMem->flags &= ~(MEM_Int|MEM_Real);
@@ -61582,76 +61764,83 @@
61582 t.db = pMem->db;
61583 ctx.pOut = &t;
61584 ctx.pMem = pMem;
61585 ctx.pFunc = pFunc;
61586 pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
61587 assert( 0==(pMem->flags&MEM_Dyn) && !pMem->xDel );
61588 sqlite3DbFree(pMem->db, pMem->zMalloc);
61589 memcpy(pMem, &t, sizeof(t));
61590 rc = ctx.isError;
61591 }
61592 return rc;
61593 }
61594
61595 /*
61596 ** If the memory cell contains a string value that must be freed by
61597 ** invoking an external callback, free it now. Calling this function
61598 ** does not free any Mem.zMalloc buffer.
61599 **
61600 ** The VdbeMemReleaseExtern() macro invokes this routine if only if there
61601 ** is work for this routine to do.
 
61602 */
61603 SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p){
61604 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
 
61605 if( p->flags&MEM_Agg ){
61606 sqlite3VdbeMemFinalize(p, p->u.pDef);
61607 assert( (p->flags & MEM_Agg)==0 );
61608 sqlite3VdbeMemRelease(p);
61609 }else if( p->flags&MEM_Dyn ){
 
61610 assert( (p->flags&MEM_RowSet)==0 );
61611 assert( p->xDel!=SQLITE_DYNAMIC && p->xDel!=0 );
61612 p->xDel((void *)p->z);
61613 p->xDel = 0;
61614 }else if( p->flags&MEM_RowSet ){
61615 sqlite3RowSetClear(p->u.pRowSet);
61616 }else if( p->flags&MEM_Frame ){
61617 sqlite3VdbeMemSetNull(p);
 
 
61618 }
 
61619 }
61620
61621 /*
61622 ** Release memory held by the Mem p, both external memory cleared
61623 ** by p->xDel and memory in p->zMalloc.
61624 **
61625 ** This is a helper routine invoked by sqlite3VdbeMemRelease() in
61626 ** the uncommon case when there really is memory in p that is
61627 ** need of freeing.
61628 */
61629 static SQLITE_NOINLINE void vdbeMemRelease(Mem *p){
61630 if( VdbeMemDynamic(p) ){
61631 sqlite3VdbeMemReleaseExternal(p);
61632 }
61633 if( p->zMalloc ){
61634 sqlite3DbFree(p->db, p->zMalloc);
61635 p->zMalloc = 0;
61636 }
61637 p->z = 0;
61638 }
61639
61640 /*
61641 ** Release any memory held by the Mem. This may leave the Mem in an
61642 ** inconsistent state, for example with (Mem.z==0) and
61643 ** (Mem.flags==MEM_Str).
 
 
 
 
 
61644 */
61645 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
61646 assert( sqlite3VdbeCheckMemInvariants(p) );
61647 if( VdbeMemDynamic(p) || p->zMalloc ){
61648 vdbeMemRelease(p);
61649 }else{
61650 p->z = 0;
61651 }
61652 assert( p->xDel==0 );
61653 }
61654
61655 /*
61656 ** Convert a 64-bit IEEE double into a 64-bit signed integer.
61657 ** If the double is out of range of a 64-bit signed integer then
@@ -61686,11 +61875,11 @@
61686 ** Return some kind of integer value which is the best we can do
61687 ** at representing the value that *pMem describes as an integer.
61688 ** If pMem is an integer, then the value is exact. If pMem is
61689 ** a floating-point then the value returned is the integer part.
61690 ** If pMem is a string or blob, then we make an attempt to convert
61691 ** it into a integer and return that. If pMem represents an
61692 ** an SQL-NULL value, return 0.
61693 **
61694 ** If pMem represents a string value, its encoding might be changed.
61695 */
61696 SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *pMem){
@@ -61699,11 +61888,11 @@
61699 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
61700 flags = pMem->flags;
61701 if( flags & MEM_Int ){
61702 return pMem->u.i;
61703 }else if( flags & MEM_Real ){
61704 return doubleToInt64(pMem->r);
61705 }else if( flags & (MEM_Str|MEM_Blob) ){
61706 i64 value = 0;
61707 assert( pMem->z || pMem->n==0 );
61708 sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
61709 return value;
@@ -61720,11 +61909,11 @@
61720 */
61721 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
61722 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61723 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
61724 if( pMem->flags & MEM_Real ){
61725 return pMem->r;
61726 }else if( pMem->flags & MEM_Int ){
61727 return (double)pMem->u.i;
61728 }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
61729 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
61730 double val = (double)0;
@@ -61739,16 +61928,17 @@
61739 /*
61740 ** The MEM structure is already a MEM_Real. Try to also make it a
61741 ** MEM_Int if we can.
61742 */
61743 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem *pMem){
 
61744 assert( pMem->flags & MEM_Real );
61745 assert( (pMem->flags & MEM_RowSet)==0 );
61746 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61747 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
61748
61749 pMem->u.i = doubleToInt64(pMem->r);
61750
61751 /* Only mark the value as an integer if
61752 **
61753 ** (1) the round-trip conversion real->int->real is a no-op, and
61754 ** (2) The integer is neither the largest nor the smallest
@@ -61756,15 +61946,13 @@
61756 **
61757 ** The second and third terms in the following conditional enforces
61758 ** the second condition under the assumption that addition overflow causes
61759 ** values to wrap around.
61760 */
61761 if( pMem->r==(double)pMem->u.i
61762 && pMem->u.i>SMALLEST_INT64
61763 && pMem->u.i<LARGEST_INT64
61764 ){
61765 pMem->flags |= MEM_Int;
61766 }
61767 }
61768
61769 /*
61770 ** Convert pMem to type integer. Invalidate any prior representations.
@@ -61785,11 +61973,11 @@
61785 */
61786 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem *pMem){
61787 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61788 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
61789
61790 pMem->r = sqlite3VdbeRealValue(pMem);
61791 MemSetTypeFlag(pMem, MEM_Real);
61792 return SQLITE_OK;
61793 }
61794
61795 /*
@@ -61805,11 +61993,11 @@
61805 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
61806 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61807 if( 0==sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc) ){
61808 MemSetTypeFlag(pMem, MEM_Int);
61809 }else{
61810 pMem->r = sqlite3VdbeRealValue(pMem);
61811 MemSetTypeFlag(pMem, MEM_Real);
61812 sqlite3VdbeIntegerAffinity(pMem);
61813 }
61814 }
61815 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))!=0 );
@@ -61859,24 +62047,41 @@
61859 break;
61860 }
61861 }
61862 }
61863
 
 
 
 
 
 
 
 
 
 
 
 
61864
61865 /*
61866 ** Delete any previous value and set the value stored in *pMem to NULL.
 
 
 
 
 
 
 
 
 
61867 */
61868 SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem *pMem){
61869 if( pMem->flags & MEM_Frame ){
61870 VdbeFrame *pFrame = pMem->u.pFrame;
61871 pFrame->pParent = pFrame->v->pDelFrame;
61872 pFrame->v->pDelFrame = pFrame;
61873 }
61874 if( pMem->flags & MEM_RowSet ){
61875 sqlite3RowSetClear(pMem->u.pRowSet);
61876 }
61877 MemSetTypeFlag(pMem, MEM_Null);
61878 }
61879 SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){
61880 sqlite3VdbeMemSetNull((Mem*)p);
61881 }
61882
@@ -61889,27 +62094,20 @@
61889 pMem->flags = MEM_Blob|MEM_Zero;
61890 pMem->n = 0;
61891 if( n<0 ) n = 0;
61892 pMem->u.nZero = n;
61893 pMem->enc = SQLITE_UTF8;
61894
61895 #ifdef SQLITE_OMIT_INCRBLOB
61896 sqlite3VdbeMemGrow(pMem, n, 0);
61897 if( pMem->z ){
61898 pMem->n = n;
61899 memset(pMem->z, 0, n);
61900 }
61901 #endif
61902 }
61903
61904 /*
61905 ** The pMem is known to contain content that needs to be destroyed prior
61906 ** to a value change. So invoke the destructor, then set the value to
61907 ** a 64-bit integer.
61908 */
61909 static SQLITE_NOINLINE void vdbeReleaseAndSetInt64(Mem *pMem, i64 val){
61910 sqlite3VdbeMemReleaseExternal(pMem);
61911 pMem->u.i = val;
61912 pMem->flags = MEM_Int;
61913 }
61914
61915 /*
@@ -61929,15 +62127,13 @@
61929 /*
61930 ** Delete any previous value and set the value stored in *pMem to val,
61931 ** manifest type REAL.
61932 */
61933 SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem *pMem, double val){
61934 if( sqlite3IsNaN(val) ){
61935 sqlite3VdbeMemSetNull(pMem);
61936 }else{
61937 sqlite3VdbeMemRelease(pMem);
61938 pMem->r = val;
61939 pMem->flags = MEM_Real;
61940 }
61941 }
61942 #endif
61943
@@ -61951,14 +62147,15 @@
61951 assert( (pMem->flags & MEM_RowSet)==0 );
61952 sqlite3VdbeMemRelease(pMem);
61953 pMem->zMalloc = sqlite3DbMallocRaw(db, 64);
61954 if( db->mallocFailed ){
61955 pMem->flags = MEM_Null;
 
61956 }else{
61957 assert( pMem->zMalloc );
61958 pMem->u.pRowSet = sqlite3RowSetInit(db, pMem->zMalloc,
61959 sqlite3DbMallocSize(db, pMem->zMalloc));
61960 assert( pMem->u.pRowSet!=0 );
61961 pMem->flags = MEM_RowSet;
61962 }
61963 }
61964
@@ -61978,11 +62175,11 @@
61978 return 0;
61979 }
61980
61981 #ifdef SQLITE_DEBUG
61982 /*
61983 ** This routine prepares a memory cell for modication by breaking
61984 ** its link to a shallow copy and by marking any current shallow
61985 ** copies of this cell as invalid.
61986 **
61987 ** This is used for testing and debugging only - to make sure shallow
61988 ** copies are not misused.
@@ -62011,13 +62208,13 @@
62011 ** pFrom->z is used, then pTo->z points to the same thing as pFrom->z
62012 ** and flags gets srcType (either MEM_Ephem or MEM_Static).
62013 */
62014 SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){
62015 assert( (pFrom->flags & MEM_RowSet)==0 );
62016 VdbeMemReleaseExtern(pTo);
 
62017 memcpy(pTo, pFrom, MEMCELLSIZE);
62018 pTo->xDel = 0;
62019 if( (pFrom->flags&MEM_Static)==0 ){
62020 pTo->flags &= ~(MEM_Dyn|MEM_Static|MEM_Ephem);
62021 assert( srcType==MEM_Ephem || srcType==MEM_Static );
62022 pTo->flags |= srcType;
62023 }
@@ -62028,16 +62225,15 @@
62028 ** freed before the copy is made.
62029 */
62030 SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){
62031 int rc = SQLITE_OK;
62032
 
62033 assert( (pFrom->flags & MEM_RowSet)==0 );
62034 VdbeMemReleaseExtern(pTo);
62035 memcpy(pTo, pFrom, MEMCELLSIZE);
62036 pTo->flags &= ~MEM_Dyn;
62037 pTo->xDel = 0;
62038
62039 if( pTo->flags&(MEM_Str|MEM_Blob) ){
62040 if( 0==(pFrom->flags&MEM_Static) ){
62041 pTo->flags |= MEM_Ephem;
62042 rc = sqlite3VdbeMemMakeWriteable(pTo);
62043 }
@@ -62058,12 +62254,11 @@
62058 assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db );
62059
62060 sqlite3VdbeMemRelease(pTo);
62061 memcpy(pTo, pFrom, sizeof(Mem));
62062 pFrom->flags = MEM_Null;
62063 pFrom->xDel = 0;
62064 pFrom->zMalloc = 0;
62065 }
62066
62067 /*
62068 ** Change the value of a Mem to be a string or a BLOB.
62069 **
@@ -62106,11 +62301,12 @@
62106 }
62107 flags = (enc==0?MEM_Blob:MEM_Str);
62108 if( nByte<0 ){
62109 assert( enc!=0 );
62110 if( enc==SQLITE_UTF8 ){
62111 for(nByte=0; nByte<=iLimit && z[nByte]; nByte++){}
 
62112 }else{
62113 for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
62114 }
62115 flags |= MEM_Term;
62116 }
@@ -62125,18 +62321,18 @@
62125 nAlloc += (enc==SQLITE_UTF8?1:2);
62126 }
62127 if( nByte>iLimit ){
62128 return SQLITE_TOOBIG;
62129 }
62130 if( sqlite3VdbeMemGrow(pMem, nAlloc, 0) ){
62131 return SQLITE_NOMEM;
62132 }
62133 memcpy(pMem->z, z, nAlloc);
62134 }else if( xDel==SQLITE_DYNAMIC ){
62135 sqlite3VdbeMemRelease(pMem);
62136 pMem->zMalloc = pMem->z = (char *)z;
62137 pMem->xDel = 0;
62138 }else{
62139 sqlite3VdbeMemRelease(pMem);
62140 pMem->z = (char *)z;
62141 pMem->xDel = xDel;
62142 flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
@@ -62164,12 +62360,15 @@
62164 ** The data or key is taken from the entry that pCur is currently pointing
62165 ** to. offset and amt determine what portion of the data or key to retrieve.
62166 ** key is true to get the key or false to get data. The result is written
62167 ** into the pMem element.
62168 **
62169 ** The pMem structure is assumed to be uninitialized. Any prior content
62170 ** is overwritten without being freed.
 
 
 
62171 **
62172 ** If this routine fails for any reason (malloc returns NULL or unable
62173 ** to read from the disk) then the pMem is left in an inconsistent state.
62174 */
62175 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
@@ -62182,10 +62381,11 @@
62182 char *zData; /* Data from the btree layer */
62183 u32 available = 0; /* Number of bytes available on the local btree page */
62184 int rc = SQLITE_OK; /* Return code */
62185
62186 assert( sqlite3BtreeCursorIsValid(pCur) );
 
62187
62188 /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
62189 ** that both the BtShared and database handle mutexes are held. */
62190 assert( (pMem->flags & MEM_RowSet)==0 );
62191 if( key ){
@@ -62194,27 +62394,29 @@
62194 zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
62195 }
62196 assert( zData!=0 );
62197
62198 if( offset+amt<=available ){
62199 sqlite3VdbeMemRelease(pMem);
62200 pMem->z = &zData[offset];
62201 pMem->flags = MEM_Blob|MEM_Ephem;
62202 pMem->n = (int)amt;
62203 }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
62204 if( key ){
62205 rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
62206 }else{
62207 rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
62208 }
62209 if( rc==SQLITE_OK ){
62210 pMem->z[amt] = 0;
62211 pMem->z[amt+1] = 0;
62212 pMem->flags = MEM_Blob|MEM_Term;
62213 pMem->n = (int)amt;
62214 }else{
62215 sqlite3VdbeMemRelease(pMem);
 
 
 
62216 }
62217 }
62218
62219 return rc;
62220 }
@@ -62434,18 +62636,18 @@
62434 /* This branch happens for multiple negative signs. Ex: -(-5) */
62435 if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal)
62436 && pVal!=0
62437 ){
62438 sqlite3VdbeMemNumerify(pVal);
62439 if( pVal->u.i==SMALLEST_INT64 ){
62440 pVal->flags &= ~MEM_Int;
62441 pVal->flags |= MEM_Real;
62442 pVal->r = (double)SMALLEST_INT64;
 
62443 }else{
62444 pVal->u.i = -pVal->u.i;
62445 }
62446 pVal->r = -pVal->r;
62447 sqlite3ValueApplyAffinity(pVal, affinity, enc);
62448 }
62449 }else if( op==TK_NULL ){
62450 pVal = valueNew(db, pCtx);
62451 if( pVal==0 ) goto no_mem;
@@ -62749,11 +62951,11 @@
62749 int i;
62750 int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
62751 Mem *aMem = pRec->aMem;
62752 sqlite3 *db = aMem[0].db;
62753 for(i=0; i<nCol; i++){
62754 sqlite3DbFree(db, aMem[i].zMalloc);
62755 }
62756 sqlite3KeyInfoUnref(pRec->pKeyInfo);
62757 sqlite3DbFree(db, pRec);
62758 }
62759 }
@@ -62809,13 +63011,11 @@
62809 ** May you find forgiveness for yourself and forgive others.
62810 ** May you share freely, never taking more than you give.
62811 **
62812 *************************************************************************
62813 ** This file contains code used for creating, destroying, and populating
62814 ** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.) Prior
62815 ** to version 2.8.7, all this code was combined into the vdbe.c source file.
62816 ** But that file was getting too big so this subroutines were split out.
62817 */
62818
62819 /*
62820 ** Create a new virtual database engine.
62821 */
@@ -63495,11 +63695,11 @@
63495 case P4_MEM: {
63496 if( db->pnBytesFreed==0 ){
63497 sqlite3ValueFree((sqlite3_value*)p4);
63498 }else{
63499 Mem *p = (Mem*)p4;
63500 sqlite3DbFree(db, p->zMalloc);
63501 sqlite3DbFree(db, p);
63502 }
63503 break;
63504 }
63505 case P4_VTAB : {
@@ -63692,11 +63892,11 @@
63692 **
63693 ** If a memory allocation error has occurred prior to the calling of this
63694 ** routine, then a pointer to a dummy VdbeOp will be returned. That opcode
63695 ** is readable but not writable, though it is cast to a writable value.
63696 ** The return of a dummy opcode allows the call to continue functioning
63697 ** after a OOM fault without having to check to see if the return from
63698 ** this routine is a valid pointer. But because the dummy.opcode is 0,
63699 ** dummy will never be written to. This is verified by code inspection and
63700 ** by running with Valgrind.
63701 */
63702 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
@@ -63873,11 +64073,11 @@
63873 if( pMem->flags & MEM_Str ){
63874 zP4 = pMem->z;
63875 }else if( pMem->flags & MEM_Int ){
63876 sqlite3_snprintf(nTemp, zTemp, "%lld", pMem->u.i);
63877 }else if( pMem->flags & MEM_Real ){
63878 sqlite3_snprintf(nTemp, zTemp, "%.16g", pMem->r);
63879 }else if( pMem->flags & MEM_Null ){
63880 sqlite3_snprintf(nTemp, zTemp, "NULL");
63881 }else{
63882 assert( pMem->flags & MEM_Blob );
63883 zP4 = "(blob)";
@@ -64023,20 +64223,20 @@
64023 /*
64024 ** Release an array of N Mem elements
64025 */
64026 static void releaseMemArray(Mem *p, int N){
64027 if( p && N ){
64028 Mem *pEnd;
64029 sqlite3 *db = p->db;
64030 u8 malloc_failed = db->mallocFailed;
64031 if( db->pnBytesFreed ){
64032 for(pEnd=&p[N]; p<pEnd; p++){
64033 sqlite3DbFree(db, p->zMalloc);
64034 }
64035 return;
64036 }
64037 for(pEnd=&p[N]; p<pEnd; p++){
64038 assert( (&p[1])==pEnd || p[0].db==p[1].db );
64039 assert( sqlite3VdbeCheckMemInvariants(p) );
64040
64041 /* This block is really an inlined version of sqlite3VdbeMemRelease()
64042 ** that takes advantage of the fact that the memory cell value is
@@ -64054,17 +64254,17 @@
64054 testcase( p->flags & MEM_Dyn );
64055 testcase( p->flags & MEM_Frame );
64056 testcase( p->flags & MEM_RowSet );
64057 if( p->flags&(MEM_Agg|MEM_Dyn|MEM_Frame|MEM_RowSet) ){
64058 sqlite3VdbeMemRelease(p);
64059 }else if( p->zMalloc ){
64060 sqlite3DbFree(db, p->zMalloc);
64061 p->zMalloc = 0;
64062 }
64063
64064 p->flags = MEM_Undefined;
64065 }
64066 db->mallocFailed = malloc_failed;
64067 }
64068 }
64069
64070 /*
@@ -64223,11 +64423,11 @@
64223
64224 pMem->flags = MEM_Int;
64225 pMem->u.i = pOp->p3; /* P3 */
64226 pMem++;
64227
64228 if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
64229 assert( p->db->mallocFailed );
64230 return SQLITE_ERROR;
64231 }
64232 pMem->flags = MEM_Str|MEM_Term;
64233 zP4 = displayP4(pOp, pMem->z, 32);
@@ -64239,11 +64439,11 @@
64239 pMem->enc = SQLITE_UTF8;
64240 }
64241 pMem++;
64242
64243 if( p->explain==1 ){
64244 if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
64245 assert( p->db->mallocFailed );
64246 return SQLITE_ERROR;
64247 }
64248 pMem->flags = MEM_Str|MEM_Term;
64249 pMem->n = 2;
@@ -64250,11 +64450,11 @@
64250 sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
64251 pMem->enc = SQLITE_UTF8;
64252 pMem++;
64253
64254 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
64255 if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
64256 assert( p->db->mallocFailed );
64257 return SQLITE_ERROR;
64258 }
64259 pMem->flags = MEM_Str|MEM_Term;
64260 pMem->n = displayComment(pOp, zP4, pMem->z, 500);
@@ -64403,17 +64603,17 @@
64403 }
64404
64405 /*
64406 ** Prepare a virtual machine for execution for the first time after
64407 ** creating the virtual machine. This involves things such
64408 ** as allocating stack space and initializing the program counter.
64409 ** After the VDBE has be prepped, it can be executed by one or more
64410 ** calls to sqlite3VdbeExec().
64411 **
64412 ** This function may be called exact once on a each virtual machine.
64413 ** After this routine is called the VM has been "packaged" and is ready
64414 ** to run. After this routine is called, futher calls to
64415 ** sqlite3VdbeAddOp() functions are prohibited. This routine disconnects
64416 ** the Vdbe from the Parse object that helped generate it so that the
64417 ** the Vdbe becomes an independent entity and the Parse object can be
64418 ** destroyed.
64419 **
@@ -64615,15 +64815,11 @@
64615 sqlite3VdbeDeleteAuxData(p, -1, 0);
64616 assert( p->pAuxData==0 );
64617 }
64618
64619 /*
64620 ** Clean up the VM after execution.
64621 **
64622 ** This routine will automatically close any cursors, lists, and/or
64623 ** sorters that were left open. It also deletes the values of
64624 ** variables in the aVar[] array.
64625 */
64626 static void Cleanup(Vdbe *p){
64627 sqlite3 *db = p->db;
64628
64629 #ifdef SQLITE_DEBUG
@@ -64787,11 +64983,11 @@
64787 }
64788 }
64789
64790 /* The complex case - There is a multi-file write-transaction active.
64791 ** This requires a master journal file to ensure the transaction is
64792 ** committed atomicly.
64793 */
64794 #ifndef SQLITE_OMIT_DISKIO
64795 else{
64796 sqlite3_vfs *pVfs = db->pVfs;
64797 int needSync = 0;
@@ -65435,11 +65631,11 @@
65435 **
65436 ** * the associated function parameter is the 32nd or later (counting
65437 ** from left to right), or
65438 **
65439 ** * the corresponding bit in argument mask is clear (where the first
65440 ** function parameter corrsponds to bit 0 etc.).
65441 */
65442 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe *pVdbe, int iOp, int mask){
65443 AuxData **pp = &pVdbe->pAuxData;
65444 while( *pp ){
65445 AuxData *pAux = *pp;
@@ -65539,11 +65735,11 @@
65539
65540 /*
65541 ** Something has moved cursor "p" out of place. Maybe the row it was
65542 ** pointed to was deleted out from under it. Or maybe the btree was
65543 ** rebalanced. Whatever the cause, try to restore "p" to the place it
65544 ** is suppose to be pointing. If the row was deleted out from under the
65545 ** cursor, set the cursor to point to a NULL row.
65546 */
65547 static int SQLITE_NOINLINE handleMovedCursor(VdbeCursor *p){
65548 int isDifferentRow, rc;
65549 assert( p->pCursor!=0 );
@@ -65746,12 +65942,12 @@
65746 /* Integer and Real */
65747 if( serial_type<=7 && serial_type>0 ){
65748 u64 v;
65749 u32 i;
65750 if( serial_type==7 ){
65751 assert( sizeof(v)==sizeof(pMem->r) );
65752 memcpy(&v, &pMem->r, sizeof(v));
65753 swapMixedEndianFloat(v);
65754 }else{
65755 v = pMem->u.i;
65756 }
65757 len = i = sqlite3VdbeSerialTypeLen(serial_type);
@@ -65817,14 +66013,14 @@
65817 static const double r1 = 1.0;
65818 u64 t2 = t1;
65819 swapMixedEndianFloat(t2);
65820 assert( sizeof(r1)==sizeof(t2) && memcmp(&r1, &t2, sizeof(r1))==0 );
65821 #endif
65822 assert( sizeof(x)==8 && sizeof(pMem->r)==8 );
65823 swapMixedEndianFloat(x);
65824 memcpy(&pMem->r, &x, sizeof(x));
65825 pMem->flags = sqlite3IsNaN(pMem->r) ? MEM_Null : MEM_Real;
65826 }
65827 return 8;
65828 }
65829 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(
65830 const unsigned char *buf, /* Buffer to deserialize from */
@@ -65882,11 +66078,10 @@
65882 }
65883 default: {
65884 static const u16 aFlag[] = { MEM_Blob|MEM_Ephem, MEM_Str|MEM_Ephem };
65885 pMem->z = (char *)buf;
65886 pMem->n = (serial_type-12)/2;
65887 pMem->xDel = 0;
65888 pMem->flags = aFlag[serial_type&1];
65889 return pMem->n;
65890 }
65891 }
65892 return 0;
@@ -65958,21 +66153,21 @@
65958 p->default_rc = 0;
65959 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
65960 idx = getVarint32(aKey, szHdr);
65961 d = szHdr;
65962 u = 0;
65963 while( idx<szHdr && u<p->nField && d<=nKey ){
65964 u32 serial_type;
65965
65966 idx += getVarint32(&aKey[idx], serial_type);
65967 pMem->enc = pKeyInfo->enc;
65968 pMem->db = pKeyInfo->db;
65969 /* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */
65970 pMem->zMalloc = 0;
65971 d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
65972 pMem++;
65973 u++;
65974 }
65975 assert( u<=pKeyInfo->nField + 1 );
65976 p->nField = u;
65977 }
65978
@@ -66005,11 +66200,11 @@
66005 pKeyInfo = pPKey2->pKeyInfo;
66006 if( pKeyInfo->db==0 ) return 1;
66007 mem1.enc = pKeyInfo->enc;
66008 mem1.db = pKeyInfo->db;
66009 /* mem1.flags = 0; // Will be initialized by sqlite3VdbeSerialGet() */
66010 VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */
66011
66012 /* Compilers may complain that mem1.u.i is potentially uninitialized.
66013 ** We could initialize it, as shown here, to silence those complaints.
66014 ** But in fact, mem1.u.i will never actually be used uninitialized, and doing
66015 ** the unnecessary initialization has a measurable negative performance
@@ -66048,11 +66243,11 @@
66048
66049 /* Do the comparison
66050 */
66051 rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i], pKeyInfo->aColl[i]);
66052 if( rc!=0 ){
66053 assert( mem1.zMalloc==0 ); /* See comment below */
66054 if( pKeyInfo->aSortOrder[i] ){
66055 rc = -rc; /* Invert the result for DESC sort order. */
66056 }
66057 goto debugCompareEnd;
66058 }
@@ -66061,14 +66256,14 @@
66061
66062 /* No memory allocation is ever used on mem1. Prove this using
66063 ** the following assert(). If the assert() fails, it indicates a
66064 ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
66065 */
66066 assert( mem1.zMalloc==0 );
66067
66068 /* rc==0 here means that one of the keys ran out of fields and
66069 ** all the fields up to that point were equal. Return the the default_rc
66070 ** value. */
66071 rc = pPKey2->default_rc;
66072
66073 debugCompareEnd:
66074 if( desiredResult==0 && rc==0 ) return 1;
@@ -66100,12 +66295,12 @@
66100 int rc;
66101 const void *v1, *v2;
66102 int n1, n2;
66103 Mem c1;
66104 Mem c2;
66105 memset(&c1, 0, sizeof(c1));
66106 memset(&c2, 0, sizeof(c2));
66107 sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
66108 sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
66109 v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
66110 n1 = v1==0 ? 0 : c1.n;
66111 v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
@@ -66115,10 +66310,22 @@
66115 sqlite3VdbeMemRelease(&c2);
66116 if( (v1==0 || v2==0) && prcErr ) *prcErr = SQLITE_NOMEM;
66117 return rc;
66118 }
66119 }
 
 
 
 
 
 
 
 
 
 
 
 
66120
66121 /*
66122 ** Compare the values contained by the two memory cells, returning
66123 ** negative, zero or positive if pMem1 is less than, equal to, or greater
66124 ** than pMem2. Sorting order is NULL's first, followed by numbers (integers
@@ -66126,11 +66333,10 @@
66126 ** sequence pColl and finally blob's ordered by memcmp().
66127 **
66128 ** Two NULL values are considered equal by this function.
66129 */
66130 SQLITE_PRIVATE int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
66131 int rc;
66132 int f1, f2;
66133 int combined_flags;
66134
66135 f1 = pMem1->flags;
66136 f2 = pMem2->flags;
@@ -66154,18 +66360,18 @@
66154 if( pMem1->u.i < pMem2->u.i ) return -1;
66155 if( pMem1->u.i > pMem2->u.i ) return 1;
66156 return 0;
66157 }
66158 if( (f1&MEM_Real)!=0 ){
66159 r1 = pMem1->r;
66160 }else if( (f1&MEM_Int)!=0 ){
66161 r1 = (double)pMem1->u.i;
66162 }else{
66163 return 1;
66164 }
66165 if( (f2&MEM_Real)!=0 ){
66166 r2 = pMem2->r;
66167 }else if( (f2&MEM_Int)!=0 ){
66168 r2 = (double)pMem2->u.i;
66169 }else{
66170 return -1;
66171 }
@@ -66201,15 +66407,11 @@
66201 /* If a NULL pointer was passed as the collate function, fall through
66202 ** to the blob case and use memcmp(). */
66203 }
66204
66205 /* Both values must be blobs. Compare using memcmp(). */
66206 rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n);
66207 if( rc==0 ){
66208 rc = pMem1->n - pMem2->n;
66209 }
66210 return rc;
66211 }
66212
66213
66214 /*
66215 ** The first argument passed to this function is a serial-type that
@@ -66255,11 +66457,11 @@
66255 /*
66256 ** This function compares the two table rows or index records
66257 ** specified by {nKey1, pKey1} and pPKey2. It returns a negative, zero
66258 ** or positive integer if key1 is less than, equal to or
66259 ** greater than key2. The {nKey1, pKey1} key must be a blob
66260 ** created by th OP_MakeRecord opcode of the VDBE. The pPKey2
66261 ** key must be a parsed key such as obtained from
66262 ** sqlite3VdbeParseRecord.
66263 **
66264 ** If argument bSkip is non-zero, it is assumed that the caller has already
66265 ** determined that the first fields of the keys are equal.
@@ -66271,11 +66473,11 @@
66271 ** If database corruption is discovered, set pPKey2->errCode to
66272 ** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
66273 ** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
66274 ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
66275 */
66276 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
66277 int nKey1, const void *pKey1, /* Left key */
66278 UnpackedRecord *pPKey2, /* Right key */
66279 int bSkip /* If true, skip the first field */
66280 ){
66281 u32 d1; /* Offset into aKey[] of next data element */
@@ -66306,11 +66508,11 @@
66306 return 0; /* Corruption */
66307 }
66308 i = 0;
66309 }
66310
66311 VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */
66312 assert( pPKey2->pKeyInfo->nField+pPKey2->pKeyInfo->nXField>=pPKey2->nField
66313 || CORRUPT_DB );
66314 assert( pPKey2->pKeyInfo->aSortOrder!=0 );
66315 assert( pPKey2->pKeyInfo->nField>0 );
66316 assert( idx1<=szHdr1 || CORRUPT_DB );
@@ -66326,13 +66528,13 @@
66326 }else if( serial_type==0 ){
66327 rc = -1;
66328 }else if( serial_type==7 ){
66329 double rhs = (double)pRhs->u.i;
66330 sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
66331 if( mem1.r<rhs ){
66332 rc = -1;
66333 }else if( mem1.r>rhs ){
66334 rc = +1;
66335 }
66336 }else{
66337 i64 lhs = vdbeRecordDecodeInt(serial_type, &aKey1[d1]);
66338 i64 rhs = pRhs->u.i;
@@ -66350,15 +66552,15 @@
66350 if( serial_type>=12 ){
66351 rc = +1;
66352 }else if( serial_type==0 ){
66353 rc = -1;
66354 }else{
66355 double rhs = pRhs->r;
66356 double lhs;
66357 sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
66358 if( serial_type==7 ){
66359 lhs = mem1.r;
66360 }else{
66361 lhs = (double)mem1.u.i;
66362 }
66363 if( lhs<rhs ){
66364 rc = -1;
@@ -66429,11 +66631,11 @@
66429 if( rc!=0 ){
66430 if( pKeyInfo->aSortOrder[i] ){
66431 rc = -rc;
66432 }
66433 assert( vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, rc) );
66434 assert( mem1.zMalloc==0 ); /* See comment below */
66435 return rc;
66436 }
66437
66438 i++;
66439 pRhs++;
@@ -66442,21 +66644,28 @@
66442 }while( idx1<(unsigned)szHdr1 && i<pPKey2->nField && d1<=(unsigned)nKey1 );
66443
66444 /* No memory allocation is ever used on mem1. Prove this using
66445 ** the following assert(). If the assert() fails, it indicates a
66446 ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1). */
66447 assert( mem1.zMalloc==0 );
66448
66449 /* rc==0 here means that one or both of the keys ran out of fields and
66450 ** all the fields up to that point were equal. Return the the default_rc
66451 ** value. */
66452 assert( CORRUPT_DB
66453 || vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, pPKey2->default_rc)
66454 || pKeyInfo->db->mallocFailed
66455 );
66456 return pPKey2->default_rc;
66457 }
 
 
 
 
 
 
 
66458
66459 /*
66460 ** This function is an optimized version of sqlite3VdbeRecordCompare()
66461 ** that (a) the first field of pPKey2 is an integer, and (b) the
66462 ** size-of-header varint at the start of (pKey1/nKey1) fits in a single
@@ -66465,23 +66674,20 @@
66465 ** To avoid concerns about buffer overreads, this routine is only used
66466 ** on schemas where the maximum valid header size is 63 bytes or less.
66467 */
66468 static int vdbeRecordCompareInt(
66469 int nKey1, const void *pKey1, /* Left key */
66470 UnpackedRecord *pPKey2, /* Right key */
66471 int bSkip /* Ignored */
66472 ){
66473 const u8 *aKey = &((const u8*)pKey1)[*(const u8*)pKey1 & 0x3F];
66474 int serial_type = ((const u8*)pKey1)[1];
66475 int res;
66476 u32 y;
66477 u64 x;
66478 i64 v = pPKey2->aMem[0].u.i;
66479 i64 lhs;
66480 UNUSED_PARAMETER(bSkip);
66481
66482 assert( bSkip==0 );
66483 assert( (*(u8*)pKey1)<=0x3F || CORRUPT_DB );
66484 switch( serial_type ){
66485 case 1: { /* 1-byte signed integer */
66486 lhs = ONE_BYTE_INT(aKey);
66487 testcase( lhs<0 );
@@ -66527,24 +66733,24 @@
66527 ** statement (since the range of switch targets now starts at zero and
66528 ** is contiguous) but does not cause any duplicate code to be generated
66529 ** (as gcc is clever enough to combine the two like cases). Other
66530 ** compilers might be similar. */
66531 case 0: case 7:
66532 return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 0);
66533
66534 default:
66535 return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 0);
66536 }
66537
66538 if( v>lhs ){
66539 res = pPKey2->r1;
66540 }else if( v<lhs ){
66541 res = pPKey2->r2;
66542 }else if( pPKey2->nField>1 ){
66543 /* The first fields of the two keys are equal. Compare the trailing
66544 ** fields. */
66545 res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1);
66546 }else{
66547 /* The first fields of the two keys are equal and there are no trailing
66548 ** fields. Return pPKey2->default_rc in this case. */
66549 res = pPKey2->default_rc;
66550 }
@@ -66559,21 +66765,17 @@
66559 ** uses the collation sequence BINARY and (c) that the size-of-header varint
66560 ** at the start of (pKey1/nKey1) fits in a single byte.
66561 */
66562 static int vdbeRecordCompareString(
66563 int nKey1, const void *pKey1, /* Left key */
66564 UnpackedRecord *pPKey2, /* Right key */
66565 int bSkip
66566 ){
66567 const u8 *aKey1 = (const u8*)pKey1;
66568 int serial_type;
66569 int res;
66570 UNUSED_PARAMETER(bSkip);
66571
66572 assert( bSkip==0 );
66573 getVarint32(&aKey1[1], serial_type);
66574
66575 if( serial_type<12 ){
66576 res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */
66577 }else if( !(serial_type & 0x01) ){
66578 res = pPKey2->r2; /* (pKey1/nKey1) is a blob */
66579 }else{
@@ -66591,11 +66793,11 @@
66591
66592 if( res==0 ){
66593 res = nStr - pPKey2->aMem[0].n;
66594 if( res==0 ){
66595 if( pPKey2->nField>1 ){
66596 res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1);
66597 }else{
66598 res = pPKey2->default_rc;
66599 }
66600 }else if( res>0 ){
66601 res = pPKey2->r2;
@@ -66673,12 +66875,10 @@
66673 u32 szHdr; /* Size of the header */
66674 u32 typeRowid; /* Serial type of the rowid */
66675 u32 lenRowid; /* Size of the rowid */
66676 Mem m, v;
66677
66678 UNUSED_PARAMETER(db);
66679
66680 /* Get the size of the index entry. Only indices entries of less
66681 ** than 2GiB are support - anything large must be database corruption.
66682 ** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
66683 ** this code can safely assume that nCellKey is 32-bits
66684 */
@@ -66686,11 +66886,11 @@
66686 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
66687 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
66688 assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
66689
66690 /* Read in the complete content of the index entry */
66691 memset(&m, 0, sizeof(m));
66692 rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
66693 if( rc ){
66694 return rc;
66695 }
66696
@@ -66729,11 +66929,11 @@
66729 return SQLITE_OK;
66730
66731 /* Jump here if database corruption is detected after m has been
66732 ** allocated. Free the m object and return SQLITE_CORRUPT. */
66733 idx_rowid_corruption:
66734 testcase( m.zMalloc!=0 );
66735 sqlite3VdbeMemRelease(&m);
66736 return SQLITE_CORRUPT_BKPT;
66737 }
66738
66739 /*
@@ -66746,10 +66946,11 @@
66746 ** omits the rowid at the end. The rowid at the end of the index entry
66747 ** is ignored as well. Hence, this routine only compares the prefixes
66748 ** of the keys prior to the final rowid, not the entire key.
66749 */
66750 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(
 
66751 VdbeCursor *pC, /* The cursor to compare against */
66752 UnpackedRecord *pUnpacked, /* Unpacked version of key */
66753 int *res /* Write the comparison result here */
66754 ){
66755 i64 nCellKey = 0;
@@ -66764,16 +66965,16 @@
66764 ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
66765 if( nCellKey<=0 || nCellKey>0x7fffffff ){
66766 *res = 0;
66767 return SQLITE_CORRUPT_BKPT;
66768 }
66769 memset(&m, 0, sizeof(m));
66770 rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m);
66771 if( rc ){
66772 return rc;
66773 }
66774 *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked, 0);
66775 sqlite3VdbeMemRelease(&m);
66776 return SQLITE_OK;
66777 }
66778
66779 /*
@@ -67083,13 +67284,16 @@
67083
67084 /**************************** sqlite3_result_ *******************************
67085 ** The following routines are used by user-defined functions to specify
67086 ** the function result.
67087 **
67088 ** The setStrOrError() funtion calls sqlite3VdbeMemSetStr() to store the
67089 ** result as a string or blob but if the string or blob is too large, it
67090 ** then sets the error code to SQLITE_TOOBIG
 
 
 
67091 */
67092 static void setResultStrOrError(
67093 sqlite3_context *pCtx, /* Function context */
67094 const char *z, /* String pointer */
67095 int n, /* Bytes in string, or negative */
@@ -67097,10 +67301,26 @@
67097 void (*xDel)(void*) /* Destructor function */
67098 ){
67099 if( sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel)==SQLITE_TOOBIG ){
67100 sqlite3_result_error_toobig(pCtx);
67101 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67102 }
67103 SQLITE_API void sqlite3_result_blob(
67104 sqlite3_context *pCtx,
67105 const void *z,
67106 int n,
@@ -67107,10 +67327,24 @@
67107 void (*xDel)(void *)
67108 ){
67109 assert( n>=0 );
67110 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
67111 setResultStrOrError(pCtx, z, n, 0, xDel);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67112 }
67113 SQLITE_API void sqlite3_result_double(sqlite3_context *pCtx, double rVal){
67114 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
67115 sqlite3VdbeMemSetDouble(pCtx->pOut, rVal);
67116 }
@@ -67146,10 +67380,25 @@
67146 int n,
67147 void (*xDel)(void *)
67148 ){
67149 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
67150 setResultStrOrError(pCtx, z, n, SQLITE_UTF8, xDel);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67151 }
67152 #ifndef SQLITE_OMIT_UTF16
67153 SQLITE_API void sqlite3_result_text16(
67154 sqlite3_context *pCtx,
67155 const void *z,
@@ -67485,15 +67734,14 @@
67485 */
67486 static SQLITE_NOINLINE void *createAggContext(sqlite3_context *p, int nByte){
67487 Mem *pMem = p->pMem;
67488 assert( (pMem->flags & MEM_Agg)==0 );
67489 if( nByte<=0 ){
67490 sqlite3VdbeMemReleaseExternal(pMem);
67491 pMem->flags = MEM_Null;
67492 pMem->z = 0;
67493 }else{
67494 sqlite3VdbeMemGrow(pMem, nByte, 0);
67495 pMem->flags = MEM_Agg;
67496 pMem->u.pDef = p->pFunc;
67497 if( pMem->z ){
67498 memset(pMem->z, 0, nByte);
67499 }
@@ -67516,11 +67764,11 @@
67516 return (void*)p->pMem->z;
67517 }
67518 }
67519
67520 /*
67521 ** Return the auxilary data pointer, if any, for the iArg'th argument to
67522 ** the user-function defined by pCtx.
67523 */
67524 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
67525 AuxData *pAuxData;
67526
@@ -67531,11 +67779,11 @@
67531
67532 return (pAuxData ? pAuxData->pAux : 0);
67533 }
67534
67535 /*
67536 ** Set the auxilary data pointer and delete function, for the iArg'th
67537 ** argument to the user-function defined by pCtx. Any previous value is
67538 ** deleted by calling the delete function specified when it was set.
67539 */
67540 SQLITE_API void sqlite3_set_auxdata(
67541 sqlite3_context *pCtx,
@@ -67577,11 +67825,11 @@
67577 }
67578 }
67579
67580 #ifndef SQLITE_OMIT_DEPRECATED
67581 /*
67582 ** Return the number of times the Step function of a aggregate has been
67583 ** called.
67584 **
67585 ** This function is deprecated. Do not use it for new code. It is
67586 ** provide only to avoid breaking legacy code. New aggregate function
67587 ** implementations should keep their own counts within their aggregate
@@ -67626,15 +67874,26 @@
67626 ** __attribute__((aligned(8))) macro. */
67627 static const Mem nullMem
67628 #if defined(SQLITE_DEBUG) && defined(__GNUC__)
67629 __attribute__((aligned(8)))
67630 #endif
67631 = {0, "", (double)0, {0}, 0, MEM_Null, 0,
 
 
 
 
 
 
 
 
 
 
67632 #ifdef SQLITE_DEBUG
67633 0, 0, /* pScopyFrom, pFiller */
 
67634 #endif
67635 0, 0 };
67636 return &nullMem;
67637 }
67638
67639 /*
67640 ** Check to see if column iCol of the given statement is valid. If
@@ -67847,11 +68106,11 @@
67847
67848 #ifdef SQLITE_ENABLE_COLUMN_METADATA
67849 /*
67850 ** Return the name of the database from which a result column derives.
67851 ** NULL is returned if the result column is an expression or constant or
67852 ** anything else which is not an unabiguous reference to a database column.
67853 */
67854 SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
67855 return columnName(
67856 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
67857 }
@@ -67863,11 +68122,11 @@
67863 #endif /* SQLITE_OMIT_UTF16 */
67864
67865 /*
67866 ** Return the name of the table from which a result column derives.
67867 ** NULL is returned if the result column is an expression or constant or
67868 ** anything else which is not an unabiguous reference to a database column.
67869 */
67870 SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
67871 return columnName(
67872 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
67873 }
@@ -67879,11 +68138,11 @@
67879 #endif /* SQLITE_OMIT_UTF16 */
67880
67881 /*
67882 ** Return the name of the table column from which a result column derives.
67883 ** NULL is returned if the result column is an expression or constant or
67884 ** anything else which is not an unabiguous reference to a database column.
67885 */
67886 SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
67887 return columnName(
67888 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
67889 }
@@ -67995,10 +68254,24 @@
67995 const void *zData,
67996 int nData,
67997 void (*xDel)(void*)
67998 ){
67999 return bindText(pStmt, i, zData, nData, xDel, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68000 }
68001 SQLITE_API int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
68002 int rc;
68003 Vdbe *p = (Vdbe *)pStmt;
68004 rc = vdbeUnbind(p, i);
@@ -68036,10 +68309,26 @@
68036 const char *zData,
68037 int nData,
68038 void (*xDel)(void*)
68039 ){
68040 return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68041 }
68042 #ifndef SQLITE_OMIT_UTF16
68043 SQLITE_API int sqlite3_bind_text16(
68044 sqlite3_stmt *pStmt,
68045 int i,
@@ -68056,11 +68345,11 @@
68056 case SQLITE_INTEGER: {
68057 rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
68058 break;
68059 }
68060 case SQLITE_FLOAT: {
68061 rc = sqlite3_bind_double(pStmt, i, pValue->r);
68062 break;
68063 }
68064 case SQLITE_BLOB: {
68065 if( pValue->flags & MEM_Zero ){
68066 rc = sqlite3_bind_zeroblob(pStmt, i, pValue->u.nZero);
@@ -68159,11 +68448,11 @@
68159 #ifndef SQLITE_OMIT_DEPRECATED
68160 /*
68161 ** Deprecated external interface. Internal/core SQLite code
68162 ** should call sqlite3TransferBindings.
68163 **
68164 ** Is is misuse to call this routine with statements from different
68165 ** database connections. But as this is a deprecated interface, we
68166 ** will not bother to check for that condition.
68167 **
68168 ** If the two statements contain a different number of bindings, then
68169 ** an SQLITE_ERROR is returned. Nothing else can go wrong, so otherwise
@@ -68303,11 +68592,11 @@
68303 ** is eventually freed.
68304 **
68305 ** ALGORITHM: Scan the input string looking for host parameters in any of
68306 ** these forms: ?, ?N, $A, @A, :A. Take care to avoid text within
68307 ** string literals, quoted identifier names, and comments. For text forms,
68308 ** the host parameter index is found by scanning the perpared
68309 ** statement for the corresponding OP_Variable opcode. Once the host
68310 ** parameter index is known, locate the value in p->aVar[]. Then render
68311 ** the value as a literal in place of the host parameter name.
68312 */
68313 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(
@@ -68366,11 +68655,11 @@
68366 if( pVar->flags & MEM_Null ){
68367 sqlite3StrAccumAppend(&out, "NULL", 4);
68368 }else if( pVar->flags & MEM_Int ){
68369 sqlite3XPrintf(&out, 0, "%lld", pVar->u.i);
68370 }else if( pVar->flags & MEM_Real ){
68371 sqlite3XPrintf(&out, 0, "%!.15g", pVar->r);
68372 }else if( pVar->flags & MEM_Str ){
68373 int nOut; /* Number of bytes of the string text to include in output */
68374 #ifndef SQLITE_OMIT_UTF16
68375 u8 enc = ENC(db);
68376 Mem utf8;
@@ -68749,11 +69038,11 @@
68749 assert( iCur<p->nCursor );
68750 if( p->apCsr[iCur] ){
68751 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
68752 p->apCsr[iCur] = 0;
68753 }
68754 if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){
68755 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
68756 memset(pCx, 0, sizeof(VdbeCursor));
68757 pCx->iDb = iDb;
68758 pCx->nField = nField;
68759 if( isBtreeCursor ){
@@ -68782,17 +69071,17 @@
68782 */
68783 static void applyNumericAffinity(Mem *pRec, int bTryForInt){
68784 double rValue;
68785 i64 iValue;
68786 u8 enc = pRec->enc;
68787 if( (pRec->flags&MEM_Str)==0 ) return;
68788 if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return;
68789 if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
68790 pRec->u.i = iValue;
68791 pRec->flags |= MEM_Int;
68792 }else{
68793 pRec->r = rValue;
68794 pRec->flags |= MEM_Real;
68795 if( bTryForInt ) sqlite3VdbeIntegerAffinity(pRec);
68796 }
68797 }
68798
@@ -68817,28 +69106,28 @@
68817 static void applyAffinity(
68818 Mem *pRec, /* The value to apply affinity to */
68819 char affinity, /* The affinity to be applied */
68820 u8 enc /* Use this text encoding */
68821 ){
68822 if( affinity==SQLITE_AFF_TEXT ){
 
 
 
 
 
 
 
 
 
 
68823 /* Only attempt the conversion to TEXT if there is an integer or real
68824 ** representation (blob and NULL do not get converted) but no string
68825 ** representation.
68826 */
68827 if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
68828 sqlite3VdbeMemStringify(pRec, enc, 1);
68829 }
68830 }else if( affinity!=SQLITE_AFF_NONE ){
68831 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
68832 || affinity==SQLITE_AFF_NUMERIC );
68833 if( (pRec->flags & MEM_Int)==0 ){
68834 if( (pRec->flags & MEM_Real)==0 ){
68835 applyNumericAffinity(pRec,1);
68836 }else{
68837 sqlite3VdbeIntegerAffinity(pRec);
68838 }
68839 }
68840 }
68841 }
68842
68843 /*
68844 ** Try to convert the type of a function argument or a result column
@@ -68869,17 +69158,17 @@
68869 }
68870
68871 /*
68872 ** pMem currently only holds a string type (or maybe a BLOB that we can
68873 ** interpret as a string if we want to). Compute its corresponding
68874 ** numeric type, if has one. Set the pMem->r and pMem->u.i fields
68875 ** accordingly.
68876 */
68877 static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){
68878 assert( (pMem->flags & (MEM_Int|MEM_Real))==0 );
68879 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
68880 if( sqlite3AtoF(pMem->z, &pMem->r, pMem->n, pMem->enc)==0 ){
68881 return 0;
68882 }
68883 if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==SQLITE_OK ){
68884 return MEM_Int;
68885 }
@@ -68889,11 +69178,11 @@
68889 /*
68890 ** Return the numeric type for pMem, either MEM_Int or MEM_Real or both or
68891 ** none.
68892 **
68893 ** Unlike applyNumericAffinity(), this routine does not modify pMem->flags.
68894 ** But it does set pMem->r and pMem->u.i appropriately.
68895 */
68896 static u16 numericType(Mem *pMem){
68897 if( pMem->flags & (MEM_Int|MEM_Real) ){
68898 return pMem->flags & (MEM_Int|MEM_Real);
68899 }
@@ -68999,11 +69288,11 @@
68999 printf(" si:%lld", p->u.i);
69000 }else if( p->flags & MEM_Int ){
69001 printf(" i:%lld", p->u.i);
69002 #ifndef SQLITE_OMIT_FLOATING_POINT
69003 }else if( p->flags & MEM_Real ){
69004 printf(" r:%g", p->r);
69005 #endif
69006 }else if( p->flags & MEM_RowSet ){
69007 printf(" (rowset)");
69008 }else{
69009 char zBuf[200];
@@ -69269,11 +69558,11 @@
69269 if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){
69270 assert( pOp->p2>0 );
69271 assert( pOp->p2<=(p->nMem-p->nCursor) );
69272 pOut = &aMem[pOp->p2];
69273 memAboutToChange(p, pOut);
69274 VdbeMemReleaseExtern(pOut);
69275 pOut->flags = MEM_Int;
69276 }
69277
69278 /* Sanity checking on other operands */
69279 #ifdef SQLITE_DEBUG
@@ -69631,11 +69920,11 @@
69631 ** Write that value into register P2.
69632 */
69633 case OP_Real: { /* same as TK_FLOAT, out2-prerelease */
69634 pOut->flags = MEM_Real;
69635 assert( !sqlite3IsNaN(*pOp->p4.pReal) );
69636 pOut->r = *pOp->p4.pReal;
69637 break;
69638 }
69639 #endif
69640
69641 /* Opcode: String8 * P2 * P4 *
@@ -69654,13 +69943,13 @@
69654 #ifndef SQLITE_OMIT_UTF16
69655 if( encoding!=SQLITE_UTF8 ){
69656 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
69657 if( rc==SQLITE_TOOBIG ) goto too_big;
69658 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
69659 assert( pOut->zMalloc==pOut->z );
69660 assert( VdbeMemDynamic(pOut)==0 );
69661 pOut->zMalloc = 0;
69662 pOut->flags |= MEM_Static;
69663 if( pOp->p4type==P4_DYNAMIC ){
69664 sqlite3DbFree(db, pOp->p4.z);
69665 }
69666 pOp->p4type = P4_DYNAMIC;
@@ -69708,11 +69997,11 @@
69708 assert( pOp->p3<=(p->nMem-p->nCursor) );
69709 pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
69710 while( cnt>0 ){
69711 pOut++;
69712 memAboutToChange(p, pOut);
69713 VdbeMemReleaseExtern(pOut);
69714 pOut->flags = nullFlag;
69715 cnt--;
69716 }
69717 break;
69718 }
@@ -69776,11 +70065,10 @@
69776 ** left holding a NULL. It is an error for register ranges
69777 ** P1..P1+P3-1 and P2..P2+P3-1 to overlap. It is an error
69778 ** for P3 to be less than 1.
69779 */
69780 case OP_Move: {
69781 char *zMalloc; /* Holding variable for allocated memory */
69782 int n; /* Number of registers left to copy */
69783 int p1; /* Register to copy from */
69784 int p2; /* Register to copy to */
69785
69786 n = pOp->p3;
@@ -69794,21 +70082,16 @@
69794 do{
69795 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
69796 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
69797 assert( memIsValid(pIn1) );
69798 memAboutToChange(p, pOut);
69799 sqlite3VdbeMemRelease(pOut);
69800 zMalloc = pOut->zMalloc;
69801 memcpy(pOut, pIn1, sizeof(Mem));
69802 #ifdef SQLITE_DEBUG
69803 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
69804 pOut->pScopyFrom += p1 - pOp->p2;
69805 }
69806 #endif
69807 pIn1->flags = MEM_Undefined;
69808 pIn1->xDel = 0;
69809 pIn1->zMalloc = zMalloc;
69810 REGISTER_TRACE(p2++, pOut);
69811 pIn1++;
69812 pOut++;
69813 }while( --n );
69814 break;
@@ -70109,11 +70392,11 @@
70109 MemSetTypeFlag(pOut, MEM_Int);
70110 #else
70111 if( sqlite3IsNaN(rB) ){
70112 goto arithmetic_result_is_null;
70113 }
70114 pOut->r = rB;
70115 MemSetTypeFlag(pOut, MEM_Real);
70116 if( ((type1|type2)&MEM_Real)==0 && !bIntint ){
70117 sqlite3VdbeIntegerAffinity(pOut);
70118 }
70119 #endif
@@ -70384,11 +70667,11 @@
70384 ** </ul>
70385 **
70386 ** A NULL value is not changed by this routine. It remains NULL.
70387 */
70388 case OP_Cast: { /* in1 */
70389 assert( pOp->p2>=SQLITE_AFF_TEXT && pOp->p2<=SQLITE_AFF_REAL );
70390 testcase( pOp->p2==SQLITE_AFF_TEXT );
70391 testcase( pOp->p2==SQLITE_AFF_NONE );
70392 testcase( pOp->p2==SQLITE_AFF_NUMERIC );
70393 testcase( pOp->p2==SQLITE_AFF_INTEGER );
70394 testcase( pOp->p2==SQLITE_AFF_REAL );
@@ -70534,19 +70817,39 @@
70534 break;
70535 }
70536 }else{
70537 /* Neither operand is NULL. Do a comparison. */
70538 affinity = pOp->p5 & SQLITE_AFF_MASK;
70539 if( affinity ){
70540 applyAffinity(pIn1, affinity, encoding);
70541 applyAffinity(pIn3, affinity, encoding);
70542 if( db->mallocFailed ) goto no_mem;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70543 }
70544
70545 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
70546 ExpandBlob(pIn1);
70547 ExpandBlob(pIn3);
 
 
 
 
 
 
 
70548 res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
70549 }
70550 switch( pOp->opcode ){
70551 case OP_Eq: res = res==0; break;
70552 case OP_Ne: res = res!=0; break;
@@ -70567,12 +70870,12 @@
70567 if( res ){
70568 pc = pOp->p2-1;
70569 }
70570 }
70571 /* Undo any changes made by applyAffinity() to the input registers. */
70572 pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask);
70573 pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask);
70574 break;
70575 }
70576
70577 /* Opcode: Permutation * * * P4 *
70578 **
@@ -70736,14 +71039,14 @@
70736 ** NULL, then a NULL is stored in P2.
70737 */
70738 case OP_Not: { /* same as TK_NOT, in1, out2 */
70739 pIn1 = &aMem[pOp->p1];
70740 pOut = &aMem[pOp->p2];
70741 if( pIn1->flags & MEM_Null ){
70742 sqlite3VdbeMemSetNull(pOut);
70743 }else{
70744 sqlite3VdbeMemSetInt64(pOut, !sqlite3VdbeIntValue(pIn1));
70745 }
70746 break;
70747 }
70748
70749 /* Opcode: BitNot P1 P2 * * *
@@ -70754,14 +71057,14 @@
70754 ** a NULL then store a NULL in P2.
70755 */
70756 case OP_BitNot: { /* same as TK_BITNOT, in1, out2 */
70757 pIn1 = &aMem[pOp->p1];
70758 pOut = &aMem[pOp->p2];
70759 if( pIn1->flags & MEM_Null ){
70760 sqlite3VdbeMemSetNull(pOut);
70761 }else{
70762 sqlite3VdbeMemSetInt64(pOut, ~sqlite3VdbeIntValue(pIn1));
70763 }
70764 break;
70765 }
70766
70767 /* Opcode: Once P1 P2 * * *
@@ -70875,11 +71178,10 @@
70875 case OP_Column: {
70876 i64 payloadSize64; /* Number of bytes in the record */
70877 int p2; /* column number to retrieve */
70878 VdbeCursor *pC; /* The VDBE cursor */
70879 BtCursor *pCrsr; /* The BTree cursor */
70880 u32 *aType; /* aType[i] holds the numeric type of the i-th column */
70881 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
70882 int len; /* The length of the serialized data for the column */
70883 int i; /* Loop counter */
70884 Mem *pDest; /* Where to write the extracted value */
70885 Mem sMem; /* For storing the record being decoded */
@@ -70888,10 +71190,11 @@
70888 const u8 *zEndHdr; /* Pointer to first byte after the header */
70889 u32 offset; /* Offset into the data */
70890 u32 szField; /* Number of bytes in the content of a field */
70891 u32 avail; /* Number of bytes of available data */
70892 u32 t; /* A type code from the record header */
 
70893 Mem *pReg; /* PseudoTable input register */
70894
70895 p2 = pOp->p2;
70896 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
70897 pDest = &aMem[pOp->p3];
@@ -70898,12 +71201,11 @@
70898 memAboutToChange(p, pDest);
70899 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70900 pC = p->apCsr[pOp->p1];
70901 assert( pC!=0 );
70902 assert( p2<pC->nField );
70903 aType = pC->aType;
70904 aOffset = aType + pC->nField;
70905 #ifndef SQLITE_OMIT_VIRTUALTABLE
70906 assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
70907 #endif
70908 pCrsr = pC->pCursor;
70909 assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
@@ -70980,11 +71282,11 @@
70980 goto op_column_error;
70981 }
70982 }
70983
70984 /* Make sure at least the first p2+1 entries of the header have been
70985 ** parsed and valid information is in aOffset[] and aType[].
70986 */
70987 if( pC->nHdrParsed<=p2 ){
70988 /* If there is more header available for parsing in the record, try
70989 ** to extract additional fields up through the p2+1-th field
70990 */
@@ -71000,11 +71302,11 @@
71000 zData = (u8*)sMem.z;
71001 }else{
71002 zData = pC->aRow;
71003 }
71004
71005 /* Fill in aType[i] and aOffset[i] values through the p2-th field. */
71006 i = pC->nHdrParsed;
71007 offset = aOffset[i];
71008 zHdr = zData + pC->iHdrOffset;
71009 zEndHdr = zData + aOffset[0];
71010 assert( i<=p2 && zHdr<zEndHdr );
@@ -71013,11 +71315,11 @@
71013 t = zHdr[0];
71014 zHdr++;
71015 }else{
71016 zHdr += sqlite3GetVarint32(zHdr, &t);
71017 }
71018 aType[i] = t;
71019 szField = sqlite3VdbeSerialTypeLen(t);
71020 offset += szField;
71021 if( offset<szField ){ /* True if offset overflows */
71022 zHdr = &zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
71023 break;
@@ -71060,65 +71362,65 @@
71060 goto op_column_out;
71061 }
71062 }
71063
71064 /* Extract the content for the p2+1-th column. Control can only
71065 ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
71066 ** all valid.
71067 */
71068 assert( p2<pC->nHdrParsed );
71069 assert( rc==SQLITE_OK );
71070 assert( sqlite3VdbeCheckMemInvariants(pDest) );
 
 
71071 if( pC->szRow>=aOffset[p2+1] ){
71072 /* This is the common case where the desired content fits on the original
71073 ** page - where the content is not on an overflow page */
71074 VdbeMemReleaseExtern(pDest);
71075 sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
71076 }else{
71077 /* This branch happens only when content is on overflow pages */
71078 t = aType[p2];
71079 if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
71080 && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
71081 || (len = sqlite3VdbeSerialTypeLen(t))==0
71082 ){
71083 /* Content is irrelevant for the typeof() function and for
71084 ** the length(X) function if X is a blob. So we might as well use
71085 ** bogus content rather than reading content from disk. NULL works
71086 ** for text and blob and whatever is in the payloadSize64 variable
71087 ** will work for everything else. Content is also irrelevant if
71088 ** the content length is 0. */
71089 zData = t<=13 ? (u8*)&payloadSize64 : 0;
71090 sMem.zMalloc = 0;
 
71091 }else{
71092 memset(&sMem, 0, sizeof(sMem));
71093 sqlite3VdbeMemMove(&sMem, pDest);
71094 rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable,
71095 &sMem);
71096 if( rc!=SQLITE_OK ){
71097 goto op_column_error;
71098 }
71099 zData = (u8*)sMem.z;
71100 }
71101 sqlite3VdbeSerialGet(zData, t, pDest);
71102 /* If we dynamically allocated space to hold the data (in the
71103 ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
71104 ** dynamically allocated space over to the pDest structure.
71105 ** This prevents a memory copy. */
71106 if( sMem.zMalloc ){
71107 assert( sMem.z==sMem.zMalloc );
71108 assert( VdbeMemDynamic(pDest)==0 );
71109 assert( (pDest->flags & (MEM_Blob|MEM_Str))==0 || pDest->z==sMem.z );
71110 pDest->flags &= ~(MEM_Ephem|MEM_Static);
71111 pDest->flags |= MEM_Term;
71112 pDest->z = sMem.z;
71113 pDest->zMalloc = sMem.zMalloc;
71114 }
71115 }
71116 pDest->enc = encoding;
71117
71118 op_column_out:
71119 Deephemeralize(pDest);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71120 op_column_error:
71121 UPDATE_MAX_BLOBSIZE(pDest);
71122 REGISTER_TRACE(pOp->p3, pDest);
71123 break;
71124 }
@@ -71189,11 +71491,11 @@
71189 ** ------------------------------------------------------------------------
71190 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
71191 ** ------------------------------------------------------------------------
71192 **
71193 ** Data(0) is taken from register P1. Data(1) comes from register P1+1
71194 ** and so froth.
71195 **
71196 ** Each type field is a varint representing the serial type of the
71197 ** corresponding data element (see sqlite3VdbeSerialType()). The
71198 ** hdr-size field is also a varint which is the offset from the beginning
71199 ** of the record to data0.
@@ -71265,13 +71567,13 @@
71265 }
71266
71267 /* Make sure the output register has a buffer large enough to store
71268 ** the new record. The output register (pOp->p3) is not allowed to
71269 ** be one of the input registers (because the following call to
71270 ** sqlite3VdbeMemGrow() could clobber the value before it is used).
71271 */
71272 if( sqlite3VdbeMemGrow(pOut, (int)nByte, 0) ){
71273 goto no_mem;
71274 }
71275 zNewRecord = (u8 *)pOut->z;
71276
71277 /* Write the record */
@@ -71288,11 +71590,10 @@
71288 assert( j==nByte );
71289
71290 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
71291 pOut->n = (int)nByte;
71292 pOut->flags = MEM_Blob;
71293 pOut->xDel = 0;
71294 if( nZero ){
71295 pOut->u.nZero = nZero;
71296 pOut->flags |= MEM_Zero;
71297 }
71298 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
@@ -72176,13 +72477,13 @@
72176 pC->seekOp = pOp->opcode;
72177 #endif
72178 if( pC->isTable ){
72179 /* The input value in P3 might be of any type: integer, real, string,
72180 ** blob, or NULL. But it needs to be an integer before we can do
72181 ** the seek, so covert it. */
72182 pIn3 = &aMem[pOp->p3];
72183 if( (pIn3->flags & (MEM_Int|MEM_Real))==0 ){
72184 applyNumericAffinity(pIn3, 0);
72185 }
72186 iKey = sqlite3VdbeIntValue(pIn3);
72187 pC->rowidIsValid = 0;
72188
@@ -72201,20 +72502,20 @@
72201 ** is 4.9 and the integer approximation 5:
72202 **
72203 ** (x > 4.9) -> (x >= 5)
72204 ** (x <= 4.9) -> (x < 5)
72205 */
72206 if( pIn3->r<(double)iKey ){
72207 assert( OP_SeekGE==(OP_SeekGT-1) );
72208 assert( OP_SeekLT==(OP_SeekLE-1) );
72209 assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) );
72210 if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--;
72211 }
72212
72213 /* If the approximation iKey is smaller than the actual real search
72214 ** term, substitute <= for < and > for >=. */
72215 else if( pIn3->r>(double)iKey ){
72216 assert( OP_SeekLE==(OP_SeekLT+1) );
72217 assert( OP_SeekGT==(OP_SeekGE+1) );
72218 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
72219 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
72220 }
@@ -72972,11 +73273,11 @@
72972 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
72973 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
72974 goto too_big;
72975 }
72976 }
72977 if( sqlite3VdbeMemGrow(pOut, n, 0) ){
72978 goto no_mem;
72979 }
72980 pOut->n = n;
72981 MemSetTypeFlag(pOut, MEM_Blob);
72982 if( pC->isTable==0 ){
@@ -73482,11 +73783,11 @@
73482 r.aMem = &aMem[pOp->p3];
73483 #ifdef SQLITE_DEBUG
73484 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
73485 #endif
73486 res = 0; /* Not needed. Only used to silence a warning. */
73487 rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
73488 assert( (OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1) );
73489 if( (pOp->opcode&1)==(OP_IdxLT&1) ){
73490 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT );
73491 res = -res;
73492 }else{
@@ -74252,15 +74553,11 @@
74252 }
74253 ctx.pFunc = pOp->p4.pFunc;
74254 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
74255 ctx.pMem = pMem = &aMem[pOp->p3];
74256 pMem->n++;
74257 t.flags = MEM_Null;
74258 t.z = 0;
74259 t.zMalloc = 0;
74260 t.xDel = 0;
74261 t.db = db;
74262 ctx.pOut = &t;
74263 ctx.isError = 0;
74264 ctx.pColl = 0;
74265 ctx.skipFlag = 0;
74266 if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
@@ -76175,12 +76472,15 @@
76175 ** *pp is undefined in this case.
76176 */
76177 static int vdbeSorterMapFile(SortSubtask *pTask, SorterFile *pFile, u8 **pp){
76178 int rc = SQLITE_OK;
76179 if( pFile->iEof<=(i64)(pTask->pSorter->db->nMaxSorterMmap) ){
76180 rc = sqlite3OsFetch(pFile->pFd, 0, (int)pFile->iEof, (void**)pp);
76181 testcase( rc!=SQLITE_OK );
 
 
 
76182 }
76183 return rc;
76184 }
76185
76186 /*
@@ -76331,11 +76631,11 @@
76331 ){
76332 UnpackedRecord *r2 = pTask->pUnpacked;
76333 if( pKey2 ){
76334 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
76335 }
76336 return sqlite3VdbeRecordCompare(nKey1, pKey1, r2, 0);
76337 }
76338
76339 /*
76340 ** Initialize the temporary index cursor just opened as a sorter cursor.
76341 **
@@ -76694,11 +76994,11 @@
76694 **
76695 ** Whether or not the file does end up memory mapped of course depends on
76696 ** the specific VFS implementation.
76697 */
76698 static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){
76699 if( nByte<=(i64)(db->nMaxSorterMmap) ){
76700 int rc = sqlite3OsTruncate(pFd, nByte);
76701 if( rc==SQLITE_OK ){
76702 void *p = 0;
76703 sqlite3OsFetch(pFd, 0, (int)nByte, &p);
76704 sqlite3OsUnfetch(pFd, 0, p);
@@ -77632,11 +77932,11 @@
77632 return pRet;
77633 }
77634
77635 /*
77636 ** Use a background thread to invoke vdbePmaReaderIncrMergeInit(INCRINIT_TASK)
77637 ** on the the PmaReader object passed as the first argument.
77638 **
77639 ** This call will initialize the various fields of the pReadr->pIncr
77640 ** structure and, if it is a multi-threaded IncrMerger, launch a
77641 ** background thread to populate aFile[1].
77642 */
@@ -78031,11 +78331,11 @@
78031 SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *pCsr, Mem *pOut){
78032 VdbeSorter *pSorter = pCsr->pSorter;
78033 void *pKey; int nKey; /* Sorter key to copy into pOut */
78034
78035 pKey = vdbeSorterRowkey(pSorter, &nKey);
78036 if( sqlite3VdbeMemGrow(pOut, nKey, 0) ){
78037 return SQLITE_NOMEM;
78038 }
78039 pOut->n = nKey;
78040 MemSetTypeFlag(pOut, MEM_Blob);
78041 memcpy(pOut->z, pKey, nKey);
@@ -78087,11 +78387,11 @@
78087 *pRes = -1;
78088 return SQLITE_OK;
78089 }
78090 }
78091
78092 *pRes = sqlite3VdbeRecordCompare(pVal->n, pVal->z, r2, 0);
78093 return SQLITE_OK;
78094 }
78095
78096 /************** End of vdbesort.c ********************************************/
78097 /************** Begin file journal.c *****************************************/
@@ -78378,11 +78678,11 @@
78378 /* Space to hold the rollback journal is allocated in increments of
78379 ** this many bytes.
78380 **
78381 ** The size chosen is a little less than a power of two. That way,
78382 ** the FileChunk object will have a size that almost exactly fills
78383 ** a power-of-two allocation. This mimimizes wasted space in power-of-two
78384 ** memory allocators.
78385 */
78386 #define JOURNAL_CHUNKSIZE ((int)(1024-sizeof(FileChunk*)))
78387
78388 /*
@@ -78628,11 +78928,11 @@
78628 /* #include <string.h> */
78629
78630
78631 /*
78632 ** Walk an expression tree. Invoke the callback once for each node
78633 ** of the expression, while decending. (In other words, the callback
78634 ** is invoked before visiting children.)
78635 **
78636 ** The return value from the callback should be one of the WRC_*
78637 ** constants to specify how to proceed with the walk.
78638 **
@@ -79484,13 +79784,11 @@
79484 ** likelihood(X,0.9375). */
79485 /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
79486 pExpr->iTable = pDef->zName[0]=='u' ? 62 : 938;
79487 }
79488 }
79489 }
79490 #ifndef SQLITE_OMIT_AUTHORIZATION
79491 if( pDef ){
79492 auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
79493 if( auth!=SQLITE_OK ){
79494 if( auth==SQLITE_DENY ){
79495 sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
79496 pDef->zName);
@@ -79497,13 +79795,13 @@
79497 pNC->nErr++;
79498 }
79499 pExpr->op = TK_NULL;
79500 return WRC_Prune;
79501 }
 
79502 if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ) ExprSetProperty(pExpr,EP_Constant);
79503 }
79504 #endif
79505 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
79506 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
79507 pNC->nErr++;
79508 is_agg = 0;
79509 }else if( no_such_func && pParse->db->init.busy==0 ){
@@ -79522,11 +79820,17 @@
79522 pExpr->op2 = 0;
79523 while( pNC2 && !sqlite3FunctionUsesThisSrc(pExpr, pNC2->pSrcList) ){
79524 pExpr->op2++;
79525 pNC2 = pNC2->pNext;
79526 }
79527 if( pNC2 ) pNC2->ncFlags |= NC_HasAgg;
 
 
 
 
 
 
79528 pNC->ncFlags |= NC_AllowAgg;
79529 }
79530 /* FIX ME: Compute pExpr->affinity based on the expected return
79531 ** type of the function
79532 */
@@ -79883,11 +80187,11 @@
79883 }
79884 return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType);
79885 }
79886
79887 /*
79888 ** Resolve names in the SELECT statement p and all of its descendents.
79889 */
79890 static int resolveSelectStep(Walker *pWalker, Select *p){
79891 NameContext *pOuterNC; /* Context that contains this SELECT */
79892 NameContext sNC; /* Name context of this SELECT */
79893 int isCompound; /* True if p is a compound select */
@@ -79987,11 +80291,12 @@
79987 ** expression, do not allow aggregates in any of the other expressions.
79988 */
79989 assert( (p->selFlags & SF_Aggregate)==0 );
79990 pGroupBy = p->pGroupBy;
79991 if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){
79992 p->selFlags |= SF_Aggregate;
 
79993 }else{
79994 sNC.ncFlags &= ~NC_AllowAgg;
79995 }
79996
79997 /* If a HAVING clause is present, then there must be a GROUP BY clause.
@@ -80115,11 +80420,11 @@
80115 */
80116 SQLITE_PRIVATE int sqlite3ResolveExprNames(
80117 NameContext *pNC, /* Namespace to resolve expressions in. */
80118 Expr *pExpr /* The expression to be analyzed. */
80119 ){
80120 u8 savedHasAgg;
80121 Walker w;
80122
80123 if( pExpr==0 ) return 0;
80124 #if SQLITE_MAX_EXPR_DEPTH>0
80125 {
@@ -80128,12 +80433,12 @@
80128 return 1;
80129 }
80130 pParse->nHeight += pExpr->nHeight;
80131 }
80132 #endif
80133 savedHasAgg = pNC->ncFlags & NC_HasAgg;
80134 pNC->ncFlags &= ~NC_HasAgg;
80135 memset(&w, 0, sizeof(w));
80136 w.xExprCallback = resolveExprStep;
80137 w.xSelectCallback = resolveSelectStep;
80138 w.pParse = pNC->pParse;
80139 w.u.pNC = pNC;
@@ -80144,13 +80449,12 @@
80144 if( pNC->nErr>0 || w.pParse->nErr>0 ){
80145 ExprSetProperty(pExpr, EP_Error);
80146 }
80147 if( pNC->ncFlags & NC_HasAgg ){
80148 ExprSetProperty(pExpr, EP_Agg);
80149 }else if( savedHasAgg ){
80150 pNC->ncFlags |= NC_HasAgg;
80151 }
 
80152 return ExprHasProperty(pExpr, EP_Error);
80153 }
80154
80155
80156 /*
@@ -80246,11 +80550,11 @@
80246 ** If pExpr is a column, a reference to a column via an 'AS' alias,
80247 ** or a sub-select with a column as the return value, then the
80248 ** affinity of that column is returned. Otherwise, 0x00 is returned,
80249 ** indicating no affinity for the expression.
80250 **
80251 ** i.e. the WHERE clause expresssions in the following statements all
80252 ** have an affinity:
80253 **
80254 ** CREATE TABLE t1(a);
80255 ** SELECT * FROM t1 WHERE a;
80256 ** SELECT a AS b FROM t1 WHERE b;
@@ -80725,11 +81029,11 @@
80725 exprSetHeight(pRoot);
80726 }
80727 }
80728
80729 /*
80730 ** Allocate a Expr node which joins as many as two subtrees.
80731 **
80732 ** One or both of the subtrees can be NULL. Return a pointer to the new
80733 ** Expr node. Or, if an OOM error occurs, set pParse->db->mallocFailed,
80734 ** free the subtrees and return NULL.
80735 */
@@ -80835,11 +81139,11 @@
80835 ** sure "nnn" is not too be to avoid a denial of service attack when
80836 ** the SQL statement comes from an external source.
80837 **
80838 ** Wildcards of the form ":aaa", "@aaa", or "$aaa" are assigned the same number
80839 ** as the previous instance of the same wildcard. Or if this is the first
80840 ** instance of the wildcard, the next sequenial variable number is
80841 ** assigned.
80842 */
80843 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
80844 sqlite3 *db = pParse->db;
80845 const char *z;
@@ -80970,11 +81274,11 @@
80970 ** Note that with flags==EXPRDUP_REDUCE, this routines works on full-size
80971 ** (unreduced) Expr objects as they or originally constructed by the parser.
80972 ** During expression analysis, extra information is computed and moved into
80973 ** later parts of teh Expr object and that extra information might get chopped
80974 ** off if the expression is reduced. Note also that it does not work to
80975 ** make a EXPRDUP_REDUCE copy of a reduced expression. It is only legal
80976 ** to reduce a pristine expression tree from the parser. The implementation
80977 ** of dupedExprStructSize() contain multiple assert() statements that attempt
80978 ** to enforce this constraint.
80979 */
80980 static int dupedExprStructSize(Expr *p, int flags){
@@ -81039,11 +81343,11 @@
81039 /*
81040 ** This function is similar to sqlite3ExprDup(), except that if pzBuffer
81041 ** is not NULL then *pzBuffer is assumed to point to a buffer large enough
81042 ** to store the copy of expression p, the copies of p->u.zToken
81043 ** (if applicable), and the copies of the p->pLeft and p->pRight expressions,
81044 ** if any. Before returning, *pzBuffer is set to the first byte passed the
81045 ** portion of the buffer copied into by this function.
81046 */
81047 static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
81048 Expr *pNew = 0; /* Value to return */
81049 if( p ){
@@ -81765,11 +82069,11 @@
81765 **
81766 ** SELECT <column> FROM <table>
81767 **
81768 ** If the RHS of the IN operator is a list or a more complex subquery, then
81769 ** an ephemeral table might need to be generated from the RHS and then
81770 ** pX->iTable made to point to the ephermeral table instead of an
81771 ** existing table.
81772 **
81773 ** The inFlags parameter must contain exactly one of the bits
81774 ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP. If inFlags contains
81775 ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a
@@ -81895,11 +82199,11 @@
81895
81896 /* If no preexisting index is available for the IN clause
81897 ** and IN_INDEX_NOOP is an allowed reply
81898 ** and the RHS of the IN operator is a list, not a subquery
81899 ** and the RHS is not contant or has two or fewer terms,
81900 ** then it is not worth creating an ephermeral table to evaluate
81901 ** the IN operator so return IN_INDEX_NOOP.
81902 */
81903 if( eType==0
81904 && (inFlags & IN_INDEX_NOOP_OK)
81905 && !ExprHasProperty(pX, EP_xIsSelect)
@@ -82656,20 +82960,13 @@
82656 /*
82657 ** Generate code to move content from registers iFrom...iFrom+nReg-1
82658 ** over to iTo..iTo+nReg-1. Keep the column cache up-to-date.
82659 */
82660 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse *pParse, int iFrom, int iTo, int nReg){
82661 int i;
82662 struct yColCache *p;
82663 assert( iFrom>=iTo+nReg || iFrom+nReg<=iTo );
82664 sqlite3VdbeAddOp3(pParse->pVdbe, OP_Move, iFrom, iTo, nReg);
82665 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
82666 int x = p->iReg;
82667 if( x>=iFrom && x<iFrom+nReg ){
82668 p->iReg += iTo-iFrom;
82669 }
82670 }
82671 }
82672
82673 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
82674 /*
82675 ** Return true if any register in the range iFrom..iTo (inclusive)
@@ -82982,11 +83279,11 @@
82982 sqlite3ErrorMsg(pParse, "unknown function: %.*s()", nId, zId);
82983 break;
82984 }
82985
82986 /* Attempt a direct implementation of the built-in COALESCE() and
82987 ** IFNULL() functions. This avoids unnecessary evalation of
82988 ** arguments past the first non-NULL argument.
82989 */
82990 if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
82991 int endCoalesce = sqlite3VdbeMakeLabel(v);
82992 assert( nFarg>=2 );
@@ -83421,11 +83718,11 @@
83421 sqlite3ExprCode(pParse, pExpr, target);
83422 }
83423 }
83424
83425 /*
83426 ** Generate code that evalutes the given expression and puts the result
83427 ** in register target.
83428 **
83429 ** Also make a copy of the expression results into another "cache" register
83430 ** and modify the expression so that the next time it is evaluated,
83431 ** the result is a copy of the cache register.
@@ -83776,11 +84073,11 @@
83776 ** The above is equivalent to
83777 **
83778 ** x>=y AND x<=z
83779 **
83780 ** Code it as such, taking care to do the common subexpression
83781 ** elementation of x.
83782 */
83783 static void exprCodeBetween(
83784 Parse *pParse, /* Parsing and code generating context */
83785 Expr *pExpr, /* The BETWEEN expression */
83786 int dest, /* Jump here if the jump is taken */
@@ -84513,11 +84810,11 @@
84513 /*
84514 ** Deallocate a register, making available for reuse for some other
84515 ** purpose.
84516 **
84517 ** If a register is currently being used by the column cache, then
84518 ** the dallocation is deferred until the column cache line that uses
84519 ** the register becomes stale.
84520 */
84521 SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){
84522 if( iReg && pParse->nTempReg<ArraySize(pParse->aTempReg) ){
84523 int i;
@@ -84740,12 +85037,12 @@
84740 sqlite3 *db = sqlite3_context_db_handle(context);
84741
84742 UNUSED_PARAMETER(NotUsed);
84743
84744 /* The principle used to locate the table name in the CREATE TRIGGER
84745 ** statement is that the table name is the first token that is immediatedly
84746 ** preceded by either TK_ON or TK_DOT and immediatedly followed by one
84747 ** of TK_WHEN, TK_BEGIN or TK_FOR.
84748 */
84749 if( zSql ){
84750 do {
84751
@@ -85432,11 +85729,11 @@
85432 ** version of sqlite_stat3 and is only available when compiled with
85433 ** SQLITE_ENABLE_STAT4 and in SQLite versions 3.8.1 and later. It is
85434 ** not possible to enable both STAT3 and STAT4 at the same time. If they
85435 ** are both enabled, then STAT4 takes precedence.
85436 **
85437 ** For most applications, sqlite_stat1 provides all the statisics required
85438 ** for the query planner to make good choices.
85439 **
85440 ** Format of sqlite_stat1:
85441 **
85442 ** There is normally one row per index, with the index identified by the
@@ -85783,12 +86080,13 @@
85783 ** WITHOUT ROWID tables, N=K+P where P is the number of columns in the
85784 ** PRIMARY KEY of the table. The covering index that implements the
85785 ** original WITHOUT ROWID table as N==K as a special case.
85786 **
85787 ** This routine allocates the Stat4Accum object in heap memory. The return
85788 ** value is a pointer to the the Stat4Accum object encoded as a blob (i.e.
85789 ** the size of the blob is sizeof(void*) bytes).
 
85790 */
85791 static void statInit(
85792 sqlite3_context *context,
85793 int argc,
85794 sqlite3_value **argv
@@ -85862,12 +86160,15 @@
85862 p->aBest[i].iCol = i;
85863 }
85864 }
85865 #endif
85866
85867 /* Return a pointer to the allocated object to the caller */
85868 sqlite3_result_blob(context, p, sizeof(p), stat4Destructor);
 
 
 
85869 }
85870 static const FuncDef statInitFuncdef = {
85871 2+IsStat34, /* nArg */
85872 SQLITE_UTF8, /* funcFlags */
85873 0, /* pUserData */
@@ -86189,11 +86490,11 @@
86189
86190 /*
86191 ** Implementation of the stat_get(P,J) SQL function. This routine is
86192 ** used to query statistical information that has been gathered into
86193 ** the Stat4Accum object by prior calls to stat_push(). The P parameter
86194 ** is a BLOB which is decoded into a pointer to the Stat4Accum objects.
86195 ** The content to returned is determined by the parameter J
86196 ** which is one of the STAT_GET_xxxx values defined above.
86197 **
86198 ** If neither STAT3 nor STAT4 are enabled, then J is always
86199 ** STAT_GET_STAT1 and is hence omitted and this routine becomes
@@ -86593,11 +86894,12 @@
86593 sqlite3VdbeChangeP5(v, 2+IsStat34);
86594 sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
86595
86596 /* Add the entry to the stat1 table. */
86597 callStatGet(v, regStat4, STAT_GET_STAT1, regStat1);
86598 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
 
86599 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
86600 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
86601 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
86602
86603 /* Add the entries to the stat3 or stat4 table. */
@@ -86656,11 +86958,12 @@
86656 if( pOnlyIdx==0 && needTableCnt ){
86657 VdbeComment((v, "%s", pTab->zName));
86658 sqlite3VdbeAddOp2(v, OP_Count, iTabCur, regStat1);
86659 jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1); VdbeCoverage(v);
86660 sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
86661 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
 
86662 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
86663 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
86664 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
86665 sqlite3VdbeJumpHere(v, jZeroRows);
86666 }
@@ -86975,11 +87278,11 @@
86975 tRowcnt nDLt = pFinal->anDLt[iCol];
86976
86977 /* Set nSum to the number of distinct (iCol+1) field prefixes that
86978 ** occur in the stat4 table for this index before pFinal. Set
86979 ** sumEq to the sum of the nEq values for column iCol for the same
86980 ** set (adding the value only once where there exist dupicate
86981 ** prefixes). */
86982 for(i=0; i<(pIdx->nSample-1); i++){
86983 if( aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol] ){
86984 sumEq += aSample[i].anEq[iCol];
86985 nSum++;
@@ -87457,10 +87760,19 @@
87457 if( rc==SQLITE_OK ){
87458 sqlite3BtreeEnterAll(db);
87459 rc = sqlite3Init(db, &zErrDyn);
87460 sqlite3BtreeLeaveAll(db);
87461 }
 
 
 
 
 
 
 
 
 
87462 if( rc ){
87463 int iDb = db->nDb - 1;
87464 assert( iDb>=2 );
87465 if( db->aDb[iDb].pBt ){
87466 sqlite3BtreeClose(db->aDb[iDb].pBt);
@@ -87899,11 +88211,11 @@
87899 sqlite3 *db,
87900 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
87901 void *pArg
87902 ){
87903 sqlite3_mutex_enter(db->mutex);
87904 db->xAuth = xAuth;
87905 db->pAuthArg = pArg;
87906 sqlite3ExpirePreparedStatements(db);
87907 sqlite3_mutex_leave(db->mutex);
87908 return SQLITE_OK;
87909 }
@@ -87934,11 +88246,15 @@
87934 ){
87935 sqlite3 *db = pParse->db; /* Database handle */
87936 char *zDb = db->aDb[iDb].zName; /* Name of attached database */
87937 int rc; /* Auth callback return code */
87938
87939 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext);
 
 
 
 
87940 if( rc==SQLITE_DENY ){
87941 if( db->nDb>2 || iDb!=0 ){
87942 sqlite3ErrorMsg(pParse, "access to %s.%s.%s is prohibited",zDb,zTab,zCol);
87943 }else{
87944 sqlite3ErrorMsg(pParse, "access to %s.%s is prohibited", zTab, zCol);
@@ -88034,11 +88350,15 @@
88034 }
88035
88036 if( db->xAuth==0 ){
88037 return SQLITE_OK;
88038 }
88039 rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext);
 
 
 
 
88040 if( rc==SQLITE_DENY ){
88041 sqlite3ErrorMsg(pParse, "not authorized");
88042 pParse->rc = SQLITE_AUTH;
88043 }else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){
88044 rc = SQLITE_DENY;
@@ -88232,10 +88552,21 @@
88232 assert( !pParse->isMultiWrite
88233 || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort));
88234 if( v ){
88235 while( sqlite3VdbeDeletePriorOpcode(v, OP_Close) ){}
88236 sqlite3VdbeAddOp0(v, OP_Halt);
 
 
 
 
 
 
 
 
 
 
 
88237
88238 /* The cookie mask contains one bit for each database file open.
88239 ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
88240 ** set for each database that is used. Generate code to start a
88241 ** transaction on each used database and to verify the schema cookie
@@ -88348,10 +88679,20 @@
88348 sqlite3DbFree(db, zSql);
88349 memcpy(&pParse->nVar, saveBuf, SAVE_SZ);
88350 pParse->nested--;
88351 }
88352
 
 
 
 
 
 
 
 
 
 
88353 /*
88354 ** Locate the in-memory structure that describes a particular database
88355 ** table given the name of that table and (optionally) the name of the
88356 ** database containing the table. Return NULL if not found.
88357 **
@@ -88366,10 +88707,17 @@
88366 Table *p = 0;
88367 int i;
88368 assert( zName!=0 );
88369 /* All mutexes are required for schema access. Make sure we hold them. */
88370 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
 
 
 
 
 
 
 
88371 for(i=OMIT_TEMPDB; i<db->nDb; i++){
88372 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
88373 if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
88374 assert( sqlite3SchemaMutexHeld(db, j, 0) );
88375 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
@@ -88410,10 +88758,16 @@
88410 }else{
88411 sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
88412 }
88413 pParse->checkSchema = 1;
88414 }
 
 
 
 
 
 
88415 return p;
88416 }
88417
88418 /*
88419 ** Locate the table identified by *p.
@@ -89220,11 +89574,11 @@
89220
89221 /* If pszEst is not NULL, store an estimate of the field size. The
89222 ** estimate is scaled so that the size of an integer is 1. */
89223 if( pszEst ){
89224 *pszEst = 1; /* default size is approx 4 bytes */
89225 if( aff<=SQLITE_AFF_NONE ){
89226 if( zChar ){
89227 while( zChar[0] ){
89228 if( sqlite3Isdigit(zChar[0]) ){
89229 int v = 0;
89230 sqlite3GetInt32(zChar, &v);
@@ -89591,12 +89945,12 @@
89591 k = sqlite3Strlen30(zStmt);
89592 identPut(zStmt, &k, p->zName);
89593 zStmt[k++] = '(';
89594 for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){
89595 static const char * const azType[] = {
89596 /* SQLITE_AFF_TEXT */ " TEXT",
89597 /* SQLITE_AFF_NONE */ "",
 
89598 /* SQLITE_AFF_NUMERIC */ " NUM",
89599 /* SQLITE_AFF_INTEGER */ " INT",
89600 /* SQLITE_AFF_REAL */ " REAL"
89601 };
89602 int len;
@@ -89604,19 +89958,19 @@
89604
89605 sqlite3_snprintf(n-k, &zStmt[k], zSep);
89606 k += sqlite3Strlen30(&zStmt[k]);
89607 zSep = zSep2;
89608 identPut(zStmt, &k, pCol->zName);
89609 assert( pCol->affinity-SQLITE_AFF_TEXT >= 0 );
89610 assert( pCol->affinity-SQLITE_AFF_TEXT < ArraySize(azType) );
89611 testcase( pCol->affinity==SQLITE_AFF_TEXT );
89612 testcase( pCol->affinity==SQLITE_AFF_NONE );
 
89613 testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
89614 testcase( pCol->affinity==SQLITE_AFF_INTEGER );
89615 testcase( pCol->affinity==SQLITE_AFF_REAL );
89616
89617 zType = azType[pCol->affinity - SQLITE_AFF_TEXT];
89618 len = sqlite3Strlen30(zType);
89619 assert( pCol->affinity==SQLITE_AFF_NONE
89620 || pCol->affinity==sqlite3AffinityType(zType, 0) );
89621 memcpy(&zStmt[k], zType, len);
89622 k += len;
@@ -89696,11 +90050,11 @@
89696 **
89697 ** (1) Convert the OP_CreateTable into an OP_CreateIndex. There is
89698 ** no rowid btree for a WITHOUT ROWID. Instead, the canonical
89699 ** data storage is a covering index btree.
89700 ** (2) Bypass the creation of the sqlite_master table entry
89701 ** for the PRIMARY KEY as the the primary key index is now
89702 ** identified by the sqlite_master table entry of the table itself.
89703 ** (3) Set the Index.tnum of the PRIMARY KEY Index object in the
89704 ** schema to the rootpage from the main table.
89705 ** (4) Set all columns of the PRIMARY KEY schema object to be NOT NULL.
89706 ** (5) Add all table columns to the PRIMARY KEY Index object
@@ -89717,11 +90071,11 @@
89717 int i, j;
89718 sqlite3 *db = pParse->db;
89719 Vdbe *v = pParse->pVdbe;
89720
89721 /* Convert the OP_CreateTable opcode that would normally create the
89722 ** root-page for the table into a OP_CreateIndex opcode. The index
89723 ** created will become the PRIMARY KEY index.
89724 */
89725 if( pParse->addrCrTab ){
89726 assert( v );
89727 sqlite3VdbeGetOp(v, pParse->addrCrTab)->opcode = OP_CreateIndex;
@@ -90129,11 +90483,11 @@
90129 Table *pSelTab; /* A fake table from which we get the result set */
90130 Select *pSel; /* Copy of the SELECT that implements the view */
90131 int nErr = 0; /* Number of errors encountered */
90132 int n; /* Temporarily holds the number of cursors assigned */
90133 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
90134 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
90135
90136 assert( pTable );
90137
90138 #ifndef SQLITE_OMIT_VIRTUALTABLE
90139 if( sqlite3VtabCallConnect(pParse, pTable) ){
@@ -90731,11 +91085,11 @@
90731 int addr2; /* Address to jump to for next iteration */
90732 int tnum; /* Root page of index */
90733 int iPartIdxLabel; /* Jump to this label to skip a row */
90734 Vdbe *v; /* Generate code into this virtual machine */
90735 KeyInfo *pKey; /* KeyInfo for index */
90736 int regRecord; /* Register holding assemblied index record */
90737 sqlite3 *db = pParse->db; /* The database connection */
90738 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
90739
90740 #ifndef SQLITE_OMIT_AUTHORIZATION
90741 if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
@@ -90944,10 +91298,14 @@
90944 pDb = &db->aDb[iDb];
90945
90946 assert( pTab!=0 );
90947 assert( pParse->nErr==0 );
90948 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
 
 
 
 
90949 && sqlite3StrNICmp(&pTab->zName[7],"altertab_",9)!=0 ){
90950 sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
90951 goto exit_create_index;
90952 }
90953 #ifndef SQLITE_OMIT_VIEW
@@ -91331,11 +91689,11 @@
91331
91332 /*
91333 ** Fill the Index.aiRowEst[] array with default information - information
91334 ** to be used when we have not run the ANALYZE command.
91335 **
91336 ** aiRowEst[0] is suppose to contain the number of elements in the index.
91337 ** Since we do not know, guess 1 million. aiRowEst[1] is an estimate of the
91338 ** number of rows in the table that match any particular value of the
91339 ** first column of the index. aiRowEst[2] is an estimate of the number
91340 ** of rows that match any particular combination of the first 2 columns
91341 ** of the index. And so forth. It must always be the case that
@@ -91710,11 +92068,11 @@
91710 ** end of a growing FROM clause. The "p" parameter is the part of
91711 ** the FROM clause that has already been constructed. "p" is NULL
91712 ** if this is the first term of the FROM clause. pTable and pDatabase
91713 ** are the name of the table and database named in the FROM clause term.
91714 ** pDatabase is NULL if the database name qualifier is missing - the
91715 ** usual case. If the term has a alias, then pAlias points to the
91716 ** alias token. If the term is a subquery, then pSubquery is the
91717 ** SELECT statement that the subquery encodes. The pTable and
91718 ** pDatabase parameters are NULL for subqueries. The pOn and pUsing
91719 ** parameters are the content of the ON and USING clauses.
91720 **
@@ -92473,11 +92831,11 @@
92473 ** specified by zName and nName is not found and parameter 'create' is
92474 ** true, then create a new entry. Otherwise return NULL.
92475 **
92476 ** Each pointer stored in the sqlite3.aCollSeq hash table contains an
92477 ** array of three CollSeq structures. The first is the collation sequence
92478 ** prefferred for UTF-8, the second UTF-16le, and the third UTF-16be.
92479 **
92480 ** Stored immediately after the three collation sequences is a copy of
92481 ** the collation sequence name. A pointer to this string is stored in
92482 ** each collation sequence structure.
92483 */
@@ -92900,11 +93258,11 @@
92900 */
92901 SQLITE_PRIVATE void sqlite3MaterializeView(
92902 Parse *pParse, /* Parsing context */
92903 Table *pView, /* View definition */
92904 Expr *pWhere, /* Optional WHERE clause to be added */
92905 int iCur /* Cursor number for ephemerial table */
92906 ){
92907 SelectDest dest;
92908 Select *pSel;
92909 SrcList *pFrom;
92910 sqlite3 *db = pParse->db;
@@ -93058,11 +93416,11 @@
93058 int iEphCur = 0; /* Ephemeral table holding all primary key values */
93059 int iRowSet = 0; /* Register for rowset of rows to delete */
93060 int addrBypass = 0; /* Address of jump over the delete logic */
93061 int addrLoop = 0; /* Top of the delete loop */
93062 int addrDelete = 0; /* Jump directly to the delete logic */
93063 int addrEphOpen = 0; /* Instruction to open the Ephermeral table */
93064
93065 #ifndef SQLITE_OMIT_TRIGGER
93066 int isView; /* True if attempting to delete from a view */
93067 Trigger *pTrigger; /* List of table triggers, if required */
93068 #endif
@@ -93138,11 +93496,11 @@
93138 }
93139 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
93140 sqlite3BeginWriteOperation(pParse, 1, iDb);
93141
93142 /* If we are trying to delete from a view, realize that view into
93143 ** a ephemeral table.
93144 */
93145 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
93146 if( isView ){
93147 sqlite3MaterializeView(pParse, pTab, pWhere, iTabCur);
93148 iDataCur = iIdxCur = iTabCur;
@@ -93192,11 +93550,11 @@
93192 pPk = 0;
93193 nPk = 1;
93194 iRowSet = ++pParse->nMem;
93195 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
93196 }else{
93197 /* For a WITHOUT ROWID table, create an ephermeral table used to
93198 ** hold all primary keys for rows to be deleted. */
93199 pPk = sqlite3PrimaryKeyIndex(pTab);
93200 assert( pPk!=0 );
93201 nPk = pPk->nKeyCol;
93202 iPk = pParse->nMem+1;
@@ -93367,11 +93725,11 @@
93367 sqlite3ExprDelete(db, pWhere);
93368 sqlite3DbFree(db, aToOpen);
93369 return;
93370 }
93371 /* Make sure "isView" and other macros defined above are undefined. Otherwise
93372 ** thely may interfere with compilation of other functions in this file
93373 ** (or in another file, if this file becomes part of the amalgamation). */
93374 #ifdef isView
93375 #undef isView
93376 #endif
93377 #ifdef pTrigger
@@ -93661,11 +94019,11 @@
93661 ** May you do good and not evil.
93662 ** May you find forgiveness for yourself and forgive others.
93663 ** May you share freely, never taking more than you give.
93664 **
93665 *************************************************************************
93666 ** This file contains the C-language implementions for many of the SQL
93667 ** functions of SQLite. (Some function, and in particular the date and
93668 ** time functions, are implemented separately.)
93669 */
93670 /* #include <stdlib.h> */
93671 /* #include <assert.h> */
@@ -93975,17 +94333,18 @@
93975 p1--;
93976 }
93977 for(z2=z; *z2 && p2; p2--){
93978 SQLITE_SKIP_UTF8(z2);
93979 }
93980 sqlite3_result_text(context, (char*)z, (int)(z2-z), SQLITE_TRANSIENT);
 
93981 }else{
93982 if( p1+p2>len ){
93983 p2 = len-p1;
93984 if( p2<0 ) p2 = 0;
93985 }
93986 sqlite3_result_blob(context, (char*)&z[p1], (int)p2, SQLITE_TRANSIENT);
93987 }
93988 }
93989
93990 /*
93991 ** Implementation of the round() function
@@ -94040,11 +94399,11 @@
94040 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
94041 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
94042 sqlite3_result_error_toobig(context);
94043 z = 0;
94044 }else{
94045 z = sqlite3Malloc((int)nByte);
94046 if( !z ){
94047 sqlite3_result_error_nomem(context);
94048 }
94049 }
94050 return z;
@@ -94691,11 +95050,11 @@
94691 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F);
94692 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F);
94693 *zOut++ = 0x80 + (u8)(c & 0x3F);
94694 } \
94695 }
94696 sqlite3_result_text(context, (char*)z, (int)(zOut-z), sqlite3_free);
94697 }
94698
94699 /*
94700 ** The hex() function. Interpret the argument as a blob. Return
94701 ** a hexadecimal rendering as text.
@@ -95141,10 +95500,11 @@
95141 sqlite3VdbeMemCopy(pBest, pArg);
95142 }else{
95143 sqlite3SkipAccumulatorLoad(context);
95144 }
95145 }else{
 
95146 sqlite3VdbeMemCopy(pBest, pArg);
95147 }
95148 }
95149 static void minMaxFinalize(sqlite3_context *context){
95150 sqlite3_value *pRes;
@@ -95288,11 +95648,11 @@
95288 *pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0;
95289 return 1;
95290 }
95291
95292 /*
95293 ** All all of the FuncDef structures in the aBuiltinFunc[] array above
95294 ** to the global function hash table. This occurs at start-time (as
95295 ** a consequence of calling sqlite3_initialize()).
95296 **
95297 ** After this routine runs
95298 */
@@ -95312,14 +95672,16 @@
95312 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
95313 FUNCTION(trim, 1, 3, 0, trimFunc ),
95314 FUNCTION(trim, 2, 3, 0, trimFunc ),
95315 FUNCTION(min, -1, 0, 1, minmaxFunc ),
95316 FUNCTION(min, 0, 0, 1, 0 ),
95317 AGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize ),
 
95318 FUNCTION(max, -1, 1, 1, minmaxFunc ),
95319 FUNCTION(max, 0, 1, 1, 0 ),
95320 AGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize ),
 
95321 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
95322 FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
95323 FUNCTION(instr, 2, 0, 0, instrFunc ),
95324 FUNCTION(substr, 2, 0, 0, substrFunc ),
95325 FUNCTION(substr, 3, 0, 0, substrFunc ),
@@ -95345,10 +95707,13 @@
95345 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
95346 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
95347 FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
95348 FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
95349 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
 
 
 
95350 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
95351 FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
95352 FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
95353 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
95354 FUNCTION(quote, 1, 0, 0, quoteFunc ),
@@ -95365,12 +95730,12 @@
95365 FUNCTION(load_extension, 2, 0, 0, loadExt ),
95366 #endif
95367 AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ),
95368 AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ),
95369 AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ),
95370 /* AGGREGATE(count, 0, 0, 0, countStep, countFinalize ), */
95371 {0,SQLITE_UTF8|SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0},
95372 AGGREGATE(count, 1, 0, 0, countStep, countFinalize ),
95373 AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, groupConcatFinalize),
95374 AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, groupConcatFinalize),
95375
95376 LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
@@ -95573,11 +95938,11 @@
95573 ** foreign key definition, and the parent table does not have a
95574 ** PRIMARY KEY, or
95575 **
95576 ** 4) No parent key columns were provided explicitly as part of the
95577 ** foreign key definition, and the PRIMARY KEY of the parent table
95578 ** consists of a a different number of columns to the child key in
95579 ** the child table.
95580 **
95581 ** then non-zero is returned, and a "foreign key mismatch" error loaded
95582 ** into pParse. If an OOM error occurs, non-zero is returned and the
95583 ** pParse->db->mallocFailed flag is set.
@@ -96820,17 +97185,17 @@
96820 ** pIdx. A column affinity string has one character for each column in
96821 ** the table, according to the affinity of the column:
96822 **
96823 ** Character Column affinity
96824 ** ------------------------------
96825 ** 'a' TEXT
96826 ** 'b' NONE
96827 ** 'c' NUMERIC
96828 ** 'd' INTEGER
96829 ** 'e' REAL
96830 **
96831 ** An extra 'd' is appended to the end of the string to cover the
96832 ** rowid that appears as the last column in every index.
96833 **
96834 ** Memory for the buffer containing the column index affinity string
96835 ** is managed along with the rest of the Index structure. It will be
96836 ** released when sqlite3DeleteIndex() is called.
@@ -96875,15 +97240,15 @@
96875 **
96876 ** A column affinity string has one character per column:
96877 **
96878 ** Character Column affinity
96879 ** ------------------------------
96880 ** 'a' TEXT
96881 ** 'b' NONE
96882 ** 'c' NUMERIC
96883 ** 'd' INTEGER
96884 ** 'e' REAL
96885 */
96886 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
96887 int i;
96888 char *zColAff = pTab->zColAff;
96889 if( zColAff==0 ){
@@ -97174,11 +97539,11 @@
97174 ** D: cleanup
97175 **
97176 ** The 4th template is used if the insert statement takes its
97177 ** values from a SELECT but the data is being inserted into a table
97178 ** that is also read as part of the SELECT. In the third form,
97179 ** we have to use a intermediate table to store the results of
97180 ** the select. The template is like this:
97181 **
97182 ** X <- A
97183 ** goto B
97184 ** A: setup for the SELECT
@@ -97339,11 +97704,11 @@
97339 ** sqlite_sequence table and store it in memory cell regAutoinc.
97340 */
97341 regAutoinc = autoIncBegin(pParse, iDb, pTab);
97342
97343 /* Allocate registers for holding the rowid of the new row,
97344 ** the content of the new row, and the assemblied row record.
97345 */
97346 regRowid = regIns = pParse->nMem+1;
97347 pParse->nMem += pTab->nCol + 1;
97348 if( IsVirtual(pTab) ){
97349 regRowid++;
@@ -97791,11 +98156,11 @@
97791 sqlite3IdListDelete(db, pColumn);
97792 sqlite3DbFree(db, aRegIdx);
97793 }
97794
97795 /* Make sure "isView" and other macros defined above are undefined. Otherwise
97796 ** thely may interfere with compilation of other functions in this file
97797 ** (or in another file, if this file becomes part of the amalgamation). */
97798 #ifdef isView
97799 #undef isView
97800 #endif
97801 #ifdef pTrigger
@@ -97907,11 +98272,11 @@
97907 sqlite3 *db; /* Database connection */
97908 int i; /* loop counter */
97909 int ix; /* Index loop counter */
97910 int nCol; /* Number of columns */
97911 int onError; /* Conflict resolution strategy */
97912 int j1; /* Addresss of jump instruction */
97913 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
97914 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
97915 int ipkTop = 0; /* Top of the rowid change constraint check */
97916 int ipkBottom = 0; /* Bottom of the rowid change constraint check */
97917 u8 isUpdate; /* True if this is an UPDATE operation */
@@ -98311,11 +98676,11 @@
98311 ){
98312 Vdbe *v; /* Prepared statements under construction */
98313 Index *pIdx; /* An index being inserted or updated */
98314 u8 pik_flags; /* flag values passed to the btree insert */
98315 int regData; /* Content registers (after the rowid) */
98316 int regRec; /* Register holding assemblied record for the table */
98317 int i; /* Loop counter */
98318 u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */
98319
98320 v = sqlite3GetVdbe(pParse);
98321 assert( v!=0 );
@@ -98436,11 +98801,11 @@
98436 #ifdef SQLITE_TEST
98437 /*
98438 ** The following global variable is incremented whenever the
98439 ** transfer optimization is used. This is used for testing
98440 ** purposes only - to make sure the transfer optimization really
98441 ** is happening when it is suppose to.
98442 */
98443 SQLITE_API int sqlite3_xferopt_count;
98444 #endif /* SQLITE_TEST */
98445
98446
@@ -98503,11 +98868,11 @@
98503 ** Attempt the transfer optimization on INSERTs of the form
98504 **
98505 ** INSERT INTO tab1 SELECT * FROM tab2;
98506 **
98507 ** The xfer optimization transfers raw records from tab2 over to tab1.
98508 ** Columns are not decoded and reassemblied, which greatly improves
98509 ** performance. Raw index records are transferred in the same way.
98510 **
98511 ** The xfer optimization is only attempted if tab1 and tab2 are compatible.
98512 ** There are lots of rules for determining compatibility - see comments
98513 ** embedded in the code for details.
@@ -98912,11 +99277,11 @@
98912 exec_out:
98913 if( pStmt ) sqlite3VdbeFinalize((Vdbe *)pStmt);
98914 sqlite3DbFree(db, azCols);
98915
98916 rc = sqlite3ApiExit(db, rc);
98917 if( rc!=SQLITE_OK && ALWAYS(rc==sqlite3_errcode(db)) && pzErrMsg ){
98918 int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db));
98919 *pzErrMsg = sqlite3Malloc(nErrMsg);
98920 if( *pzErrMsg ){
98921 memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg);
98922 }else{
@@ -98981,11 +99346,11 @@
98981 ** routines.
98982 **
98983 ** WARNING: In order to maintain backwards compatibility, add new
98984 ** interfaces to the end of this structure only. If you insert new
98985 ** interfaces in the middle of this structure, then older different
98986 ** versions of SQLite will not be able to load each others' shared
98987 ** libraries!
98988 */
98989 struct sqlite3_api_routines {
98990 void * (*aggregate_context)(sqlite3_context*,int nBytes);
98991 int (*aggregate_count)(sqlite3_context*);
@@ -99203,15 +99568,32 @@
99203 int (*uri_boolean)(const char*,const char*,int);
99204 sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64);
99205 const char *(*uri_parameter)(const char*,const char*);
99206 char *(*vsnprintf)(int,char*,const char*,va_list);
99207 int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99208 };
99209
99210 /*
99211 ** The following macros redefine the API routines so that they are
99212 ** redirected throught the global sqlite3_api structure.
99213 **
99214 ** This header file is also used by the loadext.c source file
99215 ** (part of the main SQLite library - not an extension) so that
99216 ** it can get access to the sqlite3_api_routines structure
99217 ** definition. But the main library does not want to redefine
@@ -99420,10 +99802,23 @@
99420 #define sqlite3_uri_boolean sqlite3_api->uri_boolean
99421 #define sqlite3_uri_int64 sqlite3_api->uri_int64
99422 #define sqlite3_uri_parameter sqlite3_api->uri_parameter
99423 #define sqlite3_uri_vsnprintf sqlite3_api->vsnprintf
99424 #define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2
 
 
 
 
 
 
 
 
 
 
 
 
 
99425 #endif /* SQLITE_CORE */
99426
99427 #ifndef SQLITE_CORE
99428 /* This case when the file really is being compiled as a loadable
99429 ** extension */
@@ -99813,11 +100208,24 @@
99813 sqlite3_stricmp,
99814 sqlite3_uri_boolean,
99815 sqlite3_uri_int64,
99816 sqlite3_uri_parameter,
99817 sqlite3_vsnprintf,
99818 sqlite3_wal_checkpoint_v2
 
 
 
 
 
 
 
 
 
 
 
 
 
99819 };
99820
99821 /*
99822 ** Attempt to load an SQLite extension library contained in the file
99823 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -101580,10 +101988,16 @@
101580 if( db->autoCommit==0 ){
101581 /* Foreign key support may not be enabled or disabled while not
101582 ** in auto-commit mode. */
101583 mask &= ~(SQLITE_ForeignKeys);
101584 }
 
 
 
 
 
 
101585
101586 if( sqlite3GetBoolean(zRight, 0) ){
101587 db->flags |= mask;
101588 }else{
101589 db->flags &= ~mask;
@@ -102897,11 +103311,11 @@
102897 zSql = sqlite3MPrintf(db,
102898 "SELECT name, rootpage, sql FROM '%q'.%s ORDER BY rowid",
102899 db->aDb[iDb].zName, zMasterName);
102900 #ifndef SQLITE_OMIT_AUTHORIZATION
102901 {
102902 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
102903 xAuth = db->xAuth;
102904 db->xAuth = 0;
102905 #endif
102906 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
102907 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -102963,10 +103377,11 @@
102963 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
102964 int i, rc;
102965 int commit_internal = !(db->flags&SQLITE_InternChanges);
102966
102967 assert( sqlite3_mutex_held(db->mutex) );
 
102968 rc = SQLITE_OK;
102969 db->init.busy = 1;
102970 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
102971 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
102972 rc = sqlite3InitOne(db, i, pzErrMsg);
@@ -102978,12 +103393,12 @@
102978 /* Once all the other databases have been initialized, load the schema
102979 ** for the TEMP database. This is loaded last, as the TEMP database
102980 ** schema may contain references to objects in other databases.
102981 */
102982 #ifndef SQLITE_OMIT_TEMPDB
102983 if( rc==SQLITE_OK && ALWAYS(db->nDb>1)
102984 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
102985 rc = sqlite3InitOne(db, 1, pzErrMsg);
102986 if( rc ){
102987 sqlite3ResetOneSchema(db, 1);
102988 }
102989 }
@@ -103944,11 +104359,11 @@
103944 sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, SQLITE_ECEL_DUP);
103945 if( bSeq ){
103946 sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
103947 }
103948 if( nPrefixReg==0 ){
103949 sqlite3VdbeAddOp3(v, OP_Move, regData, regBase+nExpr+bSeq, nData);
103950 }
103951
103952 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase+nOBSat, nBase-nOBSat, regRecord);
103953 if( nOBSat>0 ){
103954 int regPrevKey; /* The first nOBSat columns of the previous row */
@@ -103980,11 +104395,11 @@
103980 pSort->labelBkOut = sqlite3VdbeMakeLabel(v);
103981 pSort->regReturn = ++pParse->nMem;
103982 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
103983 sqlite3VdbeAddOp1(v, OP_ResetSorter, pSort->iECursor);
103984 sqlite3VdbeJumpHere(v, addrFirst);
103985 sqlite3VdbeAddOp3(v, OP_Move, regBase, regPrevKey, pSort->nOBSat);
103986 sqlite3VdbeJumpHere(v, addrJmp);
103987 }
103988 if( pSort->sortFlags & SORTFLAG_UseSorter ){
103989 op = OP_SorterInsert;
103990 }else{
@@ -104466,11 +104881,11 @@
104466 ** KeyInfo structure is appropriate for initializing a virtual index to
104467 ** implement that clause. If the ExprList is the result set of a SELECT
104468 ** then the KeyInfo structure is appropriate for initializing a virtual
104469 ** index to implement a DISTINCT test.
104470 **
104471 ** Space to hold the KeyInfo structure is obtain from malloc. The calling
104472 ** function is responsible for seeing that this structure is eventually
104473 ** freed.
104474 */
104475 static KeyInfo *keyInfoFromExprList(
104476 Parse *pParse, /* Parsing context */
@@ -104997,11 +105412,11 @@
104997 }
104998 generateColumnTypes(pParse, pTabList, pEList);
104999 }
105000
105001 /*
105002 ** Given a an expression list (which is really the list of expressions
105003 ** that form the result set of a SELECT statement) compute appropriate
105004 ** column names for a table that would hold the expression list.
105005 **
105006 ** All column names will be unique.
105007 **
@@ -105070,11 +105485,11 @@
105070 sqlite3DbFree(db, zName);
105071 break;
105072 }
105073
105074 /* Make sure the column name is unique. If the name is not unique,
105075 ** append a integer to the name so that it becomes unique.
105076 */
105077 nName = sqlite3Strlen30(zName);
105078 for(j=cnt=0; j<i; j++){
105079 if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){
105080 char *zNewName;
@@ -106554,11 +106969,11 @@
106554 ** This routine attempts to rewrite queries such as the above into
106555 ** a single flat select, like this:
106556 **
106557 ** SELECT x+y AS a FROM t1 WHERE z<100 AND a>5
106558 **
106559 ** The code generated for this simpification gives the same result
106560 ** but only has to scan the data once. And because indices might
106561 ** exist on the table t1, a complete scan of the data might be
106562 ** avoided.
106563 **
106564 ** Flattening is only attempted if all of the following are true:
@@ -106587,12 +107002,14 @@
106587 ** (8) The subquery does not use LIMIT or the outer query is not a join.
106588 **
106589 ** (9) The subquery does not use LIMIT or the outer query does not use
106590 ** aggregates.
106591 **
106592 ** (10) The subquery does not use aggregates or the outer query does not
106593 ** use LIMIT.
 
 
106594 **
106595 ** (11) The subquery and the outer query do not both have ORDER BY clauses.
106596 **
106597 ** (**) Not implemented. Subsumed into restriction (3). Was previously
106598 ** a separate restriction deriving from ticket #350.
@@ -106651,10 +107068,15 @@
106651 ** (23) The parent is not a recursive CTE, or the sub-query is not a
106652 ** compound query. This restriction is because transforming the
106653 ** parent to a compound query confuses the code that handles
106654 ** recursive queries in multiSelect().
106655 **
 
 
 
 
 
106656 **
106657 ** In this routine, the "p" parameter is a pointer to the outer query.
106658 ** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
106659 ** uses aggregates and subqueryIsAgg is true if the subquery uses aggregates.
106660 **
@@ -106698,11 +107120,11 @@
106698 if( isAgg && subqueryIsAgg ) return 0; /* Restriction (1) */
106699 if( subqueryIsAgg && pSrc->nSrc>1 ) return 0; /* Restriction (2) */
106700 pSubSrc = pSub->pSrc;
106701 assert( pSubSrc );
106702 /* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
106703 ** not arbitrary expresssions, we allowed some combining of LIMIT and OFFSET
106704 ** because they could be computed at compile-time. But when LIMIT and OFFSET
106705 ** became arbitrary expressions, we were forced to add restrictions (13)
106706 ** and (14). */
106707 if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
106708 if( pSub->pOffset ) return 0; /* Restriction (14) */
@@ -106723,12 +107145,18 @@
106723 if( isAgg && pSub->pOrderBy ) return 0; /* Restriction (16) */
106724 if( pSub->pLimit && p->pWhere ) return 0; /* Restriction (19) */
106725 if( pSub->pLimit && (p->selFlags & SF_Distinct)!=0 ){
106726 return 0; /* Restriction (21) */
106727 }
106728 if( pSub->selFlags & SF_Recursive ) return 0; /* Restriction (22) */
106729 if( (p->selFlags & SF_Recursive) && pSub->pPrior ) return 0; /* (23) */
 
 
 
 
 
 
106730
106731 /* OBSOLETE COMMENT 1:
106732 ** Restriction 3: If the subquery is a join, make sure the subquery is
106733 ** not used as the right operand of an outer join. Examples of why this
106734 ** is not allowed:
@@ -107084,11 +107512,11 @@
107084 return eRet;
107085 }
107086
107087 /*
107088 ** The select statement passed as the first argument is an aggregate query.
107089 ** The second argment is the associated aggregate-info object. This
107090 ** function tests if the SELECT is of the form:
107091 **
107092 ** SELECT count(*) FROM <tbl>
107093 **
107094 ** where table is a database table, not a sub-select or view. If the query
@@ -107414,14 +107842,14 @@
107414 ** (2) Fill in the pTabList->a[].pTab fields in the SrcList that
107415 ** defines FROM clause. When views appear in the FROM clause,
107416 ** fill pTabList->a[].pSelect with a copy of the SELECT statement
107417 ** that implements the view. A copy is made of the view's SELECT
107418 ** statement so that we can freely modify or delete that statement
107419 ** without worrying about messing up the presistent representation
107420 ** of the view.
107421 **
107422 ** (3) Add terms to the WHERE clause to accomodate the NATURAL keyword
107423 ** on joins and the ON and USING clause of joins.
107424 **
107425 ** (4) Scan the list of columns in the result set (pEList) looking
107426 ** for instances of the "*" operator or the TABLE.* operator.
107427 ** If found, expand each "*" to be every column in every table
@@ -108927,14 +109355,14 @@
108927 ** to the callback function is uses to build the result.
108928 */
108929 typedef struct TabResult {
108930 char **azResult; /* Accumulated output */
108931 char *zErrMsg; /* Error message text, if an error occurs */
108932 int nAlloc; /* Slots allocated for azResult[] */
108933 int nRow; /* Number of rows in the result */
108934 int nColumn; /* Number of columns in the result */
108935 int nData; /* Slots used in azResult[]. (nRow+1)*nColumn */
108936 int rc; /* Return code from sqlite3_exec() */
108937 } TabResult;
108938
108939 /*
108940 ** This routine is called once for each row in the result table. Its job
@@ -108956,11 +109384,11 @@
108956 need = nCol;
108957 }
108958 if( p->nData + need > p->nAlloc ){
108959 char **azNew;
108960 p->nAlloc = p->nAlloc*2 + need;
108961 azNew = sqlite3_realloc( p->azResult, sizeof(char*)*p->nAlloc );
108962 if( azNew==0 ) goto malloc_failed;
108963 p->azResult = azNew;
108964 }
108965
108966 /* If this is the first row, then generate an extra row containing
@@ -108971,11 +109399,11 @@
108971 for(i=0; i<nCol; i++){
108972 z = sqlite3_mprintf("%s", colv[i]);
108973 if( z==0 ) goto malloc_failed;
108974 p->azResult[p->nData++] = z;
108975 }
108976 }else if( p->nColumn!=nCol ){
108977 sqlite3_free(p->zErrMsg);
108978 p->zErrMsg = sqlite3_mprintf(
108979 "sqlite3_get_table() called with two or more incompatible queries"
108980 );
108981 p->rc = SQLITE_ERROR;
@@ -109080,11 +109508,11 @@
109080
109081 /*
109082 ** This routine frees the space the sqlite3_get_table() malloced.
109083 */
109084 SQLITE_API void sqlite3_free_table(
109085 char **azResult /* Result returned from from sqlite3_get_table() */
109086 ){
109087 if( azResult ){
109088 int i, n;
109089 azResult--;
109090 assert( azResult!=0 );
@@ -109224,11 +109652,11 @@
109224 **
109225 ** CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab ....
109226 ** ^^^^^^^^
109227 **
109228 ** To maintain backwards compatibility, ignore the database
109229 ** name on pTableName if we are reparsing our of SQLITE_MASTER.
109230 */
109231 if( db->init.busy && iDb!=1 ){
109232 sqlite3DbFree(db, pTableName->a[0].zDatabase);
109233 pTableName->a[0].zDatabase = 0;
109234 }
@@ -110545,11 +110973,11 @@
110545 if( isView ){
110546 sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
110547 }
110548
110549 /* If we are trying to update a view, realize that view into
110550 ** a ephemeral table.
110551 */
110552 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
110553 if( isView ){
110554 sqlite3MaterializeView(pParse, pTab, pWhere, iDataCur);
110555 }
@@ -110706,11 +111134,11 @@
110706 sqlite3VdbeAddOp2(v, OP_Copy, regOldRowid, regNewRowid);
110707 }
110708 }
110709
110710 /* Populate the array of registers beginning at regNew with the new
110711 ** row data. This array is used to check constaints, create the new
110712 ** table and index records, and as the values for any new.* references
110713 ** made by triggers.
110714 **
110715 ** If there are one or more BEFORE triggers, then do not populate the
110716 ** registers associated with columns that are (a) not modified by
@@ -110886,11 +111314,11 @@
110886 sqlite3ExprListDelete(db, pChanges);
110887 sqlite3ExprDelete(db, pWhere);
110888 return;
110889 }
110890 /* Make sure "isView" and other macros defined above are undefined. Otherwise
110891 ** thely may interfere with compilation of other functions in this file
110892 ** (or in another file, if this file becomes part of the amalgamation). */
110893 #ifdef isView
110894 #undef isView
110895 #endif
110896 #ifdef pTrigger
@@ -110899,19 +111327,19 @@
110899
110900 #ifndef SQLITE_OMIT_VIRTUALTABLE
110901 /*
110902 ** Generate code for an UPDATE of a virtual table.
110903 **
110904 ** The strategy is that we create an ephemerial table that contains
110905 ** for each row to be changed:
110906 **
110907 ** (A) The original rowid of that row.
110908 ** (B) The revised rowid for the row. (note1)
110909 ** (C) The content of every column in the row.
110910 **
110911 ** Then we loop over this ephemeral table and for each row in
110912 ** the ephermeral table call VUpdate.
110913 **
110914 ** When finished, drop the ephemeral table.
110915 **
110916 ** (note1) Actually, if we know in advance that (A) is always the same
110917 ** as (B) we only store (A), then duplicate (A) when pulling
@@ -111080,11 +111508,11 @@
111080 ** The transient database requires temporary disk space approximately
111081 ** equal to the size of the original database. The copy operation of
111082 ** step (3) requires additional temporary disk space approximately equal
111083 ** to the size of the original database for the rollback journal.
111084 ** Hence, temporary disk space that is approximately 2x the size of the
111085 ** orginal database is required. Every page of the database is written
111086 ** approximately 3 times: Once for step (2) and twice for step (3).
111087 ** Two writes per page are required in step (3) because the original
111088 ** database content must be written into the rollback journal prior to
111089 ** overwriting the database with the vacuumed content.
111090 **
@@ -112659,11 +113087,11 @@
112659 **
112660 ** The "solver" works by creating the N best WherePath objects of length
112661 ** 1. Then using those as a basis to compute the N best WherePath objects
112662 ** of length 2. And so forth until the length of WherePaths equals the
112663 ** number of nodes in the FROM clause. The best (lowest cost) WherePath
112664 ** at the end is the choosen query plan.
112665 */
112666 struct WherePath {
112667 Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */
112668 Bitmask revLoop; /* aLoop[]s that should be reversed for ORDER BY */
112669 LogEst nRow; /* Estimated number of rows generated by this path */
@@ -113628,11 +114056,11 @@
113628 if( *pisComplete && pRight->u.zToken[1] ){
113629 /* If the rhs of the LIKE expression is a variable, and the current
113630 ** value of the variable means there is no need to invoke the LIKE
113631 ** function, then no OP_Variable will be added to the program.
113632 ** This causes problems for the sqlite3_bind_parameter_name()
113633 ** API. To workaround them, add a dummy OP_Variable here.
113634 */
113635 int r1 = sqlite3GetTempReg(pParse);
113636 sqlite3ExprCodeTarget(pParse, pRight, r1);
113637 sqlite3VdbeChangeP3(v, sqlite3VdbeCurrentAddr(v)-1, 0);
113638 sqlite3ReleaseTempReg(pParse, r1);
@@ -113748,11 +114176,11 @@
113748 ** This analysis does not consider whether or not the index exists; that
113749 ** is decided elsewhere. This analysis only looks at whether subterms
113750 ** appropriate for indexing exist.
113751 **
113752 ** All examples A through E above satisfy case 2. But if a term
113753 ** also statisfies case 1 (such as B) we know that the optimizer will
113754 ** always prefer case 1, so in that case we pretend that case 2 is not
113755 ** satisfied.
113756 **
113757 ** It might be the case that multiple tables are indexable. For example,
113758 ** (E) above is indexable on tables P, Q, and R.
@@ -113906,11 +114334,11 @@
113906 assert( j==1 );
113907 continue;
113908 }
113909 if( (chngToIN & getMask(&pWInfo->sMaskSet, pOrTerm->leftCursor))==0 ){
113910 /* This term must be of the form t1.a==t2.b where t2 is in the
113911 ** chngToIN set but t1 is not. This term will be either preceeded
113912 ** or follwed by an inverted copy (t2.b==t1.a). Skip this term
113913 ** and use its inversion. */
113914 testcase( pOrTerm->wtFlags & TERM_COPIED );
113915 testcase( pOrTerm->wtFlags & TERM_VIRTUAL );
113916 assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) );
@@ -114317,11 +114745,11 @@
114317 */
114318 pTerm->prereqRight |= extraRight;
114319 }
114320
114321 /*
114322 ** This function searches pList for a entry that matches the iCol-th column
114323 ** of index pIdx.
114324 **
114325 ** If such an expression is found, its index in pList->a[] is returned. If
114326 ** no expression is found, -1 is returned.
114327 */
@@ -114840,11 +115268,11 @@
114840 iCol = pRec->nField - 1;
114841 assert( pIdx->nSample>0 );
114842 assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
114843 do{
114844 iTest = (iMin+i)/2;
114845 res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec, 0);
114846 if( res<0 ){
114847 iMin = iTest+1;
114848 }else{
114849 i = iTest;
114850 }
@@ -114855,20 +115283,20 @@
114855 ** above found the right answer. This block serves no purpose other
114856 ** than to invoke the asserts. */
114857 if( res==0 ){
114858 /* If (res==0) is true, then sample $i must be equal to pRec */
114859 assert( i<pIdx->nSample );
114860 assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec, 0)
114861 || pParse->db->mallocFailed );
114862 }else{
114863 /* Otherwise, pRec must be smaller than sample $i and larger than
114864 ** sample ($i-1). */
114865 assert( i==pIdx->nSample
114866 || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec, 0)>0
114867 || pParse->db->mallocFailed );
114868 assert( i==0
114869 || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec, 0)<0
114870 || pParse->db->mallocFailed );
114871 }
114872 #endif /* ifdef SQLITE_DEBUG */
114873
114874 /* At this point, aSample[i] is the first sample that is greater than
@@ -115067,11 +115495,11 @@
115067 **
115068 ** When this function is called, *pnOut is set to the sqlite3LogEst() of the
115069 ** number of rows that the index scan is expected to visit without
115070 ** considering the range constraints. If nEq is 0, this is the number of
115071 ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
115072 ** to account for the range contraints pLower and pUpper.
115073 **
115074 ** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be
115075 ** used, a single range inequality reduces the search space by a factor of 4.
115076 ** and a pair of constraints (x>? AND x<?) reduces the expected number of
115077 ** rows visited by a factor of 64.
@@ -116344,11 +116772,11 @@
116344 ** Return 2 # Jump back to the Gosub
116345 **
116346 ** B: <after the loop>
116347 **
116348 ** Added 2014-05-26: If the table is a WITHOUT ROWID table, then
116349 ** use an ephermeral index instead of a RowSet to record the primary
116350 ** keys of the rows we have already seen.
116351 **
116352 */
116353 WhereClause *pOrWc; /* The OR-clause broken out into subterms */
116354 SrcList *pOrTab; /* Shortened table list or OR-clause generation */
@@ -116395,11 +116823,11 @@
116395 }else{
116396 pOrTab = pWInfo->pTabList;
116397 }
116398
116399 /* Initialize the rowset register to contain NULL. An SQL NULL is
116400 ** equivalent to an empty rowset. Or, create an ephermeral index
116401 ** capable of holding primary keys in the case of a WITHOUT ROWID.
116402 **
116403 ** Also initialize regReturn to contain the address of the instruction
116404 ** immediately following the OP_Return at the bottom of the loop. This
116405 ** is required in a few obscure LEFT JOIN cases where control jumps
@@ -117148,18 +117576,20 @@
117148 **
117149 ** In the current implementation, the first extra WHERE clause term reduces
117150 ** the number of output rows by a factor of 10 and each additional term
117151 ** reduces the number of output rows by sqrt(2).
117152 */
117153 static void whereLoopOutputAdjust(WhereClause *pWC, WhereLoop *pLoop){
 
 
 
 
117154 WhereTerm *pTerm, *pX;
117155 Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf);
117156 int i, j;
 
117157
117158 if( !OptimizationEnabled(pWC->pWInfo->pParse->db, SQLITE_AdjustOutEst) ){
117159 return;
117160 }
117161 for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){
117162 if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
117163 if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
117164 if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
117165 for(j=pLoop->nLTerm-1; j>=0; j--){
@@ -117167,12 +117597,24 @@
117167 if( pX==0 ) continue;
117168 if( pX==pTerm ) break;
117169 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
117170 }
117171 if( j<0 ){
117172 pLoop->nOut += (pTerm->truthProb<=0 ? pTerm->truthProb : -1);
 
 
 
 
 
117173 }
 
 
 
 
 
 
 
117174 }
117175 }
117176
117177 /*
117178 ** Adjust the cost C by the costMult facter T. This only occurs if
@@ -117215,10 +117657,11 @@
117215 u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */
117216 u32 saved_wsFlags; /* Original value of pNew->wsFlags */
117217 LogEst saved_nOut; /* Original value of pNew->nOut */
117218 int iCol; /* Index of the column in the table */
117219 int rc = SQLITE_OK; /* Return code */
 
117220 LogEst rLogSize; /* Logarithm of table size */
117221 WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
117222
117223 pNew = pBuilder->pNew;
117224 if( db->mallocFailed ) return SQLITE_NOMEM;
@@ -117244,11 +117687,12 @@
117244 saved_nLTerm = pNew->nLTerm;
117245 saved_wsFlags = pNew->wsFlags;
117246 saved_prereq = pNew->prereq;
117247 saved_nOut = pNew->nOut;
117248 pNew->rSetup = 0;
117249 rLogSize = estLog(pProbe->aiRowLogEst[0]);
 
117250
117251 /* Consider using a skip-scan if there are no WHERE clause constraints
117252 ** available for the left-most terms of the index, and if the average
117253 ** number of repeats in the left-most terms is at least 18.
117254 **
@@ -117421,11 +117865,11 @@
117421 ApplyCostMultiplier(pNew->rRun, pProbe->pTable->costMult);
117422
117423 nOutUnadjusted = pNew->nOut;
117424 pNew->rRun += nInMul + nIn;
117425 pNew->nOut += nInMul + nIn;
117426 whereLoopOutputAdjust(pBuilder->pWC, pNew);
117427 rc = whereLoopInsert(pBuilder, pNew);
117428
117429 if( pNew->wsFlags & WHERE_COLUMN_RANGE ){
117430 pNew->nOut = saved_nOut;
117431 }else{
@@ -117471,10 +117915,11 @@
117471 if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
117472 for(ii=0; ii<pOB->nExpr; ii++){
117473 Expr *pExpr = sqlite3ExprSkipCollate(pOB->a[ii].pExpr);
117474 if( pExpr->op!=TK_COLUMN ) return 0;
117475 if( pExpr->iTable==iCursor ){
 
117476 for(jj=0; jj<pIndex->nKeyCol; jj++){
117477 if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1;
117478 }
117479 }
117480 }
@@ -117634,11 +118079,11 @@
117634 ** the table being indexed. */
117635 pNew->rSetup = rLogSize + rSize + 28; assert( 28==sqlite3LogEst(7) );
117636 ApplyCostMultiplier(pNew->rSetup, pTab->costMult);
117637 /* TUNING: Each index lookup yields 20 rows in the table. This
117638 ** is more than the usual guess of 10 rows, since we have no way
117639 ** of knowning how selective the index will ultimately be. It would
117640 ** not be unreasonable to make this value much larger. */
117641 pNew->nOut = 43; assert( 43==sqlite3LogEst(20) );
117642 pNew->rRun = sqlite3LogEstAdd(rLogSize,pNew->nOut);
117643 pNew->wsFlags = WHERE_AUTO_INDEX;
117644 pNew->prereq = mExtra | pTerm->prereqRight;
@@ -117675,11 +118120,11 @@
117675 /* Full table scan */
117676 pNew->iSortIdx = b ? iSortIdx : 0;
117677 /* TUNING: Cost of full table scan is (N*3.0). */
117678 pNew->rRun = rSize + 16;
117679 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
117680 whereLoopOutputAdjust(pWC, pNew);
117681 rc = whereLoopInsert(pBuilder, pNew);
117682 pNew->nOut = rSize;
117683 if( rc ) break;
117684 }else{
117685 Bitmask m;
@@ -117711,11 +118156,11 @@
117711 pNew->rRun = rSize + 1 + (15*pProbe->szIdxRow)/pTab->szTabRow;
117712 if( m!=0 ){
117713 pNew->rRun = sqlite3LogEstAdd(pNew->rRun, rSize+16);
117714 }
117715 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
117716 whereLoopOutputAdjust(pWC, pNew);
117717 rc = whereLoopInsert(pBuilder, pNew);
117718 pNew->nOut = rSize;
117719 if( rc ) break;
117720 }
117721 }
@@ -118064,11 +118509,11 @@
118064 **
118065 ** Note that processing for WHERE_GROUPBY and WHERE_DISTINCTBY is not as
118066 ** strict. With GROUP BY and DISTINCT the only requirement is that
118067 ** equivalent rows appear immediately adjacent to one another. GROUP BY
118068 ** and DISTINCT do not require rows to appear in any particular order as long
118069 ** as equivelent rows are grouped together. Thus for GROUP BY and DISTINCT
118070 ** the pOrderBy terms can be matched in any order. With ORDER BY, the
118071 ** pOrderBy terms must be matched in strict left-to-right order.
118072 */
118073 static i8 wherePathSatisfiesOrderBy(
118074 WhereInfo *pWInfo, /* The WHERE clause */
@@ -120841,13 +121286,13 @@
120841 **
120842 ** Outputs:
120843 ** A pointer to a parser. This pointer is used in subsequent calls
120844 ** to sqlite3Parser and sqlite3ParserFree.
120845 */
120846 SQLITE_PRIVATE void *sqlite3ParserAlloc(void *(*mallocProc)(size_t)){
120847 yyParser *pParser;
120848 pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
120849 if( pParser ){
120850 pParser->yyidx = -1;
120851 #ifdef YYTRACKMAXSTACKDEPTH
120852 pParser->yyidxMax = 0;
120853 #endif
@@ -123398,11 +123843,11 @@
123398 **
123399 ** For EBCDIC, the rules are more complex but have the same
123400 ** end result.
123401 **
123402 ** Ticket #1066. the SQL standard does not allow '$' in the
123403 ** middle of identfiers. But many SQL implementations do.
123404 ** SQLite will allow '$' in identifiers for compatibility.
123405 ** But the feature is undocumented.
123406 */
123407 #ifdef SQLITE_ASCII
123408 #define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)
@@ -123719,11 +124164,11 @@
123719 }
123720 pParse->rc = SQLITE_OK;
123721 pParse->zTail = zSql;
123722 i = 0;
123723 assert( pzErrMsg!=0 );
123724 pEngine = sqlite3ParserAlloc((void*(*)(size_t))sqlite3Malloc);
123725 if( pEngine==0 ){
123726 db->mallocFailed = 1;
123727 return SQLITE_NOMEM;
123728 }
123729 assert( pParse->pNewTable==0 );
@@ -123914,21 +124359,21 @@
123914 **
123915 ** (3) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
123916 ** a statement.
123917 **
123918 ** (4) CREATE The keyword CREATE has been seen at the beginning of a
123919 ** statement, possibly preceeded by EXPLAIN and/or followed by
123920 ** TEMP or TEMPORARY
123921 **
123922 ** (5) TRIGGER We are in the middle of a trigger definition that must be
123923 ** ended by a semicolon, the keyword END, and another semicolon.
123924 **
123925 ** (6) SEMI We've seen the first semicolon in the ";END;" that occurs at
123926 ** the end of a trigger definition.
123927 **
123928 ** (7) END We've seen the ";END" of the ";END;" that occurs at the end
123929 ** of a trigger difinition.
123930 **
123931 ** Transitions between states above are determined by tokens extracted
123932 ** from the input. The following tokens are significant:
123933 **
123934 ** (0) tkSEMI A semicolon.
@@ -123967,11 +124412,11 @@
123967 /* 6 SEMI: */ { 6, 6, 5, 5, 5, 5, 5, 7, },
123968 /* 7 END: */ { 1, 7, 5, 5, 5, 5, 5, 5, },
123969 };
123970 #else
123971 /* If triggers are not supported by this compile then the statement machine
123972 ** used to detect the end of a statement is much simplier
123973 */
123974 static const u8 trans[3][3] = {
123975 /* Token: */
123976 /* State: ** SEMI WS OTHER */
123977 /* 0 INVALID: */ { 1, 0, 2, },
@@ -125202,10 +125647,14 @@
125202 #endif
125203
125204 sqlite3Error(db, SQLITE_OK); /* Deallocates any cached error strings. */
125205 sqlite3ValueFree(db->pErr);
125206 sqlite3CloseExtensions(db);
 
 
 
 
125207
125208 db->magic = SQLITE_MAGIC_ERROR;
125209
125210 /* The temp-database schema is allocated differently from the other schema
125211 ** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
@@ -126783,11 +127232,10 @@
126783 goto opendb_out;
126784 }
126785 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
126786 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
126787
126788
126789 /* The default safety_level for the main database is 'full'; for the temp
126790 ** database it is 'NONE'. This matches the pager layer defaults.
126791 */
126792 db->aDb[0].zName = "main";
126793 db->aDb[0].safety_level = 3;
@@ -127070,13 +127518,13 @@
127070 SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
127071 return db->autoCommit;
127072 }
127073
127074 /*
127075 ** The following routines are subtitutes for constants SQLITE_CORRUPT,
127076 ** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_IOERR and possibly other error
127077 ** constants. They server two purposes:
127078 **
127079 ** 1. Serve as a convenient place to set a breakpoint in a debugger
127080 ** to detect when version error conditions occurs.
127081 **
127082 ** 2. Invoke sqlite3_log() to provide the source code location where
@@ -127386,11 +127834,11 @@
127386 ** as it existing before this routine was called.
127387 **
127388 ** IMPORTANT: Changing the PENDING byte from 0x40000000 results in
127389 ** an incompatible database file format. Changing the PENDING byte
127390 ** while any database connection is open results in undefined and
127391 ** dileterious behavior.
127392 */
127393 case SQLITE_TESTCTRL_PENDING_BYTE: {
127394 rc = PENDING_BYTE;
127395 #ifndef SQLITE_OMIT_WSD
127396 {
127397
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -73,10 +73,19 @@
73 # define _FILE_OFFSET_BITS 64
74 # endif
75 # define _LARGEFILE_SOURCE 1
76 #endif
77
78 /* Needed for various definitions... */
79 #if defined(__GNUC__) && !defined(_GNU_SOURCE)
80 # define _GNU_SOURCE
81 #endif
82
83 #if defined(__OpenBSD__) && !defined(_BSD_SOURCE)
84 # define _BSD_SOURCE
85 #endif
86
87 /*
88 ** For MinGW, check to see if we can include the header file containing its
89 ** version information, among other things. Normally, this internal MinGW
90 ** header file would [only] be included automatically by other MinGW header
91 ** files; however, the contained version information is now required by this
@@ -222,11 +231,11 @@
231 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232 ** [sqlite_version()] and [sqlite_source_id()].
233 */
234 #define SQLITE_VERSION "3.8.7"
235 #define SQLITE_VERSION_NUMBER 3008007
236 #define SQLITE_SOURCE_ID "2014-09-20 00:35:05 59e2c9df02d7e988c5ad44c560ead1e5288b12e7"
237
238 /*
239 ** CAPI3REF: Run-Time Library Version Numbers
240 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
241 **
@@ -610,10 +619,11 @@
619 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
620 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
621 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
622 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
623 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
624 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
625
626 /*
627 ** CAPI3REF: Flags For File Open Operations
628 **
629 ** These bit values are intended for use in the
@@ -2212,11 +2222,11 @@
2222 **
2223 ** ^Calling this routine with an argument less than or equal to zero
2224 ** turns off all busy handlers.
2225 **
2226 ** ^(There can only be a single busy handler for a particular
2227 ** [database connection] at any given moment. If another busy handler
2228 ** was defined (using [sqlite3_busy_handler()]) prior to calling
2229 ** this routine, that other busy handler is cleared.)^
2230 **
2231 ** See also: [PRAGMA busy_timeout]
2232 */
@@ -2415,10 +2425,14 @@
2425 ** of memory at least N bytes in length, where N is the parameter.
2426 ** ^If sqlite3_malloc() is unable to obtain sufficient free
2427 ** memory, it returns a NULL pointer. ^If the parameter N to
2428 ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
2429 ** a NULL pointer.
2430 **
2431 ** ^The sqlite3_malloc64(N) routine works just like
2432 ** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
2433 ** of a signed 32-bit integer.
2434 **
2435 ** ^Calling sqlite3_free() with a pointer previously returned
2436 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
2437 ** that it might be reused. ^The sqlite3_free() routine is
2438 ** a no-op if is called with a NULL pointer. Passing a NULL pointer
@@ -2427,28 +2441,42 @@
2441 ** memory might result in a segmentation fault or other severe error.
2442 ** Memory corruption, a segmentation fault, or other severe error
2443 ** might result if sqlite3_free() is called with a non-NULL pointer that
2444 ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
2445 **
2446 ** ^The sqlite3_realloc(X,N) interface attempts to resize a
2447 ** prior memory allocation X to be at least N bytes.
2448 ** ^If the X parameter to sqlite3_realloc(X,N)
 
2449 ** is a NULL pointer then its behavior is identical to calling
2450 ** sqlite3_malloc(N).
2451 ** ^If the N parameter to sqlite3_realloc(X,N) is zero or
2452 ** negative then the behavior is exactly the same as calling
2453 ** sqlite3_free(X).
2454 ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
2455 ** of at least N bytes in size or NULL if insufficient memory is available.
2456 ** ^If M is the size of the prior allocation, then min(N,M) bytes
2457 ** of the prior allocation are copied into the beginning of buffer returned
2458 ** by sqlite3_realloc(X,N) and the prior allocation is freed.
2459 ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
2460 ** prior allocation is not freed.
2461 **
2462 ** ^The sqlite3_realloc64(X,N) interfaces works the same as
2463 ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
2464 ** of a 32-bit signed integer.
2465 **
2466 ** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
2467 ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
2468 ** sqlite3_msize(X) returns the size of that memory allocation in bytes.
2469 ** ^The value returned by sqlite3_msize(X) might be larger than the number
2470 ** of bytes requested when X was allocated. ^If X is a NULL pointer then
2471 ** sqlite3_msize(X) returns zero. If X points to something that is not
2472 ** the beginning of memory allocation, or if it points to a formerly
2473 ** valid memory allocation that has now been freed, then the behavior
2474 ** of sqlite3_msize(X) is undefined and possibly harmful.
2475 **
2476 ** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
2477 ** sqlite3_malloc64(), and sqlite3_realloc64()
2478 ** is always aligned to at least an 8 byte boundary, or to a
2479 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
2480 ** option is used.
2481 **
2482 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
@@ -2472,12 +2500,15 @@
2500 ** The application must not read or write any part of
2501 ** a block of memory after it has been released using
2502 ** [sqlite3_free()] or [sqlite3_realloc()].
2503 */
2504 SQLITE_API void *sqlite3_malloc(int);
2505 SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
2506 SQLITE_API void *sqlite3_realloc(void*, int);
2507 SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
2508 SQLITE_API void sqlite3_free(void*);
2509 SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
2510
2511 /*
2512 ** CAPI3REF: Memory Allocator Statistics
2513 **
2514 ** SQLite provides these two interfaces for reporting on the status
@@ -3482,11 +3513,12 @@
3513 ** is negative, then the length of the string is
3514 ** the number of bytes up to the first zero terminator.
3515 ** If the fourth parameter to sqlite3_bind_blob() is negative, then
3516 ** the behavior is undefined.
3517 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3518 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
3519 ** that parameter must be the byte offset
3520 ** where the NUL terminator would occur assuming the string were NUL
3521 ** terminated. If any NUL characters occur at byte offsets less than
3522 ** the value of the fourth parameter then the resulting string value will
3523 ** contain embedded NULs. The result of expressions involving strings
3524 ** with embedded NULs is undefined.
@@ -3500,10 +3532,18 @@
3532 ** the special value [SQLITE_STATIC], then SQLite assumes that the
3533 ** information is in static, unmanaged space and does not need to be freed.
3534 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
3535 ** SQLite makes its own private copy of the data immediately, before
3536 ** the sqlite3_bind_*() routine returns.
3537 **
3538 ** ^The sixth argument to sqlite3_bind_text64() must be one of
3539 ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
3540 ** to specify the encoding of the text in the third parameter. If
3541 ** the sixth argument to sqlite3_bind_text64() is not how of the
3542 ** allowed values shown above, or if the text encoding is different
3543 ** from the encoding specified by the sixth parameter, then the behavior
3544 ** is undefined.
3545 **
3546 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
3547 ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
3548 ** (just an integer to hold its size) while it is being processed.
3549 ** Zeroblobs are intended to serve as placeholders for BLOBs whose
@@ -3521,23 +3561,30 @@
3561 ** ^Bindings are not cleared by the [sqlite3_reset()] routine.
3562 ** ^Unbound parameters are interpreted as NULL.
3563 **
3564 ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
3565 ** [error code] if anything goes wrong.
3566 ** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
3567 ** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
3568 ** [SQLITE_MAX_LENGTH].
3569 ** ^[SQLITE_RANGE] is returned if the parameter
3570 ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
3571 **
3572 ** See also: [sqlite3_bind_parameter_count()],
3573 ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
3574 */
3575 SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
3576 SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
3577 void(*)(void*));
3578 SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
3579 SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
3580 SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
3581 SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
3582 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
3583 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
3584 SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
3585 void(*)(void*), unsigned char encoding);
3586 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3587 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3588
3589 /*
3590 ** CAPI3REF: Number Of SQL Parameters
@@ -4282,11 +4329,11 @@
4329 ** These routines work only with [protected sqlite3_value] objects.
4330 ** Any attempt to use these routines on an [unprotected sqlite3_value]
4331 ** object results in undefined behavior.
4332 **
4333 ** ^These routines work just like the corresponding [column access functions]
4334 ** except that these routines take a single [protected sqlite3_value] object
4335 ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
4336 **
4337 ** ^The sqlite3_value_text16() interface extracts a UTF-16 string
4338 ** in the native byte-order of the host machine. ^The
4339 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
@@ -4525,14 +4572,18 @@
4572 **
4573 ** ^The sqlite3_result_null() interface sets the return value
4574 ** of the application-defined function to be NULL.
4575 **
4576 ** ^The sqlite3_result_text(), sqlite3_result_text16(),
4577 ** sqlite3_result_text16le(), and sqlite3_result_text16be()
4578 ** set the return value of the application-defined function to be
4579 ** a text string which is represented as UTF-8, UTF-16 native byte order,
4580 ** UTF-16 little endian, or UTF-16 big endian, respectively.
4581 ** ^The sqlite3_result_text64() interface sets the return value of an
4582 ** application-defined function to be a text string in an encoding
4583 ** specified by the fifth (and last) parameter, which must be one
4584 ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
4585 ** ^SQLite takes the text result from the application from
4586 ** the 2nd parameter of the sqlite3_result_text* interfaces.
4587 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
4588 ** is negative, then SQLite takes result text from the 2nd parameter
4589 ** through the first zero character.
@@ -4572,10 +4623,11 @@
4623 ** If these routines are called from within the different thread
4624 ** than the one containing the application-defined function that received
4625 ** the [sqlite3_context] pointer, the results are undefined.
4626 */
4627 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
4628 SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint64,void(*)(void*));
4629 SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
4630 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
4631 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
4632 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
4633 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
@@ -4582,10 +4634,12 @@
4634 SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
4635 SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
4636 SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
4637 SQLITE_API void sqlite3_result_null(sqlite3_context*);
4638 SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
4639 SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
4640 void(*)(void*), unsigned char encoding);
4641 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
4642 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
4643 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
4644 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4645 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
@@ -6475,25 +6529,25 @@
6529 ** memory already being in use.
6530 ** Only the high-water value is meaningful;
6531 ** the current value is always zero.)^
6532 **
6533 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6534 ** <dd>This parameter returns the approximate number of bytes of heap
6535 ** memory used by all pager caches associated with the database connection.)^
6536 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
6537 **
6538 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
6539 ** <dd>This parameter returns the approximate number of bytes of heap
6540 ** memory used to store the schema for all databases associated
6541 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
6542 ** ^The full amount of memory used by the schemas is reported, even if the
6543 ** schema memory is shared with other database connections due to
6544 ** [shared cache mode] being enabled.
6545 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
6546 **
6547 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
6548 ** <dd>This parameter returns the approximate number of bytes of heap
6549 ** and lookaside memory used by all prepared statements associated with
6550 ** the database connection.)^
6551 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
6552 ** </dd>
6553 **
@@ -7846,19 +7900,10 @@
7900 #pragma warn -aus /* Assigned value is never used */
7901 #pragma warn -csu /* Comparing signed and unsigned */
7902 #pragma warn -spa /* Suspicious pointer arithmetic */
7903 #endif
7904
 
 
 
 
 
 
 
 
 
7905 /*
7906 ** Include standard header files as necessary
7907 */
7908 #ifdef HAVE_STDINT_H
7909 #include <stdint.h>
@@ -8093,11 +8138,11 @@
8138 # define ALWAYS(X) (X)
8139 # define NEVER(X) (X)
8140 #endif
8141
8142 /*
8143 ** Return true (non-zero) if the input is an integer that is too large
8144 ** to fit in 32-bits. This macro is used inside of various testcase()
8145 ** macros to verify that we have tested SQLite for large-file support.
8146 */
8147 #define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0)
8148
@@ -8644,11 +8689,11 @@
8689 ** Assert that the pointer X is aligned to an 8-byte boundary. This
8690 ** macro is used only within assert() to verify that the code gets
8691 ** all alignment restrictions correct.
8692 **
8693 ** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the
8694 ** underlying malloc() implementation might return us 4-byte aligned
8695 ** pointers. In that case, only verify 4-byte alignment.
8696 */
8697 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
8698 # define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&3)==0)
8699 #else
@@ -9537,14 +9582,14 @@
9582 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
9583 #endif
9584 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
9585
9586 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
9587 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
9588 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
9589
9590 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
9591 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
9592
9593 #ifndef SQLITE_OMIT_TRIGGER
9594 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
9595 #endif
@@ -10180,11 +10225,11 @@
10225 ** SHARED_SIZE is the number of bytes available in the pool from which
10226 ** a random byte is selected for a shared lock. The pool of bytes for
10227 ** shared locks begins at SHARED_FIRST.
10228 **
10229 ** The same locking strategy and
10230 ** byte ranges are used for Unix. This leaves open the possibility of having
10231 ** clients on win95, winNT, and unix all talking to the same shared file
10232 ** and all locking correctly. To do so would require that samba (or whatever
10233 ** tool is being used for file sharing) implements locks correctly between
10234 ** windows and unix. I'm guessing that isn't likely to happen, but by
10235 ** using the same locking range we are at least open to the possibility.
@@ -10299,11 +10344,11 @@
10344
10345 /*
10346 ** Figure out what version of the code to use. The choices are
10347 **
10348 ** SQLITE_MUTEX_OMIT No mutex logic. Not even stubs. The
10349 ** mutexes implementation cannot be overridden
10350 ** at start-time.
10351 **
10352 ** SQLITE_MUTEX_NOOP For single-threaded applications. No
10353 ** mutual exclusion is provided. But this
10354 ** implementation can be overridden at
@@ -10465,10 +10510,49 @@
10510 ** Collisions are on the FuncDef.pHash chain.
10511 */
10512 struct FuncDefHash {
10513 FuncDef *a[23]; /* Hash table for functions */
10514 };
10515
10516 #ifdef SQLITE_USER_AUTHENTICATION
10517 /*
10518 ** Information held in the "sqlite3" database connection object and used
10519 ** to manage user authentication.
10520 */
10521 typedef struct sqlite3_userauth sqlite3_userauth;
10522 struct sqlite3_userauth {
10523 u8 authLevel; /* Current authentication level */
10524 int nAuthPW; /* Size of the zAuthPW in bytes */
10525 char *zAuthPW; /* Password used to authenticate */
10526 char *zAuthUser; /* User name used to authenticate */
10527 };
10528
10529 /* Allowed values for sqlite3_userauth.authLevel */
10530 #define UAUTH_Unknown 0 /* Authentication not yet checked */
10531 #define UAUTH_Fail 1 /* User authentication failed */
10532 #define UAUTH_User 2 /* Authenticated as a normal user */
10533 #define UAUTH_Admin 3 /* Authenticated as an administrator */
10534
10535 /* Functions used only by user authorization logic */
10536 SQLITE_PRIVATE int sqlite3UserAuthTable(const char*);
10537 SQLITE_PRIVATE int sqlite3UserAuthCheckLogin(sqlite3*,const char*,u8*);
10538 SQLITE_PRIVATE void sqlite3UserAuthInit(sqlite3*);
10539 SQLITE_PRIVATE void sqlite3CryptFunc(sqlite3_context*,int,sqlite3_value**);
10540
10541 #endif /* SQLITE_USER_AUTHENTICATION */
10542
10543 /*
10544 ** typedef for the authorization callback function.
10545 */
10546 #ifdef SQLITE_USER_AUTHENTICATION
10547 typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*,
10548 const char*, const char*);
10549 #else
10550 typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*,
10551 const char*);
10552 #endif
10553
10554
10555 /*
10556 ** Each database connection is an instance of the following structure.
10557 */
10558 struct sqlite3 {
@@ -10533,12 +10617,11 @@
10617 volatile int isInterrupted; /* True if sqlite3_interrupt has been called */
10618 double notUsed1; /* Spacer */
10619 } u1;
10620 Lookaside lookaside; /* Lookaside malloc configuration */
10621 #ifndef SQLITE_OMIT_AUTHORIZATION
10622 sqlite3_xauth xAuth; /* Access authorization function */
 
10623 void *pAuthArg; /* 1st argument to the access auth function */
10624 #endif
10625 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
10626 int (*xProgress)(void *); /* The progress callback */
10627 void *pProgressArg; /* Argument to the progress callback */
@@ -10560,11 +10643,10 @@
10643 int nSavepoint; /* Number of non-transaction savepoints */
10644 int nStatement; /* Number of nested statement-transactions */
10645 i64 nDeferredCons; /* Net deferred constraints this transaction. */
10646 i64 nDeferredImmCons; /* Net deferred immediate constraints */
10647 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
 
10648 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
10649 /* The following variables are all protected by the STATIC_MASTER
10650 ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
10651 **
10652 ** When X.pUnlockConnection==Y, that means that X is waiting for Y to
@@ -10578,10 +10660,13 @@
10660 sqlite3 *pUnlockConnection; /* Connection to watch for unlock */
10661 void *pUnlockArg; /* Argument to xUnlockNotify */
10662 void (*xUnlockNotify)(void **, int); /* Unlock notify callback */
10663 sqlite3 *pNextBlocked; /* Next in list of all blocked connections */
10664 #endif
10665 #ifdef SQLITE_USER_AUTHENTICATION
10666 sqlite3_userauth auth; /* User authentication information */
10667 #endif
10668 };
10669
10670 /*
10671 ** A macro to discover the encoding of a database.
10672 */
@@ -10637,11 +10722,10 @@
10722 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10723 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10724 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
10725 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
10726 #define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */
 
10727 #define SQLITE_AllOpts 0xffff /* All optimizations */
10728
10729 /*
10730 ** Macros for testing whether or not optimizations are enabled or disabled.
10731 */
@@ -10724,10 +10808,11 @@
10808 #define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
10809 #define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
10810 #define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
10811 #define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
10812 #define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */
10813 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
10814
10815 /*
10816 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
10817 ** used to create the initializers for the FuncDef structures.
10818 **
@@ -10770,10 +10855,13 @@
10855 #define LIKEFUNC(zName, nArg, arg, flags) \
10856 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
10857 (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
10858 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
10859 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
10860 SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
10861 #define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \
10862 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
10863 SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
10864
10865 /*
10866 ** All current savepoints are stored in a linked list starting at
10867 ** sqlite3.pSavepoint. The first element in the list is the most recently
@@ -10857,30 +10945,30 @@
10945 **
10946 ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
10947 ** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve
10948 ** the speed a little by numbering the values consecutively.
10949 **
10950 ** But rather than start with 0 or 1, we begin with 'A'. That way,
10951 ** when multiple affinity types are concatenated into a string and
10952 ** used as the P4 operand, they will be more readable.
10953 **
10954 ** Note also that the numeric types are grouped together so that testing
10955 ** for a numeric type is a single comparison. And the NONE type is first.
10956 */
10957 #define SQLITE_AFF_NONE 'A'
10958 #define SQLITE_AFF_TEXT 'B'
10959 #define SQLITE_AFF_NUMERIC 'C'
10960 #define SQLITE_AFF_INTEGER 'D'
10961 #define SQLITE_AFF_REAL 'E'
10962
10963 #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
10964
10965 /*
10966 ** The SQLITE_AFF_MASK values masks off the significant bits of an
10967 ** affinity value.
10968 */
10969 #define SQLITE_AFF_MASK 0x47
10970
10971 /*
10972 ** Additional bit values that can be ORed with an affinity without
10973 ** changing the affinity.
10974 **
@@ -10887,14 +10975,14 @@
10975 ** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL.
10976 ** It causes an assert() to fire if either operand to a comparison
10977 ** operator is NULL. It is added to certain comparison operators to
10978 ** prove that the operands are always NOT NULL.
10979 */
10980 #define SQLITE_JUMPIFNULL 0x10 /* jumps if either operand is NULL */
10981 #define SQLITE_STOREP2 0x20 /* Store result in reg[P2] rather than jump */
10982 #define SQLITE_NULLEQ 0x80 /* NULL=NULL */
10983 #define SQLITE_NOTNULL 0x90 /* Assert that operands are never NULL */
10984
10985 /*
10986 ** An object of this type is created for each virtual table present in
10987 ** the database schema.
10988 **
@@ -11693,21 +11781,26 @@
11781 ExprList *pEList; /* Optional list of result-set columns */
11782 AggInfo *pAggInfo; /* Information about aggregates at this level */
11783 NameContext *pNext; /* Next outer name context. NULL for outermost */
11784 int nRef; /* Number of names resolved by this context */
11785 int nErr; /* Number of errors encountered while resolving names */
11786 u16 ncFlags; /* Zero or more NC_* flags defined below */
11787 };
11788
11789 /*
11790 ** Allowed values for the NameContext, ncFlags field.
11791 **
11792 ** Note: NC_MinMaxAgg must have the same value as SF_MinMaxAgg and
11793 ** SQLITE_FUNC_MINMAX.
11794 **
11795 */
11796 #define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
11797 #define NC_HasAgg 0x0002 /* One or more aggregate functions seen */
11798 #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
11799 #define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */
11800 #define NC_PartIdx 0x0010 /* True if resolving a partial index WHERE */
11801 #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
11802
11803 /*
11804 ** An instance of the following structure contains all information
11805 ** needed to generate code for a single SELECT statement.
11806 **
@@ -11754,17 +11847,17 @@
11847 #define SF_Resolved 0x0002 /* Identifiers have been resolved */
11848 #define SF_Aggregate 0x0004 /* Contains aggregate functions */
11849 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
11850 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
11851 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
11852 #define SF_Compound 0x0040 /* Part of a compound query */
11853 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
11854 /* 0x0100 NOT USED */
11855 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
11856 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
11857 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
11858 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
11859
11860
11861 /*
11862 ** The results of a SELECT can be distributed in several ways, as defined
11863 ** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -12362,12 +12455,12 @@
12455 #define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__)
12456
12457
12458 /*
12459 ** FTS4 is really an extension for FTS3. It is enabled using the
12460 ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call
12461 ** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3.
12462 */
12463 #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3)
12464 # define SQLITE_ENABLE_FTS3
12465 #endif
12466
@@ -12410,19 +12503,19 @@
12503 SQLITE_PRIVATE int sqlite3Strlen30(const char*);
12504 #define sqlite3StrNICmp sqlite3_strnicmp
12505
12506 SQLITE_PRIVATE int sqlite3MallocInit(void);
12507 SQLITE_PRIVATE void sqlite3MallocEnd(void);
12508 SQLITE_PRIVATE void *sqlite3Malloc(u64);
12509 SQLITE_PRIVATE void *sqlite3MallocZero(u64);
12510 SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3*, u64);
12511 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3*, u64);
12512 SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3*,const char*);
12513 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64);
12514 SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
12515 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
12516 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
12517 SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
12518 SQLITE_PRIVATE int sqlite3MallocSize(void*);
12519 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
12520 SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
12521 SQLITE_PRIVATE void sqlite3ScratchFree(void*);
@@ -12959,11 +13052,11 @@
13052 #endif
13053
13054 /*
13055 ** The interface to the LEMON-generated parser
13056 */
13057 SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64));
13058 SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*));
13059 SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*);
13060 #ifdef YYTRACKMAXSTACKDEPTH
13061 SQLITE_PRIVATE int sqlite3ParserStackPeak(void*);
13062 #endif
@@ -13228,11 +13321,11 @@
13321 ** May you find forgiveness for yourself and forgive others.
13322 ** May you share freely, never taking more than you give.
13323 **
13324 *************************************************************************
13325 **
13326 ** This file contains definitions of global variables and constants.
13327 */
13328
13329 /* An array to map all upper-case characters into their corresponding
13330 ** lower-case character.
13331 **
@@ -13824,10 +13917,13 @@
13917 #if defined(SQLITE_THREADSAFE)
13918 "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
13919 #endif
13920 #ifdef SQLITE_USE_ALLOCA
13921 "USE_ALLOCA",
13922 #endif
13923 #ifdef SQLITE_USER_AUTHENTICATION
13924 "USER_AUTHENTICATION",
13925 #endif
13926 #ifdef SQLITE_WIN32_MALLOC
13927 "WIN32_MALLOC",
13928 #endif
13929 #ifdef SQLITE_ZERO_MALLOC
@@ -14052,29 +14148,32 @@
14148 ** Internally, the vdbe manipulates nearly all SQL values as Mem
14149 ** structures. Each Mem struct may cache multiple representations (string,
14150 ** integer etc.) of the same value.
14151 */
14152 struct Mem {
14153 union MemValue {
14154 double r; /* Real value used when MEM_Real is set in flags */
 
 
14155 i64 i; /* Integer value used when MEM_Int is set in flags */
14156 int nZero; /* Used when bit MEM_Zero is set in flags */
14157 FuncDef *pDef; /* Used only when flags==MEM_Agg */
14158 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
14159 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
14160 } u;
 
14161 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
14162 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
14163 int n; /* Number of characters in string value, excluding '\0' */
14164 char *z; /* String or BLOB value */
14165 /* ShallowCopy only needs to copy the information above */
14166 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
14167 int szMalloc; /* Size of the zMalloc allocation */
14168 int iPadding1; /* Padding for 8-byte alignment */
14169 sqlite3 *db; /* The associated database connection */
14170 void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
14171 #ifdef SQLITE_DEBUG
14172 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
14173 void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
14174 #endif
 
 
14175 };
14176
14177 /* One or more of the following flags are set to indicate the validOK
14178 ** representations of the value stored in the Mem struct.
14179 **
@@ -14129,11 +14228,11 @@
14228 #ifdef SQLITE_DEBUG
14229 #define memIsValid(M) ((M)->flags & MEM_Undefined)==0
14230 #endif
14231
14232 /*
14233 ** Each auxiliary data pointer stored by a user defined function
14234 ** implementation calling sqlite3_set_auxdata() is stored in an instance
14235 ** of this structure. All such structures associated with a single VM
14236 ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
14237 ** when the VM is halted (if not before).
14238 */
@@ -14144,11 +14243,11 @@
14243 void (*xDelete)(void *); /* Destructor for the aux data */
14244 AuxData *pNext; /* Next element in list */
14245 };
14246
14247 /*
14248 ** The "context" argument for an installable function. A pointer to an
14249 ** instance of this structure is the first argument to the routines used
14250 ** implement the SQL functions.
14251 **
14252 ** There is a typedef for this structure in sqlite.h. So all routines,
14253 ** even the public interface to SQLite, can use a pointer to this structure.
@@ -14158,17 +14257,17 @@
14257 ** This structure is defined inside of vdbeInt.h because it uses substructures
14258 ** (Mem) which are only defined there.
14259 */
14260 struct sqlite3_context {
14261 Mem *pOut; /* The return value is stored here */
14262 FuncDef *pFunc; /* Pointer to function information */
14263 Mem *pMem; /* Memory cell used to store aggregate context */
14264 CollSeq *pColl; /* Collating sequence */
14265 Vdbe *pVdbe; /* The VM that owns this context */
14266 int iOp; /* Instruction number of OP_Function */
14267 int isError; /* Error code returned by the function. */
14268 u8 skipFlag; /* Skip accumulator loading if true */
14269 u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */
14270 };
14271
14272 /*
14273 ** An Explain object accumulates indented output which is helpful
@@ -14287,12 +14386,12 @@
14386 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
14387 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
14388 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
14389
14390 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
14391 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*);
14392 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*);
14393 SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
14394 SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
14395 SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
14396 SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *, int);
14397 SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem*);
@@ -14305,10 +14404,11 @@
14404 #ifdef SQLITE_OMIT_FLOATING_POINT
14405 # define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
14406 #else
14407 SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double);
14408 #endif
14409 SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem*,sqlite3*,u16);
14410 SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*);
14411 SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int);
14412 SQLITE_PRIVATE void sqlite3VdbeMemSetRowSet(Mem*);
14413 SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
14414 SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8);
@@ -14319,18 +14419,16 @@
14419 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
14420 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
14421 SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8);
14422 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
14423 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
 
14424 #define VdbeMemDynamic(X) \
14425 (((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0)
 
 
14426 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
14427 SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
14428 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
14429 SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int n);
14430 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
14431 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
14432 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
14433 SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
14434
@@ -14653,11 +14751,11 @@
14751 ** calendar system.
14752 **
14753 ** 1970-01-01 00:00:00 is JD 2440587.5
14754 ** 2000-01-01 00:00:00 is JD 2451544.5
14755 **
14756 ** This implementation requires years to be expressed as a 4-digit number
14757 ** which means that only dates between 0000-01-01 and 9999-12-31 can
14758 ** be represented, even though julian day numbers allow a much wider
14759 ** range of dates.
14760 **
14761 ** The Gregorian calendar system is used for all dates and times,
@@ -16497,11 +16595,11 @@
16595 ** Like realloc(). Resize an allocation previously obtained from
16596 ** sqlite3MemMalloc().
16597 **
16598 ** For this low-level interface, we know that pPrior!=0. Cases where
16599 ** pPrior==0 while have been intercepted by higher-level routine and
16600 ** redirected to xMalloc. Similarly, we know that nByte>0 because
16601 ** cases where nByte<=0 will have been intercepted by higher-level
16602 ** routines and redirected to xFree.
16603 */
16604 static void *sqlite3MemRealloc(void *pPrior, int nByte){
16605 #ifdef SQLITE_MALLOCSIZE
@@ -17854,11 +17952,11 @@
17952 ** This memory allocator uses the following algorithm:
17953 **
17954 ** 1. All memory allocations sizes are rounded up to a power of 2.
17955 **
17956 ** 2. If two adjacent free blocks are the halves of a larger block,
17957 ** then the two blocks are coalesced into the single larger block.
17958 **
17959 ** 3. New memory is allocated from the first available free block.
17960 **
17961 ** This algorithm is described in: J. M. Robson. "Bounds for Some Functions
17962 ** Concerning Dynamic Storage Allocation". Journal of the Association for
@@ -20081,27 +20179,25 @@
20179
20180 /*
20181 ** Allocate memory. This routine is like sqlite3_malloc() except that it
20182 ** assumes the memory subsystem has already been initialized.
20183 */
20184 SQLITE_PRIVATE void *sqlite3Malloc(u64 n){
20185 void *p;
20186 if( n==0 || n>=0x7fffff00 ){
 
 
20187 /* A memory allocation of a number of bytes which is near the maximum
20188 ** signed integer value might cause an integer overflow inside of the
20189 ** xMalloc(). Hence we limit the maximum size to 0x7fffff00, giving
20190 ** 255 bytes of overhead. SQLite itself will never use anything near
20191 ** this amount. The only way to reach the limit is with sqlite3_malloc() */
20192 p = 0;
20193 }else if( sqlite3GlobalConfig.bMemstat ){
20194 sqlite3_mutex_enter(mem0.mutex);
20195 mallocWithAlarm((int)n, &p);
20196 sqlite3_mutex_leave(mem0.mutex);
20197 }else{
20198 p = sqlite3GlobalConfig.m.xMalloc((int)n);
20199 }
20200 assert( EIGHT_BYTE_ALIGNMENT(p) ); /* IMP: R-04675-44850 */
20201 return p;
20202 }
20203
@@ -20112,10 +20208,16 @@
20208 */
20209 SQLITE_API void *sqlite3_malloc(int n){
20210 #ifndef SQLITE_OMIT_AUTOINIT
20211 if( sqlite3_initialize() ) return 0;
20212 #endif
20213 return n<=0 ? 0 : sqlite3Malloc(n);
20214 }
20215 SQLITE_API void *sqlite3_malloc64(sqlite3_uint64 n){
20216 #ifndef SQLITE_OMIT_AUTOINIT
20217 if( sqlite3_initialize() ) return 0;
20218 #endif
20219 return sqlite3Malloc(n);
20220 }
20221
20222 /*
20223 ** Each thread may only have a single outstanding allocation from
@@ -20234,21 +20336,27 @@
20336 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20337 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
20338 return sqlite3GlobalConfig.m.xSize(p);
20339 }
20340 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
20341 if( db==0 ){
20342 return sqlite3MallocSize(p);
 
 
20343 }else{
20344 assert( sqlite3_mutex_held(db->mutex) );
20345 if( isLookaside(db, p) ){
20346 return db->lookaside.sz;
20347 }else{
20348 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20349 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20350 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20351 return sqlite3GlobalConfig.m.xSize(p);
20352 }
20353 }
20354 }
20355 SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
20356 return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p);
20357 }
20358
20359 /*
20360 ** Free memory previously obtained from sqlite3Malloc().
20361 */
20362 SQLITE_API void sqlite3_free(void *p){
@@ -20306,17 +20414,17 @@
20414 }
20415
20416 /*
20417 ** Change the size of an existing memory allocation
20418 */
20419 SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){
20420 int nOld, nNew, nDiff;
20421 void *pNew;
20422 if( pOld==0 ){
20423 return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */
20424 }
20425 if( nBytes==0 ){
20426 sqlite3_free(pOld); /* IMP: R-31593-10574 */
20427 return 0;
20428 }
20429 if( nBytes>=0x7fffff00 ){
20430 /* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */
@@ -20324,26 +20432,26 @@
20432 }
20433 nOld = sqlite3MallocSize(pOld);
20434 /* IMPLEMENTATION-OF: R-46199-30249 SQLite guarantees that the second
20435 ** argument to xRealloc is always a value returned by a prior call to
20436 ** xRoundup. */
20437 nNew = sqlite3GlobalConfig.m.xRoundup((int)nBytes);
20438 if( nOld==nNew ){
20439 pNew = pOld;
20440 }else if( sqlite3GlobalConfig.bMemstat ){
20441 sqlite3_mutex_enter(mem0.mutex);
20442 sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes);
20443 nDiff = nNew - nOld;
20444 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
20445 mem0.alarmThreshold-nDiff ){
20446 sqlite3MallocAlarm(nDiff);
20447 }
20448 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
20449 assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
20450 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20451 if( pNew==0 && mem0.alarmCallback ){
20452 sqlite3MallocAlarm((int)nBytes);
20453 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20454 }
20455 if( pNew ){
20456 nNew = sqlite3MallocSize(pNew);
20457 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
@@ -20362,33 +20470,40 @@
20470 */
20471 SQLITE_API void *sqlite3_realloc(void *pOld, int n){
20472 #ifndef SQLITE_OMIT_AUTOINIT
20473 if( sqlite3_initialize() ) return 0;
20474 #endif
20475 if( n<0 ) n = 0;
20476 return sqlite3Realloc(pOld, n);
20477 }
20478 SQLITE_API void *sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
20479 #ifndef SQLITE_OMIT_AUTOINIT
20480 if( sqlite3_initialize() ) return 0;
20481 #endif
20482 return sqlite3Realloc(pOld, n);
20483 }
20484
20485
20486 /*
20487 ** Allocate and zero memory.
20488 */
20489 SQLITE_PRIVATE void *sqlite3MallocZero(u64 n){
20490 void *p = sqlite3Malloc(n);
20491 if( p ){
20492 memset(p, 0, (size_t)n);
20493 }
20494 return p;
20495 }
20496
20497 /*
20498 ** Allocate and zero memory. If the allocation fails, make
20499 ** the mallocFailed flag in the connection pointer.
20500 */
20501 SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3 *db, u64 n){
20502 void *p = sqlite3DbMallocRaw(db, n);
20503 if( p ){
20504 memset(p, 0, (size_t)n);
20505 }
20506 return p;
20507 }
20508
20509 /*
@@ -20407,11 +20522,11 @@
20522 ** if( b ) a[10] = 9;
20523 **
20524 ** In other words, if a subsequent malloc (ex: "b") worked, it is assumed
20525 ** that all prior mallocs (ex: "a") worked too.
20526 */
20527 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, u64 n){
20528 void *p;
20529 assert( db==0 || sqlite3_mutex_held(db->mutex) );
20530 assert( db==0 || db->pnBytesFreed==0 );
20531 #ifndef SQLITE_OMIT_LOOKASIDE
20532 if( db ){
@@ -20451,11 +20566,11 @@
20566
20567 /*
20568 ** Resize the block of memory pointed to by p to n bytes. If the
20569 ** resize fails, set the mallocFailed flag in the connection object.
20570 */
20571 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){
20572 void *pNew = 0;
20573 assert( db!=0 );
20574 assert( sqlite3_mutex_held(db->mutex) );
20575 if( db->mallocFailed==0 ){
20576 if( p==0 ){
@@ -20472,11 +20587,11 @@
20587 }
20588 }else{
20589 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20590 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20591 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20592 pNew = sqlite3_realloc64(p, n);
20593 if( !pNew ){
20594 sqlite3MemdebugSetType(p, MEMTYPE_DB|MEMTYPE_HEAP);
20595 db->mallocFailed = 1;
20596 }
20597 sqlite3MemdebugSetType(pNew, MEMTYPE_DB |
@@ -20488,11 +20603,11 @@
20603
20604 /*
20605 ** Attempt to reallocate p. If the reallocation fails, then free p
20606 ** and set the mallocFailed flag in the database connection.
20607 */
20608 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, u64 n){
20609 void *pNew;
20610 pNew = sqlite3DbRealloc(db, p, n);
20611 if( !pNew ){
20612 sqlite3DbFree(db, p);
20613 }
@@ -20518,19 +20633,19 @@
20633 if( zNew ){
20634 memcpy(zNew, z, n);
20635 }
20636 return zNew;
20637 }
20638 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, u64 n){
20639 char *zNew;
20640 if( z==0 ){
20641 return 0;
20642 }
20643 assert( (n&0x7fffffff)==n );
20644 zNew = sqlite3DbMallocRaw(db, n+1);
20645 if( zNew ){
20646 memcpy(zNew, z, (size_t)n);
20647 zNew[n] = 0;
20648 }
20649 return zNew;
20650 }
20651
@@ -20599,10 +20714,25 @@
20714 ** This file contains code for a set of "printf"-like routines. These
20715 ** routines format strings much like the printf() from the standard C
20716 ** library, though the implementation here has enhancements to support
20717 ** SQLlite.
20718 */
20719
20720 /*
20721 ** If the strchrnul() library function is available, then set
20722 ** HAVE_STRCHRNUL. If that routine is not available, this module
20723 ** will supply its own. The built-in version is slower than
20724 ** the glibc version so the glibc version is definitely preferred.
20725 */
20726 #if !defined(HAVE_STRCHRNUL)
20727 # if defined(linux)
20728 # define HAVE_STRCHRNUL 1
20729 # else
20730 # define HAVE_STRCHRNUL 0
20731 # endif
20732 #endif
20733
20734
20735 /*
20736 ** Conversion types fall into various categories as defined by the
20737 ** following enumeration.
20738 */
@@ -20810,13 +20940,17 @@
20940 bArgList = useIntern = 0;
20941 }
20942 for(; (c=(*fmt))!=0; ++fmt){
20943 if( c!='%' ){
20944 bufpt = (char *)fmt;
20945 #if HAVE_STRCHRNUL
20946 fmt = strchrnul(fmt, '%');
20947 #else
20948 do{ fmt++; }while( *fmt && *fmt != '%' );
20949 #endif
20950 sqlite3StrAccumAppend(pAccum, bufpt, (int)(fmt - bufpt));
20951 if( *fmt==0 ) break;
20952 }
20953 if( (c=(*++fmt))==0 ){
20954 sqlite3StrAccumAppend(pAccum, "%", 1);
20955 break;
20956 }
@@ -21490,11 +21624,11 @@
21624 return z;
21625 }
21626
21627 /*
21628 ** Like sqlite3MPrintf(), but call sqlite3DbFree() on zStr after formatting
21629 ** the string and before returning. This routine is intended to be used
21630 ** to modify an existing string. For example:
21631 **
21632 ** x = sqlite3MPrintf(db, x, "prefix %s suffix", x);
21633 **
21634 */
@@ -22341,16 +22475,17 @@
22475 pMem->n = (int)(z - zOut);
22476 }
22477 *z = 0;
22478 assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
22479
22480 c = pMem->flags;
22481 sqlite3VdbeMemRelease(pMem);
22482 pMem->flags = MEM_Str|MEM_Term|(c&MEM_AffMask);
22483 pMem->enc = desiredEnc;
 
22484 pMem->z = (char*)zOut;
22485 pMem->zMalloc = pMem->z;
22486 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->z);
22487
22488 translate_out:
22489 #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
22490 {
22491 char zBuf[100];
@@ -22762,11 +22897,11 @@
22897 ** The return value is -1 if no dequoting occurs or the length of the
22898 ** dequoted string, exclusive of the zero terminator, if dequoting does
22899 ** occur.
22900 **
22901 ** 2002-Feb-14: This routine is extended to remove MS-Access style
22902 ** brackets from around identifiers. For example: "[a-b-c]" becomes
22903 ** "a-b-c".
22904 */
22905 SQLITE_PRIVATE int sqlite3Dequote(char *z){
22906 char quote;
22907 int i, j;
@@ -24872,10 +25007,18 @@
25007 # else
25008 # define HAVE_MREMAP 0
25009 # endif
25010 #endif
25011
25012 /*
25013 ** Explicitly call the 64-bit version of lseek() on Android. Otherwise, lseek()
25014 ** is the 32-bit version, even if _FILE_OFFSET_BITS=64 is defined.
25015 */
25016 #ifdef __ANDROID__
25017 # define lseek lseek64
25018 #endif
25019
25020 /*
25021 ** Different Unix systems declare open() in different ways. Same use
25022 ** open(const char*,int,mode_t). Others use open(const char*,int,...).
25023 ** The difference is important when using a pointer to the function.
25024 **
@@ -25204,11 +25347,11 @@
25347
25348
25349 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
25350 /*
25351 ** Helper function for printing out trace information from debugging
25352 ** binaries. This returns the string representation of the supplied
25353 ** integer lock-type.
25354 */
25355 static const char *azFileLock(int eFileLock){
25356 switch( eFileLock ){
25357 case NO_LOCK: return "NONE";
@@ -25281,13 +25424,26 @@
25424 #define osFcntl lockTrace
25425 #endif /* SQLITE_LOCK_TRACE */
25426
25427 /*
25428 ** Retry ftruncate() calls that fail due to EINTR
25429 **
25430 ** All calls to ftruncate() within this file should be made through this wrapper.
25431 ** On the Android platform, bypassing the logic below could lead to a corrupt
25432 ** database.
25433 */
25434 static int robust_ftruncate(int h, sqlite3_int64 sz){
25435 int rc;
25436 #ifdef __ANDROID__
25437 /* On Android, ftruncate() always uses 32-bit offsets, even if
25438 ** _FILE_OFFSET_BITS=64 is defined. This means it is unsafe to attempt to
25439 ** truncate a file to any size larger than 2GiB. Silently ignore any
25440 ** such attempts. */
25441 if( sz>(sqlite3_int64)0x7FFFFFFF ){
25442 rc = SQLITE_OK;
25443 }else
25444 #endif
25445 do{ rc = osFtruncate(h,sz); }while( rc<0 && errno==EINTR );
25446 return rc;
25447 }
25448
25449 /*
@@ -27671,11 +27827,11 @@
27827 ** bytes into pBuf. Return the number of bytes actually read.
27828 **
27829 ** NB: If you define USE_PREAD or USE_PREAD64, then it might also
27830 ** be necessary to define _XOPEN_SOURCE to be 500. This varies from
27831 ** one system to another. Since SQLite does not define USE_PREAD
27832 ** in any form by default, we will not attempt to define _XOPEN_SOURCE.
27833 ** See tickets #2741 and #2681.
27834 **
27835 ** To avoid stomping the errno value on a failed read the lastErrno value
27836 ** is set before returning.
27837 */
@@ -28168,11 +28324,11 @@
28324 */
28325 if( pFile->szChunk>0 ){
28326 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
28327 }
28328
28329 rc = robust_ftruncate(pFile->h, nByte);
28330 if( rc ){
28331 pFile->lastErrno = errno;
28332 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
28333 }else{
28334 #ifdef SQLITE_DEBUG
@@ -28303,11 +28459,11 @@
28459
28460 return SQLITE_OK;
28461 }
28462
28463 /*
28464 ** If *pArg is initially negative then this is a query. Set *pArg to
28465 ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
28466 **
28467 ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
28468 */
28469 static void unixModeBit(unixFile *pFile, unsigned char mask, int *pArg){
@@ -28510,11 +28666,11 @@
28666
28667 /*
28668 ** Return the device characteristics for the file.
28669 **
28670 ** This VFS is set up to return SQLITE_IOCAP_POWERSAFE_OVERWRITE by default.
28671 ** However, that choice is controversial since technically the underlying
28672 ** file system does not always provide powersafe overwrites. (In other
28673 ** words, after a power-loss event, parts of the file that were never
28674 ** written might end up being altered.) However, non-PSOW behavior is very,
28675 ** very rare. And asserting PSOW makes a large reduction in the amount
28676 ** of required I/O for journaling, since a lot of padding is eliminated.
@@ -29482,11 +29638,11 @@
29638 ** Most finder functions return a pointer to a fixed sqlite3_io_methods
29639 ** object. The only interesting finder-function is autolockIoFinder, which
29640 ** looks at the filesystem type and tries to guess the best locking
29641 ** strategy from that.
29642 **
29643 ** For finder-function F, two objects are created:
29644 **
29645 ** (1) The real finder-function named "FImpt()".
29646 **
29647 ** (2) A constant pointer to this function named just "F".
29648 **
@@ -29549,11 +29705,11 @@
29705 unixCheckReservedLock /* xCheckReservedLock method */
29706 )
29707 IOMETHODS(
29708 nolockIoFinder, /* Finder function name */
29709 nolockIoMethods, /* sqlite3_io_methods object name */
29710 3, /* shared memory is disabled */
29711 nolockClose, /* xClose method */
29712 nolockLock, /* xLock method */
29713 nolockUnlock, /* xUnlock method */
29714 nolockCheckReservedLock /* xCheckReservedLock method */
29715 )
@@ -29744,11 +29900,11 @@
29900 *(*const autolockIoFinder)(const char*,unixFile*) = autolockIoFinderImpl;
29901
29902 #endif /* OS_VXWORKS && SQLITE_ENABLE_LOCKING_STYLE */
29903
29904 /*
29905 ** An abstract type for a pointer to an IO method finder function:
29906 */
29907 typedef const sqlite3_io_methods *(*finder_type)(const char*,unixFile*);
29908
29909
29910 /****************************************************************************
@@ -30058,11 +30214,11 @@
30214 ** For this reason, if an error occurs in the stat() call here, it is
30215 ** ignored and -1 is returned. The caller will try to open a new file
30216 ** descriptor on the same path, fail, and return an error to SQLite.
30217 **
30218 ** Even if a subsequent open() call does succeed, the consequences of
30219 ** not searching for a reusable file descriptor are not dire. */
30220 if( 0==osStat(zPath, &sStat) ){
30221 unixInodeInfo *pInode;
30222
30223 unixEnterMutex();
30224 pInode = inodeList;
@@ -30089,11 +30245,11 @@
30245 ** to create new files with. If no error occurs, then SQLITE_OK is returned
30246 ** and a value suitable for passing as the third argument to open(2) is
30247 ** written to *pMode. If an IO error occurs, an SQLite error code is
30248 ** returned and the value of *pMode is not modified.
30249 **
30250 ** In most cases, this routine sets *pMode to 0, which will become
30251 ** an indication to robust_open() to create the file using
30252 ** SQLITE_DEFAULT_FILE_PERMISSIONS adjusted by the umask.
30253 ** But if the file being opened is a WAL or regular journal file, then
30254 ** this function queries the file-system for the permissions on the
30255 ** corresponding database file and sets *pMode to this value. Whenever
@@ -30881,11 +31037,11 @@
31037 ** by taking an sqlite-style shared lock on the conch file, reading the
31038 ** contents and comparing the host's unique host ID (see below) and lock
31039 ** proxy path against the values stored in the conch. The conch file is
31040 ** stored in the same directory as the database file and the file name
31041 ** is patterned after the database file name as ".<databasename>-conch".
31042 ** If the conch file does not exist, or its contents do not match the
31043 ** host ID and/or proxy path, then the lock is escalated to an exclusive
31044 ** lock and the conch file contents is updated with the host ID and proxy
31045 ** path and the lock is downgraded to a shared lock again. If the conch
31046 ** is held by another process (with a shared lock), the exclusive lock
31047 ** will fail and SQLITE_BUSY is returned.
@@ -30933,11 +31089,11 @@
31089 **
31090 ** As mentioned above, when compiled with SQLITE_PREFER_PROXY_LOCKING,
31091 ** setting the environment variable SQLITE_FORCE_PROXY_LOCKING to 1 will
31092 ** force proxy locking to be used for every database file opened, and 0
31093 ** will force automatic proxy locking to be disabled for all database
31094 ** files (explicitly calling the SQLITE_SET_LOCKPROXYFILE pragma or
31095 ** sqlite_file_control API is not affected by SQLITE_FORCE_PROXY_LOCKING).
31096 */
31097
31098 /*
31099 ** Proxy locking is only available on MacOSX
@@ -33571,16 +33727,18 @@
33727 #else
33728 osSleep(milliseconds);
33729 #endif
33730 }
33731
33732 #if SQLITE_MAX_WORKER_THREADS>0 && !SQLITE_OS_WINRT && SQLITE_THREADSAFE>0
33733 SQLITE_PRIVATE DWORD sqlite3Win32Wait(HANDLE hObject){
33734 DWORD rc;
33735 while( (rc = osWaitForSingleObjectEx(hObject, INFINITE,
33736 TRUE))==WAIT_IO_COMPLETION ){}
33737 return rc;
33738 }
33739 #endif
33740
33741 /*
33742 ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
33743 ** or WinCE. Return false (zero) for Win95, Win98, or WinME.
33744 **
@@ -33605,31 +33763,40 @@
33763 /*
33764 ** This function determines if the machine is running a version of Windows
33765 ** based on the NT kernel.
33766 */
33767 SQLITE_API int sqlite3_win32_is_nt(void){
33768 #if SQLITE_OS_WINRT
33769 /*
33770 ** NOTE: The WinRT sub-platform is always assumed to be based on the NT
33771 ** kernel.
33772 */
33773 return 1;
33774 #elif defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX
33775 if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){
33776 #if defined(SQLITE_WIN32_HAS_ANSI)
 
 
 
 
 
 
 
33777 OSVERSIONINFOA sInfo;
33778 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
33779 osGetVersionExA(&sInfo);
33780 osInterlockedCompareExchange(&sqlite3_os_type,
33781 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
33782 #elif defined(SQLITE_WIN32_HAS_WIDE)
33783 OSVERSIONINFOW sInfo;
33784 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
33785 osGetVersionExW(&sInfo);
33786 osInterlockedCompareExchange(&sqlite3_os_type,
33787 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
33788 #endif
33789 }
33790 return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
33791 #elif SQLITE_TEST
33792 return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
33793 #else
33794 /*
33795 ** NOTE: All sub-platforms where the GetVersionEx[AW] functions are
33796 ** deprecated are always assumed to be based on the NT kernel.
33797 */
33798 return 1;
33799 #endif
33800 }
33801
33802 #ifdef SQLITE_WIN32_MALLOC
@@ -35402,11 +35569,11 @@
35569 pFile->h, pFile->locktype, sqlite3ErrName(rc)));
35570 return rc;
35571 }
35572
35573 /*
35574 ** If *pArg is initially negative then this is a query. Set *pArg to
35575 ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
35576 **
35577 ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
35578 */
35579 static void winModeBit(winFile *pFile, unsigned char mask, int *pArg){
@@ -36416,11 +36583,11 @@
36583 if( p ){
36584 pFd->nFetchOut--;
36585 }else{
36586 /* FIXME: If Windows truly always prevents truncating or deleting a
36587 ** file while a mapping is held, then the following winUnmapfile() call
36588 ** is unnecessary can be omitted - potentially improving
36589 ** performance. */
36590 winUnmapfile(pFd);
36591 }
36592
36593 assert( pFd->nFetchOut>=0 );
@@ -38274,27 +38441,10 @@
38441 # define expensive_assert(X)
38442 #endif
38443
38444 /********************************** Linked List Management ********************/
38445
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38446 /* Allowed values for second argument to pcacheManageDirtyList() */
38447 #define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
38448 #define PCACHE_DIRTYLIST_ADD 2 /* Add pPage to the dirty list */
38449 #define PCACHE_DIRTYLIST_FRONT 3 /* Move pPage to the front of the list */
38450
@@ -38336,31 +38486,29 @@
38486 p->eCreate = 2;
38487 }
38488 }
38489 pPage->pDirtyNext = 0;
38490 pPage->pDirtyPrev = 0;
 
38491 }
38492 if( addRemove & PCACHE_DIRTYLIST_ADD ){
38493 assert( pPage->pDirtyNext==0 && pPage->pDirtyPrev==0 && p->pDirty!=pPage );
38494
38495 pPage->pDirtyNext = p->pDirty;
38496 if( pPage->pDirtyNext ){
38497 assert( pPage->pDirtyNext->pDirtyPrev==0 );
38498 pPage->pDirtyNext->pDirtyPrev = pPage;
38499 }else{
 
 
 
 
 
38500 p->pDirtyTail = pPage;
38501 if( p->bPurgeable ){
38502 assert( p->eCreate==2 );
38503 p->eCreate = 1;
38504 }
38505 }
38506 p->pDirty = pPage;
38507 if( !p->pSynced && 0==(pPage->flags&PGHDR_NEED_SYNC) ){
38508 p->pSynced = pPage;
38509 }
 
38510 }
38511 }
38512
38513 /*
38514 ** Wrapper around the pluggable caches xUnpin method. If the cache is
@@ -38533,11 +38681,10 @@
38681 /* Find a dirty page to write-out and recycle. First try to find a
38682 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
38683 ** cleared), but if that is not possible settle for any other
38684 ** unreferenced dirty page.
38685 */
 
38686 for(pPg=pCache->pSynced;
38687 pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
38688 pPg=pPg->pDirtyPrev
38689 );
38690 pCache->pSynced = pPg;
@@ -38619,20 +38766,20 @@
38766 return pPgHdr;
38767 }
38768
38769 /*
38770 ** Decrement the reference count on a page. If the page is clean and the
38771 ** reference count drops to 0, then it is made eligible for recycling.
38772 */
38773 SQLITE_PRIVATE void SQLITE_NOINLINE sqlite3PcacheRelease(PgHdr *p){
38774 assert( p->nRef>0 );
38775 p->nRef--;
38776 if( p->nRef==0 ){
38777 p->pCache->nRef--;
38778 if( (p->flags&PGHDR_DIRTY)==0 ){
38779 pcacheUnpin(p);
38780 }else if( p->pDirtyPrev!=0 ){
38781 /* Move the page to the head of the dirty list. */
38782 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
38783 }
38784 }
38785 }
@@ -38931,11 +39078,11 @@
39078 *************************************************************************
39079 **
39080 ** This file implements the default page cache implementation (the
39081 ** sqlite3_pcache interface). It also contains part of the implementation
39082 ** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features.
39083 ** If the default page cache implementation is overridden, then neither of
39084 ** these two features are available.
39085 */
39086
39087
39088 typedef struct PCache1 PCache1;
@@ -38942,11 +39089,11 @@
39089 typedef struct PgHdr1 PgHdr1;
39090 typedef struct PgFreeslot PgFreeslot;
39091 typedef struct PGroup PGroup;
39092
39093 /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
39094 ** of one or more PCaches that are able to recycle each other's unpinned
39095 ** pages when they are under memory pressure. A PGroup is an instance of
39096 ** the following object.
39097 **
39098 ** This page cache implementation works in one of two modes:
39099 **
@@ -40009,11 +40156,11 @@
40156 ** a non-zero batch number, it will see all prior INSERTs.
40157 **
40158 ** No INSERTs may occurs after a SMALLEST. An assertion will fail if
40159 ** that is attempted.
40160 **
40161 ** The cost of an INSERT is roughly constant. (Sometimes new memory
40162 ** has to be allocated on an INSERT.) The cost of a TEST with a new
40163 ** batch number is O(NlogN) where N is the number of elements in the RowSet.
40164 ** The cost of a TEST using the same batch number is O(logN). The cost
40165 ** of the first SMALLEST is O(NlogN). Second and subsequent SMALLEST
40166 ** primitives are constant time. The cost of DESTROY is O(N).
@@ -40401,12 +40548,12 @@
40548
40549 /*
40550 ** Check to see if element iRowid was inserted into the rowset as
40551 ** part of any insert batch prior to iBatch. Return 1 or 0.
40552 **
40553 ** If this is the first test of a new batch and if there exist entries
40554 ** on pRowSet->pEntry, then sort those entries into the forest at
40555 ** pRowSet->pForest so that they can be tested.
40556 */
40557 SQLITE_PRIVATE int sqlite3RowSetTest(RowSet *pRowSet, int iBatch, sqlite3_int64 iRowid){
40558 struct RowSetEntry *p, *pTree;
40559
@@ -40684,16 +40831,16 @@
40831 ** are synced prior to the master journal being deleted.
40832 **
40833 ** Definition: Two databases (or the same database at two points it time)
40834 ** are said to be "logically equivalent" if they give the same answer to
40835 ** all queries. Note in particular the content of freelist leaf
40836 ** pages can be changed arbitrarily without affecting the logical equivalence
40837 ** of the database.
40838 **
40839 ** (7) At any time, if any subset, including the empty set and the total set,
40840 ** of the unsynced changes to a rollback journal are removed and the
40841 ** journal is rolled back, the resulting database file will be logically
40842 ** equivalent to the database file at the beginning of the transaction.
40843 **
40844 ** (8) When a transaction is rolled back, the xTruncate method of the VFS
40845 ** is called to restore the database file to the same size it was at
40846 ** the beginning of the transaction. (In some VFSes, the xTruncate
@@ -40986,11 +41133,11 @@
41133 ** be a few redundant xLock() calls or a lock may be held for longer than
41134 ** required, but nothing really goes wrong.
41135 **
41136 ** The exception is when the database file is unlocked as the pager moves
41137 ** from ERROR to OPEN state. At this point there may be a hot-journal file
41138 ** in the file-system that needs to be rolled back (as part of an OPEN->SHARED
41139 ** transition, by the same pager or any other). If the call to xUnlock()
41140 ** fails at this point and the pager is left holding an EXCLUSIVE lock, this
41141 ** can confuse the call to xCheckReservedLock() call made later as part
41142 ** of hot-journal detection.
41143 **
@@ -41069,11 +41216,11 @@
41216 #define SPILLFLAG_OFF 0x01 /* Never spill cache. Set via pragma */
41217 #define SPILLFLAG_ROLLBACK 0x02 /* Current rolling back, so do not spill */
41218 #define SPILLFLAG_NOSYNC 0x04 /* Spill is ok, but do not sync */
41219
41220 /*
41221 ** An open page cache is an instance of struct Pager. A description of
41222 ** some of the more important member variables follows:
41223 **
41224 ** eState
41225 **
41226 ** The current 'state' of the pager object. See the comment and state
@@ -41241,11 +41388,11 @@
41388 u8 readOnly; /* True for a read-only database */
41389 u8 memDb; /* True to inhibit all file I/O */
41390
41391 /**************************************************************************
41392 ** The following block contains those class members that change during
41393 ** routine operation. Class members not in this block are either fixed
41394 ** when the pager is first created or else only change when there is a
41395 ** significant mode change (such as changing the page_size, locking_mode,
41396 ** or the journal_mode). From another view, these class members describe
41397 ** the "state" of the pager, while other class members describe the
41398 ** "configuration" of the pager.
@@ -43036,11 +43183,11 @@
43183 ** journal files extracted from regular rollback-journals.
43184 */
43185 rc = sqlite3OsFileSize(pMaster, &nMasterJournal);
43186 if( rc!=SQLITE_OK ) goto delmaster_out;
43187 nMasterPtr = pVfs->mxPathname+1;
43188 zMasterJournal = sqlite3Malloc(nMasterJournal + nMasterPtr + 1);
43189 if( !zMasterJournal ){
43190 rc = SQLITE_NOMEM;
43191 goto delmaster_out;
43192 }
43193 zMasterPtr = &zMasterJournal[nMasterJournal+1];
@@ -43105,11 +43252,11 @@
43252 ** DBMOD or OPEN state, this function is a no-op. Otherwise, the size
43253 ** of the file is changed to nPage pages (nPage*pPager->pageSize bytes).
43254 ** If the file on disk is currently larger than nPage pages, then use the VFS
43255 ** xTruncate() method to truncate it.
43256 **
43257 ** Or, it might be the case that the file on disk is smaller than
43258 ** nPage pages. Some operating system implementations can get confused if
43259 ** you try to truncate a file to some size that is larger than it
43260 ** currently is, so detect this case and write a single zero byte to
43261 ** the end of the new file instead.
43262 **
@@ -43164,11 +43311,11 @@
43311 }
43312
43313 /*
43314 ** Set the value of the Pager.sectorSize variable for the given
43315 ** pager based on the value returned by the xSectorSize method
43316 ** of the open database file. The sector size will be used
43317 ** to determine the size and alignment of journal header and
43318 ** master journal pointers within created journal files.
43319 **
43320 ** For temporary files the effective sector size is always 512 bytes.
43321 **
@@ -44226,16 +44373,18 @@
44373 if( !pNew ) rc = SQLITE_NOMEM;
44374 }
44375
44376 if( rc==SQLITE_OK ){
44377 pager_reset(pPager);
 
 
44378 sqlite3PageFree(pPager->pTmpSpace);
44379 pPager->pTmpSpace = pNew;
44380 rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
44381 }
44382 if( rc==SQLITE_OK ){
44383 pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
44384 pPager->pageSize = pageSize;
44385 }
44386 }
44387
44388 *pPageSize = pPager->pageSize;
44389 if( rc==SQLITE_OK ){
44390 if( nReserve<0 ) nReserve = pPager->nReserve;
@@ -44364,11 +44513,11 @@
44513 */
44514 static int pager_wait_on_lock(Pager *pPager, int locktype){
44515 int rc; /* Return code */
44516
44517 /* Check that this is either a no-op (because the requested lock is
44518 ** already held), or one of the transitions that the busy-handler
44519 ** may be invoked during, according to the comment above
44520 ** sqlite3PagerSetBusyhandler().
44521 */
44522 assert( (pPager->eLock>=locktype)
44523 || (pPager->eLock==NO_LOCK && locktype==SHARED_LOCK)
@@ -44992,11 +45141,11 @@
45141 ** The doNotSpill ROLLBACK and OFF bits inhibits all cache spilling
45142 ** regardless of whether or not a sync is required. This is set during
45143 ** a rollback or by user request, respectively.
45144 **
45145 ** Spilling is also prohibited when in an error state since that could
45146 ** lead to database corruption. In the current implementation it
45147 ** is impossible for sqlite3PcacheFetch() to be called with createFlag==3
45148 ** while in the error state, hence it is impossible for this routine to
45149 ** be called in the error state. Nevertheless, we include a NEVER()
45150 ** test for the error state as a safeguard against future changes.
45151 */
@@ -45532,11 +45681,11 @@
45681 sqlite3OsClose(pPager->jfd);
45682 }
45683 *pExists = (first!=0);
45684 }else if( rc==SQLITE_CANTOPEN ){
45685 /* If we cannot open the rollback journal file in order to see if
45686 ** it has a zero header, that might be due to an I/O error, or
45687 ** it might be due to the race condition described above and in
45688 ** ticket #3883. Either way, assume that the journal is hot.
45689 ** This might be a false positive. But if it is, then the
45690 ** automatic journal playback and recovery mechanism will deal
45691 ** with it under an EXCLUSIVE lock where we do not need to
@@ -47836,11 +47985,11 @@
47985 ** frames, return the size in bytes of the page images stored within the
47986 ** WAL frames. Otherwise, if this is not a WAL database or the WAL file
47987 ** is empty, return 0.
47988 */
47989 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){
47990 assert( pPager->eState>=PAGER_READER );
47991 return sqlite3WalFramesize(pPager->pWal);
47992 }
47993 #endif
47994
47995 #endif /* SQLITE_OMIT_DISKIO */
@@ -48420,11 +48569,11 @@
48569
48570 /*
48571 ** The argument to this macro must be of type u32. On a little-endian
48572 ** architecture, it returns the u32 value that results from interpreting
48573 ** the 4 bytes as a big-endian value. On a big-endian architecture, it
48574 ** returns the value that would be produced by interpreting the 4 bytes
48575 ** of the input value as a little-endian integer.
48576 */
48577 #define BYTESWAP32(x) ( \
48578 (((x)&0x000000FF)<<24) + (((x)&0x0000FF00)<<8) \
48579 + (((x)&0x00FF0000)>>8) + (((x)&0xFF000000)>>24) \
@@ -48834,11 +48983,11 @@
48983
48984 idx = iFrame - iZero;
48985 assert( idx <= HASHTABLE_NSLOT/2 + 1 );
48986
48987 /* If this is the first entry to be added to this hash-table, zero the
48988 ** entire hash table and aPgno[] array before proceeding.
48989 */
48990 if( idx==1 ){
48991 int nByte = (int)((u8 *)&aHash[HASHTABLE_NSLOT] - (u8 *)&aPgno[1]);
48992 memset((void*)&aPgno[1], 0, nByte);
48993 }
@@ -49492,11 +49641,11 @@
49641 ** WAL content is copied into the database file. This second fsync makes
49642 ** it safe to delete the WAL since the new content will persist in the
49643 ** database file.
49644 **
49645 ** This routine uses and updates the nBackfill field of the wal-index header.
49646 ** This is the only routine that will increase the value of nBackfill.
49647 ** (A WAL reset or recovery will revert nBackfill to zero, but not increase
49648 ** its value.)
49649 **
49650 ** The caller must be holding sufficient locks to ensure that no other
49651 ** checkpoint is running (in any other thread or process) at the same
@@ -49796,11 +49945,11 @@
49945 ** Read the wal-index header from the wal-index and into pWal->hdr.
49946 ** If the wal-header appears to be corrupt, try to reconstruct the
49947 ** wal-index from the WAL before returning.
49948 **
49949 ** Set *pChanged to 1 if the wal-index header value in pWal->hdr is
49950 ** changed by this operation. If pWal->hdr is unchanged, set *pChanged
49951 ** to 0.
49952 **
49953 ** If the wal-index header is successfully read, return SQLITE_OK.
49954 ** Otherwise an SQLite error code.
49955 */
@@ -50000,11 +50149,11 @@
50149 if( memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr)) ){
50150 /* It is not safe to allow the reader to continue here if frames
50151 ** may have been appended to the log before READ_LOCK(0) was obtained.
50152 ** When holding READ_LOCK(0), the reader ignores the entire log file,
50153 ** which implies that the database file contains a trustworthy
50154 ** snapshot. Since holding READ_LOCK(0) prevents a checkpoint from
50155 ** happening, this is usually correct.
50156 **
50157 ** However, if frames have been appended to the log (or if the log
50158 ** is wrapped and written for that matter) before the READ_LOCK(0)
50159 ** is obtained, that is not necessarily true. A checkpointer may
@@ -50668,11 +50817,11 @@
50817 /* If this is the end of a transaction, then we might need to pad
50818 ** the transaction and/or sync the WAL file.
50819 **
50820 ** Padding and syncing only occur if this set of frames complete a
50821 ** transaction and if PRAGMA synchronous=FULL. If synchronous==NORMAL
50822 ** or synchronous==OFF, then no padding or syncing are needed.
50823 **
50824 ** If SQLITE_IOCAP_POWERSAFE_OVERWRITE is defined, then padding is not
50825 ** needed and only the sync is done. If padding is needed, then the
50826 ** final frame is repeated (with its commit mark) until the next sector
50827 ** boundary is crossed. Only the part of the WAL prior to the last
@@ -50971,11 +51120,11 @@
51120 ** May you do good and not evil.
51121 ** May you find forgiveness for yourself and forgive others.
51122 ** May you share freely, never taking more than you give.
51123 **
51124 *************************************************************************
51125 ** This file implements an external (disk-based) database using BTrees.
51126 ** For a detailed discussion of BTrees, refer to
51127 **
51128 ** Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
51129 ** "Sorting And Searching", pages 473-480. Addison-Wesley
51130 ** Publishing Company, Reading, Massachusetts.
@@ -51097,11 +51246,11 @@
51246 ** 7 1 number of fragmented free bytes
51247 ** 8 4 Right child (the Ptr(N) value). Omitted on leaves.
51248 **
51249 ** The flags define the format of this btree page. The leaf flag means that
51250 ** this page has no children. The zerodata flag means that this page carries
51251 ** only keys and no data. The intkey flag means that the key is an integer
51252 ** which is stored in the key size entry of the cell header rather than in
51253 ** the payload area.
51254 **
51255 ** The cell pointer array begins on the first byte after the page header.
51256 ** The cell pointer array contains zero or more 2-byte numbers which are
@@ -51505,11 +51654,11 @@
51654 ** in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in
51655 ** this state, restoreCursorPosition() can be called to attempt to
51656 ** seek the cursor to the saved position.
51657 **
51658 ** CURSOR_FAULT:
51659 ** An unrecoverable error (an I/O error or a malloc failure) has occurred
51660 ** on a different connection that shares the BtShared cache with this
51661 ** cursor. The error has left the cache in an inconsistent state.
51662 ** Do nothing else with this cursor. Any attempt to use the cursor
51663 ** should return the error code stored in BtCursor.skip
51664 */
@@ -51722,11 +51871,11 @@
51871 */
51872 static void SQLITE_NOINLINE btreeLockCarefully(Btree *p){
51873 Btree *pLater;
51874
51875 /* In most cases, we should be able to acquire the lock we
51876 ** want without having to go through the ascending lock
51877 ** procedure that follows. Just be sure not to block.
51878 */
51879 if( sqlite3_mutex_try(p->pBt->mutex)==SQLITE_OK ){
51880 p->pBt->db = p->db;
51881 p->locked = 1;
@@ -51928,11 +52077,11 @@
52077 ** May you do good and not evil.
52078 ** May you find forgiveness for yourself and forgive others.
52079 ** May you share freely, never taking more than you give.
52080 **
52081 *************************************************************************
52082 ** This file implements an external (disk-based) database using BTrees.
52083 ** See the header comment on "btreeInt.h" for additional information.
52084 ** Including a description of file format and an overview of operation.
52085 */
52086
52087 /*
@@ -52524,11 +52673,11 @@
52673 ** all that is required. Otherwise, if pCur is not open on an intKey
52674 ** table, then malloc space for and store the pCur->nKey bytes of key
52675 ** data.
52676 */
52677 if( 0==pCur->apPage[0]->intKey ){
52678 void *pKey = sqlite3Malloc( pCur->nKey );
52679 if( pKey ){
52680 rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey);
52681 if( rc==SQLITE_OK ){
52682 pCur->pKey = pKey;
52683 }else{
@@ -53062,11 +53211,11 @@
53211 ** big FreeBlk that occurs in between the header and cell
53212 ** pointer array and the cell content area.
53213 */
53214 static int defragmentPage(MemPage *pPage){
53215 int i; /* Loop counter */
53216 int pc; /* Address of the i-th cell */
53217 int hdr; /* Offset to the page header */
53218 int size; /* Size of a cell */
53219 int usableSize; /* Number of usable bytes on a page */
53220 int cellOffset; /* Offset to the cell pointer array */
53221 int cbrk; /* Offset to the cell content area */
@@ -54519,11 +54668,11 @@
54668 **
54669 ** Only write cursors are counted if wrOnly is true. If wrOnly is
54670 ** false then all cursors are counted.
54671 **
54672 ** For the purposes of this routine, a cursor is any cursor that
54673 ** is capable of reading or writing to the database. Cursors that
54674 ** have been tripped into the CURSOR_FAULT state are not counted.
54675 */
54676 static int countValidCursors(BtShared *pBt, int wrOnly){
54677 BtCursor *pCur;
54678 int r = 0;
@@ -54983,19 +55132,19 @@
55132 ** Perform a single step of an incremental-vacuum. If successful, return
55133 ** SQLITE_OK. If there is no work to do (and therefore no point in
55134 ** calling this function again), return SQLITE_DONE. Or, if an error
55135 ** occurs, return some other error code.
55136 **
55137 ** More specifically, this function attempts to re-organize the database so
55138 ** that the last page of the file currently in use is no longer in use.
55139 **
55140 ** Parameter nFin is the number of pages that this database would contain
55141 ** were this function called until it returns SQLITE_DONE.
55142 **
55143 ** If the bCommit parameter is non-zero, this function assumes that the
55144 ** caller will keep calling incrVacuumStep() until it returns SQLITE_DONE
55145 ** or an error. bCommit is passed true for an auto-vacuum-on-commit
55146 ** operation, or false for an incremental vacuum.
55147 */
55148 static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg, int bCommit){
55149 Pgno nFreeList; /* Number of pages still on the free-list */
55150 int rc;
@@ -55458,11 +55607,11 @@
55607 sqlite3BtreeLeave(p);
55608 return rc;
55609 }
55610
55611 /*
55612 ** Start a statement subtransaction. The subtransaction can be rolled
55613 ** back independently of the main transaction. You must start a transaction
55614 ** before starting a subtransaction. The subtransaction is ended automatically
55615 ** if the main transaction commits or rolls back.
55616 **
55617 ** Statement subtransactions are used around individual SQL statements
@@ -55692,11 +55841,11 @@
55841 **
55842 ** 2007-06-25: There is a bug in some versions of MSVC that cause the
55843 ** compiler to crash when getCellInfo() is implemented as a macro.
55844 ** But there is a measureable speed advantage to using the macro on gcc
55845 ** (when less compiler optimizations like -Os or -O0 are used and the
55846 ** compiler is not doing aggressive inlining.) So we use a real function
55847 ** for MSVC and a macro for everything else. Ticket #2457.
55848 */
55849 #ifndef NDEBUG
55850 static void assertCellInfo(BtCursor *pCur){
55851 CellInfo info;
@@ -55909,11 +56058,11 @@
56058 ** The content being read or written might appear on the main page
56059 ** or be scattered out on multiple overflow pages.
56060 **
56061 ** If the current cursor entry uses one or more overflow pages and the
56062 ** eOp argument is not 2, this function may allocate space for and lazily
56063 ** populates the overflow page-list cache array (BtCursor.aOverflow).
56064 ** Subsequent calls use this cache to make seeking to the supplied offset
56065 ** more efficient.
56066 **
56067 ** Once an overflow page-list cache has been allocated, it may be
56068 ** invalidated if some other cursor writes to the same table, or if
@@ -56111,11 +56260,11 @@
56260 return rc;
56261 }
56262
56263 /*
56264 ** Read part of the key associated with cursor pCur. Exactly
56265 ** "amt" bytes will be transferred into pBuf[]. The transfer
56266 ** begins at "offset".
56267 **
56268 ** The caller must ensure that pCur is pointing to a valid row
56269 ** in the table.
56270 **
@@ -56664,18 +56813,18 @@
56813 if( nCell<=pPage->max1bytePayload ){
56814 /* This branch runs if the record-size field of the cell is a
56815 ** single byte varint and the record fits entirely on the main
56816 ** b-tree page. */
56817 testcase( pCell+nCell+1==pPage->aDataEnd );
56818 c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
56819 }else if( !(pCell[1] & 0x80)
56820 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
56821 ){
56822 /* The record-size field is a 2 byte varint and the record
56823 ** fits entirely on the main b-tree page. */
56824 testcase( pCell+nCell+2==pPage->aDataEnd );
56825 c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
56826 }else{
56827 /* The record flows over onto one or more overflow pages. In
56828 ** this case the whole cell needs to be parsed, a buffer allocated
56829 ** and accessPayload() used to retrieve the record into the
56830 ** buffer before VdbeRecordCompare() can be called. */
@@ -56692,11 +56841,11 @@
56841 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 2);
56842 if( rc ){
56843 sqlite3_free(pCellKey);
56844 goto moveto_finish;
56845 }
56846 c = xRecordCompare(nCell, pCellKey, pIdxKey);
56847 sqlite3_free(pCellKey);
56848 }
56849 assert(
56850 (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
56851 && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
@@ -57807,11 +57956,11 @@
57956 /*
57957 ** Add a list of cells to a page. The page should be initially empty.
57958 ** The cells are guaranteed to fit on the page.
57959 */
57960 static void assemblePage(
57961 MemPage *pPage, /* The page to be assembled */
57962 int nCell, /* The number of cells to add to this page */
57963 u8 **apCell, /* Pointers to cell bodies */
57964 u16 *aSize /* Sizes of the cells */
57965 ){
57966 int i; /* Loop counter */
@@ -58473,11 +58622,11 @@
58622 apOld[i] = 0;
58623 i++;
58624 }
58625
58626 /*
58627 ** Put the new pages in ascending order. This helps to
58628 ** keep entries in the disk file in order so that a scan
58629 ** of the table is a linear scan through the file. That
58630 ** in turn helps the operating system to deliver pages
58631 ** from the disk more rapidly.
58632 **
@@ -58868,11 +59017,11 @@
59017 && pParent->nCell==iIdx
59018 ){
59019 /* Call balance_quick() to create a new sibling of pPage on which
59020 ** to store the overflow cell. balance_quick() inserts a new cell
59021 ** into pParent, which may cause pParent overflow. If this
59022 ** happens, the next iteration of the do-loop will balance pParent
59023 ** use either balance_nonroot() or balance_deeper(). Until this
59024 ** happens, the overflow cell is stored in the aBalanceQuickSpace[]
59025 ** buffer.
59026 **
59027 ** The purpose of the following assert() is to check that only a
@@ -58945,11 +59094,11 @@
59094 **
59095 ** If the seekResult parameter is non-zero, then a successful call to
59096 ** MovetoUnpacked() to seek cursor pCur to (pKey, nKey) has already
59097 ** been performed. seekResult is the search result returned (a negative
59098 ** number if pCur points at an entry that is smaller than (pKey, nKey), or
59099 ** a positive value if pCur points at an entry that is larger than
59100 ** (pKey, nKey)).
59101 **
59102 ** If the seekResult parameter is non-zero, then the caller guarantees that
59103 ** cursor pCur is pointing at the existing copy of a row that is to be
59104 ** overwritten. If the seekResult parameter is 0, then cursor pCur may
@@ -59102,11 +59251,11 @@
59251 return rc;
59252 }
59253
59254 /*
59255 ** Delete the entry that the cursor is pointing to. The cursor
59256 ** is left pointing at an arbitrary location.
59257 */
59258 SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur){
59259 Btree *p = pCur->pBtree;
59260 BtShared *pBt = p->pBt;
59261 int rc; /* Return code */
@@ -59800,11 +59949,11 @@
59949
59950
59951 /*
59952 ** Add 1 to the reference count for page iPage. If this is the second
59953 ** reference to the page, add an error message to pCheck->zErrMsg.
59954 ** Return 1 if there are 2 or more references to the page and 0 if
59955 ** if this is the first reference to the page.
59956 **
59957 ** Also check that the page number is in bounds.
59958 */
59959 static int checkRef(IntegrityCk *pCheck, Pgno iPage, char *zContext){
@@ -61307,33 +61456,41 @@
61456 **
61457 ** This routine is intended for use inside of assert() statements, like
61458 ** this: assert( sqlite3VdbeCheckMemInvariants(pMem) );
61459 */
61460 SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem *p){
61461 /* If MEM_Dyn is set then Mem.xDel!=0.
61462 ** Mem.xDel is might not be initialized if MEM_Dyn is clear.
61463 */
61464 assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
61465
61466 /* MEM_Dyn may only be set if Mem.szMalloc==0 */
61467 assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
61468
61469 /* Cannot be both MEM_Int and MEM_Real at the same time */
61470 assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
61471
61472 /* The szMalloc field holds the correct memory allocation size */
61473 assert( p->szMalloc==0
61474 || p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
61475
61476 /* If p holds a string or blob, the Mem.z must point to exactly
61477 ** one of the following:
61478 **
61479 ** (1) Memory in Mem.zMalloc and managed by the Mem object
61480 ** (2) Memory to be freed using Mem.xDel
61481 ** (3) An ephemeral string or blob
61482 ** (4) A static string or blob
61483 */
61484 if( (p->flags & (MEM_Str|MEM_Blob)) && p->n>0 ){
61485 assert(
61486 ((p->szMalloc>0 && p->z==p->zMalloc)? 1 : 0) +
61487 ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
61488 ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
61489 ((p->flags&MEM_Static)!=0 ? 1 : 0) == 1
61490 );
61491 }
 
61492 return 1;
61493 }
61494 #endif
61495
61496
@@ -61383,33 +61540,37 @@
61540 ** If the bPreserve argument is true, then copy of the content of
61541 ** pMem->z into the new allocation. pMem must be either a string or
61542 ** blob if bPreserve is true. If bPreserve is false, any prior content
61543 ** in pMem->z is discarded.
61544 */
61545 SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
61546 assert( sqlite3VdbeCheckMemInvariants(pMem) );
61547 assert( (pMem->flags&MEM_RowSet)==0 );
61548
61549 /* If the bPreserve flag is set to true, then the memory cell must already
61550 ** contain a valid string or blob value. */
61551 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
61552 testcase( bPreserve && pMem->z==0 );
61553
61554 assert( pMem->szMalloc==0
61555 || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
61556 if( pMem->szMalloc<n ){
61557 if( n<32 ) n = 32;
61558 if( bPreserve && pMem->szMalloc>0 && pMem->z==pMem->zMalloc ){
61559 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
61560 bPreserve = 0;
61561 }else{
61562 if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
61563 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
61564 }
61565 if( pMem->zMalloc==0 ){
61566 sqlite3VdbeMemSetNull(pMem);
61567 pMem->z = 0;
61568 pMem->szMalloc = 0;
61569 return SQLITE_NOMEM;
61570 }else{
61571 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
61572 }
61573 }
61574
61575 if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
61576 memcpy(pMem->zMalloc, pMem->z, pMem->n);
@@ -61419,29 +61580,50 @@
61580 pMem->xDel((void *)(pMem->z));
61581 }
61582
61583 pMem->z = pMem->zMalloc;
61584 pMem->flags &= ~(MEM_Dyn|MEM_Ephem|MEM_Static);
 
61585 return SQLITE_OK;
61586 }
61587
61588 /*
61589 ** Change the pMem->zMalloc allocation to be at least szNew bytes.
61590 ** If pMem->zMalloc already meets or exceeds the requested size, this
61591 ** routine is a no-op.
61592 **
61593 ** Any prior string or blob content in the pMem object may be discarded.
61594 ** The pMem->xDel destructor is called, if it exists. Though MEM_Str
61595 ** and MEM_Blob values may be discarded, MEM_Int, MEM_Real, and MEM_Null
61596 ** values are preserved.
61597 **
61598 ** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
61599 ** if unable to complete the resizing.
61600 */
61601 SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
61602 assert( szNew>=0 );
61603 if( pMem->szMalloc<szNew ){
61604 return sqlite3VdbeMemGrow(pMem, szNew, 0);
61605 }
61606 assert( (pMem->flags & MEM_Dyn)==0 );
61607 pMem->z = pMem->zMalloc;
61608 pMem->flags &= (MEM_Null|MEM_Int|MEM_Real);
61609 return SQLITE_OK;
61610 }
61611
61612 /*
61613 ** Change pMem so that its MEM_Str or MEM_Blob value is stored in
61614 ** MEM.zMalloc, where it can be safely written.
61615 **
61616 ** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
61617 */
61618 SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem *pMem){
61619 int f;
61620 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61621 assert( (pMem->flags&MEM_RowSet)==0 );
61622 ExpandBlob(pMem);
61623 f = pMem->flags;
61624 if( (f&(MEM_Str|MEM_Blob)) && (pMem->szMalloc==0 || pMem->z!=pMem->zMalloc) ){
61625 if( sqlite3VdbeMemGrow(pMem, pMem->n + 2, 1) ){
61626 return SQLITE_NOMEM;
61627 }
61628 pMem->z[pMem->n] = 0;
61629 pMem->z[pMem->n+1] = 0;
@@ -61521,11 +61703,11 @@
61703 **
61704 ** A MEM_Null value will never be passed to this function. This function is
61705 ** used for converting values to text for returning to the user (i.e. via
61706 ** sqlite3_value_text()), or for ensuring that values to be used as btree
61707 ** keys are strings. In the former case a NULL pointer is returned the
61708 ** user and the latter is an internal programming error.
61709 */
61710 SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem *pMem, u8 enc, u8 bForce){
61711 int fg = pMem->flags;
61712 const int nByte = 32;
61713
@@ -61535,11 +61717,11 @@
61717 assert( fg&(MEM_Int|MEM_Real) );
61718 assert( (pMem->flags&MEM_RowSet)==0 );
61719 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
61720
61721
61722 if( sqlite3VdbeMemClearAndResize(pMem, nByte) ){
61723 return SQLITE_NOMEM;
61724 }
61725
61726 /* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8
61727 ** string representation of the value. Then, if the required encoding
@@ -61549,11 +61731,11 @@
61731 */
61732 if( fg & MEM_Int ){
61733 sqlite3_snprintf(nByte, pMem->z, "%lld", pMem->u.i);
61734 }else{
61735 assert( fg & MEM_Real );
61736 sqlite3_snprintf(nByte, pMem->z, "%!.15g", pMem->u.r);
61737 }
61738 pMem->n = sqlite3Strlen30(pMem->z);
61739 pMem->enc = SQLITE_UTF8;
61740 pMem->flags |= MEM_Str|MEM_Term;
61741 if( bForce ) pMem->flags &= ~(MEM_Int|MEM_Real);
@@ -61582,76 +61764,83 @@
61764 t.db = pMem->db;
61765 ctx.pOut = &t;
61766 ctx.pMem = pMem;
61767 ctx.pFunc = pFunc;
61768 pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
61769 assert( (pMem->flags & MEM_Dyn)==0 );
61770 if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
61771 memcpy(pMem, &t, sizeof(t));
61772 rc = ctx.isError;
61773 }
61774 return rc;
61775 }
61776
61777 /*
61778 ** If the memory cell contains a value that must be freed by
61779 ** invoking the external callback in Mem.xDel, then this routine
61780 ** will free that value. It also sets Mem.flags to MEM_Null.
61781 **
61782 ** This is a helper routine for sqlite3VdbeMemSetNull() and
61783 ** for sqlite3VdbeMemRelease(). Use those other routines as the
61784 ** entry point for releasing Mem resources.
61785 */
61786 static SQLITE_NOINLINE void vdbeMemClearExternAndSetNull(Mem *p){
61787 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
61788 assert( VdbeMemDynamic(p) );
61789 if( p->flags&MEM_Agg ){
61790 sqlite3VdbeMemFinalize(p, p->u.pDef);
61791 assert( (p->flags & MEM_Agg)==0 );
61792 testcase( p->flags & MEM_Dyn );
61793 }
61794 if( p->flags&MEM_Dyn ){
61795 assert( (p->flags&MEM_RowSet)==0 );
61796 assert( p->xDel!=SQLITE_DYNAMIC && p->xDel!=0 );
61797 p->xDel((void *)p->z);
 
61798 }else if( p->flags&MEM_RowSet ){
61799 sqlite3RowSetClear(p->u.pRowSet);
61800 }else if( p->flags&MEM_Frame ){
61801 VdbeFrame *pFrame = p->u.pFrame;
61802 pFrame->pParent = pFrame->v->pDelFrame;
61803 pFrame->v->pDelFrame = pFrame;
61804 }
61805 p->flags = MEM_Null;
61806 }
61807
61808 /*
61809 ** Release memory held by the Mem p, both external memory cleared
61810 ** by p->xDel and memory in p->zMalloc.
61811 **
61812 ** This is a helper routine invoked by sqlite3VdbeMemRelease() in
61813 ** the unusual case where there really is memory in p that needs
61814 ** to be freed.
61815 */
61816 static SQLITE_NOINLINE void vdbeMemClear(Mem *p){
61817 if( VdbeMemDynamic(p) ){
61818 vdbeMemClearExternAndSetNull(p);
61819 }
61820 if( p->szMalloc ){
61821 sqlite3DbFree(p->db, p->zMalloc);
61822 p->szMalloc = 0;
61823 }
61824 p->z = 0;
61825 }
61826
61827 /*
61828 ** Release any memory resources held by the Mem. Both the memory that is
61829 ** free by Mem.xDel and the Mem.zMalloc allocation are freed.
61830 **
61831 ** Use this routine prior to clean up prior to abandoning a Mem, or to
61832 ** reset a Mem back to its minimum memory utilization.
61833 **
61834 ** Use sqlite3VdbeMemSetNull() to release just the Mem.xDel space
61835 ** prior to inserting new content into the Mem.
61836 */
61837 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
61838 assert( sqlite3VdbeCheckMemInvariants(p) );
61839 if( VdbeMemDynamic(p) || p->szMalloc ){
61840 vdbeMemClear(p);
 
 
61841 }
 
61842 }
61843
61844 /*
61845 ** Convert a 64-bit IEEE double into a 64-bit signed integer.
61846 ** If the double is out of range of a 64-bit signed integer then
@@ -61686,11 +61875,11 @@
61875 ** Return some kind of integer value which is the best we can do
61876 ** at representing the value that *pMem describes as an integer.
61877 ** If pMem is an integer, then the value is exact. If pMem is
61878 ** a floating-point then the value returned is the integer part.
61879 ** If pMem is a string or blob, then we make an attempt to convert
61880 ** it into an integer and return that. If pMem represents an
61881 ** an SQL-NULL value, return 0.
61882 **
61883 ** If pMem represents a string value, its encoding might be changed.
61884 */
61885 SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *pMem){
@@ -61699,11 +61888,11 @@
61888 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
61889 flags = pMem->flags;
61890 if( flags & MEM_Int ){
61891 return pMem->u.i;
61892 }else if( flags & MEM_Real ){
61893 return doubleToInt64(pMem->u.r);
61894 }else if( flags & (MEM_Str|MEM_Blob) ){
61895 i64 value = 0;
61896 assert( pMem->z || pMem->n==0 );
61897 sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
61898 return value;
@@ -61720,11 +61909,11 @@
61909 */
61910 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
61911 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61912 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
61913 if( pMem->flags & MEM_Real ){
61914 return pMem->u.r;
61915 }else if( pMem->flags & MEM_Int ){
61916 return (double)pMem->u.i;
61917 }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
61918 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
61919 double val = (double)0;
@@ -61739,16 +61928,17 @@
61928 /*
61929 ** The MEM structure is already a MEM_Real. Try to also make it a
61930 ** MEM_Int if we can.
61931 */
61932 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem *pMem){
61933 i64 ix;
61934 assert( pMem->flags & MEM_Real );
61935 assert( (pMem->flags & MEM_RowSet)==0 );
61936 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61937 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
61938
61939 ix = doubleToInt64(pMem->u.r);
61940
61941 /* Only mark the value as an integer if
61942 **
61943 ** (1) the round-trip conversion real->int->real is a no-op, and
61944 ** (2) The integer is neither the largest nor the smallest
@@ -61756,15 +61946,13 @@
61946 **
61947 ** The second and third terms in the following conditional enforces
61948 ** the second condition under the assumption that addition overflow causes
61949 ** values to wrap around.
61950 */
61951 if( pMem->u.r==ix && ix>SMALLEST_INT64 && ix<LARGEST_INT64 ){
61952 pMem->u.i = ix;
61953 MemSetTypeFlag(pMem, MEM_Int);
 
 
61954 }
61955 }
61956
61957 /*
61958 ** Convert pMem to type integer. Invalidate any prior representations.
@@ -61785,11 +61973,11 @@
61973 */
61974 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem *pMem){
61975 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61976 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
61977
61978 pMem->u.r = sqlite3VdbeRealValue(pMem);
61979 MemSetTypeFlag(pMem, MEM_Real);
61980 return SQLITE_OK;
61981 }
61982
61983 /*
@@ -61805,11 +61993,11 @@
61993 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
61994 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61995 if( 0==sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc) ){
61996 MemSetTypeFlag(pMem, MEM_Int);
61997 }else{
61998 pMem->u.r = sqlite3VdbeRealValue(pMem);
61999 MemSetTypeFlag(pMem, MEM_Real);
62000 sqlite3VdbeIntegerAffinity(pMem);
62001 }
62002 }
62003 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))!=0 );
@@ -61859,24 +62047,41 @@
62047 break;
62048 }
62049 }
62050 }
62051
62052 /*
62053 ** Initialize bulk memory to be a consistent Mem object.
62054 **
62055 ** The minimum amount of initialization feasible is performed.
62056 */
62057 SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem *pMem, sqlite3 *db, u16 flags){
62058 assert( (flags & ~MEM_TypeMask)==0 );
62059 pMem->flags = flags;
62060 pMem->db = db;
62061 pMem->szMalloc = 0;
62062 }
62063
62064
62065 /*
62066 ** Delete any previous value and set the value stored in *pMem to NULL.
62067 **
62068 ** This routine calls the Mem.xDel destructor to dispose of values that
62069 ** require the destructor. But it preserves the Mem.zMalloc memory allocation.
62070 ** To free all resources, use sqlite3VdbeMemRelease(), which both calls this
62071 ** routine to invoke the destructor and deallocates Mem.zMalloc.
62072 **
62073 ** Use this routine to reset the Mem prior to insert a new value.
62074 **
62075 ** Use sqlite3VdbeMemRelease() to complete erase the Mem prior to abandoning it.
62076 */
62077 SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem *pMem){
62078 if( VdbeMemDynamic(pMem) ){
62079 vdbeMemClearExternAndSetNull(pMem);
62080 }else{
62081 pMem->flags = MEM_Null;
62082 }
 
 
 
 
62083 }
62084 SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){
62085 sqlite3VdbeMemSetNull((Mem*)p);
62086 }
62087
@@ -61889,27 +62094,20 @@
62094 pMem->flags = MEM_Blob|MEM_Zero;
62095 pMem->n = 0;
62096 if( n<0 ) n = 0;
62097 pMem->u.nZero = n;
62098 pMem->enc = SQLITE_UTF8;
62099 pMem->z = 0;
 
 
 
 
 
 
 
62100 }
62101
62102 /*
62103 ** The pMem is known to contain content that needs to be destroyed prior
62104 ** to a value change. So invoke the destructor, then set the value to
62105 ** a 64-bit integer.
62106 */
62107 static SQLITE_NOINLINE void vdbeReleaseAndSetInt64(Mem *pMem, i64 val){
62108 sqlite3VdbeMemSetNull(pMem);
62109 pMem->u.i = val;
62110 pMem->flags = MEM_Int;
62111 }
62112
62113 /*
@@ -61929,15 +62127,13 @@
62127 /*
62128 ** Delete any previous value and set the value stored in *pMem to val,
62129 ** manifest type REAL.
62130 */
62131 SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem *pMem, double val){
62132 sqlite3VdbeMemSetNull(pMem);
62133 if( !sqlite3IsNaN(val) ){
62134 pMem->u.r = val;
 
 
62135 pMem->flags = MEM_Real;
62136 }
62137 }
62138 #endif
62139
@@ -61951,14 +62147,15 @@
62147 assert( (pMem->flags & MEM_RowSet)==0 );
62148 sqlite3VdbeMemRelease(pMem);
62149 pMem->zMalloc = sqlite3DbMallocRaw(db, 64);
62150 if( db->mallocFailed ){
62151 pMem->flags = MEM_Null;
62152 pMem->szMalloc = 0;
62153 }else{
62154 assert( pMem->zMalloc );
62155 pMem->szMalloc = sqlite3DbMallocSize(db, pMem->zMalloc);
62156 pMem->u.pRowSet = sqlite3RowSetInit(db, pMem->zMalloc, pMem->szMalloc);
62157 assert( pMem->u.pRowSet!=0 );
62158 pMem->flags = MEM_RowSet;
62159 }
62160 }
62161
@@ -61978,11 +62175,11 @@
62175 return 0;
62176 }
62177
62178 #ifdef SQLITE_DEBUG
62179 /*
62180 ** This routine prepares a memory cell for modification by breaking
62181 ** its link to a shallow copy and by marking any current shallow
62182 ** copies of this cell as invalid.
62183 **
62184 ** This is used for testing and debugging only - to make sure shallow
62185 ** copies are not misused.
@@ -62011,13 +62208,13 @@
62208 ** pFrom->z is used, then pTo->z points to the same thing as pFrom->z
62209 ** and flags gets srcType (either MEM_Ephem or MEM_Static).
62210 */
62211 SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){
62212 assert( (pFrom->flags & MEM_RowSet)==0 );
62213 assert( pTo->db==pFrom->db );
62214 if( VdbeMemDynamic(pTo) ) vdbeMemClearExternAndSetNull(pTo);
62215 memcpy(pTo, pFrom, MEMCELLSIZE);
 
62216 if( (pFrom->flags&MEM_Static)==0 ){
62217 pTo->flags &= ~(MEM_Dyn|MEM_Static|MEM_Ephem);
62218 assert( srcType==MEM_Ephem || srcType==MEM_Static );
62219 pTo->flags |= srcType;
62220 }
@@ -62028,16 +62225,15 @@
62225 ** freed before the copy is made.
62226 */
62227 SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){
62228 int rc = SQLITE_OK;
62229
62230 assert( pTo->db==pFrom->db );
62231 assert( (pFrom->flags & MEM_RowSet)==0 );
62232 if( VdbeMemDynamic(pTo) ) vdbeMemClearExternAndSetNull(pTo);
62233 memcpy(pTo, pFrom, MEMCELLSIZE);
62234 pTo->flags &= ~MEM_Dyn;
 
 
62235 if( pTo->flags&(MEM_Str|MEM_Blob) ){
62236 if( 0==(pFrom->flags&MEM_Static) ){
62237 pTo->flags |= MEM_Ephem;
62238 rc = sqlite3VdbeMemMakeWriteable(pTo);
62239 }
@@ -62058,12 +62254,11 @@
62254 assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db );
62255
62256 sqlite3VdbeMemRelease(pTo);
62257 memcpy(pTo, pFrom, sizeof(Mem));
62258 pFrom->flags = MEM_Null;
62259 pFrom->szMalloc = 0;
 
62260 }
62261
62262 /*
62263 ** Change the value of a Mem to be a string or a BLOB.
62264 **
@@ -62106,11 +62301,12 @@
62301 }
62302 flags = (enc==0?MEM_Blob:MEM_Str);
62303 if( nByte<0 ){
62304 assert( enc!=0 );
62305 if( enc==SQLITE_UTF8 ){
62306 nByte = sqlite3Strlen30(z);
62307 if( nByte>iLimit ) nByte = iLimit+1;
62308 }else{
62309 for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
62310 }
62311 flags |= MEM_Term;
62312 }
@@ -62125,18 +62321,18 @@
62321 nAlloc += (enc==SQLITE_UTF8?1:2);
62322 }
62323 if( nByte>iLimit ){
62324 return SQLITE_TOOBIG;
62325 }
62326 if( sqlite3VdbeMemClearAndResize(pMem, nAlloc) ){
62327 return SQLITE_NOMEM;
62328 }
62329 memcpy(pMem->z, z, nAlloc);
62330 }else if( xDel==SQLITE_DYNAMIC ){
62331 sqlite3VdbeMemRelease(pMem);
62332 pMem->zMalloc = pMem->z = (char *)z;
62333 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
62334 }else{
62335 sqlite3VdbeMemRelease(pMem);
62336 pMem->z = (char *)z;
62337 pMem->xDel = xDel;
62338 flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
@@ -62164,12 +62360,15 @@
62360 ** The data or key is taken from the entry that pCur is currently pointing
62361 ** to. offset and amt determine what portion of the data or key to retrieve.
62362 ** key is true to get the key or false to get data. The result is written
62363 ** into the pMem element.
62364 **
62365 ** The pMem object must have been initialized. This routine will use
62366 ** pMem->zMalloc to hold the content from the btree, if possible. New
62367 ** pMem->zMalloc space will be allocated if necessary. The calling routine
62368 ** is responsible for making sure that the pMem object is eventually
62369 ** destroyed.
62370 **
62371 ** If this routine fails for any reason (malloc returns NULL or unable
62372 ** to read from the disk) then the pMem is left in an inconsistent state.
62373 */
62374 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
@@ -62182,10 +62381,11 @@
62381 char *zData; /* Data from the btree layer */
62382 u32 available = 0; /* Number of bytes available on the local btree page */
62383 int rc = SQLITE_OK; /* Return code */
62384
62385 assert( sqlite3BtreeCursorIsValid(pCur) );
62386 assert( !VdbeMemDynamic(pMem) );
62387
62388 /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
62389 ** that both the BtShared and database handle mutexes are held. */
62390 assert( (pMem->flags & MEM_RowSet)==0 );
62391 if( key ){
@@ -62194,27 +62394,29 @@
62394 zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
62395 }
62396 assert( zData!=0 );
62397
62398 if( offset+amt<=available ){
 
62399 pMem->z = &zData[offset];
62400 pMem->flags = MEM_Blob|MEM_Ephem;
62401 pMem->n = (int)amt;
62402 }else{
62403 pMem->flags = MEM_Null;
62404 if( SQLITE_OK==(rc = sqlite3VdbeMemClearAndResize(pMem, amt+2)) ){
62405 if( key ){
62406 rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
62407 }else{
62408 rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
62409 }
62410 if( rc==SQLITE_OK ){
62411 pMem->z[amt] = 0;
62412 pMem->z[amt+1] = 0;
62413 pMem->flags = MEM_Blob|MEM_Term;
62414 pMem->n = (int)amt;
62415 }else{
62416 sqlite3VdbeMemRelease(pMem);
62417 }
62418 }
62419 }
62420
62421 return rc;
62422 }
@@ -62434,18 +62636,18 @@
62636 /* This branch happens for multiple negative signs. Ex: -(-5) */
62637 if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal)
62638 && pVal!=0
62639 ){
62640 sqlite3VdbeMemNumerify(pVal);
62641 if( pVal->flags & MEM_Real ){
62642 pVal->u.r = -pVal->u.r;
62643 }else if( pVal->u.i==SMALLEST_INT64 ){
62644 pVal->u.r = -(double)SMALLEST_INT64;
62645 MemSetTypeFlag(pVal, MEM_Real);
62646 }else{
62647 pVal->u.i = -pVal->u.i;
62648 }
 
62649 sqlite3ValueApplyAffinity(pVal, affinity, enc);
62650 }
62651 }else if( op==TK_NULL ){
62652 pVal = valueNew(db, pCtx);
62653 if( pVal==0 ) goto no_mem;
@@ -62749,11 +62951,11 @@
62951 int i;
62952 int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
62953 Mem *aMem = pRec->aMem;
62954 sqlite3 *db = aMem[0].db;
62955 for(i=0; i<nCol; i++){
62956 if( aMem[i].szMalloc ) sqlite3DbFree(db, aMem[i].zMalloc);
62957 }
62958 sqlite3KeyInfoUnref(pRec->pKeyInfo);
62959 sqlite3DbFree(db, pRec);
62960 }
62961 }
@@ -62809,13 +63011,11 @@
63011 ** May you find forgiveness for yourself and forgive others.
63012 ** May you share freely, never taking more than you give.
63013 **
63014 *************************************************************************
63015 ** This file contains code used for creating, destroying, and populating
63016 ** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.)
 
 
63017 */
63018
63019 /*
63020 ** Create a new virtual database engine.
63021 */
@@ -63495,11 +63695,11 @@
63695 case P4_MEM: {
63696 if( db->pnBytesFreed==0 ){
63697 sqlite3ValueFree((sqlite3_value*)p4);
63698 }else{
63699 Mem *p = (Mem*)p4;
63700 if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
63701 sqlite3DbFree(db, p);
63702 }
63703 break;
63704 }
63705 case P4_VTAB : {
@@ -63692,11 +63892,11 @@
63892 **
63893 ** If a memory allocation error has occurred prior to the calling of this
63894 ** routine, then a pointer to a dummy VdbeOp will be returned. That opcode
63895 ** is readable but not writable, though it is cast to a writable value.
63896 ** The return of a dummy opcode allows the call to continue functioning
63897 ** after an OOM fault without having to check to see if the return from
63898 ** this routine is a valid pointer. But because the dummy.opcode is 0,
63899 ** dummy will never be written to. This is verified by code inspection and
63900 ** by running with Valgrind.
63901 */
63902 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
@@ -63873,11 +64073,11 @@
64073 if( pMem->flags & MEM_Str ){
64074 zP4 = pMem->z;
64075 }else if( pMem->flags & MEM_Int ){
64076 sqlite3_snprintf(nTemp, zTemp, "%lld", pMem->u.i);
64077 }else if( pMem->flags & MEM_Real ){
64078 sqlite3_snprintf(nTemp, zTemp, "%.16g", pMem->u.r);
64079 }else if( pMem->flags & MEM_Null ){
64080 sqlite3_snprintf(nTemp, zTemp, "NULL");
64081 }else{
64082 assert( pMem->flags & MEM_Blob );
64083 zP4 = "(blob)";
@@ -64023,20 +64223,20 @@
64223 /*
64224 ** Release an array of N Mem elements
64225 */
64226 static void releaseMemArray(Mem *p, int N){
64227 if( p && N ){
64228 Mem *pEnd = &p[N];
64229 sqlite3 *db = p->db;
64230 u8 malloc_failed = db->mallocFailed;
64231 if( db->pnBytesFreed ){
64232 do{
64233 if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
64234 }while( (++p)<pEnd );
64235 return;
64236 }
64237 do{
64238 assert( (&p[1])==pEnd || p[0].db==p[1].db );
64239 assert( sqlite3VdbeCheckMemInvariants(p) );
64240
64241 /* This block is really an inlined version of sqlite3VdbeMemRelease()
64242 ** that takes advantage of the fact that the memory cell value is
@@ -64054,17 +64254,17 @@
64254 testcase( p->flags & MEM_Dyn );
64255 testcase( p->flags & MEM_Frame );
64256 testcase( p->flags & MEM_RowSet );
64257 if( p->flags&(MEM_Agg|MEM_Dyn|MEM_Frame|MEM_RowSet) ){
64258 sqlite3VdbeMemRelease(p);
64259 }else if( p->szMalloc ){
64260 sqlite3DbFree(db, p->zMalloc);
64261 p->szMalloc = 0;
64262 }
64263
64264 p->flags = MEM_Undefined;
64265 }while( (++p)<pEnd );
64266 db->mallocFailed = malloc_failed;
64267 }
64268 }
64269
64270 /*
@@ -64223,11 +64423,11 @@
64423
64424 pMem->flags = MEM_Int;
64425 pMem->u.i = pOp->p3; /* P3 */
64426 pMem++;
64427
64428 if( sqlite3VdbeMemClearAndResize(pMem, 32) ){ /* P4 */
64429 assert( p->db->mallocFailed );
64430 return SQLITE_ERROR;
64431 }
64432 pMem->flags = MEM_Str|MEM_Term;
64433 zP4 = displayP4(pOp, pMem->z, 32);
@@ -64239,11 +64439,11 @@
64439 pMem->enc = SQLITE_UTF8;
64440 }
64441 pMem++;
64442
64443 if( p->explain==1 ){
64444 if( sqlite3VdbeMemClearAndResize(pMem, 4) ){
64445 assert( p->db->mallocFailed );
64446 return SQLITE_ERROR;
64447 }
64448 pMem->flags = MEM_Str|MEM_Term;
64449 pMem->n = 2;
@@ -64250,11 +64450,11 @@
64450 sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
64451 pMem->enc = SQLITE_UTF8;
64452 pMem++;
64453
64454 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
64455 if( sqlite3VdbeMemClearAndResize(pMem, 500) ){
64456 assert( p->db->mallocFailed );
64457 return SQLITE_ERROR;
64458 }
64459 pMem->flags = MEM_Str|MEM_Term;
64460 pMem->n = displayComment(pOp, zP4, pMem->z, 500);
@@ -64403,17 +64603,17 @@
64603 }
64604
64605 /*
64606 ** Prepare a virtual machine for execution for the first time after
64607 ** creating the virtual machine. This involves things such
64608 ** as allocating registers and initializing the program counter.
64609 ** After the VDBE has be prepped, it can be executed by one or more
64610 ** calls to sqlite3VdbeExec().
64611 **
64612 ** This function may be called exactly once on each virtual machine.
64613 ** After this routine is called the VM has been "packaged" and is ready
64614 ** to run. After this routine is called, further calls to
64615 ** sqlite3VdbeAddOp() functions are prohibited. This routine disconnects
64616 ** the Vdbe from the Parse object that helped generate it so that the
64617 ** the Vdbe becomes an independent entity and the Parse object can be
64618 ** destroyed.
64619 **
@@ -64615,15 +64815,11 @@
64815 sqlite3VdbeDeleteAuxData(p, -1, 0);
64816 assert( p->pAuxData==0 );
64817 }
64818
64819 /*
64820 ** Clean up the VM after a single run.
 
 
 
 
64821 */
64822 static void Cleanup(Vdbe *p){
64823 sqlite3 *db = p->db;
64824
64825 #ifdef SQLITE_DEBUG
@@ -64787,11 +64983,11 @@
64983 }
64984 }
64985
64986 /* The complex case - There is a multi-file write-transaction active.
64987 ** This requires a master journal file to ensure the transaction is
64988 ** committed atomically.
64989 */
64990 #ifndef SQLITE_OMIT_DISKIO
64991 else{
64992 sqlite3_vfs *pVfs = db->pVfs;
64993 int needSync = 0;
@@ -65435,11 +65631,11 @@
65631 **
65632 ** * the associated function parameter is the 32nd or later (counting
65633 ** from left to right), or
65634 **
65635 ** * the corresponding bit in argument mask is clear (where the first
65636 ** function parameter corresponds to bit 0 etc.).
65637 */
65638 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe *pVdbe, int iOp, int mask){
65639 AuxData **pp = &pVdbe->pAuxData;
65640 while( *pp ){
65641 AuxData *pAux = *pp;
@@ -65539,11 +65735,11 @@
65735
65736 /*
65737 ** Something has moved cursor "p" out of place. Maybe the row it was
65738 ** pointed to was deleted out from under it. Or maybe the btree was
65739 ** rebalanced. Whatever the cause, try to restore "p" to the place it
65740 ** is supposed to be pointing. If the row was deleted out from under the
65741 ** cursor, set the cursor to point to a NULL row.
65742 */
65743 static int SQLITE_NOINLINE handleMovedCursor(VdbeCursor *p){
65744 int isDifferentRow, rc;
65745 assert( p->pCursor!=0 );
@@ -65746,12 +65942,12 @@
65942 /* Integer and Real */
65943 if( serial_type<=7 && serial_type>0 ){
65944 u64 v;
65945 u32 i;
65946 if( serial_type==7 ){
65947 assert( sizeof(v)==sizeof(pMem->u.r) );
65948 memcpy(&v, &pMem->u.r, sizeof(v));
65949 swapMixedEndianFloat(v);
65950 }else{
65951 v = pMem->u.i;
65952 }
65953 len = i = sqlite3VdbeSerialTypeLen(serial_type);
@@ -65817,14 +66013,14 @@
66013 static const double r1 = 1.0;
66014 u64 t2 = t1;
66015 swapMixedEndianFloat(t2);
66016 assert( sizeof(r1)==sizeof(t2) && memcmp(&r1, &t2, sizeof(r1))==0 );
66017 #endif
66018 assert( sizeof(x)==8 && sizeof(pMem->u.r)==8 );
66019 swapMixedEndianFloat(x);
66020 memcpy(&pMem->u.r, &x, sizeof(x));
66021 pMem->flags = sqlite3IsNaN(pMem->u.r) ? MEM_Null : MEM_Real;
66022 }
66023 return 8;
66024 }
66025 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(
66026 const unsigned char *buf, /* Buffer to deserialize from */
@@ -65882,11 +66078,10 @@
66078 }
66079 default: {
66080 static const u16 aFlag[] = { MEM_Blob|MEM_Ephem, MEM_Str|MEM_Ephem };
66081 pMem->z = (char *)buf;
66082 pMem->n = (serial_type-12)/2;
 
66083 pMem->flags = aFlag[serial_type&1];
66084 return pMem->n;
66085 }
66086 }
66087 return 0;
@@ -65958,21 +66153,21 @@
66153 p->default_rc = 0;
66154 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
66155 idx = getVarint32(aKey, szHdr);
66156 d = szHdr;
66157 u = 0;
66158 while( idx<szHdr && d<=nKey ){
66159 u32 serial_type;
66160
66161 idx += getVarint32(&aKey[idx], serial_type);
66162 pMem->enc = pKeyInfo->enc;
66163 pMem->db = pKeyInfo->db;
66164 /* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */
66165 pMem->szMalloc = 0;
66166 d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
66167 pMem++;
66168 if( (++u)>=p->nField ) break;
66169 }
66170 assert( u<=pKeyInfo->nField + 1 );
66171 p->nField = u;
66172 }
66173
@@ -66005,11 +66200,11 @@
66200 pKeyInfo = pPKey2->pKeyInfo;
66201 if( pKeyInfo->db==0 ) return 1;
66202 mem1.enc = pKeyInfo->enc;
66203 mem1.db = pKeyInfo->db;
66204 /* mem1.flags = 0; // Will be initialized by sqlite3VdbeSerialGet() */
66205 VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
66206
66207 /* Compilers may complain that mem1.u.i is potentially uninitialized.
66208 ** We could initialize it, as shown here, to silence those complaints.
66209 ** But in fact, mem1.u.i will never actually be used uninitialized, and doing
66210 ** the unnecessary initialization has a measurable negative performance
@@ -66048,11 +66243,11 @@
66243
66244 /* Do the comparison
66245 */
66246 rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i], pKeyInfo->aColl[i]);
66247 if( rc!=0 ){
66248 assert( mem1.szMalloc==0 ); /* See comment below */
66249 if( pKeyInfo->aSortOrder[i] ){
66250 rc = -rc; /* Invert the result for DESC sort order. */
66251 }
66252 goto debugCompareEnd;
66253 }
@@ -66061,14 +66256,14 @@
66256
66257 /* No memory allocation is ever used on mem1. Prove this using
66258 ** the following assert(). If the assert() fails, it indicates a
66259 ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
66260 */
66261 assert( mem1.szMalloc==0 );
66262
66263 /* rc==0 here means that one of the keys ran out of fields and
66264 ** all the fields up to that point were equal. Return the default_rc
66265 ** value. */
66266 rc = pPKey2->default_rc;
66267
66268 debugCompareEnd:
66269 if( desiredResult==0 && rc==0 ) return 1;
@@ -66100,12 +66295,12 @@
66295 int rc;
66296 const void *v1, *v2;
66297 int n1, n2;
66298 Mem c1;
66299 Mem c2;
66300 sqlite3VdbeMemInit(&c1, pMem1->db, MEM_Null);
66301 sqlite3VdbeMemInit(&c2, pMem1->db, MEM_Null);
66302 sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
66303 sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
66304 v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
66305 n1 = v1==0 ? 0 : c1.n;
66306 v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
@@ -66115,10 +66310,22 @@
66310 sqlite3VdbeMemRelease(&c2);
66311 if( (v1==0 || v2==0) && prcErr ) *prcErr = SQLITE_NOMEM;
66312 return rc;
66313 }
66314 }
66315
66316 /*
66317 ** Compare two blobs. Return negative, zero, or positive if the first
66318 ** is less than, equal to, or greater than the second, respectively.
66319 ** If one blob is a prefix of the other, then the shorter is the lessor.
66320 */
66321 static SQLITE_NOINLINE int sqlite3BlobCompare(const Mem *pB1, const Mem *pB2){
66322 int c = memcmp(pB1->z, pB2->z, pB1->n>pB2->n ? pB2->n : pB1->n);
66323 if( c ) return c;
66324 return pB1->n - pB2->n;
66325 }
66326
66327
66328 /*
66329 ** Compare the values contained by the two memory cells, returning
66330 ** negative, zero or positive if pMem1 is less than, equal to, or greater
66331 ** than pMem2. Sorting order is NULL's first, followed by numbers (integers
@@ -66126,11 +66333,10 @@
66333 ** sequence pColl and finally blob's ordered by memcmp().
66334 **
66335 ** Two NULL values are considered equal by this function.
66336 */
66337 SQLITE_PRIVATE int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
 
66338 int f1, f2;
66339 int combined_flags;
66340
66341 f1 = pMem1->flags;
66342 f2 = pMem2->flags;
@@ -66154,18 +66360,18 @@
66360 if( pMem1->u.i < pMem2->u.i ) return -1;
66361 if( pMem1->u.i > pMem2->u.i ) return 1;
66362 return 0;
66363 }
66364 if( (f1&MEM_Real)!=0 ){
66365 r1 = pMem1->u.r;
66366 }else if( (f1&MEM_Int)!=0 ){
66367 r1 = (double)pMem1->u.i;
66368 }else{
66369 return 1;
66370 }
66371 if( (f2&MEM_Real)!=0 ){
66372 r2 = pMem2->u.r;
66373 }else if( (f2&MEM_Int)!=0 ){
66374 r2 = (double)pMem2->u.i;
66375 }else{
66376 return -1;
66377 }
@@ -66201,15 +66407,11 @@
66407 /* If a NULL pointer was passed as the collate function, fall through
66408 ** to the blob case and use memcmp(). */
66409 }
66410
66411 /* Both values must be blobs. Compare using memcmp(). */
66412 return sqlite3BlobCompare(pMem1, pMem2);
 
 
 
 
66413 }
66414
66415
66416 /*
66417 ** The first argument passed to this function is a serial-type that
@@ -66255,11 +66457,11 @@
66457 /*
66458 ** This function compares the two table rows or index records
66459 ** specified by {nKey1, pKey1} and pPKey2. It returns a negative, zero
66460 ** or positive integer if key1 is less than, equal to or
66461 ** greater than key2. The {nKey1, pKey1} key must be a blob
66462 ** created by the OP_MakeRecord opcode of the VDBE. The pPKey2
66463 ** key must be a parsed key such as obtained from
66464 ** sqlite3VdbeParseRecord.
66465 **
66466 ** If argument bSkip is non-zero, it is assumed that the caller has already
66467 ** determined that the first fields of the keys are equal.
@@ -66271,11 +66473,11 @@
66473 ** If database corruption is discovered, set pPKey2->errCode to
66474 ** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
66475 ** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
66476 ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
66477 */
66478 static int vdbeRecordCompareWithSkip(
66479 int nKey1, const void *pKey1, /* Left key */
66480 UnpackedRecord *pPKey2, /* Right key */
66481 int bSkip /* If true, skip the first field */
66482 ){
66483 u32 d1; /* Offset into aKey[] of next data element */
@@ -66306,11 +66508,11 @@
66508 return 0; /* Corruption */
66509 }
66510 i = 0;
66511 }
66512
66513 VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
66514 assert( pPKey2->pKeyInfo->nField+pPKey2->pKeyInfo->nXField>=pPKey2->nField
66515 || CORRUPT_DB );
66516 assert( pPKey2->pKeyInfo->aSortOrder!=0 );
66517 assert( pPKey2->pKeyInfo->nField>0 );
66518 assert( idx1<=szHdr1 || CORRUPT_DB );
@@ -66326,13 +66528,13 @@
66528 }else if( serial_type==0 ){
66529 rc = -1;
66530 }else if( serial_type==7 ){
66531 double rhs = (double)pRhs->u.i;
66532 sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
66533 if( mem1.u.r<rhs ){
66534 rc = -1;
66535 }else if( mem1.u.r>rhs ){
66536 rc = +1;
66537 }
66538 }else{
66539 i64 lhs = vdbeRecordDecodeInt(serial_type, &aKey1[d1]);
66540 i64 rhs = pRhs->u.i;
@@ -66350,15 +66552,15 @@
66552 if( serial_type>=12 ){
66553 rc = +1;
66554 }else if( serial_type==0 ){
66555 rc = -1;
66556 }else{
66557 double rhs = pRhs->u.r;
66558 double lhs;
66559 sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
66560 if( serial_type==7 ){
66561 lhs = mem1.u.r;
66562 }else{
66563 lhs = (double)mem1.u.i;
66564 }
66565 if( lhs<rhs ){
66566 rc = -1;
@@ -66429,11 +66631,11 @@
66631 if( rc!=0 ){
66632 if( pKeyInfo->aSortOrder[i] ){
66633 rc = -rc;
66634 }
66635 assert( vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, rc) );
66636 assert( mem1.szMalloc==0 ); /* See comment below */
66637 return rc;
66638 }
66639
66640 i++;
66641 pRhs++;
@@ -66442,21 +66644,28 @@
66644 }while( idx1<(unsigned)szHdr1 && i<pPKey2->nField && d1<=(unsigned)nKey1 );
66645
66646 /* No memory allocation is ever used on mem1. Prove this using
66647 ** the following assert(). If the assert() fails, it indicates a
66648 ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1). */
66649 assert( mem1.szMalloc==0 );
66650
66651 /* rc==0 here means that one or both of the keys ran out of fields and
66652 ** all the fields up to that point were equal. Return the default_rc
66653 ** value. */
66654 assert( CORRUPT_DB
66655 || vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, pPKey2->default_rc)
66656 || pKeyInfo->db->mallocFailed
66657 );
66658 return pPKey2->default_rc;
66659 }
66660 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
66661 int nKey1, const void *pKey1, /* Left key */
66662 UnpackedRecord *pPKey2 /* Right key */
66663 ){
66664 return vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
66665 }
66666
66667
66668 /*
66669 ** This function is an optimized version of sqlite3VdbeRecordCompare()
66670 ** that (a) the first field of pPKey2 is an integer, and (b) the
66671 ** size-of-header varint at the start of (pKey1/nKey1) fits in a single
@@ -66465,23 +66674,20 @@
66674 ** To avoid concerns about buffer overreads, this routine is only used
66675 ** on schemas where the maximum valid header size is 63 bytes or less.
66676 */
66677 static int vdbeRecordCompareInt(
66678 int nKey1, const void *pKey1, /* Left key */
66679 UnpackedRecord *pPKey2 /* Right key */
 
66680 ){
66681 const u8 *aKey = &((const u8*)pKey1)[*(const u8*)pKey1 & 0x3F];
66682 int serial_type = ((const u8*)pKey1)[1];
66683 int res;
66684 u32 y;
66685 u64 x;
66686 i64 v = pPKey2->aMem[0].u.i;
66687 i64 lhs;
 
66688
 
66689 assert( (*(u8*)pKey1)<=0x3F || CORRUPT_DB );
66690 switch( serial_type ){
66691 case 1: { /* 1-byte signed integer */
66692 lhs = ONE_BYTE_INT(aKey);
66693 testcase( lhs<0 );
@@ -66527,24 +66733,24 @@
66733 ** statement (since the range of switch targets now starts at zero and
66734 ** is contiguous) but does not cause any duplicate code to be generated
66735 ** (as gcc is clever enough to combine the two like cases). Other
66736 ** compilers might be similar. */
66737 case 0: case 7:
66738 return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2);
66739
66740 default:
66741 return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2);
66742 }
66743
66744 if( v>lhs ){
66745 res = pPKey2->r1;
66746 }else if( v<lhs ){
66747 res = pPKey2->r2;
66748 }else if( pPKey2->nField>1 ){
66749 /* The first fields of the two keys are equal. Compare the trailing
66750 ** fields. */
66751 res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
66752 }else{
66753 /* The first fields of the two keys are equal and there are no trailing
66754 ** fields. Return pPKey2->default_rc in this case. */
66755 res = pPKey2->default_rc;
66756 }
@@ -66559,21 +66765,17 @@
66765 ** uses the collation sequence BINARY and (c) that the size-of-header varint
66766 ** at the start of (pKey1/nKey1) fits in a single byte.
66767 */
66768 static int vdbeRecordCompareString(
66769 int nKey1, const void *pKey1, /* Left key */
66770 UnpackedRecord *pPKey2 /* Right key */
 
66771 ){
66772 const u8 *aKey1 = (const u8*)pKey1;
66773 int serial_type;
66774 int res;
 
66775
 
66776 getVarint32(&aKey1[1], serial_type);
 
66777 if( serial_type<12 ){
66778 res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */
66779 }else if( !(serial_type & 0x01) ){
66780 res = pPKey2->r2; /* (pKey1/nKey1) is a blob */
66781 }else{
@@ -66591,11 +66793,11 @@
66793
66794 if( res==0 ){
66795 res = nStr - pPKey2->aMem[0].n;
66796 if( res==0 ){
66797 if( pPKey2->nField>1 ){
66798 res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
66799 }else{
66800 res = pPKey2->default_rc;
66801 }
66802 }else if( res>0 ){
66803 res = pPKey2->r2;
@@ -66673,12 +66875,10 @@
66875 u32 szHdr; /* Size of the header */
66876 u32 typeRowid; /* Serial type of the rowid */
66877 u32 lenRowid; /* Size of the rowid */
66878 Mem m, v;
66879
 
 
66880 /* Get the size of the index entry. Only indices entries of less
66881 ** than 2GiB are support - anything large must be database corruption.
66882 ** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
66883 ** this code can safely assume that nCellKey is 32-bits
66884 */
@@ -66686,11 +66886,11 @@
66886 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
66887 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
66888 assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
66889
66890 /* Read in the complete content of the index entry */
66891 sqlite3VdbeMemInit(&m, db, 0);
66892 rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
66893 if( rc ){
66894 return rc;
66895 }
66896
@@ -66729,11 +66929,11 @@
66929 return SQLITE_OK;
66930
66931 /* Jump here if database corruption is detected after m has been
66932 ** allocated. Free the m object and return SQLITE_CORRUPT. */
66933 idx_rowid_corruption:
66934 testcase( m.szMalloc!=0 );
66935 sqlite3VdbeMemRelease(&m);
66936 return SQLITE_CORRUPT_BKPT;
66937 }
66938
66939 /*
@@ -66746,10 +66946,11 @@
66946 ** omits the rowid at the end. The rowid at the end of the index entry
66947 ** is ignored as well. Hence, this routine only compares the prefixes
66948 ** of the keys prior to the final rowid, not the entire key.
66949 */
66950 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(
66951 sqlite3 *db, /* Database connection */
66952 VdbeCursor *pC, /* The cursor to compare against */
66953 UnpackedRecord *pUnpacked, /* Unpacked version of key */
66954 int *res /* Write the comparison result here */
66955 ){
66956 i64 nCellKey = 0;
@@ -66764,16 +66965,16 @@
66965 ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
66966 if( nCellKey<=0 || nCellKey>0x7fffffff ){
66967 *res = 0;
66968 return SQLITE_CORRUPT_BKPT;
66969 }
66970 sqlite3VdbeMemInit(&m, db, 0);
66971 rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m);
66972 if( rc ){
66973 return rc;
66974 }
66975 *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
66976 sqlite3VdbeMemRelease(&m);
66977 return SQLITE_OK;
66978 }
66979
66980 /*
@@ -67083,13 +67284,16 @@
67284
67285 /**************************** sqlite3_result_ *******************************
67286 ** The following routines are used by user-defined functions to specify
67287 ** the function result.
67288 **
67289 ** The setStrOrError() function calls sqlite3VdbeMemSetStr() to store the
67290 ** result as a string or blob but if the string or blob is too large, it
67291 ** then sets the error code to SQLITE_TOOBIG
67292 **
67293 ** The invokeValueDestructor(P,X) routine invokes destructor function X()
67294 ** on value P is not going to be used and need to be destroyed.
67295 */
67296 static void setResultStrOrError(
67297 sqlite3_context *pCtx, /* Function context */
67298 const char *z, /* String pointer */
67299 int n, /* Bytes in string, or negative */
@@ -67097,10 +67301,26 @@
67301 void (*xDel)(void*) /* Destructor function */
67302 ){
67303 if( sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel)==SQLITE_TOOBIG ){
67304 sqlite3_result_error_toobig(pCtx);
67305 }
67306 }
67307 static int invokeValueDestructor(
67308 const void *p, /* Value to destroy */
67309 void (*xDel)(void*), /* The destructor */
67310 sqlite3_context *pCtx /* Set a SQLITE_TOOBIG error if no NULL */
67311 ){
67312 assert( xDel!=SQLITE_DYNAMIC );
67313 if( xDel==0 ){
67314 /* noop */
67315 }else if( xDel==SQLITE_TRANSIENT ){
67316 /* noop */
67317 }else{
67318 xDel((void*)p);
67319 }
67320 if( pCtx ) sqlite3_result_error_toobig(pCtx);
67321 return SQLITE_TOOBIG;
67322 }
67323 SQLITE_API void sqlite3_result_blob(
67324 sqlite3_context *pCtx,
67325 const void *z,
67326 int n,
@@ -67107,10 +67327,24 @@
67327 void (*xDel)(void *)
67328 ){
67329 assert( n>=0 );
67330 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
67331 setResultStrOrError(pCtx, z, n, 0, xDel);
67332 }
67333 SQLITE_API void sqlite3_result_blob64(
67334 sqlite3_context *pCtx,
67335 const void *z,
67336 sqlite3_uint64 n,
67337 void (*xDel)(void *)
67338 ){
67339 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
67340 assert( xDel!=SQLITE_DYNAMIC );
67341 if( n>0x7fffffff ){
67342 (void)invokeValueDestructor(z, xDel, pCtx);
67343 }else{
67344 setResultStrOrError(pCtx, z, (int)n, 0, xDel);
67345 }
67346 }
67347 SQLITE_API void sqlite3_result_double(sqlite3_context *pCtx, double rVal){
67348 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
67349 sqlite3VdbeMemSetDouble(pCtx->pOut, rVal);
67350 }
@@ -67146,10 +67380,25 @@
67380 int n,
67381 void (*xDel)(void *)
67382 ){
67383 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
67384 setResultStrOrError(pCtx, z, n, SQLITE_UTF8, xDel);
67385 }
67386 SQLITE_API void sqlite3_result_text64(
67387 sqlite3_context *pCtx,
67388 const char *z,
67389 sqlite3_uint64 n,
67390 void (*xDel)(void *),
67391 unsigned char enc
67392 ){
67393 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
67394 assert( xDel!=SQLITE_DYNAMIC );
67395 if( n>0x7fffffff ){
67396 (void)invokeValueDestructor(z, xDel, pCtx);
67397 }else{
67398 setResultStrOrError(pCtx, z, (int)n, enc, xDel);
67399 }
67400 }
67401 #ifndef SQLITE_OMIT_UTF16
67402 SQLITE_API void sqlite3_result_text16(
67403 sqlite3_context *pCtx,
67404 const void *z,
@@ -67485,15 +67734,14 @@
67734 */
67735 static SQLITE_NOINLINE void *createAggContext(sqlite3_context *p, int nByte){
67736 Mem *pMem = p->pMem;
67737 assert( (pMem->flags & MEM_Agg)==0 );
67738 if( nByte<=0 ){
67739 sqlite3VdbeMemSetNull(pMem);
 
67740 pMem->z = 0;
67741 }else{
67742 sqlite3VdbeMemClearAndResize(pMem, nByte);
67743 pMem->flags = MEM_Agg;
67744 pMem->u.pDef = p->pFunc;
67745 if( pMem->z ){
67746 memset(pMem->z, 0, nByte);
67747 }
@@ -67516,11 +67764,11 @@
67764 return (void*)p->pMem->z;
67765 }
67766 }
67767
67768 /*
67769 ** Return the auxiliary data pointer, if any, for the iArg'th argument to
67770 ** the user-function defined by pCtx.
67771 */
67772 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
67773 AuxData *pAuxData;
67774
@@ -67531,11 +67779,11 @@
67779
67780 return (pAuxData ? pAuxData->pAux : 0);
67781 }
67782
67783 /*
67784 ** Set the auxiliary data pointer and delete function, for the iArg'th
67785 ** argument to the user-function defined by pCtx. Any previous value is
67786 ** deleted by calling the delete function specified when it was set.
67787 */
67788 SQLITE_API void sqlite3_set_auxdata(
67789 sqlite3_context *pCtx,
@@ -67577,11 +67825,11 @@
67825 }
67826 }
67827
67828 #ifndef SQLITE_OMIT_DEPRECATED
67829 /*
67830 ** Return the number of times the Step function of an aggregate has been
67831 ** called.
67832 **
67833 ** This function is deprecated. Do not use it for new code. It is
67834 ** provide only to avoid breaking legacy code. New aggregate function
67835 ** implementations should keep their own counts within their aggregate
@@ -67626,15 +67874,26 @@
67874 ** __attribute__((aligned(8))) macro. */
67875 static const Mem nullMem
67876 #if defined(SQLITE_DEBUG) && defined(__GNUC__)
67877 __attribute__((aligned(8)))
67878 #endif
67879 = {
67880 /* .u = */ {0},
67881 /* .flags = */ MEM_Null,
67882 /* .enc = */ 0,
67883 /* .n = */ 0,
67884 /* .z = */ 0,
67885 /* .zMalloc = */ 0,
67886 /* .szMalloc = */ 0,
67887 /* .iPadding1 = */ 0,
67888 /* .db = */ 0,
67889 /* .xDel = */ 0,
67890 #ifdef SQLITE_DEBUG
67891 /* .pScopyFrom = */ 0,
67892 /* .pFiller = */ 0,
67893 #endif
67894 };
67895 return &nullMem;
67896 }
67897
67898 /*
67899 ** Check to see if column iCol of the given statement is valid. If
@@ -67847,11 +68106,11 @@
68106
68107 #ifdef SQLITE_ENABLE_COLUMN_METADATA
68108 /*
68109 ** Return the name of the database from which a result column derives.
68110 ** NULL is returned if the result column is an expression or constant or
68111 ** anything else which is not an unambiguous reference to a database column.
68112 */
68113 SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
68114 return columnName(
68115 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
68116 }
@@ -67863,11 +68122,11 @@
68122 #endif /* SQLITE_OMIT_UTF16 */
68123
68124 /*
68125 ** Return the name of the table from which a result column derives.
68126 ** NULL is returned if the result column is an expression or constant or
68127 ** anything else which is not an unambiguous reference to a database column.
68128 */
68129 SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
68130 return columnName(
68131 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
68132 }
@@ -67879,11 +68138,11 @@
68138 #endif /* SQLITE_OMIT_UTF16 */
68139
68140 /*
68141 ** Return the name of the table column from which a result column derives.
68142 ** NULL is returned if the result column is an expression or constant or
68143 ** anything else which is not an unambiguous reference to a database column.
68144 */
68145 SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
68146 return columnName(
68147 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
68148 }
@@ -67995,10 +68254,24 @@
68254 const void *zData,
68255 int nData,
68256 void (*xDel)(void*)
68257 ){
68258 return bindText(pStmt, i, zData, nData, xDel, 0);
68259 }
68260 SQLITE_API int sqlite3_bind_blob64(
68261 sqlite3_stmt *pStmt,
68262 int i,
68263 const void *zData,
68264 sqlite3_uint64 nData,
68265 void (*xDel)(void*)
68266 ){
68267 assert( xDel!=SQLITE_DYNAMIC );
68268 if( nData>0x7fffffff ){
68269 return invokeValueDestructor(zData, xDel, 0);
68270 }else{
68271 return bindText(pStmt, i, zData, (int)nData, xDel, 0);
68272 }
68273 }
68274 SQLITE_API int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
68275 int rc;
68276 Vdbe *p = (Vdbe *)pStmt;
68277 rc = vdbeUnbind(p, i);
@@ -68036,10 +68309,26 @@
68309 const char *zData,
68310 int nData,
68311 void (*xDel)(void*)
68312 ){
68313 return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
68314 }
68315 SQLITE_API int sqlite3_bind_text64(
68316 sqlite3_stmt *pStmt,
68317 int i,
68318 const char *zData,
68319 sqlite3_uint64 nData,
68320 void (*xDel)(void*),
68321 unsigned char enc
68322 ){
68323 assert( xDel!=SQLITE_DYNAMIC );
68324 if( nData>0x7fffffff ){
68325 return invokeValueDestructor(zData, xDel, 0);
68326 }else{
68327 if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE;
68328 return bindText(pStmt, i, zData, (int)nData, xDel, enc);
68329 }
68330 }
68331 #ifndef SQLITE_OMIT_UTF16
68332 SQLITE_API int sqlite3_bind_text16(
68333 sqlite3_stmt *pStmt,
68334 int i,
@@ -68056,11 +68345,11 @@
68345 case SQLITE_INTEGER: {
68346 rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
68347 break;
68348 }
68349 case SQLITE_FLOAT: {
68350 rc = sqlite3_bind_double(pStmt, i, pValue->u.r);
68351 break;
68352 }
68353 case SQLITE_BLOB: {
68354 if( pValue->flags & MEM_Zero ){
68355 rc = sqlite3_bind_zeroblob(pStmt, i, pValue->u.nZero);
@@ -68159,11 +68448,11 @@
68448 #ifndef SQLITE_OMIT_DEPRECATED
68449 /*
68450 ** Deprecated external interface. Internal/core SQLite code
68451 ** should call sqlite3TransferBindings.
68452 **
68453 ** It is misuse to call this routine with statements from different
68454 ** database connections. But as this is a deprecated interface, we
68455 ** will not bother to check for that condition.
68456 **
68457 ** If the two statements contain a different number of bindings, then
68458 ** an SQLITE_ERROR is returned. Nothing else can go wrong, so otherwise
@@ -68303,11 +68592,11 @@
68592 ** is eventually freed.
68593 **
68594 ** ALGORITHM: Scan the input string looking for host parameters in any of
68595 ** these forms: ?, ?N, $A, @A, :A. Take care to avoid text within
68596 ** string literals, quoted identifier names, and comments. For text forms,
68597 ** the host parameter index is found by scanning the prepared
68598 ** statement for the corresponding OP_Variable opcode. Once the host
68599 ** parameter index is known, locate the value in p->aVar[]. Then render
68600 ** the value as a literal in place of the host parameter name.
68601 */
68602 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(
@@ -68366,11 +68655,11 @@
68655 if( pVar->flags & MEM_Null ){
68656 sqlite3StrAccumAppend(&out, "NULL", 4);
68657 }else if( pVar->flags & MEM_Int ){
68658 sqlite3XPrintf(&out, 0, "%lld", pVar->u.i);
68659 }else if( pVar->flags & MEM_Real ){
68660 sqlite3XPrintf(&out, 0, "%!.15g", pVar->u.r);
68661 }else if( pVar->flags & MEM_Str ){
68662 int nOut; /* Number of bytes of the string text to include in output */
68663 #ifndef SQLITE_OMIT_UTF16
68664 u8 enc = ENC(db);
68665 Mem utf8;
@@ -68749,11 +69038,11 @@
69038 assert( iCur<p->nCursor );
69039 if( p->apCsr[iCur] ){
69040 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
69041 p->apCsr[iCur] = 0;
69042 }
69043 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
69044 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
69045 memset(pCx, 0, sizeof(VdbeCursor));
69046 pCx->iDb = iDb;
69047 pCx->nField = nField;
69048 if( isBtreeCursor ){
@@ -68782,17 +69071,17 @@
69071 */
69072 static void applyNumericAffinity(Mem *pRec, int bTryForInt){
69073 double rValue;
69074 i64 iValue;
69075 u8 enc = pRec->enc;
69076 assert( (pRec->flags & (MEM_Str|MEM_Int|MEM_Real))==MEM_Str );
69077 if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return;
69078 if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
69079 pRec->u.i = iValue;
69080 pRec->flags |= MEM_Int;
69081 }else{
69082 pRec->u.r = rValue;
69083 pRec->flags |= MEM_Real;
69084 if( bTryForInt ) sqlite3VdbeIntegerAffinity(pRec);
69085 }
69086 }
69087
@@ -68817,28 +69106,28 @@
69106 static void applyAffinity(
69107 Mem *pRec, /* The value to apply affinity to */
69108 char affinity, /* The affinity to be applied */
69109 u8 enc /* Use this text encoding */
69110 ){
69111 if( affinity>=SQLITE_AFF_NUMERIC ){
69112 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
69113 || affinity==SQLITE_AFF_NUMERIC );
69114 if( (pRec->flags & MEM_Int)==0 ){
69115 if( (pRec->flags & MEM_Real)==0 ){
69116 if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
69117 }else{
69118 sqlite3VdbeIntegerAffinity(pRec);
69119 }
69120 }
69121 }else if( affinity==SQLITE_AFF_TEXT ){
69122 /* Only attempt the conversion to TEXT if there is an integer or real
69123 ** representation (blob and NULL do not get converted) but no string
69124 ** representation.
69125 */
69126 if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
69127 sqlite3VdbeMemStringify(pRec, enc, 1);
69128 }
 
 
 
 
 
 
 
 
 
 
69129 }
69130 }
69131
69132 /*
69133 ** Try to convert the type of a function argument or a result column
@@ -68869,17 +69158,17 @@
69158 }
69159
69160 /*
69161 ** pMem currently only holds a string type (or maybe a BLOB that we can
69162 ** interpret as a string if we want to). Compute its corresponding
69163 ** numeric type, if has one. Set the pMem->u.r and pMem->u.i fields
69164 ** accordingly.
69165 */
69166 static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){
69167 assert( (pMem->flags & (MEM_Int|MEM_Real))==0 );
69168 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
69169 if( sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc)==0 ){
69170 return 0;
69171 }
69172 if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==SQLITE_OK ){
69173 return MEM_Int;
69174 }
@@ -68889,11 +69178,11 @@
69178 /*
69179 ** Return the numeric type for pMem, either MEM_Int or MEM_Real or both or
69180 ** none.
69181 **
69182 ** Unlike applyNumericAffinity(), this routine does not modify pMem->flags.
69183 ** But it does set pMem->u.r and pMem->u.i appropriately.
69184 */
69185 static u16 numericType(Mem *pMem){
69186 if( pMem->flags & (MEM_Int|MEM_Real) ){
69187 return pMem->flags & (MEM_Int|MEM_Real);
69188 }
@@ -68999,11 +69288,11 @@
69288 printf(" si:%lld", p->u.i);
69289 }else if( p->flags & MEM_Int ){
69290 printf(" i:%lld", p->u.i);
69291 #ifndef SQLITE_OMIT_FLOATING_POINT
69292 }else if( p->flags & MEM_Real ){
69293 printf(" r:%g", p->u.r);
69294 #endif
69295 }else if( p->flags & MEM_RowSet ){
69296 printf(" (rowset)");
69297 }else{
69298 char zBuf[200];
@@ -69269,11 +69558,11 @@
69558 if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){
69559 assert( pOp->p2>0 );
69560 assert( pOp->p2<=(p->nMem-p->nCursor) );
69561 pOut = &aMem[pOp->p2];
69562 memAboutToChange(p, pOut);
69563 if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
69564 pOut->flags = MEM_Int;
69565 }
69566
69567 /* Sanity checking on other operands */
69568 #ifdef SQLITE_DEBUG
@@ -69631,11 +69920,11 @@
69920 ** Write that value into register P2.
69921 */
69922 case OP_Real: { /* same as TK_FLOAT, out2-prerelease */
69923 pOut->flags = MEM_Real;
69924 assert( !sqlite3IsNaN(*pOp->p4.pReal) );
69925 pOut->u.r = *pOp->p4.pReal;
69926 break;
69927 }
69928 #endif
69929
69930 /* Opcode: String8 * P2 * P4 *
@@ -69654,13 +69943,13 @@
69943 #ifndef SQLITE_OMIT_UTF16
69944 if( encoding!=SQLITE_UTF8 ){
69945 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
69946 if( rc==SQLITE_TOOBIG ) goto too_big;
69947 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
69948 assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
69949 assert( VdbeMemDynamic(pOut)==0 );
69950 pOut->szMalloc = 0;
69951 pOut->flags |= MEM_Static;
69952 if( pOp->p4type==P4_DYNAMIC ){
69953 sqlite3DbFree(db, pOp->p4.z);
69954 }
69955 pOp->p4type = P4_DYNAMIC;
@@ -69708,11 +69997,11 @@
69997 assert( pOp->p3<=(p->nMem-p->nCursor) );
69998 pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
69999 while( cnt>0 ){
70000 pOut++;
70001 memAboutToChange(p, pOut);
70002 sqlite3VdbeMemSetNull(pOut);
70003 pOut->flags = nullFlag;
70004 cnt--;
70005 }
70006 break;
70007 }
@@ -69776,11 +70065,10 @@
70065 ** left holding a NULL. It is an error for register ranges
70066 ** P1..P1+P3-1 and P2..P2+P3-1 to overlap. It is an error
70067 ** for P3 to be less than 1.
70068 */
70069 case OP_Move: {
 
70070 int n; /* Number of registers left to copy */
70071 int p1; /* Register to copy from */
70072 int p2; /* Register to copy to */
70073
70074 n = pOp->p3;
@@ -69794,21 +70082,16 @@
70082 do{
70083 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
70084 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
70085 assert( memIsValid(pIn1) );
70086 memAboutToChange(p, pOut);
70087 sqlite3VdbeMemMove(pOut, pIn1);
 
 
70088 #ifdef SQLITE_DEBUG
70089 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
70090 pOut->pScopyFrom += p1 - pOp->p2;
70091 }
70092 #endif
 
 
 
70093 REGISTER_TRACE(p2++, pOut);
70094 pIn1++;
70095 pOut++;
70096 }while( --n );
70097 break;
@@ -70109,11 +70392,11 @@
70392 MemSetTypeFlag(pOut, MEM_Int);
70393 #else
70394 if( sqlite3IsNaN(rB) ){
70395 goto arithmetic_result_is_null;
70396 }
70397 pOut->u.r = rB;
70398 MemSetTypeFlag(pOut, MEM_Real);
70399 if( ((type1|type2)&MEM_Real)==0 && !bIntint ){
70400 sqlite3VdbeIntegerAffinity(pOut);
70401 }
70402 #endif
@@ -70384,11 +70667,11 @@
70667 ** </ul>
70668 **
70669 ** A NULL value is not changed by this routine. It remains NULL.
70670 */
70671 case OP_Cast: { /* in1 */
70672 assert( pOp->p2>=SQLITE_AFF_NONE && pOp->p2<=SQLITE_AFF_REAL );
70673 testcase( pOp->p2==SQLITE_AFF_TEXT );
70674 testcase( pOp->p2==SQLITE_AFF_NONE );
70675 testcase( pOp->p2==SQLITE_AFF_NUMERIC );
70676 testcase( pOp->p2==SQLITE_AFF_INTEGER );
70677 testcase( pOp->p2==SQLITE_AFF_REAL );
@@ -70534,19 +70817,39 @@
70817 break;
70818 }
70819 }else{
70820 /* Neither operand is NULL. Do a comparison. */
70821 affinity = pOp->p5 & SQLITE_AFF_MASK;
70822 if( affinity>=SQLITE_AFF_NUMERIC ){
70823 if( (pIn1->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
70824 applyNumericAffinity(pIn1,0);
70825 }
70826 if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
70827 applyNumericAffinity(pIn3,0);
70828 }
70829 }else if( affinity==SQLITE_AFF_TEXT ){
70830 if( (pIn1->flags & MEM_Str)==0 && (pIn1->flags & (MEM_Int|MEM_Real))!=0 ){
70831 testcase( pIn1->flags & MEM_Int );
70832 testcase( pIn1->flags & MEM_Real );
70833 sqlite3VdbeMemStringify(pIn1, encoding, 1);
70834 }
70835 if( (pIn3->flags & MEM_Str)==0 && (pIn3->flags & (MEM_Int|MEM_Real))!=0 ){
70836 testcase( pIn3->flags & MEM_Int );
70837 testcase( pIn3->flags & MEM_Real );
70838 sqlite3VdbeMemStringify(pIn3, encoding, 1);
70839 }
70840 }
 
70841 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
70842 if( pIn1->flags & MEM_Zero ){
70843 sqlite3VdbeMemExpandBlob(pIn1);
70844 flags1 &= ~MEM_Zero;
70845 }
70846 if( pIn3->flags & MEM_Zero ){
70847 sqlite3VdbeMemExpandBlob(pIn3);
70848 flags3 &= ~MEM_Zero;
70849 }
70850 if( db->mallocFailed ) goto no_mem;
70851 res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
70852 }
70853 switch( pOp->opcode ){
70854 case OP_Eq: res = res==0; break;
70855 case OP_Ne: res = res!=0; break;
@@ -70567,12 +70870,12 @@
70870 if( res ){
70871 pc = pOp->p2-1;
70872 }
70873 }
70874 /* Undo any changes made by applyAffinity() to the input registers. */
70875 pIn1->flags = flags1;
70876 pIn3->flags = flags3;
70877 break;
70878 }
70879
70880 /* Opcode: Permutation * * * P4 *
70881 **
@@ -70736,14 +71039,14 @@
71039 ** NULL, then a NULL is stored in P2.
71040 */
71041 case OP_Not: { /* same as TK_NOT, in1, out2 */
71042 pIn1 = &aMem[pOp->p1];
71043 pOut = &aMem[pOp->p2];
71044 sqlite3VdbeMemSetNull(pOut);
71045 if( (pIn1->flags & MEM_Null)==0 ){
71046 pOut->flags = MEM_Int;
71047 pOut->u.i = !sqlite3VdbeIntValue(pIn1);
71048 }
71049 break;
71050 }
71051
71052 /* Opcode: BitNot P1 P2 * * *
@@ -70754,14 +71057,14 @@
71057 ** a NULL then store a NULL in P2.
71058 */
71059 case OP_BitNot: { /* same as TK_BITNOT, in1, out2 */
71060 pIn1 = &aMem[pOp->p1];
71061 pOut = &aMem[pOp->p2];
71062 sqlite3VdbeMemSetNull(pOut);
71063 if( (pIn1->flags & MEM_Null)==0 ){
71064 pOut->flags = MEM_Int;
71065 pOut->u.i = ~sqlite3VdbeIntValue(pIn1);
71066 }
71067 break;
71068 }
71069
71070 /* Opcode: Once P1 P2 * * *
@@ -70875,11 +71178,10 @@
71178 case OP_Column: {
71179 i64 payloadSize64; /* Number of bytes in the record */
71180 int p2; /* column number to retrieve */
71181 VdbeCursor *pC; /* The VDBE cursor */
71182 BtCursor *pCrsr; /* The BTree cursor */
 
71183 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
71184 int len; /* The length of the serialized data for the column */
71185 int i; /* Loop counter */
71186 Mem *pDest; /* Where to write the extracted value */
71187 Mem sMem; /* For storing the record being decoded */
@@ -70888,10 +71190,11 @@
71190 const u8 *zEndHdr; /* Pointer to first byte after the header */
71191 u32 offset; /* Offset into the data */
71192 u32 szField; /* Number of bytes in the content of a field */
71193 u32 avail; /* Number of bytes of available data */
71194 u32 t; /* A type code from the record header */
71195 u16 fx; /* pDest->flags value */
71196 Mem *pReg; /* PseudoTable input register */
71197
71198 p2 = pOp->p2;
71199 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
71200 pDest = &aMem[pOp->p3];
@@ -70898,12 +71201,11 @@
71201 memAboutToChange(p, pDest);
71202 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71203 pC = p->apCsr[pOp->p1];
71204 assert( pC!=0 );
71205 assert( p2<pC->nField );
71206 aOffset = pC->aType + pC->nField;
 
71207 #ifndef SQLITE_OMIT_VIRTUALTABLE
71208 assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
71209 #endif
71210 pCrsr = pC->pCursor;
71211 assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
@@ -70980,11 +71282,11 @@
71282 goto op_column_error;
71283 }
71284 }
71285
71286 /* Make sure at least the first p2+1 entries of the header have been
71287 ** parsed and valid information is in aOffset[] and pC->aType[].
71288 */
71289 if( pC->nHdrParsed<=p2 ){
71290 /* If there is more header available for parsing in the record, try
71291 ** to extract additional fields up through the p2+1-th field
71292 */
@@ -71000,11 +71302,11 @@
71302 zData = (u8*)sMem.z;
71303 }else{
71304 zData = pC->aRow;
71305 }
71306
71307 /* Fill in pC->aType[i] and aOffset[i] values through the p2-th field. */
71308 i = pC->nHdrParsed;
71309 offset = aOffset[i];
71310 zHdr = zData + pC->iHdrOffset;
71311 zEndHdr = zData + aOffset[0];
71312 assert( i<=p2 && zHdr<zEndHdr );
@@ -71013,11 +71315,11 @@
71315 t = zHdr[0];
71316 zHdr++;
71317 }else{
71318 zHdr += sqlite3GetVarint32(zHdr, &t);
71319 }
71320 pC->aType[i] = t;
71321 szField = sqlite3VdbeSerialTypeLen(t);
71322 offset += szField;
71323 if( offset<szField ){ /* True if offset overflows */
71324 zHdr = &zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
71325 break;
@@ -71060,65 +71362,65 @@
71362 goto op_column_out;
71363 }
71364 }
71365
71366 /* Extract the content for the p2+1-th column. Control can only
71367 ** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are
71368 ** all valid.
71369 */
71370 assert( p2<pC->nHdrParsed );
71371 assert( rc==SQLITE_OK );
71372 assert( sqlite3VdbeCheckMemInvariants(pDest) );
71373 if( VdbeMemDynamic(pDest) ) sqlite3VdbeMemSetNull(pDest);
71374 t = pC->aType[p2];
71375 if( pC->szRow>=aOffset[p2+1] ){
71376 /* This is the common case where the desired content fits on the original
71377 ** page - where the content is not on an overflow page */
71378 sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], t, pDest);
 
71379 }else{
71380 /* This branch happens only when content is on overflow pages */
 
71381 if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
71382 && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
71383 || (len = sqlite3VdbeSerialTypeLen(t))==0
71384 ){
71385 /* Content is irrelevant for
71386 ** 1. the typeof() function,
71387 ** 2. the length(X) function if X is a blob, and
71388 ** 3. if the content length is zero.
71389 ** So we might as well use bogus content rather than reading
71390 ** content from disk. NULL will work for the value for strings
71391 ** and blobs and whatever is in the payloadSize64 variable
71392 ** will work for everything else. */
71393 sqlite3VdbeSerialGet(t<=13 ? (u8*)&payloadSize64 : 0, t, pDest);
71394 }else{
 
 
71395 rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable,
71396 pDest);
71397 if( rc!=SQLITE_OK ){
71398 goto op_column_error;
71399 }
71400 sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
71401 pDest->flags &= ~MEM_Ephem;
 
 
 
 
 
 
 
 
 
 
 
 
 
71402 }
71403 }
71404 pDest->enc = encoding;
71405
71406 op_column_out:
71407 /* If the column value is an ephemeral string, go ahead and persist
71408 ** that string in case the cursor moves before the column value is
71409 ** used. The following code does the equivalent of Deephemeralize()
71410 ** but does it faster. */
71411 if( (pDest->flags & MEM_Ephem)!=0 && pDest->z ){
71412 fx = pDest->flags & (MEM_Str|MEM_Blob);
71413 assert( fx!=0 );
71414 zData = (const u8*)pDest->z;
71415 len = pDest->n;
71416 if( sqlite3VdbeMemClearAndResize(pDest, len+2) ) goto no_mem;
71417 memcpy(pDest->z, zData, len);
71418 pDest->z[len] = 0;
71419 pDest->z[len+1] = 0;
71420 pDest->flags = fx|MEM_Term;
71421 }
71422 op_column_error:
71423 UPDATE_MAX_BLOBSIZE(pDest);
71424 REGISTER_TRACE(pOp->p3, pDest);
71425 break;
71426 }
@@ -71189,11 +71491,11 @@
71491 ** ------------------------------------------------------------------------
71492 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
71493 ** ------------------------------------------------------------------------
71494 **
71495 ** Data(0) is taken from register P1. Data(1) comes from register P1+1
71496 ** and so forth.
71497 **
71498 ** Each type field is a varint representing the serial type of the
71499 ** corresponding data element (see sqlite3VdbeSerialType()). The
71500 ** hdr-size field is also a varint which is the offset from the beginning
71501 ** of the record to data0.
@@ -71265,13 +71567,13 @@
71567 }
71568
71569 /* Make sure the output register has a buffer large enough to store
71570 ** the new record. The output register (pOp->p3) is not allowed to
71571 ** be one of the input registers (because the following call to
71572 ** sqlite3VdbeMemClearAndResize() could clobber the value before it is used).
71573 */
71574 if( sqlite3VdbeMemClearAndResize(pOut, (int)nByte) ){
71575 goto no_mem;
71576 }
71577 zNewRecord = (u8 *)pOut->z;
71578
71579 /* Write the record */
@@ -71288,11 +71590,10 @@
71590 assert( j==nByte );
71591
71592 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
71593 pOut->n = (int)nByte;
71594 pOut->flags = MEM_Blob;
 
71595 if( nZero ){
71596 pOut->u.nZero = nZero;
71597 pOut->flags |= MEM_Zero;
71598 }
71599 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
@@ -72176,13 +72477,13 @@
72477 pC->seekOp = pOp->opcode;
72478 #endif
72479 if( pC->isTable ){
72480 /* The input value in P3 might be of any type: integer, real, string,
72481 ** blob, or NULL. But it needs to be an integer before we can do
72482 ** the seek, so convert it. */
72483 pIn3 = &aMem[pOp->p3];
72484 if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
72485 applyNumericAffinity(pIn3, 0);
72486 }
72487 iKey = sqlite3VdbeIntValue(pIn3);
72488 pC->rowidIsValid = 0;
72489
@@ -72201,20 +72502,20 @@
72502 ** is 4.9 and the integer approximation 5:
72503 **
72504 ** (x > 4.9) -> (x >= 5)
72505 ** (x <= 4.9) -> (x < 5)
72506 */
72507 if( pIn3->u.r<(double)iKey ){
72508 assert( OP_SeekGE==(OP_SeekGT-1) );
72509 assert( OP_SeekLT==(OP_SeekLE-1) );
72510 assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) );
72511 if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--;
72512 }
72513
72514 /* If the approximation iKey is smaller than the actual real search
72515 ** term, substitute <= for < and > for >=. */
72516 else if( pIn3->u.r>(double)iKey ){
72517 assert( OP_SeekLE==(OP_SeekLT+1) );
72518 assert( OP_SeekGT==(OP_SeekGE+1) );
72519 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
72520 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
72521 }
@@ -72972,11 +73273,11 @@
73273 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
73274 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
73275 goto too_big;
73276 }
73277 }
73278 if( sqlite3VdbeMemClearAndResize(pOut, n) ){
73279 goto no_mem;
73280 }
73281 pOut->n = n;
73282 MemSetTypeFlag(pOut, MEM_Blob);
73283 if( pC->isTable==0 ){
@@ -73482,11 +73783,11 @@
73783 r.aMem = &aMem[pOp->p3];
73784 #ifdef SQLITE_DEBUG
73785 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
73786 #endif
73787 res = 0; /* Not needed. Only used to silence a warning. */
73788 rc = sqlite3VdbeIdxKeyCompare(db, pC, &r, &res);
73789 assert( (OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1) );
73790 if( (pOp->opcode&1)==(OP_IdxLT&1) ){
73791 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT );
73792 res = -res;
73793 }else{
@@ -74252,15 +74553,11 @@
74553 }
74554 ctx.pFunc = pOp->p4.pFunc;
74555 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
74556 ctx.pMem = pMem = &aMem[pOp->p3];
74557 pMem->n++;
74558 sqlite3VdbeMemInit(&t, db, MEM_Null);
 
 
 
 
74559 ctx.pOut = &t;
74560 ctx.isError = 0;
74561 ctx.pColl = 0;
74562 ctx.skipFlag = 0;
74563 if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
@@ -76175,12 +76472,15 @@
76472 ** *pp is undefined in this case.
76473 */
76474 static int vdbeSorterMapFile(SortSubtask *pTask, SorterFile *pFile, u8 **pp){
76475 int rc = SQLITE_OK;
76476 if( pFile->iEof<=(i64)(pTask->pSorter->db->nMaxSorterMmap) ){
76477 sqlite3_file *pFd = pFile->pFd;
76478 if( pFd->pMethods->iVersion>=3 ){
76479 rc = sqlite3OsFetch(pFd, 0, (int)pFile->iEof, (void**)pp);
76480 testcase( rc!=SQLITE_OK );
76481 }
76482 }
76483 return rc;
76484 }
76485
76486 /*
@@ -76331,11 +76631,11 @@
76631 ){
76632 UnpackedRecord *r2 = pTask->pUnpacked;
76633 if( pKey2 ){
76634 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
76635 }
76636 return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
76637 }
76638
76639 /*
76640 ** Initialize the temporary index cursor just opened as a sorter cursor.
76641 **
@@ -76694,11 +76994,11 @@
76994 **
76995 ** Whether or not the file does end up memory mapped of course depends on
76996 ** the specific VFS implementation.
76997 */
76998 static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){
76999 if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){
77000 int rc = sqlite3OsTruncate(pFd, nByte);
77001 if( rc==SQLITE_OK ){
77002 void *p = 0;
77003 sqlite3OsFetch(pFd, 0, (int)nByte, &p);
77004 sqlite3OsUnfetch(pFd, 0, p);
@@ -77632,11 +77932,11 @@
77932 return pRet;
77933 }
77934
77935 /*
77936 ** Use a background thread to invoke vdbePmaReaderIncrMergeInit(INCRINIT_TASK)
77937 ** on the PmaReader object passed as the first argument.
77938 **
77939 ** This call will initialize the various fields of the pReadr->pIncr
77940 ** structure and, if it is a multi-threaded IncrMerger, launch a
77941 ** background thread to populate aFile[1].
77942 */
@@ -78031,11 +78331,11 @@
78331 SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *pCsr, Mem *pOut){
78332 VdbeSorter *pSorter = pCsr->pSorter;
78333 void *pKey; int nKey; /* Sorter key to copy into pOut */
78334
78335 pKey = vdbeSorterRowkey(pSorter, &nKey);
78336 if( sqlite3VdbeMemClearAndResize(pOut, nKey) ){
78337 return SQLITE_NOMEM;
78338 }
78339 pOut->n = nKey;
78340 MemSetTypeFlag(pOut, MEM_Blob);
78341 memcpy(pOut->z, pKey, nKey);
@@ -78087,11 +78387,11 @@
78387 *pRes = -1;
78388 return SQLITE_OK;
78389 }
78390 }
78391
78392 *pRes = sqlite3VdbeRecordCompare(pVal->n, pVal->z, r2);
78393 return SQLITE_OK;
78394 }
78395
78396 /************** End of vdbesort.c ********************************************/
78397 /************** Begin file journal.c *****************************************/
@@ -78378,11 +78678,11 @@
78678 /* Space to hold the rollback journal is allocated in increments of
78679 ** this many bytes.
78680 **
78681 ** The size chosen is a little less than a power of two. That way,
78682 ** the FileChunk object will have a size that almost exactly fills
78683 ** a power-of-two allocation. This minimizes wasted space in power-of-two
78684 ** memory allocators.
78685 */
78686 #define JOURNAL_CHUNKSIZE ((int)(1024-sizeof(FileChunk*)))
78687
78688 /*
@@ -78628,11 +78928,11 @@
78928 /* #include <string.h> */
78929
78930
78931 /*
78932 ** Walk an expression tree. Invoke the callback once for each node
78933 ** of the expression, while descending. (In other words, the callback
78934 ** is invoked before visiting children.)
78935 **
78936 ** The return value from the callback should be one of the WRC_*
78937 ** constants to specify how to proceed with the walk.
78938 **
@@ -79484,13 +79784,11 @@
79784 ** likelihood(X,0.9375). */
79785 /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
79786 pExpr->iTable = pDef->zName[0]=='u' ? 62 : 938;
79787 }
79788 }
 
79789 #ifndef SQLITE_OMIT_AUTHORIZATION
 
79790 auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
79791 if( auth!=SQLITE_OK ){
79792 if( auth==SQLITE_DENY ){
79793 sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
79794 pDef->zName);
@@ -79497,13 +79795,13 @@
79795 pNC->nErr++;
79796 }
79797 pExpr->op = TK_NULL;
79798 return WRC_Prune;
79799 }
79800 #endif
79801 if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ) ExprSetProperty(pExpr,EP_Constant);
79802 }
 
79803 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
79804 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
79805 pNC->nErr++;
79806 is_agg = 0;
79807 }else if( no_such_func && pParse->db->init.busy==0 ){
@@ -79522,11 +79820,17 @@
79820 pExpr->op2 = 0;
79821 while( pNC2 && !sqlite3FunctionUsesThisSrc(pExpr, pNC2->pSrcList) ){
79822 pExpr->op2++;
79823 pNC2 = pNC2->pNext;
79824 }
79825 assert( pDef!=0 );
79826 if( pNC2 ){
79827 assert( SQLITE_FUNC_MINMAX==NC_MinMaxAgg );
79828 testcase( (pDef->funcFlags & SQLITE_FUNC_MINMAX)!=0 );
79829 pNC2->ncFlags |= NC_HasAgg | (pDef->funcFlags & SQLITE_FUNC_MINMAX);
79830
79831 }
79832 pNC->ncFlags |= NC_AllowAgg;
79833 }
79834 /* FIX ME: Compute pExpr->affinity based on the expected return
79835 ** type of the function
79836 */
@@ -79883,11 +80187,11 @@
80187 }
80188 return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType);
80189 }
80190
80191 /*
80192 ** Resolve names in the SELECT statement p and all of its descendants.
80193 */
80194 static int resolveSelectStep(Walker *pWalker, Select *p){
80195 NameContext *pOuterNC; /* Context that contains this SELECT */
80196 NameContext sNC; /* Name context of this SELECT */
80197 int isCompound; /* True if p is a compound select */
@@ -79987,11 +80291,12 @@
80291 ** expression, do not allow aggregates in any of the other expressions.
80292 */
80293 assert( (p->selFlags & SF_Aggregate)==0 );
80294 pGroupBy = p->pGroupBy;
80295 if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){
80296 assert( NC_MinMaxAgg==SF_MinMaxAgg );
80297 p->selFlags |= SF_Aggregate | (sNC.ncFlags&NC_MinMaxAgg);
80298 }else{
80299 sNC.ncFlags &= ~NC_AllowAgg;
80300 }
80301
80302 /* If a HAVING clause is present, then there must be a GROUP BY clause.
@@ -80115,11 +80420,11 @@
80420 */
80421 SQLITE_PRIVATE int sqlite3ResolveExprNames(
80422 NameContext *pNC, /* Namespace to resolve expressions in. */
80423 Expr *pExpr /* The expression to be analyzed. */
80424 ){
80425 u16 savedHasAgg;
80426 Walker w;
80427
80428 if( pExpr==0 ) return 0;
80429 #if SQLITE_MAX_EXPR_DEPTH>0
80430 {
@@ -80128,12 +80433,12 @@
80433 return 1;
80434 }
80435 pParse->nHeight += pExpr->nHeight;
80436 }
80437 #endif
80438 savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg);
80439 pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg);
80440 memset(&w, 0, sizeof(w));
80441 w.xExprCallback = resolveExprStep;
80442 w.xSelectCallback = resolveSelectStep;
80443 w.pParse = pNC->pParse;
80444 w.u.pNC = pNC;
@@ -80144,13 +80449,12 @@
80449 if( pNC->nErr>0 || w.pParse->nErr>0 ){
80450 ExprSetProperty(pExpr, EP_Error);
80451 }
80452 if( pNC->ncFlags & NC_HasAgg ){
80453 ExprSetProperty(pExpr, EP_Agg);
 
 
80454 }
80455 pNC->ncFlags |= savedHasAgg;
80456 return ExprHasProperty(pExpr, EP_Error);
80457 }
80458
80459
80460 /*
@@ -80246,11 +80550,11 @@
80550 ** If pExpr is a column, a reference to a column via an 'AS' alias,
80551 ** or a sub-select with a column as the return value, then the
80552 ** affinity of that column is returned. Otherwise, 0x00 is returned,
80553 ** indicating no affinity for the expression.
80554 **
80555 ** i.e. the WHERE clause expressions in the following statements all
80556 ** have an affinity:
80557 **
80558 ** CREATE TABLE t1(a);
80559 ** SELECT * FROM t1 WHERE a;
80560 ** SELECT a AS b FROM t1 WHERE b;
@@ -80725,11 +81029,11 @@
81029 exprSetHeight(pRoot);
81030 }
81031 }
81032
81033 /*
81034 ** Allocate an Expr node which joins as many as two subtrees.
81035 **
81036 ** One or both of the subtrees can be NULL. Return a pointer to the new
81037 ** Expr node. Or, if an OOM error occurs, set pParse->db->mallocFailed,
81038 ** free the subtrees and return NULL.
81039 */
@@ -80835,11 +81139,11 @@
81139 ** sure "nnn" is not too be to avoid a denial of service attack when
81140 ** the SQL statement comes from an external source.
81141 **
81142 ** Wildcards of the form ":aaa", "@aaa", or "$aaa" are assigned the same number
81143 ** as the previous instance of the same wildcard. Or if this is the first
81144 ** instance of the wildcard, the next sequential variable number is
81145 ** assigned.
81146 */
81147 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
81148 sqlite3 *db = pParse->db;
81149 const char *z;
@@ -80970,11 +81274,11 @@
81274 ** Note that with flags==EXPRDUP_REDUCE, this routines works on full-size
81275 ** (unreduced) Expr objects as they or originally constructed by the parser.
81276 ** During expression analysis, extra information is computed and moved into
81277 ** later parts of teh Expr object and that extra information might get chopped
81278 ** off if the expression is reduced. Note also that it does not work to
81279 ** make an EXPRDUP_REDUCE copy of a reduced expression. It is only legal
81280 ** to reduce a pristine expression tree from the parser. The implementation
81281 ** of dupedExprStructSize() contain multiple assert() statements that attempt
81282 ** to enforce this constraint.
81283 */
81284 static int dupedExprStructSize(Expr *p, int flags){
@@ -81039,11 +81343,11 @@
81343 /*
81344 ** This function is similar to sqlite3ExprDup(), except that if pzBuffer
81345 ** is not NULL then *pzBuffer is assumed to point to a buffer large enough
81346 ** to store the copy of expression p, the copies of p->u.zToken
81347 ** (if applicable), and the copies of the p->pLeft and p->pRight expressions,
81348 ** if any. Before returning, *pzBuffer is set to the first byte past the
81349 ** portion of the buffer copied into by this function.
81350 */
81351 static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
81352 Expr *pNew = 0; /* Value to return */
81353 if( p ){
@@ -81765,11 +82069,11 @@
82069 **
82070 ** SELECT <column> FROM <table>
82071 **
82072 ** If the RHS of the IN operator is a list or a more complex subquery, then
82073 ** an ephemeral table might need to be generated from the RHS and then
82074 ** pX->iTable made to point to the ephemeral table instead of an
82075 ** existing table.
82076 **
82077 ** The inFlags parameter must contain exactly one of the bits
82078 ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP. If inFlags contains
82079 ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a
@@ -81895,11 +82199,11 @@
82199
82200 /* If no preexisting index is available for the IN clause
82201 ** and IN_INDEX_NOOP is an allowed reply
82202 ** and the RHS of the IN operator is a list, not a subquery
82203 ** and the RHS is not contant or has two or fewer terms,
82204 ** then it is not worth creating an ephemeral table to evaluate
82205 ** the IN operator so return IN_INDEX_NOOP.
82206 */
82207 if( eType==0
82208 && (inFlags & IN_INDEX_NOOP_OK)
82209 && !ExprHasProperty(pX, EP_xIsSelect)
@@ -82656,20 +82960,13 @@
82960 /*
82961 ** Generate code to move content from registers iFrom...iFrom+nReg-1
82962 ** over to iTo..iTo+nReg-1. Keep the column cache up-to-date.
82963 */
82964 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse *pParse, int iFrom, int iTo, int nReg){
 
 
82965 assert( iFrom>=iTo+nReg || iFrom+nReg<=iTo );
82966 sqlite3VdbeAddOp3(pParse->pVdbe, OP_Move, iFrom, iTo, nReg);
82967 sqlite3ExprCacheRemove(pParse, iFrom, nReg);
 
 
 
 
 
82968 }
82969
82970 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
82971 /*
82972 ** Return true if any register in the range iFrom..iTo (inclusive)
@@ -82982,11 +83279,11 @@
83279 sqlite3ErrorMsg(pParse, "unknown function: %.*s()", nId, zId);
83280 break;
83281 }
83282
83283 /* Attempt a direct implementation of the built-in COALESCE() and
83284 ** IFNULL() functions. This avoids unnecessary evaluation of
83285 ** arguments past the first non-NULL argument.
83286 */
83287 if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
83288 int endCoalesce = sqlite3VdbeMakeLabel(v);
83289 assert( nFarg>=2 );
@@ -83421,11 +83718,11 @@
83718 sqlite3ExprCode(pParse, pExpr, target);
83719 }
83720 }
83721
83722 /*
83723 ** Generate code that evaluates the given expression and puts the result
83724 ** in register target.
83725 **
83726 ** Also make a copy of the expression results into another "cache" register
83727 ** and modify the expression so that the next time it is evaluated,
83728 ** the result is a copy of the cache register.
@@ -83776,11 +84073,11 @@
84073 ** The above is equivalent to
84074 **
84075 ** x>=y AND x<=z
84076 **
84077 ** Code it as such, taking care to do the common subexpression
84078 ** elimination of x.
84079 */
84080 static void exprCodeBetween(
84081 Parse *pParse, /* Parsing and code generating context */
84082 Expr *pExpr, /* The BETWEEN expression */
84083 int dest, /* Jump here if the jump is taken */
@@ -84513,11 +84810,11 @@
84810 /*
84811 ** Deallocate a register, making available for reuse for some other
84812 ** purpose.
84813 **
84814 ** If a register is currently being used by the column cache, then
84815 ** the deallocation is deferred until the column cache line that uses
84816 ** the register becomes stale.
84817 */
84818 SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){
84819 if( iReg && pParse->nTempReg<ArraySize(pParse->aTempReg) ){
84820 int i;
@@ -84740,12 +85037,12 @@
85037 sqlite3 *db = sqlite3_context_db_handle(context);
85038
85039 UNUSED_PARAMETER(NotUsed);
85040
85041 /* The principle used to locate the table name in the CREATE TRIGGER
85042 ** statement is that the table name is the first token that is immediately
85043 ** preceded by either TK_ON or TK_DOT and immediately followed by one
85044 ** of TK_WHEN, TK_BEGIN or TK_FOR.
85045 */
85046 if( zSql ){
85047 do {
85048
@@ -85432,11 +85729,11 @@
85729 ** version of sqlite_stat3 and is only available when compiled with
85730 ** SQLITE_ENABLE_STAT4 and in SQLite versions 3.8.1 and later. It is
85731 ** not possible to enable both STAT3 and STAT4 at the same time. If they
85732 ** are both enabled, then STAT4 takes precedence.
85733 **
85734 ** For most applications, sqlite_stat1 provides all the statistics required
85735 ** for the query planner to make good choices.
85736 **
85737 ** Format of sqlite_stat1:
85738 **
85739 ** There is normally one row per index, with the index identified by the
@@ -85783,12 +86080,13 @@
86080 ** WITHOUT ROWID tables, N=K+P where P is the number of columns in the
86081 ** PRIMARY KEY of the table. The covering index that implements the
86082 ** original WITHOUT ROWID table as N==K as a special case.
86083 **
86084 ** This routine allocates the Stat4Accum object in heap memory. The return
86085 ** value is a pointer to the Stat4Accum object. The datatype of the
86086 ** return value is BLOB, but it is really just a pointer to the Stat4Accum
86087 ** object.
86088 */
86089 static void statInit(
86090 sqlite3_context *context,
86091 int argc,
86092 sqlite3_value **argv
@@ -85862,12 +86160,15 @@
86160 p->aBest[i].iCol = i;
86161 }
86162 }
86163 #endif
86164
86165 /* Return a pointer to the allocated object to the caller. Note that
86166 ** only the pointer (the 2nd parameter) matters. The size of the object
86167 ** (given by the 3rd parameter) is never used and can be any positive
86168 ** value. */
86169 sqlite3_result_blob(context, p, sizeof(*p), stat4Destructor);
86170 }
86171 static const FuncDef statInitFuncdef = {
86172 2+IsStat34, /* nArg */
86173 SQLITE_UTF8, /* funcFlags */
86174 0, /* pUserData */
@@ -86189,11 +86490,11 @@
86490
86491 /*
86492 ** Implementation of the stat_get(P,J) SQL function. This routine is
86493 ** used to query statistical information that has been gathered into
86494 ** the Stat4Accum object by prior calls to stat_push(). The P parameter
86495 ** has type BLOB but it is really just a pointer to the Stat4Accum object.
86496 ** The content to returned is determined by the parameter J
86497 ** which is one of the STAT_GET_xxxx values defined above.
86498 **
86499 ** If neither STAT3 nor STAT4 are enabled, then J is always
86500 ** STAT_GET_STAT1 and is hence omitted and this routine becomes
@@ -86593,11 +86894,12 @@
86894 sqlite3VdbeChangeP5(v, 2+IsStat34);
86895 sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
86896
86897 /* Add the entry to the stat1 table. */
86898 callStatGet(v, regStat4, STAT_GET_STAT1, regStat1);
86899 assert( "BBB"[0]==SQLITE_AFF_TEXT );
86900 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
86901 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
86902 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
86903 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
86904
86905 /* Add the entries to the stat3 or stat4 table. */
@@ -86656,11 +86958,12 @@
86958 if( pOnlyIdx==0 && needTableCnt ){
86959 VdbeComment((v, "%s", pTab->zName));
86960 sqlite3VdbeAddOp2(v, OP_Count, iTabCur, regStat1);
86961 jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1); VdbeCoverage(v);
86962 sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
86963 assert( "BBB"[0]==SQLITE_AFF_TEXT );
86964 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
86965 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
86966 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
86967 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
86968 sqlite3VdbeJumpHere(v, jZeroRows);
86969 }
@@ -86975,11 +87278,11 @@
87278 tRowcnt nDLt = pFinal->anDLt[iCol];
87279
87280 /* Set nSum to the number of distinct (iCol+1) field prefixes that
87281 ** occur in the stat4 table for this index before pFinal. Set
87282 ** sumEq to the sum of the nEq values for column iCol for the same
87283 ** set (adding the value only once where there exist duplicate
87284 ** prefixes). */
87285 for(i=0; i<(pIdx->nSample-1); i++){
87286 if( aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol] ){
87287 sumEq += aSample[i].anEq[iCol];
87288 nSum++;
@@ -87457,10 +87760,19 @@
87760 if( rc==SQLITE_OK ){
87761 sqlite3BtreeEnterAll(db);
87762 rc = sqlite3Init(db, &zErrDyn);
87763 sqlite3BtreeLeaveAll(db);
87764 }
87765 #ifdef SQLITE_USER_AUTHENTICATION
87766 if( rc==SQLITE_OK ){
87767 u8 newAuth = 0;
87768 rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
87769 if( newAuth<db->auth.authLevel ){
87770 rc = SQLITE_AUTH_USER;
87771 }
87772 }
87773 #endif
87774 if( rc ){
87775 int iDb = db->nDb - 1;
87776 assert( iDb>=2 );
87777 if( db->aDb[iDb].pBt ){
87778 sqlite3BtreeClose(db->aDb[iDb].pBt);
@@ -87899,11 +88211,11 @@
88211 sqlite3 *db,
88212 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
88213 void *pArg
88214 ){
88215 sqlite3_mutex_enter(db->mutex);
88216 db->xAuth = (sqlite3_xauth)xAuth;
88217 db->pAuthArg = pArg;
88218 sqlite3ExpirePreparedStatements(db);
88219 sqlite3_mutex_leave(db->mutex);
88220 return SQLITE_OK;
88221 }
@@ -87934,11 +88246,15 @@
88246 ){
88247 sqlite3 *db = pParse->db; /* Database handle */
88248 char *zDb = db->aDb[iDb].zName; /* Name of attached database */
88249 int rc; /* Auth callback return code */
88250
88251 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext
88252 #ifdef SQLITE_USER_AUTHENTICATION
88253 ,db->auth.zAuthUser
88254 #endif
88255 );
88256 if( rc==SQLITE_DENY ){
88257 if( db->nDb>2 || iDb!=0 ){
88258 sqlite3ErrorMsg(pParse, "access to %s.%s.%s is prohibited",zDb,zTab,zCol);
88259 }else{
88260 sqlite3ErrorMsg(pParse, "access to %s.%s is prohibited", zTab, zCol);
@@ -88034,11 +88350,15 @@
88350 }
88351
88352 if( db->xAuth==0 ){
88353 return SQLITE_OK;
88354 }
88355 rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext
88356 #ifdef SQLITE_USER_AUTHENTICATION
88357 ,db->auth.zAuthUser
88358 #endif
88359 );
88360 if( rc==SQLITE_DENY ){
88361 sqlite3ErrorMsg(pParse, "not authorized");
88362 pParse->rc = SQLITE_AUTH;
88363 }else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){
88364 rc = SQLITE_DENY;
@@ -88232,10 +88552,21 @@
88552 assert( !pParse->isMultiWrite
88553 || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort));
88554 if( v ){
88555 while( sqlite3VdbeDeletePriorOpcode(v, OP_Close) ){}
88556 sqlite3VdbeAddOp0(v, OP_Halt);
88557
88558 #if SQLITE_USER_AUTHENTICATION
88559 if( pParse->nTableLock>0 && db->init.busy==0 ){
88560 sqlite3UserAuthInit(db);
88561 if( db->auth.authLevel<UAUTH_User ){
88562 pParse->rc = SQLITE_AUTH_USER;
88563 sqlite3ErrorMsg(pParse, "user not authenticated");
88564 return;
88565 }
88566 }
88567 #endif
88568
88569 /* The cookie mask contains one bit for each database file open.
88570 ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
88571 ** set for each database that is used. Generate code to start a
88572 ** transaction on each used database and to verify the schema cookie
@@ -88348,10 +88679,20 @@
88679 sqlite3DbFree(db, zSql);
88680 memcpy(&pParse->nVar, saveBuf, SAVE_SZ);
88681 pParse->nested--;
88682 }
88683
88684 #if SQLITE_USER_AUTHENTICATION
88685 /*
88686 ** Return TRUE if zTable is the name of the system table that stores the
88687 ** list of users and their access credentials.
88688 */
88689 SQLITE_PRIVATE int sqlite3UserAuthTable(const char *zTable){
88690 return sqlite3_stricmp(zTable, "sqlite_user")==0;
88691 }
88692 #endif
88693
88694 /*
88695 ** Locate the in-memory structure that describes a particular database
88696 ** table given the name of that table and (optionally) the name of the
88697 ** database containing the table. Return NULL if not found.
88698 **
@@ -88366,10 +88707,17 @@
88707 Table *p = 0;
88708 int i;
88709 assert( zName!=0 );
88710 /* All mutexes are required for schema access. Make sure we hold them. */
88711 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
88712 #if SQLITE_USER_AUTHENTICATION
88713 /* Only the admin user is allowed to know that the sqlite_user table
88714 ** exists */
88715 if( db->auth.authLevel<UAUTH_Admin && sqlite3UserAuthTable(zName)!=0 ){
88716 return 0;
88717 }
88718 #endif
88719 for(i=OMIT_TEMPDB; i<db->nDb; i++){
88720 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
88721 if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
88722 assert( sqlite3SchemaMutexHeld(db, j, 0) );
88723 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
@@ -88410,10 +88758,16 @@
88758 }else{
88759 sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
88760 }
88761 pParse->checkSchema = 1;
88762 }
88763 #if SQLITE_USER_AUTHENICATION
88764 else if( pParse->db->auth.authLevel<UAUTH_User ){
88765 sqlite3ErrorMsg(pParse, "user not authenticated");
88766 p = 0;
88767 }
88768 #endif
88769 return p;
88770 }
88771
88772 /*
88773 ** Locate the table identified by *p.
@@ -89220,11 +89574,11 @@
89574
89575 /* If pszEst is not NULL, store an estimate of the field size. The
89576 ** estimate is scaled so that the size of an integer is 1. */
89577 if( pszEst ){
89578 *pszEst = 1; /* default size is approx 4 bytes */
89579 if( aff<SQLITE_AFF_NUMERIC ){
89580 if( zChar ){
89581 while( zChar[0] ){
89582 if( sqlite3Isdigit(zChar[0]) ){
89583 int v = 0;
89584 sqlite3GetInt32(zChar, &v);
@@ -89591,12 +89945,12 @@
89945 k = sqlite3Strlen30(zStmt);
89946 identPut(zStmt, &k, p->zName);
89947 zStmt[k++] = '(';
89948 for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){
89949 static const char * const azType[] = {
 
89950 /* SQLITE_AFF_NONE */ "",
89951 /* SQLITE_AFF_TEXT */ " TEXT",
89952 /* SQLITE_AFF_NUMERIC */ " NUM",
89953 /* SQLITE_AFF_INTEGER */ " INT",
89954 /* SQLITE_AFF_REAL */ " REAL"
89955 };
89956 int len;
@@ -89604,19 +89958,19 @@
89958
89959 sqlite3_snprintf(n-k, &zStmt[k], zSep);
89960 k += sqlite3Strlen30(&zStmt[k]);
89961 zSep = zSep2;
89962 identPut(zStmt, &k, pCol->zName);
89963 assert( pCol->affinity-SQLITE_AFF_NONE >= 0 );
89964 assert( pCol->affinity-SQLITE_AFF_NONE < ArraySize(azType) );
 
89965 testcase( pCol->affinity==SQLITE_AFF_NONE );
89966 testcase( pCol->affinity==SQLITE_AFF_TEXT );
89967 testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
89968 testcase( pCol->affinity==SQLITE_AFF_INTEGER );
89969 testcase( pCol->affinity==SQLITE_AFF_REAL );
89970
89971 zType = azType[pCol->affinity - SQLITE_AFF_NONE];
89972 len = sqlite3Strlen30(zType);
89973 assert( pCol->affinity==SQLITE_AFF_NONE
89974 || pCol->affinity==sqlite3AffinityType(zType, 0) );
89975 memcpy(&zStmt[k], zType, len);
89976 k += len;
@@ -89696,11 +90050,11 @@
90050 **
90051 ** (1) Convert the OP_CreateTable into an OP_CreateIndex. There is
90052 ** no rowid btree for a WITHOUT ROWID. Instead, the canonical
90053 ** data storage is a covering index btree.
90054 ** (2) Bypass the creation of the sqlite_master table entry
90055 ** for the PRIMARY KEY as the primary key index is now
90056 ** identified by the sqlite_master table entry of the table itself.
90057 ** (3) Set the Index.tnum of the PRIMARY KEY Index object in the
90058 ** schema to the rootpage from the main table.
90059 ** (4) Set all columns of the PRIMARY KEY schema object to be NOT NULL.
90060 ** (5) Add all table columns to the PRIMARY KEY Index object
@@ -89717,11 +90071,11 @@
90071 int i, j;
90072 sqlite3 *db = pParse->db;
90073 Vdbe *v = pParse->pVdbe;
90074
90075 /* Convert the OP_CreateTable opcode that would normally create the
90076 ** root-page for the table into an OP_CreateIndex opcode. The index
90077 ** created will become the PRIMARY KEY index.
90078 */
90079 if( pParse->addrCrTab ){
90080 assert( v );
90081 sqlite3VdbeGetOp(v, pParse->addrCrTab)->opcode = OP_CreateIndex;
@@ -90129,11 +90483,11 @@
90483 Table *pSelTab; /* A fake table from which we get the result set */
90484 Select *pSel; /* Copy of the SELECT that implements the view */
90485 int nErr = 0; /* Number of errors encountered */
90486 int n; /* Temporarily holds the number of cursors assigned */
90487 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
90488 sqlite3_xauth xAuth; /* Saved xAuth pointer */
90489
90490 assert( pTable );
90491
90492 #ifndef SQLITE_OMIT_VIRTUALTABLE
90493 if( sqlite3VtabCallConnect(pParse, pTable) ){
@@ -90731,11 +91085,11 @@
91085 int addr2; /* Address to jump to for next iteration */
91086 int tnum; /* Root page of index */
91087 int iPartIdxLabel; /* Jump to this label to skip a row */
91088 Vdbe *v; /* Generate code into this virtual machine */
91089 KeyInfo *pKey; /* KeyInfo for index */
91090 int regRecord; /* Register holding assembled index record */
91091 sqlite3 *db = pParse->db; /* The database connection */
91092 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
91093
91094 #ifndef SQLITE_OMIT_AUTHORIZATION
91095 if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
@@ -90944,10 +91298,14 @@
91298 pDb = &db->aDb[iDb];
91299
91300 assert( pTab!=0 );
91301 assert( pParse->nErr==0 );
91302 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
91303 && db->init.busy==0
91304 #if SQLITE_USER_AUTHENTICATION
91305 && sqlite3UserAuthTable(pTab->zName)==0
91306 #endif
91307 && sqlite3StrNICmp(&pTab->zName[7],"altertab_",9)!=0 ){
91308 sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
91309 goto exit_create_index;
91310 }
91311 #ifndef SQLITE_OMIT_VIEW
@@ -91331,11 +91689,11 @@
91689
91690 /*
91691 ** Fill the Index.aiRowEst[] array with default information - information
91692 ** to be used when we have not run the ANALYZE command.
91693 **
91694 ** aiRowEst[0] is supposed to contain the number of elements in the index.
91695 ** Since we do not know, guess 1 million. aiRowEst[1] is an estimate of the
91696 ** number of rows in the table that match any particular value of the
91697 ** first column of the index. aiRowEst[2] is an estimate of the number
91698 ** of rows that match any particular combination of the first 2 columns
91699 ** of the index. And so forth. It must always be the case that
@@ -91710,11 +92068,11 @@
92068 ** end of a growing FROM clause. The "p" parameter is the part of
92069 ** the FROM clause that has already been constructed. "p" is NULL
92070 ** if this is the first term of the FROM clause. pTable and pDatabase
92071 ** are the name of the table and database named in the FROM clause term.
92072 ** pDatabase is NULL if the database name qualifier is missing - the
92073 ** usual case. If the term has an alias, then pAlias points to the
92074 ** alias token. If the term is a subquery, then pSubquery is the
92075 ** SELECT statement that the subquery encodes. The pTable and
92076 ** pDatabase parameters are NULL for subqueries. The pOn and pUsing
92077 ** parameters are the content of the ON and USING clauses.
92078 **
@@ -92473,11 +92831,11 @@
92831 ** specified by zName and nName is not found and parameter 'create' is
92832 ** true, then create a new entry. Otherwise return NULL.
92833 **
92834 ** Each pointer stored in the sqlite3.aCollSeq hash table contains an
92835 ** array of three CollSeq structures. The first is the collation sequence
92836 ** preferred for UTF-8, the second UTF-16le, and the third UTF-16be.
92837 **
92838 ** Stored immediately after the three collation sequences is a copy of
92839 ** the collation sequence name. A pointer to this string is stored in
92840 ** each collation sequence structure.
92841 */
@@ -92900,11 +93258,11 @@
93258 */
93259 SQLITE_PRIVATE void sqlite3MaterializeView(
93260 Parse *pParse, /* Parsing context */
93261 Table *pView, /* View definition */
93262 Expr *pWhere, /* Optional WHERE clause to be added */
93263 int iCur /* Cursor number for ephemeral table */
93264 ){
93265 SelectDest dest;
93266 Select *pSel;
93267 SrcList *pFrom;
93268 sqlite3 *db = pParse->db;
@@ -93058,11 +93416,11 @@
93416 int iEphCur = 0; /* Ephemeral table holding all primary key values */
93417 int iRowSet = 0; /* Register for rowset of rows to delete */
93418 int addrBypass = 0; /* Address of jump over the delete logic */
93419 int addrLoop = 0; /* Top of the delete loop */
93420 int addrDelete = 0; /* Jump directly to the delete logic */
93421 int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
93422
93423 #ifndef SQLITE_OMIT_TRIGGER
93424 int isView; /* True if attempting to delete from a view */
93425 Trigger *pTrigger; /* List of table triggers, if required */
93426 #endif
@@ -93138,11 +93496,11 @@
93496 }
93497 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
93498 sqlite3BeginWriteOperation(pParse, 1, iDb);
93499
93500 /* If we are trying to delete from a view, realize that view into
93501 ** an ephemeral table.
93502 */
93503 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
93504 if( isView ){
93505 sqlite3MaterializeView(pParse, pTab, pWhere, iTabCur);
93506 iDataCur = iIdxCur = iTabCur;
@@ -93192,11 +93550,11 @@
93550 pPk = 0;
93551 nPk = 1;
93552 iRowSet = ++pParse->nMem;
93553 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
93554 }else{
93555 /* For a WITHOUT ROWID table, create an ephemeral table used to
93556 ** hold all primary keys for rows to be deleted. */
93557 pPk = sqlite3PrimaryKeyIndex(pTab);
93558 assert( pPk!=0 );
93559 nPk = pPk->nKeyCol;
93560 iPk = pParse->nMem+1;
@@ -93367,11 +93725,11 @@
93725 sqlite3ExprDelete(db, pWhere);
93726 sqlite3DbFree(db, aToOpen);
93727 return;
93728 }
93729 /* Make sure "isView" and other macros defined above are undefined. Otherwise
93730 ** they may interfere with compilation of other functions in this file
93731 ** (or in another file, if this file becomes part of the amalgamation). */
93732 #ifdef isView
93733 #undef isView
93734 #endif
93735 #ifdef pTrigger
@@ -93661,11 +94019,11 @@
94019 ** May you do good and not evil.
94020 ** May you find forgiveness for yourself and forgive others.
94021 ** May you share freely, never taking more than you give.
94022 **
94023 *************************************************************************
94024 ** This file contains the C-language implementations for many of the SQL
94025 ** functions of SQLite. (Some function, and in particular the date and
94026 ** time functions, are implemented separately.)
94027 */
94028 /* #include <stdlib.h> */
94029 /* #include <assert.h> */
@@ -93975,17 +94333,18 @@
94333 p1--;
94334 }
94335 for(z2=z; *z2 && p2; p2--){
94336 SQLITE_SKIP_UTF8(z2);
94337 }
94338 sqlite3_result_text64(context, (char*)z, z2-z, SQLITE_TRANSIENT,
94339 SQLITE_UTF8);
94340 }else{
94341 if( p1+p2>len ){
94342 p2 = len-p1;
94343 if( p2<0 ) p2 = 0;
94344 }
94345 sqlite3_result_blob64(context, (char*)&z[p1], (u64)p2, SQLITE_TRANSIENT);
94346 }
94347 }
94348
94349 /*
94350 ** Implementation of the round() function
@@ -94040,11 +94399,11 @@
94399 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
94400 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
94401 sqlite3_result_error_toobig(context);
94402 z = 0;
94403 }else{
94404 z = sqlite3Malloc(nByte);
94405 if( !z ){
94406 sqlite3_result_error_nomem(context);
94407 }
94408 }
94409 return z;
@@ -94691,11 +95050,11 @@
95050 *zOut++ = 0x80 + (u8)((c>>12) & 0x3F);
95051 *zOut++ = 0x80 + (u8)((c>>6) & 0x3F);
95052 *zOut++ = 0x80 + (u8)(c & 0x3F);
95053 } \
95054 }
95055 sqlite3_result_text64(context, (char*)z, zOut-z, sqlite3_free, SQLITE_UTF8);
95056 }
95057
95058 /*
95059 ** The hex() function. Interpret the argument as a blob. Return
95060 ** a hexadecimal rendering as text.
@@ -95141,10 +95500,11 @@
95500 sqlite3VdbeMemCopy(pBest, pArg);
95501 }else{
95502 sqlite3SkipAccumulatorLoad(context);
95503 }
95504 }else{
95505 pBest->db = sqlite3_context_db_handle(context);
95506 sqlite3VdbeMemCopy(pBest, pArg);
95507 }
95508 }
95509 static void minMaxFinalize(sqlite3_context *context){
95510 sqlite3_value *pRes;
@@ -95288,11 +95648,11 @@
95648 *pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0;
95649 return 1;
95650 }
95651
95652 /*
95653 ** All of the FuncDef structures in the aBuiltinFunc[] array above
95654 ** to the global function hash table. This occurs at start-time (as
95655 ** a consequence of calling sqlite3_initialize()).
95656 **
95657 ** After this routine runs
95658 */
@@ -95312,14 +95672,16 @@
95672 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
95673 FUNCTION(trim, 1, 3, 0, trimFunc ),
95674 FUNCTION(trim, 2, 3, 0, trimFunc ),
95675 FUNCTION(min, -1, 0, 1, minmaxFunc ),
95676 FUNCTION(min, 0, 0, 1, 0 ),
95677 AGGREGATE2(min, 1, 0, 1, minmaxStep, minMaxFinalize,
95678 SQLITE_FUNC_MINMAX ),
95679 FUNCTION(max, -1, 1, 1, minmaxFunc ),
95680 FUNCTION(max, 0, 1, 1, 0 ),
95681 AGGREGATE2(max, 1, 1, 1, minmaxStep, minMaxFinalize,
95682 SQLITE_FUNC_MINMAX ),
95683 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
95684 FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
95685 FUNCTION(instr, 2, 0, 0, instrFunc ),
95686 FUNCTION(substr, 2, 0, 0, substrFunc ),
95687 FUNCTION(substr, 3, 0, 0, substrFunc ),
@@ -95345,10 +95707,13 @@
95707 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
95708 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
95709 FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
95710 FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
95711 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
95712 #if SQLITE_USER_AUTHENTICATION
95713 FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ),
95714 #endif
95715 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
95716 FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
95717 FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
95718 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
95719 FUNCTION(quote, 1, 0, 0, quoteFunc ),
@@ -95365,12 +95730,12 @@
95730 FUNCTION(load_extension, 2, 0, 0, loadExt ),
95731 #endif
95732 AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ),
95733 AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ),
95734 AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ),
95735 AGGREGATE2(count, 0, 0, 0, countStep, countFinalize,
95736 SQLITE_FUNC_COUNT ),
95737 AGGREGATE(count, 1, 0, 0, countStep, countFinalize ),
95738 AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, groupConcatFinalize),
95739 AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, groupConcatFinalize),
95740
95741 LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
@@ -95573,11 +95938,11 @@
95938 ** foreign key definition, and the parent table does not have a
95939 ** PRIMARY KEY, or
95940 **
95941 ** 4) No parent key columns were provided explicitly as part of the
95942 ** foreign key definition, and the PRIMARY KEY of the parent table
95943 ** consists of a different number of columns to the child key in
95944 ** the child table.
95945 **
95946 ** then non-zero is returned, and a "foreign key mismatch" error loaded
95947 ** into pParse. If an OOM error occurs, non-zero is returned and the
95948 ** pParse->db->mallocFailed flag is set.
@@ -96820,17 +97185,17 @@
97185 ** pIdx. A column affinity string has one character for each column in
97186 ** the table, according to the affinity of the column:
97187 **
97188 ** Character Column affinity
97189 ** ------------------------------
97190 ** 'A' NONE
97191 ** 'B' TEXT
97192 ** 'C' NUMERIC
97193 ** 'D' INTEGER
97194 ** 'F' REAL
97195 **
97196 ** An extra 'D' is appended to the end of the string to cover the
97197 ** rowid that appears as the last column in every index.
97198 **
97199 ** Memory for the buffer containing the column index affinity string
97200 ** is managed along with the rest of the Index structure. It will be
97201 ** released when sqlite3DeleteIndex() is called.
@@ -96875,15 +97240,15 @@
97240 **
97241 ** A column affinity string has one character per column:
97242 **
97243 ** Character Column affinity
97244 ** ------------------------------
97245 ** 'A' NONE
97246 ** 'B' TEXT
97247 ** 'C' NUMERIC
97248 ** 'D' INTEGER
97249 ** 'E' REAL
97250 */
97251 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
97252 int i;
97253 char *zColAff = pTab->zColAff;
97254 if( zColAff==0 ){
@@ -97174,11 +97539,11 @@
97539 ** D: cleanup
97540 **
97541 ** The 4th template is used if the insert statement takes its
97542 ** values from a SELECT but the data is being inserted into a table
97543 ** that is also read as part of the SELECT. In the third form,
97544 ** we have to use an intermediate table to store the results of
97545 ** the select. The template is like this:
97546 **
97547 ** X <- A
97548 ** goto B
97549 ** A: setup for the SELECT
@@ -97339,11 +97704,11 @@
97704 ** sqlite_sequence table and store it in memory cell regAutoinc.
97705 */
97706 regAutoinc = autoIncBegin(pParse, iDb, pTab);
97707
97708 /* Allocate registers for holding the rowid of the new row,
97709 ** the content of the new row, and the assembled row record.
97710 */
97711 regRowid = regIns = pParse->nMem+1;
97712 pParse->nMem += pTab->nCol + 1;
97713 if( IsVirtual(pTab) ){
97714 regRowid++;
@@ -97791,11 +98156,11 @@
98156 sqlite3IdListDelete(db, pColumn);
98157 sqlite3DbFree(db, aRegIdx);
98158 }
98159
98160 /* Make sure "isView" and other macros defined above are undefined. Otherwise
98161 ** they may interfere with compilation of other functions in this file
98162 ** (or in another file, if this file becomes part of the amalgamation). */
98163 #ifdef isView
98164 #undef isView
98165 #endif
98166 #ifdef pTrigger
@@ -97907,11 +98272,11 @@
98272 sqlite3 *db; /* Database connection */
98273 int i; /* loop counter */
98274 int ix; /* Index loop counter */
98275 int nCol; /* Number of columns */
98276 int onError; /* Conflict resolution strategy */
98277 int j1; /* Address of jump instruction */
98278 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
98279 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
98280 int ipkTop = 0; /* Top of the rowid change constraint check */
98281 int ipkBottom = 0; /* Bottom of the rowid change constraint check */
98282 u8 isUpdate; /* True if this is an UPDATE operation */
@@ -98311,11 +98676,11 @@
98676 ){
98677 Vdbe *v; /* Prepared statements under construction */
98678 Index *pIdx; /* An index being inserted or updated */
98679 u8 pik_flags; /* flag values passed to the btree insert */
98680 int regData; /* Content registers (after the rowid) */
98681 int regRec; /* Register holding assembled record for the table */
98682 int i; /* Loop counter */
98683 u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */
98684
98685 v = sqlite3GetVdbe(pParse);
98686 assert( v!=0 );
@@ -98436,11 +98801,11 @@
98801 #ifdef SQLITE_TEST
98802 /*
98803 ** The following global variable is incremented whenever the
98804 ** transfer optimization is used. This is used for testing
98805 ** purposes only - to make sure the transfer optimization really
98806 ** is happening when it is supposed to.
98807 */
98808 SQLITE_API int sqlite3_xferopt_count;
98809 #endif /* SQLITE_TEST */
98810
98811
@@ -98503,11 +98868,11 @@
98868 ** Attempt the transfer optimization on INSERTs of the form
98869 **
98870 ** INSERT INTO tab1 SELECT * FROM tab2;
98871 **
98872 ** The xfer optimization transfers raw records from tab2 over to tab1.
98873 ** Columns are not decoded and reassembled, which greatly improves
98874 ** performance. Raw index records are transferred in the same way.
98875 **
98876 ** The xfer optimization is only attempted if tab1 and tab2 are compatible.
98877 ** There are lots of rules for determining compatibility - see comments
98878 ** embedded in the code for details.
@@ -98912,11 +99277,11 @@
99277 exec_out:
99278 if( pStmt ) sqlite3VdbeFinalize((Vdbe *)pStmt);
99279 sqlite3DbFree(db, azCols);
99280
99281 rc = sqlite3ApiExit(db, rc);
99282 if( rc!=SQLITE_OK && pzErrMsg ){
99283 int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db));
99284 *pzErrMsg = sqlite3Malloc(nErrMsg);
99285 if( *pzErrMsg ){
99286 memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg);
99287 }else{
@@ -98981,11 +99346,11 @@
99346 ** routines.
99347 **
99348 ** WARNING: In order to maintain backwards compatibility, add new
99349 ** interfaces to the end of this structure only. If you insert new
99350 ** interfaces in the middle of this structure, then older different
99351 ** versions of SQLite will not be able to load each other's shared
99352 ** libraries!
99353 */
99354 struct sqlite3_api_routines {
99355 void * (*aggregate_context)(sqlite3_context*,int nBytes);
99356 int (*aggregate_count)(sqlite3_context*);
@@ -99203,15 +99568,32 @@
99568 int (*uri_boolean)(const char*,const char*,int);
99569 sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64);
99570 const char *(*uri_parameter)(const char*,const char*);
99571 char *(*vsnprintf)(int,char*,const char*,va_list);
99572 int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*);
99573 /* Version 3.8.7 and later */
99574 int (*auto_extension)(void(*)(void));
99575 int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64,
99576 void(*)(void*));
99577 int (*bind_text64)(sqlite3_stmt*,int,const char*,sqlite3_uint64,
99578 void(*)(void*),unsigned char);
99579 int (*cancel_auto_extension)(void(*)(void));
99580 int (*load_extension)(sqlite3*,const char*,const char*,char**);
99581 void *(*malloc64)(sqlite3_uint64);
99582 sqlite3_uint64 (*msize)(void*);
99583 void *(*realloc64)(void*,sqlite3_uint64);
99584 void (*reset_auto_extension)(void);
99585 void (*result_blob64)(sqlite3_context*,const void*,sqlite3_uint64,
99586 void(*)(void*));
99587 void (*result_text64)(sqlite3_context*,const char*,sqlite3_uint64,
99588 void(*)(void*), unsigned char);
99589 int (*strglob)(const char*,const char*);
99590 };
99591
99592 /*
99593 ** The following macros redefine the API routines so that they are
99594 ** redirected through the global sqlite3_api structure.
99595 **
99596 ** This header file is also used by the loadext.c source file
99597 ** (part of the main SQLite library - not an extension) so that
99598 ** it can get access to the sqlite3_api_routines structure
99599 ** definition. But the main library does not want to redefine
@@ -99420,10 +99802,23 @@
99802 #define sqlite3_uri_boolean sqlite3_api->uri_boolean
99803 #define sqlite3_uri_int64 sqlite3_api->uri_int64
99804 #define sqlite3_uri_parameter sqlite3_api->uri_parameter
99805 #define sqlite3_uri_vsnprintf sqlite3_api->vsnprintf
99806 #define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2
99807 /* Version 3.8.7 and later */
99808 #define sqlite3_auto_extension sqlite3_api->auto_extension
99809 #define sqlite3_bind_blob64 sqlite3_api->bind_blob64
99810 #define sqlite3_bind_text64 sqlite3_api->bind_text64
99811 #define sqlite3_cancel_auto_extension sqlite3_api->cancel_auto_extension
99812 #define sqlite3_load_extension sqlite3_api->load_extension
99813 #define sqlite3_malloc64 sqlite3_api->malloc64
99814 #define sqlite3_msize sqlite3_api->msize
99815 #define sqlite3_realloc64 sqlite3_api->realloc64
99816 #define sqlite3_reset_auto_extension sqlite3_api->reset_auto_extension
99817 #define sqlite3_result_blob64 sqlite3_api->result_blob64
99818 #define sqlite3_result_text64 sqlite3_api->result_text64
99819 #define sqlite3_strglob sqlite3_api->strglob
99820 #endif /* SQLITE_CORE */
99821
99822 #ifndef SQLITE_CORE
99823 /* This case when the file really is being compiled as a loadable
99824 ** extension */
@@ -99813,11 +100208,24 @@
100208 sqlite3_stricmp,
100209 sqlite3_uri_boolean,
100210 sqlite3_uri_int64,
100211 sqlite3_uri_parameter,
100212 sqlite3_vsnprintf,
100213 sqlite3_wal_checkpoint_v2,
100214 /* Version 3.8.7 and later */
100215 sqlite3_auto_extension,
100216 sqlite3_bind_blob64,
100217 sqlite3_bind_text64,
100218 sqlite3_cancel_auto_extension,
100219 sqlite3_load_extension,
100220 sqlite3_malloc64,
100221 sqlite3_msize,
100222 sqlite3_realloc64,
100223 sqlite3_reset_auto_extension,
100224 sqlite3_result_blob64,
100225 sqlite3_result_text64,
100226 sqlite3_strglob
100227 };
100228
100229 /*
100230 ** Attempt to load an SQLite extension library contained in the file
100231 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -101580,10 +101988,16 @@
101988 if( db->autoCommit==0 ){
101989 /* Foreign key support may not be enabled or disabled while not
101990 ** in auto-commit mode. */
101991 mask &= ~(SQLITE_ForeignKeys);
101992 }
101993 #if SQLITE_USER_AUTHENTICATION
101994 if( db->auth.authLevel==UAUTH_User ){
101995 /* Do not allow non-admin users to modify the schema arbitrarily */
101996 mask &= ~(SQLITE_WriteSchema);
101997 }
101998 #endif
101999
102000 if( sqlite3GetBoolean(zRight, 0) ){
102001 db->flags |= mask;
102002 }else{
102003 db->flags &= ~mask;
@@ -102897,11 +103311,11 @@
103311 zSql = sqlite3MPrintf(db,
103312 "SELECT name, rootpage, sql FROM '%q'.%s ORDER BY rowid",
103313 db->aDb[iDb].zName, zMasterName);
103314 #ifndef SQLITE_OMIT_AUTHORIZATION
103315 {
103316 sqlite3_xauth xAuth;
103317 xAuth = db->xAuth;
103318 db->xAuth = 0;
103319 #endif
103320 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
103321 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -102963,10 +103377,11 @@
103377 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
103378 int i, rc;
103379 int commit_internal = !(db->flags&SQLITE_InternChanges);
103380
103381 assert( sqlite3_mutex_held(db->mutex) );
103382 assert( db->init.busy==0 );
103383 rc = SQLITE_OK;
103384 db->init.busy = 1;
103385 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
103386 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
103387 rc = sqlite3InitOne(db, i, pzErrMsg);
@@ -102978,12 +103393,12 @@
103393 /* Once all the other databases have been initialized, load the schema
103394 ** for the TEMP database. This is loaded last, as the TEMP database
103395 ** schema may contain references to objects in other databases.
103396 */
103397 #ifndef SQLITE_OMIT_TEMPDB
103398 assert( db->nDb>1 );
103399 if( rc==SQLITE_OK && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
103400 rc = sqlite3InitOne(db, 1, pzErrMsg);
103401 if( rc ){
103402 sqlite3ResetOneSchema(db, 1);
103403 }
103404 }
@@ -103944,11 +104359,11 @@
104359 sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, SQLITE_ECEL_DUP);
104360 if( bSeq ){
104361 sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
104362 }
104363 if( nPrefixReg==0 ){
104364 sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
104365 }
104366
104367 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase+nOBSat, nBase-nOBSat, regRecord);
104368 if( nOBSat>0 ){
104369 int regPrevKey; /* The first nOBSat columns of the previous row */
@@ -103980,11 +104395,11 @@
104395 pSort->labelBkOut = sqlite3VdbeMakeLabel(v);
104396 pSort->regReturn = ++pParse->nMem;
104397 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
104398 sqlite3VdbeAddOp1(v, OP_ResetSorter, pSort->iECursor);
104399 sqlite3VdbeJumpHere(v, addrFirst);
104400 sqlite3ExprCodeMove(pParse, regBase, regPrevKey, pSort->nOBSat);
104401 sqlite3VdbeJumpHere(v, addrJmp);
104402 }
104403 if( pSort->sortFlags & SORTFLAG_UseSorter ){
104404 op = OP_SorterInsert;
104405 }else{
@@ -104466,11 +104881,11 @@
104881 ** KeyInfo structure is appropriate for initializing a virtual index to
104882 ** implement that clause. If the ExprList is the result set of a SELECT
104883 ** then the KeyInfo structure is appropriate for initializing a virtual
104884 ** index to implement a DISTINCT test.
104885 **
104886 ** Space to hold the KeyInfo structure is obtained from malloc. The calling
104887 ** function is responsible for seeing that this structure is eventually
104888 ** freed.
104889 */
104890 static KeyInfo *keyInfoFromExprList(
104891 Parse *pParse, /* Parsing context */
@@ -104997,11 +105412,11 @@
105412 }
105413 generateColumnTypes(pParse, pTabList, pEList);
105414 }
105415
105416 /*
105417 ** Given an expression list (which is really the list of expressions
105418 ** that form the result set of a SELECT statement) compute appropriate
105419 ** column names for a table that would hold the expression list.
105420 **
105421 ** All column names will be unique.
105422 **
@@ -105070,11 +105485,11 @@
105485 sqlite3DbFree(db, zName);
105486 break;
105487 }
105488
105489 /* Make sure the column name is unique. If the name is not unique,
105490 ** append an integer to the name so that it becomes unique.
105491 */
105492 nName = sqlite3Strlen30(zName);
105493 for(j=cnt=0; j<i; j++){
105494 if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){
105495 char *zNewName;
@@ -106554,11 +106969,11 @@
106969 ** This routine attempts to rewrite queries such as the above into
106970 ** a single flat select, like this:
106971 **
106972 ** SELECT x+y AS a FROM t1 WHERE z<100 AND a>5
106973 **
106974 ** The code generated for this simplification gives the same result
106975 ** but only has to scan the data once. And because indices might
106976 ** exist on the table t1, a complete scan of the data might be
106977 ** avoided.
106978 **
106979 ** Flattening is only attempted if all of the following are true:
@@ -106587,12 +107002,14 @@
107002 ** (8) The subquery does not use LIMIT or the outer query is not a join.
107003 **
107004 ** (9) The subquery does not use LIMIT or the outer query does not use
107005 ** aggregates.
107006 **
107007 ** (**) Restriction (10) was removed from the code on 2005-02-05 but we
107008 ** accidently carried the comment forward until 2014-09-15. Original
107009 ** text: "The subquery does not use aggregates or the outer query does not
107010 ** use LIMIT."
107011 **
107012 ** (11) The subquery and the outer query do not both have ORDER BY clauses.
107013 **
107014 ** (**) Not implemented. Subsumed into restriction (3). Was previously
107015 ** a separate restriction deriving from ticket #350.
@@ -106651,10 +107068,15 @@
107068 ** (23) The parent is not a recursive CTE, or the sub-query is not a
107069 ** compound query. This restriction is because transforming the
107070 ** parent to a compound query confuses the code that handles
107071 ** recursive queries in multiSelect().
107072 **
107073 ** (24) The subquery is not an aggregate that uses the built-in min() or
107074 ** or max() functions. (Without this restriction, a query like:
107075 ** "SELECT x FROM (SELECT max(y), x FROM t1)" would not necessarily
107076 ** return the value X for which Y was maximal.)
107077 **
107078 **
107079 ** In this routine, the "p" parameter is a pointer to the outer query.
107080 ** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
107081 ** uses aggregates and subqueryIsAgg is true if the subquery uses aggregates.
107082 **
@@ -106698,11 +107120,11 @@
107120 if( isAgg && subqueryIsAgg ) return 0; /* Restriction (1) */
107121 if( subqueryIsAgg && pSrc->nSrc>1 ) return 0; /* Restriction (2) */
107122 pSubSrc = pSub->pSrc;
107123 assert( pSubSrc );
107124 /* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
107125 ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
107126 ** because they could be computed at compile-time. But when LIMIT and OFFSET
107127 ** became arbitrary expressions, we were forced to add restrictions (13)
107128 ** and (14). */
107129 if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
107130 if( pSub->pOffset ) return 0; /* Restriction (14) */
@@ -106723,12 +107145,18 @@
107145 if( isAgg && pSub->pOrderBy ) return 0; /* Restriction (16) */
107146 if( pSub->pLimit && p->pWhere ) return 0; /* Restriction (19) */
107147 if( pSub->pLimit && (p->selFlags & SF_Distinct)!=0 ){
107148 return 0; /* Restriction (21) */
107149 }
107150 testcase( pSub->selFlags & SF_Recursive );
107151 testcase( pSub->selFlags & SF_MinMaxAgg );
107152 if( pSub->selFlags & (SF_Recursive|SF_MinMaxAgg) ){
107153 return 0; /* Restrictions (22) and (24) */
107154 }
107155 if( (p->selFlags & SF_Recursive) && pSub->pPrior ){
107156 return 0; /* Restriction (23) */
107157 }
107158
107159 /* OBSOLETE COMMENT 1:
107160 ** Restriction 3: If the subquery is a join, make sure the subquery is
107161 ** not used as the right operand of an outer join. Examples of why this
107162 ** is not allowed:
@@ -107084,11 +107512,11 @@
107512 return eRet;
107513 }
107514
107515 /*
107516 ** The select statement passed as the first argument is an aggregate query.
107517 ** The second argument is the associated aggregate-info object. This
107518 ** function tests if the SELECT is of the form:
107519 **
107520 ** SELECT count(*) FROM <tbl>
107521 **
107522 ** where table is a database table, not a sub-select or view. If the query
@@ -107414,14 +107842,14 @@
107842 ** (2) Fill in the pTabList->a[].pTab fields in the SrcList that
107843 ** defines FROM clause. When views appear in the FROM clause,
107844 ** fill pTabList->a[].pSelect with a copy of the SELECT statement
107845 ** that implements the view. A copy is made of the view's SELECT
107846 ** statement so that we can freely modify or delete that statement
107847 ** without worrying about messing up the persistent representation
107848 ** of the view.
107849 **
107850 ** (3) Add terms to the WHERE clause to accommodate the NATURAL keyword
107851 ** on joins and the ON and USING clause of joins.
107852 **
107853 ** (4) Scan the list of columns in the result set (pEList) looking
107854 ** for instances of the "*" operator or the TABLE.* operator.
107855 ** If found, expand each "*" to be every column in every table
@@ -108927,14 +109355,14 @@
109355 ** to the callback function is uses to build the result.
109356 */
109357 typedef struct TabResult {
109358 char **azResult; /* Accumulated output */
109359 char *zErrMsg; /* Error message text, if an error occurs */
109360 u32 nAlloc; /* Slots allocated for azResult[] */
109361 u32 nRow; /* Number of rows in the result */
109362 u32 nColumn; /* Number of columns in the result */
109363 u32 nData; /* Slots used in azResult[]. (nRow+1)*nColumn */
109364 int rc; /* Return code from sqlite3_exec() */
109365 } TabResult;
109366
109367 /*
109368 ** This routine is called once for each row in the result table. Its job
@@ -108956,11 +109384,11 @@
109384 need = nCol;
109385 }
109386 if( p->nData + need > p->nAlloc ){
109387 char **azNew;
109388 p->nAlloc = p->nAlloc*2 + need;
109389 azNew = sqlite3_realloc64( p->azResult, sizeof(char*)*p->nAlloc );
109390 if( azNew==0 ) goto malloc_failed;
109391 p->azResult = azNew;
109392 }
109393
109394 /* If this is the first row, then generate an extra row containing
@@ -108971,11 +109399,11 @@
109399 for(i=0; i<nCol; i++){
109400 z = sqlite3_mprintf("%s", colv[i]);
109401 if( z==0 ) goto malloc_failed;
109402 p->azResult[p->nData++] = z;
109403 }
109404 }else if( (int)p->nColumn!=nCol ){
109405 sqlite3_free(p->zErrMsg);
109406 p->zErrMsg = sqlite3_mprintf(
109407 "sqlite3_get_table() called with two or more incompatible queries"
109408 );
109409 p->rc = SQLITE_ERROR;
@@ -109080,11 +109508,11 @@
109508
109509 /*
109510 ** This routine frees the space the sqlite3_get_table() malloced.
109511 */
109512 SQLITE_API void sqlite3_free_table(
109513 char **azResult /* Result returned from sqlite3_get_table() */
109514 ){
109515 if( azResult ){
109516 int i, n;
109517 azResult--;
109518 assert( azResult!=0 );
@@ -109224,11 +109652,11 @@
109652 **
109653 ** CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab ....
109654 ** ^^^^^^^^
109655 **
109656 ** To maintain backwards compatibility, ignore the database
109657 ** name on pTableName if we are reparsing out of SQLITE_MASTER.
109658 */
109659 if( db->init.busy && iDb!=1 ){
109660 sqlite3DbFree(db, pTableName->a[0].zDatabase);
109661 pTableName->a[0].zDatabase = 0;
109662 }
@@ -110545,11 +110973,11 @@
110973 if( isView ){
110974 sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
110975 }
110976
110977 /* If we are trying to update a view, realize that view into
110978 ** an ephemeral table.
110979 */
110980 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
110981 if( isView ){
110982 sqlite3MaterializeView(pParse, pTab, pWhere, iDataCur);
110983 }
@@ -110706,11 +111134,11 @@
111134 sqlite3VdbeAddOp2(v, OP_Copy, regOldRowid, regNewRowid);
111135 }
111136 }
111137
111138 /* Populate the array of registers beginning at regNew with the new
111139 ** row data. This array is used to check constants, create the new
111140 ** table and index records, and as the values for any new.* references
111141 ** made by triggers.
111142 **
111143 ** If there are one or more BEFORE triggers, then do not populate the
111144 ** registers associated with columns that are (a) not modified by
@@ -110886,11 +111314,11 @@
111314 sqlite3ExprListDelete(db, pChanges);
111315 sqlite3ExprDelete(db, pWhere);
111316 return;
111317 }
111318 /* Make sure "isView" and other macros defined above are undefined. Otherwise
111319 ** they may interfere with compilation of other functions in this file
111320 ** (or in another file, if this file becomes part of the amalgamation). */
111321 #ifdef isView
111322 #undef isView
111323 #endif
111324 #ifdef pTrigger
@@ -110899,19 +111327,19 @@
111327
111328 #ifndef SQLITE_OMIT_VIRTUALTABLE
111329 /*
111330 ** Generate code for an UPDATE of a virtual table.
111331 **
111332 ** The strategy is that we create an ephemeral table that contains
111333 ** for each row to be changed:
111334 **
111335 ** (A) The original rowid of that row.
111336 ** (B) The revised rowid for the row. (note1)
111337 ** (C) The content of every column in the row.
111338 **
111339 ** Then we loop over this ephemeral table and for each row in
111340 ** the ephemeral table call VUpdate.
111341 **
111342 ** When finished, drop the ephemeral table.
111343 **
111344 ** (note1) Actually, if we know in advance that (A) is always the same
111345 ** as (B) we only store (A), then duplicate (A) when pulling
@@ -111080,11 +111508,11 @@
111508 ** The transient database requires temporary disk space approximately
111509 ** equal to the size of the original database. The copy operation of
111510 ** step (3) requires additional temporary disk space approximately equal
111511 ** to the size of the original database for the rollback journal.
111512 ** Hence, temporary disk space that is approximately 2x the size of the
111513 ** original database is required. Every page of the database is written
111514 ** approximately 3 times: Once for step (2) and twice for step (3).
111515 ** Two writes per page are required in step (3) because the original
111516 ** database content must be written into the rollback journal prior to
111517 ** overwriting the database with the vacuumed content.
111518 **
@@ -112659,11 +113087,11 @@
113087 **
113088 ** The "solver" works by creating the N best WherePath objects of length
113089 ** 1. Then using those as a basis to compute the N best WherePath objects
113090 ** of length 2. And so forth until the length of WherePaths equals the
113091 ** number of nodes in the FROM clause. The best (lowest cost) WherePath
113092 ** at the end is the chosen query plan.
113093 */
113094 struct WherePath {
113095 Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */
113096 Bitmask revLoop; /* aLoop[]s that should be reversed for ORDER BY */
113097 LogEst nRow; /* Estimated number of rows generated by this path */
@@ -113628,11 +114056,11 @@
114056 if( *pisComplete && pRight->u.zToken[1] ){
114057 /* If the rhs of the LIKE expression is a variable, and the current
114058 ** value of the variable means there is no need to invoke the LIKE
114059 ** function, then no OP_Variable will be added to the program.
114060 ** This causes problems for the sqlite3_bind_parameter_name()
114061 ** API. To work around them, add a dummy OP_Variable here.
114062 */
114063 int r1 = sqlite3GetTempReg(pParse);
114064 sqlite3ExprCodeTarget(pParse, pRight, r1);
114065 sqlite3VdbeChangeP3(v, sqlite3VdbeCurrentAddr(v)-1, 0);
114066 sqlite3ReleaseTempReg(pParse, r1);
@@ -113748,11 +114176,11 @@
114176 ** This analysis does not consider whether or not the index exists; that
114177 ** is decided elsewhere. This analysis only looks at whether subterms
114178 ** appropriate for indexing exist.
114179 **
114180 ** All examples A through E above satisfy case 2. But if a term
114181 ** also satisfies case 1 (such as B) we know that the optimizer will
114182 ** always prefer case 1, so in that case we pretend that case 2 is not
114183 ** satisfied.
114184 **
114185 ** It might be the case that multiple tables are indexable. For example,
114186 ** (E) above is indexable on tables P, Q, and R.
@@ -113906,11 +114334,11 @@
114334 assert( j==1 );
114335 continue;
114336 }
114337 if( (chngToIN & getMask(&pWInfo->sMaskSet, pOrTerm->leftCursor))==0 ){
114338 /* This term must be of the form t1.a==t2.b where t2 is in the
114339 ** chngToIN set but t1 is not. This term will be either preceded
114340 ** or follwed by an inverted copy (t2.b==t1.a). Skip this term
114341 ** and use its inversion. */
114342 testcase( pOrTerm->wtFlags & TERM_COPIED );
114343 testcase( pOrTerm->wtFlags & TERM_VIRTUAL );
114344 assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) );
@@ -114317,11 +114745,11 @@
114745 */
114746 pTerm->prereqRight |= extraRight;
114747 }
114748
114749 /*
114750 ** This function searches pList for an entry that matches the iCol-th column
114751 ** of index pIdx.
114752 **
114753 ** If such an expression is found, its index in pList->a[] is returned. If
114754 ** no expression is found, -1 is returned.
114755 */
@@ -114840,11 +115268,11 @@
115268 iCol = pRec->nField - 1;
115269 assert( pIdx->nSample>0 );
115270 assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
115271 do{
115272 iTest = (iMin+i)/2;
115273 res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec);
115274 if( res<0 ){
115275 iMin = iTest+1;
115276 }else{
115277 i = iTest;
115278 }
@@ -114855,20 +115283,20 @@
115283 ** above found the right answer. This block serves no purpose other
115284 ** than to invoke the asserts. */
115285 if( res==0 ){
115286 /* If (res==0) is true, then sample $i must be equal to pRec */
115287 assert( i<pIdx->nSample );
115288 assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)
115289 || pParse->db->mallocFailed );
115290 }else{
115291 /* Otherwise, pRec must be smaller than sample $i and larger than
115292 ** sample ($i-1). */
115293 assert( i==pIdx->nSample
115294 || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0
115295 || pParse->db->mallocFailed );
115296 assert( i==0
115297 || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0
115298 || pParse->db->mallocFailed );
115299 }
115300 #endif /* ifdef SQLITE_DEBUG */
115301
115302 /* At this point, aSample[i] is the first sample that is greater than
@@ -115067,11 +115495,11 @@
115495 **
115496 ** When this function is called, *pnOut is set to the sqlite3LogEst() of the
115497 ** number of rows that the index scan is expected to visit without
115498 ** considering the range constraints. If nEq is 0, this is the number of
115499 ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
115500 ** to account for the range constraints pLower and pUpper.
115501 **
115502 ** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be
115503 ** used, a single range inequality reduces the search space by a factor of 4.
115504 ** and a pair of constraints (x>? AND x<?) reduces the expected number of
115505 ** rows visited by a factor of 64.
@@ -116344,11 +116772,11 @@
116772 ** Return 2 # Jump back to the Gosub
116773 **
116774 ** B: <after the loop>
116775 **
116776 ** Added 2014-05-26: If the table is a WITHOUT ROWID table, then
116777 ** use an ephemeral index instead of a RowSet to record the primary
116778 ** keys of the rows we have already seen.
116779 **
116780 */
116781 WhereClause *pOrWc; /* The OR-clause broken out into subterms */
116782 SrcList *pOrTab; /* Shortened table list or OR-clause generation */
@@ -116395,11 +116823,11 @@
116823 }else{
116824 pOrTab = pWInfo->pTabList;
116825 }
116826
116827 /* Initialize the rowset register to contain NULL. An SQL NULL is
116828 ** equivalent to an empty rowset. Or, create an ephemeral index
116829 ** capable of holding primary keys in the case of a WITHOUT ROWID.
116830 **
116831 ** Also initialize regReturn to contain the address of the instruction
116832 ** immediately following the OP_Return at the bottom of the loop. This
116833 ** is required in a few obscure LEFT JOIN cases where control jumps
@@ -117148,18 +117576,20 @@
117576 **
117577 ** In the current implementation, the first extra WHERE clause term reduces
117578 ** the number of output rows by a factor of 10 and each additional term
117579 ** reduces the number of output rows by sqrt(2).
117580 */
117581 static void whereLoopOutputAdjust(
117582 WhereClause *pWC, /* The WHERE clause */
117583 WhereLoop *pLoop, /* The loop to adjust downward */
117584 LogEst nRow /* Number of rows in the entire table */
117585 ){
117586 WhereTerm *pTerm, *pX;
117587 Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf);
117588 int i, j;
117589 int nEq = 0; /* Number of = constraints not within likely()/unlikely() */
117590
 
 
 
117591 for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){
117592 if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
117593 if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
117594 if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
117595 for(j=pLoop->nLTerm-1; j>=0; j--){
@@ -117167,12 +117597,24 @@
117597 if( pX==0 ) continue;
117598 if( pX==pTerm ) break;
117599 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
117600 }
117601 if( j<0 ){
117602 if( pTerm->truthProb<=0 ){
117603 pLoop->nOut += pTerm->truthProb;
117604 }else{
117605 pLoop->nOut--;
117606 if( pTerm->eOperator&WO_EQ ) nEq++;
117607 }
117608 }
117609 }
117610 /* TUNING: If there is at least one equality constraint in the WHERE
117611 ** clause that does not have a likelihood() explicitly assigned to it
117612 ** then do not let the estimated number of output rows exceed half
117613 ** the number of rows in the table. */
117614 if( nEq && pLoop->nOut>nRow-10 ){
117615 pLoop->nOut = nRow - 10;
117616 }
117617 }
117618
117619 /*
117620 ** Adjust the cost C by the costMult facter T. This only occurs if
@@ -117215,10 +117657,11 @@
117657 u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */
117658 u32 saved_wsFlags; /* Original value of pNew->wsFlags */
117659 LogEst saved_nOut; /* Original value of pNew->nOut */
117660 int iCol; /* Index of the column in the table */
117661 int rc = SQLITE_OK; /* Return code */
117662 LogEst rSize; /* Number of rows in the table */
117663 LogEst rLogSize; /* Logarithm of table size */
117664 WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
117665
117666 pNew = pBuilder->pNew;
117667 if( db->mallocFailed ) return SQLITE_NOMEM;
@@ -117244,11 +117687,12 @@
117687 saved_nLTerm = pNew->nLTerm;
117688 saved_wsFlags = pNew->wsFlags;
117689 saved_prereq = pNew->prereq;
117690 saved_nOut = pNew->nOut;
117691 pNew->rSetup = 0;
117692 rSize = pProbe->aiRowLogEst[0];
117693 rLogSize = estLog(rSize);
117694
117695 /* Consider using a skip-scan if there are no WHERE clause constraints
117696 ** available for the left-most terms of the index, and if the average
117697 ** number of repeats in the left-most terms is at least 18.
117698 **
@@ -117421,11 +117865,11 @@
117865 ApplyCostMultiplier(pNew->rRun, pProbe->pTable->costMult);
117866
117867 nOutUnadjusted = pNew->nOut;
117868 pNew->rRun += nInMul + nIn;
117869 pNew->nOut += nInMul + nIn;
117870 whereLoopOutputAdjust(pBuilder->pWC, pNew, rSize);
117871 rc = whereLoopInsert(pBuilder, pNew);
117872
117873 if( pNew->wsFlags & WHERE_COLUMN_RANGE ){
117874 pNew->nOut = saved_nOut;
117875 }else{
@@ -117471,10 +117915,11 @@
117915 if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
117916 for(ii=0; ii<pOB->nExpr; ii++){
117917 Expr *pExpr = sqlite3ExprSkipCollate(pOB->a[ii].pExpr);
117918 if( pExpr->op!=TK_COLUMN ) return 0;
117919 if( pExpr->iTable==iCursor ){
117920 if( pExpr->iColumn<0 ) return 1;
117921 for(jj=0; jj<pIndex->nKeyCol; jj++){
117922 if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1;
117923 }
117924 }
117925 }
@@ -117634,11 +118079,11 @@
118079 ** the table being indexed. */
118080 pNew->rSetup = rLogSize + rSize + 28; assert( 28==sqlite3LogEst(7) );
118081 ApplyCostMultiplier(pNew->rSetup, pTab->costMult);
118082 /* TUNING: Each index lookup yields 20 rows in the table. This
118083 ** is more than the usual guess of 10 rows, since we have no way
118084 ** of knowing how selective the index will ultimately be. It would
118085 ** not be unreasonable to make this value much larger. */
118086 pNew->nOut = 43; assert( 43==sqlite3LogEst(20) );
118087 pNew->rRun = sqlite3LogEstAdd(rLogSize,pNew->nOut);
118088 pNew->wsFlags = WHERE_AUTO_INDEX;
118089 pNew->prereq = mExtra | pTerm->prereqRight;
@@ -117675,11 +118120,11 @@
118120 /* Full table scan */
118121 pNew->iSortIdx = b ? iSortIdx : 0;
118122 /* TUNING: Cost of full table scan is (N*3.0). */
118123 pNew->rRun = rSize + 16;
118124 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
118125 whereLoopOutputAdjust(pWC, pNew, rSize);
118126 rc = whereLoopInsert(pBuilder, pNew);
118127 pNew->nOut = rSize;
118128 if( rc ) break;
118129 }else{
118130 Bitmask m;
@@ -117711,11 +118156,11 @@
118156 pNew->rRun = rSize + 1 + (15*pProbe->szIdxRow)/pTab->szTabRow;
118157 if( m!=0 ){
118158 pNew->rRun = sqlite3LogEstAdd(pNew->rRun, rSize+16);
118159 }
118160 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
118161 whereLoopOutputAdjust(pWC, pNew, rSize);
118162 rc = whereLoopInsert(pBuilder, pNew);
118163 pNew->nOut = rSize;
118164 if( rc ) break;
118165 }
118166 }
@@ -118064,11 +118509,11 @@
118509 **
118510 ** Note that processing for WHERE_GROUPBY and WHERE_DISTINCTBY is not as
118511 ** strict. With GROUP BY and DISTINCT the only requirement is that
118512 ** equivalent rows appear immediately adjacent to one another. GROUP BY
118513 ** and DISTINCT do not require rows to appear in any particular order as long
118514 ** as equivalent rows are grouped together. Thus for GROUP BY and DISTINCT
118515 ** the pOrderBy terms can be matched in any order. With ORDER BY, the
118516 ** pOrderBy terms must be matched in strict left-to-right order.
118517 */
118518 static i8 wherePathSatisfiesOrderBy(
118519 WhereInfo *pWInfo, /* The WHERE clause */
@@ -120841,13 +121286,13 @@
121286 **
121287 ** Outputs:
121288 ** A pointer to a parser. This pointer is used in subsequent calls
121289 ** to sqlite3Parser and sqlite3ParserFree.
121290 */
121291 SQLITE_PRIVATE void *sqlite3ParserAlloc(void *(*mallocProc)(u64)){
121292 yyParser *pParser;
121293 pParser = (yyParser*)(*mallocProc)( (u64)sizeof(yyParser) );
121294 if( pParser ){
121295 pParser->yyidx = -1;
121296 #ifdef YYTRACKMAXSTACKDEPTH
121297 pParser->yyidxMax = 0;
121298 #endif
@@ -123398,11 +123843,11 @@
123843 **
123844 ** For EBCDIC, the rules are more complex but have the same
123845 ** end result.
123846 **
123847 ** Ticket #1066. the SQL standard does not allow '$' in the
123848 ** middle of identifiers. But many SQL implementations do.
123849 ** SQLite will allow '$' in identifiers for compatibility.
123850 ** But the feature is undocumented.
123851 */
123852 #ifdef SQLITE_ASCII
123853 #define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)
@@ -123719,11 +124164,11 @@
124164 }
124165 pParse->rc = SQLITE_OK;
124166 pParse->zTail = zSql;
124167 i = 0;
124168 assert( pzErrMsg!=0 );
124169 pEngine = sqlite3ParserAlloc(sqlite3Malloc);
124170 if( pEngine==0 ){
124171 db->mallocFailed = 1;
124172 return SQLITE_NOMEM;
124173 }
124174 assert( pParse->pNewTable==0 );
@@ -123914,21 +124359,21 @@
124359 **
124360 ** (3) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
124361 ** a statement.
124362 **
124363 ** (4) CREATE The keyword CREATE has been seen at the beginning of a
124364 ** statement, possibly preceded by EXPLAIN and/or followed by
124365 ** TEMP or TEMPORARY
124366 **
124367 ** (5) TRIGGER We are in the middle of a trigger definition that must be
124368 ** ended by a semicolon, the keyword END, and another semicolon.
124369 **
124370 ** (6) SEMI We've seen the first semicolon in the ";END;" that occurs at
124371 ** the end of a trigger definition.
124372 **
124373 ** (7) END We've seen the ";END" of the ";END;" that occurs at the end
124374 ** of a trigger definition.
124375 **
124376 ** Transitions between states above are determined by tokens extracted
124377 ** from the input. The following tokens are significant:
124378 **
124379 ** (0) tkSEMI A semicolon.
@@ -123967,11 +124412,11 @@
124412 /* 6 SEMI: */ { 6, 6, 5, 5, 5, 5, 5, 7, },
124413 /* 7 END: */ { 1, 7, 5, 5, 5, 5, 5, 5, },
124414 };
124415 #else
124416 /* If triggers are not supported by this compile then the statement machine
124417 ** used to detect the end of a statement is much simpler
124418 */
124419 static const u8 trans[3][3] = {
124420 /* Token: */
124421 /* State: ** SEMI WS OTHER */
124422 /* 0 INVALID: */ { 1, 0, 2, },
@@ -125202,10 +125647,14 @@
125647 #endif
125648
125649 sqlite3Error(db, SQLITE_OK); /* Deallocates any cached error strings. */
125650 sqlite3ValueFree(db->pErr);
125651 sqlite3CloseExtensions(db);
125652 #if SQLITE_USER_AUTHENTICATION
125653 sqlite3_free(db->auth.zAuthUser);
125654 sqlite3_free(db->auth.zAuthPW);
125655 #endif
125656
125657 db->magic = SQLITE_MAGIC_ERROR;
125658
125659 /* The temp-database schema is allocated differently from the other schema
125660 ** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
@@ -126783,11 +127232,10 @@
127232 goto opendb_out;
127233 }
127234 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
127235 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
127236
 
127237 /* The default safety_level for the main database is 'full'; for the temp
127238 ** database it is 'NONE'. This matches the pager layer defaults.
127239 */
127240 db->aDb[0].zName = "main";
127241 db->aDb[0].safety_level = 3;
@@ -127070,13 +127518,13 @@
127518 SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
127519 return db->autoCommit;
127520 }
127521
127522 /*
127523 ** The following routines are substitutes for constants SQLITE_CORRUPT,
127524 ** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_IOERR and possibly other error
127525 ** constants. They serve two purposes:
127526 **
127527 ** 1. Serve as a convenient place to set a breakpoint in a debugger
127528 ** to detect when version error conditions occurs.
127529 **
127530 ** 2. Invoke sqlite3_log() to provide the source code location where
@@ -127386,11 +127834,11 @@
127834 ** as it existing before this routine was called.
127835 **
127836 ** IMPORTANT: Changing the PENDING byte from 0x40000000 results in
127837 ** an incompatible database file format. Changing the PENDING byte
127838 ** while any database connection is open results in undefined and
127839 ** deleterious behavior.
127840 */
127841 case SQLITE_TESTCTRL_PENDING_BYTE: {
127842 rc = PENDING_BYTE;
127843 #ifndef SQLITE_OMIT_WSD
127844 {
127845
+67 -22
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.7"
111111
#define SQLITE_VERSION_NUMBER 3008007
112
-#define SQLITE_SOURCE_ID "2014-09-01 18:21:27 672e7387b1bda8d007da7de4244226577d7ab2dc"
112
+#define SQLITE_SOURCE_ID "2014-09-20 00:35:05 59e2c9df02d7e988c5ad44c560ead1e5288b12e7"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -495,10 +495,11 @@
495495
#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
496496
#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
497497
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
498498
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
499499
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
500
+#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
500501
501502
/*
502503
** CAPI3REF: Flags For File Open Operations
503504
**
504505
** These bit values are intended for use in the
@@ -2097,11 +2098,11 @@
20972098
**
20982099
** ^Calling this routine with an argument less than or equal to zero
20992100
** turns off all busy handlers.
21002101
**
21012102
** ^(There can only be a single busy handler for a particular
2102
-** [database connection] any any given moment. If another busy handler
2103
+** [database connection] at any given moment. If another busy handler
21032104
** was defined (using [sqlite3_busy_handler()]) prior to calling
21042105
** this routine, that other busy handler is cleared.)^
21052106
**
21062107
** See also: [PRAGMA busy_timeout]
21072108
*/
@@ -2300,10 +2301,14 @@
23002301
** of memory at least N bytes in length, where N is the parameter.
23012302
** ^If sqlite3_malloc() is unable to obtain sufficient free
23022303
** memory, it returns a NULL pointer. ^If the parameter N to
23032304
** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
23042305
** a NULL pointer.
2306
+**
2307
+** ^The sqlite3_malloc64(N) routine works just like
2308
+** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
2309
+** of a signed 32-bit integer.
23052310
**
23062311
** ^Calling sqlite3_free() with a pointer previously returned
23072312
** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
23082313
** that it might be reused. ^The sqlite3_free() routine is
23092314
** a no-op if is called with a NULL pointer. Passing a NULL pointer
@@ -2312,28 +2317,42 @@
23122317
** memory might result in a segmentation fault or other severe error.
23132318
** Memory corruption, a segmentation fault, or other severe error
23142319
** might result if sqlite3_free() is called with a non-NULL pointer that
23152320
** was not obtained from sqlite3_malloc() or sqlite3_realloc().
23162321
**
2317
-** ^(The sqlite3_realloc() interface attempts to resize a
2318
-** prior memory allocation to be at least N bytes, where N is the
2319
-** second parameter. The memory allocation to be resized is the first
2320
-** parameter.)^ ^ If the first parameter to sqlite3_realloc()
2322
+** ^The sqlite3_realloc(X,N) interface attempts to resize a
2323
+** prior memory allocation X to be at least N bytes.
2324
+** ^If the X parameter to sqlite3_realloc(X,N)
23212325
** is a NULL pointer then its behavior is identical to calling
2322
-** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().
2323
-** ^If the second parameter to sqlite3_realloc() is zero or
2326
+** sqlite3_malloc(N).
2327
+** ^If the N parameter to sqlite3_realloc(X,N) is zero or
23242328
** negative then the behavior is exactly the same as calling
2325
-** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
2326
-** ^sqlite3_realloc() returns a pointer to a memory allocation
2327
-** of at least N bytes in size or NULL if sufficient memory is unavailable.
2329
+** sqlite3_free(X).
2330
+** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
2331
+** of at least N bytes in size or NULL if insufficient memory is available.
23282332
** ^If M is the size of the prior allocation, then min(N,M) bytes
23292333
** of the prior allocation are copied into the beginning of buffer returned
2330
-** by sqlite3_realloc() and the prior allocation is freed.
2331
-** ^If sqlite3_realloc() returns NULL, then the prior allocation
2332
-** is not freed.
2334
+** by sqlite3_realloc(X,N) and the prior allocation is freed.
2335
+** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
2336
+** prior allocation is not freed.
23332337
**
2334
-** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
2338
+** ^The sqlite3_realloc64(X,N) interfaces works the same as
2339
+** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
2340
+** of a 32-bit signed integer.
2341
+**
2342
+** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
2343
+** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
2344
+** sqlite3_msize(X) returns the size of that memory allocation in bytes.
2345
+** ^The value returned by sqlite3_msize(X) might be larger than the number
2346
+** of bytes requested when X was allocated. ^If X is a NULL pointer then
2347
+** sqlite3_msize(X) returns zero. If X points to something that is not
2348
+** the beginning of memory allocation, or if it points to a formerly
2349
+** valid memory allocation that has now been freed, then the behavior
2350
+** of sqlite3_msize(X) is undefined and possibly harmful.
2351
+**
2352
+** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
2353
+** sqlite3_malloc64(), and sqlite3_realloc64()
23352354
** is always aligned to at least an 8 byte boundary, or to a
23362355
** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
23372356
** option is used.
23382357
**
23392358
** In SQLite version 3.5.0 and 3.5.1, it was possible to define
@@ -2357,12 +2376,15 @@
23572376
** The application must not read or write any part of
23582377
** a block of memory after it has been released using
23592378
** [sqlite3_free()] or [sqlite3_realloc()].
23602379
*/
23612380
SQLITE_API void *sqlite3_malloc(int);
2381
+SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
23622382
SQLITE_API void *sqlite3_realloc(void*, int);
2383
+SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
23632384
SQLITE_API void sqlite3_free(void*);
2385
+SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
23642386
23652387
/*
23662388
** CAPI3REF: Memory Allocator Statistics
23672389
**
23682390
** SQLite provides these two interfaces for reporting on the status
@@ -3367,11 +3389,12 @@
33673389
** is negative, then the length of the string is
33683390
** the number of bytes up to the first zero terminator.
33693391
** If the fourth parameter to sqlite3_bind_blob() is negative, then
33703392
** the behavior is undefined.
33713393
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3372
-** or sqlite3_bind_text16() then that parameter must be the byte offset
3394
+** or sqlite3_bind_text16() or sqlite3_bind_text64() then
3395
+** that parameter must be the byte offset
33733396
** where the NUL terminator would occur assuming the string were NUL
33743397
** terminated. If any NUL characters occur at byte offsets less than
33753398
** the value of the fourth parameter then the resulting string value will
33763399
** contain embedded NULs. The result of expressions involving strings
33773400
** with embedded NULs is undefined.
@@ -3385,10 +3408,18 @@
33853408
** the special value [SQLITE_STATIC], then SQLite assumes that the
33863409
** information is in static, unmanaged space and does not need to be freed.
33873410
** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
33883411
** SQLite makes its own private copy of the data immediately, before
33893412
** the sqlite3_bind_*() routine returns.
3413
+**
3414
+** ^The sixth argument to sqlite3_bind_text64() must be one of
3415
+** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
3416
+** to specify the encoding of the text in the third parameter. If
3417
+** the sixth argument to sqlite3_bind_text64() is not how of the
3418
+** allowed values shown above, or if the text encoding is different
3419
+** from the encoding specified by the sixth parameter, then the behavior
3420
+** is undefined.
33903421
**
33913422
** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
33923423
** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
33933424
** (just an integer to hold its size) while it is being processed.
33943425
** Zeroblobs are intended to serve as placeholders for BLOBs whose
@@ -3406,23 +3437,30 @@
34063437
** ^Bindings are not cleared by the [sqlite3_reset()] routine.
34073438
** ^Unbound parameters are interpreted as NULL.
34083439
**
34093440
** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
34103441
** [error code] if anything goes wrong.
3442
+** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
3443
+** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
3444
+** [SQLITE_MAX_LENGTH].
34113445
** ^[SQLITE_RANGE] is returned if the parameter
34123446
** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
34133447
**
34143448
** See also: [sqlite3_bind_parameter_count()],
34153449
** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
34163450
*/
34173451
SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
3452
+SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
3453
+ void(*)(void*));
34183454
SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
34193455
SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
34203456
SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
34213457
SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
3422
-SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
3458
+SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
34233459
SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
3460
+SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
3461
+ void(*)(void*), unsigned char encoding);
34243462
SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
34253463
SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
34263464
34273465
/*
34283466
** CAPI3REF: Number Of SQL Parameters
@@ -4167,11 +4205,11 @@
41674205
** These routines work only with [protected sqlite3_value] objects.
41684206
** Any attempt to use these routines on an [unprotected sqlite3_value]
41694207
** object results in undefined behavior.
41704208
**
41714209
** ^These routines work just like the corresponding [column access functions]
4172
-** except that these routines take a single [protected sqlite3_value] object
4210
+** except that these routines take a single [protected sqlite3_value] object
41734211
** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
41744212
**
41754213
** ^The sqlite3_value_text16() interface extracts a UTF-16 string
41764214
** in the native byte-order of the host machine. ^The
41774215
** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
@@ -4410,14 +4448,18 @@
44104448
**
44114449
** ^The sqlite3_result_null() interface sets the return value
44124450
** of the application-defined function to be NULL.
44134451
**
44144452
** ^The sqlite3_result_text(), sqlite3_result_text16(),
4415
-** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
4453
+** sqlite3_result_text16le(), and sqlite3_result_text16be()
44164454
** set the return value of the application-defined function to be
44174455
** a text string which is represented as UTF-8, UTF-16 native byte order,
44184456
** UTF-16 little endian, or UTF-16 big endian, respectively.
4457
+** ^The sqlite3_result_text64() interface sets the return value of an
4458
+** application-defined function to be a text string in an encoding
4459
+** specified by the fifth (and last) parameter, which must be one
4460
+** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
44194461
** ^SQLite takes the text result from the application from
44204462
** the 2nd parameter of the sqlite3_result_text* interfaces.
44214463
** ^If the 3rd parameter to the sqlite3_result_text* interfaces
44224464
** is negative, then SQLite takes result text from the 2nd parameter
44234465
** through the first zero character.
@@ -4457,10 +4499,11 @@
44574499
** If these routines are called from within the different thread
44584500
** than the one containing the application-defined function that received
44594501
** the [sqlite3_context] pointer, the results are undefined.
44604502
*/
44614503
SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
4504
+SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint64,void(*)(void*));
44624505
SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
44634506
SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
44644507
SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
44654508
SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
44664509
SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
@@ -4467,10 +4510,12 @@
44674510
SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
44684511
SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
44694512
SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
44704513
SQLITE_API void sqlite3_result_null(sqlite3_context*);
44714514
SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
4515
+SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
4516
+ void(*)(void*), unsigned char encoding);
44724517
SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
44734518
SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
44744519
SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
44754520
SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
44764521
SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
@@ -6360,25 +6405,25 @@
63606405
** memory already being in use.
63616406
** Only the high-water value is meaningful;
63626407
** the current value is always zero.)^
63636408
**
63646409
** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6365
-** <dd>This parameter returns the approximate number of of bytes of heap
6410
+** <dd>This parameter returns the approximate number of bytes of heap
63666411
** memory used by all pager caches associated with the database connection.)^
63676412
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
63686413
**
63696414
** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
6370
-** <dd>This parameter returns the approximate number of of bytes of heap
6415
+** <dd>This parameter returns the approximate number of bytes of heap
63716416
** memory used to store the schema for all databases associated
63726417
** with the connection - main, temp, and any [ATTACH]-ed databases.)^
63736418
** ^The full amount of memory used by the schemas is reported, even if the
63746419
** schema memory is shared with other database connections due to
63756420
** [shared cache mode] being enabled.
63766421
** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
63776422
**
63786423
** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
6379
-** <dd>This parameter returns the approximate number of of bytes of heap
6424
+** <dd>This parameter returns the approximate number of bytes of heap
63806425
** and lookaside memory used by all prepared statements associated with
63816426
** the database connection.)^
63826427
** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
63836428
** </dd>
63846429
**
63856430
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.7"
111 #define SQLITE_VERSION_NUMBER 3008007
112 #define SQLITE_SOURCE_ID "2014-09-01 18:21:27 672e7387b1bda8d007da7de4244226577d7ab2dc"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -495,10 +495,11 @@
495 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
496 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
497 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
498 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
499 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
 
500
501 /*
502 ** CAPI3REF: Flags For File Open Operations
503 **
504 ** These bit values are intended for use in the
@@ -2097,11 +2098,11 @@
2097 **
2098 ** ^Calling this routine with an argument less than or equal to zero
2099 ** turns off all busy handlers.
2100 **
2101 ** ^(There can only be a single busy handler for a particular
2102 ** [database connection] any any given moment. If another busy handler
2103 ** was defined (using [sqlite3_busy_handler()]) prior to calling
2104 ** this routine, that other busy handler is cleared.)^
2105 **
2106 ** See also: [PRAGMA busy_timeout]
2107 */
@@ -2300,10 +2301,14 @@
2300 ** of memory at least N bytes in length, where N is the parameter.
2301 ** ^If sqlite3_malloc() is unable to obtain sufficient free
2302 ** memory, it returns a NULL pointer. ^If the parameter N to
2303 ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
2304 ** a NULL pointer.
 
 
 
 
2305 **
2306 ** ^Calling sqlite3_free() with a pointer previously returned
2307 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
2308 ** that it might be reused. ^The sqlite3_free() routine is
2309 ** a no-op if is called with a NULL pointer. Passing a NULL pointer
@@ -2312,28 +2317,42 @@
2312 ** memory might result in a segmentation fault or other severe error.
2313 ** Memory corruption, a segmentation fault, or other severe error
2314 ** might result if sqlite3_free() is called with a non-NULL pointer that
2315 ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
2316 **
2317 ** ^(The sqlite3_realloc() interface attempts to resize a
2318 ** prior memory allocation to be at least N bytes, where N is the
2319 ** second parameter. The memory allocation to be resized is the first
2320 ** parameter.)^ ^ If the first parameter to sqlite3_realloc()
2321 ** is a NULL pointer then its behavior is identical to calling
2322 ** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().
2323 ** ^If the second parameter to sqlite3_realloc() is zero or
2324 ** negative then the behavior is exactly the same as calling
2325 ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
2326 ** ^sqlite3_realloc() returns a pointer to a memory allocation
2327 ** of at least N bytes in size or NULL if sufficient memory is unavailable.
2328 ** ^If M is the size of the prior allocation, then min(N,M) bytes
2329 ** of the prior allocation are copied into the beginning of buffer returned
2330 ** by sqlite3_realloc() and the prior allocation is freed.
2331 ** ^If sqlite3_realloc() returns NULL, then the prior allocation
2332 ** is not freed.
2333 **
2334 ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2335 ** is always aligned to at least an 8 byte boundary, or to a
2336 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
2337 ** option is used.
2338 **
2339 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
@@ -2357,12 +2376,15 @@
2357 ** The application must not read or write any part of
2358 ** a block of memory after it has been released using
2359 ** [sqlite3_free()] or [sqlite3_realloc()].
2360 */
2361 SQLITE_API void *sqlite3_malloc(int);
 
2362 SQLITE_API void *sqlite3_realloc(void*, int);
 
2363 SQLITE_API void sqlite3_free(void*);
 
2364
2365 /*
2366 ** CAPI3REF: Memory Allocator Statistics
2367 **
2368 ** SQLite provides these two interfaces for reporting on the status
@@ -3367,11 +3389,12 @@
3367 ** is negative, then the length of the string is
3368 ** the number of bytes up to the first zero terminator.
3369 ** If the fourth parameter to sqlite3_bind_blob() is negative, then
3370 ** the behavior is undefined.
3371 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3372 ** or sqlite3_bind_text16() then that parameter must be the byte offset
 
3373 ** where the NUL terminator would occur assuming the string were NUL
3374 ** terminated. If any NUL characters occur at byte offsets less than
3375 ** the value of the fourth parameter then the resulting string value will
3376 ** contain embedded NULs. The result of expressions involving strings
3377 ** with embedded NULs is undefined.
@@ -3385,10 +3408,18 @@
3385 ** the special value [SQLITE_STATIC], then SQLite assumes that the
3386 ** information is in static, unmanaged space and does not need to be freed.
3387 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
3388 ** SQLite makes its own private copy of the data immediately, before
3389 ** the sqlite3_bind_*() routine returns.
 
 
 
 
 
 
 
 
3390 **
3391 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
3392 ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
3393 ** (just an integer to hold its size) while it is being processed.
3394 ** Zeroblobs are intended to serve as placeholders for BLOBs whose
@@ -3406,23 +3437,30 @@
3406 ** ^Bindings are not cleared by the [sqlite3_reset()] routine.
3407 ** ^Unbound parameters are interpreted as NULL.
3408 **
3409 ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
3410 ** [error code] if anything goes wrong.
 
 
 
3411 ** ^[SQLITE_RANGE] is returned if the parameter
3412 ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
3413 **
3414 ** See also: [sqlite3_bind_parameter_count()],
3415 ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
3416 */
3417 SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
 
 
3418 SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
3419 SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
3420 SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
3421 SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
3422 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
3423 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
 
 
3424 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3425 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3426
3427 /*
3428 ** CAPI3REF: Number Of SQL Parameters
@@ -4167,11 +4205,11 @@
4167 ** These routines work only with [protected sqlite3_value] objects.
4168 ** Any attempt to use these routines on an [unprotected sqlite3_value]
4169 ** object results in undefined behavior.
4170 **
4171 ** ^These routines work just like the corresponding [column access functions]
4172 ** except that these routines take a single [protected sqlite3_value] object
4173 ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
4174 **
4175 ** ^The sqlite3_value_text16() interface extracts a UTF-16 string
4176 ** in the native byte-order of the host machine. ^The
4177 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
@@ -4410,14 +4448,18 @@
4410 **
4411 ** ^The sqlite3_result_null() interface sets the return value
4412 ** of the application-defined function to be NULL.
4413 **
4414 ** ^The sqlite3_result_text(), sqlite3_result_text16(),
4415 ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
4416 ** set the return value of the application-defined function to be
4417 ** a text string which is represented as UTF-8, UTF-16 native byte order,
4418 ** UTF-16 little endian, or UTF-16 big endian, respectively.
 
 
 
 
4419 ** ^SQLite takes the text result from the application from
4420 ** the 2nd parameter of the sqlite3_result_text* interfaces.
4421 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
4422 ** is negative, then SQLite takes result text from the 2nd parameter
4423 ** through the first zero character.
@@ -4457,10 +4499,11 @@
4457 ** If these routines are called from within the different thread
4458 ** than the one containing the application-defined function that received
4459 ** the [sqlite3_context] pointer, the results are undefined.
4460 */
4461 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
 
4462 SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
4463 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
4464 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
4465 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
4466 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
@@ -4467,10 +4510,12 @@
4467 SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
4468 SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
4469 SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
4470 SQLITE_API void sqlite3_result_null(sqlite3_context*);
4471 SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
 
 
4472 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
4473 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
4474 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
4475 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4476 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
@@ -6360,25 +6405,25 @@
6360 ** memory already being in use.
6361 ** Only the high-water value is meaningful;
6362 ** the current value is always zero.)^
6363 **
6364 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6365 ** <dd>This parameter returns the approximate number of of bytes of heap
6366 ** memory used by all pager caches associated with the database connection.)^
6367 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
6368 **
6369 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
6370 ** <dd>This parameter returns the approximate number of of bytes of heap
6371 ** memory used to store the schema for all databases associated
6372 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
6373 ** ^The full amount of memory used by the schemas is reported, even if the
6374 ** schema memory is shared with other database connections due to
6375 ** [shared cache mode] being enabled.
6376 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
6377 **
6378 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
6379 ** <dd>This parameter returns the approximate number of of bytes of heap
6380 ** and lookaside memory used by all prepared statements associated with
6381 ** the database connection.)^
6382 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
6383 ** </dd>
6384 **
6385
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.7"
111 #define SQLITE_VERSION_NUMBER 3008007
112 #define SQLITE_SOURCE_ID "2014-09-20 00:35:05 59e2c9df02d7e988c5ad44c560ead1e5288b12e7"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -495,10 +495,11 @@
495 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
496 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
497 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
498 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
499 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
500 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
501
502 /*
503 ** CAPI3REF: Flags For File Open Operations
504 **
505 ** These bit values are intended for use in the
@@ -2097,11 +2098,11 @@
2098 **
2099 ** ^Calling this routine with an argument less than or equal to zero
2100 ** turns off all busy handlers.
2101 **
2102 ** ^(There can only be a single busy handler for a particular
2103 ** [database connection] at any given moment. If another busy handler
2104 ** was defined (using [sqlite3_busy_handler()]) prior to calling
2105 ** this routine, that other busy handler is cleared.)^
2106 **
2107 ** See also: [PRAGMA busy_timeout]
2108 */
@@ -2300,10 +2301,14 @@
2301 ** of memory at least N bytes in length, where N is the parameter.
2302 ** ^If sqlite3_malloc() is unable to obtain sufficient free
2303 ** memory, it returns a NULL pointer. ^If the parameter N to
2304 ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
2305 ** a NULL pointer.
2306 **
2307 ** ^The sqlite3_malloc64(N) routine works just like
2308 ** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
2309 ** of a signed 32-bit integer.
2310 **
2311 ** ^Calling sqlite3_free() with a pointer previously returned
2312 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
2313 ** that it might be reused. ^The sqlite3_free() routine is
2314 ** a no-op if is called with a NULL pointer. Passing a NULL pointer
@@ -2312,28 +2317,42 @@
2317 ** memory might result in a segmentation fault or other severe error.
2318 ** Memory corruption, a segmentation fault, or other severe error
2319 ** might result if sqlite3_free() is called with a non-NULL pointer that
2320 ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
2321 **
2322 ** ^The sqlite3_realloc(X,N) interface attempts to resize a
2323 ** prior memory allocation X to be at least N bytes.
2324 ** ^If the X parameter to sqlite3_realloc(X,N)
 
2325 ** is a NULL pointer then its behavior is identical to calling
2326 ** sqlite3_malloc(N).
2327 ** ^If the N parameter to sqlite3_realloc(X,N) is zero or
2328 ** negative then the behavior is exactly the same as calling
2329 ** sqlite3_free(X).
2330 ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
2331 ** of at least N bytes in size or NULL if insufficient memory is available.
2332 ** ^If M is the size of the prior allocation, then min(N,M) bytes
2333 ** of the prior allocation are copied into the beginning of buffer returned
2334 ** by sqlite3_realloc(X,N) and the prior allocation is freed.
2335 ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
2336 ** prior allocation is not freed.
2337 **
2338 ** ^The sqlite3_realloc64(X,N) interfaces works the same as
2339 ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
2340 ** of a 32-bit signed integer.
2341 **
2342 ** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
2343 ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
2344 ** sqlite3_msize(X) returns the size of that memory allocation in bytes.
2345 ** ^The value returned by sqlite3_msize(X) might be larger than the number
2346 ** of bytes requested when X was allocated. ^If X is a NULL pointer then
2347 ** sqlite3_msize(X) returns zero. If X points to something that is not
2348 ** the beginning of memory allocation, or if it points to a formerly
2349 ** valid memory allocation that has now been freed, then the behavior
2350 ** of sqlite3_msize(X) is undefined and possibly harmful.
2351 **
2352 ** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
2353 ** sqlite3_malloc64(), and sqlite3_realloc64()
2354 ** is always aligned to at least an 8 byte boundary, or to a
2355 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
2356 ** option is used.
2357 **
2358 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
@@ -2357,12 +2376,15 @@
2376 ** The application must not read or write any part of
2377 ** a block of memory after it has been released using
2378 ** [sqlite3_free()] or [sqlite3_realloc()].
2379 */
2380 SQLITE_API void *sqlite3_malloc(int);
2381 SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
2382 SQLITE_API void *sqlite3_realloc(void*, int);
2383 SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
2384 SQLITE_API void sqlite3_free(void*);
2385 SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
2386
2387 /*
2388 ** CAPI3REF: Memory Allocator Statistics
2389 **
2390 ** SQLite provides these two interfaces for reporting on the status
@@ -3367,11 +3389,12 @@
3389 ** is negative, then the length of the string is
3390 ** the number of bytes up to the first zero terminator.
3391 ** If the fourth parameter to sqlite3_bind_blob() is negative, then
3392 ** the behavior is undefined.
3393 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3394 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
3395 ** that parameter must be the byte offset
3396 ** where the NUL terminator would occur assuming the string were NUL
3397 ** terminated. If any NUL characters occur at byte offsets less than
3398 ** the value of the fourth parameter then the resulting string value will
3399 ** contain embedded NULs. The result of expressions involving strings
3400 ** with embedded NULs is undefined.
@@ -3385,10 +3408,18 @@
3408 ** the special value [SQLITE_STATIC], then SQLite assumes that the
3409 ** information is in static, unmanaged space and does not need to be freed.
3410 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
3411 ** SQLite makes its own private copy of the data immediately, before
3412 ** the sqlite3_bind_*() routine returns.
3413 **
3414 ** ^The sixth argument to sqlite3_bind_text64() must be one of
3415 ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
3416 ** to specify the encoding of the text in the third parameter. If
3417 ** the sixth argument to sqlite3_bind_text64() is not how of the
3418 ** allowed values shown above, or if the text encoding is different
3419 ** from the encoding specified by the sixth parameter, then the behavior
3420 ** is undefined.
3421 **
3422 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
3423 ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
3424 ** (just an integer to hold its size) while it is being processed.
3425 ** Zeroblobs are intended to serve as placeholders for BLOBs whose
@@ -3406,23 +3437,30 @@
3437 ** ^Bindings are not cleared by the [sqlite3_reset()] routine.
3438 ** ^Unbound parameters are interpreted as NULL.
3439 **
3440 ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
3441 ** [error code] if anything goes wrong.
3442 ** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
3443 ** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
3444 ** [SQLITE_MAX_LENGTH].
3445 ** ^[SQLITE_RANGE] is returned if the parameter
3446 ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
3447 **
3448 ** See also: [sqlite3_bind_parameter_count()],
3449 ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
3450 */
3451 SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
3452 SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
3453 void(*)(void*));
3454 SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
3455 SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
3456 SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
3457 SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
3458 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
3459 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
3460 SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
3461 void(*)(void*), unsigned char encoding);
3462 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3463 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3464
3465 /*
3466 ** CAPI3REF: Number Of SQL Parameters
@@ -4167,11 +4205,11 @@
4205 ** These routines work only with [protected sqlite3_value] objects.
4206 ** Any attempt to use these routines on an [unprotected sqlite3_value]
4207 ** object results in undefined behavior.
4208 **
4209 ** ^These routines work just like the corresponding [column access functions]
4210 ** except that these routines take a single [protected sqlite3_value] object
4211 ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
4212 **
4213 ** ^The sqlite3_value_text16() interface extracts a UTF-16 string
4214 ** in the native byte-order of the host machine. ^The
4215 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
@@ -4410,14 +4448,18 @@
4448 **
4449 ** ^The sqlite3_result_null() interface sets the return value
4450 ** of the application-defined function to be NULL.
4451 **
4452 ** ^The sqlite3_result_text(), sqlite3_result_text16(),
4453 ** sqlite3_result_text16le(), and sqlite3_result_text16be()
4454 ** set the return value of the application-defined function to be
4455 ** a text string which is represented as UTF-8, UTF-16 native byte order,
4456 ** UTF-16 little endian, or UTF-16 big endian, respectively.
4457 ** ^The sqlite3_result_text64() interface sets the return value of an
4458 ** application-defined function to be a text string in an encoding
4459 ** specified by the fifth (and last) parameter, which must be one
4460 ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
4461 ** ^SQLite takes the text result from the application from
4462 ** the 2nd parameter of the sqlite3_result_text* interfaces.
4463 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
4464 ** is negative, then SQLite takes result text from the 2nd parameter
4465 ** through the first zero character.
@@ -4457,10 +4499,11 @@
4499 ** If these routines are called from within the different thread
4500 ** than the one containing the application-defined function that received
4501 ** the [sqlite3_context] pointer, the results are undefined.
4502 */
4503 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
4504 SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint64,void(*)(void*));
4505 SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
4506 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
4507 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
4508 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
4509 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
@@ -4467,10 +4510,12 @@
4510 SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
4511 SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
4512 SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
4513 SQLITE_API void sqlite3_result_null(sqlite3_context*);
4514 SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
4515 SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
4516 void(*)(void*), unsigned char encoding);
4517 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
4518 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
4519 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
4520 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4521 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
@@ -6360,25 +6405,25 @@
6405 ** memory already being in use.
6406 ** Only the high-water value is meaningful;
6407 ** the current value is always zero.)^
6408 **
6409 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6410 ** <dd>This parameter returns the approximate number of bytes of heap
6411 ** memory used by all pager caches associated with the database connection.)^
6412 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
6413 **
6414 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
6415 ** <dd>This parameter returns the approximate number of bytes of heap
6416 ** memory used to store the schema for all databases associated
6417 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
6418 ** ^The full amount of memory used by the schemas is reported, even if the
6419 ** schema memory is shared with other database connections due to
6420 ** [shared cache mode] being enabled.
6421 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
6422 **
6423 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
6424 ** <dd>This parameter returns the approximate number of bytes of heap
6425 ** and lookaside memory used by all prepared statements associated with
6426 ** the database connection.)^
6427 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
6428 ** </dd>
6429 **
6430
+2 -1
--- src/tar.c
+++ src/tar.c
@@ -492,12 +492,13 @@
492492
mTime = (pManifest->rDate - 2440587.5)*86400.0;
493493
tar_begin(mTime);
494494
if( db_get_boolean("manifest", 0) ){
495495
blob_append(&filename, "manifest", -1);
496496
zName = blob_str(&filename);
497
- tar_add_file(zName, &mfile, 0, mTime);
498497
sha1sum_blob(&mfile, &hash);
498
+ sterilize_manifest(&mfile);
499
+ tar_add_file(zName, &mfile, 0, mTime);
499500
blob_reset(&mfile);
500501
blob_append(&hash, "\n", 1);
501502
blob_resize(&filename, nPrefix);
502503
blob_append(&filename, "manifest.uuid", -1);
503504
zName = blob_str(&filename);
504505
--- src/tar.c
+++ src/tar.c
@@ -492,12 +492,13 @@
492 mTime = (pManifest->rDate - 2440587.5)*86400.0;
493 tar_begin(mTime);
494 if( db_get_boolean("manifest", 0) ){
495 blob_append(&filename, "manifest", -1);
496 zName = blob_str(&filename);
497 tar_add_file(zName, &mfile, 0, mTime);
498 sha1sum_blob(&mfile, &hash);
 
 
499 blob_reset(&mfile);
500 blob_append(&hash, "\n", 1);
501 blob_resize(&filename, nPrefix);
502 blob_append(&filename, "manifest.uuid", -1);
503 zName = blob_str(&filename);
504
--- src/tar.c
+++ src/tar.c
@@ -492,12 +492,13 @@
492 mTime = (pManifest->rDate - 2440587.5)*86400.0;
493 tar_begin(mTime);
494 if( db_get_boolean("manifest", 0) ){
495 blob_append(&filename, "manifest", -1);
496 zName = blob_str(&filename);
 
497 sha1sum_blob(&mfile, &hash);
498 sterilize_manifest(&mfile);
499 tar_add_file(zName, &mfile, 0, mTime);
500 blob_reset(&mfile);
501 blob_append(&hash, "\n", 1);
502 blob_resize(&filename, nPrefix);
503 blob_append(&filename, "manifest.uuid", -1);
504 zName = blob_str(&filename);
505
+29 -3
--- src/tkt.c
+++ src/tkt.c
@@ -273,10 +273,33 @@
273273
blob_reset(&sql2);
274274
blob_reset(&sql3);
275275
fossil_free(aUsed);
276276
return tktid;
277277
}
278
+
279
+/*
280
+** Returns non-zero if moderation is required for ticket changes and ticket
281
+** attachments.
282
+*/
283
+int ticket_need_moderation(
284
+ int localUser /* Are we being called for a local interactive user? */
285
+){
286
+ /*
287
+ ** If the FOSSIL_FORCE_TICKET_MODERATION variable is set, *ALL* changes for
288
+ ** tickets will be required to go through moderation (even those performed
289
+ ** by the local interactive user via the command line). This can be useful
290
+ ** for local (or remote) testing of the moderation subsystem and its impact
291
+ ** on the contents and status of tickets.
292
+ */
293
+ if( fossil_getenv("FOSSIL_FORCE_TICKET_MODERATION")!=0 ){
294
+ return 1;
295
+ }
296
+ if( localUser ){
297
+ return 0;
298
+ }
299
+ return g.perm.ModTkt==0 && db_get_boolean("modreq-tkt",0)==1;
300
+}
278301
279302
/*
280303
** Rebuild an entire entry in the TICKET table
281304
*/
282305
void ticket_rebuild_entry(const char *zTktUuid){
@@ -567,10 +590,11 @@
567590
char *zDate;
568591
const char *zUuid;
569592
int i;
570593
int nJ = 0;
571594
Blob tktchng, cksum;
595
+ int needMod;
572596
573597
login_verify_csrf_secret();
574598
if( !captcha_is_correct() ){
575599
@ <p class="generalError">Error: Incorrect security code.</p>
576600
return TH_OK;
@@ -622,25 +646,27 @@
622646
blob_appendf(&tktchng, "Z %b\n", &cksum);
623647
if( nJ==0 ){
624648
blob_reset(&tktchng);
625649
return TH_OK;
626650
}
651
+ needMod = ticket_need_moderation(0);
627652
if( g.zPath[0]=='d' ){
653
+ const char *zNeedMod = needMod ? "required" : "skipped";
628654
/* If called from /debug_tktnew or /debug_tktedit... */
629655
@ <font color="blue">
630656
@ <p>Ticket artifact that would have been submitted:</p>
631657
@ <blockquote><pre>%h(blob_str(&tktchng))</pre></blockquote>
658
+ @ <blockquote><pre>Moderation would be %h(zNeedMod).</pre></blockquote>
632659
@ <hr /></font>
633660
return TH_OK;
634661
}else{
635662
if( g.thTrace ){
636663
Th_Trace("submit_ticket {\n<blockquote><pre>\n%h\n</pre></blockquote>\n"
637664
"}<br />\n",
638665
blob_str(&tktchng));
639666
}
640
- ticket_put(&tktchng, zUuid,
641
- (g.perm.ModTkt==0 && db_get_boolean("modreq-tkt",0)==1));
667
+ ticket_put(&tktchng, zUuid, needMod);
642668
}
643669
return ticket_change(zUuid);
644670
}
645671
646672
@@ -1347,14 +1373,14 @@
13471373
}
13481374
blob_appendf(&tktchng, "K %s\n", zTktUuid);
13491375
blob_appendf(&tktchng, "U %F\n", zUser);
13501376
md5sum_blob(&tktchng, &cksum);
13511377
blob_appendf(&tktchng, "Z %b\n", &cksum);
1352
- if( ticket_put(&tktchng, zTktUuid, 0) ){
1378
+ if( ticket_put(&tktchng, zTktUuid, ticket_need_moderation(1)) ){
13531379
fossil_fatal("%s\n", g.zErrMsg);
13541380
}else{
13551381
fossil_print("ticket %s succeeded for %s\n",
13561382
(eCmd==set?"set":"add"),zTktUuid);
13571383
}
13581384
}
13591385
}
13601386
}
13611387
--- src/tkt.c
+++ src/tkt.c
@@ -273,10 +273,33 @@
273 blob_reset(&sql2);
274 blob_reset(&sql3);
275 fossil_free(aUsed);
276 return tktid;
277 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
279 /*
280 ** Rebuild an entire entry in the TICKET table
281 */
282 void ticket_rebuild_entry(const char *zTktUuid){
@@ -567,10 +590,11 @@
567 char *zDate;
568 const char *zUuid;
569 int i;
570 int nJ = 0;
571 Blob tktchng, cksum;
 
572
573 login_verify_csrf_secret();
574 if( !captcha_is_correct() ){
575 @ <p class="generalError">Error: Incorrect security code.</p>
576 return TH_OK;
@@ -622,25 +646,27 @@
622 blob_appendf(&tktchng, "Z %b\n", &cksum);
623 if( nJ==0 ){
624 blob_reset(&tktchng);
625 return TH_OK;
626 }
 
627 if( g.zPath[0]=='d' ){
 
628 /* If called from /debug_tktnew or /debug_tktedit... */
629 @ <font color="blue">
630 @ <p>Ticket artifact that would have been submitted:</p>
631 @ <blockquote><pre>%h(blob_str(&tktchng))</pre></blockquote>
 
632 @ <hr /></font>
633 return TH_OK;
634 }else{
635 if( g.thTrace ){
636 Th_Trace("submit_ticket {\n<blockquote><pre>\n%h\n</pre></blockquote>\n"
637 "}<br />\n",
638 blob_str(&tktchng));
639 }
640 ticket_put(&tktchng, zUuid,
641 (g.perm.ModTkt==0 && db_get_boolean("modreq-tkt",0)==1));
642 }
643 return ticket_change(zUuid);
644 }
645
646
@@ -1347,14 +1373,14 @@
1347 }
1348 blob_appendf(&tktchng, "K %s\n", zTktUuid);
1349 blob_appendf(&tktchng, "U %F\n", zUser);
1350 md5sum_blob(&tktchng, &cksum);
1351 blob_appendf(&tktchng, "Z %b\n", &cksum);
1352 if( ticket_put(&tktchng, zTktUuid, 0) ){
1353 fossil_fatal("%s\n", g.zErrMsg);
1354 }else{
1355 fossil_print("ticket %s succeeded for %s\n",
1356 (eCmd==set?"set":"add"),zTktUuid);
1357 }
1358 }
1359 }
1360 }
1361
--- src/tkt.c
+++ src/tkt.c
@@ -273,10 +273,33 @@
273 blob_reset(&sql2);
274 blob_reset(&sql3);
275 fossil_free(aUsed);
276 return tktid;
277 }
278
279 /*
280 ** Returns non-zero if moderation is required for ticket changes and ticket
281 ** attachments.
282 */
283 int ticket_need_moderation(
284 int localUser /* Are we being called for a local interactive user? */
285 ){
286 /*
287 ** If the FOSSIL_FORCE_TICKET_MODERATION variable is set, *ALL* changes for
288 ** tickets will be required to go through moderation (even those performed
289 ** by the local interactive user via the command line). This can be useful
290 ** for local (or remote) testing of the moderation subsystem and its impact
291 ** on the contents and status of tickets.
292 */
293 if( fossil_getenv("FOSSIL_FORCE_TICKET_MODERATION")!=0 ){
294 return 1;
295 }
296 if( localUser ){
297 return 0;
298 }
299 return g.perm.ModTkt==0 && db_get_boolean("modreq-tkt",0)==1;
300 }
301
302 /*
303 ** Rebuild an entire entry in the TICKET table
304 */
305 void ticket_rebuild_entry(const char *zTktUuid){
@@ -567,10 +590,11 @@
590 char *zDate;
591 const char *zUuid;
592 int i;
593 int nJ = 0;
594 Blob tktchng, cksum;
595 int needMod;
596
597 login_verify_csrf_secret();
598 if( !captcha_is_correct() ){
599 @ <p class="generalError">Error: Incorrect security code.</p>
600 return TH_OK;
@@ -622,25 +646,27 @@
646 blob_appendf(&tktchng, "Z %b\n", &cksum);
647 if( nJ==0 ){
648 blob_reset(&tktchng);
649 return TH_OK;
650 }
651 needMod = ticket_need_moderation(0);
652 if( g.zPath[0]=='d' ){
653 const char *zNeedMod = needMod ? "required" : "skipped";
654 /* If called from /debug_tktnew or /debug_tktedit... */
655 @ <font color="blue">
656 @ <p>Ticket artifact that would have been submitted:</p>
657 @ <blockquote><pre>%h(blob_str(&tktchng))</pre></blockquote>
658 @ <blockquote><pre>Moderation would be %h(zNeedMod).</pre></blockquote>
659 @ <hr /></font>
660 return TH_OK;
661 }else{
662 if( g.thTrace ){
663 Th_Trace("submit_ticket {\n<blockquote><pre>\n%h\n</pre></blockquote>\n"
664 "}<br />\n",
665 blob_str(&tktchng));
666 }
667 ticket_put(&tktchng, zUuid, needMod);
 
668 }
669 return ticket_change(zUuid);
670 }
671
672
@@ -1347,14 +1373,14 @@
1373 }
1374 blob_appendf(&tktchng, "K %s\n", zTktUuid);
1375 blob_appendf(&tktchng, "U %F\n", zUser);
1376 md5sum_blob(&tktchng, &cksum);
1377 blob_appendf(&tktchng, "Z %b\n", &cksum);
1378 if( ticket_put(&tktchng, zTktUuid, ticket_need_moderation(1)) ){
1379 fossil_fatal("%s\n", g.zErrMsg);
1380 }else{
1381 fossil_print("ticket %s succeeded for %s\n",
1382 (eCmd==set?"set":"add"),zTktUuid);
1383 }
1384 }
1385 }
1386 }
1387
+30 -15
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -435,15 +435,24 @@
435435
436436
static const char zDefaultView[] =
437437
@ <table cellpadding="5">
438438
@ <tr><td class="tktDspLabel">Ticket&nbsp;UUID:</td>
439439
@ <th1>
440
-@ if {[hascap s]} {
441
-@ html "<td class='tktDspValue' colspan='3'>$tkt_uuid "
442
-@ html "($tkt_id)</td></tr>\n"
440
+@ if {[info exists tkt_uuid]} {
441
+@ if {[hascap s]} {
442
+@ html "<td class='tktDspValue' colspan='3'>$tkt_uuid "
443
+@ html "($tkt_id)</td></tr>\n"
444
+@ } else {
445
+@ html "<td class='tktDspValue' colspan='3'>$tkt_uuid</td></tr>\n"
446
+@ }
443447
@ } else {
444
-@ html "<td class='tktDspValue' colspan='3'>$tkt_uuid</td></tr>\n"
448
+@ if {[hascap s]} {
449
+@ html "<td class='tktDspValue' colspan='3'>Deleted "
450
+@ html "(0)</td></tr>\n"
451
+@ } else {
452
+@ html "<td class='tktDspValue' colspan='3'>Deleted</td></tr>\n"
453
+@ }
445454
@ }
446455
@ </th1>
447456
@ <tr><td class="tktDspLabel">Title:</td>
448457
@ <td class="tktDspValue" colspan="3">
449458
@ $<title>
@@ -465,11 +474,15 @@
465474
@ </td>
466475
@ <td class="tktDspLabel">Resolution:</td><td class="tktDspValue">
467476
@ $<resolution>
468477
@ </td></tr>
469478
@ <tr><td class="tktDspLabel">Last&nbsp;Modified:</td><td class="tktDspValue">
470
-@ $<tkt_datetime>
479
+@ <th1>
480
+@ if {[info exists tkt_datetime]} {
481
+@ html $tkt_datetime
482
+@ }
483
+@ </th1>
471484
@ </td>
472485
@ <th1>enable_output [hascap e]</th1>
473486
@ <td class="tktDspLabel">Contact:</td><td class="tktDspValue">
474487
@ $<private_contact>
475488
@ </td>
@@ -479,20 +492,22 @@
479492
@ <td colspan="3" valign="top" class="tktDspValue">
480493
@ $<foundin>
481494
@ </td></tr>
482495
@
483496
@ <th1>
484
-@ if {[info exists comment] && [string length $comment]>10} {
485
-@ html {
486
-@ <tr><td class="tktDspLabel">Description:</td></tr>
487
-@ <tr><td colspan="5" class="tktDspValue">
488
-@ }
489
-@ if {[info exists plaintext]} {
490
-@ set r [randhex]
491
-@ wiki "<verbatim-$r links>\n$comment\n</verbatim-$r>"
492
-@ } else {
493
-@ wiki $comment
497
+@ if {[info exists comment]} {
498
+@ if {[string length $comment]>10} {
499
+@ html {
500
+@ <tr><td class="tktDspLabel">Description:</td></tr>
501
+@ <tr><td colspan="5" class="tktDspValue">
502
+@ }
503
+@ if {[info exists plaintext]} {
504
+@ set r [randhex]
505
+@ wiki "<verbatim-$r links>\n$comment\n</verbatim-$r>"
506
+@ } else {
507
+@ wiki $comment
508
+@ }
494509
@ }
495510
@ }
496511
@ set seenRow 0
497512
@ set alwaysPlaintext [info exists plaintext]
498513
@ query {SELECT datetime(tkt_mtime) AS xdate, login AS xlogin,
499514
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -435,15 +435,24 @@
435
436 static const char zDefaultView[] =
437 @ <table cellpadding="5">
438 @ <tr><td class="tktDspLabel">Ticket&nbsp;UUID:</td>
439 @ <th1>
440 @ if {[hascap s]} {
441 @ html "<td class='tktDspValue' colspan='3'>$tkt_uuid "
442 @ html "($tkt_id)</td></tr>\n"
 
 
 
 
443 @ } else {
444 @ html "<td class='tktDspValue' colspan='3'>$tkt_uuid</td></tr>\n"
 
 
 
 
 
445 @ }
446 @ </th1>
447 @ <tr><td class="tktDspLabel">Title:</td>
448 @ <td class="tktDspValue" colspan="3">
449 @ $<title>
@@ -465,11 +474,15 @@
465 @ </td>
466 @ <td class="tktDspLabel">Resolution:</td><td class="tktDspValue">
467 @ $<resolution>
468 @ </td></tr>
469 @ <tr><td class="tktDspLabel">Last&nbsp;Modified:</td><td class="tktDspValue">
470 @ $<tkt_datetime>
 
 
 
 
471 @ </td>
472 @ <th1>enable_output [hascap e]</th1>
473 @ <td class="tktDspLabel">Contact:</td><td class="tktDspValue">
474 @ $<private_contact>
475 @ </td>
@@ -479,20 +492,22 @@
479 @ <td colspan="3" valign="top" class="tktDspValue">
480 @ $<foundin>
481 @ </td></tr>
482 @
483 @ <th1>
484 @ if {[info exists comment] && [string length $comment]>10} {
485 @ html {
486 @ <tr><td class="tktDspLabel">Description:</td></tr>
487 @ <tr><td colspan="5" class="tktDspValue">
488 @ }
489 @ if {[info exists plaintext]} {
490 @ set r [randhex]
491 @ wiki "<verbatim-$r links>\n$comment\n</verbatim-$r>"
492 @ } else {
493 @ wiki $comment
 
 
494 @ }
495 @ }
496 @ set seenRow 0
497 @ set alwaysPlaintext [info exists plaintext]
498 @ query {SELECT datetime(tkt_mtime) AS xdate, login AS xlogin,
499
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -435,15 +435,24 @@
435
436 static const char zDefaultView[] =
437 @ <table cellpadding="5">
438 @ <tr><td class="tktDspLabel">Ticket&nbsp;UUID:</td>
439 @ <th1>
440 @ if {[info exists tkt_uuid]} {
441 @ if {[hascap s]} {
442 @ html "<td class='tktDspValue' colspan='3'>$tkt_uuid "
443 @ html "($tkt_id)</td></tr>\n"
444 @ } else {
445 @ html "<td class='tktDspValue' colspan='3'>$tkt_uuid</td></tr>\n"
446 @ }
447 @ } else {
448 @ if {[hascap s]} {
449 @ html "<td class='tktDspValue' colspan='3'>Deleted "
450 @ html "(0)</td></tr>\n"
451 @ } else {
452 @ html "<td class='tktDspValue' colspan='3'>Deleted</td></tr>\n"
453 @ }
454 @ }
455 @ </th1>
456 @ <tr><td class="tktDspLabel">Title:</td>
457 @ <td class="tktDspValue" colspan="3">
458 @ $<title>
@@ -465,11 +474,15 @@
474 @ </td>
475 @ <td class="tktDspLabel">Resolution:</td><td class="tktDspValue">
476 @ $<resolution>
477 @ </td></tr>
478 @ <tr><td class="tktDspLabel">Last&nbsp;Modified:</td><td class="tktDspValue">
479 @ <th1>
480 @ if {[info exists tkt_datetime]} {
481 @ html $tkt_datetime
482 @ }
483 @ </th1>
484 @ </td>
485 @ <th1>enable_output [hascap e]</th1>
486 @ <td class="tktDspLabel">Contact:</td><td class="tktDspValue">
487 @ $<private_contact>
488 @ </td>
@@ -479,20 +492,22 @@
492 @ <td colspan="3" valign="top" class="tktDspValue">
493 @ $<foundin>
494 @ </td></tr>
495 @
496 @ <th1>
497 @ if {[info exists comment]} {
498 @ if {[string length $comment]>10} {
499 @ html {
500 @ <tr><td class="tktDspLabel">Description:</td></tr>
501 @ <tr><td colspan="5" class="tktDspValue">
502 @ }
503 @ if {[info exists plaintext]} {
504 @ set r [randhex]
505 @ wiki "<verbatim-$r links>\n$comment\n</verbatim-$r>"
506 @ } else {
507 @ wiki $comment
508 @ }
509 @ }
510 @ }
511 @ set seenRow 0
512 @ set alwaysPlaintext [info exists plaintext]
513 @ query {SELECT datetime(tkt_mtime) AS xdate, login AS xlogin,
514
--- src/update.c
+++ src/update.c
@@ -144,11 +144,10 @@
144144
}
145145
verboseFlag = find_option("verbose","v",0)!=0;
146146
forceMissingFlag = find_option("force-missing",0,0)!=0;
147147
debugFlag = find_option("debug",0,0)!=0;
148148
setmtimeFlag = find_option("setmtime",0,0)!=0;
149
- capture_case_sensitive_option();
150149
151150
/* We should be done with options.. */
152151
verify_all_options();
153152
154153
db_must_be_within_tree();
155154
--- src/update.c
+++ src/update.c
@@ -144,11 +144,10 @@
144 }
145 verboseFlag = find_option("verbose","v",0)!=0;
146 forceMissingFlag = find_option("force-missing",0,0)!=0;
147 debugFlag = find_option("debug",0,0)!=0;
148 setmtimeFlag = find_option("setmtime",0,0)!=0;
149 capture_case_sensitive_option();
150
151 /* We should be done with options.. */
152 verify_all_options();
153
154 db_must_be_within_tree();
155
--- src/update.c
+++ src/update.c
@@ -144,11 +144,10 @@
144 }
145 verboseFlag = find_option("verbose","v",0)!=0;
146 forceMissingFlag = find_option("force-missing",0,0)!=0;
147 debugFlag = find_option("debug",0,0)!=0;
148 setmtimeFlag = find_option("setmtime",0,0)!=0;
 
149
150 /* We should be done with options.. */
151 verify_all_options();
152
153 db_must_be_within_tree();
154
+30 -8
--- src/wiki.c
+++ src/wiki.c
@@ -156,10 +156,32 @@
156156
@ %h(blob_str(pWiki))
157157
@ </pre>
158158
}
159159
}
160160
161
+/*
162
+** Returns non-zero if moderation is required for wiki changes and wiki
163
+** attachments.
164
+*/
165
+int wiki_need_moderation(
166
+ int localUser /* Are we being called for a local interactive user? */
167
+){
168
+ /*
169
+ ** If the FOSSIL_FORCE_WIKI_MODERATION variable is set, *ALL* changes for
170
+ ** wiki pages will be required to go through moderation (even those performed
171
+ ** by the local interactive user via the command line). This can be useful
172
+ ** for local (or remote) testing of the moderation subsystem and its impact
173
+ ** on the contents and status of wiki pages.
174
+ */
175
+ if( fossil_getenv("FOSSIL_FORCE_WIKI_MODERATION")!=0 ){
176
+ return 1;
177
+ }
178
+ if( localUser ){
179
+ return 0;
180
+ }
181
+ return g.perm.ModWiki==0 && db_get_boolean("modreq-wiki",0)==1;
182
+}
161183
162184
/*
163185
** WEBPAGE: wiki
164186
** URL: /wiki?name=PAGENAME
165187
*/
@@ -282,13 +304,13 @@
282304
}
283305
284306
/*
285307
** Write a wiki artifact into the repository
286308
*/
287
-static void wiki_put(Blob *pWiki, int parent){
309
+static void wiki_put(Blob *pWiki, int parent, int needMod){
288310
int nrid;
289
- if( g.perm.ModWiki || db_get_boolean("modreq-wiki",0)==0 ){
311
+ if( !needMod ){
290312
nrid = content_put_ex(pWiki, 0, 0, 0, 0);
291313
if( parent) content_deltify(parent, nrid, 0);
292314
}else{
293315
nrid = content_put_ex(pWiki, 0, 0, 0, 1);
294316
moderation_table_create();
@@ -427,11 +449,11 @@
427449
}
428450
blob_appendf(&wiki, "W %d\n%s\n", strlen(zBody), zBody);
429451
md5sum_blob(&wiki, &cksum);
430452
blob_appendf(&wiki, "Z %b\n", &cksum);
431453
blob_reset(&cksum);
432
- wiki_put(&wiki, 0);
454
+ wiki_put(&wiki, 0, wiki_need_moderation(0));
433455
}
434456
db_end_transaction(0);
435457
cgi_redirectf("wiki?name=%T", zPageName);
436458
}
437459
if( P("cancel")!=0 ){
@@ -658,11 +680,11 @@
658680
appendRemark(&body, zMimetype);
659681
blob_appendf(&wiki, "W %d\n%s\n", blob_size(&body), blob_str(&body));
660682
md5sum_blob(&wiki, &cksum);
661683
blob_appendf(&wiki, "Z %b\n", &cksum);
662684
blob_reset(&cksum);
663
- wiki_put(&wiki, rid);
685
+ wiki_put(&wiki, rid, wiki_need_moderation(0));
664686
db_end_transaction(0);
665687
}
666688
cgi_redirectf("wiki?name=%T", zPageName);
667689
}
668690
if( P("cancel")!=0 ){
@@ -961,11 +983,11 @@
961983
** zMimeType specifies the N-card for the wiki page. If it is 0,
962984
** empty, or "text/x-fossil-wiki" (the default format) then it is
963985
** ignored.
964986
*/
965987
int wiki_cmd_commit(const char *zPageName, int isNew, Blob *pContent,
966
- const char *zMimeType){
988
+ const char *zMimeType, int localUser){
967989
Blob wiki; /* Wiki page content */
968990
Blob cksum; /* wiki checksum */
969991
int rid; /* artifact ID of parent page */
970992
char *zDate; /* timestamp */
971993
char *zUuid; /* uuid for rid */
@@ -1011,11 +1033,11 @@
10111033
blob_str(pContent) );
10121034
md5sum_blob(&wiki, &cksum);
10131035
blob_appendf(&wiki, "Z %b\n", &cksum);
10141036
blob_reset(&cksum);
10151037
db_begin_transaction();
1016
- wiki_put(&wiki, 0);
1038
+ wiki_put(&wiki, 0, wiki_need_moderation(localUser));
10171039
db_end_transaction(0);
10181040
return 1;
10191041
}
10201042
10211043
/*
@@ -1119,14 +1141,14 @@
11191141
&& (pWiki->zMimetype && *pWiki->zMimetype)){
11201142
zMimeType = pWiki->zMimetype;
11211143
}
11221144
}
11231145
if( g.argv[2][1]=='r' ){
1124
- wiki_cmd_commit(zPageName, 1, &content, zMimeType);
1146
+ wiki_cmd_commit(zPageName, 1, &content, zMimeType, 1);
11251147
fossil_print("Created new wiki page %s.\n", zPageName);
11261148
}else{
1127
- wiki_cmd_commit(zPageName, 0, &content, zMimeType);
1149
+ wiki_cmd_commit(zPageName, 0, &content, zMimeType, 1);
11281150
fossil_print("Updated wiki page %s.\n", zPageName);
11291151
}
11301152
manifest_destroy(pWiki);
11311153
blob_reset(&content);
11321154
}else if( strncmp(g.argv[2],"delete",n)==0 ){
11331155
--- src/wiki.c
+++ src/wiki.c
@@ -156,10 +156,32 @@
156 @ %h(blob_str(pWiki))
157 @ </pre>
158 }
159 }
160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
162 /*
163 ** WEBPAGE: wiki
164 ** URL: /wiki?name=PAGENAME
165 */
@@ -282,13 +304,13 @@
282 }
283
284 /*
285 ** Write a wiki artifact into the repository
286 */
287 static void wiki_put(Blob *pWiki, int parent){
288 int nrid;
289 if( g.perm.ModWiki || db_get_boolean("modreq-wiki",0)==0 ){
290 nrid = content_put_ex(pWiki, 0, 0, 0, 0);
291 if( parent) content_deltify(parent, nrid, 0);
292 }else{
293 nrid = content_put_ex(pWiki, 0, 0, 0, 1);
294 moderation_table_create();
@@ -427,11 +449,11 @@
427 }
428 blob_appendf(&wiki, "W %d\n%s\n", strlen(zBody), zBody);
429 md5sum_blob(&wiki, &cksum);
430 blob_appendf(&wiki, "Z %b\n", &cksum);
431 blob_reset(&cksum);
432 wiki_put(&wiki, 0);
433 }
434 db_end_transaction(0);
435 cgi_redirectf("wiki?name=%T", zPageName);
436 }
437 if( P("cancel")!=0 ){
@@ -658,11 +680,11 @@
658 appendRemark(&body, zMimetype);
659 blob_appendf(&wiki, "W %d\n%s\n", blob_size(&body), blob_str(&body));
660 md5sum_blob(&wiki, &cksum);
661 blob_appendf(&wiki, "Z %b\n", &cksum);
662 blob_reset(&cksum);
663 wiki_put(&wiki, rid);
664 db_end_transaction(0);
665 }
666 cgi_redirectf("wiki?name=%T", zPageName);
667 }
668 if( P("cancel")!=0 ){
@@ -961,11 +983,11 @@
961 ** zMimeType specifies the N-card for the wiki page. If it is 0,
962 ** empty, or "text/x-fossil-wiki" (the default format) then it is
963 ** ignored.
964 */
965 int wiki_cmd_commit(const char *zPageName, int isNew, Blob *pContent,
966 const char *zMimeType){
967 Blob wiki; /* Wiki page content */
968 Blob cksum; /* wiki checksum */
969 int rid; /* artifact ID of parent page */
970 char *zDate; /* timestamp */
971 char *zUuid; /* uuid for rid */
@@ -1011,11 +1033,11 @@
1011 blob_str(pContent) );
1012 md5sum_blob(&wiki, &cksum);
1013 blob_appendf(&wiki, "Z %b\n", &cksum);
1014 blob_reset(&cksum);
1015 db_begin_transaction();
1016 wiki_put(&wiki, 0);
1017 db_end_transaction(0);
1018 return 1;
1019 }
1020
1021 /*
@@ -1119,14 +1141,14 @@
1119 && (pWiki->zMimetype && *pWiki->zMimetype)){
1120 zMimeType = pWiki->zMimetype;
1121 }
1122 }
1123 if( g.argv[2][1]=='r' ){
1124 wiki_cmd_commit(zPageName, 1, &content, zMimeType);
1125 fossil_print("Created new wiki page %s.\n", zPageName);
1126 }else{
1127 wiki_cmd_commit(zPageName, 0, &content, zMimeType);
1128 fossil_print("Updated wiki page %s.\n", zPageName);
1129 }
1130 manifest_destroy(pWiki);
1131 blob_reset(&content);
1132 }else if( strncmp(g.argv[2],"delete",n)==0 ){
1133
--- src/wiki.c
+++ src/wiki.c
@@ -156,10 +156,32 @@
156 @ %h(blob_str(pWiki))
157 @ </pre>
158 }
159 }
160
161 /*
162 ** Returns non-zero if moderation is required for wiki changes and wiki
163 ** attachments.
164 */
165 int wiki_need_moderation(
166 int localUser /* Are we being called for a local interactive user? */
167 ){
168 /*
169 ** If the FOSSIL_FORCE_WIKI_MODERATION variable is set, *ALL* changes for
170 ** wiki pages will be required to go through moderation (even those performed
171 ** by the local interactive user via the command line). This can be useful
172 ** for local (or remote) testing of the moderation subsystem and its impact
173 ** on the contents and status of wiki pages.
174 */
175 if( fossil_getenv("FOSSIL_FORCE_WIKI_MODERATION")!=0 ){
176 return 1;
177 }
178 if( localUser ){
179 return 0;
180 }
181 return g.perm.ModWiki==0 && db_get_boolean("modreq-wiki",0)==1;
182 }
183
184 /*
185 ** WEBPAGE: wiki
186 ** URL: /wiki?name=PAGENAME
187 */
@@ -282,13 +304,13 @@
304 }
305
306 /*
307 ** Write a wiki artifact into the repository
308 */
309 static void wiki_put(Blob *pWiki, int parent, int needMod){
310 int nrid;
311 if( !needMod ){
312 nrid = content_put_ex(pWiki, 0, 0, 0, 0);
313 if( parent) content_deltify(parent, nrid, 0);
314 }else{
315 nrid = content_put_ex(pWiki, 0, 0, 0, 1);
316 moderation_table_create();
@@ -427,11 +449,11 @@
449 }
450 blob_appendf(&wiki, "W %d\n%s\n", strlen(zBody), zBody);
451 md5sum_blob(&wiki, &cksum);
452 blob_appendf(&wiki, "Z %b\n", &cksum);
453 blob_reset(&cksum);
454 wiki_put(&wiki, 0, wiki_need_moderation(0));
455 }
456 db_end_transaction(0);
457 cgi_redirectf("wiki?name=%T", zPageName);
458 }
459 if( P("cancel")!=0 ){
@@ -658,11 +680,11 @@
680 appendRemark(&body, zMimetype);
681 blob_appendf(&wiki, "W %d\n%s\n", blob_size(&body), blob_str(&body));
682 md5sum_blob(&wiki, &cksum);
683 blob_appendf(&wiki, "Z %b\n", &cksum);
684 blob_reset(&cksum);
685 wiki_put(&wiki, rid, wiki_need_moderation(0));
686 db_end_transaction(0);
687 }
688 cgi_redirectf("wiki?name=%T", zPageName);
689 }
690 if( P("cancel")!=0 ){
@@ -961,11 +983,11 @@
983 ** zMimeType specifies the N-card for the wiki page. If it is 0,
984 ** empty, or "text/x-fossil-wiki" (the default format) then it is
985 ** ignored.
986 */
987 int wiki_cmd_commit(const char *zPageName, int isNew, Blob *pContent,
988 const char *zMimeType, int localUser){
989 Blob wiki; /* Wiki page content */
990 Blob cksum; /* wiki checksum */
991 int rid; /* artifact ID of parent page */
992 char *zDate; /* timestamp */
993 char *zUuid; /* uuid for rid */
@@ -1011,11 +1033,11 @@
1033 blob_str(pContent) );
1034 md5sum_blob(&wiki, &cksum);
1035 blob_appendf(&wiki, "Z %b\n", &cksum);
1036 blob_reset(&cksum);
1037 db_begin_transaction();
1038 wiki_put(&wiki, 0, wiki_need_moderation(localUser));
1039 db_end_transaction(0);
1040 return 1;
1041 }
1042
1043 /*
@@ -1119,14 +1141,14 @@
1141 && (pWiki->zMimetype && *pWiki->zMimetype)){
1142 zMimeType = pWiki->zMimetype;
1143 }
1144 }
1145 if( g.argv[2][1]=='r' ){
1146 wiki_cmd_commit(zPageName, 1, &content, zMimeType, 1);
1147 fossil_print("Created new wiki page %s.\n", zPageName);
1148 }else{
1149 wiki_cmd_commit(zPageName, 0, &content, zMimeType, 1);
1150 fossil_print("Updated wiki page %s.\n", zPageName);
1151 }
1152 manifest_destroy(pWiki);
1153 blob_reset(&content);
1154 }else if( strncmp(g.argv[2],"delete",n)==0 ){
1155
+22 -7
--- src/winhttp.c
+++ src/winhttp.c
@@ -32,10 +32,11 @@
3232
typedef struct HttpRequest HttpRequest;
3333
struct HttpRequest {
3434
int id; /* ID counter */
3535
SOCKET s; /* Socket on which to receive data */
3636
SOCKADDR_IN addr; /* Address from which data is coming */
37
+ int flags; /* Flags passed to win32_http_server() */
3738
const char *zOptions; /* --notfound and/or --localauth options */
3839
};
3940
4041
/*
4142
** Prefix for a temporary file.
@@ -111,14 +112,26 @@
111112
}
112113
wanted -= got;
113114
}
114115
fclose(out);
115116
out = 0;
116
- sqlite3_snprintf(sizeof(zCmd), zCmd, "%s%s\n%s\n%s\n%s",
117
- get_utf8_bom(0), g.zRepositoryName, zRequestFName, zReplyFName,
118
- inet_ntoa(p->addr.sin_addr)
119
- );
117
+ /*
118
+ ** The repository name is only needed if there was no open checkout. This
119
+ ** is designed to allow the open checkout for the interactive user to work
120
+ ** with the local Fossil server started via the "ui" command.
121
+ */
122
+ if( (p->flags & HTTP_SERVER_HAD_CHECKOUT)==0 ){
123
+ assert( g.zRepositoryName && g.zRepositoryName[0] );
124
+ sqlite3_snprintf(sizeof(zCmd), zCmd, "%s%s\n%s\n%s\n%s",
125
+ get_utf8_bom(0), zRequestFName, zReplyFName, inet_ntoa(p->addr.sin_addr),
126
+ g.zRepositoryName
127
+ );
128
+ }else{
129
+ sqlite3_snprintf(sizeof(zCmd), zCmd, "%s%s\n%s\n%s",
130
+ get_utf8_bom(0), zRequestFName, zReplyFName, inet_ntoa(p->addr.sin_addr)
131
+ );
132
+ }
120133
out = fossil_fopen(zCmdFName, "wb");
121134
if( out==0 ) goto end_request;
122135
fwrite(zCmd, 1, strlen(zCmd), out);
123136
fclose(out);
124137
@@ -180,14 +193,15 @@
180193
fwrite(zHdr, 1, got, out);
181194
wanted += got;
182195
}
183196
fclose(out);
184197
out = 0;
198
+ assert( g.zRepositoryName && g.zRepositoryName[0] );
185199
sqlite3_snprintf(sizeof(zCmd), zCmd,
186
- "\"%s\" http \"%s\" %s %s %s --scgi --nossl%s",
187
- g.nameOfExe, g.zRepositoryName, zRequestFName, zReplyFName,
188
- inet_ntoa(p->addr.sin_addr), p->zOptions
200
+ "\"%s\" http \"%s\" \"%s\" %s \"%s\" --scgi --nossl%s",
201
+ g.nameOfExe, zRequestFName, zReplyFName, inet_ntoa(p->addr.sin_addr),
202
+ g.zRepositoryName, p->zOptions
189203
);
190204
fossil_system(zCmd);
191205
in = fossil_fopen(zReplyFName, "rb");
192206
if( in ){
193207
while( (got = fread(zHdr, 1, sizeof(zHdr), in))>0 ){
@@ -318,10 +332,11 @@
318332
}
319333
p = fossil_malloc( sizeof(*p) );
320334
p->id = ++idCnt;
321335
p->s = client;
322336
p->addr = client_addr;
337
+ p->flags = flags;
323338
p->zOptions = blob_str(&options);
324339
if( flags & HTTP_SERVER_SCGI ){
325340
_beginthread(win32_scgi_request, 0, (void*)p);
326341
}else{
327342
_beginthread(win32_http_request, 0, (void*)p);
328343
--- src/winhttp.c
+++ src/winhttp.c
@@ -32,10 +32,11 @@
32 typedef struct HttpRequest HttpRequest;
33 struct HttpRequest {
34 int id; /* ID counter */
35 SOCKET s; /* Socket on which to receive data */
36 SOCKADDR_IN addr; /* Address from which data is coming */
 
37 const char *zOptions; /* --notfound and/or --localauth options */
38 };
39
40 /*
41 ** Prefix for a temporary file.
@@ -111,14 +112,26 @@
111 }
112 wanted -= got;
113 }
114 fclose(out);
115 out = 0;
116 sqlite3_snprintf(sizeof(zCmd), zCmd, "%s%s\n%s\n%s\n%s",
117 get_utf8_bom(0), g.zRepositoryName, zRequestFName, zReplyFName,
118 inet_ntoa(p->addr.sin_addr)
119 );
 
 
 
 
 
 
 
 
 
 
 
 
120 out = fossil_fopen(zCmdFName, "wb");
121 if( out==0 ) goto end_request;
122 fwrite(zCmd, 1, strlen(zCmd), out);
123 fclose(out);
124
@@ -180,14 +193,15 @@
180 fwrite(zHdr, 1, got, out);
181 wanted += got;
182 }
183 fclose(out);
184 out = 0;
 
185 sqlite3_snprintf(sizeof(zCmd), zCmd,
186 "\"%s\" http \"%s\" %s %s %s --scgi --nossl%s",
187 g.nameOfExe, g.zRepositoryName, zRequestFName, zReplyFName,
188 inet_ntoa(p->addr.sin_addr), p->zOptions
189 );
190 fossil_system(zCmd);
191 in = fossil_fopen(zReplyFName, "rb");
192 if( in ){
193 while( (got = fread(zHdr, 1, sizeof(zHdr), in))>0 ){
@@ -318,10 +332,11 @@
318 }
319 p = fossil_malloc( sizeof(*p) );
320 p->id = ++idCnt;
321 p->s = client;
322 p->addr = client_addr;
 
323 p->zOptions = blob_str(&options);
324 if( flags & HTTP_SERVER_SCGI ){
325 _beginthread(win32_scgi_request, 0, (void*)p);
326 }else{
327 _beginthread(win32_http_request, 0, (void*)p);
328
--- src/winhttp.c
+++ src/winhttp.c
@@ -32,10 +32,11 @@
32 typedef struct HttpRequest HttpRequest;
33 struct HttpRequest {
34 int id; /* ID counter */
35 SOCKET s; /* Socket on which to receive data */
36 SOCKADDR_IN addr; /* Address from which data is coming */
37 int flags; /* Flags passed to win32_http_server() */
38 const char *zOptions; /* --notfound and/or --localauth options */
39 };
40
41 /*
42 ** Prefix for a temporary file.
@@ -111,14 +112,26 @@
112 }
113 wanted -= got;
114 }
115 fclose(out);
116 out = 0;
117 /*
118 ** The repository name is only needed if there was no open checkout. This
119 ** is designed to allow the open checkout for the interactive user to work
120 ** with the local Fossil server started via the "ui" command.
121 */
122 if( (p->flags & HTTP_SERVER_HAD_CHECKOUT)==0 ){
123 assert( g.zRepositoryName && g.zRepositoryName[0] );
124 sqlite3_snprintf(sizeof(zCmd), zCmd, "%s%s\n%s\n%s\n%s",
125 get_utf8_bom(0), zRequestFName, zReplyFName, inet_ntoa(p->addr.sin_addr),
126 g.zRepositoryName
127 );
128 }else{
129 sqlite3_snprintf(sizeof(zCmd), zCmd, "%s%s\n%s\n%s",
130 get_utf8_bom(0), zRequestFName, zReplyFName, inet_ntoa(p->addr.sin_addr)
131 );
132 }
133 out = fossil_fopen(zCmdFName, "wb");
134 if( out==0 ) goto end_request;
135 fwrite(zCmd, 1, strlen(zCmd), out);
136 fclose(out);
137
@@ -180,14 +193,15 @@
193 fwrite(zHdr, 1, got, out);
194 wanted += got;
195 }
196 fclose(out);
197 out = 0;
198 assert( g.zRepositoryName && g.zRepositoryName[0] );
199 sqlite3_snprintf(sizeof(zCmd), zCmd,
200 "\"%s\" http \"%s\" \"%s\" %s \"%s\" --scgi --nossl%s",
201 g.nameOfExe, zRequestFName, zReplyFName, inet_ntoa(p->addr.sin_addr),
202 g.zRepositoryName, p->zOptions
203 );
204 fossil_system(zCmd);
205 in = fossil_fopen(zReplyFName, "rb");
206 if( in ){
207 while( (got = fread(zHdr, 1, sizeof(zHdr), in))>0 ){
@@ -318,10 +332,11 @@
332 }
333 p = fossil_malloc( sizeof(*p) );
334 p->id = ++idCnt;
335 p->s = client;
336 p->addr = client_addr;
337 p->flags = flags;
338 p->zOptions = blob_str(&options);
339 if( flags & HTTP_SERVER_SCGI ){
340 _beginthread(win32_scgi_request, 0, (void*)p);
341 }else{
342 _beginthread(win32_http_request, 0, (void*)p);
343
+2 -1
--- src/zip.c
+++ src/zip.c
@@ -350,12 +350,13 @@
350350
zip_set_timedate(pManifest->rDate);
351351
if( db_get_boolean("manifest", 0) ){
352352
blob_append(&filename, "manifest", -1);
353353
zName = blob_str(&filename);
354354
zip_add_folders(zName);
355
- zip_add_file(zName, &mfile, 0);
356355
sha1sum_blob(&mfile, &hash);
356
+ sterilize_manifest(&mfile);
357
+ zip_add_file(zName, &mfile, 0);
357358
blob_reset(&mfile);
358359
blob_append(&hash, "\n", 1);
359360
blob_resize(&filename, nPrefix);
360361
blob_append(&filename, "manifest.uuid", -1);
361362
zName = blob_str(&filename);
362363
--- src/zip.c
+++ src/zip.c
@@ -350,12 +350,13 @@
350 zip_set_timedate(pManifest->rDate);
351 if( db_get_boolean("manifest", 0) ){
352 blob_append(&filename, "manifest", -1);
353 zName = blob_str(&filename);
354 zip_add_folders(zName);
355 zip_add_file(zName, &mfile, 0);
356 sha1sum_blob(&mfile, &hash);
 
 
357 blob_reset(&mfile);
358 blob_append(&hash, "\n", 1);
359 blob_resize(&filename, nPrefix);
360 blob_append(&filename, "manifest.uuid", -1);
361 zName = blob_str(&filename);
362
--- src/zip.c
+++ src/zip.c
@@ -350,12 +350,13 @@
350 zip_set_timedate(pManifest->rDate);
351 if( db_get_boolean("manifest", 0) ){
352 blob_append(&filename, "manifest", -1);
353 zName = blob_str(&filename);
354 zip_add_folders(zName);
 
355 sha1sum_blob(&mfile, &hash);
356 sterilize_manifest(&mfile);
357 zip_add_file(zName, &mfile, 0);
358 blob_reset(&mfile);
359 blob_append(&hash, "\n", 1);
360 blob_resize(&filename, nPrefix);
361 blob_append(&filename, "manifest.uuid", -1);
362 zName = blob_str(&filename);
363
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -79,17 +79,17 @@
7979
# the automatically generated source files
8080
UTILS=translate.exe mkindex.exe makeheaders.exe
8181
UTILS_OBJ=$(UTILS:.exe=.obj)
8282
UTILS_SRC=$(foreach uf,$(UTILS),$(SRCDIR)$(uf:.exe=.c))
8383
84
-# define the sqlite files, which need special flags on compile
84
+# define the SQLite files, which need special flags on compile
8585
SQLITESRC=sqlite3.c
8686
ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
8787
SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
8888
SQLITEDEFINES=-DNDEBUG=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_WIN32_NO_ANSI
8989
90
-# define the sqlite shell files, which need special flags on compile
90
+# define the SQLite shell files, which need special flags on compile
9191
SQLITESHELLSRC=shell.c
9292
ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
9393
SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
9494
SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
9595
9696
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -79,17 +79,17 @@
79 # the automatically generated source files
80 UTILS=translate.exe mkindex.exe makeheaders.exe
81 UTILS_OBJ=$(UTILS:.exe=.obj)
82 UTILS_SRC=$(foreach uf,$(UTILS),$(SRCDIR)$(uf:.exe=.c))
83
84 # define the sqlite files, which need special flags on compile
85 SQLITESRC=sqlite3.c
86 ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
87 SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
88 SQLITEDEFINES=-DNDEBUG=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_WIN32_NO_ANSI
89
90 # define the sqlite shell files, which need special flags on compile
91 SQLITESHELLSRC=shell.c
92 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
93 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
94 SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
95
96
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -79,17 +79,17 @@
79 # the automatically generated source files
80 UTILS=translate.exe mkindex.exe makeheaders.exe
81 UTILS_OBJ=$(UTILS:.exe=.obj)
82 UTILS_SRC=$(foreach uf,$(UTILS),$(SRCDIR)$(uf:.exe=.c))
83
84 # define the SQLite files, which need special flags on compile
85 SQLITESRC=sqlite3.c
86 ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
87 SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
88 SQLITEDEFINES=-DNDEBUG=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_WIN32_NO_ANSI
89
90 # define the SQLite shell files, which need special flags on compile
91 SQLITESHELLSRC=shell.c
92 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
93 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
94 SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
95
96
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -73,11 +73,11 @@
7373
7474
#### Load Tcl using the private stubs mechanism
7575
#
7676
# FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
7777
78
-#### Use 'system' sqlite
78
+#### Use 'system' SQLite
7979
#
8080
# USE_SYSTEM_SQLITE = 1
8181
8282
#### Use the miniz compression library
8383
#
@@ -753,11 +753,11 @@
753753
$(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION)
754754
$(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
755755
756756
# The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
757757
# to 1. If it is set to 1, then there is no need to build or link
758
-# the sqlite3.o object. Instead, the system sqlite will be linked
758
+# the sqlite3.o object. Instead, the system SQLite will be linked
759759
# using -lsqlite3.
760760
SQLITE3_OBJ.1 =
761761
SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
762762
SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
763763
764764
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -73,11 +73,11 @@
73
74 #### Load Tcl using the private stubs mechanism
75 #
76 # FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
77
78 #### Use 'system' sqlite
79 #
80 # USE_SYSTEM_SQLITE = 1
81
82 #### Use the miniz compression library
83 #
@@ -753,11 +753,11 @@
753 $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION)
754 $(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
755
756 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
757 # to 1. If it is set to 1, then there is no need to build or link
758 # the sqlite3.o object. Instead, the system sqlite will be linked
759 # using -lsqlite3.
760 SQLITE3_OBJ.1 =
761 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
762 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
763
764
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -73,11 +73,11 @@
73
74 #### Load Tcl using the private stubs mechanism
75 #
76 # FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
77
78 #### Use 'system' SQLite
79 #
80 # USE_SYSTEM_SQLITE = 1
81
82 #### Use the miniz compression library
83 #
@@ -753,11 +753,11 @@
753 $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION)
754 $(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
755
756 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
757 # to 1. If it is set to 1, then there is no need to build or link
758 # the sqlite3.o object. Instead, the system SQLite will be linked
759 # using -lsqlite3.
760 SQLITE3_OBJ.1 =
761 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
762 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
763
764
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -73,11 +73,11 @@
7373
7474
#### Load Tcl using the private stubs mechanism
7575
#
7676
FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
7777
78
-#### Use 'system' sqlite
78
+#### Use 'system' SQLite
7979
#
8080
# USE_SYSTEM_SQLITE = 1
8181
8282
#### Use the miniz compression library
8383
#
@@ -753,11 +753,11 @@
753753
$(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION)
754754
$(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
755755
756756
# The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
757757
# to 1. If it is set to 1, then there is no need to build or link
758
-# the sqlite3.o object. Instead, the system sqlite will be linked
758
+# the sqlite3.o object. Instead, the system SQLite will be linked
759759
# using -lsqlite3.
760760
SQLITE3_OBJ.1 =
761761
SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
762762
SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
763763
764764
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -73,11 +73,11 @@
73
74 #### Load Tcl using the private stubs mechanism
75 #
76 FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
77
78 #### Use 'system' sqlite
79 #
80 # USE_SYSTEM_SQLITE = 1
81
82 #### Use the miniz compression library
83 #
@@ -753,11 +753,11 @@
753 $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION)
754 $(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
755
756 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
757 # to 1. If it is set to 1, then there is no need to build or link
758 # the sqlite3.o object. Instead, the system sqlite will be linked
759 # using -lsqlite3.
760 SQLITE3_OBJ.1 =
761 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
762 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
763
764
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -73,11 +73,11 @@
73
74 #### Load Tcl using the private stubs mechanism
75 #
76 FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
77
78 #### Use 'system' SQLite
79 #
80 # USE_SYSTEM_SQLITE = 1
81
82 #### Use the miniz compression library
83 #
@@ -753,11 +753,11 @@
753 $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION)
754 $(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
755
756 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
757 # to 1. If it is set to 1, then there is no need to build or link
758 # the sqlite3.o object. Instead, the system SQLite will be linked
759 # using -lsqlite3.
760 SQLITE3_OBJ.1 =
761 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
762 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
763
764
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -12,11 +12,15 @@
1212
OBJDIR = .
1313
OX = .
1414
O = .obj
1515
E = .exe
1616
P = .pdb
17
-PERLDIR =
17
+
18
+# Perl is only necessary if OpenSSL support is enabled and it must
19
+# be built from source code. The PERLDIR variable should point to
20
+# the directory containing the main Perl binary (i.e. "perl.exe").
21
+PERLDIR = C:\Perl\bin
1822
PERL = perl.exe
1923
2024
# Uncomment to enable debug symbols
2125
# DEBUG = 1
2226
@@ -38,11 +42,11 @@
3842
# Uncomment to enable Tcl support
3943
# FOSSIL_ENABLE_TCL = 1
4044
4145
!ifdef FOSSIL_ENABLE_SSL
4246
SSLDIR = $(B)\compat\openssl-1.0.1i
43
-SSLINCDIR = $(SSLDIR)\include
47
+SSLINCDIR = $(SSLDIR)\inc32
4448
SSLLIBDIR = $(SSLDIR)\out32
4549
SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
4650
!endif
4751
4852
!ifdef FOSSIL_ENABLE_TCL
@@ -413,11 +417,11 @@
413417
414418
!ifdef FOSSIL_ENABLE_SSL
415419
APPTARGETS = $(APPTARGETS) openssl
416420
!endif
417421
418
-$(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts $(APPTARGETS)
422
+$(APPNAME) : $(APPTARGETS) translate$E mkindex$E headers $(OBJ) $(OX)\linkopts
419423
cd $(OX)
420424
link $(LDFLAGS) /OUT:$@ $(LIBDIR) Wsetargv.obj fossil.res @linkopts
421425
422426
$(OX)\linkopts: $B\win\Makefile.msc
423427
echo $(OX)\add.obj > $@
424428
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -12,11 +12,15 @@
12 OBJDIR = .
13 OX = .
14 O = .obj
15 E = .exe
16 P = .pdb
17 PERLDIR =
 
 
 
 
18 PERL = perl.exe
19
20 # Uncomment to enable debug symbols
21 # DEBUG = 1
22
@@ -38,11 +42,11 @@
38 # Uncomment to enable Tcl support
39 # FOSSIL_ENABLE_TCL = 1
40
41 !ifdef FOSSIL_ENABLE_SSL
42 SSLDIR = $(B)\compat\openssl-1.0.1i
43 SSLINCDIR = $(SSLDIR)\include
44 SSLLIBDIR = $(SSLDIR)\out32
45 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
46 !endif
47
48 !ifdef FOSSIL_ENABLE_TCL
@@ -413,11 +417,11 @@
413
414 !ifdef FOSSIL_ENABLE_SSL
415 APPTARGETS = $(APPTARGETS) openssl
416 !endif
417
418 $(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts $(APPTARGETS)
419 cd $(OX)
420 link $(LDFLAGS) /OUT:$@ $(LIBDIR) Wsetargv.obj fossil.res @linkopts
421
422 $(OX)\linkopts: $B\win\Makefile.msc
423 echo $(OX)\add.obj > $@
424
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -12,11 +12,15 @@
12 OBJDIR = .
13 OX = .
14 O = .obj
15 E = .exe
16 P = .pdb
17
18 # Perl is only necessary if OpenSSL support is enabled and it must
19 # be built from source code. The PERLDIR variable should point to
20 # the directory containing the main Perl binary (i.e. "perl.exe").
21 PERLDIR = C:\Perl\bin
22 PERL = perl.exe
23
24 # Uncomment to enable debug symbols
25 # DEBUG = 1
26
@@ -38,11 +42,11 @@
42 # Uncomment to enable Tcl support
43 # FOSSIL_ENABLE_TCL = 1
44
45 !ifdef FOSSIL_ENABLE_SSL
46 SSLDIR = $(B)\compat\openssl-1.0.1i
47 SSLINCDIR = $(SSLDIR)\inc32
48 SSLLIBDIR = $(SSLDIR)\out32
49 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
50 !endif
51
52 !ifdef FOSSIL_ENABLE_TCL
@@ -413,11 +417,11 @@
417
418 !ifdef FOSSIL_ENABLE_SSL
419 APPTARGETS = $(APPTARGETS) openssl
420 !endif
421
422 $(APPNAME) : $(APPTARGETS) translate$E mkindex$E headers $(OBJ) $(OX)\linkopts
423 cd $(OX)
424 link $(LDFLAGS) /OUT:$@ $(LIBDIR) Wsetargv.obj fossil.res @linkopts
425
426 $(OX)\linkopts: $B\win\Makefile.msc
427 echo $(OX)\add.obj > $@
428

Keyboard Shortcuts

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