Fossil SCM

Merged main trunk into private branch.

michael 2010-07-09 16:25 newbuild merge
Commit 1c28a41cf1957b126173e7a79bcd2889e9684f9a
+1 -1
--- src/blob.c
+++ src/blob.c
@@ -99,11 +99,11 @@
9999
** have run out of memory.
100100
*/
101101
static void blob_panic(void){
102102
static const char zErrMsg[] = "out of memory\n";
103103
write(2, zErrMsg, sizeof(zErrMsg)-1);
104
- exit(1);
104
+ fossil_exit(1);
105105
}
106106
107107
/*
108108
** A reallocation function that assumes that aData came from malloc().
109109
** This function attempts to resize the buffer of the blob to hold
110110
--- src/blob.c
+++ src/blob.c
@@ -99,11 +99,11 @@
99 ** have run out of memory.
100 */
101 static void blob_panic(void){
102 static const char zErrMsg[] = "out of memory\n";
103 write(2, zErrMsg, sizeof(zErrMsg)-1);
104 exit(1);
105 }
106
107 /*
108 ** A reallocation function that assumes that aData came from malloc().
109 ** This function attempts to resize the buffer of the blob to hold
110
--- src/blob.c
+++ src/blob.c
@@ -99,11 +99,11 @@
99 ** have run out of memory.
100 */
101 static void blob_panic(void){
102 static const char zErrMsg[] = "out of memory\n";
103 write(2, zErrMsg, sizeof(zErrMsg)-1);
104 fossil_exit(1);
105 }
106
107 /*
108 ** A reallocation function that assumes that aData came from malloc().
109 ** This function attempts to resize the buffer of the blob to hold
110
+1 -1
--- src/branch.c
+++ src/branch.c
@@ -129,11 +129,11 @@
129129
Blob ans;
130130
blob_zero(&ans);
131131
prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
132132
if( blob_str(&ans)[0]!='y' ){
133133
db_end_transaction(1);
134
- exit(1);
134
+ fossil_exit(1);
135135
}
136136
}
137137
138138
brid = content_put(&branch, 0, 0);
139139
if( brid==0 ){
140140
--- src/branch.c
+++ src/branch.c
@@ -129,11 +129,11 @@
129 Blob ans;
130 blob_zero(&ans);
131 prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
132 if( blob_str(&ans)[0]!='y' ){
133 db_end_transaction(1);
134 exit(1);
135 }
136 }
137
138 brid = content_put(&branch, 0, 0);
139 if( brid==0 ){
140
--- src/branch.c
+++ src/branch.c
@@ -129,11 +129,11 @@
129 Blob ans;
130 blob_zero(&ans);
131 prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
132 if( blob_str(&ans)[0]!='y' ){
133 db_end_transaction(1);
134 fossil_exit(1);
135 }
136 }
137
138 brid = content_put(&branch, 0, 0);
139 if( brid==0 ){
140
+8 -8
--- src/cgi.c
+++ src/cgi.c
@@ -349,11 +349,11 @@
349349
cgi_reset_content();
350350
cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zURL);
351351
cgi_set_status(302, "Moved Temporarily");
352352
free(zLocation);
353353
cgi_reply();
354
- exit(0);
354
+ fossil_exit(0);
355355
}
356356
void cgi_redirectf(const char *zFormat, ...){
357357
va_list ap;
358358
va_start(ap, zFormat);
359359
cgi_redirect(vmprintf(zFormat, ap));
@@ -384,11 +384,11 @@
384384
*/
385385
void cgi_set_parameter_nocopy(const char *zName, const char *zValue){
386386
if( nAllocQP<=nUsedQP ){
387387
nAllocQP = nAllocQP*2 + 10;
388388
aParamQP = realloc( aParamQP, nAllocQP*sizeof(aParamQP[0]) );
389
- if( aParamQP==0 ) exit(1);
389
+ if( aParamQP==0 ) fossil_exit(1);
390390
}
391391
aParamQP[nUsedQP].zName = zName;
392392
aParamQP[nUsedQP].zValue = zValue;
393393
if( g.fHttpTrace ){
394394
fprintf(stderr, "# cgi: %s = [%s]\n", zName, zValue);
@@ -678,11 +678,11 @@
678678
if( len>0 && zType ){
679679
blob_zero(&g.cgiIn);
680680
if( strcmp(zType,"application/x-www-form-urlencoded")==0
681681
|| strncmp(zType,"multipart/form-data",19)==0 ){
682682
z = malloc( len+1 );
683
- if( z==0 ) exit(1);
683
+ if( z==0 ) fossil_exit(1);
684684
len = fread(z, 1, len, g.httpIn);
685685
z[len] = 0;
686686
if( zType[0]=='a' ){
687687
add_param_list(z, '&');
688688
}else{
@@ -1015,11 +1015,11 @@
10151015
cgi_set_status(501, "Not Implemented");
10161016
cgi_printf(
10171017
"<html><body>Unrecognized HTTP Request</body></html>\n"
10181018
);
10191019
cgi_reply();
1020
- exit(0);
1020
+ fossil_exit(0);
10211021
}
10221022
10231023
/*
10241024
** Panic and die while processing a webpage.
10251025
*/
@@ -1033,11 +1033,11 @@
10331033
);
10341034
va_start(ap, zFormat);
10351035
vxprintf(pContent,zFormat,ap);
10361036
va_end(ap);
10371037
cgi_reply();
1038
- exit(1);
1038
+ fossil_exit(1);
10391039
}
10401040
10411041
/*
10421042
** Remove the first space-delimited token from a string and return
10431043
** a pointer to it. Add a NULL to the string to terminate the token.
@@ -1163,11 +1163,11 @@
11631163
** listening socket, return non-zero.
11641164
*/
11651165
int cgi_http_server(int mnPort, int mxPort, char *zBrowser){
11661166
#ifdef __MINGW32__
11671167
/* Use win32_http_server() instead */
1168
- exit(1);
1168
+ fossil_exit(1);
11691169
#else
11701170
int listener = -1; /* The server socket */
11711171
int connection; /* A socket for each individual connection */
11721172
fd_set readfds; /* Set of file descriptors for select() */
11731173
size_t lenaddr; /* Length of the inaddr structure */
@@ -1253,11 +1253,11 @@
12531253
while( waitpid(0, 0, WNOHANG)>0 ){
12541254
nchildren--;
12551255
}
12561256
}
12571257
/* NOT REACHED */
1258
- exit(1);
1258
+ fossil_exit(1);
12591259
#endif
12601260
}
12611261
12621262
12631263
/*
@@ -1356,7 +1356,7 @@
13561356
if( zIf==0 ) return;
13571357
if( objectTime > cgi_rfc822_parsedate(zIf) ) return;
13581358
cgi_set_status(304,"Not Modified");
13591359
cgi_reset_content();
13601360
cgi_reply();
1361
- exit(0);
1361
+ fossil_exit(0);
13621362
}
13631363
--- src/cgi.c
+++ src/cgi.c
@@ -349,11 +349,11 @@
349 cgi_reset_content();
350 cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zURL);
351 cgi_set_status(302, "Moved Temporarily");
352 free(zLocation);
353 cgi_reply();
354 exit(0);
355 }
356 void cgi_redirectf(const char *zFormat, ...){
357 va_list ap;
358 va_start(ap, zFormat);
359 cgi_redirect(vmprintf(zFormat, ap));
@@ -384,11 +384,11 @@
384 */
385 void cgi_set_parameter_nocopy(const char *zName, const char *zValue){
386 if( nAllocQP<=nUsedQP ){
387 nAllocQP = nAllocQP*2 + 10;
388 aParamQP = realloc( aParamQP, nAllocQP*sizeof(aParamQP[0]) );
389 if( aParamQP==0 ) exit(1);
390 }
391 aParamQP[nUsedQP].zName = zName;
392 aParamQP[nUsedQP].zValue = zValue;
393 if( g.fHttpTrace ){
394 fprintf(stderr, "# cgi: %s = [%s]\n", zName, zValue);
@@ -678,11 +678,11 @@
678 if( len>0 && zType ){
679 blob_zero(&g.cgiIn);
680 if( strcmp(zType,"application/x-www-form-urlencoded")==0
681 || strncmp(zType,"multipart/form-data",19)==0 ){
682 z = malloc( len+1 );
683 if( z==0 ) exit(1);
684 len = fread(z, 1, len, g.httpIn);
685 z[len] = 0;
686 if( zType[0]=='a' ){
687 add_param_list(z, '&');
688 }else{
@@ -1015,11 +1015,11 @@
1015 cgi_set_status(501, "Not Implemented");
1016 cgi_printf(
1017 "<html><body>Unrecognized HTTP Request</body></html>\n"
1018 );
1019 cgi_reply();
1020 exit(0);
1021 }
1022
1023 /*
1024 ** Panic and die while processing a webpage.
1025 */
@@ -1033,11 +1033,11 @@
1033 );
1034 va_start(ap, zFormat);
1035 vxprintf(pContent,zFormat,ap);
1036 va_end(ap);
1037 cgi_reply();
1038 exit(1);
1039 }
1040
1041 /*
1042 ** Remove the first space-delimited token from a string and return
1043 ** a pointer to it. Add a NULL to the string to terminate the token.
@@ -1163,11 +1163,11 @@
1163 ** listening socket, return non-zero.
1164 */
1165 int cgi_http_server(int mnPort, int mxPort, char *zBrowser){
1166 #ifdef __MINGW32__
1167 /* Use win32_http_server() instead */
1168 exit(1);
1169 #else
1170 int listener = -1; /* The server socket */
1171 int connection; /* A socket for each individual connection */
1172 fd_set readfds; /* Set of file descriptors for select() */
1173 size_t lenaddr; /* Length of the inaddr structure */
@@ -1253,11 +1253,11 @@
1253 while( waitpid(0, 0, WNOHANG)>0 ){
1254 nchildren--;
1255 }
1256 }
1257 /* NOT REACHED */
1258 exit(1);
1259 #endif
1260 }
1261
1262
1263 /*
@@ -1356,7 +1356,7 @@
1356 if( zIf==0 ) return;
1357 if( objectTime > cgi_rfc822_parsedate(zIf) ) return;
1358 cgi_set_status(304,"Not Modified");
1359 cgi_reset_content();
1360 cgi_reply();
1361 exit(0);
1362 }
1363
--- src/cgi.c
+++ src/cgi.c
@@ -349,11 +349,11 @@
349 cgi_reset_content();
350 cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zURL);
351 cgi_set_status(302, "Moved Temporarily");
352 free(zLocation);
353 cgi_reply();
354 fossil_exit(0);
355 }
356 void cgi_redirectf(const char *zFormat, ...){
357 va_list ap;
358 va_start(ap, zFormat);
359 cgi_redirect(vmprintf(zFormat, ap));
@@ -384,11 +384,11 @@
384 */
385 void cgi_set_parameter_nocopy(const char *zName, const char *zValue){
386 if( nAllocQP<=nUsedQP ){
387 nAllocQP = nAllocQP*2 + 10;
388 aParamQP = realloc( aParamQP, nAllocQP*sizeof(aParamQP[0]) );
389 if( aParamQP==0 ) fossil_exit(1);
390 }
391 aParamQP[nUsedQP].zName = zName;
392 aParamQP[nUsedQP].zValue = zValue;
393 if( g.fHttpTrace ){
394 fprintf(stderr, "# cgi: %s = [%s]\n", zName, zValue);
@@ -678,11 +678,11 @@
678 if( len>0 && zType ){
679 blob_zero(&g.cgiIn);
680 if( strcmp(zType,"application/x-www-form-urlencoded")==0
681 || strncmp(zType,"multipart/form-data",19)==0 ){
682 z = malloc( len+1 );
683 if( z==0 ) fossil_exit(1);
684 len = fread(z, 1, len, g.httpIn);
685 z[len] = 0;
686 if( zType[0]=='a' ){
687 add_param_list(z, '&');
688 }else{
@@ -1015,11 +1015,11 @@
1015 cgi_set_status(501, "Not Implemented");
1016 cgi_printf(
1017 "<html><body>Unrecognized HTTP Request</body></html>\n"
1018 );
1019 cgi_reply();
1020 fossil_exit(0);
1021 }
1022
1023 /*
1024 ** Panic and die while processing a webpage.
1025 */
@@ -1033,11 +1033,11 @@
1033 );
1034 va_start(ap, zFormat);
1035 vxprintf(pContent,zFormat,ap);
1036 va_end(ap);
1037 cgi_reply();
1038 fossil_exit(1);
1039 }
1040
1041 /*
1042 ** Remove the first space-delimited token from a string and return
1043 ** a pointer to it. Add a NULL to the string to terminate the token.
@@ -1163,11 +1163,11 @@
1163 ** listening socket, return non-zero.
1164 */
1165 int cgi_http_server(int mnPort, int mxPort, char *zBrowser){
1166 #ifdef __MINGW32__
1167 /* Use win32_http_server() instead */
1168 fossil_exit(1);
1169 #else
1170 int listener = -1; /* The server socket */
1171 int connection; /* A socket for each individual connection */
1172 fd_set readfds; /* Set of file descriptors for select() */
1173 size_t lenaddr; /* Length of the inaddr structure */
@@ -1253,11 +1253,11 @@
1253 while( waitpid(0, 0, WNOHANG)>0 ){
1254 nchildren--;
1255 }
1256 }
1257 /* NOT REACHED */
1258 fossil_exit(1);
1259 #endif
1260 }
1261
1262
1263 /*
@@ -1356,7 +1356,7 @@
1356 if( zIf==0 ) return;
1357 if( objectTime > cgi_rfc822_parsedate(zIf) ) return;
1358 cgi_set_status(304,"Not Modified");
1359 cgi_reset_content();
1360 cgi_reply();
1361 fossil_exit(0);
1362 }
1363
+2 -4
--- src/checkin.c
+++ src/checkin.c
@@ -691,12 +691,11 @@
691691
if( blob_size(&comment)==0 ){
692692
Blob ans;
693693
blob_zero(&ans);
694694
prompt_user("empty check-in comment. continue (y/N)? ", &ans);
695695
if( blob_str(&ans)[0]!='y' ){
696
- db_end_transaction(1);
697
- exit(1);
696
+ fossil_exit(1);
698697
}
699698
}else{
700699
db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment);
701700
db_end_transaction(0);
702701
db_begin_transaction();
@@ -829,12 +828,11 @@
829828
if( !noSign && !g.markPrivate && clearsign(&manifest, &manifest) ){
830829
Blob ans;
831830
blob_zero(&ans);
832831
prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
833832
if( blob_str(&ans)[0]!='y' ){
834
- db_end_transaction(1);
835
- exit(1);
833
+ fossil_exit(1);
836834
}
837835
}
838836
blob_write_to_file(&manifest, zManifestFile);
839837
blob_reset(&manifest);
840838
blob_read_from_file(&manifest, zManifestFile);
841839
--- src/checkin.c
+++ src/checkin.c
@@ -691,12 +691,11 @@
691 if( blob_size(&comment)==0 ){
692 Blob ans;
693 blob_zero(&ans);
694 prompt_user("empty check-in comment. continue (y/N)? ", &ans);
695 if( blob_str(&ans)[0]!='y' ){
696 db_end_transaction(1);
697 exit(1);
698 }
699 }else{
700 db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment);
701 db_end_transaction(0);
702 db_begin_transaction();
@@ -829,12 +828,11 @@
829 if( !noSign && !g.markPrivate && clearsign(&manifest, &manifest) ){
830 Blob ans;
831 blob_zero(&ans);
832 prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
833 if( blob_str(&ans)[0]!='y' ){
834 db_end_transaction(1);
835 exit(1);
836 }
837 }
838 blob_write_to_file(&manifest, zManifestFile);
839 blob_reset(&manifest);
840 blob_read_from_file(&manifest, zManifestFile);
841
--- src/checkin.c
+++ src/checkin.c
@@ -691,12 +691,11 @@
691 if( blob_size(&comment)==0 ){
692 Blob ans;
693 blob_zero(&ans);
694 prompt_user("empty check-in comment. continue (y/N)? ", &ans);
695 if( blob_str(&ans)[0]!='y' ){
696 fossil_exit(1);
 
697 }
698 }else{
699 db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment);
700 db_end_transaction(0);
701 db_begin_transaction();
@@ -829,12 +828,11 @@
828 if( !noSign && !g.markPrivate && clearsign(&manifest, &manifest) ){
829 Blob ans;
830 blob_zero(&ans);
831 prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
832 if( blob_str(&ans)[0]!='y' ){
833 fossil_exit(1);
 
834 }
835 }
836 blob_write_to_file(&manifest, zManifestFile);
837 blob_reset(&manifest);
838 blob_read_from_file(&manifest, zManifestFile);
839
+7 -2
--- src/db.c
+++ src/db.c
@@ -73,11 +73,11 @@
7373
cgi_reply();
7474
}else{
7575
fprintf(stderr, "%s: %s\n\n%s", g.argv[0], z, zRebuildMsg);
7676
}
7777
db_force_rollback();
78
- exit(1);
78
+ fossil_exit(1);
7979
}
8080
8181
static int nBegin = 0; /* Nesting depth of BEGIN */
8282
static int isNewRepo = 0; /* True if the repository is newly created */
8383
static int doRollback = 0; /* True to force a rollback */
@@ -114,10 +114,11 @@
114114
sqlite3_commit_hook(g.db, db_verify_at_commit, 0);
115115
}
116116
nBegin++;
117117
}
118118
void db_end_transaction(int rollbackFlag){
119
+ if( g.db==0 ) return;
119120
if( nBegin<=0 ) return;
120121
if( rollbackFlag ) doRollback = 1;
121122
nBegin--;
122123
if( nBegin==0 ){
123124
int i;
@@ -128,11 +129,11 @@
128129
doRollback = 0;
129130
}
130131
}
131132
void db_force_rollback(void){
132133
static int busy = 0;
133
- if( busy ) return;
134
+ if( busy || g.db==0 ) return;
134135
busy = 1;
135136
undo_rollback();
136137
if( nBegin ){
137138
sqlite3_exec(g.db, "ROLLBACK", 0, 0, 0);
138139
if( isNewRepo ){
@@ -598,10 +599,11 @@
598599
);
599600
if( rc!=SQLITE_OK ){
600601
db_err(sqlite3_errmsg(db));
601602
}
602603
sqlite3_busy_timeout(db, 5000);
604
+ sqlite3_wal_autocheckpoint(db, 1); /* Set to checkpoint frequently */
603605
return db;
604606
}
605607
606608
607609
/*
@@ -610,16 +612,18 @@
610612
** already open, then attach zDbName using the name zLabel.
611613
*/
612614
void db_open_or_attach(const char *zDbName, const char *zLabel){
613615
if( !g.db ){
614616
g.db = openDatabase(zDbName);
617
+ g.zRepoDb = "main";
615618
db_connection_init();
616619
}else{
617620
#ifdef __MINGW32__
618621
zDbName = sqlite3_win32_mbcs_to_utf8(zDbName);
619622
#endif
620623
db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel);
624
+ g.zRepoDb = mprintf("%s", zLabel);
621625
}
622626
}
623627
624628
/*
625629
** Open the user database in "~/.fossil". Create the database anew if
@@ -894,10 +898,11 @@
894898
void db_close(void){
895899
if( g.db==0 ) return;
896900
while( pAllStmt ){
897901
db_finalize(pAllStmt);
898902
}
903
+ db_end_transaction(1);
899904
g.repositoryOpen = 0;
900905
g.localOpen = 0;
901906
g.configOpen = 0;
902907
sqlite3_close(g.db);
903908
g.db = 0;
904909
--- src/db.c
+++ src/db.c
@@ -73,11 +73,11 @@
73 cgi_reply();
74 }else{
75 fprintf(stderr, "%s: %s\n\n%s", g.argv[0], z, zRebuildMsg);
76 }
77 db_force_rollback();
78 exit(1);
79 }
80
81 static int nBegin = 0; /* Nesting depth of BEGIN */
82 static int isNewRepo = 0; /* True if the repository is newly created */
83 static int doRollback = 0; /* True to force a rollback */
@@ -114,10 +114,11 @@
114 sqlite3_commit_hook(g.db, db_verify_at_commit, 0);
115 }
116 nBegin++;
117 }
118 void db_end_transaction(int rollbackFlag){
 
119 if( nBegin<=0 ) return;
120 if( rollbackFlag ) doRollback = 1;
121 nBegin--;
122 if( nBegin==0 ){
123 int i;
@@ -128,11 +129,11 @@
128 doRollback = 0;
129 }
130 }
131 void db_force_rollback(void){
132 static int busy = 0;
133 if( busy ) return;
134 busy = 1;
135 undo_rollback();
136 if( nBegin ){
137 sqlite3_exec(g.db, "ROLLBACK", 0, 0, 0);
138 if( isNewRepo ){
@@ -598,10 +599,11 @@
598 );
599 if( rc!=SQLITE_OK ){
600 db_err(sqlite3_errmsg(db));
601 }
602 sqlite3_busy_timeout(db, 5000);
 
603 return db;
604 }
605
606
607 /*
@@ -610,16 +612,18 @@
610 ** already open, then attach zDbName using the name zLabel.
611 */
612 void db_open_or_attach(const char *zDbName, const char *zLabel){
613 if( !g.db ){
614 g.db = openDatabase(zDbName);
 
615 db_connection_init();
616 }else{
617 #ifdef __MINGW32__
618 zDbName = sqlite3_win32_mbcs_to_utf8(zDbName);
619 #endif
620 db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel);
 
621 }
622 }
623
624 /*
625 ** Open the user database in "~/.fossil". Create the database anew if
@@ -894,10 +898,11 @@
894 void db_close(void){
895 if( g.db==0 ) return;
896 while( pAllStmt ){
897 db_finalize(pAllStmt);
898 }
 
899 g.repositoryOpen = 0;
900 g.localOpen = 0;
901 g.configOpen = 0;
902 sqlite3_close(g.db);
903 g.db = 0;
904
--- src/db.c
+++ src/db.c
@@ -73,11 +73,11 @@
73 cgi_reply();
74 }else{
75 fprintf(stderr, "%s: %s\n\n%s", g.argv[0], z, zRebuildMsg);
76 }
77 db_force_rollback();
78 fossil_exit(1);
79 }
80
81 static int nBegin = 0; /* Nesting depth of BEGIN */
82 static int isNewRepo = 0; /* True if the repository is newly created */
83 static int doRollback = 0; /* True to force a rollback */
@@ -114,10 +114,11 @@
114 sqlite3_commit_hook(g.db, db_verify_at_commit, 0);
115 }
116 nBegin++;
117 }
118 void db_end_transaction(int rollbackFlag){
119 if( g.db==0 ) return;
120 if( nBegin<=0 ) return;
121 if( rollbackFlag ) doRollback = 1;
122 nBegin--;
123 if( nBegin==0 ){
124 int i;
@@ -128,11 +129,11 @@
129 doRollback = 0;
130 }
131 }
132 void db_force_rollback(void){
133 static int busy = 0;
134 if( busy || g.db==0 ) return;
135 busy = 1;
136 undo_rollback();
137 if( nBegin ){
138 sqlite3_exec(g.db, "ROLLBACK", 0, 0, 0);
139 if( isNewRepo ){
@@ -598,10 +599,11 @@
599 );
600 if( rc!=SQLITE_OK ){
601 db_err(sqlite3_errmsg(db));
602 }
603 sqlite3_busy_timeout(db, 5000);
604 sqlite3_wal_autocheckpoint(db, 1); /* Set to checkpoint frequently */
605 return db;
606 }
607
608
609 /*
@@ -610,16 +612,18 @@
612 ** already open, then attach zDbName using the name zLabel.
613 */
614 void db_open_or_attach(const char *zDbName, const char *zLabel){
615 if( !g.db ){
616 g.db = openDatabase(zDbName);
617 g.zRepoDb = "main";
618 db_connection_init();
619 }else{
620 #ifdef __MINGW32__
621 zDbName = sqlite3_win32_mbcs_to_utf8(zDbName);
622 #endif
623 db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel);
624 g.zRepoDb = mprintf("%s", zLabel);
625 }
626 }
627
628 /*
629 ** Open the user database in "~/.fossil". Create the database anew if
@@ -894,10 +898,11 @@
898 void db_close(void){
899 if( g.db==0 ) return;
900 while( pAllStmt ){
901 db_finalize(pAllStmt);
902 }
903 db_end_transaction(1);
904 g.repositoryOpen = 0;
905 g.localOpen = 0;
906 g.configOpen = 0;
907 sqlite3_close(g.db);
908 g.db = 0;
909
+8 -8
--- src/deltacmd.c
+++ src/deltacmd.c
@@ -50,24 +50,24 @@
5050
*/
5151
void delta_create_cmd(void){
5252
Blob orig, target, delta;
5353
if( g.argc!=5 ){
5454
fprintf(stderr,"Usage: %s %s ORIGIN TARGET DELTA\n", g.argv[0], g.argv[1]);
55
- exit(1);
55
+ fossil_exit(1);
5656
}
5757
if( blob_read_from_file(&orig, g.argv[2])<0 ){
5858
fprintf(stderr,"cannot read %s\n", g.argv[2]);
59
- exit(1);
59
+ fossil_exit(1);
6060
}
6161
if( blob_read_from_file(&target, g.argv[3])<0 ){
6262
fprintf(stderr,"cannot read %s\n", g.argv[3]);
63
- exit(1);
63
+ fossil_exit(1);
6464
}
6565
blob_delta_create(&orig, &target, &delta);
6666
if( blob_write_to_file(&delta, g.argv[4])<blob_size(&delta) ){
6767
fprintf(stderr,"cannot write %s\n", g.argv[4]);
68
- exit(1);
68
+ fossil_exit(1);
6969
}
7070
blob_reset(&orig);
7171
blob_reset(&target);
7272
blob_reset(&delta);
7373
}
@@ -113,24 +113,24 @@
113113
*/
114114
void delta_apply_cmd(void){
115115
Blob orig, target, delta;
116116
if( g.argc!=5 ){
117117
fprintf(stderr,"Usage: %s %s ORIGIN DELTA TARGET\n", g.argv[0], g.argv[1]);
118
- exit(1);
118
+ fossil_exit(1);
119119
}
120120
if( blob_read_from_file(&orig, g.argv[2])<0 ){
121121
fprintf(stderr,"cannot read %s\n", g.argv[2]);
122
- exit(1);
122
+ fossil_exit(1);
123123
}
124124
if( blob_read_from_file(&delta, g.argv[3])<0 ){
125125
fprintf(stderr,"cannot read %s\n", g.argv[3]);
126
- exit(1);
126
+ fossil_exit(1);
127127
}
128128
blob_delta_apply(&orig, &delta, &target);
129129
if( blob_write_to_file(&target, g.argv[4])<blob_size(&target) ){
130130
fprintf(stderr,"cannot write %s\n", g.argv[4]);
131
- exit(1);
131
+ fossil_exit(1);
132132
}
133133
blob_reset(&orig);
134134
blob_reset(&target);
135135
blob_reset(&delta);
136136
}
137137
--- src/deltacmd.c
+++ src/deltacmd.c
@@ -50,24 +50,24 @@
50 */
51 void delta_create_cmd(void){
52 Blob orig, target, delta;
53 if( g.argc!=5 ){
54 fprintf(stderr,"Usage: %s %s ORIGIN TARGET DELTA\n", g.argv[0], g.argv[1]);
55 exit(1);
56 }
57 if( blob_read_from_file(&orig, g.argv[2])<0 ){
58 fprintf(stderr,"cannot read %s\n", g.argv[2]);
59 exit(1);
60 }
61 if( blob_read_from_file(&target, g.argv[3])<0 ){
62 fprintf(stderr,"cannot read %s\n", g.argv[3]);
63 exit(1);
64 }
65 blob_delta_create(&orig, &target, &delta);
66 if( blob_write_to_file(&delta, g.argv[4])<blob_size(&delta) ){
67 fprintf(stderr,"cannot write %s\n", g.argv[4]);
68 exit(1);
69 }
70 blob_reset(&orig);
71 blob_reset(&target);
72 blob_reset(&delta);
73 }
@@ -113,24 +113,24 @@
113 */
114 void delta_apply_cmd(void){
115 Blob orig, target, delta;
116 if( g.argc!=5 ){
117 fprintf(stderr,"Usage: %s %s ORIGIN DELTA TARGET\n", g.argv[0], g.argv[1]);
118 exit(1);
119 }
120 if( blob_read_from_file(&orig, g.argv[2])<0 ){
121 fprintf(stderr,"cannot read %s\n", g.argv[2]);
122 exit(1);
123 }
124 if( blob_read_from_file(&delta, g.argv[3])<0 ){
125 fprintf(stderr,"cannot read %s\n", g.argv[3]);
126 exit(1);
127 }
128 blob_delta_apply(&orig, &delta, &target);
129 if( blob_write_to_file(&target, g.argv[4])<blob_size(&target) ){
130 fprintf(stderr,"cannot write %s\n", g.argv[4]);
131 exit(1);
132 }
133 blob_reset(&orig);
134 blob_reset(&target);
135 blob_reset(&delta);
136 }
137
--- src/deltacmd.c
+++ src/deltacmd.c
@@ -50,24 +50,24 @@
50 */
51 void delta_create_cmd(void){
52 Blob orig, target, delta;
53 if( g.argc!=5 ){
54 fprintf(stderr,"Usage: %s %s ORIGIN TARGET DELTA\n", g.argv[0], g.argv[1]);
55 fossil_exit(1);
56 }
57 if( blob_read_from_file(&orig, g.argv[2])<0 ){
58 fprintf(stderr,"cannot read %s\n", g.argv[2]);
59 fossil_exit(1);
60 }
61 if( blob_read_from_file(&target, g.argv[3])<0 ){
62 fprintf(stderr,"cannot read %s\n", g.argv[3]);
63 fossil_exit(1);
64 }
65 blob_delta_create(&orig, &target, &delta);
66 if( blob_write_to_file(&delta, g.argv[4])<blob_size(&delta) ){
67 fprintf(stderr,"cannot write %s\n", g.argv[4]);
68 fossil_exit(1);
69 }
70 blob_reset(&orig);
71 blob_reset(&target);
72 blob_reset(&delta);
73 }
@@ -113,24 +113,24 @@
113 */
114 void delta_apply_cmd(void){
115 Blob orig, target, delta;
116 if( g.argc!=5 ){
117 fprintf(stderr,"Usage: %s %s ORIGIN DELTA TARGET\n", g.argv[0], g.argv[1]);
118 fossil_exit(1);
119 }
120 if( blob_read_from_file(&orig, g.argv[2])<0 ){
121 fprintf(stderr,"cannot read %s\n", g.argv[2]);
122 fossil_exit(1);
123 }
124 if( blob_read_from_file(&delta, g.argv[3])<0 ){
125 fprintf(stderr,"cannot read %s\n", g.argv[3]);
126 fossil_exit(1);
127 }
128 blob_delta_apply(&orig, &delta, &target);
129 if( blob_write_to_file(&target, g.argv[4])<blob_size(&target) ){
130 fprintf(stderr,"cannot write %s\n", g.argv[4]);
131 fossil_exit(1);
132 }
133 blob_reset(&orig);
134 blob_reset(&target);
135 blob_reset(&delta);
136 }
137
+2 -2
--- src/file.c
+++ src/file.c
@@ -278,11 +278,11 @@
278278
blob_materialize(pOut);
279279
}else{
280280
char zPwd[2000];
281281
if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){
282282
fprintf(stderr, "pwd too big: max %d\n", (int)sizeof(zPwd)-20);
283
- exit(1);
283
+ fossil_exit(1);
284284
}
285285
blob_zero(pOut);
286286
blob_appendf(pOut, "%//%/", zPwd, zOrigName);
287287
}
288288
blob_resize(pOut, file_simplify_name(blob_buffer(pOut), blob_size(pOut)));
@@ -343,11 +343,11 @@
343343
int i, j;
344344
Blob tmp;
345345
char zPwd[2000];
346346
if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){
347347
fprintf(stderr, "pwd too big: max %d\n", (int)sizeof(zPwd)-20);
348
- exit(1);
348
+ fossil_exit(1);
349349
}
350350
for(i=1; zPath[i] && zPwd[i]==zPath[i]; i++){}
351351
if( zPath[i]==0 ){
352352
blob_reset(pOut);
353353
if( zPwd[i]==0 ){
354354
--- src/file.c
+++ src/file.c
@@ -278,11 +278,11 @@
278 blob_materialize(pOut);
279 }else{
280 char zPwd[2000];
281 if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){
282 fprintf(stderr, "pwd too big: max %d\n", (int)sizeof(zPwd)-20);
283 exit(1);
284 }
285 blob_zero(pOut);
286 blob_appendf(pOut, "%//%/", zPwd, zOrigName);
287 }
288 blob_resize(pOut, file_simplify_name(blob_buffer(pOut), blob_size(pOut)));
@@ -343,11 +343,11 @@
343 int i, j;
344 Blob tmp;
345 char zPwd[2000];
346 if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){
347 fprintf(stderr, "pwd too big: max %d\n", (int)sizeof(zPwd)-20);
348 exit(1);
349 }
350 for(i=1; zPath[i] && zPwd[i]==zPath[i]; i++){}
351 if( zPath[i]==0 ){
352 blob_reset(pOut);
353 if( zPwd[i]==0 ){
354
--- src/file.c
+++ src/file.c
@@ -278,11 +278,11 @@
278 blob_materialize(pOut);
279 }else{
280 char zPwd[2000];
281 if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){
282 fprintf(stderr, "pwd too big: max %d\n", (int)sizeof(zPwd)-20);
283 fossil_exit(1);
284 }
285 blob_zero(pOut);
286 blob_appendf(pOut, "%//%/", zPwd, zOrigName);
287 }
288 blob_resize(pOut, file_simplify_name(blob_buffer(pOut), blob_size(pOut)));
@@ -343,11 +343,11 @@
343 int i, j;
344 Blob tmp;
345 char zPwd[2000];
346 if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){
347 fprintf(stderr, "pwd too big: max %d\n", (int)sizeof(zPwd)-20);
348 fossil_exit(1);
349 }
350 for(i=1; zPath[i] && zPwd[i]==zPath[i]; i++){}
351 if( zPath[i]==0 ){
352 blob_reset(pOut);
353 if( zPwd[i]==0 ){
354
+19 -8
--- src/main.c
+++ src/main.c
@@ -55,10 +55,11 @@
5555
int useAttach; /* True if global_config is attached to repository */
5656
int configOpen; /* True if the config database is open */
5757
long long int now; /* Seconds since 1970 */
5858
int repositoryOpen; /* True if the main repository database is open */
5959
char *zRepositoryName; /* Name of the repository database */
60
+ char *zRepoDb; /* SQLite database name for the repository */
6061
const char *zHome; /* Name of user home directory */
6162
int localOpen; /* True if the local database is open */
6263
char *zLocalRoot; /* The directory holding the local database */
6364
int minPrefix; /* Number of digits needed for a distinct UUID */
6465
int fSqlTrace; /* True if -sqltrace flag is present */
@@ -216,11 +217,11 @@
216217
217218
/*
218219
** This procedure runs first.
219220
*/
220221
int main(int argc, char **argv){
221
- const char *zCmdName;
222
+ const char *zCmdName = "unknown";
222223
int idx;
223224
int rc;
224225
225226
sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
226227
g.now = time(0);
@@ -228,11 +229,11 @@
228229
g.argv = argv;
229230
if( getenv("GATEWAY_INTERFACE")!=0 ){
230231
zCmdName = "cgi";
231232
}else if( argc<2 ){
232233
fprintf(stderr, "Usage: %s COMMAND ...\n", argv[0]);
233
- exit(1);
234
+ fossil_exit(1);
234235
}else{
235236
g.fQuiet = find_option("quiet", 0, 0)!=0;
236237
g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
237238
g.fSqlPrint = find_option("sqlprint", 0, 0)!=0;
238239
g.fHttpTrace = find_option("httptrace", 0, 0)!=0;
@@ -242,27 +243,37 @@
242243
rc = name_search(zCmdName, aCommand, count(aCommand), &idx);
243244
if( rc==1 ){
244245
fprintf(stderr,"%s: unknown command: %s\n"
245246
"%s: use \"help\" for more information\n",
246247
argv[0], zCmdName, argv[0]);
247
- return 1;
248
+ fossil_exit(1);
248249
}else if( rc==2 ){
249250
fprintf(stderr,"%s: ambiguous command prefix: %s\n"
250251
"%s: use \"help\" for more information\n",
251252
argv[0], zCmdName, argv[0]);
252
- return 1;
253
+ fossil_exit(1);
253254
}
254255
aCommand[idx].xFunc();
256
+ fossil_exit(0);
257
+ /*NOT_REACHED*/
255258
return 0;
256259
}
257260
258261
/*
259262
** The following variable becomes true while processing a fatal error
260263
** or a panic. If additional "recursive-fatal" errors occur while
261264
** shutting down, the recursive errors are silently ignored.
262265
*/
263266
static int mainInFatalError = 0;
267
+
268
+/*
269
+** Exit. Take care to close the database first.
270
+*/
271
+void fossil_exit(int rc){
272
+ db_close();
273
+ exit(rc);
274
+}
264275
265276
/*
266277
** Print an error message, rollback all databases, and quit. These
267278
** routines never return.
268279
*/
@@ -280,11 +291,11 @@
280291
cgi_reply();
281292
}else{
282293
fprintf(stderr, "%s: %s\n", g.argv[0], z);
283294
}
284295
db_force_rollback();
285
- exit(1);
296
+ fossil_exit(1);
286297
}
287298
void fossil_fatal(const char *zFormat, ...){
288299
char *z;
289300
va_list ap;
290301
mainInFatalError = 1;
@@ -297,11 +308,11 @@
297308
cgi_reply();
298309
}else{
299310
fprintf(stderr, "%s: %s\n", g.argv[0], z);
300311
}
301312
db_force_rollback();
302
- exit(1);
313
+ fossil_exit(1);
303314
}
304315
305316
/* This routine works like fossil_fatal() except that if called
306317
** recursively, the recursive call is a no-op.
307318
**
@@ -325,11 +336,11 @@
325336
cgi_reply();
326337
}else{
327338
fprintf(stderr, "%s: %s\n", g.argv[0], z);
328339
}
329340
db_force_rollback();
330
- exit(1);
341
+ fossil_exit(1);
331342
}
332343
333344
334345
/* Print a warning message */
335346
void fossil_warning(const char *zFormat, ...){
@@ -388,11 +399,11 @@
388399
/*
389400
** Print a usage comment and quit
390401
*/
391402
void usage(const char *zFormat){
392403
fprintf(stderr, "Usage: %s %s %s\n", g.argv[0], g.argv[1], zFormat);
393
- exit(1);
404
+ fossil_exit(1);
394405
}
395406
396407
/*
397408
** Remove n elements from g.argv beginning with the i-th element.
398409
*/
399410
--- src/main.c
+++ src/main.c
@@ -55,10 +55,11 @@
55 int useAttach; /* True if global_config is attached to repository */
56 int configOpen; /* True if the config database is open */
57 long long int now; /* Seconds since 1970 */
58 int repositoryOpen; /* True if the main repository database is open */
59 char *zRepositoryName; /* Name of the repository database */
 
60 const char *zHome; /* Name of user home directory */
61 int localOpen; /* True if the local database is open */
62 char *zLocalRoot; /* The directory holding the local database */
63 int minPrefix; /* Number of digits needed for a distinct UUID */
64 int fSqlTrace; /* True if -sqltrace flag is present */
@@ -216,11 +217,11 @@
216
217 /*
218 ** This procedure runs first.
219 */
220 int main(int argc, char **argv){
221 const char *zCmdName;
222 int idx;
223 int rc;
224
225 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
226 g.now = time(0);
@@ -228,11 +229,11 @@
228 g.argv = argv;
229 if( getenv("GATEWAY_INTERFACE")!=0 ){
230 zCmdName = "cgi";
231 }else if( argc<2 ){
232 fprintf(stderr, "Usage: %s COMMAND ...\n", argv[0]);
233 exit(1);
234 }else{
235 g.fQuiet = find_option("quiet", 0, 0)!=0;
236 g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
237 g.fSqlPrint = find_option("sqlprint", 0, 0)!=0;
238 g.fHttpTrace = find_option("httptrace", 0, 0)!=0;
@@ -242,27 +243,37 @@
242 rc = name_search(zCmdName, aCommand, count(aCommand), &idx);
243 if( rc==1 ){
244 fprintf(stderr,"%s: unknown command: %s\n"
245 "%s: use \"help\" for more information\n",
246 argv[0], zCmdName, argv[0]);
247 return 1;
248 }else if( rc==2 ){
249 fprintf(stderr,"%s: ambiguous command prefix: %s\n"
250 "%s: use \"help\" for more information\n",
251 argv[0], zCmdName, argv[0]);
252 return 1;
253 }
254 aCommand[idx].xFunc();
 
 
255 return 0;
256 }
257
258 /*
259 ** The following variable becomes true while processing a fatal error
260 ** or a panic. If additional "recursive-fatal" errors occur while
261 ** shutting down, the recursive errors are silently ignored.
262 */
263 static int mainInFatalError = 0;
 
 
 
 
 
 
 
 
264
265 /*
266 ** Print an error message, rollback all databases, and quit. These
267 ** routines never return.
268 */
@@ -280,11 +291,11 @@
280 cgi_reply();
281 }else{
282 fprintf(stderr, "%s: %s\n", g.argv[0], z);
283 }
284 db_force_rollback();
285 exit(1);
286 }
287 void fossil_fatal(const char *zFormat, ...){
288 char *z;
289 va_list ap;
290 mainInFatalError = 1;
@@ -297,11 +308,11 @@
297 cgi_reply();
298 }else{
299 fprintf(stderr, "%s: %s\n", g.argv[0], z);
300 }
301 db_force_rollback();
302 exit(1);
303 }
304
305 /* This routine works like fossil_fatal() except that if called
306 ** recursively, the recursive call is a no-op.
307 **
@@ -325,11 +336,11 @@
325 cgi_reply();
326 }else{
327 fprintf(stderr, "%s: %s\n", g.argv[0], z);
328 }
329 db_force_rollback();
330 exit(1);
331 }
332
333
334 /* Print a warning message */
335 void fossil_warning(const char *zFormat, ...){
@@ -388,11 +399,11 @@
388 /*
389 ** Print a usage comment and quit
390 */
391 void usage(const char *zFormat){
392 fprintf(stderr, "Usage: %s %s %s\n", g.argv[0], g.argv[1], zFormat);
393 exit(1);
394 }
395
396 /*
397 ** Remove n elements from g.argv beginning with the i-th element.
398 */
399
--- src/main.c
+++ src/main.c
@@ -55,10 +55,11 @@
55 int useAttach; /* True if global_config is attached to repository */
56 int configOpen; /* True if the config database is open */
57 long long int now; /* Seconds since 1970 */
58 int repositoryOpen; /* True if the main repository database is open */
59 char *zRepositoryName; /* Name of the repository database */
60 char *zRepoDb; /* SQLite database name for the repository */
61 const char *zHome; /* Name of user home directory */
62 int localOpen; /* True if the local database is open */
63 char *zLocalRoot; /* The directory holding the local database */
64 int minPrefix; /* Number of digits needed for a distinct UUID */
65 int fSqlTrace; /* True if -sqltrace flag is present */
@@ -216,11 +217,11 @@
217
218 /*
219 ** This procedure runs first.
220 */
221 int main(int argc, char **argv){
222 const char *zCmdName = "unknown";
223 int idx;
224 int rc;
225
226 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
227 g.now = time(0);
@@ -228,11 +229,11 @@
229 g.argv = argv;
230 if( getenv("GATEWAY_INTERFACE")!=0 ){
231 zCmdName = "cgi";
232 }else if( argc<2 ){
233 fprintf(stderr, "Usage: %s COMMAND ...\n", argv[0]);
234 fossil_exit(1);
235 }else{
236 g.fQuiet = find_option("quiet", 0, 0)!=0;
237 g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
238 g.fSqlPrint = find_option("sqlprint", 0, 0)!=0;
239 g.fHttpTrace = find_option("httptrace", 0, 0)!=0;
@@ -242,27 +243,37 @@
243 rc = name_search(zCmdName, aCommand, count(aCommand), &idx);
244 if( rc==1 ){
245 fprintf(stderr,"%s: unknown command: %s\n"
246 "%s: use \"help\" for more information\n",
247 argv[0], zCmdName, argv[0]);
248 fossil_exit(1);
249 }else if( rc==2 ){
250 fprintf(stderr,"%s: ambiguous command prefix: %s\n"
251 "%s: use \"help\" for more information\n",
252 argv[0], zCmdName, argv[0]);
253 fossil_exit(1);
254 }
255 aCommand[idx].xFunc();
256 fossil_exit(0);
257 /*NOT_REACHED*/
258 return 0;
259 }
260
261 /*
262 ** The following variable becomes true while processing a fatal error
263 ** or a panic. If additional "recursive-fatal" errors occur while
264 ** shutting down, the recursive errors are silently ignored.
265 */
266 static int mainInFatalError = 0;
267
268 /*
269 ** Exit. Take care to close the database first.
270 */
271 void fossil_exit(int rc){
272 db_close();
273 exit(rc);
274 }
275
276 /*
277 ** Print an error message, rollback all databases, and quit. These
278 ** routines never return.
279 */
@@ -280,11 +291,11 @@
291 cgi_reply();
292 }else{
293 fprintf(stderr, "%s: %s\n", g.argv[0], z);
294 }
295 db_force_rollback();
296 fossil_exit(1);
297 }
298 void fossil_fatal(const char *zFormat, ...){
299 char *z;
300 va_list ap;
301 mainInFatalError = 1;
@@ -297,11 +308,11 @@
308 cgi_reply();
309 }else{
310 fprintf(stderr, "%s: %s\n", g.argv[0], z);
311 }
312 db_force_rollback();
313 fossil_exit(1);
314 }
315
316 /* This routine works like fossil_fatal() except that if called
317 ** recursively, the recursive call is a no-op.
318 **
@@ -325,11 +336,11 @@
336 cgi_reply();
337 }else{
338 fprintf(stderr, "%s: %s\n", g.argv[0], z);
339 }
340 db_force_rollback();
341 fossil_exit(1);
342 }
343
344
345 /* Print a warning message */
346 void fossil_warning(const char *zFormat, ...){
@@ -388,11 +399,11 @@
399 /*
400 ** Print a usage comment and quit
401 */
402 void usage(const char *zFormat){
403 fprintf(stderr, "Usage: %s %s %s\n", g.argv[0], g.argv[1], zFormat);
404 fossil_exit(1);
405 }
406
407 /*
408 ** Remove n elements from g.argv beginning with the i-th element.
409 */
410
+5 -5
--- src/merge3.c
+++ src/merge3.c
@@ -303,28 +303,28 @@
303303
*/
304304
void delta_3waymerge_cmd(void){
305305
Blob pivot, v1, v2, merged;
306306
if( g.argc!=6 ){
307307
fprintf(stderr,"Usage: %s %s PIVOT V1 V2 MERGED\n", g.argv[0], g.argv[1]);
308
- exit(1);
308
+ fossil_exit(1);
309309
}
310310
if( blob_read_from_file(&pivot, g.argv[2])<0 ){
311311
fprintf(stderr,"cannot read %s\n", g.argv[2]);
312
- exit(1);
312
+ fossil_exit(1);
313313
}
314314
if( blob_read_from_file(&v1, g.argv[3])<0 ){
315315
fprintf(stderr,"cannot read %s\n", g.argv[3]);
316
- exit(1);
316
+ fossil_exit(1);
317317
}
318318
if( blob_read_from_file(&v2, g.argv[4])<0 ){
319319
fprintf(stderr,"cannot read %s\n", g.argv[4]);
320
- exit(1);
320
+ fossil_exit(1);
321321
}
322322
blob_merge(&pivot, &v1, &v2, &merged);
323323
if( blob_write_to_file(&merged, g.argv[5])<blob_size(&merged) ){
324324
fprintf(stderr,"cannot write %s\n", g.argv[4]);
325
- exit(1);
325
+ fossil_exit(1);
326326
}
327327
blob_reset(&pivot);
328328
blob_reset(&v1);
329329
blob_reset(&v2);
330330
blob_reset(&merged);
331331
--- src/merge3.c
+++ src/merge3.c
@@ -303,28 +303,28 @@
303 */
304 void delta_3waymerge_cmd(void){
305 Blob pivot, v1, v2, merged;
306 if( g.argc!=6 ){
307 fprintf(stderr,"Usage: %s %s PIVOT V1 V2 MERGED\n", g.argv[0], g.argv[1]);
308 exit(1);
309 }
310 if( blob_read_from_file(&pivot, g.argv[2])<0 ){
311 fprintf(stderr,"cannot read %s\n", g.argv[2]);
312 exit(1);
313 }
314 if( blob_read_from_file(&v1, g.argv[3])<0 ){
315 fprintf(stderr,"cannot read %s\n", g.argv[3]);
316 exit(1);
317 }
318 if( blob_read_from_file(&v2, g.argv[4])<0 ){
319 fprintf(stderr,"cannot read %s\n", g.argv[4]);
320 exit(1);
321 }
322 blob_merge(&pivot, &v1, &v2, &merged);
323 if( blob_write_to_file(&merged, g.argv[5])<blob_size(&merged) ){
324 fprintf(stderr,"cannot write %s\n", g.argv[4]);
325 exit(1);
326 }
327 blob_reset(&pivot);
328 blob_reset(&v1);
329 blob_reset(&v2);
330 blob_reset(&merged);
331
--- src/merge3.c
+++ src/merge3.c
@@ -303,28 +303,28 @@
303 */
304 void delta_3waymerge_cmd(void){
305 Blob pivot, v1, v2, merged;
306 if( g.argc!=6 ){
307 fprintf(stderr,"Usage: %s %s PIVOT V1 V2 MERGED\n", g.argv[0], g.argv[1]);
308 fossil_exit(1);
309 }
310 if( blob_read_from_file(&pivot, g.argv[2])<0 ){
311 fprintf(stderr,"cannot read %s\n", g.argv[2]);
312 fossil_exit(1);
313 }
314 if( blob_read_from_file(&v1, g.argv[3])<0 ){
315 fprintf(stderr,"cannot read %s\n", g.argv[3]);
316 fossil_exit(1);
317 }
318 if( blob_read_from_file(&v2, g.argv[4])<0 ){
319 fprintf(stderr,"cannot read %s\n", g.argv[4]);
320 fossil_exit(1);
321 }
322 blob_merge(&pivot, &v1, &v2, &merged);
323 if( blob_write_to_file(&merged, g.argv[5])<blob_size(&merged) ){
324 fprintf(stderr,"cannot write %s\n", g.argv[4]);
325 fossil_exit(1);
326 }
327 blob_reset(&pivot);
328 blob_reset(&v1);
329 blob_reset(&v2);
330 blob_reset(&merged);
331
-1
--- src/name.c
+++ src/name.c
@@ -365,6 +365,5 @@
365365
rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name);
366366
blob_reset(&name);
367367
}
368368
return rid;
369369
}
370
-
371370
--- src/name.c
+++ src/name.c
@@ -365,6 +365,5 @@
365 rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name);
366 blob_reset(&name);
367 }
368 return rid;
369 }
370
371
--- src/name.c
+++ src/name.c
@@ -365,6 +365,5 @@
365 rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name);
366 blob_reset(&name);
367 }
368 return rid;
369 }
 
370
+1 -1
--- src/rebuild.c
+++ src/rebuild.c
@@ -374,11 +374,11 @@
374374
blob_zero(&ans);
375375
prompt_user("Scrubbing the repository will permanently remove user\n"
376376
"passwords and other information. Changes cannot be undone.\n"
377377
"Continue (y/N)? ", &ans);
378378
if( blob_str(&ans)[0]!='y' ){
379
- exit(1);
379
+ fossil_exit(1);
380380
}
381381
}
382382
db_begin_transaction();
383383
db_multi_exec(
384384
"UPDATE user SET pw='';"
385385
--- src/rebuild.c
+++ src/rebuild.c
@@ -374,11 +374,11 @@
374 blob_zero(&ans);
375 prompt_user("Scrubbing the repository will permanently remove user\n"
376 "passwords and other information. Changes cannot be undone.\n"
377 "Continue (y/N)? ", &ans);
378 if( blob_str(&ans)[0]!='y' ){
379 exit(1);
380 }
381 }
382 db_begin_transaction();
383 db_multi_exec(
384 "UPDATE user SET pw='';"
385
--- src/rebuild.c
+++ src/rebuild.c
@@ -374,11 +374,11 @@
374 blob_zero(&ans);
375 prompt_user("Scrubbing the repository will permanently remove user\n"
376 "passwords and other information. Changes cannot be undone.\n"
377 "Continue (y/N)? ", &ans);
378 if( blob_str(&ans)[0]!='y' ){
379 fossil_exit(1);
380 }
381 }
382 db_begin_transaction();
383 db_multi_exec(
384 "UPDATE user SET pw='';"
385
+239 -182
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -509,10 +509,17 @@
509509
#else
510510
# define ALWAYS(X) (X)
511511
# define NEVER(X) (X)
512512
#endif
513513
514
+/*
515
+** Return true (non-zero) if the input is a integer that is too large
516
+** to fit in 32-bits. This macro is used inside of various testcase()
517
+** macros to verify that we have tested SQLite for large-file support.
518
+*/
519
+#define IS_BIG_INT(X) (((X)&(i64)0xffffffff)!=0)
520
+
514521
/*
515522
** The macro unlikely() is a hint that surrounds a boolean
516523
** expression that is usually false. Macro likely() surrounds
517524
** a boolean expression that is usually true. GCC is able to
518525
** use these hints to generate better code, sometimes.
@@ -636,11 +643,11 @@
636643
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
637644
** [sqlite_version()] and [sqlite_source_id()].
638645
*/
639646
#define SQLITE_VERSION "3.7.0"
640647
#define SQLITE_VERSION_NUMBER 3007000
641
-#define SQLITE_SOURCE_ID "2010-07-03 13:59:01 3b20ad03be55613d922d81aec5313327bf4098b9"
648
+#define SQLITE_SOURCE_ID "2010-07-08 17:40:38 e396184cd3bdb96e29ac33af5d1f631cac553341"
642649
643650
/*
644651
** CAPI3REF: Run-Time Library Version Numbers
645652
** KEYWORDS: sqlite3_version, sqlite3_sourceid
646653
**
@@ -1359,20 +1366,27 @@
13591366
** is also passed as a parameter to both methods. If the output buffer
13601367
** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
13611368
** handled as a fatal error by SQLite, vfs implementations should endeavor
13621369
** to prevent this by setting mxPathname to a sufficiently large value.
13631370
**
1364
-** The xRandomness(), xSleep(), and xCurrentTime() interfaces
1365
-** are not strictly a part of the filesystem, but they are
1371
+** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
1372
+** interfaces are not strictly a part of the filesystem, but they are
13661373
** included in the VFS structure for completeness.
13671374
** The xRandomness() function attempts to return nBytes bytes
13681375
** of good-quality randomness into zOut. The return value is
13691376
** the actual number of bytes of randomness obtained.
13701377
** The xSleep() method causes the calling thread to sleep for at
13711378
** least the number of microseconds given. The xCurrentTime()
1372
-** method returns a Julian Day Number for the current date and time.
1373
-**
1379
+** method returns a Julian Day Number for the current date and time as
1380
+** a floating point value.
1381
+** The xCurrentTimeInt64() method returns, as an integer, the Julian
1382
+** Day Number multipled by 86400000 (the number of milliseconds in
1383
+** a 24-hour day).
1384
+** ^SQLite will use the xCurrentTimeInt64() method to get the current
1385
+** date and time if that method is available (if iVersion is 2 or
1386
+** greater and the function pointer is not NULL) and will fall back
1387
+** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
13741388
*/
13751389
typedef struct sqlite3_vfs sqlite3_vfs;
13761390
struct sqlite3_vfs {
13771391
int iVersion; /* Structure version number (currently 2) */
13781392
int szOsFile; /* Size of subclassed sqlite3_file */
@@ -1395,11 +1409,10 @@
13951409
int (*xGetLastError)(sqlite3_vfs*, int, char *);
13961410
/*
13971411
** The methods above are in version 1 of the sqlite_vfs object
13981412
** definition. Those that follow are added in version 2 or later
13991413
*/
1400
- int (*xRename)(sqlite3_vfs*, const char *zOld, const char *zNew, int dirSync);
14011414
int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
14021415
/*
14031416
** The methods above are in versions 1 and 2 of the sqlite_vfs object.
14041417
** New fields may be appended in figure versions. The iVersion
14051418
** value will increment whenever this happens.
@@ -8559,11 +8572,10 @@
85598572
int errMask; /* & result codes with this before returning */
85608573
u8 autoCommit; /* The auto-commit flag. */
85618574
u8 temp_store; /* 1: file 2: memory 0: default */
85628575
u8 mallocFailed; /* True if we have seen a malloc failure */
85638576
u8 dfltLockMode; /* Default locking-mode for attached dbs */
8564
- u8 dfltJournalMode; /* Default journal mode for attached dbs */
85658577
signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
85668578
u8 suppressErr; /* Do not issue error messages if true */
85678579
int nextPagesize; /* Pagesize after VACUUM if >0 */
85688580
int nTable; /* Number of tables in the database */
85698581
CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
@@ -11327,13 +11339,15 @@
1132711339
"OMIT_CAST",
1132811340
#endif
1132911341
#ifdef SQLITE_OMIT_CHECK
1133011342
"OMIT_CHECK",
1133111343
#endif
11332
-#ifdef SQLITE_OMIT_COMPILEOPTION_DIAGS
11333
- "OMIT_COMPILEOPTION_DIAGS",
11334
-#endif
11344
+/* // redundant
11345
+** #ifdef SQLITE_OMIT_COMPILEOPTION_DIAGS
11346
+** "OMIT_COMPILEOPTION_DIAGS",
11347
+** #endif
11348
+*/
1133511349
#ifdef SQLITE_OMIT_COMPLETE
1133611350
"OMIT_COMPLETE",
1133711351
#endif
1133811352
#ifdef SQLITE_OMIT_COMPOUND_SELECT
1133911353
"OMIT_COMPOUND_SELECT",
@@ -11363,13 +11377,10 @@
1136311377
"OMIT_FOREIGN_KEY",
1136411378
#endif
1136511379
#ifdef SQLITE_OMIT_GET_TABLE
1136611380
"OMIT_GET_TABLE",
1136711381
#endif
11368
-#ifdef SQLITE_OMIT_GLOBALRECOVER
11369
- "OMIT_GLOBALRECOVER",
11370
-#endif
1137111382
#ifdef SQLITE_OMIT_INCRBLOB
1137211383
"OMIT_INCRBLOB",
1137311384
#endif
1137411385
#ifdef SQLITE_OMIT_INTEGRITY_CHECK
1137511386
"OMIT_INTEGRITY_CHECK",
@@ -11443,10 +11454,13 @@
1144311454
#ifdef SQLITE_OMIT_VIEW
1144411455
"OMIT_VIEW",
1144511456
#endif
1144611457
#ifdef SQLITE_OMIT_VIRTUALTABLE
1144711458
"OMIT_VIRTUALTABLE",
11459
+#endif
11460
+#ifdef SQLITE_OMIT_WAL
11461
+ "OMIT_WAL",
1144811462
#endif
1144911463
#ifdef SQLITE_OMIT_WSD
1145011464
"OMIT_WSD",
1145111465
#endif
1145211466
#ifdef SQLITE_OMIT_XFER_OPT
@@ -28503,11 +28517,10 @@
2850328517
unixDlClose, /* xDlClose */ \
2850428518
unixRandomness, /* xRandomness */ \
2850528519
unixSleep, /* xSleep */ \
2850628520
unixCurrentTime, /* xCurrentTime */ \
2850728521
unixGetLastError, /* xGetLastError */ \
28508
- 0, /* xRename */ \
2850928522
unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
2851028523
}
2851128524
2851228525
/*
2851328526
** All default VFSes for unix are contained in the following array.
@@ -29406,10 +29419,11 @@
2940629419
assert( id!=0 );
2940729420
assert( pFile->pShm==0 );
2940829421
OSTRACE(("CLOSE %d\n", pFile->h));
2940929422
do{
2941029423
rc = CloseHandle(pFile->h);
29424
+ /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
2941129425
}while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (Sleep(100), 1) );
2941229426
#if SQLITE_OS_WINCE
2941329427
#define WINCE_DELETION_ATTEMPTS 3
2941429428
winceDestroyLock(pFile);
2941529429
if( pFile->zDeleteOnClose ){
@@ -29497,11 +29511,15 @@
2949729511
SimulateDiskfullError(return SQLITE_FULL);
2949829512
OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype));
2949929513
rc = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
2950029514
if( rc==INVALID_SET_FILE_POINTER && (error=GetLastError())!=NO_ERROR ){
2950129515
pFile->lastErrno = error;
29502
- return SQLITE_FULL;
29516
+ if( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ){
29517
+ return SQLITE_FULL;
29518
+ }else{
29519
+ return SQLITE_IOERR_WRITE;
29520
+ }
2950329521
}
2950429522
assert( amt>0 );
2950529523
while(
2950629524
amt>0
2950729525
&& (rc = WriteFile(pFile->h, pBuf, amt, &wrote, 0))!=0
@@ -29510,11 +29528,15 @@
2951029528
amt -= wrote;
2951129529
pBuf = &((char*)pBuf)[wrote];
2951229530
}
2951329531
if( !rc || amt>(int)wrote ){
2951429532
pFile->lastErrno = GetLastError();
29515
- return SQLITE_FULL;
29533
+ if( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ){
29534
+ return SQLITE_FULL;
29535
+ }else{
29536
+ return SQLITE_IOERR_WRITE;
29537
+ }
2951629538
}
2951729539
return SQLITE_OK;
2951829540
}
2951929541
2952029542
/*
@@ -29555,31 +29577,44 @@
2955529577
2955629578
/*
2955729579
** Make sure all writes to a particular file are committed to disk.
2955829580
*/
2955929581
static int winSync(sqlite3_file *id, int flags){
29560
-#ifndef SQLITE_NO_SYNC
29582
+#if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || defined(SQLITE_DEBUG)
2956129583
winFile *pFile = (winFile*)id;
29562
-
29563
- assert( id!=0 );
29564
- OSTRACE(("SYNC %d lock=%d\n", pFile->h, pFile->locktype));
2956529584
#else
2956629585
UNUSED_PARAMETER(id);
2956729586
#endif
29587
+
29588
+ assert( pFile );
29589
+ /* Check that one of SQLITE_SYNC_NORMAL or FULL was passed */
29590
+ assert((flags&0x0F)==SQLITE_SYNC_NORMAL
29591
+ || (flags&0x0F)==SQLITE_SYNC_FULL
29592
+ );
29593
+
29594
+ OSTRACE(("SYNC %d lock=%d\n", pFile->h, pFile->locktype));
29595
+
2956829596
#ifndef SQLITE_TEST
2956929597
UNUSED_PARAMETER(flags);
2957029598
#else
2957129599
if( flags & SQLITE_SYNC_FULL ){
2957229600
sqlite3_fullsync_count++;
2957329601
}
2957429602
sqlite3_sync_count++;
2957529603
#endif
29604
+
29605
+ /* Unix cannot, but some systems may return SQLITE_FULL from here. This
29606
+ ** line is to test that doing so does not cause any problems.
29607
+ */
29608
+ SimulateDiskfullError( return SQLITE_FULL );
29609
+ SimulateIOError( return SQLITE_IOERR; );
29610
+
2957629611
/* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
2957729612
** no-op
2957829613
*/
2957929614
#ifdef SQLITE_NO_SYNC
29580
- return SQLITE_OK;
29615
+ return SQLITE_OK;
2958129616
#else
2958229617
if( FlushFileBuffers(pFile->h) ){
2958329618
return SQLITE_OK;
2958429619
}else{
2958529620
pFile->lastErrno = GetLastError();
@@ -29818,10 +29853,12 @@
2981829853
*/
2981929854
static int winCheckReservedLock(sqlite3_file *id, int *pResOut){
2982029855
int rc;
2982129856
winFile *pFile = (winFile*)id;
2982229857
29858
+ SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
29859
+
2982329860
assert( id!=0 );
2982429861
if( pFile->locktype>=RESERVED_LOCK ){
2982529862
rc = 1;
2982629863
OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc));
2982729864
}else{
@@ -29890,11 +29927,13 @@
2989029927
*(int*)pArg = (int)((winFile*)id)->lastErrno;
2989129928
return SQLITE_OK;
2989229929
}
2989329930
case SQLITE_FCNTL_SIZE_HINT: {
2989429931
sqlite3_int64 sz = *(sqlite3_int64*)pArg;
29932
+ SimulateIOErrorBenign(1);
2989529933
winTruncate(id, sz);
29934
+ SimulateIOErrorBenign(0);
2989629935
return SQLITE_OK;
2989729936
}
2989829937
}
2989929938
return SQLITE_ERROR;
2990029939
}
@@ -30101,14 +30140,20 @@
3010130140
if( p->mutex ) sqlite3_mutex_free(p->mutex);
3010230141
for(i=0; i<p->nRegion; i++){
3010330142
UnmapViewOfFile(p->aRegion[i].pMap);
3010430143
CloseHandle(p->aRegion[i].hMap);
3010530144
}
30106
- if( p->hFile.h != INVALID_HANDLE_VALUE ) {
30145
+ if( p->hFile.h != INVALID_HANDLE_VALUE ){
30146
+ SimulateIOErrorBenign(1);
3010730147
winClose((sqlite3_file *)&p->hFile);
30148
+ SimulateIOErrorBenign(0);
3010830149
}
30109
- if( deleteFlag ) winDelete(pVfs, p->zFilename, 0);
30150
+ if( deleteFlag ){
30151
+ SimulateIOErrorBenign(1);
30152
+ winDelete(pVfs, p->zFilename, 0);
30153
+ SimulateIOErrorBenign(0);
30154
+ }
3011030155
*pp = p->pNext;
3011130156
sqlite3_free(p->aRegion);
3011230157
sqlite3_free(p);
3011330158
}else{
3011430159
pp = &p->pNext;
@@ -30506,10 +30551,17 @@
3050630551
"abcdefghijklmnopqrstuvwxyz"
3050730552
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3050830553
"0123456789";
3050930554
size_t i, j;
3051030555
char zTempPath[MAX_PATH+1];
30556
+
30557
+ /* It's odd to simulate an io-error here, but really this is just
30558
+ ** using the io-error infrastructure to test that SQLite handles this
30559
+ ** function failing.
30560
+ */
30561
+ SimulateIOError( return SQLITE_IOERR );
30562
+
3051130563
if( sqlite3_temp_directory ){
3051230564
sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
3051330565
}else if( isNT() ){
3051430566
char *zMulti;
3051530567
WCHAR zWidePath[MAX_PATH];
@@ -30537,20 +30589,30 @@
3053730589
}else{
3053830590
return SQLITE_NOMEM;
3053930591
}
3054030592
#endif
3054130593
}
30594
+
30595
+ /* Check that the output buffer is large enough for the temporary file
30596
+ ** name. If it is not, return SQLITE_ERROR.
30597
+ */
30598
+ if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 17) >= nBuf ){
30599
+ return SQLITE_ERROR;
30600
+ }
30601
+
3054230602
for(i=sqlite3Strlen30(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
3054330603
zTempPath[i] = 0;
30544
- sqlite3_snprintf(nBuf-30, zBuf,
30604
+
30605
+ sqlite3_snprintf(nBuf-17, zBuf,
3054530606
"%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath);
3054630607
j = sqlite3Strlen30(zBuf);
30547
- sqlite3_randomness(20, &zBuf[j]);
30548
- for(i=0; i<20; i++, j++){
30608
+ sqlite3_randomness(15, &zBuf[j]);
30609
+ for(i=0; i<15; i++, j++){
3054930610
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
3055030611
}
3055130612
zBuf[j] = 0;
30613
+
3055230614
OSTRACE(("TEMP FILENAME: %s\n", zBuf));
3055330615
return SQLITE_OK;
3055430616
}
3055530617
3055630618
/*
@@ -30790,17 +30852,19 @@
3079030852
int syncDir /* Not used on win32 */
3079130853
){
3079230854
int cnt = 0;
3079330855
DWORD rc;
3079430856
DWORD error = 0;
30795
- void *zConverted = convertUtf8Filename(zFilename);
30857
+ void *zConverted;
3079630858
UNUSED_PARAMETER(pVfs);
3079730859
UNUSED_PARAMETER(syncDir);
30860
+
30861
+ SimulateIOError(return SQLITE_IOERR_DELETE);
30862
+ zConverted = convertUtf8Filename(zFilename);
3079830863
if( zConverted==0 ){
3079930864
return SQLITE_NOMEM;
3080030865
}
30801
- SimulateIOError(return SQLITE_IOERR_DELETE);
3080230866
if( isNT() ){
3080330867
do{
3080430868
DeleteFileW(zConverted);
3080530869
}while( ( ((rc = GetFileAttributesW(zConverted)) != INVALID_FILE_ATTRIBUTES)
3080630870
|| ((error = GetLastError()) == ERROR_ACCESS_DENIED))
@@ -30838,17 +30902,42 @@
3083830902
int flags, /* Type of test to make on this file */
3083930903
int *pResOut /* OUT: Result */
3084030904
){
3084130905
DWORD attr;
3084230906
int rc = 0;
30843
- void *zConverted = convertUtf8Filename(zFilename);
30907
+ void *zConverted;
3084430908
UNUSED_PARAMETER(pVfs);
30909
+
30910
+ SimulateIOError( return SQLITE_IOERR_ACCESS; );
30911
+ zConverted = convertUtf8Filename(zFilename);
3084530912
if( zConverted==0 ){
3084630913
return SQLITE_NOMEM;
3084730914
}
3084830915
if( isNT() ){
30849
- attr = GetFileAttributesW((WCHAR*)zConverted);
30916
+ WIN32_FILE_ATTRIBUTE_DATA sAttrData;
30917
+ memset(&sAttrData, 0, sizeof(sAttrData));
30918
+ if( GetFileAttributesExW((WCHAR*)zConverted,
30919
+ GetFileExInfoStandard,
30920
+ &sAttrData) ){
30921
+ /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
30922
+ ** as if it does not exist.
30923
+ */
30924
+ if( flags==SQLITE_ACCESS_EXISTS
30925
+ && sAttrData.nFileSizeHigh==0
30926
+ && sAttrData.nFileSizeLow==0 ){
30927
+ attr = INVALID_FILE_ATTRIBUTES;
30928
+ }else{
30929
+ attr = sAttrData.dwFileAttributes;
30930
+ }
30931
+ }else{
30932
+ if( GetLastError()!=ERROR_FILE_NOT_FOUND ){
30933
+ free(zConverted);
30934
+ return SQLITE_IOERR_ACCESS;
30935
+ }else{
30936
+ attr = INVALID_FILE_ATTRIBUTES;
30937
+ }
30938
+ }
3085030939
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
3085130940
** Since the ASCII version of these Windows API do not exist for WINCE,
3085230941
** it's important to not reference them for WINCE builds.
3085330942
*/
3085430943
#if SQLITE_OS_WINCE==0
@@ -30884,16 +30973,18 @@
3088430973
int nFull, /* Size of output buffer in bytes */
3088530974
char *zFull /* Output buffer */
3088630975
){
3088730976
3088830977
#if defined(__CYGWIN__)
30978
+ SimulateIOError( return SQLITE_ERROR );
3088930979
UNUSED_PARAMETER(nFull);
3089030980
cygwin_conv_to_full_win32_path(zRelative, zFull);
3089130981
return SQLITE_OK;
3089230982
#endif
3089330983
3089430984
#if SQLITE_OS_WINCE
30985
+ SimulateIOError( return SQLITE_ERROR );
3089530986
UNUSED_PARAMETER(nFull);
3089630987
/* WinCE has no concept of a relative pathname, or so I am told. */
3089730988
sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zRelative);
3089830989
return SQLITE_OK;
3089930990
#endif
@@ -30900,10 +30991,17 @@
3090030991
3090130992
#if !SQLITE_OS_WINCE && !defined(__CYGWIN__)
3090230993
int nByte;
3090330994
void *zConverted;
3090430995
char *zOut;
30996
+
30997
+ /* It's odd to simulate an io-error here, but really this is just
30998
+ ** using the io-error infrastructure to test that SQLite handles this
30999
+ ** function failing. This function could fail if, for example, the
31000
+ ** current working directory has been unlinked.
31001
+ */
31002
+ SimulateIOError( return SQLITE_ERROR );
3090531003
UNUSED_PARAMETER(nFull);
3090631004
zConverted = convertUtf8Filename(zRelative);
3090731005
if( isNT() ){
3090831006
WCHAR *zTemp;
3090931007
nByte = GetFullPathNameW((WCHAR*)zConverted, 0, 0, 0) + 3;
@@ -30967,11 +31065,13 @@
3096731065
/*
3096831066
** We need to get the full path name of the file
3096931067
** to get the drive letter to look up the sector
3097031068
** size.
3097131069
*/
31070
+ SimulateIOErrorBenign(1);
3097231071
rc = winFullPathname(pVfs, zRelative, MAX_PATH, zFullpath);
31072
+ SimulateIOErrorBenign(0);
3097331073
if( rc == SQLITE_OK )
3097431074
{
3097531075
void *zConverted = convertUtf8Filename(zFullpath);
3097631076
if( zConverted ){
3097731077
if( isNT() ){
@@ -31244,11 +31344,10 @@
3124431344
winDlClose, /* xDlClose */
3124531345
winRandomness, /* xRandomness */
3124631346
winSleep, /* xSleep */
3124731347
winCurrentTime, /* xCurrentTime */
3124831348
winGetLastError, /* xGetLastError */
31249
- 0, /* xRename */
3125031349
winCurrentTimeInt64, /* xCurrentTimeInt64 */
3125131350
};
3125231351
3125331352
sqlite3_vfs_register(&winVfs, 1);
3125431353
return SQLITE_OK;
@@ -33981,10 +34080,11 @@
3398134080
char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
3398234081
PCache *pPCache; /* Pointer to page cache object */
3398334082
sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
3398434083
#ifndef SQLITE_OMIT_WAL
3398534084
Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */
34085
+ char *zWal; /* File name for write-ahead log */
3398634086
#endif
3398734087
};
3398834088
3398934089
/*
3399034090
** The following global variables hold counters used for
@@ -35091,10 +35191,25 @@
3509135191
i -= 200;
3509235192
}
3509335193
return cksum;
3509435194
}
3509535195
35196
+/*
35197
+** Report the current page size and number of reserved bytes back
35198
+** to the codec.
35199
+*/
35200
+#ifdef SQLITE_HAS_CODEC
35201
+static void pagerReportSize(Pager *pPager){
35202
+ if( pPager->xCodecSizeChng ){
35203
+ pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize,
35204
+ (int)pPager->nReserve);
35205
+ }
35206
+}
35207
+#else
35208
+# define pagerReportSize(X) /* No-op if we do not support a codec */
35209
+#endif
35210
+
3509635211
/*
3509735212
** Read a single page from either the journal file (if isMainJrnl==1) or
3509835213
** from the sub-journal (if isMainJrnl==0) and playback that page.
3509935214
** The page begins at offset *pOffset into the file. The *pOffset
3510035215
** value is increased to the start of the next page in the journal.
@@ -35183,15 +35298,24 @@
3518335298
if( !isSavepnt && pager_cksum(pPager, (u8*)aData)!=cksum ){
3518435299
return SQLITE_DONE;
3518535300
}
3518635301
}
3518735302
35303
+ /* If this page has already been played by before during the current
35304
+ ** rollback, then don't bother to play it back again.
35305
+ */
3518835306
if( pDone && (rc = sqlite3BitvecSet(pDone, pgno))!=SQLITE_OK ){
3518935307
return rc;
3519035308
}
35191
-
3519235309
assert( pPager->state==PAGER_RESERVED || pPager->state>=PAGER_EXCLUSIVE );
35310
+
35311
+ /* When playing back page 1, restore the nReserve setting
35312
+ */
35313
+ if( pgno==1 && pPager->nReserve!=((u8*)aData)[20] ){
35314
+ pPager->nReserve = ((u8*)aData)[20];
35315
+ pagerReportSize(pPager);
35316
+ }
3519335317
3519435318
/* If the pager is in RESERVED state, then there must be a copy of this
3519535319
** page in the pager cache. In this case just update the pager cache,
3519635320
** not the database file. The page is left marked dirty in this case.
3519735321
**
@@ -35987,42 +36111,10 @@
3598736111
pPager->state = PAGER_SHARED;
3598836112
3598936113
return rc;
3599036114
}
3599136115
35992
-/*
35993
-** Check for the existence of or delete the *-wal file that corresponds to
35994
-** the database opened by pPager.
35995
-**
35996
-** When pExists!=NULL, set *pExists to 1 if the *-wal file exists, or 0
35997
-** if the *-wal file does not exist.
35998
-**
35999
-** When pExists==NULL, delete the *-wal file if it exists, or the do
36000
-** nothing if the *-wal file does not exist.
36001
-**
36002
-** Return SQLITE_OK on success. If on an IO or OOM error occurs, return
36003
-** an SQLite error code.
36004
-*/
36005
-static int pagerCheckForOrDeleteWAL(Pager *pPager, int *pExists){
36006
- int rc; /* Return code */
36007
- char *zWal; /* Name of the WAL file */
36008
-
36009
- assert( !pPager->tempFile );
36010
- zWal = sqlite3_mprintf("%s-wal", pPager->zFilename);
36011
- if( !zWal ){
36012
- rc = SQLITE_NOMEM;
36013
- }else{
36014
- if( pExists ){
36015
- rc = sqlite3OsAccess(pPager->pVfs, zWal, SQLITE_ACCESS_EXISTS, pExists);
36016
- }else{
36017
- rc = sqlite3OsDelete(pPager->pVfs, zWal, 0);
36018
- }
36019
- sqlite3_free(zWal);
36020
- }
36021
- return rc;
36022
-}
36023
-
3602436116
/*
3602536117
** Check if the *-wal file that corresponds to the database opened by pPager
3602636118
** exists if the database is not empy, or verify that the *-wal file does
3602736119
** not exist (by deleting it) if the database file is empty.
3602836120
**
@@ -36048,14 +36140,16 @@
3604836140
int nPage; /* Size of the database file */
3604936141
assert( pPager->state>=SHARED_LOCK );
3605036142
rc = sqlite3PagerPagecount(pPager, &nPage);
3605136143
if( rc ) return rc;
3605236144
if( nPage==0 ){
36053
- rc = pagerCheckForOrDeleteWAL(pPager, 0);
36145
+ rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0);
3605436146
isWal = 0;
3605536147
}else{
36056
- rc = pagerCheckForOrDeleteWAL(pPager, &isWal);
36148
+ rc = sqlite3OsAccess(
36149
+ pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &isWal
36150
+ );
3605736151
}
3605836152
if( rc==SQLITE_OK ){
3605936153
if( isWal ){
3606036154
pager_reset(pPager);
3606136155
rc = sqlite3PagerOpenWal(pPager, 0);
@@ -36125,10 +36219,11 @@
3612536219
3612636220
/* Set the database size back to the value it was before the savepoint
3612736221
** being reverted was opened.
3612836222
*/
3612936223
pPager->dbSize = pSavepoint ? pSavepoint->nOrig : pPager->dbOrigSize;
36224
+ pPager->changeCountDone = pPager->tempFile;
3613036225
3613136226
if( !pSavepoint && pagerUseWal(pPager) ){
3613236227
return pagerRollbackWal(pPager);
3613336228
}
3613436229
@@ -36325,25 +36420,10 @@
3632536420
){
3632636421
pPager->xBusyHandler = xBusyHandler;
3632736422
pPager->pBusyHandlerArg = pBusyHandlerArg;
3632836423
}
3632936424
36330
-/*
36331
-** Report the current page size and number of reserved bytes back
36332
-** to the codec.
36333
-*/
36334
-#ifdef SQLITE_HAS_CODEC
36335
-static void pagerReportSize(Pager *pPager){
36336
- if( pPager->xCodecSizeChng ){
36337
- pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize,
36338
- (int)pPager->nReserve);
36339
- }
36340
-}
36341
-#else
36342
-# define pagerReportSize(X) /* No-op if we do not support a codec */
36343
-#endif
36344
-
3634536425
/*
3634636426
** Change the page size used by the Pager object. The new page size
3634736427
** is passed in *pPageSize.
3634836428
**
3634936429
** If the pager is in the error state when this function is called, it
@@ -36479,19 +36559,10 @@
3647936559
/* This routine is only called by btree immediately after creating
3648036560
** the Pager object. There has not been an opportunity to transition
3648136561
** to WAL mode yet.
3648236562
*/
3648336563
assert( !pagerUseWal(pPager) );
36484
-#if 0
36485
- if( pagerUseWal(pPager) ){
36486
- int isInWal = 0;
36487
- rc = sqlite3WalRead(pPager->pWal, 1, &isInWal, N, pDest);
36488
- if( rc!=SQLITE_OK || isInWal ){
36489
- return rc;
36490
- }
36491
- }
36492
-#endif
3649336564
3649436565
if( isOpen(pPager->fd) ){
3649536566
IOTRACE(("DBHDR %p 0 %d\n", pPager, N))
3649636567
rc = sqlite3OsRead(pPager->fd, pDest, N, 0);
3649736568
if( rc==SQLITE_IOERR_SHORT_READ ){
@@ -36931,17 +37002,13 @@
3693137002
**
3693237003
** If everything is successful, SQLITE_OK is returned. If an IO error
3693337004
** occurs, an IO error code is returned. Or, if the EXCLUSIVE lock cannot
3693437005
** be obtained, SQLITE_BUSY is returned.
3693537006
*/
36936
-static int pager_write_pagelist(PgHdr *pList){
36937
- Pager *pPager; /* Pager object */
37007
+static int pager_write_pagelist(Pager *pPager, PgHdr *pList){
3693837008
int rc; /* Return code */
3693937009
36940
- if( NEVER(pList==0) ) return SQLITE_OK;
36941
- pPager = pList->pPager;
36942
-
3694337010
/* At this point there may be either a RESERVED or EXCLUSIVE lock on the
3694437011
** database file. If there is already an EXCLUSIVE lock, the following
3694537012
** call is a no-op.
3694637013
**
3694737014
** Moving the lock from RESERVED to EXCLUSIVE actually involves going
@@ -36954,11 +37021,11 @@
3695437021
** is unchanged and we can rollback without having to playback the
3695537022
** journal into the original database file. Once we transition to
3695637023
** EXCLUSIVE, it means the database file has been changed and any rollback
3695737024
** will require a journal playback.
3695837025
*/
36959
- assert( !pagerUseWal(pList->pPager) );
37026
+ assert( !pagerUseWal(pPager) );
3696037027
assert( pPager->state>=PAGER_RESERVED );
3696137028
rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
3696237029
3696337030
/* If the file is a temp-file has not yet been opened, open it now. It
3696437031
** is not possible for rc to be other than SQLITE_OK if this branch
@@ -36970,11 +37037,12 @@
3697037037
}
3697137038
3697237039
/* Before the first write, give the VFS a hint of what the final
3697337040
** file size will be.
3697437041
*/
36975
- if( pPager->dbSize > (pPager->dbOrigSize+1) && isOpen(pPager->fd) ){
37042
+ assert( rc!=SQLITE_OK || isOpen(pPager->fd) );
37043
+ if( rc==SQLITE_OK && pPager->dbSize>(pPager->dbOrigSize+1) ){
3697637044
sqlite3_int64 szFile = pPager->pageSize * (sqlite3_int64)pPager->dbSize;
3697737045
sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &szFile);
3697837046
}
3697937047
3698037048
while( rc==SQLITE_OK && pList ){
@@ -37199,11 +37267,11 @@
3719937267
rc = subjournalPage(pPg);
3720037268
}
3720137269
3720237270
/* Write the contents of the page out to the database file. */
3720337271
if( rc==SQLITE_OK ){
37204
- rc = pager_write_pagelist(pPg);
37272
+ rc = pager_write_pagelist(pPager, pPg);
3720537273
}
3720637274
}
3720737275
3720837276
/* Mark the page as clean. */
3720937277
if( rc==SQLITE_OK ){
@@ -37339,10 +37407,13 @@
3733937407
ROUND8(pcacheSize) + /* PCache object */
3734037408
ROUND8(pVfs->szOsFile) + /* The main db file */
3734137409
journalFileSize * 2 + /* The two journal files */
3734237410
nPathname + 1 + /* zFilename */
3734337411
nPathname + 8 + 1 /* zJournal */
37412
+#ifndef SQLITE_OMIT_WAL
37413
+ + nPathname + 4 + 1 /* zWal */
37414
+#endif
3734437415
);
3734537416
assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
3734637417
if( !pPtr ){
3734737418
sqlite3_free(zPathname);
3734837419
return SQLITE_NOMEM;
@@ -37359,11 +37430,20 @@
3735937430
if( zPathname ){
3736037431
pPager->zJournal = (char*)(pPtr += nPathname + 1);
3736137432
memcpy(pPager->zFilename, zPathname, nPathname);
3736237433
memcpy(pPager->zJournal, zPathname, nPathname);
3736337434
memcpy(&pPager->zJournal[nPathname], "-journal", 8);
37364
- if( pPager->zFilename[0]==0 ) pPager->zJournal[0] = 0;
37435
+ if( pPager->zFilename[0]==0 ){
37436
+ pPager->zJournal[0] = 0;
37437
+ }
37438
+#ifndef SQLITE_OMIT_WAL
37439
+ else{
37440
+ pPager->zWal = &pPager->zJournal[nPathname+8+1];
37441
+ memcpy(pPager->zWal, zPathname, nPathname);
37442
+ memcpy(&pPager->zWal[nPathname], "-wal", 4);
37443
+ }
37444
+#endif
3736537445
sqlite3_free(zPathname);
3736637446
}
3736737447
pPager->pVfs = pVfs;
3736837448
pPager->vfsFlags = vfsFlags;
3736937449
@@ -38816,11 +38896,11 @@
3881638896
*/
3881738897
rc = syncJournal(pPager);
3881838898
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
3881938899
3882038900
/* Write all dirty pages to the database file. */
38821
- rc = pager_write_pagelist(sqlite3PcacheDirtyList(pPager->pPCache));
38901
+ rc = pager_write_pagelist(pPager,sqlite3PcacheDirtyList(pPager->pPCache));
3882238902
if( rc!=SQLITE_OK ){
3882338903
assert( rc!=SQLITE_IOERR_BLOCKED );
3882438904
goto commit_phase_one_exit;
3882538905
}
3882638906
sqlite3PcacheCleanAll(pPager->pPCache);
@@ -39651,12 +39731,11 @@
3965139731
3965239732
/* Open the connection to the log file. If this operation fails,
3965339733
** (e.g. due to malloc() failure), unlock the database file and
3965439734
** return an error code.
3965539735
*/
39656
- rc = sqlite3WalOpen(pPager->pVfs, pPager->fd,
39657
- pPager->zFilename, &pPager->pWal);
39736
+ rc = sqlite3WalOpen(pPager->pVfs, pPager->fd, pPager->zWal, &pPager->pWal);
3965839737
if( rc==SQLITE_OK ){
3965939738
pPager->journalMode = PAGER_JOURNALMODE_WAL;
3966039739
}
3966139740
}else{
3966239741
*pisOpen = 1;
@@ -39685,15 +39764,17 @@
3968539764
*/
3968639765
if( !pPager->pWal ){
3968739766
int logexists = 0;
3968839767
rc = sqlite3OsLock(pPager->fd, SQLITE_LOCK_SHARED);
3968939768
if( rc==SQLITE_OK ){
39690
- rc = pagerCheckForOrDeleteWAL(pPager, &logexists);
39769
+ rc = sqlite3OsAccess(
39770
+ pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &logexists
39771
+ );
3969139772
}
3969239773
if( rc==SQLITE_OK && logexists ){
3969339774
rc = sqlite3WalOpen(pPager->pVfs, pPager->fd,
39694
- pPager->zFilename, &pPager->pWal);
39775
+ pPager->zWal, &pPager->pWal);
3969539776
}
3969639777
}
3969739778
3969839779
/* Checkpoint and close the log. Because an EXCLUSIVE lock is held on
3969939780
** the database file, the log and log-summary files will be deleted.
@@ -40131,11 +40212,11 @@
4013140212
** Return the offset of frame iFrame in the write-ahead log file,
4013240213
** assuming a database page size of szPage bytes. The offset returned
4013340214
** is to the start of the write-ahead log frame-header.
4013440215
*/
4013540216
#define walFrameOffset(iFrame, szPage) ( \
40136
- WAL_HDRSIZE + ((iFrame)-1)*((szPage)+WAL_FRAME_HDRSIZE) \
40217
+ WAL_HDRSIZE + ((iFrame)-1)*(i64)((szPage)+WAL_FRAME_HDRSIZE) \
4013740218
)
4013840219
4013940220
/*
4014040221
** An open write-ahead log file is represented by an instance of the
4014140222
** following object.
@@ -40152,11 +40233,11 @@
4015240233
u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
4015340234
u8 isWIndexOpen; /* True if ShmOpen() called on pDbFd */
4015440235
u8 writeLock; /* True if in a write transaction */
4015540236
u8 ckptLock; /* True if holding a checkpoint lock */
4015640237
WalIndexHdr hdr; /* Wal-index header for current transaction */
40157
- char *zWalName; /* Name of WAL file */
40238
+ const char *zWalName; /* Name of WAL file */
4015840239
u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
4015940240
#ifdef SQLITE_DEBUG
4016040241
u8 lockError; /* True if a locking error has occurred */
4016140242
#endif
4016240243
};
@@ -40907,12 +40988,13 @@
4090740988
pWal->isWIndexOpen = 0;
4090840989
}
4090940990
}
4091040991
4091140992
/*
40912
-** Open a connection to the WAL file associated with database zDbName.
40913
-** The database file must already be opened on connection pDbFd.
40993
+** Open a connection to the WAL file zWalName. The database file must
40994
+** already be opened on connection pDbFd. The buffer that zWalName points
40995
+** to must remain valid for the lifetime of the returned Wal* handle.
4091440996
**
4091540997
** A SHARED lock should be held on the database file when this function
4091640998
** is called. The purpose of this SHARED lock is to prevent any other
4091740999
** client from unlinking the WAL or wal-index file. If another process
4091841000
** were to do this just after this client opened one of these files, the
@@ -40923,20 +41005,18 @@
4092341005
** an SQLite error code is returned and *ppWal is left unmodified.
4092441006
*/
4092541007
SQLITE_PRIVATE int sqlite3WalOpen(
4092641008
sqlite3_vfs *pVfs, /* vfs module to open wal and wal-index */
4092741009
sqlite3_file *pDbFd, /* The open database file */
40928
- const char *zDbName, /* Name of the database file */
41010
+ const char *zWalName, /* Name of the WAL file */
4092941011
Wal **ppWal /* OUT: Allocated Wal handle */
4093041012
){
4093141013
int rc; /* Return Code */
4093241014
Wal *pRet; /* Object to allocate and return */
4093341015
int flags; /* Flags passed to OsOpen() */
40934
- char *zWal; /* Name of write-ahead log file */
40935
- int nWal; /* Length of zWal in bytes */
4093641016
40937
- assert( zDbName && zDbName[0] );
41017
+ assert( zWalName && zWalName[0] );
4093841018
assert( pDbFd );
4093941019
4094041020
/* In the amalgamation, the os_unix.c and os_win.c source files come before
4094141021
** this source file. Verify that the #defines of the locking byte offsets
4094241022
** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
@@ -40949,30 +41029,27 @@
4094941029
#endif
4095041030
4095141031
4095241032
/* Allocate an instance of struct Wal to return. */
4095341033
*ppWal = 0;
40954
- nWal = sqlite3Strlen30(zDbName) + 5;
40955
- pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile + nWal);
41034
+ pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile);
4095641035
if( !pRet ){
4095741036
return SQLITE_NOMEM;
4095841037
}
4095941038
4096041039
pRet->pVfs = pVfs;
4096141040
pRet->pWalFd = (sqlite3_file *)&pRet[1];
4096241041
pRet->pDbFd = pDbFd;
4096341042
pRet->readLock = -1;
40964
- sqlite3_randomness(8, &pRet->hdr.aSalt);
40965
- pRet->zWalName = zWal = pVfs->szOsFile + (char*)pRet->pWalFd;
40966
- sqlite3_snprintf(nWal, zWal, "%s-wal", zDbName);
41043
+ pRet->zWalName = zWalName;
4096741044
rc = sqlite3OsShmOpen(pDbFd);
4096841045
4096941046
/* Open file handle on the write-ahead log file. */
4097041047
if( rc==SQLITE_OK ){
4097141048
pRet->isWIndexOpen = 1;
4097241049
flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_JOURNAL);
40973
- rc = sqlite3OsOpen(pVfs, zWal, pRet->pWalFd, flags, &flags);
41050
+ rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
4097441051
}
4097541052
4097641053
if( rc!=SQLITE_OK ){
4097741054
walIndexClose(pRet, 0);
4097841055
sqlite3OsClose(pRet->pWalFd);
@@ -41310,24 +41387,29 @@
4131041387
rc = sqlite3OsSync(pWal->pWalFd, sync_flags);
4131141388
}
4131241389
4131341390
/* Iterate through the contents of the WAL, copying data to the db file. */
4131441391
while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
41392
+ i64 iOffset;
4131541393
assert( walFramePgno(pWal, iFrame)==iDbpage );
4131641394
if( iFrame<=nBackfill || iFrame>mxSafeFrame ) continue;
41317
- rc = sqlite3OsRead(pWal->pWalFd, zBuf, szPage,
41318
- walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE
41319
- );
41395
+ iOffset = walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE;
41396
+ /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */
41397
+ rc = sqlite3OsRead(pWal->pWalFd, zBuf, szPage, iOffset);
4132041398
if( rc!=SQLITE_OK ) break;
41321
- rc = sqlite3OsWrite(pWal->pDbFd, zBuf, szPage, (iDbpage-1)*szPage);
41399
+ iOffset = (iDbpage-1)*(i64)szPage;
41400
+ testcase( IS_BIG_INT(iOffset) );
41401
+ rc = sqlite3OsWrite(pWal->pDbFd, zBuf, szPage, iOffset);
4132241402
if( rc!=SQLITE_OK ) break;
4132341403
}
4132441404
4132541405
/* If work was actually accomplished... */
4132641406
if( rc==SQLITE_OK ){
4132741407
if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){
41328
- rc = sqlite3OsTruncate(pWal->pDbFd, ((i64)pWal->hdr.nPage*(i64)szPage));
41408
+ i64 szDb = pWal->hdr.nPage*(i64)szPage;
41409
+ testcase( IS_BIG_INT(szDb) );
41410
+ rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
4132941411
if( rc==SQLITE_OK && sync_flags ){
4133041412
rc = sqlite3OsSync(pWal->pDbFd, sync_flags);
4133141413
}
4133241414
}
4133341415
if( rc==SQLITE_OK ){
@@ -41861,10 +41943,11 @@
4186141943
** required page. Read and return data from the log file.
4186241944
*/
4186341945
if( iRead ){
4186441946
i64 iOffset = walFrameOffset(iRead, pWal->hdr.szPage) + WAL_FRAME_HDRSIZE;
4186541947
*pInWal = 1;
41948
+ /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
4186641949
return sqlite3OsRead(pWal->pWalFd, pOut, nOut, iOffset);
4186741950
}
4186841951
4186941952
*pInWal = 0;
4187041953
return SQLITE_OK;
@@ -42127,10 +42210,11 @@
4212742210
4212842211
sqlite3Put4byte(&aWalHdr[0], (WAL_MAGIC | SQLITE_BIGENDIAN));
4212942212
sqlite3Put4byte(&aWalHdr[4], WAL_MAX_VERSION);
4213042213
sqlite3Put4byte(&aWalHdr[8], szPage);
4213142214
sqlite3Put4byte(&aWalHdr[12], pWal->nCkpt);
42215
+ sqlite3_randomness(8, pWal->hdr.aSalt);
4213242216
memcpy(&aWalHdr[16], pWal->hdr.aSalt, 8);
4213342217
walChecksumBytes(1, aWalHdr, WAL_HDRSIZE-2*4, 0, aCksum);
4213442218
sqlite3Put4byte(&aWalHdr[24], aCksum[0]);
4213542219
sqlite3Put4byte(&aWalHdr[28], aCksum[1]);
4213642220
@@ -42151,12 +42235,12 @@
4215142235
for(p=pList; p; p=p->pDirty){
4215242236
u32 nDbsize; /* Db-size field for frame header */
4215342237
i64 iOffset; /* Write offset in log file */
4215442238
void *pData;
4215542239
42156
-
4215742240
iOffset = walFrameOffset(++iFrame, szPage);
42241
+ /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
4215842242
4215942243
/* Populate and write the frame header */
4216042244
nDbsize = (isCommit && p->pDirty==0) ? nTruncate : 0;
4216142245
#if defined(SQLITE_HAS_CODEC)
4216242246
if( (pData = sqlite3PagerCodec(p))==0 ) return SQLITE_NOMEM;
@@ -42192,10 +42276,11 @@
4219242276
if( (pData = sqlite3PagerCodec(pLast))==0 ) return SQLITE_NOMEM;
4219342277
#else
4219442278
pData = pLast->pData;
4219542279
#endif
4219642280
walEncodeFrame(pWal, pLast->pgno, nTruncate, pData, aFrame);
42281
+ /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
4219742282
rc = sqlite3OsWrite(pWal->pWalFd, aFrame, sizeof(aFrame), iOffset);
4219842283
if( rc!=SQLITE_OK ){
4219942284
return rc;
4220042285
}
4220142286
iOffset += WAL_FRAME_HDRSIZE;
@@ -63501,15 +63586,10 @@
6350163586
** operation. No IO is required.
6350263587
**
6350363588
** If changing into or out of WAL mode the procedure is more complicated.
6350463589
**
6350563590
** Write a string containing the final journal-mode to register P2.
63506
-**
63507
-** If an attempt to change in to or out of WAL mode fails because another
63508
-** connection also has the same database open, then an SQLITE_BUSY error
63509
-** is raised if P5==0, or of P5!=0 the journal mode changed is skipped
63510
-** without signaling the error.
6351163591
*/
6351263592
case OP_JournalMode: { /* out2-prerelease */
6351363593
#if 0 /* local variables moved into u.cd */
6351463594
Btree *pBt; /* Btree to change journal mode of */
6351563595
Pager *pPager; /* Pager associated with pBt */
@@ -63605,11 +63685,10 @@
6360563685
}
6360663686
}
6360763687
#endif /* ifndef SQLITE_OMIT_WAL */
6360863688
6360963689
if( rc ){
63610
- if( rc==SQLITE_BUSY && pOp->p5!=0 ) rc = SQLITE_OK;
6361163690
u.cd.eNew = u.cd.eOld;
6361263691
}
6361363692
u.cd.eNew = sqlite3PagerSetJournalMode(u.cd.pPager, u.cd.eNew);
6361463693
6361563694
pOut = &aMem[pOp->p2];
@@ -63617,11 +63696,11 @@
6361763696
pOut->z = (char *)sqlite3JournalModename(u.cd.eNew);
6361863697
pOut->n = sqlite3Strlen30(pOut->z);
6361963698
pOut->enc = SQLITE_UTF8;
6362063699
sqlite3VdbeChangeEncoding(pOut, encoding);
6362163700
break;
63622
-};
63701
+};
6362363702
#endif /* SQLITE_OMIT_PRAGMA */
6362463703
6362563704
#if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
6362663705
/* Opcode: Vacuum * * * * *
6362763706
**
@@ -71830,12 +71909,10 @@
7183071909
"attached databases must use the same text encoding as main database");
7183171910
rc = SQLITE_ERROR;
7183271911
}
7183371912
pPager = sqlite3BtreePager(aNew->pBt);
7183471913
sqlite3PagerLockingMode(pPager, db->dfltLockMode);
71835
- /* journal_mode set by the OP_JournalMode opcode that will following
71836
- ** the OP_Function opcode that invoked this function. */
7183771914
sqlite3BtreeSecureDelete(aNew->pBt,
7183871915
sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
7183971916
}
7184071917
aNew->safety_level = 3;
7184171918
aNew->zName = sqlite3DbStrDup(db, zName);
@@ -72027,21 +72104,10 @@
7202772104
sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-pFunc->nArg, regArgs+3);
7202872105
assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg );
7202972106
sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg));
7203072107
sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF);
7203172108
72032
- if( type==SQLITE_ATTACH ){
72033
- /* On an attach, also set the journal mode. Note that
72034
- ** sqlite3VdbeUsesBtree() is not call here since the iDb index
72035
- ** will be out of range prior to the new database being attached.
72036
- ** The OP_JournalMode opcode will all sqlite3VdbeUsesBtree() for us.
72037
- */
72038
- sqlite3VdbeAddOp3(v, OP_JournalMode, db->nDb, regArgs+3,
72039
- db->dfltJournalMode);
72040
- sqlite3VdbeChangeP5(v, 1);
72041
- }
72042
-
7204372109
/* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
7204472110
** statement only). For DETACH, set it to false (expire all existing
7204572111
** statements).
7204672112
*/
7204772113
sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH));
@@ -75914,11 +75980,10 @@
7591475980
assert( db->aDb[1].pSchema );
7591575981
if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
7591675982
db->mallocFailed = 1;
7591775983
return 1;
7591875984
}
75919
- sqlite3PagerSetJournalMode(sqlite3BtreePager(pBt), db->dfltJournalMode);
7592075985
}
7592175986
return 0;
7592275987
}
7592375988
7592475989
/*
@@ -83583,58 +83648,49 @@
8358383648
** PRAGMA [database.]journal_mode
8358483649
** PRAGMA [database.]journal_mode =
8358583650
** (delete|persist|off|truncate|memory|wal|off)
8358683651
*/
8358783652
if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){
83588
- int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
83653
+ int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
83654
+ int ii; /* Loop counter */
83655
+
83656
+ /* Force the schema to be loaded on all databases. This cases all
83657
+ ** database files to be opened and the journal_modes set. */
83658
+ if( sqlite3ReadSchema(pParse) ){
83659
+ goto pragma_out;
83660
+ }
8358983661
8359083662
sqlite3VdbeSetNumCols(v, 1);
8359183663
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);
8359283664
8359383665
if( zRight==0 ){
83666
+ /* If there is no "=MODE" part of the pragma, do a query for the
83667
+ ** current mode */
8359483668
eMode = PAGER_JOURNALMODE_QUERY;
8359583669
}else{
8359683670
const char *zMode;
8359783671
int n = sqlite3Strlen30(zRight);
83598
- for(eMode=0; (zMode = sqlite3JournalModename(eMode)); eMode++){
83672
+ for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){
8359983673
if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break;
8360083674
}
8360183675
if( !zMode ){
83676
+ /* If the "=MODE" part does not match any known journal mode,
83677
+ ** then do a query */
8360283678
eMode = PAGER_JOURNALMODE_QUERY;
8360383679
}
8360483680
}
83605
- if( pId2->n==0 && eMode==PAGER_JOURNALMODE_QUERY ){
83606
- /* Simple "PRAGMA journal_mode;" statement. This is a query for
83607
- ** the current default journal mode (which may be different to
83608
- ** the journal-mode of the main database).
83609
- */
83610
- eMode = db->dfltJournalMode;
83611
- sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
83612
- sqlite3VdbeChangeP4(v, -1, sqlite3JournalModename(eMode), P4_STATIC);
83613
- }else{
83614
- int ii;
83615
-
83616
- if( pId2->n==0 ){
83617
- /* When there is no database name before the "journal_mode" keyword
83618
- ** in the PRAGMA, then the journal-mode will be set on
83619
- ** all attached databases, as well as the main db file.
83620
- **
83621
- ** Also, the sqlite3.dfltJournalMode variable is set so that
83622
- ** any subsequently attached databases also use the specified
83623
- ** journal mode.
83624
- */
83625
- db->dfltJournalMode = (u8)eMode;
83626
- }
83627
-
83628
- for(ii=db->nDb-1; ii>=0; ii--){
83629
- if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
83630
- sqlite3VdbeUsesBtree(v, ii);
83631
- sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode);
83632
- }
83633
- }
83634
- }
83635
-
83681
+ if( eMode==PAGER_JOURNALMODE_QUERY && pId2->n==0 ){
83682
+ /* Convert "PRAGMA journal_mode" into "PRAGMA main.journal_mode" */
83683
+ iDb = 0;
83684
+ pId2->n = 1;
83685
+ }
83686
+ for(ii=db->nDb-1; ii>=0; ii--){
83687
+ if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
83688
+ sqlite3VdbeUsesBtree(v, ii);
83689
+ sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode);
83690
+ }
83691
+ }
8363683692
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
8363783693
}else
8363883694
8363983695
/*
8364083696
** PRAGMA [database.]journal_size_limit
@@ -84648,25 +84704,28 @@
8464884704
** or executed. All the parser does is build the internal data
8464984705
** structures that describe the table, index, or view.
8465084706
*/
8465184707
int rc;
8465284708
sqlite3_stmt *pStmt;
84709
+ TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
8465384710
8465484711
assert( db->init.busy );
8465584712
db->init.iDb = iDb;
8465684713
db->init.newTnum = atoi(argv[1]);
8465784714
db->init.orphanTrigger = 0;
84658
- rc = sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
84715
+ TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
84716
+ rc = db->errCode;
84717
+ assert( (rc&0xFF)==(rcp&0xFF) );
8465984718
db->init.iDb = 0;
8466084719
if( SQLITE_OK!=rc ){
8466184720
if( db->init.orphanTrigger ){
8466284721
assert( iDb==1 );
8466384722
}else{
8466484723
pData->rc = rc;
8466584724
if( rc==SQLITE_NOMEM ){
8466684725
db->mallocFailed = 1;
84667
- }else if( rc!=SQLITE_INTERRUPT && rc!=SQLITE_LOCKED ){
84726
+ }else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ){
8466884727
corruptSchema(pData, argv[0], sqlite3_errmsg(db));
8466984728
}
8467084729
}
8467184730
}
8467284731
sqlite3_finalize(pStmt);
@@ -104123,20 +104182,18 @@
104123104182
sqlite3_mutex_leave(db->mutex);
104124104183
return SQLITE_OK;
104125104184
}
104126104185
#endif /* SQLITE_OMIT_UTF16 */
104127104186
104128
-#ifndef SQLITE_OMIT_GLOBALRECOVER
104129104187
#ifndef SQLITE_OMIT_DEPRECATED
104130104188
/*
104131104189
** This function is now an anachronism. It used to be used to recover from a
104132104190
** malloc() failure, but SQLite now does this automatically.
104133104191
*/
104134104192
SQLITE_API int sqlite3_global_recover(void){
104135104193
return SQLITE_OK;
104136104194
}
104137
-#endif
104138104195
#endif
104139104196
104140104197
/*
104141104198
** Test to see whether or not the database connection is in autocommit
104142104199
** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
104143104200
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -509,10 +509,17 @@
509 #else
510 # define ALWAYS(X) (X)
511 # define NEVER(X) (X)
512 #endif
513
 
 
 
 
 
 
 
514 /*
515 ** The macro unlikely() is a hint that surrounds a boolean
516 ** expression that is usually false. Macro likely() surrounds
517 ** a boolean expression that is usually true. GCC is able to
518 ** use these hints to generate better code, sometimes.
@@ -636,11 +643,11 @@
636 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
637 ** [sqlite_version()] and [sqlite_source_id()].
638 */
639 #define SQLITE_VERSION "3.7.0"
640 #define SQLITE_VERSION_NUMBER 3007000
641 #define SQLITE_SOURCE_ID "2010-07-03 13:59:01 3b20ad03be55613d922d81aec5313327bf4098b9"
642
643 /*
644 ** CAPI3REF: Run-Time Library Version Numbers
645 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
646 **
@@ -1359,20 +1366,27 @@
1359 ** is also passed as a parameter to both methods. If the output buffer
1360 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
1361 ** handled as a fatal error by SQLite, vfs implementations should endeavor
1362 ** to prevent this by setting mxPathname to a sufficiently large value.
1363 **
1364 ** The xRandomness(), xSleep(), and xCurrentTime() interfaces
1365 ** are not strictly a part of the filesystem, but they are
1366 ** included in the VFS structure for completeness.
1367 ** The xRandomness() function attempts to return nBytes bytes
1368 ** of good-quality randomness into zOut. The return value is
1369 ** the actual number of bytes of randomness obtained.
1370 ** The xSleep() method causes the calling thread to sleep for at
1371 ** least the number of microseconds given. The xCurrentTime()
1372 ** method returns a Julian Day Number for the current date and time.
1373 **
 
 
 
 
 
 
 
1374 */
1375 typedef struct sqlite3_vfs sqlite3_vfs;
1376 struct sqlite3_vfs {
1377 int iVersion; /* Structure version number (currently 2) */
1378 int szOsFile; /* Size of subclassed sqlite3_file */
@@ -1395,11 +1409,10 @@
1395 int (*xGetLastError)(sqlite3_vfs*, int, char *);
1396 /*
1397 ** The methods above are in version 1 of the sqlite_vfs object
1398 ** definition. Those that follow are added in version 2 or later
1399 */
1400 int (*xRename)(sqlite3_vfs*, const char *zOld, const char *zNew, int dirSync);
1401 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
1402 /*
1403 ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1404 ** New fields may be appended in figure versions. The iVersion
1405 ** value will increment whenever this happens.
@@ -8559,11 +8572,10 @@
8559 int errMask; /* & result codes with this before returning */
8560 u8 autoCommit; /* The auto-commit flag. */
8561 u8 temp_store; /* 1: file 2: memory 0: default */
8562 u8 mallocFailed; /* True if we have seen a malloc failure */
8563 u8 dfltLockMode; /* Default locking-mode for attached dbs */
8564 u8 dfltJournalMode; /* Default journal mode for attached dbs */
8565 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
8566 u8 suppressErr; /* Do not issue error messages if true */
8567 int nextPagesize; /* Pagesize after VACUUM if >0 */
8568 int nTable; /* Number of tables in the database */
8569 CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
@@ -11327,13 +11339,15 @@
11327 "OMIT_CAST",
11328 #endif
11329 #ifdef SQLITE_OMIT_CHECK
11330 "OMIT_CHECK",
11331 #endif
11332 #ifdef SQLITE_OMIT_COMPILEOPTION_DIAGS
11333 "OMIT_COMPILEOPTION_DIAGS",
11334 #endif
 
 
11335 #ifdef SQLITE_OMIT_COMPLETE
11336 "OMIT_COMPLETE",
11337 #endif
11338 #ifdef SQLITE_OMIT_COMPOUND_SELECT
11339 "OMIT_COMPOUND_SELECT",
@@ -11363,13 +11377,10 @@
11363 "OMIT_FOREIGN_KEY",
11364 #endif
11365 #ifdef SQLITE_OMIT_GET_TABLE
11366 "OMIT_GET_TABLE",
11367 #endif
11368 #ifdef SQLITE_OMIT_GLOBALRECOVER
11369 "OMIT_GLOBALRECOVER",
11370 #endif
11371 #ifdef SQLITE_OMIT_INCRBLOB
11372 "OMIT_INCRBLOB",
11373 #endif
11374 #ifdef SQLITE_OMIT_INTEGRITY_CHECK
11375 "OMIT_INTEGRITY_CHECK",
@@ -11443,10 +11454,13 @@
11443 #ifdef SQLITE_OMIT_VIEW
11444 "OMIT_VIEW",
11445 #endif
11446 #ifdef SQLITE_OMIT_VIRTUALTABLE
11447 "OMIT_VIRTUALTABLE",
 
 
 
11448 #endif
11449 #ifdef SQLITE_OMIT_WSD
11450 "OMIT_WSD",
11451 #endif
11452 #ifdef SQLITE_OMIT_XFER_OPT
@@ -28503,11 +28517,10 @@
28503 unixDlClose, /* xDlClose */ \
28504 unixRandomness, /* xRandomness */ \
28505 unixSleep, /* xSleep */ \
28506 unixCurrentTime, /* xCurrentTime */ \
28507 unixGetLastError, /* xGetLastError */ \
28508 0, /* xRename */ \
28509 unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
28510 }
28511
28512 /*
28513 ** All default VFSes for unix are contained in the following array.
@@ -29406,10 +29419,11 @@
29406 assert( id!=0 );
29407 assert( pFile->pShm==0 );
29408 OSTRACE(("CLOSE %d\n", pFile->h));
29409 do{
29410 rc = CloseHandle(pFile->h);
 
29411 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (Sleep(100), 1) );
29412 #if SQLITE_OS_WINCE
29413 #define WINCE_DELETION_ATTEMPTS 3
29414 winceDestroyLock(pFile);
29415 if( pFile->zDeleteOnClose ){
@@ -29497,11 +29511,15 @@
29497 SimulateDiskfullError(return SQLITE_FULL);
29498 OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype));
29499 rc = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
29500 if( rc==INVALID_SET_FILE_POINTER && (error=GetLastError())!=NO_ERROR ){
29501 pFile->lastErrno = error;
29502 return SQLITE_FULL;
 
 
 
 
29503 }
29504 assert( amt>0 );
29505 while(
29506 amt>0
29507 && (rc = WriteFile(pFile->h, pBuf, amt, &wrote, 0))!=0
@@ -29510,11 +29528,15 @@
29510 amt -= wrote;
29511 pBuf = &((char*)pBuf)[wrote];
29512 }
29513 if( !rc || amt>(int)wrote ){
29514 pFile->lastErrno = GetLastError();
29515 return SQLITE_FULL;
 
 
 
 
29516 }
29517 return SQLITE_OK;
29518 }
29519
29520 /*
@@ -29555,31 +29577,44 @@
29555
29556 /*
29557 ** Make sure all writes to a particular file are committed to disk.
29558 */
29559 static int winSync(sqlite3_file *id, int flags){
29560 #ifndef SQLITE_NO_SYNC
29561 winFile *pFile = (winFile*)id;
29562
29563 assert( id!=0 );
29564 OSTRACE(("SYNC %d lock=%d\n", pFile->h, pFile->locktype));
29565 #else
29566 UNUSED_PARAMETER(id);
29567 #endif
 
 
 
 
 
 
 
 
 
29568 #ifndef SQLITE_TEST
29569 UNUSED_PARAMETER(flags);
29570 #else
29571 if( flags & SQLITE_SYNC_FULL ){
29572 sqlite3_fullsync_count++;
29573 }
29574 sqlite3_sync_count++;
29575 #endif
 
 
 
 
 
 
 
29576 /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
29577 ** no-op
29578 */
29579 #ifdef SQLITE_NO_SYNC
29580 return SQLITE_OK;
29581 #else
29582 if( FlushFileBuffers(pFile->h) ){
29583 return SQLITE_OK;
29584 }else{
29585 pFile->lastErrno = GetLastError();
@@ -29818,10 +29853,12 @@
29818 */
29819 static int winCheckReservedLock(sqlite3_file *id, int *pResOut){
29820 int rc;
29821 winFile *pFile = (winFile*)id;
29822
 
 
29823 assert( id!=0 );
29824 if( pFile->locktype>=RESERVED_LOCK ){
29825 rc = 1;
29826 OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc));
29827 }else{
@@ -29890,11 +29927,13 @@
29890 *(int*)pArg = (int)((winFile*)id)->lastErrno;
29891 return SQLITE_OK;
29892 }
29893 case SQLITE_FCNTL_SIZE_HINT: {
29894 sqlite3_int64 sz = *(sqlite3_int64*)pArg;
 
29895 winTruncate(id, sz);
 
29896 return SQLITE_OK;
29897 }
29898 }
29899 return SQLITE_ERROR;
29900 }
@@ -30101,14 +30140,20 @@
30101 if( p->mutex ) sqlite3_mutex_free(p->mutex);
30102 for(i=0; i<p->nRegion; i++){
30103 UnmapViewOfFile(p->aRegion[i].pMap);
30104 CloseHandle(p->aRegion[i].hMap);
30105 }
30106 if( p->hFile.h != INVALID_HANDLE_VALUE ) {
 
30107 winClose((sqlite3_file *)&p->hFile);
 
30108 }
30109 if( deleteFlag ) winDelete(pVfs, p->zFilename, 0);
 
 
 
 
30110 *pp = p->pNext;
30111 sqlite3_free(p->aRegion);
30112 sqlite3_free(p);
30113 }else{
30114 pp = &p->pNext;
@@ -30506,10 +30551,17 @@
30506 "abcdefghijklmnopqrstuvwxyz"
30507 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
30508 "0123456789";
30509 size_t i, j;
30510 char zTempPath[MAX_PATH+1];
 
 
 
 
 
 
 
30511 if( sqlite3_temp_directory ){
30512 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
30513 }else if( isNT() ){
30514 char *zMulti;
30515 WCHAR zWidePath[MAX_PATH];
@@ -30537,20 +30589,30 @@
30537 }else{
30538 return SQLITE_NOMEM;
30539 }
30540 #endif
30541 }
 
 
 
 
 
 
 
 
30542 for(i=sqlite3Strlen30(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
30543 zTempPath[i] = 0;
30544 sqlite3_snprintf(nBuf-30, zBuf,
 
30545 "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath);
30546 j = sqlite3Strlen30(zBuf);
30547 sqlite3_randomness(20, &zBuf[j]);
30548 for(i=0; i<20; i++, j++){
30549 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
30550 }
30551 zBuf[j] = 0;
 
30552 OSTRACE(("TEMP FILENAME: %s\n", zBuf));
30553 return SQLITE_OK;
30554 }
30555
30556 /*
@@ -30790,17 +30852,19 @@
30790 int syncDir /* Not used on win32 */
30791 ){
30792 int cnt = 0;
30793 DWORD rc;
30794 DWORD error = 0;
30795 void *zConverted = convertUtf8Filename(zFilename);
30796 UNUSED_PARAMETER(pVfs);
30797 UNUSED_PARAMETER(syncDir);
 
 
 
30798 if( zConverted==0 ){
30799 return SQLITE_NOMEM;
30800 }
30801 SimulateIOError(return SQLITE_IOERR_DELETE);
30802 if( isNT() ){
30803 do{
30804 DeleteFileW(zConverted);
30805 }while( ( ((rc = GetFileAttributesW(zConverted)) != INVALID_FILE_ATTRIBUTES)
30806 || ((error = GetLastError()) == ERROR_ACCESS_DENIED))
@@ -30838,17 +30902,42 @@
30838 int flags, /* Type of test to make on this file */
30839 int *pResOut /* OUT: Result */
30840 ){
30841 DWORD attr;
30842 int rc = 0;
30843 void *zConverted = convertUtf8Filename(zFilename);
30844 UNUSED_PARAMETER(pVfs);
 
 
 
30845 if( zConverted==0 ){
30846 return SQLITE_NOMEM;
30847 }
30848 if( isNT() ){
30849 attr = GetFileAttributesW((WCHAR*)zConverted);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30850 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
30851 ** Since the ASCII version of these Windows API do not exist for WINCE,
30852 ** it's important to not reference them for WINCE builds.
30853 */
30854 #if SQLITE_OS_WINCE==0
@@ -30884,16 +30973,18 @@
30884 int nFull, /* Size of output buffer in bytes */
30885 char *zFull /* Output buffer */
30886 ){
30887
30888 #if defined(__CYGWIN__)
 
30889 UNUSED_PARAMETER(nFull);
30890 cygwin_conv_to_full_win32_path(zRelative, zFull);
30891 return SQLITE_OK;
30892 #endif
30893
30894 #if SQLITE_OS_WINCE
 
30895 UNUSED_PARAMETER(nFull);
30896 /* WinCE has no concept of a relative pathname, or so I am told. */
30897 sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zRelative);
30898 return SQLITE_OK;
30899 #endif
@@ -30900,10 +30991,17 @@
30900
30901 #if !SQLITE_OS_WINCE && !defined(__CYGWIN__)
30902 int nByte;
30903 void *zConverted;
30904 char *zOut;
 
 
 
 
 
 
 
30905 UNUSED_PARAMETER(nFull);
30906 zConverted = convertUtf8Filename(zRelative);
30907 if( isNT() ){
30908 WCHAR *zTemp;
30909 nByte = GetFullPathNameW((WCHAR*)zConverted, 0, 0, 0) + 3;
@@ -30967,11 +31065,13 @@
30967 /*
30968 ** We need to get the full path name of the file
30969 ** to get the drive letter to look up the sector
30970 ** size.
30971 */
 
30972 rc = winFullPathname(pVfs, zRelative, MAX_PATH, zFullpath);
 
30973 if( rc == SQLITE_OK )
30974 {
30975 void *zConverted = convertUtf8Filename(zFullpath);
30976 if( zConverted ){
30977 if( isNT() ){
@@ -31244,11 +31344,10 @@
31244 winDlClose, /* xDlClose */
31245 winRandomness, /* xRandomness */
31246 winSleep, /* xSleep */
31247 winCurrentTime, /* xCurrentTime */
31248 winGetLastError, /* xGetLastError */
31249 0, /* xRename */
31250 winCurrentTimeInt64, /* xCurrentTimeInt64 */
31251 };
31252
31253 sqlite3_vfs_register(&winVfs, 1);
31254 return SQLITE_OK;
@@ -33981,10 +34080,11 @@
33981 char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
33982 PCache *pPCache; /* Pointer to page cache object */
33983 sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
33984 #ifndef SQLITE_OMIT_WAL
33985 Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */
 
33986 #endif
33987 };
33988
33989 /*
33990 ** The following global variables hold counters used for
@@ -35091,10 +35191,25 @@
35091 i -= 200;
35092 }
35093 return cksum;
35094 }
35095
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35096 /*
35097 ** Read a single page from either the journal file (if isMainJrnl==1) or
35098 ** from the sub-journal (if isMainJrnl==0) and playback that page.
35099 ** The page begins at offset *pOffset into the file. The *pOffset
35100 ** value is increased to the start of the next page in the journal.
@@ -35183,15 +35298,24 @@
35183 if( !isSavepnt && pager_cksum(pPager, (u8*)aData)!=cksum ){
35184 return SQLITE_DONE;
35185 }
35186 }
35187
 
 
 
35188 if( pDone && (rc = sqlite3BitvecSet(pDone, pgno))!=SQLITE_OK ){
35189 return rc;
35190 }
35191
35192 assert( pPager->state==PAGER_RESERVED || pPager->state>=PAGER_EXCLUSIVE );
 
 
 
 
 
 
 
35193
35194 /* If the pager is in RESERVED state, then there must be a copy of this
35195 ** page in the pager cache. In this case just update the pager cache,
35196 ** not the database file. The page is left marked dirty in this case.
35197 **
@@ -35987,42 +36111,10 @@
35987 pPager->state = PAGER_SHARED;
35988
35989 return rc;
35990 }
35991
35992 /*
35993 ** Check for the existence of or delete the *-wal file that corresponds to
35994 ** the database opened by pPager.
35995 **
35996 ** When pExists!=NULL, set *pExists to 1 if the *-wal file exists, or 0
35997 ** if the *-wal file does not exist.
35998 **
35999 ** When pExists==NULL, delete the *-wal file if it exists, or the do
36000 ** nothing if the *-wal file does not exist.
36001 **
36002 ** Return SQLITE_OK on success. If on an IO or OOM error occurs, return
36003 ** an SQLite error code.
36004 */
36005 static int pagerCheckForOrDeleteWAL(Pager *pPager, int *pExists){
36006 int rc; /* Return code */
36007 char *zWal; /* Name of the WAL file */
36008
36009 assert( !pPager->tempFile );
36010 zWal = sqlite3_mprintf("%s-wal", pPager->zFilename);
36011 if( !zWal ){
36012 rc = SQLITE_NOMEM;
36013 }else{
36014 if( pExists ){
36015 rc = sqlite3OsAccess(pPager->pVfs, zWal, SQLITE_ACCESS_EXISTS, pExists);
36016 }else{
36017 rc = sqlite3OsDelete(pPager->pVfs, zWal, 0);
36018 }
36019 sqlite3_free(zWal);
36020 }
36021 return rc;
36022 }
36023
36024 /*
36025 ** Check if the *-wal file that corresponds to the database opened by pPager
36026 ** exists if the database is not empy, or verify that the *-wal file does
36027 ** not exist (by deleting it) if the database file is empty.
36028 **
@@ -36048,14 +36140,16 @@
36048 int nPage; /* Size of the database file */
36049 assert( pPager->state>=SHARED_LOCK );
36050 rc = sqlite3PagerPagecount(pPager, &nPage);
36051 if( rc ) return rc;
36052 if( nPage==0 ){
36053 rc = pagerCheckForOrDeleteWAL(pPager, 0);
36054 isWal = 0;
36055 }else{
36056 rc = pagerCheckForOrDeleteWAL(pPager, &isWal);
 
 
36057 }
36058 if( rc==SQLITE_OK ){
36059 if( isWal ){
36060 pager_reset(pPager);
36061 rc = sqlite3PagerOpenWal(pPager, 0);
@@ -36125,10 +36219,11 @@
36125
36126 /* Set the database size back to the value it was before the savepoint
36127 ** being reverted was opened.
36128 */
36129 pPager->dbSize = pSavepoint ? pSavepoint->nOrig : pPager->dbOrigSize;
 
36130
36131 if( !pSavepoint && pagerUseWal(pPager) ){
36132 return pagerRollbackWal(pPager);
36133 }
36134
@@ -36325,25 +36420,10 @@
36325 ){
36326 pPager->xBusyHandler = xBusyHandler;
36327 pPager->pBusyHandlerArg = pBusyHandlerArg;
36328 }
36329
36330 /*
36331 ** Report the current page size and number of reserved bytes back
36332 ** to the codec.
36333 */
36334 #ifdef SQLITE_HAS_CODEC
36335 static void pagerReportSize(Pager *pPager){
36336 if( pPager->xCodecSizeChng ){
36337 pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize,
36338 (int)pPager->nReserve);
36339 }
36340 }
36341 #else
36342 # define pagerReportSize(X) /* No-op if we do not support a codec */
36343 #endif
36344
36345 /*
36346 ** Change the page size used by the Pager object. The new page size
36347 ** is passed in *pPageSize.
36348 **
36349 ** If the pager is in the error state when this function is called, it
@@ -36479,19 +36559,10 @@
36479 /* This routine is only called by btree immediately after creating
36480 ** the Pager object. There has not been an opportunity to transition
36481 ** to WAL mode yet.
36482 */
36483 assert( !pagerUseWal(pPager) );
36484 #if 0
36485 if( pagerUseWal(pPager) ){
36486 int isInWal = 0;
36487 rc = sqlite3WalRead(pPager->pWal, 1, &isInWal, N, pDest);
36488 if( rc!=SQLITE_OK || isInWal ){
36489 return rc;
36490 }
36491 }
36492 #endif
36493
36494 if( isOpen(pPager->fd) ){
36495 IOTRACE(("DBHDR %p 0 %d\n", pPager, N))
36496 rc = sqlite3OsRead(pPager->fd, pDest, N, 0);
36497 if( rc==SQLITE_IOERR_SHORT_READ ){
@@ -36931,17 +37002,13 @@
36931 **
36932 ** If everything is successful, SQLITE_OK is returned. If an IO error
36933 ** occurs, an IO error code is returned. Or, if the EXCLUSIVE lock cannot
36934 ** be obtained, SQLITE_BUSY is returned.
36935 */
36936 static int pager_write_pagelist(PgHdr *pList){
36937 Pager *pPager; /* Pager object */
36938 int rc; /* Return code */
36939
36940 if( NEVER(pList==0) ) return SQLITE_OK;
36941 pPager = pList->pPager;
36942
36943 /* At this point there may be either a RESERVED or EXCLUSIVE lock on the
36944 ** database file. If there is already an EXCLUSIVE lock, the following
36945 ** call is a no-op.
36946 **
36947 ** Moving the lock from RESERVED to EXCLUSIVE actually involves going
@@ -36954,11 +37021,11 @@
36954 ** is unchanged and we can rollback without having to playback the
36955 ** journal into the original database file. Once we transition to
36956 ** EXCLUSIVE, it means the database file has been changed and any rollback
36957 ** will require a journal playback.
36958 */
36959 assert( !pagerUseWal(pList->pPager) );
36960 assert( pPager->state>=PAGER_RESERVED );
36961 rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
36962
36963 /* If the file is a temp-file has not yet been opened, open it now. It
36964 ** is not possible for rc to be other than SQLITE_OK if this branch
@@ -36970,11 +37037,12 @@
36970 }
36971
36972 /* Before the first write, give the VFS a hint of what the final
36973 ** file size will be.
36974 */
36975 if( pPager->dbSize > (pPager->dbOrigSize+1) && isOpen(pPager->fd) ){
 
36976 sqlite3_int64 szFile = pPager->pageSize * (sqlite3_int64)pPager->dbSize;
36977 sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &szFile);
36978 }
36979
36980 while( rc==SQLITE_OK && pList ){
@@ -37199,11 +37267,11 @@
37199 rc = subjournalPage(pPg);
37200 }
37201
37202 /* Write the contents of the page out to the database file. */
37203 if( rc==SQLITE_OK ){
37204 rc = pager_write_pagelist(pPg);
37205 }
37206 }
37207
37208 /* Mark the page as clean. */
37209 if( rc==SQLITE_OK ){
@@ -37339,10 +37407,13 @@
37339 ROUND8(pcacheSize) + /* PCache object */
37340 ROUND8(pVfs->szOsFile) + /* The main db file */
37341 journalFileSize * 2 + /* The two journal files */
37342 nPathname + 1 + /* zFilename */
37343 nPathname + 8 + 1 /* zJournal */
 
 
 
37344 );
37345 assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
37346 if( !pPtr ){
37347 sqlite3_free(zPathname);
37348 return SQLITE_NOMEM;
@@ -37359,11 +37430,20 @@
37359 if( zPathname ){
37360 pPager->zJournal = (char*)(pPtr += nPathname + 1);
37361 memcpy(pPager->zFilename, zPathname, nPathname);
37362 memcpy(pPager->zJournal, zPathname, nPathname);
37363 memcpy(&pPager->zJournal[nPathname], "-journal", 8);
37364 if( pPager->zFilename[0]==0 ) pPager->zJournal[0] = 0;
 
 
 
 
 
 
 
 
 
37365 sqlite3_free(zPathname);
37366 }
37367 pPager->pVfs = pVfs;
37368 pPager->vfsFlags = vfsFlags;
37369
@@ -38816,11 +38896,11 @@
38816 */
38817 rc = syncJournal(pPager);
38818 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
38819
38820 /* Write all dirty pages to the database file. */
38821 rc = pager_write_pagelist(sqlite3PcacheDirtyList(pPager->pPCache));
38822 if( rc!=SQLITE_OK ){
38823 assert( rc!=SQLITE_IOERR_BLOCKED );
38824 goto commit_phase_one_exit;
38825 }
38826 sqlite3PcacheCleanAll(pPager->pPCache);
@@ -39651,12 +39731,11 @@
39651
39652 /* Open the connection to the log file. If this operation fails,
39653 ** (e.g. due to malloc() failure), unlock the database file and
39654 ** return an error code.
39655 */
39656 rc = sqlite3WalOpen(pPager->pVfs, pPager->fd,
39657 pPager->zFilename, &pPager->pWal);
39658 if( rc==SQLITE_OK ){
39659 pPager->journalMode = PAGER_JOURNALMODE_WAL;
39660 }
39661 }else{
39662 *pisOpen = 1;
@@ -39685,15 +39764,17 @@
39685 */
39686 if( !pPager->pWal ){
39687 int logexists = 0;
39688 rc = sqlite3OsLock(pPager->fd, SQLITE_LOCK_SHARED);
39689 if( rc==SQLITE_OK ){
39690 rc = pagerCheckForOrDeleteWAL(pPager, &logexists);
 
 
39691 }
39692 if( rc==SQLITE_OK && logexists ){
39693 rc = sqlite3WalOpen(pPager->pVfs, pPager->fd,
39694 pPager->zFilename, &pPager->pWal);
39695 }
39696 }
39697
39698 /* Checkpoint and close the log. Because an EXCLUSIVE lock is held on
39699 ** the database file, the log and log-summary files will be deleted.
@@ -40131,11 +40212,11 @@
40131 ** Return the offset of frame iFrame in the write-ahead log file,
40132 ** assuming a database page size of szPage bytes. The offset returned
40133 ** is to the start of the write-ahead log frame-header.
40134 */
40135 #define walFrameOffset(iFrame, szPage) ( \
40136 WAL_HDRSIZE + ((iFrame)-1)*((szPage)+WAL_FRAME_HDRSIZE) \
40137 )
40138
40139 /*
40140 ** An open write-ahead log file is represented by an instance of the
40141 ** following object.
@@ -40152,11 +40233,11 @@
40152 u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
40153 u8 isWIndexOpen; /* True if ShmOpen() called on pDbFd */
40154 u8 writeLock; /* True if in a write transaction */
40155 u8 ckptLock; /* True if holding a checkpoint lock */
40156 WalIndexHdr hdr; /* Wal-index header for current transaction */
40157 char *zWalName; /* Name of WAL file */
40158 u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
40159 #ifdef SQLITE_DEBUG
40160 u8 lockError; /* True if a locking error has occurred */
40161 #endif
40162 };
@@ -40907,12 +40988,13 @@
40907 pWal->isWIndexOpen = 0;
40908 }
40909 }
40910
40911 /*
40912 ** Open a connection to the WAL file associated with database zDbName.
40913 ** The database file must already be opened on connection pDbFd.
 
40914 **
40915 ** A SHARED lock should be held on the database file when this function
40916 ** is called. The purpose of this SHARED lock is to prevent any other
40917 ** client from unlinking the WAL or wal-index file. If another process
40918 ** were to do this just after this client opened one of these files, the
@@ -40923,20 +41005,18 @@
40923 ** an SQLite error code is returned and *ppWal is left unmodified.
40924 */
40925 SQLITE_PRIVATE int sqlite3WalOpen(
40926 sqlite3_vfs *pVfs, /* vfs module to open wal and wal-index */
40927 sqlite3_file *pDbFd, /* The open database file */
40928 const char *zDbName, /* Name of the database file */
40929 Wal **ppWal /* OUT: Allocated Wal handle */
40930 ){
40931 int rc; /* Return Code */
40932 Wal *pRet; /* Object to allocate and return */
40933 int flags; /* Flags passed to OsOpen() */
40934 char *zWal; /* Name of write-ahead log file */
40935 int nWal; /* Length of zWal in bytes */
40936
40937 assert( zDbName && zDbName[0] );
40938 assert( pDbFd );
40939
40940 /* In the amalgamation, the os_unix.c and os_win.c source files come before
40941 ** this source file. Verify that the #defines of the locking byte offsets
40942 ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
@@ -40949,30 +41029,27 @@
40949 #endif
40950
40951
40952 /* Allocate an instance of struct Wal to return. */
40953 *ppWal = 0;
40954 nWal = sqlite3Strlen30(zDbName) + 5;
40955 pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile + nWal);
40956 if( !pRet ){
40957 return SQLITE_NOMEM;
40958 }
40959
40960 pRet->pVfs = pVfs;
40961 pRet->pWalFd = (sqlite3_file *)&pRet[1];
40962 pRet->pDbFd = pDbFd;
40963 pRet->readLock = -1;
40964 sqlite3_randomness(8, &pRet->hdr.aSalt);
40965 pRet->zWalName = zWal = pVfs->szOsFile + (char*)pRet->pWalFd;
40966 sqlite3_snprintf(nWal, zWal, "%s-wal", zDbName);
40967 rc = sqlite3OsShmOpen(pDbFd);
40968
40969 /* Open file handle on the write-ahead log file. */
40970 if( rc==SQLITE_OK ){
40971 pRet->isWIndexOpen = 1;
40972 flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_JOURNAL);
40973 rc = sqlite3OsOpen(pVfs, zWal, pRet->pWalFd, flags, &flags);
40974 }
40975
40976 if( rc!=SQLITE_OK ){
40977 walIndexClose(pRet, 0);
40978 sqlite3OsClose(pRet->pWalFd);
@@ -41310,24 +41387,29 @@
41310 rc = sqlite3OsSync(pWal->pWalFd, sync_flags);
41311 }
41312
41313 /* Iterate through the contents of the WAL, copying data to the db file. */
41314 while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
 
41315 assert( walFramePgno(pWal, iFrame)==iDbpage );
41316 if( iFrame<=nBackfill || iFrame>mxSafeFrame ) continue;
41317 rc = sqlite3OsRead(pWal->pWalFd, zBuf, szPage,
41318 walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE
41319 );
41320 if( rc!=SQLITE_OK ) break;
41321 rc = sqlite3OsWrite(pWal->pDbFd, zBuf, szPage, (iDbpage-1)*szPage);
 
 
41322 if( rc!=SQLITE_OK ) break;
41323 }
41324
41325 /* If work was actually accomplished... */
41326 if( rc==SQLITE_OK ){
41327 if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){
41328 rc = sqlite3OsTruncate(pWal->pDbFd, ((i64)pWal->hdr.nPage*(i64)szPage));
 
 
41329 if( rc==SQLITE_OK && sync_flags ){
41330 rc = sqlite3OsSync(pWal->pDbFd, sync_flags);
41331 }
41332 }
41333 if( rc==SQLITE_OK ){
@@ -41861,10 +41943,11 @@
41861 ** required page. Read and return data from the log file.
41862 */
41863 if( iRead ){
41864 i64 iOffset = walFrameOffset(iRead, pWal->hdr.szPage) + WAL_FRAME_HDRSIZE;
41865 *pInWal = 1;
 
41866 return sqlite3OsRead(pWal->pWalFd, pOut, nOut, iOffset);
41867 }
41868
41869 *pInWal = 0;
41870 return SQLITE_OK;
@@ -42127,10 +42210,11 @@
42127
42128 sqlite3Put4byte(&aWalHdr[0], (WAL_MAGIC | SQLITE_BIGENDIAN));
42129 sqlite3Put4byte(&aWalHdr[4], WAL_MAX_VERSION);
42130 sqlite3Put4byte(&aWalHdr[8], szPage);
42131 sqlite3Put4byte(&aWalHdr[12], pWal->nCkpt);
 
42132 memcpy(&aWalHdr[16], pWal->hdr.aSalt, 8);
42133 walChecksumBytes(1, aWalHdr, WAL_HDRSIZE-2*4, 0, aCksum);
42134 sqlite3Put4byte(&aWalHdr[24], aCksum[0]);
42135 sqlite3Put4byte(&aWalHdr[28], aCksum[1]);
42136
@@ -42151,12 +42235,12 @@
42151 for(p=pList; p; p=p->pDirty){
42152 u32 nDbsize; /* Db-size field for frame header */
42153 i64 iOffset; /* Write offset in log file */
42154 void *pData;
42155
42156
42157 iOffset = walFrameOffset(++iFrame, szPage);
 
42158
42159 /* Populate and write the frame header */
42160 nDbsize = (isCommit && p->pDirty==0) ? nTruncate : 0;
42161 #if defined(SQLITE_HAS_CODEC)
42162 if( (pData = sqlite3PagerCodec(p))==0 ) return SQLITE_NOMEM;
@@ -42192,10 +42276,11 @@
42192 if( (pData = sqlite3PagerCodec(pLast))==0 ) return SQLITE_NOMEM;
42193 #else
42194 pData = pLast->pData;
42195 #endif
42196 walEncodeFrame(pWal, pLast->pgno, nTruncate, pData, aFrame);
 
42197 rc = sqlite3OsWrite(pWal->pWalFd, aFrame, sizeof(aFrame), iOffset);
42198 if( rc!=SQLITE_OK ){
42199 return rc;
42200 }
42201 iOffset += WAL_FRAME_HDRSIZE;
@@ -63501,15 +63586,10 @@
63501 ** operation. No IO is required.
63502 **
63503 ** If changing into or out of WAL mode the procedure is more complicated.
63504 **
63505 ** Write a string containing the final journal-mode to register P2.
63506 **
63507 ** If an attempt to change in to or out of WAL mode fails because another
63508 ** connection also has the same database open, then an SQLITE_BUSY error
63509 ** is raised if P5==0, or of P5!=0 the journal mode changed is skipped
63510 ** without signaling the error.
63511 */
63512 case OP_JournalMode: { /* out2-prerelease */
63513 #if 0 /* local variables moved into u.cd */
63514 Btree *pBt; /* Btree to change journal mode of */
63515 Pager *pPager; /* Pager associated with pBt */
@@ -63605,11 +63685,10 @@
63605 }
63606 }
63607 #endif /* ifndef SQLITE_OMIT_WAL */
63608
63609 if( rc ){
63610 if( rc==SQLITE_BUSY && pOp->p5!=0 ) rc = SQLITE_OK;
63611 u.cd.eNew = u.cd.eOld;
63612 }
63613 u.cd.eNew = sqlite3PagerSetJournalMode(u.cd.pPager, u.cd.eNew);
63614
63615 pOut = &aMem[pOp->p2];
@@ -63617,11 +63696,11 @@
63617 pOut->z = (char *)sqlite3JournalModename(u.cd.eNew);
63618 pOut->n = sqlite3Strlen30(pOut->z);
63619 pOut->enc = SQLITE_UTF8;
63620 sqlite3VdbeChangeEncoding(pOut, encoding);
63621 break;
63622 };
63623 #endif /* SQLITE_OMIT_PRAGMA */
63624
63625 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
63626 /* Opcode: Vacuum * * * * *
63627 **
@@ -71830,12 +71909,10 @@
71830 "attached databases must use the same text encoding as main database");
71831 rc = SQLITE_ERROR;
71832 }
71833 pPager = sqlite3BtreePager(aNew->pBt);
71834 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
71835 /* journal_mode set by the OP_JournalMode opcode that will following
71836 ** the OP_Function opcode that invoked this function. */
71837 sqlite3BtreeSecureDelete(aNew->pBt,
71838 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
71839 }
71840 aNew->safety_level = 3;
71841 aNew->zName = sqlite3DbStrDup(db, zName);
@@ -72027,21 +72104,10 @@
72027 sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-pFunc->nArg, regArgs+3);
72028 assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg );
72029 sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg));
72030 sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF);
72031
72032 if( type==SQLITE_ATTACH ){
72033 /* On an attach, also set the journal mode. Note that
72034 ** sqlite3VdbeUsesBtree() is not call here since the iDb index
72035 ** will be out of range prior to the new database being attached.
72036 ** The OP_JournalMode opcode will all sqlite3VdbeUsesBtree() for us.
72037 */
72038 sqlite3VdbeAddOp3(v, OP_JournalMode, db->nDb, regArgs+3,
72039 db->dfltJournalMode);
72040 sqlite3VdbeChangeP5(v, 1);
72041 }
72042
72043 /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
72044 ** statement only). For DETACH, set it to false (expire all existing
72045 ** statements).
72046 */
72047 sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH));
@@ -75914,11 +75980,10 @@
75914 assert( db->aDb[1].pSchema );
75915 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
75916 db->mallocFailed = 1;
75917 return 1;
75918 }
75919 sqlite3PagerSetJournalMode(sqlite3BtreePager(pBt), db->dfltJournalMode);
75920 }
75921 return 0;
75922 }
75923
75924 /*
@@ -83583,58 +83648,49 @@
83583 ** PRAGMA [database.]journal_mode
83584 ** PRAGMA [database.]journal_mode =
83585 ** (delete|persist|off|truncate|memory|wal|off)
83586 */
83587 if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){
83588 int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
 
 
 
 
 
 
 
83589
83590 sqlite3VdbeSetNumCols(v, 1);
83591 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);
83592
83593 if( zRight==0 ){
 
 
83594 eMode = PAGER_JOURNALMODE_QUERY;
83595 }else{
83596 const char *zMode;
83597 int n = sqlite3Strlen30(zRight);
83598 for(eMode=0; (zMode = sqlite3JournalModename(eMode)); eMode++){
83599 if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break;
83600 }
83601 if( !zMode ){
 
 
83602 eMode = PAGER_JOURNALMODE_QUERY;
83603 }
83604 }
83605 if( pId2->n==0 && eMode==PAGER_JOURNALMODE_QUERY ){
83606 /* Simple "PRAGMA journal_mode;" statement. This is a query for
83607 ** the current default journal mode (which may be different to
83608 ** the journal-mode of the main database).
83609 */
83610 eMode = db->dfltJournalMode;
83611 sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
83612 sqlite3VdbeChangeP4(v, -1, sqlite3JournalModename(eMode), P4_STATIC);
83613 }else{
83614 int ii;
83615
83616 if( pId2->n==0 ){
83617 /* When there is no database name before the "journal_mode" keyword
83618 ** in the PRAGMA, then the journal-mode will be set on
83619 ** all attached databases, as well as the main db file.
83620 **
83621 ** Also, the sqlite3.dfltJournalMode variable is set so that
83622 ** any subsequently attached databases also use the specified
83623 ** journal mode.
83624 */
83625 db->dfltJournalMode = (u8)eMode;
83626 }
83627
83628 for(ii=db->nDb-1; ii>=0; ii--){
83629 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
83630 sqlite3VdbeUsesBtree(v, ii);
83631 sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode);
83632 }
83633 }
83634 }
83635
83636 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
83637 }else
83638
83639 /*
83640 ** PRAGMA [database.]journal_size_limit
@@ -84648,25 +84704,28 @@
84648 ** or executed. All the parser does is build the internal data
84649 ** structures that describe the table, index, or view.
84650 */
84651 int rc;
84652 sqlite3_stmt *pStmt;
 
84653
84654 assert( db->init.busy );
84655 db->init.iDb = iDb;
84656 db->init.newTnum = atoi(argv[1]);
84657 db->init.orphanTrigger = 0;
84658 rc = sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
 
 
84659 db->init.iDb = 0;
84660 if( SQLITE_OK!=rc ){
84661 if( db->init.orphanTrigger ){
84662 assert( iDb==1 );
84663 }else{
84664 pData->rc = rc;
84665 if( rc==SQLITE_NOMEM ){
84666 db->mallocFailed = 1;
84667 }else if( rc!=SQLITE_INTERRUPT && rc!=SQLITE_LOCKED ){
84668 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
84669 }
84670 }
84671 }
84672 sqlite3_finalize(pStmt);
@@ -104123,20 +104182,18 @@
104123 sqlite3_mutex_leave(db->mutex);
104124 return SQLITE_OK;
104125 }
104126 #endif /* SQLITE_OMIT_UTF16 */
104127
104128 #ifndef SQLITE_OMIT_GLOBALRECOVER
104129 #ifndef SQLITE_OMIT_DEPRECATED
104130 /*
104131 ** This function is now an anachronism. It used to be used to recover from a
104132 ** malloc() failure, but SQLite now does this automatically.
104133 */
104134 SQLITE_API int sqlite3_global_recover(void){
104135 return SQLITE_OK;
104136 }
104137 #endif
104138 #endif
104139
104140 /*
104141 ** Test to see whether or not the database connection is in autocommit
104142 ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
104143
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -509,10 +509,17 @@
509 #else
510 # define ALWAYS(X) (X)
511 # define NEVER(X) (X)
512 #endif
513
514 /*
515 ** Return true (non-zero) if the input is a integer that is too large
516 ** to fit in 32-bits. This macro is used inside of various testcase()
517 ** macros to verify that we have tested SQLite for large-file support.
518 */
519 #define IS_BIG_INT(X) (((X)&(i64)0xffffffff)!=0)
520
521 /*
522 ** The macro unlikely() is a hint that surrounds a boolean
523 ** expression that is usually false. Macro likely() surrounds
524 ** a boolean expression that is usually true. GCC is able to
525 ** use these hints to generate better code, sometimes.
@@ -636,11 +643,11 @@
643 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
644 ** [sqlite_version()] and [sqlite_source_id()].
645 */
646 #define SQLITE_VERSION "3.7.0"
647 #define SQLITE_VERSION_NUMBER 3007000
648 #define SQLITE_SOURCE_ID "2010-07-08 17:40:38 e396184cd3bdb96e29ac33af5d1f631cac553341"
649
650 /*
651 ** CAPI3REF: Run-Time Library Version Numbers
652 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
653 **
@@ -1359,20 +1366,27 @@
1366 ** is also passed as a parameter to both methods. If the output buffer
1367 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
1368 ** handled as a fatal error by SQLite, vfs implementations should endeavor
1369 ** to prevent this by setting mxPathname to a sufficiently large value.
1370 **
1371 ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
1372 ** interfaces are not strictly a part of the filesystem, but they are
1373 ** included in the VFS structure for completeness.
1374 ** The xRandomness() function attempts to return nBytes bytes
1375 ** of good-quality randomness into zOut. The return value is
1376 ** the actual number of bytes of randomness obtained.
1377 ** The xSleep() method causes the calling thread to sleep for at
1378 ** least the number of microseconds given. The xCurrentTime()
1379 ** method returns a Julian Day Number for the current date and time as
1380 ** a floating point value.
1381 ** The xCurrentTimeInt64() method returns, as an integer, the Julian
1382 ** Day Number multipled by 86400000 (the number of milliseconds in
1383 ** a 24-hour day).
1384 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
1385 ** date and time if that method is available (if iVersion is 2 or
1386 ** greater and the function pointer is not NULL) and will fall back
1387 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
1388 */
1389 typedef struct sqlite3_vfs sqlite3_vfs;
1390 struct sqlite3_vfs {
1391 int iVersion; /* Structure version number (currently 2) */
1392 int szOsFile; /* Size of subclassed sqlite3_file */
@@ -1395,11 +1409,10 @@
1409 int (*xGetLastError)(sqlite3_vfs*, int, char *);
1410 /*
1411 ** The methods above are in version 1 of the sqlite_vfs object
1412 ** definition. Those that follow are added in version 2 or later
1413 */
 
1414 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
1415 /*
1416 ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1417 ** New fields may be appended in figure versions. The iVersion
1418 ** value will increment whenever this happens.
@@ -8559,11 +8572,10 @@
8572 int errMask; /* & result codes with this before returning */
8573 u8 autoCommit; /* The auto-commit flag. */
8574 u8 temp_store; /* 1: file 2: memory 0: default */
8575 u8 mallocFailed; /* True if we have seen a malloc failure */
8576 u8 dfltLockMode; /* Default locking-mode for attached dbs */
 
8577 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
8578 u8 suppressErr; /* Do not issue error messages if true */
8579 int nextPagesize; /* Pagesize after VACUUM if >0 */
8580 int nTable; /* Number of tables in the database */
8581 CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
@@ -11327,13 +11339,15 @@
11339 "OMIT_CAST",
11340 #endif
11341 #ifdef SQLITE_OMIT_CHECK
11342 "OMIT_CHECK",
11343 #endif
11344 /* // redundant
11345 ** #ifdef SQLITE_OMIT_COMPILEOPTION_DIAGS
11346 ** "OMIT_COMPILEOPTION_DIAGS",
11347 ** #endif
11348 */
11349 #ifdef SQLITE_OMIT_COMPLETE
11350 "OMIT_COMPLETE",
11351 #endif
11352 #ifdef SQLITE_OMIT_COMPOUND_SELECT
11353 "OMIT_COMPOUND_SELECT",
@@ -11363,13 +11377,10 @@
11377 "OMIT_FOREIGN_KEY",
11378 #endif
11379 #ifdef SQLITE_OMIT_GET_TABLE
11380 "OMIT_GET_TABLE",
11381 #endif
 
 
 
11382 #ifdef SQLITE_OMIT_INCRBLOB
11383 "OMIT_INCRBLOB",
11384 #endif
11385 #ifdef SQLITE_OMIT_INTEGRITY_CHECK
11386 "OMIT_INTEGRITY_CHECK",
@@ -11443,10 +11454,13 @@
11454 #ifdef SQLITE_OMIT_VIEW
11455 "OMIT_VIEW",
11456 #endif
11457 #ifdef SQLITE_OMIT_VIRTUALTABLE
11458 "OMIT_VIRTUALTABLE",
11459 #endif
11460 #ifdef SQLITE_OMIT_WAL
11461 "OMIT_WAL",
11462 #endif
11463 #ifdef SQLITE_OMIT_WSD
11464 "OMIT_WSD",
11465 #endif
11466 #ifdef SQLITE_OMIT_XFER_OPT
@@ -28503,11 +28517,10 @@
28517 unixDlClose, /* xDlClose */ \
28518 unixRandomness, /* xRandomness */ \
28519 unixSleep, /* xSleep */ \
28520 unixCurrentTime, /* xCurrentTime */ \
28521 unixGetLastError, /* xGetLastError */ \
 
28522 unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
28523 }
28524
28525 /*
28526 ** All default VFSes for unix are contained in the following array.
@@ -29406,10 +29419,11 @@
29419 assert( id!=0 );
29420 assert( pFile->pShm==0 );
29421 OSTRACE(("CLOSE %d\n", pFile->h));
29422 do{
29423 rc = CloseHandle(pFile->h);
29424 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
29425 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (Sleep(100), 1) );
29426 #if SQLITE_OS_WINCE
29427 #define WINCE_DELETION_ATTEMPTS 3
29428 winceDestroyLock(pFile);
29429 if( pFile->zDeleteOnClose ){
@@ -29497,11 +29511,15 @@
29511 SimulateDiskfullError(return SQLITE_FULL);
29512 OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype));
29513 rc = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
29514 if( rc==INVALID_SET_FILE_POINTER && (error=GetLastError())!=NO_ERROR ){
29515 pFile->lastErrno = error;
29516 if( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ){
29517 return SQLITE_FULL;
29518 }else{
29519 return SQLITE_IOERR_WRITE;
29520 }
29521 }
29522 assert( amt>0 );
29523 while(
29524 amt>0
29525 && (rc = WriteFile(pFile->h, pBuf, amt, &wrote, 0))!=0
@@ -29510,11 +29528,15 @@
29528 amt -= wrote;
29529 pBuf = &((char*)pBuf)[wrote];
29530 }
29531 if( !rc || amt>(int)wrote ){
29532 pFile->lastErrno = GetLastError();
29533 if( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ){
29534 return SQLITE_FULL;
29535 }else{
29536 return SQLITE_IOERR_WRITE;
29537 }
29538 }
29539 return SQLITE_OK;
29540 }
29541
29542 /*
@@ -29555,31 +29577,44 @@
29577
29578 /*
29579 ** Make sure all writes to a particular file are committed to disk.
29580 */
29581 static int winSync(sqlite3_file *id, int flags){
29582 #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || defined(SQLITE_DEBUG)
29583 winFile *pFile = (winFile*)id;
 
 
 
29584 #else
29585 UNUSED_PARAMETER(id);
29586 #endif
29587
29588 assert( pFile );
29589 /* Check that one of SQLITE_SYNC_NORMAL or FULL was passed */
29590 assert((flags&0x0F)==SQLITE_SYNC_NORMAL
29591 || (flags&0x0F)==SQLITE_SYNC_FULL
29592 );
29593
29594 OSTRACE(("SYNC %d lock=%d\n", pFile->h, pFile->locktype));
29595
29596 #ifndef SQLITE_TEST
29597 UNUSED_PARAMETER(flags);
29598 #else
29599 if( flags & SQLITE_SYNC_FULL ){
29600 sqlite3_fullsync_count++;
29601 }
29602 sqlite3_sync_count++;
29603 #endif
29604
29605 /* Unix cannot, but some systems may return SQLITE_FULL from here. This
29606 ** line is to test that doing so does not cause any problems.
29607 */
29608 SimulateDiskfullError( return SQLITE_FULL );
29609 SimulateIOError( return SQLITE_IOERR; );
29610
29611 /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
29612 ** no-op
29613 */
29614 #ifdef SQLITE_NO_SYNC
29615 return SQLITE_OK;
29616 #else
29617 if( FlushFileBuffers(pFile->h) ){
29618 return SQLITE_OK;
29619 }else{
29620 pFile->lastErrno = GetLastError();
@@ -29818,10 +29853,12 @@
29853 */
29854 static int winCheckReservedLock(sqlite3_file *id, int *pResOut){
29855 int rc;
29856 winFile *pFile = (winFile*)id;
29857
29858 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
29859
29860 assert( id!=0 );
29861 if( pFile->locktype>=RESERVED_LOCK ){
29862 rc = 1;
29863 OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc));
29864 }else{
@@ -29890,11 +29927,13 @@
29927 *(int*)pArg = (int)((winFile*)id)->lastErrno;
29928 return SQLITE_OK;
29929 }
29930 case SQLITE_FCNTL_SIZE_HINT: {
29931 sqlite3_int64 sz = *(sqlite3_int64*)pArg;
29932 SimulateIOErrorBenign(1);
29933 winTruncate(id, sz);
29934 SimulateIOErrorBenign(0);
29935 return SQLITE_OK;
29936 }
29937 }
29938 return SQLITE_ERROR;
29939 }
@@ -30101,14 +30140,20 @@
30140 if( p->mutex ) sqlite3_mutex_free(p->mutex);
30141 for(i=0; i<p->nRegion; i++){
30142 UnmapViewOfFile(p->aRegion[i].pMap);
30143 CloseHandle(p->aRegion[i].hMap);
30144 }
30145 if( p->hFile.h != INVALID_HANDLE_VALUE ){
30146 SimulateIOErrorBenign(1);
30147 winClose((sqlite3_file *)&p->hFile);
30148 SimulateIOErrorBenign(0);
30149 }
30150 if( deleteFlag ){
30151 SimulateIOErrorBenign(1);
30152 winDelete(pVfs, p->zFilename, 0);
30153 SimulateIOErrorBenign(0);
30154 }
30155 *pp = p->pNext;
30156 sqlite3_free(p->aRegion);
30157 sqlite3_free(p);
30158 }else{
30159 pp = &p->pNext;
@@ -30506,10 +30551,17 @@
30551 "abcdefghijklmnopqrstuvwxyz"
30552 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
30553 "0123456789";
30554 size_t i, j;
30555 char zTempPath[MAX_PATH+1];
30556
30557 /* It's odd to simulate an io-error here, but really this is just
30558 ** using the io-error infrastructure to test that SQLite handles this
30559 ** function failing.
30560 */
30561 SimulateIOError( return SQLITE_IOERR );
30562
30563 if( sqlite3_temp_directory ){
30564 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
30565 }else if( isNT() ){
30566 char *zMulti;
30567 WCHAR zWidePath[MAX_PATH];
@@ -30537,20 +30589,30 @@
30589 }else{
30590 return SQLITE_NOMEM;
30591 }
30592 #endif
30593 }
30594
30595 /* Check that the output buffer is large enough for the temporary file
30596 ** name. If it is not, return SQLITE_ERROR.
30597 */
30598 if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 17) >= nBuf ){
30599 return SQLITE_ERROR;
30600 }
30601
30602 for(i=sqlite3Strlen30(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
30603 zTempPath[i] = 0;
30604
30605 sqlite3_snprintf(nBuf-17, zBuf,
30606 "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath);
30607 j = sqlite3Strlen30(zBuf);
30608 sqlite3_randomness(15, &zBuf[j]);
30609 for(i=0; i<15; i++, j++){
30610 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
30611 }
30612 zBuf[j] = 0;
30613
30614 OSTRACE(("TEMP FILENAME: %s\n", zBuf));
30615 return SQLITE_OK;
30616 }
30617
30618 /*
@@ -30790,17 +30852,19 @@
30852 int syncDir /* Not used on win32 */
30853 ){
30854 int cnt = 0;
30855 DWORD rc;
30856 DWORD error = 0;
30857 void *zConverted;
30858 UNUSED_PARAMETER(pVfs);
30859 UNUSED_PARAMETER(syncDir);
30860
30861 SimulateIOError(return SQLITE_IOERR_DELETE);
30862 zConverted = convertUtf8Filename(zFilename);
30863 if( zConverted==0 ){
30864 return SQLITE_NOMEM;
30865 }
 
30866 if( isNT() ){
30867 do{
30868 DeleteFileW(zConverted);
30869 }while( ( ((rc = GetFileAttributesW(zConverted)) != INVALID_FILE_ATTRIBUTES)
30870 || ((error = GetLastError()) == ERROR_ACCESS_DENIED))
@@ -30838,17 +30902,42 @@
30902 int flags, /* Type of test to make on this file */
30903 int *pResOut /* OUT: Result */
30904 ){
30905 DWORD attr;
30906 int rc = 0;
30907 void *zConverted;
30908 UNUSED_PARAMETER(pVfs);
30909
30910 SimulateIOError( return SQLITE_IOERR_ACCESS; );
30911 zConverted = convertUtf8Filename(zFilename);
30912 if( zConverted==0 ){
30913 return SQLITE_NOMEM;
30914 }
30915 if( isNT() ){
30916 WIN32_FILE_ATTRIBUTE_DATA sAttrData;
30917 memset(&sAttrData, 0, sizeof(sAttrData));
30918 if( GetFileAttributesExW((WCHAR*)zConverted,
30919 GetFileExInfoStandard,
30920 &sAttrData) ){
30921 /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
30922 ** as if it does not exist.
30923 */
30924 if( flags==SQLITE_ACCESS_EXISTS
30925 && sAttrData.nFileSizeHigh==0
30926 && sAttrData.nFileSizeLow==0 ){
30927 attr = INVALID_FILE_ATTRIBUTES;
30928 }else{
30929 attr = sAttrData.dwFileAttributes;
30930 }
30931 }else{
30932 if( GetLastError()!=ERROR_FILE_NOT_FOUND ){
30933 free(zConverted);
30934 return SQLITE_IOERR_ACCESS;
30935 }else{
30936 attr = INVALID_FILE_ATTRIBUTES;
30937 }
30938 }
30939 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
30940 ** Since the ASCII version of these Windows API do not exist for WINCE,
30941 ** it's important to not reference them for WINCE builds.
30942 */
30943 #if SQLITE_OS_WINCE==0
@@ -30884,16 +30973,18 @@
30973 int nFull, /* Size of output buffer in bytes */
30974 char *zFull /* Output buffer */
30975 ){
30976
30977 #if defined(__CYGWIN__)
30978 SimulateIOError( return SQLITE_ERROR );
30979 UNUSED_PARAMETER(nFull);
30980 cygwin_conv_to_full_win32_path(zRelative, zFull);
30981 return SQLITE_OK;
30982 #endif
30983
30984 #if SQLITE_OS_WINCE
30985 SimulateIOError( return SQLITE_ERROR );
30986 UNUSED_PARAMETER(nFull);
30987 /* WinCE has no concept of a relative pathname, or so I am told. */
30988 sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zRelative);
30989 return SQLITE_OK;
30990 #endif
@@ -30900,10 +30991,17 @@
30991
30992 #if !SQLITE_OS_WINCE && !defined(__CYGWIN__)
30993 int nByte;
30994 void *zConverted;
30995 char *zOut;
30996
30997 /* It's odd to simulate an io-error here, but really this is just
30998 ** using the io-error infrastructure to test that SQLite handles this
30999 ** function failing. This function could fail if, for example, the
31000 ** current working directory has been unlinked.
31001 */
31002 SimulateIOError( return SQLITE_ERROR );
31003 UNUSED_PARAMETER(nFull);
31004 zConverted = convertUtf8Filename(zRelative);
31005 if( isNT() ){
31006 WCHAR *zTemp;
31007 nByte = GetFullPathNameW((WCHAR*)zConverted, 0, 0, 0) + 3;
@@ -30967,11 +31065,13 @@
31065 /*
31066 ** We need to get the full path name of the file
31067 ** to get the drive letter to look up the sector
31068 ** size.
31069 */
31070 SimulateIOErrorBenign(1);
31071 rc = winFullPathname(pVfs, zRelative, MAX_PATH, zFullpath);
31072 SimulateIOErrorBenign(0);
31073 if( rc == SQLITE_OK )
31074 {
31075 void *zConverted = convertUtf8Filename(zFullpath);
31076 if( zConverted ){
31077 if( isNT() ){
@@ -31244,11 +31344,10 @@
31344 winDlClose, /* xDlClose */
31345 winRandomness, /* xRandomness */
31346 winSleep, /* xSleep */
31347 winCurrentTime, /* xCurrentTime */
31348 winGetLastError, /* xGetLastError */
 
31349 winCurrentTimeInt64, /* xCurrentTimeInt64 */
31350 };
31351
31352 sqlite3_vfs_register(&winVfs, 1);
31353 return SQLITE_OK;
@@ -33981,10 +34080,11 @@
34080 char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
34081 PCache *pPCache; /* Pointer to page cache object */
34082 sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
34083 #ifndef SQLITE_OMIT_WAL
34084 Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */
34085 char *zWal; /* File name for write-ahead log */
34086 #endif
34087 };
34088
34089 /*
34090 ** The following global variables hold counters used for
@@ -35091,10 +35191,25 @@
35191 i -= 200;
35192 }
35193 return cksum;
35194 }
35195
35196 /*
35197 ** Report the current page size and number of reserved bytes back
35198 ** to the codec.
35199 */
35200 #ifdef SQLITE_HAS_CODEC
35201 static void pagerReportSize(Pager *pPager){
35202 if( pPager->xCodecSizeChng ){
35203 pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize,
35204 (int)pPager->nReserve);
35205 }
35206 }
35207 #else
35208 # define pagerReportSize(X) /* No-op if we do not support a codec */
35209 #endif
35210
35211 /*
35212 ** Read a single page from either the journal file (if isMainJrnl==1) or
35213 ** from the sub-journal (if isMainJrnl==0) and playback that page.
35214 ** The page begins at offset *pOffset into the file. The *pOffset
35215 ** value is increased to the start of the next page in the journal.
@@ -35183,15 +35298,24 @@
35298 if( !isSavepnt && pager_cksum(pPager, (u8*)aData)!=cksum ){
35299 return SQLITE_DONE;
35300 }
35301 }
35302
35303 /* If this page has already been played by before during the current
35304 ** rollback, then don't bother to play it back again.
35305 */
35306 if( pDone && (rc = sqlite3BitvecSet(pDone, pgno))!=SQLITE_OK ){
35307 return rc;
35308 }
 
35309 assert( pPager->state==PAGER_RESERVED || pPager->state>=PAGER_EXCLUSIVE );
35310
35311 /* When playing back page 1, restore the nReserve setting
35312 */
35313 if( pgno==1 && pPager->nReserve!=((u8*)aData)[20] ){
35314 pPager->nReserve = ((u8*)aData)[20];
35315 pagerReportSize(pPager);
35316 }
35317
35318 /* If the pager is in RESERVED state, then there must be a copy of this
35319 ** page in the pager cache. In this case just update the pager cache,
35320 ** not the database file. The page is left marked dirty in this case.
35321 **
@@ -35987,42 +36111,10 @@
36111 pPager->state = PAGER_SHARED;
36112
36113 return rc;
36114 }
36115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36116 /*
36117 ** Check if the *-wal file that corresponds to the database opened by pPager
36118 ** exists if the database is not empy, or verify that the *-wal file does
36119 ** not exist (by deleting it) if the database file is empty.
36120 **
@@ -36048,14 +36140,16 @@
36140 int nPage; /* Size of the database file */
36141 assert( pPager->state>=SHARED_LOCK );
36142 rc = sqlite3PagerPagecount(pPager, &nPage);
36143 if( rc ) return rc;
36144 if( nPage==0 ){
36145 rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0);
36146 isWal = 0;
36147 }else{
36148 rc = sqlite3OsAccess(
36149 pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &isWal
36150 );
36151 }
36152 if( rc==SQLITE_OK ){
36153 if( isWal ){
36154 pager_reset(pPager);
36155 rc = sqlite3PagerOpenWal(pPager, 0);
@@ -36125,10 +36219,11 @@
36219
36220 /* Set the database size back to the value it was before the savepoint
36221 ** being reverted was opened.
36222 */
36223 pPager->dbSize = pSavepoint ? pSavepoint->nOrig : pPager->dbOrigSize;
36224 pPager->changeCountDone = pPager->tempFile;
36225
36226 if( !pSavepoint && pagerUseWal(pPager) ){
36227 return pagerRollbackWal(pPager);
36228 }
36229
@@ -36325,25 +36420,10 @@
36420 ){
36421 pPager->xBusyHandler = xBusyHandler;
36422 pPager->pBusyHandlerArg = pBusyHandlerArg;
36423 }
36424
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36425 /*
36426 ** Change the page size used by the Pager object. The new page size
36427 ** is passed in *pPageSize.
36428 **
36429 ** If the pager is in the error state when this function is called, it
@@ -36479,19 +36559,10 @@
36559 /* This routine is only called by btree immediately after creating
36560 ** the Pager object. There has not been an opportunity to transition
36561 ** to WAL mode yet.
36562 */
36563 assert( !pagerUseWal(pPager) );
 
 
 
 
 
 
 
 
 
36564
36565 if( isOpen(pPager->fd) ){
36566 IOTRACE(("DBHDR %p 0 %d\n", pPager, N))
36567 rc = sqlite3OsRead(pPager->fd, pDest, N, 0);
36568 if( rc==SQLITE_IOERR_SHORT_READ ){
@@ -36931,17 +37002,13 @@
37002 **
37003 ** If everything is successful, SQLITE_OK is returned. If an IO error
37004 ** occurs, an IO error code is returned. Or, if the EXCLUSIVE lock cannot
37005 ** be obtained, SQLITE_BUSY is returned.
37006 */
37007 static int pager_write_pagelist(Pager *pPager, PgHdr *pList){
 
37008 int rc; /* Return code */
37009
 
 
 
37010 /* At this point there may be either a RESERVED or EXCLUSIVE lock on the
37011 ** database file. If there is already an EXCLUSIVE lock, the following
37012 ** call is a no-op.
37013 **
37014 ** Moving the lock from RESERVED to EXCLUSIVE actually involves going
@@ -36954,11 +37021,11 @@
37021 ** is unchanged and we can rollback without having to playback the
37022 ** journal into the original database file. Once we transition to
37023 ** EXCLUSIVE, it means the database file has been changed and any rollback
37024 ** will require a journal playback.
37025 */
37026 assert( !pagerUseWal(pPager) );
37027 assert( pPager->state>=PAGER_RESERVED );
37028 rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
37029
37030 /* If the file is a temp-file has not yet been opened, open it now. It
37031 ** is not possible for rc to be other than SQLITE_OK if this branch
@@ -36970,11 +37037,12 @@
37037 }
37038
37039 /* Before the first write, give the VFS a hint of what the final
37040 ** file size will be.
37041 */
37042 assert( rc!=SQLITE_OK || isOpen(pPager->fd) );
37043 if( rc==SQLITE_OK && pPager->dbSize>(pPager->dbOrigSize+1) ){
37044 sqlite3_int64 szFile = pPager->pageSize * (sqlite3_int64)pPager->dbSize;
37045 sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &szFile);
37046 }
37047
37048 while( rc==SQLITE_OK && pList ){
@@ -37199,11 +37267,11 @@
37267 rc = subjournalPage(pPg);
37268 }
37269
37270 /* Write the contents of the page out to the database file. */
37271 if( rc==SQLITE_OK ){
37272 rc = pager_write_pagelist(pPager, pPg);
37273 }
37274 }
37275
37276 /* Mark the page as clean. */
37277 if( rc==SQLITE_OK ){
@@ -37339,10 +37407,13 @@
37407 ROUND8(pcacheSize) + /* PCache object */
37408 ROUND8(pVfs->szOsFile) + /* The main db file */
37409 journalFileSize * 2 + /* The two journal files */
37410 nPathname + 1 + /* zFilename */
37411 nPathname + 8 + 1 /* zJournal */
37412 #ifndef SQLITE_OMIT_WAL
37413 + nPathname + 4 + 1 /* zWal */
37414 #endif
37415 );
37416 assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
37417 if( !pPtr ){
37418 sqlite3_free(zPathname);
37419 return SQLITE_NOMEM;
@@ -37359,11 +37430,20 @@
37430 if( zPathname ){
37431 pPager->zJournal = (char*)(pPtr += nPathname + 1);
37432 memcpy(pPager->zFilename, zPathname, nPathname);
37433 memcpy(pPager->zJournal, zPathname, nPathname);
37434 memcpy(&pPager->zJournal[nPathname], "-journal", 8);
37435 if( pPager->zFilename[0]==0 ){
37436 pPager->zJournal[0] = 0;
37437 }
37438 #ifndef SQLITE_OMIT_WAL
37439 else{
37440 pPager->zWal = &pPager->zJournal[nPathname+8+1];
37441 memcpy(pPager->zWal, zPathname, nPathname);
37442 memcpy(&pPager->zWal[nPathname], "-wal", 4);
37443 }
37444 #endif
37445 sqlite3_free(zPathname);
37446 }
37447 pPager->pVfs = pVfs;
37448 pPager->vfsFlags = vfsFlags;
37449
@@ -38816,11 +38896,11 @@
38896 */
38897 rc = syncJournal(pPager);
38898 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
38899
38900 /* Write all dirty pages to the database file. */
38901 rc = pager_write_pagelist(pPager,sqlite3PcacheDirtyList(pPager->pPCache));
38902 if( rc!=SQLITE_OK ){
38903 assert( rc!=SQLITE_IOERR_BLOCKED );
38904 goto commit_phase_one_exit;
38905 }
38906 sqlite3PcacheCleanAll(pPager->pPCache);
@@ -39651,12 +39731,11 @@
39731
39732 /* Open the connection to the log file. If this operation fails,
39733 ** (e.g. due to malloc() failure), unlock the database file and
39734 ** return an error code.
39735 */
39736 rc = sqlite3WalOpen(pPager->pVfs, pPager->fd, pPager->zWal, &pPager->pWal);
 
39737 if( rc==SQLITE_OK ){
39738 pPager->journalMode = PAGER_JOURNALMODE_WAL;
39739 }
39740 }else{
39741 *pisOpen = 1;
@@ -39685,15 +39764,17 @@
39764 */
39765 if( !pPager->pWal ){
39766 int logexists = 0;
39767 rc = sqlite3OsLock(pPager->fd, SQLITE_LOCK_SHARED);
39768 if( rc==SQLITE_OK ){
39769 rc = sqlite3OsAccess(
39770 pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &logexists
39771 );
39772 }
39773 if( rc==SQLITE_OK && logexists ){
39774 rc = sqlite3WalOpen(pPager->pVfs, pPager->fd,
39775 pPager->zWal, &pPager->pWal);
39776 }
39777 }
39778
39779 /* Checkpoint and close the log. Because an EXCLUSIVE lock is held on
39780 ** the database file, the log and log-summary files will be deleted.
@@ -40131,11 +40212,11 @@
40212 ** Return the offset of frame iFrame in the write-ahead log file,
40213 ** assuming a database page size of szPage bytes. The offset returned
40214 ** is to the start of the write-ahead log frame-header.
40215 */
40216 #define walFrameOffset(iFrame, szPage) ( \
40217 WAL_HDRSIZE + ((iFrame)-1)*(i64)((szPage)+WAL_FRAME_HDRSIZE) \
40218 )
40219
40220 /*
40221 ** An open write-ahead log file is represented by an instance of the
40222 ** following object.
@@ -40152,11 +40233,11 @@
40233 u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
40234 u8 isWIndexOpen; /* True if ShmOpen() called on pDbFd */
40235 u8 writeLock; /* True if in a write transaction */
40236 u8 ckptLock; /* True if holding a checkpoint lock */
40237 WalIndexHdr hdr; /* Wal-index header for current transaction */
40238 const char *zWalName; /* Name of WAL file */
40239 u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
40240 #ifdef SQLITE_DEBUG
40241 u8 lockError; /* True if a locking error has occurred */
40242 #endif
40243 };
@@ -40907,12 +40988,13 @@
40988 pWal->isWIndexOpen = 0;
40989 }
40990 }
40991
40992 /*
40993 ** Open a connection to the WAL file zWalName. The database file must
40994 ** already be opened on connection pDbFd. The buffer that zWalName points
40995 ** to must remain valid for the lifetime of the returned Wal* handle.
40996 **
40997 ** A SHARED lock should be held on the database file when this function
40998 ** is called. The purpose of this SHARED lock is to prevent any other
40999 ** client from unlinking the WAL or wal-index file. If another process
41000 ** were to do this just after this client opened one of these files, the
@@ -40923,20 +41005,18 @@
41005 ** an SQLite error code is returned and *ppWal is left unmodified.
41006 */
41007 SQLITE_PRIVATE int sqlite3WalOpen(
41008 sqlite3_vfs *pVfs, /* vfs module to open wal and wal-index */
41009 sqlite3_file *pDbFd, /* The open database file */
41010 const char *zWalName, /* Name of the WAL file */
41011 Wal **ppWal /* OUT: Allocated Wal handle */
41012 ){
41013 int rc; /* Return Code */
41014 Wal *pRet; /* Object to allocate and return */
41015 int flags; /* Flags passed to OsOpen() */
 
 
41016
41017 assert( zWalName && zWalName[0] );
41018 assert( pDbFd );
41019
41020 /* In the amalgamation, the os_unix.c and os_win.c source files come before
41021 ** this source file. Verify that the #defines of the locking byte offsets
41022 ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
@@ -40949,30 +41029,27 @@
41029 #endif
41030
41031
41032 /* Allocate an instance of struct Wal to return. */
41033 *ppWal = 0;
41034 pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile);
 
41035 if( !pRet ){
41036 return SQLITE_NOMEM;
41037 }
41038
41039 pRet->pVfs = pVfs;
41040 pRet->pWalFd = (sqlite3_file *)&pRet[1];
41041 pRet->pDbFd = pDbFd;
41042 pRet->readLock = -1;
41043 pRet->zWalName = zWalName;
 
 
41044 rc = sqlite3OsShmOpen(pDbFd);
41045
41046 /* Open file handle on the write-ahead log file. */
41047 if( rc==SQLITE_OK ){
41048 pRet->isWIndexOpen = 1;
41049 flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_JOURNAL);
41050 rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
41051 }
41052
41053 if( rc!=SQLITE_OK ){
41054 walIndexClose(pRet, 0);
41055 sqlite3OsClose(pRet->pWalFd);
@@ -41310,24 +41387,29 @@
41387 rc = sqlite3OsSync(pWal->pWalFd, sync_flags);
41388 }
41389
41390 /* Iterate through the contents of the WAL, copying data to the db file. */
41391 while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
41392 i64 iOffset;
41393 assert( walFramePgno(pWal, iFrame)==iDbpage );
41394 if( iFrame<=nBackfill || iFrame>mxSafeFrame ) continue;
41395 iOffset = walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE;
41396 /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */
41397 rc = sqlite3OsRead(pWal->pWalFd, zBuf, szPage, iOffset);
41398 if( rc!=SQLITE_OK ) break;
41399 iOffset = (iDbpage-1)*(i64)szPage;
41400 testcase( IS_BIG_INT(iOffset) );
41401 rc = sqlite3OsWrite(pWal->pDbFd, zBuf, szPage, iOffset);
41402 if( rc!=SQLITE_OK ) break;
41403 }
41404
41405 /* If work was actually accomplished... */
41406 if( rc==SQLITE_OK ){
41407 if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){
41408 i64 szDb = pWal->hdr.nPage*(i64)szPage;
41409 testcase( IS_BIG_INT(szDb) );
41410 rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
41411 if( rc==SQLITE_OK && sync_flags ){
41412 rc = sqlite3OsSync(pWal->pDbFd, sync_flags);
41413 }
41414 }
41415 if( rc==SQLITE_OK ){
@@ -41861,10 +41943,11 @@
41943 ** required page. Read and return data from the log file.
41944 */
41945 if( iRead ){
41946 i64 iOffset = walFrameOffset(iRead, pWal->hdr.szPage) + WAL_FRAME_HDRSIZE;
41947 *pInWal = 1;
41948 /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
41949 return sqlite3OsRead(pWal->pWalFd, pOut, nOut, iOffset);
41950 }
41951
41952 *pInWal = 0;
41953 return SQLITE_OK;
@@ -42127,10 +42210,11 @@
42210
42211 sqlite3Put4byte(&aWalHdr[0], (WAL_MAGIC | SQLITE_BIGENDIAN));
42212 sqlite3Put4byte(&aWalHdr[4], WAL_MAX_VERSION);
42213 sqlite3Put4byte(&aWalHdr[8], szPage);
42214 sqlite3Put4byte(&aWalHdr[12], pWal->nCkpt);
42215 sqlite3_randomness(8, pWal->hdr.aSalt);
42216 memcpy(&aWalHdr[16], pWal->hdr.aSalt, 8);
42217 walChecksumBytes(1, aWalHdr, WAL_HDRSIZE-2*4, 0, aCksum);
42218 sqlite3Put4byte(&aWalHdr[24], aCksum[0]);
42219 sqlite3Put4byte(&aWalHdr[28], aCksum[1]);
42220
@@ -42151,12 +42235,12 @@
42235 for(p=pList; p; p=p->pDirty){
42236 u32 nDbsize; /* Db-size field for frame header */
42237 i64 iOffset; /* Write offset in log file */
42238 void *pData;
42239
 
42240 iOffset = walFrameOffset(++iFrame, szPage);
42241 /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
42242
42243 /* Populate and write the frame header */
42244 nDbsize = (isCommit && p->pDirty==0) ? nTruncate : 0;
42245 #if defined(SQLITE_HAS_CODEC)
42246 if( (pData = sqlite3PagerCodec(p))==0 ) return SQLITE_NOMEM;
@@ -42192,10 +42276,11 @@
42276 if( (pData = sqlite3PagerCodec(pLast))==0 ) return SQLITE_NOMEM;
42277 #else
42278 pData = pLast->pData;
42279 #endif
42280 walEncodeFrame(pWal, pLast->pgno, nTruncate, pData, aFrame);
42281 /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
42282 rc = sqlite3OsWrite(pWal->pWalFd, aFrame, sizeof(aFrame), iOffset);
42283 if( rc!=SQLITE_OK ){
42284 return rc;
42285 }
42286 iOffset += WAL_FRAME_HDRSIZE;
@@ -63501,15 +63586,10 @@
63586 ** operation. No IO is required.
63587 **
63588 ** If changing into or out of WAL mode the procedure is more complicated.
63589 **
63590 ** Write a string containing the final journal-mode to register P2.
 
 
 
 
 
63591 */
63592 case OP_JournalMode: { /* out2-prerelease */
63593 #if 0 /* local variables moved into u.cd */
63594 Btree *pBt; /* Btree to change journal mode of */
63595 Pager *pPager; /* Pager associated with pBt */
@@ -63605,11 +63685,10 @@
63685 }
63686 }
63687 #endif /* ifndef SQLITE_OMIT_WAL */
63688
63689 if( rc ){
 
63690 u.cd.eNew = u.cd.eOld;
63691 }
63692 u.cd.eNew = sqlite3PagerSetJournalMode(u.cd.pPager, u.cd.eNew);
63693
63694 pOut = &aMem[pOp->p2];
@@ -63617,11 +63696,11 @@
63696 pOut->z = (char *)sqlite3JournalModename(u.cd.eNew);
63697 pOut->n = sqlite3Strlen30(pOut->z);
63698 pOut->enc = SQLITE_UTF8;
63699 sqlite3VdbeChangeEncoding(pOut, encoding);
63700 break;
63701 };
63702 #endif /* SQLITE_OMIT_PRAGMA */
63703
63704 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
63705 /* Opcode: Vacuum * * * * *
63706 **
@@ -71830,12 +71909,10 @@
71909 "attached databases must use the same text encoding as main database");
71910 rc = SQLITE_ERROR;
71911 }
71912 pPager = sqlite3BtreePager(aNew->pBt);
71913 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
 
 
71914 sqlite3BtreeSecureDelete(aNew->pBt,
71915 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
71916 }
71917 aNew->safety_level = 3;
71918 aNew->zName = sqlite3DbStrDup(db, zName);
@@ -72027,21 +72104,10 @@
72104 sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-pFunc->nArg, regArgs+3);
72105 assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg );
72106 sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg));
72107 sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF);
72108
 
 
 
 
 
 
 
 
 
 
 
72109 /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
72110 ** statement only). For DETACH, set it to false (expire all existing
72111 ** statements).
72112 */
72113 sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH));
@@ -75914,11 +75980,10 @@
75980 assert( db->aDb[1].pSchema );
75981 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
75982 db->mallocFailed = 1;
75983 return 1;
75984 }
 
75985 }
75986 return 0;
75987 }
75988
75989 /*
@@ -83583,58 +83648,49 @@
83648 ** PRAGMA [database.]journal_mode
83649 ** PRAGMA [database.]journal_mode =
83650 ** (delete|persist|off|truncate|memory|wal|off)
83651 */
83652 if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){
83653 int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
83654 int ii; /* Loop counter */
83655
83656 /* Force the schema to be loaded on all databases. This cases all
83657 ** database files to be opened and the journal_modes set. */
83658 if( sqlite3ReadSchema(pParse) ){
83659 goto pragma_out;
83660 }
83661
83662 sqlite3VdbeSetNumCols(v, 1);
83663 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);
83664
83665 if( zRight==0 ){
83666 /* If there is no "=MODE" part of the pragma, do a query for the
83667 ** current mode */
83668 eMode = PAGER_JOURNALMODE_QUERY;
83669 }else{
83670 const char *zMode;
83671 int n = sqlite3Strlen30(zRight);
83672 for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){
83673 if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break;
83674 }
83675 if( !zMode ){
83676 /* If the "=MODE" part does not match any known journal mode,
83677 ** then do a query */
83678 eMode = PAGER_JOURNALMODE_QUERY;
83679 }
83680 }
83681 if( eMode==PAGER_JOURNALMODE_QUERY && pId2->n==0 ){
83682 /* Convert "PRAGMA journal_mode" into "PRAGMA main.journal_mode" */
83683 iDb = 0;
83684 pId2->n = 1;
83685 }
83686 for(ii=db->nDb-1; ii>=0; ii--){
83687 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
83688 sqlite3VdbeUsesBtree(v, ii);
83689 sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode);
83690 }
83691 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83692 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
83693 }else
83694
83695 /*
83696 ** PRAGMA [database.]journal_size_limit
@@ -84648,25 +84704,28 @@
84704 ** or executed. All the parser does is build the internal data
84705 ** structures that describe the table, index, or view.
84706 */
84707 int rc;
84708 sqlite3_stmt *pStmt;
84709 TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
84710
84711 assert( db->init.busy );
84712 db->init.iDb = iDb;
84713 db->init.newTnum = atoi(argv[1]);
84714 db->init.orphanTrigger = 0;
84715 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
84716 rc = db->errCode;
84717 assert( (rc&0xFF)==(rcp&0xFF) );
84718 db->init.iDb = 0;
84719 if( SQLITE_OK!=rc ){
84720 if( db->init.orphanTrigger ){
84721 assert( iDb==1 );
84722 }else{
84723 pData->rc = rc;
84724 if( rc==SQLITE_NOMEM ){
84725 db->mallocFailed = 1;
84726 }else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ){
84727 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
84728 }
84729 }
84730 }
84731 sqlite3_finalize(pStmt);
@@ -104123,20 +104182,18 @@
104182 sqlite3_mutex_leave(db->mutex);
104183 return SQLITE_OK;
104184 }
104185 #endif /* SQLITE_OMIT_UTF16 */
104186
 
104187 #ifndef SQLITE_OMIT_DEPRECATED
104188 /*
104189 ** This function is now an anachronism. It used to be used to recover from a
104190 ** malloc() failure, but SQLite now does this automatically.
104191 */
104192 SQLITE_API int sqlite3_global_recover(void){
104193 return SQLITE_OK;
104194 }
 
104195 #endif
104196
104197 /*
104198 ** Test to see whether or not the database connection is in autocommit
104199 ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
104200
+12 -6
--- 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.7.0"
111111
#define SQLITE_VERSION_NUMBER 3007000
112
-#define SQLITE_SOURCE_ID "2010-07-03 13:59:01 3b20ad03be55613d922d81aec5313327bf4098b9"
112
+#define SQLITE_SOURCE_ID "2010-07-08 17:40:38 e396184cd3bdb96e29ac33af5d1f631cac553341"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -830,20 +830,27 @@
830830
** is also passed as a parameter to both methods. If the output buffer
831831
** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
832832
** handled as a fatal error by SQLite, vfs implementations should endeavor
833833
** to prevent this by setting mxPathname to a sufficiently large value.
834834
**
835
-** The xRandomness(), xSleep(), and xCurrentTime() interfaces
836
-** are not strictly a part of the filesystem, but they are
835
+** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
836
+** interfaces are not strictly a part of the filesystem, but they are
837837
** included in the VFS structure for completeness.
838838
** The xRandomness() function attempts to return nBytes bytes
839839
** of good-quality randomness into zOut. The return value is
840840
** the actual number of bytes of randomness obtained.
841841
** The xSleep() method causes the calling thread to sleep for at
842842
** least the number of microseconds given. The xCurrentTime()
843
-** method returns a Julian Day Number for the current date and time.
844
-**
843
+** method returns a Julian Day Number for the current date and time as
844
+** a floating point value.
845
+** The xCurrentTimeInt64() method returns, as an integer, the Julian
846
+** Day Number multipled by 86400000 (the number of milliseconds in
847
+** a 24-hour day).
848
+** ^SQLite will use the xCurrentTimeInt64() method to get the current
849
+** date and time if that method is available (if iVersion is 2 or
850
+** greater and the function pointer is not NULL) and will fall back
851
+** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
845852
*/
846853
typedef struct sqlite3_vfs sqlite3_vfs;
847854
struct sqlite3_vfs {
848855
int iVersion; /* Structure version number (currently 2) */
849856
int szOsFile; /* Size of subclassed sqlite3_file */
@@ -866,11 +873,10 @@
866873
int (*xGetLastError)(sqlite3_vfs*, int, char *);
867874
/*
868875
** The methods above are in version 1 of the sqlite_vfs object
869876
** definition. Those that follow are added in version 2 or later
870877
*/
871
- int (*xRename)(sqlite3_vfs*, const char *zOld, const char *zNew, int dirSync);
872878
int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
873879
/*
874880
** The methods above are in versions 1 and 2 of the sqlite_vfs object.
875881
** New fields may be appended in figure versions. The iVersion
876882
** value will increment whenever this happens.
877883
--- 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.7.0"
111 #define SQLITE_VERSION_NUMBER 3007000
112 #define SQLITE_SOURCE_ID "2010-07-03 13:59:01 3b20ad03be55613d922d81aec5313327bf4098b9"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -830,20 +830,27 @@
830 ** is also passed as a parameter to both methods. If the output buffer
831 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
832 ** handled as a fatal error by SQLite, vfs implementations should endeavor
833 ** to prevent this by setting mxPathname to a sufficiently large value.
834 **
835 ** The xRandomness(), xSleep(), and xCurrentTime() interfaces
836 ** are not strictly a part of the filesystem, but they are
837 ** included in the VFS structure for completeness.
838 ** The xRandomness() function attempts to return nBytes bytes
839 ** of good-quality randomness into zOut. The return value is
840 ** the actual number of bytes of randomness obtained.
841 ** The xSleep() method causes the calling thread to sleep for at
842 ** least the number of microseconds given. The xCurrentTime()
843 ** method returns a Julian Day Number for the current date and time.
844 **
 
 
 
 
 
 
 
845 */
846 typedef struct sqlite3_vfs sqlite3_vfs;
847 struct sqlite3_vfs {
848 int iVersion; /* Structure version number (currently 2) */
849 int szOsFile; /* Size of subclassed sqlite3_file */
@@ -866,11 +873,10 @@
866 int (*xGetLastError)(sqlite3_vfs*, int, char *);
867 /*
868 ** The methods above are in version 1 of the sqlite_vfs object
869 ** definition. Those that follow are added in version 2 or later
870 */
871 int (*xRename)(sqlite3_vfs*, const char *zOld, const char *zNew, int dirSync);
872 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
873 /*
874 ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
875 ** New fields may be appended in figure versions. The iVersion
876 ** value will increment whenever this happens.
877
--- 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.7.0"
111 #define SQLITE_VERSION_NUMBER 3007000
112 #define SQLITE_SOURCE_ID "2010-07-08 17:40:38 e396184cd3bdb96e29ac33af5d1f631cac553341"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -830,20 +830,27 @@
830 ** is also passed as a parameter to both methods. If the output buffer
831 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
832 ** handled as a fatal error by SQLite, vfs implementations should endeavor
833 ** to prevent this by setting mxPathname to a sufficiently large value.
834 **
835 ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
836 ** interfaces are not strictly a part of the filesystem, but they are
837 ** included in the VFS structure for completeness.
838 ** The xRandomness() function attempts to return nBytes bytes
839 ** of good-quality randomness into zOut. The return value is
840 ** the actual number of bytes of randomness obtained.
841 ** The xSleep() method causes the calling thread to sleep for at
842 ** least the number of microseconds given. The xCurrentTime()
843 ** method returns a Julian Day Number for the current date and time as
844 ** a floating point value.
845 ** The xCurrentTimeInt64() method returns, as an integer, the Julian
846 ** Day Number multipled by 86400000 (the number of milliseconds in
847 ** a 24-hour day).
848 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
849 ** date and time if that method is available (if iVersion is 2 or
850 ** greater and the function pointer is not NULL) and will fall back
851 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
852 */
853 typedef struct sqlite3_vfs sqlite3_vfs;
854 struct sqlite3_vfs {
855 int iVersion; /* Structure version number (currently 2) */
856 int szOsFile; /* Size of subclassed sqlite3_file */
@@ -866,11 +873,10 @@
873 int (*xGetLastError)(sqlite3_vfs*, int, char *);
874 /*
875 ** The methods above are in version 1 of the sqlite_vfs object
876 ** definition. Those that follow are added in version 2 or later
877 */
 
878 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
879 /*
880 ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
881 ** New fields may be appended in figure versions. The iVersion
882 ** value will increment whenever this happens.
883
+24 -5
--- src/stat.c
+++ src/stat.c
@@ -61,33 +61,52 @@
6161
a = t/fsize;
6262
@ %d(a):%d(b)
6363
@ </td></tr>
6464
}
6565
@ <tr><th>Number&nbsp;Of&nbsp;Check-ins:</th><td>
66
- n = db_int(0, "SELECT count(distinct mid) FROM mlink");
66
+ n = db_int(0, "SELECT count(distinct mid) FROM mlink /*scan*/");
6767
@ %d(n)
6868
@ </td></tr>
6969
@ <tr><th>Number&nbsp;Of&nbsp;Files:</th><td>
70
- n = db_int(0, "SELECT count(*) FROM filename");
70
+ n = db_int(0, "SELECT count(*) FROM filename /*scan*/");
7171
@ %d(n)
7272
@ </td></tr>
7373
@ <tr><th>Number&nbsp;Of&nbsp;Wiki&nbsp;Pages:</th><td>
74
- n = db_int(0, "SELECT count(*) FROM tag WHERE +tagname GLOB 'wiki-*'");
74
+ n = db_int(0, "SELECT count(*) FROM tag /*scan*/"
75
+ " WHERE +tagname GLOB 'wiki-*'");
7576
@ %d(n)
7677
@ </td></tr>
7778
@ <tr><th>Number&nbsp;Of&nbsp;Tickets:</th><td>
78
- n = db_int(0, "SELECT count(*) FROM tag WHERE +tagname GLOB 'tkt-*'");
79
+ n = db_int(0, "SELECT count(*) FROM tag /*scan*/"
80
+ " WHERE +tagname GLOB 'tkt-*'");
7981
@ %d(n)
8082
@ </td></tr>
8183
@ <tr><th>Duration&nbsp;Of&nbsp;Project:</th><td>
82
- n = db_int(0, "SELECT julianday('now') - (SELECT min(mtime) FROM event) + 0.99");
84
+ n = db_int(0, "SELECT julianday('now') - (SELECT min(mtime) FROM event)"
85
+ " + 0.99");
8386
@ %d(n) days
8487
@ </td></tr>
8588
@ <tr><th>Project&nbsp;ID:</th><td>
8689
@ %h(db_get("project-code",""))
8790
@ </td></tr>
8891
@ <tr><th>Server&nbsp;ID:</th><td>
8992
@ %h(db_get("server-code",""))
9093
@ </td></tr>
94
+
95
+ @ <tr><th>Fossil&nbsp;Version:</th><td>
96
+ @ %h(MANIFEST_DATE) %h(MANIFEST_VERSION)
97
+ @ </td></tr>
98
+ @ <tr><th>SQLite&nbsp;Version:</th><td>
99
+ @ %h(db_text(0, "SELECT substr(sqlite_source_id(),1,30)"))
100
+ @ (%h(SQLITE_VERSION))
101
+ @ </td></tr>
102
+ @ <tr><th>Database&nbsp;Stats:</th><td>
103
+ @ %d(db_int(0, "PRAGMA %s.page_count", g.zRepoDb)) pages,
104
+ @ %d(db_int(0, "PRAGMA %s.page_size", g.zRepoDb)) bytes/page,
105
+ @ %d(db_int(0, "PRAGMA %s.freelist_count", g.zRepoDb)) free pages,
106
+ @ %s(db_text(0, "PRAGMA %s.encoding", g.zRepoDb)),
107
+ @ %s(db_text(0, "PRAGMA %s.journal_mode", g.zRepoDb)) mode
108
+ @ </td></tr>
109
+
91110
@ </table></p>
92111
style_footer();
93112
}
94113
--- src/stat.c
+++ src/stat.c
@@ -61,33 +61,52 @@
61 a = t/fsize;
62 @ %d(a):%d(b)
63 @ </td></tr>
64 }
65 @ <tr><th>Number&nbsp;Of&nbsp;Check-ins:</th><td>
66 n = db_int(0, "SELECT count(distinct mid) FROM mlink");
67 @ %d(n)
68 @ </td></tr>
69 @ <tr><th>Number&nbsp;Of&nbsp;Files:</th><td>
70 n = db_int(0, "SELECT count(*) FROM filename");
71 @ %d(n)
72 @ </td></tr>
73 @ <tr><th>Number&nbsp;Of&nbsp;Wiki&nbsp;Pages:</th><td>
74 n = db_int(0, "SELECT count(*) FROM tag WHERE +tagname GLOB 'wiki-*'");
 
75 @ %d(n)
76 @ </td></tr>
77 @ <tr><th>Number&nbsp;Of&nbsp;Tickets:</th><td>
78 n = db_int(0, "SELECT count(*) FROM tag WHERE +tagname GLOB 'tkt-*'");
 
79 @ %d(n)
80 @ </td></tr>
81 @ <tr><th>Duration&nbsp;Of&nbsp;Project:</th><td>
82 n = db_int(0, "SELECT julianday('now') - (SELECT min(mtime) FROM event) + 0.99");
 
83 @ %d(n) days
84 @ </td></tr>
85 @ <tr><th>Project&nbsp;ID:</th><td>
86 @ %h(db_get("project-code",""))
87 @ </td></tr>
88 @ <tr><th>Server&nbsp;ID:</th><td>
89 @ %h(db_get("server-code",""))
90 @ </td></tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91 @ </table></p>
92 style_footer();
93 }
94
--- src/stat.c
+++ src/stat.c
@@ -61,33 +61,52 @@
61 a = t/fsize;
62 @ %d(a):%d(b)
63 @ </td></tr>
64 }
65 @ <tr><th>Number&nbsp;Of&nbsp;Check-ins:</th><td>
66 n = db_int(0, "SELECT count(distinct mid) FROM mlink /*scan*/");
67 @ %d(n)
68 @ </td></tr>
69 @ <tr><th>Number&nbsp;Of&nbsp;Files:</th><td>
70 n = db_int(0, "SELECT count(*) FROM filename /*scan*/");
71 @ %d(n)
72 @ </td></tr>
73 @ <tr><th>Number&nbsp;Of&nbsp;Wiki&nbsp;Pages:</th><td>
74 n = db_int(0, "SELECT count(*) FROM tag /*scan*/"
75 " WHERE +tagname GLOB 'wiki-*'");
76 @ %d(n)
77 @ </td></tr>
78 @ <tr><th>Number&nbsp;Of&nbsp;Tickets:</th><td>
79 n = db_int(0, "SELECT count(*) FROM tag /*scan*/"
80 " WHERE +tagname GLOB 'tkt-*'");
81 @ %d(n)
82 @ </td></tr>
83 @ <tr><th>Duration&nbsp;Of&nbsp;Project:</th><td>
84 n = db_int(0, "SELECT julianday('now') - (SELECT min(mtime) FROM event)"
85 " + 0.99");
86 @ %d(n) days
87 @ </td></tr>
88 @ <tr><th>Project&nbsp;ID:</th><td>
89 @ %h(db_get("project-code",""))
90 @ </td></tr>
91 @ <tr><th>Server&nbsp;ID:</th><td>
92 @ %h(db_get("server-code",""))
93 @ </td></tr>
94
95 @ <tr><th>Fossil&nbsp;Version:</th><td>
96 @ %h(MANIFEST_DATE) %h(MANIFEST_VERSION)
97 @ </td></tr>
98 @ <tr><th>SQLite&nbsp;Version:</th><td>
99 @ %h(db_text(0, "SELECT substr(sqlite_source_id(),1,30)"))
100 @ (%h(SQLITE_VERSION))
101 @ </td></tr>
102 @ <tr><th>Database&nbsp;Stats:</th><td>
103 @ %d(db_int(0, "PRAGMA %s.page_count", g.zRepoDb)) pages,
104 @ %d(db_int(0, "PRAGMA %s.page_size", g.zRepoDb)) bytes/page,
105 @ %d(db_int(0, "PRAGMA %s.freelist_count", g.zRepoDb)) free pages,
106 @ %s(db_text(0, "PRAGMA %s.encoding", g.zRepoDb)),
107 @ %s(db_text(0, "PRAGMA %s.journal_mode", g.zRepoDb)) mode
108 @ </td></tr>
109
110 @ </table></p>
111 style_footer();
112 }
113
+1 -1
--- src/sync.c
+++ src/sync.c
@@ -99,11 +99,11 @@
9999
if( db_get_boolean("auto-sync",1) ) configSync = CONFIGSET_SHUN;
100100
}else if( g.argc==3 ){
101101
zUrl = g.argv[2];
102102
}
103103
if( zUrl==0 ){
104
- if( urlOptional ) exit(0);
104
+ if( urlOptional ) fossil_exit(0);
105105
usage("URL");
106106
}
107107
url_parse(zUrl);
108108
if( !g.dontKeepUrl ){
109109
db_set("last-sync-url", g.urlCanonical, 0);
110110
--- src/sync.c
+++ src/sync.c
@@ -99,11 +99,11 @@
99 if( db_get_boolean("auto-sync",1) ) configSync = CONFIGSET_SHUN;
100 }else if( g.argc==3 ){
101 zUrl = g.argv[2];
102 }
103 if( zUrl==0 ){
104 if( urlOptional ) exit(0);
105 usage("URL");
106 }
107 url_parse(zUrl);
108 if( !g.dontKeepUrl ){
109 db_set("last-sync-url", g.urlCanonical, 0);
110
--- src/sync.c
+++ src/sync.c
@@ -99,11 +99,11 @@
99 if( db_get_boolean("auto-sync",1) ) configSync = CONFIGSET_SHUN;
100 }else if( g.argc==3 ){
101 zUrl = g.argv[2];
102 }
103 if( zUrl==0 ){
104 if( urlOptional ) fossil_exit(0);
105 usage("URL");
106 }
107 url_parse(zUrl);
108 if( !g.dontKeepUrl ){
109 db_set("last-sync-url", g.urlCanonical, 0);
110

Keyboard Shortcuts

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