Fossil SCM

Merge from trunk.

michael 2010-10-05 14:40 UTC ttmrichter-skins merge
Commit 029448a394340305c963e2b4f4a9f926c608e8bd
+1 -3
--- src/add.c
+++ src/add.c
@@ -36,20 +36,18 @@
3636
Blob pathname;
3737
const char *zPath;
3838
3939
file_tree_name(zName, &pathname, 1);
4040
zPath = blob_str(&pathname);
41
- if( strcmp(zPath, "manifest")==0
42
- || strcmp(zPath, "_FOSSIL_")==0
41
+ if( strcmp(zPath, "_FOSSIL_")==0
4342
|| strcmp(zPath, "_FOSSIL_-journal")==0
4443
|| strcmp(zPath, "_FOSSIL_-wal")==0
4544
|| strcmp(zPath, "_FOSSIL_-shm")==0
4645
|| strcmp(zPath, ".fos")==0
4746
|| strcmp(zPath, ".fos-journal")==0
4847
|| strcmp(zPath, ".fos-wal")==0
4948
|| strcmp(zPath, ".fos-shm")==0
50
- || strcmp(zPath, "manifest.uuid")==0
5149
|| blob_compare(&pathname, pOmit)==0
5250
){
5351
fossil_warning("cannot add %s", zPath);
5452
}else{
5553
if( !file_is_simple_pathname(zPath) ){
5654
--- src/add.c
+++ src/add.c
@@ -36,20 +36,18 @@
36 Blob pathname;
37 const char *zPath;
38
39 file_tree_name(zName, &pathname, 1);
40 zPath = blob_str(&pathname);
41 if( strcmp(zPath, "manifest")==0
42 || strcmp(zPath, "_FOSSIL_")==0
43 || strcmp(zPath, "_FOSSIL_-journal")==0
44 || strcmp(zPath, "_FOSSIL_-wal")==0
45 || strcmp(zPath, "_FOSSIL_-shm")==0
46 || strcmp(zPath, ".fos")==0
47 || strcmp(zPath, ".fos-journal")==0
48 || strcmp(zPath, ".fos-wal")==0
49 || strcmp(zPath, ".fos-shm")==0
50 || strcmp(zPath, "manifest.uuid")==0
51 || blob_compare(&pathname, pOmit)==0
52 ){
53 fossil_warning("cannot add %s", zPath);
54 }else{
55 if( !file_is_simple_pathname(zPath) ){
56
--- src/add.c
+++ src/add.c
@@ -36,20 +36,18 @@
36 Blob pathname;
37 const char *zPath;
38
39 file_tree_name(zName, &pathname, 1);
40 zPath = blob_str(&pathname);
41 if( strcmp(zPath, "_FOSSIL_")==0
 
42 || strcmp(zPath, "_FOSSIL_-journal")==0
43 || strcmp(zPath, "_FOSSIL_-wal")==0
44 || strcmp(zPath, "_FOSSIL_-shm")==0
45 || strcmp(zPath, ".fos")==0
46 || strcmp(zPath, ".fos-journal")==0
47 || strcmp(zPath, ".fos-wal")==0
48 || strcmp(zPath, ".fos-shm")==0
 
49 || blob_compare(&pathname, pOmit)==0
50 ){
51 fossil_warning("cannot add %s", zPath);
52 }else{
53 if( !file_is_simple_pathname(zPath) ){
54
+21 -21
--- src/attach.c
+++ src/attach.c
@@ -270,25 +270,25 @@
270270
db_end_transaction(0);
271271
cgi_redirect(zFrom);
272272
}
273273
style_header("Add Attachment");
274274
@ <h2>Add Attachment To %s(zTargetType)</h2>
275
- @ <form action="%s(g.zBaseURL)/attachadd" method="POST"
276
- @ enctype="multipart/form-data">
275
+ @ <form action="%s(g.zBaseURL)/attachadd" method="post"
276
+ @ enctype="multipart/form-data"><div>
277277
@ File to Attach:
278
- @ <input type="file" name="f" size="60"><br />
278
+ @ <input type="file" name="f" size="60" /><br />
279279
@ Description:<br />
280
- @ <textarea name="comment" cols=80 rows=5 wrap="virtual"></textarea><br />
280
+ @ <textarea name="comment" cols="80" rows="5" wrap="virtual"></textarea><br />
281281
if( zTkt ){
282
- @ <input type="hidden" name="tkt" value="%h(zTkt)">
283
- }else{
284
- @ <input type="hidden" name="page" value="%h(zPage)">
285
- }
286
- @ <input type="hidden" name="from" value="%h(zFrom)">
287
- @ <input type="submit" name="ok" value="Add Attachment">
288
- @ <input type="submit" name="cancel" value="Cancel">
289
- @ </form>
282
+ @ <input type="hidden" name="tkt" value="%h(zTkt)" />
283
+ }else{
284
+ @ <input type="hidden" name="page" value="%h(zPage)" />
285
+ }
286
+ @ <input type="hidden" name="from" value="%h(zFrom)" />
287
+ @ <input type="submit" name="ok" value="Add Attachment" />
288
+ @ <input type="submit" name="cancel" value="Cancel" />
289
+ @ </div></form>
290290
style_footer();
291291
}
292292
293293
294294
/*
@@ -349,21 +349,21 @@
349349
manifest_crosslink(rid, &manifest);
350350
db_end_transaction(0);
351351
cgi_redirect(zFrom);
352352
}
353353
style_header("Delete Attachment");
354
- @ <form action="%s(g.zBaseURL)/attachdelete" method="POST">
354
+ @ <form action="%s(g.zBaseURL)/attachdelete" method="post"><div>
355355
@ <p>Confirm that you want to delete the attachment named
356
- @ "%h(zFile)" on %s(zTkt?"ticket":"wiki page") %h(zTarget):<br />
356
+ @ "%h(zFile)" on %s(zTkt?"ticket":"wiki page") %h(zTarget):<br /></p>
357357
if( zTkt ){
358
- @ <input type="hidden" name="tkt" value="%h(zTkt)">
358
+ @ <input type="hidden" name="tkt" value="%h(zTkt)" />
359359
}else{
360
- @ <input type="hidden" name="page" value="%h(zPage)">
360
+ @ <input type="hidden" name="page" value="%h(zPage)" />
361361
}
362
- @ <input type="hidden" name="file" value="%h(zFile)">
363
- @ <input type="hidden" name="from" value="%h(zFrom)">
364
- @ <input type="submit" name="confirm" value="Delete">
365
- @ <input type="submit" name="cancel" value="Cancel">
366
- @ </form>
362
+ @ <input type="hidden" name="file" value="%h(zFile)" />
363
+ @ <input type="hidden" name="from" value="%h(zFrom)" />
364
+ @ <input type="submit" name="confirm" value="Delete" />
365
+ @ <input type="submit" name="cancel" value="Cancel" />
366
+ @ </div></form>
367367
style_footer();
368368
369369
}
370370
--- src/attach.c
+++ src/attach.c
@@ -270,25 +270,25 @@
270 db_end_transaction(0);
271 cgi_redirect(zFrom);
272 }
273 style_header("Add Attachment");
274 @ <h2>Add Attachment To %s(zTargetType)</h2>
275 @ <form action="%s(g.zBaseURL)/attachadd" method="POST"
276 @ enctype="multipart/form-data">
277 @ File to Attach:
278 @ <input type="file" name="f" size="60"><br />
279 @ Description:<br />
280 @ <textarea name="comment" cols=80 rows=5 wrap="virtual"></textarea><br />
281 if( zTkt ){
282 @ <input type="hidden" name="tkt" value="%h(zTkt)">
283 }else{
284 @ <input type="hidden" name="page" value="%h(zPage)">
285 }
286 @ <input type="hidden" name="from" value="%h(zFrom)">
287 @ <input type="submit" name="ok" value="Add Attachment">
288 @ <input type="submit" name="cancel" value="Cancel">
289 @ </form>
290 style_footer();
291 }
292
293
294 /*
@@ -349,21 +349,21 @@
349 manifest_crosslink(rid, &manifest);
350 db_end_transaction(0);
351 cgi_redirect(zFrom);
352 }
353 style_header("Delete Attachment");
354 @ <form action="%s(g.zBaseURL)/attachdelete" method="POST">
355 @ <p>Confirm that you want to delete the attachment named
356 @ "%h(zFile)" on %s(zTkt?"ticket":"wiki page") %h(zTarget):<br />
357 if( zTkt ){
358 @ <input type="hidden" name="tkt" value="%h(zTkt)">
359 }else{
360 @ <input type="hidden" name="page" value="%h(zPage)">
361 }
362 @ <input type="hidden" name="file" value="%h(zFile)">
363 @ <input type="hidden" name="from" value="%h(zFrom)">
364 @ <input type="submit" name="confirm" value="Delete">
365 @ <input type="submit" name="cancel" value="Cancel">
366 @ </form>
367 style_footer();
368
369 }
370
--- src/attach.c
+++ src/attach.c
@@ -270,25 +270,25 @@
270 db_end_transaction(0);
271 cgi_redirect(zFrom);
272 }
273 style_header("Add Attachment");
274 @ <h2>Add Attachment To %s(zTargetType)</h2>
275 @ <form action="%s(g.zBaseURL)/attachadd" method="post"
276 @ enctype="multipart/form-data"><div>
277 @ File to Attach:
278 @ <input type="file" name="f" size="60" /><br />
279 @ Description:<br />
280 @ <textarea name="comment" cols="80" rows="5" wrap="virtual"></textarea><br />
281 if( zTkt ){
282 @ <input type="hidden" name="tkt" value="%h(zTkt)" />
283 }else{
284 @ <input type="hidden" name="page" value="%h(zPage)" />
285 }
286 @ <input type="hidden" name="from" value="%h(zFrom)" />
287 @ <input type="submit" name="ok" value="Add Attachment" />
288 @ <input type="submit" name="cancel" value="Cancel" />
289 @ </div></form>
290 style_footer();
291 }
292
293
294 /*
@@ -349,21 +349,21 @@
349 manifest_crosslink(rid, &manifest);
350 db_end_transaction(0);
351 cgi_redirect(zFrom);
352 }
353 style_header("Delete Attachment");
354 @ <form action="%s(g.zBaseURL)/attachdelete" method="post"><div>
355 @ <p>Confirm that you want to delete the attachment named
356 @ "%h(zFile)" on %s(zTkt?"ticket":"wiki page") %h(zTarget):<br /></p>
357 if( zTkt ){
358 @ <input type="hidden" name="tkt" value="%h(zTkt)" />
359 }else{
360 @ <input type="hidden" name="page" value="%h(zPage)" />
361 }
362 @ <input type="hidden" name="file" value="%h(zFile)" />
363 @ <input type="hidden" name="from" value="%h(zFrom)" />
364 @ <input type="submit" name="confirm" value="Delete" />
365 @ <input type="submit" name="cancel" value="Cancel" />
366 @ </div></form>
367 style_footer();
368
369 }
370
+1 -1
--- src/blob.c
+++ src/blob.c
@@ -72,11 +72,11 @@
7272
7373
/*
7474
** We find that the built-in isspace() function does not work for
7575
** some international character sets. So here is a substitute.
7676
*/
77
-static int blob_isspace(char c){
77
+int blob_isspace(char c){
7878
return c==' ' || (c<='\r' && c>='\t');
7979
}
8080
8181
/*
8282
** COMMAND: test-isspace
8383
--- src/blob.c
+++ src/blob.c
@@ -72,11 +72,11 @@
72
73 /*
74 ** We find that the built-in isspace() function does not work for
75 ** some international character sets. So here is a substitute.
76 */
77 static int blob_isspace(char c){
78 return c==' ' || (c<='\r' && c>='\t');
79 }
80
81 /*
82 ** COMMAND: test-isspace
83
--- src/blob.c
+++ src/blob.c
@@ -72,11 +72,11 @@
72
73 /*
74 ** We find that the built-in isspace() function does not work for
75 ** some international character sets. So here is a substitute.
76 */
77 int blob_isspace(char c){
78 return c==' ' || (c<='\r' && c>='\t');
79 }
80
81 /*
82 ** COMMAND: test-isspace
83
+6 -2
--- src/branch.c
+++ src/branch.c
@@ -38,13 +38,17 @@
3838
const char *zColor; /* Color of the new branch */
3939
Blob branch; /* manifest for the new branch */
4040
Blob parent; /* root check-in manifest */
4141
Manifest mParent; /* Parsed parent manifest */
4242
Blob mcksum; /* Self-checksum on the manifest */
43
+ const char *zDateOvrd; /* Override date string */
44
+ const char *zUserOvrd; /* Override user name */
4345
4446
noSign = find_option("nosign","",0)!=0;
4547
zColor = find_option("bgcolor","c",1);
48
+ zDateOvrd = find_option("date-override",0,1);
49
+ zUserOvrd = find_option("user-override",0,1);
4650
verify_all_options();
4751
if( g.argc<5 ){
4852
usage("new BRANCH-NAME CHECK-IN ?-bgcolor COLOR?");
4953
}
5054
db_find_and_open_repository(1);
@@ -72,11 +76,11 @@
7276
7377
/* Create a manifest for the new branch */
7478
blob_zero(&branch);
7579
zComment = mprintf("Create new branch named \"%h\"", zBranch);
7680
blob_appendf(&branch, "C %F\n", zComment);
77
- zDate = db_text(0, "SELECT datetime('now')");
81
+ zDate = date_in_standard_format(zDateOvrd ? zDateOvrd : "now");
7882
zDate[10] = 'T';
7983
blob_appendf(&branch, "D %s\n", zDate);
8084
8185
/* Copy all of the content from the parent into the branch */
8286
content_get(rootid, &parent);
@@ -120,11 +124,11 @@
120124
const char *zTag = db_column_text(&q, 0);
121125
blob_appendf(&branch, "T -%F *\n", zTag);
122126
}
123127
db_finalize(&q);
124128
125
- blob_appendf(&branch, "U %F\n", g.zLogin);
129
+ blob_appendf(&branch, "U %F\n", zUserOvrd ? zUserOvrd : g.zLogin);
126130
md5sum_blob(&branch, &mcksum);
127131
blob_appendf(&branch, "Z %b\n", &mcksum);
128132
if( !noSign && clearsign(&branch, &branch) ){
129133
Blob ans;
130134
blob_zero(&ans);
131135
--- src/branch.c
+++ src/branch.c
@@ -38,13 +38,17 @@
38 const char *zColor; /* Color of the new branch */
39 Blob branch; /* manifest for the new branch */
40 Blob parent; /* root check-in manifest */
41 Manifest mParent; /* Parsed parent manifest */
42 Blob mcksum; /* Self-checksum on the manifest */
 
 
43
44 noSign = find_option("nosign","",0)!=0;
45 zColor = find_option("bgcolor","c",1);
 
 
46 verify_all_options();
47 if( g.argc<5 ){
48 usage("new BRANCH-NAME CHECK-IN ?-bgcolor COLOR?");
49 }
50 db_find_and_open_repository(1);
@@ -72,11 +76,11 @@
72
73 /* Create a manifest for the new branch */
74 blob_zero(&branch);
75 zComment = mprintf("Create new branch named \"%h\"", zBranch);
76 blob_appendf(&branch, "C %F\n", zComment);
77 zDate = db_text(0, "SELECT datetime('now')");
78 zDate[10] = 'T';
79 blob_appendf(&branch, "D %s\n", zDate);
80
81 /* Copy all of the content from the parent into the branch */
82 content_get(rootid, &parent);
@@ -120,11 +124,11 @@
120 const char *zTag = db_column_text(&q, 0);
121 blob_appendf(&branch, "T -%F *\n", zTag);
122 }
123 db_finalize(&q);
124
125 blob_appendf(&branch, "U %F\n", g.zLogin);
126 md5sum_blob(&branch, &mcksum);
127 blob_appendf(&branch, "Z %b\n", &mcksum);
128 if( !noSign && clearsign(&branch, &branch) ){
129 Blob ans;
130 blob_zero(&ans);
131
--- src/branch.c
+++ src/branch.c
@@ -38,13 +38,17 @@
38 const char *zColor; /* Color of the new branch */
39 Blob branch; /* manifest for the new branch */
40 Blob parent; /* root check-in manifest */
41 Manifest mParent; /* Parsed parent manifest */
42 Blob mcksum; /* Self-checksum on the manifest */
43 const char *zDateOvrd; /* Override date string */
44 const char *zUserOvrd; /* Override user name */
45
46 noSign = find_option("nosign","",0)!=0;
47 zColor = find_option("bgcolor","c",1);
48 zDateOvrd = find_option("date-override",0,1);
49 zUserOvrd = find_option("user-override",0,1);
50 verify_all_options();
51 if( g.argc<5 ){
52 usage("new BRANCH-NAME CHECK-IN ?-bgcolor COLOR?");
53 }
54 db_find_and_open_repository(1);
@@ -72,11 +76,11 @@
76
77 /* Create a manifest for the new branch */
78 blob_zero(&branch);
79 zComment = mprintf("Create new branch named \"%h\"", zBranch);
80 blob_appendf(&branch, "C %F\n", zComment);
81 zDate = date_in_standard_format(zDateOvrd ? zDateOvrd : "now");
82 zDate[10] = 'T';
83 blob_appendf(&branch, "D %s\n", zDate);
84
85 /* Copy all of the content from the parent into the branch */
86 content_get(rootid, &parent);
@@ -120,11 +124,11 @@
124 const char *zTag = db_column_text(&q, 0);
125 blob_appendf(&branch, "T -%F *\n", zTag);
126 }
127 db_finalize(&q);
128
129 blob_appendf(&branch, "U %F\n", zUserOvrd ? zUserOvrd : g.zLogin);
130 md5sum_blob(&branch, &mcksum);
131 blob_appendf(&branch, "Z %b\n", &mcksum);
132 if( !noSign && clearsign(&branch, &branch) ){
133 Blob ans;
134 blob_zero(&ans);
135
+13 -5
--- src/browse.c
+++ src/browse.c
@@ -106,10 +106,11 @@
106106
int cnt, i;
107107
char *zPrefix;
108108
Stmt q;
109109
const char *zCI = P("ci");
110110
int rid = 0;
111
+ char *zUuid = 0;
111112
Blob content;
112113
Blob dirname;
113114
Manifest m;
114115
const char *zSubdirLink;
115116
@@ -120,16 +121,24 @@
120121
pathelementFunc, 0, 0);
121122
122123
/* If the name= parameter is an empty string, make it a NULL pointer */
123124
if( zD && strlen(zD)==0 ){ zD = 0; }
124125
125
- /* If a specific check-in is requested, fetch and parse it. */
126
- if( zCI && (rid = name_to_rid(zCI))!=0 && content_get(rid, &content) ){
127
- if( !manifest_parse(&m, &content) || m.type!=CFTYPE_MANIFEST ){
128
- zCI = 0;
126
+ /* If a specific check-in is requested, fetch and parse it. If the
127
+ ** specific check-in does not exist, clear zCI. zCI==0 will cause all
128
+ ** files from all check-ins to be displayed.
129
+ */
130
+ if( zCI ){
131
+ if( (rid = name_to_rid(zCI))==0 || content_get(rid, &content)==0 ){
132
+ zCI = 0; /* No artifact named zCI exists */
133
+ }else if( !manifest_parse(&m, &content) || m.type!=CFTYPE_MANIFEST ){
134
+ zCI = 0; /* The artifact exists but is not a manifest */
135
+ }else{
136
+ zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
129137
}
130138
}
139
+
131140
132141
/* Compute the title of the page */
133142
blob_zero(&dirname);
134143
if( zD ){
135144
blob_append(&dirname, "in directory ", -1);
@@ -138,11 +147,10 @@
138147
}else{
139148
blob_append(&dirname, "in the top-level directory", -1);
140149
zPrefix = "";
141150
}
142151
if( zCI ){
143
- char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
144152
char zShort[20];
145153
memcpy(zShort, zUuid, 10);
146154
zShort[10] = 0;
147155
@ <h2>Files of check-in [<a href="vinfo?name=%T(zUuid)">%s(zShort)</a>]
148156
@ %s(blob_str(&dirname))</h2>
149157
--- src/browse.c
+++ src/browse.c
@@ -106,10 +106,11 @@
106 int cnt, i;
107 char *zPrefix;
108 Stmt q;
109 const char *zCI = P("ci");
110 int rid = 0;
 
111 Blob content;
112 Blob dirname;
113 Manifest m;
114 const char *zSubdirLink;
115
@@ -120,16 +121,24 @@
120 pathelementFunc, 0, 0);
121
122 /* If the name= parameter is an empty string, make it a NULL pointer */
123 if( zD && strlen(zD)==0 ){ zD = 0; }
124
125 /* If a specific check-in is requested, fetch and parse it. */
126 if( zCI && (rid = name_to_rid(zCI))!=0 && content_get(rid, &content) ){
127 if( !manifest_parse(&m, &content) || m.type!=CFTYPE_MANIFEST ){
128 zCI = 0;
 
 
 
 
 
 
 
129 }
130 }
 
131
132 /* Compute the title of the page */
133 blob_zero(&dirname);
134 if( zD ){
135 blob_append(&dirname, "in directory ", -1);
@@ -138,11 +147,10 @@
138 }else{
139 blob_append(&dirname, "in the top-level directory", -1);
140 zPrefix = "";
141 }
142 if( zCI ){
143 char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
144 char zShort[20];
145 memcpy(zShort, zUuid, 10);
146 zShort[10] = 0;
147 @ <h2>Files of check-in [<a href="vinfo?name=%T(zUuid)">%s(zShort)</a>]
148 @ %s(blob_str(&dirname))</h2>
149
--- src/browse.c
+++ src/browse.c
@@ -106,10 +106,11 @@
106 int cnt, i;
107 char *zPrefix;
108 Stmt q;
109 const char *zCI = P("ci");
110 int rid = 0;
111 char *zUuid = 0;
112 Blob content;
113 Blob dirname;
114 Manifest m;
115 const char *zSubdirLink;
116
@@ -120,16 +121,24 @@
121 pathelementFunc, 0, 0);
122
123 /* If the name= parameter is an empty string, make it a NULL pointer */
124 if( zD && strlen(zD)==0 ){ zD = 0; }
125
126 /* If a specific check-in is requested, fetch and parse it. If the
127 ** specific check-in does not exist, clear zCI. zCI==0 will cause all
128 ** files from all check-ins to be displayed.
129 */
130 if( zCI ){
131 if( (rid = name_to_rid(zCI))==0 || content_get(rid, &content)==0 ){
132 zCI = 0; /* No artifact named zCI exists */
133 }else if( !manifest_parse(&m, &content) || m.type!=CFTYPE_MANIFEST ){
134 zCI = 0; /* The artifact exists but is not a manifest */
135 }else{
136 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
137 }
138 }
139
140
141 /* Compute the title of the page */
142 blob_zero(&dirname);
143 if( zD ){
144 blob_append(&dirname, "in directory ", -1);
@@ -138,11 +147,10 @@
147 }else{
148 blob_append(&dirname, "in the top-level directory", -1);
149 zPrefix = "";
150 }
151 if( zCI ){
 
152 char zShort[20];
153 memcpy(zShort, zUuid, 10);
154 zShort[10] = 0;
155 @ <h2>Files of check-in [<a href="vinfo?name=%T(zUuid)">%s(zShort)</a>]
156 @ %s(blob_str(&dirname))</h2>
157
+3
--- src/cgi.c
+++ src/cgi.c
@@ -42,10 +42,13 @@
4242
#endif
4343
#include <time.h>
4444
#include <stdio.h>
4545
#include <stdlib.h>
4646
#include <unistd.h>
47
+#if defined (__POCC__)
48
+# undef INTERFACE
49
+#endif
4750
#include "cgi.h"
4851
4952
#if INTERFACE
5053
/*
5154
** Shortcuts for cgi_parameter. P("x") returns the value of query parameter
5255
--- src/cgi.c
+++ src/cgi.c
@@ -42,10 +42,13 @@
42 #endif
43 #include <time.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <unistd.h>
 
 
 
47 #include "cgi.h"
48
49 #if INTERFACE
50 /*
51 ** Shortcuts for cgi_parameter. P("x") returns the value of query parameter
52
--- src/cgi.c
+++ src/cgi.c
@@ -42,10 +42,13 @@
42 #endif
43 #include <time.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <unistd.h>
47 #if defined (__POCC__)
48 # undef INTERFACE
49 #endif
50 #include "cgi.h"
51
52 #if INTERFACE
53 /*
54 ** Shortcuts for cgi_parameter. P("x") returns the value of query parameter
55
+40 -11
--- src/checkin.c
+++ src/checkin.c
@@ -535,10 +535,23 @@
535535
assert( strlen(zDate)==19 );
536536
assert( zDate[10]==' ' );
537537
zDate[10] = 'T';
538538
return zDate;
539539
}
540
+
541
+/*
542
+** Return TRUE (non-zero) if a file named "zFilename" exists in
543
+** the checkout identified by vid.
544
+**
545
+** The original purpose of this routine was to check for the presence of
546
+** a "checked-in" file named "manifest" or "manifest.uuid" so as to avoid
547
+** overwriting that file with automatically generated files.
548
+*/
549
+int file_exists_in_checkout(int vid, const char *zFilename){
550
+ return db_exists("SELECT 1 FROM vfile WHERE vid=%d AND pathname=%Q",
551
+ vid, zFilename);
552
+}
540553
541554
/*
542555
** COMMAND: ci
543556
** COMMAND: commit
544557
**
@@ -631,10 +644,22 @@
631644
** Autosync if autosync is enabled and this is not a private check-in.
632645
*/
633646
if( !g.markPrivate ){
634647
autosync(AUTOSYNC_PULL);
635648
}
649
+
650
+ /* Require confirmation to continue with the check-in if there is
651
+ ** clock skew
652
+ */
653
+ if( g.clockSkewSeen ){
654
+ Blob ans;
655
+ blob_zero(&ans);
656
+ prompt_user("continue in spite of time skew (y/N)? ", &ans);
657
+ if( blob_str(&ans)[0]!='y' ){
658
+ fossil_exit(1);
659
+ }
660
+ }
636661
637662
/* There are two ways this command may be executed. If there are
638663
** no arguments following the word "commit", then all modified files
639664
** in the checked out directory are committed. If one or more arguments
640665
** follows "commit", then only those files are committed.
@@ -844,38 +869,42 @@
844869
db_finalize(&q);
845870
}
846871
blob_appendf(&manifest, "U %F\n", zUserOvrd ? zUserOvrd : g.zLogin);
847872
md5sum_blob(&manifest, &mcksum);
848873
blob_appendf(&manifest, "Z %b\n", &mcksum);
849
- zManifestFile = mprintf("%smanifest", g.zLocalRoot);
850874
if( !noSign && !g.markPrivate && clearsign(&manifest, &manifest) ){
851875
Blob ans;
852876
blob_zero(&ans);
853877
prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
854878
if( blob_str(&ans)[0]!='y' ){
855879
fossil_exit(1);
856880
}
857881
}
858
- blob_write_to_file(&manifest, zManifestFile);
859
- blob_reset(&manifest);
860
- blob_read_from_file(&manifest, zManifestFile);
861
- free(zManifestFile);
882
+ if( !file_exists_in_checkout(vid, "manifest") ){
883
+ zManifestFile = mprintf("%smanifest", g.zLocalRoot);
884
+ blob_write_to_file(&manifest, zManifestFile);
885
+ blob_reset(&manifest);
886
+ blob_read_from_file(&manifest, zManifestFile);
887
+ free(zManifestFile);
888
+ }
862889
nvid = content_put(&manifest, 0, 0);
863890
if( nvid==0 ){
864891
fossil_panic("trouble committing manifest: %s", g.zErrMsg);
865892
}
866893
db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nvid);
867894
manifest_crosslink(nvid, &manifest);
868895
content_deltify(vid, nvid, 0);
869896
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", nvid);
870897
printf("New_Version: %s\n", zUuid);
871
- zManifestFile = mprintf("%smanifest.uuid", g.zLocalRoot);
872
- blob_zero(&muuid);
873
- blob_appendf(&muuid, "%s\n", zUuid);
874
- blob_write_to_file(&muuid, zManifestFile);
875
- free(zManifestFile);
876
- blob_reset(&muuid);
898
+ if( !file_exists_in_checkout(vid, "manifest.uuid") ){
899
+ zManifestFile = mprintf("%smanifest.uuid", g.zLocalRoot);
900
+ blob_zero(&muuid);
901
+ blob_appendf(&muuid, "%s\n", zUuid);
902
+ blob_write_to_file(&muuid, zManifestFile);
903
+ free(zManifestFile);
904
+ blob_reset(&muuid);
905
+ }
877906
878907
879908
/* Update the vfile and vmerge tables */
880909
db_multi_exec(
881910
"DELETE FROM vfile WHERE (vid!=%d OR deleted) AND file_is_selected(id);"
882911
--- src/checkin.c
+++ src/checkin.c
@@ -535,10 +535,23 @@
535 assert( strlen(zDate)==19 );
536 assert( zDate[10]==' ' );
537 zDate[10] = 'T';
538 return zDate;
539 }
 
 
 
 
 
 
 
 
 
 
 
 
 
540
541 /*
542 ** COMMAND: ci
543 ** COMMAND: commit
544 **
@@ -631,10 +644,22 @@
631 ** Autosync if autosync is enabled and this is not a private check-in.
632 */
633 if( !g.markPrivate ){
634 autosync(AUTOSYNC_PULL);
635 }
 
 
 
 
 
 
 
 
 
 
 
 
636
637 /* There are two ways this command may be executed. If there are
638 ** no arguments following the word "commit", then all modified files
639 ** in the checked out directory are committed. If one or more arguments
640 ** follows "commit", then only those files are committed.
@@ -844,38 +869,42 @@
844 db_finalize(&q);
845 }
846 blob_appendf(&manifest, "U %F\n", zUserOvrd ? zUserOvrd : g.zLogin);
847 md5sum_blob(&manifest, &mcksum);
848 blob_appendf(&manifest, "Z %b\n", &mcksum);
849 zManifestFile = mprintf("%smanifest", g.zLocalRoot);
850 if( !noSign && !g.markPrivate && clearsign(&manifest, &manifest) ){
851 Blob ans;
852 blob_zero(&ans);
853 prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
854 if( blob_str(&ans)[0]!='y' ){
855 fossil_exit(1);
856 }
857 }
858 blob_write_to_file(&manifest, zManifestFile);
859 blob_reset(&manifest);
860 blob_read_from_file(&manifest, zManifestFile);
861 free(zManifestFile);
 
 
 
862 nvid = content_put(&manifest, 0, 0);
863 if( nvid==0 ){
864 fossil_panic("trouble committing manifest: %s", g.zErrMsg);
865 }
866 db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nvid);
867 manifest_crosslink(nvid, &manifest);
868 content_deltify(vid, nvid, 0);
869 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", nvid);
870 printf("New_Version: %s\n", zUuid);
871 zManifestFile = mprintf("%smanifest.uuid", g.zLocalRoot);
872 blob_zero(&muuid);
873 blob_appendf(&muuid, "%s\n", zUuid);
874 blob_write_to_file(&muuid, zManifestFile);
875 free(zManifestFile);
876 blob_reset(&muuid);
 
 
877
878
879 /* Update the vfile and vmerge tables */
880 db_multi_exec(
881 "DELETE FROM vfile WHERE (vid!=%d OR deleted) AND file_is_selected(id);"
882
--- src/checkin.c
+++ src/checkin.c
@@ -535,10 +535,23 @@
535 assert( strlen(zDate)==19 );
536 assert( zDate[10]==' ' );
537 zDate[10] = 'T';
538 return zDate;
539 }
540
541 /*
542 ** Return TRUE (non-zero) if a file named "zFilename" exists in
543 ** the checkout identified by vid.
544 **
545 ** The original purpose of this routine was to check for the presence of
546 ** a "checked-in" file named "manifest" or "manifest.uuid" so as to avoid
547 ** overwriting that file with automatically generated files.
548 */
549 int file_exists_in_checkout(int vid, const char *zFilename){
550 return db_exists("SELECT 1 FROM vfile WHERE vid=%d AND pathname=%Q",
551 vid, zFilename);
552 }
553
554 /*
555 ** COMMAND: ci
556 ** COMMAND: commit
557 **
@@ -631,10 +644,22 @@
644 ** Autosync if autosync is enabled and this is not a private check-in.
645 */
646 if( !g.markPrivate ){
647 autosync(AUTOSYNC_PULL);
648 }
649
650 /* Require confirmation to continue with the check-in if there is
651 ** clock skew
652 */
653 if( g.clockSkewSeen ){
654 Blob ans;
655 blob_zero(&ans);
656 prompt_user("continue in spite of time skew (y/N)? ", &ans);
657 if( blob_str(&ans)[0]!='y' ){
658 fossil_exit(1);
659 }
660 }
661
662 /* There are two ways this command may be executed. If there are
663 ** no arguments following the word "commit", then all modified files
664 ** in the checked out directory are committed. If one or more arguments
665 ** follows "commit", then only those files are committed.
@@ -844,38 +869,42 @@
869 db_finalize(&q);
870 }
871 blob_appendf(&manifest, "U %F\n", zUserOvrd ? zUserOvrd : g.zLogin);
872 md5sum_blob(&manifest, &mcksum);
873 blob_appendf(&manifest, "Z %b\n", &mcksum);
 
874 if( !noSign && !g.markPrivate && clearsign(&manifest, &manifest) ){
875 Blob ans;
876 blob_zero(&ans);
877 prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
878 if( blob_str(&ans)[0]!='y' ){
879 fossil_exit(1);
880 }
881 }
882 if( !file_exists_in_checkout(vid, "manifest") ){
883 zManifestFile = mprintf("%smanifest", g.zLocalRoot);
884 blob_write_to_file(&manifest, zManifestFile);
885 blob_reset(&manifest);
886 blob_read_from_file(&manifest, zManifestFile);
887 free(zManifestFile);
888 }
889 nvid = content_put(&manifest, 0, 0);
890 if( nvid==0 ){
891 fossil_panic("trouble committing manifest: %s", g.zErrMsg);
892 }
893 db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nvid);
894 manifest_crosslink(nvid, &manifest);
895 content_deltify(vid, nvid, 0);
896 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", nvid);
897 printf("New_Version: %s\n", zUuid);
898 if( !file_exists_in_checkout(vid, "manifest.uuid") ){
899 zManifestFile = mprintf("%smanifest.uuid", g.zLocalRoot);
900 blob_zero(&muuid);
901 blob_appendf(&muuid, "%s\n", zUuid);
902 blob_write_to_file(&muuid, zManifestFile);
903 free(zManifestFile);
904 blob_reset(&muuid);
905 }
906
907
908 /* Update the vfile and vmerge tables */
909 db_multi_exec(
910 "DELETE FROM vfile WHERE (vid!=%d OR deleted) AND file_is_selected(id);"
911
+33 -13
--- src/checkout.c
+++ src/checkout.c
@@ -97,34 +97,33 @@
9797
db_multi_exec("UPDATE vfile SET isexe=%d WHERE vid=%d and pathname=%Q",
9898
onoff, vid, zFilename);
9999
}
100100
101101
/*
102
-** Read the manifest file given by vid out of the repository
103
-** and store it in the root of the local check-out.
102
+** Set or clear the execute permission bit (as appropriate) for all
103
+** files in the current check-out.
104
+**
105
+** If the checkout does not have explicit files named "manifest" and
106
+** "manifest.uuid" then automatically generate files with those names
107
+** containing, respectively, the text of the manifest and the artifact
108
+** ID of the manifest.
104109
*/
105110
void manifest_to_disk(int vid){
106111
char *zManFile;
107112
Blob manifest;
108113
Blob hash;
109114
Blob filename;
110115
int baseLen;
111116
int i;
117
+ int seenManifest = 0;
118
+ int seenManifestUuid = 0;
112119
Manifest m;
113120
121
+ /* Check the EXE permission status of all files
122
+ */
114123
blob_zero(&manifest);
115
- zManFile = mprintf("%smanifest", g.zLocalRoot);
116124
content_get(vid, &manifest);
117
- blob_write_to_file(&manifest, zManFile);
118
- free(zManFile);
119
- blob_zero(&hash);
120
- sha1sum_blob(&manifest, &hash);
121
- zManFile = mprintf("%smanifest.uuid", g.zLocalRoot);
122
- blob_append(&hash, "\n", 1);
123
- blob_write_to_file(&hash, zManFile);
124
- free(zManFile);
125
- blob_reset(&hash);
126125
manifest_parse(&m, &manifest);
127126
blob_zero(&filename);
128127
blob_appendf(&filename, "%s/", g.zLocalRoot);
129128
baseLen = blob_size(&filename);
130129
for(i=0; i<m.nFile; i++){
@@ -132,13 +131,34 @@
132131
blob_append(&filename, m.aFile[i].zName, -1);
133132
isExe = m.aFile[i].zPerm && strstr(m.aFile[i].zPerm, "x");
134133
file_setexe(blob_str(&filename), isExe);
135134
set_or_clear_isexe(m.aFile[i].zName, vid, isExe);
136135
blob_resize(&filename, baseLen);
136
+ if( memcmp(m.aFile[i].zName, "manifest", 8)==0 ){
137
+ if( m.aFile[i].zName[8]==0 ) seenManifest = 1;
138
+ if( strcmp(&m.aFile[i].zName[8], ".uuid")==0 ) seenManifestUuid = 1;
139
+ }
137140
}
138141
blob_reset(&filename);
139142
manifest_clear(&m);
143
+
144
+ blob_zero(&manifest);
145
+ content_get(vid, &manifest);
146
+ if( !seenManifest ){
147
+ zManFile = mprintf("%smanifest", g.zLocalRoot);
148
+ blob_write_to_file(&manifest, zManFile);
149
+ free(zManFile);
150
+ }
151
+ if( !seenManifestUuid ){
152
+ blob_zero(&hash);
153
+ sha1sum_blob(&manifest, &hash);
154
+ zManFile = mprintf("%smanifest.uuid", g.zLocalRoot);
155
+ blob_append(&hash, "\n", 1);
156
+ blob_write_to_file(&hash, zManFile);
157
+ free(zManFile);
158
+ blob_reset(&hash);
159
+ }
140160
}
141161
142162
/*
143163
** COMMAND: checkout
144164
** COMMAND: co
@@ -218,11 +238,11 @@
218238
vfile_aggregate_checksum_manifest(vid, &cksum1, &cksum1b);
219239
vfile_aggregate_checksum_disk(vid, &cksum2);
220240
if( blob_compare(&cksum1, &cksum2) ){
221241
printf("WARNING: manifest checksum does not agree with disk\n");
222242
}
223
- if( blob_compare(&cksum1, &cksum1b) ){
243
+ if( blob_size(&cksum1b) && blob_compare(&cksum1, &cksum1b) ){
224244
printf("WARNING: manifest checksum does not agree with manifest\n");
225245
}
226246
}
227247
db_end_transaction(0);
228248
}
229249
--- src/checkout.c
+++ src/checkout.c
@@ -97,34 +97,33 @@
97 db_multi_exec("UPDATE vfile SET isexe=%d WHERE vid=%d and pathname=%Q",
98 onoff, vid, zFilename);
99 }
100
101 /*
102 ** Read the manifest file given by vid out of the repository
103 ** and store it in the root of the local check-out.
 
 
 
 
 
104 */
105 void manifest_to_disk(int vid){
106 char *zManFile;
107 Blob manifest;
108 Blob hash;
109 Blob filename;
110 int baseLen;
111 int i;
 
 
112 Manifest m;
113
 
 
114 blob_zero(&manifest);
115 zManFile = mprintf("%smanifest", g.zLocalRoot);
116 content_get(vid, &manifest);
117 blob_write_to_file(&manifest, zManFile);
118 free(zManFile);
119 blob_zero(&hash);
120 sha1sum_blob(&manifest, &hash);
121 zManFile = mprintf("%smanifest.uuid", g.zLocalRoot);
122 blob_append(&hash, "\n", 1);
123 blob_write_to_file(&hash, zManFile);
124 free(zManFile);
125 blob_reset(&hash);
126 manifest_parse(&m, &manifest);
127 blob_zero(&filename);
128 blob_appendf(&filename, "%s/", g.zLocalRoot);
129 baseLen = blob_size(&filename);
130 for(i=0; i<m.nFile; i++){
@@ -132,13 +131,34 @@
132 blob_append(&filename, m.aFile[i].zName, -1);
133 isExe = m.aFile[i].zPerm && strstr(m.aFile[i].zPerm, "x");
134 file_setexe(blob_str(&filename), isExe);
135 set_or_clear_isexe(m.aFile[i].zName, vid, isExe);
136 blob_resize(&filename, baseLen);
 
 
 
 
137 }
138 blob_reset(&filename);
139 manifest_clear(&m);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140 }
141
142 /*
143 ** COMMAND: checkout
144 ** COMMAND: co
@@ -218,11 +238,11 @@
218 vfile_aggregate_checksum_manifest(vid, &cksum1, &cksum1b);
219 vfile_aggregate_checksum_disk(vid, &cksum2);
220 if( blob_compare(&cksum1, &cksum2) ){
221 printf("WARNING: manifest checksum does not agree with disk\n");
222 }
223 if( blob_compare(&cksum1, &cksum1b) ){
224 printf("WARNING: manifest checksum does not agree with manifest\n");
225 }
226 }
227 db_end_transaction(0);
228 }
229
--- src/checkout.c
+++ src/checkout.c
@@ -97,34 +97,33 @@
97 db_multi_exec("UPDATE vfile SET isexe=%d WHERE vid=%d and pathname=%Q",
98 onoff, vid, zFilename);
99 }
100
101 /*
102 ** Set or clear the execute permission bit (as appropriate) for all
103 ** files in the current check-out.
104 **
105 ** If the checkout does not have explicit files named "manifest" and
106 ** "manifest.uuid" then automatically generate files with those names
107 ** containing, respectively, the text of the manifest and the artifact
108 ** ID of the manifest.
109 */
110 void manifest_to_disk(int vid){
111 char *zManFile;
112 Blob manifest;
113 Blob hash;
114 Blob filename;
115 int baseLen;
116 int i;
117 int seenManifest = 0;
118 int seenManifestUuid = 0;
119 Manifest m;
120
121 /* Check the EXE permission status of all files
122 */
123 blob_zero(&manifest);
 
124 content_get(vid, &manifest);
 
 
 
 
 
 
 
 
 
125 manifest_parse(&m, &manifest);
126 blob_zero(&filename);
127 blob_appendf(&filename, "%s/", g.zLocalRoot);
128 baseLen = blob_size(&filename);
129 for(i=0; i<m.nFile; i++){
@@ -132,13 +131,34 @@
131 blob_append(&filename, m.aFile[i].zName, -1);
132 isExe = m.aFile[i].zPerm && strstr(m.aFile[i].zPerm, "x");
133 file_setexe(blob_str(&filename), isExe);
134 set_or_clear_isexe(m.aFile[i].zName, vid, isExe);
135 blob_resize(&filename, baseLen);
136 if( memcmp(m.aFile[i].zName, "manifest", 8)==0 ){
137 if( m.aFile[i].zName[8]==0 ) seenManifest = 1;
138 if( strcmp(&m.aFile[i].zName[8], ".uuid")==0 ) seenManifestUuid = 1;
139 }
140 }
141 blob_reset(&filename);
142 manifest_clear(&m);
143
144 blob_zero(&manifest);
145 content_get(vid, &manifest);
146 if( !seenManifest ){
147 zManFile = mprintf("%smanifest", g.zLocalRoot);
148 blob_write_to_file(&manifest, zManFile);
149 free(zManFile);
150 }
151 if( !seenManifestUuid ){
152 blob_zero(&hash);
153 sha1sum_blob(&manifest, &hash);
154 zManFile = mprintf("%smanifest.uuid", g.zLocalRoot);
155 blob_append(&hash, "\n", 1);
156 blob_write_to_file(&hash, zManFile);
157 free(zManFile);
158 blob_reset(&hash);
159 }
160 }
161
162 /*
163 ** COMMAND: checkout
164 ** COMMAND: co
@@ -218,11 +238,11 @@
238 vfile_aggregate_checksum_manifest(vid, &cksum1, &cksum1b);
239 vfile_aggregate_checksum_disk(vid, &cksum2);
240 if( blob_compare(&cksum1, &cksum2) ){
241 printf("WARNING: manifest checksum does not agree with disk\n");
242 }
243 if( blob_size(&cksum1b) && blob_compare(&cksum1, &cksum1b) ){
244 printf("WARNING: manifest checksum does not agree with manifest\n");
245 }
246 }
247 db_end_transaction(0);
248 }
249
+2 -2
--- src/config.h
+++ src/config.h
@@ -36,12 +36,12 @@
3636
#include <stdlib.h>
3737
#include <ctype.h>
3838
#include <string.h>
3939
#include <stdarg.h>
4040
#include <assert.h>
41
-#if defined( __MINGW32__) || defined(__DMC__) || defined(_MSC_VER)
42
-# if defined(__DMC__) || defined(_MSC_VER)
41
+#if defined( __MINGW32__) || defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
42
+# if defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
4343
typedef int socklen_t;
4444
# endif
4545
# ifndef _WIN32
4646
# define _WIN32
4747
# endif
4848
--- src/config.h
+++ src/config.h
@@ -36,12 +36,12 @@
36 #include <stdlib.h>
37 #include <ctype.h>
38 #include <string.h>
39 #include <stdarg.h>
40 #include <assert.h>
41 #if defined( __MINGW32__) || defined(__DMC__) || defined(_MSC_VER)
42 # if defined(__DMC__) || defined(_MSC_VER)
43 typedef int socklen_t;
44 # endif
45 # ifndef _WIN32
46 # define _WIN32
47 # endif
48
--- src/config.h
+++ src/config.h
@@ -36,12 +36,12 @@
36 #include <stdlib.h>
37 #include <ctype.h>
38 #include <string.h>
39 #include <stdarg.h>
40 #include <assert.h>
41 #if defined( __MINGW32__) || defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
42 # if defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
43 typedef int socklen_t;
44 # endif
45 # ifndef _WIN32
46 # define _WIN32
47 # endif
48
+160 -142
--- src/content.c
+++ src/content.c
@@ -19,33 +19,25 @@
1919
*/
2020
#include "config.h"
2121
#include "content.h"
2222
#include <assert.h>
2323
24
-/*
25
-** Macros for debugging
26
-*/
27
-#if 0
28
-# define CONTENT_TRACE(X) printf X;
29
-#else
30
-# define CONTENT_TRACE(X)
31
-#endif
32
-
3324
/*
3425
** The artifact retrival cache
3526
*/
36
-#define MX_CACHE_CNT 50 /* Maximum number of positive cache entries */
37
-#define EXPELL_INTERVAL 5 /* How often to expell from a full cache */
3827
static struct {
39
- int n; /* Current number of positive cache entries */
28
+ i64 szTotal; /* Total size of all entries in the cache */
29
+ int n; /* Current number of eache entries */
30
+ int nAlloc; /* Number of slots allocated in a[] */
4031
int nextAge; /* Age counter for implementing LRU */
4132
int skipCnt; /* Used to limit entries expelled from cache */
42
- struct { /* One instance of this for each cache entry */
33
+ struct cacheLine { /* One instance of this for each cache entry */
4334
int rid; /* Artifact id */
4435
int age; /* Age. Newer is larger */
4536
Blob content; /* Content of the artifact */
46
- } a[MX_CACHE_CNT]; /* The positive cache */
37
+ } *a; /* The positive cache */
38
+ Bag inCache; /* Set of artifacts currently in cache */
4739
4840
/*
4941
** The missing artifact cache.
5042
**
5143
** Artifacts whose record ID are in missingCache cannot be retrieved
@@ -56,10 +48,54 @@
5648
*/
5749
Bag missing; /* Cache of artifacts that are incomplete */
5850
Bag available; /* Cache of artifacts that are complete */
5951
} contentCache;
6052
53
+/*
54
+** Remove the oldest element from the content cache
55
+*/
56
+static void content_cache_expire_oldest(void){
57
+ int i;
58
+ int mnAge = contentCache.nextAge;
59
+ int mn = -1;
60
+ for(i=0; i<contentCache.n; i++){
61
+ if( contentCache.a[i].age<mnAge ){
62
+ mnAge = contentCache.a[i].age;
63
+ mn = i;
64
+ }
65
+ }
66
+ if( mn>=0 ){
67
+ bag_remove(&contentCache.inCache, contentCache.a[mn].rid);
68
+ contentCache.szTotal -= blob_size(&contentCache.a[mn].content);
69
+ blob_reset(&contentCache.a[mn].content);
70
+ contentCache.n--;
71
+ contentCache.a[mn] = contentCache.a[contentCache.n];
72
+ }
73
+}
74
+
75
+/*
76
+** Add an entry to the content cache
77
+*/
78
+void content_cache_insert(int rid, Blob *pBlob){
79
+ struct cacheLine *p;
80
+ if( contentCache.n>500 || contentCache.szTotal>50000000 ){
81
+ content_cache_expire_oldest();
82
+ }
83
+ if( contentCache.n>=contentCache.nAlloc ){
84
+ contentCache.nAlloc = contentCache.nAlloc*2 + 10;
85
+ contentCache.a = realloc(contentCache.a,
86
+ contentCache.nAlloc*sizeof(contentCache.a[0]));
87
+ if( contentCache.a==0 ) fossil_panic("out of memory");
88
+ }
89
+ p = &contentCache.a[contentCache.n++];
90
+ p->rid = rid;
91
+ p->age = contentCache.nextAge++;
92
+ contentCache.szTotal += blob_size(pBlob);
93
+ p->content = *pBlob;
94
+ blob_zero(pBlob);
95
+ bag_insert(&contentCache.inCache, rid);
96
+}
6197
6298
/*
6399
** Clear the content cache.
64100
*/
65101
void content_clear_cache(void){
@@ -67,11 +103,13 @@
67103
for(i=0; i<contentCache.n; i++){
68104
blob_reset(&contentCache.a[i].content);
69105
}
70106
bag_clear(&contentCache.missing);
71107
bag_clear(&contentCache.available);
108
+ bag_clear(&contentCache.inCache);
72109
contentCache.n = 0;
110
+ contentCache.szTotal = 0;
73111
}
74112
75113
/*
76114
** Return the srcid associated with rid. Or return 0 if rid is
77115
** original content and not a delta.
@@ -95,32 +133,31 @@
95133
** true if it is. Return false if rid is a phantom or depends on
96134
** a phantom.
97135
*/
98136
int content_is_available(int rid){
99137
int srcid;
100
- if( bag_find(&contentCache.missing, rid) ){
101
- return 0;
102
- }
103
- if( bag_find(&contentCache.available, rid) ){
104
- return 1;
105
- }
106
- if( db_int(-1, "SELECT size FROM blob WHERE rid=%d", rid)<0 ){
107
- bag_insert(&contentCache.missing, rid);
108
- return 0;
109
- }
110
- srcid = findSrcid(rid);
111
- if( srcid==0 ){
112
- bag_insert(&contentCache.available, rid);
113
- return 1;
114
- }
115
- if( content_is_available(srcid) ){
116
- bag_insert(&contentCache.available, rid);
117
- return 1;
118
- }else{
119
- bag_insert(&contentCache.missing, rid);
120
- return 0;
121
- }
138
+ int depth = 0; /* Limit to recursion depth */
139
+ while( depth++ < 10000000 ){
140
+ if( bag_find(&contentCache.missing, rid) ){
141
+ return 0;
142
+ }
143
+ if( bag_find(&contentCache.available, rid) ){
144
+ return 1;
145
+ }
146
+ if( db_int(-1, "SELECT size FROM blob WHERE rid=%d", rid)<0 ){
147
+ bag_insert(&contentCache.missing, rid);
148
+ return 0;
149
+ }
150
+ srcid = findSrcid(rid);
151
+ if( srcid==0 ){
152
+ bag_insert(&contentCache.available, rid);
153
+ return 1;
154
+ }
155
+ rid = srcid;
156
+ }
157
+ fossil_panic("delta-loop in repository");
158
+ return 0;
122159
}
123160
124161
/*
125162
** Mark artifact rid as being available now. Update the cache to
126163
** show that everything that was formerly unavailable because rid
@@ -163,113 +200,84 @@
163200
}
164201
db_reset(&q);
165202
return rc;
166203
}
167204
168
-
169205
/*
170206
** Extract the content for ID rid and put it into the
171207
** uninitialized blob. Return 1 on success. If the record
172208
** is a phantom, zero pBlob and return 0.
173209
*/
174210
int content_get(int rid, Blob *pBlob){
175
- Blob src;
176
- int srcid;
177
- int rc = 0;
211
+ int rc;
178212
int i;
179
- static Bag inProcess;
213
+ int nextRid;
180214
181215
assert( g.repositoryOpen );
182216
blob_zero(pBlob);
183217
if( rid==0 ) return 0;
184218
185219
/* Early out if we know the content is not available */
186220
if( bag_find(&contentCache.missing, rid) ){
187
- CONTENT_TRACE(("%*smiss from cache: %d\n",
188
- bag_count(&inProcess), "", rid))
189221
return 0;
190222
}
191223
192224
/* Look for the artifact in the cache first */
193
- for(i=0; i<contentCache.n; i++){
194
- if( contentCache.a[i].rid==rid ){
195
- *pBlob = contentCache.a[i].content;
196
- blob_zero(&contentCache.a[i].content);
197
- contentCache.n--;
198
- if( i<contentCache.n ){
199
- contentCache.a[i] = contentCache.a[contentCache.n];
200
- }
201
- CONTENT_TRACE(("%*scache: %d\n",
202
- bag_count(&inProcess), "", rid))
203
- return 1;
204
- }
205
- }
206
-
207
- /* See if we need to apply a delta to find this artifact */
208
- srcid = findSrcid(rid);
209
- CONTENT_TRACE(("%*ssearching for %d. Need %d.\n",
210
- bag_count(&inProcess), "", rid, srcid))
211
-
212
-
213
- if( srcid ){
214
- /* Yes, a delta is required */
215
- if( bag_find(&inProcess, srcid) ){
216
- db_multi_exec(
217
- "UPDATE blob SET content=NULL, size=-1 WHERE rid=%d;"
218
- "DELETE FROM delta WHERE rid=%d;"
219
- "INSERT OR IGNORE INTO phantom VALUES(%d);",
220
- srcid, srcid, srcid
221
- );
222
- blob_zero(pBlob);
223
- return 0;
224
- }
225
- bag_insert(&inProcess, srcid);
226
-
227
- if( content_get(srcid, &src) ){
228
- Blob delta;
229
- if( content_of_blob(rid, &delta) ){
230
- blob_init(pBlob,0,0);
231
- blob_delta_apply(&src, &delta, pBlob);
225
+ if( bag_find(&contentCache.inCache, rid) ){
226
+ for(i=0; i<contentCache.n; i++){
227
+ if( contentCache.a[i].rid==rid ){
228
+ blob_copy(pBlob, &contentCache.a[i].content);
229
+ contentCache.a[i].age = contentCache.nextAge++;
230
+ return 1;
231
+ }
232
+ }
233
+ }
234
+
235
+ nextRid = findSrcid(rid);
236
+ if( nextRid==0 ){
237
+ rc = content_of_blob(rid, pBlob);
238
+ }else{
239
+ int n = 1;
240
+ int nAlloc = 10;
241
+ int *a = 0;
242
+ int mx;
243
+ Blob delta, next;
244
+
245
+ a = malloc( sizeof(a[0])*nAlloc );
246
+ if( a==0 ) fossil_panic("out of memory");
247
+ a[0] = rid;
248
+ a[1] = nextRid;
249
+ n = 1;
250
+ while( !bag_find(&contentCache.inCache, nextRid)
251
+ && (nextRid = findSrcid(nextRid))>0 ){
252
+ n++;
253
+ if( n>=nAlloc ){
254
+ nAlloc = nAlloc*2 + 10;
255
+ a = realloc(a, nAlloc*sizeof(a[0]));
256
+ if( a==0 ) fossil_panic("out of memory");
257
+ }
258
+ a[n] = nextRid;
259
+ }
260
+ mx = n;
261
+ rc = content_get(a[n], pBlob);
262
+ n--;
263
+ while( rc && n>=0 ){
264
+ rc = content_of_blob(a[n], &delta);
265
+ if( rc ){
266
+ blob_delta_apply(pBlob, &delta, &next);
232267
blob_reset(&delta);
233
- rc = 1;
234
- }
235
-
236
- /* Save the srcid artifact in the cache */
237
- if( contentCache.n<MX_CACHE_CNT ){
238
- i = contentCache.n++;
239
- }else if( ((contentCache.skipCnt++)%EXPELL_INTERVAL)!=0 ){
240
- i = -1;
241
- }else{
242
- int j, best;
243
- best = contentCache.nextAge+1;
244
- i = -1;
245
- for(j=0; j<contentCache.n; j++){
246
- if( contentCache.a[j].age<best ){
247
- i = j;
248
- best = contentCache.a[j].age;
249
- }
250
- }
251
- CONTENT_TRACE(("%*sexpell %d from cache\n",
252
- bag_count(&inProcess), "", contentCache.a[i].rid))
253
- blob_reset(&contentCache.a[i].content);
254
- }
255
- if( i>=0 ){
256
- contentCache.a[i].content = src;
257
- contentCache.a[i].age = contentCache.nextAge++;
258
- contentCache.a[i].rid = srcid;
259
- CONTENT_TRACE(("%*sadd %d to cache\n",
260
- bag_count(&inProcess), "", srcid))
261
- }else{
262
- blob_reset(&src);
263
- }
264
- }
265
- bag_remove(&inProcess, srcid);
266
- }else{
267
- /* No delta required. Read content directly from the database */
268
- if( content_of_blob(rid, pBlob) ){
269
- rc = 1;
270
- }
268
+ if( (mx-n)%8==0 ){
269
+ content_cache_insert(a[n+1], pBlob);
270
+ }else{
271
+ blob_reset(pBlob);
272
+ }
273
+ *pBlob = next;
274
+ }
275
+ n--;
276
+ }
277
+ free(a);
278
+ if( !rc ) blob_reset(pBlob);
271279
}
272280
if( rc==0 ){
273281
bag_insert(&contentCache.missing, rid);
274282
}else{
275283
bag_insert(&contentCache.available, rid);
@@ -320,35 +328,45 @@
320328
321329
/*
322330
** When a record is converted from a phantom to a real record,
323331
** if that record has other records that are derived by delta,
324332
** then call manifest_crosslink() on those other records.
333
+**
334
+** Tail recursion is used to minimize stack depth.
325335
*/
326336
void after_dephantomize(int rid, int linkFlag){
327337
Stmt q;
328
- int prevTid = 0;
329
-
330
- /* The prevTid variable is used to delay invoking this routine
331
- ** recursively, if possible, until after the query has finalized,
332
- ** in order to avoid having an excessive number of prepared statements.
333
- ** This is most effective in the common case where the query returns
334
- ** just one row.
335
- */
336
- db_prepare(&q, "SELECT rid FROM delta WHERE srcid=%d", rid);
337
- while( db_step(&q)==SQLITE_ROW ){
338
- int tid = db_column_int(&q, 0);
339
- if( prevTid ) after_dephantomize(prevTid, 1);
340
- prevTid = tid;
341
- }
342
- db_finalize(&q);
343
- if( prevTid ) after_dephantomize(prevTid, 1);
344
- if( linkFlag ){
345
- Blob content;
346
- content_get(rid, &content);
347
- manifest_crosslink(rid, &content);
348
- blob_reset(&content);
349
- }
338
+ int nChildAlloc = 0;
339
+ int *aChild = 0;
340
+
341
+ while( rid ){
342
+ int nChildUsed = 0;
343
+ int i;
344
+ if( linkFlag ){
345
+ Blob content;
346
+ content_get(rid, &content);
347
+ manifest_crosslink(rid, &content);
348
+ blob_reset(&content);
349
+ }
350
+ db_prepare(&q, "SELECT rid FROM delta WHERE srcid=%d", rid);
351
+ while( db_step(&q)==SQLITE_ROW ){
352
+ int child = db_column_int(&q, 0);
353
+ if( nChildUsed>=nChildAlloc ){
354
+ nChildAlloc = nChildAlloc*2 + 10;
355
+ aChild = realloc(aChild, nChildAlloc*sizeof(aChild));
356
+ if( aChild==0 ) fossil_panic("out of memory");
357
+ }
358
+ aChild[nChildUsed++] = child;
359
+ }
360
+ db_finalize(&q);
361
+ for(i=1; i<nChildUsed; i++){
362
+ after_dephantomize(aChild[i], 1);
363
+ }
364
+ rid = nChildUsed>0 ? aChild[0] : 0;
365
+ linkFlag = 1;
366
+ }
367
+ free(aChild);
350368
}
351369
352370
/*
353371
** Write content into the database. Return the record ID. If the
354372
** content is already in the database, just return the record ID.
355373
--- src/content.c
+++ src/content.c
@@ -19,33 +19,25 @@
19 */
20 #include "config.h"
21 #include "content.h"
22 #include <assert.h>
23
24 /*
25 ** Macros for debugging
26 */
27 #if 0
28 # define CONTENT_TRACE(X) printf X;
29 #else
30 # define CONTENT_TRACE(X)
31 #endif
32
33 /*
34 ** The artifact retrival cache
35 */
36 #define MX_CACHE_CNT 50 /* Maximum number of positive cache entries */
37 #define EXPELL_INTERVAL 5 /* How often to expell from a full cache */
38 static struct {
39 int n; /* Current number of positive cache entries */
 
 
40 int nextAge; /* Age counter for implementing LRU */
41 int skipCnt; /* Used to limit entries expelled from cache */
42 struct { /* One instance of this for each cache entry */
43 int rid; /* Artifact id */
44 int age; /* Age. Newer is larger */
45 Blob content; /* Content of the artifact */
46 } a[MX_CACHE_CNT]; /* The positive cache */
 
47
48 /*
49 ** The missing artifact cache.
50 **
51 ** Artifacts whose record ID are in missingCache cannot be retrieved
@@ -56,10 +48,54 @@
56 */
57 Bag missing; /* Cache of artifacts that are incomplete */
58 Bag available; /* Cache of artifacts that are complete */
59 } contentCache;
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
62 /*
63 ** Clear the content cache.
64 */
65 void content_clear_cache(void){
@@ -67,11 +103,13 @@
67 for(i=0; i<contentCache.n; i++){
68 blob_reset(&contentCache.a[i].content);
69 }
70 bag_clear(&contentCache.missing);
71 bag_clear(&contentCache.available);
 
72 contentCache.n = 0;
 
73 }
74
75 /*
76 ** Return the srcid associated with rid. Or return 0 if rid is
77 ** original content and not a delta.
@@ -95,32 +133,31 @@
95 ** true if it is. Return false if rid is a phantom or depends on
96 ** a phantom.
97 */
98 int content_is_available(int rid){
99 int srcid;
100 if( bag_find(&contentCache.missing, rid) ){
101 return 0;
102 }
103 if( bag_find(&contentCache.available, rid) ){
104 return 1;
105 }
106 if( db_int(-1, "SELECT size FROM blob WHERE rid=%d", rid)<0 ){
107 bag_insert(&contentCache.missing, rid);
108 return 0;
109 }
110 srcid = findSrcid(rid);
111 if( srcid==0 ){
112 bag_insert(&contentCache.available, rid);
113 return 1;
114 }
115 if( content_is_available(srcid) ){
116 bag_insert(&contentCache.available, rid);
117 return 1;
118 }else{
119 bag_insert(&contentCache.missing, rid);
120 return 0;
121 }
122 }
123
124 /*
125 ** Mark artifact rid as being available now. Update the cache to
126 ** show that everything that was formerly unavailable because rid
@@ -163,113 +200,84 @@
163 }
164 db_reset(&q);
165 return rc;
166 }
167
168
169 /*
170 ** Extract the content for ID rid and put it into the
171 ** uninitialized blob. Return 1 on success. If the record
172 ** is a phantom, zero pBlob and return 0.
173 */
174 int content_get(int rid, Blob *pBlob){
175 Blob src;
176 int srcid;
177 int rc = 0;
178 int i;
179 static Bag inProcess;
180
181 assert( g.repositoryOpen );
182 blob_zero(pBlob);
183 if( rid==0 ) return 0;
184
185 /* Early out if we know the content is not available */
186 if( bag_find(&contentCache.missing, rid) ){
187 CONTENT_TRACE(("%*smiss from cache: %d\n",
188 bag_count(&inProcess), "", rid))
189 return 0;
190 }
191
192 /* Look for the artifact in the cache first */
193 for(i=0; i<contentCache.n; i++){
194 if( contentCache.a[i].rid==rid ){
195 *pBlob = contentCache.a[i].content;
196 blob_zero(&contentCache.a[i].content);
197 contentCache.n--;
198 if( i<contentCache.n ){
199 contentCache.a[i] = contentCache.a[contentCache.n];
200 }
201 CONTENT_TRACE(("%*scache: %d\n",
202 bag_count(&inProcess), "", rid))
203 return 1;
204 }
205 }
206
207 /* See if we need to apply a delta to find this artifact */
208 srcid = findSrcid(rid);
209 CONTENT_TRACE(("%*ssearching for %d. Need %d.\n",
210 bag_count(&inProcess), "", rid, srcid))
211
212
213 if( srcid ){
214 /* Yes, a delta is required */
215 if( bag_find(&inProcess, srcid) ){
216 db_multi_exec(
217 "UPDATE blob SET content=NULL, size=-1 WHERE rid=%d;"
218 "DELETE FROM delta WHERE rid=%d;"
219 "INSERT OR IGNORE INTO phantom VALUES(%d);",
220 srcid, srcid, srcid
221 );
222 blob_zero(pBlob);
223 return 0;
224 }
225 bag_insert(&inProcess, srcid);
226
227 if( content_get(srcid, &src) ){
228 Blob delta;
229 if( content_of_blob(rid, &delta) ){
230 blob_init(pBlob,0,0);
231 blob_delta_apply(&src, &delta, pBlob);
 
 
 
232 blob_reset(&delta);
233 rc = 1;
234 }
235
236 /* Save the srcid artifact in the cache */
237 if( contentCache.n<MX_CACHE_CNT ){
238 i = contentCache.n++;
239 }else if( ((contentCache.skipCnt++)%EXPELL_INTERVAL)!=0 ){
240 i = -1;
241 }else{
242 int j, best;
243 best = contentCache.nextAge+1;
244 i = -1;
245 for(j=0; j<contentCache.n; j++){
246 if( contentCache.a[j].age<best ){
247 i = j;
248 best = contentCache.a[j].age;
249 }
250 }
251 CONTENT_TRACE(("%*sexpell %d from cache\n",
252 bag_count(&inProcess), "", contentCache.a[i].rid))
253 blob_reset(&contentCache.a[i].content);
254 }
255 if( i>=0 ){
256 contentCache.a[i].content = src;
257 contentCache.a[i].age = contentCache.nextAge++;
258 contentCache.a[i].rid = srcid;
259 CONTENT_TRACE(("%*sadd %d to cache\n",
260 bag_count(&inProcess), "", srcid))
261 }else{
262 blob_reset(&src);
263 }
264 }
265 bag_remove(&inProcess, srcid);
266 }else{
267 /* No delta required. Read content directly from the database */
268 if( content_of_blob(rid, pBlob) ){
269 rc = 1;
270 }
271 }
272 if( rc==0 ){
273 bag_insert(&contentCache.missing, rid);
274 }else{
275 bag_insert(&contentCache.available, rid);
@@ -320,35 +328,45 @@
320
321 /*
322 ** When a record is converted from a phantom to a real record,
323 ** if that record has other records that are derived by delta,
324 ** then call manifest_crosslink() on those other records.
 
 
325 */
326 void after_dephantomize(int rid, int linkFlag){
327 Stmt q;
328 int prevTid = 0;
329
330 /* The prevTid variable is used to delay invoking this routine
331 ** recursively, if possible, until after the query has finalized,
332 ** in order to avoid having an excessive number of prepared statements.
333 ** This is most effective in the common case where the query returns
334 ** just one row.
335 */
336 db_prepare(&q, "SELECT rid FROM delta WHERE srcid=%d", rid);
337 while( db_step(&q)==SQLITE_ROW ){
338 int tid = db_column_int(&q, 0);
339 if( prevTid ) after_dephantomize(prevTid, 1);
340 prevTid = tid;
341 }
342 db_finalize(&q);
343 if( prevTid ) after_dephantomize(prevTid, 1);
344 if( linkFlag ){
345 Blob content;
346 content_get(rid, &content);
347 manifest_crosslink(rid, &content);
348 blob_reset(&content);
349 }
 
 
 
 
 
 
 
 
350 }
351
352 /*
353 ** Write content into the database. Return the record ID. If the
354 ** content is already in the database, just return the record ID.
355
--- src/content.c
+++ src/content.c
@@ -19,33 +19,25 @@
19 */
20 #include "config.h"
21 #include "content.h"
22 #include <assert.h>
23
 
 
 
 
 
 
 
 
 
24 /*
25 ** The artifact retrival cache
26 */
 
 
27 static struct {
28 i64 szTotal; /* Total size of all entries in the cache */
29 int n; /* Current number of eache entries */
30 int nAlloc; /* Number of slots allocated in a[] */
31 int nextAge; /* Age counter for implementing LRU */
32 int skipCnt; /* Used to limit entries expelled from cache */
33 struct cacheLine { /* One instance of this for each cache entry */
34 int rid; /* Artifact id */
35 int age; /* Age. Newer is larger */
36 Blob content; /* Content of the artifact */
37 } *a; /* The positive cache */
38 Bag inCache; /* Set of artifacts currently in cache */
39
40 /*
41 ** The missing artifact cache.
42 **
43 ** Artifacts whose record ID are in missingCache cannot be retrieved
@@ -56,10 +48,54 @@
48 */
49 Bag missing; /* Cache of artifacts that are incomplete */
50 Bag available; /* Cache of artifacts that are complete */
51 } contentCache;
52
53 /*
54 ** Remove the oldest element from the content cache
55 */
56 static void content_cache_expire_oldest(void){
57 int i;
58 int mnAge = contentCache.nextAge;
59 int mn = -1;
60 for(i=0; i<contentCache.n; i++){
61 if( contentCache.a[i].age<mnAge ){
62 mnAge = contentCache.a[i].age;
63 mn = i;
64 }
65 }
66 if( mn>=0 ){
67 bag_remove(&contentCache.inCache, contentCache.a[mn].rid);
68 contentCache.szTotal -= blob_size(&contentCache.a[mn].content);
69 blob_reset(&contentCache.a[mn].content);
70 contentCache.n--;
71 contentCache.a[mn] = contentCache.a[contentCache.n];
72 }
73 }
74
75 /*
76 ** Add an entry to the content cache
77 */
78 void content_cache_insert(int rid, Blob *pBlob){
79 struct cacheLine *p;
80 if( contentCache.n>500 || contentCache.szTotal>50000000 ){
81 content_cache_expire_oldest();
82 }
83 if( contentCache.n>=contentCache.nAlloc ){
84 contentCache.nAlloc = contentCache.nAlloc*2 + 10;
85 contentCache.a = realloc(contentCache.a,
86 contentCache.nAlloc*sizeof(contentCache.a[0]));
87 if( contentCache.a==0 ) fossil_panic("out of memory");
88 }
89 p = &contentCache.a[contentCache.n++];
90 p->rid = rid;
91 p->age = contentCache.nextAge++;
92 contentCache.szTotal += blob_size(pBlob);
93 p->content = *pBlob;
94 blob_zero(pBlob);
95 bag_insert(&contentCache.inCache, rid);
96 }
97
98 /*
99 ** Clear the content cache.
100 */
101 void content_clear_cache(void){
@@ -67,11 +103,13 @@
103 for(i=0; i<contentCache.n; i++){
104 blob_reset(&contentCache.a[i].content);
105 }
106 bag_clear(&contentCache.missing);
107 bag_clear(&contentCache.available);
108 bag_clear(&contentCache.inCache);
109 contentCache.n = 0;
110 contentCache.szTotal = 0;
111 }
112
113 /*
114 ** Return the srcid associated with rid. Or return 0 if rid is
115 ** original content and not a delta.
@@ -95,32 +133,31 @@
133 ** true if it is. Return false if rid is a phantom or depends on
134 ** a phantom.
135 */
136 int content_is_available(int rid){
137 int srcid;
138 int depth = 0; /* Limit to recursion depth */
139 while( depth++ < 10000000 ){
140 if( bag_find(&contentCache.missing, rid) ){
141 return 0;
142 }
143 if( bag_find(&contentCache.available, rid) ){
144 return 1;
145 }
146 if( db_int(-1, "SELECT size FROM blob WHERE rid=%d", rid)<0 ){
147 bag_insert(&contentCache.missing, rid);
148 return 0;
149 }
150 srcid = findSrcid(rid);
151 if( srcid==0 ){
152 bag_insert(&contentCache.available, rid);
153 return 1;
154 }
155 rid = srcid;
156 }
157 fossil_panic("delta-loop in repository");
158 return 0;
 
159 }
160
161 /*
162 ** Mark artifact rid as being available now. Update the cache to
163 ** show that everything that was formerly unavailable because rid
@@ -163,113 +200,84 @@
200 }
201 db_reset(&q);
202 return rc;
203 }
204
 
205 /*
206 ** Extract the content for ID rid and put it into the
207 ** uninitialized blob. Return 1 on success. If the record
208 ** is a phantom, zero pBlob and return 0.
209 */
210 int content_get(int rid, Blob *pBlob){
211 int rc;
 
 
212 int i;
213 int nextRid;
214
215 assert( g.repositoryOpen );
216 blob_zero(pBlob);
217 if( rid==0 ) return 0;
218
219 /* Early out if we know the content is not available */
220 if( bag_find(&contentCache.missing, rid) ){
 
 
221 return 0;
222 }
223
224 /* Look for the artifact in the cache first */
225 if( bag_find(&contentCache.inCache, rid) ){
226 for(i=0; i<contentCache.n; i++){
227 if( contentCache.a[i].rid==rid ){
228 blob_copy(pBlob, &contentCache.a[i].content);
229 contentCache.a[i].age = contentCache.nextAge++;
230 return 1;
231 }
232 }
233 }
234
235 nextRid = findSrcid(rid);
236 if( nextRid==0 ){
237 rc = content_of_blob(rid, pBlob);
238 }else{
239 int n = 1;
240 int nAlloc = 10;
241 int *a = 0;
242 int mx;
243 Blob delta, next;
244
245 a = malloc( sizeof(a[0])*nAlloc );
246 if( a==0 ) fossil_panic("out of memory");
247 a[0] = rid;
248 a[1] = nextRid;
249 n = 1;
250 while( !bag_find(&contentCache.inCache, nextRid)
251 && (nextRid = findSrcid(nextRid))>0 ){
252 n++;
253 if( n>=nAlloc ){
254 nAlloc = nAlloc*2 + 10;
255 a = realloc(a, nAlloc*sizeof(a[0]));
256 if( a==0 ) fossil_panic("out of memory");
257 }
258 a[n] = nextRid;
259 }
260 mx = n;
261 rc = content_get(a[n], pBlob);
262 n--;
263 while( rc && n>=0 ){
264 rc = content_of_blob(a[n], &delta);
265 if( rc ){
266 blob_delta_apply(pBlob, &delta, &next);
267 blob_reset(&delta);
268 if( (mx-n)%8==0 ){
269 content_cache_insert(a[n+1], pBlob);
270 }else{
271 blob_reset(pBlob);
272 }
273 *pBlob = next;
274 }
275 n--;
276 }
277 free(a);
278 if( !rc ) blob_reset(pBlob);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279 }
280 if( rc==0 ){
281 bag_insert(&contentCache.missing, rid);
282 }else{
283 bag_insert(&contentCache.available, rid);
@@ -320,35 +328,45 @@
328
329 /*
330 ** When a record is converted from a phantom to a real record,
331 ** if that record has other records that are derived by delta,
332 ** then call manifest_crosslink() on those other records.
333 **
334 ** Tail recursion is used to minimize stack depth.
335 */
336 void after_dephantomize(int rid, int linkFlag){
337 Stmt q;
338 int nChildAlloc = 0;
339 int *aChild = 0;
340
341 while( rid ){
342 int nChildUsed = 0;
343 int i;
344 if( linkFlag ){
345 Blob content;
346 content_get(rid, &content);
347 manifest_crosslink(rid, &content);
348 blob_reset(&content);
349 }
350 db_prepare(&q, "SELECT rid FROM delta WHERE srcid=%d", rid);
351 while( db_step(&q)==SQLITE_ROW ){
352 int child = db_column_int(&q, 0);
353 if( nChildUsed>=nChildAlloc ){
354 nChildAlloc = nChildAlloc*2 + 10;
355 aChild = realloc(aChild, nChildAlloc*sizeof(aChild));
356 if( aChild==0 ) fossil_panic("out of memory");
357 }
358 aChild[nChildUsed++] = child;
359 }
360 db_finalize(&q);
361 for(i=1; i<nChildUsed; i++){
362 after_dephantomize(aChild[i], 1);
363 }
364 rid = nChildUsed>0 ? aChild[0] : 0;
365 linkFlag = 1;
366 }
367 free(aChild);
368 }
369
370 /*
371 ** Write content into the database. Return the record ID. If the
372 ** content is already in the database, just return the record ID.
373
+43
--- src/db.c
+++ src/db.c
@@ -1640,5 +1640,48 @@
16401640
}
16411641
}else{
16421642
usage("?PROPERTY? ?VALUE?");
16431643
}
16441644
}
1645
+
1646
+/*
1647
+** The input in a a timespan measured in days. Return a string which
1648
+** describes that timespan in units of seconds, minutes, hours, days,
1649
+** or years, depending on its duration.
1650
+*/
1651
+char *db_timespan_name(double rSpan){
1652
+ if( rSpan<0 ) rSpan = -rSpan;
1653
+ rSpan *= 24.0*3600.0; /* Convert units to seconds */
1654
+ if( rSpan<120.0 ){
1655
+ return sqlite3_mprintf("%.1f seconds", rSpan);
1656
+ }
1657
+ rSpan /= 60.0; /* Convert units to minutes */
1658
+ if( rSpan<90.0 ){
1659
+ return sqlite3_mprintf("%.1f minutes", rSpan);
1660
+ }
1661
+ rSpan /= 60.0; /* Convert units to hours */
1662
+ if( rSpan<=48.0 ){
1663
+ return sqlite3_mprintf("%.1f hours", rSpan);
1664
+ }
1665
+ rSpan /= 24.0; /* Convert units to days */
1666
+ if( rSpan<=365.0 ){
1667
+ return sqlite3_mprintf("%.1f days", rSpan);
1668
+ }
1669
+ rSpan /= 356.24; /* Convert units to years */
1670
+ return sqlite3_mprintf("%.1f years", rSpan);
1671
+}
1672
+
1673
+/*
1674
+** COMMAND: test-timespan
1675
+** %fossil test-timespan TIMESTAMP
1676
+**
1677
+** Print the approximate span of time from now to TIMESTAMP.
1678
+*/
1679
+void test_timespan_cmd(void){
1680
+ double rDiff;
1681
+ if( g.argc!=3 ) usage("TIMESTAMP");
1682
+ sqlite3_open(":memory:", &g.db);
1683
+ rDiff = db_double(0.0, "SELECT julianday('now') - julianday(%Q)", g.argv[2]);
1684
+ printf("Time differences: %s\n", db_timespan_name(rDiff));
1685
+ sqlite3_close(g.db);
1686
+ g.db = 0;
1687
+}
16451688
16461689
ADDED src/event.c
--- src/db.c
+++ src/db.c
@@ -1640,5 +1640,48 @@
1640 }
1641 }else{
1642 usage("?PROPERTY? ?VALUE?");
1643 }
1644 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1645
1646 DDED src/event.c
--- src/db.c
+++ src/db.c
@@ -1640,5 +1640,48 @@
1640 }
1641 }else{
1642 usage("?PROPERTY? ?VALUE?");
1643 }
1644 }
1645
1646 /*
1647 ** The input in a a timespan measured in days. Return a string which
1648 ** describes that timespan in units of seconds, minutes, hours, days,
1649 ** or years, depending on its duration.
1650 */
1651 char *db_timespan_name(double rSpan){
1652 if( rSpan<0 ) rSpan = -rSpan;
1653 rSpan *= 24.0*3600.0; /* Convert units to seconds */
1654 if( rSpan<120.0 ){
1655 return sqlite3_mprintf("%.1f seconds", rSpan);
1656 }
1657 rSpan /= 60.0; /* Convert units to minutes */
1658 if( rSpan<90.0 ){
1659 return sqlite3_mprintf("%.1f minutes", rSpan);
1660 }
1661 rSpan /= 60.0; /* Convert units to hours */
1662 if( rSpan<=48.0 ){
1663 return sqlite3_mprintf("%.1f hours", rSpan);
1664 }
1665 rSpan /= 24.0; /* Convert units to days */
1666 if( rSpan<=365.0 ){
1667 return sqlite3_mprintf("%.1f days", rSpan);
1668 }
1669 rSpan /= 356.24; /* Convert units to years */
1670 return sqlite3_mprintf("%.1f years", rSpan);
1671 }
1672
1673 /*
1674 ** COMMAND: test-timespan
1675 ** %fossil test-timespan TIMESTAMP
1676 **
1677 ** Print the approximate span of time from now to TIMESTAMP.
1678 */
1679 void test_timespan_cmd(void){
1680 double rDiff;
1681 if( g.argc!=3 ) usage("TIMESTAMP");
1682 sqlite3_open(":memory:", &g.db);
1683 rDiff = db_double(0.0, "SELECT julianday('now') - julianday(%Q)", g.argv[2]);
1684 printf("Time differences: %s\n", db_timespan_name(rDiff));
1685 sqlite3_close(g.db);
1686 g.db = 0;
1687 }
1688
1689 DDED src/event.c
--- a/src/event.c
+++ b/src/event.c
@@ -0,0 +1,2 @@
1
+mParsedblobblobmParsed?name=EVENTID&de='event-%q();
2
+}
--- a/src/event.c
+++ b/src/event.c
@@ -0,0 +1,2 @@
 
 
--- a/src/event.c
+++ b/src/event.c
@@ -0,0 +1,2 @@
1 mParsedblobblobmParsed?name=EVENTID&de='event-%q();
2 }
+106 -63
--- src/info.c
+++ src/info.c
@@ -779,11 +779,11 @@
779779
}
780780
}
781781
db_finalize(&q);
782782
if( nWiki==0 ){
783783
db_prepare(&q,
784
- "SELECT datetime(mtime), user, comment, type, uuid"
784
+ "SELECT datetime(mtime), user, comment, type, uuid, tagid"
785785
" FROM event, blob"
786786
" WHERE event.objid=%d"
787787
" AND blob.rid=%d",
788788
rid, rid
789789
);
@@ -800,14 +800,19 @@
800800
@ Wiki edit
801801
}else if( zType[0]=='t' ){
802802
@ Ticket change
803803
}else if( zType[0]=='c' ){
804804
@ Manifest of check-in
805
+ }else if( zType[0]=='e' ){
806
+ @ Instance of event
807
+ hyperlink_to_event_tagid(db_column_int(&q, 5));
805808
}else{
806809
@ Control file referencing
807810
}
808
- hyperlink_to_uuid(zUuid);
811
+ if( zType[0]!='e' ){
812
+ hyperlink_to_uuid(zUuid);
813
+ }
809814
@ - %w(zCom) by
810815
hyperlink_to_user(zUser,zDate," on");
811816
hyperlink_to_date(zDate, ".");
812817
if( pDownloadName && blob_size(pDownloadName)==0 ){
813818
blob_appendf(pDownloadName, "%.10s.txt", zUuid);
@@ -1260,10 +1265,90 @@
12601265
}else
12611266
{
12621267
artifact_page();
12631268
}
12641269
}
1270
+
1271
+/*
1272
+** Generate HTML that will present the user with a selection of
1273
+** potential background colors for timeline entries.
1274
+*/
1275
+void render_color_chooser(
1276
+ int fPropagate, /* Default value for propagation */
1277
+ const char *zDefaultColor, /* The current default color */
1278
+ const char *zIdPropagate, /* ID of form element checkbox. NULL for none */
1279
+ const char *zId, /* The ID of the form element */
1280
+ const char *zIdCustom /* ID of text box for custom color */
1281
+){
1282
+ static const struct SampleColors {
1283
+ const char *zCName;
1284
+ const char *zColor;
1285
+ } aColor[] = {
1286
+ { "(none)", "" },
1287
+ { "#f2dcdc", "#f2dcdc" },
1288
+ { "#f0ffc0", "#f0ffc0" },
1289
+ { "#bde5d6", "#bde5d6" },
1290
+ { "#c0ffc0", "#c0ffc0" },
1291
+ { "#c0fff0", "#c0fff0" },
1292
+ { "#c0f0ff", "#c0f0ff" },
1293
+ { "#d0c0ff", "#d0c0ff" },
1294
+ { "#ffc0ff", "#ffc0ff" },
1295
+ { "#ffc0d0", "#ffc0d0" },
1296
+ { "#fff0c0", "#fff0c0" },
1297
+ { "#c0c0c0", "#c0c0c0" },
1298
+ { "custom", "##" },
1299
+ };
1300
+ int nColor = sizeof(aColor)/sizeof(aColor[0])-1;
1301
+ int stdClrFound = 0;
1302
+ int i;
1303
+
1304
+ @ <table border="0" cellpadding="0" cellspacing="1">
1305
+ if( zIdPropagate ){
1306
+ @ <tr><td colspan="6" align="left">
1307
+ if( fPropagate ){
1308
+ @ <input type="checkbox" name="%s(zIdPropagate)" checked="checked" />
1309
+ }else{
1310
+ @ <input type="checkbox" name="%s(zIdPropagate)" />
1311
+ }
1312
+ @ Propagate color to descendants</td></tr>
1313
+ }
1314
+ @ <tr>
1315
+ for(i=0; i<nColor; i++){
1316
+ if( aColor[i].zColor[0] ){
1317
+ @ <td style="background-color: %h(aColor[i].zColor);">
1318
+ }else{
1319
+ @ <td>
1320
+ }
1321
+ if( strcmp(zDefaultColor, aColor[i].zColor)==0 ){
1322
+ @ <input type="radio" name="%s(zId)" value="%h(aColor[i].zColor)"
1323
+ @ checked="checked" />
1324
+ stdClrFound=1;
1325
+ }else{
1326
+ @ <input type="radio" name="%s(zId)" value="%h(aColor[i].zColor)" />
1327
+ }
1328
+ @ %h(aColor[i].zCName)</td>
1329
+ if( (i%6)==5 && i+1<nColor ){
1330
+ @ </tr><tr>
1331
+ }
1332
+ }
1333
+ @ </tr><tr>
1334
+ if (stdClrFound){
1335
+ @ <td colspan="6">
1336
+ @ <input type="radio" name="%s(zId)" value="%h(aColor[nColor].zColor)" />
1337
+ }else{
1338
+ @ <td style="background-color: %h(zDefaultColor);" colspan="6">
1339
+ @ <input type="radio" name="%s(zId)" value="%h(aColor[nColor].zColor)"
1340
+ @ checked="checked" />
1341
+ }
1342
+ @ %h(aColor[i].zCName)&nbsp;
1343
+ @ <input type="text" name="%s(zIdCustom)"
1344
+ @ id="%s(zIdCustom)" class="checkinUserColor"
1345
+ @ value="%h(stdClrFound?"":zDefaultColor)" />
1346
+ @ </td>
1347
+ @ </tr>
1348
+ @ </table>
1349
+}
12651350
12661351
/*
12671352
** WEBPAGE: ci_edit
12681353
** URL: ci_edit?r=RID&c=NEWCOMMENT&u=NEWUSER
12691354
**
@@ -1290,29 +1375,10 @@
12901375
const char *zCloseFlag;
12911376
int fPropagateColor;
12921377
char *zUuid;
12931378
Blob comment;
12941379
Stmt q;
1295
- static const struct SampleColors {
1296
- const char *zCName;
1297
- const char *zColor;
1298
- } aColor[] = {
1299
- { "(none)", "" },
1300
- { "#f2dcdc", "#f2dcdc" },
1301
- { "#f0ffc0", "#f0ffc0" },
1302
- { "#bde5d6", "#bde5d6" },
1303
- { "#c0ffc0", "#c0ffc0" },
1304
- { "#c0fff0", "#c0fff0" },
1305
- { "#c0f0ff", "#c0f0ff" },
1306
- { "#d0c0ff", "#d0c0ff" },
1307
- { "#ffc0ff", "#ffc0ff" },
1308
- { "#ffc0d0", "#ffc0d0" },
1309
- { "#fff0c0", "#fff0c0" },
1310
- { "#c0c0c0", "#c0c0c0" },
1311
- };
1312
- int nColor = sizeof(aColor)/sizeof(aColor[0]);
1313
- int i;
13141380
13151381
login_check_credentials();
13161382
if( !g.okWrite ){ login_needed(); return; }
13171383
rid = name_to_rid(P("r"));
13181384
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
@@ -1332,10 +1398,13 @@
13321398
if( zDate==0 ) fossil_redirect_home();
13331399
zNewDate = PD("dt",zDate);
13341400
zColor = db_text("", "SELECT bgcolor"
13351401
" FROM event WHERE objid=%d", rid);
13361402
zNewColor = PD("clr",zColor);
1403
+ if( strcmp(zNewColor,"##")==0 ){
1404
+ zNewColor = P("clrcust");
1405
+ }
13371406
fPropagateColor = P("pclr")!=0;
13381407
zNewTagFlag = P("newtag") ? " checked" : "";
13391408
zNewTag = PD("tagname","");
13401409
zNewBrFlag = P("newbr") ? " checked" : "";
13411410
zNewBranch = PD("brname","");
@@ -1474,66 +1543,40 @@
14741543
@ <hr />
14751544
blob_reset(&suffix);
14761545
}
14771546
@ <p>Make changes to attributes of check-in
14781547
@ [<a href="ci?name=%s(zUuid)">%s(zUuid)</a>]:</p>
1479
- @ <form action="%s(g.zBaseURL)/ci_edit" method="POST">
1548
+ @ <form action="%s(g.zBaseURL)/ci_edit" method="post"><div>
14801549
login_insert_csrf_secret();
1481
- @ <input type="hidden" name="r" value="%S(zUuid)">
1550
+ @ <input type="hidden" name="r" value="%S(zUuid)" />
14821551
@ <table border="0" cellspacing="10">
14831552
14841553
@ <tr><td align="right" valign="top"><b>User:</b></td>
14851554
@ <td valign="top">
1486
- @ <input type="text" name="u" size="20" value="%h(zNewUser)">
1555
+ @ <input type="text" name="u" size="20" value="%h(zNewUser)" />
14871556
@ </td></tr>
14881557
14891558
@ <tr><td align="right" valign="top"><b>Comment:</b></td>
14901559
@ <td valign="top">
14911560
@ <textarea name="c" rows="10" cols="80">%h(zNewComment)</textarea>
14921561
@ </td></tr>
14931562
14941563
@ <tr><td align="right" valign="top"><b>Check-in Time:</b></td>
14951564
@ <td valign="top">
1496
- @ <input type="text" name="dt" size="20" value="%h(zNewDate)">
1565
+ @ <input type="text" name="dt" size="20" value="%h(zNewDate)" />
14971566
@ </td></tr>
14981567
14991568
@ <tr><td align="right" valign="top"><b>Background Color:</b></td>
15001569
@ <td valign="top">
1501
- @ <table border=0 cellpadding=0 cellspacing=1>
1502
- @ <tr><td colspan="6" align="left">
1503
- if( fPropagateColor ){
1504
- @ <input type="checkbox" name="pclr" checked>
1505
- }else{
1506
- @ <input type="checkbox" name="pclr">
1507
- }
1508
- @ Propagate color to descendants</input></td></tr>
1509
- @ <tr>
1510
- for(i=0; i<nColor; i++){
1511
- if( aColor[i].zColor[0] ){
1512
- @ <td style="background-color: %h(aColor[i].zColor);">
1513
- }else{
1514
- @ <td>
1515
- }
1516
- if( strcmp(zNewColor, aColor[i].zColor)==0 ){
1517
- @ <input type="radio" name="clr" value="%h(aColor[i].zColor)" checked>
1518
- }else{
1519
- @ <input type="radio" name="clr" value="%h(aColor[i].zColor)">
1520
- }
1521
- @ %h(aColor[i].zCName)</input></td>
1522
- if( (i%6)==5 && i+1<nColor ){
1523
- @ </tr><tr>
1524
- }
1525
- }
1526
- @ </tr>
1527
- @ </table>
1570
+ render_color_chooser(fPropagateColor, zNewColor, "pclr", "clr", "clrcust");
15281571
@ </td></tr>
15291572
15301573
@ <tr><td align="right" valign="top"><b>Tags:</b></td>
15311574
@ <td valign="top">
1532
- @ <input type="checkbox" name="newtag"%s(zNewTagFlag)>
1575
+ @ <input type="checkbox" name="newtag"%s(zNewTagFlag) />
15331576
@ Add the following new tag name to this check-in:
1534
- @ <input type="text" width="15" name="tagname" value="%h(zNewTag)">
1577
+ @ <input type="text" style="width:15;" name="tagname" value="%h(zNewTag)" />
15351578
db_prepare(&q,
15361579
"SELECT tag.tagid, tagname FROM tagxref, tag"
15371580
" WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid"
15381581
" ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)"
15391582
" ELSE tagname END",
@@ -1543,13 +1586,13 @@
15431586
int tagid = db_column_int(&q, 0);
15441587
const char *zTagName = db_column_text(&q, 1);
15451588
char zLabel[30];
15461589
sprintf(zLabel, "c%d", tagid);
15471590
if( P(zLabel) ){
1548
- @ <br /><input type="checkbox" name="c%d(tagid)" checked>
1591
+ @ <br /><input type="checkbox" name="c%d(tagid)" checked="checked" />
15491592
}else{
1550
- @ <br /><input type="checkbox" name="c%d(tagid)">
1593
+ @ <br /><input type="checkbox" name="c%d(tagid)" />
15511594
}
15521595
if( strncmp(zTagName, "sym-", 4)==0 ){
15531596
@ Cancel tag <b>%h(&zTagName[4])</b>
15541597
}else{
15551598
@ Cancel special tag <b>%h(zTagName)</b>
@@ -1558,33 +1601,33 @@
15581601
db_finalize(&q);
15591602
@ </td></tr>
15601603
15611604
@ <tr><td align="right" valign="top"><b>Branching:</b></td>
15621605
@ <td valign="top">
1563
- @ <input type="checkbox" name="newbr"%s(zNewBrFlag)>
1606
+ @ <input type="checkbox" name="newbr"%s(zNewBrFlag) />
15641607
@ Make this check-in the start of a new branch named:
1565
- @ <input type="text" width="15" name="brname" value="%h(zNewBranch)">
1608
+ @ <input type="text" style="width:15;" name="brname" value="%h(zNewBranch)" />
15661609
@ </td></tr>
15671610
15681611
if( is_a_leaf(rid)
15691612
&& !db_exists("SELECT 1 FROM tagxref "
15701613
" WHERE tagid=%d AND rid=%d AND tagtype>0",
15711614
TAG_CLOSED, rid)
15721615
){
15731616
@ <tr><td align="right" valign="top"><b>Leaf Closure:</b></td>
15741617
@ <td valign="top">
1575
- @ <input type="checkbox" name="close"%s(zCloseFlag)>
1618
+ @ <input type="checkbox" name="close"%s(zCloseFlag) />
15761619
@ Mark this leaf as "closed" so that it no longer appears on the
15771620
@ "leaves" page and is no longer labeled as a "<b>Leaf</b>".
15781621
@ </td></tr>
15791622
}
15801623
15811624
15821625
@ <tr><td colspan="2">
1583
- @ <input type="submit" name="preview" value="Preview">
1584
- @ <input type="submit" name="apply" value="Apply Changes">
1585
- @ <input type="submit" name="cancel" value="Cancel">
1626
+ @ <input type="submit" name="preview" value="Preview" />
1627
+ @ <input type="submit" name="apply" value="Apply Changes" />
1628
+ @ <input type="submit" name="cancel" value="Cancel" />
15861629
@ </td></tr>
15871630
@ </table>
1588
- @ </form>
1631
+ @ </div></form>
15891632
style_footer();
15901633
}
15911634
--- src/info.c
+++ src/info.c
@@ -779,11 +779,11 @@
779 }
780 }
781 db_finalize(&q);
782 if( nWiki==0 ){
783 db_prepare(&q,
784 "SELECT datetime(mtime), user, comment, type, uuid"
785 " FROM event, blob"
786 " WHERE event.objid=%d"
787 " AND blob.rid=%d",
788 rid, rid
789 );
@@ -800,14 +800,19 @@
800 @ Wiki edit
801 }else if( zType[0]=='t' ){
802 @ Ticket change
803 }else if( zType[0]=='c' ){
804 @ Manifest of check-in
 
 
 
805 }else{
806 @ Control file referencing
807 }
808 hyperlink_to_uuid(zUuid);
 
 
809 @ - %w(zCom) by
810 hyperlink_to_user(zUser,zDate," on");
811 hyperlink_to_date(zDate, ".");
812 if( pDownloadName && blob_size(pDownloadName)==0 ){
813 blob_appendf(pDownloadName, "%.10s.txt", zUuid);
@@ -1260,10 +1265,90 @@
1260 }else
1261 {
1262 artifact_page();
1263 }
1264 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1265
1266 /*
1267 ** WEBPAGE: ci_edit
1268 ** URL: ci_edit?r=RID&c=NEWCOMMENT&u=NEWUSER
1269 **
@@ -1290,29 +1375,10 @@
1290 const char *zCloseFlag;
1291 int fPropagateColor;
1292 char *zUuid;
1293 Blob comment;
1294 Stmt q;
1295 static const struct SampleColors {
1296 const char *zCName;
1297 const char *zColor;
1298 } aColor[] = {
1299 { "(none)", "" },
1300 { "#f2dcdc", "#f2dcdc" },
1301 { "#f0ffc0", "#f0ffc0" },
1302 { "#bde5d6", "#bde5d6" },
1303 { "#c0ffc0", "#c0ffc0" },
1304 { "#c0fff0", "#c0fff0" },
1305 { "#c0f0ff", "#c0f0ff" },
1306 { "#d0c0ff", "#d0c0ff" },
1307 { "#ffc0ff", "#ffc0ff" },
1308 { "#ffc0d0", "#ffc0d0" },
1309 { "#fff0c0", "#fff0c0" },
1310 { "#c0c0c0", "#c0c0c0" },
1311 };
1312 int nColor = sizeof(aColor)/sizeof(aColor[0]);
1313 int i;
1314
1315 login_check_credentials();
1316 if( !g.okWrite ){ login_needed(); return; }
1317 rid = name_to_rid(P("r"));
1318 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
@@ -1332,10 +1398,13 @@
1332 if( zDate==0 ) fossil_redirect_home();
1333 zNewDate = PD("dt",zDate);
1334 zColor = db_text("", "SELECT bgcolor"
1335 " FROM event WHERE objid=%d", rid);
1336 zNewColor = PD("clr",zColor);
 
 
 
1337 fPropagateColor = P("pclr")!=0;
1338 zNewTagFlag = P("newtag") ? " checked" : "";
1339 zNewTag = PD("tagname","");
1340 zNewBrFlag = P("newbr") ? " checked" : "";
1341 zNewBranch = PD("brname","");
@@ -1474,66 +1543,40 @@
1474 @ <hr />
1475 blob_reset(&suffix);
1476 }
1477 @ <p>Make changes to attributes of check-in
1478 @ [<a href="ci?name=%s(zUuid)">%s(zUuid)</a>]:</p>
1479 @ <form action="%s(g.zBaseURL)/ci_edit" method="POST">
1480 login_insert_csrf_secret();
1481 @ <input type="hidden" name="r" value="%S(zUuid)">
1482 @ <table border="0" cellspacing="10">
1483
1484 @ <tr><td align="right" valign="top"><b>User:</b></td>
1485 @ <td valign="top">
1486 @ <input type="text" name="u" size="20" value="%h(zNewUser)">
1487 @ </td></tr>
1488
1489 @ <tr><td align="right" valign="top"><b>Comment:</b></td>
1490 @ <td valign="top">
1491 @ <textarea name="c" rows="10" cols="80">%h(zNewComment)</textarea>
1492 @ </td></tr>
1493
1494 @ <tr><td align="right" valign="top"><b>Check-in Time:</b></td>
1495 @ <td valign="top">
1496 @ <input type="text" name="dt" size="20" value="%h(zNewDate)">
1497 @ </td></tr>
1498
1499 @ <tr><td align="right" valign="top"><b>Background Color:</b></td>
1500 @ <td valign="top">
1501 @ <table border=0 cellpadding=0 cellspacing=1>
1502 @ <tr><td colspan="6" align="left">
1503 if( fPropagateColor ){
1504 @ <input type="checkbox" name="pclr" checked>
1505 }else{
1506 @ <input type="checkbox" name="pclr">
1507 }
1508 @ Propagate color to descendants</input></td></tr>
1509 @ <tr>
1510 for(i=0; i<nColor; i++){
1511 if( aColor[i].zColor[0] ){
1512 @ <td style="background-color: %h(aColor[i].zColor);">
1513 }else{
1514 @ <td>
1515 }
1516 if( strcmp(zNewColor, aColor[i].zColor)==0 ){
1517 @ <input type="radio" name="clr" value="%h(aColor[i].zColor)" checked>
1518 }else{
1519 @ <input type="radio" name="clr" value="%h(aColor[i].zColor)">
1520 }
1521 @ %h(aColor[i].zCName)</input></td>
1522 if( (i%6)==5 && i+1<nColor ){
1523 @ </tr><tr>
1524 }
1525 }
1526 @ </tr>
1527 @ </table>
1528 @ </td></tr>
1529
1530 @ <tr><td align="right" valign="top"><b>Tags:</b></td>
1531 @ <td valign="top">
1532 @ <input type="checkbox" name="newtag"%s(zNewTagFlag)>
1533 @ Add the following new tag name to this check-in:
1534 @ <input type="text" width="15" name="tagname" value="%h(zNewTag)">
1535 db_prepare(&q,
1536 "SELECT tag.tagid, tagname FROM tagxref, tag"
1537 " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid"
1538 " ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)"
1539 " ELSE tagname END",
@@ -1543,13 +1586,13 @@
1543 int tagid = db_column_int(&q, 0);
1544 const char *zTagName = db_column_text(&q, 1);
1545 char zLabel[30];
1546 sprintf(zLabel, "c%d", tagid);
1547 if( P(zLabel) ){
1548 @ <br /><input type="checkbox" name="c%d(tagid)" checked>
1549 }else{
1550 @ <br /><input type="checkbox" name="c%d(tagid)">
1551 }
1552 if( strncmp(zTagName, "sym-", 4)==0 ){
1553 @ Cancel tag <b>%h(&zTagName[4])</b>
1554 }else{
1555 @ Cancel special tag <b>%h(zTagName)</b>
@@ -1558,33 +1601,33 @@
1558 db_finalize(&q);
1559 @ </td></tr>
1560
1561 @ <tr><td align="right" valign="top"><b>Branching:</b></td>
1562 @ <td valign="top">
1563 @ <input type="checkbox" name="newbr"%s(zNewBrFlag)>
1564 @ Make this check-in the start of a new branch named:
1565 @ <input type="text" width="15" name="brname" value="%h(zNewBranch)">
1566 @ </td></tr>
1567
1568 if( is_a_leaf(rid)
1569 && !db_exists("SELECT 1 FROM tagxref "
1570 " WHERE tagid=%d AND rid=%d AND tagtype>0",
1571 TAG_CLOSED, rid)
1572 ){
1573 @ <tr><td align="right" valign="top"><b>Leaf Closure:</b></td>
1574 @ <td valign="top">
1575 @ <input type="checkbox" name="close"%s(zCloseFlag)>
1576 @ Mark this leaf as "closed" so that it no longer appears on the
1577 @ "leaves" page and is no longer labeled as a "<b>Leaf</b>".
1578 @ </td></tr>
1579 }
1580
1581
1582 @ <tr><td colspan="2">
1583 @ <input type="submit" name="preview" value="Preview">
1584 @ <input type="submit" name="apply" value="Apply Changes">
1585 @ <input type="submit" name="cancel" value="Cancel">
1586 @ </td></tr>
1587 @ </table>
1588 @ </form>
1589 style_footer();
1590 }
1591
--- src/info.c
+++ src/info.c
@@ -779,11 +779,11 @@
779 }
780 }
781 db_finalize(&q);
782 if( nWiki==0 ){
783 db_prepare(&q,
784 "SELECT datetime(mtime), user, comment, type, uuid, tagid"
785 " FROM event, blob"
786 " WHERE event.objid=%d"
787 " AND blob.rid=%d",
788 rid, rid
789 );
@@ -800,14 +800,19 @@
800 @ Wiki edit
801 }else if( zType[0]=='t' ){
802 @ Ticket change
803 }else if( zType[0]=='c' ){
804 @ Manifest of check-in
805 }else if( zType[0]=='e' ){
806 @ Instance of event
807 hyperlink_to_event_tagid(db_column_int(&q, 5));
808 }else{
809 @ Control file referencing
810 }
811 if( zType[0]!='e' ){
812 hyperlink_to_uuid(zUuid);
813 }
814 @ - %w(zCom) by
815 hyperlink_to_user(zUser,zDate," on");
816 hyperlink_to_date(zDate, ".");
817 if( pDownloadName && blob_size(pDownloadName)==0 ){
818 blob_appendf(pDownloadName, "%.10s.txt", zUuid);
@@ -1260,10 +1265,90 @@
1265 }else
1266 {
1267 artifact_page();
1268 }
1269 }
1270
1271 /*
1272 ** Generate HTML that will present the user with a selection of
1273 ** potential background colors for timeline entries.
1274 */
1275 void render_color_chooser(
1276 int fPropagate, /* Default value for propagation */
1277 const char *zDefaultColor, /* The current default color */
1278 const char *zIdPropagate, /* ID of form element checkbox. NULL for none */
1279 const char *zId, /* The ID of the form element */
1280 const char *zIdCustom /* ID of text box for custom color */
1281 ){
1282 static const struct SampleColors {
1283 const char *zCName;
1284 const char *zColor;
1285 } aColor[] = {
1286 { "(none)", "" },
1287 { "#f2dcdc", "#f2dcdc" },
1288 { "#f0ffc0", "#f0ffc0" },
1289 { "#bde5d6", "#bde5d6" },
1290 { "#c0ffc0", "#c0ffc0" },
1291 { "#c0fff0", "#c0fff0" },
1292 { "#c0f0ff", "#c0f0ff" },
1293 { "#d0c0ff", "#d0c0ff" },
1294 { "#ffc0ff", "#ffc0ff" },
1295 { "#ffc0d0", "#ffc0d0" },
1296 { "#fff0c0", "#fff0c0" },
1297 { "#c0c0c0", "#c0c0c0" },
1298 { "custom", "##" },
1299 };
1300 int nColor = sizeof(aColor)/sizeof(aColor[0])-1;
1301 int stdClrFound = 0;
1302 int i;
1303
1304 @ <table border="0" cellpadding="0" cellspacing="1">
1305 if( zIdPropagate ){
1306 @ <tr><td colspan="6" align="left">
1307 if( fPropagate ){
1308 @ <input type="checkbox" name="%s(zIdPropagate)" checked="checked" />
1309 }else{
1310 @ <input type="checkbox" name="%s(zIdPropagate)" />
1311 }
1312 @ Propagate color to descendants</td></tr>
1313 }
1314 @ <tr>
1315 for(i=0; i<nColor; i++){
1316 if( aColor[i].zColor[0] ){
1317 @ <td style="background-color: %h(aColor[i].zColor);">
1318 }else{
1319 @ <td>
1320 }
1321 if( strcmp(zDefaultColor, aColor[i].zColor)==0 ){
1322 @ <input type="radio" name="%s(zId)" value="%h(aColor[i].zColor)"
1323 @ checked="checked" />
1324 stdClrFound=1;
1325 }else{
1326 @ <input type="radio" name="%s(zId)" value="%h(aColor[i].zColor)" />
1327 }
1328 @ %h(aColor[i].zCName)</td>
1329 if( (i%6)==5 && i+1<nColor ){
1330 @ </tr><tr>
1331 }
1332 }
1333 @ </tr><tr>
1334 if (stdClrFound){
1335 @ <td colspan="6">
1336 @ <input type="radio" name="%s(zId)" value="%h(aColor[nColor].zColor)" />
1337 }else{
1338 @ <td style="background-color: %h(zDefaultColor);" colspan="6">
1339 @ <input type="radio" name="%s(zId)" value="%h(aColor[nColor].zColor)"
1340 @ checked="checked" />
1341 }
1342 @ %h(aColor[i].zCName)&nbsp;
1343 @ <input type="text" name="%s(zIdCustom)"
1344 @ id="%s(zIdCustom)" class="checkinUserColor"
1345 @ value="%h(stdClrFound?"":zDefaultColor)" />
1346 @ </td>
1347 @ </tr>
1348 @ </table>
1349 }
1350
1351 /*
1352 ** WEBPAGE: ci_edit
1353 ** URL: ci_edit?r=RID&c=NEWCOMMENT&u=NEWUSER
1354 **
@@ -1290,29 +1375,10 @@
1375 const char *zCloseFlag;
1376 int fPropagateColor;
1377 char *zUuid;
1378 Blob comment;
1379 Stmt q;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1380
1381 login_check_credentials();
1382 if( !g.okWrite ){ login_needed(); return; }
1383 rid = name_to_rid(P("r"));
1384 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
@@ -1332,10 +1398,13 @@
1398 if( zDate==0 ) fossil_redirect_home();
1399 zNewDate = PD("dt",zDate);
1400 zColor = db_text("", "SELECT bgcolor"
1401 " FROM event WHERE objid=%d", rid);
1402 zNewColor = PD("clr",zColor);
1403 if( strcmp(zNewColor,"##")==0 ){
1404 zNewColor = P("clrcust");
1405 }
1406 fPropagateColor = P("pclr")!=0;
1407 zNewTagFlag = P("newtag") ? " checked" : "";
1408 zNewTag = PD("tagname","");
1409 zNewBrFlag = P("newbr") ? " checked" : "";
1410 zNewBranch = PD("brname","");
@@ -1474,66 +1543,40 @@
1543 @ <hr />
1544 blob_reset(&suffix);
1545 }
1546 @ <p>Make changes to attributes of check-in
1547 @ [<a href="ci?name=%s(zUuid)">%s(zUuid)</a>]:</p>
1548 @ <form action="%s(g.zBaseURL)/ci_edit" method="post"><div>
1549 login_insert_csrf_secret();
1550 @ <input type="hidden" name="r" value="%S(zUuid)" />
1551 @ <table border="0" cellspacing="10">
1552
1553 @ <tr><td align="right" valign="top"><b>User:</b></td>
1554 @ <td valign="top">
1555 @ <input type="text" name="u" size="20" value="%h(zNewUser)" />
1556 @ </td></tr>
1557
1558 @ <tr><td align="right" valign="top"><b>Comment:</b></td>
1559 @ <td valign="top">
1560 @ <textarea name="c" rows="10" cols="80">%h(zNewComment)</textarea>
1561 @ </td></tr>
1562
1563 @ <tr><td align="right" valign="top"><b>Check-in Time:</b></td>
1564 @ <td valign="top">
1565 @ <input type="text" name="dt" size="20" value="%h(zNewDate)" />
1566 @ </td></tr>
1567
1568 @ <tr><td align="right" valign="top"><b>Background Color:</b></td>
1569 @ <td valign="top">
1570 render_color_chooser(fPropagateColor, zNewColor, "pclr", "clr", "clrcust");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1571 @ </td></tr>
1572
1573 @ <tr><td align="right" valign="top"><b>Tags:</b></td>
1574 @ <td valign="top">
1575 @ <input type="checkbox" name="newtag"%s(zNewTagFlag) />
1576 @ Add the following new tag name to this check-in:
1577 @ <input type="text" style="width:15;" name="tagname" value="%h(zNewTag)" />
1578 db_prepare(&q,
1579 "SELECT tag.tagid, tagname FROM tagxref, tag"
1580 " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid"
1581 " ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)"
1582 " ELSE tagname END",
@@ -1543,13 +1586,13 @@
1586 int tagid = db_column_int(&q, 0);
1587 const char *zTagName = db_column_text(&q, 1);
1588 char zLabel[30];
1589 sprintf(zLabel, "c%d", tagid);
1590 if( P(zLabel) ){
1591 @ <br /><input type="checkbox" name="c%d(tagid)" checked="checked" />
1592 }else{
1593 @ <br /><input type="checkbox" name="c%d(tagid)" />
1594 }
1595 if( strncmp(zTagName, "sym-", 4)==0 ){
1596 @ Cancel tag <b>%h(&zTagName[4])</b>
1597 }else{
1598 @ Cancel special tag <b>%h(zTagName)</b>
@@ -1558,33 +1601,33 @@
1601 db_finalize(&q);
1602 @ </td></tr>
1603
1604 @ <tr><td align="right" valign="top"><b>Branching:</b></td>
1605 @ <td valign="top">
1606 @ <input type="checkbox" name="newbr"%s(zNewBrFlag) />
1607 @ Make this check-in the start of a new branch named:
1608 @ <input type="text" style="width:15;" name="brname" value="%h(zNewBranch)" />
1609 @ </td></tr>
1610
1611 if( is_a_leaf(rid)
1612 && !db_exists("SELECT 1 FROM tagxref "
1613 " WHERE tagid=%d AND rid=%d AND tagtype>0",
1614 TAG_CLOSED, rid)
1615 ){
1616 @ <tr><td align="right" valign="top"><b>Leaf Closure:</b></td>
1617 @ <td valign="top">
1618 @ <input type="checkbox" name="close"%s(zCloseFlag) />
1619 @ Mark this leaf as "closed" so that it no longer appears on the
1620 @ "leaves" page and is no longer labeled as a "<b>Leaf</b>".
1621 @ </td></tr>
1622 }
1623
1624
1625 @ <tr><td colspan="2">
1626 @ <input type="submit" name="preview" value="Preview" />
1627 @ <input type="submit" name="apply" value="Apply Changes" />
1628 @ <input type="submit" name="cancel" value="Cancel" />
1629 @ </td></tr>
1630 @ </table>
1631 @ </div></form>
1632 style_footer();
1633 }
1634
+5 -4
--- src/main.c
+++ src/main.c
@@ -83,10 +83,11 @@
8383
FILE *httpOut; /* Send HTTP output here */
8484
int xlinkClusterOnly; /* Set when cloning. Only process clusters */
8585
int fTimeFormat; /* 1 for UTC. 2 for localtime. 0 not yet selected */
8686
int *aCommitFile; /* Array of files to be committed */
8787
int markPrivate; /* All new artifacts are private if true */
88
+ int clockSkewSeen; /* True if clocks on client and server out of sync */
8889
8990
int urlIsFile; /* True if a "file:" url */
9091
int urlIsHttps; /* True if a "https:" url */
9192
int urlIsSsh; /* True if an "ssh:" url */
9293
char *urlName; /* Hostname for http: or filename for file: */
@@ -290,11 +291,11 @@
290291
va_start(ap, zFormat);
291292
z = vmprintf(zFormat, ap);
292293
va_end(ap);
293294
if( g.cgiOutput && once ){
294295
once = 0;
295
- cgi_printf("<p><font color=\"red\">%h</font></p>", z);
296
+ cgi_printf("<p class=\"generalError\">%h</p>", z);
296297
cgi_reply();
297298
}else{
298299
fprintf(stderr, "%s: %s\n", g.argv[0], z);
299300
}
300301
db_force_rollback();
@@ -307,11 +308,11 @@
307308
va_start(ap, zFormat);
308309
z = vmprintf(zFormat, ap);
309310
va_end(ap);
310311
if( g.cgiOutput ){
311312
g.cgiOutput = 0;
312
- cgi_printf("<p><font color=\"red\">%h</font></p>", z);
313
+ cgi_printf("<p class=\"generalError\">%h</p>", z);
313314
cgi_reply();
314315
}else{
315316
fprintf(stderr, "%s: %s\n", g.argv[0], z);
316317
}
317318
db_force_rollback();
@@ -335,11 +336,11 @@
335336
va_start(ap, zFormat);
336337
z = vmprintf(zFormat, ap);
337338
va_end(ap);
338339
if( g.cgiOutput ){
339340
g.cgiOutput = 0;
340
- cgi_printf("<p><font color=\"red\">%h</font></p>", z);
341
+ cgi_printf("<p class=\"generalError\">%h</p>", z);
341342
cgi_reply();
342343
}else{
343344
fprintf(stderr, "%s: %s\n", g.argv[0], z);
344345
}
345346
db_force_rollback();
@@ -353,11 +354,11 @@
353354
va_list ap;
354355
va_start(ap, zFormat);
355356
z = vmprintf(zFormat, ap);
356357
va_end(ap);
357358
if( g.cgiOutput ){
358
- cgi_printf("<p><font color=\"red\">%h</font></p>", z);
359
+ cgi_printf("<p class=\"generalError\">%h</p>", z);
359360
}else{
360361
fprintf(stderr, "%s: %s\n", g.argv[0], z);
361362
}
362363
}
363364
364365
--- src/main.c
+++ src/main.c
@@ -83,10 +83,11 @@
83 FILE *httpOut; /* Send HTTP output here */
84 int xlinkClusterOnly; /* Set when cloning. Only process clusters */
85 int fTimeFormat; /* 1 for UTC. 2 for localtime. 0 not yet selected */
86 int *aCommitFile; /* Array of files to be committed */
87 int markPrivate; /* All new artifacts are private if true */
 
88
89 int urlIsFile; /* True if a "file:" url */
90 int urlIsHttps; /* True if a "https:" url */
91 int urlIsSsh; /* True if an "ssh:" url */
92 char *urlName; /* Hostname for http: or filename for file: */
@@ -290,11 +291,11 @@
290 va_start(ap, zFormat);
291 z = vmprintf(zFormat, ap);
292 va_end(ap);
293 if( g.cgiOutput && once ){
294 once = 0;
295 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
296 cgi_reply();
297 }else{
298 fprintf(stderr, "%s: %s\n", g.argv[0], z);
299 }
300 db_force_rollback();
@@ -307,11 +308,11 @@
307 va_start(ap, zFormat);
308 z = vmprintf(zFormat, ap);
309 va_end(ap);
310 if( g.cgiOutput ){
311 g.cgiOutput = 0;
312 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
313 cgi_reply();
314 }else{
315 fprintf(stderr, "%s: %s\n", g.argv[0], z);
316 }
317 db_force_rollback();
@@ -335,11 +336,11 @@
335 va_start(ap, zFormat);
336 z = vmprintf(zFormat, ap);
337 va_end(ap);
338 if( g.cgiOutput ){
339 g.cgiOutput = 0;
340 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
341 cgi_reply();
342 }else{
343 fprintf(stderr, "%s: %s\n", g.argv[0], z);
344 }
345 db_force_rollback();
@@ -353,11 +354,11 @@
353 va_list ap;
354 va_start(ap, zFormat);
355 z = vmprintf(zFormat, ap);
356 va_end(ap);
357 if( g.cgiOutput ){
358 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
359 }else{
360 fprintf(stderr, "%s: %s\n", g.argv[0], z);
361 }
362 }
363
364
--- src/main.c
+++ src/main.c
@@ -83,10 +83,11 @@
83 FILE *httpOut; /* Send HTTP output here */
84 int xlinkClusterOnly; /* Set when cloning. Only process clusters */
85 int fTimeFormat; /* 1 for UTC. 2 for localtime. 0 not yet selected */
86 int *aCommitFile; /* Array of files to be committed */
87 int markPrivate; /* All new artifacts are private if true */
88 int clockSkewSeen; /* True if clocks on client and server out of sync */
89
90 int urlIsFile; /* True if a "file:" url */
91 int urlIsHttps; /* True if a "https:" url */
92 int urlIsSsh; /* True if an "ssh:" url */
93 char *urlName; /* Hostname for http: or filename for file: */
@@ -290,11 +291,11 @@
291 va_start(ap, zFormat);
292 z = vmprintf(zFormat, ap);
293 va_end(ap);
294 if( g.cgiOutput && once ){
295 once = 0;
296 cgi_printf("<p class=\"generalError\">%h</p>", z);
297 cgi_reply();
298 }else{
299 fprintf(stderr, "%s: %s\n", g.argv[0], z);
300 }
301 db_force_rollback();
@@ -307,11 +308,11 @@
308 va_start(ap, zFormat);
309 z = vmprintf(zFormat, ap);
310 va_end(ap);
311 if( g.cgiOutput ){
312 g.cgiOutput = 0;
313 cgi_printf("<p class=\"generalError\">%h</p>", z);
314 cgi_reply();
315 }else{
316 fprintf(stderr, "%s: %s\n", g.argv[0], z);
317 }
318 db_force_rollback();
@@ -335,11 +336,11 @@
336 va_start(ap, zFormat);
337 z = vmprintf(zFormat, ap);
338 va_end(ap);
339 if( g.cgiOutput ){
340 g.cgiOutput = 0;
341 cgi_printf("<p class=\"generalError\">%h</p>", z);
342 cgi_reply();
343 }else{
344 fprintf(stderr, "%s: %s\n", g.argv[0], z);
345 }
346 db_force_rollback();
@@ -353,11 +354,11 @@
354 va_list ap;
355 va_start(ap, zFormat);
356 z = vmprintf(zFormat, ap);
357 va_end(ap);
358 if( g.cgiOutput ){
359 cgi_printf("<p class=\"generalError\">%h</p>", z);
360 }else{
361 fprintf(stderr, "%s: %s\n", g.argv[0], z);
362 }
363 }
364
365
+12 -2
--- src/main.mk
+++ src/main.mk
@@ -35,10 +35,11 @@
3535
$(SRCDIR)/descendants.c \
3636
$(SRCDIR)/diff.c \
3737
$(SRCDIR)/diffcmd.c \
3838
$(SRCDIR)/doc.c \
3939
$(SRCDIR)/encode.c \
40
+ $(SRCDIR)/event.c \
4041
$(SRCDIR)/file.c \
4142
$(SRCDIR)/finfo.c \
4243
$(SRCDIR)/graph.c \
4344
$(SRCDIR)/http.c \
4445
$(SRCDIR)/http_socket.c \
@@ -108,10 +109,11 @@
108109
descendants_.c \
109110
diff_.c \
110111
diffcmd_.c \
111112
doc_.c \
112113
encode_.c \
114
+ event_.c \
113115
file_.c \
114116
finfo_.c \
115117
graph_.c \
116118
http_.c \
117119
http_socket_.c \
@@ -181,10 +183,11 @@
181183
$(OBJDIR)/descendants.o \
182184
$(OBJDIR)/diff.o \
183185
$(OBJDIR)/diffcmd.o \
184186
$(OBJDIR)/doc.o \
185187
$(OBJDIR)/encode.o \
188
+ $(OBJDIR)/event.o \
186189
$(OBJDIR)/file.o \
187190
$(OBJDIR)/finfo.o \
188191
$(OBJDIR)/graph.o \
189192
$(OBJDIR)/http.o \
190193
$(OBJDIR)/http_socket.o \
@@ -273,16 +276,16 @@
273276
# noop
274277
275278
clean:
276279
rm -f $(OBJDIR)/*.o *_.c $(APPNAME) VERSION.h
277280
rm -f translate makeheaders mkindex page_index.h headers
278
- rm -f add.h allrepo.h attach.h bag.h blob.h branch.h browse.h captcha.h cgi.h checkin.h checkout.h clearsign.h clone.h comformat.h configure.h content.h db.h delta.h deltacmd.h descendants.h diff.h diffcmd.h doc.h encode.h file.h finfo.h graph.h http.h http_socket.h http_ssl.h http_transport.h info.h login.h main.h manifest.h md5.h merge.h merge3.h name.h pivot.h popen.h pqueue.h printf.h rebuild.h report.h rss.h schema.h search.h setup.h sha1.h shun.h skins.h stat.h style.h sync.h tag.h th_main.h timeline.h tkt.h tktsetup.h undo.h update.h url.h user.h verify.h vfile.h wiki.h wikiformat.h winhttp.h xfer.h zip.h
281
+ rm -f add.h allrepo.h attach.h bag.h blob.h branch.h browse.h captcha.h cgi.h checkin.h checkout.h clearsign.h clone.h comformat.h configure.h content.h db.h delta.h deltacmd.h descendants.h diff.h diffcmd.h doc.h encode.h event.h file.h finfo.h graph.h http.h http_socket.h http_ssl.h http_transport.h info.h login.h main.h manifest.h md5.h merge.h merge3.h name.h pivot.h popen.h pqueue.h printf.h rebuild.h report.h rss.h schema.h search.h setup.h sha1.h shun.h skins.h stat.h style.h sync.h tag.h th_main.h timeline.h tkt.h tktsetup.h undo.h update.h url.h user.h verify.h vfile.h wiki.h wikiformat.h winhttp.h xfer.h zip.h
279282
280283
page_index.h: $(TRANS_SRC) mkindex
281284
./mkindex $(TRANS_SRC) >$@
282285
headers: page_index.h makeheaders VERSION.h
283
- ./makeheaders add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h file_.c:file.h finfo_.c:finfo.h graph_.c:graph.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h info_.c:info.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h xfer_.c:xfer.h zip_.c:zip.h $(SRCDIR)/sqlite3.h $(SRCDIR)/th.h VERSION.h
286
+ ./makeheaders add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h event_.c:event.h file_.c:file.h finfo_.c:finfo.h graph_.c:graph.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h info_.c:info.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h xfer_.c:xfer.h zip_.c:zip.h $(SRCDIR)/sqlite3.h $(SRCDIR)/th.h VERSION.h
284287
touch headers
285288
headers: Makefile
286289
Makefile:
287290
add_.c: $(SRCDIR)/add.c translate
288291
./translate $(SRCDIR)/add.c >add_.c
@@ -450,10 +453,17 @@
450453
451454
$(OBJDIR)/encode.o: encode_.c encode.h $(SRCDIR)/config.h
452455
$(XTCC) -o $(OBJDIR)/encode.o -c encode_.c
453456
454457
encode.h: headers
458
+event_.c: $(SRCDIR)/event.c translate
459
+ ./translate $(SRCDIR)/event.c >event_.c
460
+
461
+$(OBJDIR)/event.o: event_.c event.h $(SRCDIR)/config.h
462
+ $(XTCC) -o $(OBJDIR)/event.o -c event_.c
463
+
464
+event.h: headers
455465
file_.c: $(SRCDIR)/file.c translate
456466
./translate $(SRCDIR)/file.c >file_.c
457467
458468
$(OBJDIR)/file.o: file_.c file.h $(SRCDIR)/config.h
459469
$(XTCC) -o $(OBJDIR)/file.o -c file_.c
460470
--- src/main.mk
+++ src/main.mk
@@ -35,10 +35,11 @@
35 $(SRCDIR)/descendants.c \
36 $(SRCDIR)/diff.c \
37 $(SRCDIR)/diffcmd.c \
38 $(SRCDIR)/doc.c \
39 $(SRCDIR)/encode.c \
 
40 $(SRCDIR)/file.c \
41 $(SRCDIR)/finfo.c \
42 $(SRCDIR)/graph.c \
43 $(SRCDIR)/http.c \
44 $(SRCDIR)/http_socket.c \
@@ -108,10 +109,11 @@
108 descendants_.c \
109 diff_.c \
110 diffcmd_.c \
111 doc_.c \
112 encode_.c \
 
113 file_.c \
114 finfo_.c \
115 graph_.c \
116 http_.c \
117 http_socket_.c \
@@ -181,10 +183,11 @@
181 $(OBJDIR)/descendants.o \
182 $(OBJDIR)/diff.o \
183 $(OBJDIR)/diffcmd.o \
184 $(OBJDIR)/doc.o \
185 $(OBJDIR)/encode.o \
 
186 $(OBJDIR)/file.o \
187 $(OBJDIR)/finfo.o \
188 $(OBJDIR)/graph.o \
189 $(OBJDIR)/http.o \
190 $(OBJDIR)/http_socket.o \
@@ -273,16 +276,16 @@
273 # noop
274
275 clean:
276 rm -f $(OBJDIR)/*.o *_.c $(APPNAME) VERSION.h
277 rm -f translate makeheaders mkindex page_index.h headers
278 rm -f add.h allrepo.h attach.h bag.h blob.h branch.h browse.h captcha.h cgi.h checkin.h checkout.h clearsign.h clone.h comformat.h configure.h content.h db.h delta.h deltacmd.h descendants.h diff.h diffcmd.h doc.h encode.h file.h finfo.h graph.h http.h http_socket.h http_ssl.h http_transport.h info.h login.h main.h manifest.h md5.h merge.h merge3.h name.h pivot.h popen.h pqueue.h printf.h rebuild.h report.h rss.h schema.h search.h setup.h sha1.h shun.h skins.h stat.h style.h sync.h tag.h th_main.h timeline.h tkt.h tktsetup.h undo.h update.h url.h user.h verify.h vfile.h wiki.h wikiformat.h winhttp.h xfer.h zip.h
279
280 page_index.h: $(TRANS_SRC) mkindex
281 ./mkindex $(TRANS_SRC) >$@
282 headers: page_index.h makeheaders VERSION.h
283 ./makeheaders add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h file_.c:file.h finfo_.c:finfo.h graph_.c:graph.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h info_.c:info.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h xfer_.c:xfer.h zip_.c:zip.h $(SRCDIR)/sqlite3.h $(SRCDIR)/th.h VERSION.h
284 touch headers
285 headers: Makefile
286 Makefile:
287 add_.c: $(SRCDIR)/add.c translate
288 ./translate $(SRCDIR)/add.c >add_.c
@@ -450,10 +453,17 @@
450
451 $(OBJDIR)/encode.o: encode_.c encode.h $(SRCDIR)/config.h
452 $(XTCC) -o $(OBJDIR)/encode.o -c encode_.c
453
454 encode.h: headers
 
 
 
 
 
 
 
455 file_.c: $(SRCDIR)/file.c translate
456 ./translate $(SRCDIR)/file.c >file_.c
457
458 $(OBJDIR)/file.o: file_.c file.h $(SRCDIR)/config.h
459 $(XTCC) -o $(OBJDIR)/file.o -c file_.c
460
--- src/main.mk
+++ src/main.mk
@@ -35,10 +35,11 @@
35 $(SRCDIR)/descendants.c \
36 $(SRCDIR)/diff.c \
37 $(SRCDIR)/diffcmd.c \
38 $(SRCDIR)/doc.c \
39 $(SRCDIR)/encode.c \
40 $(SRCDIR)/event.c \
41 $(SRCDIR)/file.c \
42 $(SRCDIR)/finfo.c \
43 $(SRCDIR)/graph.c \
44 $(SRCDIR)/http.c \
45 $(SRCDIR)/http_socket.c \
@@ -108,10 +109,11 @@
109 descendants_.c \
110 diff_.c \
111 diffcmd_.c \
112 doc_.c \
113 encode_.c \
114 event_.c \
115 file_.c \
116 finfo_.c \
117 graph_.c \
118 http_.c \
119 http_socket_.c \
@@ -181,10 +183,11 @@
183 $(OBJDIR)/descendants.o \
184 $(OBJDIR)/diff.o \
185 $(OBJDIR)/diffcmd.o \
186 $(OBJDIR)/doc.o \
187 $(OBJDIR)/encode.o \
188 $(OBJDIR)/event.o \
189 $(OBJDIR)/file.o \
190 $(OBJDIR)/finfo.o \
191 $(OBJDIR)/graph.o \
192 $(OBJDIR)/http.o \
193 $(OBJDIR)/http_socket.o \
@@ -273,16 +276,16 @@
276 # noop
277
278 clean:
279 rm -f $(OBJDIR)/*.o *_.c $(APPNAME) VERSION.h
280 rm -f translate makeheaders mkindex page_index.h headers
281 rm -f add.h allrepo.h attach.h bag.h blob.h branch.h browse.h captcha.h cgi.h checkin.h checkout.h clearsign.h clone.h comformat.h configure.h content.h db.h delta.h deltacmd.h descendants.h diff.h diffcmd.h doc.h encode.h event.h file.h finfo.h graph.h http.h http_socket.h http_ssl.h http_transport.h info.h login.h main.h manifest.h md5.h merge.h merge3.h name.h pivot.h popen.h pqueue.h printf.h rebuild.h report.h rss.h schema.h search.h setup.h sha1.h shun.h skins.h stat.h style.h sync.h tag.h th_main.h timeline.h tkt.h tktsetup.h undo.h update.h url.h user.h verify.h vfile.h wiki.h wikiformat.h winhttp.h xfer.h zip.h
282
283 page_index.h: $(TRANS_SRC) mkindex
284 ./mkindex $(TRANS_SRC) >$@
285 headers: page_index.h makeheaders VERSION.h
286 ./makeheaders add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h event_.c:event.h file_.c:file.h finfo_.c:finfo.h graph_.c:graph.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h info_.c:info.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h xfer_.c:xfer.h zip_.c:zip.h $(SRCDIR)/sqlite3.h $(SRCDIR)/th.h VERSION.h
287 touch headers
288 headers: Makefile
289 Makefile:
290 add_.c: $(SRCDIR)/add.c translate
291 ./translate $(SRCDIR)/add.c >add_.c
@@ -450,10 +453,17 @@
453
454 $(OBJDIR)/encode.o: encode_.c encode.h $(SRCDIR)/config.h
455 $(XTCC) -o $(OBJDIR)/encode.o -c encode_.c
456
457 encode.h: headers
458 event_.c: $(SRCDIR)/event.c translate
459 ./translate $(SRCDIR)/event.c >event_.c
460
461 $(OBJDIR)/event.o: event_.c event.h $(SRCDIR)/config.h
462 $(XTCC) -o $(OBJDIR)/event.o -c event_.c
463
464 event.h: headers
465 file_.c: $(SRCDIR)/file.c translate
466 ./translate $(SRCDIR)/file.c >file_.c
467
468 $(OBJDIR)/file.o: file_.c file.h $(SRCDIR)/config.h
469 $(XTCC) -o $(OBJDIR)/file.o -c file_.c
470
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -29,10 +29,11 @@
2929
descendants
3030
diff
3131
diffcmd
3232
doc
3333
encode
34
+ event
3435
file
3536
finfo
3637
graph
3738
http
3839
http_socket
3940
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -29,10 +29,11 @@
29 descendants
30 diff
31 diffcmd
32 doc
33 encode
 
34 file
35 finfo
36 graph
37 http
38 http_socket
39
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -29,10 +29,11 @@
29 descendants
30 diff
31 diffcmd
32 doc
33 encode
34 event
35 file
36 finfo
37 graph
38 http
39 http_socket
40
+101 -9
--- src/manifest.c
+++ src/manifest.c
@@ -32,10 +32,11 @@
3232
#define CFTYPE_CLUSTER 2
3333
#define CFTYPE_CONTROL 3
3434
#define CFTYPE_WIKI 4
3535
#define CFTYPE_TICKET 5
3636
#define CFTYPE_ATTACHMENT 6
37
+#define CFTYPE_EVENT 7
3738
3839
/*
3940
** A parsed manifest or cluster.
4041
*/
4142
struct Manifest {
@@ -45,10 +46,12 @@
4546
double rDate; /* Date and time from D card. 0.0 if no D card. */
4647
char *zUser; /* Name of the user from the U card. */
4748
char *zRepoCksum; /* MD5 checksum of the baseline content. R card. */
4849
char *zWiki; /* Text of the wiki page. W card. */
4950
char *zWikiTitle; /* Name of the wiki page. L card. */
51
+ double rEventDate; /* Date of an event. E card. */
52
+ char *zEventId; /* UUID for an event. E card. */
5053
char *zTicketUuid; /* UUID for a ticket. K card. */
5154
char *zAttachName; /* Filename of an attachment. A card. */
5255
char *zAttachSrc; /* UUID of document being attached. A card. */
5356
char *zAttachTarget; /* Ticket or wiki that attachment applies to. A card */
5457
int nFile; /* Number of F cards */
@@ -230,10 +233,35 @@
230233
if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
231234
zDate = blob_terminate(&a1);
232235
p->rDate = db_double(0.0, "SELECT julianday(%Q)", zDate);
233236
break;
234237
}
238
+
239
+ /*
240
+ ** E <timestamp> <uuid>
241
+ **
242
+ ** An "event" card that contains the timestamp of the event in the
243
+ ** format YYYY-MM-DDtHH:MM:SS and a unique identifier for the event.
244
+ ** The event timestamp is distinct from the D timestamp. The D
245
+ ** timestamp is when the artifact was created whereas the E timestamp
246
+ ** is when the specific event is said to occur.
247
+ */
248
+ case 'E': {
249
+ char *zEDate;
250
+ md5sum_step_text(blob_buffer(&line), blob_size(&line));
251
+ if( p->rEventDate!=0.0 ) goto manifest_syntax_error;
252
+ if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
253
+ if( blob_token(&line, &a2)==0 ) goto manifest_syntax_error;
254
+ if( blob_token(&line, &a3)!=0 ) goto manifest_syntax_error;
255
+ zEDate = blob_terminate(&a1);
256
+ p->rEventDate = db_double(0.0, "SELECT julianday(%Q)", zEDate);
257
+ if( p->rEventDate<=0.0 ) goto manifest_syntax_error;
258
+ if( blob_size(&a2)!=UUID_SIZE ) goto manifest_syntax_error;
259
+ p->zEventId = blob_terminate(&a2);
260
+ if( !validate16(p->zEventId, UUID_SIZE) ) goto manifest_syntax_error;
261
+ break;
262
+ }
235263
236264
/*
237265
** F <filename> <uuid> ?<permissions>? ?<old-name>?
238266
**
239267
** Identifies a file in a manifest. Multiple F lines are
@@ -405,12 +433,12 @@
405433
}
406434
407435
/*
408436
** R <md5sum>
409437
**
410
- ** Specify the MD5 checksum of the entire baseline in a
411
- ** manifest.
438
+ ** Specify the MD5 checksum over the name and content of all files
439
+ ** in the manifest.
412440
*/
413441
case 'R': {
414442
md5sum_step_text(blob_buffer(&line), blob_size(&line));
415443
if( p->zRepoCksum!=0 ) goto manifest_syntax_error;
416444
if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
@@ -563,15 +591,16 @@
563591
}
564592
if( !seenHeader ) goto manifest_syntax_error;
565593
566594
if( p->nFile>0 || p->zRepoCksum!=0 ){
567595
if( p->nCChild>0 ) goto manifest_syntax_error;
568
- if( p->rDate==0.0 ) goto manifest_syntax_error;
596
+ if( p->rDate<=0.0 ) goto manifest_syntax_error;
569597
if( p->nField>0 ) goto manifest_syntax_error;
570598
if( p->zTicketUuid ) goto manifest_syntax_error;
571599
if( p->zWiki ) goto manifest_syntax_error;
572600
if( p->zWikiTitle ) goto manifest_syntax_error;
601
+ if( p->zEventId ) goto manifest_syntax_error;
573602
if( p->zTicketUuid ) goto manifest_syntax_error;
574603
if( p->zAttachName ) goto manifest_syntax_error;
575604
p->type = CFTYPE_MANIFEST;
576605
}else if( p->nCChild>0 ){
577606
if( p->rDate>0.0 ) goto manifest_syntax_error;
@@ -581,26 +610,41 @@
581610
if( p->nParent>0 ) goto manifest_syntax_error;
582611
if( p->nField>0 ) goto manifest_syntax_error;
583612
if( p->zTicketUuid ) goto manifest_syntax_error;
584613
if( p->zWiki ) goto manifest_syntax_error;
585614
if( p->zWikiTitle ) goto manifest_syntax_error;
615
+ if( p->zEventId ) goto manifest_syntax_error;
586616
if( p->zAttachName ) goto manifest_syntax_error;
587617
if( !seenZ ) goto manifest_syntax_error;
588618
p->type = CFTYPE_CLUSTER;
589619
}else if( p->nField>0 ){
590
- if( p->rDate==0.0 ) goto manifest_syntax_error;
620
+ if( p->rDate<=0.0 ) goto manifest_syntax_error;
591621
if( p->zWiki ) goto manifest_syntax_error;
592622
if( p->zWikiTitle ) goto manifest_syntax_error;
623
+ if( p->zEventId ) goto manifest_syntax_error;
593624
if( p->nCChild>0 ) goto manifest_syntax_error;
594625
if( p->nTag>0 ) goto manifest_syntax_error;
595626
if( p->zTicketUuid==0 ) goto manifest_syntax_error;
596627
if( p->zUser==0 ) goto manifest_syntax_error;
597628
if( p->zAttachName ) goto manifest_syntax_error;
598629
if( !seenZ ) goto manifest_syntax_error;
599630
p->type = CFTYPE_TICKET;
631
+ }else if( p->zEventId ){
632
+ if( p->rDate<=0.0 ) goto manifest_syntax_error;
633
+ if( p->nCChild>0 ) goto manifest_syntax_error;
634
+ if( p->zTicketUuid!=0 ) goto manifest_syntax_error;
635
+ if( p->zWikiTitle!=0 ) goto manifest_syntax_error;
636
+ if( p->zWiki==0 ) goto manifest_syntax_error;
637
+ if( p->zAttachName ) goto manifest_syntax_error;
638
+ for(i=0; i<p->nTag; i++){
639
+ if( p->aTag[i].zName[0]!='+' ) goto manifest_syntax_error;
640
+ if( p->aTag[i].zUuid!=0 ) goto manifest_syntax_error;
641
+ }
642
+ if( !seenZ ) goto manifest_syntax_error;
643
+ p->type = CFTYPE_EVENT;
600644
}else if( p->zWiki!=0 ){
601
- if( p->rDate==0.0 ) goto manifest_syntax_error;
645
+ if( p->rDate<=0.0 ) goto manifest_syntax_error;
602646
if( p->nCChild>0 ) goto manifest_syntax_error;
603647
if( p->nTag>0 ) goto manifest_syntax_error;
604648
if( p->zTicketUuid!=0 ) goto manifest_syntax_error;
605649
if( p->zWikiTitle==0 ) goto manifest_syntax_error;
606650
if( p->zAttachName ) goto manifest_syntax_error;
@@ -614,11 +658,11 @@
614658
if( p->zAttachName ) goto manifest_syntax_error;
615659
if( !seenZ ) goto manifest_syntax_error;
616660
p->type = CFTYPE_CONTROL;
617661
}else if( p->zAttachName ){
618662
if( p->nCChild>0 ) goto manifest_syntax_error;
619
- if( p->rDate==0.0 ) goto manifest_syntax_error;
663
+ if( p->rDate<=0.0 ) goto manifest_syntax_error;
620664
if( p->zTicketUuid ) goto manifest_syntax_error;
621665
if( p->zWikiTitle ) goto manifest_syntax_error;
622666
if( !seenZ ) goto manifest_syntax_error;
623667
p->type = CFTYPE_ATTACHMENT;
624668
}else{
@@ -625,14 +669,12 @@
625669
if( p->nCChild>0 ) goto manifest_syntax_error;
626670
if( p->rDate<=0.0 ) goto manifest_syntax_error;
627671
if( p->nParent>0 ) goto manifest_syntax_error;
628672
if( p->nField>0 ) goto manifest_syntax_error;
629673
if( p->zTicketUuid ) goto manifest_syntax_error;
630
- if( p->zWiki ) goto manifest_syntax_error;
631674
if( p->zWikiTitle ) goto manifest_syntax_error;
632675
if( p->zTicketUuid ) goto manifest_syntax_error;
633
- if( p->zAttachName ) goto manifest_syntax_error;
634676
p->type = CFTYPE_MANIFEST;
635677
}
636678
md5sum_init();
637679
return 1;
638680
@@ -964,10 +1006,12 @@
9641006
** * Manifest
9651007
** * Control
9661008
** * Wiki Page
9671009
** * Ticket Change
9681010
** * Cluster
1011
+** * Attachment
1012
+** * Event
9691013
**
9701014
** If the input is a control artifact, then make appropriate entries
9711015
** in the auxiliary tables of the database in order to crosslink the
9721016
** artifact.
9731017
**
@@ -1043,11 +1087,14 @@
10431087
if( mid>0 ){
10441088
db_multi_exec("DELETE FROM unclustered WHERE rid=%d", mid);
10451089
}
10461090
}
10471091
}
1048
- if( m.type==CFTYPE_CONTROL || m.type==CFTYPE_MANIFEST ){
1092
+ if( m.type==CFTYPE_CONTROL
1093
+ || m.type==CFTYPE_MANIFEST
1094
+ || m.type==CFTYPE_EVENT
1095
+ ){
10491096
for(i=0; i<m.nTag; i++){
10501097
int tid;
10511098
int type;
10521099
if( m.aTag[i].zUuid ){
10531100
tid = uuid_to_rid(m.aTag[i].zUuid, 1);
@@ -1109,10 +1156,55 @@
11091156
TAG_BGCOLOR, rid,
11101157
TAG_USER, rid,
11111158
TAG_COMMENT, rid
11121159
);
11131160
free(zComment);
1161
+ }
1162
+ if( m.type==CFTYPE_EVENT ){
1163
+ char *zTag = mprintf("event-%s", m.zEventId);
1164
+ int tagid = tag_findid(zTag, 1);
1165
+ int prior, subsequent;
1166
+ int nWiki;
1167
+ char zLength[40];
1168
+ while( isspace(m.zWiki[0]) ) m.zWiki++;
1169
+ nWiki = strlen(m.zWiki);
1170
+ sqlite3_snprintf(sizeof(zLength), zLength, "%d", nWiki);
1171
+ tag_insert(zTag, 1, zLength, rid, m.rDate, rid);
1172
+ free(zTag);
1173
+ prior = db_int(0,
1174
+ "SELECT rid FROM tagxref"
1175
+ " WHERE tagid=%d AND mtime<%.17g"
1176
+ " ORDER BY mtime DESC",
1177
+ tagid, m.rDate
1178
+ );
1179
+ if( prior ){
1180
+ content_deltify(prior, rid, 0);
1181
+ db_multi_exec(
1182
+ "DELETE FROM event"
1183
+ " WHERE type='e'"
1184
+ " AND tagid=%d"
1185
+ " AND objid IN (SELECT rid FROM tagxref WHERE tagid=%d)",
1186
+ tagid, tagid
1187
+ );
1188
+ }
1189
+ subsequent = db_int(0,
1190
+ "SELECT rid FROM tagxref"
1191
+ " WHERE tagid=%d AND mtime>%.17g"
1192
+ " ORDER BY mtime",
1193
+ tagid, m.rDate
1194
+ );
1195
+ if( subsequent ){
1196
+ content_deltify(rid, subsequent, 0);
1197
+ }else{
1198
+ db_multi_exec(
1199
+ "REPLACE INTO event(type,mtime,objid,tagid,user,comment,bgcolor)"
1200
+ "VALUES('e',%.17g,%d,%d,%Q,%Q,"
1201
+ " (SELECT value FROM tagxref WHERE tagid=%d AND rid=%d));",
1202
+ m.rEventDate, rid, tagid, m.zUser, m.zComment,
1203
+ TAG_BGCOLOR, rid
1204
+ );
1205
+ }
11141206
}
11151207
if( m.type==CFTYPE_TICKET ){
11161208
char *zTag;
11171209
11181210
assert( manifest_crosslink_busy==1 );
11191211
--- src/manifest.c
+++ src/manifest.c
@@ -32,10 +32,11 @@
32 #define CFTYPE_CLUSTER 2
33 #define CFTYPE_CONTROL 3
34 #define CFTYPE_WIKI 4
35 #define CFTYPE_TICKET 5
36 #define CFTYPE_ATTACHMENT 6
 
37
38 /*
39 ** A parsed manifest or cluster.
40 */
41 struct Manifest {
@@ -45,10 +46,12 @@
45 double rDate; /* Date and time from D card. 0.0 if no D card. */
46 char *zUser; /* Name of the user from the U card. */
47 char *zRepoCksum; /* MD5 checksum of the baseline content. R card. */
48 char *zWiki; /* Text of the wiki page. W card. */
49 char *zWikiTitle; /* Name of the wiki page. L card. */
 
 
50 char *zTicketUuid; /* UUID for a ticket. K card. */
51 char *zAttachName; /* Filename of an attachment. A card. */
52 char *zAttachSrc; /* UUID of document being attached. A card. */
53 char *zAttachTarget; /* Ticket or wiki that attachment applies to. A card */
54 int nFile; /* Number of F cards */
@@ -230,10 +233,35 @@
230 if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
231 zDate = blob_terminate(&a1);
232 p->rDate = db_double(0.0, "SELECT julianday(%Q)", zDate);
233 break;
234 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
236 /*
237 ** F <filename> <uuid> ?<permissions>? ?<old-name>?
238 **
239 ** Identifies a file in a manifest. Multiple F lines are
@@ -405,12 +433,12 @@
405 }
406
407 /*
408 ** R <md5sum>
409 **
410 ** Specify the MD5 checksum of the entire baseline in a
411 ** manifest.
412 */
413 case 'R': {
414 md5sum_step_text(blob_buffer(&line), blob_size(&line));
415 if( p->zRepoCksum!=0 ) goto manifest_syntax_error;
416 if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
@@ -563,15 +591,16 @@
563 }
564 if( !seenHeader ) goto manifest_syntax_error;
565
566 if( p->nFile>0 || p->zRepoCksum!=0 ){
567 if( p->nCChild>0 ) goto manifest_syntax_error;
568 if( p->rDate==0.0 ) goto manifest_syntax_error;
569 if( p->nField>0 ) goto manifest_syntax_error;
570 if( p->zTicketUuid ) goto manifest_syntax_error;
571 if( p->zWiki ) goto manifest_syntax_error;
572 if( p->zWikiTitle ) goto manifest_syntax_error;
 
573 if( p->zTicketUuid ) goto manifest_syntax_error;
574 if( p->zAttachName ) goto manifest_syntax_error;
575 p->type = CFTYPE_MANIFEST;
576 }else if( p->nCChild>0 ){
577 if( p->rDate>0.0 ) goto manifest_syntax_error;
@@ -581,26 +610,41 @@
581 if( p->nParent>0 ) goto manifest_syntax_error;
582 if( p->nField>0 ) goto manifest_syntax_error;
583 if( p->zTicketUuid ) goto manifest_syntax_error;
584 if( p->zWiki ) goto manifest_syntax_error;
585 if( p->zWikiTitle ) goto manifest_syntax_error;
 
586 if( p->zAttachName ) goto manifest_syntax_error;
587 if( !seenZ ) goto manifest_syntax_error;
588 p->type = CFTYPE_CLUSTER;
589 }else if( p->nField>0 ){
590 if( p->rDate==0.0 ) goto manifest_syntax_error;
591 if( p->zWiki ) goto manifest_syntax_error;
592 if( p->zWikiTitle ) goto manifest_syntax_error;
 
593 if( p->nCChild>0 ) goto manifest_syntax_error;
594 if( p->nTag>0 ) goto manifest_syntax_error;
595 if( p->zTicketUuid==0 ) goto manifest_syntax_error;
596 if( p->zUser==0 ) goto manifest_syntax_error;
597 if( p->zAttachName ) goto manifest_syntax_error;
598 if( !seenZ ) goto manifest_syntax_error;
599 p->type = CFTYPE_TICKET;
 
 
 
 
 
 
 
 
 
 
 
 
 
600 }else if( p->zWiki!=0 ){
601 if( p->rDate==0.0 ) goto manifest_syntax_error;
602 if( p->nCChild>0 ) goto manifest_syntax_error;
603 if( p->nTag>0 ) goto manifest_syntax_error;
604 if( p->zTicketUuid!=0 ) goto manifest_syntax_error;
605 if( p->zWikiTitle==0 ) goto manifest_syntax_error;
606 if( p->zAttachName ) goto manifest_syntax_error;
@@ -614,11 +658,11 @@
614 if( p->zAttachName ) goto manifest_syntax_error;
615 if( !seenZ ) goto manifest_syntax_error;
616 p->type = CFTYPE_CONTROL;
617 }else if( p->zAttachName ){
618 if( p->nCChild>0 ) goto manifest_syntax_error;
619 if( p->rDate==0.0 ) goto manifest_syntax_error;
620 if( p->zTicketUuid ) goto manifest_syntax_error;
621 if( p->zWikiTitle ) goto manifest_syntax_error;
622 if( !seenZ ) goto manifest_syntax_error;
623 p->type = CFTYPE_ATTACHMENT;
624 }else{
@@ -625,14 +669,12 @@
625 if( p->nCChild>0 ) goto manifest_syntax_error;
626 if( p->rDate<=0.0 ) goto manifest_syntax_error;
627 if( p->nParent>0 ) goto manifest_syntax_error;
628 if( p->nField>0 ) goto manifest_syntax_error;
629 if( p->zTicketUuid ) goto manifest_syntax_error;
630 if( p->zWiki ) goto manifest_syntax_error;
631 if( p->zWikiTitle ) goto manifest_syntax_error;
632 if( p->zTicketUuid ) goto manifest_syntax_error;
633 if( p->zAttachName ) goto manifest_syntax_error;
634 p->type = CFTYPE_MANIFEST;
635 }
636 md5sum_init();
637 return 1;
638
@@ -964,10 +1006,12 @@
964 ** * Manifest
965 ** * Control
966 ** * Wiki Page
967 ** * Ticket Change
968 ** * Cluster
 
 
969 **
970 ** If the input is a control artifact, then make appropriate entries
971 ** in the auxiliary tables of the database in order to crosslink the
972 ** artifact.
973 **
@@ -1043,11 +1087,14 @@
1043 if( mid>0 ){
1044 db_multi_exec("DELETE FROM unclustered WHERE rid=%d", mid);
1045 }
1046 }
1047 }
1048 if( m.type==CFTYPE_CONTROL || m.type==CFTYPE_MANIFEST ){
 
 
 
1049 for(i=0; i<m.nTag; i++){
1050 int tid;
1051 int type;
1052 if( m.aTag[i].zUuid ){
1053 tid = uuid_to_rid(m.aTag[i].zUuid, 1);
@@ -1109,10 +1156,55 @@
1109 TAG_BGCOLOR, rid,
1110 TAG_USER, rid,
1111 TAG_COMMENT, rid
1112 );
1113 free(zComment);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1114 }
1115 if( m.type==CFTYPE_TICKET ){
1116 char *zTag;
1117
1118 assert( manifest_crosslink_busy==1 );
1119
--- src/manifest.c
+++ src/manifest.c
@@ -32,10 +32,11 @@
32 #define CFTYPE_CLUSTER 2
33 #define CFTYPE_CONTROL 3
34 #define CFTYPE_WIKI 4
35 #define CFTYPE_TICKET 5
36 #define CFTYPE_ATTACHMENT 6
37 #define CFTYPE_EVENT 7
38
39 /*
40 ** A parsed manifest or cluster.
41 */
42 struct Manifest {
@@ -45,10 +46,12 @@
46 double rDate; /* Date and time from D card. 0.0 if no D card. */
47 char *zUser; /* Name of the user from the U card. */
48 char *zRepoCksum; /* MD5 checksum of the baseline content. R card. */
49 char *zWiki; /* Text of the wiki page. W card. */
50 char *zWikiTitle; /* Name of the wiki page. L card. */
51 double rEventDate; /* Date of an event. E card. */
52 char *zEventId; /* UUID for an event. E card. */
53 char *zTicketUuid; /* UUID for a ticket. K card. */
54 char *zAttachName; /* Filename of an attachment. A card. */
55 char *zAttachSrc; /* UUID of document being attached. A card. */
56 char *zAttachTarget; /* Ticket or wiki that attachment applies to. A card */
57 int nFile; /* Number of F cards */
@@ -230,10 +233,35 @@
233 if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error;
234 zDate = blob_terminate(&a1);
235 p->rDate = db_double(0.0, "SELECT julianday(%Q)", zDate);
236 break;
237 }
238
239 /*
240 ** E <timestamp> <uuid>
241 **
242 ** An "event" card that contains the timestamp of the event in the
243 ** format YYYY-MM-DDtHH:MM:SS and a unique identifier for the event.
244 ** The event timestamp is distinct from the D timestamp. The D
245 ** timestamp is when the artifact was created whereas the E timestamp
246 ** is when the specific event is said to occur.
247 */
248 case 'E': {
249 char *zEDate;
250 md5sum_step_text(blob_buffer(&line), blob_size(&line));
251 if( p->rEventDate!=0.0 ) goto manifest_syntax_error;
252 if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
253 if( blob_token(&line, &a2)==0 ) goto manifest_syntax_error;
254 if( blob_token(&line, &a3)!=0 ) goto manifest_syntax_error;
255 zEDate = blob_terminate(&a1);
256 p->rEventDate = db_double(0.0, "SELECT julianday(%Q)", zEDate);
257 if( p->rEventDate<=0.0 ) goto manifest_syntax_error;
258 if( blob_size(&a2)!=UUID_SIZE ) goto manifest_syntax_error;
259 p->zEventId = blob_terminate(&a2);
260 if( !validate16(p->zEventId, UUID_SIZE) ) goto manifest_syntax_error;
261 break;
262 }
263
264 /*
265 ** F <filename> <uuid> ?<permissions>? ?<old-name>?
266 **
267 ** Identifies a file in a manifest. Multiple F lines are
@@ -405,12 +433,12 @@
433 }
434
435 /*
436 ** R <md5sum>
437 **
438 ** Specify the MD5 checksum over the name and content of all files
439 ** in the manifest.
440 */
441 case 'R': {
442 md5sum_step_text(blob_buffer(&line), blob_size(&line));
443 if( p->zRepoCksum!=0 ) goto manifest_syntax_error;
444 if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error;
@@ -563,15 +591,16 @@
591 }
592 if( !seenHeader ) goto manifest_syntax_error;
593
594 if( p->nFile>0 || p->zRepoCksum!=0 ){
595 if( p->nCChild>0 ) goto manifest_syntax_error;
596 if( p->rDate<=0.0 ) goto manifest_syntax_error;
597 if( p->nField>0 ) goto manifest_syntax_error;
598 if( p->zTicketUuid ) goto manifest_syntax_error;
599 if( p->zWiki ) goto manifest_syntax_error;
600 if( p->zWikiTitle ) goto manifest_syntax_error;
601 if( p->zEventId ) goto manifest_syntax_error;
602 if( p->zTicketUuid ) goto manifest_syntax_error;
603 if( p->zAttachName ) goto manifest_syntax_error;
604 p->type = CFTYPE_MANIFEST;
605 }else if( p->nCChild>0 ){
606 if( p->rDate>0.0 ) goto manifest_syntax_error;
@@ -581,26 +610,41 @@
610 if( p->nParent>0 ) goto manifest_syntax_error;
611 if( p->nField>0 ) goto manifest_syntax_error;
612 if( p->zTicketUuid ) goto manifest_syntax_error;
613 if( p->zWiki ) goto manifest_syntax_error;
614 if( p->zWikiTitle ) goto manifest_syntax_error;
615 if( p->zEventId ) goto manifest_syntax_error;
616 if( p->zAttachName ) goto manifest_syntax_error;
617 if( !seenZ ) goto manifest_syntax_error;
618 p->type = CFTYPE_CLUSTER;
619 }else if( p->nField>0 ){
620 if( p->rDate<=0.0 ) goto manifest_syntax_error;
621 if( p->zWiki ) goto manifest_syntax_error;
622 if( p->zWikiTitle ) goto manifest_syntax_error;
623 if( p->zEventId ) goto manifest_syntax_error;
624 if( p->nCChild>0 ) goto manifest_syntax_error;
625 if( p->nTag>0 ) goto manifest_syntax_error;
626 if( p->zTicketUuid==0 ) goto manifest_syntax_error;
627 if( p->zUser==0 ) goto manifest_syntax_error;
628 if( p->zAttachName ) goto manifest_syntax_error;
629 if( !seenZ ) goto manifest_syntax_error;
630 p->type = CFTYPE_TICKET;
631 }else if( p->zEventId ){
632 if( p->rDate<=0.0 ) goto manifest_syntax_error;
633 if( p->nCChild>0 ) goto manifest_syntax_error;
634 if( p->zTicketUuid!=0 ) goto manifest_syntax_error;
635 if( p->zWikiTitle!=0 ) goto manifest_syntax_error;
636 if( p->zWiki==0 ) goto manifest_syntax_error;
637 if( p->zAttachName ) goto manifest_syntax_error;
638 for(i=0; i<p->nTag; i++){
639 if( p->aTag[i].zName[0]!='+' ) goto manifest_syntax_error;
640 if( p->aTag[i].zUuid!=0 ) goto manifest_syntax_error;
641 }
642 if( !seenZ ) goto manifest_syntax_error;
643 p->type = CFTYPE_EVENT;
644 }else if( p->zWiki!=0 ){
645 if( p->rDate<=0.0 ) goto manifest_syntax_error;
646 if( p->nCChild>0 ) goto manifest_syntax_error;
647 if( p->nTag>0 ) goto manifest_syntax_error;
648 if( p->zTicketUuid!=0 ) goto manifest_syntax_error;
649 if( p->zWikiTitle==0 ) goto manifest_syntax_error;
650 if( p->zAttachName ) goto manifest_syntax_error;
@@ -614,11 +658,11 @@
658 if( p->zAttachName ) goto manifest_syntax_error;
659 if( !seenZ ) goto manifest_syntax_error;
660 p->type = CFTYPE_CONTROL;
661 }else if( p->zAttachName ){
662 if( p->nCChild>0 ) goto manifest_syntax_error;
663 if( p->rDate<=0.0 ) goto manifest_syntax_error;
664 if( p->zTicketUuid ) goto manifest_syntax_error;
665 if( p->zWikiTitle ) goto manifest_syntax_error;
666 if( !seenZ ) goto manifest_syntax_error;
667 p->type = CFTYPE_ATTACHMENT;
668 }else{
@@ -625,14 +669,12 @@
669 if( p->nCChild>0 ) goto manifest_syntax_error;
670 if( p->rDate<=0.0 ) goto manifest_syntax_error;
671 if( p->nParent>0 ) goto manifest_syntax_error;
672 if( p->nField>0 ) goto manifest_syntax_error;
673 if( p->zTicketUuid ) goto manifest_syntax_error;
 
674 if( p->zWikiTitle ) goto manifest_syntax_error;
675 if( p->zTicketUuid ) goto manifest_syntax_error;
 
676 p->type = CFTYPE_MANIFEST;
677 }
678 md5sum_init();
679 return 1;
680
@@ -964,10 +1006,12 @@
1006 ** * Manifest
1007 ** * Control
1008 ** * Wiki Page
1009 ** * Ticket Change
1010 ** * Cluster
1011 ** * Attachment
1012 ** * Event
1013 **
1014 ** If the input is a control artifact, then make appropriate entries
1015 ** in the auxiliary tables of the database in order to crosslink the
1016 ** artifact.
1017 **
@@ -1043,11 +1087,14 @@
1087 if( mid>0 ){
1088 db_multi_exec("DELETE FROM unclustered WHERE rid=%d", mid);
1089 }
1090 }
1091 }
1092 if( m.type==CFTYPE_CONTROL
1093 || m.type==CFTYPE_MANIFEST
1094 || m.type==CFTYPE_EVENT
1095 ){
1096 for(i=0; i<m.nTag; i++){
1097 int tid;
1098 int type;
1099 if( m.aTag[i].zUuid ){
1100 tid = uuid_to_rid(m.aTag[i].zUuid, 1);
@@ -1109,10 +1156,55 @@
1156 TAG_BGCOLOR, rid,
1157 TAG_USER, rid,
1158 TAG_COMMENT, rid
1159 );
1160 free(zComment);
1161 }
1162 if( m.type==CFTYPE_EVENT ){
1163 char *zTag = mprintf("event-%s", m.zEventId);
1164 int tagid = tag_findid(zTag, 1);
1165 int prior, subsequent;
1166 int nWiki;
1167 char zLength[40];
1168 while( isspace(m.zWiki[0]) ) m.zWiki++;
1169 nWiki = strlen(m.zWiki);
1170 sqlite3_snprintf(sizeof(zLength), zLength, "%d", nWiki);
1171 tag_insert(zTag, 1, zLength, rid, m.rDate, rid);
1172 free(zTag);
1173 prior = db_int(0,
1174 "SELECT rid FROM tagxref"
1175 " WHERE tagid=%d AND mtime<%.17g"
1176 " ORDER BY mtime DESC",
1177 tagid, m.rDate
1178 );
1179 if( prior ){
1180 content_deltify(prior, rid, 0);
1181 db_multi_exec(
1182 "DELETE FROM event"
1183 " WHERE type='e'"
1184 " AND tagid=%d"
1185 " AND objid IN (SELECT rid FROM tagxref WHERE tagid=%d)",
1186 tagid, tagid
1187 );
1188 }
1189 subsequent = db_int(0,
1190 "SELECT rid FROM tagxref"
1191 " WHERE tagid=%d AND mtime>%.17g"
1192 " ORDER BY mtime",
1193 tagid, m.rDate
1194 );
1195 if( subsequent ){
1196 content_deltify(rid, subsequent, 0);
1197 }else{
1198 db_multi_exec(
1199 "REPLACE INTO event(type,mtime,objid,tagid,user,comment,bgcolor)"
1200 "VALUES('e',%.17g,%d,%d,%Q,%Q,"
1201 " (SELECT value FROM tagxref WHERE tagid=%d AND rid=%d));",
1202 m.rEventDate, rid, tagid, m.zUser, m.zComment,
1203 TAG_BGCOLOR, rid
1204 );
1205 }
1206 }
1207 if( m.type==CFTYPE_TICKET ){
1208 char *zTag;
1209
1210 assert( manifest_crosslink_busy==1 );
1211
+3 -3
--- src/printf.c
+++ src/printf.c
@@ -44,13 +44,13 @@
4444
#define etHTMLIZE 16 /* Make text safe for HTML */
4545
#define etHTTPIZE 17 /* Make text safe for HTTP. "/" encoded as %2f */
4646
#define etURLIZE 18 /* Make text safe for HTTP. "/" not encoded */
4747
#define etFOSSILIZE 19 /* The fossil header encoding format. */
4848
#define etPATH 20 /* Path type */
49
-#define etWIKISTR 21 /* Wiki text rendered from a char* */
50
-#define etWIKIBLOB 22 /* Wiki text rendered from a Blob* */
51
-#define etSTRINGID 23 /* String with length limit for a UUID prefix */
49
+#define etWIKISTR 21 /* Wiki text rendered from a char*: %w */
50
+#define etWIKIBLOB 22 /* Wiki text rendered from a Blob*: %W */
51
+#define etSTRINGID 23 /* String with length limit for a UUID prefix: %S */
5252
5353
5454
/*
5555
** An "etByte" is an 8-bit unsigned value.
5656
*/
5757
--- src/printf.c
+++ src/printf.c
@@ -44,13 +44,13 @@
44 #define etHTMLIZE 16 /* Make text safe for HTML */
45 #define etHTTPIZE 17 /* Make text safe for HTTP. "/" encoded as %2f */
46 #define etURLIZE 18 /* Make text safe for HTTP. "/" not encoded */
47 #define etFOSSILIZE 19 /* The fossil header encoding format. */
48 #define etPATH 20 /* Path type */
49 #define etWIKISTR 21 /* Wiki text rendered from a char* */
50 #define etWIKIBLOB 22 /* Wiki text rendered from a Blob* */
51 #define etSTRINGID 23 /* String with length limit for a UUID prefix */
52
53
54 /*
55 ** An "etByte" is an 8-bit unsigned value.
56 */
57
--- src/printf.c
+++ src/printf.c
@@ -44,13 +44,13 @@
44 #define etHTMLIZE 16 /* Make text safe for HTML */
45 #define etHTTPIZE 17 /* Make text safe for HTTP. "/" encoded as %2f */
46 #define etURLIZE 18 /* Make text safe for HTTP. "/" not encoded */
47 #define etFOSSILIZE 19 /* The fossil header encoding format. */
48 #define etPATH 20 /* Path type */
49 #define etWIKISTR 21 /* Wiki text rendered from a char*: %w */
50 #define etWIKIBLOB 22 /* Wiki text rendered from a Blob*: %W */
51 #define etSTRINGID 23 /* String with length limit for a UUID prefix: %S */
52
53
54 /*
55 ** An "etByte" is an 8-bit unsigned value.
56 */
57
+244 -86
--- src/rebuild.c
+++ src/rebuild.c
@@ -72,16 +72,20 @@
7272
@ content TEXT
7373
@ );
7474
;
7575
7676
/*
77
-** Variables used for progress information
77
+** Variables used to store state information about an on-going "rebuild"
78
+** or "deconstruct".
7879
*/
7980
static int totalSize; /* Total number of artifacts to process */
8081
static int processCnt; /* Number processed so far */
8182
static int ttyOutput; /* Do progress output */
8283
static Bag bagDone; /* Bag of records rebuilt */
84
+
85
+static char *zFNameFormat; /* Format string for filenames on deconstruct */
86
+static int prefixLength; /* Length of directory prefix for deconstruct */
8387
8488
/*
8589
** Called after each artifact is processed
8690
*/
8791
static void rebuild_step_done(rid){
@@ -98,74 +102,101 @@
98102
99103
/*
100104
** Rebuild cross-referencing information for the artifact
101105
** rid with content pBase and all of its descendants. This
102106
** routine clears the content buffer before returning.
107
+**
108
+** If the zFNameFormat variable is set, then this routine is
109
+** called to run "fossil deconstruct" instead of the usual
110
+** "fossil rebuild". In that case, instead of rebuilding the
111
+** cross-referencing information, write the file content out
112
+** to the approriate directory.
113
+**
114
+** In both cases, this routine automatically recurses to process
115
+** other artifacts that are deltas off of the current artifact.
116
+** This is the most efficient way to extract all of the original
117
+** artifact content from the Fossil repository.
103118
*/
104119
static void rebuild_step(int rid, int size, Blob *pBase){
105120
static Stmt q1;
106121
Bag children;
107122
Blob copy;
108123
Blob *pUse;
109124
int nChild, i, cid;
110125
111
- /* Fix up the "blob.size" field if needed. */
112
- if( size!=blob_size(pBase) ){
113
- db_multi_exec(
114
- "UPDATE blob SET size=%d WHERE rid=%d", blob_size(pBase), rid
115
- );
116
- }
117
-
118
- /* Find all children of artifact rid */
119
- db_static_prepare(&q1, "SELECT rid FROM delta WHERE srcid=:rid");
120
- db_bind_int(&q1, ":rid", rid);
121
- bag_init(&children);
122
- while( db_step(&q1)==SQLITE_ROW ){
123
- int cid = db_column_int(&q1, 0);
124
- if( !bag_find(&bagDone, cid) ){
125
- bag_insert(&children, cid);
126
- }
127
- }
128
- nChild = bag_count(&children);
129
- db_reset(&q1);
130
-
131
- /* Crosslink the artifact */
132
- if( nChild==0 ){
133
- pUse = pBase;
134
- }else{
135
- blob_copy(&copy, pBase);
136
- pUse = &copy;
137
- }
138
- manifest_crosslink(rid, pUse);
139
- blob_reset(pUse);
140
-
141
- /* Call all children recursively */
142
- for(cid=bag_first(&children), i=1; cid; cid=bag_next(&children, cid), i++){
143
- Stmt q2;
144
- int sz;
145
- if( nChild==i ){
146
- pUse = pBase;
147
- }else{
148
- blob_copy(&copy, pBase);
149
- pUse = &copy;
150
- }
151
- db_prepare(&q2, "SELECT content, size FROM blob WHERE rid=%d", cid);
152
- if( db_step(&q2)==SQLITE_ROW && (sz = db_column_int(&q2,1))>=0 ){
153
- Blob delta;
154
- db_ephemeral_blob(&q2, 0, &delta);
155
- blob_uncompress(&delta, &delta);
156
- blob_delta_apply(pUse, &delta, pUse);
157
- blob_reset(&delta);
158
- db_finalize(&q2);
159
- rebuild_step(cid, sz, pUse);
160
- }else{
161
- db_finalize(&q2);
162
- blob_reset(pUse);
163
- }
164
- }
165
- bag_clear(&children);
166
- rebuild_step_done(rid);
126
+ while( rid>0 ){
127
+
128
+ /* Fix up the "blob.size" field if needed. */
129
+ if( size!=blob_size(pBase) ){
130
+ db_multi_exec(
131
+ "UPDATE blob SET size=%d WHERE rid=%d", blob_size(pBase), rid
132
+ );
133
+ }
134
+
135
+ /* Find all children of artifact rid */
136
+ db_static_prepare(&q1, "SELECT rid FROM delta WHERE srcid=:rid");
137
+ db_bind_int(&q1, ":rid", rid);
138
+ bag_init(&children);
139
+ while( db_step(&q1)==SQLITE_ROW ){
140
+ int cid = db_column_int(&q1, 0);
141
+ if( !bag_find(&bagDone, cid) ){
142
+ bag_insert(&children, cid);
143
+ }
144
+ }
145
+ nChild = bag_count(&children);
146
+ db_reset(&q1);
147
+
148
+ /* Crosslink the artifact */
149
+ if( nChild==0 ){
150
+ pUse = pBase;
151
+ }else{
152
+ blob_copy(&copy, pBase);
153
+ pUse = &copy;
154
+ }
155
+ if( zFNameFormat==0 ){
156
+ /* We are doing "fossil rebuild" */
157
+ manifest_crosslink(rid, pUse);
158
+ }else{
159
+ /* We are doing "fossil deconstruct" */
160
+ char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
161
+ char *zFile = mprintf(zFNameFormat, zUuid, zUuid+prefixLength);
162
+ blob_write_to_file(pUse,zFile);
163
+ free(zFile);
164
+ free(zUuid);
165
+ }
166
+ blob_reset(pUse);
167
+ rebuild_step_done(rid);
168
+
169
+ /* Call all children recursively */
170
+ rid = 0;
171
+ for(cid=bag_first(&children), i=1; cid; cid=bag_next(&children, cid), i++){
172
+ Stmt q2;
173
+ int sz;
174
+ db_prepare(&q2, "SELECT content, size FROM blob WHERE rid=%d", cid);
175
+ if( db_step(&q2)==SQLITE_ROW && (sz = db_column_int(&q2,1))>=0 ){
176
+ Blob delta, next;
177
+ db_ephemeral_blob(&q2, 0, &delta);
178
+ blob_uncompress(&delta, &delta);
179
+ blob_delta_apply(pBase, &delta, &next);
180
+ blob_reset(&delta);
181
+ db_finalize(&q2);
182
+ if( i<nChild ){
183
+ rebuild_step(cid, sz, &next);
184
+ }else{
185
+ /* Tail recursion */
186
+ rid = cid;
187
+ size = sz;
188
+ blob_reset(pBase);
189
+ *pBase = next;
190
+ }
191
+ }else{
192
+ db_finalize(&q2);
193
+ blob_reset(pBase);
194
+ }
195
+ }
196
+ bag_clear(&children);
197
+ }
167198
}
168199
169200
/*
170201
** Check to see if the "sym-trunk" tag exists. If not, create it
171202
** and attach it to the very first check-in.
@@ -181,12 +212,12 @@
181212
if( rid==0 ) return;
182213
183214
/* Add the trunk tag to the root of the whole tree */
184215
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
185216
if( zUuid==0 ) return;
186
- tag_add_artifact("sym-", "trunk", zUuid, 0, 2);
187
- tag_add_artifact("", "branch", zUuid, "trunk", 2);
217
+ tag_add_artifact("sym-", "trunk", zUuid, 0, 2, 0, 0);
218
+ tag_add_artifact("", "branch", zUuid, "trunk", 2, 0, 0);
188219
}
189220
190221
/*
191222
** Core function to rebuild the infomration in the derived tables of a
192223
** fossil repository from the blobs. This function is shared between
@@ -401,26 +432,66 @@
401432
}else{
402433
rebuild_db(0, 1);
403434
db_end_transaction(0);
404435
}
405436
}
437
+
438
+/*
439
+** Recursively read all files from the directory zPath and install
440
+** every file read as a new artifact in the repository.
441
+*/
442
+void recon_read_dir(char *zPath){
443
+ DIR *d;
444
+ struct dirent *pEntry;
445
+ Blob aContent; /* content of the just read artifact */
446
+ static int nFileRead = 0;
447
+
448
+ d = opendir(zPath);
449
+ if( d ){
450
+ while( (pEntry=readdir(d))!=0 ){
451
+ Blob path;
452
+ char *zSubpath;
453
+
454
+ if( pEntry->d_name[0]=='.' ){
455
+ continue;
456
+ }
457
+ zSubpath = mprintf("%s/%s",zPath,pEntry->d_name);
458
+ if( file_isdir(zSubpath)==1 ){
459
+ recon_read_dir(zSubpath);
460
+ }
461
+ blob_init(&path, 0, 0);
462
+ blob_appendf(&path, "%s", zSubpath);
463
+ if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
464
+ fossil_panic("some unknown error occurred while reading \"%s\"",
465
+ blob_str(&path));
466
+ }
467
+ content_put(&aContent, 0, 0);
468
+ blob_reset(&path);
469
+ blob_reset(&aContent);
470
+ free(zSubpath);
471
+ printf("\r%d", ++nFileRead);
472
+ fflush(stdout);
473
+ }
474
+ }else {
475
+ fossil_panic("encountered error %d while trying to open \"%s\".",
476
+ errno, g.argv[3]);
477
+ }
478
+}
406479
407480
/*
408481
** COMMAND: reconstruct
409482
**
410483
** Usage: %fossil reconstruct FILENAME DIRECTORY
411484
**
412485
** This command studies the artifacts (files) in DIRECTORY and
413486
** reconstructs the fossil record from them. It places the new
414
-** fossil repository in FILENAME
487
+** fossil repository in FILENAME. Subdirectories are read, files
488
+** with leading '.' in the filename are ignored.
415489
**
416490
*/
417491
void reconstruct_cmd(void) {
418492
char *zPassword;
419
- DIR *d;
420
- struct dirent *pEntry;
421
- Blob aContent; /* content of the just read artifact */
422493
if( g.argc!=4 ){
423494
usage("FILENAME DIRECTORY");
424495
}
425496
if( file_isdir(g.argv[3])!=1 ){
426497
printf("\"%s\" is not a directory\n\n", g.argv[3]);
@@ -430,37 +501,124 @@
430501
db_open_repository(g.argv[2]);
431502
db_open_config(0);
432503
db_begin_transaction();
433504
db_initial_setup(0, 0, 1);
434505
435
- d = opendir(g.argv[3]);
436
- if( d ){
437
- while( (pEntry=readdir(d))!=0 ){
438
- Blob path;
439
- blob_init(&path, 0, 0);
440
- if( pEntry->d_name[0]=='.' ){
441
- continue;
442
- }
443
- if( file_isdir(pEntry->d_name)==1 ){
444
- continue;
445
- }
446
- blob_appendf(&path, "%s/%s", g.argv[3], pEntry->d_name);
447
- if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
448
- fossil_panic("Some unknown error occurred while reading \"%s\"", blob_str(&path));
449
- }
450
- content_put(&aContent, 0, 0);
451
- blob_reset(&path);
452
- blob_reset(&aContent);
453
- }
454
- }
455
- else {
456
- fossil_panic("Encountered error %d while trying to open \"%s\".", errno, g.argv[3]);
457
- }
506
+ printf("Reading files from directory \"%s\"...\n", g.argv[3]);
507
+ recon_read_dir(g.argv[3]);
508
+ printf("\nBuilding the Fossil repository...\n");
458509
459510
rebuild_db(0, 1);
460511
512
+ /* Skip the verify_before_commit() step on a reconstruct. Most artifacts
513
+ ** will have been changed and verification therefore takes a really, really
514
+ ** long time.
515
+ */
516
+ verify_cancel();
517
+
461518
db_end_transaction(0);
462519
printf("project-id: %s\n", db_get("project-code", 0));
463520
printf("server-id: %s\n", db_get("server-code", 0));
464521
zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
465522
printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword);
466523
}
524
+
525
+/*
526
+** COMMAND: deconstruct
527
+**
528
+** Usage %fossil deconstruct ?-R|--repository REPOSITORY? ?-L|--prefixlength N? DESTINATION
529
+**
530
+** This command exports all artifacts of o given repository and
531
+** writes all artifacts to the file system. The DESTINATION directory
532
+** will be populated with subdirectories AA and files AA/BBBBBBBBB.., where
533
+** AABBBBBBBBB.. is the 40 character artifact ID, AA the first 2 characters.
534
+** If -L|--prefixlength is given, the length (default 2) of the directory
535
+** prefix can be set to 0,1,..,9 characters.
536
+*/
537
+void deconstruct_cmd(void){
538
+ const char *zDestDir;
539
+ const char *zPrefixOpt;
540
+ Stmt s;
541
+
542
+ /* check number of arguments */
543
+ if( (g.argc != 3) && (g.argc != 5) && (g.argc != 7)){
544
+ usage ("?-R|--repository REPOSITORY? ?-L|--prefixlength N? DESTINATION");
545
+ }
546
+ /* get and check argument destination directory */
547
+ zDestDir = g.argv[g.argc-1];
548
+ if( !*zDestDir || !file_isdir(zDestDir)) {
549
+ fossil_panic("DESTINATION(%s) is not a directory!",zDestDir);
550
+ }
551
+ /* get and check prefix length argument and build format string */
552
+ zPrefixOpt=find_option("prefixlength","L",1);
553
+ if( !zPrefixOpt ){
554
+ prefixLength = 2;
555
+ }else{
556
+ if( zPrefixOpt[0]>='0' && zPrefixOpt[0]<='9' && !zPrefixOpt[1] ){
557
+ prefixLength = (int)(*zPrefixOpt-'0');
558
+ }else{
559
+ fossil_fatal("N(%s) is not a a valid prefix length!",zPrefixOpt);
560
+ }
561
+ }
562
+#ifndef _WIN32
563
+ if( access(zDestDir, W_OK) ){
564
+ fossil_fatal("DESTINATION(%s) is not writeable!",zDestDir);
565
+ }
566
+#else
567
+ /* write access on windows is not checked, errors will be
568
+ ** dected on blob_write_to_file
569
+ */
570
+#endif
571
+ if( prefixLength ){
572
+ zFNameFormat = mprintf("%s/%%.%ds/%%s",zDestDir,prefixLength);
573
+ }else{
574
+ zFNameFormat = mprintf("%s/%%s",zDestDir);
575
+ }
576
+ /* open repository and open query for all artifacts */
577
+ db_find_and_open_repository(1);
578
+ bag_init(&bagDone);
579
+ ttyOutput = 1;
580
+ processCnt = 0;
581
+ if (!g.fQuiet) {
582
+ printf("0 (0%%)...\r");
583
+ fflush(stdout);
584
+ }
585
+ totalSize = db_int(0, "SELECT count(*) FROM blob");
586
+ db_prepare(&s,
587
+ "SELECT rid, size FROM blob /*scan*/"
588
+ " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
589
+ " AND NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)"
590
+ );
591
+ while( db_step(&s)==SQLITE_ROW ){
592
+ int rid = db_column_int(&s, 0);
593
+ int size = db_column_int(&s, 1);
594
+ if( size>=0 ){
595
+ Blob content;
596
+ content_get(rid, &content);
597
+ rebuild_step(rid, size, &content);
598
+ }
599
+ }
600
+ db_finalize(&s);
601
+ db_prepare(&s,
602
+ "SELECT rid, size FROM blob"
603
+ " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
604
+ );
605
+ while( db_step(&s)==SQLITE_ROW ){
606
+ int rid = db_column_int(&s, 0);
607
+ int size = db_column_int(&s, 1);
608
+ if( size>=0 ){
609
+ if( !bag_find(&bagDone, rid) ){
610
+ Blob content;
611
+ content_get(rid, &content);
612
+ rebuild_step(rid, size, &content);
613
+ }
614
+ }
615
+ }
616
+ db_finalize(&s);
617
+ if(!g.fQuiet && ttyOutput ){
618
+ printf("\n");
619
+ }
620
+
621
+ /* free filename format string */
622
+ free(zFNameFormat);
623
+ zFNameFormat = 0;
624
+}
467625
--- src/rebuild.c
+++ src/rebuild.c
@@ -72,16 +72,20 @@
72 @ content TEXT
73 @ );
74 ;
75
76 /*
77 ** Variables used for progress information
 
78 */
79 static int totalSize; /* Total number of artifacts to process */
80 static int processCnt; /* Number processed so far */
81 static int ttyOutput; /* Do progress output */
82 static Bag bagDone; /* Bag of records rebuilt */
 
 
 
83
84 /*
85 ** Called after each artifact is processed
86 */
87 static void rebuild_step_done(rid){
@@ -98,74 +102,101 @@
98
99 /*
100 ** Rebuild cross-referencing information for the artifact
101 ** rid with content pBase and all of its descendants. This
102 ** routine clears the content buffer before returning.
 
 
 
 
 
 
 
 
 
 
 
103 */
104 static void rebuild_step(int rid, int size, Blob *pBase){
105 static Stmt q1;
106 Bag children;
107 Blob copy;
108 Blob *pUse;
109 int nChild, i, cid;
110
111 /* Fix up the "blob.size" field if needed. */
112 if( size!=blob_size(pBase) ){
113 db_multi_exec(
114 "UPDATE blob SET size=%d WHERE rid=%d", blob_size(pBase), rid
115 );
116 }
117
118 /* Find all children of artifact rid */
119 db_static_prepare(&q1, "SELECT rid FROM delta WHERE srcid=:rid");
120 db_bind_int(&q1, ":rid", rid);
121 bag_init(&children);
122 while( db_step(&q1)==SQLITE_ROW ){
123 int cid = db_column_int(&q1, 0);
124 if( !bag_find(&bagDone, cid) ){
125 bag_insert(&children, cid);
126 }
127 }
128 nChild = bag_count(&children);
129 db_reset(&q1);
130
131 /* Crosslink the artifact */
132 if( nChild==0 ){
133 pUse = pBase;
134 }else{
135 blob_copy(&copy, pBase);
136 pUse = &copy;
137 }
138 manifest_crosslink(rid, pUse);
139 blob_reset(pUse);
140
141 /* Call all children recursively */
142 for(cid=bag_first(&children), i=1; cid; cid=bag_next(&children, cid), i++){
143 Stmt q2;
144 int sz;
145 if( nChild==i ){
146 pUse = pBase;
147 }else{
148 blob_copy(&copy, pBase);
149 pUse = &copy;
150 }
151 db_prepare(&q2, "SELECT content, size FROM blob WHERE rid=%d", cid);
152 if( db_step(&q2)==SQLITE_ROW && (sz = db_column_int(&q2,1))>=0 ){
153 Blob delta;
154 db_ephemeral_blob(&q2, 0, &delta);
155 blob_uncompress(&delta, &delta);
156 blob_delta_apply(pUse, &delta, pUse);
157 blob_reset(&delta);
158 db_finalize(&q2);
159 rebuild_step(cid, sz, pUse);
160 }else{
161 db_finalize(&q2);
162 blob_reset(pUse);
163 }
164 }
165 bag_clear(&children);
166 rebuild_step_done(rid);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167 }
168
169 /*
170 ** Check to see if the "sym-trunk" tag exists. If not, create it
171 ** and attach it to the very first check-in.
@@ -181,12 +212,12 @@
181 if( rid==0 ) return;
182
183 /* Add the trunk tag to the root of the whole tree */
184 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
185 if( zUuid==0 ) return;
186 tag_add_artifact("sym-", "trunk", zUuid, 0, 2);
187 tag_add_artifact("", "branch", zUuid, "trunk", 2);
188 }
189
190 /*
191 ** Core function to rebuild the infomration in the derived tables of a
192 ** fossil repository from the blobs. This function is shared between
@@ -401,26 +432,66 @@
401 }else{
402 rebuild_db(0, 1);
403 db_end_transaction(0);
404 }
405 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
407 /*
408 ** COMMAND: reconstruct
409 **
410 ** Usage: %fossil reconstruct FILENAME DIRECTORY
411 **
412 ** This command studies the artifacts (files) in DIRECTORY and
413 ** reconstructs the fossil record from them. It places the new
414 ** fossil repository in FILENAME
 
415 **
416 */
417 void reconstruct_cmd(void) {
418 char *zPassword;
419 DIR *d;
420 struct dirent *pEntry;
421 Blob aContent; /* content of the just read artifact */
422 if( g.argc!=4 ){
423 usage("FILENAME DIRECTORY");
424 }
425 if( file_isdir(g.argv[3])!=1 ){
426 printf("\"%s\" is not a directory\n\n", g.argv[3]);
@@ -430,37 +501,124 @@
430 db_open_repository(g.argv[2]);
431 db_open_config(0);
432 db_begin_transaction();
433 db_initial_setup(0, 0, 1);
434
435 d = opendir(g.argv[3]);
436 if( d ){
437 while( (pEntry=readdir(d))!=0 ){
438 Blob path;
439 blob_init(&path, 0, 0);
440 if( pEntry->d_name[0]=='.' ){
441 continue;
442 }
443 if( file_isdir(pEntry->d_name)==1 ){
444 continue;
445 }
446 blob_appendf(&path, "%s/%s", g.argv[3], pEntry->d_name);
447 if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
448 fossil_panic("Some unknown error occurred while reading \"%s\"", blob_str(&path));
449 }
450 content_put(&aContent, 0, 0);
451 blob_reset(&path);
452 blob_reset(&aContent);
453 }
454 }
455 else {
456 fossil_panic("Encountered error %d while trying to open \"%s\".", errno, g.argv[3]);
457 }
458
459 rebuild_db(0, 1);
460
 
 
 
 
 
 
461 db_end_transaction(0);
462 printf("project-id: %s\n", db_get("project-code", 0));
463 printf("server-id: %s\n", db_get("server-code", 0));
464 zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
465 printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword);
466 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
467
--- src/rebuild.c
+++ src/rebuild.c
@@ -72,16 +72,20 @@
72 @ content TEXT
73 @ );
74 ;
75
76 /*
77 ** Variables used to store state information about an on-going "rebuild"
78 ** or "deconstruct".
79 */
80 static int totalSize; /* Total number of artifacts to process */
81 static int processCnt; /* Number processed so far */
82 static int ttyOutput; /* Do progress output */
83 static Bag bagDone; /* Bag of records rebuilt */
84
85 static char *zFNameFormat; /* Format string for filenames on deconstruct */
86 static int prefixLength; /* Length of directory prefix for deconstruct */
87
88 /*
89 ** Called after each artifact is processed
90 */
91 static void rebuild_step_done(rid){
@@ -98,74 +102,101 @@
102
103 /*
104 ** Rebuild cross-referencing information for the artifact
105 ** rid with content pBase and all of its descendants. This
106 ** routine clears the content buffer before returning.
107 **
108 ** If the zFNameFormat variable is set, then this routine is
109 ** called to run "fossil deconstruct" instead of the usual
110 ** "fossil rebuild". In that case, instead of rebuilding the
111 ** cross-referencing information, write the file content out
112 ** to the approriate directory.
113 **
114 ** In both cases, this routine automatically recurses to process
115 ** other artifacts that are deltas off of the current artifact.
116 ** This is the most efficient way to extract all of the original
117 ** artifact content from the Fossil repository.
118 */
119 static void rebuild_step(int rid, int size, Blob *pBase){
120 static Stmt q1;
121 Bag children;
122 Blob copy;
123 Blob *pUse;
124 int nChild, i, cid;
125
126 while( rid>0 ){
127
128 /* Fix up the "blob.size" field if needed. */
129 if( size!=blob_size(pBase) ){
130 db_multi_exec(
131 "UPDATE blob SET size=%d WHERE rid=%d", blob_size(pBase), rid
132 );
133 }
134
135 /* Find all children of artifact rid */
136 db_static_prepare(&q1, "SELECT rid FROM delta WHERE srcid=:rid");
137 db_bind_int(&q1, ":rid", rid);
138 bag_init(&children);
139 while( db_step(&q1)==SQLITE_ROW ){
140 int cid = db_column_int(&q1, 0);
141 if( !bag_find(&bagDone, cid) ){
142 bag_insert(&children, cid);
143 }
144 }
145 nChild = bag_count(&children);
146 db_reset(&q1);
147
148 /* Crosslink the artifact */
149 if( nChild==0 ){
150 pUse = pBase;
151 }else{
152 blob_copy(&copy, pBase);
153 pUse = &copy;
154 }
155 if( zFNameFormat==0 ){
156 /* We are doing "fossil rebuild" */
157 manifest_crosslink(rid, pUse);
158 }else{
159 /* We are doing "fossil deconstruct" */
160 char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
161 char *zFile = mprintf(zFNameFormat, zUuid, zUuid+prefixLength);
162 blob_write_to_file(pUse,zFile);
163 free(zFile);
164 free(zUuid);
165 }
166 blob_reset(pUse);
167 rebuild_step_done(rid);
168
169 /* Call all children recursively */
170 rid = 0;
171 for(cid=bag_first(&children), i=1; cid; cid=bag_next(&children, cid), i++){
172 Stmt q2;
173 int sz;
174 db_prepare(&q2, "SELECT content, size FROM blob WHERE rid=%d", cid);
175 if( db_step(&q2)==SQLITE_ROW && (sz = db_column_int(&q2,1))>=0 ){
176 Blob delta, next;
177 db_ephemeral_blob(&q2, 0, &delta);
178 blob_uncompress(&delta, &delta);
179 blob_delta_apply(pBase, &delta, &next);
180 blob_reset(&delta);
181 db_finalize(&q2);
182 if( i<nChild ){
183 rebuild_step(cid, sz, &next);
184 }else{
185 /* Tail recursion */
186 rid = cid;
187 size = sz;
188 blob_reset(pBase);
189 *pBase = next;
190 }
191 }else{
192 db_finalize(&q2);
193 blob_reset(pBase);
194 }
195 }
196 bag_clear(&children);
197 }
198 }
199
200 /*
201 ** Check to see if the "sym-trunk" tag exists. If not, create it
202 ** and attach it to the very first check-in.
@@ -181,12 +212,12 @@
212 if( rid==0 ) return;
213
214 /* Add the trunk tag to the root of the whole tree */
215 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
216 if( zUuid==0 ) return;
217 tag_add_artifact("sym-", "trunk", zUuid, 0, 2, 0, 0);
218 tag_add_artifact("", "branch", zUuid, "trunk", 2, 0, 0);
219 }
220
221 /*
222 ** Core function to rebuild the infomration in the derived tables of a
223 ** fossil repository from the blobs. This function is shared between
@@ -401,26 +432,66 @@
432 }else{
433 rebuild_db(0, 1);
434 db_end_transaction(0);
435 }
436 }
437
438 /*
439 ** Recursively read all files from the directory zPath and install
440 ** every file read as a new artifact in the repository.
441 */
442 void recon_read_dir(char *zPath){
443 DIR *d;
444 struct dirent *pEntry;
445 Blob aContent; /* content of the just read artifact */
446 static int nFileRead = 0;
447
448 d = opendir(zPath);
449 if( d ){
450 while( (pEntry=readdir(d))!=0 ){
451 Blob path;
452 char *zSubpath;
453
454 if( pEntry->d_name[0]=='.' ){
455 continue;
456 }
457 zSubpath = mprintf("%s/%s",zPath,pEntry->d_name);
458 if( file_isdir(zSubpath)==1 ){
459 recon_read_dir(zSubpath);
460 }
461 blob_init(&path, 0, 0);
462 blob_appendf(&path, "%s", zSubpath);
463 if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
464 fossil_panic("some unknown error occurred while reading \"%s\"",
465 blob_str(&path));
466 }
467 content_put(&aContent, 0, 0);
468 blob_reset(&path);
469 blob_reset(&aContent);
470 free(zSubpath);
471 printf("\r%d", ++nFileRead);
472 fflush(stdout);
473 }
474 }else {
475 fossil_panic("encountered error %d while trying to open \"%s\".",
476 errno, g.argv[3]);
477 }
478 }
479
480 /*
481 ** COMMAND: reconstruct
482 **
483 ** Usage: %fossil reconstruct FILENAME DIRECTORY
484 **
485 ** This command studies the artifacts (files) in DIRECTORY and
486 ** reconstructs the fossil record from them. It places the new
487 ** fossil repository in FILENAME. Subdirectories are read, files
488 ** with leading '.' in the filename are ignored.
489 **
490 */
491 void reconstruct_cmd(void) {
492 char *zPassword;
 
 
 
493 if( g.argc!=4 ){
494 usage("FILENAME DIRECTORY");
495 }
496 if( file_isdir(g.argv[3])!=1 ){
497 printf("\"%s\" is not a directory\n\n", g.argv[3]);
@@ -430,37 +501,124 @@
501 db_open_repository(g.argv[2]);
502 db_open_config(0);
503 db_begin_transaction();
504 db_initial_setup(0, 0, 1);
505
506 printf("Reading files from directory \"%s\"...\n", g.argv[3]);
507 recon_read_dir(g.argv[3]);
508 printf("\nBuilding the Fossil repository...\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
510 rebuild_db(0, 1);
511
512 /* Skip the verify_before_commit() step on a reconstruct. Most artifacts
513 ** will have been changed and verification therefore takes a really, really
514 ** long time.
515 */
516 verify_cancel();
517
518 db_end_transaction(0);
519 printf("project-id: %s\n", db_get("project-code", 0));
520 printf("server-id: %s\n", db_get("server-code", 0));
521 zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
522 printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword);
523 }
524
525 /*
526 ** COMMAND: deconstruct
527 **
528 ** Usage %fossil deconstruct ?-R|--repository REPOSITORY? ?-L|--prefixlength N? DESTINATION
529 **
530 ** This command exports all artifacts of o given repository and
531 ** writes all artifacts to the file system. The DESTINATION directory
532 ** will be populated with subdirectories AA and files AA/BBBBBBBBB.., where
533 ** AABBBBBBBBB.. is the 40 character artifact ID, AA the first 2 characters.
534 ** If -L|--prefixlength is given, the length (default 2) of the directory
535 ** prefix can be set to 0,1,..,9 characters.
536 */
537 void deconstruct_cmd(void){
538 const char *zDestDir;
539 const char *zPrefixOpt;
540 Stmt s;
541
542 /* check number of arguments */
543 if( (g.argc != 3) && (g.argc != 5) && (g.argc != 7)){
544 usage ("?-R|--repository REPOSITORY? ?-L|--prefixlength N? DESTINATION");
545 }
546 /* get and check argument destination directory */
547 zDestDir = g.argv[g.argc-1];
548 if( !*zDestDir || !file_isdir(zDestDir)) {
549 fossil_panic("DESTINATION(%s) is not a directory!",zDestDir);
550 }
551 /* get and check prefix length argument and build format string */
552 zPrefixOpt=find_option("prefixlength","L",1);
553 if( !zPrefixOpt ){
554 prefixLength = 2;
555 }else{
556 if( zPrefixOpt[0]>='0' && zPrefixOpt[0]<='9' && !zPrefixOpt[1] ){
557 prefixLength = (int)(*zPrefixOpt-'0');
558 }else{
559 fossil_fatal("N(%s) is not a a valid prefix length!",zPrefixOpt);
560 }
561 }
562 #ifndef _WIN32
563 if( access(zDestDir, W_OK) ){
564 fossil_fatal("DESTINATION(%s) is not writeable!",zDestDir);
565 }
566 #else
567 /* write access on windows is not checked, errors will be
568 ** dected on blob_write_to_file
569 */
570 #endif
571 if( prefixLength ){
572 zFNameFormat = mprintf("%s/%%.%ds/%%s",zDestDir,prefixLength);
573 }else{
574 zFNameFormat = mprintf("%s/%%s",zDestDir);
575 }
576 /* open repository and open query for all artifacts */
577 db_find_and_open_repository(1);
578 bag_init(&bagDone);
579 ttyOutput = 1;
580 processCnt = 0;
581 if (!g.fQuiet) {
582 printf("0 (0%%)...\r");
583 fflush(stdout);
584 }
585 totalSize = db_int(0, "SELECT count(*) FROM blob");
586 db_prepare(&s,
587 "SELECT rid, size FROM blob /*scan*/"
588 " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
589 " AND NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)"
590 );
591 while( db_step(&s)==SQLITE_ROW ){
592 int rid = db_column_int(&s, 0);
593 int size = db_column_int(&s, 1);
594 if( size>=0 ){
595 Blob content;
596 content_get(rid, &content);
597 rebuild_step(rid, size, &content);
598 }
599 }
600 db_finalize(&s);
601 db_prepare(&s,
602 "SELECT rid, size FROM blob"
603 " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
604 );
605 while( db_step(&s)==SQLITE_ROW ){
606 int rid = db_column_int(&s, 0);
607 int size = db_column_int(&s, 1);
608 if( size>=0 ){
609 if( !bag_find(&bagDone, rid) ){
610 Blob content;
611 content_get(rid, &content);
612 rebuild_step(rid, size, &content);
613 }
614 }
615 }
616 db_finalize(&s);
617 if(!g.fQuiet && ttyOutput ){
618 printf("\n");
619 }
620
621 /* free filename format string */
622 free(zFNameFormat);
623 zFNameFormat = 0;
624 }
625
+25 -25
--- src/report.c
+++ src/report.c
@@ -328,11 +328,11 @@
328328
zTitle = db_text(0, "SELECT title FROM reportfmt "
329329
"WHERE rn=%d", rn);
330330
if( zTitle==0 ) cgi_redirect("reportlist");
331331
332332
style_header("Are You Sure?");
333
- @ <form action="rptedit" method="POST">
333
+ @ <form action="rptedit" method="post">
334334
@ <p>You are about to delete all traces of the report
335335
@ <strong>%h(zTitle)</strong> from
336336
@ the database. This is an irreversible operation. All records
337337
@ related to this report will be removed and cannot be recovered.</p>
338338
@
@@ -397,26 +397,26 @@
397397
if( rn>0 ){
398398
style_submenu_element("Delete", "Delete", "rptedit?rn=%d&amp;del1=1", rn);
399399
}
400400
style_header(rn>0 ? "Edit Report Format":"Create New Report Format");
401401
if( zErr ){
402
- @ <blockquote><font color="#ff0000"><b>%h(zErr)</b></font></blockquote>
402
+ @ <blockquote class="reportError">%h(zErr)</blockquote>
403403
}
404
- @ <form action="rptedit" method="POST">
405
- @ <input type="hidden" name="rn" value="%d(rn)">
404
+ @ <form action="rptedit" method="post"><div>
405
+ @ <input type="hidden" name="rn" value="%d(rn)" />
406406
@ <p>Report Title:<br />
407
- @ <input type="text" name="t" value="%h(zTitle)" size="60"></p>
407
+ @ <input type="text" name="t" value="%h(zTitle)" size="60" /></p>
408408
@ <p>Enter a complete SQL query statement against the "TICKET" table:<br />
409409
@ <textarea name="s" rows="20" cols="80">%h(zSQL)</textarea>
410410
@ </p>
411411
login_insert_csrf_secret();
412412
if( g.okAdmin ){
413413
@ <p>Report owner:
414
- @ <input type="text" name="w" size="20" value="%h(zOwner)">
414
+ @ <input type="text" name="w" size="20" value="%h(zOwner)" />
415415
@ </p>
416416
} else {
417
- @ <input type="hidden" name="w" value="%h(zOwner)">
417
+ @ <input type="hidden" name="w" value="%h(zOwner)" />
418418
}
419419
@ <p>Enter an optional color key in the following box. (If blank, no
420420
@ color key is displayed.) Each line contains the text for a single
421421
@ entry in the key. The first token of each line is the background
422422
@ color for that line.<br />
@@ -428,15 +428,15 @@
428428
@ </form>
429429
report_format_hints();
430430
style_footer();
431431
return;
432432
}
433
- @ <input type="submit" value="Apply Changes">
433
+ @ <input type="submit" value="Apply Changes" />
434434
if( rn>0 ){
435
- @ <input type="submit" value="Delete This Report" name="del1">
435
+ @ <input type="submit" value="Delete This Report" name="del1" />
436436
}
437
- @ </form>
437
+ @ </div></form>
438438
report_format_hints();
439439
style_footer();
440440
}
441441
442442
/*
@@ -478,17 +478,17 @@
478478
@ <p>In this example, the first column in the result set is named
479479
@ "bgcolor". The value of this column is not displayed. Instead, it
480480
@ selects the background color of each row based on the TICKET.STATUS
481481
@ field of the database. The color key at the right shows the various
482482
@ color codes.</p>
483
- @ <table align="right" style="margin: 0 5px;" border=1 cellspacing=0 width=125>
484
- @ <tr bgcolor="#f2dcdc"><td align="center">new or active</td></tr>
485
- @ <tr bgcolor="#e8e8bd"><td align="center">review</td></tr>
486
- @ <tr bgcolor="#cfe8bd"><td align="center">fixed</td></tr>
487
- @ <tr bgcolor="#bde5d6"><td align="center">tested</td></tr>
488
- @ <tr bgcolor="#cacae5"><td align="center">defer</td></tr>
489
- @ <tr bgcolor="#c8c8c8"><td align="center">closed</td></tr>
483
+ @ <table class="rpteditex">
484
+ @ <tr style="background-color:#f2dcdc;"><td class="rpteditex">new or active</td></tr>
485
+ @ <tr style="background-color:#e8e8bd;"><td class="rpteditex">review</td></tr>
486
+ @ <tr style="background-color:#cfe8bd;"><td class="rpteditex">fixed</td></tr>
487
+ @ <tr style="background-color:#bde5d6;"><td class="rpteditex">tested</td></tr>
488
+ @ <tr style="background-color:#cacae5;"><td class="rpteditex">defer</td></tr>
489
+ @ <tr style="background-color:#c8c8c8;"><td class="rpteditex">closed</td></tr>
490490
@ </table>
491491
@ <blockquote><pre>
492492
@ SELECT
493493
@ CASE WHEN status IN ('new','active') THEN '#f2dcdc'
494494
@ WHEN status='review' THEN '#e8e8bd'
@@ -510,16 +510,16 @@
510510
@ FROM ticket
511511
@ </pre></blockquote>
512512
@ <p>To base the background color on the TICKET.PRIORITY or
513513
@ TICKET.SEVERITY fields, substitute the following code for the
514514
@ first column of the query:</p>
515
- @ <table align="right" style="margin: 0 5px;" border=1 cellspacing=0 width=125>
516
- @ <tr bgcolor="#f2dcdc"><td align="center">1</td></tr>
517
- @ <tr bgcolor="#e8e8bd"><td align="center">2</td></tr>
518
- @ <tr bgcolor="#cfe8bd"><td align="center">3</td></tr>
519
- @ <tr bgcolor="#cacae5"><td align="center">4</td></tr>
520
- @ <tr bgcolor="#c8c8c8"><td align="center">5</td></tr>
515
+ @ <table class="rpteditex">
516
+ @ <tr style="background-color:#f2dcdc;"><td class="rpteditex">1</td></tr>
517
+ @ <tr style="background-color:#e8e8bd;"><td class="rpteditex">2</td></tr>
518
+ @ <tr style="background-color:#cfe8bd;"><td class="rpteditex">3</td></tr>
519
+ @ <tr style="background-color:#cacae5;"><td class="rpteditex">4</td></tr>
520
+ @ <tr style="background-color:#c8c8c8;"><td class="rpteditex">5</td></tr>
521521
@ </table>
522522
@ <blockquote><pre>
523523
@ SELECT
524524
@ CASE priority WHEN 1 THEN '#f2dcdc'
525525
@ WHEN 2 THEN '#e8e8bd'
@@ -930,17 +930,17 @@
930930
sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
931931
sqlite3_exec(g.db, zSql, generate_html, &sState, &zErr2);
932932
sqlite3_set_authorizer(g.db, 0, 0);
933933
@ </table>
934934
if( zErr1 ){
935
- @ <p><font color="red"><b>Error: %h(zErr1)</b></font></p>
935
+ @ <p class="reportError">Error: %h(zErr1)</p>
936936
}else if( zErr2 ){
937
- @ <p><font color="red"><b>Error: %h(zErr2)</b></font></p>
937
+ @ <p class="reportError">Error: %h(zErr2)</p>
938938
}
939939
style_footer();
940940
}else{
941941
sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
942942
sqlite3_exec(g.db, zSql, output_tab_separated, &count, &zErr2);
943943
sqlite3_set_authorizer(g.db, 0, 0);
944944
cgi_set_content_type("text/plain");
945945
}
946946
}
947947
--- src/report.c
+++ src/report.c
@@ -328,11 +328,11 @@
328 zTitle = db_text(0, "SELECT title FROM reportfmt "
329 "WHERE rn=%d", rn);
330 if( zTitle==0 ) cgi_redirect("reportlist");
331
332 style_header("Are You Sure?");
333 @ <form action="rptedit" method="POST">
334 @ <p>You are about to delete all traces of the report
335 @ <strong>%h(zTitle)</strong> from
336 @ the database. This is an irreversible operation. All records
337 @ related to this report will be removed and cannot be recovered.</p>
338 @
@@ -397,26 +397,26 @@
397 if( rn>0 ){
398 style_submenu_element("Delete", "Delete", "rptedit?rn=%d&amp;del1=1", rn);
399 }
400 style_header(rn>0 ? "Edit Report Format":"Create New Report Format");
401 if( zErr ){
402 @ <blockquote><font color="#ff0000"><b>%h(zErr)</b></font></blockquote>
403 }
404 @ <form action="rptedit" method="POST">
405 @ <input type="hidden" name="rn" value="%d(rn)">
406 @ <p>Report Title:<br />
407 @ <input type="text" name="t" value="%h(zTitle)" size="60"></p>
408 @ <p>Enter a complete SQL query statement against the "TICKET" table:<br />
409 @ <textarea name="s" rows="20" cols="80">%h(zSQL)</textarea>
410 @ </p>
411 login_insert_csrf_secret();
412 if( g.okAdmin ){
413 @ <p>Report owner:
414 @ <input type="text" name="w" size="20" value="%h(zOwner)">
415 @ </p>
416 } else {
417 @ <input type="hidden" name="w" value="%h(zOwner)">
418 }
419 @ <p>Enter an optional color key in the following box. (If blank, no
420 @ color key is displayed.) Each line contains the text for a single
421 @ entry in the key. The first token of each line is the background
422 @ color for that line.<br />
@@ -428,15 +428,15 @@
428 @ </form>
429 report_format_hints();
430 style_footer();
431 return;
432 }
433 @ <input type="submit" value="Apply Changes">
434 if( rn>0 ){
435 @ <input type="submit" value="Delete This Report" name="del1">
436 }
437 @ </form>
438 report_format_hints();
439 style_footer();
440 }
441
442 /*
@@ -478,17 +478,17 @@
478 @ <p>In this example, the first column in the result set is named
479 @ "bgcolor". The value of this column is not displayed. Instead, it
480 @ selects the background color of each row based on the TICKET.STATUS
481 @ field of the database. The color key at the right shows the various
482 @ color codes.</p>
483 @ <table align="right" style="margin: 0 5px;" border=1 cellspacing=0 width=125>
484 @ <tr bgcolor="#f2dcdc"><td align="center">new or active</td></tr>
485 @ <tr bgcolor="#e8e8bd"><td align="center">review</td></tr>
486 @ <tr bgcolor="#cfe8bd"><td align="center">fixed</td></tr>
487 @ <tr bgcolor="#bde5d6"><td align="center">tested</td></tr>
488 @ <tr bgcolor="#cacae5"><td align="center">defer</td></tr>
489 @ <tr bgcolor="#c8c8c8"><td align="center">closed</td></tr>
490 @ </table>
491 @ <blockquote><pre>
492 @ SELECT
493 @ CASE WHEN status IN ('new','active') THEN '#f2dcdc'
494 @ WHEN status='review' THEN '#e8e8bd'
@@ -510,16 +510,16 @@
510 @ FROM ticket
511 @ </pre></blockquote>
512 @ <p>To base the background color on the TICKET.PRIORITY or
513 @ TICKET.SEVERITY fields, substitute the following code for the
514 @ first column of the query:</p>
515 @ <table align="right" style="margin: 0 5px;" border=1 cellspacing=0 width=125>
516 @ <tr bgcolor="#f2dcdc"><td align="center">1</td></tr>
517 @ <tr bgcolor="#e8e8bd"><td align="center">2</td></tr>
518 @ <tr bgcolor="#cfe8bd"><td align="center">3</td></tr>
519 @ <tr bgcolor="#cacae5"><td align="center">4</td></tr>
520 @ <tr bgcolor="#c8c8c8"><td align="center">5</td></tr>
521 @ </table>
522 @ <blockquote><pre>
523 @ SELECT
524 @ CASE priority WHEN 1 THEN '#f2dcdc'
525 @ WHEN 2 THEN '#e8e8bd'
@@ -930,17 +930,17 @@
930 sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
931 sqlite3_exec(g.db, zSql, generate_html, &sState, &zErr2);
932 sqlite3_set_authorizer(g.db, 0, 0);
933 @ </table>
934 if( zErr1 ){
935 @ <p><font color="red"><b>Error: %h(zErr1)</b></font></p>
936 }else if( zErr2 ){
937 @ <p><font color="red"><b>Error: %h(zErr2)</b></font></p>
938 }
939 style_footer();
940 }else{
941 sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
942 sqlite3_exec(g.db, zSql, output_tab_separated, &count, &zErr2);
943 sqlite3_set_authorizer(g.db, 0, 0);
944 cgi_set_content_type("text/plain");
945 }
946 }
947
--- src/report.c
+++ src/report.c
@@ -328,11 +328,11 @@
328 zTitle = db_text(0, "SELECT title FROM reportfmt "
329 "WHERE rn=%d", rn);
330 if( zTitle==0 ) cgi_redirect("reportlist");
331
332 style_header("Are You Sure?");
333 @ <form action="rptedit" method="post">
334 @ <p>You are about to delete all traces of the report
335 @ <strong>%h(zTitle)</strong> from
336 @ the database. This is an irreversible operation. All records
337 @ related to this report will be removed and cannot be recovered.</p>
338 @
@@ -397,26 +397,26 @@
397 if( rn>0 ){
398 style_submenu_element("Delete", "Delete", "rptedit?rn=%d&amp;del1=1", rn);
399 }
400 style_header(rn>0 ? "Edit Report Format":"Create New Report Format");
401 if( zErr ){
402 @ <blockquote class="reportError">%h(zErr)</blockquote>
403 }
404 @ <form action="rptedit" method="post"><div>
405 @ <input type="hidden" name="rn" value="%d(rn)" />
406 @ <p>Report Title:<br />
407 @ <input type="text" name="t" value="%h(zTitle)" size="60" /></p>
408 @ <p>Enter a complete SQL query statement against the "TICKET" table:<br />
409 @ <textarea name="s" rows="20" cols="80">%h(zSQL)</textarea>
410 @ </p>
411 login_insert_csrf_secret();
412 if( g.okAdmin ){
413 @ <p>Report owner:
414 @ <input type="text" name="w" size="20" value="%h(zOwner)" />
415 @ </p>
416 } else {
417 @ <input type="hidden" name="w" value="%h(zOwner)" />
418 }
419 @ <p>Enter an optional color key in the following box. (If blank, no
420 @ color key is displayed.) Each line contains the text for a single
421 @ entry in the key. The first token of each line is the background
422 @ color for that line.<br />
@@ -428,15 +428,15 @@
428 @ </form>
429 report_format_hints();
430 style_footer();
431 return;
432 }
433 @ <input type="submit" value="Apply Changes" />
434 if( rn>0 ){
435 @ <input type="submit" value="Delete This Report" name="del1" />
436 }
437 @ </div></form>
438 report_format_hints();
439 style_footer();
440 }
441
442 /*
@@ -478,17 +478,17 @@
478 @ <p>In this example, the first column in the result set is named
479 @ "bgcolor". The value of this column is not displayed. Instead, it
480 @ selects the background color of each row based on the TICKET.STATUS
481 @ field of the database. The color key at the right shows the various
482 @ color codes.</p>
483 @ <table class="rpteditex">
484 @ <tr style="background-color:#f2dcdc;"><td class="rpteditex">new or active</td></tr>
485 @ <tr style="background-color:#e8e8bd;"><td class="rpteditex">review</td></tr>
486 @ <tr style="background-color:#cfe8bd;"><td class="rpteditex">fixed</td></tr>
487 @ <tr style="background-color:#bde5d6;"><td class="rpteditex">tested</td></tr>
488 @ <tr style="background-color:#cacae5;"><td class="rpteditex">defer</td></tr>
489 @ <tr style="background-color:#c8c8c8;"><td class="rpteditex">closed</td></tr>
490 @ </table>
491 @ <blockquote><pre>
492 @ SELECT
493 @ CASE WHEN status IN ('new','active') THEN '#f2dcdc'
494 @ WHEN status='review' THEN '#e8e8bd'
@@ -510,16 +510,16 @@
510 @ FROM ticket
511 @ </pre></blockquote>
512 @ <p>To base the background color on the TICKET.PRIORITY or
513 @ TICKET.SEVERITY fields, substitute the following code for the
514 @ first column of the query:</p>
515 @ <table class="rpteditex">
516 @ <tr style="background-color:#f2dcdc;"><td class="rpteditex">1</td></tr>
517 @ <tr style="background-color:#e8e8bd;"><td class="rpteditex">2</td></tr>
518 @ <tr style="background-color:#cfe8bd;"><td class="rpteditex">3</td></tr>
519 @ <tr style="background-color:#cacae5;"><td class="rpteditex">4</td></tr>
520 @ <tr style="background-color:#c8c8c8;"><td class="rpteditex">5</td></tr>
521 @ </table>
522 @ <blockquote><pre>
523 @ SELECT
524 @ CASE priority WHEN 1 THEN '#f2dcdc'
525 @ WHEN 2 THEN '#e8e8bd'
@@ -930,17 +930,17 @@
930 sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
931 sqlite3_exec(g.db, zSql, generate_html, &sState, &zErr2);
932 sqlite3_set_authorizer(g.db, 0, 0);
933 @ </table>
934 if( zErr1 ){
935 @ <p class="reportError">Error: %h(zErr1)</p>
936 }else if( zErr2 ){
937 @ <p class="reportError">Error: %h(zErr2)</p>
938 }
939 style_footer();
940 }else{
941 sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
942 sqlite3_exec(g.db, zSql, output_tab_separated, &count, &zErr2);
943 sqlite3_set_authorizer(g.db, 0, 0);
944 cgi_set_content_type("text/plain");
945 }
946 }
947
+11 -6
--- src/setup.c
+++ src/setup.c
@@ -507,14 +507,14 @@
507507
@ </div></form>
508508
@ </div>
509509
@ <h2>Privileges And Capabilities:</h2>
510510
@ <ul>
511511
if( higherUser ){
512
- @ <li><p><font color="blue"><b>
512
+ @ <li><p class=missingPriv">
513513
@ User %h(zLogin) has Setup privileges and you only have Admin privileges
514514
@ so you are not permitted to make changes to %h(zLogin).
515
- @ </b></font></p></li>
515
+ @ </p></li>
516516
@
517517
}
518518
@ <li><p>
519519
@ The <span class="capability">Setup</span> user can make arbitrary
520520
@ configuration changes. An <span class="usertype">Admin</span> user
@@ -881,25 +881,25 @@
881881
pSet->var!=0 ? pSet->var : pSet->name,
882882
pSet->def[0]=='1');
883883
@ <br />
884884
}
885885
}
886
- @ </td><td width="30"></td><td valign="top">
886
+ @ </td><td style="width: 30;"></td><td valign="top">
887887
for(pSet=ctrlSettings; pSet->name!=0; pSet++){
888888
if( pSet->width!=0 ){
889889
entry_attribute(pSet->name, /*pSet->width*/ 40, pSet->name,
890890
pSet->var!=0 ? pSet->var : pSet->name,
891891
(char*)pSet->def);
892892
@ <br />
893893
}
894894
}
895
- @ </tr></table>
895
+ @ </td></tr></table>
896896
@ <p><input type="submit" name="submit" value="Apply Changes" /></p>
897897
@ </div></form>
898898
@ <hr /><p>
899
- @ These settings work in the same way, as the <kbd>set</kbd> commandline:<br>
900
- @ <pre>%s(zHelp_setting_cmd)</pre></p>
899
+ @ These settings work in the same way, as the <kbd>set</kbd> commandline:<br />
900
+ @ </p><pre>%s(zHelp_setting_cmd)</pre>
901901
db_end_transaction(0);
902902
style_footer();
903903
}
904904
905905
/*
@@ -938,10 +938,15 @@
938938
@ <blockquote><p>%h(g.zBaseURL)/home</p></blockquote>
939939
@
940940
@ <p>The default "/home" page displays a Wiki page with the same name
941941
@ as the Project Name specified above. Some sites prefer to redirect
942942
@ to a documentation page (ex: "/doc/tip/index.wiki") or to "/timeline".</p>
943
+ @
944
+ @ <p>Note: To avoid a redirect loop or other problems, this entry must
945
+ @ begin with "/" and it must specify a valid page. For example,
946
+ @ "<b>/home</b>" will work but "<b>home</b>" will not, since it omits the
947
+ @ leading "/".</p>
943948
@ <hr />
944949
onoff_attribute("Use HTML as wiki markup language",
945950
"wiki-use-html", "wiki-use-html", 0);
946951
@ <p>Use HTML as the wiki markup language. Wiki links will still be parsed
947952
@ but all other wiki formatting will be ignored. This option is helpful
948953
--- src/setup.c
+++ src/setup.c
@@ -507,14 +507,14 @@
507 @ </div></form>
508 @ </div>
509 @ <h2>Privileges And Capabilities:</h2>
510 @ <ul>
511 if( higherUser ){
512 @ <li><p><font color="blue"><b>
513 @ User %h(zLogin) has Setup privileges and you only have Admin privileges
514 @ so you are not permitted to make changes to %h(zLogin).
515 @ </b></font></p></li>
516 @
517 }
518 @ <li><p>
519 @ The <span class="capability">Setup</span> user can make arbitrary
520 @ configuration changes. An <span class="usertype">Admin</span> user
@@ -881,25 +881,25 @@
881 pSet->var!=0 ? pSet->var : pSet->name,
882 pSet->def[0]=='1');
883 @ <br />
884 }
885 }
886 @ </td><td width="30"></td><td valign="top">
887 for(pSet=ctrlSettings; pSet->name!=0; pSet++){
888 if( pSet->width!=0 ){
889 entry_attribute(pSet->name, /*pSet->width*/ 40, pSet->name,
890 pSet->var!=0 ? pSet->var : pSet->name,
891 (char*)pSet->def);
892 @ <br />
893 }
894 }
895 @ </tr></table>
896 @ <p><input type="submit" name="submit" value="Apply Changes" /></p>
897 @ </div></form>
898 @ <hr /><p>
899 @ These settings work in the same way, as the <kbd>set</kbd> commandline:<br>
900 @ <pre>%s(zHelp_setting_cmd)</pre></p>
901 db_end_transaction(0);
902 style_footer();
903 }
904
905 /*
@@ -938,10 +938,15 @@
938 @ <blockquote><p>%h(g.zBaseURL)/home</p></blockquote>
939 @
940 @ <p>The default "/home" page displays a Wiki page with the same name
941 @ as the Project Name specified above. Some sites prefer to redirect
942 @ to a documentation page (ex: "/doc/tip/index.wiki") or to "/timeline".</p>
 
 
 
 
 
943 @ <hr />
944 onoff_attribute("Use HTML as wiki markup language",
945 "wiki-use-html", "wiki-use-html", 0);
946 @ <p>Use HTML as the wiki markup language. Wiki links will still be parsed
947 @ but all other wiki formatting will be ignored. This option is helpful
948
--- src/setup.c
+++ src/setup.c
@@ -507,14 +507,14 @@
507 @ </div></form>
508 @ </div>
509 @ <h2>Privileges And Capabilities:</h2>
510 @ <ul>
511 if( higherUser ){
512 @ <li><p class=missingPriv">
513 @ User %h(zLogin) has Setup privileges and you only have Admin privileges
514 @ so you are not permitted to make changes to %h(zLogin).
515 @ </p></li>
516 @
517 }
518 @ <li><p>
519 @ The <span class="capability">Setup</span> user can make arbitrary
520 @ configuration changes. An <span class="usertype">Admin</span> user
@@ -881,25 +881,25 @@
881 pSet->var!=0 ? pSet->var : pSet->name,
882 pSet->def[0]=='1');
883 @ <br />
884 }
885 }
886 @ </td><td style="width: 30;"></td><td valign="top">
887 for(pSet=ctrlSettings; pSet->name!=0; pSet++){
888 if( pSet->width!=0 ){
889 entry_attribute(pSet->name, /*pSet->width*/ 40, pSet->name,
890 pSet->var!=0 ? pSet->var : pSet->name,
891 (char*)pSet->def);
892 @ <br />
893 }
894 }
895 @ </td></tr></table>
896 @ <p><input type="submit" name="submit" value="Apply Changes" /></p>
897 @ </div></form>
898 @ <hr /><p>
899 @ These settings work in the same way, as the <kbd>set</kbd> commandline:<br />
900 @ </p><pre>%s(zHelp_setting_cmd)</pre>
901 db_end_transaction(0);
902 style_footer();
903 }
904
905 /*
@@ -938,10 +938,15 @@
938 @ <blockquote><p>%h(g.zBaseURL)/home</p></blockquote>
939 @
940 @ <p>The default "/home" page displays a Wiki page with the same name
941 @ as the Project Name specified above. Some sites prefer to redirect
942 @ to a documentation page (ex: "/doc/tip/index.wiki") or to "/timeline".</p>
943 @
944 @ <p>Note: To avoid a redirect loop or other problems, this entry must
945 @ begin with "/" and it must specify a valid page. For example,
946 @ "<b>/home</b>" will work but "<b>home</b>" will not, since it omits the
947 @ leading "/".</p>
948 @ <hr />
949 onoff_attribute("Use HTML as wiki markup language",
950 "wiki-use-html", "wiki-use-html", 0);
951 @ <p>Use HTML as the wiki markup language. Wiki links will still be parsed
952 @ but all other wiki formatting will be ignored. This option is helpful
953
+6 -6
--- src/shun.c
+++ src/shun.c
@@ -69,29 +69,29 @@
6969
style_header("Shunned Artifacts");
7070
if( zUuid && P("sub") ){
7171
login_verify_csrf_secret();
7272
db_multi_exec("DELETE FROM shun WHERE uuid='%s'", zUuid);
7373
if( db_exists("SELECT 1 FROM blob WHERE uuid='%s'", zUuid) ){
74
- @ <p><font color="blue">Artifact
74
+ @ <p class="noMoreShun">Artifact
7575
@ <a href="%s(g.zBaseURL)/artifact/%s(zUuid)">%s(zUuid)</a> is no
76
- @ longer being shunned.</font></p>
76
+ @ longer being shunned.</p>
7777
}else{
78
- @ <p><font color="blue">Artifact %s(zUuid)</a> will no longer
78
+ @ <p class="noMoreShun">Artifact %s(zUuid) will no longer
7979
@ be shunned. But it does not exist in the repository. It
8080
@ may be necessary to rebuild the repository using the
8181
@ <b>fossil rebuild</b> command-line before the artifact content
82
- @ can pulled in from other respositories.</font></p>
82
+ @ can pulled in from other respositories.</p>
8383
}
8484
}
8585
if( zUuid && P("add") ){
8686
login_verify_csrf_secret();
8787
db_multi_exec("INSERT OR IGNORE INTO shun VALUES('%s')", zUuid);
88
- @ <p><font color="blue">Artifact
88
+ @ <p class="shunned">Artifact
8989
@ <a href="%s(g.zBaseURL)/artifact/%s(zUuid)">%s(zUuid)</a> has been
9090
@ shunned. It will no longer be pushed.
9191
@ It will be removed from the repository the next time the respository
92
- @ is rebuilt using the <b>fossil rebuild</b> command-line</font></p>
92
+ @ is rebuilt using the <b>fossil rebuild</b> command-line</p>
9393
}
9494
@ <p>A shunned artifact will not be pushed nor accepted in a pull and the
9595
@ artifact content will be purged from the repository the next time the
9696
@ repository is rebuilt. A list of shunned artifacts can be seen at the
9797
@ bottom of this page.</p>
9898
--- src/shun.c
+++ src/shun.c
@@ -69,29 +69,29 @@
69 style_header("Shunned Artifacts");
70 if( zUuid && P("sub") ){
71 login_verify_csrf_secret();
72 db_multi_exec("DELETE FROM shun WHERE uuid='%s'", zUuid);
73 if( db_exists("SELECT 1 FROM blob WHERE uuid='%s'", zUuid) ){
74 @ <p><font color="blue">Artifact
75 @ <a href="%s(g.zBaseURL)/artifact/%s(zUuid)">%s(zUuid)</a> is no
76 @ longer being shunned.</font></p>
77 }else{
78 @ <p><font color="blue">Artifact %s(zUuid)</a> will no longer
79 @ be shunned. But it does not exist in the repository. It
80 @ may be necessary to rebuild the repository using the
81 @ <b>fossil rebuild</b> command-line before the artifact content
82 @ can pulled in from other respositories.</font></p>
83 }
84 }
85 if( zUuid && P("add") ){
86 login_verify_csrf_secret();
87 db_multi_exec("INSERT OR IGNORE INTO shun VALUES('%s')", zUuid);
88 @ <p><font color="blue">Artifact
89 @ <a href="%s(g.zBaseURL)/artifact/%s(zUuid)">%s(zUuid)</a> has been
90 @ shunned. It will no longer be pushed.
91 @ It will be removed from the repository the next time the respository
92 @ is rebuilt using the <b>fossil rebuild</b> command-line</font></p>
93 }
94 @ <p>A shunned artifact will not be pushed nor accepted in a pull and the
95 @ artifact content will be purged from the repository the next time the
96 @ repository is rebuilt. A list of shunned artifacts can be seen at the
97 @ bottom of this page.</p>
98
--- src/shun.c
+++ src/shun.c
@@ -69,29 +69,29 @@
69 style_header("Shunned Artifacts");
70 if( zUuid && P("sub") ){
71 login_verify_csrf_secret();
72 db_multi_exec("DELETE FROM shun WHERE uuid='%s'", zUuid);
73 if( db_exists("SELECT 1 FROM blob WHERE uuid='%s'", zUuid) ){
74 @ <p class="noMoreShun">Artifact
75 @ <a href="%s(g.zBaseURL)/artifact/%s(zUuid)">%s(zUuid)</a> is no
76 @ longer being shunned.</p>
77 }else{
78 @ <p class="noMoreShun">Artifact %s(zUuid) will no longer
79 @ be shunned. But it does not exist in the repository. It
80 @ may be necessary to rebuild the repository using the
81 @ <b>fossil rebuild</b> command-line before the artifact content
82 @ can pulled in from other respositories.</p>
83 }
84 }
85 if( zUuid && P("add") ){
86 login_verify_csrf_secret();
87 db_multi_exec("INSERT OR IGNORE INTO shun VALUES('%s')", zUuid);
88 @ <p class="shunned">Artifact
89 @ <a href="%s(g.zBaseURL)/artifact/%s(zUuid)">%s(zUuid)</a> has been
90 @ shunned. It will no longer be pushed.
91 @ It will be removed from the repository the next time the respository
92 @ is rebuilt using the <b>fossil rebuild</b> command-line</p>
93 }
94 @ <p>A shunned artifact will not be pushed nor accepted in a pull and the
95 @ artifact content will be purged from the repository the next time the
96 @ repository is rebuilt. A list of shunned artifacts can be seen at the
97 @ bottom of this page.</p>
98
+1 -1
--- src/skins.c
+++ src/skins.c
@@ -831,11 +831,11 @@
831831
const char *zN = db_column_text(&q, 0);
832832
const char *zV = db_column_text(&q, 1);
833833
if( strcmp(zV, zCurrent)==0 ){
834834
@ <li><p>%h(zN).&nbsp;&nbsp; <b>Currently In Use</b></p>
835835
}else{
836
- @ <li><form action="%s(g.zBaseURL)/setup_skin" method="POST">
836
+ @ <li><form action="%s(g.zBaseURL)/setup_skin" method="post">
837837
@ %h(zN).&nbsp;&nbsp;
838838
@ <input type="hidden" name="sn" value="%h(zN)">
839839
@ <input type="submit" name="load" value="Use This Skin">
840840
@ <input type="submit" name="del1" value="Delete This Skin">
841841
@ </form></li>
842842
--- src/skins.c
+++ src/skins.c
@@ -831,11 +831,11 @@
831 const char *zN = db_column_text(&q, 0);
832 const char *zV = db_column_text(&q, 1);
833 if( strcmp(zV, zCurrent)==0 ){
834 @ <li><p>%h(zN).&nbsp;&nbsp; <b>Currently In Use</b></p>
835 }else{
836 @ <li><form action="%s(g.zBaseURL)/setup_skin" method="POST">
837 @ %h(zN).&nbsp;&nbsp;
838 @ <input type="hidden" name="sn" value="%h(zN)">
839 @ <input type="submit" name="load" value="Use This Skin">
840 @ <input type="submit" name="del1" value="Delete This Skin">
841 @ </form></li>
842
--- src/skins.c
+++ src/skins.c
@@ -831,11 +831,11 @@
831 const char *zN = db_column_text(&q, 0);
832 const char *zV = db_column_text(&q, 1);
833 if( strcmp(zV, zCurrent)==0 ){
834 @ <li><p>%h(zN).&nbsp;&nbsp; <b>Currently In Use</b></p>
835 }else{
836 @ <li><form action="%s(g.zBaseURL)/setup_skin" method="post">
837 @ %h(zN).&nbsp;&nbsp;
838 @ <input type="hidden" name="sn" value="%h(zN)">
839 @ <input type="submit" name="load" value="Use This Skin">
840 @ <input type="submit" name="del1" value="Delete This Skin">
841 @ </form></li>
842
+1 -1
--- src/skins.c
+++ src/skins.c
@@ -831,11 +831,11 @@
831831
const char *zN = db_column_text(&q, 0);
832832
const char *zV = db_column_text(&q, 1);
833833
if( strcmp(zV, zCurrent)==0 ){
834834
@ <li><p>%h(zN).&nbsp;&nbsp; <b>Currently In Use</b></p>
835835
}else{
836
- @ <li><form action="%s(g.zBaseURL)/setup_skin" method="POST">
836
+ @ <li><form action="%s(g.zBaseURL)/setup_skin" method="post">
837837
@ %h(zN).&nbsp;&nbsp;
838838
@ <input type="hidden" name="sn" value="%h(zN)">
839839
@ <input type="submit" name="load" value="Use This Skin">
840840
@ <input type="submit" name="del1" value="Delete This Skin">
841841
@ </form></li>
842842
--- src/skins.c
+++ src/skins.c
@@ -831,11 +831,11 @@
831 const char *zN = db_column_text(&q, 0);
832 const char *zV = db_column_text(&q, 1);
833 if( strcmp(zV, zCurrent)==0 ){
834 @ <li><p>%h(zN).&nbsp;&nbsp; <b>Currently In Use</b></p>
835 }else{
836 @ <li><form action="%s(g.zBaseURL)/setup_skin" method="POST">
837 @ %h(zN).&nbsp;&nbsp;
838 @ <input type="hidden" name="sn" value="%h(zN)">
839 @ <input type="submit" name="load" value="Use This Skin">
840 @ <input type="submit" name="del1" value="Delete This Skin">
841 @ </form></li>
842
--- src/skins.c
+++ src/skins.c
@@ -831,11 +831,11 @@
831 const char *zN = db_column_text(&q, 0);
832 const char *zV = db_column_text(&q, 1);
833 if( strcmp(zV, zCurrent)==0 ){
834 @ <li><p>%h(zN).&nbsp;&nbsp; <b>Currently In Use</b></p>
835 }else{
836 @ <li><form action="%s(g.zBaseURL)/setup_skin" method="post">
837 @ %h(zN).&nbsp;&nbsp;
838 @ <input type="hidden" name="sn" value="%h(zN)">
839 @ <input type="submit" name="load" value="Use This Skin">
840 @ <input type="submit" name="del1" value="Delete This Skin">
841 @ </form></li>
842
+2369 -1283
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.7.2. By combining all the individual C code files into this
3
+** version 3.7.3. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a one translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% are more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -352,19 +352,25 @@
352352
# define SQLITE_INT_TO_PTR(X) ((void*)(X))
353353
# define SQLITE_PTR_TO_INT(X) ((int)(X))
354354
#endif
355355
356356
/*
357
-** The SQLITE_THREADSAFE macro must be defined as either 0 or 1.
357
+** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
358
+** 0 means mutexes are permanently disable and the library is never
359
+** threadsafe. 1 means the library is serialized which is the highest
360
+** level of threadsafety. 2 means the libary is multithreaded - multiple
361
+** threads can use SQLite as long as no two threads try to use the same
362
+** database connection at the same time.
363
+**
358364
** Older versions of SQLite used an optional THREADSAFE macro.
359
-** We support that for legacy
365
+** We support that for legacy.
360366
*/
361367
#if !defined(SQLITE_THREADSAFE)
362368
#if defined(THREADSAFE)
363369
# define SQLITE_THREADSAFE THREADSAFE
364370
#else
365
-# define SQLITE_THREADSAFE 1
371
+# define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */
366372
#endif
367373
#endif
368374
369375
/*
370376
** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
@@ -642,13 +648,13 @@
642648
**
643649
** See also: [sqlite3_libversion()],
644650
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
645651
** [sqlite_version()] and [sqlite_source_id()].
646652
*/
647
-#define SQLITE_VERSION "3.7.2"
648
-#define SQLITE_VERSION_NUMBER 3007002
649
-#define SQLITE_SOURCE_ID "2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3"
653
+#define SQLITE_VERSION "3.7.3"
654
+#define SQLITE_VERSION_NUMBER 3007003
655
+#define SQLITE_SOURCE_ID "2010-10-04 23:55:51 ece641eb8951c6314cedbdb3243f91cb199c3239"
650656
651657
/*
652658
** CAPI3REF: Run-Time Library Version Numbers
653659
** KEYWORDS: sqlite3_version, sqlite3_sourceid
654660
**
@@ -1292,19 +1298,23 @@
12921298
** object once the object has been registered.
12931299
**
12941300
** The zName field holds the name of the VFS module. The name must
12951301
** be unique across all VFS modules.
12961302
**
1297
-** SQLite will guarantee that the zFilename parameter to xOpen
1303
+** ^SQLite guarantees that the zFilename parameter to xOpen
12981304
** is either a NULL pointer or string obtained
1299
-** from xFullPathname(). SQLite further guarantees that
1305
+** from xFullPathname() with an optional suffix added.
1306
+** ^If a suffix is added to the zFilename parameter, it will
1307
+** consist of a single "-" character followed by no more than
1308
+** 10 alphanumeric and/or "-" characters.
1309
+** ^SQLite further guarantees that
13001310
** the string will be valid and unchanged until xClose() is
13011311
** called. Because of the previous sentence,
13021312
** the [sqlite3_file] can safely store a pointer to the
13031313
** filename if it needs to remember the filename for some reason.
1304
-** If the zFilename parameter is xOpen is a NULL pointer then xOpen
1305
-** must invent its own temporary name for the file. Whenever the
1314
+** If the zFilename parameter to xOpen is a NULL pointer then xOpen
1315
+** must invent its own temporary name for the file. ^Whenever the
13061316
** xFilename parameter is NULL it will also be the case that the
13071317
** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
13081318
**
13091319
** The flags argument to xOpen() includes all bits set in
13101320
** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
@@ -1311,11 +1321,11 @@
13111321
** or [sqlite3_open16()] is used, then flags includes at least
13121322
** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
13131323
** If xOpen() opens a file read-only then it sets *pOutFlags to
13141324
** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
13151325
**
1316
-** SQLite will also add one of the following flags to the xOpen()
1326
+** ^(SQLite will also add one of the following flags to the xOpen()
13171327
** call, depending on the object being opened:
13181328
**
13191329
** <ul>
13201330
** <li> [SQLITE_OPEN_MAIN_DB]
13211331
** <li> [SQLITE_OPEN_MAIN_JOURNAL]
@@ -1322,11 +1332,12 @@
13221332
** <li> [SQLITE_OPEN_TEMP_DB]
13231333
** <li> [SQLITE_OPEN_TEMP_JOURNAL]
13241334
** <li> [SQLITE_OPEN_TRANSIENT_DB]
13251335
** <li> [SQLITE_OPEN_SUBJOURNAL]
13261336
** <li> [SQLITE_OPEN_MASTER_JOURNAL]
1327
-** </ul>
1337
+** <li> [SQLITE_OPEN_WAL]
1338
+** </ul>)^
13281339
**
13291340
** The file I/O implementation can use the object type flags to
13301341
** change the way it deals with files. For example, an application
13311342
** that does not care about crash recovery or rollback might make
13321343
** the open of a journal file a no-op. Writes to this journal would
@@ -1341,39 +1352,40 @@
13411352
** <li> [SQLITE_OPEN_DELETEONCLOSE]
13421353
** <li> [SQLITE_OPEN_EXCLUSIVE]
13431354
** </ul>
13441355
**
13451356
** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
1346
-** deleted when it is closed. The [SQLITE_OPEN_DELETEONCLOSE]
1347
-** will be set for TEMP databases, journals and for subjournals.
1357
+** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE]
1358
+** will be set for TEMP databases and their journals, transient
1359
+** databases, and subjournals.
13481360
**
1349
-** The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
1361
+** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
13501362
** with the [SQLITE_OPEN_CREATE] flag, which are both directly
13511363
** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
13521364
** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
13531365
** SQLITE_OPEN_CREATE, is used to indicate that file should always
13541366
** be created, and that it is an error if it already exists.
13551367
** It is <i>not</i> used to indicate the file should be opened
13561368
** for exclusive access.
13571369
**
1358
-** At least szOsFile bytes of memory are allocated by SQLite
1370
+** ^At least szOsFile bytes of memory are allocated by SQLite
13591371
** to hold the [sqlite3_file] structure passed as the third
13601372
** argument to xOpen. The xOpen method does not have to
13611373
** allocate the structure; it should just fill it in. Note that
13621374
** the xOpen method must set the sqlite3_file.pMethods to either
13631375
** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
13641376
** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
13651377
** element will be valid after xOpen returns regardless of the success
13661378
** or failure of the xOpen call.
13671379
**
1368
-** The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
1380
+** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
13691381
** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
13701382
** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
13711383
** to test whether a file is at least readable. The file can be a
13721384
** directory.
13731385
**
1374
-** SQLite will always allocate at least mxPathname+1 bytes for the
1386
+** ^SQLite will always allocate at least mxPathname+1 bytes for the
13751387
** output buffer xFullPathname. The exact size of the output buffer
13761388
** is also passed as a parameter to both methods. If the output buffer
13771389
** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
13781390
** handled as a fatal error by SQLite, vfs implementations should endeavor
13791391
** to prevent this by setting mxPathname to a sufficiently large value.
@@ -1383,14 +1395,14 @@
13831395
** included in the VFS structure for completeness.
13841396
** The xRandomness() function attempts to return nBytes bytes
13851397
** of good-quality randomness into zOut. The return value is
13861398
** the actual number of bytes of randomness obtained.
13871399
** The xSleep() method causes the calling thread to sleep for at
1388
-** least the number of microseconds given. The xCurrentTime()
1400
+** least the number of microseconds given. ^The xCurrentTime()
13891401
** method returns a Julian Day Number for the current date and time as
13901402
** a floating point value.
1391
-** The xCurrentTimeInt64() method returns, as an integer, the Julian
1403
+** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
13921404
** Day Number multipled by 86400000 (the number of milliseconds in
13931405
** a 24-hour day).
13941406
** ^SQLite will use the xCurrentTimeInt64() method to get the current
13951407
** date and time if that method is available (if iVersion is 2 or
13961408
** greater and the function pointer is not NULL) and will fall back
@@ -1783,11 +1795,11 @@
17831795
** statistics. ^(When memory allocation statistics are disabled, the
17841796
** following SQLite interfaces become non-operational:
17851797
** <ul>
17861798
** <li> [sqlite3_memory_used()]
17871799
** <li> [sqlite3_memory_highwater()]
1788
-** <li> [sqlite3_soft_heap_limit()]
1800
+** <li> [sqlite3_soft_heap_limit64()]
17891801
** <li> [sqlite3_status()]
17901802
** </ul>)^
17911803
** ^Memory allocation statistics are enabled by default unless SQLite is
17921804
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
17931805
** allocation statistics are disabled by default.
@@ -1797,19 +1809,18 @@
17971809
** <dd> ^This option specifies a static memory buffer that SQLite can use for
17981810
** scratch memory. There are three arguments: A pointer an 8-byte
17991811
** aligned memory buffer from which the scrach allocations will be
18001812
** drawn, the size of each scratch allocation (sz),
18011813
** and the maximum number of scratch allocations (N). The sz
1802
-** argument must be a multiple of 16. The sz parameter should be a few bytes
1803
-** larger than the actual scratch space required due to internal overhead.
1814
+** argument must be a multiple of 16.
18041815
** The first argument must be a pointer to an 8-byte aligned buffer
18051816
** of at least sz*N bytes of memory.
1806
-** ^SQLite will use no more than one scratch buffer per thread. So
1807
-** N should be set to the expected maximum number of threads. ^SQLite will
1808
-** never require a scratch buffer that is more than 6 times the database
1809
-** page size. ^If SQLite needs needs additional scratch memory beyond
1810
-** what is provided by this configuration option, then
1817
+** ^SQLite will use no more than two scratch buffers per thread. So
1818
+** N should be set to twice the expected maximum number of threads.
1819
+** ^SQLite will never require a scratch buffer that is more than 6
1820
+** times the database page size. ^If SQLite needs needs additional
1821
+** scratch memory beyond what is provided by this configuration option, then
18111822
** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
18121823
**
18131824
** <dt>SQLITE_CONFIG_PAGECACHE</dt>
18141825
** <dd> ^This option specifies a static memory buffer that SQLite can use for
18151826
** the database page cache with the default page cache implemenation.
@@ -1825,12 +1836,11 @@
18251836
** argument should point to an allocation of at least sz*N bytes of memory.
18261837
** ^SQLite will use the memory provided by the first argument to satisfy its
18271838
** memory needs for the first N pages that it adds to cache. ^If additional
18281839
** page cache memory is needed beyond what is provided by this option, then
18291840
** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1830
-** ^The implementation might use one or more of the N buffers to hold
1831
-** memory accounting information. The pointer in the first argument must
1841
+** The pointer in the first argument must
18321842
** be aligned to an 8-byte boundary or subsequent behavior of SQLite
18331843
** will be undefined.</dd>
18341844
**
18351845
** <dt>SQLITE_CONFIG_HEAP</dt>
18361846
** <dd> ^This option specifies a static memory buffer that SQLite will use
@@ -1955,12 +1965,18 @@
19551965
** size of each lookaside buffer slot. ^The third argument is the number of
19561966
** slots. The size of the buffer in the first argument must be greater than
19571967
** or equal to the product of the second and third arguments. The buffer
19581968
** must be aligned to an 8-byte boundary. ^If the second argument to
19591969
** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
1960
-** rounded down to the next smaller
1961
-** multiple of 8. See also: [SQLITE_CONFIG_LOOKASIDE]</dd>
1970
+** rounded down to the next smaller multiple of 8. ^(The lookaside memory
1971
+** configuration for a database connection can only be changed when that
1972
+** connection is not currently using lookaside memory, or in other words
1973
+** when the "current value" returned by
1974
+** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
1975
+** Any attempt to change the lookaside memory configuration when lookaside
1976
+** memory is in use leaves the configuration unchanged and returns
1977
+** [SQLITE_BUSY].)^</dd>
19621978
**
19631979
** </dl>
19641980
*/
19651981
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
19661982
@@ -2260,10 +2276,13 @@
22602276
*/
22612277
SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
22622278
22632279
/*
22642280
** CAPI3REF: Convenience Routines For Running Queries
2281
+**
2282
+** This is a legacy interface that is preserved for backwards compatibility.
2283
+** Use of this interface is not recommended.
22652284
**
22662285
** Definition: A <b>result table</b> is memory data structure created by the
22672286
** [sqlite3_get_table()] interface. A result table records the
22682287
** complete query results from one or more queries.
22692288
**
@@ -2281,11 +2300,11 @@
22812300
**
22822301
** A result table might consist of one or more memory allocations.
22832302
** It is not safe to pass a result table directly to [sqlite3_free()].
22842303
** A result table should be deallocated using [sqlite3_free_table()].
22852304
**
2286
-** As an example of the result table format, suppose a query result
2305
+** ^(As an example of the result table format, suppose a query result
22872306
** is as follows:
22882307
**
22892308
** <blockquote><pre>
22902309
** Name | Age
22912310
** -----------------------
@@ -2305,31 +2324,31 @@
23052324
** azResult&#91;3] = "43";
23062325
** azResult&#91;4] = "Bob";
23072326
** azResult&#91;5] = "28";
23082327
** azResult&#91;6] = "Cindy";
23092328
** azResult&#91;7] = "21";
2310
-** </pre></blockquote>
2329
+** </pre></blockquote>)^
23112330
**
23122331
** ^The sqlite3_get_table() function evaluates one or more
23132332
** semicolon-separated SQL statements in the zero-terminated UTF-8
23142333
** string of its 2nd parameter and returns a result table to the
23152334
** pointer given in its 3rd parameter.
23162335
**
23172336
** After the application has finished with the result from sqlite3_get_table(),
2318
-** it should pass the result table pointer to sqlite3_free_table() in order to
2337
+** it must pass the result table pointer to sqlite3_free_table() in order to
23192338
** release the memory that was malloced. Because of the way the
23202339
** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
23212340
** function must not try to call [sqlite3_free()] directly. Only
23222341
** [sqlite3_free_table()] is able to release the memory properly and safely.
23232342
**
2324
-** ^(The sqlite3_get_table() interface is implemented as a wrapper around
2343
+** The sqlite3_get_table() interface is implemented as a wrapper around
23252344
** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
23262345
** to any internal data structures of SQLite. It uses only the public
23272346
** interface defined here. As a consequence, errors that occur in the
23282347
** wrapper layer outside of the internal [sqlite3_exec()] call are not
23292348
** reflected in subsequent calls to [sqlite3_errcode()] or
2330
-** [sqlite3_errmsg()].)^
2349
+** [sqlite3_errmsg()].
23312350
*/
23322351
SQLITE_API int sqlite3_get_table(
23332352
sqlite3 *db, /* An open database */
23342353
const char *zSql, /* SQL to be evaluated */
23352354
char ***pazResult, /* Results of the query */
@@ -2477,11 +2496,13 @@
24772496
** by sqlite3_realloc() and the prior allocation is freed.
24782497
** ^If sqlite3_realloc() returns NULL, then the prior allocation
24792498
** is not freed.
24802499
**
24812500
** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
2482
-** is always aligned to at least an 8 byte boundary.
2501
+** is always aligned to at least an 8 byte boundary, or to a
2502
+** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
2503
+** option is used.
24832504
**
24842505
** In SQLite version 3.5.0 and 3.5.1, it was possible to define
24852506
** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
24862507
** implementation of these routines to be omitted. That capability
24872508
** is no longer provided. Only built-in memory allocators can be used.
@@ -2735,21 +2756,32 @@
27352756
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
27362757
27372758
/*
27382759
** CAPI3REF: Query Progress Callbacks
27392760
**
2740
-** ^This routine configures a callback function - the
2741
-** progress callback - that is invoked periodically during long
2742
-** running calls to [sqlite3_exec()], [sqlite3_step()] and
2743
-** [sqlite3_get_table()]. An example use for this
2761
+** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2762
+** function X to be invoked periodically during long running calls to
2763
+** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2764
+** database connection D. An example use for this
27442765
** interface is to keep a GUI updated during a large query.
2766
+**
2767
+** ^The parameter P is passed through as the only parameter to the
2768
+** callback function X. ^The parameter N is the number of
2769
+** [virtual machine instructions] that are evaluated between successive
2770
+** invocations of the callback X.
2771
+**
2772
+** ^Only a single progress handler may be defined at one time per
2773
+** [database connection]; setting a new progress handler cancels the
2774
+** old one. ^Setting parameter X to NULL disables the progress handler.
2775
+** ^The progress handler is also disabled by setting N to a value less
2776
+** than 1.
27452777
**
27462778
** ^If the progress callback returns non-zero, the operation is
27472779
** interrupted. This feature can be used to implement a
27482780
** "Cancel" button on a GUI progress dialog box.
27492781
**
2750
-** The progress handler must not do anything that will modify
2782
+** The progress handler callback must not do anything that will modify
27512783
** the database connection that invoked the progress handler.
27522784
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
27532785
** database connections for the meaning of "modify" in this paragraph.
27542786
**
27552787
*/
@@ -2804,11 +2836,11 @@
28042836
** </dl>
28052837
**
28062838
** If the 3rd parameter to sqlite3_open_v2() is not one of the
28072839
** combinations shown above or one of the combinations shown above combined
28082840
** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
2809
-** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_SHAREDCACHE] flags,
2841
+** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags,
28102842
** then the behavior is undefined.
28112843
**
28122844
** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
28132845
** opens in the multi-thread [threading mode] as long as the single-thread
28142846
** mode has not been set at compile-time or start-time. ^If the
@@ -2929,21 +2961,26 @@
29292961
** ^(This interface allows the size of various constructs to be limited
29302962
** on a connection by connection basis. The first parameter is the
29312963
** [database connection] whose limit is to be set or queried. The
29322964
** second parameter is one of the [limit categories] that define a
29332965
** class of constructs to be size limited. The third parameter is the
2934
-** new limit for that construct. The function returns the old limit.)^
2966
+** new limit for that construct.)^
29352967
**
29362968
** ^If the new limit is a negative number, the limit is unchanged.
2937
-** ^(For the limit category of SQLITE_LIMIT_XYZ there is a
2969
+** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
29382970
** [limits | hard upper bound]
2939
-** set by a compile-time C preprocessor macro named
2940
-** [limits | SQLITE_MAX_XYZ].
2971
+** set at compile-time by a C preprocessor macro called
2972
+** [limits | SQLITE_MAX_<i>NAME</i>].
29412973
** (The "_LIMIT_" in the name is changed to "_MAX_".))^
29422974
** ^Attempts to increase a limit above its hard upper bound are
29432975
** silently truncated to the hard upper bound.
29442976
**
2977
+** ^Regardless of whether or not the limit was changed, the
2978
+** [sqlite3_limit()] interface returns the prior value of the limit.
2979
+** ^Hence, to find the current value of a limit without changing it,
2980
+** simply invoke this interface with the third parameter set to -1.
2981
+**
29452982
** Run-time limits are intended for use in applications that manage
29462983
** both their own internal database and also databases that are controlled
29472984
** by untrusted external sources. An example application might be a
29482985
** web browser that has its own databases for storing history and
29492986
** separate databases controlled by JavaScript applications downloaded
@@ -2968,11 +3005,11 @@
29683005
** The synopsis of the meanings of the various limits is shown below.
29693006
** Additional information is available at [limits | Limits in SQLite].
29703007
**
29713008
** <dl>
29723009
** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
2973
-** <dd>The maximum size of any string or BLOB or table row.<dd>)^
3010
+** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
29743011
**
29753012
** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
29763013
** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
29773014
**
29783015
** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
@@ -2986,11 +3023,13 @@
29863023
** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
29873024
** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
29883025
**
29893026
** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
29903027
** <dd>The maximum number of instructions in a virtual machine program
2991
-** used to implement an SQL statement.</dd>)^
3028
+** used to implement an SQL statement. This limit is not currently
3029
+** enforced, though that might be added in some future release of
3030
+** SQLite.</dd>)^
29923031
**
29933032
** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
29943033
** <dd>The maximum number of arguments on a function.</dd>)^
29953034
**
29963035
** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
@@ -2999,12 +3038,11 @@
29993038
** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
30003039
** <dd>The maximum length of the pattern argument to the [LIKE] or
30013040
** [GLOB] operators.</dd>)^
30023041
**
30033042
** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
3004
-** <dd>The maximum number of variables in an SQL statement that can
3005
-** be bound.</dd>)^
3043
+** <dd>The maximum index number of any [parameter] in an SQL statement.)^
30063044
**
30073045
** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
30083046
** <dd>The maximum depth of recursion for triggers.</dd>)^
30093047
** </dl>
30103048
*/
@@ -3072,16 +3110,11 @@
30723110
**
30733111
** <ol>
30743112
** <li>
30753113
** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
30763114
** always used to do, [sqlite3_step()] will automatically recompile the SQL
3077
-** statement and try to run it again. ^If the schema has changed in
3078
-** a way that makes the statement no longer valid, [sqlite3_step()] will still
3079
-** return [SQLITE_SCHEMA]. But unlike the legacy behavior, [SQLITE_SCHEMA] is
3080
-** now a fatal error. Calling [sqlite3_prepare_v2()] again will not make the
3081
-** error go away. Note: use [sqlite3_errmsg()] to find the text
3082
-** of the parsing error that results in an [SQLITE_SCHEMA] return.
3115
+** statement and try to run it again.
30833116
** </li>
30843117
**
30853118
** <li>
30863119
** ^When an error occurs, [sqlite3_step()] will return one of the detailed
30873120
** [error codes] or [extended error codes]. ^The legacy behavior was that
@@ -3090,15 +3123,20 @@
30903123
** in order to find the underlying cause of the problem. With the "v2" prepare
30913124
** interfaces, the underlying reason for the error is returned immediately.
30923125
** </li>
30933126
**
30943127
** <li>
3095
-** ^If the value of a [parameter | host parameter] in the WHERE clause might
3096
-** change the query plan for a statement, then the statement may be
3097
-** automatically recompiled (as if there had been a schema change) on the first
3098
-** [sqlite3_step()] call following any change to the
3099
-** [sqlite3_bind_text | bindings] of the [parameter].
3128
+** ^If the specific value bound to [parameter | host parameter] in the
3129
+** WHERE clause might influence the choice of query plan for a statement,
3130
+** then the statement will be automatically recompiled, as if there had been
3131
+** a schema change, on the first [sqlite3_step()] call following any change
3132
+** to the [sqlite3_bind_text | bindings] of that [parameter].
3133
+** ^The specific value of WHERE-clause [parameter] might influence the
3134
+** choice of query plan if the parameter is the left-hand side of a [LIKE]
3135
+** or [GLOB] operator or if the parameter is compared to an indexed column
3136
+** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled.
3137
+** the
31003138
** </li>
31013139
** </ol>
31023140
*/
31033141
SQLITE_API int sqlite3_prepare(
31043142
sqlite3 *db, /* Database handle */
@@ -3161,11 +3199,11 @@
31613199
** or if SQLite is run in one of reduced mutex modes
31623200
** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
31633201
** then there is no distinction between protected and unprotected
31643202
** sqlite3_value objects and they can be used interchangeably. However,
31653203
** for maximum code portability it is recommended that applications
3166
-** still make the distinction between between protected and unprotected
3204
+** still make the distinction between protected and unprotected
31673205
** sqlite3_value objects even when not strictly required.
31683206
**
31693207
** ^The sqlite3_value objects that are passed as parameters into the
31703208
** implementation of [application-defined SQL functions] are protected.
31713209
** ^The sqlite3_value object returned by
@@ -3356,10 +3394,12 @@
33563394
** CAPI3REF: Number Of Columns In A Result Set
33573395
**
33583396
** ^Return the number of columns in the result set returned by the
33593397
** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
33603398
** statement that does not return data (for example an [UPDATE]).
3399
+**
3400
+** See also: [sqlite3_data_count()]
33613401
*/
33623402
SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
33633403
33643404
/*
33653405
** CAPI3REF: Column Names In A Result Set
@@ -3546,12 +3586,18 @@
35463586
SQLITE_API int sqlite3_step(sqlite3_stmt*);
35473587
35483588
/*
35493589
** CAPI3REF: Number of columns in a result set
35503590
**
3551
-** ^The sqlite3_data_count(P) the number of columns in the
3552
-** of the result set of [prepared statement] P.
3591
+** ^The sqlite3_data_count(P) interface returns the number of columns in the
3592
+** current row of the result set of [prepared statement] P.
3593
+** ^If prepared statement P does not have results ready to return
3594
+** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
3595
+** interfaces) then sqlite3_data_count(P) returns 0.
3596
+** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
3597
+**
3598
+** See also: [sqlite3_column_count()]
35533599
*/
35543600
SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
35553601
35563602
/*
35573603
** CAPI3REF: Fundamental Datatypes
@@ -3627,22 +3673,30 @@
36273673
** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
36283674
** the string to UTF-8 and then returns the number of bytes.
36293675
** ^If the result is a numeric value then sqlite3_column_bytes() uses
36303676
** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
36313677
** the number of bytes in that string.
3632
-** ^The value returned does not include the zero terminator at the end
3633
-** of the string. ^For clarity: the value returned is the number of
3678
+** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
3679
+**
3680
+** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
3681
+** routine returns the number of bytes in that BLOB or string.
3682
+** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
3683
+** the string to UTF-16 and then returns the number of bytes.
3684
+** ^If the result is a numeric value then sqlite3_column_bytes16() uses
3685
+** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
3686
+** the number of bytes in that string.
3687
+** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
3688
+**
3689
+** ^The values returned by [sqlite3_column_bytes()] and
3690
+** [sqlite3_column_bytes16()] do not include the zero terminators at the end
3691
+** of the string. ^For clarity: the values returned by
3692
+** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
36343693
** bytes in the string, not the number of characters.
36353694
**
36363695
** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
36373696
** even empty strings, are always zero terminated. ^The return
3638
-** value from sqlite3_column_blob() for a zero-length BLOB is an arbitrary
3639
-** pointer, possibly even a NULL pointer.
3640
-**
3641
-** ^The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
3642
-** but leaves the result in UTF-16 in native byte order instead of UTF-8.
3643
-** ^The zero terminator is not included in this count.
3697
+** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
36443698
**
36453699
** ^The object returned by [sqlite3_column_value()] is an
36463700
** [unprotected sqlite3_value] object. An unprotected sqlite3_value object
36473701
** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
36483702
** If the [unprotected sqlite3_value] object returned by
@@ -3683,14 +3737,14 @@
36833737
** and atof(). SQLite does not really use these functions. It has its
36843738
** own equivalent internal routines. The atoi() and atof() names are
36853739
** used in the table for brevity and because they are familiar to most
36863740
** C programmers.
36873741
**
3688
-** ^Note that when type conversions occur, pointers returned by prior
3742
+** Note that when type conversions occur, pointers returned by prior
36893743
** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
36903744
** sqlite3_column_text16() may be invalidated.
3691
-** ^(Type conversions and pointer invalidations might occur
3745
+** Type conversions and pointer invalidations might occur
36923746
** in the following cases:
36933747
**
36943748
** <ul>
36953749
** <li> The initial content is a BLOB and sqlite3_column_text() or
36963750
** sqlite3_column_text16() is called. A zero-terminator might
@@ -3699,26 +3753,26 @@
36993753
** sqlite3_column_text16() is called. The content must be converted
37003754
** to UTF-16.</li>
37013755
** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
37023756
** sqlite3_column_text() is called. The content must be converted
37033757
** to UTF-8.</li>
3704
-** </ul>)^
3758
+** </ul>
37053759
**
37063760
** ^Conversions between UTF-16be and UTF-16le are always done in place and do
37073761
** not invalidate a prior pointer, though of course the content of the buffer
3708
-** that the prior pointer points to will have been modified. Other kinds
3762
+** that the prior pointer references will have been modified. Other kinds
37093763
** of conversion are done in place when it is possible, but sometimes they
37103764
** are not possible and in those cases prior pointers are invalidated.
37113765
**
3712
-** ^(The safest and easiest to remember policy is to invoke these routines
3766
+** The safest and easiest to remember policy is to invoke these routines
37133767
** in one of the following ways:
37143768
**
37153769
** <ul>
37163770
** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
37173771
** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
37183772
** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
3719
-** </ul>)^
3773
+** </ul>
37203774
**
37213775
** In other words, you should call sqlite3_column_text(),
37223776
** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
37233777
** into the desired format, then invoke sqlite3_column_bytes() or
37243778
** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
@@ -3752,21 +3806,30 @@
37523806
37533807
/*
37543808
** CAPI3REF: Destroy A Prepared Statement Object
37553809
**
37563810
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
3757
-** ^If the statement was executed successfully or not executed at all, then
3758
-** SQLITE_OK is returned. ^If execution of the statement failed then an
3759
-** [error code] or [extended error code] is returned.
3811
+** ^If the most recent evaluation of the statement encountered no errors or
3812
+** or if the statement is never been evaluated, then sqlite3_finalize() returns
3813
+** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
3814
+** sqlite3_finalize(S) returns the appropriate [error code] or
3815
+** [extended error code].
37603816
**
3761
-** ^This routine can be called at any point during the execution of the
3762
-** [prepared statement]. ^If the virtual machine has not
3763
-** completed execution when this routine is called, that is like
3764
-** encountering an error or an [sqlite3_interrupt | interrupt].
3765
-** ^Incomplete updates may be rolled back and transactions canceled,
3766
-** depending on the circumstances, and the
3767
-** [error code] returned will be [SQLITE_ABORT].
3817
+** ^The sqlite3_finalize(S) routine can be called at any point during
3818
+** the life cycle of [prepared statement] S:
3819
+** before statement S is ever evaluated, after
3820
+** one or more calls to [sqlite3_reset()], or after any call
3821
+** to [sqlite3_step()] regardless of whether or not the statement has
3822
+** completed execution.
3823
+**
3824
+** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
3825
+**
3826
+** The application must finalize every [prepared statement] in order to avoid
3827
+** resource leaks. It is a grievous error for the application to try to use
3828
+** a prepared statement after it has been finalized. Any use of a prepared
3829
+** statement after it has been finalized can result in undefined and
3830
+** undesirable behavior such as segfaults and heap corruption.
37683831
*/
37693832
SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
37703833
37713834
/*
37723835
** CAPI3REF: Reset A Prepared Statement Object
@@ -3798,40 +3861,42 @@
37983861
** CAPI3REF: Create Or Redefine SQL Functions
37993862
** KEYWORDS: {function creation routines}
38003863
** KEYWORDS: {application-defined SQL function}
38013864
** KEYWORDS: {application-defined SQL functions}
38023865
**
3803
-** ^These two functions (collectively known as "function creation routines")
3866
+** ^These functions (collectively known as "function creation routines")
38043867
** are used to add SQL functions or aggregates or to redefine the behavior
3805
-** of existing SQL functions or aggregates. The only difference between the
3806
-** two is that the second parameter, the name of the (scalar) function or
3807
-** aggregate, is encoded in UTF-8 for sqlite3_create_function() and UTF-16
3808
-** for sqlite3_create_function16().
3868
+** of existing SQL functions or aggregates. The only differences between
3869
+** these routines are the text encoding expected for
3870
+** the the second parameter (the name of the function being created)
3871
+** and the presence or absence of a destructor callback for
3872
+** the application data pointer.
38093873
**
38103874
** ^The first parameter is the [database connection] to which the SQL
38113875
** function is to be added. ^If an application uses more than one database
38123876
** connection then application-defined SQL functions must be added
38133877
** to each database connection separately.
38143878
**
3815
-** The second parameter is the name of the SQL function to be created or
3816
-** redefined. ^The length of the name is limited to 255 bytes, exclusive of
3817
-** the zero-terminator. Note that the name length limit is in bytes, not
3818
-** characters. ^Any attempt to create a function with a longer name
3819
-** will result in [SQLITE_ERROR] being returned.
3879
+** ^The second parameter is the name of the SQL function to be created or
3880
+** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
3881
+** representation, exclusive of the zero-terminator. ^Note that the name
3882
+** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
3883
+** ^Any attempt to create a function with a longer name
3884
+** will result in [SQLITE_MISUSE] being returned.
38203885
**
38213886
** ^The third parameter (nArg)
38223887
** is the number of arguments that the SQL function or
38233888
** aggregate takes. ^If this parameter is -1, then the SQL function or
38243889
** aggregate may take any number of arguments between 0 and the limit
38253890
** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
38263891
** parameter is less than -1 or greater than 127 then the behavior is
38273892
** undefined.
38283893
**
3829
-** The fourth parameter, eTextRep, specifies what
3894
+** ^The fourth parameter, eTextRep, specifies what
38303895
** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3831
-** its parameters. Any SQL function implementation should be able to work
3832
-** work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3896
+** its parameters. Every SQL function implementation must be able to work
3897
+** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
38333898
** more efficient with one encoding than another. ^An application may
38343899
** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
38353900
** times with the same function but with different values of eTextRep.
38363901
** ^When multiple implementations of the same function are available, SQLite
38373902
** will pick the one that involves the least amount of data conversion.
@@ -3839,17 +3904,25 @@
38393904
** encoding is used, then the fourth argument should be [SQLITE_ANY].
38403905
**
38413906
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
38423907
** function can gain access to this pointer using [sqlite3_user_data()].)^
38433908
**
3844
-** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
3909
+** ^The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
38453910
** pointers to C-language functions that implement the SQL function or
38463911
** aggregate. ^A scalar SQL function requires an implementation of the xFunc
3847
-** callback only; NULL pointers should be passed as the xStep and xFinal
3912
+** callback only; NULL pointers must be passed as the xStep and xFinal
38483913
** parameters. ^An aggregate SQL function requires an implementation of xStep
3849
-** and xFinal and NULL should be passed for xFunc. ^To delete an existing
3850
-** SQL function or aggregate, pass NULL for all three function callbacks.
3914
+** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
3915
+** SQL function or aggregate, pass NULL poiners for all three function
3916
+** callbacks.
3917
+**
3918
+** ^If the tenth parameter to sqlite3_create_function_v2() is not NULL,
3919
+** then it is invoked when the function is deleted, either by being
3920
+** overloaded or when the database connection closes.
3921
+** ^When the destructure callback of the tenth parameter is invoked, it
3922
+** is passed a single argument which is a copy of the pointer which was
3923
+** the fifth parameter to sqlite3_create_function_v2().
38513924
**
38523925
** ^It is permitted to register multiple implementations of the same
38533926
** functions with the same name but with either differing numbers of
38543927
** arguments or differing preferred text encodings. ^SQLite will use
38553928
** the implementation that most closely matches the way in which the
@@ -3861,15 +3934,10 @@
38613934
** ^A function where the encoding difference is between UTF16le and UTF16be
38623935
** is a closer match than a function where the encoding difference is
38633936
** between UTF8 and UTF16.
38643937
**
38653938
** ^Built-in functions may be overloaded by new application-defined functions.
3866
-** ^The first application-defined function with a given name overrides all
3867
-** built-in functions in the same [database connection] with the same name.
3868
-** ^Subsequent application-defined functions of the same name only override
3869
-** prior application-defined functions that are an exact match for the
3870
-** number of parameters and preferred encoding.
38713939
**
38723940
** ^An application-defined function is permitted to call other
38733941
** SQLite interfaces. However, such calls must not
38743942
** close the database connection nor finalize or reset the prepared
38753943
** statement in which the function is running.
@@ -3891,10 +3959,21 @@
38913959
int eTextRep,
38923960
void *pApp,
38933961
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
38943962
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
38953963
void (*xFinal)(sqlite3_context*)
3964
+);
3965
+SQLITE_API int sqlite3_create_function_v2(
3966
+ sqlite3 *db,
3967
+ const char *zFunctionName,
3968
+ int nArg,
3969
+ int eTextRep,
3970
+ void *pApp,
3971
+ void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
3972
+ void (*xStep)(sqlite3_context*,int,sqlite3_value**),
3973
+ void (*xFinal)(sqlite3_context*),
3974
+ void(*xDestroy)(void*)
38963975
);
38973976
38983977
/*
38993978
** CAPI3REF: Text Encodings
39003979
**
@@ -4238,73 +4317,97 @@
42384317
SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
42394318
42404319
/*
42414320
** CAPI3REF: Define New Collating Sequences
42424321
**
4243
-** These functions are used to add new collation sequences to the
4244
-** [database connection] specified as the first argument.
4322
+** ^These functions add, remove, or modify a [collation] associated
4323
+** with the [database connection] specified as the first argument.
42454324
**
4246
-** ^The name of the new collation sequence is specified as a UTF-8 string
4325
+** ^The name of the collation is a UTF-8 string
42474326
** for sqlite3_create_collation() and sqlite3_create_collation_v2()
4248
-** and a UTF-16 string for sqlite3_create_collation16(). ^In all cases
4249
-** the name is passed as the second function argument.
4250
-**
4251
-** ^The third argument may be one of the constants [SQLITE_UTF8],
4252
-** [SQLITE_UTF16LE], or [SQLITE_UTF16BE], indicating that the user-supplied
4253
-** routine expects to be passed pointers to strings encoded using UTF-8,
4254
-** UTF-16 little-endian, or UTF-16 big-endian, respectively. ^The
4255
-** third argument might also be [SQLITE_UTF16] to indicate that the routine
4256
-** expects pointers to be UTF-16 strings in the native byte order, or the
4257
-** argument can be [SQLITE_UTF16_ALIGNED] if the
4258
-** the routine expects pointers to 16-bit word aligned strings
4259
-** of UTF-16 in the native byte order.
4260
-**
4261
-** A pointer to the user supplied routine must be passed as the fifth
4262
-** argument. ^If it is NULL, this is the same as deleting the collation
4263
-** sequence (so that SQLite cannot call it any more).
4264
-** ^Each time the application supplied function is invoked, it is passed
4265
-** as its first parameter a copy of the void* passed as the fourth argument
4266
-** to sqlite3_create_collation() or sqlite3_create_collation16().
4267
-**
4268
-** ^The remaining arguments to the application-supplied routine are two strings,
4269
-** each represented by a (length, data) pair and encoded in the encoding
4270
-** that was passed as the third argument when the collation sequence was
4271
-** registered. The application defined collation routine should
4272
-** return negative, zero or positive if the first string is less than,
4273
-** equal to, or greater than the second string. i.e. (STRING1 - STRING2).
4327
+** and a UTF-16 string in native byte order for sqlite3_create_collation16().
4328
+** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
4329
+** considered to be the same name.
4330
+**
4331
+** ^(The third argument (eTextRep) must be one of the constants:
4332
+** <ul>
4333
+** <li> [SQLITE_UTF8],
4334
+** <li> [SQLITE_UTF16LE],
4335
+** <li> [SQLITE_UTF16BE],
4336
+** <li> [SQLITE_UTF16], or
4337
+** <li> [SQLITE_UTF16_ALIGNED].
4338
+** </ul>)^
4339
+** ^The eTextRep argument determines the encoding of strings passed
4340
+** to the collating function callback, xCallback.
4341
+** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
4342
+** force strings to be UTF16 with native byte order.
4343
+** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
4344
+** on an even byte address.
4345
+**
4346
+** ^The fourth argument, pArg, is a application data pointer that is passed
4347
+** through as the first argument to the collating function callback.
4348
+**
4349
+** ^The fifth argument, xCallback, is a pointer to the collating function.
4350
+** ^Multiple collating functions can be registered using the same name but
4351
+** with different eTextRep parameters and SQLite will use whichever
4352
+** function requires the least amount of data transformation.
4353
+** ^If the xCallback argument is NULL then the collating function is
4354
+** deleted. ^When all collating functions having the same name are deleted,
4355
+** that collation is no longer usable.
4356
+**
4357
+** ^The collating function callback is invoked with a copy of the pArg
4358
+** application data pointer and with two strings in the encoding specified
4359
+** by the eTextRep argument. The collating function must return an
4360
+** integer that is negative, zero, or positive
4361
+** if the first string is less than, equal to, or greater than the second,
4362
+** respectively. A collating function must alway return the same answer
4363
+** given the same inputs. If two or more collating functions are registered
4364
+** to the same collation name (using different eTextRep values) then all
4365
+** must give an equivalent answer when invoked with equivalent strings.
4366
+** The collating function must obey the following properties for all
4367
+** strings A, B, and C:
4368
+**
4369
+** <ol>
4370
+** <li> If A==B then B==A.
4371
+** <li> If A==B and B==C then A==C.
4372
+** <li> If A&lt;B THEN B&gt;A.
4373
+** <li> If A&lt;B and B&lt;C then A&lt;C.
4374
+** </ol>
4375
+**
4376
+** If a collating function fails any of the above constraints and that
4377
+** collating function is registered and used, then the behavior of SQLite
4378
+** is undefined.
42744379
**
42754380
** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
4276
-** except that it takes an extra argument which is a destructor for
4277
-** the collation. ^The destructor is called when the collation is
4278
-** destroyed and is passed a copy of the fourth parameter void* pointer
4279
-** of the sqlite3_create_collation_v2().
4280
-** ^Collations are destroyed when they are overridden by later calls to the
4281
-** collation creation functions or when the [database connection] is closed
4282
-** using [sqlite3_close()].
4381
+** with the addition that the xDestroy callback is invoked on pArg when
4382
+** the collating function is deleted.
4383
+** ^Collating functions are deleted when they are overridden by later
4384
+** calls to the collation creation functions or when the
4385
+** [database connection] is closed using [sqlite3_close()].
42834386
**
42844387
** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
42854388
*/
42864389
SQLITE_API int sqlite3_create_collation(
42874390
sqlite3*,
42884391
const char *zName,
42894392
int eTextRep,
4290
- void*,
4393
+ void *pArg,
42914394
int(*xCompare)(void*,int,const void*,int,const void*)
42924395
);
42934396
SQLITE_API int sqlite3_create_collation_v2(
42944397
sqlite3*,
42954398
const char *zName,
42964399
int eTextRep,
4297
- void*,
4400
+ void *pArg,
42984401
int(*xCompare)(void*,int,const void*,int,const void*),
42994402
void(*xDestroy)(void*)
43004403
);
43014404
SQLITE_API int sqlite3_create_collation16(
43024405
sqlite3*,
43034406
const void *zName,
43044407
int eTextRep,
4305
- void*,
4408
+ void *pArg,
43064409
int(*xCompare)(void*,int,const void*,int,const void*)
43074410
);
43084411
43094412
/*
43104413
** CAPI3REF: Collation Needed Callbacks
@@ -4389,20 +4492,23 @@
43894492
#endif
43904493
43914494
/*
43924495
** CAPI3REF: Suspend Execution For A Short Time
43934496
**
4394
-** ^The sqlite3_sleep() function causes the current thread to suspend execution
4497
+** The sqlite3_sleep() function causes the current thread to suspend execution
43954498
** for at least a number of milliseconds specified in its parameter.
43964499
**
4397
-** ^If the operating system does not support sleep requests with
4500
+** If the operating system does not support sleep requests with
43984501
** millisecond time resolution, then the time will be rounded up to
4399
-** the nearest second. ^The number of milliseconds of sleep actually
4502
+** the nearest second. The number of milliseconds of sleep actually
44004503
** requested from the operating system is returned.
44014504
**
44024505
** ^SQLite implements this interface by calling the xSleep()
4403
-** method of the default [sqlite3_vfs] object.
4506
+** method of the default [sqlite3_vfs] object. If the xSleep() method
4507
+** of the default VFS is not implemented correctly, or not implemented at
4508
+** all, then the behavior of sqlite3_sleep() may deviate from the description
4509
+** in the previous paragraphs.
44044510
*/
44054511
SQLITE_API int sqlite3_sleep(int);
44064512
44074513
/*
44084514
** CAPI3REF: Name Of The Folder Holding Temporary Files
@@ -4620,44 +4726,77 @@
46204726
** of heap memory by deallocating non-essential memory allocations
46214727
** held by the database library. Memory used to cache database
46224728
** pages to improve performance is an example of non-essential memory.
46234729
** ^sqlite3_release_memory() returns the number of bytes actually freed,
46244730
** which might be more or less than the amount requested.
4731
+** ^The sqlite3_release_memory() routine is a no-op returning zero
4732
+** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
46254733
*/
46264734
SQLITE_API int sqlite3_release_memory(int);
46274735
46284736
/*
46294737
** CAPI3REF: Impose A Limit On Heap Size
46304738
**
4631
-** ^The sqlite3_soft_heap_limit() interface places a "soft" limit
4632
-** on the amount of heap memory that may be allocated by SQLite.
4633
-** ^If an internal allocation is requested that would exceed the
4634
-** soft heap limit, [sqlite3_release_memory()] is invoked one or
4635
-** more times to free up some space before the allocation is performed.
4636
-**
4637
-** ^The limit is called "soft" because if [sqlite3_release_memory()]
4638
-** cannot free sufficient memory to prevent the limit from being exceeded,
4639
-** the memory is allocated anyway and the current operation proceeds.
4640
-**
4641
-** ^A negative or zero value for N means that there is no soft heap limit and
4642
-** [sqlite3_release_memory()] will only be called when memory is exhausted.
4643
-** ^The default value for the soft heap limit is zero.
4644
-**
4645
-** ^(SQLite makes a best effort to honor the soft heap limit.
4646
-** But if the soft heap limit cannot be honored, execution will
4647
-** continue without error or notification.)^ This is why the limit is
4648
-** called a "soft" limit. It is advisory only.
4649
-**
4650
-** Prior to SQLite version 3.5.0, this routine only constrained the memory
4651
-** allocated by a single thread - the same thread in which this routine
4652
-** runs. Beginning with SQLite version 3.5.0, the soft heap limit is
4653
-** applied to all threads. The value specified for the soft heap limit
4654
-** is an upper bound on the total memory allocation for all threads. In
4655
-** version 3.5.0 there is no mechanism for limiting the heap usage for
4656
-** individual threads.
4657
-*/
4658
-SQLITE_API void sqlite3_soft_heap_limit(int);
4739
+** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
4740
+** soft limit on the amount of heap memory that may be allocated by SQLite.
4741
+** ^SQLite strives to keep heap memory utilization below the soft heap
4742
+** limit by reducing the number of pages held in the page cache
4743
+** as heap memory usages approaches the limit.
4744
+** ^The soft heap limit is "soft" because even though SQLite strives to stay
4745
+** below the limit, it will exceed the limit rather than generate
4746
+** an [SQLITE_NOMEM] error. In other words, the soft heap limit
4747
+** is advisory only.
4748
+**
4749
+** ^The return value from sqlite3_soft_heap_limit64() is the size of
4750
+** the soft heap limit prior to the call. ^If the argument N is negative
4751
+** then no change is made to the soft heap limit. Hence, the current
4752
+** size of the soft heap limit can be determined by invoking
4753
+** sqlite3_soft_heap_limit64() with a negative argument.
4754
+**
4755
+** ^If the argument N is zero then the soft heap limit is disabled.
4756
+**
4757
+** ^(The soft heap limit is not enforced in the current implementation
4758
+** if one or more of following conditions are true:
4759
+**
4760
+** <ul>
4761
+** <li> The soft heap limit is set to zero.
4762
+** <li> Memory accounting is disabled using a combination of the
4763
+** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
4764
+** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
4765
+** <li> An alternative page cache implementation is specifed using
4766
+** [sqlite3_config]([SQLITE_CONFIG_PCACHE],...).
4767
+** <li> The page cache allocates from its own memory pool supplied
4768
+** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
4769
+** from the heap.
4770
+** </ul>)^
4771
+**
4772
+** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
4773
+** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
4774
+** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
4775
+** the soft heap limit is enforced on every memory allocation. Without
4776
+** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
4777
+** when memory is allocated by the page cache. Testing suggests that because
4778
+** the page cache is the predominate memory user in SQLite, most
4779
+** applications will achieve adequate soft heap limit enforcement without
4780
+** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
4781
+**
4782
+** The circumstances under which SQLite will enforce the soft heap limit may
4783
+** changes in future releases of SQLite.
4784
+*/
4785
+SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
4786
+
4787
+/*
4788
+** CAPI3REF: Deprecated Soft Heap Limit Interface
4789
+** DEPRECATED
4790
+**
4791
+** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
4792
+** interface. This routine is provided for historical compatibility
4793
+** only. All new applications should use the
4794
+** [sqlite3_soft_heap_limit64()] interface rather than this one.
4795
+*/
4796
+SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);
4797
+
46594798
46604799
/*
46614800
** CAPI3REF: Extract Metadata About A Column Of A Table
46624801
**
46634802
** ^This routine returns metadata about a specific column of a specific
@@ -4777,38 +4916,51 @@
47774916
** it back off again.
47784917
*/
47794918
SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
47804919
47814920
/*
4782
-** CAPI3REF: Automatically Load An Extensions
4783
-**
4784
-** ^This API can be invoked at program startup in order to register
4785
-** one or more statically linked extensions that will be available
4786
-** to all new [database connections].
4787
-**
4788
-** ^(This routine stores a pointer to the extension entry point
4789
-** in an array that is obtained from [sqlite3_malloc()]. That memory
4790
-** is deallocated by [sqlite3_reset_auto_extension()].)^
4791
-**
4792
-** ^This function registers an extension entry point that is
4793
-** automatically invoked whenever a new [database connection]
4794
-** is opened using [sqlite3_open()], [sqlite3_open16()],
4795
-** or [sqlite3_open_v2()].
4796
-** ^Duplicate extensions are detected so calling this routine
4797
-** multiple times with the same extension is harmless.
4798
-** ^Automatic extensions apply across all threads.
4921
+** CAPI3REF: Automatically Load Statically Linked Extensions
4922
+**
4923
+** ^This interface causes the xEntryPoint() function to be invoked for
4924
+** each new [database connection] that is created. The idea here is that
4925
+** xEntryPoint() is the entry point for a statically linked SQLite extension
4926
+** that is to be automatically loaded into all new database connections.
4927
+**
4928
+** ^(Even though the function prototype shows that xEntryPoint() takes
4929
+** no arguments and returns void, SQLite invokes xEntryPoint() with three
4930
+** arguments and expects and integer result as if the signature of the
4931
+** entry point where as follows:
4932
+**
4933
+** <blockquote><pre>
4934
+** &nbsp; int xEntryPoint(
4935
+** &nbsp; sqlite3 *db,
4936
+** &nbsp; const char **pzErrMsg,
4937
+** &nbsp; const struct sqlite3_api_routines *pThunk
4938
+** &nbsp; );
4939
+** </pre></blockquote>)^
4940
+**
4941
+** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
4942
+** point to an appropriate error message (obtained from [sqlite3_mprintf()])
4943
+** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg
4944
+** is NULL before calling the xEntryPoint(). ^SQLite will invoke
4945
+** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any
4946
+** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
4947
+** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
4948
+**
4949
+** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
4950
+** on the list of automatic extensions is a harmless no-op. ^No entry point
4951
+** will be called more than once for each database connection that is opened.
4952
+**
4953
+** See also: [sqlite3_reset_auto_extension()].
47994954
*/
48004955
SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
48014956
48024957
/*
48034958
** CAPI3REF: Reset Automatic Extension Loading
48044959
**
4805
-** ^(This function disables all previously registered automatic
4806
-** extensions. It undoes the effect of all prior
4807
-** [sqlite3_auto_extension()] calls.)^
4808
-**
4809
-** ^This function disables automatic extensions in all threads.
4960
+** ^This interface disables all automatic extensions previously
4961
+** registered using [sqlite3_auto_extension()].
48104962
*/
48114963
SQLITE_API void sqlite3_reset_auto_extension(void);
48124964
48134965
/*
48144966
** The interface to the virtual-table mechanism is currently considered
@@ -5443,11 +5595,11 @@
54435595
** output variable when querying the system for the current mutex
54445596
** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
54455597
**
54465598
** ^The xMutexInit method defined by this structure is invoked as
54475599
** part of system initialization by the sqlite3_initialize() function.
5448
-** ^The xMutexInit routine is calle by SQLite exactly once for each
5600
+** ^The xMutexInit routine is called by SQLite exactly once for each
54495601
** effective call to [sqlite3_initialize()].
54505602
**
54515603
** ^The xMutexEnd method defined by this structure is invoked as
54525604
** part of system shutdown by the sqlite3_shutdown() function. The
54535605
** implementation of this method is expected to release all outstanding
@@ -5640,11 +5792,12 @@
56405792
#define SQLITE_TESTCTRL_ALWAYS 13
56415793
#define SQLITE_TESTCTRL_RESERVE 14
56425794
#define SQLITE_TESTCTRL_OPTIMIZATIONS 15
56435795
#define SQLITE_TESTCTRL_ISKEYWORD 16
56445796
#define SQLITE_TESTCTRL_PGHDRSZ 17
5645
-#define SQLITE_TESTCTRL_LAST 17
5797
+#define SQLITE_TESTCTRL_SCRATCHMALLOC 18
5798
+#define SQLITE_TESTCTRL_LAST 18
56465799
56475800
/*
56485801
** CAPI3REF: SQLite Runtime Status
56495802
**
56505803
** ^This interface is used to retrieve runtime status information
@@ -5659,11 +5812,11 @@
56595812
** value. For those parameters
56605813
** nothing is written into *pHighwater and the resetFlag is ignored.)^
56615814
** ^(Other parameters record only the highwater mark and not the current
56625815
** value. For these latter parameters nothing is written into *pCurrent.)^
56635816
**
5664
-** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
5817
+** ^The sqlite3_status() routine returns SQLITE_OK on success and a
56655818
** non-zero [error code] on failure.
56665819
**
56675820
** This routine is threadsafe but is not atomic. This routine can be
56685821
** called while other threads are running the same or different SQLite
56695822
** interfaces. However the values returned in *pCurrent and
@@ -5709,11 +5862,11 @@
57095862
** [SQLITE_CONFIG_PAGECACHE]. The
57105863
** value returned is in pages, not in bytes.</dd>)^
57115864
**
57125865
** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
57135866
** <dd>This parameter returns the number of bytes of page cache
5714
-** allocation which could not be statisfied by the [SQLITE_CONFIG_PAGECACHE]
5867
+** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
57155868
** buffer and where forced to overflow to [sqlite3_malloc()]. The
57165869
** returned value includes allocations that overflowed because they
57175870
** where too large (they were larger than the "sz" parameter to
57185871
** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
57195872
** no space was left in the page cache.</dd>)^
@@ -5732,11 +5885,11 @@
57325885
** outstanding at time, this parameter also reports the number of threads
57335886
** using scratch memory at the same time.</dd>)^
57345887
**
57355888
** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
57365889
** <dd>This parameter returns the number of bytes of scratch memory
5737
-** allocation which could not be statisfied by the [SQLITE_CONFIG_SCRATCH]
5890
+** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
57385891
** buffer and where forced to overflow to [sqlite3_malloc()]. The values
57395892
** returned include overflows because the requested allocation was too
57405893
** larger (that is, because the requested allocation was larger than the
57415894
** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
57425895
** slots were available.
@@ -5780,10 +5933,13 @@
57805933
**
57815934
** ^The current value of the requested parameter is written into *pCur
57825935
** and the highest instantaneous value is written into *pHiwtr. ^If
57835936
** the resetFlg is true, then the highest instantaneous value is
57845937
** reset back down to the current value.
5938
+**
5939
+** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
5940
+** non-zero [error code] on failure.
57855941
**
57865942
** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
57875943
*/
57885944
SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
57895945
@@ -5907,122 +6063,134 @@
59076063
** CAPI3REF: Application Defined Page Cache.
59086064
** KEYWORDS: {page cache}
59096065
**
59106066
** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
59116067
** register an alternative page cache implementation by passing in an
5912
-** instance of the sqlite3_pcache_methods structure.)^ The majority of the
5913
-** heap memory used by SQLite is used by the page cache to cache data read
5914
-** from, or ready to be written to, the database file. By implementing a
5915
-** custom page cache using this API, an application can control more
5916
-** precisely the amount of memory consumed by SQLite, the way in which
6068
+** instance of the sqlite3_pcache_methods structure.)^
6069
+** In many applications, most of the heap memory allocated by
6070
+** SQLite is used for the page cache.
6071
+** By implementing a
6072
+** custom page cache using this API, an application can better control
6073
+** the amount of memory consumed by SQLite, the way in which
59176074
** that memory is allocated and released, and the policies used to
59186075
** determine exactly which parts of a database file are cached and for
59196076
** how long.
59206077
**
6078
+** The alternative page cache mechanism is an
6079
+** extreme measure that is only needed by the most demanding applications.
6080
+** The built-in page cache is recommended for most uses.
6081
+**
59216082
** ^(The contents of the sqlite3_pcache_methods structure are copied to an
59226083
** internal buffer by SQLite within the call to [sqlite3_config]. Hence
59236084
** the application may discard the parameter after the call to
59246085
** [sqlite3_config()] returns.)^
59256086
**
5926
-** ^The xInit() method is called once for each call to [sqlite3_initialize()]
6087
+** ^(The xInit() method is called once for each effective
6088
+** call to [sqlite3_initialize()])^
59276089
** (usually only once during the lifetime of the process). ^(The xInit()
59286090
** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
5929
-** ^The xInit() method can set up up global structures and/or any mutexes
6091
+** The intent of the xInit() method is to set up global data structures
59306092
** required by the custom page cache implementation.
6093
+** ^(If the xInit() method is NULL, then the
6094
+** built-in default page cache is used instead of the application defined
6095
+** page cache.)^
59316096
**
5932
-** ^The xShutdown() method is called from within [sqlite3_shutdown()],
5933
-** if the application invokes this API. It can be used to clean up
6097
+** ^The xShutdown() method is called by [sqlite3_shutdown()].
6098
+** It can be used to clean up
59346099
** any outstanding resources before process shutdown, if required.
6100
+** ^The xShutdown() method may be NULL.
59356101
**
5936
-** ^SQLite holds a [SQLITE_MUTEX_RECURSIVE] mutex when it invokes
5937
-** the xInit method, so the xInit method need not be threadsafe. ^The
6102
+** ^SQLite automatically serializes calls to the xInit method,
6103
+** so the xInit method need not be threadsafe. ^The
59386104
** xShutdown method is only called from [sqlite3_shutdown()] so it does
59396105
** not need to be threadsafe either. All other methods must be threadsafe
59406106
** in multithreaded applications.
59416107
**
59426108
** ^SQLite will never invoke xInit() more than once without an intervening
59436109
** call to xShutdown().
59446110
**
5945
-** ^The xCreate() method is used to construct a new cache instance. SQLite
5946
-** will typically create one cache instance for each open database file,
6111
+** ^SQLite invokes the xCreate() method to construct a new cache instance.
6112
+** SQLite will typically create one cache instance for each open database file,
59476113
** though this is not guaranteed. ^The
59486114
** first parameter, szPage, is the size in bytes of the pages that must
59496115
** be allocated by the cache. ^szPage will not be a power of two. ^szPage
59506116
** will the page size of the database file that is to be cached plus an
5951
-** increment (here called "R") of about 100 or 200. ^SQLite will use the
6117
+** increment (here called "R") of about 100 or 200. SQLite will use the
59526118
** extra R bytes on each page to store metadata about the underlying
59536119
** database page on disk. The value of R depends
59546120
** on the SQLite version, the target platform, and how SQLite was compiled.
59556121
** ^R is constant for a particular build of SQLite. ^The second argument to
59566122
** xCreate(), bPurgeable, is true if the cache being created will
59576123
** be used to cache database pages of a file stored on disk, or
5958
-** false if it is used for an in-memory database. ^The cache implementation
6124
+** false if it is used for an in-memory database. The cache implementation
59596125
** does not have to do anything special based with the value of bPurgeable;
59606126
** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
59616127
** never invoke xUnpin() except to deliberately delete a page.
5962
-** ^In other words, a cache created with bPurgeable set to false will
6128
+** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
6129
+** false will always have the "discard" flag set to true.
6130
+** ^Hence, a cache created with bPurgeable false will
59636131
** never contain any unpinned pages.
59646132
**
59656133
** ^(The xCachesize() method may be called at any time by SQLite to set the
59666134
** suggested maximum cache-size (number of pages stored by) the cache
59676135
** instance passed as the first argument. This is the value configured using
5968
-** the SQLite "[PRAGMA cache_size]" command.)^ ^As with the bPurgeable
6136
+** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
59696137
** parameter, the implementation is not required to do anything with this
59706138
** value; it is advisory only.
59716139
**
5972
-** ^The xPagecount() method should return the number of pages currently
5973
-** stored in the cache.
6140
+** The xPagecount() method must return the number of pages currently
6141
+** stored in the cache, both pinned and unpinned.
59746142
**
5975
-** ^The xFetch() method is used to fetch a page and return a pointer to it.
5976
-** ^A 'page', in this context, is a buffer of szPage bytes aligned at an
5977
-** 8-byte boundary. ^The page to be fetched is determined by the key. ^The
5978
-** mimimum key value is 1. After it has been retrieved using xFetch, the page
6143
+** The xFetch() method locates a page in the cache and returns a pointer to
6144
+** the page, or a NULL pointer.
6145
+** A "page", in this context, means a buffer of szPage bytes aligned at an
6146
+** 8-byte boundary. The page to be fetched is determined by the key. ^The
6147
+** mimimum key value is 1. After it has been retrieved using xFetch, the page
59796148
** is considered to be "pinned".
59806149
**
5981
-** ^If the requested page is already in the page cache, then the page cache
6150
+** If the requested page is already in the page cache, then the page cache
59826151
** implementation must return a pointer to the page buffer with its content
5983
-** intact. ^(If the requested page is not already in the cache, then the
5984
-** behavior of the cache implementation is determined by the value of the
5985
-** createFlag parameter passed to xFetch, according to the following table:
6152
+** intact. If the requested page is not already in the cache, then the
6153
+** behavior of the cache implementation should use the value of the createFlag
6154
+** parameter to help it determined what action to take:
59866155
**
59876156
** <table border=1 width=85% align=center>
59886157
** <tr><th> createFlag <th> Behaviour when page is not already in cache
59896158
** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
59906159
** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
59916160
** Otherwise return NULL.
59926161
** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
59936162
** NULL if allocating a new page is effectively impossible.
5994
-** </table>)^
6163
+** </table>
59956164
**
5996
-** SQLite will normally invoke xFetch() with a createFlag of 0 or 1. If
5997
-** a call to xFetch() with createFlag==1 returns NULL, then SQLite will
6165
+** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
6166
+** will only use a createFlag of 2 after a prior call with a createFlag of 1
6167
+** failed.)^ In between the to xFetch() calls, SQLite may
59986168
** attempt to unpin one or more cache pages by spilling the content of
5999
-** pinned pages to disk and synching the operating system disk cache. After
6000
-** attempting to unpin pages, the xFetch() method will be invoked again with
6001
-** a createFlag of 2.
6169
+** pinned pages to disk and synching the operating system disk cache.
60026170
**
60036171
** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
6004
-** as its second argument. ^(If the third parameter, discard, is non-zero,
6005
-** then the page should be evicted from the cache. In this case SQLite
6006
-** assumes that the next time the page is retrieved from the cache using
6007
-** the xFetch() method, it will be zeroed.)^ ^If the discard parameter is
6008
-** zero, then the page is considered to be unpinned. ^The cache implementation
6172
+** as its second argument. If the third parameter, discard, is non-zero,
6173
+** then the page must be evicted from the cache.
6174
+** ^If the discard parameter is
6175
+** zero, then the page may be discarded or retained at the discretion of
6176
+** page cache implementation. ^The page cache implementation
60096177
** may choose to evict unpinned pages at any time.
60106178
**
6011
-** ^(The cache is not required to perform any reference counting. A single
6179
+** The cache must not perform any reference counting. A single
60126180
** call to xUnpin() unpins the page regardless of the number of prior calls
6013
-** to xFetch().)^
6181
+** to xFetch().
60146182
**
6015
-** ^The xRekey() method is used to change the key value associated with the
6016
-** page passed as the second argument from oldKey to newKey. ^If the cache
6017
-** previously contains an entry associated with newKey, it should be
6183
+** The xRekey() method is used to change the key value associated with the
6184
+** page passed as the second argument. If the cache
6185
+** previously contains an entry associated with newKey, it must be
60186186
** discarded. ^Any prior cache entry associated with newKey is guaranteed not
60196187
** to be pinned.
60206188
**
6021
-** ^When SQLite calls the xTruncate() method, the cache must discard all
6189
+** When SQLite calls the xTruncate() method, the cache must discard all
60226190
** existing cache entries with page numbers (keys) greater than or equal
6023
-** to the value of the iLimit parameter passed to xTruncate(). ^If any
6191
+** to the value of the iLimit parameter passed to xTruncate(). If any
60246192
** of these pages are pinned, they are implicitly unpinned, meaning that
60256193
** they can be safely discarded.
60266194
**
60276195
** ^The xDestroy() method is used to delete a cache allocated by xCreate().
60286196
** All resources associated with the specified cache should be freed. ^After
@@ -6496,10 +6664,66 @@
64966664
#if 0
64976665
} /* End of the 'extern "C"' block */
64986666
#endif
64996667
#endif
65006668
6669
+/*
6670
+** 2010 August 30
6671
+**
6672
+** The author disclaims copyright to this source code. In place of
6673
+** a legal notice, here is a blessing:
6674
+**
6675
+** May you do good and not evil.
6676
+** May you find forgiveness for yourself and forgive others.
6677
+** May you share freely, never taking more than you give.
6678
+**
6679
+*************************************************************************
6680
+*/
6681
+
6682
+#ifndef _SQLITE3RTREE_H_
6683
+#define _SQLITE3RTREE_H_
6684
+
6685
+
6686
+#if 0
6687
+extern "C" {
6688
+#endif
6689
+
6690
+typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
6691
+
6692
+/*
6693
+** Register a geometry callback named zGeom that can be used as part of an
6694
+** R-Tree geometry query as follows:
6695
+**
6696
+** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
6697
+*/
6698
+SQLITE_API int sqlite3_rtree_geometry_callback(
6699
+ sqlite3 *db,
6700
+ const char *zGeom,
6701
+ int (*xGeom)(sqlite3_rtree_geometry *, int nCoord, double *aCoord, int *pRes),
6702
+ void *pContext
6703
+);
6704
+
6705
+
6706
+/*
6707
+** A pointer to a structure of the following type is passed as the first
6708
+** argument to callbacks registered using rtree_geometry_callback().
6709
+*/
6710
+struct sqlite3_rtree_geometry {
6711
+ void *pContext; /* Copy of pContext passed to s_r_g_c() */
6712
+ int nParam; /* Size of array aParam[] */
6713
+ double *aParam; /* Parameters passed to SQL geom function */
6714
+ void *pUser; /* Callback implementation user data */
6715
+ void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */
6716
+};
6717
+
6718
+
6719
+#if 0
6720
+} /* end of the 'extern "C"' block */
6721
+#endif
6722
+
6723
+#endif /* ifndef _SQLITE3RTREE_H_ */
6724
+
65016725
65026726
/************** End of sqlite3.h *********************************************/
65036727
/************** Continuing where we left off in sqliteInt.h ******************/
65046728
/************** Include hash.h in the middle of sqliteInt.h ******************/
65056729
/************** Begin file hash.h ********************************************/
@@ -7066,10 +7290,11 @@
70667290
typedef struct Schema Schema;
70677291
typedef struct Expr Expr;
70687292
typedef struct ExprList ExprList;
70697293
typedef struct ExprSpan ExprSpan;
70707294
typedef struct FKey FKey;
7295
+typedef struct FuncDestructor FuncDestructor;
70717296
typedef struct FuncDef FuncDef;
70727297
typedef struct FuncDefHash FuncDefHash;
70737298
typedef struct IdList IdList;
70747299
typedef struct Index Index;
70757300
typedef struct IndexSample IndexSample;
@@ -7172,16 +7397,15 @@
71727397
** following values.
71737398
**
71747399
** NOTE: These values must match the corresponding PAGER_ values in
71757400
** pager.h.
71767401
*/
7177
-#define BTREE_OMIT_JOURNAL 1 /* Do not use journal. No argument */
7402
+#define BTREE_OMIT_JOURNAL 1 /* Do not create or use a rollback journal */
71787403
#define BTREE_NO_READLOCK 2 /* Omit readlocks on readonly files */
7179
-#define BTREE_MEMORY 4 /* In-memory DB. No argument */
7180
-#define BTREE_READONLY 8 /* Open the database in read-only mode */
7181
-#define BTREE_READWRITE 16 /* Open for both reading and writing */
7182
-#define BTREE_CREATE 32 /* Create the database if it does not exist */
7404
+#define BTREE_MEMORY 4 /* This is an in-memory DB */
7405
+#define BTREE_SINGLE 8 /* The file contains at most 1 b-tree */
7406
+#define BTREE_UNORDERED 16 /* Use of a hash implementation is OK */
71837407
71847408
SQLITE_PRIVATE int sqlite3BtreeClose(Btree*);
71857409
SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int);
71867410
SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
71877411
SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
@@ -7213,15 +7437,21 @@
72137437
SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *);
72147438
72157439
SQLITE_PRIVATE int sqlite3BtreeIncrVacuum(Btree *);
72167440
72177441
/* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
7218
-** of the following flags:
7442
+** of the flags shown below.
7443
+**
7444
+** Every SQLite table must have either BTREE_INTKEY or BTREE_BLOBKEY set.
7445
+** With BTREE_INTKEY, the table key is a 64-bit integer and arbitrary data
7446
+** is stored in the leaves. (BTREE_INTKEY is used for SQL tables.) With
7447
+** BTREE_BLOBKEY, the key is an arbitrary BLOB and no content is stored
7448
+** anywhere - the key is the content. (BTREE_BLOBKEY is used for SQL
7449
+** indices.)
72197450
*/
72207451
#define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */
7221
-#define BTREE_ZERODATA 2 /* Table has keys only - no data */
7222
-#define BTREE_LEAFDATA 4 /* Data stored in leaves only. Implies INTKEY */
7452
+#define BTREE_BLOBKEY 2 /* Table has keys only - no data */
72237453
72247454
SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*);
72257455
SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*);
72267456
SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree*, int);
72277457
@@ -7838,10 +8068,11 @@
78388068
**
78398069
** NOTE: These values must match the corresponding BTREE_ values in btree.h.
78408070
*/
78418071
#define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */
78428072
#define PAGER_NO_READLOCK 0x0002 /* Omit readlocks on readonly files */
8073
+#define PAGER_MEMORY 0x0004 /* In-memory database */
78438074
78448075
/*
78458076
** Valid values for the second argument to sqlite3PagerLockingMode().
78468077
*/
78478078
#define PAGER_LOCKINGMODE_QUERY -1
@@ -8472,12 +8703,12 @@
84728703
#define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8)
84738704
#define sqlite3_mutex_free(X)
84748705
#define sqlite3_mutex_enter(X)
84758706
#define sqlite3_mutex_try(X) SQLITE_OK
84768707
#define sqlite3_mutex_leave(X)
8477
-#define sqlite3_mutex_held(X) 1
8478
-#define sqlite3_mutex_notheld(X) 1
8708
+#define sqlite3_mutex_held(X) ((void)(X),1)
8709
+#define sqlite3_mutex_notheld(X) ((void)(X),1)
84798710
#define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8)
84808711
#define sqlite3MutexInit() SQLITE_OK
84818712
#define sqlite3MutexEnd()
84828713
#endif /* defined(SQLITE_MUTEX_OMIT) */
84838714
@@ -8795,10 +9026,31 @@
87959026
void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
87969027
void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
87979028
void (*xFinalize)(sqlite3_context*); /* Aggregate finalizer */
87989029
char *zName; /* SQL name of the function. */
87999030
FuncDef *pHash; /* Next with a different name but the same hash */
9031
+ FuncDestructor *pDestructor; /* Reference counted destructor function */
9032
+};
9033
+
9034
+/*
9035
+** This structure encapsulates a user-function destructor callback (as
9036
+** configured using create_function_v2()) and a reference counter. When
9037
+** create_function_v2() is called to create a function with a destructor,
9038
+** a single object of this type is allocated. FuncDestructor.nRef is set to
9039
+** the number of FuncDef objects created (either 1 or 3, depending on whether
9040
+** or not the specified encoding is SQLITE_ANY). The FuncDef.pDestructor
9041
+** member of each of the new FuncDef objects is set to point to the allocated
9042
+** FuncDestructor.
9043
+**
9044
+** Thereafter, when one of the FuncDef objects is deleted, the reference
9045
+** count on this object is decremented. When it reaches 0, the destructor
9046
+** is invoked and the FuncDestructor structure freed.
9047
+*/
9048
+struct FuncDestructor {
9049
+ int nRef;
9050
+ void (*xDestroy)(void *);
9051
+ void *pUserData;
88009052
};
88019053
88029054
/*
88039055
** Possible values for FuncDef.flags
88049056
*/
@@ -8835,19 +9087,19 @@
88359087
** FuncDef.flags variable is set to the value passed as the flags
88369088
** parameter.
88379089
*/
88389090
#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
88399091
{nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
8840
- SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0}
9092
+ SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
88419093
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
88429094
{nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
8843
- pArg, 0, xFunc, 0, 0, #zName, 0}
9095
+ pArg, 0, xFunc, 0, 0, #zName, 0, 0}
88449096
#define LIKEFUNC(zName, nArg, arg, flags) \
8845
- {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0}
9097
+ {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
88469098
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
88479099
{nArg, SQLITE_UTF8, nc*SQLITE_FUNC_NEEDCOLL, \
8848
- SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0}
9100
+ SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
88499101
88509102
/*
88519103
** All current savepoints are stored in a linked list starting at
88529104
** sqlite3.pSavepoint. The first element in the list is the most recently
88539105
** opened savepoint. Savepoints are added to the list by the vdbe
@@ -9063,10 +9315,11 @@
90639315
int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
90649316
int nCol; /* Number of columns in this table */
90659317
Column *aCol; /* Information about each column */
90669318
Index *pIndex; /* List of SQL indexes on this table. */
90679319
int tnum; /* Root BTree node for this table (see note above) */
9320
+ unsigned nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
90689321
Select *pSelect; /* NULL for tables. Points to definition if a view. */
90699322
u16 nRef; /* Number of pointers to this Table */
90709323
u8 tabFlags; /* Mask of TF_* values */
90719324
u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
90729325
FKey *pFKey; /* Linked list of all foreign keys in this table */
@@ -10317,11 +10570,10 @@
1031710570
1031810571
/*
1031910572
** Internal function prototypes
1032010573
*/
1032110574
SQLITE_PRIVATE int sqlite3StrICmp(const char *, const char *);
10322
-SQLITE_PRIVATE int sqlite3IsNumber(const char*, int*, u8);
1032310575
SQLITE_PRIVATE int sqlite3Strlen30(const char*);
1032410576
#define sqlite3StrNICmp sqlite3_strnicmp
1032510577
1032610578
SQLITE_PRIVATE int sqlite3MallocInit(void);
1032710579
SQLITE_PRIVATE void sqlite3MallocEnd(void);
@@ -10341,11 +10593,11 @@
1034110593
SQLITE_PRIVATE void sqlite3ScratchFree(void*);
1034210594
SQLITE_PRIVATE void *sqlite3PageMalloc(int);
1034310595
SQLITE_PRIVATE void sqlite3PageFree(void*);
1034410596
SQLITE_PRIVATE void sqlite3MemSetDefault(void);
1034510597
SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
10346
-SQLITE_PRIVATE int sqlite3MemoryAlarm(void (*)(void*, sqlite3_int64, int), void*, sqlite3_int64);
10598
+SQLITE_PRIVATE int sqlite3HeapNearlyFull(void);
1034710599
1034810600
/*
1034910601
** On systems with ample stack space and that support alloca(), make
1035010602
** use of alloca() to obtain space for large automatic objects. By default,
1035110603
** obtain space from malloc().
@@ -10512,11 +10764,10 @@
1051210764
SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
1051310765
SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
1051410766
SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
1051510767
SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
1051610768
SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
10517
-SQLITE_PRIVATE void sqlite3ExprHardCopy(Parse*,int,int);
1051810769
SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
1051910770
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
1052010771
SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
1052110772
SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
1052210773
SQLITE_PRIVATE void sqlite3ExprCodeConstants(Parse*, Expr*);
@@ -10632,21 +10883,18 @@
1063210883
# define sqlite3AuthContextPush(a,b,c)
1063310884
# define sqlite3AuthContextPop(a) ((void)(a))
1063410885
#endif
1063510886
SQLITE_PRIVATE void sqlite3Attach(Parse*, Expr*, Expr*, Expr*);
1063610887
SQLITE_PRIVATE void sqlite3Detach(Parse*, Expr*);
10637
-SQLITE_PRIVATE int sqlite3BtreeFactory(sqlite3 *db, const char *zFilename,
10638
- int omitJournal, int nCache, int flags, Btree **ppBtree);
1063910888
SQLITE_PRIVATE int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*);
1064010889
SQLITE_PRIVATE int sqlite3FixSrcList(DbFixer*, SrcList*);
1064110890
SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
1064210891
SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
1064310892
SQLITE_PRIVATE int sqlite3FixExprList(DbFixer*, ExprList*);
1064410893
SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
10645
-SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*);
10894
+SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
1064610895
SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
10647
-SQLITE_PRIVATE int sqlite3FitsIn64Bits(const char *, int);
1064810896
SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar);
1064910897
SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte);
1065010898
SQLITE_PRIVATE int sqlite3Utf8Read(const u8*, const u8**);
1065110899
1065210900
/*
@@ -10688,11 +10936,11 @@
1068810936
SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
1068910937
SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *, Table *);
1069010938
SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
1069110939
SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
1069210940
SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
10693
-SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*);
10941
+SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
1069410942
SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
1069510943
SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
1069610944
SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
1069710945
SQLITE_PRIVATE const char *sqlite3ErrStr(int);
1069810946
SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -10759,11 +11007,13 @@
1075911007
SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
1076011008
SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
1076111009
SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
1076211010
SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
1076311011
void (*)(sqlite3_context*,int,sqlite3_value **),
10764
- void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*));
11012
+ void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*),
11013
+ FuncDestructor *pDestructor
11014
+);
1076511015
SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
1076611016
SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
1076711017
1076811018
SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
1076911019
SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
@@ -11679,10 +11929,11 @@
1167911929
Bool useRandomRowid; /* Generate new record numbers semi-randomly */
1168011930
Bool nullRow; /* True if pointing to a row with no data */
1168111931
Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
1168211932
Bool isTable; /* True if a table requiring integer keys */
1168311933
Bool isIndex; /* True if an index containing keys only - no data */
11934
+ Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */
1168411935
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
1168511936
Btree *pBt; /* Separate file holding temporary table */
1168611937
int pseudoTableReg; /* Register holding pseudotable content. */
1168711938
KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
1168811939
int nField; /* Number of fields in the header */
@@ -11773,10 +12024,14 @@
1177312024
char *z; /* String or BLOB value */
1177412025
int n; /* Number of characters in string value, excluding '\0' */
1177512026
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
1177612027
u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
1177712028
u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
12029
+#ifdef SQLITE_DEBUG
12030
+ Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
12031
+ void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
12032
+#endif
1177812033
void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
1177912034
char *zMalloc; /* Dynamic buffer allocated by sqlite3_malloc() */
1178012035
};
1178112036
1178212037
/* One or more of the following flags are set to indicate the validOK
@@ -11799,10 +12054,11 @@
1179912054
#define MEM_Int 0x0004 /* Value is an integer */
1180012055
#define MEM_Real 0x0008 /* Value is a real number */
1180112056
#define MEM_Blob 0x0010 /* Value is a BLOB */
1180212057
#define MEM_RowSet 0x0020 /* Value is a RowSet object */
1180312058
#define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
12059
+#define MEM_Invalid 0x0080 /* Value is undefined */
1180412060
#define MEM_TypeMask 0x00ff /* Mask of type bits */
1180512061
1180612062
/* Whenever Mem contains a valid string or blob representation, one of
1180712063
** the following flags must be set to determine the memory management
1180812064
** policy for Mem.z. The MEM_Term flag tells us whether or not the
@@ -11812,23 +12068,29 @@
1181212068
#define MEM_Dyn 0x0400 /* Need to call sqliteFree() on Mem.z */
1181312069
#define MEM_Static 0x0800 /* Mem.z points to a static string */
1181412070
#define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
1181512071
#define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
1181612072
#define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
11817
-
1181812073
#ifdef SQLITE_OMIT_INCRBLOB
1181912074
#undef MEM_Zero
1182012075
#define MEM_Zero 0x0000
1182112076
#endif
11822
-
1182312077
1182412078
/*
1182512079
** Clear any existing type flags from a Mem and replace them with f
1182612080
*/
1182712081
#define MemSetTypeFlag(p, f) \
1182812082
((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
1182912083
12084
+/*
12085
+** Return true if a memory cell is not marked as invalid. This macro
12086
+** is for use inside assert() statements only.
12087
+*/
12088
+#ifdef SQLITE_DEBUG
12089
+#define memIsValid(M) ((M)->flags & MEM_Invalid)==0
12090
+#endif
12091
+
1183012092
1183112093
/* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
1183212094
** additional information about auxiliary information bound to arguments
1183312095
** of the function. This is used to implement the sqlite3_get_auxdata()
1183412096
** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data
@@ -12012,10 +12274,14 @@
1201212274
SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
1201312275
SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
1201412276
SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
1201512277
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
1201612278
SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
12279
+
12280
+#ifdef SQLITE_DEBUG
12281
+SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe*,Mem*);
12282
+#endif
1201712283
1201812284
#ifndef SQLITE_OMIT_FOREIGN_KEY
1201912285
SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int);
1202012286
#else
1202112287
# define sqlite3VdbeCheckFk(p,i) 0
@@ -12369,16 +12635,10 @@
1236912635
end_getDigits:
1237012636
va_end(ap);
1237112637
return cnt;
1237212638
}
1237312639
12374
-/*
12375
-** Read text from z[] and convert into a floating point number. Return
12376
-** the number of digits converted.
12377
-*/
12378
-#define getValue sqlite3AtoF
12379
-
1238012640
/*
1238112641
** Parse a timezone extension on the end of a date-time.
1238212642
** The extension is of the form:
1238312643
**
1238412644
** (+/-)HH:MM
@@ -12576,21 +12836,19 @@
1257612836
static int parseDateOrTime(
1257712837
sqlite3_context *context,
1257812838
const char *zDate,
1257912839
DateTime *p
1258012840
){
12581
- int isRealNum; /* Return from sqlite3IsNumber(). Not used */
12841
+ double r;
1258212842
if( parseYyyyMmDd(zDate,p)==0 ){
1258312843
return 0;
1258412844
}else if( parseHhMmSs(zDate, p)==0 ){
1258512845
return 0;
1258612846
}else if( sqlite3StrICmp(zDate,"now")==0){
1258712847
setDateTimeToCurrent(context, p);
1258812848
return 0;
12589
- }else if( sqlite3IsNumber(zDate, &isRealNum, SQLITE_UTF8) ){
12590
- double r;
12591
- getValue(zDate, &r);
12849
+ }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
1259212850
p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
1259312851
p->validJD = 1;
1259412852
return 0;
1259512853
}
1259612854
return 1;
@@ -12807,12 +13065,13 @@
1280713065
**
1280813066
** Move the date to the same time on the next occurrence of
1280913067
** weekday N where 0==Sunday, 1==Monday, and so forth. If the
1281013068
** date is already on the appropriate weekday, this is a no-op.
1281113069
*/
12812
- if( strncmp(z, "weekday ", 8)==0 && getValue(&z[8],&r)>0
12813
- && (n=(int)r)==r && n>=0 && r<7 ){
13070
+ if( strncmp(z, "weekday ", 8)==0
13071
+ && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)
13072
+ && (n=(int)r)==r && n>=0 && r<7 ){
1281413073
sqlite3_int64 Z;
1281513074
computeYMD_HMS(p);
1281613075
p->validTZ = 0;
1281713076
p->validJD = 0;
1281813077
computeJD(p);
@@ -12863,12 +13122,15 @@
1286313122
case '6':
1286413123
case '7':
1286513124
case '8':
1286613125
case '9': {
1286713126
double rRounder;
12868
- n = getValue(z, &r);
12869
- assert( n>=1 );
13127
+ for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){}
13128
+ if( !sqlite3AtoF(z, &r, n, SQLITE_UTF8) ){
13129
+ rc = 1;
13130
+ break;
13131
+ }
1287013132
if( z[n]==':' ){
1287113133
/* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the
1287213134
** specified number of hours, minutes, seconds, and fractional seconds
1287313135
** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be
1287413136
** omitted.
@@ -13518,10 +13780,16 @@
1351813780
SQLITE_PRIVATE int sqlite3OsSleep(sqlite3_vfs *pVfs, int nMicro){
1351913781
return pVfs->xSleep(pVfs, nMicro);
1352013782
}
1352113783
SQLITE_PRIVATE int sqlite3OsCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *pTimeOut){
1352213784
int rc;
13785
+ /* IMPLEMENTATION-OF: R-49045-42493 SQLite will use the xCurrentTimeInt64()
13786
+ ** method to get the current date and time if that method is available
13787
+ ** (if iVersion is 2 or greater and the function pointer is not NULL) and
13788
+ ** will fall back to xCurrentTime() if xCurrentTimeInt64() is
13789
+ ** unavailable.
13790
+ */
1352313791
if( pVfs->iVersion>=2 && pVfs->xCurrentTimeInt64 ){
1352413792
rc = pVfs->xCurrentTimeInt64(pVfs, pTimeOut);
1352513793
}else{
1352613794
double r;
1352713795
rc = pVfs->xCurrentTime(pVfs, &r);
@@ -13901,11 +14169,11 @@
1390114169
** routines and redirected to xFree.
1390214170
*/
1390314171
static void *sqlite3MemRealloc(void *pPrior, int nByte){
1390414172
sqlite3_int64 *p = (sqlite3_int64*)pPrior;
1390514173
assert( pPrior!=0 && nByte>0 );
13906
- nByte = ROUND8(nByte);
14174
+ assert( nByte==ROUND8(nByte) ); /* EV: R-46199-30249 */
1390714175
p--;
1390814176
p = realloc(p, nByte+8 );
1390914177
if( p ){
1391014178
p[0] = nByte;
1391114179
p++;
@@ -14307,10 +14575,11 @@
1430714575
*/
1430814576
static void *sqlite3MemRealloc(void *pPrior, int nByte){
1430914577
struct MemBlockHdr *pOldHdr;
1431014578
void *pNew;
1431114579
assert( mem.disallow==0 );
14580
+ assert( (nByte & 7)==0 ); /* EV: R-46199-30249 */
1431214581
pOldHdr = sqlite3MemsysGetHeader(pPrior);
1431314582
pNew = sqlite3MemMalloc(nByte);
1431414583
if( pNew ){
1431514584
memcpy(pNew, pPrior, nByte<pOldHdr->iSize ? nByte : pOldHdr->iSize);
1431614585
if( nByte>pOldHdr->iSize ){
@@ -15576,11 +15845,11 @@
1557615845
*/
1557715846
static void *memsys5Realloc(void *pPrior, int nBytes){
1557815847
int nOld;
1557915848
void *p;
1558015849
assert( pPrior!=0 );
15581
- assert( (nBytes&(nBytes-1))==0 );
15850
+ assert( (nBytes&(nBytes-1))==0 ); /* EV: R-46199-30249 */
1558215851
assert( nBytes>=0 );
1558315852
if( nBytes==0 ){
1558415853
return 0;
1558515854
}
1558615855
nOld = memsys5Size(pPrior);
@@ -17100,10 +17369,70 @@
1710017369
*************************************************************************
1710117370
**
1710217371
** Memory allocation functions used throughout sqlite.
1710317372
*/
1710417373
17374
+/*
17375
+** Attempt to release up to n bytes of non-essential memory currently
17376
+** held by SQLite. An example of non-essential memory is memory used to
17377
+** cache database pages that are not currently in use.
17378
+*/
17379
+SQLITE_API int sqlite3_release_memory(int n){
17380
+#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
17381
+ return sqlite3PcacheReleaseMemory(n);
17382
+#else
17383
+ /* IMPLEMENTATION-OF: R-34391-24921 The sqlite3_release_memory() routine
17384
+ ** is a no-op returning zero if SQLite is not compiled with
17385
+ ** SQLITE_ENABLE_MEMORY_MANAGEMENT. */
17386
+ UNUSED_PARAMETER(n);
17387
+ return 0;
17388
+#endif
17389
+}
17390
+
17391
+/*
17392
+** An instance of the following object records the location of
17393
+** each unused scratch buffer.
17394
+*/
17395
+typedef struct ScratchFreeslot {
17396
+ struct ScratchFreeslot *pNext; /* Next unused scratch buffer */
17397
+} ScratchFreeslot;
17398
+
17399
+/*
17400
+** State information local to the memory allocation subsystem.
17401
+*/
17402
+static SQLITE_WSD struct Mem0Global {
17403
+ sqlite3_mutex *mutex; /* Mutex to serialize access */
17404
+
17405
+ /*
17406
+ ** The alarm callback and its arguments. The mem0.mutex lock will
17407
+ ** be held while the callback is running. Recursive calls into
17408
+ ** the memory subsystem are allowed, but no new callbacks will be
17409
+ ** issued.
17410
+ */
17411
+ sqlite3_int64 alarmThreshold;
17412
+ void (*alarmCallback)(void*, sqlite3_int64,int);
17413
+ void *alarmArg;
17414
+
17415
+ /*
17416
+ ** Pointers to the end of sqlite3GlobalConfig.pScratch memory
17417
+ ** (so that a range test can be used to determine if an allocation
17418
+ ** being freed came from pScratch) and a pointer to the list of
17419
+ ** unused scratch allocations.
17420
+ */
17421
+ void *pScratchEnd;
17422
+ ScratchFreeslot *pScratchFree;
17423
+ u32 nScratchFree;
17424
+
17425
+ /*
17426
+ ** True if heap is nearly "full" where "full" is defined by the
17427
+ ** sqlite3_soft_heap_limit() setting.
17428
+ */
17429
+ int nearlyFull;
17430
+} mem0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
17431
+
17432
+#define mem0 GLOBAL(struct Mem0Global, mem0)
17433
+
1710517434
/*
1710617435
** This routine runs when the memory allocator sees that the
1710717436
** total memory allocation is about to exceed the soft heap
1710817437
** limit.
1710917438
*/
@@ -17114,82 +17443,70 @@
1711417443
){
1711517444
UNUSED_PARAMETER2(NotUsed, NotUsed2);
1711617445
sqlite3_release_memory(allocSize);
1711717446
}
1711817447
17448
+/*
17449
+** Change the alarm callback
17450
+*/
17451
+static int sqlite3MemoryAlarm(
17452
+ void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
17453
+ void *pArg,
17454
+ sqlite3_int64 iThreshold
17455
+){
17456
+ int nUsed;
17457
+ sqlite3_mutex_enter(mem0.mutex);
17458
+ mem0.alarmCallback = xCallback;
17459
+ mem0.alarmArg = pArg;
17460
+ mem0.alarmThreshold = iThreshold;
17461
+ nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
17462
+ mem0.nearlyFull = (iThreshold>0 && iThreshold<=nUsed);
17463
+ sqlite3_mutex_leave(mem0.mutex);
17464
+ return SQLITE_OK;
17465
+}
17466
+
17467
+#ifndef SQLITE_OMIT_DEPRECATED
17468
+/*
17469
+** Deprecated external interface. Internal/core SQLite code
17470
+** should call sqlite3MemoryAlarm.
17471
+*/
17472
+SQLITE_API int sqlite3_memory_alarm(
17473
+ void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
17474
+ void *pArg,
17475
+ sqlite3_int64 iThreshold
17476
+){
17477
+ return sqlite3MemoryAlarm(xCallback, pArg, iThreshold);
17478
+}
17479
+#endif
17480
+
1711917481
/*
1712017482
** Set the soft heap-size limit for the library. Passing a zero or
1712117483
** negative value indicates no limit.
1712217484
*/
17123
-SQLITE_API void sqlite3_soft_heap_limit(int n){
17124
- sqlite3_uint64 iLimit;
17125
- int overage;
17126
- if( n<0 ){
17127
- iLimit = 0;
17128
- }else{
17129
- iLimit = n;
17130
- }
17485
+SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 n){
17486
+ sqlite3_int64 priorLimit;
17487
+ sqlite3_int64 excess;
1713117488
#ifndef SQLITE_OMIT_AUTOINIT
1713217489
sqlite3_initialize();
1713317490
#endif
17134
- if( iLimit>0 ){
17135
- sqlite3MemoryAlarm(softHeapLimitEnforcer, 0, iLimit);
17491
+ sqlite3_mutex_enter(mem0.mutex);
17492
+ priorLimit = mem0.alarmThreshold;
17493
+ sqlite3_mutex_leave(mem0.mutex);
17494
+ if( n<0 ) return priorLimit;
17495
+ if( n>0 ){
17496
+ sqlite3MemoryAlarm(softHeapLimitEnforcer, 0, n);
1713617497
}else{
1713717498
sqlite3MemoryAlarm(0, 0, 0);
1713817499
}
17139
- overage = (int)(sqlite3_memory_used() - (i64)n);
17140
- if( overage>0 ){
17141
- sqlite3_release_memory(overage);
17142
- }
17143
-}
17144
-
17145
-/*
17146
-** Attempt to release up to n bytes of non-essential memory currently
17147
-** held by SQLite. An example of non-essential memory is memory used to
17148
-** cache database pages that are not currently in use.
17149
-*/
17150
-SQLITE_API int sqlite3_release_memory(int n){
17151
-#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
17152
- int nRet = 0;
17153
- nRet += sqlite3PcacheReleaseMemory(n-nRet);
17154
- return nRet;
17155
-#else
17156
- UNUSED_PARAMETER(n);
17157
- return SQLITE_OK;
17158
-#endif
17159
-}
17160
-
17161
-/*
17162
-** State information local to the memory allocation subsystem.
17163
-*/
17164
-static SQLITE_WSD struct Mem0Global {
17165
- /* Number of free pages for scratch and page-cache memory */
17166
- u32 nScratchFree;
17167
- u32 nPageFree;
17168
-
17169
- sqlite3_mutex *mutex; /* Mutex to serialize access */
17170
-
17171
- /*
17172
- ** The alarm callback and its arguments. The mem0.mutex lock will
17173
- ** be held while the callback is running. Recursive calls into
17174
- ** the memory subsystem are allowed, but no new callbacks will be
17175
- ** issued.
17176
- */
17177
- sqlite3_int64 alarmThreshold;
17178
- void (*alarmCallback)(void*, sqlite3_int64,int);
17179
- void *alarmArg;
17180
-
17181
- /*
17182
- ** Pointers to the end of sqlite3GlobalConfig.pScratch and
17183
- ** sqlite3GlobalConfig.pPage to a block of memory that records
17184
- ** which pages are available.
17185
- */
17186
- u32 *aScratchFree;
17187
- u32 *aPageFree;
17188
-} mem0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
17189
-
17190
-#define mem0 GLOBAL(struct Mem0Global, mem0)
17500
+ excess = sqlite3_memory_used() - n;
17501
+ if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff));
17502
+ return priorLimit;
17503
+}
17504
+SQLITE_API void sqlite3_soft_heap_limit(int n){
17505
+ if( n<0 ) n = 0;
17506
+ sqlite3_soft_heap_limit64(n);
17507
+}
1719117508
1719217509
/*
1719317510
** Initialize the memory allocation subsystem.
1719417511
*/
1719517512
SQLITE_PRIVATE int sqlite3MallocInit(void){
@@ -17199,39 +17516,48 @@
1719917516
memset(&mem0, 0, sizeof(mem0));
1720017517
if( sqlite3GlobalConfig.bCoreMutex ){
1720117518
mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
1720217519
}
1720317520
if( sqlite3GlobalConfig.pScratch && sqlite3GlobalConfig.szScratch>=100
17204
- && sqlite3GlobalConfig.nScratch>=0 ){
17205
- int i;
17206
- sqlite3GlobalConfig.szScratch = ROUNDDOWN8(sqlite3GlobalConfig.szScratch-4);
17207
- mem0.aScratchFree = (u32*)&((char*)sqlite3GlobalConfig.pScratch)
17208
- [sqlite3GlobalConfig.szScratch*sqlite3GlobalConfig.nScratch];
17209
- for(i=0; i<sqlite3GlobalConfig.nScratch; i++){ mem0.aScratchFree[i] = i; }
17210
- mem0.nScratchFree = sqlite3GlobalConfig.nScratch;
17521
+ && sqlite3GlobalConfig.nScratch>0 ){
17522
+ int i, n, sz;
17523
+ ScratchFreeslot *pSlot;
17524
+ sz = ROUNDDOWN8(sqlite3GlobalConfig.szScratch);
17525
+ sqlite3GlobalConfig.szScratch = sz;
17526
+ pSlot = (ScratchFreeslot*)sqlite3GlobalConfig.pScratch;
17527
+ n = sqlite3GlobalConfig.nScratch;
17528
+ mem0.pScratchFree = pSlot;
17529
+ mem0.nScratchFree = n;
17530
+ for(i=0; i<n-1; i++){
17531
+ pSlot->pNext = (ScratchFreeslot*)(sz+(char*)pSlot);
17532
+ pSlot = pSlot->pNext;
17533
+ }
17534
+ pSlot->pNext = 0;
17535
+ mem0.pScratchEnd = (void*)&pSlot[1];
1721117536
}else{
17537
+ mem0.pScratchEnd = 0;
1721217538
sqlite3GlobalConfig.pScratch = 0;
1721317539
sqlite3GlobalConfig.szScratch = 0;
17214
- }
17215
- if( sqlite3GlobalConfig.pPage && sqlite3GlobalConfig.szPage>=512
17216
- && sqlite3GlobalConfig.nPage>=1 ){
17217
- int i;
17218
- int overhead;
17219
- int sz = ROUNDDOWN8(sqlite3GlobalConfig.szPage);
17220
- int n = sqlite3GlobalConfig.nPage;
17221
- overhead = (4*n + sz - 1)/sz;
17222
- sqlite3GlobalConfig.nPage -= overhead;
17223
- mem0.aPageFree = (u32*)&((char*)sqlite3GlobalConfig.pPage)
17224
- [sqlite3GlobalConfig.szPage*sqlite3GlobalConfig.nPage];
17225
- for(i=0; i<sqlite3GlobalConfig.nPage; i++){ mem0.aPageFree[i] = i; }
17226
- mem0.nPageFree = sqlite3GlobalConfig.nPage;
17227
- }else{
17540
+ sqlite3GlobalConfig.nScratch = 0;
17541
+ }
17542
+ if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512
17543
+ || sqlite3GlobalConfig.nPage<1 ){
1722817544
sqlite3GlobalConfig.pPage = 0;
1722917545
sqlite3GlobalConfig.szPage = 0;
17546
+ sqlite3GlobalConfig.nPage = 0;
1723017547
}
1723117548
return sqlite3GlobalConfig.m.xInit(sqlite3GlobalConfig.m.pAppData);
1723217549
}
17550
+
17551
+/*
17552
+** Return true if the heap is currently under memory pressure - in other
17553
+** words if the amount of heap used is close to the limit set by
17554
+** sqlite3_soft_heap_limit().
17555
+*/
17556
+SQLITE_PRIVATE int sqlite3HeapNearlyFull(void){
17557
+ return mem0.nearlyFull;
17558
+}
1723317559
1723417560
/*
1723517561
** Deinitialize the memory allocation subsystem.
1723617562
*/
1723717563
SQLITE_PRIVATE void sqlite3MallocEnd(void){
@@ -17263,40 +17589,10 @@
1726317589
sqlite3_status(SQLITE_STATUS_MEMORY_USED, &n, &mx, resetFlag);
1726417590
res = (sqlite3_int64)mx; /* Work around bug in Borland C. Ticket #3216 */
1726517591
return res;
1726617592
}
1726717593
17268
-/*
17269
-** Change the alarm callback
17270
-*/
17271
-SQLITE_PRIVATE int sqlite3MemoryAlarm(
17272
- void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
17273
- void *pArg,
17274
- sqlite3_int64 iThreshold
17275
-){
17276
- sqlite3_mutex_enter(mem0.mutex);
17277
- mem0.alarmCallback = xCallback;
17278
- mem0.alarmArg = pArg;
17279
- mem0.alarmThreshold = iThreshold;
17280
- sqlite3_mutex_leave(mem0.mutex);
17281
- return SQLITE_OK;
17282
-}
17283
-
17284
-#ifndef SQLITE_OMIT_DEPRECATED
17285
-/*
17286
-** Deprecated external interface. Internal/core SQLite code
17287
-** should call sqlite3MemoryAlarm.
17288
-*/
17289
-SQLITE_API int sqlite3_memory_alarm(
17290
- void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
17291
- void *pArg,
17292
- sqlite3_int64 iThreshold
17293
-){
17294
- return sqlite3MemoryAlarm(xCallback, pArg, iThreshold);
17295
-}
17296
-#endif
17297
-
1729817594
/*
1729917595
** Trigger the alarm
1730017596
*/
1730117597
static void sqlite3MallocAlarm(int nByte){
1730217598
void (*xCallback)(void*,sqlite3_int64,int);
@@ -17325,18 +17621,23 @@
1732517621
nFull = sqlite3GlobalConfig.m.xRoundup(n);
1732617622
sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
1732717623
if( mem0.alarmCallback!=0 ){
1732817624
int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
1732917625
if( nUsed+nFull >= mem0.alarmThreshold ){
17626
+ mem0.nearlyFull = 1;
1733017627
sqlite3MallocAlarm(nFull);
17628
+ }else{
17629
+ mem0.nearlyFull = 0;
1733117630
}
1733217631
}
1733317632
p = sqlite3GlobalConfig.m.xMalloc(nFull);
17633
+#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
1733417634
if( p==0 && mem0.alarmCallback ){
1733517635
sqlite3MallocAlarm(nFull);
1733617636
p = sqlite3GlobalConfig.m.xMalloc(nFull);
1733717637
}
17638
+#endif
1733817639
if( p ){
1733917640
nFull = sqlite3MallocSize(p);
1734017641
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nFull);
1734117642
sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, 1);
1734217643
}
@@ -17348,11 +17649,13 @@
1734817649
** Allocate memory. This routine is like sqlite3_malloc() except that it
1734917650
** assumes the memory subsystem has already been initialized.
1735017651
*/
1735117652
SQLITE_PRIVATE void *sqlite3Malloc(int n){
1735217653
void *p;
17353
- if( n<=0 || n>=0x7fffff00 ){
17654
+ if( n<=0 /* IMP: R-65312-04917 */
17655
+ || n>=0x7fffff00
17656
+ ){
1735417657
/* A memory allocation of a number of bytes which is near the maximum
1735517658
** signed integer value might cause an integer overflow inside of the
1735617659
** xMalloc(). Hence we limit the maximum size to 0x7fffff00, giving
1735717660
** 255 bytes of overhead. SQLite itself will never use anything near
1735817661
** this amount. The only way to reach the limit is with sqlite3_malloc() */
@@ -17362,10 +17665,11 @@
1736217665
mallocWithAlarm(n, &p);
1736317666
sqlite3_mutex_leave(mem0.mutex);
1736417667
}else{
1736517668
p = sqlite3GlobalConfig.m.xMalloc(n);
1736617669
}
17670
+ assert( EIGHT_BYTE_ALIGNMENT(p) ); /* IMP: R-04675-44850 */
1736717671
return p;
1736817672
}
1736917673
1737017674
/*
1737117675
** This version of the memory allocation is for use by the application.
@@ -17399,64 +17703,70 @@
1739917703
** embedded processor.
1740017704
*/
1740117705
SQLITE_PRIVATE void *sqlite3ScratchMalloc(int n){
1740217706
void *p;
1740317707
assert( n>0 );
17708
+
17709
+ sqlite3_mutex_enter(mem0.mutex);
17710
+ if( mem0.nScratchFree && sqlite3GlobalConfig.szScratch>=n ){
17711
+ p = mem0.pScratchFree;
17712
+ mem0.pScratchFree = mem0.pScratchFree->pNext;
17713
+ mem0.nScratchFree--;
17714
+ sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, 1);
17715
+ sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
17716
+ sqlite3_mutex_leave(mem0.mutex);
17717
+ }else{
17718
+ if( sqlite3GlobalConfig.bMemstat ){
17719
+ sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
17720
+ n = mallocWithAlarm(n, &p);
17721
+ if( p ) sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, n);
17722
+ sqlite3_mutex_leave(mem0.mutex);
17723
+ }else{
17724
+ sqlite3_mutex_leave(mem0.mutex);
17725
+ p = sqlite3GlobalConfig.m.xMalloc(n);
17726
+ }
17727
+ sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH);
17728
+ }
17729
+ assert( sqlite3_mutex_notheld(mem0.mutex) );
17730
+
1740417731
1740517732
#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
17406
- /* Verify that no more than two scratch allocation per thread
17407
- ** is outstanding at one time. (This is only checked in the
17733
+ /* Verify that no more than two scratch allocations per thread
17734
+ ** are outstanding at one time. (This is only checked in the
1740817735
** single-threaded case since checking in the multi-threaded case
1740917736
** would be much more complicated.) */
1741017737
assert( scratchAllocOut<=1 );
17411
-#endif
17412
-
17413
- if( sqlite3GlobalConfig.szScratch<n ){
17414
- goto scratch_overflow;
17415
- }else{
17416
- sqlite3_mutex_enter(mem0.mutex);
17417
- if( mem0.nScratchFree==0 ){
17418
- sqlite3_mutex_leave(mem0.mutex);
17419
- goto scratch_overflow;
17420
- }else{
17421
- int i;
17422
- i = mem0.aScratchFree[--mem0.nScratchFree];
17423
- i *= sqlite3GlobalConfig.szScratch;
17424
- sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, 1);
17425
- sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
17426
- sqlite3_mutex_leave(mem0.mutex);
17427
- p = (void*)&((char*)sqlite3GlobalConfig.pScratch)[i];
17428
- assert( (((u8*)p - (u8*)0) & 7)==0 );
17429
- }
17430
- }
17431
-#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
17432
- scratchAllocOut = p!=0;
17433
-#endif
17434
-
17435
- return p;
17436
-
17437
-scratch_overflow:
17438
- if( sqlite3GlobalConfig.bMemstat ){
17439
- sqlite3_mutex_enter(mem0.mutex);
17440
- sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
17441
- n = mallocWithAlarm(n, &p);
17442
- if( p ) sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, n);
17443
- sqlite3_mutex_leave(mem0.mutex);
17444
- }else{
17445
- p = sqlite3GlobalConfig.m.xMalloc(n);
17446
- }
17447
- sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH);
17448
-#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
17449
- scratchAllocOut = p!=0;
17450
-#endif
17451
- return p;
17738
+ if( p ) scratchAllocOut++;
17739
+#endif
17740
+
17741
+ return p;
1745217742
}
1745317743
SQLITE_PRIVATE void sqlite3ScratchFree(void *p){
1745417744
if( p ){
17455
- if( sqlite3GlobalConfig.pScratch==0
17456
- || p<sqlite3GlobalConfig.pScratch
17457
- || p>=(void*)mem0.aScratchFree ){
17745
+
17746
+#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
17747
+ /* Verify that no more than two scratch allocation per thread
17748
+ ** is outstanding at one time. (This is only checked in the
17749
+ ** single-threaded case since checking in the multi-threaded case
17750
+ ** would be much more complicated.) */
17751
+ assert( scratchAllocOut>=1 && scratchAllocOut<=2 );
17752
+ scratchAllocOut--;
17753
+#endif
17754
+
17755
+ if( p>=sqlite3GlobalConfig.pScratch && p<mem0.pScratchEnd ){
17756
+ /* Release memory from the SQLITE_CONFIG_SCRATCH allocation */
17757
+ ScratchFreeslot *pSlot;
17758
+ pSlot = (ScratchFreeslot*)p;
17759
+ sqlite3_mutex_enter(mem0.mutex);
17760
+ pSlot->pNext = mem0.pScratchFree;
17761
+ mem0.pScratchFree = pSlot;
17762
+ mem0.nScratchFree++;
17763
+ assert( mem0.nScratchFree<=sqlite3GlobalConfig.nScratch );
17764
+ sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1);
17765
+ sqlite3_mutex_leave(mem0.mutex);
17766
+ }else{
17767
+ /* Release memory back to the heap */
1745817768
assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
1745917769
assert( sqlite3MemdebugNoType(p, ~MEMTYPE_SCRATCH) );
1746017770
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
1746117771
if( sqlite3GlobalConfig.bMemstat ){
1746217772
int iSize = sqlite3MallocSize(p);
@@ -17467,30 +17777,10 @@
1746717777
sqlite3GlobalConfig.m.xFree(p);
1746817778
sqlite3_mutex_leave(mem0.mutex);
1746917779
}else{
1747017780
sqlite3GlobalConfig.m.xFree(p);
1747117781
}
17472
- }else{
17473
- int i;
17474
- i = (int)((u8*)p - (u8*)sqlite3GlobalConfig.pScratch);
17475
- i /= sqlite3GlobalConfig.szScratch;
17476
- assert( i>=0 && i<sqlite3GlobalConfig.nScratch );
17477
- sqlite3_mutex_enter(mem0.mutex);
17478
- assert( mem0.nScratchFree<(u32)sqlite3GlobalConfig.nScratch );
17479
- mem0.aScratchFree[mem0.nScratchFree++] = i;
17480
- sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1);
17481
- sqlite3_mutex_leave(mem0.mutex);
17482
-
17483
-#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
17484
- /* Verify that no more than two scratch allocation per thread
17485
- ** is outstanding at one time. (This is only checked in the
17486
- ** single-threaded case since checking in the multi-threaded case
17487
- ** would be much more complicated.) */
17488
- assert( scratchAllocOut>=1 && scratchAllocOut<=2 );
17489
- scratchAllocOut = 0;
17490
-#endif
17491
-
1749217782
}
1749317783
}
1749417784
}
1749517785
1749617786
/*
@@ -17527,11 +17817,11 @@
1752717817
1752817818
/*
1752917819
** Free memory previously obtained from sqlite3Malloc().
1753017820
*/
1753117821
SQLITE_API void sqlite3_free(void *p){
17532
- if( p==0 ) return;
17822
+ if( p==0 ) return; /* IMP: R-49053-54554 */
1753317823
assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
1753417824
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
1753517825
if( sqlite3GlobalConfig.bMemstat ){
1753617826
sqlite3_mutex_enter(mem0.mutex);
1753717827
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
@@ -17574,21 +17864,24 @@
1757417864
*/
1757517865
SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, int nBytes){
1757617866
int nOld, nNew;
1757717867
void *pNew;
1757817868
if( pOld==0 ){
17579
- return sqlite3Malloc(nBytes);
17869
+ return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */
1758017870
}
1758117871
if( nBytes<=0 ){
17582
- sqlite3_free(pOld);
17872
+ sqlite3_free(pOld); /* IMP: R-31593-10574 */
1758317873
return 0;
1758417874
}
1758517875
if( nBytes>=0x7fffff00 ){
1758617876
/* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */
1758717877
return 0;
1758817878
}
1758917879
nOld = sqlite3MallocSize(pOld);
17880
+ /* IMPLEMENTATION-OF: R-46199-30249 SQLite guarantees that the second
17881
+ ** argument to xRealloc is always a value returned by a prior call to
17882
+ ** xRoundup. */
1759017883
nNew = sqlite3GlobalConfig.m.xRoundup(nBytes);
1759117884
if( nOld==nNew ){
1759217885
pNew = pOld;
1759317886
}else if( sqlite3GlobalConfig.bMemstat ){
1759417887
sqlite3_mutex_enter(mem0.mutex);
@@ -17610,10 +17903,11 @@
1761017903
}
1761117904
sqlite3_mutex_leave(mem0.mutex);
1761217905
}else{
1761317906
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
1761417907
}
17908
+ assert( EIGHT_BYTE_ALIGNMENT(pNew) ); /* IMP: R-04675-44850 */
1761517909
return pNew;
1761617910
}
1761717911
1761817912
/*
1761917913
** The public interface to sqlite3Realloc. Make sure that the memory
@@ -19773,10 +20067,16 @@
1977320067
#define UpperToLower sqlite3UpperToLower
1977420068
1977520069
/*
1977620070
** Some systems have stricmp(). Others have strcasecmp(). Because
1977720071
** there is no consistency, we will define our own.
20072
+**
20073
+** IMPLEMENTATION-OF: R-20522-24639 The sqlite3_strnicmp() API allows
20074
+** applications and extensions to compare the contents of two buffers
20075
+** containing UTF-8 strings in a case-independent fashion, using the same
20076
+** definition of case independence that SQLite uses internally when
20077
+** comparing identifiers.
1977820078
*/
1977920079
SQLITE_PRIVATE int sqlite3StrICmp(const char *zLeft, const char *zRight){
1978020080
register unsigned char *a, *b;
1978120081
a = (unsigned char *)zLeft;
1978220082
b = (unsigned char *)zRight;
@@ -19790,125 +20090,115 @@
1979020090
while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
1979120091
return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
1979220092
}
1979320093
1979420094
/*
19795
-** Return TRUE if z is a pure numeric string. Return FALSE and leave
19796
-** *realnum unchanged if the string contains any character which is not
19797
-** part of a number.
19798
-**
19799
-** If the string is pure numeric, set *realnum to TRUE if the string
19800
-** contains the '.' character or an "E+000" style exponentiation suffix.
19801
-** Otherwise set *realnum to FALSE. Note that just becaue *realnum is
19802
-** false does not mean that the number can be successfully converted into
19803
-** an integer - it might be too big.
19804
-**
19805
-** An empty string is considered non-numeric.
19806
-*/
19807
-SQLITE_PRIVATE int sqlite3IsNumber(const char *z, int *realnum, u8 enc){
20095
+** The string z[] is an text representation of a real number.
20096
+** Convert this string to a double and write it into *pResult.
20097
+**
20098
+** The string z[] is length bytes in length (bytes, not characters) and
20099
+** uses the encoding enc. The string is not necessarily zero-terminated.
20100
+**
20101
+** Return TRUE if the result is a valid real number (or integer) and FALSE
20102
+** if the string is empty or contains extraneous text. Valid numbers
20103
+** are in one of these formats:
20104
+**
20105
+** [+-]digits[E[+-]digits]
20106
+** [+-]digits.[digits][E[+-]digits]
20107
+** [+-].digits[E[+-]digits]
20108
+**
20109
+** Leading and trailing whitespace is ignored for the purpose of determining
20110
+** validity.
20111
+**
20112
+** If some prefix of the input string is a valid number, this routine
20113
+** returns FALSE but it still converts the prefix and writes the result
20114
+** into *pResult.
20115
+*/
20116
+SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
20117
+#ifndef SQLITE_OMIT_FLOATING_POINT
1980820118
int incr = (enc==SQLITE_UTF8?1:2);
19809
- if( enc==SQLITE_UTF16BE ) z++;
19810
- if( *z=='-' || *z=='+' ) z += incr;
19811
- if( !sqlite3Isdigit(*z) ){
19812
- return 0;
19813
- }
19814
- z += incr;
19815
- *realnum = 0;
19816
- while( sqlite3Isdigit(*z) ){ z += incr; }
19817
-#ifndef SQLITE_OMIT_FLOATING_POINT
19818
- if( *z=='.' ){
19819
- z += incr;
19820
- if( !sqlite3Isdigit(*z) ) return 0;
19821
- while( sqlite3Isdigit(*z) ){ z += incr; }
19822
- *realnum = 1;
19823
- }
19824
- if( *z=='e' || *z=='E' ){
19825
- z += incr;
19826
- if( *z=='+' || *z=='-' ) z += incr;
19827
- if( !sqlite3Isdigit(*z) ) return 0;
19828
- while( sqlite3Isdigit(*z) ){ z += incr; }
19829
- *realnum = 1;
19830
- }
19831
-#endif
19832
- return *z==0;
19833
-}
19834
-
19835
-/*
19836
-** The string z[] is an ASCII representation of a real number.
19837
-** Convert this string to a double.
19838
-**
19839
-** This routine assumes that z[] really is a valid number. If it
19840
-** is not, the result is undefined.
19841
-**
19842
-** This routine is used instead of the library atof() function because
19843
-** the library atof() might want to use "," as the decimal point instead
19844
-** of "." depending on how locale is set. But that would cause problems
19845
-** for SQL. So this routine always uses "." regardless of locale.
19846
-*/
19847
-SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult){
19848
-#ifndef SQLITE_OMIT_FLOATING_POINT
19849
- const char *zBegin = z;
20119
+ const char *zEnd = z + length;
1985020120
/* sign * significand * (10 ^ (esign * exponent)) */
19851
- int sign = 1; /* sign of significand */
19852
- i64 s = 0; /* significand */
19853
- int d = 0; /* adjust exponent for shifting decimal point */
19854
- int esign = 1; /* sign of exponent */
19855
- int e = 0; /* exponent */
20121
+ int sign = 1; /* sign of significand */
20122
+ i64 s = 0; /* significand */
20123
+ int d = 0; /* adjust exponent for shifting decimal point */
20124
+ int esign = 1; /* sign of exponent */
20125
+ int e = 0; /* exponent */
20126
+ int eValid = 1; /* True exponent is either not used or is well-formed */
1985620127
double result;
1985720128
int nDigits = 0;
1985820129
20130
+ *pResult = 0.0; /* Default return value, in case of an error */
20131
+
20132
+ if( enc==SQLITE_UTF16BE ) z++;
20133
+
1985920134
/* skip leading spaces */
19860
- while( sqlite3Isspace(*z) ) z++;
20135
+ while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
20136
+ if( z>=zEnd ) return 0;
20137
+
1986120138
/* get sign of significand */
1986220139
if( *z=='-' ){
1986320140
sign = -1;
19864
- z++;
20141
+ z+=incr;
1986520142
}else if( *z=='+' ){
19866
- z++;
20143
+ z+=incr;
1986720144
}
20145
+
1986820146
/* skip leading zeroes */
19869
- while( z[0]=='0' ) z++, nDigits++;
20147
+ while( z<zEnd && z[0]=='0' ) z+=incr, nDigits++;
1987020148
1987120149
/* copy max significant digits to significand */
19872
- while( sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
20150
+ while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
1987320151
s = s*10 + (*z - '0');
19874
- z++, nDigits++;
20152
+ z+=incr, nDigits++;
1987520153
}
20154
+
1987620155
/* skip non-significant significand digits
1987720156
** (increase exponent by d to shift decimal left) */
19878
- while( sqlite3Isdigit(*z) ) z++, nDigits++, d++;
20157
+ while( z<zEnd && sqlite3Isdigit(*z) ) z+=incr, nDigits++, d++;
20158
+ if( z>=zEnd ) goto do_atof_calc;
1987920159
1988020160
/* if decimal point is present */
1988120161
if( *z=='.' ){
19882
- z++;
20162
+ z+=incr;
1988320163
/* copy digits from after decimal to significand
1988420164
** (decrease exponent by d to shift decimal right) */
19885
- while( sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
20165
+ while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
1988620166
s = s*10 + (*z - '0');
19887
- z++, nDigits++, d--;
20167
+ z+=incr, nDigits++, d--;
1988820168
}
1988920169
/* skip non-significant digits */
19890
- while( sqlite3Isdigit(*z) ) z++, nDigits++;
20170
+ while( z<zEnd && sqlite3Isdigit(*z) ) z+=incr, nDigits++;
1989120171
}
20172
+ if( z>=zEnd ) goto do_atof_calc;
1989220173
1989320174
/* if exponent is present */
1989420175
if( *z=='e' || *z=='E' ){
19895
- z++;
20176
+ z+=incr;
20177
+ eValid = 0;
20178
+ if( z>=zEnd ) goto do_atof_calc;
1989620179
/* get sign of exponent */
1989720180
if( *z=='-' ){
1989820181
esign = -1;
19899
- z++;
20182
+ z+=incr;
1990020183
}else if( *z=='+' ){
19901
- z++;
20184
+ z+=incr;
1990220185
}
1990320186
/* copy digits to exponent */
19904
- while( sqlite3Isdigit(*z) ){
20187
+ while( z<zEnd && sqlite3Isdigit(*z) ){
1990520188
e = e*10 + (*z - '0');
19906
- z++;
20189
+ z+=incr;
20190
+ eValid = 1;
1990720191
}
1990820192
}
1990920193
20194
+ /* skip trailing spaces */
20195
+ if( nDigits && eValid ){
20196
+ while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
20197
+ }
20198
+
20199
+do_atof_calc:
1991020200
/* adjust exponent by d, and update sign */
1991120201
e = (e*esign) + d;
1991220202
if( e<0 ) {
1991320203
esign = -1;
1991420204
e *= -1;
@@ -19963,132 +20253,104 @@
1996320253
}
1996420254
1996520255
/* store the result */
1996620256
*pResult = result;
1996720257
19968
- /* return number of characters used */
19969
- return (int)(z - zBegin);
20258
+ /* return true if number and no extra non-whitespace chracters after */
20259
+ return z>=zEnd && nDigits>0 && eValid;
1997020260
#else
19971
- return sqlite3Atoi64(z, pResult);
20261
+ return !sqlite3Atoi64(z, pResult, length, enc);
1997220262
#endif /* SQLITE_OMIT_FLOATING_POINT */
1997320263
}
1997420264
1997520265
/*
1997620266
** Compare the 19-character string zNum against the text representation
1997720267
** value 2^63: 9223372036854775808. Return negative, zero, or positive
1997820268
** if zNum is less than, equal to, or greater than the string.
20269
+** Note that zNum must contain exactly 19 characters.
1997920270
**
1998020271
** Unlike memcmp() this routine is guaranteed to return the difference
1998120272
** in the values of the last digit if the only difference is in the
1998220273
** last digit. So, for example,
1998320274
**
19984
-** compare2pow63("9223372036854775800")
20275
+** compare2pow63("9223372036854775800", 1)
1998520276
**
1998620277
** will return -8.
1998720278
*/
19988
-static int compare2pow63(const char *zNum){
19989
- int c;
19990
- c = memcmp(zNum,"922337203685477580",18)*10;
20279
+static int compare2pow63(const char *zNum, int incr){
20280
+ int c = 0;
20281
+ int i;
20282
+ /* 012345678901234567 */
20283
+ const char *pow63 = "922337203685477580";
20284
+ for(i=0; c==0 && i<18; i++){
20285
+ c = (zNum[i*incr]-pow63[i])*10;
20286
+ }
1999120287
if( c==0 ){
19992
- c = zNum[18] - '8';
20288
+ c = zNum[18*incr] - '8';
1999320289
testcase( c==(-1) );
1999420290
testcase( c==0 );
1999520291
testcase( c==(+1) );
1999620292
}
1999720293
return c;
1999820294
}
1999920295
2000020296
2000120297
/*
20002
-** Return TRUE if zNum is a 64-bit signed integer and write
20003
-** the value of the integer into *pNum. If zNum is not an integer
20004
-** or is an integer that is too large to be expressed with 64 bits,
20005
-** then return false.
20298
+** Convert zNum to a 64-bit signed integer and write
20299
+** the value of the integer into *pNum.
20300
+** If zNum is exactly 9223372036854665808, return 2.
20301
+** This is a special case as the context will determine
20302
+** if it is too big (used as a negative).
20303
+** If zNum is not an integer or is an integer that
20304
+** is too large to be expressed with 64 bits,
20305
+** then return 1. Otherwise return 0.
2000620306
**
20007
-** When this routine was originally written it dealt with only
20008
-** 32-bit numbers. At that time, it was much faster than the
20009
-** atoi() library routine in RedHat 7.2.
20307
+** length is the number of bytes in the string (bytes, not characters).
20308
+** The string is not necessarily zero-terminated. The encoding is
20309
+** given by enc.
2001020310
*/
20011
-SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum){
20311
+SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
20312
+ int incr = (enc==SQLITE_UTF8?1:2);
2001220313
i64 v = 0;
20013
- int neg;
20014
- int i, c;
20314
+ int neg = 0; /* assume positive */
20315
+ int i;
20316
+ int c = 0;
2001520317
const char *zStart;
20016
- while( sqlite3Isspace(*zNum) ) zNum++;
20318
+ const char *zEnd = zNum + length;
20319
+ if( enc==SQLITE_UTF16BE ) zNum++;
20320
+ while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
20321
+ if( zNum>=zEnd ) goto do_atoi_calc;
2001720322
if( *zNum=='-' ){
2001820323
neg = 1;
20019
- zNum++;
20324
+ zNum+=incr;
2002020325
}else if( *zNum=='+' ){
20021
- neg = 0;
20022
- zNum++;
20023
- }else{
20024
- neg = 0;
20326
+ zNum+=incr;
2002520327
}
20328
+do_atoi_calc:
2002620329
zStart = zNum;
20027
- while( zNum[0]=='0' ){ zNum++; } /* Skip over leading zeros. Ticket #2454 */
20028
- for(i=0; (c=zNum[i])>='0' && c<='9'; i++){
20330
+ while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
20331
+ for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){
2002920332
v = v*10 + c - '0';
2003020333
}
2003120334
*pNum = neg ? -v : v;
2003220335
testcase( i==18 );
2003320336
testcase( i==19 );
2003420337
testcase( i==20 );
20035
- if( c!=0 || (i==0 && zStart==zNum) || i>19 ){
20338
+ if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr ){
2003620339
/* zNum is empty or contains non-numeric text or is longer
20037
- ** than 19 digits (thus guaranting that it is too large) */
20038
- return 0;
20039
- }else if( i<19 ){
20340
+ ** than 19 digits (thus guaranteeing that it is too large) */
20341
+ return 1;
20342
+ }else if( i<19*incr ){
2004020343
/* Less than 19 digits, so we know that it fits in 64 bits */
20041
- return 1;
20344
+ return 0;
2004220345
}else{
2004320346
/* 19-digit numbers must be no larger than 9223372036854775807 if positive
2004420347
** or 9223372036854775808 if negative. Note that 9223372036854665808
20045
- ** is 2^63. */
20046
- return compare2pow63(zNum)<neg;
20047
- }
20048
-}
20049
-
20050
-/*
20051
-** The string zNum represents an unsigned integer. The zNum string
20052
-** consists of one or more digit characters and is terminated by
20053
-** a zero character. Any stray characters in zNum result in undefined
20054
-** behavior.
20055
-**
20056
-** If the unsigned integer that zNum represents will fit in a
20057
-** 64-bit signed integer, return TRUE. Otherwise return FALSE.
20058
-**
20059
-** If the negFlag parameter is true, that means that zNum really represents
20060
-** a negative number. (The leading "-" is omitted from zNum.) This
20061
-** parameter is needed to determine a boundary case. A string
20062
-** of "9223373036854775808" returns false if negFlag is false or true
20063
-** if negFlag is true.
20064
-**
20065
-** Leading zeros are ignored.
20066
-*/
20067
-SQLITE_PRIVATE int sqlite3FitsIn64Bits(const char *zNum, int negFlag){
20068
- int i;
20069
- int neg = 0;
20070
-
20071
- assert( zNum[0]>='0' && zNum[0]<='9' ); /* zNum is an unsigned number */
20072
-
20073
- if( negFlag ) neg = 1-neg;
20074
- while( *zNum=='0' ){
20075
- zNum++; /* Skip leading zeros. Ticket #2454 */
20076
- }
20077
- for(i=0; zNum[i]; i++){ assert( zNum[i]>='0' && zNum[i]<='9' ); }
20078
- testcase( i==18 );
20079
- testcase( i==19 );
20080
- testcase( i==20 );
20081
- if( i<19 ){
20082
- /* Guaranteed to fit if less than 19 digits */
20083
- return 1;
20084
- }else if( i>19 ){
20085
- /* Guaranteed to be too big if greater than 19 digits */
20086
- return 0;
20087
- }else{
20088
- /* Compare against 2^63. */
20089
- return compare2pow63(zNum)<neg;
20348
+ ** is 2^63. Return 1 if to large */
20349
+ c=compare2pow63(zNum, incr);
20350
+ if( c==0 && neg==0 ) return 2; /* too big, exactly 9223372036854665808 */
20351
+ return c<neg ? 0 : 1;
2009020352
}
2009120353
}
2009220354
2009320355
/*
2009420356
** If zNum represents an integer that will fit in 32-bits, then set
@@ -26177,11 +26439,11 @@
2617726439
goto shmpage_out;
2617826440
}
2617926441
pShmNode->apRegion = apNew;
2618026442
while(pShmNode->nRegion<=iRegion){
2618126443
void *pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE,
26182
- MAP_SHARED, pShmNode->h, iRegion*szRegion
26444
+ MAP_SHARED, pShmNode->h, pShmNode->nRegion*szRegion
2618326445
);
2618426446
if( pMem==MAP_FAILED ){
2618526447
rc = SQLITE_IOERR;
2618626448
goto shmpage_out;
2618726449
}
@@ -28000,17 +28262,20 @@
2800028262
static int proxyGetHostID(unsigned char *pHostID, int *pError){
2800128263
struct timespec timeout = {1, 0}; /* 1 sec timeout */
2800228264
2800328265
assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
2800428266
memset(pHostID, 0, PROXY_HOSTIDLEN);
28267
+#if defined(__MAX_OS_X_VERSION_MIN_REQUIRED)\
28268
+ && __MAC_OS_X_VERSION_MIN_REQUIRED<1050
2800528269
if( gethostuuid(pHostID, &timeout) ){
2800628270
int err = errno;
2800728271
if( pError ){
2800828272
*pError = err;
2800928273
}
2801028274
return SQLITE_IOERR;
2801128275
}
28276
+#endif
2801228277
#ifdef SQLITE_TEST
2801328278
/* simulate multiple hosts by creating unique hostid file paths */
2801428279
if( sqlite3_hostid_num != 0){
2801528280
pHostID[0] = (char)(pHostID[0] + (char)(sqlite3_hostid_num & 0xFF));
2801628281
}
@@ -30339,10 +30604,18 @@
3033930604
return SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN;
3034030605
}
3034130606
3034230607
#ifndef SQLITE_OMIT_WAL
3034330608
30609
+/*
30610
+** Windows will only let you create file view mappings
30611
+** on allocation size granularity boundaries.
30612
+** During sqlite3_os_init() we do a GetSystemInfo()
30613
+** to get the granularity size.
30614
+*/
30615
+SYSTEM_INFO winSysInfo;
30616
+
3034430617
/*
3034530618
** Helper functions to obtain and relinquish the global mutex. The
3034630619
** global mutex is used to protect the winLockInfo objects used by
3034730620
** this file, all of which may be shared by multiple threads.
3034830621
**
@@ -30507,19 +30780,26 @@
3050730780
** by VFS shared-memory methods.
3050830781
*/
3050930782
static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
3051030783
winShmNode **pp;
3051130784
winShmNode *p;
30785
+ BOOL bRc;
3051230786
assert( winShmMutexHeld() );
3051330787
pp = &winShmNodeList;
3051430788
while( (p = *pp)!=0 ){
3051530789
if( p->nRef==0 ){
3051630790
int i;
3051730791
if( p->mutex ) sqlite3_mutex_free(p->mutex);
3051830792
for(i=0; i<p->nRegion; i++){
30519
- UnmapViewOfFile(p->aRegion[i].pMap);
30520
- CloseHandle(p->aRegion[i].hMap);
30793
+ bRc = UnmapViewOfFile(p->aRegion[i].pMap);
30794
+ OSTRACE(("SHM-PURGE pid-%d unmap region=%d %s\n",
30795
+ (int)GetCurrentProcessId(), i,
30796
+ bRc ? "ok" : "failed"));
30797
+ bRc = CloseHandle(p->aRegion[i].hMap);
30798
+ OSTRACE(("SHM-PURGE pid-%d close region=%d %s\n",
30799
+ (int)GetCurrentProcessId(), i,
30800
+ bRc ? "ok" : "failed"));
3052130801
}
3052230802
if( p->hFile.h != INVALID_HANDLE_VALUE ){
3052330803
SimulateIOErrorBenign(1);
3052430804
winClose((sqlite3_file *)&p->hFile);
3052530805
SimulateIOErrorBenign(0);
@@ -30592,14 +30872,15 @@
3059230872
pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
3059330873
if( pShmNode->mutex==0 ){
3059430874
rc = SQLITE_NOMEM;
3059530875
goto shm_open_err;
3059630876
}
30877
+
3059730878
rc = winOpen(pDbFd->pVfs,
3059830879
pShmNode->zFilename, /* Name of the file (UTF-8) */
3059930880
(sqlite3_file*)&pShmNode->hFile, /* File handle here */
30600
- SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, /* Mode flags */
30881
+ SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, /* Mode flags */
3060130882
0);
3060230883
if( SQLITE_OK!=rc ){
3060330884
rc = SQLITE_CANTOPEN_BKPT;
3060430885
goto shm_open_err;
3060530886
}
@@ -30903,14 +31184,22 @@
3090331184
void *pMap = 0; /* Mapped memory region */
3090431185
3090531186
hMap = CreateFileMapping(pShmNode->hFile.h,
3090631187
NULL, PAGE_READWRITE, 0, nByte, NULL
3090731188
);
31189
+ OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n",
31190
+ (int)GetCurrentProcessId(), pShmNode->nRegion, nByte,
31191
+ hMap ? "ok" : "failed"));
3090831192
if( hMap ){
31193
+ int iOffset = pShmNode->nRegion*szRegion;
31194
+ int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
3090931195
pMap = MapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
30910
- 0, 0, nByte
31196
+ 0, iOffset - iOffsetShift, szRegion + iOffsetShift
3091131197
);
31198
+ OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n",
31199
+ (int)GetCurrentProcessId(), pShmNode->nRegion, iOffset, szRegion,
31200
+ pMap ? "ok" : "failed"));
3091231201
}
3091331202
if( !pMap ){
3091431203
pShmNode->lastErrno = GetLastError();
3091531204
rc = SQLITE_IOERR;
3091631205
if( hMap ) CloseHandle(hMap);
@@ -30923,12 +31212,14 @@
3092331212
}
3092431213
}
3092531214
3092631215
shmpage_out:
3092731216
if( pShmNode->nRegion>iRegion ){
31217
+ int iOffset = iRegion*szRegion;
31218
+ int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
3092831219
char *p = (char *)pShmNode->aRegion[iRegion].pMap;
30929
- *pp = (void *)&p[iRegion*szRegion];
31220
+ *pp = (void *)&p[iOffsetShift];
3093031221
}else{
3093131222
*pp = 0;
3093231223
}
3093331224
sqlite3_mutex_leave(pShmNode->mutex);
3093431225
return rc;
@@ -31151,13 +31442,64 @@
3115131442
DWORD dwFlagsAndAttributes = 0;
3115231443
#if SQLITE_OS_WINCE
3115331444
int isTemp = 0;
3115431445
#endif
3115531446
winFile *pFile = (winFile*)id;
31156
- void *zConverted; /* Filename in OS encoding */
31157
- const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
31158
- char zTmpname[MAX_PATH+1]; /* Buffer used to create temp filename */
31447
+ void *zConverted; /* Filename in OS encoding */
31448
+ const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
31449
+
31450
+ /* If argument zPath is a NULL pointer, this function is required to open
31451
+ ** a temporary file. Use this buffer to store the file name in.
31452
+ */
31453
+ char zTmpname[MAX_PATH+1]; /* Buffer used to create temp filename */
31454
+
31455
+ int rc = SQLITE_OK; /* Function Return Code */
31456
+#if !defined(NDEBUG) || SQLITE_OS_WINCE
31457
+ int eType = flags&0xFFFFFF00; /* Type of file to open */
31458
+#endif
31459
+
31460
+ int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
31461
+ int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE);
31462
+ int isCreate = (flags & SQLITE_OPEN_CREATE);
31463
+#ifndef NDEBUG
31464
+ int isReadonly = (flags & SQLITE_OPEN_READONLY);
31465
+#endif
31466
+ int isReadWrite = (flags & SQLITE_OPEN_READWRITE);
31467
+
31468
+#ifndef NDEBUG
31469
+ int isOpenJournal = (isCreate && (
31470
+ eType==SQLITE_OPEN_MASTER_JOURNAL
31471
+ || eType==SQLITE_OPEN_MAIN_JOURNAL
31472
+ || eType==SQLITE_OPEN_WAL
31473
+ ));
31474
+#endif
31475
+
31476
+ /* Check the following statements are true:
31477
+ **
31478
+ ** (a) Exactly one of the READWRITE and READONLY flags must be set, and
31479
+ ** (b) if CREATE is set, then READWRITE must also be set, and
31480
+ ** (c) if EXCLUSIVE is set, then CREATE must also be set.
31481
+ ** (d) if DELETEONCLOSE is set, then CREATE must also be set.
31482
+ */
31483
+ assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
31484
+ assert(isCreate==0 || isReadWrite);
31485
+ assert(isExclusive==0 || isCreate);
31486
+ assert(isDelete==0 || isCreate);
31487
+
31488
+ /* The main DB, main journal, WAL file and master journal are never
31489
+ ** automatically deleted. Nor are they ever temporary files. */
31490
+ assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB );
31491
+ assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL );
31492
+ assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MASTER_JOURNAL );
31493
+ assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL );
31494
+
31495
+ /* Assert that the upper layer has set one of the "file-type" flags. */
31496
+ assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
31497
+ || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
31498
+ || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
31499
+ || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
31500
+ );
3115931501
3116031502
assert( id!=0 );
3116131503
UNUSED_PARAMETER(pVfs);
3116231504
3116331505
pFile->h = INVALID_HANDLE_VALUE;
@@ -31164,11 +31506,12 @@
3116431506
3116531507
/* If the second argument to this function is NULL, generate a
3116631508
** temporary file name to use
3116731509
*/
3116831510
if( !zUtf8Name ){
31169
- int rc = getTempname(MAX_PATH+1, zTmpname);
31511
+ assert(isDelete && !isOpenJournal);
31512
+ rc = getTempname(MAX_PATH+1, zTmpname);
3117031513
if( rc!=SQLITE_OK ){
3117131514
return rc;
3117231515
}
3117331516
zUtf8Name = zTmpname;
3117431517
}
@@ -31177,33 +31520,35 @@
3117731520
zConverted = convertUtf8Filename(zUtf8Name);
3117831521
if( zConverted==0 ){
3117931522
return SQLITE_NOMEM;
3118031523
}
3118131524
31182
- if( flags & SQLITE_OPEN_READWRITE ){
31525
+ if( isReadWrite ){
3118331526
dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
3118431527
}else{
3118531528
dwDesiredAccess = GENERIC_READ;
3118631529
}
31530
+
3118731531
/* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is
3118831532
** created. SQLite doesn't use it to indicate "exclusive access"
3118931533
** as it is usually understood.
3119031534
*/
31191
- assert(!(flags & SQLITE_OPEN_EXCLUSIVE) || (flags & SQLITE_OPEN_CREATE));
31192
- if( flags & SQLITE_OPEN_EXCLUSIVE ){
31535
+ if( isExclusive ){
3119331536
/* Creates a new file, only if it does not already exist. */
3119431537
/* If the file exists, it fails. */
3119531538
dwCreationDisposition = CREATE_NEW;
31196
- }else if( flags & SQLITE_OPEN_CREATE ){
31539
+ }else if( isCreate ){
3119731540
/* Open existing file, or create if it doesn't exist */
3119831541
dwCreationDisposition = OPEN_ALWAYS;
3119931542
}else{
3120031543
/* Opens a file, only if it exists. */
3120131544
dwCreationDisposition = OPEN_EXISTING;
3120231545
}
31546
+
3120331547
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
31204
- if( flags & SQLITE_OPEN_DELETEONCLOSE ){
31548
+
31549
+ if( isDelete ){
3120531550
#if SQLITE_OS_WINCE
3120631551
dwFlagsAndAttributes = FILE_ATTRIBUTE_HIDDEN;
3120731552
isTemp = 1;
3120831553
#else
3120931554
dwFlagsAndAttributes = FILE_ATTRIBUTE_TEMPORARY
@@ -31216,10 +31561,11 @@
3121631561
/* Reports from the internet are that performance is always
3121731562
** better if FILE_FLAG_RANDOM_ACCESS is used. Ticket #2699. */
3121831563
#if SQLITE_OS_WINCE
3121931564
dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
3122031565
#endif
31566
+
3122131567
if( isNT() ){
3122231568
h = CreateFileW((WCHAR*)zConverted,
3122331569
dwDesiredAccess,
3122431570
dwShareMode,
3122531571
NULL,
@@ -31241,41 +31587,45 @@
3124131587
dwFlagsAndAttributes,
3124231588
NULL
3124331589
);
3124431590
#endif
3124531591
}
31592
+
3124631593
OSTRACE(("OPEN %d %s 0x%lx %s\n",
3124731594
h, zName, dwDesiredAccess,
3124831595
h==INVALID_HANDLE_VALUE ? "failed" : "ok"));
31596
+
3124931597
if( h==INVALID_HANDLE_VALUE ){
3125031598
pFile->lastErrno = GetLastError();
3125131599
free(zConverted);
31252
- if( flags & SQLITE_OPEN_READWRITE ){
31600
+ if( isReadWrite ){
3125331601
return winOpen(pVfs, zName, id,
31254
- ((flags|SQLITE_OPEN_READONLY)&~SQLITE_OPEN_READWRITE), pOutFlags);
31602
+ ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)), pOutFlags);
3125531603
}else{
3125631604
return SQLITE_CANTOPEN_BKPT;
3125731605
}
3125831606
}
31607
+
3125931608
if( pOutFlags ){
31260
- if( flags & SQLITE_OPEN_READWRITE ){
31609
+ if( isReadWrite ){
3126131610
*pOutFlags = SQLITE_OPEN_READWRITE;
3126231611
}else{
3126331612
*pOutFlags = SQLITE_OPEN_READONLY;
3126431613
}
3126531614
}
31615
+
3126631616
memset(pFile, 0, sizeof(*pFile));
3126731617
pFile->pMethod = &winIoMethod;
3126831618
pFile->h = h;
3126931619
pFile->lastErrno = NO_ERROR;
3127031620
pFile->pVfs = pVfs;
3127131621
pFile->pShm = 0;
3127231622
pFile->zPath = zName;
3127331623
pFile->sectorSize = getSectorSize(pVfs, zUtf8Name);
31624
+
3127431625
#if SQLITE_OS_WINCE
31275
- if( (flags & (SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB)) ==
31276
- (SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB)
31626
+ if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
3127731627
&& !winceCreateLock(zName, pFile)
3127831628
){
3127931629
CloseHandle(h);
3128031630
free(zConverted);
3128131631
return SQLITE_CANTOPEN_BKPT;
@@ -31285,12 +31635,13 @@
3128531635
}else
3128631636
#endif
3128731637
{
3128831638
free(zConverted);
3128931639
}
31640
+
3129031641
OpenCounter(+1);
31291
- return SQLITE_OK;
31642
+ return rc;
3129231643
}
3129331644
3129431645
/*
3129531646
** Delete the named file.
3129631647
**
@@ -31804,10 +32155,17 @@
3180432155
winSleep, /* xSleep */
3180532156
winCurrentTime, /* xCurrentTime */
3180632157
winGetLastError, /* xGetLastError */
3180732158
winCurrentTimeInt64, /* xCurrentTimeInt64 */
3180832159
};
32160
+
32161
+#ifndef SQLITE_OMIT_WAL
32162
+ /* get memory map allocation granularity */
32163
+ memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
32164
+ GetSystemInfo(&winSysInfo);
32165
+ assert(winSysInfo.dwAllocationGranularity > 0);
32166
+#endif
3180932167
3181032168
sqlite3_vfs_register(&winVfs, 1);
3181132169
return SQLITE_OK;
3181232170
}
3181332171
SQLITE_API int sqlite3_os_end(void){
@@ -32369,16 +32727,20 @@
3236932727
** Initialize and shutdown the page cache subsystem. Neither of these
3237032728
** functions are threadsafe.
3237132729
*/
3237232730
SQLITE_PRIVATE int sqlite3PcacheInitialize(void){
3237332731
if( sqlite3GlobalConfig.pcache.xInit==0 ){
32732
+ /* IMPLEMENTATION-OF: R-26801-64137 If the xInit() method is NULL, then the
32733
+ ** built-in default page cache is used instead of the application defined
32734
+ ** page cache. */
3237432735
sqlite3PCacheSetDefault();
3237532736
}
3237632737
return sqlite3GlobalConfig.pcache.xInit(sqlite3GlobalConfig.pcache.pArg);
3237732738
}
3237832739
SQLITE_PRIVATE void sqlite3PcacheShutdown(void){
3237932740
if( sqlite3GlobalConfig.pcache.xShutdown ){
32741
+ /* IMPLEMENTATION-OF: R-26000-56589 The xShutdown() method may be NULL. */
3238032742
sqlite3GlobalConfig.pcache.xShutdown(sqlite3GlobalConfig.pcache.pArg);
3238132743
}
3238232744
}
3238332745
3238432746
/*
@@ -32835,12 +33197,17 @@
3283533197
3283633198
typedef struct PCache1 PCache1;
3283733199
typedef struct PgHdr1 PgHdr1;
3283833200
typedef struct PgFreeslot PgFreeslot;
3283933201
32840
-/* Pointers to structures of this type are cast and returned as
32841
-** opaque sqlite3_pcache* handles
33202
+/* Each page cache is an instance of the following object. Every
33203
+** open database file (including each in-memory database and each
33204
+** temporary or transient database) has a single page cache which
33205
+** is an instance of this object.
33206
+**
33207
+** Pointers to structures of this type are cast and returned as
33208
+** opaque sqlite3_pcache* handles.
3284233209
*/
3284333210
struct PCache1 {
3284433211
/* Cache configuration parameters. Page size (szPage) and the purgeable
3284533212
** flag (bPurgeable) are set when the cache is created. nMax may be
3284633213
** modified at any time by a call to the pcache1CacheSize() method.
@@ -32896,10 +33263,13 @@
3289633263
int nCurrentPage; /* Number of purgeable pages allocated */
3289733264
PgHdr1 *pLruHead, *pLruTail; /* LRU list of unpinned pages */
3289833265
3289933266
/* Variables related to SQLITE_CONFIG_PAGECACHE settings. */
3290033267
int szSlot; /* Size of each free slot */
33268
+ int nSlot; /* The number of pcache slots */
33269
+ int nFreeSlot; /* Number of unused pcache slots */
33270
+ int nReserve; /* Try to keep nFreeSlot above this */
3290133271
void *pStart, *pEnd; /* Bounds of pagecache malloc range */
3290233272
PgFreeslot *pFree; /* Free page blocks */
3290333273
int isInit; /* True if initialized */
3290433274
} pcache1_g;
3290533275
@@ -32943,10 +33313,12 @@
3294333313
SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){
3294433314
if( pcache1.isInit ){
3294533315
PgFreeslot *p;
3294633316
sz = ROUNDDOWN8(sz);
3294733317
pcache1.szSlot = sz;
33318
+ pcache1.nSlot = pcache1.nFreeSlot = n;
33319
+ pcache1.nReserve = n>90 ? 10 : (n/10 + 1);
3294833320
pcache1.pStart = pBuf;
3294933321
pcache1.pFree = 0;
3295033322
while( n-- ){
3295133323
p = (PgFreeslot*)pBuf;
3295233324
p->pNext = pcache1.pFree;
@@ -32969,10 +33341,12 @@
3296933341
sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
3297033342
if( nByte<=pcache1.szSlot && pcache1.pFree ){
3297133343
assert( pcache1.isInit );
3297233344
p = (PgHdr1 *)pcache1.pFree;
3297333345
pcache1.pFree = pcache1.pFree->pNext;
33346
+ pcache1.nFreeSlot--;
33347
+ assert( pcache1.nFreeSlot>=0 );
3297433348
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);
3297533349
}else{
3297633350
3297733351
/* Allocate a new buffer using sqlite3Malloc. Before doing so, exit the
3297833352
** global pcache mutex and unlock the pager-cache object pCache. This is
@@ -33002,10 +33376,12 @@
3300233376
PgFreeslot *pSlot;
3300333377
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
3300433378
pSlot = (PgFreeslot*)p;
3300533379
pSlot->pNext = pcache1.pFree;
3300633380
pcache1.pFree = pSlot;
33381
+ pcache1.nFreeSlot++;
33382
+ assert( pcache1.nFreeSlot<=pcache1.nSlot );
3300733383
}else{
3300833384
int iSize;
3300933385
assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
3301033386
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
3301133387
iSize = sqlite3MallocSize(p);
@@ -33014,11 +33390,11 @@
3301433390
}
3301533391
}
3301633392
3301733393
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
3301833394
/*
33019
-** Return the size of a pache allocation
33395
+** Return the size of a pcache allocation
3302033396
*/
3302133397
static int pcache1MemSize(void *p){
3302233398
assert( sqlite3_mutex_held(pcache1.mutex) );
3302333399
if( p>=pcache1.pStart && p<pcache1.pEnd ){
3302433400
return pcache1.szSlot;
@@ -33087,10 +33463,36 @@
3308733463
pcache1EnterMutex();
3308833464
pcache1Free(p);
3308933465
pcache1LeaveMutex();
3309033466
}
3309133467
33468
+
33469
+/*
33470
+** Return true if it desirable to avoid allocating a new page cache
33471
+** entry.
33472
+**
33473
+** If memory was allocated specifically to the page cache using
33474
+** SQLITE_CONFIG_PAGECACHE but that memory has all been used, then
33475
+** it is desirable to avoid allocating a new page cache entry because
33476
+** presumably SQLITE_CONFIG_PAGECACHE was suppose to be sufficient
33477
+** for all page cache needs and we should not need to spill the
33478
+** allocation onto the heap.
33479
+**
33480
+** Or, the heap is used for all page cache memory put the heap is
33481
+** under memory pressure, then again it is desirable to avoid
33482
+** allocating a new page cache entry in order to avoid stressing
33483
+** the heap even further.
33484
+*/
33485
+static int pcache1UnderMemoryPressure(PCache1 *pCache){
33486
+ assert( sqlite3_mutex_held(pcache1.mutex) );
33487
+ if( pcache1.nSlot && pCache->szPage<=pcache1.szSlot ){
33488
+ return pcache1.nFreeSlot<pcache1.nReserve;
33489
+ }else{
33490
+ return sqlite3HeapNearlyFull();
33491
+ }
33492
+}
33493
+
3309233494
/******************************************************************************/
3309333495
/******** General Implementation Functions ************************************/
3309433496
3309533497
/*
3309633498
** This function is used to resize the hash table used by the cache passed
@@ -33328,18 +33730,20 @@
3332833730
** copy of the requested page. If one is found, it is returned.
3332933731
**
3333033732
** 2. If createFlag==0 and the page is not already in the cache, NULL is
3333133733
** returned.
3333233734
**
33333
-** 3. If createFlag is 1, and the page is not already in the cache,
33334
-** and if either of the following are true, return NULL:
33735
+** 3. If createFlag is 1, and the page is not already in the cache, then
33736
+** return NULL (do not allocate a new page) if any of the following
33737
+** conditions are true:
3333533738
**
3333633739
** (a) the number of pages pinned by the cache is greater than
3333733740
** PCache1.nMax, or
33741
+**
3333833742
** (b) the number of pages pinned by the cache is greater than
3333933743
** the sum of nMax for all purgeable caches, less the sum of
33340
-** nMin for all other purgeable caches.
33744
+** nMin for all other purgeable caches, or
3334133745
**
3334233746
** 4. If none of the first three conditions apply and the cache is marked
3334333747
** as purgeable, and if one of the following is true:
3334433748
**
3334533749
** (a) The number of pages allocated for the cache is already
@@ -33346,10 +33750,13 @@
3334633750
** PCache1.nMax, or
3334733751
**
3334833752
** (b) The number of pages allocated for all purgeable caches is
3334933753
** already equal to or greater than the sum of nMax for all
3335033754
** purgeable caches,
33755
+**
33756
+** (c) The system is under memory pressure and wants to avoid
33757
+** unnecessary pages cache entry allocations
3335133758
**
3335233759
** then attempt to recycle a page from the LRU list. If it is the right
3335333760
** size, return the recycled buffer. Otherwise, free the buffer and
3335433761
** proceed to step 5.
3335533762
**
@@ -33378,10 +33785,11 @@
3337833785
/* Step 3 of header comment. */
3337933786
nPinned = pCache->nPage - pCache->nRecyclable;
3338033787
if( createFlag==1 && (
3338133788
nPinned>=(pcache1.nMaxPage+pCache->nMin-pcache1.nMinPage)
3338233789
|| nPinned>=(pCache->nMax * 9 / 10)
33790
+ || pcache1UnderMemoryPressure(pCache)
3338333791
)){
3338433792
goto fetch_out;
3338533793
}
3338633794
3338733795
if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){
@@ -33388,11 +33796,13 @@
3338833796
goto fetch_out;
3338933797
}
3339033798
3339133799
/* Step 4. Try to recycle a page buffer if appropriate. */
3339233800
if( pCache->bPurgeable && pcache1.pLruTail && (
33393
- (pCache->nPage+1>=pCache->nMax) || pcache1.nCurrentPage>=pcache1.nMaxPage
33801
+ (pCache->nPage+1>=pCache->nMax)
33802
+ || pcache1.nCurrentPage>=pcache1.nMaxPage
33803
+ || pcache1UnderMemoryPressure(pCache)
3339433804
)){
3339533805
pPage = pcache1.pLruTail;
3339633806
pcache1RemoveFromHash(pPage);
3339733807
pcache1PinPage(pPage);
3339833808
if( pPage->pCache->szPage!=pCache->szPage ){
@@ -33531,10 +33941,11 @@
3353133941
**
3353233942
** Destroy a cache allocated using pcache1Create().
3353333943
*/
3353433944
static void pcache1Destroy(sqlite3_pcache *p){
3353533945
PCache1 *pCache = (PCache1 *)p;
33946
+ assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
3353633947
pcache1EnterMutex();
3353733948
pcache1TruncateUnsafe(pCache, 0);
3353833949
pcache1.nMaxPage -= pCache->nMax;
3353933950
pcache1.nMinPage -= pCache->nMin;
3354033951
pcache1EnforceMaxPage();
@@ -33578,11 +33989,11 @@
3357833989
SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
3357933990
int nFree = 0;
3358033991
if( pcache1.pStart==0 ){
3358133992
PgHdr1 *p;
3358233993
pcache1EnterMutex();
33583
- while( (nReq<0 || nFree<nReq) && (p=pcache1.pLruTail) ){
33994
+ while( (nReq<0 || nFree<nReq) && ((p=pcache1.pLruTail)!=0) ){
3358433995
nFree += pcache1MemSize(PGHDR1_TO_PAGE(p));
3358533996
pcache1PinPage(p);
3358633997
pcache1RemoveFromHash(p);
3358733998
pcache1FreePage(p);
3358833999
}
@@ -37120,16 +37531,17 @@
3712037531
** the duplicate call is harmless.
3712137532
*/
3712237533
sqlite3WalEndReadTransaction(pPager->pWal);
3712337534
3712437535
rc = sqlite3WalBeginReadTransaction(pPager->pWal, &changed);
37125
- if( rc==SQLITE_OK && changed ){
37536
+ if( rc!=SQLITE_OK || changed ){
3712637537
pager_reset(pPager);
3712737538
}
3712837539
3712937540
return rc;
3713037541
}
37542
+#endif
3713137543
3713237544
/*
3713337545
** This function is called as part of the transition from PAGER_OPEN
3713437546
** to PAGER_READER state to determine the size of the database file
3713537547
** in pages (assuming the page size currently stored in Pager.pageSize).
@@ -37182,11 +37594,11 @@
3718237594
3718337595
*pnPage = nPage;
3718437596
return SQLITE_OK;
3718537597
}
3718637598
37187
-
37599
+#ifndef SQLITE_OMIT_WAL
3718837600
/*
3718937601
** Check if the *-wal file that corresponds to the database opened by pPager
3719037602
** exists if the database is not empy, or verify that the *-wal file does
3719137603
** not exist (by deleting it) if the database file is empty.
3719237604
**
@@ -38374,10 +38786,17 @@
3837438786
journalFileSize = ROUND8(sqlite3MemJournalSize());
3837538787
}
3837638788
3837738789
/* Set the output variable to NULL in case an error occurs. */
3837838790
*ppPager = 0;
38791
+
38792
+#ifndef SQLITE_OMIT_MEMORYDB
38793
+ if( flags & PAGER_MEMORY ){
38794
+ memDb = 1;
38795
+ zFilename = 0;
38796
+ }
38797
+#endif
3837938798
3838038799
/* Compute and store the full pathname in an allocated buffer pointed
3838138800
** to by zPathname, length nPathname. Or, if this is a temporary file,
3838238801
** leave both nPathname and zPathname set to 0.
3838338802
*/
@@ -38385,21 +38804,12 @@
3838538804
nPathname = pVfs->mxPathname+1;
3838638805
zPathname = sqlite3Malloc(nPathname*2);
3838738806
if( zPathname==0 ){
3838838807
return SQLITE_NOMEM;
3838938808
}
38390
-#ifndef SQLITE_OMIT_MEMORYDB
38391
- if( strcmp(zFilename,":memory:")==0 ){
38392
- memDb = 1;
38393
- zPathname[0] = 0;
38394
- }else
38395
-#endif
38396
- {
38397
- zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
38398
- rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
38399
- }
38400
-
38809
+ zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
38810
+ rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
3840138811
nPathname = sqlite3Strlen30(zPathname);
3840238812
if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){
3840338813
/* This branch is taken when the journal path required by
3840438814
** the database being opened will be more than pVfs->mxPathname
3840538815
** bytes in length. This means the database cannot be opened,
@@ -38450,34 +38860,31 @@
3845038860
pPager->zFilename = (char*)(pPtr += journalFileSize);
3845138861
assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) );
3845238862
3845338863
/* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
3845438864
if( zPathname ){
38865
+ assert( nPathname>0 );
3845538866
pPager->zJournal = (char*)(pPtr += nPathname + 1);
3845638867
memcpy(pPager->zFilename, zPathname, nPathname);
3845738868
memcpy(pPager->zJournal, zPathname, nPathname);
3845838869
memcpy(&pPager->zJournal[nPathname], "-journal", 8);
38459
- if( pPager->zFilename[0]==0 ){
38460
- pPager->zJournal[0] = 0;
38461
- }
3846238870
#ifndef SQLITE_OMIT_WAL
38463
- else{
38464
- pPager->zWal = &pPager->zJournal[nPathname+8+1];
38465
- memcpy(pPager->zWal, zPathname, nPathname);
38466
- memcpy(&pPager->zWal[nPathname], "-wal", 4);
38467
- }
38871
+ pPager->zWal = &pPager->zJournal[nPathname+8+1];
38872
+ memcpy(pPager->zWal, zPathname, nPathname);
38873
+ memcpy(&pPager->zWal[nPathname], "-wal", 4);
3846838874
#endif
3846938875
sqlite3_free(zPathname);
3847038876
}
3847138877
pPager->pVfs = pVfs;
3847238878
pPager->vfsFlags = vfsFlags;
3847338879
3847438880
/* Open the pager file.
3847538881
*/
38476
- if( zFilename && zFilename[0] && !memDb ){
38882
+ if( zFilename && zFilename[0] ){
3847738883
int fout = 0; /* VFS flags returned by xOpen() */
3847838884
rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
38885
+ assert( !memDb );
3847938886
readOnly = (fout&SQLITE_OPEN_READONLY);
3848038887
3848138888
/* If the file was successfully opened for read/write access,
3848238889
** choose a default page size in case we have to create the
3848338890
** database file. The default page size is the maximum of:
@@ -38927,11 +39334,13 @@
3892739334
3892839335
/* If there is a WAL file in the file-system, open this database in WAL
3892939336
** mode. Otherwise, the following function call is a no-op.
3893039337
*/
3893139338
rc = pagerOpenWalIfPresent(pPager);
39339
+#ifndef SQLITE_OMIT_WAL
3893239340
assert( pPager->pWal==0 || rc==SQLITE_OK );
39341
+#endif
3893339342
}
3893439343
3893539344
if( pagerUseWal(pPager) ){
3893639345
assert( rc==SQLITE_OK );
3893739346
rc = pagerBeginReadTransaction(pPager);
@@ -43292,11 +43701,11 @@
4329243701
WALTRACE(("WAL%p: wal-header write %s\n", pWal, rc ? "failed" : "ok"));
4329343702
if( rc!=SQLITE_OK ){
4329443703
return rc;
4329543704
}
4329643705
}
43297
- assert( pWal->szPage==szPage );
43706
+ assert( (int)pWal->szPage==szPage );
4329843707
4329943708
/* Write the log file. */
4330043709
for(p=pList; p; p=p->pDirty){
4330143710
u32 nDbsize; /* Db-size field for frame header */
4330243711
i64 iOffset; /* Write offset in log file */
@@ -43952,10 +44361,11 @@
4395244361
MemPage *pPage1; /* First page of the database */
4395344362
u8 readOnly; /* True if the underlying file is readonly */
4395444363
u8 pageSizeFixed; /* True if the page size can no longer be changed */
4395544364
u8 secureDelete; /* True if secure_delete is enabled */
4395644365
u8 initiallyEmpty; /* Database is empty at start of transaction */
44366
+ u8 openFlags; /* Flags to sqlite3BtreeOpen() */
4395744367
#ifndef SQLITE_OMIT_AUTOVACUUM
4395844368
u8 autoVacuum; /* True if auto-vacuum is enabled */
4395944369
u8 incrVacuum; /* True if incr-vacuum is enabled */
4396044370
#endif
4396144371
u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
@@ -46202,15 +46612,24 @@
4620246612
4620346613
/*
4620446614
** Open a database file.
4620546615
**
4620646616
** zFilename is the name of the database file. If zFilename is NULL
46207
-** a new database with a random name is created. This randomly named
46208
-** database file will be deleted when sqlite3BtreeClose() is called.
46617
+** then an ephemeral database is created. The ephemeral database might
46618
+** be exclusively in memory, or it might use a disk-based memory cache.
46619
+** Either way, the ephemeral database will be automatically deleted
46620
+** when sqlite3BtreeClose() is called.
46621
+**
4620946622
** If zFilename is ":memory:" then an in-memory database is created
4621046623
** that is automatically destroyed when it is closed.
4621146624
**
46625
+** The "flags" parameter is a bitmask that might contain bits
46626
+** BTREE_OMIT_JOURNAL and/or BTREE_NO_READLOCK. The BTREE_NO_READLOCK
46627
+** bit is also set if the SQLITE_NoReadlock flags is set in db->flags.
46628
+** These flags are passed through into sqlite3PagerOpen() and must
46629
+** be the same values as PAGER_OMIT_JOURNAL and PAGER_NO_READLOCK.
46630
+**
4621246631
** If the database is already opened in the same database connection
4621346632
** and we are in shared cache mode, then the open will fail with an
4621446633
** SQLITE_CONSTRAINT error. We cannot allow two or more BtShared
4621546634
** objects in the same database connection since doing so will lead
4621646635
** to problems with locking.
@@ -46227,10 +46646,13 @@
4622746646
Btree *p; /* Handle to return */
4622846647
sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */
4622946648
int rc = SQLITE_OK; /* Result code from this function */
4623046649
u8 nReserve; /* Byte of unused space on each page */
4623146650
unsigned char zDbHeader[100]; /* Database header content */
46651
+
46652
+ /* True if opening an ephemeral, temporary database */
46653
+ const int isTempDb = zFilename==0 || zFilename[0]==0;
4623246654
4623346655
/* Set the variable isMemdb to true for an in-memory database, or
4623446656
** false for a file-based database. This symbol is only required if
4623546657
** either of the shared-data or autovacuum features are compiled
4623646658
** into the library.
@@ -46237,17 +46659,34 @@
4623746659
*/
4623846660
#if !defined(SQLITE_OMIT_SHARED_CACHE) || !defined(SQLITE_OMIT_AUTOVACUUM)
4623946661
#ifdef SQLITE_OMIT_MEMORYDB
4624046662
const int isMemdb = 0;
4624146663
#else
46242
- const int isMemdb = zFilename && !strcmp(zFilename, ":memory:");
46664
+ const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0)
46665
+ || (isTempDb && sqlite3TempInMemory(db));
4624346666
#endif
4624446667
#endif
4624546668
4624646669
assert( db!=0 );
4624746670
assert( sqlite3_mutex_held(db->mutex) );
46671
+ assert( (flags&0xff)==flags ); /* flags fit in 8 bits */
4624846672
46673
+ /* Only a BTREE_SINGLE database can be BTREE_UNORDERED */
46674
+ assert( (flags & BTREE_UNORDERED)==0 || (flags & BTREE_SINGLE)!=0 );
46675
+
46676
+ /* A BTREE_SINGLE database is always a temporary and/or ephemeral */
46677
+ assert( (flags & BTREE_SINGLE)==0 || isTempDb );
46678
+
46679
+ if( db->flags & SQLITE_NoReadlock ){
46680
+ flags |= BTREE_NO_READLOCK;
46681
+ }
46682
+ if( isMemdb ){
46683
+ flags |= BTREE_MEMORY;
46684
+ }
46685
+ if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){
46686
+ vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB;
46687
+ }
4624946688
pVfs = db->pVfs;
4625046689
p = sqlite3MallocZero(sizeof(Btree));
4625146690
if( !p ){
4625246691
return SQLITE_NOMEM;
4625346692
}
@@ -46261,11 +46700,11 @@
4626146700
#if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
4626246701
/*
4626346702
** If this Btree is a candidate for shared cache, try to find an
4626446703
** existing BtShared object that we can share with
4626546704
*/
46266
- if( isMemdb==0 && zFilename && zFilename[0] ){
46705
+ if( isMemdb==0 && isTempDb==0 ){
4626746706
if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){
4626846707
int nFullPathname = pVfs->mxPathname+1;
4626946708
char *zFullPathname = sqlite3Malloc(nFullPathname);
4627046709
sqlite3_mutex *mutexShared;
4627146710
p->sharable = 1;
@@ -46336,10 +46775,11 @@
4633646775
rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
4633746776
}
4633846777
if( rc!=SQLITE_OK ){
4633946778
goto btree_open_out;
4634046779
}
46780
+ pBt->openFlags = (u8)flags;
4634146781
pBt->db = db;
4634246782
sqlite3PagerSetBusyhandler(pBt->pPager, btreeInvokeBusyHandler, pBt);
4634346783
p->pBt = pBt;
4634446784
4634546785
pBt->pCursor = 0;
@@ -46440,10 +46880,18 @@
4644046880
sqlite3PagerClose(pBt->pPager);
4644146881
}
4644246882
sqlite3_free(pBt);
4644346883
sqlite3_free(p);
4644446884
*ppBtree = 0;
46885
+ }else{
46886
+ /* If the B-Tree was successfully opened, set the pager-cache size to the
46887
+ ** default value. Except, when opening on an existing shared pager-cache,
46888
+ ** do not change the pager-cache size.
46889
+ */
46890
+ if( sqlite3BtreeSchema(p, 0, 0)==0 ){
46891
+ sqlite3PagerSetCachesize(p->pBt->pPager, SQLITE_DEFAULT_CACHE_SIZE);
46892
+ }
4644546893
}
4644646894
if( mutexOpen ){
4644746895
assert( sqlite3_mutex_held(mutexOpen) );
4644846896
sqlite3_mutex_leave(mutexOpen);
4644946897
}
@@ -51390,15 +51838,16 @@
5139051838
** flags might not work:
5139151839
**
5139251840
** BTREE_INTKEY|BTREE_LEAFDATA Used for SQL tables with rowid keys
5139351841
** BTREE_ZERODATA Used for SQL indices
5139451842
*/
51395
-static int btreeCreateTable(Btree *p, int *piTable, int flags){
51843
+static int btreeCreateTable(Btree *p, int *piTable, int createTabFlags){
5139651844
BtShared *pBt = p->pBt;
5139751845
MemPage *pRoot;
5139851846
Pgno pgnoRoot;
5139951847
int rc;
51848
+ int ptfFlags; /* Page-type flage for the root page of new table */
5140051849
5140151850
assert( sqlite3BtreeHoldsMutex(p) );
5140251851
assert( pBt->inTransaction==TRANS_WRITE );
5140351852
assert( !pBt->readOnly );
5140451853
@@ -51513,12 +51962,18 @@
5151351962
rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
5151451963
if( rc ) return rc;
5151551964
}
5151651965
#endif
5151751966
assert( sqlite3PagerIswriteable(pRoot->pDbPage) );
51518
- zeroPage(pRoot, flags | PTF_LEAF);
51967
+ if( createTabFlags & BTREE_INTKEY ){
51968
+ ptfFlags = PTF_INTKEY | PTF_LEAFDATA | PTF_LEAF;
51969
+ }else{
51970
+ ptfFlags = PTF_ZERODATA | PTF_LEAF;
51971
+ }
51972
+ zeroPage(pRoot, ptfFlags);
5151951973
sqlite3PagerUnref(pRoot->pDbPage);
51974
+ assert( (pBt->openFlags & BTREE_SINGLE)==0 || pgnoRoot==2 );
5152051975
*piTable = (int)pgnoRoot;
5152151976
return SQLITE_OK;
5152251977
}
5152351978
SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree *p, int *piTable, int flags){
5152451979
int rc;
@@ -52774,11 +53229,14 @@
5277453229
sqlite3Error(
5277553230
pDestDb, SQLITE_ERROR, "source and destination must be distinct"
5277653231
);
5277753232
p = 0;
5277853233
}else {
52779
- /* Allocate space for a new sqlite3_backup object */
53234
+ /* Allocate space for a new sqlite3_backup object...
53235
+ ** EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
53236
+ ** call to sqlite3_backup_init() and is destroyed by a call to
53237
+ ** sqlite3_backup_finish(). */
5278053238
p = (sqlite3_backup *)sqlite3_malloc(sizeof(sqlite3_backup));
5278153239
if( !p ){
5278253240
sqlite3Error(pDestDb, SQLITE_NOMEM, 0);
5278353241
}
5278453242
}
@@ -53157,10 +53615,13 @@
5315753615
if( p->pDestDb ){
5315853616
sqlite3_mutex_leave(p->pDestDb->mutex);
5315953617
}
5316053618
sqlite3BtreeLeave(p->pSrc);
5316153619
if( p->pDestDb ){
53620
+ /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
53621
+ ** call to sqlite3_backup_init() and is destroyed by a call to
53622
+ ** sqlite3_backup_finish(). */
5316253623
sqlite3_free(p);
5316353624
}
5316453625
sqlite3_mutex_leave(mutex);
5316553626
return rc;
5316653627
}
@@ -53408,10 +53869,13 @@
5340853869
return SQLITE_NOMEM;
5340953870
}
5341053871
pMem->z[pMem->n] = 0;
5341153872
pMem->z[pMem->n+1] = 0;
5341253873
pMem->flags |= MEM_Term;
53874
+#ifdef SQLITE_DEBUG
53875
+ pMem->pScopyFrom = 0;
53876
+#endif
5341353877
}
5341453878
5341553879
return SQLITE_OK;
5341653880
}
5341753881
@@ -53528,11 +53992,11 @@
5352853992
memset(&ctx, 0, sizeof(ctx));
5352953993
ctx.s.flags = MEM_Null;
5353053994
ctx.s.db = pMem->db;
5353153995
ctx.pMem = pMem;
5353253996
ctx.pFunc = pFunc;
53533
- pFunc->xFinalize(&ctx);
53997
+ pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
5353453998
assert( 0==(pMem->flags&MEM_Dyn) && !pMem->xDel );
5353553999
sqlite3DbFree(pMem->db, pMem->zMalloc);
5353654000
memcpy(pMem, &ctx.s, sizeof(ctx.s));
5353754001
rc = ctx.isError;
5353854002
}
@@ -53641,17 +54105,13 @@
5364154105
return pMem->u.i;
5364254106
}else if( flags & MEM_Real ){
5364354107
return doubleToInt64(pMem->r);
5364454108
}else if( flags & (MEM_Str|MEM_Blob) ){
5364554109
i64 value;
53646
- pMem->flags |= MEM_Str;
53647
- if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
53648
- || sqlite3VdbeMemNulTerminate(pMem) ){
53649
- return 0;
53650
- }
53651
- assert( pMem->z );
53652
- sqlite3Atoi64(pMem->z, &value);
54110
+ assert( pMem->z || pMem->n==0 );
54111
+ testcase( pMem->z==0 );
54112
+ sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
5365354113
return value;
5365454114
}else{
5365554115
return 0;
5365654116
}
5365754117
}
@@ -53677,11 +54137,11 @@
5367754137
|| sqlite3VdbeMemNulTerminate(pMem) ){
5367854138
/* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
5367954139
return (double)0;
5368054140
}
5368154141
assert( pMem->z );
53682
- sqlite3AtoF(pMem->z, &val);
54142
+ sqlite3AtoF(pMem->z, &val, pMem->n, SQLITE_UTF8);
5368354143
return val;
5368454144
}else{
5368554145
/* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
5368654146
return (double)0;
5368754147
}
@@ -53750,25 +54210,23 @@
5375054210
** Every effort is made to force the conversion, even if the input
5375154211
** is a string that does not look completely like a number. Convert
5375254212
** as much of the string as we can and ignore the rest.
5375354213
*/
5375454214
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem *pMem){
53755
- int rc;
53756
- assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))==0 );
53757
- assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
53758
- assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
53759
- rc = sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8);
53760
- if( rc ) return rc;
53761
- rc = sqlite3VdbeMemNulTerminate(pMem);
53762
- if( rc ) return rc;
53763
- if( sqlite3Atoi64(pMem->z, &pMem->u.i) ){
53764
- MemSetTypeFlag(pMem, MEM_Int);
53765
- }else{
53766
- pMem->r = sqlite3VdbeRealValue(pMem);
53767
- MemSetTypeFlag(pMem, MEM_Real);
53768
- sqlite3VdbeIntegerAffinity(pMem);
53769
- }
54215
+ if( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))==0 ){
54216
+ assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
54217
+ assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54218
+ if( 0==sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc) ){
54219
+ MemSetTypeFlag(pMem, MEM_Int);
54220
+ }else{
54221
+ pMem->r = sqlite3VdbeRealValue(pMem);
54222
+ MemSetTypeFlag(pMem, MEM_Real);
54223
+ sqlite3VdbeIntegerAffinity(pMem);
54224
+ }
54225
+ }
54226
+ assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))!=0 );
54227
+ pMem->flags &= ~(MEM_Str|MEM_Blob);
5377054228
return SQLITE_OK;
5377154229
}
5377254230
5377354231
/*
5377454232
** Delete any previous value and set the value stored in *pMem to NULL.
@@ -53869,10 +54327,32 @@
5386954327
return n>p->db->aLimit[SQLITE_LIMIT_LENGTH];
5387054328
}
5387154329
return 0;
5387254330
}
5387354331
54332
+#ifdef SQLITE_DEBUG
54333
+/*
54334
+** This routine prepares a memory cell for modication by breaking
54335
+** its link to a shallow copy and by marking any current shallow
54336
+** copies of this cell as invalid.
54337
+**
54338
+** This is used for testing and debugging only - to make sure shallow
54339
+** copies are not misused.
54340
+*/
54341
+SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe *pVdbe, Mem *pMem){
54342
+ int i;
54343
+ Mem *pX;
54344
+ for(i=1, pX=&pVdbe->aMem[1]; i<=pVdbe->nMem; i++, pX++){
54345
+ if( pX->pScopyFrom==pMem ){
54346
+ pX->flags |= MEM_Invalid;
54347
+ pX->pScopyFrom = 0;
54348
+ }
54349
+ }
54350
+ pMem->pScopyFrom = 0;
54351
+}
54352
+#endif /* SQLITE_DEBUG */
54353
+
5387454354
/*
5387554355
** Size of struct Mem not including the Mem.zMalloc member.
5387654356
*/
5387754357
#define MEMCELLSIZE (size_t)(&(((Mem *)0)->zMalloc))
5387854358
@@ -54237,11 +54717,11 @@
5423754717
assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 );
5423854718
if( sqlite3VdbeMemMakeWriteable(pVal)!=SQLITE_OK ){
5423954719
return 0;
5424054720
}
5424154721
}
54242
- sqlite3VdbeMemNulTerminate(pVal);
54722
+ sqlite3VdbeMemNulTerminate(pVal); /* IMP: R-59893-45467 */
5424354723
}else{
5424454724
assert( (pVal->flags&MEM_Blob)==0 );
5424554725
sqlite3VdbeMemStringify(pVal, enc);
5424654726
assert( 0==(1&SQLITE_PTR_TO_INT(pVal->z)) );
5424754727
}
@@ -54285,10 +54765,12 @@
5428554765
sqlite3_value **ppVal /* Write the new value here */
5428654766
){
5428754767
int op;
5428854768
char *zVal = 0;
5428954769
sqlite3_value *pVal = 0;
54770
+ int negInt = 1;
54771
+ const char *zNeg = "";
5429054772
5429154773
if( !pExpr ){
5429254774
*ppVal = 0;
5429354775
return SQLITE_OK;
5429454776
}
@@ -54301,35 +54783,50 @@
5430154783
#ifdef SQLITE_ENABLE_STAT2
5430254784
if( op==TK_REGISTER ) op = pExpr->op2;
5430354785
#else
5430454786
if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
5430554787
#endif
54788
+
54789
+ /* Handle negative integers in a single step. This is needed in the
54790
+ ** case when the value is -9223372036854775808.
54791
+ */
54792
+ if( op==TK_UMINUS
54793
+ && (pExpr->pLeft->op==TK_INTEGER || pExpr->pLeft->op==TK_FLOAT) ){
54794
+ pExpr = pExpr->pLeft;
54795
+ op = pExpr->op;
54796
+ negInt = -1;
54797
+ zNeg = "-";
54798
+ }
5430654799
5430754800
if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
5430854801
pVal = sqlite3ValueNew(db);
5430954802
if( pVal==0 ) goto no_mem;
5431054803
if( ExprHasProperty(pExpr, EP_IntValue) ){
54311
- sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue);
54804
+ sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt);
5431254805
}else{
54313
- zVal = sqlite3DbStrDup(db, pExpr->u.zToken);
54806
+ zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
5431454807
if( zVal==0 ) goto no_mem;
5431554808
sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
5431654809
if( op==TK_FLOAT ) pVal->type = SQLITE_FLOAT;
5431754810
}
5431854811
if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
5431954812
sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
5432054813
}else{
5432154814
sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
5432254815
}
54816
+ if( pVal->flags & (MEM_Int|MEM_Real) ) pVal->flags &= ~MEM_Str;
5432354817
if( enc!=SQLITE_UTF8 ){
5432454818
sqlite3VdbeChangeEncoding(pVal, enc);
5432554819
}
5432654820
}else if( op==TK_UMINUS ) {
54821
+ /* This branch happens for multiple negative signs. Ex: -(-5) */
5432754822
if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){
54823
+ sqlite3VdbeMemNumerify(pVal);
5432854824
pVal->u.i = -1 * pVal->u.i;
5432954825
/* (double)-1 In case of SQLITE_OMIT_FLOATING_POINT... */
5433054826
pVal->r = (double)-1 * pVal->r;
54827
+ sqlite3ValueApplyAffinity(pVal, affinity, enc);
5433154828
}
5433254829
}
5433354830
#ifndef SQLITE_OMIT_BLOB_LITERAL
5433454831
else if( op==TK_BLOB ){
5433554832
int nVal;
@@ -56152,13 +56649,14 @@
5615256649
*/
5615356650
for(i=0; i<db->nDb; i++){
5615456651
Btree *pBt = db->aDb[i].pBt;
5615556652
if( sqlite3BtreeIsInTrans(pBt) ){
5615656653
char const *zFile = sqlite3BtreeGetJournalname(pBt);
56157
- if( zFile==0 || zFile[0]==0 ){
56654
+ if( zFile==0 ){
5615856655
continue; /* Ignore TEMP and :memory: databases */
5615956656
}
56657
+ assert( zFile[0]!=0 );
5616056658
if( !needSync && !sqlite3BtreeSyncDisabled(pBt) ){
5616156659
needSync = 1;
5616256660
}
5616356661
rc = sqlite3OsWrite(pMaster, zFile, sqlite3Strlen30(zFile)+1, offset);
5616456662
offset += sqlite3Strlen30(zFile)+1;
@@ -57618,10 +58116,12 @@
5761858116
** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16().
5761958117
*/
5762058118
SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt){
5762158119
int rc;
5762258120
if( pStmt==0 ){
58121
+ /* IMPLEMENTATION-OF: R-57228-12904 Invoking sqlite3_finalize() on a NULL
58122
+ ** pointer is a harmless no-op. */
5762358123
rc = SQLITE_OK;
5762458124
}else{
5762558125
Vdbe *v = (Vdbe*)pStmt;
5762658126
sqlite3 *db = v->db;
5762758127
#if SQLITE_THREADSAFE
@@ -57694,11 +58194,11 @@
5769458194
Mem *p = (Mem*)pVal;
5769558195
if( p->flags & (MEM_Blob|MEM_Str) ){
5769658196
sqlite3VdbeMemExpandBlob(p);
5769758197
p->flags &= ~MEM_Str;
5769858198
p->flags |= MEM_Blob;
57699
- return p->z;
58199
+ return p->n ? p->z : 0;
5770058200
}else{
5770158201
return sqlite3_value_text(pVal);
5770258202
}
5770358203
}
5770458204
SQLITE_API int sqlite3_value_bytes(sqlite3_value *pVal){
@@ -58048,10 +58548,16 @@
5804858548
}
5804958549
5805058550
/*
5805158551
** Extract the user data from a sqlite3_context structure and return a
5805258552
** pointer to it.
58553
+**
58554
+** IMPLEMENTATION-OF: R-46798-50301 The sqlite3_context_db_handle() interface
58555
+** returns a copy of the pointer to the database connection (the 1st
58556
+** parameter) of the sqlite3_create_function() and
58557
+** sqlite3_create_function16() routines that originally registered the
58558
+** application defined function.
5805358559
*/
5805458560
SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){
5805558561
assert( p && p->pFunc );
5805658562
return p->s.db;
5805758563
}
@@ -58257,12 +58763,11 @@
5825758763
** sqlite3_column_text()
5825858764
** sqlite3_column_text16()
5825958765
** sqlite3_column_real()
5826058766
** sqlite3_column_bytes()
5826158767
** sqlite3_column_bytes16()
58262
-**
58263
-** But not for sqlite3_column_blob(), which never calls malloc().
58768
+** sqiite3_column_blob()
5826458769
*/
5826558770
static void columnMallocFailure(sqlite3_stmt *pStmt)
5826658771
{
5826758772
/* If malloc() failed during an encoding conversion within an
5826858773
** sqlite3_column_XXX API, then set the return code of the statement to
@@ -58526,10 +59031,16 @@
5852659031
pVar->flags = MEM_Null;
5852759032
sqlite3Error(p->db, SQLITE_OK, 0);
5852859033
5852959034
/* If the bit corresponding to this variable in Vdbe.expmask is set, then
5853059035
** binding a new value to this variable invalidates the current query plan.
59036
+ **
59037
+ ** IMPLEMENTATION-OF: R-48440-37595 If the specific value bound to host
59038
+ ** parameter in the WHERE clause might influence the choice of query plan
59039
+ ** for a statement, then the statement will be automatically recompiled,
59040
+ ** as if there had been a schema change, on the first sqlite3_step() call
59041
+ ** following any change to the bindings of that parameter.
5853159042
*/
5853259043
if( p->isPrepareV2 &&
5853359044
((i<32 && p->expmask & ((u32)1 << i)) || p->expmask==0xffffffff)
5853459045
){
5853559046
p->expired = 1;
@@ -59023,10 +59534,21 @@
5902359534
** of the code in this file is, therefore, important. See other comments
5902459535
** in this file for details. If in doubt, do not deviate from existing
5902559536
** commenting and indentation practices when changing or adding code.
5902659537
*/
5902759538
59539
+/*
59540
+** Invoke this macro on memory cells just prior to changing the
59541
+** value of the cell. This macro verifies that shallow copies are
59542
+** not misused.
59543
+*/
59544
+#ifdef SQLITE_DEBUG
59545
+# define memAboutToChange(P,M) sqlite3VdbeMemPrepareToChange(P,M)
59546
+#else
59547
+# define memAboutToChange(P,M)
59548
+#endif
59549
+
5902859550
/*
5902959551
** The following global variable is incremented every time a cursor
5903059552
** moves, either by the OP_SeekXX, OP_Next, or OP_Prev opcodes. The test
5903159553
** procedures use this information to make sure that indices are
5903259554
** working correctly. This variable has no function other than to
@@ -59215,35 +59737,21 @@
5921559737
** looks like a number, convert it into a number. If it does not
5921659738
** look like a number, leave it alone.
5921759739
*/
5921859740
static void applyNumericAffinity(Mem *pRec){
5921959741
if( (pRec->flags & (MEM_Real|MEM_Int))==0 ){
59220
- int realnum;
59742
+ double rValue;
59743
+ i64 iValue;
5922159744
u8 enc = pRec->enc;
59222
- sqlite3VdbeMemNulTerminate(pRec);
59223
- if( (pRec->flags&MEM_Str) && sqlite3IsNumber(pRec->z, &realnum, enc) ){
59224
- i64 value;
59225
- char *zUtf8 = pRec->z;
59226
-#ifndef SQLITE_OMIT_UTF16
59227
- if( enc!=SQLITE_UTF8 ){
59228
- assert( pRec->db );
59229
- zUtf8 = sqlite3Utf16to8(pRec->db, pRec->z, pRec->n, enc);
59230
- if( !zUtf8 ) return;
59231
- }
59232
-#endif
59233
- if( !realnum && sqlite3Atoi64(zUtf8, &value) ){
59234
- pRec->u.i = value;
59235
- MemSetTypeFlag(pRec, MEM_Int);
59236
- }else{
59237
- sqlite3AtoF(zUtf8, &pRec->r);
59238
- MemSetTypeFlag(pRec, MEM_Real);
59239
- }
59240
-#ifndef SQLITE_OMIT_UTF16
59241
- if( enc!=SQLITE_UTF8 ){
59242
- sqlite3DbFree(pRec->db, zUtf8);
59243
- }
59244
-#endif
59745
+ if( (pRec->flags&MEM_Str)==0 ) return;
59746
+ if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return;
59747
+ if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
59748
+ pRec->u.i = iValue;
59749
+ pRec->flags |= MEM_Int;
59750
+ }else{
59751
+ pRec->r = rValue;
59752
+ pRec->flags |= MEM_Real;
5924559753
}
5924659754
}
5924759755
}
5924859756
5924959757
/*
@@ -60132,38 +60640,44 @@
6013260640
assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
6013360641
if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){
6013460642
assert( pOp->p2>0 );
6013560643
assert( pOp->p2<=p->nMem );
6013660644
pOut = &aMem[pOp->p2];
60645
+ memAboutToChange(p, pOut);
6013760646
sqlite3VdbeMemReleaseExternal(pOut);
6013860647
pOut->flags = MEM_Int;
6013960648
}
6014060649
6014160650
/* Sanity checking on other operands */
6014260651
#ifdef SQLITE_DEBUG
6014360652
if( (pOp->opflags & OPFLG_IN1)!=0 ){
6014460653
assert( pOp->p1>0 );
6014560654
assert( pOp->p1<=p->nMem );
60655
+ assert( memIsValid(&aMem[pOp->p1]) );
6014660656
REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
6014760657
}
6014860658
if( (pOp->opflags & OPFLG_IN2)!=0 ){
6014960659
assert( pOp->p2>0 );
6015060660
assert( pOp->p2<=p->nMem );
60661
+ assert( memIsValid(&aMem[pOp->p2]) );
6015160662
REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
6015260663
}
6015360664
if( (pOp->opflags & OPFLG_IN3)!=0 ){
6015460665
assert( pOp->p3>0 );
6015560666
assert( pOp->p3<=p->nMem );
60667
+ assert( memIsValid(&aMem[pOp->p3]) );
6015660668
REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
6015760669
}
6015860670
if( (pOp->opflags & OPFLG_OUT2)!=0 ){
6015960671
assert( pOp->p2>0 );
6016060672
assert( pOp->p2<=p->nMem );
60673
+ memAboutToChange(p, &aMem[pOp->p2]);
6016160674
}
6016260675
if( (pOp->opflags & OPFLG_OUT3)!=0 ){
6016360676
assert( pOp->p3>0 );
6016460677
assert( pOp->p3<=p->nMem );
60678
+ memAboutToChange(p, &aMem[pOp->p3]);
6016560679
}
6016660680
#endif
6016760681
6016860682
switch( pOp->opcode ){
6016960683
@@ -60221,10 +60735,11 @@
6022160735
** and then jump to address P2.
6022260736
*/
6022360737
case OP_Gosub: { /* jump, in1 */
6022460738
pIn1 = &aMem[pOp->p1];
6022560739
assert( (pIn1->flags & MEM_Dyn)==0 );
60740
+ memAboutToChange(p, pIn1);
6022660741
pIn1->flags = MEM_Int;
6022760742
pIn1->u.i = pc;
6022860743
REGISTER_TRACE(pOp->p1, pIn1);
6022960744
pc = pOp->p2 - 1;
6023060745
break;
@@ -60428,15 +60943,11 @@
6042860943
6042960944
6043060945
/* Opcode: Blob P1 P2 * P4
6043160946
**
6043260947
** P4 points to a blob of data P1 bytes long. Store this
60433
-** blob in register P2. This instruction is not coded directly
60434
-** by the compiler. Instead, the compiler layer specifies
60435
-** an OP_HexBlob opcode, with the hex string representation of
60436
-** the blob as P4. This opcode is transformed to an OP_Blob
60437
-** the first time it is executed.
60948
+** blob in register P2.
6043860949
*/
6043960950
case OP_Blob: { /* out2-prerelease */
6044060951
assert( pOp->p1 <= SQLITE_MAX_LENGTH );
6044160952
sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
6044260953
pOut->enc = encoding;
@@ -60490,10 +61001,12 @@
6049061001
pIn1 = &aMem[u.ac.p1];
6049161002
pOut = &aMem[u.ac.p2];
6049261003
while( u.ac.n-- ){
6049361004
assert( pOut<=&aMem[p->nMem] );
6049461005
assert( pIn1<=&aMem[p->nMem] );
61006
+ assert( memIsValid(pIn1) );
61007
+ memAboutToChange(p, pOut);
6049561008
u.ac.zMalloc = pOut->zMalloc;
6049661009
pOut->zMalloc = 0;
6049761010
sqlite3VdbeMemMove(pOut, pIn1);
6049861011
pIn1->zMalloc = u.ac.zMalloc;
6049961012
REGISTER_TRACE(u.ac.p2++, pOut);
@@ -60535,10 +61048,13 @@
6053561048
case OP_SCopy: { /* in1, out2 */
6053661049
pIn1 = &aMem[pOp->p1];
6053761050
pOut = &aMem[pOp->p2];
6053861051
assert( pOut!=pIn1 );
6053961052
sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
61053
+#ifdef SQLITE_DEBUG
61054
+ if( pOut->pScopyFrom==0 ) pOut->pScopyFrom = pIn1;
61055
+#endif
6054061056
REGISTER_TRACE(pOp->p2, pOut);
6054161057
break;
6054261058
}
6054361059
6054461060
/* Opcode: ResultRow P1 P2 * * *
@@ -60595,10 +61111,14 @@
6059561111
** and have an assigned type. The results are de-ephemeralized as
6059661112
** as side effect.
6059761113
*/
6059861114
u.ad.pMem = p->pResultSet = &aMem[pOp->p1];
6059961115
for(u.ad.i=0; u.ad.i<pOp->p2; u.ad.i++){
61116
+ assert( memIsValid(&u.ad.pMem[u.ad.i]) );
61117
+ Deephemeralize(&u.ad.pMem[u.ad.i]);
61118
+ assert( (u.ad.pMem[u.ad.i].flags & MEM_Ephem)==0
61119
+ || (u.ad.pMem[u.ad.i].flags & (MEM_Str|MEM_Blob))==0 );
6060061120
sqlite3VdbeMemNulTerminate(&u.ad.pMem[u.ad.i]);
6060161121
sqlite3VdbeMemStoreType(&u.ad.pMem[u.ad.i]);
6060261122
REGISTER_TRACE(pOp->p1+u.ad.i, &u.ad.pMem[u.ad.i]);
6060361123
}
6060461124
if( db->mallocFailed ) goto no_mem;
@@ -60826,16 +61346,21 @@
6082661346
#endif /* local variables moved into u.ag */
6082761347
6082861348
u.ag.n = pOp->p5;
6082961349
u.ag.apVal = p->apArg;
6083061350
assert( u.ag.apVal || u.ag.n==0 );
61351
+ assert( pOp->p3>0 && pOp->p3<=p->nMem );
61352
+ pOut = &aMem[pOp->p3];
61353
+ memAboutToChange(p, pOut);
6083161354
6083261355
assert( u.ag.n==0 || (pOp->p2>0 && pOp->p2+u.ag.n<=p->nMem+1) );
6083361356
assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.ag.n );
6083461357
u.ag.pArg = &aMem[pOp->p2];
6083561358
for(u.ag.i=0; u.ag.i<u.ag.n; u.ag.i++, u.ag.pArg++){
61359
+ assert( memIsValid(u.ag.pArg) );
6083661360
u.ag.apVal[u.ag.i] = u.ag.pArg;
61361
+ Deephemeralize(u.ag.pArg);
6083761362
sqlite3VdbeMemStoreType(u.ag.pArg);
6083861363
REGISTER_TRACE(pOp->p2+u.ag.i, u.ag.pArg);
6083961364
}
6084061365
6084161366
assert( pOp->p4type==P4_FUNCDEF || pOp->p4type==P4_VDBEFUNC );
@@ -60845,12 +61370,10 @@
6084561370
}else{
6084661371
u.ag.ctx.pVdbeFunc = (VdbeFunc*)pOp->p4.pVdbeFunc;
6084761372
u.ag.ctx.pFunc = u.ag.ctx.pVdbeFunc->pFunc;
6084861373
}
6084961374
60850
- assert( pOp->p3>0 && pOp->p3<=p->nMem );
60851
- pOut = &aMem[pOp->p3];
6085261375
u.ag.ctx.s.flags = MEM_Null;
6085361376
u.ag.ctx.s.db = db;
6085461377
u.ag.ctx.s.xDel = 0;
6085561378
u.ag.ctx.s.zMalloc = 0;
6085661379
@@ -60866,11 +61389,11 @@
6086661389
assert( pOp>aOp );
6086761390
assert( pOp[-1].p4type==P4_COLLSEQ );
6086861391
assert( pOp[-1].opcode==OP_CollSeq );
6086961392
u.ag.ctx.pColl = pOp[-1].p4.pColl;
6087061393
}
60871
- (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal);
61394
+ (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */
6087261395
if( db->mallocFailed ){
6087361396
/* Even though a malloc() has failed, the implementation of the
6087461397
** user function may have called an sqlite3_result_XXX() function
6087561398
** to return a value. The following call releases any resources
6087661399
** associated with such a value.
@@ -60918,11 +61441,11 @@
6091861441
** If either input is NULL, the result is NULL.
6091961442
*/
6092061443
/* Opcode: ShiftLeft P1 P2 P3 * *
6092161444
**
6092261445
** Shift the integer value in register P2 to the left by the
60923
-** number of bits specified by the integer in regiser P1.
61446
+** number of bits specified by the integer in register P1.
6092461447
** Store the result in register P3.
6092561448
** If either input is NULL, the result is NULL.
6092661449
*/
6092761450
/* Opcode: ShiftRight P1 P2 P3 * *
6092861451
**
@@ -60968,10 +61491,11 @@
6096861491
**
6096961492
** To force any register to be an integer, just add 0.
6097061493
*/
6097161494
case OP_AddImm: { /* in1 */
6097261495
pIn1 = &aMem[pOp->p1];
61496
+ memAboutToChange(p, pIn1);
6097361497
sqlite3VdbeMemIntegerify(pIn1);
6097461498
pIn1->u.i += pOp->p2;
6097561499
break;
6097661500
}
6097761501
@@ -60982,10 +61506,11 @@
6098261506
** without data loss, then jump immediately to P2, or if P2==0
6098361507
** raise an SQLITE_MISMATCH exception.
6098461508
*/
6098561509
case OP_MustBeInt: { /* jump, in1 */
6098661510
pIn1 = &aMem[pOp->p1];
61511
+ memAboutToChange(p, pIn1);
6098761512
applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
6098861513
if( (pIn1->flags & MEM_Int)==0 ){
6098961514
if( pOp->p2==0 ){
6099061515
rc = SQLITE_MISMATCH;
6099161516
goto abort_due_to_error;
@@ -61027,10 +61552,11 @@
6102761552
**
6102861553
** A NULL value is not changed by this routine. It remains NULL.
6102961554
*/
6103061555
case OP_ToText: { /* same as TK_TO_TEXT, in1 */
6103161556
pIn1 = &aMem[pOp->p1];
61557
+ memAboutToChange(p, pIn1);
6103261558
if( pIn1->flags & MEM_Null ) break;
6103361559
assert( MEM_Str==(MEM_Blob>>3) );
6103461560
pIn1->flags |= (pIn1->flags&MEM_Blob)>>3;
6103561561
applyAffinity(pIn1, SQLITE_AFF_TEXT, encoding);
6103661562
rc = ExpandBlob(pIn1);
@@ -61073,20 +61599,18 @@
6107361599
**
6107461600
** A NULL value is not changed by this routine. It remains NULL.
6107561601
*/
6107661602
case OP_ToNumeric: { /* same as TK_TO_NUMERIC, in1 */
6107761603
pIn1 = &aMem[pOp->p1];
61078
- if( (pIn1->flags & (MEM_Null|MEM_Int|MEM_Real))==0 ){
61079
- sqlite3VdbeMemNumerify(pIn1);
61080
- }
61604
+ sqlite3VdbeMemNumerify(pIn1);
6108161605
break;
6108261606
}
6108361607
#endif /* SQLITE_OMIT_CAST */
6108461608
6108561609
/* Opcode: ToInt P1 * * * *
6108661610
**
61087
-** Force the value in register P1 be an integer. If
61611
+** Force the value in register P1 to be an integer. If
6108861612
** The value is currently a real number, drop its fractional part.
6108961613
** If the value is text or blob, try to convert it to an integer using the
6109061614
** equivalent of atoi() and store 0 if no such conversion is possible.
6109161615
**
6109261616
** A NULL value is not changed by this routine. It remains NULL.
@@ -61109,10 +61633,11 @@
6110961633
**
6111061634
** A NULL value is not changed by this routine. It remains NULL.
6111161635
*/
6111261636
case OP_ToReal: { /* same as TK_TO_REAL, in1 */
6111361637
pIn1 = &aMem[pOp->p1];
61638
+ memAboutToChange(p, pIn1);
6111461639
if( (pIn1->flags & MEM_Null)==0 ){
6111561640
sqlite3VdbeMemRealify(pIn1);
6111661641
}
6111761642
break;
6111861643
}
@@ -61123,11 +61648,11 @@
6112361648
** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
6112461649
** jump to address P2.
6112561650
**
6112661651
** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
6112761652
** reg(P3) is NULL then take the jump. If the SQLITE_JUMPIFNULL
61128
-** bit is clear then fall thru if either operand is NULL.
61653
+** bit is clear then fall through if either operand is NULL.
6112961654
**
6113061655
** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
6113161656
** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
6113261657
** to coerce both inputs according to this affinity before the
6113361658
** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
@@ -61253,10 +61778,11 @@
6125361778
default: u.ai.res = u.ai.res>=0; break;
6125461779
}
6125561780
6125661781
if( pOp->p5 & SQLITE_STOREP2 ){
6125761782
pOut = &aMem[pOp->p2];
61783
+ memAboutToChange(p, pOut);
6125861784
MemSetTypeFlag(pOut, MEM_Int);
6125961785
pOut->u.i = u.ai.res;
6126061786
REGISTER_TRACE(pOp->p2, pOut);
6126161787
}else if( u.ai.res ){
6126261788
pc = pOp->p2-1;
@@ -61284,12 +61810,12 @@
6128461810
break;
6128561811
}
6128661812
6128761813
/* Opcode: Compare P1 P2 P3 P4 *
6128861814
**
61289
-** Compare to vectors of registers in reg(P1)..reg(P1+P3-1) (all this
61290
-** one "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of
61815
+** Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this
61816
+** vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of
6129161817
** the comparison for use by the next OP_Jump instruct.
6129261818
**
6129361819
** P4 is a KeyInfo structure that defines collating sequences and sort
6129461820
** orders for the comparison. The permutation applies to registers
6129561821
** only. The KeyInfo elements are used sequentially.
@@ -61327,10 +61853,12 @@
6132761853
assert( u.aj.p2>0 && u.aj.p2+u.aj.n<=p->nMem+1 );
6132861854
}
6132961855
#endif /* SQLITE_DEBUG */
6133061856
for(u.aj.i=0; u.aj.i<u.aj.n; u.aj.i++){
6133161857
u.aj.idx = aPermute ? aPermute[u.aj.i] : u.aj.i;
61858
+ assert( memIsValid(&aMem[u.aj.p1+u.aj.idx]) );
61859
+ assert( memIsValid(&aMem[u.aj.p2+u.aj.idx]) );
6133261860
REGISTER_TRACE(u.aj.p1+u.aj.idx, &aMem[u.aj.p1+u.aj.idx]);
6133361861
REGISTER_TRACE(u.aj.p2+u.aj.idx, &aMem[u.aj.p2+u.aj.idx]);
6133461862
assert( u.aj.i<u.aj.pKeyInfo->nField );
6133561863
u.aj.pColl = u.aj.pKeyInfo->aColl[u.aj.i];
6133661864
u.aj.bRev = u.aj.pKeyInfo->aSortOrder[u.aj.i];
@@ -61558,10 +62086,11 @@
6155862086
u.am.pC = 0;
6155962087
memset(&u.am.sMem, 0, sizeof(u.am.sMem));
6156062088
assert( u.am.p1<p->nCursor );
6156162089
assert( pOp->p3>0 && pOp->p3<=p->nMem );
6156262090
u.am.pDest = &aMem[pOp->p3];
62091
+ memAboutToChange(p, u.am.pDest);
6156362092
MemSetTypeFlag(u.am.pDest, MEM_Null);
6156462093
u.am.zRec = 0;
6156562094
6156662095
/* This block sets the variable u.am.payloadSize to be the total number of
6156762096
** bytes in the record.
@@ -61605,10 +62134,11 @@
6160562134
assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
6160662135
}
6160762136
}else if( u.am.pC->pseudoTableReg>0 ){
6160862137
u.am.pReg = &aMem[u.am.pC->pseudoTableReg];
6160962138
assert( u.am.pReg->flags & MEM_Blob );
62139
+ assert( memIsValid(u.am.pReg) );
6161062140
u.am.payloadSize = u.am.pReg->n;
6161162141
u.am.zRec = u.am.pReg->z;
6161262142
u.am.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr;
6161362143
assert( u.am.payloadSize==0 || u.am.zRec!=0 );
6161462144
}else{
@@ -61829,25 +62359,23 @@
6182962359
assert( u.an.zAffinity!=0 );
6183062360
assert( u.an.zAffinity[pOp->p2]==0 );
6183162361
pIn1 = &aMem[pOp->p1];
6183262362
while( (u.an.cAff = *(u.an.zAffinity++))!=0 ){
6183362363
assert( pIn1 <= &p->aMem[p->nMem] );
62364
+ assert( memIsValid(pIn1) );
6183462365
ExpandBlob(pIn1);
6183562366
applyAffinity(pIn1, u.an.cAff, encoding);
6183662367
pIn1++;
6183762368
}
6183862369
break;
6183962370
}
6184062371
6184162372
/* Opcode: MakeRecord P1 P2 P3 P4 *
6184262373
**
61843
-** Convert P2 registers beginning with P1 into a single entry
61844
-** suitable for use as a data record in a database table or as a key
61845
-** in an index. The details of the format are irrelevant as long as
61846
-** the OP_Column opcode can decode the record later.
61847
-** Refer to source code comments for the details of the record
61848
-** format.
62374
+** Convert P2 registers beginning with P1 into the [record format]
62375
+** use as a data record in a database table or as a key
62376
+** in an index. The OP_Column opcode can decode the record later.
6184962377
**
6185062378
** P4 may be a string that is P2 characters long. The nth character of the
6185162379
** string indicates the column affinity that should be used for the nth
6185262380
** field of the index key.
6185362381
**
@@ -61899,15 +62427,21 @@
6189962427
assert( u.ao.nField>0 && pOp->p2>0 && pOp->p2+u.ao.nField<=p->nMem+1 );
6190062428
u.ao.pData0 = &aMem[u.ao.nField];
6190162429
u.ao.nField = pOp->p2;
6190262430
u.ao.pLast = &u.ao.pData0[u.ao.nField-1];
6190362431
u.ao.file_format = p->minWriteFileFormat;
62432
+
62433
+ /* Identify the output register */
62434
+ assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
62435
+ pOut = &aMem[pOp->p3];
62436
+ memAboutToChange(p, pOut);
6190462437
6190562438
/* Loop through the elements that will make up the record to figure
6190662439
** out how much space is required for the new record.
6190762440
*/
6190862441
for(u.ao.pRec=u.ao.pData0; u.ao.pRec<=u.ao.pLast; u.ao.pRec++){
62442
+ assert( memIsValid(u.ao.pRec) );
6190962443
if( u.ao.zAffinity ){
6191062444
applyAffinity(u.ao.pRec, u.ao.zAffinity[u.ao.pRec-u.ao.pData0], encoding);
6191162445
}
6191262446
if( u.ao.pRec->flags&MEM_Zero && u.ao.pRec->n>0 ){
6191362447
sqlite3VdbeMemExpandBlob(u.ao.pRec);
@@ -61938,12 +62472,10 @@
6193862472
/* Make sure the output register has a buffer large enough to store
6193962473
** the new record. The output register (pOp->p3) is not allowed to
6194062474
** be one of the input registers (because the following call to
6194162475
** sqlite3VdbeMemGrow() could clobber the value before it is used).
6194262476
*/
61943
- assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
61944
- pOut = &aMem[pOp->p3];
6194562477
if( sqlite3VdbeMemGrow(pOut, (int)u.ao.nByte, 0) ){
6194662478
goto no_mem;
6194762479
}
6194862480
u.ao.zNewRecord = (u8 *)pOut->z;
6194962481
@@ -62112,10 +62644,11 @@
6211262644
}
6211362645
}
6211462646
if( u.aq.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
6211562647
sqlite3ExpirePreparedStatements(db);
6211662648
sqlite3ResetInternalSchema(db, 0);
62649
+ db->flags = (db->flags | SQLITE_InternChanges);
6211762650
}
6211862651
}
6211962652
6212062653
/* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
6212162654
** savepoints nested inside of the savepoint being operated on. */
@@ -62502,10 +63035,12 @@
6250263035
}
6250363036
if( pOp->p5 ){
6250463037
assert( u.aw.p2>0 );
6250563038
assert( u.aw.p2<=p->nMem );
6250663039
pIn2 = &aMem[u.aw.p2];
63040
+ assert( memIsValid(pIn2) );
63041
+ assert( (pIn2->flags & MEM_Int)!=0 );
6250763042
sqlite3VdbeMemIntegerify(pIn2);
6250863043
u.aw.p2 = (int)pIn2->u.i;
6250963044
/* The u.aw.p2 value always comes from a prior OP_CreateTable opcode and
6251063045
** that opcode will always set the u.aw.p2 value to 2 or more or else fail.
6251163046
** If there were a failure, the prepared statement would have halted
@@ -62524,10 +63059,11 @@
6252463059
}
6252563060
assert( pOp->p1>=0 );
6252663061
u.aw.pCur = allocateCursor(p, pOp->p1, u.aw.nField, u.aw.iDb, 1);
6252763062
if( u.aw.pCur==0 ) goto no_mem;
6252863063
u.aw.pCur->nullRow = 1;
63064
+ u.aw.pCur->isOrdered = 1;
6252963065
rc = sqlite3BtreeCursor(u.aw.pX, u.aw.p2, u.aw.wrFlag, u.aw.pKeyInfo, u.aw.pCur->pCursor);
6253063066
u.aw.pCur->pKeyInfo = u.aw.pKeyInfo;
6253163067
6253263068
/* Since it performs no memory allocation or IO, the only values that
6253363069
** sqlite3BtreeCursor() may return are SQLITE_EMPTY and SQLITE_OK.
@@ -62576,11 +63112,11 @@
6257663112
case OP_OpenAutoindex:
6257763113
case OP_OpenEphemeral: {
6257863114
#if 0 /* local variables moved into u.ax */
6257963115
VdbeCursor *pCx;
6258063116
#endif /* local variables moved into u.ax */
62581
- static const int openFlags =
63117
+ static const int vfsFlags =
6258263118
SQLITE_OPEN_READWRITE |
6258363119
SQLITE_OPEN_CREATE |
6258463120
SQLITE_OPEN_EXCLUSIVE |
6258563121
SQLITE_OPEN_DELETEONCLOSE |
6258663122
SQLITE_OPEN_TRANSIENT_DB;
@@ -62587,25 +63123,25 @@
6258763123
6258863124
assert( pOp->p1>=0 );
6258963125
u.ax.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
6259063126
if( u.ax.pCx==0 ) goto no_mem;
6259163127
u.ax.pCx->nullRow = 1;
62592
- rc = sqlite3BtreeFactory(db, 0, 1, SQLITE_DEFAULT_TEMP_CACHE_SIZE, openFlags,
62593
- &u.ax.pCx->pBt);
63128
+ rc = sqlite3BtreeOpen(0, db, &u.ax.pCx->pBt,
63129
+ BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
6259463130
if( rc==SQLITE_OK ){
6259563131
rc = sqlite3BtreeBeginTrans(u.ax.pCx->pBt, 1);
6259663132
}
6259763133
if( rc==SQLITE_OK ){
6259863134
/* If a transient index is required, create it by calling
62599
- ** sqlite3BtreeCreateTable() with the BTREE_ZERODATA flag before
63135
+ ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
6260063136
** opening it. If a transient table is required, just use the
62601
- ** automatically created table with root-page 1 (an INTKEY table).
63137
+ ** automatically created table with root-page 1 (an BLOB_INTKEY table).
6260263138
*/
6260363139
if( pOp->p4.pKeyInfo ){
6260463140
int pgno;
6260563141
assert( pOp->p4type==P4_KEYINFO );
62606
- rc = sqlite3BtreeCreateTable(u.ax.pCx->pBt, &pgno, BTREE_ZERODATA);
63142
+ rc = sqlite3BtreeCreateTable(u.ax.pCx->pBt, &pgno, BTREE_BLOBKEY);
6260763143
if( rc==SQLITE_OK ){
6260863144
assert( pgno==MASTER_ROOT+1 );
6260963145
rc = sqlite3BtreeCursor(u.ax.pCx->pBt, pgno, 1,
6261063146
(KeyInfo*)pOp->p4.z, u.ax.pCx->pCursor);
6261163147
u.ax.pCx->pKeyInfo = pOp->p4.pKeyInfo;
@@ -62615,10 +63151,11 @@
6261563151
}else{
6261663152
rc = sqlite3BtreeCursor(u.ax.pCx->pBt, MASTER_ROOT, 1, 0, u.ax.pCx->pCursor);
6261763153
u.ax.pCx->isTable = 1;
6261863154
}
6261963155
}
63156
+ u.ax.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
6262063157
u.ax.pCx->isIndex = !u.ax.pCx->isTable;
6262163158
break;
6262263159
}
6262363160
6262463161
/* Opcode: OpenPseudo P1 P2 P3 * *
@@ -62734,10 +63271,11 @@
6273463271
assert( u.az.pC!=0 );
6273563272
assert( u.az.pC->pseudoTableReg==0 );
6273663273
assert( OP_SeekLe == OP_SeekLt+1 );
6273763274
assert( OP_SeekGe == OP_SeekLt+2 );
6273863275
assert( OP_SeekGt == OP_SeekLt+3 );
63276
+ assert( u.az.pC->isOrdered );
6273963277
if( u.az.pC->pCursor!=0 ){
6274063278
u.az.oc = pOp->opcode;
6274163279
u.az.pC->nullRow = 0;
6274263280
if( u.az.pC->isTable ){
6274363281
/* The input value in P3 might be of any type: integer, real, string,
@@ -62816,10 +63354,13 @@
6281663354
assert( u.az.oc!=OP_SeekLe || u.az.r.flags==UNPACKED_INCRKEY );
6281763355
assert( u.az.oc!=OP_SeekGe || u.az.r.flags==0 );
6281863356
assert( u.az.oc!=OP_SeekLt || u.az.r.flags==0 );
6281963357
6282063358
u.az.r.aMem = &aMem[pOp->p3];
63359
+#ifdef SQLITE_DEBUG
63360
+ { int i; for(i=0; i<u.az.r.nField; i++) assert( memIsValid(&u.az.r.aMem[i]) ); }
63361
+#endif
6282163362
ExpandBlob(u.az.r.aMem);
6282263363
rc = sqlite3BtreeMovetoUnpacked(u.az.pC->pCursor, &u.az.r, 0, 0, &u.az.res);
6282363364
if( rc!=SQLITE_OK ){
6282463365
goto abort_due_to_error;
6282563366
}
@@ -62944,15 +63485,18 @@
6294463485
assert( u.bb.pC->isTable==0 );
6294563486
if( pOp->p4.i>0 ){
6294663487
u.bb.r.pKeyInfo = u.bb.pC->pKeyInfo;
6294763488
u.bb.r.nField = (u16)pOp->p4.i;
6294863489
u.bb.r.aMem = pIn3;
63490
+#ifdef SQLITE_DEBUG
63491
+ { int i; for(i=0; i<u.bb.r.nField; i++) assert( memIsValid(&u.bb.r.aMem[i]) ); }
63492
+#endif
6294963493
u.bb.r.flags = UNPACKED_PREFIX_MATCH;
6295063494
u.bb.pIdxKey = &u.bb.r;
6295163495
}else{
6295263496
assert( pIn3->flags & MEM_Blob );
62953
- ExpandBlob(pIn3);
63497
+ assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
6295463498
u.bb.pIdxKey = sqlite3VdbeRecordUnpack(u.bb.pC->pKeyInfo, pIn3->n, pIn3->z,
6295563499
u.bb.aTempRec, sizeof(u.bb.aTempRec));
6295663500
if( u.bb.pIdxKey==0 ){
6295763501
goto no_mem;
6295863502
}
@@ -63043,10 +63587,13 @@
6304363587
/* Populate the index search key. */
6304463588
u.bc.r.pKeyInfo = u.bc.pCx->pKeyInfo;
6304563589
u.bc.r.nField = u.bc.nField + 1;
6304663590
u.bc.r.flags = UNPACKED_PREFIX_SEARCH;
6304763591
u.bc.r.aMem = u.bc.aMx;
63592
+#ifdef SQLITE_DEBUG
63593
+ { int i; for(i=0; i<u.bc.r.nField; i++) assert( memIsValid(&u.bc.r.aMem[i]) ); }
63594
+#endif
6304863595
6304963596
/* Extract the value of u.bc.R from register P3. */
6305063597
sqlite3VdbeMemIntegerify(pIn3);
6305163598
u.bc.R = pIn3->u.i;
6305263599
@@ -63065,11 +63612,11 @@
6306563612
6306663613
/* Opcode: NotExists P1 P2 P3 * *
6306763614
**
6306863615
** Use the content of register P3 as a integer key. If a record
6306963616
** with that key does not exist in table of P1, then jump to P2.
63070
-** If the record does exist, then fall thru. The cursor is left
63617
+** If the record does exist, then fall through. The cursor is left
6307163618
** pointing to the record if it exists.
6307263619
**
6307363620
** The difference between this operation and NotFound is that this
6307463621
** operation assumes the key is an integer and that P1 is a table whereas
6307563622
** NotFound assumes key is a blob constructed from MakeRecord and
@@ -63223,11 +63770,13 @@
6322363770
u.be.pMem = &u.be.pFrame->aMem[pOp->p3];
6322463771
}else{
6322563772
/* Assert that P3 is a valid memory cell. */
6322663773
assert( pOp->p3<=p->nMem );
6322763774
u.be.pMem = &aMem[pOp->p3];
63775
+ memAboutToChange(p, u.be.pMem);
6322863776
}
63777
+ assert( memIsValid(u.be.pMem) );
6322963778
6323063779
REGISTER_TRACE(pOp->p3, u.be.pMem);
6323163780
sqlite3VdbeMemIntegerify(u.be.pMem);
6323263781
assert( (u.be.pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
6323363782
if( u.be.pMem->u.i==MAX_ROWID || u.be.pC->useRandomRowid ){
@@ -63242,33 +63791,40 @@
6324263791
#endif
6324363792
6324463793
sqlite3BtreeSetCachedRowid(u.be.pC->pCursor, u.be.v<MAX_ROWID ? u.be.v+1 : 0);
6324563794
}
6324663795
if( u.be.pC->useRandomRowid ){
63247
- /* IMPLEMENTATION-OF: R-48598-02938 If the largest ROWID is equal to the
63796
+ /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
6324863797
** largest possible integer (9223372036854775807) then the database
63249
- ** engine starts picking candidate ROWIDs at random until it finds one
63250
- ** that is not previously used.
63251
- */
63798
+ ** engine starts picking positive candidate ROWIDs at random until
63799
+ ** it finds one that is not previously used. */
6325263800
assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
6325363801
** an AUTOINCREMENT table. */
63802
+ /* on the first attempt, simply do one more than previous */
6325463803
u.be.v = db->lastRowid;
63804
+ u.be.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
63805
+ u.be.v++; /* ensure non-zero */
6325563806
u.be.cnt = 0;
63256
- do{
63257
- if( u.be.cnt==0 && (u.be.v&0xffffff)==u.be.v ){
63258
- u.be.v++;
63807
+ while( ((rc = sqlite3BtreeMovetoUnpacked(u.be.pC->pCursor, 0, (u64)u.be.v,
63808
+ 0, &u.be.res))==SQLITE_OK)
63809
+ && (u.be.res==0)
63810
+ && (++u.be.cnt<100)){
63811
+ /* collision - try another random rowid */
63812
+ sqlite3_randomness(sizeof(u.be.v), &u.be.v);
63813
+ if( u.be.cnt<5 ){
63814
+ /* try "small" random rowids for the initial attempts */
63815
+ u.be.v &= 0xffffff;
6325963816
}else{
63260
- sqlite3_randomness(sizeof(u.be.v), &u.be.v);
63261
- if( u.be.cnt<5 ) u.be.v &= 0xffffff;
63817
+ u.be.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
6326263818
}
63263
- rc = sqlite3BtreeMovetoUnpacked(u.be.pC->pCursor, 0, (u64)u.be.v, 0, &u.be.res);
63264
- u.be.cnt++;
63265
- }while( u.be.cnt<100 && rc==SQLITE_OK && u.be.res==0 );
63819
+ u.be.v++; /* ensure non-zero */
63820
+ }
6326663821
if( rc==SQLITE_OK && u.be.res==0 ){
6326763822
rc = SQLITE_FULL; /* IMP: R-38219-53002 */
6326863823
goto abort_due_to_error;
6326963824
}
63825
+ assert( u.be.v>0 ); /* EV: R-40812-03570 */
6327063826
}
6327163827
u.be.pC->rowidIsValid = 0;
6327263828
u.be.pC->deferredMoveto = 0;
6327363829
u.be.pC->cacheStatus = CACHE_STALE;
6327463830
}
@@ -63334,10 +63890,11 @@
6333463890
int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
6333563891
#endif /* local variables moved into u.bf */
6333663892
6333763893
u.bf.pData = &aMem[pOp->p2];
6333863894
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
63895
+ assert( memIsValid(u.bf.pData) );
6333963896
u.bf.pC = p->apCsr[pOp->p1];
6334063897
assert( u.bf.pC!=0 );
6334163898
assert( u.bf.pC->pCursor!=0 );
6334263899
assert( u.bf.pC->pseudoTableReg==0 );
6334363900
assert( u.bf.pC->isTable );
@@ -63344,10 +63901,11 @@
6334463901
REGISTER_TRACE(pOp->p2, u.bf.pData);
6334563902
6334663903
if( pOp->opcode==OP_Insert ){
6334763904
u.bf.pKey = &aMem[pOp->p3];
6334863905
assert( u.bf.pKey->flags & MEM_Int );
63906
+ assert( memIsValid(u.bf.pKey) );
6334963907
REGISTER_TRACE(pOp->p3, u.bf.pKey);
6335063908
u.bf.iKey = u.bf.pKey->u.i;
6335163909
}else{
6335263910
assert( pOp->opcode==OP_InsertInt );
6335363911
u.bf.iKey = pOp->p3;
@@ -63495,10 +64053,11 @@
6349564053
u32 n;
6349664054
i64 n64;
6349764055
#endif /* local variables moved into u.bh */
6349864056
6349964057
pOut = &aMem[pOp->p2];
64058
+ memAboutToChange(p, pOut);
6350064059
6350164060
/* Note that RowKey and RowData are really exactly the same instruction */
6350264061
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
6350364062
u.bh.pC = p->apCsr[pOp->p1];
6350464063
assert( u.bh.pC->isTable || pOp->opcode==OP_RowKey );
@@ -63837,10 +64396,13 @@
6383764396
if( ALWAYS(u.bo.pCrsr!=0) ){
6383864397
u.bo.r.pKeyInfo = u.bo.pC->pKeyInfo;
6383964398
u.bo.r.nField = (u16)pOp->p3;
6384064399
u.bo.r.flags = 0;
6384164400
u.bo.r.aMem = &aMem[pOp->p2];
64401
+#ifdef SQLITE_DEBUG
64402
+ { int i; for(i=0; i<u.bo.r.nField; i++) assert( memIsValid(&u.bo.r.aMem[i]) ); }
64403
+#endif
6384264404
rc = sqlite3BtreeMovetoUnpacked(u.bo.pCrsr, &u.bo.r, 0, 0, &u.bo.res);
6384364405
if( rc==SQLITE_OK && u.bo.res==0 ){
6384464406
rc = sqlite3BtreeDelete(u.bo.pCrsr);
6384564407
}
6384664408
assert( u.bo.pC->deferredMoveto==0 );
@@ -63921,10 +64483,11 @@
6392164483
#endif /* local variables moved into u.bq */
6392264484
6392364485
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
6392464486
u.bq.pC = p->apCsr[pOp->p1];
6392564487
assert( u.bq.pC!=0 );
64488
+ assert( u.bq.pC->isOrdered );
6392664489
if( ALWAYS(u.bq.pC->pCursor!=0) ){
6392764490
assert( u.bq.pC->deferredMoveto==0 );
6392864491
assert( pOp->p5==0 || pOp->p5==1 );
6392964492
assert( pOp->p4type==P4_INT32 );
6393064493
u.bq.r.pKeyInfo = u.bq.pC->pKeyInfo;
@@ -63933,10 +64496,13 @@
6393364496
u.bq.r.flags = UNPACKED_INCRKEY | UNPACKED_IGNORE_ROWID;
6393464497
}else{
6393564498
u.bq.r.flags = UNPACKED_IGNORE_ROWID;
6393664499
}
6393764500
u.bq.r.aMem = &aMem[pOp->p3];
64501
+#ifdef SQLITE_DEBUG
64502
+ { int i; for(i=0; i<u.bq.r.nField; i++) assert( memIsValid(&u.bq.r.aMem[i]) ); }
64503
+#endif
6393864504
rc = sqlite3VdbeIdxKeyCompare(u.bq.pC, &u.bq.r, &u.bq.res);
6393964505
if( pOp->opcode==OP_IdxLT ){
6394064506
u.bq.res = -u.bq.res;
6394164507
}else{
6394264508
assert( pOp->opcode==OP_IdxGE );
@@ -64036,10 +64602,12 @@
6403664602
db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bs.nChange : 0)
6403764603
);
6403864604
if( pOp->p3 ){
6403964605
p->nChange += u.bs.nChange;
6404064606
if( pOp->p3>0 ){
64607
+ assert( memIsValid(&aMem[pOp->p3]) );
64608
+ memAboutToChange(p, &aMem[pOp->p3]);
6404164609
aMem[pOp->p3].u.i += u.bs.nChange;
6404264610
}
6404364611
}
6404464612
break;
6404564613
}
@@ -64079,13 +64647,13 @@
6407964647
assert( (p->btreeMask & (1<<pOp->p1))!=0 );
6408064648
u.bt.pDb = &db->aDb[pOp->p1];
6408164649
assert( u.bt.pDb->pBt!=0 );
6408264650
if( pOp->opcode==OP_CreateTable ){
6408364651
/* u.bt.flags = BTREE_INTKEY; */
64084
- u.bt.flags = BTREE_LEAFDATA|BTREE_INTKEY;
64652
+ u.bt.flags = BTREE_INTKEY;
6408564653
}else{
64086
- u.bt.flags = BTREE_ZERODATA;
64654
+ u.bt.flags = BTREE_BLOBKEY;
6408764655
}
6408864656
rc = sqlite3BtreeCreateTable(u.bt.pDb->pBt, &u.bt.pgno, u.bt.flags);
6408964657
pOut->u.i = u.bt.pgno;
6409064658
break;
6409164659
}
@@ -64410,10 +64978,11 @@
6441064978
void *t; /* Token identifying trigger */
6441164979
#endif /* local variables moved into u.by */
6441264980
6441364981
u.by.pProgram = pOp->p4.pProgram;
6441464982
u.by.pRt = &aMem[pOp->p3];
64983
+ assert( memIsValid(u.by.pRt) );
6441564984
assert( u.by.pProgram->nOp>0 );
6441664985
6441764986
/* If the p5 flag is clear, then recursive invocation of triggers is
6441864987
** disabled for backwards compatibility (p5 is set if this sub-program
6441964988
** is really a trigger, not a foreign key action, and the flag set
@@ -64583,10 +65152,11 @@
6458365152
for(u.ca.pFrame=p->pFrame; u.ca.pFrame->pParent; u.ca.pFrame=u.ca.pFrame->pParent);
6458465153
u.ca.pIn1 = &u.ca.pFrame->aMem[pOp->p1];
6458565154
}else{
6458665155
u.ca.pIn1 = &aMem[pOp->p1];
6458765156
}
65157
+ assert( memIsValid(u.ca.pIn1) );
6458865158
sqlite3VdbeMemIntegerify(u.ca.pIn1);
6458965159
pIn2 = &aMem[pOp->p2];
6459065160
sqlite3VdbeMemIntegerify(pIn2);
6459165161
if( u.ca.pIn1->u.i<pIn2->u.i){
6459265162
u.ca.pIn1->u.i = pIn2->u.i;
@@ -64669,11 +65239,13 @@
6466965239
assert( u.cb.n>=0 );
6467065240
u.cb.pRec = &aMem[pOp->p2];
6467165241
u.cb.apVal = p->apArg;
6467265242
assert( u.cb.apVal || u.cb.n==0 );
6467365243
for(u.cb.i=0; u.cb.i<u.cb.n; u.cb.i++, u.cb.pRec++){
65244
+ assert( memIsValid(u.cb.pRec) );
6467465245
u.cb.apVal[u.cb.i] = u.cb.pRec;
65246
+ memAboutToChange(p, u.cb.pRec);
6467565247
sqlite3VdbeMemStoreType(u.cb.pRec);
6467665248
}
6467765249
u.cb.ctx.pFunc = pOp->p4.pFunc;
6467865250
assert( pOp->p3>0 && pOp->p3<=p->nMem );
6467965251
u.cb.ctx.pMem = u.cb.pMem = &aMem[pOp->p3];
@@ -64689,11 +65261,11 @@
6468965261
assert( pOp>p->aOp );
6469065262
assert( pOp[-1].p4type==P4_COLLSEQ );
6469165263
assert( pOp[-1].opcode==OP_CollSeq );
6469265264
u.cb.ctx.pColl = pOp[-1].p4.pColl;
6469365265
}
64694
- (u.cb.ctx.pFunc->xStep)(&u.cb.ctx, u.cb.n, u.cb.apVal);
65266
+ (u.cb.ctx.pFunc->xStep)(&u.cb.ctx, u.cb.n, u.cb.apVal); /* IMP: R-24505-23230 */
6469565267
if( u.cb.ctx.isError ){
6469665268
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cb.ctx.s));
6469765269
rc = u.cb.ctx.isError;
6469865270
}
6469965271
sqlite3VdbeMemRelease(&u.cb.ctx.s);
@@ -65076,10 +65648,11 @@
6507665648
#endif /* local variables moved into u.ch */
6507765649
6507865650
u.ch.pQuery = &aMem[pOp->p3];
6507965651
u.ch.pArgc = &u.ch.pQuery[1];
6508065652
u.ch.pCur = p->apCsr[pOp->p1];
65653
+ assert( memIsValid(u.ch.pQuery) );
6508165654
REGISTER_TRACE(pOp->p3, u.ch.pQuery);
6508265655
assert( u.ch.pCur->pVtabCursor );
6508365656
u.ch.pVtabCursor = u.ch.pCur->pVtabCursor;
6508465657
u.ch.pVtab = u.ch.pVtabCursor->pVtab;
6508565658
u.ch.pModule = u.ch.pVtab->pModule;
@@ -65133,10 +65706,11 @@
6513365706
6513465707
VdbeCursor *pCur = p->apCsr[pOp->p1];
6513565708
assert( pCur->pVtabCursor );
6513665709
assert( pOp->p3>0 && pOp->p3<=p->nMem );
6513765710
u.ci.pDest = &aMem[pOp->p3];
65711
+ memAboutToChange(p, u.ci.pDest);
6513865712
if( pCur->nullRow ){
6513965713
sqlite3VdbeMemSetNull(u.ci.pDest);
6514065714
break;
6514165715
}
6514265716
u.ci.pVtab = pCur->pVtabCursor->pVtab;
@@ -65235,14 +65809,16 @@
6523565809
#endif /* local variables moved into u.ck */
6523665810
6523765811
u.ck.pVtab = pOp->p4.pVtab->pVtab;
6523865812
u.ck.pName = &aMem[pOp->p1];
6523965813
assert( u.ck.pVtab->pModule->xRename );
65814
+ assert( memIsValid(u.ck.pName) );
6524065815
REGISTER_TRACE(pOp->p1, u.ck.pName);
6524165816
assert( u.ck.pName->flags & MEM_Str );
6524265817
rc = u.ck.pVtab->pModule->xRename(u.ck.pVtab, u.ck.pName->z);
6524365818
importVtabErrMsg(p, u.ck.pVtab);
65819
+ p->expired = 0;
6524465820
6524565821
break;
6524665822
}
6524765823
#endif
6524865824
@@ -65287,10 +65863,12 @@
6528765863
assert( pOp->p4type==P4_VTAB );
6528865864
if( ALWAYS(u.cl.pModule->xUpdate) ){
6528965865
u.cl.apArg = p->apArg;
6529065866
u.cl.pX = &aMem[pOp->p3];
6529165867
for(u.cl.i=0; u.cl.i<u.cl.nArg; u.cl.i++){
65868
+ assert( memIsValid(u.cl.pX) );
65869
+ memAboutToChange(p, u.cl.pX);
6529265870
sqlite3VdbeMemStoreType(u.cl.pX);
6529365871
u.cl.apArg[u.cl.i] = u.cl.pX;
6529465872
u.cl.pX++;
6529565873
}
6529665874
rc = u.cl.pModule->xUpdate(u.cl.pVtab, u.cl.nArg, u.cl.apArg, &u.cl.rowid);
@@ -66341,12 +66919,11 @@
6634166919
SQLITE_PRIVATE int sqlite3IsMemJournal(sqlite3_file *pJfd){
6634266920
return pJfd->pMethods==&MemJournalMethods;
6634366921
}
6634466922
6634566923
/*
66346
-** Return the number of bytes required to store a MemJournal that uses vfs
66347
-** pVfs to create the underlying on-disk files.
66924
+** Return the number of bytes required to store a MemJournal file descriptor.
6634866925
*/
6634966926
SQLITE_PRIVATE int sqlite3MemJournalSize(void){
6635066927
return sizeof(MemJournal);
6635166928
}
6635266929
@@ -68246,11 +68823,11 @@
6824668823
pExpr->iColumn = (ynVar)(++pParse->nVar);
6824768824
}else if( z[0]=='?' ){
6824868825
/* Wildcard of the form "?nnn". Convert "nnn" to an integer and
6824968826
** use it as the variable number */
6825068827
i64 i;
68251
- int bOk = sqlite3Atoi64(&z[1], &i);
68828
+ int bOk = 0==sqlite3Atoi64(&z[1], &i, sqlite3Strlen30(&z[1]), SQLITE_UTF8);
6825268829
pExpr->iColumn = (ynVar)i;
6825368830
testcase( i==0 );
6825468831
testcase( i==1 );
6825568832
testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
6825668833
testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
@@ -69226,12 +69803,12 @@
6922669803
return eType;
6922769804
}
6922869805
#endif
6922969806
6923069807
/*
69231
-** Generate code for scalar subqueries used as an expression
69232
-** and IN operators. Examples:
69808
+** Generate code for scalar subqueries used as a subquery expression, EXISTS,
69809
+** or IN operators. Examples:
6923369810
**
6923469811
** (SELECT a FROM b) -- subquery
6923569812
** EXISTS (SELECT a FROM b) -- EXISTS subquery
6923669813
** x IN (4,5,11) -- IN operator with list on right-hand side
6923769814
** x IN (SELECT a FROM b) -- IN operator with subquery on the right
@@ -69290,14 +69867,14 @@
6929069867
assert( testAddr>0 || pParse->db->mallocFailed );
6929169868
}
6929269869
6929369870
switch( pExpr->op ){
6929469871
case TK_IN: {
69295
- char affinity;
69296
- KeyInfo keyInfo;
69297
- int addr; /* Address of OP_OpenEphemeral instruction */
69298
- Expr *pLeft = pExpr->pLeft;
69872
+ char affinity; /* Affinity of the LHS of the IN */
69873
+ KeyInfo keyInfo; /* Keyinfo for the generated table */
69874
+ int addr; /* Address of OP_OpenEphemeral instruction */
69875
+ Expr *pLeft = pExpr->pLeft; /* the LHS of the IN operator */
6929969876
6930069877
if( rMayHaveNull ){
6930169878
sqlite3VdbeAddOp2(v, OP_Null, 0, rMayHaveNull);
6930269879
}
6930369880
@@ -69316,10 +69893,11 @@
6931669893
** 'x' nor the SELECT... statement are columns, then numeric affinity
6931769894
** is used.
6931869895
*/
6931969896
pExpr->iTable = pParse->nTab++;
6932069897
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
69898
+ if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
6932169899
memset(&keyInfo, 0, sizeof(keyInfo));
6932269900
keyInfo.nField = 1;
6932369901
6932469902
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
6932569903
/* Case 1: expr IN (SELECT ...)
@@ -69608,11 +70186,11 @@
6960870186
*/
6960970187
static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){
6961070188
if( ALWAYS(z!=0) ){
6961170189
double value;
6961270190
char *zV;
69613
- sqlite3AtoF(z, &value);
70191
+ sqlite3AtoF(z, &value, sqlite3Strlen30(z), SQLITE_UTF8);
6961470192
assert( !sqlite3IsNaN(value) ); /* The new AtoF never returns NaN */
6961570193
if( negateFlag ) value = -value;
6961670194
zV = dup8bytes(v, (char*)&value);
6961770195
sqlite3VdbeAddOp4(v, OP_Real, 0, iMem, 0, zV, P4_REAL);
6961870196
}
@@ -69622,28 +70200,27 @@
6962270200
6962370201
/*
6962470202
** Generate an instruction that will put the integer describe by
6962570203
** text z[0..n-1] into register iMem.
6962670204
**
69627
-** The z[] string will probably not be zero-terminated. But the
69628
-** z[n] character is guaranteed to be something that does not look
69629
-** like the continuation of the number.
70205
+** Expr.u.zToken is always UTF8 and zero-terminated.
6963070206
*/
6963170207
static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){
6963270208
Vdbe *v = pParse->pVdbe;
6963370209
if( pExpr->flags & EP_IntValue ){
6963470210
int i = pExpr->u.iValue;
6963570211
if( negFlag ) i = -i;
6963670212
sqlite3VdbeAddOp2(v, OP_Integer, i, iMem);
6963770213
}else{
70214
+ int c;
70215
+ i64 value;
6963870216
const char *z = pExpr->u.zToken;
6963970217
assert( z!=0 );
69640
- if( sqlite3FitsIn64Bits(z, negFlag) ){
69641
- i64 value;
70218
+ c = sqlite3Atoi64(z, &value, sqlite3Strlen30(z), SQLITE_UTF8);
70219
+ if( c==0 || (c==2 && negFlag) ){
6964270220
char *zV;
69643
- sqlite3Atoi64(z, &value);
69644
- if( negFlag ) value = -value;
70221
+ if( negFlag ){ value = -value; }
6964570222
zV = dup8bytes(v, (char*)&value);
6964670223
sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64);
6964770224
}else{
6964870225
#ifdef SQLITE_OMIT_FLOATING_POINT
6964970226
sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
@@ -69924,77 +70501,10 @@
6992470501
}
6992570502
return 0;
6992670503
}
6992770504
#endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
6992870505
69929
-/*
69930
-** If the last instruction coded is an ephemeral copy of any of
69931
-** the registers in the nReg registers beginning with iReg, then
69932
-** convert the last instruction from OP_SCopy to OP_Copy.
69933
-*/
69934
-SQLITE_PRIVATE void sqlite3ExprHardCopy(Parse *pParse, int iReg, int nReg){
69935
- VdbeOp *pOp;
69936
- Vdbe *v;
69937
-
69938
- assert( pParse->db->mallocFailed==0 );
69939
- v = pParse->pVdbe;
69940
- assert( v!=0 );
69941
- pOp = sqlite3VdbeGetOp(v, -1);
69942
- assert( pOp!=0 );
69943
- if( pOp->opcode==OP_SCopy && pOp->p1>=iReg && pOp->p1<iReg+nReg ){
69944
- pOp->opcode = OP_Copy;
69945
- }
69946
-}
69947
-
69948
-/*
69949
-** Generate code to store the value of the iAlias-th alias in register
69950
-** target. The first time this is called, pExpr is evaluated to compute
69951
-** the value of the alias. The value is stored in an auxiliary register
69952
-** and the number of that register is returned. On subsequent calls,
69953
-** the register number is returned without generating any code.
69954
-**
69955
-** Note that in order for this to work, code must be generated in the
69956
-** same order that it is executed.
69957
-**
69958
-** Aliases are numbered starting with 1. So iAlias is in the range
69959
-** of 1 to pParse->nAlias inclusive.
69960
-**
69961
-** pParse->aAlias[iAlias-1] records the register number where the value
69962
-** of the iAlias-th alias is stored. If zero, that means that the
69963
-** alias has not yet been computed.
69964
-*/
69965
-static int codeAlias(Parse *pParse, int iAlias, Expr *pExpr, int target){
69966
-#if 0
69967
- sqlite3 *db = pParse->db;
69968
- int iReg;
69969
- if( pParse->nAliasAlloc<pParse->nAlias ){
69970
- pParse->aAlias = sqlite3DbReallocOrFree(db, pParse->aAlias,
69971
- sizeof(pParse->aAlias[0])*pParse->nAlias );
69972
- testcase( db->mallocFailed && pParse->nAliasAlloc>0 );
69973
- if( db->mallocFailed ) return 0;
69974
- memset(&pParse->aAlias[pParse->nAliasAlloc], 0,
69975
- (pParse->nAlias-pParse->nAliasAlloc)*sizeof(pParse->aAlias[0]));
69976
- pParse->nAliasAlloc = pParse->nAlias;
69977
- }
69978
- assert( iAlias>0 && iAlias<=pParse->nAlias );
69979
- iReg = pParse->aAlias[iAlias-1];
69980
- if( iReg==0 ){
69981
- if( pParse->iCacheLevel>0 ){
69982
- iReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
69983
- }else{
69984
- iReg = ++pParse->nMem;
69985
- sqlite3ExprCode(pParse, pExpr, iReg);
69986
- pParse->aAlias[iAlias-1] = iReg;
69987
- }
69988
- }
69989
- return iReg;
69990
-#else
69991
- UNUSED_PARAMETER(iAlias);
69992
- return sqlite3ExprCodeTarget(pParse, pExpr, target);
69993
-#endif
69994
-}
69995
-
6999670506
/*
6999770507
** Generate code into the current Vdbe to evaluate the given
6999870508
** expression. Attempt to store the results in register "target".
6999970509
** Return the register where results are stored.
7000070510
**
@@ -70099,11 +70609,11 @@
7009970609
case TK_REGISTER: {
7010070610
inReg = pExpr->iTable;
7010170611
break;
7010270612
}
7010370613
case TK_AS: {
70104
- inReg = codeAlias(pParse, pExpr->iTable, pExpr->pLeft, target);
70614
+ inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
7010570615
break;
7010670616
}
7010770617
#ifndef SQLITE_OMIT_CAST
7010870618
case TK_CAST: {
7010970619
/* Expressions of the form: CAST(pLeft AS token) */
@@ -70531,10 +71041,15 @@
7053171041
testcase( regFree1==0 );
7053271042
cacheX.op = TK_REGISTER;
7053371043
opCompare.op = TK_EQ;
7053471044
opCompare.pLeft = &cacheX;
7053571045
pTest = &opCompare;
71046
+ /* Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
71047
+ ** The value in regFree1 might get SCopy-ed into the file result.
71048
+ ** So make sure that the regFree1 register is not reused for other
71049
+ ** purposes and possibly overwritten. */
71050
+ regFree1 = 0;
7053671051
}
7053771052
for(i=0; i<nExpr; i=i+2){
7053871053
sqlite3ExprCachePush(pParse);
7053971054
if( pX ){
7054071055
assert( pTest!=0 );
@@ -70624,14 +71139,18 @@
7062471139
*/
7062571140
SQLITE_PRIVATE int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
7062671141
int inReg;
7062771142
7062871143
assert( target>0 && target<=pParse->nMem );
70629
- inReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
70630
- assert( pParse->pVdbe || pParse->db->mallocFailed );
70631
- if( inReg!=target && pParse->pVdbe ){
70632
- sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target);
71144
+ if( pExpr && pExpr->op==TK_REGISTER ){
71145
+ sqlite3VdbeAddOp2(pParse->pVdbe, OP_Copy, pExpr->iTable, target);
71146
+ }else{
71147
+ inReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
71148
+ assert( pParse->pVdbe || pParse->db->mallocFailed );
71149
+ if( inReg!=target && pParse->pVdbe ){
71150
+ sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target);
71151
+ }
7063371152
}
7063471153
return target;
7063571154
}
7063671155
7063771156
/*
@@ -70800,23 +71319,18 @@
7080071319
){
7080171320
struct ExprList_item *pItem;
7080271321
int i, n;
7080371322
assert( pList!=0 );
7080471323
assert( target>0 );
71324
+ assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
7080571325
n = pList->nExpr;
7080671326
for(pItem=pList->a, i=0; i<n; i++, pItem++){
70807
- if( pItem->iAlias ){
70808
- int iReg = codeAlias(pParse, pItem->iAlias, pItem->pExpr, target+i);
70809
- Vdbe *v = sqlite3GetVdbe(pParse);
70810
- if( iReg!=target+i ){
70811
- sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target+i);
70812
- }
70813
- }else{
70814
- sqlite3ExprCode(pParse, pItem->pExpr, target+i);
70815
- }
70816
- if( doHardCopy && !pParse->db->mallocFailed ){
70817
- sqlite3ExprHardCopy(pParse, target, n);
71327
+ Expr *pExpr = pItem->pExpr;
71328
+ int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
71329
+ if( inReg!=target+i ){
71330
+ sqlite3VdbeAddOp2(pParse->pVdbe, doHardCopy ? OP_Copy : OP_SCopy,
71331
+ inReg, target+i);
7081871332
}
7081971333
}
7082071334
return n;
7082171335
}
7082271336
@@ -71794,10 +72308,15 @@
7179472308
if( pTrig->pSchema==pTempSchema ){
7179572309
zWhere = whereOrName(db, zWhere, pTrig->zName);
7179672310
}
7179772311
}
7179872312
}
72313
+ if( zWhere ){
72314
+ char *zNew = sqlite3MPrintf(pParse->db, "type='trigger' AND (%s)", zWhere);
72315
+ sqlite3DbFree(pParse->db, zWhere);
72316
+ zWhere = zNew;
72317
+ }
7179972318
return zWhere;
7180072319
}
7180172320
7180272321
/*
7180372322
** Generate code to drop and reload the internal representation of table
@@ -72401,11 +72920,12 @@
7240172920
int iIdxCur; /* Cursor open on index being analyzed */
7240272921
Vdbe *v; /* The virtual machine being built up */
7240372922
int i; /* Loop counter */
7240472923
int topOfLoop; /* The top of the loop */
7240572924
int endOfLoop; /* The end of the loop */
72406
- int addr; /* The address of an instruction */
72925
+ int addr = 0; /* The address of an instruction */
72926
+ int jZeroRows = 0; /* Jump from here if number of rows is zero */
7240772927
int iDb; /* Index of database containing pTab */
7240872928
int regTabname = iMem++; /* Register containing table name */
7240972929
int regIdxname = iMem++; /* Register containing index name */
7241072930
int regSampleno = iMem++; /* Register containing next sample number */
7241172931
int regCol = iMem++; /* Content of a column analyzed table */
@@ -72420,12 +72940,19 @@
7242072940
int regLast = iMem++; /* Index of last sample to record */
7242172941
int regFirst = iMem++; /* Index of first sample to record */
7242272942
#endif
7242372943
7242472944
v = sqlite3GetVdbe(pParse);
72425
- if( v==0 || NEVER(pTab==0) || pTab->pIndex==0 ){
72426
- /* Do no analysis for tables that have no indices */
72945
+ if( v==0 || NEVER(pTab==0) ){
72946
+ return;
72947
+ }
72948
+ if( pTab->tnum==0 ){
72949
+ /* Do not gather statistics on views or virtual tables */
72950
+ return;
72951
+ }
72952
+ if( memcmp(pTab->zName, "sqlite_", 7)==0 ){
72953
+ /* Do not gather statistics on system tables */
7242772954
return;
7242872955
}
7242972956
assert( sqlite3BtreeHoldsAllMutexes(db) );
7243072957
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
7243172958
assert( iDb>=0 );
@@ -72438,10 +72965,11 @@
7243872965
7243972966
/* Establish a read-lock on the table at the shared-cache level. */
7244072967
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
7244172968
7244272969
iIdxCur = pParse->nTab++;
72970
+ sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
7244372971
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
7244472972
int nCol = pIdx->nColumn;
7244572973
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
7244672974
7244772975
if( iMem+1+(nCol*2)>pParse->nMem ){
@@ -72452,14 +72980,11 @@
7245272980
assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
7245372981
sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb,
7245472982
(char *)pKey, P4_KEYINFO_HANDOFF);
7245572983
VdbeComment((v, "%s", pIdx->zName));
7245672984
72457
- /* Populate the registers containing the table and index names. */
72458
- if( pTab->pIndex==pIdx ){
72459
- sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
72460
- }
72985
+ /* Populate the register containing the index name. */
7246172986
sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, pIdx->zName, 0);
7246272987
7246372988
#ifdef SQLITE_ENABLE_STAT2
7246472989
7246572990
/* If this iteration of the loop is generating code to analyze the
@@ -72590,12 +73115,14 @@
7259073115
**
7259173116
** If K==0 then no entry is made into the sqlite_stat1 table.
7259273117
** If K>0 then it is always the case the D>0 so division by zero
7259373118
** is never possible.
7259473119
*/
72595
- addr = sqlite3VdbeAddOp1(v, OP_IfNot, iMem);
7259673120
sqlite3VdbeAddOp2(v, OP_SCopy, iMem, regSampleno);
73121
+ if( jZeroRows==0 ){
73122
+ jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, iMem);
73123
+ }
7259773124
for(i=0; i<nCol; i++){
7259873125
sqlite3VdbeAddOp4(v, OP_String8, 0, regTemp, 0, " ", 0);
7259973126
sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regSampleno, regSampleno);
7260073127
sqlite3VdbeAddOp3(v, OP_Add, iMem, iMem+i+1, regTemp);
7260173128
sqlite3VdbeAddOp2(v, OP_AddImm, regTemp, -1);
@@ -72605,17 +73132,39 @@
7260573132
}
7260673133
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0);
7260773134
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regRowid);
7260873135
sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regRowid);
7260973136
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
73137
+ }
73138
+
73139
+ /* If the table has no indices, create a single sqlite_stat1 entry
73140
+ ** containing NULL as the index name and the row count as the content.
73141
+ */
73142
+ if( pTab->pIndex==0 ){
73143
+ sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pTab->tnum, iDb);
73144
+ VdbeComment((v, "%s", pTab->zName));
73145
+ sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regSampleno);
73146
+ sqlite3VdbeAddOp1(v, OP_Close, iIdxCur);
73147
+ }else{
73148
+ assert( jZeroRows>0 );
73149
+ addr = sqlite3VdbeAddOp0(v, OP_Goto);
73150
+ sqlite3VdbeJumpHere(v, jZeroRows);
73151
+ }
73152
+ sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
73153
+ sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0);
73154
+ sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regRowid);
73155
+ sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regRowid);
73156
+ sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
73157
+ if( pParse->nMem<regRec ) pParse->nMem = regRec;
73158
+ if( jZeroRows ){
7261073159
sqlite3VdbeJumpHere(v, addr);
7261173160
}
7261273161
}
7261373162
7261473163
/*
7261573164
** Generate code that will cause the most recent index analysis to
72616
-** be laoded into internal hash tables where is can be used.
73165
+** be loaded into internal hash tables where is can be used.
7261773166
*/
7261873167
static void loadAnalysis(Parse *pParse, int iDb){
7261973168
Vdbe *v = sqlite3GetVdbe(pParse);
7262073169
if( v ){
7262173170
sqlite3VdbeAddOp1(v, OP_LoadAnalysis, iDb);
@@ -72741,37 +73290,50 @@
7274173290
7274273291
/*
7274373292
** This callback is invoked once for each index when reading the
7274473293
** sqlite_stat1 table.
7274573294
**
72746
-** argv[0] = name of the index
72747
-** argv[1] = results of analysis - on integer for each column
73295
+** argv[0] = name of the table
73296
+** argv[1] = name of the index (might be NULL)
73297
+** argv[2] = results of analysis - on integer for each column
73298
+**
73299
+** Entries for which argv[1]==NULL simply record the number of rows in
73300
+** the table.
7274873301
*/
7274973302
static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){
7275073303
analysisInfo *pInfo = (analysisInfo*)pData;
7275173304
Index *pIndex;
72752
- int i, c;
73305
+ Table *pTable;
73306
+ int i, c, n;
7275373307
unsigned int v;
7275473308
const char *z;
7275573309
72756
- assert( argc==2 );
73310
+ assert( argc==3 );
7275773311
UNUSED_PARAMETER2(NotUsed, argc);
7275873312
72759
- if( argv==0 || argv[0]==0 || argv[1]==0 ){
73313
+ if( argv==0 || argv[0]==0 || argv[2]==0 ){
7276073314
return 0;
7276173315
}
72762
- pIndex = sqlite3FindIndex(pInfo->db, argv[0], pInfo->zDatabase);
72763
- if( pIndex==0 ){
73316
+ pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
73317
+ if( pTable==0 ){
7276473318
return 0;
7276573319
}
72766
- z = argv[1];
72767
- for(i=0; *z && i<=pIndex->nColumn; i++){
73320
+ if( argv[1] ){
73321
+ pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
73322
+ }else{
73323
+ pIndex = 0;
73324
+ }
73325
+ n = pIndex ? pIndex->nColumn : 0;
73326
+ z = argv[2];
73327
+ for(i=0; *z && i<=n; i++){
7276873328
v = 0;
7276973329
while( (c=z[0])>='0' && c<='9' ){
7277073330
v = v*10 + c - '0';
7277173331
z++;
7277273332
}
73333
+ if( i==0 ) pTable->nRowEst = v;
73334
+ if( pIndex==0 ) break;
7277373335
pIndex->aiRowEst[i] = v;
7277473336
if( *z==' ' ) z++;
7277573337
}
7277673338
return 0;
7277773339
}
@@ -72843,11 +73405,11 @@
7284373405
return SQLITE_ERROR;
7284473406
}
7284573407
7284673408
/* Load new statistics out of the sqlite_stat1 table */
7284773409
zSql = sqlite3MPrintf(db,
72848
- "SELECT idx, stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
73410
+ "SELECT tbl, idx, stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
7284973411
if( zSql==0 ){
7285073412
rc = SQLITE_NOMEM;
7285173413
}else{
7285273414
rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
7285373415
sqlite3DbFree(db, zSql);
@@ -73060,13 +73622,12 @@
7306073622
7306173623
/* Open the database file. If the btree is successfully opened, use
7306273624
** it to obtain the database schema. At this point the schema may
7306373625
** or may not be initialised.
7306473626
*/
73065
- rc = sqlite3BtreeFactory(db, zFile, 0, SQLITE_DEFAULT_CACHE_SIZE,
73066
- db->openFlags | SQLITE_OPEN_MAIN_DB,
73067
- &aNew->pBt);
73627
+ rc = sqlite3BtreeOpen(zFile, db, &aNew->pBt, 0,
73628
+ db->openFlags | SQLITE_OPEN_MAIN_DB);
7306873629
db->nDb++;
7306973630
if( rc==SQLITE_CONSTRAINT ){
7307073631
rc = SQLITE_ERROR;
7307173632
zErrDyn = sqlite3MPrintf(db, "database is already attached");
7307273633
}else if( rc==SQLITE_OK ){
@@ -73303,11 +73864,12 @@
7330373864
0, /* pNext */
7330473865
detachFunc, /* xFunc */
7330573866
0, /* xStep */
7330673867
0, /* xFinalize */
7330773868
"sqlite_detach", /* zName */
73308
- 0 /* pHash */
73869
+ 0, /* pHash */
73870
+ 0 /* pDestructor */
7330973871
};
7331073872
codeAttach(pParse, SQLITE_DETACH, &detach_func, pDbname, 0, 0, pDbname);
7331173873
}
7331273874
7331373875
/*
@@ -73324,11 +73886,12 @@
7332473886
0, /* pNext */
7332573887
attachFunc, /* xFunc */
7332673888
0, /* xStep */
7332773889
0, /* xFinalize */
7332873890
"sqlite_attach", /* zName */
73329
- 0 /* pHash */
73891
+ 0, /* pHash */
73892
+ 0 /* pDestructor */
7333073893
};
7333173894
codeAttach(pParse, SQLITE_ATTACH, &attach_func, p, p, pDbname, pKey);
7333273895
}
7333373896
#endif /* SQLITE_OMIT_ATTACH */
7333473897
@@ -74453,12 +75016,13 @@
7445375016
** set to the index of the database that the table or view is to be
7445475017
** created in.
7445575018
*/
7445675019
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
7445775020
if( iDb<0 ) return;
74458
- if( !OMIT_TEMPDB && isTemp && iDb>1 ){
74459
- /* If creating a temp table, the name may not be qualified */
75021
+ if( !OMIT_TEMPDB && isTemp && pName2->n>0 && iDb!=1 ){
75022
+ /* If creating a temp table, the name may not be qualified. Unless
75023
+ ** the database name is "temp" anyway. */
7446075024
sqlite3ErrorMsg(pParse, "temporary table name must be unqualified");
7446175025
return;
7446275026
}
7446375027
if( !OMIT_TEMPDB && isTemp ) iDb = 1;
7446475028
@@ -74502,21 +75066,22 @@
7450275066
** to an sqlite3_declare_vtab() call. In that case only the column names
7450375067
** and types will be used, so there is no need to test for namespace
7450475068
** collisions.
7450575069
*/
7450675070
if( !IN_DECLARE_VTAB ){
75071
+ char *zDb = db->aDb[iDb].zName;
7450775072
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
7450875073
goto begin_table_error;
7450975074
}
74510
- pTable = sqlite3FindTable(db, zName, db->aDb[iDb].zName);
75075
+ pTable = sqlite3FindTable(db, zName, zDb);
7451175076
if( pTable ){
7451275077
if( !noErr ){
7451375078
sqlite3ErrorMsg(pParse, "table %T already exists", pName);
7451475079
}
7451575080
goto begin_table_error;
7451675081
}
74517
- if( sqlite3FindIndex(db, zName, 0)!=0 && (iDb==0 || !db->init.busy) ){
75082
+ if( sqlite3FindIndex(db, zName, zDb)!=0 ){
7451875083
sqlite3ErrorMsg(pParse, "there is already an index named %s", zName);
7451975084
goto begin_table_error;
7452075085
}
7452175086
}
7452275087
@@ -74529,10 +75094,11 @@
7452975094
}
7453075095
pTable->zName = zName;
7453175096
pTable->iPKey = -1;
7453275097
pTable->pSchema = db->aDb[iDb].pSchema;
7453375098
pTable->nRef = 1;
75099
+ pTable->nRowEst = 1000000;
7453475100
assert( pParse->pNewTable==0 );
7453575101
pParse->pNewTable = pTable;
7453675102
7453775103
/* If this is the magic sqlite_sequence table used by autoincrement,
7453875104
** then record a pointer to this table in the main database structure
@@ -75375,16 +75941,14 @@
7537575941
sqlite3SelectDelete(db, pSelect);
7537675942
return;
7537775943
}
7537875944
sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
7537975945
p = pParse->pNewTable;
75380
- if( p==0 ){
75946
+ if( p==0 || pParse->nErr ){
7538175947
sqlite3SelectDelete(db, pSelect);
7538275948
return;
7538375949
}
75384
- assert( pParse->nErr==0 ); /* If sqlite3StartTable return non-NULL then
75385
- ** there could not have been an error */
7538675950
sqlite3TwoPartName(pParse, pName1, pName2, &pName);
7538775951
iDb = sqlite3SchemaToIndex(db, p->pSchema);
7538875952
if( sqlite3FixInit(&sFix, pParse, iDb, "view", pName)
7538975953
&& sqlite3FixSelect(&sFix, pSelect)
7539075954
){
@@ -76498,11 +77062,12 @@
7649877062
*/
7649977063
if( pTblName ){
7650077064
sqlite3RefillIndex(pParse, pIndex, iMem);
7650177065
sqlite3ChangeCookie(pParse, iDb);
7650277066
sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 0, 0,
76503
- sqlite3MPrintf(db, "name='%q'", pIndex->zName), P4_DYNAMIC);
77067
+ sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName),
77068
+ P4_DYNAMIC);
7650477069
sqlite3VdbeAddOp1(v, OP_Expire, 0);
7650577070
}
7650677071
}
7650777072
7650877073
/* When adding an index to the list of indices for a table, make
@@ -76559,18 +77124,18 @@
7655977124
** are based on typical values found in actual indices.
7656077125
*/
7656177126
SQLITE_PRIVATE void sqlite3DefaultRowEst(Index *pIdx){
7656277127
unsigned *a = pIdx->aiRowEst;
7656377128
int i;
77129
+ unsigned n;
7656477130
assert( a!=0 );
76565
- a[0] = 1000000;
76566
- for(i=pIdx->nColumn; i>=5; i--){
76567
- a[i] = 5;
76568
- }
76569
- while( i>=1 ){
76570
- a[i] = 11 - i;
76571
- i--;
77131
+ a[0] = pIdx->pTable->nRowEst;
77132
+ if( a[0]<10 ) a[0] = 10;
77133
+ n = 10;
77134
+ for(i=1; i<=pIdx->nColumn; i++){
77135
+ a[i] = n;
77136
+ if( n>5 ) n--;
7657277137
}
7657377138
if( pIdx->onError!=OE_None ){
7657477139
a[pIdx->nColumn] = 1;
7657577140
}
7657677141
}
@@ -76626,11 +77191,11 @@
7662677191
/* Generate code to remove the index and from the master table */
7662777192
v = sqlite3GetVdbe(pParse);
7662877193
if( v ){
7662977194
sqlite3BeginWriteOperation(pParse, 1, iDb);
7663077195
sqlite3NestedParse(pParse,
76631
- "DELETE FROM %Q.%s WHERE name=%Q",
77196
+ "DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
7663277197
db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
7663377198
pIndex->zName
7663477199
);
7663577200
if( sqlite3FindTable(db, "sqlite_stat1", db->aDb[iDb].zName) ){
7663677201
sqlite3NestedParse(pParse,
@@ -77118,11 +77683,11 @@
7711877683
SQLITE_OPEN_CREATE |
7711977684
SQLITE_OPEN_EXCLUSIVE |
7712077685
SQLITE_OPEN_DELETEONCLOSE |
7712177686
SQLITE_OPEN_TEMP_DB;
7712277687
77123
- rc = sqlite3BtreeFactory(db, 0, 0, SQLITE_DEFAULT_CACHE_SIZE, flags, &pBt);
77688
+ rc = sqlite3BtreeOpen(0, db, &pBt, 0, flags);
7712477689
if( rc!=SQLITE_OK ){
7712577690
sqlite3ErrorMsg(pParse, "unable to open a temporary database "
7712677691
"file for storing temporary tables");
7712777692
pParse->rc = rc;
7712877693
return 1;
@@ -77775,11 +78340,11 @@
7777578340
** If the SQLITE_PreferBuiltin flag is set, then search the built-in
7777678341
** functions even if a prior app-defined function was found. And give
7777778342
** priority to built-in functions.
7777878343
**
7777978344
** Except, if createFlag is true, that means that we are trying to
77780
- ** install a new function. Whatever FuncDef structure is returned will
78345
+ ** install a new function. Whatever FuncDef structure is returned it will
7778178346
** have fields overwritten with new information appropriate for the
7778278347
** new function. But the FuncDefs for built-in functions are read-only.
7778378348
** So we must not search for built-ins when creating a new function.
7778478349
*/
7778578350
if( !createFlag && (pBest==0 || (db->flags & SQLITE_PreferBuiltin)!=0) ){
@@ -78791,11 +79356,11 @@
7879179356
zBuf = sqlite3_mprintf("%.*f",n,r);
7879279357
if( zBuf==0 ){
7879379358
sqlite3_result_error_nomem(context);
7879479359
return;
7879579360
}
78796
- sqlite3AtoF(zBuf, &r);
79361
+ sqlite3AtoF(zBuf, &r, sqlite3Strlen30(zBuf), SQLITE_UTF8);
7879779362
sqlite3_free(zBuf);
7879879363
}
7879979364
sqlite3_result_double(context, r);
7880079365
}
7880179366
#endif
@@ -79956,14 +80521,14 @@
7995680521
if( caseSensitive ){
7995780522
pInfo = (struct compareInfo*)&likeInfoAlt;
7995880523
}else{
7995980524
pInfo = (struct compareInfo*)&likeInfoNorm;
7996080525
}
79961
- sqlite3CreateFunc(db, "like", 2, SQLITE_ANY, pInfo, likeFunc, 0, 0);
79962
- sqlite3CreateFunc(db, "like", 3, SQLITE_ANY, pInfo, likeFunc, 0, 0);
80526
+ sqlite3CreateFunc(db, "like", 2, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
80527
+ sqlite3CreateFunc(db, "like", 3, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
7996380528
sqlite3CreateFunc(db, "glob", 2, SQLITE_ANY,
79964
- (struct compareInfo*)&globInfo, likeFunc, 0,0);
80529
+ (struct compareInfo*)&globInfo, likeFunc, 0, 0, 0);
7996580530
setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
7996680531
setLikeOptFlag(db, "like",
7996780532
caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
7996880533
}
7996980534
@@ -80043,14 +80608,14 @@
8004380608
FUNCTION(upper, 1, 0, 0, upperFunc ),
8004480609
FUNCTION(lower, 1, 0, 0, lowerFunc ),
8004580610
FUNCTION(coalesce, 1, 0, 0, 0 ),
8004680611
FUNCTION(coalesce, 0, 0, 0, 0 ),
8004780612
/* FUNCTION(coalesce, -1, 0, 0, ifnullFunc ), */
80048
- {-1,SQLITE_UTF8,SQLITE_FUNC_COALESCE,0,0,ifnullFunc,0,0,"coalesce",0},
80613
+ {-1,SQLITE_UTF8,SQLITE_FUNC_COALESCE,0,0,ifnullFunc,0,0,"coalesce",0,0},
8004980614
FUNCTION(hex, 1, 0, 0, hexFunc ),
8005080615
/* FUNCTION(ifnull, 2, 0, 0, ifnullFunc ), */
80051
- {2,SQLITE_UTF8,SQLITE_FUNC_COALESCE,0,0,ifnullFunc,0,0,"ifnull",0},
80616
+ {2,SQLITE_UTF8,SQLITE_FUNC_COALESCE,0,0,ifnullFunc,0,0,"ifnull",0,0},
8005280617
FUNCTION(random, 0, 0, 0, randomFunc ),
8005380618
FUNCTION(randomblob, 1, 0, 0, randomBlob ),
8005480619
FUNCTION(nullif, 2, 0, 1, nullifFunc ),
8005580620
FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
8005680621
FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
@@ -80073,11 +80638,11 @@
8007380638
#endif
8007480639
AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ),
8007580640
AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ),
8007680641
AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ),
8007780642
/* AGGREGATE(count, 0, 0, 0, countStep, countFinalize ), */
80078
- {0,SQLITE_UTF8,SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0},
80643
+ {0,SQLITE_UTF8,SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0},
8007980644
AGGREGATE(count, 1, 0, 0, countStep, countFinalize ),
8008080645
AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, groupConcatFinalize),
8008180646
AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, groupConcatFinalize),
8008280647
8008380648
LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
@@ -80484,11 +81049,11 @@
8048481049
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
8048581050
8048681051
sqlite3VdbeAddOp3(v, OP_OpenRead, iCur, pIdx->tnum, iDb);
8048781052
sqlite3VdbeChangeP4(v, -1, (char*)pKey, P4_KEYINFO_HANDOFF);
8048881053
for(i=0; i<nCol; i++){
80489
- sqlite3VdbeAddOp2(v, OP_SCopy, aiCol[i]+1+regData, regTemp+i);
81054
+ sqlite3VdbeAddOp2(v, OP_Copy, aiCol[i]+1+regData, regTemp+i);
8049081055
}
8049181056
8049281057
/* If the parent table is the same as the child table, and we are about
8049381058
** to increment the constraint-counter (i.e. this is an INSERT operation),
8049481059
** then check if the row being inserted matches itself. If so, do not
@@ -84849,11 +85414,11 @@
8484985414
*/
8485085415
if( sqlite3StrICmp(zLeft,"journal_size_limit")==0 ){
8485185416
Pager *pPager = sqlite3BtreePager(pDb->pBt);
8485285417
i64 iLimit = -2;
8485385418
if( zRight ){
84854
- sqlite3Atoi64(zRight, &iLimit);
85419
+ sqlite3Atoi64(zRight, &iLimit, 1000000, SQLITE_UTF8);
8485585420
if( iLimit<-1 ) iLimit = -1;
8485685421
}
8485785422
iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
8485885423
returnSingleInt(pParse, "journal_size_limit", iLimit);
8485985424
}else
@@ -87131,15 +87696,17 @@
8713187696
sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
8713287697
sqlite3VdbeAddOp2(v, OP_IdxInsert, iTab, r1);
8713387698
sqlite3ReleaseTempReg(pParse, r1);
8713487699
}
8713587700
87701
+#ifndef SQLITE_OMIT_SUBQUERY
8713687702
/*
8713787703
** Generate an error message when a SELECT is used within a subexpression
8713887704
** (example: "a IN (SELECT * FROM table)") but it has more than 1 result
87139
-** column. We do this in a subroutine because the error occurs in multiple
87140
-** places.
87705
+** column. We do this in a subroutine because the error used to occur
87706
+** in multiple places. (The error only occurs in one place now, but we
87707
+** retain the subroutine to minimize code disruption.)
8714187708
*/
8714287709
static int checkForMultiColumnSelectError(
8714387710
Parse *pParse, /* Parse context. */
8714487711
SelectDest *pDest, /* Destination of SELECT results */
8714587712
int nExpr /* Number of result columns returned by SELECT */
@@ -87151,10 +87718,11 @@
8715187718
return 1;
8715287719
}else{
8715387720
return 0;
8715487721
}
8715587722
}
87723
+#endif
8715687724
8715787725
/*
8715887726
** This routine generates the code for the inside of the inner loop
8715987727
** of a SELECT.
8716087728
**
@@ -87230,14 +87798,10 @@
8723087798
if( pOrderBy==0 ){
8723187799
codeOffset(v, p, iContinue);
8723287800
}
8723387801
}
8723487802
87235
- if( checkForMultiColumnSelectError(pParse, pDest, pEList->nExpr) ){
87236
- return;
87237
- }
87238
-
8723987803
switch( eDest ){
8724087804
/* In this mode, write each query result to the key of the temporary
8724187805
** table iParm.
8724287806
*/
8724387807
#ifndef SQLITE_OMIT_COMPOUND_SELECT
@@ -88143,10 +88707,11 @@
8814388707
/* Create the destination temporary table if necessary
8814488708
*/
8814588709
if( dest.eDest==SRT_EphemTab ){
8814688710
assert( p->pEList );
8814788711
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, dest.iParm, p->pEList->nExpr);
88712
+ sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
8814888713
dest.eDest = SRT_Table;
8814988714
}
8815088715
8815188716
/* Make sure all SELECTs in the statement have the same number of elements
8815288717
** in their result sets.
@@ -90105,11 +90670,11 @@
9010590670
ExprList *pList = pF->pExpr->x.pList;
9010690671
assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
9010790672
if( pList ){
9010890673
nArg = pList->nExpr;
9010990674
regAgg = sqlite3GetTempRange(pParse, nArg);
90110
- sqlite3ExprCodeExprList(pParse, pList, regAgg, 0);
90675
+ sqlite3ExprCodeExprList(pParse, pList, regAgg, 1);
9011190676
}else{
9011290677
nArg = 0;
9011390678
regAgg = 0;
9011490679
}
9011590680
if( pF->iDistinct>=0 ){
@@ -90264,10 +90829,19 @@
9026490829
9026590830
/* Begin generating code.
9026690831
*/
9026790832
v = sqlite3GetVdbe(pParse);
9026890833
if( v==0 ) goto select_end;
90834
+
90835
+ /* If writing to memory or generating a set
90836
+ ** only a single column may be output.
90837
+ */
90838
+#ifndef SQLITE_OMIT_SUBQUERY
90839
+ if( checkForMultiColumnSelectError(pParse, pDest, pEList->nExpr) ){
90840
+ goto select_end;
90841
+ }
90842
+#endif
9026990843
9027090844
/* Generate code for all sub-queries in the FROM clause
9027190845
*/
9027290846
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
9027390847
for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
@@ -90338,19 +90912,10 @@
9033890912
}
9033990913
return multiSelect(pParse, p, pDest);
9034090914
}
9034190915
#endif
9034290916
90343
- /* If writing to memory or generating a set
90344
- ** only a single column may be output.
90345
- */
90346
-#ifndef SQLITE_OMIT_SUBQUERY
90347
- if( checkForMultiColumnSelectError(pParse, pDest, pEList->nExpr) ){
90348
- goto select_end;
90349
- }
90350
-#endif
90351
-
9035290917
/* If possible, rewrite the query to use GROUP BY instead of DISTINCT.
9035390918
** GROUP BY might use an index, DISTINCT never does.
9035490919
*/
9035590920
assert( p->pGroupBy==0 || (p->selFlags & SF_Aggregate)!=0 );
9035690921
if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct ){
@@ -90409,10 +90974,11 @@
9040990974
assert( isAgg || pGroupBy );
9041090975
distinct = pParse->nTab++;
9041190976
pKeyInfo = keyInfoFromExprList(pParse, p->pEList);
9041290977
sqlite3VdbeAddOp4(v, OP_OpenEphemeral, distinct, 0, 0,
9041390978
(char*)pKeyInfo, P4_KEYINFO_HANDOFF);
90979
+ sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
9041490980
}else{
9041590981
distinct = -1;
9041690982
}
9041790983
9041890984
/* Aggregate and non-aggregate queries are handled differently */
@@ -92884,10 +93450,11 @@
9288493450
** be stored.
9288593451
*/
9288693452
assert( v );
9288793453
ephemTab = pParse->nTab++;
9288893454
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, ephemTab, pTab->nCol+1+(pRowid!=0));
93455
+ sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
9288993456
9289093457
/* fill the ephemeral table
9289193458
*/
9289293459
sqlite3SelectDestInit(&dest, SRT_Table, ephemTab);
9289393460
sqlite3Select(pParse, pSelect, &dest);
@@ -93022,10 +93589,14 @@
9302293589
int nDb; /* Number of attached databases */
9302393590
9302493591
if( !db->autoCommit ){
9302593592
sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
9302693593
return SQLITE_ERROR;
93594
+ }
93595
+ if( db->activeVdbeCnt>1 ){
93596
+ sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
93597
+ return SQLITE_ERROR;
9302793598
}
9302893599
9302993600
/* Save the current value of the database flags so that it can be
9303093601
** restored before returning. Then set the writable-schema flag, and
9303193602
** disable CHECK and foreign key constraints. */
@@ -93624,11 +94195,11 @@
9362494195
sqlite3DbFree(db, zStmt);
9362594196
v = sqlite3GetVdbe(pParse);
9362694197
sqlite3ChangeCookie(pParse, iDb);
9362794198
9362894199
sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
93629
- zWhere = sqlite3MPrintf(db, "name='%q'", pTab->zName);
94200
+ zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
9363094201
sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 1, 0, zWhere, P4_DYNAMIC);
9363194202
sqlite3VdbeAddOp4(v, OP_VCreate, iDb, 0, 0,
9363294203
pTab->zName, sqlite3Strlen30(pTab->zName) + 1);
9363394204
}
9363494205
@@ -94864,15 +95435,16 @@
9486495435
if( op==TK_REGISTER ){
9486595436
op = pRight->op2;
9486695437
}
9486795438
if( op==TK_VARIABLE ){
9486895439
Vdbe *pReprepare = pParse->pReprepare;
94869
- pVal = sqlite3VdbeGetValue(pReprepare, pRight->iColumn, SQLITE_AFF_NONE);
95440
+ int iCol = pRight->iColumn;
95441
+ pVal = sqlite3VdbeGetValue(pReprepare, iCol, SQLITE_AFF_NONE);
9487095442
if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){
9487195443
z = (char *)sqlite3_value_text(pVal);
9487295444
}
94873
- sqlite3VdbeSetVarmask(pParse->pVdbe, pRight->iColumn);
95445
+ sqlite3VdbeSetVarmask(pParse->pVdbe, iCol); /* IMP: R-23257-02778 */
9487495446
assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
9487595447
}else if( op==TK_STRING ){
9487695448
z = pRight->u.zToken;
9487795449
}
9487895450
if( z ){
@@ -94886,11 +95458,11 @@
9488695458
pPrefix = sqlite3Expr(db, TK_STRING, z);
9488795459
if( pPrefix ) pPrefix->u.zToken[cnt] = 0;
9488895460
*ppPrefix = pPrefix;
9488995461
if( op==TK_VARIABLE ){
9489095462
Vdbe *v = pParse->pVdbe;
94891
- sqlite3VdbeSetVarmask(v, pRight->iColumn);
95463
+ sqlite3VdbeSetVarmask(v, pRight->iColumn); /* IMP: R-23257-02778 */
9489295464
if( *pisComplete && pRight->u.zToken[1] ){
9489395465
/* If the rhs of the LIKE expression is a variable, and the current
9489495466
** value of the variable means there is no need to invoke the LIKE
9489595467
** function, then no OP_Variable will be added to the program.
9489695468
** This causes problems for the sqlite3_bind_parameter_name()
@@ -95750,11 +96322,12 @@
9575096322
9575196323
/*
9575296324
** Required because bestIndex() is called by bestOrClauseIndex()
9575396325
*/
9575496326
static void bestIndex(
95755
- Parse*, WhereClause*, struct SrcList_item*, Bitmask, ExprList*, WhereCost*);
96327
+ Parse*, WhereClause*, struct SrcList_item*,
96328
+ Bitmask, Bitmask, ExprList*, WhereCost*);
9575696329
9575796330
/*
9575896331
** This routine attempts to find an scanning strategy that can be used
9575996332
** to optimize an 'OR' expression that is part of a WHERE clause.
9576096333
**
@@ -95763,11 +96336,12 @@
9576396336
*/
9576496337
static void bestOrClauseIndex(
9576596338
Parse *pParse, /* The parsing context */
9576696339
WhereClause *pWC, /* The WHERE clause */
9576796340
struct SrcList_item *pSrc, /* The FROM clause term to search */
95768
- Bitmask notReady, /* Mask of cursors that are not available */
96341
+ Bitmask notReady, /* Mask of cursors not available for indexing */
96342
+ Bitmask notValid, /* Cursors not available for any purpose */
9576996343
ExprList *pOrderBy, /* The ORDER BY clause */
9577096344
WhereCost *pCost /* Lowest cost query plan */
9577196345
){
9577296346
#ifndef SQLITE_OMIT_OR_OPTIMIZATION
9577396347
const int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
@@ -95799,19 +96373,19 @@
9579996373
WHERETRACE(("... Multi-index OR testing for term %d of %d....\n",
9580096374
(pOrTerm - pOrWC->a), (pTerm - pWC->a)
9580196375
));
9580296376
if( pOrTerm->eOperator==WO_AND ){
9580396377
WhereClause *pAndWC = &pOrTerm->u.pAndInfo->wc;
95804
- bestIndex(pParse, pAndWC, pSrc, notReady, 0, &sTermCost);
96378
+ bestIndex(pParse, pAndWC, pSrc, notReady, notValid, 0, &sTermCost);
9580596379
}else if( pOrTerm->leftCursor==iCur ){
9580696380
WhereClause tempWC;
9580796381
tempWC.pParse = pWC->pParse;
9580896382
tempWC.pMaskSet = pWC->pMaskSet;
9580996383
tempWC.op = TK_AND;
9581096384
tempWC.a = pOrTerm;
9581196385
tempWC.nTerm = 1;
95812
- bestIndex(pParse, &tempWC, pSrc, notReady, 0, &sTermCost);
96386
+ bestIndex(pParse, &tempWC, pSrc, notReady, notValid, 0, &sTermCost);
9581396387
}else{
9581496388
continue;
9581596389
}
9581696390
rTotal += sTermCost.rCost;
9581796391
nRow += sTermCost.nRow;
@@ -95900,11 +96474,11 @@
9590096474
return;
9590196475
}
9590296476
9590396477
assert( pParse->nQueryLoop >= (double)1 );
9590496478
pTable = pSrc->pTab;
95905
- nTableRow = pTable->pIndex ? pTable->pIndex->aiRowEst[0] : 1000000;
96479
+ nTableRow = pTable->nRowEst;
9590696480
logN = estLog(nTableRow);
9590796481
costTempIdx = 2*logN*(nTableRow/pParse->nQueryLoop + 1);
9590896482
if( costTempIdx>=pCost->rCost ){
9590996483
/* The cost of creating the transient table would be greater than
9591096484
** doing the full table scan */
@@ -96254,11 +96828,12 @@
9625496828
*/
9625596829
static void bestVirtualIndex(
9625696830
Parse *pParse, /* The parsing context */
9625796831
WhereClause *pWC, /* The WHERE clause */
9625896832
struct SrcList_item *pSrc, /* The FROM clause term to search */
96259
- Bitmask notReady, /* Mask of cursors that are not available */
96833
+ Bitmask notReady, /* Mask of cursors not available for index */
96834
+ Bitmask notValid, /* Cursors not valid for any purpose */
9626096835
ExprList *pOrderBy, /* The order by clause */
9626196836
WhereCost *pCost, /* Lowest cost query plan */
9626296837
sqlite3_index_info **ppIdxInfo /* Index information passed to xBestIndex */
9626396838
){
9626496839
Table *pTab = pSrc->pTab;
@@ -96384,11 +96959,11 @@
9638496959
pIdxInfo->nOrderBy = nOrderBy;
9638596960
9638696961
/* Try to find a more efficient access pattern by using multiple indexes
9638796962
** to optimize an OR expression within the WHERE clause.
9638896963
*/
96389
- bestOrClauseIndex(pParse, pWC, pSrc, notReady, pOrderBy, pCost);
96964
+ bestOrClauseIndex(pParse, pWC, pSrc, notReady, notValid, pOrderBy, pCost);
9639096965
}
9639196966
#endif /* SQLITE_OMIT_VIRTUALTABLE */
9639296967
9639396968
/*
9639496969
** Argument pIdx is a pointer to an index structure that has an array of
@@ -96510,11 +97085,11 @@
9651097085
/* The evalConstExpr() function will have already converted any TK_VARIABLE
9651197086
** expression involved in an comparison into a TK_REGISTER. */
9651297087
assert( pExpr->op!=TK_VARIABLE );
9651397088
if( pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE ){
9651497089
int iVar = pExpr->iColumn;
96515
- sqlite3VdbeSetVarmask(pParse->pVdbe, iVar);
97090
+ sqlite3VdbeSetVarmask(pParse->pVdbe, iVar); /* IMP: R-23257-02778 */
9651697091
*pp = sqlite3VdbeGetValue(pParse->pReprepare, iVar, aff);
9651797092
return SQLITE_OK;
9651897093
}
9651997094
return sqlite3ValueFromExpr(pParse->db, pExpr, SQLITE_UTF8, aff, pp);
9652097095
}
@@ -96665,11 +97240,12 @@
9666597240
*/
9666697241
static void bestBtreeIndex(
9666797242
Parse *pParse, /* The parsing context */
9666897243
WhereClause *pWC, /* The WHERE clause */
9666997244
struct SrcList_item *pSrc, /* The FROM clause term to search */
96670
- Bitmask notReady, /* Mask of cursors that are not available */
97245
+ Bitmask notReady, /* Mask of cursors not available for indexing */
97246
+ Bitmask notValid, /* Cursors not available for any purpose */
9667197247
ExprList *pOrderBy, /* The ORDER BY clause */
9667297248
WhereCost *pCost /* Lowest cost query plan */
9667397249
){
9667497250
int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
9667597251
Index *pProbe; /* An index we are evaluating */
@@ -96707,27 +97283,18 @@
9670797283
Index *pFirst; /* Any other index on the table */
9670897284
memset(&sPk, 0, sizeof(Index));
9670997285
sPk.nColumn = 1;
9671097286
sPk.aiColumn = &aiColumnPk;
9671197287
sPk.aiRowEst = aiRowEstPk;
96712
- aiRowEstPk[1] = 1;
9671397288
sPk.onError = OE_Replace;
9671497289
sPk.pTable = pSrc->pTab;
97290
+ aiRowEstPk[0] = pSrc->pTab->nRowEst;
97291
+ aiRowEstPk[1] = 1;
9671597292
pFirst = pSrc->pTab->pIndex;
9671697293
if( pSrc->notIndexed==0 ){
9671797294
sPk.pNext = pFirst;
9671897295
}
96719
- /* The aiRowEstPk[0] is an estimate of the total number of rows in the
96720
- ** table. Get this information from the ANALYZE information if it is
96721
- ** available. If not available, assume the table 1 million rows in size.
96722
- */
96723
- if( pFirst ){
96724
- assert( pFirst->aiRowEst!=0 ); /* Allocated together with pFirst */
96725
- aiRowEstPk[0] = pFirst->aiRowEst[0];
96726
- }else{
96727
- aiRowEstPk[0] = 1000000;
96728
- }
9672997296
pProbe = &sPk;
9673097297
wsFlagMask = ~(
9673197298
WHERE_COLUMN_IN|WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_RANGE
9673297299
);
9673397300
eqTermMask = WO_EQ|WO_IN;
@@ -96936,29 +97503,29 @@
9693697503
** of output rows, adjust the nRow value accordingly. This only
9693797504
** matters if the current index is the least costly, so do not bother
9693897505
** with this step if we already know this index will not be chosen.
9693997506
** Also, never reduce the output row count below 2 using this step.
9694097507
**
96941
- ** Do not reduce the output row count if pSrc is the only table that
96942
- ** is notReady; if notReady is a power of two. This will be the case
96943
- ** when the main sqlite3WhereBegin() loop is scanning for a table with
96944
- ** and "optimal" index, and on such a scan the output row count
96945
- ** reduction is not valid because it does not update the "pCost->used"
96946
- ** bitmap. The notReady bitmap will also be a power of two when we
96947
- ** are scanning for the last table in a 64-way join. We are willing
96948
- ** to bypass this optimization in that corner case.
97508
+ ** It is critical that the notValid mask be used here instead of
97509
+ ** the notReady mask. When computing an "optimal" index, the notReady
97510
+ ** mask will only have one bit set - the bit for the current table.
97511
+ ** The notValid mask, on the other hand, always has all bits set for
97512
+ ** tables that are not in outer loops. If notReady is used here instead
97513
+ ** of notValid, then a optimal index that depends on inner joins loops
97514
+ ** might be selected even when there exists an optimal index that has
97515
+ ** no such dependency.
9694997516
*/
96950
- if( nRow>2 && cost<=pCost->rCost && (notReady & (notReady-1))!=0 ){
97517
+ if( nRow>2 && cost<=pCost->rCost ){
9695197518
int k; /* Loop counter */
9695297519
int nSkipEq = nEq; /* Number of == constraints to skip */
9695397520
int nSkipRange = nBound; /* Number of < constraints to skip */
9695497521
Bitmask thisTab; /* Bitmap for pSrc */
9695597522
9695697523
thisTab = getMask(pWC->pMaskSet, iCur);
9695797524
for(pTerm=pWC->a, k=pWC->nTerm; nRow>2 && k; k--, pTerm++){
9695897525
if( pTerm->wtFlags & TERM_VIRTUAL ) continue;
96959
- if( (pTerm->prereqAll & notReady)!=thisTab ) continue;
97526
+ if( (pTerm->prereqAll & notValid)!=thisTab ) continue;
9696097527
if( pTerm->eOperator & (WO_EQ|WO_IN|WO_ISNULL) ){
9696197528
if( nSkipEq ){
9696297529
/* Ignore the first nEq equality matches since the index
9696397530
** has already accounted for these */
9696497531
nSkipEq--;
@@ -97036,11 +97603,11 @@
9703697603
WHERETRACE(("best index is: %s\n",
9703797604
((pCost->plan.wsFlags & WHERE_NOT_FULLSCAN)==0 ? "none" :
9703897605
pCost->plan.u.pIdx ? pCost->plan.u.pIdx->zName : "ipk")
9703997606
));
9704097607
97041
- bestOrClauseIndex(pParse, pWC, pSrc, notReady, pOrderBy, pCost);
97608
+ bestOrClauseIndex(pParse, pWC, pSrc, notReady, notValid, pOrderBy, pCost);
9704297609
bestAutomaticIndex(pParse, pWC, pSrc, notReady, pCost);
9704397610
pCost->plan.wsFlags |= eqTermMask;
9704497611
}
9704597612
9704697613
/*
@@ -97051,26 +97618,27 @@
9705197618
*/
9705297619
static void bestIndex(
9705397620
Parse *pParse, /* The parsing context */
9705497621
WhereClause *pWC, /* The WHERE clause */
9705597622
struct SrcList_item *pSrc, /* The FROM clause term to search */
97056
- Bitmask notReady, /* Mask of cursors that are not available */
97623
+ Bitmask notReady, /* Mask of cursors not available for indexing */
97624
+ Bitmask notValid, /* Cursors not available for any purpose */
9705797625
ExprList *pOrderBy, /* The ORDER BY clause */
9705897626
WhereCost *pCost /* Lowest cost query plan */
9705997627
){
9706097628
#ifndef SQLITE_OMIT_VIRTUALTABLE
9706197629
if( IsVirtual(pSrc->pTab) ){
9706297630
sqlite3_index_info *p = 0;
97063
- bestVirtualIndex(pParse, pWC, pSrc, notReady, pOrderBy, pCost, &p);
97631
+ bestVirtualIndex(pParse, pWC, pSrc, notReady, notValid, pOrderBy, pCost,&p);
9706497632
if( p->needToFreeIdxStr ){
9706597633
sqlite3_free(p->idxStr);
9706697634
}
9706797635
sqlite3DbFree(pParse->db, p);
9706897636
}else
9706997637
#endif
9707097638
{
97071
- bestBtreeIndex(pParse, pWC, pSrc, notReady, pOrderBy, pCost);
97639
+ bestBtreeIndex(pParse, pWC, pSrc, notReady, notValid, pOrderBy, pCost);
9707297640
}
9707397641
}
9707497642
9707597643
/*
9707697644
** Disable a term in the WHERE clause. Except, do not disable the term
@@ -98281,14 +98849,20 @@
9828198849
** by waiting for other tables to run first. This "optimal" test works
9828298850
** by first assuming that the FROM clause is on the inner loop and finding
9828398851
** its query plan, then checking to see if that query plan uses any
9828498852
** other FROM clause terms that are notReady. If no notReady terms are
9828598853
** used then the "optimal" query plan works.
98854
+ **
98855
+ ** Note that the WhereCost.nRow parameter for an optimal scan might
98856
+ ** not be as small as it would be if the table really were the innermost
98857
+ ** join. The nRow value can be reduced by WHERE clause constraints
98858
+ ** that do not use indices. But this nRow reduction only happens if the
98859
+ ** table really is the innermost join.
9828698860
**
9828798861
** The second loop iteration is only performed if no optimal scan
98288
- ** strategies were found by the first loop. This 2nd iteration is used to
98289
- ** search for the lowest cost scan overall.
98862
+ ** strategies were found by the first iteration. This second iteration
98863
+ ** is used to search for the lowest cost scan overall.
9829098864
**
9829198865
** Previous versions of SQLite performed only the second iteration -
9829298866
** the next outermost loop was always that with the lowest overall
9829398867
** cost. However, this meant that SQLite could select the wrong plan
9829498868
** for scripts such as the following:
@@ -98297,18 +98871,18 @@
9829798871
** CREATE TABLE t2(c, d);
9829898872
** SELECT * FROM t2, t1 WHERE t2.rowid = t1.a;
9829998873
**
9830098874
** The best strategy is to iterate through table t1 first. However it
9830198875
** is not possible to determine this with a simple greedy algorithm.
98302
- ** However, since the cost of a linear scan through table t2 is the same
98876
+ ** Since the cost of a linear scan through table t2 is the same
9830398877
** as the cost of a linear scan through table t1, a simple greedy
9830498878
** algorithm may choose to use t2 for the outer loop, which is a much
9830598879
** costlier approach.
9830698880
*/
9830798881
nUnconstrained = 0;
9830898882
notIndexed = 0;
98309
- for(isOptimal=(iFrom<nTabList-1); isOptimal>=0; isOptimal--){
98883
+ for(isOptimal=(iFrom<nTabList-1); isOptimal>=0 && bestJ<0; isOptimal--){
9831098884
Bitmask mask; /* Mask of tables not yet ready */
9831198885
for(j=iFrom, pTabItem=&pTabList->a[j]; j<nTabList; j++, pTabItem++){
9831298886
int doNotReorder; /* True if this table should not be reordered */
9831398887
WhereCost sCost; /* Cost information from best[Virtual]Index() */
9831498888
ExprList *pOrderBy; /* ORDER BY clause for index to optimize */
@@ -98326,15 +98900,17 @@
9832698900
9832798901
assert( pTabItem->pTab );
9832898902
#ifndef SQLITE_OMIT_VIRTUALTABLE
9832998903
if( IsVirtual(pTabItem->pTab) ){
9833098904
sqlite3_index_info **pp = &pWInfo->a[j].pIdxInfo;
98331
- bestVirtualIndex(pParse, pWC, pTabItem, mask, pOrderBy, &sCost, pp);
98905
+ bestVirtualIndex(pParse, pWC, pTabItem, mask, notReady, pOrderBy,
98906
+ &sCost, pp);
9833298907
}else
9833398908
#endif
9833498909
{
98335
- bestBtreeIndex(pParse, pWC, pTabItem, mask, pOrderBy, &sCost);
98910
+ bestBtreeIndex(pParse, pWC, pTabItem, mask, notReady, pOrderBy,
98911
+ &sCost);
9833698912
}
9833798913
assert( isOptimal || (sCost.used&notReady)==0 );
9833898914
9833998915
/* If an INDEXED BY clause is present, then the plan must use that
9834098916
** index if it uses any index at all */
@@ -103366,19 +103942,37 @@
103366103942
103367103943
/************** End of sqliteicu.h *******************************************/
103368103944
/************** Continuing where we left off in main.c ***********************/
103369103945
#endif
103370103946
103371
-/*
103372
-** The version of the library
103373
-*/
103374103947
#ifndef SQLITE_AMALGAMATION
103948
+/* IMPLEMENTATION-OF: R-46656-45156 The sqlite3_version[] string constant
103949
+** contains the text of SQLITE_VERSION macro.
103950
+*/
103375103951
SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
103376103952
#endif
103953
+
103954
+/* IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns
103955
+** a pointer to the to the sqlite3_version[] string constant.
103956
+*/
103377103957
SQLITE_API const char *sqlite3_libversion(void){ return sqlite3_version; }
103958
+
103959
+/* IMPLEMENTATION-OF: R-63124-39300 The sqlite3_sourceid() function returns a
103960
+** pointer to a string constant whose value is the same as the
103961
+** SQLITE_SOURCE_ID C preprocessor macro.
103962
+*/
103378103963
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
103964
+
103965
+/* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function
103966
+** returns an integer equal to SQLITE_VERSION_NUMBER.
103967
+*/
103379103968
SQLITE_API int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; }
103969
+
103970
+/* IMPLEMENTATION-OF: R-54823-41343 The sqlite3_threadsafe() function returns
103971
+** zero if and only if SQLite was compiled mutexing code omitted due to
103972
+** the SQLITE_THREADSAFE compile-time option being set to 0.
103973
+*/
103380103974
SQLITE_API int sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }
103381103975
103382103976
#if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
103383103977
/*
103384103978
** If the following function pointer is not NULL and if
@@ -103495,10 +104089,17 @@
103495104089
/* Do the rest of the initialization under the recursive mutex so
103496104090
** that we will be able to handle recursive calls into
103497104091
** sqlite3_initialize(). The recursive calls normally come through
103498104092
** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other
103499104093
** recursive calls might also be possible.
104094
+ **
104095
+ ** IMPLEMENTATION-OF: R-00140-37445 SQLite automatically serializes calls
104096
+ ** to the xInit method, so the xInit method need not be threadsafe.
104097
+ **
104098
+ ** The following mutex is what serializes access to the appdef pcache xInit
104099
+ ** methods. The sqlite3_pcache_methods.xInit() all is embedded in the
104100
+ ** call to sqlite3PcacheInitialize().
103500104101
*/
103501104102
sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex);
103502104103
if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){
103503104104
FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions);
103504104105
sqlite3GlobalConfig.inProgress = 1;
@@ -103775,16 +104376,16 @@
103775104376
if( cnt<0 ) cnt = 0;
103776104377
if( sz==0 || cnt==0 ){
103777104378
sz = 0;
103778104379
pStart = 0;
103779104380
}else if( pBuf==0 ){
103780
- sz = ROUND8(sz);
104381
+ sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */
103781104382
sqlite3BeginBenignMalloc();
103782
- pStart = sqlite3Malloc( sz*cnt );
104383
+ pStart = sqlite3Malloc( sz*cnt ); /* IMP: R-61949-35727 */
103783104384
sqlite3EndBenignMalloc();
103784104385
}else{
103785
- sz = ROUNDDOWN8(sz);
104386
+ sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */
103786104387
pStart = pBuf;
103787104388
}
103788104389
db->lookaside.pStart = pStart;
103789104390
db->lookaside.pFree = 0;
103790104391
db->lookaside.sz = (u16)sz;
@@ -103823,18 +104424,18 @@
103823104424
va_list ap;
103824104425
int rc;
103825104426
va_start(ap, op);
103826104427
switch( op ){
103827104428
case SQLITE_DBCONFIG_LOOKASIDE: {
103828
- void *pBuf = va_arg(ap, void*);
103829
- int sz = va_arg(ap, int);
103830
- int cnt = va_arg(ap, int);
104429
+ void *pBuf = va_arg(ap, void*); /* IMP: R-21112-12275 */
104430
+ int sz = va_arg(ap, int); /* IMP: R-47871-25994 */
104431
+ int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
103831104432
rc = setupLookaside(db, pBuf, sz, cnt);
103832104433
break;
103833104434
}
103834104435
default: {
103835
- rc = SQLITE_ERROR;
104436
+ rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
103836104437
break;
103837104438
}
103838104439
}
103839104440
va_end(ap);
103840104441
return rc;
@@ -103934,16 +104535,33 @@
103934104535
}
103935104536
db->nSavepoint = 0;
103936104537
db->nStatement = 0;
103937104538
db->isTransactionSavepoint = 0;
103938104539
}
104540
+
104541
+/*
104542
+** Invoke the destructor function associated with FuncDef p, if any. Except,
104543
+** if this is not the last copy of the function, do not invoke it. Multiple
104544
+** copies of a single function are created when create_function() is called
104545
+** with SQLITE_ANY as the encoding.
104546
+*/
104547
+static void functionDestroy(sqlite3 *db, FuncDef *p){
104548
+ FuncDestructor *pDestructor = p->pDestructor;
104549
+ if( pDestructor ){
104550
+ pDestructor->nRef--;
104551
+ if( pDestructor->nRef==0 ){
104552
+ pDestructor->xDestroy(pDestructor->pUserData);
104553
+ sqlite3DbFree(db, pDestructor);
104554
+ }
104555
+ }
104556
+}
103939104557
103940104558
/*
103941104559
** Close an existing SQLite database
103942104560
*/
103943104561
SQLITE_API int sqlite3_close(sqlite3 *db){
103944
- HashElem *i;
104562
+ HashElem *i; /* Hash table iterator */
103945104563
int j;
103946104564
103947104565
if( !db ){
103948104566
return SQLITE_OK;
103949104567
}
@@ -104007,10 +104625,11 @@
104007104625
for(j=0; j<ArraySize(db->aFunc.a); j++){
104008104626
FuncDef *pNext, *pHash, *p;
104009104627
for(p=db->aFunc.a[j]; p; p=pHash){
104010104628
pHash = p->pHash;
104011104629
while( p ){
104630
+ functionDestroy(db, p);
104012104631
pNext = p->pNext;
104013104632
sqlite3DbFree(db, p);
104014104633
p = pNext;
104015104634
}
104016104635
}
@@ -104281,11 +104900,12 @@
104281104900
int nArg,
104282104901
int enc,
104283104902
void *pUserData,
104284104903
void (*xFunc)(sqlite3_context*,int,sqlite3_value **),
104285104904
void (*xStep)(sqlite3_context*,int,sqlite3_value **),
104286
- void (*xFinal)(sqlite3_context*)
104905
+ void (*xFinal)(sqlite3_context*),
104906
+ FuncDestructor *pDestructor
104287104907
){
104288104908
FuncDef *p;
104289104909
int nName;
104290104910
104291104911
assert( sqlite3_mutex_held(db->mutex) );
@@ -104309,14 +104929,14 @@
104309104929
if( enc==SQLITE_UTF16 ){
104310104930
enc = SQLITE_UTF16NATIVE;
104311104931
}else if( enc==SQLITE_ANY ){
104312104932
int rc;
104313104933
rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,
104314
- pUserData, xFunc, xStep, xFinal);
104934
+ pUserData, xFunc, xStep, xFinal, pDestructor);
104315104935
if( rc==SQLITE_OK ){
104316104936
rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,
104317
- pUserData, xFunc, xStep, xFinal);
104937
+ pUserData, xFunc, xStep, xFinal, pDestructor);
104318104938
}
104319104939
if( rc!=SQLITE_OK ){
104320104940
return rc;
104321104941
}
104322104942
enc = SQLITE_UTF16BE;
@@ -104345,10 +104965,19 @@
104345104965
p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
104346104966
assert(p || db->mallocFailed);
104347104967
if( !p ){
104348104968
return SQLITE_NOMEM;
104349104969
}
104970
+
104971
+ /* If an older version of the function with a configured destructor is
104972
+ ** being replaced invoke the destructor function here. */
104973
+ functionDestroy(db, p);
104974
+
104975
+ if( pDestructor ){
104976
+ pDestructor->nRef++;
104977
+ }
104978
+ p->pDestructor = pDestructor;
104350104979
p->flags = 0;
104351104980
p->xFunc = xFunc;
104352104981
p->xStep = xStep;
104353104982
p->xFinalize = xFinal;
104354104983
p->pUserData = pUserData;
@@ -104359,21 +104988,53 @@
104359104988
/*
104360104989
** Create new user functions.
104361104990
*/
104362104991
SQLITE_API int sqlite3_create_function(
104363104992
sqlite3 *db,
104364
- const char *zFunctionName,
104993
+ const char *zFunc,
104365104994
int nArg,
104366104995
int enc,
104367104996
void *p,
104368104997
void (*xFunc)(sqlite3_context*,int,sqlite3_value **),
104369104998
void (*xStep)(sqlite3_context*,int,sqlite3_value **),
104370104999
void (*xFinal)(sqlite3_context*)
104371105000
){
104372
- int rc;
105001
+ return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xFunc, xStep,
105002
+ xFinal, 0);
105003
+}
105004
+
105005
+SQLITE_API int sqlite3_create_function_v2(
105006
+ sqlite3 *db,
105007
+ const char *zFunc,
105008
+ int nArg,
105009
+ int enc,
105010
+ void *p,
105011
+ void (*xFunc)(sqlite3_context*,int,sqlite3_value **),
105012
+ void (*xStep)(sqlite3_context*,int,sqlite3_value **),
105013
+ void (*xFinal)(sqlite3_context*),
105014
+ void (*xDestroy)(void *)
105015
+){
105016
+ int rc = SQLITE_ERROR;
105017
+ FuncDestructor *pArg = 0;
104373105018
sqlite3_mutex_enter(db->mutex);
104374
- rc = sqlite3CreateFunc(db, zFunctionName, nArg, enc, p, xFunc, xStep, xFinal);
105019
+ if( xDestroy ){
105020
+ pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
105021
+ if( !pArg ){
105022
+ xDestroy(p);
105023
+ goto out;
105024
+ }
105025
+ pArg->xDestroy = xDestroy;
105026
+ pArg->pUserData = p;
105027
+ }
105028
+ rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, pArg);
105029
+ if( pArg && pArg->nRef==0 ){
105030
+ assert( rc!=SQLITE_OK );
105031
+ xDestroy(p);
105032
+ sqlite3DbFree(db, pArg);
105033
+ }
105034
+
105035
+ out:
104375105036
rc = sqlite3ApiExit(db, rc);
104376105037
sqlite3_mutex_leave(db->mutex);
104377105038
return rc;
104378105039
}
104379105040
@@ -104391,11 +105052,11 @@
104391105052
int rc;
104392105053
char *zFunc8;
104393105054
sqlite3_mutex_enter(db->mutex);
104394105055
assert( !db->mallocFailed );
104395105056
zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
104396
- rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal);
105057
+ rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
104397105058
sqlite3DbFree(db, zFunc8);
104398105059
rc = sqlite3ApiExit(db, rc);
104399105060
sqlite3_mutex_leave(db->mutex);
104400105061
return rc;
104401105062
}
@@ -104422,11 +105083,11 @@
104422105083
int nName = sqlite3Strlen30(zName);
104423105084
int rc;
104424105085
sqlite3_mutex_enter(db->mutex);
104425105086
if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
104426105087
sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
104427
- 0, sqlite3InvalidFunction, 0, 0);
105088
+ 0, sqlite3InvalidFunction, 0, 0, 0);
104428105089
}
104429105090
rc = sqlite3ApiExit(db, SQLITE_OK);
104430105091
sqlite3_mutex_leave(db->mutex);
104431105092
return rc;
104432105093
}
@@ -104560,11 +105221,14 @@
104560105221
** registered using sqlite3_wal_hook(). Likewise, registering a callback
104561105222
** using sqlite3_wal_hook() disables the automatic checkpoint mechanism
104562105223
** configured by this function.
104563105224
*/
104564105225
SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
104565
-#ifndef SQLITE_OMIT_WAL
105226
+#ifdef SQLITE_OMIT_WAL
105227
+ UNUSED_PARAMETER(db);
105228
+ UNUSED_PARAMETER(nFrame);
105229
+#else
104566105230
if( nFrame>0 ){
104567105231
sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
104568105232
}else{
104569105233
sqlite3_wal_hook(db, 0, 0);
104570105234
}
@@ -104690,64 +105354,10 @@
104690105354
#if SQLITE_TEMP_STORE<1 || SQLITE_TEMP_STORE>3
104691105355
return 0;
104692105356
#endif
104693105357
}
104694105358
104695
-/*
104696
-** This routine is called to create a connection to a database BTree
104697
-** driver. If zFilename is the name of a file, then that file is
104698
-** opened and used. If zFilename is the magic name ":memory:" then
104699
-** the database is stored in memory (and is thus forgotten as soon as
104700
-** the connection is closed.) If zFilename is NULL then the database
104701
-** is a "virtual" database for transient use only and is deleted as
104702
-** soon as the connection is closed.
104703
-**
104704
-** A virtual database can be either a disk file (that is automatically
104705
-** deleted when the file is closed) or it an be held entirely in memory.
104706
-** The sqlite3TempInMemory() function is used to determine which.
104707
-*/
104708
-SQLITE_PRIVATE int sqlite3BtreeFactory(
104709
- sqlite3 *db, /* Main database when opening aux otherwise 0 */
104710
- const char *zFilename, /* Name of the file containing the BTree database */
104711
- int omitJournal, /* if TRUE then do not journal this file */
104712
- int nCache, /* How many pages in the page cache */
104713
- int vfsFlags, /* Flags passed through to vfsOpen */
104714
- Btree **ppBtree /* Pointer to new Btree object written here */
104715
-){
104716
- int btFlags = 0;
104717
- int rc;
104718
-
104719
- assert( sqlite3_mutex_held(db->mutex) );
104720
- assert( ppBtree != 0);
104721
- if( omitJournal ){
104722
- btFlags |= BTREE_OMIT_JOURNAL;
104723
- }
104724
- if( db->flags & SQLITE_NoReadlock ){
104725
- btFlags |= BTREE_NO_READLOCK;
104726
- }
104727
-#ifndef SQLITE_OMIT_MEMORYDB
104728
- if( zFilename==0 && sqlite3TempInMemory(db) ){
104729
- zFilename = ":memory:";
104730
- }
104731
-#endif
104732
-
104733
- if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (zFilename==0 || *zFilename==0) ){
104734
- vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB;
104735
- }
104736
- rc = sqlite3BtreeOpen(zFilename, (sqlite3 *)db, ppBtree, btFlags, vfsFlags);
104737
-
104738
- /* If the B-Tree was successfully opened, set the pager-cache size to the
104739
- ** default value. Except, if the call to BtreeOpen() returned a handle
104740
- ** open on an existing shared pager-cache, do not change the pager-cache
104741
- ** size.
104742
- */
104743
- if( rc==SQLITE_OK && 0==sqlite3BtreeSchema(*ppBtree, 0, 0) ){
104744
- sqlite3BtreeSetCacheSize(*ppBtree, nCache);
104745
- }
104746
- return rc;
104747
-}
104748
-
104749105359
/*
104750105360
** Return UTF-8 encoded English language explanation of the most recent
104751105361
** error.
104752105362
*/
104753105363
SQLITE_API const char *sqlite3_errmsg(sqlite3 *db){
@@ -104986,21 +105596,43 @@
104986105596
** It merely prevents new constructs that exceed the limit
104987105597
** from forming.
104988105598
*/
104989105599
SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
104990105600
int oldLimit;
105601
+
105602
+
105603
+ /* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME
105604
+ ** there is a hard upper bound set at compile-time by a C preprocessor
105605
+ ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
105606
+ ** "_MAX_".)
105607
+ */
105608
+ assert( aHardLimit[SQLITE_LIMIT_LENGTH]==SQLITE_MAX_LENGTH );
105609
+ assert( aHardLimit[SQLITE_LIMIT_SQL_LENGTH]==SQLITE_MAX_SQL_LENGTH );
105610
+ assert( aHardLimit[SQLITE_LIMIT_COLUMN]==SQLITE_MAX_COLUMN );
105611
+ assert( aHardLimit[SQLITE_LIMIT_EXPR_DEPTH]==SQLITE_MAX_EXPR_DEPTH );
105612
+ assert( aHardLimit[SQLITE_LIMIT_COMPOUND_SELECT]==SQLITE_MAX_COMPOUND_SELECT);
105613
+ assert( aHardLimit[SQLITE_LIMIT_VDBE_OP]==SQLITE_MAX_VDBE_OP );
105614
+ assert( aHardLimit[SQLITE_LIMIT_FUNCTION_ARG]==SQLITE_MAX_FUNCTION_ARG );
105615
+ assert( aHardLimit[SQLITE_LIMIT_ATTACHED]==SQLITE_MAX_ATTACHED );
105616
+ assert( aHardLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]==
105617
+ SQLITE_MAX_LIKE_PATTERN_LENGTH );
105618
+ assert( aHardLimit[SQLITE_LIMIT_VARIABLE_NUMBER]==SQLITE_MAX_VARIABLE_NUMBER);
105619
+ assert( aHardLimit[SQLITE_LIMIT_TRIGGER_DEPTH]==SQLITE_MAX_TRIGGER_DEPTH );
105620
+ assert( SQLITE_LIMIT_TRIGGER_DEPTH==(SQLITE_N_LIMIT-1) );
105621
+
105622
+
104991105623
if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
104992105624
return -1;
104993105625
}
104994105626
oldLimit = db->aLimit[limitId];
104995
- if( newLimit>=0 ){
105627
+ if( newLimit>=0 ){ /* IMP: R-52476-28732 */
104996105628
if( newLimit>aHardLimit[limitId] ){
104997
- newLimit = aHardLimit[limitId];
105629
+ newLimit = aHardLimit[limitId]; /* IMP: R-51463-25634 */
104998105630
}
104999105631
db->aLimit[limitId] = newLimit;
105000105632
}
105001
- return oldLimit;
105633
+ return oldLimit; /* IMP: R-53341-35419 */
105002105634
}
105003105635
105004105636
/*
105005105637
** This routine does the work of opening a database on behalf of
105006105638
** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
@@ -105019,10 +105651,28 @@
105019105651
*ppDb = 0;
105020105652
#ifndef SQLITE_OMIT_AUTOINIT
105021105653
rc = sqlite3_initialize();
105022105654
if( rc ) return rc;
105023105655
#endif
105656
+
105657
+ /* Only allow sensible combinations of bits in the flags argument.
105658
+ ** Throw an error if any non-sense combination is used. If we
105659
+ ** do not block illegal combinations here, it could trigger
105660
+ ** assert() statements in deeper layers. Sensible combinations
105661
+ ** are:
105662
+ **
105663
+ ** 1: SQLITE_OPEN_READONLY
105664
+ ** 2: SQLITE_OPEN_READWRITE
105665
+ ** 6: SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
105666
+ */
105667
+ assert( SQLITE_OPEN_READONLY == 0x01 );
105668
+ assert( SQLITE_OPEN_READWRITE == 0x02 );
105669
+ assert( SQLITE_OPEN_CREATE == 0x04 );
105670
+ testcase( (1<<(flags&7))==0x02 ); /* READONLY */
105671
+ testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
105672
+ testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
105673
+ if( ((1<<(flags&7)) & 0x46)==0 ) return SQLITE_MISUSE;
105024105674
105025105675
if( sqlite3GlobalConfig.bCoreMutex==0 ){
105026105676
isThreadsafe = 0;
105027105677
}else if( flags & SQLITE_OPEN_NOMUTEX ){
105028105678
isThreadsafe = 0;
@@ -105053,11 +105703,12 @@
105053105703
SQLITE_OPEN_MAIN_JOURNAL |
105054105704
SQLITE_OPEN_TEMP_JOURNAL |
105055105705
SQLITE_OPEN_SUBJOURNAL |
105056105706
SQLITE_OPEN_MASTER_JOURNAL |
105057105707
SQLITE_OPEN_NOMUTEX |
105058
- SQLITE_OPEN_FULLMUTEX
105708
+ SQLITE_OPEN_FULLMUTEX |
105709
+ SQLITE_OPEN_WAL
105059105710
);
105060105711
105061105712
/* Allocate the sqlite data structure */
105062105713
db = sqlite3MallocZero( sizeof(sqlite3) );
105063105714
if( db==0 ) goto opendb_out;
@@ -105125,13 +105776,12 @@
105125105776
createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0,
105126105777
nocaseCollatingFunc, 0);
105127105778
105128105779
/* Open the backend database driver */
105129105780
db->openFlags = flags;
105130
- rc = sqlite3BtreeFactory(db, zFilename, 0, SQLITE_DEFAULT_CACHE_SIZE,
105131
- flags | SQLITE_OPEN_MAIN_DB,
105132
- &db->aDb[0].pBt);
105781
+ rc = sqlite3BtreeOpen(zFilename, db, &db->aDb[0].pBt, 0,
105782
+ flags | SQLITE_OPEN_MAIN_DB);
105133105783
if( rc!=SQLITE_OK ){
105134105784
if( rc==SQLITE_IOERR_NOMEM ){
105135105785
rc = SQLITE_NOMEM;
105136105786
}
105137105787
sqlite3Error(db, rc, 0);
@@ -105833,10 +106483,26 @@
105833106483
*/
105834106484
case SQLITE_TESTCTRL_PGHDRSZ: {
105835106485
rc = sizeof(PgHdr);
105836106486
break;
105837106487
}
106488
+
106489
+ /* sqlite3_test_control(SQLITE_TESTCTRL_SCRATCHMALLOC, sz, &pNew, pFree);
106490
+ **
106491
+ ** Pass pFree into sqlite3ScratchFree().
106492
+ ** If sz>0 then allocate a scratch buffer into pNew.
106493
+ */
106494
+ case SQLITE_TESTCTRL_SCRATCHMALLOC: {
106495
+ void *pFree, **ppNew;
106496
+ int sz;
106497
+ sz = va_arg(ap, int);
106498
+ ppNew = va_arg(ap, void**);
106499
+ pFree = va_arg(ap, void*);
106500
+ if( sz ) *ppNew = sqlite3ScratchMalloc(sz);
106501
+ sqlite3ScratchFree(pFree);
106502
+ break;
106503
+ }
105838106504
105839106505
}
105840106506
va_end(ap);
105841106507
#endif /* SQLITE_OMIT_BUILTIN_TEST */
105842106508
return rc;
@@ -107022,10 +107688,11 @@
107022107688
);
107023107689
SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char const**, int*);
107024107690
SQLITE_PRIVATE int sqlite3Fts3AllSegdirs(Fts3Table*, sqlite3_stmt **);
107025107691
SQLITE_PRIVATE int sqlite3Fts3MatchinfoDocsizeLocal(Fts3Cursor*, u32*);
107026107692
SQLITE_PRIVATE int sqlite3Fts3MatchinfoDocsizeGlobal(Fts3Cursor*, u32*);
107693
+SQLITE_PRIVATE int sqlite3Fts3ReadLock(Fts3Table *);
107027107694
107028107695
/* Flags allowed as part of the 4th argument to SegmentReaderIterate() */
107029107696
#define FTS3_SEGMENT_REQUIRE_POS 0x00000001
107030107697
#define FTS3_SEGMENT_IGNORE_EMPTY 0x00000002
107031107698
#define FTS3_SEGMENT_COLUMN_FILTER 0x00000004
@@ -108971,10 +109638,13 @@
108971109638
zQuery);
108972109639
}
108973109640
return rc;
108974109641
}
108975109642
109643
+ rc = sqlite3Fts3ReadLock(p);
109644
+ if( rc!=SQLITE_OK ) return rc;
109645
+
108976109646
rc = evalFts3Expr(p, pCsr->pExpr, &pCsr->aDoclist, &pCsr->nDoclist, 0);
108977109647
pCsr->pNextId = pCsr->aDoclist;
108978109648
pCsr->iPrevId = 0;
108979109649
}
108980109650
@@ -109349,15 +110019,18 @@
109349110019
static int fts3RenameMethod(
109350110020
sqlite3_vtab *pVtab, /* Virtual table handle */
109351110021
const char *zName /* New name of table */
109352110022
){
109353110023
Fts3Table *p = (Fts3Table *)pVtab;
109354
- sqlite3 *db; /* Database connection */
110024
+ sqlite3 *db = p->db; /* Database connection */
109355110025
int rc; /* Return Code */
109356
-
109357
- db = p->db;
109358
- rc = SQLITE_OK;
110026
+
110027
+ rc = sqlite3Fts3PendingTermsFlush(p);
110028
+ if( rc!=SQLITE_OK ){
110029
+ return rc;
110030
+ }
110031
+
109359110032
fts3DbExec(&rc, db,
109360110033
"ALTER TABLE %Q.'%q_content' RENAME TO '%q_content';",
109361110034
p->zDb, p->zName, zName
109362110035
);
109363110036
if( rc==SQLITE_ERROR ) rc = SQLITE_OK;
@@ -112512,10 +113185,40 @@
112512113185
return SQLITE_CORRUPT;
112513113186
}
112514113187
}
112515113188
return SQLITE_OK;
112516113189
}
113190
+
113191
+/*
113192
+** This function ensures that the caller has obtained a shared-cache
113193
+** table-lock on the %_content table. This is required before reading
113194
+** data from the fts3 table. If this lock is not acquired first, then
113195
+** the caller may end up holding read-locks on the %_segments and %_segdir
113196
+** tables, but no read-lock on the %_content table. If this happens
113197
+** a second connection will be able to write to the fts3 table, but
113198
+** attempting to commit those writes might return SQLITE_LOCKED or
113199
+** SQLITE_LOCKED_SHAREDCACHE (because the commit attempts to obtain
113200
+** write-locks on the %_segments and %_segdir ** tables).
113201
+**
113202
+** We try to avoid this because if FTS3 returns any error when committing
113203
+** a transaction, the whole transaction will be rolled back. And this is
113204
+** not what users expect when they get SQLITE_LOCKED_SHAREDCACHE. It can
113205
+** still happen if the user reads data directly from the %_segments or
113206
+** %_segdir tables instead of going through FTS3 though.
113207
+*/
113208
+SQLITE_PRIVATE int sqlite3Fts3ReadLock(Fts3Table *p){
113209
+ int rc; /* Return code */
113210
+ sqlite3_stmt *pStmt; /* Statement used to obtain lock */
113211
+
113212
+ rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pStmt, 0);
113213
+ if( rc==SQLITE_OK ){
113214
+ sqlite3_bind_null(pStmt, 1);
113215
+ sqlite3_step(pStmt);
113216
+ rc = sqlite3_reset(pStmt);
113217
+ }
113218
+ return rc;
113219
+}
112517113220
112518113221
/*
112519113222
** Set *ppStmt to a statement handle that may be used to iterate through
112520113223
** all rows in the %_segdir table, from oldest to newest. If successful,
112521113224
** return SQLITE_OK. If an error occurs while preparing the statement,
@@ -116003,10 +116706,49 @@
116003116706
**
116004116707
*************************************************************************
116005116708
** This file contains code for implementations of the r-tree and r*-tree
116006116709
** algorithms packaged as an SQLite virtual table module.
116007116710
*/
116711
+
116712
+/*
116713
+** Database Format of R-Tree Tables
116714
+** --------------------------------
116715
+**
116716
+** The data structure for a single virtual r-tree table is stored in three
116717
+** native SQLite tables declared as follows. In each case, the '%' character
116718
+** in the table name is replaced with the user-supplied name of the r-tree
116719
+** table.
116720
+**
116721
+** CREATE TABLE %_node(nodeno INTEGER PRIMARY KEY, data BLOB)
116722
+** CREATE TABLE %_parent(nodeno INTEGER PRIMARY KEY, parentnode INTEGER)
116723
+** CREATE TABLE %_rowid(rowid INTEGER PRIMARY KEY, nodeno INTEGER)
116724
+**
116725
+** The data for each node of the r-tree structure is stored in the %_node
116726
+** table. For each node that is not the root node of the r-tree, there is
116727
+** an entry in the %_parent table associating the node with its parent.
116728
+** And for each row of data in the table, there is an entry in the %_rowid
116729
+** table that maps from the entries rowid to the id of the node that it
116730
+** is stored on.
116731
+**
116732
+** The root node of an r-tree always exists, even if the r-tree table is
116733
+** empty. The nodeno of the root node is always 1. All other nodes in the
116734
+** table must be the same size as the root node. The content of each node
116735
+** is formatted as follows:
116736
+**
116737
+** 1. If the node is the root node (node 1), then the first 2 bytes
116738
+** of the node contain the tree depth as a big-endian integer.
116739
+** For non-root nodes, the first 2 bytes are left unused.
116740
+**
116741
+** 2. The next 2 bytes contain the number of entries currently
116742
+** stored in the node.
116743
+**
116744
+** 3. The remainder of the node contains the node entries. Each entry
116745
+** consists of a single 8-byte integer followed by an even number
116746
+** of 4-byte coordinates. For leaf nodes the integer is the rowid
116747
+** of a record. For internal nodes it is the node number of a
116748
+** child page.
116749
+*/
116008116750
116009116751
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE)
116010116752
116011116753
/*
116012116754
** This file contains an implementation of a couple of different variants
@@ -116044,18 +116786,22 @@
116044116786
#endif
116045116787
#if VARIANT_RSTARTREE_SPLIT
116046116788
#define AssignCells splitNodeStartree
116047116789
#endif
116048116790
116791
+#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
116792
+# define NDEBUG 1
116793
+#endif
116049116794
116050116795
#ifndef SQLITE_CORE
116051116796
SQLITE_EXTENSION_INIT1
116052116797
#else
116053116798
#endif
116054116799
116055116800
116056116801
#ifndef SQLITE_AMALGAMATION
116802
+#include "sqlite3rtree.h"
116057116803
typedef sqlite3_int64 i64;
116058116804
typedef unsigned char u8;
116059116805
typedef unsigned int u32;
116060116806
#endif
116061116807
@@ -116062,10 +116808,12 @@
116062116808
typedef struct Rtree Rtree;
116063116809
typedef struct RtreeCursor RtreeCursor;
116064116810
typedef struct RtreeNode RtreeNode;
116065116811
typedef struct RtreeCell RtreeCell;
116066116812
typedef struct RtreeConstraint RtreeConstraint;
116813
+typedef struct RtreeMatchArg RtreeMatchArg;
116814
+typedef struct RtreeGeomCallback RtreeGeomCallback;
116067116815
typedef union RtreeCoord RtreeCoord;
116068116816
116069116817
/* The rtree may have between 1 and RTREE_MAX_DIMENSIONS dimensions. */
116070116818
#define RTREE_MAX_DIMENSIONS 5
116071116819
@@ -116131,10 +116879,19 @@
116131116879
*/
116132116880
#define RTREE_MINCELLS(p) ((((p)->iNodeSize-4)/(p)->nBytesPerCell)/3)
116133116881
#define RTREE_REINSERT(p) RTREE_MINCELLS(p)
116134116882
#define RTREE_MAXCELLS 51
116135116883
116884
+/*
116885
+** The smallest possible node-size is (512-64)==448 bytes. And the largest
116886
+** supported cell size is 48 bytes (8 byte rowid + ten 4 byte coordinates).
116887
+** Therefore all non-root nodes must contain at least 3 entries. Since
116888
+** 2^40 is greater than 2^64, an r-tree structure always has a depth of
116889
+** 40 or less.
116890
+*/
116891
+#define RTREE_MAX_DEPTH 40
116892
+
116136116893
/*
116137116894
** An rtree cursor object.
116138116895
*/
116139116896
struct RtreeCursor {
116140116897
sqlite3_vtab_cursor base;
@@ -116163,39 +116920,27 @@
116163116920
116164116921
/*
116165116922
** A search constraint.
116166116923
*/
116167116924
struct RtreeConstraint {
116168
- int iCoord; /* Index of constrained coordinate */
116169
- int op; /* Constraining operation */
116170
- double rValue; /* Constraint value. */
116925
+ int iCoord; /* Index of constrained coordinate */
116926
+ int op; /* Constraining operation */
116927
+ double rValue; /* Constraint value. */
116928
+ int (*xGeom)(sqlite3_rtree_geometry *, int, double *, int *);
116929
+ sqlite3_rtree_geometry *pGeom; /* Constraint callback argument for a MATCH */
116171116930
};
116172116931
116173116932
/* Possible values for RtreeConstraint.op */
116174
-#define RTREE_EQ 0x41
116175
-#define RTREE_LE 0x42
116176
-#define RTREE_LT 0x43
116177
-#define RTREE_GE 0x44
116178
-#define RTREE_GT 0x45
116933
+#define RTREE_EQ 0x41
116934
+#define RTREE_LE 0x42
116935
+#define RTREE_LT 0x43
116936
+#define RTREE_GE 0x44
116937
+#define RTREE_GT 0x45
116938
+#define RTREE_MATCH 0x46
116179116939
116180116940
/*
116181116941
** An rtree structure node.
116182
-**
116183
-** Data format (RtreeNode.zData):
116184
-**
116185
-** 1. If the node is the root node (node 1), then the first 2 bytes
116186
-** of the node contain the tree depth as a big-endian integer.
116187
-** For non-root nodes, the first 2 bytes are left unused.
116188
-**
116189
-** 2. The next 2 bytes contain the number of entries currently
116190
-** stored in the node.
116191
-**
116192
-** 3. The remainder of the node contains the node entries. Each entry
116193
-** consists of a single 8-byte integer followed by an even number
116194
-** of 4-byte coordinates. For leaf nodes the integer is the rowid
116195
-** of a record. For internal nodes it is the node number of a
116196
-** child page.
116197116942
*/
116198116943
struct RtreeNode {
116199116944
RtreeNode *pParent; /* Parent node */
116200116945
i64 iNode;
116201116946
int nRef;
@@ -116211,10 +116956,44 @@
116211116956
struct RtreeCell {
116212116957
i64 iRowid;
116213116958
RtreeCoord aCoord[RTREE_MAX_DIMENSIONS*2];
116214116959
};
116215116960
116961
+
116962
+/*
116963
+** Value for the first field of every RtreeMatchArg object. The MATCH
116964
+** operator tests that the first field of a blob operand matches this
116965
+** value to avoid operating on invalid blobs (which could cause a segfault).
116966
+*/
116967
+#define RTREE_GEOMETRY_MAGIC 0x891245AB
116968
+
116969
+/*
116970
+** An instance of this structure must be supplied as a blob argument to
116971
+** the right-hand-side of an SQL MATCH operator used to constrain an
116972
+** r-tree query.
116973
+*/
116974
+struct RtreeMatchArg {
116975
+ u32 magic; /* Always RTREE_GEOMETRY_MAGIC */
116976
+ int (*xGeom)(sqlite3_rtree_geometry *, int, double *, int *);
116977
+ void *pContext;
116978
+ int nParam;
116979
+ double aParam[1];
116980
+};
116981
+
116982
+/*
116983
+** When a geometry callback is created (see sqlite3_rtree_geometry_callback),
116984
+** a single instance of the following structure is allocated. It is used
116985
+** as the context for the user-function created by by s_r_g_c(). The object
116986
+** is eventually deleted by the destructor mechanism provided by
116987
+** sqlite3_create_function_v2() (which is called by s_r_g_c() to create
116988
+** the geometry callback function).
116989
+*/
116990
+struct RtreeGeomCallback {
116991
+ int (*xGeom)(sqlite3_rtree_geometry *, int, double *, int *);
116992
+ void *pContext;
116993
+};
116994
+
116216116995
#ifndef MAX
116217116996
# define MAX(x,y) ((x) < (y) ? (y) : (x))
116218116997
#endif
116219116998
#ifndef MIN
116220116999
# define MIN(x,y) ((x) > (y) ? (y) : (x))
@@ -116293,14 +117072,12 @@
116293117072
116294117073
/*
116295117074
** Clear the content of node p (set all bytes to 0x00).
116296117075
*/
116297117076
static void nodeZero(Rtree *pRtree, RtreeNode *p){
116298
- if( p ){
116299
- memset(&p->zData[2], 0, pRtree->iNodeSize-2);
116300
- p->isDirty = 1;
116301
- }
117077
+ memset(&p->zData[2], 0, pRtree->iNodeSize-2);
117078
+ p->isDirty = 1;
116302117079
}
116303117080
116304117081
/*
116305117082
** Given a node number iNode, return the corresponding key to use
116306117083
** in the Rtree.aHash table.
@@ -116316,26 +117093,23 @@
116316117093
** Search the node hash table for node iNode. If found, return a pointer
116317117094
** to it. Otherwise, return 0.
116318117095
*/
116319117096
static RtreeNode *nodeHashLookup(Rtree *pRtree, i64 iNode){
116320117097
RtreeNode *p;
116321
- assert( iNode!=0 );
116322117098
for(p=pRtree->aHash[nodeHash(iNode)]; p && p->iNode!=iNode; p=p->pNext);
116323117099
return p;
116324117100
}
116325117101
116326117102
/*
116327117103
** Add node pNode to the node hash table.
116328117104
*/
116329117105
static void nodeHashInsert(Rtree *pRtree, RtreeNode *pNode){
116330
- if( pNode ){
116331
- int iHash;
116332
- assert( pNode->pNext==0 );
116333
- iHash = nodeHash(pNode->iNode);
116334
- pNode->pNext = pRtree->aHash[iHash];
116335
- pRtree->aHash[iHash] = pNode;
116336
- }
117106
+ int iHash;
117107
+ assert( pNode->pNext==0 );
117108
+ iHash = nodeHash(pNode->iNode);
117109
+ pNode->pNext = pRtree->aHash[iHash];
117110
+ pRtree->aHash[iHash] = pNode;
116337117111
}
116338117112
116339117113
/*
116340117114
** Remove node pNode from the node hash table.
116341117115
*/
@@ -116353,15 +117127,15 @@
116353117127
** Allocate and return new r-tree node. Initially, (RtreeNode.iNode==0),
116354117128
** indicating that node has not yet been assigned a node number. It is
116355117129
** assigned a node number when nodeWrite() is called to write the
116356117130
** node contents out to the database.
116357117131
*/
116358
-static RtreeNode *nodeNew(Rtree *pRtree, RtreeNode *pParent, int zero){
117132
+static RtreeNode *nodeNew(Rtree *pRtree, RtreeNode *pParent){
116359117133
RtreeNode *pNode;
116360117134
pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode) + pRtree->iNodeSize);
116361117135
if( pNode ){
116362
- memset(pNode, 0, sizeof(RtreeNode) + (zero?pRtree->iNodeSize:0));
117136
+ memset(pNode, 0, sizeof(RtreeNode) + pRtree->iNodeSize);
116363117137
pNode->zData = (u8 *)&pNode[1];
116364117138
pNode->nRef = 1;
116365117139
pNode->pParent = pParent;
116366117140
pNode->isDirty = 1;
116367117141
nodeReference(pParent);
@@ -116378,10 +117152,11 @@
116378117152
i64 iNode, /* Node number to load */
116379117153
RtreeNode *pParent, /* Either the parent node or NULL */
116380117154
RtreeNode **ppNode /* OUT: Acquired node */
116381117155
){
116382117156
int rc;
117157
+ int rc2 = SQLITE_OK;
116383117158
RtreeNode *pNode;
116384117159
116385117160
/* Check if the requested node is already in the hash table. If so,
116386117161
** increase its reference count and return it.
116387117162
*/
@@ -116394,43 +117169,67 @@
116394117169
pNode->nRef++;
116395117170
*ppNode = pNode;
116396117171
return SQLITE_OK;
116397117172
}
116398117173
116399
- pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode) + pRtree->iNodeSize);
116400
- if( !pNode ){
116401
- *ppNode = 0;
116402
- return SQLITE_NOMEM;
116403
- }
116404
- pNode->pParent = pParent;
116405
- pNode->zData = (u8 *)&pNode[1];
116406
- pNode->nRef = 1;
116407
- pNode->iNode = iNode;
116408
- pNode->isDirty = 0;
116409
- pNode->pNext = 0;
116410
-
116411117174
sqlite3_bind_int64(pRtree->pReadNode, 1, iNode);
116412117175
rc = sqlite3_step(pRtree->pReadNode);
116413117176
if( rc==SQLITE_ROW ){
116414117177
const u8 *zBlob = sqlite3_column_blob(pRtree->pReadNode, 0);
116415
- assert( sqlite3_column_bytes(pRtree->pReadNode, 0)==pRtree->iNodeSize );
116416
- memcpy(pNode->zData, zBlob, pRtree->iNodeSize);
116417
- nodeReference(pParent);
117178
+ if( pRtree->iNodeSize==sqlite3_column_bytes(pRtree->pReadNode, 0) ){
117179
+ pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize);
117180
+ if( !pNode ){
117181
+ rc2 = SQLITE_NOMEM;
117182
+ }else{
117183
+ pNode->pParent = pParent;
117184
+ pNode->zData = (u8 *)&pNode[1];
117185
+ pNode->nRef = 1;
117186
+ pNode->iNode = iNode;
117187
+ pNode->isDirty = 0;
117188
+ pNode->pNext = 0;
117189
+ memcpy(pNode->zData, zBlob, pRtree->iNodeSize);
117190
+ nodeReference(pParent);
117191
+ }
117192
+ }
117193
+ }
117194
+ rc = sqlite3_reset(pRtree->pReadNode);
117195
+ if( rc==SQLITE_OK ) rc = rc2;
117196
+
117197
+ /* If the root node was just loaded, set pRtree->iDepth to the height
117198
+ ** of the r-tree structure. A height of zero means all data is stored on
117199
+ ** the root node. A height of one means the children of the root node
117200
+ ** are the leaves, and so on. If the depth as specified on the root node
117201
+ ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
117202
+ */
117203
+ if( pNode && iNode==1 ){
117204
+ pRtree->iDepth = readInt16(pNode->zData);
117205
+ if( pRtree->iDepth>RTREE_MAX_DEPTH ){
117206
+ rc = SQLITE_CORRUPT;
117207
+ }
117208
+ }
117209
+
117210
+ /* If no error has occurred so far, check if the "number of entries"
117211
+ ** field on the node is too large. If so, set the return code to
117212
+ ** SQLITE_CORRUPT.
117213
+ */
117214
+ if( pNode && rc==SQLITE_OK ){
117215
+ if( NCELL(pNode)>((pRtree->iNodeSize-4)/pRtree->nBytesPerCell) ){
117216
+ rc = SQLITE_CORRUPT;
117217
+ }
117218
+ }
117219
+
117220
+ if( rc==SQLITE_OK ){
117221
+ if( pNode!=0 ){
117222
+ nodeHashInsert(pRtree, pNode);
117223
+ }else{
117224
+ rc = SQLITE_CORRUPT;
117225
+ }
117226
+ *ppNode = pNode;
116418117227
}else{
116419117228
sqlite3_free(pNode);
116420
- pNode = 0;
116421
- }
116422
-
116423
- *ppNode = pNode;
116424
- rc = sqlite3_reset(pRtree->pReadNode);
116425
-
116426
- if( rc==SQLITE_OK && iNode==1 ){
116427
- pRtree->iDepth = readInt16(pNode->zData);
116428
- }
116429
-
116430
- assert( (rc==SQLITE_OK && pNode) || (pNode==0 && rc!=SQLITE_OK) );
116431
- nodeHashInsert(pRtree, pNode);
117229
+ *ppNode = 0;
117230
+ }
116432117231
116433117232
return rc;
116434117233
}
116435117234
116436117235
/*
@@ -116479,12 +117278,11 @@
116479117278
int nMaxCell; /* Maximum number of cells for pNode */
116480117279
116481117280
nMaxCell = (pRtree->iNodeSize-4)/pRtree->nBytesPerCell;
116482117281
nCell = NCELL(pNode);
116483117282
116484
- assert(nCell<=nMaxCell);
116485
-
117283
+ assert( nCell<=nMaxCell );
116486117284
if( nCell<nMaxCell ){
116487117285
nodeOverwriteCell(pRtree, pNode, pCell, nCell);
116488117286
writeInt16(&pNode->zData[2], nCell+1);
116489117287
pNode->isDirty = 1;
116490117288
}
@@ -116700,18 +117498,37 @@
116700117498
*ppCursor = (sqlite3_vtab_cursor *)pCsr;
116701117499
116702117500
return rc;
116703117501
}
116704117502
117503
+
117504
+/*
117505
+** Free the RtreeCursor.aConstraint[] array and its contents.
117506
+*/
117507
+static void freeCursorConstraints(RtreeCursor *pCsr){
117508
+ if( pCsr->aConstraint ){
117509
+ int i; /* Used to iterate through constraint array */
117510
+ for(i=0; i<pCsr->nConstraint; i++){
117511
+ sqlite3_rtree_geometry *pGeom = pCsr->aConstraint[i].pGeom;
117512
+ if( pGeom ){
117513
+ if( pGeom->xDelUser ) pGeom->xDelUser(pGeom->pUser);
117514
+ sqlite3_free(pGeom);
117515
+ }
117516
+ }
117517
+ sqlite3_free(pCsr->aConstraint);
117518
+ pCsr->aConstraint = 0;
117519
+ }
117520
+}
117521
+
116705117522
/*
116706117523
** Rtree virtual table module xClose method.
116707117524
*/
116708117525
static int rtreeClose(sqlite3_vtab_cursor *cur){
116709117526
Rtree *pRtree = (Rtree *)(cur->pVtab);
116710117527
int rc;
116711117528
RtreeCursor *pCsr = (RtreeCursor *)cur;
116712
- sqlite3_free(pCsr->aConstraint);
117529
+ freeCursorConstraints(pCsr);
116713117530
rc = nodeRelease(pRtree, pCsr->pNode);
116714117531
sqlite3_free(pCsr);
116715117532
return rc;
116716117533
}
116717117534
@@ -116723,18 +117540,44 @@
116723117540
*/
116724117541
static int rtreeEof(sqlite3_vtab_cursor *cur){
116725117542
RtreeCursor *pCsr = (RtreeCursor *)cur;
116726117543
return (pCsr->pNode==0);
116727117544
}
117545
+
117546
+/*
117547
+** The r-tree constraint passed as the second argument to this function is
117548
+** guaranteed to be a MATCH constraint.
117549
+*/
117550
+static int testRtreeGeom(
117551
+ Rtree *pRtree, /* R-Tree object */
117552
+ RtreeConstraint *pConstraint, /* MATCH constraint to test */
117553
+ RtreeCell *pCell, /* Cell to test */
117554
+ int *pbRes /* OUT: Test result */
117555
+){
117556
+ int i;
117557
+ double aCoord[RTREE_MAX_DIMENSIONS*2];
117558
+ int nCoord = pRtree->nDim*2;
117559
+
117560
+ assert( pConstraint->op==RTREE_MATCH );
117561
+ assert( pConstraint->pGeom );
117562
+
117563
+ for(i=0; i<nCoord; i++){
117564
+ aCoord[i] = DCOORD(pCell->aCoord[i]);
117565
+ }
117566
+ return pConstraint->xGeom(pConstraint->pGeom, nCoord, aCoord, pbRes);
117567
+}
116728117568
116729117569
/*
116730117570
** Cursor pCursor currently points to a cell in a non-leaf page.
116731
-** Return true if the sub-tree headed by the cell is filtered
117571
+** Set *pbEof to true if the sub-tree headed by the cell is filtered
116732117572
** (excluded) by the constraints in the pCursor->aConstraint[]
116733117573
** array, or false otherwise.
117574
+**
117575
+** Return SQLITE_OK if successful or an SQLite error code if an error
117576
+** occurs within a geometry callback.
116734117577
*/
116735
-static int testRtreeCell(Rtree *pRtree, RtreeCursor *pCursor){
117578
+static int testRtreeCell(Rtree *pRtree, RtreeCursor *pCursor, int *pbEof){
116736117579
RtreeCell cell;
116737117580
int ii;
116738117581
int bRes = 0;
116739117582
116740117583
nodeGetCell(pRtree, pCursor->pNode, pCursor->iCell, &cell);
@@ -116742,56 +117585,92 @@
116742117585
RtreeConstraint *p = &pCursor->aConstraint[ii];
116743117586
double cell_min = DCOORD(cell.aCoord[(p->iCoord>>1)*2]);
116744117587
double cell_max = DCOORD(cell.aCoord[(p->iCoord>>1)*2+1]);
116745117588
116746117589
assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
116747
- || p->op==RTREE_GT || p->op==RTREE_EQ
117590
+ || p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_MATCH
116748117591
);
116749117592
116750117593
switch( p->op ){
116751
- case RTREE_LE: case RTREE_LT: bRes = p->rValue<cell_min; break;
116752
- case RTREE_GE: case RTREE_GT: bRes = p->rValue>cell_max; break;
116753
- case RTREE_EQ:
117594
+ case RTREE_LE: case RTREE_LT:
117595
+ bRes = p->rValue<cell_min;
117596
+ break;
117597
+
117598
+ case RTREE_GE: case RTREE_GT:
117599
+ bRes = p->rValue>cell_max;
117600
+ break;
117601
+
117602
+ case RTREE_EQ:
116754117603
bRes = (p->rValue>cell_max || p->rValue<cell_min);
116755117604
break;
117605
+
117606
+ default: {
117607
+ int rc;
117608
+ assert( p->op==RTREE_MATCH );
117609
+ rc = testRtreeGeom(pRtree, p, &cell, &bRes);
117610
+ if( rc!=SQLITE_OK ){
117611
+ return rc;
117612
+ }
117613
+ bRes = !bRes;
117614
+ break;
117615
+ }
116756117616
}
116757117617
}
116758117618
116759
- return bRes;
117619
+ *pbEof = bRes;
117620
+ return SQLITE_OK;
116760117621
}
116761117622
116762117623
/*
116763
-** Return true if the cell that cursor pCursor currently points to
117624
+** Test if the cell that cursor pCursor currently points to
116764117625
** would be filtered (excluded) by the constraints in the
116765
-** pCursor->aConstraint[] array, or false otherwise.
117626
+** pCursor->aConstraint[] array. If so, set *pbEof to true before
117627
+** returning. If the cell is not filtered (excluded) by the constraints,
117628
+** set pbEof to zero.
117629
+**
117630
+** Return SQLITE_OK if successful or an SQLite error code if an error
117631
+** occurs within a geometry callback.
116766117632
**
116767117633
** This function assumes that the cell is part of a leaf node.
116768117634
*/
116769
-static int testRtreeEntry(Rtree *pRtree, RtreeCursor *pCursor){
117635
+static int testRtreeEntry(Rtree *pRtree, RtreeCursor *pCursor, int *pbEof){
116770117636
RtreeCell cell;
116771117637
int ii;
117638
+ *pbEof = 0;
116772117639
116773117640
nodeGetCell(pRtree, pCursor->pNode, pCursor->iCell, &cell);
116774117641
for(ii=0; ii<pCursor->nConstraint; ii++){
116775117642
RtreeConstraint *p = &pCursor->aConstraint[ii];
116776117643
double coord = DCOORD(cell.aCoord[p->iCoord]);
116777117644
int res;
116778117645
assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
116779
- || p->op==RTREE_GT || p->op==RTREE_EQ
117646
+ || p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_MATCH
116780117647
);
116781117648
switch( p->op ){
116782117649
case RTREE_LE: res = (coord<=p->rValue); break;
116783117650
case RTREE_LT: res = (coord<p->rValue); break;
116784117651
case RTREE_GE: res = (coord>=p->rValue); break;
116785117652
case RTREE_GT: res = (coord>p->rValue); break;
116786117653
case RTREE_EQ: res = (coord==p->rValue); break;
117654
+ default: {
117655
+ int rc;
117656
+ assert( p->op==RTREE_MATCH );
117657
+ rc = testRtreeGeom(pRtree, p, &cell, &res);
117658
+ if( rc!=SQLITE_OK ){
117659
+ return rc;
117660
+ }
117661
+ break;
117662
+ }
116787117663
}
116788117664
116789
- if( !res ) return 1;
117665
+ if( !res ){
117666
+ *pbEof = 1;
117667
+ return SQLITE_OK;
117668
+ }
116790117669
}
116791117670
116792
- return 0;
117671
+ return SQLITE_OK;
116793117672
}
116794117673
116795117674
/*
116796117675
** Cursor pCursor currently points at a node that heads a sub-tree of
116797117676
** height iHeight (if iHeight==0, then the node is a leaf). Descend
@@ -116814,17 +117693,17 @@
116814117693
int iSavedCell = pCursor->iCell;
116815117694
116816117695
assert( iHeight>=0 );
116817117696
116818117697
if( iHeight==0 ){
116819
- isEof = testRtreeEntry(pRtree, pCursor);
117698
+ rc = testRtreeEntry(pRtree, pCursor, &isEof);
116820117699
}else{
116821
- isEof = testRtreeCell(pRtree, pCursor);
117700
+ rc = testRtreeCell(pRtree, pCursor, &isEof);
116822117701
}
116823
- if( isEof || iHeight==0 ){
117702
+ if( rc!=SQLITE_OK || isEof || iHeight==0 ){
116824117703
*pEof = isEof;
116825
- return SQLITE_OK;
117704
+ return rc;
116826117705
}
116827117706
116828117707
iRowid = nodeGetRowid(pRtree, pCursor->pNode, pCursor->iCell);
116829117708
rc = nodeAcquire(pRtree, iRowid, pCursor->pNode, &pChild);
116830117709
if( rc!=SQLITE_OK ){
@@ -116856,45 +117735,59 @@
116856117735
116857117736
/*
116858117737
** One of the cells in node pNode is guaranteed to have a 64-bit
116859117738
** integer value equal to iRowid. Return the index of this cell.
116860117739
*/
116861
-static int nodeRowidIndex(Rtree *pRtree, RtreeNode *pNode, i64 iRowid){
117740
+static int nodeRowidIndex(
117741
+ Rtree *pRtree,
117742
+ RtreeNode *pNode,
117743
+ i64 iRowid,
117744
+ int *piIndex
117745
+){
116862117746
int ii;
116863
- for(ii=0; nodeGetRowid(pRtree, pNode, ii)!=iRowid; ii++){
116864
- assert( ii<(NCELL(pNode)-1) );
117747
+ int nCell = NCELL(pNode);
117748
+ for(ii=0; ii<nCell; ii++){
117749
+ if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){
117750
+ *piIndex = ii;
117751
+ return SQLITE_OK;
117752
+ }
116865117753
}
116866
- return ii;
117754
+ return SQLITE_CORRUPT;
116867117755
}
116868117756
116869117757
/*
116870117758
** Return the index of the cell containing a pointer to node pNode
116871117759
** in its parent. If pNode is the root node, return -1.
116872117760
*/
116873
-static int nodeParentIndex(Rtree *pRtree, RtreeNode *pNode){
117761
+static int nodeParentIndex(Rtree *pRtree, RtreeNode *pNode, int *piIndex){
116874117762
RtreeNode *pParent = pNode->pParent;
116875117763
if( pParent ){
116876
- return nodeRowidIndex(pRtree, pParent, pNode->iNode);
117764
+ return nodeRowidIndex(pRtree, pParent, pNode->iNode, piIndex);
116877117765
}
116878
- return -1;
117766
+ *piIndex = -1;
117767
+ return SQLITE_OK;
116879117768
}
116880117769
116881117770
/*
116882117771
** Rtree virtual table module xNext method.
116883117772
*/
116884117773
static int rtreeNext(sqlite3_vtab_cursor *pVtabCursor){
116885117774
Rtree *pRtree = (Rtree *)(pVtabCursor->pVtab);
116886117775
RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
116887117776
int rc = SQLITE_OK;
117777
+
117778
+ /* RtreeCursor.pNode must not be NULL. If is is NULL, then this cursor is
117779
+ ** already at EOF. It is against the rules to call the xNext() method of
117780
+ ** a cursor that has already reached EOF.
117781
+ */
117782
+ assert( pCsr->pNode );
116888117783
116889117784
if( pCsr->iStrategy==1 ){
116890117785
/* This "scan" is a direct lookup by rowid. There is no next entry. */
116891117786
nodeRelease(pRtree, pCsr->pNode);
116892117787
pCsr->pNode = 0;
116893
- }
116894
-
116895
- else if( pCsr->pNode ){
117788
+ }else{
116896117789
/* Move to the next entry that matches the configured constraints. */
116897117790
int iHeight = 0;
116898117791
while( pCsr->pNode ){
116899117792
RtreeNode *pNode = pCsr->pNode;
116900117793
int nCell = NCELL(pNode);
@@ -116904,11 +117797,14 @@
116904117797
if( rc!=SQLITE_OK || !isEof ){
116905117798
return rc;
116906117799
}
116907117800
}
116908117801
pCsr->pNode = pNode->pParent;
116909
- pCsr->iCell = nodeParentIndex(pRtree, pNode);
117802
+ rc = nodeParentIndex(pRtree, pNode, &pCsr->iCell);
117803
+ if( rc!=SQLITE_OK ){
117804
+ return rc;
117805
+ }
116910117806
nodeReference(pCsr->pNode);
116911117807
nodeRelease(pRtree, pNode);
116912117808
iHeight++;
116913117809
}
116914117810
}
@@ -116972,10 +117868,55 @@
116972117868
rc = sqlite3_reset(pRtree->pReadRowid);
116973117869
}
116974117870
return rc;
116975117871
}
116976117872
117873
+/*
117874
+** This function is called to configure the RtreeConstraint object passed
117875
+** as the second argument for a MATCH constraint. The value passed as the
117876
+** first argument to this function is the right-hand operand to the MATCH
117877
+** operator.
117878
+*/
117879
+static int deserializeGeometry(sqlite3_value *pValue, RtreeConstraint *pCons){
117880
+ RtreeMatchArg *p;
117881
+ sqlite3_rtree_geometry *pGeom;
117882
+ int nBlob;
117883
+
117884
+ /* Check that value is actually a blob. */
117885
+ if( !sqlite3_value_type(pValue)==SQLITE_BLOB ) return SQLITE_ERROR;
117886
+
117887
+ /* Check that the blob is roughly the right size. */
117888
+ nBlob = sqlite3_value_bytes(pValue);
117889
+ if( nBlob<sizeof(RtreeMatchArg)
117890
+ || ((nBlob-sizeof(RtreeMatchArg))%sizeof(double))!=0
117891
+ ){
117892
+ return SQLITE_ERROR;
117893
+ }
117894
+
117895
+ pGeom = (sqlite3_rtree_geometry *)sqlite3_malloc(
117896
+ sizeof(sqlite3_rtree_geometry) + nBlob
117897
+ );
117898
+ if( !pGeom ) return SQLITE_NOMEM;
117899
+ memset(pGeom, 0, sizeof(sqlite3_rtree_geometry));
117900
+ p = (RtreeMatchArg *)&pGeom[1];
117901
+
117902
+ memcpy(p, sqlite3_value_blob(pValue), nBlob);
117903
+ if( p->magic!=RTREE_GEOMETRY_MAGIC
117904
+ || nBlob!=(sizeof(RtreeMatchArg) + (p->nParam-1)*sizeof(double))
117905
+ ){
117906
+ sqlite3_free(pGeom);
117907
+ return SQLITE_ERROR;
117908
+ }
117909
+
117910
+ pGeom->pContext = p->pContext;
117911
+ pGeom->nParam = p->nParam;
117912
+ pGeom->aParam = p->aParam;
117913
+
117914
+ pCons->xGeom = p->xGeom;
117915
+ pCons->pGeom = pGeom;
117916
+ return SQLITE_OK;
117917
+}
116977117918
116978117919
/*
116979117920
** Rtree virtual table module xFilter method.
116980117921
*/
116981117922
static int rtreeFilter(
@@ -116990,22 +117931,22 @@
116990117931
int ii;
116991117932
int rc = SQLITE_OK;
116992117933
116993117934
rtreeReference(pRtree);
116994117935
116995
- sqlite3_free(pCsr->aConstraint);
116996
- pCsr->aConstraint = 0;
117936
+ freeCursorConstraints(pCsr);
116997117937
pCsr->iStrategy = idxNum;
116998117938
116999117939
if( idxNum==1 ){
117000117940
/* Special case - lookup by rowid. */
117001117941
RtreeNode *pLeaf; /* Leaf on which the required cell resides */
117002117942
i64 iRowid = sqlite3_value_int64(argv[0]);
117003117943
rc = findLeafNode(pRtree, iRowid, &pLeaf);
117004117944
pCsr->pNode = pLeaf;
117005
- if( pLeaf && rc==SQLITE_OK ){
117006
- pCsr->iCell = nodeRowidIndex(pRtree, pLeaf, iRowid);
117945
+ if( pLeaf ){
117946
+ assert( rc==SQLITE_OK );
117947
+ rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &pCsr->iCell);
117007117948
}
117008117949
}else{
117009117950
/* Normal case - r-tree scan. Set up the RtreeCursor.aConstraint array
117010117951
** with the configured constraints.
117011117952
*/
@@ -117013,16 +117954,28 @@
117013117954
pCsr->aConstraint = sqlite3_malloc(sizeof(RtreeConstraint)*argc);
117014117955
pCsr->nConstraint = argc;
117015117956
if( !pCsr->aConstraint ){
117016117957
rc = SQLITE_NOMEM;
117017117958
}else{
117959
+ memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc);
117018117960
assert( (idxStr==0 && argc==0) || strlen(idxStr)==argc*2 );
117019117961
for(ii=0; ii<argc; ii++){
117020117962
RtreeConstraint *p = &pCsr->aConstraint[ii];
117021117963
p->op = idxStr[ii*2];
117022117964
p->iCoord = idxStr[ii*2+1]-'a';
117023
- p->rValue = sqlite3_value_double(argv[ii]);
117965
+ if( p->op==RTREE_MATCH ){
117966
+ /* A MATCH operator. The right-hand-side must be a blob that
117967
+ ** can be cast into an RtreeMatchArg object. One created using
117968
+ ** an sqlite3_rtree_geometry_callback() SQL user function.
117969
+ */
117970
+ rc = deserializeGeometry(argv[ii], p);
117971
+ if( rc!=SQLITE_OK ){
117972
+ break;
117973
+ }
117974
+ }else{
117975
+ p->rValue = sqlite3_value_double(argv[ii]);
117976
+ }
117024117977
}
117025117978
}
117026117979
}
117027117980
117028117981
if( rc==SQLITE_OK ){
@@ -117078,10 +118031,11 @@
117078118031
** = 0x41 ('A')
117079118032
** <= 0x42 ('B')
117080118033
** < 0x43 ('C')
117081118034
** >= 0x44 ('D')
117082118035
** > 0x45 ('E')
118036
+** MATCH 0x46 ('F')
117083118037
** ----------------------
117084118038
**
117085118039
** The second of each pair of bytes identifies the coordinate column
117086118040
** to which the constraint applies. The leftmost coordinate column
117087118041
** is 'a', the second from the left 'b' etc.
@@ -117116,43 +118070,47 @@
117116118070
*/
117117118071
pIdxInfo->estimatedCost = 10.0;
117118118072
return SQLITE_OK;
117119118073
}
117120118074
117121
- if( p->usable && p->iColumn>0 ){
118075
+ if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
118076
+ int j, opmsk;
118077
+ static const unsigned char compatible[] = { 0, 0, 1, 1, 2, 2 };
117122118078
u8 op = 0;
117123118079
switch( p->op ){
117124118080
case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; break;
117125118081
case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; break;
117126118082
case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break;
117127118083
case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; break;
117128118084
case SQLITE_INDEX_CONSTRAINT_GE: op = RTREE_GE; break;
117129
- }
117130
- if( op ){
117131
- /* Make sure this particular constraint has not been used before.
117132
- ** If it has been used before, ignore it.
117133
- **
117134
- ** A <= or < can be used if there is a prior >= or >.
117135
- ** A >= or > can be used if there is a prior < or <=.
117136
- ** A <= or < is disqualified if there is a prior <=, <, or ==.
117137
- ** A >= or > is disqualified if there is a prior >=, >, or ==.
117138
- ** A == is disqualifed if there is any prior constraint.
117139
- */
117140
- int j, opmsk;
117141
- static const unsigned char compatible[] = { 0, 0, 1, 1, 2, 2 };
117142
- assert( compatible[RTREE_EQ & 7]==0 );
117143
- assert( compatible[RTREE_LT & 7]==1 );
117144
- assert( compatible[RTREE_LE & 7]==1 );
117145
- assert( compatible[RTREE_GT & 7]==2 );
117146
- assert( compatible[RTREE_GE & 7]==2 );
117147
- cCol = p->iColumn - 1 + 'a';
117148
- opmsk = compatible[op & 7];
117149
- for(j=0; j<iIdx; j+=2){
117150
- if( zIdxStr[j+1]==cCol && (compatible[zIdxStr[j] & 7] & opmsk)!=0 ){
117151
- op = 0;
117152
- break;
117153
- }
118085
+ default:
118086
+ assert( p->op==SQLITE_INDEX_CONSTRAINT_MATCH );
118087
+ op = RTREE_MATCH;
118088
+ break;
118089
+ }
118090
+ assert( op!=0 );
118091
+
118092
+ /* Make sure this particular constraint has not been used before.
118093
+ ** If it has been used before, ignore it.
118094
+ **
118095
+ ** A <= or < can be used if there is a prior >= or >.
118096
+ ** A >= or > can be used if there is a prior < or <=.
118097
+ ** A <= or < is disqualified if there is a prior <=, <, or ==.
118098
+ ** A >= or > is disqualified if there is a prior >=, >, or ==.
118099
+ ** A == is disqualifed if there is any prior constraint.
118100
+ */
118101
+ assert( compatible[RTREE_EQ & 7]==0 );
118102
+ assert( compatible[RTREE_LT & 7]==1 );
118103
+ assert( compatible[RTREE_LE & 7]==1 );
118104
+ assert( compatible[RTREE_GT & 7]==2 );
118105
+ assert( compatible[RTREE_GE & 7]==2 );
118106
+ cCol = p->iColumn - 1 + 'a';
118107
+ opmsk = compatible[op & 7];
118108
+ for(j=0; j<iIdx; j+=2){
118109
+ if( zIdxStr[j+1]==cCol && (compatible[zIdxStr[j] & 7] & opmsk)!=0 ){
118110
+ op = 0;
118111
+ break;
117154118112
}
117155118113
}
117156118114
if( op ){
117157118115
assert( iIdx<sizeof(zIdxStr)-1 );
117158118116
zIdxStr[iIdx++] = op;
@@ -117256,11 +118214,16 @@
117256118214
int iExclude
117257118215
){
117258118216
int ii;
117259118217
float overlap = 0.0;
117260118218
for(ii=0; ii<nCell; ii++){
117261
- if( ii!=iExclude ){
118219
+#if VARIANT_RSTARTREE_CHOOSESUBTREE
118220
+ if( ii!=iExclude )
118221
+#else
118222
+ assert( iExclude==-1 );
118223
+#endif
118224
+ {
117262118225
int jj;
117263118226
float o = 1.0;
117264118227
for(jj=0; jj<(pRtree->nDim*2); jj+=2){
117265118228
double x1;
117266118229
double x2;
@@ -117349,26 +118312,35 @@
117349118312
/* Select the child node which will be enlarged the least if pCell
117350118313
** is inserted into it. Resolve ties by choosing the entry with
117351118314
** the smallest area.
117352118315
*/
117353118316
for(iCell=0; iCell<nCell; iCell++){
118317
+ int bBest = 0;
117354118318
float growth;
117355118319
float area;
117356118320
float overlap = 0.0;
117357118321
nodeGetCell(pRtree, pNode, iCell, &cell);
117358118322
growth = cellGrowth(pRtree, &cell, pCell);
117359118323
area = cellArea(pRtree, &cell);
118324
+
117360118325
#if VARIANT_RSTARTREE_CHOOSESUBTREE
117361118326
if( ii==(pRtree->iDepth-1) ){
117362118327
overlap = cellOverlapEnlargement(pRtree,&cell,pCell,aCell,nCell,iCell);
117363118328
}
117364
-#endif
117365118329
if( (iCell==0)
117366118330
|| (overlap<fMinOverlap)
117367118331
|| (overlap==fMinOverlap && growth<fMinGrowth)
117368118332
|| (overlap==fMinOverlap && growth==fMinGrowth && area<fMinArea)
117369118333
){
118334
+ bBest = 1;
118335
+ }
118336
+#else
118337
+ if( iCell==0||growth<fMinGrowth||(growth==fMinGrowth && area<fMinArea) ){
118338
+ bBest = 1;
118339
+ }
118340
+#endif
118341
+ if( bBest ){
117370118342
fMinOverlap = overlap;
117371118343
fMinGrowth = growth;
117372118344
fMinArea = area;
117373118345
iBest = cell.iRowid;
117374118346
}
@@ -117387,29 +118359,34 @@
117387118359
/*
117388118360
** A cell with the same content as pCell has just been inserted into
117389118361
** the node pNode. This function updates the bounding box cells in
117390118362
** all ancestor elements.
117391118363
*/
117392
-static void AdjustTree(
118364
+static int AdjustTree(
117393118365
Rtree *pRtree, /* Rtree table */
117394118366
RtreeNode *pNode, /* Adjust ancestry of this node. */
117395118367
RtreeCell *pCell /* This cell was just inserted */
117396118368
){
117397118369
RtreeNode *p = pNode;
117398118370
while( p->pParent ){
117399
- RtreeCell cell;
117400118371
RtreeNode *pParent = p->pParent;
117401
- int iCell = nodeParentIndex(pRtree, p);
118372
+ RtreeCell cell;
118373
+ int iCell;
118374
+
118375
+ if( nodeParentIndex(pRtree, p, &iCell) ){
118376
+ return SQLITE_CORRUPT;
118377
+ }
117402118378
117403118379
nodeGetCell(pRtree, pParent, iCell, &cell);
117404118380
if( !cellContains(pRtree, &cell, pCell) ){
117405118381
cellUnion(pRtree, &cell, pCell);
117406118382
nodeOverwriteCell(pRtree, pParent, &cell, iCell);
117407118383
}
117408118384
117409118385
p = pParent;
117410118386
}
118387
+ return SQLITE_OK;
117411118388
}
117412118389
117413118390
/*
117414118391
** Write mapping (iRowid->iNode) to the <rtree>_rowid table.
117415118392
*/
@@ -117934,18 +118911,18 @@
117934118911
nodeZero(pRtree, pNode);
117935118912
memcpy(&aCell[nCell], pCell, sizeof(RtreeCell));
117936118913
nCell++;
117937118914
117938118915
if( pNode->iNode==1 ){
117939
- pRight = nodeNew(pRtree, pNode, 1);
117940
- pLeft = nodeNew(pRtree, pNode, 1);
118916
+ pRight = nodeNew(pRtree, pNode);
118917
+ pLeft = nodeNew(pRtree, pNode);
117941118918
pRtree->iDepth++;
117942118919
pNode->isDirty = 1;
117943118920
writeInt16(pNode->zData, pRtree->iDepth);
117944118921
}else{
117945118922
pLeft = pNode;
117946
- pRight = nodeNew(pRtree, pLeft->pParent, 1);
118923
+ pRight = nodeNew(pRtree, pLeft->pParent);
117947118924
nodeReference(pLeft);
117948118925
}
117949118926
117950118927
if( !pLeft || !pRight ){
117951118928
rc = SQLITE_NOMEM;
@@ -117958,12 +118935,16 @@
117958118935
rc = AssignCells(pRtree, aCell, nCell, pLeft, pRight, &leftbbox, &rightbbox);
117959118936
if( rc!=SQLITE_OK ){
117960118937
goto splitnode_out;
117961118938
}
117962118939
117963
- /* Ensure both child nodes have node numbers assigned to them. */
117964
- if( (0==pRight->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pRight)))
118940
+ /* Ensure both child nodes have node numbers assigned to them by calling
118941
+ ** nodeWrite(). Node pRight always needs a node number, as it was created
118942
+ ** by nodeNew() above. But node pLeft sometimes already has a node number.
118943
+ ** In this case avoid the all to nodeWrite().
118944
+ */
118945
+ if( SQLITE_OK!=(rc = nodeWrite(pRtree, pRight))
117965118946
|| (0==pLeft->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pLeft)))
117966118947
){
117967118948
goto splitnode_out;
117968118949
}
117969118950
@@ -117975,13 +118956,19 @@
117975118956
if( rc!=SQLITE_OK ){
117976118957
goto splitnode_out;
117977118958
}
117978118959
}else{
117979118960
RtreeNode *pParent = pLeft->pParent;
117980
- int iCell = nodeParentIndex(pRtree, pLeft);
117981
- nodeOverwriteCell(pRtree, pParent, &leftbbox, iCell);
117982
- AdjustTree(pRtree, pParent, &leftbbox);
118961
+ int iCell;
118962
+ rc = nodeParentIndex(pRtree, pLeft, &iCell);
118963
+ if( rc==SQLITE_OK ){
118964
+ nodeOverwriteCell(pRtree, pParent, &leftbbox, iCell);
118965
+ rc = AdjustTree(pRtree, pParent, &leftbbox);
118966
+ }
118967
+ if( rc!=SQLITE_OK ){
118968
+ goto splitnode_out;
118969
+ }
117983118970
}
117984118971
if( (rc = rtreeInsertCell(pRtree, pRight->pParent, &rightbbox, iHeight+1)) ){
117985118972
goto splitnode_out;
117986118973
}
117987118974
@@ -118021,44 +119008,73 @@
118021119008
nodeRelease(pRtree, pLeft);
118022119009
sqlite3_free(aCell);
118023119010
return rc;
118024119011
}
118025119012
119013
+/*
119014
+** If node pLeaf is not the root of the r-tree and its pParent pointer is
119015
+** still NULL, load all ancestor nodes of pLeaf into memory and populate
119016
+** the pLeaf->pParent chain all the way up to the root node.
119017
+**
119018
+** This operation is required when a row is deleted (or updated - an update
119019
+** is implemented as a delete followed by an insert). SQLite provides the
119020
+** rowid of the row to delete, which can be used to find the leaf on which
119021
+** the entry resides (argument pLeaf). Once the leaf is located, this
119022
+** function is called to determine its ancestry.
119023
+*/
118026119024
static int fixLeafParent(Rtree *pRtree, RtreeNode *pLeaf){
118027119025
int rc = SQLITE_OK;
118028
- if( pLeaf->iNode!=1 && pLeaf->pParent==0 ){
118029
- sqlite3_bind_int64(pRtree->pReadParent, 1, pLeaf->iNode);
118030
- if( sqlite3_step(pRtree->pReadParent)==SQLITE_ROW ){
118031
- i64 iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
118032
- rc = nodeAcquire(pRtree, iNode, 0, &pLeaf->pParent);
118033
- }else{
118034
- rc = SQLITE_ERROR;
118035
- }
118036
- sqlite3_reset(pRtree->pReadParent);
118037
- if( rc==SQLITE_OK ){
118038
- rc = fixLeafParent(pRtree, pLeaf->pParent);
118039
- }
119026
+ RtreeNode *pChild = pLeaf;
119027
+ while( rc==SQLITE_OK && pChild->iNode!=1 && pChild->pParent==0 ){
119028
+ int rc2 = SQLITE_OK; /* sqlite3_reset() return code */
119029
+ sqlite3_bind_int64(pRtree->pReadParent, 1, pChild->iNode);
119030
+ rc = sqlite3_step(pRtree->pReadParent);
119031
+ if( rc==SQLITE_ROW ){
119032
+ RtreeNode *pTest; /* Used to test for reference loops */
119033
+ i64 iNode; /* Node number of parent node */
119034
+
119035
+ /* Before setting pChild->pParent, test that we are not creating a
119036
+ ** loop of references (as we would if, say, pChild==pParent). We don't
119037
+ ** want to do this as it leads to a memory leak when trying to delete
119038
+ ** the referenced counted node structures.
119039
+ */
119040
+ iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
119041
+ for(pTest=pLeaf; pTest && pTest->iNode!=iNode; pTest=pTest->pParent);
119042
+ if( !pTest ){
119043
+ rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
119044
+ }
119045
+ }
119046
+ rc = sqlite3_reset(pRtree->pReadParent);
119047
+ if( rc==SQLITE_OK ) rc = rc2;
119048
+ if( rc==SQLITE_OK && !pChild->pParent ) rc = SQLITE_CORRUPT;
119049
+ pChild = pChild->pParent;
118040119050
}
118041119051
return rc;
118042119052
}
118043119053
118044119054
static int deleteCell(Rtree *, RtreeNode *, int, int);
118045119055
118046119056
static int removeNode(Rtree *pRtree, RtreeNode *pNode, int iHeight){
118047119057
int rc;
119058
+ int rc2;
118048119059
RtreeNode *pParent;
118049119060
int iCell;
118050119061
118051119062
assert( pNode->nRef==1 );
118052119063
118053119064
/* Remove the entry in the parent cell. */
118054
- iCell = nodeParentIndex(pRtree, pNode);
118055
- pParent = pNode->pParent;
118056
- pNode->pParent = 0;
118057
- if( SQLITE_OK!=(rc = deleteCell(pRtree, pParent, iCell, iHeight+1))
118058
- || SQLITE_OK!=(rc = nodeRelease(pRtree, pParent))
118059
- ){
119065
+ rc = nodeParentIndex(pRtree, pNode, &iCell);
119066
+ if( rc==SQLITE_OK ){
119067
+ pParent = pNode->pParent;
119068
+ pNode->pParent = 0;
119069
+ rc = deleteCell(pRtree, pParent, iCell, iHeight+1);
119070
+ }
119071
+ rc2 = nodeRelease(pRtree, pParent);
119072
+ if( rc==SQLITE_OK ){
119073
+ rc = rc2;
119074
+ }
119075
+ if( rc!=SQLITE_OK ){
118060119076
return rc;
118061119077
}
118062119078
118063119079
/* Remove the xxx_node entry. */
118064119080
sqlite3_bind_int64(pRtree->pDeleteNode, 1, pNode->iNode);
@@ -118084,12 +119100,13 @@
118084119100
pRtree->pDeleted = pNode;
118085119101
118086119102
return SQLITE_OK;
118087119103
}
118088119104
118089
-static void fixBoundingBox(Rtree *pRtree, RtreeNode *pNode){
119105
+static int fixBoundingBox(Rtree *pRtree, RtreeNode *pNode){
118090119106
RtreeNode *pParent = pNode->pParent;
119107
+ int rc = SQLITE_OK;
118091119108
if( pParent ){
118092119109
int ii;
118093119110
int nCell = NCELL(pNode);
118094119111
RtreeCell box; /* Bounding box for pNode */
118095119112
nodeGetCell(pRtree, pNode, 0, &box);
@@ -118097,21 +119114,25 @@
118097119114
RtreeCell cell;
118098119115
nodeGetCell(pRtree, pNode, ii, &cell);
118099119116
cellUnion(pRtree, &box, &cell);
118100119117
}
118101119118
box.iRowid = pNode->iNode;
118102
- ii = nodeParentIndex(pRtree, pNode);
118103
- nodeOverwriteCell(pRtree, pParent, &box, ii);
118104
- fixBoundingBox(pRtree, pParent);
119119
+ rc = nodeParentIndex(pRtree, pNode, &ii);
119120
+ if( rc==SQLITE_OK ){
119121
+ nodeOverwriteCell(pRtree, pParent, &box, ii);
119122
+ rc = fixBoundingBox(pRtree, pParent);
119123
+ }
118105119124
}
119125
+ return rc;
118106119126
}
118107119127
118108119128
/*
118109119129
** Delete the cell at index iCell of node pNode. After removing the
118110119130
** cell, adjust the r-tree data structure if required.
118111119131
*/
118112119132
static int deleteCell(Rtree *pRtree, RtreeNode *pNode, int iCell, int iHeight){
119133
+ RtreeNode *pParent;
118113119134
int rc;
118114119135
118115119136
if( SQLITE_OK!=(rc = fixLeafParent(pRtree, pNode)) ){
118116119137
return rc;
118117119138
}
@@ -118124,18 +119145,17 @@
118124119145
/* If the node is not the tree root and now has less than the minimum
118125119146
** number of cells, remove it from the tree. Otherwise, update the
118126119147
** cell in the parent node so that it tightly contains the updated
118127119148
** node.
118128119149
*/
118129
- if( pNode->iNode!=1 ){
118130
- RtreeNode *pParent = pNode->pParent;
118131
- if( (pParent->iNode!=1 || NCELL(pParent)!=1)
118132
- && (NCELL(pNode)<RTREE_MINCELLS(pRtree))
118133
- ){
119150
+ pParent = pNode->pParent;
119151
+ assert( pParent || pNode->iNode==1 );
119152
+ if( pParent ){
119153
+ if( NCELL(pNode)<RTREE_MINCELLS(pRtree) ){
118134119154
rc = removeNode(pRtree, pNode, iHeight);
118135119155
}else{
118136
- fixBoundingBox(pRtree, pNode);
119156
+ rc = fixBoundingBox(pRtree, pNode);
118137119157
}
118138119158
}
118139119159
118140119160
return rc;
118141119161
}
@@ -118214,11 +119234,11 @@
118214119234
rc = parentWrite(pRtree, p->iRowid, pNode->iNode);
118215119235
}
118216119236
}
118217119237
}
118218119238
if( rc==SQLITE_OK ){
118219
- fixBoundingBox(pRtree, pNode);
119239
+ rc = fixBoundingBox(pRtree, pNode);
118220119240
}
118221119241
for(; rc==SQLITE_OK && ii<nCell; ii++){
118222119242
/* Find a node to store this cell in. pNode->iNode currently contains
118223119243
** the height of the sub-tree headed by the cell.
118224119244
*/
@@ -118268,15 +119288,17 @@
118268119288
}
118269119289
#else
118270119290
rc = SplitNode(pRtree, pNode, pCell, iHeight);
118271119291
#endif
118272119292
}else{
118273
- AdjustTree(pRtree, pNode, pCell);
118274
- if( iHeight==0 ){
118275
- rc = rowidWrite(pRtree, pCell->iRowid, pNode->iNode);
118276
- }else{
118277
- rc = parentWrite(pRtree, pCell->iRowid, pNode->iNode);
119293
+ rc = AdjustTree(pRtree, pNode, pCell);
119294
+ if( rc==SQLITE_OK ){
119295
+ if( iHeight==0 ){
119296
+ rc = rowidWrite(pRtree, pCell->iRowid, pNode->iNode);
119297
+ }else{
119298
+ rc = parentWrite(pRtree, pCell->iRowid, pNode->iNode);
119299
+ }
118278119300
}
118279119301
}
118280119302
return rc;
118281119303
}
118282119304
@@ -118342,11 +119364,10 @@
118342119364
int rc = SQLITE_OK;
118343119365
118344119366
rtreeReference(pRtree);
118345119367
118346119368
assert(nData>=1);
118347
- assert(hashIsEmpty(pRtree));
118348119369
118349119370
/* If azData[0] is not an SQL NULL value, it is the rowid of a
118350119371
** record to delete from the r-tree table. The following block does
118351119372
** just that.
118352119373
*/
@@ -118368,12 +119389,14 @@
118368119389
}
118369119390
118370119391
/* Delete the cell in question from the leaf node. */
118371119392
if( rc==SQLITE_OK ){
118372119393
int rc2;
118373
- iCell = nodeRowidIndex(pRtree, pLeaf, iDelete);
118374
- rc = deleteCell(pRtree, pLeaf, iCell, 0);
119394
+ rc = nodeRowidIndex(pRtree, pLeaf, iDelete, &iCell);
119395
+ if( rc==SQLITE_OK ){
119396
+ rc = deleteCell(pRtree, pLeaf, iCell, 0);
119397
+ }
118375119398
rc2 = nodeRelease(pRtree, pLeaf);
118376119399
if( rc==SQLITE_OK ){
118377119400
rc = rc2;
118378119401
}
118379119402
}
@@ -118391,23 +119414,24 @@
118391119414
**
118392119415
** This is equivalent to copying the contents of the child into
118393119416
** the root node (the operation that Gutman's paper says to perform
118394119417
** in this scenario).
118395119418
*/
118396
- if( rc==SQLITE_OK && pRtree->iDepth>0 ){
118397
- if( rc==SQLITE_OK && NCELL(pRoot)==1 ){
118398
- RtreeNode *pChild;
118399
- i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
118400
- rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
118401
- if( rc==SQLITE_OK ){
118402
- rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
118403
- }
118404
- if( rc==SQLITE_OK ){
118405
- pRtree->iDepth--;
118406
- writeInt16(pRoot->zData, pRtree->iDepth);
118407
- pRoot->isDirty = 1;
118408
- }
119419
+ if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
119420
+ int rc2;
119421
+ RtreeNode *pChild;
119422
+ i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
119423
+ rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
119424
+ if( rc==SQLITE_OK ){
119425
+ rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
119426
+ }
119427
+ rc2 = nodeRelease(pRtree, pChild);
119428
+ if( rc==SQLITE_OK ) rc = rc2;
119429
+ if( rc==SQLITE_OK ){
119430
+ pRtree->iDepth--;
119431
+ writeInt16(pRoot->zData, pRtree->iDepth);
119432
+ pRoot->isDirty = 1;
118409119433
}
118410119434
}
118411119435
118412119436
/* Re-insert the contents of any underfull nodes removed from the tree. */
118413119437
for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){
@@ -118693,11 +119717,11 @@
118693119717
){
118694119718
int rc = SQLITE_OK;
118695119719
Rtree *pRtree;
118696119720
int nDb; /* Length of string argv[1] */
118697119721
int nName; /* Length of string argv[2] */
118698
- int eCoordType = (int)pAux;
119722
+ int eCoordType = (pAux ? RTREE_COORD_INT32 : RTREE_COORD_REAL32);
118699119723
118700119724
const char *aErrMsg[] = {
118701119725
0, /* 0 */
118702119726
"Wrong number of columns for an rtree table", /* 1 */
118703119727
"Too few columns for an rtree table", /* 2 */
@@ -118839,16 +119863,14 @@
118839119863
** Register the r-tree module with database handle db. This creates the
118840119864
** virtual table module "rtree" and the debugging/analysis scalar
118841119865
** function "rtreenode".
118842119866
*/
118843119867
SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db){
118844
- int rc = SQLITE_OK;
119868
+ const int utf8 = SQLITE_UTF8;
119869
+ int rc;
118845119870
118846
- if( rc==SQLITE_OK ){
118847
- int utf8 = SQLITE_UTF8;
118848
- rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
118849
- }
119871
+ rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
118850119872
if( rc==SQLITE_OK ){
118851119873
int utf8 = SQLITE_UTF8;
118852119874
rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
118853119875
}
118854119876
if( rc==SQLITE_OK ){
@@ -118860,10 +119882,74 @@
118860119882
rc = sqlite3_create_module_v2(db, "rtree_i32", &rtreeModule, c, 0);
118861119883
}
118862119884
118863119885
return rc;
118864119886
}
119887
+
119888
+/*
119889
+** A version of sqlite3_free() that can be used as a callback. This is used
119890
+** in two places - as the destructor for the blob value returned by the
119891
+** invocation of a geometry function, and as the destructor for the geometry
119892
+** functions themselves.
119893
+*/
119894
+static void doSqlite3Free(void *p){
119895
+ sqlite3_free(p);
119896
+}
119897
+
119898
+/*
119899
+** Each call to sqlite3_rtree_geometry_callback() creates an ordinary SQLite
119900
+** scalar user function. This C function is the callback used for all such
119901
+** registered SQL functions.
119902
+**
119903
+** The scalar user functions return a blob that is interpreted by r-tree
119904
+** table MATCH operators.
119905
+*/
119906
+static void geomCallback(sqlite3_context *ctx, int nArg, sqlite3_value **aArg){
119907
+ RtreeGeomCallback *pGeomCtx = (RtreeGeomCallback *)sqlite3_user_data(ctx);
119908
+ RtreeMatchArg *pBlob;
119909
+ int nBlob;
119910
+
119911
+ nBlob = sizeof(RtreeMatchArg) + (nArg-1)*sizeof(double);
119912
+ pBlob = (RtreeMatchArg *)sqlite3_malloc(nBlob);
119913
+ if( !pBlob ){
119914
+ sqlite3_result_error_nomem(ctx);
119915
+ }else{
119916
+ int i;
119917
+ pBlob->magic = RTREE_GEOMETRY_MAGIC;
119918
+ pBlob->xGeom = pGeomCtx->xGeom;
119919
+ pBlob->pContext = pGeomCtx->pContext;
119920
+ pBlob->nParam = nArg;
119921
+ for(i=0; i<nArg; i++){
119922
+ pBlob->aParam[i] = sqlite3_value_double(aArg[i]);
119923
+ }
119924
+ sqlite3_result_blob(ctx, pBlob, nBlob, doSqlite3Free);
119925
+ }
119926
+}
119927
+
119928
+/*
119929
+** Register a new geometry function for use with the r-tree MATCH operator.
119930
+*/
119931
+SQLITE_API int sqlite3_rtree_geometry_callback(
119932
+ sqlite3 *db,
119933
+ const char *zGeom,
119934
+ int (*xGeom)(sqlite3_rtree_geometry *, int, double *, int *),
119935
+ void *pContext
119936
+){
119937
+ RtreeGeomCallback *pGeomCtx; /* Context object for new user-function */
119938
+
119939
+ /* Allocate and populate the context object. */
119940
+ pGeomCtx = (RtreeGeomCallback *)sqlite3_malloc(sizeof(RtreeGeomCallback));
119941
+ if( !pGeomCtx ) return SQLITE_NOMEM;
119942
+ pGeomCtx->xGeom = xGeom;
119943
+ pGeomCtx->pContext = pContext;
119944
+
119945
+ /* Create the new user-function. Register a destructor function to delete
119946
+ ** the context object when it is no longer required. */
119947
+ return sqlite3_create_function_v2(db, zGeom, -1, SQLITE_ANY,
119948
+ (void *)pGeomCtx, geomCallback, 0, 0, doSqlite3Free
119949
+ );
119950
+}
118865119951
118866119952
#if !SQLITE_CORE
118867119953
SQLITE_API int sqlite3_extension_init(
118868119954
sqlite3 *db,
118869119955
char **pzErrMsg,
118870119956
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.7.2. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a one translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% are more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -352,19 +352,25 @@
352 # define SQLITE_INT_TO_PTR(X) ((void*)(X))
353 # define SQLITE_PTR_TO_INT(X) ((int)(X))
354 #endif
355
356 /*
357 ** The SQLITE_THREADSAFE macro must be defined as either 0 or 1.
 
 
 
 
 
 
358 ** Older versions of SQLite used an optional THREADSAFE macro.
359 ** We support that for legacy
360 */
361 #if !defined(SQLITE_THREADSAFE)
362 #if defined(THREADSAFE)
363 # define SQLITE_THREADSAFE THREADSAFE
364 #else
365 # define SQLITE_THREADSAFE 1
366 #endif
367 #endif
368
369 /*
370 ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
@@ -642,13 +648,13 @@
642 **
643 ** See also: [sqlite3_libversion()],
644 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
645 ** [sqlite_version()] and [sqlite_source_id()].
646 */
647 #define SQLITE_VERSION "3.7.2"
648 #define SQLITE_VERSION_NUMBER 3007002
649 #define SQLITE_SOURCE_ID "2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3"
650
651 /*
652 ** CAPI3REF: Run-Time Library Version Numbers
653 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
654 **
@@ -1292,19 +1298,23 @@
1292 ** object once the object has been registered.
1293 **
1294 ** The zName field holds the name of the VFS module. The name must
1295 ** be unique across all VFS modules.
1296 **
1297 ** SQLite will guarantee that the zFilename parameter to xOpen
1298 ** is either a NULL pointer or string obtained
1299 ** from xFullPathname(). SQLite further guarantees that
 
 
 
 
1300 ** the string will be valid and unchanged until xClose() is
1301 ** called. Because of the previous sentence,
1302 ** the [sqlite3_file] can safely store a pointer to the
1303 ** filename if it needs to remember the filename for some reason.
1304 ** If the zFilename parameter is xOpen is a NULL pointer then xOpen
1305 ** must invent its own temporary name for the file. Whenever the
1306 ** xFilename parameter is NULL it will also be the case that the
1307 ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
1308 **
1309 ** The flags argument to xOpen() includes all bits set in
1310 ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
@@ -1311,11 +1321,11 @@
1311 ** or [sqlite3_open16()] is used, then flags includes at least
1312 ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
1313 ** If xOpen() opens a file read-only then it sets *pOutFlags to
1314 ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
1315 **
1316 ** SQLite will also add one of the following flags to the xOpen()
1317 ** call, depending on the object being opened:
1318 **
1319 ** <ul>
1320 ** <li> [SQLITE_OPEN_MAIN_DB]
1321 ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
@@ -1322,11 +1332,12 @@
1322 ** <li> [SQLITE_OPEN_TEMP_DB]
1323 ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
1324 ** <li> [SQLITE_OPEN_TRANSIENT_DB]
1325 ** <li> [SQLITE_OPEN_SUBJOURNAL]
1326 ** <li> [SQLITE_OPEN_MASTER_JOURNAL]
1327 ** </ul>
 
1328 **
1329 ** The file I/O implementation can use the object type flags to
1330 ** change the way it deals with files. For example, an application
1331 ** that does not care about crash recovery or rollback might make
1332 ** the open of a journal file a no-op. Writes to this journal would
@@ -1341,39 +1352,40 @@
1341 ** <li> [SQLITE_OPEN_DELETEONCLOSE]
1342 ** <li> [SQLITE_OPEN_EXCLUSIVE]
1343 ** </ul>
1344 **
1345 ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
1346 ** deleted when it is closed. The [SQLITE_OPEN_DELETEONCLOSE]
1347 ** will be set for TEMP databases, journals and for subjournals.
 
1348 **
1349 ** The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
1350 ** with the [SQLITE_OPEN_CREATE] flag, which are both directly
1351 ** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
1352 ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
1353 ** SQLITE_OPEN_CREATE, is used to indicate that file should always
1354 ** be created, and that it is an error if it already exists.
1355 ** It is <i>not</i> used to indicate the file should be opened
1356 ** for exclusive access.
1357 **
1358 ** At least szOsFile bytes of memory are allocated by SQLite
1359 ** to hold the [sqlite3_file] structure passed as the third
1360 ** argument to xOpen. The xOpen method does not have to
1361 ** allocate the structure; it should just fill it in. Note that
1362 ** the xOpen method must set the sqlite3_file.pMethods to either
1363 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
1364 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
1365 ** element will be valid after xOpen returns regardless of the success
1366 ** or failure of the xOpen call.
1367 **
1368 ** The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
1369 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
1370 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
1371 ** to test whether a file is at least readable. The file can be a
1372 ** directory.
1373 **
1374 ** SQLite will always allocate at least mxPathname+1 bytes for the
1375 ** output buffer xFullPathname. The exact size of the output buffer
1376 ** is also passed as a parameter to both methods. If the output buffer
1377 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
1378 ** handled as a fatal error by SQLite, vfs implementations should endeavor
1379 ** to prevent this by setting mxPathname to a sufficiently large value.
@@ -1383,14 +1395,14 @@
1383 ** included in the VFS structure for completeness.
1384 ** The xRandomness() function attempts to return nBytes bytes
1385 ** of good-quality randomness into zOut. The return value is
1386 ** the actual number of bytes of randomness obtained.
1387 ** The xSleep() method causes the calling thread to sleep for at
1388 ** least the number of microseconds given. The xCurrentTime()
1389 ** method returns a Julian Day Number for the current date and time as
1390 ** a floating point value.
1391 ** The xCurrentTimeInt64() method returns, as an integer, the Julian
1392 ** Day Number multipled by 86400000 (the number of milliseconds in
1393 ** a 24-hour day).
1394 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
1395 ** date and time if that method is available (if iVersion is 2 or
1396 ** greater and the function pointer is not NULL) and will fall back
@@ -1783,11 +1795,11 @@
1783 ** statistics. ^(When memory allocation statistics are disabled, the
1784 ** following SQLite interfaces become non-operational:
1785 ** <ul>
1786 ** <li> [sqlite3_memory_used()]
1787 ** <li> [sqlite3_memory_highwater()]
1788 ** <li> [sqlite3_soft_heap_limit()]
1789 ** <li> [sqlite3_status()]
1790 ** </ul>)^
1791 ** ^Memory allocation statistics are enabled by default unless SQLite is
1792 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1793 ** allocation statistics are disabled by default.
@@ -1797,19 +1809,18 @@
1797 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1798 ** scratch memory. There are three arguments: A pointer an 8-byte
1799 ** aligned memory buffer from which the scrach allocations will be
1800 ** drawn, the size of each scratch allocation (sz),
1801 ** and the maximum number of scratch allocations (N). The sz
1802 ** argument must be a multiple of 16. The sz parameter should be a few bytes
1803 ** larger than the actual scratch space required due to internal overhead.
1804 ** The first argument must be a pointer to an 8-byte aligned buffer
1805 ** of at least sz*N bytes of memory.
1806 ** ^SQLite will use no more than one scratch buffer per thread. So
1807 ** N should be set to the expected maximum number of threads. ^SQLite will
1808 ** never require a scratch buffer that is more than 6 times the database
1809 ** page size. ^If SQLite needs needs additional scratch memory beyond
1810 ** what is provided by this configuration option, then
1811 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
1812 **
1813 ** <dt>SQLITE_CONFIG_PAGECACHE</dt>
1814 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1815 ** the database page cache with the default page cache implemenation.
@@ -1825,12 +1836,11 @@
1825 ** argument should point to an allocation of at least sz*N bytes of memory.
1826 ** ^SQLite will use the memory provided by the first argument to satisfy its
1827 ** memory needs for the first N pages that it adds to cache. ^If additional
1828 ** page cache memory is needed beyond what is provided by this option, then
1829 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1830 ** ^The implementation might use one or more of the N buffers to hold
1831 ** memory accounting information. The pointer in the first argument must
1832 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1833 ** will be undefined.</dd>
1834 **
1835 ** <dt>SQLITE_CONFIG_HEAP</dt>
1836 ** <dd> ^This option specifies a static memory buffer that SQLite will use
@@ -1955,12 +1965,18 @@
1955 ** size of each lookaside buffer slot. ^The third argument is the number of
1956 ** slots. The size of the buffer in the first argument must be greater than
1957 ** or equal to the product of the second and third arguments. The buffer
1958 ** must be aligned to an 8-byte boundary. ^If the second argument to
1959 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
1960 ** rounded down to the next smaller
1961 ** multiple of 8. See also: [SQLITE_CONFIG_LOOKASIDE]</dd>
 
 
 
 
 
 
1962 **
1963 ** </dl>
1964 */
1965 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1966
@@ -2260,10 +2276,13 @@
2260 */
2261 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
2262
2263 /*
2264 ** CAPI3REF: Convenience Routines For Running Queries
 
 
 
2265 **
2266 ** Definition: A <b>result table</b> is memory data structure created by the
2267 ** [sqlite3_get_table()] interface. A result table records the
2268 ** complete query results from one or more queries.
2269 **
@@ -2281,11 +2300,11 @@
2281 **
2282 ** A result table might consist of one or more memory allocations.
2283 ** It is not safe to pass a result table directly to [sqlite3_free()].
2284 ** A result table should be deallocated using [sqlite3_free_table()].
2285 **
2286 ** As an example of the result table format, suppose a query result
2287 ** is as follows:
2288 **
2289 ** <blockquote><pre>
2290 ** Name | Age
2291 ** -----------------------
@@ -2305,31 +2324,31 @@
2305 ** azResult&#91;3] = "43";
2306 ** azResult&#91;4] = "Bob";
2307 ** azResult&#91;5] = "28";
2308 ** azResult&#91;6] = "Cindy";
2309 ** azResult&#91;7] = "21";
2310 ** </pre></blockquote>
2311 **
2312 ** ^The sqlite3_get_table() function evaluates one or more
2313 ** semicolon-separated SQL statements in the zero-terminated UTF-8
2314 ** string of its 2nd parameter and returns a result table to the
2315 ** pointer given in its 3rd parameter.
2316 **
2317 ** After the application has finished with the result from sqlite3_get_table(),
2318 ** it should pass the result table pointer to sqlite3_free_table() in order to
2319 ** release the memory that was malloced. Because of the way the
2320 ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
2321 ** function must not try to call [sqlite3_free()] directly. Only
2322 ** [sqlite3_free_table()] is able to release the memory properly and safely.
2323 **
2324 ** ^(The sqlite3_get_table() interface is implemented as a wrapper around
2325 ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
2326 ** to any internal data structures of SQLite. It uses only the public
2327 ** interface defined here. As a consequence, errors that occur in the
2328 ** wrapper layer outside of the internal [sqlite3_exec()] call are not
2329 ** reflected in subsequent calls to [sqlite3_errcode()] or
2330 ** [sqlite3_errmsg()].)^
2331 */
2332 SQLITE_API int sqlite3_get_table(
2333 sqlite3 *db, /* An open database */
2334 const char *zSql, /* SQL to be evaluated */
2335 char ***pazResult, /* Results of the query */
@@ -2477,11 +2496,13 @@
2477 ** by sqlite3_realloc() and the prior allocation is freed.
2478 ** ^If sqlite3_realloc() returns NULL, then the prior allocation
2479 ** is not freed.
2480 **
2481 ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
2482 ** is always aligned to at least an 8 byte boundary.
 
 
2483 **
2484 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
2485 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
2486 ** implementation of these routines to be omitted. That capability
2487 ** is no longer provided. Only built-in memory allocators can be used.
@@ -2735,21 +2756,32 @@
2735 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2736
2737 /*
2738 ** CAPI3REF: Query Progress Callbacks
2739 **
2740 ** ^This routine configures a callback function - the
2741 ** progress callback - that is invoked periodically during long
2742 ** running calls to [sqlite3_exec()], [sqlite3_step()] and
2743 ** [sqlite3_get_table()]. An example use for this
2744 ** interface is to keep a GUI updated during a large query.
 
 
 
 
 
 
 
 
 
 
 
2745 **
2746 ** ^If the progress callback returns non-zero, the operation is
2747 ** interrupted. This feature can be used to implement a
2748 ** "Cancel" button on a GUI progress dialog box.
2749 **
2750 ** The progress handler must not do anything that will modify
2751 ** the database connection that invoked the progress handler.
2752 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
2753 ** database connections for the meaning of "modify" in this paragraph.
2754 **
2755 */
@@ -2804,11 +2836,11 @@
2804 ** </dl>
2805 **
2806 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
2807 ** combinations shown above or one of the combinations shown above combined
2808 ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
2809 ** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_SHAREDCACHE] flags,
2810 ** then the behavior is undefined.
2811 **
2812 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
2813 ** opens in the multi-thread [threading mode] as long as the single-thread
2814 ** mode has not been set at compile-time or start-time. ^If the
@@ -2929,21 +2961,26 @@
2929 ** ^(This interface allows the size of various constructs to be limited
2930 ** on a connection by connection basis. The first parameter is the
2931 ** [database connection] whose limit is to be set or queried. The
2932 ** second parameter is one of the [limit categories] that define a
2933 ** class of constructs to be size limited. The third parameter is the
2934 ** new limit for that construct. The function returns the old limit.)^
2935 **
2936 ** ^If the new limit is a negative number, the limit is unchanged.
2937 ** ^(For the limit category of SQLITE_LIMIT_XYZ there is a
2938 ** [limits | hard upper bound]
2939 ** set by a compile-time C preprocessor macro named
2940 ** [limits | SQLITE_MAX_XYZ].
2941 ** (The "_LIMIT_" in the name is changed to "_MAX_".))^
2942 ** ^Attempts to increase a limit above its hard upper bound are
2943 ** silently truncated to the hard upper bound.
2944 **
 
 
 
 
 
2945 ** Run-time limits are intended for use in applications that manage
2946 ** both their own internal database and also databases that are controlled
2947 ** by untrusted external sources. An example application might be a
2948 ** web browser that has its own databases for storing history and
2949 ** separate databases controlled by JavaScript applications downloaded
@@ -2968,11 +3005,11 @@
2968 ** The synopsis of the meanings of the various limits is shown below.
2969 ** Additional information is available at [limits | Limits in SQLite].
2970 **
2971 ** <dl>
2972 ** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
2973 ** <dd>The maximum size of any string or BLOB or table row.<dd>)^
2974 **
2975 ** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
2976 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
2977 **
2978 ** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
@@ -2986,11 +3023,13 @@
2986 ** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
2987 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
2988 **
2989 ** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
2990 ** <dd>The maximum number of instructions in a virtual machine program
2991 ** used to implement an SQL statement.</dd>)^
 
 
2992 **
2993 ** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
2994 ** <dd>The maximum number of arguments on a function.</dd>)^
2995 **
2996 ** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
@@ -2999,12 +3038,11 @@
2999 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
3000 ** <dd>The maximum length of the pattern argument to the [LIKE] or
3001 ** [GLOB] operators.</dd>)^
3002 **
3003 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
3004 ** <dd>The maximum number of variables in an SQL statement that can
3005 ** be bound.</dd>)^
3006 **
3007 ** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
3008 ** <dd>The maximum depth of recursion for triggers.</dd>)^
3009 ** </dl>
3010 */
@@ -3072,16 +3110,11 @@
3072 **
3073 ** <ol>
3074 ** <li>
3075 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
3076 ** always used to do, [sqlite3_step()] will automatically recompile the SQL
3077 ** statement and try to run it again. ^If the schema has changed in
3078 ** a way that makes the statement no longer valid, [sqlite3_step()] will still
3079 ** return [SQLITE_SCHEMA]. But unlike the legacy behavior, [SQLITE_SCHEMA] is
3080 ** now a fatal error. Calling [sqlite3_prepare_v2()] again will not make the
3081 ** error go away. Note: use [sqlite3_errmsg()] to find the text
3082 ** of the parsing error that results in an [SQLITE_SCHEMA] return.
3083 ** </li>
3084 **
3085 ** <li>
3086 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
3087 ** [error codes] or [extended error codes]. ^The legacy behavior was that
@@ -3090,15 +3123,20 @@
3090 ** in order to find the underlying cause of the problem. With the "v2" prepare
3091 ** interfaces, the underlying reason for the error is returned immediately.
3092 ** </li>
3093 **
3094 ** <li>
3095 ** ^If the value of a [parameter | host parameter] in the WHERE clause might
3096 ** change the query plan for a statement, then the statement may be
3097 ** automatically recompiled (as if there had been a schema change) on the first
3098 ** [sqlite3_step()] call following any change to the
3099 ** [sqlite3_bind_text | bindings] of the [parameter].
 
 
 
 
 
3100 ** </li>
3101 ** </ol>
3102 */
3103 SQLITE_API int sqlite3_prepare(
3104 sqlite3 *db, /* Database handle */
@@ -3161,11 +3199,11 @@
3161 ** or if SQLite is run in one of reduced mutex modes
3162 ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
3163 ** then there is no distinction between protected and unprotected
3164 ** sqlite3_value objects and they can be used interchangeably. However,
3165 ** for maximum code portability it is recommended that applications
3166 ** still make the distinction between between protected and unprotected
3167 ** sqlite3_value objects even when not strictly required.
3168 **
3169 ** ^The sqlite3_value objects that are passed as parameters into the
3170 ** implementation of [application-defined SQL functions] are protected.
3171 ** ^The sqlite3_value object returned by
@@ -3356,10 +3394,12 @@
3356 ** CAPI3REF: Number Of Columns In A Result Set
3357 **
3358 ** ^Return the number of columns in the result set returned by the
3359 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3360 ** statement that does not return data (for example an [UPDATE]).
 
 
3361 */
3362 SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
3363
3364 /*
3365 ** CAPI3REF: Column Names In A Result Set
@@ -3546,12 +3586,18 @@
3546 SQLITE_API int sqlite3_step(sqlite3_stmt*);
3547
3548 /*
3549 ** CAPI3REF: Number of columns in a result set
3550 **
3551 ** ^The sqlite3_data_count(P) the number of columns in the
3552 ** of the result set of [prepared statement] P.
 
 
 
 
 
 
3553 */
3554 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
3555
3556 /*
3557 ** CAPI3REF: Fundamental Datatypes
@@ -3627,22 +3673,30 @@
3627 ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
3628 ** the string to UTF-8 and then returns the number of bytes.
3629 ** ^If the result is a numeric value then sqlite3_column_bytes() uses
3630 ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
3631 ** the number of bytes in that string.
3632 ** ^The value returned does not include the zero terminator at the end
3633 ** of the string. ^For clarity: the value returned is the number of
 
 
 
 
 
 
 
 
 
 
 
 
 
3634 ** bytes in the string, not the number of characters.
3635 **
3636 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
3637 ** even empty strings, are always zero terminated. ^The return
3638 ** value from sqlite3_column_blob() for a zero-length BLOB is an arbitrary
3639 ** pointer, possibly even a NULL pointer.
3640 **
3641 ** ^The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
3642 ** but leaves the result in UTF-16 in native byte order instead of UTF-8.
3643 ** ^The zero terminator is not included in this count.
3644 **
3645 ** ^The object returned by [sqlite3_column_value()] is an
3646 ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object
3647 ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
3648 ** If the [unprotected sqlite3_value] object returned by
@@ -3683,14 +3737,14 @@
3683 ** and atof(). SQLite does not really use these functions. It has its
3684 ** own equivalent internal routines. The atoi() and atof() names are
3685 ** used in the table for brevity and because they are familiar to most
3686 ** C programmers.
3687 **
3688 ** ^Note that when type conversions occur, pointers returned by prior
3689 ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
3690 ** sqlite3_column_text16() may be invalidated.
3691 ** ^(Type conversions and pointer invalidations might occur
3692 ** in the following cases:
3693 **
3694 ** <ul>
3695 ** <li> The initial content is a BLOB and sqlite3_column_text() or
3696 ** sqlite3_column_text16() is called. A zero-terminator might
@@ -3699,26 +3753,26 @@
3699 ** sqlite3_column_text16() is called. The content must be converted
3700 ** to UTF-16.</li>
3701 ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
3702 ** sqlite3_column_text() is called. The content must be converted
3703 ** to UTF-8.</li>
3704 ** </ul>)^
3705 **
3706 ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
3707 ** not invalidate a prior pointer, though of course the content of the buffer
3708 ** that the prior pointer points to will have been modified. Other kinds
3709 ** of conversion are done in place when it is possible, but sometimes they
3710 ** are not possible and in those cases prior pointers are invalidated.
3711 **
3712 ** ^(The safest and easiest to remember policy is to invoke these routines
3713 ** in one of the following ways:
3714 **
3715 ** <ul>
3716 ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
3717 ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
3718 ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
3719 ** </ul>)^
3720 **
3721 ** In other words, you should call sqlite3_column_text(),
3722 ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
3723 ** into the desired format, then invoke sqlite3_column_bytes() or
3724 ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
@@ -3752,21 +3806,30 @@
3752
3753 /*
3754 ** CAPI3REF: Destroy A Prepared Statement Object
3755 **
3756 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
3757 ** ^If the statement was executed successfully or not executed at all, then
3758 ** SQLITE_OK is returned. ^If execution of the statement failed then an
3759 ** [error code] or [extended error code] is returned.
 
 
3760 **
3761 ** ^This routine can be called at any point during the execution of the
3762 ** [prepared statement]. ^If the virtual machine has not
3763 ** completed execution when this routine is called, that is like
3764 ** encountering an error or an [sqlite3_interrupt | interrupt].
3765 ** ^Incomplete updates may be rolled back and transactions canceled,
3766 ** depending on the circumstances, and the
3767 ** [error code] returned will be [SQLITE_ABORT].
 
 
 
 
 
 
 
3768 */
3769 SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
3770
3771 /*
3772 ** CAPI3REF: Reset A Prepared Statement Object
@@ -3798,40 +3861,42 @@
3798 ** CAPI3REF: Create Or Redefine SQL Functions
3799 ** KEYWORDS: {function creation routines}
3800 ** KEYWORDS: {application-defined SQL function}
3801 ** KEYWORDS: {application-defined SQL functions}
3802 **
3803 ** ^These two functions (collectively known as "function creation routines")
3804 ** are used to add SQL functions or aggregates or to redefine the behavior
3805 ** of existing SQL functions or aggregates. The only difference between the
3806 ** two is that the second parameter, the name of the (scalar) function or
3807 ** aggregate, is encoded in UTF-8 for sqlite3_create_function() and UTF-16
3808 ** for sqlite3_create_function16().
 
3809 **
3810 ** ^The first parameter is the [database connection] to which the SQL
3811 ** function is to be added. ^If an application uses more than one database
3812 ** connection then application-defined SQL functions must be added
3813 ** to each database connection separately.
3814 **
3815 ** The second parameter is the name of the SQL function to be created or
3816 ** redefined. ^The length of the name is limited to 255 bytes, exclusive of
3817 ** the zero-terminator. Note that the name length limit is in bytes, not
3818 ** characters. ^Any attempt to create a function with a longer name
3819 ** will result in [SQLITE_ERROR] being returned.
 
3820 **
3821 ** ^The third parameter (nArg)
3822 ** is the number of arguments that the SQL function or
3823 ** aggregate takes. ^If this parameter is -1, then the SQL function or
3824 ** aggregate may take any number of arguments between 0 and the limit
3825 ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
3826 ** parameter is less than -1 or greater than 127 then the behavior is
3827 ** undefined.
3828 **
3829 ** The fourth parameter, eTextRep, specifies what
3830 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3831 ** its parameters. Any SQL function implementation should be able to work
3832 ** work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3833 ** more efficient with one encoding than another. ^An application may
3834 ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
3835 ** times with the same function but with different values of eTextRep.
3836 ** ^When multiple implementations of the same function are available, SQLite
3837 ** will pick the one that involves the least amount of data conversion.
@@ -3839,17 +3904,25 @@
3839 ** encoding is used, then the fourth argument should be [SQLITE_ANY].
3840 **
3841 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
3842 ** function can gain access to this pointer using [sqlite3_user_data()].)^
3843 **
3844 ** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
3845 ** pointers to C-language functions that implement the SQL function or
3846 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
3847 ** callback only; NULL pointers should be passed as the xStep and xFinal
3848 ** parameters. ^An aggregate SQL function requires an implementation of xStep
3849 ** and xFinal and NULL should be passed for xFunc. ^To delete an existing
3850 ** SQL function or aggregate, pass NULL for all three function callbacks.
 
 
 
 
 
 
 
 
3851 **
3852 ** ^It is permitted to register multiple implementations of the same
3853 ** functions with the same name but with either differing numbers of
3854 ** arguments or differing preferred text encodings. ^SQLite will use
3855 ** the implementation that most closely matches the way in which the
@@ -3861,15 +3934,10 @@
3861 ** ^A function where the encoding difference is between UTF16le and UTF16be
3862 ** is a closer match than a function where the encoding difference is
3863 ** between UTF8 and UTF16.
3864 **
3865 ** ^Built-in functions may be overloaded by new application-defined functions.
3866 ** ^The first application-defined function with a given name overrides all
3867 ** built-in functions in the same [database connection] with the same name.
3868 ** ^Subsequent application-defined functions of the same name only override
3869 ** prior application-defined functions that are an exact match for the
3870 ** number of parameters and preferred encoding.
3871 **
3872 ** ^An application-defined function is permitted to call other
3873 ** SQLite interfaces. However, such calls must not
3874 ** close the database connection nor finalize or reset the prepared
3875 ** statement in which the function is running.
@@ -3891,10 +3959,21 @@
3891 int eTextRep,
3892 void *pApp,
3893 void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
3894 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
3895 void (*xFinal)(sqlite3_context*)
 
 
 
 
 
 
 
 
 
 
 
3896 );
3897
3898 /*
3899 ** CAPI3REF: Text Encodings
3900 **
@@ -4238,73 +4317,97 @@
4238 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
4239
4240 /*
4241 ** CAPI3REF: Define New Collating Sequences
4242 **
4243 ** These functions are used to add new collation sequences to the
4244 ** [database connection] specified as the first argument.
4245 **
4246 ** ^The name of the new collation sequence is specified as a UTF-8 string
4247 ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
4248 ** and a UTF-16 string for sqlite3_create_collation16(). ^In all cases
4249 ** the name is passed as the second function argument.
4250 **
4251 ** ^The third argument may be one of the constants [SQLITE_UTF8],
4252 ** [SQLITE_UTF16LE], or [SQLITE_UTF16BE], indicating that the user-supplied
4253 ** routine expects to be passed pointers to strings encoded using UTF-8,
4254 ** UTF-16 little-endian, or UTF-16 big-endian, respectively. ^The
4255 ** third argument might also be [SQLITE_UTF16] to indicate that the routine
4256 ** expects pointers to be UTF-16 strings in the native byte order, or the
4257 ** argument can be [SQLITE_UTF16_ALIGNED] if the
4258 ** the routine expects pointers to 16-bit word aligned strings
4259 ** of UTF-16 in the native byte order.
4260 **
4261 ** A pointer to the user supplied routine must be passed as the fifth
4262 ** argument. ^If it is NULL, this is the same as deleting the collation
4263 ** sequence (so that SQLite cannot call it any more).
4264 ** ^Each time the application supplied function is invoked, it is passed
4265 ** as its first parameter a copy of the void* passed as the fourth argument
4266 ** to sqlite3_create_collation() or sqlite3_create_collation16().
4267 **
4268 ** ^The remaining arguments to the application-supplied routine are two strings,
4269 ** each represented by a (length, data) pair and encoded in the encoding
4270 ** that was passed as the third argument when the collation sequence was
4271 ** registered. The application defined collation routine should
4272 ** return negative, zero or positive if the first string is less than,
4273 ** equal to, or greater than the second string. i.e. (STRING1 - STRING2).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4274 **
4275 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
4276 ** except that it takes an extra argument which is a destructor for
4277 ** the collation. ^The destructor is called when the collation is
4278 ** destroyed and is passed a copy of the fourth parameter void* pointer
4279 ** of the sqlite3_create_collation_v2().
4280 ** ^Collations are destroyed when they are overridden by later calls to the
4281 ** collation creation functions or when the [database connection] is closed
4282 ** using [sqlite3_close()].
4283 **
4284 ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
4285 */
4286 SQLITE_API int sqlite3_create_collation(
4287 sqlite3*,
4288 const char *zName,
4289 int eTextRep,
4290 void*,
4291 int(*xCompare)(void*,int,const void*,int,const void*)
4292 );
4293 SQLITE_API int sqlite3_create_collation_v2(
4294 sqlite3*,
4295 const char *zName,
4296 int eTextRep,
4297 void*,
4298 int(*xCompare)(void*,int,const void*,int,const void*),
4299 void(*xDestroy)(void*)
4300 );
4301 SQLITE_API int sqlite3_create_collation16(
4302 sqlite3*,
4303 const void *zName,
4304 int eTextRep,
4305 void*,
4306 int(*xCompare)(void*,int,const void*,int,const void*)
4307 );
4308
4309 /*
4310 ** CAPI3REF: Collation Needed Callbacks
@@ -4389,20 +4492,23 @@
4389 #endif
4390
4391 /*
4392 ** CAPI3REF: Suspend Execution For A Short Time
4393 **
4394 ** ^The sqlite3_sleep() function causes the current thread to suspend execution
4395 ** for at least a number of milliseconds specified in its parameter.
4396 **
4397 ** ^If the operating system does not support sleep requests with
4398 ** millisecond time resolution, then the time will be rounded up to
4399 ** the nearest second. ^The number of milliseconds of sleep actually
4400 ** requested from the operating system is returned.
4401 **
4402 ** ^SQLite implements this interface by calling the xSleep()
4403 ** method of the default [sqlite3_vfs] object.
 
 
 
4404 */
4405 SQLITE_API int sqlite3_sleep(int);
4406
4407 /*
4408 ** CAPI3REF: Name Of The Folder Holding Temporary Files
@@ -4620,44 +4726,77 @@
4620 ** of heap memory by deallocating non-essential memory allocations
4621 ** held by the database library. Memory used to cache database
4622 ** pages to improve performance is an example of non-essential memory.
4623 ** ^sqlite3_release_memory() returns the number of bytes actually freed,
4624 ** which might be more or less than the amount requested.
 
 
4625 */
4626 SQLITE_API int sqlite3_release_memory(int);
4627
4628 /*
4629 ** CAPI3REF: Impose A Limit On Heap Size
4630 **
4631 ** ^The sqlite3_soft_heap_limit() interface places a "soft" limit
4632 ** on the amount of heap memory that may be allocated by SQLite.
4633 ** ^If an internal allocation is requested that would exceed the
4634 ** soft heap limit, [sqlite3_release_memory()] is invoked one or
4635 ** more times to free up some space before the allocation is performed.
4636 **
4637 ** ^The limit is called "soft" because if [sqlite3_release_memory()]
4638 ** cannot free sufficient memory to prevent the limit from being exceeded,
4639 ** the memory is allocated anyway and the current operation proceeds.
4640 **
4641 ** ^A negative or zero value for N means that there is no soft heap limit and
4642 ** [sqlite3_release_memory()] will only be called when memory is exhausted.
4643 ** ^The default value for the soft heap limit is zero.
4644 **
4645 ** ^(SQLite makes a best effort to honor the soft heap limit.
4646 ** But if the soft heap limit cannot be honored, execution will
4647 ** continue without error or notification.)^ This is why the limit is
4648 ** called a "soft" limit. It is advisory only.
4649 **
4650 ** Prior to SQLite version 3.5.0, this routine only constrained the memory
4651 ** allocated by a single thread - the same thread in which this routine
4652 ** runs. Beginning with SQLite version 3.5.0, the soft heap limit is
4653 ** applied to all threads. The value specified for the soft heap limit
4654 ** is an upper bound on the total memory allocation for all threads. In
4655 ** version 3.5.0 there is no mechanism for limiting the heap usage for
4656 ** individual threads.
4657 */
4658 SQLITE_API void sqlite3_soft_heap_limit(int);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4659
4660 /*
4661 ** CAPI3REF: Extract Metadata About A Column Of A Table
4662 **
4663 ** ^This routine returns metadata about a specific column of a specific
@@ -4777,38 +4916,51 @@
4777 ** it back off again.
4778 */
4779 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
4780
4781 /*
4782 ** CAPI3REF: Automatically Load An Extensions
4783 **
4784 ** ^This API can be invoked at program startup in order to register
4785 ** one or more statically linked extensions that will be available
4786 ** to all new [database connections].
4787 **
4788 ** ^(This routine stores a pointer to the extension entry point
4789 ** in an array that is obtained from [sqlite3_malloc()]. That memory
4790 ** is deallocated by [sqlite3_reset_auto_extension()].)^
4791 **
4792 ** ^This function registers an extension entry point that is
4793 ** automatically invoked whenever a new [database connection]
4794 ** is opened using [sqlite3_open()], [sqlite3_open16()],
4795 ** or [sqlite3_open_v2()].
4796 ** ^Duplicate extensions are detected so calling this routine
4797 ** multiple times with the same extension is harmless.
4798 ** ^Automatic extensions apply across all threads.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4799 */
4800 SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
4801
4802 /*
4803 ** CAPI3REF: Reset Automatic Extension Loading
4804 **
4805 ** ^(This function disables all previously registered automatic
4806 ** extensions. It undoes the effect of all prior
4807 ** [sqlite3_auto_extension()] calls.)^
4808 **
4809 ** ^This function disables automatic extensions in all threads.
4810 */
4811 SQLITE_API void sqlite3_reset_auto_extension(void);
4812
4813 /*
4814 ** The interface to the virtual-table mechanism is currently considered
@@ -5443,11 +5595,11 @@
5443 ** output variable when querying the system for the current mutex
5444 ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
5445 **
5446 ** ^The xMutexInit method defined by this structure is invoked as
5447 ** part of system initialization by the sqlite3_initialize() function.
5448 ** ^The xMutexInit routine is calle by SQLite exactly once for each
5449 ** effective call to [sqlite3_initialize()].
5450 **
5451 ** ^The xMutexEnd method defined by this structure is invoked as
5452 ** part of system shutdown by the sqlite3_shutdown() function. The
5453 ** implementation of this method is expected to release all outstanding
@@ -5640,11 +5792,12 @@
5640 #define SQLITE_TESTCTRL_ALWAYS 13
5641 #define SQLITE_TESTCTRL_RESERVE 14
5642 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
5643 #define SQLITE_TESTCTRL_ISKEYWORD 16
5644 #define SQLITE_TESTCTRL_PGHDRSZ 17
5645 #define SQLITE_TESTCTRL_LAST 17
 
5646
5647 /*
5648 ** CAPI3REF: SQLite Runtime Status
5649 **
5650 ** ^This interface is used to retrieve runtime status information
@@ -5659,11 +5812,11 @@
5659 ** value. For those parameters
5660 ** nothing is written into *pHighwater and the resetFlag is ignored.)^
5661 ** ^(Other parameters record only the highwater mark and not the current
5662 ** value. For these latter parameters nothing is written into *pCurrent.)^
5663 **
5664 ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
5665 ** non-zero [error code] on failure.
5666 **
5667 ** This routine is threadsafe but is not atomic. This routine can be
5668 ** called while other threads are running the same or different SQLite
5669 ** interfaces. However the values returned in *pCurrent and
@@ -5709,11 +5862,11 @@
5709 ** [SQLITE_CONFIG_PAGECACHE]. The
5710 ** value returned is in pages, not in bytes.</dd>)^
5711 **
5712 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
5713 ** <dd>This parameter returns the number of bytes of page cache
5714 ** allocation which could not be statisfied by the [SQLITE_CONFIG_PAGECACHE]
5715 ** buffer and where forced to overflow to [sqlite3_malloc()]. The
5716 ** returned value includes allocations that overflowed because they
5717 ** where too large (they were larger than the "sz" parameter to
5718 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
5719 ** no space was left in the page cache.</dd>)^
@@ -5732,11 +5885,11 @@
5732 ** outstanding at time, this parameter also reports the number of threads
5733 ** using scratch memory at the same time.</dd>)^
5734 **
5735 ** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
5736 ** <dd>This parameter returns the number of bytes of scratch memory
5737 ** allocation which could not be statisfied by the [SQLITE_CONFIG_SCRATCH]
5738 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
5739 ** returned include overflows because the requested allocation was too
5740 ** larger (that is, because the requested allocation was larger than the
5741 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
5742 ** slots were available.
@@ -5780,10 +5933,13 @@
5780 **
5781 ** ^The current value of the requested parameter is written into *pCur
5782 ** and the highest instantaneous value is written into *pHiwtr. ^If
5783 ** the resetFlg is true, then the highest instantaneous value is
5784 ** reset back down to the current value.
 
 
 
5785 **
5786 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
5787 */
5788 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5789
@@ -5907,122 +6063,134 @@
5907 ** CAPI3REF: Application Defined Page Cache.
5908 ** KEYWORDS: {page cache}
5909 **
5910 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
5911 ** register an alternative page cache implementation by passing in an
5912 ** instance of the sqlite3_pcache_methods structure.)^ The majority of the
5913 ** heap memory used by SQLite is used by the page cache to cache data read
5914 ** from, or ready to be written to, the database file. By implementing a
5915 ** custom page cache using this API, an application can control more
5916 ** precisely the amount of memory consumed by SQLite, the way in which
 
5917 ** that memory is allocated and released, and the policies used to
5918 ** determine exactly which parts of a database file are cached and for
5919 ** how long.
5920 **
 
 
 
 
5921 ** ^(The contents of the sqlite3_pcache_methods structure are copied to an
5922 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence
5923 ** the application may discard the parameter after the call to
5924 ** [sqlite3_config()] returns.)^
5925 **
5926 ** ^The xInit() method is called once for each call to [sqlite3_initialize()]
 
5927 ** (usually only once during the lifetime of the process). ^(The xInit()
5928 ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
5929 ** ^The xInit() method can set up up global structures and/or any mutexes
5930 ** required by the custom page cache implementation.
 
 
 
5931 **
5932 ** ^The xShutdown() method is called from within [sqlite3_shutdown()],
5933 ** if the application invokes this API. It can be used to clean up
5934 ** any outstanding resources before process shutdown, if required.
 
5935 **
5936 ** ^SQLite holds a [SQLITE_MUTEX_RECURSIVE] mutex when it invokes
5937 ** the xInit method, so the xInit method need not be threadsafe. ^The
5938 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
5939 ** not need to be threadsafe either. All other methods must be threadsafe
5940 ** in multithreaded applications.
5941 **
5942 ** ^SQLite will never invoke xInit() more than once without an intervening
5943 ** call to xShutdown().
5944 **
5945 ** ^The xCreate() method is used to construct a new cache instance. SQLite
5946 ** will typically create one cache instance for each open database file,
5947 ** though this is not guaranteed. ^The
5948 ** first parameter, szPage, is the size in bytes of the pages that must
5949 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage
5950 ** will the page size of the database file that is to be cached plus an
5951 ** increment (here called "R") of about 100 or 200. ^SQLite will use the
5952 ** extra R bytes on each page to store metadata about the underlying
5953 ** database page on disk. The value of R depends
5954 ** on the SQLite version, the target platform, and how SQLite was compiled.
5955 ** ^R is constant for a particular build of SQLite. ^The second argument to
5956 ** xCreate(), bPurgeable, is true if the cache being created will
5957 ** be used to cache database pages of a file stored on disk, or
5958 ** false if it is used for an in-memory database. ^The cache implementation
5959 ** does not have to do anything special based with the value of bPurgeable;
5960 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
5961 ** never invoke xUnpin() except to deliberately delete a page.
5962 ** ^In other words, a cache created with bPurgeable set to false will
 
 
5963 ** never contain any unpinned pages.
5964 **
5965 ** ^(The xCachesize() method may be called at any time by SQLite to set the
5966 ** suggested maximum cache-size (number of pages stored by) the cache
5967 ** instance passed as the first argument. This is the value configured using
5968 ** the SQLite "[PRAGMA cache_size]" command.)^ ^As with the bPurgeable
5969 ** parameter, the implementation is not required to do anything with this
5970 ** value; it is advisory only.
5971 **
5972 ** ^The xPagecount() method should return the number of pages currently
5973 ** stored in the cache.
5974 **
5975 ** ^The xFetch() method is used to fetch a page and return a pointer to it.
5976 ** ^A 'page', in this context, is a buffer of szPage bytes aligned at an
5977 ** 8-byte boundary. ^The page to be fetched is determined by the key. ^The
5978 ** mimimum key value is 1. After it has been retrieved using xFetch, the page
 
5979 ** is considered to be "pinned".
5980 **
5981 ** ^If the requested page is already in the page cache, then the page cache
5982 ** implementation must return a pointer to the page buffer with its content
5983 ** intact. ^(If the requested page is not already in the cache, then the
5984 ** behavior of the cache implementation is determined by the value of the
5985 ** createFlag parameter passed to xFetch, according to the following table:
5986 **
5987 ** <table border=1 width=85% align=center>
5988 ** <tr><th> createFlag <th> Behaviour when page is not already in cache
5989 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
5990 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
5991 ** Otherwise return NULL.
5992 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
5993 ** NULL if allocating a new page is effectively impossible.
5994 ** </table>)^
5995 **
5996 ** SQLite will normally invoke xFetch() with a createFlag of 0 or 1. If
5997 ** a call to xFetch() with createFlag==1 returns NULL, then SQLite will
 
5998 ** attempt to unpin one or more cache pages by spilling the content of
5999 ** pinned pages to disk and synching the operating system disk cache. After
6000 ** attempting to unpin pages, the xFetch() method will be invoked again with
6001 ** a createFlag of 2.
6002 **
6003 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
6004 ** as its second argument. ^(If the third parameter, discard, is non-zero,
6005 ** then the page should be evicted from the cache. In this case SQLite
6006 ** assumes that the next time the page is retrieved from the cache using
6007 ** the xFetch() method, it will be zeroed.)^ ^If the discard parameter is
6008 ** zero, then the page is considered to be unpinned. ^The cache implementation
6009 ** may choose to evict unpinned pages at any time.
6010 **
6011 ** ^(The cache is not required to perform any reference counting. A single
6012 ** call to xUnpin() unpins the page regardless of the number of prior calls
6013 ** to xFetch().)^
6014 **
6015 ** ^The xRekey() method is used to change the key value associated with the
6016 ** page passed as the second argument from oldKey to newKey. ^If the cache
6017 ** previously contains an entry associated with newKey, it should be
6018 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
6019 ** to be pinned.
6020 **
6021 ** ^When SQLite calls the xTruncate() method, the cache must discard all
6022 ** existing cache entries with page numbers (keys) greater than or equal
6023 ** to the value of the iLimit parameter passed to xTruncate(). ^If any
6024 ** of these pages are pinned, they are implicitly unpinned, meaning that
6025 ** they can be safely discarded.
6026 **
6027 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
6028 ** All resources associated with the specified cache should be freed. ^After
@@ -6496,10 +6664,66 @@
6496 #if 0
6497 } /* End of the 'extern "C"' block */
6498 #endif
6499 #endif
6500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6501
6502 /************** End of sqlite3.h *********************************************/
6503 /************** Continuing where we left off in sqliteInt.h ******************/
6504 /************** Include hash.h in the middle of sqliteInt.h ******************/
6505 /************** Begin file hash.h ********************************************/
@@ -7066,10 +7290,11 @@
7066 typedef struct Schema Schema;
7067 typedef struct Expr Expr;
7068 typedef struct ExprList ExprList;
7069 typedef struct ExprSpan ExprSpan;
7070 typedef struct FKey FKey;
 
7071 typedef struct FuncDef FuncDef;
7072 typedef struct FuncDefHash FuncDefHash;
7073 typedef struct IdList IdList;
7074 typedef struct Index Index;
7075 typedef struct IndexSample IndexSample;
@@ -7172,16 +7397,15 @@
7172 ** following values.
7173 **
7174 ** NOTE: These values must match the corresponding PAGER_ values in
7175 ** pager.h.
7176 */
7177 #define BTREE_OMIT_JOURNAL 1 /* Do not use journal. No argument */
7178 #define BTREE_NO_READLOCK 2 /* Omit readlocks on readonly files */
7179 #define BTREE_MEMORY 4 /* In-memory DB. No argument */
7180 #define BTREE_READONLY 8 /* Open the database in read-only mode */
7181 #define BTREE_READWRITE 16 /* Open for both reading and writing */
7182 #define BTREE_CREATE 32 /* Create the database if it does not exist */
7183
7184 SQLITE_PRIVATE int sqlite3BtreeClose(Btree*);
7185 SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int);
7186 SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
7187 SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
@@ -7213,15 +7437,21 @@
7213 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *);
7214
7215 SQLITE_PRIVATE int sqlite3BtreeIncrVacuum(Btree *);
7216
7217 /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
7218 ** of the following flags:
 
 
 
 
 
 
 
7219 */
7220 #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */
7221 #define BTREE_ZERODATA 2 /* Table has keys only - no data */
7222 #define BTREE_LEAFDATA 4 /* Data stored in leaves only. Implies INTKEY */
7223
7224 SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*);
7225 SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*);
7226 SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree*, int);
7227
@@ -7838,10 +8068,11 @@
7838 **
7839 ** NOTE: These values must match the corresponding BTREE_ values in btree.h.
7840 */
7841 #define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */
7842 #define PAGER_NO_READLOCK 0x0002 /* Omit readlocks on readonly files */
 
7843
7844 /*
7845 ** Valid values for the second argument to sqlite3PagerLockingMode().
7846 */
7847 #define PAGER_LOCKINGMODE_QUERY -1
@@ -8472,12 +8703,12 @@
8472 #define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8)
8473 #define sqlite3_mutex_free(X)
8474 #define sqlite3_mutex_enter(X)
8475 #define sqlite3_mutex_try(X) SQLITE_OK
8476 #define sqlite3_mutex_leave(X)
8477 #define sqlite3_mutex_held(X) 1
8478 #define sqlite3_mutex_notheld(X) 1
8479 #define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8)
8480 #define sqlite3MutexInit() SQLITE_OK
8481 #define sqlite3MutexEnd()
8482 #endif /* defined(SQLITE_MUTEX_OMIT) */
8483
@@ -8795,10 +9026,31 @@
8795 void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
8796 void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
8797 void (*xFinalize)(sqlite3_context*); /* Aggregate finalizer */
8798 char *zName; /* SQL name of the function. */
8799 FuncDef *pHash; /* Next with a different name but the same hash */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8800 };
8801
8802 /*
8803 ** Possible values for FuncDef.flags
8804 */
@@ -8835,19 +9087,19 @@
8835 ** FuncDef.flags variable is set to the value passed as the flags
8836 ** parameter.
8837 */
8838 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
8839 {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
8840 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0}
8841 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
8842 {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
8843 pArg, 0, xFunc, 0, 0, #zName, 0}
8844 #define LIKEFUNC(zName, nArg, arg, flags) \
8845 {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0}
8846 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
8847 {nArg, SQLITE_UTF8, nc*SQLITE_FUNC_NEEDCOLL, \
8848 SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0}
8849
8850 /*
8851 ** All current savepoints are stored in a linked list starting at
8852 ** sqlite3.pSavepoint. The first element in the list is the most recently
8853 ** opened savepoint. Savepoints are added to the list by the vdbe
@@ -9063,10 +9315,11 @@
9063 int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
9064 int nCol; /* Number of columns in this table */
9065 Column *aCol; /* Information about each column */
9066 Index *pIndex; /* List of SQL indexes on this table. */
9067 int tnum; /* Root BTree node for this table (see note above) */
 
9068 Select *pSelect; /* NULL for tables. Points to definition if a view. */
9069 u16 nRef; /* Number of pointers to this Table */
9070 u8 tabFlags; /* Mask of TF_* values */
9071 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
9072 FKey *pFKey; /* Linked list of all foreign keys in this table */
@@ -10317,11 +10570,10 @@
10317
10318 /*
10319 ** Internal function prototypes
10320 */
10321 SQLITE_PRIVATE int sqlite3StrICmp(const char *, const char *);
10322 SQLITE_PRIVATE int sqlite3IsNumber(const char*, int*, u8);
10323 SQLITE_PRIVATE int sqlite3Strlen30(const char*);
10324 #define sqlite3StrNICmp sqlite3_strnicmp
10325
10326 SQLITE_PRIVATE int sqlite3MallocInit(void);
10327 SQLITE_PRIVATE void sqlite3MallocEnd(void);
@@ -10341,11 +10593,11 @@
10341 SQLITE_PRIVATE void sqlite3ScratchFree(void*);
10342 SQLITE_PRIVATE void *sqlite3PageMalloc(int);
10343 SQLITE_PRIVATE void sqlite3PageFree(void*);
10344 SQLITE_PRIVATE void sqlite3MemSetDefault(void);
10345 SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
10346 SQLITE_PRIVATE int sqlite3MemoryAlarm(void (*)(void*, sqlite3_int64, int), void*, sqlite3_int64);
10347
10348 /*
10349 ** On systems with ample stack space and that support alloca(), make
10350 ** use of alloca() to obtain space for large automatic objects. By default,
10351 ** obtain space from malloc().
@@ -10512,11 +10764,10 @@
10512 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
10513 SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
10514 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
10515 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
10516 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
10517 SQLITE_PRIVATE void sqlite3ExprHardCopy(Parse*,int,int);
10518 SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
10519 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
10520 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
10521 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
10522 SQLITE_PRIVATE void sqlite3ExprCodeConstants(Parse*, Expr*);
@@ -10632,21 +10883,18 @@
10632 # define sqlite3AuthContextPush(a,b,c)
10633 # define sqlite3AuthContextPop(a) ((void)(a))
10634 #endif
10635 SQLITE_PRIVATE void sqlite3Attach(Parse*, Expr*, Expr*, Expr*);
10636 SQLITE_PRIVATE void sqlite3Detach(Parse*, Expr*);
10637 SQLITE_PRIVATE int sqlite3BtreeFactory(sqlite3 *db, const char *zFilename,
10638 int omitJournal, int nCache, int flags, Btree **ppBtree);
10639 SQLITE_PRIVATE int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*);
10640 SQLITE_PRIVATE int sqlite3FixSrcList(DbFixer*, SrcList*);
10641 SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
10642 SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
10643 SQLITE_PRIVATE int sqlite3FixExprList(DbFixer*, ExprList*);
10644 SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
10645 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*);
10646 SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
10647 SQLITE_PRIVATE int sqlite3FitsIn64Bits(const char *, int);
10648 SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar);
10649 SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte);
10650 SQLITE_PRIVATE int sqlite3Utf8Read(const u8*, const u8**);
10651
10652 /*
@@ -10688,11 +10936,11 @@
10688 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
10689 SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *, Table *);
10690 SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
10691 SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
10692 SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
10693 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*);
10694 SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
10695 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
10696 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
10697 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
10698 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -10759,11 +11007,13 @@
10759 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
10760 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
10761 SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
10762 SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
10763 void (*)(sqlite3_context*,int,sqlite3_value **),
10764 void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*));
 
 
10765 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
10766 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
10767
10768 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
10769 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
@@ -11679,10 +11929,11 @@
11679 Bool useRandomRowid; /* Generate new record numbers semi-randomly */
11680 Bool nullRow; /* True if pointing to a row with no data */
11681 Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
11682 Bool isTable; /* True if a table requiring integer keys */
11683 Bool isIndex; /* True if an index containing keys only - no data */
 
11684 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
11685 Btree *pBt; /* Separate file holding temporary table */
11686 int pseudoTableReg; /* Register holding pseudotable content. */
11687 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
11688 int nField; /* Number of fields in the header */
@@ -11773,10 +12024,14 @@
11773 char *z; /* String or BLOB value */
11774 int n; /* Number of characters in string value, excluding '\0' */
11775 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
11776 u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
11777 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
 
 
 
 
11778 void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
11779 char *zMalloc; /* Dynamic buffer allocated by sqlite3_malloc() */
11780 };
11781
11782 /* One or more of the following flags are set to indicate the validOK
@@ -11799,10 +12054,11 @@
11799 #define MEM_Int 0x0004 /* Value is an integer */
11800 #define MEM_Real 0x0008 /* Value is a real number */
11801 #define MEM_Blob 0x0010 /* Value is a BLOB */
11802 #define MEM_RowSet 0x0020 /* Value is a RowSet object */
11803 #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
 
11804 #define MEM_TypeMask 0x00ff /* Mask of type bits */
11805
11806 /* Whenever Mem contains a valid string or blob representation, one of
11807 ** the following flags must be set to determine the memory management
11808 ** policy for Mem.z. The MEM_Term flag tells us whether or not the
@@ -11812,23 +12068,29 @@
11812 #define MEM_Dyn 0x0400 /* Need to call sqliteFree() on Mem.z */
11813 #define MEM_Static 0x0800 /* Mem.z points to a static string */
11814 #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
11815 #define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
11816 #define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
11817
11818 #ifdef SQLITE_OMIT_INCRBLOB
11819 #undef MEM_Zero
11820 #define MEM_Zero 0x0000
11821 #endif
11822
11823
11824 /*
11825 ** Clear any existing type flags from a Mem and replace them with f
11826 */
11827 #define MemSetTypeFlag(p, f) \
11828 ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
11829
 
 
 
 
 
 
 
 
11830
11831 /* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
11832 ** additional information about auxiliary information bound to arguments
11833 ** of the function. This is used to implement the sqlite3_get_auxdata()
11834 ** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data
@@ -12012,10 +12274,14 @@
12012 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
12013 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
12014 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
12015 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
12016 SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
 
 
 
 
12017
12018 #ifndef SQLITE_OMIT_FOREIGN_KEY
12019 SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int);
12020 #else
12021 # define sqlite3VdbeCheckFk(p,i) 0
@@ -12369,16 +12635,10 @@
12369 end_getDigits:
12370 va_end(ap);
12371 return cnt;
12372 }
12373
12374 /*
12375 ** Read text from z[] and convert into a floating point number. Return
12376 ** the number of digits converted.
12377 */
12378 #define getValue sqlite3AtoF
12379
12380 /*
12381 ** Parse a timezone extension on the end of a date-time.
12382 ** The extension is of the form:
12383 **
12384 ** (+/-)HH:MM
@@ -12576,21 +12836,19 @@
12576 static int parseDateOrTime(
12577 sqlite3_context *context,
12578 const char *zDate,
12579 DateTime *p
12580 ){
12581 int isRealNum; /* Return from sqlite3IsNumber(). Not used */
12582 if( parseYyyyMmDd(zDate,p)==0 ){
12583 return 0;
12584 }else if( parseHhMmSs(zDate, p)==0 ){
12585 return 0;
12586 }else if( sqlite3StrICmp(zDate,"now")==0){
12587 setDateTimeToCurrent(context, p);
12588 return 0;
12589 }else if( sqlite3IsNumber(zDate, &isRealNum, SQLITE_UTF8) ){
12590 double r;
12591 getValue(zDate, &r);
12592 p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
12593 p->validJD = 1;
12594 return 0;
12595 }
12596 return 1;
@@ -12807,12 +13065,13 @@
12807 **
12808 ** Move the date to the same time on the next occurrence of
12809 ** weekday N where 0==Sunday, 1==Monday, and so forth. If the
12810 ** date is already on the appropriate weekday, this is a no-op.
12811 */
12812 if( strncmp(z, "weekday ", 8)==0 && getValue(&z[8],&r)>0
12813 && (n=(int)r)==r && n>=0 && r<7 ){
 
12814 sqlite3_int64 Z;
12815 computeYMD_HMS(p);
12816 p->validTZ = 0;
12817 p->validJD = 0;
12818 computeJD(p);
@@ -12863,12 +13122,15 @@
12863 case '6':
12864 case '7':
12865 case '8':
12866 case '9': {
12867 double rRounder;
12868 n = getValue(z, &r);
12869 assert( n>=1 );
 
 
 
12870 if( z[n]==':' ){
12871 /* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the
12872 ** specified number of hours, minutes, seconds, and fractional seconds
12873 ** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be
12874 ** omitted.
@@ -13518,10 +13780,16 @@
13518 SQLITE_PRIVATE int sqlite3OsSleep(sqlite3_vfs *pVfs, int nMicro){
13519 return pVfs->xSleep(pVfs, nMicro);
13520 }
13521 SQLITE_PRIVATE int sqlite3OsCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *pTimeOut){
13522 int rc;
 
 
 
 
 
 
13523 if( pVfs->iVersion>=2 && pVfs->xCurrentTimeInt64 ){
13524 rc = pVfs->xCurrentTimeInt64(pVfs, pTimeOut);
13525 }else{
13526 double r;
13527 rc = pVfs->xCurrentTime(pVfs, &r);
@@ -13901,11 +14169,11 @@
13901 ** routines and redirected to xFree.
13902 */
13903 static void *sqlite3MemRealloc(void *pPrior, int nByte){
13904 sqlite3_int64 *p = (sqlite3_int64*)pPrior;
13905 assert( pPrior!=0 && nByte>0 );
13906 nByte = ROUND8(nByte);
13907 p--;
13908 p = realloc(p, nByte+8 );
13909 if( p ){
13910 p[0] = nByte;
13911 p++;
@@ -14307,10 +14575,11 @@
14307 */
14308 static void *sqlite3MemRealloc(void *pPrior, int nByte){
14309 struct MemBlockHdr *pOldHdr;
14310 void *pNew;
14311 assert( mem.disallow==0 );
 
14312 pOldHdr = sqlite3MemsysGetHeader(pPrior);
14313 pNew = sqlite3MemMalloc(nByte);
14314 if( pNew ){
14315 memcpy(pNew, pPrior, nByte<pOldHdr->iSize ? nByte : pOldHdr->iSize);
14316 if( nByte>pOldHdr->iSize ){
@@ -15576,11 +15845,11 @@
15576 */
15577 static void *memsys5Realloc(void *pPrior, int nBytes){
15578 int nOld;
15579 void *p;
15580 assert( pPrior!=0 );
15581 assert( (nBytes&(nBytes-1))==0 );
15582 assert( nBytes>=0 );
15583 if( nBytes==0 ){
15584 return 0;
15585 }
15586 nOld = memsys5Size(pPrior);
@@ -17100,10 +17369,70 @@
17100 *************************************************************************
17101 **
17102 ** Memory allocation functions used throughout sqlite.
17103 */
17104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17105 /*
17106 ** This routine runs when the memory allocator sees that the
17107 ** total memory allocation is about to exceed the soft heap
17108 ** limit.
17109 */
@@ -17114,82 +17443,70 @@
17114 ){
17115 UNUSED_PARAMETER2(NotUsed, NotUsed2);
17116 sqlite3_release_memory(allocSize);
17117 }
17118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17119 /*
17120 ** Set the soft heap-size limit for the library. Passing a zero or
17121 ** negative value indicates no limit.
17122 */
17123 SQLITE_API void sqlite3_soft_heap_limit(int n){
17124 sqlite3_uint64 iLimit;
17125 int overage;
17126 if( n<0 ){
17127 iLimit = 0;
17128 }else{
17129 iLimit = n;
17130 }
17131 #ifndef SQLITE_OMIT_AUTOINIT
17132 sqlite3_initialize();
17133 #endif
17134 if( iLimit>0 ){
17135 sqlite3MemoryAlarm(softHeapLimitEnforcer, 0, iLimit);
 
 
 
 
17136 }else{
17137 sqlite3MemoryAlarm(0, 0, 0);
17138 }
17139 overage = (int)(sqlite3_memory_used() - (i64)n);
17140 if( overage>0 ){
17141 sqlite3_release_memory(overage);
17142 }
17143 }
17144
17145 /*
17146 ** Attempt to release up to n bytes of non-essential memory currently
17147 ** held by SQLite. An example of non-essential memory is memory used to
17148 ** cache database pages that are not currently in use.
17149 */
17150 SQLITE_API int sqlite3_release_memory(int n){
17151 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
17152 int nRet = 0;
17153 nRet += sqlite3PcacheReleaseMemory(n-nRet);
17154 return nRet;
17155 #else
17156 UNUSED_PARAMETER(n);
17157 return SQLITE_OK;
17158 #endif
17159 }
17160
17161 /*
17162 ** State information local to the memory allocation subsystem.
17163 */
17164 static SQLITE_WSD struct Mem0Global {
17165 /* Number of free pages for scratch and page-cache memory */
17166 u32 nScratchFree;
17167 u32 nPageFree;
17168
17169 sqlite3_mutex *mutex; /* Mutex to serialize access */
17170
17171 /*
17172 ** The alarm callback and its arguments. The mem0.mutex lock will
17173 ** be held while the callback is running. Recursive calls into
17174 ** the memory subsystem are allowed, but no new callbacks will be
17175 ** issued.
17176 */
17177 sqlite3_int64 alarmThreshold;
17178 void (*alarmCallback)(void*, sqlite3_int64,int);
17179 void *alarmArg;
17180
17181 /*
17182 ** Pointers to the end of sqlite3GlobalConfig.pScratch and
17183 ** sqlite3GlobalConfig.pPage to a block of memory that records
17184 ** which pages are available.
17185 */
17186 u32 *aScratchFree;
17187 u32 *aPageFree;
17188 } mem0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
17189
17190 #define mem0 GLOBAL(struct Mem0Global, mem0)
17191
17192 /*
17193 ** Initialize the memory allocation subsystem.
17194 */
17195 SQLITE_PRIVATE int sqlite3MallocInit(void){
@@ -17199,39 +17516,48 @@
17199 memset(&mem0, 0, sizeof(mem0));
17200 if( sqlite3GlobalConfig.bCoreMutex ){
17201 mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
17202 }
17203 if( sqlite3GlobalConfig.pScratch && sqlite3GlobalConfig.szScratch>=100
17204 && sqlite3GlobalConfig.nScratch>=0 ){
17205 int i;
17206 sqlite3GlobalConfig.szScratch = ROUNDDOWN8(sqlite3GlobalConfig.szScratch-4);
17207 mem0.aScratchFree = (u32*)&((char*)sqlite3GlobalConfig.pScratch)
17208 [sqlite3GlobalConfig.szScratch*sqlite3GlobalConfig.nScratch];
17209 for(i=0; i<sqlite3GlobalConfig.nScratch; i++){ mem0.aScratchFree[i] = i; }
17210 mem0.nScratchFree = sqlite3GlobalConfig.nScratch;
 
 
 
 
 
 
 
 
17211 }else{
 
17212 sqlite3GlobalConfig.pScratch = 0;
17213 sqlite3GlobalConfig.szScratch = 0;
17214 }
17215 if( sqlite3GlobalConfig.pPage && sqlite3GlobalConfig.szPage>=512
17216 && sqlite3GlobalConfig.nPage>=1 ){
17217 int i;
17218 int overhead;
17219 int sz = ROUNDDOWN8(sqlite3GlobalConfig.szPage);
17220 int n = sqlite3GlobalConfig.nPage;
17221 overhead = (4*n + sz - 1)/sz;
17222 sqlite3GlobalConfig.nPage -= overhead;
17223 mem0.aPageFree = (u32*)&((char*)sqlite3GlobalConfig.pPage)
17224 [sqlite3GlobalConfig.szPage*sqlite3GlobalConfig.nPage];
17225 for(i=0; i<sqlite3GlobalConfig.nPage; i++){ mem0.aPageFree[i] = i; }
17226 mem0.nPageFree = sqlite3GlobalConfig.nPage;
17227 }else{
17228 sqlite3GlobalConfig.pPage = 0;
17229 sqlite3GlobalConfig.szPage = 0;
 
17230 }
17231 return sqlite3GlobalConfig.m.xInit(sqlite3GlobalConfig.m.pAppData);
17232 }
 
 
 
 
 
 
 
 
 
17233
17234 /*
17235 ** Deinitialize the memory allocation subsystem.
17236 */
17237 SQLITE_PRIVATE void sqlite3MallocEnd(void){
@@ -17263,40 +17589,10 @@
17263 sqlite3_status(SQLITE_STATUS_MEMORY_USED, &n, &mx, resetFlag);
17264 res = (sqlite3_int64)mx; /* Work around bug in Borland C. Ticket #3216 */
17265 return res;
17266 }
17267
17268 /*
17269 ** Change the alarm callback
17270 */
17271 SQLITE_PRIVATE int sqlite3MemoryAlarm(
17272 void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
17273 void *pArg,
17274 sqlite3_int64 iThreshold
17275 ){
17276 sqlite3_mutex_enter(mem0.mutex);
17277 mem0.alarmCallback = xCallback;
17278 mem0.alarmArg = pArg;
17279 mem0.alarmThreshold = iThreshold;
17280 sqlite3_mutex_leave(mem0.mutex);
17281 return SQLITE_OK;
17282 }
17283
17284 #ifndef SQLITE_OMIT_DEPRECATED
17285 /*
17286 ** Deprecated external interface. Internal/core SQLite code
17287 ** should call sqlite3MemoryAlarm.
17288 */
17289 SQLITE_API int sqlite3_memory_alarm(
17290 void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
17291 void *pArg,
17292 sqlite3_int64 iThreshold
17293 ){
17294 return sqlite3MemoryAlarm(xCallback, pArg, iThreshold);
17295 }
17296 #endif
17297
17298 /*
17299 ** Trigger the alarm
17300 */
17301 static void sqlite3MallocAlarm(int nByte){
17302 void (*xCallback)(void*,sqlite3_int64,int);
@@ -17325,18 +17621,23 @@
17325 nFull = sqlite3GlobalConfig.m.xRoundup(n);
17326 sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
17327 if( mem0.alarmCallback!=0 ){
17328 int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
17329 if( nUsed+nFull >= mem0.alarmThreshold ){
 
17330 sqlite3MallocAlarm(nFull);
 
 
17331 }
17332 }
17333 p = sqlite3GlobalConfig.m.xMalloc(nFull);
 
17334 if( p==0 && mem0.alarmCallback ){
17335 sqlite3MallocAlarm(nFull);
17336 p = sqlite3GlobalConfig.m.xMalloc(nFull);
17337 }
 
17338 if( p ){
17339 nFull = sqlite3MallocSize(p);
17340 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nFull);
17341 sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, 1);
17342 }
@@ -17348,11 +17649,13 @@
17348 ** Allocate memory. This routine is like sqlite3_malloc() except that it
17349 ** assumes the memory subsystem has already been initialized.
17350 */
17351 SQLITE_PRIVATE void *sqlite3Malloc(int n){
17352 void *p;
17353 if( n<=0 || n>=0x7fffff00 ){
 
 
17354 /* A memory allocation of a number of bytes which is near the maximum
17355 ** signed integer value might cause an integer overflow inside of the
17356 ** xMalloc(). Hence we limit the maximum size to 0x7fffff00, giving
17357 ** 255 bytes of overhead. SQLite itself will never use anything near
17358 ** this amount. The only way to reach the limit is with sqlite3_malloc() */
@@ -17362,10 +17665,11 @@
17362 mallocWithAlarm(n, &p);
17363 sqlite3_mutex_leave(mem0.mutex);
17364 }else{
17365 p = sqlite3GlobalConfig.m.xMalloc(n);
17366 }
 
17367 return p;
17368 }
17369
17370 /*
17371 ** This version of the memory allocation is for use by the application.
@@ -17399,64 +17703,70 @@
17399 ** embedded processor.
17400 */
17401 SQLITE_PRIVATE void *sqlite3ScratchMalloc(int n){
17402 void *p;
17403 assert( n>0 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17404
17405 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
17406 /* Verify that no more than two scratch allocation per thread
17407 ** is outstanding at one time. (This is only checked in the
17408 ** single-threaded case since checking in the multi-threaded case
17409 ** would be much more complicated.) */
17410 assert( scratchAllocOut<=1 );
17411 #endif
17412
17413 if( sqlite3GlobalConfig.szScratch<n ){
17414 goto scratch_overflow;
17415 }else{
17416 sqlite3_mutex_enter(mem0.mutex);
17417 if( mem0.nScratchFree==0 ){
17418 sqlite3_mutex_leave(mem0.mutex);
17419 goto scratch_overflow;
17420 }else{
17421 int i;
17422 i = mem0.aScratchFree[--mem0.nScratchFree];
17423 i *= sqlite3GlobalConfig.szScratch;
17424 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, 1);
17425 sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
17426 sqlite3_mutex_leave(mem0.mutex);
17427 p = (void*)&((char*)sqlite3GlobalConfig.pScratch)[i];
17428 assert( (((u8*)p - (u8*)0) & 7)==0 );
17429 }
17430 }
17431 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
17432 scratchAllocOut = p!=0;
17433 #endif
17434
17435 return p;
17436
17437 scratch_overflow:
17438 if( sqlite3GlobalConfig.bMemstat ){
17439 sqlite3_mutex_enter(mem0.mutex);
17440 sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
17441 n = mallocWithAlarm(n, &p);
17442 if( p ) sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, n);
17443 sqlite3_mutex_leave(mem0.mutex);
17444 }else{
17445 p = sqlite3GlobalConfig.m.xMalloc(n);
17446 }
17447 sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH);
17448 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
17449 scratchAllocOut = p!=0;
17450 #endif
17451 return p;
17452 }
17453 SQLITE_PRIVATE void sqlite3ScratchFree(void *p){
17454 if( p ){
17455 if( sqlite3GlobalConfig.pScratch==0
17456 || p<sqlite3GlobalConfig.pScratch
17457 || p>=(void*)mem0.aScratchFree ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17458 assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
17459 assert( sqlite3MemdebugNoType(p, ~MEMTYPE_SCRATCH) );
17460 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
17461 if( sqlite3GlobalConfig.bMemstat ){
17462 int iSize = sqlite3MallocSize(p);
@@ -17467,30 +17777,10 @@
17467 sqlite3GlobalConfig.m.xFree(p);
17468 sqlite3_mutex_leave(mem0.mutex);
17469 }else{
17470 sqlite3GlobalConfig.m.xFree(p);
17471 }
17472 }else{
17473 int i;
17474 i = (int)((u8*)p - (u8*)sqlite3GlobalConfig.pScratch);
17475 i /= sqlite3GlobalConfig.szScratch;
17476 assert( i>=0 && i<sqlite3GlobalConfig.nScratch );
17477 sqlite3_mutex_enter(mem0.mutex);
17478 assert( mem0.nScratchFree<(u32)sqlite3GlobalConfig.nScratch );
17479 mem0.aScratchFree[mem0.nScratchFree++] = i;
17480 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1);
17481 sqlite3_mutex_leave(mem0.mutex);
17482
17483 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
17484 /* Verify that no more than two scratch allocation per thread
17485 ** is outstanding at one time. (This is only checked in the
17486 ** single-threaded case since checking in the multi-threaded case
17487 ** would be much more complicated.) */
17488 assert( scratchAllocOut>=1 && scratchAllocOut<=2 );
17489 scratchAllocOut = 0;
17490 #endif
17491
17492 }
17493 }
17494 }
17495
17496 /*
@@ -17527,11 +17817,11 @@
17527
17528 /*
17529 ** Free memory previously obtained from sqlite3Malloc().
17530 */
17531 SQLITE_API void sqlite3_free(void *p){
17532 if( p==0 ) return;
17533 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
17534 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
17535 if( sqlite3GlobalConfig.bMemstat ){
17536 sqlite3_mutex_enter(mem0.mutex);
17537 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
@@ -17574,21 +17864,24 @@
17574 */
17575 SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, int nBytes){
17576 int nOld, nNew;
17577 void *pNew;
17578 if( pOld==0 ){
17579 return sqlite3Malloc(nBytes);
17580 }
17581 if( nBytes<=0 ){
17582 sqlite3_free(pOld);
17583 return 0;
17584 }
17585 if( nBytes>=0x7fffff00 ){
17586 /* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */
17587 return 0;
17588 }
17589 nOld = sqlite3MallocSize(pOld);
 
 
 
17590 nNew = sqlite3GlobalConfig.m.xRoundup(nBytes);
17591 if( nOld==nNew ){
17592 pNew = pOld;
17593 }else if( sqlite3GlobalConfig.bMemstat ){
17594 sqlite3_mutex_enter(mem0.mutex);
@@ -17610,10 +17903,11 @@
17610 }
17611 sqlite3_mutex_leave(mem0.mutex);
17612 }else{
17613 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
17614 }
 
17615 return pNew;
17616 }
17617
17618 /*
17619 ** The public interface to sqlite3Realloc. Make sure that the memory
@@ -19773,10 +20067,16 @@
19773 #define UpperToLower sqlite3UpperToLower
19774
19775 /*
19776 ** Some systems have stricmp(). Others have strcasecmp(). Because
19777 ** there is no consistency, we will define our own.
 
 
 
 
 
 
19778 */
19779 SQLITE_PRIVATE int sqlite3StrICmp(const char *zLeft, const char *zRight){
19780 register unsigned char *a, *b;
19781 a = (unsigned char *)zLeft;
19782 b = (unsigned char *)zRight;
@@ -19790,125 +20090,115 @@
19790 while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
19791 return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
19792 }
19793
19794 /*
19795 ** Return TRUE if z is a pure numeric string. Return FALSE and leave
19796 ** *realnum unchanged if the string contains any character which is not
19797 ** part of a number.
19798 **
19799 ** If the string is pure numeric, set *realnum to TRUE if the string
19800 ** contains the '.' character or an "E+000" style exponentiation suffix.
19801 ** Otherwise set *realnum to FALSE. Note that just becaue *realnum is
19802 ** false does not mean that the number can be successfully converted into
19803 ** an integer - it might be too big.
19804 **
19805 ** An empty string is considered non-numeric.
19806 */
19807 SQLITE_PRIVATE int sqlite3IsNumber(const char *z, int *realnum, u8 enc){
 
 
 
 
 
 
 
 
 
 
19808 int incr = (enc==SQLITE_UTF8?1:2);
19809 if( enc==SQLITE_UTF16BE ) z++;
19810 if( *z=='-' || *z=='+' ) z += incr;
19811 if( !sqlite3Isdigit(*z) ){
19812 return 0;
19813 }
19814 z += incr;
19815 *realnum = 0;
19816 while( sqlite3Isdigit(*z) ){ z += incr; }
19817 #ifndef SQLITE_OMIT_FLOATING_POINT
19818 if( *z=='.' ){
19819 z += incr;
19820 if( !sqlite3Isdigit(*z) ) return 0;
19821 while( sqlite3Isdigit(*z) ){ z += incr; }
19822 *realnum = 1;
19823 }
19824 if( *z=='e' || *z=='E' ){
19825 z += incr;
19826 if( *z=='+' || *z=='-' ) z += incr;
19827 if( !sqlite3Isdigit(*z) ) return 0;
19828 while( sqlite3Isdigit(*z) ){ z += incr; }
19829 *realnum = 1;
19830 }
19831 #endif
19832 return *z==0;
19833 }
19834
19835 /*
19836 ** The string z[] is an ASCII representation of a real number.
19837 ** Convert this string to a double.
19838 **
19839 ** This routine assumes that z[] really is a valid number. If it
19840 ** is not, the result is undefined.
19841 **
19842 ** This routine is used instead of the library atof() function because
19843 ** the library atof() might want to use "," as the decimal point instead
19844 ** of "." depending on how locale is set. But that would cause problems
19845 ** for SQL. So this routine always uses "." regardless of locale.
19846 */
19847 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult){
19848 #ifndef SQLITE_OMIT_FLOATING_POINT
19849 const char *zBegin = z;
19850 /* sign * significand * (10 ^ (esign * exponent)) */
19851 int sign = 1; /* sign of significand */
19852 i64 s = 0; /* significand */
19853 int d = 0; /* adjust exponent for shifting decimal point */
19854 int esign = 1; /* sign of exponent */
19855 int e = 0; /* exponent */
 
19856 double result;
19857 int nDigits = 0;
19858
 
 
 
 
19859 /* skip leading spaces */
19860 while( sqlite3Isspace(*z) ) z++;
 
 
19861 /* get sign of significand */
19862 if( *z=='-' ){
19863 sign = -1;
19864 z++;
19865 }else if( *z=='+' ){
19866 z++;
19867 }
 
19868 /* skip leading zeroes */
19869 while( z[0]=='0' ) z++, nDigits++;
19870
19871 /* copy max significant digits to significand */
19872 while( sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
19873 s = s*10 + (*z - '0');
19874 z++, nDigits++;
19875 }
 
19876 /* skip non-significant significand digits
19877 ** (increase exponent by d to shift decimal left) */
19878 while( sqlite3Isdigit(*z) ) z++, nDigits++, d++;
 
19879
19880 /* if decimal point is present */
19881 if( *z=='.' ){
19882 z++;
19883 /* copy digits from after decimal to significand
19884 ** (decrease exponent by d to shift decimal right) */
19885 while( sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
19886 s = s*10 + (*z - '0');
19887 z++, nDigits++, d--;
19888 }
19889 /* skip non-significant digits */
19890 while( sqlite3Isdigit(*z) ) z++, nDigits++;
19891 }
 
19892
19893 /* if exponent is present */
19894 if( *z=='e' || *z=='E' ){
19895 z++;
 
 
19896 /* get sign of exponent */
19897 if( *z=='-' ){
19898 esign = -1;
19899 z++;
19900 }else if( *z=='+' ){
19901 z++;
19902 }
19903 /* copy digits to exponent */
19904 while( sqlite3Isdigit(*z) ){
19905 e = e*10 + (*z - '0');
19906 z++;
 
19907 }
19908 }
19909
 
 
 
 
 
 
19910 /* adjust exponent by d, and update sign */
19911 e = (e*esign) + d;
19912 if( e<0 ) {
19913 esign = -1;
19914 e *= -1;
@@ -19963,132 +20253,104 @@
19963 }
19964
19965 /* store the result */
19966 *pResult = result;
19967
19968 /* return number of characters used */
19969 return (int)(z - zBegin);
19970 #else
19971 return sqlite3Atoi64(z, pResult);
19972 #endif /* SQLITE_OMIT_FLOATING_POINT */
19973 }
19974
19975 /*
19976 ** Compare the 19-character string zNum against the text representation
19977 ** value 2^63: 9223372036854775808. Return negative, zero, or positive
19978 ** if zNum is less than, equal to, or greater than the string.
 
19979 **
19980 ** Unlike memcmp() this routine is guaranteed to return the difference
19981 ** in the values of the last digit if the only difference is in the
19982 ** last digit. So, for example,
19983 **
19984 ** compare2pow63("9223372036854775800")
19985 **
19986 ** will return -8.
19987 */
19988 static int compare2pow63(const char *zNum){
19989 int c;
19990 c = memcmp(zNum,"922337203685477580",18)*10;
 
 
 
 
 
19991 if( c==0 ){
19992 c = zNum[18] - '8';
19993 testcase( c==(-1) );
19994 testcase( c==0 );
19995 testcase( c==(+1) );
19996 }
19997 return c;
19998 }
19999
20000
20001 /*
20002 ** Return TRUE if zNum is a 64-bit signed integer and write
20003 ** the value of the integer into *pNum. If zNum is not an integer
20004 ** or is an integer that is too large to be expressed with 64 bits,
20005 ** then return false.
 
 
 
 
20006 **
20007 ** When this routine was originally written it dealt with only
20008 ** 32-bit numbers. At that time, it was much faster than the
20009 ** atoi() library routine in RedHat 7.2.
20010 */
20011 SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum){
 
20012 i64 v = 0;
20013 int neg;
20014 int i, c;
 
20015 const char *zStart;
20016 while( sqlite3Isspace(*zNum) ) zNum++;
 
 
 
20017 if( *zNum=='-' ){
20018 neg = 1;
20019 zNum++;
20020 }else if( *zNum=='+' ){
20021 neg = 0;
20022 zNum++;
20023 }else{
20024 neg = 0;
20025 }
 
20026 zStart = zNum;
20027 while( zNum[0]=='0' ){ zNum++; } /* Skip over leading zeros. Ticket #2454 */
20028 for(i=0; (c=zNum[i])>='0' && c<='9'; i++){
20029 v = v*10 + c - '0';
20030 }
20031 *pNum = neg ? -v : v;
20032 testcase( i==18 );
20033 testcase( i==19 );
20034 testcase( i==20 );
20035 if( c!=0 || (i==0 && zStart==zNum) || i>19 ){
20036 /* zNum is empty or contains non-numeric text or is longer
20037 ** than 19 digits (thus guaranting that it is too large) */
20038 return 0;
20039 }else if( i<19 ){
20040 /* Less than 19 digits, so we know that it fits in 64 bits */
20041 return 1;
20042 }else{
20043 /* 19-digit numbers must be no larger than 9223372036854775807 if positive
20044 ** or 9223372036854775808 if negative. Note that 9223372036854665808
20045 ** is 2^63. */
20046 return compare2pow63(zNum)<neg;
20047 }
20048 }
20049
20050 /*
20051 ** The string zNum represents an unsigned integer. The zNum string
20052 ** consists of one or more digit characters and is terminated by
20053 ** a zero character. Any stray characters in zNum result in undefined
20054 ** behavior.
20055 **
20056 ** If the unsigned integer that zNum represents will fit in a
20057 ** 64-bit signed integer, return TRUE. Otherwise return FALSE.
20058 **
20059 ** If the negFlag parameter is true, that means that zNum really represents
20060 ** a negative number. (The leading "-" is omitted from zNum.) This
20061 ** parameter is needed to determine a boundary case. A string
20062 ** of "9223373036854775808" returns false if negFlag is false or true
20063 ** if negFlag is true.
20064 **
20065 ** Leading zeros are ignored.
20066 */
20067 SQLITE_PRIVATE int sqlite3FitsIn64Bits(const char *zNum, int negFlag){
20068 int i;
20069 int neg = 0;
20070
20071 assert( zNum[0]>='0' && zNum[0]<='9' ); /* zNum is an unsigned number */
20072
20073 if( negFlag ) neg = 1-neg;
20074 while( *zNum=='0' ){
20075 zNum++; /* Skip leading zeros. Ticket #2454 */
20076 }
20077 for(i=0; zNum[i]; i++){ assert( zNum[i]>='0' && zNum[i]<='9' ); }
20078 testcase( i==18 );
20079 testcase( i==19 );
20080 testcase( i==20 );
20081 if( i<19 ){
20082 /* Guaranteed to fit if less than 19 digits */
20083 return 1;
20084 }else if( i>19 ){
20085 /* Guaranteed to be too big if greater than 19 digits */
20086 return 0;
20087 }else{
20088 /* Compare against 2^63. */
20089 return compare2pow63(zNum)<neg;
20090 }
20091 }
20092
20093 /*
20094 ** If zNum represents an integer that will fit in 32-bits, then set
@@ -26177,11 +26439,11 @@
26177 goto shmpage_out;
26178 }
26179 pShmNode->apRegion = apNew;
26180 while(pShmNode->nRegion<=iRegion){
26181 void *pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE,
26182 MAP_SHARED, pShmNode->h, iRegion*szRegion
26183 );
26184 if( pMem==MAP_FAILED ){
26185 rc = SQLITE_IOERR;
26186 goto shmpage_out;
26187 }
@@ -28000,17 +28262,20 @@
28000 static int proxyGetHostID(unsigned char *pHostID, int *pError){
28001 struct timespec timeout = {1, 0}; /* 1 sec timeout */
28002
28003 assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
28004 memset(pHostID, 0, PROXY_HOSTIDLEN);
 
 
28005 if( gethostuuid(pHostID, &timeout) ){
28006 int err = errno;
28007 if( pError ){
28008 *pError = err;
28009 }
28010 return SQLITE_IOERR;
28011 }
 
28012 #ifdef SQLITE_TEST
28013 /* simulate multiple hosts by creating unique hostid file paths */
28014 if( sqlite3_hostid_num != 0){
28015 pHostID[0] = (char)(pHostID[0] + (char)(sqlite3_hostid_num & 0xFF));
28016 }
@@ -30339,10 +30604,18 @@
30339 return SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN;
30340 }
30341
30342 #ifndef SQLITE_OMIT_WAL
30343
 
 
 
 
 
 
 
 
30344 /*
30345 ** Helper functions to obtain and relinquish the global mutex. The
30346 ** global mutex is used to protect the winLockInfo objects used by
30347 ** this file, all of which may be shared by multiple threads.
30348 **
@@ -30507,19 +30780,26 @@
30507 ** by VFS shared-memory methods.
30508 */
30509 static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
30510 winShmNode **pp;
30511 winShmNode *p;
 
30512 assert( winShmMutexHeld() );
30513 pp = &winShmNodeList;
30514 while( (p = *pp)!=0 ){
30515 if( p->nRef==0 ){
30516 int i;
30517 if( p->mutex ) sqlite3_mutex_free(p->mutex);
30518 for(i=0; i<p->nRegion; i++){
30519 UnmapViewOfFile(p->aRegion[i].pMap);
30520 CloseHandle(p->aRegion[i].hMap);
 
 
 
 
 
 
30521 }
30522 if( p->hFile.h != INVALID_HANDLE_VALUE ){
30523 SimulateIOErrorBenign(1);
30524 winClose((sqlite3_file *)&p->hFile);
30525 SimulateIOErrorBenign(0);
@@ -30592,14 +30872,15 @@
30592 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
30593 if( pShmNode->mutex==0 ){
30594 rc = SQLITE_NOMEM;
30595 goto shm_open_err;
30596 }
 
30597 rc = winOpen(pDbFd->pVfs,
30598 pShmNode->zFilename, /* Name of the file (UTF-8) */
30599 (sqlite3_file*)&pShmNode->hFile, /* File handle here */
30600 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, /* Mode flags */
30601 0);
30602 if( SQLITE_OK!=rc ){
30603 rc = SQLITE_CANTOPEN_BKPT;
30604 goto shm_open_err;
30605 }
@@ -30903,14 +31184,22 @@
30903 void *pMap = 0; /* Mapped memory region */
30904
30905 hMap = CreateFileMapping(pShmNode->hFile.h,
30906 NULL, PAGE_READWRITE, 0, nByte, NULL
30907 );
 
 
 
30908 if( hMap ){
 
 
30909 pMap = MapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
30910 0, 0, nByte
30911 );
 
 
 
30912 }
30913 if( !pMap ){
30914 pShmNode->lastErrno = GetLastError();
30915 rc = SQLITE_IOERR;
30916 if( hMap ) CloseHandle(hMap);
@@ -30923,12 +31212,14 @@
30923 }
30924 }
30925
30926 shmpage_out:
30927 if( pShmNode->nRegion>iRegion ){
 
 
30928 char *p = (char *)pShmNode->aRegion[iRegion].pMap;
30929 *pp = (void *)&p[iRegion*szRegion];
30930 }else{
30931 *pp = 0;
30932 }
30933 sqlite3_mutex_leave(pShmNode->mutex);
30934 return rc;
@@ -31151,13 +31442,64 @@
31151 DWORD dwFlagsAndAttributes = 0;
31152 #if SQLITE_OS_WINCE
31153 int isTemp = 0;
31154 #endif
31155 winFile *pFile = (winFile*)id;
31156 void *zConverted; /* Filename in OS encoding */
31157 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
31158 char zTmpname[MAX_PATH+1]; /* Buffer used to create temp filename */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31159
31160 assert( id!=0 );
31161 UNUSED_PARAMETER(pVfs);
31162
31163 pFile->h = INVALID_HANDLE_VALUE;
@@ -31164,11 +31506,12 @@
31164
31165 /* If the second argument to this function is NULL, generate a
31166 ** temporary file name to use
31167 */
31168 if( !zUtf8Name ){
31169 int rc = getTempname(MAX_PATH+1, zTmpname);
 
31170 if( rc!=SQLITE_OK ){
31171 return rc;
31172 }
31173 zUtf8Name = zTmpname;
31174 }
@@ -31177,33 +31520,35 @@
31177 zConverted = convertUtf8Filename(zUtf8Name);
31178 if( zConverted==0 ){
31179 return SQLITE_NOMEM;
31180 }
31181
31182 if( flags & SQLITE_OPEN_READWRITE ){
31183 dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
31184 }else{
31185 dwDesiredAccess = GENERIC_READ;
31186 }
 
31187 /* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is
31188 ** created. SQLite doesn't use it to indicate "exclusive access"
31189 ** as it is usually understood.
31190 */
31191 assert(!(flags & SQLITE_OPEN_EXCLUSIVE) || (flags & SQLITE_OPEN_CREATE));
31192 if( flags & SQLITE_OPEN_EXCLUSIVE ){
31193 /* Creates a new file, only if it does not already exist. */
31194 /* If the file exists, it fails. */
31195 dwCreationDisposition = CREATE_NEW;
31196 }else if( flags & SQLITE_OPEN_CREATE ){
31197 /* Open existing file, or create if it doesn't exist */
31198 dwCreationDisposition = OPEN_ALWAYS;
31199 }else{
31200 /* Opens a file, only if it exists. */
31201 dwCreationDisposition = OPEN_EXISTING;
31202 }
 
31203 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
31204 if( flags & SQLITE_OPEN_DELETEONCLOSE ){
 
31205 #if SQLITE_OS_WINCE
31206 dwFlagsAndAttributes = FILE_ATTRIBUTE_HIDDEN;
31207 isTemp = 1;
31208 #else
31209 dwFlagsAndAttributes = FILE_ATTRIBUTE_TEMPORARY
@@ -31216,10 +31561,11 @@
31216 /* Reports from the internet are that performance is always
31217 ** better if FILE_FLAG_RANDOM_ACCESS is used. Ticket #2699. */
31218 #if SQLITE_OS_WINCE
31219 dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
31220 #endif
 
31221 if( isNT() ){
31222 h = CreateFileW((WCHAR*)zConverted,
31223 dwDesiredAccess,
31224 dwShareMode,
31225 NULL,
@@ -31241,41 +31587,45 @@
31241 dwFlagsAndAttributes,
31242 NULL
31243 );
31244 #endif
31245 }
 
31246 OSTRACE(("OPEN %d %s 0x%lx %s\n",
31247 h, zName, dwDesiredAccess,
31248 h==INVALID_HANDLE_VALUE ? "failed" : "ok"));
 
31249 if( h==INVALID_HANDLE_VALUE ){
31250 pFile->lastErrno = GetLastError();
31251 free(zConverted);
31252 if( flags & SQLITE_OPEN_READWRITE ){
31253 return winOpen(pVfs, zName, id,
31254 ((flags|SQLITE_OPEN_READONLY)&~SQLITE_OPEN_READWRITE), pOutFlags);
31255 }else{
31256 return SQLITE_CANTOPEN_BKPT;
31257 }
31258 }
 
31259 if( pOutFlags ){
31260 if( flags & SQLITE_OPEN_READWRITE ){
31261 *pOutFlags = SQLITE_OPEN_READWRITE;
31262 }else{
31263 *pOutFlags = SQLITE_OPEN_READONLY;
31264 }
31265 }
 
31266 memset(pFile, 0, sizeof(*pFile));
31267 pFile->pMethod = &winIoMethod;
31268 pFile->h = h;
31269 pFile->lastErrno = NO_ERROR;
31270 pFile->pVfs = pVfs;
31271 pFile->pShm = 0;
31272 pFile->zPath = zName;
31273 pFile->sectorSize = getSectorSize(pVfs, zUtf8Name);
 
31274 #if SQLITE_OS_WINCE
31275 if( (flags & (SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB)) ==
31276 (SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB)
31277 && !winceCreateLock(zName, pFile)
31278 ){
31279 CloseHandle(h);
31280 free(zConverted);
31281 return SQLITE_CANTOPEN_BKPT;
@@ -31285,12 +31635,13 @@
31285 }else
31286 #endif
31287 {
31288 free(zConverted);
31289 }
 
31290 OpenCounter(+1);
31291 return SQLITE_OK;
31292 }
31293
31294 /*
31295 ** Delete the named file.
31296 **
@@ -31804,10 +32155,17 @@
31804 winSleep, /* xSleep */
31805 winCurrentTime, /* xCurrentTime */
31806 winGetLastError, /* xGetLastError */
31807 winCurrentTimeInt64, /* xCurrentTimeInt64 */
31808 };
 
 
 
 
 
 
 
31809
31810 sqlite3_vfs_register(&winVfs, 1);
31811 return SQLITE_OK;
31812 }
31813 SQLITE_API int sqlite3_os_end(void){
@@ -32369,16 +32727,20 @@
32369 ** Initialize and shutdown the page cache subsystem. Neither of these
32370 ** functions are threadsafe.
32371 */
32372 SQLITE_PRIVATE int sqlite3PcacheInitialize(void){
32373 if( sqlite3GlobalConfig.pcache.xInit==0 ){
 
 
 
32374 sqlite3PCacheSetDefault();
32375 }
32376 return sqlite3GlobalConfig.pcache.xInit(sqlite3GlobalConfig.pcache.pArg);
32377 }
32378 SQLITE_PRIVATE void sqlite3PcacheShutdown(void){
32379 if( sqlite3GlobalConfig.pcache.xShutdown ){
 
32380 sqlite3GlobalConfig.pcache.xShutdown(sqlite3GlobalConfig.pcache.pArg);
32381 }
32382 }
32383
32384 /*
@@ -32835,12 +33197,17 @@
32835
32836 typedef struct PCache1 PCache1;
32837 typedef struct PgHdr1 PgHdr1;
32838 typedef struct PgFreeslot PgFreeslot;
32839
32840 /* Pointers to structures of this type are cast and returned as
32841 ** opaque sqlite3_pcache* handles
 
 
 
 
 
32842 */
32843 struct PCache1 {
32844 /* Cache configuration parameters. Page size (szPage) and the purgeable
32845 ** flag (bPurgeable) are set when the cache is created. nMax may be
32846 ** modified at any time by a call to the pcache1CacheSize() method.
@@ -32896,10 +33263,13 @@
32896 int nCurrentPage; /* Number of purgeable pages allocated */
32897 PgHdr1 *pLruHead, *pLruTail; /* LRU list of unpinned pages */
32898
32899 /* Variables related to SQLITE_CONFIG_PAGECACHE settings. */
32900 int szSlot; /* Size of each free slot */
 
 
 
32901 void *pStart, *pEnd; /* Bounds of pagecache malloc range */
32902 PgFreeslot *pFree; /* Free page blocks */
32903 int isInit; /* True if initialized */
32904 } pcache1_g;
32905
@@ -32943,10 +33313,12 @@
32943 SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){
32944 if( pcache1.isInit ){
32945 PgFreeslot *p;
32946 sz = ROUNDDOWN8(sz);
32947 pcache1.szSlot = sz;
 
 
32948 pcache1.pStart = pBuf;
32949 pcache1.pFree = 0;
32950 while( n-- ){
32951 p = (PgFreeslot*)pBuf;
32952 p->pNext = pcache1.pFree;
@@ -32969,10 +33341,12 @@
32969 sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
32970 if( nByte<=pcache1.szSlot && pcache1.pFree ){
32971 assert( pcache1.isInit );
32972 p = (PgHdr1 *)pcache1.pFree;
32973 pcache1.pFree = pcache1.pFree->pNext;
 
 
32974 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);
32975 }else{
32976
32977 /* Allocate a new buffer using sqlite3Malloc. Before doing so, exit the
32978 ** global pcache mutex and unlock the pager-cache object pCache. This is
@@ -33002,10 +33376,12 @@
33002 PgFreeslot *pSlot;
33003 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
33004 pSlot = (PgFreeslot*)p;
33005 pSlot->pNext = pcache1.pFree;
33006 pcache1.pFree = pSlot;
 
 
33007 }else{
33008 int iSize;
33009 assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
33010 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
33011 iSize = sqlite3MallocSize(p);
@@ -33014,11 +33390,11 @@
33014 }
33015 }
33016
33017 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
33018 /*
33019 ** Return the size of a pache allocation
33020 */
33021 static int pcache1MemSize(void *p){
33022 assert( sqlite3_mutex_held(pcache1.mutex) );
33023 if( p>=pcache1.pStart && p<pcache1.pEnd ){
33024 return pcache1.szSlot;
@@ -33087,10 +33463,36 @@
33087 pcache1EnterMutex();
33088 pcache1Free(p);
33089 pcache1LeaveMutex();
33090 }
33091
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33092 /******************************************************************************/
33093 /******** General Implementation Functions ************************************/
33094
33095 /*
33096 ** This function is used to resize the hash table used by the cache passed
@@ -33328,18 +33730,20 @@
33328 ** copy of the requested page. If one is found, it is returned.
33329 **
33330 ** 2. If createFlag==0 and the page is not already in the cache, NULL is
33331 ** returned.
33332 **
33333 ** 3. If createFlag is 1, and the page is not already in the cache,
33334 ** and if either of the following are true, return NULL:
 
33335 **
33336 ** (a) the number of pages pinned by the cache is greater than
33337 ** PCache1.nMax, or
 
33338 ** (b) the number of pages pinned by the cache is greater than
33339 ** the sum of nMax for all purgeable caches, less the sum of
33340 ** nMin for all other purgeable caches.
33341 **
33342 ** 4. If none of the first three conditions apply and the cache is marked
33343 ** as purgeable, and if one of the following is true:
33344 **
33345 ** (a) The number of pages allocated for the cache is already
@@ -33346,10 +33750,13 @@
33346 ** PCache1.nMax, or
33347 **
33348 ** (b) The number of pages allocated for all purgeable caches is
33349 ** already equal to or greater than the sum of nMax for all
33350 ** purgeable caches,
 
 
 
33351 **
33352 ** then attempt to recycle a page from the LRU list. If it is the right
33353 ** size, return the recycled buffer. Otherwise, free the buffer and
33354 ** proceed to step 5.
33355 **
@@ -33378,10 +33785,11 @@
33378 /* Step 3 of header comment. */
33379 nPinned = pCache->nPage - pCache->nRecyclable;
33380 if( createFlag==1 && (
33381 nPinned>=(pcache1.nMaxPage+pCache->nMin-pcache1.nMinPage)
33382 || nPinned>=(pCache->nMax * 9 / 10)
 
33383 )){
33384 goto fetch_out;
33385 }
33386
33387 if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){
@@ -33388,11 +33796,13 @@
33388 goto fetch_out;
33389 }
33390
33391 /* Step 4. Try to recycle a page buffer if appropriate. */
33392 if( pCache->bPurgeable && pcache1.pLruTail && (
33393 (pCache->nPage+1>=pCache->nMax) || pcache1.nCurrentPage>=pcache1.nMaxPage
 
 
33394 )){
33395 pPage = pcache1.pLruTail;
33396 pcache1RemoveFromHash(pPage);
33397 pcache1PinPage(pPage);
33398 if( pPage->pCache->szPage!=pCache->szPage ){
@@ -33531,10 +33941,11 @@
33531 **
33532 ** Destroy a cache allocated using pcache1Create().
33533 */
33534 static void pcache1Destroy(sqlite3_pcache *p){
33535 PCache1 *pCache = (PCache1 *)p;
 
33536 pcache1EnterMutex();
33537 pcache1TruncateUnsafe(pCache, 0);
33538 pcache1.nMaxPage -= pCache->nMax;
33539 pcache1.nMinPage -= pCache->nMin;
33540 pcache1EnforceMaxPage();
@@ -33578,11 +33989,11 @@
33578 SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
33579 int nFree = 0;
33580 if( pcache1.pStart==0 ){
33581 PgHdr1 *p;
33582 pcache1EnterMutex();
33583 while( (nReq<0 || nFree<nReq) && (p=pcache1.pLruTail) ){
33584 nFree += pcache1MemSize(PGHDR1_TO_PAGE(p));
33585 pcache1PinPage(p);
33586 pcache1RemoveFromHash(p);
33587 pcache1FreePage(p);
33588 }
@@ -37120,16 +37531,17 @@
37120 ** the duplicate call is harmless.
37121 */
37122 sqlite3WalEndReadTransaction(pPager->pWal);
37123
37124 rc = sqlite3WalBeginReadTransaction(pPager->pWal, &changed);
37125 if( rc==SQLITE_OK && changed ){
37126 pager_reset(pPager);
37127 }
37128
37129 return rc;
37130 }
 
37131
37132 /*
37133 ** This function is called as part of the transition from PAGER_OPEN
37134 ** to PAGER_READER state to determine the size of the database file
37135 ** in pages (assuming the page size currently stored in Pager.pageSize).
@@ -37182,11 +37594,11 @@
37182
37183 *pnPage = nPage;
37184 return SQLITE_OK;
37185 }
37186
37187
37188 /*
37189 ** Check if the *-wal file that corresponds to the database opened by pPager
37190 ** exists if the database is not empy, or verify that the *-wal file does
37191 ** not exist (by deleting it) if the database file is empty.
37192 **
@@ -38374,10 +38786,17 @@
38374 journalFileSize = ROUND8(sqlite3MemJournalSize());
38375 }
38376
38377 /* Set the output variable to NULL in case an error occurs. */
38378 *ppPager = 0;
 
 
 
 
 
 
 
38379
38380 /* Compute and store the full pathname in an allocated buffer pointed
38381 ** to by zPathname, length nPathname. Or, if this is a temporary file,
38382 ** leave both nPathname and zPathname set to 0.
38383 */
@@ -38385,21 +38804,12 @@
38385 nPathname = pVfs->mxPathname+1;
38386 zPathname = sqlite3Malloc(nPathname*2);
38387 if( zPathname==0 ){
38388 return SQLITE_NOMEM;
38389 }
38390 #ifndef SQLITE_OMIT_MEMORYDB
38391 if( strcmp(zFilename,":memory:")==0 ){
38392 memDb = 1;
38393 zPathname[0] = 0;
38394 }else
38395 #endif
38396 {
38397 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
38398 rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
38399 }
38400
38401 nPathname = sqlite3Strlen30(zPathname);
38402 if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){
38403 /* This branch is taken when the journal path required by
38404 ** the database being opened will be more than pVfs->mxPathname
38405 ** bytes in length. This means the database cannot be opened,
@@ -38450,34 +38860,31 @@
38450 pPager->zFilename = (char*)(pPtr += journalFileSize);
38451 assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) );
38452
38453 /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
38454 if( zPathname ){
 
38455 pPager->zJournal = (char*)(pPtr += nPathname + 1);
38456 memcpy(pPager->zFilename, zPathname, nPathname);
38457 memcpy(pPager->zJournal, zPathname, nPathname);
38458 memcpy(&pPager->zJournal[nPathname], "-journal", 8);
38459 if( pPager->zFilename[0]==0 ){
38460 pPager->zJournal[0] = 0;
38461 }
38462 #ifndef SQLITE_OMIT_WAL
38463 else{
38464 pPager->zWal = &pPager->zJournal[nPathname+8+1];
38465 memcpy(pPager->zWal, zPathname, nPathname);
38466 memcpy(&pPager->zWal[nPathname], "-wal", 4);
38467 }
38468 #endif
38469 sqlite3_free(zPathname);
38470 }
38471 pPager->pVfs = pVfs;
38472 pPager->vfsFlags = vfsFlags;
38473
38474 /* Open the pager file.
38475 */
38476 if( zFilename && zFilename[0] && !memDb ){
38477 int fout = 0; /* VFS flags returned by xOpen() */
38478 rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
 
38479 readOnly = (fout&SQLITE_OPEN_READONLY);
38480
38481 /* If the file was successfully opened for read/write access,
38482 ** choose a default page size in case we have to create the
38483 ** database file. The default page size is the maximum of:
@@ -38927,11 +39334,13 @@
38927
38928 /* If there is a WAL file in the file-system, open this database in WAL
38929 ** mode. Otherwise, the following function call is a no-op.
38930 */
38931 rc = pagerOpenWalIfPresent(pPager);
 
38932 assert( pPager->pWal==0 || rc==SQLITE_OK );
 
38933 }
38934
38935 if( pagerUseWal(pPager) ){
38936 assert( rc==SQLITE_OK );
38937 rc = pagerBeginReadTransaction(pPager);
@@ -43292,11 +43701,11 @@
43292 WALTRACE(("WAL%p: wal-header write %s\n", pWal, rc ? "failed" : "ok"));
43293 if( rc!=SQLITE_OK ){
43294 return rc;
43295 }
43296 }
43297 assert( pWal->szPage==szPage );
43298
43299 /* Write the log file. */
43300 for(p=pList; p; p=p->pDirty){
43301 u32 nDbsize; /* Db-size field for frame header */
43302 i64 iOffset; /* Write offset in log file */
@@ -43952,10 +44361,11 @@
43952 MemPage *pPage1; /* First page of the database */
43953 u8 readOnly; /* True if the underlying file is readonly */
43954 u8 pageSizeFixed; /* True if the page size can no longer be changed */
43955 u8 secureDelete; /* True if secure_delete is enabled */
43956 u8 initiallyEmpty; /* Database is empty at start of transaction */
 
43957 #ifndef SQLITE_OMIT_AUTOVACUUM
43958 u8 autoVacuum; /* True if auto-vacuum is enabled */
43959 u8 incrVacuum; /* True if incr-vacuum is enabled */
43960 #endif
43961 u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
@@ -46202,15 +46612,24 @@
46202
46203 /*
46204 ** Open a database file.
46205 **
46206 ** zFilename is the name of the database file. If zFilename is NULL
46207 ** a new database with a random name is created. This randomly named
46208 ** database file will be deleted when sqlite3BtreeClose() is called.
 
 
 
46209 ** If zFilename is ":memory:" then an in-memory database is created
46210 ** that is automatically destroyed when it is closed.
46211 **
 
 
 
 
 
 
46212 ** If the database is already opened in the same database connection
46213 ** and we are in shared cache mode, then the open will fail with an
46214 ** SQLITE_CONSTRAINT error. We cannot allow two or more BtShared
46215 ** objects in the same database connection since doing so will lead
46216 ** to problems with locking.
@@ -46227,10 +46646,13 @@
46227 Btree *p; /* Handle to return */
46228 sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */
46229 int rc = SQLITE_OK; /* Result code from this function */
46230 u8 nReserve; /* Byte of unused space on each page */
46231 unsigned char zDbHeader[100]; /* Database header content */
 
 
 
46232
46233 /* Set the variable isMemdb to true for an in-memory database, or
46234 ** false for a file-based database. This symbol is only required if
46235 ** either of the shared-data or autovacuum features are compiled
46236 ** into the library.
@@ -46237,17 +46659,34 @@
46237 */
46238 #if !defined(SQLITE_OMIT_SHARED_CACHE) || !defined(SQLITE_OMIT_AUTOVACUUM)
46239 #ifdef SQLITE_OMIT_MEMORYDB
46240 const int isMemdb = 0;
46241 #else
46242 const int isMemdb = zFilename && !strcmp(zFilename, ":memory:");
 
46243 #endif
46244 #endif
46245
46246 assert( db!=0 );
46247 assert( sqlite3_mutex_held(db->mutex) );
 
46248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46249 pVfs = db->pVfs;
46250 p = sqlite3MallocZero(sizeof(Btree));
46251 if( !p ){
46252 return SQLITE_NOMEM;
46253 }
@@ -46261,11 +46700,11 @@
46261 #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
46262 /*
46263 ** If this Btree is a candidate for shared cache, try to find an
46264 ** existing BtShared object that we can share with
46265 */
46266 if( isMemdb==0 && zFilename && zFilename[0] ){
46267 if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){
46268 int nFullPathname = pVfs->mxPathname+1;
46269 char *zFullPathname = sqlite3Malloc(nFullPathname);
46270 sqlite3_mutex *mutexShared;
46271 p->sharable = 1;
@@ -46336,10 +46775,11 @@
46336 rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
46337 }
46338 if( rc!=SQLITE_OK ){
46339 goto btree_open_out;
46340 }
 
46341 pBt->db = db;
46342 sqlite3PagerSetBusyhandler(pBt->pPager, btreeInvokeBusyHandler, pBt);
46343 p->pBt = pBt;
46344
46345 pBt->pCursor = 0;
@@ -46440,10 +46880,18 @@
46440 sqlite3PagerClose(pBt->pPager);
46441 }
46442 sqlite3_free(pBt);
46443 sqlite3_free(p);
46444 *ppBtree = 0;
 
 
 
 
 
 
 
 
46445 }
46446 if( mutexOpen ){
46447 assert( sqlite3_mutex_held(mutexOpen) );
46448 sqlite3_mutex_leave(mutexOpen);
46449 }
@@ -51390,15 +51838,16 @@
51390 ** flags might not work:
51391 **
51392 ** BTREE_INTKEY|BTREE_LEAFDATA Used for SQL tables with rowid keys
51393 ** BTREE_ZERODATA Used for SQL indices
51394 */
51395 static int btreeCreateTable(Btree *p, int *piTable, int flags){
51396 BtShared *pBt = p->pBt;
51397 MemPage *pRoot;
51398 Pgno pgnoRoot;
51399 int rc;
 
51400
51401 assert( sqlite3BtreeHoldsMutex(p) );
51402 assert( pBt->inTransaction==TRANS_WRITE );
51403 assert( !pBt->readOnly );
51404
@@ -51513,12 +51962,18 @@
51513 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
51514 if( rc ) return rc;
51515 }
51516 #endif
51517 assert( sqlite3PagerIswriteable(pRoot->pDbPage) );
51518 zeroPage(pRoot, flags | PTF_LEAF);
 
 
 
 
 
51519 sqlite3PagerUnref(pRoot->pDbPage);
 
51520 *piTable = (int)pgnoRoot;
51521 return SQLITE_OK;
51522 }
51523 SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree *p, int *piTable, int flags){
51524 int rc;
@@ -52774,11 +53229,14 @@
52774 sqlite3Error(
52775 pDestDb, SQLITE_ERROR, "source and destination must be distinct"
52776 );
52777 p = 0;
52778 }else {
52779 /* Allocate space for a new sqlite3_backup object */
 
 
 
52780 p = (sqlite3_backup *)sqlite3_malloc(sizeof(sqlite3_backup));
52781 if( !p ){
52782 sqlite3Error(pDestDb, SQLITE_NOMEM, 0);
52783 }
52784 }
@@ -53157,10 +53615,13 @@
53157 if( p->pDestDb ){
53158 sqlite3_mutex_leave(p->pDestDb->mutex);
53159 }
53160 sqlite3BtreeLeave(p->pSrc);
53161 if( p->pDestDb ){
 
 
 
53162 sqlite3_free(p);
53163 }
53164 sqlite3_mutex_leave(mutex);
53165 return rc;
53166 }
@@ -53408,10 +53869,13 @@
53408 return SQLITE_NOMEM;
53409 }
53410 pMem->z[pMem->n] = 0;
53411 pMem->z[pMem->n+1] = 0;
53412 pMem->flags |= MEM_Term;
 
 
 
53413 }
53414
53415 return SQLITE_OK;
53416 }
53417
@@ -53528,11 +53992,11 @@
53528 memset(&ctx, 0, sizeof(ctx));
53529 ctx.s.flags = MEM_Null;
53530 ctx.s.db = pMem->db;
53531 ctx.pMem = pMem;
53532 ctx.pFunc = pFunc;
53533 pFunc->xFinalize(&ctx);
53534 assert( 0==(pMem->flags&MEM_Dyn) && !pMem->xDel );
53535 sqlite3DbFree(pMem->db, pMem->zMalloc);
53536 memcpy(pMem, &ctx.s, sizeof(ctx.s));
53537 rc = ctx.isError;
53538 }
@@ -53641,17 +54105,13 @@
53641 return pMem->u.i;
53642 }else if( flags & MEM_Real ){
53643 return doubleToInt64(pMem->r);
53644 }else if( flags & (MEM_Str|MEM_Blob) ){
53645 i64 value;
53646 pMem->flags |= MEM_Str;
53647 if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
53648 || sqlite3VdbeMemNulTerminate(pMem) ){
53649 return 0;
53650 }
53651 assert( pMem->z );
53652 sqlite3Atoi64(pMem->z, &value);
53653 return value;
53654 }else{
53655 return 0;
53656 }
53657 }
@@ -53677,11 +54137,11 @@
53677 || sqlite3VdbeMemNulTerminate(pMem) ){
53678 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
53679 return (double)0;
53680 }
53681 assert( pMem->z );
53682 sqlite3AtoF(pMem->z, &val);
53683 return val;
53684 }else{
53685 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
53686 return (double)0;
53687 }
@@ -53750,25 +54210,23 @@
53750 ** Every effort is made to force the conversion, even if the input
53751 ** is a string that does not look completely like a number. Convert
53752 ** as much of the string as we can and ignore the rest.
53753 */
53754 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem *pMem){
53755 int rc;
53756 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))==0 );
53757 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
53758 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
53759 rc = sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8);
53760 if( rc ) return rc;
53761 rc = sqlite3VdbeMemNulTerminate(pMem);
53762 if( rc ) return rc;
53763 if( sqlite3Atoi64(pMem->z, &pMem->u.i) ){
53764 MemSetTypeFlag(pMem, MEM_Int);
53765 }else{
53766 pMem->r = sqlite3VdbeRealValue(pMem);
53767 MemSetTypeFlag(pMem, MEM_Real);
53768 sqlite3VdbeIntegerAffinity(pMem);
53769 }
53770 return SQLITE_OK;
53771 }
53772
53773 /*
53774 ** Delete any previous value and set the value stored in *pMem to NULL.
@@ -53869,10 +54327,32 @@
53869 return n>p->db->aLimit[SQLITE_LIMIT_LENGTH];
53870 }
53871 return 0;
53872 }
53873
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53874 /*
53875 ** Size of struct Mem not including the Mem.zMalloc member.
53876 */
53877 #define MEMCELLSIZE (size_t)(&(((Mem *)0)->zMalloc))
53878
@@ -54237,11 +54717,11 @@
54237 assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 );
54238 if( sqlite3VdbeMemMakeWriteable(pVal)!=SQLITE_OK ){
54239 return 0;
54240 }
54241 }
54242 sqlite3VdbeMemNulTerminate(pVal);
54243 }else{
54244 assert( (pVal->flags&MEM_Blob)==0 );
54245 sqlite3VdbeMemStringify(pVal, enc);
54246 assert( 0==(1&SQLITE_PTR_TO_INT(pVal->z)) );
54247 }
@@ -54285,10 +54765,12 @@
54285 sqlite3_value **ppVal /* Write the new value here */
54286 ){
54287 int op;
54288 char *zVal = 0;
54289 sqlite3_value *pVal = 0;
 
 
54290
54291 if( !pExpr ){
54292 *ppVal = 0;
54293 return SQLITE_OK;
54294 }
@@ -54301,35 +54783,50 @@
54301 #ifdef SQLITE_ENABLE_STAT2
54302 if( op==TK_REGISTER ) op = pExpr->op2;
54303 #else
54304 if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
54305 #endif
 
 
 
 
 
 
 
 
 
 
 
54306
54307 if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
54308 pVal = sqlite3ValueNew(db);
54309 if( pVal==0 ) goto no_mem;
54310 if( ExprHasProperty(pExpr, EP_IntValue) ){
54311 sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue);
54312 }else{
54313 zVal = sqlite3DbStrDup(db, pExpr->u.zToken);
54314 if( zVal==0 ) goto no_mem;
54315 sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
54316 if( op==TK_FLOAT ) pVal->type = SQLITE_FLOAT;
54317 }
54318 if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
54319 sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
54320 }else{
54321 sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
54322 }
 
54323 if( enc!=SQLITE_UTF8 ){
54324 sqlite3VdbeChangeEncoding(pVal, enc);
54325 }
54326 }else if( op==TK_UMINUS ) {
 
54327 if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){
 
54328 pVal->u.i = -1 * pVal->u.i;
54329 /* (double)-1 In case of SQLITE_OMIT_FLOATING_POINT... */
54330 pVal->r = (double)-1 * pVal->r;
 
54331 }
54332 }
54333 #ifndef SQLITE_OMIT_BLOB_LITERAL
54334 else if( op==TK_BLOB ){
54335 int nVal;
@@ -56152,13 +56649,14 @@
56152 */
56153 for(i=0; i<db->nDb; i++){
56154 Btree *pBt = db->aDb[i].pBt;
56155 if( sqlite3BtreeIsInTrans(pBt) ){
56156 char const *zFile = sqlite3BtreeGetJournalname(pBt);
56157 if( zFile==0 || zFile[0]==0 ){
56158 continue; /* Ignore TEMP and :memory: databases */
56159 }
 
56160 if( !needSync && !sqlite3BtreeSyncDisabled(pBt) ){
56161 needSync = 1;
56162 }
56163 rc = sqlite3OsWrite(pMaster, zFile, sqlite3Strlen30(zFile)+1, offset);
56164 offset += sqlite3Strlen30(zFile)+1;
@@ -57618,10 +58116,12 @@
57618 ** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16().
57619 */
57620 SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt){
57621 int rc;
57622 if( pStmt==0 ){
 
 
57623 rc = SQLITE_OK;
57624 }else{
57625 Vdbe *v = (Vdbe*)pStmt;
57626 sqlite3 *db = v->db;
57627 #if SQLITE_THREADSAFE
@@ -57694,11 +58194,11 @@
57694 Mem *p = (Mem*)pVal;
57695 if( p->flags & (MEM_Blob|MEM_Str) ){
57696 sqlite3VdbeMemExpandBlob(p);
57697 p->flags &= ~MEM_Str;
57698 p->flags |= MEM_Blob;
57699 return p->z;
57700 }else{
57701 return sqlite3_value_text(pVal);
57702 }
57703 }
57704 SQLITE_API int sqlite3_value_bytes(sqlite3_value *pVal){
@@ -58048,10 +58548,16 @@
58048 }
58049
58050 /*
58051 ** Extract the user data from a sqlite3_context structure and return a
58052 ** pointer to it.
 
 
 
 
 
 
58053 */
58054 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){
58055 assert( p && p->pFunc );
58056 return p->s.db;
58057 }
@@ -58257,12 +58763,11 @@
58257 ** sqlite3_column_text()
58258 ** sqlite3_column_text16()
58259 ** sqlite3_column_real()
58260 ** sqlite3_column_bytes()
58261 ** sqlite3_column_bytes16()
58262 **
58263 ** But not for sqlite3_column_blob(), which never calls malloc().
58264 */
58265 static void columnMallocFailure(sqlite3_stmt *pStmt)
58266 {
58267 /* If malloc() failed during an encoding conversion within an
58268 ** sqlite3_column_XXX API, then set the return code of the statement to
@@ -58526,10 +59031,16 @@
58526 pVar->flags = MEM_Null;
58527 sqlite3Error(p->db, SQLITE_OK, 0);
58528
58529 /* If the bit corresponding to this variable in Vdbe.expmask is set, then
58530 ** binding a new value to this variable invalidates the current query plan.
 
 
 
 
 
 
58531 */
58532 if( p->isPrepareV2 &&
58533 ((i<32 && p->expmask & ((u32)1 << i)) || p->expmask==0xffffffff)
58534 ){
58535 p->expired = 1;
@@ -59023,10 +59534,21 @@
59023 ** of the code in this file is, therefore, important. See other comments
59024 ** in this file for details. If in doubt, do not deviate from existing
59025 ** commenting and indentation practices when changing or adding code.
59026 */
59027
 
 
 
 
 
 
 
 
 
 
 
59028 /*
59029 ** The following global variable is incremented every time a cursor
59030 ** moves, either by the OP_SeekXX, OP_Next, or OP_Prev opcodes. The test
59031 ** procedures use this information to make sure that indices are
59032 ** working correctly. This variable has no function other than to
@@ -59215,35 +59737,21 @@
59215 ** looks like a number, convert it into a number. If it does not
59216 ** look like a number, leave it alone.
59217 */
59218 static void applyNumericAffinity(Mem *pRec){
59219 if( (pRec->flags & (MEM_Real|MEM_Int))==0 ){
59220 int realnum;
 
59221 u8 enc = pRec->enc;
59222 sqlite3VdbeMemNulTerminate(pRec);
59223 if( (pRec->flags&MEM_Str) && sqlite3IsNumber(pRec->z, &realnum, enc) ){
59224 i64 value;
59225 char *zUtf8 = pRec->z;
59226 #ifndef SQLITE_OMIT_UTF16
59227 if( enc!=SQLITE_UTF8 ){
59228 assert( pRec->db );
59229 zUtf8 = sqlite3Utf16to8(pRec->db, pRec->z, pRec->n, enc);
59230 if( !zUtf8 ) return;
59231 }
59232 #endif
59233 if( !realnum && sqlite3Atoi64(zUtf8, &value) ){
59234 pRec->u.i = value;
59235 MemSetTypeFlag(pRec, MEM_Int);
59236 }else{
59237 sqlite3AtoF(zUtf8, &pRec->r);
59238 MemSetTypeFlag(pRec, MEM_Real);
59239 }
59240 #ifndef SQLITE_OMIT_UTF16
59241 if( enc!=SQLITE_UTF8 ){
59242 sqlite3DbFree(pRec->db, zUtf8);
59243 }
59244 #endif
59245 }
59246 }
59247 }
59248
59249 /*
@@ -60132,38 +60640,44 @@
60132 assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
60133 if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){
60134 assert( pOp->p2>0 );
60135 assert( pOp->p2<=p->nMem );
60136 pOut = &aMem[pOp->p2];
 
60137 sqlite3VdbeMemReleaseExternal(pOut);
60138 pOut->flags = MEM_Int;
60139 }
60140
60141 /* Sanity checking on other operands */
60142 #ifdef SQLITE_DEBUG
60143 if( (pOp->opflags & OPFLG_IN1)!=0 ){
60144 assert( pOp->p1>0 );
60145 assert( pOp->p1<=p->nMem );
 
60146 REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
60147 }
60148 if( (pOp->opflags & OPFLG_IN2)!=0 ){
60149 assert( pOp->p2>0 );
60150 assert( pOp->p2<=p->nMem );
 
60151 REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
60152 }
60153 if( (pOp->opflags & OPFLG_IN3)!=0 ){
60154 assert( pOp->p3>0 );
60155 assert( pOp->p3<=p->nMem );
 
60156 REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
60157 }
60158 if( (pOp->opflags & OPFLG_OUT2)!=0 ){
60159 assert( pOp->p2>0 );
60160 assert( pOp->p2<=p->nMem );
 
60161 }
60162 if( (pOp->opflags & OPFLG_OUT3)!=0 ){
60163 assert( pOp->p3>0 );
60164 assert( pOp->p3<=p->nMem );
 
60165 }
60166 #endif
60167
60168 switch( pOp->opcode ){
60169
@@ -60221,10 +60735,11 @@
60221 ** and then jump to address P2.
60222 */
60223 case OP_Gosub: { /* jump, in1 */
60224 pIn1 = &aMem[pOp->p1];
60225 assert( (pIn1->flags & MEM_Dyn)==0 );
 
60226 pIn1->flags = MEM_Int;
60227 pIn1->u.i = pc;
60228 REGISTER_TRACE(pOp->p1, pIn1);
60229 pc = pOp->p2 - 1;
60230 break;
@@ -60428,15 +60943,11 @@
60428
60429
60430 /* Opcode: Blob P1 P2 * P4
60431 **
60432 ** P4 points to a blob of data P1 bytes long. Store this
60433 ** blob in register P2. This instruction is not coded directly
60434 ** by the compiler. Instead, the compiler layer specifies
60435 ** an OP_HexBlob opcode, with the hex string representation of
60436 ** the blob as P4. This opcode is transformed to an OP_Blob
60437 ** the first time it is executed.
60438 */
60439 case OP_Blob: { /* out2-prerelease */
60440 assert( pOp->p1 <= SQLITE_MAX_LENGTH );
60441 sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
60442 pOut->enc = encoding;
@@ -60490,10 +61001,12 @@
60490 pIn1 = &aMem[u.ac.p1];
60491 pOut = &aMem[u.ac.p2];
60492 while( u.ac.n-- ){
60493 assert( pOut<=&aMem[p->nMem] );
60494 assert( pIn1<=&aMem[p->nMem] );
 
 
60495 u.ac.zMalloc = pOut->zMalloc;
60496 pOut->zMalloc = 0;
60497 sqlite3VdbeMemMove(pOut, pIn1);
60498 pIn1->zMalloc = u.ac.zMalloc;
60499 REGISTER_TRACE(u.ac.p2++, pOut);
@@ -60535,10 +61048,13 @@
60535 case OP_SCopy: { /* in1, out2 */
60536 pIn1 = &aMem[pOp->p1];
60537 pOut = &aMem[pOp->p2];
60538 assert( pOut!=pIn1 );
60539 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
 
 
 
60540 REGISTER_TRACE(pOp->p2, pOut);
60541 break;
60542 }
60543
60544 /* Opcode: ResultRow P1 P2 * * *
@@ -60595,10 +61111,14 @@
60595 ** and have an assigned type. The results are de-ephemeralized as
60596 ** as side effect.
60597 */
60598 u.ad.pMem = p->pResultSet = &aMem[pOp->p1];
60599 for(u.ad.i=0; u.ad.i<pOp->p2; u.ad.i++){
 
 
 
 
60600 sqlite3VdbeMemNulTerminate(&u.ad.pMem[u.ad.i]);
60601 sqlite3VdbeMemStoreType(&u.ad.pMem[u.ad.i]);
60602 REGISTER_TRACE(pOp->p1+u.ad.i, &u.ad.pMem[u.ad.i]);
60603 }
60604 if( db->mallocFailed ) goto no_mem;
@@ -60826,16 +61346,21 @@
60826 #endif /* local variables moved into u.ag */
60827
60828 u.ag.n = pOp->p5;
60829 u.ag.apVal = p->apArg;
60830 assert( u.ag.apVal || u.ag.n==0 );
 
 
 
60831
60832 assert( u.ag.n==0 || (pOp->p2>0 && pOp->p2+u.ag.n<=p->nMem+1) );
60833 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.ag.n );
60834 u.ag.pArg = &aMem[pOp->p2];
60835 for(u.ag.i=0; u.ag.i<u.ag.n; u.ag.i++, u.ag.pArg++){
 
60836 u.ag.apVal[u.ag.i] = u.ag.pArg;
 
60837 sqlite3VdbeMemStoreType(u.ag.pArg);
60838 REGISTER_TRACE(pOp->p2+u.ag.i, u.ag.pArg);
60839 }
60840
60841 assert( pOp->p4type==P4_FUNCDEF || pOp->p4type==P4_VDBEFUNC );
@@ -60845,12 +61370,10 @@
60845 }else{
60846 u.ag.ctx.pVdbeFunc = (VdbeFunc*)pOp->p4.pVdbeFunc;
60847 u.ag.ctx.pFunc = u.ag.ctx.pVdbeFunc->pFunc;
60848 }
60849
60850 assert( pOp->p3>0 && pOp->p3<=p->nMem );
60851 pOut = &aMem[pOp->p3];
60852 u.ag.ctx.s.flags = MEM_Null;
60853 u.ag.ctx.s.db = db;
60854 u.ag.ctx.s.xDel = 0;
60855 u.ag.ctx.s.zMalloc = 0;
60856
@@ -60866,11 +61389,11 @@
60866 assert( pOp>aOp );
60867 assert( pOp[-1].p4type==P4_COLLSEQ );
60868 assert( pOp[-1].opcode==OP_CollSeq );
60869 u.ag.ctx.pColl = pOp[-1].p4.pColl;
60870 }
60871 (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal);
60872 if( db->mallocFailed ){
60873 /* Even though a malloc() has failed, the implementation of the
60874 ** user function may have called an sqlite3_result_XXX() function
60875 ** to return a value. The following call releases any resources
60876 ** associated with such a value.
@@ -60918,11 +61441,11 @@
60918 ** If either input is NULL, the result is NULL.
60919 */
60920 /* Opcode: ShiftLeft P1 P2 P3 * *
60921 **
60922 ** Shift the integer value in register P2 to the left by the
60923 ** number of bits specified by the integer in regiser P1.
60924 ** Store the result in register P3.
60925 ** If either input is NULL, the result is NULL.
60926 */
60927 /* Opcode: ShiftRight P1 P2 P3 * *
60928 **
@@ -60968,10 +61491,11 @@
60968 **
60969 ** To force any register to be an integer, just add 0.
60970 */
60971 case OP_AddImm: { /* in1 */
60972 pIn1 = &aMem[pOp->p1];
 
60973 sqlite3VdbeMemIntegerify(pIn1);
60974 pIn1->u.i += pOp->p2;
60975 break;
60976 }
60977
@@ -60982,10 +61506,11 @@
60982 ** without data loss, then jump immediately to P2, or if P2==0
60983 ** raise an SQLITE_MISMATCH exception.
60984 */
60985 case OP_MustBeInt: { /* jump, in1 */
60986 pIn1 = &aMem[pOp->p1];
 
60987 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
60988 if( (pIn1->flags & MEM_Int)==0 ){
60989 if( pOp->p2==0 ){
60990 rc = SQLITE_MISMATCH;
60991 goto abort_due_to_error;
@@ -61027,10 +61552,11 @@
61027 **
61028 ** A NULL value is not changed by this routine. It remains NULL.
61029 */
61030 case OP_ToText: { /* same as TK_TO_TEXT, in1 */
61031 pIn1 = &aMem[pOp->p1];
 
61032 if( pIn1->flags & MEM_Null ) break;
61033 assert( MEM_Str==(MEM_Blob>>3) );
61034 pIn1->flags |= (pIn1->flags&MEM_Blob)>>3;
61035 applyAffinity(pIn1, SQLITE_AFF_TEXT, encoding);
61036 rc = ExpandBlob(pIn1);
@@ -61073,20 +61599,18 @@
61073 **
61074 ** A NULL value is not changed by this routine. It remains NULL.
61075 */
61076 case OP_ToNumeric: { /* same as TK_TO_NUMERIC, in1 */
61077 pIn1 = &aMem[pOp->p1];
61078 if( (pIn1->flags & (MEM_Null|MEM_Int|MEM_Real))==0 ){
61079 sqlite3VdbeMemNumerify(pIn1);
61080 }
61081 break;
61082 }
61083 #endif /* SQLITE_OMIT_CAST */
61084
61085 /* Opcode: ToInt P1 * * * *
61086 **
61087 ** Force the value in register P1 be an integer. If
61088 ** The value is currently a real number, drop its fractional part.
61089 ** If the value is text or blob, try to convert it to an integer using the
61090 ** equivalent of atoi() and store 0 if no such conversion is possible.
61091 **
61092 ** A NULL value is not changed by this routine. It remains NULL.
@@ -61109,10 +61633,11 @@
61109 **
61110 ** A NULL value is not changed by this routine. It remains NULL.
61111 */
61112 case OP_ToReal: { /* same as TK_TO_REAL, in1 */
61113 pIn1 = &aMem[pOp->p1];
 
61114 if( (pIn1->flags & MEM_Null)==0 ){
61115 sqlite3VdbeMemRealify(pIn1);
61116 }
61117 break;
61118 }
@@ -61123,11 +61648,11 @@
61123 ** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
61124 ** jump to address P2.
61125 **
61126 ** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
61127 ** reg(P3) is NULL then take the jump. If the SQLITE_JUMPIFNULL
61128 ** bit is clear then fall thru if either operand is NULL.
61129 **
61130 ** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
61131 ** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
61132 ** to coerce both inputs according to this affinity before the
61133 ** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
@@ -61253,10 +61778,11 @@
61253 default: u.ai.res = u.ai.res>=0; break;
61254 }
61255
61256 if( pOp->p5 & SQLITE_STOREP2 ){
61257 pOut = &aMem[pOp->p2];
 
61258 MemSetTypeFlag(pOut, MEM_Int);
61259 pOut->u.i = u.ai.res;
61260 REGISTER_TRACE(pOp->p2, pOut);
61261 }else if( u.ai.res ){
61262 pc = pOp->p2-1;
@@ -61284,12 +61810,12 @@
61284 break;
61285 }
61286
61287 /* Opcode: Compare P1 P2 P3 P4 *
61288 **
61289 ** Compare to vectors of registers in reg(P1)..reg(P1+P3-1) (all this
61290 ** one "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of
61291 ** the comparison for use by the next OP_Jump instruct.
61292 **
61293 ** P4 is a KeyInfo structure that defines collating sequences and sort
61294 ** orders for the comparison. The permutation applies to registers
61295 ** only. The KeyInfo elements are used sequentially.
@@ -61327,10 +61853,12 @@
61327 assert( u.aj.p2>0 && u.aj.p2+u.aj.n<=p->nMem+1 );
61328 }
61329 #endif /* SQLITE_DEBUG */
61330 for(u.aj.i=0; u.aj.i<u.aj.n; u.aj.i++){
61331 u.aj.idx = aPermute ? aPermute[u.aj.i] : u.aj.i;
 
 
61332 REGISTER_TRACE(u.aj.p1+u.aj.idx, &aMem[u.aj.p1+u.aj.idx]);
61333 REGISTER_TRACE(u.aj.p2+u.aj.idx, &aMem[u.aj.p2+u.aj.idx]);
61334 assert( u.aj.i<u.aj.pKeyInfo->nField );
61335 u.aj.pColl = u.aj.pKeyInfo->aColl[u.aj.i];
61336 u.aj.bRev = u.aj.pKeyInfo->aSortOrder[u.aj.i];
@@ -61558,10 +62086,11 @@
61558 u.am.pC = 0;
61559 memset(&u.am.sMem, 0, sizeof(u.am.sMem));
61560 assert( u.am.p1<p->nCursor );
61561 assert( pOp->p3>0 && pOp->p3<=p->nMem );
61562 u.am.pDest = &aMem[pOp->p3];
 
61563 MemSetTypeFlag(u.am.pDest, MEM_Null);
61564 u.am.zRec = 0;
61565
61566 /* This block sets the variable u.am.payloadSize to be the total number of
61567 ** bytes in the record.
@@ -61605,10 +62134,11 @@
61605 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
61606 }
61607 }else if( u.am.pC->pseudoTableReg>0 ){
61608 u.am.pReg = &aMem[u.am.pC->pseudoTableReg];
61609 assert( u.am.pReg->flags & MEM_Blob );
 
61610 u.am.payloadSize = u.am.pReg->n;
61611 u.am.zRec = u.am.pReg->z;
61612 u.am.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr;
61613 assert( u.am.payloadSize==0 || u.am.zRec!=0 );
61614 }else{
@@ -61829,25 +62359,23 @@
61829 assert( u.an.zAffinity!=0 );
61830 assert( u.an.zAffinity[pOp->p2]==0 );
61831 pIn1 = &aMem[pOp->p1];
61832 while( (u.an.cAff = *(u.an.zAffinity++))!=0 ){
61833 assert( pIn1 <= &p->aMem[p->nMem] );
 
61834 ExpandBlob(pIn1);
61835 applyAffinity(pIn1, u.an.cAff, encoding);
61836 pIn1++;
61837 }
61838 break;
61839 }
61840
61841 /* Opcode: MakeRecord P1 P2 P3 P4 *
61842 **
61843 ** Convert P2 registers beginning with P1 into a single entry
61844 ** suitable for use as a data record in a database table or as a key
61845 ** in an index. The details of the format are irrelevant as long as
61846 ** the OP_Column opcode can decode the record later.
61847 ** Refer to source code comments for the details of the record
61848 ** format.
61849 **
61850 ** P4 may be a string that is P2 characters long. The nth character of the
61851 ** string indicates the column affinity that should be used for the nth
61852 ** field of the index key.
61853 **
@@ -61899,15 +62427,21 @@
61899 assert( u.ao.nField>0 && pOp->p2>0 && pOp->p2+u.ao.nField<=p->nMem+1 );
61900 u.ao.pData0 = &aMem[u.ao.nField];
61901 u.ao.nField = pOp->p2;
61902 u.ao.pLast = &u.ao.pData0[u.ao.nField-1];
61903 u.ao.file_format = p->minWriteFileFormat;
 
 
 
 
 
61904
61905 /* Loop through the elements that will make up the record to figure
61906 ** out how much space is required for the new record.
61907 */
61908 for(u.ao.pRec=u.ao.pData0; u.ao.pRec<=u.ao.pLast; u.ao.pRec++){
 
61909 if( u.ao.zAffinity ){
61910 applyAffinity(u.ao.pRec, u.ao.zAffinity[u.ao.pRec-u.ao.pData0], encoding);
61911 }
61912 if( u.ao.pRec->flags&MEM_Zero && u.ao.pRec->n>0 ){
61913 sqlite3VdbeMemExpandBlob(u.ao.pRec);
@@ -61938,12 +62472,10 @@
61938 /* Make sure the output register has a buffer large enough to store
61939 ** the new record. The output register (pOp->p3) is not allowed to
61940 ** be one of the input registers (because the following call to
61941 ** sqlite3VdbeMemGrow() could clobber the value before it is used).
61942 */
61943 assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
61944 pOut = &aMem[pOp->p3];
61945 if( sqlite3VdbeMemGrow(pOut, (int)u.ao.nByte, 0) ){
61946 goto no_mem;
61947 }
61948 u.ao.zNewRecord = (u8 *)pOut->z;
61949
@@ -62112,10 +62644,11 @@
62112 }
62113 }
62114 if( u.aq.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
62115 sqlite3ExpirePreparedStatements(db);
62116 sqlite3ResetInternalSchema(db, 0);
 
62117 }
62118 }
62119
62120 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
62121 ** savepoints nested inside of the savepoint being operated on. */
@@ -62502,10 +63035,12 @@
62502 }
62503 if( pOp->p5 ){
62504 assert( u.aw.p2>0 );
62505 assert( u.aw.p2<=p->nMem );
62506 pIn2 = &aMem[u.aw.p2];
 
 
62507 sqlite3VdbeMemIntegerify(pIn2);
62508 u.aw.p2 = (int)pIn2->u.i;
62509 /* The u.aw.p2 value always comes from a prior OP_CreateTable opcode and
62510 ** that opcode will always set the u.aw.p2 value to 2 or more or else fail.
62511 ** If there were a failure, the prepared statement would have halted
@@ -62524,10 +63059,11 @@
62524 }
62525 assert( pOp->p1>=0 );
62526 u.aw.pCur = allocateCursor(p, pOp->p1, u.aw.nField, u.aw.iDb, 1);
62527 if( u.aw.pCur==0 ) goto no_mem;
62528 u.aw.pCur->nullRow = 1;
 
62529 rc = sqlite3BtreeCursor(u.aw.pX, u.aw.p2, u.aw.wrFlag, u.aw.pKeyInfo, u.aw.pCur->pCursor);
62530 u.aw.pCur->pKeyInfo = u.aw.pKeyInfo;
62531
62532 /* Since it performs no memory allocation or IO, the only values that
62533 ** sqlite3BtreeCursor() may return are SQLITE_EMPTY and SQLITE_OK.
@@ -62576,11 +63112,11 @@
62576 case OP_OpenAutoindex:
62577 case OP_OpenEphemeral: {
62578 #if 0 /* local variables moved into u.ax */
62579 VdbeCursor *pCx;
62580 #endif /* local variables moved into u.ax */
62581 static const int openFlags =
62582 SQLITE_OPEN_READWRITE |
62583 SQLITE_OPEN_CREATE |
62584 SQLITE_OPEN_EXCLUSIVE |
62585 SQLITE_OPEN_DELETEONCLOSE |
62586 SQLITE_OPEN_TRANSIENT_DB;
@@ -62587,25 +63123,25 @@
62587
62588 assert( pOp->p1>=0 );
62589 u.ax.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
62590 if( u.ax.pCx==0 ) goto no_mem;
62591 u.ax.pCx->nullRow = 1;
62592 rc = sqlite3BtreeFactory(db, 0, 1, SQLITE_DEFAULT_TEMP_CACHE_SIZE, openFlags,
62593 &u.ax.pCx->pBt);
62594 if( rc==SQLITE_OK ){
62595 rc = sqlite3BtreeBeginTrans(u.ax.pCx->pBt, 1);
62596 }
62597 if( rc==SQLITE_OK ){
62598 /* If a transient index is required, create it by calling
62599 ** sqlite3BtreeCreateTable() with the BTREE_ZERODATA flag before
62600 ** opening it. If a transient table is required, just use the
62601 ** automatically created table with root-page 1 (an INTKEY table).
62602 */
62603 if( pOp->p4.pKeyInfo ){
62604 int pgno;
62605 assert( pOp->p4type==P4_KEYINFO );
62606 rc = sqlite3BtreeCreateTable(u.ax.pCx->pBt, &pgno, BTREE_ZERODATA);
62607 if( rc==SQLITE_OK ){
62608 assert( pgno==MASTER_ROOT+1 );
62609 rc = sqlite3BtreeCursor(u.ax.pCx->pBt, pgno, 1,
62610 (KeyInfo*)pOp->p4.z, u.ax.pCx->pCursor);
62611 u.ax.pCx->pKeyInfo = pOp->p4.pKeyInfo;
@@ -62615,10 +63151,11 @@
62615 }else{
62616 rc = sqlite3BtreeCursor(u.ax.pCx->pBt, MASTER_ROOT, 1, 0, u.ax.pCx->pCursor);
62617 u.ax.pCx->isTable = 1;
62618 }
62619 }
 
62620 u.ax.pCx->isIndex = !u.ax.pCx->isTable;
62621 break;
62622 }
62623
62624 /* Opcode: OpenPseudo P1 P2 P3 * *
@@ -62734,10 +63271,11 @@
62734 assert( u.az.pC!=0 );
62735 assert( u.az.pC->pseudoTableReg==0 );
62736 assert( OP_SeekLe == OP_SeekLt+1 );
62737 assert( OP_SeekGe == OP_SeekLt+2 );
62738 assert( OP_SeekGt == OP_SeekLt+3 );
 
62739 if( u.az.pC->pCursor!=0 ){
62740 u.az.oc = pOp->opcode;
62741 u.az.pC->nullRow = 0;
62742 if( u.az.pC->isTable ){
62743 /* The input value in P3 might be of any type: integer, real, string,
@@ -62816,10 +63354,13 @@
62816 assert( u.az.oc!=OP_SeekLe || u.az.r.flags==UNPACKED_INCRKEY );
62817 assert( u.az.oc!=OP_SeekGe || u.az.r.flags==0 );
62818 assert( u.az.oc!=OP_SeekLt || u.az.r.flags==0 );
62819
62820 u.az.r.aMem = &aMem[pOp->p3];
 
 
 
62821 ExpandBlob(u.az.r.aMem);
62822 rc = sqlite3BtreeMovetoUnpacked(u.az.pC->pCursor, &u.az.r, 0, 0, &u.az.res);
62823 if( rc!=SQLITE_OK ){
62824 goto abort_due_to_error;
62825 }
@@ -62944,15 +63485,18 @@
62944 assert( u.bb.pC->isTable==0 );
62945 if( pOp->p4.i>0 ){
62946 u.bb.r.pKeyInfo = u.bb.pC->pKeyInfo;
62947 u.bb.r.nField = (u16)pOp->p4.i;
62948 u.bb.r.aMem = pIn3;
 
 
 
62949 u.bb.r.flags = UNPACKED_PREFIX_MATCH;
62950 u.bb.pIdxKey = &u.bb.r;
62951 }else{
62952 assert( pIn3->flags & MEM_Blob );
62953 ExpandBlob(pIn3);
62954 u.bb.pIdxKey = sqlite3VdbeRecordUnpack(u.bb.pC->pKeyInfo, pIn3->n, pIn3->z,
62955 u.bb.aTempRec, sizeof(u.bb.aTempRec));
62956 if( u.bb.pIdxKey==0 ){
62957 goto no_mem;
62958 }
@@ -63043,10 +63587,13 @@
63043 /* Populate the index search key. */
63044 u.bc.r.pKeyInfo = u.bc.pCx->pKeyInfo;
63045 u.bc.r.nField = u.bc.nField + 1;
63046 u.bc.r.flags = UNPACKED_PREFIX_SEARCH;
63047 u.bc.r.aMem = u.bc.aMx;
 
 
 
63048
63049 /* Extract the value of u.bc.R from register P3. */
63050 sqlite3VdbeMemIntegerify(pIn3);
63051 u.bc.R = pIn3->u.i;
63052
@@ -63065,11 +63612,11 @@
63065
63066 /* Opcode: NotExists P1 P2 P3 * *
63067 **
63068 ** Use the content of register P3 as a integer key. If a record
63069 ** with that key does not exist in table of P1, then jump to P2.
63070 ** If the record does exist, then fall thru. The cursor is left
63071 ** pointing to the record if it exists.
63072 **
63073 ** The difference between this operation and NotFound is that this
63074 ** operation assumes the key is an integer and that P1 is a table whereas
63075 ** NotFound assumes key is a blob constructed from MakeRecord and
@@ -63223,11 +63770,13 @@
63223 u.be.pMem = &u.be.pFrame->aMem[pOp->p3];
63224 }else{
63225 /* Assert that P3 is a valid memory cell. */
63226 assert( pOp->p3<=p->nMem );
63227 u.be.pMem = &aMem[pOp->p3];
 
63228 }
 
63229
63230 REGISTER_TRACE(pOp->p3, u.be.pMem);
63231 sqlite3VdbeMemIntegerify(u.be.pMem);
63232 assert( (u.be.pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
63233 if( u.be.pMem->u.i==MAX_ROWID || u.be.pC->useRandomRowid ){
@@ -63242,33 +63791,40 @@
63242 #endif
63243
63244 sqlite3BtreeSetCachedRowid(u.be.pC->pCursor, u.be.v<MAX_ROWID ? u.be.v+1 : 0);
63245 }
63246 if( u.be.pC->useRandomRowid ){
63247 /* IMPLEMENTATION-OF: R-48598-02938 If the largest ROWID is equal to the
63248 ** largest possible integer (9223372036854775807) then the database
63249 ** engine starts picking candidate ROWIDs at random until it finds one
63250 ** that is not previously used.
63251 */
63252 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
63253 ** an AUTOINCREMENT table. */
 
63254 u.be.v = db->lastRowid;
 
 
63255 u.be.cnt = 0;
63256 do{
63257 if( u.be.cnt==0 && (u.be.v&0xffffff)==u.be.v ){
63258 u.be.v++;
 
 
 
 
 
 
63259 }else{
63260 sqlite3_randomness(sizeof(u.be.v), &u.be.v);
63261 if( u.be.cnt<5 ) u.be.v &= 0xffffff;
63262 }
63263 rc = sqlite3BtreeMovetoUnpacked(u.be.pC->pCursor, 0, (u64)u.be.v, 0, &u.be.res);
63264 u.be.cnt++;
63265 }while( u.be.cnt<100 && rc==SQLITE_OK && u.be.res==0 );
63266 if( rc==SQLITE_OK && u.be.res==0 ){
63267 rc = SQLITE_FULL; /* IMP: R-38219-53002 */
63268 goto abort_due_to_error;
63269 }
 
63270 }
63271 u.be.pC->rowidIsValid = 0;
63272 u.be.pC->deferredMoveto = 0;
63273 u.be.pC->cacheStatus = CACHE_STALE;
63274 }
@@ -63334,10 +63890,11 @@
63334 int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
63335 #endif /* local variables moved into u.bf */
63336
63337 u.bf.pData = &aMem[pOp->p2];
63338 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
 
63339 u.bf.pC = p->apCsr[pOp->p1];
63340 assert( u.bf.pC!=0 );
63341 assert( u.bf.pC->pCursor!=0 );
63342 assert( u.bf.pC->pseudoTableReg==0 );
63343 assert( u.bf.pC->isTable );
@@ -63344,10 +63901,11 @@
63344 REGISTER_TRACE(pOp->p2, u.bf.pData);
63345
63346 if( pOp->opcode==OP_Insert ){
63347 u.bf.pKey = &aMem[pOp->p3];
63348 assert( u.bf.pKey->flags & MEM_Int );
 
63349 REGISTER_TRACE(pOp->p3, u.bf.pKey);
63350 u.bf.iKey = u.bf.pKey->u.i;
63351 }else{
63352 assert( pOp->opcode==OP_InsertInt );
63353 u.bf.iKey = pOp->p3;
@@ -63495,10 +64053,11 @@
63495 u32 n;
63496 i64 n64;
63497 #endif /* local variables moved into u.bh */
63498
63499 pOut = &aMem[pOp->p2];
 
63500
63501 /* Note that RowKey and RowData are really exactly the same instruction */
63502 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
63503 u.bh.pC = p->apCsr[pOp->p1];
63504 assert( u.bh.pC->isTable || pOp->opcode==OP_RowKey );
@@ -63837,10 +64396,13 @@
63837 if( ALWAYS(u.bo.pCrsr!=0) ){
63838 u.bo.r.pKeyInfo = u.bo.pC->pKeyInfo;
63839 u.bo.r.nField = (u16)pOp->p3;
63840 u.bo.r.flags = 0;
63841 u.bo.r.aMem = &aMem[pOp->p2];
 
 
 
63842 rc = sqlite3BtreeMovetoUnpacked(u.bo.pCrsr, &u.bo.r, 0, 0, &u.bo.res);
63843 if( rc==SQLITE_OK && u.bo.res==0 ){
63844 rc = sqlite3BtreeDelete(u.bo.pCrsr);
63845 }
63846 assert( u.bo.pC->deferredMoveto==0 );
@@ -63921,10 +64483,11 @@
63921 #endif /* local variables moved into u.bq */
63922
63923 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
63924 u.bq.pC = p->apCsr[pOp->p1];
63925 assert( u.bq.pC!=0 );
 
63926 if( ALWAYS(u.bq.pC->pCursor!=0) ){
63927 assert( u.bq.pC->deferredMoveto==0 );
63928 assert( pOp->p5==0 || pOp->p5==1 );
63929 assert( pOp->p4type==P4_INT32 );
63930 u.bq.r.pKeyInfo = u.bq.pC->pKeyInfo;
@@ -63933,10 +64496,13 @@
63933 u.bq.r.flags = UNPACKED_INCRKEY | UNPACKED_IGNORE_ROWID;
63934 }else{
63935 u.bq.r.flags = UNPACKED_IGNORE_ROWID;
63936 }
63937 u.bq.r.aMem = &aMem[pOp->p3];
 
 
 
63938 rc = sqlite3VdbeIdxKeyCompare(u.bq.pC, &u.bq.r, &u.bq.res);
63939 if( pOp->opcode==OP_IdxLT ){
63940 u.bq.res = -u.bq.res;
63941 }else{
63942 assert( pOp->opcode==OP_IdxGE );
@@ -64036,10 +64602,12 @@
64036 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bs.nChange : 0)
64037 );
64038 if( pOp->p3 ){
64039 p->nChange += u.bs.nChange;
64040 if( pOp->p3>0 ){
 
 
64041 aMem[pOp->p3].u.i += u.bs.nChange;
64042 }
64043 }
64044 break;
64045 }
@@ -64079,13 +64647,13 @@
64079 assert( (p->btreeMask & (1<<pOp->p1))!=0 );
64080 u.bt.pDb = &db->aDb[pOp->p1];
64081 assert( u.bt.pDb->pBt!=0 );
64082 if( pOp->opcode==OP_CreateTable ){
64083 /* u.bt.flags = BTREE_INTKEY; */
64084 u.bt.flags = BTREE_LEAFDATA|BTREE_INTKEY;
64085 }else{
64086 u.bt.flags = BTREE_ZERODATA;
64087 }
64088 rc = sqlite3BtreeCreateTable(u.bt.pDb->pBt, &u.bt.pgno, u.bt.flags);
64089 pOut->u.i = u.bt.pgno;
64090 break;
64091 }
@@ -64410,10 +64978,11 @@
64410 void *t; /* Token identifying trigger */
64411 #endif /* local variables moved into u.by */
64412
64413 u.by.pProgram = pOp->p4.pProgram;
64414 u.by.pRt = &aMem[pOp->p3];
 
64415 assert( u.by.pProgram->nOp>0 );
64416
64417 /* If the p5 flag is clear, then recursive invocation of triggers is
64418 ** disabled for backwards compatibility (p5 is set if this sub-program
64419 ** is really a trigger, not a foreign key action, and the flag set
@@ -64583,10 +65152,11 @@
64583 for(u.ca.pFrame=p->pFrame; u.ca.pFrame->pParent; u.ca.pFrame=u.ca.pFrame->pParent);
64584 u.ca.pIn1 = &u.ca.pFrame->aMem[pOp->p1];
64585 }else{
64586 u.ca.pIn1 = &aMem[pOp->p1];
64587 }
 
64588 sqlite3VdbeMemIntegerify(u.ca.pIn1);
64589 pIn2 = &aMem[pOp->p2];
64590 sqlite3VdbeMemIntegerify(pIn2);
64591 if( u.ca.pIn1->u.i<pIn2->u.i){
64592 u.ca.pIn1->u.i = pIn2->u.i;
@@ -64669,11 +65239,13 @@
64669 assert( u.cb.n>=0 );
64670 u.cb.pRec = &aMem[pOp->p2];
64671 u.cb.apVal = p->apArg;
64672 assert( u.cb.apVal || u.cb.n==0 );
64673 for(u.cb.i=0; u.cb.i<u.cb.n; u.cb.i++, u.cb.pRec++){
 
64674 u.cb.apVal[u.cb.i] = u.cb.pRec;
 
64675 sqlite3VdbeMemStoreType(u.cb.pRec);
64676 }
64677 u.cb.ctx.pFunc = pOp->p4.pFunc;
64678 assert( pOp->p3>0 && pOp->p3<=p->nMem );
64679 u.cb.ctx.pMem = u.cb.pMem = &aMem[pOp->p3];
@@ -64689,11 +65261,11 @@
64689 assert( pOp>p->aOp );
64690 assert( pOp[-1].p4type==P4_COLLSEQ );
64691 assert( pOp[-1].opcode==OP_CollSeq );
64692 u.cb.ctx.pColl = pOp[-1].p4.pColl;
64693 }
64694 (u.cb.ctx.pFunc->xStep)(&u.cb.ctx, u.cb.n, u.cb.apVal);
64695 if( u.cb.ctx.isError ){
64696 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cb.ctx.s));
64697 rc = u.cb.ctx.isError;
64698 }
64699 sqlite3VdbeMemRelease(&u.cb.ctx.s);
@@ -65076,10 +65648,11 @@
65076 #endif /* local variables moved into u.ch */
65077
65078 u.ch.pQuery = &aMem[pOp->p3];
65079 u.ch.pArgc = &u.ch.pQuery[1];
65080 u.ch.pCur = p->apCsr[pOp->p1];
 
65081 REGISTER_TRACE(pOp->p3, u.ch.pQuery);
65082 assert( u.ch.pCur->pVtabCursor );
65083 u.ch.pVtabCursor = u.ch.pCur->pVtabCursor;
65084 u.ch.pVtab = u.ch.pVtabCursor->pVtab;
65085 u.ch.pModule = u.ch.pVtab->pModule;
@@ -65133,10 +65706,11 @@
65133
65134 VdbeCursor *pCur = p->apCsr[pOp->p1];
65135 assert( pCur->pVtabCursor );
65136 assert( pOp->p3>0 && pOp->p3<=p->nMem );
65137 u.ci.pDest = &aMem[pOp->p3];
 
65138 if( pCur->nullRow ){
65139 sqlite3VdbeMemSetNull(u.ci.pDest);
65140 break;
65141 }
65142 u.ci.pVtab = pCur->pVtabCursor->pVtab;
@@ -65235,14 +65809,16 @@
65235 #endif /* local variables moved into u.ck */
65236
65237 u.ck.pVtab = pOp->p4.pVtab->pVtab;
65238 u.ck.pName = &aMem[pOp->p1];
65239 assert( u.ck.pVtab->pModule->xRename );
 
65240 REGISTER_TRACE(pOp->p1, u.ck.pName);
65241 assert( u.ck.pName->flags & MEM_Str );
65242 rc = u.ck.pVtab->pModule->xRename(u.ck.pVtab, u.ck.pName->z);
65243 importVtabErrMsg(p, u.ck.pVtab);
 
65244
65245 break;
65246 }
65247 #endif
65248
@@ -65287,10 +65863,12 @@
65287 assert( pOp->p4type==P4_VTAB );
65288 if( ALWAYS(u.cl.pModule->xUpdate) ){
65289 u.cl.apArg = p->apArg;
65290 u.cl.pX = &aMem[pOp->p3];
65291 for(u.cl.i=0; u.cl.i<u.cl.nArg; u.cl.i++){
 
 
65292 sqlite3VdbeMemStoreType(u.cl.pX);
65293 u.cl.apArg[u.cl.i] = u.cl.pX;
65294 u.cl.pX++;
65295 }
65296 rc = u.cl.pModule->xUpdate(u.cl.pVtab, u.cl.nArg, u.cl.apArg, &u.cl.rowid);
@@ -66341,12 +66919,11 @@
66341 SQLITE_PRIVATE int sqlite3IsMemJournal(sqlite3_file *pJfd){
66342 return pJfd->pMethods==&MemJournalMethods;
66343 }
66344
66345 /*
66346 ** Return the number of bytes required to store a MemJournal that uses vfs
66347 ** pVfs to create the underlying on-disk files.
66348 */
66349 SQLITE_PRIVATE int sqlite3MemJournalSize(void){
66350 return sizeof(MemJournal);
66351 }
66352
@@ -68246,11 +68823,11 @@
68246 pExpr->iColumn = (ynVar)(++pParse->nVar);
68247 }else if( z[0]=='?' ){
68248 /* Wildcard of the form "?nnn". Convert "nnn" to an integer and
68249 ** use it as the variable number */
68250 i64 i;
68251 int bOk = sqlite3Atoi64(&z[1], &i);
68252 pExpr->iColumn = (ynVar)i;
68253 testcase( i==0 );
68254 testcase( i==1 );
68255 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
68256 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
@@ -69226,12 +69803,12 @@
69226 return eType;
69227 }
69228 #endif
69229
69230 /*
69231 ** Generate code for scalar subqueries used as an expression
69232 ** and IN operators. Examples:
69233 **
69234 ** (SELECT a FROM b) -- subquery
69235 ** EXISTS (SELECT a FROM b) -- EXISTS subquery
69236 ** x IN (4,5,11) -- IN operator with list on right-hand side
69237 ** x IN (SELECT a FROM b) -- IN operator with subquery on the right
@@ -69290,14 +69867,14 @@
69290 assert( testAddr>0 || pParse->db->mallocFailed );
69291 }
69292
69293 switch( pExpr->op ){
69294 case TK_IN: {
69295 char affinity;
69296 KeyInfo keyInfo;
69297 int addr; /* Address of OP_OpenEphemeral instruction */
69298 Expr *pLeft = pExpr->pLeft;
69299
69300 if( rMayHaveNull ){
69301 sqlite3VdbeAddOp2(v, OP_Null, 0, rMayHaveNull);
69302 }
69303
@@ -69316,10 +69893,11 @@
69316 ** 'x' nor the SELECT... statement are columns, then numeric affinity
69317 ** is used.
69318 */
69319 pExpr->iTable = pParse->nTab++;
69320 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
 
69321 memset(&keyInfo, 0, sizeof(keyInfo));
69322 keyInfo.nField = 1;
69323
69324 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
69325 /* Case 1: expr IN (SELECT ...)
@@ -69608,11 +70186,11 @@
69608 */
69609 static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){
69610 if( ALWAYS(z!=0) ){
69611 double value;
69612 char *zV;
69613 sqlite3AtoF(z, &value);
69614 assert( !sqlite3IsNaN(value) ); /* The new AtoF never returns NaN */
69615 if( negateFlag ) value = -value;
69616 zV = dup8bytes(v, (char*)&value);
69617 sqlite3VdbeAddOp4(v, OP_Real, 0, iMem, 0, zV, P4_REAL);
69618 }
@@ -69622,28 +70200,27 @@
69622
69623 /*
69624 ** Generate an instruction that will put the integer describe by
69625 ** text z[0..n-1] into register iMem.
69626 **
69627 ** The z[] string will probably not be zero-terminated. But the
69628 ** z[n] character is guaranteed to be something that does not look
69629 ** like the continuation of the number.
69630 */
69631 static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){
69632 Vdbe *v = pParse->pVdbe;
69633 if( pExpr->flags & EP_IntValue ){
69634 int i = pExpr->u.iValue;
69635 if( negFlag ) i = -i;
69636 sqlite3VdbeAddOp2(v, OP_Integer, i, iMem);
69637 }else{
 
 
69638 const char *z = pExpr->u.zToken;
69639 assert( z!=0 );
69640 if( sqlite3FitsIn64Bits(z, negFlag) ){
69641 i64 value;
69642 char *zV;
69643 sqlite3Atoi64(z, &value);
69644 if( negFlag ) value = -value;
69645 zV = dup8bytes(v, (char*)&value);
69646 sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64);
69647 }else{
69648 #ifdef SQLITE_OMIT_FLOATING_POINT
69649 sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
@@ -69924,77 +70501,10 @@
69924 }
69925 return 0;
69926 }
69927 #endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
69928
69929 /*
69930 ** If the last instruction coded is an ephemeral copy of any of
69931 ** the registers in the nReg registers beginning with iReg, then
69932 ** convert the last instruction from OP_SCopy to OP_Copy.
69933 */
69934 SQLITE_PRIVATE void sqlite3ExprHardCopy(Parse *pParse, int iReg, int nReg){
69935 VdbeOp *pOp;
69936 Vdbe *v;
69937
69938 assert( pParse->db->mallocFailed==0 );
69939 v = pParse->pVdbe;
69940 assert( v!=0 );
69941 pOp = sqlite3VdbeGetOp(v, -1);
69942 assert( pOp!=0 );
69943 if( pOp->opcode==OP_SCopy && pOp->p1>=iReg && pOp->p1<iReg+nReg ){
69944 pOp->opcode = OP_Copy;
69945 }
69946 }
69947
69948 /*
69949 ** Generate code to store the value of the iAlias-th alias in register
69950 ** target. The first time this is called, pExpr is evaluated to compute
69951 ** the value of the alias. The value is stored in an auxiliary register
69952 ** and the number of that register is returned. On subsequent calls,
69953 ** the register number is returned without generating any code.
69954 **
69955 ** Note that in order for this to work, code must be generated in the
69956 ** same order that it is executed.
69957 **
69958 ** Aliases are numbered starting with 1. So iAlias is in the range
69959 ** of 1 to pParse->nAlias inclusive.
69960 **
69961 ** pParse->aAlias[iAlias-1] records the register number where the value
69962 ** of the iAlias-th alias is stored. If zero, that means that the
69963 ** alias has not yet been computed.
69964 */
69965 static int codeAlias(Parse *pParse, int iAlias, Expr *pExpr, int target){
69966 #if 0
69967 sqlite3 *db = pParse->db;
69968 int iReg;
69969 if( pParse->nAliasAlloc<pParse->nAlias ){
69970 pParse->aAlias = sqlite3DbReallocOrFree(db, pParse->aAlias,
69971 sizeof(pParse->aAlias[0])*pParse->nAlias );
69972 testcase( db->mallocFailed && pParse->nAliasAlloc>0 );
69973 if( db->mallocFailed ) return 0;
69974 memset(&pParse->aAlias[pParse->nAliasAlloc], 0,
69975 (pParse->nAlias-pParse->nAliasAlloc)*sizeof(pParse->aAlias[0]));
69976 pParse->nAliasAlloc = pParse->nAlias;
69977 }
69978 assert( iAlias>0 && iAlias<=pParse->nAlias );
69979 iReg = pParse->aAlias[iAlias-1];
69980 if( iReg==0 ){
69981 if( pParse->iCacheLevel>0 ){
69982 iReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
69983 }else{
69984 iReg = ++pParse->nMem;
69985 sqlite3ExprCode(pParse, pExpr, iReg);
69986 pParse->aAlias[iAlias-1] = iReg;
69987 }
69988 }
69989 return iReg;
69990 #else
69991 UNUSED_PARAMETER(iAlias);
69992 return sqlite3ExprCodeTarget(pParse, pExpr, target);
69993 #endif
69994 }
69995
69996 /*
69997 ** Generate code into the current Vdbe to evaluate the given
69998 ** expression. Attempt to store the results in register "target".
69999 ** Return the register where results are stored.
70000 **
@@ -70099,11 +70609,11 @@
70099 case TK_REGISTER: {
70100 inReg = pExpr->iTable;
70101 break;
70102 }
70103 case TK_AS: {
70104 inReg = codeAlias(pParse, pExpr->iTable, pExpr->pLeft, target);
70105 break;
70106 }
70107 #ifndef SQLITE_OMIT_CAST
70108 case TK_CAST: {
70109 /* Expressions of the form: CAST(pLeft AS token) */
@@ -70531,10 +71041,15 @@
70531 testcase( regFree1==0 );
70532 cacheX.op = TK_REGISTER;
70533 opCompare.op = TK_EQ;
70534 opCompare.pLeft = &cacheX;
70535 pTest = &opCompare;
 
 
 
 
 
70536 }
70537 for(i=0; i<nExpr; i=i+2){
70538 sqlite3ExprCachePush(pParse);
70539 if( pX ){
70540 assert( pTest!=0 );
@@ -70624,14 +71139,18 @@
70624 */
70625 SQLITE_PRIVATE int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
70626 int inReg;
70627
70628 assert( target>0 && target<=pParse->nMem );
70629 inReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
70630 assert( pParse->pVdbe || pParse->db->mallocFailed );
70631 if( inReg!=target && pParse->pVdbe ){
70632 sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target);
 
 
 
 
70633 }
70634 return target;
70635 }
70636
70637 /*
@@ -70800,23 +71319,18 @@
70800 ){
70801 struct ExprList_item *pItem;
70802 int i, n;
70803 assert( pList!=0 );
70804 assert( target>0 );
 
70805 n = pList->nExpr;
70806 for(pItem=pList->a, i=0; i<n; i++, pItem++){
70807 if( pItem->iAlias ){
70808 int iReg = codeAlias(pParse, pItem->iAlias, pItem->pExpr, target+i);
70809 Vdbe *v = sqlite3GetVdbe(pParse);
70810 if( iReg!=target+i ){
70811 sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target+i);
70812 }
70813 }else{
70814 sqlite3ExprCode(pParse, pItem->pExpr, target+i);
70815 }
70816 if( doHardCopy && !pParse->db->mallocFailed ){
70817 sqlite3ExprHardCopy(pParse, target, n);
70818 }
70819 }
70820 return n;
70821 }
70822
@@ -71794,10 +72308,15 @@
71794 if( pTrig->pSchema==pTempSchema ){
71795 zWhere = whereOrName(db, zWhere, pTrig->zName);
71796 }
71797 }
71798 }
 
 
 
 
 
71799 return zWhere;
71800 }
71801
71802 /*
71803 ** Generate code to drop and reload the internal representation of table
@@ -72401,11 +72920,12 @@
72401 int iIdxCur; /* Cursor open on index being analyzed */
72402 Vdbe *v; /* The virtual machine being built up */
72403 int i; /* Loop counter */
72404 int topOfLoop; /* The top of the loop */
72405 int endOfLoop; /* The end of the loop */
72406 int addr; /* The address of an instruction */
 
72407 int iDb; /* Index of database containing pTab */
72408 int regTabname = iMem++; /* Register containing table name */
72409 int regIdxname = iMem++; /* Register containing index name */
72410 int regSampleno = iMem++; /* Register containing next sample number */
72411 int regCol = iMem++; /* Content of a column analyzed table */
@@ -72420,12 +72940,19 @@
72420 int regLast = iMem++; /* Index of last sample to record */
72421 int regFirst = iMem++; /* Index of first sample to record */
72422 #endif
72423
72424 v = sqlite3GetVdbe(pParse);
72425 if( v==0 || NEVER(pTab==0) || pTab->pIndex==0 ){
72426 /* Do no analysis for tables that have no indices */
 
 
 
 
 
 
 
72427 return;
72428 }
72429 assert( sqlite3BtreeHoldsAllMutexes(db) );
72430 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
72431 assert( iDb>=0 );
@@ -72438,10 +72965,11 @@
72438
72439 /* Establish a read-lock on the table at the shared-cache level. */
72440 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
72441
72442 iIdxCur = pParse->nTab++;
 
72443 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
72444 int nCol = pIdx->nColumn;
72445 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
72446
72447 if( iMem+1+(nCol*2)>pParse->nMem ){
@@ -72452,14 +72980,11 @@
72452 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
72453 sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb,
72454 (char *)pKey, P4_KEYINFO_HANDOFF);
72455 VdbeComment((v, "%s", pIdx->zName));
72456
72457 /* Populate the registers containing the table and index names. */
72458 if( pTab->pIndex==pIdx ){
72459 sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
72460 }
72461 sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, pIdx->zName, 0);
72462
72463 #ifdef SQLITE_ENABLE_STAT2
72464
72465 /* If this iteration of the loop is generating code to analyze the
@@ -72590,12 +73115,14 @@
72590 **
72591 ** If K==0 then no entry is made into the sqlite_stat1 table.
72592 ** If K>0 then it is always the case the D>0 so division by zero
72593 ** is never possible.
72594 */
72595 addr = sqlite3VdbeAddOp1(v, OP_IfNot, iMem);
72596 sqlite3VdbeAddOp2(v, OP_SCopy, iMem, regSampleno);
 
 
 
72597 for(i=0; i<nCol; i++){
72598 sqlite3VdbeAddOp4(v, OP_String8, 0, regTemp, 0, " ", 0);
72599 sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regSampleno, regSampleno);
72600 sqlite3VdbeAddOp3(v, OP_Add, iMem, iMem+i+1, regTemp);
72601 sqlite3VdbeAddOp2(v, OP_AddImm, regTemp, -1);
@@ -72605,17 +73132,39 @@
72605 }
72606 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0);
72607 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regRowid);
72608 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regRowid);
72609 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72610 sqlite3VdbeJumpHere(v, addr);
72611 }
72612 }
72613
72614 /*
72615 ** Generate code that will cause the most recent index analysis to
72616 ** be laoded into internal hash tables where is can be used.
72617 */
72618 static void loadAnalysis(Parse *pParse, int iDb){
72619 Vdbe *v = sqlite3GetVdbe(pParse);
72620 if( v ){
72621 sqlite3VdbeAddOp1(v, OP_LoadAnalysis, iDb);
@@ -72741,37 +73290,50 @@
72741
72742 /*
72743 ** This callback is invoked once for each index when reading the
72744 ** sqlite_stat1 table.
72745 **
72746 ** argv[0] = name of the index
72747 ** argv[1] = results of analysis - on integer for each column
 
 
 
 
72748 */
72749 static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){
72750 analysisInfo *pInfo = (analysisInfo*)pData;
72751 Index *pIndex;
72752 int i, c;
 
72753 unsigned int v;
72754 const char *z;
72755
72756 assert( argc==2 );
72757 UNUSED_PARAMETER2(NotUsed, argc);
72758
72759 if( argv==0 || argv[0]==0 || argv[1]==0 ){
72760 return 0;
72761 }
72762 pIndex = sqlite3FindIndex(pInfo->db, argv[0], pInfo->zDatabase);
72763 if( pIndex==0 ){
72764 return 0;
72765 }
72766 z = argv[1];
72767 for(i=0; *z && i<=pIndex->nColumn; i++){
 
 
 
 
 
 
72768 v = 0;
72769 while( (c=z[0])>='0' && c<='9' ){
72770 v = v*10 + c - '0';
72771 z++;
72772 }
 
 
72773 pIndex->aiRowEst[i] = v;
72774 if( *z==' ' ) z++;
72775 }
72776 return 0;
72777 }
@@ -72843,11 +73405,11 @@
72843 return SQLITE_ERROR;
72844 }
72845
72846 /* Load new statistics out of the sqlite_stat1 table */
72847 zSql = sqlite3MPrintf(db,
72848 "SELECT idx, stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
72849 if( zSql==0 ){
72850 rc = SQLITE_NOMEM;
72851 }else{
72852 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
72853 sqlite3DbFree(db, zSql);
@@ -73060,13 +73622,12 @@
73060
73061 /* Open the database file. If the btree is successfully opened, use
73062 ** it to obtain the database schema. At this point the schema may
73063 ** or may not be initialised.
73064 */
73065 rc = sqlite3BtreeFactory(db, zFile, 0, SQLITE_DEFAULT_CACHE_SIZE,
73066 db->openFlags | SQLITE_OPEN_MAIN_DB,
73067 &aNew->pBt);
73068 db->nDb++;
73069 if( rc==SQLITE_CONSTRAINT ){
73070 rc = SQLITE_ERROR;
73071 zErrDyn = sqlite3MPrintf(db, "database is already attached");
73072 }else if( rc==SQLITE_OK ){
@@ -73303,11 +73864,12 @@
73303 0, /* pNext */
73304 detachFunc, /* xFunc */
73305 0, /* xStep */
73306 0, /* xFinalize */
73307 "sqlite_detach", /* zName */
73308 0 /* pHash */
 
73309 };
73310 codeAttach(pParse, SQLITE_DETACH, &detach_func, pDbname, 0, 0, pDbname);
73311 }
73312
73313 /*
@@ -73324,11 +73886,12 @@
73324 0, /* pNext */
73325 attachFunc, /* xFunc */
73326 0, /* xStep */
73327 0, /* xFinalize */
73328 "sqlite_attach", /* zName */
73329 0 /* pHash */
 
73330 };
73331 codeAttach(pParse, SQLITE_ATTACH, &attach_func, p, p, pDbname, pKey);
73332 }
73333 #endif /* SQLITE_OMIT_ATTACH */
73334
@@ -74453,12 +75016,13 @@
74453 ** set to the index of the database that the table or view is to be
74454 ** created in.
74455 */
74456 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
74457 if( iDb<0 ) return;
74458 if( !OMIT_TEMPDB && isTemp && iDb>1 ){
74459 /* If creating a temp table, the name may not be qualified */
 
74460 sqlite3ErrorMsg(pParse, "temporary table name must be unqualified");
74461 return;
74462 }
74463 if( !OMIT_TEMPDB && isTemp ) iDb = 1;
74464
@@ -74502,21 +75066,22 @@
74502 ** to an sqlite3_declare_vtab() call. In that case only the column names
74503 ** and types will be used, so there is no need to test for namespace
74504 ** collisions.
74505 */
74506 if( !IN_DECLARE_VTAB ){
 
74507 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
74508 goto begin_table_error;
74509 }
74510 pTable = sqlite3FindTable(db, zName, db->aDb[iDb].zName);
74511 if( pTable ){
74512 if( !noErr ){
74513 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
74514 }
74515 goto begin_table_error;
74516 }
74517 if( sqlite3FindIndex(db, zName, 0)!=0 && (iDb==0 || !db->init.busy) ){
74518 sqlite3ErrorMsg(pParse, "there is already an index named %s", zName);
74519 goto begin_table_error;
74520 }
74521 }
74522
@@ -74529,10 +75094,11 @@
74529 }
74530 pTable->zName = zName;
74531 pTable->iPKey = -1;
74532 pTable->pSchema = db->aDb[iDb].pSchema;
74533 pTable->nRef = 1;
 
74534 assert( pParse->pNewTable==0 );
74535 pParse->pNewTable = pTable;
74536
74537 /* If this is the magic sqlite_sequence table used by autoincrement,
74538 ** then record a pointer to this table in the main database structure
@@ -75375,16 +75941,14 @@
75375 sqlite3SelectDelete(db, pSelect);
75376 return;
75377 }
75378 sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
75379 p = pParse->pNewTable;
75380 if( p==0 ){
75381 sqlite3SelectDelete(db, pSelect);
75382 return;
75383 }
75384 assert( pParse->nErr==0 ); /* If sqlite3StartTable return non-NULL then
75385 ** there could not have been an error */
75386 sqlite3TwoPartName(pParse, pName1, pName2, &pName);
75387 iDb = sqlite3SchemaToIndex(db, p->pSchema);
75388 if( sqlite3FixInit(&sFix, pParse, iDb, "view", pName)
75389 && sqlite3FixSelect(&sFix, pSelect)
75390 ){
@@ -76498,11 +77062,12 @@
76498 */
76499 if( pTblName ){
76500 sqlite3RefillIndex(pParse, pIndex, iMem);
76501 sqlite3ChangeCookie(pParse, iDb);
76502 sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 0, 0,
76503 sqlite3MPrintf(db, "name='%q'", pIndex->zName), P4_DYNAMIC);
 
76504 sqlite3VdbeAddOp1(v, OP_Expire, 0);
76505 }
76506 }
76507
76508 /* When adding an index to the list of indices for a table, make
@@ -76559,18 +77124,18 @@
76559 ** are based on typical values found in actual indices.
76560 */
76561 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index *pIdx){
76562 unsigned *a = pIdx->aiRowEst;
76563 int i;
 
76564 assert( a!=0 );
76565 a[0] = 1000000;
76566 for(i=pIdx->nColumn; i>=5; i--){
76567 a[i] = 5;
76568 }
76569 while( i>=1 ){
76570 a[i] = 11 - i;
76571 i--;
76572 }
76573 if( pIdx->onError!=OE_None ){
76574 a[pIdx->nColumn] = 1;
76575 }
76576 }
@@ -76626,11 +77191,11 @@
76626 /* Generate code to remove the index and from the master table */
76627 v = sqlite3GetVdbe(pParse);
76628 if( v ){
76629 sqlite3BeginWriteOperation(pParse, 1, iDb);
76630 sqlite3NestedParse(pParse,
76631 "DELETE FROM %Q.%s WHERE name=%Q",
76632 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
76633 pIndex->zName
76634 );
76635 if( sqlite3FindTable(db, "sqlite_stat1", db->aDb[iDb].zName) ){
76636 sqlite3NestedParse(pParse,
@@ -77118,11 +77683,11 @@
77118 SQLITE_OPEN_CREATE |
77119 SQLITE_OPEN_EXCLUSIVE |
77120 SQLITE_OPEN_DELETEONCLOSE |
77121 SQLITE_OPEN_TEMP_DB;
77122
77123 rc = sqlite3BtreeFactory(db, 0, 0, SQLITE_DEFAULT_CACHE_SIZE, flags, &pBt);
77124 if( rc!=SQLITE_OK ){
77125 sqlite3ErrorMsg(pParse, "unable to open a temporary database "
77126 "file for storing temporary tables");
77127 pParse->rc = rc;
77128 return 1;
@@ -77775,11 +78340,11 @@
77775 ** If the SQLITE_PreferBuiltin flag is set, then search the built-in
77776 ** functions even if a prior app-defined function was found. And give
77777 ** priority to built-in functions.
77778 **
77779 ** Except, if createFlag is true, that means that we are trying to
77780 ** install a new function. Whatever FuncDef structure is returned will
77781 ** have fields overwritten with new information appropriate for the
77782 ** new function. But the FuncDefs for built-in functions are read-only.
77783 ** So we must not search for built-ins when creating a new function.
77784 */
77785 if( !createFlag && (pBest==0 || (db->flags & SQLITE_PreferBuiltin)!=0) ){
@@ -78791,11 +79356,11 @@
78791 zBuf = sqlite3_mprintf("%.*f",n,r);
78792 if( zBuf==0 ){
78793 sqlite3_result_error_nomem(context);
78794 return;
78795 }
78796 sqlite3AtoF(zBuf, &r);
78797 sqlite3_free(zBuf);
78798 }
78799 sqlite3_result_double(context, r);
78800 }
78801 #endif
@@ -79956,14 +80521,14 @@
79956 if( caseSensitive ){
79957 pInfo = (struct compareInfo*)&likeInfoAlt;
79958 }else{
79959 pInfo = (struct compareInfo*)&likeInfoNorm;
79960 }
79961 sqlite3CreateFunc(db, "like", 2, SQLITE_ANY, pInfo, likeFunc, 0, 0);
79962 sqlite3CreateFunc(db, "like", 3, SQLITE_ANY, pInfo, likeFunc, 0, 0);
79963 sqlite3CreateFunc(db, "glob", 2, SQLITE_ANY,
79964 (struct compareInfo*)&globInfo, likeFunc, 0,0);
79965 setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
79966 setLikeOptFlag(db, "like",
79967 caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
79968 }
79969
@@ -80043,14 +80608,14 @@
80043 FUNCTION(upper, 1, 0, 0, upperFunc ),
80044 FUNCTION(lower, 1, 0, 0, lowerFunc ),
80045 FUNCTION(coalesce, 1, 0, 0, 0 ),
80046 FUNCTION(coalesce, 0, 0, 0, 0 ),
80047 /* FUNCTION(coalesce, -1, 0, 0, ifnullFunc ), */
80048 {-1,SQLITE_UTF8,SQLITE_FUNC_COALESCE,0,0,ifnullFunc,0,0,"coalesce",0},
80049 FUNCTION(hex, 1, 0, 0, hexFunc ),
80050 /* FUNCTION(ifnull, 2, 0, 0, ifnullFunc ), */
80051 {2,SQLITE_UTF8,SQLITE_FUNC_COALESCE,0,0,ifnullFunc,0,0,"ifnull",0},
80052 FUNCTION(random, 0, 0, 0, randomFunc ),
80053 FUNCTION(randomblob, 1, 0, 0, randomBlob ),
80054 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
80055 FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
80056 FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
@@ -80073,11 +80638,11 @@
80073 #endif
80074 AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ),
80075 AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ),
80076 AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ),
80077 /* AGGREGATE(count, 0, 0, 0, countStep, countFinalize ), */
80078 {0,SQLITE_UTF8,SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0},
80079 AGGREGATE(count, 1, 0, 0, countStep, countFinalize ),
80080 AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, groupConcatFinalize),
80081 AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, groupConcatFinalize),
80082
80083 LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
@@ -80484,11 +81049,11 @@
80484 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
80485
80486 sqlite3VdbeAddOp3(v, OP_OpenRead, iCur, pIdx->tnum, iDb);
80487 sqlite3VdbeChangeP4(v, -1, (char*)pKey, P4_KEYINFO_HANDOFF);
80488 for(i=0; i<nCol; i++){
80489 sqlite3VdbeAddOp2(v, OP_SCopy, aiCol[i]+1+regData, regTemp+i);
80490 }
80491
80492 /* If the parent table is the same as the child table, and we are about
80493 ** to increment the constraint-counter (i.e. this is an INSERT operation),
80494 ** then check if the row being inserted matches itself. If so, do not
@@ -84849,11 +85414,11 @@
84849 */
84850 if( sqlite3StrICmp(zLeft,"journal_size_limit")==0 ){
84851 Pager *pPager = sqlite3BtreePager(pDb->pBt);
84852 i64 iLimit = -2;
84853 if( zRight ){
84854 sqlite3Atoi64(zRight, &iLimit);
84855 if( iLimit<-1 ) iLimit = -1;
84856 }
84857 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
84858 returnSingleInt(pParse, "journal_size_limit", iLimit);
84859 }else
@@ -87131,15 +87696,17 @@
87131 sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
87132 sqlite3VdbeAddOp2(v, OP_IdxInsert, iTab, r1);
87133 sqlite3ReleaseTempReg(pParse, r1);
87134 }
87135
 
87136 /*
87137 ** Generate an error message when a SELECT is used within a subexpression
87138 ** (example: "a IN (SELECT * FROM table)") but it has more than 1 result
87139 ** column. We do this in a subroutine because the error occurs in multiple
87140 ** places.
 
87141 */
87142 static int checkForMultiColumnSelectError(
87143 Parse *pParse, /* Parse context. */
87144 SelectDest *pDest, /* Destination of SELECT results */
87145 int nExpr /* Number of result columns returned by SELECT */
@@ -87151,10 +87718,11 @@
87151 return 1;
87152 }else{
87153 return 0;
87154 }
87155 }
 
87156
87157 /*
87158 ** This routine generates the code for the inside of the inner loop
87159 ** of a SELECT.
87160 **
@@ -87230,14 +87798,10 @@
87230 if( pOrderBy==0 ){
87231 codeOffset(v, p, iContinue);
87232 }
87233 }
87234
87235 if( checkForMultiColumnSelectError(pParse, pDest, pEList->nExpr) ){
87236 return;
87237 }
87238
87239 switch( eDest ){
87240 /* In this mode, write each query result to the key of the temporary
87241 ** table iParm.
87242 */
87243 #ifndef SQLITE_OMIT_COMPOUND_SELECT
@@ -88143,10 +88707,11 @@
88143 /* Create the destination temporary table if necessary
88144 */
88145 if( dest.eDest==SRT_EphemTab ){
88146 assert( p->pEList );
88147 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, dest.iParm, p->pEList->nExpr);
 
88148 dest.eDest = SRT_Table;
88149 }
88150
88151 /* Make sure all SELECTs in the statement have the same number of elements
88152 ** in their result sets.
@@ -90105,11 +90670,11 @@
90105 ExprList *pList = pF->pExpr->x.pList;
90106 assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
90107 if( pList ){
90108 nArg = pList->nExpr;
90109 regAgg = sqlite3GetTempRange(pParse, nArg);
90110 sqlite3ExprCodeExprList(pParse, pList, regAgg, 0);
90111 }else{
90112 nArg = 0;
90113 regAgg = 0;
90114 }
90115 if( pF->iDistinct>=0 ){
@@ -90264,10 +90829,19 @@
90264
90265 /* Begin generating code.
90266 */
90267 v = sqlite3GetVdbe(pParse);
90268 if( v==0 ) goto select_end;
 
 
 
 
 
 
 
 
 
90269
90270 /* Generate code for all sub-queries in the FROM clause
90271 */
90272 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
90273 for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
@@ -90338,19 +90912,10 @@
90338 }
90339 return multiSelect(pParse, p, pDest);
90340 }
90341 #endif
90342
90343 /* If writing to memory or generating a set
90344 ** only a single column may be output.
90345 */
90346 #ifndef SQLITE_OMIT_SUBQUERY
90347 if( checkForMultiColumnSelectError(pParse, pDest, pEList->nExpr) ){
90348 goto select_end;
90349 }
90350 #endif
90351
90352 /* If possible, rewrite the query to use GROUP BY instead of DISTINCT.
90353 ** GROUP BY might use an index, DISTINCT never does.
90354 */
90355 assert( p->pGroupBy==0 || (p->selFlags & SF_Aggregate)!=0 );
90356 if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct ){
@@ -90409,10 +90974,11 @@
90409 assert( isAgg || pGroupBy );
90410 distinct = pParse->nTab++;
90411 pKeyInfo = keyInfoFromExprList(pParse, p->pEList);
90412 sqlite3VdbeAddOp4(v, OP_OpenEphemeral, distinct, 0, 0,
90413 (char*)pKeyInfo, P4_KEYINFO_HANDOFF);
 
90414 }else{
90415 distinct = -1;
90416 }
90417
90418 /* Aggregate and non-aggregate queries are handled differently */
@@ -92884,10 +93450,11 @@
92884 ** be stored.
92885 */
92886 assert( v );
92887 ephemTab = pParse->nTab++;
92888 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, ephemTab, pTab->nCol+1+(pRowid!=0));
 
92889
92890 /* fill the ephemeral table
92891 */
92892 sqlite3SelectDestInit(&dest, SRT_Table, ephemTab);
92893 sqlite3Select(pParse, pSelect, &dest);
@@ -93022,10 +93589,14 @@
93022 int nDb; /* Number of attached databases */
93023
93024 if( !db->autoCommit ){
93025 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
93026 return SQLITE_ERROR;
 
 
 
 
93027 }
93028
93029 /* Save the current value of the database flags so that it can be
93030 ** restored before returning. Then set the writable-schema flag, and
93031 ** disable CHECK and foreign key constraints. */
@@ -93624,11 +94195,11 @@
93624 sqlite3DbFree(db, zStmt);
93625 v = sqlite3GetVdbe(pParse);
93626 sqlite3ChangeCookie(pParse, iDb);
93627
93628 sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
93629 zWhere = sqlite3MPrintf(db, "name='%q'", pTab->zName);
93630 sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 1, 0, zWhere, P4_DYNAMIC);
93631 sqlite3VdbeAddOp4(v, OP_VCreate, iDb, 0, 0,
93632 pTab->zName, sqlite3Strlen30(pTab->zName) + 1);
93633 }
93634
@@ -94864,15 +95435,16 @@
94864 if( op==TK_REGISTER ){
94865 op = pRight->op2;
94866 }
94867 if( op==TK_VARIABLE ){
94868 Vdbe *pReprepare = pParse->pReprepare;
94869 pVal = sqlite3VdbeGetValue(pReprepare, pRight->iColumn, SQLITE_AFF_NONE);
 
94870 if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){
94871 z = (char *)sqlite3_value_text(pVal);
94872 }
94873 sqlite3VdbeSetVarmask(pParse->pVdbe, pRight->iColumn);
94874 assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
94875 }else if( op==TK_STRING ){
94876 z = pRight->u.zToken;
94877 }
94878 if( z ){
@@ -94886,11 +95458,11 @@
94886 pPrefix = sqlite3Expr(db, TK_STRING, z);
94887 if( pPrefix ) pPrefix->u.zToken[cnt] = 0;
94888 *ppPrefix = pPrefix;
94889 if( op==TK_VARIABLE ){
94890 Vdbe *v = pParse->pVdbe;
94891 sqlite3VdbeSetVarmask(v, pRight->iColumn);
94892 if( *pisComplete && pRight->u.zToken[1] ){
94893 /* If the rhs of the LIKE expression is a variable, and the current
94894 ** value of the variable means there is no need to invoke the LIKE
94895 ** function, then no OP_Variable will be added to the program.
94896 ** This causes problems for the sqlite3_bind_parameter_name()
@@ -95750,11 +96322,12 @@
95750
95751 /*
95752 ** Required because bestIndex() is called by bestOrClauseIndex()
95753 */
95754 static void bestIndex(
95755 Parse*, WhereClause*, struct SrcList_item*, Bitmask, ExprList*, WhereCost*);
 
95756
95757 /*
95758 ** This routine attempts to find an scanning strategy that can be used
95759 ** to optimize an 'OR' expression that is part of a WHERE clause.
95760 **
@@ -95763,11 +96336,12 @@
95763 */
95764 static void bestOrClauseIndex(
95765 Parse *pParse, /* The parsing context */
95766 WhereClause *pWC, /* The WHERE clause */
95767 struct SrcList_item *pSrc, /* The FROM clause term to search */
95768 Bitmask notReady, /* Mask of cursors that are not available */
 
95769 ExprList *pOrderBy, /* The ORDER BY clause */
95770 WhereCost *pCost /* Lowest cost query plan */
95771 ){
95772 #ifndef SQLITE_OMIT_OR_OPTIMIZATION
95773 const int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
@@ -95799,19 +96373,19 @@
95799 WHERETRACE(("... Multi-index OR testing for term %d of %d....\n",
95800 (pOrTerm - pOrWC->a), (pTerm - pWC->a)
95801 ));
95802 if( pOrTerm->eOperator==WO_AND ){
95803 WhereClause *pAndWC = &pOrTerm->u.pAndInfo->wc;
95804 bestIndex(pParse, pAndWC, pSrc, notReady, 0, &sTermCost);
95805 }else if( pOrTerm->leftCursor==iCur ){
95806 WhereClause tempWC;
95807 tempWC.pParse = pWC->pParse;
95808 tempWC.pMaskSet = pWC->pMaskSet;
95809 tempWC.op = TK_AND;
95810 tempWC.a = pOrTerm;
95811 tempWC.nTerm = 1;
95812 bestIndex(pParse, &tempWC, pSrc, notReady, 0, &sTermCost);
95813 }else{
95814 continue;
95815 }
95816 rTotal += sTermCost.rCost;
95817 nRow += sTermCost.nRow;
@@ -95900,11 +96474,11 @@
95900 return;
95901 }
95902
95903 assert( pParse->nQueryLoop >= (double)1 );
95904 pTable = pSrc->pTab;
95905 nTableRow = pTable->pIndex ? pTable->pIndex->aiRowEst[0] : 1000000;
95906 logN = estLog(nTableRow);
95907 costTempIdx = 2*logN*(nTableRow/pParse->nQueryLoop + 1);
95908 if( costTempIdx>=pCost->rCost ){
95909 /* The cost of creating the transient table would be greater than
95910 ** doing the full table scan */
@@ -96254,11 +96828,12 @@
96254 */
96255 static void bestVirtualIndex(
96256 Parse *pParse, /* The parsing context */
96257 WhereClause *pWC, /* The WHERE clause */
96258 struct SrcList_item *pSrc, /* The FROM clause term to search */
96259 Bitmask notReady, /* Mask of cursors that are not available */
 
96260 ExprList *pOrderBy, /* The order by clause */
96261 WhereCost *pCost, /* Lowest cost query plan */
96262 sqlite3_index_info **ppIdxInfo /* Index information passed to xBestIndex */
96263 ){
96264 Table *pTab = pSrc->pTab;
@@ -96384,11 +96959,11 @@
96384 pIdxInfo->nOrderBy = nOrderBy;
96385
96386 /* Try to find a more efficient access pattern by using multiple indexes
96387 ** to optimize an OR expression within the WHERE clause.
96388 */
96389 bestOrClauseIndex(pParse, pWC, pSrc, notReady, pOrderBy, pCost);
96390 }
96391 #endif /* SQLITE_OMIT_VIRTUALTABLE */
96392
96393 /*
96394 ** Argument pIdx is a pointer to an index structure that has an array of
@@ -96510,11 +97085,11 @@
96510 /* The evalConstExpr() function will have already converted any TK_VARIABLE
96511 ** expression involved in an comparison into a TK_REGISTER. */
96512 assert( pExpr->op!=TK_VARIABLE );
96513 if( pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE ){
96514 int iVar = pExpr->iColumn;
96515 sqlite3VdbeSetVarmask(pParse->pVdbe, iVar);
96516 *pp = sqlite3VdbeGetValue(pParse->pReprepare, iVar, aff);
96517 return SQLITE_OK;
96518 }
96519 return sqlite3ValueFromExpr(pParse->db, pExpr, SQLITE_UTF8, aff, pp);
96520 }
@@ -96665,11 +97240,12 @@
96665 */
96666 static void bestBtreeIndex(
96667 Parse *pParse, /* The parsing context */
96668 WhereClause *pWC, /* The WHERE clause */
96669 struct SrcList_item *pSrc, /* The FROM clause term to search */
96670 Bitmask notReady, /* Mask of cursors that are not available */
 
96671 ExprList *pOrderBy, /* The ORDER BY clause */
96672 WhereCost *pCost /* Lowest cost query plan */
96673 ){
96674 int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
96675 Index *pProbe; /* An index we are evaluating */
@@ -96707,27 +97283,18 @@
96707 Index *pFirst; /* Any other index on the table */
96708 memset(&sPk, 0, sizeof(Index));
96709 sPk.nColumn = 1;
96710 sPk.aiColumn = &aiColumnPk;
96711 sPk.aiRowEst = aiRowEstPk;
96712 aiRowEstPk[1] = 1;
96713 sPk.onError = OE_Replace;
96714 sPk.pTable = pSrc->pTab;
 
 
96715 pFirst = pSrc->pTab->pIndex;
96716 if( pSrc->notIndexed==0 ){
96717 sPk.pNext = pFirst;
96718 }
96719 /* The aiRowEstPk[0] is an estimate of the total number of rows in the
96720 ** table. Get this information from the ANALYZE information if it is
96721 ** available. If not available, assume the table 1 million rows in size.
96722 */
96723 if( pFirst ){
96724 assert( pFirst->aiRowEst!=0 ); /* Allocated together with pFirst */
96725 aiRowEstPk[0] = pFirst->aiRowEst[0];
96726 }else{
96727 aiRowEstPk[0] = 1000000;
96728 }
96729 pProbe = &sPk;
96730 wsFlagMask = ~(
96731 WHERE_COLUMN_IN|WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_RANGE
96732 );
96733 eqTermMask = WO_EQ|WO_IN;
@@ -96936,29 +97503,29 @@
96936 ** of output rows, adjust the nRow value accordingly. This only
96937 ** matters if the current index is the least costly, so do not bother
96938 ** with this step if we already know this index will not be chosen.
96939 ** Also, never reduce the output row count below 2 using this step.
96940 **
96941 ** Do not reduce the output row count if pSrc is the only table that
96942 ** is notReady; if notReady is a power of two. This will be the case
96943 ** when the main sqlite3WhereBegin() loop is scanning for a table with
96944 ** and "optimal" index, and on such a scan the output row count
96945 ** reduction is not valid because it does not update the "pCost->used"
96946 ** bitmap. The notReady bitmap will also be a power of two when we
96947 ** are scanning for the last table in a 64-way join. We are willing
96948 ** to bypass this optimization in that corner case.
96949 */
96950 if( nRow>2 && cost<=pCost->rCost && (notReady & (notReady-1))!=0 ){
96951 int k; /* Loop counter */
96952 int nSkipEq = nEq; /* Number of == constraints to skip */
96953 int nSkipRange = nBound; /* Number of < constraints to skip */
96954 Bitmask thisTab; /* Bitmap for pSrc */
96955
96956 thisTab = getMask(pWC->pMaskSet, iCur);
96957 for(pTerm=pWC->a, k=pWC->nTerm; nRow>2 && k; k--, pTerm++){
96958 if( pTerm->wtFlags & TERM_VIRTUAL ) continue;
96959 if( (pTerm->prereqAll & notReady)!=thisTab ) continue;
96960 if( pTerm->eOperator & (WO_EQ|WO_IN|WO_ISNULL) ){
96961 if( nSkipEq ){
96962 /* Ignore the first nEq equality matches since the index
96963 ** has already accounted for these */
96964 nSkipEq--;
@@ -97036,11 +97603,11 @@
97036 WHERETRACE(("best index is: %s\n",
97037 ((pCost->plan.wsFlags & WHERE_NOT_FULLSCAN)==0 ? "none" :
97038 pCost->plan.u.pIdx ? pCost->plan.u.pIdx->zName : "ipk")
97039 ));
97040
97041 bestOrClauseIndex(pParse, pWC, pSrc, notReady, pOrderBy, pCost);
97042 bestAutomaticIndex(pParse, pWC, pSrc, notReady, pCost);
97043 pCost->plan.wsFlags |= eqTermMask;
97044 }
97045
97046 /*
@@ -97051,26 +97618,27 @@
97051 */
97052 static void bestIndex(
97053 Parse *pParse, /* The parsing context */
97054 WhereClause *pWC, /* The WHERE clause */
97055 struct SrcList_item *pSrc, /* The FROM clause term to search */
97056 Bitmask notReady, /* Mask of cursors that are not available */
 
97057 ExprList *pOrderBy, /* The ORDER BY clause */
97058 WhereCost *pCost /* Lowest cost query plan */
97059 ){
97060 #ifndef SQLITE_OMIT_VIRTUALTABLE
97061 if( IsVirtual(pSrc->pTab) ){
97062 sqlite3_index_info *p = 0;
97063 bestVirtualIndex(pParse, pWC, pSrc, notReady, pOrderBy, pCost, &p);
97064 if( p->needToFreeIdxStr ){
97065 sqlite3_free(p->idxStr);
97066 }
97067 sqlite3DbFree(pParse->db, p);
97068 }else
97069 #endif
97070 {
97071 bestBtreeIndex(pParse, pWC, pSrc, notReady, pOrderBy, pCost);
97072 }
97073 }
97074
97075 /*
97076 ** Disable a term in the WHERE clause. Except, do not disable the term
@@ -98281,14 +98849,20 @@
98281 ** by waiting for other tables to run first. This "optimal" test works
98282 ** by first assuming that the FROM clause is on the inner loop and finding
98283 ** its query plan, then checking to see if that query plan uses any
98284 ** other FROM clause terms that are notReady. If no notReady terms are
98285 ** used then the "optimal" query plan works.
 
 
 
 
 
 
98286 **
98287 ** The second loop iteration is only performed if no optimal scan
98288 ** strategies were found by the first loop. This 2nd iteration is used to
98289 ** search for the lowest cost scan overall.
98290 **
98291 ** Previous versions of SQLite performed only the second iteration -
98292 ** the next outermost loop was always that with the lowest overall
98293 ** cost. However, this meant that SQLite could select the wrong plan
98294 ** for scripts such as the following:
@@ -98297,18 +98871,18 @@
98297 ** CREATE TABLE t2(c, d);
98298 ** SELECT * FROM t2, t1 WHERE t2.rowid = t1.a;
98299 **
98300 ** The best strategy is to iterate through table t1 first. However it
98301 ** is not possible to determine this with a simple greedy algorithm.
98302 ** However, since the cost of a linear scan through table t2 is the same
98303 ** as the cost of a linear scan through table t1, a simple greedy
98304 ** algorithm may choose to use t2 for the outer loop, which is a much
98305 ** costlier approach.
98306 */
98307 nUnconstrained = 0;
98308 notIndexed = 0;
98309 for(isOptimal=(iFrom<nTabList-1); isOptimal>=0; isOptimal--){
98310 Bitmask mask; /* Mask of tables not yet ready */
98311 for(j=iFrom, pTabItem=&pTabList->a[j]; j<nTabList; j++, pTabItem++){
98312 int doNotReorder; /* True if this table should not be reordered */
98313 WhereCost sCost; /* Cost information from best[Virtual]Index() */
98314 ExprList *pOrderBy; /* ORDER BY clause for index to optimize */
@@ -98326,15 +98900,17 @@
98326
98327 assert( pTabItem->pTab );
98328 #ifndef SQLITE_OMIT_VIRTUALTABLE
98329 if( IsVirtual(pTabItem->pTab) ){
98330 sqlite3_index_info **pp = &pWInfo->a[j].pIdxInfo;
98331 bestVirtualIndex(pParse, pWC, pTabItem, mask, pOrderBy, &sCost, pp);
 
98332 }else
98333 #endif
98334 {
98335 bestBtreeIndex(pParse, pWC, pTabItem, mask, pOrderBy, &sCost);
 
98336 }
98337 assert( isOptimal || (sCost.used&notReady)==0 );
98338
98339 /* If an INDEXED BY clause is present, then the plan must use that
98340 ** index if it uses any index at all */
@@ -103366,19 +103942,37 @@
103366
103367 /************** End of sqliteicu.h *******************************************/
103368 /************** Continuing where we left off in main.c ***********************/
103369 #endif
103370
103371 /*
103372 ** The version of the library
103373 */
103374 #ifndef SQLITE_AMALGAMATION
 
 
 
103375 SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
103376 #endif
 
 
 
 
103377 SQLITE_API const char *sqlite3_libversion(void){ return sqlite3_version; }
 
 
 
 
 
103378 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
 
 
 
 
103379 SQLITE_API int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; }
 
 
 
 
 
103380 SQLITE_API int sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }
103381
103382 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
103383 /*
103384 ** If the following function pointer is not NULL and if
@@ -103495,10 +104089,17 @@
103495 /* Do the rest of the initialization under the recursive mutex so
103496 ** that we will be able to handle recursive calls into
103497 ** sqlite3_initialize(). The recursive calls normally come through
103498 ** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other
103499 ** recursive calls might also be possible.
 
 
 
 
 
 
 
103500 */
103501 sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex);
103502 if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){
103503 FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions);
103504 sqlite3GlobalConfig.inProgress = 1;
@@ -103775,16 +104376,16 @@
103775 if( cnt<0 ) cnt = 0;
103776 if( sz==0 || cnt==0 ){
103777 sz = 0;
103778 pStart = 0;
103779 }else if( pBuf==0 ){
103780 sz = ROUND8(sz);
103781 sqlite3BeginBenignMalloc();
103782 pStart = sqlite3Malloc( sz*cnt );
103783 sqlite3EndBenignMalloc();
103784 }else{
103785 sz = ROUNDDOWN8(sz);
103786 pStart = pBuf;
103787 }
103788 db->lookaside.pStart = pStart;
103789 db->lookaside.pFree = 0;
103790 db->lookaside.sz = (u16)sz;
@@ -103823,18 +104424,18 @@
103823 va_list ap;
103824 int rc;
103825 va_start(ap, op);
103826 switch( op ){
103827 case SQLITE_DBCONFIG_LOOKASIDE: {
103828 void *pBuf = va_arg(ap, void*);
103829 int sz = va_arg(ap, int);
103830 int cnt = va_arg(ap, int);
103831 rc = setupLookaside(db, pBuf, sz, cnt);
103832 break;
103833 }
103834 default: {
103835 rc = SQLITE_ERROR;
103836 break;
103837 }
103838 }
103839 va_end(ap);
103840 return rc;
@@ -103934,16 +104535,33 @@
103934 }
103935 db->nSavepoint = 0;
103936 db->nStatement = 0;
103937 db->isTransactionSavepoint = 0;
103938 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103939
103940 /*
103941 ** Close an existing SQLite database
103942 */
103943 SQLITE_API int sqlite3_close(sqlite3 *db){
103944 HashElem *i;
103945 int j;
103946
103947 if( !db ){
103948 return SQLITE_OK;
103949 }
@@ -104007,10 +104625,11 @@
104007 for(j=0; j<ArraySize(db->aFunc.a); j++){
104008 FuncDef *pNext, *pHash, *p;
104009 for(p=db->aFunc.a[j]; p; p=pHash){
104010 pHash = p->pHash;
104011 while( p ){
 
104012 pNext = p->pNext;
104013 sqlite3DbFree(db, p);
104014 p = pNext;
104015 }
104016 }
@@ -104281,11 +104900,12 @@
104281 int nArg,
104282 int enc,
104283 void *pUserData,
104284 void (*xFunc)(sqlite3_context*,int,sqlite3_value **),
104285 void (*xStep)(sqlite3_context*,int,sqlite3_value **),
104286 void (*xFinal)(sqlite3_context*)
 
104287 ){
104288 FuncDef *p;
104289 int nName;
104290
104291 assert( sqlite3_mutex_held(db->mutex) );
@@ -104309,14 +104929,14 @@
104309 if( enc==SQLITE_UTF16 ){
104310 enc = SQLITE_UTF16NATIVE;
104311 }else if( enc==SQLITE_ANY ){
104312 int rc;
104313 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,
104314 pUserData, xFunc, xStep, xFinal);
104315 if( rc==SQLITE_OK ){
104316 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,
104317 pUserData, xFunc, xStep, xFinal);
104318 }
104319 if( rc!=SQLITE_OK ){
104320 return rc;
104321 }
104322 enc = SQLITE_UTF16BE;
@@ -104345,10 +104965,19 @@
104345 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
104346 assert(p || db->mallocFailed);
104347 if( !p ){
104348 return SQLITE_NOMEM;
104349 }
 
 
 
 
 
 
 
 
 
104350 p->flags = 0;
104351 p->xFunc = xFunc;
104352 p->xStep = xStep;
104353 p->xFinalize = xFinal;
104354 p->pUserData = pUserData;
@@ -104359,21 +104988,53 @@
104359 /*
104360 ** Create new user functions.
104361 */
104362 SQLITE_API int sqlite3_create_function(
104363 sqlite3 *db,
104364 const char *zFunctionName,
104365 int nArg,
104366 int enc,
104367 void *p,
104368 void (*xFunc)(sqlite3_context*,int,sqlite3_value **),
104369 void (*xStep)(sqlite3_context*,int,sqlite3_value **),
104370 void (*xFinal)(sqlite3_context*)
104371 ){
104372 int rc;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104373 sqlite3_mutex_enter(db->mutex);
104374 rc = sqlite3CreateFunc(db, zFunctionName, nArg, enc, p, xFunc, xStep, xFinal);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104375 rc = sqlite3ApiExit(db, rc);
104376 sqlite3_mutex_leave(db->mutex);
104377 return rc;
104378 }
104379
@@ -104391,11 +105052,11 @@
104391 int rc;
104392 char *zFunc8;
104393 sqlite3_mutex_enter(db->mutex);
104394 assert( !db->mallocFailed );
104395 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
104396 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal);
104397 sqlite3DbFree(db, zFunc8);
104398 rc = sqlite3ApiExit(db, rc);
104399 sqlite3_mutex_leave(db->mutex);
104400 return rc;
104401 }
@@ -104422,11 +105083,11 @@
104422 int nName = sqlite3Strlen30(zName);
104423 int rc;
104424 sqlite3_mutex_enter(db->mutex);
104425 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
104426 sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
104427 0, sqlite3InvalidFunction, 0, 0);
104428 }
104429 rc = sqlite3ApiExit(db, SQLITE_OK);
104430 sqlite3_mutex_leave(db->mutex);
104431 return rc;
104432 }
@@ -104560,11 +105221,14 @@
104560 ** registered using sqlite3_wal_hook(). Likewise, registering a callback
104561 ** using sqlite3_wal_hook() disables the automatic checkpoint mechanism
104562 ** configured by this function.
104563 */
104564 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
104565 #ifndef SQLITE_OMIT_WAL
 
 
 
104566 if( nFrame>0 ){
104567 sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
104568 }else{
104569 sqlite3_wal_hook(db, 0, 0);
104570 }
@@ -104690,64 +105354,10 @@
104690 #if SQLITE_TEMP_STORE<1 || SQLITE_TEMP_STORE>3
104691 return 0;
104692 #endif
104693 }
104694
104695 /*
104696 ** This routine is called to create a connection to a database BTree
104697 ** driver. If zFilename is the name of a file, then that file is
104698 ** opened and used. If zFilename is the magic name ":memory:" then
104699 ** the database is stored in memory (and is thus forgotten as soon as
104700 ** the connection is closed.) If zFilename is NULL then the database
104701 ** is a "virtual" database for transient use only and is deleted as
104702 ** soon as the connection is closed.
104703 **
104704 ** A virtual database can be either a disk file (that is automatically
104705 ** deleted when the file is closed) or it an be held entirely in memory.
104706 ** The sqlite3TempInMemory() function is used to determine which.
104707 */
104708 SQLITE_PRIVATE int sqlite3BtreeFactory(
104709 sqlite3 *db, /* Main database when opening aux otherwise 0 */
104710 const char *zFilename, /* Name of the file containing the BTree database */
104711 int omitJournal, /* if TRUE then do not journal this file */
104712 int nCache, /* How many pages in the page cache */
104713 int vfsFlags, /* Flags passed through to vfsOpen */
104714 Btree **ppBtree /* Pointer to new Btree object written here */
104715 ){
104716 int btFlags = 0;
104717 int rc;
104718
104719 assert( sqlite3_mutex_held(db->mutex) );
104720 assert( ppBtree != 0);
104721 if( omitJournal ){
104722 btFlags |= BTREE_OMIT_JOURNAL;
104723 }
104724 if( db->flags & SQLITE_NoReadlock ){
104725 btFlags |= BTREE_NO_READLOCK;
104726 }
104727 #ifndef SQLITE_OMIT_MEMORYDB
104728 if( zFilename==0 && sqlite3TempInMemory(db) ){
104729 zFilename = ":memory:";
104730 }
104731 #endif
104732
104733 if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (zFilename==0 || *zFilename==0) ){
104734 vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB;
104735 }
104736 rc = sqlite3BtreeOpen(zFilename, (sqlite3 *)db, ppBtree, btFlags, vfsFlags);
104737
104738 /* If the B-Tree was successfully opened, set the pager-cache size to the
104739 ** default value. Except, if the call to BtreeOpen() returned a handle
104740 ** open on an existing shared pager-cache, do not change the pager-cache
104741 ** size.
104742 */
104743 if( rc==SQLITE_OK && 0==sqlite3BtreeSchema(*ppBtree, 0, 0) ){
104744 sqlite3BtreeSetCacheSize(*ppBtree, nCache);
104745 }
104746 return rc;
104747 }
104748
104749 /*
104750 ** Return UTF-8 encoded English language explanation of the most recent
104751 ** error.
104752 */
104753 SQLITE_API const char *sqlite3_errmsg(sqlite3 *db){
@@ -104986,21 +105596,43 @@
104986 ** It merely prevents new constructs that exceed the limit
104987 ** from forming.
104988 */
104989 SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
104990 int oldLimit;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104991 if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
104992 return -1;
104993 }
104994 oldLimit = db->aLimit[limitId];
104995 if( newLimit>=0 ){
104996 if( newLimit>aHardLimit[limitId] ){
104997 newLimit = aHardLimit[limitId];
104998 }
104999 db->aLimit[limitId] = newLimit;
105000 }
105001 return oldLimit;
105002 }
105003
105004 /*
105005 ** This routine does the work of opening a database on behalf of
105006 ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
@@ -105019,10 +105651,28 @@
105019 *ppDb = 0;
105020 #ifndef SQLITE_OMIT_AUTOINIT
105021 rc = sqlite3_initialize();
105022 if( rc ) return rc;
105023 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105024
105025 if( sqlite3GlobalConfig.bCoreMutex==0 ){
105026 isThreadsafe = 0;
105027 }else if( flags & SQLITE_OPEN_NOMUTEX ){
105028 isThreadsafe = 0;
@@ -105053,11 +105703,12 @@
105053 SQLITE_OPEN_MAIN_JOURNAL |
105054 SQLITE_OPEN_TEMP_JOURNAL |
105055 SQLITE_OPEN_SUBJOURNAL |
105056 SQLITE_OPEN_MASTER_JOURNAL |
105057 SQLITE_OPEN_NOMUTEX |
105058 SQLITE_OPEN_FULLMUTEX
 
105059 );
105060
105061 /* Allocate the sqlite data structure */
105062 db = sqlite3MallocZero( sizeof(sqlite3) );
105063 if( db==0 ) goto opendb_out;
@@ -105125,13 +105776,12 @@
105125 createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0,
105126 nocaseCollatingFunc, 0);
105127
105128 /* Open the backend database driver */
105129 db->openFlags = flags;
105130 rc = sqlite3BtreeFactory(db, zFilename, 0, SQLITE_DEFAULT_CACHE_SIZE,
105131 flags | SQLITE_OPEN_MAIN_DB,
105132 &db->aDb[0].pBt);
105133 if( rc!=SQLITE_OK ){
105134 if( rc==SQLITE_IOERR_NOMEM ){
105135 rc = SQLITE_NOMEM;
105136 }
105137 sqlite3Error(db, rc, 0);
@@ -105833,10 +106483,26 @@
105833 */
105834 case SQLITE_TESTCTRL_PGHDRSZ: {
105835 rc = sizeof(PgHdr);
105836 break;
105837 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105838
105839 }
105840 va_end(ap);
105841 #endif /* SQLITE_OMIT_BUILTIN_TEST */
105842 return rc;
@@ -107022,10 +107688,11 @@
107022 );
107023 SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char const**, int*);
107024 SQLITE_PRIVATE int sqlite3Fts3AllSegdirs(Fts3Table*, sqlite3_stmt **);
107025 SQLITE_PRIVATE int sqlite3Fts3MatchinfoDocsizeLocal(Fts3Cursor*, u32*);
107026 SQLITE_PRIVATE int sqlite3Fts3MatchinfoDocsizeGlobal(Fts3Cursor*, u32*);
 
107027
107028 /* Flags allowed as part of the 4th argument to SegmentReaderIterate() */
107029 #define FTS3_SEGMENT_REQUIRE_POS 0x00000001
107030 #define FTS3_SEGMENT_IGNORE_EMPTY 0x00000002
107031 #define FTS3_SEGMENT_COLUMN_FILTER 0x00000004
@@ -108971,10 +109638,13 @@
108971 zQuery);
108972 }
108973 return rc;
108974 }
108975
 
 
 
108976 rc = evalFts3Expr(p, pCsr->pExpr, &pCsr->aDoclist, &pCsr->nDoclist, 0);
108977 pCsr->pNextId = pCsr->aDoclist;
108978 pCsr->iPrevId = 0;
108979 }
108980
@@ -109349,15 +110019,18 @@
109349 static int fts3RenameMethod(
109350 sqlite3_vtab *pVtab, /* Virtual table handle */
109351 const char *zName /* New name of table */
109352 ){
109353 Fts3Table *p = (Fts3Table *)pVtab;
109354 sqlite3 *db; /* Database connection */
109355 int rc; /* Return Code */
109356
109357 db = p->db;
109358 rc = SQLITE_OK;
 
 
 
109359 fts3DbExec(&rc, db,
109360 "ALTER TABLE %Q.'%q_content' RENAME TO '%q_content';",
109361 p->zDb, p->zName, zName
109362 );
109363 if( rc==SQLITE_ERROR ) rc = SQLITE_OK;
@@ -112512,10 +113185,40 @@
112512 return SQLITE_CORRUPT;
112513 }
112514 }
112515 return SQLITE_OK;
112516 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112517
112518 /*
112519 ** Set *ppStmt to a statement handle that may be used to iterate through
112520 ** all rows in the %_segdir table, from oldest to newest. If successful,
112521 ** return SQLITE_OK. If an error occurs while preparing the statement,
@@ -116003,10 +116706,49 @@
116003 **
116004 *************************************************************************
116005 ** This file contains code for implementations of the r-tree and r*-tree
116006 ** algorithms packaged as an SQLite virtual table module.
116007 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116008
116009 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE)
116010
116011 /*
116012 ** This file contains an implementation of a couple of different variants
@@ -116044,18 +116786,22 @@
116044 #endif
116045 #if VARIANT_RSTARTREE_SPLIT
116046 #define AssignCells splitNodeStartree
116047 #endif
116048
 
 
 
116049
116050 #ifndef SQLITE_CORE
116051 SQLITE_EXTENSION_INIT1
116052 #else
116053 #endif
116054
116055
116056 #ifndef SQLITE_AMALGAMATION
 
116057 typedef sqlite3_int64 i64;
116058 typedef unsigned char u8;
116059 typedef unsigned int u32;
116060 #endif
116061
@@ -116062,10 +116808,12 @@
116062 typedef struct Rtree Rtree;
116063 typedef struct RtreeCursor RtreeCursor;
116064 typedef struct RtreeNode RtreeNode;
116065 typedef struct RtreeCell RtreeCell;
116066 typedef struct RtreeConstraint RtreeConstraint;
 
 
116067 typedef union RtreeCoord RtreeCoord;
116068
116069 /* The rtree may have between 1 and RTREE_MAX_DIMENSIONS dimensions. */
116070 #define RTREE_MAX_DIMENSIONS 5
116071
@@ -116131,10 +116879,19 @@
116131 */
116132 #define RTREE_MINCELLS(p) ((((p)->iNodeSize-4)/(p)->nBytesPerCell)/3)
116133 #define RTREE_REINSERT(p) RTREE_MINCELLS(p)
116134 #define RTREE_MAXCELLS 51
116135
 
 
 
 
 
 
 
 
 
116136 /*
116137 ** An rtree cursor object.
116138 */
116139 struct RtreeCursor {
116140 sqlite3_vtab_cursor base;
@@ -116163,39 +116920,27 @@
116163
116164 /*
116165 ** A search constraint.
116166 */
116167 struct RtreeConstraint {
116168 int iCoord; /* Index of constrained coordinate */
116169 int op; /* Constraining operation */
116170 double rValue; /* Constraint value. */
 
 
116171 };
116172
116173 /* Possible values for RtreeConstraint.op */
116174 #define RTREE_EQ 0x41
116175 #define RTREE_LE 0x42
116176 #define RTREE_LT 0x43
116177 #define RTREE_GE 0x44
116178 #define RTREE_GT 0x45
 
116179
116180 /*
116181 ** An rtree structure node.
116182 **
116183 ** Data format (RtreeNode.zData):
116184 **
116185 ** 1. If the node is the root node (node 1), then the first 2 bytes
116186 ** of the node contain the tree depth as a big-endian integer.
116187 ** For non-root nodes, the first 2 bytes are left unused.
116188 **
116189 ** 2. The next 2 bytes contain the number of entries currently
116190 ** stored in the node.
116191 **
116192 ** 3. The remainder of the node contains the node entries. Each entry
116193 ** consists of a single 8-byte integer followed by an even number
116194 ** of 4-byte coordinates. For leaf nodes the integer is the rowid
116195 ** of a record. For internal nodes it is the node number of a
116196 ** child page.
116197 */
116198 struct RtreeNode {
116199 RtreeNode *pParent; /* Parent node */
116200 i64 iNode;
116201 int nRef;
@@ -116211,10 +116956,44 @@
116211 struct RtreeCell {
116212 i64 iRowid;
116213 RtreeCoord aCoord[RTREE_MAX_DIMENSIONS*2];
116214 };
116215
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116216 #ifndef MAX
116217 # define MAX(x,y) ((x) < (y) ? (y) : (x))
116218 #endif
116219 #ifndef MIN
116220 # define MIN(x,y) ((x) > (y) ? (y) : (x))
@@ -116293,14 +117072,12 @@
116293
116294 /*
116295 ** Clear the content of node p (set all bytes to 0x00).
116296 */
116297 static void nodeZero(Rtree *pRtree, RtreeNode *p){
116298 if( p ){
116299 memset(&p->zData[2], 0, pRtree->iNodeSize-2);
116300 p->isDirty = 1;
116301 }
116302 }
116303
116304 /*
116305 ** Given a node number iNode, return the corresponding key to use
116306 ** in the Rtree.aHash table.
@@ -116316,26 +117093,23 @@
116316 ** Search the node hash table for node iNode. If found, return a pointer
116317 ** to it. Otherwise, return 0.
116318 */
116319 static RtreeNode *nodeHashLookup(Rtree *pRtree, i64 iNode){
116320 RtreeNode *p;
116321 assert( iNode!=0 );
116322 for(p=pRtree->aHash[nodeHash(iNode)]; p && p->iNode!=iNode; p=p->pNext);
116323 return p;
116324 }
116325
116326 /*
116327 ** Add node pNode to the node hash table.
116328 */
116329 static void nodeHashInsert(Rtree *pRtree, RtreeNode *pNode){
116330 if( pNode ){
116331 int iHash;
116332 assert( pNode->pNext==0 );
116333 iHash = nodeHash(pNode->iNode);
116334 pNode->pNext = pRtree->aHash[iHash];
116335 pRtree->aHash[iHash] = pNode;
116336 }
116337 }
116338
116339 /*
116340 ** Remove node pNode from the node hash table.
116341 */
@@ -116353,15 +117127,15 @@
116353 ** Allocate and return new r-tree node. Initially, (RtreeNode.iNode==0),
116354 ** indicating that node has not yet been assigned a node number. It is
116355 ** assigned a node number when nodeWrite() is called to write the
116356 ** node contents out to the database.
116357 */
116358 static RtreeNode *nodeNew(Rtree *pRtree, RtreeNode *pParent, int zero){
116359 RtreeNode *pNode;
116360 pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode) + pRtree->iNodeSize);
116361 if( pNode ){
116362 memset(pNode, 0, sizeof(RtreeNode) + (zero?pRtree->iNodeSize:0));
116363 pNode->zData = (u8 *)&pNode[1];
116364 pNode->nRef = 1;
116365 pNode->pParent = pParent;
116366 pNode->isDirty = 1;
116367 nodeReference(pParent);
@@ -116378,10 +117152,11 @@
116378 i64 iNode, /* Node number to load */
116379 RtreeNode *pParent, /* Either the parent node or NULL */
116380 RtreeNode **ppNode /* OUT: Acquired node */
116381 ){
116382 int rc;
 
116383 RtreeNode *pNode;
116384
116385 /* Check if the requested node is already in the hash table. If so,
116386 ** increase its reference count and return it.
116387 */
@@ -116394,43 +117169,67 @@
116394 pNode->nRef++;
116395 *ppNode = pNode;
116396 return SQLITE_OK;
116397 }
116398
116399 pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode) + pRtree->iNodeSize);
116400 if( !pNode ){
116401 *ppNode = 0;
116402 return SQLITE_NOMEM;
116403 }
116404 pNode->pParent = pParent;
116405 pNode->zData = (u8 *)&pNode[1];
116406 pNode->nRef = 1;
116407 pNode->iNode = iNode;
116408 pNode->isDirty = 0;
116409 pNode->pNext = 0;
116410
116411 sqlite3_bind_int64(pRtree->pReadNode, 1, iNode);
116412 rc = sqlite3_step(pRtree->pReadNode);
116413 if( rc==SQLITE_ROW ){
116414 const u8 *zBlob = sqlite3_column_blob(pRtree->pReadNode, 0);
116415 assert( sqlite3_column_bytes(pRtree->pReadNode, 0)==pRtree->iNodeSize );
116416 memcpy(pNode->zData, zBlob, pRtree->iNodeSize);
116417 nodeReference(pParent);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116418 }else{
116419 sqlite3_free(pNode);
116420 pNode = 0;
116421 }
116422
116423 *ppNode = pNode;
116424 rc = sqlite3_reset(pRtree->pReadNode);
116425
116426 if( rc==SQLITE_OK && iNode==1 ){
116427 pRtree->iDepth = readInt16(pNode->zData);
116428 }
116429
116430 assert( (rc==SQLITE_OK && pNode) || (pNode==0 && rc!=SQLITE_OK) );
116431 nodeHashInsert(pRtree, pNode);
116432
116433 return rc;
116434 }
116435
116436 /*
@@ -116479,12 +117278,11 @@
116479 int nMaxCell; /* Maximum number of cells for pNode */
116480
116481 nMaxCell = (pRtree->iNodeSize-4)/pRtree->nBytesPerCell;
116482 nCell = NCELL(pNode);
116483
116484 assert(nCell<=nMaxCell);
116485
116486 if( nCell<nMaxCell ){
116487 nodeOverwriteCell(pRtree, pNode, pCell, nCell);
116488 writeInt16(&pNode->zData[2], nCell+1);
116489 pNode->isDirty = 1;
116490 }
@@ -116700,18 +117498,37 @@
116700 *ppCursor = (sqlite3_vtab_cursor *)pCsr;
116701
116702 return rc;
116703 }
116704
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116705 /*
116706 ** Rtree virtual table module xClose method.
116707 */
116708 static int rtreeClose(sqlite3_vtab_cursor *cur){
116709 Rtree *pRtree = (Rtree *)(cur->pVtab);
116710 int rc;
116711 RtreeCursor *pCsr = (RtreeCursor *)cur;
116712 sqlite3_free(pCsr->aConstraint);
116713 rc = nodeRelease(pRtree, pCsr->pNode);
116714 sqlite3_free(pCsr);
116715 return rc;
116716 }
116717
@@ -116723,18 +117540,44 @@
116723 */
116724 static int rtreeEof(sqlite3_vtab_cursor *cur){
116725 RtreeCursor *pCsr = (RtreeCursor *)cur;
116726 return (pCsr->pNode==0);
116727 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116728
116729 /*
116730 ** Cursor pCursor currently points to a cell in a non-leaf page.
116731 ** Return true if the sub-tree headed by the cell is filtered
116732 ** (excluded) by the constraints in the pCursor->aConstraint[]
116733 ** array, or false otherwise.
 
 
 
116734 */
116735 static int testRtreeCell(Rtree *pRtree, RtreeCursor *pCursor){
116736 RtreeCell cell;
116737 int ii;
116738 int bRes = 0;
116739
116740 nodeGetCell(pRtree, pCursor->pNode, pCursor->iCell, &cell);
@@ -116742,56 +117585,92 @@
116742 RtreeConstraint *p = &pCursor->aConstraint[ii];
116743 double cell_min = DCOORD(cell.aCoord[(p->iCoord>>1)*2]);
116744 double cell_max = DCOORD(cell.aCoord[(p->iCoord>>1)*2+1]);
116745
116746 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
116747 || p->op==RTREE_GT || p->op==RTREE_EQ
116748 );
116749
116750 switch( p->op ){
116751 case RTREE_LE: case RTREE_LT: bRes = p->rValue<cell_min; break;
116752 case RTREE_GE: case RTREE_GT: bRes = p->rValue>cell_max; break;
116753 case RTREE_EQ:
 
 
 
 
 
 
116754 bRes = (p->rValue>cell_max || p->rValue<cell_min);
116755 break;
 
 
 
 
 
 
 
 
 
 
 
116756 }
116757 }
116758
116759 return bRes;
 
116760 }
116761
116762 /*
116763 ** Return true if the cell that cursor pCursor currently points to
116764 ** would be filtered (excluded) by the constraints in the
116765 ** pCursor->aConstraint[] array, or false otherwise.
 
 
 
 
 
116766 **
116767 ** This function assumes that the cell is part of a leaf node.
116768 */
116769 static int testRtreeEntry(Rtree *pRtree, RtreeCursor *pCursor){
116770 RtreeCell cell;
116771 int ii;
 
116772
116773 nodeGetCell(pRtree, pCursor->pNode, pCursor->iCell, &cell);
116774 for(ii=0; ii<pCursor->nConstraint; ii++){
116775 RtreeConstraint *p = &pCursor->aConstraint[ii];
116776 double coord = DCOORD(cell.aCoord[p->iCoord]);
116777 int res;
116778 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
116779 || p->op==RTREE_GT || p->op==RTREE_EQ
116780 );
116781 switch( p->op ){
116782 case RTREE_LE: res = (coord<=p->rValue); break;
116783 case RTREE_LT: res = (coord<p->rValue); break;
116784 case RTREE_GE: res = (coord>=p->rValue); break;
116785 case RTREE_GT: res = (coord>p->rValue); break;
116786 case RTREE_EQ: res = (coord==p->rValue); break;
 
 
 
 
 
 
 
 
 
116787 }
116788
116789 if( !res ) return 1;
 
 
 
116790 }
116791
116792 return 0;
116793 }
116794
116795 /*
116796 ** Cursor pCursor currently points at a node that heads a sub-tree of
116797 ** height iHeight (if iHeight==0, then the node is a leaf). Descend
@@ -116814,17 +117693,17 @@
116814 int iSavedCell = pCursor->iCell;
116815
116816 assert( iHeight>=0 );
116817
116818 if( iHeight==0 ){
116819 isEof = testRtreeEntry(pRtree, pCursor);
116820 }else{
116821 isEof = testRtreeCell(pRtree, pCursor);
116822 }
116823 if( isEof || iHeight==0 ){
116824 *pEof = isEof;
116825 return SQLITE_OK;
116826 }
116827
116828 iRowid = nodeGetRowid(pRtree, pCursor->pNode, pCursor->iCell);
116829 rc = nodeAcquire(pRtree, iRowid, pCursor->pNode, &pChild);
116830 if( rc!=SQLITE_OK ){
@@ -116856,45 +117735,59 @@
116856
116857 /*
116858 ** One of the cells in node pNode is guaranteed to have a 64-bit
116859 ** integer value equal to iRowid. Return the index of this cell.
116860 */
116861 static int nodeRowidIndex(Rtree *pRtree, RtreeNode *pNode, i64 iRowid){
 
 
 
 
 
116862 int ii;
116863 for(ii=0; nodeGetRowid(pRtree, pNode, ii)!=iRowid; ii++){
116864 assert( ii<(NCELL(pNode)-1) );
 
 
 
 
116865 }
116866 return ii;
116867 }
116868
116869 /*
116870 ** Return the index of the cell containing a pointer to node pNode
116871 ** in its parent. If pNode is the root node, return -1.
116872 */
116873 static int nodeParentIndex(Rtree *pRtree, RtreeNode *pNode){
116874 RtreeNode *pParent = pNode->pParent;
116875 if( pParent ){
116876 return nodeRowidIndex(pRtree, pParent, pNode->iNode);
116877 }
116878 return -1;
 
116879 }
116880
116881 /*
116882 ** Rtree virtual table module xNext method.
116883 */
116884 static int rtreeNext(sqlite3_vtab_cursor *pVtabCursor){
116885 Rtree *pRtree = (Rtree *)(pVtabCursor->pVtab);
116886 RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
116887 int rc = SQLITE_OK;
 
 
 
 
 
 
116888
116889 if( pCsr->iStrategy==1 ){
116890 /* This "scan" is a direct lookup by rowid. There is no next entry. */
116891 nodeRelease(pRtree, pCsr->pNode);
116892 pCsr->pNode = 0;
116893 }
116894
116895 else if( pCsr->pNode ){
116896 /* Move to the next entry that matches the configured constraints. */
116897 int iHeight = 0;
116898 while( pCsr->pNode ){
116899 RtreeNode *pNode = pCsr->pNode;
116900 int nCell = NCELL(pNode);
@@ -116904,11 +117797,14 @@
116904 if( rc!=SQLITE_OK || !isEof ){
116905 return rc;
116906 }
116907 }
116908 pCsr->pNode = pNode->pParent;
116909 pCsr->iCell = nodeParentIndex(pRtree, pNode);
 
 
 
116910 nodeReference(pCsr->pNode);
116911 nodeRelease(pRtree, pNode);
116912 iHeight++;
116913 }
116914 }
@@ -116972,10 +117868,55 @@
116972 rc = sqlite3_reset(pRtree->pReadRowid);
116973 }
116974 return rc;
116975 }
116976
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116977
116978 /*
116979 ** Rtree virtual table module xFilter method.
116980 */
116981 static int rtreeFilter(
@@ -116990,22 +117931,22 @@
116990 int ii;
116991 int rc = SQLITE_OK;
116992
116993 rtreeReference(pRtree);
116994
116995 sqlite3_free(pCsr->aConstraint);
116996 pCsr->aConstraint = 0;
116997 pCsr->iStrategy = idxNum;
116998
116999 if( idxNum==1 ){
117000 /* Special case - lookup by rowid. */
117001 RtreeNode *pLeaf; /* Leaf on which the required cell resides */
117002 i64 iRowid = sqlite3_value_int64(argv[0]);
117003 rc = findLeafNode(pRtree, iRowid, &pLeaf);
117004 pCsr->pNode = pLeaf;
117005 if( pLeaf && rc==SQLITE_OK ){
117006 pCsr->iCell = nodeRowidIndex(pRtree, pLeaf, iRowid);
 
117007 }
117008 }else{
117009 /* Normal case - r-tree scan. Set up the RtreeCursor.aConstraint array
117010 ** with the configured constraints.
117011 */
@@ -117013,16 +117954,28 @@
117013 pCsr->aConstraint = sqlite3_malloc(sizeof(RtreeConstraint)*argc);
117014 pCsr->nConstraint = argc;
117015 if( !pCsr->aConstraint ){
117016 rc = SQLITE_NOMEM;
117017 }else{
 
117018 assert( (idxStr==0 && argc==0) || strlen(idxStr)==argc*2 );
117019 for(ii=0; ii<argc; ii++){
117020 RtreeConstraint *p = &pCsr->aConstraint[ii];
117021 p->op = idxStr[ii*2];
117022 p->iCoord = idxStr[ii*2+1]-'a';
117023 p->rValue = sqlite3_value_double(argv[ii]);
 
 
 
 
 
 
 
 
 
 
 
117024 }
117025 }
117026 }
117027
117028 if( rc==SQLITE_OK ){
@@ -117078,10 +118031,11 @@
117078 ** = 0x41 ('A')
117079 ** <= 0x42 ('B')
117080 ** < 0x43 ('C')
117081 ** >= 0x44 ('D')
117082 ** > 0x45 ('E')
 
117083 ** ----------------------
117084 **
117085 ** The second of each pair of bytes identifies the coordinate column
117086 ** to which the constraint applies. The leftmost coordinate column
117087 ** is 'a', the second from the left 'b' etc.
@@ -117116,43 +118070,47 @@
117116 */
117117 pIdxInfo->estimatedCost = 10.0;
117118 return SQLITE_OK;
117119 }
117120
117121 if( p->usable && p->iColumn>0 ){
 
 
117122 u8 op = 0;
117123 switch( p->op ){
117124 case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; break;
117125 case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; break;
117126 case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break;
117127 case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; break;
117128 case SQLITE_INDEX_CONSTRAINT_GE: op = RTREE_GE; break;
117129 }
117130 if( op ){
117131 /* Make sure this particular constraint has not been used before.
117132 ** If it has been used before, ignore it.
117133 **
117134 ** A <= or < can be used if there is a prior >= or >.
117135 ** A >= or > can be used if there is a prior < or <=.
117136 ** A <= or < is disqualified if there is a prior <=, <, or ==.
117137 ** A >= or > is disqualified if there is a prior >=, >, or ==.
117138 ** A == is disqualifed if there is any prior constraint.
117139 */
117140 int j, opmsk;
117141 static const unsigned char compatible[] = { 0, 0, 1, 1, 2, 2 };
117142 assert( compatible[RTREE_EQ & 7]==0 );
117143 assert( compatible[RTREE_LT & 7]==1 );
117144 assert( compatible[RTREE_LE & 7]==1 );
117145 assert( compatible[RTREE_GT & 7]==2 );
117146 assert( compatible[RTREE_GE & 7]==2 );
117147 cCol = p->iColumn - 1 + 'a';
117148 opmsk = compatible[op & 7];
117149 for(j=0; j<iIdx; j+=2){
117150 if( zIdxStr[j+1]==cCol && (compatible[zIdxStr[j] & 7] & opmsk)!=0 ){
117151 op = 0;
117152 break;
117153 }
 
 
117154 }
117155 }
117156 if( op ){
117157 assert( iIdx<sizeof(zIdxStr)-1 );
117158 zIdxStr[iIdx++] = op;
@@ -117256,11 +118214,16 @@
117256 int iExclude
117257 ){
117258 int ii;
117259 float overlap = 0.0;
117260 for(ii=0; ii<nCell; ii++){
117261 if( ii!=iExclude ){
 
 
 
 
 
117262 int jj;
117263 float o = 1.0;
117264 for(jj=0; jj<(pRtree->nDim*2); jj+=2){
117265 double x1;
117266 double x2;
@@ -117349,26 +118312,35 @@
117349 /* Select the child node which will be enlarged the least if pCell
117350 ** is inserted into it. Resolve ties by choosing the entry with
117351 ** the smallest area.
117352 */
117353 for(iCell=0; iCell<nCell; iCell++){
 
117354 float growth;
117355 float area;
117356 float overlap = 0.0;
117357 nodeGetCell(pRtree, pNode, iCell, &cell);
117358 growth = cellGrowth(pRtree, &cell, pCell);
117359 area = cellArea(pRtree, &cell);
 
117360 #if VARIANT_RSTARTREE_CHOOSESUBTREE
117361 if( ii==(pRtree->iDepth-1) ){
117362 overlap = cellOverlapEnlargement(pRtree,&cell,pCell,aCell,nCell,iCell);
117363 }
117364 #endif
117365 if( (iCell==0)
117366 || (overlap<fMinOverlap)
117367 || (overlap==fMinOverlap && growth<fMinGrowth)
117368 || (overlap==fMinOverlap && growth==fMinGrowth && area<fMinArea)
117369 ){
 
 
 
 
 
 
 
 
117370 fMinOverlap = overlap;
117371 fMinGrowth = growth;
117372 fMinArea = area;
117373 iBest = cell.iRowid;
117374 }
@@ -117387,29 +118359,34 @@
117387 /*
117388 ** A cell with the same content as pCell has just been inserted into
117389 ** the node pNode. This function updates the bounding box cells in
117390 ** all ancestor elements.
117391 */
117392 static void AdjustTree(
117393 Rtree *pRtree, /* Rtree table */
117394 RtreeNode *pNode, /* Adjust ancestry of this node. */
117395 RtreeCell *pCell /* This cell was just inserted */
117396 ){
117397 RtreeNode *p = pNode;
117398 while( p->pParent ){
117399 RtreeCell cell;
117400 RtreeNode *pParent = p->pParent;
117401 int iCell = nodeParentIndex(pRtree, p);
 
 
 
 
 
117402
117403 nodeGetCell(pRtree, pParent, iCell, &cell);
117404 if( !cellContains(pRtree, &cell, pCell) ){
117405 cellUnion(pRtree, &cell, pCell);
117406 nodeOverwriteCell(pRtree, pParent, &cell, iCell);
117407 }
117408
117409 p = pParent;
117410 }
 
117411 }
117412
117413 /*
117414 ** Write mapping (iRowid->iNode) to the <rtree>_rowid table.
117415 */
@@ -117934,18 +118911,18 @@
117934 nodeZero(pRtree, pNode);
117935 memcpy(&aCell[nCell], pCell, sizeof(RtreeCell));
117936 nCell++;
117937
117938 if( pNode->iNode==1 ){
117939 pRight = nodeNew(pRtree, pNode, 1);
117940 pLeft = nodeNew(pRtree, pNode, 1);
117941 pRtree->iDepth++;
117942 pNode->isDirty = 1;
117943 writeInt16(pNode->zData, pRtree->iDepth);
117944 }else{
117945 pLeft = pNode;
117946 pRight = nodeNew(pRtree, pLeft->pParent, 1);
117947 nodeReference(pLeft);
117948 }
117949
117950 if( !pLeft || !pRight ){
117951 rc = SQLITE_NOMEM;
@@ -117958,12 +118935,16 @@
117958 rc = AssignCells(pRtree, aCell, nCell, pLeft, pRight, &leftbbox, &rightbbox);
117959 if( rc!=SQLITE_OK ){
117960 goto splitnode_out;
117961 }
117962
117963 /* Ensure both child nodes have node numbers assigned to them. */
117964 if( (0==pRight->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pRight)))
 
 
 
 
117965 || (0==pLeft->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pLeft)))
117966 ){
117967 goto splitnode_out;
117968 }
117969
@@ -117975,13 +118956,19 @@
117975 if( rc!=SQLITE_OK ){
117976 goto splitnode_out;
117977 }
117978 }else{
117979 RtreeNode *pParent = pLeft->pParent;
117980 int iCell = nodeParentIndex(pRtree, pLeft);
117981 nodeOverwriteCell(pRtree, pParent, &leftbbox, iCell);
117982 AdjustTree(pRtree, pParent, &leftbbox);
 
 
 
 
 
 
117983 }
117984 if( (rc = rtreeInsertCell(pRtree, pRight->pParent, &rightbbox, iHeight+1)) ){
117985 goto splitnode_out;
117986 }
117987
@@ -118021,44 +119008,73 @@
118021 nodeRelease(pRtree, pLeft);
118022 sqlite3_free(aCell);
118023 return rc;
118024 }
118025
 
 
 
 
 
 
 
 
 
 
 
118026 static int fixLeafParent(Rtree *pRtree, RtreeNode *pLeaf){
118027 int rc = SQLITE_OK;
118028 if( pLeaf->iNode!=1 && pLeaf->pParent==0 ){
118029 sqlite3_bind_int64(pRtree->pReadParent, 1, pLeaf->iNode);
118030 if( sqlite3_step(pRtree->pReadParent)==SQLITE_ROW ){
118031 i64 iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
118032 rc = nodeAcquire(pRtree, iNode, 0, &pLeaf->pParent);
118033 }else{
118034 rc = SQLITE_ERROR;
118035 }
118036 sqlite3_reset(pRtree->pReadParent);
118037 if( rc==SQLITE_OK ){
118038 rc = fixLeafParent(pRtree, pLeaf->pParent);
118039 }
 
 
 
 
 
 
 
 
 
 
 
 
118040 }
118041 return rc;
118042 }
118043
118044 static int deleteCell(Rtree *, RtreeNode *, int, int);
118045
118046 static int removeNode(Rtree *pRtree, RtreeNode *pNode, int iHeight){
118047 int rc;
 
118048 RtreeNode *pParent;
118049 int iCell;
118050
118051 assert( pNode->nRef==1 );
118052
118053 /* Remove the entry in the parent cell. */
118054 iCell = nodeParentIndex(pRtree, pNode);
118055 pParent = pNode->pParent;
118056 pNode->pParent = 0;
118057 if( SQLITE_OK!=(rc = deleteCell(pRtree, pParent, iCell, iHeight+1))
118058 || SQLITE_OK!=(rc = nodeRelease(pRtree, pParent))
118059 ){
 
 
 
 
 
118060 return rc;
118061 }
118062
118063 /* Remove the xxx_node entry. */
118064 sqlite3_bind_int64(pRtree->pDeleteNode, 1, pNode->iNode);
@@ -118084,12 +119100,13 @@
118084 pRtree->pDeleted = pNode;
118085
118086 return SQLITE_OK;
118087 }
118088
118089 static void fixBoundingBox(Rtree *pRtree, RtreeNode *pNode){
118090 RtreeNode *pParent = pNode->pParent;
 
118091 if( pParent ){
118092 int ii;
118093 int nCell = NCELL(pNode);
118094 RtreeCell box; /* Bounding box for pNode */
118095 nodeGetCell(pRtree, pNode, 0, &box);
@@ -118097,21 +119114,25 @@
118097 RtreeCell cell;
118098 nodeGetCell(pRtree, pNode, ii, &cell);
118099 cellUnion(pRtree, &box, &cell);
118100 }
118101 box.iRowid = pNode->iNode;
118102 ii = nodeParentIndex(pRtree, pNode);
118103 nodeOverwriteCell(pRtree, pParent, &box, ii);
118104 fixBoundingBox(pRtree, pParent);
 
 
118105 }
 
118106 }
118107
118108 /*
118109 ** Delete the cell at index iCell of node pNode. After removing the
118110 ** cell, adjust the r-tree data structure if required.
118111 */
118112 static int deleteCell(Rtree *pRtree, RtreeNode *pNode, int iCell, int iHeight){
 
118113 int rc;
118114
118115 if( SQLITE_OK!=(rc = fixLeafParent(pRtree, pNode)) ){
118116 return rc;
118117 }
@@ -118124,18 +119145,17 @@
118124 /* If the node is not the tree root and now has less than the minimum
118125 ** number of cells, remove it from the tree. Otherwise, update the
118126 ** cell in the parent node so that it tightly contains the updated
118127 ** node.
118128 */
118129 if( pNode->iNode!=1 ){
118130 RtreeNode *pParent = pNode->pParent;
118131 if( (pParent->iNode!=1 || NCELL(pParent)!=1)
118132 && (NCELL(pNode)<RTREE_MINCELLS(pRtree))
118133 ){
118134 rc = removeNode(pRtree, pNode, iHeight);
118135 }else{
118136 fixBoundingBox(pRtree, pNode);
118137 }
118138 }
118139
118140 return rc;
118141 }
@@ -118214,11 +119234,11 @@
118214 rc = parentWrite(pRtree, p->iRowid, pNode->iNode);
118215 }
118216 }
118217 }
118218 if( rc==SQLITE_OK ){
118219 fixBoundingBox(pRtree, pNode);
118220 }
118221 for(; rc==SQLITE_OK && ii<nCell; ii++){
118222 /* Find a node to store this cell in. pNode->iNode currently contains
118223 ** the height of the sub-tree headed by the cell.
118224 */
@@ -118268,15 +119288,17 @@
118268 }
118269 #else
118270 rc = SplitNode(pRtree, pNode, pCell, iHeight);
118271 #endif
118272 }else{
118273 AdjustTree(pRtree, pNode, pCell);
118274 if( iHeight==0 ){
118275 rc = rowidWrite(pRtree, pCell->iRowid, pNode->iNode);
118276 }else{
118277 rc = parentWrite(pRtree, pCell->iRowid, pNode->iNode);
 
 
118278 }
118279 }
118280 return rc;
118281 }
118282
@@ -118342,11 +119364,10 @@
118342 int rc = SQLITE_OK;
118343
118344 rtreeReference(pRtree);
118345
118346 assert(nData>=1);
118347 assert(hashIsEmpty(pRtree));
118348
118349 /* If azData[0] is not an SQL NULL value, it is the rowid of a
118350 ** record to delete from the r-tree table. The following block does
118351 ** just that.
118352 */
@@ -118368,12 +119389,14 @@
118368 }
118369
118370 /* Delete the cell in question from the leaf node. */
118371 if( rc==SQLITE_OK ){
118372 int rc2;
118373 iCell = nodeRowidIndex(pRtree, pLeaf, iDelete);
118374 rc = deleteCell(pRtree, pLeaf, iCell, 0);
 
 
118375 rc2 = nodeRelease(pRtree, pLeaf);
118376 if( rc==SQLITE_OK ){
118377 rc = rc2;
118378 }
118379 }
@@ -118391,23 +119414,24 @@
118391 **
118392 ** This is equivalent to copying the contents of the child into
118393 ** the root node (the operation that Gutman's paper says to perform
118394 ** in this scenario).
118395 */
118396 if( rc==SQLITE_OK && pRtree->iDepth>0 ){
118397 if( rc==SQLITE_OK && NCELL(pRoot)==1 ){
118398 RtreeNode *pChild;
118399 i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
118400 rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
118401 if( rc==SQLITE_OK ){
118402 rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
118403 }
118404 if( rc==SQLITE_OK ){
118405 pRtree->iDepth--;
118406 writeInt16(pRoot->zData, pRtree->iDepth);
118407 pRoot->isDirty = 1;
118408 }
 
118409 }
118410 }
118411
118412 /* Re-insert the contents of any underfull nodes removed from the tree. */
118413 for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){
@@ -118693,11 +119717,11 @@
118693 ){
118694 int rc = SQLITE_OK;
118695 Rtree *pRtree;
118696 int nDb; /* Length of string argv[1] */
118697 int nName; /* Length of string argv[2] */
118698 int eCoordType = (int)pAux;
118699
118700 const char *aErrMsg[] = {
118701 0, /* 0 */
118702 "Wrong number of columns for an rtree table", /* 1 */
118703 "Too few columns for an rtree table", /* 2 */
@@ -118839,16 +119863,14 @@
118839 ** Register the r-tree module with database handle db. This creates the
118840 ** virtual table module "rtree" and the debugging/analysis scalar
118841 ** function "rtreenode".
118842 */
118843 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db){
118844 int rc = SQLITE_OK;
 
118845
118846 if( rc==SQLITE_OK ){
118847 int utf8 = SQLITE_UTF8;
118848 rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
118849 }
118850 if( rc==SQLITE_OK ){
118851 int utf8 = SQLITE_UTF8;
118852 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
118853 }
118854 if( rc==SQLITE_OK ){
@@ -118860,10 +119882,74 @@
118860 rc = sqlite3_create_module_v2(db, "rtree_i32", &rtreeModule, c, 0);
118861 }
118862
118863 return rc;
118864 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118865
118866 #if !SQLITE_CORE
118867 SQLITE_API int sqlite3_extension_init(
118868 sqlite3 *db,
118869 char **pzErrMsg,
118870
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.7.3. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a one translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% are more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -352,19 +352,25 @@
352 # define SQLITE_INT_TO_PTR(X) ((void*)(X))
353 # define SQLITE_PTR_TO_INT(X) ((int)(X))
354 #endif
355
356 /*
357 ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
358 ** 0 means mutexes are permanently disable and the library is never
359 ** threadsafe. 1 means the library is serialized which is the highest
360 ** level of threadsafety. 2 means the libary is multithreaded - multiple
361 ** threads can use SQLite as long as no two threads try to use the same
362 ** database connection at the same time.
363 **
364 ** Older versions of SQLite used an optional THREADSAFE macro.
365 ** We support that for legacy.
366 */
367 #if !defined(SQLITE_THREADSAFE)
368 #if defined(THREADSAFE)
369 # define SQLITE_THREADSAFE THREADSAFE
370 #else
371 # define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */
372 #endif
373 #endif
374
375 /*
376 ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
@@ -642,13 +648,13 @@
648 **
649 ** See also: [sqlite3_libversion()],
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.3"
654 #define SQLITE_VERSION_NUMBER 3007003
655 #define SQLITE_SOURCE_ID "2010-10-04 23:55:51 ece641eb8951c6314cedbdb3243f91cb199c3239"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1292,19 +1298,23 @@
1298 ** object once the object has been registered.
1299 **
1300 ** The zName field holds the name of the VFS module. The name must
1301 ** be unique across all VFS modules.
1302 **
1303 ** ^SQLite guarantees that the zFilename parameter to xOpen
1304 ** is either a NULL pointer or string obtained
1305 ** from xFullPathname() with an optional suffix added.
1306 ** ^If a suffix is added to the zFilename parameter, it will
1307 ** consist of a single "-" character followed by no more than
1308 ** 10 alphanumeric and/or "-" characters.
1309 ** ^SQLite further guarantees that
1310 ** the string will be valid and unchanged until xClose() is
1311 ** called. Because of the previous sentence,
1312 ** the [sqlite3_file] can safely store a pointer to the
1313 ** filename if it needs to remember the filename for some reason.
1314 ** If the zFilename parameter to xOpen is a NULL pointer then xOpen
1315 ** must invent its own temporary name for the file. ^Whenever the
1316 ** xFilename parameter is NULL it will also be the case that the
1317 ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
1318 **
1319 ** The flags argument to xOpen() includes all bits set in
1320 ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
@@ -1311,11 +1321,11 @@
1321 ** or [sqlite3_open16()] is used, then flags includes at least
1322 ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
1323 ** If xOpen() opens a file read-only then it sets *pOutFlags to
1324 ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
1325 **
1326 ** ^(SQLite will also add one of the following flags to the xOpen()
1327 ** call, depending on the object being opened:
1328 **
1329 ** <ul>
1330 ** <li> [SQLITE_OPEN_MAIN_DB]
1331 ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
@@ -1322,11 +1332,12 @@
1332 ** <li> [SQLITE_OPEN_TEMP_DB]
1333 ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
1334 ** <li> [SQLITE_OPEN_TRANSIENT_DB]
1335 ** <li> [SQLITE_OPEN_SUBJOURNAL]
1336 ** <li> [SQLITE_OPEN_MASTER_JOURNAL]
1337 ** <li> [SQLITE_OPEN_WAL]
1338 ** </ul>)^
1339 **
1340 ** The file I/O implementation can use the object type flags to
1341 ** change the way it deals with files. For example, an application
1342 ** that does not care about crash recovery or rollback might make
1343 ** the open of a journal file a no-op. Writes to this journal would
@@ -1341,39 +1352,40 @@
1352 ** <li> [SQLITE_OPEN_DELETEONCLOSE]
1353 ** <li> [SQLITE_OPEN_EXCLUSIVE]
1354 ** </ul>
1355 **
1356 ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
1357 ** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE]
1358 ** will be set for TEMP databases and their journals, transient
1359 ** databases, and subjournals.
1360 **
1361 ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
1362 ** with the [SQLITE_OPEN_CREATE] flag, which are both directly
1363 ** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
1364 ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
1365 ** SQLITE_OPEN_CREATE, is used to indicate that file should always
1366 ** be created, and that it is an error if it already exists.
1367 ** It is <i>not</i> used to indicate the file should be opened
1368 ** for exclusive access.
1369 **
1370 ** ^At least szOsFile bytes of memory are allocated by SQLite
1371 ** to hold the [sqlite3_file] structure passed as the third
1372 ** argument to xOpen. The xOpen method does not have to
1373 ** allocate the structure; it should just fill it in. Note that
1374 ** the xOpen method must set the sqlite3_file.pMethods to either
1375 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
1376 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
1377 ** element will be valid after xOpen returns regardless of the success
1378 ** or failure of the xOpen call.
1379 **
1380 ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
1381 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
1382 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
1383 ** to test whether a file is at least readable. The file can be a
1384 ** directory.
1385 **
1386 ** ^SQLite will always allocate at least mxPathname+1 bytes for the
1387 ** output buffer xFullPathname. The exact size of the output buffer
1388 ** is also passed as a parameter to both methods. If the output buffer
1389 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
1390 ** handled as a fatal error by SQLite, vfs implementations should endeavor
1391 ** to prevent this by setting mxPathname to a sufficiently large value.
@@ -1383,14 +1395,14 @@
1395 ** included in the VFS structure for completeness.
1396 ** The xRandomness() function attempts to return nBytes bytes
1397 ** of good-quality randomness into zOut. The return value is
1398 ** the actual number of bytes of randomness obtained.
1399 ** The xSleep() method causes the calling thread to sleep for at
1400 ** least the number of microseconds given. ^The xCurrentTime()
1401 ** method returns a Julian Day Number for the current date and time as
1402 ** a floating point value.
1403 ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
1404 ** Day Number multipled by 86400000 (the number of milliseconds in
1405 ** a 24-hour day).
1406 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
1407 ** date and time if that method is available (if iVersion is 2 or
1408 ** greater and the function pointer is not NULL) and will fall back
@@ -1783,11 +1795,11 @@
1795 ** statistics. ^(When memory allocation statistics are disabled, the
1796 ** following SQLite interfaces become non-operational:
1797 ** <ul>
1798 ** <li> [sqlite3_memory_used()]
1799 ** <li> [sqlite3_memory_highwater()]
1800 ** <li> [sqlite3_soft_heap_limit64()]
1801 ** <li> [sqlite3_status()]
1802 ** </ul>)^
1803 ** ^Memory allocation statistics are enabled by default unless SQLite is
1804 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1805 ** allocation statistics are disabled by default.
@@ -1797,19 +1809,18 @@
1809 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1810 ** scratch memory. There are three arguments: A pointer an 8-byte
1811 ** aligned memory buffer from which the scrach allocations will be
1812 ** drawn, the size of each scratch allocation (sz),
1813 ** and the maximum number of scratch allocations (N). The sz
1814 ** argument must be a multiple of 16.
 
1815 ** The first argument must be a pointer to an 8-byte aligned buffer
1816 ** of at least sz*N bytes of memory.
1817 ** ^SQLite will use no more than two scratch buffers per thread. So
1818 ** N should be set to twice the expected maximum number of threads.
1819 ** ^SQLite will never require a scratch buffer that is more than 6
1820 ** times the database page size. ^If SQLite needs needs additional
1821 ** scratch memory beyond what is provided by this configuration option, then
1822 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
1823 **
1824 ** <dt>SQLITE_CONFIG_PAGECACHE</dt>
1825 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1826 ** the database page cache with the default page cache implemenation.
@@ -1825,12 +1836,11 @@
1836 ** argument should point to an allocation of at least sz*N bytes of memory.
1837 ** ^SQLite will use the memory provided by the first argument to satisfy its
1838 ** memory needs for the first N pages that it adds to cache. ^If additional
1839 ** page cache memory is needed beyond what is provided by this option, then
1840 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1841 ** The pointer in the first argument must
 
1842 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1843 ** will be undefined.</dd>
1844 **
1845 ** <dt>SQLITE_CONFIG_HEAP</dt>
1846 ** <dd> ^This option specifies a static memory buffer that SQLite will use
@@ -1955,12 +1965,18 @@
1965 ** size of each lookaside buffer slot. ^The third argument is the number of
1966 ** slots. The size of the buffer in the first argument must be greater than
1967 ** or equal to the product of the second and third arguments. The buffer
1968 ** must be aligned to an 8-byte boundary. ^If the second argument to
1969 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
1970 ** rounded down to the next smaller multiple of 8. ^(The lookaside memory
1971 ** configuration for a database connection can only be changed when that
1972 ** connection is not currently using lookaside memory, or in other words
1973 ** when the "current value" returned by
1974 ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
1975 ** Any attempt to change the lookaside memory configuration when lookaside
1976 ** memory is in use leaves the configuration unchanged and returns
1977 ** [SQLITE_BUSY].)^</dd>
1978 **
1979 ** </dl>
1980 */
1981 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1982
@@ -2260,10 +2276,13 @@
2276 */
2277 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
2278
2279 /*
2280 ** CAPI3REF: Convenience Routines For Running Queries
2281 **
2282 ** This is a legacy interface that is preserved for backwards compatibility.
2283 ** Use of this interface is not recommended.
2284 **
2285 ** Definition: A <b>result table</b> is memory data structure created by the
2286 ** [sqlite3_get_table()] interface. A result table records the
2287 ** complete query results from one or more queries.
2288 **
@@ -2281,11 +2300,11 @@
2300 **
2301 ** A result table might consist of one or more memory allocations.
2302 ** It is not safe to pass a result table directly to [sqlite3_free()].
2303 ** A result table should be deallocated using [sqlite3_free_table()].
2304 **
2305 ** ^(As an example of the result table format, suppose a query result
2306 ** is as follows:
2307 **
2308 ** <blockquote><pre>
2309 ** Name | Age
2310 ** -----------------------
@@ -2305,31 +2324,31 @@
2324 ** azResult&#91;3] = "43";
2325 ** azResult&#91;4] = "Bob";
2326 ** azResult&#91;5] = "28";
2327 ** azResult&#91;6] = "Cindy";
2328 ** azResult&#91;7] = "21";
2329 ** </pre></blockquote>)^
2330 **
2331 ** ^The sqlite3_get_table() function evaluates one or more
2332 ** semicolon-separated SQL statements in the zero-terminated UTF-8
2333 ** string of its 2nd parameter and returns a result table to the
2334 ** pointer given in its 3rd parameter.
2335 **
2336 ** After the application has finished with the result from sqlite3_get_table(),
2337 ** it must pass the result table pointer to sqlite3_free_table() in order to
2338 ** release the memory that was malloced. Because of the way the
2339 ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
2340 ** function must not try to call [sqlite3_free()] directly. Only
2341 ** [sqlite3_free_table()] is able to release the memory properly and safely.
2342 **
2343 ** The sqlite3_get_table() interface is implemented as a wrapper around
2344 ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
2345 ** to any internal data structures of SQLite. It uses only the public
2346 ** interface defined here. As a consequence, errors that occur in the
2347 ** wrapper layer outside of the internal [sqlite3_exec()] call are not
2348 ** reflected in subsequent calls to [sqlite3_errcode()] or
2349 ** [sqlite3_errmsg()].
2350 */
2351 SQLITE_API int sqlite3_get_table(
2352 sqlite3 *db, /* An open database */
2353 const char *zSql, /* SQL to be evaluated */
2354 char ***pazResult, /* Results of the query */
@@ -2477,11 +2496,13 @@
2496 ** by sqlite3_realloc() and the prior allocation is freed.
2497 ** ^If sqlite3_realloc() returns NULL, then the prior allocation
2498 ** is not freed.
2499 **
2500 ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
2501 ** is always aligned to at least an 8 byte boundary, or to a
2502 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
2503 ** option is used.
2504 **
2505 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
2506 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
2507 ** implementation of these routines to be omitted. That capability
2508 ** is no longer provided. Only built-in memory allocators can be used.
@@ -2735,21 +2756,32 @@
2756 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2757
2758 /*
2759 ** CAPI3REF: Query Progress Callbacks
2760 **
2761 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2762 ** function X to be invoked periodically during long running calls to
2763 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2764 ** database connection D. An example use for this
2765 ** interface is to keep a GUI updated during a large query.
2766 **
2767 ** ^The parameter P is passed through as the only parameter to the
2768 ** callback function X. ^The parameter N is the number of
2769 ** [virtual machine instructions] that are evaluated between successive
2770 ** invocations of the callback X.
2771 **
2772 ** ^Only a single progress handler may be defined at one time per
2773 ** [database connection]; setting a new progress handler cancels the
2774 ** old one. ^Setting parameter X to NULL disables the progress handler.
2775 ** ^The progress handler is also disabled by setting N to a value less
2776 ** than 1.
2777 **
2778 ** ^If the progress callback returns non-zero, the operation is
2779 ** interrupted. This feature can be used to implement a
2780 ** "Cancel" button on a GUI progress dialog box.
2781 **
2782 ** The progress handler callback must not do anything that will modify
2783 ** the database connection that invoked the progress handler.
2784 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
2785 ** database connections for the meaning of "modify" in this paragraph.
2786 **
2787 */
@@ -2804,11 +2836,11 @@
2836 ** </dl>
2837 **
2838 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
2839 ** combinations shown above or one of the combinations shown above combined
2840 ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
2841 ** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags,
2842 ** then the behavior is undefined.
2843 **
2844 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
2845 ** opens in the multi-thread [threading mode] as long as the single-thread
2846 ** mode has not been set at compile-time or start-time. ^If the
@@ -2929,21 +2961,26 @@
2961 ** ^(This interface allows the size of various constructs to be limited
2962 ** on a connection by connection basis. The first parameter is the
2963 ** [database connection] whose limit is to be set or queried. The
2964 ** second parameter is one of the [limit categories] that define a
2965 ** class of constructs to be size limited. The third parameter is the
2966 ** new limit for that construct.)^
2967 **
2968 ** ^If the new limit is a negative number, the limit is unchanged.
2969 ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
2970 ** [limits | hard upper bound]
2971 ** set at compile-time by a C preprocessor macro called
2972 ** [limits | SQLITE_MAX_<i>NAME</i>].
2973 ** (The "_LIMIT_" in the name is changed to "_MAX_".))^
2974 ** ^Attempts to increase a limit above its hard upper bound are
2975 ** silently truncated to the hard upper bound.
2976 **
2977 ** ^Regardless of whether or not the limit was changed, the
2978 ** [sqlite3_limit()] interface returns the prior value of the limit.
2979 ** ^Hence, to find the current value of a limit without changing it,
2980 ** simply invoke this interface with the third parameter set to -1.
2981 **
2982 ** Run-time limits are intended for use in applications that manage
2983 ** both their own internal database and also databases that are controlled
2984 ** by untrusted external sources. An example application might be a
2985 ** web browser that has its own databases for storing history and
2986 ** separate databases controlled by JavaScript applications downloaded
@@ -2968,11 +3005,11 @@
3005 ** The synopsis of the meanings of the various limits is shown below.
3006 ** Additional information is available at [limits | Limits in SQLite].
3007 **
3008 ** <dl>
3009 ** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
3010 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
3011 **
3012 ** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
3013 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
3014 **
3015 ** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
@@ -2986,11 +3023,13 @@
3023 ** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
3024 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
3025 **
3026 ** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
3027 ** <dd>The maximum number of instructions in a virtual machine program
3028 ** used to implement an SQL statement. This limit is not currently
3029 ** enforced, though that might be added in some future release of
3030 ** SQLite.</dd>)^
3031 **
3032 ** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
3033 ** <dd>The maximum number of arguments on a function.</dd>)^
3034 **
3035 ** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
@@ -2999,12 +3038,11 @@
3038 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
3039 ** <dd>The maximum length of the pattern argument to the [LIKE] or
3040 ** [GLOB] operators.</dd>)^
3041 **
3042 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
3043 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
 
3044 **
3045 ** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
3046 ** <dd>The maximum depth of recursion for triggers.</dd>)^
3047 ** </dl>
3048 */
@@ -3072,16 +3110,11 @@
3110 **
3111 ** <ol>
3112 ** <li>
3113 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
3114 ** always used to do, [sqlite3_step()] will automatically recompile the SQL
3115 ** statement and try to run it again.
 
 
 
 
 
3116 ** </li>
3117 **
3118 ** <li>
3119 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
3120 ** [error codes] or [extended error codes]. ^The legacy behavior was that
@@ -3090,15 +3123,20 @@
3123 ** in order to find the underlying cause of the problem. With the "v2" prepare
3124 ** interfaces, the underlying reason for the error is returned immediately.
3125 ** </li>
3126 **
3127 ** <li>
3128 ** ^If the specific value bound to [parameter | host parameter] in the
3129 ** WHERE clause might influence the choice of query plan for a statement,
3130 ** then the statement will be automatically recompiled, as if there had been
3131 ** a schema change, on the first [sqlite3_step()] call following any change
3132 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3133 ** ^The specific value of WHERE-clause [parameter] might influence the
3134 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3135 ** or [GLOB] operator or if the parameter is compared to an indexed column
3136 ** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled.
3137 ** the
3138 ** </li>
3139 ** </ol>
3140 */
3141 SQLITE_API int sqlite3_prepare(
3142 sqlite3 *db, /* Database handle */
@@ -3161,11 +3199,11 @@
3199 ** or if SQLite is run in one of reduced mutex modes
3200 ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
3201 ** then there is no distinction between protected and unprotected
3202 ** sqlite3_value objects and they can be used interchangeably. However,
3203 ** for maximum code portability it is recommended that applications
3204 ** still make the distinction between protected and unprotected
3205 ** sqlite3_value objects even when not strictly required.
3206 **
3207 ** ^The sqlite3_value objects that are passed as parameters into the
3208 ** implementation of [application-defined SQL functions] are protected.
3209 ** ^The sqlite3_value object returned by
@@ -3356,10 +3394,12 @@
3394 ** CAPI3REF: Number Of Columns In A Result Set
3395 **
3396 ** ^Return the number of columns in the result set returned by the
3397 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3398 ** statement that does not return data (for example an [UPDATE]).
3399 **
3400 ** See also: [sqlite3_data_count()]
3401 */
3402 SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
3403
3404 /*
3405 ** CAPI3REF: Column Names In A Result Set
@@ -3546,12 +3586,18 @@
3586 SQLITE_API int sqlite3_step(sqlite3_stmt*);
3587
3588 /*
3589 ** CAPI3REF: Number of columns in a result set
3590 **
3591 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
3592 ** current row of the result set of [prepared statement] P.
3593 ** ^If prepared statement P does not have results ready to return
3594 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
3595 ** interfaces) then sqlite3_data_count(P) returns 0.
3596 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
3597 **
3598 ** See also: [sqlite3_column_count()]
3599 */
3600 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
3601
3602 /*
3603 ** CAPI3REF: Fundamental Datatypes
@@ -3627,22 +3673,30 @@
3673 ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
3674 ** the string to UTF-8 and then returns the number of bytes.
3675 ** ^If the result is a numeric value then sqlite3_column_bytes() uses
3676 ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
3677 ** the number of bytes in that string.
3678 ** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
3679 **
3680 ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
3681 ** routine returns the number of bytes in that BLOB or string.
3682 ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
3683 ** the string to UTF-16 and then returns the number of bytes.
3684 ** ^If the result is a numeric value then sqlite3_column_bytes16() uses
3685 ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
3686 ** the number of bytes in that string.
3687 ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
3688 **
3689 ** ^The values returned by [sqlite3_column_bytes()] and
3690 ** [sqlite3_column_bytes16()] do not include the zero terminators at the end
3691 ** of the string. ^For clarity: the values returned by
3692 ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
3693 ** bytes in the string, not the number of characters.
3694 **
3695 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
3696 ** even empty strings, are always zero terminated. ^The return
3697 ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
 
 
 
 
 
3698 **
3699 ** ^The object returned by [sqlite3_column_value()] is an
3700 ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object
3701 ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
3702 ** If the [unprotected sqlite3_value] object returned by
@@ -3683,14 +3737,14 @@
3737 ** and atof(). SQLite does not really use these functions. It has its
3738 ** own equivalent internal routines. The atoi() and atof() names are
3739 ** used in the table for brevity and because they are familiar to most
3740 ** C programmers.
3741 **
3742 ** Note that when type conversions occur, pointers returned by prior
3743 ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
3744 ** sqlite3_column_text16() may be invalidated.
3745 ** Type conversions and pointer invalidations might occur
3746 ** in the following cases:
3747 **
3748 ** <ul>
3749 ** <li> The initial content is a BLOB and sqlite3_column_text() or
3750 ** sqlite3_column_text16() is called. A zero-terminator might
@@ -3699,26 +3753,26 @@
3753 ** sqlite3_column_text16() is called. The content must be converted
3754 ** to UTF-16.</li>
3755 ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
3756 ** sqlite3_column_text() is called. The content must be converted
3757 ** to UTF-8.</li>
3758 ** </ul>
3759 **
3760 ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
3761 ** not invalidate a prior pointer, though of course the content of the buffer
3762 ** that the prior pointer references will have been modified. Other kinds
3763 ** of conversion are done in place when it is possible, but sometimes they
3764 ** are not possible and in those cases prior pointers are invalidated.
3765 **
3766 ** The safest and easiest to remember policy is to invoke these routines
3767 ** in one of the following ways:
3768 **
3769 ** <ul>
3770 ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
3771 ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
3772 ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
3773 ** </ul>
3774 **
3775 ** In other words, you should call sqlite3_column_text(),
3776 ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
3777 ** into the desired format, then invoke sqlite3_column_bytes() or
3778 ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
@@ -3752,21 +3806,30 @@
3806
3807 /*
3808 ** CAPI3REF: Destroy A Prepared Statement Object
3809 **
3810 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
3811 ** ^If the most recent evaluation of the statement encountered no errors or
3812 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
3813 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
3814 ** sqlite3_finalize(S) returns the appropriate [error code] or
3815 ** [extended error code].
3816 **
3817 ** ^The sqlite3_finalize(S) routine can be called at any point during
3818 ** the life cycle of [prepared statement] S:
3819 ** before statement S is ever evaluated, after
3820 ** one or more calls to [sqlite3_reset()], or after any call
3821 ** to [sqlite3_step()] regardless of whether or not the statement has
3822 ** completed execution.
3823 **
3824 ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
3825 **
3826 ** The application must finalize every [prepared statement] in order to avoid
3827 ** resource leaks. It is a grievous error for the application to try to use
3828 ** a prepared statement after it has been finalized. Any use of a prepared
3829 ** statement after it has been finalized can result in undefined and
3830 ** undesirable behavior such as segfaults and heap corruption.
3831 */
3832 SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
3833
3834 /*
3835 ** CAPI3REF: Reset A Prepared Statement Object
@@ -3798,40 +3861,42 @@
3861 ** CAPI3REF: Create Or Redefine SQL Functions
3862 ** KEYWORDS: {function creation routines}
3863 ** KEYWORDS: {application-defined SQL function}
3864 ** KEYWORDS: {application-defined SQL functions}
3865 **
3866 ** ^These functions (collectively known as "function creation routines")
3867 ** are used to add SQL functions or aggregates or to redefine the behavior
3868 ** of existing SQL functions or aggregates. The only differences between
3869 ** these routines are the text encoding expected for
3870 ** the the second parameter (the name of the function being created)
3871 ** and the presence or absence of a destructor callback for
3872 ** the application data pointer.
3873 **
3874 ** ^The first parameter is the [database connection] to which the SQL
3875 ** function is to be added. ^If an application uses more than one database
3876 ** connection then application-defined SQL functions must be added
3877 ** to each database connection separately.
3878 **
3879 ** ^The second parameter is the name of the SQL function to be created or
3880 ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
3881 ** representation, exclusive of the zero-terminator. ^Note that the name
3882 ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
3883 ** ^Any attempt to create a function with a longer name
3884 ** will result in [SQLITE_MISUSE] being returned.
3885 **
3886 ** ^The third parameter (nArg)
3887 ** is the number of arguments that the SQL function or
3888 ** aggregate takes. ^If this parameter is -1, then the SQL function or
3889 ** aggregate may take any number of arguments between 0 and the limit
3890 ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
3891 ** parameter is less than -1 or greater than 127 then the behavior is
3892 ** undefined.
3893 **
3894 ** ^The fourth parameter, eTextRep, specifies what
3895 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3896 ** its parameters. Every SQL function implementation must be able to work
3897 ** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3898 ** more efficient with one encoding than another. ^An application may
3899 ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
3900 ** times with the same function but with different values of eTextRep.
3901 ** ^When multiple implementations of the same function are available, SQLite
3902 ** will pick the one that involves the least amount of data conversion.
@@ -3839,17 +3904,25 @@
3904 ** encoding is used, then the fourth argument should be [SQLITE_ANY].
3905 **
3906 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
3907 ** function can gain access to this pointer using [sqlite3_user_data()].)^
3908 **
3909 ** ^The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
3910 ** pointers to C-language functions that implement the SQL function or
3911 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
3912 ** callback only; NULL pointers must be passed as the xStep and xFinal
3913 ** parameters. ^An aggregate SQL function requires an implementation of xStep
3914 ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
3915 ** SQL function or aggregate, pass NULL poiners for all three function
3916 ** callbacks.
3917 **
3918 ** ^If the tenth parameter to sqlite3_create_function_v2() is not NULL,
3919 ** then it is invoked when the function is deleted, either by being
3920 ** overloaded or when the database connection closes.
3921 ** ^When the destructure callback of the tenth parameter is invoked, it
3922 ** is passed a single argument which is a copy of the pointer which was
3923 ** the fifth parameter to sqlite3_create_function_v2().
3924 **
3925 ** ^It is permitted to register multiple implementations of the same
3926 ** functions with the same name but with either differing numbers of
3927 ** arguments or differing preferred text encodings. ^SQLite will use
3928 ** the implementation that most closely matches the way in which the
@@ -3861,15 +3934,10 @@
3934 ** ^A function where the encoding difference is between UTF16le and UTF16be
3935 ** is a closer match than a function where the encoding difference is
3936 ** between UTF8 and UTF16.
3937 **
3938 ** ^Built-in functions may be overloaded by new application-defined functions.
 
 
 
 
 
3939 **
3940 ** ^An application-defined function is permitted to call other
3941 ** SQLite interfaces. However, such calls must not
3942 ** close the database connection nor finalize or reset the prepared
3943 ** statement in which the function is running.
@@ -3891,10 +3959,21 @@
3959 int eTextRep,
3960 void *pApp,
3961 void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
3962 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
3963 void (*xFinal)(sqlite3_context*)
3964 );
3965 SQLITE_API int sqlite3_create_function_v2(
3966 sqlite3 *db,
3967 const char *zFunctionName,
3968 int nArg,
3969 int eTextRep,
3970 void *pApp,
3971 void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
3972 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
3973 void (*xFinal)(sqlite3_context*),
3974 void(*xDestroy)(void*)
3975 );
3976
3977 /*
3978 ** CAPI3REF: Text Encodings
3979 **
@@ -4238,73 +4317,97 @@
4317 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
4318
4319 /*
4320 ** CAPI3REF: Define New Collating Sequences
4321 **
4322 ** ^These functions add, remove, or modify a [collation] associated
4323 ** with the [database connection] specified as the first argument.
4324 **
4325 ** ^The name of the collation is a UTF-8 string
4326 ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
4327 ** and a UTF-16 string in native byte order for sqlite3_create_collation16().
4328 ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
4329 ** considered to be the same name.
4330 **
4331 ** ^(The third argument (eTextRep) must be one of the constants:
4332 ** <ul>
4333 ** <li> [SQLITE_UTF8],
4334 ** <li> [SQLITE_UTF16LE],
4335 ** <li> [SQLITE_UTF16BE],
4336 ** <li> [SQLITE_UTF16], or
4337 ** <li> [SQLITE_UTF16_ALIGNED].
4338 ** </ul>)^
4339 ** ^The eTextRep argument determines the encoding of strings passed
4340 ** to the collating function callback, xCallback.
4341 ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
4342 ** force strings to be UTF16 with native byte order.
4343 ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
4344 ** on an even byte address.
4345 **
4346 ** ^The fourth argument, pArg, is a application data pointer that is passed
4347 ** through as the first argument to the collating function callback.
4348 **
4349 ** ^The fifth argument, xCallback, is a pointer to the collating function.
4350 ** ^Multiple collating functions can be registered using the same name but
4351 ** with different eTextRep parameters and SQLite will use whichever
4352 ** function requires the least amount of data transformation.
4353 ** ^If the xCallback argument is NULL then the collating function is
4354 ** deleted. ^When all collating functions having the same name are deleted,
4355 ** that collation is no longer usable.
4356 **
4357 ** ^The collating function callback is invoked with a copy of the pArg
4358 ** application data pointer and with two strings in the encoding specified
4359 ** by the eTextRep argument. The collating function must return an
4360 ** integer that is negative, zero, or positive
4361 ** if the first string is less than, equal to, or greater than the second,
4362 ** respectively. A collating function must alway return the same answer
4363 ** given the same inputs. If two or more collating functions are registered
4364 ** to the same collation name (using different eTextRep values) then all
4365 ** must give an equivalent answer when invoked with equivalent strings.
4366 ** The collating function must obey the following properties for all
4367 ** strings A, B, and C:
4368 **
4369 ** <ol>
4370 ** <li> If A==B then B==A.
4371 ** <li> If A==B and B==C then A==C.
4372 ** <li> If A&lt;B THEN B&gt;A.
4373 ** <li> If A&lt;B and B&lt;C then A&lt;C.
4374 ** </ol>
4375 **
4376 ** If a collating function fails any of the above constraints and that
4377 ** collating function is registered and used, then the behavior of SQLite
4378 ** is undefined.
4379 **
4380 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
4381 ** with the addition that the xDestroy callback is invoked on pArg when
4382 ** the collating function is deleted.
4383 ** ^Collating functions are deleted when they are overridden by later
4384 ** calls to the collation creation functions or when the
4385 ** [database connection] is closed using [sqlite3_close()].
 
 
4386 **
4387 ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
4388 */
4389 SQLITE_API int sqlite3_create_collation(
4390 sqlite3*,
4391 const char *zName,
4392 int eTextRep,
4393 void *pArg,
4394 int(*xCompare)(void*,int,const void*,int,const void*)
4395 );
4396 SQLITE_API int sqlite3_create_collation_v2(
4397 sqlite3*,
4398 const char *zName,
4399 int eTextRep,
4400 void *pArg,
4401 int(*xCompare)(void*,int,const void*,int,const void*),
4402 void(*xDestroy)(void*)
4403 );
4404 SQLITE_API int sqlite3_create_collation16(
4405 sqlite3*,
4406 const void *zName,
4407 int eTextRep,
4408 void *pArg,
4409 int(*xCompare)(void*,int,const void*,int,const void*)
4410 );
4411
4412 /*
4413 ** CAPI3REF: Collation Needed Callbacks
@@ -4389,20 +4492,23 @@
4492 #endif
4493
4494 /*
4495 ** CAPI3REF: Suspend Execution For A Short Time
4496 **
4497 ** The sqlite3_sleep() function causes the current thread to suspend execution
4498 ** for at least a number of milliseconds specified in its parameter.
4499 **
4500 ** If the operating system does not support sleep requests with
4501 ** millisecond time resolution, then the time will be rounded up to
4502 ** the nearest second. The number of milliseconds of sleep actually
4503 ** requested from the operating system is returned.
4504 **
4505 ** ^SQLite implements this interface by calling the xSleep()
4506 ** method of the default [sqlite3_vfs] object. If the xSleep() method
4507 ** of the default VFS is not implemented correctly, or not implemented at
4508 ** all, then the behavior of sqlite3_sleep() may deviate from the description
4509 ** in the previous paragraphs.
4510 */
4511 SQLITE_API int sqlite3_sleep(int);
4512
4513 /*
4514 ** CAPI3REF: Name Of The Folder Holding Temporary Files
@@ -4620,44 +4726,77 @@
4726 ** of heap memory by deallocating non-essential memory allocations
4727 ** held by the database library. Memory used to cache database
4728 ** pages to improve performance is an example of non-essential memory.
4729 ** ^sqlite3_release_memory() returns the number of bytes actually freed,
4730 ** which might be more or less than the amount requested.
4731 ** ^The sqlite3_release_memory() routine is a no-op returning zero
4732 ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
4733 */
4734 SQLITE_API int sqlite3_release_memory(int);
4735
4736 /*
4737 ** CAPI3REF: Impose A Limit On Heap Size
4738 **
4739 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
4740 ** soft limit on the amount of heap memory that may be allocated by SQLite.
4741 ** ^SQLite strives to keep heap memory utilization below the soft heap
4742 ** limit by reducing the number of pages held in the page cache
4743 ** as heap memory usages approaches the limit.
4744 ** ^The soft heap limit is "soft" because even though SQLite strives to stay
4745 ** below the limit, it will exceed the limit rather than generate
4746 ** an [SQLITE_NOMEM] error. In other words, the soft heap limit
4747 ** is advisory only.
4748 **
4749 ** ^The return value from sqlite3_soft_heap_limit64() is the size of
4750 ** the soft heap limit prior to the call. ^If the argument N is negative
4751 ** then no change is made to the soft heap limit. Hence, the current
4752 ** size of the soft heap limit can be determined by invoking
4753 ** sqlite3_soft_heap_limit64() with a negative argument.
4754 **
4755 ** ^If the argument N is zero then the soft heap limit is disabled.
4756 **
4757 ** ^(The soft heap limit is not enforced in the current implementation
4758 ** if one or more of following conditions are true:
4759 **
4760 ** <ul>
4761 ** <li> The soft heap limit is set to zero.
4762 ** <li> Memory accounting is disabled using a combination of the
4763 ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
4764 ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
4765 ** <li> An alternative page cache implementation is specifed using
4766 ** [sqlite3_config]([SQLITE_CONFIG_PCACHE],...).
4767 ** <li> The page cache allocates from its own memory pool supplied
4768 ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
4769 ** from the heap.
4770 ** </ul>)^
4771 **
4772 ** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
4773 ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
4774 ** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
4775 ** the soft heap limit is enforced on every memory allocation. Without
4776 ** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
4777 ** when memory is allocated by the page cache. Testing suggests that because
4778 ** the page cache is the predominate memory user in SQLite, most
4779 ** applications will achieve adequate soft heap limit enforcement without
4780 ** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
4781 **
4782 ** The circumstances under which SQLite will enforce the soft heap limit may
4783 ** changes in future releases of SQLite.
4784 */
4785 SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
4786
4787 /*
4788 ** CAPI3REF: Deprecated Soft Heap Limit Interface
4789 ** DEPRECATED
4790 **
4791 ** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
4792 ** interface. This routine is provided for historical compatibility
4793 ** only. All new applications should use the
4794 ** [sqlite3_soft_heap_limit64()] interface rather than this one.
4795 */
4796 SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);
4797
4798
4799 /*
4800 ** CAPI3REF: Extract Metadata About A Column Of A Table
4801 **
4802 ** ^This routine returns metadata about a specific column of a specific
@@ -4777,38 +4916,51 @@
4916 ** it back off again.
4917 */
4918 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
4919
4920 /*
4921 ** CAPI3REF: Automatically Load Statically Linked Extensions
4922 **
4923 ** ^This interface causes the xEntryPoint() function to be invoked for
4924 ** each new [database connection] that is created. The idea here is that
4925 ** xEntryPoint() is the entry point for a statically linked SQLite extension
4926 ** that is to be automatically loaded into all new database connections.
4927 **
4928 ** ^(Even though the function prototype shows that xEntryPoint() takes
4929 ** no arguments and returns void, SQLite invokes xEntryPoint() with three
4930 ** arguments and expects and integer result as if the signature of the
4931 ** entry point where as follows:
4932 **
4933 ** <blockquote><pre>
4934 ** &nbsp; int xEntryPoint(
4935 ** &nbsp; sqlite3 *db,
4936 ** &nbsp; const char **pzErrMsg,
4937 ** &nbsp; const struct sqlite3_api_routines *pThunk
4938 ** &nbsp; );
4939 ** </pre></blockquote>)^
4940 **
4941 ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
4942 ** point to an appropriate error message (obtained from [sqlite3_mprintf()])
4943 ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg
4944 ** is NULL before calling the xEntryPoint(). ^SQLite will invoke
4945 ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any
4946 ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
4947 ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
4948 **
4949 ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
4950 ** on the list of automatic extensions is a harmless no-op. ^No entry point
4951 ** will be called more than once for each database connection that is opened.
4952 **
4953 ** See also: [sqlite3_reset_auto_extension()].
4954 */
4955 SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
4956
4957 /*
4958 ** CAPI3REF: Reset Automatic Extension Loading
4959 **
4960 ** ^This interface disables all automatic extensions previously
4961 ** registered using [sqlite3_auto_extension()].
 
 
 
4962 */
4963 SQLITE_API void sqlite3_reset_auto_extension(void);
4964
4965 /*
4966 ** The interface to the virtual-table mechanism is currently considered
@@ -5443,11 +5595,11 @@
5595 ** output variable when querying the system for the current mutex
5596 ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
5597 **
5598 ** ^The xMutexInit method defined by this structure is invoked as
5599 ** part of system initialization by the sqlite3_initialize() function.
5600 ** ^The xMutexInit routine is called by SQLite exactly once for each
5601 ** effective call to [sqlite3_initialize()].
5602 **
5603 ** ^The xMutexEnd method defined by this structure is invoked as
5604 ** part of system shutdown by the sqlite3_shutdown() function. The
5605 ** implementation of this method is expected to release all outstanding
@@ -5640,11 +5792,12 @@
5792 #define SQLITE_TESTCTRL_ALWAYS 13
5793 #define SQLITE_TESTCTRL_RESERVE 14
5794 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
5795 #define SQLITE_TESTCTRL_ISKEYWORD 16
5796 #define SQLITE_TESTCTRL_PGHDRSZ 17
5797 #define SQLITE_TESTCTRL_SCRATCHMALLOC 18
5798 #define SQLITE_TESTCTRL_LAST 18
5799
5800 /*
5801 ** CAPI3REF: SQLite Runtime Status
5802 **
5803 ** ^This interface is used to retrieve runtime status information
@@ -5659,11 +5812,11 @@
5812 ** value. For those parameters
5813 ** nothing is written into *pHighwater and the resetFlag is ignored.)^
5814 ** ^(Other parameters record only the highwater mark and not the current
5815 ** value. For these latter parameters nothing is written into *pCurrent.)^
5816 **
5817 ** ^The sqlite3_status() routine returns SQLITE_OK on success and a
5818 ** non-zero [error code] on failure.
5819 **
5820 ** This routine is threadsafe but is not atomic. This routine can be
5821 ** called while other threads are running the same or different SQLite
5822 ** interfaces. However the values returned in *pCurrent and
@@ -5709,11 +5862,11 @@
5862 ** [SQLITE_CONFIG_PAGECACHE]. The
5863 ** value returned is in pages, not in bytes.</dd>)^
5864 **
5865 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
5866 ** <dd>This parameter returns the number of bytes of page cache
5867 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
5868 ** buffer and where forced to overflow to [sqlite3_malloc()]. The
5869 ** returned value includes allocations that overflowed because they
5870 ** where too large (they were larger than the "sz" parameter to
5871 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
5872 ** no space was left in the page cache.</dd>)^
@@ -5732,11 +5885,11 @@
5885 ** outstanding at time, this parameter also reports the number of threads
5886 ** using scratch memory at the same time.</dd>)^
5887 **
5888 ** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
5889 ** <dd>This parameter returns the number of bytes of scratch memory
5890 ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
5891 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
5892 ** returned include overflows because the requested allocation was too
5893 ** larger (that is, because the requested allocation was larger than the
5894 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
5895 ** slots were available.
@@ -5780,10 +5933,13 @@
5933 **
5934 ** ^The current value of the requested parameter is written into *pCur
5935 ** and the highest instantaneous value is written into *pHiwtr. ^If
5936 ** the resetFlg is true, then the highest instantaneous value is
5937 ** reset back down to the current value.
5938 **
5939 ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
5940 ** non-zero [error code] on failure.
5941 **
5942 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
5943 */
5944 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5945
@@ -5907,122 +6063,134 @@
6063 ** CAPI3REF: Application Defined Page Cache.
6064 ** KEYWORDS: {page cache}
6065 **
6066 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
6067 ** register an alternative page cache implementation by passing in an
6068 ** instance of the sqlite3_pcache_methods structure.)^
6069 ** In many applications, most of the heap memory allocated by
6070 ** SQLite is used for the page cache.
6071 ** By implementing a
6072 ** custom page cache using this API, an application can better control
6073 ** the amount of memory consumed by SQLite, the way in which
6074 ** that memory is allocated and released, and the policies used to
6075 ** determine exactly which parts of a database file are cached and for
6076 ** how long.
6077 **
6078 ** The alternative page cache mechanism is an
6079 ** extreme measure that is only needed by the most demanding applications.
6080 ** The built-in page cache is recommended for most uses.
6081 **
6082 ** ^(The contents of the sqlite3_pcache_methods structure are copied to an
6083 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence
6084 ** the application may discard the parameter after the call to
6085 ** [sqlite3_config()] returns.)^
6086 **
6087 ** ^(The xInit() method is called once for each effective
6088 ** call to [sqlite3_initialize()])^
6089 ** (usually only once during the lifetime of the process). ^(The xInit()
6090 ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
6091 ** The intent of the xInit() method is to set up global data structures
6092 ** required by the custom page cache implementation.
6093 ** ^(If the xInit() method is NULL, then the
6094 ** built-in default page cache is used instead of the application defined
6095 ** page cache.)^
6096 **
6097 ** ^The xShutdown() method is called by [sqlite3_shutdown()].
6098 ** It can be used to clean up
6099 ** any outstanding resources before process shutdown, if required.
6100 ** ^The xShutdown() method may be NULL.
6101 **
6102 ** ^SQLite automatically serializes calls to the xInit method,
6103 ** so the xInit method need not be threadsafe. ^The
6104 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
6105 ** not need to be threadsafe either. All other methods must be threadsafe
6106 ** in multithreaded applications.
6107 **
6108 ** ^SQLite will never invoke xInit() more than once without an intervening
6109 ** call to xShutdown().
6110 **
6111 ** ^SQLite invokes the xCreate() method to construct a new cache instance.
6112 ** SQLite will typically create one cache instance for each open database file,
6113 ** though this is not guaranteed. ^The
6114 ** first parameter, szPage, is the size in bytes of the pages that must
6115 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage
6116 ** will the page size of the database file that is to be cached plus an
6117 ** increment (here called "R") of about 100 or 200. SQLite will use the
6118 ** extra R bytes on each page to store metadata about the underlying
6119 ** database page on disk. The value of R depends
6120 ** on the SQLite version, the target platform, and how SQLite was compiled.
6121 ** ^R is constant for a particular build of SQLite. ^The second argument to
6122 ** xCreate(), bPurgeable, is true if the cache being created will
6123 ** be used to cache database pages of a file stored on disk, or
6124 ** false if it is used for an in-memory database. The cache implementation
6125 ** does not have to do anything special based with the value of bPurgeable;
6126 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
6127 ** never invoke xUnpin() except to deliberately delete a page.
6128 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
6129 ** false will always have the "discard" flag set to true.
6130 ** ^Hence, a cache created with bPurgeable false will
6131 ** never contain any unpinned pages.
6132 **
6133 ** ^(The xCachesize() method may be called at any time by SQLite to set the
6134 ** suggested maximum cache-size (number of pages stored by) the cache
6135 ** instance passed as the first argument. This is the value configured using
6136 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
6137 ** parameter, the implementation is not required to do anything with this
6138 ** value; it is advisory only.
6139 **
6140 ** The xPagecount() method must return the number of pages currently
6141 ** stored in the cache, both pinned and unpinned.
6142 **
6143 ** The xFetch() method locates a page in the cache and returns a pointer to
6144 ** the page, or a NULL pointer.
6145 ** A "page", in this context, means a buffer of szPage bytes aligned at an
6146 ** 8-byte boundary. The page to be fetched is determined by the key. ^The
6147 ** mimimum key value is 1. After it has been retrieved using xFetch, the page
6148 ** is considered to be "pinned".
6149 **
6150 ** If the requested page is already in the page cache, then the page cache
6151 ** implementation must return a pointer to the page buffer with its content
6152 ** intact. If the requested page is not already in the cache, then the
6153 ** behavior of the cache implementation should use the value of the createFlag
6154 ** parameter to help it determined what action to take:
6155 **
6156 ** <table border=1 width=85% align=center>
6157 ** <tr><th> createFlag <th> Behaviour when page is not already in cache
6158 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
6159 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
6160 ** Otherwise return NULL.
6161 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
6162 ** NULL if allocating a new page is effectively impossible.
6163 ** </table>
6164 **
6165 ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
6166 ** will only use a createFlag of 2 after a prior call with a createFlag of 1
6167 ** failed.)^ In between the to xFetch() calls, SQLite may
6168 ** attempt to unpin one or more cache pages by spilling the content of
6169 ** pinned pages to disk and synching the operating system disk cache.
 
 
6170 **
6171 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
6172 ** as its second argument. If the third parameter, discard, is non-zero,
6173 ** then the page must be evicted from the cache.
6174 ** ^If the discard parameter is
6175 ** zero, then the page may be discarded or retained at the discretion of
6176 ** page cache implementation. ^The page cache implementation
6177 ** may choose to evict unpinned pages at any time.
6178 **
6179 ** The cache must not perform any reference counting. A single
6180 ** call to xUnpin() unpins the page regardless of the number of prior calls
6181 ** to xFetch().
6182 **
6183 ** The xRekey() method is used to change the key value associated with the
6184 ** page passed as the second argument. If the cache
6185 ** previously contains an entry associated with newKey, it must be
6186 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
6187 ** to be pinned.
6188 **
6189 ** When SQLite calls the xTruncate() method, the cache must discard all
6190 ** existing cache entries with page numbers (keys) greater than or equal
6191 ** to the value of the iLimit parameter passed to xTruncate(). If any
6192 ** of these pages are pinned, they are implicitly unpinned, meaning that
6193 ** they can be safely discarded.
6194 **
6195 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
6196 ** All resources associated with the specified cache should be freed. ^After
@@ -6496,10 +6664,66 @@
6664 #if 0
6665 } /* End of the 'extern "C"' block */
6666 #endif
6667 #endif
6668
6669 /*
6670 ** 2010 August 30
6671 **
6672 ** The author disclaims copyright to this source code. In place of
6673 ** a legal notice, here is a blessing:
6674 **
6675 ** May you do good and not evil.
6676 ** May you find forgiveness for yourself and forgive others.
6677 ** May you share freely, never taking more than you give.
6678 **
6679 *************************************************************************
6680 */
6681
6682 #ifndef _SQLITE3RTREE_H_
6683 #define _SQLITE3RTREE_H_
6684
6685
6686 #if 0
6687 extern "C" {
6688 #endif
6689
6690 typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
6691
6692 /*
6693 ** Register a geometry callback named zGeom that can be used as part of an
6694 ** R-Tree geometry query as follows:
6695 **
6696 ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
6697 */
6698 SQLITE_API int sqlite3_rtree_geometry_callback(
6699 sqlite3 *db,
6700 const char *zGeom,
6701 int (*xGeom)(sqlite3_rtree_geometry *, int nCoord, double *aCoord, int *pRes),
6702 void *pContext
6703 );
6704
6705
6706 /*
6707 ** A pointer to a structure of the following type is passed as the first
6708 ** argument to callbacks registered using rtree_geometry_callback().
6709 */
6710 struct sqlite3_rtree_geometry {
6711 void *pContext; /* Copy of pContext passed to s_r_g_c() */
6712 int nParam; /* Size of array aParam[] */
6713 double *aParam; /* Parameters passed to SQL geom function */
6714 void *pUser; /* Callback implementation user data */
6715 void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */
6716 };
6717
6718
6719 #if 0
6720 } /* end of the 'extern "C"' block */
6721 #endif
6722
6723 #endif /* ifndef _SQLITE3RTREE_H_ */
6724
6725
6726 /************** End of sqlite3.h *********************************************/
6727 /************** Continuing where we left off in sqliteInt.h ******************/
6728 /************** Include hash.h in the middle of sqliteInt.h ******************/
6729 /************** Begin file hash.h ********************************************/
@@ -7066,10 +7290,11 @@
7290 typedef struct Schema Schema;
7291 typedef struct Expr Expr;
7292 typedef struct ExprList ExprList;
7293 typedef struct ExprSpan ExprSpan;
7294 typedef struct FKey FKey;
7295 typedef struct FuncDestructor FuncDestructor;
7296 typedef struct FuncDef FuncDef;
7297 typedef struct FuncDefHash FuncDefHash;
7298 typedef struct IdList IdList;
7299 typedef struct Index Index;
7300 typedef struct IndexSample IndexSample;
@@ -7172,16 +7397,15 @@
7397 ** following values.
7398 **
7399 ** NOTE: These values must match the corresponding PAGER_ values in
7400 ** pager.h.
7401 */
7402 #define BTREE_OMIT_JOURNAL 1 /* Do not create or use a rollback journal */
7403 #define BTREE_NO_READLOCK 2 /* Omit readlocks on readonly files */
7404 #define BTREE_MEMORY 4 /* This is an in-memory DB */
7405 #define BTREE_SINGLE 8 /* The file contains at most 1 b-tree */
7406 #define BTREE_UNORDERED 16 /* Use of a hash implementation is OK */
 
7407
7408 SQLITE_PRIVATE int sqlite3BtreeClose(Btree*);
7409 SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int);
7410 SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
7411 SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
@@ -7213,15 +7437,21 @@
7437 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *);
7438
7439 SQLITE_PRIVATE int sqlite3BtreeIncrVacuum(Btree *);
7440
7441 /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
7442 ** of the flags shown below.
7443 **
7444 ** Every SQLite table must have either BTREE_INTKEY or BTREE_BLOBKEY set.
7445 ** With BTREE_INTKEY, the table key is a 64-bit integer and arbitrary data
7446 ** is stored in the leaves. (BTREE_INTKEY is used for SQL tables.) With
7447 ** BTREE_BLOBKEY, the key is an arbitrary BLOB and no content is stored
7448 ** anywhere - the key is the content. (BTREE_BLOBKEY is used for SQL
7449 ** indices.)
7450 */
7451 #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */
7452 #define BTREE_BLOBKEY 2 /* Table has keys only - no data */
 
7453
7454 SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*);
7455 SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*);
7456 SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree*, int);
7457
@@ -7838,10 +8068,11 @@
8068 **
8069 ** NOTE: These values must match the corresponding BTREE_ values in btree.h.
8070 */
8071 #define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */
8072 #define PAGER_NO_READLOCK 0x0002 /* Omit readlocks on readonly files */
8073 #define PAGER_MEMORY 0x0004 /* In-memory database */
8074
8075 /*
8076 ** Valid values for the second argument to sqlite3PagerLockingMode().
8077 */
8078 #define PAGER_LOCKINGMODE_QUERY -1
@@ -8472,12 +8703,12 @@
8703 #define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8)
8704 #define sqlite3_mutex_free(X)
8705 #define sqlite3_mutex_enter(X)
8706 #define sqlite3_mutex_try(X) SQLITE_OK
8707 #define sqlite3_mutex_leave(X)
8708 #define sqlite3_mutex_held(X) ((void)(X),1)
8709 #define sqlite3_mutex_notheld(X) ((void)(X),1)
8710 #define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8)
8711 #define sqlite3MutexInit() SQLITE_OK
8712 #define sqlite3MutexEnd()
8713 #endif /* defined(SQLITE_MUTEX_OMIT) */
8714
@@ -8795,10 +9026,31 @@
9026 void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
9027 void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
9028 void (*xFinalize)(sqlite3_context*); /* Aggregate finalizer */
9029 char *zName; /* SQL name of the function. */
9030 FuncDef *pHash; /* Next with a different name but the same hash */
9031 FuncDestructor *pDestructor; /* Reference counted destructor function */
9032 };
9033
9034 /*
9035 ** This structure encapsulates a user-function destructor callback (as
9036 ** configured using create_function_v2()) and a reference counter. When
9037 ** create_function_v2() is called to create a function with a destructor,
9038 ** a single object of this type is allocated. FuncDestructor.nRef is set to
9039 ** the number of FuncDef objects created (either 1 or 3, depending on whether
9040 ** or not the specified encoding is SQLITE_ANY). The FuncDef.pDestructor
9041 ** member of each of the new FuncDef objects is set to point to the allocated
9042 ** FuncDestructor.
9043 **
9044 ** Thereafter, when one of the FuncDef objects is deleted, the reference
9045 ** count on this object is decremented. When it reaches 0, the destructor
9046 ** is invoked and the FuncDestructor structure freed.
9047 */
9048 struct FuncDestructor {
9049 int nRef;
9050 void (*xDestroy)(void *);
9051 void *pUserData;
9052 };
9053
9054 /*
9055 ** Possible values for FuncDef.flags
9056 */
@@ -8835,19 +9087,19 @@
9087 ** FuncDef.flags variable is set to the value passed as the flags
9088 ** parameter.
9089 */
9090 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
9091 {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
9092 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
9093 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
9094 {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
9095 pArg, 0, xFunc, 0, 0, #zName, 0, 0}
9096 #define LIKEFUNC(zName, nArg, arg, flags) \
9097 {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
9098 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
9099 {nArg, SQLITE_UTF8, nc*SQLITE_FUNC_NEEDCOLL, \
9100 SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
9101
9102 /*
9103 ** All current savepoints are stored in a linked list starting at
9104 ** sqlite3.pSavepoint. The first element in the list is the most recently
9105 ** opened savepoint. Savepoints are added to the list by the vdbe
@@ -9063,10 +9315,11 @@
9315 int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
9316 int nCol; /* Number of columns in this table */
9317 Column *aCol; /* Information about each column */
9318 Index *pIndex; /* List of SQL indexes on this table. */
9319 int tnum; /* Root BTree node for this table (see note above) */
9320 unsigned nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
9321 Select *pSelect; /* NULL for tables. Points to definition if a view. */
9322 u16 nRef; /* Number of pointers to this Table */
9323 u8 tabFlags; /* Mask of TF_* values */
9324 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
9325 FKey *pFKey; /* Linked list of all foreign keys in this table */
@@ -10317,11 +10570,10 @@
10570
10571 /*
10572 ** Internal function prototypes
10573 */
10574 SQLITE_PRIVATE int sqlite3StrICmp(const char *, const char *);
 
10575 SQLITE_PRIVATE int sqlite3Strlen30(const char*);
10576 #define sqlite3StrNICmp sqlite3_strnicmp
10577
10578 SQLITE_PRIVATE int sqlite3MallocInit(void);
10579 SQLITE_PRIVATE void sqlite3MallocEnd(void);
@@ -10341,11 +10593,11 @@
10593 SQLITE_PRIVATE void sqlite3ScratchFree(void*);
10594 SQLITE_PRIVATE void *sqlite3PageMalloc(int);
10595 SQLITE_PRIVATE void sqlite3PageFree(void*);
10596 SQLITE_PRIVATE void sqlite3MemSetDefault(void);
10597 SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
10598 SQLITE_PRIVATE int sqlite3HeapNearlyFull(void);
10599
10600 /*
10601 ** On systems with ample stack space and that support alloca(), make
10602 ** use of alloca() to obtain space for large automatic objects. By default,
10603 ** obtain space from malloc().
@@ -10512,11 +10764,10 @@
10764 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
10765 SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
10766 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
10767 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
10768 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
 
10769 SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
10770 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
10771 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
10772 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
10773 SQLITE_PRIVATE void sqlite3ExprCodeConstants(Parse*, Expr*);
@@ -10632,21 +10883,18 @@
10883 # define sqlite3AuthContextPush(a,b,c)
10884 # define sqlite3AuthContextPop(a) ((void)(a))
10885 #endif
10886 SQLITE_PRIVATE void sqlite3Attach(Parse*, Expr*, Expr*, Expr*);
10887 SQLITE_PRIVATE void sqlite3Detach(Parse*, Expr*);
 
 
10888 SQLITE_PRIVATE int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*);
10889 SQLITE_PRIVATE int sqlite3FixSrcList(DbFixer*, SrcList*);
10890 SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
10891 SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
10892 SQLITE_PRIVATE int sqlite3FixExprList(DbFixer*, ExprList*);
10893 SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
10894 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
10895 SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
 
10896 SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar);
10897 SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte);
10898 SQLITE_PRIVATE int sqlite3Utf8Read(const u8*, const u8**);
10899
10900 /*
@@ -10688,11 +10936,11 @@
10936 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
10937 SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *, Table *);
10938 SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
10939 SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
10940 SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
10941 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
10942 SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
10943 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
10944 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
10945 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
10946 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -10759,11 +11007,13 @@
11007 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
11008 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
11009 SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
11010 SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
11011 void (*)(sqlite3_context*,int,sqlite3_value **),
11012 void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*),
11013 FuncDestructor *pDestructor
11014 );
11015 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
11016 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
11017
11018 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
11019 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
@@ -11679,10 +11929,11 @@
11929 Bool useRandomRowid; /* Generate new record numbers semi-randomly */
11930 Bool nullRow; /* True if pointing to a row with no data */
11931 Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
11932 Bool isTable; /* True if a table requiring integer keys */
11933 Bool isIndex; /* True if an index containing keys only - no data */
11934 Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */
11935 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
11936 Btree *pBt; /* Separate file holding temporary table */
11937 int pseudoTableReg; /* Register holding pseudotable content. */
11938 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
11939 int nField; /* Number of fields in the header */
@@ -11773,10 +12024,14 @@
12024 char *z; /* String or BLOB value */
12025 int n; /* Number of characters in string value, excluding '\0' */
12026 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
12027 u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
12028 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
12029 #ifdef SQLITE_DEBUG
12030 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
12031 void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
12032 #endif
12033 void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
12034 char *zMalloc; /* Dynamic buffer allocated by sqlite3_malloc() */
12035 };
12036
12037 /* One or more of the following flags are set to indicate the validOK
@@ -11799,10 +12054,11 @@
12054 #define MEM_Int 0x0004 /* Value is an integer */
12055 #define MEM_Real 0x0008 /* Value is a real number */
12056 #define MEM_Blob 0x0010 /* Value is a BLOB */
12057 #define MEM_RowSet 0x0020 /* Value is a RowSet object */
12058 #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
12059 #define MEM_Invalid 0x0080 /* Value is undefined */
12060 #define MEM_TypeMask 0x00ff /* Mask of type bits */
12061
12062 /* Whenever Mem contains a valid string or blob representation, one of
12063 ** the following flags must be set to determine the memory management
12064 ** policy for Mem.z. The MEM_Term flag tells us whether or not the
@@ -11812,23 +12068,29 @@
12068 #define MEM_Dyn 0x0400 /* Need to call sqliteFree() on Mem.z */
12069 #define MEM_Static 0x0800 /* Mem.z points to a static string */
12070 #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
12071 #define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
12072 #define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
 
12073 #ifdef SQLITE_OMIT_INCRBLOB
12074 #undef MEM_Zero
12075 #define MEM_Zero 0x0000
12076 #endif
 
12077
12078 /*
12079 ** Clear any existing type flags from a Mem and replace them with f
12080 */
12081 #define MemSetTypeFlag(p, f) \
12082 ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
12083
12084 /*
12085 ** Return true if a memory cell is not marked as invalid. This macro
12086 ** is for use inside assert() statements only.
12087 */
12088 #ifdef SQLITE_DEBUG
12089 #define memIsValid(M) ((M)->flags & MEM_Invalid)==0
12090 #endif
12091
12092
12093 /* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
12094 ** additional information about auxiliary information bound to arguments
12095 ** of the function. This is used to implement the sqlite3_get_auxdata()
12096 ** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data
@@ -12012,10 +12274,14 @@
12274 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
12275 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
12276 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
12277 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
12278 SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
12279
12280 #ifdef SQLITE_DEBUG
12281 SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe*,Mem*);
12282 #endif
12283
12284 #ifndef SQLITE_OMIT_FOREIGN_KEY
12285 SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int);
12286 #else
12287 # define sqlite3VdbeCheckFk(p,i) 0
@@ -12369,16 +12635,10 @@
12635 end_getDigits:
12636 va_end(ap);
12637 return cnt;
12638 }
12639
 
 
 
 
 
 
12640 /*
12641 ** Parse a timezone extension on the end of a date-time.
12642 ** The extension is of the form:
12643 **
12644 ** (+/-)HH:MM
@@ -12576,21 +12836,19 @@
12836 static int parseDateOrTime(
12837 sqlite3_context *context,
12838 const char *zDate,
12839 DateTime *p
12840 ){
12841 double r;
12842 if( parseYyyyMmDd(zDate,p)==0 ){
12843 return 0;
12844 }else if( parseHhMmSs(zDate, p)==0 ){
12845 return 0;
12846 }else if( sqlite3StrICmp(zDate,"now")==0){
12847 setDateTimeToCurrent(context, p);
12848 return 0;
12849 }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
 
 
12850 p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
12851 p->validJD = 1;
12852 return 0;
12853 }
12854 return 1;
@@ -12807,12 +13065,13 @@
13065 **
13066 ** Move the date to the same time on the next occurrence of
13067 ** weekday N where 0==Sunday, 1==Monday, and so forth. If the
13068 ** date is already on the appropriate weekday, this is a no-op.
13069 */
13070 if( strncmp(z, "weekday ", 8)==0
13071 && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)
13072 && (n=(int)r)==r && n>=0 && r<7 ){
13073 sqlite3_int64 Z;
13074 computeYMD_HMS(p);
13075 p->validTZ = 0;
13076 p->validJD = 0;
13077 computeJD(p);
@@ -12863,12 +13122,15 @@
13122 case '6':
13123 case '7':
13124 case '8':
13125 case '9': {
13126 double rRounder;
13127 for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){}
13128 if( !sqlite3AtoF(z, &r, n, SQLITE_UTF8) ){
13129 rc = 1;
13130 break;
13131 }
13132 if( z[n]==':' ){
13133 /* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the
13134 ** specified number of hours, minutes, seconds, and fractional seconds
13135 ** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be
13136 ** omitted.
@@ -13518,10 +13780,16 @@
13780 SQLITE_PRIVATE int sqlite3OsSleep(sqlite3_vfs *pVfs, int nMicro){
13781 return pVfs->xSleep(pVfs, nMicro);
13782 }
13783 SQLITE_PRIVATE int sqlite3OsCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *pTimeOut){
13784 int rc;
13785 /* IMPLEMENTATION-OF: R-49045-42493 SQLite will use the xCurrentTimeInt64()
13786 ** method to get the current date and time if that method is available
13787 ** (if iVersion is 2 or greater and the function pointer is not NULL) and
13788 ** will fall back to xCurrentTime() if xCurrentTimeInt64() is
13789 ** unavailable.
13790 */
13791 if( pVfs->iVersion>=2 && pVfs->xCurrentTimeInt64 ){
13792 rc = pVfs->xCurrentTimeInt64(pVfs, pTimeOut);
13793 }else{
13794 double r;
13795 rc = pVfs->xCurrentTime(pVfs, &r);
@@ -13901,11 +14169,11 @@
14169 ** routines and redirected to xFree.
14170 */
14171 static void *sqlite3MemRealloc(void *pPrior, int nByte){
14172 sqlite3_int64 *p = (sqlite3_int64*)pPrior;
14173 assert( pPrior!=0 && nByte>0 );
14174 assert( nByte==ROUND8(nByte) ); /* EV: R-46199-30249 */
14175 p--;
14176 p = realloc(p, nByte+8 );
14177 if( p ){
14178 p[0] = nByte;
14179 p++;
@@ -14307,10 +14575,11 @@
14575 */
14576 static void *sqlite3MemRealloc(void *pPrior, int nByte){
14577 struct MemBlockHdr *pOldHdr;
14578 void *pNew;
14579 assert( mem.disallow==0 );
14580 assert( (nByte & 7)==0 ); /* EV: R-46199-30249 */
14581 pOldHdr = sqlite3MemsysGetHeader(pPrior);
14582 pNew = sqlite3MemMalloc(nByte);
14583 if( pNew ){
14584 memcpy(pNew, pPrior, nByte<pOldHdr->iSize ? nByte : pOldHdr->iSize);
14585 if( nByte>pOldHdr->iSize ){
@@ -15576,11 +15845,11 @@
15845 */
15846 static void *memsys5Realloc(void *pPrior, int nBytes){
15847 int nOld;
15848 void *p;
15849 assert( pPrior!=0 );
15850 assert( (nBytes&(nBytes-1))==0 ); /* EV: R-46199-30249 */
15851 assert( nBytes>=0 );
15852 if( nBytes==0 ){
15853 return 0;
15854 }
15855 nOld = memsys5Size(pPrior);
@@ -17100,10 +17369,70 @@
17369 *************************************************************************
17370 **
17371 ** Memory allocation functions used throughout sqlite.
17372 */
17373
17374 /*
17375 ** Attempt to release up to n bytes of non-essential memory currently
17376 ** held by SQLite. An example of non-essential memory is memory used to
17377 ** cache database pages that are not currently in use.
17378 */
17379 SQLITE_API int sqlite3_release_memory(int n){
17380 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
17381 return sqlite3PcacheReleaseMemory(n);
17382 #else
17383 /* IMPLEMENTATION-OF: R-34391-24921 The sqlite3_release_memory() routine
17384 ** is a no-op returning zero if SQLite is not compiled with
17385 ** SQLITE_ENABLE_MEMORY_MANAGEMENT. */
17386 UNUSED_PARAMETER(n);
17387 return 0;
17388 #endif
17389 }
17390
17391 /*
17392 ** An instance of the following object records the location of
17393 ** each unused scratch buffer.
17394 */
17395 typedef struct ScratchFreeslot {
17396 struct ScratchFreeslot *pNext; /* Next unused scratch buffer */
17397 } ScratchFreeslot;
17398
17399 /*
17400 ** State information local to the memory allocation subsystem.
17401 */
17402 static SQLITE_WSD struct Mem0Global {
17403 sqlite3_mutex *mutex; /* Mutex to serialize access */
17404
17405 /*
17406 ** The alarm callback and its arguments. The mem0.mutex lock will
17407 ** be held while the callback is running. Recursive calls into
17408 ** the memory subsystem are allowed, but no new callbacks will be
17409 ** issued.
17410 */
17411 sqlite3_int64 alarmThreshold;
17412 void (*alarmCallback)(void*, sqlite3_int64,int);
17413 void *alarmArg;
17414
17415 /*
17416 ** Pointers to the end of sqlite3GlobalConfig.pScratch memory
17417 ** (so that a range test can be used to determine if an allocation
17418 ** being freed came from pScratch) and a pointer to the list of
17419 ** unused scratch allocations.
17420 */
17421 void *pScratchEnd;
17422 ScratchFreeslot *pScratchFree;
17423 u32 nScratchFree;
17424
17425 /*
17426 ** True if heap is nearly "full" where "full" is defined by the
17427 ** sqlite3_soft_heap_limit() setting.
17428 */
17429 int nearlyFull;
17430 } mem0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
17431
17432 #define mem0 GLOBAL(struct Mem0Global, mem0)
17433
17434 /*
17435 ** This routine runs when the memory allocator sees that the
17436 ** total memory allocation is about to exceed the soft heap
17437 ** limit.
17438 */
@@ -17114,82 +17443,70 @@
17443 ){
17444 UNUSED_PARAMETER2(NotUsed, NotUsed2);
17445 sqlite3_release_memory(allocSize);
17446 }
17447
17448 /*
17449 ** Change the alarm callback
17450 */
17451 static int sqlite3MemoryAlarm(
17452 void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
17453 void *pArg,
17454 sqlite3_int64 iThreshold
17455 ){
17456 int nUsed;
17457 sqlite3_mutex_enter(mem0.mutex);
17458 mem0.alarmCallback = xCallback;
17459 mem0.alarmArg = pArg;
17460 mem0.alarmThreshold = iThreshold;
17461 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
17462 mem0.nearlyFull = (iThreshold>0 && iThreshold<=nUsed);
17463 sqlite3_mutex_leave(mem0.mutex);
17464 return SQLITE_OK;
17465 }
17466
17467 #ifndef SQLITE_OMIT_DEPRECATED
17468 /*
17469 ** Deprecated external interface. Internal/core SQLite code
17470 ** should call sqlite3MemoryAlarm.
17471 */
17472 SQLITE_API int sqlite3_memory_alarm(
17473 void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
17474 void *pArg,
17475 sqlite3_int64 iThreshold
17476 ){
17477 return sqlite3MemoryAlarm(xCallback, pArg, iThreshold);
17478 }
17479 #endif
17480
17481 /*
17482 ** Set the soft heap-size limit for the library. Passing a zero or
17483 ** negative value indicates no limit.
17484 */
17485 SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 n){
17486 sqlite3_int64 priorLimit;
17487 sqlite3_int64 excess;
 
 
 
 
 
17488 #ifndef SQLITE_OMIT_AUTOINIT
17489 sqlite3_initialize();
17490 #endif
17491 sqlite3_mutex_enter(mem0.mutex);
17492 priorLimit = mem0.alarmThreshold;
17493 sqlite3_mutex_leave(mem0.mutex);
17494 if( n<0 ) return priorLimit;
17495 if( n>0 ){
17496 sqlite3MemoryAlarm(softHeapLimitEnforcer, 0, n);
17497 }else{
17498 sqlite3MemoryAlarm(0, 0, 0);
17499 }
17500 excess = sqlite3_memory_used() - n;
17501 if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff));
17502 return priorLimit;
17503 }
17504 SQLITE_API void sqlite3_soft_heap_limit(int n){
17505 if( n<0 ) n = 0;
17506 sqlite3_soft_heap_limit64(n);
17507 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17508
17509 /*
17510 ** Initialize the memory allocation subsystem.
17511 */
17512 SQLITE_PRIVATE int sqlite3MallocInit(void){
@@ -17199,39 +17516,48 @@
17516 memset(&mem0, 0, sizeof(mem0));
17517 if( sqlite3GlobalConfig.bCoreMutex ){
17518 mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
17519 }
17520 if( sqlite3GlobalConfig.pScratch && sqlite3GlobalConfig.szScratch>=100
17521 && sqlite3GlobalConfig.nScratch>0 ){
17522 int i, n, sz;
17523 ScratchFreeslot *pSlot;
17524 sz = ROUNDDOWN8(sqlite3GlobalConfig.szScratch);
17525 sqlite3GlobalConfig.szScratch = sz;
17526 pSlot = (ScratchFreeslot*)sqlite3GlobalConfig.pScratch;
17527 n = sqlite3GlobalConfig.nScratch;
17528 mem0.pScratchFree = pSlot;
17529 mem0.nScratchFree = n;
17530 for(i=0; i<n-1; i++){
17531 pSlot->pNext = (ScratchFreeslot*)(sz+(char*)pSlot);
17532 pSlot = pSlot->pNext;
17533 }
17534 pSlot->pNext = 0;
17535 mem0.pScratchEnd = (void*)&pSlot[1];
17536 }else{
17537 mem0.pScratchEnd = 0;
17538 sqlite3GlobalConfig.pScratch = 0;
17539 sqlite3GlobalConfig.szScratch = 0;
17540 sqlite3GlobalConfig.nScratch = 0;
17541 }
17542 if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512
17543 || sqlite3GlobalConfig.nPage<1 ){
 
 
 
 
 
 
 
 
 
 
17544 sqlite3GlobalConfig.pPage = 0;
17545 sqlite3GlobalConfig.szPage = 0;
17546 sqlite3GlobalConfig.nPage = 0;
17547 }
17548 return sqlite3GlobalConfig.m.xInit(sqlite3GlobalConfig.m.pAppData);
17549 }
17550
17551 /*
17552 ** Return true if the heap is currently under memory pressure - in other
17553 ** words if the amount of heap used is close to the limit set by
17554 ** sqlite3_soft_heap_limit().
17555 */
17556 SQLITE_PRIVATE int sqlite3HeapNearlyFull(void){
17557 return mem0.nearlyFull;
17558 }
17559
17560 /*
17561 ** Deinitialize the memory allocation subsystem.
17562 */
17563 SQLITE_PRIVATE void sqlite3MallocEnd(void){
@@ -17263,40 +17589,10 @@
17589 sqlite3_status(SQLITE_STATUS_MEMORY_USED, &n, &mx, resetFlag);
17590 res = (sqlite3_int64)mx; /* Work around bug in Borland C. Ticket #3216 */
17591 return res;
17592 }
17593
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17594 /*
17595 ** Trigger the alarm
17596 */
17597 static void sqlite3MallocAlarm(int nByte){
17598 void (*xCallback)(void*,sqlite3_int64,int);
@@ -17325,18 +17621,23 @@
17621 nFull = sqlite3GlobalConfig.m.xRoundup(n);
17622 sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
17623 if( mem0.alarmCallback!=0 ){
17624 int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
17625 if( nUsed+nFull >= mem0.alarmThreshold ){
17626 mem0.nearlyFull = 1;
17627 sqlite3MallocAlarm(nFull);
17628 }else{
17629 mem0.nearlyFull = 0;
17630 }
17631 }
17632 p = sqlite3GlobalConfig.m.xMalloc(nFull);
17633 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
17634 if( p==0 && mem0.alarmCallback ){
17635 sqlite3MallocAlarm(nFull);
17636 p = sqlite3GlobalConfig.m.xMalloc(nFull);
17637 }
17638 #endif
17639 if( p ){
17640 nFull = sqlite3MallocSize(p);
17641 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nFull);
17642 sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, 1);
17643 }
@@ -17348,11 +17649,13 @@
17649 ** Allocate memory. This routine is like sqlite3_malloc() except that it
17650 ** assumes the memory subsystem has already been initialized.
17651 */
17652 SQLITE_PRIVATE void *sqlite3Malloc(int n){
17653 void *p;
17654 if( n<=0 /* IMP: R-65312-04917 */
17655 || n>=0x7fffff00
17656 ){
17657 /* A memory allocation of a number of bytes which is near the maximum
17658 ** signed integer value might cause an integer overflow inside of the
17659 ** xMalloc(). Hence we limit the maximum size to 0x7fffff00, giving
17660 ** 255 bytes of overhead. SQLite itself will never use anything near
17661 ** this amount. The only way to reach the limit is with sqlite3_malloc() */
@@ -17362,10 +17665,11 @@
17665 mallocWithAlarm(n, &p);
17666 sqlite3_mutex_leave(mem0.mutex);
17667 }else{
17668 p = sqlite3GlobalConfig.m.xMalloc(n);
17669 }
17670 assert( EIGHT_BYTE_ALIGNMENT(p) ); /* IMP: R-04675-44850 */
17671 return p;
17672 }
17673
17674 /*
17675 ** This version of the memory allocation is for use by the application.
@@ -17399,64 +17703,70 @@
17703 ** embedded processor.
17704 */
17705 SQLITE_PRIVATE void *sqlite3ScratchMalloc(int n){
17706 void *p;
17707 assert( n>0 );
17708
17709 sqlite3_mutex_enter(mem0.mutex);
17710 if( mem0.nScratchFree && sqlite3GlobalConfig.szScratch>=n ){
17711 p = mem0.pScratchFree;
17712 mem0.pScratchFree = mem0.pScratchFree->pNext;
17713 mem0.nScratchFree--;
17714 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, 1);
17715 sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
17716 sqlite3_mutex_leave(mem0.mutex);
17717 }else{
17718 if( sqlite3GlobalConfig.bMemstat ){
17719 sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
17720 n = mallocWithAlarm(n, &p);
17721 if( p ) sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, n);
17722 sqlite3_mutex_leave(mem0.mutex);
17723 }else{
17724 sqlite3_mutex_leave(mem0.mutex);
17725 p = sqlite3GlobalConfig.m.xMalloc(n);
17726 }
17727 sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH);
17728 }
17729 assert( sqlite3_mutex_notheld(mem0.mutex) );
17730
17731
17732 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
17733 /* Verify that no more than two scratch allocations per thread
17734 ** are outstanding at one time. (This is only checked in the
17735 ** single-threaded case since checking in the multi-threaded case
17736 ** would be much more complicated.) */
17737 assert( scratchAllocOut<=1 );
17738 if( p ) scratchAllocOut++;
17739 #endif
17740
17741 return p;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17742 }
17743 SQLITE_PRIVATE void sqlite3ScratchFree(void *p){
17744 if( p ){
17745
17746 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
17747 /* Verify that no more than two scratch allocation per thread
17748 ** is outstanding at one time. (This is only checked in the
17749 ** single-threaded case since checking in the multi-threaded case
17750 ** would be much more complicated.) */
17751 assert( scratchAllocOut>=1 && scratchAllocOut<=2 );
17752 scratchAllocOut--;
17753 #endif
17754
17755 if( p>=sqlite3GlobalConfig.pScratch && p<mem0.pScratchEnd ){
17756 /* Release memory from the SQLITE_CONFIG_SCRATCH allocation */
17757 ScratchFreeslot *pSlot;
17758 pSlot = (ScratchFreeslot*)p;
17759 sqlite3_mutex_enter(mem0.mutex);
17760 pSlot->pNext = mem0.pScratchFree;
17761 mem0.pScratchFree = pSlot;
17762 mem0.nScratchFree++;
17763 assert( mem0.nScratchFree<=sqlite3GlobalConfig.nScratch );
17764 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1);
17765 sqlite3_mutex_leave(mem0.mutex);
17766 }else{
17767 /* Release memory back to the heap */
17768 assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
17769 assert( sqlite3MemdebugNoType(p, ~MEMTYPE_SCRATCH) );
17770 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
17771 if( sqlite3GlobalConfig.bMemstat ){
17772 int iSize = sqlite3MallocSize(p);
@@ -17467,30 +17777,10 @@
17777 sqlite3GlobalConfig.m.xFree(p);
17778 sqlite3_mutex_leave(mem0.mutex);
17779 }else{
17780 sqlite3GlobalConfig.m.xFree(p);
17781 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17782 }
17783 }
17784 }
17785
17786 /*
@@ -17527,11 +17817,11 @@
17817
17818 /*
17819 ** Free memory previously obtained from sqlite3Malloc().
17820 */
17821 SQLITE_API void sqlite3_free(void *p){
17822 if( p==0 ) return; /* IMP: R-49053-54554 */
17823 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
17824 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
17825 if( sqlite3GlobalConfig.bMemstat ){
17826 sqlite3_mutex_enter(mem0.mutex);
17827 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
@@ -17574,21 +17864,24 @@
17864 */
17865 SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, int nBytes){
17866 int nOld, nNew;
17867 void *pNew;
17868 if( pOld==0 ){
17869 return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */
17870 }
17871 if( nBytes<=0 ){
17872 sqlite3_free(pOld); /* IMP: R-31593-10574 */
17873 return 0;
17874 }
17875 if( nBytes>=0x7fffff00 ){
17876 /* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */
17877 return 0;
17878 }
17879 nOld = sqlite3MallocSize(pOld);
17880 /* IMPLEMENTATION-OF: R-46199-30249 SQLite guarantees that the second
17881 ** argument to xRealloc is always a value returned by a prior call to
17882 ** xRoundup. */
17883 nNew = sqlite3GlobalConfig.m.xRoundup(nBytes);
17884 if( nOld==nNew ){
17885 pNew = pOld;
17886 }else if( sqlite3GlobalConfig.bMemstat ){
17887 sqlite3_mutex_enter(mem0.mutex);
@@ -17610,10 +17903,11 @@
17903 }
17904 sqlite3_mutex_leave(mem0.mutex);
17905 }else{
17906 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
17907 }
17908 assert( EIGHT_BYTE_ALIGNMENT(pNew) ); /* IMP: R-04675-44850 */
17909 return pNew;
17910 }
17911
17912 /*
17913 ** The public interface to sqlite3Realloc. Make sure that the memory
@@ -19773,10 +20067,16 @@
20067 #define UpperToLower sqlite3UpperToLower
20068
20069 /*
20070 ** Some systems have stricmp(). Others have strcasecmp(). Because
20071 ** there is no consistency, we will define our own.
20072 **
20073 ** IMPLEMENTATION-OF: R-20522-24639 The sqlite3_strnicmp() API allows
20074 ** applications and extensions to compare the contents of two buffers
20075 ** containing UTF-8 strings in a case-independent fashion, using the same
20076 ** definition of case independence that SQLite uses internally when
20077 ** comparing identifiers.
20078 */
20079 SQLITE_PRIVATE int sqlite3StrICmp(const char *zLeft, const char *zRight){
20080 register unsigned char *a, *b;
20081 a = (unsigned char *)zLeft;
20082 b = (unsigned char *)zRight;
@@ -19790,125 +20090,115 @@
20090 while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
20091 return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
20092 }
20093
20094 /*
20095 ** The string z[] is an text representation of a real number.
20096 ** Convert this string to a double and write it into *pResult.
20097 **
20098 ** The string z[] is length bytes in length (bytes, not characters) and
20099 ** uses the encoding enc. The string is not necessarily zero-terminated.
20100 **
20101 ** Return TRUE if the result is a valid real number (or integer) and FALSE
20102 ** if the string is empty or contains extraneous text. Valid numbers
20103 ** are in one of these formats:
20104 **
20105 ** [+-]digits[E[+-]digits]
20106 ** [+-]digits.[digits][E[+-]digits]
20107 ** [+-].digits[E[+-]digits]
20108 **
20109 ** Leading and trailing whitespace is ignored for the purpose of determining
20110 ** validity.
20111 **
20112 ** If some prefix of the input string is a valid number, this routine
20113 ** returns FALSE but it still converts the prefix and writes the result
20114 ** into *pResult.
20115 */
20116 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
20117 #ifndef SQLITE_OMIT_FLOATING_POINT
20118 int incr = (enc==SQLITE_UTF8?1:2);
20119 const char *zEnd = z + length;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20120 /* sign * significand * (10 ^ (esign * exponent)) */
20121 int sign = 1; /* sign of significand */
20122 i64 s = 0; /* significand */
20123 int d = 0; /* adjust exponent for shifting decimal point */
20124 int esign = 1; /* sign of exponent */
20125 int e = 0; /* exponent */
20126 int eValid = 1; /* True exponent is either not used or is well-formed */
20127 double result;
20128 int nDigits = 0;
20129
20130 *pResult = 0.0; /* Default return value, in case of an error */
20131
20132 if( enc==SQLITE_UTF16BE ) z++;
20133
20134 /* skip leading spaces */
20135 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
20136 if( z>=zEnd ) return 0;
20137
20138 /* get sign of significand */
20139 if( *z=='-' ){
20140 sign = -1;
20141 z+=incr;
20142 }else if( *z=='+' ){
20143 z+=incr;
20144 }
20145
20146 /* skip leading zeroes */
20147 while( z<zEnd && z[0]=='0' ) z+=incr, nDigits++;
20148
20149 /* copy max significant digits to significand */
20150 while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
20151 s = s*10 + (*z - '0');
20152 z+=incr, nDigits++;
20153 }
20154
20155 /* skip non-significant significand digits
20156 ** (increase exponent by d to shift decimal left) */
20157 while( z<zEnd && sqlite3Isdigit(*z) ) z+=incr, nDigits++, d++;
20158 if( z>=zEnd ) goto do_atof_calc;
20159
20160 /* if decimal point is present */
20161 if( *z=='.' ){
20162 z+=incr;
20163 /* copy digits from after decimal to significand
20164 ** (decrease exponent by d to shift decimal right) */
20165 while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
20166 s = s*10 + (*z - '0');
20167 z+=incr, nDigits++, d--;
20168 }
20169 /* skip non-significant digits */
20170 while( z<zEnd && sqlite3Isdigit(*z) ) z+=incr, nDigits++;
20171 }
20172 if( z>=zEnd ) goto do_atof_calc;
20173
20174 /* if exponent is present */
20175 if( *z=='e' || *z=='E' ){
20176 z+=incr;
20177 eValid = 0;
20178 if( z>=zEnd ) goto do_atof_calc;
20179 /* get sign of exponent */
20180 if( *z=='-' ){
20181 esign = -1;
20182 z+=incr;
20183 }else if( *z=='+' ){
20184 z+=incr;
20185 }
20186 /* copy digits to exponent */
20187 while( z<zEnd && sqlite3Isdigit(*z) ){
20188 e = e*10 + (*z - '0');
20189 z+=incr;
20190 eValid = 1;
20191 }
20192 }
20193
20194 /* skip trailing spaces */
20195 if( nDigits && eValid ){
20196 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
20197 }
20198
20199 do_atof_calc:
20200 /* adjust exponent by d, and update sign */
20201 e = (e*esign) + d;
20202 if( e<0 ) {
20203 esign = -1;
20204 e *= -1;
@@ -19963,132 +20253,104 @@
20253 }
20254
20255 /* store the result */
20256 *pResult = result;
20257
20258 /* return true if number and no extra non-whitespace chracters after */
20259 return z>=zEnd && nDigits>0 && eValid;
20260 #else
20261 return !sqlite3Atoi64(z, pResult, length, enc);
20262 #endif /* SQLITE_OMIT_FLOATING_POINT */
20263 }
20264
20265 /*
20266 ** Compare the 19-character string zNum against the text representation
20267 ** value 2^63: 9223372036854775808. Return negative, zero, or positive
20268 ** if zNum is less than, equal to, or greater than the string.
20269 ** Note that zNum must contain exactly 19 characters.
20270 **
20271 ** Unlike memcmp() this routine is guaranteed to return the difference
20272 ** in the values of the last digit if the only difference is in the
20273 ** last digit. So, for example,
20274 **
20275 ** compare2pow63("9223372036854775800", 1)
20276 **
20277 ** will return -8.
20278 */
20279 static int compare2pow63(const char *zNum, int incr){
20280 int c = 0;
20281 int i;
20282 /* 012345678901234567 */
20283 const char *pow63 = "922337203685477580";
20284 for(i=0; c==0 && i<18; i++){
20285 c = (zNum[i*incr]-pow63[i])*10;
20286 }
20287 if( c==0 ){
20288 c = zNum[18*incr] - '8';
20289 testcase( c==(-1) );
20290 testcase( c==0 );
20291 testcase( c==(+1) );
20292 }
20293 return c;
20294 }
20295
20296
20297 /*
20298 ** Convert zNum to a 64-bit signed integer and write
20299 ** the value of the integer into *pNum.
20300 ** If zNum is exactly 9223372036854665808, return 2.
20301 ** This is a special case as the context will determine
20302 ** if it is too big (used as a negative).
20303 ** If zNum is not an integer or is an integer that
20304 ** is too large to be expressed with 64 bits,
20305 ** then return 1. Otherwise return 0.
20306 **
20307 ** length is the number of bytes in the string (bytes, not characters).
20308 ** The string is not necessarily zero-terminated. The encoding is
20309 ** given by enc.
20310 */
20311 SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
20312 int incr = (enc==SQLITE_UTF8?1:2);
20313 i64 v = 0;
20314 int neg = 0; /* assume positive */
20315 int i;
20316 int c = 0;
20317 const char *zStart;
20318 const char *zEnd = zNum + length;
20319 if( enc==SQLITE_UTF16BE ) zNum++;
20320 while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
20321 if( zNum>=zEnd ) goto do_atoi_calc;
20322 if( *zNum=='-' ){
20323 neg = 1;
20324 zNum+=incr;
20325 }else if( *zNum=='+' ){
20326 zNum+=incr;
 
 
 
20327 }
20328 do_atoi_calc:
20329 zStart = zNum;
20330 while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
20331 for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){
20332 v = v*10 + c - '0';
20333 }
20334 *pNum = neg ? -v : v;
20335 testcase( i==18 );
20336 testcase( i==19 );
20337 testcase( i==20 );
20338 if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr ){
20339 /* zNum is empty or contains non-numeric text or is longer
20340 ** than 19 digits (thus guaranteeing that it is too large) */
20341 return 1;
20342 }else if( i<19*incr ){
20343 /* Less than 19 digits, so we know that it fits in 64 bits */
20344 return 0;
20345 }else{
20346 /* 19-digit numbers must be no larger than 9223372036854775807 if positive
20347 ** or 9223372036854775808 if negative. Note that 9223372036854665808
20348 ** is 2^63. Return 1 if to large */
20349 c=compare2pow63(zNum, incr);
20350 if( c==0 && neg==0 ) return 2; /* too big, exactly 9223372036854665808 */
20351 return c<neg ? 0 : 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20352 }
20353 }
20354
20355 /*
20356 ** If zNum represents an integer that will fit in 32-bits, then set
@@ -26177,11 +26439,11 @@
26439 goto shmpage_out;
26440 }
26441 pShmNode->apRegion = apNew;
26442 while(pShmNode->nRegion<=iRegion){
26443 void *pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE,
26444 MAP_SHARED, pShmNode->h, pShmNode->nRegion*szRegion
26445 );
26446 if( pMem==MAP_FAILED ){
26447 rc = SQLITE_IOERR;
26448 goto shmpage_out;
26449 }
@@ -28000,17 +28262,20 @@
28262 static int proxyGetHostID(unsigned char *pHostID, int *pError){
28263 struct timespec timeout = {1, 0}; /* 1 sec timeout */
28264
28265 assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
28266 memset(pHostID, 0, PROXY_HOSTIDLEN);
28267 #if defined(__MAX_OS_X_VERSION_MIN_REQUIRED)\
28268 && __MAC_OS_X_VERSION_MIN_REQUIRED<1050
28269 if( gethostuuid(pHostID, &timeout) ){
28270 int err = errno;
28271 if( pError ){
28272 *pError = err;
28273 }
28274 return SQLITE_IOERR;
28275 }
28276 #endif
28277 #ifdef SQLITE_TEST
28278 /* simulate multiple hosts by creating unique hostid file paths */
28279 if( sqlite3_hostid_num != 0){
28280 pHostID[0] = (char)(pHostID[0] + (char)(sqlite3_hostid_num & 0xFF));
28281 }
@@ -30339,10 +30604,18 @@
30604 return SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN;
30605 }
30606
30607 #ifndef SQLITE_OMIT_WAL
30608
30609 /*
30610 ** Windows will only let you create file view mappings
30611 ** on allocation size granularity boundaries.
30612 ** During sqlite3_os_init() we do a GetSystemInfo()
30613 ** to get the granularity size.
30614 */
30615 SYSTEM_INFO winSysInfo;
30616
30617 /*
30618 ** Helper functions to obtain and relinquish the global mutex. The
30619 ** global mutex is used to protect the winLockInfo objects used by
30620 ** this file, all of which may be shared by multiple threads.
30621 **
@@ -30507,19 +30780,26 @@
30780 ** by VFS shared-memory methods.
30781 */
30782 static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
30783 winShmNode **pp;
30784 winShmNode *p;
30785 BOOL bRc;
30786 assert( winShmMutexHeld() );
30787 pp = &winShmNodeList;
30788 while( (p = *pp)!=0 ){
30789 if( p->nRef==0 ){
30790 int i;
30791 if( p->mutex ) sqlite3_mutex_free(p->mutex);
30792 for(i=0; i<p->nRegion; i++){
30793 bRc = UnmapViewOfFile(p->aRegion[i].pMap);
30794 OSTRACE(("SHM-PURGE pid-%d unmap region=%d %s\n",
30795 (int)GetCurrentProcessId(), i,
30796 bRc ? "ok" : "failed"));
30797 bRc = CloseHandle(p->aRegion[i].hMap);
30798 OSTRACE(("SHM-PURGE pid-%d close region=%d %s\n",
30799 (int)GetCurrentProcessId(), i,
30800 bRc ? "ok" : "failed"));
30801 }
30802 if( p->hFile.h != INVALID_HANDLE_VALUE ){
30803 SimulateIOErrorBenign(1);
30804 winClose((sqlite3_file *)&p->hFile);
30805 SimulateIOErrorBenign(0);
@@ -30592,14 +30872,15 @@
30872 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
30873 if( pShmNode->mutex==0 ){
30874 rc = SQLITE_NOMEM;
30875 goto shm_open_err;
30876 }
30877
30878 rc = winOpen(pDbFd->pVfs,
30879 pShmNode->zFilename, /* Name of the file (UTF-8) */
30880 (sqlite3_file*)&pShmNode->hFile, /* File handle here */
30881 SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, /* Mode flags */
30882 0);
30883 if( SQLITE_OK!=rc ){
30884 rc = SQLITE_CANTOPEN_BKPT;
30885 goto shm_open_err;
30886 }
@@ -30903,14 +31184,22 @@
31184 void *pMap = 0; /* Mapped memory region */
31185
31186 hMap = CreateFileMapping(pShmNode->hFile.h,
31187 NULL, PAGE_READWRITE, 0, nByte, NULL
31188 );
31189 OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n",
31190 (int)GetCurrentProcessId(), pShmNode->nRegion, nByte,
31191 hMap ? "ok" : "failed"));
31192 if( hMap ){
31193 int iOffset = pShmNode->nRegion*szRegion;
31194 int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
31195 pMap = MapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
31196 0, iOffset - iOffsetShift, szRegion + iOffsetShift
31197 );
31198 OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n",
31199 (int)GetCurrentProcessId(), pShmNode->nRegion, iOffset, szRegion,
31200 pMap ? "ok" : "failed"));
31201 }
31202 if( !pMap ){
31203 pShmNode->lastErrno = GetLastError();
31204 rc = SQLITE_IOERR;
31205 if( hMap ) CloseHandle(hMap);
@@ -30923,12 +31212,14 @@
31212 }
31213 }
31214
31215 shmpage_out:
31216 if( pShmNode->nRegion>iRegion ){
31217 int iOffset = iRegion*szRegion;
31218 int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
31219 char *p = (char *)pShmNode->aRegion[iRegion].pMap;
31220 *pp = (void *)&p[iOffsetShift];
31221 }else{
31222 *pp = 0;
31223 }
31224 sqlite3_mutex_leave(pShmNode->mutex);
31225 return rc;
@@ -31151,13 +31442,64 @@
31442 DWORD dwFlagsAndAttributes = 0;
31443 #if SQLITE_OS_WINCE
31444 int isTemp = 0;
31445 #endif
31446 winFile *pFile = (winFile*)id;
31447 void *zConverted; /* Filename in OS encoding */
31448 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
31449
31450 /* If argument zPath is a NULL pointer, this function is required to open
31451 ** a temporary file. Use this buffer to store the file name in.
31452 */
31453 char zTmpname[MAX_PATH+1]; /* Buffer used to create temp filename */
31454
31455 int rc = SQLITE_OK; /* Function Return Code */
31456 #if !defined(NDEBUG) || SQLITE_OS_WINCE
31457 int eType = flags&0xFFFFFF00; /* Type of file to open */
31458 #endif
31459
31460 int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
31461 int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE);
31462 int isCreate = (flags & SQLITE_OPEN_CREATE);
31463 #ifndef NDEBUG
31464 int isReadonly = (flags & SQLITE_OPEN_READONLY);
31465 #endif
31466 int isReadWrite = (flags & SQLITE_OPEN_READWRITE);
31467
31468 #ifndef NDEBUG
31469 int isOpenJournal = (isCreate && (
31470 eType==SQLITE_OPEN_MASTER_JOURNAL
31471 || eType==SQLITE_OPEN_MAIN_JOURNAL
31472 || eType==SQLITE_OPEN_WAL
31473 ));
31474 #endif
31475
31476 /* Check the following statements are true:
31477 **
31478 ** (a) Exactly one of the READWRITE and READONLY flags must be set, and
31479 ** (b) if CREATE is set, then READWRITE must also be set, and
31480 ** (c) if EXCLUSIVE is set, then CREATE must also be set.
31481 ** (d) if DELETEONCLOSE is set, then CREATE must also be set.
31482 */
31483 assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
31484 assert(isCreate==0 || isReadWrite);
31485 assert(isExclusive==0 || isCreate);
31486 assert(isDelete==0 || isCreate);
31487
31488 /* The main DB, main journal, WAL file and master journal are never
31489 ** automatically deleted. Nor are they ever temporary files. */
31490 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB );
31491 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL );
31492 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MASTER_JOURNAL );
31493 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL );
31494
31495 /* Assert that the upper layer has set one of the "file-type" flags. */
31496 assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
31497 || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
31498 || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
31499 || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
31500 );
31501
31502 assert( id!=0 );
31503 UNUSED_PARAMETER(pVfs);
31504
31505 pFile->h = INVALID_HANDLE_VALUE;
@@ -31164,11 +31506,12 @@
31506
31507 /* If the second argument to this function is NULL, generate a
31508 ** temporary file name to use
31509 */
31510 if( !zUtf8Name ){
31511 assert(isDelete && !isOpenJournal);
31512 rc = getTempname(MAX_PATH+1, zTmpname);
31513 if( rc!=SQLITE_OK ){
31514 return rc;
31515 }
31516 zUtf8Name = zTmpname;
31517 }
@@ -31177,33 +31520,35 @@
31520 zConverted = convertUtf8Filename(zUtf8Name);
31521 if( zConverted==0 ){
31522 return SQLITE_NOMEM;
31523 }
31524
31525 if( isReadWrite ){
31526 dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
31527 }else{
31528 dwDesiredAccess = GENERIC_READ;
31529 }
31530
31531 /* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is
31532 ** created. SQLite doesn't use it to indicate "exclusive access"
31533 ** as it is usually understood.
31534 */
31535 if( isExclusive ){
 
31536 /* Creates a new file, only if it does not already exist. */
31537 /* If the file exists, it fails. */
31538 dwCreationDisposition = CREATE_NEW;
31539 }else if( isCreate ){
31540 /* Open existing file, or create if it doesn't exist */
31541 dwCreationDisposition = OPEN_ALWAYS;
31542 }else{
31543 /* Opens a file, only if it exists. */
31544 dwCreationDisposition = OPEN_EXISTING;
31545 }
31546
31547 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
31548
31549 if( isDelete ){
31550 #if SQLITE_OS_WINCE
31551 dwFlagsAndAttributes = FILE_ATTRIBUTE_HIDDEN;
31552 isTemp = 1;
31553 #else
31554 dwFlagsAndAttributes = FILE_ATTRIBUTE_TEMPORARY
@@ -31216,10 +31561,11 @@
31561 /* Reports from the internet are that performance is always
31562 ** better if FILE_FLAG_RANDOM_ACCESS is used. Ticket #2699. */
31563 #if SQLITE_OS_WINCE
31564 dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
31565 #endif
31566
31567 if( isNT() ){
31568 h = CreateFileW((WCHAR*)zConverted,
31569 dwDesiredAccess,
31570 dwShareMode,
31571 NULL,
@@ -31241,41 +31587,45 @@
31587 dwFlagsAndAttributes,
31588 NULL
31589 );
31590 #endif
31591 }
31592
31593 OSTRACE(("OPEN %d %s 0x%lx %s\n",
31594 h, zName, dwDesiredAccess,
31595 h==INVALID_HANDLE_VALUE ? "failed" : "ok"));
31596
31597 if( h==INVALID_HANDLE_VALUE ){
31598 pFile->lastErrno = GetLastError();
31599 free(zConverted);
31600 if( isReadWrite ){
31601 return winOpen(pVfs, zName, id,
31602 ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)), pOutFlags);
31603 }else{
31604 return SQLITE_CANTOPEN_BKPT;
31605 }
31606 }
31607
31608 if( pOutFlags ){
31609 if( isReadWrite ){
31610 *pOutFlags = SQLITE_OPEN_READWRITE;
31611 }else{
31612 *pOutFlags = SQLITE_OPEN_READONLY;
31613 }
31614 }
31615
31616 memset(pFile, 0, sizeof(*pFile));
31617 pFile->pMethod = &winIoMethod;
31618 pFile->h = h;
31619 pFile->lastErrno = NO_ERROR;
31620 pFile->pVfs = pVfs;
31621 pFile->pShm = 0;
31622 pFile->zPath = zName;
31623 pFile->sectorSize = getSectorSize(pVfs, zUtf8Name);
31624
31625 #if SQLITE_OS_WINCE
31626 if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
 
31627 && !winceCreateLock(zName, pFile)
31628 ){
31629 CloseHandle(h);
31630 free(zConverted);
31631 return SQLITE_CANTOPEN_BKPT;
@@ -31285,12 +31635,13 @@
31635 }else
31636 #endif
31637 {
31638 free(zConverted);
31639 }
31640
31641 OpenCounter(+1);
31642 return rc;
31643 }
31644
31645 /*
31646 ** Delete the named file.
31647 **
@@ -31804,10 +32155,17 @@
32155 winSleep, /* xSleep */
32156 winCurrentTime, /* xCurrentTime */
32157 winGetLastError, /* xGetLastError */
32158 winCurrentTimeInt64, /* xCurrentTimeInt64 */
32159 };
32160
32161 #ifndef SQLITE_OMIT_WAL
32162 /* get memory map allocation granularity */
32163 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
32164 GetSystemInfo(&winSysInfo);
32165 assert(winSysInfo.dwAllocationGranularity > 0);
32166 #endif
32167
32168 sqlite3_vfs_register(&winVfs, 1);
32169 return SQLITE_OK;
32170 }
32171 SQLITE_API int sqlite3_os_end(void){
@@ -32369,16 +32727,20 @@
32727 ** Initialize and shutdown the page cache subsystem. Neither of these
32728 ** functions are threadsafe.
32729 */
32730 SQLITE_PRIVATE int sqlite3PcacheInitialize(void){
32731 if( sqlite3GlobalConfig.pcache.xInit==0 ){
32732 /* IMPLEMENTATION-OF: R-26801-64137 If the xInit() method is NULL, then the
32733 ** built-in default page cache is used instead of the application defined
32734 ** page cache. */
32735 sqlite3PCacheSetDefault();
32736 }
32737 return sqlite3GlobalConfig.pcache.xInit(sqlite3GlobalConfig.pcache.pArg);
32738 }
32739 SQLITE_PRIVATE void sqlite3PcacheShutdown(void){
32740 if( sqlite3GlobalConfig.pcache.xShutdown ){
32741 /* IMPLEMENTATION-OF: R-26000-56589 The xShutdown() method may be NULL. */
32742 sqlite3GlobalConfig.pcache.xShutdown(sqlite3GlobalConfig.pcache.pArg);
32743 }
32744 }
32745
32746 /*
@@ -32835,12 +33197,17 @@
33197
33198 typedef struct PCache1 PCache1;
33199 typedef struct PgHdr1 PgHdr1;
33200 typedef struct PgFreeslot PgFreeslot;
33201
33202 /* Each page cache is an instance of the following object. Every
33203 ** open database file (including each in-memory database and each
33204 ** temporary or transient database) has a single page cache which
33205 ** is an instance of this object.
33206 **
33207 ** Pointers to structures of this type are cast and returned as
33208 ** opaque sqlite3_pcache* handles.
33209 */
33210 struct PCache1 {
33211 /* Cache configuration parameters. Page size (szPage) and the purgeable
33212 ** flag (bPurgeable) are set when the cache is created. nMax may be
33213 ** modified at any time by a call to the pcache1CacheSize() method.
@@ -32896,10 +33263,13 @@
33263 int nCurrentPage; /* Number of purgeable pages allocated */
33264 PgHdr1 *pLruHead, *pLruTail; /* LRU list of unpinned pages */
33265
33266 /* Variables related to SQLITE_CONFIG_PAGECACHE settings. */
33267 int szSlot; /* Size of each free slot */
33268 int nSlot; /* The number of pcache slots */
33269 int nFreeSlot; /* Number of unused pcache slots */
33270 int nReserve; /* Try to keep nFreeSlot above this */
33271 void *pStart, *pEnd; /* Bounds of pagecache malloc range */
33272 PgFreeslot *pFree; /* Free page blocks */
33273 int isInit; /* True if initialized */
33274 } pcache1_g;
33275
@@ -32943,10 +33313,12 @@
33313 SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){
33314 if( pcache1.isInit ){
33315 PgFreeslot *p;
33316 sz = ROUNDDOWN8(sz);
33317 pcache1.szSlot = sz;
33318 pcache1.nSlot = pcache1.nFreeSlot = n;
33319 pcache1.nReserve = n>90 ? 10 : (n/10 + 1);
33320 pcache1.pStart = pBuf;
33321 pcache1.pFree = 0;
33322 while( n-- ){
33323 p = (PgFreeslot*)pBuf;
33324 p->pNext = pcache1.pFree;
@@ -32969,10 +33341,12 @@
33341 sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
33342 if( nByte<=pcache1.szSlot && pcache1.pFree ){
33343 assert( pcache1.isInit );
33344 p = (PgHdr1 *)pcache1.pFree;
33345 pcache1.pFree = pcache1.pFree->pNext;
33346 pcache1.nFreeSlot--;
33347 assert( pcache1.nFreeSlot>=0 );
33348 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);
33349 }else{
33350
33351 /* Allocate a new buffer using sqlite3Malloc. Before doing so, exit the
33352 ** global pcache mutex and unlock the pager-cache object pCache. This is
@@ -33002,10 +33376,12 @@
33376 PgFreeslot *pSlot;
33377 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
33378 pSlot = (PgFreeslot*)p;
33379 pSlot->pNext = pcache1.pFree;
33380 pcache1.pFree = pSlot;
33381 pcache1.nFreeSlot++;
33382 assert( pcache1.nFreeSlot<=pcache1.nSlot );
33383 }else{
33384 int iSize;
33385 assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
33386 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
33387 iSize = sqlite3MallocSize(p);
@@ -33014,11 +33390,11 @@
33390 }
33391 }
33392
33393 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
33394 /*
33395 ** Return the size of a pcache allocation
33396 */
33397 static int pcache1MemSize(void *p){
33398 assert( sqlite3_mutex_held(pcache1.mutex) );
33399 if( p>=pcache1.pStart && p<pcache1.pEnd ){
33400 return pcache1.szSlot;
@@ -33087,10 +33463,36 @@
33463 pcache1EnterMutex();
33464 pcache1Free(p);
33465 pcache1LeaveMutex();
33466 }
33467
33468
33469 /*
33470 ** Return true if it desirable to avoid allocating a new page cache
33471 ** entry.
33472 **
33473 ** If memory was allocated specifically to the page cache using
33474 ** SQLITE_CONFIG_PAGECACHE but that memory has all been used, then
33475 ** it is desirable to avoid allocating a new page cache entry because
33476 ** presumably SQLITE_CONFIG_PAGECACHE was suppose to be sufficient
33477 ** for all page cache needs and we should not need to spill the
33478 ** allocation onto the heap.
33479 **
33480 ** Or, the heap is used for all page cache memory put the heap is
33481 ** under memory pressure, then again it is desirable to avoid
33482 ** allocating a new page cache entry in order to avoid stressing
33483 ** the heap even further.
33484 */
33485 static int pcache1UnderMemoryPressure(PCache1 *pCache){
33486 assert( sqlite3_mutex_held(pcache1.mutex) );
33487 if( pcache1.nSlot && pCache->szPage<=pcache1.szSlot ){
33488 return pcache1.nFreeSlot<pcache1.nReserve;
33489 }else{
33490 return sqlite3HeapNearlyFull();
33491 }
33492 }
33493
33494 /******************************************************************************/
33495 /******** General Implementation Functions ************************************/
33496
33497 /*
33498 ** This function is used to resize the hash table used by the cache passed
@@ -33328,18 +33730,20 @@
33730 ** copy of the requested page. If one is found, it is returned.
33731 **
33732 ** 2. If createFlag==0 and the page is not already in the cache, NULL is
33733 ** returned.
33734 **
33735 ** 3. If createFlag is 1, and the page is not already in the cache, then
33736 ** return NULL (do not allocate a new page) if any of the following
33737 ** conditions are true:
33738 **
33739 ** (a) the number of pages pinned by the cache is greater than
33740 ** PCache1.nMax, or
33741 **
33742 ** (b) the number of pages pinned by the cache is greater than
33743 ** the sum of nMax for all purgeable caches, less the sum of
33744 ** nMin for all other purgeable caches, or
33745 **
33746 ** 4. If none of the first three conditions apply and the cache is marked
33747 ** as purgeable, and if one of the following is true:
33748 **
33749 ** (a) The number of pages allocated for the cache is already
@@ -33346,10 +33750,13 @@
33750 ** PCache1.nMax, or
33751 **
33752 ** (b) The number of pages allocated for all purgeable caches is
33753 ** already equal to or greater than the sum of nMax for all
33754 ** purgeable caches,
33755 **
33756 ** (c) The system is under memory pressure and wants to avoid
33757 ** unnecessary pages cache entry allocations
33758 **
33759 ** then attempt to recycle a page from the LRU list. If it is the right
33760 ** size, return the recycled buffer. Otherwise, free the buffer and
33761 ** proceed to step 5.
33762 **
@@ -33378,10 +33785,11 @@
33785 /* Step 3 of header comment. */
33786 nPinned = pCache->nPage - pCache->nRecyclable;
33787 if( createFlag==1 && (
33788 nPinned>=(pcache1.nMaxPage+pCache->nMin-pcache1.nMinPage)
33789 || nPinned>=(pCache->nMax * 9 / 10)
33790 || pcache1UnderMemoryPressure(pCache)
33791 )){
33792 goto fetch_out;
33793 }
33794
33795 if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){
@@ -33388,11 +33796,13 @@
33796 goto fetch_out;
33797 }
33798
33799 /* Step 4. Try to recycle a page buffer if appropriate. */
33800 if( pCache->bPurgeable && pcache1.pLruTail && (
33801 (pCache->nPage+1>=pCache->nMax)
33802 || pcache1.nCurrentPage>=pcache1.nMaxPage
33803 || pcache1UnderMemoryPressure(pCache)
33804 )){
33805 pPage = pcache1.pLruTail;
33806 pcache1RemoveFromHash(pPage);
33807 pcache1PinPage(pPage);
33808 if( pPage->pCache->szPage!=pCache->szPage ){
@@ -33531,10 +33941,11 @@
33941 **
33942 ** Destroy a cache allocated using pcache1Create().
33943 */
33944 static void pcache1Destroy(sqlite3_pcache *p){
33945 PCache1 *pCache = (PCache1 *)p;
33946 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
33947 pcache1EnterMutex();
33948 pcache1TruncateUnsafe(pCache, 0);
33949 pcache1.nMaxPage -= pCache->nMax;
33950 pcache1.nMinPage -= pCache->nMin;
33951 pcache1EnforceMaxPage();
@@ -33578,11 +33989,11 @@
33989 SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
33990 int nFree = 0;
33991 if( pcache1.pStart==0 ){
33992 PgHdr1 *p;
33993 pcache1EnterMutex();
33994 while( (nReq<0 || nFree<nReq) && ((p=pcache1.pLruTail)!=0) ){
33995 nFree += pcache1MemSize(PGHDR1_TO_PAGE(p));
33996 pcache1PinPage(p);
33997 pcache1RemoveFromHash(p);
33998 pcache1FreePage(p);
33999 }
@@ -37120,16 +37531,17 @@
37531 ** the duplicate call is harmless.
37532 */
37533 sqlite3WalEndReadTransaction(pPager->pWal);
37534
37535 rc = sqlite3WalBeginReadTransaction(pPager->pWal, &changed);
37536 if( rc!=SQLITE_OK || changed ){
37537 pager_reset(pPager);
37538 }
37539
37540 return rc;
37541 }
37542 #endif
37543
37544 /*
37545 ** This function is called as part of the transition from PAGER_OPEN
37546 ** to PAGER_READER state to determine the size of the database file
37547 ** in pages (assuming the page size currently stored in Pager.pageSize).
@@ -37182,11 +37594,11 @@
37594
37595 *pnPage = nPage;
37596 return SQLITE_OK;
37597 }
37598
37599 #ifndef SQLITE_OMIT_WAL
37600 /*
37601 ** Check if the *-wal file that corresponds to the database opened by pPager
37602 ** exists if the database is not empy, or verify that the *-wal file does
37603 ** not exist (by deleting it) if the database file is empty.
37604 **
@@ -38374,10 +38786,17 @@
38786 journalFileSize = ROUND8(sqlite3MemJournalSize());
38787 }
38788
38789 /* Set the output variable to NULL in case an error occurs. */
38790 *ppPager = 0;
38791
38792 #ifndef SQLITE_OMIT_MEMORYDB
38793 if( flags & PAGER_MEMORY ){
38794 memDb = 1;
38795 zFilename = 0;
38796 }
38797 #endif
38798
38799 /* Compute and store the full pathname in an allocated buffer pointed
38800 ** to by zPathname, length nPathname. Or, if this is a temporary file,
38801 ** leave both nPathname and zPathname set to 0.
38802 */
@@ -38385,21 +38804,12 @@
38804 nPathname = pVfs->mxPathname+1;
38805 zPathname = sqlite3Malloc(nPathname*2);
38806 if( zPathname==0 ){
38807 return SQLITE_NOMEM;
38808 }
38809 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
38810 rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
 
 
 
 
 
 
 
 
 
38811 nPathname = sqlite3Strlen30(zPathname);
38812 if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){
38813 /* This branch is taken when the journal path required by
38814 ** the database being opened will be more than pVfs->mxPathname
38815 ** bytes in length. This means the database cannot be opened,
@@ -38450,34 +38860,31 @@
38860 pPager->zFilename = (char*)(pPtr += journalFileSize);
38861 assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) );
38862
38863 /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
38864 if( zPathname ){
38865 assert( nPathname>0 );
38866 pPager->zJournal = (char*)(pPtr += nPathname + 1);
38867 memcpy(pPager->zFilename, zPathname, nPathname);
38868 memcpy(pPager->zJournal, zPathname, nPathname);
38869 memcpy(&pPager->zJournal[nPathname], "-journal", 8);
 
 
 
38870 #ifndef SQLITE_OMIT_WAL
38871 pPager->zWal = &pPager->zJournal[nPathname+8+1];
38872 memcpy(pPager->zWal, zPathname, nPathname);
38873 memcpy(&pPager->zWal[nPathname], "-wal", 4);
 
 
38874 #endif
38875 sqlite3_free(zPathname);
38876 }
38877 pPager->pVfs = pVfs;
38878 pPager->vfsFlags = vfsFlags;
38879
38880 /* Open the pager file.
38881 */
38882 if( zFilename && zFilename[0] ){
38883 int fout = 0; /* VFS flags returned by xOpen() */
38884 rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
38885 assert( !memDb );
38886 readOnly = (fout&SQLITE_OPEN_READONLY);
38887
38888 /* If the file was successfully opened for read/write access,
38889 ** choose a default page size in case we have to create the
38890 ** database file. The default page size is the maximum of:
@@ -38927,11 +39334,13 @@
39334
39335 /* If there is a WAL file in the file-system, open this database in WAL
39336 ** mode. Otherwise, the following function call is a no-op.
39337 */
39338 rc = pagerOpenWalIfPresent(pPager);
39339 #ifndef SQLITE_OMIT_WAL
39340 assert( pPager->pWal==0 || rc==SQLITE_OK );
39341 #endif
39342 }
39343
39344 if( pagerUseWal(pPager) ){
39345 assert( rc==SQLITE_OK );
39346 rc = pagerBeginReadTransaction(pPager);
@@ -43292,11 +43701,11 @@
43701 WALTRACE(("WAL%p: wal-header write %s\n", pWal, rc ? "failed" : "ok"));
43702 if( rc!=SQLITE_OK ){
43703 return rc;
43704 }
43705 }
43706 assert( (int)pWal->szPage==szPage );
43707
43708 /* Write the log file. */
43709 for(p=pList; p; p=p->pDirty){
43710 u32 nDbsize; /* Db-size field for frame header */
43711 i64 iOffset; /* Write offset in log file */
@@ -43952,10 +44361,11 @@
44361 MemPage *pPage1; /* First page of the database */
44362 u8 readOnly; /* True if the underlying file is readonly */
44363 u8 pageSizeFixed; /* True if the page size can no longer be changed */
44364 u8 secureDelete; /* True if secure_delete is enabled */
44365 u8 initiallyEmpty; /* Database is empty at start of transaction */
44366 u8 openFlags; /* Flags to sqlite3BtreeOpen() */
44367 #ifndef SQLITE_OMIT_AUTOVACUUM
44368 u8 autoVacuum; /* True if auto-vacuum is enabled */
44369 u8 incrVacuum; /* True if incr-vacuum is enabled */
44370 #endif
44371 u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
@@ -46202,15 +46612,24 @@
46612
46613 /*
46614 ** Open a database file.
46615 **
46616 ** zFilename is the name of the database file. If zFilename is NULL
46617 ** then an ephemeral database is created. The ephemeral database might
46618 ** be exclusively in memory, or it might use a disk-based memory cache.
46619 ** Either way, the ephemeral database will be automatically deleted
46620 ** when sqlite3BtreeClose() is called.
46621 **
46622 ** If zFilename is ":memory:" then an in-memory database is created
46623 ** that is automatically destroyed when it is closed.
46624 **
46625 ** The "flags" parameter is a bitmask that might contain bits
46626 ** BTREE_OMIT_JOURNAL and/or BTREE_NO_READLOCK. The BTREE_NO_READLOCK
46627 ** bit is also set if the SQLITE_NoReadlock flags is set in db->flags.
46628 ** These flags are passed through into sqlite3PagerOpen() and must
46629 ** be the same values as PAGER_OMIT_JOURNAL and PAGER_NO_READLOCK.
46630 **
46631 ** If the database is already opened in the same database connection
46632 ** and we are in shared cache mode, then the open will fail with an
46633 ** SQLITE_CONSTRAINT error. We cannot allow two or more BtShared
46634 ** objects in the same database connection since doing so will lead
46635 ** to problems with locking.
@@ -46227,10 +46646,13 @@
46646 Btree *p; /* Handle to return */
46647 sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */
46648 int rc = SQLITE_OK; /* Result code from this function */
46649 u8 nReserve; /* Byte of unused space on each page */
46650 unsigned char zDbHeader[100]; /* Database header content */
46651
46652 /* True if opening an ephemeral, temporary database */
46653 const int isTempDb = zFilename==0 || zFilename[0]==0;
46654
46655 /* Set the variable isMemdb to true for an in-memory database, or
46656 ** false for a file-based database. This symbol is only required if
46657 ** either of the shared-data or autovacuum features are compiled
46658 ** into the library.
@@ -46237,17 +46659,34 @@
46659 */
46660 #if !defined(SQLITE_OMIT_SHARED_CACHE) || !defined(SQLITE_OMIT_AUTOVACUUM)
46661 #ifdef SQLITE_OMIT_MEMORYDB
46662 const int isMemdb = 0;
46663 #else
46664 const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0)
46665 || (isTempDb && sqlite3TempInMemory(db));
46666 #endif
46667 #endif
46668
46669 assert( db!=0 );
46670 assert( sqlite3_mutex_held(db->mutex) );
46671 assert( (flags&0xff)==flags ); /* flags fit in 8 bits */
46672
46673 /* Only a BTREE_SINGLE database can be BTREE_UNORDERED */
46674 assert( (flags & BTREE_UNORDERED)==0 || (flags & BTREE_SINGLE)!=0 );
46675
46676 /* A BTREE_SINGLE database is always a temporary and/or ephemeral */
46677 assert( (flags & BTREE_SINGLE)==0 || isTempDb );
46678
46679 if( db->flags & SQLITE_NoReadlock ){
46680 flags |= BTREE_NO_READLOCK;
46681 }
46682 if( isMemdb ){
46683 flags |= BTREE_MEMORY;
46684 }
46685 if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){
46686 vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB;
46687 }
46688 pVfs = db->pVfs;
46689 p = sqlite3MallocZero(sizeof(Btree));
46690 if( !p ){
46691 return SQLITE_NOMEM;
46692 }
@@ -46261,11 +46700,11 @@
46700 #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
46701 /*
46702 ** If this Btree is a candidate for shared cache, try to find an
46703 ** existing BtShared object that we can share with
46704 */
46705 if( isMemdb==0 && isTempDb==0 ){
46706 if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){
46707 int nFullPathname = pVfs->mxPathname+1;
46708 char *zFullPathname = sqlite3Malloc(nFullPathname);
46709 sqlite3_mutex *mutexShared;
46710 p->sharable = 1;
@@ -46336,10 +46775,11 @@
46775 rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
46776 }
46777 if( rc!=SQLITE_OK ){
46778 goto btree_open_out;
46779 }
46780 pBt->openFlags = (u8)flags;
46781 pBt->db = db;
46782 sqlite3PagerSetBusyhandler(pBt->pPager, btreeInvokeBusyHandler, pBt);
46783 p->pBt = pBt;
46784
46785 pBt->pCursor = 0;
@@ -46440,10 +46880,18 @@
46880 sqlite3PagerClose(pBt->pPager);
46881 }
46882 sqlite3_free(pBt);
46883 sqlite3_free(p);
46884 *ppBtree = 0;
46885 }else{
46886 /* If the B-Tree was successfully opened, set the pager-cache size to the
46887 ** default value. Except, when opening on an existing shared pager-cache,
46888 ** do not change the pager-cache size.
46889 */
46890 if( sqlite3BtreeSchema(p, 0, 0)==0 ){
46891 sqlite3PagerSetCachesize(p->pBt->pPager, SQLITE_DEFAULT_CACHE_SIZE);
46892 }
46893 }
46894 if( mutexOpen ){
46895 assert( sqlite3_mutex_held(mutexOpen) );
46896 sqlite3_mutex_leave(mutexOpen);
46897 }
@@ -51390,15 +51838,16 @@
51838 ** flags might not work:
51839 **
51840 ** BTREE_INTKEY|BTREE_LEAFDATA Used for SQL tables with rowid keys
51841 ** BTREE_ZERODATA Used for SQL indices
51842 */
51843 static int btreeCreateTable(Btree *p, int *piTable, int createTabFlags){
51844 BtShared *pBt = p->pBt;
51845 MemPage *pRoot;
51846 Pgno pgnoRoot;
51847 int rc;
51848 int ptfFlags; /* Page-type flage for the root page of new table */
51849
51850 assert( sqlite3BtreeHoldsMutex(p) );
51851 assert( pBt->inTransaction==TRANS_WRITE );
51852 assert( !pBt->readOnly );
51853
@@ -51513,12 +51962,18 @@
51962 rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
51963 if( rc ) return rc;
51964 }
51965 #endif
51966 assert( sqlite3PagerIswriteable(pRoot->pDbPage) );
51967 if( createTabFlags & BTREE_INTKEY ){
51968 ptfFlags = PTF_INTKEY | PTF_LEAFDATA | PTF_LEAF;
51969 }else{
51970 ptfFlags = PTF_ZERODATA | PTF_LEAF;
51971 }
51972 zeroPage(pRoot, ptfFlags);
51973 sqlite3PagerUnref(pRoot->pDbPage);
51974 assert( (pBt->openFlags & BTREE_SINGLE)==0 || pgnoRoot==2 );
51975 *piTable = (int)pgnoRoot;
51976 return SQLITE_OK;
51977 }
51978 SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree *p, int *piTable, int flags){
51979 int rc;
@@ -52774,11 +53229,14 @@
53229 sqlite3Error(
53230 pDestDb, SQLITE_ERROR, "source and destination must be distinct"
53231 );
53232 p = 0;
53233 }else {
53234 /* Allocate space for a new sqlite3_backup object...
53235 ** EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
53236 ** call to sqlite3_backup_init() and is destroyed by a call to
53237 ** sqlite3_backup_finish(). */
53238 p = (sqlite3_backup *)sqlite3_malloc(sizeof(sqlite3_backup));
53239 if( !p ){
53240 sqlite3Error(pDestDb, SQLITE_NOMEM, 0);
53241 }
53242 }
@@ -53157,10 +53615,13 @@
53615 if( p->pDestDb ){
53616 sqlite3_mutex_leave(p->pDestDb->mutex);
53617 }
53618 sqlite3BtreeLeave(p->pSrc);
53619 if( p->pDestDb ){
53620 /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
53621 ** call to sqlite3_backup_init() and is destroyed by a call to
53622 ** sqlite3_backup_finish(). */
53623 sqlite3_free(p);
53624 }
53625 sqlite3_mutex_leave(mutex);
53626 return rc;
53627 }
@@ -53408,10 +53869,13 @@
53869 return SQLITE_NOMEM;
53870 }
53871 pMem->z[pMem->n] = 0;
53872 pMem->z[pMem->n+1] = 0;
53873 pMem->flags |= MEM_Term;
53874 #ifdef SQLITE_DEBUG
53875 pMem->pScopyFrom = 0;
53876 #endif
53877 }
53878
53879 return SQLITE_OK;
53880 }
53881
@@ -53528,11 +53992,11 @@
53992 memset(&ctx, 0, sizeof(ctx));
53993 ctx.s.flags = MEM_Null;
53994 ctx.s.db = pMem->db;
53995 ctx.pMem = pMem;
53996 ctx.pFunc = pFunc;
53997 pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
53998 assert( 0==(pMem->flags&MEM_Dyn) && !pMem->xDel );
53999 sqlite3DbFree(pMem->db, pMem->zMalloc);
54000 memcpy(pMem, &ctx.s, sizeof(ctx.s));
54001 rc = ctx.isError;
54002 }
@@ -53641,17 +54105,13 @@
54105 return pMem->u.i;
54106 }else if( flags & MEM_Real ){
54107 return doubleToInt64(pMem->r);
54108 }else if( flags & (MEM_Str|MEM_Blob) ){
54109 i64 value;
54110 assert( pMem->z || pMem->n==0 );
54111 testcase( pMem->z==0 );
54112 sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
 
 
 
 
54113 return value;
54114 }else{
54115 return 0;
54116 }
54117 }
@@ -53677,11 +54137,11 @@
54137 || sqlite3VdbeMemNulTerminate(pMem) ){
54138 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
54139 return (double)0;
54140 }
54141 assert( pMem->z );
54142 sqlite3AtoF(pMem->z, &val, pMem->n, SQLITE_UTF8);
54143 return val;
54144 }else{
54145 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
54146 return (double)0;
54147 }
@@ -53750,25 +54210,23 @@
54210 ** Every effort is made to force the conversion, even if the input
54211 ** is a string that does not look completely like a number. Convert
54212 ** as much of the string as we can and ignore the rest.
54213 */
54214 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem *pMem){
54215 if( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))==0 ){
54216 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
54217 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54218 if( 0==sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc) ){
54219 MemSetTypeFlag(pMem, MEM_Int);
54220 }else{
54221 pMem->r = sqlite3VdbeRealValue(pMem);
54222 MemSetTypeFlag(pMem, MEM_Real);
54223 sqlite3VdbeIntegerAffinity(pMem);
54224 }
54225 }
54226 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))!=0 );
54227 pMem->flags &= ~(MEM_Str|MEM_Blob);
 
 
54228 return SQLITE_OK;
54229 }
54230
54231 /*
54232 ** Delete any previous value and set the value stored in *pMem to NULL.
@@ -53869,10 +54327,32 @@
54327 return n>p->db->aLimit[SQLITE_LIMIT_LENGTH];
54328 }
54329 return 0;
54330 }
54331
54332 #ifdef SQLITE_DEBUG
54333 /*
54334 ** This routine prepares a memory cell for modication by breaking
54335 ** its link to a shallow copy and by marking any current shallow
54336 ** copies of this cell as invalid.
54337 **
54338 ** This is used for testing and debugging only - to make sure shallow
54339 ** copies are not misused.
54340 */
54341 SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe *pVdbe, Mem *pMem){
54342 int i;
54343 Mem *pX;
54344 for(i=1, pX=&pVdbe->aMem[1]; i<=pVdbe->nMem; i++, pX++){
54345 if( pX->pScopyFrom==pMem ){
54346 pX->flags |= MEM_Invalid;
54347 pX->pScopyFrom = 0;
54348 }
54349 }
54350 pMem->pScopyFrom = 0;
54351 }
54352 #endif /* SQLITE_DEBUG */
54353
54354 /*
54355 ** Size of struct Mem not including the Mem.zMalloc member.
54356 */
54357 #define MEMCELLSIZE (size_t)(&(((Mem *)0)->zMalloc))
54358
@@ -54237,11 +54717,11 @@
54717 assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 );
54718 if( sqlite3VdbeMemMakeWriteable(pVal)!=SQLITE_OK ){
54719 return 0;
54720 }
54721 }
54722 sqlite3VdbeMemNulTerminate(pVal); /* IMP: R-59893-45467 */
54723 }else{
54724 assert( (pVal->flags&MEM_Blob)==0 );
54725 sqlite3VdbeMemStringify(pVal, enc);
54726 assert( 0==(1&SQLITE_PTR_TO_INT(pVal->z)) );
54727 }
@@ -54285,10 +54765,12 @@
54765 sqlite3_value **ppVal /* Write the new value here */
54766 ){
54767 int op;
54768 char *zVal = 0;
54769 sqlite3_value *pVal = 0;
54770 int negInt = 1;
54771 const char *zNeg = "";
54772
54773 if( !pExpr ){
54774 *ppVal = 0;
54775 return SQLITE_OK;
54776 }
@@ -54301,35 +54783,50 @@
54783 #ifdef SQLITE_ENABLE_STAT2
54784 if( op==TK_REGISTER ) op = pExpr->op2;
54785 #else
54786 if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
54787 #endif
54788
54789 /* Handle negative integers in a single step. This is needed in the
54790 ** case when the value is -9223372036854775808.
54791 */
54792 if( op==TK_UMINUS
54793 && (pExpr->pLeft->op==TK_INTEGER || pExpr->pLeft->op==TK_FLOAT) ){
54794 pExpr = pExpr->pLeft;
54795 op = pExpr->op;
54796 negInt = -1;
54797 zNeg = "-";
54798 }
54799
54800 if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
54801 pVal = sqlite3ValueNew(db);
54802 if( pVal==0 ) goto no_mem;
54803 if( ExprHasProperty(pExpr, EP_IntValue) ){
54804 sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt);
54805 }else{
54806 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
54807 if( zVal==0 ) goto no_mem;
54808 sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
54809 if( op==TK_FLOAT ) pVal->type = SQLITE_FLOAT;
54810 }
54811 if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
54812 sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
54813 }else{
54814 sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
54815 }
54816 if( pVal->flags & (MEM_Int|MEM_Real) ) pVal->flags &= ~MEM_Str;
54817 if( enc!=SQLITE_UTF8 ){
54818 sqlite3VdbeChangeEncoding(pVal, enc);
54819 }
54820 }else if( op==TK_UMINUS ) {
54821 /* This branch happens for multiple negative signs. Ex: -(-5) */
54822 if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){
54823 sqlite3VdbeMemNumerify(pVal);
54824 pVal->u.i = -1 * pVal->u.i;
54825 /* (double)-1 In case of SQLITE_OMIT_FLOATING_POINT... */
54826 pVal->r = (double)-1 * pVal->r;
54827 sqlite3ValueApplyAffinity(pVal, affinity, enc);
54828 }
54829 }
54830 #ifndef SQLITE_OMIT_BLOB_LITERAL
54831 else if( op==TK_BLOB ){
54832 int nVal;
@@ -56152,13 +56649,14 @@
56649 */
56650 for(i=0; i<db->nDb; i++){
56651 Btree *pBt = db->aDb[i].pBt;
56652 if( sqlite3BtreeIsInTrans(pBt) ){
56653 char const *zFile = sqlite3BtreeGetJournalname(pBt);
56654 if( zFile==0 ){
56655 continue; /* Ignore TEMP and :memory: databases */
56656 }
56657 assert( zFile[0]!=0 );
56658 if( !needSync && !sqlite3BtreeSyncDisabled(pBt) ){
56659 needSync = 1;
56660 }
56661 rc = sqlite3OsWrite(pMaster, zFile, sqlite3Strlen30(zFile)+1, offset);
56662 offset += sqlite3Strlen30(zFile)+1;
@@ -57618,10 +58116,12 @@
58116 ** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16().
58117 */
58118 SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt){
58119 int rc;
58120 if( pStmt==0 ){
58121 /* IMPLEMENTATION-OF: R-57228-12904 Invoking sqlite3_finalize() on a NULL
58122 ** pointer is a harmless no-op. */
58123 rc = SQLITE_OK;
58124 }else{
58125 Vdbe *v = (Vdbe*)pStmt;
58126 sqlite3 *db = v->db;
58127 #if SQLITE_THREADSAFE
@@ -57694,11 +58194,11 @@
58194 Mem *p = (Mem*)pVal;
58195 if( p->flags & (MEM_Blob|MEM_Str) ){
58196 sqlite3VdbeMemExpandBlob(p);
58197 p->flags &= ~MEM_Str;
58198 p->flags |= MEM_Blob;
58199 return p->n ? p->z : 0;
58200 }else{
58201 return sqlite3_value_text(pVal);
58202 }
58203 }
58204 SQLITE_API int sqlite3_value_bytes(sqlite3_value *pVal){
@@ -58048,10 +58548,16 @@
58548 }
58549
58550 /*
58551 ** Extract the user data from a sqlite3_context structure and return a
58552 ** pointer to it.
58553 **
58554 ** IMPLEMENTATION-OF: R-46798-50301 The sqlite3_context_db_handle() interface
58555 ** returns a copy of the pointer to the database connection (the 1st
58556 ** parameter) of the sqlite3_create_function() and
58557 ** sqlite3_create_function16() routines that originally registered the
58558 ** application defined function.
58559 */
58560 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){
58561 assert( p && p->pFunc );
58562 return p->s.db;
58563 }
@@ -58257,12 +58763,11 @@
58763 ** sqlite3_column_text()
58764 ** sqlite3_column_text16()
58765 ** sqlite3_column_real()
58766 ** sqlite3_column_bytes()
58767 ** sqlite3_column_bytes16()
58768 ** sqiite3_column_blob()
 
58769 */
58770 static void columnMallocFailure(sqlite3_stmt *pStmt)
58771 {
58772 /* If malloc() failed during an encoding conversion within an
58773 ** sqlite3_column_XXX API, then set the return code of the statement to
@@ -58526,10 +59031,16 @@
59031 pVar->flags = MEM_Null;
59032 sqlite3Error(p->db, SQLITE_OK, 0);
59033
59034 /* If the bit corresponding to this variable in Vdbe.expmask is set, then
59035 ** binding a new value to this variable invalidates the current query plan.
59036 **
59037 ** IMPLEMENTATION-OF: R-48440-37595 If the specific value bound to host
59038 ** parameter in the WHERE clause might influence the choice of query plan
59039 ** for a statement, then the statement will be automatically recompiled,
59040 ** as if there had been a schema change, on the first sqlite3_step() call
59041 ** following any change to the bindings of that parameter.
59042 */
59043 if( p->isPrepareV2 &&
59044 ((i<32 && p->expmask & ((u32)1 << i)) || p->expmask==0xffffffff)
59045 ){
59046 p->expired = 1;
@@ -59023,10 +59534,21 @@
59534 ** of the code in this file is, therefore, important. See other comments
59535 ** in this file for details. If in doubt, do not deviate from existing
59536 ** commenting and indentation practices when changing or adding code.
59537 */
59538
59539 /*
59540 ** Invoke this macro on memory cells just prior to changing the
59541 ** value of the cell. This macro verifies that shallow copies are
59542 ** not misused.
59543 */
59544 #ifdef SQLITE_DEBUG
59545 # define memAboutToChange(P,M) sqlite3VdbeMemPrepareToChange(P,M)
59546 #else
59547 # define memAboutToChange(P,M)
59548 #endif
59549
59550 /*
59551 ** The following global variable is incremented every time a cursor
59552 ** moves, either by the OP_SeekXX, OP_Next, or OP_Prev opcodes. The test
59553 ** procedures use this information to make sure that indices are
59554 ** working correctly. This variable has no function other than to
@@ -59215,35 +59737,21 @@
59737 ** looks like a number, convert it into a number. If it does not
59738 ** look like a number, leave it alone.
59739 */
59740 static void applyNumericAffinity(Mem *pRec){
59741 if( (pRec->flags & (MEM_Real|MEM_Int))==0 ){
59742 double rValue;
59743 i64 iValue;
59744 u8 enc = pRec->enc;
59745 if( (pRec->flags&MEM_Str)==0 ) return;
59746 if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return;
59747 if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
59748 pRec->u.i = iValue;
59749 pRec->flags |= MEM_Int;
59750 }else{
59751 pRec->r = rValue;
59752 pRec->flags |= MEM_Real;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59753 }
59754 }
59755 }
59756
59757 /*
@@ -60132,38 +60640,44 @@
60640 assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
60641 if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){
60642 assert( pOp->p2>0 );
60643 assert( pOp->p2<=p->nMem );
60644 pOut = &aMem[pOp->p2];
60645 memAboutToChange(p, pOut);
60646 sqlite3VdbeMemReleaseExternal(pOut);
60647 pOut->flags = MEM_Int;
60648 }
60649
60650 /* Sanity checking on other operands */
60651 #ifdef SQLITE_DEBUG
60652 if( (pOp->opflags & OPFLG_IN1)!=0 ){
60653 assert( pOp->p1>0 );
60654 assert( pOp->p1<=p->nMem );
60655 assert( memIsValid(&aMem[pOp->p1]) );
60656 REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
60657 }
60658 if( (pOp->opflags & OPFLG_IN2)!=0 ){
60659 assert( pOp->p2>0 );
60660 assert( pOp->p2<=p->nMem );
60661 assert( memIsValid(&aMem[pOp->p2]) );
60662 REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
60663 }
60664 if( (pOp->opflags & OPFLG_IN3)!=0 ){
60665 assert( pOp->p3>0 );
60666 assert( pOp->p3<=p->nMem );
60667 assert( memIsValid(&aMem[pOp->p3]) );
60668 REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
60669 }
60670 if( (pOp->opflags & OPFLG_OUT2)!=0 ){
60671 assert( pOp->p2>0 );
60672 assert( pOp->p2<=p->nMem );
60673 memAboutToChange(p, &aMem[pOp->p2]);
60674 }
60675 if( (pOp->opflags & OPFLG_OUT3)!=0 ){
60676 assert( pOp->p3>0 );
60677 assert( pOp->p3<=p->nMem );
60678 memAboutToChange(p, &aMem[pOp->p3]);
60679 }
60680 #endif
60681
60682 switch( pOp->opcode ){
60683
@@ -60221,10 +60735,11 @@
60735 ** and then jump to address P2.
60736 */
60737 case OP_Gosub: { /* jump, in1 */
60738 pIn1 = &aMem[pOp->p1];
60739 assert( (pIn1->flags & MEM_Dyn)==0 );
60740 memAboutToChange(p, pIn1);
60741 pIn1->flags = MEM_Int;
60742 pIn1->u.i = pc;
60743 REGISTER_TRACE(pOp->p1, pIn1);
60744 pc = pOp->p2 - 1;
60745 break;
@@ -60428,15 +60943,11 @@
60943
60944
60945 /* Opcode: Blob P1 P2 * P4
60946 **
60947 ** P4 points to a blob of data P1 bytes long. Store this
60948 ** blob in register P2.
 
 
 
 
60949 */
60950 case OP_Blob: { /* out2-prerelease */
60951 assert( pOp->p1 <= SQLITE_MAX_LENGTH );
60952 sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
60953 pOut->enc = encoding;
@@ -60490,10 +61001,12 @@
61001 pIn1 = &aMem[u.ac.p1];
61002 pOut = &aMem[u.ac.p2];
61003 while( u.ac.n-- ){
61004 assert( pOut<=&aMem[p->nMem] );
61005 assert( pIn1<=&aMem[p->nMem] );
61006 assert( memIsValid(pIn1) );
61007 memAboutToChange(p, pOut);
61008 u.ac.zMalloc = pOut->zMalloc;
61009 pOut->zMalloc = 0;
61010 sqlite3VdbeMemMove(pOut, pIn1);
61011 pIn1->zMalloc = u.ac.zMalloc;
61012 REGISTER_TRACE(u.ac.p2++, pOut);
@@ -60535,10 +61048,13 @@
61048 case OP_SCopy: { /* in1, out2 */
61049 pIn1 = &aMem[pOp->p1];
61050 pOut = &aMem[pOp->p2];
61051 assert( pOut!=pIn1 );
61052 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
61053 #ifdef SQLITE_DEBUG
61054 if( pOut->pScopyFrom==0 ) pOut->pScopyFrom = pIn1;
61055 #endif
61056 REGISTER_TRACE(pOp->p2, pOut);
61057 break;
61058 }
61059
61060 /* Opcode: ResultRow P1 P2 * * *
@@ -60595,10 +61111,14 @@
61111 ** and have an assigned type. The results are de-ephemeralized as
61112 ** as side effect.
61113 */
61114 u.ad.pMem = p->pResultSet = &aMem[pOp->p1];
61115 for(u.ad.i=0; u.ad.i<pOp->p2; u.ad.i++){
61116 assert( memIsValid(&u.ad.pMem[u.ad.i]) );
61117 Deephemeralize(&u.ad.pMem[u.ad.i]);
61118 assert( (u.ad.pMem[u.ad.i].flags & MEM_Ephem)==0
61119 || (u.ad.pMem[u.ad.i].flags & (MEM_Str|MEM_Blob))==0 );
61120 sqlite3VdbeMemNulTerminate(&u.ad.pMem[u.ad.i]);
61121 sqlite3VdbeMemStoreType(&u.ad.pMem[u.ad.i]);
61122 REGISTER_TRACE(pOp->p1+u.ad.i, &u.ad.pMem[u.ad.i]);
61123 }
61124 if( db->mallocFailed ) goto no_mem;
@@ -60826,16 +61346,21 @@
61346 #endif /* local variables moved into u.ag */
61347
61348 u.ag.n = pOp->p5;
61349 u.ag.apVal = p->apArg;
61350 assert( u.ag.apVal || u.ag.n==0 );
61351 assert( pOp->p3>0 && pOp->p3<=p->nMem );
61352 pOut = &aMem[pOp->p3];
61353 memAboutToChange(p, pOut);
61354
61355 assert( u.ag.n==0 || (pOp->p2>0 && pOp->p2+u.ag.n<=p->nMem+1) );
61356 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.ag.n );
61357 u.ag.pArg = &aMem[pOp->p2];
61358 for(u.ag.i=0; u.ag.i<u.ag.n; u.ag.i++, u.ag.pArg++){
61359 assert( memIsValid(u.ag.pArg) );
61360 u.ag.apVal[u.ag.i] = u.ag.pArg;
61361 Deephemeralize(u.ag.pArg);
61362 sqlite3VdbeMemStoreType(u.ag.pArg);
61363 REGISTER_TRACE(pOp->p2+u.ag.i, u.ag.pArg);
61364 }
61365
61366 assert( pOp->p4type==P4_FUNCDEF || pOp->p4type==P4_VDBEFUNC );
@@ -60845,12 +61370,10 @@
61370 }else{
61371 u.ag.ctx.pVdbeFunc = (VdbeFunc*)pOp->p4.pVdbeFunc;
61372 u.ag.ctx.pFunc = u.ag.ctx.pVdbeFunc->pFunc;
61373 }
61374
 
 
61375 u.ag.ctx.s.flags = MEM_Null;
61376 u.ag.ctx.s.db = db;
61377 u.ag.ctx.s.xDel = 0;
61378 u.ag.ctx.s.zMalloc = 0;
61379
@@ -60866,11 +61389,11 @@
61389 assert( pOp>aOp );
61390 assert( pOp[-1].p4type==P4_COLLSEQ );
61391 assert( pOp[-1].opcode==OP_CollSeq );
61392 u.ag.ctx.pColl = pOp[-1].p4.pColl;
61393 }
61394 (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */
61395 if( db->mallocFailed ){
61396 /* Even though a malloc() has failed, the implementation of the
61397 ** user function may have called an sqlite3_result_XXX() function
61398 ** to return a value. The following call releases any resources
61399 ** associated with such a value.
@@ -60918,11 +61441,11 @@
61441 ** If either input is NULL, the result is NULL.
61442 */
61443 /* Opcode: ShiftLeft P1 P2 P3 * *
61444 **
61445 ** Shift the integer value in register P2 to the left by the
61446 ** number of bits specified by the integer in register P1.
61447 ** Store the result in register P3.
61448 ** If either input is NULL, the result is NULL.
61449 */
61450 /* Opcode: ShiftRight P1 P2 P3 * *
61451 **
@@ -60968,10 +61491,11 @@
61491 **
61492 ** To force any register to be an integer, just add 0.
61493 */
61494 case OP_AddImm: { /* in1 */
61495 pIn1 = &aMem[pOp->p1];
61496 memAboutToChange(p, pIn1);
61497 sqlite3VdbeMemIntegerify(pIn1);
61498 pIn1->u.i += pOp->p2;
61499 break;
61500 }
61501
@@ -60982,10 +61506,11 @@
61506 ** without data loss, then jump immediately to P2, or if P2==0
61507 ** raise an SQLITE_MISMATCH exception.
61508 */
61509 case OP_MustBeInt: { /* jump, in1 */
61510 pIn1 = &aMem[pOp->p1];
61511 memAboutToChange(p, pIn1);
61512 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
61513 if( (pIn1->flags & MEM_Int)==0 ){
61514 if( pOp->p2==0 ){
61515 rc = SQLITE_MISMATCH;
61516 goto abort_due_to_error;
@@ -61027,10 +61552,11 @@
61552 **
61553 ** A NULL value is not changed by this routine. It remains NULL.
61554 */
61555 case OP_ToText: { /* same as TK_TO_TEXT, in1 */
61556 pIn1 = &aMem[pOp->p1];
61557 memAboutToChange(p, pIn1);
61558 if( pIn1->flags & MEM_Null ) break;
61559 assert( MEM_Str==(MEM_Blob>>3) );
61560 pIn1->flags |= (pIn1->flags&MEM_Blob)>>3;
61561 applyAffinity(pIn1, SQLITE_AFF_TEXT, encoding);
61562 rc = ExpandBlob(pIn1);
@@ -61073,20 +61599,18 @@
61599 **
61600 ** A NULL value is not changed by this routine. It remains NULL.
61601 */
61602 case OP_ToNumeric: { /* same as TK_TO_NUMERIC, in1 */
61603 pIn1 = &aMem[pOp->p1];
61604 sqlite3VdbeMemNumerify(pIn1);
 
 
61605 break;
61606 }
61607 #endif /* SQLITE_OMIT_CAST */
61608
61609 /* Opcode: ToInt P1 * * * *
61610 **
61611 ** Force the value in register P1 to be an integer. If
61612 ** The value is currently a real number, drop its fractional part.
61613 ** If the value is text or blob, try to convert it to an integer using the
61614 ** equivalent of atoi() and store 0 if no such conversion is possible.
61615 **
61616 ** A NULL value is not changed by this routine. It remains NULL.
@@ -61109,10 +61633,11 @@
61633 **
61634 ** A NULL value is not changed by this routine. It remains NULL.
61635 */
61636 case OP_ToReal: { /* same as TK_TO_REAL, in1 */
61637 pIn1 = &aMem[pOp->p1];
61638 memAboutToChange(p, pIn1);
61639 if( (pIn1->flags & MEM_Null)==0 ){
61640 sqlite3VdbeMemRealify(pIn1);
61641 }
61642 break;
61643 }
@@ -61123,11 +61648,11 @@
61648 ** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
61649 ** jump to address P2.
61650 **
61651 ** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
61652 ** reg(P3) is NULL then take the jump. If the SQLITE_JUMPIFNULL
61653 ** bit is clear then fall through if either operand is NULL.
61654 **
61655 ** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
61656 ** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
61657 ** to coerce both inputs according to this affinity before the
61658 ** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
@@ -61253,10 +61778,11 @@
61778 default: u.ai.res = u.ai.res>=0; break;
61779 }
61780
61781 if( pOp->p5 & SQLITE_STOREP2 ){
61782 pOut = &aMem[pOp->p2];
61783 memAboutToChange(p, pOut);
61784 MemSetTypeFlag(pOut, MEM_Int);
61785 pOut->u.i = u.ai.res;
61786 REGISTER_TRACE(pOp->p2, pOut);
61787 }else if( u.ai.res ){
61788 pc = pOp->p2-1;
@@ -61284,12 +61810,12 @@
61810 break;
61811 }
61812
61813 /* Opcode: Compare P1 P2 P3 P4 *
61814 **
61815 ** Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this
61816 ** vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of
61817 ** the comparison for use by the next OP_Jump instruct.
61818 **
61819 ** P4 is a KeyInfo structure that defines collating sequences and sort
61820 ** orders for the comparison. The permutation applies to registers
61821 ** only. The KeyInfo elements are used sequentially.
@@ -61327,10 +61853,12 @@
61853 assert( u.aj.p2>0 && u.aj.p2+u.aj.n<=p->nMem+1 );
61854 }
61855 #endif /* SQLITE_DEBUG */
61856 for(u.aj.i=0; u.aj.i<u.aj.n; u.aj.i++){
61857 u.aj.idx = aPermute ? aPermute[u.aj.i] : u.aj.i;
61858 assert( memIsValid(&aMem[u.aj.p1+u.aj.idx]) );
61859 assert( memIsValid(&aMem[u.aj.p2+u.aj.idx]) );
61860 REGISTER_TRACE(u.aj.p1+u.aj.idx, &aMem[u.aj.p1+u.aj.idx]);
61861 REGISTER_TRACE(u.aj.p2+u.aj.idx, &aMem[u.aj.p2+u.aj.idx]);
61862 assert( u.aj.i<u.aj.pKeyInfo->nField );
61863 u.aj.pColl = u.aj.pKeyInfo->aColl[u.aj.i];
61864 u.aj.bRev = u.aj.pKeyInfo->aSortOrder[u.aj.i];
@@ -61558,10 +62086,11 @@
62086 u.am.pC = 0;
62087 memset(&u.am.sMem, 0, sizeof(u.am.sMem));
62088 assert( u.am.p1<p->nCursor );
62089 assert( pOp->p3>0 && pOp->p3<=p->nMem );
62090 u.am.pDest = &aMem[pOp->p3];
62091 memAboutToChange(p, u.am.pDest);
62092 MemSetTypeFlag(u.am.pDest, MEM_Null);
62093 u.am.zRec = 0;
62094
62095 /* This block sets the variable u.am.payloadSize to be the total number of
62096 ** bytes in the record.
@@ -61605,10 +62134,11 @@
62134 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
62135 }
62136 }else if( u.am.pC->pseudoTableReg>0 ){
62137 u.am.pReg = &aMem[u.am.pC->pseudoTableReg];
62138 assert( u.am.pReg->flags & MEM_Blob );
62139 assert( memIsValid(u.am.pReg) );
62140 u.am.payloadSize = u.am.pReg->n;
62141 u.am.zRec = u.am.pReg->z;
62142 u.am.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr;
62143 assert( u.am.payloadSize==0 || u.am.zRec!=0 );
62144 }else{
@@ -61829,25 +62359,23 @@
62359 assert( u.an.zAffinity!=0 );
62360 assert( u.an.zAffinity[pOp->p2]==0 );
62361 pIn1 = &aMem[pOp->p1];
62362 while( (u.an.cAff = *(u.an.zAffinity++))!=0 ){
62363 assert( pIn1 <= &p->aMem[p->nMem] );
62364 assert( memIsValid(pIn1) );
62365 ExpandBlob(pIn1);
62366 applyAffinity(pIn1, u.an.cAff, encoding);
62367 pIn1++;
62368 }
62369 break;
62370 }
62371
62372 /* Opcode: MakeRecord P1 P2 P3 P4 *
62373 **
62374 ** Convert P2 registers beginning with P1 into the [record format]
62375 ** use as a data record in a database table or as a key
62376 ** in an index. The OP_Column opcode can decode the record later.
 
 
 
62377 **
62378 ** P4 may be a string that is P2 characters long. The nth character of the
62379 ** string indicates the column affinity that should be used for the nth
62380 ** field of the index key.
62381 **
@@ -61899,15 +62427,21 @@
62427 assert( u.ao.nField>0 && pOp->p2>0 && pOp->p2+u.ao.nField<=p->nMem+1 );
62428 u.ao.pData0 = &aMem[u.ao.nField];
62429 u.ao.nField = pOp->p2;
62430 u.ao.pLast = &u.ao.pData0[u.ao.nField-1];
62431 u.ao.file_format = p->minWriteFileFormat;
62432
62433 /* Identify the output register */
62434 assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
62435 pOut = &aMem[pOp->p3];
62436 memAboutToChange(p, pOut);
62437
62438 /* Loop through the elements that will make up the record to figure
62439 ** out how much space is required for the new record.
62440 */
62441 for(u.ao.pRec=u.ao.pData0; u.ao.pRec<=u.ao.pLast; u.ao.pRec++){
62442 assert( memIsValid(u.ao.pRec) );
62443 if( u.ao.zAffinity ){
62444 applyAffinity(u.ao.pRec, u.ao.zAffinity[u.ao.pRec-u.ao.pData0], encoding);
62445 }
62446 if( u.ao.pRec->flags&MEM_Zero && u.ao.pRec->n>0 ){
62447 sqlite3VdbeMemExpandBlob(u.ao.pRec);
@@ -61938,12 +62472,10 @@
62472 /* Make sure the output register has a buffer large enough to store
62473 ** the new record. The output register (pOp->p3) is not allowed to
62474 ** be one of the input registers (because the following call to
62475 ** sqlite3VdbeMemGrow() could clobber the value before it is used).
62476 */
 
 
62477 if( sqlite3VdbeMemGrow(pOut, (int)u.ao.nByte, 0) ){
62478 goto no_mem;
62479 }
62480 u.ao.zNewRecord = (u8 *)pOut->z;
62481
@@ -62112,10 +62644,11 @@
62644 }
62645 }
62646 if( u.aq.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
62647 sqlite3ExpirePreparedStatements(db);
62648 sqlite3ResetInternalSchema(db, 0);
62649 db->flags = (db->flags | SQLITE_InternChanges);
62650 }
62651 }
62652
62653 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
62654 ** savepoints nested inside of the savepoint being operated on. */
@@ -62502,10 +63035,12 @@
63035 }
63036 if( pOp->p5 ){
63037 assert( u.aw.p2>0 );
63038 assert( u.aw.p2<=p->nMem );
63039 pIn2 = &aMem[u.aw.p2];
63040 assert( memIsValid(pIn2) );
63041 assert( (pIn2->flags & MEM_Int)!=0 );
63042 sqlite3VdbeMemIntegerify(pIn2);
63043 u.aw.p2 = (int)pIn2->u.i;
63044 /* The u.aw.p2 value always comes from a prior OP_CreateTable opcode and
63045 ** that opcode will always set the u.aw.p2 value to 2 or more or else fail.
63046 ** If there were a failure, the prepared statement would have halted
@@ -62524,10 +63059,11 @@
63059 }
63060 assert( pOp->p1>=0 );
63061 u.aw.pCur = allocateCursor(p, pOp->p1, u.aw.nField, u.aw.iDb, 1);
63062 if( u.aw.pCur==0 ) goto no_mem;
63063 u.aw.pCur->nullRow = 1;
63064 u.aw.pCur->isOrdered = 1;
63065 rc = sqlite3BtreeCursor(u.aw.pX, u.aw.p2, u.aw.wrFlag, u.aw.pKeyInfo, u.aw.pCur->pCursor);
63066 u.aw.pCur->pKeyInfo = u.aw.pKeyInfo;
63067
63068 /* Since it performs no memory allocation or IO, the only values that
63069 ** sqlite3BtreeCursor() may return are SQLITE_EMPTY and SQLITE_OK.
@@ -62576,11 +63112,11 @@
63112 case OP_OpenAutoindex:
63113 case OP_OpenEphemeral: {
63114 #if 0 /* local variables moved into u.ax */
63115 VdbeCursor *pCx;
63116 #endif /* local variables moved into u.ax */
63117 static const int vfsFlags =
63118 SQLITE_OPEN_READWRITE |
63119 SQLITE_OPEN_CREATE |
63120 SQLITE_OPEN_EXCLUSIVE |
63121 SQLITE_OPEN_DELETEONCLOSE |
63122 SQLITE_OPEN_TRANSIENT_DB;
@@ -62587,25 +63123,25 @@
63123
63124 assert( pOp->p1>=0 );
63125 u.ax.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
63126 if( u.ax.pCx==0 ) goto no_mem;
63127 u.ax.pCx->nullRow = 1;
63128 rc = sqlite3BtreeOpen(0, db, &u.ax.pCx->pBt,
63129 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
63130 if( rc==SQLITE_OK ){
63131 rc = sqlite3BtreeBeginTrans(u.ax.pCx->pBt, 1);
63132 }
63133 if( rc==SQLITE_OK ){
63134 /* If a transient index is required, create it by calling
63135 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
63136 ** opening it. If a transient table is required, just use the
63137 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
63138 */
63139 if( pOp->p4.pKeyInfo ){
63140 int pgno;
63141 assert( pOp->p4type==P4_KEYINFO );
63142 rc = sqlite3BtreeCreateTable(u.ax.pCx->pBt, &pgno, BTREE_BLOBKEY);
63143 if( rc==SQLITE_OK ){
63144 assert( pgno==MASTER_ROOT+1 );
63145 rc = sqlite3BtreeCursor(u.ax.pCx->pBt, pgno, 1,
63146 (KeyInfo*)pOp->p4.z, u.ax.pCx->pCursor);
63147 u.ax.pCx->pKeyInfo = pOp->p4.pKeyInfo;
@@ -62615,10 +63151,11 @@
63151 }else{
63152 rc = sqlite3BtreeCursor(u.ax.pCx->pBt, MASTER_ROOT, 1, 0, u.ax.pCx->pCursor);
63153 u.ax.pCx->isTable = 1;
63154 }
63155 }
63156 u.ax.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
63157 u.ax.pCx->isIndex = !u.ax.pCx->isTable;
63158 break;
63159 }
63160
63161 /* Opcode: OpenPseudo P1 P2 P3 * *
@@ -62734,10 +63271,11 @@
63271 assert( u.az.pC!=0 );
63272 assert( u.az.pC->pseudoTableReg==0 );
63273 assert( OP_SeekLe == OP_SeekLt+1 );
63274 assert( OP_SeekGe == OP_SeekLt+2 );
63275 assert( OP_SeekGt == OP_SeekLt+3 );
63276 assert( u.az.pC->isOrdered );
63277 if( u.az.pC->pCursor!=0 ){
63278 u.az.oc = pOp->opcode;
63279 u.az.pC->nullRow = 0;
63280 if( u.az.pC->isTable ){
63281 /* The input value in P3 might be of any type: integer, real, string,
@@ -62816,10 +63354,13 @@
63354 assert( u.az.oc!=OP_SeekLe || u.az.r.flags==UNPACKED_INCRKEY );
63355 assert( u.az.oc!=OP_SeekGe || u.az.r.flags==0 );
63356 assert( u.az.oc!=OP_SeekLt || u.az.r.flags==0 );
63357
63358 u.az.r.aMem = &aMem[pOp->p3];
63359 #ifdef SQLITE_DEBUG
63360 { int i; for(i=0; i<u.az.r.nField; i++) assert( memIsValid(&u.az.r.aMem[i]) ); }
63361 #endif
63362 ExpandBlob(u.az.r.aMem);
63363 rc = sqlite3BtreeMovetoUnpacked(u.az.pC->pCursor, &u.az.r, 0, 0, &u.az.res);
63364 if( rc!=SQLITE_OK ){
63365 goto abort_due_to_error;
63366 }
@@ -62944,15 +63485,18 @@
63485 assert( u.bb.pC->isTable==0 );
63486 if( pOp->p4.i>0 ){
63487 u.bb.r.pKeyInfo = u.bb.pC->pKeyInfo;
63488 u.bb.r.nField = (u16)pOp->p4.i;
63489 u.bb.r.aMem = pIn3;
63490 #ifdef SQLITE_DEBUG
63491 { int i; for(i=0; i<u.bb.r.nField; i++) assert( memIsValid(&u.bb.r.aMem[i]) ); }
63492 #endif
63493 u.bb.r.flags = UNPACKED_PREFIX_MATCH;
63494 u.bb.pIdxKey = &u.bb.r;
63495 }else{
63496 assert( pIn3->flags & MEM_Blob );
63497 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
63498 u.bb.pIdxKey = sqlite3VdbeRecordUnpack(u.bb.pC->pKeyInfo, pIn3->n, pIn3->z,
63499 u.bb.aTempRec, sizeof(u.bb.aTempRec));
63500 if( u.bb.pIdxKey==0 ){
63501 goto no_mem;
63502 }
@@ -63043,10 +63587,13 @@
63587 /* Populate the index search key. */
63588 u.bc.r.pKeyInfo = u.bc.pCx->pKeyInfo;
63589 u.bc.r.nField = u.bc.nField + 1;
63590 u.bc.r.flags = UNPACKED_PREFIX_SEARCH;
63591 u.bc.r.aMem = u.bc.aMx;
63592 #ifdef SQLITE_DEBUG
63593 { int i; for(i=0; i<u.bc.r.nField; i++) assert( memIsValid(&u.bc.r.aMem[i]) ); }
63594 #endif
63595
63596 /* Extract the value of u.bc.R from register P3. */
63597 sqlite3VdbeMemIntegerify(pIn3);
63598 u.bc.R = pIn3->u.i;
63599
@@ -63065,11 +63612,11 @@
63612
63613 /* Opcode: NotExists P1 P2 P3 * *
63614 **
63615 ** Use the content of register P3 as a integer key. If a record
63616 ** with that key does not exist in table of P1, then jump to P2.
63617 ** If the record does exist, then fall through. The cursor is left
63618 ** pointing to the record if it exists.
63619 **
63620 ** The difference between this operation and NotFound is that this
63621 ** operation assumes the key is an integer and that P1 is a table whereas
63622 ** NotFound assumes key is a blob constructed from MakeRecord and
@@ -63223,11 +63770,13 @@
63770 u.be.pMem = &u.be.pFrame->aMem[pOp->p3];
63771 }else{
63772 /* Assert that P3 is a valid memory cell. */
63773 assert( pOp->p3<=p->nMem );
63774 u.be.pMem = &aMem[pOp->p3];
63775 memAboutToChange(p, u.be.pMem);
63776 }
63777 assert( memIsValid(u.be.pMem) );
63778
63779 REGISTER_TRACE(pOp->p3, u.be.pMem);
63780 sqlite3VdbeMemIntegerify(u.be.pMem);
63781 assert( (u.be.pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
63782 if( u.be.pMem->u.i==MAX_ROWID || u.be.pC->useRandomRowid ){
@@ -63242,33 +63791,40 @@
63791 #endif
63792
63793 sqlite3BtreeSetCachedRowid(u.be.pC->pCursor, u.be.v<MAX_ROWID ? u.be.v+1 : 0);
63794 }
63795 if( u.be.pC->useRandomRowid ){
63796 /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
63797 ** largest possible integer (9223372036854775807) then the database
63798 ** engine starts picking positive candidate ROWIDs at random until
63799 ** it finds one that is not previously used. */
 
63800 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
63801 ** an AUTOINCREMENT table. */
63802 /* on the first attempt, simply do one more than previous */
63803 u.be.v = db->lastRowid;
63804 u.be.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
63805 u.be.v++; /* ensure non-zero */
63806 u.be.cnt = 0;
63807 while( ((rc = sqlite3BtreeMovetoUnpacked(u.be.pC->pCursor, 0, (u64)u.be.v,
63808 0, &u.be.res))==SQLITE_OK)
63809 && (u.be.res==0)
63810 && (++u.be.cnt<100)){
63811 /* collision - try another random rowid */
63812 sqlite3_randomness(sizeof(u.be.v), &u.be.v);
63813 if( u.be.cnt<5 ){
63814 /* try "small" random rowids for the initial attempts */
63815 u.be.v &= 0xffffff;
63816 }else{
63817 u.be.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
 
63818 }
63819 u.be.v++; /* ensure non-zero */
63820 }
 
63821 if( rc==SQLITE_OK && u.be.res==0 ){
63822 rc = SQLITE_FULL; /* IMP: R-38219-53002 */
63823 goto abort_due_to_error;
63824 }
63825 assert( u.be.v>0 ); /* EV: R-40812-03570 */
63826 }
63827 u.be.pC->rowidIsValid = 0;
63828 u.be.pC->deferredMoveto = 0;
63829 u.be.pC->cacheStatus = CACHE_STALE;
63830 }
@@ -63334,10 +63890,11 @@
63890 int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
63891 #endif /* local variables moved into u.bf */
63892
63893 u.bf.pData = &aMem[pOp->p2];
63894 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
63895 assert( memIsValid(u.bf.pData) );
63896 u.bf.pC = p->apCsr[pOp->p1];
63897 assert( u.bf.pC!=0 );
63898 assert( u.bf.pC->pCursor!=0 );
63899 assert( u.bf.pC->pseudoTableReg==0 );
63900 assert( u.bf.pC->isTable );
@@ -63344,10 +63901,11 @@
63901 REGISTER_TRACE(pOp->p2, u.bf.pData);
63902
63903 if( pOp->opcode==OP_Insert ){
63904 u.bf.pKey = &aMem[pOp->p3];
63905 assert( u.bf.pKey->flags & MEM_Int );
63906 assert( memIsValid(u.bf.pKey) );
63907 REGISTER_TRACE(pOp->p3, u.bf.pKey);
63908 u.bf.iKey = u.bf.pKey->u.i;
63909 }else{
63910 assert( pOp->opcode==OP_InsertInt );
63911 u.bf.iKey = pOp->p3;
@@ -63495,10 +64053,11 @@
64053 u32 n;
64054 i64 n64;
64055 #endif /* local variables moved into u.bh */
64056
64057 pOut = &aMem[pOp->p2];
64058 memAboutToChange(p, pOut);
64059
64060 /* Note that RowKey and RowData are really exactly the same instruction */
64061 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
64062 u.bh.pC = p->apCsr[pOp->p1];
64063 assert( u.bh.pC->isTable || pOp->opcode==OP_RowKey );
@@ -63837,10 +64396,13 @@
64396 if( ALWAYS(u.bo.pCrsr!=0) ){
64397 u.bo.r.pKeyInfo = u.bo.pC->pKeyInfo;
64398 u.bo.r.nField = (u16)pOp->p3;
64399 u.bo.r.flags = 0;
64400 u.bo.r.aMem = &aMem[pOp->p2];
64401 #ifdef SQLITE_DEBUG
64402 { int i; for(i=0; i<u.bo.r.nField; i++) assert( memIsValid(&u.bo.r.aMem[i]) ); }
64403 #endif
64404 rc = sqlite3BtreeMovetoUnpacked(u.bo.pCrsr, &u.bo.r, 0, 0, &u.bo.res);
64405 if( rc==SQLITE_OK && u.bo.res==0 ){
64406 rc = sqlite3BtreeDelete(u.bo.pCrsr);
64407 }
64408 assert( u.bo.pC->deferredMoveto==0 );
@@ -63921,10 +64483,11 @@
64483 #endif /* local variables moved into u.bq */
64484
64485 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
64486 u.bq.pC = p->apCsr[pOp->p1];
64487 assert( u.bq.pC!=0 );
64488 assert( u.bq.pC->isOrdered );
64489 if( ALWAYS(u.bq.pC->pCursor!=0) ){
64490 assert( u.bq.pC->deferredMoveto==0 );
64491 assert( pOp->p5==0 || pOp->p5==1 );
64492 assert( pOp->p4type==P4_INT32 );
64493 u.bq.r.pKeyInfo = u.bq.pC->pKeyInfo;
@@ -63933,10 +64496,13 @@
64496 u.bq.r.flags = UNPACKED_INCRKEY | UNPACKED_IGNORE_ROWID;
64497 }else{
64498 u.bq.r.flags = UNPACKED_IGNORE_ROWID;
64499 }
64500 u.bq.r.aMem = &aMem[pOp->p3];
64501 #ifdef SQLITE_DEBUG
64502 { int i; for(i=0; i<u.bq.r.nField; i++) assert( memIsValid(&u.bq.r.aMem[i]) ); }
64503 #endif
64504 rc = sqlite3VdbeIdxKeyCompare(u.bq.pC, &u.bq.r, &u.bq.res);
64505 if( pOp->opcode==OP_IdxLT ){
64506 u.bq.res = -u.bq.res;
64507 }else{
64508 assert( pOp->opcode==OP_IdxGE );
@@ -64036,10 +64602,12 @@
64602 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bs.nChange : 0)
64603 );
64604 if( pOp->p3 ){
64605 p->nChange += u.bs.nChange;
64606 if( pOp->p3>0 ){
64607 assert( memIsValid(&aMem[pOp->p3]) );
64608 memAboutToChange(p, &aMem[pOp->p3]);
64609 aMem[pOp->p3].u.i += u.bs.nChange;
64610 }
64611 }
64612 break;
64613 }
@@ -64079,13 +64647,13 @@
64647 assert( (p->btreeMask & (1<<pOp->p1))!=0 );
64648 u.bt.pDb = &db->aDb[pOp->p1];
64649 assert( u.bt.pDb->pBt!=0 );
64650 if( pOp->opcode==OP_CreateTable ){
64651 /* u.bt.flags = BTREE_INTKEY; */
64652 u.bt.flags = BTREE_INTKEY;
64653 }else{
64654 u.bt.flags = BTREE_BLOBKEY;
64655 }
64656 rc = sqlite3BtreeCreateTable(u.bt.pDb->pBt, &u.bt.pgno, u.bt.flags);
64657 pOut->u.i = u.bt.pgno;
64658 break;
64659 }
@@ -64410,10 +64978,11 @@
64978 void *t; /* Token identifying trigger */
64979 #endif /* local variables moved into u.by */
64980
64981 u.by.pProgram = pOp->p4.pProgram;
64982 u.by.pRt = &aMem[pOp->p3];
64983 assert( memIsValid(u.by.pRt) );
64984 assert( u.by.pProgram->nOp>0 );
64985
64986 /* If the p5 flag is clear, then recursive invocation of triggers is
64987 ** disabled for backwards compatibility (p5 is set if this sub-program
64988 ** is really a trigger, not a foreign key action, and the flag set
@@ -64583,10 +65152,11 @@
65152 for(u.ca.pFrame=p->pFrame; u.ca.pFrame->pParent; u.ca.pFrame=u.ca.pFrame->pParent);
65153 u.ca.pIn1 = &u.ca.pFrame->aMem[pOp->p1];
65154 }else{
65155 u.ca.pIn1 = &aMem[pOp->p1];
65156 }
65157 assert( memIsValid(u.ca.pIn1) );
65158 sqlite3VdbeMemIntegerify(u.ca.pIn1);
65159 pIn2 = &aMem[pOp->p2];
65160 sqlite3VdbeMemIntegerify(pIn2);
65161 if( u.ca.pIn1->u.i<pIn2->u.i){
65162 u.ca.pIn1->u.i = pIn2->u.i;
@@ -64669,11 +65239,13 @@
65239 assert( u.cb.n>=0 );
65240 u.cb.pRec = &aMem[pOp->p2];
65241 u.cb.apVal = p->apArg;
65242 assert( u.cb.apVal || u.cb.n==0 );
65243 for(u.cb.i=0; u.cb.i<u.cb.n; u.cb.i++, u.cb.pRec++){
65244 assert( memIsValid(u.cb.pRec) );
65245 u.cb.apVal[u.cb.i] = u.cb.pRec;
65246 memAboutToChange(p, u.cb.pRec);
65247 sqlite3VdbeMemStoreType(u.cb.pRec);
65248 }
65249 u.cb.ctx.pFunc = pOp->p4.pFunc;
65250 assert( pOp->p3>0 && pOp->p3<=p->nMem );
65251 u.cb.ctx.pMem = u.cb.pMem = &aMem[pOp->p3];
@@ -64689,11 +65261,11 @@
65261 assert( pOp>p->aOp );
65262 assert( pOp[-1].p4type==P4_COLLSEQ );
65263 assert( pOp[-1].opcode==OP_CollSeq );
65264 u.cb.ctx.pColl = pOp[-1].p4.pColl;
65265 }
65266 (u.cb.ctx.pFunc->xStep)(&u.cb.ctx, u.cb.n, u.cb.apVal); /* IMP: R-24505-23230 */
65267 if( u.cb.ctx.isError ){
65268 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cb.ctx.s));
65269 rc = u.cb.ctx.isError;
65270 }
65271 sqlite3VdbeMemRelease(&u.cb.ctx.s);
@@ -65076,10 +65648,11 @@
65648 #endif /* local variables moved into u.ch */
65649
65650 u.ch.pQuery = &aMem[pOp->p3];
65651 u.ch.pArgc = &u.ch.pQuery[1];
65652 u.ch.pCur = p->apCsr[pOp->p1];
65653 assert( memIsValid(u.ch.pQuery) );
65654 REGISTER_TRACE(pOp->p3, u.ch.pQuery);
65655 assert( u.ch.pCur->pVtabCursor );
65656 u.ch.pVtabCursor = u.ch.pCur->pVtabCursor;
65657 u.ch.pVtab = u.ch.pVtabCursor->pVtab;
65658 u.ch.pModule = u.ch.pVtab->pModule;
@@ -65133,10 +65706,11 @@
65706
65707 VdbeCursor *pCur = p->apCsr[pOp->p1];
65708 assert( pCur->pVtabCursor );
65709 assert( pOp->p3>0 && pOp->p3<=p->nMem );
65710 u.ci.pDest = &aMem[pOp->p3];
65711 memAboutToChange(p, u.ci.pDest);
65712 if( pCur->nullRow ){
65713 sqlite3VdbeMemSetNull(u.ci.pDest);
65714 break;
65715 }
65716 u.ci.pVtab = pCur->pVtabCursor->pVtab;
@@ -65235,14 +65809,16 @@
65809 #endif /* local variables moved into u.ck */
65810
65811 u.ck.pVtab = pOp->p4.pVtab->pVtab;
65812 u.ck.pName = &aMem[pOp->p1];
65813 assert( u.ck.pVtab->pModule->xRename );
65814 assert( memIsValid(u.ck.pName) );
65815 REGISTER_TRACE(pOp->p1, u.ck.pName);
65816 assert( u.ck.pName->flags & MEM_Str );
65817 rc = u.ck.pVtab->pModule->xRename(u.ck.pVtab, u.ck.pName->z);
65818 importVtabErrMsg(p, u.ck.pVtab);
65819 p->expired = 0;
65820
65821 break;
65822 }
65823 #endif
65824
@@ -65287,10 +65863,12 @@
65863 assert( pOp->p4type==P4_VTAB );
65864 if( ALWAYS(u.cl.pModule->xUpdate) ){
65865 u.cl.apArg = p->apArg;
65866 u.cl.pX = &aMem[pOp->p3];
65867 for(u.cl.i=0; u.cl.i<u.cl.nArg; u.cl.i++){
65868 assert( memIsValid(u.cl.pX) );
65869 memAboutToChange(p, u.cl.pX);
65870 sqlite3VdbeMemStoreType(u.cl.pX);
65871 u.cl.apArg[u.cl.i] = u.cl.pX;
65872 u.cl.pX++;
65873 }
65874 rc = u.cl.pModule->xUpdate(u.cl.pVtab, u.cl.nArg, u.cl.apArg, &u.cl.rowid);
@@ -66341,12 +66919,11 @@
66919 SQLITE_PRIVATE int sqlite3IsMemJournal(sqlite3_file *pJfd){
66920 return pJfd->pMethods==&MemJournalMethods;
66921 }
66922
66923 /*
66924 ** Return the number of bytes required to store a MemJournal file descriptor.
 
66925 */
66926 SQLITE_PRIVATE int sqlite3MemJournalSize(void){
66927 return sizeof(MemJournal);
66928 }
66929
@@ -68246,11 +68823,11 @@
68823 pExpr->iColumn = (ynVar)(++pParse->nVar);
68824 }else if( z[0]=='?' ){
68825 /* Wildcard of the form "?nnn". Convert "nnn" to an integer and
68826 ** use it as the variable number */
68827 i64 i;
68828 int bOk = 0==sqlite3Atoi64(&z[1], &i, sqlite3Strlen30(&z[1]), SQLITE_UTF8);
68829 pExpr->iColumn = (ynVar)i;
68830 testcase( i==0 );
68831 testcase( i==1 );
68832 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
68833 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
@@ -69226,12 +69803,12 @@
69803 return eType;
69804 }
69805 #endif
69806
69807 /*
69808 ** Generate code for scalar subqueries used as a subquery expression, EXISTS,
69809 ** or IN operators. Examples:
69810 **
69811 ** (SELECT a FROM b) -- subquery
69812 ** EXISTS (SELECT a FROM b) -- EXISTS subquery
69813 ** x IN (4,5,11) -- IN operator with list on right-hand side
69814 ** x IN (SELECT a FROM b) -- IN operator with subquery on the right
@@ -69290,14 +69867,14 @@
69867 assert( testAddr>0 || pParse->db->mallocFailed );
69868 }
69869
69870 switch( pExpr->op ){
69871 case TK_IN: {
69872 char affinity; /* Affinity of the LHS of the IN */
69873 KeyInfo keyInfo; /* Keyinfo for the generated table */
69874 int addr; /* Address of OP_OpenEphemeral instruction */
69875 Expr *pLeft = pExpr->pLeft; /* the LHS of the IN operator */
69876
69877 if( rMayHaveNull ){
69878 sqlite3VdbeAddOp2(v, OP_Null, 0, rMayHaveNull);
69879 }
69880
@@ -69316,10 +69893,11 @@
69893 ** 'x' nor the SELECT... statement are columns, then numeric affinity
69894 ** is used.
69895 */
69896 pExpr->iTable = pParse->nTab++;
69897 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
69898 if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
69899 memset(&keyInfo, 0, sizeof(keyInfo));
69900 keyInfo.nField = 1;
69901
69902 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
69903 /* Case 1: expr IN (SELECT ...)
@@ -69608,11 +70186,11 @@
70186 */
70187 static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){
70188 if( ALWAYS(z!=0) ){
70189 double value;
70190 char *zV;
70191 sqlite3AtoF(z, &value, sqlite3Strlen30(z), SQLITE_UTF8);
70192 assert( !sqlite3IsNaN(value) ); /* The new AtoF never returns NaN */
70193 if( negateFlag ) value = -value;
70194 zV = dup8bytes(v, (char*)&value);
70195 sqlite3VdbeAddOp4(v, OP_Real, 0, iMem, 0, zV, P4_REAL);
70196 }
@@ -69622,28 +70200,27 @@
70200
70201 /*
70202 ** Generate an instruction that will put the integer describe by
70203 ** text z[0..n-1] into register iMem.
70204 **
70205 ** Expr.u.zToken is always UTF8 and zero-terminated.
 
 
70206 */
70207 static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){
70208 Vdbe *v = pParse->pVdbe;
70209 if( pExpr->flags & EP_IntValue ){
70210 int i = pExpr->u.iValue;
70211 if( negFlag ) i = -i;
70212 sqlite3VdbeAddOp2(v, OP_Integer, i, iMem);
70213 }else{
70214 int c;
70215 i64 value;
70216 const char *z = pExpr->u.zToken;
70217 assert( z!=0 );
70218 c = sqlite3Atoi64(z, &value, sqlite3Strlen30(z), SQLITE_UTF8);
70219 if( c==0 || (c==2 && negFlag) ){
70220 char *zV;
70221 if( negFlag ){ value = -value; }
 
70222 zV = dup8bytes(v, (char*)&value);
70223 sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64);
70224 }else{
70225 #ifdef SQLITE_OMIT_FLOATING_POINT
70226 sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
@@ -69924,77 +70501,10 @@
70501 }
70502 return 0;
70503 }
70504 #endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
70505
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70506 /*
70507 ** Generate code into the current Vdbe to evaluate the given
70508 ** expression. Attempt to store the results in register "target".
70509 ** Return the register where results are stored.
70510 **
@@ -70099,11 +70609,11 @@
70609 case TK_REGISTER: {
70610 inReg = pExpr->iTable;
70611 break;
70612 }
70613 case TK_AS: {
70614 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
70615 break;
70616 }
70617 #ifndef SQLITE_OMIT_CAST
70618 case TK_CAST: {
70619 /* Expressions of the form: CAST(pLeft AS token) */
@@ -70531,10 +71041,15 @@
71041 testcase( regFree1==0 );
71042 cacheX.op = TK_REGISTER;
71043 opCompare.op = TK_EQ;
71044 opCompare.pLeft = &cacheX;
71045 pTest = &opCompare;
71046 /* Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
71047 ** The value in regFree1 might get SCopy-ed into the file result.
71048 ** So make sure that the regFree1 register is not reused for other
71049 ** purposes and possibly overwritten. */
71050 regFree1 = 0;
71051 }
71052 for(i=0; i<nExpr; i=i+2){
71053 sqlite3ExprCachePush(pParse);
71054 if( pX ){
71055 assert( pTest!=0 );
@@ -70624,14 +71139,18 @@
71139 */
71140 SQLITE_PRIVATE int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
71141 int inReg;
71142
71143 assert( target>0 && target<=pParse->nMem );
71144 if( pExpr && pExpr->op==TK_REGISTER ){
71145 sqlite3VdbeAddOp2(pParse->pVdbe, OP_Copy, pExpr->iTable, target);
71146 }else{
71147 inReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
71148 assert( pParse->pVdbe || pParse->db->mallocFailed );
71149 if( inReg!=target && pParse->pVdbe ){
71150 sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target);
71151 }
71152 }
71153 return target;
71154 }
71155
71156 /*
@@ -70800,23 +71319,18 @@
71319 ){
71320 struct ExprList_item *pItem;
71321 int i, n;
71322 assert( pList!=0 );
71323 assert( target>0 );
71324 assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
71325 n = pList->nExpr;
71326 for(pItem=pList->a, i=0; i<n; i++, pItem++){
71327 Expr *pExpr = pItem->pExpr;
71328 int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
71329 if( inReg!=target+i ){
71330 sqlite3VdbeAddOp2(pParse->pVdbe, doHardCopy ? OP_Copy : OP_SCopy,
71331 inReg, target+i);
 
 
 
 
 
 
71332 }
71333 }
71334 return n;
71335 }
71336
@@ -71794,10 +72308,15 @@
72308 if( pTrig->pSchema==pTempSchema ){
72309 zWhere = whereOrName(db, zWhere, pTrig->zName);
72310 }
72311 }
72312 }
72313 if( zWhere ){
72314 char *zNew = sqlite3MPrintf(pParse->db, "type='trigger' AND (%s)", zWhere);
72315 sqlite3DbFree(pParse->db, zWhere);
72316 zWhere = zNew;
72317 }
72318 return zWhere;
72319 }
72320
72321 /*
72322 ** Generate code to drop and reload the internal representation of table
@@ -72401,11 +72920,12 @@
72920 int iIdxCur; /* Cursor open on index being analyzed */
72921 Vdbe *v; /* The virtual machine being built up */
72922 int i; /* Loop counter */
72923 int topOfLoop; /* The top of the loop */
72924 int endOfLoop; /* The end of the loop */
72925 int addr = 0; /* The address of an instruction */
72926 int jZeroRows = 0; /* Jump from here if number of rows is zero */
72927 int iDb; /* Index of database containing pTab */
72928 int regTabname = iMem++; /* Register containing table name */
72929 int regIdxname = iMem++; /* Register containing index name */
72930 int regSampleno = iMem++; /* Register containing next sample number */
72931 int regCol = iMem++; /* Content of a column analyzed table */
@@ -72420,12 +72940,19 @@
72940 int regLast = iMem++; /* Index of last sample to record */
72941 int regFirst = iMem++; /* Index of first sample to record */
72942 #endif
72943
72944 v = sqlite3GetVdbe(pParse);
72945 if( v==0 || NEVER(pTab==0) ){
72946 return;
72947 }
72948 if( pTab->tnum==0 ){
72949 /* Do not gather statistics on views or virtual tables */
72950 return;
72951 }
72952 if( memcmp(pTab->zName, "sqlite_", 7)==0 ){
72953 /* Do not gather statistics on system tables */
72954 return;
72955 }
72956 assert( sqlite3BtreeHoldsAllMutexes(db) );
72957 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
72958 assert( iDb>=0 );
@@ -72438,10 +72965,11 @@
72965
72966 /* Establish a read-lock on the table at the shared-cache level. */
72967 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
72968
72969 iIdxCur = pParse->nTab++;
72970 sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
72971 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
72972 int nCol = pIdx->nColumn;
72973 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
72974
72975 if( iMem+1+(nCol*2)>pParse->nMem ){
@@ -72452,14 +72980,11 @@
72980 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
72981 sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb,
72982 (char *)pKey, P4_KEYINFO_HANDOFF);
72983 VdbeComment((v, "%s", pIdx->zName));
72984
72985 /* Populate the register containing the index name. */
 
 
 
72986 sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, pIdx->zName, 0);
72987
72988 #ifdef SQLITE_ENABLE_STAT2
72989
72990 /* If this iteration of the loop is generating code to analyze the
@@ -72590,12 +73115,14 @@
73115 **
73116 ** If K==0 then no entry is made into the sqlite_stat1 table.
73117 ** If K>0 then it is always the case the D>0 so division by zero
73118 ** is never possible.
73119 */
 
73120 sqlite3VdbeAddOp2(v, OP_SCopy, iMem, regSampleno);
73121 if( jZeroRows==0 ){
73122 jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, iMem);
73123 }
73124 for(i=0; i<nCol; i++){
73125 sqlite3VdbeAddOp4(v, OP_String8, 0, regTemp, 0, " ", 0);
73126 sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regSampleno, regSampleno);
73127 sqlite3VdbeAddOp3(v, OP_Add, iMem, iMem+i+1, regTemp);
73128 sqlite3VdbeAddOp2(v, OP_AddImm, regTemp, -1);
@@ -72605,17 +73132,39 @@
73132 }
73133 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0);
73134 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regRowid);
73135 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regRowid);
73136 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
73137 }
73138
73139 /* If the table has no indices, create a single sqlite_stat1 entry
73140 ** containing NULL as the index name and the row count as the content.
73141 */
73142 if( pTab->pIndex==0 ){
73143 sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pTab->tnum, iDb);
73144 VdbeComment((v, "%s", pTab->zName));
73145 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regSampleno);
73146 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur);
73147 }else{
73148 assert( jZeroRows>0 );
73149 addr = sqlite3VdbeAddOp0(v, OP_Goto);
73150 sqlite3VdbeJumpHere(v, jZeroRows);
73151 }
73152 sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
73153 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0);
73154 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regRowid);
73155 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regRowid);
73156 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
73157 if( pParse->nMem<regRec ) pParse->nMem = regRec;
73158 if( jZeroRows ){
73159 sqlite3VdbeJumpHere(v, addr);
73160 }
73161 }
73162
73163 /*
73164 ** Generate code that will cause the most recent index analysis to
73165 ** be loaded into internal hash tables where is can be used.
73166 */
73167 static void loadAnalysis(Parse *pParse, int iDb){
73168 Vdbe *v = sqlite3GetVdbe(pParse);
73169 if( v ){
73170 sqlite3VdbeAddOp1(v, OP_LoadAnalysis, iDb);
@@ -72741,37 +73290,50 @@
73290
73291 /*
73292 ** This callback is invoked once for each index when reading the
73293 ** sqlite_stat1 table.
73294 **
73295 ** argv[0] = name of the table
73296 ** argv[1] = name of the index (might be NULL)
73297 ** argv[2] = results of analysis - on integer for each column
73298 **
73299 ** Entries for which argv[1]==NULL simply record the number of rows in
73300 ** the table.
73301 */
73302 static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){
73303 analysisInfo *pInfo = (analysisInfo*)pData;
73304 Index *pIndex;
73305 Table *pTable;
73306 int i, c, n;
73307 unsigned int v;
73308 const char *z;
73309
73310 assert( argc==3 );
73311 UNUSED_PARAMETER2(NotUsed, argc);
73312
73313 if( argv==0 || argv[0]==0 || argv[2]==0 ){
73314 return 0;
73315 }
73316 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
73317 if( pTable==0 ){
73318 return 0;
73319 }
73320 if( argv[1] ){
73321 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
73322 }else{
73323 pIndex = 0;
73324 }
73325 n = pIndex ? pIndex->nColumn : 0;
73326 z = argv[2];
73327 for(i=0; *z && i<=n; i++){
73328 v = 0;
73329 while( (c=z[0])>='0' && c<='9' ){
73330 v = v*10 + c - '0';
73331 z++;
73332 }
73333 if( i==0 ) pTable->nRowEst = v;
73334 if( pIndex==0 ) break;
73335 pIndex->aiRowEst[i] = v;
73336 if( *z==' ' ) z++;
73337 }
73338 return 0;
73339 }
@@ -72843,11 +73405,11 @@
73405 return SQLITE_ERROR;
73406 }
73407
73408 /* Load new statistics out of the sqlite_stat1 table */
73409 zSql = sqlite3MPrintf(db,
73410 "SELECT tbl, idx, stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
73411 if( zSql==0 ){
73412 rc = SQLITE_NOMEM;
73413 }else{
73414 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
73415 sqlite3DbFree(db, zSql);
@@ -73060,13 +73622,12 @@
73622
73623 /* Open the database file. If the btree is successfully opened, use
73624 ** it to obtain the database schema. At this point the schema may
73625 ** or may not be initialised.
73626 */
73627 rc = sqlite3BtreeOpen(zFile, db, &aNew->pBt, 0,
73628 db->openFlags | SQLITE_OPEN_MAIN_DB);
 
73629 db->nDb++;
73630 if( rc==SQLITE_CONSTRAINT ){
73631 rc = SQLITE_ERROR;
73632 zErrDyn = sqlite3MPrintf(db, "database is already attached");
73633 }else if( rc==SQLITE_OK ){
@@ -73303,11 +73864,12 @@
73864 0, /* pNext */
73865 detachFunc, /* xFunc */
73866 0, /* xStep */
73867 0, /* xFinalize */
73868 "sqlite_detach", /* zName */
73869 0, /* pHash */
73870 0 /* pDestructor */
73871 };
73872 codeAttach(pParse, SQLITE_DETACH, &detach_func, pDbname, 0, 0, pDbname);
73873 }
73874
73875 /*
@@ -73324,11 +73886,12 @@
73886 0, /* pNext */
73887 attachFunc, /* xFunc */
73888 0, /* xStep */
73889 0, /* xFinalize */
73890 "sqlite_attach", /* zName */
73891 0, /* pHash */
73892 0 /* pDestructor */
73893 };
73894 codeAttach(pParse, SQLITE_ATTACH, &attach_func, p, p, pDbname, pKey);
73895 }
73896 #endif /* SQLITE_OMIT_ATTACH */
73897
@@ -74453,12 +75016,13 @@
75016 ** set to the index of the database that the table or view is to be
75017 ** created in.
75018 */
75019 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
75020 if( iDb<0 ) return;
75021 if( !OMIT_TEMPDB && isTemp && pName2->n>0 && iDb!=1 ){
75022 /* If creating a temp table, the name may not be qualified. Unless
75023 ** the database name is "temp" anyway. */
75024 sqlite3ErrorMsg(pParse, "temporary table name must be unqualified");
75025 return;
75026 }
75027 if( !OMIT_TEMPDB && isTemp ) iDb = 1;
75028
@@ -74502,21 +75066,22 @@
75066 ** to an sqlite3_declare_vtab() call. In that case only the column names
75067 ** and types will be used, so there is no need to test for namespace
75068 ** collisions.
75069 */
75070 if( !IN_DECLARE_VTAB ){
75071 char *zDb = db->aDb[iDb].zName;
75072 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
75073 goto begin_table_error;
75074 }
75075 pTable = sqlite3FindTable(db, zName, zDb);
75076 if( pTable ){
75077 if( !noErr ){
75078 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
75079 }
75080 goto begin_table_error;
75081 }
75082 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
75083 sqlite3ErrorMsg(pParse, "there is already an index named %s", zName);
75084 goto begin_table_error;
75085 }
75086 }
75087
@@ -74529,10 +75094,11 @@
75094 }
75095 pTable->zName = zName;
75096 pTable->iPKey = -1;
75097 pTable->pSchema = db->aDb[iDb].pSchema;
75098 pTable->nRef = 1;
75099 pTable->nRowEst = 1000000;
75100 assert( pParse->pNewTable==0 );
75101 pParse->pNewTable = pTable;
75102
75103 /* If this is the magic sqlite_sequence table used by autoincrement,
75104 ** then record a pointer to this table in the main database structure
@@ -75375,16 +75941,14 @@
75941 sqlite3SelectDelete(db, pSelect);
75942 return;
75943 }
75944 sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
75945 p = pParse->pNewTable;
75946 if( p==0 || pParse->nErr ){
75947 sqlite3SelectDelete(db, pSelect);
75948 return;
75949 }
 
 
75950 sqlite3TwoPartName(pParse, pName1, pName2, &pName);
75951 iDb = sqlite3SchemaToIndex(db, p->pSchema);
75952 if( sqlite3FixInit(&sFix, pParse, iDb, "view", pName)
75953 && sqlite3FixSelect(&sFix, pSelect)
75954 ){
@@ -76498,11 +77062,12 @@
77062 */
77063 if( pTblName ){
77064 sqlite3RefillIndex(pParse, pIndex, iMem);
77065 sqlite3ChangeCookie(pParse, iDb);
77066 sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 0, 0,
77067 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName),
77068 P4_DYNAMIC);
77069 sqlite3VdbeAddOp1(v, OP_Expire, 0);
77070 }
77071 }
77072
77073 /* When adding an index to the list of indices for a table, make
@@ -76559,18 +77124,18 @@
77124 ** are based on typical values found in actual indices.
77125 */
77126 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index *pIdx){
77127 unsigned *a = pIdx->aiRowEst;
77128 int i;
77129 unsigned n;
77130 assert( a!=0 );
77131 a[0] = pIdx->pTable->nRowEst;
77132 if( a[0]<10 ) a[0] = 10;
77133 n = 10;
77134 for(i=1; i<=pIdx->nColumn; i++){
77135 a[i] = n;
77136 if( n>5 ) n--;
 
77137 }
77138 if( pIdx->onError!=OE_None ){
77139 a[pIdx->nColumn] = 1;
77140 }
77141 }
@@ -76626,11 +77191,11 @@
77191 /* Generate code to remove the index and from the master table */
77192 v = sqlite3GetVdbe(pParse);
77193 if( v ){
77194 sqlite3BeginWriteOperation(pParse, 1, iDb);
77195 sqlite3NestedParse(pParse,
77196 "DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
77197 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
77198 pIndex->zName
77199 );
77200 if( sqlite3FindTable(db, "sqlite_stat1", db->aDb[iDb].zName) ){
77201 sqlite3NestedParse(pParse,
@@ -77118,11 +77683,11 @@
77683 SQLITE_OPEN_CREATE |
77684 SQLITE_OPEN_EXCLUSIVE |
77685 SQLITE_OPEN_DELETEONCLOSE |
77686 SQLITE_OPEN_TEMP_DB;
77687
77688 rc = sqlite3BtreeOpen(0, db, &pBt, 0, flags);
77689 if( rc!=SQLITE_OK ){
77690 sqlite3ErrorMsg(pParse, "unable to open a temporary database "
77691 "file for storing temporary tables");
77692 pParse->rc = rc;
77693 return 1;
@@ -77775,11 +78340,11 @@
78340 ** If the SQLITE_PreferBuiltin flag is set, then search the built-in
78341 ** functions even if a prior app-defined function was found. And give
78342 ** priority to built-in functions.
78343 **
78344 ** Except, if createFlag is true, that means that we are trying to
78345 ** install a new function. Whatever FuncDef structure is returned it will
78346 ** have fields overwritten with new information appropriate for the
78347 ** new function. But the FuncDefs for built-in functions are read-only.
78348 ** So we must not search for built-ins when creating a new function.
78349 */
78350 if( !createFlag && (pBest==0 || (db->flags & SQLITE_PreferBuiltin)!=0) ){
@@ -78791,11 +79356,11 @@
79356 zBuf = sqlite3_mprintf("%.*f",n,r);
79357 if( zBuf==0 ){
79358 sqlite3_result_error_nomem(context);
79359 return;
79360 }
79361 sqlite3AtoF(zBuf, &r, sqlite3Strlen30(zBuf), SQLITE_UTF8);
79362 sqlite3_free(zBuf);
79363 }
79364 sqlite3_result_double(context, r);
79365 }
79366 #endif
@@ -79956,14 +80521,14 @@
80521 if( caseSensitive ){
80522 pInfo = (struct compareInfo*)&likeInfoAlt;
80523 }else{
80524 pInfo = (struct compareInfo*)&likeInfoNorm;
80525 }
80526 sqlite3CreateFunc(db, "like", 2, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
80527 sqlite3CreateFunc(db, "like", 3, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
80528 sqlite3CreateFunc(db, "glob", 2, SQLITE_ANY,
80529 (struct compareInfo*)&globInfo, likeFunc, 0, 0, 0);
80530 setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
80531 setLikeOptFlag(db, "like",
80532 caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
80533 }
80534
@@ -80043,14 +80608,14 @@
80608 FUNCTION(upper, 1, 0, 0, upperFunc ),
80609 FUNCTION(lower, 1, 0, 0, lowerFunc ),
80610 FUNCTION(coalesce, 1, 0, 0, 0 ),
80611 FUNCTION(coalesce, 0, 0, 0, 0 ),
80612 /* FUNCTION(coalesce, -1, 0, 0, ifnullFunc ), */
80613 {-1,SQLITE_UTF8,SQLITE_FUNC_COALESCE,0,0,ifnullFunc,0,0,"coalesce",0,0},
80614 FUNCTION(hex, 1, 0, 0, hexFunc ),
80615 /* FUNCTION(ifnull, 2, 0, 0, ifnullFunc ), */
80616 {2,SQLITE_UTF8,SQLITE_FUNC_COALESCE,0,0,ifnullFunc,0,0,"ifnull",0,0},
80617 FUNCTION(random, 0, 0, 0, randomFunc ),
80618 FUNCTION(randomblob, 1, 0, 0, randomBlob ),
80619 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
80620 FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
80621 FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
@@ -80073,11 +80638,11 @@
80638 #endif
80639 AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ),
80640 AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ),
80641 AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ),
80642 /* AGGREGATE(count, 0, 0, 0, countStep, countFinalize ), */
80643 {0,SQLITE_UTF8,SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0},
80644 AGGREGATE(count, 1, 0, 0, countStep, countFinalize ),
80645 AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, groupConcatFinalize),
80646 AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, groupConcatFinalize),
80647
80648 LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
@@ -80484,11 +81049,11 @@
81049 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
81050
81051 sqlite3VdbeAddOp3(v, OP_OpenRead, iCur, pIdx->tnum, iDb);
81052 sqlite3VdbeChangeP4(v, -1, (char*)pKey, P4_KEYINFO_HANDOFF);
81053 for(i=0; i<nCol; i++){
81054 sqlite3VdbeAddOp2(v, OP_Copy, aiCol[i]+1+regData, regTemp+i);
81055 }
81056
81057 /* If the parent table is the same as the child table, and we are about
81058 ** to increment the constraint-counter (i.e. this is an INSERT operation),
81059 ** then check if the row being inserted matches itself. If so, do not
@@ -84849,11 +85414,11 @@
85414 */
85415 if( sqlite3StrICmp(zLeft,"journal_size_limit")==0 ){
85416 Pager *pPager = sqlite3BtreePager(pDb->pBt);
85417 i64 iLimit = -2;
85418 if( zRight ){
85419 sqlite3Atoi64(zRight, &iLimit, 1000000, SQLITE_UTF8);
85420 if( iLimit<-1 ) iLimit = -1;
85421 }
85422 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
85423 returnSingleInt(pParse, "journal_size_limit", iLimit);
85424 }else
@@ -87131,15 +87696,17 @@
87696 sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
87697 sqlite3VdbeAddOp2(v, OP_IdxInsert, iTab, r1);
87698 sqlite3ReleaseTempReg(pParse, r1);
87699 }
87700
87701 #ifndef SQLITE_OMIT_SUBQUERY
87702 /*
87703 ** Generate an error message when a SELECT is used within a subexpression
87704 ** (example: "a IN (SELECT * FROM table)") but it has more than 1 result
87705 ** column. We do this in a subroutine because the error used to occur
87706 ** in multiple places. (The error only occurs in one place now, but we
87707 ** retain the subroutine to minimize code disruption.)
87708 */
87709 static int checkForMultiColumnSelectError(
87710 Parse *pParse, /* Parse context. */
87711 SelectDest *pDest, /* Destination of SELECT results */
87712 int nExpr /* Number of result columns returned by SELECT */
@@ -87151,10 +87718,11 @@
87718 return 1;
87719 }else{
87720 return 0;
87721 }
87722 }
87723 #endif
87724
87725 /*
87726 ** This routine generates the code for the inside of the inner loop
87727 ** of a SELECT.
87728 **
@@ -87230,14 +87798,10 @@
87798 if( pOrderBy==0 ){
87799 codeOffset(v, p, iContinue);
87800 }
87801 }
87802
 
 
 
 
87803 switch( eDest ){
87804 /* In this mode, write each query result to the key of the temporary
87805 ** table iParm.
87806 */
87807 #ifndef SQLITE_OMIT_COMPOUND_SELECT
@@ -88143,10 +88707,11 @@
88707 /* Create the destination temporary table if necessary
88708 */
88709 if( dest.eDest==SRT_EphemTab ){
88710 assert( p->pEList );
88711 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, dest.iParm, p->pEList->nExpr);
88712 sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
88713 dest.eDest = SRT_Table;
88714 }
88715
88716 /* Make sure all SELECTs in the statement have the same number of elements
88717 ** in their result sets.
@@ -90105,11 +90670,11 @@
90670 ExprList *pList = pF->pExpr->x.pList;
90671 assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
90672 if( pList ){
90673 nArg = pList->nExpr;
90674 regAgg = sqlite3GetTempRange(pParse, nArg);
90675 sqlite3ExprCodeExprList(pParse, pList, regAgg, 1);
90676 }else{
90677 nArg = 0;
90678 regAgg = 0;
90679 }
90680 if( pF->iDistinct>=0 ){
@@ -90264,10 +90829,19 @@
90829
90830 /* Begin generating code.
90831 */
90832 v = sqlite3GetVdbe(pParse);
90833 if( v==0 ) goto select_end;
90834
90835 /* If writing to memory or generating a set
90836 ** only a single column may be output.
90837 */
90838 #ifndef SQLITE_OMIT_SUBQUERY
90839 if( checkForMultiColumnSelectError(pParse, pDest, pEList->nExpr) ){
90840 goto select_end;
90841 }
90842 #endif
90843
90844 /* Generate code for all sub-queries in the FROM clause
90845 */
90846 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
90847 for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
@@ -90338,19 +90912,10 @@
90912 }
90913 return multiSelect(pParse, p, pDest);
90914 }
90915 #endif
90916
 
 
 
 
 
 
 
 
 
90917 /* If possible, rewrite the query to use GROUP BY instead of DISTINCT.
90918 ** GROUP BY might use an index, DISTINCT never does.
90919 */
90920 assert( p->pGroupBy==0 || (p->selFlags & SF_Aggregate)!=0 );
90921 if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct ){
@@ -90409,10 +90974,11 @@
90974 assert( isAgg || pGroupBy );
90975 distinct = pParse->nTab++;
90976 pKeyInfo = keyInfoFromExprList(pParse, p->pEList);
90977 sqlite3VdbeAddOp4(v, OP_OpenEphemeral, distinct, 0, 0,
90978 (char*)pKeyInfo, P4_KEYINFO_HANDOFF);
90979 sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
90980 }else{
90981 distinct = -1;
90982 }
90983
90984 /* Aggregate and non-aggregate queries are handled differently */
@@ -92884,10 +93450,11 @@
93450 ** be stored.
93451 */
93452 assert( v );
93453 ephemTab = pParse->nTab++;
93454 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, ephemTab, pTab->nCol+1+(pRowid!=0));
93455 sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
93456
93457 /* fill the ephemeral table
93458 */
93459 sqlite3SelectDestInit(&dest, SRT_Table, ephemTab);
93460 sqlite3Select(pParse, pSelect, &dest);
@@ -93022,10 +93589,14 @@
93589 int nDb; /* Number of attached databases */
93590
93591 if( !db->autoCommit ){
93592 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
93593 return SQLITE_ERROR;
93594 }
93595 if( db->activeVdbeCnt>1 ){
93596 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
93597 return SQLITE_ERROR;
93598 }
93599
93600 /* Save the current value of the database flags so that it can be
93601 ** restored before returning. Then set the writable-schema flag, and
93602 ** disable CHECK and foreign key constraints. */
@@ -93624,11 +94195,11 @@
94195 sqlite3DbFree(db, zStmt);
94196 v = sqlite3GetVdbe(pParse);
94197 sqlite3ChangeCookie(pParse, iDb);
94198
94199 sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
94200 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
94201 sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 1, 0, zWhere, P4_DYNAMIC);
94202 sqlite3VdbeAddOp4(v, OP_VCreate, iDb, 0, 0,
94203 pTab->zName, sqlite3Strlen30(pTab->zName) + 1);
94204 }
94205
@@ -94864,15 +95435,16 @@
95435 if( op==TK_REGISTER ){
95436 op = pRight->op2;
95437 }
95438 if( op==TK_VARIABLE ){
95439 Vdbe *pReprepare = pParse->pReprepare;
95440 int iCol = pRight->iColumn;
95441 pVal = sqlite3VdbeGetValue(pReprepare, iCol, SQLITE_AFF_NONE);
95442 if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){
95443 z = (char *)sqlite3_value_text(pVal);
95444 }
95445 sqlite3VdbeSetVarmask(pParse->pVdbe, iCol); /* IMP: R-23257-02778 */
95446 assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
95447 }else if( op==TK_STRING ){
95448 z = pRight->u.zToken;
95449 }
95450 if( z ){
@@ -94886,11 +95458,11 @@
95458 pPrefix = sqlite3Expr(db, TK_STRING, z);
95459 if( pPrefix ) pPrefix->u.zToken[cnt] = 0;
95460 *ppPrefix = pPrefix;
95461 if( op==TK_VARIABLE ){
95462 Vdbe *v = pParse->pVdbe;
95463 sqlite3VdbeSetVarmask(v, pRight->iColumn); /* IMP: R-23257-02778 */
95464 if( *pisComplete && pRight->u.zToken[1] ){
95465 /* If the rhs of the LIKE expression is a variable, and the current
95466 ** value of the variable means there is no need to invoke the LIKE
95467 ** function, then no OP_Variable will be added to the program.
95468 ** This causes problems for the sqlite3_bind_parameter_name()
@@ -95750,11 +96322,12 @@
96322
96323 /*
96324 ** Required because bestIndex() is called by bestOrClauseIndex()
96325 */
96326 static void bestIndex(
96327 Parse*, WhereClause*, struct SrcList_item*,
96328 Bitmask, Bitmask, ExprList*, WhereCost*);
96329
96330 /*
96331 ** This routine attempts to find an scanning strategy that can be used
96332 ** to optimize an 'OR' expression that is part of a WHERE clause.
96333 **
@@ -95763,11 +96336,12 @@
96336 */
96337 static void bestOrClauseIndex(
96338 Parse *pParse, /* The parsing context */
96339 WhereClause *pWC, /* The WHERE clause */
96340 struct SrcList_item *pSrc, /* The FROM clause term to search */
96341 Bitmask notReady, /* Mask of cursors not available for indexing */
96342 Bitmask notValid, /* Cursors not available for any purpose */
96343 ExprList *pOrderBy, /* The ORDER BY clause */
96344 WhereCost *pCost /* Lowest cost query plan */
96345 ){
96346 #ifndef SQLITE_OMIT_OR_OPTIMIZATION
96347 const int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
@@ -95799,19 +96373,19 @@
96373 WHERETRACE(("... Multi-index OR testing for term %d of %d....\n",
96374 (pOrTerm - pOrWC->a), (pTerm - pWC->a)
96375 ));
96376 if( pOrTerm->eOperator==WO_AND ){
96377 WhereClause *pAndWC = &pOrTerm->u.pAndInfo->wc;
96378 bestIndex(pParse, pAndWC, pSrc, notReady, notValid, 0, &sTermCost);
96379 }else if( pOrTerm->leftCursor==iCur ){
96380 WhereClause tempWC;
96381 tempWC.pParse = pWC->pParse;
96382 tempWC.pMaskSet = pWC->pMaskSet;
96383 tempWC.op = TK_AND;
96384 tempWC.a = pOrTerm;
96385 tempWC.nTerm = 1;
96386 bestIndex(pParse, &tempWC, pSrc, notReady, notValid, 0, &sTermCost);
96387 }else{
96388 continue;
96389 }
96390 rTotal += sTermCost.rCost;
96391 nRow += sTermCost.nRow;
@@ -95900,11 +96474,11 @@
96474 return;
96475 }
96476
96477 assert( pParse->nQueryLoop >= (double)1 );
96478 pTable = pSrc->pTab;
96479 nTableRow = pTable->nRowEst;
96480 logN = estLog(nTableRow);
96481 costTempIdx = 2*logN*(nTableRow/pParse->nQueryLoop + 1);
96482 if( costTempIdx>=pCost->rCost ){
96483 /* The cost of creating the transient table would be greater than
96484 ** doing the full table scan */
@@ -96254,11 +96828,12 @@
96828 */
96829 static void bestVirtualIndex(
96830 Parse *pParse, /* The parsing context */
96831 WhereClause *pWC, /* The WHERE clause */
96832 struct SrcList_item *pSrc, /* The FROM clause term to search */
96833 Bitmask notReady, /* Mask of cursors not available for index */
96834 Bitmask notValid, /* Cursors not valid for any purpose */
96835 ExprList *pOrderBy, /* The order by clause */
96836 WhereCost *pCost, /* Lowest cost query plan */
96837 sqlite3_index_info **ppIdxInfo /* Index information passed to xBestIndex */
96838 ){
96839 Table *pTab = pSrc->pTab;
@@ -96384,11 +96959,11 @@
96959 pIdxInfo->nOrderBy = nOrderBy;
96960
96961 /* Try to find a more efficient access pattern by using multiple indexes
96962 ** to optimize an OR expression within the WHERE clause.
96963 */
96964 bestOrClauseIndex(pParse, pWC, pSrc, notReady, notValid, pOrderBy, pCost);
96965 }
96966 #endif /* SQLITE_OMIT_VIRTUALTABLE */
96967
96968 /*
96969 ** Argument pIdx is a pointer to an index structure that has an array of
@@ -96510,11 +97085,11 @@
97085 /* The evalConstExpr() function will have already converted any TK_VARIABLE
97086 ** expression involved in an comparison into a TK_REGISTER. */
97087 assert( pExpr->op!=TK_VARIABLE );
97088 if( pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE ){
97089 int iVar = pExpr->iColumn;
97090 sqlite3VdbeSetVarmask(pParse->pVdbe, iVar); /* IMP: R-23257-02778 */
97091 *pp = sqlite3VdbeGetValue(pParse->pReprepare, iVar, aff);
97092 return SQLITE_OK;
97093 }
97094 return sqlite3ValueFromExpr(pParse->db, pExpr, SQLITE_UTF8, aff, pp);
97095 }
@@ -96665,11 +97240,12 @@
97240 */
97241 static void bestBtreeIndex(
97242 Parse *pParse, /* The parsing context */
97243 WhereClause *pWC, /* The WHERE clause */
97244 struct SrcList_item *pSrc, /* The FROM clause term to search */
97245 Bitmask notReady, /* Mask of cursors not available for indexing */
97246 Bitmask notValid, /* Cursors not available for any purpose */
97247 ExprList *pOrderBy, /* The ORDER BY clause */
97248 WhereCost *pCost /* Lowest cost query plan */
97249 ){
97250 int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
97251 Index *pProbe; /* An index we are evaluating */
@@ -96707,27 +97283,18 @@
97283 Index *pFirst; /* Any other index on the table */
97284 memset(&sPk, 0, sizeof(Index));
97285 sPk.nColumn = 1;
97286 sPk.aiColumn = &aiColumnPk;
97287 sPk.aiRowEst = aiRowEstPk;
 
97288 sPk.onError = OE_Replace;
97289 sPk.pTable = pSrc->pTab;
97290 aiRowEstPk[0] = pSrc->pTab->nRowEst;
97291 aiRowEstPk[1] = 1;
97292 pFirst = pSrc->pTab->pIndex;
97293 if( pSrc->notIndexed==0 ){
97294 sPk.pNext = pFirst;
97295 }
 
 
 
 
 
 
 
 
 
 
97296 pProbe = &sPk;
97297 wsFlagMask = ~(
97298 WHERE_COLUMN_IN|WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_RANGE
97299 );
97300 eqTermMask = WO_EQ|WO_IN;
@@ -96936,29 +97503,29 @@
97503 ** of output rows, adjust the nRow value accordingly. This only
97504 ** matters if the current index is the least costly, so do not bother
97505 ** with this step if we already know this index will not be chosen.
97506 ** Also, never reduce the output row count below 2 using this step.
97507 **
97508 ** It is critical that the notValid mask be used here instead of
97509 ** the notReady mask. When computing an "optimal" index, the notReady
97510 ** mask will only have one bit set - the bit for the current table.
97511 ** The notValid mask, on the other hand, always has all bits set for
97512 ** tables that are not in outer loops. If notReady is used here instead
97513 ** of notValid, then a optimal index that depends on inner joins loops
97514 ** might be selected even when there exists an optimal index that has
97515 ** no such dependency.
97516 */
97517 if( nRow>2 && cost<=pCost->rCost ){
97518 int k; /* Loop counter */
97519 int nSkipEq = nEq; /* Number of == constraints to skip */
97520 int nSkipRange = nBound; /* Number of < constraints to skip */
97521 Bitmask thisTab; /* Bitmap for pSrc */
97522
97523 thisTab = getMask(pWC->pMaskSet, iCur);
97524 for(pTerm=pWC->a, k=pWC->nTerm; nRow>2 && k; k--, pTerm++){
97525 if( pTerm->wtFlags & TERM_VIRTUAL ) continue;
97526 if( (pTerm->prereqAll & notValid)!=thisTab ) continue;
97527 if( pTerm->eOperator & (WO_EQ|WO_IN|WO_ISNULL) ){
97528 if( nSkipEq ){
97529 /* Ignore the first nEq equality matches since the index
97530 ** has already accounted for these */
97531 nSkipEq--;
@@ -97036,11 +97603,11 @@
97603 WHERETRACE(("best index is: %s\n",
97604 ((pCost->plan.wsFlags & WHERE_NOT_FULLSCAN)==0 ? "none" :
97605 pCost->plan.u.pIdx ? pCost->plan.u.pIdx->zName : "ipk")
97606 ));
97607
97608 bestOrClauseIndex(pParse, pWC, pSrc, notReady, notValid, pOrderBy, pCost);
97609 bestAutomaticIndex(pParse, pWC, pSrc, notReady, pCost);
97610 pCost->plan.wsFlags |= eqTermMask;
97611 }
97612
97613 /*
@@ -97051,26 +97618,27 @@
97618 */
97619 static void bestIndex(
97620 Parse *pParse, /* The parsing context */
97621 WhereClause *pWC, /* The WHERE clause */
97622 struct SrcList_item *pSrc, /* The FROM clause term to search */
97623 Bitmask notReady, /* Mask of cursors not available for indexing */
97624 Bitmask notValid, /* Cursors not available for any purpose */
97625 ExprList *pOrderBy, /* The ORDER BY clause */
97626 WhereCost *pCost /* Lowest cost query plan */
97627 ){
97628 #ifndef SQLITE_OMIT_VIRTUALTABLE
97629 if( IsVirtual(pSrc->pTab) ){
97630 sqlite3_index_info *p = 0;
97631 bestVirtualIndex(pParse, pWC, pSrc, notReady, notValid, pOrderBy, pCost,&p);
97632 if( p->needToFreeIdxStr ){
97633 sqlite3_free(p->idxStr);
97634 }
97635 sqlite3DbFree(pParse->db, p);
97636 }else
97637 #endif
97638 {
97639 bestBtreeIndex(pParse, pWC, pSrc, notReady, notValid, pOrderBy, pCost);
97640 }
97641 }
97642
97643 /*
97644 ** Disable a term in the WHERE clause. Except, do not disable the term
@@ -98281,14 +98849,20 @@
98849 ** by waiting for other tables to run first. This "optimal" test works
98850 ** by first assuming that the FROM clause is on the inner loop and finding
98851 ** its query plan, then checking to see if that query plan uses any
98852 ** other FROM clause terms that are notReady. If no notReady terms are
98853 ** used then the "optimal" query plan works.
98854 **
98855 ** Note that the WhereCost.nRow parameter for an optimal scan might
98856 ** not be as small as it would be if the table really were the innermost
98857 ** join. The nRow value can be reduced by WHERE clause constraints
98858 ** that do not use indices. But this nRow reduction only happens if the
98859 ** table really is the innermost join.
98860 **
98861 ** The second loop iteration is only performed if no optimal scan
98862 ** strategies were found by the first iteration. This second iteration
98863 ** is used to search for the lowest cost scan overall.
98864 **
98865 ** Previous versions of SQLite performed only the second iteration -
98866 ** the next outermost loop was always that with the lowest overall
98867 ** cost. However, this meant that SQLite could select the wrong plan
98868 ** for scripts such as the following:
@@ -98297,18 +98871,18 @@
98871 ** CREATE TABLE t2(c, d);
98872 ** SELECT * FROM t2, t1 WHERE t2.rowid = t1.a;
98873 **
98874 ** The best strategy is to iterate through table t1 first. However it
98875 ** is not possible to determine this with a simple greedy algorithm.
98876 ** Since the cost of a linear scan through table t2 is the same
98877 ** as the cost of a linear scan through table t1, a simple greedy
98878 ** algorithm may choose to use t2 for the outer loop, which is a much
98879 ** costlier approach.
98880 */
98881 nUnconstrained = 0;
98882 notIndexed = 0;
98883 for(isOptimal=(iFrom<nTabList-1); isOptimal>=0 && bestJ<0; isOptimal--){
98884 Bitmask mask; /* Mask of tables not yet ready */
98885 for(j=iFrom, pTabItem=&pTabList->a[j]; j<nTabList; j++, pTabItem++){
98886 int doNotReorder; /* True if this table should not be reordered */
98887 WhereCost sCost; /* Cost information from best[Virtual]Index() */
98888 ExprList *pOrderBy; /* ORDER BY clause for index to optimize */
@@ -98326,15 +98900,17 @@
98900
98901 assert( pTabItem->pTab );
98902 #ifndef SQLITE_OMIT_VIRTUALTABLE
98903 if( IsVirtual(pTabItem->pTab) ){
98904 sqlite3_index_info **pp = &pWInfo->a[j].pIdxInfo;
98905 bestVirtualIndex(pParse, pWC, pTabItem, mask, notReady, pOrderBy,
98906 &sCost, pp);
98907 }else
98908 #endif
98909 {
98910 bestBtreeIndex(pParse, pWC, pTabItem, mask, notReady, pOrderBy,
98911 &sCost);
98912 }
98913 assert( isOptimal || (sCost.used&notReady)==0 );
98914
98915 /* If an INDEXED BY clause is present, then the plan must use that
98916 ** index if it uses any index at all */
@@ -103366,19 +103942,37 @@
103942
103943 /************** End of sqliteicu.h *******************************************/
103944 /************** Continuing where we left off in main.c ***********************/
103945 #endif
103946
 
 
 
103947 #ifndef SQLITE_AMALGAMATION
103948 /* IMPLEMENTATION-OF: R-46656-45156 The sqlite3_version[] string constant
103949 ** contains the text of SQLITE_VERSION macro.
103950 */
103951 SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
103952 #endif
103953
103954 /* IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns
103955 ** a pointer to the to the sqlite3_version[] string constant.
103956 */
103957 SQLITE_API const char *sqlite3_libversion(void){ return sqlite3_version; }
103958
103959 /* IMPLEMENTATION-OF: R-63124-39300 The sqlite3_sourceid() function returns a
103960 ** pointer to a string constant whose value is the same as the
103961 ** SQLITE_SOURCE_ID C preprocessor macro.
103962 */
103963 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
103964
103965 /* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function
103966 ** returns an integer equal to SQLITE_VERSION_NUMBER.
103967 */
103968 SQLITE_API int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; }
103969
103970 /* IMPLEMENTATION-OF: R-54823-41343 The sqlite3_threadsafe() function returns
103971 ** zero if and only if SQLite was compiled mutexing code omitted due to
103972 ** the SQLITE_THREADSAFE compile-time option being set to 0.
103973 */
103974 SQLITE_API int sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }
103975
103976 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
103977 /*
103978 ** If the following function pointer is not NULL and if
@@ -103495,10 +104089,17 @@
104089 /* Do the rest of the initialization under the recursive mutex so
104090 ** that we will be able to handle recursive calls into
104091 ** sqlite3_initialize(). The recursive calls normally come through
104092 ** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other
104093 ** recursive calls might also be possible.
104094 **
104095 ** IMPLEMENTATION-OF: R-00140-37445 SQLite automatically serializes calls
104096 ** to the xInit method, so the xInit method need not be threadsafe.
104097 **
104098 ** The following mutex is what serializes access to the appdef pcache xInit
104099 ** methods. The sqlite3_pcache_methods.xInit() all is embedded in the
104100 ** call to sqlite3PcacheInitialize().
104101 */
104102 sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex);
104103 if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){
104104 FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions);
104105 sqlite3GlobalConfig.inProgress = 1;
@@ -103775,16 +104376,16 @@
104376 if( cnt<0 ) cnt = 0;
104377 if( sz==0 || cnt==0 ){
104378 sz = 0;
104379 pStart = 0;
104380 }else if( pBuf==0 ){
104381 sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */
104382 sqlite3BeginBenignMalloc();
104383 pStart = sqlite3Malloc( sz*cnt ); /* IMP: R-61949-35727 */
104384 sqlite3EndBenignMalloc();
104385 }else{
104386 sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */
104387 pStart = pBuf;
104388 }
104389 db->lookaside.pStart = pStart;
104390 db->lookaside.pFree = 0;
104391 db->lookaside.sz = (u16)sz;
@@ -103823,18 +104424,18 @@
104424 va_list ap;
104425 int rc;
104426 va_start(ap, op);
104427 switch( op ){
104428 case SQLITE_DBCONFIG_LOOKASIDE: {
104429 void *pBuf = va_arg(ap, void*); /* IMP: R-21112-12275 */
104430 int sz = va_arg(ap, int); /* IMP: R-47871-25994 */
104431 int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
104432 rc = setupLookaside(db, pBuf, sz, cnt);
104433 break;
104434 }
104435 default: {
104436 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
104437 break;
104438 }
104439 }
104440 va_end(ap);
104441 return rc;
@@ -103934,16 +104535,33 @@
104535 }
104536 db->nSavepoint = 0;
104537 db->nStatement = 0;
104538 db->isTransactionSavepoint = 0;
104539 }
104540
104541 /*
104542 ** Invoke the destructor function associated with FuncDef p, if any. Except,
104543 ** if this is not the last copy of the function, do not invoke it. Multiple
104544 ** copies of a single function are created when create_function() is called
104545 ** with SQLITE_ANY as the encoding.
104546 */
104547 static void functionDestroy(sqlite3 *db, FuncDef *p){
104548 FuncDestructor *pDestructor = p->pDestructor;
104549 if( pDestructor ){
104550 pDestructor->nRef--;
104551 if( pDestructor->nRef==0 ){
104552 pDestructor->xDestroy(pDestructor->pUserData);
104553 sqlite3DbFree(db, pDestructor);
104554 }
104555 }
104556 }
104557
104558 /*
104559 ** Close an existing SQLite database
104560 */
104561 SQLITE_API int sqlite3_close(sqlite3 *db){
104562 HashElem *i; /* Hash table iterator */
104563 int j;
104564
104565 if( !db ){
104566 return SQLITE_OK;
104567 }
@@ -104007,10 +104625,11 @@
104625 for(j=0; j<ArraySize(db->aFunc.a); j++){
104626 FuncDef *pNext, *pHash, *p;
104627 for(p=db->aFunc.a[j]; p; p=pHash){
104628 pHash = p->pHash;
104629 while( p ){
104630 functionDestroy(db, p);
104631 pNext = p->pNext;
104632 sqlite3DbFree(db, p);
104633 p = pNext;
104634 }
104635 }
@@ -104281,11 +104900,12 @@
104900 int nArg,
104901 int enc,
104902 void *pUserData,
104903 void (*xFunc)(sqlite3_context*,int,sqlite3_value **),
104904 void (*xStep)(sqlite3_context*,int,sqlite3_value **),
104905 void (*xFinal)(sqlite3_context*),
104906 FuncDestructor *pDestructor
104907 ){
104908 FuncDef *p;
104909 int nName;
104910
104911 assert( sqlite3_mutex_held(db->mutex) );
@@ -104309,14 +104929,14 @@
104929 if( enc==SQLITE_UTF16 ){
104930 enc = SQLITE_UTF16NATIVE;
104931 }else if( enc==SQLITE_ANY ){
104932 int rc;
104933 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,
104934 pUserData, xFunc, xStep, xFinal, pDestructor);
104935 if( rc==SQLITE_OK ){
104936 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,
104937 pUserData, xFunc, xStep, xFinal, pDestructor);
104938 }
104939 if( rc!=SQLITE_OK ){
104940 return rc;
104941 }
104942 enc = SQLITE_UTF16BE;
@@ -104345,10 +104965,19 @@
104965 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
104966 assert(p || db->mallocFailed);
104967 if( !p ){
104968 return SQLITE_NOMEM;
104969 }
104970
104971 /* If an older version of the function with a configured destructor is
104972 ** being replaced invoke the destructor function here. */
104973 functionDestroy(db, p);
104974
104975 if( pDestructor ){
104976 pDestructor->nRef++;
104977 }
104978 p->pDestructor = pDestructor;
104979 p->flags = 0;
104980 p->xFunc = xFunc;
104981 p->xStep = xStep;
104982 p->xFinalize = xFinal;
104983 p->pUserData = pUserData;
@@ -104359,21 +104988,53 @@
104988 /*
104989 ** Create new user functions.
104990 */
104991 SQLITE_API int sqlite3_create_function(
104992 sqlite3 *db,
104993 const char *zFunc,
104994 int nArg,
104995 int enc,
104996 void *p,
104997 void (*xFunc)(sqlite3_context*,int,sqlite3_value **),
104998 void (*xStep)(sqlite3_context*,int,sqlite3_value **),
104999 void (*xFinal)(sqlite3_context*)
105000 ){
105001 return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xFunc, xStep,
105002 xFinal, 0);
105003 }
105004
105005 SQLITE_API int sqlite3_create_function_v2(
105006 sqlite3 *db,
105007 const char *zFunc,
105008 int nArg,
105009 int enc,
105010 void *p,
105011 void (*xFunc)(sqlite3_context*,int,sqlite3_value **),
105012 void (*xStep)(sqlite3_context*,int,sqlite3_value **),
105013 void (*xFinal)(sqlite3_context*),
105014 void (*xDestroy)(void *)
105015 ){
105016 int rc = SQLITE_ERROR;
105017 FuncDestructor *pArg = 0;
105018 sqlite3_mutex_enter(db->mutex);
105019 if( xDestroy ){
105020 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
105021 if( !pArg ){
105022 xDestroy(p);
105023 goto out;
105024 }
105025 pArg->xDestroy = xDestroy;
105026 pArg->pUserData = p;
105027 }
105028 rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, pArg);
105029 if( pArg && pArg->nRef==0 ){
105030 assert( rc!=SQLITE_OK );
105031 xDestroy(p);
105032 sqlite3DbFree(db, pArg);
105033 }
105034
105035 out:
105036 rc = sqlite3ApiExit(db, rc);
105037 sqlite3_mutex_leave(db->mutex);
105038 return rc;
105039 }
105040
@@ -104391,11 +105052,11 @@
105052 int rc;
105053 char *zFunc8;
105054 sqlite3_mutex_enter(db->mutex);
105055 assert( !db->mallocFailed );
105056 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
105057 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
105058 sqlite3DbFree(db, zFunc8);
105059 rc = sqlite3ApiExit(db, rc);
105060 sqlite3_mutex_leave(db->mutex);
105061 return rc;
105062 }
@@ -104422,11 +105083,11 @@
105083 int nName = sqlite3Strlen30(zName);
105084 int rc;
105085 sqlite3_mutex_enter(db->mutex);
105086 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
105087 sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
105088 0, sqlite3InvalidFunction, 0, 0, 0);
105089 }
105090 rc = sqlite3ApiExit(db, SQLITE_OK);
105091 sqlite3_mutex_leave(db->mutex);
105092 return rc;
105093 }
@@ -104560,11 +105221,14 @@
105221 ** registered using sqlite3_wal_hook(). Likewise, registering a callback
105222 ** using sqlite3_wal_hook() disables the automatic checkpoint mechanism
105223 ** configured by this function.
105224 */
105225 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
105226 #ifdef SQLITE_OMIT_WAL
105227 UNUSED_PARAMETER(db);
105228 UNUSED_PARAMETER(nFrame);
105229 #else
105230 if( nFrame>0 ){
105231 sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
105232 }else{
105233 sqlite3_wal_hook(db, 0, 0);
105234 }
@@ -104690,64 +105354,10 @@
105354 #if SQLITE_TEMP_STORE<1 || SQLITE_TEMP_STORE>3
105355 return 0;
105356 #endif
105357 }
105358
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105359 /*
105360 ** Return UTF-8 encoded English language explanation of the most recent
105361 ** error.
105362 */
105363 SQLITE_API const char *sqlite3_errmsg(sqlite3 *db){
@@ -104986,21 +105596,43 @@
105596 ** It merely prevents new constructs that exceed the limit
105597 ** from forming.
105598 */
105599 SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
105600 int oldLimit;
105601
105602
105603 /* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME
105604 ** there is a hard upper bound set at compile-time by a C preprocessor
105605 ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
105606 ** "_MAX_".)
105607 */
105608 assert( aHardLimit[SQLITE_LIMIT_LENGTH]==SQLITE_MAX_LENGTH );
105609 assert( aHardLimit[SQLITE_LIMIT_SQL_LENGTH]==SQLITE_MAX_SQL_LENGTH );
105610 assert( aHardLimit[SQLITE_LIMIT_COLUMN]==SQLITE_MAX_COLUMN );
105611 assert( aHardLimit[SQLITE_LIMIT_EXPR_DEPTH]==SQLITE_MAX_EXPR_DEPTH );
105612 assert( aHardLimit[SQLITE_LIMIT_COMPOUND_SELECT]==SQLITE_MAX_COMPOUND_SELECT);
105613 assert( aHardLimit[SQLITE_LIMIT_VDBE_OP]==SQLITE_MAX_VDBE_OP );
105614 assert( aHardLimit[SQLITE_LIMIT_FUNCTION_ARG]==SQLITE_MAX_FUNCTION_ARG );
105615 assert( aHardLimit[SQLITE_LIMIT_ATTACHED]==SQLITE_MAX_ATTACHED );
105616 assert( aHardLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]==
105617 SQLITE_MAX_LIKE_PATTERN_LENGTH );
105618 assert( aHardLimit[SQLITE_LIMIT_VARIABLE_NUMBER]==SQLITE_MAX_VARIABLE_NUMBER);
105619 assert( aHardLimit[SQLITE_LIMIT_TRIGGER_DEPTH]==SQLITE_MAX_TRIGGER_DEPTH );
105620 assert( SQLITE_LIMIT_TRIGGER_DEPTH==(SQLITE_N_LIMIT-1) );
105621
105622
105623 if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
105624 return -1;
105625 }
105626 oldLimit = db->aLimit[limitId];
105627 if( newLimit>=0 ){ /* IMP: R-52476-28732 */
105628 if( newLimit>aHardLimit[limitId] ){
105629 newLimit = aHardLimit[limitId]; /* IMP: R-51463-25634 */
105630 }
105631 db->aLimit[limitId] = newLimit;
105632 }
105633 return oldLimit; /* IMP: R-53341-35419 */
105634 }
105635
105636 /*
105637 ** This routine does the work of opening a database on behalf of
105638 ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
@@ -105019,10 +105651,28 @@
105651 *ppDb = 0;
105652 #ifndef SQLITE_OMIT_AUTOINIT
105653 rc = sqlite3_initialize();
105654 if( rc ) return rc;
105655 #endif
105656
105657 /* Only allow sensible combinations of bits in the flags argument.
105658 ** Throw an error if any non-sense combination is used. If we
105659 ** do not block illegal combinations here, it could trigger
105660 ** assert() statements in deeper layers. Sensible combinations
105661 ** are:
105662 **
105663 ** 1: SQLITE_OPEN_READONLY
105664 ** 2: SQLITE_OPEN_READWRITE
105665 ** 6: SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
105666 */
105667 assert( SQLITE_OPEN_READONLY == 0x01 );
105668 assert( SQLITE_OPEN_READWRITE == 0x02 );
105669 assert( SQLITE_OPEN_CREATE == 0x04 );
105670 testcase( (1<<(flags&7))==0x02 ); /* READONLY */
105671 testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
105672 testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
105673 if( ((1<<(flags&7)) & 0x46)==0 ) return SQLITE_MISUSE;
105674
105675 if( sqlite3GlobalConfig.bCoreMutex==0 ){
105676 isThreadsafe = 0;
105677 }else if( flags & SQLITE_OPEN_NOMUTEX ){
105678 isThreadsafe = 0;
@@ -105053,11 +105703,12 @@
105703 SQLITE_OPEN_MAIN_JOURNAL |
105704 SQLITE_OPEN_TEMP_JOURNAL |
105705 SQLITE_OPEN_SUBJOURNAL |
105706 SQLITE_OPEN_MASTER_JOURNAL |
105707 SQLITE_OPEN_NOMUTEX |
105708 SQLITE_OPEN_FULLMUTEX |
105709 SQLITE_OPEN_WAL
105710 );
105711
105712 /* Allocate the sqlite data structure */
105713 db = sqlite3MallocZero( sizeof(sqlite3) );
105714 if( db==0 ) goto opendb_out;
@@ -105125,13 +105776,12 @@
105776 createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0,
105777 nocaseCollatingFunc, 0);
105778
105779 /* Open the backend database driver */
105780 db->openFlags = flags;
105781 rc = sqlite3BtreeOpen(zFilename, db, &db->aDb[0].pBt, 0,
105782 flags | SQLITE_OPEN_MAIN_DB);
 
105783 if( rc!=SQLITE_OK ){
105784 if( rc==SQLITE_IOERR_NOMEM ){
105785 rc = SQLITE_NOMEM;
105786 }
105787 sqlite3Error(db, rc, 0);
@@ -105833,10 +106483,26 @@
106483 */
106484 case SQLITE_TESTCTRL_PGHDRSZ: {
106485 rc = sizeof(PgHdr);
106486 break;
106487 }
106488
106489 /* sqlite3_test_control(SQLITE_TESTCTRL_SCRATCHMALLOC, sz, &pNew, pFree);
106490 **
106491 ** Pass pFree into sqlite3ScratchFree().
106492 ** If sz>0 then allocate a scratch buffer into pNew.
106493 */
106494 case SQLITE_TESTCTRL_SCRATCHMALLOC: {
106495 void *pFree, **ppNew;
106496 int sz;
106497 sz = va_arg(ap, int);
106498 ppNew = va_arg(ap, void**);
106499 pFree = va_arg(ap, void*);
106500 if( sz ) *ppNew = sqlite3ScratchMalloc(sz);
106501 sqlite3ScratchFree(pFree);
106502 break;
106503 }
106504
106505 }
106506 va_end(ap);
106507 #endif /* SQLITE_OMIT_BUILTIN_TEST */
106508 return rc;
@@ -107022,10 +107688,11 @@
107688 );
107689 SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char const**, int*);
107690 SQLITE_PRIVATE int sqlite3Fts3AllSegdirs(Fts3Table*, sqlite3_stmt **);
107691 SQLITE_PRIVATE int sqlite3Fts3MatchinfoDocsizeLocal(Fts3Cursor*, u32*);
107692 SQLITE_PRIVATE int sqlite3Fts3MatchinfoDocsizeGlobal(Fts3Cursor*, u32*);
107693 SQLITE_PRIVATE int sqlite3Fts3ReadLock(Fts3Table *);
107694
107695 /* Flags allowed as part of the 4th argument to SegmentReaderIterate() */
107696 #define FTS3_SEGMENT_REQUIRE_POS 0x00000001
107697 #define FTS3_SEGMENT_IGNORE_EMPTY 0x00000002
107698 #define FTS3_SEGMENT_COLUMN_FILTER 0x00000004
@@ -108971,10 +109638,13 @@
109638 zQuery);
109639 }
109640 return rc;
109641 }
109642
109643 rc = sqlite3Fts3ReadLock(p);
109644 if( rc!=SQLITE_OK ) return rc;
109645
109646 rc = evalFts3Expr(p, pCsr->pExpr, &pCsr->aDoclist, &pCsr->nDoclist, 0);
109647 pCsr->pNextId = pCsr->aDoclist;
109648 pCsr->iPrevId = 0;
109649 }
109650
@@ -109349,15 +110019,18 @@
110019 static int fts3RenameMethod(
110020 sqlite3_vtab *pVtab, /* Virtual table handle */
110021 const char *zName /* New name of table */
110022 ){
110023 Fts3Table *p = (Fts3Table *)pVtab;
110024 sqlite3 *db = p->db; /* Database connection */
110025 int rc; /* Return Code */
110026
110027 rc = sqlite3Fts3PendingTermsFlush(p);
110028 if( rc!=SQLITE_OK ){
110029 return rc;
110030 }
110031
110032 fts3DbExec(&rc, db,
110033 "ALTER TABLE %Q.'%q_content' RENAME TO '%q_content';",
110034 p->zDb, p->zName, zName
110035 );
110036 if( rc==SQLITE_ERROR ) rc = SQLITE_OK;
@@ -112512,10 +113185,40 @@
113185 return SQLITE_CORRUPT;
113186 }
113187 }
113188 return SQLITE_OK;
113189 }
113190
113191 /*
113192 ** This function ensures that the caller has obtained a shared-cache
113193 ** table-lock on the %_content table. This is required before reading
113194 ** data from the fts3 table. If this lock is not acquired first, then
113195 ** the caller may end up holding read-locks on the %_segments and %_segdir
113196 ** tables, but no read-lock on the %_content table. If this happens
113197 ** a second connection will be able to write to the fts3 table, but
113198 ** attempting to commit those writes might return SQLITE_LOCKED or
113199 ** SQLITE_LOCKED_SHAREDCACHE (because the commit attempts to obtain
113200 ** write-locks on the %_segments and %_segdir ** tables).
113201 **
113202 ** We try to avoid this because if FTS3 returns any error when committing
113203 ** a transaction, the whole transaction will be rolled back. And this is
113204 ** not what users expect when they get SQLITE_LOCKED_SHAREDCACHE. It can
113205 ** still happen if the user reads data directly from the %_segments or
113206 ** %_segdir tables instead of going through FTS3 though.
113207 */
113208 SQLITE_PRIVATE int sqlite3Fts3ReadLock(Fts3Table *p){
113209 int rc; /* Return code */
113210 sqlite3_stmt *pStmt; /* Statement used to obtain lock */
113211
113212 rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pStmt, 0);
113213 if( rc==SQLITE_OK ){
113214 sqlite3_bind_null(pStmt, 1);
113215 sqlite3_step(pStmt);
113216 rc = sqlite3_reset(pStmt);
113217 }
113218 return rc;
113219 }
113220
113221 /*
113222 ** Set *ppStmt to a statement handle that may be used to iterate through
113223 ** all rows in the %_segdir table, from oldest to newest. If successful,
113224 ** return SQLITE_OK. If an error occurs while preparing the statement,
@@ -116003,10 +116706,49 @@
116706 **
116707 *************************************************************************
116708 ** This file contains code for implementations of the r-tree and r*-tree
116709 ** algorithms packaged as an SQLite virtual table module.
116710 */
116711
116712 /*
116713 ** Database Format of R-Tree Tables
116714 ** --------------------------------
116715 **
116716 ** The data structure for a single virtual r-tree table is stored in three
116717 ** native SQLite tables declared as follows. In each case, the '%' character
116718 ** in the table name is replaced with the user-supplied name of the r-tree
116719 ** table.
116720 **
116721 ** CREATE TABLE %_node(nodeno INTEGER PRIMARY KEY, data BLOB)
116722 ** CREATE TABLE %_parent(nodeno INTEGER PRIMARY KEY, parentnode INTEGER)
116723 ** CREATE TABLE %_rowid(rowid INTEGER PRIMARY KEY, nodeno INTEGER)
116724 **
116725 ** The data for each node of the r-tree structure is stored in the %_node
116726 ** table. For each node that is not the root node of the r-tree, there is
116727 ** an entry in the %_parent table associating the node with its parent.
116728 ** And for each row of data in the table, there is an entry in the %_rowid
116729 ** table that maps from the entries rowid to the id of the node that it
116730 ** is stored on.
116731 **
116732 ** The root node of an r-tree always exists, even if the r-tree table is
116733 ** empty. The nodeno of the root node is always 1. All other nodes in the
116734 ** table must be the same size as the root node. The content of each node
116735 ** is formatted as follows:
116736 **
116737 ** 1. If the node is the root node (node 1), then the first 2 bytes
116738 ** of the node contain the tree depth as a big-endian integer.
116739 ** For non-root nodes, the first 2 bytes are left unused.
116740 **
116741 ** 2. The next 2 bytes contain the number of entries currently
116742 ** stored in the node.
116743 **
116744 ** 3. The remainder of the node contains the node entries. Each entry
116745 ** consists of a single 8-byte integer followed by an even number
116746 ** of 4-byte coordinates. For leaf nodes the integer is the rowid
116747 ** of a record. For internal nodes it is the node number of a
116748 ** child page.
116749 */
116750
116751 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE)
116752
116753 /*
116754 ** This file contains an implementation of a couple of different variants
@@ -116044,18 +116786,22 @@
116786 #endif
116787 #if VARIANT_RSTARTREE_SPLIT
116788 #define AssignCells splitNodeStartree
116789 #endif
116790
116791 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
116792 # define NDEBUG 1
116793 #endif
116794
116795 #ifndef SQLITE_CORE
116796 SQLITE_EXTENSION_INIT1
116797 #else
116798 #endif
116799
116800
116801 #ifndef SQLITE_AMALGAMATION
116802 #include "sqlite3rtree.h"
116803 typedef sqlite3_int64 i64;
116804 typedef unsigned char u8;
116805 typedef unsigned int u32;
116806 #endif
116807
@@ -116062,10 +116808,12 @@
116808 typedef struct Rtree Rtree;
116809 typedef struct RtreeCursor RtreeCursor;
116810 typedef struct RtreeNode RtreeNode;
116811 typedef struct RtreeCell RtreeCell;
116812 typedef struct RtreeConstraint RtreeConstraint;
116813 typedef struct RtreeMatchArg RtreeMatchArg;
116814 typedef struct RtreeGeomCallback RtreeGeomCallback;
116815 typedef union RtreeCoord RtreeCoord;
116816
116817 /* The rtree may have between 1 and RTREE_MAX_DIMENSIONS dimensions. */
116818 #define RTREE_MAX_DIMENSIONS 5
116819
@@ -116131,10 +116879,19 @@
116879 */
116880 #define RTREE_MINCELLS(p) ((((p)->iNodeSize-4)/(p)->nBytesPerCell)/3)
116881 #define RTREE_REINSERT(p) RTREE_MINCELLS(p)
116882 #define RTREE_MAXCELLS 51
116883
116884 /*
116885 ** The smallest possible node-size is (512-64)==448 bytes. And the largest
116886 ** supported cell size is 48 bytes (8 byte rowid + ten 4 byte coordinates).
116887 ** Therefore all non-root nodes must contain at least 3 entries. Since
116888 ** 2^40 is greater than 2^64, an r-tree structure always has a depth of
116889 ** 40 or less.
116890 */
116891 #define RTREE_MAX_DEPTH 40
116892
116893 /*
116894 ** An rtree cursor object.
116895 */
116896 struct RtreeCursor {
116897 sqlite3_vtab_cursor base;
@@ -116163,39 +116920,27 @@
116920
116921 /*
116922 ** A search constraint.
116923 */
116924 struct RtreeConstraint {
116925 int iCoord; /* Index of constrained coordinate */
116926 int op; /* Constraining operation */
116927 double rValue; /* Constraint value. */
116928 int (*xGeom)(sqlite3_rtree_geometry *, int, double *, int *);
116929 sqlite3_rtree_geometry *pGeom; /* Constraint callback argument for a MATCH */
116930 };
116931
116932 /* Possible values for RtreeConstraint.op */
116933 #define RTREE_EQ 0x41
116934 #define RTREE_LE 0x42
116935 #define RTREE_LT 0x43
116936 #define RTREE_GE 0x44
116937 #define RTREE_GT 0x45
116938 #define RTREE_MATCH 0x46
116939
116940 /*
116941 ** An rtree structure node.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116942 */
116943 struct RtreeNode {
116944 RtreeNode *pParent; /* Parent node */
116945 i64 iNode;
116946 int nRef;
@@ -116211,10 +116956,44 @@
116956 struct RtreeCell {
116957 i64 iRowid;
116958 RtreeCoord aCoord[RTREE_MAX_DIMENSIONS*2];
116959 };
116960
116961
116962 /*
116963 ** Value for the first field of every RtreeMatchArg object. The MATCH
116964 ** operator tests that the first field of a blob operand matches this
116965 ** value to avoid operating on invalid blobs (which could cause a segfault).
116966 */
116967 #define RTREE_GEOMETRY_MAGIC 0x891245AB
116968
116969 /*
116970 ** An instance of this structure must be supplied as a blob argument to
116971 ** the right-hand-side of an SQL MATCH operator used to constrain an
116972 ** r-tree query.
116973 */
116974 struct RtreeMatchArg {
116975 u32 magic; /* Always RTREE_GEOMETRY_MAGIC */
116976 int (*xGeom)(sqlite3_rtree_geometry *, int, double *, int *);
116977 void *pContext;
116978 int nParam;
116979 double aParam[1];
116980 };
116981
116982 /*
116983 ** When a geometry callback is created (see sqlite3_rtree_geometry_callback),
116984 ** a single instance of the following structure is allocated. It is used
116985 ** as the context for the user-function created by by s_r_g_c(). The object
116986 ** is eventually deleted by the destructor mechanism provided by
116987 ** sqlite3_create_function_v2() (which is called by s_r_g_c() to create
116988 ** the geometry callback function).
116989 */
116990 struct RtreeGeomCallback {
116991 int (*xGeom)(sqlite3_rtree_geometry *, int, double *, int *);
116992 void *pContext;
116993 };
116994
116995 #ifndef MAX
116996 # define MAX(x,y) ((x) < (y) ? (y) : (x))
116997 #endif
116998 #ifndef MIN
116999 # define MIN(x,y) ((x) > (y) ? (y) : (x))
@@ -116293,14 +117072,12 @@
117072
117073 /*
117074 ** Clear the content of node p (set all bytes to 0x00).
117075 */
117076 static void nodeZero(Rtree *pRtree, RtreeNode *p){
117077 memset(&p->zData[2], 0, pRtree->iNodeSize-2);
117078 p->isDirty = 1;
 
 
117079 }
117080
117081 /*
117082 ** Given a node number iNode, return the corresponding key to use
117083 ** in the Rtree.aHash table.
@@ -116316,26 +117093,23 @@
117093 ** Search the node hash table for node iNode. If found, return a pointer
117094 ** to it. Otherwise, return 0.
117095 */
117096 static RtreeNode *nodeHashLookup(Rtree *pRtree, i64 iNode){
117097 RtreeNode *p;
 
117098 for(p=pRtree->aHash[nodeHash(iNode)]; p && p->iNode!=iNode; p=p->pNext);
117099 return p;
117100 }
117101
117102 /*
117103 ** Add node pNode to the node hash table.
117104 */
117105 static void nodeHashInsert(Rtree *pRtree, RtreeNode *pNode){
117106 int iHash;
117107 assert( pNode->pNext==0 );
117108 iHash = nodeHash(pNode->iNode);
117109 pNode->pNext = pRtree->aHash[iHash];
117110 pRtree->aHash[iHash] = pNode;
 
 
117111 }
117112
117113 /*
117114 ** Remove node pNode from the node hash table.
117115 */
@@ -116353,15 +117127,15 @@
117127 ** Allocate and return new r-tree node. Initially, (RtreeNode.iNode==0),
117128 ** indicating that node has not yet been assigned a node number. It is
117129 ** assigned a node number when nodeWrite() is called to write the
117130 ** node contents out to the database.
117131 */
117132 static RtreeNode *nodeNew(Rtree *pRtree, RtreeNode *pParent){
117133 RtreeNode *pNode;
117134 pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode) + pRtree->iNodeSize);
117135 if( pNode ){
117136 memset(pNode, 0, sizeof(RtreeNode) + pRtree->iNodeSize);
117137 pNode->zData = (u8 *)&pNode[1];
117138 pNode->nRef = 1;
117139 pNode->pParent = pParent;
117140 pNode->isDirty = 1;
117141 nodeReference(pParent);
@@ -116378,10 +117152,11 @@
117152 i64 iNode, /* Node number to load */
117153 RtreeNode *pParent, /* Either the parent node or NULL */
117154 RtreeNode **ppNode /* OUT: Acquired node */
117155 ){
117156 int rc;
117157 int rc2 = SQLITE_OK;
117158 RtreeNode *pNode;
117159
117160 /* Check if the requested node is already in the hash table. If so,
117161 ** increase its reference count and return it.
117162 */
@@ -116394,43 +117169,67 @@
117169 pNode->nRef++;
117170 *ppNode = pNode;
117171 return SQLITE_OK;
117172 }
117173
 
 
 
 
 
 
 
 
 
 
 
 
117174 sqlite3_bind_int64(pRtree->pReadNode, 1, iNode);
117175 rc = sqlite3_step(pRtree->pReadNode);
117176 if( rc==SQLITE_ROW ){
117177 const u8 *zBlob = sqlite3_column_blob(pRtree->pReadNode, 0);
117178 if( pRtree->iNodeSize==sqlite3_column_bytes(pRtree->pReadNode, 0) ){
117179 pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize);
117180 if( !pNode ){
117181 rc2 = SQLITE_NOMEM;
117182 }else{
117183 pNode->pParent = pParent;
117184 pNode->zData = (u8 *)&pNode[1];
117185 pNode->nRef = 1;
117186 pNode->iNode = iNode;
117187 pNode->isDirty = 0;
117188 pNode->pNext = 0;
117189 memcpy(pNode->zData, zBlob, pRtree->iNodeSize);
117190 nodeReference(pParent);
117191 }
117192 }
117193 }
117194 rc = sqlite3_reset(pRtree->pReadNode);
117195 if( rc==SQLITE_OK ) rc = rc2;
117196
117197 /* If the root node was just loaded, set pRtree->iDepth to the height
117198 ** of the r-tree structure. A height of zero means all data is stored on
117199 ** the root node. A height of one means the children of the root node
117200 ** are the leaves, and so on. If the depth as specified on the root node
117201 ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
117202 */
117203 if( pNode && iNode==1 ){
117204 pRtree->iDepth = readInt16(pNode->zData);
117205 if( pRtree->iDepth>RTREE_MAX_DEPTH ){
117206 rc = SQLITE_CORRUPT;
117207 }
117208 }
117209
117210 /* If no error has occurred so far, check if the "number of entries"
117211 ** field on the node is too large. If so, set the return code to
117212 ** SQLITE_CORRUPT.
117213 */
117214 if( pNode && rc==SQLITE_OK ){
117215 if( NCELL(pNode)>((pRtree->iNodeSize-4)/pRtree->nBytesPerCell) ){
117216 rc = SQLITE_CORRUPT;
117217 }
117218 }
117219
117220 if( rc==SQLITE_OK ){
117221 if( pNode!=0 ){
117222 nodeHashInsert(pRtree, pNode);
117223 }else{
117224 rc = SQLITE_CORRUPT;
117225 }
117226 *ppNode = pNode;
117227 }else{
117228 sqlite3_free(pNode);
117229 *ppNode = 0;
117230 }
 
 
 
 
 
 
 
 
 
 
117231
117232 return rc;
117233 }
117234
117235 /*
@@ -116479,12 +117278,11 @@
117278 int nMaxCell; /* Maximum number of cells for pNode */
117279
117280 nMaxCell = (pRtree->iNodeSize-4)/pRtree->nBytesPerCell;
117281 nCell = NCELL(pNode);
117282
117283 assert( nCell<=nMaxCell );
 
117284 if( nCell<nMaxCell ){
117285 nodeOverwriteCell(pRtree, pNode, pCell, nCell);
117286 writeInt16(&pNode->zData[2], nCell+1);
117287 pNode->isDirty = 1;
117288 }
@@ -116700,18 +117498,37 @@
117498 *ppCursor = (sqlite3_vtab_cursor *)pCsr;
117499
117500 return rc;
117501 }
117502
117503
117504 /*
117505 ** Free the RtreeCursor.aConstraint[] array and its contents.
117506 */
117507 static void freeCursorConstraints(RtreeCursor *pCsr){
117508 if( pCsr->aConstraint ){
117509 int i; /* Used to iterate through constraint array */
117510 for(i=0; i<pCsr->nConstraint; i++){
117511 sqlite3_rtree_geometry *pGeom = pCsr->aConstraint[i].pGeom;
117512 if( pGeom ){
117513 if( pGeom->xDelUser ) pGeom->xDelUser(pGeom->pUser);
117514 sqlite3_free(pGeom);
117515 }
117516 }
117517 sqlite3_free(pCsr->aConstraint);
117518 pCsr->aConstraint = 0;
117519 }
117520 }
117521
117522 /*
117523 ** Rtree virtual table module xClose method.
117524 */
117525 static int rtreeClose(sqlite3_vtab_cursor *cur){
117526 Rtree *pRtree = (Rtree *)(cur->pVtab);
117527 int rc;
117528 RtreeCursor *pCsr = (RtreeCursor *)cur;
117529 freeCursorConstraints(pCsr);
117530 rc = nodeRelease(pRtree, pCsr->pNode);
117531 sqlite3_free(pCsr);
117532 return rc;
117533 }
117534
@@ -116723,18 +117540,44 @@
117540 */
117541 static int rtreeEof(sqlite3_vtab_cursor *cur){
117542 RtreeCursor *pCsr = (RtreeCursor *)cur;
117543 return (pCsr->pNode==0);
117544 }
117545
117546 /*
117547 ** The r-tree constraint passed as the second argument to this function is
117548 ** guaranteed to be a MATCH constraint.
117549 */
117550 static int testRtreeGeom(
117551 Rtree *pRtree, /* R-Tree object */
117552 RtreeConstraint *pConstraint, /* MATCH constraint to test */
117553 RtreeCell *pCell, /* Cell to test */
117554 int *pbRes /* OUT: Test result */
117555 ){
117556 int i;
117557 double aCoord[RTREE_MAX_DIMENSIONS*2];
117558 int nCoord = pRtree->nDim*2;
117559
117560 assert( pConstraint->op==RTREE_MATCH );
117561 assert( pConstraint->pGeom );
117562
117563 for(i=0; i<nCoord; i++){
117564 aCoord[i] = DCOORD(pCell->aCoord[i]);
117565 }
117566 return pConstraint->xGeom(pConstraint->pGeom, nCoord, aCoord, pbRes);
117567 }
117568
117569 /*
117570 ** Cursor pCursor currently points to a cell in a non-leaf page.
117571 ** Set *pbEof to true if the sub-tree headed by the cell is filtered
117572 ** (excluded) by the constraints in the pCursor->aConstraint[]
117573 ** array, or false otherwise.
117574 **
117575 ** Return SQLITE_OK if successful or an SQLite error code if an error
117576 ** occurs within a geometry callback.
117577 */
117578 static int testRtreeCell(Rtree *pRtree, RtreeCursor *pCursor, int *pbEof){
117579 RtreeCell cell;
117580 int ii;
117581 int bRes = 0;
117582
117583 nodeGetCell(pRtree, pCursor->pNode, pCursor->iCell, &cell);
@@ -116742,56 +117585,92 @@
117585 RtreeConstraint *p = &pCursor->aConstraint[ii];
117586 double cell_min = DCOORD(cell.aCoord[(p->iCoord>>1)*2]);
117587 double cell_max = DCOORD(cell.aCoord[(p->iCoord>>1)*2+1]);
117588
117589 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
117590 || p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_MATCH
117591 );
117592
117593 switch( p->op ){
117594 case RTREE_LE: case RTREE_LT:
117595 bRes = p->rValue<cell_min;
117596 break;
117597
117598 case RTREE_GE: case RTREE_GT:
117599 bRes = p->rValue>cell_max;
117600 break;
117601
117602 case RTREE_EQ:
117603 bRes = (p->rValue>cell_max || p->rValue<cell_min);
117604 break;
117605
117606 default: {
117607 int rc;
117608 assert( p->op==RTREE_MATCH );
117609 rc = testRtreeGeom(pRtree, p, &cell, &bRes);
117610 if( rc!=SQLITE_OK ){
117611 return rc;
117612 }
117613 bRes = !bRes;
117614 break;
117615 }
117616 }
117617 }
117618
117619 *pbEof = bRes;
117620 return SQLITE_OK;
117621 }
117622
117623 /*
117624 ** Test if the cell that cursor pCursor currently points to
117625 ** would be filtered (excluded) by the constraints in the
117626 ** pCursor->aConstraint[] array. If so, set *pbEof to true before
117627 ** returning. If the cell is not filtered (excluded) by the constraints,
117628 ** set pbEof to zero.
117629 **
117630 ** Return SQLITE_OK if successful or an SQLite error code if an error
117631 ** occurs within a geometry callback.
117632 **
117633 ** This function assumes that the cell is part of a leaf node.
117634 */
117635 static int testRtreeEntry(Rtree *pRtree, RtreeCursor *pCursor, int *pbEof){
117636 RtreeCell cell;
117637 int ii;
117638 *pbEof = 0;
117639
117640 nodeGetCell(pRtree, pCursor->pNode, pCursor->iCell, &cell);
117641 for(ii=0; ii<pCursor->nConstraint; ii++){
117642 RtreeConstraint *p = &pCursor->aConstraint[ii];
117643 double coord = DCOORD(cell.aCoord[p->iCoord]);
117644 int res;
117645 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
117646 || p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_MATCH
117647 );
117648 switch( p->op ){
117649 case RTREE_LE: res = (coord<=p->rValue); break;
117650 case RTREE_LT: res = (coord<p->rValue); break;
117651 case RTREE_GE: res = (coord>=p->rValue); break;
117652 case RTREE_GT: res = (coord>p->rValue); break;
117653 case RTREE_EQ: res = (coord==p->rValue); break;
117654 default: {
117655 int rc;
117656 assert( p->op==RTREE_MATCH );
117657 rc = testRtreeGeom(pRtree, p, &cell, &res);
117658 if( rc!=SQLITE_OK ){
117659 return rc;
117660 }
117661 break;
117662 }
117663 }
117664
117665 if( !res ){
117666 *pbEof = 1;
117667 return SQLITE_OK;
117668 }
117669 }
117670
117671 return SQLITE_OK;
117672 }
117673
117674 /*
117675 ** Cursor pCursor currently points at a node that heads a sub-tree of
117676 ** height iHeight (if iHeight==0, then the node is a leaf). Descend
@@ -116814,17 +117693,17 @@
117693 int iSavedCell = pCursor->iCell;
117694
117695 assert( iHeight>=0 );
117696
117697 if( iHeight==0 ){
117698 rc = testRtreeEntry(pRtree, pCursor, &isEof);
117699 }else{
117700 rc = testRtreeCell(pRtree, pCursor, &isEof);
117701 }
117702 if( rc!=SQLITE_OK || isEof || iHeight==0 ){
117703 *pEof = isEof;
117704 return rc;
117705 }
117706
117707 iRowid = nodeGetRowid(pRtree, pCursor->pNode, pCursor->iCell);
117708 rc = nodeAcquire(pRtree, iRowid, pCursor->pNode, &pChild);
117709 if( rc!=SQLITE_OK ){
@@ -116856,45 +117735,59 @@
117735
117736 /*
117737 ** One of the cells in node pNode is guaranteed to have a 64-bit
117738 ** integer value equal to iRowid. Return the index of this cell.
117739 */
117740 static int nodeRowidIndex(
117741 Rtree *pRtree,
117742 RtreeNode *pNode,
117743 i64 iRowid,
117744 int *piIndex
117745 ){
117746 int ii;
117747 int nCell = NCELL(pNode);
117748 for(ii=0; ii<nCell; ii++){
117749 if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){
117750 *piIndex = ii;
117751 return SQLITE_OK;
117752 }
117753 }
117754 return SQLITE_CORRUPT;
117755 }
117756
117757 /*
117758 ** Return the index of the cell containing a pointer to node pNode
117759 ** in its parent. If pNode is the root node, return -1.
117760 */
117761 static int nodeParentIndex(Rtree *pRtree, RtreeNode *pNode, int *piIndex){
117762 RtreeNode *pParent = pNode->pParent;
117763 if( pParent ){
117764 return nodeRowidIndex(pRtree, pParent, pNode->iNode, piIndex);
117765 }
117766 *piIndex = -1;
117767 return SQLITE_OK;
117768 }
117769
117770 /*
117771 ** Rtree virtual table module xNext method.
117772 */
117773 static int rtreeNext(sqlite3_vtab_cursor *pVtabCursor){
117774 Rtree *pRtree = (Rtree *)(pVtabCursor->pVtab);
117775 RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
117776 int rc = SQLITE_OK;
117777
117778 /* RtreeCursor.pNode must not be NULL. If is is NULL, then this cursor is
117779 ** already at EOF. It is against the rules to call the xNext() method of
117780 ** a cursor that has already reached EOF.
117781 */
117782 assert( pCsr->pNode );
117783
117784 if( pCsr->iStrategy==1 ){
117785 /* This "scan" is a direct lookup by rowid. There is no next entry. */
117786 nodeRelease(pRtree, pCsr->pNode);
117787 pCsr->pNode = 0;
117788 }else{
 
 
117789 /* Move to the next entry that matches the configured constraints. */
117790 int iHeight = 0;
117791 while( pCsr->pNode ){
117792 RtreeNode *pNode = pCsr->pNode;
117793 int nCell = NCELL(pNode);
@@ -116904,11 +117797,14 @@
117797 if( rc!=SQLITE_OK || !isEof ){
117798 return rc;
117799 }
117800 }
117801 pCsr->pNode = pNode->pParent;
117802 rc = nodeParentIndex(pRtree, pNode, &pCsr->iCell);
117803 if( rc!=SQLITE_OK ){
117804 return rc;
117805 }
117806 nodeReference(pCsr->pNode);
117807 nodeRelease(pRtree, pNode);
117808 iHeight++;
117809 }
117810 }
@@ -116972,10 +117868,55 @@
117868 rc = sqlite3_reset(pRtree->pReadRowid);
117869 }
117870 return rc;
117871 }
117872
117873 /*
117874 ** This function is called to configure the RtreeConstraint object passed
117875 ** as the second argument for a MATCH constraint. The value passed as the
117876 ** first argument to this function is the right-hand operand to the MATCH
117877 ** operator.
117878 */
117879 static int deserializeGeometry(sqlite3_value *pValue, RtreeConstraint *pCons){
117880 RtreeMatchArg *p;
117881 sqlite3_rtree_geometry *pGeom;
117882 int nBlob;
117883
117884 /* Check that value is actually a blob. */
117885 if( !sqlite3_value_type(pValue)==SQLITE_BLOB ) return SQLITE_ERROR;
117886
117887 /* Check that the blob is roughly the right size. */
117888 nBlob = sqlite3_value_bytes(pValue);
117889 if( nBlob<sizeof(RtreeMatchArg)
117890 || ((nBlob-sizeof(RtreeMatchArg))%sizeof(double))!=0
117891 ){
117892 return SQLITE_ERROR;
117893 }
117894
117895 pGeom = (sqlite3_rtree_geometry *)sqlite3_malloc(
117896 sizeof(sqlite3_rtree_geometry) + nBlob
117897 );
117898 if( !pGeom ) return SQLITE_NOMEM;
117899 memset(pGeom, 0, sizeof(sqlite3_rtree_geometry));
117900 p = (RtreeMatchArg *)&pGeom[1];
117901
117902 memcpy(p, sqlite3_value_blob(pValue), nBlob);
117903 if( p->magic!=RTREE_GEOMETRY_MAGIC
117904 || nBlob!=(sizeof(RtreeMatchArg) + (p->nParam-1)*sizeof(double))
117905 ){
117906 sqlite3_free(pGeom);
117907 return SQLITE_ERROR;
117908 }
117909
117910 pGeom->pContext = p->pContext;
117911 pGeom->nParam = p->nParam;
117912 pGeom->aParam = p->aParam;
117913
117914 pCons->xGeom = p->xGeom;
117915 pCons->pGeom = pGeom;
117916 return SQLITE_OK;
117917 }
117918
117919 /*
117920 ** Rtree virtual table module xFilter method.
117921 */
117922 static int rtreeFilter(
@@ -116990,22 +117931,22 @@
117931 int ii;
117932 int rc = SQLITE_OK;
117933
117934 rtreeReference(pRtree);
117935
117936 freeCursorConstraints(pCsr);
 
117937 pCsr->iStrategy = idxNum;
117938
117939 if( idxNum==1 ){
117940 /* Special case - lookup by rowid. */
117941 RtreeNode *pLeaf; /* Leaf on which the required cell resides */
117942 i64 iRowid = sqlite3_value_int64(argv[0]);
117943 rc = findLeafNode(pRtree, iRowid, &pLeaf);
117944 pCsr->pNode = pLeaf;
117945 if( pLeaf ){
117946 assert( rc==SQLITE_OK );
117947 rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &pCsr->iCell);
117948 }
117949 }else{
117950 /* Normal case - r-tree scan. Set up the RtreeCursor.aConstraint array
117951 ** with the configured constraints.
117952 */
@@ -117013,16 +117954,28 @@
117954 pCsr->aConstraint = sqlite3_malloc(sizeof(RtreeConstraint)*argc);
117955 pCsr->nConstraint = argc;
117956 if( !pCsr->aConstraint ){
117957 rc = SQLITE_NOMEM;
117958 }else{
117959 memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc);
117960 assert( (idxStr==0 && argc==0) || strlen(idxStr)==argc*2 );
117961 for(ii=0; ii<argc; ii++){
117962 RtreeConstraint *p = &pCsr->aConstraint[ii];
117963 p->op = idxStr[ii*2];
117964 p->iCoord = idxStr[ii*2+1]-'a';
117965 if( p->op==RTREE_MATCH ){
117966 /* A MATCH operator. The right-hand-side must be a blob that
117967 ** can be cast into an RtreeMatchArg object. One created using
117968 ** an sqlite3_rtree_geometry_callback() SQL user function.
117969 */
117970 rc = deserializeGeometry(argv[ii], p);
117971 if( rc!=SQLITE_OK ){
117972 break;
117973 }
117974 }else{
117975 p->rValue = sqlite3_value_double(argv[ii]);
117976 }
117977 }
117978 }
117979 }
117980
117981 if( rc==SQLITE_OK ){
@@ -117078,10 +118031,11 @@
118031 ** = 0x41 ('A')
118032 ** <= 0x42 ('B')
118033 ** < 0x43 ('C')
118034 ** >= 0x44 ('D')
118035 ** > 0x45 ('E')
118036 ** MATCH 0x46 ('F')
118037 ** ----------------------
118038 **
118039 ** The second of each pair of bytes identifies the coordinate column
118040 ** to which the constraint applies. The leftmost coordinate column
118041 ** is 'a', the second from the left 'b' etc.
@@ -117116,43 +118070,47 @@
118070 */
118071 pIdxInfo->estimatedCost = 10.0;
118072 return SQLITE_OK;
118073 }
118074
118075 if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
118076 int j, opmsk;
118077 static const unsigned char compatible[] = { 0, 0, 1, 1, 2, 2 };
118078 u8 op = 0;
118079 switch( p->op ){
118080 case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; break;
118081 case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; break;
118082 case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break;
118083 case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; break;
118084 case SQLITE_INDEX_CONSTRAINT_GE: op = RTREE_GE; break;
118085 default:
118086 assert( p->op==SQLITE_INDEX_CONSTRAINT_MATCH );
118087 op = RTREE_MATCH;
118088 break;
118089 }
118090 assert( op!=0 );
118091
118092 /* Make sure this particular constraint has not been used before.
118093 ** If it has been used before, ignore it.
118094 **
118095 ** A <= or < can be used if there is a prior >= or >.
118096 ** A >= or > can be used if there is a prior < or <=.
118097 ** A <= or < is disqualified if there is a prior <=, <, or ==.
118098 ** A >= or > is disqualified if there is a prior >=, >, or ==.
118099 ** A == is disqualifed if there is any prior constraint.
118100 */
118101 assert( compatible[RTREE_EQ & 7]==0 );
118102 assert( compatible[RTREE_LT & 7]==1 );
118103 assert( compatible[RTREE_LE & 7]==1 );
118104 assert( compatible[RTREE_GT & 7]==2 );
118105 assert( compatible[RTREE_GE & 7]==2 );
118106 cCol = p->iColumn - 1 + 'a';
118107 opmsk = compatible[op & 7];
118108 for(j=0; j<iIdx; j+=2){
118109 if( zIdxStr[j+1]==cCol && (compatible[zIdxStr[j] & 7] & opmsk)!=0 ){
118110 op = 0;
118111 break;
118112 }
118113 }
118114 if( op ){
118115 assert( iIdx<sizeof(zIdxStr)-1 );
118116 zIdxStr[iIdx++] = op;
@@ -117256,11 +118214,16 @@
118214 int iExclude
118215 ){
118216 int ii;
118217 float overlap = 0.0;
118218 for(ii=0; ii<nCell; ii++){
118219 #if VARIANT_RSTARTREE_CHOOSESUBTREE
118220 if( ii!=iExclude )
118221 #else
118222 assert( iExclude==-1 );
118223 #endif
118224 {
118225 int jj;
118226 float o = 1.0;
118227 for(jj=0; jj<(pRtree->nDim*2); jj+=2){
118228 double x1;
118229 double x2;
@@ -117349,26 +118312,35 @@
118312 /* Select the child node which will be enlarged the least if pCell
118313 ** is inserted into it. Resolve ties by choosing the entry with
118314 ** the smallest area.
118315 */
118316 for(iCell=0; iCell<nCell; iCell++){
118317 int bBest = 0;
118318 float growth;
118319 float area;
118320 float overlap = 0.0;
118321 nodeGetCell(pRtree, pNode, iCell, &cell);
118322 growth = cellGrowth(pRtree, &cell, pCell);
118323 area = cellArea(pRtree, &cell);
118324
118325 #if VARIANT_RSTARTREE_CHOOSESUBTREE
118326 if( ii==(pRtree->iDepth-1) ){
118327 overlap = cellOverlapEnlargement(pRtree,&cell,pCell,aCell,nCell,iCell);
118328 }
 
118329 if( (iCell==0)
118330 || (overlap<fMinOverlap)
118331 || (overlap==fMinOverlap && growth<fMinGrowth)
118332 || (overlap==fMinOverlap && growth==fMinGrowth && area<fMinArea)
118333 ){
118334 bBest = 1;
118335 }
118336 #else
118337 if( iCell==0||growth<fMinGrowth||(growth==fMinGrowth && area<fMinArea) ){
118338 bBest = 1;
118339 }
118340 #endif
118341 if( bBest ){
118342 fMinOverlap = overlap;
118343 fMinGrowth = growth;
118344 fMinArea = area;
118345 iBest = cell.iRowid;
118346 }
@@ -117387,29 +118359,34 @@
118359 /*
118360 ** A cell with the same content as pCell has just been inserted into
118361 ** the node pNode. This function updates the bounding box cells in
118362 ** all ancestor elements.
118363 */
118364 static int AdjustTree(
118365 Rtree *pRtree, /* Rtree table */
118366 RtreeNode *pNode, /* Adjust ancestry of this node. */
118367 RtreeCell *pCell /* This cell was just inserted */
118368 ){
118369 RtreeNode *p = pNode;
118370 while( p->pParent ){
 
118371 RtreeNode *pParent = p->pParent;
118372 RtreeCell cell;
118373 int iCell;
118374
118375 if( nodeParentIndex(pRtree, p, &iCell) ){
118376 return SQLITE_CORRUPT;
118377 }
118378
118379 nodeGetCell(pRtree, pParent, iCell, &cell);
118380 if( !cellContains(pRtree, &cell, pCell) ){
118381 cellUnion(pRtree, &cell, pCell);
118382 nodeOverwriteCell(pRtree, pParent, &cell, iCell);
118383 }
118384
118385 p = pParent;
118386 }
118387 return SQLITE_OK;
118388 }
118389
118390 /*
118391 ** Write mapping (iRowid->iNode) to the <rtree>_rowid table.
118392 */
@@ -117934,18 +118911,18 @@
118911 nodeZero(pRtree, pNode);
118912 memcpy(&aCell[nCell], pCell, sizeof(RtreeCell));
118913 nCell++;
118914
118915 if( pNode->iNode==1 ){
118916 pRight = nodeNew(pRtree, pNode);
118917 pLeft = nodeNew(pRtree, pNode);
118918 pRtree->iDepth++;
118919 pNode->isDirty = 1;
118920 writeInt16(pNode->zData, pRtree->iDepth);
118921 }else{
118922 pLeft = pNode;
118923 pRight = nodeNew(pRtree, pLeft->pParent);
118924 nodeReference(pLeft);
118925 }
118926
118927 if( !pLeft || !pRight ){
118928 rc = SQLITE_NOMEM;
@@ -117958,12 +118935,16 @@
118935 rc = AssignCells(pRtree, aCell, nCell, pLeft, pRight, &leftbbox, &rightbbox);
118936 if( rc!=SQLITE_OK ){
118937 goto splitnode_out;
118938 }
118939
118940 /* Ensure both child nodes have node numbers assigned to them by calling
118941 ** nodeWrite(). Node pRight always needs a node number, as it was created
118942 ** by nodeNew() above. But node pLeft sometimes already has a node number.
118943 ** In this case avoid the all to nodeWrite().
118944 */
118945 if( SQLITE_OK!=(rc = nodeWrite(pRtree, pRight))
118946 || (0==pLeft->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pLeft)))
118947 ){
118948 goto splitnode_out;
118949 }
118950
@@ -117975,13 +118956,19 @@
118956 if( rc!=SQLITE_OK ){
118957 goto splitnode_out;
118958 }
118959 }else{
118960 RtreeNode *pParent = pLeft->pParent;
118961 int iCell;
118962 rc = nodeParentIndex(pRtree, pLeft, &iCell);
118963 if( rc==SQLITE_OK ){
118964 nodeOverwriteCell(pRtree, pParent, &leftbbox, iCell);
118965 rc = AdjustTree(pRtree, pParent, &leftbbox);
118966 }
118967 if( rc!=SQLITE_OK ){
118968 goto splitnode_out;
118969 }
118970 }
118971 if( (rc = rtreeInsertCell(pRtree, pRight->pParent, &rightbbox, iHeight+1)) ){
118972 goto splitnode_out;
118973 }
118974
@@ -118021,44 +119008,73 @@
119008 nodeRelease(pRtree, pLeft);
119009 sqlite3_free(aCell);
119010 return rc;
119011 }
119012
119013 /*
119014 ** If node pLeaf is not the root of the r-tree and its pParent pointer is
119015 ** still NULL, load all ancestor nodes of pLeaf into memory and populate
119016 ** the pLeaf->pParent chain all the way up to the root node.
119017 **
119018 ** This operation is required when a row is deleted (or updated - an update
119019 ** is implemented as a delete followed by an insert). SQLite provides the
119020 ** rowid of the row to delete, which can be used to find the leaf on which
119021 ** the entry resides (argument pLeaf). Once the leaf is located, this
119022 ** function is called to determine its ancestry.
119023 */
119024 static int fixLeafParent(Rtree *pRtree, RtreeNode *pLeaf){
119025 int rc = SQLITE_OK;
119026 RtreeNode *pChild = pLeaf;
119027 while( rc==SQLITE_OK && pChild->iNode!=1 && pChild->pParent==0 ){
119028 int rc2 = SQLITE_OK; /* sqlite3_reset() return code */
119029 sqlite3_bind_int64(pRtree->pReadParent, 1, pChild->iNode);
119030 rc = sqlite3_step(pRtree->pReadParent);
119031 if( rc==SQLITE_ROW ){
119032 RtreeNode *pTest; /* Used to test for reference loops */
119033 i64 iNode; /* Node number of parent node */
119034
119035 /* Before setting pChild->pParent, test that we are not creating a
119036 ** loop of references (as we would if, say, pChild==pParent). We don't
119037 ** want to do this as it leads to a memory leak when trying to delete
119038 ** the referenced counted node structures.
119039 */
119040 iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
119041 for(pTest=pLeaf; pTest && pTest->iNode!=iNode; pTest=pTest->pParent);
119042 if( !pTest ){
119043 rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
119044 }
119045 }
119046 rc = sqlite3_reset(pRtree->pReadParent);
119047 if( rc==SQLITE_OK ) rc = rc2;
119048 if( rc==SQLITE_OK && !pChild->pParent ) rc = SQLITE_CORRUPT;
119049 pChild = pChild->pParent;
119050 }
119051 return rc;
119052 }
119053
119054 static int deleteCell(Rtree *, RtreeNode *, int, int);
119055
119056 static int removeNode(Rtree *pRtree, RtreeNode *pNode, int iHeight){
119057 int rc;
119058 int rc2;
119059 RtreeNode *pParent;
119060 int iCell;
119061
119062 assert( pNode->nRef==1 );
119063
119064 /* Remove the entry in the parent cell. */
119065 rc = nodeParentIndex(pRtree, pNode, &iCell);
119066 if( rc==SQLITE_OK ){
119067 pParent = pNode->pParent;
119068 pNode->pParent = 0;
119069 rc = deleteCell(pRtree, pParent, iCell, iHeight+1);
119070 }
119071 rc2 = nodeRelease(pRtree, pParent);
119072 if( rc==SQLITE_OK ){
119073 rc = rc2;
119074 }
119075 if( rc!=SQLITE_OK ){
119076 return rc;
119077 }
119078
119079 /* Remove the xxx_node entry. */
119080 sqlite3_bind_int64(pRtree->pDeleteNode, 1, pNode->iNode);
@@ -118084,12 +119100,13 @@
119100 pRtree->pDeleted = pNode;
119101
119102 return SQLITE_OK;
119103 }
119104
119105 static int fixBoundingBox(Rtree *pRtree, RtreeNode *pNode){
119106 RtreeNode *pParent = pNode->pParent;
119107 int rc = SQLITE_OK;
119108 if( pParent ){
119109 int ii;
119110 int nCell = NCELL(pNode);
119111 RtreeCell box; /* Bounding box for pNode */
119112 nodeGetCell(pRtree, pNode, 0, &box);
@@ -118097,21 +119114,25 @@
119114 RtreeCell cell;
119115 nodeGetCell(pRtree, pNode, ii, &cell);
119116 cellUnion(pRtree, &box, &cell);
119117 }
119118 box.iRowid = pNode->iNode;
119119 rc = nodeParentIndex(pRtree, pNode, &ii);
119120 if( rc==SQLITE_OK ){
119121 nodeOverwriteCell(pRtree, pParent, &box, ii);
119122 rc = fixBoundingBox(pRtree, pParent);
119123 }
119124 }
119125 return rc;
119126 }
119127
119128 /*
119129 ** Delete the cell at index iCell of node pNode. After removing the
119130 ** cell, adjust the r-tree data structure if required.
119131 */
119132 static int deleteCell(Rtree *pRtree, RtreeNode *pNode, int iCell, int iHeight){
119133 RtreeNode *pParent;
119134 int rc;
119135
119136 if( SQLITE_OK!=(rc = fixLeafParent(pRtree, pNode)) ){
119137 return rc;
119138 }
@@ -118124,18 +119145,17 @@
119145 /* If the node is not the tree root and now has less than the minimum
119146 ** number of cells, remove it from the tree. Otherwise, update the
119147 ** cell in the parent node so that it tightly contains the updated
119148 ** node.
119149 */
119150 pParent = pNode->pParent;
119151 assert( pParent || pNode->iNode==1 );
119152 if( pParent ){
119153 if( NCELL(pNode)<RTREE_MINCELLS(pRtree) ){
 
119154 rc = removeNode(pRtree, pNode, iHeight);
119155 }else{
119156 rc = fixBoundingBox(pRtree, pNode);
119157 }
119158 }
119159
119160 return rc;
119161 }
@@ -118214,11 +119234,11 @@
119234 rc = parentWrite(pRtree, p->iRowid, pNode->iNode);
119235 }
119236 }
119237 }
119238 if( rc==SQLITE_OK ){
119239 rc = fixBoundingBox(pRtree, pNode);
119240 }
119241 for(; rc==SQLITE_OK && ii<nCell; ii++){
119242 /* Find a node to store this cell in. pNode->iNode currently contains
119243 ** the height of the sub-tree headed by the cell.
119244 */
@@ -118268,15 +119288,17 @@
119288 }
119289 #else
119290 rc = SplitNode(pRtree, pNode, pCell, iHeight);
119291 #endif
119292 }else{
119293 rc = AdjustTree(pRtree, pNode, pCell);
119294 if( rc==SQLITE_OK ){
119295 if( iHeight==0 ){
119296 rc = rowidWrite(pRtree, pCell->iRowid, pNode->iNode);
119297 }else{
119298 rc = parentWrite(pRtree, pCell->iRowid, pNode->iNode);
119299 }
119300 }
119301 }
119302 return rc;
119303 }
119304
@@ -118342,11 +119364,10 @@
119364 int rc = SQLITE_OK;
119365
119366 rtreeReference(pRtree);
119367
119368 assert(nData>=1);
 
119369
119370 /* If azData[0] is not an SQL NULL value, it is the rowid of a
119371 ** record to delete from the r-tree table. The following block does
119372 ** just that.
119373 */
@@ -118368,12 +119389,14 @@
119389 }
119390
119391 /* Delete the cell in question from the leaf node. */
119392 if( rc==SQLITE_OK ){
119393 int rc2;
119394 rc = nodeRowidIndex(pRtree, pLeaf, iDelete, &iCell);
119395 if( rc==SQLITE_OK ){
119396 rc = deleteCell(pRtree, pLeaf, iCell, 0);
119397 }
119398 rc2 = nodeRelease(pRtree, pLeaf);
119399 if( rc==SQLITE_OK ){
119400 rc = rc2;
119401 }
119402 }
@@ -118391,23 +119414,24 @@
119414 **
119415 ** This is equivalent to copying the contents of the child into
119416 ** the root node (the operation that Gutman's paper says to perform
119417 ** in this scenario).
119418 */
119419 if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
119420 int rc2;
119421 RtreeNode *pChild;
119422 i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
119423 rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
119424 if( rc==SQLITE_OK ){
119425 rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
119426 }
119427 rc2 = nodeRelease(pRtree, pChild);
119428 if( rc==SQLITE_OK ) rc = rc2;
119429 if( rc==SQLITE_OK ){
119430 pRtree->iDepth--;
119431 writeInt16(pRoot->zData, pRtree->iDepth);
119432 pRoot->isDirty = 1;
119433 }
119434 }
119435
119436 /* Re-insert the contents of any underfull nodes removed from the tree. */
119437 for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){
@@ -118693,11 +119717,11 @@
119717 ){
119718 int rc = SQLITE_OK;
119719 Rtree *pRtree;
119720 int nDb; /* Length of string argv[1] */
119721 int nName; /* Length of string argv[2] */
119722 int eCoordType = (pAux ? RTREE_COORD_INT32 : RTREE_COORD_REAL32);
119723
119724 const char *aErrMsg[] = {
119725 0, /* 0 */
119726 "Wrong number of columns for an rtree table", /* 1 */
119727 "Too few columns for an rtree table", /* 2 */
@@ -118839,16 +119863,14 @@
119863 ** Register the r-tree module with database handle db. This creates the
119864 ** virtual table module "rtree" and the debugging/analysis scalar
119865 ** function "rtreenode".
119866 */
119867 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db){
119868 const int utf8 = SQLITE_UTF8;
119869 int rc;
119870
119871 rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
 
 
 
119872 if( rc==SQLITE_OK ){
119873 int utf8 = SQLITE_UTF8;
119874 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
119875 }
119876 if( rc==SQLITE_OK ){
@@ -118860,10 +119882,74 @@
119882 rc = sqlite3_create_module_v2(db, "rtree_i32", &rtreeModule, c, 0);
119883 }
119884
119885 return rc;
119886 }
119887
119888 /*
119889 ** A version of sqlite3_free() that can be used as a callback. This is used
119890 ** in two places - as the destructor for the blob value returned by the
119891 ** invocation of a geometry function, and as the destructor for the geometry
119892 ** functions themselves.
119893 */
119894 static void doSqlite3Free(void *p){
119895 sqlite3_free(p);
119896 }
119897
119898 /*
119899 ** Each call to sqlite3_rtree_geometry_callback() creates an ordinary SQLite
119900 ** scalar user function. This C function is the callback used for all such
119901 ** registered SQL functions.
119902 **
119903 ** The scalar user functions return a blob that is interpreted by r-tree
119904 ** table MATCH operators.
119905 */
119906 static void geomCallback(sqlite3_context *ctx, int nArg, sqlite3_value **aArg){
119907 RtreeGeomCallback *pGeomCtx = (RtreeGeomCallback *)sqlite3_user_data(ctx);
119908 RtreeMatchArg *pBlob;
119909 int nBlob;
119910
119911 nBlob = sizeof(RtreeMatchArg) + (nArg-1)*sizeof(double);
119912 pBlob = (RtreeMatchArg *)sqlite3_malloc(nBlob);
119913 if( !pBlob ){
119914 sqlite3_result_error_nomem(ctx);
119915 }else{
119916 int i;
119917 pBlob->magic = RTREE_GEOMETRY_MAGIC;
119918 pBlob->xGeom = pGeomCtx->xGeom;
119919 pBlob->pContext = pGeomCtx->pContext;
119920 pBlob->nParam = nArg;
119921 for(i=0; i<nArg; i++){
119922 pBlob->aParam[i] = sqlite3_value_double(aArg[i]);
119923 }
119924 sqlite3_result_blob(ctx, pBlob, nBlob, doSqlite3Free);
119925 }
119926 }
119927
119928 /*
119929 ** Register a new geometry function for use with the r-tree MATCH operator.
119930 */
119931 SQLITE_API int sqlite3_rtree_geometry_callback(
119932 sqlite3 *db,
119933 const char *zGeom,
119934 int (*xGeom)(sqlite3_rtree_geometry *, int, double *, int *),
119935 void *pContext
119936 ){
119937 RtreeGeomCallback *pGeomCtx; /* Context object for new user-function */
119938
119939 /* Allocate and populate the context object. */
119940 pGeomCtx = (RtreeGeomCallback *)sqlite3_malloc(sizeof(RtreeGeomCallback));
119941 if( !pGeomCtx ) return SQLITE_NOMEM;
119942 pGeomCtx->xGeom = xGeom;
119943 pGeomCtx->pContext = pContext;
119944
119945 /* Create the new user-function. Register a destructor function to delete
119946 ** the context object when it is no longer required. */
119947 return sqlite3_create_function_v2(db, zGeom, -1, SQLITE_ANY,
119948 (void *)pGeomCtx, geomCallback, 0, 0, doSqlite3Free
119949 );
119950 }
119951
119952 #if !SQLITE_CORE
119953 SQLITE_API int sqlite3_extension_init(
119954 sqlite3 *db,
119955 char **pzErrMsg,
119956
+469 -251
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.7.2"
111
-#define SQLITE_VERSION_NUMBER 3007002
112
-#define SQLITE_SOURCE_ID "2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3"
110
+#define SQLITE_VERSION "3.7.3"
111
+#define SQLITE_VERSION_NUMBER 3007003
112
+#define SQLITE_SOURCE_ID "2010-10-04 23:55:51 ece641eb8951c6314cedbdb3243f91cb199c3239"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -755,19 +755,23 @@
755755
** object once the object has been registered.
756756
**
757757
** The zName field holds the name of the VFS module. The name must
758758
** be unique across all VFS modules.
759759
**
760
-** SQLite will guarantee that the zFilename parameter to xOpen
760
+** ^SQLite guarantees that the zFilename parameter to xOpen
761761
** is either a NULL pointer or string obtained
762
-** from xFullPathname(). SQLite further guarantees that
762
+** from xFullPathname() with an optional suffix added.
763
+** ^If a suffix is added to the zFilename parameter, it will
764
+** consist of a single "-" character followed by no more than
765
+** 10 alphanumeric and/or "-" characters.
766
+** ^SQLite further guarantees that
763767
** the string will be valid and unchanged until xClose() is
764768
** called. Because of the previous sentence,
765769
** the [sqlite3_file] can safely store a pointer to the
766770
** filename if it needs to remember the filename for some reason.
767
-** If the zFilename parameter is xOpen is a NULL pointer then xOpen
768
-** must invent its own temporary name for the file. Whenever the
771
+** If the zFilename parameter to xOpen is a NULL pointer then xOpen
772
+** must invent its own temporary name for the file. ^Whenever the
769773
** xFilename parameter is NULL it will also be the case that the
770774
** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
771775
**
772776
** The flags argument to xOpen() includes all bits set in
773777
** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
@@ -774,11 +778,11 @@
774778
** or [sqlite3_open16()] is used, then flags includes at least
775779
** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
776780
** If xOpen() opens a file read-only then it sets *pOutFlags to
777781
** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
778782
**
779
-** SQLite will also add one of the following flags to the xOpen()
783
+** ^(SQLite will also add one of the following flags to the xOpen()
780784
** call, depending on the object being opened:
781785
**
782786
** <ul>
783787
** <li> [SQLITE_OPEN_MAIN_DB]
784788
** <li> [SQLITE_OPEN_MAIN_JOURNAL]
@@ -785,11 +789,12 @@
785789
** <li> [SQLITE_OPEN_TEMP_DB]
786790
** <li> [SQLITE_OPEN_TEMP_JOURNAL]
787791
** <li> [SQLITE_OPEN_TRANSIENT_DB]
788792
** <li> [SQLITE_OPEN_SUBJOURNAL]
789793
** <li> [SQLITE_OPEN_MASTER_JOURNAL]
790
-** </ul>
794
+** <li> [SQLITE_OPEN_WAL]
795
+** </ul>)^
791796
**
792797
** The file I/O implementation can use the object type flags to
793798
** change the way it deals with files. For example, an application
794799
** that does not care about crash recovery or rollback might make
795800
** the open of a journal file a no-op. Writes to this journal would
@@ -804,39 +809,40 @@
804809
** <li> [SQLITE_OPEN_DELETEONCLOSE]
805810
** <li> [SQLITE_OPEN_EXCLUSIVE]
806811
** </ul>
807812
**
808813
** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
809
-** deleted when it is closed. The [SQLITE_OPEN_DELETEONCLOSE]
810
-** will be set for TEMP databases, journals and for subjournals.
814
+** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE]
815
+** will be set for TEMP databases and their journals, transient
816
+** databases, and subjournals.
811817
**
812
-** The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
818
+** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
813819
** with the [SQLITE_OPEN_CREATE] flag, which are both directly
814820
** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
815821
** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
816822
** SQLITE_OPEN_CREATE, is used to indicate that file should always
817823
** be created, and that it is an error if it already exists.
818824
** It is <i>not</i> used to indicate the file should be opened
819825
** for exclusive access.
820826
**
821
-** At least szOsFile bytes of memory are allocated by SQLite
827
+** ^At least szOsFile bytes of memory are allocated by SQLite
822828
** to hold the [sqlite3_file] structure passed as the third
823829
** argument to xOpen. The xOpen method does not have to
824830
** allocate the structure; it should just fill it in. Note that
825831
** the xOpen method must set the sqlite3_file.pMethods to either
826832
** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
827833
** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
828834
** element will be valid after xOpen returns regardless of the success
829835
** or failure of the xOpen call.
830836
**
831
-** The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
837
+** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
832838
** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
833839
** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
834840
** to test whether a file is at least readable. The file can be a
835841
** directory.
836842
**
837
-** SQLite will always allocate at least mxPathname+1 bytes for the
843
+** ^SQLite will always allocate at least mxPathname+1 bytes for the
838844
** output buffer xFullPathname. The exact size of the output buffer
839845
** is also passed as a parameter to both methods. If the output buffer
840846
** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
841847
** handled as a fatal error by SQLite, vfs implementations should endeavor
842848
** to prevent this by setting mxPathname to a sufficiently large value.
@@ -846,14 +852,14 @@
846852
** included in the VFS structure for completeness.
847853
** The xRandomness() function attempts to return nBytes bytes
848854
** of good-quality randomness into zOut. The return value is
849855
** the actual number of bytes of randomness obtained.
850856
** The xSleep() method causes the calling thread to sleep for at
851
-** least the number of microseconds given. The xCurrentTime()
857
+** least the number of microseconds given. ^The xCurrentTime()
852858
** method returns a Julian Day Number for the current date and time as
853859
** a floating point value.
854
-** The xCurrentTimeInt64() method returns, as an integer, the Julian
860
+** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
855861
** Day Number multipled by 86400000 (the number of milliseconds in
856862
** a 24-hour day).
857863
** ^SQLite will use the xCurrentTimeInt64() method to get the current
858864
** date and time if that method is available (if iVersion is 2 or
859865
** greater and the function pointer is not NULL) and will fall back
@@ -1246,11 +1252,11 @@
12461252
** statistics. ^(When memory allocation statistics are disabled, the
12471253
** following SQLite interfaces become non-operational:
12481254
** <ul>
12491255
** <li> [sqlite3_memory_used()]
12501256
** <li> [sqlite3_memory_highwater()]
1251
-** <li> [sqlite3_soft_heap_limit()]
1257
+** <li> [sqlite3_soft_heap_limit64()]
12521258
** <li> [sqlite3_status()]
12531259
** </ul>)^
12541260
** ^Memory allocation statistics are enabled by default unless SQLite is
12551261
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
12561262
** allocation statistics are disabled by default.
@@ -1260,19 +1266,18 @@
12601266
** <dd> ^This option specifies a static memory buffer that SQLite can use for
12611267
** scratch memory. There are three arguments: A pointer an 8-byte
12621268
** aligned memory buffer from which the scrach allocations will be
12631269
** drawn, the size of each scratch allocation (sz),
12641270
** and the maximum number of scratch allocations (N). The sz
1265
-** argument must be a multiple of 16. The sz parameter should be a few bytes
1266
-** larger than the actual scratch space required due to internal overhead.
1271
+** argument must be a multiple of 16.
12671272
** The first argument must be a pointer to an 8-byte aligned buffer
12681273
** of at least sz*N bytes of memory.
1269
-** ^SQLite will use no more than one scratch buffer per thread. So
1270
-** N should be set to the expected maximum number of threads. ^SQLite will
1271
-** never require a scratch buffer that is more than 6 times the database
1272
-** page size. ^If SQLite needs needs additional scratch memory beyond
1273
-** what is provided by this configuration option, then
1274
+** ^SQLite will use no more than two scratch buffers per thread. So
1275
+** N should be set to twice the expected maximum number of threads.
1276
+** ^SQLite will never require a scratch buffer that is more than 6
1277
+** times the database page size. ^If SQLite needs needs additional
1278
+** scratch memory beyond what is provided by this configuration option, then
12741279
** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
12751280
**
12761281
** <dt>SQLITE_CONFIG_PAGECACHE</dt>
12771282
** <dd> ^This option specifies a static memory buffer that SQLite can use for
12781283
** the database page cache with the default page cache implemenation.
@@ -1288,12 +1293,11 @@
12881293
** argument should point to an allocation of at least sz*N bytes of memory.
12891294
** ^SQLite will use the memory provided by the first argument to satisfy its
12901295
** memory needs for the first N pages that it adds to cache. ^If additional
12911296
** page cache memory is needed beyond what is provided by this option, then
12921297
** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1293
-** ^The implementation might use one or more of the N buffers to hold
1294
-** memory accounting information. The pointer in the first argument must
1298
+** The pointer in the first argument must
12951299
** be aligned to an 8-byte boundary or subsequent behavior of SQLite
12961300
** will be undefined.</dd>
12971301
**
12981302
** <dt>SQLITE_CONFIG_HEAP</dt>
12991303
** <dd> ^This option specifies a static memory buffer that SQLite will use
@@ -1418,12 +1422,18 @@
14181422
** size of each lookaside buffer slot. ^The third argument is the number of
14191423
** slots. The size of the buffer in the first argument must be greater than
14201424
** or equal to the product of the second and third arguments. The buffer
14211425
** must be aligned to an 8-byte boundary. ^If the second argument to
14221426
** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
1423
-** rounded down to the next smaller
1424
-** multiple of 8. See also: [SQLITE_CONFIG_LOOKASIDE]</dd>
1427
+** rounded down to the next smaller multiple of 8. ^(The lookaside memory
1428
+** configuration for a database connection can only be changed when that
1429
+** connection is not currently using lookaside memory, or in other words
1430
+** when the "current value" returned by
1431
+** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
1432
+** Any attempt to change the lookaside memory configuration when lookaside
1433
+** memory is in use leaves the configuration unchanged and returns
1434
+** [SQLITE_BUSY].)^</dd>
14251435
**
14261436
** </dl>
14271437
*/
14281438
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
14291439
@@ -1723,10 +1733,13 @@
17231733
*/
17241734
SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
17251735
17261736
/*
17271737
** CAPI3REF: Convenience Routines For Running Queries
1738
+**
1739
+** This is a legacy interface that is preserved for backwards compatibility.
1740
+** Use of this interface is not recommended.
17281741
**
17291742
** Definition: A <b>result table</b> is memory data structure created by the
17301743
** [sqlite3_get_table()] interface. A result table records the
17311744
** complete query results from one or more queries.
17321745
**
@@ -1744,11 +1757,11 @@
17441757
**
17451758
** A result table might consist of one or more memory allocations.
17461759
** It is not safe to pass a result table directly to [sqlite3_free()].
17471760
** A result table should be deallocated using [sqlite3_free_table()].
17481761
**
1749
-** As an example of the result table format, suppose a query result
1762
+** ^(As an example of the result table format, suppose a query result
17501763
** is as follows:
17511764
**
17521765
** <blockquote><pre>
17531766
** Name | Age
17541767
** -----------------------
@@ -1768,31 +1781,31 @@
17681781
** azResult&#91;3] = "43";
17691782
** azResult&#91;4] = "Bob";
17701783
** azResult&#91;5] = "28";
17711784
** azResult&#91;6] = "Cindy";
17721785
** azResult&#91;7] = "21";
1773
-** </pre></blockquote>
1786
+** </pre></blockquote>)^
17741787
**
17751788
** ^The sqlite3_get_table() function evaluates one or more
17761789
** semicolon-separated SQL statements in the zero-terminated UTF-8
17771790
** string of its 2nd parameter and returns a result table to the
17781791
** pointer given in its 3rd parameter.
17791792
**
17801793
** After the application has finished with the result from sqlite3_get_table(),
1781
-** it should pass the result table pointer to sqlite3_free_table() in order to
1794
+** it must pass the result table pointer to sqlite3_free_table() in order to
17821795
** release the memory that was malloced. Because of the way the
17831796
** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
17841797
** function must not try to call [sqlite3_free()] directly. Only
17851798
** [sqlite3_free_table()] is able to release the memory properly and safely.
17861799
**
1787
-** ^(The sqlite3_get_table() interface is implemented as a wrapper around
1800
+** The sqlite3_get_table() interface is implemented as a wrapper around
17881801
** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
17891802
** to any internal data structures of SQLite. It uses only the public
17901803
** interface defined here. As a consequence, errors that occur in the
17911804
** wrapper layer outside of the internal [sqlite3_exec()] call are not
17921805
** reflected in subsequent calls to [sqlite3_errcode()] or
1793
-** [sqlite3_errmsg()].)^
1806
+** [sqlite3_errmsg()].
17941807
*/
17951808
SQLITE_API int sqlite3_get_table(
17961809
sqlite3 *db, /* An open database */
17971810
const char *zSql, /* SQL to be evaluated */
17981811
char ***pazResult, /* Results of the query */
@@ -1940,11 +1953,13 @@
19401953
** by sqlite3_realloc() and the prior allocation is freed.
19411954
** ^If sqlite3_realloc() returns NULL, then the prior allocation
19421955
** is not freed.
19431956
**
19441957
** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
1945
-** is always aligned to at least an 8 byte boundary.
1958
+** is always aligned to at least an 8 byte boundary, or to a
1959
+** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
1960
+** option is used.
19461961
**
19471962
** In SQLite version 3.5.0 and 3.5.1, it was possible to define
19481963
** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
19491964
** implementation of these routines to be omitted. That capability
19501965
** is no longer provided. Only built-in memory allocators can be used.
@@ -2198,21 +2213,32 @@
21982213
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
21992214
22002215
/*
22012216
** CAPI3REF: Query Progress Callbacks
22022217
**
2203
-** ^This routine configures a callback function - the
2204
-** progress callback - that is invoked periodically during long
2205
-** running calls to [sqlite3_exec()], [sqlite3_step()] and
2206
-** [sqlite3_get_table()]. An example use for this
2218
+** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2219
+** function X to be invoked periodically during long running calls to
2220
+** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2221
+** database connection D. An example use for this
22072222
** interface is to keep a GUI updated during a large query.
2223
+**
2224
+** ^The parameter P is passed through as the only parameter to the
2225
+** callback function X. ^The parameter N is the number of
2226
+** [virtual machine instructions] that are evaluated between successive
2227
+** invocations of the callback X.
2228
+**
2229
+** ^Only a single progress handler may be defined at one time per
2230
+** [database connection]; setting a new progress handler cancels the
2231
+** old one. ^Setting parameter X to NULL disables the progress handler.
2232
+** ^The progress handler is also disabled by setting N to a value less
2233
+** than 1.
22082234
**
22092235
** ^If the progress callback returns non-zero, the operation is
22102236
** interrupted. This feature can be used to implement a
22112237
** "Cancel" button on a GUI progress dialog box.
22122238
**
2213
-** The progress handler must not do anything that will modify
2239
+** The progress handler callback must not do anything that will modify
22142240
** the database connection that invoked the progress handler.
22152241
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
22162242
** database connections for the meaning of "modify" in this paragraph.
22172243
**
22182244
*/
@@ -2267,11 +2293,11 @@
22672293
** </dl>
22682294
**
22692295
** If the 3rd parameter to sqlite3_open_v2() is not one of the
22702296
** combinations shown above or one of the combinations shown above combined
22712297
** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
2272
-** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_SHAREDCACHE] flags,
2298
+** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags,
22732299
** then the behavior is undefined.
22742300
**
22752301
** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
22762302
** opens in the multi-thread [threading mode] as long as the single-thread
22772303
** mode has not been set at compile-time or start-time. ^If the
@@ -2392,21 +2418,26 @@
23922418
** ^(This interface allows the size of various constructs to be limited
23932419
** on a connection by connection basis. The first parameter is the
23942420
** [database connection] whose limit is to be set or queried. The
23952421
** second parameter is one of the [limit categories] that define a
23962422
** class of constructs to be size limited. The third parameter is the
2397
-** new limit for that construct. The function returns the old limit.)^
2423
+** new limit for that construct.)^
23982424
**
23992425
** ^If the new limit is a negative number, the limit is unchanged.
2400
-** ^(For the limit category of SQLITE_LIMIT_XYZ there is a
2426
+** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
24012427
** [limits | hard upper bound]
2402
-** set by a compile-time C preprocessor macro named
2403
-** [limits | SQLITE_MAX_XYZ].
2428
+** set at compile-time by a C preprocessor macro called
2429
+** [limits | SQLITE_MAX_<i>NAME</i>].
24042430
** (The "_LIMIT_" in the name is changed to "_MAX_".))^
24052431
** ^Attempts to increase a limit above its hard upper bound are
24062432
** silently truncated to the hard upper bound.
24072433
**
2434
+** ^Regardless of whether or not the limit was changed, the
2435
+** [sqlite3_limit()] interface returns the prior value of the limit.
2436
+** ^Hence, to find the current value of a limit without changing it,
2437
+** simply invoke this interface with the third parameter set to -1.
2438
+**
24082439
** Run-time limits are intended for use in applications that manage
24092440
** both their own internal database and also databases that are controlled
24102441
** by untrusted external sources. An example application might be a
24112442
** web browser that has its own databases for storing history and
24122443
** separate databases controlled by JavaScript applications downloaded
@@ -2431,11 +2462,11 @@
24312462
** The synopsis of the meanings of the various limits is shown below.
24322463
** Additional information is available at [limits | Limits in SQLite].
24332464
**
24342465
** <dl>
24352466
** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
2436
-** <dd>The maximum size of any string or BLOB or table row.<dd>)^
2467
+** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
24372468
**
24382469
** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
24392470
** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
24402471
**
24412472
** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
@@ -2449,11 +2480,13 @@
24492480
** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
24502481
** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
24512482
**
24522483
** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
24532484
** <dd>The maximum number of instructions in a virtual machine program
2454
-** used to implement an SQL statement.</dd>)^
2485
+** used to implement an SQL statement. This limit is not currently
2486
+** enforced, though that might be added in some future release of
2487
+** SQLite.</dd>)^
24552488
**
24562489
** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
24572490
** <dd>The maximum number of arguments on a function.</dd>)^
24582491
**
24592492
** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
@@ -2462,12 +2495,11 @@
24622495
** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
24632496
** <dd>The maximum length of the pattern argument to the [LIKE] or
24642497
** [GLOB] operators.</dd>)^
24652498
**
24662499
** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
2467
-** <dd>The maximum number of variables in an SQL statement that can
2468
-** be bound.</dd>)^
2500
+** <dd>The maximum index number of any [parameter] in an SQL statement.)^
24692501
**
24702502
** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
24712503
** <dd>The maximum depth of recursion for triggers.</dd>)^
24722504
** </dl>
24732505
*/
@@ -2535,16 +2567,11 @@
25352567
**
25362568
** <ol>
25372569
** <li>
25382570
** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
25392571
** always used to do, [sqlite3_step()] will automatically recompile the SQL
2540
-** statement and try to run it again. ^If the schema has changed in
2541
-** a way that makes the statement no longer valid, [sqlite3_step()] will still
2542
-** return [SQLITE_SCHEMA]. But unlike the legacy behavior, [SQLITE_SCHEMA] is
2543
-** now a fatal error. Calling [sqlite3_prepare_v2()] again will not make the
2544
-** error go away. Note: use [sqlite3_errmsg()] to find the text
2545
-** of the parsing error that results in an [SQLITE_SCHEMA] return.
2572
+** statement and try to run it again.
25462573
** </li>
25472574
**
25482575
** <li>
25492576
** ^When an error occurs, [sqlite3_step()] will return one of the detailed
25502577
** [error codes] or [extended error codes]. ^The legacy behavior was that
@@ -2553,15 +2580,20 @@
25532580
** in order to find the underlying cause of the problem. With the "v2" prepare
25542581
** interfaces, the underlying reason for the error is returned immediately.
25552582
** </li>
25562583
**
25572584
** <li>
2558
-** ^If the value of a [parameter | host parameter] in the WHERE clause might
2559
-** change the query plan for a statement, then the statement may be
2560
-** automatically recompiled (as if there had been a schema change) on the first
2561
-** [sqlite3_step()] call following any change to the
2562
-** [sqlite3_bind_text | bindings] of the [parameter].
2585
+** ^If the specific value bound to [parameter | host parameter] in the
2586
+** WHERE clause might influence the choice of query plan for a statement,
2587
+** then the statement will be automatically recompiled, as if there had been
2588
+** a schema change, on the first [sqlite3_step()] call following any change
2589
+** to the [sqlite3_bind_text | bindings] of that [parameter].
2590
+** ^The specific value of WHERE-clause [parameter] might influence the
2591
+** choice of query plan if the parameter is the left-hand side of a [LIKE]
2592
+** or [GLOB] operator or if the parameter is compared to an indexed column
2593
+** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled.
2594
+** the
25632595
** </li>
25642596
** </ol>
25652597
*/
25662598
SQLITE_API int sqlite3_prepare(
25672599
sqlite3 *db, /* Database handle */
@@ -2624,11 +2656,11 @@
26242656
** or if SQLite is run in one of reduced mutex modes
26252657
** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
26262658
** then there is no distinction between protected and unprotected
26272659
** sqlite3_value objects and they can be used interchangeably. However,
26282660
** for maximum code portability it is recommended that applications
2629
-** still make the distinction between between protected and unprotected
2661
+** still make the distinction between protected and unprotected
26302662
** sqlite3_value objects even when not strictly required.
26312663
**
26322664
** ^The sqlite3_value objects that are passed as parameters into the
26332665
** implementation of [application-defined SQL functions] are protected.
26342666
** ^The sqlite3_value object returned by
@@ -2819,10 +2851,12 @@
28192851
** CAPI3REF: Number Of Columns In A Result Set
28202852
**
28212853
** ^Return the number of columns in the result set returned by the
28222854
** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
28232855
** statement that does not return data (for example an [UPDATE]).
2856
+**
2857
+** See also: [sqlite3_data_count()]
28242858
*/
28252859
SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
28262860
28272861
/*
28282862
** CAPI3REF: Column Names In A Result Set
@@ -3009,12 +3043,18 @@
30093043
SQLITE_API int sqlite3_step(sqlite3_stmt*);
30103044
30113045
/*
30123046
** CAPI3REF: Number of columns in a result set
30133047
**
3014
-** ^The sqlite3_data_count(P) the number of columns in the
3015
-** of the result set of [prepared statement] P.
3048
+** ^The sqlite3_data_count(P) interface returns the number of columns in the
3049
+** current row of the result set of [prepared statement] P.
3050
+** ^If prepared statement P does not have results ready to return
3051
+** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
3052
+** interfaces) then sqlite3_data_count(P) returns 0.
3053
+** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
3054
+**
3055
+** See also: [sqlite3_column_count()]
30163056
*/
30173057
SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
30183058
30193059
/*
30203060
** CAPI3REF: Fundamental Datatypes
@@ -3090,22 +3130,30 @@
30903130
** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
30913131
** the string to UTF-8 and then returns the number of bytes.
30923132
** ^If the result is a numeric value then sqlite3_column_bytes() uses
30933133
** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
30943134
** the number of bytes in that string.
3095
-** ^The value returned does not include the zero terminator at the end
3096
-** of the string. ^For clarity: the value returned is the number of
3135
+** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
3136
+**
3137
+** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
3138
+** routine returns the number of bytes in that BLOB or string.
3139
+** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
3140
+** the string to UTF-16 and then returns the number of bytes.
3141
+** ^If the result is a numeric value then sqlite3_column_bytes16() uses
3142
+** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
3143
+** the number of bytes in that string.
3144
+** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
3145
+**
3146
+** ^The values returned by [sqlite3_column_bytes()] and
3147
+** [sqlite3_column_bytes16()] do not include the zero terminators at the end
3148
+** of the string. ^For clarity: the values returned by
3149
+** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
30973150
** bytes in the string, not the number of characters.
30983151
**
30993152
** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
31003153
** even empty strings, are always zero terminated. ^The return
3101
-** value from sqlite3_column_blob() for a zero-length BLOB is an arbitrary
3102
-** pointer, possibly even a NULL pointer.
3103
-**
3104
-** ^The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
3105
-** but leaves the result in UTF-16 in native byte order instead of UTF-8.
3106
-** ^The zero terminator is not included in this count.
3154
+** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
31073155
**
31083156
** ^The object returned by [sqlite3_column_value()] is an
31093157
** [unprotected sqlite3_value] object. An unprotected sqlite3_value object
31103158
** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
31113159
** If the [unprotected sqlite3_value] object returned by
@@ -3146,14 +3194,14 @@
31463194
** and atof(). SQLite does not really use these functions. It has its
31473195
** own equivalent internal routines. The atoi() and atof() names are
31483196
** used in the table for brevity and because they are familiar to most
31493197
** C programmers.
31503198
**
3151
-** ^Note that when type conversions occur, pointers returned by prior
3199
+** Note that when type conversions occur, pointers returned by prior
31523200
** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
31533201
** sqlite3_column_text16() may be invalidated.
3154
-** ^(Type conversions and pointer invalidations might occur
3202
+** Type conversions and pointer invalidations might occur
31553203
** in the following cases:
31563204
**
31573205
** <ul>
31583206
** <li> The initial content is a BLOB and sqlite3_column_text() or
31593207
** sqlite3_column_text16() is called. A zero-terminator might
@@ -3162,26 +3210,26 @@
31623210
** sqlite3_column_text16() is called. The content must be converted
31633211
** to UTF-16.</li>
31643212
** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
31653213
** sqlite3_column_text() is called. The content must be converted
31663214
** to UTF-8.</li>
3167
-** </ul>)^
3215
+** </ul>
31683216
**
31693217
** ^Conversions between UTF-16be and UTF-16le are always done in place and do
31703218
** not invalidate a prior pointer, though of course the content of the buffer
3171
-** that the prior pointer points to will have been modified. Other kinds
3219
+** that the prior pointer references will have been modified. Other kinds
31723220
** of conversion are done in place when it is possible, but sometimes they
31733221
** are not possible and in those cases prior pointers are invalidated.
31743222
**
3175
-** ^(The safest and easiest to remember policy is to invoke these routines
3223
+** The safest and easiest to remember policy is to invoke these routines
31763224
** in one of the following ways:
31773225
**
31783226
** <ul>
31793227
** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
31803228
** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
31813229
** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
3182
-** </ul>)^
3230
+** </ul>
31833231
**
31843232
** In other words, you should call sqlite3_column_text(),
31853233
** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
31863234
** into the desired format, then invoke sqlite3_column_bytes() or
31873235
** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
@@ -3215,21 +3263,30 @@
32153263
32163264
/*
32173265
** CAPI3REF: Destroy A Prepared Statement Object
32183266
**
32193267
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
3220
-** ^If the statement was executed successfully or not executed at all, then
3221
-** SQLITE_OK is returned. ^If execution of the statement failed then an
3222
-** [error code] or [extended error code] is returned.
3268
+** ^If the most recent evaluation of the statement encountered no errors or
3269
+** or if the statement is never been evaluated, then sqlite3_finalize() returns
3270
+** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
3271
+** sqlite3_finalize(S) returns the appropriate [error code] or
3272
+** [extended error code].
32233273
**
3224
-** ^This routine can be called at any point during the execution of the
3225
-** [prepared statement]. ^If the virtual machine has not
3226
-** completed execution when this routine is called, that is like
3227
-** encountering an error or an [sqlite3_interrupt | interrupt].
3228
-** ^Incomplete updates may be rolled back and transactions canceled,
3229
-** depending on the circumstances, and the
3230
-** [error code] returned will be [SQLITE_ABORT].
3274
+** ^The sqlite3_finalize(S) routine can be called at any point during
3275
+** the life cycle of [prepared statement] S:
3276
+** before statement S is ever evaluated, after
3277
+** one or more calls to [sqlite3_reset()], or after any call
3278
+** to [sqlite3_step()] regardless of whether or not the statement has
3279
+** completed execution.
3280
+**
3281
+** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
3282
+**
3283
+** The application must finalize every [prepared statement] in order to avoid
3284
+** resource leaks. It is a grievous error for the application to try to use
3285
+** a prepared statement after it has been finalized. Any use of a prepared
3286
+** statement after it has been finalized can result in undefined and
3287
+** undesirable behavior such as segfaults and heap corruption.
32313288
*/
32323289
SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
32333290
32343291
/*
32353292
** CAPI3REF: Reset A Prepared Statement Object
@@ -3261,40 +3318,42 @@
32613318
** CAPI3REF: Create Or Redefine SQL Functions
32623319
** KEYWORDS: {function creation routines}
32633320
** KEYWORDS: {application-defined SQL function}
32643321
** KEYWORDS: {application-defined SQL functions}
32653322
**
3266
-** ^These two functions (collectively known as "function creation routines")
3323
+** ^These functions (collectively known as "function creation routines")
32673324
** are used to add SQL functions or aggregates or to redefine the behavior
3268
-** of existing SQL functions or aggregates. The only difference between the
3269
-** two is that the second parameter, the name of the (scalar) function or
3270
-** aggregate, is encoded in UTF-8 for sqlite3_create_function() and UTF-16
3271
-** for sqlite3_create_function16().
3325
+** of existing SQL functions or aggregates. The only differences between
3326
+** these routines are the text encoding expected for
3327
+** the the second parameter (the name of the function being created)
3328
+** and the presence or absence of a destructor callback for
3329
+** the application data pointer.
32723330
**
32733331
** ^The first parameter is the [database connection] to which the SQL
32743332
** function is to be added. ^If an application uses more than one database
32753333
** connection then application-defined SQL functions must be added
32763334
** to each database connection separately.
32773335
**
3278
-** The second parameter is the name of the SQL function to be created or
3279
-** redefined. ^The length of the name is limited to 255 bytes, exclusive of
3280
-** the zero-terminator. Note that the name length limit is in bytes, not
3281
-** characters. ^Any attempt to create a function with a longer name
3282
-** will result in [SQLITE_ERROR] being returned.
3336
+** ^The second parameter is the name of the SQL function to be created or
3337
+** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
3338
+** representation, exclusive of the zero-terminator. ^Note that the name
3339
+** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
3340
+** ^Any attempt to create a function with a longer name
3341
+** will result in [SQLITE_MISUSE] being returned.
32833342
**
32843343
** ^The third parameter (nArg)
32853344
** is the number of arguments that the SQL function or
32863345
** aggregate takes. ^If this parameter is -1, then the SQL function or
32873346
** aggregate may take any number of arguments between 0 and the limit
32883347
** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
32893348
** parameter is less than -1 or greater than 127 then the behavior is
32903349
** undefined.
32913350
**
3292
-** The fourth parameter, eTextRep, specifies what
3351
+** ^The fourth parameter, eTextRep, specifies what
32933352
** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3294
-** its parameters. Any SQL function implementation should be able to work
3295
-** work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3353
+** its parameters. Every SQL function implementation must be able to work
3354
+** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
32963355
** more efficient with one encoding than another. ^An application may
32973356
** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
32983357
** times with the same function but with different values of eTextRep.
32993358
** ^When multiple implementations of the same function are available, SQLite
33003359
** will pick the one that involves the least amount of data conversion.
@@ -3302,17 +3361,25 @@
33023361
** encoding is used, then the fourth argument should be [SQLITE_ANY].
33033362
**
33043363
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
33053364
** function can gain access to this pointer using [sqlite3_user_data()].)^
33063365
**
3307
-** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
3366
+** ^The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
33083367
** pointers to C-language functions that implement the SQL function or
33093368
** aggregate. ^A scalar SQL function requires an implementation of the xFunc
3310
-** callback only; NULL pointers should be passed as the xStep and xFinal
3369
+** callback only; NULL pointers must be passed as the xStep and xFinal
33113370
** parameters. ^An aggregate SQL function requires an implementation of xStep
3312
-** and xFinal and NULL should be passed for xFunc. ^To delete an existing
3313
-** SQL function or aggregate, pass NULL for all three function callbacks.
3371
+** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
3372
+** SQL function or aggregate, pass NULL poiners for all three function
3373
+** callbacks.
3374
+**
3375
+** ^If the tenth parameter to sqlite3_create_function_v2() is not NULL,
3376
+** then it is invoked when the function is deleted, either by being
3377
+** overloaded or when the database connection closes.
3378
+** ^When the destructure callback of the tenth parameter is invoked, it
3379
+** is passed a single argument which is a copy of the pointer which was
3380
+** the fifth parameter to sqlite3_create_function_v2().
33143381
**
33153382
** ^It is permitted to register multiple implementations of the same
33163383
** functions with the same name but with either differing numbers of
33173384
** arguments or differing preferred text encodings. ^SQLite will use
33183385
** the implementation that most closely matches the way in which the
@@ -3324,15 +3391,10 @@
33243391
** ^A function where the encoding difference is between UTF16le and UTF16be
33253392
** is a closer match than a function where the encoding difference is
33263393
** between UTF8 and UTF16.
33273394
**
33283395
** ^Built-in functions may be overloaded by new application-defined functions.
3329
-** ^The first application-defined function with a given name overrides all
3330
-** built-in functions in the same [database connection] with the same name.
3331
-** ^Subsequent application-defined functions of the same name only override
3332
-** prior application-defined functions that are an exact match for the
3333
-** number of parameters and preferred encoding.
33343396
**
33353397
** ^An application-defined function is permitted to call other
33363398
** SQLite interfaces. However, such calls must not
33373399
** close the database connection nor finalize or reset the prepared
33383400
** statement in which the function is running.
@@ -3354,10 +3416,21 @@
33543416
int eTextRep,
33553417
void *pApp,
33563418
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
33573419
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
33583420
void (*xFinal)(sqlite3_context*)
3421
+);
3422
+SQLITE_API int sqlite3_create_function_v2(
3423
+ sqlite3 *db,
3424
+ const char *zFunctionName,
3425
+ int nArg,
3426
+ int eTextRep,
3427
+ void *pApp,
3428
+ void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
3429
+ void (*xStep)(sqlite3_context*,int,sqlite3_value**),
3430
+ void (*xFinal)(sqlite3_context*),
3431
+ void(*xDestroy)(void*)
33593432
);
33603433
33613434
/*
33623435
** CAPI3REF: Text Encodings
33633436
**
@@ -3701,73 +3774,97 @@
37013774
SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
37023775
37033776
/*
37043777
** CAPI3REF: Define New Collating Sequences
37053778
**
3706
-** These functions are used to add new collation sequences to the
3707
-** [database connection] specified as the first argument.
3779
+** ^These functions add, remove, or modify a [collation] associated
3780
+** with the [database connection] specified as the first argument.
37083781
**
3709
-** ^The name of the new collation sequence is specified as a UTF-8 string
3782
+** ^The name of the collation is a UTF-8 string
37103783
** for sqlite3_create_collation() and sqlite3_create_collation_v2()
3711
-** and a UTF-16 string for sqlite3_create_collation16(). ^In all cases
3712
-** the name is passed as the second function argument.
3713
-**
3714
-** ^The third argument may be one of the constants [SQLITE_UTF8],
3715
-** [SQLITE_UTF16LE], or [SQLITE_UTF16BE], indicating that the user-supplied
3716
-** routine expects to be passed pointers to strings encoded using UTF-8,
3717
-** UTF-16 little-endian, or UTF-16 big-endian, respectively. ^The
3718
-** third argument might also be [SQLITE_UTF16] to indicate that the routine
3719
-** expects pointers to be UTF-16 strings in the native byte order, or the
3720
-** argument can be [SQLITE_UTF16_ALIGNED] if the
3721
-** the routine expects pointers to 16-bit word aligned strings
3722
-** of UTF-16 in the native byte order.
3723
-**
3724
-** A pointer to the user supplied routine must be passed as the fifth
3725
-** argument. ^If it is NULL, this is the same as deleting the collation
3726
-** sequence (so that SQLite cannot call it any more).
3727
-** ^Each time the application supplied function is invoked, it is passed
3728
-** as its first parameter a copy of the void* passed as the fourth argument
3729
-** to sqlite3_create_collation() or sqlite3_create_collation16().
3730
-**
3731
-** ^The remaining arguments to the application-supplied routine are two strings,
3732
-** each represented by a (length, data) pair and encoded in the encoding
3733
-** that was passed as the third argument when the collation sequence was
3734
-** registered. The application defined collation routine should
3735
-** return negative, zero or positive if the first string is less than,
3736
-** equal to, or greater than the second string. i.e. (STRING1 - STRING2).
3784
+** and a UTF-16 string in native byte order for sqlite3_create_collation16().
3785
+** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
3786
+** considered to be the same name.
3787
+**
3788
+** ^(The third argument (eTextRep) must be one of the constants:
3789
+** <ul>
3790
+** <li> [SQLITE_UTF8],
3791
+** <li> [SQLITE_UTF16LE],
3792
+** <li> [SQLITE_UTF16BE],
3793
+** <li> [SQLITE_UTF16], or
3794
+** <li> [SQLITE_UTF16_ALIGNED].
3795
+** </ul>)^
3796
+** ^The eTextRep argument determines the encoding of strings passed
3797
+** to the collating function callback, xCallback.
3798
+** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
3799
+** force strings to be UTF16 with native byte order.
3800
+** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
3801
+** on an even byte address.
3802
+**
3803
+** ^The fourth argument, pArg, is a application data pointer that is passed
3804
+** through as the first argument to the collating function callback.
3805
+**
3806
+** ^The fifth argument, xCallback, is a pointer to the collating function.
3807
+** ^Multiple collating functions can be registered using the same name but
3808
+** with different eTextRep parameters and SQLite will use whichever
3809
+** function requires the least amount of data transformation.
3810
+** ^If the xCallback argument is NULL then the collating function is
3811
+** deleted. ^When all collating functions having the same name are deleted,
3812
+** that collation is no longer usable.
3813
+**
3814
+** ^The collating function callback is invoked with a copy of the pArg
3815
+** application data pointer and with two strings in the encoding specified
3816
+** by the eTextRep argument. The collating function must return an
3817
+** integer that is negative, zero, or positive
3818
+** if the first string is less than, equal to, or greater than the second,
3819
+** respectively. A collating function must alway return the same answer
3820
+** given the same inputs. If two or more collating functions are registered
3821
+** to the same collation name (using different eTextRep values) then all
3822
+** must give an equivalent answer when invoked with equivalent strings.
3823
+** The collating function must obey the following properties for all
3824
+** strings A, B, and C:
3825
+**
3826
+** <ol>
3827
+** <li> If A==B then B==A.
3828
+** <li> If A==B and B==C then A==C.
3829
+** <li> If A&lt;B THEN B&gt;A.
3830
+** <li> If A&lt;B and B&lt;C then A&lt;C.
3831
+** </ol>
3832
+**
3833
+** If a collating function fails any of the above constraints and that
3834
+** collating function is registered and used, then the behavior of SQLite
3835
+** is undefined.
37373836
**
37383837
** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
3739
-** except that it takes an extra argument which is a destructor for
3740
-** the collation. ^The destructor is called when the collation is
3741
-** destroyed and is passed a copy of the fourth parameter void* pointer
3742
-** of the sqlite3_create_collation_v2().
3743
-** ^Collations are destroyed when they are overridden by later calls to the
3744
-** collation creation functions or when the [database connection] is closed
3745
-** using [sqlite3_close()].
3838
+** with the addition that the xDestroy callback is invoked on pArg when
3839
+** the collating function is deleted.
3840
+** ^Collating functions are deleted when they are overridden by later
3841
+** calls to the collation creation functions or when the
3842
+** [database connection] is closed using [sqlite3_close()].
37463843
**
37473844
** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
37483845
*/
37493846
SQLITE_API int sqlite3_create_collation(
37503847
sqlite3*,
37513848
const char *zName,
37523849
int eTextRep,
3753
- void*,
3850
+ void *pArg,
37543851
int(*xCompare)(void*,int,const void*,int,const void*)
37553852
);
37563853
SQLITE_API int sqlite3_create_collation_v2(
37573854
sqlite3*,
37583855
const char *zName,
37593856
int eTextRep,
3760
- void*,
3857
+ void *pArg,
37613858
int(*xCompare)(void*,int,const void*,int,const void*),
37623859
void(*xDestroy)(void*)
37633860
);
37643861
SQLITE_API int sqlite3_create_collation16(
37653862
sqlite3*,
37663863
const void *zName,
37673864
int eTextRep,
3768
- void*,
3865
+ void *pArg,
37693866
int(*xCompare)(void*,int,const void*,int,const void*)
37703867
);
37713868
37723869
/*
37733870
** CAPI3REF: Collation Needed Callbacks
@@ -3852,20 +3949,23 @@
38523949
#endif
38533950
38543951
/*
38553952
** CAPI3REF: Suspend Execution For A Short Time
38563953
**
3857
-** ^The sqlite3_sleep() function causes the current thread to suspend execution
3954
+** The sqlite3_sleep() function causes the current thread to suspend execution
38583955
** for at least a number of milliseconds specified in its parameter.
38593956
**
3860
-** ^If the operating system does not support sleep requests with
3957
+** If the operating system does not support sleep requests with
38613958
** millisecond time resolution, then the time will be rounded up to
3862
-** the nearest second. ^The number of milliseconds of sleep actually
3959
+** the nearest second. The number of milliseconds of sleep actually
38633960
** requested from the operating system is returned.
38643961
**
38653962
** ^SQLite implements this interface by calling the xSleep()
3866
-** method of the default [sqlite3_vfs] object.
3963
+** method of the default [sqlite3_vfs] object. If the xSleep() method
3964
+** of the default VFS is not implemented correctly, or not implemented at
3965
+** all, then the behavior of sqlite3_sleep() may deviate from the description
3966
+** in the previous paragraphs.
38673967
*/
38683968
SQLITE_API int sqlite3_sleep(int);
38693969
38703970
/*
38713971
** CAPI3REF: Name Of The Folder Holding Temporary Files
@@ -4083,44 +4183,77 @@
40834183
** of heap memory by deallocating non-essential memory allocations
40844184
** held by the database library. Memory used to cache database
40854185
** pages to improve performance is an example of non-essential memory.
40864186
** ^sqlite3_release_memory() returns the number of bytes actually freed,
40874187
** which might be more or less than the amount requested.
4188
+** ^The sqlite3_release_memory() routine is a no-op returning zero
4189
+** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
40884190
*/
40894191
SQLITE_API int sqlite3_release_memory(int);
40904192
40914193
/*
40924194
** CAPI3REF: Impose A Limit On Heap Size
40934195
**
4094
-** ^The sqlite3_soft_heap_limit() interface places a "soft" limit
4095
-** on the amount of heap memory that may be allocated by SQLite.
4096
-** ^If an internal allocation is requested that would exceed the
4097
-** soft heap limit, [sqlite3_release_memory()] is invoked one or
4098
-** more times to free up some space before the allocation is performed.
4099
-**
4100
-** ^The limit is called "soft" because if [sqlite3_release_memory()]
4101
-** cannot free sufficient memory to prevent the limit from being exceeded,
4102
-** the memory is allocated anyway and the current operation proceeds.
4103
-**
4104
-** ^A negative or zero value for N means that there is no soft heap limit and
4105
-** [sqlite3_release_memory()] will only be called when memory is exhausted.
4106
-** ^The default value for the soft heap limit is zero.
4107
-**
4108
-** ^(SQLite makes a best effort to honor the soft heap limit.
4109
-** But if the soft heap limit cannot be honored, execution will
4110
-** continue without error or notification.)^ This is why the limit is
4111
-** called a "soft" limit. It is advisory only.
4112
-**
4113
-** Prior to SQLite version 3.5.0, this routine only constrained the memory
4114
-** allocated by a single thread - the same thread in which this routine
4115
-** runs. Beginning with SQLite version 3.5.0, the soft heap limit is
4116
-** applied to all threads. The value specified for the soft heap limit
4117
-** is an upper bound on the total memory allocation for all threads. In
4118
-** version 3.5.0 there is no mechanism for limiting the heap usage for
4119
-** individual threads.
4196
+** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
4197
+** soft limit on the amount of heap memory that may be allocated by SQLite.
4198
+** ^SQLite strives to keep heap memory utilization below the soft heap
4199
+** limit by reducing the number of pages held in the page cache
4200
+** as heap memory usages approaches the limit.
4201
+** ^The soft heap limit is "soft" because even though SQLite strives to stay
4202
+** below the limit, it will exceed the limit rather than generate
4203
+** an [SQLITE_NOMEM] error. In other words, the soft heap limit
4204
+** is advisory only.
4205
+**
4206
+** ^The return value from sqlite3_soft_heap_limit64() is the size of
4207
+** the soft heap limit prior to the call. ^If the argument N is negative
4208
+** then no change is made to the soft heap limit. Hence, the current
4209
+** size of the soft heap limit can be determined by invoking
4210
+** sqlite3_soft_heap_limit64() with a negative argument.
4211
+**
4212
+** ^If the argument N is zero then the soft heap limit is disabled.
4213
+**
4214
+** ^(The soft heap limit is not enforced in the current implementation
4215
+** if one or more of following conditions are true:
4216
+**
4217
+** <ul>
4218
+** <li> The soft heap limit is set to zero.
4219
+** <li> Memory accounting is disabled using a combination of the
4220
+** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
4221
+** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
4222
+** <li> An alternative page cache implementation is specifed using
4223
+** [sqlite3_config]([SQLITE_CONFIG_PCACHE],...).
4224
+** <li> The page cache allocates from its own memory pool supplied
4225
+** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
4226
+** from the heap.
4227
+** </ul>)^
4228
+**
4229
+** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
4230
+** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
4231
+** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
4232
+** the soft heap limit is enforced on every memory allocation. Without
4233
+** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
4234
+** when memory is allocated by the page cache. Testing suggests that because
4235
+** the page cache is the predominate memory user in SQLite, most
4236
+** applications will achieve adequate soft heap limit enforcement without
4237
+** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
4238
+**
4239
+** The circumstances under which SQLite will enforce the soft heap limit may
4240
+** changes in future releases of SQLite.
4241
+*/
4242
+SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
4243
+
4244
+/*
4245
+** CAPI3REF: Deprecated Soft Heap Limit Interface
4246
+** DEPRECATED
4247
+**
4248
+** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
4249
+** interface. This routine is provided for historical compatibility
4250
+** only. All new applications should use the
4251
+** [sqlite3_soft_heap_limit64()] interface rather than this one.
41204252
*/
4121
-SQLITE_API void sqlite3_soft_heap_limit(int);
4253
+SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);
4254
+
41224255
41234256
/*
41244257
** CAPI3REF: Extract Metadata About A Column Of A Table
41254258
**
41264259
** ^This routine returns metadata about a specific column of a specific
@@ -4240,38 +4373,51 @@
42404373
** it back off again.
42414374
*/
42424375
SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
42434376
42444377
/*
4245
-** CAPI3REF: Automatically Load An Extensions
4246
-**
4247
-** ^This API can be invoked at program startup in order to register
4248
-** one or more statically linked extensions that will be available
4249
-** to all new [database connections].
4250
-**
4251
-** ^(This routine stores a pointer to the extension entry point
4252
-** in an array that is obtained from [sqlite3_malloc()]. That memory
4253
-** is deallocated by [sqlite3_reset_auto_extension()].)^
4254
-**
4255
-** ^This function registers an extension entry point that is
4256
-** automatically invoked whenever a new [database connection]
4257
-** is opened using [sqlite3_open()], [sqlite3_open16()],
4258
-** or [sqlite3_open_v2()].
4259
-** ^Duplicate extensions are detected so calling this routine
4260
-** multiple times with the same extension is harmless.
4261
-** ^Automatic extensions apply across all threads.
4378
+** CAPI3REF: Automatically Load Statically Linked Extensions
4379
+**
4380
+** ^This interface causes the xEntryPoint() function to be invoked for
4381
+** each new [database connection] that is created. The idea here is that
4382
+** xEntryPoint() is the entry point for a statically linked SQLite extension
4383
+** that is to be automatically loaded into all new database connections.
4384
+**
4385
+** ^(Even though the function prototype shows that xEntryPoint() takes
4386
+** no arguments and returns void, SQLite invokes xEntryPoint() with three
4387
+** arguments and expects and integer result as if the signature of the
4388
+** entry point where as follows:
4389
+**
4390
+** <blockquote><pre>
4391
+** &nbsp; int xEntryPoint(
4392
+** &nbsp; sqlite3 *db,
4393
+** &nbsp; const char **pzErrMsg,
4394
+** &nbsp; const struct sqlite3_api_routines *pThunk
4395
+** &nbsp; );
4396
+** </pre></blockquote>)^
4397
+**
4398
+** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
4399
+** point to an appropriate error message (obtained from [sqlite3_mprintf()])
4400
+** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg
4401
+** is NULL before calling the xEntryPoint(). ^SQLite will invoke
4402
+** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any
4403
+** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
4404
+** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
4405
+**
4406
+** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
4407
+** on the list of automatic extensions is a harmless no-op. ^No entry point
4408
+** will be called more than once for each database connection that is opened.
4409
+**
4410
+** See also: [sqlite3_reset_auto_extension()].
42624411
*/
42634412
SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
42644413
42654414
/*
42664415
** CAPI3REF: Reset Automatic Extension Loading
42674416
**
4268
-** ^(This function disables all previously registered automatic
4269
-** extensions. It undoes the effect of all prior
4270
-** [sqlite3_auto_extension()] calls.)^
4271
-**
4272
-** ^This function disables automatic extensions in all threads.
4417
+** ^This interface disables all automatic extensions previously
4418
+** registered using [sqlite3_auto_extension()].
42734419
*/
42744420
SQLITE_API void sqlite3_reset_auto_extension(void);
42754421
42764422
/*
42774423
** The interface to the virtual-table mechanism is currently considered
@@ -4906,11 +5052,11 @@
49065052
** output variable when querying the system for the current mutex
49075053
** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
49085054
**
49095055
** ^The xMutexInit method defined by this structure is invoked as
49105056
** part of system initialization by the sqlite3_initialize() function.
4911
-** ^The xMutexInit routine is calle by SQLite exactly once for each
5057
+** ^The xMutexInit routine is called by SQLite exactly once for each
49125058
** effective call to [sqlite3_initialize()].
49135059
**
49145060
** ^The xMutexEnd method defined by this structure is invoked as
49155061
** part of system shutdown by the sqlite3_shutdown() function. The
49165062
** implementation of this method is expected to release all outstanding
@@ -5103,11 +5249,12 @@
51035249
#define SQLITE_TESTCTRL_ALWAYS 13
51045250
#define SQLITE_TESTCTRL_RESERVE 14
51055251
#define SQLITE_TESTCTRL_OPTIMIZATIONS 15
51065252
#define SQLITE_TESTCTRL_ISKEYWORD 16
51075253
#define SQLITE_TESTCTRL_PGHDRSZ 17
5108
-#define SQLITE_TESTCTRL_LAST 17
5254
+#define SQLITE_TESTCTRL_SCRATCHMALLOC 18
5255
+#define SQLITE_TESTCTRL_LAST 18
51095256
51105257
/*
51115258
** CAPI3REF: SQLite Runtime Status
51125259
**
51135260
** ^This interface is used to retrieve runtime status information
@@ -5122,11 +5269,11 @@
51225269
** value. For those parameters
51235270
** nothing is written into *pHighwater and the resetFlag is ignored.)^
51245271
** ^(Other parameters record only the highwater mark and not the current
51255272
** value. For these latter parameters nothing is written into *pCurrent.)^
51265273
**
5127
-** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
5274
+** ^The sqlite3_status() routine returns SQLITE_OK on success and a
51285275
** non-zero [error code] on failure.
51295276
**
51305277
** This routine is threadsafe but is not atomic. This routine can be
51315278
** called while other threads are running the same or different SQLite
51325279
** interfaces. However the values returned in *pCurrent and
@@ -5172,11 +5319,11 @@
51725319
** [SQLITE_CONFIG_PAGECACHE]. The
51735320
** value returned is in pages, not in bytes.</dd>)^
51745321
**
51755322
** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
51765323
** <dd>This parameter returns the number of bytes of page cache
5177
-** allocation which could not be statisfied by the [SQLITE_CONFIG_PAGECACHE]
5324
+** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
51785325
** buffer and where forced to overflow to [sqlite3_malloc()]. The
51795326
** returned value includes allocations that overflowed because they
51805327
** where too large (they were larger than the "sz" parameter to
51815328
** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
51825329
** no space was left in the page cache.</dd>)^
@@ -5195,11 +5342,11 @@
51955342
** outstanding at time, this parameter also reports the number of threads
51965343
** using scratch memory at the same time.</dd>)^
51975344
**
51985345
** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
51995346
** <dd>This parameter returns the number of bytes of scratch memory
5200
-** allocation which could not be statisfied by the [SQLITE_CONFIG_SCRATCH]
5347
+** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
52015348
** buffer and where forced to overflow to [sqlite3_malloc()]. The values
52025349
** returned include overflows because the requested allocation was too
52035350
** larger (that is, because the requested allocation was larger than the
52045351
** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
52055352
** slots were available.
@@ -5243,10 +5390,13 @@
52435390
**
52445391
** ^The current value of the requested parameter is written into *pCur
52455392
** and the highest instantaneous value is written into *pHiwtr. ^If
52465393
** the resetFlg is true, then the highest instantaneous value is
52475394
** reset back down to the current value.
5395
+**
5396
+** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
5397
+** non-zero [error code] on failure.
52485398
**
52495399
** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
52505400
*/
52515401
SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
52525402
@@ -5370,122 +5520,134 @@
53705520
** CAPI3REF: Application Defined Page Cache.
53715521
** KEYWORDS: {page cache}
53725522
**
53735523
** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
53745524
** register an alternative page cache implementation by passing in an
5375
-** instance of the sqlite3_pcache_methods structure.)^ The majority of the
5376
-** heap memory used by SQLite is used by the page cache to cache data read
5377
-** from, or ready to be written to, the database file. By implementing a
5378
-** custom page cache using this API, an application can control more
5379
-** precisely the amount of memory consumed by SQLite, the way in which
5525
+** instance of the sqlite3_pcache_methods structure.)^
5526
+** In many applications, most of the heap memory allocated by
5527
+** SQLite is used for the page cache.
5528
+** By implementing a
5529
+** custom page cache using this API, an application can better control
5530
+** the amount of memory consumed by SQLite, the way in which
53805531
** that memory is allocated and released, and the policies used to
53815532
** determine exactly which parts of a database file are cached and for
53825533
** how long.
53835534
**
5535
+** The alternative page cache mechanism is an
5536
+** extreme measure that is only needed by the most demanding applications.
5537
+** The built-in page cache is recommended for most uses.
5538
+**
53845539
** ^(The contents of the sqlite3_pcache_methods structure are copied to an
53855540
** internal buffer by SQLite within the call to [sqlite3_config]. Hence
53865541
** the application may discard the parameter after the call to
53875542
** [sqlite3_config()] returns.)^
53885543
**
5389
-** ^The xInit() method is called once for each call to [sqlite3_initialize()]
5544
+** ^(The xInit() method is called once for each effective
5545
+** call to [sqlite3_initialize()])^
53905546
** (usually only once during the lifetime of the process). ^(The xInit()
53915547
** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
5392
-** ^The xInit() method can set up up global structures and/or any mutexes
5548
+** The intent of the xInit() method is to set up global data structures
53935549
** required by the custom page cache implementation.
5550
+** ^(If the xInit() method is NULL, then the
5551
+** built-in default page cache is used instead of the application defined
5552
+** page cache.)^
53945553
**
5395
-** ^The xShutdown() method is called from within [sqlite3_shutdown()],
5396
-** if the application invokes this API. It can be used to clean up
5554
+** ^The xShutdown() method is called by [sqlite3_shutdown()].
5555
+** It can be used to clean up
53975556
** any outstanding resources before process shutdown, if required.
5557
+** ^The xShutdown() method may be NULL.
53985558
**
5399
-** ^SQLite holds a [SQLITE_MUTEX_RECURSIVE] mutex when it invokes
5400
-** the xInit method, so the xInit method need not be threadsafe. ^The
5559
+** ^SQLite automatically serializes calls to the xInit method,
5560
+** so the xInit method need not be threadsafe. ^The
54015561
** xShutdown method is only called from [sqlite3_shutdown()] so it does
54025562
** not need to be threadsafe either. All other methods must be threadsafe
54035563
** in multithreaded applications.
54045564
**
54055565
** ^SQLite will never invoke xInit() more than once without an intervening
54065566
** call to xShutdown().
54075567
**
5408
-** ^The xCreate() method is used to construct a new cache instance. SQLite
5409
-** will typically create one cache instance for each open database file,
5568
+** ^SQLite invokes the xCreate() method to construct a new cache instance.
5569
+** SQLite will typically create one cache instance for each open database file,
54105570
** though this is not guaranteed. ^The
54115571
** first parameter, szPage, is the size in bytes of the pages that must
54125572
** be allocated by the cache. ^szPage will not be a power of two. ^szPage
54135573
** will the page size of the database file that is to be cached plus an
5414
-** increment (here called "R") of about 100 or 200. ^SQLite will use the
5574
+** increment (here called "R") of about 100 or 200. SQLite will use the
54155575
** extra R bytes on each page to store metadata about the underlying
54165576
** database page on disk. The value of R depends
54175577
** on the SQLite version, the target platform, and how SQLite was compiled.
54185578
** ^R is constant for a particular build of SQLite. ^The second argument to
54195579
** xCreate(), bPurgeable, is true if the cache being created will
54205580
** be used to cache database pages of a file stored on disk, or
5421
-** false if it is used for an in-memory database. ^The cache implementation
5581
+** false if it is used for an in-memory database. The cache implementation
54225582
** does not have to do anything special based with the value of bPurgeable;
54235583
** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
54245584
** never invoke xUnpin() except to deliberately delete a page.
5425
-** ^In other words, a cache created with bPurgeable set to false will
5585
+** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
5586
+** false will always have the "discard" flag set to true.
5587
+** ^Hence, a cache created with bPurgeable false will
54265588
** never contain any unpinned pages.
54275589
**
54285590
** ^(The xCachesize() method may be called at any time by SQLite to set the
54295591
** suggested maximum cache-size (number of pages stored by) the cache
54305592
** instance passed as the first argument. This is the value configured using
5431
-** the SQLite "[PRAGMA cache_size]" command.)^ ^As with the bPurgeable
5593
+** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
54325594
** parameter, the implementation is not required to do anything with this
54335595
** value; it is advisory only.
54345596
**
5435
-** ^The xPagecount() method should return the number of pages currently
5436
-** stored in the cache.
5597
+** The xPagecount() method must return the number of pages currently
5598
+** stored in the cache, both pinned and unpinned.
54375599
**
5438
-** ^The xFetch() method is used to fetch a page and return a pointer to it.
5439
-** ^A 'page', in this context, is a buffer of szPage bytes aligned at an
5440
-** 8-byte boundary. ^The page to be fetched is determined by the key. ^The
5441
-** mimimum key value is 1. After it has been retrieved using xFetch, the page
5600
+** The xFetch() method locates a page in the cache and returns a pointer to
5601
+** the page, or a NULL pointer.
5602
+** A "page", in this context, means a buffer of szPage bytes aligned at an
5603
+** 8-byte boundary. The page to be fetched is determined by the key. ^The
5604
+** mimimum key value is 1. After it has been retrieved using xFetch, the page
54425605
** is considered to be "pinned".
54435606
**
5444
-** ^If the requested page is already in the page cache, then the page cache
5607
+** If the requested page is already in the page cache, then the page cache
54455608
** implementation must return a pointer to the page buffer with its content
5446
-** intact. ^(If the requested page is not already in the cache, then the
5447
-** behavior of the cache implementation is determined by the value of the
5448
-** createFlag parameter passed to xFetch, according to the following table:
5609
+** intact. If the requested page is not already in the cache, then the
5610
+** behavior of the cache implementation should use the value of the createFlag
5611
+** parameter to help it determined what action to take:
54495612
**
54505613
** <table border=1 width=85% align=center>
54515614
** <tr><th> createFlag <th> Behaviour when page is not already in cache
54525615
** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
54535616
** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
54545617
** Otherwise return NULL.
54555618
** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
54565619
** NULL if allocating a new page is effectively impossible.
5457
-** </table>)^
5620
+** </table>
54585621
**
5459
-** SQLite will normally invoke xFetch() with a createFlag of 0 or 1. If
5460
-** a call to xFetch() with createFlag==1 returns NULL, then SQLite will
5622
+** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
5623
+** will only use a createFlag of 2 after a prior call with a createFlag of 1
5624
+** failed.)^ In between the to xFetch() calls, SQLite may
54615625
** attempt to unpin one or more cache pages by spilling the content of
5462
-** pinned pages to disk and synching the operating system disk cache. After
5463
-** attempting to unpin pages, the xFetch() method will be invoked again with
5464
-** a createFlag of 2.
5626
+** pinned pages to disk and synching the operating system disk cache.
54655627
**
54665628
** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
5467
-** as its second argument. ^(If the third parameter, discard, is non-zero,
5468
-** then the page should be evicted from the cache. In this case SQLite
5469
-** assumes that the next time the page is retrieved from the cache using
5470
-** the xFetch() method, it will be zeroed.)^ ^If the discard parameter is
5471
-** zero, then the page is considered to be unpinned. ^The cache implementation
5629
+** as its second argument. If the third parameter, discard, is non-zero,
5630
+** then the page must be evicted from the cache.
5631
+** ^If the discard parameter is
5632
+** zero, then the page may be discarded or retained at the discretion of
5633
+** page cache implementation. ^The page cache implementation
54725634
** may choose to evict unpinned pages at any time.
54735635
**
5474
-** ^(The cache is not required to perform any reference counting. A single
5636
+** The cache must not perform any reference counting. A single
54755637
** call to xUnpin() unpins the page regardless of the number of prior calls
5476
-** to xFetch().)^
5638
+** to xFetch().
54775639
**
5478
-** ^The xRekey() method is used to change the key value associated with the
5479
-** page passed as the second argument from oldKey to newKey. ^If the cache
5480
-** previously contains an entry associated with newKey, it should be
5640
+** The xRekey() method is used to change the key value associated with the
5641
+** page passed as the second argument. If the cache
5642
+** previously contains an entry associated with newKey, it must be
54815643
** discarded. ^Any prior cache entry associated with newKey is guaranteed not
54825644
** to be pinned.
54835645
**
5484
-** ^When SQLite calls the xTruncate() method, the cache must discard all
5646
+** When SQLite calls the xTruncate() method, the cache must discard all
54855647
** existing cache entries with page numbers (keys) greater than or equal
5486
-** to the value of the iLimit parameter passed to xTruncate(). ^If any
5648
+** to the value of the iLimit parameter passed to xTruncate(). If any
54875649
** of these pages are pinned, they are implicitly unpinned, meaning that
54885650
** they can be safely discarded.
54895651
**
54905652
** ^The xDestroy() method is used to delete a cache allocated by xCreate().
54915653
** All resources associated with the specified cache should be freed. ^After
@@ -5959,5 +6121,61 @@
59596121
#ifdef __cplusplus
59606122
} /* End of the 'extern "C"' block */
59616123
#endif
59626124
#endif
59636125
6126
+/*
6127
+** 2010 August 30
6128
+**
6129
+** The author disclaims copyright to this source code. In place of
6130
+** a legal notice, here is a blessing:
6131
+**
6132
+** May you do good and not evil.
6133
+** May you find forgiveness for yourself and forgive others.
6134
+** May you share freely, never taking more than you give.
6135
+**
6136
+*************************************************************************
6137
+*/
6138
+
6139
+#ifndef _SQLITE3RTREE_H_
6140
+#define _SQLITE3RTREE_H_
6141
+
6142
+
6143
+#ifdef __cplusplus
6144
+extern "C" {
6145
+#endif
6146
+
6147
+typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
6148
+
6149
+/*
6150
+** Register a geometry callback named zGeom that can be used as part of an
6151
+** R-Tree geometry query as follows:
6152
+**
6153
+** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
6154
+*/
6155
+SQLITE_API int sqlite3_rtree_geometry_callback(
6156
+ sqlite3 *db,
6157
+ const char *zGeom,
6158
+ int (*xGeom)(sqlite3_rtree_geometry *, int nCoord, double *aCoord, int *pRes),
6159
+ void *pContext
6160
+);
6161
+
6162
+
6163
+/*
6164
+** A pointer to a structure of the following type is passed as the first
6165
+** argument to callbacks registered using rtree_geometry_callback().
6166
+*/
6167
+struct sqlite3_rtree_geometry {
6168
+ void *pContext; /* Copy of pContext passed to s_r_g_c() */
6169
+ int nParam; /* Size of array aParam[] */
6170
+ double *aParam; /* Parameters passed to SQL geom function */
6171
+ void *pUser; /* Callback implementation user data */
6172
+ void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */
6173
+};
6174
+
6175
+
6176
+#ifdef __cplusplus
6177
+} /* end of the 'extern "C"' block */
6178
+#endif
6179
+
6180
+#endif /* ifndef _SQLITE3RTREE_H_ */
6181
+
59646182
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.2"
111 #define SQLITE_VERSION_NUMBER 3007002
112 #define SQLITE_SOURCE_ID "2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -755,19 +755,23 @@
755 ** object once the object has been registered.
756 **
757 ** The zName field holds the name of the VFS module. The name must
758 ** be unique across all VFS modules.
759 **
760 ** SQLite will guarantee that the zFilename parameter to xOpen
761 ** is either a NULL pointer or string obtained
762 ** from xFullPathname(). SQLite further guarantees that
 
 
 
 
763 ** the string will be valid and unchanged until xClose() is
764 ** called. Because of the previous sentence,
765 ** the [sqlite3_file] can safely store a pointer to the
766 ** filename if it needs to remember the filename for some reason.
767 ** If the zFilename parameter is xOpen is a NULL pointer then xOpen
768 ** must invent its own temporary name for the file. Whenever the
769 ** xFilename parameter is NULL it will also be the case that the
770 ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
771 **
772 ** The flags argument to xOpen() includes all bits set in
773 ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
@@ -774,11 +778,11 @@
774 ** or [sqlite3_open16()] is used, then flags includes at least
775 ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
776 ** If xOpen() opens a file read-only then it sets *pOutFlags to
777 ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
778 **
779 ** SQLite will also add one of the following flags to the xOpen()
780 ** call, depending on the object being opened:
781 **
782 ** <ul>
783 ** <li> [SQLITE_OPEN_MAIN_DB]
784 ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
@@ -785,11 +789,12 @@
785 ** <li> [SQLITE_OPEN_TEMP_DB]
786 ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
787 ** <li> [SQLITE_OPEN_TRANSIENT_DB]
788 ** <li> [SQLITE_OPEN_SUBJOURNAL]
789 ** <li> [SQLITE_OPEN_MASTER_JOURNAL]
790 ** </ul>
 
791 **
792 ** The file I/O implementation can use the object type flags to
793 ** change the way it deals with files. For example, an application
794 ** that does not care about crash recovery or rollback might make
795 ** the open of a journal file a no-op. Writes to this journal would
@@ -804,39 +809,40 @@
804 ** <li> [SQLITE_OPEN_DELETEONCLOSE]
805 ** <li> [SQLITE_OPEN_EXCLUSIVE]
806 ** </ul>
807 **
808 ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
809 ** deleted when it is closed. The [SQLITE_OPEN_DELETEONCLOSE]
810 ** will be set for TEMP databases, journals and for subjournals.
 
811 **
812 ** The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
813 ** with the [SQLITE_OPEN_CREATE] flag, which are both directly
814 ** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
815 ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
816 ** SQLITE_OPEN_CREATE, is used to indicate that file should always
817 ** be created, and that it is an error if it already exists.
818 ** It is <i>not</i> used to indicate the file should be opened
819 ** for exclusive access.
820 **
821 ** At least szOsFile bytes of memory are allocated by SQLite
822 ** to hold the [sqlite3_file] structure passed as the third
823 ** argument to xOpen. The xOpen method does not have to
824 ** allocate the structure; it should just fill it in. Note that
825 ** the xOpen method must set the sqlite3_file.pMethods to either
826 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
827 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
828 ** element will be valid after xOpen returns regardless of the success
829 ** or failure of the xOpen call.
830 **
831 ** The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
832 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
833 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
834 ** to test whether a file is at least readable. The file can be a
835 ** directory.
836 **
837 ** SQLite will always allocate at least mxPathname+1 bytes for the
838 ** output buffer xFullPathname. The exact size of the output buffer
839 ** is also passed as a parameter to both methods. If the output buffer
840 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
841 ** handled as a fatal error by SQLite, vfs implementations should endeavor
842 ** to prevent this by setting mxPathname to a sufficiently large value.
@@ -846,14 +852,14 @@
846 ** included in the VFS structure for completeness.
847 ** The xRandomness() function attempts to return nBytes bytes
848 ** of good-quality randomness into zOut. The return value is
849 ** the actual number of bytes of randomness obtained.
850 ** The xSleep() method causes the calling thread to sleep for at
851 ** least the number of microseconds given. The xCurrentTime()
852 ** method returns a Julian Day Number for the current date and time as
853 ** a floating point value.
854 ** The xCurrentTimeInt64() method returns, as an integer, the Julian
855 ** Day Number multipled by 86400000 (the number of milliseconds in
856 ** a 24-hour day).
857 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
858 ** date and time if that method is available (if iVersion is 2 or
859 ** greater and the function pointer is not NULL) and will fall back
@@ -1246,11 +1252,11 @@
1246 ** statistics. ^(When memory allocation statistics are disabled, the
1247 ** following SQLite interfaces become non-operational:
1248 ** <ul>
1249 ** <li> [sqlite3_memory_used()]
1250 ** <li> [sqlite3_memory_highwater()]
1251 ** <li> [sqlite3_soft_heap_limit()]
1252 ** <li> [sqlite3_status()]
1253 ** </ul>)^
1254 ** ^Memory allocation statistics are enabled by default unless SQLite is
1255 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1256 ** allocation statistics are disabled by default.
@@ -1260,19 +1266,18 @@
1260 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1261 ** scratch memory. There are three arguments: A pointer an 8-byte
1262 ** aligned memory buffer from which the scrach allocations will be
1263 ** drawn, the size of each scratch allocation (sz),
1264 ** and the maximum number of scratch allocations (N). The sz
1265 ** argument must be a multiple of 16. The sz parameter should be a few bytes
1266 ** larger than the actual scratch space required due to internal overhead.
1267 ** The first argument must be a pointer to an 8-byte aligned buffer
1268 ** of at least sz*N bytes of memory.
1269 ** ^SQLite will use no more than one scratch buffer per thread. So
1270 ** N should be set to the expected maximum number of threads. ^SQLite will
1271 ** never require a scratch buffer that is more than 6 times the database
1272 ** page size. ^If SQLite needs needs additional scratch memory beyond
1273 ** what is provided by this configuration option, then
1274 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
1275 **
1276 ** <dt>SQLITE_CONFIG_PAGECACHE</dt>
1277 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1278 ** the database page cache with the default page cache implemenation.
@@ -1288,12 +1293,11 @@
1288 ** argument should point to an allocation of at least sz*N bytes of memory.
1289 ** ^SQLite will use the memory provided by the first argument to satisfy its
1290 ** memory needs for the first N pages that it adds to cache. ^If additional
1291 ** page cache memory is needed beyond what is provided by this option, then
1292 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1293 ** ^The implementation might use one or more of the N buffers to hold
1294 ** memory accounting information. The pointer in the first argument must
1295 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1296 ** will be undefined.</dd>
1297 **
1298 ** <dt>SQLITE_CONFIG_HEAP</dt>
1299 ** <dd> ^This option specifies a static memory buffer that SQLite will use
@@ -1418,12 +1422,18 @@
1418 ** size of each lookaside buffer slot. ^The third argument is the number of
1419 ** slots. The size of the buffer in the first argument must be greater than
1420 ** or equal to the product of the second and third arguments. The buffer
1421 ** must be aligned to an 8-byte boundary. ^If the second argument to
1422 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
1423 ** rounded down to the next smaller
1424 ** multiple of 8. See also: [SQLITE_CONFIG_LOOKASIDE]</dd>
 
 
 
 
 
 
1425 **
1426 ** </dl>
1427 */
1428 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1429
@@ -1723,10 +1733,13 @@
1723 */
1724 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
1725
1726 /*
1727 ** CAPI3REF: Convenience Routines For Running Queries
 
 
 
1728 **
1729 ** Definition: A <b>result table</b> is memory data structure created by the
1730 ** [sqlite3_get_table()] interface. A result table records the
1731 ** complete query results from one or more queries.
1732 **
@@ -1744,11 +1757,11 @@
1744 **
1745 ** A result table might consist of one or more memory allocations.
1746 ** It is not safe to pass a result table directly to [sqlite3_free()].
1747 ** A result table should be deallocated using [sqlite3_free_table()].
1748 **
1749 ** As an example of the result table format, suppose a query result
1750 ** is as follows:
1751 **
1752 ** <blockquote><pre>
1753 ** Name | Age
1754 ** -----------------------
@@ -1768,31 +1781,31 @@
1768 ** azResult&#91;3] = "43";
1769 ** azResult&#91;4] = "Bob";
1770 ** azResult&#91;5] = "28";
1771 ** azResult&#91;6] = "Cindy";
1772 ** azResult&#91;7] = "21";
1773 ** </pre></blockquote>
1774 **
1775 ** ^The sqlite3_get_table() function evaluates one or more
1776 ** semicolon-separated SQL statements in the zero-terminated UTF-8
1777 ** string of its 2nd parameter and returns a result table to the
1778 ** pointer given in its 3rd parameter.
1779 **
1780 ** After the application has finished with the result from sqlite3_get_table(),
1781 ** it should pass the result table pointer to sqlite3_free_table() in order to
1782 ** release the memory that was malloced. Because of the way the
1783 ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
1784 ** function must not try to call [sqlite3_free()] directly. Only
1785 ** [sqlite3_free_table()] is able to release the memory properly and safely.
1786 **
1787 ** ^(The sqlite3_get_table() interface is implemented as a wrapper around
1788 ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
1789 ** to any internal data structures of SQLite. It uses only the public
1790 ** interface defined here. As a consequence, errors that occur in the
1791 ** wrapper layer outside of the internal [sqlite3_exec()] call are not
1792 ** reflected in subsequent calls to [sqlite3_errcode()] or
1793 ** [sqlite3_errmsg()].)^
1794 */
1795 SQLITE_API int sqlite3_get_table(
1796 sqlite3 *db, /* An open database */
1797 const char *zSql, /* SQL to be evaluated */
1798 char ***pazResult, /* Results of the query */
@@ -1940,11 +1953,13 @@
1940 ** by sqlite3_realloc() and the prior allocation is freed.
1941 ** ^If sqlite3_realloc() returns NULL, then the prior allocation
1942 ** is not freed.
1943 **
1944 ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
1945 ** is always aligned to at least an 8 byte boundary.
 
 
1946 **
1947 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
1948 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
1949 ** implementation of these routines to be omitted. That capability
1950 ** is no longer provided. Only built-in memory allocators can be used.
@@ -2198,21 +2213,32 @@
2198 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2199
2200 /*
2201 ** CAPI3REF: Query Progress Callbacks
2202 **
2203 ** ^This routine configures a callback function - the
2204 ** progress callback - that is invoked periodically during long
2205 ** running calls to [sqlite3_exec()], [sqlite3_step()] and
2206 ** [sqlite3_get_table()]. An example use for this
2207 ** interface is to keep a GUI updated during a large query.
 
 
 
 
 
 
 
 
 
 
 
2208 **
2209 ** ^If the progress callback returns non-zero, the operation is
2210 ** interrupted. This feature can be used to implement a
2211 ** "Cancel" button on a GUI progress dialog box.
2212 **
2213 ** The progress handler must not do anything that will modify
2214 ** the database connection that invoked the progress handler.
2215 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
2216 ** database connections for the meaning of "modify" in this paragraph.
2217 **
2218 */
@@ -2267,11 +2293,11 @@
2267 ** </dl>
2268 **
2269 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
2270 ** combinations shown above or one of the combinations shown above combined
2271 ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
2272 ** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_SHAREDCACHE] flags,
2273 ** then the behavior is undefined.
2274 **
2275 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
2276 ** opens in the multi-thread [threading mode] as long as the single-thread
2277 ** mode has not been set at compile-time or start-time. ^If the
@@ -2392,21 +2418,26 @@
2392 ** ^(This interface allows the size of various constructs to be limited
2393 ** on a connection by connection basis. The first parameter is the
2394 ** [database connection] whose limit is to be set or queried. The
2395 ** second parameter is one of the [limit categories] that define a
2396 ** class of constructs to be size limited. The third parameter is the
2397 ** new limit for that construct. The function returns the old limit.)^
2398 **
2399 ** ^If the new limit is a negative number, the limit is unchanged.
2400 ** ^(For the limit category of SQLITE_LIMIT_XYZ there is a
2401 ** [limits | hard upper bound]
2402 ** set by a compile-time C preprocessor macro named
2403 ** [limits | SQLITE_MAX_XYZ].
2404 ** (The "_LIMIT_" in the name is changed to "_MAX_".))^
2405 ** ^Attempts to increase a limit above its hard upper bound are
2406 ** silently truncated to the hard upper bound.
2407 **
 
 
 
 
 
2408 ** Run-time limits are intended for use in applications that manage
2409 ** both their own internal database and also databases that are controlled
2410 ** by untrusted external sources. An example application might be a
2411 ** web browser that has its own databases for storing history and
2412 ** separate databases controlled by JavaScript applications downloaded
@@ -2431,11 +2462,11 @@
2431 ** The synopsis of the meanings of the various limits is shown below.
2432 ** Additional information is available at [limits | Limits in SQLite].
2433 **
2434 ** <dl>
2435 ** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
2436 ** <dd>The maximum size of any string or BLOB or table row.<dd>)^
2437 **
2438 ** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
2439 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
2440 **
2441 ** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
@@ -2449,11 +2480,13 @@
2449 ** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
2450 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
2451 **
2452 ** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
2453 ** <dd>The maximum number of instructions in a virtual machine program
2454 ** used to implement an SQL statement.</dd>)^
 
 
2455 **
2456 ** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
2457 ** <dd>The maximum number of arguments on a function.</dd>)^
2458 **
2459 ** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
@@ -2462,12 +2495,11 @@
2462 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
2463 ** <dd>The maximum length of the pattern argument to the [LIKE] or
2464 ** [GLOB] operators.</dd>)^
2465 **
2466 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
2467 ** <dd>The maximum number of variables in an SQL statement that can
2468 ** be bound.</dd>)^
2469 **
2470 ** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
2471 ** <dd>The maximum depth of recursion for triggers.</dd>)^
2472 ** </dl>
2473 */
@@ -2535,16 +2567,11 @@
2535 **
2536 ** <ol>
2537 ** <li>
2538 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
2539 ** always used to do, [sqlite3_step()] will automatically recompile the SQL
2540 ** statement and try to run it again. ^If the schema has changed in
2541 ** a way that makes the statement no longer valid, [sqlite3_step()] will still
2542 ** return [SQLITE_SCHEMA]. But unlike the legacy behavior, [SQLITE_SCHEMA] is
2543 ** now a fatal error. Calling [sqlite3_prepare_v2()] again will not make the
2544 ** error go away. Note: use [sqlite3_errmsg()] to find the text
2545 ** of the parsing error that results in an [SQLITE_SCHEMA] return.
2546 ** </li>
2547 **
2548 ** <li>
2549 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
2550 ** [error codes] or [extended error codes]. ^The legacy behavior was that
@@ -2553,15 +2580,20 @@
2553 ** in order to find the underlying cause of the problem. With the "v2" prepare
2554 ** interfaces, the underlying reason for the error is returned immediately.
2555 ** </li>
2556 **
2557 ** <li>
2558 ** ^If the value of a [parameter | host parameter] in the WHERE clause might
2559 ** change the query plan for a statement, then the statement may be
2560 ** automatically recompiled (as if there had been a schema change) on the first
2561 ** [sqlite3_step()] call following any change to the
2562 ** [sqlite3_bind_text | bindings] of the [parameter].
 
 
 
 
 
2563 ** </li>
2564 ** </ol>
2565 */
2566 SQLITE_API int sqlite3_prepare(
2567 sqlite3 *db, /* Database handle */
@@ -2624,11 +2656,11 @@
2624 ** or if SQLite is run in one of reduced mutex modes
2625 ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
2626 ** then there is no distinction between protected and unprotected
2627 ** sqlite3_value objects and they can be used interchangeably. However,
2628 ** for maximum code portability it is recommended that applications
2629 ** still make the distinction between between protected and unprotected
2630 ** sqlite3_value objects even when not strictly required.
2631 **
2632 ** ^The sqlite3_value objects that are passed as parameters into the
2633 ** implementation of [application-defined SQL functions] are protected.
2634 ** ^The sqlite3_value object returned by
@@ -2819,10 +2851,12 @@
2819 ** CAPI3REF: Number Of Columns In A Result Set
2820 **
2821 ** ^Return the number of columns in the result set returned by the
2822 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
2823 ** statement that does not return data (for example an [UPDATE]).
 
 
2824 */
2825 SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
2826
2827 /*
2828 ** CAPI3REF: Column Names In A Result Set
@@ -3009,12 +3043,18 @@
3009 SQLITE_API int sqlite3_step(sqlite3_stmt*);
3010
3011 /*
3012 ** CAPI3REF: Number of columns in a result set
3013 **
3014 ** ^The sqlite3_data_count(P) the number of columns in the
3015 ** of the result set of [prepared statement] P.
 
 
 
 
 
 
3016 */
3017 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
3018
3019 /*
3020 ** CAPI3REF: Fundamental Datatypes
@@ -3090,22 +3130,30 @@
3090 ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
3091 ** the string to UTF-8 and then returns the number of bytes.
3092 ** ^If the result is a numeric value then sqlite3_column_bytes() uses
3093 ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
3094 ** the number of bytes in that string.
3095 ** ^The value returned does not include the zero terminator at the end
3096 ** of the string. ^For clarity: the value returned is the number of
 
 
 
 
 
 
 
 
 
 
 
 
 
3097 ** bytes in the string, not the number of characters.
3098 **
3099 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
3100 ** even empty strings, are always zero terminated. ^The return
3101 ** value from sqlite3_column_blob() for a zero-length BLOB is an arbitrary
3102 ** pointer, possibly even a NULL pointer.
3103 **
3104 ** ^The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
3105 ** but leaves the result in UTF-16 in native byte order instead of UTF-8.
3106 ** ^The zero terminator is not included in this count.
3107 **
3108 ** ^The object returned by [sqlite3_column_value()] is an
3109 ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object
3110 ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
3111 ** If the [unprotected sqlite3_value] object returned by
@@ -3146,14 +3194,14 @@
3146 ** and atof(). SQLite does not really use these functions. It has its
3147 ** own equivalent internal routines. The atoi() and atof() names are
3148 ** used in the table for brevity and because they are familiar to most
3149 ** C programmers.
3150 **
3151 ** ^Note that when type conversions occur, pointers returned by prior
3152 ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
3153 ** sqlite3_column_text16() may be invalidated.
3154 ** ^(Type conversions and pointer invalidations might occur
3155 ** in the following cases:
3156 **
3157 ** <ul>
3158 ** <li> The initial content is a BLOB and sqlite3_column_text() or
3159 ** sqlite3_column_text16() is called. A zero-terminator might
@@ -3162,26 +3210,26 @@
3162 ** sqlite3_column_text16() is called. The content must be converted
3163 ** to UTF-16.</li>
3164 ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
3165 ** sqlite3_column_text() is called. The content must be converted
3166 ** to UTF-8.</li>
3167 ** </ul>)^
3168 **
3169 ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
3170 ** not invalidate a prior pointer, though of course the content of the buffer
3171 ** that the prior pointer points to will have been modified. Other kinds
3172 ** of conversion are done in place when it is possible, but sometimes they
3173 ** are not possible and in those cases prior pointers are invalidated.
3174 **
3175 ** ^(The safest and easiest to remember policy is to invoke these routines
3176 ** in one of the following ways:
3177 **
3178 ** <ul>
3179 ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
3180 ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
3181 ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
3182 ** </ul>)^
3183 **
3184 ** In other words, you should call sqlite3_column_text(),
3185 ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
3186 ** into the desired format, then invoke sqlite3_column_bytes() or
3187 ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
@@ -3215,21 +3263,30 @@
3215
3216 /*
3217 ** CAPI3REF: Destroy A Prepared Statement Object
3218 **
3219 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
3220 ** ^If the statement was executed successfully or not executed at all, then
3221 ** SQLITE_OK is returned. ^If execution of the statement failed then an
3222 ** [error code] or [extended error code] is returned.
 
 
3223 **
3224 ** ^This routine can be called at any point during the execution of the
3225 ** [prepared statement]. ^If the virtual machine has not
3226 ** completed execution when this routine is called, that is like
3227 ** encountering an error or an [sqlite3_interrupt | interrupt].
3228 ** ^Incomplete updates may be rolled back and transactions canceled,
3229 ** depending on the circumstances, and the
3230 ** [error code] returned will be [SQLITE_ABORT].
 
 
 
 
 
 
 
3231 */
3232 SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
3233
3234 /*
3235 ** CAPI3REF: Reset A Prepared Statement Object
@@ -3261,40 +3318,42 @@
3261 ** CAPI3REF: Create Or Redefine SQL Functions
3262 ** KEYWORDS: {function creation routines}
3263 ** KEYWORDS: {application-defined SQL function}
3264 ** KEYWORDS: {application-defined SQL functions}
3265 **
3266 ** ^These two functions (collectively known as "function creation routines")
3267 ** are used to add SQL functions or aggregates or to redefine the behavior
3268 ** of existing SQL functions or aggregates. The only difference between the
3269 ** two is that the second parameter, the name of the (scalar) function or
3270 ** aggregate, is encoded in UTF-8 for sqlite3_create_function() and UTF-16
3271 ** for sqlite3_create_function16().
 
3272 **
3273 ** ^The first parameter is the [database connection] to which the SQL
3274 ** function is to be added. ^If an application uses more than one database
3275 ** connection then application-defined SQL functions must be added
3276 ** to each database connection separately.
3277 **
3278 ** The second parameter is the name of the SQL function to be created or
3279 ** redefined. ^The length of the name is limited to 255 bytes, exclusive of
3280 ** the zero-terminator. Note that the name length limit is in bytes, not
3281 ** characters. ^Any attempt to create a function with a longer name
3282 ** will result in [SQLITE_ERROR] being returned.
 
3283 **
3284 ** ^The third parameter (nArg)
3285 ** is the number of arguments that the SQL function or
3286 ** aggregate takes. ^If this parameter is -1, then the SQL function or
3287 ** aggregate may take any number of arguments between 0 and the limit
3288 ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
3289 ** parameter is less than -1 or greater than 127 then the behavior is
3290 ** undefined.
3291 **
3292 ** The fourth parameter, eTextRep, specifies what
3293 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3294 ** its parameters. Any SQL function implementation should be able to work
3295 ** work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3296 ** more efficient with one encoding than another. ^An application may
3297 ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
3298 ** times with the same function but with different values of eTextRep.
3299 ** ^When multiple implementations of the same function are available, SQLite
3300 ** will pick the one that involves the least amount of data conversion.
@@ -3302,17 +3361,25 @@
3302 ** encoding is used, then the fourth argument should be [SQLITE_ANY].
3303 **
3304 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
3305 ** function can gain access to this pointer using [sqlite3_user_data()].)^
3306 **
3307 ** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
3308 ** pointers to C-language functions that implement the SQL function or
3309 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
3310 ** callback only; NULL pointers should be passed as the xStep and xFinal
3311 ** parameters. ^An aggregate SQL function requires an implementation of xStep
3312 ** and xFinal and NULL should be passed for xFunc. ^To delete an existing
3313 ** SQL function or aggregate, pass NULL for all three function callbacks.
 
 
 
 
 
 
 
 
3314 **
3315 ** ^It is permitted to register multiple implementations of the same
3316 ** functions with the same name but with either differing numbers of
3317 ** arguments or differing preferred text encodings. ^SQLite will use
3318 ** the implementation that most closely matches the way in which the
@@ -3324,15 +3391,10 @@
3324 ** ^A function where the encoding difference is between UTF16le and UTF16be
3325 ** is a closer match than a function where the encoding difference is
3326 ** between UTF8 and UTF16.
3327 **
3328 ** ^Built-in functions may be overloaded by new application-defined functions.
3329 ** ^The first application-defined function with a given name overrides all
3330 ** built-in functions in the same [database connection] with the same name.
3331 ** ^Subsequent application-defined functions of the same name only override
3332 ** prior application-defined functions that are an exact match for the
3333 ** number of parameters and preferred encoding.
3334 **
3335 ** ^An application-defined function is permitted to call other
3336 ** SQLite interfaces. However, such calls must not
3337 ** close the database connection nor finalize or reset the prepared
3338 ** statement in which the function is running.
@@ -3354,10 +3416,21 @@
3354 int eTextRep,
3355 void *pApp,
3356 void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
3357 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
3358 void (*xFinal)(sqlite3_context*)
 
 
 
 
 
 
 
 
 
 
 
3359 );
3360
3361 /*
3362 ** CAPI3REF: Text Encodings
3363 **
@@ -3701,73 +3774,97 @@
3701 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
3702
3703 /*
3704 ** CAPI3REF: Define New Collating Sequences
3705 **
3706 ** These functions are used to add new collation sequences to the
3707 ** [database connection] specified as the first argument.
3708 **
3709 ** ^The name of the new collation sequence is specified as a UTF-8 string
3710 ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
3711 ** and a UTF-16 string for sqlite3_create_collation16(). ^In all cases
3712 ** the name is passed as the second function argument.
3713 **
3714 ** ^The third argument may be one of the constants [SQLITE_UTF8],
3715 ** [SQLITE_UTF16LE], or [SQLITE_UTF16BE], indicating that the user-supplied
3716 ** routine expects to be passed pointers to strings encoded using UTF-8,
3717 ** UTF-16 little-endian, or UTF-16 big-endian, respectively. ^The
3718 ** third argument might also be [SQLITE_UTF16] to indicate that the routine
3719 ** expects pointers to be UTF-16 strings in the native byte order, or the
3720 ** argument can be [SQLITE_UTF16_ALIGNED] if the
3721 ** the routine expects pointers to 16-bit word aligned strings
3722 ** of UTF-16 in the native byte order.
3723 **
3724 ** A pointer to the user supplied routine must be passed as the fifth
3725 ** argument. ^If it is NULL, this is the same as deleting the collation
3726 ** sequence (so that SQLite cannot call it any more).
3727 ** ^Each time the application supplied function is invoked, it is passed
3728 ** as its first parameter a copy of the void* passed as the fourth argument
3729 ** to sqlite3_create_collation() or sqlite3_create_collation16().
3730 **
3731 ** ^The remaining arguments to the application-supplied routine are two strings,
3732 ** each represented by a (length, data) pair and encoded in the encoding
3733 ** that was passed as the third argument when the collation sequence was
3734 ** registered. The application defined collation routine should
3735 ** return negative, zero or positive if the first string is less than,
3736 ** equal to, or greater than the second string. i.e. (STRING1 - STRING2).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3737 **
3738 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
3739 ** except that it takes an extra argument which is a destructor for
3740 ** the collation. ^The destructor is called when the collation is
3741 ** destroyed and is passed a copy of the fourth parameter void* pointer
3742 ** of the sqlite3_create_collation_v2().
3743 ** ^Collations are destroyed when they are overridden by later calls to the
3744 ** collation creation functions or when the [database connection] is closed
3745 ** using [sqlite3_close()].
3746 **
3747 ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
3748 */
3749 SQLITE_API int sqlite3_create_collation(
3750 sqlite3*,
3751 const char *zName,
3752 int eTextRep,
3753 void*,
3754 int(*xCompare)(void*,int,const void*,int,const void*)
3755 );
3756 SQLITE_API int sqlite3_create_collation_v2(
3757 sqlite3*,
3758 const char *zName,
3759 int eTextRep,
3760 void*,
3761 int(*xCompare)(void*,int,const void*,int,const void*),
3762 void(*xDestroy)(void*)
3763 );
3764 SQLITE_API int sqlite3_create_collation16(
3765 sqlite3*,
3766 const void *zName,
3767 int eTextRep,
3768 void*,
3769 int(*xCompare)(void*,int,const void*,int,const void*)
3770 );
3771
3772 /*
3773 ** CAPI3REF: Collation Needed Callbacks
@@ -3852,20 +3949,23 @@
3852 #endif
3853
3854 /*
3855 ** CAPI3REF: Suspend Execution For A Short Time
3856 **
3857 ** ^The sqlite3_sleep() function causes the current thread to suspend execution
3858 ** for at least a number of milliseconds specified in its parameter.
3859 **
3860 ** ^If the operating system does not support sleep requests with
3861 ** millisecond time resolution, then the time will be rounded up to
3862 ** the nearest second. ^The number of milliseconds of sleep actually
3863 ** requested from the operating system is returned.
3864 **
3865 ** ^SQLite implements this interface by calling the xSleep()
3866 ** method of the default [sqlite3_vfs] object.
 
 
 
3867 */
3868 SQLITE_API int sqlite3_sleep(int);
3869
3870 /*
3871 ** CAPI3REF: Name Of The Folder Holding Temporary Files
@@ -4083,44 +4183,77 @@
4083 ** of heap memory by deallocating non-essential memory allocations
4084 ** held by the database library. Memory used to cache database
4085 ** pages to improve performance is an example of non-essential memory.
4086 ** ^sqlite3_release_memory() returns the number of bytes actually freed,
4087 ** which might be more or less than the amount requested.
 
 
4088 */
4089 SQLITE_API int sqlite3_release_memory(int);
4090
4091 /*
4092 ** CAPI3REF: Impose A Limit On Heap Size
4093 **
4094 ** ^The sqlite3_soft_heap_limit() interface places a "soft" limit
4095 ** on the amount of heap memory that may be allocated by SQLite.
4096 ** ^If an internal allocation is requested that would exceed the
4097 ** soft heap limit, [sqlite3_release_memory()] is invoked one or
4098 ** more times to free up some space before the allocation is performed.
4099 **
4100 ** ^The limit is called "soft" because if [sqlite3_release_memory()]
4101 ** cannot free sufficient memory to prevent the limit from being exceeded,
4102 ** the memory is allocated anyway and the current operation proceeds.
4103 **
4104 ** ^A negative or zero value for N means that there is no soft heap limit and
4105 ** [sqlite3_release_memory()] will only be called when memory is exhausted.
4106 ** ^The default value for the soft heap limit is zero.
4107 **
4108 ** ^(SQLite makes a best effort to honor the soft heap limit.
4109 ** But if the soft heap limit cannot be honored, execution will
4110 ** continue without error or notification.)^ This is why the limit is
4111 ** called a "soft" limit. It is advisory only.
4112 **
4113 ** Prior to SQLite version 3.5.0, this routine only constrained the memory
4114 ** allocated by a single thread - the same thread in which this routine
4115 ** runs. Beginning with SQLite version 3.5.0, the soft heap limit is
4116 ** applied to all threads. The value specified for the soft heap limit
4117 ** is an upper bound on the total memory allocation for all threads. In
4118 ** version 3.5.0 there is no mechanism for limiting the heap usage for
4119 ** individual threads.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4120 */
4121 SQLITE_API void sqlite3_soft_heap_limit(int);
 
4122
4123 /*
4124 ** CAPI3REF: Extract Metadata About A Column Of A Table
4125 **
4126 ** ^This routine returns metadata about a specific column of a specific
@@ -4240,38 +4373,51 @@
4240 ** it back off again.
4241 */
4242 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
4243
4244 /*
4245 ** CAPI3REF: Automatically Load An Extensions
4246 **
4247 ** ^This API can be invoked at program startup in order to register
4248 ** one or more statically linked extensions that will be available
4249 ** to all new [database connections].
4250 **
4251 ** ^(This routine stores a pointer to the extension entry point
4252 ** in an array that is obtained from [sqlite3_malloc()]. That memory
4253 ** is deallocated by [sqlite3_reset_auto_extension()].)^
4254 **
4255 ** ^This function registers an extension entry point that is
4256 ** automatically invoked whenever a new [database connection]
4257 ** is opened using [sqlite3_open()], [sqlite3_open16()],
4258 ** or [sqlite3_open_v2()].
4259 ** ^Duplicate extensions are detected so calling this routine
4260 ** multiple times with the same extension is harmless.
4261 ** ^Automatic extensions apply across all threads.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4262 */
4263 SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
4264
4265 /*
4266 ** CAPI3REF: Reset Automatic Extension Loading
4267 **
4268 ** ^(This function disables all previously registered automatic
4269 ** extensions. It undoes the effect of all prior
4270 ** [sqlite3_auto_extension()] calls.)^
4271 **
4272 ** ^This function disables automatic extensions in all threads.
4273 */
4274 SQLITE_API void sqlite3_reset_auto_extension(void);
4275
4276 /*
4277 ** The interface to the virtual-table mechanism is currently considered
@@ -4906,11 +5052,11 @@
4906 ** output variable when querying the system for the current mutex
4907 ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
4908 **
4909 ** ^The xMutexInit method defined by this structure is invoked as
4910 ** part of system initialization by the sqlite3_initialize() function.
4911 ** ^The xMutexInit routine is calle by SQLite exactly once for each
4912 ** effective call to [sqlite3_initialize()].
4913 **
4914 ** ^The xMutexEnd method defined by this structure is invoked as
4915 ** part of system shutdown by the sqlite3_shutdown() function. The
4916 ** implementation of this method is expected to release all outstanding
@@ -5103,11 +5249,12 @@
5103 #define SQLITE_TESTCTRL_ALWAYS 13
5104 #define SQLITE_TESTCTRL_RESERVE 14
5105 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
5106 #define SQLITE_TESTCTRL_ISKEYWORD 16
5107 #define SQLITE_TESTCTRL_PGHDRSZ 17
5108 #define SQLITE_TESTCTRL_LAST 17
 
5109
5110 /*
5111 ** CAPI3REF: SQLite Runtime Status
5112 **
5113 ** ^This interface is used to retrieve runtime status information
@@ -5122,11 +5269,11 @@
5122 ** value. For those parameters
5123 ** nothing is written into *pHighwater and the resetFlag is ignored.)^
5124 ** ^(Other parameters record only the highwater mark and not the current
5125 ** value. For these latter parameters nothing is written into *pCurrent.)^
5126 **
5127 ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
5128 ** non-zero [error code] on failure.
5129 **
5130 ** This routine is threadsafe but is not atomic. This routine can be
5131 ** called while other threads are running the same or different SQLite
5132 ** interfaces. However the values returned in *pCurrent and
@@ -5172,11 +5319,11 @@
5172 ** [SQLITE_CONFIG_PAGECACHE]. The
5173 ** value returned is in pages, not in bytes.</dd>)^
5174 **
5175 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
5176 ** <dd>This parameter returns the number of bytes of page cache
5177 ** allocation which could not be statisfied by the [SQLITE_CONFIG_PAGECACHE]
5178 ** buffer and where forced to overflow to [sqlite3_malloc()]. The
5179 ** returned value includes allocations that overflowed because they
5180 ** where too large (they were larger than the "sz" parameter to
5181 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
5182 ** no space was left in the page cache.</dd>)^
@@ -5195,11 +5342,11 @@
5195 ** outstanding at time, this parameter also reports the number of threads
5196 ** using scratch memory at the same time.</dd>)^
5197 **
5198 ** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
5199 ** <dd>This parameter returns the number of bytes of scratch memory
5200 ** allocation which could not be statisfied by the [SQLITE_CONFIG_SCRATCH]
5201 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
5202 ** returned include overflows because the requested allocation was too
5203 ** larger (that is, because the requested allocation was larger than the
5204 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
5205 ** slots were available.
@@ -5243,10 +5390,13 @@
5243 **
5244 ** ^The current value of the requested parameter is written into *pCur
5245 ** and the highest instantaneous value is written into *pHiwtr. ^If
5246 ** the resetFlg is true, then the highest instantaneous value is
5247 ** reset back down to the current value.
 
 
 
5248 **
5249 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
5250 */
5251 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5252
@@ -5370,122 +5520,134 @@
5370 ** CAPI3REF: Application Defined Page Cache.
5371 ** KEYWORDS: {page cache}
5372 **
5373 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
5374 ** register an alternative page cache implementation by passing in an
5375 ** instance of the sqlite3_pcache_methods structure.)^ The majority of the
5376 ** heap memory used by SQLite is used by the page cache to cache data read
5377 ** from, or ready to be written to, the database file. By implementing a
5378 ** custom page cache using this API, an application can control more
5379 ** precisely the amount of memory consumed by SQLite, the way in which
 
5380 ** that memory is allocated and released, and the policies used to
5381 ** determine exactly which parts of a database file are cached and for
5382 ** how long.
5383 **
 
 
 
 
5384 ** ^(The contents of the sqlite3_pcache_methods structure are copied to an
5385 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence
5386 ** the application may discard the parameter after the call to
5387 ** [sqlite3_config()] returns.)^
5388 **
5389 ** ^The xInit() method is called once for each call to [sqlite3_initialize()]
 
5390 ** (usually only once during the lifetime of the process). ^(The xInit()
5391 ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
5392 ** ^The xInit() method can set up up global structures and/or any mutexes
5393 ** required by the custom page cache implementation.
 
 
 
5394 **
5395 ** ^The xShutdown() method is called from within [sqlite3_shutdown()],
5396 ** if the application invokes this API. It can be used to clean up
5397 ** any outstanding resources before process shutdown, if required.
 
5398 **
5399 ** ^SQLite holds a [SQLITE_MUTEX_RECURSIVE] mutex when it invokes
5400 ** the xInit method, so the xInit method need not be threadsafe. ^The
5401 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
5402 ** not need to be threadsafe either. All other methods must be threadsafe
5403 ** in multithreaded applications.
5404 **
5405 ** ^SQLite will never invoke xInit() more than once without an intervening
5406 ** call to xShutdown().
5407 **
5408 ** ^The xCreate() method is used to construct a new cache instance. SQLite
5409 ** will typically create one cache instance for each open database file,
5410 ** though this is not guaranteed. ^The
5411 ** first parameter, szPage, is the size in bytes of the pages that must
5412 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage
5413 ** will the page size of the database file that is to be cached plus an
5414 ** increment (here called "R") of about 100 or 200. ^SQLite will use the
5415 ** extra R bytes on each page to store metadata about the underlying
5416 ** database page on disk. The value of R depends
5417 ** on the SQLite version, the target platform, and how SQLite was compiled.
5418 ** ^R is constant for a particular build of SQLite. ^The second argument to
5419 ** xCreate(), bPurgeable, is true if the cache being created will
5420 ** be used to cache database pages of a file stored on disk, or
5421 ** false if it is used for an in-memory database. ^The cache implementation
5422 ** does not have to do anything special based with the value of bPurgeable;
5423 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
5424 ** never invoke xUnpin() except to deliberately delete a page.
5425 ** ^In other words, a cache created with bPurgeable set to false will
 
 
5426 ** never contain any unpinned pages.
5427 **
5428 ** ^(The xCachesize() method may be called at any time by SQLite to set the
5429 ** suggested maximum cache-size (number of pages stored by) the cache
5430 ** instance passed as the first argument. This is the value configured using
5431 ** the SQLite "[PRAGMA cache_size]" command.)^ ^As with the bPurgeable
5432 ** parameter, the implementation is not required to do anything with this
5433 ** value; it is advisory only.
5434 **
5435 ** ^The xPagecount() method should return the number of pages currently
5436 ** stored in the cache.
5437 **
5438 ** ^The xFetch() method is used to fetch a page and return a pointer to it.
5439 ** ^A 'page', in this context, is a buffer of szPage bytes aligned at an
5440 ** 8-byte boundary. ^The page to be fetched is determined by the key. ^The
5441 ** mimimum key value is 1. After it has been retrieved using xFetch, the page
 
5442 ** is considered to be "pinned".
5443 **
5444 ** ^If the requested page is already in the page cache, then the page cache
5445 ** implementation must return a pointer to the page buffer with its content
5446 ** intact. ^(If the requested page is not already in the cache, then the
5447 ** behavior of the cache implementation is determined by the value of the
5448 ** createFlag parameter passed to xFetch, according to the following table:
5449 **
5450 ** <table border=1 width=85% align=center>
5451 ** <tr><th> createFlag <th> Behaviour when page is not already in cache
5452 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
5453 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
5454 ** Otherwise return NULL.
5455 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
5456 ** NULL if allocating a new page is effectively impossible.
5457 ** </table>)^
5458 **
5459 ** SQLite will normally invoke xFetch() with a createFlag of 0 or 1. If
5460 ** a call to xFetch() with createFlag==1 returns NULL, then SQLite will
 
5461 ** attempt to unpin one or more cache pages by spilling the content of
5462 ** pinned pages to disk and synching the operating system disk cache. After
5463 ** attempting to unpin pages, the xFetch() method will be invoked again with
5464 ** a createFlag of 2.
5465 **
5466 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
5467 ** as its second argument. ^(If the third parameter, discard, is non-zero,
5468 ** then the page should be evicted from the cache. In this case SQLite
5469 ** assumes that the next time the page is retrieved from the cache using
5470 ** the xFetch() method, it will be zeroed.)^ ^If the discard parameter is
5471 ** zero, then the page is considered to be unpinned. ^The cache implementation
5472 ** may choose to evict unpinned pages at any time.
5473 **
5474 ** ^(The cache is not required to perform any reference counting. A single
5475 ** call to xUnpin() unpins the page regardless of the number of prior calls
5476 ** to xFetch().)^
5477 **
5478 ** ^The xRekey() method is used to change the key value associated with the
5479 ** page passed as the second argument from oldKey to newKey. ^If the cache
5480 ** previously contains an entry associated with newKey, it should be
5481 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
5482 ** to be pinned.
5483 **
5484 ** ^When SQLite calls the xTruncate() method, the cache must discard all
5485 ** existing cache entries with page numbers (keys) greater than or equal
5486 ** to the value of the iLimit parameter passed to xTruncate(). ^If any
5487 ** of these pages are pinned, they are implicitly unpinned, meaning that
5488 ** they can be safely discarded.
5489 **
5490 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
5491 ** All resources associated with the specified cache should be freed. ^After
@@ -5959,5 +6121,61 @@
5959 #ifdef __cplusplus
5960 } /* End of the 'extern "C"' block */
5961 #endif
5962 #endif
5963
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5964
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.3"
111 #define SQLITE_VERSION_NUMBER 3007003
112 #define SQLITE_SOURCE_ID "2010-10-04 23:55:51 ece641eb8951c6314cedbdb3243f91cb199c3239"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -755,19 +755,23 @@
755 ** object once the object has been registered.
756 **
757 ** The zName field holds the name of the VFS module. The name must
758 ** be unique across all VFS modules.
759 **
760 ** ^SQLite guarantees that the zFilename parameter to xOpen
761 ** is either a NULL pointer or string obtained
762 ** from xFullPathname() with an optional suffix added.
763 ** ^If a suffix is added to the zFilename parameter, it will
764 ** consist of a single "-" character followed by no more than
765 ** 10 alphanumeric and/or "-" characters.
766 ** ^SQLite further guarantees that
767 ** the string will be valid and unchanged until xClose() is
768 ** called. Because of the previous sentence,
769 ** the [sqlite3_file] can safely store a pointer to the
770 ** filename if it needs to remember the filename for some reason.
771 ** If the zFilename parameter to xOpen is a NULL pointer then xOpen
772 ** must invent its own temporary name for the file. ^Whenever the
773 ** xFilename parameter is NULL it will also be the case that the
774 ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
775 **
776 ** The flags argument to xOpen() includes all bits set in
777 ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
@@ -774,11 +778,11 @@
778 ** or [sqlite3_open16()] is used, then flags includes at least
779 ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
780 ** If xOpen() opens a file read-only then it sets *pOutFlags to
781 ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
782 **
783 ** ^(SQLite will also add one of the following flags to the xOpen()
784 ** call, depending on the object being opened:
785 **
786 ** <ul>
787 ** <li> [SQLITE_OPEN_MAIN_DB]
788 ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
@@ -785,11 +789,12 @@
789 ** <li> [SQLITE_OPEN_TEMP_DB]
790 ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
791 ** <li> [SQLITE_OPEN_TRANSIENT_DB]
792 ** <li> [SQLITE_OPEN_SUBJOURNAL]
793 ** <li> [SQLITE_OPEN_MASTER_JOURNAL]
794 ** <li> [SQLITE_OPEN_WAL]
795 ** </ul>)^
796 **
797 ** The file I/O implementation can use the object type flags to
798 ** change the way it deals with files. For example, an application
799 ** that does not care about crash recovery or rollback might make
800 ** the open of a journal file a no-op. Writes to this journal would
@@ -804,39 +809,40 @@
809 ** <li> [SQLITE_OPEN_DELETEONCLOSE]
810 ** <li> [SQLITE_OPEN_EXCLUSIVE]
811 ** </ul>
812 **
813 ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
814 ** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE]
815 ** will be set for TEMP databases and their journals, transient
816 ** databases, and subjournals.
817 **
818 ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
819 ** with the [SQLITE_OPEN_CREATE] flag, which are both directly
820 ** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
821 ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
822 ** SQLITE_OPEN_CREATE, is used to indicate that file should always
823 ** be created, and that it is an error if it already exists.
824 ** It is <i>not</i> used to indicate the file should be opened
825 ** for exclusive access.
826 **
827 ** ^At least szOsFile bytes of memory are allocated by SQLite
828 ** to hold the [sqlite3_file] structure passed as the third
829 ** argument to xOpen. The xOpen method does not have to
830 ** allocate the structure; it should just fill it in. Note that
831 ** the xOpen method must set the sqlite3_file.pMethods to either
832 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
833 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
834 ** element will be valid after xOpen returns regardless of the success
835 ** or failure of the xOpen call.
836 **
837 ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
838 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
839 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
840 ** to test whether a file is at least readable. The file can be a
841 ** directory.
842 **
843 ** ^SQLite will always allocate at least mxPathname+1 bytes for the
844 ** output buffer xFullPathname. The exact size of the output buffer
845 ** is also passed as a parameter to both methods. If the output buffer
846 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
847 ** handled as a fatal error by SQLite, vfs implementations should endeavor
848 ** to prevent this by setting mxPathname to a sufficiently large value.
@@ -846,14 +852,14 @@
852 ** included in the VFS structure for completeness.
853 ** The xRandomness() function attempts to return nBytes bytes
854 ** of good-quality randomness into zOut. The return value is
855 ** the actual number of bytes of randomness obtained.
856 ** The xSleep() method causes the calling thread to sleep for at
857 ** least the number of microseconds given. ^The xCurrentTime()
858 ** method returns a Julian Day Number for the current date and time as
859 ** a floating point value.
860 ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
861 ** Day Number multipled by 86400000 (the number of milliseconds in
862 ** a 24-hour day).
863 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
864 ** date and time if that method is available (if iVersion is 2 or
865 ** greater and the function pointer is not NULL) and will fall back
@@ -1246,11 +1252,11 @@
1252 ** statistics. ^(When memory allocation statistics are disabled, the
1253 ** following SQLite interfaces become non-operational:
1254 ** <ul>
1255 ** <li> [sqlite3_memory_used()]
1256 ** <li> [sqlite3_memory_highwater()]
1257 ** <li> [sqlite3_soft_heap_limit64()]
1258 ** <li> [sqlite3_status()]
1259 ** </ul>)^
1260 ** ^Memory allocation statistics are enabled by default unless SQLite is
1261 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1262 ** allocation statistics are disabled by default.
@@ -1260,19 +1266,18 @@
1266 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1267 ** scratch memory. There are three arguments: A pointer an 8-byte
1268 ** aligned memory buffer from which the scrach allocations will be
1269 ** drawn, the size of each scratch allocation (sz),
1270 ** and the maximum number of scratch allocations (N). The sz
1271 ** argument must be a multiple of 16.
 
1272 ** The first argument must be a pointer to an 8-byte aligned buffer
1273 ** of at least sz*N bytes of memory.
1274 ** ^SQLite will use no more than two scratch buffers per thread. So
1275 ** N should be set to twice the expected maximum number of threads.
1276 ** ^SQLite will never require a scratch buffer that is more than 6
1277 ** times the database page size. ^If SQLite needs needs additional
1278 ** scratch memory beyond what is provided by this configuration option, then
1279 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
1280 **
1281 ** <dt>SQLITE_CONFIG_PAGECACHE</dt>
1282 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1283 ** the database page cache with the default page cache implemenation.
@@ -1288,12 +1293,11 @@
1293 ** argument should point to an allocation of at least sz*N bytes of memory.
1294 ** ^SQLite will use the memory provided by the first argument to satisfy its
1295 ** memory needs for the first N pages that it adds to cache. ^If additional
1296 ** page cache memory is needed beyond what is provided by this option, then
1297 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1298 ** The pointer in the first argument must
 
1299 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1300 ** will be undefined.</dd>
1301 **
1302 ** <dt>SQLITE_CONFIG_HEAP</dt>
1303 ** <dd> ^This option specifies a static memory buffer that SQLite will use
@@ -1418,12 +1422,18 @@
1422 ** size of each lookaside buffer slot. ^The third argument is the number of
1423 ** slots. The size of the buffer in the first argument must be greater than
1424 ** or equal to the product of the second and third arguments. The buffer
1425 ** must be aligned to an 8-byte boundary. ^If the second argument to
1426 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
1427 ** rounded down to the next smaller multiple of 8. ^(The lookaside memory
1428 ** configuration for a database connection can only be changed when that
1429 ** connection is not currently using lookaside memory, or in other words
1430 ** when the "current value" returned by
1431 ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
1432 ** Any attempt to change the lookaside memory configuration when lookaside
1433 ** memory is in use leaves the configuration unchanged and returns
1434 ** [SQLITE_BUSY].)^</dd>
1435 **
1436 ** </dl>
1437 */
1438 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1439
@@ -1723,10 +1733,13 @@
1733 */
1734 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
1735
1736 /*
1737 ** CAPI3REF: Convenience Routines For Running Queries
1738 **
1739 ** This is a legacy interface that is preserved for backwards compatibility.
1740 ** Use of this interface is not recommended.
1741 **
1742 ** Definition: A <b>result table</b> is memory data structure created by the
1743 ** [sqlite3_get_table()] interface. A result table records the
1744 ** complete query results from one or more queries.
1745 **
@@ -1744,11 +1757,11 @@
1757 **
1758 ** A result table might consist of one or more memory allocations.
1759 ** It is not safe to pass a result table directly to [sqlite3_free()].
1760 ** A result table should be deallocated using [sqlite3_free_table()].
1761 **
1762 ** ^(As an example of the result table format, suppose a query result
1763 ** is as follows:
1764 **
1765 ** <blockquote><pre>
1766 ** Name | Age
1767 ** -----------------------
@@ -1768,31 +1781,31 @@
1781 ** azResult&#91;3] = "43";
1782 ** azResult&#91;4] = "Bob";
1783 ** azResult&#91;5] = "28";
1784 ** azResult&#91;6] = "Cindy";
1785 ** azResult&#91;7] = "21";
1786 ** </pre></blockquote>)^
1787 **
1788 ** ^The sqlite3_get_table() function evaluates one or more
1789 ** semicolon-separated SQL statements in the zero-terminated UTF-8
1790 ** string of its 2nd parameter and returns a result table to the
1791 ** pointer given in its 3rd parameter.
1792 **
1793 ** After the application has finished with the result from sqlite3_get_table(),
1794 ** it must pass the result table pointer to sqlite3_free_table() in order to
1795 ** release the memory that was malloced. Because of the way the
1796 ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
1797 ** function must not try to call [sqlite3_free()] directly. Only
1798 ** [sqlite3_free_table()] is able to release the memory properly and safely.
1799 **
1800 ** The sqlite3_get_table() interface is implemented as a wrapper around
1801 ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
1802 ** to any internal data structures of SQLite. It uses only the public
1803 ** interface defined here. As a consequence, errors that occur in the
1804 ** wrapper layer outside of the internal [sqlite3_exec()] call are not
1805 ** reflected in subsequent calls to [sqlite3_errcode()] or
1806 ** [sqlite3_errmsg()].
1807 */
1808 SQLITE_API int sqlite3_get_table(
1809 sqlite3 *db, /* An open database */
1810 const char *zSql, /* SQL to be evaluated */
1811 char ***pazResult, /* Results of the query */
@@ -1940,11 +1953,13 @@
1953 ** by sqlite3_realloc() and the prior allocation is freed.
1954 ** ^If sqlite3_realloc() returns NULL, then the prior allocation
1955 ** is not freed.
1956 **
1957 ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
1958 ** is always aligned to at least an 8 byte boundary, or to a
1959 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
1960 ** option is used.
1961 **
1962 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
1963 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
1964 ** implementation of these routines to be omitted. That capability
1965 ** is no longer provided. Only built-in memory allocators can be used.
@@ -2198,21 +2213,32 @@
2213 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2214
2215 /*
2216 ** CAPI3REF: Query Progress Callbacks
2217 **
2218 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2219 ** function X to be invoked periodically during long running calls to
2220 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2221 ** database connection D. An example use for this
2222 ** interface is to keep a GUI updated during a large query.
2223 **
2224 ** ^The parameter P is passed through as the only parameter to the
2225 ** callback function X. ^The parameter N is the number of
2226 ** [virtual machine instructions] that are evaluated between successive
2227 ** invocations of the callback X.
2228 **
2229 ** ^Only a single progress handler may be defined at one time per
2230 ** [database connection]; setting a new progress handler cancels the
2231 ** old one. ^Setting parameter X to NULL disables the progress handler.
2232 ** ^The progress handler is also disabled by setting N to a value less
2233 ** than 1.
2234 **
2235 ** ^If the progress callback returns non-zero, the operation is
2236 ** interrupted. This feature can be used to implement a
2237 ** "Cancel" button on a GUI progress dialog box.
2238 **
2239 ** The progress handler callback must not do anything that will modify
2240 ** the database connection that invoked the progress handler.
2241 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
2242 ** database connections for the meaning of "modify" in this paragraph.
2243 **
2244 */
@@ -2267,11 +2293,11 @@
2293 ** </dl>
2294 **
2295 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
2296 ** combinations shown above or one of the combinations shown above combined
2297 ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
2298 ** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags,
2299 ** then the behavior is undefined.
2300 **
2301 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
2302 ** opens in the multi-thread [threading mode] as long as the single-thread
2303 ** mode has not been set at compile-time or start-time. ^If the
@@ -2392,21 +2418,26 @@
2418 ** ^(This interface allows the size of various constructs to be limited
2419 ** on a connection by connection basis. The first parameter is the
2420 ** [database connection] whose limit is to be set or queried. The
2421 ** second parameter is one of the [limit categories] that define a
2422 ** class of constructs to be size limited. The third parameter is the
2423 ** new limit for that construct.)^
2424 **
2425 ** ^If the new limit is a negative number, the limit is unchanged.
2426 ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
2427 ** [limits | hard upper bound]
2428 ** set at compile-time by a C preprocessor macro called
2429 ** [limits | SQLITE_MAX_<i>NAME</i>].
2430 ** (The "_LIMIT_" in the name is changed to "_MAX_".))^
2431 ** ^Attempts to increase a limit above its hard upper bound are
2432 ** silently truncated to the hard upper bound.
2433 **
2434 ** ^Regardless of whether or not the limit was changed, the
2435 ** [sqlite3_limit()] interface returns the prior value of the limit.
2436 ** ^Hence, to find the current value of a limit without changing it,
2437 ** simply invoke this interface with the third parameter set to -1.
2438 **
2439 ** Run-time limits are intended for use in applications that manage
2440 ** both their own internal database and also databases that are controlled
2441 ** by untrusted external sources. An example application might be a
2442 ** web browser that has its own databases for storing history and
2443 ** separate databases controlled by JavaScript applications downloaded
@@ -2431,11 +2462,11 @@
2462 ** The synopsis of the meanings of the various limits is shown below.
2463 ** Additional information is available at [limits | Limits in SQLite].
2464 **
2465 ** <dl>
2466 ** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
2467 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
2468 **
2469 ** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
2470 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
2471 **
2472 ** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
@@ -2449,11 +2480,13 @@
2480 ** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
2481 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
2482 **
2483 ** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
2484 ** <dd>The maximum number of instructions in a virtual machine program
2485 ** used to implement an SQL statement. This limit is not currently
2486 ** enforced, though that might be added in some future release of
2487 ** SQLite.</dd>)^
2488 **
2489 ** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
2490 ** <dd>The maximum number of arguments on a function.</dd>)^
2491 **
2492 ** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
@@ -2462,12 +2495,11 @@
2495 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
2496 ** <dd>The maximum length of the pattern argument to the [LIKE] or
2497 ** [GLOB] operators.</dd>)^
2498 **
2499 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
2500 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
 
2501 **
2502 ** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
2503 ** <dd>The maximum depth of recursion for triggers.</dd>)^
2504 ** </dl>
2505 */
@@ -2535,16 +2567,11 @@
2567 **
2568 ** <ol>
2569 ** <li>
2570 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
2571 ** always used to do, [sqlite3_step()] will automatically recompile the SQL
2572 ** statement and try to run it again.
 
 
 
 
 
2573 ** </li>
2574 **
2575 ** <li>
2576 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
2577 ** [error codes] or [extended error codes]. ^The legacy behavior was that
@@ -2553,15 +2580,20 @@
2580 ** in order to find the underlying cause of the problem. With the "v2" prepare
2581 ** interfaces, the underlying reason for the error is returned immediately.
2582 ** </li>
2583 **
2584 ** <li>
2585 ** ^If the specific value bound to [parameter | host parameter] in the
2586 ** WHERE clause might influence the choice of query plan for a statement,
2587 ** then the statement will be automatically recompiled, as if there had been
2588 ** a schema change, on the first [sqlite3_step()] call following any change
2589 ** to the [sqlite3_bind_text | bindings] of that [parameter].
2590 ** ^The specific value of WHERE-clause [parameter] might influence the
2591 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
2592 ** or [GLOB] operator or if the parameter is compared to an indexed column
2593 ** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled.
2594 ** the
2595 ** </li>
2596 ** </ol>
2597 */
2598 SQLITE_API int sqlite3_prepare(
2599 sqlite3 *db, /* Database handle */
@@ -2624,11 +2656,11 @@
2656 ** or if SQLite is run in one of reduced mutex modes
2657 ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
2658 ** then there is no distinction between protected and unprotected
2659 ** sqlite3_value objects and they can be used interchangeably. However,
2660 ** for maximum code portability it is recommended that applications
2661 ** still make the distinction between protected and unprotected
2662 ** sqlite3_value objects even when not strictly required.
2663 **
2664 ** ^The sqlite3_value objects that are passed as parameters into the
2665 ** implementation of [application-defined SQL functions] are protected.
2666 ** ^The sqlite3_value object returned by
@@ -2819,10 +2851,12 @@
2851 ** CAPI3REF: Number Of Columns In A Result Set
2852 **
2853 ** ^Return the number of columns in the result set returned by the
2854 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
2855 ** statement that does not return data (for example an [UPDATE]).
2856 **
2857 ** See also: [sqlite3_data_count()]
2858 */
2859 SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
2860
2861 /*
2862 ** CAPI3REF: Column Names In A Result Set
@@ -3009,12 +3043,18 @@
3043 SQLITE_API int sqlite3_step(sqlite3_stmt*);
3044
3045 /*
3046 ** CAPI3REF: Number of columns in a result set
3047 **
3048 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
3049 ** current row of the result set of [prepared statement] P.
3050 ** ^If prepared statement P does not have results ready to return
3051 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
3052 ** interfaces) then sqlite3_data_count(P) returns 0.
3053 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
3054 **
3055 ** See also: [sqlite3_column_count()]
3056 */
3057 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
3058
3059 /*
3060 ** CAPI3REF: Fundamental Datatypes
@@ -3090,22 +3130,30 @@
3130 ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
3131 ** the string to UTF-8 and then returns the number of bytes.
3132 ** ^If the result is a numeric value then sqlite3_column_bytes() uses
3133 ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
3134 ** the number of bytes in that string.
3135 ** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
3136 **
3137 ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
3138 ** routine returns the number of bytes in that BLOB or string.
3139 ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
3140 ** the string to UTF-16 and then returns the number of bytes.
3141 ** ^If the result is a numeric value then sqlite3_column_bytes16() uses
3142 ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
3143 ** the number of bytes in that string.
3144 ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
3145 **
3146 ** ^The values returned by [sqlite3_column_bytes()] and
3147 ** [sqlite3_column_bytes16()] do not include the zero terminators at the end
3148 ** of the string. ^For clarity: the values returned by
3149 ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
3150 ** bytes in the string, not the number of characters.
3151 **
3152 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
3153 ** even empty strings, are always zero terminated. ^The return
3154 ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
 
 
 
 
 
3155 **
3156 ** ^The object returned by [sqlite3_column_value()] is an
3157 ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object
3158 ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
3159 ** If the [unprotected sqlite3_value] object returned by
@@ -3146,14 +3194,14 @@
3194 ** and atof(). SQLite does not really use these functions. It has its
3195 ** own equivalent internal routines. The atoi() and atof() names are
3196 ** used in the table for brevity and because they are familiar to most
3197 ** C programmers.
3198 **
3199 ** Note that when type conversions occur, pointers returned by prior
3200 ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
3201 ** sqlite3_column_text16() may be invalidated.
3202 ** Type conversions and pointer invalidations might occur
3203 ** in the following cases:
3204 **
3205 ** <ul>
3206 ** <li> The initial content is a BLOB and sqlite3_column_text() or
3207 ** sqlite3_column_text16() is called. A zero-terminator might
@@ -3162,26 +3210,26 @@
3210 ** sqlite3_column_text16() is called. The content must be converted
3211 ** to UTF-16.</li>
3212 ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
3213 ** sqlite3_column_text() is called. The content must be converted
3214 ** to UTF-8.</li>
3215 ** </ul>
3216 **
3217 ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
3218 ** not invalidate a prior pointer, though of course the content of the buffer
3219 ** that the prior pointer references will have been modified. Other kinds
3220 ** of conversion are done in place when it is possible, but sometimes they
3221 ** are not possible and in those cases prior pointers are invalidated.
3222 **
3223 ** The safest and easiest to remember policy is to invoke these routines
3224 ** in one of the following ways:
3225 **
3226 ** <ul>
3227 ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
3228 ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
3229 ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
3230 ** </ul>
3231 **
3232 ** In other words, you should call sqlite3_column_text(),
3233 ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
3234 ** into the desired format, then invoke sqlite3_column_bytes() or
3235 ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
@@ -3215,21 +3263,30 @@
3263
3264 /*
3265 ** CAPI3REF: Destroy A Prepared Statement Object
3266 **
3267 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
3268 ** ^If the most recent evaluation of the statement encountered no errors or
3269 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
3270 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
3271 ** sqlite3_finalize(S) returns the appropriate [error code] or
3272 ** [extended error code].
3273 **
3274 ** ^The sqlite3_finalize(S) routine can be called at any point during
3275 ** the life cycle of [prepared statement] S:
3276 ** before statement S is ever evaluated, after
3277 ** one or more calls to [sqlite3_reset()], or after any call
3278 ** to [sqlite3_step()] regardless of whether or not the statement has
3279 ** completed execution.
3280 **
3281 ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
3282 **
3283 ** The application must finalize every [prepared statement] in order to avoid
3284 ** resource leaks. It is a grievous error for the application to try to use
3285 ** a prepared statement after it has been finalized. Any use of a prepared
3286 ** statement after it has been finalized can result in undefined and
3287 ** undesirable behavior such as segfaults and heap corruption.
3288 */
3289 SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
3290
3291 /*
3292 ** CAPI3REF: Reset A Prepared Statement Object
@@ -3261,40 +3318,42 @@
3318 ** CAPI3REF: Create Or Redefine SQL Functions
3319 ** KEYWORDS: {function creation routines}
3320 ** KEYWORDS: {application-defined SQL function}
3321 ** KEYWORDS: {application-defined SQL functions}
3322 **
3323 ** ^These functions (collectively known as "function creation routines")
3324 ** are used to add SQL functions or aggregates or to redefine the behavior
3325 ** of existing SQL functions or aggregates. The only differences between
3326 ** these routines are the text encoding expected for
3327 ** the the second parameter (the name of the function being created)
3328 ** and the presence or absence of a destructor callback for
3329 ** the application data pointer.
3330 **
3331 ** ^The first parameter is the [database connection] to which the SQL
3332 ** function is to be added. ^If an application uses more than one database
3333 ** connection then application-defined SQL functions must be added
3334 ** to each database connection separately.
3335 **
3336 ** ^The second parameter is the name of the SQL function to be created or
3337 ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
3338 ** representation, exclusive of the zero-terminator. ^Note that the name
3339 ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
3340 ** ^Any attempt to create a function with a longer name
3341 ** will result in [SQLITE_MISUSE] being returned.
3342 **
3343 ** ^The third parameter (nArg)
3344 ** is the number of arguments that the SQL function or
3345 ** aggregate takes. ^If this parameter is -1, then the SQL function or
3346 ** aggregate may take any number of arguments between 0 and the limit
3347 ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
3348 ** parameter is less than -1 or greater than 127 then the behavior is
3349 ** undefined.
3350 **
3351 ** ^The fourth parameter, eTextRep, specifies what
3352 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3353 ** its parameters. Every SQL function implementation must be able to work
3354 ** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3355 ** more efficient with one encoding than another. ^An application may
3356 ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
3357 ** times with the same function but with different values of eTextRep.
3358 ** ^When multiple implementations of the same function are available, SQLite
3359 ** will pick the one that involves the least amount of data conversion.
@@ -3302,17 +3361,25 @@
3361 ** encoding is used, then the fourth argument should be [SQLITE_ANY].
3362 **
3363 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
3364 ** function can gain access to this pointer using [sqlite3_user_data()].)^
3365 **
3366 ** ^The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
3367 ** pointers to C-language functions that implement the SQL function or
3368 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
3369 ** callback only; NULL pointers must be passed as the xStep and xFinal
3370 ** parameters. ^An aggregate SQL function requires an implementation of xStep
3371 ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
3372 ** SQL function or aggregate, pass NULL poiners for all three function
3373 ** callbacks.
3374 **
3375 ** ^If the tenth parameter to sqlite3_create_function_v2() is not NULL,
3376 ** then it is invoked when the function is deleted, either by being
3377 ** overloaded or when the database connection closes.
3378 ** ^When the destructure callback of the tenth parameter is invoked, it
3379 ** is passed a single argument which is a copy of the pointer which was
3380 ** the fifth parameter to sqlite3_create_function_v2().
3381 **
3382 ** ^It is permitted to register multiple implementations of the same
3383 ** functions with the same name but with either differing numbers of
3384 ** arguments or differing preferred text encodings. ^SQLite will use
3385 ** the implementation that most closely matches the way in which the
@@ -3324,15 +3391,10 @@
3391 ** ^A function where the encoding difference is between UTF16le and UTF16be
3392 ** is a closer match than a function where the encoding difference is
3393 ** between UTF8 and UTF16.
3394 **
3395 ** ^Built-in functions may be overloaded by new application-defined functions.
 
 
 
 
 
3396 **
3397 ** ^An application-defined function is permitted to call other
3398 ** SQLite interfaces. However, such calls must not
3399 ** close the database connection nor finalize or reset the prepared
3400 ** statement in which the function is running.
@@ -3354,10 +3416,21 @@
3416 int eTextRep,
3417 void *pApp,
3418 void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
3419 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
3420 void (*xFinal)(sqlite3_context*)
3421 );
3422 SQLITE_API int sqlite3_create_function_v2(
3423 sqlite3 *db,
3424 const char *zFunctionName,
3425 int nArg,
3426 int eTextRep,
3427 void *pApp,
3428 void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
3429 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
3430 void (*xFinal)(sqlite3_context*),
3431 void(*xDestroy)(void*)
3432 );
3433
3434 /*
3435 ** CAPI3REF: Text Encodings
3436 **
@@ -3701,73 +3774,97 @@
3774 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
3775
3776 /*
3777 ** CAPI3REF: Define New Collating Sequences
3778 **
3779 ** ^These functions add, remove, or modify a [collation] associated
3780 ** with the [database connection] specified as the first argument.
3781 **
3782 ** ^The name of the collation is a UTF-8 string
3783 ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
3784 ** and a UTF-16 string in native byte order for sqlite3_create_collation16().
3785 ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
3786 ** considered to be the same name.
3787 **
3788 ** ^(The third argument (eTextRep) must be one of the constants:
3789 ** <ul>
3790 ** <li> [SQLITE_UTF8],
3791 ** <li> [SQLITE_UTF16LE],
3792 ** <li> [SQLITE_UTF16BE],
3793 ** <li> [SQLITE_UTF16], or
3794 ** <li> [SQLITE_UTF16_ALIGNED].
3795 ** </ul>)^
3796 ** ^The eTextRep argument determines the encoding of strings passed
3797 ** to the collating function callback, xCallback.
3798 ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
3799 ** force strings to be UTF16 with native byte order.
3800 ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
3801 ** on an even byte address.
3802 **
3803 ** ^The fourth argument, pArg, is a application data pointer that is passed
3804 ** through as the first argument to the collating function callback.
3805 **
3806 ** ^The fifth argument, xCallback, is a pointer to the collating function.
3807 ** ^Multiple collating functions can be registered using the same name but
3808 ** with different eTextRep parameters and SQLite will use whichever
3809 ** function requires the least amount of data transformation.
3810 ** ^If the xCallback argument is NULL then the collating function is
3811 ** deleted. ^When all collating functions having the same name are deleted,
3812 ** that collation is no longer usable.
3813 **
3814 ** ^The collating function callback is invoked with a copy of the pArg
3815 ** application data pointer and with two strings in the encoding specified
3816 ** by the eTextRep argument. The collating function must return an
3817 ** integer that is negative, zero, or positive
3818 ** if the first string is less than, equal to, or greater than the second,
3819 ** respectively. A collating function must alway return the same answer
3820 ** given the same inputs. If two or more collating functions are registered
3821 ** to the same collation name (using different eTextRep values) then all
3822 ** must give an equivalent answer when invoked with equivalent strings.
3823 ** The collating function must obey the following properties for all
3824 ** strings A, B, and C:
3825 **
3826 ** <ol>
3827 ** <li> If A==B then B==A.
3828 ** <li> If A==B and B==C then A==C.
3829 ** <li> If A&lt;B THEN B&gt;A.
3830 ** <li> If A&lt;B and B&lt;C then A&lt;C.
3831 ** </ol>
3832 **
3833 ** If a collating function fails any of the above constraints and that
3834 ** collating function is registered and used, then the behavior of SQLite
3835 ** is undefined.
3836 **
3837 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
3838 ** with the addition that the xDestroy callback is invoked on pArg when
3839 ** the collating function is deleted.
3840 ** ^Collating functions are deleted when they are overridden by later
3841 ** calls to the collation creation functions or when the
3842 ** [database connection] is closed using [sqlite3_close()].
 
 
3843 **
3844 ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
3845 */
3846 SQLITE_API int sqlite3_create_collation(
3847 sqlite3*,
3848 const char *zName,
3849 int eTextRep,
3850 void *pArg,
3851 int(*xCompare)(void*,int,const void*,int,const void*)
3852 );
3853 SQLITE_API int sqlite3_create_collation_v2(
3854 sqlite3*,
3855 const char *zName,
3856 int eTextRep,
3857 void *pArg,
3858 int(*xCompare)(void*,int,const void*,int,const void*),
3859 void(*xDestroy)(void*)
3860 );
3861 SQLITE_API int sqlite3_create_collation16(
3862 sqlite3*,
3863 const void *zName,
3864 int eTextRep,
3865 void *pArg,
3866 int(*xCompare)(void*,int,const void*,int,const void*)
3867 );
3868
3869 /*
3870 ** CAPI3REF: Collation Needed Callbacks
@@ -3852,20 +3949,23 @@
3949 #endif
3950
3951 /*
3952 ** CAPI3REF: Suspend Execution For A Short Time
3953 **
3954 ** The sqlite3_sleep() function causes the current thread to suspend execution
3955 ** for at least a number of milliseconds specified in its parameter.
3956 **
3957 ** If the operating system does not support sleep requests with
3958 ** millisecond time resolution, then the time will be rounded up to
3959 ** the nearest second. The number of milliseconds of sleep actually
3960 ** requested from the operating system is returned.
3961 **
3962 ** ^SQLite implements this interface by calling the xSleep()
3963 ** method of the default [sqlite3_vfs] object. If the xSleep() method
3964 ** of the default VFS is not implemented correctly, or not implemented at
3965 ** all, then the behavior of sqlite3_sleep() may deviate from the description
3966 ** in the previous paragraphs.
3967 */
3968 SQLITE_API int sqlite3_sleep(int);
3969
3970 /*
3971 ** CAPI3REF: Name Of The Folder Holding Temporary Files
@@ -4083,44 +4183,77 @@
4183 ** of heap memory by deallocating non-essential memory allocations
4184 ** held by the database library. Memory used to cache database
4185 ** pages to improve performance is an example of non-essential memory.
4186 ** ^sqlite3_release_memory() returns the number of bytes actually freed,
4187 ** which might be more or less than the amount requested.
4188 ** ^The sqlite3_release_memory() routine is a no-op returning zero
4189 ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
4190 */
4191 SQLITE_API int sqlite3_release_memory(int);
4192
4193 /*
4194 ** CAPI3REF: Impose A Limit On Heap Size
4195 **
4196 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
4197 ** soft limit on the amount of heap memory that may be allocated by SQLite.
4198 ** ^SQLite strives to keep heap memory utilization below the soft heap
4199 ** limit by reducing the number of pages held in the page cache
4200 ** as heap memory usages approaches the limit.
4201 ** ^The soft heap limit is "soft" because even though SQLite strives to stay
4202 ** below the limit, it will exceed the limit rather than generate
4203 ** an [SQLITE_NOMEM] error. In other words, the soft heap limit
4204 ** is advisory only.
4205 **
4206 ** ^The return value from sqlite3_soft_heap_limit64() is the size of
4207 ** the soft heap limit prior to the call. ^If the argument N is negative
4208 ** then no change is made to the soft heap limit. Hence, the current
4209 ** size of the soft heap limit can be determined by invoking
4210 ** sqlite3_soft_heap_limit64() with a negative argument.
4211 **
4212 ** ^If the argument N is zero then the soft heap limit is disabled.
4213 **
4214 ** ^(The soft heap limit is not enforced in the current implementation
4215 ** if one or more of following conditions are true:
4216 **
4217 ** <ul>
4218 ** <li> The soft heap limit is set to zero.
4219 ** <li> Memory accounting is disabled using a combination of the
4220 ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
4221 ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
4222 ** <li> An alternative page cache implementation is specifed using
4223 ** [sqlite3_config]([SQLITE_CONFIG_PCACHE],...).
4224 ** <li> The page cache allocates from its own memory pool supplied
4225 ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
4226 ** from the heap.
4227 ** </ul>)^
4228 **
4229 ** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
4230 ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
4231 ** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
4232 ** the soft heap limit is enforced on every memory allocation. Without
4233 ** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
4234 ** when memory is allocated by the page cache. Testing suggests that because
4235 ** the page cache is the predominate memory user in SQLite, most
4236 ** applications will achieve adequate soft heap limit enforcement without
4237 ** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
4238 **
4239 ** The circumstances under which SQLite will enforce the soft heap limit may
4240 ** changes in future releases of SQLite.
4241 */
4242 SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
4243
4244 /*
4245 ** CAPI3REF: Deprecated Soft Heap Limit Interface
4246 ** DEPRECATED
4247 **
4248 ** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
4249 ** interface. This routine is provided for historical compatibility
4250 ** only. All new applications should use the
4251 ** [sqlite3_soft_heap_limit64()] interface rather than this one.
4252 */
4253 SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);
4254
4255
4256 /*
4257 ** CAPI3REF: Extract Metadata About A Column Of A Table
4258 **
4259 ** ^This routine returns metadata about a specific column of a specific
@@ -4240,38 +4373,51 @@
4373 ** it back off again.
4374 */
4375 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
4376
4377 /*
4378 ** CAPI3REF: Automatically Load Statically Linked Extensions
4379 **
4380 ** ^This interface causes the xEntryPoint() function to be invoked for
4381 ** each new [database connection] that is created. The idea here is that
4382 ** xEntryPoint() is the entry point for a statically linked SQLite extension
4383 ** that is to be automatically loaded into all new database connections.
4384 **
4385 ** ^(Even though the function prototype shows that xEntryPoint() takes
4386 ** no arguments and returns void, SQLite invokes xEntryPoint() with three
4387 ** arguments and expects and integer result as if the signature of the
4388 ** entry point where as follows:
4389 **
4390 ** <blockquote><pre>
4391 ** &nbsp; int xEntryPoint(
4392 ** &nbsp; sqlite3 *db,
4393 ** &nbsp; const char **pzErrMsg,
4394 ** &nbsp; const struct sqlite3_api_routines *pThunk
4395 ** &nbsp; );
4396 ** </pre></blockquote>)^
4397 **
4398 ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
4399 ** point to an appropriate error message (obtained from [sqlite3_mprintf()])
4400 ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg
4401 ** is NULL before calling the xEntryPoint(). ^SQLite will invoke
4402 ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any
4403 ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
4404 ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
4405 **
4406 ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
4407 ** on the list of automatic extensions is a harmless no-op. ^No entry point
4408 ** will be called more than once for each database connection that is opened.
4409 **
4410 ** See also: [sqlite3_reset_auto_extension()].
4411 */
4412 SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
4413
4414 /*
4415 ** CAPI3REF: Reset Automatic Extension Loading
4416 **
4417 ** ^This interface disables all automatic extensions previously
4418 ** registered using [sqlite3_auto_extension()].
 
 
 
4419 */
4420 SQLITE_API void sqlite3_reset_auto_extension(void);
4421
4422 /*
4423 ** The interface to the virtual-table mechanism is currently considered
@@ -4906,11 +5052,11 @@
5052 ** output variable when querying the system for the current mutex
5053 ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
5054 **
5055 ** ^The xMutexInit method defined by this structure is invoked as
5056 ** part of system initialization by the sqlite3_initialize() function.
5057 ** ^The xMutexInit routine is called by SQLite exactly once for each
5058 ** effective call to [sqlite3_initialize()].
5059 **
5060 ** ^The xMutexEnd method defined by this structure is invoked as
5061 ** part of system shutdown by the sqlite3_shutdown() function. The
5062 ** implementation of this method is expected to release all outstanding
@@ -5103,11 +5249,12 @@
5249 #define SQLITE_TESTCTRL_ALWAYS 13
5250 #define SQLITE_TESTCTRL_RESERVE 14
5251 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
5252 #define SQLITE_TESTCTRL_ISKEYWORD 16
5253 #define SQLITE_TESTCTRL_PGHDRSZ 17
5254 #define SQLITE_TESTCTRL_SCRATCHMALLOC 18
5255 #define SQLITE_TESTCTRL_LAST 18
5256
5257 /*
5258 ** CAPI3REF: SQLite Runtime Status
5259 **
5260 ** ^This interface is used to retrieve runtime status information
@@ -5122,11 +5269,11 @@
5269 ** value. For those parameters
5270 ** nothing is written into *pHighwater and the resetFlag is ignored.)^
5271 ** ^(Other parameters record only the highwater mark and not the current
5272 ** value. For these latter parameters nothing is written into *pCurrent.)^
5273 **
5274 ** ^The sqlite3_status() routine returns SQLITE_OK on success and a
5275 ** non-zero [error code] on failure.
5276 **
5277 ** This routine is threadsafe but is not atomic. This routine can be
5278 ** called while other threads are running the same or different SQLite
5279 ** interfaces. However the values returned in *pCurrent and
@@ -5172,11 +5319,11 @@
5319 ** [SQLITE_CONFIG_PAGECACHE]. The
5320 ** value returned is in pages, not in bytes.</dd>)^
5321 **
5322 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
5323 ** <dd>This parameter returns the number of bytes of page cache
5324 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
5325 ** buffer and where forced to overflow to [sqlite3_malloc()]. The
5326 ** returned value includes allocations that overflowed because they
5327 ** where too large (they were larger than the "sz" parameter to
5328 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
5329 ** no space was left in the page cache.</dd>)^
@@ -5195,11 +5342,11 @@
5342 ** outstanding at time, this parameter also reports the number of threads
5343 ** using scratch memory at the same time.</dd>)^
5344 **
5345 ** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
5346 ** <dd>This parameter returns the number of bytes of scratch memory
5347 ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
5348 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
5349 ** returned include overflows because the requested allocation was too
5350 ** larger (that is, because the requested allocation was larger than the
5351 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
5352 ** slots were available.
@@ -5243,10 +5390,13 @@
5390 **
5391 ** ^The current value of the requested parameter is written into *pCur
5392 ** and the highest instantaneous value is written into *pHiwtr. ^If
5393 ** the resetFlg is true, then the highest instantaneous value is
5394 ** reset back down to the current value.
5395 **
5396 ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
5397 ** non-zero [error code] on failure.
5398 **
5399 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
5400 */
5401 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5402
@@ -5370,122 +5520,134 @@
5520 ** CAPI3REF: Application Defined Page Cache.
5521 ** KEYWORDS: {page cache}
5522 **
5523 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
5524 ** register an alternative page cache implementation by passing in an
5525 ** instance of the sqlite3_pcache_methods structure.)^
5526 ** In many applications, most of the heap memory allocated by
5527 ** SQLite is used for the page cache.
5528 ** By implementing a
5529 ** custom page cache using this API, an application can better control
5530 ** the amount of memory consumed by SQLite, the way in which
5531 ** that memory is allocated and released, and the policies used to
5532 ** determine exactly which parts of a database file are cached and for
5533 ** how long.
5534 **
5535 ** The alternative page cache mechanism is an
5536 ** extreme measure that is only needed by the most demanding applications.
5537 ** The built-in page cache is recommended for most uses.
5538 **
5539 ** ^(The contents of the sqlite3_pcache_methods structure are copied to an
5540 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence
5541 ** the application may discard the parameter after the call to
5542 ** [sqlite3_config()] returns.)^
5543 **
5544 ** ^(The xInit() method is called once for each effective
5545 ** call to [sqlite3_initialize()])^
5546 ** (usually only once during the lifetime of the process). ^(The xInit()
5547 ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
5548 ** The intent of the xInit() method is to set up global data structures
5549 ** required by the custom page cache implementation.
5550 ** ^(If the xInit() method is NULL, then the
5551 ** built-in default page cache is used instead of the application defined
5552 ** page cache.)^
5553 **
5554 ** ^The xShutdown() method is called by [sqlite3_shutdown()].
5555 ** It can be used to clean up
5556 ** any outstanding resources before process shutdown, if required.
5557 ** ^The xShutdown() method may be NULL.
5558 **
5559 ** ^SQLite automatically serializes calls to the xInit method,
5560 ** so the xInit method need not be threadsafe. ^The
5561 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
5562 ** not need to be threadsafe either. All other methods must be threadsafe
5563 ** in multithreaded applications.
5564 **
5565 ** ^SQLite will never invoke xInit() more than once without an intervening
5566 ** call to xShutdown().
5567 **
5568 ** ^SQLite invokes the xCreate() method to construct a new cache instance.
5569 ** SQLite will typically create one cache instance for each open database file,
5570 ** though this is not guaranteed. ^The
5571 ** first parameter, szPage, is the size in bytes of the pages that must
5572 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage
5573 ** will the page size of the database file that is to be cached plus an
5574 ** increment (here called "R") of about 100 or 200. SQLite will use the
5575 ** extra R bytes on each page to store metadata about the underlying
5576 ** database page on disk. The value of R depends
5577 ** on the SQLite version, the target platform, and how SQLite was compiled.
5578 ** ^R is constant for a particular build of SQLite. ^The second argument to
5579 ** xCreate(), bPurgeable, is true if the cache being created will
5580 ** be used to cache database pages of a file stored on disk, or
5581 ** false if it is used for an in-memory database. The cache implementation
5582 ** does not have to do anything special based with the value of bPurgeable;
5583 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
5584 ** never invoke xUnpin() except to deliberately delete a page.
5585 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
5586 ** false will always have the "discard" flag set to true.
5587 ** ^Hence, a cache created with bPurgeable false will
5588 ** never contain any unpinned pages.
5589 **
5590 ** ^(The xCachesize() method may be called at any time by SQLite to set the
5591 ** suggested maximum cache-size (number of pages stored by) the cache
5592 ** instance passed as the first argument. This is the value configured using
5593 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
5594 ** parameter, the implementation is not required to do anything with this
5595 ** value; it is advisory only.
5596 **
5597 ** The xPagecount() method must return the number of pages currently
5598 ** stored in the cache, both pinned and unpinned.
5599 **
5600 ** The xFetch() method locates a page in the cache and returns a pointer to
5601 ** the page, or a NULL pointer.
5602 ** A "page", in this context, means a buffer of szPage bytes aligned at an
5603 ** 8-byte boundary. The page to be fetched is determined by the key. ^The
5604 ** mimimum key value is 1. After it has been retrieved using xFetch, the page
5605 ** is considered to be "pinned".
5606 **
5607 ** If the requested page is already in the page cache, then the page cache
5608 ** implementation must return a pointer to the page buffer with its content
5609 ** intact. If the requested page is not already in the cache, then the
5610 ** behavior of the cache implementation should use the value of the createFlag
5611 ** parameter to help it determined what action to take:
5612 **
5613 ** <table border=1 width=85% align=center>
5614 ** <tr><th> createFlag <th> Behaviour when page is not already in cache
5615 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
5616 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
5617 ** Otherwise return NULL.
5618 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
5619 ** NULL if allocating a new page is effectively impossible.
5620 ** </table>
5621 **
5622 ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
5623 ** will only use a createFlag of 2 after a prior call with a createFlag of 1
5624 ** failed.)^ In between the to xFetch() calls, SQLite may
5625 ** attempt to unpin one or more cache pages by spilling the content of
5626 ** pinned pages to disk and synching the operating system disk cache.
 
 
5627 **
5628 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
5629 ** as its second argument. If the third parameter, discard, is non-zero,
5630 ** then the page must be evicted from the cache.
5631 ** ^If the discard parameter is
5632 ** zero, then the page may be discarded or retained at the discretion of
5633 ** page cache implementation. ^The page cache implementation
5634 ** may choose to evict unpinned pages at any time.
5635 **
5636 ** The cache must not perform any reference counting. A single
5637 ** call to xUnpin() unpins the page regardless of the number of prior calls
5638 ** to xFetch().
5639 **
5640 ** The xRekey() method is used to change the key value associated with the
5641 ** page passed as the second argument. If the cache
5642 ** previously contains an entry associated with newKey, it must be
5643 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
5644 ** to be pinned.
5645 **
5646 ** When SQLite calls the xTruncate() method, the cache must discard all
5647 ** existing cache entries with page numbers (keys) greater than or equal
5648 ** to the value of the iLimit parameter passed to xTruncate(). If any
5649 ** of these pages are pinned, they are implicitly unpinned, meaning that
5650 ** they can be safely discarded.
5651 **
5652 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
5653 ** All resources associated with the specified cache should be freed. ^After
@@ -5959,5 +6121,61 @@
6121 #ifdef __cplusplus
6122 } /* End of the 'extern "C"' block */
6123 #endif
6124 #endif
6125
6126 /*
6127 ** 2010 August 30
6128 **
6129 ** The author disclaims copyright to this source code. In place of
6130 ** a legal notice, here is a blessing:
6131 **
6132 ** May you do good and not evil.
6133 ** May you find forgiveness for yourself and forgive others.
6134 ** May you share freely, never taking more than you give.
6135 **
6136 *************************************************************************
6137 */
6138
6139 #ifndef _SQLITE3RTREE_H_
6140 #define _SQLITE3RTREE_H_
6141
6142
6143 #ifdef __cplusplus
6144 extern "C" {
6145 #endif
6146
6147 typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
6148
6149 /*
6150 ** Register a geometry callback named zGeom that can be used as part of an
6151 ** R-Tree geometry query as follows:
6152 **
6153 ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
6154 */
6155 SQLITE_API int sqlite3_rtree_geometry_callback(
6156 sqlite3 *db,
6157 const char *zGeom,
6158 int (*xGeom)(sqlite3_rtree_geometry *, int nCoord, double *aCoord, int *pRes),
6159 void *pContext
6160 );
6161
6162
6163 /*
6164 ** A pointer to a structure of the following type is passed as the first
6165 ** argument to callbacks registered using rtree_geometry_callback().
6166 */
6167 struct sqlite3_rtree_geometry {
6168 void *pContext; /* Copy of pContext passed to s_r_g_c() */
6169 int nParam; /* Size of array aParam[] */
6170 double *aParam; /* Parameters passed to SQL geom function */
6171 void *pUser; /* Callback implementation user data */
6172 void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */
6173 };
6174
6175
6176 #ifdef __cplusplus
6177 } /* end of the 'extern "C"' block */
6178 #endif
6179
6180 #endif /* ifndef _SQLITE3RTREE_H_ */
6181
6182
+90 -10
--- src/style.c
+++ src/style.c
@@ -40,10 +40,15 @@
4040
** Remember that the header has been generated. The footer is omitted
4141
** if an error occurs before the header.
4242
*/
4343
static int headerHasBeenGenerated = 0;
4444
45
+/*
46
+** remember, if a sidebox was used
47
+*/
48
+static int sideboxUsed = 0;
49
+
4550
/*
4651
** Add a new element to the submenu
4752
*/
4853
void style_submenu_element(
4954
const char *zLabel,
@@ -106,10 +111,11 @@
106111
if( g.thTrace ) Th_Trace("END_HEADER<br />\n", -1);
107112
Th_Unstore("title"); /* Avoid collisions with ticket field names */
108113
cgi_destination(CGI_BODY);
109114
g.cgiOutput = 1;
110115
headerHasBeenGenerated = 1;
116
+ sideboxUsed = 0;
111117
}
112118
113119
/*
114120
** Draw the footer at the bottom of the page.
115121
*/
@@ -138,35 +144,38 @@
138144
@ </div>
139145
}
140146
@ <div class="content">
141147
cgi_destination(CGI_BODY);
142148
143
- /* Put the footer at the bottom of the page.
144
- ** the additional clear/both is needed to extend the content
145
- ** part to the end of an optional sidebox.
146
- */
147
- @ <div style="clear: both;"></div>
149
+ if (sideboxUsed) {
150
+ /* Put the footer at the bottom of the page.
151
+ ** the additional clear/both is needed to extend the content
152
+ ** part to the end of an optional sidebox.
153
+ */
154
+ @ <div class="endContent"></div>
155
+ }
148156
@ </div>
149157
zFooter = db_get("footer", (char*)zDefaultFooter);
150158
if( g.thTrace ) Th_Trace("BEGIN_FOOTER<br />\n", -1);
151159
Th_Render(zFooter);
152160
if( g.thTrace ) Th_Trace("END_FOOTER<br />\n", -1);
153161
154162
/* Render trace log if TH1 tracing is enabled. */
155163
if( g.thTrace ){
156
- cgi_append_content("<font color=\"red\"><hr />\n", -1);
164
+ cgi_append_content("<span class=\"thTrace\"><hr />\n", -1);
157165
cgi_append_content(blob_str(&g.thLog), blob_size(&g.thLog));
158
- cgi_append_content("</font>\n", -1);
166
+ cgi_append_content("</span>\n", -1);
159167
}
160168
}
161169
162170
/*
163171
** Begin a side-box on the right-hand side of a page. The title and
164172
** the width of the box are given as arguments. The width is usually
165173
** a percentage of total screen width.
166174
*/
167175
void style_sidebox_begin(const char *zTitle, const char *zWidth){
176
+ sideboxUsed = 1;
168177
@ <div class="sidebox" style="width:%s(zWidth)">
169178
@ <div class="sideboxTitle">%h(zTitle)</div>
170179
}
171180
172181
/* End the side-box
@@ -189,11 +198,11 @@
189198
@ media="screen" />
190199
@ </head>
191200
@ <body>
192201
@ <div class="header">
193202
@ <div class="logo">
194
-@ <img src="$baseurl/logo" alt="logo">
203
+@ <img src="$baseurl/logo" alt="logo" />
195204
@ </div>
196205
@ <div class="title"><small>$<project_name></small><br />$<title></div>
197206
@ <div class="status"><th1>
198207
@ if {[info exists login]} {
199208
@ puts "Logged in as $login"
@@ -360,10 +369,11 @@
360369
@ white-space: nowrap;
361370
@ }
362371
@
363372
@ /* The footer at the very bottom of the page */
364373
@ div.footer {
374
+@ clear: both;
365375
@ font-size: 0.8em;
366376
@ margin-top: 12px;
367377
@ padding: 5px 10px 5px 10px;
368378
@ text-align: right;
369379
@ background-color: #558195;
@@ -521,13 +531,13 @@
521531
},
522532
{ "table.captcha",
523533
"format for the layout table, used for the captcha display",
524534
@ margin: auto;
525535
@ padding: 10px;
526
- @ border-width: 1;
536
+ @ border-width: 4px;
527537
@ border-style: double;
528
- @ bordor-color: black;
538
+ @ border-color: black;
529539
},
530540
{ "td.login_out_label",
531541
"format for the label cells in the login/out table",
532542
@ text-align: center;
533543
},
@@ -629,10 +639,14 @@
629639
@ content:"'";
630640
},
631641
{ "span.usertype:after",
632642
"trailing text for user types, mentioned on the user edit page",
633643
@ content:"'";
644
+ },
645
+ { "p.missingPriv",
646
+ "format for missing priviliges note on user setup page",
647
+ @ color: blue;
634648
},
635649
{ "span.wikiruleHead",
636650
"format for leading text in wikirules definitions",
637651
@ font-weight: bold;
638652
},
@@ -648,10 +662,76 @@
648662
},
649663
{ "span.tktError",
650664
"format for ticket error messages",
651665
@ color: red;
652666
@ font-weight: bold;
667
+ },
668
+ { "table.rpteditex",
669
+ "format for example tables on the report edit page",
670
+ @ float: right;
671
+ @ margin: 0;
672
+ @ padding: 0;
673
+ @ width: 125px;
674
+ @ text-align: center;
675
+ @ border-collapse: collapse;
676
+ @ border-spacing: 0;
677
+ },
678
+ { "td.rpteditex",
679
+ "format for example table cells on the report edit page",
680
+ @ border-width: thin;
681
+ @ border-color: #000000;
682
+ @ border-style: solid;
683
+ },
684
+ { "input.checkinUserColor",
685
+ "format for user color input on checkin edit page",
686
+ @ # no special definitions, class defined, to enable color pickers, f.e.:
687
+ @ # add the color picker found at http:jscolor.com as java script include
688
+ @ # to the header and configure the java script file with
689
+ @ # 1. use as bindClass :checkinUserColor
690
+ @ # 2. change the default hash adding behaviour to ON
691
+ @ # or change the class defition of element identified by id="clrcust"
692
+ @ # to a standard jscolor definition with java script in the footer.
693
+ },
694
+ { "div.endContent",
695
+ "format for end of content area, to be used to clear page flow(sidebox on branch,..",
696
+ @ clear: both;
697
+ },
698
+ { "p.generalError",
699
+ "format for general errors",
700
+ @ color: red;
701
+ },
702
+ { "p.tktsetupError",
703
+ "format for tktsetup errors",
704
+ @ color: red;
705
+ @ font-weight: bold;
706
+ },
707
+ { "p.thmainError",
708
+ "format for th script errors",
709
+ @ color: red;
710
+ @ font-weight: bold;
711
+ },
712
+ { "span.thTrace",
713
+ "format for th script trace messages",
714
+ @ color: red;
715
+ },
716
+ { "p:reportError",
717
+ "format for report configuration errors",
718
+ @ color: red;
719
+ @ font-weight: bold;
720
+ },
721
+ { "blockquote.reportError",
722
+ "format for report configuration errors",
723
+ @ color: red;
724
+ @ font-weight: bold;
725
+ },
726
+ { "p.noMoreShun",
727
+ "format for artifact lines, no longer shunned",
728
+ @ color: blue;
729
+ },
730
+ { "p.shunned",
731
+ "format for artifact lines beeing shunned",
732
+ @ color: blue;
653733
},
654734
{ 0,
655735
0,
656736
0
657737
}
658738
--- src/style.c
+++ src/style.c
@@ -40,10 +40,15 @@
40 ** Remember that the header has been generated. The footer is omitted
41 ** if an error occurs before the header.
42 */
43 static int headerHasBeenGenerated = 0;
44
 
 
 
 
 
45 /*
46 ** Add a new element to the submenu
47 */
48 void style_submenu_element(
49 const char *zLabel,
@@ -106,10 +111,11 @@
106 if( g.thTrace ) Th_Trace("END_HEADER<br />\n", -1);
107 Th_Unstore("title"); /* Avoid collisions with ticket field names */
108 cgi_destination(CGI_BODY);
109 g.cgiOutput = 1;
110 headerHasBeenGenerated = 1;
 
111 }
112
113 /*
114 ** Draw the footer at the bottom of the page.
115 */
@@ -138,35 +144,38 @@
138 @ </div>
139 }
140 @ <div class="content">
141 cgi_destination(CGI_BODY);
142
143 /* Put the footer at the bottom of the page.
144 ** the additional clear/both is needed to extend the content
145 ** part to the end of an optional sidebox.
146 */
147 @ <div style="clear: both;"></div>
 
 
148 @ </div>
149 zFooter = db_get("footer", (char*)zDefaultFooter);
150 if( g.thTrace ) Th_Trace("BEGIN_FOOTER<br />\n", -1);
151 Th_Render(zFooter);
152 if( g.thTrace ) Th_Trace("END_FOOTER<br />\n", -1);
153
154 /* Render trace log if TH1 tracing is enabled. */
155 if( g.thTrace ){
156 cgi_append_content("<font color=\"red\"><hr />\n", -1);
157 cgi_append_content(blob_str(&g.thLog), blob_size(&g.thLog));
158 cgi_append_content("</font>\n", -1);
159 }
160 }
161
162 /*
163 ** Begin a side-box on the right-hand side of a page. The title and
164 ** the width of the box are given as arguments. The width is usually
165 ** a percentage of total screen width.
166 */
167 void style_sidebox_begin(const char *zTitle, const char *zWidth){
 
168 @ <div class="sidebox" style="width:%s(zWidth)">
169 @ <div class="sideboxTitle">%h(zTitle)</div>
170 }
171
172 /* End the side-box
@@ -189,11 +198,11 @@
189 @ media="screen" />
190 @ </head>
191 @ <body>
192 @ <div class="header">
193 @ <div class="logo">
194 @ <img src="$baseurl/logo" alt="logo">
195 @ </div>
196 @ <div class="title"><small>$<project_name></small><br />$<title></div>
197 @ <div class="status"><th1>
198 @ if {[info exists login]} {
199 @ puts "Logged in as $login"
@@ -360,10 +369,11 @@
360 @ white-space: nowrap;
361 @ }
362 @
363 @ /* The footer at the very bottom of the page */
364 @ div.footer {
 
365 @ font-size: 0.8em;
366 @ margin-top: 12px;
367 @ padding: 5px 10px 5px 10px;
368 @ text-align: right;
369 @ background-color: #558195;
@@ -521,13 +531,13 @@
521 },
522 { "table.captcha",
523 "format for the layout table, used for the captcha display",
524 @ margin: auto;
525 @ padding: 10px;
526 @ border-width: 1;
527 @ border-style: double;
528 @ bordor-color: black;
529 },
530 { "td.login_out_label",
531 "format for the label cells in the login/out table",
532 @ text-align: center;
533 },
@@ -629,10 +639,14 @@
629 @ content:"'";
630 },
631 { "span.usertype:after",
632 "trailing text for user types, mentioned on the user edit page",
633 @ content:"'";
 
 
 
 
634 },
635 { "span.wikiruleHead",
636 "format for leading text in wikirules definitions",
637 @ font-weight: bold;
638 },
@@ -648,10 +662,76 @@
648 },
649 { "span.tktError",
650 "format for ticket error messages",
651 @ color: red;
652 @ font-weight: bold;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
653 },
654 { 0,
655 0,
656 0
657 }
658
--- src/style.c
+++ src/style.c
@@ -40,10 +40,15 @@
40 ** Remember that the header has been generated. The footer is omitted
41 ** if an error occurs before the header.
42 */
43 static int headerHasBeenGenerated = 0;
44
45 /*
46 ** remember, if a sidebox was used
47 */
48 static int sideboxUsed = 0;
49
50 /*
51 ** Add a new element to the submenu
52 */
53 void style_submenu_element(
54 const char *zLabel,
@@ -106,10 +111,11 @@
111 if( g.thTrace ) Th_Trace("END_HEADER<br />\n", -1);
112 Th_Unstore("title"); /* Avoid collisions with ticket field names */
113 cgi_destination(CGI_BODY);
114 g.cgiOutput = 1;
115 headerHasBeenGenerated = 1;
116 sideboxUsed = 0;
117 }
118
119 /*
120 ** Draw the footer at the bottom of the page.
121 */
@@ -138,35 +144,38 @@
144 @ </div>
145 }
146 @ <div class="content">
147 cgi_destination(CGI_BODY);
148
149 if (sideboxUsed) {
150 /* Put the footer at the bottom of the page.
151 ** the additional clear/both is needed to extend the content
152 ** part to the end of an optional sidebox.
153 */
154 @ <div class="endContent"></div>
155 }
156 @ </div>
157 zFooter = db_get("footer", (char*)zDefaultFooter);
158 if( g.thTrace ) Th_Trace("BEGIN_FOOTER<br />\n", -1);
159 Th_Render(zFooter);
160 if( g.thTrace ) Th_Trace("END_FOOTER<br />\n", -1);
161
162 /* Render trace log if TH1 tracing is enabled. */
163 if( g.thTrace ){
164 cgi_append_content("<span class=\"thTrace\"><hr />\n", -1);
165 cgi_append_content(blob_str(&g.thLog), blob_size(&g.thLog));
166 cgi_append_content("</span>\n", -1);
167 }
168 }
169
170 /*
171 ** Begin a side-box on the right-hand side of a page. The title and
172 ** the width of the box are given as arguments. The width is usually
173 ** a percentage of total screen width.
174 */
175 void style_sidebox_begin(const char *zTitle, const char *zWidth){
176 sideboxUsed = 1;
177 @ <div class="sidebox" style="width:%s(zWidth)">
178 @ <div class="sideboxTitle">%h(zTitle)</div>
179 }
180
181 /* End the side-box
@@ -189,11 +198,11 @@
198 @ media="screen" />
199 @ </head>
200 @ <body>
201 @ <div class="header">
202 @ <div class="logo">
203 @ <img src="$baseurl/logo" alt="logo" />
204 @ </div>
205 @ <div class="title"><small>$<project_name></small><br />$<title></div>
206 @ <div class="status"><th1>
207 @ if {[info exists login]} {
208 @ puts "Logged in as $login"
@@ -360,10 +369,11 @@
369 @ white-space: nowrap;
370 @ }
371 @
372 @ /* The footer at the very bottom of the page */
373 @ div.footer {
374 @ clear: both;
375 @ font-size: 0.8em;
376 @ margin-top: 12px;
377 @ padding: 5px 10px 5px 10px;
378 @ text-align: right;
379 @ background-color: #558195;
@@ -521,13 +531,13 @@
531 },
532 { "table.captcha",
533 "format for the layout table, used for the captcha display",
534 @ margin: auto;
535 @ padding: 10px;
536 @ border-width: 4px;
537 @ border-style: double;
538 @ border-color: black;
539 },
540 { "td.login_out_label",
541 "format for the label cells in the login/out table",
542 @ text-align: center;
543 },
@@ -629,10 +639,14 @@
639 @ content:"'";
640 },
641 { "span.usertype:after",
642 "trailing text for user types, mentioned on the user edit page",
643 @ content:"'";
644 },
645 { "p.missingPriv",
646 "format for missing priviliges note on user setup page",
647 @ color: blue;
648 },
649 { "span.wikiruleHead",
650 "format for leading text in wikirules definitions",
651 @ font-weight: bold;
652 },
@@ -648,10 +662,76 @@
662 },
663 { "span.tktError",
664 "format for ticket error messages",
665 @ color: red;
666 @ font-weight: bold;
667 },
668 { "table.rpteditex",
669 "format for example tables on the report edit page",
670 @ float: right;
671 @ margin: 0;
672 @ padding: 0;
673 @ width: 125px;
674 @ text-align: center;
675 @ border-collapse: collapse;
676 @ border-spacing: 0;
677 },
678 { "td.rpteditex",
679 "format for example table cells on the report edit page",
680 @ border-width: thin;
681 @ border-color: #000000;
682 @ border-style: solid;
683 },
684 { "input.checkinUserColor",
685 "format for user color input on checkin edit page",
686 @ # no special definitions, class defined, to enable color pickers, f.e.:
687 @ # add the color picker found at http:jscolor.com as java script include
688 @ # to the header and configure the java script file with
689 @ # 1. use as bindClass :checkinUserColor
690 @ # 2. change the default hash adding behaviour to ON
691 @ # or change the class defition of element identified by id="clrcust"
692 @ # to a standard jscolor definition with java script in the footer.
693 },
694 { "div.endContent",
695 "format for end of content area, to be used to clear page flow(sidebox on branch,..",
696 @ clear: both;
697 },
698 { "p.generalError",
699 "format for general errors",
700 @ color: red;
701 },
702 { "p.tktsetupError",
703 "format for tktsetup errors",
704 @ color: red;
705 @ font-weight: bold;
706 },
707 { "p.thmainError",
708 "format for th script errors",
709 @ color: red;
710 @ font-weight: bold;
711 },
712 { "span.thTrace",
713 "format for th script trace messages",
714 @ color: red;
715 },
716 { "p:reportError",
717 "format for report configuration errors",
718 @ color: red;
719 @ font-weight: bold;
720 },
721 { "blockquote.reportError",
722 "format for report configuration errors",
723 @ color: red;
724 @ font-weight: bold;
725 },
726 { "p.noMoreShun",
727 "format for artifact lines, no longer shunned",
728 @ color: blue;
729 },
730 { "p.shunned",
731 "format for artifact lines beeing shunned",
732 @ color: blue;
733 },
734 { 0,
735 0,
736 0
737 }
738
+14 -5
--- src/tag.c
+++ src/tag.c
@@ -258,11 +258,13 @@
258258
void tag_add_artifact(
259259
const char *zPrefix, /* Prefix to prepend to tag name */
260260
const char *zTagname, /* The tag to add or cancel */
261261
const char *zObjName, /* Name of object attached to */
262262
const char *zValue, /* Value for the tag. Might be NULL */
263
- int tagtype /* 0:cancel 1:singleton 2:propagated */
263
+ int tagtype, /* 0:cancel 1:singleton 2:propagated */
264
+ const char *zDateOvrd, /* Override date string */
265
+ const char *zUserOvrd /* Override user name */
264266
){
265267
int rid;
266268
int nrid;
267269
char *zDate;
268270
Blob uuid;
@@ -289,21 +291,21 @@
289291
" a hexadecimal artifact ID",
290292
zTagname
291293
);
292294
}
293295
#endif
294
- zDate = db_text(0, "SELECT datetime('now')");
296
+ zDate = date_in_standard_format(zDateOvrd ? zDateOvrd : "now");
295297
zDate[10] = 'T';
296298
blob_appendf(&ctrl, "D %s\n", zDate);
297299
blob_appendf(&ctrl, "T %c%s%F %b",
298300
zTagtype[tagtype], zPrefix, zTagname, &uuid);
299301
if( tagtype>0 && zValue && zValue[0] ){
300302
blob_appendf(&ctrl, " %F\n", zValue);
301303
}else{
302304
blob_appendf(&ctrl, "\n");
303305
}
304
- blob_appendf(&ctrl, "U %F\n", g.zLogin);
306
+ blob_appendf(&ctrl, "U %F\n", zUserOvrd ? zUserOvrd : g.zLogin);
305307
md5sum_blob(&ctrl, &cksum);
306308
blob_appendf(&ctrl, "Z %b\n", &cksum);
307309
nrid = content_put(&ctrl, 0, 0);
308310
manifest_crosslink(nrid, &ctrl);
309311
}
@@ -352,10 +354,14 @@
352354
**
353355
** fossil update tag:decaf
354356
**
355357
** will assume that "decaf" is a tag/branch name.
356358
**
359
+** only allow --date-override and --user-override in
360
+** %fossil tag add --date-override 'YYYY-MMM-DD HH:MM:SS' \
361
+** --user-override user
362
+** in order to import history from other scm systems
357363
*/
358364
void tag_cmd(void){
359365
int n;
360366
int fRaw = find_option("raw","",0)!=0;
361367
int fPropagate = find_option("propagate","",0)!=0;
@@ -370,16 +376,19 @@
370376
goto tag_cmd_usage;
371377
}
372378
373379
if( strncmp(g.argv[2],"add",n)==0 ){
374380
char *zValue;
381
+ const char *zDateOvrd = find_option("date-override",0,1);
382
+ const char *zUserOvrd = find_option("user-override",0,1);
375383
if( g.argc!=5 && g.argc!=6 ){
376384
usage("add ?--raw? ?--propagate? TAGNAME CHECK-IN ?VALUE?");
377385
}
378386
zValue = g.argc==6 ? g.argv[5] : 0;
379387
db_begin_transaction();
380
- tag_add_artifact(zPrefix, g.argv[3], g.argv[4], zValue, 1+fPropagate);
388
+ tag_add_artifact(zPrefix, g.argv[3], g.argv[4], zValue,
389
+ 1+fPropagate,zDateOvrd,zUserOvrd);
381390
db_end_transaction(0);
382391
}else
383392
384393
if( strncmp(g.argv[2],"branch",n)==0 ){
385394
fossil_fatal("the \"fossil tag branch\" command is discontinued\n"
@@ -389,11 +398,11 @@
389398
if( strncmp(g.argv[2],"cancel",n)==0 ){
390399
if( g.argc!=5 ){
391400
usage("cancel ?--raw? TAGNAME CHECK-IN");
392401
}
393402
db_begin_transaction();
394
- tag_add_artifact(zPrefix, g.argv[3], g.argv[4], 0, 0);
403
+ tag_add_artifact(zPrefix, g.argv[3], g.argv[4], 0, 0, 0, 0);
395404
db_end_transaction(0);
396405
}else
397406
398407
if( strncmp(g.argv[2],"find",n)==0 ){
399408
Stmt q;
400409
--- src/tag.c
+++ src/tag.c
@@ -258,11 +258,13 @@
258 void tag_add_artifact(
259 const char *zPrefix, /* Prefix to prepend to tag name */
260 const char *zTagname, /* The tag to add or cancel */
261 const char *zObjName, /* Name of object attached to */
262 const char *zValue, /* Value for the tag. Might be NULL */
263 int tagtype /* 0:cancel 1:singleton 2:propagated */
 
 
264 ){
265 int rid;
266 int nrid;
267 char *zDate;
268 Blob uuid;
@@ -289,21 +291,21 @@
289 " a hexadecimal artifact ID",
290 zTagname
291 );
292 }
293 #endif
294 zDate = db_text(0, "SELECT datetime('now')");
295 zDate[10] = 'T';
296 blob_appendf(&ctrl, "D %s\n", zDate);
297 blob_appendf(&ctrl, "T %c%s%F %b",
298 zTagtype[tagtype], zPrefix, zTagname, &uuid);
299 if( tagtype>0 && zValue && zValue[0] ){
300 blob_appendf(&ctrl, " %F\n", zValue);
301 }else{
302 blob_appendf(&ctrl, "\n");
303 }
304 blob_appendf(&ctrl, "U %F\n", g.zLogin);
305 md5sum_blob(&ctrl, &cksum);
306 blob_appendf(&ctrl, "Z %b\n", &cksum);
307 nrid = content_put(&ctrl, 0, 0);
308 manifest_crosslink(nrid, &ctrl);
309 }
@@ -352,10 +354,14 @@
352 **
353 ** fossil update tag:decaf
354 **
355 ** will assume that "decaf" is a tag/branch name.
356 **
 
 
 
 
357 */
358 void tag_cmd(void){
359 int n;
360 int fRaw = find_option("raw","",0)!=0;
361 int fPropagate = find_option("propagate","",0)!=0;
@@ -370,16 +376,19 @@
370 goto tag_cmd_usage;
371 }
372
373 if( strncmp(g.argv[2],"add",n)==0 ){
374 char *zValue;
 
 
375 if( g.argc!=5 && g.argc!=6 ){
376 usage("add ?--raw? ?--propagate? TAGNAME CHECK-IN ?VALUE?");
377 }
378 zValue = g.argc==6 ? g.argv[5] : 0;
379 db_begin_transaction();
380 tag_add_artifact(zPrefix, g.argv[3], g.argv[4], zValue, 1+fPropagate);
 
381 db_end_transaction(0);
382 }else
383
384 if( strncmp(g.argv[2],"branch",n)==0 ){
385 fossil_fatal("the \"fossil tag branch\" command is discontinued\n"
@@ -389,11 +398,11 @@
389 if( strncmp(g.argv[2],"cancel",n)==0 ){
390 if( g.argc!=5 ){
391 usage("cancel ?--raw? TAGNAME CHECK-IN");
392 }
393 db_begin_transaction();
394 tag_add_artifact(zPrefix, g.argv[3], g.argv[4], 0, 0);
395 db_end_transaction(0);
396 }else
397
398 if( strncmp(g.argv[2],"find",n)==0 ){
399 Stmt q;
400
--- src/tag.c
+++ src/tag.c
@@ -258,11 +258,13 @@
258 void tag_add_artifact(
259 const char *zPrefix, /* Prefix to prepend to tag name */
260 const char *zTagname, /* The tag to add or cancel */
261 const char *zObjName, /* Name of object attached to */
262 const char *zValue, /* Value for the tag. Might be NULL */
263 int tagtype, /* 0:cancel 1:singleton 2:propagated */
264 const char *zDateOvrd, /* Override date string */
265 const char *zUserOvrd /* Override user name */
266 ){
267 int rid;
268 int nrid;
269 char *zDate;
270 Blob uuid;
@@ -289,21 +291,21 @@
291 " a hexadecimal artifact ID",
292 zTagname
293 );
294 }
295 #endif
296 zDate = date_in_standard_format(zDateOvrd ? zDateOvrd : "now");
297 zDate[10] = 'T';
298 blob_appendf(&ctrl, "D %s\n", zDate);
299 blob_appendf(&ctrl, "T %c%s%F %b",
300 zTagtype[tagtype], zPrefix, zTagname, &uuid);
301 if( tagtype>0 && zValue && zValue[0] ){
302 blob_appendf(&ctrl, " %F\n", zValue);
303 }else{
304 blob_appendf(&ctrl, "\n");
305 }
306 blob_appendf(&ctrl, "U %F\n", zUserOvrd ? zUserOvrd : g.zLogin);
307 md5sum_blob(&ctrl, &cksum);
308 blob_appendf(&ctrl, "Z %b\n", &cksum);
309 nrid = content_put(&ctrl, 0, 0);
310 manifest_crosslink(nrid, &ctrl);
311 }
@@ -352,10 +354,14 @@
354 **
355 ** fossil update tag:decaf
356 **
357 ** will assume that "decaf" is a tag/branch name.
358 **
359 ** only allow --date-override and --user-override in
360 ** %fossil tag add --date-override 'YYYY-MMM-DD HH:MM:SS' \
361 ** --user-override user
362 ** in order to import history from other scm systems
363 */
364 void tag_cmd(void){
365 int n;
366 int fRaw = find_option("raw","",0)!=0;
367 int fPropagate = find_option("propagate","",0)!=0;
@@ -370,16 +376,19 @@
376 goto tag_cmd_usage;
377 }
378
379 if( strncmp(g.argv[2],"add",n)==0 ){
380 char *zValue;
381 const char *zDateOvrd = find_option("date-override",0,1);
382 const char *zUserOvrd = find_option("user-override",0,1);
383 if( g.argc!=5 && g.argc!=6 ){
384 usage("add ?--raw? ?--propagate? TAGNAME CHECK-IN ?VALUE?");
385 }
386 zValue = g.argc==6 ? g.argv[5] : 0;
387 db_begin_transaction();
388 tag_add_artifact(zPrefix, g.argv[3], g.argv[4], zValue,
389 1+fPropagate,zDateOvrd,zUserOvrd);
390 db_end_transaction(0);
391 }else
392
393 if( strncmp(g.argv[2],"branch",n)==0 ){
394 fossil_fatal("the \"fossil tag branch\" command is discontinued\n"
@@ -389,11 +398,11 @@
398 if( strncmp(g.argv[2],"cancel",n)==0 ){
399 if( g.argc!=5 ){
400 usage("cancel ?--raw? TAGNAME CHECK-IN");
401 }
402 db_begin_transaction();
403 tag_add_artifact(zPrefix, g.argv[3], g.argv[4], 0, 0, 0, 0);
404 db_end_transaction(0);
405 }else
406
407 if( strncmp(g.argv[2],"find",n)==0 ){
408 Stmt q;
409
+2 -2
--- src/th_main.c
+++ src/th_main.c
@@ -504,14 +504,14 @@
504504
}else{
505505
i++;
506506
}
507507
}
508508
if( rc==TH_ERROR ){
509
- sendText("<hr><p><font color=\"red\"><b>ERROR: ", -1, 0);
509
+ sendText("<hr><p class=\"thmainError\">ERROR: ", -1, 0);
510510
zResult = (char*)Th_GetResult(g.interp, &n);
511511
sendText((char*)zResult, n, 1);
512
- sendText("</b></font></p>", -1, 0);
512
+ sendText("</p>", -1, 0);
513513
}else{
514514
sendText(z, i, 0);
515515
}
516516
return rc;
517517
}
518518
--- src/th_main.c
+++ src/th_main.c
@@ -504,14 +504,14 @@
504 }else{
505 i++;
506 }
507 }
508 if( rc==TH_ERROR ){
509 sendText("<hr><p><font color=\"red\"><b>ERROR: ", -1, 0);
510 zResult = (char*)Th_GetResult(g.interp, &n);
511 sendText((char*)zResult, n, 1);
512 sendText("</b></font></p>", -1, 0);
513 }else{
514 sendText(z, i, 0);
515 }
516 return rc;
517 }
518
--- src/th_main.c
+++ src/th_main.c
@@ -504,14 +504,14 @@
504 }else{
505 i++;
506 }
507 }
508 if( rc==TH_ERROR ){
509 sendText("<hr><p class=\"thmainError\">ERROR: ", -1, 0);
510 zResult = (char*)Th_GetResult(g.interp, &n);
511 sendText((char*)zResult, n, 1);
512 sendText("</p>", -1, 0);
513 }else{
514 sendText(z, i, 0);
515 }
516 return rc;
517 }
518
+16 -8
--- src/timeline.c
+++ src/timeline.c
@@ -165,11 +165,11 @@
165165
** 4. User
166166
** 5. True if is a leaf
167167
** 6. background color
168168
** 7. type ("ci", "w", "t")
169169
** 8. list of symbolic tags.
170
-** 9. tagid for ticket or wiki
170
+** 9. tagid for ticket or wiki or event
171171
** 10. Short comment to user for repeated tickets and wiki
172172
*/
173173
void www_print_timeline(
174174
Stmt *pQuery, /* Query to implement the timeline */
175175
int tmFlags, /* Flags controlling display behavior */
@@ -288,10 +288,12 @@
288288
@ <span class="timelineLeaf">Closed-Leaf:</span>
289289
}else{
290290
@ <span class="timelineLeaf">Leaf:</span>
291291
}
292292
}
293
+ }else if( zType[0]=='e' && tagid ){
294
+ hyperlink_to_event_tagid(tagid);
293295
}else if( (tmFlags & TIMELINE_ARTID)!=0 ){
294296
hyperlink_to_uuid(zUuid);
295297
}
296298
db_column_blob(pQuery, commentColumn, &comment);
297299
if( mxWikiLen>0 && blob_size(&comment)>mxWikiLen ){
@@ -639,11 +641,11 @@
639641
** p=RID artifact RID and up to COUNT parents and ancestors
640642
** d=RID artifact RID and up to COUNT descendants
641643
** t=TAGID show only check-ins with the given tagid
642644
** r=TAGID show check-ins related to tagid
643645
** u=USER only if belonging to this user
644
-** y=TYPE 'ci', 'w', 't'
646
+** y=TYPE 'ci', 'w', 't', 'e'
645647
** s=TEXT string search (comment and brief)
646648
** ng Suppress the graph if present
647649
**
648650
** p= and d= can appear individually or together. If either p= or d=
649651
** appear, then u=, y=, a=, and b= are ignored.
@@ -749,22 +751,22 @@
749751
}else{
750752
blob_appendf(&desc, " of check-in [%.10s]", zUuid);
751753
}
752754
}else{
753755
int n;
754
- const char *zEType = "event";
756
+ const char *zEType = "timeline item";
755757
char *zDate;
756758
char *zNEntry = mprintf("%d", nEntry);
757759
url_initialize(&url, "timeline");
758760
url_add_parameter(&url, "n", zNEntry);
759761
if( tagid>0 ){
760
- zType = "ci";
762
+ if( zType[0]!='e' ) zType = "ci";
761763
blob_appendf(&sql,
762764
"AND (EXISTS(SELECT 1 FROM tagxref"
763765
" WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)", tagid);
764766
765
- if( zBrName ){
767
+ if( zBrName && zType[0]=='c' ){
766768
/* The next two blob_appendf() calls add SQL that causes checkins that
767769
** are not part of the branch which are parents or childen of the branch
768770
** to be included in the report. This related check-ins are useful
769771
** in helping to visualize what has happened on a quiescent branch
770772
** that is infrequently merged with a much more activate branch.
@@ -781,10 +783,11 @@
781783
}
782784
blob_appendf(&sql, ")");
783785
}
784786
if( (zType[0]=='w' && !g.okRdWiki)
785787
|| (zType[0]=='t' && !g.okRdTkt)
788
+ || (zType[0]=='e' && !g.okRdWiki)
786789
|| (zType[0]=='c' && !g.okRead)
787790
){
788791
zType = "all";
789792
}
790793
if( zType[0]=='a' ){
@@ -794,11 +797,11 @@
794797
if( g.okRead ){
795798
blob_appendf(&sql, "%c'ci'", cSep);
796799
cSep = ',';
797800
}
798801
if( g.okRdWiki ){
799
- blob_appendf(&sql, "%c'w'", cSep);
802
+ blob_appendf(&sql, "%c'w','e'", cSep);
800803
cSep = ',';
801804
}
802805
if( g.okRdTkt ){
803806
blob_appendf(&sql, "%c't'", cSep);
804807
cSep = ',';
@@ -812,10 +815,12 @@
812815
zEType = "checkin";
813816
}else if( zType[0]=='w' ){
814817
zEType = "wiki edit";
815818
}else if( zType[0]=='t' ){
816819
zEType = "ticket change";
820
+ }else if( zType[0]=='e' ){
821
+ zEType = "event";
817822
}
818823
}
819824
if( zUser ){
820825
blob_appendf(&sql, " AND event.user=%Q", zUser);
821826
url_add_parameter(&url, "u", zUser);
@@ -926,16 +931,19 @@
926931
timeline_submenu(&url, "Checkins Only", "y", "ci", 0);
927932
}
928933
if( zType[0]!='t' && g.okRdTkt ){
929934
timeline_submenu(&url, "Tickets Only", "y", "t", 0);
930935
}
936
+ if( zType[0]!='e' && g.okRdWiki ){
937
+ timeline_submenu(&url, "Events Only", "y", "e", 0);
938
+ }
931939
}
932940
if( nEntry>20 ){
933
- timeline_submenu(&url, "20 Events", "n", "20", 0);
941
+ timeline_submenu(&url, "20 Entries", "n", "20", 0);
934942
}
935943
if( nEntry<200 ){
936
- timeline_submenu(&url, "200 Events", "n", "200", 0);
944
+ timeline_submenu(&url, "200 Entries", "n", "200", 0);
937945
}
938946
}
939947
}
940948
blob_zero(&sql);
941949
db_prepare(&q, "SELECT * FROM timeline ORDER BY timestamp DESC /*scan*/");
942950
--- src/timeline.c
+++ src/timeline.c
@@ -165,11 +165,11 @@
165 ** 4. User
166 ** 5. True if is a leaf
167 ** 6. background color
168 ** 7. type ("ci", "w", "t")
169 ** 8. list of symbolic tags.
170 ** 9. tagid for ticket or wiki
171 ** 10. Short comment to user for repeated tickets and wiki
172 */
173 void www_print_timeline(
174 Stmt *pQuery, /* Query to implement the timeline */
175 int tmFlags, /* Flags controlling display behavior */
@@ -288,10 +288,12 @@
288 @ <span class="timelineLeaf">Closed-Leaf:</span>
289 }else{
290 @ <span class="timelineLeaf">Leaf:</span>
291 }
292 }
 
 
293 }else if( (tmFlags & TIMELINE_ARTID)!=0 ){
294 hyperlink_to_uuid(zUuid);
295 }
296 db_column_blob(pQuery, commentColumn, &comment);
297 if( mxWikiLen>0 && blob_size(&comment)>mxWikiLen ){
@@ -639,11 +641,11 @@
639 ** p=RID artifact RID and up to COUNT parents and ancestors
640 ** d=RID artifact RID and up to COUNT descendants
641 ** t=TAGID show only check-ins with the given tagid
642 ** r=TAGID show check-ins related to tagid
643 ** u=USER only if belonging to this user
644 ** y=TYPE 'ci', 'w', 't'
645 ** s=TEXT string search (comment and brief)
646 ** ng Suppress the graph if present
647 **
648 ** p= and d= can appear individually or together. If either p= or d=
649 ** appear, then u=, y=, a=, and b= are ignored.
@@ -749,22 +751,22 @@
749 }else{
750 blob_appendf(&desc, " of check-in [%.10s]", zUuid);
751 }
752 }else{
753 int n;
754 const char *zEType = "event";
755 char *zDate;
756 char *zNEntry = mprintf("%d", nEntry);
757 url_initialize(&url, "timeline");
758 url_add_parameter(&url, "n", zNEntry);
759 if( tagid>0 ){
760 zType = "ci";
761 blob_appendf(&sql,
762 "AND (EXISTS(SELECT 1 FROM tagxref"
763 " WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)", tagid);
764
765 if( zBrName ){
766 /* The next two blob_appendf() calls add SQL that causes checkins that
767 ** are not part of the branch which are parents or childen of the branch
768 ** to be included in the report. This related check-ins are useful
769 ** in helping to visualize what has happened on a quiescent branch
770 ** that is infrequently merged with a much more activate branch.
@@ -781,10 +783,11 @@
781 }
782 blob_appendf(&sql, ")");
783 }
784 if( (zType[0]=='w' && !g.okRdWiki)
785 || (zType[0]=='t' && !g.okRdTkt)
 
786 || (zType[0]=='c' && !g.okRead)
787 ){
788 zType = "all";
789 }
790 if( zType[0]=='a' ){
@@ -794,11 +797,11 @@
794 if( g.okRead ){
795 blob_appendf(&sql, "%c'ci'", cSep);
796 cSep = ',';
797 }
798 if( g.okRdWiki ){
799 blob_appendf(&sql, "%c'w'", cSep);
800 cSep = ',';
801 }
802 if( g.okRdTkt ){
803 blob_appendf(&sql, "%c't'", cSep);
804 cSep = ',';
@@ -812,10 +815,12 @@
812 zEType = "checkin";
813 }else if( zType[0]=='w' ){
814 zEType = "wiki edit";
815 }else if( zType[0]=='t' ){
816 zEType = "ticket change";
 
 
817 }
818 }
819 if( zUser ){
820 blob_appendf(&sql, " AND event.user=%Q", zUser);
821 url_add_parameter(&url, "u", zUser);
@@ -926,16 +931,19 @@
926 timeline_submenu(&url, "Checkins Only", "y", "ci", 0);
927 }
928 if( zType[0]!='t' && g.okRdTkt ){
929 timeline_submenu(&url, "Tickets Only", "y", "t", 0);
930 }
 
 
 
931 }
932 if( nEntry>20 ){
933 timeline_submenu(&url, "20 Events", "n", "20", 0);
934 }
935 if( nEntry<200 ){
936 timeline_submenu(&url, "200 Events", "n", "200", 0);
937 }
938 }
939 }
940 blob_zero(&sql);
941 db_prepare(&q, "SELECT * FROM timeline ORDER BY timestamp DESC /*scan*/");
942
--- src/timeline.c
+++ src/timeline.c
@@ -165,11 +165,11 @@
165 ** 4. User
166 ** 5. True if is a leaf
167 ** 6. background color
168 ** 7. type ("ci", "w", "t")
169 ** 8. list of symbolic tags.
170 ** 9. tagid for ticket or wiki or event
171 ** 10. Short comment to user for repeated tickets and wiki
172 */
173 void www_print_timeline(
174 Stmt *pQuery, /* Query to implement the timeline */
175 int tmFlags, /* Flags controlling display behavior */
@@ -288,10 +288,12 @@
288 @ <span class="timelineLeaf">Closed-Leaf:</span>
289 }else{
290 @ <span class="timelineLeaf">Leaf:</span>
291 }
292 }
293 }else if( zType[0]=='e' && tagid ){
294 hyperlink_to_event_tagid(tagid);
295 }else if( (tmFlags & TIMELINE_ARTID)!=0 ){
296 hyperlink_to_uuid(zUuid);
297 }
298 db_column_blob(pQuery, commentColumn, &comment);
299 if( mxWikiLen>0 && blob_size(&comment)>mxWikiLen ){
@@ -639,11 +641,11 @@
641 ** p=RID artifact RID and up to COUNT parents and ancestors
642 ** d=RID artifact RID and up to COUNT descendants
643 ** t=TAGID show only check-ins with the given tagid
644 ** r=TAGID show check-ins related to tagid
645 ** u=USER only if belonging to this user
646 ** y=TYPE 'ci', 'w', 't', 'e'
647 ** s=TEXT string search (comment and brief)
648 ** ng Suppress the graph if present
649 **
650 ** p= and d= can appear individually or together. If either p= or d=
651 ** appear, then u=, y=, a=, and b= are ignored.
@@ -749,22 +751,22 @@
751 }else{
752 blob_appendf(&desc, " of check-in [%.10s]", zUuid);
753 }
754 }else{
755 int n;
756 const char *zEType = "timeline item";
757 char *zDate;
758 char *zNEntry = mprintf("%d", nEntry);
759 url_initialize(&url, "timeline");
760 url_add_parameter(&url, "n", zNEntry);
761 if( tagid>0 ){
762 if( zType[0]!='e' ) zType = "ci";
763 blob_appendf(&sql,
764 "AND (EXISTS(SELECT 1 FROM tagxref"
765 " WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)", tagid);
766
767 if( zBrName && zType[0]=='c' ){
768 /* The next two blob_appendf() calls add SQL that causes checkins that
769 ** are not part of the branch which are parents or childen of the branch
770 ** to be included in the report. This related check-ins are useful
771 ** in helping to visualize what has happened on a quiescent branch
772 ** that is infrequently merged with a much more activate branch.
@@ -781,10 +783,11 @@
783 }
784 blob_appendf(&sql, ")");
785 }
786 if( (zType[0]=='w' && !g.okRdWiki)
787 || (zType[0]=='t' && !g.okRdTkt)
788 || (zType[0]=='e' && !g.okRdWiki)
789 || (zType[0]=='c' && !g.okRead)
790 ){
791 zType = "all";
792 }
793 if( zType[0]=='a' ){
@@ -794,11 +797,11 @@
797 if( g.okRead ){
798 blob_appendf(&sql, "%c'ci'", cSep);
799 cSep = ',';
800 }
801 if( g.okRdWiki ){
802 blob_appendf(&sql, "%c'w','e'", cSep);
803 cSep = ',';
804 }
805 if( g.okRdTkt ){
806 blob_appendf(&sql, "%c't'", cSep);
807 cSep = ',';
@@ -812,10 +815,12 @@
815 zEType = "checkin";
816 }else if( zType[0]=='w' ){
817 zEType = "wiki edit";
818 }else if( zType[0]=='t' ){
819 zEType = "ticket change";
820 }else if( zType[0]=='e' ){
821 zEType = "event";
822 }
823 }
824 if( zUser ){
825 blob_appendf(&sql, " AND event.user=%Q", zUser);
826 url_add_parameter(&url, "u", zUser);
@@ -926,16 +931,19 @@
931 timeline_submenu(&url, "Checkins Only", "y", "ci", 0);
932 }
933 if( zType[0]!='t' && g.okRdTkt ){
934 timeline_submenu(&url, "Tickets Only", "y", "t", 0);
935 }
936 if( zType[0]!='e' && g.okRdWiki ){
937 timeline_submenu(&url, "Events Only", "y", "e", 0);
938 }
939 }
940 if( nEntry>20 ){
941 timeline_submenu(&url, "20 Entries", "n", "20", 0);
942 }
943 if( nEntry<200 ){
944 timeline_submenu(&url, "200 Entries", "n", "200", 0);
945 }
946 }
947 }
948 blob_zero(&sql);
949 db_prepare(&q, "SELECT * FROM timeline ORDER BY timestamp DESC /*scan*/");
950
+4 -2
--- src/tkt.c
+++ src/tkt.c
@@ -346,21 +346,23 @@
346346
if( cnt==0 ){
347347
@ <hr /><h2>Attachments:</h2>
348348
@ <ul>
349349
}
350350
cnt++;
351
+ @ <li>
351352
if( g.okRead && g.okHistory ){
352
- @ <li><a href="%s(g.zTop)/attachview?tkt=%s(zFullName)&amp;file=%t(zFile)">
353
+ @ <a href="%s(g.zTop)/attachview?tkt=%s(zFullName)&amp;file=%t(zFile)">
353354
@ %h(zFile)</a>
354355
}else{
355356
@ %h(zFile)
356357
}
357358
@ added by %h(zUser) on
358359
hyperlink_to_date(zDate, ".");
359360
if( g.okWrTkt && g.okAttach ){
360361
@ [<a href="%s(g.zTop)/attachdelete?tkt=%s(zFullName)&amp;file=%t(zFile)&amp;from=%s(g.zTop)/tktview%%3fname=%s(zFullName)">delete</a>]
361362
}
363
+ @ </li>
362364
}
363365
if( cnt ){
364366
@ </ul>
365367
}
366368
db_finalize(&q);
@@ -567,11 +569,11 @@
567569
@ <span class="tktError">No such ticket: \"%h(zName)\"</span>
568570
style_footer();
569571
return;
570572
}
571573
if( nRec>1 ){
572
- @ <span class="tktError"><b>%d(nRec) tickets begin with:
574
+ @ <span class="tktError">%d(nRec) tickets begin with:
573575
@ \"%h(zName)\"</span>
574576
style_footer();
575577
return;
576578
}
577579
if( g.thTrace ) Th_Trace("BEGIN_TKTEDIT<br />\n", -1);
578580
--- src/tkt.c
+++ src/tkt.c
@@ -346,21 +346,23 @@
346 if( cnt==0 ){
347 @ <hr /><h2>Attachments:</h2>
348 @ <ul>
349 }
350 cnt++;
 
351 if( g.okRead && g.okHistory ){
352 @ <li><a href="%s(g.zTop)/attachview?tkt=%s(zFullName)&amp;file=%t(zFile)">
353 @ %h(zFile)</a>
354 }else{
355 @ %h(zFile)
356 }
357 @ added by %h(zUser) on
358 hyperlink_to_date(zDate, ".");
359 if( g.okWrTkt && g.okAttach ){
360 @ [<a href="%s(g.zTop)/attachdelete?tkt=%s(zFullName)&amp;file=%t(zFile)&amp;from=%s(g.zTop)/tktview%%3fname=%s(zFullName)">delete</a>]
361 }
 
362 }
363 if( cnt ){
364 @ </ul>
365 }
366 db_finalize(&q);
@@ -567,11 +569,11 @@
567 @ <span class="tktError">No such ticket: \"%h(zName)\"</span>
568 style_footer();
569 return;
570 }
571 if( nRec>1 ){
572 @ <span class="tktError"><b>%d(nRec) tickets begin with:
573 @ \"%h(zName)\"</span>
574 style_footer();
575 return;
576 }
577 if( g.thTrace ) Th_Trace("BEGIN_TKTEDIT<br />\n", -1);
578
--- src/tkt.c
+++ src/tkt.c
@@ -346,21 +346,23 @@
346 if( cnt==0 ){
347 @ <hr /><h2>Attachments:</h2>
348 @ <ul>
349 }
350 cnt++;
351 @ <li>
352 if( g.okRead && g.okHistory ){
353 @ <a href="%s(g.zTop)/attachview?tkt=%s(zFullName)&amp;file=%t(zFile)">
354 @ %h(zFile)</a>
355 }else{
356 @ %h(zFile)
357 }
358 @ added by %h(zUser) on
359 hyperlink_to_date(zDate, ".");
360 if( g.okWrTkt && g.okAttach ){
361 @ [<a href="%s(g.zTop)/attachdelete?tkt=%s(zFullName)&amp;file=%t(zFile)&amp;from=%s(g.zTop)/tktview%%3fname=%s(zFullName)">delete</a>]
362 }
363 @ </li>
364 }
365 if( cnt ){
366 @ </ul>
367 }
368 db_finalize(&q);
@@ -567,11 +569,11 @@
569 @ <span class="tktError">No such ticket: \"%h(zName)\"</span>
570 style_footer();
571 return;
572 }
573 if( nRec>1 ){
574 @ <span class="tktError">%d(nRec) tickets begin with:
575 @ \"%h(zName)\"</span>
576 style_footer();
577 return;
578 }
579 if( g.thTrace ) Th_Trace("BEGIN_TKTEDIT<br />\n", -1);
580
+1 -1
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -123,11 +123,11 @@
123123
z = zDfltValue;
124124
}else if( isSubmit ){
125125
char *zErr = 0;
126126
login_verify_csrf_secret();
127127
if( xText && (zErr = xText(z))!=0 ){
128
- @ <p><font color="red"><b>ERROR: %h(zErr)</b></font></p>
128
+ @ <p class="tktsetupError">ERROR: %h(zErr)</p>
129129
}else{
130130
db_set(zDbField, z, 0);
131131
if( xRebuild ) xRebuild();
132132
cgi_redirect("tktsetup");
133133
}
134134
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -123,11 +123,11 @@
123 z = zDfltValue;
124 }else if( isSubmit ){
125 char *zErr = 0;
126 login_verify_csrf_secret();
127 if( xText && (zErr = xText(z))!=0 ){
128 @ <p><font color="red"><b>ERROR: %h(zErr)</b></font></p>
129 }else{
130 db_set(zDbField, z, 0);
131 if( xRebuild ) xRebuild();
132 cgi_redirect("tktsetup");
133 }
134
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -123,11 +123,11 @@
123 z = zDfltValue;
124 }else if( isSubmit ){
125 char *zErr = 0;
126 login_verify_csrf_secret();
127 if( xText && (zErr = xText(z))!=0 ){
128 @ <p class="tktsetupError">ERROR: %h(zErr)</p>
129 }else{
130 db_set(zDbField, z, 0);
131 if( xRebuild ) xRebuild();
132 cgi_redirect("tktsetup");
133 }
134
+5 -1
--- src/vfile.c
+++ src/vfile.c
@@ -462,11 +462,15 @@
462462
md5sum_step_text(zBuf, -1);
463463
md5sum_step_blob(&file);
464464
blob_reset(&file);
465465
}
466466
if( pManOut ){
467
- blob_append(pManOut, m.zRepoCksum, -1);
467
+ if( m.zRepoCksum ){
468
+ blob_append(pManOut, m.zRepoCksum, -1);
469
+ }else{
470
+ blob_zero(pManOut);
471
+ }
468472
}
469473
manifest_clear(&m);
470474
md5sum_finish(pOut);
471475
}
472476
473477
--- src/vfile.c
+++ src/vfile.c
@@ -462,11 +462,15 @@
462 md5sum_step_text(zBuf, -1);
463 md5sum_step_blob(&file);
464 blob_reset(&file);
465 }
466 if( pManOut ){
467 blob_append(pManOut, m.zRepoCksum, -1);
 
 
 
 
468 }
469 manifest_clear(&m);
470 md5sum_finish(pOut);
471 }
472
473
--- src/vfile.c
+++ src/vfile.c
@@ -462,11 +462,15 @@
462 md5sum_step_text(zBuf, -1);
463 md5sum_step_blob(&file);
464 blob_reset(&file);
465 }
466 if( pManOut ){
467 if( m.zRepoCksum ){
468 blob_append(pManOut, m.zRepoCksum, -1);
469 }else{
470 blob_zero(pManOut);
471 }
472 }
473 manifest_clear(&m);
474 md5sum_finish(pOut);
475 }
476
477
+18 -58
--- src/wiki.c
+++ src/wiki.c
@@ -85,14 +85,15 @@
8585
login_check_credentials();
8686
if( !g.okRdWiki ){
8787
cgi_redirectf("%s/login?g=%s/home", g.zBaseURL, g.zBaseURL);
8888
}
8989
if( zIndexPage ){
90
- while( zIndexPage[0]=='/' ) zIndexPage++;
91
- if( strcmp(zIndexPage, P("PATH_INFO"))==0 ) zIndexPage = 0;
90
+ const char *zPathInfo = P("PATH_INFO");
91
+ if( strcmp(zIndexPage, zPathInfo)==0 ) zIndexPage = 0;
9292
}
9393
if( zIndexPage ){
94
+ while( zIndexPage[0]=='/' ) zIndexPage++;
9495
cgi_redirectf("%s/%s", g.zBaseURL, zIndexPage);
9596
}
9697
if( zPageName ){
9798
login_check_credentials();
9899
g.zExtra = zPageName;
@@ -105,11 +106,11 @@
105106
@ <p>This is a stub home-page for the project.
106107
@ To fill in this page, first go to
107108
@ <a href="%s(g.zBaseURL)/setup_config">setup/config</a>
108109
@ and establish a "Project Name". Then create a
109110
@ wiki page with that name. The content of that wiki page
110
- @ will be displayed in place of this message.
111
+ @ will be displayed in place of this message.</p>
111112
style_footer();
112113
}
113114
114115
/*
115116
** Return true if the given pagename is the name of the sandbox
@@ -152,10 +153,13 @@
152153
@ wiki.</li>
153154
@ <li> Use the <a href="%s(g.zBaseURL)/wiki?name=Sandbox">Sandbox</a>
154155
@ to experiment.</li>
155156
if( g.okNewWiki ){
156157
@ <li> Create a <a href="%s(g.zBaseURL)/wikinew">new wiki page</a>.</li>
158
+ if( g.okWrite ){
159
+ @ <li> Create a <a href="%s(g.zTop)/eventedit">new event</a>.</li>
160
+ }
157161
}
158162
@ <li> <a href="%s(g.zBaseURL)/wcontent">List of All Wiki Pages</a>
159163
@ available on this server.</li>
160164
@ <li> <form method="get" action="%s(g.zBaseURL)/wfind"><div>
161165
@ Search wiki titles: <input type="text" name="title"/>
@@ -222,16 +226,16 @@
222226
while( db_step(&q)==SQLITE_ROW ){
223227
const char *zDate = db_column_text(&q, 0);
224228
const char *zFile = db_column_text(&q, 1);
225229
const char *zUser = db_column_text(&q, 2);
226230
if( cnt==0 ){
227
- @ <hr><h2>Attachments:</h2>
231
+ @ <hr /><h2>Attachments:</h2>
228232
@ <ul>
229233
}
230234
cnt++;
235
+ @ <li>
231236
if( g.okHistory && g.okRead ){
232
- @ <li>
233237
@ <a href="%s(g.zTop)/attachview?page=%s(zPageName)&amp;file=%t(zFile)">
234238
@ %h(zFile)</a>
235239
}else{
236240
@ <li>%h(zFile)
237241
}
@@ -238,10 +242,11 @@
238242
@ added by %h(zUser) on
239243
hyperlink_to_date(zDate, ".");
240244
if( g.okWrWiki && g.okAttach ){
241245
@ [<a href="%s(g.zTop)/attachdelete?page=%s(zPageName)&amp;file=%t(zFile)&amp;from=%s(g.zTop)/wiki%%3fname=%s(zPageName)">delete</a>]
242246
}
247
+ @ </li>
243248
}
244249
if( cnt ){
245250
@ </ul>
246251
}
247252
db_finalize(&q);
@@ -533,22 +538,22 @@
533538
wiki_convert(&preview, 0, 0);
534539
@ <hr>
535540
blob_reset(&preview);
536541
}
537542
zUser = PD("u", g.zLogin);
538
- @ <form method="POST" action="%s(g.zBaseURL)/wikiappend">
543
+ @ <form method="post" action="%s(g.zBaseURL)/wikiappend">
539544
login_insert_csrf_secret();
540
- @ <input type="hidden" name="name" value="%h(zPageName)">
545
+ @ <input type="hidden" name="name" value="%h(zPageName)" />
541546
@ Your Name:
542
- @ <input type="text" name="u" size="20" value="%h(zUser)"><br />
547
+ @ <input type="text" name="u" size="20" value="%h(zUser)" /><br />
543548
@ Comment to append:<br />
544549
@ <textarea name="r" class="wikiedit" cols="80"
545550
@ rows="10" wrap="virtual">%h(PD("r",""))</textarea>
546551
@ <br />
547
- @ <input type="submit" name="preview" value="Preview Your Comment">
548
- @ <input type="submit" name="submit" value="Append Your Changes">
549
- @ <input type="submit" name="cancel" value="Cancel">
552
+ @ <input type="submit" name="preview" value="Preview Your Comment" />
553
+ @ <input type="submit" name="submit" value="Append Your Changes" />
554
+ @ <input type="submit" name="cancel" value="Cancel" />
550555
@ </form>
551556
style_footer();
552557
}
553558
554559
/*
@@ -770,57 +775,12 @@
770775
@ <p>You can also link to internal anchor names using [#anchor-name], providing
771776
@ you have added the necessary "&lt;a name="anchor-name"&gt;&lt;/a&gt;"
772777
@ tag to your wiki page.</p></li>
773778
@ <li> <p><span class="wikiruleHead">HTML</span>.
774779
@ The following standard HTML elements may be used:
775
- @ &lt;a&gt;
776
- @ &lt;address&gt;
777
- @ &lt;b&gt;
778
- @ &lt;big&gt;
779
- @ &lt;blockquote&gt;
780
- @ &lt;br&gt;
781
- @ &lt;center&gt;
782
- @ &lt;cite&gt;
783
- @ &lt;code&gt;
784
- @ &lt;dd&gt;
785
- @ &lt;dfn&gt;
786
- @ &lt;div&gt;
787
- @ &lt;dl&gt;
788
- @ &lt;dt&gt;
789
- @ &lt;em&gt;
790
- @ &lt;font&gt;
791
- @ &lt;h1&gt;
792
- @ &lt;h2&gt;
793
- @ &lt;h3&gt;
794
- @ &lt;h4&gt;
795
- @ &lt;h5&gt;
796
- @ &lt;h6&gt;
797
- @ &lt;hr&gt;
798
- @ &lt;img&gt;
799
- @ &lt;i&gt;
800
- @ &lt;kbd&gt;
801
- @ &lt;li&gt;
802
- @ &lt;nobr&gt;
803
- @ &lt;ol&gt;
804
- @ &lt;p&gt;
805
- @ &lt;pre&gt;
806
- @ &lt;s&gt;
807
- @ &lt;samp&gt;
808
- @ &lt;small&gt;
809
- @ &lt;strike&gt;
810
- @ &lt;strong&gt;
811
- @ &lt;sub&gt;
812
- @ &lt;sup&gt;
813
- @ &lt;table&gt;
814
- @ &lt;td&gt;
815
- @ &lt;th&gt;
816
- @ &lt;tr&gt;
817
- @ &lt;tt&gt;
818
- @ &lt;u&gt;
819
- @ &lt;ul&gt;
820
- @ &lt;var&gt;.
821
- @ In addition, there are two non-standard elements available:
780
+ show_allowed_wiki_markup();
781
+ @ . There are two non-standard elements available:
822782
@ &lt;verbatim&gt; and &lt;nowiki&gt;.
823783
@ No other elements are allowed. All attributes are checked and
824784
@ only a few benign attributes are allowed on each element.
825785
@ In particular, any attributes that specify javascript or CSS
826786
@ are elided.</p></li>
827787
--- src/wiki.c
+++ src/wiki.c
@@ -85,14 +85,15 @@
85 login_check_credentials();
86 if( !g.okRdWiki ){
87 cgi_redirectf("%s/login?g=%s/home", g.zBaseURL, g.zBaseURL);
88 }
89 if( zIndexPage ){
90 while( zIndexPage[0]=='/' ) zIndexPage++;
91 if( strcmp(zIndexPage, P("PATH_INFO"))==0 ) zIndexPage = 0;
92 }
93 if( zIndexPage ){
 
94 cgi_redirectf("%s/%s", g.zBaseURL, zIndexPage);
95 }
96 if( zPageName ){
97 login_check_credentials();
98 g.zExtra = zPageName;
@@ -105,11 +106,11 @@
105 @ <p>This is a stub home-page for the project.
106 @ To fill in this page, first go to
107 @ <a href="%s(g.zBaseURL)/setup_config">setup/config</a>
108 @ and establish a "Project Name". Then create a
109 @ wiki page with that name. The content of that wiki page
110 @ will be displayed in place of this message.
111 style_footer();
112 }
113
114 /*
115 ** Return true if the given pagename is the name of the sandbox
@@ -152,10 +153,13 @@
152 @ wiki.</li>
153 @ <li> Use the <a href="%s(g.zBaseURL)/wiki?name=Sandbox">Sandbox</a>
154 @ to experiment.</li>
155 if( g.okNewWiki ){
156 @ <li> Create a <a href="%s(g.zBaseURL)/wikinew">new wiki page</a>.</li>
 
 
 
157 }
158 @ <li> <a href="%s(g.zBaseURL)/wcontent">List of All Wiki Pages</a>
159 @ available on this server.</li>
160 @ <li> <form method="get" action="%s(g.zBaseURL)/wfind"><div>
161 @ Search wiki titles: <input type="text" name="title"/>
@@ -222,16 +226,16 @@
222 while( db_step(&q)==SQLITE_ROW ){
223 const char *zDate = db_column_text(&q, 0);
224 const char *zFile = db_column_text(&q, 1);
225 const char *zUser = db_column_text(&q, 2);
226 if( cnt==0 ){
227 @ <hr><h2>Attachments:</h2>
228 @ <ul>
229 }
230 cnt++;
 
231 if( g.okHistory && g.okRead ){
232 @ <li>
233 @ <a href="%s(g.zTop)/attachview?page=%s(zPageName)&amp;file=%t(zFile)">
234 @ %h(zFile)</a>
235 }else{
236 @ <li>%h(zFile)
237 }
@@ -238,10 +242,11 @@
238 @ added by %h(zUser) on
239 hyperlink_to_date(zDate, ".");
240 if( g.okWrWiki && g.okAttach ){
241 @ [<a href="%s(g.zTop)/attachdelete?page=%s(zPageName)&amp;file=%t(zFile)&amp;from=%s(g.zTop)/wiki%%3fname=%s(zPageName)">delete</a>]
242 }
 
243 }
244 if( cnt ){
245 @ </ul>
246 }
247 db_finalize(&q);
@@ -533,22 +538,22 @@
533 wiki_convert(&preview, 0, 0);
534 @ <hr>
535 blob_reset(&preview);
536 }
537 zUser = PD("u", g.zLogin);
538 @ <form method="POST" action="%s(g.zBaseURL)/wikiappend">
539 login_insert_csrf_secret();
540 @ <input type="hidden" name="name" value="%h(zPageName)">
541 @ Your Name:
542 @ <input type="text" name="u" size="20" value="%h(zUser)"><br />
543 @ Comment to append:<br />
544 @ <textarea name="r" class="wikiedit" cols="80"
545 @ rows="10" wrap="virtual">%h(PD("r",""))</textarea>
546 @ <br />
547 @ <input type="submit" name="preview" value="Preview Your Comment">
548 @ <input type="submit" name="submit" value="Append Your Changes">
549 @ <input type="submit" name="cancel" value="Cancel">
550 @ </form>
551 style_footer();
552 }
553
554 /*
@@ -770,57 +775,12 @@
770 @ <p>You can also link to internal anchor names using [#anchor-name], providing
771 @ you have added the necessary "&lt;a name="anchor-name"&gt;&lt;/a&gt;"
772 @ tag to your wiki page.</p></li>
773 @ <li> <p><span class="wikiruleHead">HTML</span>.
774 @ The following standard HTML elements may be used:
775 @ &lt;a&gt;
776 @ &lt;address&gt;
777 @ &lt;b&gt;
778 @ &lt;big&gt;
779 @ &lt;blockquote&gt;
780 @ &lt;br&gt;
781 @ &lt;center&gt;
782 @ &lt;cite&gt;
783 @ &lt;code&gt;
784 @ &lt;dd&gt;
785 @ &lt;dfn&gt;
786 @ &lt;div&gt;
787 @ &lt;dl&gt;
788 @ &lt;dt&gt;
789 @ &lt;em&gt;
790 @ &lt;font&gt;
791 @ &lt;h1&gt;
792 @ &lt;h2&gt;
793 @ &lt;h3&gt;
794 @ &lt;h4&gt;
795 @ &lt;h5&gt;
796 @ &lt;h6&gt;
797 @ &lt;hr&gt;
798 @ &lt;img&gt;
799 @ &lt;i&gt;
800 @ &lt;kbd&gt;
801 @ &lt;li&gt;
802 @ &lt;nobr&gt;
803 @ &lt;ol&gt;
804 @ &lt;p&gt;
805 @ &lt;pre&gt;
806 @ &lt;s&gt;
807 @ &lt;samp&gt;
808 @ &lt;small&gt;
809 @ &lt;strike&gt;
810 @ &lt;strong&gt;
811 @ &lt;sub&gt;
812 @ &lt;sup&gt;
813 @ &lt;table&gt;
814 @ &lt;td&gt;
815 @ &lt;th&gt;
816 @ &lt;tr&gt;
817 @ &lt;tt&gt;
818 @ &lt;u&gt;
819 @ &lt;ul&gt;
820 @ &lt;var&gt;.
821 @ In addition, there are two non-standard elements available:
822 @ &lt;verbatim&gt; and &lt;nowiki&gt;.
823 @ No other elements are allowed. All attributes are checked and
824 @ only a few benign attributes are allowed on each element.
825 @ In particular, any attributes that specify javascript or CSS
826 @ are elided.</p></li>
827
--- src/wiki.c
+++ src/wiki.c
@@ -85,14 +85,15 @@
85 login_check_credentials();
86 if( !g.okRdWiki ){
87 cgi_redirectf("%s/login?g=%s/home", g.zBaseURL, g.zBaseURL);
88 }
89 if( zIndexPage ){
90 const char *zPathInfo = P("PATH_INFO");
91 if( strcmp(zIndexPage, zPathInfo)==0 ) zIndexPage = 0;
92 }
93 if( zIndexPage ){
94 while( zIndexPage[0]=='/' ) zIndexPage++;
95 cgi_redirectf("%s/%s", g.zBaseURL, zIndexPage);
96 }
97 if( zPageName ){
98 login_check_credentials();
99 g.zExtra = zPageName;
@@ -105,11 +106,11 @@
106 @ <p>This is a stub home-page for the project.
107 @ To fill in this page, first go to
108 @ <a href="%s(g.zBaseURL)/setup_config">setup/config</a>
109 @ and establish a "Project Name". Then create a
110 @ wiki page with that name. The content of that wiki page
111 @ will be displayed in place of this message.</p>
112 style_footer();
113 }
114
115 /*
116 ** Return true if the given pagename is the name of the sandbox
@@ -152,10 +153,13 @@
153 @ wiki.</li>
154 @ <li> Use the <a href="%s(g.zBaseURL)/wiki?name=Sandbox">Sandbox</a>
155 @ to experiment.</li>
156 if( g.okNewWiki ){
157 @ <li> Create a <a href="%s(g.zBaseURL)/wikinew">new wiki page</a>.</li>
158 if( g.okWrite ){
159 @ <li> Create a <a href="%s(g.zTop)/eventedit">new event</a>.</li>
160 }
161 }
162 @ <li> <a href="%s(g.zBaseURL)/wcontent">List of All Wiki Pages</a>
163 @ available on this server.</li>
164 @ <li> <form method="get" action="%s(g.zBaseURL)/wfind"><div>
165 @ Search wiki titles: <input type="text" name="title"/>
@@ -222,16 +226,16 @@
226 while( db_step(&q)==SQLITE_ROW ){
227 const char *zDate = db_column_text(&q, 0);
228 const char *zFile = db_column_text(&q, 1);
229 const char *zUser = db_column_text(&q, 2);
230 if( cnt==0 ){
231 @ <hr /><h2>Attachments:</h2>
232 @ <ul>
233 }
234 cnt++;
235 @ <li>
236 if( g.okHistory && g.okRead ){
 
237 @ <a href="%s(g.zTop)/attachview?page=%s(zPageName)&amp;file=%t(zFile)">
238 @ %h(zFile)</a>
239 }else{
240 @ <li>%h(zFile)
241 }
@@ -238,10 +242,11 @@
242 @ added by %h(zUser) on
243 hyperlink_to_date(zDate, ".");
244 if( g.okWrWiki && g.okAttach ){
245 @ [<a href="%s(g.zTop)/attachdelete?page=%s(zPageName)&amp;file=%t(zFile)&amp;from=%s(g.zTop)/wiki%%3fname=%s(zPageName)">delete</a>]
246 }
247 @ </li>
248 }
249 if( cnt ){
250 @ </ul>
251 }
252 db_finalize(&q);
@@ -533,22 +538,22 @@
538 wiki_convert(&preview, 0, 0);
539 @ <hr>
540 blob_reset(&preview);
541 }
542 zUser = PD("u", g.zLogin);
543 @ <form method="post" action="%s(g.zBaseURL)/wikiappend">
544 login_insert_csrf_secret();
545 @ <input type="hidden" name="name" value="%h(zPageName)" />
546 @ Your Name:
547 @ <input type="text" name="u" size="20" value="%h(zUser)" /><br />
548 @ Comment to append:<br />
549 @ <textarea name="r" class="wikiedit" cols="80"
550 @ rows="10" wrap="virtual">%h(PD("r",""))</textarea>
551 @ <br />
552 @ <input type="submit" name="preview" value="Preview Your Comment" />
553 @ <input type="submit" name="submit" value="Append Your Changes" />
554 @ <input type="submit" name="cancel" value="Cancel" />
555 @ </form>
556 style_footer();
557 }
558
559 /*
@@ -770,57 +775,12 @@
775 @ <p>You can also link to internal anchor names using [#anchor-name], providing
776 @ you have added the necessary "&lt;a name="anchor-name"&gt;&lt;/a&gt;"
777 @ tag to your wiki page.</p></li>
778 @ <li> <p><span class="wikiruleHead">HTML</span>.
779 @ The following standard HTML elements may be used:
780 show_allowed_wiki_markup();
781 @ . There are two non-standard elements available:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
782 @ &lt;verbatim&gt; and &lt;nowiki&gt;.
783 @ No other elements are allowed. All attributes are checked and
784 @ only a few benign attributes are allowed on each element.
785 @ In particular, any attributes that specify javascript or CSS
786 @ are elided.</p></li>
787
+75 -52
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -150,59 +150,65 @@
150150
** Except for MARKUP_INVALID, this must all be in alphabetical order
151151
** and in numerical sequence. The first markup type must be zero.
152152
** The value for MARKUP_XYZ must correspond to the <xyz> entry
153153
** in aAllowedMarkup[].
154154
*/
155
-#define MARKUP_INVALID 0
156
-#define MARKUP_A 1
157
-#define MARKUP_ADDRESS 2
158
-#define MARKUP_B 3
159
-#define MARKUP_BIG 4
160
-#define MARKUP_BLOCKQUOTE 5
161
-#define MARKUP_BR 6
162
-#define MARKUP_CENTER 7
163
-#define MARKUP_CITE 8
164
-#define MARKUP_CODE 9
165
-#define MARKUP_DD 10
166
-#define MARKUP_DFN 11
167
-#define MARKUP_DIV 12
168
-#define MARKUP_DL 13
169
-#define MARKUP_DT 14
170
-#define MARKUP_EM 15
171
-#define MARKUP_FONT 16
172
-#define MARKUP_H1 17
173
-#define MARKUP_H2 18
174
-#define MARKUP_H3 19
175
-#define MARKUP_H4 20
176
-#define MARKUP_H5 21
177
-#define MARKUP_H6 22
178
-#define MARKUP_HR 23
179
-#define MARKUP_I 24
180
-#define MARKUP_IMG 25
181
-#define MARKUP_KBD 26
182
-#define MARKUP_LI 27
183
-#define MARKUP_NOBR 28
184
-#define MARKUP_NOWIKI 29
185
-#define MARKUP_OL 30
186
-#define MARKUP_P 31
187
-#define MARKUP_PRE 32
188
-#define MARKUP_S 33
189
-#define MARKUP_SAMP 34
190
-#define MARKUP_SMALL 35
191
-#define MARKUP_STRIKE 36
192
-#define MARKUP_STRONG 37
193
-#define MARKUP_SUB 38
194
-#define MARKUP_SUP 39
195
-#define MARKUP_TABLE 40
196
-#define MARKUP_TD 41
197
-#define MARKUP_TH 42
198
-#define MARKUP_TR 43
199
-#define MARKUP_TT 44
200
-#define MARKUP_U 45
201
-#define MARKUP_UL 46
202
-#define MARKUP_VAR 47
203
-#define MARKUP_VERBATIM 48
155
+#define MARKUP_INVALID 0
156
+#define MARKUP_A 1
157
+#define MARKUP_ADDRESS 2
158
+#define MARKUP_B 3
159
+#define MARKUP_BIG 4
160
+#define MARKUP_BLOCKQUOTE 5
161
+#define MARKUP_BR 6
162
+#define MARKUP_CENTER 7
163
+#define MARKUP_CITE 8
164
+#define MARKUP_CODE 9
165
+#define MARKUP_COL 10
166
+#define MARKUP_COLGROUP 11
167
+#define MARKUP_DD 12
168
+#define MARKUP_DFN 13
169
+#define MARKUP_DIV 14
170
+#define MARKUP_DL 15
171
+#define MARKUP_DT 16
172
+#define MARKUP_EM 17
173
+#define MARKUP_FONT 18
174
+#define MARKUP_H1 19
175
+#define MARKUP_H2 20
176
+#define MARKUP_H3 21
177
+#define MARKUP_H4 22
178
+#define MARKUP_H5 23
179
+#define MARKUP_H6 24
180
+#define MARKUP_HR 25
181
+#define MARKUP_I 26
182
+#define MARKUP_IMG 27
183
+#define MARKUP_KBD 28
184
+#define MARKUP_LI 29
185
+#define MARKUP_NOBR 30
186
+#define MARKUP_NOWIKI 31
187
+#define MARKUP_OL 32
188
+#define MARKUP_P 33
189
+#define MARKUP_PRE 34
190
+#define MARKUP_S 35
191
+#define MARKUP_SAMP 36
192
+#define MARKUP_SMALL 37
193
+#define MARKUP_SPAN 38
194
+#define MARKUP_STRIKE 39
195
+#define MARKUP_STRONG 40
196
+#define MARKUP_SUB 41
197
+#define MARKUP_SUP 42
198
+#define MARKUP_TABLE 43
199
+#define MARKUP_TBODY 44
200
+#define MARKUP_TD 45
201
+#define MARKUP_TFOOT 46
202
+#define MARKUP_TH 47
203
+#define MARKUP_THEAD 48
204
+#define MARKUP_TR 49
205
+#define MARKUP_TT 50
206
+#define MARKUP_U 51
207
+#define MARKUP_UL 52
208
+#define MARKUP_VAR 53
209
+#define MARKUP_VERBATIM 54
204210
205211
/*
206212
** The various markup is divided into the following types:
207213
*/
208214
#define MUTYPE_SINGLE 0x0001 /* <img>, <br>, or <hr> */
@@ -241,10 +247,14 @@
241247
{ "blockquote", MARKUP_BLOCKQUOTE, MUTYPE_BLOCK, 0 },
242248
{ "br", MARKUP_BR, MUTYPE_SINGLE, AMSK_CLEAR },
243249
{ "center", MARKUP_CENTER, MUTYPE_BLOCK, 0 },
244250
{ "cite", MARKUP_CITE, MUTYPE_FONT, 0 },
245251
{ "code", MARKUP_CODE, MUTYPE_FONT, 0 },
252
+ { "col", MARKUP_COL, MUTYPE_SINGLE,
253
+ AMSK_ALIGN|AMSK_CLASS|AMSK_COLSPAN|AMSK_WIDTH },
254
+ { "colgroup", MARKUP_COLGROUP, MUTYPE_BLOCK,
255
+ AMSK_ALIGN|AMSK_CLASS|AMSK_COLSPAN|AMSK_WIDTH},
246256
{ "dd", MARKUP_DD, MUTYPE_LI, 0 },
247257
{ "dfn", MARKUP_DFN, MUTYPE_FONT, 0 },
248258
{ "div", MARKUP_DIV, MUTYPE_BLOCK, AMSK_ID|AMSK_CLASS },
249259
{ "dl", MARKUP_DL, MUTYPE_LIST, AMSK_COMPACT },
250260
{ "dt", MARKUP_DT, MUTYPE_LI, 0 },
@@ -273,32 +283,44 @@
273283
{ "p", MARKUP_P, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
274284
{ "pre", MARKUP_PRE, MUTYPE_BLOCK, 0 },
275285
{ "s", MARKUP_S, MUTYPE_FONT, 0 },
276286
{ "samp", MARKUP_SAMP, MUTYPE_FONT, 0 },
277287
{ "small", MARKUP_SMALL, MUTYPE_FONT, 0 },
288
+ { "span", MARKUP_SPAN, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
278289
{ "strike", MARKUP_STRIKE, MUTYPE_FONT, 0 },
279290
{ "strong", MARKUP_STRONG, MUTYPE_FONT, 0 },
280291
{ "sub", MARKUP_SUB, MUTYPE_FONT, 0 },
281292
{ "sup", MARKUP_SUP, MUTYPE_FONT, 0 },
282293
{ "table", MARKUP_TABLE, MUTYPE_TABLE,
283294
AMSK_ALIGN|AMSK_BGCOLOR|AMSK_BORDER|AMSK_CELLPADDING|
284295
AMSK_CELLSPACING|AMSK_HSPACE|AMSK_VSPACE|AMSK_CLASS },
296
+ { "tbody", MARKUP_TBODY, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
285297
{ "td", MARKUP_TD, MUTYPE_TD,
286298
AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN|
287299
AMSK_ROWSPAN|AMSK_VALIGN|AMSK_CLASS },
300
+ { "tfoot", MARKUP_TFOOT, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
288301
{ "th", MARKUP_TH, MUTYPE_TD,
289302
AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN|
290303
AMSK_ROWSPAN|AMSK_VALIGN|AMSK_CLASS },
304
+ { "thead", MARKUP_THEAD, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
291305
{ "tr", MARKUP_TR, MUTYPE_TR,
292306
AMSK_ALIGN|AMSK_BGCOLOR||AMSK_VALIGN|AMSK_CLASS },
293307
{ "tt", MARKUP_TT, MUTYPE_FONT, 0 },
294308
{ "u", MARKUP_U, MUTYPE_FONT, 0 },
295309
{ "ul", MARKUP_UL, MUTYPE_LIST,
296310
AMSK_TYPE|AMSK_COMPACT },
297311
{ "var", MARKUP_VAR, MUTYPE_FONT, 0 },
298312
{ "verbatim", MARKUP_VERBATIM, MUTYPE_SPECIAL, AMSK_ID|AMSK_TYPE },
299313
};
314
+
315
+void show_allowed_wiki_markup( void ){
316
+ int i; /* loop over allowedAttr */
317
+
318
+ for( i=1 ; i<=sizeof(aMarkup)/sizeof(aMarkup[0]) - 1 ; i++ ){
319
+ @ &lt;%s(aMarkup[i].zName)&gt;
320
+ }
321
+}
300322
301323
/*
302324
** Use binary search to locate a tag in the aMarkup[] table.
303325
*/
304326
static int findTag(const char *z){
@@ -379,11 +401,10 @@
379401
static int r = -1;
380402
if( r<0 ) r = db_get_boolean("wiki-use-html", 0);
381403
return r;
382404
}
383405
384
-
385406
/*
386407
** z points to a "<" character. Check to see if this is the start of
387408
** a valid markup. If it is, return the total number of characters in
388409
** the markup including the initial "<" and the terminating ">". If
389410
** it is not well-formed markup, return 0.
@@ -393,15 +414,17 @@
393414
int inparen = 0;
394415
int c;
395416
if( z[n]=='/' ){ n++; }
396417
if( !isalpha(z[n]) ) return 0;
397418
while( isalnum(z[n]) ){ n++; }
398
- if( (c = z[n])!='>' && !isspace(c) ) return 0;
419
+ c = z[n];
420
+ if( c=='/' && z[n+1]=='>' ){ return n+2; }
421
+ if( c!='>' && !isspace(c) ) return 0;
399422
while( (c = z[n])!=0 && (c!='>' || inparen) ){
400423
if( c==inparen ){
401424
inparen = 0;
402
- }else if( c=='"' || c=='\'' ){
425
+ }else if( inparen==0 && (c=='"' || c=='\'') ){
403426
inparen = c;
404427
}
405428
n++;
406429
}
407430
if( z[n]!='>' ) return 0;
408431
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -150,59 +150,65 @@
150 ** Except for MARKUP_INVALID, this must all be in alphabetical order
151 ** and in numerical sequence. The first markup type must be zero.
152 ** The value for MARKUP_XYZ must correspond to the <xyz> entry
153 ** in aAllowedMarkup[].
154 */
155 #define MARKUP_INVALID 0
156 #define MARKUP_A 1
157 #define MARKUP_ADDRESS 2
158 #define MARKUP_B 3
159 #define MARKUP_BIG 4
160 #define MARKUP_BLOCKQUOTE 5
161 #define MARKUP_BR 6
162 #define MARKUP_CENTER 7
163 #define MARKUP_CITE 8
164 #define MARKUP_CODE 9
165 #define MARKUP_DD 10
166 #define MARKUP_DFN 11
167 #define MARKUP_DIV 12
168 #define MARKUP_DL 13
169 #define MARKUP_DT 14
170 #define MARKUP_EM 15
171 #define MARKUP_FONT 16
172 #define MARKUP_H1 17
173 #define MARKUP_H2 18
174 #define MARKUP_H3 19
175 #define MARKUP_H4 20
176 #define MARKUP_H5 21
177 #define MARKUP_H6 22
178 #define MARKUP_HR 23
179 #define MARKUP_I 24
180 #define MARKUP_IMG 25
181 #define MARKUP_KBD 26
182 #define MARKUP_LI 27
183 #define MARKUP_NOBR 28
184 #define MARKUP_NOWIKI 29
185 #define MARKUP_OL 30
186 #define MARKUP_P 31
187 #define MARKUP_PRE 32
188 #define MARKUP_S 33
189 #define MARKUP_SAMP 34
190 #define MARKUP_SMALL 35
191 #define MARKUP_STRIKE 36
192 #define MARKUP_STRONG 37
193 #define MARKUP_SUB 38
194 #define MARKUP_SUP 39
195 #define MARKUP_TABLE 40
196 #define MARKUP_TD 41
197 #define MARKUP_TH 42
198 #define MARKUP_TR 43
199 #define MARKUP_TT 44
200 #define MARKUP_U 45
201 #define MARKUP_UL 46
202 #define MARKUP_VAR 47
203 #define MARKUP_VERBATIM 48
 
 
 
 
 
 
204
205 /*
206 ** The various markup is divided into the following types:
207 */
208 #define MUTYPE_SINGLE 0x0001 /* <img>, <br>, or <hr> */
@@ -241,10 +247,14 @@
241 { "blockquote", MARKUP_BLOCKQUOTE, MUTYPE_BLOCK, 0 },
242 { "br", MARKUP_BR, MUTYPE_SINGLE, AMSK_CLEAR },
243 { "center", MARKUP_CENTER, MUTYPE_BLOCK, 0 },
244 { "cite", MARKUP_CITE, MUTYPE_FONT, 0 },
245 { "code", MARKUP_CODE, MUTYPE_FONT, 0 },
 
 
 
 
246 { "dd", MARKUP_DD, MUTYPE_LI, 0 },
247 { "dfn", MARKUP_DFN, MUTYPE_FONT, 0 },
248 { "div", MARKUP_DIV, MUTYPE_BLOCK, AMSK_ID|AMSK_CLASS },
249 { "dl", MARKUP_DL, MUTYPE_LIST, AMSK_COMPACT },
250 { "dt", MARKUP_DT, MUTYPE_LI, 0 },
@@ -273,32 +283,44 @@
273 { "p", MARKUP_P, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
274 { "pre", MARKUP_PRE, MUTYPE_BLOCK, 0 },
275 { "s", MARKUP_S, MUTYPE_FONT, 0 },
276 { "samp", MARKUP_SAMP, MUTYPE_FONT, 0 },
277 { "small", MARKUP_SMALL, MUTYPE_FONT, 0 },
 
278 { "strike", MARKUP_STRIKE, MUTYPE_FONT, 0 },
279 { "strong", MARKUP_STRONG, MUTYPE_FONT, 0 },
280 { "sub", MARKUP_SUB, MUTYPE_FONT, 0 },
281 { "sup", MARKUP_SUP, MUTYPE_FONT, 0 },
282 { "table", MARKUP_TABLE, MUTYPE_TABLE,
283 AMSK_ALIGN|AMSK_BGCOLOR|AMSK_BORDER|AMSK_CELLPADDING|
284 AMSK_CELLSPACING|AMSK_HSPACE|AMSK_VSPACE|AMSK_CLASS },
 
285 { "td", MARKUP_TD, MUTYPE_TD,
286 AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN|
287 AMSK_ROWSPAN|AMSK_VALIGN|AMSK_CLASS },
 
288 { "th", MARKUP_TH, MUTYPE_TD,
289 AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN|
290 AMSK_ROWSPAN|AMSK_VALIGN|AMSK_CLASS },
 
291 { "tr", MARKUP_TR, MUTYPE_TR,
292 AMSK_ALIGN|AMSK_BGCOLOR||AMSK_VALIGN|AMSK_CLASS },
293 { "tt", MARKUP_TT, MUTYPE_FONT, 0 },
294 { "u", MARKUP_U, MUTYPE_FONT, 0 },
295 { "ul", MARKUP_UL, MUTYPE_LIST,
296 AMSK_TYPE|AMSK_COMPACT },
297 { "var", MARKUP_VAR, MUTYPE_FONT, 0 },
298 { "verbatim", MARKUP_VERBATIM, MUTYPE_SPECIAL, AMSK_ID|AMSK_TYPE },
299 };
 
 
 
 
 
 
 
 
300
301 /*
302 ** Use binary search to locate a tag in the aMarkup[] table.
303 */
304 static int findTag(const char *z){
@@ -379,11 +401,10 @@
379 static int r = -1;
380 if( r<0 ) r = db_get_boolean("wiki-use-html", 0);
381 return r;
382 }
383
384
385 /*
386 ** z points to a "<" character. Check to see if this is the start of
387 ** a valid markup. If it is, return the total number of characters in
388 ** the markup including the initial "<" and the terminating ">". If
389 ** it is not well-formed markup, return 0.
@@ -393,15 +414,17 @@
393 int inparen = 0;
394 int c;
395 if( z[n]=='/' ){ n++; }
396 if( !isalpha(z[n]) ) return 0;
397 while( isalnum(z[n]) ){ n++; }
398 if( (c = z[n])!='>' && !isspace(c) ) return 0;
 
 
399 while( (c = z[n])!=0 && (c!='>' || inparen) ){
400 if( c==inparen ){
401 inparen = 0;
402 }else if( c=='"' || c=='\'' ){
403 inparen = c;
404 }
405 n++;
406 }
407 if( z[n]!='>' ) return 0;
408
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -150,59 +150,65 @@
150 ** Except for MARKUP_INVALID, this must all be in alphabetical order
151 ** and in numerical sequence. The first markup type must be zero.
152 ** The value for MARKUP_XYZ must correspond to the <xyz> entry
153 ** in aAllowedMarkup[].
154 */
155 #define MARKUP_INVALID 0
156 #define MARKUP_A 1
157 #define MARKUP_ADDRESS 2
158 #define MARKUP_B 3
159 #define MARKUP_BIG 4
160 #define MARKUP_BLOCKQUOTE 5
161 #define MARKUP_BR 6
162 #define MARKUP_CENTER 7
163 #define MARKUP_CITE 8
164 #define MARKUP_CODE 9
165 #define MARKUP_COL 10
166 #define MARKUP_COLGROUP 11
167 #define MARKUP_DD 12
168 #define MARKUP_DFN 13
169 #define MARKUP_DIV 14
170 #define MARKUP_DL 15
171 #define MARKUP_DT 16
172 #define MARKUP_EM 17
173 #define MARKUP_FONT 18
174 #define MARKUP_H1 19
175 #define MARKUP_H2 20
176 #define MARKUP_H3 21
177 #define MARKUP_H4 22
178 #define MARKUP_H5 23
179 #define MARKUP_H6 24
180 #define MARKUP_HR 25
181 #define MARKUP_I 26
182 #define MARKUP_IMG 27
183 #define MARKUP_KBD 28
184 #define MARKUP_LI 29
185 #define MARKUP_NOBR 30
186 #define MARKUP_NOWIKI 31
187 #define MARKUP_OL 32
188 #define MARKUP_P 33
189 #define MARKUP_PRE 34
190 #define MARKUP_S 35
191 #define MARKUP_SAMP 36
192 #define MARKUP_SMALL 37
193 #define MARKUP_SPAN 38
194 #define MARKUP_STRIKE 39
195 #define MARKUP_STRONG 40
196 #define MARKUP_SUB 41
197 #define MARKUP_SUP 42
198 #define MARKUP_TABLE 43
199 #define MARKUP_TBODY 44
200 #define MARKUP_TD 45
201 #define MARKUP_TFOOT 46
202 #define MARKUP_TH 47
203 #define MARKUP_THEAD 48
204 #define MARKUP_TR 49
205 #define MARKUP_TT 50
206 #define MARKUP_U 51
207 #define MARKUP_UL 52
208 #define MARKUP_VAR 53
209 #define MARKUP_VERBATIM 54
210
211 /*
212 ** The various markup is divided into the following types:
213 */
214 #define MUTYPE_SINGLE 0x0001 /* <img>, <br>, or <hr> */
@@ -241,10 +247,14 @@
247 { "blockquote", MARKUP_BLOCKQUOTE, MUTYPE_BLOCK, 0 },
248 { "br", MARKUP_BR, MUTYPE_SINGLE, AMSK_CLEAR },
249 { "center", MARKUP_CENTER, MUTYPE_BLOCK, 0 },
250 { "cite", MARKUP_CITE, MUTYPE_FONT, 0 },
251 { "code", MARKUP_CODE, MUTYPE_FONT, 0 },
252 { "col", MARKUP_COL, MUTYPE_SINGLE,
253 AMSK_ALIGN|AMSK_CLASS|AMSK_COLSPAN|AMSK_WIDTH },
254 { "colgroup", MARKUP_COLGROUP, MUTYPE_BLOCK,
255 AMSK_ALIGN|AMSK_CLASS|AMSK_COLSPAN|AMSK_WIDTH},
256 { "dd", MARKUP_DD, MUTYPE_LI, 0 },
257 { "dfn", MARKUP_DFN, MUTYPE_FONT, 0 },
258 { "div", MARKUP_DIV, MUTYPE_BLOCK, AMSK_ID|AMSK_CLASS },
259 { "dl", MARKUP_DL, MUTYPE_LIST, AMSK_COMPACT },
260 { "dt", MARKUP_DT, MUTYPE_LI, 0 },
@@ -273,32 +283,44 @@
283 { "p", MARKUP_P, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
284 { "pre", MARKUP_PRE, MUTYPE_BLOCK, 0 },
285 { "s", MARKUP_S, MUTYPE_FONT, 0 },
286 { "samp", MARKUP_SAMP, MUTYPE_FONT, 0 },
287 { "small", MARKUP_SMALL, MUTYPE_FONT, 0 },
288 { "span", MARKUP_SPAN, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
289 { "strike", MARKUP_STRIKE, MUTYPE_FONT, 0 },
290 { "strong", MARKUP_STRONG, MUTYPE_FONT, 0 },
291 { "sub", MARKUP_SUB, MUTYPE_FONT, 0 },
292 { "sup", MARKUP_SUP, MUTYPE_FONT, 0 },
293 { "table", MARKUP_TABLE, MUTYPE_TABLE,
294 AMSK_ALIGN|AMSK_BGCOLOR|AMSK_BORDER|AMSK_CELLPADDING|
295 AMSK_CELLSPACING|AMSK_HSPACE|AMSK_VSPACE|AMSK_CLASS },
296 { "tbody", MARKUP_TBODY, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
297 { "td", MARKUP_TD, MUTYPE_TD,
298 AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN|
299 AMSK_ROWSPAN|AMSK_VALIGN|AMSK_CLASS },
300 { "tfoot", MARKUP_TFOOT, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
301 { "th", MARKUP_TH, MUTYPE_TD,
302 AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN|
303 AMSK_ROWSPAN|AMSK_VALIGN|AMSK_CLASS },
304 { "thead", MARKUP_THEAD, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
305 { "tr", MARKUP_TR, MUTYPE_TR,
306 AMSK_ALIGN|AMSK_BGCOLOR||AMSK_VALIGN|AMSK_CLASS },
307 { "tt", MARKUP_TT, MUTYPE_FONT, 0 },
308 { "u", MARKUP_U, MUTYPE_FONT, 0 },
309 { "ul", MARKUP_UL, MUTYPE_LIST,
310 AMSK_TYPE|AMSK_COMPACT },
311 { "var", MARKUP_VAR, MUTYPE_FONT, 0 },
312 { "verbatim", MARKUP_VERBATIM, MUTYPE_SPECIAL, AMSK_ID|AMSK_TYPE },
313 };
314
315 void show_allowed_wiki_markup( void ){
316 int i; /* loop over allowedAttr */
317
318 for( i=1 ; i<=sizeof(aMarkup)/sizeof(aMarkup[0]) - 1 ; i++ ){
319 @ &lt;%s(aMarkup[i].zName)&gt;
320 }
321 }
322
323 /*
324 ** Use binary search to locate a tag in the aMarkup[] table.
325 */
326 static int findTag(const char *z){
@@ -379,11 +401,10 @@
401 static int r = -1;
402 if( r<0 ) r = db_get_boolean("wiki-use-html", 0);
403 return r;
404 }
405
 
406 /*
407 ** z points to a "<" character. Check to see if this is the start of
408 ** a valid markup. If it is, return the total number of characters in
409 ** the markup including the initial "<" and the terminating ">". If
410 ** it is not well-formed markup, return 0.
@@ -393,15 +414,17 @@
414 int inparen = 0;
415 int c;
416 if( z[n]=='/' ){ n++; }
417 if( !isalpha(z[n]) ) return 0;
418 while( isalnum(z[n]) ){ n++; }
419 c = z[n];
420 if( c=='/' && z[n+1]=='>' ){ return n+2; }
421 if( c!='>' && !isspace(c) ) return 0;
422 while( (c = z[n])!=0 && (c!='>' || inparen) ){
423 if( c==inparen ){
424 inparen = 0;
425 }else if( inparen==0 && (c=='"' || c=='\'') ){
426 inparen = c;
427 }
428 n++;
429 }
430 if( z[n]!='>' ) return 0;
431
+23 -3
--- src/xfer.c
+++ src/xfer.c
@@ -119,22 +119,24 @@
119119
if( uuid_is_shunned(blob_str(&pXfer->aToken[1])) ){
120120
/* Ignore files that have been shunned */
121121
return;
122122
}
123123
if( pXfer->nToken==4 ){
124
- Blob src;
124
+ Blob src, next;
125125
srcid = rid_from_uuid(&pXfer->aToken[2], 1);
126126
if( content_get(srcid, &src)==0 ){
127127
rid = content_put(&content, blob_str(&pXfer->aToken[1]), srcid);
128128
pXfer->nDanglingFile++;
129129
db_multi_exec("DELETE FROM phantom WHERE rid=%d", rid);
130130
content_make_public(rid);
131131
return;
132132
}
133133
pXfer->nDeltaRcvd++;
134
- blob_delta_apply(&src, &content, &content);
134
+ blob_delta_apply(&src, &content, &next);
135135
blob_reset(&src);
136
+ blob_reset(&content);
137
+ content = next;
136138
}else{
137139
pXfer->nFileRcvd++;
138140
}
139141
sha1sum_blob(&content, &hash);
140142
if( !blob_eq_str(&pXfer->aToken[1], blob_str(&hash), -1) ){
@@ -476,11 +478,11 @@
476478
** But if we do (because of a bug) now is a good time to delete them. */
477479
db_multi_exec(
478480
"DELETE FROM unclustered WHERE rid IN (SELECT rid FROM private)"
479481
);
480482
481
- nUncl = db_int(0, "SELECT count(*) FROM unclustered"
483
+ nUncl = db_int(0, "SELECT count(*) FROM unclustered /*scan*/"
482484
" WHERE NOT EXISTS(SELECT 1 FROM phantom"
483485
" WHERE rid=unclustered.rid)");
484486
if( nUncl<100 ){
485487
return;
486488
}
@@ -593,10 +595,11 @@
593595
int deltaFlag = 0;
594596
int isClone = 0;
595597
int nGimme = 0;
596598
int size;
597599
int recvConfig = 0;
600
+ char *zNow;
598601
599602
if( strcmp(PD("REQUEST_METHOD","POST"),"POST") ){
600603
fossil_redirect_home();
601604
}
602605
memset(&xfer, 0, sizeof(xfer));
@@ -610,10 +613,12 @@
610613
611614
db_begin_transaction();
612615
db_multi_exec(
613616
"CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);"
614617
);
618
+ zNow = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%S', 'now')");
619
+ @ # timestamp %s(zNow)
615620
manifest_crosslink_begin();
616621
while( blob_line(xfer.pIn, &xfer.line) ){
617622
if( blob_buffer(&xfer.line)[0]=='#' ) continue;
618623
xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
619624
@@ -1082,10 +1087,25 @@
10821087
go = 0;
10831088
10841089
/* Process the reply that came back from the server */
10851090
while( blob_line(&recv, &xfer.line) ){
10861091
if( blob_buffer(&xfer.line)[0]=='#' ){
1092
+ const char *zLine = blob_buffer(&xfer.line);
1093
+ if( memcmp(zLine, "# timestamp ", 12)==0 ){
1094
+ char zTime[20];
1095
+ double rDiff;
1096
+ sqlite3_snprintf(sizeof(zTime), zTime, "%.19s", &zLine[12]);
1097
+ rDiff = db_double(9e99, "SELECT julianday('%q') - julianday('now')",
1098
+ zTime);
1099
+ if( rDiff<0.0 ) rDiff = -rDiff;
1100
+ if( rDiff>9e98 ) rDiff = 0.0;
1101
+ if( (rDiff*24.0*3600.0)>=60.0 ){
1102
+ fossil_warning("*** time skew *** server time differs by %s",
1103
+ db_timespan_name(rDiff));
1104
+ g.clockSkewSeen = 1;
1105
+ }
1106
+ }
10871107
continue;
10881108
}
10891109
xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
10901110
nCardRcvd++;
10911111
if( !g.cgiOutput && !g.fQuiet ){
10921112
10931113
ADDED win/Makefile.PellesCGMake
--- src/xfer.c
+++ src/xfer.c
@@ -119,22 +119,24 @@
119 if( uuid_is_shunned(blob_str(&pXfer->aToken[1])) ){
120 /* Ignore files that have been shunned */
121 return;
122 }
123 if( pXfer->nToken==4 ){
124 Blob src;
125 srcid = rid_from_uuid(&pXfer->aToken[2], 1);
126 if( content_get(srcid, &src)==0 ){
127 rid = content_put(&content, blob_str(&pXfer->aToken[1]), srcid);
128 pXfer->nDanglingFile++;
129 db_multi_exec("DELETE FROM phantom WHERE rid=%d", rid);
130 content_make_public(rid);
131 return;
132 }
133 pXfer->nDeltaRcvd++;
134 blob_delta_apply(&src, &content, &content);
135 blob_reset(&src);
 
 
136 }else{
137 pXfer->nFileRcvd++;
138 }
139 sha1sum_blob(&content, &hash);
140 if( !blob_eq_str(&pXfer->aToken[1], blob_str(&hash), -1) ){
@@ -476,11 +478,11 @@
476 ** But if we do (because of a bug) now is a good time to delete them. */
477 db_multi_exec(
478 "DELETE FROM unclustered WHERE rid IN (SELECT rid FROM private)"
479 );
480
481 nUncl = db_int(0, "SELECT count(*) FROM unclustered"
482 " WHERE NOT EXISTS(SELECT 1 FROM phantom"
483 " WHERE rid=unclustered.rid)");
484 if( nUncl<100 ){
485 return;
486 }
@@ -593,10 +595,11 @@
593 int deltaFlag = 0;
594 int isClone = 0;
595 int nGimme = 0;
596 int size;
597 int recvConfig = 0;
 
598
599 if( strcmp(PD("REQUEST_METHOD","POST"),"POST") ){
600 fossil_redirect_home();
601 }
602 memset(&xfer, 0, sizeof(xfer));
@@ -610,10 +613,12 @@
610
611 db_begin_transaction();
612 db_multi_exec(
613 "CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);"
614 );
 
 
615 manifest_crosslink_begin();
616 while( blob_line(xfer.pIn, &xfer.line) ){
617 if( blob_buffer(&xfer.line)[0]=='#' ) continue;
618 xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
619
@@ -1082,10 +1087,25 @@
1082 go = 0;
1083
1084 /* Process the reply that came back from the server */
1085 while( blob_line(&recv, &xfer.line) ){
1086 if( blob_buffer(&xfer.line)[0]=='#' ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1087 continue;
1088 }
1089 xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
1090 nCardRcvd++;
1091 if( !g.cgiOutput && !g.fQuiet ){
1092
1093 DDED win/Makefile.PellesCGMake
--- src/xfer.c
+++ src/xfer.c
@@ -119,22 +119,24 @@
119 if( uuid_is_shunned(blob_str(&pXfer->aToken[1])) ){
120 /* Ignore files that have been shunned */
121 return;
122 }
123 if( pXfer->nToken==4 ){
124 Blob src, next;
125 srcid = rid_from_uuid(&pXfer->aToken[2], 1);
126 if( content_get(srcid, &src)==0 ){
127 rid = content_put(&content, blob_str(&pXfer->aToken[1]), srcid);
128 pXfer->nDanglingFile++;
129 db_multi_exec("DELETE FROM phantom WHERE rid=%d", rid);
130 content_make_public(rid);
131 return;
132 }
133 pXfer->nDeltaRcvd++;
134 blob_delta_apply(&src, &content, &next);
135 blob_reset(&src);
136 blob_reset(&content);
137 content = next;
138 }else{
139 pXfer->nFileRcvd++;
140 }
141 sha1sum_blob(&content, &hash);
142 if( !blob_eq_str(&pXfer->aToken[1], blob_str(&hash), -1) ){
@@ -476,11 +478,11 @@
478 ** But if we do (because of a bug) now is a good time to delete them. */
479 db_multi_exec(
480 "DELETE FROM unclustered WHERE rid IN (SELECT rid FROM private)"
481 );
482
483 nUncl = db_int(0, "SELECT count(*) FROM unclustered /*scan*/"
484 " WHERE NOT EXISTS(SELECT 1 FROM phantom"
485 " WHERE rid=unclustered.rid)");
486 if( nUncl<100 ){
487 return;
488 }
@@ -593,10 +595,11 @@
595 int deltaFlag = 0;
596 int isClone = 0;
597 int nGimme = 0;
598 int size;
599 int recvConfig = 0;
600 char *zNow;
601
602 if( strcmp(PD("REQUEST_METHOD","POST"),"POST") ){
603 fossil_redirect_home();
604 }
605 memset(&xfer, 0, sizeof(xfer));
@@ -610,10 +613,12 @@
613
614 db_begin_transaction();
615 db_multi_exec(
616 "CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);"
617 );
618 zNow = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%S', 'now')");
619 @ # timestamp %s(zNow)
620 manifest_crosslink_begin();
621 while( blob_line(xfer.pIn, &xfer.line) ){
622 if( blob_buffer(&xfer.line)[0]=='#' ) continue;
623 xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
624
@@ -1082,10 +1087,25 @@
1087 go = 0;
1088
1089 /* Process the reply that came back from the server */
1090 while( blob_line(&recv, &xfer.line) ){
1091 if( blob_buffer(&xfer.line)[0]=='#' ){
1092 const char *zLine = blob_buffer(&xfer.line);
1093 if( memcmp(zLine, "# timestamp ", 12)==0 ){
1094 char zTime[20];
1095 double rDiff;
1096 sqlite3_snprintf(sizeof(zTime), zTime, "%.19s", &zLine[12]);
1097 rDiff = db_double(9e99, "SELECT julianday('%q') - julianday('now')",
1098 zTime);
1099 if( rDiff<0.0 ) rDiff = -rDiff;
1100 if( rDiff>9e98 ) rDiff = 0.0;
1101 if( (rDiff*24.0*3600.0)>=60.0 ){
1102 fossil_warning("*** time skew *** server time differs by %s",
1103 db_timespan_name(rDiff));
1104 g.clockSkewSeen = 1;
1105 }
1106 }
1107 continue;
1108 }
1109 xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
1110 nCardRcvd++;
1111 if( !g.cgiOutput && !g.fQuiet ){
1112
1113 DDED win/Makefile.PellesCGMake
--- a/win/Makefile.PellesCGMake
+++ b/win/Makefile.PellesCGMake
@@ -0,0 +1,80 @@
1
+# LITE3.h ../src/jim.h VERSION.h
2
+ -DSQLITE_ENABjim
3
+#
4
+# HowTo
5
+# -----
6
+#
7
+
8
+
9
+
10
+
11
+
12
+# =sqlite3DEFINES=C# LITE3.h ../src/jim.hh VERSION.h
13
+ -DSQLITE_ENABjim
14
+#
15
+# HowTo
16
+# -----
17
+#
18
+
19
+
20
+
21
+
22
+
23
+# =sqlite3DEFE:/fossil-w32/zlib/
24
+C
25
+SRC=add.c allrepo.c attach.c bag.c blob.c branch.c browse.c captcha.c cgi.c checkin.c checkout.c clearsign.c clone.c comformat.c configure.c content.c db.c delta.c deltacmd.c descendants.c diff.c diffcmd.c doc.c encode.c event.c file.c finfo.c graph.c http.c http_socket.c http_ssl.c http_transport.c info.c login.c main.c manifest.c md5.c merge.c merge3.c name.c pivot.c popen.c pqueue.c printf.c rebuild.c report.c rss.c schema.c search.c setup.c sha1.c shun.c skins.c stat.c style.c sync.c tag.c th_main.c timeline.c tkt.c tktsetup.c undo.c update.c url.c user.c verify.c vfile.c wiki.c wikiformat.c winhttp.c xfer.c zip.c
26
+ORIGSRC=$(foreach sf,$(m.h VERSION.h
27
+ -DSQLITE_ENABjim
28
+#
29
+# HowTo
30
+# -----
31
+#
32
+
33
+
34
+
35
+
36
+
37
+# =sqlite3DEFINES=C# LITE3# LITE3.h ../src/jim.h VERSION.h
38
+ -DSQLITE_ENABjim
39
+#
40
+# HowTo
41
+# -----
42
+#
43
+
44
+
45
+
46
+
47
+
48
+# =sqlite3DEFINES=C# LITE3.h ../src/jim.hh VERSION.h
49
+ -DSQLITE_ENABjim
50
+#
51
+# HowTo
52
+# -----
53
+#
54
+
55
+
56
+
57
+
58
+
59
+# =sqlite3DEF$(UTILS)
60
+#
61
+
62
+
63
+
64
+
65
+
66
+# =sqlite3DEFINES=C# LITE3.h ../src/jim.hh VERSION.h
67
+ -DSQLITE_EN# LITE3.h ../src/jim.h VERSION.h
68
+ -DSQLITE_ENABjim
69
+#
70
+# HowTo
71
+# -----
72
+#
73
+
74
+
75
+
76
+
77
+
78
+# LITE3.h ../src/jim versionh@12T,1E@15T,1d@1F8,3L@1IY,5g@1No,19@1YS,1J@1Zm,Z@1bh,c:*.obj
79
+ del /F *.c
80
+ del /F *.h headersr@1eT,6~RN2;
--- a/win/Makefile.PellesCGMake
+++ b/win/Makefile.PellesCGMake
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/win/Makefile.PellesCGMake
+++ b/win/Makefile.PellesCGMake
@@ -0,0 +1,80 @@
1 # LITE3.h ../src/jim.h VERSION.h
2 -DSQLITE_ENABjim
3 #
4 # HowTo
5 # -----
6 #
7
8
9
10
11
12 # =sqlite3DEFINES=C# LITE3.h ../src/jim.hh VERSION.h
13 -DSQLITE_ENABjim
14 #
15 # HowTo
16 # -----
17 #
18
19
20
21
22
23 # =sqlite3DEFE:/fossil-w32/zlib/
24 C
25 SRC=add.c allrepo.c attach.c bag.c blob.c branch.c browse.c captcha.c cgi.c checkin.c checkout.c clearsign.c clone.c comformat.c configure.c content.c db.c delta.c deltacmd.c descendants.c diff.c diffcmd.c doc.c encode.c event.c file.c finfo.c graph.c http.c http_socket.c http_ssl.c http_transport.c info.c login.c main.c manifest.c md5.c merge.c merge3.c name.c pivot.c popen.c pqueue.c printf.c rebuild.c report.c rss.c schema.c search.c setup.c sha1.c shun.c skins.c stat.c style.c sync.c tag.c th_main.c timeline.c tkt.c tktsetup.c undo.c update.c url.c user.c verify.c vfile.c wiki.c wikiformat.c winhttp.c xfer.c zip.c
26 ORIGSRC=$(foreach sf,$(m.h VERSION.h
27 -DSQLITE_ENABjim
28 #
29 # HowTo
30 # -----
31 #
32
33
34
35
36
37 # =sqlite3DEFINES=C# LITE3# LITE3.h ../src/jim.h VERSION.h
38 -DSQLITE_ENABjim
39 #
40 # HowTo
41 # -----
42 #
43
44
45
46
47
48 # =sqlite3DEFINES=C# LITE3.h ../src/jim.hh VERSION.h
49 -DSQLITE_ENABjim
50 #
51 # HowTo
52 # -----
53 #
54
55
56
57
58
59 # =sqlite3DEF$(UTILS)
60 #
61
62
63
64
65
66 # =sqlite3DEFINES=C# LITE3.h ../src/jim.hh VERSION.h
67 -DSQLITE_EN# LITE3.h ../src/jim.h VERSION.h
68 -DSQLITE_ENABjim
69 #
70 # HowTo
71 # -----
72 #
73
74
75
76
77
78 # LITE3.h ../src/jim versionh@12T,1E@15T,1d@1F8,3L@1IY,5g@1No,19@1YS,1J@1Zm,Z@1bh,c:*.obj
79 del /F *.c
80 del /F *.h headersr@1eT,6~RN2;
--- www/branching.wiki
+++ www/branching.wiki
@@ -155,10 +155,11 @@
155155
accident that stems from concurrent development. In figure 4, giving
156156
check-in 2 multiple children is a deliberate act. So, to a good
157157
approximation, we define forking to be by accident and branching to
158158
be by intent. Apart from that, they are the same.
159159
160
+<a name="tags"></a>
160161
<h2>Tags And Properties</h2>
161162
162163
Tags and properties are used in fossil to help express the intent, and
163164
thus to distinguish between forks and branches. Figure 5 shows the
164165
same scenario as figure 4 but with tags and properties added:
165166
166167
ADDED www/event.wiki
--- www/branching.wiki
+++ www/branching.wiki
@@ -155,10 +155,11 @@
155 accident that stems from concurrent development. In figure 4, giving
156 check-in 2 multiple children is a deliberate act. So, to a good
157 approximation, we define forking to be by accident and branching to
158 be by intent. Apart from that, they are the same.
159
 
160 <h2>Tags And Properties</h2>
161
162 Tags and properties are used in fossil to help express the intent, and
163 thus to distinguish between forks and branches. Figure 5 shows the
164 same scenario as figure 4 but with tags and properties added:
165
166 DDED www/event.wiki
--- www/branching.wiki
+++ www/branching.wiki
@@ -155,10 +155,11 @@
155 accident that stems from concurrent development. In figure 4, giving
156 check-in 2 multiple children is a deliberate act. So, to a good
157 approximation, we define forking to be by accident and branching to
158 be by intent. Apart from that, they are the same.
159
160 <a name="tags"></a>
161 <h2>Tags And Properties</h2>
162
163 Tags and properties are used in fossil to help express the intent, and
164 thus to distinguish between forks and branches. Figure 5 shows the
165 same scenario as figure 4 but with tags and properties added:
166
167 DDED www/event.wiki
--- a/www/event.wiki
+++ b/www/event.wiki
@@ -0,0 +1,35 @@
1
+<title>Eventes</title>
2
+
3
+<h2>What Is A "Event"?</h2>e?y=<titl
4
+Possible uses for technotes include:
5
+
6
+ * <b>Milestones</b>. Project milestones, such as releases or beta-test
7
+ cycles, can be recorded as technotes. The timeline entry for the technote
8
+ can be something simple like "Version 1.2.3" perhaps with a bright
9
+ color background to draw attention to the entry and the wiki content
10
+ can contain release notes, for example.
11
+
12
+ * <b>Blog Entries</b>. Blog entries from developers describing the current
13
+ state of a project, or rational for v arious design decisions, or
14
+ roadmaps for future development, can be entered as technotes.
15
+
16
+ * <b>Process Checkpoints</b>. For projects that have a formal process,
17
+ technotes can be used to record the completion or the initiation of
18
+ various process steps. For example, a technote can be used to record
19
+ the successful completion of a long-running test, perhaps w[./wikitheory.wiki | wiki page]
20
+that is associated with a point in time rather thaevent causes a si [/timelinhyperlink ofTimeline Page]entry cause a jump to the wiThe wiki content, the timeline entry text, the
21
+time of the eventTechnical Notes</title>
22
+
23
+<h2>What Is A "Technote"?</h2>
24
+
25
+In Fossil, a "technical note" or "technoteventerly called an "event")
26
+is a speeventiki page]
27
+that is associated with a point in time rather than having a page name.
28
+eventaving a page name.
29
+Each technote causes a single entry to appear on the
30
+[/timeline?y=<titl
31
+Possible uses for technotes include:
32
+
33
+ * <b>Milestones</b>. Project milestones, such as releases or beta-test
34
+ cycles, can be recorded as technotes. The timeline entry for the technote
35
+ can be something simple like "V
--- a/www/event.wiki
+++ b/www/event.wiki
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/www/event.wiki
+++ b/www/event.wiki
@@ -0,0 +1,35 @@
1 <title>Eventes</title>
2
3 <h2>What Is A "Event"?</h2>e?y=<titl
4 Possible uses for technotes include:
5
6 * <b>Milestones</b>. Project milestones, such as releases or beta-test
7 cycles, can be recorded as technotes. The timeline entry for the technote
8 can be something simple like "Version 1.2.3" perhaps with a bright
9 color background to draw attention to the entry and the wiki content
10 can contain release notes, for example.
11
12 * <b>Blog Entries</b>. Blog entries from developers describing the current
13 state of a project, or rational for v arious design decisions, or
14 roadmaps for future development, can be entered as technotes.
15
16 * <b>Process Checkpoints</b>. For projects that have a formal process,
17 technotes can be used to record the completion or the initiation of
18 various process steps. For example, a technote can be used to record
19 the successful completion of a long-running test, perhaps w[./wikitheory.wiki | wiki page]
20 that is associated with a point in time rather thaevent causes a si [/timelinhyperlink ofTimeline Page]entry cause a jump to the wiThe wiki content, the timeline entry text, the
21 time of the eventTechnical Notes</title>
22
23 <h2>What Is A "Technote"?</h2>
24
25 In Fossil, a "technical note" or "technoteventerly called an "event")
26 is a speeventiki page]
27 that is associated with a point in time rather than having a page name.
28 eventaving a page name.
29 Each technote causes a single entry to appear on the
30 [/timeline?y=<titl
31 Possible uses for technotes include:
32
33 * <b>Milestones</b>. Project milestones, such as releases or beta-test
34 cycles, can be recorded as technotes. The timeline entry for the technote
35 can be something simple like "V
+106 -13
--- www/fileformat.wiki
+++ www/fileformat.wiki
@@ -43,13 +43,14 @@
4343
<li> [#cluster | Clusters] </li>
4444
<li> [#ctrl | Control Artifacts] </li>
4545
<li> [#wikichng | Wiki Pages] </li>
4646
<li> [#tktchng | Ticket Changes] </li>
4747
<li> [#attachment | Attachments] </li>
48
+<li> [#event | Events] </li>
4849
</ul>
4950
50
-These five artifact types are described in the sequel.
51
+These seven artifact types are described in the sequel.
5152
5253
In the current implementation (as of 2009-01-25) the artifacts that
5354
make up a fossil repository are stored in in as delta- and zlib-compressed
5455
blobs in an <a href="http://www.sqlite.org/">SQLite</a> database. This
5556
is an implementation detail and might change in a future release. For
@@ -56,10 +57,13 @@
5657
the purpose of this article "file format" means the format of the artifacts,
5758
not how the artifacts are stored on disk. It is the artifact format that
5859
is intended to be enduring. The specifics of how artifacts are stored on
5960
disk, though stable, is not intended to live as long as the
6061
artifact format.
62
+
63
+All of the artifacts can be extracted from a Fossil repository using
64
+the "fossil deconstruct" command.
6165
6266
<a name="manifest"></a>
6367
<h2>1.0 The Manifest</h2>
6468
6569
A manifest defines a check-in or version of the project
@@ -165,12 +169,13 @@
165169
repository, append a single space (ASCII 0x20), the
166170
size of the file in ASCII decimal, a single newline
167171
character (ASCII 0x0A), and the complete text of the file.
168172
Compute the MD5 checksum of the result.
169173
170
-A manifest might contain one or more T-cards used to set tags or
171
-properties on the check-in. The format of the T-card is the same as
174
+A manifest might contain one or more T-cards used to set
175
+[./branching.wiki#tags | tags or properties]
176
+on the check-in. The format of the T-card is the same as
172177
described in <i>Control Artifacts</i> section below, except that the
173178
second argument is the single characcter "<b>*</b>" instead of an
174179
artifact ID. The <b>*</b> in place of the artifact ID indicates that
175180
the tag or property applies to the current artifact. It is not
176181
possible to encode the current artifact ID as part of an artifact,
@@ -182,11 +187,11 @@
182187
Each manifest has a single U-card. The argument to the U-card is
183188
the login of the user who created the manifest. The login name
184189
is encoded using the same character escapes as is used for the
185190
check-in comment argument to the C-card.
186191
187
-A manifest has an option Z-card as its last line. The argument
192
+A manifest has an optional Z-card as its last line. The argument
188193
to the Z-card is a 32-character lowercase hexadecimal MD5 hash
189194
of all prior lines of the manifest up to and including the newline
190195
character that immediately precedes the "Z". The Z-card is just
191196
a sanity check to prove that the manifest is well-formed and
192197
consistent.
@@ -262,11 +267,12 @@
262267
clearsigned.
263268
264269
The D card and the Z card of a control artifact are the same
265270
as in a manifest.
266271
267
-The T card represents a "tag" or property that is applied to
272
+The T card represents a [./branching.wiki#tags | tag or property]
273
+that is applied to
268274
some other artifact. The T card has two or three values. The
269275
second argument is the 40 character lowercase artifact ID of the artifact
270276
to which the tag is to be applied. The
271277
first value is the tag name. The first character of the tag
272278
is either "+", "-", or "*". A "+" means the tag should be added
@@ -324,11 +330,11 @@
324330
of text in the wiki page. That text follows the newline character
325331
that terminates the W card. The wiki text is always followed by one
326332
extra newline.
327333
328334
An example wiki artifact can be seen
329
-[/artifact/7b2f5fd0e0 | here].
335
+[/artifact?name=7b2f5fd0e0&txt=1 | here].
330336
331337
<a name="tktchng"></a>
332338
<h2>5.0 Ticket Changes</h2>
333339
334340
A ticket-change artifact represents a change to a trouble ticket.
@@ -375,25 +381,25 @@
375381
376382
<a name="attachment"></a>
377383
<h2>6.0 Attachments</h2>
378384
379385
An attachment artifact associates some other artifact that is the
380
-attachment (the source artifact) with a ticket or wiki page to which
386
+attachment (the source artifact) with a ticket or wiki page or event to which
381387
the attachment is connected (the target artifact).
382388
The following cards are allowed on an attachment artifact:
383389
384390
<blockquote>
385
-<b>A</b> <i>filename target</i> ?<i>source</i>?
386
-<b>C</b> <i>comment</i><br>
391
+<b>A</b> <i>filename target</i> ?<i>source</i>?<br />
392
+<b>C</b> <i>comment</i><br />
387393
<b>D</b> <i>time-and-date-stamp</i><br />
388394
<b>U</b> <i>user-name</i><br />
389395
<b>Z</b> <i>checksum</i>
390396
</blockquote>
391397
392398
The A card specifies a filename for the attachment in its first argument.
393399
The second argument to the A card is the name
394
-of the wiki page or ticket to which the attachment is connected. The
400
+of the wiki page or ticket or event to which the attachment is connected. The
395401
third argument is either missing or else it is the 40-character artifact
396402
ID of the attachment itself. A missing third argument means that the
397403
attachment should be deleted.
398404
399405
The C card is an optional comment describing what the attachment is about.
@@ -405,46 +411,111 @@
405411
A single U card gives the name of the user to added the attachment.
406412
If an attachment is added anonymously, then the U card may be omitted.
407413
408414
The Z card is the usual checksum over the rest of the attachment artifact.
409415
416
+
417
+<a name="event"></a>
418
+<h2>7.0 Events</h2>
419
+
420
+An event artifact associates a timeline comment and a page of text
421
+(similar to a wiki page) with a point in time. Events can be used
422
+to record project milestones, release notes, blog entries, process
423
+checkpoints, or news articles.
424
+The following cards are allowed on an event artifact:
425
+
426
+<blockquote>
427
+<b>C</b> <i>comment</i><br>
428
+<b>D</b> <i>time-and-date-stamp</i><br />
429
+<b>E</b> <i>event-time</i> <i>event-id</i><br />
430
+<b>P</b> <i>parent-artifact-id</i>+<br />
431
+<b>T</b> <b>+</b><i>tag-name</i> <b>*</b> <i>value</i><br />
432
+<b>U</b> <i>user-name</i><br />
433
+<b>W</b> <i>size</i> <b>\n</b> <i>text</i> <b>\n</b><br />
434
+<b>Z</b> <i>checksum</i>
435
+</blockquote>
436
+
437
+The C card contains text that is displayed on the timeline for the
438
+event. Exactly one C card is required on an event artifact.
439
+
440
+A single D card is required to give the date and time when the
441
+event artifact was created. This is different from the time at which
442
+the event occurs.
443
+
444
+A single E card gives the time of the event (the point on the timeline
445
+where the event is displayed) and a unique identifier for the event.
446
+When there are multiple artifacts with the same event-id, the one with
447
+the most recent D card is the only one used. The event-id must be a
448
+40-character lower-case hexadecimal string.
449
+
450
+The option P card specifies a prior event with the same event-id from
451
+which the current event is an edit. The P card is a hint to the system
452
+that it might be space efficient to store one event as a delta of the
453
+other.
454
+
455
+An event might contain one or more T-cards used to set
456
+[./branching.wiki#tags | tags or properties]
457
+on the event. The format of the T-card is the same as
458
+described in [#ctrl | Control Artifacts] section above, except that the
459
+second argument is the single characcter "<b>*</b>" instead of an
460
+artifact ID and the name is always prefaced by "<b>+</b>".
461
+The <b>*</b> in place of the artifact ID indicates that
462
+the tag or property applies to the current artifact. It is not
463
+possible to encode the current artifact ID as part of an artifact,
464
+since the act of inserting the artifact ID would change the artifact ID,
465
+hence a <b>*</b> is used to represent "self". The "<b>+</b>" on the
466
+name means that tags can only be add and they can only be non-propagating
467
+tags. A an event, T cards are normally used to set the background
468
+display color for timelines.
469
+
470
+The optional U card gives name of the user who entered the event.
471
+
472
+A single W card provides wiki text for the document associated with the
473
+event. The format of the W card is exactly the same as for a
474
+[#wikichng | wiki artifact].
475
+
476
+The Z card is the usual checksum over the rest of the attachment artifact.
477
+
410478
411479
<a name="summary"></a>
412
-<h2>7.0 Card Summary</h2>
480
+<h2>8.0 Card Summary</h2>
413481
414482
The following table summaries the various kinds of cards that
415483
appear on Fossil artifacts:
416484
417485
<table border=1 width="100%">
418486
<tr>
419487
<th rowspan=2 valign=bottom>Card Format</th>
420
-<th colspan=6>Used By</th>
488
+<th colspan=7>Used By</th>
421489
</tr>
422490
<tr>
423491
<th>Manifest</th>
424492
<th>Cluster</th>
425493
<th>Control</th>
426494
<th>Wiki</th>
427495
<th>Ticket</th>
428496
<th>Attachment</th>
497
+<th>Event</th>
429498
</tr>
430499
<tr>
431500
<td><b>A</b> <i>filename target source</i></td>
432501
<td>&nbsp;</td>
433502
<td>&nbsp;</td>
434503
<td>&nbsp;</td>
435504
<td>&nbsp;</td>
436505
<td>&nbsp;</td>
437506
<td align=center><b>X</b></td>
507
+<td>&nbsp;</td>
438508
</tr>
439509
<tr>
440
-<td><b>C</b> <i>coment-text</i></td>
510
+<td><b>C</b> <i>comment-text</i></td>
441511
<td align=center><b>X</b></td>
442512
<td>&nbsp;</td>
443513
<td>&nbsp;</td>
444514
<td>&nbsp;</td>
445515
<td>&nbsp;</td>
516
+<td align=center><b>X</b></td>
446517
<td align=center><b>X</b></td>
447518
</tr>
448519
<tr>
449520
<td><b>D</b> <i>date-time-stamp</i></td>
450521
<td align=center><b>X</b></td>
@@ -451,14 +522,26 @@
451522
<td align=center>&nbsp;</td>
452523
<td align=center><b>X</b></td>
453524
<td align=center><b>X</b></td>
454525
<td align=center><b>X</b></td>
455526
<td align=center><b>X</b></td>
527
+<td align=center><b>X</b></td>
528
+</tr>
529
+<tr>
530
+<td><b>E</b> <i>event-time event-id</i></td>
531
+<td align=center>&nbsp;</td>
532
+<td align=center>&nbsp;</td>
533
+<td align=center>&nbsp;</td>
534
+<td align=center>&nbsp;</td>
535
+<td align=center>&nbsp;</td>
536
+<td align=center>&nbsp;</td>
537
+<td align=center><b>X</b></td>
456538
</tr>
457539
<tr>
458540
<td><b>F</b> <i>filename uuid permissions oldname</i></td>
459541
<td align=center><b>X</b></td>
542
+<td align=center>&nbsp;</td>
460543
<td align=center>&nbsp;</td>
461544
<td align=center>&nbsp;</td>
462545
<td align=center>&nbsp;</td>
463546
<td align=center>&nbsp;</td>
464547
<td align=center>&nbsp;</td>
@@ -469,18 +552,20 @@
469552
<td align=center>&nbsp;</td>
470553
<td align=center>&nbsp;</td>
471554
<td align=center>&nbsp;</td>
472555
<td align=center><b>X</b></td>
473556
<td align=center>&nbsp;</td>
557
+<td align=center>&nbsp;</td>
474558
</tr>
475559
<tr>
476560
<td><b>K</b> <i>ticket-uuid</i></td>
477561
<td align=center>&nbsp;</td>
478562
<td align=center>&nbsp;</td>
479563
<td align=center>&nbsp;</td>
480564
<td align=center>&nbsp;</td>
481565
<td align=center><b>X</b></td>
566
+<td align=center>&nbsp;</td>
482567
<td align=center>&nbsp;</td>
483568
</tr>
484569
<tr>
485570
<td><b>L</b> <i>wiki-title</i></td>
486571
<td align=center>&nbsp;</td>
@@ -487,15 +572,17 @@
487572
<td align=center>&nbsp;</td>
488573
<td align=center>&nbsp;</td>
489574
<td align=center><b>X</b></td>
490575
<td align=center>&nbsp;</td>
491576
<td align=center>&nbsp;</td>
577
+<td align=center>&nbsp;</td>
492578
</tr>
493579
<tr>
494580
<td><b>M</b> <i>uuid</i></td>
495581
<td align=center>&nbsp;</td>
496582
<td align=center><b>X</b></td>
583
+<td align=center>&nbsp;</td>
497584
<td align=center>&nbsp;</td>
498585
<td align=center>&nbsp;</td>
499586
<td align=center>&nbsp;</td>
500587
<td align=center>&nbsp;</td>
501588
</tr>
@@ -505,14 +592,16 @@
505592
<td align=center>&nbsp;</td>
506593
<td align=center>&nbsp;</td>
507594
<td align=center><b>X</b></td>
508595
<td align=center>&nbsp;</td>
509596
<td align=center>&nbsp;</td>
597
+<td align=center>&nbsp;</td>
510598
</tr>
511599
<tr>
512600
<td><b>R</b> <i>md5sum</i></td>
513601
<td align=center><b>X</b></td>
602
+<td align=center>&nbsp;</td>
514603
<td align=center>&nbsp;</td>
515604
<td align=center>&nbsp;</td>
516605
<td align=center>&nbsp;</td>
517606
<td align=center>&nbsp;</td>
518607
<td align=center>&nbsp;</td>
@@ -522,15 +611,17 @@
522611
<td align=center>&nbsp;</td>
523612
<td align=center><b>X</b></td>
524613
<td align=center>&nbsp;</td>
525614
<td align=center>&nbsp;</td>
526615
<td align=center>&nbsp;</td>
616
+<td align=center><b>X</b></td>
527617
</tr>
528618
<tr>
529619
<td><b>U</b> <i>username</i></td>
530620
<td align=center><b>X</b></td>
531621
<td align=center>&nbsp;</td>
622
+<td align=center><b>X</b></td>
532623
<td align=center><b>X</b></td>
533624
<td align=center><b>X</b></td>
534625
<td align=center><b>X</b></td>
535626
<td align=center><b>X</b></td>
536627
</tr>
@@ -540,16 +631,18 @@
540631
<td align=center>&nbsp;</td>
541632
<td align=center>&nbsp;</td>
542633
<td align=center><b>X</b></td>
543634
<td align=center>&nbsp;</td>
544635
<td align=center>&nbsp;</td>
636
+<td align=center><b>X</b></td>
545637
</tr>
546638
<tr>
547639
<td><b>Z</b> <i>md5sum</i></td>
640
+<td align=center><b>X</b></td>
548641
<td align=center><b>X</b></td>
549642
<td align=center><b>X</b></td>
550643
<td align=center><b>X</b></td>
551644
<td align=center><b>X</b></td>
552645
<td align=center><b>X</b></td>
553646
<td align=center><b>X</b></td>
554647
</tr>
555648
</table>
556649
--- www/fileformat.wiki
+++ www/fileformat.wiki
@@ -43,13 +43,14 @@
43 <li> [#cluster | Clusters] </li>
44 <li> [#ctrl | Control Artifacts] </li>
45 <li> [#wikichng | Wiki Pages] </li>
46 <li> [#tktchng | Ticket Changes] </li>
47 <li> [#attachment | Attachments] </li>
 
48 </ul>
49
50 These five artifact types are described in the sequel.
51
52 In the current implementation (as of 2009-01-25) the artifacts that
53 make up a fossil repository are stored in in as delta- and zlib-compressed
54 blobs in an <a href="http://www.sqlite.org/">SQLite</a> database. This
55 is an implementation detail and might change in a future release. For
@@ -56,10 +57,13 @@
56 the purpose of this article "file format" means the format of the artifacts,
57 not how the artifacts are stored on disk. It is the artifact format that
58 is intended to be enduring. The specifics of how artifacts are stored on
59 disk, though stable, is not intended to live as long as the
60 artifact format.
 
 
 
61
62 <a name="manifest"></a>
63 <h2>1.0 The Manifest</h2>
64
65 A manifest defines a check-in or version of the project
@@ -165,12 +169,13 @@
165 repository, append a single space (ASCII 0x20), the
166 size of the file in ASCII decimal, a single newline
167 character (ASCII 0x0A), and the complete text of the file.
168 Compute the MD5 checksum of the result.
169
170 A manifest might contain one or more T-cards used to set tags or
171 properties on the check-in. The format of the T-card is the same as
 
172 described in <i>Control Artifacts</i> section below, except that the
173 second argument is the single characcter "<b>*</b>" instead of an
174 artifact ID. The <b>*</b> in place of the artifact ID indicates that
175 the tag or property applies to the current artifact. It is not
176 possible to encode the current artifact ID as part of an artifact,
@@ -182,11 +187,11 @@
182 Each manifest has a single U-card. The argument to the U-card is
183 the login of the user who created the manifest. The login name
184 is encoded using the same character escapes as is used for the
185 check-in comment argument to the C-card.
186
187 A manifest has an option Z-card as its last line. The argument
188 to the Z-card is a 32-character lowercase hexadecimal MD5 hash
189 of all prior lines of the manifest up to and including the newline
190 character that immediately precedes the "Z". The Z-card is just
191 a sanity check to prove that the manifest is well-formed and
192 consistent.
@@ -262,11 +267,12 @@
262 clearsigned.
263
264 The D card and the Z card of a control artifact are the same
265 as in a manifest.
266
267 The T card represents a "tag" or property that is applied to
 
268 some other artifact. The T card has two or three values. The
269 second argument is the 40 character lowercase artifact ID of the artifact
270 to which the tag is to be applied. The
271 first value is the tag name. The first character of the tag
272 is either "+", "-", or "*". A "+" means the tag should be added
@@ -324,11 +330,11 @@
324 of text in the wiki page. That text follows the newline character
325 that terminates the W card. The wiki text is always followed by one
326 extra newline.
327
328 An example wiki artifact can be seen
329 [/artifact/7b2f5fd0e0 | here].
330
331 <a name="tktchng"></a>
332 <h2>5.0 Ticket Changes</h2>
333
334 A ticket-change artifact represents a change to a trouble ticket.
@@ -375,25 +381,25 @@
375
376 <a name="attachment"></a>
377 <h2>6.0 Attachments</h2>
378
379 An attachment artifact associates some other artifact that is the
380 attachment (the source artifact) with a ticket or wiki page to which
381 the attachment is connected (the target artifact).
382 The following cards are allowed on an attachment artifact:
383
384 <blockquote>
385 <b>A</b> <i>filename target</i> ?<i>source</i>?
386 <b>C</b> <i>comment</i><br>
387 <b>D</b> <i>time-and-date-stamp</i><br />
388 <b>U</b> <i>user-name</i><br />
389 <b>Z</b> <i>checksum</i>
390 </blockquote>
391
392 The A card specifies a filename for the attachment in its first argument.
393 The second argument to the A card is the name
394 of the wiki page or ticket to which the attachment is connected. The
395 third argument is either missing or else it is the 40-character artifact
396 ID of the attachment itself. A missing third argument means that the
397 attachment should be deleted.
398
399 The C card is an optional comment describing what the attachment is about.
@@ -405,46 +411,111 @@
405 A single U card gives the name of the user to added the attachment.
406 If an attachment is added anonymously, then the U card may be omitted.
407
408 The Z card is the usual checksum over the rest of the attachment artifact.
409
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
410
411 <a name="summary"></a>
412 <h2>7.0 Card Summary</h2>
413
414 The following table summaries the various kinds of cards that
415 appear on Fossil artifacts:
416
417 <table border=1 width="100%">
418 <tr>
419 <th rowspan=2 valign=bottom>Card Format</th>
420 <th colspan=6>Used By</th>
421 </tr>
422 <tr>
423 <th>Manifest</th>
424 <th>Cluster</th>
425 <th>Control</th>
426 <th>Wiki</th>
427 <th>Ticket</th>
428 <th>Attachment</th>
 
429 </tr>
430 <tr>
431 <td><b>A</b> <i>filename target source</i></td>
432 <td>&nbsp;</td>
433 <td>&nbsp;</td>
434 <td>&nbsp;</td>
435 <td>&nbsp;</td>
436 <td>&nbsp;</td>
437 <td align=center><b>X</b></td>
 
438 </tr>
439 <tr>
440 <td><b>C</b> <i>coment-text</i></td>
441 <td align=center><b>X</b></td>
442 <td>&nbsp;</td>
443 <td>&nbsp;</td>
444 <td>&nbsp;</td>
445 <td>&nbsp;</td>
 
446 <td align=center><b>X</b></td>
447 </tr>
448 <tr>
449 <td><b>D</b> <i>date-time-stamp</i></td>
450 <td align=center><b>X</b></td>
@@ -451,14 +522,26 @@
451 <td align=center>&nbsp;</td>
452 <td align=center><b>X</b></td>
453 <td align=center><b>X</b></td>
454 <td align=center><b>X</b></td>
455 <td align=center><b>X</b></td>
 
 
 
 
 
 
 
 
 
 
 
456 </tr>
457 <tr>
458 <td><b>F</b> <i>filename uuid permissions oldname</i></td>
459 <td align=center><b>X</b></td>
 
460 <td align=center>&nbsp;</td>
461 <td align=center>&nbsp;</td>
462 <td align=center>&nbsp;</td>
463 <td align=center>&nbsp;</td>
464 <td align=center>&nbsp;</td>
@@ -469,18 +552,20 @@
469 <td align=center>&nbsp;</td>
470 <td align=center>&nbsp;</td>
471 <td align=center>&nbsp;</td>
472 <td align=center><b>X</b></td>
473 <td align=center>&nbsp;</td>
 
474 </tr>
475 <tr>
476 <td><b>K</b> <i>ticket-uuid</i></td>
477 <td align=center>&nbsp;</td>
478 <td align=center>&nbsp;</td>
479 <td align=center>&nbsp;</td>
480 <td align=center>&nbsp;</td>
481 <td align=center><b>X</b></td>
 
482 <td align=center>&nbsp;</td>
483 </tr>
484 <tr>
485 <td><b>L</b> <i>wiki-title</i></td>
486 <td align=center>&nbsp;</td>
@@ -487,15 +572,17 @@
487 <td align=center>&nbsp;</td>
488 <td align=center>&nbsp;</td>
489 <td align=center><b>X</b></td>
490 <td align=center>&nbsp;</td>
491 <td align=center>&nbsp;</td>
 
492 </tr>
493 <tr>
494 <td><b>M</b> <i>uuid</i></td>
495 <td align=center>&nbsp;</td>
496 <td align=center><b>X</b></td>
 
497 <td align=center>&nbsp;</td>
498 <td align=center>&nbsp;</td>
499 <td align=center>&nbsp;</td>
500 <td align=center>&nbsp;</td>
501 </tr>
@@ -505,14 +592,16 @@
505 <td align=center>&nbsp;</td>
506 <td align=center>&nbsp;</td>
507 <td align=center><b>X</b></td>
508 <td align=center>&nbsp;</td>
509 <td align=center>&nbsp;</td>
 
510 </tr>
511 <tr>
512 <td><b>R</b> <i>md5sum</i></td>
513 <td align=center><b>X</b></td>
 
514 <td align=center>&nbsp;</td>
515 <td align=center>&nbsp;</td>
516 <td align=center>&nbsp;</td>
517 <td align=center>&nbsp;</td>
518 <td align=center>&nbsp;</td>
@@ -522,15 +611,17 @@
522 <td align=center>&nbsp;</td>
523 <td align=center><b>X</b></td>
524 <td align=center>&nbsp;</td>
525 <td align=center>&nbsp;</td>
526 <td align=center>&nbsp;</td>
 
527 </tr>
528 <tr>
529 <td><b>U</b> <i>username</i></td>
530 <td align=center><b>X</b></td>
531 <td align=center>&nbsp;</td>
 
532 <td align=center><b>X</b></td>
533 <td align=center><b>X</b></td>
534 <td align=center><b>X</b></td>
535 <td align=center><b>X</b></td>
536 </tr>
@@ -540,16 +631,18 @@
540 <td align=center>&nbsp;</td>
541 <td align=center>&nbsp;</td>
542 <td align=center><b>X</b></td>
543 <td align=center>&nbsp;</td>
544 <td align=center>&nbsp;</td>
 
545 </tr>
546 <tr>
547 <td><b>Z</b> <i>md5sum</i></td>
 
548 <td align=center><b>X</b></td>
549 <td align=center><b>X</b></td>
550 <td align=center><b>X</b></td>
551 <td align=center><b>X</b></td>
552 <td align=center><b>X</b></td>
553 <td align=center><b>X</b></td>
554 </tr>
555 </table>
556
--- www/fileformat.wiki
+++ www/fileformat.wiki
@@ -43,13 +43,14 @@
43 <li> [#cluster | Clusters] </li>
44 <li> [#ctrl | Control Artifacts] </li>
45 <li> [#wikichng | Wiki Pages] </li>
46 <li> [#tktchng | Ticket Changes] </li>
47 <li> [#attachment | Attachments] </li>
48 <li> [#event | Events] </li>
49 </ul>
50
51 These seven artifact types are described in the sequel.
52
53 In the current implementation (as of 2009-01-25) the artifacts that
54 make up a fossil repository are stored in in as delta- and zlib-compressed
55 blobs in an <a href="http://www.sqlite.org/">SQLite</a> database. This
56 is an implementation detail and might change in a future release. For
@@ -56,10 +57,13 @@
57 the purpose of this article "file format" means the format of the artifacts,
58 not how the artifacts are stored on disk. It is the artifact format that
59 is intended to be enduring. The specifics of how artifacts are stored on
60 disk, though stable, is not intended to live as long as the
61 artifact format.
62
63 All of the artifacts can be extracted from a Fossil repository using
64 the "fossil deconstruct" command.
65
66 <a name="manifest"></a>
67 <h2>1.0 The Manifest</h2>
68
69 A manifest defines a check-in or version of the project
@@ -165,12 +169,13 @@
169 repository, append a single space (ASCII 0x20), the
170 size of the file in ASCII decimal, a single newline
171 character (ASCII 0x0A), and the complete text of the file.
172 Compute the MD5 checksum of the result.
173
174 A manifest might contain one or more T-cards used to set
175 [./branching.wiki#tags | tags or properties]
176 on the check-in. The format of the T-card is the same as
177 described in <i>Control Artifacts</i> section below, except that the
178 second argument is the single characcter "<b>*</b>" instead of an
179 artifact ID. The <b>*</b> in place of the artifact ID indicates that
180 the tag or property applies to the current artifact. It is not
181 possible to encode the current artifact ID as part of an artifact,
@@ -182,11 +187,11 @@
187 Each manifest has a single U-card. The argument to the U-card is
188 the login of the user who created the manifest. The login name
189 is encoded using the same character escapes as is used for the
190 check-in comment argument to the C-card.
191
192 A manifest has an optional Z-card as its last line. The argument
193 to the Z-card is a 32-character lowercase hexadecimal MD5 hash
194 of all prior lines of the manifest up to and including the newline
195 character that immediately precedes the "Z". The Z-card is just
196 a sanity check to prove that the manifest is well-formed and
197 consistent.
@@ -262,11 +267,12 @@
267 clearsigned.
268
269 The D card and the Z card of a control artifact are the same
270 as in a manifest.
271
272 The T card represents a [./branching.wiki#tags | tag or property]
273 that is applied to
274 some other artifact. The T card has two or three values. The
275 second argument is the 40 character lowercase artifact ID of the artifact
276 to which the tag is to be applied. The
277 first value is the tag name. The first character of the tag
278 is either "+", "-", or "*". A "+" means the tag should be added
@@ -324,11 +330,11 @@
330 of text in the wiki page. That text follows the newline character
331 that terminates the W card. The wiki text is always followed by one
332 extra newline.
333
334 An example wiki artifact can be seen
335 [/artifact?name=7b2f5fd0e0&txt=1 | here].
336
337 <a name="tktchng"></a>
338 <h2>5.0 Ticket Changes</h2>
339
340 A ticket-change artifact represents a change to a trouble ticket.
@@ -375,25 +381,25 @@
381
382 <a name="attachment"></a>
383 <h2>6.0 Attachments</h2>
384
385 An attachment artifact associates some other artifact that is the
386 attachment (the source artifact) with a ticket or wiki page or event to which
387 the attachment is connected (the target artifact).
388 The following cards are allowed on an attachment artifact:
389
390 <blockquote>
391 <b>A</b> <i>filename target</i> ?<i>source</i>?<br />
392 <b>C</b> <i>comment</i><br />
393 <b>D</b> <i>time-and-date-stamp</i><br />
394 <b>U</b> <i>user-name</i><br />
395 <b>Z</b> <i>checksum</i>
396 </blockquote>
397
398 The A card specifies a filename for the attachment in its first argument.
399 The second argument to the A card is the name
400 of the wiki page or ticket or event to which the attachment is connected. The
401 third argument is either missing or else it is the 40-character artifact
402 ID of the attachment itself. A missing third argument means that the
403 attachment should be deleted.
404
405 The C card is an optional comment describing what the attachment is about.
@@ -405,46 +411,111 @@
411 A single U card gives the name of the user to added the attachment.
412 If an attachment is added anonymously, then the U card may be omitted.
413
414 The Z card is the usual checksum over the rest of the attachment artifact.
415
416
417 <a name="event"></a>
418 <h2>7.0 Events</h2>
419
420 An event artifact associates a timeline comment and a page of text
421 (similar to a wiki page) with a point in time. Events can be used
422 to record project milestones, release notes, blog entries, process
423 checkpoints, or news articles.
424 The following cards are allowed on an event artifact:
425
426 <blockquote>
427 <b>C</b> <i>comment</i><br>
428 <b>D</b> <i>time-and-date-stamp</i><br />
429 <b>E</b> <i>event-time</i> <i>event-id</i><br />
430 <b>P</b> <i>parent-artifact-id</i>+<br />
431 <b>T</b> <b>+</b><i>tag-name</i> <b>*</b> <i>value</i><br />
432 <b>U</b> <i>user-name</i><br />
433 <b>W</b> <i>size</i> <b>\n</b> <i>text</i> <b>\n</b><br />
434 <b>Z</b> <i>checksum</i>
435 </blockquote>
436
437 The C card contains text that is displayed on the timeline for the
438 event. Exactly one C card is required on an event artifact.
439
440 A single D card is required to give the date and time when the
441 event artifact was created. This is different from the time at which
442 the event occurs.
443
444 A single E card gives the time of the event (the point on the timeline
445 where the event is displayed) and a unique identifier for the event.
446 When there are multiple artifacts with the same event-id, the one with
447 the most recent D card is the only one used. The event-id must be a
448 40-character lower-case hexadecimal string.
449
450 The option P card specifies a prior event with the same event-id from
451 which the current event is an edit. The P card is a hint to the system
452 that it might be space efficient to store one event as a delta of the
453 other.
454
455 An event might contain one or more T-cards used to set
456 [./branching.wiki#tags | tags or properties]
457 on the event. The format of the T-card is the same as
458 described in [#ctrl | Control Artifacts] section above, except that the
459 second argument is the single characcter "<b>*</b>" instead of an
460 artifact ID and the name is always prefaced by "<b>+</b>".
461 The <b>*</b> in place of the artifact ID indicates that
462 the tag or property applies to the current artifact. It is not
463 possible to encode the current artifact ID as part of an artifact,
464 since the act of inserting the artifact ID would change the artifact ID,
465 hence a <b>*</b> is used to represent "self". The "<b>+</b>" on the
466 name means that tags can only be add and they can only be non-propagating
467 tags. A an event, T cards are normally used to set the background
468 display color for timelines.
469
470 The optional U card gives name of the user who entered the event.
471
472 A single W card provides wiki text for the document associated with the
473 event. The format of the W card is exactly the same as for a
474 [#wikichng | wiki artifact].
475
476 The Z card is the usual checksum over the rest of the attachment artifact.
477
478
479 <a name="summary"></a>
480 <h2>8.0 Card Summary</h2>
481
482 The following table summaries the various kinds of cards that
483 appear on Fossil artifacts:
484
485 <table border=1 width="100%">
486 <tr>
487 <th rowspan=2 valign=bottom>Card Format</th>
488 <th colspan=7>Used By</th>
489 </tr>
490 <tr>
491 <th>Manifest</th>
492 <th>Cluster</th>
493 <th>Control</th>
494 <th>Wiki</th>
495 <th>Ticket</th>
496 <th>Attachment</th>
497 <th>Event</th>
498 </tr>
499 <tr>
500 <td><b>A</b> <i>filename target source</i></td>
501 <td>&nbsp;</td>
502 <td>&nbsp;</td>
503 <td>&nbsp;</td>
504 <td>&nbsp;</td>
505 <td>&nbsp;</td>
506 <td align=center><b>X</b></td>
507 <td>&nbsp;</td>
508 </tr>
509 <tr>
510 <td><b>C</b> <i>comment-text</i></td>
511 <td align=center><b>X</b></td>
512 <td>&nbsp;</td>
513 <td>&nbsp;</td>
514 <td>&nbsp;</td>
515 <td>&nbsp;</td>
516 <td align=center><b>X</b></td>
517 <td align=center><b>X</b></td>
518 </tr>
519 <tr>
520 <td><b>D</b> <i>date-time-stamp</i></td>
521 <td align=center><b>X</b></td>
@@ -451,14 +522,26 @@
522 <td align=center>&nbsp;</td>
523 <td align=center><b>X</b></td>
524 <td align=center><b>X</b></td>
525 <td align=center><b>X</b></td>
526 <td align=center><b>X</b></td>
527 <td align=center><b>X</b></td>
528 </tr>
529 <tr>
530 <td><b>E</b> <i>event-time event-id</i></td>
531 <td align=center>&nbsp;</td>
532 <td align=center>&nbsp;</td>
533 <td align=center>&nbsp;</td>
534 <td align=center>&nbsp;</td>
535 <td align=center>&nbsp;</td>
536 <td align=center>&nbsp;</td>
537 <td align=center><b>X</b></td>
538 </tr>
539 <tr>
540 <td><b>F</b> <i>filename uuid permissions oldname</i></td>
541 <td align=center><b>X</b></td>
542 <td align=center>&nbsp;</td>
543 <td align=center>&nbsp;</td>
544 <td align=center>&nbsp;</td>
545 <td align=center>&nbsp;</td>
546 <td align=center>&nbsp;</td>
547 <td align=center>&nbsp;</td>
@@ -469,18 +552,20 @@
552 <td align=center>&nbsp;</td>
553 <td align=center>&nbsp;</td>
554 <td align=center>&nbsp;</td>
555 <td align=center><b>X</b></td>
556 <td align=center>&nbsp;</td>
557 <td align=center>&nbsp;</td>
558 </tr>
559 <tr>
560 <td><b>K</b> <i>ticket-uuid</i></td>
561 <td align=center>&nbsp;</td>
562 <td align=center>&nbsp;</td>
563 <td align=center>&nbsp;</td>
564 <td align=center>&nbsp;</td>
565 <td align=center><b>X</b></td>
566 <td align=center>&nbsp;</td>
567 <td align=center>&nbsp;</td>
568 </tr>
569 <tr>
570 <td><b>L</b> <i>wiki-title</i></td>
571 <td align=center>&nbsp;</td>
@@ -487,15 +572,17 @@
572 <td align=center>&nbsp;</td>
573 <td align=center>&nbsp;</td>
574 <td align=center><b>X</b></td>
575 <td align=center>&nbsp;</td>
576 <td align=center>&nbsp;</td>
577 <td align=center>&nbsp;</td>
578 </tr>
579 <tr>
580 <td><b>M</b> <i>uuid</i></td>
581 <td align=center>&nbsp;</td>
582 <td align=center><b>X</b></td>
583 <td align=center>&nbsp;</td>
584 <td align=center>&nbsp;</td>
585 <td align=center>&nbsp;</td>
586 <td align=center>&nbsp;</td>
587 <td align=center>&nbsp;</td>
588 </tr>
@@ -505,14 +592,16 @@
592 <td align=center>&nbsp;</td>
593 <td align=center>&nbsp;</td>
594 <td align=center><b>X</b></td>
595 <td align=center>&nbsp;</td>
596 <td align=center>&nbsp;</td>
597 <td align=center>&nbsp;</td>
598 </tr>
599 <tr>
600 <td><b>R</b> <i>md5sum</i></td>
601 <td align=center><b>X</b></td>
602 <td align=center>&nbsp;</td>
603 <td align=center>&nbsp;</td>
604 <td align=center>&nbsp;</td>
605 <td align=center>&nbsp;</td>
606 <td align=center>&nbsp;</td>
607 <td align=center>&nbsp;</td>
@@ -522,15 +611,17 @@
611 <td align=center>&nbsp;</td>
612 <td align=center><b>X</b></td>
613 <td align=center>&nbsp;</td>
614 <td align=center>&nbsp;</td>
615 <td align=center>&nbsp;</td>
616 <td align=center><b>X</b></td>
617 </tr>
618 <tr>
619 <td><b>U</b> <i>username</i></td>
620 <td align=center><b>X</b></td>
621 <td align=center>&nbsp;</td>
622 <td align=center><b>X</b></td>
623 <td align=center><b>X</b></td>
624 <td align=center><b>X</b></td>
625 <td align=center><b>X</b></td>
626 <td align=center><b>X</b></td>
627 </tr>
@@ -540,16 +631,18 @@
631 <td align=center>&nbsp;</td>
632 <td align=center>&nbsp;</td>
633 <td align=center><b>X</b></td>
634 <td align=center>&nbsp;</td>
635 <td align=center>&nbsp;</td>
636 <td align=center><b>X</b></td>
637 </tr>
638 <tr>
639 <td><b>Z</b> <i>md5sum</i></td>
640 <td align=center><b>X</b></td>
641 <td align=center><b>X</b></td>
642 <td align=center><b>X</b></td>
643 <td align=center><b>X</b></td>
644 <td align=center><b>X</b></td>
645 <td align=center><b>X</b></td>
646 <td align=center><b>X</b></td>
647 </tr>
648 </table>
649
+5 -2
--- www/index.wiki
+++ www/index.wiki
@@ -40,12 +40,13 @@
4040
internet these days. What makes Fossil worthy of attention?
4141
4242
1. <b>Bug Tracking And Wiki</b> -
4343
In addition to doing [./concepts.wiki | distributed version control]
4444
like Git and Mercurial,
45
- Fossil also supports [./bugtheory.wiki | distributed bug tracking] and
46
- [./wikitheory.wiki | distributed wiki] all in a single
45
+ Fossil also supports [./bugtheory.wiki | distributed bug tracking],
46
+ [./wikitheory.wiki | distributed wiki], and a
47
+ [./event.wiki | distributed blog] mechanism all in a single
4748
integrated package.
4849
4950
2. <b>Web Interface</b> -
5051
Fossil has a built-in and easy-to-use [./webui.wiki | web interface]
5152
that simplifies project tracking and promotes situational awareness.
@@ -111,10 +112,12 @@
111112
* A tutorial on [./branching.wiki | branching], what it means and how
112113
to do it using fossil.
113114
* The [./selfcheck.wiki | automatic self-check] mechanism
114115
helps insure project integrity.
115116
* Fossil contains a [./wikitheory.wiki | built-in wiki].
117
+ * An [./event.wiki | Event] is a special kind of wiki page associated
118
+ with a point in time rather than a name.
116119
* There is a
117120
[http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users | mailing list] (with publicly readable
118121
[http://www.mail-archive.com/[email protected] | archives]
119122
available for discussing fossil issues.
120123
* [./stats.wiki | Performance statistics] taken from real-world projects
121124
--- www/index.wiki
+++ www/index.wiki
@@ -40,12 +40,13 @@
40 internet these days. What makes Fossil worthy of attention?
41
42 1. <b>Bug Tracking And Wiki</b> -
43 In addition to doing [./concepts.wiki | distributed version control]
44 like Git and Mercurial,
45 Fossil also supports [./bugtheory.wiki | distributed bug tracking] and
46 [./wikitheory.wiki | distributed wiki] all in a single
 
47 integrated package.
48
49 2. <b>Web Interface</b> -
50 Fossil has a built-in and easy-to-use [./webui.wiki | web interface]
51 that simplifies project tracking and promotes situational awareness.
@@ -111,10 +112,12 @@
111 * A tutorial on [./branching.wiki | branching], what it means and how
112 to do it using fossil.
113 * The [./selfcheck.wiki | automatic self-check] mechanism
114 helps insure project integrity.
115 * Fossil contains a [./wikitheory.wiki | built-in wiki].
 
 
116 * There is a
117 [http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users | mailing list] (with publicly readable
118 [http://www.mail-archive.com/[email protected] | archives]
119 available for discussing fossil issues.
120 * [./stats.wiki | Performance statistics] taken from real-world projects
121
--- www/index.wiki
+++ www/index.wiki
@@ -40,12 +40,13 @@
40 internet these days. What makes Fossil worthy of attention?
41
42 1. <b>Bug Tracking And Wiki</b> -
43 In addition to doing [./concepts.wiki | distributed version control]
44 like Git and Mercurial,
45 Fossil also supports [./bugtheory.wiki | distributed bug tracking],
46 [./wikitheory.wiki | distributed wiki], and a
47 [./event.wiki | distributed blog] mechanism all in a single
48 integrated package.
49
50 2. <b>Web Interface</b> -
51 Fossil has a built-in and easy-to-use [./webui.wiki | web interface]
52 that simplifies project tracking and promotes situational awareness.
@@ -111,10 +112,12 @@
112 * A tutorial on [./branching.wiki | branching], what it means and how
113 to do it using fossil.
114 * The [./selfcheck.wiki | automatic self-check] mechanism
115 helps insure project integrity.
116 * Fossil contains a [./wikitheory.wiki | built-in wiki].
117 * An [./event.wiki | Event] is a special kind of wiki page associated
118 with a point in time rather than a name.
119 * There is a
120 [http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users | mailing list] (with publicly readable
121 [http://www.mail-archive.com/[email protected] | archives]
122 available for discussing fossil issues.
123 * [./stats.wiki | Performance statistics] taken from real-world projects
124
+1 -1
--- www/qandc.wiki
+++ www/qandc.wiki
@@ -63,11 +63,11 @@
6363
Other projects are also adopting fossil. But fossil does not yet have
6464
the massive user base of git or mercurial.
6565
</blockquote>
6666
6767
<b>Fossil looks like the bug tracker that would be in your
68
-Linksys Router's administration screen.</p>
68
+Linksys Router's administration screen.</b>
6969
7070
<blockquote>
7171
<p>I take a pragmatic approach to software: form follows function.
7272
To me, it is more important to have a reliable, fast, efficient,
7373
enduring, and simple DVCS than one that looks pretty.</p>
7474
--- www/qandc.wiki
+++ www/qandc.wiki
@@ -63,11 +63,11 @@
63 Other projects are also adopting fossil. But fossil does not yet have
64 the massive user base of git or mercurial.
65 </blockquote>
66
67 <b>Fossil looks like the bug tracker that would be in your
68 Linksys Router's administration screen.</p>
69
70 <blockquote>
71 <p>I take a pragmatic approach to software: form follows function.
72 To me, it is more important to have a reliable, fast, efficient,
73 enduring, and simple DVCS than one that looks pretty.</p>
74
--- www/qandc.wiki
+++ www/qandc.wiki
@@ -63,11 +63,11 @@
63 Other projects are also adopting fossil. But fossil does not yet have
64 the massive user base of git or mercurial.
65 </blockquote>
66
67 <b>Fossil looks like the bug tracker that would be in your
68 Linksys Router's administration screen.</b>
69
70 <blockquote>
71 <p>I take a pragmatic approach to software: form follows function.
72 To me, it is more important to have a reliable, fast, efficient,
73 enduring, and simple DVCS than one that looks pretty.</p>
74
--- www/wikitheory.wiki
+++ www/wikitheory.wiki
@@ -5,10 +5,11 @@
55
* Stand-alone wiki pages.
66
* Description and comments in [./bugtheory.wiki | bug reports].
77
* Check-in comments.
88
* [./embeddeddoc.wiki | Embedded documentation] files whose
99
name ends in "wiki".
10
+ * [./event.wiki | Event descriptions].
1011
1112
The [/wiki_rules | formatting rules] for fossil wiki
1213
are designed to be simple and intuitive. The idea is that wiki provides
1314
paragraph breaks, numbered and bulleted lists, and hyperlinking for
1415
simple documents together with a safe subset of HTML for more complex
1516
--- www/wikitheory.wiki
+++ www/wikitheory.wiki
@@ -5,10 +5,11 @@
5 * Stand-alone wiki pages.
6 * Description and comments in [./bugtheory.wiki | bug reports].
7 * Check-in comments.
8 * [./embeddeddoc.wiki | Embedded documentation] files whose
9 name ends in "wiki".
 
10
11 The [/wiki_rules | formatting rules] for fossil wiki
12 are designed to be simple and intuitive. The idea is that wiki provides
13 paragraph breaks, numbered and bulleted lists, and hyperlinking for
14 simple documents together with a safe subset of HTML for more complex
15
--- www/wikitheory.wiki
+++ www/wikitheory.wiki
@@ -5,10 +5,11 @@
5 * Stand-alone wiki pages.
6 * Description and comments in [./bugtheory.wiki | bug reports].
7 * Check-in comments.
8 * [./embeddeddoc.wiki | Embedded documentation] files whose
9 name ends in "wiki".
10 * [./event.wiki | Event descriptions].
11
12 The [/wiki_rules | formatting rules] for fossil wiki
13 are designed to be simple and intuitive. The idea is that wiki provides
14 paragraph breaks, numbered and bulleted lists, and hyperlinking for
15 simple documents together with a safe subset of HTML for more complex
16

Keyboard Shortcuts

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