Fossil SCM

Merge trunk

jan.nijtmans 2015-05-23 12:11 cleanX merge
Commit 533ff3d079529a29f3b10da63fbe399f225b631a
+1 -1
--- VERSION
+++ VERSION
@@ -1,1 +1,1 @@
1
-1.32
1
+1.33
22
--- VERSION
+++ VERSION
@@ -1,1 +1,1 @@
1 1.32
2
--- VERSION
+++ VERSION
@@ -1,1 +1,1 @@
1 1.33
2
+1
--- auto.def
+++ auto.def
@@ -299,10 +299,11 @@
299299
if {![cc-check-functions getpassphrase]} {
300300
# Haiku needs this
301301
cc-check-function-in-lib getpass bsd
302302
}
303303
cc-check-function-in-lib dlopen dl
304
+cc-check-function-in-lib sin m
304305
305306
# Check for the FuseFS library
306307
if {[opt-bool fusefs]} {
307308
if {[cc-check-function-in-lib fuse_mount fuse]} {
308309
define FOSSIL_HAVE_FUSEFS 1
309310
--- auto.def
+++ auto.def
@@ -299,10 +299,11 @@
299 if {![cc-check-functions getpassphrase]} {
300 # Haiku needs this
301 cc-check-function-in-lib getpass bsd
302 }
303 cc-check-function-in-lib dlopen dl
 
304
305 # Check for the FuseFS library
306 if {[opt-bool fusefs]} {
307 if {[cc-check-function-in-lib fuse_mount fuse]} {
308 define FOSSIL_HAVE_FUSEFS 1
309
--- auto.def
+++ auto.def
@@ -299,10 +299,11 @@
299 if {![cc-check-functions getpassphrase]} {
300 # Haiku needs this
301 cc-check-function-in-lib getpass bsd
302 }
303 cc-check-function-in-lib dlopen dl
304 cc-check-function-in-lib sin m
305
306 # Check for the FuseFS library
307 if {[opt-bool fusefs]} {
308 if {[cc-check-function-in-lib fuse_mount fuse]} {
309 define FOSSIL_HAVE_FUSEFS 1
310
--- skins/default/details.txt
+++ skins/default/details.txt
@@ -1,4 +1,4 @@
11
timeline-arrowheads: 1
2
-timeline-circle-nodes: 0
3
-timeline-color-graph-lines: 0
2
+timeline-circle-nodes: 1
3
+timeline-color-graph-lines: 1
44
white-foreground: 0
55
--- skins/default/details.txt
+++ skins/default/details.txt
@@ -1,4 +1,4 @@
1 timeline-arrowheads: 1
2 timeline-circle-nodes: 0
3 timeline-color-graph-lines: 0
4 white-foreground: 0
5
--- skins/default/details.txt
+++ skins/default/details.txt
@@ -1,4 +1,4 @@
1 timeline-arrowheads: 1
2 timeline-circle-nodes: 1
3 timeline-color-graph-lines: 1
4 white-foreground: 0
5
--- skins/eagle/css.txt
+++ skins/eagle/css.txt
@@ -168,10 +168,58 @@
168168
}
169169
170170
tr.timelineSelected {
171171
background-color: #7EA2D9;
172172
}
173
+
174
+/* commit node */
175
+.tl-node {
176
+ width: 10px;
177
+ height: 10px;
178
+ border: 1px solid #fff;
179
+ background: #485D7B;
180
+ cursor: pointer;
181
+}
182
+
183
+/* leaf commit marker */
184
+.tl-node.leaf:after {
185
+ content: '';
186
+ position: absolute;
187
+ top: 3px;
188
+ left: 3px;
189
+ width: 4px;
190
+ height: 4px;
191
+ background: #fff;
192
+}
193
+
194
+/* up arrow */
195
+.tl-arrow.u {
196
+ margin-top: -1px;
197
+ border-width: 0 3px;
198
+ border-bottom: 7px solid #fff;
199
+}
200
+
201
+/* small up arrow */
202
+.tl-arrow.u.sm {
203
+ border-bottom: 5px solid #fff;
204
+}
205
+
206
+/* line */
207
+.tl-line {
208
+ background: #fff;
209
+ width: 2px;
210
+}
211
+
212
+/* left merge arrow */
213
+.tl-arrow.merge.l {
214
+ border-right: 3px solid #fff;
215
+}
216
+
217
+/* right merge arrow */
218
+.tl-arrow.merge.r {
219
+ border-left: 3px solid #fff;
220
+}
173221
174222
/* Side-by-side diff */
175223
table.sbsdiff {
176224
background-color: #485D7B;
177225
font-family: fixed, Dejavu Sans Mono, Monaco, Lucida Console, monospace;
@@ -264,14 +312,10 @@
264312
/* line numbers in a diff */
265313
span.diffln {
266314
color: white;
267315
}
268316
269
-#canvas {
270
- background-color: #485D7B;
271
-}
272
-
273317
.fileage tr:hover {
274318
background-color: #7EA2D9;
275319
}
276320
277321
.fileage td {
278322
--- skins/eagle/css.txt
+++ skins/eagle/css.txt
@@ -168,10 +168,58 @@
168 }
169
170 tr.timelineSelected {
171 background-color: #7EA2D9;
172 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
174 /* Side-by-side diff */
175 table.sbsdiff {
176 background-color: #485D7B;
177 font-family: fixed, Dejavu Sans Mono, Monaco, Lucida Console, monospace;
@@ -264,14 +312,10 @@
264 /* line numbers in a diff */
265 span.diffln {
266 color: white;
267 }
268
269 #canvas {
270 background-color: #485D7B;
271 }
272
273 .fileage tr:hover {
274 background-color: #7EA2D9;
275 }
276
277 .fileage td {
278
--- skins/eagle/css.txt
+++ skins/eagle/css.txt
@@ -168,10 +168,58 @@
168 }
169
170 tr.timelineSelected {
171 background-color: #7EA2D9;
172 }
173
174 /* commit node */
175 .tl-node {
176 width: 10px;
177 height: 10px;
178 border: 1px solid #fff;
179 background: #485D7B;
180 cursor: pointer;
181 }
182
183 /* leaf commit marker */
184 .tl-node.leaf:after {
185 content: '';
186 position: absolute;
187 top: 3px;
188 left: 3px;
189 width: 4px;
190 height: 4px;
191 background: #fff;
192 }
193
194 /* up arrow */
195 .tl-arrow.u {
196 margin-top: -1px;
197 border-width: 0 3px;
198 border-bottom: 7px solid #fff;
199 }
200
201 /* small up arrow */
202 .tl-arrow.u.sm {
203 border-bottom: 5px solid #fff;
204 }
205
206 /* line */
207 .tl-line {
208 background: #fff;
209 width: 2px;
210 }
211
212 /* left merge arrow */
213 .tl-arrow.merge.l {
214 border-right: 3px solid #fff;
215 }
216
217 /* right merge arrow */
218 .tl-arrow.merge.r {
219 border-left: 3px solid #fff;
220 }
221
222 /* Side-by-side diff */
223 table.sbsdiff {
224 background-color: #485D7B;
225 font-family: fixed, Dejavu Sans Mono, Monaco, Lucida Console, monospace;
@@ -264,14 +312,10 @@
312 /* line numbers in a diff */
313 span.diffln {
314 color: white;
315 }
316
 
 
 
 
317 .fileage tr:hover {
318 background-color: #7EA2D9;
319 }
320
321 .fileage td {
322
--- skins/xekri/css.txt
+++ skins/xekri/css.txt
@@ -202,10 +202,17 @@
202202
}
203203
204204
div.content table[bgcolor="white"] {
205205
color: #000;
206206
}
207
+
208
+.piechartLabel {
209
+ fill: white;
210
+}
211
+.piechartLine {
212
+ stroke: white;
213
+}
207214
208215
/**************************************
209216
* Main Area: Footer
210217
*/
211218
@@ -700,15 +707,10 @@
700707
701708
/**************************************
702709
* Timeline
703710
*/
704711
705
-#canvas {
706
- color: #000;
707
- background-color: #fff;
708
-}
709
-
710712
div.divider {
711713
color: #ee0;
712714
font-size: 1.2rem;
713715
font-weight: bold;
714716
margin-top: 1rem;
@@ -1027,6 +1029,5 @@
10271029
}
10281030
/* odd table row color */
10291031
tr.row1 {
10301032
/* Use default */
10311033
}
1032
-
10331034
--- skins/xekri/css.txt
+++ skins/xekri/css.txt
@@ -202,10 +202,17 @@
202 }
203
204 div.content table[bgcolor="white"] {
205 color: #000;
206 }
 
 
 
 
 
 
 
207
208 /**************************************
209 * Main Area: Footer
210 */
211
@@ -700,15 +707,10 @@
700
701 /**************************************
702 * Timeline
703 */
704
705 #canvas {
706 color: #000;
707 background-color: #fff;
708 }
709
710 div.divider {
711 color: #ee0;
712 font-size: 1.2rem;
713 font-weight: bold;
714 margin-top: 1rem;
@@ -1027,6 +1029,5 @@
1027 }
1028 /* odd table row color */
1029 tr.row1 {
1030 /* Use default */
1031 }
1032
1033
--- skins/xekri/css.txt
+++ skins/xekri/css.txt
@@ -202,10 +202,17 @@
202 }
203
204 div.content table[bgcolor="white"] {
205 color: #000;
206 }
207
208 .piechartLabel {
209 fill: white;
210 }
211 .piechartLine {
212 stroke: white;
213 }
214
215 /**************************************
216 * Main Area: Footer
217 */
218
@@ -700,15 +707,10 @@
707
708 /**************************************
709 * Timeline
710 */
711
 
 
 
 
 
712 div.divider {
713 color: #ee0;
714 font-size: 1.2rem;
715 font-weight: bold;
716 margin-top: 1rem;
@@ -1027,6 +1029,5 @@
1029 }
1030 /* odd table row color */
1031 tr.row1 {
1032 /* Use default */
1033 }
 
1034
--- skins/xekri/header.txt
+++ skins/xekri/header.txt
@@ -127,10 +127,11 @@
127127
menulink /ticket Tickets
128128
}
129129
if {[anoncap j]} {
130130
menulink /wiki Wiki
131131
}
132
+ menulink /sitemap More...
132133
if {[hascap s]} {
133134
menulink /setup Admin
134135
} elseif {[hascap a]} {
135136
menulink /setup_ulist Users
136137
}
137138
--- skins/xekri/header.txt
+++ skins/xekri/header.txt
@@ -127,10 +127,11 @@
127 menulink /ticket Tickets
128 }
129 if {[anoncap j]} {
130 menulink /wiki Wiki
131 }
 
132 if {[hascap s]} {
133 menulink /setup Admin
134 } elseif {[hascap a]} {
135 menulink /setup_ulist Users
136 }
137
--- skins/xekri/header.txt
+++ skins/xekri/header.txt
@@ -127,10 +127,11 @@
127 menulink /ticket Tickets
128 }
129 if {[anoncap j]} {
130 menulink /wiki Wiki
131 }
132 menulink /sitemap More...
133 if {[hascap s]} {
134 menulink /setup Admin
135 } elseif {[hascap a]} {
136 menulink /setup_ulist Users
137 }
138
+8 -2
--- src/add.c
+++ src/add.c
@@ -317,12 +317,10 @@
317317
isDir = file_wd_isdir(zName);
318318
if( isDir==1 ){
319319
vfile_scan(&fullName, nRoot-1, scanFlags, pClean, pIgnore);
320320
}else if( isDir==0 ){
321321
fossil_warning("not found: %s", zName);
322
- }else if( file_access(zName, R_OK) ){
323
- fossil_fatal("cannot open %s", zName);
324322
}else{
325323
char *zTreeName = &zName[nRoot];
326324
if( !forceFlag && glob_match(pIgnore, zTreeName) ){
327325
Blob ans;
328326
char cReply;
@@ -632,10 +630,18 @@
632630
}
633631
634632
/* We should be done with options.. */
635633
verify_all_options();
636634
635
+ /* Fail if unprocessed arguments are present, in case user expect the
636
+ ** addremove command to accept a list of file or directory.
637
+ */
638
+ if( g.argc>2 ){
639
+ fossil_fatal(
640
+ "%s: Can only work on the entire checkout, no arguments supported.",
641
+ g.argv[1]);
642
+ }
637643
db_must_be_within_tree();
638644
if( zCleanFlag==0 ){
639645
zCleanFlag = db_get("clean-glob", 0);
640646
}
641647
if( zIgnoreFlag==0 ){
642648
--- src/add.c
+++ src/add.c
@@ -317,12 +317,10 @@
317 isDir = file_wd_isdir(zName);
318 if( isDir==1 ){
319 vfile_scan(&fullName, nRoot-1, scanFlags, pClean, pIgnore);
320 }else if( isDir==0 ){
321 fossil_warning("not found: %s", zName);
322 }else if( file_access(zName, R_OK) ){
323 fossil_fatal("cannot open %s", zName);
324 }else{
325 char *zTreeName = &zName[nRoot];
326 if( !forceFlag && glob_match(pIgnore, zTreeName) ){
327 Blob ans;
328 char cReply;
@@ -632,10 +630,18 @@
632 }
633
634 /* We should be done with options.. */
635 verify_all_options();
636
 
 
 
 
 
 
 
 
637 db_must_be_within_tree();
638 if( zCleanFlag==0 ){
639 zCleanFlag = db_get("clean-glob", 0);
640 }
641 if( zIgnoreFlag==0 ){
642
--- src/add.c
+++ src/add.c
@@ -317,12 +317,10 @@
317 isDir = file_wd_isdir(zName);
318 if( isDir==1 ){
319 vfile_scan(&fullName, nRoot-1, scanFlags, pClean, pIgnore);
320 }else if( isDir==0 ){
321 fossil_warning("not found: %s", zName);
 
 
322 }else{
323 char *zTreeName = &zName[nRoot];
324 if( !forceFlag && glob_match(pIgnore, zTreeName) ){
325 Blob ans;
326 char cReply;
@@ -632,10 +630,18 @@
630 }
631
632 /* We should be done with options.. */
633 verify_all_options();
634
635 /* Fail if unprocessed arguments are present, in case user expect the
636 ** addremove command to accept a list of file or directory.
637 */
638 if( g.argc>2 ){
639 fossil_fatal(
640 "%s: Can only work on the entire checkout, no arguments supported.",
641 g.argv[1]);
642 }
643 db_must_be_within_tree();
644 if( zCleanFlag==0 ){
645 zCleanFlag = db_get("clean-glob", 0);
646 }
647 if( zIgnoreFlag==0 ){
648
--- src/allrepo.c
+++ src/allrepo.c
@@ -231,10 +231,11 @@
231231
collect_argument(&extra, "verbose","v");
232232
}else if( strncmp(zCmd, "rebuild", n)==0 ){
233233
zCmd = "rebuild";
234234
collect_argument(&extra, "cluster",0);
235235
collect_argument(&extra, "compress",0);
236
+ collect_argument(&extra, "compress-only",0);
236237
collect_argument(&extra, "noverify",0);
237238
collect_argument_value(&extra, "pagesize");
238239
collect_argument(&extra, "vacuum",0);
239240
collect_argument(&extra, "deanalyze",0);
240241
collect_argument(&extra, "analyze",0);
241242
--- src/allrepo.c
+++ src/allrepo.c
@@ -231,10 +231,11 @@
231 collect_argument(&extra, "verbose","v");
232 }else if( strncmp(zCmd, "rebuild", n)==0 ){
233 zCmd = "rebuild";
234 collect_argument(&extra, "cluster",0);
235 collect_argument(&extra, "compress",0);
 
236 collect_argument(&extra, "noverify",0);
237 collect_argument_value(&extra, "pagesize");
238 collect_argument(&extra, "vacuum",0);
239 collect_argument(&extra, "deanalyze",0);
240 collect_argument(&extra, "analyze",0);
241
--- src/allrepo.c
+++ src/allrepo.c
@@ -231,10 +231,11 @@
231 collect_argument(&extra, "verbose","v");
232 }else if( strncmp(zCmd, "rebuild", n)==0 ){
233 zCmd = "rebuild";
234 collect_argument(&extra, "cluster",0);
235 collect_argument(&extra, "compress",0);
236 collect_argument(&extra, "compress-only",0);
237 collect_argument(&extra, "noverify",0);
238 collect_argument_value(&extra, "pagesize");
239 collect_argument(&extra, "vacuum",0);
240 collect_argument(&extra, "deanalyze",0);
241 collect_argument(&extra, "analyze",0);
242
+2 -2
--- src/blob.c
+++ src/blob.c
@@ -300,11 +300,11 @@
300300
** Return a pointer to a null-terminated string for a blob.
301301
*/
302302
char *blob_str(Blob *p){
303303
blob_is_init(p);
304304
if( p->nUsed==0 ){
305
- blob_append(p, "", 1);
305
+ blob_append(p, "", 1); /* NOTE: Changes nUsed. */
306306
p->nUsed = 0;
307307
}
308308
if( p->aData[p->nUsed]!=0 ){
309309
blob_materialize(p);
310310
}
@@ -839,11 +839,11 @@
839839
#if defined(_WIN32)
840840
fflush(stdout);
841841
_setmode(_fileno(stdout), _O_TEXT);
842842
#endif
843843
}else{
844
- file_mkfolder(zFilename, 1);
844
+ file_mkfolder(zFilename, 1, 0);
845845
out = fossil_fopen(zFilename, "wb");
846846
if( out==0 ){
847847
fossil_fatal_recursive("unable to open file \"%s\" for writing",
848848
zFilename);
849849
return 0;
850850
--- src/blob.c
+++ src/blob.c
@@ -300,11 +300,11 @@
300 ** Return a pointer to a null-terminated string for a blob.
301 */
302 char *blob_str(Blob *p){
303 blob_is_init(p);
304 if( p->nUsed==0 ){
305 blob_append(p, "", 1);
306 p->nUsed = 0;
307 }
308 if( p->aData[p->nUsed]!=0 ){
309 blob_materialize(p);
310 }
@@ -839,11 +839,11 @@
839 #if defined(_WIN32)
840 fflush(stdout);
841 _setmode(_fileno(stdout), _O_TEXT);
842 #endif
843 }else{
844 file_mkfolder(zFilename, 1);
845 out = fossil_fopen(zFilename, "wb");
846 if( out==0 ){
847 fossil_fatal_recursive("unable to open file \"%s\" for writing",
848 zFilename);
849 return 0;
850
--- src/blob.c
+++ src/blob.c
@@ -300,11 +300,11 @@
300 ** Return a pointer to a null-terminated string for a blob.
301 */
302 char *blob_str(Blob *p){
303 blob_is_init(p);
304 if( p->nUsed==0 ){
305 blob_append(p, "", 1); /* NOTE: Changes nUsed. */
306 p->nUsed = 0;
307 }
308 if( p->aData[p->nUsed]!=0 ){
309 blob_materialize(p);
310 }
@@ -839,11 +839,11 @@
839 #if defined(_WIN32)
840 fflush(stdout);
841 _setmode(_fileno(stdout), _O_TEXT);
842 #endif
843 }else{
844 file_mkfolder(zFilename, 1, 0);
845 out = fossil_fopen(zFilename, "wb");
846 if( out==0 ){
847 fossil_fatal_recursive("unable to open file \"%s\" for writing",
848 zFilename);
849 return 0;
850
+33 -7
--- src/checkin.c
+++ src/checkin.c
@@ -113,10 +113,18 @@
113113
blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName);
114114
}else if( isChnged==4 ){
115115
blob_appendf(report, "UPDATED_BY_INTEGRATE %s\n", zDisplayName);
116116
}else if( isChnged==5 ){
117117
blob_appendf(report, "ADDED_BY_INTEGRATE %s\n", zDisplayName);
118
+ }else if( isChnged==6 ){
119
+ blob_appendf(report, "EXECUTABLE %s\n", zDisplayName);
120
+ }else if( isChnged==7 ){
121
+ blob_appendf(report, "SYMLINK %s\n", zDisplayName);
122
+ }else if( isChnged==8 ){
123
+ blob_appendf(report, "UNEXEC %s\n", zDisplayName);
124
+ }else if( isChnged==9 ){
125
+ blob_appendf(report, "UNLINK %s\n", zDisplayName);
118126
}else if( file_contains_merge_marker(zFullName) ){
119127
blob_appendf(report, "CONFLICT %s\n", zDisplayName);
120128
}else{
121129
blob_appendf(report, "EDITED %s\n", zDisplayName);
122130
}
@@ -1640,10 +1648,12 @@
16401648
int dryRunFlag; /* True for a test run. Debugging only */
16411649
CheckinInfo sCiInfo; /* Information about this check-in */
16421650
const char *zComFile; /* Read commit message from this file */
16431651
int nTag = 0; /* Number of --tag arguments */
16441652
const char *zTag; /* A single --tag argument */
1653
+ ManifestFile *pFile; /* File structure in the manifest */
1654
+ Manifest *pManifest; /* Manifest structure */
16451655
Blob manifest; /* Manifest in baseline form */
16461656
Blob muuid; /* Manifest uuid */
16471657
Blob cksum1, cksum2; /* Before and after commit checksums */
16481658
Blob cksum1b; /* Checksum recorded in the manifest */
16491659
int szD; /* Size of the delta manifest */
@@ -1907,11 +1917,11 @@
19071917
/* Step 2: Insert records for all modified files into the blob
19081918
** table. If there were arguments passed to this command, only
19091919
** the identified files are inserted (if they have been modified).
19101920
*/
19111921
db_prepare(&q,
1912
- "SELECT id, %Q || pathname, mrid, %s, chnged, %s, %s FROM vfile "
1922
+ "SELECT id, %Q || pathname, mrid, %s, %s, %s FROM vfile "
19131923
"WHERE chnged==1 AND NOT deleted AND is_selected(id)",
19141924
g.zLocalRoot,
19151925
glob_expr("pathname", db_get("crnl-glob","")),
19161926
glob_expr("pathname", db_get("binary-glob","")),
19171927
glob_expr("pathname", db_get("encoding-glob",""))
@@ -1918,19 +1928,18 @@
19181928
);
19191929
while( db_step(&q)==SQLITE_ROW ){
19201930
int id, rid;
19211931
const char *zFullname;
19221932
Blob content;
1923
- int crnlOk, binOk, encodingOk, chnged;
1933
+ int crnlOk, binOk, encodingOk;
19241934
19251935
id = db_column_int(&q, 0);
19261936
zFullname = db_column_text(&q, 1);
19271937
rid = db_column_int(&q, 2);
19281938
crnlOk = db_column_int(&q, 3);
1929
- chnged = db_column_int(&q, 4);
1930
- binOk = db_column_int(&q, 5);
1931
- encodingOk = db_column_int(&q, 6);
1939
+ binOk = db_column_int(&q, 4);
1940
+ encodingOk = db_column_int(&q, 5);
19321941
19331942
blob_zero(&content);
19341943
if( file_wd_islink(zFullname) ){
19351944
/* Instead of file content, put link destination path */
19361945
blob_read_link(&content, zFullname);
@@ -1940,11 +1949,11 @@
19401949
/* Do not emit any warnings when they are disabled. */
19411950
if( !noWarningFlag ){
19421951
abortCommit |= commit_warning(&content, crnlOk, binOk,
19431952
encodingOk, zFullname);
19441953
}
1945
- if( chnged==1 && contains_merge_marker(&content) ){
1954
+ if( contains_merge_marker(&content) ){
19461955
Blob fname; /* Relative pathname of the file */
19471956
19481957
nConflict++;
19491958
file_relative_name(zFullname, &fname, 0);
19501959
fossil_print("possible unresolved merge conflict in %s\n",
@@ -2078,11 +2087,10 @@
20782087
blob_write_to_file(&muuid, zManifestFile);
20792088
free(zManifestFile);
20802089
blob_reset(&muuid);
20812090
}
20822091
2083
-
20842092
/* Update the vfile and vmerge tables */
20852093
db_multi_exec(
20862094
"DELETE FROM vfile WHERE (vid!=%d OR deleted) AND is_selected(id);"
20872095
"DELETE FROM vmerge;"
20882096
"UPDATE vfile SET vid=%d;"
@@ -2089,10 +2097,28 @@
20892097
"UPDATE vfile SET rid=mrid, chnged=0, deleted=0, origname=NULL"
20902098
" WHERE is_selected(id);"
20912099
, vid, nvid
20922100
);
20932101
db_lset_int("checkout", nvid);
2102
+
2103
+ /* Update the isexe and islink columns of the vfile table */
2104
+ db_prepare(&q,
2105
+ "UPDATE vfile SET isexe=:exec, islink=:link"
2106
+ " WHERE vid=:vid AND pathname=:path AND (isexe!=:exec OR islink!=:link)"
2107
+ );
2108
+ db_bind_int(&q, ":vid", nvid);
2109
+ pManifest = manifest_get(nvid, CFTYPE_MANIFEST, 0);
2110
+ manifest_file_rewind(pManifest);
2111
+ while( (pFile = manifest_file_next(pManifest, 0)) ){
2112
+ db_bind_int(&q, ":exec", pFile->zPerm && strstr(pFile->zPerm, "x"));
2113
+ db_bind_int(&q, ":link", pFile->zPerm && strstr(pFile->zPerm, "l"));
2114
+ db_bind_text(&q, ":path", pFile->zName);
2115
+ db_step(&q);
2116
+ db_reset(&q);
2117
+ }
2118
+ db_finalize(&q);
2119
+ manifest_destroy(pManifest);
20942120
20952121
if( useCksum ){
20962122
/* Verify that the repository checksum matches the expected checksum
20972123
** calculated before the check-in started (and stored as the R record
20982124
** of the manifest file).
20992125
--- src/checkin.c
+++ src/checkin.c
@@ -113,10 +113,18 @@
113 blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName);
114 }else if( isChnged==4 ){
115 blob_appendf(report, "UPDATED_BY_INTEGRATE %s\n", zDisplayName);
116 }else if( isChnged==5 ){
117 blob_appendf(report, "ADDED_BY_INTEGRATE %s\n", zDisplayName);
 
 
 
 
 
 
 
 
118 }else if( file_contains_merge_marker(zFullName) ){
119 blob_appendf(report, "CONFLICT %s\n", zDisplayName);
120 }else{
121 blob_appendf(report, "EDITED %s\n", zDisplayName);
122 }
@@ -1640,10 +1648,12 @@
1640 int dryRunFlag; /* True for a test run. Debugging only */
1641 CheckinInfo sCiInfo; /* Information about this check-in */
1642 const char *zComFile; /* Read commit message from this file */
1643 int nTag = 0; /* Number of --tag arguments */
1644 const char *zTag; /* A single --tag argument */
 
 
1645 Blob manifest; /* Manifest in baseline form */
1646 Blob muuid; /* Manifest uuid */
1647 Blob cksum1, cksum2; /* Before and after commit checksums */
1648 Blob cksum1b; /* Checksum recorded in the manifest */
1649 int szD; /* Size of the delta manifest */
@@ -1907,11 +1917,11 @@
1907 /* Step 2: Insert records for all modified files into the blob
1908 ** table. If there were arguments passed to this command, only
1909 ** the identified files are inserted (if they have been modified).
1910 */
1911 db_prepare(&q,
1912 "SELECT id, %Q || pathname, mrid, %s, chnged, %s, %s FROM vfile "
1913 "WHERE chnged==1 AND NOT deleted AND is_selected(id)",
1914 g.zLocalRoot,
1915 glob_expr("pathname", db_get("crnl-glob","")),
1916 glob_expr("pathname", db_get("binary-glob","")),
1917 glob_expr("pathname", db_get("encoding-glob",""))
@@ -1918,19 +1928,18 @@
1918 );
1919 while( db_step(&q)==SQLITE_ROW ){
1920 int id, rid;
1921 const char *zFullname;
1922 Blob content;
1923 int crnlOk, binOk, encodingOk, chnged;
1924
1925 id = db_column_int(&q, 0);
1926 zFullname = db_column_text(&q, 1);
1927 rid = db_column_int(&q, 2);
1928 crnlOk = db_column_int(&q, 3);
1929 chnged = db_column_int(&q, 4);
1930 binOk = db_column_int(&q, 5);
1931 encodingOk = db_column_int(&q, 6);
1932
1933 blob_zero(&content);
1934 if( file_wd_islink(zFullname) ){
1935 /* Instead of file content, put link destination path */
1936 blob_read_link(&content, zFullname);
@@ -1940,11 +1949,11 @@
1940 /* Do not emit any warnings when they are disabled. */
1941 if( !noWarningFlag ){
1942 abortCommit |= commit_warning(&content, crnlOk, binOk,
1943 encodingOk, zFullname);
1944 }
1945 if( chnged==1 && contains_merge_marker(&content) ){
1946 Blob fname; /* Relative pathname of the file */
1947
1948 nConflict++;
1949 file_relative_name(zFullname, &fname, 0);
1950 fossil_print("possible unresolved merge conflict in %s\n",
@@ -2078,11 +2087,10 @@
2078 blob_write_to_file(&muuid, zManifestFile);
2079 free(zManifestFile);
2080 blob_reset(&muuid);
2081 }
2082
2083
2084 /* Update the vfile and vmerge tables */
2085 db_multi_exec(
2086 "DELETE FROM vfile WHERE (vid!=%d OR deleted) AND is_selected(id);"
2087 "DELETE FROM vmerge;"
2088 "UPDATE vfile SET vid=%d;"
@@ -2089,10 +2097,28 @@
2089 "UPDATE vfile SET rid=mrid, chnged=0, deleted=0, origname=NULL"
2090 " WHERE is_selected(id);"
2091 , vid, nvid
2092 );
2093 db_lset_int("checkout", nvid);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2094
2095 if( useCksum ){
2096 /* Verify that the repository checksum matches the expected checksum
2097 ** calculated before the check-in started (and stored as the R record
2098 ** of the manifest file).
2099
--- src/checkin.c
+++ src/checkin.c
@@ -113,10 +113,18 @@
113 blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName);
114 }else if( isChnged==4 ){
115 blob_appendf(report, "UPDATED_BY_INTEGRATE %s\n", zDisplayName);
116 }else if( isChnged==5 ){
117 blob_appendf(report, "ADDED_BY_INTEGRATE %s\n", zDisplayName);
118 }else if( isChnged==6 ){
119 blob_appendf(report, "EXECUTABLE %s\n", zDisplayName);
120 }else if( isChnged==7 ){
121 blob_appendf(report, "SYMLINK %s\n", zDisplayName);
122 }else if( isChnged==8 ){
123 blob_appendf(report, "UNEXEC %s\n", zDisplayName);
124 }else if( isChnged==9 ){
125 blob_appendf(report, "UNLINK %s\n", zDisplayName);
126 }else if( file_contains_merge_marker(zFullName) ){
127 blob_appendf(report, "CONFLICT %s\n", zDisplayName);
128 }else{
129 blob_appendf(report, "EDITED %s\n", zDisplayName);
130 }
@@ -1640,10 +1648,12 @@
1648 int dryRunFlag; /* True for a test run. Debugging only */
1649 CheckinInfo sCiInfo; /* Information about this check-in */
1650 const char *zComFile; /* Read commit message from this file */
1651 int nTag = 0; /* Number of --tag arguments */
1652 const char *zTag; /* A single --tag argument */
1653 ManifestFile *pFile; /* File structure in the manifest */
1654 Manifest *pManifest; /* Manifest structure */
1655 Blob manifest; /* Manifest in baseline form */
1656 Blob muuid; /* Manifest uuid */
1657 Blob cksum1, cksum2; /* Before and after commit checksums */
1658 Blob cksum1b; /* Checksum recorded in the manifest */
1659 int szD; /* Size of the delta manifest */
@@ -1907,11 +1917,11 @@
1917 /* Step 2: Insert records for all modified files into the blob
1918 ** table. If there were arguments passed to this command, only
1919 ** the identified files are inserted (if they have been modified).
1920 */
1921 db_prepare(&q,
1922 "SELECT id, %Q || pathname, mrid, %s, %s, %s FROM vfile "
1923 "WHERE chnged==1 AND NOT deleted AND is_selected(id)",
1924 g.zLocalRoot,
1925 glob_expr("pathname", db_get("crnl-glob","")),
1926 glob_expr("pathname", db_get("binary-glob","")),
1927 glob_expr("pathname", db_get("encoding-glob",""))
@@ -1918,19 +1928,18 @@
1928 );
1929 while( db_step(&q)==SQLITE_ROW ){
1930 int id, rid;
1931 const char *zFullname;
1932 Blob content;
1933 int crnlOk, binOk, encodingOk;
1934
1935 id = db_column_int(&q, 0);
1936 zFullname = db_column_text(&q, 1);
1937 rid = db_column_int(&q, 2);
1938 crnlOk = db_column_int(&q, 3);
1939 binOk = db_column_int(&q, 4);
1940 encodingOk = db_column_int(&q, 5);
 
1941
1942 blob_zero(&content);
1943 if( file_wd_islink(zFullname) ){
1944 /* Instead of file content, put link destination path */
1945 blob_read_link(&content, zFullname);
@@ -1940,11 +1949,11 @@
1949 /* Do not emit any warnings when they are disabled. */
1950 if( !noWarningFlag ){
1951 abortCommit |= commit_warning(&content, crnlOk, binOk,
1952 encodingOk, zFullname);
1953 }
1954 if( contains_merge_marker(&content) ){
1955 Blob fname; /* Relative pathname of the file */
1956
1957 nConflict++;
1958 file_relative_name(zFullname, &fname, 0);
1959 fossil_print("possible unresolved merge conflict in %s\n",
@@ -2078,11 +2087,10 @@
2087 blob_write_to_file(&muuid, zManifestFile);
2088 free(zManifestFile);
2089 blob_reset(&muuid);
2090 }
2091
 
2092 /* Update the vfile and vmerge tables */
2093 db_multi_exec(
2094 "DELETE FROM vfile WHERE (vid!=%d OR deleted) AND is_selected(id);"
2095 "DELETE FROM vmerge;"
2096 "UPDATE vfile SET vid=%d;"
@@ -2089,10 +2097,28 @@
2097 "UPDATE vfile SET rid=mrid, chnged=0, deleted=0, origname=NULL"
2098 " WHERE is_selected(id);"
2099 , vid, nvid
2100 );
2101 db_lset_int("checkout", nvid);
2102
2103 /* Update the isexe and islink columns of the vfile table */
2104 db_prepare(&q,
2105 "UPDATE vfile SET isexe=:exec, islink=:link"
2106 " WHERE vid=:vid AND pathname=:path AND (isexe!=:exec OR islink!=:link)"
2107 );
2108 db_bind_int(&q, ":vid", nvid);
2109 pManifest = manifest_get(nvid, CFTYPE_MANIFEST, 0);
2110 manifest_file_rewind(pManifest);
2111 while( (pFile = manifest_file_next(pManifest, 0)) ){
2112 db_bind_int(&q, ":exec", pFile->zPerm && strstr(pFile->zPerm, "x"));
2113 db_bind_int(&q, ":link", pFile->zPerm && strstr(pFile->zPerm, "l"));
2114 db_bind_text(&q, ":path", pFile->zName);
2115 db_step(&q);
2116 db_reset(&q);
2117 }
2118 db_finalize(&q);
2119 manifest_destroy(pManifest);
2120
2121 if( useCksum ){
2122 /* Verify that the repository checksum matches the expected checksum
2123 ** calculated before the check-in started (and stored as the R record
2124 ** of the manifest file).
2125
+33 -7
--- src/checkin.c
+++ src/checkin.c
@@ -113,10 +113,18 @@
113113
blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName);
114114
}else if( isChnged==4 ){
115115
blob_appendf(report, "UPDATED_BY_INTEGRATE %s\n", zDisplayName);
116116
}else if( isChnged==5 ){
117117
blob_appendf(report, "ADDED_BY_INTEGRATE %s\n", zDisplayName);
118
+ }else if( isChnged==6 ){
119
+ blob_appendf(report, "EXECUTABLE %s\n", zDisplayName);
120
+ }else if( isChnged==7 ){
121
+ blob_appendf(report, "SYMLINK %s\n", zDisplayName);
122
+ }else if( isChnged==8 ){
123
+ blob_appendf(report, "UNEXEC %s\n", zDisplayName);
124
+ }else if( isChnged==9 ){
125
+ blob_appendf(report, "UNLINK %s\n", zDisplayName);
118126
}else if( file_contains_merge_marker(zFullName) ){
119127
blob_appendf(report, "CONFLICT %s\n", zDisplayName);
120128
}else{
121129
blob_appendf(report, "EDITED %s\n", zDisplayName);
122130
}
@@ -1640,10 +1648,12 @@
16401648
int dryRunFlag; /* True for a test run. Debugging only */
16411649
CheckinInfo sCiInfo; /* Information about this check-in */
16421650
const char *zComFile; /* Read commit message from this file */
16431651
int nTag = 0; /* Number of --tag arguments */
16441652
const char *zTag; /* A single --tag argument */
1653
+ ManifestFile *pFile; /* File structure in the manifest */
1654
+ Manifest *pManifest; /* Manifest structure */
16451655
Blob manifest; /* Manifest in baseline form */
16461656
Blob muuid; /* Manifest uuid */
16471657
Blob cksum1, cksum2; /* Before and after commit checksums */
16481658
Blob cksum1b; /* Checksum recorded in the manifest */
16491659
int szD; /* Size of the delta manifest */
@@ -1907,11 +1917,11 @@
19071917
/* Step 2: Insert records for all modified files into the blob
19081918
** table. If there were arguments passed to this command, only
19091919
** the identified files are inserted (if they have been modified).
19101920
*/
19111921
db_prepare(&q,
1912
- "SELECT id, %Q || pathname, mrid, %s, chnged, %s, %s FROM vfile "
1922
+ "SELECT id, %Q || pathname, mrid, %s, %s, %s FROM vfile "
19131923
"WHERE chnged==1 AND NOT deleted AND is_selected(id)",
19141924
g.zLocalRoot,
19151925
glob_expr("pathname", db_get("crnl-glob","")),
19161926
glob_expr("pathname", db_get("binary-glob","")),
19171927
glob_expr("pathname", db_get("encoding-glob",""))
@@ -1918,19 +1928,18 @@
19181928
);
19191929
while( db_step(&q)==SQLITE_ROW ){
19201930
int id, rid;
19211931
const char *zFullname;
19221932
Blob content;
1923
- int crnlOk, binOk, encodingOk, chnged;
1933
+ int crnlOk, binOk, encodingOk;
19241934
19251935
id = db_column_int(&q, 0);
19261936
zFullname = db_column_text(&q, 1);
19271937
rid = db_column_int(&q, 2);
19281938
crnlOk = db_column_int(&q, 3);
1929
- chnged = db_column_int(&q, 4);
1930
- binOk = db_column_int(&q, 5);
1931
- encodingOk = db_column_int(&q, 6);
1939
+ binOk = db_column_int(&q, 4);
1940
+ encodingOk = db_column_int(&q, 5);
19321941
19331942
blob_zero(&content);
19341943
if( file_wd_islink(zFullname) ){
19351944
/* Instead of file content, put link destination path */
19361945
blob_read_link(&content, zFullname);
@@ -1940,11 +1949,11 @@
19401949
/* Do not emit any warnings when they are disabled. */
19411950
if( !noWarningFlag ){
19421951
abortCommit |= commit_warning(&content, crnlOk, binOk,
19431952
encodingOk, zFullname);
19441953
}
1945
- if( chnged==1 && contains_merge_marker(&content) ){
1954
+ if( contains_merge_marker(&content) ){
19461955
Blob fname; /* Relative pathname of the file */
19471956
19481957
nConflict++;
19491958
file_relative_name(zFullname, &fname, 0);
19501959
fossil_print("possible unresolved merge conflict in %s\n",
@@ -2078,11 +2087,10 @@
20782087
blob_write_to_file(&muuid, zManifestFile);
20792088
free(zManifestFile);
20802089
blob_reset(&muuid);
20812090
}
20822091
2083
-
20842092
/* Update the vfile and vmerge tables */
20852093
db_multi_exec(
20862094
"DELETE FROM vfile WHERE (vid!=%d OR deleted) AND is_selected(id);"
20872095
"DELETE FROM vmerge;"
20882096
"UPDATE vfile SET vid=%d;"
@@ -2089,10 +2097,28 @@
20892097
"UPDATE vfile SET rid=mrid, chnged=0, deleted=0, origname=NULL"
20902098
" WHERE is_selected(id);"
20912099
, vid, nvid
20922100
);
20932101
db_lset_int("checkout", nvid);
2102
+
2103
+ /* Update the isexe and islink columns of the vfile table */
2104
+ db_prepare(&q,
2105
+ "UPDATE vfile SET isexe=:exec, islink=:link"
2106
+ " WHERE vid=:vid AND pathname=:path AND (isexe!=:exec OR islink!=:link)"
2107
+ );
2108
+ db_bind_int(&q, ":vid", nvid);
2109
+ pManifest = manifest_get(nvid, CFTYPE_MANIFEST, 0);
2110
+ manifest_file_rewind(pManifest);
2111
+ while( (pFile = manifest_file_next(pManifest, 0)) ){
2112
+ db_bind_int(&q, ":exec", pFile->zPerm && strstr(pFile->zPerm, "x"));
2113
+ db_bind_int(&q, ":link", pFile->zPerm && strstr(pFile->zPerm, "l"));
2114
+ db_bind_text(&q, ":path", pFile->zName);
2115
+ db_step(&q);
2116
+ db_reset(&q);
2117
+ }
2118
+ db_finalize(&q);
2119
+ manifest_destroy(pManifest);
20942120
20952121
if( useCksum ){
20962122
/* Verify that the repository checksum matches the expected checksum
20972123
** calculated before the check-in started (and stored as the R record
20982124
** of the manifest file).
20992125
--- src/checkin.c
+++ src/checkin.c
@@ -113,10 +113,18 @@
113 blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName);
114 }else if( isChnged==4 ){
115 blob_appendf(report, "UPDATED_BY_INTEGRATE %s\n", zDisplayName);
116 }else if( isChnged==5 ){
117 blob_appendf(report, "ADDED_BY_INTEGRATE %s\n", zDisplayName);
 
 
 
 
 
 
 
 
118 }else if( file_contains_merge_marker(zFullName) ){
119 blob_appendf(report, "CONFLICT %s\n", zDisplayName);
120 }else{
121 blob_appendf(report, "EDITED %s\n", zDisplayName);
122 }
@@ -1640,10 +1648,12 @@
1640 int dryRunFlag; /* True for a test run. Debugging only */
1641 CheckinInfo sCiInfo; /* Information about this check-in */
1642 const char *zComFile; /* Read commit message from this file */
1643 int nTag = 0; /* Number of --tag arguments */
1644 const char *zTag; /* A single --tag argument */
 
 
1645 Blob manifest; /* Manifest in baseline form */
1646 Blob muuid; /* Manifest uuid */
1647 Blob cksum1, cksum2; /* Before and after commit checksums */
1648 Blob cksum1b; /* Checksum recorded in the manifest */
1649 int szD; /* Size of the delta manifest */
@@ -1907,11 +1917,11 @@
1907 /* Step 2: Insert records for all modified files into the blob
1908 ** table. If there were arguments passed to this command, only
1909 ** the identified files are inserted (if they have been modified).
1910 */
1911 db_prepare(&q,
1912 "SELECT id, %Q || pathname, mrid, %s, chnged, %s, %s FROM vfile "
1913 "WHERE chnged==1 AND NOT deleted AND is_selected(id)",
1914 g.zLocalRoot,
1915 glob_expr("pathname", db_get("crnl-glob","")),
1916 glob_expr("pathname", db_get("binary-glob","")),
1917 glob_expr("pathname", db_get("encoding-glob",""))
@@ -1918,19 +1928,18 @@
1918 );
1919 while( db_step(&q)==SQLITE_ROW ){
1920 int id, rid;
1921 const char *zFullname;
1922 Blob content;
1923 int crnlOk, binOk, encodingOk, chnged;
1924
1925 id = db_column_int(&q, 0);
1926 zFullname = db_column_text(&q, 1);
1927 rid = db_column_int(&q, 2);
1928 crnlOk = db_column_int(&q, 3);
1929 chnged = db_column_int(&q, 4);
1930 binOk = db_column_int(&q, 5);
1931 encodingOk = db_column_int(&q, 6);
1932
1933 blob_zero(&content);
1934 if( file_wd_islink(zFullname) ){
1935 /* Instead of file content, put link destination path */
1936 blob_read_link(&content, zFullname);
@@ -1940,11 +1949,11 @@
1940 /* Do not emit any warnings when they are disabled. */
1941 if( !noWarningFlag ){
1942 abortCommit |= commit_warning(&content, crnlOk, binOk,
1943 encodingOk, zFullname);
1944 }
1945 if( chnged==1 && contains_merge_marker(&content) ){
1946 Blob fname; /* Relative pathname of the file */
1947
1948 nConflict++;
1949 file_relative_name(zFullname, &fname, 0);
1950 fossil_print("possible unresolved merge conflict in %s\n",
@@ -2078,11 +2087,10 @@
2078 blob_write_to_file(&muuid, zManifestFile);
2079 free(zManifestFile);
2080 blob_reset(&muuid);
2081 }
2082
2083
2084 /* Update the vfile and vmerge tables */
2085 db_multi_exec(
2086 "DELETE FROM vfile WHERE (vid!=%d OR deleted) AND is_selected(id);"
2087 "DELETE FROM vmerge;"
2088 "UPDATE vfile SET vid=%d;"
@@ -2089,10 +2097,28 @@
2089 "UPDATE vfile SET rid=mrid, chnged=0, deleted=0, origname=NULL"
2090 " WHERE is_selected(id);"
2091 , vid, nvid
2092 );
2093 db_lset_int("checkout", nvid);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2094
2095 if( useCksum ){
2096 /* Verify that the repository checksum matches the expected checksum
2097 ** calculated before the check-in started (and stored as the R record
2098 ** of the manifest file).
2099
--- src/checkin.c
+++ src/checkin.c
@@ -113,10 +113,18 @@
113 blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName);
114 }else if( isChnged==4 ){
115 blob_appendf(report, "UPDATED_BY_INTEGRATE %s\n", zDisplayName);
116 }else if( isChnged==5 ){
117 blob_appendf(report, "ADDED_BY_INTEGRATE %s\n", zDisplayName);
118 }else if( isChnged==6 ){
119 blob_appendf(report, "EXECUTABLE %s\n", zDisplayName);
120 }else if( isChnged==7 ){
121 blob_appendf(report, "SYMLINK %s\n", zDisplayName);
122 }else if( isChnged==8 ){
123 blob_appendf(report, "UNEXEC %s\n", zDisplayName);
124 }else if( isChnged==9 ){
125 blob_appendf(report, "UNLINK %s\n", zDisplayName);
126 }else if( file_contains_merge_marker(zFullName) ){
127 blob_appendf(report, "CONFLICT %s\n", zDisplayName);
128 }else{
129 blob_appendf(report, "EDITED %s\n", zDisplayName);
130 }
@@ -1640,10 +1648,12 @@
1648 int dryRunFlag; /* True for a test run. Debugging only */
1649 CheckinInfo sCiInfo; /* Information about this check-in */
1650 const char *zComFile; /* Read commit message from this file */
1651 int nTag = 0; /* Number of --tag arguments */
1652 const char *zTag; /* A single --tag argument */
1653 ManifestFile *pFile; /* File structure in the manifest */
1654 Manifest *pManifest; /* Manifest structure */
1655 Blob manifest; /* Manifest in baseline form */
1656 Blob muuid; /* Manifest uuid */
1657 Blob cksum1, cksum2; /* Before and after commit checksums */
1658 Blob cksum1b; /* Checksum recorded in the manifest */
1659 int szD; /* Size of the delta manifest */
@@ -1907,11 +1917,11 @@
1917 /* Step 2: Insert records for all modified files into the blob
1918 ** table. If there were arguments passed to this command, only
1919 ** the identified files are inserted (if they have been modified).
1920 */
1921 db_prepare(&q,
1922 "SELECT id, %Q || pathname, mrid, %s, %s, %s FROM vfile "
1923 "WHERE chnged==1 AND NOT deleted AND is_selected(id)",
1924 g.zLocalRoot,
1925 glob_expr("pathname", db_get("crnl-glob","")),
1926 glob_expr("pathname", db_get("binary-glob","")),
1927 glob_expr("pathname", db_get("encoding-glob",""))
@@ -1918,19 +1928,18 @@
1928 );
1929 while( db_step(&q)==SQLITE_ROW ){
1930 int id, rid;
1931 const char *zFullname;
1932 Blob content;
1933 int crnlOk, binOk, encodingOk;
1934
1935 id = db_column_int(&q, 0);
1936 zFullname = db_column_text(&q, 1);
1937 rid = db_column_int(&q, 2);
1938 crnlOk = db_column_int(&q, 3);
1939 binOk = db_column_int(&q, 4);
1940 encodingOk = db_column_int(&q, 5);
 
1941
1942 blob_zero(&content);
1943 if( file_wd_islink(zFullname) ){
1944 /* Instead of file content, put link destination path */
1945 blob_read_link(&content, zFullname);
@@ -1940,11 +1949,11 @@
1949 /* Do not emit any warnings when they are disabled. */
1950 if( !noWarningFlag ){
1951 abortCommit |= commit_warning(&content, crnlOk, binOk,
1952 encodingOk, zFullname);
1953 }
1954 if( contains_merge_marker(&content) ){
1955 Blob fname; /* Relative pathname of the file */
1956
1957 nConflict++;
1958 file_relative_name(zFullname, &fname, 0);
1959 fossil_print("possible unresolved merge conflict in %s\n",
@@ -2078,11 +2087,10 @@
2087 blob_write_to_file(&muuid, zManifestFile);
2088 free(zManifestFile);
2089 blob_reset(&muuid);
2090 }
2091
 
2092 /* Update the vfile and vmerge tables */
2093 db_multi_exec(
2094 "DELETE FROM vfile WHERE (vid!=%d OR deleted) AND is_selected(id);"
2095 "DELETE FROM vmerge;"
2096 "UPDATE vfile SET vid=%d;"
@@ -2089,10 +2097,28 @@
2097 "UPDATE vfile SET rid=mrid, chnged=0, deleted=0, origname=NULL"
2098 " WHERE is_selected(id);"
2099 , vid, nvid
2100 );
2101 db_lset_int("checkout", nvid);
2102
2103 /* Update the isexe and islink columns of the vfile table */
2104 db_prepare(&q,
2105 "UPDATE vfile SET isexe=:exec, islink=:link"
2106 " WHERE vid=:vid AND pathname=:path AND (isexe!=:exec OR islink!=:link)"
2107 );
2108 db_bind_int(&q, ":vid", nvid);
2109 pManifest = manifest_get(nvid, CFTYPE_MANIFEST, 0);
2110 manifest_file_rewind(pManifest);
2111 while( (pFile = manifest_file_next(pManifest, 0)) ){
2112 db_bind_int(&q, ":exec", pFile->zPerm && strstr(pFile->zPerm, "x"));
2113 db_bind_int(&q, ":link", pFile->zPerm && strstr(pFile->zPerm, "l"));
2114 db_bind_text(&q, ":path", pFile->zName);
2115 db_step(&q);
2116 db_reset(&q);
2117 }
2118 db_finalize(&q);
2119 manifest_destroy(pManifest);
2120
2121 if( useCksum ){
2122 /* Verify that the repository checksum matches the expected checksum
2123 ** calculated before the check-in started (and stored as the R record
2124 ** of the manifest file).
2125
+52 -23
--- src/db.c
+++ src/db.c
@@ -1894,53 +1894,72 @@
18941894
** might be generated.
18951895
*/
18961896
char *db_get_versioned(const char *zName, char *zNonVersionedSetting){
18971897
char *zVersionedSetting = 0;
18981898
int noWarn = 0;
1899
+ int found = 0;
18991900
struct _cacheEntry {
19001901
struct _cacheEntry *next;
19011902
const char *zName, *zValue;
19021903
} *cacheEntry = 0;
19031904
static struct _cacheEntry *cache = 0;
19041905
1905
- if( !g.localOpen) return zNonVersionedSetting;
1906
+ if( !g.localOpen && g.zOpenRevision==0 ) return zNonVersionedSetting;
19061907
/* Look up name in cache */
19071908
cacheEntry = cache;
19081909
while( cacheEntry!=0 ){
19091910
if( fossil_strcmp(cacheEntry->zName, zName)==0 ){
19101911
zVersionedSetting = fossil_strdup(cacheEntry->zValue);
19111912
break;
19121913
}
19131914
cacheEntry = cacheEntry->next;
19141915
}
1915
- /* Attempt to read value from file in checkout if there wasn't a cache hit
1916
- ** and a checkout is open. */
1916
+ /* Attempt to read value from file in checkout if there wasn't a cache hit. */
19171917
if( cacheEntry==0 ){
19181918
Blob versionedPathname;
1919
- char *zVersionedPathname;
1919
+ Blob setting;
19201920
blob_zero(&versionedPathname);
1921
+ blob_zero(&setting);
19211922
blob_appendf(&versionedPathname, "%s.fossil-settings/%s",
19221923
g.zLocalRoot, zName);
1923
- zVersionedPathname = blob_str(&versionedPathname);
1924
- if( file_size(zVersionedPathname)>=0 ){
1924
+ if( !g.localOpen ){
1925
+ /* Repository is in the process of being opened, but files have not been
1926
+ * written to disk. Load from the database. */
1927
+ Blob noWarnFile;
1928
+ if( historical_version_of_file(g.zOpenRevision,
1929
+ blob_str(&versionedPathname),
1930
+ &setting, 0, 0, 0, 2)!=2 ){
1931
+ found = 1;
1932
+ }
1933
+ /* See if there's a no-warn flag */
1934
+ blob_append(&versionedPathname, ".no-warn", -1);
1935
+ blob_zero(&noWarnFile);
1936
+ if( historical_version_of_file(g.zOpenRevision,
1937
+ blob_str(&versionedPathname),
1938
+ &noWarnFile, 0, 0, 0, 2)!=2 ){
1939
+ noWarn = 1;
1940
+ }
1941
+ blob_reset(&noWarnFile);
1942
+ }else if( file_size(blob_str(&versionedPathname))>=0 ){
19251943
/* File exists, and contains the value for this setting. Load from
19261944
** the file. */
1927
- Blob setting;
1928
- blob_zero(&setting);
1929
- if( blob_read_from_file(&setting, zVersionedPathname) >= 0 ){
1930
- blob_trim(&setting); /* Avoid non-obvious problems with line endings
1931
- ** on boolean properties */
1932
- zVersionedSetting = fossil_strdup(blob_str(&setting));
1933
- }
1934
- blob_reset(&setting);
1945
+ if( blob_read_from_file(&setting, blob_str(&versionedPathname))>=0 ){
1946
+ found = 1;
1947
+ }
19351948
/* See if there's a no-warn flag */
19361949
blob_append(&versionedPathname, ".no-warn", -1);
19371950
if( file_size(blob_str(&versionedPathname))>=0 ){
19381951
noWarn = 1;
19391952
}
19401953
}
19411954
blob_reset(&versionedPathname);
1955
+ if( found ){
1956
+ blob_trim(&setting); /* Avoid non-obvious problems with line endings
1957
+ ** on boolean properties */
1958
+ zVersionedSetting = fossil_strdup(blob_str(&setting));
1959
+ }
1960
+ blob_reset(&setting);
19421961
/* Store result in cache, which can be the value or 0 if not found */
19431962
cacheEntry = (struct _cacheEntry*)fossil_malloc(sizeof(struct _cacheEntry));
19441963
cacheEntry->next = cache;
19451964
cacheEntry->zName = zName;
19461965
cacheEntry->zValue = fossil_strdup(zVersionedSetting);
@@ -2198,12 +2217,10 @@
21982217
void cmd_open(void){
21992218
int emptyFlag;
22002219
int keepFlag;
22012220
int forceMissingFlag;
22022221
int allowNested;
2203
- char **oldArgv;
2204
- int oldArgc;
22052222
static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0, 0 };
22062223
22072224
url_proxy_options();
22082225
emptyFlag = find_option("empty",0,0)!=0;
22092226
keepFlag = find_option("keep",0,0)!=0;
@@ -2218,10 +2235,26 @@
22182235
}
22192236
if( !allowNested && db_open_local(0) ){
22202237
fossil_fatal("already within an open tree rooted at %s", g.zLocalRoot);
22212238
}
22222239
db_open_repository(g.argv[2]);
2240
+
2241
+ /* Figure out which revision to open. */
2242
+ if( !emptyFlag ){
2243
+ if( g.argc==4 ){
2244
+ g.zOpenRevision = g.argv[3];
2245
+ }else if( db_exists("SELECT 1 FROM event WHERE type='ci'") ){
2246
+ g.zOpenRevision = db_get("main-branch", "trunk");
2247
+ }
2248
+ }
2249
+
2250
+ if( g.zOpenRevision ){
2251
+ /* Since the repository is open and we know the revision now,
2252
+ ** refresh the allow-symlinks flag. */
2253
+ g.allowSymlinks = db_get_boolean("allow-symlinks", 0);
2254
+ }
2255
+
22232256
#if defined(_WIN32) || defined(__CYGWIN__)
22242257
# define LOCALDB_NAME "./_FOSSIL_"
22252258
#else
22262259
# define LOCALDB_NAME "./.fslckout"
22272260
#endif
@@ -2233,22 +2266,18 @@
22332266
db_delete_on_failure(LOCALDB_NAME);
22342267
db_open_local(0);
22352268
db_lset("repository", g.argv[2]);
22362269
db_record_repository_filename(g.argv[2]);
22372270
db_lset_int("checkout", 0);
2238
- oldArgv = g.argv;
2239
- oldArgc = g.argc;
22402271
azNewArgv[0] = g.argv[0];
22412272
g.argv = azNewArgv;
22422273
if( !emptyFlag ){
22432274
g.argc = 3;
2244
- if( oldArgc==4 ){
2245
- azNewArgv[g.argc-1] = oldArgv[3];
2246
- }else if( !db_exists("SELECT 1 FROM event WHERE type='ci'") ){
2247
- azNewArgv[g.argc-1] = "--latest";
2275
+ if( g.zOpenRevision ){
2276
+ azNewArgv[g.argc-1] = g.zOpenRevision;
22482277
}else{
2249
- azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2278
+ azNewArgv[g.argc-1] = "--latest";
22502279
}
22512280
if( keepFlag ){
22522281
azNewArgv[g.argc++] = "--keep";
22532282
}
22542283
if( forceMissingFlag ){
22552284
--- src/db.c
+++ src/db.c
@@ -1894,53 +1894,72 @@
1894 ** might be generated.
1895 */
1896 char *db_get_versioned(const char *zName, char *zNonVersionedSetting){
1897 char *zVersionedSetting = 0;
1898 int noWarn = 0;
 
1899 struct _cacheEntry {
1900 struct _cacheEntry *next;
1901 const char *zName, *zValue;
1902 } *cacheEntry = 0;
1903 static struct _cacheEntry *cache = 0;
1904
1905 if( !g.localOpen) return zNonVersionedSetting;
1906 /* Look up name in cache */
1907 cacheEntry = cache;
1908 while( cacheEntry!=0 ){
1909 if( fossil_strcmp(cacheEntry->zName, zName)==0 ){
1910 zVersionedSetting = fossil_strdup(cacheEntry->zValue);
1911 break;
1912 }
1913 cacheEntry = cacheEntry->next;
1914 }
1915 /* Attempt to read value from file in checkout if there wasn't a cache hit
1916 ** and a checkout is open. */
1917 if( cacheEntry==0 ){
1918 Blob versionedPathname;
1919 char *zVersionedPathname;
1920 blob_zero(&versionedPathname);
 
1921 blob_appendf(&versionedPathname, "%s.fossil-settings/%s",
1922 g.zLocalRoot, zName);
1923 zVersionedPathname = blob_str(&versionedPathname);
1924 if( file_size(zVersionedPathname)>=0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1925 /* File exists, and contains the value for this setting. Load from
1926 ** the file. */
1927 Blob setting;
1928 blob_zero(&setting);
1929 if( blob_read_from_file(&setting, zVersionedPathname) >= 0 ){
1930 blob_trim(&setting); /* Avoid non-obvious problems with line endings
1931 ** on boolean properties */
1932 zVersionedSetting = fossil_strdup(blob_str(&setting));
1933 }
1934 blob_reset(&setting);
1935 /* See if there's a no-warn flag */
1936 blob_append(&versionedPathname, ".no-warn", -1);
1937 if( file_size(blob_str(&versionedPathname))>=0 ){
1938 noWarn = 1;
1939 }
1940 }
1941 blob_reset(&versionedPathname);
 
 
 
 
 
 
1942 /* Store result in cache, which can be the value or 0 if not found */
1943 cacheEntry = (struct _cacheEntry*)fossil_malloc(sizeof(struct _cacheEntry));
1944 cacheEntry->next = cache;
1945 cacheEntry->zName = zName;
1946 cacheEntry->zValue = fossil_strdup(zVersionedSetting);
@@ -2198,12 +2217,10 @@
2198 void cmd_open(void){
2199 int emptyFlag;
2200 int keepFlag;
2201 int forceMissingFlag;
2202 int allowNested;
2203 char **oldArgv;
2204 int oldArgc;
2205 static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0, 0 };
2206
2207 url_proxy_options();
2208 emptyFlag = find_option("empty",0,0)!=0;
2209 keepFlag = find_option("keep",0,0)!=0;
@@ -2218,10 +2235,26 @@
2218 }
2219 if( !allowNested && db_open_local(0) ){
2220 fossil_fatal("already within an open tree rooted at %s", g.zLocalRoot);
2221 }
2222 db_open_repository(g.argv[2]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2223 #if defined(_WIN32) || defined(__CYGWIN__)
2224 # define LOCALDB_NAME "./_FOSSIL_"
2225 #else
2226 # define LOCALDB_NAME "./.fslckout"
2227 #endif
@@ -2233,22 +2266,18 @@
2233 db_delete_on_failure(LOCALDB_NAME);
2234 db_open_local(0);
2235 db_lset("repository", g.argv[2]);
2236 db_record_repository_filename(g.argv[2]);
2237 db_lset_int("checkout", 0);
2238 oldArgv = g.argv;
2239 oldArgc = g.argc;
2240 azNewArgv[0] = g.argv[0];
2241 g.argv = azNewArgv;
2242 if( !emptyFlag ){
2243 g.argc = 3;
2244 if( oldArgc==4 ){
2245 azNewArgv[g.argc-1] = oldArgv[3];
2246 }else if( !db_exists("SELECT 1 FROM event WHERE type='ci'") ){
2247 azNewArgv[g.argc-1] = "--latest";
2248 }else{
2249 azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2250 }
2251 if( keepFlag ){
2252 azNewArgv[g.argc++] = "--keep";
2253 }
2254 if( forceMissingFlag ){
2255
--- src/db.c
+++ src/db.c
@@ -1894,53 +1894,72 @@
1894 ** might be generated.
1895 */
1896 char *db_get_versioned(const char *zName, char *zNonVersionedSetting){
1897 char *zVersionedSetting = 0;
1898 int noWarn = 0;
1899 int found = 0;
1900 struct _cacheEntry {
1901 struct _cacheEntry *next;
1902 const char *zName, *zValue;
1903 } *cacheEntry = 0;
1904 static struct _cacheEntry *cache = 0;
1905
1906 if( !g.localOpen && g.zOpenRevision==0 ) return zNonVersionedSetting;
1907 /* Look up name in cache */
1908 cacheEntry = cache;
1909 while( cacheEntry!=0 ){
1910 if( fossil_strcmp(cacheEntry->zName, zName)==0 ){
1911 zVersionedSetting = fossil_strdup(cacheEntry->zValue);
1912 break;
1913 }
1914 cacheEntry = cacheEntry->next;
1915 }
1916 /* Attempt to read value from file in checkout if there wasn't a cache hit. */
 
1917 if( cacheEntry==0 ){
1918 Blob versionedPathname;
1919 Blob setting;
1920 blob_zero(&versionedPathname);
1921 blob_zero(&setting);
1922 blob_appendf(&versionedPathname, "%s.fossil-settings/%s",
1923 g.zLocalRoot, zName);
1924 if( !g.localOpen ){
1925 /* Repository is in the process of being opened, but files have not been
1926 * written to disk. Load from the database. */
1927 Blob noWarnFile;
1928 if( historical_version_of_file(g.zOpenRevision,
1929 blob_str(&versionedPathname),
1930 &setting, 0, 0, 0, 2)!=2 ){
1931 found = 1;
1932 }
1933 /* See if there's a no-warn flag */
1934 blob_append(&versionedPathname, ".no-warn", -1);
1935 blob_zero(&noWarnFile);
1936 if( historical_version_of_file(g.zOpenRevision,
1937 blob_str(&versionedPathname),
1938 &noWarnFile, 0, 0, 0, 2)!=2 ){
1939 noWarn = 1;
1940 }
1941 blob_reset(&noWarnFile);
1942 }else if( file_size(blob_str(&versionedPathname))>=0 ){
1943 /* File exists, and contains the value for this setting. Load from
1944 ** the file. */
1945 if( blob_read_from_file(&setting, blob_str(&versionedPathname))>=0 ){
1946 found = 1;
1947 }
 
 
 
 
 
1948 /* See if there's a no-warn flag */
1949 blob_append(&versionedPathname, ".no-warn", -1);
1950 if( file_size(blob_str(&versionedPathname))>=0 ){
1951 noWarn = 1;
1952 }
1953 }
1954 blob_reset(&versionedPathname);
1955 if( found ){
1956 blob_trim(&setting); /* Avoid non-obvious problems with line endings
1957 ** on boolean properties */
1958 zVersionedSetting = fossil_strdup(blob_str(&setting));
1959 }
1960 blob_reset(&setting);
1961 /* Store result in cache, which can be the value or 0 if not found */
1962 cacheEntry = (struct _cacheEntry*)fossil_malloc(sizeof(struct _cacheEntry));
1963 cacheEntry->next = cache;
1964 cacheEntry->zName = zName;
1965 cacheEntry->zValue = fossil_strdup(zVersionedSetting);
@@ -2198,12 +2217,10 @@
2217 void cmd_open(void){
2218 int emptyFlag;
2219 int keepFlag;
2220 int forceMissingFlag;
2221 int allowNested;
 
 
2222 static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0, 0 };
2223
2224 url_proxy_options();
2225 emptyFlag = find_option("empty",0,0)!=0;
2226 keepFlag = find_option("keep",0,0)!=0;
@@ -2218,10 +2235,26 @@
2235 }
2236 if( !allowNested && db_open_local(0) ){
2237 fossil_fatal("already within an open tree rooted at %s", g.zLocalRoot);
2238 }
2239 db_open_repository(g.argv[2]);
2240
2241 /* Figure out which revision to open. */
2242 if( !emptyFlag ){
2243 if( g.argc==4 ){
2244 g.zOpenRevision = g.argv[3];
2245 }else if( db_exists("SELECT 1 FROM event WHERE type='ci'") ){
2246 g.zOpenRevision = db_get("main-branch", "trunk");
2247 }
2248 }
2249
2250 if( g.zOpenRevision ){
2251 /* Since the repository is open and we know the revision now,
2252 ** refresh the allow-symlinks flag. */
2253 g.allowSymlinks = db_get_boolean("allow-symlinks", 0);
2254 }
2255
2256 #if defined(_WIN32) || defined(__CYGWIN__)
2257 # define LOCALDB_NAME "./_FOSSIL_"
2258 #else
2259 # define LOCALDB_NAME "./.fslckout"
2260 #endif
@@ -2233,22 +2266,18 @@
2266 db_delete_on_failure(LOCALDB_NAME);
2267 db_open_local(0);
2268 db_lset("repository", g.argv[2]);
2269 db_record_repository_filename(g.argv[2]);
2270 db_lset_int("checkout", 0);
 
 
2271 azNewArgv[0] = g.argv[0];
2272 g.argv = azNewArgv;
2273 if( !emptyFlag ){
2274 g.argc = 3;
2275 if( g.zOpenRevision ){
2276 azNewArgv[g.argc-1] = g.zOpenRevision;
 
 
2277 }else{
2278 azNewArgv[g.argc-1] = "--latest";
2279 }
2280 if( keepFlag ){
2281 azNewArgv[g.argc++] = "--keep";
2282 }
2283 if( forceMissingFlag ){
2284
+12 -5
--- src/file.c
+++ src/file.c
@@ -386,11 +386,11 @@
386386
FILE *in, *out;
387387
int got;
388388
char zBuf[8192];
389389
in = fossil_fopen(zFrom, "rb");
390390
if( in==0 ) fossil_fatal("cannot open \"%s\" for reading", zFrom);
391
- file_mkfolder(zTo, 0);
391
+ file_mkfolder(zTo, 0, 0);
392392
out = fossil_fopen(zTo, "wb");
393393
if( out==0 ) fossil_fatal("cannot open \"%s\" for writing", zTo);
394394
while( (got=fread(zBuf, 1, sizeof(zBuf), in))>0 ){
395395
fwrite(zBuf, 1, got, out);
396396
}
@@ -530,13 +530,16 @@
530530
}
531531
532532
/*
533533
** Create the tree of directories in which zFilename belongs, if that sequence
534534
** of directories does not already exist.
535
+**
536
+** On success, return zero. On error, return errorReturn if positive, otherwise
537
+** print an error message and abort.
535538
*/
536
-void file_mkfolder(const char *zFilename, int forceFlag){
537
- int i, nName;
539
+int file_mkfolder(const char *zFilename, int forceFlag, int errorReturn){
540
+ int i, nName, rc = 0;
538541
char *zName;
539542
540543
nName = strlen(zFilename);
541544
zName = mprintf("%s", zFilename);
542545
nName = file_simplify_name(zName, nName, 0);
@@ -550,20 +553,24 @@
550553
** C: in this example.
551554
*/
552555
if( !(i==2 && zName[1]==':') ){
553556
#endif
554557
if( file_mkdir(zName, forceFlag) && file_isdir(zName)!=1 ){
555
- fossil_fatal_recursive("unable to create directory %s", zName);
556
- return;
558
+ if (errorReturn <= 0) {
559
+ fossil_fatal_recursive("unable to create directory %s", zName);
560
+ }
561
+ rc = errorReturn;
562
+ break;
557563
}
558564
#if defined(_WIN32) || defined(__CYGWIN__)
559565
}
560566
#endif
561567
zName[i] = '/';
562568
}
563569
}
564570
free(zName);
571
+ return rc;
565572
}
566573
567574
/*
568575
** Removes the directory named in the argument, if it exists. The directory
569576
** must be empty and cannot be the current directory or the root directory.
570577
--- src/file.c
+++ src/file.c
@@ -386,11 +386,11 @@
386 FILE *in, *out;
387 int got;
388 char zBuf[8192];
389 in = fossil_fopen(zFrom, "rb");
390 if( in==0 ) fossil_fatal("cannot open \"%s\" for reading", zFrom);
391 file_mkfolder(zTo, 0);
392 out = fossil_fopen(zTo, "wb");
393 if( out==0 ) fossil_fatal("cannot open \"%s\" for writing", zTo);
394 while( (got=fread(zBuf, 1, sizeof(zBuf), in))>0 ){
395 fwrite(zBuf, 1, got, out);
396 }
@@ -530,13 +530,16 @@
530 }
531
532 /*
533 ** Create the tree of directories in which zFilename belongs, if that sequence
534 ** of directories does not already exist.
 
 
 
535 */
536 void file_mkfolder(const char *zFilename, int forceFlag){
537 int i, nName;
538 char *zName;
539
540 nName = strlen(zFilename);
541 zName = mprintf("%s", zFilename);
542 nName = file_simplify_name(zName, nName, 0);
@@ -550,20 +553,24 @@
550 ** C: in this example.
551 */
552 if( !(i==2 && zName[1]==':') ){
553 #endif
554 if( file_mkdir(zName, forceFlag) && file_isdir(zName)!=1 ){
555 fossil_fatal_recursive("unable to create directory %s", zName);
556 return;
 
 
 
557 }
558 #if defined(_WIN32) || defined(__CYGWIN__)
559 }
560 #endif
561 zName[i] = '/';
562 }
563 }
564 free(zName);
 
565 }
566
567 /*
568 ** Removes the directory named in the argument, if it exists. The directory
569 ** must be empty and cannot be the current directory or the root directory.
570
--- src/file.c
+++ src/file.c
@@ -386,11 +386,11 @@
386 FILE *in, *out;
387 int got;
388 char zBuf[8192];
389 in = fossil_fopen(zFrom, "rb");
390 if( in==0 ) fossil_fatal("cannot open \"%s\" for reading", zFrom);
391 file_mkfolder(zTo, 0, 0);
392 out = fossil_fopen(zTo, "wb");
393 if( out==0 ) fossil_fatal("cannot open \"%s\" for writing", zTo);
394 while( (got=fread(zBuf, 1, sizeof(zBuf), in))>0 ){
395 fwrite(zBuf, 1, got, out);
396 }
@@ -530,13 +530,16 @@
530 }
531
532 /*
533 ** Create the tree of directories in which zFilename belongs, if that sequence
534 ** of directories does not already exist.
535 **
536 ** On success, return zero. On error, return errorReturn if positive, otherwise
537 ** print an error message and abort.
538 */
539 int file_mkfolder(const char *zFilename, int forceFlag, int errorReturn){
540 int i, nName, rc = 0;
541 char *zName;
542
543 nName = strlen(zFilename);
544 zName = mprintf("%s", zFilename);
545 nName = file_simplify_name(zName, nName, 0);
@@ -550,20 +553,24 @@
553 ** C: in this example.
554 */
555 if( !(i==2 && zName[1]==':') ){
556 #endif
557 if( file_mkdir(zName, forceFlag) && file_isdir(zName)!=1 ){
558 if (errorReturn <= 0) {
559 fossil_fatal_recursive("unable to create directory %s", zName);
560 }
561 rc = errorReturn;
562 break;
563 }
564 #if defined(_WIN32) || defined(__CYGWIN__)
565 }
566 #endif
567 zName[i] = '/';
568 }
569 }
570 free(zName);
571 return rc;
572 }
573
574 /*
575 ** Removes the directory named in the argument, if it exists. The directory
576 ** must be empty and cannot be the current directory or the root directory.
577
+4 -9
--- src/finfo.c
+++ src/finfo.c
@@ -182,11 +182,11 @@
182182
if( rid==0 ){
183183
fossil_fatal("no history for file: %b", &fname);
184184
}
185185
zFilename = blob_str(&fname);
186186
db_prepare(&q,
187
- "SELECT b.uuid, ci.uuid, date(event.mtime%s),"
187
+ "SELECT DISTINCT b.uuid, ci.uuid, date(event.mtime%s),"
188188
" coalesce(event.ecomment, event.comment),"
189189
" coalesce(event.euser, event.user),"
190190
" (SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0"
191191
" AND tagxref.rid=mlink.mid)" /* Tags */
192192
" FROM mlink, blob b, event, blob ci, filename"
@@ -403,12 +403,10 @@
403403
if( fShowId ) blob_appendf(&title, " (%d)", fnid);
404404
}
405405
@ <h2>%b(&title)</h2>
406406
blob_reset(&title);
407407
pGraph = graph_init();
408
- @ <div id="canvas" style="position:relative;width:1px;height:1px;"
409
- @ onclick="clickOnGraph(event)"></div>
410408
@ <table id="timelineTable" class="timelineTable">
411409
while( db_step(&q)==SQLITE_ROW ){
412410
const char *zDate = db_column_text(&q, 0);
413411
const char *zCom = db_column_text(&q, 1);
414412
const char *zUser = db_column_text(&q, 2);
@@ -459,11 +457,11 @@
459457
}
460458
memcpy(zTime, &zDate[11], 5);
461459
zTime[5] = 0;
462460
@ <tr><td class="timelineTime">
463461
@ %z(href("%R/timeline?c=%t",zDate))%s(zTime)</a></td>
464
- @ <td class="timelineGraph"><div id="m%d(gidx)"></div></td>
462
+ @ <td class="timelineGraph"><div id="m%d(gidx)" class="tl-nodemark"></div></td>
465463
if( zBgClr && zBgClr[0] ){
466464
@ <td class="timelineTableCell" style="background-color: %h(zBgClr);">
467465
}else{
468466
@ <td class="timelineTableCell">
469467
}
@@ -509,11 +507,11 @@
509507
@ %z(href("%R/annotate?filename=%h&checkin=%s",z,zCkin))
510508
@ [annotate]</a>
511509
@ %z(href("%R/blame?filename=%h&checkin=%s",z,zCkin))
512510
@ [blame]</a>
513511
@ %z(href("%R/timeline?n=200&uf=%!S",zUuid))[check-ins&nbsp;using]</a>
514
- if( fpid ){
512
+ if( fpid>0 ){
515513
@ %z(href("%R/fdiff?sbs=1&v1=%!S&v2=%!S",zPUuid,zUuid))[diff]</a>
516514
}
517515
}
518516
if( fDebug & FINFO_DEBUG_MLINK ){
519517
int ii;
@@ -536,15 +534,12 @@
536534
graph_finish(pGraph, 1);
537535
if( pGraph->nErr ){
538536
graph_free(pGraph);
539537
pGraph = 0;
540538
}else{
541
- int w = pGraph->mxRail*pGraph->iRailPitch + 28;
542
- @ <tr><td></td><td>
543
- @ <div id="grbtm" style="width:%d(w)px;"></div>
544
- @ </td><td></td></tr>
539
+ @ <tr class="timelineBottom"><td></td><td></td><td></td></tr>
545540
}
546541
}
547542
@ </table>
548543
timeline_output_graph_javascript(pGraph, 0, 1);
549544
style_footer();
550545
}
551546
--- src/finfo.c
+++ src/finfo.c
@@ -182,11 +182,11 @@
182 if( rid==0 ){
183 fossil_fatal("no history for file: %b", &fname);
184 }
185 zFilename = blob_str(&fname);
186 db_prepare(&q,
187 "SELECT b.uuid, ci.uuid, date(event.mtime%s),"
188 " coalesce(event.ecomment, event.comment),"
189 " coalesce(event.euser, event.user),"
190 " (SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0"
191 " AND tagxref.rid=mlink.mid)" /* Tags */
192 " FROM mlink, blob b, event, blob ci, filename"
@@ -403,12 +403,10 @@
403 if( fShowId ) blob_appendf(&title, " (%d)", fnid);
404 }
405 @ <h2>%b(&title)</h2>
406 blob_reset(&title);
407 pGraph = graph_init();
408 @ <div id="canvas" style="position:relative;width:1px;height:1px;"
409 @ onclick="clickOnGraph(event)"></div>
410 @ <table id="timelineTable" class="timelineTable">
411 while( db_step(&q)==SQLITE_ROW ){
412 const char *zDate = db_column_text(&q, 0);
413 const char *zCom = db_column_text(&q, 1);
414 const char *zUser = db_column_text(&q, 2);
@@ -459,11 +457,11 @@
459 }
460 memcpy(zTime, &zDate[11], 5);
461 zTime[5] = 0;
462 @ <tr><td class="timelineTime">
463 @ %z(href("%R/timeline?c=%t",zDate))%s(zTime)</a></td>
464 @ <td class="timelineGraph"><div id="m%d(gidx)"></div></td>
465 if( zBgClr && zBgClr[0] ){
466 @ <td class="timelineTableCell" style="background-color: %h(zBgClr);">
467 }else{
468 @ <td class="timelineTableCell">
469 }
@@ -509,11 +507,11 @@
509 @ %z(href("%R/annotate?filename=%h&checkin=%s",z,zCkin))
510 @ [annotate]</a>
511 @ %z(href("%R/blame?filename=%h&checkin=%s",z,zCkin))
512 @ [blame]</a>
513 @ %z(href("%R/timeline?n=200&uf=%!S",zUuid))[check-ins&nbsp;using]</a>
514 if( fpid ){
515 @ %z(href("%R/fdiff?sbs=1&v1=%!S&v2=%!S",zPUuid,zUuid))[diff]</a>
516 }
517 }
518 if( fDebug & FINFO_DEBUG_MLINK ){
519 int ii;
@@ -536,15 +534,12 @@
536 graph_finish(pGraph, 1);
537 if( pGraph->nErr ){
538 graph_free(pGraph);
539 pGraph = 0;
540 }else{
541 int w = pGraph->mxRail*pGraph->iRailPitch + 28;
542 @ <tr><td></td><td>
543 @ <div id="grbtm" style="width:%d(w)px;"></div>
544 @ </td><td></td></tr>
545 }
546 }
547 @ </table>
548 timeline_output_graph_javascript(pGraph, 0, 1);
549 style_footer();
550 }
551
--- src/finfo.c
+++ src/finfo.c
@@ -182,11 +182,11 @@
182 if( rid==0 ){
183 fossil_fatal("no history for file: %b", &fname);
184 }
185 zFilename = blob_str(&fname);
186 db_prepare(&q,
187 "SELECT DISTINCT b.uuid, ci.uuid, date(event.mtime%s),"
188 " coalesce(event.ecomment, event.comment),"
189 " coalesce(event.euser, event.user),"
190 " (SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0"
191 " AND tagxref.rid=mlink.mid)" /* Tags */
192 " FROM mlink, blob b, event, blob ci, filename"
@@ -403,12 +403,10 @@
403 if( fShowId ) blob_appendf(&title, " (%d)", fnid);
404 }
405 @ <h2>%b(&title)</h2>
406 blob_reset(&title);
407 pGraph = graph_init();
 
 
408 @ <table id="timelineTable" class="timelineTable">
409 while( db_step(&q)==SQLITE_ROW ){
410 const char *zDate = db_column_text(&q, 0);
411 const char *zCom = db_column_text(&q, 1);
412 const char *zUser = db_column_text(&q, 2);
@@ -459,11 +457,11 @@
457 }
458 memcpy(zTime, &zDate[11], 5);
459 zTime[5] = 0;
460 @ <tr><td class="timelineTime">
461 @ %z(href("%R/timeline?c=%t",zDate))%s(zTime)</a></td>
462 @ <td class="timelineGraph"><div id="m%d(gidx)" class="tl-nodemark"></div></td>
463 if( zBgClr && zBgClr[0] ){
464 @ <td class="timelineTableCell" style="background-color: %h(zBgClr);">
465 }else{
466 @ <td class="timelineTableCell">
467 }
@@ -509,11 +507,11 @@
507 @ %z(href("%R/annotate?filename=%h&checkin=%s",z,zCkin))
508 @ [annotate]</a>
509 @ %z(href("%R/blame?filename=%h&checkin=%s",z,zCkin))
510 @ [blame]</a>
511 @ %z(href("%R/timeline?n=200&uf=%!S",zUuid))[check-ins&nbsp;using]</a>
512 if( fpid>0 ){
513 @ %z(href("%R/fdiff?sbs=1&v1=%!S&v2=%!S",zPUuid,zUuid))[diff]</a>
514 }
515 }
516 if( fDebug & FINFO_DEBUG_MLINK ){
517 int ii;
@@ -536,15 +534,12 @@
534 graph_finish(pGraph, 1);
535 if( pGraph->nErr ){
536 graph_free(pGraph);
537 pGraph = 0;
538 }else{
539 @ <tr class="timelineBottom"><td></td><td></td><td></td></tr>
 
 
 
540 }
541 }
542 @ </table>
543 timeline_output_graph_javascript(pGraph, 0, 1);
544 style_footer();
545 }
546
+8 -15
--- src/graph.c
+++ src/graph.c
@@ -47,11 +47,11 @@
4747
u8 isDup; /* True if this is duplicate of a prior entry */
4848
u8 isLeaf; /* True if this is a leaf node */
4949
u8 timeWarp; /* Child is earlier in time */
5050
u8 bDescender; /* True if riser from bottom of graph to here. */
5151
i8 iRail; /* Which rail this check-in appears on. 0-based.*/
52
- i8 mergeOut; /* Merge out on rail mergeOut/4. -1 for none */
52
+ i8 mergeOut; /* Merge out to this rail. -1 if no merge-out */
5353
u8 mergeIn[GR_MAX_RAIL]; /* Merge in from non-zero rails */
5454
int aiRiser[GR_MAX_RAIL]; /* Risers from this node to a higher row. */
5555
int mergeUpto; /* Draw the mergeOut rail up to this level */
5656
u64 mergeDown; /* Draw merge lines up from bottom of graph */
5757
@@ -61,11 +61,10 @@
6161
/* Context while building a graph
6262
*/
6363
struct GraphContext {
6464
int nErr; /* Number of errors encountered */
6565
int mxRail; /* Number of rails required to render the graph */
66
- int iRailPitch; /* Pixels between rail centers */
6766
GraphRow *pFirst; /* First row in the list */
6867
GraphRow *pLast; /* Last row in the list */
6968
int nBranch; /* Number of distinct branches */
7069
char **azBranch; /* Names of the branches */
7170
int nRow; /* Number of rows */
@@ -294,28 +293,27 @@
294293
u = pParent->aiRiser[pParent->iRail];
295294
if( u>=0 && u<pChild->idx ){
296295
/* The thick arrow up to the next primary child of pDesc goes
297296
** further up than the thin merge arrow riser, so draw them both
298297
** on the same rail. */
299
- pParent->mergeOut = pParent->iRail*4;
300
- if( pParent->iRail<pChild->iRail ) pParent->mergeOut += 2;
298
+ pParent->mergeOut = pParent->iRail;
301299
pParent->mergeUpto = pChild->idx;
302300
}else{
303301
/* The thin merge arrow riser is taller than the thick primary
304302
** child riser, so use separate rails. */
305303
int iTarget = pParent->iRail;
306304
pParent->mergeOut = findFreeRail(p, pChild->idx, pParent->idx-1,
307
- 0, iTarget)*4 + 1;
305
+ 0, iTarget);
308306
pParent->mergeUpto = pChild->idx;
309
- mask = BIT(pParent->mergeOut/4);
307
+ mask = BIT(pParent->mergeOut);
310308
for(pLoop=pChild->pNext; pLoop && pLoop->rid!=pParent->rid;
311309
pLoop=pLoop->pNext){
312310
pLoop->railInUse |= mask;
313311
}
314312
}
315313
}
316
- pChild->mergeIn[pParent->mergeOut/4] = (pParent->mergeOut&3)+1;
314
+ pChild->mergeIn[pParent->mergeOut] = 1;
317315
}
318316
319317
/*
320318
** Compute the maximum rail number.
321319
*/
@@ -322,11 +320,11 @@
322320
static void find_max_rail(GraphContext *p){
323321
GraphRow *pRow;
324322
p->mxRail = 0;
325323
for(pRow=p->pFirst; pRow; pRow=pRow->pNext){
326324
if( pRow->iRail>p->mxRail ) p->mxRail = pRow->iRail;
327
- if( pRow->mergeOut/4>p->mxRail ) p->mxRail = pRow->mergeOut/4;
325
+ if( pRow->mergeOut>p->mxRail ) p->mxRail = pRow->mergeOut;
328326
while( p->mxRail<GR_MAX_RAIL && pRow->mergeDown>(BIT(p->mxRail+1)-1) ){
329327
p->mxRail++;
330328
}
331329
}
332330
}
@@ -540,11 +538,11 @@
540538
if( pDesc==0 ){
541539
/* Merge from a node that is off-screen */
542540
int iMrail = findFreeRail(p, pRow->idx, p->nRow, 0, 0);
543541
if( p->mxRail>=GR_MAX_RAIL ) return;
544542
mask = BIT(iMrail);
545
- pRow->mergeIn[iMrail] = 2;
543
+ pRow->mergeIn[iMrail] = 1;
546544
pRow->mergeDown |= mask;
547545
for(pLoop=pRow->pNext; pLoop; pLoop=pLoop->pNext){
548546
pLoop->railInUse |= mask;
549547
}
550548
}else{
@@ -569,11 +567,11 @@
569567
if( !pRow->isDup ) continue;
570568
pRow->iRail = dupRail;
571569
pDesc = hashFind(p, pRow->rid);
572570
assert( pDesc!=0 && pDesc!=pRow );
573571
createMergeRiser(p, pDesc, pRow);
574
- if( pDesc->mergeOut/4>mxRail ) mxRail = pDesc->mergeOut/4;
572
+ if( pDesc->mergeOut>mxRail ) mxRail = pDesc->mergeOut;
575573
}
576574
if( dupRail<=mxRail ){
577575
dupRail = mxRail+1;
578576
for(pRow=p->pFirst; pRow; pRow=pRow->pNext){
579577
if( pRow->isDup ) pRow->iRail = dupRail;
@@ -584,12 +582,7 @@
584582
585583
/*
586584
** Find the maximum rail number.
587585
*/
588586
find_max_rail(p);
589
- p->iRailPitch = atoi(PD("railpitch","0"));
590
- if( p->iRailPitch<=0 ){
591
- p->iRailPitch = 18 - (p->mxRail/3);
592
- if( p->iRailPitch<11 ) p->iRailPitch = 11;
593
- }
594587
p->nErr = 0;
595588
}
596589
--- src/graph.c
+++ src/graph.c
@@ -47,11 +47,11 @@
47 u8 isDup; /* True if this is duplicate of a prior entry */
48 u8 isLeaf; /* True if this is a leaf node */
49 u8 timeWarp; /* Child is earlier in time */
50 u8 bDescender; /* True if riser from bottom of graph to here. */
51 i8 iRail; /* Which rail this check-in appears on. 0-based.*/
52 i8 mergeOut; /* Merge out on rail mergeOut/4. -1 for none */
53 u8 mergeIn[GR_MAX_RAIL]; /* Merge in from non-zero rails */
54 int aiRiser[GR_MAX_RAIL]; /* Risers from this node to a higher row. */
55 int mergeUpto; /* Draw the mergeOut rail up to this level */
56 u64 mergeDown; /* Draw merge lines up from bottom of graph */
57
@@ -61,11 +61,10 @@
61 /* Context while building a graph
62 */
63 struct GraphContext {
64 int nErr; /* Number of errors encountered */
65 int mxRail; /* Number of rails required to render the graph */
66 int iRailPitch; /* Pixels between rail centers */
67 GraphRow *pFirst; /* First row in the list */
68 GraphRow *pLast; /* Last row in the list */
69 int nBranch; /* Number of distinct branches */
70 char **azBranch; /* Names of the branches */
71 int nRow; /* Number of rows */
@@ -294,28 +293,27 @@
294 u = pParent->aiRiser[pParent->iRail];
295 if( u>=0 && u<pChild->idx ){
296 /* The thick arrow up to the next primary child of pDesc goes
297 ** further up than the thin merge arrow riser, so draw them both
298 ** on the same rail. */
299 pParent->mergeOut = pParent->iRail*4;
300 if( pParent->iRail<pChild->iRail ) pParent->mergeOut += 2;
301 pParent->mergeUpto = pChild->idx;
302 }else{
303 /* The thin merge arrow riser is taller than the thick primary
304 ** child riser, so use separate rails. */
305 int iTarget = pParent->iRail;
306 pParent->mergeOut = findFreeRail(p, pChild->idx, pParent->idx-1,
307 0, iTarget)*4 + 1;
308 pParent->mergeUpto = pChild->idx;
309 mask = BIT(pParent->mergeOut/4);
310 for(pLoop=pChild->pNext; pLoop && pLoop->rid!=pParent->rid;
311 pLoop=pLoop->pNext){
312 pLoop->railInUse |= mask;
313 }
314 }
315 }
316 pChild->mergeIn[pParent->mergeOut/4] = (pParent->mergeOut&3)+1;
317 }
318
319 /*
320 ** Compute the maximum rail number.
321 */
@@ -322,11 +320,11 @@
322 static void find_max_rail(GraphContext *p){
323 GraphRow *pRow;
324 p->mxRail = 0;
325 for(pRow=p->pFirst; pRow; pRow=pRow->pNext){
326 if( pRow->iRail>p->mxRail ) p->mxRail = pRow->iRail;
327 if( pRow->mergeOut/4>p->mxRail ) p->mxRail = pRow->mergeOut/4;
328 while( p->mxRail<GR_MAX_RAIL && pRow->mergeDown>(BIT(p->mxRail+1)-1) ){
329 p->mxRail++;
330 }
331 }
332 }
@@ -540,11 +538,11 @@
540 if( pDesc==0 ){
541 /* Merge from a node that is off-screen */
542 int iMrail = findFreeRail(p, pRow->idx, p->nRow, 0, 0);
543 if( p->mxRail>=GR_MAX_RAIL ) return;
544 mask = BIT(iMrail);
545 pRow->mergeIn[iMrail] = 2;
546 pRow->mergeDown |= mask;
547 for(pLoop=pRow->pNext; pLoop; pLoop=pLoop->pNext){
548 pLoop->railInUse |= mask;
549 }
550 }else{
@@ -569,11 +567,11 @@
569 if( !pRow->isDup ) continue;
570 pRow->iRail = dupRail;
571 pDesc = hashFind(p, pRow->rid);
572 assert( pDesc!=0 && pDesc!=pRow );
573 createMergeRiser(p, pDesc, pRow);
574 if( pDesc->mergeOut/4>mxRail ) mxRail = pDesc->mergeOut/4;
575 }
576 if( dupRail<=mxRail ){
577 dupRail = mxRail+1;
578 for(pRow=p->pFirst; pRow; pRow=pRow->pNext){
579 if( pRow->isDup ) pRow->iRail = dupRail;
@@ -584,12 +582,7 @@
584
585 /*
586 ** Find the maximum rail number.
587 */
588 find_max_rail(p);
589 p->iRailPitch = atoi(PD("railpitch","0"));
590 if( p->iRailPitch<=0 ){
591 p->iRailPitch = 18 - (p->mxRail/3);
592 if( p->iRailPitch<11 ) p->iRailPitch = 11;
593 }
594 p->nErr = 0;
595 }
596
--- src/graph.c
+++ src/graph.c
@@ -47,11 +47,11 @@
47 u8 isDup; /* True if this is duplicate of a prior entry */
48 u8 isLeaf; /* True if this is a leaf node */
49 u8 timeWarp; /* Child is earlier in time */
50 u8 bDescender; /* True if riser from bottom of graph to here. */
51 i8 iRail; /* Which rail this check-in appears on. 0-based.*/
52 i8 mergeOut; /* Merge out to this rail. -1 if no merge-out */
53 u8 mergeIn[GR_MAX_RAIL]; /* Merge in from non-zero rails */
54 int aiRiser[GR_MAX_RAIL]; /* Risers from this node to a higher row. */
55 int mergeUpto; /* Draw the mergeOut rail up to this level */
56 u64 mergeDown; /* Draw merge lines up from bottom of graph */
57
@@ -61,11 +61,10 @@
61 /* Context while building a graph
62 */
63 struct GraphContext {
64 int nErr; /* Number of errors encountered */
65 int mxRail; /* Number of rails required to render the graph */
 
66 GraphRow *pFirst; /* First row in the list */
67 GraphRow *pLast; /* Last row in the list */
68 int nBranch; /* Number of distinct branches */
69 char **azBranch; /* Names of the branches */
70 int nRow; /* Number of rows */
@@ -294,28 +293,27 @@
293 u = pParent->aiRiser[pParent->iRail];
294 if( u>=0 && u<pChild->idx ){
295 /* The thick arrow up to the next primary child of pDesc goes
296 ** further up than the thin merge arrow riser, so draw them both
297 ** on the same rail. */
298 pParent->mergeOut = pParent->iRail;
 
299 pParent->mergeUpto = pChild->idx;
300 }else{
301 /* The thin merge arrow riser is taller than the thick primary
302 ** child riser, so use separate rails. */
303 int iTarget = pParent->iRail;
304 pParent->mergeOut = findFreeRail(p, pChild->idx, pParent->idx-1,
305 0, iTarget);
306 pParent->mergeUpto = pChild->idx;
307 mask = BIT(pParent->mergeOut);
308 for(pLoop=pChild->pNext; pLoop && pLoop->rid!=pParent->rid;
309 pLoop=pLoop->pNext){
310 pLoop->railInUse |= mask;
311 }
312 }
313 }
314 pChild->mergeIn[pParent->mergeOut] = 1;
315 }
316
317 /*
318 ** Compute the maximum rail number.
319 */
@@ -322,11 +320,11 @@
320 static void find_max_rail(GraphContext *p){
321 GraphRow *pRow;
322 p->mxRail = 0;
323 for(pRow=p->pFirst; pRow; pRow=pRow->pNext){
324 if( pRow->iRail>p->mxRail ) p->mxRail = pRow->iRail;
325 if( pRow->mergeOut>p->mxRail ) p->mxRail = pRow->mergeOut;
326 while( p->mxRail<GR_MAX_RAIL && pRow->mergeDown>(BIT(p->mxRail+1)-1) ){
327 p->mxRail++;
328 }
329 }
330 }
@@ -540,11 +538,11 @@
538 if( pDesc==0 ){
539 /* Merge from a node that is off-screen */
540 int iMrail = findFreeRail(p, pRow->idx, p->nRow, 0, 0);
541 if( p->mxRail>=GR_MAX_RAIL ) return;
542 mask = BIT(iMrail);
543 pRow->mergeIn[iMrail] = 1;
544 pRow->mergeDown |= mask;
545 for(pLoop=pRow->pNext; pLoop; pLoop=pLoop->pNext){
546 pLoop->railInUse |= mask;
547 }
548 }else{
@@ -569,11 +567,11 @@
567 if( !pRow->isDup ) continue;
568 pRow->iRail = dupRail;
569 pDesc = hashFind(p, pRow->rid);
570 assert( pDesc!=0 && pDesc!=pRow );
571 createMergeRiser(p, pDesc, pRow);
572 if( pDesc->mergeOut>mxRail ) mxRail = pDesc->mergeOut;
573 }
574 if( dupRail<=mxRail ){
575 dupRail = mxRail+1;
576 for(pRow=p->pFirst; pRow; pRow=pRow->pNext){
577 if( pRow->isDup ) pRow->iRail = dupRail;
@@ -584,12 +582,7 @@
582
583 /*
584 ** Find the maximum rail number.
585 */
586 find_max_rail(p);
 
 
 
 
 
587 p->nErr = 0;
588 }
589
+2 -2
--- src/http.c
+++ src/http.c
@@ -338,14 +338,14 @@
338338
j = strlen(zLine) - 1;
339339
while( j>4 && fossil_strcmp(&zLine[j-4],"/xfer")==0 ){
340340
j -= 4;
341341
zLine[j] = 0;
342342
}
343
+ fossil_print("redirect with status %d to %s\n", rc, &zLine[i]);
344
+ url_parse(&zLine[i], 0);
343345
transport_close(&g.url);
344346
transport_global_shutdown(&g.url);
345
- fossil_print("redirect with status %d to %s\n", rc, &zLine[i]);
346
- url_parse(&zLine[i], 0);
347347
fSeenHttpAuth = 0;
348348
if( g.zHttpAuth ) free(g.zHttpAuth);
349349
g.zHttpAuth = get_httpauth();
350350
return http_exchange(pSend, pReply, useLogin, maxRedirect);
351351
}else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){
352352
--- src/http.c
+++ src/http.c
@@ -338,14 +338,14 @@
338 j = strlen(zLine) - 1;
339 while( j>4 && fossil_strcmp(&zLine[j-4],"/xfer")==0 ){
340 j -= 4;
341 zLine[j] = 0;
342 }
 
 
343 transport_close(&g.url);
344 transport_global_shutdown(&g.url);
345 fossil_print("redirect with status %d to %s\n", rc, &zLine[i]);
346 url_parse(&zLine[i], 0);
347 fSeenHttpAuth = 0;
348 if( g.zHttpAuth ) free(g.zHttpAuth);
349 g.zHttpAuth = get_httpauth();
350 return http_exchange(pSend, pReply, useLogin, maxRedirect);
351 }else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){
352
--- src/http.c
+++ src/http.c
@@ -338,14 +338,14 @@
338 j = strlen(zLine) - 1;
339 while( j>4 && fossil_strcmp(&zLine[j-4],"/xfer")==0 ){
340 j -= 4;
341 zLine[j] = 0;
342 }
343 fossil_print("redirect with status %d to %s\n", rc, &zLine[i]);
344 url_parse(&zLine[i], 0);
345 transport_close(&g.url);
346 transport_global_shutdown(&g.url);
 
 
347 fSeenHttpAuth = 0;
348 if( g.zHttpAuth ) free(g.zHttpAuth);
349 g.zHttpAuth = get_httpauth();
350 return http_exchange(pSend, pReply, useLogin, maxRedirect);
351 }else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){
352
+28 -14
--- src/info.c
+++ src/info.c
@@ -368,54 +368,68 @@
368368
const char *zOldName, /* Prior name. NULL if no name change. */
369369
u64 diffFlags, /* Flags for text_diff(). Zero to omit diffs */
370370
ReCompiled *pRe, /* Only show diffs that match this regex, if not NULL */
371371
int mperm /* executable or symlink permission for zNew */
372372
){
373
+ @ <p>
373374
if( !g.perm.Hyperlink ){
374375
if( zNew==0 ){
375
- @ <p>Deleted %h(zName)</p>
376
+ @ Deleted %h(zName).
376377
}else if( zOld==0 ){
377
- @ <p>Added %h(zName)</p>
378
+ @ Added %h(zName).
378379
}else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){
379
- @ <p>Name change from %h(zOldName) to %h(zName)
380
+ @ Name change from %h(zOldName) to %h(zName).
380381
}else if( fossil_strcmp(zNew, zOld)==0 ){
381
- @ <p>Execute permission %s(( mperm==PERM_EXE )?"set":"cleared")
382
- @ for %h(zName)</p>
382
+ if( mperm==PERM_EXE ){
383
+ @ %h(zName) became executable.
384
+ }else if( mperm==PERM_LNK ){
385
+ @ %h(zName) became a symlink.
386
+ }else{
387
+ @ %h(zName) became a regular file.
388
+ }
383389
}else{
384
- @ <p>Changes to %h(zName)</p>
390
+ @ Changes to %h(zName).
385391
}
386392
if( diffFlags ){
387393
append_diff(zOld, zNew, diffFlags, pRe);
388394
}
389395
}else{
390396
if( zOld && zNew ){
391397
if( fossil_strcmp(zOld, zNew)!=0 ){
392
- @ <p>Modified %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
398
+ @ Modified %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
393399
@ from %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a>
394400
@ to %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>.
395401
}else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){
396
- @ <p>Name change
402
+ @ Name change
397403
@ from %z(href("%R/finfo?name=%T",zOldName))%h(zOldName)</a>
398404
@ to %z(href("%R/finfo?name=%T",zName))%h(zName)</a>.
399405
}else{
400
- @ <p>Execute permission %s(( mperm==PERM_EXE )?"set":"cleared") for
401
- @ %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
406
+ @ %z(href("%R/finfo?name=%T",zName))%h(zName)</a> became
407
+ if( mperm==PERM_EXE ){
408
+ @ executable with contents
409
+ }else if( mperm==PERM_LNK ){
410
+ @ a symlink with target
411
+ }else{
412
+ @ a regular file with contents
413
+ }
414
+ @ %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>.
402415
}
403416
}else if( zOld ){
404
- @ <p>Deleted %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
405
- @ version %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a>
417
+ @ Deleted %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
418
+ @ version %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a>.
406419
}else{
407
- @ <p>Added %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
408
- @ version %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>
420
+ @ Added %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
421
+ @ version %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>.
409422
}
410423
if( diffFlags ){
411424
append_diff(zOld, zNew, diffFlags, pRe);
412425
}else if( zOld && zNew && fossil_strcmp(zOld,zNew)!=0 ){
413426
@ &nbsp;&nbsp;
414427
@ %z(href("%R/fdiff?v1=%!S&v2=%!S&sbs=1",zOld,zNew))[diff]</a>
415428
}
416429
}
430
+ @ </p>
417431
}
418432
419433
/*
420434
** Generate javascript to enhance HTML diffs.
421435
*/
422436
--- src/info.c
+++ src/info.c
@@ -368,54 +368,68 @@
368 const char *zOldName, /* Prior name. NULL if no name change. */
369 u64 diffFlags, /* Flags for text_diff(). Zero to omit diffs */
370 ReCompiled *pRe, /* Only show diffs that match this regex, if not NULL */
371 int mperm /* executable or symlink permission for zNew */
372 ){
 
373 if( !g.perm.Hyperlink ){
374 if( zNew==0 ){
375 @ <p>Deleted %h(zName)</p>
376 }else if( zOld==0 ){
377 @ <p>Added %h(zName)</p>
378 }else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){
379 @ <p>Name change from %h(zOldName) to %h(zName)
380 }else if( fossil_strcmp(zNew, zOld)==0 ){
381 @ <p>Execute permission %s(( mperm==PERM_EXE )?"set":"cleared")
382 @ for %h(zName)</p>
 
 
 
 
 
383 }else{
384 @ <p>Changes to %h(zName)</p>
385 }
386 if( diffFlags ){
387 append_diff(zOld, zNew, diffFlags, pRe);
388 }
389 }else{
390 if( zOld && zNew ){
391 if( fossil_strcmp(zOld, zNew)!=0 ){
392 @ <p>Modified %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
393 @ from %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a>
394 @ to %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>.
395 }else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){
396 @ <p>Name change
397 @ from %z(href("%R/finfo?name=%T",zOldName))%h(zOldName)</a>
398 @ to %z(href("%R/finfo?name=%T",zName))%h(zName)</a>.
399 }else{
400 @ <p>Execute permission %s(( mperm==PERM_EXE )?"set":"cleared") for
401 @ %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
 
 
 
 
 
 
 
402 }
403 }else if( zOld ){
404 @ <p>Deleted %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
405 @ version %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a>
406 }else{
407 @ <p>Added %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
408 @ version %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>
409 }
410 if( diffFlags ){
411 append_diff(zOld, zNew, diffFlags, pRe);
412 }else if( zOld && zNew && fossil_strcmp(zOld,zNew)!=0 ){
413 @ &nbsp;&nbsp;
414 @ %z(href("%R/fdiff?v1=%!S&v2=%!S&sbs=1",zOld,zNew))[diff]</a>
415 }
416 }
 
417 }
418
419 /*
420 ** Generate javascript to enhance HTML diffs.
421 */
422
--- src/info.c
+++ src/info.c
@@ -368,54 +368,68 @@
368 const char *zOldName, /* Prior name. NULL if no name change. */
369 u64 diffFlags, /* Flags for text_diff(). Zero to omit diffs */
370 ReCompiled *pRe, /* Only show diffs that match this regex, if not NULL */
371 int mperm /* executable or symlink permission for zNew */
372 ){
373 @ <p>
374 if( !g.perm.Hyperlink ){
375 if( zNew==0 ){
376 @ Deleted %h(zName).
377 }else if( zOld==0 ){
378 @ Added %h(zName).
379 }else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){
380 @ Name change from %h(zOldName) to %h(zName).
381 }else if( fossil_strcmp(zNew, zOld)==0 ){
382 if( mperm==PERM_EXE ){
383 @ %h(zName) became executable.
384 }else if( mperm==PERM_LNK ){
385 @ %h(zName) became a symlink.
386 }else{
387 @ %h(zName) became a regular file.
388 }
389 }else{
390 @ Changes to %h(zName).
391 }
392 if( diffFlags ){
393 append_diff(zOld, zNew, diffFlags, pRe);
394 }
395 }else{
396 if( zOld && zNew ){
397 if( fossil_strcmp(zOld, zNew)!=0 ){
398 @ Modified %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
399 @ from %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a>
400 @ to %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>.
401 }else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){
402 @ Name change
403 @ from %z(href("%R/finfo?name=%T",zOldName))%h(zOldName)</a>
404 @ to %z(href("%R/finfo?name=%T",zName))%h(zName)</a>.
405 }else{
406 @ %z(href("%R/finfo?name=%T",zName))%h(zName)</a> became
407 if( mperm==PERM_EXE ){
408 @ executable with contents
409 }else if( mperm==PERM_LNK ){
410 @ a symlink with target
411 }else{
412 @ a regular file with contents
413 }
414 @ %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>.
415 }
416 }else if( zOld ){
417 @ Deleted %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
418 @ version %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a>.
419 }else{
420 @ Added %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
421 @ version %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>.
422 }
423 if( diffFlags ){
424 append_diff(zOld, zNew, diffFlags, pRe);
425 }else if( zOld && zNew && fossil_strcmp(zOld,zNew)!=0 ){
426 @ &nbsp;&nbsp;
427 @ %z(href("%R/fdiff?v1=%!S&v2=%!S&sbs=1",zOld,zNew))[diff]</a>
428 }
429 }
430 @ </p>
431 }
432
433 /*
434 ** Generate javascript to enhance HTML diffs.
435 */
436
+1
--- src/json.c
+++ src/json.c
@@ -1292,10 +1292,11 @@
12921292
INT(g, nAux);
12931293
INT(g, allowSymlinks);
12941294
12951295
CSTR(g, zMainDbType);
12961296
CSTR(g, zConfigDbType);
1297
+ CSTR(g, zOpenRevision);
12971298
CSTR(g, zLocalRoot);
12981299
CSTR(g, zPath);
12991300
CSTR(g, zExtra);
13001301
CSTR(g, zBaseURL);
13011302
CSTR(g, zTop);
13021303
--- src/json.c
+++ src/json.c
@@ -1292,10 +1292,11 @@
1292 INT(g, nAux);
1293 INT(g, allowSymlinks);
1294
1295 CSTR(g, zMainDbType);
1296 CSTR(g, zConfigDbType);
 
1297 CSTR(g, zLocalRoot);
1298 CSTR(g, zPath);
1299 CSTR(g, zExtra);
1300 CSTR(g, zBaseURL);
1301 CSTR(g, zTop);
1302
--- src/json.c
+++ src/json.c
@@ -1292,10 +1292,11 @@
1292 INT(g, nAux);
1293 INT(g, allowSymlinks);
1294
1295 CSTR(g, zMainDbType);
1296 CSTR(g, zConfigDbType);
1297 CSTR(g, zOpenRevision);
1298 CSTR(g, zLocalRoot);
1299 CSTR(g, zPath);
1300 CSTR(g, zExtra);
1301 CSTR(g, zBaseURL);
1302 CSTR(g, zTop);
1303
+13 -5
--- src/main.c
+++ src/main.c
@@ -135,10 +135,11 @@
135135
char *zRepositoryOption; /* Most recent cached repository option value */
136136
char *zRepositoryName; /* Name of the repository database */
137137
char *zLocalDbName; /* Name of the local database */
138138
const char *zMainDbType;/* "configdb", "localdb", or "repository" */
139139
const char *zConfigDbType; /* "configdb", "localdb", or "repository" */
140
+ char *zOpenRevision; /* Check-in version to use during database open */
140141
int localOpen; /* True if the local database is open */
141142
char *zLocalRoot; /* The directory holding the local database */
142143
int minPrefix; /* Number of digits needed for a distinct UUID */
143144
int fSqlTrace; /* True if --sqltrace flag is present */
144145
int fSqlStats; /* True if --sqltrace or --sqlstats are present */
@@ -1441,20 +1442,27 @@
14411442
vfile_scan(&base, blob_size(&base), 0, 0, 0);
14421443
db_multi_exec("DELETE FROM sfile WHERE x NOT GLOB '*.fossil'");
14431444
n = db_int(0, "SELECT count(*) FROM sfile");
14441445
if( n>0 ){
14451446
Stmt q;
1447
+ @ <html>
1448
+ @ <head>
1449
+ @ <title>Repository List</title>
1450
+ @ </head>
1451
+ @ <body>
14461452
@ <h1>Available Repositories:</h1>
14471453
@ <ol>
14481454
db_prepare(&q, "SELECT x, substr(x,-7,-100000)||'/home'"
14491455
" FROM sfile ORDER BY x COLLATE nocase;");
14501456
while( db_step(&q)==SQLITE_ROW ){
14511457
const char *zName = db_column_text(&q, 0);
14521458
const char *zUrl = db_column_text(&q, 1);
1453
- @ <li><a href="%h(zUrl)">%h(zName)</a></li>
1459
+ @ <li><a href="%h(zUrl)" target="_blank">%h(zName)</a></li>
14541460
}
14551461
@ </ol>
1462
+ @ </body>
1463
+ @ </html>
14561464
cgi_reply();
14571465
}
14581466
sqlite3_close(g.db);
14591467
g.db = 0;
14601468
return n;
@@ -1563,16 +1571,16 @@
15631571
zRepo[j] = '.';
15641572
}
15651573
15661574
if( szFile<1024 ){
15671575
set_base_url(0);
1568
- if( zNotFound ){
1569
- cgi_redirect(zNotFound);
1570
- }else if( strcmp(zPathInfo,"/")==0
1576
+ if( strcmp(zPathInfo,"/")==0
15711577
&& allowRepoList
15721578
&& repo_list_page() ){
15731579
/* Will return a list of repositories */
1580
+ }else if( zNotFound ){
1581
+ cgi_redirect(zNotFound);
15741582
}else{
15751583
#ifdef FOSSIL_ENABLE_JSON
15761584
if(g.json.isJsonMode){
15771585
json_err(FSL_JSON_E_RESOURCE_NOT_FOUND,NULL,1);
15781586
return;
@@ -2169,18 +2177,18 @@
21692177
zIpAddr = fossil_getenv("REMOTE_HOST"); /* From stunnel */
21702178
cgi_replace_parameter("HTTPS","on");
21712179
}
21722180
zHost = find_option("host", 0, 1);
21732181
if( zHost ) cgi_replace_parameter("HTTP_HOST",zHost);
2174
- g.cgiOutput = 1;
21752182
21762183
/* We should be done with options.. */
21772184
verify_all_options();
21782185
21792186
if( g.argc!=2 && g.argc!=3 && g.argc!=5 && g.argc!=6 ){
21802187
fossil_fatal("no repository specified");
21812188
}
2189
+ g.cgiOutput = 1;
21822190
g.fullHttpReply = 1;
21832191
if( g.argc>=5 ){
21842192
g.httpIn = fossil_fopen(g.argv[2], "rb");
21852193
g.httpOut = fossil_fopen(g.argv[3], "wb");
21862194
zIpAddr = g.argv[4];
21872195
--- src/main.c
+++ src/main.c
@@ -135,10 +135,11 @@
135 char *zRepositoryOption; /* Most recent cached repository option value */
136 char *zRepositoryName; /* Name of the repository database */
137 char *zLocalDbName; /* Name of the local database */
138 const char *zMainDbType;/* "configdb", "localdb", or "repository" */
139 const char *zConfigDbType; /* "configdb", "localdb", or "repository" */
 
140 int localOpen; /* True if the local database is open */
141 char *zLocalRoot; /* The directory holding the local database */
142 int minPrefix; /* Number of digits needed for a distinct UUID */
143 int fSqlTrace; /* True if --sqltrace flag is present */
144 int fSqlStats; /* True if --sqltrace or --sqlstats are present */
@@ -1441,20 +1442,27 @@
1441 vfile_scan(&base, blob_size(&base), 0, 0, 0);
1442 db_multi_exec("DELETE FROM sfile WHERE x NOT GLOB '*.fossil'");
1443 n = db_int(0, "SELECT count(*) FROM sfile");
1444 if( n>0 ){
1445 Stmt q;
 
 
 
 
 
1446 @ <h1>Available Repositories:</h1>
1447 @ <ol>
1448 db_prepare(&q, "SELECT x, substr(x,-7,-100000)||'/home'"
1449 " FROM sfile ORDER BY x COLLATE nocase;");
1450 while( db_step(&q)==SQLITE_ROW ){
1451 const char *zName = db_column_text(&q, 0);
1452 const char *zUrl = db_column_text(&q, 1);
1453 @ <li><a href="%h(zUrl)">%h(zName)</a></li>
1454 }
1455 @ </ol>
 
 
1456 cgi_reply();
1457 }
1458 sqlite3_close(g.db);
1459 g.db = 0;
1460 return n;
@@ -1563,16 +1571,16 @@
1563 zRepo[j] = '.';
1564 }
1565
1566 if( szFile<1024 ){
1567 set_base_url(0);
1568 if( zNotFound ){
1569 cgi_redirect(zNotFound);
1570 }else if( strcmp(zPathInfo,"/")==0
1571 && allowRepoList
1572 && repo_list_page() ){
1573 /* Will return a list of repositories */
 
 
1574 }else{
1575 #ifdef FOSSIL_ENABLE_JSON
1576 if(g.json.isJsonMode){
1577 json_err(FSL_JSON_E_RESOURCE_NOT_FOUND,NULL,1);
1578 return;
@@ -2169,18 +2177,18 @@
2169 zIpAddr = fossil_getenv("REMOTE_HOST"); /* From stunnel */
2170 cgi_replace_parameter("HTTPS","on");
2171 }
2172 zHost = find_option("host", 0, 1);
2173 if( zHost ) cgi_replace_parameter("HTTP_HOST",zHost);
2174 g.cgiOutput = 1;
2175
2176 /* We should be done with options.. */
2177 verify_all_options();
2178
2179 if( g.argc!=2 && g.argc!=3 && g.argc!=5 && g.argc!=6 ){
2180 fossil_fatal("no repository specified");
2181 }
 
2182 g.fullHttpReply = 1;
2183 if( g.argc>=5 ){
2184 g.httpIn = fossil_fopen(g.argv[2], "rb");
2185 g.httpOut = fossil_fopen(g.argv[3], "wb");
2186 zIpAddr = g.argv[4];
2187
--- src/main.c
+++ src/main.c
@@ -135,10 +135,11 @@
135 char *zRepositoryOption; /* Most recent cached repository option value */
136 char *zRepositoryName; /* Name of the repository database */
137 char *zLocalDbName; /* Name of the local database */
138 const char *zMainDbType;/* "configdb", "localdb", or "repository" */
139 const char *zConfigDbType; /* "configdb", "localdb", or "repository" */
140 char *zOpenRevision; /* Check-in version to use during database open */
141 int localOpen; /* True if the local database is open */
142 char *zLocalRoot; /* The directory holding the local database */
143 int minPrefix; /* Number of digits needed for a distinct UUID */
144 int fSqlTrace; /* True if --sqltrace flag is present */
145 int fSqlStats; /* True if --sqltrace or --sqlstats are present */
@@ -1441,20 +1442,27 @@
1442 vfile_scan(&base, blob_size(&base), 0, 0, 0);
1443 db_multi_exec("DELETE FROM sfile WHERE x NOT GLOB '*.fossil'");
1444 n = db_int(0, "SELECT count(*) FROM sfile");
1445 if( n>0 ){
1446 Stmt q;
1447 @ <html>
1448 @ <head>
1449 @ <title>Repository List</title>
1450 @ </head>
1451 @ <body>
1452 @ <h1>Available Repositories:</h1>
1453 @ <ol>
1454 db_prepare(&q, "SELECT x, substr(x,-7,-100000)||'/home'"
1455 " FROM sfile ORDER BY x COLLATE nocase;");
1456 while( db_step(&q)==SQLITE_ROW ){
1457 const char *zName = db_column_text(&q, 0);
1458 const char *zUrl = db_column_text(&q, 1);
1459 @ <li><a href="%h(zUrl)" target="_blank">%h(zName)</a></li>
1460 }
1461 @ </ol>
1462 @ </body>
1463 @ </html>
1464 cgi_reply();
1465 }
1466 sqlite3_close(g.db);
1467 g.db = 0;
1468 return n;
@@ -1563,16 +1571,16 @@
1571 zRepo[j] = '.';
1572 }
1573
1574 if( szFile<1024 ){
1575 set_base_url(0);
1576 if( strcmp(zPathInfo,"/")==0
 
 
1577 && allowRepoList
1578 && repo_list_page() ){
1579 /* Will return a list of repositories */
1580 }else if( zNotFound ){
1581 cgi_redirect(zNotFound);
1582 }else{
1583 #ifdef FOSSIL_ENABLE_JSON
1584 if(g.json.isJsonMode){
1585 json_err(FSL_JSON_E_RESOURCE_NOT_FOUND,NULL,1);
1586 return;
@@ -2169,18 +2177,18 @@
2177 zIpAddr = fossil_getenv("REMOTE_HOST"); /* From stunnel */
2178 cgi_replace_parameter("HTTPS","on");
2179 }
2180 zHost = find_option("host", 0, 1);
2181 if( zHost ) cgi_replace_parameter("HTTP_HOST",zHost);
 
2182
2183 /* We should be done with options.. */
2184 verify_all_options();
2185
2186 if( g.argc!=2 && g.argc!=3 && g.argc!=5 && g.argc!=6 ){
2187 fossil_fatal("no repository specified");
2188 }
2189 g.cgiOutput = 1;
2190 g.fullHttpReply = 1;
2191 if( g.argc>=5 ){
2192 g.httpIn = fossil_fopen(g.argv[2], "rb");
2193 g.httpOut = fossil_fopen(g.argv[3], "wb");
2194 zIpAddr = g.argv[4];
2195
+14 -1
--- src/main.mk
+++ src/main.mk
@@ -84,10 +84,11 @@
8484
$(SRCDIR)/merge.c \
8585
$(SRCDIR)/merge3.c \
8686
$(SRCDIR)/moderate.c \
8787
$(SRCDIR)/name.c \
8888
$(SRCDIR)/path.c \
89
+ $(SRCDIR)/piechart.c \
8990
$(SRCDIR)/pivot.c \
9091
$(SRCDIR)/popen.c \
9192
$(SRCDIR)/pqueue.c \
9293
$(SRCDIR)/printf.c \
9394
$(SRCDIR)/publish.c \
@@ -255,10 +256,11 @@
255256
$(OBJDIR)/merge_.c \
256257
$(OBJDIR)/merge3_.c \
257258
$(OBJDIR)/moderate_.c \
258259
$(OBJDIR)/name_.c \
259260
$(OBJDIR)/path_.c \
261
+ $(OBJDIR)/piechart_.c \
260262
$(OBJDIR)/pivot_.c \
261263
$(OBJDIR)/popen_.c \
262264
$(OBJDIR)/pqueue_.c \
263265
$(OBJDIR)/printf_.c \
264266
$(OBJDIR)/publish_.c \
@@ -375,10 +377,11 @@
375377
$(OBJDIR)/merge.o \
376378
$(OBJDIR)/merge3.o \
377379
$(OBJDIR)/moderate.o \
378380
$(OBJDIR)/name.o \
379381
$(OBJDIR)/path.o \
382
+ $(OBJDIR)/piechart.o \
380383
$(OBJDIR)/pivot.o \
381384
$(OBJDIR)/popen.o \
382385
$(OBJDIR)/pqueue.o \
383386
$(OBJDIR)/printf.o \
384387
$(OBJDIR)/publish.o \
@@ -474,11 +477,12 @@
474477
-DSQLITE_THREADSAFE=0 \
475478
-DSQLITE_DEFAULT_FILE_FORMAT=4 \
476479
-DSQLITE_OMIT_DEPRECATED \
477480
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
478481
-DSQLITE_ENABLE_FTS4 \
479
- -DSQLITE_ENABLE_FTS3_PARENTHESIS
482
+ -DSQLITE_ENABLE_FTS3_PARENTHESIS \
483
+ -DSQLITE_ENABLE_DBSTAT_VTAB
480484
481485
# Setup the options used to compile the included SQLite shell.
482486
SHELL_OPTIONS = -Dmain=sqlite3_shell \
483487
-DSQLITE_OMIT_LOAD_EXTENSION=1 \
484488
-DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
@@ -606,10 +610,11 @@
606610
$(OBJDIR)/merge_.c:$(OBJDIR)/merge.h \
607611
$(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h \
608612
$(OBJDIR)/moderate_.c:$(OBJDIR)/moderate.h \
609613
$(OBJDIR)/name_.c:$(OBJDIR)/name.h \
610614
$(OBJDIR)/path_.c:$(OBJDIR)/path.h \
615
+ $(OBJDIR)/piechart_.c:$(OBJDIR)/piechart.h \
611616
$(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
612617
$(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
613618
$(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
614619
$(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
615620
$(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
@@ -1234,10 +1239,18 @@
12341239
12351240
$(OBJDIR)/path.o: $(OBJDIR)/path_.c $(OBJDIR)/path.h $(SRCDIR)/config.h
12361241
$(XTCC) -o $(OBJDIR)/path.o -c $(OBJDIR)/path_.c
12371242
12381243
$(OBJDIR)/path.h: $(OBJDIR)/headers
1244
+
1245
+$(OBJDIR)/piechart_.c: $(SRCDIR)/piechart.c $(OBJDIR)/translate
1246
+ $(OBJDIR)/translate $(SRCDIR)/piechart.c >$@
1247
+
1248
+$(OBJDIR)/piechart.o: $(OBJDIR)/piechart_.c $(OBJDIR)/piechart.h $(SRCDIR)/config.h
1249
+ $(XTCC) -o $(OBJDIR)/piechart.o -c $(OBJDIR)/piechart_.c
1250
+
1251
+$(OBJDIR)/piechart.h: $(OBJDIR)/headers
12391252
12401253
$(OBJDIR)/pivot_.c: $(SRCDIR)/pivot.c $(OBJDIR)/translate
12411254
$(OBJDIR)/translate $(SRCDIR)/pivot.c >$@
12421255
12431256
$(OBJDIR)/pivot.o: $(OBJDIR)/pivot_.c $(OBJDIR)/pivot.h $(SRCDIR)/config.h
12441257
--- src/main.mk
+++ src/main.mk
@@ -84,10 +84,11 @@
84 $(SRCDIR)/merge.c \
85 $(SRCDIR)/merge3.c \
86 $(SRCDIR)/moderate.c \
87 $(SRCDIR)/name.c \
88 $(SRCDIR)/path.c \
 
89 $(SRCDIR)/pivot.c \
90 $(SRCDIR)/popen.c \
91 $(SRCDIR)/pqueue.c \
92 $(SRCDIR)/printf.c \
93 $(SRCDIR)/publish.c \
@@ -255,10 +256,11 @@
255 $(OBJDIR)/merge_.c \
256 $(OBJDIR)/merge3_.c \
257 $(OBJDIR)/moderate_.c \
258 $(OBJDIR)/name_.c \
259 $(OBJDIR)/path_.c \
 
260 $(OBJDIR)/pivot_.c \
261 $(OBJDIR)/popen_.c \
262 $(OBJDIR)/pqueue_.c \
263 $(OBJDIR)/printf_.c \
264 $(OBJDIR)/publish_.c \
@@ -375,10 +377,11 @@
375 $(OBJDIR)/merge.o \
376 $(OBJDIR)/merge3.o \
377 $(OBJDIR)/moderate.o \
378 $(OBJDIR)/name.o \
379 $(OBJDIR)/path.o \
 
380 $(OBJDIR)/pivot.o \
381 $(OBJDIR)/popen.o \
382 $(OBJDIR)/pqueue.o \
383 $(OBJDIR)/printf.o \
384 $(OBJDIR)/publish.o \
@@ -474,11 +477,12 @@
474 -DSQLITE_THREADSAFE=0 \
475 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
476 -DSQLITE_OMIT_DEPRECATED \
477 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
478 -DSQLITE_ENABLE_FTS4 \
479 -DSQLITE_ENABLE_FTS3_PARENTHESIS
 
480
481 # Setup the options used to compile the included SQLite shell.
482 SHELL_OPTIONS = -Dmain=sqlite3_shell \
483 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
484 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
@@ -606,10 +610,11 @@
606 $(OBJDIR)/merge_.c:$(OBJDIR)/merge.h \
607 $(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h \
608 $(OBJDIR)/moderate_.c:$(OBJDIR)/moderate.h \
609 $(OBJDIR)/name_.c:$(OBJDIR)/name.h \
610 $(OBJDIR)/path_.c:$(OBJDIR)/path.h \
 
611 $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
612 $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
613 $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
614 $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
615 $(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
@@ -1234,10 +1239,18 @@
1234
1235 $(OBJDIR)/path.o: $(OBJDIR)/path_.c $(OBJDIR)/path.h $(SRCDIR)/config.h
1236 $(XTCC) -o $(OBJDIR)/path.o -c $(OBJDIR)/path_.c
1237
1238 $(OBJDIR)/path.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
1239
1240 $(OBJDIR)/pivot_.c: $(SRCDIR)/pivot.c $(OBJDIR)/translate
1241 $(OBJDIR)/translate $(SRCDIR)/pivot.c >$@
1242
1243 $(OBJDIR)/pivot.o: $(OBJDIR)/pivot_.c $(OBJDIR)/pivot.h $(SRCDIR)/config.h
1244
--- src/main.mk
+++ src/main.mk
@@ -84,10 +84,11 @@
84 $(SRCDIR)/merge.c \
85 $(SRCDIR)/merge3.c \
86 $(SRCDIR)/moderate.c \
87 $(SRCDIR)/name.c \
88 $(SRCDIR)/path.c \
89 $(SRCDIR)/piechart.c \
90 $(SRCDIR)/pivot.c \
91 $(SRCDIR)/popen.c \
92 $(SRCDIR)/pqueue.c \
93 $(SRCDIR)/printf.c \
94 $(SRCDIR)/publish.c \
@@ -255,10 +256,11 @@
256 $(OBJDIR)/merge_.c \
257 $(OBJDIR)/merge3_.c \
258 $(OBJDIR)/moderate_.c \
259 $(OBJDIR)/name_.c \
260 $(OBJDIR)/path_.c \
261 $(OBJDIR)/piechart_.c \
262 $(OBJDIR)/pivot_.c \
263 $(OBJDIR)/popen_.c \
264 $(OBJDIR)/pqueue_.c \
265 $(OBJDIR)/printf_.c \
266 $(OBJDIR)/publish_.c \
@@ -375,10 +377,11 @@
377 $(OBJDIR)/merge.o \
378 $(OBJDIR)/merge3.o \
379 $(OBJDIR)/moderate.o \
380 $(OBJDIR)/name.o \
381 $(OBJDIR)/path.o \
382 $(OBJDIR)/piechart.o \
383 $(OBJDIR)/pivot.o \
384 $(OBJDIR)/popen.o \
385 $(OBJDIR)/pqueue.o \
386 $(OBJDIR)/printf.o \
387 $(OBJDIR)/publish.o \
@@ -474,11 +477,12 @@
477 -DSQLITE_THREADSAFE=0 \
478 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
479 -DSQLITE_OMIT_DEPRECATED \
480 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
481 -DSQLITE_ENABLE_FTS4 \
482 -DSQLITE_ENABLE_FTS3_PARENTHESIS \
483 -DSQLITE_ENABLE_DBSTAT_VTAB
484
485 # Setup the options used to compile the included SQLite shell.
486 SHELL_OPTIONS = -Dmain=sqlite3_shell \
487 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
488 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
@@ -606,10 +610,11 @@
610 $(OBJDIR)/merge_.c:$(OBJDIR)/merge.h \
611 $(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h \
612 $(OBJDIR)/moderate_.c:$(OBJDIR)/moderate.h \
613 $(OBJDIR)/name_.c:$(OBJDIR)/name.h \
614 $(OBJDIR)/path_.c:$(OBJDIR)/path.h \
615 $(OBJDIR)/piechart_.c:$(OBJDIR)/piechart.h \
616 $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
617 $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
618 $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
619 $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
620 $(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
@@ -1234,10 +1239,18 @@
1239
1240 $(OBJDIR)/path.o: $(OBJDIR)/path_.c $(OBJDIR)/path.h $(SRCDIR)/config.h
1241 $(XTCC) -o $(OBJDIR)/path.o -c $(OBJDIR)/path_.c
1242
1243 $(OBJDIR)/path.h: $(OBJDIR)/headers
1244
1245 $(OBJDIR)/piechart_.c: $(SRCDIR)/piechart.c $(OBJDIR)/translate
1246 $(OBJDIR)/translate $(SRCDIR)/piechart.c >$@
1247
1248 $(OBJDIR)/piechart.o: $(OBJDIR)/piechart_.c $(OBJDIR)/piechart.h $(SRCDIR)/config.h
1249 $(XTCC) -o $(OBJDIR)/piechart.o -c $(OBJDIR)/piechart_.c
1250
1251 $(OBJDIR)/piechart.h: $(OBJDIR)/headers
1252
1253 $(OBJDIR)/pivot_.c: $(SRCDIR)/pivot.c $(OBJDIR)/translate
1254 $(OBJDIR)/translate $(SRCDIR)/pivot.c >$@
1255
1256 $(OBJDIR)/pivot.o: $(OBJDIR)/pivot_.c $(OBJDIR)/pivot.h $(SRCDIR)/config.h
1257
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -90,10 +90,11 @@
9090
merge
9191
merge3
9292
moderate
9393
name
9494
path
95
+ piechart
9596
pivot
9697
popen
9798
pqueue
9899
printf
99100
publish
@@ -159,10 +160,11 @@
159160
-DSQLITE_DEFAULT_FILE_FORMAT=4
160161
-DSQLITE_OMIT_DEPRECATED
161162
-DSQLITE_ENABLE_EXPLAIN_COMMENTS
162163
-DSQLITE_ENABLE_FTS4
163164
-DSQLITE_ENABLE_FTS3_PARENTHESIS
165
+ -DSQLITE_ENABLE_DBSTAT_VTAB
164166
}
165167
#lappend SQLITE_OPTIONS -DSQLITE_ENABLE_FTS3=1
166168
#lappend SQLITE_OPTIONS -DSQLITE_ENABLE_STAT4
167169
#lappend SQLITE_OPTIONS -DSQLITE_WIN32_NO_ANSI
168170
#lappend SQLITE_OPTIONS -DSQLITE_WINNT_MAX_PATH_CHARS=4096
169171
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -90,10 +90,11 @@
90 merge
91 merge3
92 moderate
93 name
94 path
 
95 pivot
96 popen
97 pqueue
98 printf
99 publish
@@ -159,10 +160,11 @@
159 -DSQLITE_DEFAULT_FILE_FORMAT=4
160 -DSQLITE_OMIT_DEPRECATED
161 -DSQLITE_ENABLE_EXPLAIN_COMMENTS
162 -DSQLITE_ENABLE_FTS4
163 -DSQLITE_ENABLE_FTS3_PARENTHESIS
 
164 }
165 #lappend SQLITE_OPTIONS -DSQLITE_ENABLE_FTS3=1
166 #lappend SQLITE_OPTIONS -DSQLITE_ENABLE_STAT4
167 #lappend SQLITE_OPTIONS -DSQLITE_WIN32_NO_ANSI
168 #lappend SQLITE_OPTIONS -DSQLITE_WINNT_MAX_PATH_CHARS=4096
169
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -90,10 +90,11 @@
90 merge
91 merge3
92 moderate
93 name
94 path
95 piechart
96 pivot
97 popen
98 pqueue
99 printf
100 publish
@@ -159,10 +160,11 @@
160 -DSQLITE_DEFAULT_FILE_FORMAT=4
161 -DSQLITE_OMIT_DEPRECATED
162 -DSQLITE_ENABLE_EXPLAIN_COMMENTS
163 -DSQLITE_ENABLE_FTS4
164 -DSQLITE_ENABLE_FTS3_PARENTHESIS
165 -DSQLITE_ENABLE_DBSTAT_VTAB
166 }
167 #lappend SQLITE_OPTIONS -DSQLITE_ENABLE_FTS3=1
168 #lappend SQLITE_OPTIONS -DSQLITE_ENABLE_STAT4
169 #lappend SQLITE_OPTIONS -DSQLITE_WIN32_NO_ANSI
170 #lappend SQLITE_OPTIONS -DSQLITE_WINNT_MAX_PATH_CHARS=4096
171
+3 -3
--- src/manifest.c
+++ src/manifest.c
@@ -1344,10 +1344,11 @@
13441344
** A single mlink entry is added for every file that changed content,
13451345
** name, and/or permissions going from pid to cid.
13461346
**
13471347
** Deleted files have mlink.fid=0.
13481348
** Added files have mlink.pid=0.
1349
+** File added by merge have mlink.pid=-1
13491350
** Edited files have both mlink.pid!=0 and mlink.fid!=0
13501351
*/
13511352
static void add_mlink(
13521353
int pmid, Manifest *pParent, /* Parent check-in */
13531354
int mid, Manifest *pChild, /* The child check-in */
@@ -1801,14 +1802,13 @@
18011802
pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
18021803
add_mlink(pid, 0, rid, p, i==0);
18031804
if( i==0 ) parentid = pid;
18041805
}
18051806
if( p->nParent>1 ){
1806
- /* Remove incorrect MLINK create-file entries that arise when a
1807
- ** file is added by merge. */
1807
+ /* Change MLINK.PID from 0 to -1 for files that are added by merge. */
18081808
db_multi_exec(
1809
- "DELETE FROM mlink"
1809
+ "UPDATE mlink SET pid=-1"
18101810
" WHERE mid=%d"
18111811
" AND pid=0"
18121812
" AND fnid IN "
18131813
" (SELECT fnid FROM mlink WHERE mid=%d GROUP BY fnid"
18141814
" HAVING count(*)<%d)",
18151815
--- src/manifest.c
+++ src/manifest.c
@@ -1344,10 +1344,11 @@
1344 ** A single mlink entry is added for every file that changed content,
1345 ** name, and/or permissions going from pid to cid.
1346 **
1347 ** Deleted files have mlink.fid=0.
1348 ** Added files have mlink.pid=0.
 
1349 ** Edited files have both mlink.pid!=0 and mlink.fid!=0
1350 */
1351 static void add_mlink(
1352 int pmid, Manifest *pParent, /* Parent check-in */
1353 int mid, Manifest *pChild, /* The child check-in */
@@ -1801,14 +1802,13 @@
1801 pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
1802 add_mlink(pid, 0, rid, p, i==0);
1803 if( i==0 ) parentid = pid;
1804 }
1805 if( p->nParent>1 ){
1806 /* Remove incorrect MLINK create-file entries that arise when a
1807 ** file is added by merge. */
1808 db_multi_exec(
1809 "DELETE FROM mlink"
1810 " WHERE mid=%d"
1811 " AND pid=0"
1812 " AND fnid IN "
1813 " (SELECT fnid FROM mlink WHERE mid=%d GROUP BY fnid"
1814 " HAVING count(*)<%d)",
1815
--- src/manifest.c
+++ src/manifest.c
@@ -1344,10 +1344,11 @@
1344 ** A single mlink entry is added for every file that changed content,
1345 ** name, and/or permissions going from pid to cid.
1346 **
1347 ** Deleted files have mlink.fid=0.
1348 ** Added files have mlink.pid=0.
1349 ** File added by merge have mlink.pid=-1
1350 ** Edited files have both mlink.pid!=0 and mlink.fid!=0
1351 */
1352 static void add_mlink(
1353 int pmid, Manifest *pParent, /* Parent check-in */
1354 int mid, Manifest *pChild, /* The child check-in */
@@ -1801,14 +1802,13 @@
1802 pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
1803 add_mlink(pid, 0, rid, p, i==0);
1804 if( i==0 ) parentid = pid;
1805 }
1806 if( p->nParent>1 ){
1807 /* Change MLINK.PID from 0 to -1 for files that are added by merge. */
 
1808 db_multi_exec(
1809 "UPDATE mlink SET pid=-1"
1810 " WHERE mid=%d"
1811 " AND pid=0"
1812 " AND fnid IN "
1813 " (SELECT fnid FROM mlink WHERE mid=%d GROUP BY fnid"
1814 " HAVING count(*)<%d)",
1815
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -34,16 +34,16 @@
3434
3535
/* INTER_BLOCK -- skip a line between block level elements */
3636
#define INTER_BLOCK(ob) \
3737
do { if( blob_size(ob)>0 ) blob_append(ob, "\n", 1); } while (0)
3838
39
-/* BLOB_APPEND_LITTERAL -- append a string litteral to a blob */
40
-#define BLOB_APPEND_LITTERAL(blob, litteral) \
41
- blob_append((blob), "" litteral, (sizeof litteral)-1)
39
+/* BLOB_APPEND_LITERAL -- append a string literal to a blob */
40
+#define BLOB_APPEND_LITERAL(blob, literal) \
41
+ blob_append((blob), "" literal, (sizeof literal)-1)
4242
/*
4343
* The empty string in the second argument leads to a syntax error
44
- * when the macro is not used with a string litteral. Unfortunately
44
+ * when the macro is not used with a string literal. Unfortunately
4545
* the error is not overly explicit.
4646
*/
4747
4848
/* BLOB_APPEND_BLOB -- append blob contents to another */
4949
#define BLOB_APPEND_BLOB(dest, src) \
@@ -65,17 +65,17 @@
6565
i++;
6666
}
6767
blob_append(ob, data+beg, i-beg);
6868
while( i<size ){
6969
if( data[i]=='<' ){
70
- BLOB_APPEND_LITTERAL(ob, "&lt;");
70
+ BLOB_APPEND_LITERAL(ob, "&lt;");
7171
}else if( data[i]=='>' ){
72
- BLOB_APPEND_LITTERAL(ob, "&gt;");
72
+ BLOB_APPEND_LITERAL(ob, "&gt;");
7373
}else if( data[i]=='&' ){
74
- BLOB_APPEND_LITTERAL(ob, "&amp;");
74
+ BLOB_APPEND_LITERAL(ob, "&amp;");
7575
}else if( data[i]=='"' ){
76
- BLOB_APPEND_LITTERAL(ob, "&quot;");
76
+ BLOB_APPEND_LITERAL(ob, "&quot;");
7777
}else{
7878
break;
7979
}
8080
i++;
8181
}
@@ -88,41 +88,41 @@
8888
/* Size of the prolog: "<div class='markdown'>\n" */
8989
#define PROLOG_SIZE 23
9090
9191
static void html_prolog(struct Blob *ob, void *opaque){
9292
INTER_BLOCK(ob);
93
- BLOB_APPEND_LITTERAL(ob, "<div class=\"markdown\">\n");
93
+ BLOB_APPEND_LITERAL(ob, "<div class=\"markdown\">\n");
9494
assert( blob_size(ob)==PROLOG_SIZE );
9595
}
9696
9797
static void html_epilog(struct Blob *ob, void *opaque){
9898
INTER_BLOCK(ob);
99
- BLOB_APPEND_LITTERAL(ob, "</div>\n");
99
+ BLOB_APPEND_LITERAL(ob, "</div>\n");
100100
}
101101
102102
static void html_raw_block(struct Blob *ob, struct Blob *text, void *opaque){
103103
char *data = blob_buffer(text);
104104
size_t first = 0, size = blob_size(text);
105105
INTER_BLOCK(ob);
106106
while( first<size && data[first]=='\n' ) first++;
107107
while( size>first && data[size-1]=='\n' ) size--;
108108
blob_append(ob, data+first, size-first);
109
- BLOB_APPEND_LITTERAL(ob, "\n");
109
+ BLOB_APPEND_LITERAL(ob, "\n");
110110
}
111111
112112
static void html_blockcode(struct Blob *ob, struct Blob *text, void *opaque){
113113
INTER_BLOCK(ob);
114
- BLOB_APPEND_LITTERAL(ob, "<pre><code>");
114
+ BLOB_APPEND_LITERAL(ob, "<pre><code>");
115115
html_escape(ob, blob_buffer(text), blob_size(text));
116
- BLOB_APPEND_LITTERAL(ob, "</code></pre>\n");
116
+ BLOB_APPEND_LITERAL(ob, "</code></pre>\n");
117117
}
118118
119119
static void html_blockquote(struct Blob *ob, struct Blob *text, void *opaque){
120120
INTER_BLOCK(ob);
121
- BLOB_APPEND_LITTERAL(ob, "<blockquote>\n");
121
+ BLOB_APPEND_LITERAL(ob, "<blockquote>\n");
122122
BLOB_APPEND_BLOB(ob, text);
123
- BLOB_APPEND_LITTERAL(ob, "</blockquote>\n");
123
+ BLOB_APPEND_LITERAL(ob, "</blockquote>\n");
124124
}
125125
126126
static void html_header(
127127
struct Blob *ob,
128128
struct Blob *text,
@@ -141,11 +141,11 @@
141141
blob_appendf(ob, "</h%d>", level);
142142
}
143143
144144
static void html_hrule(struct Blob *ob, void *opaque){
145145
INTER_BLOCK(ob);
146
- BLOB_APPEND_LITTERAL(ob, "<hr />\n");
146
+ BLOB_APPEND_LITERAL(ob, "<hr />\n");
147147
}
148148
149149
150150
static void html_list(
151151
struct Blob *ob,
@@ -169,20 +169,20 @@
169169
void *opaque
170170
){
171171
char *text_data = blob_buffer(text);
172172
size_t text_size = blob_size(text);
173173
while( text_size>0 && text_data[text_size-1]=='\n' ) text_size--;
174
- BLOB_APPEND_LITTERAL(ob, "<li>");
174
+ BLOB_APPEND_LITERAL(ob, "<li>");
175175
blob_append(ob, text_data, text_size);
176
- BLOB_APPEND_LITTERAL(ob, "</li>\n");
176
+ BLOB_APPEND_LITERAL(ob, "</li>\n");
177177
}
178178
179179
static void html_paragraph(struct Blob *ob, struct Blob *text, void *opaque){
180180
INTER_BLOCK(ob);
181
- BLOB_APPEND_LITTERAL(ob, "<p>");
181
+ BLOB_APPEND_LITERAL(ob, "<p>");
182182
BLOB_APPEND_BLOB(ob, text);
183
- BLOB_APPEND_LITTERAL(ob, "</p>\n");
183
+ BLOB_APPEND_LITERAL(ob, "</p>\n");
184184
}
185185
186186
187187
static void html_table(
188188
struct Blob *ob,
@@ -189,68 +189,68 @@
189189
struct Blob *head_row,
190190
struct Blob *rows,
191191
void *opaque
192192
){
193193
INTER_BLOCK(ob);
194
- BLOB_APPEND_LITTERAL(ob, "<table>\n");
194
+ BLOB_APPEND_LITERAL(ob, "<table>\n");
195195
if( head_row && blob_size(head_row)>0 ){
196
- BLOB_APPEND_LITTERAL(ob, "<thead>\n");
196
+ BLOB_APPEND_LITERAL(ob, "<thead>\n");
197197
BLOB_APPEND_BLOB(ob, head_row);
198
- BLOB_APPEND_LITTERAL(ob, "</thead>\n<tbody>\n");
198
+ BLOB_APPEND_LITERAL(ob, "</thead>\n<tbody>\n");
199199
}
200200
if( rows ){
201201
BLOB_APPEND_BLOB(ob, rows);
202202
}
203203
if( head_row && blob_size(head_row)>0 ){
204
- BLOB_APPEND_LITTERAL(ob, "</tbody>\n");
204
+ BLOB_APPEND_LITERAL(ob, "</tbody>\n");
205205
}
206
- BLOB_APPEND_LITTERAL(ob, "</table>\n");
206
+ BLOB_APPEND_LITERAL(ob, "</table>\n");
207207
}
208208
209209
static void html_table_cell(
210210
struct Blob *ob,
211211
struct Blob *text,
212212
int flags,
213213
void *opaque
214214
){
215215
if( flags & MKD_CELL_HEAD ){
216
- BLOB_APPEND_LITTERAL(ob, " <th");
216
+ BLOB_APPEND_LITERAL(ob, " <th");
217217
}else{
218
- BLOB_APPEND_LITTERAL(ob, " <td");
218
+ BLOB_APPEND_LITERAL(ob, " <td");
219219
}
220220
switch( flags & MKD_CELL_ALIGN_MASK ){
221221
case MKD_CELL_ALIGN_LEFT: {
222
- BLOB_APPEND_LITTERAL(ob, " align=\"left\"");
222
+ BLOB_APPEND_LITERAL(ob, " align=\"left\"");
223223
break;
224224
}
225225
case MKD_CELL_ALIGN_RIGHT: {
226
- BLOB_APPEND_LITTERAL(ob, " align=\"right\"");
226
+ BLOB_APPEND_LITERAL(ob, " align=\"right\"");
227227
break;
228228
}
229229
case MKD_CELL_ALIGN_CENTER: {
230
- BLOB_APPEND_LITTERAL(ob, " align=\"center\"");
230
+ BLOB_APPEND_LITERAL(ob, " align=\"center\"");
231231
break;
232232
}
233233
}
234
- BLOB_APPEND_LITTERAL(ob, ">");
234
+ BLOB_APPEND_LITERAL(ob, ">");
235235
BLOB_APPEND_BLOB(ob, text);
236236
if( flags & MKD_CELL_HEAD ){
237
- BLOB_APPEND_LITTERAL(ob, "</th>\n");
237
+ BLOB_APPEND_LITERAL(ob, "</th>\n");
238238
}else{
239
- BLOB_APPEND_LITTERAL(ob, "</td>\n");
239
+ BLOB_APPEND_LITERAL(ob, "</td>\n");
240240
}
241241
}
242242
243243
static void html_table_row(
244244
struct Blob *ob,
245245
struct Blob *cells,
246246
int flags,
247247
void *opaque
248248
){
249
- BLOB_APPEND_LITTERAL(ob, " <tr>\n");
249
+ BLOB_APPEND_LITERAL(ob, " <tr>\n");
250250
BLOB_APPEND_BLOB(ob, cells);
251
- BLOB_APPEND_LITTERAL(ob, " </tr>\n");
251
+ BLOB_APPEND_LITERAL(ob, " </tr>\n");
252252
}
253253
254254
255255
256256
/* HTML span tags */
@@ -265,52 +265,52 @@
265265
struct Blob *link,
266266
enum mkd_autolink type,
267267
void *opaque
268268
){
269269
if( !link || blob_size(link)<=0 ) return 0;
270
- BLOB_APPEND_LITTERAL(ob, "<a href=\"");
271
- if( type==MKDA_IMPLICIT_EMAIL ) BLOB_APPEND_LITTERAL(ob, "mailto:");
270
+ BLOB_APPEND_LITERAL(ob, "<a href=\"");
271
+ if( type==MKDA_IMPLICIT_EMAIL ) BLOB_APPEND_LITERAL(ob, "mailto:");
272272
html_escape(ob, blob_buffer(link), blob_size(link));
273
- BLOB_APPEND_LITTERAL(ob, "\">");
273
+ BLOB_APPEND_LITERAL(ob, "\">");
274274
if( type==MKDA_EXPLICIT_EMAIL && blob_size(link)>7 ){
275275
/* remove "mailto:" from displayed text */
276276
html_escape(ob, blob_buffer(link)+7, blob_size(link)-7);
277277
}else{
278278
html_escape(ob, blob_buffer(link), blob_size(link));
279279
}
280
- BLOB_APPEND_LITTERAL(ob, "</a>");
280
+ BLOB_APPEND_LITERAL(ob, "</a>");
281281
return 1;
282282
}
283283
284284
static int html_code_span(struct Blob *ob, struct Blob *text, void *opaque){
285
- BLOB_APPEND_LITTERAL(ob, "<code>");
285
+ BLOB_APPEND_LITERAL(ob, "<code>");
286286
html_escape(ob, blob_buffer(text), blob_size(text));
287
- BLOB_APPEND_LITTERAL(ob, "</code>");
287
+ BLOB_APPEND_LITERAL(ob, "</code>");
288288
return 1;
289289
}
290290
291291
static int html_double_emphasis(
292292
struct Blob *ob,
293293
struct Blob *text,
294294
char c,
295295
void *opaque
296296
){
297
- BLOB_APPEND_LITTERAL(ob, "<strong>");
297
+ BLOB_APPEND_LITERAL(ob, "<strong>");
298298
BLOB_APPEND_BLOB(ob, text);
299
- BLOB_APPEND_LITTERAL(ob, "</strong>");
299
+ BLOB_APPEND_LITERAL(ob, "</strong>");
300300
return 1;
301301
}
302302
303303
static int html_emphasis(
304304
struct Blob *ob,
305305
struct Blob *text,
306306
char c,
307307
void *opaque
308308
){
309
- BLOB_APPEND_LITTERAL(ob, "<em>");
309
+ BLOB_APPEND_LITERAL(ob, "<em>");
310310
BLOB_APPEND_BLOB(ob, text);
311
- BLOB_APPEND_LITTERAL(ob, "</em>");
311
+ BLOB_APPEND_LITERAL(ob, "</em>");
312312
return 1;
313313
}
314314
315315
static int html_image(
316316
struct Blob *ob,
@@ -317,24 +317,24 @@
317317
struct Blob *link,
318318
struct Blob *title,
319319
struct Blob *alt,
320320
void *opaque
321321
){
322
- BLOB_APPEND_LITTERAL(ob, "<img src=\"");
322
+ BLOB_APPEND_LITERAL(ob, "<img src=\"");
323323
html_escape(ob, blob_buffer(link), blob_size(link));
324
- BLOB_APPEND_LITTERAL(ob, "\" alt=\"");
324
+ BLOB_APPEND_LITERAL(ob, "\" alt=\"");
325325
html_escape(ob, blob_buffer(alt), blob_size(alt));
326326
if( title && blob_size(title)>0 ){
327
- BLOB_APPEND_LITTERAL(ob, "\" title=\"");
327
+ BLOB_APPEND_LITERAL(ob, "\" title=\"");
328328
html_escape(ob, blob_buffer(title), blob_size(title));
329329
}
330
- BLOB_APPEND_LITTERAL(ob, "\" />");
330
+ BLOB_APPEND_LITERAL(ob, "\" />");
331331
return 1;
332332
}
333333
334334
static int html_line_break(struct Blob *ob, void *opaque){
335
- BLOB_APPEND_LITTERAL(ob, "<br />\n");
335
+ BLOB_APPEND_LITERAL(ob, "<br />\n");
336336
return 1;
337337
}
338338
339339
static int html_link(
340340
struct Blob *ob,
@@ -341,31 +341,31 @@
341341
struct Blob *link,
342342
struct Blob *title,
343343
struct Blob *content,
344344
void *opaque
345345
){
346
- BLOB_APPEND_LITTERAL(ob, "<a href=\"");
346
+ BLOB_APPEND_LITERAL(ob, "<a href=\"");
347347
html_escape(ob, blob_buffer(link), blob_size(link));
348348
if( title && blob_size(title)>0 ){
349
- BLOB_APPEND_LITTERAL(ob, "\" title=\"");
349
+ BLOB_APPEND_LITERAL(ob, "\" title=\"");
350350
html_escape(ob, blob_buffer(title), blob_size(title));
351351
}
352
- BLOB_APPEND_LITTERAL(ob, "\">");
352
+ BLOB_APPEND_LITERAL(ob, "\">");
353353
BLOB_APPEND_BLOB(ob, content);
354
- BLOB_APPEND_LITTERAL(ob, "</a>");
354
+ BLOB_APPEND_LITERAL(ob, "</a>");
355355
return 1;
356356
}
357357
358358
static int html_triple_emphasis(
359359
struct Blob *ob,
360360
struct Blob *text,
361361
char c,
362362
void *opaque
363363
){
364
- BLOB_APPEND_LITTERAL(ob, "<strong><em>");
364
+ BLOB_APPEND_LITERAL(ob, "<strong><em>");
365365
BLOB_APPEND_BLOB(ob, text);
366
- BLOB_APPEND_LITTERAL(ob, "</em></strong>");
366
+ BLOB_APPEND_LITERAL(ob, "</em></strong>");
367367
return 1;
368368
}
369369
370370
371371
static void html_normal_text(struct Blob *ob, struct Blob *text, void *opaque){
372372
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -34,16 +34,16 @@
34
35 /* INTER_BLOCK -- skip a line between block level elements */
36 #define INTER_BLOCK(ob) \
37 do { if( blob_size(ob)>0 ) blob_append(ob, "\n", 1); } while (0)
38
39 /* BLOB_APPEND_LITTERAL -- append a string litteral to a blob */
40 #define BLOB_APPEND_LITTERAL(blob, litteral) \
41 blob_append((blob), "" litteral, (sizeof litteral)-1)
42 /*
43 * The empty string in the second argument leads to a syntax error
44 * when the macro is not used with a string litteral. Unfortunately
45 * the error is not overly explicit.
46 */
47
48 /* BLOB_APPEND_BLOB -- append blob contents to another */
49 #define BLOB_APPEND_BLOB(dest, src) \
@@ -65,17 +65,17 @@
65 i++;
66 }
67 blob_append(ob, data+beg, i-beg);
68 while( i<size ){
69 if( data[i]=='<' ){
70 BLOB_APPEND_LITTERAL(ob, "&lt;");
71 }else if( data[i]=='>' ){
72 BLOB_APPEND_LITTERAL(ob, "&gt;");
73 }else if( data[i]=='&' ){
74 BLOB_APPEND_LITTERAL(ob, "&amp;");
75 }else if( data[i]=='"' ){
76 BLOB_APPEND_LITTERAL(ob, "&quot;");
77 }else{
78 break;
79 }
80 i++;
81 }
@@ -88,41 +88,41 @@
88 /* Size of the prolog: "<div class='markdown'>\n" */
89 #define PROLOG_SIZE 23
90
91 static void html_prolog(struct Blob *ob, void *opaque){
92 INTER_BLOCK(ob);
93 BLOB_APPEND_LITTERAL(ob, "<div class=\"markdown\">\n");
94 assert( blob_size(ob)==PROLOG_SIZE );
95 }
96
97 static void html_epilog(struct Blob *ob, void *opaque){
98 INTER_BLOCK(ob);
99 BLOB_APPEND_LITTERAL(ob, "</div>\n");
100 }
101
102 static void html_raw_block(struct Blob *ob, struct Blob *text, void *opaque){
103 char *data = blob_buffer(text);
104 size_t first = 0, size = blob_size(text);
105 INTER_BLOCK(ob);
106 while( first<size && data[first]=='\n' ) first++;
107 while( size>first && data[size-1]=='\n' ) size--;
108 blob_append(ob, data+first, size-first);
109 BLOB_APPEND_LITTERAL(ob, "\n");
110 }
111
112 static void html_blockcode(struct Blob *ob, struct Blob *text, void *opaque){
113 INTER_BLOCK(ob);
114 BLOB_APPEND_LITTERAL(ob, "<pre><code>");
115 html_escape(ob, blob_buffer(text), blob_size(text));
116 BLOB_APPEND_LITTERAL(ob, "</code></pre>\n");
117 }
118
119 static void html_blockquote(struct Blob *ob, struct Blob *text, void *opaque){
120 INTER_BLOCK(ob);
121 BLOB_APPEND_LITTERAL(ob, "<blockquote>\n");
122 BLOB_APPEND_BLOB(ob, text);
123 BLOB_APPEND_LITTERAL(ob, "</blockquote>\n");
124 }
125
126 static void html_header(
127 struct Blob *ob,
128 struct Blob *text,
@@ -141,11 +141,11 @@
141 blob_appendf(ob, "</h%d>", level);
142 }
143
144 static void html_hrule(struct Blob *ob, void *opaque){
145 INTER_BLOCK(ob);
146 BLOB_APPEND_LITTERAL(ob, "<hr />\n");
147 }
148
149
150 static void html_list(
151 struct Blob *ob,
@@ -169,20 +169,20 @@
169 void *opaque
170 ){
171 char *text_data = blob_buffer(text);
172 size_t text_size = blob_size(text);
173 while( text_size>0 && text_data[text_size-1]=='\n' ) text_size--;
174 BLOB_APPEND_LITTERAL(ob, "<li>");
175 blob_append(ob, text_data, text_size);
176 BLOB_APPEND_LITTERAL(ob, "</li>\n");
177 }
178
179 static void html_paragraph(struct Blob *ob, struct Blob *text, void *opaque){
180 INTER_BLOCK(ob);
181 BLOB_APPEND_LITTERAL(ob, "<p>");
182 BLOB_APPEND_BLOB(ob, text);
183 BLOB_APPEND_LITTERAL(ob, "</p>\n");
184 }
185
186
187 static void html_table(
188 struct Blob *ob,
@@ -189,68 +189,68 @@
189 struct Blob *head_row,
190 struct Blob *rows,
191 void *opaque
192 ){
193 INTER_BLOCK(ob);
194 BLOB_APPEND_LITTERAL(ob, "<table>\n");
195 if( head_row && blob_size(head_row)>0 ){
196 BLOB_APPEND_LITTERAL(ob, "<thead>\n");
197 BLOB_APPEND_BLOB(ob, head_row);
198 BLOB_APPEND_LITTERAL(ob, "</thead>\n<tbody>\n");
199 }
200 if( rows ){
201 BLOB_APPEND_BLOB(ob, rows);
202 }
203 if( head_row && blob_size(head_row)>0 ){
204 BLOB_APPEND_LITTERAL(ob, "</tbody>\n");
205 }
206 BLOB_APPEND_LITTERAL(ob, "</table>\n");
207 }
208
209 static void html_table_cell(
210 struct Blob *ob,
211 struct Blob *text,
212 int flags,
213 void *opaque
214 ){
215 if( flags & MKD_CELL_HEAD ){
216 BLOB_APPEND_LITTERAL(ob, " <th");
217 }else{
218 BLOB_APPEND_LITTERAL(ob, " <td");
219 }
220 switch( flags & MKD_CELL_ALIGN_MASK ){
221 case MKD_CELL_ALIGN_LEFT: {
222 BLOB_APPEND_LITTERAL(ob, " align=\"left\"");
223 break;
224 }
225 case MKD_CELL_ALIGN_RIGHT: {
226 BLOB_APPEND_LITTERAL(ob, " align=\"right\"");
227 break;
228 }
229 case MKD_CELL_ALIGN_CENTER: {
230 BLOB_APPEND_LITTERAL(ob, " align=\"center\"");
231 break;
232 }
233 }
234 BLOB_APPEND_LITTERAL(ob, ">");
235 BLOB_APPEND_BLOB(ob, text);
236 if( flags & MKD_CELL_HEAD ){
237 BLOB_APPEND_LITTERAL(ob, "</th>\n");
238 }else{
239 BLOB_APPEND_LITTERAL(ob, "</td>\n");
240 }
241 }
242
243 static void html_table_row(
244 struct Blob *ob,
245 struct Blob *cells,
246 int flags,
247 void *opaque
248 ){
249 BLOB_APPEND_LITTERAL(ob, " <tr>\n");
250 BLOB_APPEND_BLOB(ob, cells);
251 BLOB_APPEND_LITTERAL(ob, " </tr>\n");
252 }
253
254
255
256 /* HTML span tags */
@@ -265,52 +265,52 @@
265 struct Blob *link,
266 enum mkd_autolink type,
267 void *opaque
268 ){
269 if( !link || blob_size(link)<=0 ) return 0;
270 BLOB_APPEND_LITTERAL(ob, "<a href=\"");
271 if( type==MKDA_IMPLICIT_EMAIL ) BLOB_APPEND_LITTERAL(ob, "mailto:");
272 html_escape(ob, blob_buffer(link), blob_size(link));
273 BLOB_APPEND_LITTERAL(ob, "\">");
274 if( type==MKDA_EXPLICIT_EMAIL && blob_size(link)>7 ){
275 /* remove "mailto:" from displayed text */
276 html_escape(ob, blob_buffer(link)+7, blob_size(link)-7);
277 }else{
278 html_escape(ob, blob_buffer(link), blob_size(link));
279 }
280 BLOB_APPEND_LITTERAL(ob, "</a>");
281 return 1;
282 }
283
284 static int html_code_span(struct Blob *ob, struct Blob *text, void *opaque){
285 BLOB_APPEND_LITTERAL(ob, "<code>");
286 html_escape(ob, blob_buffer(text), blob_size(text));
287 BLOB_APPEND_LITTERAL(ob, "</code>");
288 return 1;
289 }
290
291 static int html_double_emphasis(
292 struct Blob *ob,
293 struct Blob *text,
294 char c,
295 void *opaque
296 ){
297 BLOB_APPEND_LITTERAL(ob, "<strong>");
298 BLOB_APPEND_BLOB(ob, text);
299 BLOB_APPEND_LITTERAL(ob, "</strong>");
300 return 1;
301 }
302
303 static int html_emphasis(
304 struct Blob *ob,
305 struct Blob *text,
306 char c,
307 void *opaque
308 ){
309 BLOB_APPEND_LITTERAL(ob, "<em>");
310 BLOB_APPEND_BLOB(ob, text);
311 BLOB_APPEND_LITTERAL(ob, "</em>");
312 return 1;
313 }
314
315 static int html_image(
316 struct Blob *ob,
@@ -317,24 +317,24 @@
317 struct Blob *link,
318 struct Blob *title,
319 struct Blob *alt,
320 void *opaque
321 ){
322 BLOB_APPEND_LITTERAL(ob, "<img src=\"");
323 html_escape(ob, blob_buffer(link), blob_size(link));
324 BLOB_APPEND_LITTERAL(ob, "\" alt=\"");
325 html_escape(ob, blob_buffer(alt), blob_size(alt));
326 if( title && blob_size(title)>0 ){
327 BLOB_APPEND_LITTERAL(ob, "\" title=\"");
328 html_escape(ob, blob_buffer(title), blob_size(title));
329 }
330 BLOB_APPEND_LITTERAL(ob, "\" />");
331 return 1;
332 }
333
334 static int html_line_break(struct Blob *ob, void *opaque){
335 BLOB_APPEND_LITTERAL(ob, "<br />\n");
336 return 1;
337 }
338
339 static int html_link(
340 struct Blob *ob,
@@ -341,31 +341,31 @@
341 struct Blob *link,
342 struct Blob *title,
343 struct Blob *content,
344 void *opaque
345 ){
346 BLOB_APPEND_LITTERAL(ob, "<a href=\"");
347 html_escape(ob, blob_buffer(link), blob_size(link));
348 if( title && blob_size(title)>0 ){
349 BLOB_APPEND_LITTERAL(ob, "\" title=\"");
350 html_escape(ob, blob_buffer(title), blob_size(title));
351 }
352 BLOB_APPEND_LITTERAL(ob, "\">");
353 BLOB_APPEND_BLOB(ob, content);
354 BLOB_APPEND_LITTERAL(ob, "</a>");
355 return 1;
356 }
357
358 static int html_triple_emphasis(
359 struct Blob *ob,
360 struct Blob *text,
361 char c,
362 void *opaque
363 ){
364 BLOB_APPEND_LITTERAL(ob, "<strong><em>");
365 BLOB_APPEND_BLOB(ob, text);
366 BLOB_APPEND_LITTERAL(ob, "</em></strong>");
367 return 1;
368 }
369
370
371 static void html_normal_text(struct Blob *ob, struct Blob *text, void *opaque){
372
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -34,16 +34,16 @@
34
35 /* INTER_BLOCK -- skip a line between block level elements */
36 #define INTER_BLOCK(ob) \
37 do { if( blob_size(ob)>0 ) blob_append(ob, "\n", 1); } while (0)
38
39 /* BLOB_APPEND_LITERAL -- append a string literal to a blob */
40 #define BLOB_APPEND_LITERAL(blob, literal) \
41 blob_append((blob), "" literal, (sizeof literal)-1)
42 /*
43 * The empty string in the second argument leads to a syntax error
44 * when the macro is not used with a string literal. Unfortunately
45 * the error is not overly explicit.
46 */
47
48 /* BLOB_APPEND_BLOB -- append blob contents to another */
49 #define BLOB_APPEND_BLOB(dest, src) \
@@ -65,17 +65,17 @@
65 i++;
66 }
67 blob_append(ob, data+beg, i-beg);
68 while( i<size ){
69 if( data[i]=='<' ){
70 BLOB_APPEND_LITERAL(ob, "&lt;");
71 }else if( data[i]=='>' ){
72 BLOB_APPEND_LITERAL(ob, "&gt;");
73 }else if( data[i]=='&' ){
74 BLOB_APPEND_LITERAL(ob, "&amp;");
75 }else if( data[i]=='"' ){
76 BLOB_APPEND_LITERAL(ob, "&quot;");
77 }else{
78 break;
79 }
80 i++;
81 }
@@ -88,41 +88,41 @@
88 /* Size of the prolog: "<div class='markdown'>\n" */
89 #define PROLOG_SIZE 23
90
91 static void html_prolog(struct Blob *ob, void *opaque){
92 INTER_BLOCK(ob);
93 BLOB_APPEND_LITERAL(ob, "<div class=\"markdown\">\n");
94 assert( blob_size(ob)==PROLOG_SIZE );
95 }
96
97 static void html_epilog(struct Blob *ob, void *opaque){
98 INTER_BLOCK(ob);
99 BLOB_APPEND_LITERAL(ob, "</div>\n");
100 }
101
102 static void html_raw_block(struct Blob *ob, struct Blob *text, void *opaque){
103 char *data = blob_buffer(text);
104 size_t first = 0, size = blob_size(text);
105 INTER_BLOCK(ob);
106 while( first<size && data[first]=='\n' ) first++;
107 while( size>first && data[size-1]=='\n' ) size--;
108 blob_append(ob, data+first, size-first);
109 BLOB_APPEND_LITERAL(ob, "\n");
110 }
111
112 static void html_blockcode(struct Blob *ob, struct Blob *text, void *opaque){
113 INTER_BLOCK(ob);
114 BLOB_APPEND_LITERAL(ob, "<pre><code>");
115 html_escape(ob, blob_buffer(text), blob_size(text));
116 BLOB_APPEND_LITERAL(ob, "</code></pre>\n");
117 }
118
119 static void html_blockquote(struct Blob *ob, struct Blob *text, void *opaque){
120 INTER_BLOCK(ob);
121 BLOB_APPEND_LITERAL(ob, "<blockquote>\n");
122 BLOB_APPEND_BLOB(ob, text);
123 BLOB_APPEND_LITERAL(ob, "</blockquote>\n");
124 }
125
126 static void html_header(
127 struct Blob *ob,
128 struct Blob *text,
@@ -141,11 +141,11 @@
141 blob_appendf(ob, "</h%d>", level);
142 }
143
144 static void html_hrule(struct Blob *ob, void *opaque){
145 INTER_BLOCK(ob);
146 BLOB_APPEND_LITERAL(ob, "<hr />\n");
147 }
148
149
150 static void html_list(
151 struct Blob *ob,
@@ -169,20 +169,20 @@
169 void *opaque
170 ){
171 char *text_data = blob_buffer(text);
172 size_t text_size = blob_size(text);
173 while( text_size>0 && text_data[text_size-1]=='\n' ) text_size--;
174 BLOB_APPEND_LITERAL(ob, "<li>");
175 blob_append(ob, text_data, text_size);
176 BLOB_APPEND_LITERAL(ob, "</li>\n");
177 }
178
179 static void html_paragraph(struct Blob *ob, struct Blob *text, void *opaque){
180 INTER_BLOCK(ob);
181 BLOB_APPEND_LITERAL(ob, "<p>");
182 BLOB_APPEND_BLOB(ob, text);
183 BLOB_APPEND_LITERAL(ob, "</p>\n");
184 }
185
186
187 static void html_table(
188 struct Blob *ob,
@@ -189,68 +189,68 @@
189 struct Blob *head_row,
190 struct Blob *rows,
191 void *opaque
192 ){
193 INTER_BLOCK(ob);
194 BLOB_APPEND_LITERAL(ob, "<table>\n");
195 if( head_row && blob_size(head_row)>0 ){
196 BLOB_APPEND_LITERAL(ob, "<thead>\n");
197 BLOB_APPEND_BLOB(ob, head_row);
198 BLOB_APPEND_LITERAL(ob, "</thead>\n<tbody>\n");
199 }
200 if( rows ){
201 BLOB_APPEND_BLOB(ob, rows);
202 }
203 if( head_row && blob_size(head_row)>0 ){
204 BLOB_APPEND_LITERAL(ob, "</tbody>\n");
205 }
206 BLOB_APPEND_LITERAL(ob, "</table>\n");
207 }
208
209 static void html_table_cell(
210 struct Blob *ob,
211 struct Blob *text,
212 int flags,
213 void *opaque
214 ){
215 if( flags & MKD_CELL_HEAD ){
216 BLOB_APPEND_LITERAL(ob, " <th");
217 }else{
218 BLOB_APPEND_LITERAL(ob, " <td");
219 }
220 switch( flags & MKD_CELL_ALIGN_MASK ){
221 case MKD_CELL_ALIGN_LEFT: {
222 BLOB_APPEND_LITERAL(ob, " align=\"left\"");
223 break;
224 }
225 case MKD_CELL_ALIGN_RIGHT: {
226 BLOB_APPEND_LITERAL(ob, " align=\"right\"");
227 break;
228 }
229 case MKD_CELL_ALIGN_CENTER: {
230 BLOB_APPEND_LITERAL(ob, " align=\"center\"");
231 break;
232 }
233 }
234 BLOB_APPEND_LITERAL(ob, ">");
235 BLOB_APPEND_BLOB(ob, text);
236 if( flags & MKD_CELL_HEAD ){
237 BLOB_APPEND_LITERAL(ob, "</th>\n");
238 }else{
239 BLOB_APPEND_LITERAL(ob, "</td>\n");
240 }
241 }
242
243 static void html_table_row(
244 struct Blob *ob,
245 struct Blob *cells,
246 int flags,
247 void *opaque
248 ){
249 BLOB_APPEND_LITERAL(ob, " <tr>\n");
250 BLOB_APPEND_BLOB(ob, cells);
251 BLOB_APPEND_LITERAL(ob, " </tr>\n");
252 }
253
254
255
256 /* HTML span tags */
@@ -265,52 +265,52 @@
265 struct Blob *link,
266 enum mkd_autolink type,
267 void *opaque
268 ){
269 if( !link || blob_size(link)<=0 ) return 0;
270 BLOB_APPEND_LITERAL(ob, "<a href=\"");
271 if( type==MKDA_IMPLICIT_EMAIL ) BLOB_APPEND_LITERAL(ob, "mailto:");
272 html_escape(ob, blob_buffer(link), blob_size(link));
273 BLOB_APPEND_LITERAL(ob, "\">");
274 if( type==MKDA_EXPLICIT_EMAIL && blob_size(link)>7 ){
275 /* remove "mailto:" from displayed text */
276 html_escape(ob, blob_buffer(link)+7, blob_size(link)-7);
277 }else{
278 html_escape(ob, blob_buffer(link), blob_size(link));
279 }
280 BLOB_APPEND_LITERAL(ob, "</a>");
281 return 1;
282 }
283
284 static int html_code_span(struct Blob *ob, struct Blob *text, void *opaque){
285 BLOB_APPEND_LITERAL(ob, "<code>");
286 html_escape(ob, blob_buffer(text), blob_size(text));
287 BLOB_APPEND_LITERAL(ob, "</code>");
288 return 1;
289 }
290
291 static int html_double_emphasis(
292 struct Blob *ob,
293 struct Blob *text,
294 char c,
295 void *opaque
296 ){
297 BLOB_APPEND_LITERAL(ob, "<strong>");
298 BLOB_APPEND_BLOB(ob, text);
299 BLOB_APPEND_LITERAL(ob, "</strong>");
300 return 1;
301 }
302
303 static int html_emphasis(
304 struct Blob *ob,
305 struct Blob *text,
306 char c,
307 void *opaque
308 ){
309 BLOB_APPEND_LITERAL(ob, "<em>");
310 BLOB_APPEND_BLOB(ob, text);
311 BLOB_APPEND_LITERAL(ob, "</em>");
312 return 1;
313 }
314
315 static int html_image(
316 struct Blob *ob,
@@ -317,24 +317,24 @@
317 struct Blob *link,
318 struct Blob *title,
319 struct Blob *alt,
320 void *opaque
321 ){
322 BLOB_APPEND_LITERAL(ob, "<img src=\"");
323 html_escape(ob, blob_buffer(link), blob_size(link));
324 BLOB_APPEND_LITERAL(ob, "\" alt=\"");
325 html_escape(ob, blob_buffer(alt), blob_size(alt));
326 if( title && blob_size(title)>0 ){
327 BLOB_APPEND_LITERAL(ob, "\" title=\"");
328 html_escape(ob, blob_buffer(title), blob_size(title));
329 }
330 BLOB_APPEND_LITERAL(ob, "\" />");
331 return 1;
332 }
333
334 static int html_line_break(struct Blob *ob, void *opaque){
335 BLOB_APPEND_LITERAL(ob, "<br />\n");
336 return 1;
337 }
338
339 static int html_link(
340 struct Blob *ob,
@@ -341,31 +341,31 @@
341 struct Blob *link,
342 struct Blob *title,
343 struct Blob *content,
344 void *opaque
345 ){
346 BLOB_APPEND_LITERAL(ob, "<a href=\"");
347 html_escape(ob, blob_buffer(link), blob_size(link));
348 if( title && blob_size(title)>0 ){
349 BLOB_APPEND_LITERAL(ob, "\" title=\"");
350 html_escape(ob, blob_buffer(title), blob_size(title));
351 }
352 BLOB_APPEND_LITERAL(ob, "\">");
353 BLOB_APPEND_BLOB(ob, content);
354 BLOB_APPEND_LITERAL(ob, "</a>");
355 return 1;
356 }
357
358 static int html_triple_emphasis(
359 struct Blob *ob,
360 struct Blob *text,
361 char c,
362 void *opaque
363 ){
364 BLOB_APPEND_LITERAL(ob, "<strong><em>");
365 BLOB_APPEND_BLOB(ob, text);
366 BLOB_APPEND_LITERAL(ob, "</em></strong>");
367 return 1;
368 }
369
370
371 static void html_normal_text(struct Blob *ob, struct Blob *text, void *opaque){
372
+28 -10
--- src/name.c
+++ src/name.c
@@ -1068,29 +1068,26 @@
10681068
10691069
/* Maximum number of collision examples to remember */
10701070
#define MAX_COLLIDE 25
10711071
10721072
/*
1073
-** WEBPAGE: hash-collisions
1074
-**
1075
-** Show the number of hash collisions for hash prefixes of various lengths.
1073
+** Generate a report on the number of collisions in SHA1 hashes
1074
+** generated by the SQL given in the argument.
10761075
*/
1077
-void hash_collisions_webpage(void){
1076
+static void collision_report(const char *zSql){
10781077
int i, j, kk;
10791078
int nHash = 0;
10801079
Stmt q;
10811080
char zPrev[UUID_SIZE+1];
10821081
struct {
10831082
int cnt;
10841083
char *azHit[MAX_COLLIDE];
10851084
char z[UUID_SIZE+1];
10861085
} aCollide[UUID_SIZE+1];
1087
- login_check_credentials();
1088
- if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
10891086
memset(aCollide, 0, sizeof(aCollide));
10901087
memset(zPrev, 0, sizeof(zPrev));
1091
- db_prepare(&q,"SELECT uuid FROM blob ORDER BY 1");
1088
+ db_prepare(&q,"%s",zSql/*safe-for-%s*/);
10921089
while( db_step(&q)==SQLITE_ROW ){
10931090
const char *zUuid = db_column_text(&q,0);
10941091
int n = db_column_bytes(&q,0);
10951092
int i;
10961093
nHash++;
@@ -1103,13 +1100,10 @@
11031100
if( aCollide[i].z[0]==0 ) memcpy(aCollide[i].z, zPrev, n+1);
11041101
}
11051102
memcpy(zPrev, zUuid, n+1);
11061103
}
11071104
db_finalize(&q);
1108
- style_header("SHA1 Prefix Collisions");
1109
- style_submenu_element("Activity Reports", 0, "reports");
1110
- style_submenu_element("Stats", 0, "stat");
11111105
@ <table border=1><thead>
11121106
@ <tr><th>Length<th>Instances<th>First Instance</tr>
11131107
@ </thead><tbody>
11141108
for(i=1; i<=UUID_SIZE; i++){
11151109
if( aCollide[i].cnt==0 ) continue;
@@ -1131,7 +1125,31 @@
11311125
char *zId = aCollide[i].azHit[j];
11321126
if( zId==0 ) continue;
11331127
@ %z(href("%R/whatis/%s",zId))%h(zId)</a>
11341128
}
11351129
}
1130
+ for(i=4; i<ArraySize(aCollide); i++){
1131
+ for(j=0; j<aCollide[i].cnt && j<MAX_COLLIDE; j++){
1132
+ fossil_free(aCollide[i].azHit[j]);
1133
+ }
1134
+ }
1135
+}
1136
+
1137
+/*
1138
+** WEBPAGE: hash-collisions
1139
+**
1140
+** Show the number of hash collisions for hash prefixes of various lengths.
1141
+*/
1142
+void hash_collisions_webpage(void){
1143
+ login_check_credentials();
1144
+ if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
1145
+ style_header("SHA1 Prefix Collisions");
1146
+ style_submenu_element("Activity Reports", 0, "reports");
1147
+ style_submenu_element("Stats", 0, "stat");
1148
+ @ <h1>Hash Prefix Collisions on Check-ins</h1>
1149
+ collision_report("SELECT (SELECT uuid FROM blob WHERE rid=objid)"
1150
+ " FROM event WHERE event.type='ci'"
1151
+ " ORDER BY 1");
1152
+ @ <h1>Hash Prefix Collisions on All Artifacts</h1>
1153
+ collision_report("SELECT uuid FROM blob ORDER BY 1");
11361154
style_footer();
11371155
}
11381156
11391157
ADDED src/piechart.c
--- src/name.c
+++ src/name.c
@@ -1068,29 +1068,26 @@
1068
1069 /* Maximum number of collision examples to remember */
1070 #define MAX_COLLIDE 25
1071
1072 /*
1073 ** WEBPAGE: hash-collisions
1074 **
1075 ** Show the number of hash collisions for hash prefixes of various lengths.
1076 */
1077 void hash_collisions_webpage(void){
1078 int i, j, kk;
1079 int nHash = 0;
1080 Stmt q;
1081 char zPrev[UUID_SIZE+1];
1082 struct {
1083 int cnt;
1084 char *azHit[MAX_COLLIDE];
1085 char z[UUID_SIZE+1];
1086 } aCollide[UUID_SIZE+1];
1087 login_check_credentials();
1088 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
1089 memset(aCollide, 0, sizeof(aCollide));
1090 memset(zPrev, 0, sizeof(zPrev));
1091 db_prepare(&q,"SELECT uuid FROM blob ORDER BY 1");
1092 while( db_step(&q)==SQLITE_ROW ){
1093 const char *zUuid = db_column_text(&q,0);
1094 int n = db_column_bytes(&q,0);
1095 int i;
1096 nHash++;
@@ -1103,13 +1100,10 @@
1103 if( aCollide[i].z[0]==0 ) memcpy(aCollide[i].z, zPrev, n+1);
1104 }
1105 memcpy(zPrev, zUuid, n+1);
1106 }
1107 db_finalize(&q);
1108 style_header("SHA1 Prefix Collisions");
1109 style_submenu_element("Activity Reports", 0, "reports");
1110 style_submenu_element("Stats", 0, "stat");
1111 @ <table border=1><thead>
1112 @ <tr><th>Length<th>Instances<th>First Instance</tr>
1113 @ </thead><tbody>
1114 for(i=1; i<=UUID_SIZE; i++){
1115 if( aCollide[i].cnt==0 ) continue;
@@ -1131,7 +1125,31 @@
1131 char *zId = aCollide[i].azHit[j];
1132 if( zId==0 ) continue;
1133 @ %z(href("%R/whatis/%s",zId))%h(zId)</a>
1134 }
1135 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1136 style_footer();
1137 }
1138
1139 DDED src/piechart.c
--- src/name.c
+++ src/name.c
@@ -1068,29 +1068,26 @@
1068
1069 /* Maximum number of collision examples to remember */
1070 #define MAX_COLLIDE 25
1071
1072 /*
1073 ** Generate a report on the number of collisions in SHA1 hashes
1074 ** generated by the SQL given in the argument.
 
1075 */
1076 static void collision_report(const char *zSql){
1077 int i, j, kk;
1078 int nHash = 0;
1079 Stmt q;
1080 char zPrev[UUID_SIZE+1];
1081 struct {
1082 int cnt;
1083 char *azHit[MAX_COLLIDE];
1084 char z[UUID_SIZE+1];
1085 } aCollide[UUID_SIZE+1];
 
 
1086 memset(aCollide, 0, sizeof(aCollide));
1087 memset(zPrev, 0, sizeof(zPrev));
1088 db_prepare(&q,"%s",zSql/*safe-for-%s*/);
1089 while( db_step(&q)==SQLITE_ROW ){
1090 const char *zUuid = db_column_text(&q,0);
1091 int n = db_column_bytes(&q,0);
1092 int i;
1093 nHash++;
@@ -1103,13 +1100,10 @@
1100 if( aCollide[i].z[0]==0 ) memcpy(aCollide[i].z, zPrev, n+1);
1101 }
1102 memcpy(zPrev, zUuid, n+1);
1103 }
1104 db_finalize(&q);
 
 
 
1105 @ <table border=1><thead>
1106 @ <tr><th>Length<th>Instances<th>First Instance</tr>
1107 @ </thead><tbody>
1108 for(i=1; i<=UUID_SIZE; i++){
1109 if( aCollide[i].cnt==0 ) continue;
@@ -1131,7 +1125,31 @@
1125 char *zId = aCollide[i].azHit[j];
1126 if( zId==0 ) continue;
1127 @ %z(href("%R/whatis/%s",zId))%h(zId)</a>
1128 }
1129 }
1130 for(i=4; i<ArraySize(aCollide); i++){
1131 for(j=0; j<aCollide[i].cnt && j<MAX_COLLIDE; j++){
1132 fossil_free(aCollide[i].azHit[j]);
1133 }
1134 }
1135 }
1136
1137 /*
1138 ** WEBPAGE: hash-collisions
1139 **
1140 ** Show the number of hash collisions for hash prefixes of various lengths.
1141 */
1142 void hash_collisions_webpage(void){
1143 login_check_credentials();
1144 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
1145 style_header("SHA1 Prefix Collisions");
1146 style_submenu_element("Activity Reports", 0, "reports");
1147 style_submenu_element("Stats", 0, "stat");
1148 @ <h1>Hash Prefix Collisions on Check-ins</h1>
1149 collision_report("SELECT (SELECT uuid FROM blob WHERE rid=objid)"
1150 " FROM event WHERE event.type='ci'"
1151 " ORDER BY 1");
1152 @ <h1>Hash Prefix Collisions on All Artifacts</h1>
1153 collision_report("SELECT uuid FROM blob ORDER BY 1");
1154 style_footer();
1155 }
1156
1157 DDED src/piechart.c
--- a/src/piechart.c
+++ b/src/piechart.c
@@ -0,0 +1,19 @@
1
+/*
2
+** Copyright (c) 2015 D. Richard Hipp
3
+**
4
+** This program is free software; you can redistribute it and/or
5
+** modify it under the terms o return;test_piecharpiechart_tes, q;
6
+ Bloblob_init(&all, zData, -1);
7
+ whif( blob_token(&line, &token1)==0 ) continue;
8
+ rAmt = atof(blob_str(&token1));
9
+ if( rAmt<=0.0 ) continue;
10
+ blob_tail(&line, &token2blob_str(&token2)n++ins);
11
+ blob_reset(&all);
12
+ if( n>0postOne slice per line. Value and then Label.<p>
13
+ @ <textarea name='data' rows='20' cohidden<input type='hiddenhr /><p>Previous Data:<rowid,");
14
+ while( ){
15
+ @ <tr><td>%d(db_column_int1))</td>
16
+ @ <td>%h(db_c. @ </table>
17
+ style_footer();
18
+}
19
+=
--- a/src/piechart.c
+++ b/src/piechart.c
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/src/piechart.c
+++ b/src/piechart.c
@@ -0,0 +1,19 @@
1 /*
2 ** Copyright (c) 2015 D. Richard Hipp
3 **
4 ** This program is free software; you can redistribute it and/or
5 ** modify it under the terms o return;test_piecharpiechart_tes, q;
6 Bloblob_init(&all, zData, -1);
7 whif( blob_token(&line, &token1)==0 ) continue;
8 rAmt = atof(blob_str(&token1));
9 if( rAmt<=0.0 ) continue;
10 blob_tail(&line, &token2blob_str(&token2)n++ins);
11 blob_reset(&all);
12 if( n>0postOne slice per line. Value and then Label.<p>
13 @ <textarea name='data' rows='20' cohidden<input type='hiddenhr /><p>Previous Data:<rowid,");
14 while( ){
15 @ <tr><td>%d(db_column_int1))</td>
16 @ <td>%h(db_c. @ </table>
17 style_footer();
18 }
19 =
+26 -20
--- src/rebuild.c
+++ src/rebuild.c
@@ -522,31 +522,32 @@
522522
** Reconstruct the named repository database from the core
523523
** records. Run this command after updating the fossil
524524
** executable in a way that changes the database schema.
525525
**
526526
** Options:
527
-** --analyze Run ANALYZE on the database after rebuilding
528
-** --cluster Compute clusters for unclustered artifacts
529
-** --compress Strive to make the database as small as possible
530
-** --deanalyze Remove ANALYZE tables from the database
531
-** --force Force the rebuild to complete even if errors are seen
532
-** --ifneeded Only do the rebuild if it would change the schema version
533
-** --index Always add in the full-text search index
534
-** --noverify Skip the verification of changes to the BLOB table
535
-** --noindex Always omit the full-text search index
536
-** --pagesize N Set the database pagesize to N. (512..65536 and power of 2)
537
-** --randomize Scan artifacts in a random order
538
-** --stats Show artifact statistics after rebuilding
539
-** --vacuum Run VACUUM on the database after rebuilding
540
-** --wal Set Write-Ahead-Log journalling mode on the database
527
+** --analyze Run ANALYZE on the database after rebuilding
528
+** --cluster Compute clusters for unclustered artifacts
529
+** --compress Strive to make the database as small as possible
530
+** --compress-only Skip the rebuilding step. Do --compress only
531
+** --deanalyze Remove ANALYZE tables from the database
532
+** --force Force the rebuild to complete even if errors are seen
533
+** --ifneeded Only do the rebuild if it would change the schema version
534
+** --index Always add in the full-text search index
535
+** --noverify Skip the verification of changes to the BLOB table
536
+** --noindex Always omit the full-text search index
537
+** --pagesize N Set the database pagesize to N. (512..65536 and power of 2)
538
+** --randomize Scan artifacts in a random order
539
+** --stats Show artifact statistics after rebuilding
540
+** --vacuum Run VACUUM on the database after rebuilding
541
+** --wal Set Write-Ahead-Log journalling mode on the database
541542
**
542543
** See also: deconstruct, reconstruct
543544
*/
544545
void rebuild_database(void){
545546
int forceFlag;
546547
int randomizeFlag;
547
- int errCnt;
548
+ int errCnt = 0;
548549
int omitVerify;
549550
int doClustering;
550551
const char *zPagesize;
551552
int newPagesize = 0;
552553
int activateWal;
@@ -557,10 +558,11 @@
557558
int showStats;
558559
int runReindex;
559560
int optNoIndex;
560561
int optIndex;
561562
int optIfNeeded;
563
+ int compressOnlyFlag;
562564
563565
omitVerify = find_option("noverify",0,0)!=0;
564566
forceFlag = find_option("force","f",0)!=0;
565567
randomizeFlag = find_option("randomize", 0, 0)!=0;
566568
doClustering = find_option("cluster", 0, 0)!=0;
@@ -571,10 +573,12 @@
571573
zPagesize = find_option("pagesize",0,1);
572574
showStats = find_option("stats",0,0)!=0;
573575
optIndex = find_option("index",0,0)!=0;
574576
optNoIndex = find_option("noindex",0,0)!=0;
575577
optIfNeeded = find_option("ifneeded",0,0)!=0;
578
+ compressOnlyFlag = find_option("compress-only",0,0)!=0;
579
+ if( compressOnlyFlag ) runCompress = runVacuum = 1;
576580
if( zPagesize ){
577581
newPagesize = atoi(zPagesize);
578582
if( newPagesize<512 || newPagesize>65536
579583
|| (newPagesize&(newPagesize-1))!=0
580584
){
@@ -590,11 +594,11 @@
590594
usage("?REPOSITORY-FILENAME?");
591595
}
592596
db_close(1);
593597
db_open_repository(g.zRepositoryName);
594598
}
595
- runReindex = search_index_exists();
599
+ runReindex = search_index_exists() && !compressOnlyFlag;
596600
if( optIndex ) runReindex = 1;
597601
if( optNoIndex ) runReindex = 0;
598602
if( optIfNeeded && fossil_strcmp(db_get("aux-schema",""),AUX_SCHEMA_MAX)==0 ){
599603
return;
600604
}
@@ -601,14 +605,16 @@
601605
602606
/* We should be done with options.. */
603607
verify_all_options();
604608
605609
db_begin_transaction();
606
- search_drop_index();
607
- ttyOutput = 1;
608
- errCnt = rebuild_db(randomizeFlag, 1, doClustering);
609
- reconstruct_private_table();
610
+ if( !compressOnlyFlag ){
611
+ search_drop_index();
612
+ ttyOutput = 1;
613
+ errCnt = rebuild_db(randomizeFlag, 1, doClustering);
614
+ reconstruct_private_table();
615
+ }
610616
db_multi_exec(
611617
"REPLACE INTO config(name,value,mtime) VALUES('content-schema',%Q,now());"
612618
"REPLACE INTO config(name,value,mtime) VALUES('aux-schema',%Q,now());"
613619
"REPLACE INTO config(name,value,mtime) VALUES('rebuilt',%Q,now());",
614620
CONTENT_SCHEMA, AUX_SCHEMA_MAX, get_version()
615621
--- src/rebuild.c
+++ src/rebuild.c
@@ -522,31 +522,32 @@
522 ** Reconstruct the named repository database from the core
523 ** records. Run this command after updating the fossil
524 ** executable in a way that changes the database schema.
525 **
526 ** Options:
527 ** --analyze Run ANALYZE on the database after rebuilding
528 ** --cluster Compute clusters for unclustered artifacts
529 ** --compress Strive to make the database as small as possible
530 ** --deanalyze Remove ANALYZE tables from the database
531 ** --force Force the rebuild to complete even if errors are seen
532 ** --ifneeded Only do the rebuild if it would change the schema version
533 ** --index Always add in the full-text search index
534 ** --noverify Skip the verification of changes to the BLOB table
535 ** --noindex Always omit the full-text search index
536 ** --pagesize N Set the database pagesize to N. (512..65536 and power of 2)
537 ** --randomize Scan artifacts in a random order
538 ** --stats Show artifact statistics after rebuilding
539 ** --vacuum Run VACUUM on the database after rebuilding
540 ** --wal Set Write-Ahead-Log journalling mode on the database
 
541 **
542 ** See also: deconstruct, reconstruct
543 */
544 void rebuild_database(void){
545 int forceFlag;
546 int randomizeFlag;
547 int errCnt;
548 int omitVerify;
549 int doClustering;
550 const char *zPagesize;
551 int newPagesize = 0;
552 int activateWal;
@@ -557,10 +558,11 @@
557 int showStats;
558 int runReindex;
559 int optNoIndex;
560 int optIndex;
561 int optIfNeeded;
 
562
563 omitVerify = find_option("noverify",0,0)!=0;
564 forceFlag = find_option("force","f",0)!=0;
565 randomizeFlag = find_option("randomize", 0, 0)!=0;
566 doClustering = find_option("cluster", 0, 0)!=0;
@@ -571,10 +573,12 @@
571 zPagesize = find_option("pagesize",0,1);
572 showStats = find_option("stats",0,0)!=0;
573 optIndex = find_option("index",0,0)!=0;
574 optNoIndex = find_option("noindex",0,0)!=0;
575 optIfNeeded = find_option("ifneeded",0,0)!=0;
 
 
576 if( zPagesize ){
577 newPagesize = atoi(zPagesize);
578 if( newPagesize<512 || newPagesize>65536
579 || (newPagesize&(newPagesize-1))!=0
580 ){
@@ -590,11 +594,11 @@
590 usage("?REPOSITORY-FILENAME?");
591 }
592 db_close(1);
593 db_open_repository(g.zRepositoryName);
594 }
595 runReindex = search_index_exists();
596 if( optIndex ) runReindex = 1;
597 if( optNoIndex ) runReindex = 0;
598 if( optIfNeeded && fossil_strcmp(db_get("aux-schema",""),AUX_SCHEMA_MAX)==0 ){
599 return;
600 }
@@ -601,14 +605,16 @@
601
602 /* We should be done with options.. */
603 verify_all_options();
604
605 db_begin_transaction();
606 search_drop_index();
607 ttyOutput = 1;
608 errCnt = rebuild_db(randomizeFlag, 1, doClustering);
609 reconstruct_private_table();
 
 
610 db_multi_exec(
611 "REPLACE INTO config(name,value,mtime) VALUES('content-schema',%Q,now());"
612 "REPLACE INTO config(name,value,mtime) VALUES('aux-schema',%Q,now());"
613 "REPLACE INTO config(name,value,mtime) VALUES('rebuilt',%Q,now());",
614 CONTENT_SCHEMA, AUX_SCHEMA_MAX, get_version()
615
--- src/rebuild.c
+++ src/rebuild.c
@@ -522,31 +522,32 @@
522 ** Reconstruct the named repository database from the core
523 ** records. Run this command after updating the fossil
524 ** executable in a way that changes the database schema.
525 **
526 ** Options:
527 ** --analyze Run ANALYZE on the database after rebuilding
528 ** --cluster Compute clusters for unclustered artifacts
529 ** --compress Strive to make the database as small as possible
530 ** --compress-only Skip the rebuilding step. Do --compress only
531 ** --deanalyze Remove ANALYZE tables from the database
532 ** --force Force the rebuild to complete even if errors are seen
533 ** --ifneeded Only do the rebuild if it would change the schema version
534 ** --index Always add in the full-text search index
535 ** --noverify Skip the verification of changes to the BLOB table
536 ** --noindex Always omit the full-text search index
537 ** --pagesize N Set the database pagesize to N. (512..65536 and power of 2)
538 ** --randomize Scan artifacts in a random order
539 ** --stats Show artifact statistics after rebuilding
540 ** --vacuum Run VACUUM on the database after rebuilding
541 ** --wal Set Write-Ahead-Log journalling mode on the database
542 **
543 ** See also: deconstruct, reconstruct
544 */
545 void rebuild_database(void){
546 int forceFlag;
547 int randomizeFlag;
548 int errCnt = 0;
549 int omitVerify;
550 int doClustering;
551 const char *zPagesize;
552 int newPagesize = 0;
553 int activateWal;
@@ -557,10 +558,11 @@
558 int showStats;
559 int runReindex;
560 int optNoIndex;
561 int optIndex;
562 int optIfNeeded;
563 int compressOnlyFlag;
564
565 omitVerify = find_option("noverify",0,0)!=0;
566 forceFlag = find_option("force","f",0)!=0;
567 randomizeFlag = find_option("randomize", 0, 0)!=0;
568 doClustering = find_option("cluster", 0, 0)!=0;
@@ -571,10 +573,12 @@
573 zPagesize = find_option("pagesize",0,1);
574 showStats = find_option("stats",0,0)!=0;
575 optIndex = find_option("index",0,0)!=0;
576 optNoIndex = find_option("noindex",0,0)!=0;
577 optIfNeeded = find_option("ifneeded",0,0)!=0;
578 compressOnlyFlag = find_option("compress-only",0,0)!=0;
579 if( compressOnlyFlag ) runCompress = runVacuum = 1;
580 if( zPagesize ){
581 newPagesize = atoi(zPagesize);
582 if( newPagesize<512 || newPagesize>65536
583 || (newPagesize&(newPagesize-1))!=0
584 ){
@@ -590,11 +594,11 @@
594 usage("?REPOSITORY-FILENAME?");
595 }
596 db_close(1);
597 db_open_repository(g.zRepositoryName);
598 }
599 runReindex = search_index_exists() && !compressOnlyFlag;
600 if( optIndex ) runReindex = 1;
601 if( optNoIndex ) runReindex = 0;
602 if( optIfNeeded && fossil_strcmp(db_get("aux-schema",""),AUX_SCHEMA_MAX)==0 ){
603 return;
604 }
@@ -601,14 +605,16 @@
605
606 /* We should be done with options.. */
607 verify_all_options();
608
609 db_begin_transaction();
610 if( !compressOnlyFlag ){
611 search_drop_index();
612 ttyOutput = 1;
613 errCnt = rebuild_db(randomizeFlag, 1, doClustering);
614 reconstruct_private_table();
615 }
616 db_multi_exec(
617 "REPLACE INTO config(name,value,mtime) VALUES('content-schema',%Q,now());"
618 "REPLACE INTO config(name,value,mtime) VALUES('aux-schema',%Q,now());"
619 "REPLACE INTO config(name,value,mtime) VALUES('rebuilt',%Q,now());",
620 CONTENT_SCHEMA, AUX_SCHEMA_MAX, get_version()
621
+12 -10
--- src/schema.c
+++ src/schema.c
@@ -249,22 +249,24 @@
249249
@ -- pid = Parent file ID.
250250
@ -- fnid = File Name ID.
251251
@ -- pfnid = Parent File Name ID.
252252
@ -- isaux = pmid IS AUXiliary parent, not primary parent
253253
@ --
254
-@ -- pid==0 if the file is added by check-in mid.
255
-@ -- fid==0 if the file is removed by check-in mid.
254
+@ -- pid==0 if the file is added by check-in mid.
255
+@ -- pid==(-1) if the file exists in a merge parents but not in the primary
256
+@ -- parent. In other words, if the file file was added by merge.
257
+@ -- fid==0 if the file is removed by check-in mid.
256258
@ --
257259
@ CREATE TABLE mlink(
258
-@ mid INTEGER REFERENCES plink(cid), -- Check-in that contains fid
259
-@ fid INTEGER REFERENCES blob, -- New file content. 0 if deleted
260
-@ pmid INTEGER REFERENCES plink(cid), -- Check-in that contains pid
261
-@ pid INTEGER REFERENCES blob, -- Prev file content. 0 if new
262
-@ fnid INTEGER REFERENCES filename, -- Name of the file
263
-@ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged
264
-@ mperm INTEGER, -- File permissions. 1==exec
265
-@ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
260
+@ mid INTEGER, -- Check-in that contains fid
261
+@ fid INTEGER, -- New file content. 0 if deleted
262
+@ pmid INTEGER, -- Check-in that contains pid
263
+@ pid INTEGER, -- Prev file content. 0 if new. -1 merge
264
+@ fnid INTEGER REFERENCES filename, -- Name of the file
265
+@ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged
266
+@ mperm INTEGER, -- File permissions. 1==exec
267
+@ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
266268
@ );
267269
@ CREATE INDEX mlink_i1 ON mlink(mid);
268270
@ CREATE INDEX mlink_i2 ON mlink(fnid);
269271
@ CREATE INDEX mlink_i3 ON mlink(fid);
270272
@ CREATE INDEX mlink_i4 ON mlink(pid);
271273
--- src/schema.c
+++ src/schema.c
@@ -249,22 +249,24 @@
249 @ -- pid = Parent file ID.
250 @ -- fnid = File Name ID.
251 @ -- pfnid = Parent File Name ID.
252 @ -- isaux = pmid IS AUXiliary parent, not primary parent
253 @ --
254 @ -- pid==0 if the file is added by check-in mid.
255 @ -- fid==0 if the file is removed by check-in mid.
 
 
256 @ --
257 @ CREATE TABLE mlink(
258 @ mid INTEGER REFERENCES plink(cid), -- Check-in that contains fid
259 @ fid INTEGER REFERENCES blob, -- New file content. 0 if deleted
260 @ pmid INTEGER REFERENCES plink(cid), -- Check-in that contains pid
261 @ pid INTEGER REFERENCES blob, -- Prev file content. 0 if new
262 @ fnid INTEGER REFERENCES filename, -- Name of the file
263 @ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged
264 @ mperm INTEGER, -- File permissions. 1==exec
265 @ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
266 @ );
267 @ CREATE INDEX mlink_i1 ON mlink(mid);
268 @ CREATE INDEX mlink_i2 ON mlink(fnid);
269 @ CREATE INDEX mlink_i3 ON mlink(fid);
270 @ CREATE INDEX mlink_i4 ON mlink(pid);
271
--- src/schema.c
+++ src/schema.c
@@ -249,22 +249,24 @@
249 @ -- pid = Parent file ID.
250 @ -- fnid = File Name ID.
251 @ -- pfnid = Parent File Name ID.
252 @ -- isaux = pmid IS AUXiliary parent, not primary parent
253 @ --
254 @ -- pid==0 if the file is added by check-in mid.
255 @ -- pid==(-1) if the file exists in a merge parents but not in the primary
256 @ -- parent. In other words, if the file file was added by merge.
257 @ -- fid==0 if the file is removed by check-in mid.
258 @ --
259 @ CREATE TABLE mlink(
260 @ mid INTEGER, -- Check-in that contains fid
261 @ fid INTEGER, -- New file content. 0 if deleted
262 @ pmid INTEGER, -- Check-in that contains pid
263 @ pid INTEGER, -- Prev file content. 0 if new. -1 merge
264 @ fnid INTEGER REFERENCES filename, -- Name of the file
265 @ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged
266 @ mperm INTEGER, -- File permissions. 1==exec
267 @ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
268 @ );
269 @ CREATE INDEX mlink_i1 ON mlink(mid);
270 @ CREATE INDEX mlink_i2 ON mlink(fnid);
271 @ CREATE INDEX mlink_i3 ON mlink(fid);
272 @ CREATE INDEX mlink_i4 ON mlink(pid);
273
+1 -1
--- src/search.c
+++ src/search.c
@@ -102,11 +102,11 @@
102102
}
103103
104104
/*
105105
** Compile a search pattern
106106
*/
107
-Search *search_init(
107
+static Search *search_init(
108108
const char *zPattern, /* The search pattern */
109109
const char *zMarkBegin, /* Start of a match */
110110
const char *zMarkEnd, /* End of a match */
111111
const char *zMarkGap, /* A gap between two matches */
112112
unsigned fSrchFlg /* Flags */
113113
--- src/search.c
+++ src/search.c
@@ -102,11 +102,11 @@
102 }
103
104 /*
105 ** Compile a search pattern
106 */
107 Search *search_init(
108 const char *zPattern, /* The search pattern */
109 const char *zMarkBegin, /* Start of a match */
110 const char *zMarkEnd, /* End of a match */
111 const char *zMarkGap, /* A gap between two matches */
112 unsigned fSrchFlg /* Flags */
113
--- src/search.c
+++ src/search.c
@@ -102,11 +102,11 @@
102 }
103
104 /*
105 ** Compile a search pattern
106 */
107 static Search *search_init(
108 const char *zPattern, /* The search pattern */
109 const char *zMarkBegin, /* Start of a match */
110 const char *zMarkEnd, /* End of a match */
111 const char *zMarkGap, /* A gap between two matches */
112 unsigned fSrchFlg /* Flags */
113
+2 -7
--- src/shell.c
+++ src/shell.c
@@ -1918,16 +1918,10 @@
19181918
*/
19191919
static void open_db(ShellState *p, int keepAlive){
19201920
if( p->db==0 ){
19211921
sqlite3_initialize();
19221922
sqlite3_open(p->zDbFilename, &p->db);
1923
-#ifdef SQLITE_ENABLE_DBSTAT_VTAB
1924
- if( p->db ){
1925
- int sqlite3_dbstat_register(sqlite3*);
1926
- sqlite3_dbstat_register(p->db);
1927
- }
1928
-#endif
19291923
globalDb = p->db;
19301924
if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){
19311925
sqlite3_create_function(p->db, "shellstatic", 0, SQLITE_UTF8, 0,
19321926
shellstaticFunc, 0, 0);
19331927
}
@@ -3262,11 +3256,12 @@
32623256
azArg[1]);
32633257
rc = 1;
32643258
goto meta_command_exit;
32653259
}
32663260
if( nArg==3 ){
3267
- sqlite3_limit(p->db, aLimit[iLimit].limitCode, integerValue(azArg[2]));
3261
+ sqlite3_limit(p->db, aLimit[iLimit].limitCode,
3262
+ (int)integerValue(azArg[2]));
32683263
}
32693264
printf("%20s %d\n", aLimit[iLimit].zLimitName,
32703265
sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
32713266
}
32723267
}else
32733268
--- src/shell.c
+++ src/shell.c
@@ -1918,16 +1918,10 @@
1918 */
1919 static void open_db(ShellState *p, int keepAlive){
1920 if( p->db==0 ){
1921 sqlite3_initialize();
1922 sqlite3_open(p->zDbFilename, &p->db);
1923 #ifdef SQLITE_ENABLE_DBSTAT_VTAB
1924 if( p->db ){
1925 int sqlite3_dbstat_register(sqlite3*);
1926 sqlite3_dbstat_register(p->db);
1927 }
1928 #endif
1929 globalDb = p->db;
1930 if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){
1931 sqlite3_create_function(p->db, "shellstatic", 0, SQLITE_UTF8, 0,
1932 shellstaticFunc, 0, 0);
1933 }
@@ -3262,11 +3256,12 @@
3262 azArg[1]);
3263 rc = 1;
3264 goto meta_command_exit;
3265 }
3266 if( nArg==3 ){
3267 sqlite3_limit(p->db, aLimit[iLimit].limitCode, integerValue(azArg[2]));
 
3268 }
3269 printf("%20s %d\n", aLimit[iLimit].zLimitName,
3270 sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
3271 }
3272 }else
3273
--- src/shell.c
+++ src/shell.c
@@ -1918,16 +1918,10 @@
1918 */
1919 static void open_db(ShellState *p, int keepAlive){
1920 if( p->db==0 ){
1921 sqlite3_initialize();
1922 sqlite3_open(p->zDbFilename, &p->db);
 
 
 
 
 
 
1923 globalDb = p->db;
1924 if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){
1925 sqlite3_create_function(p->db, "shellstatic", 0, SQLITE_UTF8, 0,
1926 shellstaticFunc, 0, 0);
1927 }
@@ -3262,11 +3256,12 @@
3256 azArg[1]);
3257 rc = 1;
3258 goto meta_command_exit;
3259 }
3260 if( nArg==3 ){
3261 sqlite3_limit(p->db, aLimit[iLimit].limitCode,
3262 (int)integerValue(azArg[2]));
3263 }
3264 printf("%20s %d\n", aLimit[iLimit].zLimitName,
3265 sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
3266 }
3267 }else
3268
+1961 -728
--- 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.8.9. By combining all the individual C code files into this
3
+** version 3.8.10.2. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -68,10 +68,11 @@
6868
#if defined(_MSC_VER)
6969
#pragma warning(disable : 4054)
7070
#pragma warning(disable : 4055)
7171
#pragma warning(disable : 4100)
7272
#pragma warning(disable : 4127)
73
+#pragma warning(disable : 4130)
7374
#pragma warning(disable : 4152)
7475
#pragma warning(disable : 4189)
7576
#pragma warning(disable : 4206)
7677
#pragma warning(disable : 4210)
7778
#pragma warning(disable : 4232)
@@ -315,13 +316,13 @@
315316
**
316317
** See also: [sqlite3_libversion()],
317318
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
318319
** [sqlite_version()] and [sqlite_source_id()].
319320
*/
320
-#define SQLITE_VERSION "3.8.9"
321
-#define SQLITE_VERSION_NUMBER 3008009
322
-#define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09"
321
+#define SQLITE_VERSION "3.8.10.2"
322
+#define SQLITE_VERSION_NUMBER 3008010
323
+#define SQLITE_SOURCE_ID "2015-05-20 18:17:19 2ef4f3a5b1d1d0c4338f8243d40a2452cc1f7fe4"
323324
324325
/*
325326
** CAPI3REF: Run-Time Library Version Numbers
326327
** KEYWORDS: sqlite3_version, sqlite3_sourceid
327328
**
@@ -474,10 +475,11 @@
474475
# define double sqlite3_int64
475476
#endif
476477
477478
/*
478479
** CAPI3REF: Closing A Database Connection
480
+** DESTRUCTOR: sqlite3
479481
**
480482
** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
481483
** for the [sqlite3] object.
482484
** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
483485
** the [sqlite3] object is successfully destroyed and all associated
@@ -525,10 +527,11 @@
525527
*/
526528
typedef int (*sqlite3_callback)(void*,int,char**, char**);
527529
528530
/*
529531
** CAPI3REF: One-Step Query Execution Interface
532
+** METHOD: sqlite3
530533
**
531534
** The sqlite3_exec() interface is a convenience wrapper around
532535
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
533536
** that allows an application to run multiple statements of SQL
534537
** without having to use a lot of C code.
@@ -1582,10 +1585,11 @@
15821585
*/
15831586
SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
15841587
15851588
/*
15861589
** CAPI3REF: Configure database connections
1590
+** METHOD: sqlite3
15871591
**
15881592
** The sqlite3_db_config() interface is used to make configuration
15891593
** changes to a [database connection]. The interface is similar to
15901594
** [sqlite3_config()] except that the changes apply to a single
15911595
** [database connection] (specified in the first argument).
@@ -2079,19 +2083,21 @@
20792083
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
20802084
20812085
20822086
/*
20832087
** CAPI3REF: Enable Or Disable Extended Result Codes
2088
+** METHOD: sqlite3
20842089
**
20852090
** ^The sqlite3_extended_result_codes() routine enables or disables the
20862091
** [extended result codes] feature of SQLite. ^The extended result
20872092
** codes are disabled by default for historical compatibility.
20882093
*/
20892094
SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
20902095
20912096
/*
20922097
** CAPI3REF: Last Insert Rowid
2098
+** METHOD: sqlite3
20932099
**
20942100
** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
20952101
** has a unique 64-bit signed
20962102
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
20972103
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -2139,10 +2145,11 @@
21392145
*/
21402146
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
21412147
21422148
/*
21432149
** CAPI3REF: Count The Number Of Rows Modified
2150
+** METHOD: sqlite3
21442151
**
21452152
** ^This function returns the number of rows modified, inserted or
21462153
** deleted by the most recently completed INSERT, UPDATE or DELETE
21472154
** statement on the database connection specified by the only parameter.
21482155
** ^Executing any other type of SQL statement does not modify the value
@@ -2191,10 +2198,11 @@
21912198
*/
21922199
SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
21932200
21942201
/*
21952202
** CAPI3REF: Total Number Of Rows Modified
2203
+** METHOD: sqlite3
21962204
**
21972205
** ^This function returns the total number of rows inserted, modified or
21982206
** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
21992207
** since the database connection was opened, including those executed as
22002208
** part of trigger programs. ^Executing any other type of SQL statement
@@ -2214,10 +2222,11 @@
22142222
*/
22152223
SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
22162224
22172225
/*
22182226
** CAPI3REF: Interrupt A Long-Running Query
2227
+** METHOD: sqlite3
22192228
**
22202229
** ^This function causes any pending database operation to abort and
22212230
** return at its earliest opportunity. This routine is typically
22222231
** called in response to a user action such as pressing "Cancel"
22232232
** or Ctrl-C where the user wants a long query operation to halt
@@ -2290,10 +2299,11 @@
22902299
SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
22912300
22922301
/*
22932302
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
22942303
** KEYWORDS: {busy-handler callback} {busy handler}
2304
+** METHOD: sqlite3
22952305
**
22962306
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
22972307
** that might be invoked with argument P whenever
22982308
** an attempt is made to access a database table associated with
22992309
** [database connection] D when another thread
@@ -2349,10 +2359,11 @@
23492359
*/
23502360
SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
23512361
23522362
/*
23532363
** CAPI3REF: Set A Busy Timeout
2364
+** METHOD: sqlite3
23542365
**
23552366
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
23562367
** for a specified amount of time when a table is locked. ^The handler
23572368
** will sleep multiple times until at least "ms" milliseconds of sleeping
23582369
** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2371,10 +2382,11 @@
23712382
*/
23722383
SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
23732384
23742385
/*
23752386
** CAPI3REF: Convenience Routines For Running Queries
2387
+** METHOD: sqlite3
23762388
**
23772389
** This is a legacy interface that is preserved for backwards compatibility.
23782390
** Use of this interface is not recommended.
23792391
**
23802392
** Definition: A <b>result table</b> is memory data structure created by the
@@ -2706,10 +2718,11 @@
27062718
*/
27072719
SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
27082720
27092721
/*
27102722
** CAPI3REF: Compile-Time Authorization Callbacks
2723
+** METHOD: sqlite3
27112724
**
27122725
** ^This routine registers an authorizer callback with a particular
27132726
** [database connection], supplied in the first argument.
27142727
** ^The authorizer callback is invoked as SQL statements are being compiled
27152728
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2862,10 +2875,11 @@
28622875
#define SQLITE_COPY 0 /* No longer used */
28632876
#define SQLITE_RECURSIVE 33 /* NULL NULL */
28642877
28652878
/*
28662879
** CAPI3REF: Tracing And Profiling Functions
2880
+** METHOD: sqlite3
28672881
**
28682882
** These routines register callback functions that can be used for
28692883
** tracing and profiling the execution of SQL statements.
28702884
**
28712885
** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2894,10 +2908,11 @@
28942908
SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
28952909
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
28962910
28972911
/*
28982912
** CAPI3REF: Query Progress Callbacks
2913
+** METHOD: sqlite3
28992914
**
29002915
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
29012916
** function X to be invoked periodically during long running calls to
29022917
** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
29032918
** database connection D. An example use for this
@@ -2927,10 +2942,11 @@
29272942
*/
29282943
SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
29292944
29302945
/*
29312946
** CAPI3REF: Opening A New Database Connection
2947
+** CONSTRUCTOR: sqlite3
29322948
**
29332949
** ^These routines open an SQLite database file as specified by the
29342950
** filename argument. ^The filename argument is interpreted as UTF-8 for
29352951
** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
29362952
** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3212,10 +3228,11 @@
32123228
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
32133229
32143230
32153231
/*
32163232
** CAPI3REF: Error Codes And Messages
3233
+** METHOD: sqlite3
32173234
**
32183235
** ^If the most recent sqlite3_* API call associated with
32193236
** [database connection] D failed, then the sqlite3_errcode(D) interface
32203237
** returns the numeric [result code] or [extended result code] for that
32213238
** API call.
@@ -3257,37 +3274,38 @@
32573274
SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
32583275
SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
32593276
SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
32603277
32613278
/*
3262
-** CAPI3REF: SQL Statement Object
3279
+** CAPI3REF: Prepared Statement Object
32633280
** KEYWORDS: {prepared statement} {prepared statements}
32643281
**
3265
-** An instance of this object represents a single SQL statement.
3266
-** This object is variously known as a "prepared statement" or a
3267
-** "compiled SQL statement" or simply as a "statement".
3282
+** An instance of this object represents a single SQL statement that
3283
+** has been compiled into binary form and is ready to be evaluated.
32683284
**
3269
-** The life of a statement object goes something like this:
3285
+** Think of each SQL statement as a separate computer program. The
3286
+** original SQL text is source code. A prepared statement object
3287
+** is the compiled object code. All SQL must be converted into a
3288
+** prepared statement before it can be run.
3289
+**
3290
+** The life-cycle of a prepared statement object usually goes like this:
32703291
**
32713292
** <ol>
3272
-** <li> Create the object using [sqlite3_prepare_v2()] or a related
3273
-** function.
3274
-** <li> Bind values to [host parameters] using the sqlite3_bind_*()
3293
+** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
3294
+** <li> Bind values to [parameters] using the sqlite3_bind_*()
32753295
** interfaces.
32763296
** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3277
-** <li> Reset the statement using [sqlite3_reset()] then go back
3297
+** <li> Reset the prepared statement using [sqlite3_reset()] then go back
32783298
** to step 2. Do this zero or more times.
32793299
** <li> Destroy the object using [sqlite3_finalize()].
32803300
** </ol>
3281
-**
3282
-** Refer to documentation on individual methods above for additional
3283
-** information.
32843301
*/
32853302
typedef struct sqlite3_stmt sqlite3_stmt;
32863303
32873304
/*
32883305
** CAPI3REF: Run-time Limits
3306
+** METHOD: sqlite3
32893307
**
32903308
** ^(This interface allows the size of various constructs to be limited
32913309
** on a connection by connection basis. The first parameter is the
32923310
** [database connection] whose limit is to be set or queried. The
32933311
** second parameter is one of the [limit categories] that define a
@@ -3395,10 +3413,12 @@
33953413
#define SQLITE_LIMIT_WORKER_THREADS 11
33963414
33973415
/*
33983416
** CAPI3REF: Compiling An SQL Statement
33993417
** KEYWORDS: {SQL statement compiler}
3418
+** METHOD: sqlite3
3419
+** CONSTRUCTOR: sqlite3_stmt
34003420
**
34013421
** To execute an SQL query, it must first be compiled into a byte-code
34023422
** program using one of these routines.
34033423
**
34043424
** The first argument, "db", is a [database connection] obtained from a
@@ -3502,19 +3522,21 @@
35023522
const void **pzTail /* OUT: Pointer to unused portion of zSql */
35033523
);
35043524
35053525
/*
35063526
** CAPI3REF: Retrieving Statement SQL
3527
+** METHOD: sqlite3_stmt
35073528
**
35083529
** ^This interface can be used to retrieve a saved copy of the original
35093530
** SQL text used to create a [prepared statement] if that statement was
35103531
** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
35113532
*/
35123533
SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
35133534
35143535
/*
35153536
** CAPI3REF: Determine If An SQL Statement Writes The Database
3537
+** METHOD: sqlite3_stmt
35163538
**
35173539
** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
35183540
** and only if the [prepared statement] X makes no direct changes to
35193541
** the content of the database file.
35203542
**
@@ -3542,10 +3564,11 @@
35423564
*/
35433565
SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
35443566
35453567
/*
35463568
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3569
+** METHOD: sqlite3_stmt
35473570
**
35483571
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
35493572
** [prepared statement] S has been stepped at least once using
35503573
** [sqlite3_step(S)] but has not run to completion and/or has not
35513574
** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3616,10 +3639,11 @@
36163639
36173640
/*
36183641
** CAPI3REF: Binding Values To Prepared Statements
36193642
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
36203643
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3644
+** METHOD: sqlite3_stmt
36213645
**
36223646
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
36233647
** literals may be replaced by a [parameter] that matches one of following
36243648
** templates:
36253649
**
@@ -3734,10 +3758,11 @@
37343758
SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
37353759
SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
37363760
37373761
/*
37383762
** CAPI3REF: Number Of SQL Parameters
3763
+** METHOD: sqlite3_stmt
37393764
**
37403765
** ^This routine can be used to find the number of [SQL parameters]
37413766
** in a [prepared statement]. SQL parameters are tokens of the
37423767
** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
37433768
** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3754,10 +3779,11 @@
37543779
*/
37553780
SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
37563781
37573782
/*
37583783
** CAPI3REF: Name Of A Host Parameter
3784
+** METHOD: sqlite3_stmt
37593785
**
37603786
** ^The sqlite3_bind_parameter_name(P,N) interface returns
37613787
** the name of the N-th [SQL parameter] in the [prepared statement] P.
37623788
** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
37633789
** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3781,10 +3807,11 @@
37813807
*/
37823808
SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
37833809
37843810
/*
37853811
** CAPI3REF: Index Of A Parameter With A Given Name
3812
+** METHOD: sqlite3_stmt
37863813
**
37873814
** ^Return the index of an SQL parameter given its name. ^The
37883815
** index value returned is suitable for use as the second
37893816
** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
37903817
** is returned if no matching parameter is found. ^The parameter
@@ -3797,19 +3824,21 @@
37973824
*/
37983825
SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
37993826
38003827
/*
38013828
** CAPI3REF: Reset All Bindings On A Prepared Statement
3829
+** METHOD: sqlite3_stmt
38023830
**
38033831
** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
38043832
** the [sqlite3_bind_blob | bindings] on a [prepared statement].
38053833
** ^Use this routine to reset all host parameters to NULL.
38063834
*/
38073835
SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
38083836
38093837
/*
38103838
** CAPI3REF: Number Of Columns In A Result Set
3839
+** METHOD: sqlite3_stmt
38113840
**
38123841
** ^Return the number of columns in the result set returned by the
38133842
** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
38143843
** statement that does not return data (for example an [UPDATE]).
38153844
**
@@ -3817,10 +3846,11 @@
38173846
*/
38183847
SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
38193848
38203849
/*
38213850
** CAPI3REF: Column Names In A Result Set
3851
+** METHOD: sqlite3_stmt
38223852
**
38233853
** ^These routines return the name assigned to a particular column
38243854
** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
38253855
** interface returns a pointer to a zero-terminated UTF-8 string
38263856
** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3846,10 +3876,11 @@
38463876
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
38473877
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
38483878
38493879
/*
38503880
** CAPI3REF: Source Of Data In A Query Result
3881
+** METHOD: sqlite3_stmt
38513882
**
38523883
** ^These routines provide a means to determine the database, table, and
38533884
** table column that is the origin of a particular result column in
38543885
** [SELECT] statement.
38553886
** ^The name of the database or table or column can be returned as
@@ -3898,10 +3929,11 @@
38983929
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
38993930
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
39003931
39013932
/*
39023933
** CAPI3REF: Declared Datatype Of A Query Result
3934
+** METHOD: sqlite3_stmt
39033935
**
39043936
** ^(The first parameter is a [prepared statement].
39053937
** If this statement is a [SELECT] statement and the Nth column of the
39063938
** returned result set of that [SELECT] is a table column (not an
39073939
** expression or subquery) then the declared type of the table
@@ -3930,10 +3962,11 @@
39303962
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
39313963
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
39323964
39333965
/*
39343966
** CAPI3REF: Evaluate An SQL Statement
3967
+** METHOD: sqlite3_stmt
39353968
**
39363969
** After a [prepared statement] has been prepared using either
39373970
** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
39383971
** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
39393972
** must be called one or more times to evaluate the statement.
@@ -4009,10 +4042,11 @@
40094042
*/
40104043
SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
40114044
40124045
/*
40134046
** CAPI3REF: Number of columns in a result set
4047
+** METHOD: sqlite3_stmt
40144048
**
40154049
** ^The sqlite3_data_count(P) interface returns the number of columns in the
40164050
** current row of the result set of [prepared statement] P.
40174051
** ^If prepared statement P does not have results ready to return
40184052
** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -4062,10 +4096,11 @@
40624096
#define SQLITE3_TEXT 3
40634097
40644098
/*
40654099
** CAPI3REF: Result Values From A Query
40664100
** KEYWORDS: {column access functions}
4101
+** METHOD: sqlite3_stmt
40674102
**
40684103
** These routines form the "result set" interface.
40694104
**
40704105
** ^These routines return information about a single column of the current
40714106
** result row of a query. ^In every case the first argument is a pointer
@@ -4234,10 +4269,11 @@
42344269
SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
42354270
SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
42364271
42374272
/*
42384273
** CAPI3REF: Destroy A Prepared Statement Object
4274
+** DESTRUCTOR: sqlite3_stmt
42394275
**
42404276
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
42414277
** ^If the most recent evaluation of the statement encountered no errors
42424278
** or if the statement is never been evaluated, then sqlite3_finalize() returns
42434279
** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4261,10 +4297,11 @@
42614297
*/
42624298
SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
42634299
42644300
/*
42654301
** CAPI3REF: Reset A Prepared Statement Object
4302
+** METHOD: sqlite3_stmt
42664303
**
42674304
** The sqlite3_reset() function is called to reset a [prepared statement]
42684305
** object back to its initial state, ready to be re-executed.
42694306
** ^Any SQL statement variables that had values bound to them using
42704307
** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4290,10 +4327,11 @@
42904327
/*
42914328
** CAPI3REF: Create Or Redefine SQL Functions
42924329
** KEYWORDS: {function creation routines}
42934330
** KEYWORDS: {application-defined SQL function}
42944331
** KEYWORDS: {application-defined SQL functions}
4332
+** METHOD: sqlite3
42954333
**
42964334
** ^These functions (collectively known as "function creation routines")
42974335
** are used to add SQL functions or aggregates or to redefine the behavior
42984336
** of existing SQL functions or aggregates. The only differences between
42994337
** these routines are the text encoding expected for
@@ -4459,10 +4497,11 @@
44594497
void*,sqlite3_int64);
44604498
#endif
44614499
44624500
/*
44634501
** CAPI3REF: Obtaining SQL Function Parameter Values
4502
+** METHOD: sqlite3_value
44644503
**
44654504
** The C-language implementation of SQL functions and aggregates uses
44664505
** this set of interface routines to access the parameter values on
44674506
** the function or aggregate.
44684507
**
@@ -4517,10 +4556,11 @@
45174556
SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
45184557
SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
45194558
45204559
/*
45214560
** CAPI3REF: Obtain Aggregate Function Context
4561
+** METHOD: sqlite3_context
45224562
**
45234563
** Implementations of aggregate SQL functions use this
45244564
** routine to allocate memory for storing their state.
45254565
**
45264566
** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4561,10 +4601,11 @@
45614601
*/
45624602
SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
45634603
45644604
/*
45654605
** CAPI3REF: User Data For Functions
4606
+** METHOD: sqlite3_context
45664607
**
45674608
** ^The sqlite3_user_data() interface returns a copy of
45684609
** the pointer that was the pUserData parameter (the 5th parameter)
45694610
** of the [sqlite3_create_function()]
45704611
** and [sqlite3_create_function16()] routines that originally
@@ -4575,10 +4616,11 @@
45754616
*/
45764617
SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
45774618
45784619
/*
45794620
** CAPI3REF: Database Connection For Functions
4621
+** METHOD: sqlite3_context
45804622
**
45814623
** ^The sqlite3_context_db_handle() interface returns a copy of
45824624
** the pointer to the [database connection] (the 1st parameter)
45834625
** of the [sqlite3_create_function()]
45844626
** and [sqlite3_create_function16()] routines that originally
@@ -4586,10 +4628,11 @@
45864628
*/
45874629
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
45884630
45894631
/*
45904632
** CAPI3REF: Function Auxiliary Data
4633
+** METHOD: sqlite3_context
45914634
**
45924635
** These functions may be used by (non-aggregate) SQL functions to
45934636
** associate metadata with argument values. If the same value is passed to
45944637
** multiple invocations of the same SQL function during query execution, under
45954638
** some circumstances the associated metadata may be preserved. An example
@@ -4658,10 +4701,11 @@
46584701
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
46594702
#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
46604703
46614704
/*
46624705
** CAPI3REF: Setting The Result Of An SQL Function
4706
+** METHOD: sqlite3_context
46634707
**
46644708
** These routines are used by the xFunc or xFinal callbacks that
46654709
** implement SQL functions and aggregates. See
46664710
** [sqlite3_create_function()] and [sqlite3_create_function16()]
46674711
** for additional information.
@@ -4793,10 +4837,11 @@
47934837
SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
47944838
SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
47954839
47964840
/*
47974841
** CAPI3REF: Define New Collating Sequences
4842
+** METHOD: sqlite3
47984843
**
47994844
** ^These functions add, remove, or modify a [collation] associated
48004845
** with the [database connection] specified as the first argument.
48014846
**
48024847
** ^The name of the collation is a UTF-8 string
@@ -4895,10 +4940,11 @@
48954940
int(*xCompare)(void*,int,const void*,int,const void*)
48964941
);
48974942
48984943
/*
48994944
** CAPI3REF: Collation Needed Callbacks
4945
+** METHOD: sqlite3
49004946
**
49014947
** ^To avoid having to register all collation sequences before a database
49024948
** can be used, a single callback function may be registered with the
49034949
** [database connection] to be invoked whenever an undefined collation
49044950
** sequence is required.
@@ -5102,10 +5148,11 @@
51025148
SQLITE_API char *sqlite3_data_directory;
51035149
51045150
/*
51055151
** CAPI3REF: Test For Auto-Commit Mode
51065152
** KEYWORDS: {autocommit mode}
5153
+** METHOD: sqlite3
51075154
**
51085155
** ^The sqlite3_get_autocommit() interface returns non-zero or
51095156
** zero if the given database connection is or is not in autocommit mode,
51105157
** respectively. ^Autocommit mode is on by default.
51115158
** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -5124,10 +5171,11 @@
51245171
*/
51255172
SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
51265173
51275174
/*
51285175
** CAPI3REF: Find The Database Handle Of A Prepared Statement
5176
+** METHOD: sqlite3_stmt
51295177
**
51305178
** ^The sqlite3_db_handle interface returns the [database connection] handle
51315179
** to which a [prepared statement] belongs. ^The [database connection]
51325180
** returned by sqlite3_db_handle is the same [database connection]
51335181
** that was the first argument
@@ -5136,10 +5184,11 @@
51365184
*/
51375185
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
51385186
51395187
/*
51405188
** CAPI3REF: Return The Filename For A Database Connection
5189
+** METHOD: sqlite3
51415190
**
51425191
** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
51435192
** associated with database N of connection D. ^The main database file
51445193
** has the name "main". If there is no attached database N on the database
51455194
** connection D, or if database N is a temporary or in-memory database, then
@@ -5152,19 +5201,21 @@
51525201
*/
51535202
SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
51545203
51555204
/*
51565205
** CAPI3REF: Determine if a database is read-only
5206
+** METHOD: sqlite3
51575207
**
51585208
** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
51595209
** of connection D is read-only, 0 if it is read/write, or -1 if N is not
51605210
** the name of a database on connection D.
51615211
*/
51625212
SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
51635213
51645214
/*
51655215
** CAPI3REF: Find the next prepared statement
5216
+** METHOD: sqlite3
51665217
**
51675218
** ^This interface returns a pointer to the next [prepared statement] after
51685219
** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
51695220
** then this interface returns a pointer to the first prepared statement
51705221
** associated with the database connection pDb. ^If no prepared statement
@@ -5176,10 +5227,11 @@
51765227
*/
51775228
SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
51785229
51795230
/*
51805231
** CAPI3REF: Commit And Rollback Notification Callbacks
5232
+** METHOD: sqlite3
51815233
**
51825234
** ^The sqlite3_commit_hook() interface registers a callback
51835235
** function to be invoked whenever a transaction is [COMMIT | committed].
51845236
** ^Any callback set by a previous call to sqlite3_commit_hook()
51855237
** for the same database connection is overridden.
@@ -5225,10 +5277,11 @@
52255277
SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
52265278
SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
52275279
52285280
/*
52295281
** CAPI3REF: Data Change Notification Callbacks
5282
+** METHOD: sqlite3
52305283
**
52315284
** ^The sqlite3_update_hook() interface registers a callback function
52325285
** with the [database connection] identified by the first argument
52335286
** to be invoked whenever a row is updated, inserted or deleted in
52345287
** a rowid table.
@@ -5331,10 +5384,11 @@
53315384
*/
53325385
SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
53335386
53345387
/*
53355388
** CAPI3REF: Free Memory Used By A Database Connection
5389
+** METHOD: sqlite3
53365390
**
53375391
** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
53385392
** memory as possible from database connection D. Unlike the
53395393
** [sqlite3_release_memory()] interface, this interface is in effect even
53405394
** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5408,10 +5462,11 @@
54085462
SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
54095463
54105464
54115465
/*
54125466
** CAPI3REF: Extract Metadata About A Column Of A Table
5467
+** METHOD: sqlite3
54135468
**
54145469
** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
54155470
** information about column C of table T in database D
54165471
** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
54175472
** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5486,10 +5541,11 @@
54865541
int *pAutoinc /* OUTPUT: True if column is auto-increment */
54875542
);
54885543
54895544
/*
54905545
** CAPI3REF: Load An Extension
5546
+** METHOD: sqlite3
54915547
**
54925548
** ^This interface loads an SQLite extension library from the named file.
54935549
**
54945550
** ^The sqlite3_load_extension() interface attempts to load an
54955551
** [SQLite extension] library contained in the file zFile. If
@@ -5527,10 +5583,11 @@
55275583
char **pzErrMsg /* Put error message here if not 0 */
55285584
);
55295585
55305586
/*
55315587
** CAPI3REF: Enable Or Disable Extension Loading
5588
+** METHOD: sqlite3
55325589
**
55335590
** ^So as not to open security holes in older applications that are
55345591
** unprepared to deal with [extension loading], and as a means of disabling
55355592
** [extension loading] while evaluating user-entered SQL, the following API
55365593
** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5776,10 +5833,11 @@
57765833
#define SQLITE_INDEX_CONSTRAINT_GE 32
57775834
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
57785835
57795836
/*
57805837
** CAPI3REF: Register A Virtual Table Implementation
5838
+** METHOD: sqlite3
57815839
**
57825840
** ^These routines are used to register a new [virtual table module] name.
57835841
** ^Module names must be registered before
57845842
** creating a new [virtual table] using the module and before using a
57855843
** preexisting [virtual table] for the module.
@@ -5872,10 +5930,11 @@
58725930
*/
58735931
SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
58745932
58755933
/*
58765934
** CAPI3REF: Overload A Function For A Virtual Table
5935
+** METHOD: sqlite3
58775936
**
58785937
** ^(Virtual tables can provide alternative implementations of functions
58795938
** using the [xFindFunction] method of the [virtual table module].
58805939
** But global versions of those functions
58815940
** must exist in order to be overloaded.)^
@@ -5914,10 +5973,12 @@
59145973
*/
59155974
typedef struct sqlite3_blob sqlite3_blob;
59165975
59175976
/*
59185977
** CAPI3REF: Open A BLOB For Incremental I/O
5978
+** METHOD: sqlite3
5979
+** CONSTRUCTOR: sqlite3_blob
59195980
**
59205981
** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
59215982
** in row iRow, column zColumn, table zTable in database zDb;
59225983
** in other words, the same BLOB that would be selected by:
59235984
**
@@ -5995,10 +6056,11 @@
59956056
sqlite3_blob **ppBlob
59966057
);
59976058
59986059
/*
59996060
** CAPI3REF: Move a BLOB Handle to a New Row
6061
+** METHOD: sqlite3_blob
60006062
**
60016063
** ^This function is used to move an existing blob handle so that it points
60026064
** to a different row of the same database table. ^The new row is identified
60036065
** by the rowid value passed as the second argument. Only the row can be
60046066
** changed. ^The database, table and column on which the blob handle is open
@@ -6019,10 +6081,11 @@
60196081
*/
60206082
SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
60216083
60226084
/*
60236085
** CAPI3REF: Close A BLOB Handle
6086
+** DESTRUCTOR: sqlite3_blob
60246087
**
60256088
** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
60266089
** unconditionally. Even if this routine returns an error code, the
60276090
** handle is still closed.)^
60286091
**
@@ -6041,10 +6104,11 @@
60416104
*/
60426105
SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
60436106
60446107
/*
60456108
** CAPI3REF: Return The Size Of An Open BLOB
6109
+** METHOD: sqlite3_blob
60466110
**
60476111
** ^Returns the size in bytes of the BLOB accessible via the
60486112
** successfully opened [BLOB handle] in its only argument. ^The
60496113
** incremental blob I/O routines can only read or overwriting existing
60506114
** blob content; they cannot change the size of a blob.
@@ -6056,10 +6120,11 @@
60566120
*/
60576121
SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
60586122
60596123
/*
60606124
** CAPI3REF: Read Data From A BLOB Incrementally
6125
+** METHOD: sqlite3_blob
60616126
**
60626127
** ^(This function is used to read data from an open [BLOB handle] into a
60636128
** caller-supplied buffer. N bytes of data are copied into buffer Z
60646129
** from the open BLOB, starting at offset iOffset.)^
60656130
**
@@ -6084,10 +6149,11 @@
60846149
*/
60856150
SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
60866151
60876152
/*
60886153
** CAPI3REF: Write Data Into A BLOB Incrementally
6154
+** METHOD: sqlite3_blob
60896155
**
60906156
** ^(This function is used to write data into an open [BLOB handle] from a
60916157
** caller-supplied buffer. N bytes of data are copied from the buffer Z
60926158
** into the open BLOB, starting at offset iOffset.)^
60936159
**
@@ -6411,10 +6477,11 @@
64116477
#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
64126478
#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
64136479
64146480
/*
64156481
** CAPI3REF: Retrieve the mutex for a database connection
6482
+** METHOD: sqlite3
64166483
**
64176484
** ^This interface returns a pointer the [sqlite3_mutex] object that
64186485
** serializes access to the [database connection] given in the argument
64196486
** when the [threading mode] is Serialized.
64206487
** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6422,10 +6489,11 @@
64226489
*/
64236490
SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
64246491
64256492
/*
64266493
** CAPI3REF: Low-Level Control Of Database Files
6494
+** METHOD: sqlite3
64276495
**
64286496
** ^The [sqlite3_file_control()] interface makes a direct call to the
64296497
** xFileControl method for the [sqlite3_io_methods] object associated
64306498
** with a particular database identified by the second argument. ^The
64316499
** name of the database is "main" for the main database or "temp" for the
@@ -6638,10 +6706,11 @@
66386706
#define SQLITE_STATUS_SCRATCH_SIZE 8
66396707
#define SQLITE_STATUS_MALLOC_COUNT 9
66406708
66416709
/*
66426710
** CAPI3REF: Database Connection Status
6711
+** METHOD: sqlite3
66436712
**
66446713
** ^This interface is used to retrieve runtime status information
66456714
** about a single [database connection]. ^The first argument is the
66466715
** database connection object to be interrogated. ^The second argument
66476716
** is an integer constant, taken from the set of
@@ -6766,10 +6835,11 @@
67666835
#define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
67676836
67686837
67696838
/*
67706839
** CAPI3REF: Prepared Statement Status
6840
+** METHOD: sqlite3_stmt
67716841
**
67726842
** ^(Each prepared statement maintains various
67736843
** [SQLITE_STMTSTATUS counters] that measure the number
67746844
** of times it has performed specific operations.)^ These counters can
67756845
** be used to monitor the performance characteristics of the prepared
@@ -7269,10 +7339,11 @@
72697339
SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
72707340
SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
72717341
72727342
/*
72737343
** CAPI3REF: Unlock Notification
7344
+** METHOD: sqlite3
72747345
**
72757346
** ^When running in shared-cache mode, a database operation may fail with
72767347
** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
72777348
** individual tables within the shared-cache cannot be obtained. See
72787349
** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7439,10 +7510,11 @@
74397510
*/
74407511
SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
74417512
74427513
/*
74437514
** CAPI3REF: Write-Ahead Log Commit Hook
7515
+** METHOD: sqlite3
74447516
**
74457517
** ^The [sqlite3_wal_hook()] function is used to register a callback that
74467518
** is invoked each time data is committed to a database in wal mode.
74477519
**
74487520
** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7478,10 +7550,11 @@
74787550
void*
74797551
);
74807552
74817553
/*
74827554
** CAPI3REF: Configure an auto-checkpoint
7555
+** METHOD: sqlite3
74837556
**
74847557
** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
74857558
** [sqlite3_wal_hook()] that causes any database on [database connection] D
74867559
** to automatically [checkpoint]
74877560
** after committing a transaction if there are N or
@@ -7508,10 +7581,11 @@
75087581
*/
75097582
SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
75107583
75117584
/*
75127585
** CAPI3REF: Checkpoint a database
7586
+** METHOD: sqlite3
75137587
**
75147588
** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
75157589
** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
75167590
**
75177591
** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7529,10 +7603,11 @@
75297603
*/
75307604
SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
75317605
75327606
/*
75337607
** CAPI3REF: Checkpoint a database
7608
+** METHOD: sqlite3
75347609
**
75357610
** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
75367611
** operation on database X of [database connection] D in mode M. Status
75377612
** information is written back into integers pointed to by L and C.)^
75387613
** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7783,10 +7858,11 @@
77837858
#define SQLITE_SCANSTAT_EXPLAIN 4
77847859
#define SQLITE_SCANSTAT_SELECTID 5
77857860
77867861
/*
77877862
** CAPI3REF: Prepared Statement Scan Status
7863
+** METHOD: sqlite3_stmt
77887864
**
77897865
** This interface returns information about the predicted and measured
77907866
** performance for pStmt. Advanced applications can use this
77917867
** interface to compare the predicted and the measured performance and
77927868
** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7820,10 +7896,11 @@
78207896
void *pOut /* Result written here */
78217897
);
78227898
78237899
/*
78247900
** CAPI3REF: Zero Scan-Status Counters
7901
+** METHOD: sqlite3_stmt
78257902
**
78267903
** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
78277904
**
78287905
** This API is only available if the library is built with pre-processor
78297906
** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
@@ -8430,10 +8507,36 @@
84308507
#else
84318508
# define ALWAYS(X) (X)
84328509
# define NEVER(X) (X)
84338510
#endif
84348511
8512
+/*
8513
+** Declarations used for tracing the operating system interfaces.
8514
+*/
8515
+#if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \
8516
+ (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
8517
+ extern int sqlite3OSTrace;
8518
+# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
8519
+# define SQLITE_HAVE_OS_TRACE
8520
+#else
8521
+# define OSTRACE(X)
8522
+# undef SQLITE_HAVE_OS_TRACE
8523
+#endif
8524
+
8525
+/*
8526
+** Is the sqlite3ErrName() function needed in the build? Currently,
8527
+** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when
8528
+** OSTRACE is enabled), and by several "test*.c" files (which are
8529
+** compiled using SQLITE_TEST).
8530
+*/
8531
+#if defined(SQLITE_HAVE_OS_TRACE) || defined(SQLITE_TEST) || \
8532
+ (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
8533
+# define SQLITE_NEED_ERR_NAME
8534
+#else
8535
+# undef SQLITE_NEED_ERR_NAME
8536
+#endif
8537
+
84358538
/*
84368539
** Return true (non-zero) if the input is an integer that is too large
84378540
** to fit in 32-bits. This macro is used inside of various testcase()
84388541
** macros to verify that we have tested SQLite for large-file support.
84398542
*/
@@ -9841,37 +9944,36 @@
98419944
/* Properties such as "out2" or "jump" that are specified in
98429945
** comments following the "case" for each opcode in the vdbe.c
98439946
** are encoded into bitvectors as follows:
98449947
*/
98459948
#define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */
9846
-#define OPFLG_OUT2_PRERELEASE 0x0002 /* out2-prerelease: */
9847
-#define OPFLG_IN1 0x0004 /* in1: P1 is an input */
9848
-#define OPFLG_IN2 0x0008 /* in2: P2 is an input */
9849
-#define OPFLG_IN3 0x0010 /* in3: P3 is an input */
9850
-#define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
9851
-#define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9949
+#define OPFLG_IN1 0x0002 /* in1: P1 is an input */
9950
+#define OPFLG_IN2 0x0004 /* in2: P2 is an input */
9951
+#define OPFLG_IN3 0x0008 /* in3: P3 is an input */
9952
+#define OPFLG_OUT2 0x0010 /* out2: P2 is an output */
9953
+#define OPFLG_OUT3 0x0020 /* out3: P3 is an output */
98529954
#define OPFLG_INITIALIZER {\
98539955
/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9854
-/* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
9855
-/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\
9856
-/* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\
9857
-/* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\
9858
-/* 40 */ 0x04, 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00,\
9859
-/* 48 */ 0x00, 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00,\
9860
-/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,\
9861
-/* 64 */ 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11, 0x4c,\
9862
-/* 72 */ 0x4c, 0x02, 0x02, 0x00, 0x05, 0x05, 0x15, 0x15,\
9863
-/* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
9864
-/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9865
-/* 96 */ 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,\
9866
-/* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08, 0x00,\
9867
-/* 112 */ 0x02, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00,\
9868
-/* 120 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9869
-/* 128 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x02, 0x00, 0x01,\
9870
-/* 136 */ 0x08, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x01,\
9956
+/* 8 */ 0x01, 0x01, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
9957
+/* 16 */ 0x01, 0x01, 0x02, 0x12, 0x01, 0x02, 0x03, 0x08,\
9958
+/* 24 */ 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10,\
9959
+/* 32 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x03, 0x02,\
9960
+/* 40 */ 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00,\
9961
+/* 48 */ 0x00, 0x00, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,\
9962
+/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09,\
9963
+/* 64 */ 0x09, 0x09, 0x04, 0x09, 0x09, 0x09, 0x09, 0x26,\
9964
+/* 72 */ 0x26, 0x10, 0x10, 0x00, 0x03, 0x03, 0x0b, 0x0b,\
9965
+/* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x26, 0x26, 0x26,\
9966
+/* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
9967
+/* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
9968
+/* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04, 0x00,\
9969
+/* 112 */ 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00, 0x00,\
9970
+/* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9971
+/* 128 */ 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00, 0x01,\
9972
+/* 136 */ 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x01,\
98719973
/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\
9872
-/* 152 */ 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,}
9974
+/* 152 */ 0x00, 0x10, 0x10, 0x01, 0x00, 0x00,}
98739975
98749976
/************** End of opcodes.h *********************************************/
98759977
/************** Continuing where we left off in vdbe.h ***********************/
98769978
98779979
/*
@@ -9926,10 +10028,11 @@
992610028
#endif
992710029
SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
992810030
992910031
SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
993010032
SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
10033
+SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
993110034
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
993210035
993310036
typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
993410037
SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
993510038
@@ -11063,10 +11166,11 @@
1106311166
#define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
1106411167
#define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
1106511168
#define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
1106611169
#define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
1106711170
#define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
11171
+#define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */
1106811172
1106911173
1107011174
/*
1107111175
** Bits of the sqlite3.dbOptFlags field that are used by the
1107211176
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -11393,38 +11497,12 @@
1139311497
int iSavepoint; /* Depth of the SAVEPOINT stack */
1139411498
VTable *pNext; /* Next in linked list (see above) */
1139511499
};
1139611500
1139711501
/*
11398
-** Each SQL table is represented in memory by an instance of the
11399
-** following structure.
11400
-**
11401
-** Table.zName is the name of the table. The case of the original
11402
-** CREATE TABLE statement is stored, but case is not significant for
11403
-** comparisons.
11404
-**
11405
-** Table.nCol is the number of columns in this table. Table.aCol is a
11406
-** pointer to an array of Column structures, one for each column.
11407
-**
11408
-** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
11409
-** the column that is that key. Otherwise Table.iPKey is negative. Note
11410
-** that the datatype of the PRIMARY KEY must be INTEGER for this field to
11411
-** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of
11412
-** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid
11413
-** is generated for each row of the table. TF_HasPrimaryKey is set if
11414
-** the table has any PRIMARY KEY, INTEGER or otherwise.
11415
-**
11416
-** Table.tnum is the page number for the root BTree page of the table in the
11417
-** database file. If Table.iDb is the index of the database table backend
11418
-** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
11419
-** holds temporary tables and indices. If TF_Ephemeral is set
11420
-** then the table is stored in a file that is automatically deleted
11421
-** when the VDBE cursor to the table is closed. In this case Table.tnum
11422
-** refers VDBE cursor number that holds the table open, not to the root
11423
-** page number. Transient tables are used to hold the results of a
11424
-** sub-query that appears instead of a real table name in the FROM clause
11425
-** of a SELECT statement.
11502
+** The schema for each SQL table and view is represented in memory
11503
+** by an instance of the following structure.
1142611504
*/
1142711505
struct Table {
1142811506
char *zName; /* Name of the table or view */
1142911507
Column *aCol; /* Information about each column */
1143011508
Index *pIndex; /* List of SQL indexes on this table. */
@@ -11432,15 +11510,15 @@
1143211510
FKey *pFKey; /* Linked list of all foreign keys in this table */
1143311511
char *zColAff; /* String defining the affinity of each column */
1143411512
#ifndef SQLITE_OMIT_CHECK
1143511513
ExprList *pCheck; /* All CHECK constraints */
1143611514
#endif
11437
- LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
11438
- int tnum; /* Root BTree node for this table (see note above) */
11439
- i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */
11515
+ int tnum; /* Root BTree page for this table */
11516
+ i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
1144011517
i16 nCol; /* Number of columns in this table */
1144111518
u16 nRef; /* Number of pointers to this Table */
11519
+ LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
1144211520
LogEst szTabRow; /* Estimated size of each table row in bytes */
1144311521
#ifdef SQLITE_ENABLE_COSTMULT
1144411522
LogEst costMult; /* Cost multiplier for using this table */
1144511523
#endif
1144611524
u8 tabFlags; /* Mask of TF_* values */
@@ -11458,17 +11536,24 @@
1145811536
Table *pNextZombie; /* Next on the Parse.pZombieTab list */
1145911537
};
1146011538
1146111539
/*
1146211540
** Allowed values for Table.tabFlags.
11541
+**
11542
+** TF_OOOHidden applies to virtual tables that have hidden columns that are
11543
+** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING
11544
+** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden,
11545
+** the TF_OOOHidden attribute would apply in this case. Such tables require
11546
+** special handling during INSERT processing.
1146311547
*/
1146411548
#define TF_Readonly 0x01 /* Read-only system table */
1146511549
#define TF_Ephemeral 0x02 /* An ephemeral table */
1146611550
#define TF_HasPrimaryKey 0x04 /* Table has a primary key */
1146711551
#define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
1146811552
#define TF_Virtual 0x10 /* Is a virtual table */
1146911553
#define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */
11554
+#define TF_OOOHidden 0x40 /* Out-of-Order hidden columns */
1147011555
1147111556
1147211557
/*
1147311558
** Test to see whether or not a table is a virtual table. This is
1147411559
** done as a macro so that it will be optimized out when virtual
@@ -12221,11 +12306,11 @@
1222112306
#define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
1222212307
#define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
1222312308
#define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
1222412309
#define SF_Compound 0x0040 /* Part of a compound query */
1222512310
#define SF_Values 0x0080 /* Synthesized from VALUES clause */
12226
-#define SF_AllValues 0x0100 /* All terms of compound are VALUES */
12311
+#define SF_MultiValue 0x0100 /* Single VALUES term with multiple rows */
1222712312
#define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
1222812313
#define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
1222912314
#define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
1223012315
#define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
1223112316
#define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */
@@ -12605,24 +12690,24 @@
1260512690
*
1260612691
* (op == TK_INSERT)
1260712692
* orconf -> stores the ON CONFLICT algorithm
1260812693
* pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
1260912694
* this stores a pointer to the SELECT statement. Otherwise NULL.
12610
- * target -> A token holding the quoted name of the table to insert into.
12695
+ * zTarget -> Dequoted name of the table to insert into.
1261112696
* pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
1261212697
* this stores values to be inserted. Otherwise NULL.
1261312698
* pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
1261412699
* statement, then this stores the column-names to be
1261512700
* inserted into.
1261612701
*
1261712702
* (op == TK_DELETE)
12618
- * target -> A token holding the quoted name of the table to delete from.
12703
+ * zTarget -> Dequoted name of the table to delete from.
1261912704
* pWhere -> The WHERE clause of the DELETE statement if one is specified.
1262012705
* Otherwise NULL.
1262112706
*
1262212707
* (op == TK_UPDATE)
12623
- * target -> A token holding the quoted name of the table to update rows of.
12708
+ * zTarget -> Dequoted name of the table to update.
1262412709
* pWhere -> The WHERE clause of the UPDATE statement if one is specified.
1262512710
* Otherwise NULL.
1262612711
* pExprList -> A list of the columns to update and the expressions to update
1262712712
* them to. See sqlite3Update() documentation of "pChanges"
1262812713
* argument.
@@ -12630,12 +12715,12 @@
1263012715
*/
1263112716
struct TriggerStep {
1263212717
u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
1263312718
u8 orconf; /* OE_Rollback etc. */
1263412719
Trigger *pTrig; /* The trigger that this step is a part of */
12635
- Select *pSelect; /* SELECT statment or RHS of INSERT INTO .. SELECT ... */
12636
- Token target; /* Target table for DELETE, UPDATE, INSERT */
12720
+ Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */
12721
+ char *zTarget; /* Target table for DELETE, UPDATE, INSERT */
1263712722
Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
1263812723
ExprList *pExprList; /* SET clause for UPDATE. */
1263912724
IdList *pIdList; /* Column names for INSERT */
1264012725
TriggerStep *pNext; /* Next in the link-list */
1264112726
TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
@@ -12664,12 +12749,11 @@
1266412749
sqlite3 *db; /* Optional database for lookaside. Can be NULL */
1266512750
char *zBase; /* A base allocation. Not from malloc. */
1266612751
char *zText; /* The string collected so far */
1266712752
int nChar; /* Length of the string so far */
1266812753
int nAlloc; /* Amount of space allocated in zText */
12669
- int mxAlloc; /* Maximum allowed string length */
12670
- u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */
12754
+ int mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
1267112755
u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
1267212756
};
1267312757
#define STRACCUM_NOMEM 1
1267412758
#define STRACCUM_TOOBIG 2
1267512759
@@ -12982,11 +13066,11 @@
1298213066
SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
1298313067
SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
1298413068
SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
1298513069
SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
1298613070
SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
12987
-#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
13071
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
1298813072
SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
1298913073
#endif
1299013074
#if defined(SQLITE_TEST)
1299113075
SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
1299213076
#endif
@@ -13329,11 +13413,11 @@
1332913413
SQLITE_PRIVATE void sqlite3Error(sqlite3*,int);
1333013414
SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
1333113415
SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
1333213416
SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
1333313417
13334
-#if defined(SQLITE_TEST)
13418
+#if defined(SQLITE_NEED_ERR_NAME)
1333513419
SQLITE_PRIVATE const char *sqlite3ErrName(int);
1333613420
#endif
1333713421
1333813422
SQLITE_PRIVATE const char *sqlite3ErrStr(int);
1333913423
SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -13423,11 +13507,11 @@
1342313507
FuncDestructor *pDestructor
1342413508
);
1342513509
SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
1342613510
SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
1342713511
13428
-SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
13512
+SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
1342913513
SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
1343013514
SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
1343113515
SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char);
1343213516
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
1343313517
SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
@@ -14039,10 +14123,13 @@
1403914123
#if SQLITE_ENABLE_CEROD
1404014124
"ENABLE_CEROD",
1404114125
#endif
1404214126
#if SQLITE_ENABLE_COLUMN_METADATA
1404314127
"ENABLE_COLUMN_METADATA",
14128
+#endif
14129
+#if SQLITE_ENABLE_DBSTAT_VTAB
14130
+ "ENABLE_DBSTAT_VTAB",
1404414131
#endif
1404514132
#if SQLITE_ENABLE_EXPENSIVE_ASSERT
1404614133
"ENABLE_EXPENSIVE_ASSERT",
1404714134
#endif
1404814135
#if SQLITE_ENABLE_FTS1
@@ -19807,20 +19894,10 @@
1980719894
*/
1980819895
#ifdef MEMORY_DEBUG
1980919896
# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
1981019897
#endif
1981119898
19812
-#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
19813
-# ifndef SQLITE_DEBUG_OS_TRACE
19814
-# define SQLITE_DEBUG_OS_TRACE 0
19815
-# endif
19816
- int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
19817
-# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
19818
-#else
19819
-# define OSTRACE(X)
19820
-#endif
19821
-
1982219899
/*
1982319900
** Macros for performance tracing. Normally turned off. Only works
1982419901
** on i486 hardware.
1982519902
*/
1982619903
#ifdef SQLITE_PERFORMANCE_TRACE
@@ -21401,10 +21478,11 @@
2140121478
2140221479
/*
2140321480
** Set the StrAccum object to an error mode.
2140421481
*/
2140521482
static void setStrAccumError(StrAccum *p, u8 eError){
21483
+ assert( eError==STRACCUM_NOMEM || eError==STRACCUM_TOOBIG );
2140621484
p->accError = eError;
2140721485
p->nAlloc = 0;
2140821486
}
2140921487
2141021488
/*
@@ -21515,11 +21593,10 @@
2151521593
case '0': flag_zeropad = 1; break;
2151621594
default: done = 1; break;
2151721595
}
2151821596
}while( !done && (c=(*++fmt))!=0 );
2151921597
/* Get the field width */
21520
- width = 0;
2152121598
if( c=='*' ){
2152221599
if( bArgList ){
2152321600
width = (int)getIntArg(pArgList);
2152421601
}else{
2152521602
width = va_arg(ap,int);
@@ -21539,11 +21616,10 @@
2153921616
width = wx & 0x7fffffff;
2154021617
}
2154121618
2154221619
/* Get the precision */
2154321620
if( c=='.' ){
21544
- precision = 0;
2154521621
c = *++fmt;
2154621622
if( c=='*' ){
2154721623
if( bArgList ){
2154821624
precision = (int)getIntArg(pArgList);
2154921625
}else{
@@ -22018,11 +22094,11 @@
2201822094
if( p->accError ){
2201922095
testcase(p->accError==STRACCUM_TOOBIG);
2202022096
testcase(p->accError==STRACCUM_NOMEM);
2202122097
return 0;
2202222098
}
22023
- if( !p->useMalloc ){
22099
+ if( p->mxAlloc==0 ){
2202422100
N = p->nAlloc - p->nChar - 1;
2202522101
setStrAccumError(p, STRACCUM_TOOBIG);
2202622102
return N;
2202722103
}else{
2202822104
char *zOld = (p->zText==p->zBase ? 0 : p->zText);
@@ -22038,14 +22114,14 @@
2203822114
setStrAccumError(p, STRACCUM_TOOBIG);
2203922115
return 0;
2204022116
}else{
2204122117
p->nAlloc = (int)szNew;
2204222118
}
22043
- if( p->useMalloc==1 ){
22119
+ if( p->db ){
2204422120
zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
2204522121
}else{
22046
- zNew = sqlite3_realloc(zOld, p->nAlloc);
22122
+ zNew = sqlite3_realloc64(zOld, p->nAlloc);
2204722123
}
2204822124
if( zNew ){
2204922125
assert( p->zText!=0 || p->nChar==0 );
2205022126
if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
2205122127
p->zText = zNew;
@@ -22089,11 +22165,11 @@
2208922165
/*
2209022166
** Append N bytes of text from z to the StrAccum object. Increase the
2209122167
** size of the memory allocation for StrAccum if necessary.
2209222168
*/
2209322169
SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
22094
- assert( z!=0 );
22170
+ assert( z!=0 || N==0 );
2209522171
assert( p->zText!=0 || p->nChar==0 || p->accError );
2209622172
assert( N>=0 );
2209722173
assert( p->accError==0 || p->nAlloc==0 );
2209822174
if( p->nChar+N >= p->nAlloc ){
2209922175
enlargeAndAppend(p,z,N);
@@ -22118,16 +22194,12 @@
2211822194
** pointer if any kind of error was encountered.
2211922195
*/
2212022196
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
2212122197
if( p->zText ){
2212222198
p->zText[p->nChar] = 0;
22123
- if( p->useMalloc && p->zText==p->zBase ){
22124
- if( p->useMalloc==1 ){
22125
- p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
22126
- }else{
22127
- p->zText = sqlite3_malloc(p->nChar+1);
22128
- }
22199
+ if( p->mxAlloc>0 && p->zText==p->zBase ){
22200
+ p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
2212922201
if( p->zText ){
2213022202
memcpy(p->zText, p->zBase, p->nChar+1);
2213122203
}else{
2213222204
setStrAccumError(p, STRACCUM_NOMEM);
2213322205
}
@@ -22139,29 +22211,35 @@
2213922211
/*
2214022212
** Reset an StrAccum string. Reclaim all malloced memory.
2214122213
*/
2214222214
SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
2214322215
if( p->zText!=p->zBase ){
22144
- if( p->useMalloc==1 ){
22145
- sqlite3DbFree(p->db, p->zText);
22146
- }else{
22147
- sqlite3_free(p->zText);
22148
- }
22216
+ sqlite3DbFree(p->db, p->zText);
2214922217
}
2215022218
p->zText = 0;
2215122219
}
2215222220
2215322221
/*
22154
-** Initialize a string accumulator
22222
+** Initialize a string accumulator.
22223
+**
22224
+** p: The accumulator to be initialized.
22225
+** db: Pointer to a database connection. May be NULL. Lookaside
22226
+** memory is used if not NULL. db->mallocFailed is set appropriately
22227
+** when not NULL.
22228
+** zBase: An initial buffer. May be NULL in which case the initial buffer
22229
+** is malloced.
22230
+** n: Size of zBase in bytes. If total space requirements never exceed
22231
+** n then no memory allocations ever occur.
22232
+** mx: Maximum number of bytes to accumulate. If mx==0 then no memory
22233
+** allocations will ever occur.
2215522234
*/
22156
-SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){
22235
+SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){
2215722236
p->zText = p->zBase = zBase;
22158
- p->db = 0;
22237
+ p->db = db;
2215922238
p->nChar = 0;
2216022239
p->nAlloc = n;
2216122240
p->mxAlloc = mx;
22162
- p->useMalloc = 1;
2216322241
p->accError = 0;
2216422242
}
2216522243
2216622244
/*
2216722245
** Print into memory obtained from sqliteMalloc(). Use the internal
@@ -22170,13 +22248,12 @@
2217022248
SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
2217122249
char *z;
2217222250
char zBase[SQLITE_PRINT_BUF_SIZE];
2217322251
StrAccum acc;
2217422252
assert( db!=0 );
22175
- sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
22253
+ sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase),
2217622254
db->aLimit[SQLITE_LIMIT_LENGTH]);
22177
- acc.db = db;
2217822255
sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap);
2217922256
z = sqlite3StrAccumFinish(&acc);
2218022257
if( acc.accError==STRACCUM_NOMEM ){
2218122258
db->mallocFailed = 1;
2218222259
}
@@ -22230,12 +22307,11 @@
2223022307
}
2223122308
#endif
2223222309
#ifndef SQLITE_OMIT_AUTOINIT
2223322310
if( sqlite3_initialize() ) return 0;
2223422311
#endif
22235
- sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
22236
- acc.useMalloc = 2;
22312
+ sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
2223722313
sqlite3VXPrintf(&acc, 0, zFormat, ap);
2223822314
z = sqlite3StrAccumFinish(&acc);
2223922315
return z;
2224022316
}
2224122317
@@ -22276,12 +22352,11 @@
2227622352
(void)SQLITE_MISUSE_BKPT;
2227722353
if( zBuf ) zBuf[0] = 0;
2227822354
return zBuf;
2227922355
}
2228022356
#endif
22281
- sqlite3StrAccumInit(&acc, zBuf, n, 0);
22282
- acc.useMalloc = 0;
22357
+ sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
2228322358
sqlite3VXPrintf(&acc, 0, zFormat, ap);
2228422359
return sqlite3StrAccumFinish(&acc);
2228522360
}
2228622361
SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
2228722362
char *z;
@@ -22303,12 +22378,11 @@
2230322378
*/
2230422379
static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
2230522380
StrAccum acc; /* String accumulator */
2230622381
char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
2230722382
22308
- sqlite3StrAccumInit(&acc, zMsg, sizeof(zMsg), 0);
22309
- acc.useMalloc = 0;
22383
+ sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0);
2231022384
sqlite3VXPrintf(&acc, 0, zFormat, ap);
2231122385
sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
2231222386
sqlite3StrAccumFinish(&acc));
2231322387
}
2231422388
@@ -22322,22 +22396,21 @@
2232222396
renderLogMsg(iErrCode, zFormat, ap);
2232322397
va_end(ap);
2232422398
}
2232522399
}
2232622400
22327
-#if defined(SQLITE_DEBUG)
22401
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
2232822402
/*
2232922403
** A version of printf() that understands %lld. Used for debugging.
2233022404
** The printf() built into some versions of windows does not understand %lld
2233122405
** and segfaults if you give it a long long int.
2233222406
*/
2233322407
SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){
2233422408
va_list ap;
2233522409
StrAccum acc;
2233622410
char zBuf[500];
22337
- sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
22338
- acc.useMalloc = 0;
22411
+ sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
2233922412
va_start(ap,zFormat);
2234022413
sqlite3VXPrintf(&acc, 0, zFormat, ap);
2234122414
va_end(ap);
2234222415
sqlite3StrAccumFinish(&acc);
2234322416
fprintf(stdout,"%s", zBuf);
@@ -22360,11 +22433,11 @@
2236022433
*/
2236122434
/* Add a new subitem to the tree. The moreToFollow flag indicates that this
2236222435
** is not the last item in the tree. */
2236322436
SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){
2236422437
if( p==0 ){
22365
- p = sqlite3_malloc( sizeof(*p) );
22438
+ p = sqlite3_malloc64( sizeof(*p) );
2236622439
if( p==0 ) return 0;
2236722440
memset(p, 0, sizeof(*p));
2236822441
}else{
2236922442
p->iLevel++;
2237022443
}
@@ -22383,12 +22456,11 @@
2238322456
SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
2238422457
va_list ap;
2238522458
int i;
2238622459
StrAccum acc;
2238722460
char zBuf[500];
22388
- sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
22389
- acc.useMalloc = 0;
22461
+ sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
2239022462
if( p ){
2239122463
for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
2239222464
sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
2239322465
}
2239422466
sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
@@ -24007,10 +24079,11 @@
2400724079
}else{
2400824080
return 0;
2400924081
}
2401024082
}
2401124083
#endif
24084
+ while( zNum[0]=='0' ) zNum++;
2401224085
for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
2401324086
v = v*10 + c;
2401424087
}
2401524088
2401624089
/* The longest decimal representation of a 32 bit integer is 10 digits:
@@ -25261,10 +25334,21 @@
2526125334
#if SQLITE_ENABLE_LOCKING_STYLE
2526225335
# include <sys/ioctl.h>
2526325336
# include <sys/file.h>
2526425337
# include <sys/param.h>
2526525338
#endif /* SQLITE_ENABLE_LOCKING_STYLE */
25339
+
25340
+#if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
25341
+ (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
25342
+# if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \
25343
+ && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))
25344
+# define HAVE_GETHOSTUUID 1
25345
+# else
25346
+# warning "gethostuuid() is disabled."
25347
+# endif
25348
+#endif
25349
+
2526625350
2526725351
#if OS_VXWORKS
2526825352
/* # include <sys/ioctl.h> */
2526925353
# include <semaphore.h>
2527025354
# include <limits.h>
@@ -25457,20 +25541,10 @@
2545725541
*/
2545825542
#ifdef MEMORY_DEBUG
2545925543
# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
2546025544
#endif
2546125545
25462
-#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
25463
-# ifndef SQLITE_DEBUG_OS_TRACE
25464
-# define SQLITE_DEBUG_OS_TRACE 0
25465
-# endif
25466
- int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
25467
-# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
25468
-#else
25469
-# define OSTRACE(X)
25470
-#endif
25471
-
2547225546
/*
2547325547
** Macros for performance tracing. Normally turned off. Only works
2547425548
** on i486 hardware.
2547525549
*/
2547625550
#ifdef SQLITE_PERFORMANCE_TRACE
@@ -26009,11 +26083,11 @@
2600926083
return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
2601026084
}
2601126085
#endif
2601226086
2601326087
26014
-#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
26088
+#ifdef SQLITE_HAVE_OS_TRACE
2601526089
/*
2601626090
** Helper function for printing out trace information from debugging
2601726091
** binaries. This returns the string representation of the supplied
2601826092
** integer lock-type.
2601926093
*/
@@ -26272,11 +26346,11 @@
2627226346
struct vxworksFileId *pCandidate; /* For looping over existing file IDs */
2627326347
int n; /* Length of zAbsoluteName string */
2627426348
2627526349
assert( zAbsoluteName[0]=='/' );
2627626350
n = (int)strlen(zAbsoluteName);
26277
- pNew = sqlite3_malloc( sizeof(*pNew) + (n+1) );
26351
+ pNew = sqlite3_malloc64( sizeof(*pNew) + (n+1) );
2627826352
if( pNew==0 ) return 0;
2627926353
pNew->zCanonicalName = (char*)&pNew[1];
2628026354
memcpy(pNew->zCanonicalName, zAbsoluteName, n+1);
2628126355
n = vxworksSimplifyName(pNew->zCanonicalName, n);
2628226356
@@ -26676,11 +26750,11 @@
2667626750
pInode = inodeList;
2667726751
while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
2667826752
pInode = pInode->pNext;
2667926753
}
2668026754
if( pInode==0 ){
26681
- pInode = sqlite3_malloc( sizeof(*pInode) );
26755
+ pInode = sqlite3_malloc64( sizeof(*pInode) );
2668226756
if( pInode==0 ){
2668326757
return SQLITE_NOMEM;
2668426758
}
2668526759
memset(pInode, 0, sizeof(*pInode));
2668626760
memcpy(&pInode->fileId, &fileId, sizeof(fileId));
@@ -29197,11 +29271,11 @@
2919729271
case SQLITE_FCNTL_VFSNAME: {
2919829272
*(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
2919929273
return SQLITE_OK;
2920029274
}
2920129275
case SQLITE_FCNTL_TEMPFILENAME: {
29202
- char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname );
29276
+ char *zTFile = sqlite3_malloc64( pFile->pVfs->mxPathname );
2920329277
if( zTFile ){
2920429278
unixGetTempname(pFile->pVfs->mxPathname, zTFile);
2920529279
*(char**)pArg = zTFile;
2920629280
}
2920729281
return SQLITE_OK;
@@ -29638,11 +29712,11 @@
2963829712
unixInodeInfo *pInode; /* The inode of fd */
2963929713
char *zShmFilename; /* Name of the file used for SHM */
2964029714
int nShmFilename; /* Size of the SHM filename in bytes */
2964129715
2964229716
/* Allocate space for the new unixShm object. */
29643
- p = sqlite3_malloc( sizeof(*p) );
29717
+ p = sqlite3_malloc64( sizeof(*p) );
2964429718
if( p==0 ) return SQLITE_NOMEM;
2964529719
memset(p, 0, sizeof(*p));
2964629720
assert( pDbFd->pShm==0 );
2964729721
2964829722
/* Check to see if a unixShmNode object already exists. Reuse an existing
@@ -29669,11 +29743,11 @@
2966929743
#ifdef SQLITE_SHM_DIRECTORY
2967029744
nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
2967129745
#else
2967229746
nShmFilename = 6 + (int)strlen(zBasePath);
2967329747
#endif
29674
- pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
29748
+ pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename );
2967529749
if( pShmNode==0 ){
2967629750
rc = SQLITE_NOMEM;
2967729751
goto shm_open_err;
2967829752
}
2967929753
memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
@@ -29879,11 +29953,11 @@
2987929953
if( pMem==MAP_FAILED ){
2988029954
rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
2988129955
goto shmpage_out;
2988229956
}
2988329957
}else{
29884
- pMem = sqlite3_malloc(szRegion);
29958
+ pMem = sqlite3_malloc64(szRegion);
2988529959
if( pMem==0 ){
2988629960
rc = SQLITE_NOMEM;
2988729961
goto shmpage_out;
2988829962
}
2988929963
memset(pMem, 0, szRegion);
@@ -30716,11 +30790,11 @@
3071630790
else if( pLockingStyle == &afpIoMethods ){
3071730791
/* AFP locking uses the file path so it needs to be included in
3071830792
** the afpLockingContext.
3071930793
*/
3072030794
afpLockingContext *pCtx;
30721
- pNew->lockingContext = pCtx = sqlite3_malloc( sizeof(*pCtx) );
30795
+ pNew->lockingContext = pCtx = sqlite3_malloc64( sizeof(*pCtx) );
3072230796
if( pCtx==0 ){
3072330797
rc = SQLITE_NOMEM;
3072430798
}else{
3072530799
/* NB: zFilename exists and remains valid until the file is closed
3072630800
** according to requirement F11141. So we do not need to make a
@@ -30746,11 +30820,11 @@
3074630820
*/
3074730821
char *zLockFile;
3074830822
int nFilename;
3074930823
assert( zFilename!=0 );
3075030824
nFilename = (int)strlen(zFilename) + 6;
30751
- zLockFile = (char *)sqlite3_malloc(nFilename);
30825
+ zLockFile = (char *)sqlite3_malloc64(nFilename);
3075230826
if( zLockFile==0 ){
3075330827
rc = SQLITE_NOMEM;
3075430828
}else{
3075530829
sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename);
3075630830
}
@@ -31123,11 +31197,11 @@
3112331197
UnixUnusedFd *pUnused;
3112431198
pUnused = findReusableFd(zName, flags);
3112531199
if( pUnused ){
3112631200
fd = pUnused->fd;
3112731201
}else{
31128
- pUnused = sqlite3_malloc(sizeof(*pUnused));
31202
+ pUnused = sqlite3_malloc64(sizeof(*pUnused));
3112931203
if( !pUnused ){
3113031204
return SQLITE_NOMEM;
3113131205
}
3113231206
}
3113331207
p->pUnused = pUnused;
@@ -31503,11 +31577,11 @@
3150331577
** that we always use the same random number sequence. This makes the
3150431578
** tests repeatable.
3150531579
*/
3150631580
memset(zBuf, 0, nBuf);
3150731581
randomnessPid = osGetpid(0);
31508
-#if !defined(SQLITE_TEST)
31582
+#if !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS)
3150931583
{
3151031584
int fd, got;
3151131585
fd = robust_open("/dev/urandom", O_RDONLY, 0);
3151231586
if( fd<0 ){
3151331587
time_t t;
@@ -31915,11 +31989,11 @@
3191531989
*/
3191631990
pUnused = findReusableFd(path, openFlags);
3191731991
if( pUnused ){
3191831992
fd = pUnused->fd;
3191931993
}else{
31920
- pUnused = sqlite3_malloc(sizeof(*pUnused));
31994
+ pUnused = sqlite3_malloc64(sizeof(*pUnused));
3192131995
if( !pUnused ){
3192231996
return SQLITE_NOMEM;
3192331997
}
3192431998
}
3192531999
if( fd<0 ){
@@ -31948,11 +32022,11 @@
3194832022
default:
3194932023
return SQLITE_CANTOPEN_BKPT;
3195032024
}
3195132025
}
3195232026
31953
- pNew = (unixFile *)sqlite3_malloc(sizeof(*pNew));
32027
+ pNew = (unixFile *)sqlite3_malloc64(sizeof(*pNew));
3195432028
if( pNew==NULL ){
3195532029
rc = SQLITE_NOMEM;
3195632030
goto end_create_proxy;
3195732031
}
3195832032
memset(pNew, 0, sizeof(unixFile));
@@ -31981,21 +32055,22 @@
3198132055
SQLITE_API int sqlite3_hostid_num = 0;
3198232056
#endif
3198332057
3198432058
#define PROXY_HOSTIDLEN 16 /* conch file host id length */
3198532059
32060
+#ifdef HAVE_GETHOSTUUID
3198632061
/* Not always defined in the headers as it ought to be */
3198732062
extern int gethostuuid(uuid_t id, const struct timespec *wait);
32063
+#endif
3198832064
3198932065
/* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
3199032066
** bytes of writable memory.
3199132067
*/
3199232068
static int proxyGetHostID(unsigned char *pHostID, int *pError){
3199332069
assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
3199432070
memset(pHostID, 0, PROXY_HOSTIDLEN);
31995
-# if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
31996
- (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
32071
+#ifdef HAVE_GETHOSTUUID
3199732072
{
3199832073
struct timespec timeout = {1, 0}; /* 1 sec timeout */
3199932074
if( gethostuuid(pHostID, &timeout) ){
3200032075
int err = errno;
3200132076
if( pError ){
@@ -32409,11 +32484,11 @@
3240932484
return rc;
3241032485
}
3241132486
3241232487
/*
3241332488
** Given the name of a database file, compute the name of its conch file.
32414
-** Store the conch filename in memory obtained from sqlite3_malloc().
32489
+** Store the conch filename in memory obtained from sqlite3_malloc64().
3241532490
** Make *pConchPath point to the new name. Return SQLITE_OK on success
3241632491
** or SQLITE_NOMEM if unable to obtain memory.
3241732492
**
3241832493
** The caller is responsible for ensuring that the allocated memory
3241932494
** space is eventually freed.
@@ -32425,11 +32500,11 @@
3242532500
int len = (int)strlen(dbPath); /* Length of database filename - dbPath */
3242632501
char *conchPath; /* buffer in which to construct conch name */
3242732502
3242832503
/* Allocate space for the conch filename and initialize the name to
3242932504
** the name of the original database file. */
32430
- *pConchPath = conchPath = (char *)sqlite3_malloc(len + 8);
32505
+ *pConchPath = conchPath = (char *)sqlite3_malloc64(len + 8);
3243132506
if( conchPath==0 ){
3243232507
return SQLITE_NOMEM;
3243332508
}
3243432509
memcpy(conchPath, dbPath, len+1);
3243532510
@@ -32541,11 +32616,11 @@
3254132616
}
3254232617
3254332618
OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
3254432619
(lockPath ? lockPath : ":auto:"), osGetpid(0)));
3254532620
32546
- pCtx = sqlite3_malloc( sizeof(*pCtx) );
32621
+ pCtx = sqlite3_malloc64( sizeof(*pCtx) );
3254732622
if( pCtx==0 ){
3254832623
return SQLITE_NOMEM;
3254932624
}
3255032625
memset(pCtx, 0, sizeof(*pCtx));
3255132626
@@ -32985,20 +33060,10 @@
3298533060
*/
3298633061
#ifdef MEMORY_DEBUG
3298733062
# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
3298833063
#endif
3298933064
32990
-#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
32991
-# ifndef SQLITE_DEBUG_OS_TRACE
32992
-# define SQLITE_DEBUG_OS_TRACE 0
32993
-# endif
32994
- int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
32995
-# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
32996
-#else
32997
-# define OSTRACE(X)
32998
-#endif
32999
-
3300033065
/*
3300133066
** Macros for performance tracing. Normally turned off. Only works
3300233067
** on i486 hardware.
3300333068
*/
3300433069
#ifdef SQLITE_PERFORMANCE_TRACE
@@ -35898,11 +35963,11 @@
3589835963
** Used only when SQLITE_NO_SYNC is not defined.
3589935964
*/
3590035965
BOOL rc;
3590135966
#endif
3590235967
#if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \
35903
- (defined(SQLITE_TEST) && defined(SQLITE_DEBUG))
35968
+ defined(SQLITE_HAVE_OS_TRACE)
3590435969
/*
3590535970
** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or
3590635971
** OSTRACE() macros.
3590735972
*/
3590835973
winFile *pFile = (winFile*)id;
@@ -36575,11 +36640,11 @@
3657536640
DWORD lastErrno; /* The Windows errno from the last I/O error */
3657636641
3657736642
int nRef; /* Number of winShm objects pointing to this */
3657836643
winShm *pFirst; /* All winShm objects pointing to this */
3657936644
winShmNode *pNext; /* Next in list of all winShmNode objects */
36580
-#ifdef SQLITE_DEBUG
36645
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
3658136646
u8 nextShmId; /* Next available winShm.id value */
3658236647
#endif
3658336648
};
3658436649
3658536650
/*
@@ -36606,11 +36671,11 @@
3660636671
winShmNode *pShmNode; /* The underlying winShmNode object */
3660736672
winShm *pNext; /* Next winShm with the same winShmNode */
3660836673
u8 hasMutex; /* True if holding the winShmNode mutex */
3660936674
u16 sharedMask; /* Mask of shared locks held */
3661036675
u16 exclMask; /* Mask of exclusive locks held */
36611
-#ifdef SQLITE_DEBUG
36676
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
3661236677
u8 id; /* Id of this connection with its winShmNode */
3661336678
#endif
3661436679
};
3661536680
3661636681
/*
@@ -36797,11 +36862,11 @@
3679736862
if( rc ) goto shm_open_err;
3679836863
}
3679936864
3680036865
/* Make the new connection a child of the winShmNode */
3680136866
p->pShmNode = pShmNode;
36802
-#ifdef SQLITE_DEBUG
36867
+#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
3680336868
p->id = pShmNode->nextShmId++;
3680436869
#endif
3680536870
pShmNode->nRef++;
3680636871
pDbFd->pShm = p;
3680736872
winShmLeaveMutex();
@@ -37066,11 +37131,11 @@
3706637131
goto shmpage_out;
3706737132
}
3706837133
}
3706937134
3707037135
/* Map the requested memory region into this processes address space. */
37071
- apNew = (struct ShmRegion *)sqlite3_realloc(
37136
+ apNew = (struct ShmRegion *)sqlite3_realloc64(
3707237137
pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
3707337138
);
3707437139
if( !apNew ){
3707537140
rc = SQLITE_IOERR_NOMEM;
3707637141
goto shmpage_out;
@@ -38513,11 +38578,11 @@
3851338578
** Write up to nBuf bytes of randomness into zBuf.
3851438579
*/
3851538580
static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
3851638581
int n = 0;
3851738582
UNUSED_PARAMETER(pVfs);
38518
-#if defined(SQLITE_TEST)
38583
+#if defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS)
3851938584
n = nBuf;
3852038585
memset(zBuf, 0, nBuf);
3852138586
#else
3852238587
if( sizeof(SYSTEMTIME)<=nBuf-n ){
3852338588
SYSTEMTIME x;
@@ -38547,11 +38612,10 @@
3854738612
LARGE_INTEGER i;
3854838613
osQueryPerformanceCounter(&i);
3854938614
memcpy(&zBuf[n], &i, sizeof(i));
3855038615
n += sizeof(i);
3855138616
}
38552
-#endif
3855338617
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
3855438618
if( sizeof(UUID)<=nBuf-n ){
3855538619
UUID id;
3855638620
memset(&id, 0, sizeof(UUID));
3855738621
osUuidCreate(&id);
@@ -38564,10 +38628,11 @@
3856438628
osUuidCreateSequential(&id);
3856538629
memcpy(zBuf, &id, sizeof(UUID));
3856638630
n += sizeof(UUID);
3856738631
}
3856838632
#endif
38633
+#endif /* defined(SQLITE_TEST) || defined(SQLITE_ZERO_PRNG_SEED) */
3856938634
return n;
3857038635
}
3857138636
3857238637
3857338638
/*
@@ -39118,11 +39183,11 @@
3911839183
3911939184
/* Allocate the Bitvec to be tested and a linear array of
3912039185
** bits to act as the reference */
3912139186
pBitvec = sqlite3BitvecCreate( sz );
3912239187
pV = sqlite3MallocZero( (sz+7)/8 + 1 );
39123
- pTmpSpace = sqlite3_malloc(BITVEC_SZ);
39188
+ pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
3912439189
if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
3912539190
3912639191
/* NULL pBitvec tests */
3912739192
sqlite3BitvecSet(0, 1);
3912839193
sqlite3BitvecClear(0, 1, pTmpSpace);
@@ -44607,13 +44672,11 @@
4460744672
Pgno nTruncate, /* Database size after this commit */
4460844673
int isCommit /* True if this is a commit */
4460944674
){
4461044675
int rc; /* Return code */
4461144676
int nList; /* Number of pages in pList */
44612
-#if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES)
4461344677
PgHdr *p; /* For looping over pages */
44614
-#endif
4461544678
4461644679
assert( pPager->pWal );
4461744680
assert( pList );
4461844681
#ifdef SQLITE_DEBUG
4461944682
/* Verify that the page list is in accending order */
@@ -44626,11 +44689,10 @@
4462644689
if( isCommit ){
4462744690
/* If a WAL transaction is being committed, there is no point in writing
4462844691
** any pages with page numbers greater than nTruncate into the WAL file.
4462944692
** They will never be read by any client. So remove them from the pDirty
4463044693
** list here. */
44631
- PgHdr *p;
4463244694
PgHdr **ppNext = &pList;
4463344695
nList = 0;
4463444696
for(p=pList; (*ppNext = p)!=0; p=p->pDirty){
4463544697
if( p->pgno<=nTruncate ){
4463644698
ppNext = &p->pDirty;
@@ -44646,11 +44708,10 @@
4464644708
if( pList->pgno==1 ) pager_write_changecounter(pList);
4464744709
rc = sqlite3WalFrames(pPager->pWal,
4464844710
pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags
4464944711
);
4465044712
if( rc==SQLITE_OK && pPager->pBackup ){
44651
- PgHdr *p;
4465244713
for(p=pList; p; p=p->pDirty){
4465344714
sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
4465444715
}
4465544716
}
4465644717
@@ -48577,10 +48638,12 @@
4857748638
}else if( state==PAGER_OPEN ){
4857848639
pager_unlock(pPager);
4857948640
}
4858048641
assert( state==pPager->eState );
4858148642
}
48643
+ }else if( eMode==PAGER_JOURNALMODE_OFF ){
48644
+ sqlite3OsClose(pPager->jfd);
4858248645
}
4858348646
}
4858448647
4858548648
/* Return the new journal mode */
4858648649
return (int)pPager->journalMode;
@@ -49359,11 +49422,11 @@
4935949422
4936049423
/* Enlarge the pWal->apWiData[] array if required */
4936149424
if( pWal->nWiData<=iPage ){
4936249425
int nByte = sizeof(u32*)*(iPage+1);
4936349426
volatile u32 **apNew;
49364
- apNew = (volatile u32 **)sqlite3_realloc((void *)pWal->apWiData, nByte);
49427
+ apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte);
4936549428
if( !apNew ){
4936649429
*ppPage = 0;
4936749430
return SQLITE_NOMEM;
4936849431
}
4936949432
memset((void*)&apNew[pWal->nWiData], 0,
@@ -49984,11 +50047,11 @@
4998450047
goto finished;
4998550048
}
4998650049
4998750050
/* Malloc a buffer to read frames into. */
4998850051
szFrame = szPage + WAL_FRAME_HDRSIZE;
49989
- aFrame = (u8 *)sqlite3_malloc(szFrame);
50052
+ aFrame = (u8 *)sqlite3_malloc64(szFrame);
4999050053
if( !aFrame ){
4999150054
rc = SQLITE_NOMEM;
4999250055
goto recovery_error;
4999350056
}
4999450057
aData = &aFrame[WAL_FRAME_HDRSIZE];
@@ -50377,21 +50440,21 @@
5037750440
/* Allocate space for the WalIterator object. */
5037850441
nSegment = walFramePage(iLast) + 1;
5037950442
nByte = sizeof(WalIterator)
5038050443
+ (nSegment-1)*sizeof(struct WalSegment)
5038150444
+ iLast*sizeof(ht_slot);
50382
- p = (WalIterator *)sqlite3_malloc(nByte);
50445
+ p = (WalIterator *)sqlite3_malloc64(nByte);
5038350446
if( !p ){
5038450447
return SQLITE_NOMEM;
5038550448
}
5038650449
memset(p, 0, nByte);
5038750450
p->nSegment = nSegment;
5038850451
5038950452
/* Allocate temporary space used by the merge-sort routine. This block
5039050453
** of memory will be freed before this function returns.
5039150454
*/
50392
- aTmp = (ht_slot *)sqlite3_malloc(
50455
+ aTmp = (ht_slot *)sqlite3_malloc64(
5039350456
sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
5039450457
);
5039550458
if( !aTmp ){
5039650459
rc = SQLITE_NOMEM;
5039750460
}
@@ -50567,10 +50630,18 @@
5056750630
** cannot be backfilled from the WAL.
5056850631
*/
5056950632
mxSafeFrame = pWal->hdr.mxFrame;
5057050633
mxPage = pWal->hdr.nPage;
5057150634
for(i=1; i<WAL_NREADER; i++){
50635
+ /* Thread-sanitizer reports that the following is an unsafe read,
50636
+ ** as some other thread may be in the process of updating the value
50637
+ ** of the aReadMark[] slot. The assumption here is that if that is
50638
+ ** happening, the other client may only be increasing the value,
50639
+ ** not decreasing it. So assuming either that either the "old" or
50640
+ ** "new" version of the value is read, and not some arbitrary value
50641
+ ** that would never be written by a real client, things are still
50642
+ ** safe. */
5057250643
u32 y = pInfo->aReadMark[i];
5057350644
if( mxSafeFrame>y ){
5057450645
assert( y<=pWal->hdr.mxFrame );
5057550646
rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
5057650647
if( rc==SQLITE_OK ){
@@ -55407,11 +55478,11 @@
5540755478
}
5540855479
assert( nReserve>=0 && nReserve<=255 );
5540955480
if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE &&
5541055481
((pageSize-1)&pageSize)==0 ){
5541155482
assert( (pageSize & 7)==0 );
55412
- assert( !pBt->pPage1 && !pBt->pCursor );
55483
+ assert( !pBt->pCursor );
5541355484
pBt->pageSize = (u32)pageSize;
5541455485
freeTempSpace(pBt);
5541555486
}
5541655487
rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve);
5541755488
pBt->usableSize = pBt->pageSize - (u16)nReserve;
@@ -57429,17 +57500,22 @@
5742957500
*/
5743057501
static const void *fetchPayload(
5743157502
BtCursor *pCur, /* Cursor pointing to entry to read from */
5743257503
u32 *pAmt /* Write the number of available bytes here */
5743357504
){
57505
+ u32 amt;
5743457506
assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
5743557507
assert( pCur->eState==CURSOR_VALID );
5743657508
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
5743757509
assert( cursorHoldsMutex(pCur) );
5743857510
assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
5743957511
assert( pCur->info.nSize>0 );
57440
- *pAmt = pCur->info.nLocal;
57512
+ assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
57513
+ assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
57514
+ amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
57515
+ if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
57516
+ *pAmt = amt;
5744157517
return (void*)pCur->info.pPayload;
5744257518
}
5744357519
5744457520
5744557521
/*
@@ -59713,11 +59789,10 @@
5971359789
if( iParentIdx==0 ){
5971459790
nxDiv = 0;
5971559791
}else if( iParentIdx==i ){
5971659792
nxDiv = i-2+bBulk;
5971759793
}else{
59718
- assert( bBulk==0 );
5971959794
nxDiv = iParentIdx-1;
5972059795
}
5972159796
i = 2-bBulk;
5972259797
}
5972359798
nOld = i+1;
@@ -61501,10 +61576,61 @@
6150161576
iPage = get4byte(pOvflData);
6150261577
sqlite3PagerUnref(pOvflPage);
6150361578
}
6150461579
}
6150561580
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
61581
+
61582
+/*
61583
+** An implementation of a min-heap.
61584
+**
61585
+** aHeap[0] is the number of elements on the heap. aHeap[1] is the
61586
+** root element. The daughter nodes of aHeap[N] are aHeap[N*2]
61587
+** and aHeap[N*2+1].
61588
+**
61589
+** The heap property is this: Every node is less than or equal to both
61590
+** of its daughter nodes. A consequence of the heap property is that the
61591
+** root node aHeap[1] is always the minimum value currently in the heap.
61592
+**
61593
+** The btreeHeapInsert() routine inserts an unsigned 32-bit number onto
61594
+** the heap, preserving the heap property. The btreeHeapPull() routine
61595
+** removes the root element from the heap (the minimum value in the heap)
61596
+** and then moves other nodes around as necessary to preserve the heap
61597
+** property.
61598
+**
61599
+** This heap is used for cell overlap and coverage testing. Each u32
61600
+** entry represents the span of a cell or freeblock on a btree page.
61601
+** The upper 16 bits are the index of the first byte of a range and the
61602
+** lower 16 bits are the index of the last byte of that range.
61603
+*/
61604
+static void btreeHeapInsert(u32 *aHeap, u32 x){
61605
+ u32 j, i = ++aHeap[0];
61606
+ aHeap[i] = x;
61607
+ while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){
61608
+ x = aHeap[j];
61609
+ aHeap[j] = aHeap[i];
61610
+ aHeap[i] = x;
61611
+ i = j;
61612
+ }
61613
+}
61614
+static int btreeHeapPull(u32 *aHeap, u32 *pOut){
61615
+ u32 j, i, x;
61616
+ if( (x = aHeap[0])==0 ) return 0;
61617
+ *pOut = aHeap[1];
61618
+ aHeap[1] = aHeap[x];
61619
+ aHeap[x] = 0xffffffff;
61620
+ aHeap[0]--;
61621
+ i = 1;
61622
+ while( (j = i*2)<=aHeap[0] ){
61623
+ if( aHeap[j]>aHeap[j+1] ) j++;
61624
+ if( aHeap[i]<aHeap[j] ) break;
61625
+ x = aHeap[i];
61626
+ aHeap[i] = aHeap[j];
61627
+ aHeap[j] = x;
61628
+ i = j;
61629
+ }
61630
+ return 1;
61631
+}
6150661632
6150761633
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
6150861634
/*
6150961635
** Do various sanity checks on a single page of a tree. Return
6151061636
** the tree depth. Root pages return 0. Parents of root pages
@@ -61534,11 +61660,12 @@
6153461660
int hdr, cellStart;
6153561661
int nCell;
6153661662
u8 *data;
6153761663
BtShared *pBt;
6153861664
int usableSize;
61539
- char *hit = 0;
61665
+ u32 *heap = 0;
61666
+ u32 x, prev = 0;
6154061667
i64 nMinKey = 0;
6154161668
i64 nMaxKey = 0;
6154261669
const char *saved_zPfx = pCheck->zPfx;
6154361670
int saved_v1 = pCheck->v1;
6154461671
int saved_v2 = pCheck->v2;
@@ -61679,19 +61806,19 @@
6167961806
6168061807
/* Check for complete coverage of the page
6168161808
*/
6168261809
data = pPage->aData;
6168361810
hdr = pPage->hdrOffset;
61684
- hit = sqlite3PageMalloc( pBt->pageSize );
61811
+ heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
6168561812
pCheck->zPfx = 0;
61686
- if( hit==0 ){
61813
+ if( heap==0 ){
6168761814
pCheck->mallocFailed = 1;
6168861815
}else{
6168961816
int contentOffset = get2byteNotZero(&data[hdr+5]);
6169061817
assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
61691
- memset(hit+contentOffset, 0, usableSize-contentOffset);
61692
- memset(hit, 1, contentOffset);
61818
+ heap[0] = 0;
61819
+ btreeHeapInsert(heap, contentOffset-1);
6169361820
/* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
6169461821
** number of cells on the page. */
6169561822
nCell = get2byte(&data[hdr+3]);
6169661823
/* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
6169761824
** immediately follows the b-tree page header. */
@@ -61699,20 +61826,19 @@
6169961826
/* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
6170061827
** integer offsets to the cell contents. */
6170161828
for(i=0; i<nCell; i++){
6170261829
int pc = get2byte(&data[cellStart+i*2]);
6170361830
u32 size = 65536;
61704
- int j;
6170561831
if( pc<=usableSize-4 ){
6170661832
size = cellSizePtr(pPage, &data[pc]);
6170761833
}
6170861834
if( (int)(pc+size-1)>=usableSize ){
6170961835
pCheck->zPfx = 0;
6171061836
checkAppendMsg(pCheck,
6171161837
"Corruption detected in cell %d on page %d",i,iPage);
6171261838
}else{
61713
- for(j=pc+size-1; j>=pc; j--) hit[j]++;
61839
+ btreeHeapInsert(heap, (pc<<16)|(pc+size-1));
6171461840
}
6171561841
}
6171661842
/* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
6171761843
** is the offset of the first freeblock, or zero if there are no
6171861844
** freeblocks on the page. */
@@ -61720,11 +61846,11 @@
6172061846
while( i>0 ){
6172161847
int size, j;
6172261848
assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */
6172361849
size = get2byte(&data[i+2]);
6172461850
assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */
61725
- for(j=i+size-1; j>=i; j--) hit[j]++;
61851
+ btreeHeapInsert(heap, (i<<16)|(i+size-1));
6172661852
/* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
6172761853
** big-endian integer which is the offset in the b-tree page of the next
6172861854
** freeblock in the chain, or zero if the freeblock is the last on the
6172961855
** chain. */
6173061856
j = get2byte(&data[i]);
@@ -61732,31 +61858,37 @@
6173261858
** increasing offset. */
6173361859
assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */
6173461860
assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */
6173561861
i = j;
6173661862
}
61737
- for(i=cnt=0; i<usableSize; i++){
61738
- if( hit[i]==0 ){
61739
- cnt++;
61740
- }else if( hit[i]>1 ){
61863
+ cnt = 0;
61864
+ assert( heap[0]>0 );
61865
+ assert( (heap[1]>>16)==0 );
61866
+ btreeHeapPull(heap,&prev);
61867
+ while( btreeHeapPull(heap,&x) ){
61868
+ if( (prev&0xffff)+1>(x>>16) ){
6174161869
checkAppendMsg(pCheck,
61742
- "Multiple uses for byte %d of page %d", i, iPage);
61870
+ "Multiple uses for byte %u of page %d", x>>16, iPage);
6174361871
break;
61872
+ }else{
61873
+ cnt += (x>>16) - (prev&0xffff) - 1;
61874
+ prev = x;
6174461875
}
6174561876
}
61877
+ cnt += usableSize - (prev&0xffff) - 1;
6174661878
/* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
6174761879
** is stored in the fifth field of the b-tree page header.
6174861880
** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
6174961881
** number of fragmented free bytes within the cell content area.
6175061882
*/
61751
- if( cnt!=data[hdr+7] ){
61883
+ if( heap[0]==0 && cnt!=data[hdr+7] ){
6175261884
checkAppendMsg(pCheck,
6175361885
"Fragmentation of %d bytes reported as %d on page %d",
6175461886
cnt, data[hdr+7], iPage);
6175561887
}
6175661888
}
61757
- sqlite3PageFree(hit);
61889
+ sqlite3PageFree(heap);
6175861890
releasePage(pPage);
6175961891
6176061892
end_of_check:
6176161893
pCheck->zPfx = saved_zPfx;
6176261894
pCheck->v1 = saved_v1;
@@ -61816,12 +61948,11 @@
6181661948
sqlite3BtreeLeave(p);
6181761949
return 0;
6181861950
}
6181961951
i = PENDING_BYTE_PAGE(pBt);
6182061952
if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
61821
- sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
61822
- sCheck.errMsg.useMalloc = 2;
61953
+ sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
6182361954
6182461955
/* Check the integrity of the freelist
6182561956
*/
6182661957
sCheck.zPfx = "Main freelist: ";
6182761958
checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
@@ -63153,14 +63284,15 @@
6315363284
return SQLITE_NOMEM;
6315463285
}
6315563286
pMem->z[pMem->n] = 0;
6315663287
pMem->z[pMem->n+1] = 0;
6315763288
pMem->flags |= MEM_Term;
63289
+ }
63290
+ pMem->flags &= ~MEM_Ephem;
6315863291
#ifdef SQLITE_DEBUG
63159
- pMem->pScopyFrom = 0;
63292
+ pMem->pScopyFrom = 0;
6316063293
#endif
63161
- }
6316263294
6316363295
return SQLITE_OK;
6316463296
}
6316563297
6316663298
/*
@@ -64600,11 +64732,11 @@
6460064732
int i;
6460164733
int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
6460264734
Mem *aMem = pRec->aMem;
6460364735
sqlite3 *db = aMem[0].db;
6460464736
for(i=0; i<nCol; i++){
64605
- if( aMem[i].szMalloc ) sqlite3DbFree(db, aMem[i].zMalloc);
64737
+ sqlite3VdbeMemRelease(&aMem[i]);
6460664738
}
6460764739
sqlite3KeyInfoUnref(pRec->pKeyInfo);
6460864740
sqlite3DbFree(db, pRec);
6460964741
}
6461064742
}
@@ -66436,18 +66568,35 @@
6643666568
pVtabCursor->pVtab->nRef--;
6643766569
pModule->xClose(pVtabCursor);
6643866570
}
6643966571
#endif
6644066572
}
66573
+
66574
+/*
66575
+** Close all cursors in the current frame.
66576
+*/
66577
+static void closeCursorsInFrame(Vdbe *p){
66578
+ if( p->apCsr ){
66579
+ int i;
66580
+ for(i=0; i<p->nCursor; i++){
66581
+ VdbeCursor *pC = p->apCsr[i];
66582
+ if( pC ){
66583
+ sqlite3VdbeFreeCursor(p, pC);
66584
+ p->apCsr[i] = 0;
66585
+ }
66586
+ }
66587
+ }
66588
+}
6644166589
6644266590
/*
6644366591
** Copy the values stored in the VdbeFrame structure to its Vdbe. This
6644466592
** is used, for example, when a trigger sub-program is halted to restore
6644566593
** control to the main program.
6644666594
*/
6644766595
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
6644866596
Vdbe *v = pFrame->v;
66597
+ closeCursorsInFrame(v);
6644966598
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
6645066599
v->anExec = pFrame->anExec;
6645166600
#endif
6645266601
v->aOnceFlag = pFrame->aOnceFlag;
6645366602
v->nOnceFlag = pFrame->nOnceFlag;
@@ -66478,21 +66627,11 @@
6647866627
sqlite3VdbeFrameRestore(pFrame);
6647966628
p->pFrame = 0;
6648066629
p->nFrame = 0;
6648166630
}
6648266631
assert( p->nFrame==0 );
66483
-
66484
- if( p->apCsr ){
66485
- int i;
66486
- for(i=0; i<p->nCursor; i++){
66487
- VdbeCursor *pC = p->apCsr[i];
66488
- if( pC ){
66489
- sqlite3VdbeFreeCursor(p, pC);
66490
- p->apCsr[i] = 0;
66491
- }
66492
- }
66493
- }
66632
+ closeCursorsInFrame(p);
6649466633
if( p->aMem ){
6649566634
releaseMemArray(&p->aMem[1], p->nMem);
6649666635
}
6649766636
while( p->pDelFrame ){
6649866637
VdbeFrame *pDel = p->pDelFrame;
@@ -68233,11 +68372,11 @@
6823368372
** If database corruption is discovered, set pPKey2->errCode to
6823468373
** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
6823568374
** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
6823668375
** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
6823768376
*/
68238
-static int vdbeRecordCompareWithSkip(
68377
+SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(
6823968378
int nKey1, const void *pKey1, /* Left key */
6824068379
UnpackedRecord *pPKey2, /* Right key */
6824168380
int bSkip /* If true, skip the first field */
6824268381
){
6824368382
u32 d1; /* Offset into aKey[] of next data element */
@@ -68419,11 +68558,11 @@
6841968558
}
6842068559
SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
6842168560
int nKey1, const void *pKey1, /* Left key */
6842268561
UnpackedRecord *pPKey2 /* Right key */
6842368562
){
68424
- return vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
68563
+ return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
6842568564
}
6842668565
6842768566
6842868567
/*
6842968568
** This function is an optimized version of sqlite3VdbeRecordCompare()
@@ -68507,11 +68646,11 @@
6850768646
}else if( v<lhs ){
6850868647
res = pPKey2->r2;
6850968648
}else if( pPKey2->nField>1 ){
6851068649
/* The first fields of the two keys are equal. Compare the trailing
6851168650
** fields. */
68512
- res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68651
+ res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
6851368652
}else{
6851468653
/* The first fields of the two keys are equal and there are no trailing
6851568654
** fields. Return pPKey2->default_rc in this case. */
6851668655
res = pPKey2->default_rc;
6851768656
}
@@ -68555,11 +68694,11 @@
6855568694
6855668695
if( res==0 ){
6855768696
res = nStr - pPKey2->aMem[0].n;
6855868697
if( res==0 ){
6855968698
if( pPKey2->nField>1 ){
68560
- res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68699
+ res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
6856168700
}else{
6856268701
res = pPKey2->default_rc;
6856368702
}
6856468703
}else if( res>0 ){
6856568704
res = pPKey2->r2;
@@ -70497,21 +70636,22 @@
7049770636
Mem *pVar; /* Value of a host parameter */
7049870637
StrAccum out; /* Accumulate the output here */
7049970638
char zBase[100]; /* Initial working space */
7050070639
7050170640
db = p->db;
70502
- sqlite3StrAccumInit(&out, zBase, sizeof(zBase),
70641
+ sqlite3StrAccumInit(&out, db, zBase, sizeof(zBase),
7050370642
db->aLimit[SQLITE_LIMIT_LENGTH]);
70504
- out.db = db;
7050570643
if( db->nVdbeExec>1 ){
7050670644
while( *zRawSql ){
7050770645
const char *zStart = zRawSql;
7050870646
while( *(zRawSql++)!='\n' && *zRawSql );
7050970647
sqlite3StrAccumAppend(&out, "-- ", 3);
7051070648
assert( (zRawSql - zStart) > 0 );
7051170649
sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
7051270650
}
70651
+ }else if( p->nVar==0 ){
70652
+ sqlite3StrAccumAppend(&out, zRawSql, sqlite3Strlen30(zRawSql));
7051370653
}else{
7051470654
while( zRawSql[0] ){
7051570655
n = findNextHostParameter(zRawSql, &nToken);
7051670656
assert( n>0 );
7051770657
sqlite3StrAccumAppend(&out, zRawSql, n);
@@ -70524,14 +70664,16 @@
7052470664
sqlite3GetInt32(&zRawSql[1], &idx);
7052570665
}else{
7052670666
idx = nextIndex;
7052770667
}
7052870668
}else{
70529
- assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' );
70669
+ assert( zRawSql[0]==':' || zRawSql[0]=='$' ||
70670
+ zRawSql[0]=='@' || zRawSql[0]=='#' );
7053070671
testcase( zRawSql[0]==':' );
7053170672
testcase( zRawSql[0]=='$' );
7053270673
testcase( zRawSql[0]=='@' );
70674
+ testcase( zRawSql[0]=='#' );
7053370675
idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken);
7053470676
assert( idx>0 );
7053570677
}
7053670678
zRawSql += nToken;
7053770679
nextIndex = idx + 1;
@@ -70895,10 +71037,11 @@
7089571037
** representation.
7089671038
*/
7089771039
if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
7089871040
sqlite3VdbeMemStringify(pRec, enc, 1);
7089971041
}
71042
+ pRec->flags &= ~(MEM_Real|MEM_Int);
7090071043
}
7090171044
}
7090271045
7090371046
/*
7090471047
** Try to convert the type of a function argument or a result column
@@ -71202,21 +71345,38 @@
7120271345
assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
7120371346
return 1;
7120471347
}
7120571348
#endif
7120671349
71350
+/*
71351
+** Return the register of pOp->p2 after first preparing it to be
71352
+** overwritten with an integer value.
71353
+*/
71354
+static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){
71355
+ Mem *pOut;
71356
+ assert( pOp->p2>0 );
71357
+ assert( pOp->p2<=(p->nMem-p->nCursor) );
71358
+ pOut = &p->aMem[pOp->p2];
71359
+ memAboutToChange(p, pOut);
71360
+ if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
71361
+ pOut->flags = MEM_Int;
71362
+ return pOut;
71363
+}
71364
+
7120771365
7120871366
/*
7120971367
** Execute as much of a VDBE program as we can.
7121071368
** This is the core of sqlite3_step().
7121171369
*/
7121271370
SQLITE_PRIVATE int sqlite3VdbeExec(
7121371371
Vdbe *p /* The VDBE */
7121471372
){
71215
- int pc=0; /* The program counter */
7121671373
Op *aOp = p->aOp; /* Copy of p->aOp */
71217
- Op *pOp; /* Current operation */
71374
+ Op *pOp = aOp; /* Current operation */
71375
+#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
71376
+ Op *pOrigOp; /* Value of pOp at the top of the loop */
71377
+#endif
7121871378
int rc = SQLITE_OK; /* Value to return */
7121971379
sqlite3 *db = p->db; /* The database */
7122071380
u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
7122171381
u8 encoding = ENC(db); /* The database encoding */
7122271382
int iCompare = 0; /* Result of last OP_Compare operation */
@@ -71288,27 +71448,26 @@
7128871448
}
7128971449
if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
7129071450
}
7129171451
sqlite3EndBenignMalloc();
7129271452
#endif
71293
- for(pc=p->pc; rc==SQLITE_OK; pc++){
71294
- assert( pc>=0 && pc<p->nOp );
71453
+ for(pOp=&aOp[p->pc]; rc==SQLITE_OK; pOp++){
71454
+ assert( pOp>=aOp && pOp<&aOp[p->nOp]);
7129571455
if( db->mallocFailed ) goto no_mem;
7129671456
#ifdef VDBE_PROFILE
7129771457
start = sqlite3Hwtime();
7129871458
#endif
7129971459
nVmStep++;
71300
- pOp = &aOp[pc];
7130171460
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
71302
- if( p->anExec ) p->anExec[pc]++;
71461
+ if( p->anExec ) p->anExec[(int)(pOp-aOp)]++;
7130371462
#endif
7130471463
7130571464
/* Only allow tracing if SQLITE_DEBUG is defined.
7130671465
*/
7130771466
#ifdef SQLITE_DEBUG
7130871467
if( db->flags & SQLITE_VdbeTrace ){
71309
- sqlite3VdbePrintOp(stdout, pc, pOp);
71468
+ sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp);
7131071469
}
7131171470
#endif
7131271471
7131371472
7131471473
/* Check to see if we need to simulate an interrupt. This only happens
@@ -71321,27 +71480,13 @@
7132171480
sqlite3_interrupt(db);
7132271481
}
7132371482
}
7132471483
#endif
7132571484
71326
- /* On any opcode with the "out2-prerelease" tag, free any
71327
- ** external allocations out of mem[p2] and set mem[p2] to be
71328
- ** an undefined integer. Opcodes will either fill in the integer
71329
- ** value or convert mem[p2] to a different type.
71330
- */
71331
- assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
71332
- if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){
71333
- assert( pOp->p2>0 );
71334
- assert( pOp->p2<=(p->nMem-p->nCursor) );
71335
- pOut = &aMem[pOp->p2];
71336
- memAboutToChange(p, pOut);
71337
- if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
71338
- pOut->flags = MEM_Int;
71339
- }
71340
-
7134171485
/* Sanity checking on other operands */
7134271486
#ifdef SQLITE_DEBUG
71487
+ assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
7134371488
if( (pOp->opflags & OPFLG_IN1)!=0 ){
7134471489
assert( pOp->p1>0 );
7134571490
assert( pOp->p1<=(p->nMem-p->nCursor) );
7134671491
assert( memIsValid(&aMem[pOp->p1]) );
7134771492
assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
@@ -71370,10 +71515,13 @@
7137071515
assert( pOp->p3>0 );
7137171516
assert( pOp->p3<=(p->nMem-p->nCursor) );
7137271517
memAboutToChange(p, &aMem[pOp->p3]);
7137371518
}
7137471519
#endif
71520
+#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
71521
+ pOrigOp = pOp;
71522
+#endif
7137571523
7137671524
switch( pOp->opcode ){
7137771525
7137871526
/*****************************************************************************
7137971527
** What follows is a massive switch statement where each case implements a
@@ -71393,11 +71541,11 @@
7139371541
** case statement is followed by a comment of the form "/# same as ... #/"
7139471542
** that comment is used to determine the particular value of the opcode.
7139571543
**
7139671544
** Other keywords in the comment that follows each case are used to
7139771545
** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[].
71398
-** Keywords include: in1, in2, in3, out2_prerelease, out2, out3. See
71546
+** Keywords include: in1, in2, in3, out2, out3. See
7139971547
** the mkopcodeh.awk script for additional information.
7140071548
**
7140171549
** Documentation about VDBE opcodes is generated by scanning this file
7140271550
** for lines of that contain "Opcode:". That line and all subsequent
7140371551
** comment lines are used in the generation of the opcode.html documentation
@@ -71421,11 +71569,12 @@
7142171569
** is sometimes set to 1 instead of 0 as a hint to the command-line shell
7142271570
** that this Goto is the bottom of a loop and that the lines from P2 down
7142371571
** to the current line should be indented for EXPLAIN output.
7142471572
*/
7142571573
case OP_Goto: { /* jump */
71426
- pc = pOp->p2 - 1;
71574
+jump_to_p2_and_check_for_interrupt:
71575
+ pOp = &aOp[pOp->p2 - 1];
7142771576
7142871577
/* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
7142971578
** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
7143071579
** completion. Check to see if sqlite3_interrupt() has been called
7143171580
** or if the progress callback needs to be invoked.
@@ -71466,13 +71615,17 @@
7146671615
assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
7146771616
pIn1 = &aMem[pOp->p1];
7146871617
assert( VdbeMemDynamic(pIn1)==0 );
7146971618
memAboutToChange(p, pIn1);
7147071619
pIn1->flags = MEM_Int;
71471
- pIn1->u.i = pc;
71620
+ pIn1->u.i = (int)(pOp-aOp);
7147271621
REGISTER_TRACE(pOp->p1, pIn1);
71473
- pc = pOp->p2 - 1;
71622
+
71623
+ /* Most jump operations do a goto to this spot in order to update
71624
+ ** the pOp pointer. */
71625
+jump_to_p2:
71626
+ pOp = &aOp[pOp->p2 - 1];
7147471627
break;
7147571628
}
7147671629
7147771630
/* Opcode: Return P1 * * * *
7147871631
**
@@ -71480,11 +71633,11 @@
7148071633
** the jump, register P1 becomes undefined.
7148171634
*/
7148271635
case OP_Return: { /* in1 */
7148371636
pIn1 = &aMem[pOp->p1];
7148471637
assert( pIn1->flags==MEM_Int );
71485
- pc = (int)pIn1->u.i;
71638
+ pOp = &aOp[pIn1->u.i];
7148671639
pIn1->flags = MEM_Undefined;
7148771640
break;
7148871641
}
7148971642
7149071643
/* Opcode: InitCoroutine P1 P2 P3 * *
@@ -71504,11 +71657,11 @@
7150471657
assert( pOp->p3>=0 && pOp->p3<p->nOp );
7150571658
pOut = &aMem[pOp->p1];
7150671659
assert( !VdbeMemDynamic(pOut) );
7150771660
pOut->u.i = pOp->p3 - 1;
7150871661
pOut->flags = MEM_Int;
71509
- if( pOp->p2 ) pc = pOp->p2 - 1;
71662
+ if( pOp->p2 ) goto jump_to_p2;
7151071663
break;
7151171664
}
7151271665
7151371666
/* Opcode: EndCoroutine P1 * * * *
7151471667
**
@@ -71524,11 +71677,11 @@
7152471677
assert( pIn1->flags==MEM_Int );
7152571678
assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
7152671679
pCaller = &aOp[pIn1->u.i];
7152771680
assert( pCaller->opcode==OP_Yield );
7152871681
assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
71529
- pc = pCaller->p2 - 1;
71682
+ pOp = &aOp[pCaller->p2 - 1];
7153071683
pIn1->flags = MEM_Undefined;
7153171684
break;
7153271685
}
7153371686
7153471687
/* Opcode: Yield P1 P2 * * *
@@ -71548,13 +71701,13 @@
7154871701
int pcDest;
7154971702
pIn1 = &aMem[pOp->p1];
7155071703
assert( VdbeMemDynamic(pIn1)==0 );
7155171704
pIn1->flags = MEM_Int;
7155271705
pcDest = (int)pIn1->u.i;
71553
- pIn1->u.i = pc;
71706
+ pIn1->u.i = (int)(pOp - aOp);
7155471707
REGISTER_TRACE(pOp->p1, pIn1);
71555
- pc = pcDest;
71708
+ pOp = &aOp[pcDest];
7155671709
break;
7155771710
}
7155871711
7155971712
/* Opcode: HaltIfNull P1 P2 P3 P4 P5
7156071713
** Synopsis: if r[P3]=null halt
@@ -71601,34 +71754,38 @@
7160171754
** is the same as executing Halt.
7160271755
*/
7160371756
case OP_Halt: {
7160471757
const char *zType;
7160571758
const char *zLogFmt;
71759
+ VdbeFrame *pFrame;
71760
+ int pcx;
7160671761
71762
+ pcx = (int)(pOp - aOp);
7160771763
if( pOp->p1==SQLITE_OK && p->pFrame ){
7160871764
/* Halt the sub-program. Return control to the parent frame. */
71609
- VdbeFrame *pFrame = p->pFrame;
71765
+ pFrame = p->pFrame;
7161071766
p->pFrame = pFrame->pParent;
7161171767
p->nFrame--;
7161271768
sqlite3VdbeSetChanges(db, p->nChange);
71613
- pc = sqlite3VdbeFrameRestore(pFrame);
71769
+ pcx = sqlite3VdbeFrameRestore(pFrame);
7161471770
lastRowid = db->lastRowid;
7161571771
if( pOp->p2==OE_Ignore ){
71616
- /* Instruction pc is the OP_Program that invoked the sub-program
71772
+ /* Instruction pcx is the OP_Program that invoked the sub-program
7161771773
** currently being halted. If the p2 instruction of this OP_Halt
7161871774
** instruction is set to OE_Ignore, then the sub-program is throwing
7161971775
** an IGNORE exception. In this case jump to the address specified
7162071776
** as the p2 of the calling OP_Program. */
71621
- pc = p->aOp[pc].p2-1;
71777
+ pcx = p->aOp[pcx].p2-1;
7162271778
}
7162371779
aOp = p->aOp;
7162471780
aMem = p->aMem;
71781
+ pOp = &aOp[pcx];
7162571782
break;
7162671783
}
7162771784
p->rc = pOp->p1;
7162871785
p->errorAction = (u8)pOp->p2;
71629
- p->pc = pc;
71786
+ p->pc = pcx;
7163071787
if( p->rc ){
7163171788
if( pOp->p5 ){
7163271789
static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
7163371790
"FOREIGN KEY" };
7163471791
assert( pOp->p5>=1 && pOp->p5<=4 );
@@ -71648,11 +71805,11 @@
7164871805
}else if( pOp->p4.z ){
7164971806
sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
7165071807
}else{
7165171808
sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
7165271809
}
71653
- sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg);
71810
+ sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg);
7165471811
}
7165571812
rc = sqlite3VdbeHalt(p);
7165671813
assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
7165771814
if( rc==SQLITE_BUSY ){
7165871815
p->rc = rc = SQLITE_BUSY;
@@ -71667,11 +71824,12 @@
7166771824
/* Opcode: Integer P1 P2 * * *
7166871825
** Synopsis: r[P2]=P1
7166971826
**
7167071827
** The 32-bit integer value P1 is written into register P2.
7167171828
*/
71672
-case OP_Integer: { /* out2-prerelease */
71829
+case OP_Integer: { /* out2 */
71830
+ pOut = out2Prerelease(p, pOp);
7167371831
pOut->u.i = pOp->p1;
7167471832
break;
7167571833
}
7167671834
7167771835
/* Opcode: Int64 * P2 * P4 *
@@ -71678,11 +71836,12 @@
7167871836
** Synopsis: r[P2]=P4
7167971837
**
7168071838
** P4 is a pointer to a 64-bit integer value.
7168171839
** Write that value into register P2.
7168271840
*/
71683
-case OP_Int64: { /* out2-prerelease */
71841
+case OP_Int64: { /* out2 */
71842
+ pOut = out2Prerelease(p, pOp);
7168471843
assert( pOp->p4.pI64!=0 );
7168571844
pOut->u.i = *pOp->p4.pI64;
7168671845
break;
7168771846
}
7168871847
@@ -71691,11 +71850,12 @@
7169171850
** Synopsis: r[P2]=P4
7169271851
**
7169371852
** P4 is a pointer to a 64-bit floating point value.
7169471853
** Write that value into register P2.
7169571854
*/
71696
-case OP_Real: { /* same as TK_FLOAT, out2-prerelease */
71855
+case OP_Real: { /* same as TK_FLOAT, out2 */
71856
+ pOut = out2Prerelease(p, pOp);
7169771857
pOut->flags = MEM_Real;
7169871858
assert( !sqlite3IsNaN(*pOp->p4.pReal) );
7169971859
pOut->u.r = *pOp->p4.pReal;
7170071860
break;
7170171861
}
@@ -71707,12 +71867,13 @@
7170771867
** P4 points to a nul terminated UTF-8 string. This opcode is transformed
7170871868
** into a String opcode before it is executed for the first time. During
7170971869
** this transformation, the length of string P4 is computed and stored
7171071870
** as the P1 parameter.
7171171871
*/
71712
-case OP_String8: { /* same as TK_STRING, out2-prerelease */
71872
+case OP_String8: { /* same as TK_STRING, out2 */
7171371873
assert( pOp->p4.z!=0 );
71874
+ pOut = out2Prerelease(p, pOp);
7171471875
pOp->opcode = OP_String;
7171571876
pOp->p1 = sqlite3Strlen30(pOp->p4.z);
7171671877
7171771878
#ifndef SQLITE_OMIT_UTF16
7171871879
if( encoding!=SQLITE_UTF8 ){
@@ -71745,12 +71906,13 @@
7174571906
** If P5!=0 and the content of register P3 is greater than zero, then
7174671907
** the datatype of the register P2 is converted to BLOB. The content is
7174771908
** the same sequence of bytes, it is merely interpreted as a BLOB instead
7174871909
** of a string, as if it had been CAST.
7174971910
*/
71750
-case OP_String: { /* out2-prerelease */
71911
+case OP_String: { /* out2 */
7175171912
assert( pOp->p4.z!=0 );
71913
+ pOut = out2Prerelease(p, pOp);
7175271914
pOut->flags = MEM_Str|MEM_Static|MEM_Term;
7175371915
pOut->z = pOp->p4.z;
7175471916
pOut->n = pOp->p1;
7175571917
pOut->enc = encoding;
7175671918
UPDATE_MAX_BLOBSIZE(pOut);
@@ -71774,13 +71936,14 @@
7177471936
**
7177571937
** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
7177671938
** NULL values will not compare equal even if SQLITE_NULLEQ is set on
7177771939
** OP_Ne or OP_Eq.
7177871940
*/
71779
-case OP_Null: { /* out2-prerelease */
71941
+case OP_Null: { /* out2 */
7178071942
int cnt;
7178171943
u16 nullFlag;
71944
+ pOut = out2Prerelease(p, pOp);
7178271945
cnt = pOp->p3-pOp->p2;
7178371946
assert( pOp->p3<=(p->nMem-p->nCursor) );
7178471947
pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
7178571948
while( cnt>0 ){
7178671949
pOut++;
@@ -71811,12 +71974,13 @@
7181171974
** Synopsis: r[P2]=P4 (len=P1)
7181271975
**
7181371976
** P4 points to a blob of data P1 bytes long. Store this
7181471977
** blob in register P2.
7181571978
*/
71816
-case OP_Blob: { /* out2-prerelease */
71979
+case OP_Blob: { /* out2 */
7181771980
assert( pOp->p1 <= SQLITE_MAX_LENGTH );
71981
+ pOut = out2Prerelease(p, pOp);
7181871982
sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
7181971983
pOut->enc = encoding;
7182071984
UPDATE_MAX_BLOBSIZE(pOut);
7182171985
break;
7182271986
}
@@ -71827,19 +71991,20 @@
7182771991
** Transfer the values of bound parameter P1 into register P2
7182871992
**
7182971993
** If the parameter is named, then its name appears in P4.
7183071994
** The P4 value is used by sqlite3_bind_parameter_name().
7183171995
*/
71832
-case OP_Variable: { /* out2-prerelease */
71996
+case OP_Variable: { /* out2 */
7183371997
Mem *pVar; /* Value being transferred */
7183471998
7183571999
assert( pOp->p1>0 && pOp->p1<=p->nVar );
7183672000
assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
7183772001
pVar = &p->aVar[pOp->p1 - 1];
7183872002
if( sqlite3VdbeMemTooBig(pVar) ){
7183972003
goto too_big;
7184072004
}
72005
+ pOut = out2Prerelease(p, pOp);
7184172006
sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
7184272007
UPDATE_MAX_BLOBSIZE(pOut);
7184372008
break;
7184472009
}
7184572010
@@ -71870,14 +72035,15 @@
7187072035
assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
7187172036
assert( memIsValid(pIn1) );
7187272037
memAboutToChange(p, pOut);
7187372038
sqlite3VdbeMemMove(pOut, pIn1);
7187472039
#ifdef SQLITE_DEBUG
71875
- if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
71876
- pOut->pScopyFrom += p1 - pOp->p2;
72040
+ if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<pOut ){
72041
+ pOut->pScopyFrom += pOp->p2 - p1;
7187772042
}
7187872043
#endif
72044
+ Deephemeralize(pOut);
7187972045
REGISTER_TRACE(p2++, pOut);
7188072046
pIn1++;
7188172047
pOut++;
7188272048
}while( --n );
7188372049
break;
@@ -72012,11 +72178,11 @@
7201272178
}
7201372179
if( db->mallocFailed ) goto no_mem;
7201472180
7201572181
/* Return SQLITE_ROW
7201672182
*/
72017
- p->pc = pc + 1;
72183
+ p->pc = (int)(pOp - aOp) + 1;
7201872184
rc = SQLITE_ROW;
7201972185
goto vdbe_return;
7202072186
}
7202172187
7202272188
/* Opcode: Concat P1 P2 P3 * *
@@ -72258,11 +72424,11 @@
7225872424
REGISTER_TRACE(pOp->p2+i, pArg);
7225972425
}
7226072426
7226172427
assert( pOp->p4type==P4_FUNCDEF );
7226272428
ctx.pFunc = pOp->p4.pFunc;
72263
- ctx.iOp = pc;
72429
+ ctx.iOp = (int)(pOp - aOp);
7226472430
ctx.pVdbe = p;
7226572431
MemSetTypeFlag(ctx.pOut, MEM_Null);
7226672432
ctx.fErrorOrAux = 0;
7226772433
db->lastRowid = lastRowid;
7226872434
(*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
@@ -72272,11 +72438,11 @@
7227272438
if( ctx.fErrorOrAux ){
7227372439
if( ctx.isError ){
7227472440
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut));
7227572441
rc = ctx.isError;
7227672442
}
72277
- sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
72443
+ sqlite3VdbeDeleteAuxData(p, (int)(pOp - aOp), pOp->p1);
7227872444
}
7227972445
7228072446
/* Copy the result of the function into register P3 */
7228172447
sqlite3VdbeChangeEncoding(ctx.pOut, encoding);
7228272448
if( sqlite3VdbeMemTooBig(ctx.pOut) ){
@@ -72401,12 +72567,11 @@
7240172567
if( (pIn1->flags & MEM_Int)==0 ){
7240272568
if( pOp->p2==0 ){
7240372569
rc = SQLITE_MISMATCH;
7240472570
goto abort_due_to_error;
7240572571
}else{
72406
- pc = pOp->p2 - 1;
72407
- break;
72572
+ goto jump_to_p2;
7240872573
}
7240972574
}
7241072575
}
7241172576
MemSetTypeFlag(pIn1, MEM_Int);
7241272577
break;
@@ -72588,11 +72753,11 @@
7258872753
MemSetTypeFlag(pOut, MEM_Null);
7258972754
REGISTER_TRACE(pOp->p2, pOut);
7259072755
}else{
7259172756
VdbeBranchTaken(2,3);
7259272757
if( pOp->p5 & SQLITE_JUMPIFNULL ){
72593
- pc = pOp->p2-1;
72758
+ goto jump_to_p2;
7259472759
}
7259572760
}
7259672761
break;
7259772762
}
7259872763
}else{
@@ -72639,10 +72804,16 @@
7263972804
case OP_Lt: res = res<0; break;
7264072805
case OP_Le: res = res<=0; break;
7264172806
case OP_Gt: res = res>0; break;
7264272807
default: res = res>=0; break;
7264372808
}
72809
+
72810
+ /* Undo any changes made by applyAffinity() to the input registers. */
72811
+ assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
72812
+ pIn1->flags = flags1;
72813
+ assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
72814
+ pIn3->flags = flags3;
7264472815
7264572816
if( pOp->p5 & SQLITE_STOREP2 ){
7264672817
pOut = &aMem[pOp->p2];
7264772818
memAboutToChange(p, pOut);
7264872819
MemSetTypeFlag(pOut, MEM_Int);
@@ -72649,18 +72820,13 @@
7264972820
pOut->u.i = res;
7265072821
REGISTER_TRACE(pOp->p2, pOut);
7265172822
}else{
7265272823
VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
7265372824
if( res ){
72654
- pc = pOp->p2-1;
72825
+ goto jump_to_p2;
7265572826
}
7265672827
}
72657
- /* Undo any changes made by applyAffinity() to the input registers. */
72658
- assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
72659
- pIn1->flags = flags1;
72660
- assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
72661
- pIn3->flags = flags3;
7266272828
break;
7266372829
}
7266472830
7266572831
/* Opcode: Permutation * * * P4 *
7266672832
**
@@ -72751,15 +72917,15 @@
7275172917
** in the most recent OP_Compare instruction the P1 vector was less than
7275272918
** equal to, or greater than the P2 vector, respectively.
7275372919
*/
7275472920
case OP_Jump: { /* jump */
7275572921
if( iCompare<0 ){
72756
- pc = pOp->p1 - 1; VdbeBranchTaken(0,3);
72922
+ VdbeBranchTaken(0,3); pOp = &aOp[pOp->p1 - 1];
7275772923
}else if( iCompare==0 ){
72758
- pc = pOp->p2 - 1; VdbeBranchTaken(1,3);
72924
+ VdbeBranchTaken(1,3); pOp = &aOp[pOp->p2 - 1];
7275972925
}else{
72760
- pc = pOp->p3 - 1; VdbeBranchTaken(2,3);
72926
+ VdbeBranchTaken(2,3); pOp = &aOp[pOp->p3 - 1];
7276172927
}
7276272928
break;
7276372929
}
7276472930
7276572931
/* Opcode: And P1 P2 P3 * *
@@ -72865,11 +73031,11 @@
7286573031
*/
7286673032
case OP_Once: { /* jump */
7286773033
assert( pOp->p1<p->nOnceFlag );
7286873034
VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
7286973035
if( p->aOnceFlag[pOp->p1] ){
72870
- pc = pOp->p2-1;
73036
+ goto jump_to_p2;
7287173037
}else{
7287273038
p->aOnceFlag[pOp->p1] = 1;
7287373039
}
7287473040
break;
7287573041
}
@@ -72900,11 +73066,11 @@
7290073066
#endif
7290173067
if( pOp->opcode==OP_IfNot ) c = !c;
7290273068
}
7290373069
VdbeBranchTaken(c!=0, 2);
7290473070
if( c ){
72905
- pc = pOp->p2-1;
73071
+ goto jump_to_p2;
7290673072
}
7290773073
break;
7290873074
}
7290973075
7291073076
/* Opcode: IsNull P1 P2 * * *
@@ -72914,11 +73080,11 @@
7291473080
*/
7291573081
case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
7291673082
pIn1 = &aMem[pOp->p1];
7291773083
VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
7291873084
if( (pIn1->flags & MEM_Null)!=0 ){
72919
- pc = pOp->p2 - 1;
73085
+ goto jump_to_p2;
7292073086
}
7292173087
break;
7292273088
}
7292373089
7292473090
/* Opcode: NotNull P1 P2 * * *
@@ -72928,11 +73094,11 @@
7292873094
*/
7292973095
case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
7293073096
pIn1 = &aMem[pOp->p1];
7293173097
VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
7293273098
if( (pIn1->flags & MEM_Null)==0 ){
72933
- pc = pOp->p2 - 1;
73099
+ goto jump_to_p2;
7293473100
}
7293573101
break;
7293673102
}
7293773103
7293873104
/* Opcode: Column P1 P2 P3 P4 P5
@@ -73142,11 +73308,11 @@
7314273308
rc = SQLITE_CORRUPT_BKPT;
7314373309
goto op_column_error;
7314473310
}
7314573311
}
7314673312
73147
- /* If after trying to extra new entries from the header, nHdrParsed is
73313
+ /* If after trying to extract new entries from the header, nHdrParsed is
7314873314
** still not up to p2, that means that the record has fewer than p2
7314973315
** columns. So the result will be either the default value or a NULL.
7315073316
*/
7315173317
if( pC->nHdrParsed<=p2 ){
7315273318
if( pOp->p4type==P4_MEM ){
@@ -73266,11 +73432,11 @@
7326673432
u8 *zNewRecord; /* A buffer to hold the data for the new record */
7326773433
Mem *pRec; /* The new record */
7326873434
u64 nData; /* Number of bytes of data space */
7326973435
int nHdr; /* Number of bytes of header space */
7327073436
i64 nByte; /* Data space required for this record */
73271
- int nZero; /* Number of zero bytes at the end of the record */
73437
+ i64 nZero; /* Number of zero bytes at the end of the record */
7327273438
int nVarint; /* Number of bytes in a varint */
7327373439
u32 serial_type; /* Type field */
7327473440
Mem *pData0; /* First field to be combined into the record */
7327573441
Mem *pLast; /* Last field of the record */
7327673442
int nField; /* Number of fields in the record */
@@ -73358,11 +73524,11 @@
7335873524
nVarint = sqlite3VarintLen(nHdr);
7335973525
nHdr += nVarint;
7336073526
if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
7336173527
}
7336273528
nByte = nHdr+nData;
73363
- if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
73529
+ if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){
7336473530
goto too_big;
7336573531
}
7336673532
7336773533
/* Make sure the output register has a buffer large enough to store
7336873534
** the new record. The output register (pOp->p3) is not allowed to
@@ -73409,18 +73575,19 @@
7340973575
**
7341073576
** Store the number of entries (an integer value) in the table or index
7341173577
** opened by cursor P1 in register P2
7341273578
*/
7341373579
#ifndef SQLITE_OMIT_BTREECOUNT
73414
-case OP_Count: { /* out2-prerelease */
73580
+case OP_Count: { /* out2 */
7341573581
i64 nEntry;
7341673582
BtCursor *pCrsr;
7341773583
7341873584
pCrsr = p->apCsr[pOp->p1]->pCursor;
7341973585
assert( pCrsr );
7342073586
nEntry = 0; /* Not needed. Only used to silence a warning. */
7342173587
rc = sqlite3BtreeCount(pCrsr, &nEntry);
73588
+ pOut = out2Prerelease(p, pOp);
7342273589
pOut->u.i = nEntry;
7342373590
break;
7342473591
}
7342573592
#endif
7342673593
@@ -73530,11 +73697,11 @@
7353073697
if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
7353173698
goto vdbe_return;
7353273699
}
7353373700
db->autoCommit = 1;
7353473701
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73535
- p->pc = pc;
73702
+ p->pc = (int)(pOp - aOp);
7353673703
db->autoCommit = 0;
7353773704
p->rc = rc = SQLITE_BUSY;
7353873705
goto vdbe_return;
7353973706
}
7354073707
db->isTransactionSavepoint = 0;
@@ -73589,11 +73756,11 @@
7358973756
}else{
7359073757
db->nDeferredCons = pSavepoint->nDeferredCons;
7359173758
db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
7359273759
}
7359373760
73594
- if( !isTransaction ){
73761
+ if( !isTransaction || p1==SAVEPOINT_ROLLBACK ){
7359573762
rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
7359673763
if( rc!=SQLITE_OK ) goto abort_due_to_error;
7359773764
}
7359873765
}
7359973766
}
@@ -73649,11 +73816,11 @@
7364973816
}else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
7365073817
goto vdbe_return;
7365173818
}else{
7365273819
db->autoCommit = (u8)desiredAutoCommit;
7365373820
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73654
- p->pc = pc;
73821
+ p->pc = (int)(pOp - aOp);
7365573822
db->autoCommit = (u8)(1-desiredAutoCommit);
7365673823
p->rc = rc = SQLITE_BUSY;
7365773824
goto vdbe_return;
7365873825
}
7365973826
}
@@ -73726,11 +73893,11 @@
7372673893
pBt = db->aDb[pOp->p1].pBt;
7372773894
7372873895
if( pBt ){
7372973896
rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
7373073897
if( rc==SQLITE_BUSY ){
73731
- p->pc = pc;
73898
+ p->pc = (int)(pOp - aOp);
7373273899
p->rc = rc = SQLITE_BUSY;
7373373900
goto vdbe_return;
7373473901
}
7373573902
if( rc!=SQLITE_OK ){
7373673903
goto abort_due_to_error;
@@ -73805,11 +73972,11 @@
7380573972
**
7380673973
** There must be a read-lock on the database (either a transaction
7380773974
** must be started or there must be an open cursor) before
7380873975
** executing this instruction.
7380973976
*/
73810
-case OP_ReadCookie: { /* out2-prerelease */
73977
+case OP_ReadCookie: { /* out2 */
7381173978
int iMeta;
7381273979
int iDb;
7381373980
int iCookie;
7381473981
7381573982
assert( p->bIsReader );
@@ -73819,10 +73986,11 @@
7381973986
assert( iDb>=0 && iDb<db->nDb );
7382073987
assert( db->aDb[iDb].pBt!=0 );
7382173988
assert( DbMaskTest(p->btreeMask, iDb) );
7382273989
7382373990
sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
73991
+ pOut = out2Prerelease(p, pOp);
7382473992
pOut->u.i = iMeta;
7382573993
break;
7382673994
}
7382773995
7382873996
/* Opcode: SetCookie P1 P2 P3 * *
@@ -74140,11 +74308,11 @@
7414074308
VdbeCursor *pC;
7414174309
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7414274310
pC = p->apCsr[pOp->p1];
7414374311
assert( pC->pSorter );
7414474312
if( (pC->seqCount++)==0 ){
74145
- pc = pOp->p2 - 1;
74313
+ goto jump_to_p2;
7414674314
}
7414774315
break;
7414874316
}
7414974317
7415074318
/* Opcode: OpenPseudo P1 P2 P3 * *
@@ -74317,11 +74485,11 @@
7431774485
** loss of information, then special processing is required... */
7431874486
if( (pIn3->flags & MEM_Int)==0 ){
7431974487
if( (pIn3->flags & MEM_Real)==0 ){
7432074488
/* If the P3 value cannot be converted into any kind of a number,
7432174489
** then the seek is not possible, so jump to P2 */
74322
- pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
74490
+ VdbeBranchTaken(1,2); goto jump_to_p2;
7432374491
break;
7432474492
}
7432574493
7432674494
/* If the approximation iKey is larger than the actual real search
7432774495
** term, substitute >= for > and < for <=. e.g. if the search term
@@ -74408,11 +74576,11 @@
7440874576
}
7440974577
}
7441074578
assert( pOp->p2>0 );
7441174579
VdbeBranchTaken(res!=0,2);
7441274580
if( res ){
74413
- pc = pOp->p2 - 1;
74581
+ goto jump_to_p2;
7441474582
}
7441574583
break;
7441674584
}
7441774585
7441874586
/* Opcode: Seek P1 P2 * * *
@@ -74502,10 +74670,11 @@
7450274670
*/
7450374671
case OP_NoConflict: /* jump, in3 */
7450474672
case OP_NotFound: /* jump, in3 */
7450574673
case OP_Found: { /* jump, in3 */
7450674674
int alreadyExists;
74675
+ int takeJump;
7450774676
int ii;
7450874677
VdbeCursor *pC;
7450974678
int res;
7451074679
char *pFree;
7451174680
UnpackedRecord *pIdxKey;
@@ -74524,11 +74693,11 @@
7452474693
pC->seekOp = pOp->opcode;
7452574694
#endif
7452674695
pIn3 = &aMem[pOp->p3];
7452774696
assert( pC->pCursor!=0 );
7452874697
assert( pC->isTable==0 );
74529
- pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
74698
+ pFree = 0;
7453074699
if( pOp->p4.i>0 ){
7453174700
r.pKeyInfo = pC->pKeyInfo;
7453274701
r.nField = (u16)pOp->p4.i;
7453374702
r.aMem = pIn3;
7453474703
for(ii=0; ii<r.nField; ii++){
@@ -74547,25 +74716,24 @@
7454774716
assert( pIn3->flags & MEM_Blob );
7454874717
ExpandBlob(pIn3);
7454974718
sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
7455074719
}
7455174720
pIdxKey->default_rc = 0;
74721
+ takeJump = 0;
7455274722
if( pOp->opcode==OP_NoConflict ){
7455374723
/* For the OP_NoConflict opcode, take the jump if any of the
7455474724
** input fields are NULL, since any key with a NULL will not
7455574725
** conflict */
7455674726
for(ii=0; ii<pIdxKey->nField; ii++){
7455774727
if( pIdxKey->aMem[ii].flags & MEM_Null ){
74558
- pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
74728
+ takeJump = 1;
7455974729
break;
7456074730
}
7456174731
}
7456274732
}
7456374733
rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
74564
- if( pOp->p4.i==0 ){
74565
- sqlite3DbFree(db, pFree);
74566
- }
74734
+ sqlite3DbFree(db, pFree);
7456774735
if( rc!=SQLITE_OK ){
7456874736
break;
7456974737
}
7457074738
pC->seekResult = res;
7457174739
alreadyExists = (res==0);
@@ -74572,14 +74740,14 @@
7457274740
pC->nullRow = 1-alreadyExists;
7457374741
pC->deferredMoveto = 0;
7457474742
pC->cacheStatus = CACHE_STALE;
7457574743
if( pOp->opcode==OP_Found ){
7457674744
VdbeBranchTaken(alreadyExists!=0,2);
74577
- if( alreadyExists ) pc = pOp->p2 - 1;
74745
+ if( alreadyExists ) goto jump_to_p2;
7457874746
}else{
74579
- VdbeBranchTaken(alreadyExists==0,2);
74580
- if( !alreadyExists ) pc = pOp->p2 - 1;
74747
+ VdbeBranchTaken(takeJump||alreadyExists==0,2);
74748
+ if( takeJump || !alreadyExists ) goto jump_to_p2;
7458174749
}
7458274750
break;
7458374751
}
7458474752
7458574753
/* Opcode: NotExists P1 P2 P3 * *
@@ -74624,14 +74792,12 @@
7462474792
pC->movetoTarget = iKey; /* Used by OP_Delete */
7462574793
pC->nullRow = 0;
7462674794
pC->cacheStatus = CACHE_STALE;
7462774795
pC->deferredMoveto = 0;
7462874796
VdbeBranchTaken(res!=0,2);
74629
- if( res!=0 ){
74630
- pc = pOp->p2 - 1;
74631
- }
7463274797
pC->seekResult = res;
74798
+ if( res!=0 ) goto jump_to_p2;
7463374799
break;
7463474800
}
7463574801
7463674802
/* Opcode: Sequence P1 P2 * * *
7463774803
** Synopsis: r[P2]=cursor[P1].ctr++
@@ -74639,13 +74805,14 @@
7463974805
** Find the next available sequence number for cursor P1.
7464074806
** Write the sequence number into register P2.
7464174807
** The sequence number on the cursor is incremented after this
7464274808
** instruction.
7464374809
*/
74644
-case OP_Sequence: { /* out2-prerelease */
74810
+case OP_Sequence: { /* out2 */
7464574811
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7464674812
assert( p->apCsr[pOp->p1]!=0 );
74813
+ pOut = out2Prerelease(p, pOp);
7464774814
pOut->u.i = p->apCsr[pOp->p1]->seqCount++;
7464874815
break;
7464974816
}
7465074817
7465174818
@@ -74662,20 +74829,21 @@
7466274829
** allowed to be less than this value. When this value reaches its maximum,
7466374830
** an SQLITE_FULL error is generated. The P3 register is updated with the '
7466474831
** generated record number. This P3 mechanism is used to help implement the
7466574832
** AUTOINCREMENT feature.
7466674833
*/
74667
-case OP_NewRowid: { /* out2-prerelease */
74834
+case OP_NewRowid: { /* out2 */
7466874835
i64 v; /* The new rowid */
7466974836
VdbeCursor *pC; /* Cursor of table to get the new rowid */
7467074837
int res; /* Result of an sqlite3BtreeLast() */
7467174838
int cnt; /* Counter to limit the number of searches */
7467274839
Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
7467374840
VdbeFrame *pFrame; /* Root frame of VDBE */
7467474841
7467574842
v = 0;
7467674843
res = 0;
74844
+ pOut = out2Prerelease(p, pOp);
7467774845
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7467874846
pC = p->apCsr[pOp->p1];
7467974847
assert( pC!=0 );
7468074848
if( NEVER(pC->pCursor==0) ){
7468174849
/* The zero initialization above is all that is needed */
@@ -74985,13 +75153,11 @@
7498575153
pIn3 = &aMem[pOp->p3];
7498675154
nKeyCol = pOp->p4.i;
7498775155
res = 0;
7498875156
rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res);
7498975157
VdbeBranchTaken(res!=0,2);
74990
- if( res ){
74991
- pc = pOp->p2-1;
74992
- }
75158
+ if( res ) goto jump_to_p2;
7499375159
break;
7499475160
};
7499575161
7499675162
/* Opcode: SorterData P1 P2 P3 * *
7499775163
** Synopsis: r[P2]=data
@@ -75116,16 +75282,17 @@
7511675282
**
7511775283
** P1 can be either an ordinary table or a virtual table. There used to
7511875284
** be a separate OP_VRowid opcode for use with virtual tables, but this
7511975285
** one opcode now works for both table types.
7512075286
*/
75121
-case OP_Rowid: { /* out2-prerelease */
75287
+case OP_Rowid: { /* out2 */
7512275288
VdbeCursor *pC;
7512375289
i64 v;
7512475290
sqlite3_vtab *pVtab;
7512575291
const sqlite3_module *pModule;
7512675292
75293
+ pOut = out2Prerelease(p, pOp);
7512775294
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7512875295
pC = p->apCsr[pOp->p1];
7512975296
assert( pC!=0 );
7513075297
assert( pC->pseudoTableReg==0 || pC->nullRow );
7513175298
if( pC->nullRow ){
@@ -75174,11 +75341,11 @@
7517475341
sqlite3BtreeClearCursor(pC->pCursor);
7517575342
}
7517675343
break;
7517775344
}
7517875345
75179
-/* Opcode: Last P1 P2 * * *
75346
+/* Opcode: Last P1 P2 P3 * *
7518075347
**
7518175348
** The next use of the Rowid or Column or Prev instruction for P1
7518275349
** will refer to the last entry in the database table or index.
7518375350
** If the table or index is empty and P2>0, then jump immediately to P2.
7518475351
** If P2 is 0 or if the table or index is not empty, fall through
@@ -75201,16 +75368,17 @@
7520175368
assert( pCrsr!=0 );
7520275369
rc = sqlite3BtreeLast(pCrsr, &res);
7520375370
pC->nullRow = (u8)res;
7520475371
pC->deferredMoveto = 0;
7520575372
pC->cacheStatus = CACHE_STALE;
75373
+ pC->seekResult = pOp->p3;
7520675374
#ifdef SQLITE_DEBUG
7520775375
pC->seekOp = OP_Last;
7520875376
#endif
7520975377
if( pOp->p2>0 ){
7521075378
VdbeBranchTaken(res!=0,2);
75211
- if( res ) pc = pOp->p2 - 1;
75379
+ if( res ) goto jump_to_p2;
7521275380
}
7521375381
break;
7521475382
}
7521575383
7521675384
@@ -75270,13 +75438,11 @@
7527075438
pC->cacheStatus = CACHE_STALE;
7527175439
}
7527275440
pC->nullRow = (u8)res;
7527375441
assert( pOp->p2>0 && pOp->p2<p->nOp );
7527475442
VdbeBranchTaken(res!=0,2);
75275
- if( res ){
75276
- pc = pOp->p2 - 1;
75277
- }
75443
+ if( res ) goto jump_to_p2;
7527875444
break;
7527975445
}
7528075446
7528175447
/* Opcode: Next P1 P2 P3 P4 P5
7528275448
**
@@ -75383,15 +75549,15 @@
7538375549
next_tail:
7538475550
pC->cacheStatus = CACHE_STALE;
7538575551
VdbeBranchTaken(res==0,2);
7538675552
if( res==0 ){
7538775553
pC->nullRow = 0;
75388
- pc = pOp->p2 - 1;
7538975554
p->aCounter[pOp->p5]++;
7539075555
#ifdef SQLITE_TEST
7539175556
sqlite3_search_count++;
7539275557
#endif
75558
+ goto jump_to_p2_and_check_for_interrupt;
7539375559
}else{
7539475560
pC->nullRow = 1;
7539575561
}
7539675562
goto check_for_interrupt;
7539775563
}
@@ -75495,15 +75661,16 @@
7549575661
** the end of the index key pointed to by cursor P1. This integer should be
7549675662
** the rowid of the table entry to which this index entry points.
7549775663
**
7549875664
** See also: Rowid, MakeRecord.
7549975665
*/
75500
-case OP_IdxRowid: { /* out2-prerelease */
75666
+case OP_IdxRowid: { /* out2 */
7550175667
BtCursor *pCrsr;
7550275668
VdbeCursor *pC;
7550375669
i64 rowid;
7550475670
75671
+ pOut = out2Prerelease(p, pOp);
7550575672
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7550675673
pC = p->apCsr[pOp->p1];
7550775674
assert( pC!=0 );
7550875675
pCrsr = pC->pCursor;
7550975676
assert( pCrsr!=0 );
@@ -75612,13 +75779,11 @@
7561275779
}else{
7561375780
assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
7561475781
res++;
7561575782
}
7561675783
VdbeBranchTaken(res>0,2);
75617
- if( res>0 ){
75618
- pc = pOp->p2 - 1 ;
75619
- }
75784
+ if( res>0 ) goto jump_to_p2;
7562075785
break;
7562175786
}
7562275787
7562375788
/* Opcode: Destroy P1 P2 P3 * *
7562475789
**
@@ -75638,15 +75803,16 @@
7563875803
** the last one in the database) then a zero is stored in register P2.
7563975804
** If AUTOVACUUM is disabled then a zero is stored in register P2.
7564075805
**
7564175806
** See also: Clear
7564275807
*/
75643
-case OP_Destroy: { /* out2-prerelease */
75808
+case OP_Destroy: { /* out2 */
7564475809
int iMoved;
7564575810
int iDb;
7564675811
7564775812
assert( p->readOnly==0 );
75813
+ pOut = out2Prerelease(p, pOp);
7564875814
pOut->flags = MEM_Null;
7564975815
if( db->nVdbeRead > db->nVDestroy+1 ){
7565075816
rc = SQLITE_LOCKED;
7565175817
p->errorAction = OE_Abort;
7565275818
}else{
@@ -75751,16 +75917,17 @@
7575175917
** P1>1. Write the root page number of the new table into
7575275918
** register P2.
7575375919
**
7575475920
** See documentation on OP_CreateTable for additional information.
7575575921
*/
75756
-case OP_CreateIndex: /* out2-prerelease */
75757
-case OP_CreateTable: { /* out2-prerelease */
75922
+case OP_CreateIndex: /* out2 */
75923
+case OP_CreateTable: { /* out2 */
7575875924
int pgno;
7575975925
int flags;
7576075926
Db *pDb;
7576175927
75928
+ pOut = out2Prerelease(p, pOp);
7576275929
pgno = 0;
7576375930
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7576475931
assert( DbMaskTest(p->btreeMask, pOp->p1) );
7576575932
assert( p->readOnly==0 );
7576675933
pDb = &db->aDb[pOp->p1];
@@ -75982,16 +76149,16 @@
7598276149
if( (pIn1->flags & MEM_RowSet)==0
7598376150
|| sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
7598476151
){
7598576152
/* The boolean index is empty */
7598676153
sqlite3VdbeMemSetNull(pIn1);
75987
- pc = pOp->p2 - 1;
7598876154
VdbeBranchTaken(1,2);
76155
+ goto jump_to_p2_and_check_for_interrupt;
7598976156
}else{
7599076157
/* A value was pulled from the index */
75991
- sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
7599276158
VdbeBranchTaken(0,2);
76159
+ sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
7599376160
}
7599476161
goto check_for_interrupt;
7599576162
}
7599676163
7599776164
/* Opcode: RowSetTest P1 P2 P3 P4
@@ -76038,14 +76205,11 @@
7603876205
assert( pOp->p4type==P4_INT32 );
7603976206
assert( iSet==-1 || iSet>=0 );
7604076207
if( iSet ){
7604176208
exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i);
7604276209
VdbeBranchTaken(exists!=0,2);
76043
- if( exists ){
76044
- pc = pOp->p2 - 1;
76045
- break;
76046
- }
76210
+ if( exists ) goto jump_to_p2;
7604776211
}
7604876212
if( iSet>=0 ){
7604976213
sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
7605076214
}
7605176215
break;
@@ -76130,11 +76294,11 @@
7613076294
pRt->u.pFrame = pFrame;
7613176295
7613276296
pFrame->v = p;
7613376297
pFrame->nChildMem = nMem;
7613476298
pFrame->nChildCsr = pProgram->nCsr;
76135
- pFrame->pc = pc;
76299
+ pFrame->pc = (int)(pOp - aOp);
7613676300
pFrame->aMem = p->aMem;
7613776301
pFrame->nMem = p->nMem;
7613876302
pFrame->apCsr = p->apCsr;
7613976303
pFrame->nCursor = p->nCursor;
7614076304
pFrame->aOp = p->aOp;
@@ -76153,11 +76317,11 @@
7615376317
}
7615476318
}else{
7615576319
pFrame = pRt->u.pFrame;
7615676320
assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
7615776321
assert( pProgram->nCsr==pFrame->nChildCsr );
76158
- assert( pc==pFrame->pc );
76322
+ assert( (int)(pOp - aOp)==pFrame->pc );
7615976323
}
7616076324
7616176325
p->nFrame++;
7616276326
pFrame->pParent = p->pFrame;
7616376327
pFrame->lastRowid = lastRowid;
@@ -76174,11 +76338,11 @@
7617476338
p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
7617576339
p->nOnceFlag = pProgram->nOnce;
7617676340
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
7617776341
p->anExec = 0;
7617876342
#endif
76179
- pc = -1;
76343
+ pOp = &aOp[-1];
7618076344
memset(p->aOnceFlag, 0, p->nOnceFlag);
7618176345
7618276346
break;
7618376347
}
7618476348
@@ -76192,13 +76356,14 @@
7619276356
**
7619376357
** The address of the cell in the parent frame is determined by adding
7619476358
** the value of the P1 argument to the value of the P1 argument to the
7619576359
** calling OP_Program instruction.
7619676360
*/
76197
-case OP_Param: { /* out2-prerelease */
76361
+case OP_Param: { /* out2 */
7619876362
VdbeFrame *pFrame;
7619976363
Mem *pIn;
76364
+ pOut = out2Prerelease(p, pOp);
7620076365
pFrame = p->pFrame;
7620176366
pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
7620276367
sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem);
7620376368
break;
7620476369
}
@@ -76238,14 +76403,14 @@
7623876403
** (immediate foreign key constraint violations).
7623976404
*/
7624076405
case OP_FkIfZero: { /* jump */
7624176406
if( pOp->p1 ){
7624276407
VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
76243
- if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
76408
+ if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
7624476409
}else{
7624576410
VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
76246
- if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
76411
+ if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
7624776412
}
7624876413
break;
7624976414
}
7625076415
#endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
7625176416
@@ -76292,13 +76457,11 @@
7629276457
*/
7629376458
case OP_IfPos: { /* jump, in1 */
7629476459
pIn1 = &aMem[pOp->p1];
7629576460
assert( pIn1->flags&MEM_Int );
7629676461
VdbeBranchTaken( pIn1->u.i>0, 2);
76297
- if( pIn1->u.i>0 ){
76298
- pc = pOp->p2 - 1;
76299
- }
76462
+ if( pIn1->u.i>0 ) goto jump_to_p2;
7630076463
break;
7630176464
}
7630276465
7630376466
/* Opcode: IfNeg P1 P2 P3 * *
7630476467
** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2
@@ -76309,13 +76472,11 @@
7630976472
case OP_IfNeg: { /* jump, in1 */
7631076473
pIn1 = &aMem[pOp->p1];
7631176474
assert( pIn1->flags&MEM_Int );
7631276475
pIn1->u.i += pOp->p3;
7631376476
VdbeBranchTaken(pIn1->u.i<0, 2);
76314
- if( pIn1->u.i<0 ){
76315
- pc = pOp->p2 - 1;
76316
- }
76477
+ if( pIn1->u.i<0 ) goto jump_to_p2;
7631776478
break;
7631876479
}
7631976480
7632076481
/* Opcode: IfNotZero P1 P2 P3 * *
7632176482
** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2
@@ -76328,11 +76489,11 @@
7632876489
pIn1 = &aMem[pOp->p1];
7632976490
assert( pIn1->flags&MEM_Int );
7633076491
VdbeBranchTaken(pIn1->u.i<0, 2);
7633176492
if( pIn1->u.i ){
7633276493
pIn1->u.i += pOp->p3;
76333
- pc = pOp->p2 - 1;
76494
+ goto jump_to_p2;
7633476495
}
7633576496
break;
7633676497
}
7633776498
7633876499
/* Opcode: DecrJumpZero P1 P2 * * *
@@ -76344,13 +76505,11 @@
7634476505
case OP_DecrJumpZero: { /* jump, in1 */
7634576506
pIn1 = &aMem[pOp->p1];
7634676507
assert( pIn1->flags&MEM_Int );
7634776508
pIn1->u.i--;
7634876509
VdbeBranchTaken(pIn1->u.i==0, 2);
76349
- if( pIn1->u.i==0 ){
76350
- pc = pOp->p2 - 1;
76351
- }
76510
+ if( pIn1->u.i==0 ) goto jump_to_p2;
7635276511
break;
7635376512
}
7635476513
7635576514
7635676515
/* Opcode: JumpZeroIncr P1 P2 * * *
@@ -76362,13 +76521,11 @@
7636276521
*/
7636376522
case OP_JumpZeroIncr: { /* jump, in1 */
7636476523
pIn1 = &aMem[pOp->p1];
7636576524
assert( pIn1->flags&MEM_Int );
7636676525
VdbeBranchTaken(pIn1->u.i==0, 2);
76367
- if( (pIn1->u.i++)==0 ){
76368
- pc = pOp->p2 - 1;
76369
- }
76526
+ if( (pIn1->u.i++)==0 ) goto jump_to_p2;
7637076527
break;
7637176528
}
7637276529
7637376530
/* Opcode: AggStep * P2 P3 P4 P5
7637476531
** Synopsis: accum=r[P3] step(r[P2@P5])
@@ -76406,11 +76563,11 @@
7640676563
pMem->n++;
7640776564
sqlite3VdbeMemInit(&t, db, MEM_Null);
7640876565
ctx.pOut = &t;
7640976566
ctx.isError = 0;
7641076567
ctx.pVdbe = p;
76411
- ctx.iOp = pc;
76568
+ ctx.iOp = (int)(pOp - aOp);
7641276569
ctx.skipFlag = 0;
7641376570
(ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
7641476571
if( ctx.isError ){
7641576572
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t));
7641676573
rc = ctx.isError;
@@ -76501,19 +76658,20 @@
7650176658
**
7650276659
** If changing into or out of WAL mode the procedure is more complicated.
7650376660
**
7650476661
** Write a string containing the final journal-mode to register P2.
7650576662
*/
76506
-case OP_JournalMode: { /* out2-prerelease */
76663
+case OP_JournalMode: { /* out2 */
7650776664
Btree *pBt; /* Btree to change journal mode of */
7650876665
Pager *pPager; /* Pager associated with pBt */
7650976666
int eNew; /* New journal mode */
7651076667
int eOld; /* The old journal mode */
7651176668
#ifndef SQLITE_OMIT_WAL
7651276669
const char *zFilename; /* Name of database file for pPager */
7651376670
#endif
7651476671
76672
+ pOut = out2Prerelease(p, pOp);
7651576673
eNew = pOp->p3;
7651676674
assert( eNew==PAGER_JOURNALMODE_DELETE
7651776675
|| eNew==PAGER_JOURNALMODE_TRUNCATE
7651876676
|| eNew==PAGER_JOURNALMODE_PERSIST
7651976677
|| eNew==PAGER_JOURNALMODE_OFF
@@ -76585,11 +76743,10 @@
7658576743
if( rc ){
7658676744
eNew = eOld;
7658776745
}
7658876746
eNew = sqlite3PagerSetJournalMode(pPager, eNew);
7658976747
76590
- pOut = &aMem[pOp->p2];
7659176748
pOut->flags = MEM_Str|MEM_Static|MEM_Term;
7659276749
pOut->z = (char *)sqlite3JournalModename(eNew);
7659376750
pOut->n = sqlite3Strlen30(pOut->z);
7659476751
pOut->enc = SQLITE_UTF8;
7659576752
sqlite3VdbeChangeEncoding(pOut, encoding);
@@ -76626,12 +76783,12 @@
7662676783
assert( p->readOnly==0 );
7662776784
pBt = db->aDb[pOp->p1].pBt;
7662876785
rc = sqlite3BtreeIncrVacuum(pBt);
7662976786
VdbeBranchTaken(rc==SQLITE_DONE,2);
7663076787
if( rc==SQLITE_DONE ){
76631
- pc = pOp->p2 - 1;
7663276788
rc = SQLITE_OK;
76789
+ goto jump_to_p2;
7663376790
}
7663476791
break;
7663576792
}
7663676793
#endif
7663776794
@@ -76780,12 +76937,13 @@
7678076937
pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
7678176938
if( pCur ){
7678276939
pCur->pVtabCursor = pVtabCursor;
7678376940
pVtab->nRef++;
7678476941
}else{
76785
- db->mallocFailed = 1;
76942
+ assert( db->mallocFailed );
7678676943
pModule->xClose(pVtabCursor);
76944
+ goto no_mem;
7678776945
}
7678876946
}
7678976947
break;
7679076948
}
7679176949
#endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -76837,29 +76995,23 @@
7683776995
assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
7683876996
nArg = (int)pArgc->u.i;
7683976997
iQuery = (int)pQuery->u.i;
7684076998
7684176999
/* Invoke the xFilter method */
76842
- {
76843
- res = 0;
76844
- apArg = p->apArg;
76845
- for(i = 0; i<nArg; i++){
76846
- apArg[i] = &pArgc[i+1];
76847
- }
76848
-
76849
- rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
76850
- sqlite3VtabImportErrmsg(p, pVtab);
76851
- if( rc==SQLITE_OK ){
76852
- res = pModule->xEof(pVtabCursor);
76853
- }
76854
- VdbeBranchTaken(res!=0,2);
76855
- if( res ){
76856
- pc = pOp->p2 - 1;
76857
- }
77000
+ res = 0;
77001
+ apArg = p->apArg;
77002
+ for(i = 0; i<nArg; i++){
77003
+ apArg[i] = &pArgc[i+1];
77004
+ }
77005
+ rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
77006
+ sqlite3VtabImportErrmsg(p, pVtab);
77007
+ if( rc==SQLITE_OK ){
77008
+ res = pModule->xEof(pVtabCursor);
7685877009
}
7685977010
pCur->nullRow = 0;
76860
-
77011
+ VdbeBranchTaken(res!=0,2);
77012
+ if( res ) goto jump_to_p2;
7686177013
break;
7686277014
}
7686377015
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7686477016
7686577017
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76942,11 +77094,11 @@
7694277094
res = pModule->xEof(pCur->pVtabCursor);
7694377095
}
7694477096
VdbeBranchTaken(!res,2);
7694577097
if( !res ){
7694677098
/* If there is data, jump to P2 */
76947
- pc = pOp->p2 - 1;
77099
+ goto jump_to_p2_and_check_for_interrupt;
7694877100
}
7694977101
goto check_for_interrupt;
7695077102
}
7695177103
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7695277104
@@ -77065,11 +77217,12 @@
7706577217
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
7706677218
/* Opcode: Pagecount P1 P2 * * *
7706777219
**
7706877220
** Write the current number of pages in database P1 to memory cell P2.
7706977221
*/
77070
-case OP_Pagecount: { /* out2-prerelease */
77222
+case OP_Pagecount: { /* out2 */
77223
+ pOut = out2Prerelease(p, pOp);
7707177224
pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
7707277225
break;
7707377226
}
7707477227
#endif
7707577228
@@ -77081,14 +77234,15 @@
7708177234
** Do not let the maximum page count fall below the current page count and
7708277235
** do not change the maximum page count value if P3==0.
7708377236
**
7708477237
** Store the maximum page count after the change in register P2.
7708577238
*/
77086
-case OP_MaxPgcnt: { /* out2-prerelease */
77239
+case OP_MaxPgcnt: { /* out2 */
7708777240
unsigned int newMax;
7708877241
Btree *pBt;
7708977242
77243
+ pOut = out2Prerelease(p, pOp);
7709077244
pBt = db->aDb[pOp->p1].pBt;
7709177245
newMax = 0;
7709277246
if( pOp->p3 ){
7709377247
newMax = sqlite3BtreeLastPage(pBt);
7709477248
if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3;
@@ -77113,13 +77267,10 @@
7711377267
*/
7711477268
case OP_Init: { /* jump */
7711577269
char *zTrace;
7711677270
char *z;
7711777271
77118
- if( pOp->p2 ){
77119
- pc = pOp->p2 - 1;
77120
- }
7712177272
#ifndef SQLITE_OMIT_TRACE
7712277273
if( db->xTrace
7712377274
&& !p->doingRerun
7712477275
&& (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
7712577276
){
@@ -77143,10 +77294,11 @@
7714377294
){
7714477295
sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
7714577296
}
7714677297
#endif /* SQLITE_DEBUG */
7714777298
#endif /* SQLITE_OMIT_TRACE */
77299
+ if( pOp->p2 ) goto jump_to_p2;
7714877300
break;
7714977301
}
7715077302
7715177303
7715277304
/* Opcode: Noop * * * * *
@@ -77174,31 +77326,31 @@
7717477326
}
7717577327
7717677328
#ifdef VDBE_PROFILE
7717777329
{
7717877330
u64 endTime = sqlite3Hwtime();
77179
- if( endTime>start ) pOp->cycles += endTime - start;
77180
- pOp->cnt++;
77331
+ if( endTime>start ) pOrigOp->cycles += endTime - start;
77332
+ pOrigOp->cnt++;
7718177333
}
7718277334
#endif
7718377335
7718477336
/* The following code adds nothing to the actual functionality
7718577337
** of the program. It is only here for testing and debugging.
7718677338
** On the other hand, it does burn CPU cycles every time through
7718777339
** the evaluator loop. So we can leave it out when NDEBUG is defined.
7718877340
*/
7718977341
#ifndef NDEBUG
77190
- assert( pc>=-1 && pc<p->nOp );
77342
+ assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] );
7719177343
7719277344
#ifdef SQLITE_DEBUG
7719377345
if( db->flags & SQLITE_VdbeTrace ){
7719477346
if( rc!=0 ) printf("rc=%d\n",rc);
77195
- if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){
77196
- registerTrace(pOp->p2, &aMem[pOp->p2]);
77347
+ if( pOrigOp->opflags & (OPFLG_OUT2) ){
77348
+ registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
7719777349
}
77198
- if( pOp->opflags & OPFLG_OUT3 ){
77199
- registerTrace(pOp->p3, &aMem[pOp->p3]);
77350
+ if( pOrigOp->opflags & OPFLG_OUT3 ){
77351
+ registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
7720077352
}
7720177353
}
7720277354
#endif /* SQLITE_DEBUG */
7720377355
#endif /* NDEBUG */
7720477356
} /* The end of the for(;;) loop the loops through opcodes */
@@ -77209,11 +77361,11 @@
7720977361
vdbe_error_halt:
7721077362
assert( rc );
7721177363
p->rc = rc;
7721277364
testcase( sqlite3GlobalConfig.xLog!=0 );
7721377365
sqlite3_log(rc, "statement aborts at %d: [%s] %s",
77214
- pc, p->zSql, p->zErrMsg);
77366
+ (int)(pOp - aOp), p->zSql, p->zErrMsg);
7721577367
sqlite3VdbeHalt(p);
7721677368
if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
7721777369
rc = SQLITE_ERROR;
7721877370
if( resetSchemaOnFault>0 ){
7721977371
sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
@@ -78035,20 +78187,23 @@
7803578187
**
7803678188
** In both cases, the effects of the main thread seeing (bDone==0) even
7803778189
** after the thread has finished are not dire. So we don't worry about
7803878190
** memory barriers and such here.
7803978191
*/
78192
+typedef int (*SorterCompare)(SortSubtask*,int*,const void*,int,const void*,int);
7804078193
struct SortSubtask {
7804178194
SQLiteThread *pThread; /* Background thread, if any */
7804278195
int bDone; /* Set if thread is finished but not joined */
7804378196
VdbeSorter *pSorter; /* Sorter that owns this sub-task */
7804478197
UnpackedRecord *pUnpacked; /* Space to unpack a record */
7804578198
SorterList list; /* List for thread to write to a PMA */
7804678199
int nPMA; /* Number of PMAs currently in file */
78200
+ SorterCompare xCompare; /* Compare function to use */
7804778201
SorterFile file; /* Temp file for level-0 PMAs */
7804878202
SorterFile file2; /* Space for other PMAs */
7804978203
};
78204
+
7805078205
7805178206
/*
7805278207
** Main sorter structure. A single instance of this is allocated for each
7805378208
** sorter cursor created by the VDBE.
7805478209
**
@@ -78072,12 +78227,16 @@
7807278227
int nMemory; /* Size of list.aMemory allocation in bytes */
7807378228
u8 bUsePMA; /* True if one or more PMAs created */
7807478229
u8 bUseThreads; /* True to use background threads */
7807578230
u8 iPrev; /* Previous thread used to flush PMA */
7807678231
u8 nTask; /* Size of aTask[] array */
78232
+ u8 typeMask;
7807778233
SortSubtask aTask[1]; /* One or more subtasks */
7807878234
};
78235
+
78236
+#define SORTER_TYPE_INTEGER 0x01
78237
+#define SORTER_TYPE_TEXT 0x02
7807978238
7808078239
/*
7808178240
** An instance of the following object is used to read records out of a
7808278241
** PMA, in sorted order. The next key to be read is cached in nKey/aKey.
7808378242
** aKey might point into aMap or into aBuffer. If neither of those locations
@@ -78486,35 +78645,165 @@
7848678645
rc = vdbePmaReaderNext(pReadr);
7848778646
}
7848878647
return rc;
7848978648
}
7849078649
78650
+/*
78651
+** A version of vdbeSorterCompare() that assumes that it has already been
78652
+** determined that the first field of key1 is equal to the first field of
78653
+** key2.
78654
+*/
78655
+static int vdbeSorterCompareTail(
78656
+ SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78657
+ int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78658
+ const void *pKey1, int nKey1, /* Left side of comparison */
78659
+ const void *pKey2, int nKey2 /* Right side of comparison */
78660
+){
78661
+ UnpackedRecord *r2 = pTask->pUnpacked;
78662
+ if( *pbKey2Cached==0 ){
78663
+ sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
78664
+ *pbKey2Cached = 1;
78665
+ }
78666
+ return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1);
78667
+}
7849178668
7849278669
/*
7849378670
** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2,
7849478671
** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences
7849578672
** used by the comparison. Return the result of the comparison.
7849678673
**
78497
-** Before returning, object (pTask->pUnpacked) is populated with the
78498
-** unpacked version of key2. Or, if pKey2 is passed a NULL pointer, then it
78499
-** is assumed that the (pTask->pUnpacked) structure already contains the
78500
-** unpacked key to use as key2.
78674
+** If IN/OUT parameter *pbKey2Cached is true when this function is called,
78675
+** it is assumed that (pTask->pUnpacked) contains the unpacked version
78676
+** of key2. If it is false, (pTask->pUnpacked) is populated with the unpacked
78677
+** version of key2 and *pbKey2Cached set to true before returning.
7850178678
**
7850278679
** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set
7850378680
** to SQLITE_NOMEM.
7850478681
*/
7850578682
static int vdbeSorterCompare(
7850678683
SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78684
+ int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
7850778685
const void *pKey1, int nKey1, /* Left side of comparison */
7850878686
const void *pKey2, int nKey2 /* Right side of comparison */
7850978687
){
7851078688
UnpackedRecord *r2 = pTask->pUnpacked;
78511
- if( pKey2 ){
78689
+ if( !*pbKey2Cached ){
7851278690
sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
78691
+ *pbKey2Cached = 1;
7851378692
}
7851478693
return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
7851578694
}
78695
+
78696
+/*
78697
+** A specially optimized version of vdbeSorterCompare() that assumes that
78698
+** the first field of each key is a TEXT value and that the collation
78699
+** sequence to compare them with is BINARY.
78700
+*/
78701
+static int vdbeSorterCompareText(
78702
+ SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78703
+ int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78704
+ const void *pKey1, int nKey1, /* Left side of comparison */
78705
+ const void *pKey2, int nKey2 /* Right side of comparison */
78706
+){
78707
+ const u8 * const p1 = (const u8 * const)pKey1;
78708
+ const u8 * const p2 = (const u8 * const)pKey2;
78709
+ const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
78710
+ const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
78711
+
78712
+ int n1;
78713
+ int n2;
78714
+ int res;
78715
+
78716
+ getVarint32(&p1[1], n1); n1 = (n1 - 13) / 2;
78717
+ getVarint32(&p2[1], n2); n2 = (n2 - 13) / 2;
78718
+ res = memcmp(v1, v2, MIN(n1, n2));
78719
+ if( res==0 ){
78720
+ res = n1 - n2;
78721
+ }
78722
+
78723
+ if( res==0 ){
78724
+ if( pTask->pSorter->pKeyInfo->nField>1 ){
78725
+ res = vdbeSorterCompareTail(
78726
+ pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
78727
+ );
78728
+ }
78729
+ }else{
78730
+ if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
78731
+ res = res * -1;
78732
+ }
78733
+ }
78734
+
78735
+ return res;
78736
+}
78737
+
78738
+/*
78739
+** A specially optimized version of vdbeSorterCompare() that assumes that
78740
+** the first field of each key is an INTEGER value.
78741
+*/
78742
+static int vdbeSorterCompareInt(
78743
+ SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78744
+ int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78745
+ const void *pKey1, int nKey1, /* Left side of comparison */
78746
+ const void *pKey2, int nKey2 /* Right side of comparison */
78747
+){
78748
+ const u8 * const p1 = (const u8 * const)pKey1;
78749
+ const u8 * const p2 = (const u8 * const)pKey2;
78750
+ const int s1 = p1[1]; /* Left hand serial type */
78751
+ const int s2 = p2[1]; /* Right hand serial type */
78752
+ const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
78753
+ const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
78754
+ int res; /* Return value */
78755
+
78756
+ assert( (s1>0 && s1<7) || s1==8 || s1==9 );
78757
+ assert( (s2>0 && s2<7) || s2==8 || s2==9 );
78758
+
78759
+ if( s1>7 && s2>7 ){
78760
+ res = s1 - s2;
78761
+ }else{
78762
+ if( s1==s2 ){
78763
+ if( (*v1 ^ *v2) & 0x80 ){
78764
+ /* The two values have different signs */
78765
+ res = (*v1 & 0x80) ? -1 : +1;
78766
+ }else{
78767
+ /* The two values have the same sign. Compare using memcmp(). */
78768
+ static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 };
78769
+ int i;
78770
+ res = 0;
78771
+ for(i=0; i<aLen[s1]; i++){
78772
+ if( (res = v1[i] - v2[i]) ) break;
78773
+ }
78774
+ }
78775
+ }else{
78776
+ if( s2>7 ){
78777
+ res = +1;
78778
+ }else if( s1>7 ){
78779
+ res = -1;
78780
+ }else{
78781
+ res = s1 - s2;
78782
+ }
78783
+ assert( res!=0 );
78784
+
78785
+ if( res>0 ){
78786
+ if( *v1 & 0x80 ) res = -1;
78787
+ }else{
78788
+ if( *v2 & 0x80 ) res = +1;
78789
+ }
78790
+ }
78791
+ }
78792
+
78793
+ if( res==0 ){
78794
+ if( pTask->pSorter->pKeyInfo->nField>1 ){
78795
+ res = vdbeSorterCompareTail(
78796
+ pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
78797
+ );
78798
+ }
78799
+ }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
78800
+ res = res * -1;
78801
+ }
78802
+
78803
+ return res;
78804
+}
7851678805
7851778806
/*
7851878807
** Initialize the temporary index cursor just opened as a sorter cursor.
7851978808
**
7852078809
** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField)
@@ -78579,13 +78868,17 @@
7857978868
rc = SQLITE_NOMEM;
7858078869
}else{
7858178870
pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
7858278871
memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
7858378872
pKeyInfo->db = 0;
78584
- if( nField && nWorker==0 ) pKeyInfo->nField = nField;
78873
+ if( nField && nWorker==0 ){
78874
+ pKeyInfo->nXField += (pKeyInfo->nField - nField);
78875
+ pKeyInfo->nField = nField;
78876
+ }
7858578877
pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
7858678878
pSorter->nTask = nWorker + 1;
78879
+ pSorter->iPrev = nWorker-1;
7858778880
pSorter->bUseThreads = (pSorter->nTask>1);
7858878881
pSorter->db = db;
7858978882
for(i=0; i<pSorter->nTask; i++){
7859078883
SortSubtask *pTask = &pSorter->aTask[i];
7859178884
pTask->pSorter = pSorter;
@@ -78607,10 +78900,16 @@
7860778900
pSorter->nMemory = pgsz;
7860878901
pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
7860978902
if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM;
7861078903
}
7861178904
}
78905
+
78906
+ if( (pKeyInfo->nField+pKeyInfo->nXField)<13
78907
+ && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
78908
+ ){
78909
+ pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
78910
+ }
7861278911
}
7861378912
7861478913
return rc;
7861578914
}
7861678915
#undef nWorker /* Defined at the top of this function */
@@ -78631,34 +78930,28 @@
7863178930
** Free all resources owned by the object indicated by argument pTask. All
7863278931
** fields of *pTask are zeroed before returning.
7863378932
*/
7863478933
static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){
7863578934
sqlite3DbFree(db, pTask->pUnpacked);
78636
- pTask->pUnpacked = 0;
7863778935
#if SQLITE_MAX_WORKER_THREADS>0
7863878936
/* pTask->list.aMemory can only be non-zero if it was handed memory
7863978937
** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */
7864078938
if( pTask->list.aMemory ){
7864178939
sqlite3_free(pTask->list.aMemory);
78642
- pTask->list.aMemory = 0;
7864378940
}else
7864478941
#endif
7864578942
{
7864678943
assert( pTask->list.aMemory==0 );
7864778944
vdbeSorterRecordFree(0, pTask->list.pList);
7864878945
}
78649
- pTask->list.pList = 0;
7865078946
if( pTask->file.pFd ){
7865178947
sqlite3OsCloseFree(pTask->file.pFd);
78652
- pTask->file.pFd = 0;
78653
- pTask->file.iEof = 0;
7865478948
}
7865578949
if( pTask->file2.pFd ){
7865678950
sqlite3OsCloseFree(pTask->file2.pFd);
78657
- pTask->file2.pFd = 0;
78658
- pTask->file2.iEof = 0;
7865978951
}
78952
+ memset(pTask, 0, sizeof(SortSubtask));
7866078953
}
7866178954
7866278955
#ifdef SQLITE_DEBUG_SORTER_THREADS
7866378956
static void vdbeSorterWorkDebug(SortSubtask *pTask, const char *zEvent){
7866478957
i64 t;
@@ -78834,10 +79127,11 @@
7883479127
vdbeMergeEngineFree(pSorter->pMerger);
7883579128
pSorter->pMerger = 0;
7883679129
for(i=0; i<pSorter->nTask; i++){
7883779130
SortSubtask *pTask = &pSorter->aTask[i];
7883879131
vdbeSortSubtaskCleanup(db, pTask);
79132
+ pTask->pSorter = pSorter;
7883979133
}
7884079134
if( pSorter->list.aMemory==0 ){
7884179135
vdbeSorterRecordFree(0, pSorter->list.pList);
7884279136
}
7884379137
pSorter->list.pList = 0;
@@ -78943,31 +79237,45 @@
7894379237
SorterRecord *p2, /* Second list to merge */
7894479238
SorterRecord **ppOut /* OUT: Head of merged list */
7894579239
){
7894679240
SorterRecord *pFinal = 0;
7894779241
SorterRecord **pp = &pFinal;
78948
- void *pVal2 = p2 ? SRVAL(p2) : 0;
79242
+ int bCached = 0;
7894979243
7895079244
while( p1 && p2 ){
7895179245
int res;
78952
- res = vdbeSorterCompare(pTask, SRVAL(p1), p1->nVal, pVal2, p2->nVal);
79246
+ res = pTask->xCompare(
79247
+ pTask, &bCached, SRVAL(p1), p1->nVal, SRVAL(p2), p2->nVal
79248
+ );
79249
+
7895379250
if( res<=0 ){
7895479251
*pp = p1;
7895579252
pp = &p1->u.pNext;
7895679253
p1 = p1->u.pNext;
78957
- pVal2 = 0;
7895879254
}else{
7895979255
*pp = p2;
78960
- pp = &p2->u.pNext;
79256
+ pp = &p2->u.pNext;
7896179257
p2 = p2->u.pNext;
78962
- if( p2==0 ) break;
78963
- pVal2 = SRVAL(p2);
79258
+ bCached = 0;
7896479259
}
7896579260
}
7896679261
*pp = p1 ? p1 : p2;
7896779262
*ppOut = pFinal;
7896879263
}
79264
+
79265
+/*
79266
+** Return the SorterCompare function to compare values collected by the
79267
+** sorter object passed as the only argument.
79268
+*/
79269
+static SorterCompare vdbeSorterGetCompare(VdbeSorter *p){
79270
+ if( p->typeMask==SORTER_TYPE_INTEGER ){
79271
+ return vdbeSorterCompareInt;
79272
+ }else if( p->typeMask==SORTER_TYPE_TEXT ){
79273
+ return vdbeSorterCompareText;
79274
+ }
79275
+ return vdbeSorterCompare;
79276
+}
7896979277
7897079278
/*
7897179279
** Sort the linked list of records headed at pTask->pList. Return
7897279280
** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if
7897379281
** an error occurs.
@@ -78979,16 +79287,18 @@
7897979287
int rc;
7898079288
7898179289
rc = vdbeSortAllocUnpacked(pTask);
7898279290
if( rc!=SQLITE_OK ) return rc;
7898379291
79292
+ p = pList->pList;
79293
+ pTask->xCompare = vdbeSorterGetCompare(pTask->pSorter);
79294
+
7898479295
aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *));
7898579296
if( !aSlot ){
7898679297
return SQLITE_NOMEM;
7898779298
}
7898879299
78989
- p = pList->pList;
7899079300
while( p ){
7899179301
SorterRecord *pNext;
7899279302
if( pList->aMemory ){
7899379303
if( (u8*)p==pList->aMemory ){
7899479304
pNext = 0;
@@ -79198,28 +79508,27 @@
7919879508
/* Update contents of aTree[] */
7919979509
if( rc==SQLITE_OK ){
7920079510
int i; /* Index of aTree[] to recalculate */
7920179511
PmaReader *pReadr1; /* First PmaReader to compare */
7920279512
PmaReader *pReadr2; /* Second PmaReader to compare */
79203
- u8 *pKey2; /* To pReadr2->aKey, or 0 if record cached */
79513
+ int bCached = 0;
7920479514
7920579515
/* Find the first two PmaReaders to compare. The one that was just
7920679516
** advanced (iPrev) and the one next to it in the array. */
7920779517
pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)];
7920879518
pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)];
79209
- pKey2 = pReadr2->aKey;
7921079519
7921179520
for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){
7921279521
/* Compare pReadr1 and pReadr2. Store the result in variable iRes. */
7921379522
int iRes;
7921479523
if( pReadr1->pFd==0 ){
7921579524
iRes = +1;
7921679525
}else if( pReadr2->pFd==0 ){
7921779526
iRes = -1;
7921879527
}else{
79219
- iRes = vdbeSorterCompare(pTask,
79220
- pReadr1->aKey, pReadr1->nKey, pKey2, pReadr2->nKey
79528
+ iRes = pTask->xCompare(pTask, &bCached,
79529
+ pReadr1->aKey, pReadr1->nKey, pReadr2->aKey, pReadr2->nKey
7922179530
);
7922279531
}
7922379532
7922479533
/* If pReadr1 contained the smaller value, set aTree[i] to its index.
7922579534
** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this
@@ -79237,13 +79546,13 @@
7923779546
** is sorted from oldest to newest, so pReadr1 contains older values
7923879547
** than pReadr2 iff (pReadr1<pReadr2). */
7923979548
if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){
7924079549
pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr);
7924179550
pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79242
- pKey2 = pReadr2->aKey;
79551
+ bCached = 0;
7924379552
}else{
79244
- if( pReadr1->pFd ) pKey2 = 0;
79553
+ if( pReadr1->pFd ) bCached = 0;
7924579554
pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr);
7924679555
pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
7924779556
}
7924879557
}
7924979558
*pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0);
@@ -79346,10 +79655,20 @@
7934679655
SorterRecord *pNew; /* New list element */
7934779656
7934879657
int bFlush; /* True to flush contents of memory to PMA */
7934979658
int nReq; /* Bytes of memory required */
7935079659
int nPMA; /* Bytes of PMA space required */
79660
+ int t; /* serial type of first record field */
79661
+
79662
+ getVarint32((const u8*)&pVal->z[1], t);
79663
+ if( t>0 && t<10 && t!=7 ){
79664
+ pSorter->typeMask &= SORTER_TYPE_INTEGER;
79665
+ }else if( t>10 && (t & 0x01) ){
79666
+ pSorter->typeMask &= SORTER_TYPE_TEXT;
79667
+ }else{
79668
+ pSorter->typeMask = 0;
79669
+ }
7935179670
7935279671
assert( pSorter );
7935379672
7935479673
/* Figure out whether or not the current contents of memory should be
7935579674
** flushed to a PMA before continuing. If so, do so.
@@ -79611,14 +79930,16 @@
7961179930
if( p1->pFd==0 ){
7961279931
iRes = i2;
7961379932
}else if( p2->pFd==0 ){
7961479933
iRes = i1;
7961579934
}else{
79935
+ SortSubtask *pTask = pMerger->pTask;
79936
+ int bCached = 0;
7961679937
int res;
79617
- assert( pMerger->pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
79618
- res = vdbeSorterCompare(
79619
- pMerger->pTask, p1->aKey, p1->nKey, p2->aKey, p2->nKey
79938
+ assert( pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
79939
+ res = pTask->xCompare(
79940
+ pTask, &bCached, p1->aKey, p1->nKey, p2->aKey, p2->nKey
7962079941
);
7962179942
if( res<=0 ){
7962279943
iRes = i1;
7962379944
}else{
7962479945
iRes = i2;
@@ -79638,15 +79959,16 @@
7963879959
*/
7963979960
#define INCRINIT_NORMAL 0
7964079961
#define INCRINIT_TASK 1
7964179962
#define INCRINIT_ROOT 2
7964279963
79643
-/* Forward reference.
79644
-** The vdbeIncrMergeInit() and vdbePmaReaderIncrMergeInit() routines call each
79645
-** other (when building a merge tree).
79964
+/*
79965
+** Forward reference required as the vdbeIncrMergeInit() and
79966
+** vdbePmaReaderIncrInit() routines are called mutually recursively when
79967
+** building a merge tree.
7964679968
*/
79647
-static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode);
79969
+static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode);
7964879970
7964979971
/*
7965079972
** Initialize the MergeEngine object passed as the second argument. Once this
7965179973
** function returns, the first key of merged data may be read from the
7965279974
** MergeEngine object in the usual fashion.
@@ -79689,11 +80011,11 @@
7968980011
** the main thread to fill its buffer. So calling PmaReaderNext()
7969080012
** on this PmaReader before any of the multi-threaded PmaReaders takes
7969180013
** better advantage of multi-processor hardware. */
7969280014
rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]);
7969380015
}else{
79694
- rc = vdbePmaReaderIncrMergeInit(&pMerger->aReadr[i], INCRINIT_NORMAL);
80016
+ rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i], INCRINIT_NORMAL);
7969580017
}
7969680018
if( rc!=SQLITE_OK ) return rc;
7969780019
}
7969880020
7969980021
for(i=pMerger->nTree-1; i>0; i--){
@@ -79701,21 +80023,19 @@
7970180023
}
7970280024
return pTask->pUnpacked->errCode;
7970380025
}
7970480026
7970580027
/*
79706
-** Initialize the IncrMerge field of a PmaReader.
79707
-**
79708
-** If the PmaReader passed as the first argument is not an incremental-reader
79709
-** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it serves
79710
-** to open and/or initialize the temp file related fields of the IncrMerge
80028
+** The PmaReader passed as the first argument is guaranteed to be an
80029
+** incremental-reader (pReadr->pIncr!=0). This function serves to open
80030
+** and/or initialize the temp file related fields of the IncrMerge
7971180031
** object at (pReadr->pIncr).
7971280032
**
7971380033
** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders
79714
-** in the sub-tree headed by pReadr are also initialized. Data is then loaded
79715
-** into the buffers belonging to pReadr and it is set to
79716
-** point to the first key in its range.
80034
+** in the sub-tree headed by pReadr are also initialized. Data is then
80035
+** loaded into the buffers belonging to pReadr and it is set to point to
80036
+** the first key in its range.
7971780037
**
7971880038
** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed
7971980039
** to be a multi-threaded PmaReader and this function is being called in a
7972080040
** background thread. In this case all PmaReaders in the sub-tree are
7972180041
** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to
@@ -79738,93 +80058,112 @@
7973880058
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
7973980059
*/
7974080060
static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode){
7974180061
int rc = SQLITE_OK;
7974280062
IncrMerger *pIncr = pReadr->pIncr;
80063
+ SortSubtask *pTask = pIncr->pTask;
80064
+ sqlite3 *db = pTask->pSorter->db;
7974380065
7974480066
/* eMode is always INCRINIT_NORMAL in single-threaded mode */
7974580067
assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
7974680068
79747
- if( pIncr ){
79748
- SortSubtask *pTask = pIncr->pTask;
79749
- sqlite3 *db = pTask->pSorter->db;
79750
-
79751
- rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
79752
-
79753
- /* Set up the required files for pIncr. A multi-theaded IncrMerge object
79754
- ** requires two temp files to itself, whereas a single-threaded object
79755
- ** only requires a region of pTask->file2. */
79756
- if( rc==SQLITE_OK ){
79757
- int mxSz = pIncr->mxSz;
79758
-#if SQLITE_MAX_WORKER_THREADS>0
79759
- if( pIncr->bUseThread ){
79760
- rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
79761
- if( rc==SQLITE_OK ){
79762
- rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
79763
- }
79764
- }else
79765
-#endif
79766
- /*if( !pIncr->bUseThread )*/{
79767
- if( pTask->file2.pFd==0 ){
79768
- assert( pTask->file2.iEof>0 );
79769
- rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
79770
- pTask->file2.iEof = 0;
79771
- }
79772
- if( rc==SQLITE_OK ){
79773
- pIncr->aFile[1].pFd = pTask->file2.pFd;
79774
- pIncr->iStartOff = pTask->file2.iEof;
79775
- pTask->file2.iEof += mxSz;
79776
- }
79777
- }
79778
- }
79779
-
79780
-#if SQLITE_MAX_WORKER_THREADS>0
79781
- if( rc==SQLITE_OK && pIncr->bUseThread ){
79782
- /* Use the current thread to populate aFile[1], even though this
79783
- ** PmaReader is multi-threaded. The reason being that this function
79784
- ** is already running in background thread pIncr->pTask->thread. */
79785
- assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK );
79786
- rc = vdbeIncrPopulate(pIncr);
79787
- }
79788
-#endif
79789
-
79790
- if( rc==SQLITE_OK
79791
- && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK)
79792
- ){
79793
- rc = vdbePmaReaderNext(pReadr);
79794
- }
79795
- }
80069
+ rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
80070
+
80071
+ /* Set up the required files for pIncr. A multi-theaded IncrMerge object
80072
+ ** requires two temp files to itself, whereas a single-threaded object
80073
+ ** only requires a region of pTask->file2. */
80074
+ if( rc==SQLITE_OK ){
80075
+ int mxSz = pIncr->mxSz;
80076
+#if SQLITE_MAX_WORKER_THREADS>0
80077
+ if( pIncr->bUseThread ){
80078
+ rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
80079
+ if( rc==SQLITE_OK ){
80080
+ rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
80081
+ }
80082
+ }else
80083
+#endif
80084
+ /*if( !pIncr->bUseThread )*/{
80085
+ if( pTask->file2.pFd==0 ){
80086
+ assert( pTask->file2.iEof>0 );
80087
+ rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
80088
+ pTask->file2.iEof = 0;
80089
+ }
80090
+ if( rc==SQLITE_OK ){
80091
+ pIncr->aFile[1].pFd = pTask->file2.pFd;
80092
+ pIncr->iStartOff = pTask->file2.iEof;
80093
+ pTask->file2.iEof += mxSz;
80094
+ }
80095
+ }
80096
+ }
80097
+
80098
+#if SQLITE_MAX_WORKER_THREADS>0
80099
+ if( rc==SQLITE_OK && pIncr->bUseThread ){
80100
+ /* Use the current thread to populate aFile[1], even though this
80101
+ ** PmaReader is multi-threaded. If this is an INCRINIT_TASK object,
80102
+ ** then this function is already running in background thread
80103
+ ** pIncr->pTask->thread.
80104
+ **
80105
+ ** If this is the INCRINIT_ROOT object, then it is running in the
80106
+ ** main VDBE thread. But that is Ok, as that thread cannot return
80107
+ ** control to the VDBE or proceed with anything useful until the
80108
+ ** first results are ready from this merger object anyway.
80109
+ */
80110
+ assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK );
80111
+ rc = vdbeIncrPopulate(pIncr);
80112
+ }
80113
+#endif
80114
+
80115
+ if( rc==SQLITE_OK && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) ){
80116
+ rc = vdbePmaReaderNext(pReadr);
80117
+ }
80118
+
7979680119
return rc;
7979780120
}
7979880121
7979980122
#if SQLITE_MAX_WORKER_THREADS>0
7980080123
/*
7980180124
** The main routine for vdbePmaReaderIncrMergeInit() operations run in
7980280125
** background threads.
7980380126
*/
79804
-static void *vdbePmaReaderBgInit(void *pCtx){
80127
+static void *vdbePmaReaderBgIncrInit(void *pCtx){
7980580128
PmaReader *pReader = (PmaReader*)pCtx;
7980680129
void *pRet = SQLITE_INT_TO_PTR(
7980780130
vdbePmaReaderIncrMergeInit(pReader,INCRINIT_TASK)
7980880131
);
7980980132
pReader->pIncr->pTask->bDone = 1;
7981080133
return pRet;
7981180134
}
80135
+#endif
7981280136
7981380137
/*
79814
-** Use a background thread to invoke vdbePmaReaderIncrMergeInit(INCRINIT_TASK)
79815
-** on the PmaReader object passed as the first argument.
79816
-**
79817
-** This call will initialize the various fields of the pReadr->pIncr
79818
-** structure and, if it is a multi-threaded IncrMerger, launch a
79819
-** background thread to populate aFile[1].
80138
+** If the PmaReader passed as the first argument is not an incremental-reader
80139
+** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it invokes
80140
+** the vdbePmaReaderIncrMergeInit() function with the parameters passed to
80141
+** this routine to initialize the incremental merge.
80142
+**
80143
+** If the IncrMerger object is multi-threaded (IncrMerger.bUseThread==1),
80144
+** then a background thread is launched to call vdbePmaReaderIncrMergeInit().
80145
+** Or, if the IncrMerger is single threaded, the same function is called
80146
+** using the current thread.
7982080147
*/
79821
-static int vdbePmaReaderBgIncrInit(PmaReader *pReadr){
79822
- void *pCtx = (void*)pReadr;
79823
- return vdbeSorterCreateThread(pReadr->pIncr->pTask, vdbePmaReaderBgInit, pCtx);
80148
+static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode){
80149
+ IncrMerger *pIncr = pReadr->pIncr; /* Incremental merger */
80150
+ int rc = SQLITE_OK; /* Return code */
80151
+ if( pIncr ){
80152
+#if SQLITE_MAX_WORKER_THREADS>0
80153
+ assert( pIncr->bUseThread==0 || eMode==INCRINIT_TASK );
80154
+ if( pIncr->bUseThread ){
80155
+ void *pCtx = (void*)pReadr;
80156
+ rc = vdbeSorterCreateThread(pIncr->pTask, vdbePmaReaderBgIncrInit, pCtx);
80157
+ }else
80158
+#endif
80159
+ {
80160
+ rc = vdbePmaReaderIncrMergeInit(pReadr, eMode);
80161
+ }
80162
+ }
80163
+ return rc;
7982480164
}
79825
-#endif
7982680165
7982780166
/*
7982880167
** Allocate a new MergeEngine object to merge the contents of nPMA level-0
7982980168
** PMAs from pTask->file. If no error occurs, set *ppOut to point to
7983080169
** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut
@@ -80032,10 +80371,15 @@
8003280371
int rc; /* Return code */
8003380372
SortSubtask *pTask0 = &pSorter->aTask[0];
8003480373
MergeEngine *pMain = 0;
8003580374
#if SQLITE_MAX_WORKER_THREADS
8003680375
sqlite3 *db = pTask0->pSorter->db;
80376
+ int i;
80377
+ SorterCompare xCompare = vdbeSorterGetCompare(pSorter);
80378
+ for(i=0; i<pSorter->nTask; i++){
80379
+ pSorter->aTask[i].xCompare = xCompare;
80380
+ }
8003780381
#endif
8003880382
8003980383
rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
8004080384
if( rc==SQLITE_OK ){
8004180385
#if SQLITE_MAX_WORKER_THREADS
@@ -80060,19 +80404,25 @@
8006080404
vdbeIncrMergerSetThreads(pIncr);
8006180405
assert( pIncr->pTask!=pLast );
8006280406
}
8006380407
}
8006480408
for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
80409
+ /* Check that:
80410
+ **
80411
+ ** a) The incremental merge object is configured to use the
80412
+ ** right task, and
80413
+ ** b) If it is using task (nTask-1), it is configured to run
80414
+ ** in single-threaded mode. This is important, as the
80415
+ ** root merge (INCRINIT_ROOT) will be using the same task
80416
+ ** object.
80417
+ */
8006580418
PmaReader *p = &pMain->aReadr[iTask];
80066
- assert( p->pIncr==0 || p->pIncr->pTask==&pSorter->aTask[iTask] );
80067
- if( p->pIncr ){
80068
- if( iTask==pSorter->nTask-1 ){
80069
- rc = vdbePmaReaderIncrMergeInit(p, INCRINIT_TASK);
80070
- }else{
80071
- rc = vdbePmaReaderBgIncrInit(p);
80072
- }
80073
- }
80419
+ assert( p->pIncr==0 || (
80420
+ (p->pIncr->pTask==&pSorter->aTask[iTask]) /* a */
80421
+ && (iTask!=pSorter->nTask-1 || p->pIncr->bUseThread==0) /* b */
80422
+ ));
80423
+ rc = vdbePmaReaderIncrInit(p, INCRINIT_TASK);
8007480424
}
8007580425
}
8007680426
pMain = 0;
8007780427
}
8007880428
if( rc==SQLITE_OK ){
@@ -81023,11 +81373,11 @@
8102381373
** Should be transformed into:
8102481374
**
8102581375
** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase;
8102681376
**
8102781377
** The nSubquery parameter specifies how many levels of subquery the
81028
-** alias is removed from the original expression. The usually value is
81378
+** alias is removed from the original expression. The usual value is
8102981379
** zero but it might be more if the alias is contained within a subquery
8103081380
** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION
8103181381
** structures must be increased by the nSubquery amount.
8103281382
*/
8103381383
static void resolveAlias(
@@ -81043,11 +81393,10 @@
8104381393
sqlite3 *db; /* The database connection */
8104481394
8104581395
assert( iCol>=0 && iCol<pEList->nExpr );
8104681396
pOrig = pEList->a[iCol].pExpr;
8104781397
assert( pOrig!=0 );
81048
- assert( pOrig->flags & EP_Resolved );
8104981398
db = pParse->db;
8105081399
pDup = sqlite3ExprDup(db, pOrig, 0);
8105181400
if( pDup==0 ) return;
8105281401
if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
8105381402
incrAggFunctionDepth(pDup, nSubquery);
@@ -81937,13 +82286,15 @@
8193782286
pNew->flags |= EP_IntValue;
8193882287
pNew->u.iValue = iCol;
8193982288
if( pItem->pExpr==pE ){
8194082289
pItem->pExpr = pNew;
8194182290
}else{
81942
- assert( pItem->pExpr->op==TK_COLLATE );
81943
- assert( pItem->pExpr->pLeft==pE );
81944
- pItem->pExpr->pLeft = pNew;
82291
+ Expr *pParent = pItem->pExpr;
82292
+ assert( pParent->op==TK_COLLATE );
82293
+ while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
82294
+ assert( pParent->pLeft==pE );
82295
+ pParent->pLeft = pNew;
8194582296
}
8194682297
sqlite3ExprDelete(db, pE);
8194782298
pItem->u.x.iOrderByCol = (u16)iCol;
8194882299
pItem->done = 1;
8194982300
}else{
@@ -82139,11 +82490,11 @@
8213982490
** as if it were part of the sub-query, not the parent. This block
8214082491
** moves the pOrderBy down to the sub-query. It will be moved back
8214182492
** after the names have been resolved. */
8214282493
if( p->selFlags & SF_Converted ){
8214382494
Select *pSub = p->pSrc->a[0].pSelect;
82144
- assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy );
82495
+ assert( p->pSrc->nSrc==1 && p->pOrderBy );
8214582496
assert( pSub->pPrior && pSub->pOrderBy==0 );
8214682497
pSub->pOrderBy = p->pOrderBy;
8214782498
p->pOrderBy = 0;
8214882499
}
8214982500
@@ -82241,12 +82592,19 @@
8224182592
8224282593
/* Process the ORDER BY clause for singleton SELECT statements.
8224382594
** The ORDER BY clause for compounds SELECT statements is handled
8224482595
** below, after all of the result-sets for all of the elements of
8224582596
** the compound have been resolved.
82597
+ **
82598
+ ** If there is an ORDER BY clause on a term of a compound-select other
82599
+ ** than the right-most term, then that is a syntax error. But the error
82600
+ ** is not detected until much later, and so we need to go ahead and
82601
+ ** resolve those symbols on the incorrect ORDER BY for consistency.
8224682602
*/
82247
- if( !isCompound && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") ){
82603
+ if( isCompound<=nCompound /* Defer right-most ORDER BY of a compound */
82604
+ && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER")
82605
+ ){
8224882606
return WRC_Abort;
8224982607
}
8225082608
if( db->mallocFailed ){
8225182609
return WRC_Abort;
8225282610
}
@@ -83694,11 +84052,12 @@
8369484052
SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){
8369584053
int i;
8369684054
u32 m = 0;
8369784055
if( pList ){
8369884056
for(i=0; i<pList->nExpr; i++){
83699
- m |= pList->a[i].pExpr->flags;
84057
+ Expr *pExpr = pList->a[i].pExpr;
84058
+ if( ALWAYS(pExpr) ) m |= pExpr->flags;
8370084059
}
8370184060
}
8370284061
return m;
8370384062
}
8370484063
@@ -84134,11 +84493,11 @@
8413484493
/* Check to see if an existing table or index can be used to
8413584494
** satisfy the query. This is preferable to generating a new
8413684495
** ephemeral table.
8413784496
*/
8413884497
p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
84139
- if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
84498
+ if( pParse->nErr==0 && isCandidateForInOpt(p) ){
8414084499
sqlite3 *db = pParse->db; /* Database connection */
8414184500
Table *pTab; /* Table <table>. */
8414284501
Expr *pExpr; /* Expression <column> */
8414384502
i16 iCol; /* Index of column <column> */
8414484503
i16 iDb; /* Database idx for pTab */
@@ -84459,10 +84818,11 @@
8445984818
}
8446084819
sqlite3ExprDelete(pParse->db, pSel->pLimit);
8446184820
pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0,
8446284821
&sqlite3IntTokens[1]);
8446384822
pSel->iLimit = 0;
84823
+ pSel->selFlags &= ~SF_MultiValue;
8446484824
if( sqlite3Select(pParse, pSel, &dest) ){
8446584825
return 0;
8446684826
}
8446784827
rReg = dest.iSDParm;
8446884828
ExprSetVVAProperty(pExpr, EP_NoReduce);
@@ -85824,11 +86184,11 @@
8582486184
sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
8582586185
sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
8582686186
break;
8582786187
}
8582886188
case TK_ID: {
85829
- sqlite3TreeViewLine(pView,"ID %Q", pExpr->u.zToken);
86189
+ sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
8583086190
break;
8583186191
}
8583286192
#ifndef SQLITE_OMIT_CAST
8583386193
case TK_CAST: {
8583486194
/* Expressions of the form: CAST(pLeft AS token) */
@@ -86459,11 +86819,11 @@
8645986819
if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
8646086820
if( combinedFlags & EP_xIsSelect ) return 2;
8646186821
if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
8646286822
if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
8646386823
if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
86464
- if( ALWAYS((combinedFlags & EP_Reduced)==0) ){
86824
+ if( ALWAYS((combinedFlags & EP_Reduced)==0) && pA->op!=TK_STRING ){
8646586825
if( pA->iColumn!=pB->iColumn ) return 2;
8646686826
if( pA->iTable!=pB->iTable
8646786827
&& (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
8646886828
}
8646986829
}
@@ -86991,10 +87351,11 @@
8699187351
do {
8699287352
z += n;
8699387353
n = sqlite3GetToken(z, &token);
8699487354
}while( token==TK_SPACE );
8699587355
87356
+ if( token==TK_ILLEGAL ) break;
8699687357
zParent = sqlite3DbStrNDup(db, (const char *)z, n);
8699787358
if( zParent==0 ) break;
8699887359
sqlite3Dequote(zParent);
8699987360
if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
8700087361
char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
@@ -89217,18 +89578,21 @@
8921789578
pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
8921889579
}
8921989580
z = argv[2];
8922089581
8922189582
if( pIndex ){
89583
+ tRowcnt *aiRowEst = 0;
8922289584
int nCol = pIndex->nKeyCol+1;
8922389585
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
89224
- tRowcnt * const aiRowEst = pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(
89225
- sizeof(tRowcnt) * nCol
89226
- );
89227
- if( aiRowEst==0 ) pInfo->db->mallocFailed = 1;
89228
-#else
89229
- tRowcnt * const aiRowEst = 0;
89586
+ /* Index.aiRowEst may already be set here if there are duplicate
89587
+ ** sqlite_stat1 entries for this index. In that case just clobber
89588
+ ** the old data with the new instead of allocating a new array. */
89589
+ if( pIndex->aiRowEst==0 ){
89590
+ pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(sizeof(tRowcnt) * nCol);
89591
+ if( pIndex->aiRowEst==0 ) pInfo->db->mallocFailed = 1;
89592
+ }
89593
+ aiRowEst = pIndex->aiRowEst;
8923089594
#endif
8923189595
pIndex->bUnordered = 0;
8923289596
decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
8923389597
if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
8923489598
}else{
@@ -89887,11 +90251,11 @@
8988790251
}
8988890252
8988990253
sqlite3BtreeClose(pDb->pBt);
8989090254
pDb->pBt = 0;
8989190255
pDb->pSchema = 0;
89892
- sqlite3ResetAllSchemasOfConnection(db);
90256
+ sqlite3CollapseDatabaseArray(db);
8989390257
return;
8989490258
8989590259
detach_error:
8989690260
sqlite3_result_error(context, zErr, -1);
8989790261
}
@@ -89921,11 +90285,10 @@
8992190285
if(
8992290286
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
8992390287
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
8992490288
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
8992590289
){
89926
- pParse->nErr++;
8992790290
goto attach_end;
8992890291
}
8992990292
8993090293
#ifndef SQLITE_OMIT_AUTHORIZATION
8993190294
if( pAuthArg ){
@@ -90580,13 +90943,15 @@
9058090943
sqlite3 *db;
9058190944
Vdbe *v;
9058290945
9058390946
assert( pParse->pToplevel==0 );
9058490947
db = pParse->db;
90585
- if( db->mallocFailed ) return;
9058690948
if( pParse->nested ) return;
90587
- if( pParse->nErr ) return;
90949
+ if( db->mallocFailed || pParse->nErr ){
90950
+ if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR;
90951
+ return;
90952
+ }
9058890953
9058990954
/* Begin by generating some termination code at the end of the
9059090955
** vdbe program
9059190956
*/
9059290957
v = sqlite3GetVdbe(pParse);
@@ -90664,11 +91029,11 @@
9066491029
}
9066591030
9066691031
9066791032
/* Get the VDBE program ready for execution
9066891033
*/
90669
- if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
91034
+ if( v && pParse->nErr==0 && !db->mallocFailed ){
9067091035
assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
9067191036
/* A minimum of one cursor is required if autoincrement is used
9067291037
* See ticket [a696379c1f08866] */
9067391038
if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
9067491039
sqlite3VdbeMakeReady(v, pParse);
@@ -91199,18 +91564,16 @@
9119991564
sqlite3 *db = pParse->db;
9120091565
9120191566
if( ALWAYS(pName2!=0) && pName2->n>0 ){
9120291567
if( db->init.busy ) {
9120391568
sqlite3ErrorMsg(pParse, "corrupt database");
91204
- pParse->nErr++;
9120591569
return -1;
9120691570
}
9120791571
*pUnqual = pName2;
9120891572
iDb = sqlite3FindDb(db, pName1);
9120991573
if( iDb<0 ){
9121091574
sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
91211
- pParse->nErr++;
9121291575
return -1;
9121391576
}
9121491577
}else{
9121591578
assert( db->init.iDb==0 || db->init.busy );
9121691579
iDb = db->init.iDb;
@@ -91365,11 +91728,11 @@
9136591728
pTable = sqlite3FindTable(db, zName, zDb);
9136691729
if( pTable ){
9136791730
if( !noErr ){
9136891731
sqlite3ErrorMsg(pParse, "table %T already exists", pName);
9136991732
}else{
91370
- assert( !db->init.busy );
91733
+ assert( !db->init.busy || CORRUPT_DB );
9137191734
sqlite3CodeVerifySchema(pParse, iDb);
9137291735
}
9137391736
goto begin_table_error;
9137491737
}
9137591738
if( sqlite3FindIndex(db, zName, zDb)!=0 ){
@@ -91654,11 +92017,12 @@
9165492017
Column *pCol;
9165592018
9165692019
p = pParse->pNewTable;
9165792020
if( p==0 || NEVER(p->nCol<1) ) return;
9165892021
pCol = &p->aCol[p->nCol-1];
91659
- assert( pCol->zType==0 );
92022
+ assert( pCol->zType==0 || CORRUPT_DB );
92023
+ sqlite3DbFree(pParse->db, pCol->zType);
9166092024
pCol->zType = sqlite3NameFromToken(pParse->db, pType);
9166192025
pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst);
9166292026
}
9166392027
9166492028
/*
@@ -92888,10 +93252,11 @@
9288893252
if( db->mallocFailed ){
9288993253
goto exit_drop_table;
9289093254
}
9289193255
assert( pParse->nErr==0 );
9289293256
assert( pName->nSrc==1 );
93257
+ if( sqlite3ReadSchema(pParse) ) goto exit_drop_table;
9289393258
if( noErr ) db->suppressErr++;
9289493259
pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
9289593260
if( noErr ) db->suppressErr--;
9289693261
9289793262
if( pTab==0 ){
@@ -93201,11 +93566,12 @@
9320193566
sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
9320293567
}else{
9320393568
addr2 = sqlite3VdbeCurrentAddr(v);
9320493569
}
9320593570
sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
93206
- sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
93571
+ sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1);
93572
+ sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0);
9320793573
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
9320893574
sqlite3ReleaseTempReg(pParse, regRecord);
9320993575
sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
9321093576
sqlite3VdbeJumpHere(v, addr1);
9321193577
@@ -93294,12 +93660,11 @@
9329493660
int nExtra = 0; /* Space allocated for zExtra[] */
9329593661
int nExtraCol; /* Number of extra columns needed */
9329693662
char *zExtra = 0; /* Extra space after the Index object */
9329793663
Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
9329893664
93299
- assert( pParse->nErr==0 ); /* Never called with prior errors */
93300
- if( db->mallocFailed || IN_DECLARE_VTAB ){
93665
+ if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){
9330193666
goto exit_create_index;
9330293667
}
9330393668
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
9330493669
goto exit_create_index;
9330593670
}
@@ -94214,11 +94579,10 @@
9421494579
** operator with A. This routine shifts that operator over to B.
9421594580
*/
9421694581
SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){
9421794582
if( p ){
9421894583
int i;
94219
- assert( p->a || p->nSrc==0 );
9422094584
for(i=p->nSrc-1; i>0; i--){
9422194585
p->a[i].jointype = p->a[i-1].jointype;
9422294586
}
9422394587
p->a[0].jointype = 0;
9422494588
}
@@ -94461,12 +94825,11 @@
9446194825
char *zErr;
9446294826
int j;
9446394827
StrAccum errMsg;
9446494828
Table *pTab = pIdx->pTable;
9446594829
94466
- sqlite3StrAccumInit(&errMsg, 0, 0, 200);
94467
- errMsg.db = pParse->db;
94830
+ sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
9446894831
for(j=0; j<pIdx->nKeyCol; j++){
9446994832
char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
9447094833
if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
9447194834
sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
9447294835
sqlite3StrAccumAppend(&errMsg, ".", 1);
@@ -96291,17 +96654,17 @@
9629196654
){
9629296655
PrintfArguments x;
9629396656
StrAccum str;
9629496657
const char *zFormat;
9629596658
int n;
96659
+ sqlite3 *db = sqlite3_context_db_handle(context);
9629696660
9629796661
if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
9629896662
x.nArg = argc-1;
9629996663
x.nUsed = 0;
9630096664
x.apArg = argv+1;
96301
- sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH);
96302
- str.db = sqlite3_context_db_handle(context);
96665
+ sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
9630396666
sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x);
9630496667
n = str.nChar;
9630596668
sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
9630696669
SQLITE_DYNAMIC);
9630796670
}
@@ -96447,11 +96810,11 @@
9644796810
sqlite3_result_double(context, r);
9644896811
}
9644996812
#endif
9645096813
9645196814
/*
96452
-** Allocate nByte bytes of space using sqlite3_malloc(). If the
96815
+** Allocate nByte bytes of space using sqlite3Malloc(). If the
9645396816
** allocation fails, call sqlite3_result_error_nomem() to notify
9645496817
** the database handle that malloc() has failed and return NULL.
9645596818
** If nByte is larger than the maximum string or blob length, then
9645696819
** raise an SQLITE_TOOBIG exception and return NULL.
9645796820
*/
@@ -97116,11 +97479,11 @@
9711697479
int argc,
9711797480
sqlite3_value **argv
9711897481
){
9711997482
unsigned char *z, *zOut;
9712097483
int i;
97121
- zOut = z = sqlite3_malloc( argc*4+1 );
97484
+ zOut = z = sqlite3_malloc64( argc*4+1 );
9712297485
if( z==0 ){
9712397486
sqlite3_result_error_nomem(context);
9712497487
return;
9712597488
}
9712697489
for(i=0; i<argc; i++){
@@ -97264,11 +97627,11 @@
9726497627
sqlite3_result_error_toobig(context);
9726597628
sqlite3_free(zOut);
9726697629
return;
9726797630
}
9726897631
zOld = zOut;
97269
- zOut = sqlite3_realloc(zOut, (int)nOut);
97632
+ zOut = sqlite3_realloc64(zOut, (int)nOut);
9727097633
if( zOut==0 ){
9727197634
sqlite3_result_error_nomem(context);
9727297635
sqlite3_free(zOld);
9727397636
return;
9727497637
}
@@ -97626,12 +97989,11 @@
9762697989
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
9762797990
pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
9762897991
9762997992
if( pAccum ){
9763097993
sqlite3 *db = sqlite3_context_db_handle(context);
97631
- int firstTerm = pAccum->useMalloc==0;
97632
- pAccum->useMalloc = 2;
97994
+ int firstTerm = pAccum->mxAlloc==0;
9763397995
pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
9763497996
if( !firstTerm ){
9763597997
if( argc==2 ){
9763697998
zSep = (char*)sqlite3_value_text(argv[1]);
9763797999
nSep = sqlite3_value_bytes(argv[1]);
@@ -99047,11 +99409,12 @@
9904799409
int iFromCol; /* Idx of column in child table */
9904899410
Expr *pEq; /* tFromCol = OLD.tToCol */
9904999411
9905099412
iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
9905199413
assert( iFromCol>=0 );
99052
- tToCol.z = pIdx ? pTab->aCol[pIdx->aiColumn[i]].zName : "oid";
99414
+ assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
99415
+ tToCol.z = pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName;
9905399416
tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName;
9905499417
9905599418
tToCol.n = sqlite3Strlen30(tToCol.z);
9905699419
tFromCol.n = sqlite3Strlen30(tFromCol.z);
9905799420
@@ -99059,14 +99422,14 @@
9905999422
** that the "OLD.zToCol" term is on the LHS of the = operator, so
9906099423
** that the affinity and collation sequence associated with the
9906199424
** parent table are used for the comparison. */
9906299425
pEq = sqlite3PExpr(pParse, TK_EQ,
9906399426
sqlite3PExpr(pParse, TK_DOT,
99064
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld),
99065
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
99427
+ sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
99428
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
9906699429
, 0),
99067
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tFromCol)
99430
+ sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
9906899431
, 0);
9906999432
pWhere = sqlite3ExprAnd(db, pWhere, pEq);
9907099433
9907199434
/* For ON UPDATE, construct the next term of the WHEN clause.
9907299435
** The final WHEN clause will be like this:
@@ -99074,27 +99437,27 @@
9907499437
** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN)
9907599438
*/
9907699439
if( pChanges ){
9907799440
pEq = sqlite3PExpr(pParse, TK_IS,
9907899441
sqlite3PExpr(pParse, TK_DOT,
99079
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld),
99080
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol),
99442
+ sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
99443
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
9908199444
0),
9908299445
sqlite3PExpr(pParse, TK_DOT,
99083
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew),
99084
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol),
99446
+ sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
99447
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
9908599448
0),
9908699449
0);
9908799450
pWhen = sqlite3ExprAnd(db, pWhen, pEq);
9908899451
}
9908999452
9909099453
if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
9909199454
Expr *pNew;
9909299455
if( action==OE_Cascade ){
9909399456
pNew = sqlite3PExpr(pParse, TK_DOT,
99094
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew),
99095
- sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
99457
+ sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
99458
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
9909699459
, 0);
9909799460
}else if( action==OE_SetDflt ){
9909899461
Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
9909999462
if( pDflt ){
9910099463
pNew = sqlite3ExprDup(db, pDflt, 0);
@@ -99137,17 +99500,16 @@
9913799500
db->lookaside.bEnabled = 0;
9913899501
9913999502
pTrigger = (Trigger *)sqlite3DbMallocZero(db,
9914099503
sizeof(Trigger) + /* struct Trigger */
9914199504
sizeof(TriggerStep) + /* Single step in trigger program */
99142
- nFrom + 1 /* Space for pStep->target.z */
99505
+ nFrom + 1 /* Space for pStep->zTarget */
9914399506
);
9914499507
if( pTrigger ){
9914599508
pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1];
99146
- pStep->target.z = (char *)&pStep[1];
99147
- pStep->target.n = nFrom;
99148
- memcpy((char *)pStep->target.z, zFrom, nFrom);
99509
+ pStep->zTarget = (char *)&pStep[1];
99510
+ memcpy((char *)pStep->zTarget, zFrom, nFrom);
9914999511
9915099512
pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
9915199513
pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
9915299514
pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
9915399515
if( pWhen ){
@@ -99608,24 +99970,27 @@
9960899970
);
9960999971
9961099972
/*
9961199973
** This routine is called to handle SQL of the following forms:
9961299974
**
99613
-** insert into TABLE (IDLIST) values(EXPRLIST)
99975
+** insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),...
9961499976
** insert into TABLE (IDLIST) select
99977
+** insert into TABLE (IDLIST) default values
9961599978
**
9961699979
** The IDLIST following the table name is always optional. If omitted,
99617
-** then a list of all columns for the table is substituted. The IDLIST
99618
-** appears in the pColumn parameter. pColumn is NULL if IDLIST is omitted.
99980
+** then a list of all (non-hidden) columns for the table is substituted.
99981
+** The IDLIST appears in the pColumn parameter. pColumn is NULL if IDLIST
99982
+** is omitted.
9961999983
**
99620
-** The pList parameter holds EXPRLIST in the first form of the INSERT
99621
-** statement above, and pSelect is NULL. For the second form, pList is
99622
-** NULL and pSelect is a pointer to the select statement used to generate
99623
-** data for the insert.
99984
+** For the pSelect parameter holds the values to be inserted for the
99985
+** first two forms shown above. A VALUES clause is really just short-hand
99986
+** for a SELECT statement that omits the FROM clause and everything else
99987
+** that follows. If the pSelect parameter is NULL, that means that the
99988
+** DEFAULT VALUES form of the INSERT statement is intended.
9962499989
**
9962599990
** The code generated follows one of four templates. For a simple
99626
-** insert with data coming from a VALUES clause, the code executes
99991
+** insert with data coming from a single-row VALUES clause, the code executes
9962799992
** once straight down through. Pseudo-code follows (we call this
9962899993
** the "1st template"):
9962999994
**
9963099995
** open write cursor to <table> and its indices
9963199996
** put VALUES clause expressions into registers
@@ -99728,11 +100093,11 @@
99728100093
int iDb; /* Index of database holding TABLE */
99729100094
Db *pDb; /* The database containing table being inserted into */
99730100095
u8 useTempTable = 0; /* Store SELECT results in intermediate table */
99731100096
u8 appendFlag = 0; /* True if the insert is likely to be an append */
99732100097
u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
99733
- u8 bIdListInOrder = 1; /* True if IDLIST is in table order */
100098
+ u8 bIdListInOrder; /* True if IDLIST is in table order */
99734100099
ExprList *pList = 0; /* List of VALUES() to be inserted */
99735100100
99736100101
/* Register allocations */
99737100102
int regFromSelect = 0;/* Base register for data coming from SELECT */
99738100103
int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
@@ -99753,12 +100118,12 @@
99753100118
if( pParse->nErr || db->mallocFailed ){
99754100119
goto insert_cleanup;
99755100120
}
99756100121
99757100122
/* If the Select object is really just a simple VALUES() list with a
99758
- ** single row values (the common case) then keep that one row of values
99759
- ** and go ahead and discard the Select object
100123
+ ** single row (the common case) then keep that one row of values
100124
+ ** and discard the other (unused) parts of the pSelect object
99760100125
*/
99761100126
if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){
99762100127
pList = pSelect->pEList;
99763100128
pSelect->pEList = 0;
99764100129
sqlite3SelectDelete(db, pSelect);
@@ -99862,10 +100227,11 @@
99862100227
** the index into IDLIST of the primary key column. ipkColumn is
99863100228
** the index of the primary key as it appears in IDLIST, not as
99864100229
** is appears in the original table. (The index of the INTEGER
99865100230
** PRIMARY KEY in the original table is pTab->iPKey.)
99866100231
*/
100232
+ bIdListInOrder = (pTab->tabFlags & TF_OOOHidden)==0;
99867100233
if( pColumn ){
99868100234
for(i=0; i<pColumn->nId; i++){
99869100235
pColumn->a[i].idx = -1;
99870100236
}
99871100237
for(i=0; i<pColumn->nId; i++){
@@ -99897,11 +100263,12 @@
99897100263
** is coming from a SELECT statement, then generate a co-routine that
99898100264
** produces a single row of the SELECT on each invocation. The
99899100265
** co-routine is the common header to the 3rd and 4th templates.
99900100266
*/
99901100267
if( pSelect ){
99902
- /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
100268
+ /* Data is coming from a SELECT or from a multi-row VALUES clause.
100269
+ ** Generate a co-routine to run the SELECT. */
99903100270
int regYield; /* Register holding co-routine entry-point */
99904100271
int addrTop; /* Top of the co-routine */
99905100272
int rc; /* Result code */
99906100273
99907100274
regYield = ++pParse->nMem;
@@ -99910,12 +100277,11 @@
99910100277
sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
99911100278
dest.iSdst = bIdListInOrder ? regData : 0;
99912100279
dest.nSdst = pTab->nCol;
99913100280
rc = sqlite3Select(pParse, pSelect, &dest);
99914100281
regFromSelect = dest.iSdst;
99915
- assert( pParse->nErr==0 || rc );
99916
- if( rc || db->mallocFailed ) goto insert_cleanup;
100282
+ if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
99917100283
sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
99918100284
sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
99919100285
assert( pSelect->pEList );
99920100286
nColumn = pSelect->pEList->nExpr;
99921100287
@@ -99959,12 +100325,12 @@
99959100325
sqlite3VdbeJumpHere(v, addrL);
99960100326
sqlite3ReleaseTempReg(pParse, regRec);
99961100327
sqlite3ReleaseTempReg(pParse, regTempRowid);
99962100328
}
99963100329
}else{
99964
- /* This is the case if the data for the INSERT is coming from a VALUES
99965
- ** clause
100330
+ /* This is the case if the data for the INSERT is coming from a
100331
+ ** single-row VALUES clause
99966100332
*/
99967100333
NameContext sNC;
99968100334
memset(&sNC, 0, sizeof(sNC));
99969100335
sNC.pParse = pParse;
99970100336
srcTab = -1;
@@ -101031,10 +101397,11 @@
101031101397
Table *pDest, /* The table we are inserting into */
101032101398
Select *pSelect, /* A SELECT statement to use as the data source */
101033101399
int onError, /* How to handle constraint errors */
101034101400
int iDbDest /* The database of pDest */
101035101401
){
101402
+ sqlite3 *db = pParse->db;
101036101403
ExprList *pEList; /* The result set of the SELECT */
101037101404
Table *pSrc; /* The table in the FROM clause of SELECT */
101038101405
Index *pSrcIdx, *pDestIdx; /* Source and destination indices */
101039101406
struct SrcList_item *pItem; /* An element of pSelect->pSrc */
101040101407
int i; /* Loop counter */
@@ -101178,15 +101545,15 @@
101178101545
** But the main beneficiary of the transfer optimization is the VACUUM
101179101546
** command, and the VACUUM command disables foreign key constraints. So
101180101547
** the extra complication to make this rule less restrictive is probably
101181101548
** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
101182101549
*/
101183
- if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
101550
+ if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
101184101551
return 0;
101185101552
}
101186101553
#endif
101187
- if( (pParse->db->flags & SQLITE_CountRows)!=0 ){
101554
+ if( (db->flags & SQLITE_CountRows)!=0 ){
101188101555
return 0; /* xfer opt does not play well with PRAGMA count_changes */
101189101556
}
101190101557
101191101558
/* If we get this far, it means that the xfer optimization is at
101192101559
** least a possibility, though it might only work if the destination
@@ -101193,28 +101560,32 @@
101193101560
** table (tab1) is initially empty.
101194101561
*/
101195101562
#ifdef SQLITE_TEST
101196101563
sqlite3_xferopt_count++;
101197101564
#endif
101198
- iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema);
101565
+ iDbSrc = sqlite3SchemaToIndex(db, pSrc->pSchema);
101199101566
v = sqlite3GetVdbe(pParse);
101200101567
sqlite3CodeVerifySchema(pParse, iDbSrc);
101201101568
iSrc = pParse->nTab++;
101202101569
iDest = pParse->nTab++;
101203101570
regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
101204101571
regData = sqlite3GetTempReg(pParse);
101205101572
regRowid = sqlite3GetTempReg(pParse);
101206101573
sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
101207101574
assert( HasRowid(pDest) || destHasUniqueIdx );
101208
- if( (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
101575
+ if( (db->flags & SQLITE_Vacuum)==0 && (
101576
+ (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
101209101577
|| destHasUniqueIdx /* (2) */
101210101578
|| (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
101211
- ){
101579
+ )){
101212101580
/* In some circumstances, we are able to run the xfer optimization
101213
- ** only if the destination table is initially empty. This code makes
101214
- ** that determination. Conditions under which the destination must
101215
- ** be empty:
101581
+ ** only if the destination table is initially empty. Unless the
101582
+ ** SQLITE_Vacuum flag is set, this block generates code to make
101583
+ ** that determination. If SQLITE_Vacuum is set, then the destination
101584
+ ** table is always empty.
101585
+ **
101586
+ ** Conditions under which the destination must be empty:
101216101587
**
101217101588
** (1) There is no INTEGER PRIMARY KEY but there are indices.
101218101589
** (If the destination is not initially empty, the rowid fields
101219101590
** of index entries might need to change.)
101220101591
**
@@ -101253,10 +101624,11 @@
101253101624
}else{
101254101625
sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
101255101626
sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
101256101627
}
101257101628
for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
101629
+ u8 useSeekResult = 0;
101258101630
for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
101259101631
if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
101260101632
}
101261101633
assert( pSrcIdx );
101262101634
sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
@@ -101266,11 +101638,37 @@
101266101638
sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
101267101639
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
101268101640
VdbeComment((v, "%s", pDestIdx->zName));
101269101641
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
101270101642
sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
101643
+ if( db->flags & SQLITE_Vacuum ){
101644
+ /* This INSERT command is part of a VACUUM operation, which guarantees
101645
+ ** that the destination table is empty. If all indexed columns use
101646
+ ** collation sequence BINARY, then it can also be assumed that the
101647
+ ** index will be populated by inserting keys in strictly sorted
101648
+ ** order. In this case, instead of seeking within the b-tree as part
101649
+ ** of every OP_IdxInsert opcode, an OP_Last is added before the
101650
+ ** OP_IdxInsert to seek to the point within the b-tree where each key
101651
+ ** should be inserted. This is faster.
101652
+ **
101653
+ ** If any of the indexed columns use a collation sequence other than
101654
+ ** BINARY, this optimization is disabled. This is because the user
101655
+ ** might change the definition of a collation sequence and then run
101656
+ ** a VACUUM command. In that case keys may not be written in strictly
101657
+ ** sorted order. */
101658
+ for(i=0; i<pSrcIdx->nColumn; i++){
101659
+ char *zColl = pSrcIdx->azColl[i];
101660
+ assert( zColl!=0 );
101661
+ if( sqlite3_stricmp("BINARY", zColl) ) break;
101662
+ }
101663
+ if( i==pSrcIdx->nColumn ){
101664
+ useSeekResult = OPFLAG_USESEEKRESULT;
101665
+ sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
101666
+ }
101667
+ }
101271101668
sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
101669
+ sqlite3VdbeChangeP5(v, useSeekResult);
101272101670
sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
101273101671
sqlite3VdbeJumpHere(v, addr1);
101274101672
sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
101275101673
sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
101276101674
}
@@ -102385,11 +102783,11 @@
102385102783
int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102386102784
char *zErrmsg = 0;
102387102785
const char *zEntry;
102388102786
char *zAltEntry = 0;
102389102787
void **aHandle;
102390
- int nMsg = 300 + sqlite3Strlen30(zFile);
102788
+ u64 nMsg = 300 + sqlite3Strlen30(zFile);
102391102789
int ii;
102392102790
102393102791
/* Shared library endings to try if zFile cannot be loaded as written */
102394102792
static const char *azEndings[] = {
102395102793
#if SQLITE_OS_WIN
@@ -102428,11 +102826,11 @@
102428102826
sqlite3_free(zAltFile);
102429102827
}
102430102828
#endif
102431102829
if( handle==0 ){
102432102830
if( pzErrMsg ){
102433
- *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
102831
+ *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
102434102832
if( zErrmsg ){
102435102833
sqlite3_snprintf(nMsg, zErrmsg,
102436102834
"unable to open shared library [%s]", zFile);
102437102835
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102438102836
}
@@ -102454,11 +102852,11 @@
102454102852
** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
102455102853
*/
102456102854
if( xInit==0 && zProc==0 ){
102457102855
int iFile, iEntry, c;
102458102856
int ncFile = sqlite3Strlen30(zFile);
102459
- zAltEntry = sqlite3_malloc(ncFile+30);
102857
+ zAltEntry = sqlite3_malloc64(ncFile+30);
102460102858
if( zAltEntry==0 ){
102461102859
sqlite3OsDlClose(pVfs, handle);
102462102860
return SQLITE_NOMEM;
102463102861
}
102464102862
memcpy(zAltEntry, "sqlite3_", 8);
@@ -102476,11 +102874,11 @@
102476102874
sqlite3OsDlSym(pVfs, handle, zEntry);
102477102875
}
102478102876
if( xInit==0 ){
102479102877
if( pzErrMsg ){
102480102878
nMsg += sqlite3Strlen30(zEntry);
102481
- *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
102879
+ *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
102482102880
if( zErrmsg ){
102483102881
sqlite3_snprintf(nMsg, zErrmsg,
102484102882
"no entry point [%s] in shared library [%s]", zEntry, zFile);
102485102883
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102486102884
}
@@ -102575,11 +102973,11 @@
102575102973
** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER
102576102974
** mutex must be held while accessing this list.
102577102975
*/
102578102976
typedef struct sqlite3AutoExtList sqlite3AutoExtList;
102579102977
static SQLITE_WSD struct sqlite3AutoExtList {
102580
- int nExt; /* Number of entries in aExt[] */
102978
+ u32 nExt; /* Number of entries in aExt[] */
102581102979
void (**aExt)(void); /* Pointers to the extension init functions */
102582102980
} sqlite3Autoext = { 0, 0 };
102583102981
102584102982
/* The "wsdAutoext" macro will resolve to the autoextension
102585102983
** state vector. If writable static data is unsupported on the target,
@@ -102608,23 +103006,23 @@
102608103006
if( rc ){
102609103007
return rc;
102610103008
}else
102611103009
#endif
102612103010
{
102613
- int i;
103011
+ u32 i;
102614103012
#if SQLITE_THREADSAFE
102615103013
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
102616103014
#endif
102617103015
wsdAutoextInit;
102618103016
sqlite3_mutex_enter(mutex);
102619103017
for(i=0; i<wsdAutoext.nExt; i++){
102620103018
if( wsdAutoext.aExt[i]==xInit ) break;
102621103019
}
102622103020
if( i==wsdAutoext.nExt ){
102623
- int nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
103021
+ u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
102624103022
void (**aNew)(void);
102625
- aNew = sqlite3_realloc(wsdAutoext.aExt, nByte);
103023
+ aNew = sqlite3_realloc64(wsdAutoext.aExt, nByte);
102626103024
if( aNew==0 ){
102627103025
rc = SQLITE_NOMEM;
102628103026
}else{
102629103027
wsdAutoext.aExt = aNew;
102630103028
wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
@@ -102652,11 +103050,11 @@
102652103050
#endif
102653103051
int i;
102654103052
int n = 0;
102655103053
wsdAutoextInit;
102656103054
sqlite3_mutex_enter(mutex);
102657
- for(i=wsdAutoext.nExt-1; i>=0; i--){
103055
+ for(i=(int)wsdAutoext.nExt-1; i>=0; i--){
102658103056
if( wsdAutoext.aExt[i]==xInit ){
102659103057
wsdAutoext.nExt--;
102660103058
wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
102661103059
n++;
102662103060
break;
@@ -102690,11 +103088,11 @@
102690103088
** Load all automatic extensions.
102691103089
**
102692103090
** If anything goes wrong, set an error in the database connection.
102693103091
*/
102694103092
SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
102695
- int i;
103093
+ u32 i;
102696103094
int go = 1;
102697103095
int rc;
102698103096
int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102699103097
102700103098
wsdAutoextInit;
@@ -103354,19 +103752,19 @@
103354103752
/*
103355103753
** Generate code to return a single integer value.
103356103754
*/
103357103755
static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
103358103756
Vdbe *v = sqlite3GetVdbe(pParse);
103359
- int mem = ++pParse->nMem;
103757
+ int nMem = ++pParse->nMem;
103360103758
i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
103361103759
if( pI64 ){
103362103760
memcpy(pI64, &value, sizeof(value));
103363103761
}
103364
- sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64);
103762
+ sqlite3VdbeAddOp4(v, OP_Int64, 0, nMem, 0, (char*)pI64, P4_INT64);
103365103763
sqlite3VdbeSetNumCols(v, 1);
103366103764
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
103367
- sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
103765
+ sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
103368103766
}
103369103767
103370103768
103371103769
/*
103372103770
** Set the safety_level and pager flags for pager iDb. Or if iDb<0
@@ -103527,15 +103925,15 @@
103527103925
aFcntl[3] = 0;
103528103926
db->busyHandler.nBusy = 0;
103529103927
rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
103530103928
if( rc==SQLITE_OK ){
103531103929
if( aFcntl[0] ){
103532
- int mem = ++pParse->nMem;
103533
- sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0);
103930
+ int nMem = ++pParse->nMem;
103931
+ sqlite3VdbeAddOp4(v, OP_String8, 0, nMem, 0, aFcntl[0], 0);
103534103932
sqlite3VdbeSetNumCols(v, 1);
103535103933
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
103536
- sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
103934
+ sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
103537103935
sqlite3_free(aFcntl[0]);
103538103936
}
103539103937
goto pragma_out;
103540103938
}
103541103939
if( rc!=SQLITE_NOTFOUND ){
@@ -104136,11 +104534,13 @@
104136104534
}else{
104137104535
if( !db->autoCommit ){
104138104536
sqlite3ErrorMsg(pParse,
104139104537
"Safety level may not be changed inside a transaction");
104140104538
}else{
104141
- pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
104539
+ int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
104540
+ if( iLevel==0 ) iLevel = 1;
104541
+ pDb->safety_level = iLevel;
104142104542
setAllPagerFlags(db);
104143104543
}
104144104544
}
104145104545
break;
104146104546
}
@@ -104231,11 +104631,11 @@
104231104631
if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
104232104632
k = 0;
104233104633
}else if( pPk==0 ){
104234104634
k = 1;
104235104635
}else{
104236
- for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){}
104636
+ for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
104237104637
}
104238104638
sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
104239104639
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
104240104640
}
104241104641
}
@@ -105237,11 +105637,11 @@
105237105637
105238105638
assert( iDb>=0 && iDb<db->nDb );
105239105639
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
105240105640
if( argv[1]==0 ){
105241105641
corruptSchema(pData, argv[0], 0);
105242
- }else if( argv[2] && argv[2][0] ){
105642
+ }else if( sqlite3_strnicmp(argv[2],"create ",7)==0 ){
105243105643
/* Call the parser to process a CREATE TABLE, INDEX or VIEW.
105244105644
** But because db->init.busy is set to 1, no VDBE code is generated
105245105645
** or executed. All the parser does is build the internal data
105246105646
** structures that describe the table, index, or view.
105247105647
*/
@@ -105268,12 +105668,12 @@
105268105668
corruptSchema(pData, argv[0], sqlite3_errmsg(db));
105269105669
}
105270105670
}
105271105671
}
105272105672
sqlite3_finalize(pStmt);
105273
- }else if( argv[0]==0 ){
105274
- corruptSchema(pData, 0, 0);
105673
+ }else if( argv[0]==0 || (argv[2]!=0 && argv[2][0]!=0) ){
105674
+ corruptSchema(pData, argv[0], 0);
105275105675
}else{
105276105676
/* If the SQL column is blank it means this is an index that
105277105677
** was created to be the PRIMARY KEY or to fulfill a UNIQUE
105278105678
** constraint for a CREATE TABLE. The index should have already
105279105679
** been created when we processed the CREATE TABLE. All we have
@@ -106176,11 +106576,10 @@
106176106576
){
106177106577
Select *pNew;
106178106578
Select standin;
106179106579
sqlite3 *db = pParse->db;
106180106580
pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
106181
- assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */
106182106581
if( pNew==0 ){
106183106582
assert( db->mallocFailed );
106184106583
pNew = &standin;
106185106584
memset(pNew, 0, sizeof(*pNew));
106186106585
}
@@ -106196,11 +106595,11 @@
106196106595
pNew->pOrderBy = pOrderBy;
106197106596
pNew->selFlags = selFlags;
106198106597
pNew->op = TK_SELECT;
106199106598
pNew->pLimit = pLimit;
106200106599
pNew->pOffset = pOffset;
106201
- assert( pOffset==0 || pLimit!=0 );
106600
+ assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 );
106202106601
pNew->addrOpenEphm[0] = -1;
106203106602
pNew->addrOpenEphm[1] = -1;
106204106603
if( db->mallocFailed ) {
106205106604
clearSelect(db, pNew, pNew!=&standin);
106206106605
pNew = 0;
@@ -107446,11 +107845,11 @@
107446107845
if( pS ){
107447107846
/* The "table" is actually a sub-select or a view in the FROM clause
107448107847
** of the SELECT statement. Return the declaration type and origin
107449107848
** data for the result-set column of the sub-select.
107450107849
*/
107451
- if( iCol>=0 && ALWAYS(iCol<pS->pEList->nExpr) ){
107850
+ if( iCol>=0 && iCol<pS->pEList->nExpr ){
107452107851
/* If iCol is less than zero, then the expression requests the
107453107852
** rowid of the sub-select or view. This expression is legal (see
107454107853
** test case misc2.2.2) - it always evaluates to NULL.
107455107854
*/
107456107855
NameContext sNC;
@@ -107766,16 +108165,18 @@
107766108165
memset(&sNC, 0, sizeof(sNC));
107767108166
sNC.pSrcList = pSelect->pSrc;
107768108167
a = pSelect->pEList->a;
107769108168
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
107770108169
p = a[i].pExpr;
107771
- pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst));
108170
+ if( pCol->zType==0 ){
108171
+ pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst));
108172
+ }
107772108173
szAll += pCol->szEst;
107773108174
pCol->affinity = sqlite3ExprAffinity(p);
107774108175
if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE;
107775108176
pColl = sqlite3ExprCollSeq(pParse, p);
107776
- if( pColl ){
108177
+ if( pColl && pCol->zColl==0 ){
107777108178
pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
107778108179
}
107779108180
}
107780108181
pTab->szTabRow = sqlite3LogEst(szAll*4);
107781108182
}
@@ -108173,12 +108574,11 @@
108173108574
){
108174108575
Select *pPrior;
108175108576
int nExpr = p->pEList->nExpr;
108176108577
int nRow = 1;
108177108578
int rc = 0;
108178
- assert( p->pNext==0 );
108179
- assert( p->selFlags & SF_AllValues );
108579
+ assert( p->selFlags & SF_MultiValue );
108180108580
do{
108181108581
assert( p->selFlags & SF_Values );
108182108582
assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
108183108583
assert( p->pLimit==0 );
108184108584
assert( p->pOffset==0 );
@@ -108283,11 +108683,11 @@
108283108683
dest.eDest = SRT_Table;
108284108684
}
108285108685
108286108686
/* Special handling for a compound-select that originates as a VALUES clause.
108287108687
*/
108288
- if( p->selFlags & SF_AllValues ){
108688
+ if( p->selFlags & SF_MultiValue ){
108289108689
rc = multiSelectValues(pParse, p, &dest);
108290108690
goto multi_select_end;
108291108691
}
108292108692
108293108693
/* Make sure all SELECTs in the statement have the same number of elements
@@ -108668,11 +109068,11 @@
108668109068
** then there should be a single item on the stack. Write this
108669109069
** item into the set table with bogus data.
108670109070
*/
108671109071
case SRT_Set: {
108672109072
int r1;
108673
- assert( pIn->nSdst==1 );
109073
+ assert( pIn->nSdst==1 || pParse->nErr>0 );
108674109074
pDest->affSdst =
108675109075
sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affSdst);
108676109076
r1 = sqlite3GetTempReg(pParse);
108677109077
sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, 1, r1, &pDest->affSdst,1);
108678109078
sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, 1);
@@ -108694,11 +109094,11 @@
108694109094
/* If this is a scalar select that is part of an expression, then
108695109095
** store the results in the appropriate memory cell and break out
108696109096
** of the scan loop.
108697109097
*/
108698109098
case SRT_Mem: {
108699
- assert( pIn->nSdst==1 );
109099
+ assert( pIn->nSdst==1 || pParse->nErr>0 ); testcase( pIn->nSdst!=1 );
108700109100
sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1);
108701109101
/* The LIMIT clause will jump out of the loop for us */
108702109102
break;
108703109103
}
108704109104
#endif /* #ifndef SQLITE_OMIT_SUBQUERY */
@@ -108709,11 +109109,11 @@
108709109109
case SRT_Coroutine: {
108710109110
if( pDest->iSdst==0 ){
108711109111
pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst);
108712109112
pDest->nSdst = pIn->nSdst;
108713109113
}
108714
- sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pDest->nSdst);
109114
+ sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst);
108715109115
sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
108716109116
break;
108717109117
}
108718109118
108719109119
/* If none of the above, then the result destination must be
@@ -108925,12 +109325,14 @@
108925109325
*/
108926109326
aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
108927109327
if( aPermute ){
108928109328
struct ExprList_item *pItem;
108929109329
for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
108930
- assert( pItem->u.x.iOrderByCol>0
108931
- && pItem->u.x.iOrderByCol<=p->pEList->nExpr );
109330
+ assert( pItem->u.x.iOrderByCol>0 );
109331
+ /* assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr ) is also true
109332
+ ** but only for well-formed SELECT statements. */
109333
+ testcase( pItem->u.x.iOrderByCol > p->pEList->nExpr );
108932109334
aPermute[i] = pItem->u.x.iOrderByCol - 1;
108933109335
}
108934109336
pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1);
108935109337
}else{
108936109338
pKeyMerge = 0;
@@ -109136,11 +109538,11 @@
109136109538
pPrior->pNext = p;
109137109539
109138109540
/*** TBD: Insert subroutine calls to close cursors on incomplete
109139109541
**** subqueries ****/
109140109542
explainComposite(pParse, p->op, iSub1, iSub2, 0);
109141
- return SQLITE_OK;
109543
+ return pParse->nErr!=0;
109142109544
}
109143109545
#endif
109144109546
109145109547
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
109146109548
/* Forward Declarations */
@@ -109948,10 +110350,11 @@
109948110350
pNew->pGroupBy = 0;
109949110351
pNew->pHaving = 0;
109950110352
pNew->pOrderBy = 0;
109951110353
p->pPrior = 0;
109952110354
p->pNext = 0;
110355
+ p->pWith = 0;
109953110356
p->selFlags &= ~SF_Compound;
109954110357
assert( (p->selFlags & SF_Converted)==0 );
109955110358
p->selFlags |= SF_Converted;
109956110359
assert( pNew->pPrior!=0 );
109957110360
pNew->pPrior->pNext = pNew;
@@ -110486,11 +110889,11 @@
110486110889
if( pParse->hasCompound ){
110487110890
w.xSelectCallback = convertCompoundSelectToSubquery;
110488110891
sqlite3WalkSelect(&w, pSelect);
110489110892
}
110490110893
w.xSelectCallback = selectExpander;
110491
- if( (pSelect->selFlags & SF_AllValues)==0 ){
110894
+ if( (pSelect->selFlags & SF_MultiValue)==0 ){
110492110895
w.xSelectCallback2 = selectPopWith;
110493110896
}
110494110897
sqlite3WalkSelect(&w, pSelect);
110495110898
}
110496110899
@@ -110672,11 +111075,12 @@
110672111075
nArg = 0;
110673111076
regAgg = 0;
110674111077
}
110675111078
if( pF->iDistinct>=0 ){
110676111079
addrNext = sqlite3VdbeMakeLabel(v);
110677
- assert( nArg==1 );
111080
+ testcase( nArg==0 ); /* Error condition */
111081
+ testcase( nArg>1 ); /* Also an error */
110678111082
codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
110679111083
}
110680111084
if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
110681111085
CollSeq *pColl = 0;
110682111086
struct ExprList_item *pItem;
@@ -111547,14 +111951,13 @@
111547111951
111548111952
/* Jump here to skip this query
111549111953
*/
111550111954
sqlite3VdbeResolveLabel(v, iEnd);
111551111955
111552
- /* The SELECT was successfully coded. Set the return code to 0
111553
- ** to indicate no errors.
111554
- */
111555
- rc = 0;
111956
+ /* The SELECT has been coded. If there is an error in the Parse structure,
111957
+ ** set the return code to 1. Otherwise 0. */
111958
+ rc = (pParse->nErr>0);
111556111959
111557111960
/* Control jumps to here if an error is encountered above, or upon
111558111961
** successful coding of the SELECT.
111559111962
*/
111560111963
select_end:
@@ -111601,11 +112004,11 @@
111601112004
sqlite3TreeViewLine(pView, "FROM");
111602112005
for(i=0; i<p->pSrc->nSrc; i++){
111603112006
struct SrcList_item *pItem = &p->pSrc->a[i];
111604112007
StrAccum x;
111605112008
char zLine[100];
111606
- sqlite3StrAccumInit(&x, zLine, sizeof(zLine), 0);
112009
+ sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
111607112010
sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
111608112011
if( pItem->zDatabase ){
111609112012
sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
111610112013
}else if( pItem->zName ){
111611112014
sqlite3XPrintf(&x, 0, " %s", pItem->zName);
@@ -111760,11 +112163,11 @@
111760112163
for(i=0; i<nCol; i++){
111761112164
if( argv[i]==0 ){
111762112165
z = 0;
111763112166
}else{
111764112167
int n = sqlite3Strlen30(argv[i])+1;
111765
- z = sqlite3_malloc( n );
112168
+ z = sqlite3_malloc64( n );
111766112169
if( z==0 ) goto malloc_failed;
111767112170
memcpy(z, argv[i], n);
111768112171
}
111769112172
p->azResult[p->nData++] = z;
111770112173
}
@@ -111809,11 +112212,11 @@
111809112212
res.nRow = 0;
111810112213
res.nColumn = 0;
111811112214
res.nData = 1;
111812112215
res.nAlloc = 20;
111813112216
res.rc = SQLITE_OK;
111814
- res.azResult = sqlite3_malloc(sizeof(char*)*res.nAlloc );
112217
+ res.azResult = sqlite3_malloc64(sizeof(char*)*res.nAlloc );
111815112218
if( res.azResult==0 ){
111816112219
db->errCode = SQLITE_NOMEM;
111817112220
return SQLITE_NOMEM;
111818112221
}
111819112222
res.azResult[0] = 0;
@@ -111837,11 +112240,11 @@
111837112240
sqlite3_free_table(&res.azResult[1]);
111838112241
return rc;
111839112242
}
111840112243
if( res.nAlloc>res.nData ){
111841112244
char **azNew;
111842
- azNew = sqlite3_realloc( res.azResult, sizeof(char*)*res.nData );
112245
+ azNew = sqlite3_realloc64( res.azResult, sizeof(char*)*res.nData );
111843112246
if( azNew==0 ){
111844112247
sqlite3_free_table(&res.azResult[1]);
111845112248
db->errCode = SQLITE_NOMEM;
111846112249
return SQLITE_NOMEM;
111847112250
}
@@ -112065,11 +112468,10 @@
112065112468
}
112066112469
112067112470
/* Do not create a trigger on a system table */
112068112471
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
112069112472
sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
112070
- pParse->nErr++;
112071112473
goto trigger_cleanup;
112072112474
}
112073112475
112074112476
/* INSTEAD of triggers are only for views and views only support INSTEAD
112075112477
** of triggers.
@@ -112245,16 +112647,16 @@
112245112647
u8 op, /* Trigger opcode */
112246112648
Token *pName /* The target name */
112247112649
){
112248112650
TriggerStep *pTriggerStep;
112249112651
112250
- pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n);
112652
+ pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
112251112653
if( pTriggerStep ){
112252112654
char *z = (char*)&pTriggerStep[1];
112253112655
memcpy(z, pName->z, pName->n);
112254
- pTriggerStep->target.z = z;
112255
- pTriggerStep->target.n = pName->n;
112656
+ sqlite3Dequote(z);
112657
+ pTriggerStep->zTarget = z;
112256112658
pTriggerStep->op = op;
112257112659
}
112258112660
return pTriggerStep;
112259112661
}
112260112662
@@ -112533,11 +112935,11 @@
112533112935
}
112534112936
return (mask ? pList : 0);
112535112937
}
112536112938
112537112939
/*
112538
-** Convert the pStep->target token into a SrcList and return a pointer
112940
+** Convert the pStep->zTarget string into a SrcList and return a pointer
112539112941
** to that SrcList.
112540112942
**
112541112943
** This routine adds a specific database name, if needed, to the target when
112542112944
** forming the SrcList. This prevents a trigger in one database from
112543112945
** referring to a target in another database. An exception is when the
@@ -112546,21 +112948,21 @@
112546112948
*/
112547112949
static SrcList *targetSrcList(
112548112950
Parse *pParse, /* The parsing context */
112549112951
TriggerStep *pStep /* The trigger containing the target token */
112550112952
){
112953
+ sqlite3 *db = pParse->db;
112551112954
int iDb; /* Index of the database to use */
112552112955
SrcList *pSrc; /* SrcList to be returned */
112553112956
112554
- pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0);
112957
+ pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
112555112958
if( pSrc ){
112556112959
assert( pSrc->nSrc>0 );
112557
- assert( pSrc->a!=0 );
112558
- iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema);
112960
+ pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
112961
+ iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
112559112962
if( iDb==0 || iDb>=2 ){
112560
- sqlite3 *db = pParse->db;
112561
- assert( iDb<pParse->db->nDb );
112963
+ assert( iDb<db->nDb );
112562112964
pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
112563112965
}
112564112966
}
112565112967
return pSrc;
112566112968
}
@@ -112668,10 +113070,11 @@
112668113070
assert( pFrom->zErrMsg==0 || pFrom->nErr );
112669113071
assert( pTo->zErrMsg==0 || pTo->nErr );
112670113072
if( pTo->nErr==0 ){
112671113073
pTo->zErrMsg = pFrom->zErrMsg;
112672113074
pTo->nErr = pFrom->nErr;
113075
+ pTo->rc = pFrom->rc;
112673113076
}else{
112674113077
sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
112675113078
}
112676113079
}
112677113080
@@ -114018,17 +114421,21 @@
114018114421
114019114422
/* Loop through the tables in the main database. For each, do
114020114423
** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
114021114424
** the contents to the temporary database.
114022114425
*/
114426
+ assert( (db->flags & SQLITE_Vacuum)==0 );
114427
+ db->flags |= SQLITE_Vacuum;
114023114428
rc = execExecSql(db, pzErrMsg,
114024114429
"SELECT 'INSERT INTO vacuum_db.' || quote(name) "
114025114430
"|| ' SELECT * FROM main.' || quote(name) || ';'"
114026114431
"FROM main.sqlite_master "
114027114432
"WHERE type = 'table' AND name!='sqlite_sequence' "
114028114433
" AND coalesce(rootpage,1)>0"
114029114434
);
114435
+ assert( (db->flags & SQLITE_Vacuum)!=0 );
114436
+ db->flags &= ~SQLITE_Vacuum;
114030114437
if( rc!=SQLITE_OK ) goto end_of_vacuum;
114031114438
114032114439
/* Copy over the sequence table
114033114440
*/
114034114441
rc = execExecSql(db, pzErrMsg,
@@ -114163,10 +114570,12 @@
114163114570
** are invoked only from within xCreate and xConnect methods.
114164114571
*/
114165114572
struct VtabCtx {
114166114573
VTable *pVTable; /* The virtual table being constructed */
114167114574
Table *pTab; /* The Table object to which the virtual table belongs */
114575
+ VtabCtx *pPrior; /* Parent context (if any) */
114576
+ int bDeclared; /* True after sqlite3_declare_vtab() is called */
114168114577
};
114169114578
114170114579
/*
114171114580
** The actual function that does the work of creating a new module.
114172114581
** This function implements the sqlite3_create_module() and
@@ -114609,11 +115018,11 @@
114609115018
Token *pArg = &pParse->sArg;
114610115019
if( pArg->z==0 ){
114611115020
pArg->z = p->z;
114612115021
pArg->n = p->n;
114613115022
}else{
114614
- assert(pArg->z < p->z);
115023
+ assert(pArg->z <= p->z);
114615115024
pArg->n = (int)(&p->z[p->n] - pArg->z);
114616115025
}
114617115026
}
114618115027
114619115028
/*
@@ -114626,19 +115035,31 @@
114626115035
Table *pTab,
114627115036
Module *pMod,
114628115037
int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**),
114629115038
char **pzErr
114630115039
){
114631
- VtabCtx sCtx, *pPriorCtx;
115040
+ VtabCtx sCtx;
114632115041
VTable *pVTable;
114633115042
int rc;
114634115043
const char *const*azArg = (const char *const*)pTab->azModuleArg;
114635115044
int nArg = pTab->nModuleArg;
114636115045
char *zErr = 0;
114637
- char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
115046
+ char *zModuleName;
114638115047
int iDb;
115048
+ VtabCtx *pCtx;
114639115049
115050
+ /* Check that the virtual-table is not already being initialized */
115051
+ for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
115052
+ if( pCtx->pTab==pTab ){
115053
+ *pzErr = sqlite3MPrintf(db,
115054
+ "vtable constructor called recursively: %s", pTab->zName
115055
+ );
115056
+ return SQLITE_LOCKED;
115057
+ }
115058
+ }
115059
+
115060
+ zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
114640115061
if( !zModuleName ){
114641115062
return SQLITE_NOMEM;
114642115063
}
114643115064
114644115065
pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
@@ -114655,15 +115076,17 @@
114655115076
/* Invoke the virtual table constructor */
114656115077
assert( &db->pVtabCtx );
114657115078
assert( xConstruct );
114658115079
sCtx.pTab = pTab;
114659115080
sCtx.pVTable = pVTable;
114660
- pPriorCtx = db->pVtabCtx;
115081
+ sCtx.pPrior = db->pVtabCtx;
115082
+ sCtx.bDeclared = 0;
114661115083
db->pVtabCtx = &sCtx;
114662115084
rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
114663
- db->pVtabCtx = pPriorCtx;
115085
+ db->pVtabCtx = sCtx.pPrior;
114664115086
if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
115087
+ assert( sCtx.pTab==pTab );
114665115088
114666115089
if( SQLITE_OK!=rc ){
114667115090
if( zErr==0 ){
114668115091
*pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
114669115092
}else {
@@ -114675,17 +115098,18 @@
114675115098
/* Justification of ALWAYS(): A correct vtab constructor must allocate
114676115099
** the sqlite3_vtab object if successful. */
114677115100
memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
114678115101
pVTable->pVtab->pModule = pMod->pModule;
114679115102
pVTable->nRef = 1;
114680
- if( sCtx.pTab ){
115103
+ if( sCtx.bDeclared==0 ){
114681115104
const char *zFormat = "vtable constructor did not declare schema: %s";
114682115105
*pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
114683115106
sqlite3VtabUnlock(pVTable);
114684115107
rc = SQLITE_ERROR;
114685115108
}else{
114686115109
int iCol;
115110
+ u8 oooHidden = 0;
114687115111
/* If everything went according to plan, link the new VTable structure
114688115112
** into the linked list headed by pTab->pVTable. Then loop through the
114689115113
** columns of the table to see if any of them contain the token "hidden".
114690115114
** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
114691115115
** the type string. */
@@ -114694,11 +115118,14 @@
114694115118
114695115119
for(iCol=0; iCol<pTab->nCol; iCol++){
114696115120
char *zType = pTab->aCol[iCol].zType;
114697115121
int nType;
114698115122
int i = 0;
114699
- if( !zType ) continue;
115123
+ if( !zType ){
115124
+ pTab->tabFlags |= oooHidden;
115125
+ continue;
115126
+ }
114700115127
nType = sqlite3Strlen30(zType);
114701115128
if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){
114702115129
for(i=0; i<nType; i++){
114703115130
if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7))
114704115131
&& (zType[i+7]=='\0' || zType[i+7]==' ')
@@ -114717,10 +115144,13 @@
114717115144
if( zType[i]=='\0' && i>0 ){
114718115145
assert(zType[i-1]==' ');
114719115146
zType[i-1] = '\0';
114720115147
}
114721115148
pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN;
115149
+ oooHidden = TF_OOOHidden;
115150
+ }else{
115151
+ pTab->tabFlags |= oooHidden;
114722115152
}
114723115153
}
114724115154
}
114725115155
}
114726115156
@@ -114845,12 +115275,12 @@
114845115275
** This function is used to set the schema of a virtual table. It is only
114846115276
** valid to call this function from within the xCreate() or xConnect() of a
114847115277
** virtual table module.
114848115278
*/
114849115279
SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
115280
+ VtabCtx *pCtx;
114850115281
Parse *pParse;
114851
-
114852115282
int rc = SQLITE_OK;
114853115283
Table *pTab;
114854115284
char *zErr = 0;
114855115285
114856115286
#ifdef SQLITE_ENABLE_API_ARMOR
@@ -114857,15 +115287,17 @@
114857115287
if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
114858115288
return SQLITE_MISUSE_BKPT;
114859115289
}
114860115290
#endif
114861115291
sqlite3_mutex_enter(db->mutex);
114862
- if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
115292
+ pCtx = db->pVtabCtx;
115293
+ if( !pCtx || pCtx->bDeclared ){
114863115294
sqlite3Error(db, SQLITE_MISUSE);
114864115295
sqlite3_mutex_leave(db->mutex);
114865115296
return SQLITE_MISUSE_BKPT;
114866115297
}
115298
+ pTab = pCtx->pTab;
114867115299
assert( (pTab->tabFlags & TF_Virtual)!=0 );
114868115300
114869115301
pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
114870115302
if( pParse==0 ){
114871115303
rc = SQLITE_NOMEM;
@@ -114884,11 +115316,11 @@
114884115316
pTab->aCol = pParse->pNewTable->aCol;
114885115317
pTab->nCol = pParse->pNewTable->nCol;
114886115318
pParse->pNewTable->nCol = 0;
114887115319
pParse->pNewTable->aCol = 0;
114888115320
}
114889
- db->pVtabCtx->pTab = 0;
115321
+ pCtx->bDeclared = 1;
114890115322
}else{
114891115323
sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
114892115324
sqlite3DbFree(db, zErr);
114893115325
rc = SQLITE_ERROR;
114894115326
}
@@ -115078,11 +115510,11 @@
115078115510
*/
115079115511
SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
115080115512
int rc = SQLITE_OK;
115081115513
115082115514
assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
115083
- assert( iSavepoint>=0 );
115515
+ assert( iSavepoint>=-1 );
115084115516
if( db->aVTrans ){
115085115517
int i;
115086115518
for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
115087115519
VTable *pVTab = db->aVTrans[i];
115088115520
const sqlite3_module *pMod = pVTab->pMod->pModule;
@@ -115196,11 +115628,11 @@
115196115628
assert( IsVirtual(pTab) );
115197115629
for(i=0; i<pToplevel->nVtabLock; i++){
115198115630
if( pTab==pToplevel->apVtabLock[i] ) return;
115199115631
}
115200115632
n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]);
115201
- apVtabLock = sqlite3_realloc(pToplevel->apVtabLock, n);
115633
+ apVtabLock = sqlite3_realloc64(pToplevel->apVtabLock, n);
115202115634
if( apVtabLock ){
115203115635
pToplevel->apVtabLock = apVtabLock;
115204115636
pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
115205115637
}else{
115206115638
pToplevel->db->mallocFailed = 1;
@@ -115995,17 +116427,18 @@
115995116427
** In the previous sentence and in the diagram, "slot[]" refers to
115996116428
** the WhereClause.a[] array. The slot[] array grows as needed to contain
115997116429
** all terms of the WHERE clause.
115998116430
*/
115999116431
static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){
116432
+ Expr *pE2 = sqlite3ExprSkipCollate(pExpr);
116000116433
pWC->op = op;
116001
- if( pExpr==0 ) return;
116002
- if( pExpr->op!=op ){
116434
+ if( pE2==0 ) return;
116435
+ if( pE2->op!=op ){
116003116436
whereClauseInsert(pWC, pExpr, 0);
116004116437
}else{
116005
- whereSplit(pWC, pExpr->pLeft, op);
116006
- whereSplit(pWC, pExpr->pRight, op);
116438
+ whereSplit(pWC, pE2->pLeft, op);
116439
+ whereSplit(pWC, pE2->pRight, op);
116007116440
}
116008116441
}
116009116442
116010116443
/*
116011116444
** Initialize a WhereMaskSet object
@@ -117272,11 +117705,11 @@
117272117705
if( p->op==TK_COLUMN
117273117706
&& p->iColumn==pIdx->aiColumn[iCol]
117274117707
&& p->iTable==iBase
117275117708
){
117276117709
CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr);
117277
- if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){
117710
+ if( pColl && 0==sqlite3StrICmp(pColl->zName, zColl) ){
117278117711
return i;
117279117712
}
117280117713
}
117281117714
}
117282117715
@@ -117546,11 +117979,11 @@
117546117979
if( (idxCols & cMask)==0 ){
117547117980
Expr *pX = pTerm->pExpr;
117548117981
idxCols |= cMask;
117549117982
pIdx->aiColumn[n] = pTerm->u.leftColumn;
117550117983
pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
117551
- pIdx->azColl[n] = ALWAYS(pColl) ? pColl->zName : "BINARY";
117984
+ pIdx->azColl[n] = pColl ? pColl->zName : "BINARY";
117552117985
n++;
117553117986
}
117554117987
}
117555117988
}
117556117989
assert( (u32)n==pLoop->u.btree.nEq );
@@ -118842,12 +119275,11 @@
118842119275
118843119276
isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
118844119277
|| ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
118845119278
|| (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
118846119279
118847
- sqlite3StrAccumInit(&str, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
118848
- str.db = db;
119280
+ sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
118849119281
sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
118850119282
if( pItem->pSelect ){
118851119283
sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId);
118852119284
}else{
118853119285
sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName);
@@ -120042,10 +120474,17 @@
120042120474
/*
120043120475
** Free a WhereInfo structure
120044120476
*/
120045120477
static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
120046120478
if( ALWAYS(pWInfo) ){
120479
+ int i;
120480
+ for(i=0; i<pWInfo->nLevel; i++){
120481
+ WhereLevel *pLevel = &pWInfo->a[i];
120482
+ if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){
120483
+ sqlite3DbFree(db, pLevel->u.in.aInLoop);
120484
+ }
120485
+ }
120047120486
whereClauseClear(&pWInfo->sWC);
120048120487
while( pWInfo->pLoops ){
120049120488
WhereLoop *p = pWInfo->pLoops;
120050120489
pWInfo->pLoops = p->pNextLoop;
120051120490
whereLoopDelete(db, p);
@@ -120521,11 +120960,11 @@
120521120960
** changes "x IN (?)" into "x=?". */
120522120961
120523120962
}else if( eOp & (WO_EQ) ){
120524120963
pNew->wsFlags |= WHERE_COLUMN_EQ;
120525120964
if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
120526
- if( iCol>=0 && !IsUniqueIndex(pProbe) ){
120965
+ if( iCol>=0 && pProbe->uniqNotNull==0 ){
120527120966
pNew->wsFlags |= WHERE_UNQ_WANTED;
120528120967
}else{
120529120968
pNew->wsFlags |= WHERE_ONEROW;
120530120969
}
120531120970
}
@@ -121981,11 +122420,11 @@
121981122420
pWInfo->nOBSat = pFrom->isOrdered;
121982122421
if( pWInfo->nOBSat<0 ) pWInfo->nOBSat = 0;
121983122422
pWInfo->revMask = pFrom->revLoop;
121984122423
}
121985122424
if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
121986
- && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr
122425
+ && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && nLoop>0
121987122426
){
121988122427
Bitmask revMask = 0;
121989122428
int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
121990122429
pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
121991122430
);
@@ -122386,11 +122825,10 @@
122386122825
if( pParse->nErr || NEVER(db->mallocFailed) ){
122387122826
goto whereBeginError;
122388122827
}
122389122828
#ifdef WHERETRACE_ENABLED /* !=0 */
122390122829
if( sqlite3WhereTrace ){
122391
- int ii;
122392122830
sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
122393122831
if( pWInfo->nOBSat>0 ){
122394122832
sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
122395122833
}
122396122834
switch( pWInfo->eDistinct ){
@@ -122639,11 +123077,10 @@
122639123077
VdbeCoverage(v);
122640123078
VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
122641123079
VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
122642123080
sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
122643123081
}
122644
- sqlite3DbFree(db, pLevel->u.in.aInLoop);
122645123082
}
122646123083
sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
122647123084
if( pLevel->addrSkip ){
122648123085
sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
122649123086
VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
@@ -122850,10 +123287,32 @@
122850123287
/*
122851123288
** An instance of this structure holds the ATTACH key and the key type.
122852123289
*/
122853123290
struct AttachKey { int type; Token key; };
122854123291
123292
+
123293
+ /*
123294
+ ** For a compound SELECT statement, make sure p->pPrior->pNext==p for
123295
+ ** all elements in the list. And make sure list length does not exceed
123296
+ ** SQLITE_LIMIT_COMPOUND_SELECT.
123297
+ */
123298
+ static void parserDoubleLinkSelect(Parse *pParse, Select *p){
123299
+ if( p->pPrior ){
123300
+ Select *pNext = 0, *pLoop;
123301
+ int mxSelect, cnt = 0;
123302
+ for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
123303
+ pLoop->pNext = pNext;
123304
+ pLoop->selFlags |= SF_Compound;
123305
+ }
123306
+ if( (p->selFlags & SF_MultiValue)==0 &&
123307
+ (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 &&
123308
+ cnt>mxSelect
123309
+ ){
123310
+ sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
123311
+ }
123312
+ }
123313
+ }
122855123314
122856123315
/* This is a utility routine used to set the ExprSpan.zStart and
122857123316
** ExprSpan.zEnd values of pOut so that the span covers the complete
122858123317
** range of text beginning with pStart and going to the end of pEnd.
122859123318
*/
@@ -125167,31 +125626,14 @@
125167125626
sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
125168125627
}
125169125628
break;
125170125629
case 112: /* select ::= with selectnowith */
125171125630
{
125172
- Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
125631
+ Select *p = yymsp[0].minor.yy3;
125173125632
if( p ){
125174
- int cnt = 0, mxSelect;
125175125633
p->pWith = yymsp[-1].minor.yy59;
125176
- if( p->pPrior ){
125177
- u16 allValues = SF_Values;
125178
- pNext = 0;
125179
- for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
125180
- pLoop->pNext = pNext;
125181
- pLoop->selFlags |= SF_Compound;
125182
- allValues &= pLoop->selFlags;
125183
- }
125184
- if( allValues ){
125185
- p->selFlags |= SF_AllValues;
125186
- }else if(
125187
- (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0
125188
- && cnt>mxSelect
125189
- ){
125190
- sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
125191
- }
125192
- }
125634
+ parserDoubleLinkSelect(pParse, p);
125193125635
}else{
125194125636
sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
125195125637
}
125196125638
yygotominor.yy3 = p;
125197125639
}
@@ -125205,16 +125647,18 @@
125205125647
Select *pRhs = yymsp[0].minor.yy3;
125206125648
if( pRhs && pRhs->pPrior ){
125207125649
SrcList *pFrom;
125208125650
Token x;
125209125651
x.n = 0;
125652
+ parserDoubleLinkSelect(pParse, pRhs);
125210125653
pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
125211125654
pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
125212125655
}
125213125656
if( pRhs ){
125214125657
pRhs->op = (u8)yymsp[-1].minor.yy328;
125215125658
pRhs->pPrior = yymsp[-2].minor.yy3;
125659
+ pRhs->selFlags &= ~SF_MultiValue;
125216125660
if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
125217125661
}else{
125218125662
sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
125219125663
}
125220125664
yygotominor.yy3 = pRhs;
@@ -125257,17 +125701,20 @@
125257125701
yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
125258125702
}
125259125703
break;
125260125704
case 121: /* values ::= values COMMA LP exprlist RP */
125261125705
{
125262
- Select *pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
125706
+ Select *pRight, *pLeft = yymsp[-4].minor.yy3;
125707
+ pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values|SF_MultiValue,0,0);
125708
+ if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
125263125709
if( pRight ){
125264125710
pRight->op = TK_ALL;
125265
- pRight->pPrior = yymsp[-4].minor.yy3;
125711
+ pLeft = yymsp[-4].minor.yy3;
125712
+ pRight->pPrior = pLeft;
125266125713
yygotominor.yy3 = pRight;
125267125714
}else{
125268
- yygotominor.yy3 = yymsp[-4].minor.yy3;
125715
+ yygotominor.yy3 = pLeft;
125269125716
}
125270125717
}
125271125718
break;
125272125719
case 122: /* distinct ::= DISTINCT */
125273125720
{yygotominor.yy381 = SF_Distinct;}
@@ -127067,14 +127514,12 @@
127067127514
goto abort_parse;
127068127515
}
127069127516
break;
127070127517
}
127071127518
case TK_ILLEGAL: {
127072
- sqlite3DbFree(db, *pzErrMsg);
127073
- *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"",
127519
+ sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"",
127074127520
&pParse->sLastToken);
127075
- nErr++;
127076127521
goto abort_parse;
127077127522
}
127078127523
case TK_SEMI: {
127079127524
pParse->zTail = &zSql[i];
127080127525
/* Fall thru into the default case */
@@ -127088,16 +127533,19 @@
127088127533
break;
127089127534
}
127090127535
}
127091127536
}
127092127537
abort_parse:
127093
- if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){
127538
+ assert( nErr==0 );
127539
+ if( zSql[i]==0 && pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
127094127540
if( lastTokenParsed!=TK_SEMI ){
127095127541
sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
127096127542
pParse->zTail = &zSql[i];
127097127543
}
127098
- sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
127544
+ if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
127545
+ sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
127546
+ }
127099127547
}
127100127548
#ifdef YYTRACKMAXSTACKDEPTH
127101127549
sqlite3_mutex_enter(sqlite3MallocMutex());
127102127550
sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
127103127551
sqlite3ParserStackPeak(pEngine)
@@ -127154,13 +127602,11 @@
127154127602
while( pParse->pZombieTab ){
127155127603
Table *p = pParse->pZombieTab;
127156127604
pParse->pZombieTab = p->pNextZombie;
127157127605
sqlite3DeleteTable(db, p);
127158127606
}
127159
- if( nErr>0 && pParse->rc==SQLITE_OK ){
127160
- pParse->rc = SQLITE_ERROR;
127161
- }
127607
+ assert( nErr==0 || pParse->rc!=SQLITE_OK );
127162127608
return nErr;
127163127609
}
127164127610
127165127611
/************** End of tokenize.c ********************************************/
127166127612
/************** Begin file complete.c ****************************************/
@@ -127432,11 +127878,11 @@
127432127878
** UTF-8.
127433127879
*/
127434127880
SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *zSql){
127435127881
sqlite3_value *pVal;
127436127882
char const *zSql8;
127437
- int rc = SQLITE_NOMEM;
127883
+ int rc;
127438127884
127439127885
#ifndef SQLITE_OMIT_AUTOINIT
127440127886
rc = sqlite3_initialize();
127441127887
if( rc ) return rc;
127442127888
#endif
@@ -127598,10 +128044,22 @@
127598128044
** zero if and only if SQLite was compiled with mutexing code omitted due to
127599128045
** the SQLITE_THREADSAFE compile-time option being set to 0.
127600128046
*/
127601128047
SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }
127602128048
128049
+/*
128050
+** When compiling the test fixture or with debugging enabled (on Win32),
128051
+** this variable being set to non-zero will cause OSTRACE macros to emit
128052
+** extra diagnostic information.
128053
+*/
128054
+#ifdef SQLITE_HAVE_OS_TRACE
128055
+# ifndef SQLITE_DEBUG_OS_TRACE
128056
+# define SQLITE_DEBUG_OS_TRACE 0
128057
+# endif
128058
+ int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
128059
+#endif
128060
+
127603128061
#if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
127604128062
/*
127605128063
** If the following function pointer is not NULL and if
127606128064
** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
127607128065
** I/O active are written using this function. These messages
@@ -128737,11 +129195,11 @@
128737129195
128738129196
/*
128739129197
** Return a static string containing the name corresponding to the error code
128740129198
** specified in the argument.
128741129199
*/
128742
-#if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || defined(SQLITE_TEST)
129200
+#if defined(SQLITE_NEED_ERR_NAME)
128743129201
SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
128744129202
const char *zName = 0;
128745129203
int i, origRc = rc;
128746129204
for(i=0; i<2 && zName==0; i++, rc &= 0xff){
128747129205
switch( rc ){
@@ -129962,18 +130420,18 @@
129962130420
){
129963130421
char *zOpt;
129964130422
int eState; /* Parser state when parsing URI */
129965130423
int iIn; /* Input character index */
129966130424
int iOut = 0; /* Output character index */
129967
- int nByte = nUri+2; /* Bytes of space to allocate */
130425
+ u64 nByte = nUri+2; /* Bytes of space to allocate */
129968130426
129969130427
/* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
129970130428
** method that there may be extra parameters following the file-name. */
129971130429
flags |= SQLITE_OPEN_URI;
129972130430
129973130431
for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
129974
- zFile = sqlite3_malloc(nByte);
130432
+ zFile = sqlite3_malloc64(nByte);
129975130433
if( !zFile ) return SQLITE_NOMEM;
129976130434
129977130435
iIn = 5;
129978130436
#ifdef SQLITE_ALLOW_URI_AUTHORITY
129979130437
if( strncmp(zUri+5, "///", 3)==0 ){
@@ -130135,11 +130593,11 @@
130135130593
130136130594
zOpt = &zVal[nVal+1];
130137130595
}
130138130596
130139130597
}else{
130140
- zFile = sqlite3_malloc(nUri+2);
130598
+ zFile = sqlite3_malloc64(nUri+2);
130141130599
if( !zFile ) return SQLITE_NOMEM;
130142130600
memcpy(zFile, zUri, nUri);
130143130601
zFile[nUri] = '\0';
130144130602
zFile[nUri+1] = '\0';
130145130603
flags &= ~SQLITE_OPEN_URI;
@@ -130406,10 +130864,17 @@
130406130864
#ifdef SQLITE_ENABLE_RTREE
130407130865
if( !db->mallocFailed && rc==SQLITE_OK){
130408130866
rc = sqlite3RtreeInit(db);
130409130867
}
130410130868
#endif
130869
+
130870
+#ifdef SQLITE_ENABLE_DBSTAT_VTAB
130871
+ if( !db->mallocFailed && rc==SQLITE_OK){
130872
+ int sqlite3_dbstat_register(sqlite3*);
130873
+ rc = sqlite3_dbstat_register(db);
130874
+ }
130875
+#endif
130411130876
130412130877
/* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
130413130878
** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
130414130879
** mode. Doing nothing at all also makes NORMAL the default.
130415130880
*/
@@ -132344,10 +132809,15 @@
132344132809
** false.
132345132810
*/
132346132811
#ifdef SQLITE_COVERAGE_TEST
132347132812
# define ALWAYS(x) (1)
132348132813
# define NEVER(X) (0)
132814
+#elif defined(SQLITE_DEBUG)
132815
+# define ALWAYS(x) sqlite3Fts3Always((x)!=0)
132816
+# define NEVER(x) sqlite3Fts3Never((x)!=0)
132817
+SQLITE_PRIVATE int sqlite3Fts3Always(int b);
132818
+SQLITE_PRIVATE int sqlite3Fts3Never(int b);
132349132819
#else
132350132820
# define ALWAYS(x) (x)
132351132821
# define NEVER(x) (x)
132352132822
#endif
132353132823
@@ -132744,10 +133214,11 @@
132744133214
#define fts3GetVarint32(p, piVal) ( \
132745133215
(*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
132746133216
)
132747133217
132748133218
/* fts3.c */
133219
+SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...);
132749133220
SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
132750133221
SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
132751133222
SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
132752133223
SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
132753133224
SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
@@ -132832,10 +133303,17 @@
132832133303
132833133304
static int fts3EvalNext(Fts3Cursor *pCsr);
132834133305
static int fts3EvalStart(Fts3Cursor *pCsr);
132835133306
static int fts3TermSegReaderCursor(
132836133307
Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **);
133308
+
133309
+#ifndef SQLITE_AMALGAMATION
133310
+# if defined(SQLITE_DEBUG)
133311
+SQLITE_PRIVATE int sqlite3Fts3Always(int b) { assert( b ); return b; }
133312
+SQLITE_PRIVATE int sqlite3Fts3Never(int b) { assert( !b ); return b; }
133313
+# endif
133314
+#endif
132837133315
132838133316
/*
132839133317
** Write a 64-bit variable-length integer to memory starting at p[0].
132840133318
** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
132841133319
** The number of bytes written is returned.
@@ -132942,11 +133420,11 @@
132942133420
int iOut = 0; /* Index of next byte to write to output */
132943133421
132944133422
/* If the first byte was a '[', then the close-quote character is a ']' */
132945133423
if( quote=='[' ) quote = ']';
132946133424
132947
- while( ALWAYS(z[iIn]) ){
133425
+ while( z[iIn] ){
132948133426
if( z[iIn]==quote ){
132949133427
if( z[iIn+1]!=quote ) break;
132950133428
z[iOut++] = quote;
132951133429
iIn += 2;
132952133430
}else{
@@ -133020,10 +133498,21 @@
133020133498
p->pTokenizer->pModule->xDestroy(p->pTokenizer);
133021133499
133022133500
sqlite3_free(p);
133023133501
return SQLITE_OK;
133024133502
}
133503
+
133504
+/*
133505
+** Write an error message into *pzErr
133506
+*/
133507
+SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char **pzErr, const char *zFormat, ...){
133508
+ va_list ap;
133509
+ sqlite3_free(*pzErr);
133510
+ va_start(ap, zFormat);
133511
+ *pzErr = sqlite3_vmprintf(zFormat, ap);
133512
+ va_end(ap);
133513
+}
133025133514
133026133515
/*
133027133516
** Construct one or more SQL statements from the format string given
133028133517
** and then evaluate those statements. The success code is written
133029133518
** into *pRc.
@@ -133539,11 +134028,12 @@
133539134028
sqlite3 *db, /* Database handle */
133540134029
const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */
133541134030
const char *zTbl, /* Name of content table */
133542134031
const char ***pazCol, /* OUT: Malloc'd array of column names */
133543134032
int *pnCol, /* OUT: Size of array *pazCol */
133544
- int *pnStr /* OUT: Bytes of string content */
134033
+ int *pnStr, /* OUT: Bytes of string content */
134034
+ char **pzErr /* OUT: error message */
133545134035
){
133546134036
int rc = SQLITE_OK; /* Return code */
133547134037
char *zSql; /* "SELECT *" statement on zTbl */
133548134038
sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */
133549134039
@@ -133550,10 +134040,13 @@
133550134040
zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", zDb, zTbl);
133551134041
if( !zSql ){
133552134042
rc = SQLITE_NOMEM;
133553134043
}else{
133554134044
rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
134045
+ if( rc!=SQLITE_OK ){
134046
+ sqlite3Fts3ErrMsg(pzErr, "%s", sqlite3_errmsg(db));
134047
+ }
133555134048
}
133556134049
sqlite3_free(zSql);
133557134050
133558134051
if( rc==SQLITE_OK ){
133559134052
const char **azCol; /* Output array */
@@ -133716,17 +134209,17 @@
133716134209
if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
133717134210
break;
133718134211
}
133719134212
}
133720134213
if( iOpt==SizeofArray(aFts4Opt) ){
133721
- *pzErr = sqlite3_mprintf("unrecognized parameter: %s", z);
134214
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
133722134215
rc = SQLITE_ERROR;
133723134216
}else{
133724134217
switch( iOpt ){
133725134218
case 0: /* MATCHINFO */
133726134219
if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
133727
- *pzErr = sqlite3_mprintf("unrecognized matchinfo: %s", zVal);
134220
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
133728134221
rc = SQLITE_ERROR;
133729134222
}
133730134223
bNoDocsize = 1;
133731134224
break;
133732134225
@@ -133750,11 +134243,11 @@
133750134243
133751134244
case 4: /* ORDER */
133752134245
if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
133753134246
&& (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
133754134247
){
133755
- *pzErr = sqlite3_mprintf("unrecognized order: %s", zVal);
134248
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
133756134249
rc = SQLITE_ERROR;
133757134250
}
133758134251
bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
133759134252
break;
133760134253
@@ -133801,11 +134294,11 @@
133801134294
zCompress = 0;
133802134295
zUncompress = 0;
133803134296
if( nCol==0 ){
133804134297
sqlite3_free((void*)aCol);
133805134298
aCol = 0;
133806
- rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString);
134299
+ rc = fts3ContentColumns(db, argv[1], zContent,&aCol,&nCol,&nString,pzErr);
133807134300
133808134301
/* If a languageid= option was specified, remove the language id
133809134302
** column from the aCol[] array. */
133810134303
if( rc==SQLITE_OK && zLanguageid ){
133811134304
int j;
@@ -133836,11 +134329,11 @@
133836134329
assert( pTokenizer );
133837134330
133838134331
rc = fts3PrefixParameter(zPrefix, &nIndex, &aIndex);
133839134332
if( rc==SQLITE_ERROR ){
133840134333
assert( zPrefix );
133841
- *pzErr = sqlite3_mprintf("error parsing prefix parameter: %s", zPrefix);
134334
+ sqlite3Fts3ErrMsg(pzErr, "error parsing prefix parameter: %s", zPrefix);
133842134335
}
133843134336
if( rc!=SQLITE_OK ) goto fts3_init_out;
133844134337
133845134338
/* Allocate and populate the Fts3Table structure. */
133846134339
nByte = sizeof(Fts3Table) + /* Fts3Table */
@@ -133918,19 +134411,19 @@
133918134411
}
133919134412
}
133920134413
}
133921134414
for(i=0; i<nNotindexed; i++){
133922134415
if( azNotindexed[i] ){
133923
- *pzErr = sqlite3_mprintf("no such column: %s", azNotindexed[i]);
134416
+ sqlite3Fts3ErrMsg(pzErr, "no such column: %s", azNotindexed[i]);
133924134417
rc = SQLITE_ERROR;
133925134418
}
133926134419
}
133927134420
133928134421
if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
133929134422
char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
133930134423
rc = SQLITE_ERROR;
133931
- *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
134424
+ sqlite3Fts3ErrMsg(pzErr, "missing %s parameter in fts4 constructor", zMiss);
133932134425
}
133933134426
p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
133934134427
p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc);
133935134428
if( rc!=SQLITE_OK ) goto fts3_init_out;
133936134429
@@ -135319,11 +135812,11 @@
135319135812
** Fts3SegReaderPending might segfault, as the data structures used by
135320135813
** fts4aux are not completely populated. So it's easiest to filter these
135321135814
** calls out here. */
135322135815
if( iLevel<0 && p->aIndex ){
135323135816
Fts3SegReader *pSeg = 0;
135324
- rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix, &pSeg);
135817
+ rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix||isScan, &pSeg);
135325135818
if( rc==SQLITE_OK && pSeg ){
135326135819
rc = fts3SegReaderCursorAppend(pCsr, pSeg);
135327135820
}
135328135821
}
135329135822
@@ -135968,15 +136461,35 @@
135968136461
*/
135969136462
static void fts3ReversePoslist(char *pStart, char **ppPoslist){
135970136463
char *p = &(*ppPoslist)[-2];
135971136464
char c = 0;
135972136465
136466
+ /* Skip backwards passed any trailing 0x00 bytes added by NearTrim() */
135973136467
while( p>pStart && (c=*p--)==0 );
136468
+
136469
+ /* Search backwards for a varint with value zero (the end of the previous
136470
+ ** poslist). This is an 0x00 byte preceded by some byte that does not
136471
+ ** have the 0x80 bit set. */
135974136472
while( p>pStart && (*p & 0x80) | c ){
135975136473
c = *p--;
135976136474
}
135977
- if( p>pStart ){ p = &p[2]; }
136475
+ assert( p==pStart || c==0 );
136476
+
136477
+ /* At this point p points to that preceding byte without the 0x80 bit
136478
+ ** set. So to find the start of the poslist, skip forward 2 bytes then
136479
+ ** over a varint.
136480
+ **
136481
+ ** Normally. The other case is that p==pStart and the poslist to return
136482
+ ** is the first in the doclist. In this case do not skip forward 2 bytes.
136483
+ ** The second part of the if condition (c==0 && *ppPoslist>&p[2])
136484
+ ** is required for cases where the first byte of a doclist and the
136485
+ ** doclist is empty. For example, if the first docid is 10, a doclist
136486
+ ** that begins with:
136487
+ **
136488
+ ** 0x0A 0x00 <next docid delta varint>
136489
+ */
136490
+ if( p>pStart || (c==0 && *ppPoslist>&p[2]) ){ p = &p[2]; }
135978136491
while( *p++&0x80 );
135979136492
*ppPoslist = p;
135980136493
}
135981136494
135982136495
/*
@@ -136043,10 +136556,12 @@
136043136556
case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]);
136044136557
case 2: zStart = (const char*)sqlite3_value_text(apVal[1]);
136045136558
}
136046136559
if( !zEllipsis || !zEnd || !zStart ){
136047136560
sqlite3_result_error_nomem(pContext);
136561
+ }else if( nToken==0 ){
136562
+ sqlite3_result_text(pContext, "", -1, SQLITE_STATIC);
136048136563
}else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){
136049136564
sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken);
136050136565
}
136051136566
}
136052136567
@@ -137104,16 +137619,18 @@
137104137619
Fts3Expr *pExpr, /* Expression to initialize phrases in */
137105137620
int *pRc /* IN/OUT: Error code */
137106137621
){
137107137622
if( pExpr && SQLITE_OK==*pRc ){
137108137623
if( pExpr->eType==FTSQUERY_PHRASE ){
137109
- int i;
137110137624
int nToken = pExpr->pPhrase->nToken;
137111
- for(i=0; i<nToken; i++){
137112
- if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
137625
+ if( nToken ){
137626
+ int i;
137627
+ for(i=0; i<nToken; i++){
137628
+ if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
137629
+ }
137630
+ pExpr->bDeferred = (i==nToken);
137113137631
}
137114
- pExpr->bDeferred = (i==nToken);
137115137632
*pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase);
137116137633
}else{
137117137634
fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc);
137118137635
fts3EvalStartReaders(pCsr, pExpr->pRight, pRc);
137119137636
pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred);
@@ -138272,11 +138789,12 @@
138272138789
if( rc!=SQLITE_OK ) return rc;
138273138790
138274138791
pIter = pPhrase->pOrPoslist;
138275138792
iDocid = pPhrase->iOrDocid;
138276138793
if( pCsr->bDesc==bDescDoclist ){
138277
- bEof = (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll));
138794
+ bEof = !pPhrase->doclist.nAll ||
138795
+ (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll));
138278138796
while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
138279138797
sqlite3Fts3DoclistNext(
138280138798
bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
138281138799
&pIter, &iDocid, &bEof
138282138800
);
@@ -138484,11 +139002,11 @@
138484139002
138485139003
*ppVtab = (sqlite3_vtab *)p;
138486139004
return SQLITE_OK;
138487139005
138488139006
bad_args:
138489
- *pzErr = sqlite3_mprintf("invalid arguments to fts4aux constructor");
139007
+ sqlite3Fts3ErrMsg(pzErr, "invalid arguments to fts4aux constructor");
138490139008
return SQLITE_ERROR;
138491139009
}
138492139010
138493139011
/*
138494139012
** This function does the work for both the xDisconnect and xDestroy methods.
@@ -139942,17 +140460,17 @@
139942140460
139943140461
if( rc!=SQLITE_OK ){
139944140462
sqlite3Fts3ExprFree(*ppExpr);
139945140463
*ppExpr = 0;
139946140464
if( rc==SQLITE_TOOBIG ){
139947
- *pzErr = sqlite3_mprintf(
140465
+ sqlite3Fts3ErrMsg(pzErr,
139948140466
"FTS expression tree is too large (maximum depth %d)",
139949140467
SQLITE_FTS3_MAX_EXPR_DEPTH
139950140468
);
139951140469
rc = SQLITE_ERROR;
139952140470
}else if( rc==SQLITE_ERROR ){
139953
- *pzErr = sqlite3_mprintf("malformed MATCH expression: [%s]", z);
140471
+ sqlite3Fts3ErrMsg(pzErr, "malformed MATCH expression: [%s]", z);
139954140472
}
139955140473
}
139956140474
139957140475
return rc;
139958140476
}
@@ -141424,11 +141942,11 @@
141424141942
z[n] = '\0';
141425141943
sqlite3Fts3Dequote(z);
141426141944
141427141945
m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1);
141428141946
if( !m ){
141429
- *pzErr = sqlite3_mprintf("unknown tokenizer: %s", z);
141947
+ sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", z);
141430141948
rc = SQLITE_ERROR;
141431141949
}else{
141432141950
char const **aArg = 0;
141433141951
int iArg = 0;
141434141952
z = &z[n+1];
@@ -141447,11 +141965,11 @@
141447141965
z = &z[n+1];
141448141966
}
141449141967
rc = m->xCreate(iArg, aArg, ppTok);
141450141968
assert( rc!=SQLITE_OK || *ppTok );
141451141969
if( rc!=SQLITE_OK ){
141452
- *pzErr = sqlite3_mprintf("unknown tokenizer");
141970
+ sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer");
141453141971
}else{
141454141972
(*ppTok)->pModule = m;
141455141973
}
141456141974
sqlite3_free((void *)aArg);
141457141975
}
@@ -141531,13 +142049,13 @@
141531142049
141532142050
pHash = (Fts3Hash *)sqlite3_user_data(context);
141533142051
p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
141534142052
141535142053
if( !p ){
141536
- char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
141537
- sqlite3_result_error(context, zErr, -1);
141538
- sqlite3_free(zErr);
142054
+ char *zErr2 = sqlite3_mprintf("unknown tokenizer: %s", zName);
142055
+ sqlite3_result_error(context, zErr2, -1);
142056
+ sqlite3_free(zErr2);
141539142057
return;
141540142058
}
141541142059
141542142060
pRet = Tcl_NewObj();
141543142061
Tcl_IncrRefCount(pRet);
@@ -142068,11 +142586,11 @@
142068142586
sqlite3_tokenizer_module *p;
142069142587
int nName = (int)strlen(zName);
142070142588
142071142589
p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
142072142590
if( !p ){
142073
- *pzErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
142591
+ sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", zName);
142074142592
return SQLITE_ERROR;
142075142593
}
142076142594
142077142595
*pp = p;
142078142596
return SQLITE_OK;
@@ -142765,11 +143283,11 @@
142765143283
/* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)",
142766143284
/* 24 */ "",
142767143285
/* 25 */ "",
142768143286
142769143287
/* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?",
142770
-/* 27 */ "SELECT DISTINCT level / (1024 * ?) FROM %Q.'%q_segdir'",
143288
+/* 27 */ "SELECT ? UNION SELECT level / (1024 * ?) FROM %Q.'%q_segdir'",
142771143289
142772143290
/* This statement is used to determine which level to read the input from
142773143291
** when performing an incremental merge. It returns the absolute level number
142774143292
** of the oldest level in the db that contains at least ? segments. Or,
142775143293
** if no level in the FTS index contains more than ? segments, the statement
@@ -145883,11 +146401,12 @@
145883146401
sqlite3_stmt *pAllLangid = 0;
145884146402
145885146403
rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
145886146404
if( rc==SQLITE_OK ){
145887146405
int rc2;
145888
- sqlite3_bind_int(pAllLangid, 1, p->nIndex);
146406
+ sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid);
146407
+ sqlite3_bind_int(pAllLangid, 2, p->nIndex);
145889146408
while( sqlite3_step(pAllLangid)==SQLITE_ROW ){
145890146409
int i;
145891146410
int iLangid = sqlite3_column_int(pAllLangid, 0);
145892146411
for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
145893146412
rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL);
@@ -147215,11 +147734,11 @@
147215147734
while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
147216147735
147217147736
pHint->n = i;
147218147737
i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
147219147738
i += fts3GetVarint32(&pHint->a[i], pnInput);
147220
- if( i!=nHint ) return SQLITE_CORRUPT_VTAB;
147739
+ if( i!=nHint ) return FTS_CORRUPT_VTAB;
147221147740
147222147741
return SQLITE_OK;
147223147742
}
147224147743
147225147744
@@ -147583,11 +148102,12 @@
147583148102
147584148103
/* This block calculates the checksum according to the FTS index. */
147585148104
rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
147586148105
if( rc==SQLITE_OK ){
147587148106
int rc2;
147588
- sqlite3_bind_int(pAllLangid, 1, p->nIndex);
148107
+ sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid);
148108
+ sqlite3_bind_int(pAllLangid, 2, p->nIndex);
147589148109
while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){
147590148110
int iLangid = sqlite3_column_int(pAllLangid, 0);
147591148111
int i;
147592148112
for(i=0; i<p->nIndex; i++){
147593148113
cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc);
@@ -147596,11 +148116,10 @@
147596148116
rc2 = sqlite3_reset(pAllLangid);
147597148117
if( rc==SQLITE_OK ) rc = rc2;
147598148118
}
147599148119
147600148120
/* This block calculates the checksum according to the %_content table */
147601
- rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
147602148121
if( rc==SQLITE_OK ){
147603148122
sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule;
147604148123
sqlite3_stmt *pStmt = 0;
147605148124
char *zSql;
147606148125
@@ -147693,11 +148212,11 @@
147693148212
Fts3Table *p /* FTS3 table handle */
147694148213
){
147695148214
int rc;
147696148215
int bOk = 0;
147697148216
rc = fts3IntegrityCheck(p, &bOk);
147698
- if( rc==SQLITE_OK && bOk==0 ) rc = SQLITE_CORRUPT_VTAB;
148217
+ if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB;
147699148218
return rc;
147700148219
}
147701148220
147702148221
/*
147703148222
** Handle a 'special' INSERT of the form:
@@ -148131,10 +148650,11 @@
148131148650
#define FTS3_MATCHINFO_NDOC 'n' /* 1 value */
148132148651
#define FTS3_MATCHINFO_AVGLENGTH 'a' /* nCol values */
148133148652
#define FTS3_MATCHINFO_LENGTH 'l' /* nCol values */
148134148653
#define FTS3_MATCHINFO_LCS 's' /* nCol values */
148135148654
#define FTS3_MATCHINFO_HITS 'x' /* 3*nCol*nPhrase values */
148655
+#define FTS3_MATCHINFO_LHITS 'y' /* nCol*nPhrase values */
148136148656
148137148657
/*
148138148658
** The default value for the second argument to matchinfo().
148139148659
*/
148140148660
#define FTS3_MATCHINFO_DEFAULT "pcx"
@@ -148912,10 +149432,55 @@
148912149432
}
148913149433
}
148914149434
148915149435
return rc;
148916149436
}
149437
+
149438
+/*
149439
+** fts3ExprIterate() callback used to gather information for the matchinfo
149440
+** directive 'y'.
149441
+*/
149442
+static int fts3ExprLHitsCb(
149443
+ Fts3Expr *pExpr, /* Phrase expression node */
149444
+ int iPhrase, /* Phrase number */
149445
+ void *pCtx /* Pointer to MatchInfo structure */
149446
+){
149447
+ MatchInfo *p = (MatchInfo *)pCtx;
149448
+ Fts3Table *pTab = (Fts3Table *)p->pCursor->base.pVtab;
149449
+ int rc = SQLITE_OK;
149450
+ int iStart = iPhrase * p->nCol;
149451
+ Fts3Expr *pEof; /* Ancestor node already at EOF */
149452
+
149453
+ /* This must be a phrase */
149454
+ assert( pExpr->pPhrase );
149455
+
149456
+ /* Initialize all output integers to zero. */
149457
+ memset(&p->aMatchinfo[iStart], 0, sizeof(u32) * p->nCol);
149458
+
149459
+ /* Check if this or any parent node is at EOF. If so, then all output
149460
+ ** values are zero. */
149461
+ for(pEof=pExpr; pEof && pEof->bEof==0; pEof=pEof->pParent);
149462
+
149463
+ if( pEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
149464
+ Fts3Phrase *pPhrase = pExpr->pPhrase;
149465
+ char *pIter = pPhrase->doclist.pList;
149466
+ int iCol = 0;
149467
+
149468
+ while( 1 ){
149469
+ int nHit = fts3ColumnlistCount(&pIter);
149470
+ if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){
149471
+ p->aMatchinfo[iStart + iCol] = (u32)nHit;
149472
+ }
149473
+ assert( *pIter==0x00 || *pIter==0x01 );
149474
+ if( *pIter!=0x01 ) break;
149475
+ pIter++;
149476
+ pIter += fts3GetVarint32(pIter, &iCol);
149477
+ }
149478
+ }
149479
+
149480
+ return rc;
149481
+}
148917149482
148918149483
static int fts3MatchinfoCheck(
148919149484
Fts3Table *pTab,
148920149485
char cArg,
148921149486
char **pzErr
@@ -148925,14 +149490,15 @@
148925149490
|| (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4)
148926149491
|| (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4)
148927149492
|| (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize)
148928149493
|| (cArg==FTS3_MATCHINFO_LCS)
148929149494
|| (cArg==FTS3_MATCHINFO_HITS)
149495
+ || (cArg==FTS3_MATCHINFO_LHITS)
148930149496
){
148931149497
return SQLITE_OK;
148932149498
}
148933
- *pzErr = sqlite3_mprintf("unrecognized matchinfo request: %c", cArg);
149499
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
148934149500
return SQLITE_ERROR;
148935149501
}
148936149502
148937149503
static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
148938149504
int nVal; /* Number of integers output by cArg */
@@ -148947,10 +149513,14 @@
148947149513
case FTS3_MATCHINFO_AVGLENGTH:
148948149514
case FTS3_MATCHINFO_LENGTH:
148949149515
case FTS3_MATCHINFO_LCS:
148950149516
nVal = pInfo->nCol;
148951149517
break;
149518
+
149519
+ case FTS3_MATCHINFO_LHITS:
149520
+ nVal = pInfo->nCol * pInfo->nPhrase;
149521
+ break;
148952149522
148953149523
default:
148954149524
assert( cArg==FTS3_MATCHINFO_HITS );
148955149525
nVal = pInfo->nCol * pInfo->nPhrase * 3;
148956149526
break;
@@ -149201,10 +149771,14 @@
149201149771
rc = fts3ExprLoadDoclists(pCsr, 0, 0);
149202149772
if( rc==SQLITE_OK ){
149203149773
rc = fts3MatchinfoLcs(pCsr, pInfo);
149204149774
}
149205149775
break;
149776
+
149777
+ case FTS3_MATCHINFO_LHITS:
149778
+ (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLHitsCb, (void*)pInfo);
149779
+ break;
149206149780
149207149781
default: {
149208149782
Fts3Expr *pExpr;
149209149783
assert( zArg[i]==FTS3_MATCHINFO_HITS );
149210149784
pExpr = pCsr->pExpr;
@@ -153214,15 +153788,23 @@
153214153788
** conflict-handling mode specified by the user.
153215153789
*/
153216153790
if( nData>1 ){
153217153791
int ii;
153218153792
153219
- /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
153220
- assert( nData==(pRtree->nDim*2 + 3) );
153793
+ /* Populate the cell.aCoord[] array. The first coordinate is azData[3].
153794
+ **
153795
+ ** NB: nData can only be less than nDim*2+3 if the rtree is mis-declared
153796
+ ** with "column" that are interpreted as table constraints.
153797
+ ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5));
153798
+ ** This problem was discovered after years of use, so we silently ignore
153799
+ ** these kinds of misdeclared tables to avoid breaking any legacy.
153800
+ */
153801
+ assert( nData<=(pRtree->nDim*2 + 3) );
153802
+
153221153803
#ifndef SQLITE_RTREE_INT_ONLY
153222153804
if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
153223
- for(ii=0; ii<(pRtree->nDim*2); ii+=2){
153805
+ for(ii=0; ii<nData-4; ii+=2){
153224153806
cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
153225153807
cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]);
153226153808
if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
153227153809
rc = SQLITE_CONSTRAINT;
153228153810
goto constraint;
@@ -153229,11 +153811,11 @@
153229153811
}
153230153812
}
153231153813
}else
153232153814
#endif
153233153815
{
153234
- for(ii=0; ii<(pRtree->nDim*2); ii+=2){
153816
+ for(ii=0; ii<nData-4; ii+=2){
153235153817
cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]);
153236153818
cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]);
153237153819
if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){
153238153820
rc = SQLITE_CONSTRAINT;
153239153821
goto constraint;
@@ -154629,5 +155211,656 @@
154629155211
154630155212
#endif /* defined(SQLITE_ENABLE_ICU) */
154631155213
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
154632155214
154633155215
/************** End of fts3_icu.c ********************************************/
155216
+/************** Begin file dbstat.c ******************************************/
155217
+/*
155218
+** 2010 July 12
155219
+**
155220
+** The author disclaims copyright to this source code. In place of
155221
+** a legal notice, here is a blessing:
155222
+**
155223
+** May you do good and not evil.
155224
+** May you find forgiveness for yourself and forgive others.
155225
+** May you share freely, never taking more than you give.
155226
+**
155227
+******************************************************************************
155228
+**
155229
+** This file contains an implementation of the "dbstat" virtual table.
155230
+**
155231
+** The dbstat virtual table is used to extract low-level formatting
155232
+** information from an SQLite database in order to implement the
155233
+** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script
155234
+** for an example implementation.
155235
+*/
155236
+
155237
+#if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
155238
+ && !defined(SQLITE_OMIT_VIRTUALTABLE)
155239
+
155240
+/*
155241
+** Page paths:
155242
+**
155243
+** The value of the 'path' column describes the path taken from the
155244
+** root-node of the b-tree structure to each page. The value of the
155245
+** root-node path is '/'.
155246
+**
155247
+** The value of the path for the left-most child page of the root of
155248
+** a b-tree is '/000/'. (Btrees store content ordered from left to right
155249
+** so the pages to the left have smaller keys than the pages to the right.)
155250
+** The next to left-most child of the root page is
155251
+** '/001', and so on, each sibling page identified by a 3-digit hex
155252
+** value. The children of the 451st left-most sibling have paths such
155253
+** as '/1c2/000/, '/1c2/001/' etc.
155254
+**
155255
+** Overflow pages are specified by appending a '+' character and a
155256
+** six-digit hexadecimal value to the path to the cell they are linked
155257
+** from. For example, the three overflow pages in a chain linked from
155258
+** the left-most cell of the 450th child of the root page are identified
155259
+** by the paths:
155260
+**
155261
+** '/1c2/000+000000' // First page in overflow chain
155262
+** '/1c2/000+000001' // Second page in overflow chain
155263
+** '/1c2/000+000002' // Third page in overflow chain
155264
+**
155265
+** If the paths are sorted using the BINARY collation sequence, then
155266
+** the overflow pages associated with a cell will appear earlier in the
155267
+** sort-order than its child page:
155268
+**
155269
+** '/1c2/000/' // Left-most child of 451st child of root
155270
+*/
155271
+#define VTAB_SCHEMA \
155272
+ "CREATE TABLE xx( " \
155273
+ " name STRING, /* Name of table or index */" \
155274
+ " path INTEGER, /* Path to page from root */" \
155275
+ " pageno INTEGER, /* Page number */" \
155276
+ " pagetype STRING, /* 'internal', 'leaf' or 'overflow' */" \
155277
+ " ncell INTEGER, /* Cells on page (0 for overflow) */" \
155278
+ " payload INTEGER, /* Bytes of payload on this page */" \
155279
+ " unused INTEGER, /* Bytes of unused space on this page */" \
155280
+ " mx_payload INTEGER, /* Largest payload size of all cells */" \
155281
+ " pgoffset INTEGER, /* Offset of page in file */" \
155282
+ " pgsize INTEGER /* Size of the page */" \
155283
+ ");"
155284
+
155285
+
155286
+typedef struct StatTable StatTable;
155287
+typedef struct StatCursor StatCursor;
155288
+typedef struct StatPage StatPage;
155289
+typedef struct StatCell StatCell;
155290
+
155291
+struct StatCell {
155292
+ int nLocal; /* Bytes of local payload */
155293
+ u32 iChildPg; /* Child node (or 0 if this is a leaf) */
155294
+ int nOvfl; /* Entries in aOvfl[] */
155295
+ u32 *aOvfl; /* Array of overflow page numbers */
155296
+ int nLastOvfl; /* Bytes of payload on final overflow page */
155297
+ int iOvfl; /* Iterates through aOvfl[] */
155298
+};
155299
+
155300
+struct StatPage {
155301
+ u32 iPgno;
155302
+ DbPage *pPg;
155303
+ int iCell;
155304
+
155305
+ char *zPath; /* Path to this page */
155306
+
155307
+ /* Variables populated by statDecodePage(): */
155308
+ u8 flags; /* Copy of flags byte */
155309
+ int nCell; /* Number of cells on page */
155310
+ int nUnused; /* Number of unused bytes on page */
155311
+ StatCell *aCell; /* Array of parsed cells */
155312
+ u32 iRightChildPg; /* Right-child page number (or 0) */
155313
+ int nMxPayload; /* Largest payload of any cell on this page */
155314
+};
155315
+
155316
+struct StatCursor {
155317
+ sqlite3_vtab_cursor base;
155318
+ sqlite3_stmt *pStmt; /* Iterates through set of root pages */
155319
+ int isEof; /* After pStmt has returned SQLITE_DONE */
155320
+
155321
+ StatPage aPage[32];
155322
+ int iPage; /* Current entry in aPage[] */
155323
+
155324
+ /* Values to return. */
155325
+ char *zName; /* Value of 'name' column */
155326
+ char *zPath; /* Value of 'path' column */
155327
+ u32 iPageno; /* Value of 'pageno' column */
155328
+ char *zPagetype; /* Value of 'pagetype' column */
155329
+ int nCell; /* Value of 'ncell' column */
155330
+ int nPayload; /* Value of 'payload' column */
155331
+ int nUnused; /* Value of 'unused' column */
155332
+ int nMxPayload; /* Value of 'mx_payload' column */
155333
+ i64 iOffset; /* Value of 'pgOffset' column */
155334
+ int szPage; /* Value of 'pgSize' column */
155335
+};
155336
+
155337
+struct StatTable {
155338
+ sqlite3_vtab base;
155339
+ sqlite3 *db;
155340
+ int iDb; /* Index of database to analyze */
155341
+};
155342
+
155343
+#ifndef get2byte
155344
+# define get2byte(x) ((x)[0]<<8 | (x)[1])
155345
+#endif
155346
+
155347
+/*
155348
+** Connect to or create a statvfs virtual table.
155349
+*/
155350
+static int statConnect(
155351
+ sqlite3 *db,
155352
+ void *pAux,
155353
+ int argc, const char *const*argv,
155354
+ sqlite3_vtab **ppVtab,
155355
+ char **pzErr
155356
+){
155357
+ StatTable *pTab = 0;
155358
+ int rc = SQLITE_OK;
155359
+ int iDb;
155360
+
155361
+ if( argc>=4 ){
155362
+ iDb = sqlite3FindDbName(db, argv[3]);
155363
+ if( iDb<0 ){
155364
+ *pzErr = sqlite3_mprintf("no such database: %s", argv[3]);
155365
+ return SQLITE_ERROR;
155366
+ }
155367
+ }else{
155368
+ iDb = 0;
155369
+ }
155370
+ rc = sqlite3_declare_vtab(db, VTAB_SCHEMA);
155371
+ if( rc==SQLITE_OK ){
155372
+ pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable));
155373
+ if( pTab==0 ) rc = SQLITE_NOMEM;
155374
+ }
155375
+
155376
+ assert( rc==SQLITE_OK || pTab==0 );
155377
+ if( rc==SQLITE_OK ){
155378
+ memset(pTab, 0, sizeof(StatTable));
155379
+ pTab->db = db;
155380
+ pTab->iDb = iDb;
155381
+ }
155382
+
155383
+ *ppVtab = (sqlite3_vtab*)pTab;
155384
+ return rc;
155385
+}
155386
+
155387
+/*
155388
+** Disconnect from or destroy a statvfs virtual table.
155389
+*/
155390
+static int statDisconnect(sqlite3_vtab *pVtab){
155391
+ sqlite3_free(pVtab);
155392
+ return SQLITE_OK;
155393
+}
155394
+
155395
+/*
155396
+** There is no "best-index". This virtual table always does a linear
155397
+** scan of the binary VFS log file.
155398
+*/
155399
+static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
155400
+
155401
+ /* Records are always returned in ascending order of (name, path).
155402
+ ** If this will satisfy the client, set the orderByConsumed flag so that
155403
+ ** SQLite does not do an external sort.
155404
+ */
155405
+ if( ( pIdxInfo->nOrderBy==1
155406
+ && pIdxInfo->aOrderBy[0].iColumn==0
155407
+ && pIdxInfo->aOrderBy[0].desc==0
155408
+ ) ||
155409
+ ( pIdxInfo->nOrderBy==2
155410
+ && pIdxInfo->aOrderBy[0].iColumn==0
155411
+ && pIdxInfo->aOrderBy[0].desc==0
155412
+ && pIdxInfo->aOrderBy[1].iColumn==1
155413
+ && pIdxInfo->aOrderBy[1].desc==0
155414
+ )
155415
+ ){
155416
+ pIdxInfo->orderByConsumed = 1;
155417
+ }
155418
+
155419
+ pIdxInfo->estimatedCost = 10.0;
155420
+ return SQLITE_OK;
155421
+}
155422
+
155423
+/*
155424
+** Open a new statvfs cursor.
155425
+*/
155426
+static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
155427
+ StatTable *pTab = (StatTable *)pVTab;
155428
+ StatCursor *pCsr;
155429
+ int rc;
155430
+
155431
+ pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor));
155432
+ if( pCsr==0 ){
155433
+ rc = SQLITE_NOMEM;
155434
+ }else{
155435
+ char *zSql;
155436
+ memset(pCsr, 0, sizeof(StatCursor));
155437
+ pCsr->base.pVtab = pVTab;
155438
+
155439
+ zSql = sqlite3_mprintf(
155440
+ "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
155441
+ " UNION ALL "
155442
+ "SELECT name, rootpage, type"
155443
+ " FROM \"%w\".sqlite_master WHERE rootpage!=0"
155444
+ " ORDER BY name", pTab->db->aDb[pTab->iDb].zName);
155445
+ if( zSql==0 ){
155446
+ rc = SQLITE_NOMEM;
155447
+ }else{
155448
+ rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
155449
+ sqlite3_free(zSql);
155450
+ }
155451
+ if( rc!=SQLITE_OK ){
155452
+ sqlite3_free(pCsr);
155453
+ pCsr = 0;
155454
+ }
155455
+ }
155456
+
155457
+ *ppCursor = (sqlite3_vtab_cursor *)pCsr;
155458
+ return rc;
155459
+}
155460
+
155461
+static void statClearPage(StatPage *p){
155462
+ int i;
155463
+ if( p->aCell ){
155464
+ for(i=0; i<p->nCell; i++){
155465
+ sqlite3_free(p->aCell[i].aOvfl);
155466
+ }
155467
+ sqlite3_free(p->aCell);
155468
+ }
155469
+ sqlite3PagerUnref(p->pPg);
155470
+ sqlite3_free(p->zPath);
155471
+ memset(p, 0, sizeof(StatPage));
155472
+}
155473
+
155474
+static void statResetCsr(StatCursor *pCsr){
155475
+ int i;
155476
+ sqlite3_reset(pCsr->pStmt);
155477
+ for(i=0; i<ArraySize(pCsr->aPage); i++){
155478
+ statClearPage(&pCsr->aPage[i]);
155479
+ }
155480
+ pCsr->iPage = 0;
155481
+ sqlite3_free(pCsr->zPath);
155482
+ pCsr->zPath = 0;
155483
+}
155484
+
155485
+/*
155486
+** Close a statvfs cursor.
155487
+*/
155488
+static int statClose(sqlite3_vtab_cursor *pCursor){
155489
+ StatCursor *pCsr = (StatCursor *)pCursor;
155490
+ statResetCsr(pCsr);
155491
+ sqlite3_finalize(pCsr->pStmt);
155492
+ sqlite3_free(pCsr);
155493
+ return SQLITE_OK;
155494
+}
155495
+
155496
+static void getLocalPayload(
155497
+ int nUsable, /* Usable bytes per page */
155498
+ u8 flags, /* Page flags */
155499
+ int nTotal, /* Total record (payload) size */
155500
+ int *pnLocal /* OUT: Bytes stored locally */
155501
+){
155502
+ int nLocal;
155503
+ int nMinLocal;
155504
+ int nMaxLocal;
155505
+
155506
+ if( flags==0x0D ){ /* Table leaf node */
155507
+ nMinLocal = (nUsable - 12) * 32 / 255 - 23;
155508
+ nMaxLocal = nUsable - 35;
155509
+ }else{ /* Index interior and leaf nodes */
155510
+ nMinLocal = (nUsable - 12) * 32 / 255 - 23;
155511
+ nMaxLocal = (nUsable - 12) * 64 / 255 - 23;
155512
+ }
155513
+
155514
+ nLocal = nMinLocal + (nTotal - nMinLocal) % (nUsable - 4);
155515
+ if( nLocal>nMaxLocal ) nLocal = nMinLocal;
155516
+ *pnLocal = nLocal;
155517
+}
155518
+
155519
+static int statDecodePage(Btree *pBt, StatPage *p){
155520
+ int nUnused;
155521
+ int iOff;
155522
+ int nHdr;
155523
+ int isLeaf;
155524
+ int szPage;
155525
+
155526
+ u8 *aData = sqlite3PagerGetData(p->pPg);
155527
+ u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0];
155528
+
155529
+ p->flags = aHdr[0];
155530
+ p->nCell = get2byte(&aHdr[3]);
155531
+ p->nMxPayload = 0;
155532
+
155533
+ isLeaf = (p->flags==0x0A || p->flags==0x0D);
155534
+ nHdr = 12 - isLeaf*4 + (p->iPgno==1)*100;
155535
+
155536
+ nUnused = get2byte(&aHdr[5]) - nHdr - 2*p->nCell;
155537
+ nUnused += (int)aHdr[7];
155538
+ iOff = get2byte(&aHdr[1]);
155539
+ while( iOff ){
155540
+ nUnused += get2byte(&aData[iOff+2]);
155541
+ iOff = get2byte(&aData[iOff]);
155542
+ }
155543
+ p->nUnused = nUnused;
155544
+ p->iRightChildPg = isLeaf ? 0 : sqlite3Get4byte(&aHdr[8]);
155545
+ szPage = sqlite3BtreeGetPageSize(pBt);
155546
+
155547
+ if( p->nCell ){
155548
+ int i; /* Used to iterate through cells */
155549
+ int nUsable; /* Usable bytes per page */
155550
+
155551
+ sqlite3BtreeEnter(pBt);
155552
+ nUsable = szPage - sqlite3BtreeGetReserveNoMutex(pBt);
155553
+ sqlite3BtreeLeave(pBt);
155554
+ p->aCell = sqlite3_malloc64((p->nCell+1) * sizeof(StatCell));
155555
+ if( p->aCell==0 ) return SQLITE_NOMEM;
155556
+ memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell));
155557
+
155558
+ for(i=0; i<p->nCell; i++){
155559
+ StatCell *pCell = &p->aCell[i];
155560
+
155561
+ iOff = get2byte(&aData[nHdr+i*2]);
155562
+ if( !isLeaf ){
155563
+ pCell->iChildPg = sqlite3Get4byte(&aData[iOff]);
155564
+ iOff += 4;
155565
+ }
155566
+ if( p->flags==0x05 ){
155567
+ /* A table interior node. nPayload==0. */
155568
+ }else{
155569
+ u32 nPayload; /* Bytes of payload total (local+overflow) */
155570
+ int nLocal; /* Bytes of payload stored locally */
155571
+ iOff += getVarint32(&aData[iOff], nPayload);
155572
+ if( p->flags==0x0D ){
155573
+ u64 dummy;
155574
+ iOff += sqlite3GetVarint(&aData[iOff], &dummy);
155575
+ }
155576
+ if( nPayload>(u32)p->nMxPayload ) p->nMxPayload = nPayload;
155577
+ getLocalPayload(nUsable, p->flags, nPayload, &nLocal);
155578
+ pCell->nLocal = nLocal;
155579
+ assert( nLocal>=0 );
155580
+ assert( nPayload>=(u32)nLocal );
155581
+ assert( nLocal<=(nUsable-35) );
155582
+ if( nPayload>(u32)nLocal ){
155583
+ int j;
155584
+ int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4);
155585
+ pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4);
155586
+ pCell->nOvfl = nOvfl;
155587
+ pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl);
155588
+ if( pCell->aOvfl==0 ) return SQLITE_NOMEM;
155589
+ pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]);
155590
+ for(j=1; j<nOvfl; j++){
155591
+ int rc;
155592
+ u32 iPrev = pCell->aOvfl[j-1];
155593
+ DbPage *pPg = 0;
155594
+ rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg);
155595
+ if( rc!=SQLITE_OK ){
155596
+ assert( pPg==0 );
155597
+ return rc;
155598
+ }
155599
+ pCell->aOvfl[j] = sqlite3Get4byte(sqlite3PagerGetData(pPg));
155600
+ sqlite3PagerUnref(pPg);
155601
+ }
155602
+ }
155603
+ }
155604
+ }
155605
+ }
155606
+
155607
+ return SQLITE_OK;
155608
+}
155609
+
155610
+/*
155611
+** Populate the pCsr->iOffset and pCsr->szPage member variables. Based on
155612
+** the current value of pCsr->iPageno.
155613
+*/
155614
+static void statSizeAndOffset(StatCursor *pCsr){
155615
+ StatTable *pTab = (StatTable *)((sqlite3_vtab_cursor *)pCsr)->pVtab;
155616
+ Btree *pBt = pTab->db->aDb[pTab->iDb].pBt;
155617
+ Pager *pPager = sqlite3BtreePager(pBt);
155618
+ sqlite3_file *fd;
155619
+ sqlite3_int64 x[2];
155620
+
155621
+ /* The default page size and offset */
155622
+ pCsr->szPage = sqlite3BtreeGetPageSize(pBt);
155623
+ pCsr->iOffset = (i64)pCsr->szPage * (pCsr->iPageno - 1);
155624
+
155625
+ /* If connected to a ZIPVFS backend, override the page size and
155626
+ ** offset with actual values obtained from ZIPVFS.
155627
+ */
155628
+ fd = sqlite3PagerFile(pPager);
155629
+ x[0] = pCsr->iPageno;
155630
+ if( fd->pMethods!=0 && sqlite3OsFileControl(fd, 230440, &x)==SQLITE_OK ){
155631
+ pCsr->iOffset = x[0];
155632
+ pCsr->szPage = (int)x[1];
155633
+ }
155634
+}
155635
+
155636
+/*
155637
+** Move a statvfs cursor to the next entry in the file.
155638
+*/
155639
+static int statNext(sqlite3_vtab_cursor *pCursor){
155640
+ int rc;
155641
+ int nPayload;
155642
+ char *z;
155643
+ StatCursor *pCsr = (StatCursor *)pCursor;
155644
+ StatTable *pTab = (StatTable *)pCursor->pVtab;
155645
+ Btree *pBt = pTab->db->aDb[pTab->iDb].pBt;
155646
+ Pager *pPager = sqlite3BtreePager(pBt);
155647
+
155648
+ sqlite3_free(pCsr->zPath);
155649
+ pCsr->zPath = 0;
155650
+
155651
+statNextRestart:
155652
+ if( pCsr->aPage[0].pPg==0 ){
155653
+ rc = sqlite3_step(pCsr->pStmt);
155654
+ if( rc==SQLITE_ROW ){
155655
+ int nPage;
155656
+ u32 iRoot = (u32)sqlite3_column_int64(pCsr->pStmt, 1);
155657
+ sqlite3PagerPagecount(pPager, &nPage);
155658
+ if( nPage==0 ){
155659
+ pCsr->isEof = 1;
155660
+ return sqlite3_reset(pCsr->pStmt);
155661
+ }
155662
+ rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg);
155663
+ pCsr->aPage[0].iPgno = iRoot;
155664
+ pCsr->aPage[0].iCell = 0;
155665
+ pCsr->aPage[0].zPath = z = sqlite3_mprintf("/");
155666
+ pCsr->iPage = 0;
155667
+ if( z==0 ) rc = SQLITE_NOMEM;
155668
+ }else{
155669
+ pCsr->isEof = 1;
155670
+ return sqlite3_reset(pCsr->pStmt);
155671
+ }
155672
+ }else{
155673
+
155674
+ /* Page p itself has already been visited. */
155675
+ StatPage *p = &pCsr->aPage[pCsr->iPage];
155676
+
155677
+ while( p->iCell<p->nCell ){
155678
+ StatCell *pCell = &p->aCell[p->iCell];
155679
+ if( pCell->iOvfl<pCell->nOvfl ){
155680
+ int nUsable;
155681
+ sqlite3BtreeEnter(pBt);
155682
+ nUsable = sqlite3BtreeGetPageSize(pBt) -
155683
+ sqlite3BtreeGetReserveNoMutex(pBt);
155684
+ sqlite3BtreeLeave(pBt);
155685
+ pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
155686
+ pCsr->iPageno = pCell->aOvfl[pCell->iOvfl];
155687
+ pCsr->zPagetype = "overflow";
155688
+ pCsr->nCell = 0;
155689
+ pCsr->nMxPayload = 0;
155690
+ pCsr->zPath = z = sqlite3_mprintf(
155691
+ "%s%.3x+%.6x", p->zPath, p->iCell, pCell->iOvfl
155692
+ );
155693
+ if( pCell->iOvfl<pCell->nOvfl-1 ){
155694
+ pCsr->nUnused = 0;
155695
+ pCsr->nPayload = nUsable - 4;
155696
+ }else{
155697
+ pCsr->nPayload = pCell->nLastOvfl;
155698
+ pCsr->nUnused = nUsable - 4 - pCsr->nPayload;
155699
+ }
155700
+ pCell->iOvfl++;
155701
+ statSizeAndOffset(pCsr);
155702
+ return z==0 ? SQLITE_NOMEM : SQLITE_OK;
155703
+ }
155704
+ if( p->iRightChildPg ) break;
155705
+ p->iCell++;
155706
+ }
155707
+
155708
+ if( !p->iRightChildPg || p->iCell>p->nCell ){
155709
+ statClearPage(p);
155710
+ if( pCsr->iPage==0 ) return statNext(pCursor);
155711
+ pCsr->iPage--;
155712
+ goto statNextRestart; /* Tail recursion */
155713
+ }
155714
+ pCsr->iPage++;
155715
+ assert( p==&pCsr->aPage[pCsr->iPage-1] );
155716
+
155717
+ if( p->iCell==p->nCell ){
155718
+ p[1].iPgno = p->iRightChildPg;
155719
+ }else{
155720
+ p[1].iPgno = p->aCell[p->iCell].iChildPg;
155721
+ }
155722
+ rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg);
155723
+ p[1].iCell = 0;
155724
+ p[1].zPath = z = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell);
155725
+ p->iCell++;
155726
+ if( z==0 ) rc = SQLITE_NOMEM;
155727
+ }
155728
+
155729
+
155730
+ /* Populate the StatCursor fields with the values to be returned
155731
+ ** by the xColumn() and xRowid() methods.
155732
+ */
155733
+ if( rc==SQLITE_OK ){
155734
+ int i;
155735
+ StatPage *p = &pCsr->aPage[pCsr->iPage];
155736
+ pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
155737
+ pCsr->iPageno = p->iPgno;
155738
+
155739
+ rc = statDecodePage(pBt, p);
155740
+ if( rc==SQLITE_OK ){
155741
+ statSizeAndOffset(pCsr);
155742
+
155743
+ switch( p->flags ){
155744
+ case 0x05: /* table internal */
155745
+ case 0x02: /* index internal */
155746
+ pCsr->zPagetype = "internal";
155747
+ break;
155748
+ case 0x0D: /* table leaf */
155749
+ case 0x0A: /* index leaf */
155750
+ pCsr->zPagetype = "leaf";
155751
+ break;
155752
+ default:
155753
+ pCsr->zPagetype = "corrupted";
155754
+ break;
155755
+ }
155756
+ pCsr->nCell = p->nCell;
155757
+ pCsr->nUnused = p->nUnused;
155758
+ pCsr->nMxPayload = p->nMxPayload;
155759
+ pCsr->zPath = z = sqlite3_mprintf("%s", p->zPath);
155760
+ if( z==0 ) rc = SQLITE_NOMEM;
155761
+ nPayload = 0;
155762
+ for(i=0; i<p->nCell; i++){
155763
+ nPayload += p->aCell[i].nLocal;
155764
+ }
155765
+ pCsr->nPayload = nPayload;
155766
+ }
155767
+ }
155768
+
155769
+ return rc;
155770
+}
155771
+
155772
+static int statEof(sqlite3_vtab_cursor *pCursor){
155773
+ StatCursor *pCsr = (StatCursor *)pCursor;
155774
+ return pCsr->isEof;
155775
+}
155776
+
155777
+static int statFilter(
155778
+ sqlite3_vtab_cursor *pCursor,
155779
+ int idxNum, const char *idxStr,
155780
+ int argc, sqlite3_value **argv
155781
+){
155782
+ StatCursor *pCsr = (StatCursor *)pCursor;
155783
+
155784
+ statResetCsr(pCsr);
155785
+ return statNext(pCursor);
155786
+}
155787
+
155788
+static int statColumn(
155789
+ sqlite3_vtab_cursor *pCursor,
155790
+ sqlite3_context *ctx,
155791
+ int i
155792
+){
155793
+ StatCursor *pCsr = (StatCursor *)pCursor;
155794
+ switch( i ){
155795
+ case 0: /* name */
155796
+ sqlite3_result_text(ctx, pCsr->zName, -1, SQLITE_TRANSIENT);
155797
+ break;
155798
+ case 1: /* path */
155799
+ sqlite3_result_text(ctx, pCsr->zPath, -1, SQLITE_TRANSIENT);
155800
+ break;
155801
+ case 2: /* pageno */
155802
+ sqlite3_result_int64(ctx, pCsr->iPageno);
155803
+ break;
155804
+ case 3: /* pagetype */
155805
+ sqlite3_result_text(ctx, pCsr->zPagetype, -1, SQLITE_STATIC);
155806
+ break;
155807
+ case 4: /* ncell */
155808
+ sqlite3_result_int(ctx, pCsr->nCell);
155809
+ break;
155810
+ case 5: /* payload */
155811
+ sqlite3_result_int(ctx, pCsr->nPayload);
155812
+ break;
155813
+ case 6: /* unused */
155814
+ sqlite3_result_int(ctx, pCsr->nUnused);
155815
+ break;
155816
+ case 7: /* mx_payload */
155817
+ sqlite3_result_int(ctx, pCsr->nMxPayload);
155818
+ break;
155819
+ case 8: /* pgoffset */
155820
+ sqlite3_result_int64(ctx, pCsr->iOffset);
155821
+ break;
155822
+ default: /* pgsize */
155823
+ assert( i==9 );
155824
+ sqlite3_result_int(ctx, pCsr->szPage);
155825
+ break;
155826
+ }
155827
+ return SQLITE_OK;
155828
+}
155829
+
155830
+static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
155831
+ StatCursor *pCsr = (StatCursor *)pCursor;
155832
+ *pRowid = pCsr->iPageno;
155833
+ return SQLITE_OK;
155834
+}
155835
+
155836
+/*
155837
+** Invoke this routine to register the "dbstat" virtual table module
155838
+*/
155839
+SQLITE_API int SQLITE_STDCALL sqlite3_dbstat_register(sqlite3 *db){
155840
+ static sqlite3_module dbstat_module = {
155841
+ 0, /* iVersion */
155842
+ statConnect, /* xCreate */
155843
+ statConnect, /* xConnect */
155844
+ statBestIndex, /* xBestIndex */
155845
+ statDisconnect, /* xDisconnect */
155846
+ statDisconnect, /* xDestroy */
155847
+ statOpen, /* xOpen - open a cursor */
155848
+ statClose, /* xClose - close a cursor */
155849
+ statFilter, /* xFilter - configure scan constraints */
155850
+ statNext, /* xNext - advance a cursor */
155851
+ statEof, /* xEof - check for end of scan */
155852
+ statColumn, /* xColumn - read data */
155853
+ statRowid, /* xRowid - read data */
155854
+ 0, /* xUpdate */
155855
+ 0, /* xBegin */
155856
+ 0, /* xSync */
155857
+ 0, /* xCommit */
155858
+ 0, /* xRollback */
155859
+ 0, /* xFindMethod */
155860
+ 0, /* xRename */
155861
+ };
155862
+ return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
155863
+}
155864
+#endif /* SQLITE_ENABLE_DBSTAT_VTAB */
155865
+
155866
+/************** End of dbstat.c **********************************************/
154634155867
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.9. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -68,10 +68,11 @@
68 #if defined(_MSC_VER)
69 #pragma warning(disable : 4054)
70 #pragma warning(disable : 4055)
71 #pragma warning(disable : 4100)
72 #pragma warning(disable : 4127)
 
73 #pragma warning(disable : 4152)
74 #pragma warning(disable : 4189)
75 #pragma warning(disable : 4206)
76 #pragma warning(disable : 4210)
77 #pragma warning(disable : 4232)
@@ -315,13 +316,13 @@
315 **
316 ** See also: [sqlite3_libversion()],
317 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
318 ** [sqlite_version()] and [sqlite_source_id()].
319 */
320 #define SQLITE_VERSION "3.8.9"
321 #define SQLITE_VERSION_NUMBER 3008009
322 #define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09"
323
324 /*
325 ** CAPI3REF: Run-Time Library Version Numbers
326 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
327 **
@@ -474,10 +475,11 @@
474 # define double sqlite3_int64
475 #endif
476
477 /*
478 ** CAPI3REF: Closing A Database Connection
 
479 **
480 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
481 ** for the [sqlite3] object.
482 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
483 ** the [sqlite3] object is successfully destroyed and all associated
@@ -525,10 +527,11 @@
525 */
526 typedef int (*sqlite3_callback)(void*,int,char**, char**);
527
528 /*
529 ** CAPI3REF: One-Step Query Execution Interface
 
530 **
531 ** The sqlite3_exec() interface is a convenience wrapper around
532 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
533 ** that allows an application to run multiple statements of SQL
534 ** without having to use a lot of C code.
@@ -1582,10 +1585,11 @@
1582 */
1583 SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
1584
1585 /*
1586 ** CAPI3REF: Configure database connections
 
1587 **
1588 ** The sqlite3_db_config() interface is used to make configuration
1589 ** changes to a [database connection]. The interface is similar to
1590 ** [sqlite3_config()] except that the changes apply to a single
1591 ** [database connection] (specified in the first argument).
@@ -2079,19 +2083,21 @@
2079 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2080
2081
2082 /*
2083 ** CAPI3REF: Enable Or Disable Extended Result Codes
 
2084 **
2085 ** ^The sqlite3_extended_result_codes() routine enables or disables the
2086 ** [extended result codes] feature of SQLite. ^The extended result
2087 ** codes are disabled by default for historical compatibility.
2088 */
2089 SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
2090
2091 /*
2092 ** CAPI3REF: Last Insert Rowid
 
2093 **
2094 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
2095 ** has a unique 64-bit signed
2096 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
2097 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -2139,10 +2145,11 @@
2139 */
2140 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
2141
2142 /*
2143 ** CAPI3REF: Count The Number Of Rows Modified
 
2144 **
2145 ** ^This function returns the number of rows modified, inserted or
2146 ** deleted by the most recently completed INSERT, UPDATE or DELETE
2147 ** statement on the database connection specified by the only parameter.
2148 ** ^Executing any other type of SQL statement does not modify the value
@@ -2191,10 +2198,11 @@
2191 */
2192 SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
2193
2194 /*
2195 ** CAPI3REF: Total Number Of Rows Modified
 
2196 **
2197 ** ^This function returns the total number of rows inserted, modified or
2198 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2199 ** since the database connection was opened, including those executed as
2200 ** part of trigger programs. ^Executing any other type of SQL statement
@@ -2214,10 +2222,11 @@
2214 */
2215 SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
2216
2217 /*
2218 ** CAPI3REF: Interrupt A Long-Running Query
 
2219 **
2220 ** ^This function causes any pending database operation to abort and
2221 ** return at its earliest opportunity. This routine is typically
2222 ** called in response to a user action such as pressing "Cancel"
2223 ** or Ctrl-C where the user wants a long query operation to halt
@@ -2290,10 +2299,11 @@
2290 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
2291
2292 /*
2293 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2294 ** KEYWORDS: {busy-handler callback} {busy handler}
 
2295 **
2296 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2297 ** that might be invoked with argument P whenever
2298 ** an attempt is made to access a database table associated with
2299 ** [database connection] D when another thread
@@ -2349,10 +2359,11 @@
2349 */
2350 SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
2351
2352 /*
2353 ** CAPI3REF: Set A Busy Timeout
 
2354 **
2355 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2356 ** for a specified amount of time when a table is locked. ^The handler
2357 ** will sleep multiple times until at least "ms" milliseconds of sleeping
2358 ** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2371,10 +2382,11 @@
2371 */
2372 SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
2373
2374 /*
2375 ** CAPI3REF: Convenience Routines For Running Queries
 
2376 **
2377 ** This is a legacy interface that is preserved for backwards compatibility.
2378 ** Use of this interface is not recommended.
2379 **
2380 ** Definition: A <b>result table</b> is memory data structure created by the
@@ -2706,10 +2718,11 @@
2706 */
2707 SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
2708
2709 /*
2710 ** CAPI3REF: Compile-Time Authorization Callbacks
 
2711 **
2712 ** ^This routine registers an authorizer callback with a particular
2713 ** [database connection], supplied in the first argument.
2714 ** ^The authorizer callback is invoked as SQL statements are being compiled
2715 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2862,10 +2875,11 @@
2862 #define SQLITE_COPY 0 /* No longer used */
2863 #define SQLITE_RECURSIVE 33 /* NULL NULL */
2864
2865 /*
2866 ** CAPI3REF: Tracing And Profiling Functions
 
2867 **
2868 ** These routines register callback functions that can be used for
2869 ** tracing and profiling the execution of SQL statements.
2870 **
2871 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2894,10 +2908,11 @@
2894 SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
2895 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2896
2897 /*
2898 ** CAPI3REF: Query Progress Callbacks
 
2899 **
2900 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2901 ** function X to be invoked periodically during long running calls to
2902 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2903 ** database connection D. An example use for this
@@ -2927,10 +2942,11 @@
2927 */
2928 SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2929
2930 /*
2931 ** CAPI3REF: Opening A New Database Connection
 
2932 **
2933 ** ^These routines open an SQLite database file as specified by the
2934 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2935 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2936 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3212,10 +3228,11 @@
3212 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3213
3214
3215 /*
3216 ** CAPI3REF: Error Codes And Messages
 
3217 **
3218 ** ^If the most recent sqlite3_* API call associated with
3219 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3220 ** returns the numeric [result code] or [extended result code] for that
3221 ** API call.
@@ -3257,37 +3274,38 @@
3257 SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
3258 SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
3259 SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
3260
3261 /*
3262 ** CAPI3REF: SQL Statement Object
3263 ** KEYWORDS: {prepared statement} {prepared statements}
3264 **
3265 ** An instance of this object represents a single SQL statement.
3266 ** This object is variously known as a "prepared statement" or a
3267 ** "compiled SQL statement" or simply as a "statement".
3268 **
3269 ** The life of a statement object goes something like this:
 
 
 
 
 
3270 **
3271 ** <ol>
3272 ** <li> Create the object using [sqlite3_prepare_v2()] or a related
3273 ** function.
3274 ** <li> Bind values to [host parameters] using the sqlite3_bind_*()
3275 ** interfaces.
3276 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3277 ** <li> Reset the statement using [sqlite3_reset()] then go back
3278 ** to step 2. Do this zero or more times.
3279 ** <li> Destroy the object using [sqlite3_finalize()].
3280 ** </ol>
3281 **
3282 ** Refer to documentation on individual methods above for additional
3283 ** information.
3284 */
3285 typedef struct sqlite3_stmt sqlite3_stmt;
3286
3287 /*
3288 ** CAPI3REF: Run-time Limits
 
3289 **
3290 ** ^(This interface allows the size of various constructs to be limited
3291 ** on a connection by connection basis. The first parameter is the
3292 ** [database connection] whose limit is to be set or queried. The
3293 ** second parameter is one of the [limit categories] that define a
@@ -3395,10 +3413,12 @@
3395 #define SQLITE_LIMIT_WORKER_THREADS 11
3396
3397 /*
3398 ** CAPI3REF: Compiling An SQL Statement
3399 ** KEYWORDS: {SQL statement compiler}
 
 
3400 **
3401 ** To execute an SQL query, it must first be compiled into a byte-code
3402 ** program using one of these routines.
3403 **
3404 ** The first argument, "db", is a [database connection] obtained from a
@@ -3502,19 +3522,21 @@
3502 const void **pzTail /* OUT: Pointer to unused portion of zSql */
3503 );
3504
3505 /*
3506 ** CAPI3REF: Retrieving Statement SQL
 
3507 **
3508 ** ^This interface can be used to retrieve a saved copy of the original
3509 ** SQL text used to create a [prepared statement] if that statement was
3510 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
3511 */
3512 SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
3513
3514 /*
3515 ** CAPI3REF: Determine If An SQL Statement Writes The Database
 
3516 **
3517 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3518 ** and only if the [prepared statement] X makes no direct changes to
3519 ** the content of the database file.
3520 **
@@ -3542,10 +3564,11 @@
3542 */
3543 SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3544
3545 /*
3546 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
 
3547 **
3548 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3549 ** [prepared statement] S has been stepped at least once using
3550 ** [sqlite3_step(S)] but has not run to completion and/or has not
3551 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3616,10 +3639,11 @@
3616
3617 /*
3618 ** CAPI3REF: Binding Values To Prepared Statements
3619 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3620 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
 
3621 **
3622 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3623 ** literals may be replaced by a [parameter] that matches one of following
3624 ** templates:
3625 **
@@ -3734,10 +3758,11 @@
3734 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3735 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3736
3737 /*
3738 ** CAPI3REF: Number Of SQL Parameters
 
3739 **
3740 ** ^This routine can be used to find the number of [SQL parameters]
3741 ** in a [prepared statement]. SQL parameters are tokens of the
3742 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
3743 ** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3754,10 +3779,11 @@
3754 */
3755 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
3756
3757 /*
3758 ** CAPI3REF: Name Of A Host Parameter
 
3759 **
3760 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
3761 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
3762 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3763 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3781,10 +3807,11 @@
3781 */
3782 SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
3783
3784 /*
3785 ** CAPI3REF: Index Of A Parameter With A Given Name
 
3786 **
3787 ** ^Return the index of an SQL parameter given its name. ^The
3788 ** index value returned is suitable for use as the second
3789 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
3790 ** is returned if no matching parameter is found. ^The parameter
@@ -3797,19 +3824,21 @@
3797 */
3798 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
3799
3800 /*
3801 ** CAPI3REF: Reset All Bindings On A Prepared Statement
 
3802 **
3803 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
3804 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3805 ** ^Use this routine to reset all host parameters to NULL.
3806 */
3807 SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
3808
3809 /*
3810 ** CAPI3REF: Number Of Columns In A Result Set
 
3811 **
3812 ** ^Return the number of columns in the result set returned by the
3813 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3814 ** statement that does not return data (for example an [UPDATE]).
3815 **
@@ -3817,10 +3846,11 @@
3817 */
3818 SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
3819
3820 /*
3821 ** CAPI3REF: Column Names In A Result Set
 
3822 **
3823 ** ^These routines return the name assigned to a particular column
3824 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
3825 ** interface returns a pointer to a zero-terminated UTF-8 string
3826 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3846,10 +3876,11 @@
3846 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
3847 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
3848
3849 /*
3850 ** CAPI3REF: Source Of Data In A Query Result
 
3851 **
3852 ** ^These routines provide a means to determine the database, table, and
3853 ** table column that is the origin of a particular result column in
3854 ** [SELECT] statement.
3855 ** ^The name of the database or table or column can be returned as
@@ -3898,10 +3929,11 @@
3898 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
3899 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
3900
3901 /*
3902 ** CAPI3REF: Declared Datatype Of A Query Result
 
3903 **
3904 ** ^(The first parameter is a [prepared statement].
3905 ** If this statement is a [SELECT] statement and the Nth column of the
3906 ** returned result set of that [SELECT] is a table column (not an
3907 ** expression or subquery) then the declared type of the table
@@ -3930,10 +3962,11 @@
3930 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
3931 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
3932
3933 /*
3934 ** CAPI3REF: Evaluate An SQL Statement
 
3935 **
3936 ** After a [prepared statement] has been prepared using either
3937 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
3938 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
3939 ** must be called one or more times to evaluate the statement.
@@ -4009,10 +4042,11 @@
4009 */
4010 SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
4011
4012 /*
4013 ** CAPI3REF: Number of columns in a result set
 
4014 **
4015 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
4016 ** current row of the result set of [prepared statement] P.
4017 ** ^If prepared statement P does not have results ready to return
4018 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -4062,10 +4096,11 @@
4062 #define SQLITE3_TEXT 3
4063
4064 /*
4065 ** CAPI3REF: Result Values From A Query
4066 ** KEYWORDS: {column access functions}
 
4067 **
4068 ** These routines form the "result set" interface.
4069 **
4070 ** ^These routines return information about a single column of the current
4071 ** result row of a query. ^In every case the first argument is a pointer
@@ -4234,10 +4269,11 @@
4234 SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
4235 SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
4236
4237 /*
4238 ** CAPI3REF: Destroy A Prepared Statement Object
 
4239 **
4240 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
4241 ** ^If the most recent evaluation of the statement encountered no errors
4242 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
4243 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4261,10 +4297,11 @@
4261 */
4262 SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
4263
4264 /*
4265 ** CAPI3REF: Reset A Prepared Statement Object
 
4266 **
4267 ** The sqlite3_reset() function is called to reset a [prepared statement]
4268 ** object back to its initial state, ready to be re-executed.
4269 ** ^Any SQL statement variables that had values bound to them using
4270 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4290,10 +4327,11 @@
4290 /*
4291 ** CAPI3REF: Create Or Redefine SQL Functions
4292 ** KEYWORDS: {function creation routines}
4293 ** KEYWORDS: {application-defined SQL function}
4294 ** KEYWORDS: {application-defined SQL functions}
 
4295 **
4296 ** ^These functions (collectively known as "function creation routines")
4297 ** are used to add SQL functions or aggregates or to redefine the behavior
4298 ** of existing SQL functions or aggregates. The only differences between
4299 ** these routines are the text encoding expected for
@@ -4459,10 +4497,11 @@
4459 void*,sqlite3_int64);
4460 #endif
4461
4462 /*
4463 ** CAPI3REF: Obtaining SQL Function Parameter Values
 
4464 **
4465 ** The C-language implementation of SQL functions and aggregates uses
4466 ** this set of interface routines to access the parameter values on
4467 ** the function or aggregate.
4468 **
@@ -4517,10 +4556,11 @@
4517 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4518 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4519
4520 /*
4521 ** CAPI3REF: Obtain Aggregate Function Context
 
4522 **
4523 ** Implementations of aggregate SQL functions use this
4524 ** routine to allocate memory for storing their state.
4525 **
4526 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4561,10 +4601,11 @@
4561 */
4562 SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
4563
4564 /*
4565 ** CAPI3REF: User Data For Functions
 
4566 **
4567 ** ^The sqlite3_user_data() interface returns a copy of
4568 ** the pointer that was the pUserData parameter (the 5th parameter)
4569 ** of the [sqlite3_create_function()]
4570 ** and [sqlite3_create_function16()] routines that originally
@@ -4575,10 +4616,11 @@
4575 */
4576 SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
4577
4578 /*
4579 ** CAPI3REF: Database Connection For Functions
 
4580 **
4581 ** ^The sqlite3_context_db_handle() interface returns a copy of
4582 ** the pointer to the [database connection] (the 1st parameter)
4583 ** of the [sqlite3_create_function()]
4584 ** and [sqlite3_create_function16()] routines that originally
@@ -4586,10 +4628,11 @@
4586 */
4587 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
4588
4589 /*
4590 ** CAPI3REF: Function Auxiliary Data
 
4591 **
4592 ** These functions may be used by (non-aggregate) SQL functions to
4593 ** associate metadata with argument values. If the same value is passed to
4594 ** multiple invocations of the same SQL function during query execution, under
4595 ** some circumstances the associated metadata may be preserved. An example
@@ -4658,10 +4701,11 @@
4658 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
4659 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
4660
4661 /*
4662 ** CAPI3REF: Setting The Result Of An SQL Function
 
4663 **
4664 ** These routines are used by the xFunc or xFinal callbacks that
4665 ** implement SQL functions and aggregates. See
4666 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
4667 ** for additional information.
@@ -4793,10 +4837,11 @@
4793 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4794 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4795
4796 /*
4797 ** CAPI3REF: Define New Collating Sequences
 
4798 **
4799 ** ^These functions add, remove, or modify a [collation] associated
4800 ** with the [database connection] specified as the first argument.
4801 **
4802 ** ^The name of the collation is a UTF-8 string
@@ -4895,10 +4940,11 @@
4895 int(*xCompare)(void*,int,const void*,int,const void*)
4896 );
4897
4898 /*
4899 ** CAPI3REF: Collation Needed Callbacks
 
4900 **
4901 ** ^To avoid having to register all collation sequences before a database
4902 ** can be used, a single callback function may be registered with the
4903 ** [database connection] to be invoked whenever an undefined collation
4904 ** sequence is required.
@@ -5102,10 +5148,11 @@
5102 SQLITE_API char *sqlite3_data_directory;
5103
5104 /*
5105 ** CAPI3REF: Test For Auto-Commit Mode
5106 ** KEYWORDS: {autocommit mode}
 
5107 **
5108 ** ^The sqlite3_get_autocommit() interface returns non-zero or
5109 ** zero if the given database connection is or is not in autocommit mode,
5110 ** respectively. ^Autocommit mode is on by default.
5111 ** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -5124,10 +5171,11 @@
5124 */
5125 SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
5126
5127 /*
5128 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
 
5129 **
5130 ** ^The sqlite3_db_handle interface returns the [database connection] handle
5131 ** to which a [prepared statement] belongs. ^The [database connection]
5132 ** returned by sqlite3_db_handle is the same [database connection]
5133 ** that was the first argument
@@ -5136,10 +5184,11 @@
5136 */
5137 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
5138
5139 /*
5140 ** CAPI3REF: Return The Filename For A Database Connection
 
5141 **
5142 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
5143 ** associated with database N of connection D. ^The main database file
5144 ** has the name "main". If there is no attached database N on the database
5145 ** connection D, or if database N is a temporary or in-memory database, then
@@ -5152,19 +5201,21 @@
5152 */
5153 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
5154
5155 /*
5156 ** CAPI3REF: Determine if a database is read-only
 
5157 **
5158 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
5159 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
5160 ** the name of a database on connection D.
5161 */
5162 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5163
5164 /*
5165 ** CAPI3REF: Find the next prepared statement
 
5166 **
5167 ** ^This interface returns a pointer to the next [prepared statement] after
5168 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
5169 ** then this interface returns a pointer to the first prepared statement
5170 ** associated with the database connection pDb. ^If no prepared statement
@@ -5176,10 +5227,11 @@
5176 */
5177 SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
5178
5179 /*
5180 ** CAPI3REF: Commit And Rollback Notification Callbacks
 
5181 **
5182 ** ^The sqlite3_commit_hook() interface registers a callback
5183 ** function to be invoked whenever a transaction is [COMMIT | committed].
5184 ** ^Any callback set by a previous call to sqlite3_commit_hook()
5185 ** for the same database connection is overridden.
@@ -5225,10 +5277,11 @@
5225 SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
5226 SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5227
5228 /*
5229 ** CAPI3REF: Data Change Notification Callbacks
 
5230 **
5231 ** ^The sqlite3_update_hook() interface registers a callback function
5232 ** with the [database connection] identified by the first argument
5233 ** to be invoked whenever a row is updated, inserted or deleted in
5234 ** a rowid table.
@@ -5331,10 +5384,11 @@
5331 */
5332 SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
5333
5334 /*
5335 ** CAPI3REF: Free Memory Used By A Database Connection
 
5336 **
5337 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5338 ** memory as possible from database connection D. Unlike the
5339 ** [sqlite3_release_memory()] interface, this interface is in effect even
5340 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5408,10 +5462,11 @@
5408 SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
5409
5410
5411 /*
5412 ** CAPI3REF: Extract Metadata About A Column Of A Table
 
5413 **
5414 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5415 ** information about column C of table T in database D
5416 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5417 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5486,10 +5541,11 @@
5486 int *pAutoinc /* OUTPUT: True if column is auto-increment */
5487 );
5488
5489 /*
5490 ** CAPI3REF: Load An Extension
 
5491 **
5492 ** ^This interface loads an SQLite extension library from the named file.
5493 **
5494 ** ^The sqlite3_load_extension() interface attempts to load an
5495 ** [SQLite extension] library contained in the file zFile. If
@@ -5527,10 +5583,11 @@
5527 char **pzErrMsg /* Put error message here if not 0 */
5528 );
5529
5530 /*
5531 ** CAPI3REF: Enable Or Disable Extension Loading
 
5532 **
5533 ** ^So as not to open security holes in older applications that are
5534 ** unprepared to deal with [extension loading], and as a means of disabling
5535 ** [extension loading] while evaluating user-entered SQL, the following API
5536 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5776,10 +5833,11 @@
5776 #define SQLITE_INDEX_CONSTRAINT_GE 32
5777 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
5778
5779 /*
5780 ** CAPI3REF: Register A Virtual Table Implementation
 
5781 **
5782 ** ^These routines are used to register a new [virtual table module] name.
5783 ** ^Module names must be registered before
5784 ** creating a new [virtual table] using the module and before using a
5785 ** preexisting [virtual table] for the module.
@@ -5872,10 +5930,11 @@
5872 */
5873 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
5874
5875 /*
5876 ** CAPI3REF: Overload A Function For A Virtual Table
 
5877 **
5878 ** ^(Virtual tables can provide alternative implementations of functions
5879 ** using the [xFindFunction] method of the [virtual table module].
5880 ** But global versions of those functions
5881 ** must exist in order to be overloaded.)^
@@ -5914,10 +5973,12 @@
5914 */
5915 typedef struct sqlite3_blob sqlite3_blob;
5916
5917 /*
5918 ** CAPI3REF: Open A BLOB For Incremental I/O
 
 
5919 **
5920 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
5921 ** in row iRow, column zColumn, table zTable in database zDb;
5922 ** in other words, the same BLOB that would be selected by:
5923 **
@@ -5995,10 +6056,11 @@
5995 sqlite3_blob **ppBlob
5996 );
5997
5998 /*
5999 ** CAPI3REF: Move a BLOB Handle to a New Row
 
6000 **
6001 ** ^This function is used to move an existing blob handle so that it points
6002 ** to a different row of the same database table. ^The new row is identified
6003 ** by the rowid value passed as the second argument. Only the row can be
6004 ** changed. ^The database, table and column on which the blob handle is open
@@ -6019,10 +6081,11 @@
6019 */
6020 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
6021
6022 /*
6023 ** CAPI3REF: Close A BLOB Handle
 
6024 **
6025 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
6026 ** unconditionally. Even if this routine returns an error code, the
6027 ** handle is still closed.)^
6028 **
@@ -6041,10 +6104,11 @@
6041 */
6042 SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
6043
6044 /*
6045 ** CAPI3REF: Return The Size Of An Open BLOB
 
6046 **
6047 ** ^Returns the size in bytes of the BLOB accessible via the
6048 ** successfully opened [BLOB handle] in its only argument. ^The
6049 ** incremental blob I/O routines can only read or overwriting existing
6050 ** blob content; they cannot change the size of a blob.
@@ -6056,10 +6120,11 @@
6056 */
6057 SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
6058
6059 /*
6060 ** CAPI3REF: Read Data From A BLOB Incrementally
 
6061 **
6062 ** ^(This function is used to read data from an open [BLOB handle] into a
6063 ** caller-supplied buffer. N bytes of data are copied into buffer Z
6064 ** from the open BLOB, starting at offset iOffset.)^
6065 **
@@ -6084,10 +6149,11 @@
6084 */
6085 SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
6086
6087 /*
6088 ** CAPI3REF: Write Data Into A BLOB Incrementally
 
6089 **
6090 ** ^(This function is used to write data into an open [BLOB handle] from a
6091 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
6092 ** into the open BLOB, starting at offset iOffset.)^
6093 **
@@ -6411,10 +6477,11 @@
6411 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6412 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6413
6414 /*
6415 ** CAPI3REF: Retrieve the mutex for a database connection
 
6416 **
6417 ** ^This interface returns a pointer the [sqlite3_mutex] object that
6418 ** serializes access to the [database connection] given in the argument
6419 ** when the [threading mode] is Serialized.
6420 ** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6422,10 +6489,11 @@
6422 */
6423 SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
6424
6425 /*
6426 ** CAPI3REF: Low-Level Control Of Database Files
 
6427 **
6428 ** ^The [sqlite3_file_control()] interface makes a direct call to the
6429 ** xFileControl method for the [sqlite3_io_methods] object associated
6430 ** with a particular database identified by the second argument. ^The
6431 ** name of the database is "main" for the main database or "temp" for the
@@ -6638,10 +6706,11 @@
6638 #define SQLITE_STATUS_SCRATCH_SIZE 8
6639 #define SQLITE_STATUS_MALLOC_COUNT 9
6640
6641 /*
6642 ** CAPI3REF: Database Connection Status
 
6643 **
6644 ** ^This interface is used to retrieve runtime status information
6645 ** about a single [database connection]. ^The first argument is the
6646 ** database connection object to be interrogated. ^The second argument
6647 ** is an integer constant, taken from the set of
@@ -6766,10 +6835,11 @@
6766 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
6767
6768
6769 /*
6770 ** CAPI3REF: Prepared Statement Status
 
6771 **
6772 ** ^(Each prepared statement maintains various
6773 ** [SQLITE_STMTSTATUS counters] that measure the number
6774 ** of times it has performed specific operations.)^ These counters can
6775 ** be used to monitor the performance characteristics of the prepared
@@ -7269,10 +7339,11 @@
7269 SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
7270 SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
7271
7272 /*
7273 ** CAPI3REF: Unlock Notification
 
7274 **
7275 ** ^When running in shared-cache mode, a database operation may fail with
7276 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
7277 ** individual tables within the shared-cache cannot be obtained. See
7278 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7439,10 +7510,11 @@
7439 */
7440 SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
7441
7442 /*
7443 ** CAPI3REF: Write-Ahead Log Commit Hook
 
7444 **
7445 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7446 ** is invoked each time data is committed to a database in wal mode.
7447 **
7448 ** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7478,10 +7550,11 @@
7478 void*
7479 );
7480
7481 /*
7482 ** CAPI3REF: Configure an auto-checkpoint
 
7483 **
7484 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
7485 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
7486 ** to automatically [checkpoint]
7487 ** after committing a transaction if there are N or
@@ -7508,10 +7581,11 @@
7508 */
7509 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7510
7511 /*
7512 ** CAPI3REF: Checkpoint a database
 
7513 **
7514 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7515 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7516 **
7517 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7529,10 +7603,11 @@
7529 */
7530 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7531
7532 /*
7533 ** CAPI3REF: Checkpoint a database
 
7534 **
7535 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7536 ** operation on database X of [database connection] D in mode M. Status
7537 ** information is written back into integers pointed to by L and C.)^
7538 ** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7783,10 +7858,11 @@
7783 #define SQLITE_SCANSTAT_EXPLAIN 4
7784 #define SQLITE_SCANSTAT_SELECTID 5
7785
7786 /*
7787 ** CAPI3REF: Prepared Statement Scan Status
 
7788 **
7789 ** This interface returns information about the predicted and measured
7790 ** performance for pStmt. Advanced applications can use this
7791 ** interface to compare the predicted and the measured performance and
7792 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7820,10 +7896,11 @@
7820 void *pOut /* Result written here */
7821 );
7822
7823 /*
7824 ** CAPI3REF: Zero Scan-Status Counters
 
7825 **
7826 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7827 **
7828 ** This API is only available if the library is built with pre-processor
7829 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
@@ -8430,10 +8507,36 @@
8430 #else
8431 # define ALWAYS(X) (X)
8432 # define NEVER(X) (X)
8433 #endif
8434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8435 /*
8436 ** Return true (non-zero) if the input is an integer that is too large
8437 ** to fit in 32-bits. This macro is used inside of various testcase()
8438 ** macros to verify that we have tested SQLite for large-file support.
8439 */
@@ -9841,37 +9944,36 @@
9841 /* Properties such as "out2" or "jump" that are specified in
9842 ** comments following the "case" for each opcode in the vdbe.c
9843 ** are encoded into bitvectors as follows:
9844 */
9845 #define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */
9846 #define OPFLG_OUT2_PRERELEASE 0x0002 /* out2-prerelease: */
9847 #define OPFLG_IN1 0x0004 /* in1: P1 is an input */
9848 #define OPFLG_IN2 0x0008 /* in2: P2 is an input */
9849 #define OPFLG_IN3 0x0010 /* in3: P3 is an input */
9850 #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
9851 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9852 #define OPFLG_INITIALIZER {\
9853 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9854 /* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
9855 /* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\
9856 /* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\
9857 /* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\
9858 /* 40 */ 0x04, 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00,\
9859 /* 48 */ 0x00, 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00,\
9860 /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,\
9861 /* 64 */ 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11, 0x4c,\
9862 /* 72 */ 0x4c, 0x02, 0x02, 0x00, 0x05, 0x05, 0x15, 0x15,\
9863 /* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
9864 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9865 /* 96 */ 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,\
9866 /* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08, 0x00,\
9867 /* 112 */ 0x02, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00,\
9868 /* 120 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9869 /* 128 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x02, 0x00, 0x01,\
9870 /* 136 */ 0x08, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x01,\
9871 /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\
9872 /* 152 */ 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,}
9873
9874 /************** End of opcodes.h *********************************************/
9875 /************** Continuing where we left off in vdbe.h ***********************/
9876
9877 /*
@@ -9926,10 +10028,11 @@
9926 #endif
9927 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
9928
9929 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
9930 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
 
9931 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
9932
9933 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
9934 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
9935
@@ -11063,10 +11166,11 @@
11063 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
11064 #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
11065 #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
11066 #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
11067 #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
 
11068
11069
11070 /*
11071 ** Bits of the sqlite3.dbOptFlags field that are used by the
11072 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -11393,38 +11497,12 @@
11393 int iSavepoint; /* Depth of the SAVEPOINT stack */
11394 VTable *pNext; /* Next in linked list (see above) */
11395 };
11396
11397 /*
11398 ** Each SQL table is represented in memory by an instance of the
11399 ** following structure.
11400 **
11401 ** Table.zName is the name of the table. The case of the original
11402 ** CREATE TABLE statement is stored, but case is not significant for
11403 ** comparisons.
11404 **
11405 ** Table.nCol is the number of columns in this table. Table.aCol is a
11406 ** pointer to an array of Column structures, one for each column.
11407 **
11408 ** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
11409 ** the column that is that key. Otherwise Table.iPKey is negative. Note
11410 ** that the datatype of the PRIMARY KEY must be INTEGER for this field to
11411 ** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of
11412 ** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid
11413 ** is generated for each row of the table. TF_HasPrimaryKey is set if
11414 ** the table has any PRIMARY KEY, INTEGER or otherwise.
11415 **
11416 ** Table.tnum is the page number for the root BTree page of the table in the
11417 ** database file. If Table.iDb is the index of the database table backend
11418 ** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
11419 ** holds temporary tables and indices. If TF_Ephemeral is set
11420 ** then the table is stored in a file that is automatically deleted
11421 ** when the VDBE cursor to the table is closed. In this case Table.tnum
11422 ** refers VDBE cursor number that holds the table open, not to the root
11423 ** page number. Transient tables are used to hold the results of a
11424 ** sub-query that appears instead of a real table name in the FROM clause
11425 ** of a SELECT statement.
11426 */
11427 struct Table {
11428 char *zName; /* Name of the table or view */
11429 Column *aCol; /* Information about each column */
11430 Index *pIndex; /* List of SQL indexes on this table. */
@@ -11432,15 +11510,15 @@
11432 FKey *pFKey; /* Linked list of all foreign keys in this table */
11433 char *zColAff; /* String defining the affinity of each column */
11434 #ifndef SQLITE_OMIT_CHECK
11435 ExprList *pCheck; /* All CHECK constraints */
11436 #endif
11437 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
11438 int tnum; /* Root BTree node for this table (see note above) */
11439 i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */
11440 i16 nCol; /* Number of columns in this table */
11441 u16 nRef; /* Number of pointers to this Table */
 
11442 LogEst szTabRow; /* Estimated size of each table row in bytes */
11443 #ifdef SQLITE_ENABLE_COSTMULT
11444 LogEst costMult; /* Cost multiplier for using this table */
11445 #endif
11446 u8 tabFlags; /* Mask of TF_* values */
@@ -11458,17 +11536,24 @@
11458 Table *pNextZombie; /* Next on the Parse.pZombieTab list */
11459 };
11460
11461 /*
11462 ** Allowed values for Table.tabFlags.
 
 
 
 
 
 
11463 */
11464 #define TF_Readonly 0x01 /* Read-only system table */
11465 #define TF_Ephemeral 0x02 /* An ephemeral table */
11466 #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
11467 #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
11468 #define TF_Virtual 0x10 /* Is a virtual table */
11469 #define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */
 
11470
11471
11472 /*
11473 ** Test to see whether or not a table is a virtual table. This is
11474 ** done as a macro so that it will be optimized out when virtual
@@ -12221,11 +12306,11 @@
12221 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
12222 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
12223 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
12224 #define SF_Compound 0x0040 /* Part of a compound query */
12225 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
12226 #define SF_AllValues 0x0100 /* All terms of compound are VALUES */
12227 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
12228 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
12229 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
12230 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
12231 #define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */
@@ -12605,24 +12690,24 @@
12605 *
12606 * (op == TK_INSERT)
12607 * orconf -> stores the ON CONFLICT algorithm
12608 * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
12609 * this stores a pointer to the SELECT statement. Otherwise NULL.
12610 * target -> A token holding the quoted name of the table to insert into.
12611 * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
12612 * this stores values to be inserted. Otherwise NULL.
12613 * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
12614 * statement, then this stores the column-names to be
12615 * inserted into.
12616 *
12617 * (op == TK_DELETE)
12618 * target -> A token holding the quoted name of the table to delete from.
12619 * pWhere -> The WHERE clause of the DELETE statement if one is specified.
12620 * Otherwise NULL.
12621 *
12622 * (op == TK_UPDATE)
12623 * target -> A token holding the quoted name of the table to update rows of.
12624 * pWhere -> The WHERE clause of the UPDATE statement if one is specified.
12625 * Otherwise NULL.
12626 * pExprList -> A list of the columns to update and the expressions to update
12627 * them to. See sqlite3Update() documentation of "pChanges"
12628 * argument.
@@ -12630,12 +12715,12 @@
12630 */
12631 struct TriggerStep {
12632 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
12633 u8 orconf; /* OE_Rollback etc. */
12634 Trigger *pTrig; /* The trigger that this step is a part of */
12635 Select *pSelect; /* SELECT statment or RHS of INSERT INTO .. SELECT ... */
12636 Token target; /* Target table for DELETE, UPDATE, INSERT */
12637 Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
12638 ExprList *pExprList; /* SET clause for UPDATE. */
12639 IdList *pIdList; /* Column names for INSERT */
12640 TriggerStep *pNext; /* Next in the link-list */
12641 TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
@@ -12664,12 +12749,11 @@
12664 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
12665 char *zBase; /* A base allocation. Not from malloc. */
12666 char *zText; /* The string collected so far */
12667 int nChar; /* Length of the string so far */
12668 int nAlloc; /* Amount of space allocated in zText */
12669 int mxAlloc; /* Maximum allowed string length */
12670 u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */
12671 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
12672 };
12673 #define STRACCUM_NOMEM 1
12674 #define STRACCUM_TOOBIG 2
12675
@@ -12982,11 +13066,11 @@
12982 SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
12983 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
12984 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
12985 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
12986 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
12987 #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
12988 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
12989 #endif
12990 #if defined(SQLITE_TEST)
12991 SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
12992 #endif
@@ -13329,11 +13413,11 @@
13329 SQLITE_PRIVATE void sqlite3Error(sqlite3*,int);
13330 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
13331 SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
13332 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
13333
13334 #if defined(SQLITE_TEST)
13335 SQLITE_PRIVATE const char *sqlite3ErrName(int);
13336 #endif
13337
13338 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
13339 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -13423,11 +13507,11 @@
13423 FuncDestructor *pDestructor
13424 );
13425 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
13426 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
13427
13428 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
13429 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
13430 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
13431 SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char);
13432 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
13433 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
@@ -14039,10 +14123,13 @@
14039 #if SQLITE_ENABLE_CEROD
14040 "ENABLE_CEROD",
14041 #endif
14042 #if SQLITE_ENABLE_COLUMN_METADATA
14043 "ENABLE_COLUMN_METADATA",
 
 
 
14044 #endif
14045 #if SQLITE_ENABLE_EXPENSIVE_ASSERT
14046 "ENABLE_EXPENSIVE_ASSERT",
14047 #endif
14048 #if SQLITE_ENABLE_FTS1
@@ -19807,20 +19894,10 @@
19807 */
19808 #ifdef MEMORY_DEBUG
19809 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
19810 #endif
19811
19812 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
19813 # ifndef SQLITE_DEBUG_OS_TRACE
19814 # define SQLITE_DEBUG_OS_TRACE 0
19815 # endif
19816 int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
19817 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
19818 #else
19819 # define OSTRACE(X)
19820 #endif
19821
19822 /*
19823 ** Macros for performance tracing. Normally turned off. Only works
19824 ** on i486 hardware.
19825 */
19826 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -21401,10 +21478,11 @@
21401
21402 /*
21403 ** Set the StrAccum object to an error mode.
21404 */
21405 static void setStrAccumError(StrAccum *p, u8 eError){
 
21406 p->accError = eError;
21407 p->nAlloc = 0;
21408 }
21409
21410 /*
@@ -21515,11 +21593,10 @@
21515 case '0': flag_zeropad = 1; break;
21516 default: done = 1; break;
21517 }
21518 }while( !done && (c=(*++fmt))!=0 );
21519 /* Get the field width */
21520 width = 0;
21521 if( c=='*' ){
21522 if( bArgList ){
21523 width = (int)getIntArg(pArgList);
21524 }else{
21525 width = va_arg(ap,int);
@@ -21539,11 +21616,10 @@
21539 width = wx & 0x7fffffff;
21540 }
21541
21542 /* Get the precision */
21543 if( c=='.' ){
21544 precision = 0;
21545 c = *++fmt;
21546 if( c=='*' ){
21547 if( bArgList ){
21548 precision = (int)getIntArg(pArgList);
21549 }else{
@@ -22018,11 +22094,11 @@
22018 if( p->accError ){
22019 testcase(p->accError==STRACCUM_TOOBIG);
22020 testcase(p->accError==STRACCUM_NOMEM);
22021 return 0;
22022 }
22023 if( !p->useMalloc ){
22024 N = p->nAlloc - p->nChar - 1;
22025 setStrAccumError(p, STRACCUM_TOOBIG);
22026 return N;
22027 }else{
22028 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
@@ -22038,14 +22114,14 @@
22038 setStrAccumError(p, STRACCUM_TOOBIG);
22039 return 0;
22040 }else{
22041 p->nAlloc = (int)szNew;
22042 }
22043 if( p->useMalloc==1 ){
22044 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
22045 }else{
22046 zNew = sqlite3_realloc(zOld, p->nAlloc);
22047 }
22048 if( zNew ){
22049 assert( p->zText!=0 || p->nChar==0 );
22050 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
22051 p->zText = zNew;
@@ -22089,11 +22165,11 @@
22089 /*
22090 ** Append N bytes of text from z to the StrAccum object. Increase the
22091 ** size of the memory allocation for StrAccum if necessary.
22092 */
22093 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
22094 assert( z!=0 );
22095 assert( p->zText!=0 || p->nChar==0 || p->accError );
22096 assert( N>=0 );
22097 assert( p->accError==0 || p->nAlloc==0 );
22098 if( p->nChar+N >= p->nAlloc ){
22099 enlargeAndAppend(p,z,N);
@@ -22118,16 +22194,12 @@
22118 ** pointer if any kind of error was encountered.
22119 */
22120 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
22121 if( p->zText ){
22122 p->zText[p->nChar] = 0;
22123 if( p->useMalloc && p->zText==p->zBase ){
22124 if( p->useMalloc==1 ){
22125 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
22126 }else{
22127 p->zText = sqlite3_malloc(p->nChar+1);
22128 }
22129 if( p->zText ){
22130 memcpy(p->zText, p->zBase, p->nChar+1);
22131 }else{
22132 setStrAccumError(p, STRACCUM_NOMEM);
22133 }
@@ -22139,29 +22211,35 @@
22139 /*
22140 ** Reset an StrAccum string. Reclaim all malloced memory.
22141 */
22142 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
22143 if( p->zText!=p->zBase ){
22144 if( p->useMalloc==1 ){
22145 sqlite3DbFree(p->db, p->zText);
22146 }else{
22147 sqlite3_free(p->zText);
22148 }
22149 }
22150 p->zText = 0;
22151 }
22152
22153 /*
22154 ** Initialize a string accumulator
 
 
 
 
 
 
 
 
 
 
 
22155 */
22156 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){
22157 p->zText = p->zBase = zBase;
22158 p->db = 0;
22159 p->nChar = 0;
22160 p->nAlloc = n;
22161 p->mxAlloc = mx;
22162 p->useMalloc = 1;
22163 p->accError = 0;
22164 }
22165
22166 /*
22167 ** Print into memory obtained from sqliteMalloc(). Use the internal
@@ -22170,13 +22248,12 @@
22170 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
22171 char *z;
22172 char zBase[SQLITE_PRINT_BUF_SIZE];
22173 StrAccum acc;
22174 assert( db!=0 );
22175 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
22176 db->aLimit[SQLITE_LIMIT_LENGTH]);
22177 acc.db = db;
22178 sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap);
22179 z = sqlite3StrAccumFinish(&acc);
22180 if( acc.accError==STRACCUM_NOMEM ){
22181 db->mallocFailed = 1;
22182 }
@@ -22230,12 +22307,11 @@
22230 }
22231 #endif
22232 #ifndef SQLITE_OMIT_AUTOINIT
22233 if( sqlite3_initialize() ) return 0;
22234 #endif
22235 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
22236 acc.useMalloc = 2;
22237 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22238 z = sqlite3StrAccumFinish(&acc);
22239 return z;
22240 }
22241
@@ -22276,12 +22352,11 @@
22276 (void)SQLITE_MISUSE_BKPT;
22277 if( zBuf ) zBuf[0] = 0;
22278 return zBuf;
22279 }
22280 #endif
22281 sqlite3StrAccumInit(&acc, zBuf, n, 0);
22282 acc.useMalloc = 0;
22283 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22284 return sqlite3StrAccumFinish(&acc);
22285 }
22286 SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
22287 char *z;
@@ -22303,12 +22378,11 @@
22303 */
22304 static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
22305 StrAccum acc; /* String accumulator */
22306 char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
22307
22308 sqlite3StrAccumInit(&acc, zMsg, sizeof(zMsg), 0);
22309 acc.useMalloc = 0;
22310 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22311 sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
22312 sqlite3StrAccumFinish(&acc));
22313 }
22314
@@ -22322,22 +22396,21 @@
22322 renderLogMsg(iErrCode, zFormat, ap);
22323 va_end(ap);
22324 }
22325 }
22326
22327 #if defined(SQLITE_DEBUG)
22328 /*
22329 ** A version of printf() that understands %lld. Used for debugging.
22330 ** The printf() built into some versions of windows does not understand %lld
22331 ** and segfaults if you give it a long long int.
22332 */
22333 SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){
22334 va_list ap;
22335 StrAccum acc;
22336 char zBuf[500];
22337 sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
22338 acc.useMalloc = 0;
22339 va_start(ap,zFormat);
22340 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22341 va_end(ap);
22342 sqlite3StrAccumFinish(&acc);
22343 fprintf(stdout,"%s", zBuf);
@@ -22360,11 +22433,11 @@
22360 */
22361 /* Add a new subitem to the tree. The moreToFollow flag indicates that this
22362 ** is not the last item in the tree. */
22363 SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){
22364 if( p==0 ){
22365 p = sqlite3_malloc( sizeof(*p) );
22366 if( p==0 ) return 0;
22367 memset(p, 0, sizeof(*p));
22368 }else{
22369 p->iLevel++;
22370 }
@@ -22383,12 +22456,11 @@
22383 SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
22384 va_list ap;
22385 int i;
22386 StrAccum acc;
22387 char zBuf[500];
22388 sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
22389 acc.useMalloc = 0;
22390 if( p ){
22391 for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
22392 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
22393 }
22394 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
@@ -24007,10 +24079,11 @@
24007 }else{
24008 return 0;
24009 }
24010 }
24011 #endif
 
24012 for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
24013 v = v*10 + c;
24014 }
24015
24016 /* The longest decimal representation of a 32 bit integer is 10 digits:
@@ -25261,10 +25334,21 @@
25261 #if SQLITE_ENABLE_LOCKING_STYLE
25262 # include <sys/ioctl.h>
25263 # include <sys/file.h>
25264 # include <sys/param.h>
25265 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
 
 
 
 
 
 
 
 
 
 
 
25266
25267 #if OS_VXWORKS
25268 /* # include <sys/ioctl.h> */
25269 # include <semaphore.h>
25270 # include <limits.h>
@@ -25457,20 +25541,10 @@
25457 */
25458 #ifdef MEMORY_DEBUG
25459 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
25460 #endif
25461
25462 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
25463 # ifndef SQLITE_DEBUG_OS_TRACE
25464 # define SQLITE_DEBUG_OS_TRACE 0
25465 # endif
25466 int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
25467 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
25468 #else
25469 # define OSTRACE(X)
25470 #endif
25471
25472 /*
25473 ** Macros for performance tracing. Normally turned off. Only works
25474 ** on i486 hardware.
25475 */
25476 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -26009,11 +26083,11 @@
26009 return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
26010 }
26011 #endif
26012
26013
26014 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
26015 /*
26016 ** Helper function for printing out trace information from debugging
26017 ** binaries. This returns the string representation of the supplied
26018 ** integer lock-type.
26019 */
@@ -26272,11 +26346,11 @@
26272 struct vxworksFileId *pCandidate; /* For looping over existing file IDs */
26273 int n; /* Length of zAbsoluteName string */
26274
26275 assert( zAbsoluteName[0]=='/' );
26276 n = (int)strlen(zAbsoluteName);
26277 pNew = sqlite3_malloc( sizeof(*pNew) + (n+1) );
26278 if( pNew==0 ) return 0;
26279 pNew->zCanonicalName = (char*)&pNew[1];
26280 memcpy(pNew->zCanonicalName, zAbsoluteName, n+1);
26281 n = vxworksSimplifyName(pNew->zCanonicalName, n);
26282
@@ -26676,11 +26750,11 @@
26676 pInode = inodeList;
26677 while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
26678 pInode = pInode->pNext;
26679 }
26680 if( pInode==0 ){
26681 pInode = sqlite3_malloc( sizeof(*pInode) );
26682 if( pInode==0 ){
26683 return SQLITE_NOMEM;
26684 }
26685 memset(pInode, 0, sizeof(*pInode));
26686 memcpy(&pInode->fileId, &fileId, sizeof(fileId));
@@ -29197,11 +29271,11 @@
29197 case SQLITE_FCNTL_VFSNAME: {
29198 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
29199 return SQLITE_OK;
29200 }
29201 case SQLITE_FCNTL_TEMPFILENAME: {
29202 char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname );
29203 if( zTFile ){
29204 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
29205 *(char**)pArg = zTFile;
29206 }
29207 return SQLITE_OK;
@@ -29638,11 +29712,11 @@
29638 unixInodeInfo *pInode; /* The inode of fd */
29639 char *zShmFilename; /* Name of the file used for SHM */
29640 int nShmFilename; /* Size of the SHM filename in bytes */
29641
29642 /* Allocate space for the new unixShm object. */
29643 p = sqlite3_malloc( sizeof(*p) );
29644 if( p==0 ) return SQLITE_NOMEM;
29645 memset(p, 0, sizeof(*p));
29646 assert( pDbFd->pShm==0 );
29647
29648 /* Check to see if a unixShmNode object already exists. Reuse an existing
@@ -29669,11 +29743,11 @@
29669 #ifdef SQLITE_SHM_DIRECTORY
29670 nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
29671 #else
29672 nShmFilename = 6 + (int)strlen(zBasePath);
29673 #endif
29674 pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
29675 if( pShmNode==0 ){
29676 rc = SQLITE_NOMEM;
29677 goto shm_open_err;
29678 }
29679 memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
@@ -29879,11 +29953,11 @@
29879 if( pMem==MAP_FAILED ){
29880 rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
29881 goto shmpage_out;
29882 }
29883 }else{
29884 pMem = sqlite3_malloc(szRegion);
29885 if( pMem==0 ){
29886 rc = SQLITE_NOMEM;
29887 goto shmpage_out;
29888 }
29889 memset(pMem, 0, szRegion);
@@ -30716,11 +30790,11 @@
30716 else if( pLockingStyle == &afpIoMethods ){
30717 /* AFP locking uses the file path so it needs to be included in
30718 ** the afpLockingContext.
30719 */
30720 afpLockingContext *pCtx;
30721 pNew->lockingContext = pCtx = sqlite3_malloc( sizeof(*pCtx) );
30722 if( pCtx==0 ){
30723 rc = SQLITE_NOMEM;
30724 }else{
30725 /* NB: zFilename exists and remains valid until the file is closed
30726 ** according to requirement F11141. So we do not need to make a
@@ -30746,11 +30820,11 @@
30746 */
30747 char *zLockFile;
30748 int nFilename;
30749 assert( zFilename!=0 );
30750 nFilename = (int)strlen(zFilename) + 6;
30751 zLockFile = (char *)sqlite3_malloc(nFilename);
30752 if( zLockFile==0 ){
30753 rc = SQLITE_NOMEM;
30754 }else{
30755 sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename);
30756 }
@@ -31123,11 +31197,11 @@
31123 UnixUnusedFd *pUnused;
31124 pUnused = findReusableFd(zName, flags);
31125 if( pUnused ){
31126 fd = pUnused->fd;
31127 }else{
31128 pUnused = sqlite3_malloc(sizeof(*pUnused));
31129 if( !pUnused ){
31130 return SQLITE_NOMEM;
31131 }
31132 }
31133 p->pUnused = pUnused;
@@ -31503,11 +31577,11 @@
31503 ** that we always use the same random number sequence. This makes the
31504 ** tests repeatable.
31505 */
31506 memset(zBuf, 0, nBuf);
31507 randomnessPid = osGetpid(0);
31508 #if !defined(SQLITE_TEST)
31509 {
31510 int fd, got;
31511 fd = robust_open("/dev/urandom", O_RDONLY, 0);
31512 if( fd<0 ){
31513 time_t t;
@@ -31915,11 +31989,11 @@
31915 */
31916 pUnused = findReusableFd(path, openFlags);
31917 if( pUnused ){
31918 fd = pUnused->fd;
31919 }else{
31920 pUnused = sqlite3_malloc(sizeof(*pUnused));
31921 if( !pUnused ){
31922 return SQLITE_NOMEM;
31923 }
31924 }
31925 if( fd<0 ){
@@ -31948,11 +32022,11 @@
31948 default:
31949 return SQLITE_CANTOPEN_BKPT;
31950 }
31951 }
31952
31953 pNew = (unixFile *)sqlite3_malloc(sizeof(*pNew));
31954 if( pNew==NULL ){
31955 rc = SQLITE_NOMEM;
31956 goto end_create_proxy;
31957 }
31958 memset(pNew, 0, sizeof(unixFile));
@@ -31981,21 +32055,22 @@
31981 SQLITE_API int sqlite3_hostid_num = 0;
31982 #endif
31983
31984 #define PROXY_HOSTIDLEN 16 /* conch file host id length */
31985
 
31986 /* Not always defined in the headers as it ought to be */
31987 extern int gethostuuid(uuid_t id, const struct timespec *wait);
 
31988
31989 /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
31990 ** bytes of writable memory.
31991 */
31992 static int proxyGetHostID(unsigned char *pHostID, int *pError){
31993 assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
31994 memset(pHostID, 0, PROXY_HOSTIDLEN);
31995 # if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
31996 (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
31997 {
31998 struct timespec timeout = {1, 0}; /* 1 sec timeout */
31999 if( gethostuuid(pHostID, &timeout) ){
32000 int err = errno;
32001 if( pError ){
@@ -32409,11 +32484,11 @@
32409 return rc;
32410 }
32411
32412 /*
32413 ** Given the name of a database file, compute the name of its conch file.
32414 ** Store the conch filename in memory obtained from sqlite3_malloc().
32415 ** Make *pConchPath point to the new name. Return SQLITE_OK on success
32416 ** or SQLITE_NOMEM if unable to obtain memory.
32417 **
32418 ** The caller is responsible for ensuring that the allocated memory
32419 ** space is eventually freed.
@@ -32425,11 +32500,11 @@
32425 int len = (int)strlen(dbPath); /* Length of database filename - dbPath */
32426 char *conchPath; /* buffer in which to construct conch name */
32427
32428 /* Allocate space for the conch filename and initialize the name to
32429 ** the name of the original database file. */
32430 *pConchPath = conchPath = (char *)sqlite3_malloc(len + 8);
32431 if( conchPath==0 ){
32432 return SQLITE_NOMEM;
32433 }
32434 memcpy(conchPath, dbPath, len+1);
32435
@@ -32541,11 +32616,11 @@
32541 }
32542
32543 OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
32544 (lockPath ? lockPath : ":auto:"), osGetpid(0)));
32545
32546 pCtx = sqlite3_malloc( sizeof(*pCtx) );
32547 if( pCtx==0 ){
32548 return SQLITE_NOMEM;
32549 }
32550 memset(pCtx, 0, sizeof(*pCtx));
32551
@@ -32985,20 +33060,10 @@
32985 */
32986 #ifdef MEMORY_DEBUG
32987 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
32988 #endif
32989
32990 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
32991 # ifndef SQLITE_DEBUG_OS_TRACE
32992 # define SQLITE_DEBUG_OS_TRACE 0
32993 # endif
32994 int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
32995 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
32996 #else
32997 # define OSTRACE(X)
32998 #endif
32999
33000 /*
33001 ** Macros for performance tracing. Normally turned off. Only works
33002 ** on i486 hardware.
33003 */
33004 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -35898,11 +35963,11 @@
35898 ** Used only when SQLITE_NO_SYNC is not defined.
35899 */
35900 BOOL rc;
35901 #endif
35902 #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \
35903 (defined(SQLITE_TEST) && defined(SQLITE_DEBUG))
35904 /*
35905 ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or
35906 ** OSTRACE() macros.
35907 */
35908 winFile *pFile = (winFile*)id;
@@ -36575,11 +36640,11 @@
36575 DWORD lastErrno; /* The Windows errno from the last I/O error */
36576
36577 int nRef; /* Number of winShm objects pointing to this */
36578 winShm *pFirst; /* All winShm objects pointing to this */
36579 winShmNode *pNext; /* Next in list of all winShmNode objects */
36580 #ifdef SQLITE_DEBUG
36581 u8 nextShmId; /* Next available winShm.id value */
36582 #endif
36583 };
36584
36585 /*
@@ -36606,11 +36671,11 @@
36606 winShmNode *pShmNode; /* The underlying winShmNode object */
36607 winShm *pNext; /* Next winShm with the same winShmNode */
36608 u8 hasMutex; /* True if holding the winShmNode mutex */
36609 u16 sharedMask; /* Mask of shared locks held */
36610 u16 exclMask; /* Mask of exclusive locks held */
36611 #ifdef SQLITE_DEBUG
36612 u8 id; /* Id of this connection with its winShmNode */
36613 #endif
36614 };
36615
36616 /*
@@ -36797,11 +36862,11 @@
36797 if( rc ) goto shm_open_err;
36798 }
36799
36800 /* Make the new connection a child of the winShmNode */
36801 p->pShmNode = pShmNode;
36802 #ifdef SQLITE_DEBUG
36803 p->id = pShmNode->nextShmId++;
36804 #endif
36805 pShmNode->nRef++;
36806 pDbFd->pShm = p;
36807 winShmLeaveMutex();
@@ -37066,11 +37131,11 @@
37066 goto shmpage_out;
37067 }
37068 }
37069
37070 /* Map the requested memory region into this processes address space. */
37071 apNew = (struct ShmRegion *)sqlite3_realloc(
37072 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
37073 );
37074 if( !apNew ){
37075 rc = SQLITE_IOERR_NOMEM;
37076 goto shmpage_out;
@@ -38513,11 +38578,11 @@
38513 ** Write up to nBuf bytes of randomness into zBuf.
38514 */
38515 static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
38516 int n = 0;
38517 UNUSED_PARAMETER(pVfs);
38518 #if defined(SQLITE_TEST)
38519 n = nBuf;
38520 memset(zBuf, 0, nBuf);
38521 #else
38522 if( sizeof(SYSTEMTIME)<=nBuf-n ){
38523 SYSTEMTIME x;
@@ -38547,11 +38612,10 @@
38547 LARGE_INTEGER i;
38548 osQueryPerformanceCounter(&i);
38549 memcpy(&zBuf[n], &i, sizeof(i));
38550 n += sizeof(i);
38551 }
38552 #endif
38553 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
38554 if( sizeof(UUID)<=nBuf-n ){
38555 UUID id;
38556 memset(&id, 0, sizeof(UUID));
38557 osUuidCreate(&id);
@@ -38564,10 +38628,11 @@
38564 osUuidCreateSequential(&id);
38565 memcpy(zBuf, &id, sizeof(UUID));
38566 n += sizeof(UUID);
38567 }
38568 #endif
 
38569 return n;
38570 }
38571
38572
38573 /*
@@ -39118,11 +39183,11 @@
39118
39119 /* Allocate the Bitvec to be tested and a linear array of
39120 ** bits to act as the reference */
39121 pBitvec = sqlite3BitvecCreate( sz );
39122 pV = sqlite3MallocZero( (sz+7)/8 + 1 );
39123 pTmpSpace = sqlite3_malloc(BITVEC_SZ);
39124 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
39125
39126 /* NULL pBitvec tests */
39127 sqlite3BitvecSet(0, 1);
39128 sqlite3BitvecClear(0, 1, pTmpSpace);
@@ -44607,13 +44672,11 @@
44607 Pgno nTruncate, /* Database size after this commit */
44608 int isCommit /* True if this is a commit */
44609 ){
44610 int rc; /* Return code */
44611 int nList; /* Number of pages in pList */
44612 #if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES)
44613 PgHdr *p; /* For looping over pages */
44614 #endif
44615
44616 assert( pPager->pWal );
44617 assert( pList );
44618 #ifdef SQLITE_DEBUG
44619 /* Verify that the page list is in accending order */
@@ -44626,11 +44689,10 @@
44626 if( isCommit ){
44627 /* If a WAL transaction is being committed, there is no point in writing
44628 ** any pages with page numbers greater than nTruncate into the WAL file.
44629 ** They will never be read by any client. So remove them from the pDirty
44630 ** list here. */
44631 PgHdr *p;
44632 PgHdr **ppNext = &pList;
44633 nList = 0;
44634 for(p=pList; (*ppNext = p)!=0; p=p->pDirty){
44635 if( p->pgno<=nTruncate ){
44636 ppNext = &p->pDirty;
@@ -44646,11 +44708,10 @@
44646 if( pList->pgno==1 ) pager_write_changecounter(pList);
44647 rc = sqlite3WalFrames(pPager->pWal,
44648 pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags
44649 );
44650 if( rc==SQLITE_OK && pPager->pBackup ){
44651 PgHdr *p;
44652 for(p=pList; p; p=p->pDirty){
44653 sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
44654 }
44655 }
44656
@@ -48577,10 +48638,12 @@
48577 }else if( state==PAGER_OPEN ){
48578 pager_unlock(pPager);
48579 }
48580 assert( state==pPager->eState );
48581 }
 
 
48582 }
48583 }
48584
48585 /* Return the new journal mode */
48586 return (int)pPager->journalMode;
@@ -49359,11 +49422,11 @@
49359
49360 /* Enlarge the pWal->apWiData[] array if required */
49361 if( pWal->nWiData<=iPage ){
49362 int nByte = sizeof(u32*)*(iPage+1);
49363 volatile u32 **apNew;
49364 apNew = (volatile u32 **)sqlite3_realloc((void *)pWal->apWiData, nByte);
49365 if( !apNew ){
49366 *ppPage = 0;
49367 return SQLITE_NOMEM;
49368 }
49369 memset((void*)&apNew[pWal->nWiData], 0,
@@ -49984,11 +50047,11 @@
49984 goto finished;
49985 }
49986
49987 /* Malloc a buffer to read frames into. */
49988 szFrame = szPage + WAL_FRAME_HDRSIZE;
49989 aFrame = (u8 *)sqlite3_malloc(szFrame);
49990 if( !aFrame ){
49991 rc = SQLITE_NOMEM;
49992 goto recovery_error;
49993 }
49994 aData = &aFrame[WAL_FRAME_HDRSIZE];
@@ -50377,21 +50440,21 @@
50377 /* Allocate space for the WalIterator object. */
50378 nSegment = walFramePage(iLast) + 1;
50379 nByte = sizeof(WalIterator)
50380 + (nSegment-1)*sizeof(struct WalSegment)
50381 + iLast*sizeof(ht_slot);
50382 p = (WalIterator *)sqlite3_malloc(nByte);
50383 if( !p ){
50384 return SQLITE_NOMEM;
50385 }
50386 memset(p, 0, nByte);
50387 p->nSegment = nSegment;
50388
50389 /* Allocate temporary space used by the merge-sort routine. This block
50390 ** of memory will be freed before this function returns.
50391 */
50392 aTmp = (ht_slot *)sqlite3_malloc(
50393 sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
50394 );
50395 if( !aTmp ){
50396 rc = SQLITE_NOMEM;
50397 }
@@ -50567,10 +50630,18 @@
50567 ** cannot be backfilled from the WAL.
50568 */
50569 mxSafeFrame = pWal->hdr.mxFrame;
50570 mxPage = pWal->hdr.nPage;
50571 for(i=1; i<WAL_NREADER; i++){
 
 
 
 
 
 
 
 
50572 u32 y = pInfo->aReadMark[i];
50573 if( mxSafeFrame>y ){
50574 assert( y<=pWal->hdr.mxFrame );
50575 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
50576 if( rc==SQLITE_OK ){
@@ -55407,11 +55478,11 @@
55407 }
55408 assert( nReserve>=0 && nReserve<=255 );
55409 if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE &&
55410 ((pageSize-1)&pageSize)==0 ){
55411 assert( (pageSize & 7)==0 );
55412 assert( !pBt->pPage1 && !pBt->pCursor );
55413 pBt->pageSize = (u32)pageSize;
55414 freeTempSpace(pBt);
55415 }
55416 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve);
55417 pBt->usableSize = pBt->pageSize - (u16)nReserve;
@@ -57429,17 +57500,22 @@
57429 */
57430 static const void *fetchPayload(
57431 BtCursor *pCur, /* Cursor pointing to entry to read from */
57432 u32 *pAmt /* Write the number of available bytes here */
57433 ){
 
57434 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
57435 assert( pCur->eState==CURSOR_VALID );
57436 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
57437 assert( cursorHoldsMutex(pCur) );
57438 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
57439 assert( pCur->info.nSize>0 );
57440 *pAmt = pCur->info.nLocal;
 
 
 
 
57441 return (void*)pCur->info.pPayload;
57442 }
57443
57444
57445 /*
@@ -59713,11 +59789,10 @@
59713 if( iParentIdx==0 ){
59714 nxDiv = 0;
59715 }else if( iParentIdx==i ){
59716 nxDiv = i-2+bBulk;
59717 }else{
59718 assert( bBulk==0 );
59719 nxDiv = iParentIdx-1;
59720 }
59721 i = 2-bBulk;
59722 }
59723 nOld = i+1;
@@ -61501,10 +61576,61 @@
61501 iPage = get4byte(pOvflData);
61502 sqlite3PagerUnref(pOvflPage);
61503 }
61504 }
61505 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61506
61507 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
61508 /*
61509 ** Do various sanity checks on a single page of a tree. Return
61510 ** the tree depth. Root pages return 0. Parents of root pages
@@ -61534,11 +61660,12 @@
61534 int hdr, cellStart;
61535 int nCell;
61536 u8 *data;
61537 BtShared *pBt;
61538 int usableSize;
61539 char *hit = 0;
 
61540 i64 nMinKey = 0;
61541 i64 nMaxKey = 0;
61542 const char *saved_zPfx = pCheck->zPfx;
61543 int saved_v1 = pCheck->v1;
61544 int saved_v2 = pCheck->v2;
@@ -61679,19 +61806,19 @@
61679
61680 /* Check for complete coverage of the page
61681 */
61682 data = pPage->aData;
61683 hdr = pPage->hdrOffset;
61684 hit = sqlite3PageMalloc( pBt->pageSize );
61685 pCheck->zPfx = 0;
61686 if( hit==0 ){
61687 pCheck->mallocFailed = 1;
61688 }else{
61689 int contentOffset = get2byteNotZero(&data[hdr+5]);
61690 assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
61691 memset(hit+contentOffset, 0, usableSize-contentOffset);
61692 memset(hit, 1, contentOffset);
61693 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
61694 ** number of cells on the page. */
61695 nCell = get2byte(&data[hdr+3]);
61696 /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
61697 ** immediately follows the b-tree page header. */
@@ -61699,20 +61826,19 @@
61699 /* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
61700 ** integer offsets to the cell contents. */
61701 for(i=0; i<nCell; i++){
61702 int pc = get2byte(&data[cellStart+i*2]);
61703 u32 size = 65536;
61704 int j;
61705 if( pc<=usableSize-4 ){
61706 size = cellSizePtr(pPage, &data[pc]);
61707 }
61708 if( (int)(pc+size-1)>=usableSize ){
61709 pCheck->zPfx = 0;
61710 checkAppendMsg(pCheck,
61711 "Corruption detected in cell %d on page %d",i,iPage);
61712 }else{
61713 for(j=pc+size-1; j>=pc; j--) hit[j]++;
61714 }
61715 }
61716 /* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
61717 ** is the offset of the first freeblock, or zero if there are no
61718 ** freeblocks on the page. */
@@ -61720,11 +61846,11 @@
61720 while( i>0 ){
61721 int size, j;
61722 assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */
61723 size = get2byte(&data[i+2]);
61724 assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */
61725 for(j=i+size-1; j>=i; j--) hit[j]++;
61726 /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
61727 ** big-endian integer which is the offset in the b-tree page of the next
61728 ** freeblock in the chain, or zero if the freeblock is the last on the
61729 ** chain. */
61730 j = get2byte(&data[i]);
@@ -61732,31 +61858,37 @@
61732 ** increasing offset. */
61733 assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */
61734 assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */
61735 i = j;
61736 }
61737 for(i=cnt=0; i<usableSize; i++){
61738 if( hit[i]==0 ){
61739 cnt++;
61740 }else if( hit[i]>1 ){
 
 
61741 checkAppendMsg(pCheck,
61742 "Multiple uses for byte %d of page %d", i, iPage);
61743 break;
 
 
 
61744 }
61745 }
 
61746 /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
61747 ** is stored in the fifth field of the b-tree page header.
61748 ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
61749 ** number of fragmented free bytes within the cell content area.
61750 */
61751 if( cnt!=data[hdr+7] ){
61752 checkAppendMsg(pCheck,
61753 "Fragmentation of %d bytes reported as %d on page %d",
61754 cnt, data[hdr+7], iPage);
61755 }
61756 }
61757 sqlite3PageFree(hit);
61758 releasePage(pPage);
61759
61760 end_of_check:
61761 pCheck->zPfx = saved_zPfx;
61762 pCheck->v1 = saved_v1;
@@ -61816,12 +61948,11 @@
61816 sqlite3BtreeLeave(p);
61817 return 0;
61818 }
61819 i = PENDING_BYTE_PAGE(pBt);
61820 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
61821 sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
61822 sCheck.errMsg.useMalloc = 2;
61823
61824 /* Check the integrity of the freelist
61825 */
61826 sCheck.zPfx = "Main freelist: ";
61827 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
@@ -63153,14 +63284,15 @@
63153 return SQLITE_NOMEM;
63154 }
63155 pMem->z[pMem->n] = 0;
63156 pMem->z[pMem->n+1] = 0;
63157 pMem->flags |= MEM_Term;
 
 
63158 #ifdef SQLITE_DEBUG
63159 pMem->pScopyFrom = 0;
63160 #endif
63161 }
63162
63163 return SQLITE_OK;
63164 }
63165
63166 /*
@@ -64600,11 +64732,11 @@
64600 int i;
64601 int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
64602 Mem *aMem = pRec->aMem;
64603 sqlite3 *db = aMem[0].db;
64604 for(i=0; i<nCol; i++){
64605 if( aMem[i].szMalloc ) sqlite3DbFree(db, aMem[i].zMalloc);
64606 }
64607 sqlite3KeyInfoUnref(pRec->pKeyInfo);
64608 sqlite3DbFree(db, pRec);
64609 }
64610 }
@@ -66436,18 +66568,35 @@
66436 pVtabCursor->pVtab->nRef--;
66437 pModule->xClose(pVtabCursor);
66438 }
66439 #endif
66440 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66441
66442 /*
66443 ** Copy the values stored in the VdbeFrame structure to its Vdbe. This
66444 ** is used, for example, when a trigger sub-program is halted to restore
66445 ** control to the main program.
66446 */
66447 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
66448 Vdbe *v = pFrame->v;
 
66449 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
66450 v->anExec = pFrame->anExec;
66451 #endif
66452 v->aOnceFlag = pFrame->aOnceFlag;
66453 v->nOnceFlag = pFrame->nOnceFlag;
@@ -66478,21 +66627,11 @@
66478 sqlite3VdbeFrameRestore(pFrame);
66479 p->pFrame = 0;
66480 p->nFrame = 0;
66481 }
66482 assert( p->nFrame==0 );
66483
66484 if( p->apCsr ){
66485 int i;
66486 for(i=0; i<p->nCursor; i++){
66487 VdbeCursor *pC = p->apCsr[i];
66488 if( pC ){
66489 sqlite3VdbeFreeCursor(p, pC);
66490 p->apCsr[i] = 0;
66491 }
66492 }
66493 }
66494 if( p->aMem ){
66495 releaseMemArray(&p->aMem[1], p->nMem);
66496 }
66497 while( p->pDelFrame ){
66498 VdbeFrame *pDel = p->pDelFrame;
@@ -68233,11 +68372,11 @@
68233 ** If database corruption is discovered, set pPKey2->errCode to
68234 ** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
68235 ** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
68236 ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
68237 */
68238 static int vdbeRecordCompareWithSkip(
68239 int nKey1, const void *pKey1, /* Left key */
68240 UnpackedRecord *pPKey2, /* Right key */
68241 int bSkip /* If true, skip the first field */
68242 ){
68243 u32 d1; /* Offset into aKey[] of next data element */
@@ -68419,11 +68558,11 @@
68419 }
68420 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
68421 int nKey1, const void *pKey1, /* Left key */
68422 UnpackedRecord *pPKey2 /* Right key */
68423 ){
68424 return vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
68425 }
68426
68427
68428 /*
68429 ** This function is an optimized version of sqlite3VdbeRecordCompare()
@@ -68507,11 +68646,11 @@
68507 }else if( v<lhs ){
68508 res = pPKey2->r2;
68509 }else if( pPKey2->nField>1 ){
68510 /* The first fields of the two keys are equal. Compare the trailing
68511 ** fields. */
68512 res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68513 }else{
68514 /* The first fields of the two keys are equal and there are no trailing
68515 ** fields. Return pPKey2->default_rc in this case. */
68516 res = pPKey2->default_rc;
68517 }
@@ -68555,11 +68694,11 @@
68555
68556 if( res==0 ){
68557 res = nStr - pPKey2->aMem[0].n;
68558 if( res==0 ){
68559 if( pPKey2->nField>1 ){
68560 res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68561 }else{
68562 res = pPKey2->default_rc;
68563 }
68564 }else if( res>0 ){
68565 res = pPKey2->r2;
@@ -70497,21 +70636,22 @@
70497 Mem *pVar; /* Value of a host parameter */
70498 StrAccum out; /* Accumulate the output here */
70499 char zBase[100]; /* Initial working space */
70500
70501 db = p->db;
70502 sqlite3StrAccumInit(&out, zBase, sizeof(zBase),
70503 db->aLimit[SQLITE_LIMIT_LENGTH]);
70504 out.db = db;
70505 if( db->nVdbeExec>1 ){
70506 while( *zRawSql ){
70507 const char *zStart = zRawSql;
70508 while( *(zRawSql++)!='\n' && *zRawSql );
70509 sqlite3StrAccumAppend(&out, "-- ", 3);
70510 assert( (zRawSql - zStart) > 0 );
70511 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
70512 }
 
 
70513 }else{
70514 while( zRawSql[0] ){
70515 n = findNextHostParameter(zRawSql, &nToken);
70516 assert( n>0 );
70517 sqlite3StrAccumAppend(&out, zRawSql, n);
@@ -70524,14 +70664,16 @@
70524 sqlite3GetInt32(&zRawSql[1], &idx);
70525 }else{
70526 idx = nextIndex;
70527 }
70528 }else{
70529 assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' );
 
70530 testcase( zRawSql[0]==':' );
70531 testcase( zRawSql[0]=='$' );
70532 testcase( zRawSql[0]=='@' );
 
70533 idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken);
70534 assert( idx>0 );
70535 }
70536 zRawSql += nToken;
70537 nextIndex = idx + 1;
@@ -70895,10 +71037,11 @@
70895 ** representation.
70896 */
70897 if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
70898 sqlite3VdbeMemStringify(pRec, enc, 1);
70899 }
 
70900 }
70901 }
70902
70903 /*
70904 ** Try to convert the type of a function argument or a result column
@@ -71202,21 +71345,38 @@
71202 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
71203 return 1;
71204 }
71205 #endif
71206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71207
71208 /*
71209 ** Execute as much of a VDBE program as we can.
71210 ** This is the core of sqlite3_step().
71211 */
71212 SQLITE_PRIVATE int sqlite3VdbeExec(
71213 Vdbe *p /* The VDBE */
71214 ){
71215 int pc=0; /* The program counter */
71216 Op *aOp = p->aOp; /* Copy of p->aOp */
71217 Op *pOp; /* Current operation */
 
 
 
71218 int rc = SQLITE_OK; /* Value to return */
71219 sqlite3 *db = p->db; /* The database */
71220 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
71221 u8 encoding = ENC(db); /* The database encoding */
71222 int iCompare = 0; /* Result of last OP_Compare operation */
@@ -71288,27 +71448,26 @@
71288 }
71289 if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
71290 }
71291 sqlite3EndBenignMalloc();
71292 #endif
71293 for(pc=p->pc; rc==SQLITE_OK; pc++){
71294 assert( pc>=0 && pc<p->nOp );
71295 if( db->mallocFailed ) goto no_mem;
71296 #ifdef VDBE_PROFILE
71297 start = sqlite3Hwtime();
71298 #endif
71299 nVmStep++;
71300 pOp = &aOp[pc];
71301 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
71302 if( p->anExec ) p->anExec[pc]++;
71303 #endif
71304
71305 /* Only allow tracing if SQLITE_DEBUG is defined.
71306 */
71307 #ifdef SQLITE_DEBUG
71308 if( db->flags & SQLITE_VdbeTrace ){
71309 sqlite3VdbePrintOp(stdout, pc, pOp);
71310 }
71311 #endif
71312
71313
71314 /* Check to see if we need to simulate an interrupt. This only happens
@@ -71321,27 +71480,13 @@
71321 sqlite3_interrupt(db);
71322 }
71323 }
71324 #endif
71325
71326 /* On any opcode with the "out2-prerelease" tag, free any
71327 ** external allocations out of mem[p2] and set mem[p2] to be
71328 ** an undefined integer. Opcodes will either fill in the integer
71329 ** value or convert mem[p2] to a different type.
71330 */
71331 assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
71332 if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){
71333 assert( pOp->p2>0 );
71334 assert( pOp->p2<=(p->nMem-p->nCursor) );
71335 pOut = &aMem[pOp->p2];
71336 memAboutToChange(p, pOut);
71337 if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
71338 pOut->flags = MEM_Int;
71339 }
71340
71341 /* Sanity checking on other operands */
71342 #ifdef SQLITE_DEBUG
 
71343 if( (pOp->opflags & OPFLG_IN1)!=0 ){
71344 assert( pOp->p1>0 );
71345 assert( pOp->p1<=(p->nMem-p->nCursor) );
71346 assert( memIsValid(&aMem[pOp->p1]) );
71347 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
@@ -71370,10 +71515,13 @@
71370 assert( pOp->p3>0 );
71371 assert( pOp->p3<=(p->nMem-p->nCursor) );
71372 memAboutToChange(p, &aMem[pOp->p3]);
71373 }
71374 #endif
 
 
 
71375
71376 switch( pOp->opcode ){
71377
71378 /*****************************************************************************
71379 ** What follows is a massive switch statement where each case implements a
@@ -71393,11 +71541,11 @@
71393 ** case statement is followed by a comment of the form "/# same as ... #/"
71394 ** that comment is used to determine the particular value of the opcode.
71395 **
71396 ** Other keywords in the comment that follows each case are used to
71397 ** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[].
71398 ** Keywords include: in1, in2, in3, out2_prerelease, out2, out3. See
71399 ** the mkopcodeh.awk script for additional information.
71400 **
71401 ** Documentation about VDBE opcodes is generated by scanning this file
71402 ** for lines of that contain "Opcode:". That line and all subsequent
71403 ** comment lines are used in the generation of the opcode.html documentation
@@ -71421,11 +71569,12 @@
71421 ** is sometimes set to 1 instead of 0 as a hint to the command-line shell
71422 ** that this Goto is the bottom of a loop and that the lines from P2 down
71423 ** to the current line should be indented for EXPLAIN output.
71424 */
71425 case OP_Goto: { /* jump */
71426 pc = pOp->p2 - 1;
 
71427
71428 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
71429 ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
71430 ** completion. Check to see if sqlite3_interrupt() has been called
71431 ** or if the progress callback needs to be invoked.
@@ -71466,13 +71615,17 @@
71466 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
71467 pIn1 = &aMem[pOp->p1];
71468 assert( VdbeMemDynamic(pIn1)==0 );
71469 memAboutToChange(p, pIn1);
71470 pIn1->flags = MEM_Int;
71471 pIn1->u.i = pc;
71472 REGISTER_TRACE(pOp->p1, pIn1);
71473 pc = pOp->p2 - 1;
 
 
 
 
71474 break;
71475 }
71476
71477 /* Opcode: Return P1 * * * *
71478 **
@@ -71480,11 +71633,11 @@
71480 ** the jump, register P1 becomes undefined.
71481 */
71482 case OP_Return: { /* in1 */
71483 pIn1 = &aMem[pOp->p1];
71484 assert( pIn1->flags==MEM_Int );
71485 pc = (int)pIn1->u.i;
71486 pIn1->flags = MEM_Undefined;
71487 break;
71488 }
71489
71490 /* Opcode: InitCoroutine P1 P2 P3 * *
@@ -71504,11 +71657,11 @@
71504 assert( pOp->p3>=0 && pOp->p3<p->nOp );
71505 pOut = &aMem[pOp->p1];
71506 assert( !VdbeMemDynamic(pOut) );
71507 pOut->u.i = pOp->p3 - 1;
71508 pOut->flags = MEM_Int;
71509 if( pOp->p2 ) pc = pOp->p2 - 1;
71510 break;
71511 }
71512
71513 /* Opcode: EndCoroutine P1 * * * *
71514 **
@@ -71524,11 +71677,11 @@
71524 assert( pIn1->flags==MEM_Int );
71525 assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
71526 pCaller = &aOp[pIn1->u.i];
71527 assert( pCaller->opcode==OP_Yield );
71528 assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
71529 pc = pCaller->p2 - 1;
71530 pIn1->flags = MEM_Undefined;
71531 break;
71532 }
71533
71534 /* Opcode: Yield P1 P2 * * *
@@ -71548,13 +71701,13 @@
71548 int pcDest;
71549 pIn1 = &aMem[pOp->p1];
71550 assert( VdbeMemDynamic(pIn1)==0 );
71551 pIn1->flags = MEM_Int;
71552 pcDest = (int)pIn1->u.i;
71553 pIn1->u.i = pc;
71554 REGISTER_TRACE(pOp->p1, pIn1);
71555 pc = pcDest;
71556 break;
71557 }
71558
71559 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
71560 ** Synopsis: if r[P3]=null halt
@@ -71601,34 +71754,38 @@
71601 ** is the same as executing Halt.
71602 */
71603 case OP_Halt: {
71604 const char *zType;
71605 const char *zLogFmt;
 
 
71606
 
71607 if( pOp->p1==SQLITE_OK && p->pFrame ){
71608 /* Halt the sub-program. Return control to the parent frame. */
71609 VdbeFrame *pFrame = p->pFrame;
71610 p->pFrame = pFrame->pParent;
71611 p->nFrame--;
71612 sqlite3VdbeSetChanges(db, p->nChange);
71613 pc = sqlite3VdbeFrameRestore(pFrame);
71614 lastRowid = db->lastRowid;
71615 if( pOp->p2==OE_Ignore ){
71616 /* Instruction pc is the OP_Program that invoked the sub-program
71617 ** currently being halted. If the p2 instruction of this OP_Halt
71618 ** instruction is set to OE_Ignore, then the sub-program is throwing
71619 ** an IGNORE exception. In this case jump to the address specified
71620 ** as the p2 of the calling OP_Program. */
71621 pc = p->aOp[pc].p2-1;
71622 }
71623 aOp = p->aOp;
71624 aMem = p->aMem;
 
71625 break;
71626 }
71627 p->rc = pOp->p1;
71628 p->errorAction = (u8)pOp->p2;
71629 p->pc = pc;
71630 if( p->rc ){
71631 if( pOp->p5 ){
71632 static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
71633 "FOREIGN KEY" };
71634 assert( pOp->p5>=1 && pOp->p5<=4 );
@@ -71648,11 +71805,11 @@
71648 }else if( pOp->p4.z ){
71649 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
71650 }else{
71651 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
71652 }
71653 sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg);
71654 }
71655 rc = sqlite3VdbeHalt(p);
71656 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
71657 if( rc==SQLITE_BUSY ){
71658 p->rc = rc = SQLITE_BUSY;
@@ -71667,11 +71824,12 @@
71667 /* Opcode: Integer P1 P2 * * *
71668 ** Synopsis: r[P2]=P1
71669 **
71670 ** The 32-bit integer value P1 is written into register P2.
71671 */
71672 case OP_Integer: { /* out2-prerelease */
 
71673 pOut->u.i = pOp->p1;
71674 break;
71675 }
71676
71677 /* Opcode: Int64 * P2 * P4 *
@@ -71678,11 +71836,12 @@
71678 ** Synopsis: r[P2]=P4
71679 **
71680 ** P4 is a pointer to a 64-bit integer value.
71681 ** Write that value into register P2.
71682 */
71683 case OP_Int64: { /* out2-prerelease */
 
71684 assert( pOp->p4.pI64!=0 );
71685 pOut->u.i = *pOp->p4.pI64;
71686 break;
71687 }
71688
@@ -71691,11 +71850,12 @@
71691 ** Synopsis: r[P2]=P4
71692 **
71693 ** P4 is a pointer to a 64-bit floating point value.
71694 ** Write that value into register P2.
71695 */
71696 case OP_Real: { /* same as TK_FLOAT, out2-prerelease */
 
71697 pOut->flags = MEM_Real;
71698 assert( !sqlite3IsNaN(*pOp->p4.pReal) );
71699 pOut->u.r = *pOp->p4.pReal;
71700 break;
71701 }
@@ -71707,12 +71867,13 @@
71707 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
71708 ** into a String opcode before it is executed for the first time. During
71709 ** this transformation, the length of string P4 is computed and stored
71710 ** as the P1 parameter.
71711 */
71712 case OP_String8: { /* same as TK_STRING, out2-prerelease */
71713 assert( pOp->p4.z!=0 );
 
71714 pOp->opcode = OP_String;
71715 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
71716
71717 #ifndef SQLITE_OMIT_UTF16
71718 if( encoding!=SQLITE_UTF8 ){
@@ -71745,12 +71906,13 @@
71745 ** If P5!=0 and the content of register P3 is greater than zero, then
71746 ** the datatype of the register P2 is converted to BLOB. The content is
71747 ** the same sequence of bytes, it is merely interpreted as a BLOB instead
71748 ** of a string, as if it had been CAST.
71749 */
71750 case OP_String: { /* out2-prerelease */
71751 assert( pOp->p4.z!=0 );
 
71752 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
71753 pOut->z = pOp->p4.z;
71754 pOut->n = pOp->p1;
71755 pOut->enc = encoding;
71756 UPDATE_MAX_BLOBSIZE(pOut);
@@ -71774,13 +71936,14 @@
71774 **
71775 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
71776 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
71777 ** OP_Ne or OP_Eq.
71778 */
71779 case OP_Null: { /* out2-prerelease */
71780 int cnt;
71781 u16 nullFlag;
 
71782 cnt = pOp->p3-pOp->p2;
71783 assert( pOp->p3<=(p->nMem-p->nCursor) );
71784 pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
71785 while( cnt>0 ){
71786 pOut++;
@@ -71811,12 +71974,13 @@
71811 ** Synopsis: r[P2]=P4 (len=P1)
71812 **
71813 ** P4 points to a blob of data P1 bytes long. Store this
71814 ** blob in register P2.
71815 */
71816 case OP_Blob: { /* out2-prerelease */
71817 assert( pOp->p1 <= SQLITE_MAX_LENGTH );
 
71818 sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
71819 pOut->enc = encoding;
71820 UPDATE_MAX_BLOBSIZE(pOut);
71821 break;
71822 }
@@ -71827,19 +71991,20 @@
71827 ** Transfer the values of bound parameter P1 into register P2
71828 **
71829 ** If the parameter is named, then its name appears in P4.
71830 ** The P4 value is used by sqlite3_bind_parameter_name().
71831 */
71832 case OP_Variable: { /* out2-prerelease */
71833 Mem *pVar; /* Value being transferred */
71834
71835 assert( pOp->p1>0 && pOp->p1<=p->nVar );
71836 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
71837 pVar = &p->aVar[pOp->p1 - 1];
71838 if( sqlite3VdbeMemTooBig(pVar) ){
71839 goto too_big;
71840 }
 
71841 sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
71842 UPDATE_MAX_BLOBSIZE(pOut);
71843 break;
71844 }
71845
@@ -71870,14 +72035,15 @@
71870 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
71871 assert( memIsValid(pIn1) );
71872 memAboutToChange(p, pOut);
71873 sqlite3VdbeMemMove(pOut, pIn1);
71874 #ifdef SQLITE_DEBUG
71875 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
71876 pOut->pScopyFrom += p1 - pOp->p2;
71877 }
71878 #endif
 
71879 REGISTER_TRACE(p2++, pOut);
71880 pIn1++;
71881 pOut++;
71882 }while( --n );
71883 break;
@@ -72012,11 +72178,11 @@
72012 }
72013 if( db->mallocFailed ) goto no_mem;
72014
72015 /* Return SQLITE_ROW
72016 */
72017 p->pc = pc + 1;
72018 rc = SQLITE_ROW;
72019 goto vdbe_return;
72020 }
72021
72022 /* Opcode: Concat P1 P2 P3 * *
@@ -72258,11 +72424,11 @@
72258 REGISTER_TRACE(pOp->p2+i, pArg);
72259 }
72260
72261 assert( pOp->p4type==P4_FUNCDEF );
72262 ctx.pFunc = pOp->p4.pFunc;
72263 ctx.iOp = pc;
72264 ctx.pVdbe = p;
72265 MemSetTypeFlag(ctx.pOut, MEM_Null);
72266 ctx.fErrorOrAux = 0;
72267 db->lastRowid = lastRowid;
72268 (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
@@ -72272,11 +72438,11 @@
72272 if( ctx.fErrorOrAux ){
72273 if( ctx.isError ){
72274 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut));
72275 rc = ctx.isError;
72276 }
72277 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
72278 }
72279
72280 /* Copy the result of the function into register P3 */
72281 sqlite3VdbeChangeEncoding(ctx.pOut, encoding);
72282 if( sqlite3VdbeMemTooBig(ctx.pOut) ){
@@ -72401,12 +72567,11 @@
72401 if( (pIn1->flags & MEM_Int)==0 ){
72402 if( pOp->p2==0 ){
72403 rc = SQLITE_MISMATCH;
72404 goto abort_due_to_error;
72405 }else{
72406 pc = pOp->p2 - 1;
72407 break;
72408 }
72409 }
72410 }
72411 MemSetTypeFlag(pIn1, MEM_Int);
72412 break;
@@ -72588,11 +72753,11 @@
72588 MemSetTypeFlag(pOut, MEM_Null);
72589 REGISTER_TRACE(pOp->p2, pOut);
72590 }else{
72591 VdbeBranchTaken(2,3);
72592 if( pOp->p5 & SQLITE_JUMPIFNULL ){
72593 pc = pOp->p2-1;
72594 }
72595 }
72596 break;
72597 }
72598 }else{
@@ -72639,10 +72804,16 @@
72639 case OP_Lt: res = res<0; break;
72640 case OP_Le: res = res<=0; break;
72641 case OP_Gt: res = res>0; break;
72642 default: res = res>=0; break;
72643 }
 
 
 
 
 
 
72644
72645 if( pOp->p5 & SQLITE_STOREP2 ){
72646 pOut = &aMem[pOp->p2];
72647 memAboutToChange(p, pOut);
72648 MemSetTypeFlag(pOut, MEM_Int);
@@ -72649,18 +72820,13 @@
72649 pOut->u.i = res;
72650 REGISTER_TRACE(pOp->p2, pOut);
72651 }else{
72652 VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
72653 if( res ){
72654 pc = pOp->p2-1;
72655 }
72656 }
72657 /* Undo any changes made by applyAffinity() to the input registers. */
72658 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
72659 pIn1->flags = flags1;
72660 assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
72661 pIn3->flags = flags3;
72662 break;
72663 }
72664
72665 /* Opcode: Permutation * * * P4 *
72666 **
@@ -72751,15 +72917,15 @@
72751 ** in the most recent OP_Compare instruction the P1 vector was less than
72752 ** equal to, or greater than the P2 vector, respectively.
72753 */
72754 case OP_Jump: { /* jump */
72755 if( iCompare<0 ){
72756 pc = pOp->p1 - 1; VdbeBranchTaken(0,3);
72757 }else if( iCompare==0 ){
72758 pc = pOp->p2 - 1; VdbeBranchTaken(1,3);
72759 }else{
72760 pc = pOp->p3 - 1; VdbeBranchTaken(2,3);
72761 }
72762 break;
72763 }
72764
72765 /* Opcode: And P1 P2 P3 * *
@@ -72865,11 +73031,11 @@
72865 */
72866 case OP_Once: { /* jump */
72867 assert( pOp->p1<p->nOnceFlag );
72868 VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
72869 if( p->aOnceFlag[pOp->p1] ){
72870 pc = pOp->p2-1;
72871 }else{
72872 p->aOnceFlag[pOp->p1] = 1;
72873 }
72874 break;
72875 }
@@ -72900,11 +73066,11 @@
72900 #endif
72901 if( pOp->opcode==OP_IfNot ) c = !c;
72902 }
72903 VdbeBranchTaken(c!=0, 2);
72904 if( c ){
72905 pc = pOp->p2-1;
72906 }
72907 break;
72908 }
72909
72910 /* Opcode: IsNull P1 P2 * * *
@@ -72914,11 +73080,11 @@
72914 */
72915 case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
72916 pIn1 = &aMem[pOp->p1];
72917 VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
72918 if( (pIn1->flags & MEM_Null)!=0 ){
72919 pc = pOp->p2 - 1;
72920 }
72921 break;
72922 }
72923
72924 /* Opcode: NotNull P1 P2 * * *
@@ -72928,11 +73094,11 @@
72928 */
72929 case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
72930 pIn1 = &aMem[pOp->p1];
72931 VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
72932 if( (pIn1->flags & MEM_Null)==0 ){
72933 pc = pOp->p2 - 1;
72934 }
72935 break;
72936 }
72937
72938 /* Opcode: Column P1 P2 P3 P4 P5
@@ -73142,11 +73308,11 @@
73142 rc = SQLITE_CORRUPT_BKPT;
73143 goto op_column_error;
73144 }
73145 }
73146
73147 /* If after trying to extra new entries from the header, nHdrParsed is
73148 ** still not up to p2, that means that the record has fewer than p2
73149 ** columns. So the result will be either the default value or a NULL.
73150 */
73151 if( pC->nHdrParsed<=p2 ){
73152 if( pOp->p4type==P4_MEM ){
@@ -73266,11 +73432,11 @@
73266 u8 *zNewRecord; /* A buffer to hold the data for the new record */
73267 Mem *pRec; /* The new record */
73268 u64 nData; /* Number of bytes of data space */
73269 int nHdr; /* Number of bytes of header space */
73270 i64 nByte; /* Data space required for this record */
73271 int nZero; /* Number of zero bytes at the end of the record */
73272 int nVarint; /* Number of bytes in a varint */
73273 u32 serial_type; /* Type field */
73274 Mem *pData0; /* First field to be combined into the record */
73275 Mem *pLast; /* Last field of the record */
73276 int nField; /* Number of fields in the record */
@@ -73358,11 +73524,11 @@
73358 nVarint = sqlite3VarintLen(nHdr);
73359 nHdr += nVarint;
73360 if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
73361 }
73362 nByte = nHdr+nData;
73363 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
73364 goto too_big;
73365 }
73366
73367 /* Make sure the output register has a buffer large enough to store
73368 ** the new record. The output register (pOp->p3) is not allowed to
@@ -73409,18 +73575,19 @@
73409 **
73410 ** Store the number of entries (an integer value) in the table or index
73411 ** opened by cursor P1 in register P2
73412 */
73413 #ifndef SQLITE_OMIT_BTREECOUNT
73414 case OP_Count: { /* out2-prerelease */
73415 i64 nEntry;
73416 BtCursor *pCrsr;
73417
73418 pCrsr = p->apCsr[pOp->p1]->pCursor;
73419 assert( pCrsr );
73420 nEntry = 0; /* Not needed. Only used to silence a warning. */
73421 rc = sqlite3BtreeCount(pCrsr, &nEntry);
 
73422 pOut->u.i = nEntry;
73423 break;
73424 }
73425 #endif
73426
@@ -73530,11 +73697,11 @@
73530 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
73531 goto vdbe_return;
73532 }
73533 db->autoCommit = 1;
73534 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73535 p->pc = pc;
73536 db->autoCommit = 0;
73537 p->rc = rc = SQLITE_BUSY;
73538 goto vdbe_return;
73539 }
73540 db->isTransactionSavepoint = 0;
@@ -73589,11 +73756,11 @@
73589 }else{
73590 db->nDeferredCons = pSavepoint->nDeferredCons;
73591 db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
73592 }
73593
73594 if( !isTransaction ){
73595 rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
73596 if( rc!=SQLITE_OK ) goto abort_due_to_error;
73597 }
73598 }
73599 }
@@ -73649,11 +73816,11 @@
73649 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
73650 goto vdbe_return;
73651 }else{
73652 db->autoCommit = (u8)desiredAutoCommit;
73653 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73654 p->pc = pc;
73655 db->autoCommit = (u8)(1-desiredAutoCommit);
73656 p->rc = rc = SQLITE_BUSY;
73657 goto vdbe_return;
73658 }
73659 }
@@ -73726,11 +73893,11 @@
73726 pBt = db->aDb[pOp->p1].pBt;
73727
73728 if( pBt ){
73729 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
73730 if( rc==SQLITE_BUSY ){
73731 p->pc = pc;
73732 p->rc = rc = SQLITE_BUSY;
73733 goto vdbe_return;
73734 }
73735 if( rc!=SQLITE_OK ){
73736 goto abort_due_to_error;
@@ -73805,11 +73972,11 @@
73805 **
73806 ** There must be a read-lock on the database (either a transaction
73807 ** must be started or there must be an open cursor) before
73808 ** executing this instruction.
73809 */
73810 case OP_ReadCookie: { /* out2-prerelease */
73811 int iMeta;
73812 int iDb;
73813 int iCookie;
73814
73815 assert( p->bIsReader );
@@ -73819,10 +73986,11 @@
73819 assert( iDb>=0 && iDb<db->nDb );
73820 assert( db->aDb[iDb].pBt!=0 );
73821 assert( DbMaskTest(p->btreeMask, iDb) );
73822
73823 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
 
73824 pOut->u.i = iMeta;
73825 break;
73826 }
73827
73828 /* Opcode: SetCookie P1 P2 P3 * *
@@ -74140,11 +74308,11 @@
74140 VdbeCursor *pC;
74141 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74142 pC = p->apCsr[pOp->p1];
74143 assert( pC->pSorter );
74144 if( (pC->seqCount++)==0 ){
74145 pc = pOp->p2 - 1;
74146 }
74147 break;
74148 }
74149
74150 /* Opcode: OpenPseudo P1 P2 P3 * *
@@ -74317,11 +74485,11 @@
74317 ** loss of information, then special processing is required... */
74318 if( (pIn3->flags & MEM_Int)==0 ){
74319 if( (pIn3->flags & MEM_Real)==0 ){
74320 /* If the P3 value cannot be converted into any kind of a number,
74321 ** then the seek is not possible, so jump to P2 */
74322 pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
74323 break;
74324 }
74325
74326 /* If the approximation iKey is larger than the actual real search
74327 ** term, substitute >= for > and < for <=. e.g. if the search term
@@ -74408,11 +74576,11 @@
74408 }
74409 }
74410 assert( pOp->p2>0 );
74411 VdbeBranchTaken(res!=0,2);
74412 if( res ){
74413 pc = pOp->p2 - 1;
74414 }
74415 break;
74416 }
74417
74418 /* Opcode: Seek P1 P2 * * *
@@ -74502,10 +74670,11 @@
74502 */
74503 case OP_NoConflict: /* jump, in3 */
74504 case OP_NotFound: /* jump, in3 */
74505 case OP_Found: { /* jump, in3 */
74506 int alreadyExists;
 
74507 int ii;
74508 VdbeCursor *pC;
74509 int res;
74510 char *pFree;
74511 UnpackedRecord *pIdxKey;
@@ -74524,11 +74693,11 @@
74524 pC->seekOp = pOp->opcode;
74525 #endif
74526 pIn3 = &aMem[pOp->p3];
74527 assert( pC->pCursor!=0 );
74528 assert( pC->isTable==0 );
74529 pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
74530 if( pOp->p4.i>0 ){
74531 r.pKeyInfo = pC->pKeyInfo;
74532 r.nField = (u16)pOp->p4.i;
74533 r.aMem = pIn3;
74534 for(ii=0; ii<r.nField; ii++){
@@ -74547,25 +74716,24 @@
74547 assert( pIn3->flags & MEM_Blob );
74548 ExpandBlob(pIn3);
74549 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
74550 }
74551 pIdxKey->default_rc = 0;
 
74552 if( pOp->opcode==OP_NoConflict ){
74553 /* For the OP_NoConflict opcode, take the jump if any of the
74554 ** input fields are NULL, since any key with a NULL will not
74555 ** conflict */
74556 for(ii=0; ii<pIdxKey->nField; ii++){
74557 if( pIdxKey->aMem[ii].flags & MEM_Null ){
74558 pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
74559 break;
74560 }
74561 }
74562 }
74563 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
74564 if( pOp->p4.i==0 ){
74565 sqlite3DbFree(db, pFree);
74566 }
74567 if( rc!=SQLITE_OK ){
74568 break;
74569 }
74570 pC->seekResult = res;
74571 alreadyExists = (res==0);
@@ -74572,14 +74740,14 @@
74572 pC->nullRow = 1-alreadyExists;
74573 pC->deferredMoveto = 0;
74574 pC->cacheStatus = CACHE_STALE;
74575 if( pOp->opcode==OP_Found ){
74576 VdbeBranchTaken(alreadyExists!=0,2);
74577 if( alreadyExists ) pc = pOp->p2 - 1;
74578 }else{
74579 VdbeBranchTaken(alreadyExists==0,2);
74580 if( !alreadyExists ) pc = pOp->p2 - 1;
74581 }
74582 break;
74583 }
74584
74585 /* Opcode: NotExists P1 P2 P3 * *
@@ -74624,14 +74792,12 @@
74624 pC->movetoTarget = iKey; /* Used by OP_Delete */
74625 pC->nullRow = 0;
74626 pC->cacheStatus = CACHE_STALE;
74627 pC->deferredMoveto = 0;
74628 VdbeBranchTaken(res!=0,2);
74629 if( res!=0 ){
74630 pc = pOp->p2 - 1;
74631 }
74632 pC->seekResult = res;
 
74633 break;
74634 }
74635
74636 /* Opcode: Sequence P1 P2 * * *
74637 ** Synopsis: r[P2]=cursor[P1].ctr++
@@ -74639,13 +74805,14 @@
74639 ** Find the next available sequence number for cursor P1.
74640 ** Write the sequence number into register P2.
74641 ** The sequence number on the cursor is incremented after this
74642 ** instruction.
74643 */
74644 case OP_Sequence: { /* out2-prerelease */
74645 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74646 assert( p->apCsr[pOp->p1]!=0 );
 
74647 pOut->u.i = p->apCsr[pOp->p1]->seqCount++;
74648 break;
74649 }
74650
74651
@@ -74662,20 +74829,21 @@
74662 ** allowed to be less than this value. When this value reaches its maximum,
74663 ** an SQLITE_FULL error is generated. The P3 register is updated with the '
74664 ** generated record number. This P3 mechanism is used to help implement the
74665 ** AUTOINCREMENT feature.
74666 */
74667 case OP_NewRowid: { /* out2-prerelease */
74668 i64 v; /* The new rowid */
74669 VdbeCursor *pC; /* Cursor of table to get the new rowid */
74670 int res; /* Result of an sqlite3BtreeLast() */
74671 int cnt; /* Counter to limit the number of searches */
74672 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
74673 VdbeFrame *pFrame; /* Root frame of VDBE */
74674
74675 v = 0;
74676 res = 0;
 
74677 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74678 pC = p->apCsr[pOp->p1];
74679 assert( pC!=0 );
74680 if( NEVER(pC->pCursor==0) ){
74681 /* The zero initialization above is all that is needed */
@@ -74985,13 +75153,11 @@
74985 pIn3 = &aMem[pOp->p3];
74986 nKeyCol = pOp->p4.i;
74987 res = 0;
74988 rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res);
74989 VdbeBranchTaken(res!=0,2);
74990 if( res ){
74991 pc = pOp->p2-1;
74992 }
74993 break;
74994 };
74995
74996 /* Opcode: SorterData P1 P2 P3 * *
74997 ** Synopsis: r[P2]=data
@@ -75116,16 +75282,17 @@
75116 **
75117 ** P1 can be either an ordinary table or a virtual table. There used to
75118 ** be a separate OP_VRowid opcode for use with virtual tables, but this
75119 ** one opcode now works for both table types.
75120 */
75121 case OP_Rowid: { /* out2-prerelease */
75122 VdbeCursor *pC;
75123 i64 v;
75124 sqlite3_vtab *pVtab;
75125 const sqlite3_module *pModule;
75126
 
75127 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
75128 pC = p->apCsr[pOp->p1];
75129 assert( pC!=0 );
75130 assert( pC->pseudoTableReg==0 || pC->nullRow );
75131 if( pC->nullRow ){
@@ -75174,11 +75341,11 @@
75174 sqlite3BtreeClearCursor(pC->pCursor);
75175 }
75176 break;
75177 }
75178
75179 /* Opcode: Last P1 P2 * * *
75180 **
75181 ** The next use of the Rowid or Column or Prev instruction for P1
75182 ** will refer to the last entry in the database table or index.
75183 ** If the table or index is empty and P2>0, then jump immediately to P2.
75184 ** If P2 is 0 or if the table or index is not empty, fall through
@@ -75201,16 +75368,17 @@
75201 assert( pCrsr!=0 );
75202 rc = sqlite3BtreeLast(pCrsr, &res);
75203 pC->nullRow = (u8)res;
75204 pC->deferredMoveto = 0;
75205 pC->cacheStatus = CACHE_STALE;
 
75206 #ifdef SQLITE_DEBUG
75207 pC->seekOp = OP_Last;
75208 #endif
75209 if( pOp->p2>0 ){
75210 VdbeBranchTaken(res!=0,2);
75211 if( res ) pc = pOp->p2 - 1;
75212 }
75213 break;
75214 }
75215
75216
@@ -75270,13 +75438,11 @@
75270 pC->cacheStatus = CACHE_STALE;
75271 }
75272 pC->nullRow = (u8)res;
75273 assert( pOp->p2>0 && pOp->p2<p->nOp );
75274 VdbeBranchTaken(res!=0,2);
75275 if( res ){
75276 pc = pOp->p2 - 1;
75277 }
75278 break;
75279 }
75280
75281 /* Opcode: Next P1 P2 P3 P4 P5
75282 **
@@ -75383,15 +75549,15 @@
75383 next_tail:
75384 pC->cacheStatus = CACHE_STALE;
75385 VdbeBranchTaken(res==0,2);
75386 if( res==0 ){
75387 pC->nullRow = 0;
75388 pc = pOp->p2 - 1;
75389 p->aCounter[pOp->p5]++;
75390 #ifdef SQLITE_TEST
75391 sqlite3_search_count++;
75392 #endif
 
75393 }else{
75394 pC->nullRow = 1;
75395 }
75396 goto check_for_interrupt;
75397 }
@@ -75495,15 +75661,16 @@
75495 ** the end of the index key pointed to by cursor P1. This integer should be
75496 ** the rowid of the table entry to which this index entry points.
75497 **
75498 ** See also: Rowid, MakeRecord.
75499 */
75500 case OP_IdxRowid: { /* out2-prerelease */
75501 BtCursor *pCrsr;
75502 VdbeCursor *pC;
75503 i64 rowid;
75504
 
75505 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
75506 pC = p->apCsr[pOp->p1];
75507 assert( pC!=0 );
75508 pCrsr = pC->pCursor;
75509 assert( pCrsr!=0 );
@@ -75612,13 +75779,11 @@
75612 }else{
75613 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
75614 res++;
75615 }
75616 VdbeBranchTaken(res>0,2);
75617 if( res>0 ){
75618 pc = pOp->p2 - 1 ;
75619 }
75620 break;
75621 }
75622
75623 /* Opcode: Destroy P1 P2 P3 * *
75624 **
@@ -75638,15 +75803,16 @@
75638 ** the last one in the database) then a zero is stored in register P2.
75639 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
75640 **
75641 ** See also: Clear
75642 */
75643 case OP_Destroy: { /* out2-prerelease */
75644 int iMoved;
75645 int iDb;
75646
75647 assert( p->readOnly==0 );
 
75648 pOut->flags = MEM_Null;
75649 if( db->nVdbeRead > db->nVDestroy+1 ){
75650 rc = SQLITE_LOCKED;
75651 p->errorAction = OE_Abort;
75652 }else{
@@ -75751,16 +75917,17 @@
75751 ** P1>1. Write the root page number of the new table into
75752 ** register P2.
75753 **
75754 ** See documentation on OP_CreateTable for additional information.
75755 */
75756 case OP_CreateIndex: /* out2-prerelease */
75757 case OP_CreateTable: { /* out2-prerelease */
75758 int pgno;
75759 int flags;
75760 Db *pDb;
75761
 
75762 pgno = 0;
75763 assert( pOp->p1>=0 && pOp->p1<db->nDb );
75764 assert( DbMaskTest(p->btreeMask, pOp->p1) );
75765 assert( p->readOnly==0 );
75766 pDb = &db->aDb[pOp->p1];
@@ -75982,16 +76149,16 @@
75982 if( (pIn1->flags & MEM_RowSet)==0
75983 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
75984 ){
75985 /* The boolean index is empty */
75986 sqlite3VdbeMemSetNull(pIn1);
75987 pc = pOp->p2 - 1;
75988 VdbeBranchTaken(1,2);
 
75989 }else{
75990 /* A value was pulled from the index */
75991 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
75992 VdbeBranchTaken(0,2);
 
75993 }
75994 goto check_for_interrupt;
75995 }
75996
75997 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -76038,14 +76205,11 @@
76038 assert( pOp->p4type==P4_INT32 );
76039 assert( iSet==-1 || iSet>=0 );
76040 if( iSet ){
76041 exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i);
76042 VdbeBranchTaken(exists!=0,2);
76043 if( exists ){
76044 pc = pOp->p2 - 1;
76045 break;
76046 }
76047 }
76048 if( iSet>=0 ){
76049 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
76050 }
76051 break;
@@ -76130,11 +76294,11 @@
76130 pRt->u.pFrame = pFrame;
76131
76132 pFrame->v = p;
76133 pFrame->nChildMem = nMem;
76134 pFrame->nChildCsr = pProgram->nCsr;
76135 pFrame->pc = pc;
76136 pFrame->aMem = p->aMem;
76137 pFrame->nMem = p->nMem;
76138 pFrame->apCsr = p->apCsr;
76139 pFrame->nCursor = p->nCursor;
76140 pFrame->aOp = p->aOp;
@@ -76153,11 +76317,11 @@
76153 }
76154 }else{
76155 pFrame = pRt->u.pFrame;
76156 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
76157 assert( pProgram->nCsr==pFrame->nChildCsr );
76158 assert( pc==pFrame->pc );
76159 }
76160
76161 p->nFrame++;
76162 pFrame->pParent = p->pFrame;
76163 pFrame->lastRowid = lastRowid;
@@ -76174,11 +76338,11 @@
76174 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
76175 p->nOnceFlag = pProgram->nOnce;
76176 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
76177 p->anExec = 0;
76178 #endif
76179 pc = -1;
76180 memset(p->aOnceFlag, 0, p->nOnceFlag);
76181
76182 break;
76183 }
76184
@@ -76192,13 +76356,14 @@
76192 **
76193 ** The address of the cell in the parent frame is determined by adding
76194 ** the value of the P1 argument to the value of the P1 argument to the
76195 ** calling OP_Program instruction.
76196 */
76197 case OP_Param: { /* out2-prerelease */
76198 VdbeFrame *pFrame;
76199 Mem *pIn;
 
76200 pFrame = p->pFrame;
76201 pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
76202 sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem);
76203 break;
76204 }
@@ -76238,14 +76403,14 @@
76238 ** (immediate foreign key constraint violations).
76239 */
76240 case OP_FkIfZero: { /* jump */
76241 if( pOp->p1 ){
76242 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
76243 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
76244 }else{
76245 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
76246 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
76247 }
76248 break;
76249 }
76250 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
76251
@@ -76292,13 +76457,11 @@
76292 */
76293 case OP_IfPos: { /* jump, in1 */
76294 pIn1 = &aMem[pOp->p1];
76295 assert( pIn1->flags&MEM_Int );
76296 VdbeBranchTaken( pIn1->u.i>0, 2);
76297 if( pIn1->u.i>0 ){
76298 pc = pOp->p2 - 1;
76299 }
76300 break;
76301 }
76302
76303 /* Opcode: IfNeg P1 P2 P3 * *
76304 ** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2
@@ -76309,13 +76472,11 @@
76309 case OP_IfNeg: { /* jump, in1 */
76310 pIn1 = &aMem[pOp->p1];
76311 assert( pIn1->flags&MEM_Int );
76312 pIn1->u.i += pOp->p3;
76313 VdbeBranchTaken(pIn1->u.i<0, 2);
76314 if( pIn1->u.i<0 ){
76315 pc = pOp->p2 - 1;
76316 }
76317 break;
76318 }
76319
76320 /* Opcode: IfNotZero P1 P2 P3 * *
76321 ** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2
@@ -76328,11 +76489,11 @@
76328 pIn1 = &aMem[pOp->p1];
76329 assert( pIn1->flags&MEM_Int );
76330 VdbeBranchTaken(pIn1->u.i<0, 2);
76331 if( pIn1->u.i ){
76332 pIn1->u.i += pOp->p3;
76333 pc = pOp->p2 - 1;
76334 }
76335 break;
76336 }
76337
76338 /* Opcode: DecrJumpZero P1 P2 * * *
@@ -76344,13 +76505,11 @@
76344 case OP_DecrJumpZero: { /* jump, in1 */
76345 pIn1 = &aMem[pOp->p1];
76346 assert( pIn1->flags&MEM_Int );
76347 pIn1->u.i--;
76348 VdbeBranchTaken(pIn1->u.i==0, 2);
76349 if( pIn1->u.i==0 ){
76350 pc = pOp->p2 - 1;
76351 }
76352 break;
76353 }
76354
76355
76356 /* Opcode: JumpZeroIncr P1 P2 * * *
@@ -76362,13 +76521,11 @@
76362 */
76363 case OP_JumpZeroIncr: { /* jump, in1 */
76364 pIn1 = &aMem[pOp->p1];
76365 assert( pIn1->flags&MEM_Int );
76366 VdbeBranchTaken(pIn1->u.i==0, 2);
76367 if( (pIn1->u.i++)==0 ){
76368 pc = pOp->p2 - 1;
76369 }
76370 break;
76371 }
76372
76373 /* Opcode: AggStep * P2 P3 P4 P5
76374 ** Synopsis: accum=r[P3] step(r[P2@P5])
@@ -76406,11 +76563,11 @@
76406 pMem->n++;
76407 sqlite3VdbeMemInit(&t, db, MEM_Null);
76408 ctx.pOut = &t;
76409 ctx.isError = 0;
76410 ctx.pVdbe = p;
76411 ctx.iOp = pc;
76412 ctx.skipFlag = 0;
76413 (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
76414 if( ctx.isError ){
76415 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t));
76416 rc = ctx.isError;
@@ -76501,19 +76658,20 @@
76501 **
76502 ** If changing into or out of WAL mode the procedure is more complicated.
76503 **
76504 ** Write a string containing the final journal-mode to register P2.
76505 */
76506 case OP_JournalMode: { /* out2-prerelease */
76507 Btree *pBt; /* Btree to change journal mode of */
76508 Pager *pPager; /* Pager associated with pBt */
76509 int eNew; /* New journal mode */
76510 int eOld; /* The old journal mode */
76511 #ifndef SQLITE_OMIT_WAL
76512 const char *zFilename; /* Name of database file for pPager */
76513 #endif
76514
 
76515 eNew = pOp->p3;
76516 assert( eNew==PAGER_JOURNALMODE_DELETE
76517 || eNew==PAGER_JOURNALMODE_TRUNCATE
76518 || eNew==PAGER_JOURNALMODE_PERSIST
76519 || eNew==PAGER_JOURNALMODE_OFF
@@ -76585,11 +76743,10 @@
76585 if( rc ){
76586 eNew = eOld;
76587 }
76588 eNew = sqlite3PagerSetJournalMode(pPager, eNew);
76589
76590 pOut = &aMem[pOp->p2];
76591 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
76592 pOut->z = (char *)sqlite3JournalModename(eNew);
76593 pOut->n = sqlite3Strlen30(pOut->z);
76594 pOut->enc = SQLITE_UTF8;
76595 sqlite3VdbeChangeEncoding(pOut, encoding);
@@ -76626,12 +76783,12 @@
76626 assert( p->readOnly==0 );
76627 pBt = db->aDb[pOp->p1].pBt;
76628 rc = sqlite3BtreeIncrVacuum(pBt);
76629 VdbeBranchTaken(rc==SQLITE_DONE,2);
76630 if( rc==SQLITE_DONE ){
76631 pc = pOp->p2 - 1;
76632 rc = SQLITE_OK;
 
76633 }
76634 break;
76635 }
76636 #endif
76637
@@ -76780,12 +76937,13 @@
76780 pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
76781 if( pCur ){
76782 pCur->pVtabCursor = pVtabCursor;
76783 pVtab->nRef++;
76784 }else{
76785 db->mallocFailed = 1;
76786 pModule->xClose(pVtabCursor);
 
76787 }
76788 }
76789 break;
76790 }
76791 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -76837,29 +76995,23 @@
76837 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
76838 nArg = (int)pArgc->u.i;
76839 iQuery = (int)pQuery->u.i;
76840
76841 /* Invoke the xFilter method */
76842 {
76843 res = 0;
76844 apArg = p->apArg;
76845 for(i = 0; i<nArg; i++){
76846 apArg[i] = &pArgc[i+1];
76847 }
76848
76849 rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
76850 sqlite3VtabImportErrmsg(p, pVtab);
76851 if( rc==SQLITE_OK ){
76852 res = pModule->xEof(pVtabCursor);
76853 }
76854 VdbeBranchTaken(res!=0,2);
76855 if( res ){
76856 pc = pOp->p2 - 1;
76857 }
76858 }
76859 pCur->nullRow = 0;
76860
 
76861 break;
76862 }
76863 #endif /* SQLITE_OMIT_VIRTUALTABLE */
76864
76865 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76942,11 +77094,11 @@
76942 res = pModule->xEof(pCur->pVtabCursor);
76943 }
76944 VdbeBranchTaken(!res,2);
76945 if( !res ){
76946 /* If there is data, jump to P2 */
76947 pc = pOp->p2 - 1;
76948 }
76949 goto check_for_interrupt;
76950 }
76951 #endif /* SQLITE_OMIT_VIRTUALTABLE */
76952
@@ -77065,11 +77217,12 @@
77065 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
77066 /* Opcode: Pagecount P1 P2 * * *
77067 **
77068 ** Write the current number of pages in database P1 to memory cell P2.
77069 */
77070 case OP_Pagecount: { /* out2-prerelease */
 
77071 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
77072 break;
77073 }
77074 #endif
77075
@@ -77081,14 +77234,15 @@
77081 ** Do not let the maximum page count fall below the current page count and
77082 ** do not change the maximum page count value if P3==0.
77083 **
77084 ** Store the maximum page count after the change in register P2.
77085 */
77086 case OP_MaxPgcnt: { /* out2-prerelease */
77087 unsigned int newMax;
77088 Btree *pBt;
77089
 
77090 pBt = db->aDb[pOp->p1].pBt;
77091 newMax = 0;
77092 if( pOp->p3 ){
77093 newMax = sqlite3BtreeLastPage(pBt);
77094 if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3;
@@ -77113,13 +77267,10 @@
77113 */
77114 case OP_Init: { /* jump */
77115 char *zTrace;
77116 char *z;
77117
77118 if( pOp->p2 ){
77119 pc = pOp->p2 - 1;
77120 }
77121 #ifndef SQLITE_OMIT_TRACE
77122 if( db->xTrace
77123 && !p->doingRerun
77124 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
77125 ){
@@ -77143,10 +77294,11 @@
77143 ){
77144 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
77145 }
77146 #endif /* SQLITE_DEBUG */
77147 #endif /* SQLITE_OMIT_TRACE */
 
77148 break;
77149 }
77150
77151
77152 /* Opcode: Noop * * * * *
@@ -77174,31 +77326,31 @@
77174 }
77175
77176 #ifdef VDBE_PROFILE
77177 {
77178 u64 endTime = sqlite3Hwtime();
77179 if( endTime>start ) pOp->cycles += endTime - start;
77180 pOp->cnt++;
77181 }
77182 #endif
77183
77184 /* The following code adds nothing to the actual functionality
77185 ** of the program. It is only here for testing and debugging.
77186 ** On the other hand, it does burn CPU cycles every time through
77187 ** the evaluator loop. So we can leave it out when NDEBUG is defined.
77188 */
77189 #ifndef NDEBUG
77190 assert( pc>=-1 && pc<p->nOp );
77191
77192 #ifdef SQLITE_DEBUG
77193 if( db->flags & SQLITE_VdbeTrace ){
77194 if( rc!=0 ) printf("rc=%d\n",rc);
77195 if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){
77196 registerTrace(pOp->p2, &aMem[pOp->p2]);
77197 }
77198 if( pOp->opflags & OPFLG_OUT3 ){
77199 registerTrace(pOp->p3, &aMem[pOp->p3]);
77200 }
77201 }
77202 #endif /* SQLITE_DEBUG */
77203 #endif /* NDEBUG */
77204 } /* The end of the for(;;) loop the loops through opcodes */
@@ -77209,11 +77361,11 @@
77209 vdbe_error_halt:
77210 assert( rc );
77211 p->rc = rc;
77212 testcase( sqlite3GlobalConfig.xLog!=0 );
77213 sqlite3_log(rc, "statement aborts at %d: [%s] %s",
77214 pc, p->zSql, p->zErrMsg);
77215 sqlite3VdbeHalt(p);
77216 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
77217 rc = SQLITE_ERROR;
77218 if( resetSchemaOnFault>0 ){
77219 sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
@@ -78035,20 +78187,23 @@
78035 **
78036 ** In both cases, the effects of the main thread seeing (bDone==0) even
78037 ** after the thread has finished are not dire. So we don't worry about
78038 ** memory barriers and such here.
78039 */
 
78040 struct SortSubtask {
78041 SQLiteThread *pThread; /* Background thread, if any */
78042 int bDone; /* Set if thread is finished but not joined */
78043 VdbeSorter *pSorter; /* Sorter that owns this sub-task */
78044 UnpackedRecord *pUnpacked; /* Space to unpack a record */
78045 SorterList list; /* List for thread to write to a PMA */
78046 int nPMA; /* Number of PMAs currently in file */
 
78047 SorterFile file; /* Temp file for level-0 PMAs */
78048 SorterFile file2; /* Space for other PMAs */
78049 };
 
78050
78051 /*
78052 ** Main sorter structure. A single instance of this is allocated for each
78053 ** sorter cursor created by the VDBE.
78054 **
@@ -78072,12 +78227,16 @@
78072 int nMemory; /* Size of list.aMemory allocation in bytes */
78073 u8 bUsePMA; /* True if one or more PMAs created */
78074 u8 bUseThreads; /* True to use background threads */
78075 u8 iPrev; /* Previous thread used to flush PMA */
78076 u8 nTask; /* Size of aTask[] array */
 
78077 SortSubtask aTask[1]; /* One or more subtasks */
78078 };
 
 
 
78079
78080 /*
78081 ** An instance of the following object is used to read records out of a
78082 ** PMA, in sorted order. The next key to be read is cached in nKey/aKey.
78083 ** aKey might point into aMap or into aBuffer. If neither of those locations
@@ -78486,35 +78645,165 @@
78486 rc = vdbePmaReaderNext(pReadr);
78487 }
78488 return rc;
78489 }
78490
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78491
78492 /*
78493 ** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2,
78494 ** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences
78495 ** used by the comparison. Return the result of the comparison.
78496 **
78497 ** Before returning, object (pTask->pUnpacked) is populated with the
78498 ** unpacked version of key2. Or, if pKey2 is passed a NULL pointer, then it
78499 ** is assumed that the (pTask->pUnpacked) structure already contains the
78500 ** unpacked key to use as key2.
78501 **
78502 ** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set
78503 ** to SQLITE_NOMEM.
78504 */
78505 static int vdbeSorterCompare(
78506 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
 
78507 const void *pKey1, int nKey1, /* Left side of comparison */
78508 const void *pKey2, int nKey2 /* Right side of comparison */
78509 ){
78510 UnpackedRecord *r2 = pTask->pUnpacked;
78511 if( pKey2 ){
78512 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
 
78513 }
78514 return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
78515 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78516
78517 /*
78518 ** Initialize the temporary index cursor just opened as a sorter cursor.
78519 **
78520 ** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField)
@@ -78579,13 +78868,17 @@
78579 rc = SQLITE_NOMEM;
78580 }else{
78581 pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
78582 memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
78583 pKeyInfo->db = 0;
78584 if( nField && nWorker==0 ) pKeyInfo->nField = nField;
 
 
 
78585 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
78586 pSorter->nTask = nWorker + 1;
 
78587 pSorter->bUseThreads = (pSorter->nTask>1);
78588 pSorter->db = db;
78589 for(i=0; i<pSorter->nTask; i++){
78590 SortSubtask *pTask = &pSorter->aTask[i];
78591 pTask->pSorter = pSorter;
@@ -78607,10 +78900,16 @@
78607 pSorter->nMemory = pgsz;
78608 pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
78609 if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM;
78610 }
78611 }
 
 
 
 
 
 
78612 }
78613
78614 return rc;
78615 }
78616 #undef nWorker /* Defined at the top of this function */
@@ -78631,34 +78930,28 @@
78631 ** Free all resources owned by the object indicated by argument pTask. All
78632 ** fields of *pTask are zeroed before returning.
78633 */
78634 static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){
78635 sqlite3DbFree(db, pTask->pUnpacked);
78636 pTask->pUnpacked = 0;
78637 #if SQLITE_MAX_WORKER_THREADS>0
78638 /* pTask->list.aMemory can only be non-zero if it was handed memory
78639 ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */
78640 if( pTask->list.aMemory ){
78641 sqlite3_free(pTask->list.aMemory);
78642 pTask->list.aMemory = 0;
78643 }else
78644 #endif
78645 {
78646 assert( pTask->list.aMemory==0 );
78647 vdbeSorterRecordFree(0, pTask->list.pList);
78648 }
78649 pTask->list.pList = 0;
78650 if( pTask->file.pFd ){
78651 sqlite3OsCloseFree(pTask->file.pFd);
78652 pTask->file.pFd = 0;
78653 pTask->file.iEof = 0;
78654 }
78655 if( pTask->file2.pFd ){
78656 sqlite3OsCloseFree(pTask->file2.pFd);
78657 pTask->file2.pFd = 0;
78658 pTask->file2.iEof = 0;
78659 }
 
78660 }
78661
78662 #ifdef SQLITE_DEBUG_SORTER_THREADS
78663 static void vdbeSorterWorkDebug(SortSubtask *pTask, const char *zEvent){
78664 i64 t;
@@ -78834,10 +79127,11 @@
78834 vdbeMergeEngineFree(pSorter->pMerger);
78835 pSorter->pMerger = 0;
78836 for(i=0; i<pSorter->nTask; i++){
78837 SortSubtask *pTask = &pSorter->aTask[i];
78838 vdbeSortSubtaskCleanup(db, pTask);
 
78839 }
78840 if( pSorter->list.aMemory==0 ){
78841 vdbeSorterRecordFree(0, pSorter->list.pList);
78842 }
78843 pSorter->list.pList = 0;
@@ -78943,31 +79237,45 @@
78943 SorterRecord *p2, /* Second list to merge */
78944 SorterRecord **ppOut /* OUT: Head of merged list */
78945 ){
78946 SorterRecord *pFinal = 0;
78947 SorterRecord **pp = &pFinal;
78948 void *pVal2 = p2 ? SRVAL(p2) : 0;
78949
78950 while( p1 && p2 ){
78951 int res;
78952 res = vdbeSorterCompare(pTask, SRVAL(p1), p1->nVal, pVal2, p2->nVal);
 
 
 
78953 if( res<=0 ){
78954 *pp = p1;
78955 pp = &p1->u.pNext;
78956 p1 = p1->u.pNext;
78957 pVal2 = 0;
78958 }else{
78959 *pp = p2;
78960 pp = &p2->u.pNext;
78961 p2 = p2->u.pNext;
78962 if( p2==0 ) break;
78963 pVal2 = SRVAL(p2);
78964 }
78965 }
78966 *pp = p1 ? p1 : p2;
78967 *ppOut = pFinal;
78968 }
 
 
 
 
 
 
 
 
 
 
 
 
 
78969
78970 /*
78971 ** Sort the linked list of records headed at pTask->pList. Return
78972 ** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if
78973 ** an error occurs.
@@ -78979,16 +79287,18 @@
78979 int rc;
78980
78981 rc = vdbeSortAllocUnpacked(pTask);
78982 if( rc!=SQLITE_OK ) return rc;
78983
 
 
 
78984 aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *));
78985 if( !aSlot ){
78986 return SQLITE_NOMEM;
78987 }
78988
78989 p = pList->pList;
78990 while( p ){
78991 SorterRecord *pNext;
78992 if( pList->aMemory ){
78993 if( (u8*)p==pList->aMemory ){
78994 pNext = 0;
@@ -79198,28 +79508,27 @@
79198 /* Update contents of aTree[] */
79199 if( rc==SQLITE_OK ){
79200 int i; /* Index of aTree[] to recalculate */
79201 PmaReader *pReadr1; /* First PmaReader to compare */
79202 PmaReader *pReadr2; /* Second PmaReader to compare */
79203 u8 *pKey2; /* To pReadr2->aKey, or 0 if record cached */
79204
79205 /* Find the first two PmaReaders to compare. The one that was just
79206 ** advanced (iPrev) and the one next to it in the array. */
79207 pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)];
79208 pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)];
79209 pKey2 = pReadr2->aKey;
79210
79211 for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){
79212 /* Compare pReadr1 and pReadr2. Store the result in variable iRes. */
79213 int iRes;
79214 if( pReadr1->pFd==0 ){
79215 iRes = +1;
79216 }else if( pReadr2->pFd==0 ){
79217 iRes = -1;
79218 }else{
79219 iRes = vdbeSorterCompare(pTask,
79220 pReadr1->aKey, pReadr1->nKey, pKey2, pReadr2->nKey
79221 );
79222 }
79223
79224 /* If pReadr1 contained the smaller value, set aTree[i] to its index.
79225 ** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this
@@ -79237,13 +79546,13 @@
79237 ** is sorted from oldest to newest, so pReadr1 contains older values
79238 ** than pReadr2 iff (pReadr1<pReadr2). */
79239 if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){
79240 pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr);
79241 pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79242 pKey2 = pReadr2->aKey;
79243 }else{
79244 if( pReadr1->pFd ) pKey2 = 0;
79245 pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr);
79246 pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79247 }
79248 }
79249 *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0);
@@ -79346,10 +79655,20 @@
79346 SorterRecord *pNew; /* New list element */
79347
79348 int bFlush; /* True to flush contents of memory to PMA */
79349 int nReq; /* Bytes of memory required */
79350 int nPMA; /* Bytes of PMA space required */
 
 
 
 
 
 
 
 
 
 
79351
79352 assert( pSorter );
79353
79354 /* Figure out whether or not the current contents of memory should be
79355 ** flushed to a PMA before continuing. If so, do so.
@@ -79611,14 +79930,16 @@
79611 if( p1->pFd==0 ){
79612 iRes = i2;
79613 }else if( p2->pFd==0 ){
79614 iRes = i1;
79615 }else{
 
 
79616 int res;
79617 assert( pMerger->pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
79618 res = vdbeSorterCompare(
79619 pMerger->pTask, p1->aKey, p1->nKey, p2->aKey, p2->nKey
79620 );
79621 if( res<=0 ){
79622 iRes = i1;
79623 }else{
79624 iRes = i2;
@@ -79638,15 +79959,16 @@
79638 */
79639 #define INCRINIT_NORMAL 0
79640 #define INCRINIT_TASK 1
79641 #define INCRINIT_ROOT 2
79642
79643 /* Forward reference.
79644 ** The vdbeIncrMergeInit() and vdbePmaReaderIncrMergeInit() routines call each
79645 ** other (when building a merge tree).
 
79646 */
79647 static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode);
79648
79649 /*
79650 ** Initialize the MergeEngine object passed as the second argument. Once this
79651 ** function returns, the first key of merged data may be read from the
79652 ** MergeEngine object in the usual fashion.
@@ -79689,11 +80011,11 @@
79689 ** the main thread to fill its buffer. So calling PmaReaderNext()
79690 ** on this PmaReader before any of the multi-threaded PmaReaders takes
79691 ** better advantage of multi-processor hardware. */
79692 rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]);
79693 }else{
79694 rc = vdbePmaReaderIncrMergeInit(&pMerger->aReadr[i], INCRINIT_NORMAL);
79695 }
79696 if( rc!=SQLITE_OK ) return rc;
79697 }
79698
79699 for(i=pMerger->nTree-1; i>0; i--){
@@ -79701,21 +80023,19 @@
79701 }
79702 return pTask->pUnpacked->errCode;
79703 }
79704
79705 /*
79706 ** Initialize the IncrMerge field of a PmaReader.
79707 **
79708 ** If the PmaReader passed as the first argument is not an incremental-reader
79709 ** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it serves
79710 ** to open and/or initialize the temp file related fields of the IncrMerge
79711 ** object at (pReadr->pIncr).
79712 **
79713 ** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders
79714 ** in the sub-tree headed by pReadr are also initialized. Data is then loaded
79715 ** into the buffers belonging to pReadr and it is set to
79716 ** point to the first key in its range.
79717 **
79718 ** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed
79719 ** to be a multi-threaded PmaReader and this function is being called in a
79720 ** background thread. In this case all PmaReaders in the sub-tree are
79721 ** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to
@@ -79738,93 +80058,112 @@
79738 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
79739 */
79740 static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode){
79741 int rc = SQLITE_OK;
79742 IncrMerger *pIncr = pReadr->pIncr;
 
 
79743
79744 /* eMode is always INCRINIT_NORMAL in single-threaded mode */
79745 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
79746
79747 if( pIncr ){
79748 SortSubtask *pTask = pIncr->pTask;
79749 sqlite3 *db = pTask->pSorter->db;
79750
79751 rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
79752
79753 /* Set up the required files for pIncr. A multi-theaded IncrMerge object
79754 ** requires two temp files to itself, whereas a single-threaded object
79755 ** only requires a region of pTask->file2. */
79756 if( rc==SQLITE_OK ){
79757 int mxSz = pIncr->mxSz;
79758 #if SQLITE_MAX_WORKER_THREADS>0
79759 if( pIncr->bUseThread ){
79760 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
79761 if( rc==SQLITE_OK ){
79762 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
79763 }
79764 }else
79765 #endif
79766 /*if( !pIncr->bUseThread )*/{
79767 if( pTask->file2.pFd==0 ){
79768 assert( pTask->file2.iEof>0 );
79769 rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
79770 pTask->file2.iEof = 0;
79771 }
79772 if( rc==SQLITE_OK ){
79773 pIncr->aFile[1].pFd = pTask->file2.pFd;
79774 pIncr->iStartOff = pTask->file2.iEof;
79775 pTask->file2.iEof += mxSz;
79776 }
79777 }
79778 }
79779
79780 #if SQLITE_MAX_WORKER_THREADS>0
79781 if( rc==SQLITE_OK && pIncr->bUseThread ){
79782 /* Use the current thread to populate aFile[1], even though this
79783 ** PmaReader is multi-threaded. The reason being that this function
79784 ** is already running in background thread pIncr->pTask->thread. */
79785 assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK );
79786 rc = vdbeIncrPopulate(pIncr);
79787 }
79788 #endif
79789
79790 if( rc==SQLITE_OK
79791 && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK)
79792 ){
79793 rc = vdbePmaReaderNext(pReadr);
79794 }
79795 }
 
79796 return rc;
79797 }
79798
79799 #if SQLITE_MAX_WORKER_THREADS>0
79800 /*
79801 ** The main routine for vdbePmaReaderIncrMergeInit() operations run in
79802 ** background threads.
79803 */
79804 static void *vdbePmaReaderBgInit(void *pCtx){
79805 PmaReader *pReader = (PmaReader*)pCtx;
79806 void *pRet = SQLITE_INT_TO_PTR(
79807 vdbePmaReaderIncrMergeInit(pReader,INCRINIT_TASK)
79808 );
79809 pReader->pIncr->pTask->bDone = 1;
79810 return pRet;
79811 }
 
79812
79813 /*
79814 ** Use a background thread to invoke vdbePmaReaderIncrMergeInit(INCRINIT_TASK)
79815 ** on the PmaReader object passed as the first argument.
79816 **
79817 ** This call will initialize the various fields of the pReadr->pIncr
79818 ** structure and, if it is a multi-threaded IncrMerger, launch a
79819 ** background thread to populate aFile[1].
 
 
 
79820 */
79821 static int vdbePmaReaderBgIncrInit(PmaReader *pReadr){
79822 void *pCtx = (void*)pReadr;
79823 return vdbeSorterCreateThread(pReadr->pIncr->pTask, vdbePmaReaderBgInit, pCtx);
 
 
 
 
 
 
 
 
 
 
 
 
 
79824 }
79825 #endif
79826
79827 /*
79828 ** Allocate a new MergeEngine object to merge the contents of nPMA level-0
79829 ** PMAs from pTask->file. If no error occurs, set *ppOut to point to
79830 ** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut
@@ -80032,10 +80371,15 @@
80032 int rc; /* Return code */
80033 SortSubtask *pTask0 = &pSorter->aTask[0];
80034 MergeEngine *pMain = 0;
80035 #if SQLITE_MAX_WORKER_THREADS
80036 sqlite3 *db = pTask0->pSorter->db;
 
 
 
 
 
80037 #endif
80038
80039 rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
80040 if( rc==SQLITE_OK ){
80041 #if SQLITE_MAX_WORKER_THREADS
@@ -80060,19 +80404,25 @@
80060 vdbeIncrMergerSetThreads(pIncr);
80061 assert( pIncr->pTask!=pLast );
80062 }
80063 }
80064 for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
 
 
 
 
 
 
 
 
 
80065 PmaReader *p = &pMain->aReadr[iTask];
80066 assert( p->pIncr==0 || p->pIncr->pTask==&pSorter->aTask[iTask] );
80067 if( p->pIncr ){
80068 if( iTask==pSorter->nTask-1 ){
80069 rc = vdbePmaReaderIncrMergeInit(p, INCRINIT_TASK);
80070 }else{
80071 rc = vdbePmaReaderBgIncrInit(p);
80072 }
80073 }
80074 }
80075 }
80076 pMain = 0;
80077 }
80078 if( rc==SQLITE_OK ){
@@ -81023,11 +81373,11 @@
81023 ** Should be transformed into:
81024 **
81025 ** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase;
81026 **
81027 ** The nSubquery parameter specifies how many levels of subquery the
81028 ** alias is removed from the original expression. The usually value is
81029 ** zero but it might be more if the alias is contained within a subquery
81030 ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION
81031 ** structures must be increased by the nSubquery amount.
81032 */
81033 static void resolveAlias(
@@ -81043,11 +81393,10 @@
81043 sqlite3 *db; /* The database connection */
81044
81045 assert( iCol>=0 && iCol<pEList->nExpr );
81046 pOrig = pEList->a[iCol].pExpr;
81047 assert( pOrig!=0 );
81048 assert( pOrig->flags & EP_Resolved );
81049 db = pParse->db;
81050 pDup = sqlite3ExprDup(db, pOrig, 0);
81051 if( pDup==0 ) return;
81052 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
81053 incrAggFunctionDepth(pDup, nSubquery);
@@ -81937,13 +82286,15 @@
81937 pNew->flags |= EP_IntValue;
81938 pNew->u.iValue = iCol;
81939 if( pItem->pExpr==pE ){
81940 pItem->pExpr = pNew;
81941 }else{
81942 assert( pItem->pExpr->op==TK_COLLATE );
81943 assert( pItem->pExpr->pLeft==pE );
81944 pItem->pExpr->pLeft = pNew;
 
 
81945 }
81946 sqlite3ExprDelete(db, pE);
81947 pItem->u.x.iOrderByCol = (u16)iCol;
81948 pItem->done = 1;
81949 }else{
@@ -82139,11 +82490,11 @@
82139 ** as if it were part of the sub-query, not the parent. This block
82140 ** moves the pOrderBy down to the sub-query. It will be moved back
82141 ** after the names have been resolved. */
82142 if( p->selFlags & SF_Converted ){
82143 Select *pSub = p->pSrc->a[0].pSelect;
82144 assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy );
82145 assert( pSub->pPrior && pSub->pOrderBy==0 );
82146 pSub->pOrderBy = p->pOrderBy;
82147 p->pOrderBy = 0;
82148 }
82149
@@ -82241,12 +82592,19 @@
82241
82242 /* Process the ORDER BY clause for singleton SELECT statements.
82243 ** The ORDER BY clause for compounds SELECT statements is handled
82244 ** below, after all of the result-sets for all of the elements of
82245 ** the compound have been resolved.
 
 
 
 
 
82246 */
82247 if( !isCompound && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") ){
 
 
82248 return WRC_Abort;
82249 }
82250 if( db->mallocFailed ){
82251 return WRC_Abort;
82252 }
@@ -83694,11 +84052,12 @@
83694 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){
83695 int i;
83696 u32 m = 0;
83697 if( pList ){
83698 for(i=0; i<pList->nExpr; i++){
83699 m |= pList->a[i].pExpr->flags;
 
83700 }
83701 }
83702 return m;
83703 }
83704
@@ -84134,11 +84493,11 @@
84134 /* Check to see if an existing table or index can be used to
84135 ** satisfy the query. This is preferable to generating a new
84136 ** ephemeral table.
84137 */
84138 p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
84139 if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
84140 sqlite3 *db = pParse->db; /* Database connection */
84141 Table *pTab; /* Table <table>. */
84142 Expr *pExpr; /* Expression <column> */
84143 i16 iCol; /* Index of column <column> */
84144 i16 iDb; /* Database idx for pTab */
@@ -84459,10 +84818,11 @@
84459 }
84460 sqlite3ExprDelete(pParse->db, pSel->pLimit);
84461 pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0,
84462 &sqlite3IntTokens[1]);
84463 pSel->iLimit = 0;
 
84464 if( sqlite3Select(pParse, pSel, &dest) ){
84465 return 0;
84466 }
84467 rReg = dest.iSDParm;
84468 ExprSetVVAProperty(pExpr, EP_NoReduce);
@@ -85824,11 +86184,11 @@
85824 sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
85825 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
85826 break;
85827 }
85828 case TK_ID: {
85829 sqlite3TreeViewLine(pView,"ID %Q", pExpr->u.zToken);
85830 break;
85831 }
85832 #ifndef SQLITE_OMIT_CAST
85833 case TK_CAST: {
85834 /* Expressions of the form: CAST(pLeft AS token) */
@@ -86459,11 +86819,11 @@
86459 if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
86460 if( combinedFlags & EP_xIsSelect ) return 2;
86461 if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
86462 if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
86463 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
86464 if( ALWAYS((combinedFlags & EP_Reduced)==0) ){
86465 if( pA->iColumn!=pB->iColumn ) return 2;
86466 if( pA->iTable!=pB->iTable
86467 && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
86468 }
86469 }
@@ -86991,10 +87351,11 @@
86991 do {
86992 z += n;
86993 n = sqlite3GetToken(z, &token);
86994 }while( token==TK_SPACE );
86995
 
86996 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
86997 if( zParent==0 ) break;
86998 sqlite3Dequote(zParent);
86999 if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
87000 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
@@ -89217,18 +89578,21 @@
89217 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
89218 }
89219 z = argv[2];
89220
89221 if( pIndex ){
 
89222 int nCol = pIndex->nKeyCol+1;
89223 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
89224 tRowcnt * const aiRowEst = pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(
89225 sizeof(tRowcnt) * nCol
89226 );
89227 if( aiRowEst==0 ) pInfo->db->mallocFailed = 1;
89228 #else
89229 tRowcnt * const aiRowEst = 0;
 
 
89230 #endif
89231 pIndex->bUnordered = 0;
89232 decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
89233 if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
89234 }else{
@@ -89887,11 +90251,11 @@
89887 }
89888
89889 sqlite3BtreeClose(pDb->pBt);
89890 pDb->pBt = 0;
89891 pDb->pSchema = 0;
89892 sqlite3ResetAllSchemasOfConnection(db);
89893 return;
89894
89895 detach_error:
89896 sqlite3_result_error(context, zErr, -1);
89897 }
@@ -89921,11 +90285,10 @@
89921 if(
89922 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
89923 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
89924 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
89925 ){
89926 pParse->nErr++;
89927 goto attach_end;
89928 }
89929
89930 #ifndef SQLITE_OMIT_AUTHORIZATION
89931 if( pAuthArg ){
@@ -90580,13 +90943,15 @@
90580 sqlite3 *db;
90581 Vdbe *v;
90582
90583 assert( pParse->pToplevel==0 );
90584 db = pParse->db;
90585 if( db->mallocFailed ) return;
90586 if( pParse->nested ) return;
90587 if( pParse->nErr ) return;
 
 
 
90588
90589 /* Begin by generating some termination code at the end of the
90590 ** vdbe program
90591 */
90592 v = sqlite3GetVdbe(pParse);
@@ -90664,11 +91029,11 @@
90664 }
90665
90666
90667 /* Get the VDBE program ready for execution
90668 */
90669 if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
90670 assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
90671 /* A minimum of one cursor is required if autoincrement is used
90672 * See ticket [a696379c1f08866] */
90673 if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
90674 sqlite3VdbeMakeReady(v, pParse);
@@ -91199,18 +91564,16 @@
91199 sqlite3 *db = pParse->db;
91200
91201 if( ALWAYS(pName2!=0) && pName2->n>0 ){
91202 if( db->init.busy ) {
91203 sqlite3ErrorMsg(pParse, "corrupt database");
91204 pParse->nErr++;
91205 return -1;
91206 }
91207 *pUnqual = pName2;
91208 iDb = sqlite3FindDb(db, pName1);
91209 if( iDb<0 ){
91210 sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
91211 pParse->nErr++;
91212 return -1;
91213 }
91214 }else{
91215 assert( db->init.iDb==0 || db->init.busy );
91216 iDb = db->init.iDb;
@@ -91365,11 +91728,11 @@
91365 pTable = sqlite3FindTable(db, zName, zDb);
91366 if( pTable ){
91367 if( !noErr ){
91368 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
91369 }else{
91370 assert( !db->init.busy );
91371 sqlite3CodeVerifySchema(pParse, iDb);
91372 }
91373 goto begin_table_error;
91374 }
91375 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
@@ -91654,11 +92017,12 @@
91654 Column *pCol;
91655
91656 p = pParse->pNewTable;
91657 if( p==0 || NEVER(p->nCol<1) ) return;
91658 pCol = &p->aCol[p->nCol-1];
91659 assert( pCol->zType==0 );
 
91660 pCol->zType = sqlite3NameFromToken(pParse->db, pType);
91661 pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst);
91662 }
91663
91664 /*
@@ -92888,10 +93252,11 @@
92888 if( db->mallocFailed ){
92889 goto exit_drop_table;
92890 }
92891 assert( pParse->nErr==0 );
92892 assert( pName->nSrc==1 );
 
92893 if( noErr ) db->suppressErr++;
92894 pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
92895 if( noErr ) db->suppressErr--;
92896
92897 if( pTab==0 ){
@@ -93201,11 +93566,12 @@
93201 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
93202 }else{
93203 addr2 = sqlite3VdbeCurrentAddr(v);
93204 }
93205 sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
93206 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
 
93207 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
93208 sqlite3ReleaseTempReg(pParse, regRecord);
93209 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
93210 sqlite3VdbeJumpHere(v, addr1);
93211
@@ -93294,12 +93660,11 @@
93294 int nExtra = 0; /* Space allocated for zExtra[] */
93295 int nExtraCol; /* Number of extra columns needed */
93296 char *zExtra = 0; /* Extra space after the Index object */
93297 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
93298
93299 assert( pParse->nErr==0 ); /* Never called with prior errors */
93300 if( db->mallocFailed || IN_DECLARE_VTAB ){
93301 goto exit_create_index;
93302 }
93303 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
93304 goto exit_create_index;
93305 }
@@ -94214,11 +94579,10 @@
94214 ** operator with A. This routine shifts that operator over to B.
94215 */
94216 SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){
94217 if( p ){
94218 int i;
94219 assert( p->a || p->nSrc==0 );
94220 for(i=p->nSrc-1; i>0; i--){
94221 p->a[i].jointype = p->a[i-1].jointype;
94222 }
94223 p->a[0].jointype = 0;
94224 }
@@ -94461,12 +94825,11 @@
94461 char *zErr;
94462 int j;
94463 StrAccum errMsg;
94464 Table *pTab = pIdx->pTable;
94465
94466 sqlite3StrAccumInit(&errMsg, 0, 0, 200);
94467 errMsg.db = pParse->db;
94468 for(j=0; j<pIdx->nKeyCol; j++){
94469 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
94470 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
94471 sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
94472 sqlite3StrAccumAppend(&errMsg, ".", 1);
@@ -96291,17 +96654,17 @@
96291 ){
96292 PrintfArguments x;
96293 StrAccum str;
96294 const char *zFormat;
96295 int n;
 
96296
96297 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
96298 x.nArg = argc-1;
96299 x.nUsed = 0;
96300 x.apArg = argv+1;
96301 sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH);
96302 str.db = sqlite3_context_db_handle(context);
96303 sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x);
96304 n = str.nChar;
96305 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
96306 SQLITE_DYNAMIC);
96307 }
@@ -96447,11 +96810,11 @@
96447 sqlite3_result_double(context, r);
96448 }
96449 #endif
96450
96451 /*
96452 ** Allocate nByte bytes of space using sqlite3_malloc(). If the
96453 ** allocation fails, call sqlite3_result_error_nomem() to notify
96454 ** the database handle that malloc() has failed and return NULL.
96455 ** If nByte is larger than the maximum string or blob length, then
96456 ** raise an SQLITE_TOOBIG exception and return NULL.
96457 */
@@ -97116,11 +97479,11 @@
97116 int argc,
97117 sqlite3_value **argv
97118 ){
97119 unsigned char *z, *zOut;
97120 int i;
97121 zOut = z = sqlite3_malloc( argc*4+1 );
97122 if( z==0 ){
97123 sqlite3_result_error_nomem(context);
97124 return;
97125 }
97126 for(i=0; i<argc; i++){
@@ -97264,11 +97627,11 @@
97264 sqlite3_result_error_toobig(context);
97265 sqlite3_free(zOut);
97266 return;
97267 }
97268 zOld = zOut;
97269 zOut = sqlite3_realloc(zOut, (int)nOut);
97270 if( zOut==0 ){
97271 sqlite3_result_error_nomem(context);
97272 sqlite3_free(zOld);
97273 return;
97274 }
@@ -97626,12 +97989,11 @@
97626 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
97627 pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
97628
97629 if( pAccum ){
97630 sqlite3 *db = sqlite3_context_db_handle(context);
97631 int firstTerm = pAccum->useMalloc==0;
97632 pAccum->useMalloc = 2;
97633 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
97634 if( !firstTerm ){
97635 if( argc==2 ){
97636 zSep = (char*)sqlite3_value_text(argv[1]);
97637 nSep = sqlite3_value_bytes(argv[1]);
@@ -99047,11 +99409,12 @@
99047 int iFromCol; /* Idx of column in child table */
99048 Expr *pEq; /* tFromCol = OLD.tToCol */
99049
99050 iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
99051 assert( iFromCol>=0 );
99052 tToCol.z = pIdx ? pTab->aCol[pIdx->aiColumn[i]].zName : "oid";
 
99053 tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName;
99054
99055 tToCol.n = sqlite3Strlen30(tToCol.z);
99056 tFromCol.n = sqlite3Strlen30(tFromCol.z);
99057
@@ -99059,14 +99422,14 @@
99059 ** that the "OLD.zToCol" term is on the LHS of the = operator, so
99060 ** that the affinity and collation sequence associated with the
99061 ** parent table are used for the comparison. */
99062 pEq = sqlite3PExpr(pParse, TK_EQ,
99063 sqlite3PExpr(pParse, TK_DOT,
99064 sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld),
99065 sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
99066 , 0),
99067 sqlite3PExpr(pParse, TK_ID, 0, 0, &tFromCol)
99068 , 0);
99069 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
99070
99071 /* For ON UPDATE, construct the next term of the WHEN clause.
99072 ** The final WHEN clause will be like this:
@@ -99074,27 +99437,27 @@
99074 ** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN)
99075 */
99076 if( pChanges ){
99077 pEq = sqlite3PExpr(pParse, TK_IS,
99078 sqlite3PExpr(pParse, TK_DOT,
99079 sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld),
99080 sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol),
99081 0),
99082 sqlite3PExpr(pParse, TK_DOT,
99083 sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew),
99084 sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol),
99085 0),
99086 0);
99087 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
99088 }
99089
99090 if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
99091 Expr *pNew;
99092 if( action==OE_Cascade ){
99093 pNew = sqlite3PExpr(pParse, TK_DOT,
99094 sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew),
99095 sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
99096 , 0);
99097 }else if( action==OE_SetDflt ){
99098 Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
99099 if( pDflt ){
99100 pNew = sqlite3ExprDup(db, pDflt, 0);
@@ -99137,17 +99500,16 @@
99137 db->lookaside.bEnabled = 0;
99138
99139 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
99140 sizeof(Trigger) + /* struct Trigger */
99141 sizeof(TriggerStep) + /* Single step in trigger program */
99142 nFrom + 1 /* Space for pStep->target.z */
99143 );
99144 if( pTrigger ){
99145 pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1];
99146 pStep->target.z = (char *)&pStep[1];
99147 pStep->target.n = nFrom;
99148 memcpy((char *)pStep->target.z, zFrom, nFrom);
99149
99150 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
99151 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
99152 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
99153 if( pWhen ){
@@ -99608,24 +99970,27 @@
99608 );
99609
99610 /*
99611 ** This routine is called to handle SQL of the following forms:
99612 **
99613 ** insert into TABLE (IDLIST) values(EXPRLIST)
99614 ** insert into TABLE (IDLIST) select
 
99615 **
99616 ** The IDLIST following the table name is always optional. If omitted,
99617 ** then a list of all columns for the table is substituted. The IDLIST
99618 ** appears in the pColumn parameter. pColumn is NULL if IDLIST is omitted.
 
99619 **
99620 ** The pList parameter holds EXPRLIST in the first form of the INSERT
99621 ** statement above, and pSelect is NULL. For the second form, pList is
99622 ** NULL and pSelect is a pointer to the select statement used to generate
99623 ** data for the insert.
 
99624 **
99625 ** The code generated follows one of four templates. For a simple
99626 ** insert with data coming from a VALUES clause, the code executes
99627 ** once straight down through. Pseudo-code follows (we call this
99628 ** the "1st template"):
99629 **
99630 ** open write cursor to <table> and its indices
99631 ** put VALUES clause expressions into registers
@@ -99728,11 +100093,11 @@
99728 int iDb; /* Index of database holding TABLE */
99729 Db *pDb; /* The database containing table being inserted into */
99730 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
99731 u8 appendFlag = 0; /* True if the insert is likely to be an append */
99732 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
99733 u8 bIdListInOrder = 1; /* True if IDLIST is in table order */
99734 ExprList *pList = 0; /* List of VALUES() to be inserted */
99735
99736 /* Register allocations */
99737 int regFromSelect = 0;/* Base register for data coming from SELECT */
99738 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
@@ -99753,12 +100118,12 @@
99753 if( pParse->nErr || db->mallocFailed ){
99754 goto insert_cleanup;
99755 }
99756
99757 /* If the Select object is really just a simple VALUES() list with a
99758 ** single row values (the common case) then keep that one row of values
99759 ** and go ahead and discard the Select object
99760 */
99761 if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){
99762 pList = pSelect->pEList;
99763 pSelect->pEList = 0;
99764 sqlite3SelectDelete(db, pSelect);
@@ -99862,10 +100227,11 @@
99862 ** the index into IDLIST of the primary key column. ipkColumn is
99863 ** the index of the primary key as it appears in IDLIST, not as
99864 ** is appears in the original table. (The index of the INTEGER
99865 ** PRIMARY KEY in the original table is pTab->iPKey.)
99866 */
 
99867 if( pColumn ){
99868 for(i=0; i<pColumn->nId; i++){
99869 pColumn->a[i].idx = -1;
99870 }
99871 for(i=0; i<pColumn->nId; i++){
@@ -99897,11 +100263,12 @@
99897 ** is coming from a SELECT statement, then generate a co-routine that
99898 ** produces a single row of the SELECT on each invocation. The
99899 ** co-routine is the common header to the 3rd and 4th templates.
99900 */
99901 if( pSelect ){
99902 /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
 
99903 int regYield; /* Register holding co-routine entry-point */
99904 int addrTop; /* Top of the co-routine */
99905 int rc; /* Result code */
99906
99907 regYield = ++pParse->nMem;
@@ -99910,12 +100277,11 @@
99910 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
99911 dest.iSdst = bIdListInOrder ? regData : 0;
99912 dest.nSdst = pTab->nCol;
99913 rc = sqlite3Select(pParse, pSelect, &dest);
99914 regFromSelect = dest.iSdst;
99915 assert( pParse->nErr==0 || rc );
99916 if( rc || db->mallocFailed ) goto insert_cleanup;
99917 sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
99918 sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
99919 assert( pSelect->pEList );
99920 nColumn = pSelect->pEList->nExpr;
99921
@@ -99959,12 +100325,12 @@
99959 sqlite3VdbeJumpHere(v, addrL);
99960 sqlite3ReleaseTempReg(pParse, regRec);
99961 sqlite3ReleaseTempReg(pParse, regTempRowid);
99962 }
99963 }else{
99964 /* This is the case if the data for the INSERT is coming from a VALUES
99965 ** clause
99966 */
99967 NameContext sNC;
99968 memset(&sNC, 0, sizeof(sNC));
99969 sNC.pParse = pParse;
99970 srcTab = -1;
@@ -101031,10 +101397,11 @@
101031 Table *pDest, /* The table we are inserting into */
101032 Select *pSelect, /* A SELECT statement to use as the data source */
101033 int onError, /* How to handle constraint errors */
101034 int iDbDest /* The database of pDest */
101035 ){
 
101036 ExprList *pEList; /* The result set of the SELECT */
101037 Table *pSrc; /* The table in the FROM clause of SELECT */
101038 Index *pSrcIdx, *pDestIdx; /* Source and destination indices */
101039 struct SrcList_item *pItem; /* An element of pSelect->pSrc */
101040 int i; /* Loop counter */
@@ -101178,15 +101545,15 @@
101178 ** But the main beneficiary of the transfer optimization is the VACUUM
101179 ** command, and the VACUUM command disables foreign key constraints. So
101180 ** the extra complication to make this rule less restrictive is probably
101181 ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
101182 */
101183 if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
101184 return 0;
101185 }
101186 #endif
101187 if( (pParse->db->flags & SQLITE_CountRows)!=0 ){
101188 return 0; /* xfer opt does not play well with PRAGMA count_changes */
101189 }
101190
101191 /* If we get this far, it means that the xfer optimization is at
101192 ** least a possibility, though it might only work if the destination
@@ -101193,28 +101560,32 @@
101193 ** table (tab1) is initially empty.
101194 */
101195 #ifdef SQLITE_TEST
101196 sqlite3_xferopt_count++;
101197 #endif
101198 iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema);
101199 v = sqlite3GetVdbe(pParse);
101200 sqlite3CodeVerifySchema(pParse, iDbSrc);
101201 iSrc = pParse->nTab++;
101202 iDest = pParse->nTab++;
101203 regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
101204 regData = sqlite3GetTempReg(pParse);
101205 regRowid = sqlite3GetTempReg(pParse);
101206 sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
101207 assert( HasRowid(pDest) || destHasUniqueIdx );
101208 if( (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
 
101209 || destHasUniqueIdx /* (2) */
101210 || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
101211 ){
101212 /* In some circumstances, we are able to run the xfer optimization
101213 ** only if the destination table is initially empty. This code makes
101214 ** that determination. Conditions under which the destination must
101215 ** be empty:
 
 
 
101216 **
101217 ** (1) There is no INTEGER PRIMARY KEY but there are indices.
101218 ** (If the destination is not initially empty, the rowid fields
101219 ** of index entries might need to change.)
101220 **
@@ -101253,10 +101624,11 @@
101253 }else{
101254 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
101255 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
101256 }
101257 for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
 
101258 for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
101259 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
101260 }
101261 assert( pSrcIdx );
101262 sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
@@ -101266,11 +101638,37 @@
101266 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
101267 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
101268 VdbeComment((v, "%s", pDestIdx->zName));
101269 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
101270 sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101271 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
 
101272 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
101273 sqlite3VdbeJumpHere(v, addr1);
101274 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
101275 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
101276 }
@@ -102385,11 +102783,11 @@
102385 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102386 char *zErrmsg = 0;
102387 const char *zEntry;
102388 char *zAltEntry = 0;
102389 void **aHandle;
102390 int nMsg = 300 + sqlite3Strlen30(zFile);
102391 int ii;
102392
102393 /* Shared library endings to try if zFile cannot be loaded as written */
102394 static const char *azEndings[] = {
102395 #if SQLITE_OS_WIN
@@ -102428,11 +102826,11 @@
102428 sqlite3_free(zAltFile);
102429 }
102430 #endif
102431 if( handle==0 ){
102432 if( pzErrMsg ){
102433 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
102434 if( zErrmsg ){
102435 sqlite3_snprintf(nMsg, zErrmsg,
102436 "unable to open shared library [%s]", zFile);
102437 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102438 }
@@ -102454,11 +102852,11 @@
102454 ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
102455 */
102456 if( xInit==0 && zProc==0 ){
102457 int iFile, iEntry, c;
102458 int ncFile = sqlite3Strlen30(zFile);
102459 zAltEntry = sqlite3_malloc(ncFile+30);
102460 if( zAltEntry==0 ){
102461 sqlite3OsDlClose(pVfs, handle);
102462 return SQLITE_NOMEM;
102463 }
102464 memcpy(zAltEntry, "sqlite3_", 8);
@@ -102476,11 +102874,11 @@
102476 sqlite3OsDlSym(pVfs, handle, zEntry);
102477 }
102478 if( xInit==0 ){
102479 if( pzErrMsg ){
102480 nMsg += sqlite3Strlen30(zEntry);
102481 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
102482 if( zErrmsg ){
102483 sqlite3_snprintf(nMsg, zErrmsg,
102484 "no entry point [%s] in shared library [%s]", zEntry, zFile);
102485 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102486 }
@@ -102575,11 +102973,11 @@
102575 ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER
102576 ** mutex must be held while accessing this list.
102577 */
102578 typedef struct sqlite3AutoExtList sqlite3AutoExtList;
102579 static SQLITE_WSD struct sqlite3AutoExtList {
102580 int nExt; /* Number of entries in aExt[] */
102581 void (**aExt)(void); /* Pointers to the extension init functions */
102582 } sqlite3Autoext = { 0, 0 };
102583
102584 /* The "wsdAutoext" macro will resolve to the autoextension
102585 ** state vector. If writable static data is unsupported on the target,
@@ -102608,23 +103006,23 @@
102608 if( rc ){
102609 return rc;
102610 }else
102611 #endif
102612 {
102613 int i;
102614 #if SQLITE_THREADSAFE
102615 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
102616 #endif
102617 wsdAutoextInit;
102618 sqlite3_mutex_enter(mutex);
102619 for(i=0; i<wsdAutoext.nExt; i++){
102620 if( wsdAutoext.aExt[i]==xInit ) break;
102621 }
102622 if( i==wsdAutoext.nExt ){
102623 int nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
102624 void (**aNew)(void);
102625 aNew = sqlite3_realloc(wsdAutoext.aExt, nByte);
102626 if( aNew==0 ){
102627 rc = SQLITE_NOMEM;
102628 }else{
102629 wsdAutoext.aExt = aNew;
102630 wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
@@ -102652,11 +103050,11 @@
102652 #endif
102653 int i;
102654 int n = 0;
102655 wsdAutoextInit;
102656 sqlite3_mutex_enter(mutex);
102657 for(i=wsdAutoext.nExt-1; i>=0; i--){
102658 if( wsdAutoext.aExt[i]==xInit ){
102659 wsdAutoext.nExt--;
102660 wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
102661 n++;
102662 break;
@@ -102690,11 +103088,11 @@
102690 ** Load all automatic extensions.
102691 **
102692 ** If anything goes wrong, set an error in the database connection.
102693 */
102694 SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
102695 int i;
102696 int go = 1;
102697 int rc;
102698 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102699
102700 wsdAutoextInit;
@@ -103354,19 +103752,19 @@
103354 /*
103355 ** Generate code to return a single integer value.
103356 */
103357 static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
103358 Vdbe *v = sqlite3GetVdbe(pParse);
103359 int mem = ++pParse->nMem;
103360 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
103361 if( pI64 ){
103362 memcpy(pI64, &value, sizeof(value));
103363 }
103364 sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64);
103365 sqlite3VdbeSetNumCols(v, 1);
103366 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
103367 sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
103368 }
103369
103370
103371 /*
103372 ** Set the safety_level and pager flags for pager iDb. Or if iDb<0
@@ -103527,15 +103925,15 @@
103527 aFcntl[3] = 0;
103528 db->busyHandler.nBusy = 0;
103529 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
103530 if( rc==SQLITE_OK ){
103531 if( aFcntl[0] ){
103532 int mem = ++pParse->nMem;
103533 sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0);
103534 sqlite3VdbeSetNumCols(v, 1);
103535 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
103536 sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
103537 sqlite3_free(aFcntl[0]);
103538 }
103539 goto pragma_out;
103540 }
103541 if( rc!=SQLITE_NOTFOUND ){
@@ -104136,11 +104534,13 @@
104136 }else{
104137 if( !db->autoCommit ){
104138 sqlite3ErrorMsg(pParse,
104139 "Safety level may not be changed inside a transaction");
104140 }else{
104141 pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
 
 
104142 setAllPagerFlags(db);
104143 }
104144 }
104145 break;
104146 }
@@ -104231,11 +104631,11 @@
104231 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
104232 k = 0;
104233 }else if( pPk==0 ){
104234 k = 1;
104235 }else{
104236 for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){}
104237 }
104238 sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
104239 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
104240 }
104241 }
@@ -105237,11 +105637,11 @@
105237
105238 assert( iDb>=0 && iDb<db->nDb );
105239 if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
105240 if( argv[1]==0 ){
105241 corruptSchema(pData, argv[0], 0);
105242 }else if( argv[2] && argv[2][0] ){
105243 /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
105244 ** But because db->init.busy is set to 1, no VDBE code is generated
105245 ** or executed. All the parser does is build the internal data
105246 ** structures that describe the table, index, or view.
105247 */
@@ -105268,12 +105668,12 @@
105268 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
105269 }
105270 }
105271 }
105272 sqlite3_finalize(pStmt);
105273 }else if( argv[0]==0 ){
105274 corruptSchema(pData, 0, 0);
105275 }else{
105276 /* If the SQL column is blank it means this is an index that
105277 ** was created to be the PRIMARY KEY or to fulfill a UNIQUE
105278 ** constraint for a CREATE TABLE. The index should have already
105279 ** been created when we processed the CREATE TABLE. All we have
@@ -106176,11 +106576,10 @@
106176 ){
106177 Select *pNew;
106178 Select standin;
106179 sqlite3 *db = pParse->db;
106180 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
106181 assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */
106182 if( pNew==0 ){
106183 assert( db->mallocFailed );
106184 pNew = &standin;
106185 memset(pNew, 0, sizeof(*pNew));
106186 }
@@ -106196,11 +106595,11 @@
106196 pNew->pOrderBy = pOrderBy;
106197 pNew->selFlags = selFlags;
106198 pNew->op = TK_SELECT;
106199 pNew->pLimit = pLimit;
106200 pNew->pOffset = pOffset;
106201 assert( pOffset==0 || pLimit!=0 );
106202 pNew->addrOpenEphm[0] = -1;
106203 pNew->addrOpenEphm[1] = -1;
106204 if( db->mallocFailed ) {
106205 clearSelect(db, pNew, pNew!=&standin);
106206 pNew = 0;
@@ -107446,11 +107845,11 @@
107446 if( pS ){
107447 /* The "table" is actually a sub-select or a view in the FROM clause
107448 ** of the SELECT statement. Return the declaration type and origin
107449 ** data for the result-set column of the sub-select.
107450 */
107451 if( iCol>=0 && ALWAYS(iCol<pS->pEList->nExpr) ){
107452 /* If iCol is less than zero, then the expression requests the
107453 ** rowid of the sub-select or view. This expression is legal (see
107454 ** test case misc2.2.2) - it always evaluates to NULL.
107455 */
107456 NameContext sNC;
@@ -107766,16 +108165,18 @@
107766 memset(&sNC, 0, sizeof(sNC));
107767 sNC.pSrcList = pSelect->pSrc;
107768 a = pSelect->pEList->a;
107769 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
107770 p = a[i].pExpr;
107771 pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst));
 
 
107772 szAll += pCol->szEst;
107773 pCol->affinity = sqlite3ExprAffinity(p);
107774 if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE;
107775 pColl = sqlite3ExprCollSeq(pParse, p);
107776 if( pColl ){
107777 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
107778 }
107779 }
107780 pTab->szTabRow = sqlite3LogEst(szAll*4);
107781 }
@@ -108173,12 +108574,11 @@
108173 ){
108174 Select *pPrior;
108175 int nExpr = p->pEList->nExpr;
108176 int nRow = 1;
108177 int rc = 0;
108178 assert( p->pNext==0 );
108179 assert( p->selFlags & SF_AllValues );
108180 do{
108181 assert( p->selFlags & SF_Values );
108182 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
108183 assert( p->pLimit==0 );
108184 assert( p->pOffset==0 );
@@ -108283,11 +108683,11 @@
108283 dest.eDest = SRT_Table;
108284 }
108285
108286 /* Special handling for a compound-select that originates as a VALUES clause.
108287 */
108288 if( p->selFlags & SF_AllValues ){
108289 rc = multiSelectValues(pParse, p, &dest);
108290 goto multi_select_end;
108291 }
108292
108293 /* Make sure all SELECTs in the statement have the same number of elements
@@ -108668,11 +109068,11 @@
108668 ** then there should be a single item on the stack. Write this
108669 ** item into the set table with bogus data.
108670 */
108671 case SRT_Set: {
108672 int r1;
108673 assert( pIn->nSdst==1 );
108674 pDest->affSdst =
108675 sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affSdst);
108676 r1 = sqlite3GetTempReg(pParse);
108677 sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, 1, r1, &pDest->affSdst,1);
108678 sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, 1);
@@ -108694,11 +109094,11 @@
108694 /* If this is a scalar select that is part of an expression, then
108695 ** store the results in the appropriate memory cell and break out
108696 ** of the scan loop.
108697 */
108698 case SRT_Mem: {
108699 assert( pIn->nSdst==1 );
108700 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1);
108701 /* The LIMIT clause will jump out of the loop for us */
108702 break;
108703 }
108704 #endif /* #ifndef SQLITE_OMIT_SUBQUERY */
@@ -108709,11 +109109,11 @@
108709 case SRT_Coroutine: {
108710 if( pDest->iSdst==0 ){
108711 pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst);
108712 pDest->nSdst = pIn->nSdst;
108713 }
108714 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pDest->nSdst);
108715 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
108716 break;
108717 }
108718
108719 /* If none of the above, then the result destination must be
@@ -108925,12 +109325,14 @@
108925 */
108926 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
108927 if( aPermute ){
108928 struct ExprList_item *pItem;
108929 for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
108930 assert( pItem->u.x.iOrderByCol>0
108931 && pItem->u.x.iOrderByCol<=p->pEList->nExpr );
 
 
108932 aPermute[i] = pItem->u.x.iOrderByCol - 1;
108933 }
108934 pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1);
108935 }else{
108936 pKeyMerge = 0;
@@ -109136,11 +109538,11 @@
109136 pPrior->pNext = p;
109137
109138 /*** TBD: Insert subroutine calls to close cursors on incomplete
109139 **** subqueries ****/
109140 explainComposite(pParse, p->op, iSub1, iSub2, 0);
109141 return SQLITE_OK;
109142 }
109143 #endif
109144
109145 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
109146 /* Forward Declarations */
@@ -109948,10 +110350,11 @@
109948 pNew->pGroupBy = 0;
109949 pNew->pHaving = 0;
109950 pNew->pOrderBy = 0;
109951 p->pPrior = 0;
109952 p->pNext = 0;
 
109953 p->selFlags &= ~SF_Compound;
109954 assert( (p->selFlags & SF_Converted)==0 );
109955 p->selFlags |= SF_Converted;
109956 assert( pNew->pPrior!=0 );
109957 pNew->pPrior->pNext = pNew;
@@ -110486,11 +110889,11 @@
110486 if( pParse->hasCompound ){
110487 w.xSelectCallback = convertCompoundSelectToSubquery;
110488 sqlite3WalkSelect(&w, pSelect);
110489 }
110490 w.xSelectCallback = selectExpander;
110491 if( (pSelect->selFlags & SF_AllValues)==0 ){
110492 w.xSelectCallback2 = selectPopWith;
110493 }
110494 sqlite3WalkSelect(&w, pSelect);
110495 }
110496
@@ -110672,11 +111075,12 @@
110672 nArg = 0;
110673 regAgg = 0;
110674 }
110675 if( pF->iDistinct>=0 ){
110676 addrNext = sqlite3VdbeMakeLabel(v);
110677 assert( nArg==1 );
 
110678 codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
110679 }
110680 if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
110681 CollSeq *pColl = 0;
110682 struct ExprList_item *pItem;
@@ -111547,14 +111951,13 @@
111547
111548 /* Jump here to skip this query
111549 */
111550 sqlite3VdbeResolveLabel(v, iEnd);
111551
111552 /* The SELECT was successfully coded. Set the return code to 0
111553 ** to indicate no errors.
111554 */
111555 rc = 0;
111556
111557 /* Control jumps to here if an error is encountered above, or upon
111558 ** successful coding of the SELECT.
111559 */
111560 select_end:
@@ -111601,11 +112004,11 @@
111601 sqlite3TreeViewLine(pView, "FROM");
111602 for(i=0; i<p->pSrc->nSrc; i++){
111603 struct SrcList_item *pItem = &p->pSrc->a[i];
111604 StrAccum x;
111605 char zLine[100];
111606 sqlite3StrAccumInit(&x, zLine, sizeof(zLine), 0);
111607 sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
111608 if( pItem->zDatabase ){
111609 sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
111610 }else if( pItem->zName ){
111611 sqlite3XPrintf(&x, 0, " %s", pItem->zName);
@@ -111760,11 +112163,11 @@
111760 for(i=0; i<nCol; i++){
111761 if( argv[i]==0 ){
111762 z = 0;
111763 }else{
111764 int n = sqlite3Strlen30(argv[i])+1;
111765 z = sqlite3_malloc( n );
111766 if( z==0 ) goto malloc_failed;
111767 memcpy(z, argv[i], n);
111768 }
111769 p->azResult[p->nData++] = z;
111770 }
@@ -111809,11 +112212,11 @@
111809 res.nRow = 0;
111810 res.nColumn = 0;
111811 res.nData = 1;
111812 res.nAlloc = 20;
111813 res.rc = SQLITE_OK;
111814 res.azResult = sqlite3_malloc(sizeof(char*)*res.nAlloc );
111815 if( res.azResult==0 ){
111816 db->errCode = SQLITE_NOMEM;
111817 return SQLITE_NOMEM;
111818 }
111819 res.azResult[0] = 0;
@@ -111837,11 +112240,11 @@
111837 sqlite3_free_table(&res.azResult[1]);
111838 return rc;
111839 }
111840 if( res.nAlloc>res.nData ){
111841 char **azNew;
111842 azNew = sqlite3_realloc( res.azResult, sizeof(char*)*res.nData );
111843 if( azNew==0 ){
111844 sqlite3_free_table(&res.azResult[1]);
111845 db->errCode = SQLITE_NOMEM;
111846 return SQLITE_NOMEM;
111847 }
@@ -112065,11 +112468,10 @@
112065 }
112066
112067 /* Do not create a trigger on a system table */
112068 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
112069 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
112070 pParse->nErr++;
112071 goto trigger_cleanup;
112072 }
112073
112074 /* INSTEAD of triggers are only for views and views only support INSTEAD
112075 ** of triggers.
@@ -112245,16 +112647,16 @@
112245 u8 op, /* Trigger opcode */
112246 Token *pName /* The target name */
112247 ){
112248 TriggerStep *pTriggerStep;
112249
112250 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n);
112251 if( pTriggerStep ){
112252 char *z = (char*)&pTriggerStep[1];
112253 memcpy(z, pName->z, pName->n);
112254 pTriggerStep->target.z = z;
112255 pTriggerStep->target.n = pName->n;
112256 pTriggerStep->op = op;
112257 }
112258 return pTriggerStep;
112259 }
112260
@@ -112533,11 +112935,11 @@
112533 }
112534 return (mask ? pList : 0);
112535 }
112536
112537 /*
112538 ** Convert the pStep->target token into a SrcList and return a pointer
112539 ** to that SrcList.
112540 **
112541 ** This routine adds a specific database name, if needed, to the target when
112542 ** forming the SrcList. This prevents a trigger in one database from
112543 ** referring to a target in another database. An exception is when the
@@ -112546,21 +112948,21 @@
112546 */
112547 static SrcList *targetSrcList(
112548 Parse *pParse, /* The parsing context */
112549 TriggerStep *pStep /* The trigger containing the target token */
112550 ){
 
112551 int iDb; /* Index of the database to use */
112552 SrcList *pSrc; /* SrcList to be returned */
112553
112554 pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0);
112555 if( pSrc ){
112556 assert( pSrc->nSrc>0 );
112557 assert( pSrc->a!=0 );
112558 iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema);
112559 if( iDb==0 || iDb>=2 ){
112560 sqlite3 *db = pParse->db;
112561 assert( iDb<pParse->db->nDb );
112562 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
112563 }
112564 }
112565 return pSrc;
112566 }
@@ -112668,10 +113070,11 @@
112668 assert( pFrom->zErrMsg==0 || pFrom->nErr );
112669 assert( pTo->zErrMsg==0 || pTo->nErr );
112670 if( pTo->nErr==0 ){
112671 pTo->zErrMsg = pFrom->zErrMsg;
112672 pTo->nErr = pFrom->nErr;
 
112673 }else{
112674 sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
112675 }
112676 }
112677
@@ -114018,17 +114421,21 @@
114018
114019 /* Loop through the tables in the main database. For each, do
114020 ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
114021 ** the contents to the temporary database.
114022 */
 
 
114023 rc = execExecSql(db, pzErrMsg,
114024 "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
114025 "|| ' SELECT * FROM main.' || quote(name) || ';'"
114026 "FROM main.sqlite_master "
114027 "WHERE type = 'table' AND name!='sqlite_sequence' "
114028 " AND coalesce(rootpage,1)>0"
114029 );
 
 
114030 if( rc!=SQLITE_OK ) goto end_of_vacuum;
114031
114032 /* Copy over the sequence table
114033 */
114034 rc = execExecSql(db, pzErrMsg,
@@ -114163,10 +114570,12 @@
114163 ** are invoked only from within xCreate and xConnect methods.
114164 */
114165 struct VtabCtx {
114166 VTable *pVTable; /* The virtual table being constructed */
114167 Table *pTab; /* The Table object to which the virtual table belongs */
 
 
114168 };
114169
114170 /*
114171 ** The actual function that does the work of creating a new module.
114172 ** This function implements the sqlite3_create_module() and
@@ -114609,11 +115018,11 @@
114609 Token *pArg = &pParse->sArg;
114610 if( pArg->z==0 ){
114611 pArg->z = p->z;
114612 pArg->n = p->n;
114613 }else{
114614 assert(pArg->z < p->z);
114615 pArg->n = (int)(&p->z[p->n] - pArg->z);
114616 }
114617 }
114618
114619 /*
@@ -114626,19 +115035,31 @@
114626 Table *pTab,
114627 Module *pMod,
114628 int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**),
114629 char **pzErr
114630 ){
114631 VtabCtx sCtx, *pPriorCtx;
114632 VTable *pVTable;
114633 int rc;
114634 const char *const*azArg = (const char *const*)pTab->azModuleArg;
114635 int nArg = pTab->nModuleArg;
114636 char *zErr = 0;
114637 char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
114638 int iDb;
 
114639
 
 
 
 
 
 
 
 
 
 
 
114640 if( !zModuleName ){
114641 return SQLITE_NOMEM;
114642 }
114643
114644 pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
@@ -114655,15 +115076,17 @@
114655 /* Invoke the virtual table constructor */
114656 assert( &db->pVtabCtx );
114657 assert( xConstruct );
114658 sCtx.pTab = pTab;
114659 sCtx.pVTable = pVTable;
114660 pPriorCtx = db->pVtabCtx;
 
114661 db->pVtabCtx = &sCtx;
114662 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
114663 db->pVtabCtx = pPriorCtx;
114664 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
 
114665
114666 if( SQLITE_OK!=rc ){
114667 if( zErr==0 ){
114668 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
114669 }else {
@@ -114675,17 +115098,18 @@
114675 /* Justification of ALWAYS(): A correct vtab constructor must allocate
114676 ** the sqlite3_vtab object if successful. */
114677 memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
114678 pVTable->pVtab->pModule = pMod->pModule;
114679 pVTable->nRef = 1;
114680 if( sCtx.pTab ){
114681 const char *zFormat = "vtable constructor did not declare schema: %s";
114682 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
114683 sqlite3VtabUnlock(pVTable);
114684 rc = SQLITE_ERROR;
114685 }else{
114686 int iCol;
 
114687 /* If everything went according to plan, link the new VTable structure
114688 ** into the linked list headed by pTab->pVTable. Then loop through the
114689 ** columns of the table to see if any of them contain the token "hidden".
114690 ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
114691 ** the type string. */
@@ -114694,11 +115118,14 @@
114694
114695 for(iCol=0; iCol<pTab->nCol; iCol++){
114696 char *zType = pTab->aCol[iCol].zType;
114697 int nType;
114698 int i = 0;
114699 if( !zType ) continue;
 
 
 
114700 nType = sqlite3Strlen30(zType);
114701 if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){
114702 for(i=0; i<nType; i++){
114703 if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7))
114704 && (zType[i+7]=='\0' || zType[i+7]==' ')
@@ -114717,10 +115144,13 @@
114717 if( zType[i]=='\0' && i>0 ){
114718 assert(zType[i-1]==' ');
114719 zType[i-1] = '\0';
114720 }
114721 pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN;
 
 
 
114722 }
114723 }
114724 }
114725 }
114726
@@ -114845,12 +115275,12 @@
114845 ** This function is used to set the schema of a virtual table. It is only
114846 ** valid to call this function from within the xCreate() or xConnect() of a
114847 ** virtual table module.
114848 */
114849 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
 
114850 Parse *pParse;
114851
114852 int rc = SQLITE_OK;
114853 Table *pTab;
114854 char *zErr = 0;
114855
114856 #ifdef SQLITE_ENABLE_API_ARMOR
@@ -114857,15 +115287,17 @@
114857 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
114858 return SQLITE_MISUSE_BKPT;
114859 }
114860 #endif
114861 sqlite3_mutex_enter(db->mutex);
114862 if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
 
114863 sqlite3Error(db, SQLITE_MISUSE);
114864 sqlite3_mutex_leave(db->mutex);
114865 return SQLITE_MISUSE_BKPT;
114866 }
 
114867 assert( (pTab->tabFlags & TF_Virtual)!=0 );
114868
114869 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
114870 if( pParse==0 ){
114871 rc = SQLITE_NOMEM;
@@ -114884,11 +115316,11 @@
114884 pTab->aCol = pParse->pNewTable->aCol;
114885 pTab->nCol = pParse->pNewTable->nCol;
114886 pParse->pNewTable->nCol = 0;
114887 pParse->pNewTable->aCol = 0;
114888 }
114889 db->pVtabCtx->pTab = 0;
114890 }else{
114891 sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
114892 sqlite3DbFree(db, zErr);
114893 rc = SQLITE_ERROR;
114894 }
@@ -115078,11 +115510,11 @@
115078 */
115079 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
115080 int rc = SQLITE_OK;
115081
115082 assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
115083 assert( iSavepoint>=0 );
115084 if( db->aVTrans ){
115085 int i;
115086 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
115087 VTable *pVTab = db->aVTrans[i];
115088 const sqlite3_module *pMod = pVTab->pMod->pModule;
@@ -115196,11 +115628,11 @@
115196 assert( IsVirtual(pTab) );
115197 for(i=0; i<pToplevel->nVtabLock; i++){
115198 if( pTab==pToplevel->apVtabLock[i] ) return;
115199 }
115200 n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]);
115201 apVtabLock = sqlite3_realloc(pToplevel->apVtabLock, n);
115202 if( apVtabLock ){
115203 pToplevel->apVtabLock = apVtabLock;
115204 pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
115205 }else{
115206 pToplevel->db->mallocFailed = 1;
@@ -115995,17 +116427,18 @@
115995 ** In the previous sentence and in the diagram, "slot[]" refers to
115996 ** the WhereClause.a[] array. The slot[] array grows as needed to contain
115997 ** all terms of the WHERE clause.
115998 */
115999 static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){
 
116000 pWC->op = op;
116001 if( pExpr==0 ) return;
116002 if( pExpr->op!=op ){
116003 whereClauseInsert(pWC, pExpr, 0);
116004 }else{
116005 whereSplit(pWC, pExpr->pLeft, op);
116006 whereSplit(pWC, pExpr->pRight, op);
116007 }
116008 }
116009
116010 /*
116011 ** Initialize a WhereMaskSet object
@@ -117272,11 +117705,11 @@
117272 if( p->op==TK_COLUMN
117273 && p->iColumn==pIdx->aiColumn[iCol]
117274 && p->iTable==iBase
117275 ){
117276 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr);
117277 if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){
117278 return i;
117279 }
117280 }
117281 }
117282
@@ -117546,11 +117979,11 @@
117546 if( (idxCols & cMask)==0 ){
117547 Expr *pX = pTerm->pExpr;
117548 idxCols |= cMask;
117549 pIdx->aiColumn[n] = pTerm->u.leftColumn;
117550 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
117551 pIdx->azColl[n] = ALWAYS(pColl) ? pColl->zName : "BINARY";
117552 n++;
117553 }
117554 }
117555 }
117556 assert( (u32)n==pLoop->u.btree.nEq );
@@ -118842,12 +119275,11 @@
118842
118843 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
118844 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
118845 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
118846
118847 sqlite3StrAccumInit(&str, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
118848 str.db = db;
118849 sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
118850 if( pItem->pSelect ){
118851 sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId);
118852 }else{
118853 sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName);
@@ -120042,10 +120474,17 @@
120042 /*
120043 ** Free a WhereInfo structure
120044 */
120045 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
120046 if( ALWAYS(pWInfo) ){
 
 
 
 
 
 
 
120047 whereClauseClear(&pWInfo->sWC);
120048 while( pWInfo->pLoops ){
120049 WhereLoop *p = pWInfo->pLoops;
120050 pWInfo->pLoops = p->pNextLoop;
120051 whereLoopDelete(db, p);
@@ -120521,11 +120960,11 @@
120521 ** changes "x IN (?)" into "x=?". */
120522
120523 }else if( eOp & (WO_EQ) ){
120524 pNew->wsFlags |= WHERE_COLUMN_EQ;
120525 if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
120526 if( iCol>=0 && !IsUniqueIndex(pProbe) ){
120527 pNew->wsFlags |= WHERE_UNQ_WANTED;
120528 }else{
120529 pNew->wsFlags |= WHERE_ONEROW;
120530 }
120531 }
@@ -121981,11 +122420,11 @@
121981 pWInfo->nOBSat = pFrom->isOrdered;
121982 if( pWInfo->nOBSat<0 ) pWInfo->nOBSat = 0;
121983 pWInfo->revMask = pFrom->revLoop;
121984 }
121985 if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
121986 && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr
121987 ){
121988 Bitmask revMask = 0;
121989 int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
121990 pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
121991 );
@@ -122386,11 +122825,10 @@
122386 if( pParse->nErr || NEVER(db->mallocFailed) ){
122387 goto whereBeginError;
122388 }
122389 #ifdef WHERETRACE_ENABLED /* !=0 */
122390 if( sqlite3WhereTrace ){
122391 int ii;
122392 sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
122393 if( pWInfo->nOBSat>0 ){
122394 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
122395 }
122396 switch( pWInfo->eDistinct ){
@@ -122639,11 +123077,10 @@
122639 VdbeCoverage(v);
122640 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
122641 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
122642 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
122643 }
122644 sqlite3DbFree(db, pLevel->u.in.aInLoop);
122645 }
122646 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
122647 if( pLevel->addrSkip ){
122648 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
122649 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
@@ -122850,10 +123287,32 @@
122850 /*
122851 ** An instance of this structure holds the ATTACH key and the key type.
122852 */
122853 struct AttachKey { int type; Token key; };
122854
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122855
122856 /* This is a utility routine used to set the ExprSpan.zStart and
122857 ** ExprSpan.zEnd values of pOut so that the span covers the complete
122858 ** range of text beginning with pStart and going to the end of pEnd.
122859 */
@@ -125167,31 +125626,14 @@
125167 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
125168 }
125169 break;
125170 case 112: /* select ::= with selectnowith */
125171 {
125172 Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
125173 if( p ){
125174 int cnt = 0, mxSelect;
125175 p->pWith = yymsp[-1].minor.yy59;
125176 if( p->pPrior ){
125177 u16 allValues = SF_Values;
125178 pNext = 0;
125179 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
125180 pLoop->pNext = pNext;
125181 pLoop->selFlags |= SF_Compound;
125182 allValues &= pLoop->selFlags;
125183 }
125184 if( allValues ){
125185 p->selFlags |= SF_AllValues;
125186 }else if(
125187 (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0
125188 && cnt>mxSelect
125189 ){
125190 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
125191 }
125192 }
125193 }else{
125194 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
125195 }
125196 yygotominor.yy3 = p;
125197 }
@@ -125205,16 +125647,18 @@
125205 Select *pRhs = yymsp[0].minor.yy3;
125206 if( pRhs && pRhs->pPrior ){
125207 SrcList *pFrom;
125208 Token x;
125209 x.n = 0;
 
125210 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
125211 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
125212 }
125213 if( pRhs ){
125214 pRhs->op = (u8)yymsp[-1].minor.yy328;
125215 pRhs->pPrior = yymsp[-2].minor.yy3;
 
125216 if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
125217 }else{
125218 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
125219 }
125220 yygotominor.yy3 = pRhs;
@@ -125257,17 +125701,20 @@
125257 yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
125258 }
125259 break;
125260 case 121: /* values ::= values COMMA LP exprlist RP */
125261 {
125262 Select *pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
 
 
125263 if( pRight ){
125264 pRight->op = TK_ALL;
125265 pRight->pPrior = yymsp[-4].minor.yy3;
 
125266 yygotominor.yy3 = pRight;
125267 }else{
125268 yygotominor.yy3 = yymsp[-4].minor.yy3;
125269 }
125270 }
125271 break;
125272 case 122: /* distinct ::= DISTINCT */
125273 {yygotominor.yy381 = SF_Distinct;}
@@ -127067,14 +127514,12 @@
127067 goto abort_parse;
127068 }
127069 break;
127070 }
127071 case TK_ILLEGAL: {
127072 sqlite3DbFree(db, *pzErrMsg);
127073 *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"",
127074 &pParse->sLastToken);
127075 nErr++;
127076 goto abort_parse;
127077 }
127078 case TK_SEMI: {
127079 pParse->zTail = &zSql[i];
127080 /* Fall thru into the default case */
@@ -127088,16 +127533,19 @@
127088 break;
127089 }
127090 }
127091 }
127092 abort_parse:
127093 if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){
 
127094 if( lastTokenParsed!=TK_SEMI ){
127095 sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
127096 pParse->zTail = &zSql[i];
127097 }
127098 sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
 
 
127099 }
127100 #ifdef YYTRACKMAXSTACKDEPTH
127101 sqlite3_mutex_enter(sqlite3MallocMutex());
127102 sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
127103 sqlite3ParserStackPeak(pEngine)
@@ -127154,13 +127602,11 @@
127154 while( pParse->pZombieTab ){
127155 Table *p = pParse->pZombieTab;
127156 pParse->pZombieTab = p->pNextZombie;
127157 sqlite3DeleteTable(db, p);
127158 }
127159 if( nErr>0 && pParse->rc==SQLITE_OK ){
127160 pParse->rc = SQLITE_ERROR;
127161 }
127162 return nErr;
127163 }
127164
127165 /************** End of tokenize.c ********************************************/
127166 /************** Begin file complete.c ****************************************/
@@ -127432,11 +127878,11 @@
127432 ** UTF-8.
127433 */
127434 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *zSql){
127435 sqlite3_value *pVal;
127436 char const *zSql8;
127437 int rc = SQLITE_NOMEM;
127438
127439 #ifndef SQLITE_OMIT_AUTOINIT
127440 rc = sqlite3_initialize();
127441 if( rc ) return rc;
127442 #endif
@@ -127598,10 +128044,22 @@
127598 ** zero if and only if SQLite was compiled with mutexing code omitted due to
127599 ** the SQLITE_THREADSAFE compile-time option being set to 0.
127600 */
127601 SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }
127602
 
 
 
 
 
 
 
 
 
 
 
 
127603 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
127604 /*
127605 ** If the following function pointer is not NULL and if
127606 ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
127607 ** I/O active are written using this function. These messages
@@ -128737,11 +129195,11 @@
128737
128738 /*
128739 ** Return a static string containing the name corresponding to the error code
128740 ** specified in the argument.
128741 */
128742 #if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || defined(SQLITE_TEST)
128743 SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
128744 const char *zName = 0;
128745 int i, origRc = rc;
128746 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
128747 switch( rc ){
@@ -129962,18 +130420,18 @@
129962 ){
129963 char *zOpt;
129964 int eState; /* Parser state when parsing URI */
129965 int iIn; /* Input character index */
129966 int iOut = 0; /* Output character index */
129967 int nByte = nUri+2; /* Bytes of space to allocate */
129968
129969 /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
129970 ** method that there may be extra parameters following the file-name. */
129971 flags |= SQLITE_OPEN_URI;
129972
129973 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
129974 zFile = sqlite3_malloc(nByte);
129975 if( !zFile ) return SQLITE_NOMEM;
129976
129977 iIn = 5;
129978 #ifdef SQLITE_ALLOW_URI_AUTHORITY
129979 if( strncmp(zUri+5, "///", 3)==0 ){
@@ -130135,11 +130593,11 @@
130135
130136 zOpt = &zVal[nVal+1];
130137 }
130138
130139 }else{
130140 zFile = sqlite3_malloc(nUri+2);
130141 if( !zFile ) return SQLITE_NOMEM;
130142 memcpy(zFile, zUri, nUri);
130143 zFile[nUri] = '\0';
130144 zFile[nUri+1] = '\0';
130145 flags &= ~SQLITE_OPEN_URI;
@@ -130406,10 +130864,17 @@
130406 #ifdef SQLITE_ENABLE_RTREE
130407 if( !db->mallocFailed && rc==SQLITE_OK){
130408 rc = sqlite3RtreeInit(db);
130409 }
130410 #endif
 
 
 
 
 
 
 
130411
130412 /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
130413 ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
130414 ** mode. Doing nothing at all also makes NORMAL the default.
130415 */
@@ -132344,10 +132809,15 @@
132344 ** false.
132345 */
132346 #ifdef SQLITE_COVERAGE_TEST
132347 # define ALWAYS(x) (1)
132348 # define NEVER(X) (0)
 
 
 
 
 
132349 #else
132350 # define ALWAYS(x) (x)
132351 # define NEVER(x) (x)
132352 #endif
132353
@@ -132744,10 +133214,11 @@
132744 #define fts3GetVarint32(p, piVal) ( \
132745 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
132746 )
132747
132748 /* fts3.c */
 
132749 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
132750 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
132751 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
132752 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
132753 SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
@@ -132832,10 +133303,17 @@
132832
132833 static int fts3EvalNext(Fts3Cursor *pCsr);
132834 static int fts3EvalStart(Fts3Cursor *pCsr);
132835 static int fts3TermSegReaderCursor(
132836 Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **);
 
 
 
 
 
 
 
132837
132838 /*
132839 ** Write a 64-bit variable-length integer to memory starting at p[0].
132840 ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
132841 ** The number of bytes written is returned.
@@ -132942,11 +133420,11 @@
132942 int iOut = 0; /* Index of next byte to write to output */
132943
132944 /* If the first byte was a '[', then the close-quote character is a ']' */
132945 if( quote=='[' ) quote = ']';
132946
132947 while( ALWAYS(z[iIn]) ){
132948 if( z[iIn]==quote ){
132949 if( z[iIn+1]!=quote ) break;
132950 z[iOut++] = quote;
132951 iIn += 2;
132952 }else{
@@ -133020,10 +133498,21 @@
133020 p->pTokenizer->pModule->xDestroy(p->pTokenizer);
133021
133022 sqlite3_free(p);
133023 return SQLITE_OK;
133024 }
 
 
 
 
 
 
 
 
 
 
 
133025
133026 /*
133027 ** Construct one or more SQL statements from the format string given
133028 ** and then evaluate those statements. The success code is written
133029 ** into *pRc.
@@ -133539,11 +134028,12 @@
133539 sqlite3 *db, /* Database handle */
133540 const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */
133541 const char *zTbl, /* Name of content table */
133542 const char ***pazCol, /* OUT: Malloc'd array of column names */
133543 int *pnCol, /* OUT: Size of array *pazCol */
133544 int *pnStr /* OUT: Bytes of string content */
 
133545 ){
133546 int rc = SQLITE_OK; /* Return code */
133547 char *zSql; /* "SELECT *" statement on zTbl */
133548 sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */
133549
@@ -133550,10 +134040,13 @@
133550 zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", zDb, zTbl);
133551 if( !zSql ){
133552 rc = SQLITE_NOMEM;
133553 }else{
133554 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
 
 
 
133555 }
133556 sqlite3_free(zSql);
133557
133558 if( rc==SQLITE_OK ){
133559 const char **azCol; /* Output array */
@@ -133716,17 +134209,17 @@
133716 if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
133717 break;
133718 }
133719 }
133720 if( iOpt==SizeofArray(aFts4Opt) ){
133721 *pzErr = sqlite3_mprintf("unrecognized parameter: %s", z);
133722 rc = SQLITE_ERROR;
133723 }else{
133724 switch( iOpt ){
133725 case 0: /* MATCHINFO */
133726 if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
133727 *pzErr = sqlite3_mprintf("unrecognized matchinfo: %s", zVal);
133728 rc = SQLITE_ERROR;
133729 }
133730 bNoDocsize = 1;
133731 break;
133732
@@ -133750,11 +134243,11 @@
133750
133751 case 4: /* ORDER */
133752 if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
133753 && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
133754 ){
133755 *pzErr = sqlite3_mprintf("unrecognized order: %s", zVal);
133756 rc = SQLITE_ERROR;
133757 }
133758 bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
133759 break;
133760
@@ -133801,11 +134294,11 @@
133801 zCompress = 0;
133802 zUncompress = 0;
133803 if( nCol==0 ){
133804 sqlite3_free((void*)aCol);
133805 aCol = 0;
133806 rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString);
133807
133808 /* If a languageid= option was specified, remove the language id
133809 ** column from the aCol[] array. */
133810 if( rc==SQLITE_OK && zLanguageid ){
133811 int j;
@@ -133836,11 +134329,11 @@
133836 assert( pTokenizer );
133837
133838 rc = fts3PrefixParameter(zPrefix, &nIndex, &aIndex);
133839 if( rc==SQLITE_ERROR ){
133840 assert( zPrefix );
133841 *pzErr = sqlite3_mprintf("error parsing prefix parameter: %s", zPrefix);
133842 }
133843 if( rc!=SQLITE_OK ) goto fts3_init_out;
133844
133845 /* Allocate and populate the Fts3Table structure. */
133846 nByte = sizeof(Fts3Table) + /* Fts3Table */
@@ -133918,19 +134411,19 @@
133918 }
133919 }
133920 }
133921 for(i=0; i<nNotindexed; i++){
133922 if( azNotindexed[i] ){
133923 *pzErr = sqlite3_mprintf("no such column: %s", azNotindexed[i]);
133924 rc = SQLITE_ERROR;
133925 }
133926 }
133927
133928 if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
133929 char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
133930 rc = SQLITE_ERROR;
133931 *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
133932 }
133933 p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
133934 p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc);
133935 if( rc!=SQLITE_OK ) goto fts3_init_out;
133936
@@ -135319,11 +135812,11 @@
135319 ** Fts3SegReaderPending might segfault, as the data structures used by
135320 ** fts4aux are not completely populated. So it's easiest to filter these
135321 ** calls out here. */
135322 if( iLevel<0 && p->aIndex ){
135323 Fts3SegReader *pSeg = 0;
135324 rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix, &pSeg);
135325 if( rc==SQLITE_OK && pSeg ){
135326 rc = fts3SegReaderCursorAppend(pCsr, pSeg);
135327 }
135328 }
135329
@@ -135968,15 +136461,35 @@
135968 */
135969 static void fts3ReversePoslist(char *pStart, char **ppPoslist){
135970 char *p = &(*ppPoslist)[-2];
135971 char c = 0;
135972
 
135973 while( p>pStart && (c=*p--)==0 );
 
 
 
 
135974 while( p>pStart && (*p & 0x80) | c ){
135975 c = *p--;
135976 }
135977 if( p>pStart ){ p = &p[2]; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135978 while( *p++&0x80 );
135979 *ppPoslist = p;
135980 }
135981
135982 /*
@@ -136043,10 +136556,12 @@
136043 case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]);
136044 case 2: zStart = (const char*)sqlite3_value_text(apVal[1]);
136045 }
136046 if( !zEllipsis || !zEnd || !zStart ){
136047 sqlite3_result_error_nomem(pContext);
 
 
136048 }else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){
136049 sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken);
136050 }
136051 }
136052
@@ -137104,16 +137619,18 @@
137104 Fts3Expr *pExpr, /* Expression to initialize phrases in */
137105 int *pRc /* IN/OUT: Error code */
137106 ){
137107 if( pExpr && SQLITE_OK==*pRc ){
137108 if( pExpr->eType==FTSQUERY_PHRASE ){
137109 int i;
137110 int nToken = pExpr->pPhrase->nToken;
137111 for(i=0; i<nToken; i++){
137112 if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
 
 
 
 
137113 }
137114 pExpr->bDeferred = (i==nToken);
137115 *pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase);
137116 }else{
137117 fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc);
137118 fts3EvalStartReaders(pCsr, pExpr->pRight, pRc);
137119 pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred);
@@ -138272,11 +138789,12 @@
138272 if( rc!=SQLITE_OK ) return rc;
138273
138274 pIter = pPhrase->pOrPoslist;
138275 iDocid = pPhrase->iOrDocid;
138276 if( pCsr->bDesc==bDescDoclist ){
138277 bEof = (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll));
 
138278 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
138279 sqlite3Fts3DoclistNext(
138280 bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
138281 &pIter, &iDocid, &bEof
138282 );
@@ -138484,11 +139002,11 @@
138484
138485 *ppVtab = (sqlite3_vtab *)p;
138486 return SQLITE_OK;
138487
138488 bad_args:
138489 *pzErr = sqlite3_mprintf("invalid arguments to fts4aux constructor");
138490 return SQLITE_ERROR;
138491 }
138492
138493 /*
138494 ** This function does the work for both the xDisconnect and xDestroy methods.
@@ -139942,17 +140460,17 @@
139942
139943 if( rc!=SQLITE_OK ){
139944 sqlite3Fts3ExprFree(*ppExpr);
139945 *ppExpr = 0;
139946 if( rc==SQLITE_TOOBIG ){
139947 *pzErr = sqlite3_mprintf(
139948 "FTS expression tree is too large (maximum depth %d)",
139949 SQLITE_FTS3_MAX_EXPR_DEPTH
139950 );
139951 rc = SQLITE_ERROR;
139952 }else if( rc==SQLITE_ERROR ){
139953 *pzErr = sqlite3_mprintf("malformed MATCH expression: [%s]", z);
139954 }
139955 }
139956
139957 return rc;
139958 }
@@ -141424,11 +141942,11 @@
141424 z[n] = '\0';
141425 sqlite3Fts3Dequote(z);
141426
141427 m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1);
141428 if( !m ){
141429 *pzErr = sqlite3_mprintf("unknown tokenizer: %s", z);
141430 rc = SQLITE_ERROR;
141431 }else{
141432 char const **aArg = 0;
141433 int iArg = 0;
141434 z = &z[n+1];
@@ -141447,11 +141965,11 @@
141447 z = &z[n+1];
141448 }
141449 rc = m->xCreate(iArg, aArg, ppTok);
141450 assert( rc!=SQLITE_OK || *ppTok );
141451 if( rc!=SQLITE_OK ){
141452 *pzErr = sqlite3_mprintf("unknown tokenizer");
141453 }else{
141454 (*ppTok)->pModule = m;
141455 }
141456 sqlite3_free((void *)aArg);
141457 }
@@ -141531,13 +142049,13 @@
141531
141532 pHash = (Fts3Hash *)sqlite3_user_data(context);
141533 p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
141534
141535 if( !p ){
141536 char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
141537 sqlite3_result_error(context, zErr, -1);
141538 sqlite3_free(zErr);
141539 return;
141540 }
141541
141542 pRet = Tcl_NewObj();
141543 Tcl_IncrRefCount(pRet);
@@ -142068,11 +142586,11 @@
142068 sqlite3_tokenizer_module *p;
142069 int nName = (int)strlen(zName);
142070
142071 p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
142072 if( !p ){
142073 *pzErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
142074 return SQLITE_ERROR;
142075 }
142076
142077 *pp = p;
142078 return SQLITE_OK;
@@ -142765,11 +143283,11 @@
142765 /* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)",
142766 /* 24 */ "",
142767 /* 25 */ "",
142768
142769 /* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?",
142770 /* 27 */ "SELECT DISTINCT level / (1024 * ?) FROM %Q.'%q_segdir'",
142771
142772 /* This statement is used to determine which level to read the input from
142773 ** when performing an incremental merge. It returns the absolute level number
142774 ** of the oldest level in the db that contains at least ? segments. Or,
142775 ** if no level in the FTS index contains more than ? segments, the statement
@@ -145883,11 +146401,12 @@
145883 sqlite3_stmt *pAllLangid = 0;
145884
145885 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
145886 if( rc==SQLITE_OK ){
145887 int rc2;
145888 sqlite3_bind_int(pAllLangid, 1, p->nIndex);
 
145889 while( sqlite3_step(pAllLangid)==SQLITE_ROW ){
145890 int i;
145891 int iLangid = sqlite3_column_int(pAllLangid, 0);
145892 for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
145893 rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL);
@@ -147215,11 +147734,11 @@
147215 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
147216
147217 pHint->n = i;
147218 i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
147219 i += fts3GetVarint32(&pHint->a[i], pnInput);
147220 if( i!=nHint ) return SQLITE_CORRUPT_VTAB;
147221
147222 return SQLITE_OK;
147223 }
147224
147225
@@ -147583,11 +148102,12 @@
147583
147584 /* This block calculates the checksum according to the FTS index. */
147585 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
147586 if( rc==SQLITE_OK ){
147587 int rc2;
147588 sqlite3_bind_int(pAllLangid, 1, p->nIndex);
 
147589 while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){
147590 int iLangid = sqlite3_column_int(pAllLangid, 0);
147591 int i;
147592 for(i=0; i<p->nIndex; i++){
147593 cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc);
@@ -147596,11 +148116,10 @@
147596 rc2 = sqlite3_reset(pAllLangid);
147597 if( rc==SQLITE_OK ) rc = rc2;
147598 }
147599
147600 /* This block calculates the checksum according to the %_content table */
147601 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
147602 if( rc==SQLITE_OK ){
147603 sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule;
147604 sqlite3_stmt *pStmt = 0;
147605 char *zSql;
147606
@@ -147693,11 +148212,11 @@
147693 Fts3Table *p /* FTS3 table handle */
147694 ){
147695 int rc;
147696 int bOk = 0;
147697 rc = fts3IntegrityCheck(p, &bOk);
147698 if( rc==SQLITE_OK && bOk==0 ) rc = SQLITE_CORRUPT_VTAB;
147699 return rc;
147700 }
147701
147702 /*
147703 ** Handle a 'special' INSERT of the form:
@@ -148131,10 +148650,11 @@
148131 #define FTS3_MATCHINFO_NDOC 'n' /* 1 value */
148132 #define FTS3_MATCHINFO_AVGLENGTH 'a' /* nCol values */
148133 #define FTS3_MATCHINFO_LENGTH 'l' /* nCol values */
148134 #define FTS3_MATCHINFO_LCS 's' /* nCol values */
148135 #define FTS3_MATCHINFO_HITS 'x' /* 3*nCol*nPhrase values */
 
148136
148137 /*
148138 ** The default value for the second argument to matchinfo().
148139 */
148140 #define FTS3_MATCHINFO_DEFAULT "pcx"
@@ -148912,10 +149432,55 @@
148912 }
148913 }
148914
148915 return rc;
148916 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148917
148918 static int fts3MatchinfoCheck(
148919 Fts3Table *pTab,
148920 char cArg,
148921 char **pzErr
@@ -148925,14 +149490,15 @@
148925 || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4)
148926 || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4)
148927 || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize)
148928 || (cArg==FTS3_MATCHINFO_LCS)
148929 || (cArg==FTS3_MATCHINFO_HITS)
 
148930 ){
148931 return SQLITE_OK;
148932 }
148933 *pzErr = sqlite3_mprintf("unrecognized matchinfo request: %c", cArg);
148934 return SQLITE_ERROR;
148935 }
148936
148937 static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
148938 int nVal; /* Number of integers output by cArg */
@@ -148947,10 +149513,14 @@
148947 case FTS3_MATCHINFO_AVGLENGTH:
148948 case FTS3_MATCHINFO_LENGTH:
148949 case FTS3_MATCHINFO_LCS:
148950 nVal = pInfo->nCol;
148951 break;
 
 
 
 
148952
148953 default:
148954 assert( cArg==FTS3_MATCHINFO_HITS );
148955 nVal = pInfo->nCol * pInfo->nPhrase * 3;
148956 break;
@@ -149201,10 +149771,14 @@
149201 rc = fts3ExprLoadDoclists(pCsr, 0, 0);
149202 if( rc==SQLITE_OK ){
149203 rc = fts3MatchinfoLcs(pCsr, pInfo);
149204 }
149205 break;
 
 
 
 
149206
149207 default: {
149208 Fts3Expr *pExpr;
149209 assert( zArg[i]==FTS3_MATCHINFO_HITS );
149210 pExpr = pCsr->pExpr;
@@ -153214,15 +153788,23 @@
153214 ** conflict-handling mode specified by the user.
153215 */
153216 if( nData>1 ){
153217 int ii;
153218
153219 /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
153220 assert( nData==(pRtree->nDim*2 + 3) );
 
 
 
 
 
 
 
 
153221 #ifndef SQLITE_RTREE_INT_ONLY
153222 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
153223 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
153224 cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
153225 cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]);
153226 if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
153227 rc = SQLITE_CONSTRAINT;
153228 goto constraint;
@@ -153229,11 +153811,11 @@
153229 }
153230 }
153231 }else
153232 #endif
153233 {
153234 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
153235 cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]);
153236 cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]);
153237 if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){
153238 rc = SQLITE_CONSTRAINT;
153239 goto constraint;
@@ -154629,5 +155211,656 @@
154629
154630 #endif /* defined(SQLITE_ENABLE_ICU) */
154631 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
154632
154633 /************** End of fts3_icu.c ********************************************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154634
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.10.2. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -68,10 +68,11 @@
68 #if defined(_MSC_VER)
69 #pragma warning(disable : 4054)
70 #pragma warning(disable : 4055)
71 #pragma warning(disable : 4100)
72 #pragma warning(disable : 4127)
73 #pragma warning(disable : 4130)
74 #pragma warning(disable : 4152)
75 #pragma warning(disable : 4189)
76 #pragma warning(disable : 4206)
77 #pragma warning(disable : 4210)
78 #pragma warning(disable : 4232)
@@ -315,13 +316,13 @@
316 **
317 ** See also: [sqlite3_libversion()],
318 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
319 ** [sqlite_version()] and [sqlite_source_id()].
320 */
321 #define SQLITE_VERSION "3.8.10.2"
322 #define SQLITE_VERSION_NUMBER 3008010
323 #define SQLITE_SOURCE_ID "2015-05-20 18:17:19 2ef4f3a5b1d1d0c4338f8243d40a2452cc1f7fe4"
324
325 /*
326 ** CAPI3REF: Run-Time Library Version Numbers
327 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
328 **
@@ -474,10 +475,11 @@
475 # define double sqlite3_int64
476 #endif
477
478 /*
479 ** CAPI3REF: Closing A Database Connection
480 ** DESTRUCTOR: sqlite3
481 **
482 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
483 ** for the [sqlite3] object.
484 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
485 ** the [sqlite3] object is successfully destroyed and all associated
@@ -525,10 +527,11 @@
527 */
528 typedef int (*sqlite3_callback)(void*,int,char**, char**);
529
530 /*
531 ** CAPI3REF: One-Step Query Execution Interface
532 ** METHOD: sqlite3
533 **
534 ** The sqlite3_exec() interface is a convenience wrapper around
535 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
536 ** that allows an application to run multiple statements of SQL
537 ** without having to use a lot of C code.
@@ -1582,10 +1585,11 @@
1585 */
1586 SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
1587
1588 /*
1589 ** CAPI3REF: Configure database connections
1590 ** METHOD: sqlite3
1591 **
1592 ** The sqlite3_db_config() interface is used to make configuration
1593 ** changes to a [database connection]. The interface is similar to
1594 ** [sqlite3_config()] except that the changes apply to a single
1595 ** [database connection] (specified in the first argument).
@@ -2079,19 +2083,21 @@
2083 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2084
2085
2086 /*
2087 ** CAPI3REF: Enable Or Disable Extended Result Codes
2088 ** METHOD: sqlite3
2089 **
2090 ** ^The sqlite3_extended_result_codes() routine enables or disables the
2091 ** [extended result codes] feature of SQLite. ^The extended result
2092 ** codes are disabled by default for historical compatibility.
2093 */
2094 SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
2095
2096 /*
2097 ** CAPI3REF: Last Insert Rowid
2098 ** METHOD: sqlite3
2099 **
2100 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
2101 ** has a unique 64-bit signed
2102 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
2103 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -2139,10 +2145,11 @@
2145 */
2146 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
2147
2148 /*
2149 ** CAPI3REF: Count The Number Of Rows Modified
2150 ** METHOD: sqlite3
2151 **
2152 ** ^This function returns the number of rows modified, inserted or
2153 ** deleted by the most recently completed INSERT, UPDATE or DELETE
2154 ** statement on the database connection specified by the only parameter.
2155 ** ^Executing any other type of SQL statement does not modify the value
@@ -2191,10 +2198,11 @@
2198 */
2199 SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
2200
2201 /*
2202 ** CAPI3REF: Total Number Of Rows Modified
2203 ** METHOD: sqlite3
2204 **
2205 ** ^This function returns the total number of rows inserted, modified or
2206 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2207 ** since the database connection was opened, including those executed as
2208 ** part of trigger programs. ^Executing any other type of SQL statement
@@ -2214,10 +2222,11 @@
2222 */
2223 SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
2224
2225 /*
2226 ** CAPI3REF: Interrupt A Long-Running Query
2227 ** METHOD: sqlite3
2228 **
2229 ** ^This function causes any pending database operation to abort and
2230 ** return at its earliest opportunity. This routine is typically
2231 ** called in response to a user action such as pressing "Cancel"
2232 ** or Ctrl-C where the user wants a long query operation to halt
@@ -2290,10 +2299,11 @@
2299 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
2300
2301 /*
2302 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2303 ** KEYWORDS: {busy-handler callback} {busy handler}
2304 ** METHOD: sqlite3
2305 **
2306 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2307 ** that might be invoked with argument P whenever
2308 ** an attempt is made to access a database table associated with
2309 ** [database connection] D when another thread
@@ -2349,10 +2359,11 @@
2359 */
2360 SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
2361
2362 /*
2363 ** CAPI3REF: Set A Busy Timeout
2364 ** METHOD: sqlite3
2365 **
2366 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2367 ** for a specified amount of time when a table is locked. ^The handler
2368 ** will sleep multiple times until at least "ms" milliseconds of sleeping
2369 ** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2371,10 +2382,11 @@
2382 */
2383 SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
2384
2385 /*
2386 ** CAPI3REF: Convenience Routines For Running Queries
2387 ** METHOD: sqlite3
2388 **
2389 ** This is a legacy interface that is preserved for backwards compatibility.
2390 ** Use of this interface is not recommended.
2391 **
2392 ** Definition: A <b>result table</b> is memory data structure created by the
@@ -2706,10 +2718,11 @@
2718 */
2719 SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
2720
2721 /*
2722 ** CAPI3REF: Compile-Time Authorization Callbacks
2723 ** METHOD: sqlite3
2724 **
2725 ** ^This routine registers an authorizer callback with a particular
2726 ** [database connection], supplied in the first argument.
2727 ** ^The authorizer callback is invoked as SQL statements are being compiled
2728 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2862,10 +2875,11 @@
2875 #define SQLITE_COPY 0 /* No longer used */
2876 #define SQLITE_RECURSIVE 33 /* NULL NULL */
2877
2878 /*
2879 ** CAPI3REF: Tracing And Profiling Functions
2880 ** METHOD: sqlite3
2881 **
2882 ** These routines register callback functions that can be used for
2883 ** tracing and profiling the execution of SQL statements.
2884 **
2885 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2894,10 +2908,11 @@
2908 SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
2909 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2910
2911 /*
2912 ** CAPI3REF: Query Progress Callbacks
2913 ** METHOD: sqlite3
2914 **
2915 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2916 ** function X to be invoked periodically during long running calls to
2917 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2918 ** database connection D. An example use for this
@@ -2927,10 +2942,11 @@
2942 */
2943 SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2944
2945 /*
2946 ** CAPI3REF: Opening A New Database Connection
2947 ** CONSTRUCTOR: sqlite3
2948 **
2949 ** ^These routines open an SQLite database file as specified by the
2950 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2951 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2952 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3212,10 +3228,11 @@
3228 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3229
3230
3231 /*
3232 ** CAPI3REF: Error Codes And Messages
3233 ** METHOD: sqlite3
3234 **
3235 ** ^If the most recent sqlite3_* API call associated with
3236 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3237 ** returns the numeric [result code] or [extended result code] for that
3238 ** API call.
@@ -3257,37 +3274,38 @@
3274 SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
3275 SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
3276 SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
3277
3278 /*
3279 ** CAPI3REF: Prepared Statement Object
3280 ** KEYWORDS: {prepared statement} {prepared statements}
3281 **
3282 ** An instance of this object represents a single SQL statement that
3283 ** has been compiled into binary form and is ready to be evaluated.
 
3284 **
3285 ** Think of each SQL statement as a separate computer program. The
3286 ** original SQL text is source code. A prepared statement object
3287 ** is the compiled object code. All SQL must be converted into a
3288 ** prepared statement before it can be run.
3289 **
3290 ** The life-cycle of a prepared statement object usually goes like this:
3291 **
3292 ** <ol>
3293 ** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
3294 ** <li> Bind values to [parameters] using the sqlite3_bind_*()
 
3295 ** interfaces.
3296 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3297 ** <li> Reset the prepared statement using [sqlite3_reset()] then go back
3298 ** to step 2. Do this zero or more times.
3299 ** <li> Destroy the object using [sqlite3_finalize()].
3300 ** </ol>
 
 
 
3301 */
3302 typedef struct sqlite3_stmt sqlite3_stmt;
3303
3304 /*
3305 ** CAPI3REF: Run-time Limits
3306 ** METHOD: sqlite3
3307 **
3308 ** ^(This interface allows the size of various constructs to be limited
3309 ** on a connection by connection basis. The first parameter is the
3310 ** [database connection] whose limit is to be set or queried. The
3311 ** second parameter is one of the [limit categories] that define a
@@ -3395,10 +3413,12 @@
3413 #define SQLITE_LIMIT_WORKER_THREADS 11
3414
3415 /*
3416 ** CAPI3REF: Compiling An SQL Statement
3417 ** KEYWORDS: {SQL statement compiler}
3418 ** METHOD: sqlite3
3419 ** CONSTRUCTOR: sqlite3_stmt
3420 **
3421 ** To execute an SQL query, it must first be compiled into a byte-code
3422 ** program using one of these routines.
3423 **
3424 ** The first argument, "db", is a [database connection] obtained from a
@@ -3502,19 +3522,21 @@
3522 const void **pzTail /* OUT: Pointer to unused portion of zSql */
3523 );
3524
3525 /*
3526 ** CAPI3REF: Retrieving Statement SQL
3527 ** METHOD: sqlite3_stmt
3528 **
3529 ** ^This interface can be used to retrieve a saved copy of the original
3530 ** SQL text used to create a [prepared statement] if that statement was
3531 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
3532 */
3533 SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
3534
3535 /*
3536 ** CAPI3REF: Determine If An SQL Statement Writes The Database
3537 ** METHOD: sqlite3_stmt
3538 **
3539 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3540 ** and only if the [prepared statement] X makes no direct changes to
3541 ** the content of the database file.
3542 **
@@ -3542,10 +3564,11 @@
3564 */
3565 SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3566
3567 /*
3568 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3569 ** METHOD: sqlite3_stmt
3570 **
3571 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3572 ** [prepared statement] S has been stepped at least once using
3573 ** [sqlite3_step(S)] but has not run to completion and/or has not
3574 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3616,10 +3639,11 @@
3639
3640 /*
3641 ** CAPI3REF: Binding Values To Prepared Statements
3642 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3643 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3644 ** METHOD: sqlite3_stmt
3645 **
3646 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3647 ** literals may be replaced by a [parameter] that matches one of following
3648 ** templates:
3649 **
@@ -3734,10 +3758,11 @@
3758 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3759 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3760
3761 /*
3762 ** CAPI3REF: Number Of SQL Parameters
3763 ** METHOD: sqlite3_stmt
3764 **
3765 ** ^This routine can be used to find the number of [SQL parameters]
3766 ** in a [prepared statement]. SQL parameters are tokens of the
3767 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
3768 ** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3754,10 +3779,11 @@
3779 */
3780 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
3781
3782 /*
3783 ** CAPI3REF: Name Of A Host Parameter
3784 ** METHOD: sqlite3_stmt
3785 **
3786 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
3787 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
3788 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3789 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3781,10 +3807,11 @@
3807 */
3808 SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
3809
3810 /*
3811 ** CAPI3REF: Index Of A Parameter With A Given Name
3812 ** METHOD: sqlite3_stmt
3813 **
3814 ** ^Return the index of an SQL parameter given its name. ^The
3815 ** index value returned is suitable for use as the second
3816 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
3817 ** is returned if no matching parameter is found. ^The parameter
@@ -3797,19 +3824,21 @@
3824 */
3825 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
3826
3827 /*
3828 ** CAPI3REF: Reset All Bindings On A Prepared Statement
3829 ** METHOD: sqlite3_stmt
3830 **
3831 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
3832 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3833 ** ^Use this routine to reset all host parameters to NULL.
3834 */
3835 SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
3836
3837 /*
3838 ** CAPI3REF: Number Of Columns In A Result Set
3839 ** METHOD: sqlite3_stmt
3840 **
3841 ** ^Return the number of columns in the result set returned by the
3842 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3843 ** statement that does not return data (for example an [UPDATE]).
3844 **
@@ -3817,10 +3846,11 @@
3846 */
3847 SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
3848
3849 /*
3850 ** CAPI3REF: Column Names In A Result Set
3851 ** METHOD: sqlite3_stmt
3852 **
3853 ** ^These routines return the name assigned to a particular column
3854 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
3855 ** interface returns a pointer to a zero-terminated UTF-8 string
3856 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3846,10 +3876,11 @@
3876 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
3877 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
3878
3879 /*
3880 ** CAPI3REF: Source Of Data In A Query Result
3881 ** METHOD: sqlite3_stmt
3882 **
3883 ** ^These routines provide a means to determine the database, table, and
3884 ** table column that is the origin of a particular result column in
3885 ** [SELECT] statement.
3886 ** ^The name of the database or table or column can be returned as
@@ -3898,10 +3929,11 @@
3929 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
3930 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
3931
3932 /*
3933 ** CAPI3REF: Declared Datatype Of A Query Result
3934 ** METHOD: sqlite3_stmt
3935 **
3936 ** ^(The first parameter is a [prepared statement].
3937 ** If this statement is a [SELECT] statement and the Nth column of the
3938 ** returned result set of that [SELECT] is a table column (not an
3939 ** expression or subquery) then the declared type of the table
@@ -3930,10 +3962,11 @@
3962 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
3963 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
3964
3965 /*
3966 ** CAPI3REF: Evaluate An SQL Statement
3967 ** METHOD: sqlite3_stmt
3968 **
3969 ** After a [prepared statement] has been prepared using either
3970 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
3971 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
3972 ** must be called one or more times to evaluate the statement.
@@ -4009,10 +4042,11 @@
4042 */
4043 SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
4044
4045 /*
4046 ** CAPI3REF: Number of columns in a result set
4047 ** METHOD: sqlite3_stmt
4048 **
4049 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
4050 ** current row of the result set of [prepared statement] P.
4051 ** ^If prepared statement P does not have results ready to return
4052 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -4062,10 +4096,11 @@
4096 #define SQLITE3_TEXT 3
4097
4098 /*
4099 ** CAPI3REF: Result Values From A Query
4100 ** KEYWORDS: {column access functions}
4101 ** METHOD: sqlite3_stmt
4102 **
4103 ** These routines form the "result set" interface.
4104 **
4105 ** ^These routines return information about a single column of the current
4106 ** result row of a query. ^In every case the first argument is a pointer
@@ -4234,10 +4269,11 @@
4269 SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
4270 SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
4271
4272 /*
4273 ** CAPI3REF: Destroy A Prepared Statement Object
4274 ** DESTRUCTOR: sqlite3_stmt
4275 **
4276 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
4277 ** ^If the most recent evaluation of the statement encountered no errors
4278 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
4279 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4261,10 +4297,11 @@
4297 */
4298 SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
4299
4300 /*
4301 ** CAPI3REF: Reset A Prepared Statement Object
4302 ** METHOD: sqlite3_stmt
4303 **
4304 ** The sqlite3_reset() function is called to reset a [prepared statement]
4305 ** object back to its initial state, ready to be re-executed.
4306 ** ^Any SQL statement variables that had values bound to them using
4307 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4290,10 +4327,11 @@
4327 /*
4328 ** CAPI3REF: Create Or Redefine SQL Functions
4329 ** KEYWORDS: {function creation routines}
4330 ** KEYWORDS: {application-defined SQL function}
4331 ** KEYWORDS: {application-defined SQL functions}
4332 ** METHOD: sqlite3
4333 **
4334 ** ^These functions (collectively known as "function creation routines")
4335 ** are used to add SQL functions or aggregates or to redefine the behavior
4336 ** of existing SQL functions or aggregates. The only differences between
4337 ** these routines are the text encoding expected for
@@ -4459,10 +4497,11 @@
4497 void*,sqlite3_int64);
4498 #endif
4499
4500 /*
4501 ** CAPI3REF: Obtaining SQL Function Parameter Values
4502 ** METHOD: sqlite3_value
4503 **
4504 ** The C-language implementation of SQL functions and aggregates uses
4505 ** this set of interface routines to access the parameter values on
4506 ** the function or aggregate.
4507 **
@@ -4517,10 +4556,11 @@
4556 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4557 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4558
4559 /*
4560 ** CAPI3REF: Obtain Aggregate Function Context
4561 ** METHOD: sqlite3_context
4562 **
4563 ** Implementations of aggregate SQL functions use this
4564 ** routine to allocate memory for storing their state.
4565 **
4566 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4561,10 +4601,11 @@
4601 */
4602 SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
4603
4604 /*
4605 ** CAPI3REF: User Data For Functions
4606 ** METHOD: sqlite3_context
4607 **
4608 ** ^The sqlite3_user_data() interface returns a copy of
4609 ** the pointer that was the pUserData parameter (the 5th parameter)
4610 ** of the [sqlite3_create_function()]
4611 ** and [sqlite3_create_function16()] routines that originally
@@ -4575,10 +4616,11 @@
4616 */
4617 SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
4618
4619 /*
4620 ** CAPI3REF: Database Connection For Functions
4621 ** METHOD: sqlite3_context
4622 **
4623 ** ^The sqlite3_context_db_handle() interface returns a copy of
4624 ** the pointer to the [database connection] (the 1st parameter)
4625 ** of the [sqlite3_create_function()]
4626 ** and [sqlite3_create_function16()] routines that originally
@@ -4586,10 +4628,11 @@
4628 */
4629 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
4630
4631 /*
4632 ** CAPI3REF: Function Auxiliary Data
4633 ** METHOD: sqlite3_context
4634 **
4635 ** These functions may be used by (non-aggregate) SQL functions to
4636 ** associate metadata with argument values. If the same value is passed to
4637 ** multiple invocations of the same SQL function during query execution, under
4638 ** some circumstances the associated metadata may be preserved. An example
@@ -4658,10 +4701,11 @@
4701 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
4702 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
4703
4704 /*
4705 ** CAPI3REF: Setting The Result Of An SQL Function
4706 ** METHOD: sqlite3_context
4707 **
4708 ** These routines are used by the xFunc or xFinal callbacks that
4709 ** implement SQL functions and aggregates. See
4710 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
4711 ** for additional information.
@@ -4793,10 +4837,11 @@
4837 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4838 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4839
4840 /*
4841 ** CAPI3REF: Define New Collating Sequences
4842 ** METHOD: sqlite3
4843 **
4844 ** ^These functions add, remove, or modify a [collation] associated
4845 ** with the [database connection] specified as the first argument.
4846 **
4847 ** ^The name of the collation is a UTF-8 string
@@ -4895,10 +4940,11 @@
4940 int(*xCompare)(void*,int,const void*,int,const void*)
4941 );
4942
4943 /*
4944 ** CAPI3REF: Collation Needed Callbacks
4945 ** METHOD: sqlite3
4946 **
4947 ** ^To avoid having to register all collation sequences before a database
4948 ** can be used, a single callback function may be registered with the
4949 ** [database connection] to be invoked whenever an undefined collation
4950 ** sequence is required.
@@ -5102,10 +5148,11 @@
5148 SQLITE_API char *sqlite3_data_directory;
5149
5150 /*
5151 ** CAPI3REF: Test For Auto-Commit Mode
5152 ** KEYWORDS: {autocommit mode}
5153 ** METHOD: sqlite3
5154 **
5155 ** ^The sqlite3_get_autocommit() interface returns non-zero or
5156 ** zero if the given database connection is or is not in autocommit mode,
5157 ** respectively. ^Autocommit mode is on by default.
5158 ** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -5124,10 +5171,11 @@
5171 */
5172 SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
5173
5174 /*
5175 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
5176 ** METHOD: sqlite3_stmt
5177 **
5178 ** ^The sqlite3_db_handle interface returns the [database connection] handle
5179 ** to which a [prepared statement] belongs. ^The [database connection]
5180 ** returned by sqlite3_db_handle is the same [database connection]
5181 ** that was the first argument
@@ -5136,10 +5184,11 @@
5184 */
5185 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
5186
5187 /*
5188 ** CAPI3REF: Return The Filename For A Database Connection
5189 ** METHOD: sqlite3
5190 **
5191 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
5192 ** associated with database N of connection D. ^The main database file
5193 ** has the name "main". If there is no attached database N on the database
5194 ** connection D, or if database N is a temporary or in-memory database, then
@@ -5152,19 +5201,21 @@
5201 */
5202 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
5203
5204 /*
5205 ** CAPI3REF: Determine if a database is read-only
5206 ** METHOD: sqlite3
5207 **
5208 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
5209 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
5210 ** the name of a database on connection D.
5211 */
5212 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5213
5214 /*
5215 ** CAPI3REF: Find the next prepared statement
5216 ** METHOD: sqlite3
5217 **
5218 ** ^This interface returns a pointer to the next [prepared statement] after
5219 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
5220 ** then this interface returns a pointer to the first prepared statement
5221 ** associated with the database connection pDb. ^If no prepared statement
@@ -5176,10 +5227,11 @@
5227 */
5228 SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
5229
5230 /*
5231 ** CAPI3REF: Commit And Rollback Notification Callbacks
5232 ** METHOD: sqlite3
5233 **
5234 ** ^The sqlite3_commit_hook() interface registers a callback
5235 ** function to be invoked whenever a transaction is [COMMIT | committed].
5236 ** ^Any callback set by a previous call to sqlite3_commit_hook()
5237 ** for the same database connection is overridden.
@@ -5225,10 +5277,11 @@
5277 SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
5278 SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5279
5280 /*
5281 ** CAPI3REF: Data Change Notification Callbacks
5282 ** METHOD: sqlite3
5283 **
5284 ** ^The sqlite3_update_hook() interface registers a callback function
5285 ** with the [database connection] identified by the first argument
5286 ** to be invoked whenever a row is updated, inserted or deleted in
5287 ** a rowid table.
@@ -5331,10 +5384,11 @@
5384 */
5385 SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
5386
5387 /*
5388 ** CAPI3REF: Free Memory Used By A Database Connection
5389 ** METHOD: sqlite3
5390 **
5391 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5392 ** memory as possible from database connection D. Unlike the
5393 ** [sqlite3_release_memory()] interface, this interface is in effect even
5394 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5408,10 +5462,11 @@
5462 SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
5463
5464
5465 /*
5466 ** CAPI3REF: Extract Metadata About A Column Of A Table
5467 ** METHOD: sqlite3
5468 **
5469 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5470 ** information about column C of table T in database D
5471 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5472 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5486,10 +5541,11 @@
5541 int *pAutoinc /* OUTPUT: True if column is auto-increment */
5542 );
5543
5544 /*
5545 ** CAPI3REF: Load An Extension
5546 ** METHOD: sqlite3
5547 **
5548 ** ^This interface loads an SQLite extension library from the named file.
5549 **
5550 ** ^The sqlite3_load_extension() interface attempts to load an
5551 ** [SQLite extension] library contained in the file zFile. If
@@ -5527,10 +5583,11 @@
5583 char **pzErrMsg /* Put error message here if not 0 */
5584 );
5585
5586 /*
5587 ** CAPI3REF: Enable Or Disable Extension Loading
5588 ** METHOD: sqlite3
5589 **
5590 ** ^So as not to open security holes in older applications that are
5591 ** unprepared to deal with [extension loading], and as a means of disabling
5592 ** [extension loading] while evaluating user-entered SQL, the following API
5593 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5776,10 +5833,11 @@
5833 #define SQLITE_INDEX_CONSTRAINT_GE 32
5834 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
5835
5836 /*
5837 ** CAPI3REF: Register A Virtual Table Implementation
5838 ** METHOD: sqlite3
5839 **
5840 ** ^These routines are used to register a new [virtual table module] name.
5841 ** ^Module names must be registered before
5842 ** creating a new [virtual table] using the module and before using a
5843 ** preexisting [virtual table] for the module.
@@ -5872,10 +5930,11 @@
5930 */
5931 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
5932
5933 /*
5934 ** CAPI3REF: Overload A Function For A Virtual Table
5935 ** METHOD: sqlite3
5936 **
5937 ** ^(Virtual tables can provide alternative implementations of functions
5938 ** using the [xFindFunction] method of the [virtual table module].
5939 ** But global versions of those functions
5940 ** must exist in order to be overloaded.)^
@@ -5914,10 +5973,12 @@
5973 */
5974 typedef struct sqlite3_blob sqlite3_blob;
5975
5976 /*
5977 ** CAPI3REF: Open A BLOB For Incremental I/O
5978 ** METHOD: sqlite3
5979 ** CONSTRUCTOR: sqlite3_blob
5980 **
5981 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
5982 ** in row iRow, column zColumn, table zTable in database zDb;
5983 ** in other words, the same BLOB that would be selected by:
5984 **
@@ -5995,10 +6056,11 @@
6056 sqlite3_blob **ppBlob
6057 );
6058
6059 /*
6060 ** CAPI3REF: Move a BLOB Handle to a New Row
6061 ** METHOD: sqlite3_blob
6062 **
6063 ** ^This function is used to move an existing blob handle so that it points
6064 ** to a different row of the same database table. ^The new row is identified
6065 ** by the rowid value passed as the second argument. Only the row can be
6066 ** changed. ^The database, table and column on which the blob handle is open
@@ -6019,10 +6081,11 @@
6081 */
6082 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
6083
6084 /*
6085 ** CAPI3REF: Close A BLOB Handle
6086 ** DESTRUCTOR: sqlite3_blob
6087 **
6088 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
6089 ** unconditionally. Even if this routine returns an error code, the
6090 ** handle is still closed.)^
6091 **
@@ -6041,10 +6104,11 @@
6104 */
6105 SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
6106
6107 /*
6108 ** CAPI3REF: Return The Size Of An Open BLOB
6109 ** METHOD: sqlite3_blob
6110 **
6111 ** ^Returns the size in bytes of the BLOB accessible via the
6112 ** successfully opened [BLOB handle] in its only argument. ^The
6113 ** incremental blob I/O routines can only read or overwriting existing
6114 ** blob content; they cannot change the size of a blob.
@@ -6056,10 +6120,11 @@
6120 */
6121 SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
6122
6123 /*
6124 ** CAPI3REF: Read Data From A BLOB Incrementally
6125 ** METHOD: sqlite3_blob
6126 **
6127 ** ^(This function is used to read data from an open [BLOB handle] into a
6128 ** caller-supplied buffer. N bytes of data are copied into buffer Z
6129 ** from the open BLOB, starting at offset iOffset.)^
6130 **
@@ -6084,10 +6149,11 @@
6149 */
6150 SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
6151
6152 /*
6153 ** CAPI3REF: Write Data Into A BLOB Incrementally
6154 ** METHOD: sqlite3_blob
6155 **
6156 ** ^(This function is used to write data into an open [BLOB handle] from a
6157 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
6158 ** into the open BLOB, starting at offset iOffset.)^
6159 **
@@ -6411,10 +6477,11 @@
6477 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6478 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6479
6480 /*
6481 ** CAPI3REF: Retrieve the mutex for a database connection
6482 ** METHOD: sqlite3
6483 **
6484 ** ^This interface returns a pointer the [sqlite3_mutex] object that
6485 ** serializes access to the [database connection] given in the argument
6486 ** when the [threading mode] is Serialized.
6487 ** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6422,10 +6489,11 @@
6489 */
6490 SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
6491
6492 /*
6493 ** CAPI3REF: Low-Level Control Of Database Files
6494 ** METHOD: sqlite3
6495 **
6496 ** ^The [sqlite3_file_control()] interface makes a direct call to the
6497 ** xFileControl method for the [sqlite3_io_methods] object associated
6498 ** with a particular database identified by the second argument. ^The
6499 ** name of the database is "main" for the main database or "temp" for the
@@ -6638,10 +6706,11 @@
6706 #define SQLITE_STATUS_SCRATCH_SIZE 8
6707 #define SQLITE_STATUS_MALLOC_COUNT 9
6708
6709 /*
6710 ** CAPI3REF: Database Connection Status
6711 ** METHOD: sqlite3
6712 **
6713 ** ^This interface is used to retrieve runtime status information
6714 ** about a single [database connection]. ^The first argument is the
6715 ** database connection object to be interrogated. ^The second argument
6716 ** is an integer constant, taken from the set of
@@ -6766,10 +6835,11 @@
6835 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
6836
6837
6838 /*
6839 ** CAPI3REF: Prepared Statement Status
6840 ** METHOD: sqlite3_stmt
6841 **
6842 ** ^(Each prepared statement maintains various
6843 ** [SQLITE_STMTSTATUS counters] that measure the number
6844 ** of times it has performed specific operations.)^ These counters can
6845 ** be used to monitor the performance characteristics of the prepared
@@ -7269,10 +7339,11 @@
7339 SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
7340 SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
7341
7342 /*
7343 ** CAPI3REF: Unlock Notification
7344 ** METHOD: sqlite3
7345 **
7346 ** ^When running in shared-cache mode, a database operation may fail with
7347 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
7348 ** individual tables within the shared-cache cannot be obtained. See
7349 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7439,10 +7510,11 @@
7510 */
7511 SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
7512
7513 /*
7514 ** CAPI3REF: Write-Ahead Log Commit Hook
7515 ** METHOD: sqlite3
7516 **
7517 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7518 ** is invoked each time data is committed to a database in wal mode.
7519 **
7520 ** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7478,10 +7550,11 @@
7550 void*
7551 );
7552
7553 /*
7554 ** CAPI3REF: Configure an auto-checkpoint
7555 ** METHOD: sqlite3
7556 **
7557 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
7558 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
7559 ** to automatically [checkpoint]
7560 ** after committing a transaction if there are N or
@@ -7508,10 +7581,11 @@
7581 */
7582 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7583
7584 /*
7585 ** CAPI3REF: Checkpoint a database
7586 ** METHOD: sqlite3
7587 **
7588 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7589 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7590 **
7591 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7529,10 +7603,11 @@
7603 */
7604 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7605
7606 /*
7607 ** CAPI3REF: Checkpoint a database
7608 ** METHOD: sqlite3
7609 **
7610 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7611 ** operation on database X of [database connection] D in mode M. Status
7612 ** information is written back into integers pointed to by L and C.)^
7613 ** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7783,10 +7858,11 @@
7858 #define SQLITE_SCANSTAT_EXPLAIN 4
7859 #define SQLITE_SCANSTAT_SELECTID 5
7860
7861 /*
7862 ** CAPI3REF: Prepared Statement Scan Status
7863 ** METHOD: sqlite3_stmt
7864 **
7865 ** This interface returns information about the predicted and measured
7866 ** performance for pStmt. Advanced applications can use this
7867 ** interface to compare the predicted and the measured performance and
7868 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7820,10 +7896,11 @@
7896 void *pOut /* Result written here */
7897 );
7898
7899 /*
7900 ** CAPI3REF: Zero Scan-Status Counters
7901 ** METHOD: sqlite3_stmt
7902 **
7903 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7904 **
7905 ** This API is only available if the library is built with pre-processor
7906 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
@@ -8430,10 +8507,36 @@
8507 #else
8508 # define ALWAYS(X) (X)
8509 # define NEVER(X) (X)
8510 #endif
8511
8512 /*
8513 ** Declarations used for tracing the operating system interfaces.
8514 */
8515 #if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \
8516 (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
8517 extern int sqlite3OSTrace;
8518 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
8519 # define SQLITE_HAVE_OS_TRACE
8520 #else
8521 # define OSTRACE(X)
8522 # undef SQLITE_HAVE_OS_TRACE
8523 #endif
8524
8525 /*
8526 ** Is the sqlite3ErrName() function needed in the build? Currently,
8527 ** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when
8528 ** OSTRACE is enabled), and by several "test*.c" files (which are
8529 ** compiled using SQLITE_TEST).
8530 */
8531 #if defined(SQLITE_HAVE_OS_TRACE) || defined(SQLITE_TEST) || \
8532 (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
8533 # define SQLITE_NEED_ERR_NAME
8534 #else
8535 # undef SQLITE_NEED_ERR_NAME
8536 #endif
8537
8538 /*
8539 ** Return true (non-zero) if the input is an integer that is too large
8540 ** to fit in 32-bits. This macro is used inside of various testcase()
8541 ** macros to verify that we have tested SQLite for large-file support.
8542 */
@@ -9841,37 +9944,36 @@
9944 /* Properties such as "out2" or "jump" that are specified in
9945 ** comments following the "case" for each opcode in the vdbe.c
9946 ** are encoded into bitvectors as follows:
9947 */
9948 #define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */
9949 #define OPFLG_IN1 0x0002 /* in1: P1 is an input */
9950 #define OPFLG_IN2 0x0004 /* in2: P2 is an input */
9951 #define OPFLG_IN3 0x0008 /* in3: P3 is an input */
9952 #define OPFLG_OUT2 0x0010 /* out2: P2 is an output */
9953 #define OPFLG_OUT3 0x0020 /* out3: P3 is an output */
 
9954 #define OPFLG_INITIALIZER {\
9955 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9956 /* 8 */ 0x01, 0x01, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
9957 /* 16 */ 0x01, 0x01, 0x02, 0x12, 0x01, 0x02, 0x03, 0x08,\
9958 /* 24 */ 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10,\
9959 /* 32 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x03, 0x02,\
9960 /* 40 */ 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00,\
9961 /* 48 */ 0x00, 0x00, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,\
9962 /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09,\
9963 /* 64 */ 0x09, 0x09, 0x04, 0x09, 0x09, 0x09, 0x09, 0x26,\
9964 /* 72 */ 0x26, 0x10, 0x10, 0x00, 0x03, 0x03, 0x0b, 0x0b,\
9965 /* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x26, 0x26, 0x26,\
9966 /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
9967 /* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
9968 /* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04, 0x00,\
9969 /* 112 */ 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00, 0x00,\
9970 /* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9971 /* 128 */ 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00, 0x01,\
9972 /* 136 */ 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x01,\
9973 /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\
9974 /* 152 */ 0x00, 0x10, 0x10, 0x01, 0x00, 0x00,}
9975
9976 /************** End of opcodes.h *********************************************/
9977 /************** Continuing where we left off in vdbe.h ***********************/
9978
9979 /*
@@ -9926,10 +10028,11 @@
10028 #endif
10029 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
10030
10031 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
10032 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
10033 SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
10034 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
10035
10036 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
10037 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
10038
@@ -11063,10 +11166,11 @@
11166 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
11167 #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
11168 #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
11169 #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
11170 #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
11171 #define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */
11172
11173
11174 /*
11175 ** Bits of the sqlite3.dbOptFlags field that are used by the
11176 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -11393,38 +11497,12 @@
11497 int iSavepoint; /* Depth of the SAVEPOINT stack */
11498 VTable *pNext; /* Next in linked list (see above) */
11499 };
11500
11501 /*
11502 ** The schema for each SQL table and view is represented in memory
11503 ** by an instance of the following structure.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11504 */
11505 struct Table {
11506 char *zName; /* Name of the table or view */
11507 Column *aCol; /* Information about each column */
11508 Index *pIndex; /* List of SQL indexes on this table. */
@@ -11432,15 +11510,15 @@
11510 FKey *pFKey; /* Linked list of all foreign keys in this table */
11511 char *zColAff; /* String defining the affinity of each column */
11512 #ifndef SQLITE_OMIT_CHECK
11513 ExprList *pCheck; /* All CHECK constraints */
11514 #endif
11515 int tnum; /* Root BTree page for this table */
11516 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
 
11517 i16 nCol; /* Number of columns in this table */
11518 u16 nRef; /* Number of pointers to this Table */
11519 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
11520 LogEst szTabRow; /* Estimated size of each table row in bytes */
11521 #ifdef SQLITE_ENABLE_COSTMULT
11522 LogEst costMult; /* Cost multiplier for using this table */
11523 #endif
11524 u8 tabFlags; /* Mask of TF_* values */
@@ -11458,17 +11536,24 @@
11536 Table *pNextZombie; /* Next on the Parse.pZombieTab list */
11537 };
11538
11539 /*
11540 ** Allowed values for Table.tabFlags.
11541 **
11542 ** TF_OOOHidden applies to virtual tables that have hidden columns that are
11543 ** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING
11544 ** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden,
11545 ** the TF_OOOHidden attribute would apply in this case. Such tables require
11546 ** special handling during INSERT processing.
11547 */
11548 #define TF_Readonly 0x01 /* Read-only system table */
11549 #define TF_Ephemeral 0x02 /* An ephemeral table */
11550 #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
11551 #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
11552 #define TF_Virtual 0x10 /* Is a virtual table */
11553 #define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */
11554 #define TF_OOOHidden 0x40 /* Out-of-Order hidden columns */
11555
11556
11557 /*
11558 ** Test to see whether or not a table is a virtual table. This is
11559 ** done as a macro so that it will be optimized out when virtual
@@ -12221,11 +12306,11 @@
12306 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
12307 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
12308 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
12309 #define SF_Compound 0x0040 /* Part of a compound query */
12310 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
12311 #define SF_MultiValue 0x0100 /* Single VALUES term with multiple rows */
12312 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
12313 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
12314 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
12315 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
12316 #define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */
@@ -12605,24 +12690,24 @@
12690 *
12691 * (op == TK_INSERT)
12692 * orconf -> stores the ON CONFLICT algorithm
12693 * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
12694 * this stores a pointer to the SELECT statement. Otherwise NULL.
12695 * zTarget -> Dequoted name of the table to insert into.
12696 * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
12697 * this stores values to be inserted. Otherwise NULL.
12698 * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
12699 * statement, then this stores the column-names to be
12700 * inserted into.
12701 *
12702 * (op == TK_DELETE)
12703 * zTarget -> Dequoted name of the table to delete from.
12704 * pWhere -> The WHERE clause of the DELETE statement if one is specified.
12705 * Otherwise NULL.
12706 *
12707 * (op == TK_UPDATE)
12708 * zTarget -> Dequoted name of the table to update.
12709 * pWhere -> The WHERE clause of the UPDATE statement if one is specified.
12710 * Otherwise NULL.
12711 * pExprList -> A list of the columns to update and the expressions to update
12712 * them to. See sqlite3Update() documentation of "pChanges"
12713 * argument.
@@ -12630,12 +12715,12 @@
12715 */
12716 struct TriggerStep {
12717 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
12718 u8 orconf; /* OE_Rollback etc. */
12719 Trigger *pTrig; /* The trigger that this step is a part of */
12720 Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */
12721 char *zTarget; /* Target table for DELETE, UPDATE, INSERT */
12722 Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
12723 ExprList *pExprList; /* SET clause for UPDATE. */
12724 IdList *pIdList; /* Column names for INSERT */
12725 TriggerStep *pNext; /* Next in the link-list */
12726 TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
@@ -12664,12 +12749,11 @@
12749 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
12750 char *zBase; /* A base allocation. Not from malloc. */
12751 char *zText; /* The string collected so far */
12752 int nChar; /* Length of the string so far */
12753 int nAlloc; /* Amount of space allocated in zText */
12754 int mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
 
12755 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
12756 };
12757 #define STRACCUM_NOMEM 1
12758 #define STRACCUM_TOOBIG 2
12759
@@ -12982,11 +13066,11 @@
13066 SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
13067 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
13068 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
13069 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
13070 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
13071 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
13072 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
13073 #endif
13074 #if defined(SQLITE_TEST)
13075 SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
13076 #endif
@@ -13329,11 +13413,11 @@
13413 SQLITE_PRIVATE void sqlite3Error(sqlite3*,int);
13414 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
13415 SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
13416 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
13417
13418 #if defined(SQLITE_NEED_ERR_NAME)
13419 SQLITE_PRIVATE const char *sqlite3ErrName(int);
13420 #endif
13421
13422 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
13423 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -13423,11 +13507,11 @@
13507 FuncDestructor *pDestructor
13508 );
13509 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
13510 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
13511
13512 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
13513 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
13514 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
13515 SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char);
13516 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
13517 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
@@ -14039,10 +14123,13 @@
14123 #if SQLITE_ENABLE_CEROD
14124 "ENABLE_CEROD",
14125 #endif
14126 #if SQLITE_ENABLE_COLUMN_METADATA
14127 "ENABLE_COLUMN_METADATA",
14128 #endif
14129 #if SQLITE_ENABLE_DBSTAT_VTAB
14130 "ENABLE_DBSTAT_VTAB",
14131 #endif
14132 #if SQLITE_ENABLE_EXPENSIVE_ASSERT
14133 "ENABLE_EXPENSIVE_ASSERT",
14134 #endif
14135 #if SQLITE_ENABLE_FTS1
@@ -19807,20 +19894,10 @@
19894 */
19895 #ifdef MEMORY_DEBUG
19896 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
19897 #endif
19898
 
 
 
 
 
 
 
 
 
 
19899 /*
19900 ** Macros for performance tracing. Normally turned off. Only works
19901 ** on i486 hardware.
19902 */
19903 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -21401,10 +21478,11 @@
21478
21479 /*
21480 ** Set the StrAccum object to an error mode.
21481 */
21482 static void setStrAccumError(StrAccum *p, u8 eError){
21483 assert( eError==STRACCUM_NOMEM || eError==STRACCUM_TOOBIG );
21484 p->accError = eError;
21485 p->nAlloc = 0;
21486 }
21487
21488 /*
@@ -21515,11 +21593,10 @@
21593 case '0': flag_zeropad = 1; break;
21594 default: done = 1; break;
21595 }
21596 }while( !done && (c=(*++fmt))!=0 );
21597 /* Get the field width */
 
21598 if( c=='*' ){
21599 if( bArgList ){
21600 width = (int)getIntArg(pArgList);
21601 }else{
21602 width = va_arg(ap,int);
@@ -21539,11 +21616,10 @@
21616 width = wx & 0x7fffffff;
21617 }
21618
21619 /* Get the precision */
21620 if( c=='.' ){
 
21621 c = *++fmt;
21622 if( c=='*' ){
21623 if( bArgList ){
21624 precision = (int)getIntArg(pArgList);
21625 }else{
@@ -22018,11 +22094,11 @@
22094 if( p->accError ){
22095 testcase(p->accError==STRACCUM_TOOBIG);
22096 testcase(p->accError==STRACCUM_NOMEM);
22097 return 0;
22098 }
22099 if( p->mxAlloc==0 ){
22100 N = p->nAlloc - p->nChar - 1;
22101 setStrAccumError(p, STRACCUM_TOOBIG);
22102 return N;
22103 }else{
22104 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
@@ -22038,14 +22114,14 @@
22114 setStrAccumError(p, STRACCUM_TOOBIG);
22115 return 0;
22116 }else{
22117 p->nAlloc = (int)szNew;
22118 }
22119 if( p->db ){
22120 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
22121 }else{
22122 zNew = sqlite3_realloc64(zOld, p->nAlloc);
22123 }
22124 if( zNew ){
22125 assert( p->zText!=0 || p->nChar==0 );
22126 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
22127 p->zText = zNew;
@@ -22089,11 +22165,11 @@
22165 /*
22166 ** Append N bytes of text from z to the StrAccum object. Increase the
22167 ** size of the memory allocation for StrAccum if necessary.
22168 */
22169 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
22170 assert( z!=0 || N==0 );
22171 assert( p->zText!=0 || p->nChar==0 || p->accError );
22172 assert( N>=0 );
22173 assert( p->accError==0 || p->nAlloc==0 );
22174 if( p->nChar+N >= p->nAlloc ){
22175 enlargeAndAppend(p,z,N);
@@ -22118,16 +22194,12 @@
22194 ** pointer if any kind of error was encountered.
22195 */
22196 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
22197 if( p->zText ){
22198 p->zText[p->nChar] = 0;
22199 if( p->mxAlloc>0 && p->zText==p->zBase ){
22200 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
 
 
 
 
22201 if( p->zText ){
22202 memcpy(p->zText, p->zBase, p->nChar+1);
22203 }else{
22204 setStrAccumError(p, STRACCUM_NOMEM);
22205 }
@@ -22139,29 +22211,35 @@
22211 /*
22212 ** Reset an StrAccum string. Reclaim all malloced memory.
22213 */
22214 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
22215 if( p->zText!=p->zBase ){
22216 sqlite3DbFree(p->db, p->zText);
 
 
 
 
22217 }
22218 p->zText = 0;
22219 }
22220
22221 /*
22222 ** Initialize a string accumulator.
22223 **
22224 ** p: The accumulator to be initialized.
22225 ** db: Pointer to a database connection. May be NULL. Lookaside
22226 ** memory is used if not NULL. db->mallocFailed is set appropriately
22227 ** when not NULL.
22228 ** zBase: An initial buffer. May be NULL in which case the initial buffer
22229 ** is malloced.
22230 ** n: Size of zBase in bytes. If total space requirements never exceed
22231 ** n then no memory allocations ever occur.
22232 ** mx: Maximum number of bytes to accumulate. If mx==0 then no memory
22233 ** allocations will ever occur.
22234 */
22235 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){
22236 p->zText = p->zBase = zBase;
22237 p->db = db;
22238 p->nChar = 0;
22239 p->nAlloc = n;
22240 p->mxAlloc = mx;
 
22241 p->accError = 0;
22242 }
22243
22244 /*
22245 ** Print into memory obtained from sqliteMalloc(). Use the internal
@@ -22170,13 +22248,12 @@
22248 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
22249 char *z;
22250 char zBase[SQLITE_PRINT_BUF_SIZE];
22251 StrAccum acc;
22252 assert( db!=0 );
22253 sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase),
22254 db->aLimit[SQLITE_LIMIT_LENGTH]);
 
22255 sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap);
22256 z = sqlite3StrAccumFinish(&acc);
22257 if( acc.accError==STRACCUM_NOMEM ){
22258 db->mallocFailed = 1;
22259 }
@@ -22230,12 +22307,11 @@
22307 }
22308 #endif
22309 #ifndef SQLITE_OMIT_AUTOINIT
22310 if( sqlite3_initialize() ) return 0;
22311 #endif
22312 sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
 
22313 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22314 z = sqlite3StrAccumFinish(&acc);
22315 return z;
22316 }
22317
@@ -22276,12 +22352,11 @@
22352 (void)SQLITE_MISUSE_BKPT;
22353 if( zBuf ) zBuf[0] = 0;
22354 return zBuf;
22355 }
22356 #endif
22357 sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
 
22358 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22359 return sqlite3StrAccumFinish(&acc);
22360 }
22361 SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
22362 char *z;
@@ -22303,12 +22378,11 @@
22378 */
22379 static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
22380 StrAccum acc; /* String accumulator */
22381 char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
22382
22383 sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0);
 
22384 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22385 sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
22386 sqlite3StrAccumFinish(&acc));
22387 }
22388
@@ -22322,22 +22396,21 @@
22396 renderLogMsg(iErrCode, zFormat, ap);
22397 va_end(ap);
22398 }
22399 }
22400
22401 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
22402 /*
22403 ** A version of printf() that understands %lld. Used for debugging.
22404 ** The printf() built into some versions of windows does not understand %lld
22405 ** and segfaults if you give it a long long int.
22406 */
22407 SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){
22408 va_list ap;
22409 StrAccum acc;
22410 char zBuf[500];
22411 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
 
22412 va_start(ap,zFormat);
22413 sqlite3VXPrintf(&acc, 0, zFormat, ap);
22414 va_end(ap);
22415 sqlite3StrAccumFinish(&acc);
22416 fprintf(stdout,"%s", zBuf);
@@ -22360,11 +22433,11 @@
22433 */
22434 /* Add a new subitem to the tree. The moreToFollow flag indicates that this
22435 ** is not the last item in the tree. */
22436 SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){
22437 if( p==0 ){
22438 p = sqlite3_malloc64( sizeof(*p) );
22439 if( p==0 ) return 0;
22440 memset(p, 0, sizeof(*p));
22441 }else{
22442 p->iLevel++;
22443 }
@@ -22383,12 +22456,11 @@
22456 SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
22457 va_list ap;
22458 int i;
22459 StrAccum acc;
22460 char zBuf[500];
22461 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
 
22462 if( p ){
22463 for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
22464 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
22465 }
22466 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
@@ -24007,10 +24079,11 @@
24079 }else{
24080 return 0;
24081 }
24082 }
24083 #endif
24084 while( zNum[0]=='0' ) zNum++;
24085 for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
24086 v = v*10 + c;
24087 }
24088
24089 /* The longest decimal representation of a 32 bit integer is 10 digits:
@@ -25261,10 +25334,21 @@
25334 #if SQLITE_ENABLE_LOCKING_STYLE
25335 # include <sys/ioctl.h>
25336 # include <sys/file.h>
25337 # include <sys/param.h>
25338 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
25339
25340 #if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
25341 (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
25342 # if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \
25343 && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))
25344 # define HAVE_GETHOSTUUID 1
25345 # else
25346 # warning "gethostuuid() is disabled."
25347 # endif
25348 #endif
25349
25350
25351 #if OS_VXWORKS
25352 /* # include <sys/ioctl.h> */
25353 # include <semaphore.h>
25354 # include <limits.h>
@@ -25457,20 +25541,10 @@
25541 */
25542 #ifdef MEMORY_DEBUG
25543 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
25544 #endif
25545
 
 
 
 
 
 
 
 
 
 
25546 /*
25547 ** Macros for performance tracing. Normally turned off. Only works
25548 ** on i486 hardware.
25549 */
25550 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -26009,11 +26083,11 @@
26083 return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
26084 }
26085 #endif
26086
26087
26088 #ifdef SQLITE_HAVE_OS_TRACE
26089 /*
26090 ** Helper function for printing out trace information from debugging
26091 ** binaries. This returns the string representation of the supplied
26092 ** integer lock-type.
26093 */
@@ -26272,11 +26346,11 @@
26346 struct vxworksFileId *pCandidate; /* For looping over existing file IDs */
26347 int n; /* Length of zAbsoluteName string */
26348
26349 assert( zAbsoluteName[0]=='/' );
26350 n = (int)strlen(zAbsoluteName);
26351 pNew = sqlite3_malloc64( sizeof(*pNew) + (n+1) );
26352 if( pNew==0 ) return 0;
26353 pNew->zCanonicalName = (char*)&pNew[1];
26354 memcpy(pNew->zCanonicalName, zAbsoluteName, n+1);
26355 n = vxworksSimplifyName(pNew->zCanonicalName, n);
26356
@@ -26676,11 +26750,11 @@
26750 pInode = inodeList;
26751 while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
26752 pInode = pInode->pNext;
26753 }
26754 if( pInode==0 ){
26755 pInode = sqlite3_malloc64( sizeof(*pInode) );
26756 if( pInode==0 ){
26757 return SQLITE_NOMEM;
26758 }
26759 memset(pInode, 0, sizeof(*pInode));
26760 memcpy(&pInode->fileId, &fileId, sizeof(fileId));
@@ -29197,11 +29271,11 @@
29271 case SQLITE_FCNTL_VFSNAME: {
29272 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
29273 return SQLITE_OK;
29274 }
29275 case SQLITE_FCNTL_TEMPFILENAME: {
29276 char *zTFile = sqlite3_malloc64( pFile->pVfs->mxPathname );
29277 if( zTFile ){
29278 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
29279 *(char**)pArg = zTFile;
29280 }
29281 return SQLITE_OK;
@@ -29638,11 +29712,11 @@
29712 unixInodeInfo *pInode; /* The inode of fd */
29713 char *zShmFilename; /* Name of the file used for SHM */
29714 int nShmFilename; /* Size of the SHM filename in bytes */
29715
29716 /* Allocate space for the new unixShm object. */
29717 p = sqlite3_malloc64( sizeof(*p) );
29718 if( p==0 ) return SQLITE_NOMEM;
29719 memset(p, 0, sizeof(*p));
29720 assert( pDbFd->pShm==0 );
29721
29722 /* Check to see if a unixShmNode object already exists. Reuse an existing
@@ -29669,11 +29743,11 @@
29743 #ifdef SQLITE_SHM_DIRECTORY
29744 nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
29745 #else
29746 nShmFilename = 6 + (int)strlen(zBasePath);
29747 #endif
29748 pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename );
29749 if( pShmNode==0 ){
29750 rc = SQLITE_NOMEM;
29751 goto shm_open_err;
29752 }
29753 memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
@@ -29879,11 +29953,11 @@
29953 if( pMem==MAP_FAILED ){
29954 rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
29955 goto shmpage_out;
29956 }
29957 }else{
29958 pMem = sqlite3_malloc64(szRegion);
29959 if( pMem==0 ){
29960 rc = SQLITE_NOMEM;
29961 goto shmpage_out;
29962 }
29963 memset(pMem, 0, szRegion);
@@ -30716,11 +30790,11 @@
30790 else if( pLockingStyle == &afpIoMethods ){
30791 /* AFP locking uses the file path so it needs to be included in
30792 ** the afpLockingContext.
30793 */
30794 afpLockingContext *pCtx;
30795 pNew->lockingContext = pCtx = sqlite3_malloc64( sizeof(*pCtx) );
30796 if( pCtx==0 ){
30797 rc = SQLITE_NOMEM;
30798 }else{
30799 /* NB: zFilename exists and remains valid until the file is closed
30800 ** according to requirement F11141. So we do not need to make a
@@ -30746,11 +30820,11 @@
30820 */
30821 char *zLockFile;
30822 int nFilename;
30823 assert( zFilename!=0 );
30824 nFilename = (int)strlen(zFilename) + 6;
30825 zLockFile = (char *)sqlite3_malloc64(nFilename);
30826 if( zLockFile==0 ){
30827 rc = SQLITE_NOMEM;
30828 }else{
30829 sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename);
30830 }
@@ -31123,11 +31197,11 @@
31197 UnixUnusedFd *pUnused;
31198 pUnused = findReusableFd(zName, flags);
31199 if( pUnused ){
31200 fd = pUnused->fd;
31201 }else{
31202 pUnused = sqlite3_malloc64(sizeof(*pUnused));
31203 if( !pUnused ){
31204 return SQLITE_NOMEM;
31205 }
31206 }
31207 p->pUnused = pUnused;
@@ -31503,11 +31577,11 @@
31577 ** that we always use the same random number sequence. This makes the
31578 ** tests repeatable.
31579 */
31580 memset(zBuf, 0, nBuf);
31581 randomnessPid = osGetpid(0);
31582 #if !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS)
31583 {
31584 int fd, got;
31585 fd = robust_open("/dev/urandom", O_RDONLY, 0);
31586 if( fd<0 ){
31587 time_t t;
@@ -31915,11 +31989,11 @@
31989 */
31990 pUnused = findReusableFd(path, openFlags);
31991 if( pUnused ){
31992 fd = pUnused->fd;
31993 }else{
31994 pUnused = sqlite3_malloc64(sizeof(*pUnused));
31995 if( !pUnused ){
31996 return SQLITE_NOMEM;
31997 }
31998 }
31999 if( fd<0 ){
@@ -31948,11 +32022,11 @@
32022 default:
32023 return SQLITE_CANTOPEN_BKPT;
32024 }
32025 }
32026
32027 pNew = (unixFile *)sqlite3_malloc64(sizeof(*pNew));
32028 if( pNew==NULL ){
32029 rc = SQLITE_NOMEM;
32030 goto end_create_proxy;
32031 }
32032 memset(pNew, 0, sizeof(unixFile));
@@ -31981,21 +32055,22 @@
32055 SQLITE_API int sqlite3_hostid_num = 0;
32056 #endif
32057
32058 #define PROXY_HOSTIDLEN 16 /* conch file host id length */
32059
32060 #ifdef HAVE_GETHOSTUUID
32061 /* Not always defined in the headers as it ought to be */
32062 extern int gethostuuid(uuid_t id, const struct timespec *wait);
32063 #endif
32064
32065 /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
32066 ** bytes of writable memory.
32067 */
32068 static int proxyGetHostID(unsigned char *pHostID, int *pError){
32069 assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
32070 memset(pHostID, 0, PROXY_HOSTIDLEN);
32071 #ifdef HAVE_GETHOSTUUID
 
32072 {
32073 struct timespec timeout = {1, 0}; /* 1 sec timeout */
32074 if( gethostuuid(pHostID, &timeout) ){
32075 int err = errno;
32076 if( pError ){
@@ -32409,11 +32484,11 @@
32484 return rc;
32485 }
32486
32487 /*
32488 ** Given the name of a database file, compute the name of its conch file.
32489 ** Store the conch filename in memory obtained from sqlite3_malloc64().
32490 ** Make *pConchPath point to the new name. Return SQLITE_OK on success
32491 ** or SQLITE_NOMEM if unable to obtain memory.
32492 **
32493 ** The caller is responsible for ensuring that the allocated memory
32494 ** space is eventually freed.
@@ -32425,11 +32500,11 @@
32500 int len = (int)strlen(dbPath); /* Length of database filename - dbPath */
32501 char *conchPath; /* buffer in which to construct conch name */
32502
32503 /* Allocate space for the conch filename and initialize the name to
32504 ** the name of the original database file. */
32505 *pConchPath = conchPath = (char *)sqlite3_malloc64(len + 8);
32506 if( conchPath==0 ){
32507 return SQLITE_NOMEM;
32508 }
32509 memcpy(conchPath, dbPath, len+1);
32510
@@ -32541,11 +32616,11 @@
32616 }
32617
32618 OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
32619 (lockPath ? lockPath : ":auto:"), osGetpid(0)));
32620
32621 pCtx = sqlite3_malloc64( sizeof(*pCtx) );
32622 if( pCtx==0 ){
32623 return SQLITE_NOMEM;
32624 }
32625 memset(pCtx, 0, sizeof(*pCtx));
32626
@@ -32985,20 +33060,10 @@
33060 */
33061 #ifdef MEMORY_DEBUG
33062 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
33063 #endif
33064
 
 
 
 
 
 
 
 
 
 
33065 /*
33066 ** Macros for performance tracing. Normally turned off. Only works
33067 ** on i486 hardware.
33068 */
33069 #ifdef SQLITE_PERFORMANCE_TRACE
@@ -35898,11 +35963,11 @@
35963 ** Used only when SQLITE_NO_SYNC is not defined.
35964 */
35965 BOOL rc;
35966 #endif
35967 #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \
35968 defined(SQLITE_HAVE_OS_TRACE)
35969 /*
35970 ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or
35971 ** OSTRACE() macros.
35972 */
35973 winFile *pFile = (winFile*)id;
@@ -36575,11 +36640,11 @@
36640 DWORD lastErrno; /* The Windows errno from the last I/O error */
36641
36642 int nRef; /* Number of winShm objects pointing to this */
36643 winShm *pFirst; /* All winShm objects pointing to this */
36644 winShmNode *pNext; /* Next in list of all winShmNode objects */
36645 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
36646 u8 nextShmId; /* Next available winShm.id value */
36647 #endif
36648 };
36649
36650 /*
@@ -36606,11 +36671,11 @@
36671 winShmNode *pShmNode; /* The underlying winShmNode object */
36672 winShm *pNext; /* Next winShm with the same winShmNode */
36673 u8 hasMutex; /* True if holding the winShmNode mutex */
36674 u16 sharedMask; /* Mask of shared locks held */
36675 u16 exclMask; /* Mask of exclusive locks held */
36676 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
36677 u8 id; /* Id of this connection with its winShmNode */
36678 #endif
36679 };
36680
36681 /*
@@ -36797,11 +36862,11 @@
36862 if( rc ) goto shm_open_err;
36863 }
36864
36865 /* Make the new connection a child of the winShmNode */
36866 p->pShmNode = pShmNode;
36867 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
36868 p->id = pShmNode->nextShmId++;
36869 #endif
36870 pShmNode->nRef++;
36871 pDbFd->pShm = p;
36872 winShmLeaveMutex();
@@ -37066,11 +37131,11 @@
37131 goto shmpage_out;
37132 }
37133 }
37134
37135 /* Map the requested memory region into this processes address space. */
37136 apNew = (struct ShmRegion *)sqlite3_realloc64(
37137 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
37138 );
37139 if( !apNew ){
37140 rc = SQLITE_IOERR_NOMEM;
37141 goto shmpage_out;
@@ -38513,11 +38578,11 @@
38578 ** Write up to nBuf bytes of randomness into zBuf.
38579 */
38580 static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
38581 int n = 0;
38582 UNUSED_PARAMETER(pVfs);
38583 #if defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS)
38584 n = nBuf;
38585 memset(zBuf, 0, nBuf);
38586 #else
38587 if( sizeof(SYSTEMTIME)<=nBuf-n ){
38588 SYSTEMTIME x;
@@ -38547,11 +38612,10 @@
38612 LARGE_INTEGER i;
38613 osQueryPerformanceCounter(&i);
38614 memcpy(&zBuf[n], &i, sizeof(i));
38615 n += sizeof(i);
38616 }
 
38617 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
38618 if( sizeof(UUID)<=nBuf-n ){
38619 UUID id;
38620 memset(&id, 0, sizeof(UUID));
38621 osUuidCreate(&id);
@@ -38564,10 +38628,11 @@
38628 osUuidCreateSequential(&id);
38629 memcpy(zBuf, &id, sizeof(UUID));
38630 n += sizeof(UUID);
38631 }
38632 #endif
38633 #endif /* defined(SQLITE_TEST) || defined(SQLITE_ZERO_PRNG_SEED) */
38634 return n;
38635 }
38636
38637
38638 /*
@@ -39118,11 +39183,11 @@
39183
39184 /* Allocate the Bitvec to be tested and a linear array of
39185 ** bits to act as the reference */
39186 pBitvec = sqlite3BitvecCreate( sz );
39187 pV = sqlite3MallocZero( (sz+7)/8 + 1 );
39188 pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
39189 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
39190
39191 /* NULL pBitvec tests */
39192 sqlite3BitvecSet(0, 1);
39193 sqlite3BitvecClear(0, 1, pTmpSpace);
@@ -44607,13 +44672,11 @@
44672 Pgno nTruncate, /* Database size after this commit */
44673 int isCommit /* True if this is a commit */
44674 ){
44675 int rc; /* Return code */
44676 int nList; /* Number of pages in pList */
 
44677 PgHdr *p; /* For looping over pages */
 
44678
44679 assert( pPager->pWal );
44680 assert( pList );
44681 #ifdef SQLITE_DEBUG
44682 /* Verify that the page list is in accending order */
@@ -44626,11 +44689,10 @@
44689 if( isCommit ){
44690 /* If a WAL transaction is being committed, there is no point in writing
44691 ** any pages with page numbers greater than nTruncate into the WAL file.
44692 ** They will never be read by any client. So remove them from the pDirty
44693 ** list here. */
 
44694 PgHdr **ppNext = &pList;
44695 nList = 0;
44696 for(p=pList; (*ppNext = p)!=0; p=p->pDirty){
44697 if( p->pgno<=nTruncate ){
44698 ppNext = &p->pDirty;
@@ -44646,11 +44708,10 @@
44708 if( pList->pgno==1 ) pager_write_changecounter(pList);
44709 rc = sqlite3WalFrames(pPager->pWal,
44710 pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags
44711 );
44712 if( rc==SQLITE_OK && pPager->pBackup ){
 
44713 for(p=pList; p; p=p->pDirty){
44714 sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
44715 }
44716 }
44717
@@ -48577,10 +48638,12 @@
48638 }else if( state==PAGER_OPEN ){
48639 pager_unlock(pPager);
48640 }
48641 assert( state==pPager->eState );
48642 }
48643 }else if( eMode==PAGER_JOURNALMODE_OFF ){
48644 sqlite3OsClose(pPager->jfd);
48645 }
48646 }
48647
48648 /* Return the new journal mode */
48649 return (int)pPager->journalMode;
@@ -49359,11 +49422,11 @@
49422
49423 /* Enlarge the pWal->apWiData[] array if required */
49424 if( pWal->nWiData<=iPage ){
49425 int nByte = sizeof(u32*)*(iPage+1);
49426 volatile u32 **apNew;
49427 apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte);
49428 if( !apNew ){
49429 *ppPage = 0;
49430 return SQLITE_NOMEM;
49431 }
49432 memset((void*)&apNew[pWal->nWiData], 0,
@@ -49984,11 +50047,11 @@
50047 goto finished;
50048 }
50049
50050 /* Malloc a buffer to read frames into. */
50051 szFrame = szPage + WAL_FRAME_HDRSIZE;
50052 aFrame = (u8 *)sqlite3_malloc64(szFrame);
50053 if( !aFrame ){
50054 rc = SQLITE_NOMEM;
50055 goto recovery_error;
50056 }
50057 aData = &aFrame[WAL_FRAME_HDRSIZE];
@@ -50377,21 +50440,21 @@
50440 /* Allocate space for the WalIterator object. */
50441 nSegment = walFramePage(iLast) + 1;
50442 nByte = sizeof(WalIterator)
50443 + (nSegment-1)*sizeof(struct WalSegment)
50444 + iLast*sizeof(ht_slot);
50445 p = (WalIterator *)sqlite3_malloc64(nByte);
50446 if( !p ){
50447 return SQLITE_NOMEM;
50448 }
50449 memset(p, 0, nByte);
50450 p->nSegment = nSegment;
50451
50452 /* Allocate temporary space used by the merge-sort routine. This block
50453 ** of memory will be freed before this function returns.
50454 */
50455 aTmp = (ht_slot *)sqlite3_malloc64(
50456 sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
50457 );
50458 if( !aTmp ){
50459 rc = SQLITE_NOMEM;
50460 }
@@ -50567,10 +50630,18 @@
50630 ** cannot be backfilled from the WAL.
50631 */
50632 mxSafeFrame = pWal->hdr.mxFrame;
50633 mxPage = pWal->hdr.nPage;
50634 for(i=1; i<WAL_NREADER; i++){
50635 /* Thread-sanitizer reports that the following is an unsafe read,
50636 ** as some other thread may be in the process of updating the value
50637 ** of the aReadMark[] slot. The assumption here is that if that is
50638 ** happening, the other client may only be increasing the value,
50639 ** not decreasing it. So assuming either that either the "old" or
50640 ** "new" version of the value is read, and not some arbitrary value
50641 ** that would never be written by a real client, things are still
50642 ** safe. */
50643 u32 y = pInfo->aReadMark[i];
50644 if( mxSafeFrame>y ){
50645 assert( y<=pWal->hdr.mxFrame );
50646 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
50647 if( rc==SQLITE_OK ){
@@ -55407,11 +55478,11 @@
55478 }
55479 assert( nReserve>=0 && nReserve<=255 );
55480 if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE &&
55481 ((pageSize-1)&pageSize)==0 ){
55482 assert( (pageSize & 7)==0 );
55483 assert( !pBt->pCursor );
55484 pBt->pageSize = (u32)pageSize;
55485 freeTempSpace(pBt);
55486 }
55487 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, nReserve);
55488 pBt->usableSize = pBt->pageSize - (u16)nReserve;
@@ -57429,17 +57500,22 @@
57500 */
57501 static const void *fetchPayload(
57502 BtCursor *pCur, /* Cursor pointing to entry to read from */
57503 u32 *pAmt /* Write the number of available bytes here */
57504 ){
57505 u32 amt;
57506 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
57507 assert( pCur->eState==CURSOR_VALID );
57508 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
57509 assert( cursorHoldsMutex(pCur) );
57510 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
57511 assert( pCur->info.nSize>0 );
57512 assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
57513 assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
57514 amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
57515 if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
57516 *pAmt = amt;
57517 return (void*)pCur->info.pPayload;
57518 }
57519
57520
57521 /*
@@ -59713,11 +59789,10 @@
59789 if( iParentIdx==0 ){
59790 nxDiv = 0;
59791 }else if( iParentIdx==i ){
59792 nxDiv = i-2+bBulk;
59793 }else{
 
59794 nxDiv = iParentIdx-1;
59795 }
59796 i = 2-bBulk;
59797 }
59798 nOld = i+1;
@@ -61501,10 +61576,61 @@
61576 iPage = get4byte(pOvflData);
61577 sqlite3PagerUnref(pOvflPage);
61578 }
61579 }
61580 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
61581
61582 /*
61583 ** An implementation of a min-heap.
61584 **
61585 ** aHeap[0] is the number of elements on the heap. aHeap[1] is the
61586 ** root element. The daughter nodes of aHeap[N] are aHeap[N*2]
61587 ** and aHeap[N*2+1].
61588 **
61589 ** The heap property is this: Every node is less than or equal to both
61590 ** of its daughter nodes. A consequence of the heap property is that the
61591 ** root node aHeap[1] is always the minimum value currently in the heap.
61592 **
61593 ** The btreeHeapInsert() routine inserts an unsigned 32-bit number onto
61594 ** the heap, preserving the heap property. The btreeHeapPull() routine
61595 ** removes the root element from the heap (the minimum value in the heap)
61596 ** and then moves other nodes around as necessary to preserve the heap
61597 ** property.
61598 **
61599 ** This heap is used for cell overlap and coverage testing. Each u32
61600 ** entry represents the span of a cell or freeblock on a btree page.
61601 ** The upper 16 bits are the index of the first byte of a range and the
61602 ** lower 16 bits are the index of the last byte of that range.
61603 */
61604 static void btreeHeapInsert(u32 *aHeap, u32 x){
61605 u32 j, i = ++aHeap[0];
61606 aHeap[i] = x;
61607 while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){
61608 x = aHeap[j];
61609 aHeap[j] = aHeap[i];
61610 aHeap[i] = x;
61611 i = j;
61612 }
61613 }
61614 static int btreeHeapPull(u32 *aHeap, u32 *pOut){
61615 u32 j, i, x;
61616 if( (x = aHeap[0])==0 ) return 0;
61617 *pOut = aHeap[1];
61618 aHeap[1] = aHeap[x];
61619 aHeap[x] = 0xffffffff;
61620 aHeap[0]--;
61621 i = 1;
61622 while( (j = i*2)<=aHeap[0] ){
61623 if( aHeap[j]>aHeap[j+1] ) j++;
61624 if( aHeap[i]<aHeap[j] ) break;
61625 x = aHeap[i];
61626 aHeap[i] = aHeap[j];
61627 aHeap[j] = x;
61628 i = j;
61629 }
61630 return 1;
61631 }
61632
61633 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
61634 /*
61635 ** Do various sanity checks on a single page of a tree. Return
61636 ** the tree depth. Root pages return 0. Parents of root pages
@@ -61534,11 +61660,12 @@
61660 int hdr, cellStart;
61661 int nCell;
61662 u8 *data;
61663 BtShared *pBt;
61664 int usableSize;
61665 u32 *heap = 0;
61666 u32 x, prev = 0;
61667 i64 nMinKey = 0;
61668 i64 nMaxKey = 0;
61669 const char *saved_zPfx = pCheck->zPfx;
61670 int saved_v1 = pCheck->v1;
61671 int saved_v2 = pCheck->v2;
@@ -61679,19 +61806,19 @@
61806
61807 /* Check for complete coverage of the page
61808 */
61809 data = pPage->aData;
61810 hdr = pPage->hdrOffset;
61811 heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
61812 pCheck->zPfx = 0;
61813 if( heap==0 ){
61814 pCheck->mallocFailed = 1;
61815 }else{
61816 int contentOffset = get2byteNotZero(&data[hdr+5]);
61817 assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
61818 heap[0] = 0;
61819 btreeHeapInsert(heap, contentOffset-1);
61820 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
61821 ** number of cells on the page. */
61822 nCell = get2byte(&data[hdr+3]);
61823 /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
61824 ** immediately follows the b-tree page header. */
@@ -61699,20 +61826,19 @@
61826 /* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
61827 ** integer offsets to the cell contents. */
61828 for(i=0; i<nCell; i++){
61829 int pc = get2byte(&data[cellStart+i*2]);
61830 u32 size = 65536;
 
61831 if( pc<=usableSize-4 ){
61832 size = cellSizePtr(pPage, &data[pc]);
61833 }
61834 if( (int)(pc+size-1)>=usableSize ){
61835 pCheck->zPfx = 0;
61836 checkAppendMsg(pCheck,
61837 "Corruption detected in cell %d on page %d",i,iPage);
61838 }else{
61839 btreeHeapInsert(heap, (pc<<16)|(pc+size-1));
61840 }
61841 }
61842 /* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
61843 ** is the offset of the first freeblock, or zero if there are no
61844 ** freeblocks on the page. */
@@ -61720,11 +61846,11 @@
61846 while( i>0 ){
61847 int size, j;
61848 assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */
61849 size = get2byte(&data[i+2]);
61850 assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */
61851 btreeHeapInsert(heap, (i<<16)|(i+size-1));
61852 /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
61853 ** big-endian integer which is the offset in the b-tree page of the next
61854 ** freeblock in the chain, or zero if the freeblock is the last on the
61855 ** chain. */
61856 j = get2byte(&data[i]);
@@ -61732,31 +61858,37 @@
61858 ** increasing offset. */
61859 assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */
61860 assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */
61861 i = j;
61862 }
61863 cnt = 0;
61864 assert( heap[0]>0 );
61865 assert( (heap[1]>>16)==0 );
61866 btreeHeapPull(heap,&prev);
61867 while( btreeHeapPull(heap,&x) ){
61868 if( (prev&0xffff)+1>(x>>16) ){
61869 checkAppendMsg(pCheck,
61870 "Multiple uses for byte %u of page %d", x>>16, iPage);
61871 break;
61872 }else{
61873 cnt += (x>>16) - (prev&0xffff) - 1;
61874 prev = x;
61875 }
61876 }
61877 cnt += usableSize - (prev&0xffff) - 1;
61878 /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
61879 ** is stored in the fifth field of the b-tree page header.
61880 ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
61881 ** number of fragmented free bytes within the cell content area.
61882 */
61883 if( heap[0]==0 && cnt!=data[hdr+7] ){
61884 checkAppendMsg(pCheck,
61885 "Fragmentation of %d bytes reported as %d on page %d",
61886 cnt, data[hdr+7], iPage);
61887 }
61888 }
61889 sqlite3PageFree(heap);
61890 releasePage(pPage);
61891
61892 end_of_check:
61893 pCheck->zPfx = saved_zPfx;
61894 pCheck->v1 = saved_v1;
@@ -61816,12 +61948,11 @@
61948 sqlite3BtreeLeave(p);
61949 return 0;
61950 }
61951 i = PENDING_BYTE_PAGE(pBt);
61952 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
61953 sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
 
61954
61955 /* Check the integrity of the freelist
61956 */
61957 sCheck.zPfx = "Main freelist: ";
61958 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
@@ -63153,14 +63284,15 @@
63284 return SQLITE_NOMEM;
63285 }
63286 pMem->z[pMem->n] = 0;
63287 pMem->z[pMem->n+1] = 0;
63288 pMem->flags |= MEM_Term;
63289 }
63290 pMem->flags &= ~MEM_Ephem;
63291 #ifdef SQLITE_DEBUG
63292 pMem->pScopyFrom = 0;
63293 #endif
 
63294
63295 return SQLITE_OK;
63296 }
63297
63298 /*
@@ -64600,11 +64732,11 @@
64732 int i;
64733 int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
64734 Mem *aMem = pRec->aMem;
64735 sqlite3 *db = aMem[0].db;
64736 for(i=0; i<nCol; i++){
64737 sqlite3VdbeMemRelease(&aMem[i]);
64738 }
64739 sqlite3KeyInfoUnref(pRec->pKeyInfo);
64740 sqlite3DbFree(db, pRec);
64741 }
64742 }
@@ -66436,18 +66568,35 @@
66568 pVtabCursor->pVtab->nRef--;
66569 pModule->xClose(pVtabCursor);
66570 }
66571 #endif
66572 }
66573
66574 /*
66575 ** Close all cursors in the current frame.
66576 */
66577 static void closeCursorsInFrame(Vdbe *p){
66578 if( p->apCsr ){
66579 int i;
66580 for(i=0; i<p->nCursor; i++){
66581 VdbeCursor *pC = p->apCsr[i];
66582 if( pC ){
66583 sqlite3VdbeFreeCursor(p, pC);
66584 p->apCsr[i] = 0;
66585 }
66586 }
66587 }
66588 }
66589
66590 /*
66591 ** Copy the values stored in the VdbeFrame structure to its Vdbe. This
66592 ** is used, for example, when a trigger sub-program is halted to restore
66593 ** control to the main program.
66594 */
66595 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
66596 Vdbe *v = pFrame->v;
66597 closeCursorsInFrame(v);
66598 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
66599 v->anExec = pFrame->anExec;
66600 #endif
66601 v->aOnceFlag = pFrame->aOnceFlag;
66602 v->nOnceFlag = pFrame->nOnceFlag;
@@ -66478,21 +66627,11 @@
66627 sqlite3VdbeFrameRestore(pFrame);
66628 p->pFrame = 0;
66629 p->nFrame = 0;
66630 }
66631 assert( p->nFrame==0 );
66632 closeCursorsInFrame(p);
 
 
 
 
 
 
 
 
 
 
66633 if( p->aMem ){
66634 releaseMemArray(&p->aMem[1], p->nMem);
66635 }
66636 while( p->pDelFrame ){
66637 VdbeFrame *pDel = p->pDelFrame;
@@ -68233,11 +68372,11 @@
68372 ** If database corruption is discovered, set pPKey2->errCode to
68373 ** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
68374 ** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
68375 ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
68376 */
68377 SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(
68378 int nKey1, const void *pKey1, /* Left key */
68379 UnpackedRecord *pPKey2, /* Right key */
68380 int bSkip /* If true, skip the first field */
68381 ){
68382 u32 d1; /* Offset into aKey[] of next data element */
@@ -68419,11 +68558,11 @@
68558 }
68559 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
68560 int nKey1, const void *pKey1, /* Left key */
68561 UnpackedRecord *pPKey2 /* Right key */
68562 ){
68563 return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
68564 }
68565
68566
68567 /*
68568 ** This function is an optimized version of sqlite3VdbeRecordCompare()
@@ -68507,11 +68646,11 @@
68646 }else if( v<lhs ){
68647 res = pPKey2->r2;
68648 }else if( pPKey2->nField>1 ){
68649 /* The first fields of the two keys are equal. Compare the trailing
68650 ** fields. */
68651 res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68652 }else{
68653 /* The first fields of the two keys are equal and there are no trailing
68654 ** fields. Return pPKey2->default_rc in this case. */
68655 res = pPKey2->default_rc;
68656 }
@@ -68555,11 +68694,11 @@
68694
68695 if( res==0 ){
68696 res = nStr - pPKey2->aMem[0].n;
68697 if( res==0 ){
68698 if( pPKey2->nField>1 ){
68699 res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
68700 }else{
68701 res = pPKey2->default_rc;
68702 }
68703 }else if( res>0 ){
68704 res = pPKey2->r2;
@@ -70497,21 +70636,22 @@
70636 Mem *pVar; /* Value of a host parameter */
70637 StrAccum out; /* Accumulate the output here */
70638 char zBase[100]; /* Initial working space */
70639
70640 db = p->db;
70641 sqlite3StrAccumInit(&out, db, zBase, sizeof(zBase),
70642 db->aLimit[SQLITE_LIMIT_LENGTH]);
 
70643 if( db->nVdbeExec>1 ){
70644 while( *zRawSql ){
70645 const char *zStart = zRawSql;
70646 while( *(zRawSql++)!='\n' && *zRawSql );
70647 sqlite3StrAccumAppend(&out, "-- ", 3);
70648 assert( (zRawSql - zStart) > 0 );
70649 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
70650 }
70651 }else if( p->nVar==0 ){
70652 sqlite3StrAccumAppend(&out, zRawSql, sqlite3Strlen30(zRawSql));
70653 }else{
70654 while( zRawSql[0] ){
70655 n = findNextHostParameter(zRawSql, &nToken);
70656 assert( n>0 );
70657 sqlite3StrAccumAppend(&out, zRawSql, n);
@@ -70524,14 +70664,16 @@
70664 sqlite3GetInt32(&zRawSql[1], &idx);
70665 }else{
70666 idx = nextIndex;
70667 }
70668 }else{
70669 assert( zRawSql[0]==':' || zRawSql[0]=='$' ||
70670 zRawSql[0]=='@' || zRawSql[0]=='#' );
70671 testcase( zRawSql[0]==':' );
70672 testcase( zRawSql[0]=='$' );
70673 testcase( zRawSql[0]=='@' );
70674 testcase( zRawSql[0]=='#' );
70675 idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken);
70676 assert( idx>0 );
70677 }
70678 zRawSql += nToken;
70679 nextIndex = idx + 1;
@@ -70895,10 +71037,11 @@
71037 ** representation.
71038 */
71039 if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
71040 sqlite3VdbeMemStringify(pRec, enc, 1);
71041 }
71042 pRec->flags &= ~(MEM_Real|MEM_Int);
71043 }
71044 }
71045
71046 /*
71047 ** Try to convert the type of a function argument or a result column
@@ -71202,21 +71345,38 @@
71345 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
71346 return 1;
71347 }
71348 #endif
71349
71350 /*
71351 ** Return the register of pOp->p2 after first preparing it to be
71352 ** overwritten with an integer value.
71353 */
71354 static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){
71355 Mem *pOut;
71356 assert( pOp->p2>0 );
71357 assert( pOp->p2<=(p->nMem-p->nCursor) );
71358 pOut = &p->aMem[pOp->p2];
71359 memAboutToChange(p, pOut);
71360 if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
71361 pOut->flags = MEM_Int;
71362 return pOut;
71363 }
71364
71365
71366 /*
71367 ** Execute as much of a VDBE program as we can.
71368 ** This is the core of sqlite3_step().
71369 */
71370 SQLITE_PRIVATE int sqlite3VdbeExec(
71371 Vdbe *p /* The VDBE */
71372 ){
 
71373 Op *aOp = p->aOp; /* Copy of p->aOp */
71374 Op *pOp = aOp; /* Current operation */
71375 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
71376 Op *pOrigOp; /* Value of pOp at the top of the loop */
71377 #endif
71378 int rc = SQLITE_OK; /* Value to return */
71379 sqlite3 *db = p->db; /* The database */
71380 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
71381 u8 encoding = ENC(db); /* The database encoding */
71382 int iCompare = 0; /* Result of last OP_Compare operation */
@@ -71288,27 +71448,26 @@
71448 }
71449 if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
71450 }
71451 sqlite3EndBenignMalloc();
71452 #endif
71453 for(pOp=&aOp[p->pc]; rc==SQLITE_OK; pOp++){
71454 assert( pOp>=aOp && pOp<&aOp[p->nOp]);
71455 if( db->mallocFailed ) goto no_mem;
71456 #ifdef VDBE_PROFILE
71457 start = sqlite3Hwtime();
71458 #endif
71459 nVmStep++;
 
71460 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
71461 if( p->anExec ) p->anExec[(int)(pOp-aOp)]++;
71462 #endif
71463
71464 /* Only allow tracing if SQLITE_DEBUG is defined.
71465 */
71466 #ifdef SQLITE_DEBUG
71467 if( db->flags & SQLITE_VdbeTrace ){
71468 sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp);
71469 }
71470 #endif
71471
71472
71473 /* Check to see if we need to simulate an interrupt. This only happens
@@ -71321,27 +71480,13 @@
71480 sqlite3_interrupt(db);
71481 }
71482 }
71483 #endif
71484
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71485 /* Sanity checking on other operands */
71486 #ifdef SQLITE_DEBUG
71487 assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
71488 if( (pOp->opflags & OPFLG_IN1)!=0 ){
71489 assert( pOp->p1>0 );
71490 assert( pOp->p1<=(p->nMem-p->nCursor) );
71491 assert( memIsValid(&aMem[pOp->p1]) );
71492 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
@@ -71370,10 +71515,13 @@
71515 assert( pOp->p3>0 );
71516 assert( pOp->p3<=(p->nMem-p->nCursor) );
71517 memAboutToChange(p, &aMem[pOp->p3]);
71518 }
71519 #endif
71520 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
71521 pOrigOp = pOp;
71522 #endif
71523
71524 switch( pOp->opcode ){
71525
71526 /*****************************************************************************
71527 ** What follows is a massive switch statement where each case implements a
@@ -71393,11 +71541,11 @@
71541 ** case statement is followed by a comment of the form "/# same as ... #/"
71542 ** that comment is used to determine the particular value of the opcode.
71543 **
71544 ** Other keywords in the comment that follows each case are used to
71545 ** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[].
71546 ** Keywords include: in1, in2, in3, out2, out3. See
71547 ** the mkopcodeh.awk script for additional information.
71548 **
71549 ** Documentation about VDBE opcodes is generated by scanning this file
71550 ** for lines of that contain "Opcode:". That line and all subsequent
71551 ** comment lines are used in the generation of the opcode.html documentation
@@ -71421,11 +71569,12 @@
71569 ** is sometimes set to 1 instead of 0 as a hint to the command-line shell
71570 ** that this Goto is the bottom of a loop and that the lines from P2 down
71571 ** to the current line should be indented for EXPLAIN output.
71572 */
71573 case OP_Goto: { /* jump */
71574 jump_to_p2_and_check_for_interrupt:
71575 pOp = &aOp[pOp->p2 - 1];
71576
71577 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
71578 ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
71579 ** completion. Check to see if sqlite3_interrupt() has been called
71580 ** or if the progress callback needs to be invoked.
@@ -71466,13 +71615,17 @@
71615 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
71616 pIn1 = &aMem[pOp->p1];
71617 assert( VdbeMemDynamic(pIn1)==0 );
71618 memAboutToChange(p, pIn1);
71619 pIn1->flags = MEM_Int;
71620 pIn1->u.i = (int)(pOp-aOp);
71621 REGISTER_TRACE(pOp->p1, pIn1);
71622
71623 /* Most jump operations do a goto to this spot in order to update
71624 ** the pOp pointer. */
71625 jump_to_p2:
71626 pOp = &aOp[pOp->p2 - 1];
71627 break;
71628 }
71629
71630 /* Opcode: Return P1 * * * *
71631 **
@@ -71480,11 +71633,11 @@
71633 ** the jump, register P1 becomes undefined.
71634 */
71635 case OP_Return: { /* in1 */
71636 pIn1 = &aMem[pOp->p1];
71637 assert( pIn1->flags==MEM_Int );
71638 pOp = &aOp[pIn1->u.i];
71639 pIn1->flags = MEM_Undefined;
71640 break;
71641 }
71642
71643 /* Opcode: InitCoroutine P1 P2 P3 * *
@@ -71504,11 +71657,11 @@
71657 assert( pOp->p3>=0 && pOp->p3<p->nOp );
71658 pOut = &aMem[pOp->p1];
71659 assert( !VdbeMemDynamic(pOut) );
71660 pOut->u.i = pOp->p3 - 1;
71661 pOut->flags = MEM_Int;
71662 if( pOp->p2 ) goto jump_to_p2;
71663 break;
71664 }
71665
71666 /* Opcode: EndCoroutine P1 * * * *
71667 **
@@ -71524,11 +71677,11 @@
71677 assert( pIn1->flags==MEM_Int );
71678 assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
71679 pCaller = &aOp[pIn1->u.i];
71680 assert( pCaller->opcode==OP_Yield );
71681 assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
71682 pOp = &aOp[pCaller->p2 - 1];
71683 pIn1->flags = MEM_Undefined;
71684 break;
71685 }
71686
71687 /* Opcode: Yield P1 P2 * * *
@@ -71548,13 +71701,13 @@
71701 int pcDest;
71702 pIn1 = &aMem[pOp->p1];
71703 assert( VdbeMemDynamic(pIn1)==0 );
71704 pIn1->flags = MEM_Int;
71705 pcDest = (int)pIn1->u.i;
71706 pIn1->u.i = (int)(pOp - aOp);
71707 REGISTER_TRACE(pOp->p1, pIn1);
71708 pOp = &aOp[pcDest];
71709 break;
71710 }
71711
71712 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
71713 ** Synopsis: if r[P3]=null halt
@@ -71601,34 +71754,38 @@
71754 ** is the same as executing Halt.
71755 */
71756 case OP_Halt: {
71757 const char *zType;
71758 const char *zLogFmt;
71759 VdbeFrame *pFrame;
71760 int pcx;
71761
71762 pcx = (int)(pOp - aOp);
71763 if( pOp->p1==SQLITE_OK && p->pFrame ){
71764 /* Halt the sub-program. Return control to the parent frame. */
71765 pFrame = p->pFrame;
71766 p->pFrame = pFrame->pParent;
71767 p->nFrame--;
71768 sqlite3VdbeSetChanges(db, p->nChange);
71769 pcx = sqlite3VdbeFrameRestore(pFrame);
71770 lastRowid = db->lastRowid;
71771 if( pOp->p2==OE_Ignore ){
71772 /* Instruction pcx is the OP_Program that invoked the sub-program
71773 ** currently being halted. If the p2 instruction of this OP_Halt
71774 ** instruction is set to OE_Ignore, then the sub-program is throwing
71775 ** an IGNORE exception. In this case jump to the address specified
71776 ** as the p2 of the calling OP_Program. */
71777 pcx = p->aOp[pcx].p2-1;
71778 }
71779 aOp = p->aOp;
71780 aMem = p->aMem;
71781 pOp = &aOp[pcx];
71782 break;
71783 }
71784 p->rc = pOp->p1;
71785 p->errorAction = (u8)pOp->p2;
71786 p->pc = pcx;
71787 if( p->rc ){
71788 if( pOp->p5 ){
71789 static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
71790 "FOREIGN KEY" };
71791 assert( pOp->p5>=1 && pOp->p5<=4 );
@@ -71648,11 +71805,11 @@
71805 }else if( pOp->p4.z ){
71806 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
71807 }else{
71808 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
71809 }
71810 sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg);
71811 }
71812 rc = sqlite3VdbeHalt(p);
71813 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
71814 if( rc==SQLITE_BUSY ){
71815 p->rc = rc = SQLITE_BUSY;
@@ -71667,11 +71824,12 @@
71824 /* Opcode: Integer P1 P2 * * *
71825 ** Synopsis: r[P2]=P1
71826 **
71827 ** The 32-bit integer value P1 is written into register P2.
71828 */
71829 case OP_Integer: { /* out2 */
71830 pOut = out2Prerelease(p, pOp);
71831 pOut->u.i = pOp->p1;
71832 break;
71833 }
71834
71835 /* Opcode: Int64 * P2 * P4 *
@@ -71678,11 +71836,12 @@
71836 ** Synopsis: r[P2]=P4
71837 **
71838 ** P4 is a pointer to a 64-bit integer value.
71839 ** Write that value into register P2.
71840 */
71841 case OP_Int64: { /* out2 */
71842 pOut = out2Prerelease(p, pOp);
71843 assert( pOp->p4.pI64!=0 );
71844 pOut->u.i = *pOp->p4.pI64;
71845 break;
71846 }
71847
@@ -71691,11 +71850,12 @@
71850 ** Synopsis: r[P2]=P4
71851 **
71852 ** P4 is a pointer to a 64-bit floating point value.
71853 ** Write that value into register P2.
71854 */
71855 case OP_Real: { /* same as TK_FLOAT, out2 */
71856 pOut = out2Prerelease(p, pOp);
71857 pOut->flags = MEM_Real;
71858 assert( !sqlite3IsNaN(*pOp->p4.pReal) );
71859 pOut->u.r = *pOp->p4.pReal;
71860 break;
71861 }
@@ -71707,12 +71867,13 @@
71867 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
71868 ** into a String opcode before it is executed for the first time. During
71869 ** this transformation, the length of string P4 is computed and stored
71870 ** as the P1 parameter.
71871 */
71872 case OP_String8: { /* same as TK_STRING, out2 */
71873 assert( pOp->p4.z!=0 );
71874 pOut = out2Prerelease(p, pOp);
71875 pOp->opcode = OP_String;
71876 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
71877
71878 #ifndef SQLITE_OMIT_UTF16
71879 if( encoding!=SQLITE_UTF8 ){
@@ -71745,12 +71906,13 @@
71906 ** If P5!=0 and the content of register P3 is greater than zero, then
71907 ** the datatype of the register P2 is converted to BLOB. The content is
71908 ** the same sequence of bytes, it is merely interpreted as a BLOB instead
71909 ** of a string, as if it had been CAST.
71910 */
71911 case OP_String: { /* out2 */
71912 assert( pOp->p4.z!=0 );
71913 pOut = out2Prerelease(p, pOp);
71914 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
71915 pOut->z = pOp->p4.z;
71916 pOut->n = pOp->p1;
71917 pOut->enc = encoding;
71918 UPDATE_MAX_BLOBSIZE(pOut);
@@ -71774,13 +71936,14 @@
71936 **
71937 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
71938 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
71939 ** OP_Ne or OP_Eq.
71940 */
71941 case OP_Null: { /* out2 */
71942 int cnt;
71943 u16 nullFlag;
71944 pOut = out2Prerelease(p, pOp);
71945 cnt = pOp->p3-pOp->p2;
71946 assert( pOp->p3<=(p->nMem-p->nCursor) );
71947 pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
71948 while( cnt>0 ){
71949 pOut++;
@@ -71811,12 +71974,13 @@
71974 ** Synopsis: r[P2]=P4 (len=P1)
71975 **
71976 ** P4 points to a blob of data P1 bytes long. Store this
71977 ** blob in register P2.
71978 */
71979 case OP_Blob: { /* out2 */
71980 assert( pOp->p1 <= SQLITE_MAX_LENGTH );
71981 pOut = out2Prerelease(p, pOp);
71982 sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
71983 pOut->enc = encoding;
71984 UPDATE_MAX_BLOBSIZE(pOut);
71985 break;
71986 }
@@ -71827,19 +71991,20 @@
71991 ** Transfer the values of bound parameter P1 into register P2
71992 **
71993 ** If the parameter is named, then its name appears in P4.
71994 ** The P4 value is used by sqlite3_bind_parameter_name().
71995 */
71996 case OP_Variable: { /* out2 */
71997 Mem *pVar; /* Value being transferred */
71998
71999 assert( pOp->p1>0 && pOp->p1<=p->nVar );
72000 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
72001 pVar = &p->aVar[pOp->p1 - 1];
72002 if( sqlite3VdbeMemTooBig(pVar) ){
72003 goto too_big;
72004 }
72005 pOut = out2Prerelease(p, pOp);
72006 sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
72007 UPDATE_MAX_BLOBSIZE(pOut);
72008 break;
72009 }
72010
@@ -71870,14 +72035,15 @@
72035 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
72036 assert( memIsValid(pIn1) );
72037 memAboutToChange(p, pOut);
72038 sqlite3VdbeMemMove(pOut, pIn1);
72039 #ifdef SQLITE_DEBUG
72040 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<pOut ){
72041 pOut->pScopyFrom += pOp->p2 - p1;
72042 }
72043 #endif
72044 Deephemeralize(pOut);
72045 REGISTER_TRACE(p2++, pOut);
72046 pIn1++;
72047 pOut++;
72048 }while( --n );
72049 break;
@@ -72012,11 +72178,11 @@
72178 }
72179 if( db->mallocFailed ) goto no_mem;
72180
72181 /* Return SQLITE_ROW
72182 */
72183 p->pc = (int)(pOp - aOp) + 1;
72184 rc = SQLITE_ROW;
72185 goto vdbe_return;
72186 }
72187
72188 /* Opcode: Concat P1 P2 P3 * *
@@ -72258,11 +72424,11 @@
72424 REGISTER_TRACE(pOp->p2+i, pArg);
72425 }
72426
72427 assert( pOp->p4type==P4_FUNCDEF );
72428 ctx.pFunc = pOp->p4.pFunc;
72429 ctx.iOp = (int)(pOp - aOp);
72430 ctx.pVdbe = p;
72431 MemSetTypeFlag(ctx.pOut, MEM_Null);
72432 ctx.fErrorOrAux = 0;
72433 db->lastRowid = lastRowid;
72434 (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
@@ -72272,11 +72438,11 @@
72438 if( ctx.fErrorOrAux ){
72439 if( ctx.isError ){
72440 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut));
72441 rc = ctx.isError;
72442 }
72443 sqlite3VdbeDeleteAuxData(p, (int)(pOp - aOp), pOp->p1);
72444 }
72445
72446 /* Copy the result of the function into register P3 */
72447 sqlite3VdbeChangeEncoding(ctx.pOut, encoding);
72448 if( sqlite3VdbeMemTooBig(ctx.pOut) ){
@@ -72401,12 +72567,11 @@
72567 if( (pIn1->flags & MEM_Int)==0 ){
72568 if( pOp->p2==0 ){
72569 rc = SQLITE_MISMATCH;
72570 goto abort_due_to_error;
72571 }else{
72572 goto jump_to_p2;
 
72573 }
72574 }
72575 }
72576 MemSetTypeFlag(pIn1, MEM_Int);
72577 break;
@@ -72588,11 +72753,11 @@
72753 MemSetTypeFlag(pOut, MEM_Null);
72754 REGISTER_TRACE(pOp->p2, pOut);
72755 }else{
72756 VdbeBranchTaken(2,3);
72757 if( pOp->p5 & SQLITE_JUMPIFNULL ){
72758 goto jump_to_p2;
72759 }
72760 }
72761 break;
72762 }
72763 }else{
@@ -72639,10 +72804,16 @@
72804 case OP_Lt: res = res<0; break;
72805 case OP_Le: res = res<=0; break;
72806 case OP_Gt: res = res>0; break;
72807 default: res = res>=0; break;
72808 }
72809
72810 /* Undo any changes made by applyAffinity() to the input registers. */
72811 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
72812 pIn1->flags = flags1;
72813 assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
72814 pIn3->flags = flags3;
72815
72816 if( pOp->p5 & SQLITE_STOREP2 ){
72817 pOut = &aMem[pOp->p2];
72818 memAboutToChange(p, pOut);
72819 MemSetTypeFlag(pOut, MEM_Int);
@@ -72649,18 +72820,13 @@
72820 pOut->u.i = res;
72821 REGISTER_TRACE(pOp->p2, pOut);
72822 }else{
72823 VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
72824 if( res ){
72825 goto jump_to_p2;
72826 }
72827 }
 
 
 
 
 
72828 break;
72829 }
72830
72831 /* Opcode: Permutation * * * P4 *
72832 **
@@ -72751,15 +72917,15 @@
72917 ** in the most recent OP_Compare instruction the P1 vector was less than
72918 ** equal to, or greater than the P2 vector, respectively.
72919 */
72920 case OP_Jump: { /* jump */
72921 if( iCompare<0 ){
72922 VdbeBranchTaken(0,3); pOp = &aOp[pOp->p1 - 1];
72923 }else if( iCompare==0 ){
72924 VdbeBranchTaken(1,3); pOp = &aOp[pOp->p2 - 1];
72925 }else{
72926 VdbeBranchTaken(2,3); pOp = &aOp[pOp->p3 - 1];
72927 }
72928 break;
72929 }
72930
72931 /* Opcode: And P1 P2 P3 * *
@@ -72865,11 +73031,11 @@
73031 */
73032 case OP_Once: { /* jump */
73033 assert( pOp->p1<p->nOnceFlag );
73034 VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
73035 if( p->aOnceFlag[pOp->p1] ){
73036 goto jump_to_p2;
73037 }else{
73038 p->aOnceFlag[pOp->p1] = 1;
73039 }
73040 break;
73041 }
@@ -72900,11 +73066,11 @@
73066 #endif
73067 if( pOp->opcode==OP_IfNot ) c = !c;
73068 }
73069 VdbeBranchTaken(c!=0, 2);
73070 if( c ){
73071 goto jump_to_p2;
73072 }
73073 break;
73074 }
73075
73076 /* Opcode: IsNull P1 P2 * * *
@@ -72914,11 +73080,11 @@
73080 */
73081 case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
73082 pIn1 = &aMem[pOp->p1];
73083 VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
73084 if( (pIn1->flags & MEM_Null)!=0 ){
73085 goto jump_to_p2;
73086 }
73087 break;
73088 }
73089
73090 /* Opcode: NotNull P1 P2 * * *
@@ -72928,11 +73094,11 @@
73094 */
73095 case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
73096 pIn1 = &aMem[pOp->p1];
73097 VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
73098 if( (pIn1->flags & MEM_Null)==0 ){
73099 goto jump_to_p2;
73100 }
73101 break;
73102 }
73103
73104 /* Opcode: Column P1 P2 P3 P4 P5
@@ -73142,11 +73308,11 @@
73308 rc = SQLITE_CORRUPT_BKPT;
73309 goto op_column_error;
73310 }
73311 }
73312
73313 /* If after trying to extract new entries from the header, nHdrParsed is
73314 ** still not up to p2, that means that the record has fewer than p2
73315 ** columns. So the result will be either the default value or a NULL.
73316 */
73317 if( pC->nHdrParsed<=p2 ){
73318 if( pOp->p4type==P4_MEM ){
@@ -73266,11 +73432,11 @@
73432 u8 *zNewRecord; /* A buffer to hold the data for the new record */
73433 Mem *pRec; /* The new record */
73434 u64 nData; /* Number of bytes of data space */
73435 int nHdr; /* Number of bytes of header space */
73436 i64 nByte; /* Data space required for this record */
73437 i64 nZero; /* Number of zero bytes at the end of the record */
73438 int nVarint; /* Number of bytes in a varint */
73439 u32 serial_type; /* Type field */
73440 Mem *pData0; /* First field to be combined into the record */
73441 Mem *pLast; /* Last field of the record */
73442 int nField; /* Number of fields in the record */
@@ -73358,11 +73524,11 @@
73524 nVarint = sqlite3VarintLen(nHdr);
73525 nHdr += nVarint;
73526 if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
73527 }
73528 nByte = nHdr+nData;
73529 if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){
73530 goto too_big;
73531 }
73532
73533 /* Make sure the output register has a buffer large enough to store
73534 ** the new record. The output register (pOp->p3) is not allowed to
@@ -73409,18 +73575,19 @@
73575 **
73576 ** Store the number of entries (an integer value) in the table or index
73577 ** opened by cursor P1 in register P2
73578 */
73579 #ifndef SQLITE_OMIT_BTREECOUNT
73580 case OP_Count: { /* out2 */
73581 i64 nEntry;
73582 BtCursor *pCrsr;
73583
73584 pCrsr = p->apCsr[pOp->p1]->pCursor;
73585 assert( pCrsr );
73586 nEntry = 0; /* Not needed. Only used to silence a warning. */
73587 rc = sqlite3BtreeCount(pCrsr, &nEntry);
73588 pOut = out2Prerelease(p, pOp);
73589 pOut->u.i = nEntry;
73590 break;
73591 }
73592 #endif
73593
@@ -73530,11 +73697,11 @@
73697 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
73698 goto vdbe_return;
73699 }
73700 db->autoCommit = 1;
73701 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73702 p->pc = (int)(pOp - aOp);
73703 db->autoCommit = 0;
73704 p->rc = rc = SQLITE_BUSY;
73705 goto vdbe_return;
73706 }
73707 db->isTransactionSavepoint = 0;
@@ -73589,11 +73756,11 @@
73756 }else{
73757 db->nDeferredCons = pSavepoint->nDeferredCons;
73758 db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
73759 }
73760
73761 if( !isTransaction || p1==SAVEPOINT_ROLLBACK ){
73762 rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
73763 if( rc!=SQLITE_OK ) goto abort_due_to_error;
73764 }
73765 }
73766 }
@@ -73649,11 +73816,11 @@
73816 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
73817 goto vdbe_return;
73818 }else{
73819 db->autoCommit = (u8)desiredAutoCommit;
73820 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
73821 p->pc = (int)(pOp - aOp);
73822 db->autoCommit = (u8)(1-desiredAutoCommit);
73823 p->rc = rc = SQLITE_BUSY;
73824 goto vdbe_return;
73825 }
73826 }
@@ -73726,11 +73893,11 @@
73893 pBt = db->aDb[pOp->p1].pBt;
73894
73895 if( pBt ){
73896 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
73897 if( rc==SQLITE_BUSY ){
73898 p->pc = (int)(pOp - aOp);
73899 p->rc = rc = SQLITE_BUSY;
73900 goto vdbe_return;
73901 }
73902 if( rc!=SQLITE_OK ){
73903 goto abort_due_to_error;
@@ -73805,11 +73972,11 @@
73972 **
73973 ** There must be a read-lock on the database (either a transaction
73974 ** must be started or there must be an open cursor) before
73975 ** executing this instruction.
73976 */
73977 case OP_ReadCookie: { /* out2 */
73978 int iMeta;
73979 int iDb;
73980 int iCookie;
73981
73982 assert( p->bIsReader );
@@ -73819,10 +73986,11 @@
73986 assert( iDb>=0 && iDb<db->nDb );
73987 assert( db->aDb[iDb].pBt!=0 );
73988 assert( DbMaskTest(p->btreeMask, iDb) );
73989
73990 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
73991 pOut = out2Prerelease(p, pOp);
73992 pOut->u.i = iMeta;
73993 break;
73994 }
73995
73996 /* Opcode: SetCookie P1 P2 P3 * *
@@ -74140,11 +74308,11 @@
74308 VdbeCursor *pC;
74309 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74310 pC = p->apCsr[pOp->p1];
74311 assert( pC->pSorter );
74312 if( (pC->seqCount++)==0 ){
74313 goto jump_to_p2;
74314 }
74315 break;
74316 }
74317
74318 /* Opcode: OpenPseudo P1 P2 P3 * *
@@ -74317,11 +74485,11 @@
74485 ** loss of information, then special processing is required... */
74486 if( (pIn3->flags & MEM_Int)==0 ){
74487 if( (pIn3->flags & MEM_Real)==0 ){
74488 /* If the P3 value cannot be converted into any kind of a number,
74489 ** then the seek is not possible, so jump to P2 */
74490 VdbeBranchTaken(1,2); goto jump_to_p2;
74491 break;
74492 }
74493
74494 /* If the approximation iKey is larger than the actual real search
74495 ** term, substitute >= for > and < for <=. e.g. if the search term
@@ -74408,11 +74576,11 @@
74576 }
74577 }
74578 assert( pOp->p2>0 );
74579 VdbeBranchTaken(res!=0,2);
74580 if( res ){
74581 goto jump_to_p2;
74582 }
74583 break;
74584 }
74585
74586 /* Opcode: Seek P1 P2 * * *
@@ -74502,10 +74670,11 @@
74670 */
74671 case OP_NoConflict: /* jump, in3 */
74672 case OP_NotFound: /* jump, in3 */
74673 case OP_Found: { /* jump, in3 */
74674 int alreadyExists;
74675 int takeJump;
74676 int ii;
74677 VdbeCursor *pC;
74678 int res;
74679 char *pFree;
74680 UnpackedRecord *pIdxKey;
@@ -74524,11 +74693,11 @@
74693 pC->seekOp = pOp->opcode;
74694 #endif
74695 pIn3 = &aMem[pOp->p3];
74696 assert( pC->pCursor!=0 );
74697 assert( pC->isTable==0 );
74698 pFree = 0;
74699 if( pOp->p4.i>0 ){
74700 r.pKeyInfo = pC->pKeyInfo;
74701 r.nField = (u16)pOp->p4.i;
74702 r.aMem = pIn3;
74703 for(ii=0; ii<r.nField; ii++){
@@ -74547,25 +74716,24 @@
74716 assert( pIn3->flags & MEM_Blob );
74717 ExpandBlob(pIn3);
74718 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
74719 }
74720 pIdxKey->default_rc = 0;
74721 takeJump = 0;
74722 if( pOp->opcode==OP_NoConflict ){
74723 /* For the OP_NoConflict opcode, take the jump if any of the
74724 ** input fields are NULL, since any key with a NULL will not
74725 ** conflict */
74726 for(ii=0; ii<pIdxKey->nField; ii++){
74727 if( pIdxKey->aMem[ii].flags & MEM_Null ){
74728 takeJump = 1;
74729 break;
74730 }
74731 }
74732 }
74733 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
74734 sqlite3DbFree(db, pFree);
 
 
74735 if( rc!=SQLITE_OK ){
74736 break;
74737 }
74738 pC->seekResult = res;
74739 alreadyExists = (res==0);
@@ -74572,14 +74740,14 @@
74740 pC->nullRow = 1-alreadyExists;
74741 pC->deferredMoveto = 0;
74742 pC->cacheStatus = CACHE_STALE;
74743 if( pOp->opcode==OP_Found ){
74744 VdbeBranchTaken(alreadyExists!=0,2);
74745 if( alreadyExists ) goto jump_to_p2;
74746 }else{
74747 VdbeBranchTaken(takeJump||alreadyExists==0,2);
74748 if( takeJump || !alreadyExists ) goto jump_to_p2;
74749 }
74750 break;
74751 }
74752
74753 /* Opcode: NotExists P1 P2 P3 * *
@@ -74624,14 +74792,12 @@
74792 pC->movetoTarget = iKey; /* Used by OP_Delete */
74793 pC->nullRow = 0;
74794 pC->cacheStatus = CACHE_STALE;
74795 pC->deferredMoveto = 0;
74796 VdbeBranchTaken(res!=0,2);
 
 
 
74797 pC->seekResult = res;
74798 if( res!=0 ) goto jump_to_p2;
74799 break;
74800 }
74801
74802 /* Opcode: Sequence P1 P2 * * *
74803 ** Synopsis: r[P2]=cursor[P1].ctr++
@@ -74639,13 +74805,14 @@
74805 ** Find the next available sequence number for cursor P1.
74806 ** Write the sequence number into register P2.
74807 ** The sequence number on the cursor is incremented after this
74808 ** instruction.
74809 */
74810 case OP_Sequence: { /* out2 */
74811 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74812 assert( p->apCsr[pOp->p1]!=0 );
74813 pOut = out2Prerelease(p, pOp);
74814 pOut->u.i = p->apCsr[pOp->p1]->seqCount++;
74815 break;
74816 }
74817
74818
@@ -74662,20 +74829,21 @@
74829 ** allowed to be less than this value. When this value reaches its maximum,
74830 ** an SQLITE_FULL error is generated. The P3 register is updated with the '
74831 ** generated record number. This P3 mechanism is used to help implement the
74832 ** AUTOINCREMENT feature.
74833 */
74834 case OP_NewRowid: { /* out2 */
74835 i64 v; /* The new rowid */
74836 VdbeCursor *pC; /* Cursor of table to get the new rowid */
74837 int res; /* Result of an sqlite3BtreeLast() */
74838 int cnt; /* Counter to limit the number of searches */
74839 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
74840 VdbeFrame *pFrame; /* Root frame of VDBE */
74841
74842 v = 0;
74843 res = 0;
74844 pOut = out2Prerelease(p, pOp);
74845 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
74846 pC = p->apCsr[pOp->p1];
74847 assert( pC!=0 );
74848 if( NEVER(pC->pCursor==0) ){
74849 /* The zero initialization above is all that is needed */
@@ -74985,13 +75153,11 @@
75153 pIn3 = &aMem[pOp->p3];
75154 nKeyCol = pOp->p4.i;
75155 res = 0;
75156 rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res);
75157 VdbeBranchTaken(res!=0,2);
75158 if( res ) goto jump_to_p2;
 
 
75159 break;
75160 };
75161
75162 /* Opcode: SorterData P1 P2 P3 * *
75163 ** Synopsis: r[P2]=data
@@ -75116,16 +75282,17 @@
75282 **
75283 ** P1 can be either an ordinary table or a virtual table. There used to
75284 ** be a separate OP_VRowid opcode for use with virtual tables, but this
75285 ** one opcode now works for both table types.
75286 */
75287 case OP_Rowid: { /* out2 */
75288 VdbeCursor *pC;
75289 i64 v;
75290 sqlite3_vtab *pVtab;
75291 const sqlite3_module *pModule;
75292
75293 pOut = out2Prerelease(p, pOp);
75294 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
75295 pC = p->apCsr[pOp->p1];
75296 assert( pC!=0 );
75297 assert( pC->pseudoTableReg==0 || pC->nullRow );
75298 if( pC->nullRow ){
@@ -75174,11 +75341,11 @@
75341 sqlite3BtreeClearCursor(pC->pCursor);
75342 }
75343 break;
75344 }
75345
75346 /* Opcode: Last P1 P2 P3 * *
75347 **
75348 ** The next use of the Rowid or Column or Prev instruction for P1
75349 ** will refer to the last entry in the database table or index.
75350 ** If the table or index is empty and P2>0, then jump immediately to P2.
75351 ** If P2 is 0 or if the table or index is not empty, fall through
@@ -75201,16 +75368,17 @@
75368 assert( pCrsr!=0 );
75369 rc = sqlite3BtreeLast(pCrsr, &res);
75370 pC->nullRow = (u8)res;
75371 pC->deferredMoveto = 0;
75372 pC->cacheStatus = CACHE_STALE;
75373 pC->seekResult = pOp->p3;
75374 #ifdef SQLITE_DEBUG
75375 pC->seekOp = OP_Last;
75376 #endif
75377 if( pOp->p2>0 ){
75378 VdbeBranchTaken(res!=0,2);
75379 if( res ) goto jump_to_p2;
75380 }
75381 break;
75382 }
75383
75384
@@ -75270,13 +75438,11 @@
75438 pC->cacheStatus = CACHE_STALE;
75439 }
75440 pC->nullRow = (u8)res;
75441 assert( pOp->p2>0 && pOp->p2<p->nOp );
75442 VdbeBranchTaken(res!=0,2);
75443 if( res ) goto jump_to_p2;
 
 
75444 break;
75445 }
75446
75447 /* Opcode: Next P1 P2 P3 P4 P5
75448 **
@@ -75383,15 +75549,15 @@
75549 next_tail:
75550 pC->cacheStatus = CACHE_STALE;
75551 VdbeBranchTaken(res==0,2);
75552 if( res==0 ){
75553 pC->nullRow = 0;
 
75554 p->aCounter[pOp->p5]++;
75555 #ifdef SQLITE_TEST
75556 sqlite3_search_count++;
75557 #endif
75558 goto jump_to_p2_and_check_for_interrupt;
75559 }else{
75560 pC->nullRow = 1;
75561 }
75562 goto check_for_interrupt;
75563 }
@@ -75495,15 +75661,16 @@
75661 ** the end of the index key pointed to by cursor P1. This integer should be
75662 ** the rowid of the table entry to which this index entry points.
75663 **
75664 ** See also: Rowid, MakeRecord.
75665 */
75666 case OP_IdxRowid: { /* out2 */
75667 BtCursor *pCrsr;
75668 VdbeCursor *pC;
75669 i64 rowid;
75670
75671 pOut = out2Prerelease(p, pOp);
75672 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
75673 pC = p->apCsr[pOp->p1];
75674 assert( pC!=0 );
75675 pCrsr = pC->pCursor;
75676 assert( pCrsr!=0 );
@@ -75612,13 +75779,11 @@
75779 }else{
75780 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
75781 res++;
75782 }
75783 VdbeBranchTaken(res>0,2);
75784 if( res>0 ) goto jump_to_p2;
 
 
75785 break;
75786 }
75787
75788 /* Opcode: Destroy P1 P2 P3 * *
75789 **
@@ -75638,15 +75803,16 @@
75803 ** the last one in the database) then a zero is stored in register P2.
75804 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
75805 **
75806 ** See also: Clear
75807 */
75808 case OP_Destroy: { /* out2 */
75809 int iMoved;
75810 int iDb;
75811
75812 assert( p->readOnly==0 );
75813 pOut = out2Prerelease(p, pOp);
75814 pOut->flags = MEM_Null;
75815 if( db->nVdbeRead > db->nVDestroy+1 ){
75816 rc = SQLITE_LOCKED;
75817 p->errorAction = OE_Abort;
75818 }else{
@@ -75751,16 +75917,17 @@
75917 ** P1>1. Write the root page number of the new table into
75918 ** register P2.
75919 **
75920 ** See documentation on OP_CreateTable for additional information.
75921 */
75922 case OP_CreateIndex: /* out2 */
75923 case OP_CreateTable: { /* out2 */
75924 int pgno;
75925 int flags;
75926 Db *pDb;
75927
75928 pOut = out2Prerelease(p, pOp);
75929 pgno = 0;
75930 assert( pOp->p1>=0 && pOp->p1<db->nDb );
75931 assert( DbMaskTest(p->btreeMask, pOp->p1) );
75932 assert( p->readOnly==0 );
75933 pDb = &db->aDb[pOp->p1];
@@ -75982,16 +76149,16 @@
76149 if( (pIn1->flags & MEM_RowSet)==0
76150 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
76151 ){
76152 /* The boolean index is empty */
76153 sqlite3VdbeMemSetNull(pIn1);
 
76154 VdbeBranchTaken(1,2);
76155 goto jump_to_p2_and_check_for_interrupt;
76156 }else{
76157 /* A value was pulled from the index */
 
76158 VdbeBranchTaken(0,2);
76159 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
76160 }
76161 goto check_for_interrupt;
76162 }
76163
76164 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -76038,14 +76205,11 @@
76205 assert( pOp->p4type==P4_INT32 );
76206 assert( iSet==-1 || iSet>=0 );
76207 if( iSet ){
76208 exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i);
76209 VdbeBranchTaken(exists!=0,2);
76210 if( exists ) goto jump_to_p2;
 
 
 
76211 }
76212 if( iSet>=0 ){
76213 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
76214 }
76215 break;
@@ -76130,11 +76294,11 @@
76294 pRt->u.pFrame = pFrame;
76295
76296 pFrame->v = p;
76297 pFrame->nChildMem = nMem;
76298 pFrame->nChildCsr = pProgram->nCsr;
76299 pFrame->pc = (int)(pOp - aOp);
76300 pFrame->aMem = p->aMem;
76301 pFrame->nMem = p->nMem;
76302 pFrame->apCsr = p->apCsr;
76303 pFrame->nCursor = p->nCursor;
76304 pFrame->aOp = p->aOp;
@@ -76153,11 +76317,11 @@
76317 }
76318 }else{
76319 pFrame = pRt->u.pFrame;
76320 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
76321 assert( pProgram->nCsr==pFrame->nChildCsr );
76322 assert( (int)(pOp - aOp)==pFrame->pc );
76323 }
76324
76325 p->nFrame++;
76326 pFrame->pParent = p->pFrame;
76327 pFrame->lastRowid = lastRowid;
@@ -76174,11 +76338,11 @@
76338 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
76339 p->nOnceFlag = pProgram->nOnce;
76340 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
76341 p->anExec = 0;
76342 #endif
76343 pOp = &aOp[-1];
76344 memset(p->aOnceFlag, 0, p->nOnceFlag);
76345
76346 break;
76347 }
76348
@@ -76192,13 +76356,14 @@
76356 **
76357 ** The address of the cell in the parent frame is determined by adding
76358 ** the value of the P1 argument to the value of the P1 argument to the
76359 ** calling OP_Program instruction.
76360 */
76361 case OP_Param: { /* out2 */
76362 VdbeFrame *pFrame;
76363 Mem *pIn;
76364 pOut = out2Prerelease(p, pOp);
76365 pFrame = p->pFrame;
76366 pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
76367 sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem);
76368 break;
76369 }
@@ -76238,14 +76403,14 @@
76403 ** (immediate foreign key constraint violations).
76404 */
76405 case OP_FkIfZero: { /* jump */
76406 if( pOp->p1 ){
76407 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
76408 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
76409 }else{
76410 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
76411 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
76412 }
76413 break;
76414 }
76415 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
76416
@@ -76292,13 +76457,11 @@
76457 */
76458 case OP_IfPos: { /* jump, in1 */
76459 pIn1 = &aMem[pOp->p1];
76460 assert( pIn1->flags&MEM_Int );
76461 VdbeBranchTaken( pIn1->u.i>0, 2);
76462 if( pIn1->u.i>0 ) goto jump_to_p2;
 
 
76463 break;
76464 }
76465
76466 /* Opcode: IfNeg P1 P2 P3 * *
76467 ** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2
@@ -76309,13 +76472,11 @@
76472 case OP_IfNeg: { /* jump, in1 */
76473 pIn1 = &aMem[pOp->p1];
76474 assert( pIn1->flags&MEM_Int );
76475 pIn1->u.i += pOp->p3;
76476 VdbeBranchTaken(pIn1->u.i<0, 2);
76477 if( pIn1->u.i<0 ) goto jump_to_p2;
 
 
76478 break;
76479 }
76480
76481 /* Opcode: IfNotZero P1 P2 P3 * *
76482 ** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2
@@ -76328,11 +76489,11 @@
76489 pIn1 = &aMem[pOp->p1];
76490 assert( pIn1->flags&MEM_Int );
76491 VdbeBranchTaken(pIn1->u.i<0, 2);
76492 if( pIn1->u.i ){
76493 pIn1->u.i += pOp->p3;
76494 goto jump_to_p2;
76495 }
76496 break;
76497 }
76498
76499 /* Opcode: DecrJumpZero P1 P2 * * *
@@ -76344,13 +76505,11 @@
76505 case OP_DecrJumpZero: { /* jump, in1 */
76506 pIn1 = &aMem[pOp->p1];
76507 assert( pIn1->flags&MEM_Int );
76508 pIn1->u.i--;
76509 VdbeBranchTaken(pIn1->u.i==0, 2);
76510 if( pIn1->u.i==0 ) goto jump_to_p2;
 
 
76511 break;
76512 }
76513
76514
76515 /* Opcode: JumpZeroIncr P1 P2 * * *
@@ -76362,13 +76521,11 @@
76521 */
76522 case OP_JumpZeroIncr: { /* jump, in1 */
76523 pIn1 = &aMem[pOp->p1];
76524 assert( pIn1->flags&MEM_Int );
76525 VdbeBranchTaken(pIn1->u.i==0, 2);
76526 if( (pIn1->u.i++)==0 ) goto jump_to_p2;
 
 
76527 break;
76528 }
76529
76530 /* Opcode: AggStep * P2 P3 P4 P5
76531 ** Synopsis: accum=r[P3] step(r[P2@P5])
@@ -76406,11 +76563,11 @@
76563 pMem->n++;
76564 sqlite3VdbeMemInit(&t, db, MEM_Null);
76565 ctx.pOut = &t;
76566 ctx.isError = 0;
76567 ctx.pVdbe = p;
76568 ctx.iOp = (int)(pOp - aOp);
76569 ctx.skipFlag = 0;
76570 (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
76571 if( ctx.isError ){
76572 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t));
76573 rc = ctx.isError;
@@ -76501,19 +76658,20 @@
76658 **
76659 ** If changing into or out of WAL mode the procedure is more complicated.
76660 **
76661 ** Write a string containing the final journal-mode to register P2.
76662 */
76663 case OP_JournalMode: { /* out2 */
76664 Btree *pBt; /* Btree to change journal mode of */
76665 Pager *pPager; /* Pager associated with pBt */
76666 int eNew; /* New journal mode */
76667 int eOld; /* The old journal mode */
76668 #ifndef SQLITE_OMIT_WAL
76669 const char *zFilename; /* Name of database file for pPager */
76670 #endif
76671
76672 pOut = out2Prerelease(p, pOp);
76673 eNew = pOp->p3;
76674 assert( eNew==PAGER_JOURNALMODE_DELETE
76675 || eNew==PAGER_JOURNALMODE_TRUNCATE
76676 || eNew==PAGER_JOURNALMODE_PERSIST
76677 || eNew==PAGER_JOURNALMODE_OFF
@@ -76585,11 +76743,10 @@
76743 if( rc ){
76744 eNew = eOld;
76745 }
76746 eNew = sqlite3PagerSetJournalMode(pPager, eNew);
76747
 
76748 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
76749 pOut->z = (char *)sqlite3JournalModename(eNew);
76750 pOut->n = sqlite3Strlen30(pOut->z);
76751 pOut->enc = SQLITE_UTF8;
76752 sqlite3VdbeChangeEncoding(pOut, encoding);
@@ -76626,12 +76783,12 @@
76783 assert( p->readOnly==0 );
76784 pBt = db->aDb[pOp->p1].pBt;
76785 rc = sqlite3BtreeIncrVacuum(pBt);
76786 VdbeBranchTaken(rc==SQLITE_DONE,2);
76787 if( rc==SQLITE_DONE ){
 
76788 rc = SQLITE_OK;
76789 goto jump_to_p2;
76790 }
76791 break;
76792 }
76793 #endif
76794
@@ -76780,12 +76937,13 @@
76937 pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
76938 if( pCur ){
76939 pCur->pVtabCursor = pVtabCursor;
76940 pVtab->nRef++;
76941 }else{
76942 assert( db->mallocFailed );
76943 pModule->xClose(pVtabCursor);
76944 goto no_mem;
76945 }
76946 }
76947 break;
76948 }
76949 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -76837,29 +76995,23 @@
76995 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
76996 nArg = (int)pArgc->u.i;
76997 iQuery = (int)pQuery->u.i;
76998
76999 /* Invoke the xFilter method */
77000 res = 0;
77001 apArg = p->apArg;
77002 for(i = 0; i<nArg; i++){
77003 apArg[i] = &pArgc[i+1];
77004 }
77005 rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
77006 sqlite3VtabImportErrmsg(p, pVtab);
77007 if( rc==SQLITE_OK ){
77008 res = pModule->xEof(pVtabCursor);
 
 
 
 
 
 
 
77009 }
77010 pCur->nullRow = 0;
77011 VdbeBranchTaken(res!=0,2);
77012 if( res ) goto jump_to_p2;
77013 break;
77014 }
77015 #endif /* SQLITE_OMIT_VIRTUALTABLE */
77016
77017 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76942,11 +77094,11 @@
77094 res = pModule->xEof(pCur->pVtabCursor);
77095 }
77096 VdbeBranchTaken(!res,2);
77097 if( !res ){
77098 /* If there is data, jump to P2 */
77099 goto jump_to_p2_and_check_for_interrupt;
77100 }
77101 goto check_for_interrupt;
77102 }
77103 #endif /* SQLITE_OMIT_VIRTUALTABLE */
77104
@@ -77065,11 +77217,12 @@
77217 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
77218 /* Opcode: Pagecount P1 P2 * * *
77219 **
77220 ** Write the current number of pages in database P1 to memory cell P2.
77221 */
77222 case OP_Pagecount: { /* out2 */
77223 pOut = out2Prerelease(p, pOp);
77224 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
77225 break;
77226 }
77227 #endif
77228
@@ -77081,14 +77234,15 @@
77234 ** Do not let the maximum page count fall below the current page count and
77235 ** do not change the maximum page count value if P3==0.
77236 **
77237 ** Store the maximum page count after the change in register P2.
77238 */
77239 case OP_MaxPgcnt: { /* out2 */
77240 unsigned int newMax;
77241 Btree *pBt;
77242
77243 pOut = out2Prerelease(p, pOp);
77244 pBt = db->aDb[pOp->p1].pBt;
77245 newMax = 0;
77246 if( pOp->p3 ){
77247 newMax = sqlite3BtreeLastPage(pBt);
77248 if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3;
@@ -77113,13 +77267,10 @@
77267 */
77268 case OP_Init: { /* jump */
77269 char *zTrace;
77270 char *z;
77271
 
 
 
77272 #ifndef SQLITE_OMIT_TRACE
77273 if( db->xTrace
77274 && !p->doingRerun
77275 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
77276 ){
@@ -77143,10 +77294,11 @@
77294 ){
77295 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
77296 }
77297 #endif /* SQLITE_DEBUG */
77298 #endif /* SQLITE_OMIT_TRACE */
77299 if( pOp->p2 ) goto jump_to_p2;
77300 break;
77301 }
77302
77303
77304 /* Opcode: Noop * * * * *
@@ -77174,31 +77326,31 @@
77326 }
77327
77328 #ifdef VDBE_PROFILE
77329 {
77330 u64 endTime = sqlite3Hwtime();
77331 if( endTime>start ) pOrigOp->cycles += endTime - start;
77332 pOrigOp->cnt++;
77333 }
77334 #endif
77335
77336 /* The following code adds nothing to the actual functionality
77337 ** of the program. It is only here for testing and debugging.
77338 ** On the other hand, it does burn CPU cycles every time through
77339 ** the evaluator loop. So we can leave it out when NDEBUG is defined.
77340 */
77341 #ifndef NDEBUG
77342 assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] );
77343
77344 #ifdef SQLITE_DEBUG
77345 if( db->flags & SQLITE_VdbeTrace ){
77346 if( rc!=0 ) printf("rc=%d\n",rc);
77347 if( pOrigOp->opflags & (OPFLG_OUT2) ){
77348 registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
77349 }
77350 if( pOrigOp->opflags & OPFLG_OUT3 ){
77351 registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
77352 }
77353 }
77354 #endif /* SQLITE_DEBUG */
77355 #endif /* NDEBUG */
77356 } /* The end of the for(;;) loop the loops through opcodes */
@@ -77209,11 +77361,11 @@
77361 vdbe_error_halt:
77362 assert( rc );
77363 p->rc = rc;
77364 testcase( sqlite3GlobalConfig.xLog!=0 );
77365 sqlite3_log(rc, "statement aborts at %d: [%s] %s",
77366 (int)(pOp - aOp), p->zSql, p->zErrMsg);
77367 sqlite3VdbeHalt(p);
77368 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
77369 rc = SQLITE_ERROR;
77370 if( resetSchemaOnFault>0 ){
77371 sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
@@ -78035,20 +78187,23 @@
78187 **
78188 ** In both cases, the effects of the main thread seeing (bDone==0) even
78189 ** after the thread has finished are not dire. So we don't worry about
78190 ** memory barriers and such here.
78191 */
78192 typedef int (*SorterCompare)(SortSubtask*,int*,const void*,int,const void*,int);
78193 struct SortSubtask {
78194 SQLiteThread *pThread; /* Background thread, if any */
78195 int bDone; /* Set if thread is finished but not joined */
78196 VdbeSorter *pSorter; /* Sorter that owns this sub-task */
78197 UnpackedRecord *pUnpacked; /* Space to unpack a record */
78198 SorterList list; /* List for thread to write to a PMA */
78199 int nPMA; /* Number of PMAs currently in file */
78200 SorterCompare xCompare; /* Compare function to use */
78201 SorterFile file; /* Temp file for level-0 PMAs */
78202 SorterFile file2; /* Space for other PMAs */
78203 };
78204
78205
78206 /*
78207 ** Main sorter structure. A single instance of this is allocated for each
78208 ** sorter cursor created by the VDBE.
78209 **
@@ -78072,12 +78227,16 @@
78227 int nMemory; /* Size of list.aMemory allocation in bytes */
78228 u8 bUsePMA; /* True if one or more PMAs created */
78229 u8 bUseThreads; /* True to use background threads */
78230 u8 iPrev; /* Previous thread used to flush PMA */
78231 u8 nTask; /* Size of aTask[] array */
78232 u8 typeMask;
78233 SortSubtask aTask[1]; /* One or more subtasks */
78234 };
78235
78236 #define SORTER_TYPE_INTEGER 0x01
78237 #define SORTER_TYPE_TEXT 0x02
78238
78239 /*
78240 ** An instance of the following object is used to read records out of a
78241 ** PMA, in sorted order. The next key to be read is cached in nKey/aKey.
78242 ** aKey might point into aMap or into aBuffer. If neither of those locations
@@ -78486,35 +78645,165 @@
78645 rc = vdbePmaReaderNext(pReadr);
78646 }
78647 return rc;
78648 }
78649
78650 /*
78651 ** A version of vdbeSorterCompare() that assumes that it has already been
78652 ** determined that the first field of key1 is equal to the first field of
78653 ** key2.
78654 */
78655 static int vdbeSorterCompareTail(
78656 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78657 int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78658 const void *pKey1, int nKey1, /* Left side of comparison */
78659 const void *pKey2, int nKey2 /* Right side of comparison */
78660 ){
78661 UnpackedRecord *r2 = pTask->pUnpacked;
78662 if( *pbKey2Cached==0 ){
78663 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
78664 *pbKey2Cached = 1;
78665 }
78666 return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1);
78667 }
78668
78669 /*
78670 ** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2,
78671 ** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences
78672 ** used by the comparison. Return the result of the comparison.
78673 **
78674 ** If IN/OUT parameter *pbKey2Cached is true when this function is called,
78675 ** it is assumed that (pTask->pUnpacked) contains the unpacked version
78676 ** of key2. If it is false, (pTask->pUnpacked) is populated with the unpacked
78677 ** version of key2 and *pbKey2Cached set to true before returning.
78678 **
78679 ** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set
78680 ** to SQLITE_NOMEM.
78681 */
78682 static int vdbeSorterCompare(
78683 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78684 int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78685 const void *pKey1, int nKey1, /* Left side of comparison */
78686 const void *pKey2, int nKey2 /* Right side of comparison */
78687 ){
78688 UnpackedRecord *r2 = pTask->pUnpacked;
78689 if( !*pbKey2Cached ){
78690 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
78691 *pbKey2Cached = 1;
78692 }
78693 return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
78694 }
78695
78696 /*
78697 ** A specially optimized version of vdbeSorterCompare() that assumes that
78698 ** the first field of each key is a TEXT value and that the collation
78699 ** sequence to compare them with is BINARY.
78700 */
78701 static int vdbeSorterCompareText(
78702 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78703 int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78704 const void *pKey1, int nKey1, /* Left side of comparison */
78705 const void *pKey2, int nKey2 /* Right side of comparison */
78706 ){
78707 const u8 * const p1 = (const u8 * const)pKey1;
78708 const u8 * const p2 = (const u8 * const)pKey2;
78709 const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
78710 const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
78711
78712 int n1;
78713 int n2;
78714 int res;
78715
78716 getVarint32(&p1[1], n1); n1 = (n1 - 13) / 2;
78717 getVarint32(&p2[1], n2); n2 = (n2 - 13) / 2;
78718 res = memcmp(v1, v2, MIN(n1, n2));
78719 if( res==0 ){
78720 res = n1 - n2;
78721 }
78722
78723 if( res==0 ){
78724 if( pTask->pSorter->pKeyInfo->nField>1 ){
78725 res = vdbeSorterCompareTail(
78726 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
78727 );
78728 }
78729 }else{
78730 if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
78731 res = res * -1;
78732 }
78733 }
78734
78735 return res;
78736 }
78737
78738 /*
78739 ** A specially optimized version of vdbeSorterCompare() that assumes that
78740 ** the first field of each key is an INTEGER value.
78741 */
78742 static int vdbeSorterCompareInt(
78743 SortSubtask *pTask, /* Subtask context (for pKeyInfo) */
78744 int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */
78745 const void *pKey1, int nKey1, /* Left side of comparison */
78746 const void *pKey2, int nKey2 /* Right side of comparison */
78747 ){
78748 const u8 * const p1 = (const u8 * const)pKey1;
78749 const u8 * const p2 = (const u8 * const)pKey2;
78750 const int s1 = p1[1]; /* Left hand serial type */
78751 const int s2 = p2[1]; /* Right hand serial type */
78752 const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */
78753 const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */
78754 int res; /* Return value */
78755
78756 assert( (s1>0 && s1<7) || s1==8 || s1==9 );
78757 assert( (s2>0 && s2<7) || s2==8 || s2==9 );
78758
78759 if( s1>7 && s2>7 ){
78760 res = s1 - s2;
78761 }else{
78762 if( s1==s2 ){
78763 if( (*v1 ^ *v2) & 0x80 ){
78764 /* The two values have different signs */
78765 res = (*v1 & 0x80) ? -1 : +1;
78766 }else{
78767 /* The two values have the same sign. Compare using memcmp(). */
78768 static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 };
78769 int i;
78770 res = 0;
78771 for(i=0; i<aLen[s1]; i++){
78772 if( (res = v1[i] - v2[i]) ) break;
78773 }
78774 }
78775 }else{
78776 if( s2>7 ){
78777 res = +1;
78778 }else if( s1>7 ){
78779 res = -1;
78780 }else{
78781 res = s1 - s2;
78782 }
78783 assert( res!=0 );
78784
78785 if( res>0 ){
78786 if( *v1 & 0x80 ) res = -1;
78787 }else{
78788 if( *v2 & 0x80 ) res = +1;
78789 }
78790 }
78791 }
78792
78793 if( res==0 ){
78794 if( pTask->pSorter->pKeyInfo->nField>1 ){
78795 res = vdbeSorterCompareTail(
78796 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
78797 );
78798 }
78799 }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
78800 res = res * -1;
78801 }
78802
78803 return res;
78804 }
78805
78806 /*
78807 ** Initialize the temporary index cursor just opened as a sorter cursor.
78808 **
78809 ** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField)
@@ -78579,13 +78868,17 @@
78868 rc = SQLITE_NOMEM;
78869 }else{
78870 pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
78871 memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
78872 pKeyInfo->db = 0;
78873 if( nField && nWorker==0 ){
78874 pKeyInfo->nXField += (pKeyInfo->nField - nField);
78875 pKeyInfo->nField = nField;
78876 }
78877 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
78878 pSorter->nTask = nWorker + 1;
78879 pSorter->iPrev = nWorker-1;
78880 pSorter->bUseThreads = (pSorter->nTask>1);
78881 pSorter->db = db;
78882 for(i=0; i<pSorter->nTask; i++){
78883 SortSubtask *pTask = &pSorter->aTask[i];
78884 pTask->pSorter = pSorter;
@@ -78607,10 +78900,16 @@
78900 pSorter->nMemory = pgsz;
78901 pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
78902 if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM;
78903 }
78904 }
78905
78906 if( (pKeyInfo->nField+pKeyInfo->nXField)<13
78907 && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
78908 ){
78909 pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
78910 }
78911 }
78912
78913 return rc;
78914 }
78915 #undef nWorker /* Defined at the top of this function */
@@ -78631,34 +78930,28 @@
78930 ** Free all resources owned by the object indicated by argument pTask. All
78931 ** fields of *pTask are zeroed before returning.
78932 */
78933 static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){
78934 sqlite3DbFree(db, pTask->pUnpacked);
 
78935 #if SQLITE_MAX_WORKER_THREADS>0
78936 /* pTask->list.aMemory can only be non-zero if it was handed memory
78937 ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */
78938 if( pTask->list.aMemory ){
78939 sqlite3_free(pTask->list.aMemory);
 
78940 }else
78941 #endif
78942 {
78943 assert( pTask->list.aMemory==0 );
78944 vdbeSorterRecordFree(0, pTask->list.pList);
78945 }
 
78946 if( pTask->file.pFd ){
78947 sqlite3OsCloseFree(pTask->file.pFd);
 
 
78948 }
78949 if( pTask->file2.pFd ){
78950 sqlite3OsCloseFree(pTask->file2.pFd);
 
 
78951 }
78952 memset(pTask, 0, sizeof(SortSubtask));
78953 }
78954
78955 #ifdef SQLITE_DEBUG_SORTER_THREADS
78956 static void vdbeSorterWorkDebug(SortSubtask *pTask, const char *zEvent){
78957 i64 t;
@@ -78834,10 +79127,11 @@
79127 vdbeMergeEngineFree(pSorter->pMerger);
79128 pSorter->pMerger = 0;
79129 for(i=0; i<pSorter->nTask; i++){
79130 SortSubtask *pTask = &pSorter->aTask[i];
79131 vdbeSortSubtaskCleanup(db, pTask);
79132 pTask->pSorter = pSorter;
79133 }
79134 if( pSorter->list.aMemory==0 ){
79135 vdbeSorterRecordFree(0, pSorter->list.pList);
79136 }
79137 pSorter->list.pList = 0;
@@ -78943,31 +79237,45 @@
79237 SorterRecord *p2, /* Second list to merge */
79238 SorterRecord **ppOut /* OUT: Head of merged list */
79239 ){
79240 SorterRecord *pFinal = 0;
79241 SorterRecord **pp = &pFinal;
79242 int bCached = 0;
79243
79244 while( p1 && p2 ){
79245 int res;
79246 res = pTask->xCompare(
79247 pTask, &bCached, SRVAL(p1), p1->nVal, SRVAL(p2), p2->nVal
79248 );
79249
79250 if( res<=0 ){
79251 *pp = p1;
79252 pp = &p1->u.pNext;
79253 p1 = p1->u.pNext;
 
79254 }else{
79255 *pp = p2;
79256 pp = &p2->u.pNext;
79257 p2 = p2->u.pNext;
79258 bCached = 0;
 
79259 }
79260 }
79261 *pp = p1 ? p1 : p2;
79262 *ppOut = pFinal;
79263 }
79264
79265 /*
79266 ** Return the SorterCompare function to compare values collected by the
79267 ** sorter object passed as the only argument.
79268 */
79269 static SorterCompare vdbeSorterGetCompare(VdbeSorter *p){
79270 if( p->typeMask==SORTER_TYPE_INTEGER ){
79271 return vdbeSorterCompareInt;
79272 }else if( p->typeMask==SORTER_TYPE_TEXT ){
79273 return vdbeSorterCompareText;
79274 }
79275 return vdbeSorterCompare;
79276 }
79277
79278 /*
79279 ** Sort the linked list of records headed at pTask->pList. Return
79280 ** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if
79281 ** an error occurs.
@@ -78979,16 +79287,18 @@
79287 int rc;
79288
79289 rc = vdbeSortAllocUnpacked(pTask);
79290 if( rc!=SQLITE_OK ) return rc;
79291
79292 p = pList->pList;
79293 pTask->xCompare = vdbeSorterGetCompare(pTask->pSorter);
79294
79295 aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *));
79296 if( !aSlot ){
79297 return SQLITE_NOMEM;
79298 }
79299
 
79300 while( p ){
79301 SorterRecord *pNext;
79302 if( pList->aMemory ){
79303 if( (u8*)p==pList->aMemory ){
79304 pNext = 0;
@@ -79198,28 +79508,27 @@
79508 /* Update contents of aTree[] */
79509 if( rc==SQLITE_OK ){
79510 int i; /* Index of aTree[] to recalculate */
79511 PmaReader *pReadr1; /* First PmaReader to compare */
79512 PmaReader *pReadr2; /* Second PmaReader to compare */
79513 int bCached = 0;
79514
79515 /* Find the first two PmaReaders to compare. The one that was just
79516 ** advanced (iPrev) and the one next to it in the array. */
79517 pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)];
79518 pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)];
 
79519
79520 for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){
79521 /* Compare pReadr1 and pReadr2. Store the result in variable iRes. */
79522 int iRes;
79523 if( pReadr1->pFd==0 ){
79524 iRes = +1;
79525 }else if( pReadr2->pFd==0 ){
79526 iRes = -1;
79527 }else{
79528 iRes = pTask->xCompare(pTask, &bCached,
79529 pReadr1->aKey, pReadr1->nKey, pReadr2->aKey, pReadr2->nKey
79530 );
79531 }
79532
79533 /* If pReadr1 contained the smaller value, set aTree[i] to its index.
79534 ** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this
@@ -79237,13 +79546,13 @@
79546 ** is sorted from oldest to newest, so pReadr1 contains older values
79547 ** than pReadr2 iff (pReadr1<pReadr2). */
79548 if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){
79549 pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr);
79550 pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79551 bCached = 0;
79552 }else{
79553 if( pReadr1->pFd ) bCached = 0;
79554 pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr);
79555 pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
79556 }
79557 }
79558 *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0);
@@ -79346,10 +79655,20 @@
79655 SorterRecord *pNew; /* New list element */
79656
79657 int bFlush; /* True to flush contents of memory to PMA */
79658 int nReq; /* Bytes of memory required */
79659 int nPMA; /* Bytes of PMA space required */
79660 int t; /* serial type of first record field */
79661
79662 getVarint32((const u8*)&pVal->z[1], t);
79663 if( t>0 && t<10 && t!=7 ){
79664 pSorter->typeMask &= SORTER_TYPE_INTEGER;
79665 }else if( t>10 && (t & 0x01) ){
79666 pSorter->typeMask &= SORTER_TYPE_TEXT;
79667 }else{
79668 pSorter->typeMask = 0;
79669 }
79670
79671 assert( pSorter );
79672
79673 /* Figure out whether or not the current contents of memory should be
79674 ** flushed to a PMA before continuing. If so, do so.
@@ -79611,14 +79930,16 @@
79930 if( p1->pFd==0 ){
79931 iRes = i2;
79932 }else if( p2->pFd==0 ){
79933 iRes = i1;
79934 }else{
79935 SortSubtask *pTask = pMerger->pTask;
79936 int bCached = 0;
79937 int res;
79938 assert( pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */
79939 res = pTask->xCompare(
79940 pTask, &bCached, p1->aKey, p1->nKey, p2->aKey, p2->nKey
79941 );
79942 if( res<=0 ){
79943 iRes = i1;
79944 }else{
79945 iRes = i2;
@@ -79638,15 +79959,16 @@
79959 */
79960 #define INCRINIT_NORMAL 0
79961 #define INCRINIT_TASK 1
79962 #define INCRINIT_ROOT 2
79963
79964 /*
79965 ** Forward reference required as the vdbeIncrMergeInit() and
79966 ** vdbePmaReaderIncrInit() routines are called mutually recursively when
79967 ** building a merge tree.
79968 */
79969 static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode);
79970
79971 /*
79972 ** Initialize the MergeEngine object passed as the second argument. Once this
79973 ** function returns, the first key of merged data may be read from the
79974 ** MergeEngine object in the usual fashion.
@@ -79689,11 +80011,11 @@
80011 ** the main thread to fill its buffer. So calling PmaReaderNext()
80012 ** on this PmaReader before any of the multi-threaded PmaReaders takes
80013 ** better advantage of multi-processor hardware. */
80014 rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]);
80015 }else{
80016 rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i], INCRINIT_NORMAL);
80017 }
80018 if( rc!=SQLITE_OK ) return rc;
80019 }
80020
80021 for(i=pMerger->nTree-1; i>0; i--){
@@ -79701,21 +80023,19 @@
80023 }
80024 return pTask->pUnpacked->errCode;
80025 }
80026
80027 /*
80028 ** The PmaReader passed as the first argument is guaranteed to be an
80029 ** incremental-reader (pReadr->pIncr!=0). This function serves to open
80030 ** and/or initialize the temp file related fields of the IncrMerge
 
 
80031 ** object at (pReadr->pIncr).
80032 **
80033 ** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders
80034 ** in the sub-tree headed by pReadr are also initialized. Data is then
80035 ** loaded into the buffers belonging to pReadr and it is set to point to
80036 ** the first key in its range.
80037 **
80038 ** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed
80039 ** to be a multi-threaded PmaReader and this function is being called in a
80040 ** background thread. In this case all PmaReaders in the sub-tree are
80041 ** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to
@@ -79738,93 +80058,112 @@
80058 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
80059 */
80060 static int vdbePmaReaderIncrMergeInit(PmaReader *pReadr, int eMode){
80061 int rc = SQLITE_OK;
80062 IncrMerger *pIncr = pReadr->pIncr;
80063 SortSubtask *pTask = pIncr->pTask;
80064 sqlite3 *db = pTask->pSorter->db;
80065
80066 /* eMode is always INCRINIT_NORMAL in single-threaded mode */
80067 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
80068
80069 rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
80070
80071 /* Set up the required files for pIncr. A multi-theaded IncrMerge object
80072 ** requires two temp files to itself, whereas a single-threaded object
80073 ** only requires a region of pTask->file2. */
80074 if( rc==SQLITE_OK ){
80075 int mxSz = pIncr->mxSz;
80076 #if SQLITE_MAX_WORKER_THREADS>0
80077 if( pIncr->bUseThread ){
80078 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
80079 if( rc==SQLITE_OK ){
80080 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
80081 }
80082 }else
80083 #endif
80084 /*if( !pIncr->bUseThread )*/{
80085 if( pTask->file2.pFd==0 ){
80086 assert( pTask->file2.iEof>0 );
80087 rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
80088 pTask->file2.iEof = 0;
80089 }
80090 if( rc==SQLITE_OK ){
80091 pIncr->aFile[1].pFd = pTask->file2.pFd;
80092 pIncr->iStartOff = pTask->file2.iEof;
80093 pTask->file2.iEof += mxSz;
80094 }
80095 }
80096 }
80097
80098 #if SQLITE_MAX_WORKER_THREADS>0
80099 if( rc==SQLITE_OK && pIncr->bUseThread ){
80100 /* Use the current thread to populate aFile[1], even though this
80101 ** PmaReader is multi-threaded. If this is an INCRINIT_TASK object,
80102 ** then this function is already running in background thread
80103 ** pIncr->pTask->thread.
80104 **
80105 ** If this is the INCRINIT_ROOT object, then it is running in the
80106 ** main VDBE thread. But that is Ok, as that thread cannot return
80107 ** control to the VDBE or proceed with anything useful until the
80108 ** first results are ready from this merger object anyway.
80109 */
80110 assert( eMode==INCRINIT_ROOT || eMode==INCRINIT_TASK );
80111 rc = vdbeIncrPopulate(pIncr);
80112 }
80113 #endif
80114
80115 if( rc==SQLITE_OK && (SQLITE_MAX_WORKER_THREADS==0 || eMode!=INCRINIT_TASK) ){
80116 rc = vdbePmaReaderNext(pReadr);
80117 }
80118
80119 return rc;
80120 }
80121
80122 #if SQLITE_MAX_WORKER_THREADS>0
80123 /*
80124 ** The main routine for vdbePmaReaderIncrMergeInit() operations run in
80125 ** background threads.
80126 */
80127 static void *vdbePmaReaderBgIncrInit(void *pCtx){
80128 PmaReader *pReader = (PmaReader*)pCtx;
80129 void *pRet = SQLITE_INT_TO_PTR(
80130 vdbePmaReaderIncrMergeInit(pReader,INCRINIT_TASK)
80131 );
80132 pReader->pIncr->pTask->bDone = 1;
80133 return pRet;
80134 }
80135 #endif
80136
80137 /*
80138 ** If the PmaReader passed as the first argument is not an incremental-reader
80139 ** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it invokes
80140 ** the vdbePmaReaderIncrMergeInit() function with the parameters passed to
80141 ** this routine to initialize the incremental merge.
80142 **
80143 ** If the IncrMerger object is multi-threaded (IncrMerger.bUseThread==1),
80144 ** then a background thread is launched to call vdbePmaReaderIncrMergeInit().
80145 ** Or, if the IncrMerger is single threaded, the same function is called
80146 ** using the current thread.
80147 */
80148 static int vdbePmaReaderIncrInit(PmaReader *pReadr, int eMode){
80149 IncrMerger *pIncr = pReadr->pIncr; /* Incremental merger */
80150 int rc = SQLITE_OK; /* Return code */
80151 if( pIncr ){
80152 #if SQLITE_MAX_WORKER_THREADS>0
80153 assert( pIncr->bUseThread==0 || eMode==INCRINIT_TASK );
80154 if( pIncr->bUseThread ){
80155 void *pCtx = (void*)pReadr;
80156 rc = vdbeSorterCreateThread(pIncr->pTask, vdbePmaReaderBgIncrInit, pCtx);
80157 }else
80158 #endif
80159 {
80160 rc = vdbePmaReaderIncrMergeInit(pReadr, eMode);
80161 }
80162 }
80163 return rc;
80164 }
 
80165
80166 /*
80167 ** Allocate a new MergeEngine object to merge the contents of nPMA level-0
80168 ** PMAs from pTask->file. If no error occurs, set *ppOut to point to
80169 ** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut
@@ -80032,10 +80371,15 @@
80371 int rc; /* Return code */
80372 SortSubtask *pTask0 = &pSorter->aTask[0];
80373 MergeEngine *pMain = 0;
80374 #if SQLITE_MAX_WORKER_THREADS
80375 sqlite3 *db = pTask0->pSorter->db;
80376 int i;
80377 SorterCompare xCompare = vdbeSorterGetCompare(pSorter);
80378 for(i=0; i<pSorter->nTask; i++){
80379 pSorter->aTask[i].xCompare = xCompare;
80380 }
80381 #endif
80382
80383 rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
80384 if( rc==SQLITE_OK ){
80385 #if SQLITE_MAX_WORKER_THREADS
@@ -80060,19 +80404,25 @@
80404 vdbeIncrMergerSetThreads(pIncr);
80405 assert( pIncr->pTask!=pLast );
80406 }
80407 }
80408 for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
80409 /* Check that:
80410 **
80411 ** a) The incremental merge object is configured to use the
80412 ** right task, and
80413 ** b) If it is using task (nTask-1), it is configured to run
80414 ** in single-threaded mode. This is important, as the
80415 ** root merge (INCRINIT_ROOT) will be using the same task
80416 ** object.
80417 */
80418 PmaReader *p = &pMain->aReadr[iTask];
80419 assert( p->pIncr==0 || (
80420 (p->pIncr->pTask==&pSorter->aTask[iTask]) /* a */
80421 && (iTask!=pSorter->nTask-1 || p->pIncr->bUseThread==0) /* b */
80422 ));
80423 rc = vdbePmaReaderIncrInit(p, INCRINIT_TASK);
 
 
 
80424 }
80425 }
80426 pMain = 0;
80427 }
80428 if( rc==SQLITE_OK ){
@@ -81023,11 +81373,11 @@
81373 ** Should be transformed into:
81374 **
81375 ** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase;
81376 **
81377 ** The nSubquery parameter specifies how many levels of subquery the
81378 ** alias is removed from the original expression. The usual value is
81379 ** zero but it might be more if the alias is contained within a subquery
81380 ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION
81381 ** structures must be increased by the nSubquery amount.
81382 */
81383 static void resolveAlias(
@@ -81043,11 +81393,10 @@
81393 sqlite3 *db; /* The database connection */
81394
81395 assert( iCol>=0 && iCol<pEList->nExpr );
81396 pOrig = pEList->a[iCol].pExpr;
81397 assert( pOrig!=0 );
 
81398 db = pParse->db;
81399 pDup = sqlite3ExprDup(db, pOrig, 0);
81400 if( pDup==0 ) return;
81401 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
81402 incrAggFunctionDepth(pDup, nSubquery);
@@ -81937,13 +82286,15 @@
82286 pNew->flags |= EP_IntValue;
82287 pNew->u.iValue = iCol;
82288 if( pItem->pExpr==pE ){
82289 pItem->pExpr = pNew;
82290 }else{
82291 Expr *pParent = pItem->pExpr;
82292 assert( pParent->op==TK_COLLATE );
82293 while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
82294 assert( pParent->pLeft==pE );
82295 pParent->pLeft = pNew;
82296 }
82297 sqlite3ExprDelete(db, pE);
82298 pItem->u.x.iOrderByCol = (u16)iCol;
82299 pItem->done = 1;
82300 }else{
@@ -82139,11 +82490,11 @@
82490 ** as if it were part of the sub-query, not the parent. This block
82491 ** moves the pOrderBy down to the sub-query. It will be moved back
82492 ** after the names have been resolved. */
82493 if( p->selFlags & SF_Converted ){
82494 Select *pSub = p->pSrc->a[0].pSelect;
82495 assert( p->pSrc->nSrc==1 && p->pOrderBy );
82496 assert( pSub->pPrior && pSub->pOrderBy==0 );
82497 pSub->pOrderBy = p->pOrderBy;
82498 p->pOrderBy = 0;
82499 }
82500
@@ -82241,12 +82592,19 @@
82592
82593 /* Process the ORDER BY clause for singleton SELECT statements.
82594 ** The ORDER BY clause for compounds SELECT statements is handled
82595 ** below, after all of the result-sets for all of the elements of
82596 ** the compound have been resolved.
82597 **
82598 ** If there is an ORDER BY clause on a term of a compound-select other
82599 ** than the right-most term, then that is a syntax error. But the error
82600 ** is not detected until much later, and so we need to go ahead and
82601 ** resolve those symbols on the incorrect ORDER BY for consistency.
82602 */
82603 if( isCompound<=nCompound /* Defer right-most ORDER BY of a compound */
82604 && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER")
82605 ){
82606 return WRC_Abort;
82607 }
82608 if( db->mallocFailed ){
82609 return WRC_Abort;
82610 }
@@ -83694,11 +84052,12 @@
84052 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList *pList){
84053 int i;
84054 u32 m = 0;
84055 if( pList ){
84056 for(i=0; i<pList->nExpr; i++){
84057 Expr *pExpr = pList->a[i].pExpr;
84058 if( ALWAYS(pExpr) ) m |= pExpr->flags;
84059 }
84060 }
84061 return m;
84062 }
84063
@@ -84134,11 +84493,11 @@
84493 /* Check to see if an existing table or index can be used to
84494 ** satisfy the query. This is preferable to generating a new
84495 ** ephemeral table.
84496 */
84497 p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
84498 if( pParse->nErr==0 && isCandidateForInOpt(p) ){
84499 sqlite3 *db = pParse->db; /* Database connection */
84500 Table *pTab; /* Table <table>. */
84501 Expr *pExpr; /* Expression <column> */
84502 i16 iCol; /* Index of column <column> */
84503 i16 iDb; /* Database idx for pTab */
@@ -84459,10 +84818,11 @@
84818 }
84819 sqlite3ExprDelete(pParse->db, pSel->pLimit);
84820 pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0,
84821 &sqlite3IntTokens[1]);
84822 pSel->iLimit = 0;
84823 pSel->selFlags &= ~SF_MultiValue;
84824 if( sqlite3Select(pParse, pSel, &dest) ){
84825 return 0;
84826 }
84827 rReg = dest.iSDParm;
84828 ExprSetVVAProperty(pExpr, EP_NoReduce);
@@ -85824,11 +86184,11 @@
86184 sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
86185 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
86186 break;
86187 }
86188 case TK_ID: {
86189 sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
86190 break;
86191 }
86192 #ifndef SQLITE_OMIT_CAST
86193 case TK_CAST: {
86194 /* Expressions of the form: CAST(pLeft AS token) */
@@ -86459,11 +86819,11 @@
86819 if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
86820 if( combinedFlags & EP_xIsSelect ) return 2;
86821 if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
86822 if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
86823 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
86824 if( ALWAYS((combinedFlags & EP_Reduced)==0) && pA->op!=TK_STRING ){
86825 if( pA->iColumn!=pB->iColumn ) return 2;
86826 if( pA->iTable!=pB->iTable
86827 && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
86828 }
86829 }
@@ -86991,10 +87351,11 @@
87351 do {
87352 z += n;
87353 n = sqlite3GetToken(z, &token);
87354 }while( token==TK_SPACE );
87355
87356 if( token==TK_ILLEGAL ) break;
87357 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
87358 if( zParent==0 ) break;
87359 sqlite3Dequote(zParent);
87360 if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
87361 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
@@ -89217,18 +89578,21 @@
89578 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
89579 }
89580 z = argv[2];
89581
89582 if( pIndex ){
89583 tRowcnt *aiRowEst = 0;
89584 int nCol = pIndex->nKeyCol+1;
89585 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
89586 /* Index.aiRowEst may already be set here if there are duplicate
89587 ** sqlite_stat1 entries for this index. In that case just clobber
89588 ** the old data with the new instead of allocating a new array. */
89589 if( pIndex->aiRowEst==0 ){
89590 pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(sizeof(tRowcnt) * nCol);
89591 if( pIndex->aiRowEst==0 ) pInfo->db->mallocFailed = 1;
89592 }
89593 aiRowEst = pIndex->aiRowEst;
89594 #endif
89595 pIndex->bUnordered = 0;
89596 decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
89597 if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
89598 }else{
@@ -89887,11 +90251,11 @@
90251 }
90252
90253 sqlite3BtreeClose(pDb->pBt);
90254 pDb->pBt = 0;
90255 pDb->pSchema = 0;
90256 sqlite3CollapseDatabaseArray(db);
90257 return;
90258
90259 detach_error:
90260 sqlite3_result_error(context, zErr, -1);
90261 }
@@ -89921,11 +90285,10 @@
90285 if(
90286 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
90287 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
90288 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
90289 ){
 
90290 goto attach_end;
90291 }
90292
90293 #ifndef SQLITE_OMIT_AUTHORIZATION
90294 if( pAuthArg ){
@@ -90580,13 +90943,15 @@
90943 sqlite3 *db;
90944 Vdbe *v;
90945
90946 assert( pParse->pToplevel==0 );
90947 db = pParse->db;
 
90948 if( pParse->nested ) return;
90949 if( db->mallocFailed || pParse->nErr ){
90950 if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR;
90951 return;
90952 }
90953
90954 /* Begin by generating some termination code at the end of the
90955 ** vdbe program
90956 */
90957 v = sqlite3GetVdbe(pParse);
@@ -90664,11 +91029,11 @@
91029 }
91030
91031
91032 /* Get the VDBE program ready for execution
91033 */
91034 if( v && pParse->nErr==0 && !db->mallocFailed ){
91035 assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
91036 /* A minimum of one cursor is required if autoincrement is used
91037 * See ticket [a696379c1f08866] */
91038 if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
91039 sqlite3VdbeMakeReady(v, pParse);
@@ -91199,18 +91564,16 @@
91564 sqlite3 *db = pParse->db;
91565
91566 if( ALWAYS(pName2!=0) && pName2->n>0 ){
91567 if( db->init.busy ) {
91568 sqlite3ErrorMsg(pParse, "corrupt database");
 
91569 return -1;
91570 }
91571 *pUnqual = pName2;
91572 iDb = sqlite3FindDb(db, pName1);
91573 if( iDb<0 ){
91574 sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
 
91575 return -1;
91576 }
91577 }else{
91578 assert( db->init.iDb==0 || db->init.busy );
91579 iDb = db->init.iDb;
@@ -91365,11 +91728,11 @@
91728 pTable = sqlite3FindTable(db, zName, zDb);
91729 if( pTable ){
91730 if( !noErr ){
91731 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
91732 }else{
91733 assert( !db->init.busy || CORRUPT_DB );
91734 sqlite3CodeVerifySchema(pParse, iDb);
91735 }
91736 goto begin_table_error;
91737 }
91738 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
@@ -91654,11 +92017,12 @@
92017 Column *pCol;
92018
92019 p = pParse->pNewTable;
92020 if( p==0 || NEVER(p->nCol<1) ) return;
92021 pCol = &p->aCol[p->nCol-1];
92022 assert( pCol->zType==0 || CORRUPT_DB );
92023 sqlite3DbFree(pParse->db, pCol->zType);
92024 pCol->zType = sqlite3NameFromToken(pParse->db, pType);
92025 pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst);
92026 }
92027
92028 /*
@@ -92888,10 +93252,11 @@
93252 if( db->mallocFailed ){
93253 goto exit_drop_table;
93254 }
93255 assert( pParse->nErr==0 );
93256 assert( pName->nSrc==1 );
93257 if( sqlite3ReadSchema(pParse) ) goto exit_drop_table;
93258 if( noErr ) db->suppressErr++;
93259 pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
93260 if( noErr ) db->suppressErr--;
93261
93262 if( pTab==0 ){
@@ -93201,11 +93566,12 @@
93566 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
93567 }else{
93568 addr2 = sqlite3VdbeCurrentAddr(v);
93569 }
93570 sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
93571 sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1);
93572 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0);
93573 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
93574 sqlite3ReleaseTempReg(pParse, regRecord);
93575 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
93576 sqlite3VdbeJumpHere(v, addr1);
93577
@@ -93294,12 +93660,11 @@
93660 int nExtra = 0; /* Space allocated for zExtra[] */
93661 int nExtraCol; /* Number of extra columns needed */
93662 char *zExtra = 0; /* Extra space after the Index object */
93663 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
93664
93665 if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){
 
93666 goto exit_create_index;
93667 }
93668 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
93669 goto exit_create_index;
93670 }
@@ -94214,11 +94579,10 @@
94579 ** operator with A. This routine shifts that operator over to B.
94580 */
94581 SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){
94582 if( p ){
94583 int i;
 
94584 for(i=p->nSrc-1; i>0; i--){
94585 p->a[i].jointype = p->a[i-1].jointype;
94586 }
94587 p->a[0].jointype = 0;
94588 }
@@ -94461,12 +94825,11 @@
94825 char *zErr;
94826 int j;
94827 StrAccum errMsg;
94828 Table *pTab = pIdx->pTable;
94829
94830 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
 
94831 for(j=0; j<pIdx->nKeyCol; j++){
94832 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
94833 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
94834 sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
94835 sqlite3StrAccumAppend(&errMsg, ".", 1);
@@ -96291,17 +96654,17 @@
96654 ){
96655 PrintfArguments x;
96656 StrAccum str;
96657 const char *zFormat;
96658 int n;
96659 sqlite3 *db = sqlite3_context_db_handle(context);
96660
96661 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
96662 x.nArg = argc-1;
96663 x.nUsed = 0;
96664 x.apArg = argv+1;
96665 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
 
96666 sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x);
96667 n = str.nChar;
96668 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
96669 SQLITE_DYNAMIC);
96670 }
@@ -96447,11 +96810,11 @@
96810 sqlite3_result_double(context, r);
96811 }
96812 #endif
96813
96814 /*
96815 ** Allocate nByte bytes of space using sqlite3Malloc(). If the
96816 ** allocation fails, call sqlite3_result_error_nomem() to notify
96817 ** the database handle that malloc() has failed and return NULL.
96818 ** If nByte is larger than the maximum string or blob length, then
96819 ** raise an SQLITE_TOOBIG exception and return NULL.
96820 */
@@ -97116,11 +97479,11 @@
97479 int argc,
97480 sqlite3_value **argv
97481 ){
97482 unsigned char *z, *zOut;
97483 int i;
97484 zOut = z = sqlite3_malloc64( argc*4+1 );
97485 if( z==0 ){
97486 sqlite3_result_error_nomem(context);
97487 return;
97488 }
97489 for(i=0; i<argc; i++){
@@ -97264,11 +97627,11 @@
97627 sqlite3_result_error_toobig(context);
97628 sqlite3_free(zOut);
97629 return;
97630 }
97631 zOld = zOut;
97632 zOut = sqlite3_realloc64(zOut, (int)nOut);
97633 if( zOut==0 ){
97634 sqlite3_result_error_nomem(context);
97635 sqlite3_free(zOld);
97636 return;
97637 }
@@ -97626,12 +97989,11 @@
97989 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
97990 pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
97991
97992 if( pAccum ){
97993 sqlite3 *db = sqlite3_context_db_handle(context);
97994 int firstTerm = pAccum->mxAlloc==0;
 
97995 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
97996 if( !firstTerm ){
97997 if( argc==2 ){
97998 zSep = (char*)sqlite3_value_text(argv[1]);
97999 nSep = sqlite3_value_bytes(argv[1]);
@@ -99047,11 +99409,12 @@
99409 int iFromCol; /* Idx of column in child table */
99410 Expr *pEq; /* tFromCol = OLD.tToCol */
99411
99412 iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
99413 assert( iFromCol>=0 );
99414 assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
99415 tToCol.z = pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName;
99416 tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName;
99417
99418 tToCol.n = sqlite3Strlen30(tToCol.z);
99419 tFromCol.n = sqlite3Strlen30(tFromCol.z);
99420
@@ -99059,14 +99422,14 @@
99422 ** that the "OLD.zToCol" term is on the LHS of the = operator, so
99423 ** that the affinity and collation sequence associated with the
99424 ** parent table are used for the comparison. */
99425 pEq = sqlite3PExpr(pParse, TK_EQ,
99426 sqlite3PExpr(pParse, TK_DOT,
99427 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
99428 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
99429 , 0),
99430 sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
99431 , 0);
99432 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
99433
99434 /* For ON UPDATE, construct the next term of the WHEN clause.
99435 ** The final WHEN clause will be like this:
@@ -99074,27 +99437,27 @@
99437 ** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN)
99438 */
99439 if( pChanges ){
99440 pEq = sqlite3PExpr(pParse, TK_IS,
99441 sqlite3PExpr(pParse, TK_DOT,
99442 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
99443 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
99444 0),
99445 sqlite3PExpr(pParse, TK_DOT,
99446 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
99447 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
99448 0),
99449 0);
99450 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
99451 }
99452
99453 if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
99454 Expr *pNew;
99455 if( action==OE_Cascade ){
99456 pNew = sqlite3PExpr(pParse, TK_DOT,
99457 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
99458 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
99459 , 0);
99460 }else if( action==OE_SetDflt ){
99461 Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
99462 if( pDflt ){
99463 pNew = sqlite3ExprDup(db, pDflt, 0);
@@ -99137,17 +99500,16 @@
99500 db->lookaside.bEnabled = 0;
99501
99502 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
99503 sizeof(Trigger) + /* struct Trigger */
99504 sizeof(TriggerStep) + /* Single step in trigger program */
99505 nFrom + 1 /* Space for pStep->zTarget */
99506 );
99507 if( pTrigger ){
99508 pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1];
99509 pStep->zTarget = (char *)&pStep[1];
99510 memcpy((char *)pStep->zTarget, zFrom, nFrom);
 
99511
99512 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
99513 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
99514 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
99515 if( pWhen ){
@@ -99608,24 +99970,27 @@
99970 );
99971
99972 /*
99973 ** This routine is called to handle SQL of the following forms:
99974 **
99975 ** insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),...
99976 ** insert into TABLE (IDLIST) select
99977 ** insert into TABLE (IDLIST) default values
99978 **
99979 ** The IDLIST following the table name is always optional. If omitted,
99980 ** then a list of all (non-hidden) columns for the table is substituted.
99981 ** The IDLIST appears in the pColumn parameter. pColumn is NULL if IDLIST
99982 ** is omitted.
99983 **
99984 ** For the pSelect parameter holds the values to be inserted for the
99985 ** first two forms shown above. A VALUES clause is really just short-hand
99986 ** for a SELECT statement that omits the FROM clause and everything else
99987 ** that follows. If the pSelect parameter is NULL, that means that the
99988 ** DEFAULT VALUES form of the INSERT statement is intended.
99989 **
99990 ** The code generated follows one of four templates. For a simple
99991 ** insert with data coming from a single-row VALUES clause, the code executes
99992 ** once straight down through. Pseudo-code follows (we call this
99993 ** the "1st template"):
99994 **
99995 ** open write cursor to <table> and its indices
99996 ** put VALUES clause expressions into registers
@@ -99728,11 +100093,11 @@
100093 int iDb; /* Index of database holding TABLE */
100094 Db *pDb; /* The database containing table being inserted into */
100095 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
100096 u8 appendFlag = 0; /* True if the insert is likely to be an append */
100097 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
100098 u8 bIdListInOrder; /* True if IDLIST is in table order */
100099 ExprList *pList = 0; /* List of VALUES() to be inserted */
100100
100101 /* Register allocations */
100102 int regFromSelect = 0;/* Base register for data coming from SELECT */
100103 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
@@ -99753,12 +100118,12 @@
100118 if( pParse->nErr || db->mallocFailed ){
100119 goto insert_cleanup;
100120 }
100121
100122 /* If the Select object is really just a simple VALUES() list with a
100123 ** single row (the common case) then keep that one row of values
100124 ** and discard the other (unused) parts of the pSelect object
100125 */
100126 if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){
100127 pList = pSelect->pEList;
100128 pSelect->pEList = 0;
100129 sqlite3SelectDelete(db, pSelect);
@@ -99862,10 +100227,11 @@
100227 ** the index into IDLIST of the primary key column. ipkColumn is
100228 ** the index of the primary key as it appears in IDLIST, not as
100229 ** is appears in the original table. (The index of the INTEGER
100230 ** PRIMARY KEY in the original table is pTab->iPKey.)
100231 */
100232 bIdListInOrder = (pTab->tabFlags & TF_OOOHidden)==0;
100233 if( pColumn ){
100234 for(i=0; i<pColumn->nId; i++){
100235 pColumn->a[i].idx = -1;
100236 }
100237 for(i=0; i<pColumn->nId; i++){
@@ -99897,11 +100263,12 @@
100263 ** is coming from a SELECT statement, then generate a co-routine that
100264 ** produces a single row of the SELECT on each invocation. The
100265 ** co-routine is the common header to the 3rd and 4th templates.
100266 */
100267 if( pSelect ){
100268 /* Data is coming from a SELECT or from a multi-row VALUES clause.
100269 ** Generate a co-routine to run the SELECT. */
100270 int regYield; /* Register holding co-routine entry-point */
100271 int addrTop; /* Top of the co-routine */
100272 int rc; /* Result code */
100273
100274 regYield = ++pParse->nMem;
@@ -99910,12 +100277,11 @@
100277 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
100278 dest.iSdst = bIdListInOrder ? regData : 0;
100279 dest.nSdst = pTab->nCol;
100280 rc = sqlite3Select(pParse, pSelect, &dest);
100281 regFromSelect = dest.iSdst;
100282 if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
 
100283 sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
100284 sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
100285 assert( pSelect->pEList );
100286 nColumn = pSelect->pEList->nExpr;
100287
@@ -99959,12 +100325,12 @@
100325 sqlite3VdbeJumpHere(v, addrL);
100326 sqlite3ReleaseTempReg(pParse, regRec);
100327 sqlite3ReleaseTempReg(pParse, regTempRowid);
100328 }
100329 }else{
100330 /* This is the case if the data for the INSERT is coming from a
100331 ** single-row VALUES clause
100332 */
100333 NameContext sNC;
100334 memset(&sNC, 0, sizeof(sNC));
100335 sNC.pParse = pParse;
100336 srcTab = -1;
@@ -101031,10 +101397,11 @@
101397 Table *pDest, /* The table we are inserting into */
101398 Select *pSelect, /* A SELECT statement to use as the data source */
101399 int onError, /* How to handle constraint errors */
101400 int iDbDest /* The database of pDest */
101401 ){
101402 sqlite3 *db = pParse->db;
101403 ExprList *pEList; /* The result set of the SELECT */
101404 Table *pSrc; /* The table in the FROM clause of SELECT */
101405 Index *pSrcIdx, *pDestIdx; /* Source and destination indices */
101406 struct SrcList_item *pItem; /* An element of pSelect->pSrc */
101407 int i; /* Loop counter */
@@ -101178,15 +101545,15 @@
101545 ** But the main beneficiary of the transfer optimization is the VACUUM
101546 ** command, and the VACUUM command disables foreign key constraints. So
101547 ** the extra complication to make this rule less restrictive is probably
101548 ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
101549 */
101550 if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
101551 return 0;
101552 }
101553 #endif
101554 if( (db->flags & SQLITE_CountRows)!=0 ){
101555 return 0; /* xfer opt does not play well with PRAGMA count_changes */
101556 }
101557
101558 /* If we get this far, it means that the xfer optimization is at
101559 ** least a possibility, though it might only work if the destination
@@ -101193,28 +101560,32 @@
101560 ** table (tab1) is initially empty.
101561 */
101562 #ifdef SQLITE_TEST
101563 sqlite3_xferopt_count++;
101564 #endif
101565 iDbSrc = sqlite3SchemaToIndex(db, pSrc->pSchema);
101566 v = sqlite3GetVdbe(pParse);
101567 sqlite3CodeVerifySchema(pParse, iDbSrc);
101568 iSrc = pParse->nTab++;
101569 iDest = pParse->nTab++;
101570 regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
101571 regData = sqlite3GetTempReg(pParse);
101572 regRowid = sqlite3GetTempReg(pParse);
101573 sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
101574 assert( HasRowid(pDest) || destHasUniqueIdx );
101575 if( (db->flags & SQLITE_Vacuum)==0 && (
101576 (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
101577 || destHasUniqueIdx /* (2) */
101578 || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
101579 )){
101580 /* In some circumstances, we are able to run the xfer optimization
101581 ** only if the destination table is initially empty. Unless the
101582 ** SQLITE_Vacuum flag is set, this block generates code to make
101583 ** that determination. If SQLITE_Vacuum is set, then the destination
101584 ** table is always empty.
101585 **
101586 ** Conditions under which the destination must be empty:
101587 **
101588 ** (1) There is no INTEGER PRIMARY KEY but there are indices.
101589 ** (If the destination is not initially empty, the rowid fields
101590 ** of index entries might need to change.)
101591 **
@@ -101253,10 +101624,11 @@
101624 }else{
101625 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
101626 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
101627 }
101628 for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
101629 u8 useSeekResult = 0;
101630 for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){
101631 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
101632 }
101633 assert( pSrcIdx );
101634 sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
@@ -101266,11 +101638,37 @@
101638 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
101639 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
101640 VdbeComment((v, "%s", pDestIdx->zName));
101641 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
101642 sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
101643 if( db->flags & SQLITE_Vacuum ){
101644 /* This INSERT command is part of a VACUUM operation, which guarantees
101645 ** that the destination table is empty. If all indexed columns use
101646 ** collation sequence BINARY, then it can also be assumed that the
101647 ** index will be populated by inserting keys in strictly sorted
101648 ** order. In this case, instead of seeking within the b-tree as part
101649 ** of every OP_IdxInsert opcode, an OP_Last is added before the
101650 ** OP_IdxInsert to seek to the point within the b-tree where each key
101651 ** should be inserted. This is faster.
101652 **
101653 ** If any of the indexed columns use a collation sequence other than
101654 ** BINARY, this optimization is disabled. This is because the user
101655 ** might change the definition of a collation sequence and then run
101656 ** a VACUUM command. In that case keys may not be written in strictly
101657 ** sorted order. */
101658 for(i=0; i<pSrcIdx->nColumn; i++){
101659 char *zColl = pSrcIdx->azColl[i];
101660 assert( zColl!=0 );
101661 if( sqlite3_stricmp("BINARY", zColl) ) break;
101662 }
101663 if( i==pSrcIdx->nColumn ){
101664 useSeekResult = OPFLAG_USESEEKRESULT;
101665 sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
101666 }
101667 }
101668 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
101669 sqlite3VdbeChangeP5(v, useSeekResult);
101670 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
101671 sqlite3VdbeJumpHere(v, addr1);
101672 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
101673 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
101674 }
@@ -102385,11 +102783,11 @@
102783 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
102784 char *zErrmsg = 0;
102785 const char *zEntry;
102786 char *zAltEntry = 0;
102787 void **aHandle;
102788 u64 nMsg = 300 + sqlite3Strlen30(zFile);
102789 int ii;
102790
102791 /* Shared library endings to try if zFile cannot be loaded as written */
102792 static const char *azEndings[] = {
102793 #if SQLITE_OS_WIN
@@ -102428,11 +102826,11 @@
102826 sqlite3_free(zAltFile);
102827 }
102828 #endif
102829 if( handle==0 ){
102830 if( pzErrMsg ){
102831 *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
102832 if( zErrmsg ){
102833 sqlite3_snprintf(nMsg, zErrmsg,
102834 "unable to open shared library [%s]", zFile);
102835 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102836 }
@@ -102454,11 +102852,11 @@
102852 ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
102853 */
102854 if( xInit==0 && zProc==0 ){
102855 int iFile, iEntry, c;
102856 int ncFile = sqlite3Strlen30(zFile);
102857 zAltEntry = sqlite3_malloc64(ncFile+30);
102858 if( zAltEntry==0 ){
102859 sqlite3OsDlClose(pVfs, handle);
102860 return SQLITE_NOMEM;
102861 }
102862 memcpy(zAltEntry, "sqlite3_", 8);
@@ -102476,11 +102874,11 @@
102874 sqlite3OsDlSym(pVfs, handle, zEntry);
102875 }
102876 if( xInit==0 ){
102877 if( pzErrMsg ){
102878 nMsg += sqlite3Strlen30(zEntry);
102879 *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
102880 if( zErrmsg ){
102881 sqlite3_snprintf(nMsg, zErrmsg,
102882 "no entry point [%s] in shared library [%s]", zEntry, zFile);
102883 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
102884 }
@@ -102575,11 +102973,11 @@
102973 ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER
102974 ** mutex must be held while accessing this list.
102975 */
102976 typedef struct sqlite3AutoExtList sqlite3AutoExtList;
102977 static SQLITE_WSD struct sqlite3AutoExtList {
102978 u32 nExt; /* Number of entries in aExt[] */
102979 void (**aExt)(void); /* Pointers to the extension init functions */
102980 } sqlite3Autoext = { 0, 0 };
102981
102982 /* The "wsdAutoext" macro will resolve to the autoextension
102983 ** state vector. If writable static data is unsupported on the target,
@@ -102608,23 +103006,23 @@
103006 if( rc ){
103007 return rc;
103008 }else
103009 #endif
103010 {
103011 u32 i;
103012 #if SQLITE_THREADSAFE
103013 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
103014 #endif
103015 wsdAutoextInit;
103016 sqlite3_mutex_enter(mutex);
103017 for(i=0; i<wsdAutoext.nExt; i++){
103018 if( wsdAutoext.aExt[i]==xInit ) break;
103019 }
103020 if( i==wsdAutoext.nExt ){
103021 u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
103022 void (**aNew)(void);
103023 aNew = sqlite3_realloc64(wsdAutoext.aExt, nByte);
103024 if( aNew==0 ){
103025 rc = SQLITE_NOMEM;
103026 }else{
103027 wsdAutoext.aExt = aNew;
103028 wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
@@ -102652,11 +103050,11 @@
103050 #endif
103051 int i;
103052 int n = 0;
103053 wsdAutoextInit;
103054 sqlite3_mutex_enter(mutex);
103055 for(i=(int)wsdAutoext.nExt-1; i>=0; i--){
103056 if( wsdAutoext.aExt[i]==xInit ){
103057 wsdAutoext.nExt--;
103058 wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
103059 n++;
103060 break;
@@ -102690,11 +103088,11 @@
103088 ** Load all automatic extensions.
103089 **
103090 ** If anything goes wrong, set an error in the database connection.
103091 */
103092 SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
103093 u32 i;
103094 int go = 1;
103095 int rc;
103096 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
103097
103098 wsdAutoextInit;
@@ -103354,19 +103752,19 @@
103752 /*
103753 ** Generate code to return a single integer value.
103754 */
103755 static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
103756 Vdbe *v = sqlite3GetVdbe(pParse);
103757 int nMem = ++pParse->nMem;
103758 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
103759 if( pI64 ){
103760 memcpy(pI64, &value, sizeof(value));
103761 }
103762 sqlite3VdbeAddOp4(v, OP_Int64, 0, nMem, 0, (char*)pI64, P4_INT64);
103763 sqlite3VdbeSetNumCols(v, 1);
103764 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
103765 sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
103766 }
103767
103768
103769 /*
103770 ** Set the safety_level and pager flags for pager iDb. Or if iDb<0
@@ -103527,15 +103925,15 @@
103925 aFcntl[3] = 0;
103926 db->busyHandler.nBusy = 0;
103927 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
103928 if( rc==SQLITE_OK ){
103929 if( aFcntl[0] ){
103930 int nMem = ++pParse->nMem;
103931 sqlite3VdbeAddOp4(v, OP_String8, 0, nMem, 0, aFcntl[0], 0);
103932 sqlite3VdbeSetNumCols(v, 1);
103933 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
103934 sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
103935 sqlite3_free(aFcntl[0]);
103936 }
103937 goto pragma_out;
103938 }
103939 if( rc!=SQLITE_NOTFOUND ){
@@ -104136,11 +104534,13 @@
104534 }else{
104535 if( !db->autoCommit ){
104536 sqlite3ErrorMsg(pParse,
104537 "Safety level may not be changed inside a transaction");
104538 }else{
104539 int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
104540 if( iLevel==0 ) iLevel = 1;
104541 pDb->safety_level = iLevel;
104542 setAllPagerFlags(db);
104543 }
104544 }
104545 break;
104546 }
@@ -104231,11 +104631,11 @@
104631 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
104632 k = 0;
104633 }else if( pPk==0 ){
104634 k = 1;
104635 }else{
104636 for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
104637 }
104638 sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
104639 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
104640 }
104641 }
@@ -105237,11 +105637,11 @@
105637
105638 assert( iDb>=0 && iDb<db->nDb );
105639 if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
105640 if( argv[1]==0 ){
105641 corruptSchema(pData, argv[0], 0);
105642 }else if( sqlite3_strnicmp(argv[2],"create ",7)==0 ){
105643 /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
105644 ** But because db->init.busy is set to 1, no VDBE code is generated
105645 ** or executed. All the parser does is build the internal data
105646 ** structures that describe the table, index, or view.
105647 */
@@ -105268,12 +105668,12 @@
105668 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
105669 }
105670 }
105671 }
105672 sqlite3_finalize(pStmt);
105673 }else if( argv[0]==0 || (argv[2]!=0 && argv[2][0]!=0) ){
105674 corruptSchema(pData, argv[0], 0);
105675 }else{
105676 /* If the SQL column is blank it means this is an index that
105677 ** was created to be the PRIMARY KEY or to fulfill a UNIQUE
105678 ** constraint for a CREATE TABLE. The index should have already
105679 ** been created when we processed the CREATE TABLE. All we have
@@ -106176,11 +106576,10 @@
106576 ){
106577 Select *pNew;
106578 Select standin;
106579 sqlite3 *db = pParse->db;
106580 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
 
106581 if( pNew==0 ){
106582 assert( db->mallocFailed );
106583 pNew = &standin;
106584 memset(pNew, 0, sizeof(*pNew));
106585 }
@@ -106196,11 +106595,11 @@
106595 pNew->pOrderBy = pOrderBy;
106596 pNew->selFlags = selFlags;
106597 pNew->op = TK_SELECT;
106598 pNew->pLimit = pLimit;
106599 pNew->pOffset = pOffset;
106600 assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 );
106601 pNew->addrOpenEphm[0] = -1;
106602 pNew->addrOpenEphm[1] = -1;
106603 if( db->mallocFailed ) {
106604 clearSelect(db, pNew, pNew!=&standin);
106605 pNew = 0;
@@ -107446,11 +107845,11 @@
107845 if( pS ){
107846 /* The "table" is actually a sub-select or a view in the FROM clause
107847 ** of the SELECT statement. Return the declaration type and origin
107848 ** data for the result-set column of the sub-select.
107849 */
107850 if( iCol>=0 && iCol<pS->pEList->nExpr ){
107851 /* If iCol is less than zero, then the expression requests the
107852 ** rowid of the sub-select or view. This expression is legal (see
107853 ** test case misc2.2.2) - it always evaluates to NULL.
107854 */
107855 NameContext sNC;
@@ -107766,16 +108165,18 @@
108165 memset(&sNC, 0, sizeof(sNC));
108166 sNC.pSrcList = pSelect->pSrc;
108167 a = pSelect->pEList->a;
108168 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
108169 p = a[i].pExpr;
108170 if( pCol->zType==0 ){
108171 pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst));
108172 }
108173 szAll += pCol->szEst;
108174 pCol->affinity = sqlite3ExprAffinity(p);
108175 if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE;
108176 pColl = sqlite3ExprCollSeq(pParse, p);
108177 if( pColl && pCol->zColl==0 ){
108178 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
108179 }
108180 }
108181 pTab->szTabRow = sqlite3LogEst(szAll*4);
108182 }
@@ -108173,12 +108574,11 @@
108574 ){
108575 Select *pPrior;
108576 int nExpr = p->pEList->nExpr;
108577 int nRow = 1;
108578 int rc = 0;
108579 assert( p->selFlags & SF_MultiValue );
 
108580 do{
108581 assert( p->selFlags & SF_Values );
108582 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
108583 assert( p->pLimit==0 );
108584 assert( p->pOffset==0 );
@@ -108283,11 +108683,11 @@
108683 dest.eDest = SRT_Table;
108684 }
108685
108686 /* Special handling for a compound-select that originates as a VALUES clause.
108687 */
108688 if( p->selFlags & SF_MultiValue ){
108689 rc = multiSelectValues(pParse, p, &dest);
108690 goto multi_select_end;
108691 }
108692
108693 /* Make sure all SELECTs in the statement have the same number of elements
@@ -108668,11 +109068,11 @@
109068 ** then there should be a single item on the stack. Write this
109069 ** item into the set table with bogus data.
109070 */
109071 case SRT_Set: {
109072 int r1;
109073 assert( pIn->nSdst==1 || pParse->nErr>0 );
109074 pDest->affSdst =
109075 sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affSdst);
109076 r1 = sqlite3GetTempReg(pParse);
109077 sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, 1, r1, &pDest->affSdst,1);
109078 sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, 1);
@@ -108694,11 +109094,11 @@
109094 /* If this is a scalar select that is part of an expression, then
109095 ** store the results in the appropriate memory cell and break out
109096 ** of the scan loop.
109097 */
109098 case SRT_Mem: {
109099 assert( pIn->nSdst==1 || pParse->nErr>0 ); testcase( pIn->nSdst!=1 );
109100 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1);
109101 /* The LIMIT clause will jump out of the loop for us */
109102 break;
109103 }
109104 #endif /* #ifndef SQLITE_OMIT_SUBQUERY */
@@ -108709,11 +109109,11 @@
109109 case SRT_Coroutine: {
109110 if( pDest->iSdst==0 ){
109111 pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst);
109112 pDest->nSdst = pIn->nSdst;
109113 }
109114 sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst);
109115 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
109116 break;
109117 }
109118
109119 /* If none of the above, then the result destination must be
@@ -108925,12 +109325,14 @@
109325 */
109326 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
109327 if( aPermute ){
109328 struct ExprList_item *pItem;
109329 for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
109330 assert( pItem->u.x.iOrderByCol>0 );
109331 /* assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr ) is also true
109332 ** but only for well-formed SELECT statements. */
109333 testcase( pItem->u.x.iOrderByCol > p->pEList->nExpr );
109334 aPermute[i] = pItem->u.x.iOrderByCol - 1;
109335 }
109336 pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1);
109337 }else{
109338 pKeyMerge = 0;
@@ -109136,11 +109538,11 @@
109538 pPrior->pNext = p;
109539
109540 /*** TBD: Insert subroutine calls to close cursors on incomplete
109541 **** subqueries ****/
109542 explainComposite(pParse, p->op, iSub1, iSub2, 0);
109543 return pParse->nErr!=0;
109544 }
109545 #endif
109546
109547 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
109548 /* Forward Declarations */
@@ -109948,10 +110350,11 @@
110350 pNew->pGroupBy = 0;
110351 pNew->pHaving = 0;
110352 pNew->pOrderBy = 0;
110353 p->pPrior = 0;
110354 p->pNext = 0;
110355 p->pWith = 0;
110356 p->selFlags &= ~SF_Compound;
110357 assert( (p->selFlags & SF_Converted)==0 );
110358 p->selFlags |= SF_Converted;
110359 assert( pNew->pPrior!=0 );
110360 pNew->pPrior->pNext = pNew;
@@ -110486,11 +110889,11 @@
110889 if( pParse->hasCompound ){
110890 w.xSelectCallback = convertCompoundSelectToSubquery;
110891 sqlite3WalkSelect(&w, pSelect);
110892 }
110893 w.xSelectCallback = selectExpander;
110894 if( (pSelect->selFlags & SF_MultiValue)==0 ){
110895 w.xSelectCallback2 = selectPopWith;
110896 }
110897 sqlite3WalkSelect(&w, pSelect);
110898 }
110899
@@ -110672,11 +111075,12 @@
111075 nArg = 0;
111076 regAgg = 0;
111077 }
111078 if( pF->iDistinct>=0 ){
111079 addrNext = sqlite3VdbeMakeLabel(v);
111080 testcase( nArg==0 ); /* Error condition */
111081 testcase( nArg>1 ); /* Also an error */
111082 codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
111083 }
111084 if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
111085 CollSeq *pColl = 0;
111086 struct ExprList_item *pItem;
@@ -111547,14 +111951,13 @@
111951
111952 /* Jump here to skip this query
111953 */
111954 sqlite3VdbeResolveLabel(v, iEnd);
111955
111956 /* The SELECT has been coded. If there is an error in the Parse structure,
111957 ** set the return code to 1. Otherwise 0. */
111958 rc = (pParse->nErr>0);
 
111959
111960 /* Control jumps to here if an error is encountered above, or upon
111961 ** successful coding of the SELECT.
111962 */
111963 select_end:
@@ -111601,11 +112004,11 @@
112004 sqlite3TreeViewLine(pView, "FROM");
112005 for(i=0; i<p->pSrc->nSrc; i++){
112006 struct SrcList_item *pItem = &p->pSrc->a[i];
112007 StrAccum x;
112008 char zLine[100];
112009 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
112010 sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
112011 if( pItem->zDatabase ){
112012 sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
112013 }else if( pItem->zName ){
112014 sqlite3XPrintf(&x, 0, " %s", pItem->zName);
@@ -111760,11 +112163,11 @@
112163 for(i=0; i<nCol; i++){
112164 if( argv[i]==0 ){
112165 z = 0;
112166 }else{
112167 int n = sqlite3Strlen30(argv[i])+1;
112168 z = sqlite3_malloc64( n );
112169 if( z==0 ) goto malloc_failed;
112170 memcpy(z, argv[i], n);
112171 }
112172 p->azResult[p->nData++] = z;
112173 }
@@ -111809,11 +112212,11 @@
112212 res.nRow = 0;
112213 res.nColumn = 0;
112214 res.nData = 1;
112215 res.nAlloc = 20;
112216 res.rc = SQLITE_OK;
112217 res.azResult = sqlite3_malloc64(sizeof(char*)*res.nAlloc );
112218 if( res.azResult==0 ){
112219 db->errCode = SQLITE_NOMEM;
112220 return SQLITE_NOMEM;
112221 }
112222 res.azResult[0] = 0;
@@ -111837,11 +112240,11 @@
112240 sqlite3_free_table(&res.azResult[1]);
112241 return rc;
112242 }
112243 if( res.nAlloc>res.nData ){
112244 char **azNew;
112245 azNew = sqlite3_realloc64( res.azResult, sizeof(char*)*res.nData );
112246 if( azNew==0 ){
112247 sqlite3_free_table(&res.azResult[1]);
112248 db->errCode = SQLITE_NOMEM;
112249 return SQLITE_NOMEM;
112250 }
@@ -112065,11 +112468,10 @@
112468 }
112469
112470 /* Do not create a trigger on a system table */
112471 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
112472 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
 
112473 goto trigger_cleanup;
112474 }
112475
112476 /* INSTEAD of triggers are only for views and views only support INSTEAD
112477 ** of triggers.
@@ -112245,16 +112647,16 @@
112647 u8 op, /* Trigger opcode */
112648 Token *pName /* The target name */
112649 ){
112650 TriggerStep *pTriggerStep;
112651
112652 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
112653 if( pTriggerStep ){
112654 char *z = (char*)&pTriggerStep[1];
112655 memcpy(z, pName->z, pName->n);
112656 sqlite3Dequote(z);
112657 pTriggerStep->zTarget = z;
112658 pTriggerStep->op = op;
112659 }
112660 return pTriggerStep;
112661 }
112662
@@ -112533,11 +112935,11 @@
112935 }
112936 return (mask ? pList : 0);
112937 }
112938
112939 /*
112940 ** Convert the pStep->zTarget string into a SrcList and return a pointer
112941 ** to that SrcList.
112942 **
112943 ** This routine adds a specific database name, if needed, to the target when
112944 ** forming the SrcList. This prevents a trigger in one database from
112945 ** referring to a target in another database. An exception is when the
@@ -112546,21 +112948,21 @@
112948 */
112949 static SrcList *targetSrcList(
112950 Parse *pParse, /* The parsing context */
112951 TriggerStep *pStep /* The trigger containing the target token */
112952 ){
112953 sqlite3 *db = pParse->db;
112954 int iDb; /* Index of the database to use */
112955 SrcList *pSrc; /* SrcList to be returned */
112956
112957 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
112958 if( pSrc ){
112959 assert( pSrc->nSrc>0 );
112960 pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
112961 iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
112962 if( iDb==0 || iDb>=2 ){
112963 assert( iDb<db->nDb );
 
112964 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
112965 }
112966 }
112967 return pSrc;
112968 }
@@ -112668,10 +113070,11 @@
113070 assert( pFrom->zErrMsg==0 || pFrom->nErr );
113071 assert( pTo->zErrMsg==0 || pTo->nErr );
113072 if( pTo->nErr==0 ){
113073 pTo->zErrMsg = pFrom->zErrMsg;
113074 pTo->nErr = pFrom->nErr;
113075 pTo->rc = pFrom->rc;
113076 }else{
113077 sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
113078 }
113079 }
113080
@@ -114018,17 +114421,21 @@
114421
114422 /* Loop through the tables in the main database. For each, do
114423 ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
114424 ** the contents to the temporary database.
114425 */
114426 assert( (db->flags & SQLITE_Vacuum)==0 );
114427 db->flags |= SQLITE_Vacuum;
114428 rc = execExecSql(db, pzErrMsg,
114429 "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
114430 "|| ' SELECT * FROM main.' || quote(name) || ';'"
114431 "FROM main.sqlite_master "
114432 "WHERE type = 'table' AND name!='sqlite_sequence' "
114433 " AND coalesce(rootpage,1)>0"
114434 );
114435 assert( (db->flags & SQLITE_Vacuum)!=0 );
114436 db->flags &= ~SQLITE_Vacuum;
114437 if( rc!=SQLITE_OK ) goto end_of_vacuum;
114438
114439 /* Copy over the sequence table
114440 */
114441 rc = execExecSql(db, pzErrMsg,
@@ -114163,10 +114570,12 @@
114570 ** are invoked only from within xCreate and xConnect methods.
114571 */
114572 struct VtabCtx {
114573 VTable *pVTable; /* The virtual table being constructed */
114574 Table *pTab; /* The Table object to which the virtual table belongs */
114575 VtabCtx *pPrior; /* Parent context (if any) */
114576 int bDeclared; /* True after sqlite3_declare_vtab() is called */
114577 };
114578
114579 /*
114580 ** The actual function that does the work of creating a new module.
114581 ** This function implements the sqlite3_create_module() and
@@ -114609,11 +115018,11 @@
115018 Token *pArg = &pParse->sArg;
115019 if( pArg->z==0 ){
115020 pArg->z = p->z;
115021 pArg->n = p->n;
115022 }else{
115023 assert(pArg->z <= p->z);
115024 pArg->n = (int)(&p->z[p->n] - pArg->z);
115025 }
115026 }
115027
115028 /*
@@ -114626,19 +115035,31 @@
115035 Table *pTab,
115036 Module *pMod,
115037 int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**),
115038 char **pzErr
115039 ){
115040 VtabCtx sCtx;
115041 VTable *pVTable;
115042 int rc;
115043 const char *const*azArg = (const char *const*)pTab->azModuleArg;
115044 int nArg = pTab->nModuleArg;
115045 char *zErr = 0;
115046 char *zModuleName;
115047 int iDb;
115048 VtabCtx *pCtx;
115049
115050 /* Check that the virtual-table is not already being initialized */
115051 for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
115052 if( pCtx->pTab==pTab ){
115053 *pzErr = sqlite3MPrintf(db,
115054 "vtable constructor called recursively: %s", pTab->zName
115055 );
115056 return SQLITE_LOCKED;
115057 }
115058 }
115059
115060 zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
115061 if( !zModuleName ){
115062 return SQLITE_NOMEM;
115063 }
115064
115065 pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
@@ -114655,15 +115076,17 @@
115076 /* Invoke the virtual table constructor */
115077 assert( &db->pVtabCtx );
115078 assert( xConstruct );
115079 sCtx.pTab = pTab;
115080 sCtx.pVTable = pVTable;
115081 sCtx.pPrior = db->pVtabCtx;
115082 sCtx.bDeclared = 0;
115083 db->pVtabCtx = &sCtx;
115084 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
115085 db->pVtabCtx = sCtx.pPrior;
115086 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
115087 assert( sCtx.pTab==pTab );
115088
115089 if( SQLITE_OK!=rc ){
115090 if( zErr==0 ){
115091 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
115092 }else {
@@ -114675,17 +115098,18 @@
115098 /* Justification of ALWAYS(): A correct vtab constructor must allocate
115099 ** the sqlite3_vtab object if successful. */
115100 memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
115101 pVTable->pVtab->pModule = pMod->pModule;
115102 pVTable->nRef = 1;
115103 if( sCtx.bDeclared==0 ){
115104 const char *zFormat = "vtable constructor did not declare schema: %s";
115105 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
115106 sqlite3VtabUnlock(pVTable);
115107 rc = SQLITE_ERROR;
115108 }else{
115109 int iCol;
115110 u8 oooHidden = 0;
115111 /* If everything went according to plan, link the new VTable structure
115112 ** into the linked list headed by pTab->pVTable. Then loop through the
115113 ** columns of the table to see if any of them contain the token "hidden".
115114 ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
115115 ** the type string. */
@@ -114694,11 +115118,14 @@
115118
115119 for(iCol=0; iCol<pTab->nCol; iCol++){
115120 char *zType = pTab->aCol[iCol].zType;
115121 int nType;
115122 int i = 0;
115123 if( !zType ){
115124 pTab->tabFlags |= oooHidden;
115125 continue;
115126 }
115127 nType = sqlite3Strlen30(zType);
115128 if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){
115129 for(i=0; i<nType; i++){
115130 if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7))
115131 && (zType[i+7]=='\0' || zType[i+7]==' ')
@@ -114717,10 +115144,13 @@
115144 if( zType[i]=='\0' && i>0 ){
115145 assert(zType[i-1]==' ');
115146 zType[i-1] = '\0';
115147 }
115148 pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN;
115149 oooHidden = TF_OOOHidden;
115150 }else{
115151 pTab->tabFlags |= oooHidden;
115152 }
115153 }
115154 }
115155 }
115156
@@ -114845,12 +115275,12 @@
115275 ** This function is used to set the schema of a virtual table. It is only
115276 ** valid to call this function from within the xCreate() or xConnect() of a
115277 ** virtual table module.
115278 */
115279 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
115280 VtabCtx *pCtx;
115281 Parse *pParse;
 
115282 int rc = SQLITE_OK;
115283 Table *pTab;
115284 char *zErr = 0;
115285
115286 #ifdef SQLITE_ENABLE_API_ARMOR
@@ -114857,15 +115287,17 @@
115287 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
115288 return SQLITE_MISUSE_BKPT;
115289 }
115290 #endif
115291 sqlite3_mutex_enter(db->mutex);
115292 pCtx = db->pVtabCtx;
115293 if( !pCtx || pCtx->bDeclared ){
115294 sqlite3Error(db, SQLITE_MISUSE);
115295 sqlite3_mutex_leave(db->mutex);
115296 return SQLITE_MISUSE_BKPT;
115297 }
115298 pTab = pCtx->pTab;
115299 assert( (pTab->tabFlags & TF_Virtual)!=0 );
115300
115301 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
115302 if( pParse==0 ){
115303 rc = SQLITE_NOMEM;
@@ -114884,11 +115316,11 @@
115316 pTab->aCol = pParse->pNewTable->aCol;
115317 pTab->nCol = pParse->pNewTable->nCol;
115318 pParse->pNewTable->nCol = 0;
115319 pParse->pNewTable->aCol = 0;
115320 }
115321 pCtx->bDeclared = 1;
115322 }else{
115323 sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
115324 sqlite3DbFree(db, zErr);
115325 rc = SQLITE_ERROR;
115326 }
@@ -115078,11 +115510,11 @@
115510 */
115511 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
115512 int rc = SQLITE_OK;
115513
115514 assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
115515 assert( iSavepoint>=-1 );
115516 if( db->aVTrans ){
115517 int i;
115518 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
115519 VTable *pVTab = db->aVTrans[i];
115520 const sqlite3_module *pMod = pVTab->pMod->pModule;
@@ -115196,11 +115628,11 @@
115628 assert( IsVirtual(pTab) );
115629 for(i=0; i<pToplevel->nVtabLock; i++){
115630 if( pTab==pToplevel->apVtabLock[i] ) return;
115631 }
115632 n = (pToplevel->nVtabLock+1)*sizeof(pToplevel->apVtabLock[0]);
115633 apVtabLock = sqlite3_realloc64(pToplevel->apVtabLock, n);
115634 if( apVtabLock ){
115635 pToplevel->apVtabLock = apVtabLock;
115636 pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
115637 }else{
115638 pToplevel->db->mallocFailed = 1;
@@ -115995,17 +116427,18 @@
116427 ** In the previous sentence and in the diagram, "slot[]" refers to
116428 ** the WhereClause.a[] array. The slot[] array grows as needed to contain
116429 ** all terms of the WHERE clause.
116430 */
116431 static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){
116432 Expr *pE2 = sqlite3ExprSkipCollate(pExpr);
116433 pWC->op = op;
116434 if( pE2==0 ) return;
116435 if( pE2->op!=op ){
116436 whereClauseInsert(pWC, pExpr, 0);
116437 }else{
116438 whereSplit(pWC, pE2->pLeft, op);
116439 whereSplit(pWC, pE2->pRight, op);
116440 }
116441 }
116442
116443 /*
116444 ** Initialize a WhereMaskSet object
@@ -117272,11 +117705,11 @@
117705 if( p->op==TK_COLUMN
117706 && p->iColumn==pIdx->aiColumn[iCol]
117707 && p->iTable==iBase
117708 ){
117709 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr);
117710 if( pColl && 0==sqlite3StrICmp(pColl->zName, zColl) ){
117711 return i;
117712 }
117713 }
117714 }
117715
@@ -117546,11 +117979,11 @@
117979 if( (idxCols & cMask)==0 ){
117980 Expr *pX = pTerm->pExpr;
117981 idxCols |= cMask;
117982 pIdx->aiColumn[n] = pTerm->u.leftColumn;
117983 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
117984 pIdx->azColl[n] = pColl ? pColl->zName : "BINARY";
117985 n++;
117986 }
117987 }
117988 }
117989 assert( (u32)n==pLoop->u.btree.nEq );
@@ -118842,12 +119275,11 @@
119275
119276 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
119277 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
119278 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
119279
119280 sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
 
119281 sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
119282 if( pItem->pSelect ){
119283 sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId);
119284 }else{
119285 sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName);
@@ -120042,10 +120474,17 @@
120474 /*
120475 ** Free a WhereInfo structure
120476 */
120477 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
120478 if( ALWAYS(pWInfo) ){
120479 int i;
120480 for(i=0; i<pWInfo->nLevel; i++){
120481 WhereLevel *pLevel = &pWInfo->a[i];
120482 if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){
120483 sqlite3DbFree(db, pLevel->u.in.aInLoop);
120484 }
120485 }
120486 whereClauseClear(&pWInfo->sWC);
120487 while( pWInfo->pLoops ){
120488 WhereLoop *p = pWInfo->pLoops;
120489 pWInfo->pLoops = p->pNextLoop;
120490 whereLoopDelete(db, p);
@@ -120521,11 +120960,11 @@
120960 ** changes "x IN (?)" into "x=?". */
120961
120962 }else if( eOp & (WO_EQ) ){
120963 pNew->wsFlags |= WHERE_COLUMN_EQ;
120964 if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
120965 if( iCol>=0 && pProbe->uniqNotNull==0 ){
120966 pNew->wsFlags |= WHERE_UNQ_WANTED;
120967 }else{
120968 pNew->wsFlags |= WHERE_ONEROW;
120969 }
120970 }
@@ -121981,11 +122420,11 @@
122420 pWInfo->nOBSat = pFrom->isOrdered;
122421 if( pWInfo->nOBSat<0 ) pWInfo->nOBSat = 0;
122422 pWInfo->revMask = pFrom->revLoop;
122423 }
122424 if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
122425 && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && nLoop>0
122426 ){
122427 Bitmask revMask = 0;
122428 int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
122429 pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
122430 );
@@ -122386,11 +122825,10 @@
122825 if( pParse->nErr || NEVER(db->mallocFailed) ){
122826 goto whereBeginError;
122827 }
122828 #ifdef WHERETRACE_ENABLED /* !=0 */
122829 if( sqlite3WhereTrace ){
 
122830 sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
122831 if( pWInfo->nOBSat>0 ){
122832 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
122833 }
122834 switch( pWInfo->eDistinct ){
@@ -122639,11 +123077,10 @@
123077 VdbeCoverage(v);
123078 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
123079 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
123080 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
123081 }
 
123082 }
123083 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
123084 if( pLevel->addrSkip ){
123085 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
123086 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
@@ -122850,10 +123287,32 @@
123287 /*
123288 ** An instance of this structure holds the ATTACH key and the key type.
123289 */
123290 struct AttachKey { int type; Token key; };
123291
123292
123293 /*
123294 ** For a compound SELECT statement, make sure p->pPrior->pNext==p for
123295 ** all elements in the list. And make sure list length does not exceed
123296 ** SQLITE_LIMIT_COMPOUND_SELECT.
123297 */
123298 static void parserDoubleLinkSelect(Parse *pParse, Select *p){
123299 if( p->pPrior ){
123300 Select *pNext = 0, *pLoop;
123301 int mxSelect, cnt = 0;
123302 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
123303 pLoop->pNext = pNext;
123304 pLoop->selFlags |= SF_Compound;
123305 }
123306 if( (p->selFlags & SF_MultiValue)==0 &&
123307 (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 &&
123308 cnt>mxSelect
123309 ){
123310 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
123311 }
123312 }
123313 }
123314
123315 /* This is a utility routine used to set the ExprSpan.zStart and
123316 ** ExprSpan.zEnd values of pOut so that the span covers the complete
123317 ** range of text beginning with pStart and going to the end of pEnd.
123318 */
@@ -125167,31 +125626,14 @@
125626 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
125627 }
125628 break;
125629 case 112: /* select ::= with selectnowith */
125630 {
125631 Select *p = yymsp[0].minor.yy3;
125632 if( p ){
 
125633 p->pWith = yymsp[-1].minor.yy59;
125634 parserDoubleLinkSelect(pParse, p);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125635 }else{
125636 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
125637 }
125638 yygotominor.yy3 = p;
125639 }
@@ -125205,16 +125647,18 @@
125647 Select *pRhs = yymsp[0].minor.yy3;
125648 if( pRhs && pRhs->pPrior ){
125649 SrcList *pFrom;
125650 Token x;
125651 x.n = 0;
125652 parserDoubleLinkSelect(pParse, pRhs);
125653 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
125654 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
125655 }
125656 if( pRhs ){
125657 pRhs->op = (u8)yymsp[-1].minor.yy328;
125658 pRhs->pPrior = yymsp[-2].minor.yy3;
125659 pRhs->selFlags &= ~SF_MultiValue;
125660 if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
125661 }else{
125662 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
125663 }
125664 yygotominor.yy3 = pRhs;
@@ -125257,17 +125701,20 @@
125701 yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
125702 }
125703 break;
125704 case 121: /* values ::= values COMMA LP exprlist RP */
125705 {
125706 Select *pRight, *pLeft = yymsp[-4].minor.yy3;
125707 pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values|SF_MultiValue,0,0);
125708 if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
125709 if( pRight ){
125710 pRight->op = TK_ALL;
125711 pLeft = yymsp[-4].minor.yy3;
125712 pRight->pPrior = pLeft;
125713 yygotominor.yy3 = pRight;
125714 }else{
125715 yygotominor.yy3 = pLeft;
125716 }
125717 }
125718 break;
125719 case 122: /* distinct ::= DISTINCT */
125720 {yygotominor.yy381 = SF_Distinct;}
@@ -127067,14 +127514,12 @@
127514 goto abort_parse;
127515 }
127516 break;
127517 }
127518 case TK_ILLEGAL: {
127519 sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"",
 
127520 &pParse->sLastToken);
 
127521 goto abort_parse;
127522 }
127523 case TK_SEMI: {
127524 pParse->zTail = &zSql[i];
127525 /* Fall thru into the default case */
@@ -127088,16 +127533,19 @@
127533 break;
127534 }
127535 }
127536 }
127537 abort_parse:
127538 assert( nErr==0 );
127539 if( zSql[i]==0 && pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
127540 if( lastTokenParsed!=TK_SEMI ){
127541 sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
127542 pParse->zTail = &zSql[i];
127543 }
127544 if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
127545 sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
127546 }
127547 }
127548 #ifdef YYTRACKMAXSTACKDEPTH
127549 sqlite3_mutex_enter(sqlite3MallocMutex());
127550 sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
127551 sqlite3ParserStackPeak(pEngine)
@@ -127154,13 +127602,11 @@
127602 while( pParse->pZombieTab ){
127603 Table *p = pParse->pZombieTab;
127604 pParse->pZombieTab = p->pNextZombie;
127605 sqlite3DeleteTable(db, p);
127606 }
127607 assert( nErr==0 || pParse->rc!=SQLITE_OK );
 
 
127608 return nErr;
127609 }
127610
127611 /************** End of tokenize.c ********************************************/
127612 /************** Begin file complete.c ****************************************/
@@ -127432,11 +127878,11 @@
127878 ** UTF-8.
127879 */
127880 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *zSql){
127881 sqlite3_value *pVal;
127882 char const *zSql8;
127883 int rc;
127884
127885 #ifndef SQLITE_OMIT_AUTOINIT
127886 rc = sqlite3_initialize();
127887 if( rc ) return rc;
127888 #endif
@@ -127598,10 +128044,22 @@
128044 ** zero if and only if SQLite was compiled with mutexing code omitted due to
128045 ** the SQLITE_THREADSAFE compile-time option being set to 0.
128046 */
128047 SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }
128048
128049 /*
128050 ** When compiling the test fixture or with debugging enabled (on Win32),
128051 ** this variable being set to non-zero will cause OSTRACE macros to emit
128052 ** extra diagnostic information.
128053 */
128054 #ifdef SQLITE_HAVE_OS_TRACE
128055 # ifndef SQLITE_DEBUG_OS_TRACE
128056 # define SQLITE_DEBUG_OS_TRACE 0
128057 # endif
128058 int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
128059 #endif
128060
128061 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
128062 /*
128063 ** If the following function pointer is not NULL and if
128064 ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
128065 ** I/O active are written using this function. These messages
@@ -128737,11 +129195,11 @@
129195
129196 /*
129197 ** Return a static string containing the name corresponding to the error code
129198 ** specified in the argument.
129199 */
129200 #if defined(SQLITE_NEED_ERR_NAME)
129201 SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
129202 const char *zName = 0;
129203 int i, origRc = rc;
129204 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
129205 switch( rc ){
@@ -129962,18 +130420,18 @@
130420 ){
130421 char *zOpt;
130422 int eState; /* Parser state when parsing URI */
130423 int iIn; /* Input character index */
130424 int iOut = 0; /* Output character index */
130425 u64 nByte = nUri+2; /* Bytes of space to allocate */
130426
130427 /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
130428 ** method that there may be extra parameters following the file-name. */
130429 flags |= SQLITE_OPEN_URI;
130430
130431 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
130432 zFile = sqlite3_malloc64(nByte);
130433 if( !zFile ) return SQLITE_NOMEM;
130434
130435 iIn = 5;
130436 #ifdef SQLITE_ALLOW_URI_AUTHORITY
130437 if( strncmp(zUri+5, "///", 3)==0 ){
@@ -130135,11 +130593,11 @@
130593
130594 zOpt = &zVal[nVal+1];
130595 }
130596
130597 }else{
130598 zFile = sqlite3_malloc64(nUri+2);
130599 if( !zFile ) return SQLITE_NOMEM;
130600 memcpy(zFile, zUri, nUri);
130601 zFile[nUri] = '\0';
130602 zFile[nUri+1] = '\0';
130603 flags &= ~SQLITE_OPEN_URI;
@@ -130406,10 +130864,17 @@
130864 #ifdef SQLITE_ENABLE_RTREE
130865 if( !db->mallocFailed && rc==SQLITE_OK){
130866 rc = sqlite3RtreeInit(db);
130867 }
130868 #endif
130869
130870 #ifdef SQLITE_ENABLE_DBSTAT_VTAB
130871 if( !db->mallocFailed && rc==SQLITE_OK){
130872 int sqlite3_dbstat_register(sqlite3*);
130873 rc = sqlite3_dbstat_register(db);
130874 }
130875 #endif
130876
130877 /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
130878 ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
130879 ** mode. Doing nothing at all also makes NORMAL the default.
130880 */
@@ -132344,10 +132809,15 @@
132809 ** false.
132810 */
132811 #ifdef SQLITE_COVERAGE_TEST
132812 # define ALWAYS(x) (1)
132813 # define NEVER(X) (0)
132814 #elif defined(SQLITE_DEBUG)
132815 # define ALWAYS(x) sqlite3Fts3Always((x)!=0)
132816 # define NEVER(x) sqlite3Fts3Never((x)!=0)
132817 SQLITE_PRIVATE int sqlite3Fts3Always(int b);
132818 SQLITE_PRIVATE int sqlite3Fts3Never(int b);
132819 #else
132820 # define ALWAYS(x) (x)
132821 # define NEVER(x) (x)
132822 #endif
132823
@@ -132744,10 +133214,11 @@
133214 #define fts3GetVarint32(p, piVal) ( \
133215 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
133216 )
133217
133218 /* fts3.c */
133219 SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...);
133220 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
133221 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
133222 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
133223 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
133224 SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
@@ -132832,10 +133303,17 @@
133303
133304 static int fts3EvalNext(Fts3Cursor *pCsr);
133305 static int fts3EvalStart(Fts3Cursor *pCsr);
133306 static int fts3TermSegReaderCursor(
133307 Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **);
133308
133309 #ifndef SQLITE_AMALGAMATION
133310 # if defined(SQLITE_DEBUG)
133311 SQLITE_PRIVATE int sqlite3Fts3Always(int b) { assert( b ); return b; }
133312 SQLITE_PRIVATE int sqlite3Fts3Never(int b) { assert( !b ); return b; }
133313 # endif
133314 #endif
133315
133316 /*
133317 ** Write a 64-bit variable-length integer to memory starting at p[0].
133318 ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
133319 ** The number of bytes written is returned.
@@ -132942,11 +133420,11 @@
133420 int iOut = 0; /* Index of next byte to write to output */
133421
133422 /* If the first byte was a '[', then the close-quote character is a ']' */
133423 if( quote=='[' ) quote = ']';
133424
133425 while( z[iIn] ){
133426 if( z[iIn]==quote ){
133427 if( z[iIn+1]!=quote ) break;
133428 z[iOut++] = quote;
133429 iIn += 2;
133430 }else{
@@ -133020,10 +133498,21 @@
133498 p->pTokenizer->pModule->xDestroy(p->pTokenizer);
133499
133500 sqlite3_free(p);
133501 return SQLITE_OK;
133502 }
133503
133504 /*
133505 ** Write an error message into *pzErr
133506 */
133507 SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char **pzErr, const char *zFormat, ...){
133508 va_list ap;
133509 sqlite3_free(*pzErr);
133510 va_start(ap, zFormat);
133511 *pzErr = sqlite3_vmprintf(zFormat, ap);
133512 va_end(ap);
133513 }
133514
133515 /*
133516 ** Construct one or more SQL statements from the format string given
133517 ** and then evaluate those statements. The success code is written
133518 ** into *pRc.
@@ -133539,11 +134028,12 @@
134028 sqlite3 *db, /* Database handle */
134029 const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */
134030 const char *zTbl, /* Name of content table */
134031 const char ***pazCol, /* OUT: Malloc'd array of column names */
134032 int *pnCol, /* OUT: Size of array *pazCol */
134033 int *pnStr, /* OUT: Bytes of string content */
134034 char **pzErr /* OUT: error message */
134035 ){
134036 int rc = SQLITE_OK; /* Return code */
134037 char *zSql; /* "SELECT *" statement on zTbl */
134038 sqlite3_stmt *pStmt = 0; /* Compiled version of zSql */
134039
@@ -133550,10 +134040,13 @@
134040 zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", zDb, zTbl);
134041 if( !zSql ){
134042 rc = SQLITE_NOMEM;
134043 }else{
134044 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
134045 if( rc!=SQLITE_OK ){
134046 sqlite3Fts3ErrMsg(pzErr, "%s", sqlite3_errmsg(db));
134047 }
134048 }
134049 sqlite3_free(zSql);
134050
134051 if( rc==SQLITE_OK ){
134052 const char **azCol; /* Output array */
@@ -133716,17 +134209,17 @@
134209 if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
134210 break;
134211 }
134212 }
134213 if( iOpt==SizeofArray(aFts4Opt) ){
134214 sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
134215 rc = SQLITE_ERROR;
134216 }else{
134217 switch( iOpt ){
134218 case 0: /* MATCHINFO */
134219 if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
134220 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
134221 rc = SQLITE_ERROR;
134222 }
134223 bNoDocsize = 1;
134224 break;
134225
@@ -133750,11 +134243,11 @@
134243
134244 case 4: /* ORDER */
134245 if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
134246 && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
134247 ){
134248 sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
134249 rc = SQLITE_ERROR;
134250 }
134251 bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
134252 break;
134253
@@ -133801,11 +134294,11 @@
134294 zCompress = 0;
134295 zUncompress = 0;
134296 if( nCol==0 ){
134297 sqlite3_free((void*)aCol);
134298 aCol = 0;
134299 rc = fts3ContentColumns(db, argv[1], zContent,&aCol,&nCol,&nString,pzErr);
134300
134301 /* If a languageid= option was specified, remove the language id
134302 ** column from the aCol[] array. */
134303 if( rc==SQLITE_OK && zLanguageid ){
134304 int j;
@@ -133836,11 +134329,11 @@
134329 assert( pTokenizer );
134330
134331 rc = fts3PrefixParameter(zPrefix, &nIndex, &aIndex);
134332 if( rc==SQLITE_ERROR ){
134333 assert( zPrefix );
134334 sqlite3Fts3ErrMsg(pzErr, "error parsing prefix parameter: %s", zPrefix);
134335 }
134336 if( rc!=SQLITE_OK ) goto fts3_init_out;
134337
134338 /* Allocate and populate the Fts3Table structure. */
134339 nByte = sizeof(Fts3Table) + /* Fts3Table */
@@ -133918,19 +134411,19 @@
134411 }
134412 }
134413 }
134414 for(i=0; i<nNotindexed; i++){
134415 if( azNotindexed[i] ){
134416 sqlite3Fts3ErrMsg(pzErr, "no such column: %s", azNotindexed[i]);
134417 rc = SQLITE_ERROR;
134418 }
134419 }
134420
134421 if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
134422 char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
134423 rc = SQLITE_ERROR;
134424 sqlite3Fts3ErrMsg(pzErr, "missing %s parameter in fts4 constructor", zMiss);
134425 }
134426 p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
134427 p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc);
134428 if( rc!=SQLITE_OK ) goto fts3_init_out;
134429
@@ -135319,11 +135812,11 @@
135812 ** Fts3SegReaderPending might segfault, as the data structures used by
135813 ** fts4aux are not completely populated. So it's easiest to filter these
135814 ** calls out here. */
135815 if( iLevel<0 && p->aIndex ){
135816 Fts3SegReader *pSeg = 0;
135817 rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix||isScan, &pSeg);
135818 if( rc==SQLITE_OK && pSeg ){
135819 rc = fts3SegReaderCursorAppend(pCsr, pSeg);
135820 }
135821 }
135822
@@ -135968,15 +136461,35 @@
136461 */
136462 static void fts3ReversePoslist(char *pStart, char **ppPoslist){
136463 char *p = &(*ppPoslist)[-2];
136464 char c = 0;
136465
136466 /* Skip backwards passed any trailing 0x00 bytes added by NearTrim() */
136467 while( p>pStart && (c=*p--)==0 );
136468
136469 /* Search backwards for a varint with value zero (the end of the previous
136470 ** poslist). This is an 0x00 byte preceded by some byte that does not
136471 ** have the 0x80 bit set. */
136472 while( p>pStart && (*p & 0x80) | c ){
136473 c = *p--;
136474 }
136475 assert( p==pStart || c==0 );
136476
136477 /* At this point p points to that preceding byte without the 0x80 bit
136478 ** set. So to find the start of the poslist, skip forward 2 bytes then
136479 ** over a varint.
136480 **
136481 ** Normally. The other case is that p==pStart and the poslist to return
136482 ** is the first in the doclist. In this case do not skip forward 2 bytes.
136483 ** The second part of the if condition (c==0 && *ppPoslist>&p[2])
136484 ** is required for cases where the first byte of a doclist and the
136485 ** doclist is empty. For example, if the first docid is 10, a doclist
136486 ** that begins with:
136487 **
136488 ** 0x0A 0x00 <next docid delta varint>
136489 */
136490 if( p>pStart || (c==0 && *ppPoslist>&p[2]) ){ p = &p[2]; }
136491 while( *p++&0x80 );
136492 *ppPoslist = p;
136493 }
136494
136495 /*
@@ -136043,10 +136556,12 @@
136556 case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]);
136557 case 2: zStart = (const char*)sqlite3_value_text(apVal[1]);
136558 }
136559 if( !zEllipsis || !zEnd || !zStart ){
136560 sqlite3_result_error_nomem(pContext);
136561 }else if( nToken==0 ){
136562 sqlite3_result_text(pContext, "", -1, SQLITE_STATIC);
136563 }else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){
136564 sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken);
136565 }
136566 }
136567
@@ -137104,16 +137619,18 @@
137619 Fts3Expr *pExpr, /* Expression to initialize phrases in */
137620 int *pRc /* IN/OUT: Error code */
137621 ){
137622 if( pExpr && SQLITE_OK==*pRc ){
137623 if( pExpr->eType==FTSQUERY_PHRASE ){
 
137624 int nToken = pExpr->pPhrase->nToken;
137625 if( nToken ){
137626 int i;
137627 for(i=0; i<nToken; i++){
137628 if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
137629 }
137630 pExpr->bDeferred = (i==nToken);
137631 }
 
137632 *pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase);
137633 }else{
137634 fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc);
137635 fts3EvalStartReaders(pCsr, pExpr->pRight, pRc);
137636 pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred);
@@ -138272,11 +138789,12 @@
138789 if( rc!=SQLITE_OK ) return rc;
138790
138791 pIter = pPhrase->pOrPoslist;
138792 iDocid = pPhrase->iOrDocid;
138793 if( pCsr->bDesc==bDescDoclist ){
138794 bEof = !pPhrase->doclist.nAll ||
138795 (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll));
138796 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
138797 sqlite3Fts3DoclistNext(
138798 bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
138799 &pIter, &iDocid, &bEof
138800 );
@@ -138484,11 +139002,11 @@
139002
139003 *ppVtab = (sqlite3_vtab *)p;
139004 return SQLITE_OK;
139005
139006 bad_args:
139007 sqlite3Fts3ErrMsg(pzErr, "invalid arguments to fts4aux constructor");
139008 return SQLITE_ERROR;
139009 }
139010
139011 /*
139012 ** This function does the work for both the xDisconnect and xDestroy methods.
@@ -139942,17 +140460,17 @@
140460
140461 if( rc!=SQLITE_OK ){
140462 sqlite3Fts3ExprFree(*ppExpr);
140463 *ppExpr = 0;
140464 if( rc==SQLITE_TOOBIG ){
140465 sqlite3Fts3ErrMsg(pzErr,
140466 "FTS expression tree is too large (maximum depth %d)",
140467 SQLITE_FTS3_MAX_EXPR_DEPTH
140468 );
140469 rc = SQLITE_ERROR;
140470 }else if( rc==SQLITE_ERROR ){
140471 sqlite3Fts3ErrMsg(pzErr, "malformed MATCH expression: [%s]", z);
140472 }
140473 }
140474
140475 return rc;
140476 }
@@ -141424,11 +141942,11 @@
141942 z[n] = '\0';
141943 sqlite3Fts3Dequote(z);
141944
141945 m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1);
141946 if( !m ){
141947 sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", z);
141948 rc = SQLITE_ERROR;
141949 }else{
141950 char const **aArg = 0;
141951 int iArg = 0;
141952 z = &z[n+1];
@@ -141447,11 +141965,11 @@
141965 z = &z[n+1];
141966 }
141967 rc = m->xCreate(iArg, aArg, ppTok);
141968 assert( rc!=SQLITE_OK || *ppTok );
141969 if( rc!=SQLITE_OK ){
141970 sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer");
141971 }else{
141972 (*ppTok)->pModule = m;
141973 }
141974 sqlite3_free((void *)aArg);
141975 }
@@ -141531,13 +142049,13 @@
142049
142050 pHash = (Fts3Hash *)sqlite3_user_data(context);
142051 p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
142052
142053 if( !p ){
142054 char *zErr2 = sqlite3_mprintf("unknown tokenizer: %s", zName);
142055 sqlite3_result_error(context, zErr2, -1);
142056 sqlite3_free(zErr2);
142057 return;
142058 }
142059
142060 pRet = Tcl_NewObj();
142061 Tcl_IncrRefCount(pRet);
@@ -142068,11 +142586,11 @@
142586 sqlite3_tokenizer_module *p;
142587 int nName = (int)strlen(zName);
142588
142589 p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1);
142590 if( !p ){
142591 sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", zName);
142592 return SQLITE_ERROR;
142593 }
142594
142595 *pp = p;
142596 return SQLITE_OK;
@@ -142765,11 +143283,11 @@
143283 /* 23 */ "REPLACE INTO %Q.'%q_stat' VALUES(?,?)",
143284 /* 24 */ "",
143285 /* 25 */ "",
143286
143287 /* 26 */ "DELETE FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?",
143288 /* 27 */ "SELECT ? UNION SELECT level / (1024 * ?) FROM %Q.'%q_segdir'",
143289
143290 /* This statement is used to determine which level to read the input from
143291 ** when performing an incremental merge. It returns the absolute level number
143292 ** of the oldest level in the db that contains at least ? segments. Or,
143293 ** if no level in the FTS index contains more than ? segments, the statement
@@ -145883,11 +146401,12 @@
146401 sqlite3_stmt *pAllLangid = 0;
146402
146403 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
146404 if( rc==SQLITE_OK ){
146405 int rc2;
146406 sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid);
146407 sqlite3_bind_int(pAllLangid, 2, p->nIndex);
146408 while( sqlite3_step(pAllLangid)==SQLITE_ROW ){
146409 int i;
146410 int iLangid = sqlite3_column_int(pAllLangid, 0);
146411 for(i=0; rc==SQLITE_OK && i<p->nIndex; i++){
146412 rc = fts3SegmentMerge(p, iLangid, i, FTS3_SEGCURSOR_ALL);
@@ -147215,11 +147734,11 @@
147734 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
147735
147736 pHint->n = i;
147737 i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
147738 i += fts3GetVarint32(&pHint->a[i], pnInput);
147739 if( i!=nHint ) return FTS_CORRUPT_VTAB;
147740
147741 return SQLITE_OK;
147742 }
147743
147744
@@ -147583,11 +148102,12 @@
148102
148103 /* This block calculates the checksum according to the FTS index. */
148104 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
148105 if( rc==SQLITE_OK ){
148106 int rc2;
148107 sqlite3_bind_int(pAllLangid, 1, p->iPrevLangid);
148108 sqlite3_bind_int(pAllLangid, 2, p->nIndex);
148109 while( rc==SQLITE_OK && sqlite3_step(pAllLangid)==SQLITE_ROW ){
148110 int iLangid = sqlite3_column_int(pAllLangid, 0);
148111 int i;
148112 for(i=0; i<p->nIndex; i++){
148113 cksum1 = cksum1 ^ fts3ChecksumIndex(p, iLangid, i, &rc);
@@ -147596,11 +148116,10 @@
148116 rc2 = sqlite3_reset(pAllLangid);
148117 if( rc==SQLITE_OK ) rc = rc2;
148118 }
148119
148120 /* This block calculates the checksum according to the %_content table */
 
148121 if( rc==SQLITE_OK ){
148122 sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule;
148123 sqlite3_stmt *pStmt = 0;
148124 char *zSql;
148125
@@ -147693,11 +148212,11 @@
148212 Fts3Table *p /* FTS3 table handle */
148213 ){
148214 int rc;
148215 int bOk = 0;
148216 rc = fts3IntegrityCheck(p, &bOk);
148217 if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB;
148218 return rc;
148219 }
148220
148221 /*
148222 ** Handle a 'special' INSERT of the form:
@@ -148131,10 +148650,11 @@
148650 #define FTS3_MATCHINFO_NDOC 'n' /* 1 value */
148651 #define FTS3_MATCHINFO_AVGLENGTH 'a' /* nCol values */
148652 #define FTS3_MATCHINFO_LENGTH 'l' /* nCol values */
148653 #define FTS3_MATCHINFO_LCS 's' /* nCol values */
148654 #define FTS3_MATCHINFO_HITS 'x' /* 3*nCol*nPhrase values */
148655 #define FTS3_MATCHINFO_LHITS 'y' /* nCol*nPhrase values */
148656
148657 /*
148658 ** The default value for the second argument to matchinfo().
148659 */
148660 #define FTS3_MATCHINFO_DEFAULT "pcx"
@@ -148912,10 +149432,55 @@
149432 }
149433 }
149434
149435 return rc;
149436 }
149437
149438 /*
149439 ** fts3ExprIterate() callback used to gather information for the matchinfo
149440 ** directive 'y'.
149441 */
149442 static int fts3ExprLHitsCb(
149443 Fts3Expr *pExpr, /* Phrase expression node */
149444 int iPhrase, /* Phrase number */
149445 void *pCtx /* Pointer to MatchInfo structure */
149446 ){
149447 MatchInfo *p = (MatchInfo *)pCtx;
149448 Fts3Table *pTab = (Fts3Table *)p->pCursor->base.pVtab;
149449 int rc = SQLITE_OK;
149450 int iStart = iPhrase * p->nCol;
149451 Fts3Expr *pEof; /* Ancestor node already at EOF */
149452
149453 /* This must be a phrase */
149454 assert( pExpr->pPhrase );
149455
149456 /* Initialize all output integers to zero. */
149457 memset(&p->aMatchinfo[iStart], 0, sizeof(u32) * p->nCol);
149458
149459 /* Check if this or any parent node is at EOF. If so, then all output
149460 ** values are zero. */
149461 for(pEof=pExpr; pEof && pEof->bEof==0; pEof=pEof->pParent);
149462
149463 if( pEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
149464 Fts3Phrase *pPhrase = pExpr->pPhrase;
149465 char *pIter = pPhrase->doclist.pList;
149466 int iCol = 0;
149467
149468 while( 1 ){
149469 int nHit = fts3ColumnlistCount(&pIter);
149470 if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){
149471 p->aMatchinfo[iStart + iCol] = (u32)nHit;
149472 }
149473 assert( *pIter==0x00 || *pIter==0x01 );
149474 if( *pIter!=0x01 ) break;
149475 pIter++;
149476 pIter += fts3GetVarint32(pIter, &iCol);
149477 }
149478 }
149479
149480 return rc;
149481 }
149482
149483 static int fts3MatchinfoCheck(
149484 Fts3Table *pTab,
149485 char cArg,
149486 char **pzErr
@@ -148925,14 +149490,15 @@
149490 || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4)
149491 || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4)
149492 || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize)
149493 || (cArg==FTS3_MATCHINFO_LCS)
149494 || (cArg==FTS3_MATCHINFO_HITS)
149495 || (cArg==FTS3_MATCHINFO_LHITS)
149496 ){
149497 return SQLITE_OK;
149498 }
149499 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
149500 return SQLITE_ERROR;
149501 }
149502
149503 static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
149504 int nVal; /* Number of integers output by cArg */
@@ -148947,10 +149513,14 @@
149513 case FTS3_MATCHINFO_AVGLENGTH:
149514 case FTS3_MATCHINFO_LENGTH:
149515 case FTS3_MATCHINFO_LCS:
149516 nVal = pInfo->nCol;
149517 break;
149518
149519 case FTS3_MATCHINFO_LHITS:
149520 nVal = pInfo->nCol * pInfo->nPhrase;
149521 break;
149522
149523 default:
149524 assert( cArg==FTS3_MATCHINFO_HITS );
149525 nVal = pInfo->nCol * pInfo->nPhrase * 3;
149526 break;
@@ -149201,10 +149771,14 @@
149771 rc = fts3ExprLoadDoclists(pCsr, 0, 0);
149772 if( rc==SQLITE_OK ){
149773 rc = fts3MatchinfoLcs(pCsr, pInfo);
149774 }
149775 break;
149776
149777 case FTS3_MATCHINFO_LHITS:
149778 (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLHitsCb, (void*)pInfo);
149779 break;
149780
149781 default: {
149782 Fts3Expr *pExpr;
149783 assert( zArg[i]==FTS3_MATCHINFO_HITS );
149784 pExpr = pCsr->pExpr;
@@ -153214,15 +153788,23 @@
153788 ** conflict-handling mode specified by the user.
153789 */
153790 if( nData>1 ){
153791 int ii;
153792
153793 /* Populate the cell.aCoord[] array. The first coordinate is azData[3].
153794 **
153795 ** NB: nData can only be less than nDim*2+3 if the rtree is mis-declared
153796 ** with "column" that are interpreted as table constraints.
153797 ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5));
153798 ** This problem was discovered after years of use, so we silently ignore
153799 ** these kinds of misdeclared tables to avoid breaking any legacy.
153800 */
153801 assert( nData<=(pRtree->nDim*2 + 3) );
153802
153803 #ifndef SQLITE_RTREE_INT_ONLY
153804 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
153805 for(ii=0; ii<nData-4; ii+=2){
153806 cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
153807 cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]);
153808 if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
153809 rc = SQLITE_CONSTRAINT;
153810 goto constraint;
@@ -153229,11 +153811,11 @@
153811 }
153812 }
153813 }else
153814 #endif
153815 {
153816 for(ii=0; ii<nData-4; ii+=2){
153817 cell.aCoord[ii].i = sqlite3_value_int(azData[ii+3]);
153818 cell.aCoord[ii+1].i = sqlite3_value_int(azData[ii+4]);
153819 if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){
153820 rc = SQLITE_CONSTRAINT;
153821 goto constraint;
@@ -154629,5 +155211,656 @@
155211
155212 #endif /* defined(SQLITE_ENABLE_ICU) */
155213 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
155214
155215 /************** End of fts3_icu.c ********************************************/
155216 /************** Begin file dbstat.c ******************************************/
155217 /*
155218 ** 2010 July 12
155219 **
155220 ** The author disclaims copyright to this source code. In place of
155221 ** a legal notice, here is a blessing:
155222 **
155223 ** May you do good and not evil.
155224 ** May you find forgiveness for yourself and forgive others.
155225 ** May you share freely, never taking more than you give.
155226 **
155227 ******************************************************************************
155228 **
155229 ** This file contains an implementation of the "dbstat" virtual table.
155230 **
155231 ** The dbstat virtual table is used to extract low-level formatting
155232 ** information from an SQLite database in order to implement the
155233 ** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script
155234 ** for an example implementation.
155235 */
155236
155237 #if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
155238 && !defined(SQLITE_OMIT_VIRTUALTABLE)
155239
155240 /*
155241 ** Page paths:
155242 **
155243 ** The value of the 'path' column describes the path taken from the
155244 ** root-node of the b-tree structure to each page. The value of the
155245 ** root-node path is '/'.
155246 **
155247 ** The value of the path for the left-most child page of the root of
155248 ** a b-tree is '/000/'. (Btrees store content ordered from left to right
155249 ** so the pages to the left have smaller keys than the pages to the right.)
155250 ** The next to left-most child of the root page is
155251 ** '/001', and so on, each sibling page identified by a 3-digit hex
155252 ** value. The children of the 451st left-most sibling have paths such
155253 ** as '/1c2/000/, '/1c2/001/' etc.
155254 **
155255 ** Overflow pages are specified by appending a '+' character and a
155256 ** six-digit hexadecimal value to the path to the cell they are linked
155257 ** from. For example, the three overflow pages in a chain linked from
155258 ** the left-most cell of the 450th child of the root page are identified
155259 ** by the paths:
155260 **
155261 ** '/1c2/000+000000' // First page in overflow chain
155262 ** '/1c2/000+000001' // Second page in overflow chain
155263 ** '/1c2/000+000002' // Third page in overflow chain
155264 **
155265 ** If the paths are sorted using the BINARY collation sequence, then
155266 ** the overflow pages associated with a cell will appear earlier in the
155267 ** sort-order than its child page:
155268 **
155269 ** '/1c2/000/' // Left-most child of 451st child of root
155270 */
155271 #define VTAB_SCHEMA \
155272 "CREATE TABLE xx( " \
155273 " name STRING, /* Name of table or index */" \
155274 " path INTEGER, /* Path to page from root */" \
155275 " pageno INTEGER, /* Page number */" \
155276 " pagetype STRING, /* 'internal', 'leaf' or 'overflow' */" \
155277 " ncell INTEGER, /* Cells on page (0 for overflow) */" \
155278 " payload INTEGER, /* Bytes of payload on this page */" \
155279 " unused INTEGER, /* Bytes of unused space on this page */" \
155280 " mx_payload INTEGER, /* Largest payload size of all cells */" \
155281 " pgoffset INTEGER, /* Offset of page in file */" \
155282 " pgsize INTEGER /* Size of the page */" \
155283 ");"
155284
155285
155286 typedef struct StatTable StatTable;
155287 typedef struct StatCursor StatCursor;
155288 typedef struct StatPage StatPage;
155289 typedef struct StatCell StatCell;
155290
155291 struct StatCell {
155292 int nLocal; /* Bytes of local payload */
155293 u32 iChildPg; /* Child node (or 0 if this is a leaf) */
155294 int nOvfl; /* Entries in aOvfl[] */
155295 u32 *aOvfl; /* Array of overflow page numbers */
155296 int nLastOvfl; /* Bytes of payload on final overflow page */
155297 int iOvfl; /* Iterates through aOvfl[] */
155298 };
155299
155300 struct StatPage {
155301 u32 iPgno;
155302 DbPage *pPg;
155303 int iCell;
155304
155305 char *zPath; /* Path to this page */
155306
155307 /* Variables populated by statDecodePage(): */
155308 u8 flags; /* Copy of flags byte */
155309 int nCell; /* Number of cells on page */
155310 int nUnused; /* Number of unused bytes on page */
155311 StatCell *aCell; /* Array of parsed cells */
155312 u32 iRightChildPg; /* Right-child page number (or 0) */
155313 int nMxPayload; /* Largest payload of any cell on this page */
155314 };
155315
155316 struct StatCursor {
155317 sqlite3_vtab_cursor base;
155318 sqlite3_stmt *pStmt; /* Iterates through set of root pages */
155319 int isEof; /* After pStmt has returned SQLITE_DONE */
155320
155321 StatPage aPage[32];
155322 int iPage; /* Current entry in aPage[] */
155323
155324 /* Values to return. */
155325 char *zName; /* Value of 'name' column */
155326 char *zPath; /* Value of 'path' column */
155327 u32 iPageno; /* Value of 'pageno' column */
155328 char *zPagetype; /* Value of 'pagetype' column */
155329 int nCell; /* Value of 'ncell' column */
155330 int nPayload; /* Value of 'payload' column */
155331 int nUnused; /* Value of 'unused' column */
155332 int nMxPayload; /* Value of 'mx_payload' column */
155333 i64 iOffset; /* Value of 'pgOffset' column */
155334 int szPage; /* Value of 'pgSize' column */
155335 };
155336
155337 struct StatTable {
155338 sqlite3_vtab base;
155339 sqlite3 *db;
155340 int iDb; /* Index of database to analyze */
155341 };
155342
155343 #ifndef get2byte
155344 # define get2byte(x) ((x)[0]<<8 | (x)[1])
155345 #endif
155346
155347 /*
155348 ** Connect to or create a statvfs virtual table.
155349 */
155350 static int statConnect(
155351 sqlite3 *db,
155352 void *pAux,
155353 int argc, const char *const*argv,
155354 sqlite3_vtab **ppVtab,
155355 char **pzErr
155356 ){
155357 StatTable *pTab = 0;
155358 int rc = SQLITE_OK;
155359 int iDb;
155360
155361 if( argc>=4 ){
155362 iDb = sqlite3FindDbName(db, argv[3]);
155363 if( iDb<0 ){
155364 *pzErr = sqlite3_mprintf("no such database: %s", argv[3]);
155365 return SQLITE_ERROR;
155366 }
155367 }else{
155368 iDb = 0;
155369 }
155370 rc = sqlite3_declare_vtab(db, VTAB_SCHEMA);
155371 if( rc==SQLITE_OK ){
155372 pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable));
155373 if( pTab==0 ) rc = SQLITE_NOMEM;
155374 }
155375
155376 assert( rc==SQLITE_OK || pTab==0 );
155377 if( rc==SQLITE_OK ){
155378 memset(pTab, 0, sizeof(StatTable));
155379 pTab->db = db;
155380 pTab->iDb = iDb;
155381 }
155382
155383 *ppVtab = (sqlite3_vtab*)pTab;
155384 return rc;
155385 }
155386
155387 /*
155388 ** Disconnect from or destroy a statvfs virtual table.
155389 */
155390 static int statDisconnect(sqlite3_vtab *pVtab){
155391 sqlite3_free(pVtab);
155392 return SQLITE_OK;
155393 }
155394
155395 /*
155396 ** There is no "best-index". This virtual table always does a linear
155397 ** scan of the binary VFS log file.
155398 */
155399 static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
155400
155401 /* Records are always returned in ascending order of (name, path).
155402 ** If this will satisfy the client, set the orderByConsumed flag so that
155403 ** SQLite does not do an external sort.
155404 */
155405 if( ( pIdxInfo->nOrderBy==1
155406 && pIdxInfo->aOrderBy[0].iColumn==0
155407 && pIdxInfo->aOrderBy[0].desc==0
155408 ) ||
155409 ( pIdxInfo->nOrderBy==2
155410 && pIdxInfo->aOrderBy[0].iColumn==0
155411 && pIdxInfo->aOrderBy[0].desc==0
155412 && pIdxInfo->aOrderBy[1].iColumn==1
155413 && pIdxInfo->aOrderBy[1].desc==0
155414 )
155415 ){
155416 pIdxInfo->orderByConsumed = 1;
155417 }
155418
155419 pIdxInfo->estimatedCost = 10.0;
155420 return SQLITE_OK;
155421 }
155422
155423 /*
155424 ** Open a new statvfs cursor.
155425 */
155426 static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
155427 StatTable *pTab = (StatTable *)pVTab;
155428 StatCursor *pCsr;
155429 int rc;
155430
155431 pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor));
155432 if( pCsr==0 ){
155433 rc = SQLITE_NOMEM;
155434 }else{
155435 char *zSql;
155436 memset(pCsr, 0, sizeof(StatCursor));
155437 pCsr->base.pVtab = pVTab;
155438
155439 zSql = sqlite3_mprintf(
155440 "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
155441 " UNION ALL "
155442 "SELECT name, rootpage, type"
155443 " FROM \"%w\".sqlite_master WHERE rootpage!=0"
155444 " ORDER BY name", pTab->db->aDb[pTab->iDb].zName);
155445 if( zSql==0 ){
155446 rc = SQLITE_NOMEM;
155447 }else{
155448 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
155449 sqlite3_free(zSql);
155450 }
155451 if( rc!=SQLITE_OK ){
155452 sqlite3_free(pCsr);
155453 pCsr = 0;
155454 }
155455 }
155456
155457 *ppCursor = (sqlite3_vtab_cursor *)pCsr;
155458 return rc;
155459 }
155460
155461 static void statClearPage(StatPage *p){
155462 int i;
155463 if( p->aCell ){
155464 for(i=0; i<p->nCell; i++){
155465 sqlite3_free(p->aCell[i].aOvfl);
155466 }
155467 sqlite3_free(p->aCell);
155468 }
155469 sqlite3PagerUnref(p->pPg);
155470 sqlite3_free(p->zPath);
155471 memset(p, 0, sizeof(StatPage));
155472 }
155473
155474 static void statResetCsr(StatCursor *pCsr){
155475 int i;
155476 sqlite3_reset(pCsr->pStmt);
155477 for(i=0; i<ArraySize(pCsr->aPage); i++){
155478 statClearPage(&pCsr->aPage[i]);
155479 }
155480 pCsr->iPage = 0;
155481 sqlite3_free(pCsr->zPath);
155482 pCsr->zPath = 0;
155483 }
155484
155485 /*
155486 ** Close a statvfs cursor.
155487 */
155488 static int statClose(sqlite3_vtab_cursor *pCursor){
155489 StatCursor *pCsr = (StatCursor *)pCursor;
155490 statResetCsr(pCsr);
155491 sqlite3_finalize(pCsr->pStmt);
155492 sqlite3_free(pCsr);
155493 return SQLITE_OK;
155494 }
155495
155496 static void getLocalPayload(
155497 int nUsable, /* Usable bytes per page */
155498 u8 flags, /* Page flags */
155499 int nTotal, /* Total record (payload) size */
155500 int *pnLocal /* OUT: Bytes stored locally */
155501 ){
155502 int nLocal;
155503 int nMinLocal;
155504 int nMaxLocal;
155505
155506 if( flags==0x0D ){ /* Table leaf node */
155507 nMinLocal = (nUsable - 12) * 32 / 255 - 23;
155508 nMaxLocal = nUsable - 35;
155509 }else{ /* Index interior and leaf nodes */
155510 nMinLocal = (nUsable - 12) * 32 / 255 - 23;
155511 nMaxLocal = (nUsable - 12) * 64 / 255 - 23;
155512 }
155513
155514 nLocal = nMinLocal + (nTotal - nMinLocal) % (nUsable - 4);
155515 if( nLocal>nMaxLocal ) nLocal = nMinLocal;
155516 *pnLocal = nLocal;
155517 }
155518
155519 static int statDecodePage(Btree *pBt, StatPage *p){
155520 int nUnused;
155521 int iOff;
155522 int nHdr;
155523 int isLeaf;
155524 int szPage;
155525
155526 u8 *aData = sqlite3PagerGetData(p->pPg);
155527 u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0];
155528
155529 p->flags = aHdr[0];
155530 p->nCell = get2byte(&aHdr[3]);
155531 p->nMxPayload = 0;
155532
155533 isLeaf = (p->flags==0x0A || p->flags==0x0D);
155534 nHdr = 12 - isLeaf*4 + (p->iPgno==1)*100;
155535
155536 nUnused = get2byte(&aHdr[5]) - nHdr - 2*p->nCell;
155537 nUnused += (int)aHdr[7];
155538 iOff = get2byte(&aHdr[1]);
155539 while( iOff ){
155540 nUnused += get2byte(&aData[iOff+2]);
155541 iOff = get2byte(&aData[iOff]);
155542 }
155543 p->nUnused = nUnused;
155544 p->iRightChildPg = isLeaf ? 0 : sqlite3Get4byte(&aHdr[8]);
155545 szPage = sqlite3BtreeGetPageSize(pBt);
155546
155547 if( p->nCell ){
155548 int i; /* Used to iterate through cells */
155549 int nUsable; /* Usable bytes per page */
155550
155551 sqlite3BtreeEnter(pBt);
155552 nUsable = szPage - sqlite3BtreeGetReserveNoMutex(pBt);
155553 sqlite3BtreeLeave(pBt);
155554 p->aCell = sqlite3_malloc64((p->nCell+1) * sizeof(StatCell));
155555 if( p->aCell==0 ) return SQLITE_NOMEM;
155556 memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell));
155557
155558 for(i=0; i<p->nCell; i++){
155559 StatCell *pCell = &p->aCell[i];
155560
155561 iOff = get2byte(&aData[nHdr+i*2]);
155562 if( !isLeaf ){
155563 pCell->iChildPg = sqlite3Get4byte(&aData[iOff]);
155564 iOff += 4;
155565 }
155566 if( p->flags==0x05 ){
155567 /* A table interior node. nPayload==0. */
155568 }else{
155569 u32 nPayload; /* Bytes of payload total (local+overflow) */
155570 int nLocal; /* Bytes of payload stored locally */
155571 iOff += getVarint32(&aData[iOff], nPayload);
155572 if( p->flags==0x0D ){
155573 u64 dummy;
155574 iOff += sqlite3GetVarint(&aData[iOff], &dummy);
155575 }
155576 if( nPayload>(u32)p->nMxPayload ) p->nMxPayload = nPayload;
155577 getLocalPayload(nUsable, p->flags, nPayload, &nLocal);
155578 pCell->nLocal = nLocal;
155579 assert( nLocal>=0 );
155580 assert( nPayload>=(u32)nLocal );
155581 assert( nLocal<=(nUsable-35) );
155582 if( nPayload>(u32)nLocal ){
155583 int j;
155584 int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4);
155585 pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4);
155586 pCell->nOvfl = nOvfl;
155587 pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl);
155588 if( pCell->aOvfl==0 ) return SQLITE_NOMEM;
155589 pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]);
155590 for(j=1; j<nOvfl; j++){
155591 int rc;
155592 u32 iPrev = pCell->aOvfl[j-1];
155593 DbPage *pPg = 0;
155594 rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg);
155595 if( rc!=SQLITE_OK ){
155596 assert( pPg==0 );
155597 return rc;
155598 }
155599 pCell->aOvfl[j] = sqlite3Get4byte(sqlite3PagerGetData(pPg));
155600 sqlite3PagerUnref(pPg);
155601 }
155602 }
155603 }
155604 }
155605 }
155606
155607 return SQLITE_OK;
155608 }
155609
155610 /*
155611 ** Populate the pCsr->iOffset and pCsr->szPage member variables. Based on
155612 ** the current value of pCsr->iPageno.
155613 */
155614 static void statSizeAndOffset(StatCursor *pCsr){
155615 StatTable *pTab = (StatTable *)((sqlite3_vtab_cursor *)pCsr)->pVtab;
155616 Btree *pBt = pTab->db->aDb[pTab->iDb].pBt;
155617 Pager *pPager = sqlite3BtreePager(pBt);
155618 sqlite3_file *fd;
155619 sqlite3_int64 x[2];
155620
155621 /* The default page size and offset */
155622 pCsr->szPage = sqlite3BtreeGetPageSize(pBt);
155623 pCsr->iOffset = (i64)pCsr->szPage * (pCsr->iPageno - 1);
155624
155625 /* If connected to a ZIPVFS backend, override the page size and
155626 ** offset with actual values obtained from ZIPVFS.
155627 */
155628 fd = sqlite3PagerFile(pPager);
155629 x[0] = pCsr->iPageno;
155630 if( fd->pMethods!=0 && sqlite3OsFileControl(fd, 230440, &x)==SQLITE_OK ){
155631 pCsr->iOffset = x[0];
155632 pCsr->szPage = (int)x[1];
155633 }
155634 }
155635
155636 /*
155637 ** Move a statvfs cursor to the next entry in the file.
155638 */
155639 static int statNext(sqlite3_vtab_cursor *pCursor){
155640 int rc;
155641 int nPayload;
155642 char *z;
155643 StatCursor *pCsr = (StatCursor *)pCursor;
155644 StatTable *pTab = (StatTable *)pCursor->pVtab;
155645 Btree *pBt = pTab->db->aDb[pTab->iDb].pBt;
155646 Pager *pPager = sqlite3BtreePager(pBt);
155647
155648 sqlite3_free(pCsr->zPath);
155649 pCsr->zPath = 0;
155650
155651 statNextRestart:
155652 if( pCsr->aPage[0].pPg==0 ){
155653 rc = sqlite3_step(pCsr->pStmt);
155654 if( rc==SQLITE_ROW ){
155655 int nPage;
155656 u32 iRoot = (u32)sqlite3_column_int64(pCsr->pStmt, 1);
155657 sqlite3PagerPagecount(pPager, &nPage);
155658 if( nPage==0 ){
155659 pCsr->isEof = 1;
155660 return sqlite3_reset(pCsr->pStmt);
155661 }
155662 rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg);
155663 pCsr->aPage[0].iPgno = iRoot;
155664 pCsr->aPage[0].iCell = 0;
155665 pCsr->aPage[0].zPath = z = sqlite3_mprintf("/");
155666 pCsr->iPage = 0;
155667 if( z==0 ) rc = SQLITE_NOMEM;
155668 }else{
155669 pCsr->isEof = 1;
155670 return sqlite3_reset(pCsr->pStmt);
155671 }
155672 }else{
155673
155674 /* Page p itself has already been visited. */
155675 StatPage *p = &pCsr->aPage[pCsr->iPage];
155676
155677 while( p->iCell<p->nCell ){
155678 StatCell *pCell = &p->aCell[p->iCell];
155679 if( pCell->iOvfl<pCell->nOvfl ){
155680 int nUsable;
155681 sqlite3BtreeEnter(pBt);
155682 nUsable = sqlite3BtreeGetPageSize(pBt) -
155683 sqlite3BtreeGetReserveNoMutex(pBt);
155684 sqlite3BtreeLeave(pBt);
155685 pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
155686 pCsr->iPageno = pCell->aOvfl[pCell->iOvfl];
155687 pCsr->zPagetype = "overflow";
155688 pCsr->nCell = 0;
155689 pCsr->nMxPayload = 0;
155690 pCsr->zPath = z = sqlite3_mprintf(
155691 "%s%.3x+%.6x", p->zPath, p->iCell, pCell->iOvfl
155692 );
155693 if( pCell->iOvfl<pCell->nOvfl-1 ){
155694 pCsr->nUnused = 0;
155695 pCsr->nPayload = nUsable - 4;
155696 }else{
155697 pCsr->nPayload = pCell->nLastOvfl;
155698 pCsr->nUnused = nUsable - 4 - pCsr->nPayload;
155699 }
155700 pCell->iOvfl++;
155701 statSizeAndOffset(pCsr);
155702 return z==0 ? SQLITE_NOMEM : SQLITE_OK;
155703 }
155704 if( p->iRightChildPg ) break;
155705 p->iCell++;
155706 }
155707
155708 if( !p->iRightChildPg || p->iCell>p->nCell ){
155709 statClearPage(p);
155710 if( pCsr->iPage==0 ) return statNext(pCursor);
155711 pCsr->iPage--;
155712 goto statNextRestart; /* Tail recursion */
155713 }
155714 pCsr->iPage++;
155715 assert( p==&pCsr->aPage[pCsr->iPage-1] );
155716
155717 if( p->iCell==p->nCell ){
155718 p[1].iPgno = p->iRightChildPg;
155719 }else{
155720 p[1].iPgno = p->aCell[p->iCell].iChildPg;
155721 }
155722 rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg);
155723 p[1].iCell = 0;
155724 p[1].zPath = z = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell);
155725 p->iCell++;
155726 if( z==0 ) rc = SQLITE_NOMEM;
155727 }
155728
155729
155730 /* Populate the StatCursor fields with the values to be returned
155731 ** by the xColumn() and xRowid() methods.
155732 */
155733 if( rc==SQLITE_OK ){
155734 int i;
155735 StatPage *p = &pCsr->aPage[pCsr->iPage];
155736 pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
155737 pCsr->iPageno = p->iPgno;
155738
155739 rc = statDecodePage(pBt, p);
155740 if( rc==SQLITE_OK ){
155741 statSizeAndOffset(pCsr);
155742
155743 switch( p->flags ){
155744 case 0x05: /* table internal */
155745 case 0x02: /* index internal */
155746 pCsr->zPagetype = "internal";
155747 break;
155748 case 0x0D: /* table leaf */
155749 case 0x0A: /* index leaf */
155750 pCsr->zPagetype = "leaf";
155751 break;
155752 default:
155753 pCsr->zPagetype = "corrupted";
155754 break;
155755 }
155756 pCsr->nCell = p->nCell;
155757 pCsr->nUnused = p->nUnused;
155758 pCsr->nMxPayload = p->nMxPayload;
155759 pCsr->zPath = z = sqlite3_mprintf("%s", p->zPath);
155760 if( z==0 ) rc = SQLITE_NOMEM;
155761 nPayload = 0;
155762 for(i=0; i<p->nCell; i++){
155763 nPayload += p->aCell[i].nLocal;
155764 }
155765 pCsr->nPayload = nPayload;
155766 }
155767 }
155768
155769 return rc;
155770 }
155771
155772 static int statEof(sqlite3_vtab_cursor *pCursor){
155773 StatCursor *pCsr = (StatCursor *)pCursor;
155774 return pCsr->isEof;
155775 }
155776
155777 static int statFilter(
155778 sqlite3_vtab_cursor *pCursor,
155779 int idxNum, const char *idxStr,
155780 int argc, sqlite3_value **argv
155781 ){
155782 StatCursor *pCsr = (StatCursor *)pCursor;
155783
155784 statResetCsr(pCsr);
155785 return statNext(pCursor);
155786 }
155787
155788 static int statColumn(
155789 sqlite3_vtab_cursor *pCursor,
155790 sqlite3_context *ctx,
155791 int i
155792 ){
155793 StatCursor *pCsr = (StatCursor *)pCursor;
155794 switch( i ){
155795 case 0: /* name */
155796 sqlite3_result_text(ctx, pCsr->zName, -1, SQLITE_TRANSIENT);
155797 break;
155798 case 1: /* path */
155799 sqlite3_result_text(ctx, pCsr->zPath, -1, SQLITE_TRANSIENT);
155800 break;
155801 case 2: /* pageno */
155802 sqlite3_result_int64(ctx, pCsr->iPageno);
155803 break;
155804 case 3: /* pagetype */
155805 sqlite3_result_text(ctx, pCsr->zPagetype, -1, SQLITE_STATIC);
155806 break;
155807 case 4: /* ncell */
155808 sqlite3_result_int(ctx, pCsr->nCell);
155809 break;
155810 case 5: /* payload */
155811 sqlite3_result_int(ctx, pCsr->nPayload);
155812 break;
155813 case 6: /* unused */
155814 sqlite3_result_int(ctx, pCsr->nUnused);
155815 break;
155816 case 7: /* mx_payload */
155817 sqlite3_result_int(ctx, pCsr->nMxPayload);
155818 break;
155819 case 8: /* pgoffset */
155820 sqlite3_result_int64(ctx, pCsr->iOffset);
155821 break;
155822 default: /* pgsize */
155823 assert( i==9 );
155824 sqlite3_result_int(ctx, pCsr->szPage);
155825 break;
155826 }
155827 return SQLITE_OK;
155828 }
155829
155830 static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
155831 StatCursor *pCsr = (StatCursor *)pCursor;
155832 *pRowid = pCsr->iPageno;
155833 return SQLITE_OK;
155834 }
155835
155836 /*
155837 ** Invoke this routine to register the "dbstat" virtual table module
155838 */
155839 SQLITE_API int SQLITE_STDCALL sqlite3_dbstat_register(sqlite3 *db){
155840 static sqlite3_module dbstat_module = {
155841 0, /* iVersion */
155842 statConnect, /* xCreate */
155843 statConnect, /* xConnect */
155844 statBestIndex, /* xBestIndex */
155845 statDisconnect, /* xDisconnect */
155846 statDisconnect, /* xDestroy */
155847 statOpen, /* xOpen - open a cursor */
155848 statClose, /* xClose - close a cursor */
155849 statFilter, /* xFilter - configure scan constraints */
155850 statNext, /* xNext - advance a cursor */
155851 statEof, /* xEof - check for end of scan */
155852 statColumn, /* xColumn - read data */
155853 statRowid, /* xRowid - read data */
155854 0, /* xUpdate */
155855 0, /* xBegin */
155856 0, /* xSync */
155857 0, /* xCommit */
155858 0, /* xRollback */
155859 0, /* xFindMethod */
155860 0, /* xRename */
155861 };
155862 return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
155863 }
155864 #endif /* SQLITE_ENABLE_DBSTAT_VTAB */
155865
155866 /************** End of dbstat.c **********************************************/
155867
+91 -15
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -109,13 +109,13 @@
109109
**
110110
** See also: [sqlite3_libversion()],
111111
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112112
** [sqlite_version()] and [sqlite_source_id()].
113113
*/
114
-#define SQLITE_VERSION "3.8.9"
115
-#define SQLITE_VERSION_NUMBER 3008009
116
-#define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09"
114
+#define SQLITE_VERSION "3.8.10.2"
115
+#define SQLITE_VERSION_NUMBER 3008010
116
+#define SQLITE_SOURCE_ID "2015-05-20 18:17:19 2ef4f3a5b1d1d0c4338f8243d40a2452cc1f7fe4"
117117
118118
/*
119119
** CAPI3REF: Run-Time Library Version Numbers
120120
** KEYWORDS: sqlite3_version, sqlite3_sourceid
121121
**
@@ -268,10 +268,11 @@
268268
# define double sqlite3_int64
269269
#endif
270270
271271
/*
272272
** CAPI3REF: Closing A Database Connection
273
+** DESTRUCTOR: sqlite3
273274
**
274275
** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
275276
** for the [sqlite3] object.
276277
** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
277278
** the [sqlite3] object is successfully destroyed and all associated
@@ -319,10 +320,11 @@
319320
*/
320321
typedef int (*sqlite3_callback)(void*,int,char**, char**);
321322
322323
/*
323324
** CAPI3REF: One-Step Query Execution Interface
325
+** METHOD: sqlite3
324326
**
325327
** The sqlite3_exec() interface is a convenience wrapper around
326328
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
327329
** that allows an application to run multiple statements of SQL
328330
** without having to use a lot of C code.
@@ -1376,10 +1378,11 @@
13761378
*/
13771379
SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
13781380
13791381
/*
13801382
** CAPI3REF: Configure database connections
1383
+** METHOD: sqlite3
13811384
**
13821385
** The sqlite3_db_config() interface is used to make configuration
13831386
** changes to a [database connection]. The interface is similar to
13841387
** [sqlite3_config()] except that the changes apply to a single
13851388
** [database connection] (specified in the first argument).
@@ -1873,19 +1876,21 @@
18731876
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
18741877
18751878
18761879
/*
18771880
** CAPI3REF: Enable Or Disable Extended Result Codes
1881
+** METHOD: sqlite3
18781882
**
18791883
** ^The sqlite3_extended_result_codes() routine enables or disables the
18801884
** [extended result codes] feature of SQLite. ^The extended result
18811885
** codes are disabled by default for historical compatibility.
18821886
*/
18831887
SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
18841888
18851889
/*
18861890
** CAPI3REF: Last Insert Rowid
1891
+** METHOD: sqlite3
18871892
**
18881893
** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
18891894
** has a unique 64-bit signed
18901895
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
18911896
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -1933,10 +1938,11 @@
19331938
*/
19341939
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
19351940
19361941
/*
19371942
** CAPI3REF: Count The Number Of Rows Modified
1943
+** METHOD: sqlite3
19381944
**
19391945
** ^This function returns the number of rows modified, inserted or
19401946
** deleted by the most recently completed INSERT, UPDATE or DELETE
19411947
** statement on the database connection specified by the only parameter.
19421948
** ^Executing any other type of SQL statement does not modify the value
@@ -1985,10 +1991,11 @@
19851991
*/
19861992
SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
19871993
19881994
/*
19891995
** CAPI3REF: Total Number Of Rows Modified
1996
+** METHOD: sqlite3
19901997
**
19911998
** ^This function returns the total number of rows inserted, modified or
19921999
** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
19932000
** since the database connection was opened, including those executed as
19942001
** part of trigger programs. ^Executing any other type of SQL statement
@@ -2008,10 +2015,11 @@
20082015
*/
20092016
SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
20102017
20112018
/*
20122019
** CAPI3REF: Interrupt A Long-Running Query
2020
+** METHOD: sqlite3
20132021
**
20142022
** ^This function causes any pending database operation to abort and
20152023
** return at its earliest opportunity. This routine is typically
20162024
** called in response to a user action such as pressing "Cancel"
20172025
** or Ctrl-C where the user wants a long query operation to halt
@@ -2084,10 +2092,11 @@
20842092
SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
20852093
20862094
/*
20872095
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
20882096
** KEYWORDS: {busy-handler callback} {busy handler}
2097
+** METHOD: sqlite3
20892098
**
20902099
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
20912100
** that might be invoked with argument P whenever
20922101
** an attempt is made to access a database table associated with
20932102
** [database connection] D when another thread
@@ -2143,10 +2152,11 @@
21432152
*/
21442153
SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
21452154
21462155
/*
21472156
** CAPI3REF: Set A Busy Timeout
2157
+** METHOD: sqlite3
21482158
**
21492159
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
21502160
** for a specified amount of time when a table is locked. ^The handler
21512161
** will sleep multiple times until at least "ms" milliseconds of sleeping
21522162
** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2165,10 +2175,11 @@
21652175
*/
21662176
SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
21672177
21682178
/*
21692179
** CAPI3REF: Convenience Routines For Running Queries
2180
+** METHOD: sqlite3
21702181
**
21712182
** This is a legacy interface that is preserved for backwards compatibility.
21722183
** Use of this interface is not recommended.
21732184
**
21742185
** Definition: A <b>result table</b> is memory data structure created by the
@@ -2500,10 +2511,11 @@
25002511
*/
25012512
SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
25022513
25032514
/*
25042515
** CAPI3REF: Compile-Time Authorization Callbacks
2516
+** METHOD: sqlite3
25052517
**
25062518
** ^This routine registers an authorizer callback with a particular
25072519
** [database connection], supplied in the first argument.
25082520
** ^The authorizer callback is invoked as SQL statements are being compiled
25092521
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2656,10 +2668,11 @@
26562668
#define SQLITE_COPY 0 /* No longer used */
26572669
#define SQLITE_RECURSIVE 33 /* NULL NULL */
26582670
26592671
/*
26602672
** CAPI3REF: Tracing And Profiling Functions
2673
+** METHOD: sqlite3
26612674
**
26622675
** These routines register callback functions that can be used for
26632676
** tracing and profiling the execution of SQL statements.
26642677
**
26652678
** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2688,10 +2701,11 @@
26882701
SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
26892702
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
26902703
26912704
/*
26922705
** CAPI3REF: Query Progress Callbacks
2706
+** METHOD: sqlite3
26932707
**
26942708
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
26952709
** function X to be invoked periodically during long running calls to
26962710
** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
26972711
** database connection D. An example use for this
@@ -2721,10 +2735,11 @@
27212735
*/
27222736
SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
27232737
27242738
/*
27252739
** CAPI3REF: Opening A New Database Connection
2740
+** CONSTRUCTOR: sqlite3
27262741
**
27272742
** ^These routines open an SQLite database file as specified by the
27282743
** filename argument. ^The filename argument is interpreted as UTF-8 for
27292744
** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
27302745
** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3006,10 +3021,11 @@
30063021
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
30073022
30083023
30093024
/*
30103025
** CAPI3REF: Error Codes And Messages
3026
+** METHOD: sqlite3
30113027
**
30123028
** ^If the most recent sqlite3_* API call associated with
30133029
** [database connection] D failed, then the sqlite3_errcode(D) interface
30143030
** returns the numeric [result code] or [extended result code] for that
30153031
** API call.
@@ -3051,37 +3067,38 @@
30513067
SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
30523068
SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
30533069
SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
30543070
30553071
/*
3056
-** CAPI3REF: SQL Statement Object
3072
+** CAPI3REF: Prepared Statement Object
30573073
** KEYWORDS: {prepared statement} {prepared statements}
30583074
**
3059
-** An instance of this object represents a single SQL statement.
3060
-** This object is variously known as a "prepared statement" or a
3061
-** "compiled SQL statement" or simply as a "statement".
3075
+** An instance of this object represents a single SQL statement that
3076
+** has been compiled into binary form and is ready to be evaluated.
30623077
**
3063
-** The life of a statement object goes something like this:
3078
+** Think of each SQL statement as a separate computer program. The
3079
+** original SQL text is source code. A prepared statement object
3080
+** is the compiled object code. All SQL must be converted into a
3081
+** prepared statement before it can be run.
3082
+**
3083
+** The life-cycle of a prepared statement object usually goes like this:
30643084
**
30653085
** <ol>
3066
-** <li> Create the object using [sqlite3_prepare_v2()] or a related
3067
-** function.
3068
-** <li> Bind values to [host parameters] using the sqlite3_bind_*()
3086
+** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
3087
+** <li> Bind values to [parameters] using the sqlite3_bind_*()
30693088
** interfaces.
30703089
** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3071
-** <li> Reset the statement using [sqlite3_reset()] then go back
3090
+** <li> Reset the prepared statement using [sqlite3_reset()] then go back
30723091
** to step 2. Do this zero or more times.
30733092
** <li> Destroy the object using [sqlite3_finalize()].
30743093
** </ol>
3075
-**
3076
-** Refer to documentation on individual methods above for additional
3077
-** information.
30783094
*/
30793095
typedef struct sqlite3_stmt sqlite3_stmt;
30803096
30813097
/*
30823098
** CAPI3REF: Run-time Limits
3099
+** METHOD: sqlite3
30833100
**
30843101
** ^(This interface allows the size of various constructs to be limited
30853102
** on a connection by connection basis. The first parameter is the
30863103
** [database connection] whose limit is to be set or queried. The
30873104
** second parameter is one of the [limit categories] that define a
@@ -3189,10 +3206,12 @@
31893206
#define SQLITE_LIMIT_WORKER_THREADS 11
31903207
31913208
/*
31923209
** CAPI3REF: Compiling An SQL Statement
31933210
** KEYWORDS: {SQL statement compiler}
3211
+** METHOD: sqlite3
3212
+** CONSTRUCTOR: sqlite3_stmt
31943213
**
31953214
** To execute an SQL query, it must first be compiled into a byte-code
31963215
** program using one of these routines.
31973216
**
31983217
** The first argument, "db", is a [database connection] obtained from a
@@ -3296,19 +3315,21 @@
32963315
const void **pzTail /* OUT: Pointer to unused portion of zSql */
32973316
);
32983317
32993318
/*
33003319
** CAPI3REF: Retrieving Statement SQL
3320
+** METHOD: sqlite3_stmt
33013321
**
33023322
** ^This interface can be used to retrieve a saved copy of the original
33033323
** SQL text used to create a [prepared statement] if that statement was
33043324
** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
33053325
*/
33063326
SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
33073327
33083328
/*
33093329
** CAPI3REF: Determine If An SQL Statement Writes The Database
3330
+** METHOD: sqlite3_stmt
33103331
**
33113332
** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
33123333
** and only if the [prepared statement] X makes no direct changes to
33133334
** the content of the database file.
33143335
**
@@ -3336,10 +3357,11 @@
33363357
*/
33373358
SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
33383359
33393360
/*
33403361
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3362
+** METHOD: sqlite3_stmt
33413363
**
33423364
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
33433365
** [prepared statement] S has been stepped at least once using
33443366
** [sqlite3_step(S)] but has not run to completion and/or has not
33453367
** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3410,10 +3432,11 @@
34103432
34113433
/*
34123434
** CAPI3REF: Binding Values To Prepared Statements
34133435
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
34143436
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3437
+** METHOD: sqlite3_stmt
34153438
**
34163439
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
34173440
** literals may be replaced by a [parameter] that matches one of following
34183441
** templates:
34193442
**
@@ -3528,10 +3551,11 @@
35283551
SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
35293552
SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
35303553
35313554
/*
35323555
** CAPI3REF: Number Of SQL Parameters
3556
+** METHOD: sqlite3_stmt
35333557
**
35343558
** ^This routine can be used to find the number of [SQL parameters]
35353559
** in a [prepared statement]. SQL parameters are tokens of the
35363560
** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
35373561
** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3548,10 +3572,11 @@
35483572
*/
35493573
SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
35503574
35513575
/*
35523576
** CAPI3REF: Name Of A Host Parameter
3577
+** METHOD: sqlite3_stmt
35533578
**
35543579
** ^The sqlite3_bind_parameter_name(P,N) interface returns
35553580
** the name of the N-th [SQL parameter] in the [prepared statement] P.
35563581
** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
35573582
** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3575,10 +3600,11 @@
35753600
*/
35763601
SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
35773602
35783603
/*
35793604
** CAPI3REF: Index Of A Parameter With A Given Name
3605
+** METHOD: sqlite3_stmt
35803606
**
35813607
** ^Return the index of an SQL parameter given its name. ^The
35823608
** index value returned is suitable for use as the second
35833609
** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
35843610
** is returned if no matching parameter is found. ^The parameter
@@ -3591,19 +3617,21 @@
35913617
*/
35923618
SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
35933619
35943620
/*
35953621
** CAPI3REF: Reset All Bindings On A Prepared Statement
3622
+** METHOD: sqlite3_stmt
35963623
**
35973624
** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
35983625
** the [sqlite3_bind_blob | bindings] on a [prepared statement].
35993626
** ^Use this routine to reset all host parameters to NULL.
36003627
*/
36013628
SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
36023629
36033630
/*
36043631
** CAPI3REF: Number Of Columns In A Result Set
3632
+** METHOD: sqlite3_stmt
36053633
**
36063634
** ^Return the number of columns in the result set returned by the
36073635
** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
36083636
** statement that does not return data (for example an [UPDATE]).
36093637
**
@@ -3611,10 +3639,11 @@
36113639
*/
36123640
SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
36133641
36143642
/*
36153643
** CAPI3REF: Column Names In A Result Set
3644
+** METHOD: sqlite3_stmt
36163645
**
36173646
** ^These routines return the name assigned to a particular column
36183647
** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
36193648
** interface returns a pointer to a zero-terminated UTF-8 string
36203649
** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3640,10 +3669,11 @@
36403669
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
36413670
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
36423671
36433672
/*
36443673
** CAPI3REF: Source Of Data In A Query Result
3674
+** METHOD: sqlite3_stmt
36453675
**
36463676
** ^These routines provide a means to determine the database, table, and
36473677
** table column that is the origin of a particular result column in
36483678
** [SELECT] statement.
36493679
** ^The name of the database or table or column can be returned as
@@ -3692,10 +3722,11 @@
36923722
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
36933723
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
36943724
36953725
/*
36963726
** CAPI3REF: Declared Datatype Of A Query Result
3727
+** METHOD: sqlite3_stmt
36973728
**
36983729
** ^(The first parameter is a [prepared statement].
36993730
** If this statement is a [SELECT] statement and the Nth column of the
37003731
** returned result set of that [SELECT] is a table column (not an
37013732
** expression or subquery) then the declared type of the table
@@ -3724,10 +3755,11 @@
37243755
SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
37253756
SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
37263757
37273758
/*
37283759
** CAPI3REF: Evaluate An SQL Statement
3760
+** METHOD: sqlite3_stmt
37293761
**
37303762
** After a [prepared statement] has been prepared using either
37313763
** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
37323764
** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
37333765
** must be called one or more times to evaluate the statement.
@@ -3803,10 +3835,11 @@
38033835
*/
38043836
SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
38053837
38063838
/*
38073839
** CAPI3REF: Number of columns in a result set
3840
+** METHOD: sqlite3_stmt
38083841
**
38093842
** ^The sqlite3_data_count(P) interface returns the number of columns in the
38103843
** current row of the result set of [prepared statement] P.
38113844
** ^If prepared statement P does not have results ready to return
38123845
** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -3856,10 +3889,11 @@
38563889
#define SQLITE3_TEXT 3
38573890
38583891
/*
38593892
** CAPI3REF: Result Values From A Query
38603893
** KEYWORDS: {column access functions}
3894
+** METHOD: sqlite3_stmt
38613895
**
38623896
** These routines form the "result set" interface.
38633897
**
38643898
** ^These routines return information about a single column of the current
38653899
** result row of a query. ^In every case the first argument is a pointer
@@ -4028,10 +4062,11 @@
40284062
SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
40294063
SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
40304064
40314065
/*
40324066
** CAPI3REF: Destroy A Prepared Statement Object
4067
+** DESTRUCTOR: sqlite3_stmt
40334068
**
40344069
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
40354070
** ^If the most recent evaluation of the statement encountered no errors
40364071
** or if the statement is never been evaluated, then sqlite3_finalize() returns
40374072
** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4055,10 +4090,11 @@
40554090
*/
40564091
SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
40574092
40584093
/*
40594094
** CAPI3REF: Reset A Prepared Statement Object
4095
+** METHOD: sqlite3_stmt
40604096
**
40614097
** The sqlite3_reset() function is called to reset a [prepared statement]
40624098
** object back to its initial state, ready to be re-executed.
40634099
** ^Any SQL statement variables that had values bound to them using
40644100
** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4084,10 +4120,11 @@
40844120
/*
40854121
** CAPI3REF: Create Or Redefine SQL Functions
40864122
** KEYWORDS: {function creation routines}
40874123
** KEYWORDS: {application-defined SQL function}
40884124
** KEYWORDS: {application-defined SQL functions}
4125
+** METHOD: sqlite3
40894126
**
40904127
** ^These functions (collectively known as "function creation routines")
40914128
** are used to add SQL functions or aggregates or to redefine the behavior
40924129
** of existing SQL functions or aggregates. The only differences between
40934130
** these routines are the text encoding expected for
@@ -4253,10 +4290,11 @@
42534290
void*,sqlite3_int64);
42544291
#endif
42554292
42564293
/*
42574294
** CAPI3REF: Obtaining SQL Function Parameter Values
4295
+** METHOD: sqlite3_value
42584296
**
42594297
** The C-language implementation of SQL functions and aggregates uses
42604298
** this set of interface routines to access the parameter values on
42614299
** the function or aggregate.
42624300
**
@@ -4311,10 +4349,11 @@
43114349
SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
43124350
SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
43134351
43144352
/*
43154353
** CAPI3REF: Obtain Aggregate Function Context
4354
+** METHOD: sqlite3_context
43164355
**
43174356
** Implementations of aggregate SQL functions use this
43184357
** routine to allocate memory for storing their state.
43194358
**
43204359
** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4355,10 +4394,11 @@
43554394
*/
43564395
SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
43574396
43584397
/*
43594398
** CAPI3REF: User Data For Functions
4399
+** METHOD: sqlite3_context
43604400
**
43614401
** ^The sqlite3_user_data() interface returns a copy of
43624402
** the pointer that was the pUserData parameter (the 5th parameter)
43634403
** of the [sqlite3_create_function()]
43644404
** and [sqlite3_create_function16()] routines that originally
@@ -4369,10 +4409,11 @@
43694409
*/
43704410
SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
43714411
43724412
/*
43734413
** CAPI3REF: Database Connection For Functions
4414
+** METHOD: sqlite3_context
43744415
**
43754416
** ^The sqlite3_context_db_handle() interface returns a copy of
43764417
** the pointer to the [database connection] (the 1st parameter)
43774418
** of the [sqlite3_create_function()]
43784419
** and [sqlite3_create_function16()] routines that originally
@@ -4380,10 +4421,11 @@
43804421
*/
43814422
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
43824423
43834424
/*
43844425
** CAPI3REF: Function Auxiliary Data
4426
+** METHOD: sqlite3_context
43854427
**
43864428
** These functions may be used by (non-aggregate) SQL functions to
43874429
** associate metadata with argument values. If the same value is passed to
43884430
** multiple invocations of the same SQL function during query execution, under
43894431
** some circumstances the associated metadata may be preserved. An example
@@ -4452,10 +4494,11 @@
44524494
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
44534495
#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
44544496
44554497
/*
44564498
** CAPI3REF: Setting The Result Of An SQL Function
4499
+** METHOD: sqlite3_context
44574500
**
44584501
** These routines are used by the xFunc or xFinal callbacks that
44594502
** implement SQL functions and aggregates. See
44604503
** [sqlite3_create_function()] and [sqlite3_create_function16()]
44614504
** for additional information.
@@ -4587,10 +4630,11 @@
45874630
SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
45884631
SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
45894632
45904633
/*
45914634
** CAPI3REF: Define New Collating Sequences
4635
+** METHOD: sqlite3
45924636
**
45934637
** ^These functions add, remove, or modify a [collation] associated
45944638
** with the [database connection] specified as the first argument.
45954639
**
45964640
** ^The name of the collation is a UTF-8 string
@@ -4689,10 +4733,11 @@
46894733
int(*xCompare)(void*,int,const void*,int,const void*)
46904734
);
46914735
46924736
/*
46934737
** CAPI3REF: Collation Needed Callbacks
4738
+** METHOD: sqlite3
46944739
**
46954740
** ^To avoid having to register all collation sequences before a database
46964741
** can be used, a single callback function may be registered with the
46974742
** [database connection] to be invoked whenever an undefined collation
46984743
** sequence is required.
@@ -4896,10 +4941,11 @@
48964941
SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
48974942
48984943
/*
48994944
** CAPI3REF: Test For Auto-Commit Mode
49004945
** KEYWORDS: {autocommit mode}
4946
+** METHOD: sqlite3
49014947
**
49024948
** ^The sqlite3_get_autocommit() interface returns non-zero or
49034949
** zero if the given database connection is or is not in autocommit mode,
49044950
** respectively. ^Autocommit mode is on by default.
49054951
** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -4918,10 +4964,11 @@
49184964
*/
49194965
SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
49204966
49214967
/*
49224968
** CAPI3REF: Find The Database Handle Of A Prepared Statement
4969
+** METHOD: sqlite3_stmt
49234970
**
49244971
** ^The sqlite3_db_handle interface returns the [database connection] handle
49254972
** to which a [prepared statement] belongs. ^The [database connection]
49264973
** returned by sqlite3_db_handle is the same [database connection]
49274974
** that was the first argument
@@ -4930,10 +4977,11 @@
49304977
*/
49314978
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
49324979
49334980
/*
49344981
** CAPI3REF: Return The Filename For A Database Connection
4982
+** METHOD: sqlite3
49354983
**
49364984
** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
49374985
** associated with database N of connection D. ^The main database file
49384986
** has the name "main". If there is no attached database N on the database
49394987
** connection D, or if database N is a temporary or in-memory database, then
@@ -4946,19 +4994,21 @@
49464994
*/
49474995
SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
49484996
49494997
/*
49504998
** CAPI3REF: Determine if a database is read-only
4999
+** METHOD: sqlite3
49515000
**
49525001
** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
49535002
** of connection D is read-only, 0 if it is read/write, or -1 if N is not
49545003
** the name of a database on connection D.
49555004
*/
49565005
SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
49575006
49585007
/*
49595008
** CAPI3REF: Find the next prepared statement
5009
+** METHOD: sqlite3
49605010
**
49615011
** ^This interface returns a pointer to the next [prepared statement] after
49625012
** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
49635013
** then this interface returns a pointer to the first prepared statement
49645014
** associated with the database connection pDb. ^If no prepared statement
@@ -4970,10 +5020,11 @@
49705020
*/
49715021
SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
49725022
49735023
/*
49745024
** CAPI3REF: Commit And Rollback Notification Callbacks
5025
+** METHOD: sqlite3
49755026
**
49765027
** ^The sqlite3_commit_hook() interface registers a callback
49775028
** function to be invoked whenever a transaction is [COMMIT | committed].
49785029
** ^Any callback set by a previous call to sqlite3_commit_hook()
49795030
** for the same database connection is overridden.
@@ -5019,10 +5070,11 @@
50195070
SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
50205071
SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
50215072
50225073
/*
50235074
** CAPI3REF: Data Change Notification Callbacks
5075
+** METHOD: sqlite3
50245076
**
50255077
** ^The sqlite3_update_hook() interface registers a callback function
50265078
** with the [database connection] identified by the first argument
50275079
** to be invoked whenever a row is updated, inserted or deleted in
50285080
** a rowid table.
@@ -5125,10 +5177,11 @@
51255177
*/
51265178
SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
51275179
51285180
/*
51295181
** CAPI3REF: Free Memory Used By A Database Connection
5182
+** METHOD: sqlite3
51305183
**
51315184
** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
51325185
** memory as possible from database connection D. Unlike the
51335186
** [sqlite3_release_memory()] interface, this interface is in effect even
51345187
** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5202,10 +5255,11 @@
52025255
SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
52035256
52045257
52055258
/*
52065259
** CAPI3REF: Extract Metadata About A Column Of A Table
5260
+** METHOD: sqlite3
52075261
**
52085262
** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
52095263
** information about column C of table T in database D
52105264
** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
52115265
** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5280,10 +5334,11 @@
52805334
int *pAutoinc /* OUTPUT: True if column is auto-increment */
52815335
);
52825336
52835337
/*
52845338
** CAPI3REF: Load An Extension
5339
+** METHOD: sqlite3
52855340
**
52865341
** ^This interface loads an SQLite extension library from the named file.
52875342
**
52885343
** ^The sqlite3_load_extension() interface attempts to load an
52895344
** [SQLite extension] library contained in the file zFile. If
@@ -5321,10 +5376,11 @@
53215376
char **pzErrMsg /* Put error message here if not 0 */
53225377
);
53235378
53245379
/*
53255380
** CAPI3REF: Enable Or Disable Extension Loading
5381
+** METHOD: sqlite3
53265382
**
53275383
** ^So as not to open security holes in older applications that are
53285384
** unprepared to deal with [extension loading], and as a means of disabling
53295385
** [extension loading] while evaluating user-entered SQL, the following API
53305386
** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5570,10 +5626,11 @@
55705626
#define SQLITE_INDEX_CONSTRAINT_GE 32
55715627
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
55725628
55735629
/*
55745630
** CAPI3REF: Register A Virtual Table Implementation
5631
+** METHOD: sqlite3
55755632
**
55765633
** ^These routines are used to register a new [virtual table module] name.
55775634
** ^Module names must be registered before
55785635
** creating a new [virtual table] using the module and before using a
55795636
** preexisting [virtual table] for the module.
@@ -5666,10 +5723,11 @@
56665723
*/
56675724
SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
56685725
56695726
/*
56705727
** CAPI3REF: Overload A Function For A Virtual Table
5728
+** METHOD: sqlite3
56715729
**
56725730
** ^(Virtual tables can provide alternative implementations of functions
56735731
** using the [xFindFunction] method of the [virtual table module].
56745732
** But global versions of those functions
56755733
** must exist in order to be overloaded.)^
@@ -5708,10 +5766,12 @@
57085766
*/
57095767
typedef struct sqlite3_blob sqlite3_blob;
57105768
57115769
/*
57125770
** CAPI3REF: Open A BLOB For Incremental I/O
5771
+** METHOD: sqlite3
5772
+** CONSTRUCTOR: sqlite3_blob
57135773
**
57145774
** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
57155775
** in row iRow, column zColumn, table zTable in database zDb;
57165776
** in other words, the same BLOB that would be selected by:
57175777
**
@@ -5789,10 +5849,11 @@
57895849
sqlite3_blob **ppBlob
57905850
);
57915851
57925852
/*
57935853
** CAPI3REF: Move a BLOB Handle to a New Row
5854
+** METHOD: sqlite3_blob
57945855
**
57955856
** ^This function is used to move an existing blob handle so that it points
57965857
** to a different row of the same database table. ^The new row is identified
57975858
** by the rowid value passed as the second argument. Only the row can be
57985859
** changed. ^The database, table and column on which the blob handle is open
@@ -5813,10 +5874,11 @@
58135874
*/
58145875
SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
58155876
58165877
/*
58175878
** CAPI3REF: Close A BLOB Handle
5879
+** DESTRUCTOR: sqlite3_blob
58185880
**
58195881
** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
58205882
** unconditionally. Even if this routine returns an error code, the
58215883
** handle is still closed.)^
58225884
**
@@ -5835,10 +5897,11 @@
58355897
*/
58365898
SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
58375899
58385900
/*
58395901
** CAPI3REF: Return The Size Of An Open BLOB
5902
+** METHOD: sqlite3_blob
58405903
**
58415904
** ^Returns the size in bytes of the BLOB accessible via the
58425905
** successfully opened [BLOB handle] in its only argument. ^The
58435906
** incremental blob I/O routines can only read or overwriting existing
58445907
** blob content; they cannot change the size of a blob.
@@ -5850,10 +5913,11 @@
58505913
*/
58515914
SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
58525915
58535916
/*
58545917
** CAPI3REF: Read Data From A BLOB Incrementally
5918
+** METHOD: sqlite3_blob
58555919
**
58565920
** ^(This function is used to read data from an open [BLOB handle] into a
58575921
** caller-supplied buffer. N bytes of data are copied into buffer Z
58585922
** from the open BLOB, starting at offset iOffset.)^
58595923
**
@@ -5878,10 +5942,11 @@
58785942
*/
58795943
SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
58805944
58815945
/*
58825946
** CAPI3REF: Write Data Into A BLOB Incrementally
5947
+** METHOD: sqlite3_blob
58835948
**
58845949
** ^(This function is used to write data into an open [BLOB handle] from a
58855950
** caller-supplied buffer. N bytes of data are copied from the buffer Z
58865951
** into the open BLOB, starting at offset iOffset.)^
58875952
**
@@ -6205,10 +6270,11 @@
62056270
#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
62066271
#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
62076272
62086273
/*
62096274
** CAPI3REF: Retrieve the mutex for a database connection
6275
+** METHOD: sqlite3
62106276
**
62116277
** ^This interface returns a pointer the [sqlite3_mutex] object that
62126278
** serializes access to the [database connection] given in the argument
62136279
** when the [threading mode] is Serialized.
62146280
** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6216,10 +6282,11 @@
62166282
*/
62176283
SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
62186284
62196285
/*
62206286
** CAPI3REF: Low-Level Control Of Database Files
6287
+** METHOD: sqlite3
62216288
**
62226289
** ^The [sqlite3_file_control()] interface makes a direct call to the
62236290
** xFileControl method for the [sqlite3_io_methods] object associated
62246291
** with a particular database identified by the second argument. ^The
62256292
** name of the database is "main" for the main database or "temp" for the
@@ -6432,10 +6499,11 @@
64326499
#define SQLITE_STATUS_SCRATCH_SIZE 8
64336500
#define SQLITE_STATUS_MALLOC_COUNT 9
64346501
64356502
/*
64366503
** CAPI3REF: Database Connection Status
6504
+** METHOD: sqlite3
64376505
**
64386506
** ^This interface is used to retrieve runtime status information
64396507
** about a single [database connection]. ^The first argument is the
64406508
** database connection object to be interrogated. ^The second argument
64416509
** is an integer constant, taken from the set of
@@ -6560,10 +6628,11 @@
65606628
#define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
65616629
65626630
65636631
/*
65646632
** CAPI3REF: Prepared Statement Status
6633
+** METHOD: sqlite3_stmt
65656634
**
65666635
** ^(Each prepared statement maintains various
65676636
** [SQLITE_STMTSTATUS counters] that measure the number
65686637
** of times it has performed specific operations.)^ These counters can
65696638
** be used to monitor the performance characteristics of the prepared
@@ -7063,10 +7132,11 @@
70637132
SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
70647133
SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
70657134
70667135
/*
70677136
** CAPI3REF: Unlock Notification
7137
+** METHOD: sqlite3
70687138
**
70697139
** ^When running in shared-cache mode, a database operation may fail with
70707140
** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
70717141
** individual tables within the shared-cache cannot be obtained. See
70727142
** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7233,10 +7303,11 @@
72337303
*/
72347304
SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
72357305
72367306
/*
72377307
** CAPI3REF: Write-Ahead Log Commit Hook
7308
+** METHOD: sqlite3
72387309
**
72397310
** ^The [sqlite3_wal_hook()] function is used to register a callback that
72407311
** is invoked each time data is committed to a database in wal mode.
72417312
**
72427313
** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7272,10 +7343,11 @@
72727343
void*
72737344
);
72747345
72757346
/*
72767347
** CAPI3REF: Configure an auto-checkpoint
7348
+** METHOD: sqlite3
72777349
**
72787350
** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
72797351
** [sqlite3_wal_hook()] that causes any database on [database connection] D
72807352
** to automatically [checkpoint]
72817353
** after committing a transaction if there are N or
@@ -7302,10 +7374,11 @@
73027374
*/
73037375
SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
73047376
73057377
/*
73067378
** CAPI3REF: Checkpoint a database
7379
+** METHOD: sqlite3
73077380
**
73087381
** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
73097382
** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
73107383
**
73117384
** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7323,10 +7396,11 @@
73237396
*/
73247397
SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
73257398
73267399
/*
73277400
** CAPI3REF: Checkpoint a database
7401
+** METHOD: sqlite3
73287402
**
73297403
** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
73307404
** operation on database X of [database connection] D in mode M. Status
73317405
** information is written back into integers pointed to by L and C.)^
73327406
** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7577,10 +7651,11 @@
75777651
#define SQLITE_SCANSTAT_EXPLAIN 4
75787652
#define SQLITE_SCANSTAT_SELECTID 5
75797653
75807654
/*
75817655
** CAPI3REF: Prepared Statement Scan Status
7656
+** METHOD: sqlite3_stmt
75827657
**
75837658
** This interface returns information about the predicted and measured
75847659
** performance for pStmt. Advanced applications can use this
75857660
** interface to compare the predicted and the measured performance and
75867661
** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7614,10 +7689,11 @@
76147689
void *pOut /* Result written here */
76157690
);
76167691
76177692
/*
76187693
** CAPI3REF: Zero Scan-Status Counters
7694
+** METHOD: sqlite3_stmt
76197695
**
76207696
** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
76217697
**
76227698
** This API is only available if the library is built with pre-processor
76237699
** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
76247700
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -109,13 +109,13 @@
109 **
110 ** See also: [sqlite3_libversion()],
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.8.9"
115 #define SQLITE_VERSION_NUMBER 3008009
116 #define SQLITE_SOURCE_ID "2015-04-08 12:16:33 8a8ffc862e96f57aa698f93de10dee28e69f6e09"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -268,10 +268,11 @@
268 # define double sqlite3_int64
269 #endif
270
271 /*
272 ** CAPI3REF: Closing A Database Connection
 
273 **
274 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
275 ** for the [sqlite3] object.
276 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
277 ** the [sqlite3] object is successfully destroyed and all associated
@@ -319,10 +320,11 @@
319 */
320 typedef int (*sqlite3_callback)(void*,int,char**, char**);
321
322 /*
323 ** CAPI3REF: One-Step Query Execution Interface
 
324 **
325 ** The sqlite3_exec() interface is a convenience wrapper around
326 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
327 ** that allows an application to run multiple statements of SQL
328 ** without having to use a lot of C code.
@@ -1376,10 +1378,11 @@
1376 */
1377 SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
1378
1379 /*
1380 ** CAPI3REF: Configure database connections
 
1381 **
1382 ** The sqlite3_db_config() interface is used to make configuration
1383 ** changes to a [database connection]. The interface is similar to
1384 ** [sqlite3_config()] except that the changes apply to a single
1385 ** [database connection] (specified in the first argument).
@@ -1873,19 +1876,21 @@
1873 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1874
1875
1876 /*
1877 ** CAPI3REF: Enable Or Disable Extended Result Codes
 
1878 **
1879 ** ^The sqlite3_extended_result_codes() routine enables or disables the
1880 ** [extended result codes] feature of SQLite. ^The extended result
1881 ** codes are disabled by default for historical compatibility.
1882 */
1883 SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
1884
1885 /*
1886 ** CAPI3REF: Last Insert Rowid
 
1887 **
1888 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
1889 ** has a unique 64-bit signed
1890 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
1891 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -1933,10 +1938,11 @@
1933 */
1934 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
1935
1936 /*
1937 ** CAPI3REF: Count The Number Of Rows Modified
 
1938 **
1939 ** ^This function returns the number of rows modified, inserted or
1940 ** deleted by the most recently completed INSERT, UPDATE or DELETE
1941 ** statement on the database connection specified by the only parameter.
1942 ** ^Executing any other type of SQL statement does not modify the value
@@ -1985,10 +1991,11 @@
1985 */
1986 SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
1987
1988 /*
1989 ** CAPI3REF: Total Number Of Rows Modified
 
1990 **
1991 ** ^This function returns the total number of rows inserted, modified or
1992 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
1993 ** since the database connection was opened, including those executed as
1994 ** part of trigger programs. ^Executing any other type of SQL statement
@@ -2008,10 +2015,11 @@
2008 */
2009 SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
2010
2011 /*
2012 ** CAPI3REF: Interrupt A Long-Running Query
 
2013 **
2014 ** ^This function causes any pending database operation to abort and
2015 ** return at its earliest opportunity. This routine is typically
2016 ** called in response to a user action such as pressing "Cancel"
2017 ** or Ctrl-C where the user wants a long query operation to halt
@@ -2084,10 +2092,11 @@
2084 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
2085
2086 /*
2087 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2088 ** KEYWORDS: {busy-handler callback} {busy handler}
 
2089 **
2090 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2091 ** that might be invoked with argument P whenever
2092 ** an attempt is made to access a database table associated with
2093 ** [database connection] D when another thread
@@ -2143,10 +2152,11 @@
2143 */
2144 SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
2145
2146 /*
2147 ** CAPI3REF: Set A Busy Timeout
 
2148 **
2149 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2150 ** for a specified amount of time when a table is locked. ^The handler
2151 ** will sleep multiple times until at least "ms" milliseconds of sleeping
2152 ** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2165,10 +2175,11 @@
2165 */
2166 SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
2167
2168 /*
2169 ** CAPI3REF: Convenience Routines For Running Queries
 
2170 **
2171 ** This is a legacy interface that is preserved for backwards compatibility.
2172 ** Use of this interface is not recommended.
2173 **
2174 ** Definition: A <b>result table</b> is memory data structure created by the
@@ -2500,10 +2511,11 @@
2500 */
2501 SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
2502
2503 /*
2504 ** CAPI3REF: Compile-Time Authorization Callbacks
 
2505 **
2506 ** ^This routine registers an authorizer callback with a particular
2507 ** [database connection], supplied in the first argument.
2508 ** ^The authorizer callback is invoked as SQL statements are being compiled
2509 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2656,10 +2668,11 @@
2656 #define SQLITE_COPY 0 /* No longer used */
2657 #define SQLITE_RECURSIVE 33 /* NULL NULL */
2658
2659 /*
2660 ** CAPI3REF: Tracing And Profiling Functions
 
2661 **
2662 ** These routines register callback functions that can be used for
2663 ** tracing and profiling the execution of SQL statements.
2664 **
2665 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2688,10 +2701,11 @@
2688 SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
2689 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2690
2691 /*
2692 ** CAPI3REF: Query Progress Callbacks
 
2693 **
2694 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2695 ** function X to be invoked periodically during long running calls to
2696 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2697 ** database connection D. An example use for this
@@ -2721,10 +2735,11 @@
2721 */
2722 SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2723
2724 /*
2725 ** CAPI3REF: Opening A New Database Connection
 
2726 **
2727 ** ^These routines open an SQLite database file as specified by the
2728 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2729 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2730 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3006,10 +3021,11 @@
3006 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3007
3008
3009 /*
3010 ** CAPI3REF: Error Codes And Messages
 
3011 **
3012 ** ^If the most recent sqlite3_* API call associated with
3013 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3014 ** returns the numeric [result code] or [extended result code] for that
3015 ** API call.
@@ -3051,37 +3067,38 @@
3051 SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
3052 SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
3053 SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
3054
3055 /*
3056 ** CAPI3REF: SQL Statement Object
3057 ** KEYWORDS: {prepared statement} {prepared statements}
3058 **
3059 ** An instance of this object represents a single SQL statement.
3060 ** This object is variously known as a "prepared statement" or a
3061 ** "compiled SQL statement" or simply as a "statement".
3062 **
3063 ** The life of a statement object goes something like this:
 
 
 
 
 
3064 **
3065 ** <ol>
3066 ** <li> Create the object using [sqlite3_prepare_v2()] or a related
3067 ** function.
3068 ** <li> Bind values to [host parameters] using the sqlite3_bind_*()
3069 ** interfaces.
3070 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3071 ** <li> Reset the statement using [sqlite3_reset()] then go back
3072 ** to step 2. Do this zero or more times.
3073 ** <li> Destroy the object using [sqlite3_finalize()].
3074 ** </ol>
3075 **
3076 ** Refer to documentation on individual methods above for additional
3077 ** information.
3078 */
3079 typedef struct sqlite3_stmt sqlite3_stmt;
3080
3081 /*
3082 ** CAPI3REF: Run-time Limits
 
3083 **
3084 ** ^(This interface allows the size of various constructs to be limited
3085 ** on a connection by connection basis. The first parameter is the
3086 ** [database connection] whose limit is to be set or queried. The
3087 ** second parameter is one of the [limit categories] that define a
@@ -3189,10 +3206,12 @@
3189 #define SQLITE_LIMIT_WORKER_THREADS 11
3190
3191 /*
3192 ** CAPI3REF: Compiling An SQL Statement
3193 ** KEYWORDS: {SQL statement compiler}
 
 
3194 **
3195 ** To execute an SQL query, it must first be compiled into a byte-code
3196 ** program using one of these routines.
3197 **
3198 ** The first argument, "db", is a [database connection] obtained from a
@@ -3296,19 +3315,21 @@
3296 const void **pzTail /* OUT: Pointer to unused portion of zSql */
3297 );
3298
3299 /*
3300 ** CAPI3REF: Retrieving Statement SQL
 
3301 **
3302 ** ^This interface can be used to retrieve a saved copy of the original
3303 ** SQL text used to create a [prepared statement] if that statement was
3304 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
3305 */
3306 SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
3307
3308 /*
3309 ** CAPI3REF: Determine If An SQL Statement Writes The Database
 
3310 **
3311 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3312 ** and only if the [prepared statement] X makes no direct changes to
3313 ** the content of the database file.
3314 **
@@ -3336,10 +3357,11 @@
3336 */
3337 SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3338
3339 /*
3340 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
 
3341 **
3342 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3343 ** [prepared statement] S has been stepped at least once using
3344 ** [sqlite3_step(S)] but has not run to completion and/or has not
3345 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3410,10 +3432,11 @@
3410
3411 /*
3412 ** CAPI3REF: Binding Values To Prepared Statements
3413 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3414 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
 
3415 **
3416 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3417 ** literals may be replaced by a [parameter] that matches one of following
3418 ** templates:
3419 **
@@ -3528,10 +3551,11 @@
3528 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3529 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3530
3531 /*
3532 ** CAPI3REF: Number Of SQL Parameters
 
3533 **
3534 ** ^This routine can be used to find the number of [SQL parameters]
3535 ** in a [prepared statement]. SQL parameters are tokens of the
3536 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
3537 ** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3548,10 +3572,11 @@
3548 */
3549 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
3550
3551 /*
3552 ** CAPI3REF: Name Of A Host Parameter
 
3553 **
3554 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
3555 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
3556 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3557 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3575,10 +3600,11 @@
3575 */
3576 SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
3577
3578 /*
3579 ** CAPI3REF: Index Of A Parameter With A Given Name
 
3580 **
3581 ** ^Return the index of an SQL parameter given its name. ^The
3582 ** index value returned is suitable for use as the second
3583 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
3584 ** is returned if no matching parameter is found. ^The parameter
@@ -3591,19 +3617,21 @@
3591 */
3592 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
3593
3594 /*
3595 ** CAPI3REF: Reset All Bindings On A Prepared Statement
 
3596 **
3597 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
3598 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3599 ** ^Use this routine to reset all host parameters to NULL.
3600 */
3601 SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
3602
3603 /*
3604 ** CAPI3REF: Number Of Columns In A Result Set
 
3605 **
3606 ** ^Return the number of columns in the result set returned by the
3607 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3608 ** statement that does not return data (for example an [UPDATE]).
3609 **
@@ -3611,10 +3639,11 @@
3611 */
3612 SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
3613
3614 /*
3615 ** CAPI3REF: Column Names In A Result Set
 
3616 **
3617 ** ^These routines return the name assigned to a particular column
3618 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
3619 ** interface returns a pointer to a zero-terminated UTF-8 string
3620 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3640,10 +3669,11 @@
3640 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
3641 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
3642
3643 /*
3644 ** CAPI3REF: Source Of Data In A Query Result
 
3645 **
3646 ** ^These routines provide a means to determine the database, table, and
3647 ** table column that is the origin of a particular result column in
3648 ** [SELECT] statement.
3649 ** ^The name of the database or table or column can be returned as
@@ -3692,10 +3722,11 @@
3692 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
3693 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
3694
3695 /*
3696 ** CAPI3REF: Declared Datatype Of A Query Result
 
3697 **
3698 ** ^(The first parameter is a [prepared statement].
3699 ** If this statement is a [SELECT] statement and the Nth column of the
3700 ** returned result set of that [SELECT] is a table column (not an
3701 ** expression or subquery) then the declared type of the table
@@ -3724,10 +3755,11 @@
3724 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
3725 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
3726
3727 /*
3728 ** CAPI3REF: Evaluate An SQL Statement
 
3729 **
3730 ** After a [prepared statement] has been prepared using either
3731 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
3732 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
3733 ** must be called one or more times to evaluate the statement.
@@ -3803,10 +3835,11 @@
3803 */
3804 SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
3805
3806 /*
3807 ** CAPI3REF: Number of columns in a result set
 
3808 **
3809 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
3810 ** current row of the result set of [prepared statement] P.
3811 ** ^If prepared statement P does not have results ready to return
3812 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -3856,10 +3889,11 @@
3856 #define SQLITE3_TEXT 3
3857
3858 /*
3859 ** CAPI3REF: Result Values From A Query
3860 ** KEYWORDS: {column access functions}
 
3861 **
3862 ** These routines form the "result set" interface.
3863 **
3864 ** ^These routines return information about a single column of the current
3865 ** result row of a query. ^In every case the first argument is a pointer
@@ -4028,10 +4062,11 @@
4028 SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
4029 SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
4030
4031 /*
4032 ** CAPI3REF: Destroy A Prepared Statement Object
 
4033 **
4034 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
4035 ** ^If the most recent evaluation of the statement encountered no errors
4036 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
4037 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4055,10 +4090,11 @@
4055 */
4056 SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
4057
4058 /*
4059 ** CAPI3REF: Reset A Prepared Statement Object
 
4060 **
4061 ** The sqlite3_reset() function is called to reset a [prepared statement]
4062 ** object back to its initial state, ready to be re-executed.
4063 ** ^Any SQL statement variables that had values bound to them using
4064 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4084,10 +4120,11 @@
4084 /*
4085 ** CAPI3REF: Create Or Redefine SQL Functions
4086 ** KEYWORDS: {function creation routines}
4087 ** KEYWORDS: {application-defined SQL function}
4088 ** KEYWORDS: {application-defined SQL functions}
 
4089 **
4090 ** ^These functions (collectively known as "function creation routines")
4091 ** are used to add SQL functions or aggregates or to redefine the behavior
4092 ** of existing SQL functions or aggregates. The only differences between
4093 ** these routines are the text encoding expected for
@@ -4253,10 +4290,11 @@
4253 void*,sqlite3_int64);
4254 #endif
4255
4256 /*
4257 ** CAPI3REF: Obtaining SQL Function Parameter Values
 
4258 **
4259 ** The C-language implementation of SQL functions and aggregates uses
4260 ** this set of interface routines to access the parameter values on
4261 ** the function or aggregate.
4262 **
@@ -4311,10 +4349,11 @@
4311 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4312 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4313
4314 /*
4315 ** CAPI3REF: Obtain Aggregate Function Context
 
4316 **
4317 ** Implementations of aggregate SQL functions use this
4318 ** routine to allocate memory for storing their state.
4319 **
4320 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4355,10 +4394,11 @@
4355 */
4356 SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
4357
4358 /*
4359 ** CAPI3REF: User Data For Functions
 
4360 **
4361 ** ^The sqlite3_user_data() interface returns a copy of
4362 ** the pointer that was the pUserData parameter (the 5th parameter)
4363 ** of the [sqlite3_create_function()]
4364 ** and [sqlite3_create_function16()] routines that originally
@@ -4369,10 +4409,11 @@
4369 */
4370 SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
4371
4372 /*
4373 ** CAPI3REF: Database Connection For Functions
 
4374 **
4375 ** ^The sqlite3_context_db_handle() interface returns a copy of
4376 ** the pointer to the [database connection] (the 1st parameter)
4377 ** of the [sqlite3_create_function()]
4378 ** and [sqlite3_create_function16()] routines that originally
@@ -4380,10 +4421,11 @@
4380 */
4381 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
4382
4383 /*
4384 ** CAPI3REF: Function Auxiliary Data
 
4385 **
4386 ** These functions may be used by (non-aggregate) SQL functions to
4387 ** associate metadata with argument values. If the same value is passed to
4388 ** multiple invocations of the same SQL function during query execution, under
4389 ** some circumstances the associated metadata may be preserved. An example
@@ -4452,10 +4494,11 @@
4452 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
4453 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
4454
4455 /*
4456 ** CAPI3REF: Setting The Result Of An SQL Function
 
4457 **
4458 ** These routines are used by the xFunc or xFinal callbacks that
4459 ** implement SQL functions and aggregates. See
4460 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
4461 ** for additional information.
@@ -4587,10 +4630,11 @@
4587 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4588 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4589
4590 /*
4591 ** CAPI3REF: Define New Collating Sequences
 
4592 **
4593 ** ^These functions add, remove, or modify a [collation] associated
4594 ** with the [database connection] specified as the first argument.
4595 **
4596 ** ^The name of the collation is a UTF-8 string
@@ -4689,10 +4733,11 @@
4689 int(*xCompare)(void*,int,const void*,int,const void*)
4690 );
4691
4692 /*
4693 ** CAPI3REF: Collation Needed Callbacks
 
4694 **
4695 ** ^To avoid having to register all collation sequences before a database
4696 ** can be used, a single callback function may be registered with the
4697 ** [database connection] to be invoked whenever an undefined collation
4698 ** sequence is required.
@@ -4896,10 +4941,11 @@
4896 SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
4897
4898 /*
4899 ** CAPI3REF: Test For Auto-Commit Mode
4900 ** KEYWORDS: {autocommit mode}
 
4901 **
4902 ** ^The sqlite3_get_autocommit() interface returns non-zero or
4903 ** zero if the given database connection is or is not in autocommit mode,
4904 ** respectively. ^Autocommit mode is on by default.
4905 ** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -4918,10 +4964,11 @@
4918 */
4919 SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
4920
4921 /*
4922 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
 
4923 **
4924 ** ^The sqlite3_db_handle interface returns the [database connection] handle
4925 ** to which a [prepared statement] belongs. ^The [database connection]
4926 ** returned by sqlite3_db_handle is the same [database connection]
4927 ** that was the first argument
@@ -4930,10 +4977,11 @@
4930 */
4931 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
4932
4933 /*
4934 ** CAPI3REF: Return The Filename For A Database Connection
 
4935 **
4936 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
4937 ** associated with database N of connection D. ^The main database file
4938 ** has the name "main". If there is no attached database N on the database
4939 ** connection D, or if database N is a temporary or in-memory database, then
@@ -4946,19 +4994,21 @@
4946 */
4947 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
4948
4949 /*
4950 ** CAPI3REF: Determine if a database is read-only
 
4951 **
4952 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
4953 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
4954 ** the name of a database on connection D.
4955 */
4956 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
4957
4958 /*
4959 ** CAPI3REF: Find the next prepared statement
 
4960 **
4961 ** ^This interface returns a pointer to the next [prepared statement] after
4962 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
4963 ** then this interface returns a pointer to the first prepared statement
4964 ** associated with the database connection pDb. ^If no prepared statement
@@ -4970,10 +5020,11 @@
4970 */
4971 SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
4972
4973 /*
4974 ** CAPI3REF: Commit And Rollback Notification Callbacks
 
4975 **
4976 ** ^The sqlite3_commit_hook() interface registers a callback
4977 ** function to be invoked whenever a transaction is [COMMIT | committed].
4978 ** ^Any callback set by a previous call to sqlite3_commit_hook()
4979 ** for the same database connection is overridden.
@@ -5019,10 +5070,11 @@
5019 SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
5020 SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5021
5022 /*
5023 ** CAPI3REF: Data Change Notification Callbacks
 
5024 **
5025 ** ^The sqlite3_update_hook() interface registers a callback function
5026 ** with the [database connection] identified by the first argument
5027 ** to be invoked whenever a row is updated, inserted or deleted in
5028 ** a rowid table.
@@ -5125,10 +5177,11 @@
5125 */
5126 SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
5127
5128 /*
5129 ** CAPI3REF: Free Memory Used By A Database Connection
 
5130 **
5131 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5132 ** memory as possible from database connection D. Unlike the
5133 ** [sqlite3_release_memory()] interface, this interface is in effect even
5134 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5202,10 +5255,11 @@
5202 SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
5203
5204
5205 /*
5206 ** CAPI3REF: Extract Metadata About A Column Of A Table
 
5207 **
5208 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5209 ** information about column C of table T in database D
5210 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5211 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5280,10 +5334,11 @@
5280 int *pAutoinc /* OUTPUT: True if column is auto-increment */
5281 );
5282
5283 /*
5284 ** CAPI3REF: Load An Extension
 
5285 **
5286 ** ^This interface loads an SQLite extension library from the named file.
5287 **
5288 ** ^The sqlite3_load_extension() interface attempts to load an
5289 ** [SQLite extension] library contained in the file zFile. If
@@ -5321,10 +5376,11 @@
5321 char **pzErrMsg /* Put error message here if not 0 */
5322 );
5323
5324 /*
5325 ** CAPI3REF: Enable Or Disable Extension Loading
 
5326 **
5327 ** ^So as not to open security holes in older applications that are
5328 ** unprepared to deal with [extension loading], and as a means of disabling
5329 ** [extension loading] while evaluating user-entered SQL, the following API
5330 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5570,10 +5626,11 @@
5570 #define SQLITE_INDEX_CONSTRAINT_GE 32
5571 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
5572
5573 /*
5574 ** CAPI3REF: Register A Virtual Table Implementation
 
5575 **
5576 ** ^These routines are used to register a new [virtual table module] name.
5577 ** ^Module names must be registered before
5578 ** creating a new [virtual table] using the module and before using a
5579 ** preexisting [virtual table] for the module.
@@ -5666,10 +5723,11 @@
5666 */
5667 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
5668
5669 /*
5670 ** CAPI3REF: Overload A Function For A Virtual Table
 
5671 **
5672 ** ^(Virtual tables can provide alternative implementations of functions
5673 ** using the [xFindFunction] method of the [virtual table module].
5674 ** But global versions of those functions
5675 ** must exist in order to be overloaded.)^
@@ -5708,10 +5766,12 @@
5708 */
5709 typedef struct sqlite3_blob sqlite3_blob;
5710
5711 /*
5712 ** CAPI3REF: Open A BLOB For Incremental I/O
 
 
5713 **
5714 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
5715 ** in row iRow, column zColumn, table zTable in database zDb;
5716 ** in other words, the same BLOB that would be selected by:
5717 **
@@ -5789,10 +5849,11 @@
5789 sqlite3_blob **ppBlob
5790 );
5791
5792 /*
5793 ** CAPI3REF: Move a BLOB Handle to a New Row
 
5794 **
5795 ** ^This function is used to move an existing blob handle so that it points
5796 ** to a different row of the same database table. ^The new row is identified
5797 ** by the rowid value passed as the second argument. Only the row can be
5798 ** changed. ^The database, table and column on which the blob handle is open
@@ -5813,10 +5874,11 @@
5813 */
5814 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5815
5816 /*
5817 ** CAPI3REF: Close A BLOB Handle
 
5818 **
5819 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
5820 ** unconditionally. Even if this routine returns an error code, the
5821 ** handle is still closed.)^
5822 **
@@ -5835,10 +5897,11 @@
5835 */
5836 SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
5837
5838 /*
5839 ** CAPI3REF: Return The Size Of An Open BLOB
 
5840 **
5841 ** ^Returns the size in bytes of the BLOB accessible via the
5842 ** successfully opened [BLOB handle] in its only argument. ^The
5843 ** incremental blob I/O routines can only read or overwriting existing
5844 ** blob content; they cannot change the size of a blob.
@@ -5850,10 +5913,11 @@
5850 */
5851 SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
5852
5853 /*
5854 ** CAPI3REF: Read Data From A BLOB Incrementally
 
5855 **
5856 ** ^(This function is used to read data from an open [BLOB handle] into a
5857 ** caller-supplied buffer. N bytes of data are copied into buffer Z
5858 ** from the open BLOB, starting at offset iOffset.)^
5859 **
@@ -5878,10 +5942,11 @@
5878 */
5879 SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5880
5881 /*
5882 ** CAPI3REF: Write Data Into A BLOB Incrementally
 
5883 **
5884 ** ^(This function is used to write data into an open [BLOB handle] from a
5885 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
5886 ** into the open BLOB, starting at offset iOffset.)^
5887 **
@@ -6205,10 +6270,11 @@
6205 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6206 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6207
6208 /*
6209 ** CAPI3REF: Retrieve the mutex for a database connection
 
6210 **
6211 ** ^This interface returns a pointer the [sqlite3_mutex] object that
6212 ** serializes access to the [database connection] given in the argument
6213 ** when the [threading mode] is Serialized.
6214 ** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6216,10 +6282,11 @@
6216 */
6217 SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
6218
6219 /*
6220 ** CAPI3REF: Low-Level Control Of Database Files
 
6221 **
6222 ** ^The [sqlite3_file_control()] interface makes a direct call to the
6223 ** xFileControl method for the [sqlite3_io_methods] object associated
6224 ** with a particular database identified by the second argument. ^The
6225 ** name of the database is "main" for the main database or "temp" for the
@@ -6432,10 +6499,11 @@
6432 #define SQLITE_STATUS_SCRATCH_SIZE 8
6433 #define SQLITE_STATUS_MALLOC_COUNT 9
6434
6435 /*
6436 ** CAPI3REF: Database Connection Status
 
6437 **
6438 ** ^This interface is used to retrieve runtime status information
6439 ** about a single [database connection]. ^The first argument is the
6440 ** database connection object to be interrogated. ^The second argument
6441 ** is an integer constant, taken from the set of
@@ -6560,10 +6628,11 @@
6560 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
6561
6562
6563 /*
6564 ** CAPI3REF: Prepared Statement Status
 
6565 **
6566 ** ^(Each prepared statement maintains various
6567 ** [SQLITE_STMTSTATUS counters] that measure the number
6568 ** of times it has performed specific operations.)^ These counters can
6569 ** be used to monitor the performance characteristics of the prepared
@@ -7063,10 +7132,11 @@
7063 SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
7064 SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
7065
7066 /*
7067 ** CAPI3REF: Unlock Notification
 
7068 **
7069 ** ^When running in shared-cache mode, a database operation may fail with
7070 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
7071 ** individual tables within the shared-cache cannot be obtained. See
7072 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7233,10 +7303,11 @@
7233 */
7234 SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
7235
7236 /*
7237 ** CAPI3REF: Write-Ahead Log Commit Hook
 
7238 **
7239 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7240 ** is invoked each time data is committed to a database in wal mode.
7241 **
7242 ** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7272,10 +7343,11 @@
7272 void*
7273 );
7274
7275 /*
7276 ** CAPI3REF: Configure an auto-checkpoint
 
7277 **
7278 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
7279 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
7280 ** to automatically [checkpoint]
7281 ** after committing a transaction if there are N or
@@ -7302,10 +7374,11 @@
7302 */
7303 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7304
7305 /*
7306 ** CAPI3REF: Checkpoint a database
 
7307 **
7308 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7309 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7310 **
7311 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7323,10 +7396,11 @@
7323 */
7324 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7325
7326 /*
7327 ** CAPI3REF: Checkpoint a database
 
7328 **
7329 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7330 ** operation on database X of [database connection] D in mode M. Status
7331 ** information is written back into integers pointed to by L and C.)^
7332 ** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7577,10 +7651,11 @@
7577 #define SQLITE_SCANSTAT_EXPLAIN 4
7578 #define SQLITE_SCANSTAT_SELECTID 5
7579
7580 /*
7581 ** CAPI3REF: Prepared Statement Scan Status
 
7582 **
7583 ** This interface returns information about the predicted and measured
7584 ** performance for pStmt. Advanced applications can use this
7585 ** interface to compare the predicted and the measured performance and
7586 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7614,10 +7689,11 @@
7614 void *pOut /* Result written here */
7615 );
7616
7617 /*
7618 ** CAPI3REF: Zero Scan-Status Counters
 
7619 **
7620 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7621 **
7622 ** This API is only available if the library is built with pre-processor
7623 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7624
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -109,13 +109,13 @@
109 **
110 ** See also: [sqlite3_libversion()],
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.8.10.2"
115 #define SQLITE_VERSION_NUMBER 3008010
116 #define SQLITE_SOURCE_ID "2015-05-20 18:17:19 2ef4f3a5b1d1d0c4338f8243d40a2452cc1f7fe4"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -268,10 +268,11 @@
268 # define double sqlite3_int64
269 #endif
270
271 /*
272 ** CAPI3REF: Closing A Database Connection
273 ** DESTRUCTOR: sqlite3
274 **
275 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
276 ** for the [sqlite3] object.
277 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
278 ** the [sqlite3] object is successfully destroyed and all associated
@@ -319,10 +320,11 @@
320 */
321 typedef int (*sqlite3_callback)(void*,int,char**, char**);
322
323 /*
324 ** CAPI3REF: One-Step Query Execution Interface
325 ** METHOD: sqlite3
326 **
327 ** The sqlite3_exec() interface is a convenience wrapper around
328 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
329 ** that allows an application to run multiple statements of SQL
330 ** without having to use a lot of C code.
@@ -1376,10 +1378,11 @@
1378 */
1379 SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
1380
1381 /*
1382 ** CAPI3REF: Configure database connections
1383 ** METHOD: sqlite3
1384 **
1385 ** The sqlite3_db_config() interface is used to make configuration
1386 ** changes to a [database connection]. The interface is similar to
1387 ** [sqlite3_config()] except that the changes apply to a single
1388 ** [database connection] (specified in the first argument).
@@ -1873,19 +1876,21 @@
1876 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1877
1878
1879 /*
1880 ** CAPI3REF: Enable Or Disable Extended Result Codes
1881 ** METHOD: sqlite3
1882 **
1883 ** ^The sqlite3_extended_result_codes() routine enables or disables the
1884 ** [extended result codes] feature of SQLite. ^The extended result
1885 ** codes are disabled by default for historical compatibility.
1886 */
1887 SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
1888
1889 /*
1890 ** CAPI3REF: Last Insert Rowid
1891 ** METHOD: sqlite3
1892 **
1893 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
1894 ** has a unique 64-bit signed
1895 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
1896 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
@@ -1933,10 +1938,11 @@
1938 */
1939 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
1940
1941 /*
1942 ** CAPI3REF: Count The Number Of Rows Modified
1943 ** METHOD: sqlite3
1944 **
1945 ** ^This function returns the number of rows modified, inserted or
1946 ** deleted by the most recently completed INSERT, UPDATE or DELETE
1947 ** statement on the database connection specified by the only parameter.
1948 ** ^Executing any other type of SQL statement does not modify the value
@@ -1985,10 +1991,11 @@
1991 */
1992 SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
1993
1994 /*
1995 ** CAPI3REF: Total Number Of Rows Modified
1996 ** METHOD: sqlite3
1997 **
1998 ** ^This function returns the total number of rows inserted, modified or
1999 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2000 ** since the database connection was opened, including those executed as
2001 ** part of trigger programs. ^Executing any other type of SQL statement
@@ -2008,10 +2015,11 @@
2015 */
2016 SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
2017
2018 /*
2019 ** CAPI3REF: Interrupt A Long-Running Query
2020 ** METHOD: sqlite3
2021 **
2022 ** ^This function causes any pending database operation to abort and
2023 ** return at its earliest opportunity. This routine is typically
2024 ** called in response to a user action such as pressing "Cancel"
2025 ** or Ctrl-C where the user wants a long query operation to halt
@@ -2084,10 +2092,11 @@
2092 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
2093
2094 /*
2095 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2096 ** KEYWORDS: {busy-handler callback} {busy handler}
2097 ** METHOD: sqlite3
2098 **
2099 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2100 ** that might be invoked with argument P whenever
2101 ** an attempt is made to access a database table associated with
2102 ** [database connection] D when another thread
@@ -2143,10 +2152,11 @@
2152 */
2153 SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
2154
2155 /*
2156 ** CAPI3REF: Set A Busy Timeout
2157 ** METHOD: sqlite3
2158 **
2159 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2160 ** for a specified amount of time when a table is locked. ^The handler
2161 ** will sleep multiple times until at least "ms" milliseconds of sleeping
2162 ** have accumulated. ^After at least "ms" milliseconds of sleeping,
@@ -2165,10 +2175,11 @@
2175 */
2176 SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
2177
2178 /*
2179 ** CAPI3REF: Convenience Routines For Running Queries
2180 ** METHOD: sqlite3
2181 **
2182 ** This is a legacy interface that is preserved for backwards compatibility.
2183 ** Use of this interface is not recommended.
2184 **
2185 ** Definition: A <b>result table</b> is memory data structure created by the
@@ -2500,10 +2511,11 @@
2511 */
2512 SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
2513
2514 /*
2515 ** CAPI3REF: Compile-Time Authorization Callbacks
2516 ** METHOD: sqlite3
2517 **
2518 ** ^This routine registers an authorizer callback with a particular
2519 ** [database connection], supplied in the first argument.
2520 ** ^The authorizer callback is invoked as SQL statements are being compiled
2521 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2656,10 +2668,11 @@
2668 #define SQLITE_COPY 0 /* No longer used */
2669 #define SQLITE_RECURSIVE 33 /* NULL NULL */
2670
2671 /*
2672 ** CAPI3REF: Tracing And Profiling Functions
2673 ** METHOD: sqlite3
2674 **
2675 ** These routines register callback functions that can be used for
2676 ** tracing and profiling the execution of SQL statements.
2677 **
2678 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2688,10 +2701,11 @@
2701 SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
2702 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2703
2704 /*
2705 ** CAPI3REF: Query Progress Callbacks
2706 ** METHOD: sqlite3
2707 **
2708 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2709 ** function X to be invoked periodically during long running calls to
2710 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2711 ** database connection D. An example use for this
@@ -2721,10 +2735,11 @@
2735 */
2736 SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2737
2738 /*
2739 ** CAPI3REF: Opening A New Database Connection
2740 ** CONSTRUCTOR: sqlite3
2741 **
2742 ** ^These routines open an SQLite database file as specified by the
2743 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2744 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2745 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -3006,10 +3021,11 @@
3021 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3022
3023
3024 /*
3025 ** CAPI3REF: Error Codes And Messages
3026 ** METHOD: sqlite3
3027 **
3028 ** ^If the most recent sqlite3_* API call associated with
3029 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3030 ** returns the numeric [result code] or [extended result code] for that
3031 ** API call.
@@ -3051,37 +3067,38 @@
3067 SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
3068 SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
3069 SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
3070
3071 /*
3072 ** CAPI3REF: Prepared Statement Object
3073 ** KEYWORDS: {prepared statement} {prepared statements}
3074 **
3075 ** An instance of this object represents a single SQL statement that
3076 ** has been compiled into binary form and is ready to be evaluated.
 
3077 **
3078 ** Think of each SQL statement as a separate computer program. The
3079 ** original SQL text is source code. A prepared statement object
3080 ** is the compiled object code. All SQL must be converted into a
3081 ** prepared statement before it can be run.
3082 **
3083 ** The life-cycle of a prepared statement object usually goes like this:
3084 **
3085 ** <ol>
3086 ** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
3087 ** <li> Bind values to [parameters] using the sqlite3_bind_*()
 
3088 ** interfaces.
3089 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3090 ** <li> Reset the prepared statement using [sqlite3_reset()] then go back
3091 ** to step 2. Do this zero or more times.
3092 ** <li> Destroy the object using [sqlite3_finalize()].
3093 ** </ol>
 
 
 
3094 */
3095 typedef struct sqlite3_stmt sqlite3_stmt;
3096
3097 /*
3098 ** CAPI3REF: Run-time Limits
3099 ** METHOD: sqlite3
3100 **
3101 ** ^(This interface allows the size of various constructs to be limited
3102 ** on a connection by connection basis. The first parameter is the
3103 ** [database connection] whose limit is to be set or queried. The
3104 ** second parameter is one of the [limit categories] that define a
@@ -3189,10 +3206,12 @@
3206 #define SQLITE_LIMIT_WORKER_THREADS 11
3207
3208 /*
3209 ** CAPI3REF: Compiling An SQL Statement
3210 ** KEYWORDS: {SQL statement compiler}
3211 ** METHOD: sqlite3
3212 ** CONSTRUCTOR: sqlite3_stmt
3213 **
3214 ** To execute an SQL query, it must first be compiled into a byte-code
3215 ** program using one of these routines.
3216 **
3217 ** The first argument, "db", is a [database connection] obtained from a
@@ -3296,19 +3315,21 @@
3315 const void **pzTail /* OUT: Pointer to unused portion of zSql */
3316 );
3317
3318 /*
3319 ** CAPI3REF: Retrieving Statement SQL
3320 ** METHOD: sqlite3_stmt
3321 **
3322 ** ^This interface can be used to retrieve a saved copy of the original
3323 ** SQL text used to create a [prepared statement] if that statement was
3324 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
3325 */
3326 SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
3327
3328 /*
3329 ** CAPI3REF: Determine If An SQL Statement Writes The Database
3330 ** METHOD: sqlite3_stmt
3331 **
3332 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3333 ** and only if the [prepared statement] X makes no direct changes to
3334 ** the content of the database file.
3335 **
@@ -3336,10 +3357,11 @@
3357 */
3358 SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3359
3360 /*
3361 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3362 ** METHOD: sqlite3_stmt
3363 **
3364 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3365 ** [prepared statement] S has been stepped at least once using
3366 ** [sqlite3_step(S)] but has not run to completion and/or has not
3367 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
@@ -3410,10 +3432,11 @@
3432
3433 /*
3434 ** CAPI3REF: Binding Values To Prepared Statements
3435 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3436 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3437 ** METHOD: sqlite3_stmt
3438 **
3439 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3440 ** literals may be replaced by a [parameter] that matches one of following
3441 ** templates:
3442 **
@@ -3528,10 +3551,11 @@
3551 SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3552 SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3553
3554 /*
3555 ** CAPI3REF: Number Of SQL Parameters
3556 ** METHOD: sqlite3_stmt
3557 **
3558 ** ^This routine can be used to find the number of [SQL parameters]
3559 ** in a [prepared statement]. SQL parameters are tokens of the
3560 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
3561 ** placeholders for values that are [sqlite3_bind_blob | bound]
@@ -3548,10 +3572,11 @@
3572 */
3573 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
3574
3575 /*
3576 ** CAPI3REF: Name Of A Host Parameter
3577 ** METHOD: sqlite3_stmt
3578 **
3579 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
3580 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
3581 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3582 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
@@ -3575,10 +3600,11 @@
3600 */
3601 SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
3602
3603 /*
3604 ** CAPI3REF: Index Of A Parameter With A Given Name
3605 ** METHOD: sqlite3_stmt
3606 **
3607 ** ^Return the index of an SQL parameter given its name. ^The
3608 ** index value returned is suitable for use as the second
3609 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
3610 ** is returned if no matching parameter is found. ^The parameter
@@ -3591,19 +3617,21 @@
3617 */
3618 SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
3619
3620 /*
3621 ** CAPI3REF: Reset All Bindings On A Prepared Statement
3622 ** METHOD: sqlite3_stmt
3623 **
3624 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
3625 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3626 ** ^Use this routine to reset all host parameters to NULL.
3627 */
3628 SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
3629
3630 /*
3631 ** CAPI3REF: Number Of Columns In A Result Set
3632 ** METHOD: sqlite3_stmt
3633 **
3634 ** ^Return the number of columns in the result set returned by the
3635 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3636 ** statement that does not return data (for example an [UPDATE]).
3637 **
@@ -3611,10 +3639,11 @@
3639 */
3640 SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
3641
3642 /*
3643 ** CAPI3REF: Column Names In A Result Set
3644 ** METHOD: sqlite3_stmt
3645 **
3646 ** ^These routines return the name assigned to a particular column
3647 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
3648 ** interface returns a pointer to a zero-terminated UTF-8 string
3649 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
@@ -3640,10 +3669,11 @@
3669 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
3670 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
3671
3672 /*
3673 ** CAPI3REF: Source Of Data In A Query Result
3674 ** METHOD: sqlite3_stmt
3675 **
3676 ** ^These routines provide a means to determine the database, table, and
3677 ** table column that is the origin of a particular result column in
3678 ** [SELECT] statement.
3679 ** ^The name of the database or table or column can be returned as
@@ -3692,10 +3722,11 @@
3722 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
3723 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
3724
3725 /*
3726 ** CAPI3REF: Declared Datatype Of A Query Result
3727 ** METHOD: sqlite3_stmt
3728 **
3729 ** ^(The first parameter is a [prepared statement].
3730 ** If this statement is a [SELECT] statement and the Nth column of the
3731 ** returned result set of that [SELECT] is a table column (not an
3732 ** expression or subquery) then the declared type of the table
@@ -3724,10 +3755,11 @@
3755 SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
3756 SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
3757
3758 /*
3759 ** CAPI3REF: Evaluate An SQL Statement
3760 ** METHOD: sqlite3_stmt
3761 **
3762 ** After a [prepared statement] has been prepared using either
3763 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
3764 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
3765 ** must be called one or more times to evaluate the statement.
@@ -3803,10 +3835,11 @@
3835 */
3836 SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
3837
3838 /*
3839 ** CAPI3REF: Number of columns in a result set
3840 ** METHOD: sqlite3_stmt
3841 **
3842 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
3843 ** current row of the result set of [prepared statement] P.
3844 ** ^If prepared statement P does not have results ready to return
3845 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
@@ -3856,10 +3889,11 @@
3889 #define SQLITE3_TEXT 3
3890
3891 /*
3892 ** CAPI3REF: Result Values From A Query
3893 ** KEYWORDS: {column access functions}
3894 ** METHOD: sqlite3_stmt
3895 **
3896 ** These routines form the "result set" interface.
3897 **
3898 ** ^These routines return information about a single column of the current
3899 ** result row of a query. ^In every case the first argument is a pointer
@@ -4028,10 +4062,11 @@
4062 SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
4063 SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
4064
4065 /*
4066 ** CAPI3REF: Destroy A Prepared Statement Object
4067 ** DESTRUCTOR: sqlite3_stmt
4068 **
4069 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
4070 ** ^If the most recent evaluation of the statement encountered no errors
4071 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
4072 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
@@ -4055,10 +4090,11 @@
4090 */
4091 SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
4092
4093 /*
4094 ** CAPI3REF: Reset A Prepared Statement Object
4095 ** METHOD: sqlite3_stmt
4096 **
4097 ** The sqlite3_reset() function is called to reset a [prepared statement]
4098 ** object back to its initial state, ready to be re-executed.
4099 ** ^Any SQL statement variables that had values bound to them using
4100 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
@@ -4084,10 +4120,11 @@
4120 /*
4121 ** CAPI3REF: Create Or Redefine SQL Functions
4122 ** KEYWORDS: {function creation routines}
4123 ** KEYWORDS: {application-defined SQL function}
4124 ** KEYWORDS: {application-defined SQL functions}
4125 ** METHOD: sqlite3
4126 **
4127 ** ^These functions (collectively known as "function creation routines")
4128 ** are used to add SQL functions or aggregates or to redefine the behavior
4129 ** of existing SQL functions or aggregates. The only differences between
4130 ** these routines are the text encoding expected for
@@ -4253,10 +4290,11 @@
4290 void*,sqlite3_int64);
4291 #endif
4292
4293 /*
4294 ** CAPI3REF: Obtaining SQL Function Parameter Values
4295 ** METHOD: sqlite3_value
4296 **
4297 ** The C-language implementation of SQL functions and aggregates uses
4298 ** this set of interface routines to access the parameter values on
4299 ** the function or aggregate.
4300 **
@@ -4311,10 +4349,11 @@
4349 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4350 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4351
4352 /*
4353 ** CAPI3REF: Obtain Aggregate Function Context
4354 ** METHOD: sqlite3_context
4355 **
4356 ** Implementations of aggregate SQL functions use this
4357 ** routine to allocate memory for storing their state.
4358 **
4359 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
@@ -4355,10 +4394,11 @@
4394 */
4395 SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
4396
4397 /*
4398 ** CAPI3REF: User Data For Functions
4399 ** METHOD: sqlite3_context
4400 **
4401 ** ^The sqlite3_user_data() interface returns a copy of
4402 ** the pointer that was the pUserData parameter (the 5th parameter)
4403 ** of the [sqlite3_create_function()]
4404 ** and [sqlite3_create_function16()] routines that originally
@@ -4369,10 +4409,11 @@
4409 */
4410 SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
4411
4412 /*
4413 ** CAPI3REF: Database Connection For Functions
4414 ** METHOD: sqlite3_context
4415 **
4416 ** ^The sqlite3_context_db_handle() interface returns a copy of
4417 ** the pointer to the [database connection] (the 1st parameter)
4418 ** of the [sqlite3_create_function()]
4419 ** and [sqlite3_create_function16()] routines that originally
@@ -4380,10 +4421,11 @@
4421 */
4422 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
4423
4424 /*
4425 ** CAPI3REF: Function Auxiliary Data
4426 ** METHOD: sqlite3_context
4427 **
4428 ** These functions may be used by (non-aggregate) SQL functions to
4429 ** associate metadata with argument values. If the same value is passed to
4430 ** multiple invocations of the same SQL function during query execution, under
4431 ** some circumstances the associated metadata may be preserved. An example
@@ -4452,10 +4494,11 @@
4494 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
4495 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
4496
4497 /*
4498 ** CAPI3REF: Setting The Result Of An SQL Function
4499 ** METHOD: sqlite3_context
4500 **
4501 ** These routines are used by the xFunc or xFinal callbacks that
4502 ** implement SQL functions and aggregates. See
4503 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
4504 ** for additional information.
@@ -4587,10 +4630,11 @@
4630 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4631 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4632
4633 /*
4634 ** CAPI3REF: Define New Collating Sequences
4635 ** METHOD: sqlite3
4636 **
4637 ** ^These functions add, remove, or modify a [collation] associated
4638 ** with the [database connection] specified as the first argument.
4639 **
4640 ** ^The name of the collation is a UTF-8 string
@@ -4689,10 +4733,11 @@
4733 int(*xCompare)(void*,int,const void*,int,const void*)
4734 );
4735
4736 /*
4737 ** CAPI3REF: Collation Needed Callbacks
4738 ** METHOD: sqlite3
4739 **
4740 ** ^To avoid having to register all collation sequences before a database
4741 ** can be used, a single callback function may be registered with the
4742 ** [database connection] to be invoked whenever an undefined collation
4743 ** sequence is required.
@@ -4896,10 +4941,11 @@
4941 SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
4942
4943 /*
4944 ** CAPI3REF: Test For Auto-Commit Mode
4945 ** KEYWORDS: {autocommit mode}
4946 ** METHOD: sqlite3
4947 **
4948 ** ^The sqlite3_get_autocommit() interface returns non-zero or
4949 ** zero if the given database connection is or is not in autocommit mode,
4950 ** respectively. ^Autocommit mode is on by default.
4951 ** ^Autocommit mode is disabled by a [BEGIN] statement.
@@ -4918,10 +4964,11 @@
4964 */
4965 SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
4966
4967 /*
4968 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
4969 ** METHOD: sqlite3_stmt
4970 **
4971 ** ^The sqlite3_db_handle interface returns the [database connection] handle
4972 ** to which a [prepared statement] belongs. ^The [database connection]
4973 ** returned by sqlite3_db_handle is the same [database connection]
4974 ** that was the first argument
@@ -4930,10 +4977,11 @@
4977 */
4978 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
4979
4980 /*
4981 ** CAPI3REF: Return The Filename For A Database Connection
4982 ** METHOD: sqlite3
4983 **
4984 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
4985 ** associated with database N of connection D. ^The main database file
4986 ** has the name "main". If there is no attached database N on the database
4987 ** connection D, or if database N is a temporary or in-memory database, then
@@ -4946,19 +4994,21 @@
4994 */
4995 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
4996
4997 /*
4998 ** CAPI3REF: Determine if a database is read-only
4999 ** METHOD: sqlite3
5000 **
5001 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
5002 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
5003 ** the name of a database on connection D.
5004 */
5005 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5006
5007 /*
5008 ** CAPI3REF: Find the next prepared statement
5009 ** METHOD: sqlite3
5010 **
5011 ** ^This interface returns a pointer to the next [prepared statement] after
5012 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
5013 ** then this interface returns a pointer to the first prepared statement
5014 ** associated with the database connection pDb. ^If no prepared statement
@@ -4970,10 +5020,11 @@
5020 */
5021 SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
5022
5023 /*
5024 ** CAPI3REF: Commit And Rollback Notification Callbacks
5025 ** METHOD: sqlite3
5026 **
5027 ** ^The sqlite3_commit_hook() interface registers a callback
5028 ** function to be invoked whenever a transaction is [COMMIT | committed].
5029 ** ^Any callback set by a previous call to sqlite3_commit_hook()
5030 ** for the same database connection is overridden.
@@ -5019,10 +5070,11 @@
5070 SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
5071 SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5072
5073 /*
5074 ** CAPI3REF: Data Change Notification Callbacks
5075 ** METHOD: sqlite3
5076 **
5077 ** ^The sqlite3_update_hook() interface registers a callback function
5078 ** with the [database connection] identified by the first argument
5079 ** to be invoked whenever a row is updated, inserted or deleted in
5080 ** a rowid table.
@@ -5125,10 +5177,11 @@
5177 */
5178 SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
5179
5180 /*
5181 ** CAPI3REF: Free Memory Used By A Database Connection
5182 ** METHOD: sqlite3
5183 **
5184 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5185 ** memory as possible from database connection D. Unlike the
5186 ** [sqlite3_release_memory()] interface, this interface is in effect even
5187 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
@@ -5202,10 +5255,11 @@
5255 SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
5256
5257
5258 /*
5259 ** CAPI3REF: Extract Metadata About A Column Of A Table
5260 ** METHOD: sqlite3
5261 **
5262 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5263 ** information about column C of table T in database D
5264 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5265 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
@@ -5280,10 +5334,11 @@
5334 int *pAutoinc /* OUTPUT: True if column is auto-increment */
5335 );
5336
5337 /*
5338 ** CAPI3REF: Load An Extension
5339 ** METHOD: sqlite3
5340 **
5341 ** ^This interface loads an SQLite extension library from the named file.
5342 **
5343 ** ^The sqlite3_load_extension() interface attempts to load an
5344 ** [SQLite extension] library contained in the file zFile. If
@@ -5321,10 +5376,11 @@
5376 char **pzErrMsg /* Put error message here if not 0 */
5377 );
5378
5379 /*
5380 ** CAPI3REF: Enable Or Disable Extension Loading
5381 ** METHOD: sqlite3
5382 **
5383 ** ^So as not to open security holes in older applications that are
5384 ** unprepared to deal with [extension loading], and as a means of disabling
5385 ** [extension loading] while evaluating user-entered SQL, the following API
5386 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
@@ -5570,10 +5626,11 @@
5626 #define SQLITE_INDEX_CONSTRAINT_GE 32
5627 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
5628
5629 /*
5630 ** CAPI3REF: Register A Virtual Table Implementation
5631 ** METHOD: sqlite3
5632 **
5633 ** ^These routines are used to register a new [virtual table module] name.
5634 ** ^Module names must be registered before
5635 ** creating a new [virtual table] using the module and before using a
5636 ** preexisting [virtual table] for the module.
@@ -5666,10 +5723,11 @@
5723 */
5724 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
5725
5726 /*
5727 ** CAPI3REF: Overload A Function For A Virtual Table
5728 ** METHOD: sqlite3
5729 **
5730 ** ^(Virtual tables can provide alternative implementations of functions
5731 ** using the [xFindFunction] method of the [virtual table module].
5732 ** But global versions of those functions
5733 ** must exist in order to be overloaded.)^
@@ -5708,10 +5766,12 @@
5766 */
5767 typedef struct sqlite3_blob sqlite3_blob;
5768
5769 /*
5770 ** CAPI3REF: Open A BLOB For Incremental I/O
5771 ** METHOD: sqlite3
5772 ** CONSTRUCTOR: sqlite3_blob
5773 **
5774 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
5775 ** in row iRow, column zColumn, table zTable in database zDb;
5776 ** in other words, the same BLOB that would be selected by:
5777 **
@@ -5789,10 +5849,11 @@
5849 sqlite3_blob **ppBlob
5850 );
5851
5852 /*
5853 ** CAPI3REF: Move a BLOB Handle to a New Row
5854 ** METHOD: sqlite3_blob
5855 **
5856 ** ^This function is used to move an existing blob handle so that it points
5857 ** to a different row of the same database table. ^The new row is identified
5858 ** by the rowid value passed as the second argument. Only the row can be
5859 ** changed. ^The database, table and column on which the blob handle is open
@@ -5813,10 +5874,11 @@
5874 */
5875 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5876
5877 /*
5878 ** CAPI3REF: Close A BLOB Handle
5879 ** DESTRUCTOR: sqlite3_blob
5880 **
5881 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
5882 ** unconditionally. Even if this routine returns an error code, the
5883 ** handle is still closed.)^
5884 **
@@ -5835,10 +5897,11 @@
5897 */
5898 SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
5899
5900 /*
5901 ** CAPI3REF: Return The Size Of An Open BLOB
5902 ** METHOD: sqlite3_blob
5903 **
5904 ** ^Returns the size in bytes of the BLOB accessible via the
5905 ** successfully opened [BLOB handle] in its only argument. ^The
5906 ** incremental blob I/O routines can only read or overwriting existing
5907 ** blob content; they cannot change the size of a blob.
@@ -5850,10 +5913,11 @@
5913 */
5914 SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
5915
5916 /*
5917 ** CAPI3REF: Read Data From A BLOB Incrementally
5918 ** METHOD: sqlite3_blob
5919 **
5920 ** ^(This function is used to read data from an open [BLOB handle] into a
5921 ** caller-supplied buffer. N bytes of data are copied into buffer Z
5922 ** from the open BLOB, starting at offset iOffset.)^
5923 **
@@ -5878,10 +5942,11 @@
5942 */
5943 SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5944
5945 /*
5946 ** CAPI3REF: Write Data Into A BLOB Incrementally
5947 ** METHOD: sqlite3_blob
5948 **
5949 ** ^(This function is used to write data into an open [BLOB handle] from a
5950 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
5951 ** into the open BLOB, starting at offset iOffset.)^
5952 **
@@ -6205,10 +6270,11 @@
6270 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6271 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6272
6273 /*
6274 ** CAPI3REF: Retrieve the mutex for a database connection
6275 ** METHOD: sqlite3
6276 **
6277 ** ^This interface returns a pointer the [sqlite3_mutex] object that
6278 ** serializes access to the [database connection] given in the argument
6279 ** when the [threading mode] is Serialized.
6280 ** ^If the [threading mode] is Single-thread or Multi-thread then this
@@ -6216,10 +6282,11 @@
6282 */
6283 SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
6284
6285 /*
6286 ** CAPI3REF: Low-Level Control Of Database Files
6287 ** METHOD: sqlite3
6288 **
6289 ** ^The [sqlite3_file_control()] interface makes a direct call to the
6290 ** xFileControl method for the [sqlite3_io_methods] object associated
6291 ** with a particular database identified by the second argument. ^The
6292 ** name of the database is "main" for the main database or "temp" for the
@@ -6432,10 +6499,11 @@
6499 #define SQLITE_STATUS_SCRATCH_SIZE 8
6500 #define SQLITE_STATUS_MALLOC_COUNT 9
6501
6502 /*
6503 ** CAPI3REF: Database Connection Status
6504 ** METHOD: sqlite3
6505 **
6506 ** ^This interface is used to retrieve runtime status information
6507 ** about a single [database connection]. ^The first argument is the
6508 ** database connection object to be interrogated. ^The second argument
6509 ** is an integer constant, taken from the set of
@@ -6560,10 +6628,11 @@
6628 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
6629
6630
6631 /*
6632 ** CAPI3REF: Prepared Statement Status
6633 ** METHOD: sqlite3_stmt
6634 **
6635 ** ^(Each prepared statement maintains various
6636 ** [SQLITE_STMTSTATUS counters] that measure the number
6637 ** of times it has performed specific operations.)^ These counters can
6638 ** be used to monitor the performance characteristics of the prepared
@@ -7063,10 +7132,11 @@
7132 SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
7133 SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
7134
7135 /*
7136 ** CAPI3REF: Unlock Notification
7137 ** METHOD: sqlite3
7138 **
7139 ** ^When running in shared-cache mode, a database operation may fail with
7140 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
7141 ** individual tables within the shared-cache cannot be obtained. See
7142 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -7233,10 +7303,11 @@
7303 */
7304 SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
7305
7306 /*
7307 ** CAPI3REF: Write-Ahead Log Commit Hook
7308 ** METHOD: sqlite3
7309 **
7310 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
7311 ** is invoked each time data is committed to a database in wal mode.
7312 **
7313 ** ^(The callback is invoked by SQLite after the commit has taken place and
@@ -7272,10 +7343,11 @@
7343 void*
7344 );
7345
7346 /*
7347 ** CAPI3REF: Configure an auto-checkpoint
7348 ** METHOD: sqlite3
7349 **
7350 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
7351 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
7352 ** to automatically [checkpoint]
7353 ** after committing a transaction if there are N or
@@ -7302,10 +7374,11 @@
7374 */
7375 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7376
7377 /*
7378 ** CAPI3REF: Checkpoint a database
7379 ** METHOD: sqlite3
7380 **
7381 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7382 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7383 **
7384 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
@@ -7323,10 +7396,11 @@
7396 */
7397 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7398
7399 /*
7400 ** CAPI3REF: Checkpoint a database
7401 ** METHOD: sqlite3
7402 **
7403 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7404 ** operation on database X of [database connection] D in mode M. Status
7405 ** information is written back into integers pointed to by L and C.)^
7406 ** ^(The M parameter must be a valid [checkpoint mode]:)^
@@ -7577,10 +7651,11 @@
7651 #define SQLITE_SCANSTAT_EXPLAIN 4
7652 #define SQLITE_SCANSTAT_SELECTID 5
7653
7654 /*
7655 ** CAPI3REF: Prepared Statement Scan Status
7656 ** METHOD: sqlite3_stmt
7657 **
7658 ** This interface returns information about the predicted and measured
7659 ** performance for pStmt. Advanced applications can use this
7660 ** interface to compare the predicted and the measured performance and
7661 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -7614,10 +7689,11 @@
7689 void *pOut /* Result written here */
7690 );
7691
7692 /*
7693 ** CAPI3REF: Zero Scan-Status Counters
7694 ** METHOD: sqlite3_stmt
7695 **
7696 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7697 **
7698 ** This API is only available if the library is built with pre-processor
7699 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7700
+92
--- src/stat.c
+++ src/stat.c
@@ -36,10 +36,25 @@
3636
}else{
3737
sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fGB)",
3838
v, (double)v/1000000000.0);
3939
}
4040
}
41
+
42
+/*
43
+** Return the approximate size as KB, MB, GB, or TB.
44
+*/
45
+void approxSizeName(int nOut, char *zOut, sqlite3_int64 v){
46
+ if( v<1000 ){
47
+ sqlite3_snprintf(nOut, zOut, "%lld bytes", v);
48
+ }else if( v<1000000 ){
49
+ sqlite3_snprintf(nOut, zOut, "%.1fKB", (double)v/1000.0);
50
+ }else if( v<1000000000 ){
51
+ sqlite3_snprintf(nOut, zOut, "%.1fMB", (double)v/1000000.0);
52
+ }else{
53
+ sqlite3_snprintf(nOut, zOut, "%.1fGB", (double)v/1000000000.0);
54
+ }
55
+}
4156
4257
/*
4358
** WEBPAGE: stat
4459
**
4560
** Show statistics and global information about the repository.
@@ -63,10 +78,13 @@
6378
style_submenu_element("Schema", "Repository Schema", "repo_schema");
6479
style_submenu_element("Web-Cache", "Web-Cache Stats", "cachestat");
6580
}
6681
style_submenu_element("Activity Reports", 0, "reports");
6782
style_submenu_element("SHA1 Collisions", 0, "hash-collisions");
83
+ if( sqlite3_libversion_number()>=3008010 ){
84
+ style_submenu_element("Table Sizes", 0, "repo-tabsize");
85
+ }
6886
@ <table class="label-value">
6987
@ <tr><th>Repository&nbsp;Size:</th><td>
7088
fsize = file_size(g.zRepositoryName);
7189
bigSizeName(sizeof(zBuf), zBuf, fsize);
7290
@ %s(zBuf)
@@ -355,5 +373,79 @@
355373
}
356374
@ </pre>
357375
db_finalize(&q);
358376
style_footer();
359377
}
378
+
379
+/*
380
+** WEBPAGE: repo-tabsize
381
+**
382
+** Show relative sizes of tables in the repository database.
383
+*/
384
+void repo_tabsize_page(void){
385
+ int nPageFree;
386
+ sqlite3_int64 fsize;
387
+ char zBuf[100];
388
+
389
+ login_check_credentials();
390
+ if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
391
+ style_header("Repository Table Sizes");
392
+ style_adunit_config(ADUNIT_RIGHT_OK);
393
+ style_submenu_element("Stat", "Repository Stats", "stat");
394
+ db_multi_exec(
395
+ "CREATE VIRTUAL TABLE temp.dbx USING dbstat(%s);"
396
+ "CREATE TEMP TABLE trans(name TEXT PRIMARY KEY, tabname TEXT)WITHOUT ROWID;"
397
+ "INSERT INTO trans(name,tabname)"
398
+ " SELECT name, tbl_name FROM %s.sqlite_master;"
399
+ "CREATE TEMP TABLE piechart(amt REAL, label TEXT);"
400
+ "INSERT INTO piechart(amt,label)"
401
+ " SELECT count(*), "
402
+ " coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
403
+ " FROM dbx"
404
+ " GROUP BY 2 ORDER BY 2;",
405
+ db_name("repository"), db_name("repository")
406
+ );
407
+ nPageFree = db_int(0, "PRAGMA \"%w\".freelist_count", db_name("repository"));
408
+ if( nPageFree>0 ){
409
+ db_multi_exec(
410
+ "INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
411
+ nPageFree
412
+ );
413
+ }
414
+ fsize = file_size(g.zRepositoryName);
415
+ approxSizeName(sizeof(zBuf), zBuf, fsize);
416
+ @ <h2>Repository Size: %s(zBuf)</h2>
417
+ @ <center><svg width='800' height='500'>
418
+ piechart_render(800,500,PIE_OTHER|PIE_PERCENT);
419
+ @ </svg></center>
420
+
421
+ if( g.localOpen ){
422
+ db_multi_exec(
423
+ "DROP TABLE temp.dbx;"
424
+ "CREATE VIRTUAL TABLE temp.dbx USING dbstat(%s);"
425
+ "DELETE FROM trans;"
426
+ "INSERT INTO trans(name,tabname)"
427
+ " SELECT name, tbl_name FROM %s.sqlite_master;"
428
+ "DELETE FROM piechart;"
429
+ "INSERT INTO piechart(amt,label)"
430
+ " SELECT count(*), "
431
+ " coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
432
+ " FROM dbx"
433
+ " GROUP BY 2 ORDER BY 2;",
434
+ db_name("localdb"), db_name("localdb")
435
+ );
436
+ nPageFree = db_int(0, "PRAGMA \"%s\".freelist_count", db_name("localdb"));
437
+ if( nPageFree>0 ){
438
+ db_multi_exec(
439
+ "INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
440
+ nPageFree
441
+ );
442
+ }
443
+ fsize = file_size(g.zLocalDbName);
444
+ approxSizeName(sizeof(zBuf), zBuf, fsize);
445
+ @ <h2>%h(file_tail(g.zLocalDbName)) Size: %s(zBuf)</h2>
446
+ @ <center><svg width='800' height='500'>
447
+ piechart_render(800,500,PIE_OTHER|PIE_PERCENT);
448
+ @ </svg></center>
449
+ }
450
+ style_footer();
451
+}
360452
--- src/stat.c
+++ src/stat.c
@@ -36,10 +36,25 @@
36 }else{
37 sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fGB)",
38 v, (double)v/1000000000.0);
39 }
40 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
42 /*
43 ** WEBPAGE: stat
44 **
45 ** Show statistics and global information about the repository.
@@ -63,10 +78,13 @@
63 style_submenu_element("Schema", "Repository Schema", "repo_schema");
64 style_submenu_element("Web-Cache", "Web-Cache Stats", "cachestat");
65 }
66 style_submenu_element("Activity Reports", 0, "reports");
67 style_submenu_element("SHA1 Collisions", 0, "hash-collisions");
 
 
 
68 @ <table class="label-value">
69 @ <tr><th>Repository&nbsp;Size:</th><td>
70 fsize = file_size(g.zRepositoryName);
71 bigSizeName(sizeof(zBuf), zBuf, fsize);
72 @ %s(zBuf)
@@ -355,5 +373,79 @@
355 }
356 @ </pre>
357 db_finalize(&q);
358 style_footer();
359 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
--- src/stat.c
+++ src/stat.c
@@ -36,10 +36,25 @@
36 }else{
37 sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fGB)",
38 v, (double)v/1000000000.0);
39 }
40 }
41
42 /*
43 ** Return the approximate size as KB, MB, GB, or TB.
44 */
45 void approxSizeName(int nOut, char *zOut, sqlite3_int64 v){
46 if( v<1000 ){
47 sqlite3_snprintf(nOut, zOut, "%lld bytes", v);
48 }else if( v<1000000 ){
49 sqlite3_snprintf(nOut, zOut, "%.1fKB", (double)v/1000.0);
50 }else if( v<1000000000 ){
51 sqlite3_snprintf(nOut, zOut, "%.1fMB", (double)v/1000000.0);
52 }else{
53 sqlite3_snprintf(nOut, zOut, "%.1fGB", (double)v/1000000000.0);
54 }
55 }
56
57 /*
58 ** WEBPAGE: stat
59 **
60 ** Show statistics and global information about the repository.
@@ -63,10 +78,13 @@
78 style_submenu_element("Schema", "Repository Schema", "repo_schema");
79 style_submenu_element("Web-Cache", "Web-Cache Stats", "cachestat");
80 }
81 style_submenu_element("Activity Reports", 0, "reports");
82 style_submenu_element("SHA1 Collisions", 0, "hash-collisions");
83 if( sqlite3_libversion_number()>=3008010 ){
84 style_submenu_element("Table Sizes", 0, "repo-tabsize");
85 }
86 @ <table class="label-value">
87 @ <tr><th>Repository&nbsp;Size:</th><td>
88 fsize = file_size(g.zRepositoryName);
89 bigSizeName(sizeof(zBuf), zBuf, fsize);
90 @ %s(zBuf)
@@ -355,5 +373,79 @@
373 }
374 @ </pre>
375 db_finalize(&q);
376 style_footer();
377 }
378
379 /*
380 ** WEBPAGE: repo-tabsize
381 **
382 ** Show relative sizes of tables in the repository database.
383 */
384 void repo_tabsize_page(void){
385 int nPageFree;
386 sqlite3_int64 fsize;
387 char zBuf[100];
388
389 login_check_credentials();
390 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
391 style_header("Repository Table Sizes");
392 style_adunit_config(ADUNIT_RIGHT_OK);
393 style_submenu_element("Stat", "Repository Stats", "stat");
394 db_multi_exec(
395 "CREATE VIRTUAL TABLE temp.dbx USING dbstat(%s);"
396 "CREATE TEMP TABLE trans(name TEXT PRIMARY KEY, tabname TEXT)WITHOUT ROWID;"
397 "INSERT INTO trans(name,tabname)"
398 " SELECT name, tbl_name FROM %s.sqlite_master;"
399 "CREATE TEMP TABLE piechart(amt REAL, label TEXT);"
400 "INSERT INTO piechart(amt,label)"
401 " SELECT count(*), "
402 " coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
403 " FROM dbx"
404 " GROUP BY 2 ORDER BY 2;",
405 db_name("repository"), db_name("repository")
406 );
407 nPageFree = db_int(0, "PRAGMA \"%w\".freelist_count", db_name("repository"));
408 if( nPageFree>0 ){
409 db_multi_exec(
410 "INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
411 nPageFree
412 );
413 }
414 fsize = file_size(g.zRepositoryName);
415 approxSizeName(sizeof(zBuf), zBuf, fsize);
416 @ <h2>Repository Size: %s(zBuf)</h2>
417 @ <center><svg width='800' height='500'>
418 piechart_render(800,500,PIE_OTHER|PIE_PERCENT);
419 @ </svg></center>
420
421 if( g.localOpen ){
422 db_multi_exec(
423 "DROP TABLE temp.dbx;"
424 "CREATE VIRTUAL TABLE temp.dbx USING dbstat(%s);"
425 "DELETE FROM trans;"
426 "INSERT INTO trans(name,tabname)"
427 " SELECT name, tbl_name FROM %s.sqlite_master;"
428 "DELETE FROM piechart;"
429 "INSERT INTO piechart(amt,label)"
430 " SELECT count(*), "
431 " coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
432 " FROM dbx"
433 " GROUP BY 2 ORDER BY 2;",
434 db_name("localdb"), db_name("localdb")
435 );
436 nPageFree = db_int(0, "PRAGMA \"%s\".freelist_count", db_name("localdb"));
437 if( nPageFree>0 ){
438 db_multi_exec(
439 "INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
440 nPageFree
441 );
442 }
443 fsize = file_size(g.zLocalDbName);
444 approxSizeName(sizeof(zBuf), zBuf, fsize);
445 @ <h2>%h(file_tail(g.zLocalDbName)) Size: %s(zBuf)</h2>
446 @ <center><svg width='800' height='500'>
447 piechart_render(800,500,PIE_OTHER|PIE_PERCENT);
448 @ </svg></center>
449 }
450 style_footer();
451 }
452
+270 -264
--- src/statrep.c
+++ src/statrep.c
@@ -141,63 +141,10 @@
141141
default:
142142
return "all types";
143143
}
144144
}
145145
146
-/*
147
-** A helper for the /reports family of pages which prints out a menu
148
-** of links for the various type=XXX flags. zCurrentViewName must be
149
-** the name/value of the 'view' parameter which is in effect at the
150
-** time this is called. e.g. if called from the 'byuser' view then
151
-** zCurrentViewName must be "byuser". Any URL parameters which need to
152
-** be added to the generated URLs should be passed in zParam. The
153
-** caller is expected to have already encoded any zParam in the %T or
154
-** %t encoding. */
155
-static void stats_report_event_types_menu(const char *zCurrentViewName,
156
- const char *zParam){
157
- char *zTop;
158
- if(zParam && !*zParam){
159
- zParam = NULL;
160
- }
161
- zTop = mprintf("%s/reports?view=%s%s%s", g.zTop, zCurrentViewName,
162
- zParam ? "&" : "", zParam);
163
- cgi_printf("<div>");
164
- cgi_printf("<span>Types:</span> ");
165
- if('*' == statsReportType){
166
- cgi_printf(" <strong>all</strong>", zTop);
167
- }else{
168
- cgi_printf(" <a href='%s'>all</a>", zTop);
169
- }
170
- if('c' == statsReportType){
171
- cgi_printf(" <strong>check-ins</strong>", zTop);
172
- }else{
173
- cgi_printf(" <a href='%s&type=ci'>check-ins</a>", zTop);
174
- }
175
- if('e' == statsReportType){
176
- cgi_printf(" <strong>technotes</strong>", zTop);
177
- }else{
178
- cgi_printf(" <a href='%s&type=e'>technotes</a>", zTop);
179
- }
180
- if( 't' == statsReportType ){
181
- cgi_printf(" <strong>tickets</strong>", zTop);
182
- }else{
183
- cgi_printf(" <a href='%s&type=t'>tickets</a>", zTop);
184
- }
185
- if( 'g' == statsReportType ){
186
- cgi_printf(" <strong>tags</strong>", zTop);
187
- }else{
188
- cgi_printf(" <a href='%s&type=g'>tags</a>", zTop);
189
- }
190
- if( 'w' == statsReportType ){
191
- cgi_printf(" <strong>wiki</strong>", zTop);
192
- }else{
193
- cgi_printf(" <a href='%s&type=w'>wiki</a>", zTop);
194
- }
195
- fossil_free(zTop);
196
- cgi_printf("</div>");
197
-}
198
-
199146
200147
/*
201148
** Helper for stats_report_by_month_year(), which generates a list of
202149
** week numbers. zTimeframe should be either a timeframe in the form YYYY
203150
** or YYYY-MM.
@@ -227,23 +174,21 @@
227174
}
228175
229176
/*
230177
** Implements the "byyear" and "bymonth" reports for /reports.
231178
** If includeMonth is true then it generates the "bymonth" report,
232
-** else the "byyear" report. If zUserName is not NULL and not empty
233
-** then the report is restricted to events created by the named user
234
-** account.
179
+** else the "byyear" report. If zUserName is not NULL then the report is
180
+** restricted to events created by the named user account.
235181
*/
236182
static void stats_report_by_month_year(char includeMonth,
237183
char includeWeeks,
238184
const char *zUserName){
239185
Stmt query = empty_Stmt;
240186
int nRowNumber = 0; /* current TR number */
241187
int nEventTotal = 0; /* Total event count */
242188
int rowClass = 0; /* counter for alternating
243189
row colors */
244
- Blob sql = empty_blob; /* SQL */
245190
const char *zTimeLabel = includeMonth ? "Year/Month" : "Year";
246191
char zPrevYear[5] = {0}; /* For keeping track of when
247192
we change years while looping */
248193
int nEventsPerYear = 0; /* Total event count for the
249194
current year */
@@ -252,39 +197,37 @@
252197
Blob header = empty_blob; /* Page header text */
253198
int nMaxEvents = 1; /* for calculating length of graph
254199
bars. */
255200
int iterations = 0; /* number of weeks/months we iterate
256201
over */
202
+ Blob userFilter = empty_blob; /* Optional user=johndoe query string */
257203
stats_report_init_view();
258
- stats_report_event_types_menu( includeMonth ? "bymonth" : "byyear", NULL );
259
- blob_appendf(&header, "Timeline Events (%s) by year%s",
260
- stats_report_label_for_type(),
261
- (includeMonth ? "/month" : ""));
262
- blob_append_sql(&sql,
263
- "SELECT substr(date(mtime),1,%d) AS timeframe, "
264
- "count(*) AS eventCount "
265
- "FROM v_reports ",
266
- includeMonth ? 7 : 4);
267
- if(zUserName&&*zUserName){
268
- blob_append_sql(&sql, " WHERE user=%Q ", zUserName);
269
- blob_appendf(&header," for user %q", zUserName);
270
- }
271
- blob_append(&sql,
272
- " GROUP BY timeframe"
273
- " ORDER BY timeframe DESC",
274
- -1);
275
- db_prepare(&query, "%s", blob_sql_text(&sql));
276
- blob_reset(&sql);
277
- @ <h1>%b(&header)</h1>
204
+ if( zUserName ){
205
+ blob_appendf(&userFilter, "user=%s", zUserName);
206
+ }
207
+ blob_reset(&userFilter);
208
+ db_prepare(&query,
209
+ "SELECT substr(date(mtime),1,%d) AS timeframe,"
210
+ " count(*) AS eventCount"
211
+ " FROM v_reports"
212
+ " WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
213
+ " GROUP BY timeframe"
214
+ " ORDER BY timeframe DESC",
215
+ includeMonth ? 7 : 4, zUserName);
216
+ @ <h1>Timeline Events (%s(stats_report_label_for_type()))
217
+ @ by year%s(includeMonth ? "/month" : "")
218
+ if( zUserName ){
219
+ @ for user %h(zUserName)
220
+ }
221
+ @ </h1>
278222
@ <table class='statistics-report-table-events' border='0' cellpadding='2'
279223
@ cellspacing='0' id='statsTable'>
280224
@ <thead>
281225
@ <th>%s(zTimeLabel)</th>
282226
@ <th>Events</th>
283227
@ <th width='90%%'><!-- relative commits graph --></th>
284228
@ </thead><tbody>
285
- blob_reset(&header);
286229
/*
287230
Run the query twice. The first time we calculate the maximum
288231
number of events for a given row. Maybe someone with better SQL
289232
Fu can re-implement this with a single query.
290233
*/
@@ -335,18 +278,18 @@
335278
zTimeframe, nCount,
336279
statsReportTimelineYFlag );
337280
/* Reminder: n=nCount is not actually correct for bymonth unless
338281
that was the only user who caused events.
339282
*/
340
- if( zUserName && *zUserName ){
283
+ if( zUserName ){
341284
cgi_printf("&u=%t", zUserName);
342285
}
343286
cgi_printf("' target='_new'>%s</a>",zTimeframe);
344287
}else {
345288
cgi_printf("<a href='?view=byweek&y=%s&type=%c",
346289
zTimeframe, (char)statsReportType);
347
- if(zUserName && *zUserName){
290
+ if( zUserName ){
348291
cgi_printf("&u=%t", zUserName);
349292
}
350293
cgi_printf("'>%s</a>", zTimeframe);
351294
}
352295
@ </td><td>%d(nCount)</td>
@@ -403,25 +346,34 @@
403346
int rowClass = 0; /* counter for alternating
404347
row colors */
405348
int nMaxEvents = 1; /* max number of events for
406349
all rows. */
407350
stats_report_init_view();
408
- stats_report_event_types_menu("byuser", NULL);
409
- db_prepare(&query,
410
- "SELECT user, "
411
- "COUNT(*) AS eventCount "
412
- "FROM v_reports "
413
- "GROUP BY user ORDER BY eventCount DESC");
414351
@ <h1>Timeline Events
415352
@ (%s(stats_report_label_for_type())) by User</h1>
353
+ db_multi_exec(
354
+ "CREATE TEMP TABLE piechart(amt,label);"
355
+ "INSERT INTO piechart SELECT count(*), ifnull(euser,user) FROM v_reports"
356
+ " GROUP BY ifnull(euser,user) ORDER BY count(*) DESC;"
357
+ );
358
+ if( db_int(0, "SELECT count(*) FROM piechart")>=2 ){
359
+ @ <center><svg width=700 height=400>
360
+ piechart_render(700, 400, PIE_OTHER|PIE_PERCENT);
361
+ @ </svg></centre><hr/>
362
+ }
416363
@ <table class='statistics-report-table-events' border='0'
417364
@ cellpadding='2' cellspacing='0' id='statsTable'>
418365
@ <thead><tr>
419366
@ <th>User</th>
420367
@ <th>Events</th>
421368
@ <th width='90%%'><!-- relative commits graph --></th>
422369
@ </tr></thead><tbody>
370
+ db_prepare(&query,
371
+ "SELECT ifnull(euser,user), "
372
+ "COUNT(*) AS eventCount "
373
+ "FROM v_reports "
374
+ "GROUP BY ifnull(euser,user) ORDER BY eventCount DESC");
423375
while( SQLITE_ROW == db_step(&query) ){
424376
const int nCount = db_column_int(&query, 1);
425377
if(nCount>nMaxEvents){
426378
nMaxEvents = nCount;
427379
}
@@ -428,20 +380,21 @@
428380
}
429381
db_reset(&query);
430382
while( SQLITE_ROW == db_step(&query) ){
431383
const char *zUser = db_column_text(&query, 0);
432384
const int nCount = db_column_int(&query, 1);
385
+ char y = (char)statsReportType;
433386
int nSize = nCount
434387
? (int)(100 * nCount / nMaxEvents)
435388
: 0;
436389
if(!nCount) continue /* arguable! Possible? */;
437390
else if(!nSize) nSize = 1;
438391
rowClass = ++nRowNumber % 2;
439392
nEventTotal += nCount;
440
- @<tr class='row%d(rowClass)'>
393
+ @ <tr class='row%d(rowClass)'>
441394
@ <td>
442
- @ <a href="?view=bymonth&user=%h(zUser)&type=%c((char)statsReportType)">%h(zUser)</a>
395
+ @ <a href="?view=bymonth&user=%h(zUser)&type=%c(y)">%h(zUser)</a>
443396
@ </td><td data-sortkey='%08x(-nCount)'>%d(nCount)</td>
444397
@ <td>
445398
@ <div class='statistics-report-graph-line'
446399
@ style='width:%d(nSize)%%;'>&nbsp;</div>
447400
@ </td>
@@ -455,30 +408,37 @@
455408
db_finalize(&query);
456409
output_table_sorting_javascript("statsTable","tkx",2);
457410
}
458411
459412
/*
460
-** Implements the "byfile" view for /reports.
413
+** Implements the "byfile" view for /reports. If zUserName is not NULL then the
414
+** report is restricted to events created by the named user account.
461415
*/
462
-static void stats_report_by_file(){
416
+static void stats_report_by_file(const char *zUserName){
463417
Stmt query;
464418
int mxEvent = 1; /* max number of events across all rows */
465419
int nRowNumber = 0;
466420
467421
db_multi_exec(
468422
"CREATE TEMP TABLE statrep(filename, cnt);"
469423
"INSERT INTO statrep(filename, cnt)"
470424
" SELECT filename.name, count(distinct mlink.mid)"
471
- " FROM filename, mlink"
425
+ " FROM filename, mlink, event"
472426
" WHERE filename.fnid=mlink.fnid"
473
- " GROUP BY 1"
427
+ " AND mlink.mid=event.objid"
428
+ " AND ifnull(coalesce(euser,user,'')=%Q,1)"
429
+ " GROUP BY 1", zUserName
474430
);
475431
db_prepare(&query,
476432
"SELECT filename, cnt FROM statrep ORDER BY cnt DESC, filename /*sort*/"
477433
);
478434
mxEvent = db_int(1, "SELECT max(cnt) FROM statrep");
479
- @ <h1>Check-ins Per File</h1>
435
+ @ <h1>Check-ins Per File
436
+ if( zUserName ){
437
+ @ for user %h(zUserName)
438
+ }
439
+ @ </h1>
480440
@ <table class='statistics-report-table-events' border='0'
481441
@ cellpadding='2' cellspacing='0' id='statsTable'>
482442
@ <thead><tr>
483443
@ <th>File</th>
484444
@ <th>Check-ins</th>
@@ -504,34 +464,62 @@
504464
db_finalize(&query);
505465
output_table_sorting_javascript("statsTable","tNx",2);
506466
}
507467
508468
/*
509
-** Implements the "byweekday" view for /reports.
469
+** Implements the "byweekday" view for /reports. If zUserName is not NULL then
470
+** the report is restricted to events created by the named user account.
510471
*/
511
-static void stats_report_day_of_week(){
472
+static void stats_report_day_of_week(const char *zUserName){
512473
Stmt query = empty_Stmt;
513474
int nRowNumber = 0; /* current TR number */
514475
int nEventTotal = 0; /* Total event count */
515476
int rowClass = 0; /* counter for alternating
516477
row colors */
517478
int nMaxEvents = 1; /* max number of events for
518479
all rows. */
480
+ Blob userFilter = empty_blob; /* Optional user=johndoe query string */
519481
static const char *const daysOfWeek[] = {
520482
"Monday", "Tuesday", "Wednesday", "Thursday",
521483
"Friday", "Saturday", "Sunday"
522484
};
523485
524486
stats_report_init_view();
525
- stats_report_event_types_menu("byweekday", NULL);
487
+ if( zUserName ){
488
+ blob_appendf(&userFilter, "user=%s", zUserName);
489
+ }
526490
db_prepare(&query,
527
- "SELECT cast(mtime %% 7 AS INTEGER) dow, "
528
- "COUNT(*) AS eventCount "
529
- "FROM v_reports "
530
- "GROUP BY dow ORDER BY dow");
531
- @ <h1>Timeline Events
532
- @ (%s(stats_report_label_for_type())) by Day of the Week</h1>
491
+ "SELECT cast(mtime %% 7 AS INTEGER) dow,"
492
+ " COUNT(*) AS eventCount"
493
+ " FROM v_reports"
494
+ " WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
495
+ " GROUP BY dow ORDER BY dow", zUserName);
496
+ @ <h1>Timeline Events (%h(stats_report_label_for_type())) by Day of the Week
497
+ if( zUserName ){
498
+ @ for user %h(zUserName)
499
+ }
500
+ @ </h1>
501
+ db_multi_exec(
502
+ "CREATE TEMP TABLE piechart(amt,label);"
503
+ "INSERT INTO piechart"
504
+ " SELECT count(*), cast(mtime %% 7 AS INT) FROM v_reports"
505
+ " WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
506
+ " GROUP BY 2 ORDER BY 2;"
507
+ "UPDATE piechart SET label = CASE label"
508
+ " WHEN 0 THEN 'Monday'"
509
+ " WHEN 1 THEN 'Tuesday'"
510
+ " WHEN 2 THEN 'Wednesday'"
511
+ " WHEN 3 THEN 'Thursday'"
512
+ " WHEN 4 THEN 'Friday'"
513
+ " WHEN 5 THEN 'Saturday'"
514
+ " ELSE 'Sunday' END;", zUserName
515
+ );
516
+ if( db_int(0, "SELECT count(*) FROM piechart")>=2 ){
517
+ @ <center><svg width=700 height=400>
518
+ piechart_render(700, 400, PIE_OTHER|PIE_PERCENT);
519
+ @ </svg></centre><hr/>
520
+ }
533521
@ <table class='statistics-report-table-events' border='0'
534522
@ cellpadding='2' cellspacing='0' id='statsTable'>
535523
@ <thead><tr>
536524
@ <th>DoW</th>
537525
@ <th>Day</th>
@@ -572,139 +560,114 @@
572560
573561
574562
/*
575563
** Helper for stats_report_by_month_year(), which generates a list of
576564
** week numbers. zTimeframe should be either a timeframe in the form YYYY
577
-** or YYYY-MM.
565
+** or YYYY-MM. If zUserName is not NULL then the report is restricted to events
566
+** created by the named user account.
578567
*/
579568
static void stats_report_year_weeks(const char *zUserName){
580
- const char *zYear = P("y");
581
- int nYear = zYear ? strlen(zYear) : 0;
569
+ const char *zYear = P("y"); /* Year for which report shown */
570
+ int isValidYear = 0; /* True if a valid year */
582571
int i = 0;
583
- Stmt qYears = empty_Stmt;
584
- char *zDefaultYear = NULL;
585
- Blob sql = empty_blob;
572
+ Stmt q;
586573
int nMaxEvents = 1; /* max number of events for
587574
all rows. */
588575
int iterations = 0; /* # of active time periods. */
589
- stats_report_init_view();
590
- if(4==nYear){
591
- Blob urlParams = empty_blob;
592
- blob_appendf(&urlParams, "y=%T", zYear);
593
- stats_report_event_types_menu("byweek", blob_str(&urlParams));
594
- blob_reset(&urlParams);
595
- }else{
596
- stats_report_event_types_menu("byweek", NULL);
597
- }
598
- blob_append(&sql,
599
- "SELECT DISTINCT substr(date(mtime),1,4) AS y "
600
- "FROM v_reports WHERE 1 ", -1);
601
- if(zUserName&&*zUserName){
602
- blob_append_sql(&sql,"AND user=%Q ", zUserName);
603
- }
604
- blob_append(&sql,"GROUP BY y ORDER BY y", -1);
605
- db_prepare(&qYears, "%s", blob_sql_text(&sql));
606
- blob_reset(&sql);
607
- cgi_printf("Select year: ");
608
- while( SQLITE_ROW == db_step(&qYears) ){
609
- const char *zT = db_column_text(&qYears, 0);
610
- if( i++ ){
611
- cgi_printf(" ");
612
- }
613
- cgi_printf("<a href='?view=byweek&y=%s&type=%c", zT,
614
- (char)statsReportType);
615
- if(zUserName && *zUserName){
616
- cgi_printf("&user=%t",zUserName);
617
- }
618
- cgi_printf("'>%s</a>",zT);
619
- }
620
- db_finalize(&qYears);
621
- cgi_printf("<br/>");
622
- if(!zYear || !*zYear){
623
- zDefaultYear = db_text("????", "SELECT strftime('%%Y')");
624
- zYear = zDefaultYear;
625
- nYear = 4;
626
- }
627
- if(4 == nYear){
628
- Stmt stWeek = empty_Stmt;
629
- int rowCount = 0;
630
- int total = 0;
631
- Blob header = empty_blob;
632
- blob_appendf(&header, "Timeline events (%s) for the calendar weeks "
633
- "of %h", stats_report_label_for_type(),
634
- zYear);
635
- blob_append_sql(&sql,
636
- "SELECT DISTINCT strftime('%%W',mtime) AS wk, "
637
- "count(*) AS n "
638
- "FROM v_reports "
639
- "WHERE %Q=substr(date(mtime),1,4) "
640
- "AND mtime < current_timestamp ",
641
- zYear);
642
- if(zUserName&&*zUserName){
643
- blob_append_sql(&sql, " AND user=%Q ", zUserName);
644
- blob_appendf(&header," for user %h", zUserName);
645
- }
646
- blob_append_sql(&sql, "GROUP BY wk ORDER BY wk DESC");
647
- cgi_printf("<h1>%h</h1>", blob_str(&header));
648
- blob_reset(&header);
649
- cgi_printf("<table class='statistics-report-table-events' "
650
- "border='0' cellpadding='2' width='100%%' "
651
- "cellspacing='0' id='statsTable'>");
652
- cgi_printf("<thead><tr>"
653
- "<th>Week</th>"
654
- "<th>Events</th>"
655
- "<th width='90%%'><!-- relative commits graph --></th>"
656
- "</tr></thead>"
657
- "<tbody>");
658
- db_prepare(&stWeek, "%s", blob_sql_text(&sql));
659
- blob_reset(&sql);
660
- while( SQLITE_ROW == db_step(&stWeek) ){
661
- const int nCount = db_column_int(&stWeek, 1);
662
- if(nCount>nMaxEvents){
663
- nMaxEvents = nCount;
664
- }
665
- ++iterations;
666
- }
667
- db_reset(&stWeek);
668
- while( SQLITE_ROW == db_step(&stWeek) ){
669
- const char *zWeek = db_column_text(&stWeek,0);
670
- const int nCount = db_column_int(&stWeek,1);
671
- int nSize = nCount
672
- ? (int)(100 * nCount / nMaxEvents)
673
- : 0;
674
- if(!nSize) nSize = 1;
675
- total += nCount;
676
- cgi_printf("<tr class='row%d'>", ++rowCount % 2 );
677
- cgi_printf("<td><a href='%R/timeline?yw=%t-%s&n=%d&y=%s",
678
- zYear, zWeek, nCount,
679
- statsReportTimelineYFlag);
680
- if(zUserName && *zUserName){
681
- cgi_printf("&u=%t",zUserName);
682
- }
683
- cgi_printf("'>%s</a></td>",zWeek);
684
-
685
- cgi_printf("<td>%d</td>",nCount);
686
- cgi_printf("<td>");
687
- if(nCount){
688
- cgi_printf("<div class='statistics-report-graph-line'"
689
- "style='width:%d%%;'>&nbsp;</div>",
690
- nSize);
691
- }
692
- cgi_printf("</td></tr>");
693
- }
694
- db_finalize(&stWeek);
695
- free(zDefaultYear);
696
- cgi_printf("</tbody></table>");
697
- if(total){
698
- int nAvg = iterations ? (total/iterations) : 0;
699
- cgi_printf("<br><div>Total events: %d<br>"
700
- "Average per active week: %d</div>",
701
- total, nAvg);
702
- }
703
- output_table_sorting_javascript("statsTable","tnx",-1);
704
- }
705
-}
576
+ int n = 0; /* Number of entries in azYear */
577
+ char **azYear = 0; /* Year dropdown menu */
578
+ int rowCount = 0;
579
+ int total = 0;
580
+
581
+ stats_report_init_view();
582
+ style_submenu_sql("y", "Year:",
583
+ "WITH RECURSIVE a(b) AS ("
584
+ " SELECT substr(date('now'),1,4) UNION ALL"
585
+ " SELECT b-1 FROM a"
586
+ " WHERE b>0+(SELECT substr(date(min(mtime)),1,4) FROM event)"
587
+ ") SELECT b, b FROM a ORDER BY b DESC");
588
+ if( zYear==0 || strlen(zYear)!=4 ){
589
+ zYear = db_text("1970","SELECT substr(date('now'),1,4);");
590
+ }
591
+ cgi_printf("<br/>");
592
+ db_prepare(&q,
593
+ "SELECT DISTINCT strftime('%%W',mtime) AS wk, "
594
+ " count(*) AS n "
595
+ " FROM v_reports "
596
+ " WHERE %Q=substr(date(mtime),1,4) "
597
+ " AND mtime < current_timestamp "
598
+ " AND ifnull(coalesce(euser,user,'')=%Q,1)"
599
+ " GROUP BY wk ORDER BY wk DESC", zYear, zUserName);
600
+ @ <h1>Timeline events (%h(stats_report_label_for_type()))
601
+ @ for the calendar weeks of %h(zYear)
602
+ if( zUserName ){
603
+ @ for user %h(zUserName)
604
+ }
605
+ @ </h1>
606
+ cgi_printf("<table class='statistics-report-table-events' "
607
+ "border='0' cellpadding='2' width='100%%' "
608
+ "cellspacing='0' id='statsTable'>");
609
+ cgi_printf("<thead><tr>"
610
+ "<th>Week</th>"
611
+ "<th>Events</th>"
612
+ "<th width='90%%'><!-- relative commits graph --></th>"
613
+ "</tr></thead>"
614
+ "<tbody>");
615
+ while( SQLITE_ROW == db_step(&q) ){
616
+ const int nCount = db_column_int(&q, 1);
617
+ if(nCount>nMaxEvents){
618
+ nMaxEvents = nCount;
619
+ }
620
+ ++iterations;
621
+ }
622
+ db_reset(&q);
623
+ while( SQLITE_ROW == db_step(&q) ){
624
+ const char *zWeek = db_column_text(&q,0);
625
+ const int nCount = db_column_int(&q,1);
626
+ int nSize = nCount
627
+ ? (int)(100 * nCount / nMaxEvents)
628
+ : 0;
629
+ if(!nSize) nSize = 1;
630
+ total += nCount;
631
+ cgi_printf("<tr class='row%d'>", ++rowCount % 2 );
632
+ cgi_printf("<td><a href='%R/timeline?yw=%t-%s&n=%d&y=%s",
633
+ zYear, zWeek, nCount,
634
+ statsReportTimelineYFlag);
635
+ if( zUserName ){
636
+ cgi_printf("&u=%t",zUserName);
637
+ }
638
+ cgi_printf("'>%s</a></td>",zWeek);
639
+
640
+ cgi_printf("<td>%d</td>",nCount);
641
+ cgi_printf("<td>");
642
+ if(nCount){
643
+ cgi_printf("<div class='statistics-report-graph-line'"
644
+ "style='width:%d%%;'>&nbsp;</div>",
645
+ nSize);
646
+ }
647
+ cgi_printf("</td></tr>");
648
+ }
649
+ db_finalize(&q);
650
+ cgi_printf("</tbody></table>");
651
+ if(total){
652
+ int nAvg = iterations ? (total/iterations) : 0;
653
+ cgi_printf("<br><div>Total events: %d<br>"
654
+ "Average per active week: %d</div>",
655
+ total, nAvg);
656
+ }
657
+ output_table_sorting_javascript("statsTable","tnx",-1);
658
+}
659
+
660
+/* Report types
661
+*/
662
+#define RPT_BYFILE 1
663
+#define RPT_BYMONTH 2
664
+#define RPT_BYUSER 3
665
+#define RPT_BYWEEK 4
666
+#define RPT_BYWEEKDAY 5
667
+#define RPT_BYYEAR 6
668
+#define RPT_NONE 0 /* None of the above */
706669
707670
/*
708671
** WEBPAGE: reports
709672
**
710673
** Shows activity reports for the repository.
@@ -724,51 +687,94 @@
724687
** y=YYYY The year to report (default is the server's
725688
** current year).
726689
*/
727690
void stats_report_page(){
728691
HQuery url; /* URL for various branch links */
729
- const char *zView = P("view"); /* Which view/report to show. */
730
- const char *zUserName = P("user");
731
-
692
+ const char *zView = P("view"); /* Which view/report to show. */
693
+ int eType = RPT_NONE; /* Numeric code for view/report to show */
694
+ int i; /* Loop counter */
695
+ const char *zUserName; /* Name of user */
696
+ const struct {
697
+ const char *zName; /* Name of view= screen type */
698
+ const char *zVal; /* Value of view= query parameter */
699
+ int eType; /* Corresponding RPT_* define */
700
+ } aViewType[] = {
701
+ { "File Changes","byfile", RPT_BYFILE },
702
+ { "By Month", "bymonth", RPT_BYMONTH },
703
+ { "By User", "byuser", RPT_BYUSER },
704
+ { "By Week", "byweek", RPT_BYWEEK },
705
+ { "By Weekday", "byweekday", RPT_BYWEEKDAY },
706
+ { "By Year", "byyear", RPT_BYYEAR },
707
+ };
708
+ const char *azType[] = {
709
+ "a", "All Changes",
710
+ "ci", "Check-ins",
711
+ "g", "Tags",
712
+ "e", "Tech Notes",
713
+ "t", "Tickets",
714
+ "w", "Wiki"
715
+ };
716
+
732717
login_check_credentials();
733718
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
734
- if(!zUserName) zUserName = P("u");
735
- url_initialize(&url, "reports");
736
- if(zUserName && *zUserName){
737
- url_add_parameter(&url,"user", zUserName);
738
- statrep_submenu(&url, "(Remove User Flag)", "view", zView, "user");
739
- }
740
- statrep_submenu(&url, "By Year", "view", "byyear", 0);
741
- statrep_submenu(&url, "By Month", "view", "bymonth", 0);
742
- statrep_submenu(&url, "By Week", "view", "byweek", 0);
743
- statrep_submenu(&url, "By Weekday", "view", "byweekday", 0);
744
- statrep_submenu(&url, "By User", "view", "byuser", "user");
745
- statrep_submenu(&url, "By File", "view", "byfile", "file");
719
+ zUserName = P("user");
720
+ if( zUserName==0 ) zUserName = P("u");
721
+ if( zUserName && zUserName[0]==0 ) zUserName = 0;
722
+ if( zView==0 ){
723
+ zView = "byuser";
724
+ cgi_replace_query_parameter("view","byuser");
725
+ }
726
+ for(i=0; i<ArraySize(aViewType); i++){
727
+ if( fossil_strcmp(zView, aViewType[i].zVal)==0 ){
728
+ eType = aViewType[i].eType;
729
+ break;
730
+ }
731
+ }
732
+ url_initialize(&url, "reports");
733
+ cgi_query_parameters_to_url(&url);
734
+ if( eType!=RPT_NONE ){
735
+ int nView = 0; /* Slots used in azView[] */
736
+ const char *azView[16]; /* Drop-down menu of view types */
737
+ for(i=0; i<ArraySize(aViewType); i++){
738
+ azView[nView++] = aViewType[i].zVal;
739
+ azView[nView++] = aViewType[i].zName;
740
+ }
741
+ if( eType!=RPT_BYFILE ){
742
+ style_submenu_multichoice("type", ArraySize(azType)/2, azType, 0);
743
+ }
744
+ style_submenu_multichoice("view", nView/2, azView, 0);
745
+ if( eType!=RPT_BYUSER ){
746
+ style_submenu_sql("u","User:",
747
+ "SELECT '', 'All Users' UNION ALL "
748
+ "SELECT x, x FROM ("
749
+ " SELECT DISTINCT trim(coalesce(euser,user)) AS x FROM event %s"
750
+ " ORDER BY 1 COLLATE nocase) WHERE x!=''",
751
+ eType==RPT_BYFILE ? "WHERE type='ci'" : ""
752
+ );
753
+ }
754
+ }
746755
style_submenu_element("Stats", "Stats", "%R/stat");
747756
url_reset(&url);
748757
style_header("Activity Reports");
749
- if(0==fossil_strcmp(zView,"byyear")){
750
- stats_report_by_month_year(0, 0, zUserName);
751
- }else if(0==fossil_strcmp(zView,"bymonth")){
752
- stats_report_by_month_year(1, 0, zUserName);
753
- }else if(0==fossil_strcmp(zView,"byweek")){
754
- stats_report_year_weeks(zUserName);
755
- }else if(0==fossil_strcmp(zView,"byuser")){
756
- stats_report_by_user();
757
- }else if(0==fossil_strcmp(zView,"byweekday")){
758
- stats_report_day_of_week();
759
- }else if(0==fossil_strcmp(zView,"byfile")){
760
- stats_report_by_file();
761
- }else{
762
- @ <h1>Activity Reports:</h1>
763
- @ <ul>
764
- @ <li>%z(href("?view=byyear"))Events by year</a></li>
765
- @ <li>%z(href("?view=bymonth"))Events by month</a></li>
766
- @ <li>%z(href("?view=byweek"))Events by calendar week</a></li>
767
- @ <li>%z(href("?view=byweekday"))Events by day of the week</a></li>
768
- @ <li>%z(href("?view=byuser"))Events by user</a></li>
769
- @ <li>%z(href("?view=byfile"))Events by file</a></li>
770
- @ </ul>
771
- }
772
-
758
+ switch( eType ){
759
+ case RPT_BYYEAR:
760
+ stats_report_by_month_year(0, 0, zUserName);
761
+ break;
762
+ case RPT_BYMONTH:
763
+ stats_report_by_month_year(1, 0, zUserName);
764
+ break;
765
+ case RPT_BYWEEK:
766
+ stats_report_year_weeks(zUserName);
767
+ break;
768
+ default:
769
+ case RPT_BYUSER:
770
+ stats_report_by_user();
771
+ break;
772
+ case RPT_BYWEEKDAY:
773
+ stats_report_day_of_week(zUserName);
774
+ break;
775
+ case RPT_BYFILE:
776
+ stats_report_by_file(zUserName);
777
+ break;
778
+ }
773779
style_footer();
774780
}
775781
--- src/statrep.c
+++ src/statrep.c
@@ -141,63 +141,10 @@
141 default:
142 return "all types";
143 }
144 }
145
146 /*
147 ** A helper for the /reports family of pages which prints out a menu
148 ** of links for the various type=XXX flags. zCurrentViewName must be
149 ** the name/value of the 'view' parameter which is in effect at the
150 ** time this is called. e.g. if called from the 'byuser' view then
151 ** zCurrentViewName must be "byuser". Any URL parameters which need to
152 ** be added to the generated URLs should be passed in zParam. The
153 ** caller is expected to have already encoded any zParam in the %T or
154 ** %t encoding. */
155 static void stats_report_event_types_menu(const char *zCurrentViewName,
156 const char *zParam){
157 char *zTop;
158 if(zParam && !*zParam){
159 zParam = NULL;
160 }
161 zTop = mprintf("%s/reports?view=%s%s%s", g.zTop, zCurrentViewName,
162 zParam ? "&" : "", zParam);
163 cgi_printf("<div>");
164 cgi_printf("<span>Types:</span> ");
165 if('*' == statsReportType){
166 cgi_printf(" <strong>all</strong>", zTop);
167 }else{
168 cgi_printf(" <a href='%s'>all</a>", zTop);
169 }
170 if('c' == statsReportType){
171 cgi_printf(" <strong>check-ins</strong>", zTop);
172 }else{
173 cgi_printf(" <a href='%s&type=ci'>check-ins</a>", zTop);
174 }
175 if('e' == statsReportType){
176 cgi_printf(" <strong>technotes</strong>", zTop);
177 }else{
178 cgi_printf(" <a href='%s&type=e'>technotes</a>", zTop);
179 }
180 if( 't' == statsReportType ){
181 cgi_printf(" <strong>tickets</strong>", zTop);
182 }else{
183 cgi_printf(" <a href='%s&type=t'>tickets</a>", zTop);
184 }
185 if( 'g' == statsReportType ){
186 cgi_printf(" <strong>tags</strong>", zTop);
187 }else{
188 cgi_printf(" <a href='%s&type=g'>tags</a>", zTop);
189 }
190 if( 'w' == statsReportType ){
191 cgi_printf(" <strong>wiki</strong>", zTop);
192 }else{
193 cgi_printf(" <a href='%s&type=w'>wiki</a>", zTop);
194 }
195 fossil_free(zTop);
196 cgi_printf("</div>");
197 }
198
199
200 /*
201 ** Helper for stats_report_by_month_year(), which generates a list of
202 ** week numbers. zTimeframe should be either a timeframe in the form YYYY
203 ** or YYYY-MM.
@@ -227,23 +174,21 @@
227 }
228
229 /*
230 ** Implements the "byyear" and "bymonth" reports for /reports.
231 ** If includeMonth is true then it generates the "bymonth" report,
232 ** else the "byyear" report. If zUserName is not NULL and not empty
233 ** then the report is restricted to events created by the named user
234 ** account.
235 */
236 static void stats_report_by_month_year(char includeMonth,
237 char includeWeeks,
238 const char *zUserName){
239 Stmt query = empty_Stmt;
240 int nRowNumber = 0; /* current TR number */
241 int nEventTotal = 0; /* Total event count */
242 int rowClass = 0; /* counter for alternating
243 row colors */
244 Blob sql = empty_blob; /* SQL */
245 const char *zTimeLabel = includeMonth ? "Year/Month" : "Year";
246 char zPrevYear[5] = {0}; /* For keeping track of when
247 we change years while looping */
248 int nEventsPerYear = 0; /* Total event count for the
249 current year */
@@ -252,39 +197,37 @@
252 Blob header = empty_blob; /* Page header text */
253 int nMaxEvents = 1; /* for calculating length of graph
254 bars. */
255 int iterations = 0; /* number of weeks/months we iterate
256 over */
 
257 stats_report_init_view();
258 stats_report_event_types_menu( includeMonth ? "bymonth" : "byyear", NULL );
259 blob_appendf(&header, "Timeline Events (%s) by year%s",
260 stats_report_label_for_type(),
261 (includeMonth ? "/month" : ""));
262 blob_append_sql(&sql,
263 "SELECT substr(date(mtime),1,%d) AS timeframe, "
264 "count(*) AS eventCount "
265 "FROM v_reports ",
266 includeMonth ? 7 : 4);
267 if(zUserName&&*zUserName){
268 blob_append_sql(&sql, " WHERE user=%Q ", zUserName);
269 blob_appendf(&header," for user %q", zUserName);
270 }
271 blob_append(&sql,
272 " GROUP BY timeframe"
273 " ORDER BY timeframe DESC",
274 -1);
275 db_prepare(&query, "%s", blob_sql_text(&sql));
276 blob_reset(&sql);
277 @ <h1>%b(&header)</h1>
278 @ <table class='statistics-report-table-events' border='0' cellpadding='2'
279 @ cellspacing='0' id='statsTable'>
280 @ <thead>
281 @ <th>%s(zTimeLabel)</th>
282 @ <th>Events</th>
283 @ <th width='90%%'><!-- relative commits graph --></th>
284 @ </thead><tbody>
285 blob_reset(&header);
286 /*
287 Run the query twice. The first time we calculate the maximum
288 number of events for a given row. Maybe someone with better SQL
289 Fu can re-implement this with a single query.
290 */
@@ -335,18 +278,18 @@
335 zTimeframe, nCount,
336 statsReportTimelineYFlag );
337 /* Reminder: n=nCount is not actually correct for bymonth unless
338 that was the only user who caused events.
339 */
340 if( zUserName && *zUserName ){
341 cgi_printf("&u=%t", zUserName);
342 }
343 cgi_printf("' target='_new'>%s</a>",zTimeframe);
344 }else {
345 cgi_printf("<a href='?view=byweek&y=%s&type=%c",
346 zTimeframe, (char)statsReportType);
347 if(zUserName && *zUserName){
348 cgi_printf("&u=%t", zUserName);
349 }
350 cgi_printf("'>%s</a>", zTimeframe);
351 }
352 @ </td><td>%d(nCount)</td>
@@ -403,25 +346,34 @@
403 int rowClass = 0; /* counter for alternating
404 row colors */
405 int nMaxEvents = 1; /* max number of events for
406 all rows. */
407 stats_report_init_view();
408 stats_report_event_types_menu("byuser", NULL);
409 db_prepare(&query,
410 "SELECT user, "
411 "COUNT(*) AS eventCount "
412 "FROM v_reports "
413 "GROUP BY user ORDER BY eventCount DESC");
414 @ <h1>Timeline Events
415 @ (%s(stats_report_label_for_type())) by User</h1>
 
 
 
 
 
 
 
 
 
 
416 @ <table class='statistics-report-table-events' border='0'
417 @ cellpadding='2' cellspacing='0' id='statsTable'>
418 @ <thead><tr>
419 @ <th>User</th>
420 @ <th>Events</th>
421 @ <th width='90%%'><!-- relative commits graph --></th>
422 @ </tr></thead><tbody>
 
 
 
 
 
423 while( SQLITE_ROW == db_step(&query) ){
424 const int nCount = db_column_int(&query, 1);
425 if(nCount>nMaxEvents){
426 nMaxEvents = nCount;
427 }
@@ -428,20 +380,21 @@
428 }
429 db_reset(&query);
430 while( SQLITE_ROW == db_step(&query) ){
431 const char *zUser = db_column_text(&query, 0);
432 const int nCount = db_column_int(&query, 1);
 
433 int nSize = nCount
434 ? (int)(100 * nCount / nMaxEvents)
435 : 0;
436 if(!nCount) continue /* arguable! Possible? */;
437 else if(!nSize) nSize = 1;
438 rowClass = ++nRowNumber % 2;
439 nEventTotal += nCount;
440 @<tr class='row%d(rowClass)'>
441 @ <td>
442 @ <a href="?view=bymonth&user=%h(zUser)&type=%c((char)statsReportType)">%h(zUser)</a>
443 @ </td><td data-sortkey='%08x(-nCount)'>%d(nCount)</td>
444 @ <td>
445 @ <div class='statistics-report-graph-line'
446 @ style='width:%d(nSize)%%;'>&nbsp;</div>
447 @ </td>
@@ -455,30 +408,37 @@
455 db_finalize(&query);
456 output_table_sorting_javascript("statsTable","tkx",2);
457 }
458
459 /*
460 ** Implements the "byfile" view for /reports.
 
461 */
462 static void stats_report_by_file(){
463 Stmt query;
464 int mxEvent = 1; /* max number of events across all rows */
465 int nRowNumber = 0;
466
467 db_multi_exec(
468 "CREATE TEMP TABLE statrep(filename, cnt);"
469 "INSERT INTO statrep(filename, cnt)"
470 " SELECT filename.name, count(distinct mlink.mid)"
471 " FROM filename, mlink"
472 " WHERE filename.fnid=mlink.fnid"
473 " GROUP BY 1"
 
 
474 );
475 db_prepare(&query,
476 "SELECT filename, cnt FROM statrep ORDER BY cnt DESC, filename /*sort*/"
477 );
478 mxEvent = db_int(1, "SELECT max(cnt) FROM statrep");
479 @ <h1>Check-ins Per File</h1>
 
 
 
 
480 @ <table class='statistics-report-table-events' border='0'
481 @ cellpadding='2' cellspacing='0' id='statsTable'>
482 @ <thead><tr>
483 @ <th>File</th>
484 @ <th>Check-ins</th>
@@ -504,34 +464,62 @@
504 db_finalize(&query);
505 output_table_sorting_javascript("statsTable","tNx",2);
506 }
507
508 /*
509 ** Implements the "byweekday" view for /reports.
 
510 */
511 static void stats_report_day_of_week(){
512 Stmt query = empty_Stmt;
513 int nRowNumber = 0; /* current TR number */
514 int nEventTotal = 0; /* Total event count */
515 int rowClass = 0; /* counter for alternating
516 row colors */
517 int nMaxEvents = 1; /* max number of events for
518 all rows. */
 
519 static const char *const daysOfWeek[] = {
520 "Monday", "Tuesday", "Wednesday", "Thursday",
521 "Friday", "Saturday", "Sunday"
522 };
523
524 stats_report_init_view();
525 stats_report_event_types_menu("byweekday", NULL);
 
 
526 db_prepare(&query,
527 "SELECT cast(mtime %% 7 AS INTEGER) dow, "
528 "COUNT(*) AS eventCount "
529 "FROM v_reports "
530 "GROUP BY dow ORDER BY dow");
531 @ <h1>Timeline Events
532 @ (%s(stats_report_label_for_type())) by Day of the Week</h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
533 @ <table class='statistics-report-table-events' border='0'
534 @ cellpadding='2' cellspacing='0' id='statsTable'>
535 @ <thead><tr>
536 @ <th>DoW</th>
537 @ <th>Day</th>
@@ -572,139 +560,114 @@
572
573
574 /*
575 ** Helper for stats_report_by_month_year(), which generates a list of
576 ** week numbers. zTimeframe should be either a timeframe in the form YYYY
577 ** or YYYY-MM.
 
578 */
579 static void stats_report_year_weeks(const char *zUserName){
580 const char *zYear = P("y");
581 int nYear = zYear ? strlen(zYear) : 0;
582 int i = 0;
583 Stmt qYears = empty_Stmt;
584 char *zDefaultYear = NULL;
585 Blob sql = empty_blob;
586 int nMaxEvents = 1; /* max number of events for
587 all rows. */
588 int iterations = 0; /* # of active time periods. */
589 stats_report_init_view();
590 if(4==nYear){
591 Blob urlParams = empty_blob;
592 blob_appendf(&urlParams, "y=%T", zYear);
593 stats_report_event_types_menu("byweek", blob_str(&urlParams));
594 blob_reset(&urlParams);
595 }else{
596 stats_report_event_types_menu("byweek", NULL);
597 }
598 blob_append(&sql,
599 "SELECT DISTINCT substr(date(mtime),1,4) AS y "
600 "FROM v_reports WHERE 1 ", -1);
601 if(zUserName&&*zUserName){
602 blob_append_sql(&sql,"AND user=%Q ", zUserName);
603 }
604 blob_append(&sql,"GROUP BY y ORDER BY y", -1);
605 db_prepare(&qYears, "%s", blob_sql_text(&sql));
606 blob_reset(&sql);
607 cgi_printf("Select year: ");
608 while( SQLITE_ROW == db_step(&qYears) ){
609 const char *zT = db_column_text(&qYears, 0);
610 if( i++ ){
611 cgi_printf(" ");
612 }
613 cgi_printf("<a href='?view=byweek&y=%s&type=%c", zT,
614 (char)statsReportType);
615 if(zUserName && *zUserName){
616 cgi_printf("&user=%t",zUserName);
617 }
618 cgi_printf("'>%s</a>",zT);
619 }
620 db_finalize(&qYears);
621 cgi_printf("<br/>");
622 if(!zYear || !*zYear){
623 zDefaultYear = db_text("????", "SELECT strftime('%%Y')");
624 zYear = zDefaultYear;
625 nYear = 4;
626 }
627 if(4 == nYear){
628 Stmt stWeek = empty_Stmt;
629 int rowCount = 0;
630 int total = 0;
631 Blob header = empty_blob;
632 blob_appendf(&header, "Timeline events (%s) for the calendar weeks "
633 "of %h", stats_report_label_for_type(),
634 zYear);
635 blob_append_sql(&sql,
636 "SELECT DISTINCT strftime('%%W',mtime) AS wk, "
637 "count(*) AS n "
638 "FROM v_reports "
639 "WHERE %Q=substr(date(mtime),1,4) "
640 "AND mtime < current_timestamp ",
641 zYear);
642 if(zUserName&&*zUserName){
643 blob_append_sql(&sql, " AND user=%Q ", zUserName);
644 blob_appendf(&header," for user %h", zUserName);
645 }
646 blob_append_sql(&sql, "GROUP BY wk ORDER BY wk DESC");
647 cgi_printf("<h1>%h</h1>", blob_str(&header));
648 blob_reset(&header);
649 cgi_printf("<table class='statistics-report-table-events' "
650 "border='0' cellpadding='2' width='100%%' "
651 "cellspacing='0' id='statsTable'>");
652 cgi_printf("<thead><tr>"
653 "<th>Week</th>"
654 "<th>Events</th>"
655 "<th width='90%%'><!-- relative commits graph --></th>"
656 "</tr></thead>"
657 "<tbody>");
658 db_prepare(&stWeek, "%s", blob_sql_text(&sql));
659 blob_reset(&sql);
660 while( SQLITE_ROW == db_step(&stWeek) ){
661 const int nCount = db_column_int(&stWeek, 1);
662 if(nCount>nMaxEvents){
663 nMaxEvents = nCount;
664 }
665 ++iterations;
666 }
667 db_reset(&stWeek);
668 while( SQLITE_ROW == db_step(&stWeek) ){
669 const char *zWeek = db_column_text(&stWeek,0);
670 const int nCount = db_column_int(&stWeek,1);
671 int nSize = nCount
672 ? (int)(100 * nCount / nMaxEvents)
673 : 0;
674 if(!nSize) nSize = 1;
675 total += nCount;
676 cgi_printf("<tr class='row%d'>", ++rowCount % 2 );
677 cgi_printf("<td><a href='%R/timeline?yw=%t-%s&n=%d&y=%s",
678 zYear, zWeek, nCount,
679 statsReportTimelineYFlag);
680 if(zUserName && *zUserName){
681 cgi_printf("&u=%t",zUserName);
682 }
683 cgi_printf("'>%s</a></td>",zWeek);
684
685 cgi_printf("<td>%d</td>",nCount);
686 cgi_printf("<td>");
687 if(nCount){
688 cgi_printf("<div class='statistics-report-graph-line'"
689 "style='width:%d%%;'>&nbsp;</div>",
690 nSize);
691 }
692 cgi_printf("</td></tr>");
693 }
694 db_finalize(&stWeek);
695 free(zDefaultYear);
696 cgi_printf("</tbody></table>");
697 if(total){
698 int nAvg = iterations ? (total/iterations) : 0;
699 cgi_printf("<br><div>Total events: %d<br>"
700 "Average per active week: %d</div>",
701 total, nAvg);
702 }
703 output_table_sorting_javascript("statsTable","tnx",-1);
704 }
705 }
706
707 /*
708 ** WEBPAGE: reports
709 **
710 ** Shows activity reports for the repository.
@@ -724,51 +687,94 @@
724 ** y=YYYY The year to report (default is the server's
725 ** current year).
726 */
727 void stats_report_page(){
728 HQuery url; /* URL for various branch links */
729 const char *zView = P("view"); /* Which view/report to show. */
730 const char *zUserName = P("user");
731
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
732 login_check_credentials();
733 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
734 if(!zUserName) zUserName = P("u");
735 url_initialize(&url, "reports");
736 if(zUserName && *zUserName){
737 url_add_parameter(&url,"user", zUserName);
738 statrep_submenu(&url, "(Remove User Flag)", "view", zView, "user");
739 }
740 statrep_submenu(&url, "By Year", "view", "byyear", 0);
741 statrep_submenu(&url, "By Month", "view", "bymonth", 0);
742 statrep_submenu(&url, "By Week", "view", "byweek", 0);
743 statrep_submenu(&url, "By Weekday", "view", "byweekday", 0);
744 statrep_submenu(&url, "By User", "view", "byuser", "user");
745 statrep_submenu(&url, "By File", "view", "byfile", "file");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
746 style_submenu_element("Stats", "Stats", "%R/stat");
747 url_reset(&url);
748 style_header("Activity Reports");
749 if(0==fossil_strcmp(zView,"byyear")){
750 stats_report_by_month_year(0, 0, zUserName);
751 }else if(0==fossil_strcmp(zView,"bymonth")){
752 stats_report_by_month_year(1, 0, zUserName);
753 }else if(0==fossil_strcmp(zView,"byweek")){
754 stats_report_year_weeks(zUserName);
755 }else if(0==fossil_strcmp(zView,"byuser")){
756 stats_report_by_user();
757 }else if(0==fossil_strcmp(zView,"byweekday")){
758 stats_report_day_of_week();
759 }else if(0==fossil_strcmp(zView,"byfile")){
760 stats_report_by_file();
761 }else{
762 @ <h1>Activity Reports:</h1>
763 @ <ul>
764 @ <li>%z(href("?view=byyear"))Events by year</a></li>
765 @ <li>%z(href("?view=bymonth"))Events by month</a></li>
766 @ <li>%z(href("?view=byweek"))Events by calendar week</a></li>
767 @ <li>%z(href("?view=byweekday"))Events by day of the week</a></li>
768 @ <li>%z(href("?view=byuser"))Events by user</a></li>
769 @ <li>%z(href("?view=byfile"))Events by file</a></li>
770 @ </ul>
771 }
772
773 style_footer();
774 }
775
--- src/statrep.c
+++ src/statrep.c
@@ -141,63 +141,10 @@
141 default:
142 return "all types";
143 }
144 }
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
147 /*
148 ** Helper for stats_report_by_month_year(), which generates a list of
149 ** week numbers. zTimeframe should be either a timeframe in the form YYYY
150 ** or YYYY-MM.
@@ -227,23 +174,21 @@
174 }
175
176 /*
177 ** Implements the "byyear" and "bymonth" reports for /reports.
178 ** If includeMonth is true then it generates the "bymonth" report,
179 ** else the "byyear" report. If zUserName is not NULL then the report is
180 ** restricted to events created by the named user account.
 
181 */
182 static void stats_report_by_month_year(char includeMonth,
183 char includeWeeks,
184 const char *zUserName){
185 Stmt query = empty_Stmt;
186 int nRowNumber = 0; /* current TR number */
187 int nEventTotal = 0; /* Total event count */
188 int rowClass = 0; /* counter for alternating
189 row colors */
 
190 const char *zTimeLabel = includeMonth ? "Year/Month" : "Year";
191 char zPrevYear[5] = {0}; /* For keeping track of when
192 we change years while looping */
193 int nEventsPerYear = 0; /* Total event count for the
194 current year */
@@ -252,39 +197,37 @@
197 Blob header = empty_blob; /* Page header text */
198 int nMaxEvents = 1; /* for calculating length of graph
199 bars. */
200 int iterations = 0; /* number of weeks/months we iterate
201 over */
202 Blob userFilter = empty_blob; /* Optional user=johndoe query string */
203 stats_report_init_view();
204 if( zUserName ){
205 blob_appendf(&userFilter, "user=%s", zUserName);
206 }
207 blob_reset(&userFilter);
208 db_prepare(&query,
209 "SELECT substr(date(mtime),1,%d) AS timeframe,"
210 " count(*) AS eventCount"
211 " FROM v_reports"
212 " WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
213 " GROUP BY timeframe"
214 " ORDER BY timeframe DESC",
215 includeMonth ? 7 : 4, zUserName);
216 @ <h1>Timeline Events (%s(stats_report_label_for_type()))
217 @ by year%s(includeMonth ? "/month" : "")
218 if( zUserName ){
219 @ for user %h(zUserName)
220 }
221 @ </h1>
 
 
222 @ <table class='statistics-report-table-events' border='0' cellpadding='2'
223 @ cellspacing='0' id='statsTable'>
224 @ <thead>
225 @ <th>%s(zTimeLabel)</th>
226 @ <th>Events</th>
227 @ <th width='90%%'><!-- relative commits graph --></th>
228 @ </thead><tbody>
 
229 /*
230 Run the query twice. The first time we calculate the maximum
231 number of events for a given row. Maybe someone with better SQL
232 Fu can re-implement this with a single query.
233 */
@@ -335,18 +278,18 @@
278 zTimeframe, nCount,
279 statsReportTimelineYFlag );
280 /* Reminder: n=nCount is not actually correct for bymonth unless
281 that was the only user who caused events.
282 */
283 if( zUserName ){
284 cgi_printf("&u=%t", zUserName);
285 }
286 cgi_printf("' target='_new'>%s</a>",zTimeframe);
287 }else {
288 cgi_printf("<a href='?view=byweek&y=%s&type=%c",
289 zTimeframe, (char)statsReportType);
290 if( zUserName ){
291 cgi_printf("&u=%t", zUserName);
292 }
293 cgi_printf("'>%s</a>", zTimeframe);
294 }
295 @ </td><td>%d(nCount)</td>
@@ -403,25 +346,34 @@
346 int rowClass = 0; /* counter for alternating
347 row colors */
348 int nMaxEvents = 1; /* max number of events for
349 all rows. */
350 stats_report_init_view();
 
 
 
 
 
 
351 @ <h1>Timeline Events
352 @ (%s(stats_report_label_for_type())) by User</h1>
353 db_multi_exec(
354 "CREATE TEMP TABLE piechart(amt,label);"
355 "INSERT INTO piechart SELECT count(*), ifnull(euser,user) FROM v_reports"
356 " GROUP BY ifnull(euser,user) ORDER BY count(*) DESC;"
357 );
358 if( db_int(0, "SELECT count(*) FROM piechart")>=2 ){
359 @ <center><svg width=700 height=400>
360 piechart_render(700, 400, PIE_OTHER|PIE_PERCENT);
361 @ </svg></centre><hr/>
362 }
363 @ <table class='statistics-report-table-events' border='0'
364 @ cellpadding='2' cellspacing='0' id='statsTable'>
365 @ <thead><tr>
366 @ <th>User</th>
367 @ <th>Events</th>
368 @ <th width='90%%'><!-- relative commits graph --></th>
369 @ </tr></thead><tbody>
370 db_prepare(&query,
371 "SELECT ifnull(euser,user), "
372 "COUNT(*) AS eventCount "
373 "FROM v_reports "
374 "GROUP BY ifnull(euser,user) ORDER BY eventCount DESC");
375 while( SQLITE_ROW == db_step(&query) ){
376 const int nCount = db_column_int(&query, 1);
377 if(nCount>nMaxEvents){
378 nMaxEvents = nCount;
379 }
@@ -428,20 +380,21 @@
380 }
381 db_reset(&query);
382 while( SQLITE_ROW == db_step(&query) ){
383 const char *zUser = db_column_text(&query, 0);
384 const int nCount = db_column_int(&query, 1);
385 char y = (char)statsReportType;
386 int nSize = nCount
387 ? (int)(100 * nCount / nMaxEvents)
388 : 0;
389 if(!nCount) continue /* arguable! Possible? */;
390 else if(!nSize) nSize = 1;
391 rowClass = ++nRowNumber % 2;
392 nEventTotal += nCount;
393 @ <tr class='row%d(rowClass)'>
394 @ <td>
395 @ <a href="?view=bymonth&user=%h(zUser)&type=%c(y)">%h(zUser)</a>
396 @ </td><td data-sortkey='%08x(-nCount)'>%d(nCount)</td>
397 @ <td>
398 @ <div class='statistics-report-graph-line'
399 @ style='width:%d(nSize)%%;'>&nbsp;</div>
400 @ </td>
@@ -455,30 +408,37 @@
408 db_finalize(&query);
409 output_table_sorting_javascript("statsTable","tkx",2);
410 }
411
412 /*
413 ** Implements the "byfile" view for /reports. If zUserName is not NULL then the
414 ** report is restricted to events created by the named user account.
415 */
416 static void stats_report_by_file(const char *zUserName){
417 Stmt query;
418 int mxEvent = 1; /* max number of events across all rows */
419 int nRowNumber = 0;
420
421 db_multi_exec(
422 "CREATE TEMP TABLE statrep(filename, cnt);"
423 "INSERT INTO statrep(filename, cnt)"
424 " SELECT filename.name, count(distinct mlink.mid)"
425 " FROM filename, mlink, event"
426 " WHERE filename.fnid=mlink.fnid"
427 " AND mlink.mid=event.objid"
428 " AND ifnull(coalesce(euser,user,'')=%Q,1)"
429 " GROUP BY 1", zUserName
430 );
431 db_prepare(&query,
432 "SELECT filename, cnt FROM statrep ORDER BY cnt DESC, filename /*sort*/"
433 );
434 mxEvent = db_int(1, "SELECT max(cnt) FROM statrep");
435 @ <h1>Check-ins Per File
436 if( zUserName ){
437 @ for user %h(zUserName)
438 }
439 @ </h1>
440 @ <table class='statistics-report-table-events' border='0'
441 @ cellpadding='2' cellspacing='0' id='statsTable'>
442 @ <thead><tr>
443 @ <th>File</th>
444 @ <th>Check-ins</th>
@@ -504,34 +464,62 @@
464 db_finalize(&query);
465 output_table_sorting_javascript("statsTable","tNx",2);
466 }
467
468 /*
469 ** Implements the "byweekday" view for /reports. If zUserName is not NULL then
470 ** the report is restricted to events created by the named user account.
471 */
472 static void stats_report_day_of_week(const char *zUserName){
473 Stmt query = empty_Stmt;
474 int nRowNumber = 0; /* current TR number */
475 int nEventTotal = 0; /* Total event count */
476 int rowClass = 0; /* counter for alternating
477 row colors */
478 int nMaxEvents = 1; /* max number of events for
479 all rows. */
480 Blob userFilter = empty_blob; /* Optional user=johndoe query string */
481 static const char *const daysOfWeek[] = {
482 "Monday", "Tuesday", "Wednesday", "Thursday",
483 "Friday", "Saturday", "Sunday"
484 };
485
486 stats_report_init_view();
487 if( zUserName ){
488 blob_appendf(&userFilter, "user=%s", zUserName);
489 }
490 db_prepare(&query,
491 "SELECT cast(mtime %% 7 AS INTEGER) dow,"
492 " COUNT(*) AS eventCount"
493 " FROM v_reports"
494 " WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
495 " GROUP BY dow ORDER BY dow", zUserName);
496 @ <h1>Timeline Events (%h(stats_report_label_for_type())) by Day of the Week
497 if( zUserName ){
498 @ for user %h(zUserName)
499 }
500 @ </h1>
501 db_multi_exec(
502 "CREATE TEMP TABLE piechart(amt,label);"
503 "INSERT INTO piechart"
504 " SELECT count(*), cast(mtime %% 7 AS INT) FROM v_reports"
505 " WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
506 " GROUP BY 2 ORDER BY 2;"
507 "UPDATE piechart SET label = CASE label"
508 " WHEN 0 THEN 'Monday'"
509 " WHEN 1 THEN 'Tuesday'"
510 " WHEN 2 THEN 'Wednesday'"
511 " WHEN 3 THEN 'Thursday'"
512 " WHEN 4 THEN 'Friday'"
513 " WHEN 5 THEN 'Saturday'"
514 " ELSE 'Sunday' END;", zUserName
515 );
516 if( db_int(0, "SELECT count(*) FROM piechart")>=2 ){
517 @ <center><svg width=700 height=400>
518 piechart_render(700, 400, PIE_OTHER|PIE_PERCENT);
519 @ </svg></centre><hr/>
520 }
521 @ <table class='statistics-report-table-events' border='0'
522 @ cellpadding='2' cellspacing='0' id='statsTable'>
523 @ <thead><tr>
524 @ <th>DoW</th>
525 @ <th>Day</th>
@@ -572,139 +560,114 @@
560
561
562 /*
563 ** Helper for stats_report_by_month_year(), which generates a list of
564 ** week numbers. zTimeframe should be either a timeframe in the form YYYY
565 ** or YYYY-MM. If zUserName is not NULL then the report is restricted to events
566 ** created by the named user account.
567 */
568 static void stats_report_year_weeks(const char *zUserName){
569 const char *zYear = P("y"); /* Year for which report shown */
570 int isValidYear = 0; /* True if a valid year */
571 int i = 0;
572 Stmt q;
 
 
573 int nMaxEvents = 1; /* max number of events for
574 all rows. */
575 int iterations = 0; /* # of active time periods. */
576 int n = 0; /* Number of entries in azYear */
577 char **azYear = 0; /* Year dropdown menu */
578 int rowCount = 0;
579 int total = 0;
580
581 stats_report_init_view();
582 style_submenu_sql("y", "Year:",
583 "WITH RECURSIVE a(b) AS ("
584 " SELECT substr(date('now'),1,4) UNION ALL"
585 " SELECT b-1 FROM a"
586 " WHERE b>0+(SELECT substr(date(min(mtime)),1,4) FROM event)"
587 ") SELECT b, b FROM a ORDER BY b DESC");
588 if( zYear==0 || strlen(zYear)!=4 ){
589 zYear = db_text("1970","SELECT substr(date('now'),1,4);");
590 }
591 cgi_printf("<br/>");
592 db_prepare(&q,
593 "SELECT DISTINCT strftime('%%W',mtime) AS wk, "
594 " count(*) AS n "
595 " FROM v_reports "
596 " WHERE %Q=substr(date(mtime),1,4) "
597 " AND mtime < current_timestamp "
598 " AND ifnull(coalesce(euser,user,'')=%Q,1)"
599 " GROUP BY wk ORDER BY wk DESC", zYear, zUserName);
600 @ <h1>Timeline events (%h(stats_report_label_for_type()))
601 @ for the calendar weeks of %h(zYear)
602 if( zUserName ){
603 @ for user %h(zUserName)
604 }
605 @ </h1>
606 cgi_printf("<table class='statistics-report-table-events' "
607 "border='0' cellpadding='2' width='100%%' "
608 "cellspacing='0' id='statsTable'>");
609 cgi_printf("<thead><tr>"
610 "<th>Week</th>"
611 "<th>Events</th>"
612 "<th width='90%%'><!-- relative commits graph --></th>"
613 "</tr></thead>"
614 "<tbody>");
615 while( SQLITE_ROW == db_step(&q) ){
616 const int nCount = db_column_int(&q, 1);
617 if(nCount>nMaxEvents){
618 nMaxEvents = nCount;
619 }
620 ++iterations;
621 }
622 db_reset(&q);
623 while( SQLITE_ROW == db_step(&q) ){
624 const char *zWeek = db_column_text(&q,0);
625 const int nCount = db_column_int(&q,1);
626 int nSize = nCount
627 ? (int)(100 * nCount / nMaxEvents)
628 : 0;
629 if(!nSize) nSize = 1;
630 total += nCount;
631 cgi_printf("<tr class='row%d'>", ++rowCount % 2 );
632 cgi_printf("<td><a href='%R/timeline?yw=%t-%s&n=%d&y=%s",
633 zYear, zWeek, nCount,
634 statsReportTimelineYFlag);
635 if( zUserName ){
636 cgi_printf("&u=%t",zUserName);
637 }
638 cgi_printf("'>%s</a></td>",zWeek);
639
640 cgi_printf("<td>%d</td>",nCount);
641 cgi_printf("<td>");
642 if(nCount){
643 cgi_printf("<div class='statistics-report-graph-line'"
644 "style='width:%d%%;'>&nbsp;</div>",
645 nSize);
646 }
647 cgi_printf("</td></tr>");
648 }
649 db_finalize(&q);
650 cgi_printf("</tbody></table>");
651 if(total){
652 int nAvg = iterations ? (total/iterations) : 0;
653 cgi_printf("<br><div>Total events: %d<br>"
654 "Average per active week: %d</div>",
655 total, nAvg);
656 }
657 output_table_sorting_javascript("statsTable","tnx",-1);
658 }
659
660 /* Report types
661 */
662 #define RPT_BYFILE 1
663 #define RPT_BYMONTH 2
664 #define RPT_BYUSER 3
665 #define RPT_BYWEEK 4
666 #define RPT_BYWEEKDAY 5
667 #define RPT_BYYEAR 6
668 #define RPT_NONE 0 /* None of the above */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
669
670 /*
671 ** WEBPAGE: reports
672 **
673 ** Shows activity reports for the repository.
@@ -724,51 +687,94 @@
687 ** y=YYYY The year to report (default is the server's
688 ** current year).
689 */
690 void stats_report_page(){
691 HQuery url; /* URL for various branch links */
692 const char *zView = P("view"); /* Which view/report to show. */
693 int eType = RPT_NONE; /* Numeric code for view/report to show */
694 int i; /* Loop counter */
695 const char *zUserName; /* Name of user */
696 const struct {
697 const char *zName; /* Name of view= screen type */
698 const char *zVal; /* Value of view= query parameter */
699 int eType; /* Corresponding RPT_* define */
700 } aViewType[] = {
701 { "File Changes","byfile", RPT_BYFILE },
702 { "By Month", "bymonth", RPT_BYMONTH },
703 { "By User", "byuser", RPT_BYUSER },
704 { "By Week", "byweek", RPT_BYWEEK },
705 { "By Weekday", "byweekday", RPT_BYWEEKDAY },
706 { "By Year", "byyear", RPT_BYYEAR },
707 };
708 const char *azType[] = {
709 "a", "All Changes",
710 "ci", "Check-ins",
711 "g", "Tags",
712 "e", "Tech Notes",
713 "t", "Tickets",
714 "w", "Wiki"
715 };
716
717 login_check_credentials();
718 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
719 zUserName = P("user");
720 if( zUserName==0 ) zUserName = P("u");
721 if( zUserName && zUserName[0]==0 ) zUserName = 0;
722 if( zView==0 ){
723 zView = "byuser";
724 cgi_replace_query_parameter("view","byuser");
725 }
726 for(i=0; i<ArraySize(aViewType); i++){
727 if( fossil_strcmp(zView, aViewType[i].zVal)==0 ){
728 eType = aViewType[i].eType;
729 break;
730 }
731 }
732 url_initialize(&url, "reports");
733 cgi_query_parameters_to_url(&url);
734 if( eType!=RPT_NONE ){
735 int nView = 0; /* Slots used in azView[] */
736 const char *azView[16]; /* Drop-down menu of view types */
737 for(i=0; i<ArraySize(aViewType); i++){
738 azView[nView++] = aViewType[i].zVal;
739 azView[nView++] = aViewType[i].zName;
740 }
741 if( eType!=RPT_BYFILE ){
742 style_submenu_multichoice("type", ArraySize(azType)/2, azType, 0);
743 }
744 style_submenu_multichoice("view", nView/2, azView, 0);
745 if( eType!=RPT_BYUSER ){
746 style_submenu_sql("u","User:",
747 "SELECT '', 'All Users' UNION ALL "
748 "SELECT x, x FROM ("
749 " SELECT DISTINCT trim(coalesce(euser,user)) AS x FROM event %s"
750 " ORDER BY 1 COLLATE nocase) WHERE x!=''",
751 eType==RPT_BYFILE ? "WHERE type='ci'" : ""
752 );
753 }
754 }
755 style_submenu_element("Stats", "Stats", "%R/stat");
756 url_reset(&url);
757 style_header("Activity Reports");
758 switch( eType ){
759 case RPT_BYYEAR:
760 stats_report_by_month_year(0, 0, zUserName);
761 break;
762 case RPT_BYMONTH:
763 stats_report_by_month_year(1, 0, zUserName);
764 break;
765 case RPT_BYWEEK:
766 stats_report_year_weeks(zUserName);
767 break;
768 default:
769 case RPT_BYUSER:
770 stats_report_by_user();
771 break;
772 case RPT_BYWEEKDAY:
773 stats_report_day_of_week(zUserName);
774 break;
775 case RPT_BYFILE:
776 stats_report_by_file(zUserName);
777 break;
778 }
 
 
 
779 style_footer();
780 }
781
+162 -16
--- src/style.c
+++ src/style.c
@@ -285,11 +285,45 @@
285285
aSubmenuCtrl[nSubmenuCtrl].azChoice = azChoice;
286286
aSubmenuCtrl[nSubmenuCtrl].isDisabled = isDisabled;
287287
aSubmenuCtrl[nSubmenuCtrl].eType = FF_MULTI;
288288
nSubmenuCtrl++;
289289
}
290
+void style_submenu_sql(
291
+ const char *zName, /* Query parameter name */
292
+ const char *zLabel, /* Label on the control */
293
+ const char *zFormat, /* Format string for SQL command for choices */
294
+ ... /* Arguments to the format string */
295
+){
296
+ Stmt q;
297
+ int n = 0;
298
+ int nAlloc = 0;
299
+ char **az = 0;
300
+ va_list ap;
290301
302
+ va_start(ap, zFormat);
303
+ db_vprepare(&q, 0, zFormat, ap);
304
+ va_end(ap);
305
+ while( SQLITE_ROW==db_step(&q) ){
306
+ if( n+2>=nAlloc ){
307
+ nAlloc += nAlloc + 20;
308
+ az = fossil_realloc(az, sizeof(char*)*nAlloc);
309
+ }
310
+ az[n++] = fossil_strdup(db_column_text(&q,0));
311
+ az[n++] = fossil_strdup(db_column_text(&q,1));
312
+ }
313
+ db_finalize(&q);
314
+ if( n>0 ){
315
+ aSubmenuCtrl[nSubmenuCtrl].zName = zName;
316
+ aSubmenuCtrl[nSubmenuCtrl].zLabel = zLabel;
317
+ aSubmenuCtrl[nSubmenuCtrl].iSize = n/2;
318
+ aSubmenuCtrl[nSubmenuCtrl].azChoice = (const char**)az;
319
+ aSubmenuCtrl[nSubmenuCtrl].isDisabled = 0;
320
+ aSubmenuCtrl[nSubmenuCtrl].eType = FF_MULTI;
321
+ nSubmenuCtrl++;
322
+ }
323
+}
324
+
291325
292326
/*
293327
** Compare two submenu items for sorting purposes
294328
*/
295329
static int submenuCompare(const void *a, const void *b){
@@ -514,10 +548,13 @@
514548
break;
515549
}
516550
case FF_MULTI: {
517551
int j;
518552
const char *zVal = P(zQPN);
553
+ if( aSubmenuCtrl[i].zLabel ){
554
+ cgi_printf("&nbsp;%h", aSubmenuCtrl[i].zLabel);
555
+ }
519556
cgi_printf(
520557
"<select class='submenuctrl' size='1' name='%s'%s "
521558
"onchange='gebi(\"f01\").submit();'>\n",
522559
zQPN, zDisabled
523560
);
@@ -701,15 +738,108 @@
701738
@ vertical-align: top;
702739
@ text-align: right;
703740
@ white-space: nowrap;
704741
},
705742
{ "td.timelineGraph",
706
- "the format for the grap placeholder cells in timelines",
743
+ "the format for the graph placeholder cells in timelines",
707744
@ width: 20px;
708745
@ text-align: left;
709746
@ vertical-align: top;
710747
},
748
+ { ".tl-canvas",
749
+ "timeline graph canvas",
750
+ @ margin: 0 6px 0 10px;
751
+ },
752
+ { ".tl-rail",
753
+ "maximum rail spacing",
754
+ @ width: 18px;
755
+ },
756
+ { ".tl-mergeoffset",
757
+ "maximum spacing between merge risers and primary child risers",
758
+ @ width: 2px;
759
+ },
760
+ { ".tl-nodemark",
761
+ "adjusts the vertical position of graph nodes",
762
+ @ margin-top: 5px;
763
+ },
764
+ { ".tl-node",
765
+ "commit node",
766
+ @ width: 10px;
767
+ @ height: 10px;
768
+ @ border: 1px solid #000;
769
+ @ background: #fff;
770
+ @ cursor: pointer;
771
+ },
772
+ { ".tl-node.leaf:after",
773
+ "leaf commit marker",
774
+ @ content: '';
775
+ @ position: absolute;
776
+ @ top: 3px;
777
+ @ left: 3px;
778
+ @ width: 4px;
779
+ @ height: 4px;
780
+ @ background: #000;
781
+ },
782
+ { ".tl-node.sel:after",
783
+ "selected commit node marker",
784
+ @ content: '';
785
+ @ position: absolute;
786
+ @ top: 2px;
787
+ @ left: 2px;
788
+ @ width: 6px;
789
+ @ height: 6px;
790
+ @ background: red;
791
+ },
792
+ { ".tl-arrow",
793
+ "arrow",
794
+ @ width: 0;
795
+ @ height: 0;
796
+ @ transform: scale(.999);
797
+ @ border: 0 solid transparent;
798
+ },
799
+ { ".tl-arrow.u",
800
+ "up arrow",
801
+ @ margin-top: -1px;
802
+ @ border-width: 0 3px;
803
+ @ border-bottom: 7px solid #000;
804
+ },
805
+ { ".tl-arrow.u.sm",
806
+ "small up arrow",
807
+ @ border-bottom: 5px solid #000;
808
+ },
809
+ { ".tl-line",
810
+ "line",
811
+ @ background: #000;
812
+ @ width: 2px;
813
+ },
814
+ { ".tl-arrow.merge",
815
+ "merge arrow",
816
+ @ height: 1px;
817
+ @ border-width: 2px 0;
818
+ },
819
+ { ".tl-arrow.merge.l",
820
+ "left merge arrow",
821
+ @ border-right: 3px solid #000;
822
+ },
823
+ { ".tl-arrow.merge.r",
824
+ "right merge arrow",
825
+ @ border-left: 3px solid #000;
826
+ },
827
+ { ".tl-line.merge",
828
+ "merge line",
829
+ @ width: 1px;
830
+ },
831
+ { ".tl-arrow.warp",
832
+ "timewarp arrow",
833
+ @ margin-left: 1px;
834
+ @ border-width: 3px 0;
835
+ @ border-left: 7px solid #600000;
836
+ },
837
+ { ".tl-line.warp",
838
+ "timewarp line",
839
+ @ background: #600000;
840
+ },
711841
{ "a.tagLink",
712842
"the format for the tag links",
713843
@
714844
},
715845
{ "span.tagDsp",
@@ -1226,14 +1356,10 @@
12261356
},
12271357
{ "#usetupEditCapability",
12281358
"format for capabilities string, mentioned on the user edit page",
12291359
@ font-weight: bold;
12301360
},
1231
- { "#canvas", "timeline graph node colors",
1232
- @ color: black;
1233
- @ background-color: white;
1234
- },
12351361
{ "table.adminLogTable",
12361362
"Class for the /admin_log table",
12371363
@ text-align: left;
12381364
},
12391365
{ ".adminLogTable .adminTime",
@@ -1336,30 +1462,50 @@
13361462
}
13371463
}
13381464
}
13391465
13401466
/*
1341
-** Search string zHaystack for zNeedle. zNeedle must be an isolated
1342
-** word with space or punctuation on either size.
1467
+** Search string zCss for zSelector.
13431468
**
13441469
** Return true if found. Return false if not found
13451470
*/
1346
-static int containsString(const char *zHaystack, const char *zNeedle){
1347
- char *z;
1471
+static int containsSelector(const char *zCss, const char *zSelector){
1472
+ const char *z;
13481473
int n;
1474
+ int selectorLen = (int)strlen(zSelector);
13491475
1350
- while( zHaystack[0] ){
1351
- z = strstr(zHaystack, zNeedle);
1476
+ for(z=zCss; *z; z+=selectorLen){
1477
+ z = strstr(z, zSelector);
13521478
if( z==0 ) return 0;
1353
- n = (int)strlen(zNeedle);
1354
- if( (z==zHaystack || !fossil_isalnum(z[-1])) && !fossil_isalnum(z[n]) ){
1355
- return 1;
1479
+ if( z!=zCss ){
1480
+ for( n=-1; z+n!=zCss && fossil_isspace(z[n]); n--);
1481
+ if( z+n!=zCss && z[n]!=',' && z[n]!= '}' && z[n]!='/' ) continue;
13561482
}
1357
- zHaystack = z + n;
1483
+ for( n=selectorLen; z[n] && fossil_isspace(z[n]); n++ );
1484
+ if( z[n]==',' || z[n]=='{' || z[n]=='/' ) return 1;
13581485
}
13591486
return 0;
13601487
}
1488
+
1489
+/*
1490
+** COMMAND: test-contains-selector
1491
+**
1492
+** Usage: %fossil test-contains-selector FILENAME SELECTOR
1493
+**
1494
+** Determine if the CSS stylesheet FILENAME contains SELECTOR.
1495
+*/
1496
+void contains_selector_cmd(void){
1497
+ int found;
1498
+ char *zSelector;
1499
+ Blob css;
1500
+ if( g.argc!=4 ) usage("FILENAME SELECTOR");
1501
+ blob_read_from_file(&css, g.argv[2]);
1502
+ zSelector = g.argv[3];
1503
+ found = containsSelector(blob_str(&css), zSelector);
1504
+ fossil_print("%s %s\n", zSelector, found ? "found" : "not found");
1505
+ blob_reset(&css);
1506
+}
13611507
13621508
13631509
/*
13641510
** WEBPAGE: style.css
13651511
**
@@ -1373,11 +1519,11 @@
13731519
blob_init(&css,skin_get("css"),-1);
13741520
13751521
/* add special missing definitions */
13761522
for(i=1; cssDefaultList[i].elementClass; i++){
13771523
char *z = blob_str(&css);
1378
- if( !containsString(z, cssDefaultList[i].elementClass) ){
1524
+ if( !containsSelector(z, cssDefaultList[i].elementClass) ){
13791525
blob_appendf(&css, "/* %s */\n%s {\n%s}\n",
13801526
cssDefaultList[i].comment,
13811527
cssDefaultList[i].elementClass,
13821528
cssDefaultList[i].value);
13831529
}
13841530
--- src/style.c
+++ src/style.c
@@ -285,11 +285,45 @@
285 aSubmenuCtrl[nSubmenuCtrl].azChoice = azChoice;
286 aSubmenuCtrl[nSubmenuCtrl].isDisabled = isDisabled;
287 aSubmenuCtrl[nSubmenuCtrl].eType = FF_MULTI;
288 nSubmenuCtrl++;
289 }
 
 
 
 
 
 
 
 
 
 
 
290
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
292 /*
293 ** Compare two submenu items for sorting purposes
294 */
295 static int submenuCompare(const void *a, const void *b){
@@ -514,10 +548,13 @@
514 break;
515 }
516 case FF_MULTI: {
517 int j;
518 const char *zVal = P(zQPN);
 
 
 
519 cgi_printf(
520 "<select class='submenuctrl' size='1' name='%s'%s "
521 "onchange='gebi(\"f01\").submit();'>\n",
522 zQPN, zDisabled
523 );
@@ -701,15 +738,108 @@
701 @ vertical-align: top;
702 @ text-align: right;
703 @ white-space: nowrap;
704 },
705 { "td.timelineGraph",
706 "the format for the grap placeholder cells in timelines",
707 @ width: 20px;
708 @ text-align: left;
709 @ vertical-align: top;
710 },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
711 { "a.tagLink",
712 "the format for the tag links",
713 @
714 },
715 { "span.tagDsp",
@@ -1226,14 +1356,10 @@
1226 },
1227 { "#usetupEditCapability",
1228 "format for capabilities string, mentioned on the user edit page",
1229 @ font-weight: bold;
1230 },
1231 { "#canvas", "timeline graph node colors",
1232 @ color: black;
1233 @ background-color: white;
1234 },
1235 { "table.adminLogTable",
1236 "Class for the /admin_log table",
1237 @ text-align: left;
1238 },
1239 { ".adminLogTable .adminTime",
@@ -1336,30 +1462,50 @@
1336 }
1337 }
1338 }
1339
1340 /*
1341 ** Search string zHaystack for zNeedle. zNeedle must be an isolated
1342 ** word with space or punctuation on either size.
1343 **
1344 ** Return true if found. Return false if not found
1345 */
1346 static int containsString(const char *zHaystack, const char *zNeedle){
1347 char *z;
1348 int n;
 
1349
1350 while( zHaystack[0] ){
1351 z = strstr(zHaystack, zNeedle);
1352 if( z==0 ) return 0;
1353 n = (int)strlen(zNeedle);
1354 if( (z==zHaystack || !fossil_isalnum(z[-1])) && !fossil_isalnum(z[n]) ){
1355 return 1;
1356 }
1357 zHaystack = z + n;
 
1358 }
1359 return 0;
1360 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1361
1362
1363 /*
1364 ** WEBPAGE: style.css
1365 **
@@ -1373,11 +1519,11 @@
1373 blob_init(&css,skin_get("css"),-1);
1374
1375 /* add special missing definitions */
1376 for(i=1; cssDefaultList[i].elementClass; i++){
1377 char *z = blob_str(&css);
1378 if( !containsString(z, cssDefaultList[i].elementClass) ){
1379 blob_appendf(&css, "/* %s */\n%s {\n%s}\n",
1380 cssDefaultList[i].comment,
1381 cssDefaultList[i].elementClass,
1382 cssDefaultList[i].value);
1383 }
1384
--- src/style.c
+++ src/style.c
@@ -285,11 +285,45 @@
285 aSubmenuCtrl[nSubmenuCtrl].azChoice = azChoice;
286 aSubmenuCtrl[nSubmenuCtrl].isDisabled = isDisabled;
287 aSubmenuCtrl[nSubmenuCtrl].eType = FF_MULTI;
288 nSubmenuCtrl++;
289 }
290 void style_submenu_sql(
291 const char *zName, /* Query parameter name */
292 const char *zLabel, /* Label on the control */
293 const char *zFormat, /* Format string for SQL command for choices */
294 ... /* Arguments to the format string */
295 ){
296 Stmt q;
297 int n = 0;
298 int nAlloc = 0;
299 char **az = 0;
300 va_list ap;
301
302 va_start(ap, zFormat);
303 db_vprepare(&q, 0, zFormat, ap);
304 va_end(ap);
305 while( SQLITE_ROW==db_step(&q) ){
306 if( n+2>=nAlloc ){
307 nAlloc += nAlloc + 20;
308 az = fossil_realloc(az, sizeof(char*)*nAlloc);
309 }
310 az[n++] = fossil_strdup(db_column_text(&q,0));
311 az[n++] = fossil_strdup(db_column_text(&q,1));
312 }
313 db_finalize(&q);
314 if( n>0 ){
315 aSubmenuCtrl[nSubmenuCtrl].zName = zName;
316 aSubmenuCtrl[nSubmenuCtrl].zLabel = zLabel;
317 aSubmenuCtrl[nSubmenuCtrl].iSize = n/2;
318 aSubmenuCtrl[nSubmenuCtrl].azChoice = (const char**)az;
319 aSubmenuCtrl[nSubmenuCtrl].isDisabled = 0;
320 aSubmenuCtrl[nSubmenuCtrl].eType = FF_MULTI;
321 nSubmenuCtrl++;
322 }
323 }
324
325
326 /*
327 ** Compare two submenu items for sorting purposes
328 */
329 static int submenuCompare(const void *a, const void *b){
@@ -514,10 +548,13 @@
548 break;
549 }
550 case FF_MULTI: {
551 int j;
552 const char *zVal = P(zQPN);
553 if( aSubmenuCtrl[i].zLabel ){
554 cgi_printf("&nbsp;%h", aSubmenuCtrl[i].zLabel);
555 }
556 cgi_printf(
557 "<select class='submenuctrl' size='1' name='%s'%s "
558 "onchange='gebi(\"f01\").submit();'>\n",
559 zQPN, zDisabled
560 );
@@ -701,15 +738,108 @@
738 @ vertical-align: top;
739 @ text-align: right;
740 @ white-space: nowrap;
741 },
742 { "td.timelineGraph",
743 "the format for the graph placeholder cells in timelines",
744 @ width: 20px;
745 @ text-align: left;
746 @ vertical-align: top;
747 },
748 { ".tl-canvas",
749 "timeline graph canvas",
750 @ margin: 0 6px 0 10px;
751 },
752 { ".tl-rail",
753 "maximum rail spacing",
754 @ width: 18px;
755 },
756 { ".tl-mergeoffset",
757 "maximum spacing between merge risers and primary child risers",
758 @ width: 2px;
759 },
760 { ".tl-nodemark",
761 "adjusts the vertical position of graph nodes",
762 @ margin-top: 5px;
763 },
764 { ".tl-node",
765 "commit node",
766 @ width: 10px;
767 @ height: 10px;
768 @ border: 1px solid #000;
769 @ background: #fff;
770 @ cursor: pointer;
771 },
772 { ".tl-node.leaf:after",
773 "leaf commit marker",
774 @ content: '';
775 @ position: absolute;
776 @ top: 3px;
777 @ left: 3px;
778 @ width: 4px;
779 @ height: 4px;
780 @ background: #000;
781 },
782 { ".tl-node.sel:after",
783 "selected commit node marker",
784 @ content: '';
785 @ position: absolute;
786 @ top: 2px;
787 @ left: 2px;
788 @ width: 6px;
789 @ height: 6px;
790 @ background: red;
791 },
792 { ".tl-arrow",
793 "arrow",
794 @ width: 0;
795 @ height: 0;
796 @ transform: scale(.999);
797 @ border: 0 solid transparent;
798 },
799 { ".tl-arrow.u",
800 "up arrow",
801 @ margin-top: -1px;
802 @ border-width: 0 3px;
803 @ border-bottom: 7px solid #000;
804 },
805 { ".tl-arrow.u.sm",
806 "small up arrow",
807 @ border-bottom: 5px solid #000;
808 },
809 { ".tl-line",
810 "line",
811 @ background: #000;
812 @ width: 2px;
813 },
814 { ".tl-arrow.merge",
815 "merge arrow",
816 @ height: 1px;
817 @ border-width: 2px 0;
818 },
819 { ".tl-arrow.merge.l",
820 "left merge arrow",
821 @ border-right: 3px solid #000;
822 },
823 { ".tl-arrow.merge.r",
824 "right merge arrow",
825 @ border-left: 3px solid #000;
826 },
827 { ".tl-line.merge",
828 "merge line",
829 @ width: 1px;
830 },
831 { ".tl-arrow.warp",
832 "timewarp arrow",
833 @ margin-left: 1px;
834 @ border-width: 3px 0;
835 @ border-left: 7px solid #600000;
836 },
837 { ".tl-line.warp",
838 "timewarp line",
839 @ background: #600000;
840 },
841 { "a.tagLink",
842 "the format for the tag links",
843 @
844 },
845 { "span.tagDsp",
@@ -1226,14 +1356,10 @@
1356 },
1357 { "#usetupEditCapability",
1358 "format for capabilities string, mentioned on the user edit page",
1359 @ font-weight: bold;
1360 },
 
 
 
 
1361 { "table.adminLogTable",
1362 "Class for the /admin_log table",
1363 @ text-align: left;
1364 },
1365 { ".adminLogTable .adminTime",
@@ -1336,30 +1462,50 @@
1462 }
1463 }
1464 }
1465
1466 /*
1467 ** Search string zCss for zSelector.
 
1468 **
1469 ** Return true if found. Return false if not found
1470 */
1471 static int containsSelector(const char *zCss, const char *zSelector){
1472 const char *z;
1473 int n;
1474 int selectorLen = (int)strlen(zSelector);
1475
1476 for(z=zCss; *z; z+=selectorLen){
1477 z = strstr(z, zSelector);
1478 if( z==0 ) return 0;
1479 if( z!=zCss ){
1480 for( n=-1; z+n!=zCss && fossil_isspace(z[n]); n--);
1481 if( z+n!=zCss && z[n]!=',' && z[n]!= '}' && z[n]!='/' ) continue;
1482 }
1483 for( n=selectorLen; z[n] && fossil_isspace(z[n]); n++ );
1484 if( z[n]==',' || z[n]=='{' || z[n]=='/' ) return 1;
1485 }
1486 return 0;
1487 }
1488
1489 /*
1490 ** COMMAND: test-contains-selector
1491 **
1492 ** Usage: %fossil test-contains-selector FILENAME SELECTOR
1493 **
1494 ** Determine if the CSS stylesheet FILENAME contains SELECTOR.
1495 */
1496 void contains_selector_cmd(void){
1497 int found;
1498 char *zSelector;
1499 Blob css;
1500 if( g.argc!=4 ) usage("FILENAME SELECTOR");
1501 blob_read_from_file(&css, g.argv[2]);
1502 zSelector = g.argv[3];
1503 found = containsSelector(blob_str(&css), zSelector);
1504 fossil_print("%s %s\n", zSelector, found ? "found" : "not found");
1505 blob_reset(&css);
1506 }
1507
1508
1509 /*
1510 ** WEBPAGE: style.css
1511 **
@@ -1373,11 +1519,11 @@
1519 blob_init(&css,skin_get("css"),-1);
1520
1521 /* add special missing definitions */
1522 for(i=1; cssDefaultList[i].elementClass; i++){
1523 char *z = blob_str(&css);
1524 if( !containsSelector(z, cssDefaultList[i].elementClass) ){
1525 blob_appendf(&css, "/* %s */\n%s {\n%s}\n",
1526 cssDefaultList[i].comment,
1527 cssDefaultList[i].elementClass,
1528 cssDefaultList[i].value);
1529 }
1530
+256 -281
--- src/timeline.c
+++ src/timeline.c
@@ -241,23 +241,17 @@
241241
dateFormat = db_get_int("timeline-date-format", 0);
242242
zDateFmt = P("datefmt");
243243
if( zDateFmt ) dateFormat = atoi(zDateFmt);
244244
if( tmFlags & TIMELINE_GRAPH ){
245245
pGraph = graph_init();
246
- /* style is not moved to css, because this is
247
- ** a technical div for the timeline graph
248
- */
249
- @ <div id="canvas" style="position:relative;height:0px;width:0px;"
250
- @ onclick="clickOnGraph(event)"></div>
251246
}
252247
db_static_prepare(&qbranch,
253248
"SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=:rid",
254249
TAG_BRANCH
255250
);
256251
257
- @ <table id="timelineTable" class="timelineTable"
258
- @ onclick="clickOnGraph(event)">
252
+ @ <table id="timelineTable" class="timelineTable">
259253
blob_zero(&comment);
260254
while( db_step(pQuery)==SQLITE_ROW ){
261255
int rid = db_column_int(pQuery, 0);
262256
const char *zUuid = db_column_text(pQuery, 1);
263257
int isLeaf = db_column_int(pQuery, 5);
@@ -391,11 +385,11 @@
391385
}
392386
db_reset(&qparent);
393387
gidx = graph_add_row(pGraph, rid, nParent, aParent, zBr, zBgClr,
394388
zUuid, isLeaf);
395389
db_reset(&qbranch);
396
- @ <div id="m%d(gidx)"></div>
390
+ @ <div id="m%d(gidx)" class="tl-nodemark"></div>
397391
}
398392
@</td>
399393
if( zBgClr && zBgClr[0] && rid!=selectedRid ){
400394
@ <td class="timelineTableCell" style="background-color: %h(zBgClr);">
401395
}else{
@@ -499,11 +493,11 @@
499493
&& zType[0]=='c' && g.perm.Hyperlink
500494
){
501495
int inUl = 0;
502496
if( !fchngQueryInit ){
503497
db_prepare(&fchngQuery,
504
- "SELECT (pid==0) AS isnew,"
498
+ "SELECT pid,"
505499
" fid,"
506500
" (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
507501
" (SELECT uuid FROM blob WHERE rid=fid),"
508502
" (SELECT uuid FROM blob WHERE rid=pid),"
509503
" (SELECT name FROM filename WHERE fnid=mlink.pfnid) AS oldnm"
@@ -517,11 +511,12 @@
517511
fchngQueryInit = 1;
518512
}
519513
db_bind_int(&fchngQuery, ":mid", rid);
520514
while( db_step(&fchngQuery)==SQLITE_ROW ){
521515
const char *zFilename = db_column_text(&fchngQuery, 2);
522
- int isNew = db_column_int(&fchngQuery, 0);
516
+ int isNew = db_column_int(&fchngQuery, 0)<=0;
517
+ int isMergeNew = db_column_int(&fchngQuery, 0)<0;
523518
int fid = db_column_int(&fchngQuery, 1);
524519
int isDel = fid==0;
525520
const char *zOldName = db_column_text(&fchngQuery, 5);
526521
const char *zOld = db_column_text(&fchngQuery, 4);
527522
const char *zNew = db_column_text(&fchngQuery, 3);
@@ -546,12 +541,17 @@
546541
zA = href("%R/artifact/%!S",fid?zNew:zOld);
547542
if( content_is_private(fid) ){
548543
zUnpub = UNPUB_TAG;
549544
}
550545
if( isNew ){
551
- @ <li> %s(zA)%h(zFilename)</a>%s(zId) %s(zUnpub) (new file) &nbsp;
552
- @ %z(href("%R/artifact/%!S",zNew))[view]</a></li>
546
+ @ <li> %s(zA)%h(zFilename)</a>%s(zId) %s(zUnpub)
547
+ if( isMergeNew ){
548
+ @ (added by merge)
549
+ }else{
550
+ @ (new file)
551
+ }
552
+ @ &nbsp; %z(href("%R/artifact/%!S",zNew))[view]</a></li>
553553
}else if( isDel ){
554554
@ <li> %s(zA)%h(zFilename)</a> (deleted)</li>
555555
}else if( fossil_strcmp(zOld,zNew)==0 && zOldName!=0 ){
556556
@ <li> %h(zOldName) &rarr; %s(zA)%h(zFilename)</a>%s(zId)
557557
@ %s(zUnpub) %z(href("%R/artifact/%!S",zNew))[view]</a></li>
@@ -583,18 +583,11 @@
583583
graph_finish(pGraph, (tmFlags & TIMELINE_DISJOINT)!=0);
584584
if( pGraph->nErr ){
585585
graph_free(pGraph);
586586
pGraph = 0;
587587
}else{
588
- int w;
589
- /* style is not moved to css, because this is
590
- ** a technical div for the timeline graph
591
- */
592
- w = pGraph->mxRail*pGraph->iRailPitch + 28;
593
- @ <tr class="timelineBottom"><td></td><td>
594
- @ <div id="grbtm" style="width:%d(w)px;"></div>
595
- @ </td><td></td></tr>
588
+ @ <tr class="timelineBottom"><td></td><td></td><td></td></tr>
596589
}
597590
}
598591
@ </table>
599592
if( fchngQueryInit ) db_finalize(&fchngQuery);
600593
timeline_output_graph_javascript(pGraph, (tmFlags & TIMELINE_DISJOINT)!=0, 0);
@@ -642,31 +635,34 @@
642635
){
643636
if( pGraph && pGraph->nErr==0 && pGraph->nRow>0 ){
644637
GraphRow *pRow;
645638
int i;
646639
char cSep;
647
- int mergeOffset; /* Pixel offset from rail to merge riser */
648640
int iRailPitch; /* Pixels between consecutive rails */
649641
int showArrowheads; /* True to draw arrowheads. False to omit. */
650642
int circleNodes; /* True for circle nodes. False for square nodes */
651643
int colorGraph; /* Use colors for graph lines */
652644
653
- iRailPitch = pGraph->iRailPitch;
645
+ iRailPitch = atoi(PD("railpitch","0"));
654646
showArrowheads = skin_detail_boolean("timeline-arrowheads");
655647
circleNodes = skin_detail_boolean("timeline-circle-nodes");
656648
colorGraph = skin_detail_boolean("timeline-color-graph-lines");
657649
658
- /* Number of pixels that the thin merge lines are offset from the
659
- ** the center of the think rail lines. If zero, then the vertical
660
- ** merge lines overlap with the thicker rail lines.
661
- */
662
- mergeOffset = iRailPitch>=14 ? 4 : iRailPitch>=13 ? 3 : 0;
663
- if( PB("nomo") ) mergeOffset = 0;
664
-
665
- @ <script>
666
- @ var railPitch=%d(iRailPitch);
667
-
650
+ @ <script>(function(){
651
+ @ "use strict";
652
+ @ var css = "";
653
+ if( circleNodes ){
654
+ @ css += ".tl-node, .tl-node:after { border-radius: 50%%; }";
655
+ }
656
+ if( !showArrowheads ){
657
+ @ css += ".tl-arrow.u { display: none; }";
658
+ }
659
+ @ if( css!=="" ){
660
+ @ var style = document.createElement("style");
661
+ @ style.textContent = css;
662
+ @ document.querySelector("head").appendChild(style);
663
+ @ }
668664
/* the rowinfo[] array contains all the information needed to generate
669665
** the graph. Each entry contains information for a single row:
670666
**
671667
** id: The id of the <div> element for the row. This is an integer.
672668
** to get an actual id, prepend "m" to the integer. The top node
@@ -674,13 +670,13 @@
674670
** bg: The background color for this row
675671
** r: The "rail" that the node for this row sits on. The left-most
676672
** rail is 0 and the number increases to the right.
677673
** d: True if there is a "descender" - an arrow coming from the bottom
678674
** of the page straight up to this node.
679
- ** mo: "merge-out". If non-zero, this is one more than the x-coordinate
675
+ ** mo: "merge-out". If non-negative, this is the rail position
680676
** for the upward portion of a merge arrow. The merge arrow goes up
681
- ** to the row identified by mu:. If this value is zero then
677
+ ** to the row identified by mu:. If this value is negative then
682678
** node has no merge children and no merge-out line is drawn.
683679
** mu: The id of the row which is the top of the merge-out arrow.
684680
** u: Draw a thick child-line out of the top of this node and up to
685681
** the node with an id equal to this value. 0 if it is straight to
686682
** the top of the page, -1 if there is no thick-line riser.
@@ -687,37 +683,25 @@
687683
** f: 0x01: a leaf node.
688684
** au: An array of integers that define thick-line risers for branches.
689685
** The integers are in pairs. For each pair, the first integer is
690686
** is the rail on which the riser should run and the second integer
691687
** is the id of the node upto which the riser should run.
692
- ** mi: "merge-in". An array of integer x-coordinates from which
688
+ ** mi: "merge-in". An array of integer rail positions from which
693689
** merge arrows should be drawn into this node. If the value is
694
- ** negative, then the x-coordinate is the absolute value of mi[]
690
+ ** negative, then the rail position is the absolute value of mi[]
695691
** and a thin merge-arrow descender is drawn to the bottom of
696692
** the screen.
697693
** h: The SHA1 hash of the object being graphed
698694
*/
699695
cgi_printf("var rowinfo = [\n");
700696
for(pRow=pGraph->pFirst; pRow; pRow=pRow->pNext){
701
- int mo = pRow->mergeOut;
702
- if( mo<0 ){
703
- mo = 0;
704
- }else{
705
- int x = (mo/4)*iRailPitch;
706
- switch( mo&3 ){
707
- case 0: x -= mergeOffset-2; break;
708
- case 1: x += 1; break;
709
- case 2: x += mergeOffset+1; break;
710
- }
711
- mo = x;
712
- }
713697
cgi_printf("{id:%d,bg:\"%s\",r:%d,d:%d,mo:%d,mu:%d,u:%d,f:%d,au:",
714698
pRow->idx, /* id */
715699
pRow->zBgClr, /* bg */
716700
pRow->iRail, /* r */
717701
pRow->bDescender, /* d */
718
- mo, /* mo */
702
+ pRow->mergeOut, /* mo */
719703
pRow->mergeUpto, /* mu */
720704
pRow->aiRiser[pRow->iRail], /* u */
721705
pRow->isLeaf ? 1 : 0 /* f */
722706
);
723707
/* u */
@@ -737,13 +721,11 @@
737721
/* mi */
738722
cgi_printf("mi:");
739723
cSep = '[';
740724
for(i=0; i<GR_MAX_RAIL; i++){
741725
if( pRow->mergeIn[i] ){
742
- int mi = i*iRailPitch;
743
- if( pRow->mergeIn[i]==1 ) mi -= mergeOffset-1;
744
- if( pRow->mergeIn[i]==3 ) mi += mergeOffset;
726
+ int mi = i;
745727
if( pRow->mergeDown & (1<<i) ) mi = -mi;
746728
cgi_printf("%c%d", cSep, mi);
747729
cSep = ',';
748730
}
749731
}
@@ -750,246 +732,238 @@
750732
if( cSep=='[' ) cgi_printf("[");
751733
cgi_printf("],h:\"%s\"}%s", pRow->zUuid, pRow->pNext ? ",\n" : "];\n");
752734
}
753735
cgi_printf("var nrail = %d\n", pGraph->mxRail+1);
754736
graph_free(pGraph);
755
- @ var cDiv = gebi("canvas");
756
- @ var csty = window.getComputedStyle && window.getComputedStyle(cDiv,null);
757
- @ var lineClr = (csty && csty.getPropertyValue('color')) || 'black';
758
- @ var bgClr = (csty && csty.getPropertyValue('background-color')) ||'white';
759
- @ if( bgClr=='transparent' ) bgClr = 'white';
760
- @ var boxColor = lineClr;
761
- @ function drawBox(color,x0,y0,x1,y1){
737
+ @ var canvasDiv;
738
+ @ var railPitch;
739
+ @ var mergeOffset;
740
+ @ var node, arrow, arrowSmall, line, mArrow, mLine, wArrow, wLine;
741
+ @ function initGraph(){
742
+ @ var parent = gebi("timelineTable").rows[0].cells[1];
743
+ @ parent.style.verticalAlign = "top";
744
+ @ canvasDiv = document.createElement("div");
745
+ @ canvasDiv.className = "tl-canvas";
746
+ @ canvasDiv.style.position = "absolute";
747
+ @ parent.appendChild(canvasDiv);
748
+ @
749
+ @ var elems = {};
750
+ @ var elemClasses = [
751
+ @ "rail", "mergeoffset", "node", "arrow u", "arrow u sm", "line",
752
+ @ "arrow merge r", "line merge", "arrow warp", "line warp"
753
+ @ ];
754
+ @ for( var i=0; i<elemClasses.length; i++ ){
755
+ @ var cls = elemClasses[i];
756
+ @ var elem = document.createElement("div");
757
+ @ elem.className = "tl-" + cls;
758
+ @ if( cls.indexOf("line")==0 ) elem.className += " v";
759
+ @ canvasDiv.appendChild(elem);
760
+ @ var k = cls.replace(/\s/g, "_");
761
+ @ var r = elem.getBoundingClientRect();
762
+ @ var w = Math.round(r.right - r.left);
763
+ @ var h = Math.round(r.bottom - r.top);
764
+ @ elems[k] = {w: w, h: h, cls: cls};
765
+ @ }
766
+ @ node = elems.node;
767
+ @ arrow = elems.arrow_u;
768
+ @ arrowSmall = elems.arrow_u_sm;
769
+ @ line = elems.line;
770
+ @ mArrow = elems.arrow_merge_r;
771
+ @ mLine = elems.line_merge;
772
+ @ wArrow = elems.arrow_warp;
773
+ @ wLine = elems.line_warp;
774
+ @
775
+ @ var minRailPitch = Math.ceil((node.w+line.w)/2 + mArrow.w + 1);
776
+ if( iRailPitch ){
777
+ @ railPitch = %d(iRailPitch);
778
+ }else{
779
+ @ railPitch = elems.rail.w;
780
+ @ railPitch -= Math.floor((nrail-1)*(railPitch-minRailPitch)/21);
781
+ }
782
+ @ railPitch = Math.max(railPitch, minRailPitch);
783
+ @
784
+ if( PB("nomo") ){
785
+ @ mergeOffset = 0;
786
+ }else{
787
+ @ mergeOffset = railPitch-minRailPitch-mLine.w;
788
+ @ mergeOffset = Math.min(mergeOffset, elems.mergeoffset.w);
789
+ @ mergeOffset = mergeOffset>0 ? mergeOffset + line.w/2 : 0;
790
+ }
791
+ @
792
+ @ var canvasWidth = (nrail-1)*railPitch + node.w;
793
+ @ canvasDiv.style.width = canvasWidth + "px";
794
+ @ canvasDiv.style.position = "relative";
795
+ @ }
796
+ @ function drawBox(cls,color,x0,y0,x1,y1){
762797
@ var n = document.createElement("div");
798
+ @ x0 = Math.floor(x0);
799
+ @ y0 = Math.floor(y0);
800
+ @ x1 = x1 || x1===0 ? Math.floor(x1) : x0;
801
+ @ y1 = y1 || y1===0 ? Math.floor(y1) : y0;
763802
@ if( x0>x1 ){ var t=x0; x0=x1; x1=t; }
764803
@ if( y0>y1 ){ var t=y0; y0=y1; y1=t; }
765
- @ var w = x1-x0+1;
766
- @ var h = y1-y0+1;
804
+ @ var w = x1-x0;
805
+ @ var h = y1-y0;
767806
@ n.style.position = "absolute";
768
- @ n.style.overflow = "hidden";
769807
@ n.style.left = x0+"px";
770808
@ n.style.top = y0+"px";
771
- @ n.style.width = w+"px";
772
- @ n.style.height = h+"px";
773
- @ n.style.backgroundColor = color;
774
- @ cDiv.appendChild(n);
809
+ @ if( w ) n.style.width = w+"px";
810
+ @ if( h ) n.style.height = h+"px";
811
+ @ if( color ) n.style.backgroundColor = color;
812
+ @ n.className = "tl-"+cls;
813
+ @ canvasDiv.appendChild(n);
775814
@ return n;
776815
@ }
777
- @ function absoluteY(id){
778
- @ var obj = gebi(id);
779
- @ if( !obj ) return;
816
+ @ function absoluteY(obj){
780817
@ var top = 0;
781818
@ if( obj.offsetParent ){
782819
@ do{
783820
@ top += obj.offsetTop;
784821
@ }while( obj = obj.offsetParent );
785822
@ }
786823
@ return top;
787824
@ }
788
- @ function absoluteX(id){
789
- @ var obj = gebi(id);
790
- @ if( !obj ) return;
791
- @ var left = 0;
792
- @ if( obj.offsetParent ){
793
- @ do{
794
- @ left += obj.offsetLeft;
795
- @ }while( obj = obj.offsetParent );
796
- @ }
797
- @ return left;
798
- @ }
799
- if( showArrowheads ){
800
- @ function drawUpArrow(x,y0,y1,clr){
801
- @ drawBox(clr,x,y0+4,x+1,y1);
802
- @ var n = document.createElement("div"),
803
- @ l = x-2,
804
- @ t = y0;
805
- @ n.style.position = "absolute";
806
- @ n.style.left = l+"px";
807
- @ n.style.top = t+"px";
808
- @ n.style.width = 0;
809
- @ n.style.height = 0;
810
- @ n.style.transform = "scale(.999)";
811
- @ n.style.borderWidth = 0;
812
- @ n.style.borderStyle = "solid";
813
- @ n.style.borderColor = "transparent";
814
- @ n.style.borderRightWidth = "3px";
815
- @ n.style.borderBottomColor = clr;
816
- @ n.style.borderLeftWidth = "3px";
817
- @ if( y0+10>=y1 ){
818
- @ n.style.borderBottomWidth = "5px";
819
- @ } else {
820
- @ n.style.borderBottomWidth = "7px";
821
- @ }
822
- @ cDiv.appendChild(n);
823
- @ }
824
- }else{
825
- @ function drawUpArrow(x,y0,y1,clr){
826
- @ drawBox(clr,x,y0+1,x+1,y1);
827
- @ }
828
- }
829
- @ function drawThinArrow(y,xFrom,xTo){
830
- @ var n = document.createElement("div"),
831
- @ t = y-2;
832
- @ n.style.position = "absolute";
833
- @ n.style.top = t+"px";
834
- @ n.style.width = 0;
835
- @ n.style.height = "1px";
836
- @ n.style.transform = "scale(.999)";
837
- @ n.style.borderWidth = 0;
838
- @ n.style.borderStyle = "solid";
839
- @ n.style.borderColor = "transparent";
840
- @ n.style.borderTopWidth = "2px";
841
- @ n.style.borderBottomWidth = "2px";
842
- @ if( xFrom<xTo ){
843
- @ drawBox(lineClr,xFrom,y,xTo-3,y);
844
- @ n.style.left = xTo-3+"px";
845
- @ n.style.borderLeftWidth = "3px";
846
- @ n.style.borderLeftColor = lineClr;
847
- @ }else{
848
- @ drawBox(lineClr,xTo+3,y,xFrom,y);
849
- @ n.style.left = xTo+1+"px";
850
- @ n.style.borderRightWidth = "3px";
851
- @ n.style.borderRightColor = lineClr;
852
- @ }
853
- @ cDiv.appendChild(n);
854
- @ }
855
- @ function drawThinLine(x0,y0,x1,y1){
856
- @ drawBox(lineClr,x0,y0,x1,y1);
857
- @ }
858
- @ function drawNodeBox(color,x0,y0,x1,y1){
859
- @ var n = drawBox(color,x0,y0,x1,y1);
860
- @ n.style.cursor = "pointer";
861
- if( circleNodes ){
862
- @ n.style.borderRadius = "6px";
863
- }
864
- @ }
865
- @ function drawNode(p, left, btm){
866
- @ drawNodeBox(boxColor,p.x-5,p.y-5,p.x+6,p.y+6);
867
- @ drawNodeBox(p.bg||bgClr,p.x-4,p.y-4,p.x+5,p.y+5);
868
- @ if( p.u>0 ) drawUpArrow(p.x,rowinfo[p.u-1].y+6,p.y-6,p.fg||lineClr);
869
- @ if( p.f&1 ) drawNodeBox(boxColor,p.x-1,p.y-1,p.x+2,p.y+2);
870
- if( !omitDescenders ){
871
- @ if( p.u==0 ) drawUpArrow(p.x,0,p.y-6,p.fg||lineClr);
872
- @ if( p.d ) drawUpArrow(p.x,p.y+6,btm,p.fg||lineClr);
873
- }
874
- @ if( p.mo>0 ){
875
- @ var x1 = p.mo + left - 1;
876
- @ var y1 = p.y-3;
877
- @ var x0 = x1>p.x ? p.x+7 : p.x-6;
878
- @ var u = rowinfo[p.mu-1];
879
- @ var y0 = u.y+5;
880
- @ if( x1>=p.x-5 && x1<=p.x+5 ){
881
- @ y1 = p.y-5;
882
- @ }else{
883
- @ drawThinLine(x0,y1,x1,y1);
884
- @ }
885
- if( mergeOffset==0 ) cgi_printf("if( p.mo!=p.u-1 ) ");
886
- @ drawThinLine(x1,y0,x1,y1);
887
- @ }
888
- @ var n = p.au.length;
889
- @ for(var i=0; i<n; i+=2){
890
- @ var x1 = p.au[i]*railPitch + left;
891
- @ var x0 = x1>p.x ? p.x+7 : p.x-6;
892
- @ var u = rowinfo[p.au[i+1]-1];
893
- @ if(u.id<p.id){
894
- @ drawBox(u.fg||lineClr,x0,p.y,x1+1,p.y+1);
895
- @ drawUpArrow(x1,u.y+6,p.y,u.fg||lineClr);
896
- @ }else{
897
- @ drawBox("#600000",x0,p.y,x1,p.y+1);
898
- @ drawBox("#600000",x1-1,p.y,x1,u.y+1);
899
- @ drawBox("#600000",x1,u.y,u.x-10,u.y+1);
900
- @ var n = document.createElement("div"),
901
- @ t = u.y-2,
902
- @ l = u.x-11;
903
- @ n.style.position = "absolute";
904
- @ n.style.top = t+"px";
905
- @ n.style.left = l+"px";
906
- @ n.style.width = 0;
907
- @ n.style.height = 0;
908
- @ n.style.transform = "scale(.999)";
909
- @ n.style.borderWidth = 0;
910
- @ n.style.borderStyle = "solid";
911
- @ n.style.borderColor = "transparent";
912
- @ n.style.borderTopWidth = "3px";
913
- @ n.style.borderBottomWidth = "3px";
914
- @ n.style.borderLeftWidth = "7px";
915
- @ n.style.borderLeftColor = "#600000";
916
- @ cDiv.appendChild(n);
917
- @ }
918
- @ }
919
- @ for(var j in p.mi){
920
- @ var y0 = p.y+5;
921
- @ var mx = p.mi[j];
922
- @ if( mx<0 ){
923
- @ mx = left-mx;
924
- @ drawThinLine(mx,y0,mx,btm);
925
- @ }else{
926
- @ mx += left;
927
- @ }
928
- @ if( mx>p.x ){
929
- @ drawThinArrow(y0,mx,p.x+6);
930
- @ }else{
931
- @ drawThinArrow(y0,mx,p.x-5);
932
- @ }
933
- @ }
934
- @ }
935
- @ var selBox = null;
936
- @ var selRow = null;
937
- @ function renderGraph(){
938
- @ var canvasDiv = gebi("canvas");
939
- @ while( canvasDiv.hasChildNodes() ){
940
- @ canvasDiv.removeChild(canvasDiv.firstChild);
941
- @ }
942
- @ var canvasY = absoluteY("timelineTable");
943
- @ var left = absoluteX("m"+rowinfo[0].id) - absoluteX("canvas") + 15;
944
- @ for(var i in rowinfo){
945
- @ rowinfo[i].y = absoluteY("m"+rowinfo[i].id) + 10 - canvasY;
946
- @ rowinfo[i].x = left + rowinfo[i].r*railPitch;
947
- @ }
948
- @ var btm = absoluteY("grbtm") + 10 - canvasY;
949
- @ for(var i in rowinfo){
950
- @ drawNode(rowinfo[i], left, btm);
951
- @ }
952
- @ if( selRow!=null ) clickOnRow(selRow);
953
- @ }
954
- @ function clickOnGraph(event){
955
- @ var x=event.clientX-absoluteX("canvas");
956
- @ var y=event.clientY-absoluteY("canvas");
957
- @ if(window.pageXOffset!=null){
958
- @ x += window.pageXOffset;
959
- @ y += window.pageYOffset;
960
- @ }else{
961
- @ var d = window.document.documentElement;
962
- @ if(document.compatMode!="CSS1Compat") d = d.body;
963
- @ x += d.scrollLeft;
964
- @ y += d.scrollTop;
965
- @ }
966
- if( P("clicktest")!=0 ){
967
- @ alert("click at "+x+","+y)
968
- }
969
- @ for(var i in rowinfo){
970
- @ p = rowinfo[i];
971
- @ if( p.y<y-11 ) continue;
972
- @ if( p.y>y+9 ) break;
973
- @ if( p.x>x-11 && p.x<x+9 ){
974
- @ clickOnRow(p);
975
- @ break;
976
- @ }
977
- @ }
978
- @ }
979
- @ function clickOnRow(p){
980
- @ if( selRow==null ){
981
- @ selBox = drawBox("red",p.x-2,p.y-2,p.x+3,p.y+3);
982
- if( circleNodes ){
983
- @ selBox.style.borderRadius="6px";
984
- }
985
- @ selRow = p;
986
- @ }else if( selRow==p ){
987
- @ var canvasDiv = gebi("canvas");
988
- @ canvasDiv.removeChild(selBox);
989
- @ selBox = null;
990
- @ selRow = null;
825
+ @ function miLineY(p){
826
+ @ return p.y + node.h - mLine.w - 1;
827
+ @ }
828
+ @ function drawLine(elem,color,x0,y0,x1,y1){
829
+ @ var cls = elem.cls + " ";
830
+ @ if( x1===null ){
831
+ @ x1 = x0+elem.w;
832
+ @ cls += "v";
833
+ @ }else{
834
+ @ y1 = y0+elem.w;
835
+ @ cls += "h";
836
+ @ }
837
+ @ drawBox(cls,color,x0,y0,x1,y1);
838
+ @ }
839
+ @ function drawUpArrow(from,to,color){
840
+ @ var y = to.y + node.h;
841
+ @ var arrowSpace = from.y - y + (!from.id || from.r!=to.r ? node.h/2 : 0);
842
+ @ var arw = arrowSpace < arrow.h*1.5 ? arrowSmall : arrow;
843
+ @ var x = to.x + (node.w-line.w)/2;
844
+ @ var y0 = from.y + node.h/2;
845
+ @ var y1 = Math.ceil(to.y + node.h + arw.h/2);
846
+ @ drawLine(line,color,x,y0,null,y1);
847
+ @ x = to.x + (node.w-arw.w)/2;
848
+ @ var n = drawBox(arw.cls,null,x,y);
849
+ @ n.style.borderBottomColor = color;
850
+ @ }
851
+ @ function drawMergeLine(x0,y0,x1,y1){
852
+ @ drawLine(mLine,null,x0,y0,x1,y1);
853
+ @ }
854
+ @ function drawMergeArrow(p,rail){
855
+ @ var x0 = rail*railPitch + node.w/2;
856
+ @ if( rail in mergeLines ){
857
+ @ x0 += mergeLines[rail];
858
+ @ if( p.r<rail ) x0 += mLine.w;
859
+ @ }else{
860
+ @ x0 += (p.r<rail ? -1 : 1)*line.w/2;
861
+ @ }
862
+ @ var x1 = mArrow.w ? mArrow.w/2 : -node.w/2;
863
+ @ x1 = p.x + (p.r<rail ? node.w + Math.ceil(x1) : -x1);
864
+ @ var y = miLineY(p);
865
+ @ drawMergeLine(x0,y,x1,null);
866
+ @ var x = p.x + (p.r<rail ? node.w : -mArrow.w);
867
+ @ var cls = "arrow merge " + (p.r<rail ? "l" : "r");
868
+ @ drawBox(cls,null,x,y+(mLine.w-mArrow.h)/2);
869
+ @ }
870
+ @ function drawNode(p, btm){
871
+ @ if( p.u>0 ) drawUpArrow(p,rowinfo[p.u-1],p.fg);
872
+ @ var cls = node.cls;
873
+ @ if( p.mi.length ) cls += " merge";
874
+ @ if( p.f&1 ) cls += " leaf";
875
+ @ var n = drawBox(cls,p.bg,p.x,p.y);
876
+ @ n.id = "tln"+p.id;
877
+ @ n.onclick = clickOnNode;
878
+ @ n.style.zIndex = 10;
879
+ if( !omitDescenders ){
880
+ @ if( p.u==0 ) drawUpArrow(p,{x: p.x, y: -node.h},p.fg);
881
+ @ if( p.d ) drawUpArrow({x: p.x, y: btm-node.h/2},p,p.fg);
882
+ }
883
+ @ if( p.mo>=0 ){
884
+ @ var x0 = p.x + node.w/2;
885
+ @ var x1 = p.mo*railPitch + node.w/2;
886
+ @ var u = rowinfo[p.mu-1];
887
+ @ var y1 = miLineY(u);
888
+ @ if( p.u<0 || p.mo!=p.r ){
889
+ @ x1 += mergeLines[p.mo] = -mLine.w/2;
890
+ @ var y0 = p.y+2;
891
+ @ if( p.r!=p.mo ) drawMergeLine(x0,y0,x1+(x0<x1 ? mLine.w : 0),null);
892
+ @ drawMergeLine(x1,y0+mLine.w,null,y1);
893
+ @ }else if( mergeOffset ){
894
+ @ mergeLines[p.mo] = u.r<p.r ? -mergeOffset-mLine.w : mergeOffset;
895
+ @ x1 += mergeLines[p.mo];
896
+ @ drawMergeLine(x1,p.y+node.h/2,null,y1);
897
+ @ }else{
898
+ @ delete mergeLines[p.mo];
899
+ @ }
900
+ @ }
901
+ @ for( var i=0; i<p.au.length; i+=2 ){
902
+ @ var rail = p.au[i];
903
+ @ var x0 = p.x + node.w/2;
904
+ @ var x1 = rail*railPitch + (node.w-line.w)/2;
905
+ @ if( x0<x1 ){
906
+ @ x0 = Math.ceil(x0);
907
+ @ x1 += line.w;
908
+ @ }
909
+ @ var y0 = p.y + (node.h-line.w)/2;
910
+ @ var u = rowinfo[p.au[i+1]-1];
911
+ @ if( u.id<p.id ){
912
+ @ drawLine(line,u.fg,x0,y0,x1,null);
913
+ @ drawUpArrow(p,u,u.fg);
914
+ @ }else{
915
+ @ var y1 = u.y + (node.h-line.w)/2;
916
+ @ drawLine(wLine,u.fg,x0,y0,x1,null);
917
+ @ drawLine(wLine,u.fg,x1-line.w,y0,null,y1+line.w);
918
+ @ drawLine(wLine,u.fg,x1,y1,u.x-wArrow.w/2,null);
919
+ @ var x = u.x-wArrow.w;
920
+ @ var y = u.y+(node.h-wArrow.h)/2;
921
+ @ var n = drawBox(wArrow.cls,null,x,y);
922
+ @ if( u.fg ) n.style.borderLeftColor = u.fg;
923
+ @ }
924
+ @ }
925
+ @ for( var i=0; i<p.mi.length; i++ ){
926
+ @ var rail = p.mi[i];
927
+ @ if( rail<0 ){
928
+ @ rail = -rail;
929
+ @ mergeLines[rail] = -mLine.w/2;
930
+ @ var x = rail*railPitch + (node.w-mLine.w)/2;
931
+ @ drawMergeLine(x,miLineY(p),null,btm);
932
+ @ }
933
+ @ drawMergeArrow(p,rail);
934
+ @ }
935
+ @ }
936
+ @ var mergeLines;
937
+ @ function renderGraph(){
938
+ @ mergeLines = {};
939
+ @ canvasDiv.innerHTML = "";
940
+ @ var canvasY = absoluteY(canvasDiv);
941
+ @ for( var i=0; i<rowinfo.length; i++ ){
942
+ @ rowinfo[i].y = absoluteY(gebi("m"+rowinfo[i].id)) - canvasY;
943
+ @ rowinfo[i].x = rowinfo[i].r*railPitch;
944
+ @ }
945
+ @ var tlBtm = document.querySelector(".timelineBottom");
946
+ @ if( tlBtm.offsetHeight<node.h ){
947
+ @ tlBtm.style.height = node.h + "px";
948
+ @ }
949
+ @ var btm = absoluteY(tlBtm) - canvasY + tlBtm.offsetHeight;
950
+ @ for( var i=rowinfo.length-1; i>=0; i-- ){
951
+ @ drawNode(rowinfo[i], btm);
952
+ @ }
953
+ @ }
954
+ @ var selRow;
955
+ @ function clickOnNode(){
956
+ @ var p = rowinfo[parseInt(this.id.match(/\d+$/)[0], 10)-1];
957
+ @ if( !selRow ){
958
+ @ selRow = p;
959
+ @ this.className += " sel";
960
+ @ canvasDiv.className += " sel";
961
+ @ }else if( selRow==p ){
962
+ @ selRow = null;
963
+ @ this.className = this.className.replace(" sel", "");
964
+ @ canvasDiv.className = canvasDiv.className.replace(" sel", "");
991965
@ }else{
992966
if( fileDiff ){
993967
@ location.href="%R/fdiff?v1="+selRow.h+"&v2="+p.h+"&sbs=1";
994968
}else{
995969
if( db_get_boolean("show-version-diffs", 0)==0 ){
@@ -998,22 +972,23 @@
998972
@ location.href="%R/vdiff?from="+selRow.h+"&to="+p.h+"&sbs=1";
999973
}
1000974
}
1001975
@ }
1002976
@ }
1003
- @ var lastId = "m"+rowinfo[rowinfo.length-1].id;
977
+ @ var lastRow = gebi("m"+rowinfo[rowinfo.length-1].id);
1004978
@ var lastY = 0;
1005979
@ function checkHeight(){
1006
- @ var h = absoluteY(lastId);
980
+ @ var h = absoluteY(lastRow);
1007981
@ if( h!=lastY ){
1008982
@ renderGraph();
1009983
@ lastY = h;
1010984
@ }
1011
- @ setTimeout("checkHeight();", 1000);
985
+ @ setTimeout(checkHeight, 1000);
1012986
@ }
987
+ @ initGraph();
1013988
@ checkHeight();
1014
- @ </script>
989
+ @ }())</script>
1015990
}
1016991
}
1017992
1018993
/*
1019994
** Create a temporary table suitable for storing timeline data.
@@ -1302,24 +1277,24 @@
13021277
return;
13031278
}
13041279
url_initialize(&url, "timeline");
13051280
cgi_query_parameters_to_url(&url);
13061281
if( zTagName && g.perm.Read ){
1307
- tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='sym-%q'", zTagName);
1282
+ tagid = db_int(-1,"SELECT tagid FROM tag WHERE tagname='sym-%q'",zTagName);
13081283
zThisTag = zTagName;
13091284
}else if( zBrName && g.perm.Read ){
1310
- tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='sym-%q'",zBrName);
1285
+ tagid = db_int(-1,"SELECT tagid FROM tag WHERE tagname='sym-%q'",zBrName);
13111286
zThisTag = zBrName;
13121287
}else{
13131288
tagid = 0;
13141289
}
13151290
if( zMark && zMark[0]==0 ){
13161291
if( zAfter ) zMark = zAfter;
13171292
if( zBefore ) zMark = zBefore;
13181293
if( zCirca ) zMark = zCirca;
13191294
}
1320
- if( tagid>0
1295
+ if( tagid
13211296
&& db_int(0,"SELECT count(*) FROM tagxref WHERE tagid=%d",tagid)<=nEntry
13221297
){
13231298
nEntry = -1;
13241299
zCirca = 0;
13251300
}
@@ -1518,11 +1493,11 @@
15181493
}
15191494
else if( zYearWeek ){
15201495
blob_append_sql(&sql, " AND %Q=strftime('%%Y-%%W',event.mtime) ",
15211496
zYearWeek);
15221497
}
1523
- if( tagid>0 ){
1498
+ if( tagid ){
15241499
blob_append_sql(&sql,
15251500
" AND (EXISTS(SELECT 1 FROM tagxref"
15261501
" WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)\n", tagid);
15271502
15281503
if( zBrName ){
@@ -1873,11 +1848,11 @@
18731848
fossil_free(zFree);
18741849
18751850
if(verboseFlag){
18761851
if( !fchngQueryInit ){
18771852
db_prepare(&fchngQuery,
1878
- "SELECT (pid==0) AS isnew,"
1853
+ "SELECT (pid<=0) AS isnew,"
18791854
" (fid==0) AS isdel,"
18801855
" (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
18811856
" (SELECT uuid FROM blob WHERE rid=fid),"
18821857
" (SELECT uuid FROM blob WHERE rid=pid)"
18831858
" FROM mlink"
18841859
--- src/timeline.c
+++ src/timeline.c
@@ -241,23 +241,17 @@
241 dateFormat = db_get_int("timeline-date-format", 0);
242 zDateFmt = P("datefmt");
243 if( zDateFmt ) dateFormat = atoi(zDateFmt);
244 if( tmFlags & TIMELINE_GRAPH ){
245 pGraph = graph_init();
246 /* style is not moved to css, because this is
247 ** a technical div for the timeline graph
248 */
249 @ <div id="canvas" style="position:relative;height:0px;width:0px;"
250 @ onclick="clickOnGraph(event)"></div>
251 }
252 db_static_prepare(&qbranch,
253 "SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=:rid",
254 TAG_BRANCH
255 );
256
257 @ <table id="timelineTable" class="timelineTable"
258 @ onclick="clickOnGraph(event)">
259 blob_zero(&comment);
260 while( db_step(pQuery)==SQLITE_ROW ){
261 int rid = db_column_int(pQuery, 0);
262 const char *zUuid = db_column_text(pQuery, 1);
263 int isLeaf = db_column_int(pQuery, 5);
@@ -391,11 +385,11 @@
391 }
392 db_reset(&qparent);
393 gidx = graph_add_row(pGraph, rid, nParent, aParent, zBr, zBgClr,
394 zUuid, isLeaf);
395 db_reset(&qbranch);
396 @ <div id="m%d(gidx)"></div>
397 }
398 @</td>
399 if( zBgClr && zBgClr[0] && rid!=selectedRid ){
400 @ <td class="timelineTableCell" style="background-color: %h(zBgClr);">
401 }else{
@@ -499,11 +493,11 @@
499 && zType[0]=='c' && g.perm.Hyperlink
500 ){
501 int inUl = 0;
502 if( !fchngQueryInit ){
503 db_prepare(&fchngQuery,
504 "SELECT (pid==0) AS isnew,"
505 " fid,"
506 " (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
507 " (SELECT uuid FROM blob WHERE rid=fid),"
508 " (SELECT uuid FROM blob WHERE rid=pid),"
509 " (SELECT name FROM filename WHERE fnid=mlink.pfnid) AS oldnm"
@@ -517,11 +511,12 @@
517 fchngQueryInit = 1;
518 }
519 db_bind_int(&fchngQuery, ":mid", rid);
520 while( db_step(&fchngQuery)==SQLITE_ROW ){
521 const char *zFilename = db_column_text(&fchngQuery, 2);
522 int isNew = db_column_int(&fchngQuery, 0);
 
523 int fid = db_column_int(&fchngQuery, 1);
524 int isDel = fid==0;
525 const char *zOldName = db_column_text(&fchngQuery, 5);
526 const char *zOld = db_column_text(&fchngQuery, 4);
527 const char *zNew = db_column_text(&fchngQuery, 3);
@@ -546,12 +541,17 @@
546 zA = href("%R/artifact/%!S",fid?zNew:zOld);
547 if( content_is_private(fid) ){
548 zUnpub = UNPUB_TAG;
549 }
550 if( isNew ){
551 @ <li> %s(zA)%h(zFilename)</a>%s(zId) %s(zUnpub) (new file) &nbsp;
552 @ %z(href("%R/artifact/%!S",zNew))[view]</a></li>
 
 
 
 
 
553 }else if( isDel ){
554 @ <li> %s(zA)%h(zFilename)</a> (deleted)</li>
555 }else if( fossil_strcmp(zOld,zNew)==0 && zOldName!=0 ){
556 @ <li> %h(zOldName) &rarr; %s(zA)%h(zFilename)</a>%s(zId)
557 @ %s(zUnpub) %z(href("%R/artifact/%!S",zNew))[view]</a></li>
@@ -583,18 +583,11 @@
583 graph_finish(pGraph, (tmFlags & TIMELINE_DISJOINT)!=0);
584 if( pGraph->nErr ){
585 graph_free(pGraph);
586 pGraph = 0;
587 }else{
588 int w;
589 /* style is not moved to css, because this is
590 ** a technical div for the timeline graph
591 */
592 w = pGraph->mxRail*pGraph->iRailPitch + 28;
593 @ <tr class="timelineBottom"><td></td><td>
594 @ <div id="grbtm" style="width:%d(w)px;"></div>
595 @ </td><td></td></tr>
596 }
597 }
598 @ </table>
599 if( fchngQueryInit ) db_finalize(&fchngQuery);
600 timeline_output_graph_javascript(pGraph, (tmFlags & TIMELINE_DISJOINT)!=0, 0);
@@ -642,31 +635,34 @@
642 ){
643 if( pGraph && pGraph->nErr==0 && pGraph->nRow>0 ){
644 GraphRow *pRow;
645 int i;
646 char cSep;
647 int mergeOffset; /* Pixel offset from rail to merge riser */
648 int iRailPitch; /* Pixels between consecutive rails */
649 int showArrowheads; /* True to draw arrowheads. False to omit. */
650 int circleNodes; /* True for circle nodes. False for square nodes */
651 int colorGraph; /* Use colors for graph lines */
652
653 iRailPitch = pGraph->iRailPitch;
654 showArrowheads = skin_detail_boolean("timeline-arrowheads");
655 circleNodes = skin_detail_boolean("timeline-circle-nodes");
656 colorGraph = skin_detail_boolean("timeline-color-graph-lines");
657
658 /* Number of pixels that the thin merge lines are offset from the
659 ** the center of the think rail lines. If zero, then the vertical
660 ** merge lines overlap with the thicker rail lines.
661 */
662 mergeOffset = iRailPitch>=14 ? 4 : iRailPitch>=13 ? 3 : 0;
663 if( PB("nomo") ) mergeOffset = 0;
664
665 @ <script>
666 @ var railPitch=%d(iRailPitch);
667
 
 
 
 
668 /* the rowinfo[] array contains all the information needed to generate
669 ** the graph. Each entry contains information for a single row:
670 **
671 ** id: The id of the <div> element for the row. This is an integer.
672 ** to get an actual id, prepend "m" to the integer. The top node
@@ -674,13 +670,13 @@
674 ** bg: The background color for this row
675 ** r: The "rail" that the node for this row sits on. The left-most
676 ** rail is 0 and the number increases to the right.
677 ** d: True if there is a "descender" - an arrow coming from the bottom
678 ** of the page straight up to this node.
679 ** mo: "merge-out". If non-zero, this is one more than the x-coordinate
680 ** for the upward portion of a merge arrow. The merge arrow goes up
681 ** to the row identified by mu:. If this value is zero then
682 ** node has no merge children and no merge-out line is drawn.
683 ** mu: The id of the row which is the top of the merge-out arrow.
684 ** u: Draw a thick child-line out of the top of this node and up to
685 ** the node with an id equal to this value. 0 if it is straight to
686 ** the top of the page, -1 if there is no thick-line riser.
@@ -687,37 +683,25 @@
687 ** f: 0x01: a leaf node.
688 ** au: An array of integers that define thick-line risers for branches.
689 ** The integers are in pairs. For each pair, the first integer is
690 ** is the rail on which the riser should run and the second integer
691 ** is the id of the node upto which the riser should run.
692 ** mi: "merge-in". An array of integer x-coordinates from which
693 ** merge arrows should be drawn into this node. If the value is
694 ** negative, then the x-coordinate is the absolute value of mi[]
695 ** and a thin merge-arrow descender is drawn to the bottom of
696 ** the screen.
697 ** h: The SHA1 hash of the object being graphed
698 */
699 cgi_printf("var rowinfo = [\n");
700 for(pRow=pGraph->pFirst; pRow; pRow=pRow->pNext){
701 int mo = pRow->mergeOut;
702 if( mo<0 ){
703 mo = 0;
704 }else{
705 int x = (mo/4)*iRailPitch;
706 switch( mo&3 ){
707 case 0: x -= mergeOffset-2; break;
708 case 1: x += 1; break;
709 case 2: x += mergeOffset+1; break;
710 }
711 mo = x;
712 }
713 cgi_printf("{id:%d,bg:\"%s\",r:%d,d:%d,mo:%d,mu:%d,u:%d,f:%d,au:",
714 pRow->idx, /* id */
715 pRow->zBgClr, /* bg */
716 pRow->iRail, /* r */
717 pRow->bDescender, /* d */
718 mo, /* mo */
719 pRow->mergeUpto, /* mu */
720 pRow->aiRiser[pRow->iRail], /* u */
721 pRow->isLeaf ? 1 : 0 /* f */
722 );
723 /* u */
@@ -737,13 +721,11 @@
737 /* mi */
738 cgi_printf("mi:");
739 cSep = '[';
740 for(i=0; i<GR_MAX_RAIL; i++){
741 if( pRow->mergeIn[i] ){
742 int mi = i*iRailPitch;
743 if( pRow->mergeIn[i]==1 ) mi -= mergeOffset-1;
744 if( pRow->mergeIn[i]==3 ) mi += mergeOffset;
745 if( pRow->mergeDown & (1<<i) ) mi = -mi;
746 cgi_printf("%c%d", cSep, mi);
747 cSep = ',';
748 }
749 }
@@ -750,246 +732,238 @@
750 if( cSep=='[' ) cgi_printf("[");
751 cgi_printf("],h:\"%s\"}%s", pRow->zUuid, pRow->pNext ? ",\n" : "];\n");
752 }
753 cgi_printf("var nrail = %d\n", pGraph->mxRail+1);
754 graph_free(pGraph);
755 @ var cDiv = gebi("canvas");
756 @ var csty = window.getComputedStyle && window.getComputedStyle(cDiv,null);
757 @ var lineClr = (csty && csty.getPropertyValue('color')) || 'black';
758 @ var bgClr = (csty && csty.getPropertyValue('background-color')) ||'white';
759 @ if( bgClr=='transparent' ) bgClr = 'white';
760 @ var boxColor = lineClr;
761 @ function drawBox(color,x0,y0,x1,y1){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
762 @ var n = document.createElement("div");
 
 
 
 
763 @ if( x0>x1 ){ var t=x0; x0=x1; x1=t; }
764 @ if( y0>y1 ){ var t=y0; y0=y1; y1=t; }
765 @ var w = x1-x0+1;
766 @ var h = y1-y0+1;
767 @ n.style.position = "absolute";
768 @ n.style.overflow = "hidden";
769 @ n.style.left = x0+"px";
770 @ n.style.top = y0+"px";
771 @ n.style.width = w+"px";
772 @ n.style.height = h+"px";
773 @ n.style.backgroundColor = color;
774 @ cDiv.appendChild(n);
 
775 @ return n;
776 @ }
777 @ function absoluteY(id){
778 @ var obj = gebi(id);
779 @ if( !obj ) return;
780 @ var top = 0;
781 @ if( obj.offsetParent ){
782 @ do{
783 @ top += obj.offsetTop;
784 @ }while( obj = obj.offsetParent );
785 @ }
786 @ return top;
787 @ }
788 @ function absoluteX(id){
789 @ var obj = gebi(id);
790 @ if( !obj ) return;
791 @ var left = 0;
792 @ if( obj.offsetParent ){
793 @ do{
794 @ left += obj.offsetLeft;
795 @ }while( obj = obj.offsetParent );
796 @ }
797 @ return left;
798 @ }
799 if( showArrowheads ){
800 @ function drawUpArrow(x,y0,y1,clr){
801 @ drawBox(clr,x,y0+4,x+1,y1);
802 @ var n = document.createElement("div"),
803 @ l = x-2,
804 @ t = y0;
805 @ n.style.position = "absolute";
806 @ n.style.left = l+"px";
807 @ n.style.top = t+"px";
808 @ n.style.width = 0;
809 @ n.style.height = 0;
810 @ n.style.transform = "scale(.999)";
811 @ n.style.borderWidth = 0;
812 @ n.style.borderStyle = "solid";
813 @ n.style.borderColor = "transparent";
814 @ n.style.borderRightWidth = "3px";
815 @ n.style.borderBottomColor = clr;
816 @ n.style.borderLeftWidth = "3px";
817 @ if( y0+10>=y1 ){
818 @ n.style.borderBottomWidth = "5px";
819 @ } else {
820 @ n.style.borderBottomWidth = "7px";
821 @ }
822 @ cDiv.appendChild(n);
823 @ }
824 }else{
825 @ function drawUpArrow(x,y0,y1,clr){
826 @ drawBox(clr,x,y0+1,x+1,y1);
827 @ }
828 }
829 @ function drawThinArrow(y,xFrom,xTo){
830 @ var n = document.createElement("div"),
831 @ t = y-2;
832 @ n.style.position = "absolute";
833 @ n.style.top = t+"px";
834 @ n.style.width = 0;
835 @ n.style.height = "1px";
836 @ n.style.transform = "scale(.999)";
837 @ n.style.borderWidth = 0;
838 @ n.style.borderStyle = "solid";
839 @ n.style.borderColor = "transparent";
840 @ n.style.borderTopWidth = "2px";
841 @ n.style.borderBottomWidth = "2px";
842 @ if( xFrom<xTo ){
843 @ drawBox(lineClr,xFrom,y,xTo-3,y);
844 @ n.style.left = xTo-3+"px";
845 @ n.style.borderLeftWidth = "3px";
846 @ n.style.borderLeftColor = lineClr;
847 @ }else{
848 @ drawBox(lineClr,xTo+3,y,xFrom,y);
849 @ n.style.left = xTo+1+"px";
850 @ n.style.borderRightWidth = "3px";
851 @ n.style.borderRightColor = lineClr;
852 @ }
853 @ cDiv.appendChild(n);
854 @ }
855 @ function drawThinLine(x0,y0,x1,y1){
856 @ drawBox(lineClr,x0,y0,x1,y1);
857 @ }
858 @ function drawNodeBox(color,x0,y0,x1,y1){
859 @ var n = drawBox(color,x0,y0,x1,y1);
860 @ n.style.cursor = "pointer";
861 if( circleNodes ){
862 @ n.style.borderRadius = "6px";
863 }
864 @ }
865 @ function drawNode(p, left, btm){
866 @ drawNodeBox(boxColor,p.x-5,p.y-5,p.x+6,p.y+6);
867 @ drawNodeBox(p.bg||bgClr,p.x-4,p.y-4,p.x+5,p.y+5);
868 @ if( p.u>0 ) drawUpArrow(p.x,rowinfo[p.u-1].y+6,p.y-6,p.fg||lineClr);
869 @ if( p.f&1 ) drawNodeBox(boxColor,p.x-1,p.y-1,p.x+2,p.y+2);
870 if( !omitDescenders ){
871 @ if( p.u==0 ) drawUpArrow(p.x,0,p.y-6,p.fg||lineClr);
872 @ if( p.d ) drawUpArrow(p.x,p.y+6,btm,p.fg||lineClr);
873 }
874 @ if( p.mo>0 ){
875 @ var x1 = p.mo + left - 1;
876 @ var y1 = p.y-3;
877 @ var x0 = x1>p.x ? p.x+7 : p.x-6;
878 @ var u = rowinfo[p.mu-1];
879 @ var y0 = u.y+5;
880 @ if( x1>=p.x-5 && x1<=p.x+5 ){
881 @ y1 = p.y-5;
882 @ }else{
883 @ drawThinLine(x0,y1,x1,y1);
884 @ }
885 if( mergeOffset==0 ) cgi_printf("if( p.mo!=p.u-1 ) ");
886 @ drawThinLine(x1,y0,x1,y1);
887 @ }
888 @ var n = p.au.length;
889 @ for(var i=0; i<n; i+=2){
890 @ var x1 = p.au[i]*railPitch + left;
891 @ var x0 = x1>p.x ? p.x+7 : p.x-6;
892 @ var u = rowinfo[p.au[i+1]-1];
893 @ if(u.id<p.id){
894 @ drawBox(u.fg||lineClr,x0,p.y,x1+1,p.y+1);
895 @ drawUpArrow(x1,u.y+6,p.y,u.fg||lineClr);
896 @ }else{
897 @ drawBox("#600000",x0,p.y,x1,p.y+1);
898 @ drawBox("#600000",x1-1,p.y,x1,u.y+1);
899 @ drawBox("#600000",x1,u.y,u.x-10,u.y+1);
900 @ var n = document.createElement("div"),
901 @ t = u.y-2,
902 @ l = u.x-11;
903 @ n.style.position = "absolute";
904 @ n.style.top = t+"px";
905 @ n.style.left = l+"px";
906 @ n.style.width = 0;
907 @ n.style.height = 0;
908 @ n.style.transform = "scale(.999)";
909 @ n.style.borderWidth = 0;
910 @ n.style.borderStyle = "solid";
911 @ n.style.borderColor = "transparent";
912 @ n.style.borderTopWidth = "3px";
913 @ n.style.borderBottomWidth = "3px";
914 @ n.style.borderLeftWidth = "7px";
915 @ n.style.borderLeftColor = "#600000";
916 @ cDiv.appendChild(n);
917 @ }
918 @ }
919 @ for(var j in p.mi){
920 @ var y0 = p.y+5;
921 @ var mx = p.mi[j];
922 @ if( mx<0 ){
923 @ mx = left-mx;
924 @ drawThinLine(mx,y0,mx,btm);
925 @ }else{
926 @ mx += left;
927 @ }
928 @ if( mx>p.x ){
929 @ drawThinArrow(y0,mx,p.x+6);
930 @ }else{
931 @ drawThinArrow(y0,mx,p.x-5);
932 @ }
933 @ }
934 @ }
935 @ var selBox = null;
936 @ var selRow = null;
937 @ function renderGraph(){
938 @ var canvasDiv = gebi("canvas");
939 @ while( canvasDiv.hasChildNodes() ){
940 @ canvasDiv.removeChild(canvasDiv.firstChild);
941 @ }
942 @ var canvasY = absoluteY("timelineTable");
943 @ var left = absoluteX("m"+rowinfo[0].id) - absoluteX("canvas") + 15;
944 @ for(var i in rowinfo){
945 @ rowinfo[i].y = absoluteY("m"+rowinfo[i].id) + 10 - canvasY;
946 @ rowinfo[i].x = left + rowinfo[i].r*railPitch;
947 @ }
948 @ var btm = absoluteY("grbtm") + 10 - canvasY;
949 @ for(var i in rowinfo){
950 @ drawNode(rowinfo[i], left, btm);
951 @ }
952 @ if( selRow!=null ) clickOnRow(selRow);
953 @ }
954 @ function clickOnGraph(event){
955 @ var x=event.clientX-absoluteX("canvas");
956 @ var y=event.clientY-absoluteY("canvas");
957 @ if(window.pageXOffset!=null){
958 @ x += window.pageXOffset;
959 @ y += window.pageYOffset;
960 @ }else{
961 @ var d = window.document.documentElement;
962 @ if(document.compatMode!="CSS1Compat") d = d.body;
963 @ x += d.scrollLeft;
964 @ y += d.scrollTop;
965 @ }
966 if( P("clicktest")!=0 ){
967 @ alert("click at "+x+","+y)
968 }
969 @ for(var i in rowinfo){
970 @ p = rowinfo[i];
971 @ if( p.y<y-11 ) continue;
972 @ if( p.y>y+9 ) break;
973 @ if( p.x>x-11 && p.x<x+9 ){
974 @ clickOnRow(p);
975 @ break;
976 @ }
977 @ }
978 @ }
979 @ function clickOnRow(p){
980 @ if( selRow==null ){
981 @ selBox = drawBox("red",p.x-2,p.y-2,p.x+3,p.y+3);
982 if( circleNodes ){
983 @ selBox.style.borderRadius="6px";
984 }
985 @ selRow = p;
986 @ }else if( selRow==p ){
987 @ var canvasDiv = gebi("canvas");
988 @ canvasDiv.removeChild(selBox);
989 @ selBox = null;
990 @ selRow = null;
991 @ }else{
992 if( fileDiff ){
993 @ location.href="%R/fdiff?v1="+selRow.h+"&v2="+p.h+"&sbs=1";
994 }else{
995 if( db_get_boolean("show-version-diffs", 0)==0 ){
@@ -998,22 +972,23 @@
998 @ location.href="%R/vdiff?from="+selRow.h+"&to="+p.h+"&sbs=1";
999 }
1000 }
1001 @ }
1002 @ }
1003 @ var lastId = "m"+rowinfo[rowinfo.length-1].id;
1004 @ var lastY = 0;
1005 @ function checkHeight(){
1006 @ var h = absoluteY(lastId);
1007 @ if( h!=lastY ){
1008 @ renderGraph();
1009 @ lastY = h;
1010 @ }
1011 @ setTimeout("checkHeight();", 1000);
1012 @ }
 
1013 @ checkHeight();
1014 @ </script>
1015 }
1016 }
1017
1018 /*
1019 ** Create a temporary table suitable for storing timeline data.
@@ -1302,24 +1277,24 @@
1302 return;
1303 }
1304 url_initialize(&url, "timeline");
1305 cgi_query_parameters_to_url(&url);
1306 if( zTagName && g.perm.Read ){
1307 tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='sym-%q'", zTagName);
1308 zThisTag = zTagName;
1309 }else if( zBrName && g.perm.Read ){
1310 tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='sym-%q'",zBrName);
1311 zThisTag = zBrName;
1312 }else{
1313 tagid = 0;
1314 }
1315 if( zMark && zMark[0]==0 ){
1316 if( zAfter ) zMark = zAfter;
1317 if( zBefore ) zMark = zBefore;
1318 if( zCirca ) zMark = zCirca;
1319 }
1320 if( tagid>0
1321 && db_int(0,"SELECT count(*) FROM tagxref WHERE tagid=%d",tagid)<=nEntry
1322 ){
1323 nEntry = -1;
1324 zCirca = 0;
1325 }
@@ -1518,11 +1493,11 @@
1518 }
1519 else if( zYearWeek ){
1520 blob_append_sql(&sql, " AND %Q=strftime('%%Y-%%W',event.mtime) ",
1521 zYearWeek);
1522 }
1523 if( tagid>0 ){
1524 blob_append_sql(&sql,
1525 " AND (EXISTS(SELECT 1 FROM tagxref"
1526 " WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)\n", tagid);
1527
1528 if( zBrName ){
@@ -1873,11 +1848,11 @@
1873 fossil_free(zFree);
1874
1875 if(verboseFlag){
1876 if( !fchngQueryInit ){
1877 db_prepare(&fchngQuery,
1878 "SELECT (pid==0) AS isnew,"
1879 " (fid==0) AS isdel,"
1880 " (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
1881 " (SELECT uuid FROM blob WHERE rid=fid),"
1882 " (SELECT uuid FROM blob WHERE rid=pid)"
1883 " FROM mlink"
1884
--- src/timeline.c
+++ src/timeline.c
@@ -241,23 +241,17 @@
241 dateFormat = db_get_int("timeline-date-format", 0);
242 zDateFmt = P("datefmt");
243 if( zDateFmt ) dateFormat = atoi(zDateFmt);
244 if( tmFlags & TIMELINE_GRAPH ){
245 pGraph = graph_init();
 
 
 
 
 
246 }
247 db_static_prepare(&qbranch,
248 "SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=:rid",
249 TAG_BRANCH
250 );
251
252 @ <table id="timelineTable" class="timelineTable">
 
253 blob_zero(&comment);
254 while( db_step(pQuery)==SQLITE_ROW ){
255 int rid = db_column_int(pQuery, 0);
256 const char *zUuid = db_column_text(pQuery, 1);
257 int isLeaf = db_column_int(pQuery, 5);
@@ -391,11 +385,11 @@
385 }
386 db_reset(&qparent);
387 gidx = graph_add_row(pGraph, rid, nParent, aParent, zBr, zBgClr,
388 zUuid, isLeaf);
389 db_reset(&qbranch);
390 @ <div id="m%d(gidx)" class="tl-nodemark"></div>
391 }
392 @</td>
393 if( zBgClr && zBgClr[0] && rid!=selectedRid ){
394 @ <td class="timelineTableCell" style="background-color: %h(zBgClr);">
395 }else{
@@ -499,11 +493,11 @@
493 && zType[0]=='c' && g.perm.Hyperlink
494 ){
495 int inUl = 0;
496 if( !fchngQueryInit ){
497 db_prepare(&fchngQuery,
498 "SELECT pid,"
499 " fid,"
500 " (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
501 " (SELECT uuid FROM blob WHERE rid=fid),"
502 " (SELECT uuid FROM blob WHERE rid=pid),"
503 " (SELECT name FROM filename WHERE fnid=mlink.pfnid) AS oldnm"
@@ -517,11 +511,12 @@
511 fchngQueryInit = 1;
512 }
513 db_bind_int(&fchngQuery, ":mid", rid);
514 while( db_step(&fchngQuery)==SQLITE_ROW ){
515 const char *zFilename = db_column_text(&fchngQuery, 2);
516 int isNew = db_column_int(&fchngQuery, 0)<=0;
517 int isMergeNew = db_column_int(&fchngQuery, 0)<0;
518 int fid = db_column_int(&fchngQuery, 1);
519 int isDel = fid==0;
520 const char *zOldName = db_column_text(&fchngQuery, 5);
521 const char *zOld = db_column_text(&fchngQuery, 4);
522 const char *zNew = db_column_text(&fchngQuery, 3);
@@ -546,12 +541,17 @@
541 zA = href("%R/artifact/%!S",fid?zNew:zOld);
542 if( content_is_private(fid) ){
543 zUnpub = UNPUB_TAG;
544 }
545 if( isNew ){
546 @ <li> %s(zA)%h(zFilename)</a>%s(zId) %s(zUnpub)
547 if( isMergeNew ){
548 @ (added by merge)
549 }else{
550 @ (new file)
551 }
552 @ &nbsp; %z(href("%R/artifact/%!S",zNew))[view]</a></li>
553 }else if( isDel ){
554 @ <li> %s(zA)%h(zFilename)</a> (deleted)</li>
555 }else if( fossil_strcmp(zOld,zNew)==0 && zOldName!=0 ){
556 @ <li> %h(zOldName) &rarr; %s(zA)%h(zFilename)</a>%s(zId)
557 @ %s(zUnpub) %z(href("%R/artifact/%!S",zNew))[view]</a></li>
@@ -583,18 +583,11 @@
583 graph_finish(pGraph, (tmFlags & TIMELINE_DISJOINT)!=0);
584 if( pGraph->nErr ){
585 graph_free(pGraph);
586 pGraph = 0;
587 }else{
588 @ <tr class="timelineBottom"><td></td><td></td><td></td></tr>
 
 
 
 
 
 
 
589 }
590 }
591 @ </table>
592 if( fchngQueryInit ) db_finalize(&fchngQuery);
593 timeline_output_graph_javascript(pGraph, (tmFlags & TIMELINE_DISJOINT)!=0, 0);
@@ -642,31 +635,34 @@
635 ){
636 if( pGraph && pGraph->nErr==0 && pGraph->nRow>0 ){
637 GraphRow *pRow;
638 int i;
639 char cSep;
 
640 int iRailPitch; /* Pixels between consecutive rails */
641 int showArrowheads; /* True to draw arrowheads. False to omit. */
642 int circleNodes; /* True for circle nodes. False for square nodes */
643 int colorGraph; /* Use colors for graph lines */
644
645 iRailPitch = atoi(PD("railpitch","0"));
646 showArrowheads = skin_detail_boolean("timeline-arrowheads");
647 circleNodes = skin_detail_boolean("timeline-circle-nodes");
648 colorGraph = skin_detail_boolean("timeline-color-graph-lines");
649
650 @ <script>(function(){
651 @ "use strict";
652 @ var css = "";
653 if( circleNodes ){
654 @ css += ".tl-node, .tl-node:after { border-radius: 50%%; }";
655 }
656 if( !showArrowheads ){
657 @ css += ".tl-arrow.u { display: none; }";
658 }
659 @ if( css!=="" ){
660 @ var style = document.createElement("style");
661 @ style.textContent = css;
662 @ document.querySelector("head").appendChild(style);
663 @ }
664 /* the rowinfo[] array contains all the information needed to generate
665 ** the graph. Each entry contains information for a single row:
666 **
667 ** id: The id of the <div> element for the row. This is an integer.
668 ** to get an actual id, prepend "m" to the integer. The top node
@@ -674,13 +670,13 @@
670 ** bg: The background color for this row
671 ** r: The "rail" that the node for this row sits on. The left-most
672 ** rail is 0 and the number increases to the right.
673 ** d: True if there is a "descender" - an arrow coming from the bottom
674 ** of the page straight up to this node.
675 ** mo: "merge-out". If non-negative, this is the rail position
676 ** for the upward portion of a merge arrow. The merge arrow goes up
677 ** to the row identified by mu:. If this value is negative then
678 ** node has no merge children and no merge-out line is drawn.
679 ** mu: The id of the row which is the top of the merge-out arrow.
680 ** u: Draw a thick child-line out of the top of this node and up to
681 ** the node with an id equal to this value. 0 if it is straight to
682 ** the top of the page, -1 if there is no thick-line riser.
@@ -687,37 +683,25 @@
683 ** f: 0x01: a leaf node.
684 ** au: An array of integers that define thick-line risers for branches.
685 ** The integers are in pairs. For each pair, the first integer is
686 ** is the rail on which the riser should run and the second integer
687 ** is the id of the node upto which the riser should run.
688 ** mi: "merge-in". An array of integer rail positions from which
689 ** merge arrows should be drawn into this node. If the value is
690 ** negative, then the rail position is the absolute value of mi[]
691 ** and a thin merge-arrow descender is drawn to the bottom of
692 ** the screen.
693 ** h: The SHA1 hash of the object being graphed
694 */
695 cgi_printf("var rowinfo = [\n");
696 for(pRow=pGraph->pFirst; pRow; pRow=pRow->pNext){
 
 
 
 
 
 
 
 
 
 
 
 
697 cgi_printf("{id:%d,bg:\"%s\",r:%d,d:%d,mo:%d,mu:%d,u:%d,f:%d,au:",
698 pRow->idx, /* id */
699 pRow->zBgClr, /* bg */
700 pRow->iRail, /* r */
701 pRow->bDescender, /* d */
702 pRow->mergeOut, /* mo */
703 pRow->mergeUpto, /* mu */
704 pRow->aiRiser[pRow->iRail], /* u */
705 pRow->isLeaf ? 1 : 0 /* f */
706 );
707 /* u */
@@ -737,13 +721,11 @@
721 /* mi */
722 cgi_printf("mi:");
723 cSep = '[';
724 for(i=0; i<GR_MAX_RAIL; i++){
725 if( pRow->mergeIn[i] ){
726 int mi = i;
 
 
727 if( pRow->mergeDown & (1<<i) ) mi = -mi;
728 cgi_printf("%c%d", cSep, mi);
729 cSep = ',';
730 }
731 }
@@ -750,246 +732,238 @@
732 if( cSep=='[' ) cgi_printf("[");
733 cgi_printf("],h:\"%s\"}%s", pRow->zUuid, pRow->pNext ? ",\n" : "];\n");
734 }
735 cgi_printf("var nrail = %d\n", pGraph->mxRail+1);
736 graph_free(pGraph);
737 @ var canvasDiv;
738 @ var railPitch;
739 @ var mergeOffset;
740 @ var node, arrow, arrowSmall, line, mArrow, mLine, wArrow, wLine;
741 @ function initGraph(){
742 @ var parent = gebi("timelineTable").rows[0].cells[1];
743 @ parent.style.verticalAlign = "top";
744 @ canvasDiv = document.createElement("div");
745 @ canvasDiv.className = "tl-canvas";
746 @ canvasDiv.style.position = "absolute";
747 @ parent.appendChild(canvasDiv);
748 @
749 @ var elems = {};
750 @ var elemClasses = [
751 @ "rail", "mergeoffset", "node", "arrow u", "arrow u sm", "line",
752 @ "arrow merge r", "line merge", "arrow warp", "line warp"
753 @ ];
754 @ for( var i=0; i<elemClasses.length; i++ ){
755 @ var cls = elemClasses[i];
756 @ var elem = document.createElement("div");
757 @ elem.className = "tl-" + cls;
758 @ if( cls.indexOf("line")==0 ) elem.className += " v";
759 @ canvasDiv.appendChild(elem);
760 @ var k = cls.replace(/\s/g, "_");
761 @ var r = elem.getBoundingClientRect();
762 @ var w = Math.round(r.right - r.left);
763 @ var h = Math.round(r.bottom - r.top);
764 @ elems[k] = {w: w, h: h, cls: cls};
765 @ }
766 @ node = elems.node;
767 @ arrow = elems.arrow_u;
768 @ arrowSmall = elems.arrow_u_sm;
769 @ line = elems.line;
770 @ mArrow = elems.arrow_merge_r;
771 @ mLine = elems.line_merge;
772 @ wArrow = elems.arrow_warp;
773 @ wLine = elems.line_warp;
774 @
775 @ var minRailPitch = Math.ceil((node.w+line.w)/2 + mArrow.w + 1);
776 if( iRailPitch ){
777 @ railPitch = %d(iRailPitch);
778 }else{
779 @ railPitch = elems.rail.w;
780 @ railPitch -= Math.floor((nrail-1)*(railPitch-minRailPitch)/21);
781 }
782 @ railPitch = Math.max(railPitch, minRailPitch);
783 @
784 if( PB("nomo") ){
785 @ mergeOffset = 0;
786 }else{
787 @ mergeOffset = railPitch-minRailPitch-mLine.w;
788 @ mergeOffset = Math.min(mergeOffset, elems.mergeoffset.w);
789 @ mergeOffset = mergeOffset>0 ? mergeOffset + line.w/2 : 0;
790 }
791 @
792 @ var canvasWidth = (nrail-1)*railPitch + node.w;
793 @ canvasDiv.style.width = canvasWidth + "px";
794 @ canvasDiv.style.position = "relative";
795 @ }
796 @ function drawBox(cls,color,x0,y0,x1,y1){
797 @ var n = document.createElement("div");
798 @ x0 = Math.floor(x0);
799 @ y0 = Math.floor(y0);
800 @ x1 = x1 || x1===0 ? Math.floor(x1) : x0;
801 @ y1 = y1 || y1===0 ? Math.floor(y1) : y0;
802 @ if( x0>x1 ){ var t=x0; x0=x1; x1=t; }
803 @ if( y0>y1 ){ var t=y0; y0=y1; y1=t; }
804 @ var w = x1-x0;
805 @ var h = y1-y0;
806 @ n.style.position = "absolute";
 
807 @ n.style.left = x0+"px";
808 @ n.style.top = y0+"px";
809 @ if( w ) n.style.width = w+"px";
810 @ if( h ) n.style.height = h+"px";
811 @ if( color ) n.style.backgroundColor = color;
812 @ n.className = "tl-"+cls;
813 @ canvasDiv.appendChild(n);
814 @ return n;
815 @ }
816 @ function absoluteY(obj){
 
 
817 @ var top = 0;
818 @ if( obj.offsetParent ){
819 @ do{
820 @ top += obj.offsetTop;
821 @ }while( obj = obj.offsetParent );
822 @ }
823 @ return top;
824 @ }
825 @ function miLineY(p){
826 @ return p.y + node.h - mLine.w - 1;
827 @ }
828 @ function drawLine(elem,color,x0,y0,x1,y1){
829 @ var cls = elem.cls + " ";
830 @ if( x1===null ){
831 @ x1 = x0+elem.w;
832 @ cls += "v";
833 @ }else{
834 @ y1 = y0+elem.w;
835 @ cls += "h";
836 @ }
837 @ drawBox(cls,color,x0,y0,x1,y1);
838 @ }
839 @ function drawUpArrow(from,to,color){
840 @ var y = to.y + node.h;
841 @ var arrowSpace = from.y - y + (!from.id || from.r!=to.r ? node.h/2 : 0);
842 @ var arw = arrowSpace < arrow.h*1.5 ? arrowSmall : arrow;
843 @ var x = to.x + (node.w-line.w)/2;
844 @ var y0 = from.y + node.h/2;
845 @ var y1 = Math.ceil(to.y + node.h + arw.h/2);
846 @ drawLine(line,color,x,y0,null,y1);
847 @ x = to.x + (node.w-arw.w)/2;
848 @ var n = drawBox(arw.cls,null,x,y);
849 @ n.style.borderBottomColor = color;
850 @ }
851 @ function drawMergeLine(x0,y0,x1,y1){
852 @ drawLine(mLine,null,x0,y0,x1,y1);
853 @ }
854 @ function drawMergeArrow(p,rail){
855 @ var x0 = rail*railPitch + node.w/2;
856 @ if( rail in mergeLines ){
857 @ x0 += mergeLines[rail];
858 @ if( p.r<rail ) x0 += mLine.w;
859 @ }else{
860 @ x0 += (p.r<rail ? -1 : 1)*line.w/2;
861 @ }
862 @ var x1 = mArrow.w ? mArrow.w/2 : -node.w/2;
863 @ x1 = p.x + (p.r<rail ? node.w + Math.ceil(x1) : -x1);
864 @ var y = miLineY(p);
865 @ drawMergeLine(x0,y,x1,null);
866 @ var x = p.x + (p.r<rail ? node.w : -mArrow.w);
867 @ var cls = "arrow merge " + (p.r<rail ? "l" : "r");
868 @ drawBox(cls,null,x,y+(mLine.w-mArrow.h)/2);
869 @ }
870 @ function drawNode(p, btm){
871 @ if( p.u>0 ) drawUpArrow(p,rowinfo[p.u-1],p.fg);
872 @ var cls = node.cls;
873 @ if( p.mi.length ) cls += " merge";
874 @ if( p.f&1 ) cls += " leaf";
875 @ var n = drawBox(cls,p.bg,p.x,p.y);
876 @ n.id = "tln"+p.id;
877 @ n.onclick = clickOnNode;
878 @ n.style.zIndex = 10;
879 if( !omitDescenders ){
880 @ if( p.u==0 ) drawUpArrow(p,{x: p.x, y: -node.h},p.fg);
881 @ if( p.d ) drawUpArrow({x: p.x, y: btm-node.h/2},p,p.fg);
882 }
883 @ if( p.mo>=0 ){
884 @ var x0 = p.x + node.w/2;
885 @ var x1 = p.mo*railPitch + node.w/2;
886 @ var u = rowinfo[p.mu-1];
887 @ var y1 = miLineY(u);
888 @ if( p.u<0 || p.mo!=p.r ){
889 @ x1 += mergeLines[p.mo] = -mLine.w/2;
890 @ var y0 = p.y+2;
891 @ if( p.r!=p.mo ) drawMergeLine(x0,y0,x1+(x0<x1 ? mLine.w : 0),null);
892 @ drawMergeLine(x1,y0+mLine.w,null,y1);
893 @ }else if( mergeOffset ){
894 @ mergeLines[p.mo] = u.r<p.r ? -mergeOffset-mLine.w : mergeOffset;
895 @ x1 += mergeLines[p.mo];
896 @ drawMergeLine(x1,p.y+node.h/2,null,y1);
897 @ }else{
898 @ delete mergeLines[p.mo];
899 @ }
900 @ }
901 @ for( var i=0; i<p.au.length; i+=2 ){
902 @ var rail = p.au[i];
903 @ var x0 = p.x + node.w/2;
904 @ var x1 = rail*railPitch + (node.w-line.w)/2;
905 @ if( x0<x1 ){
906 @ x0 = Math.ceil(x0);
907 @ x1 += line.w;
908 @ }
909 @ var y0 = p.y + (node.h-line.w)/2;
910 @ var u = rowinfo[p.au[i+1]-1];
911 @ if( u.id<p.id ){
912 @ drawLine(line,u.fg,x0,y0,x1,null);
913 @ drawUpArrow(p,u,u.fg);
914 @ }else{
915 @ var y1 = u.y + (node.h-line.w)/2;
916 @ drawLine(wLine,u.fg,x0,y0,x1,null);
917 @ drawLine(wLine,u.fg,x1-line.w,y0,null,y1+line.w);
918 @ drawLine(wLine,u.fg,x1,y1,u.x-wArrow.w/2,null);
919 @ var x = u.x-wArrow.w;
920 @ var y = u.y+(node.h-wArrow.h)/2;
921 @ var n = drawBox(wArrow.cls,null,x,y);
922 @ if( u.fg ) n.style.borderLeftColor = u.fg;
923 @ }
924 @ }
925 @ for( var i=0; i<p.mi.length; i++ ){
926 @ var rail = p.mi[i];
927 @ if( rail<0 ){
928 @ rail = -rail;
929 @ mergeLines[rail] = -mLine.w/2;
930 @ var x = rail*railPitch + (node.w-mLine.w)/2;
931 @ drawMergeLine(x,miLineY(p),null,btm);
932 @ }
933 @ drawMergeArrow(p,rail);
934 @ }
935 @ }
936 @ var mergeLines;
937 @ function renderGraph(){
938 @ mergeLines = {};
939 @ canvasDiv.innerHTML = "";
940 @ var canvasY = absoluteY(canvasDiv);
941 @ for( var i=0; i<rowinfo.length; i++ ){
942 @ rowinfo[i].y = absoluteY(gebi("m"+rowinfo[i].id)) - canvasY;
943 @ rowinfo[i].x = rowinfo[i].r*railPitch;
944 @ }
945 @ var tlBtm = document.querySelector(".timelineBottom");
946 @ if( tlBtm.offsetHeight<node.h ){
947 @ tlBtm.style.height = node.h + "px";
948 @ }
949 @ var btm = absoluteY(tlBtm) - canvasY + tlBtm.offsetHeight;
950 @ for( var i=rowinfo.length-1; i>=0; i-- ){
951 @ drawNode(rowinfo[i], btm);
952 @ }
953 @ }
954 @ var selRow;
955 @ function clickOnNode(){
956 @ var p = rowinfo[parseInt(this.id.match(/\d+$/)[0], 10)-1];
957 @ if( !selRow ){
958 @ selRow = p;
959 @ this.className += " sel";
960 @ canvasDiv.className += " sel";
961 @ }else if( selRow==p ){
962 @ selRow = null;
963 @ this.className = this.className.replace(" sel", "");
964 @ canvasDiv.className = canvasDiv.className.replace(" sel", "");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
965 @ }else{
966 if( fileDiff ){
967 @ location.href="%R/fdiff?v1="+selRow.h+"&v2="+p.h+"&sbs=1";
968 }else{
969 if( db_get_boolean("show-version-diffs", 0)==0 ){
@@ -998,22 +972,23 @@
972 @ location.href="%R/vdiff?from="+selRow.h+"&to="+p.h+"&sbs=1";
973 }
974 }
975 @ }
976 @ }
977 @ var lastRow = gebi("m"+rowinfo[rowinfo.length-1].id);
978 @ var lastY = 0;
979 @ function checkHeight(){
980 @ var h = absoluteY(lastRow);
981 @ if( h!=lastY ){
982 @ renderGraph();
983 @ lastY = h;
984 @ }
985 @ setTimeout(checkHeight, 1000);
986 @ }
987 @ initGraph();
988 @ checkHeight();
989 @ }())</script>
990 }
991 }
992
993 /*
994 ** Create a temporary table suitable for storing timeline data.
@@ -1302,24 +1277,24 @@
1277 return;
1278 }
1279 url_initialize(&url, "timeline");
1280 cgi_query_parameters_to_url(&url);
1281 if( zTagName && g.perm.Read ){
1282 tagid = db_int(-1,"SELECT tagid FROM tag WHERE tagname='sym-%q'",zTagName);
1283 zThisTag = zTagName;
1284 }else if( zBrName && g.perm.Read ){
1285 tagid = db_int(-1,"SELECT tagid FROM tag WHERE tagname='sym-%q'",zBrName);
1286 zThisTag = zBrName;
1287 }else{
1288 tagid = 0;
1289 }
1290 if( zMark && zMark[0]==0 ){
1291 if( zAfter ) zMark = zAfter;
1292 if( zBefore ) zMark = zBefore;
1293 if( zCirca ) zMark = zCirca;
1294 }
1295 if( tagid
1296 && db_int(0,"SELECT count(*) FROM tagxref WHERE tagid=%d",tagid)<=nEntry
1297 ){
1298 nEntry = -1;
1299 zCirca = 0;
1300 }
@@ -1518,11 +1493,11 @@
1493 }
1494 else if( zYearWeek ){
1495 blob_append_sql(&sql, " AND %Q=strftime('%%Y-%%W',event.mtime) ",
1496 zYearWeek);
1497 }
1498 if( tagid ){
1499 blob_append_sql(&sql,
1500 " AND (EXISTS(SELECT 1 FROM tagxref"
1501 " WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)\n", tagid);
1502
1503 if( zBrName ){
@@ -1873,11 +1848,11 @@
1848 fossil_free(zFree);
1849
1850 if(verboseFlag){
1851 if( !fchngQueryInit ){
1852 db_prepare(&fchngQuery,
1853 "SELECT (pid<=0) AS isnew,"
1854 " (fid==0) AS isdel,"
1855 " (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
1856 " (SELECT uuid FROM blob WHERE rid=fid),"
1857 " (SELECT uuid FROM blob WHERE rid=pid)"
1858 " FROM mlink"
1859
+5 -5
--- src/translate.c
+++ src/translate.c
@@ -40,15 +40,15 @@
4040
** rather than text that is to be output via cgi_printf(). Render it
4141
** as such.
4242
**
4343
** Enhancement #2:
4444
**
45
-** Comments of the form: "/* @-comment: CC" cause CC to become a
46
-** comment character for the @-substitution. Typical values for CC are
47
-** "--" (for SQL text) or "#" (for Tcl script) or "//" (for C++ code).
48
-** Lines of subsequent @-blocks that begin with CC are omitted from the
49
-** output.
45
+** Comments of the form: "|* @-comment: CC" (where "|" is really "/")
46
+** cause CC to become a comment character for the @-substitution.
47
+** Typical values for CC are "--" (for SQL text) or "#" (for Tcl script)
48
+** or "//" (for C++ code). Lines of subsequent @-blocks that begin with
49
+** CC are omitted from the output.
5050
**
5151
*/
5252
#include <stdio.h>
5353
#include <ctype.h>
5454
#include <stdlib.h>
5555
--- src/translate.c
+++ src/translate.c
@@ -40,15 +40,15 @@
40 ** rather than text that is to be output via cgi_printf(). Render it
41 ** as such.
42 **
43 ** Enhancement #2:
44 **
45 ** Comments of the form: "/* @-comment: CC" cause CC to become a
46 ** comment character for the @-substitution. Typical values for CC are
47 ** "--" (for SQL text) or "#" (for Tcl script) or "//" (for C++ code).
48 ** Lines of subsequent @-blocks that begin with CC are omitted from the
49 ** output.
50 **
51 */
52 #include <stdio.h>
53 #include <ctype.h>
54 #include <stdlib.h>
55
--- src/translate.c
+++ src/translate.c
@@ -40,15 +40,15 @@
40 ** rather than text that is to be output via cgi_printf(). Render it
41 ** as such.
42 **
43 ** Enhancement #2:
44 **
45 ** Comments of the form: "|* @-comment: CC" (where "|" is really "/")
46 ** cause CC to become a comment character for the @-substitution.
47 ** Typical values for CC are "--" (for SQL text) or "#" (for Tcl script)
48 ** or "//" (for C++ code). Lines of subsequent @-blocks that begin with
49 ** CC are omitted from the output.
50 **
51 */
52 #include <stdio.h>
53 #include <ctype.h>
54 #include <stdlib.h>
55
+16 -24
--- src/update.c
+++ src/update.c
@@ -586,43 +586,32 @@
586586
db_end_transaction(0);
587587
}
588588
}
589589
590590
/*
591
-** Make sure empty directories are created
591
+** Create empty directories specified by the empty-dirs setting.
592592
*/
593593
void ensure_empty_dirs_created(void){
594
- /* Make empty directories? */
595594
char *zEmptyDirs = db_get("empty-dirs", 0);
596595
if( zEmptyDirs!=0 ){
597
- char *bc;
596
+ int i;
598597
Blob dirName;
599598
Blob dirsList;
600599
601
- blob_zero(&dirsList);
602
- blob_init(&dirsList, zEmptyDirs, strlen(zEmptyDirs));
603
- /* Replace commas by spaces */
604
- bc = blob_str(&dirsList);
605
- while( (*bc)!='\0' ){
606
- if( (*bc)==',' ) { *bc = ' '; }
607
- ++bc;
608
- }
609
- /* Make directories */
610
- blob_zero(&dirName);
600
+ zEmptyDirs = fossil_strdup(zEmptyDirs);
601
+ for(i=0; zEmptyDirs[i]; i++){
602
+ if( zEmptyDirs[i]==',' ) zEmptyDirs[i] = ' ';
603
+ }
604
+ blob_init(&dirsList, zEmptyDirs, -1);
611605
while( blob_token(&dirsList, &dirName) ){
612
- const char *zDir = blob_str(&dirName);
613
- /* Make full pathname of the directory */
614
- Blob path;
615
- const char *zPath;
616
-
617
- blob_zero(&path);
618
- blob_appendf(&path, "%s/%s", g.zLocalRoot, zDir);
619
- zPath = blob_str(&path);
620
- /* Handle various cases of existence of the directory */
606
+ char *zDir = blob_str(&dirName);
607
+ char *zPath = mprintf("%s/%s", g.zLocalRoot, zDir);
621608
switch( file_wd_isdir(zPath) ){
622609
case 0: { /* doesn't exist */
623
- if( file_mkdir(zPath, 0)!=0 ) {
610
+ fossil_free(zPath);
611
+ zPath = mprintf("%s/%s/x", g.zLocalRoot, zDir);
612
+ if( file_mkfolder(zPath, 0, 1)!=0 ) {
624613
fossil_warning("couldn't create directory %s as "
625614
"required by empty-dirs setting", zDir);
626615
}
627616
break;
628617
}
@@ -633,12 +622,15 @@
633622
case 2: { /* exists, but isn't a directory */
634623
fossil_warning("file %s found, but a directory is required "
635624
"by empty-dirs setting", zDir);
636625
}
637626
}
638
- blob_reset(&path);
627
+ fossil_free(zPath);
628
+ blob_reset(&dirName);
639629
}
630
+ blob_reset(&dirsList);
631
+ fossil_free(zEmptyDirs);
640632
}
641633
}
642634
643635
644636
/*
645637
--- src/update.c
+++ src/update.c
@@ -586,43 +586,32 @@
586 db_end_transaction(0);
587 }
588 }
589
590 /*
591 ** Make sure empty directories are created
592 */
593 void ensure_empty_dirs_created(void){
594 /* Make empty directories? */
595 char *zEmptyDirs = db_get("empty-dirs", 0);
596 if( zEmptyDirs!=0 ){
597 char *bc;
598 Blob dirName;
599 Blob dirsList;
600
601 blob_zero(&dirsList);
602 blob_init(&dirsList, zEmptyDirs, strlen(zEmptyDirs));
603 /* Replace commas by spaces */
604 bc = blob_str(&dirsList);
605 while( (*bc)!='\0' ){
606 if( (*bc)==',' ) { *bc = ' '; }
607 ++bc;
608 }
609 /* Make directories */
610 blob_zero(&dirName);
611 while( blob_token(&dirsList, &dirName) ){
612 const char *zDir = blob_str(&dirName);
613 /* Make full pathname of the directory */
614 Blob path;
615 const char *zPath;
616
617 blob_zero(&path);
618 blob_appendf(&path, "%s/%s", g.zLocalRoot, zDir);
619 zPath = blob_str(&path);
620 /* Handle various cases of existence of the directory */
621 switch( file_wd_isdir(zPath) ){
622 case 0: { /* doesn't exist */
623 if( file_mkdir(zPath, 0)!=0 ) {
 
 
624 fossil_warning("couldn't create directory %s as "
625 "required by empty-dirs setting", zDir);
626 }
627 break;
628 }
@@ -633,12 +622,15 @@
633 case 2: { /* exists, but isn't a directory */
634 fossil_warning("file %s found, but a directory is required "
635 "by empty-dirs setting", zDir);
636 }
637 }
638 blob_reset(&path);
 
639 }
 
 
640 }
641 }
642
643
644 /*
645
--- src/update.c
+++ src/update.c
@@ -586,43 +586,32 @@
586 db_end_transaction(0);
587 }
588 }
589
590 /*
591 ** Create empty directories specified by the empty-dirs setting.
592 */
593 void ensure_empty_dirs_created(void){
 
594 char *zEmptyDirs = db_get("empty-dirs", 0);
595 if( zEmptyDirs!=0 ){
596 int i;
597 Blob dirName;
598 Blob dirsList;
599
600 zEmptyDirs = fossil_strdup(zEmptyDirs);
601 for(i=0; zEmptyDirs[i]; i++){
602 if( zEmptyDirs[i]==',' ) zEmptyDirs[i] = ' ';
603 }
604 blob_init(&dirsList, zEmptyDirs, -1);
 
 
 
 
 
605 while( blob_token(&dirsList, &dirName) ){
606 char *zDir = blob_str(&dirName);
607 char *zPath = mprintf("%s/%s", g.zLocalRoot, zDir);
 
 
 
 
 
 
 
608 switch( file_wd_isdir(zPath) ){
609 case 0: { /* doesn't exist */
610 fossil_free(zPath);
611 zPath = mprintf("%s/%s/x", g.zLocalRoot, zDir);
612 if( file_mkfolder(zPath, 0, 1)!=0 ) {
613 fossil_warning("couldn't create directory %s as "
614 "required by empty-dirs setting", zDir);
615 }
616 break;
617 }
@@ -633,12 +622,15 @@
622 case 2: { /* exists, but isn't a directory */
623 fossil_warning("file %s found, but a directory is required "
624 "by empty-dirs setting", zDir);
625 }
626 }
627 fossil_free(zPath);
628 blob_reset(&dirName);
629 }
630 blob_reset(&dirsList);
631 fossil_free(zEmptyDirs);
632 }
633 }
634
635
636 /*
637
+6 -4
--- src/url.c
+++ src/url.c
@@ -454,12 +454,12 @@
454454
** Resets the given URL object, deallocating any memory
455455
** it uses.
456456
*/
457457
void url_reset(HQuery *p){
458458
blob_reset(&p->url);
459
- fossil_free(p->azName);
460
- fossil_free(p->azValue);
459
+ fossil_free((void *)p->azName);
460
+ fossil_free((void *)p->azValue);
461461
url_initialize(p, p->zBase);
462462
}
463463
464464
/*
465465
** Add a fixed parameter to an HQuery. Or remove the parameters if zValue==0.
@@ -480,12 +480,14 @@
480480
}
481481
assert( i==p->nParam );
482482
if( zValue==0 ) return;
483483
if( i>=p->nAlloc ){
484484
p->nAlloc = p->nAlloc*2 + 10;
485
- p->azName = fossil_realloc(p->azName, sizeof(p->azName[0])*p->nAlloc);
486
- p->azValue = fossil_realloc(p->azValue, sizeof(p->azValue[0])*p->nAlloc);
485
+ p->azName = fossil_realloc((void *)p->azName,
486
+ sizeof(p->azName[0])*p->nAlloc);
487
+ p->azValue = fossil_realloc((void *)p->azValue,
488
+ sizeof(p->azValue[0])*p->nAlloc);
487489
}
488490
p->azName[i] = zName;
489491
p->azValue[i] = zValue;
490492
p->nParam++;
491493
}
492494
--- src/url.c
+++ src/url.c
@@ -454,12 +454,12 @@
454 ** Resets the given URL object, deallocating any memory
455 ** it uses.
456 */
457 void url_reset(HQuery *p){
458 blob_reset(&p->url);
459 fossil_free(p->azName);
460 fossil_free(p->azValue);
461 url_initialize(p, p->zBase);
462 }
463
464 /*
465 ** Add a fixed parameter to an HQuery. Or remove the parameters if zValue==0.
@@ -480,12 +480,14 @@
480 }
481 assert( i==p->nParam );
482 if( zValue==0 ) return;
483 if( i>=p->nAlloc ){
484 p->nAlloc = p->nAlloc*2 + 10;
485 p->azName = fossil_realloc(p->azName, sizeof(p->azName[0])*p->nAlloc);
486 p->azValue = fossil_realloc(p->azValue, sizeof(p->azValue[0])*p->nAlloc);
 
 
487 }
488 p->azName[i] = zName;
489 p->azValue[i] = zValue;
490 p->nParam++;
491 }
492
--- src/url.c
+++ src/url.c
@@ -454,12 +454,12 @@
454 ** Resets the given URL object, deallocating any memory
455 ** it uses.
456 */
457 void url_reset(HQuery *p){
458 blob_reset(&p->url);
459 fossil_free((void *)p->azName);
460 fossil_free((void *)p->azValue);
461 url_initialize(p, p->zBase);
462 }
463
464 /*
465 ** Add a fixed parameter to an HQuery. Or remove the parameters if zValue==0.
@@ -480,12 +480,14 @@
480 }
481 assert( i==p->nParam );
482 if( zValue==0 ) return;
483 if( i>=p->nAlloc ){
484 p->nAlloc = p->nAlloc*2 + 10;
485 p->azName = fossil_realloc((void *)p->azName,
486 sizeof(p->azName[0])*p->nAlloc);
487 p->azValue = fossil_realloc((void *)p->azValue,
488 sizeof(p->azValue[0])*p->nAlloc);
489 }
490 p->azName[i] = zName;
491 p->azValue[i] = zValue;
492 p->nParam++;
493 }
494
+35 -7
--- src/vfile.c
+++ src/vfile.c
@@ -136,15 +136,22 @@
136136
#define CKSIG_SETMTIME 0x004 /* Set mtime to last check-out time */
137137
138138
#endif /* INTERFACE */
139139
140140
/*
141
-** Look at every VFILE entry with the given vid and update
142
-** VFILE.CHNGED field according to whether or not
143
-** the file has changed. 0 means no change. 1 means edited. 2 means
144
-** the file has changed due to a merge. 3 means the file was added
145
-** by a merge.
141
+** Look at every VFILE entry with the given vid and update VFILE.CHNGED field
142
+** according to whether or not the file has changed.
143
+** - 0 means no change.
144
+** - 1 means edited.
145
+** - 2 means changed due to a merge.
146
+** - 3 means added by a merge.
147
+** - 4 means changed due to an integrate merge.
148
+** - 5 means added by an integrate merge.
149
+** - 6 means became executable but has unmodified contents.
150
+** - 7 means became a symlink whose target equals its old contents.
151
+** - 8 means lost executable status but has unmodified contents.
152
+** - 9 means lost symlink status and has contents equal to its old target.
146153
**
147154
** If VFILE.DELETED is true or if VFILE.RID is zero, then the file was either
148155
** removed from configuration management via "fossil rm" or added via
149156
** "fossil add", respectively, and in both cases we always know that
150157
** the file has changed without having the check the size, mtime,
@@ -170,18 +177,22 @@
170177
int useMtime = (cksigFlags & CKSIG_SHA1)==0
171178
&& db_get_boolean("mtime-changes", 1);
172179
173180
db_begin_transaction();
174181
db_prepare(&q, "SELECT id, %Q || pathname,"
175
- " vfile.mrid, deleted, chnged, uuid, size, mtime"
182
+ " vfile.mrid, deleted, chnged, uuid, size, mtime,"
183
+ " CASE WHEN isexe THEN %d WHEN islink THEN %d ELSE %d END"
176184
" FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
177
- " WHERE vid=%d ", g.zLocalRoot, vid);
185
+ " WHERE vid=%d ", g.zLocalRoot, PERM_EXE, PERM_LNK, PERM_REG,
186
+ vid);
178187
while( db_step(&q)==SQLITE_ROW ){
179188
int id, rid, isDeleted;
180189
const char *zName;
181190
int chnged = 0;
182191
int oldChnged;
192
+ int origPerm;
193
+ int currentPerm;
183194
i64 oldMtime;
184195
i64 currentMtime;
185196
i64 origSize;
186197
i64 currentSize;
187198
@@ -192,10 +203,12 @@
192203
oldChnged = chnged = db_column_int(&q, 4);
193204
oldMtime = db_column_int64(&q, 7);
194205
origSize = db_column_int64(&q, 6);
195206
currentSize = file_wd_size(zName);
196207
currentMtime = file_wd_mtime(0);
208
+ origPerm = db_column_int(&q, 8);
209
+ currentPerm = file_wd_perm(zName);
197210
if( chnged==0 && (isDeleted || rid==0) ){
198211
/* "fossil rm" or "fossil add" always change the file */
199212
chnged = 1;
200213
}else if( !file_wd_isfile_or_link(0) && currentSize>=0 ){
201214
if( cksigFlags & CKSIG_ENOTFILE ){
@@ -245,10 +258,25 @@
245258
file_set_mtime(zName, desiredMtime);
246259
currentMtime = file_wd_mtime(zName);
247260
}
248261
}
249262
}
263
+#ifndef _WIN32
264
+ if( chnged==0 || chnged==6 || chnged==7 || chnged==8 || chnged==9 ){
265
+ if( origPerm == currentPerm ){
266
+ chnged = 0;
267
+ }else if( currentPerm == PERM_EXE ){
268
+ chnged = 6;
269
+ }else if( currentPerm == PERM_LNK ){
270
+ chnged = 7;
271
+ }else if( origPerm == PERM_EXE ){
272
+ chnged = 8;
273
+ }else if( origPerm == PERM_LNK ){
274
+ chnged = 9;
275
+ }
276
+ }
277
+#endif
250278
if( currentMtime!=oldMtime || chnged!=oldChnged ){
251279
db_multi_exec("UPDATE vfile SET mtime=%lld, chnged=%d WHERE id=%d",
252280
currentMtime, chnged, id);
253281
}
254282
}
255283
--- src/vfile.c
+++ src/vfile.c
@@ -136,15 +136,22 @@
136 #define CKSIG_SETMTIME 0x004 /* Set mtime to last check-out time */
137
138 #endif /* INTERFACE */
139
140 /*
141 ** Look at every VFILE entry with the given vid and update
142 ** VFILE.CHNGED field according to whether or not
143 ** the file has changed. 0 means no change. 1 means edited. 2 means
144 ** the file has changed due to a merge. 3 means the file was added
145 ** by a merge.
 
 
 
 
 
 
 
146 **
147 ** If VFILE.DELETED is true or if VFILE.RID is zero, then the file was either
148 ** removed from configuration management via "fossil rm" or added via
149 ** "fossil add", respectively, and in both cases we always know that
150 ** the file has changed without having the check the size, mtime,
@@ -170,18 +177,22 @@
170 int useMtime = (cksigFlags & CKSIG_SHA1)==0
171 && db_get_boolean("mtime-changes", 1);
172
173 db_begin_transaction();
174 db_prepare(&q, "SELECT id, %Q || pathname,"
175 " vfile.mrid, deleted, chnged, uuid, size, mtime"
 
176 " FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
177 " WHERE vid=%d ", g.zLocalRoot, vid);
 
178 while( db_step(&q)==SQLITE_ROW ){
179 int id, rid, isDeleted;
180 const char *zName;
181 int chnged = 0;
182 int oldChnged;
 
 
183 i64 oldMtime;
184 i64 currentMtime;
185 i64 origSize;
186 i64 currentSize;
187
@@ -192,10 +203,12 @@
192 oldChnged = chnged = db_column_int(&q, 4);
193 oldMtime = db_column_int64(&q, 7);
194 origSize = db_column_int64(&q, 6);
195 currentSize = file_wd_size(zName);
196 currentMtime = file_wd_mtime(0);
 
 
197 if( chnged==0 && (isDeleted || rid==0) ){
198 /* "fossil rm" or "fossil add" always change the file */
199 chnged = 1;
200 }else if( !file_wd_isfile_or_link(0) && currentSize>=0 ){
201 if( cksigFlags & CKSIG_ENOTFILE ){
@@ -245,10 +258,25 @@
245 file_set_mtime(zName, desiredMtime);
246 currentMtime = file_wd_mtime(zName);
247 }
248 }
249 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250 if( currentMtime!=oldMtime || chnged!=oldChnged ){
251 db_multi_exec("UPDATE vfile SET mtime=%lld, chnged=%d WHERE id=%d",
252 currentMtime, chnged, id);
253 }
254 }
255
--- src/vfile.c
+++ src/vfile.c
@@ -136,15 +136,22 @@
136 #define CKSIG_SETMTIME 0x004 /* Set mtime to last check-out time */
137
138 #endif /* INTERFACE */
139
140 /*
141 ** Look at every VFILE entry with the given vid and update VFILE.CHNGED field
142 ** according to whether or not the file has changed.
143 ** - 0 means no change.
144 ** - 1 means edited.
145 ** - 2 means changed due to a merge.
146 ** - 3 means added by a merge.
147 ** - 4 means changed due to an integrate merge.
148 ** - 5 means added by an integrate merge.
149 ** - 6 means became executable but has unmodified contents.
150 ** - 7 means became a symlink whose target equals its old contents.
151 ** - 8 means lost executable status but has unmodified contents.
152 ** - 9 means lost symlink status and has contents equal to its old target.
153 **
154 ** If VFILE.DELETED is true or if VFILE.RID is zero, then the file was either
155 ** removed from configuration management via "fossil rm" or added via
156 ** "fossil add", respectively, and in both cases we always know that
157 ** the file has changed without having the check the size, mtime,
@@ -170,18 +177,22 @@
177 int useMtime = (cksigFlags & CKSIG_SHA1)==0
178 && db_get_boolean("mtime-changes", 1);
179
180 db_begin_transaction();
181 db_prepare(&q, "SELECT id, %Q || pathname,"
182 " vfile.mrid, deleted, chnged, uuid, size, mtime,"
183 " CASE WHEN isexe THEN %d WHEN islink THEN %d ELSE %d END"
184 " FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
185 " WHERE vid=%d ", g.zLocalRoot, PERM_EXE, PERM_LNK, PERM_REG,
186 vid);
187 while( db_step(&q)==SQLITE_ROW ){
188 int id, rid, isDeleted;
189 const char *zName;
190 int chnged = 0;
191 int oldChnged;
192 int origPerm;
193 int currentPerm;
194 i64 oldMtime;
195 i64 currentMtime;
196 i64 origSize;
197 i64 currentSize;
198
@@ -192,10 +203,12 @@
203 oldChnged = chnged = db_column_int(&q, 4);
204 oldMtime = db_column_int64(&q, 7);
205 origSize = db_column_int64(&q, 6);
206 currentSize = file_wd_size(zName);
207 currentMtime = file_wd_mtime(0);
208 origPerm = db_column_int(&q, 8);
209 currentPerm = file_wd_perm(zName);
210 if( chnged==0 && (isDeleted || rid==0) ){
211 /* "fossil rm" or "fossil add" always change the file */
212 chnged = 1;
213 }else if( !file_wd_isfile_or_link(0) && currentSize>=0 ){
214 if( cksigFlags & CKSIG_ENOTFILE ){
@@ -245,10 +258,25 @@
258 file_set_mtime(zName, desiredMtime);
259 currentMtime = file_wd_mtime(zName);
260 }
261 }
262 }
263 #ifndef _WIN32
264 if( chnged==0 || chnged==6 || chnged==7 || chnged==8 || chnged==9 ){
265 if( origPerm == currentPerm ){
266 chnged = 0;
267 }else if( currentPerm == PERM_EXE ){
268 chnged = 6;
269 }else if( currentPerm == PERM_LNK ){
270 chnged = 7;
271 }else if( origPerm == PERM_EXE ){
272 chnged = 8;
273 }else if( origPerm == PERM_LNK ){
274 chnged = 9;
275 }
276 }
277 #endif
278 if( currentMtime!=oldMtime || chnged!=oldChnged ){
279 db_multi_exec("UPDATE vfile SET mtime=%lld, chnged=%d WHERE id=%d",
280 currentMtime, chnged, id);
281 }
282 }
283
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1151,11 +1151,13 @@
11511151
return zTarget+5;
11521152
}
11531153
if( strcmp(zTarget, "Sandbox")==0 ) return zTarget;
11541154
if( wiki_name_is_wellformed((const unsigned char *)zTarget)
11551155
&& ((p->state & WIKI_NOBADLINKS)==0 ||
1156
- db_exists("SELECT 1 FROM tag WHERE tagname GLOB 'wiki-%q'", zTarget))
1156
+ db_exists("SELECT 1 FROM tag WHERE tagname GLOB 'wiki-%q'"
1157
+ " AND (SELECT value FROM tagxref WHERE tagid=tag.tagid"
1158
+ " ORDER BY mtime DESC LIMIT 1) > 0", zTarget))
11571159
){
11581160
return zTarget;
11591161
}
11601162
return 0;
11611163
}
11621164
11631165
ADDED test/contains-selector.test
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1151,11 +1151,13 @@
1151 return zTarget+5;
1152 }
1153 if( strcmp(zTarget, "Sandbox")==0 ) return zTarget;
1154 if( wiki_name_is_wellformed((const unsigned char *)zTarget)
1155 && ((p->state & WIKI_NOBADLINKS)==0 ||
1156 db_exists("SELECT 1 FROM tag WHERE tagname GLOB 'wiki-%q'", zTarget))
 
 
1157 ){
1158 return zTarget;
1159 }
1160 return 0;
1161 }
1162
1163 DDED test/contains-selector.test
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1151,11 +1151,13 @@
1151 return zTarget+5;
1152 }
1153 if( strcmp(zTarget, "Sandbox")==0 ) return zTarget;
1154 if( wiki_name_is_wellformed((const unsigned char *)zTarget)
1155 && ((p->state & WIKI_NOBADLINKS)==0 ||
1156 db_exists("SELECT 1 FROM tag WHERE tagname GLOB 'wiki-%q'"
1157 " AND (SELECT value FROM tagxref WHERE tagid=tag.tagid"
1158 " ORDER BY mtime DESC LIMIT 1) > 0", zTarget))
1159 ){
1160 return zTarget;
1161 }
1162 return 0;
1163 }
1164
1165 DDED test/contains-selector.test
--- a/test/contains-selector.test
+++ b/test/contains-selector.test
@@ -0,0 +1,43 @@
1
+#
2
+# Copyright (c) 2015 D. Richard Hipp
3
+#
4
+# This program is free software; you can redistribute it and/or
5
+# modify it under the terms of the Simplified BSD License (also
6
+# known as the "2-Clause License" or "FreeBSD License".)
7
+#
8
+# This program is distributed in the hope that it will be useful,
9
+# but without any warranty; without even the implied warranty of
10
+# merchantability or fitness for a particular purpose.
11
+#
12
+# Author contact information:
13
+# [email protected]
14
+# http://www.hwaci.com/drh/
15
+#
16
+############################################################################
17
+#
18
+# Test containsSelector() proc contains-selector {testId css selectorResultMap} {
19
+ set css [string trim $css]
20
+ set filename [file join $::tempPath compare-selector.css]
21
+ set fh [open $filename w]
22
+ puts -nonewline $fh $css
23
+ close $fh
24
+ foreach {selector found} $selectorResultMap {
25
+ set expected "$selector [expr {$found ? "found" : "not found"}]"
26
+ set result [fossil test-contains-selector $filename $selector]
27
+ test "contains-selector $testId $selector" {$result eq $expected}
28
+ }
29
+ file delete $filename
30
+}
31
+
32
+contains-selector 1 {
33
+ .a.b {}
34
+ .c .de {}
35
+ /* comment */
36
+ .c .d, .e /* comment */ {}
37
+} {
38
+ .a 0
39
+ .b 0
40
+ .a.b 1
41
+ .c 0
42
+ .d 0
43
+ {.c
--- a/test/contains-selector.test
+++ b/test/contains-selector.test
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/contains-selector.test
+++ b/test/contains-selector.test
@@ -0,0 +1,43 @@
1 #
2 # Copyright (c) 2015 D. Richard Hipp
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the Simplified BSD License (also
6 # known as the "2-Clause License" or "FreeBSD License".)
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but without any warranty; without even the implied warranty of
10 # merchantability or fitness for a particular purpose.
11 #
12 # Author contact information:
13 # [email protected]
14 # http://www.hwaci.com/drh/
15 #
16 ############################################################################
17 #
18 # Test containsSelector() proc contains-selector {testId css selectorResultMap} {
19 set css [string trim $css]
20 set filename [file join $::tempPath compare-selector.css]
21 set fh [open $filename w]
22 puts -nonewline $fh $css
23 close $fh
24 foreach {selector found} $selectorResultMap {
25 set expected "$selector [expr {$found ? "found" : "not found"}]"
26 set result [fossil test-contains-selector $filename $selector]
27 test "contains-selector $testId $selector" {$result eq $expected}
28 }
29 file delete $filename
30 }
31
32 contains-selector 1 {
33 .a.b {}
34 .c .de {}
35 /* comment */
36 .c .d, .e /* comment */ {}
37 } {
38 .a 0
39 .b 0
40 .a.b 1
41 .c 0
42 .d 0
43 {.c
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -83,11 +83,11 @@
8383
8484
# define the SQLite files, which need special flags on compile
8585
SQLITESRC=sqlite3.c
8686
ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
8787
SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
88
-SQLITEDEFINES=-DNDEBUG=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_WIN32_NO_ANSI
88
+SQLITEDEFINES=-DNDEBUG=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_WIN32_NO_ANSI
8989
9090
# define the SQLite shell files, which need special flags on compile
9191
SQLITESHELLSRC=shell.c
9292
ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
9393
SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
9494
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -83,11 +83,11 @@
83
84 # define the SQLite files, which need special flags on compile
85 SQLITESRC=sqlite3.c
86 ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
87 SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
88 SQLITEDEFINES=-DNDEBUG=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_WIN32_NO_ANSI
89
90 # define the SQLite shell files, which need special flags on compile
91 SQLITESHELLSRC=shell.c
92 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
93 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
94
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -83,11 +83,11 @@
83
84 # define the SQLite files, which need special flags on compile
85 SQLITESRC=sqlite3.c
86 ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
87 SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
88 SQLITEDEFINES=-DNDEBUG=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_WIN32_NO_ANSI
89
90 # define the SQLite shell files, which need special flags on compile
91 SQLITESHELLSRC=shell.c
92 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
93 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
94
+11 -5
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -24,17 +24,17 @@
2424
CFLAGS = -o
2525
BCC = $(DMDIR)\bin\dmc $(CFLAGS)
2626
TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
2727
LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
2828
29
-SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS
29
+SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_DBSTAT_VTAB
3030
3131
SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
3232
33
-SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.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 export_.c file_.c finfo_.c foci_.c fusefs_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c sitemap_.c skins_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
33
+SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.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 export_.c file_.c finfo_.c foci_.c fusefs_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c piechart_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c sitemap_.c skins_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
3434
35
-OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\builtin$O $(OBJDIR)\bundle$O $(OBJDIR)\cache$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\foci$O $(OBJDIR)\fusefs$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\loadctrl$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\publish$O $(OBJDIR)\purge$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\sitemap$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\statrep$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
35
+OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\builtin$O $(OBJDIR)\bundle$O $(OBJDIR)\cache$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\foci$O $(OBJDIR)\fusefs$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\loadctrl$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\piechart$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\publish$O $(OBJDIR)\purge$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\sitemap$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\statrep$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
3636
3737
3838
RC=$(DMDIR)\bin\rcc
3939
RCFLAGS=-32 -w1 -I$(SRCDIR) /D__DMC__
4040
@@ -49,11 +49,11 @@
4949
5050
$(OBJDIR)\fossil.res: $B\win\fossil.rc
5151
$(RC) $(RCFLAGS) -o$@ $**
5252
5353
$(OBJDIR)\link: $B\win\Makefile.dmc $(OBJDIR)\fossil.res
54
- +echo add allrepo attach bag bisect blob branch browse builtin bundle cache captcha cgi checkin checkout clearsign clone comformat configure content db delta deltacmd descendants diff diffcmd doc encode event export file finfo foci fusefs glob graph gzip http http_socket http_ssl http_transport import info json json_artifact json_branch json_config json_diff json_dir json_finfo json_login json_query json_report json_status json_tag json_timeline json_user json_wiki leaf loadctrl login lookslike main manifest markdown markdown_html md5 merge merge3 moderate name path pivot popen pqueue printf publish purge rebuild regexp report rss schema search setup sha1 shun sitemap skins sqlcmd stash stat statrep style sync tag tar th_main timeline tkt tktsetup undo unicode update url user utf8 util verify vfile wiki wikiformat winfile winhttp wysiwyg xfer xfersetup zip shell sqlite3 th th_lang > $@
54
+ +echo add allrepo attach bag bisect blob branch browse builtin bundle cache captcha cgi checkin checkout clearsign clone comformat configure content db delta deltacmd descendants diff diffcmd doc encode event export file finfo foci fusefs glob graph gzip http http_socket http_ssl http_transport import info json json_artifact json_branch json_config json_diff json_dir json_finfo json_login json_query json_report json_status json_tag json_timeline json_user json_wiki leaf loadctrl login lookslike main manifest markdown markdown_html md5 merge merge3 moderate name path piechart pivot popen pqueue printf publish purge rebuild regexp report rss schema search setup sha1 shun sitemap skins sqlcmd stash stat statrep style sync tag tar th_main timeline tkt tktsetup undo unicode update url user utf8 util verify vfile wiki wikiformat winfile winhttp wysiwyg xfer xfersetup zip shell sqlite3 th th_lang > $@
5555
+echo fossil >> $@
5656
+echo fossil >> $@
5757
+echo $(LIBS) >> $@
5858
+echo. >> $@
5959
+echo fossil >> $@
@@ -554,10 +554,16 @@
554554
$(OBJDIR)\path$O : path_.c path.h
555555
$(TCC) -o$@ -c path_.c
556556
557557
path_.c : $(SRCDIR)\path.c
558558
+translate$E $** > $@
559
+
560
+$(OBJDIR)\piechart$O : piechart_.c piechart.h
561
+ $(TCC) -o$@ -c piechart_.c
562
+
563
+piechart_.c : $(SRCDIR)\piechart.c
564
+ +translate$E $** > $@
559565
560566
$(OBJDIR)\pivot$O : pivot_.c pivot.h
561567
$(TCC) -o$@ -c pivot_.c
562568
563569
pivot_.c : $(SRCDIR)\pivot.c
@@ -832,7 +838,7 @@
832838
833839
zip_.c : $(SRCDIR)\zip.c
834840
+translate$E $** > $@
835841
836842
headers: makeheaders$E page_index.h builtin_data.h VERSION.h
837
- +makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h builtin_.c:builtin.h bundle_.c:bundle.h cache_.c:cache.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 export_.c:export.h file_.c:file.h finfo_.c:finfo.h foci_.c:foci.h fusefs_.c:fusefs.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_status_.c:json_status.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h loadctrl_.c:loadctrl.h login_.c:login.h lookslike_.c:lookslike.h main_.c:main.h manifest_.c:manifest.h markdown_.c:markdown.h markdown_html_.c:markdown_html.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h path_.c:path.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h publish_.c:publish.h purge_.c:purge.h rebuild_.c:rebuild.h regexp_.c:regexp.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 sitemap_.c:sitemap.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h statrep_.c:statrep.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h unicode_.c:unicode.h update_.c:update.h url_.c:url.h user_.c:user.h utf8_.c:utf8.h util_.c:util.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winfile_.c:winfile.h winhttp_.c:winhttp.h wysiwyg_.c:wysiwyg.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h
843
+ +makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h builtin_.c:builtin.h bundle_.c:bundle.h cache_.c:cache.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 export_.c:export.h file_.c:file.h finfo_.c:finfo.h foci_.c:foci.h fusefs_.c:fusefs.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_status_.c:json_status.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h loadctrl_.c:loadctrl.h login_.c:login.h lookslike_.c:lookslike.h main_.c:main.h manifest_.c:manifest.h markdown_.c:markdown.h markdown_html_.c:markdown_html.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h path_.c:path.h piechart_.c:piechart.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h publish_.c:publish.h purge_.c:purge.h rebuild_.c:rebuild.h regexp_.c:regexp.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 sitemap_.c:sitemap.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h statrep_.c:statrep.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h unicode_.c:unicode.h update_.c:update.h url_.c:url.h user_.c:user.h utf8_.c:utf8.h util_.c:util.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winfile_.c:winfile.h winhttp_.c:winhttp.h wysiwyg_.c:wysiwyg.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h
838844
@copy /Y nul: headers
839845
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -24,17 +24,17 @@
24 CFLAGS = -o
25 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
26 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
27 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
28
29 SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS
30
31 SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
32
33 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.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 export_.c file_.c finfo_.c foci_.c fusefs_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c sitemap_.c skins_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
34
35 OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\builtin$O $(OBJDIR)\bundle$O $(OBJDIR)\cache$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\foci$O $(OBJDIR)\fusefs$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\loadctrl$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\publish$O $(OBJDIR)\purge$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\sitemap$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\statrep$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
36
37
38 RC=$(DMDIR)\bin\rcc
39 RCFLAGS=-32 -w1 -I$(SRCDIR) /D__DMC__
40
@@ -49,11 +49,11 @@
49
50 $(OBJDIR)\fossil.res: $B\win\fossil.rc
51 $(RC) $(RCFLAGS) -o$@ $**
52
53 $(OBJDIR)\link: $B\win\Makefile.dmc $(OBJDIR)\fossil.res
54 +echo add allrepo attach bag bisect blob branch browse builtin bundle cache captcha cgi checkin checkout clearsign clone comformat configure content db delta deltacmd descendants diff diffcmd doc encode event export file finfo foci fusefs glob graph gzip http http_socket http_ssl http_transport import info json json_artifact json_branch json_config json_diff json_dir json_finfo json_login json_query json_report json_status json_tag json_timeline json_user json_wiki leaf loadctrl login lookslike main manifest markdown markdown_html md5 merge merge3 moderate name path pivot popen pqueue printf publish purge rebuild regexp report rss schema search setup sha1 shun sitemap skins sqlcmd stash stat statrep style sync tag tar th_main timeline tkt tktsetup undo unicode update url user utf8 util verify vfile wiki wikiformat winfile winhttp wysiwyg xfer xfersetup zip shell sqlite3 th th_lang > $@
55 +echo fossil >> $@
56 +echo fossil >> $@
57 +echo $(LIBS) >> $@
58 +echo. >> $@
59 +echo fossil >> $@
@@ -554,10 +554,16 @@
554 $(OBJDIR)\path$O : path_.c path.h
555 $(TCC) -o$@ -c path_.c
556
557 path_.c : $(SRCDIR)\path.c
558 +translate$E $** > $@
 
 
 
 
 
 
559
560 $(OBJDIR)\pivot$O : pivot_.c pivot.h
561 $(TCC) -o$@ -c pivot_.c
562
563 pivot_.c : $(SRCDIR)\pivot.c
@@ -832,7 +838,7 @@
832
833 zip_.c : $(SRCDIR)\zip.c
834 +translate$E $** > $@
835
836 headers: makeheaders$E page_index.h builtin_data.h VERSION.h
837 +makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h builtin_.c:builtin.h bundle_.c:bundle.h cache_.c:cache.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 export_.c:export.h file_.c:file.h finfo_.c:finfo.h foci_.c:foci.h fusefs_.c:fusefs.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_status_.c:json_status.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h loadctrl_.c:loadctrl.h login_.c:login.h lookslike_.c:lookslike.h main_.c:main.h manifest_.c:manifest.h markdown_.c:markdown.h markdown_html_.c:markdown_html.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h path_.c:path.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h publish_.c:publish.h purge_.c:purge.h rebuild_.c:rebuild.h regexp_.c:regexp.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 sitemap_.c:sitemap.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h statrep_.c:statrep.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h unicode_.c:unicode.h update_.c:update.h url_.c:url.h user_.c:user.h utf8_.c:utf8.h util_.c:util.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winfile_.c:winfile.h winhttp_.c:winhttp.h wysiwyg_.c:wysiwyg.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h
838 @copy /Y nul: headers
839
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -24,17 +24,17 @@
24 CFLAGS = -o
25 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
26 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
27 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
28
29 SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_DBSTAT_VTAB
30
31 SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
32
33 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.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 export_.c file_.c finfo_.c foci_.c fusefs_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c piechart_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c sitemap_.c skins_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
34
35 OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\builtin$O $(OBJDIR)\bundle$O $(OBJDIR)\cache$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\foci$O $(OBJDIR)\fusefs$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\loadctrl$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\piechart$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\publish$O $(OBJDIR)\purge$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\sitemap$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\statrep$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
36
37
38 RC=$(DMDIR)\bin\rcc
39 RCFLAGS=-32 -w1 -I$(SRCDIR) /D__DMC__
40
@@ -49,11 +49,11 @@
49
50 $(OBJDIR)\fossil.res: $B\win\fossil.rc
51 $(RC) $(RCFLAGS) -o$@ $**
52
53 $(OBJDIR)\link: $B\win\Makefile.dmc $(OBJDIR)\fossil.res
54 +echo add allrepo attach bag bisect blob branch browse builtin bundle cache captcha cgi checkin checkout clearsign clone comformat configure content db delta deltacmd descendants diff diffcmd doc encode event export file finfo foci fusefs glob graph gzip http http_socket http_ssl http_transport import info json json_artifact json_branch json_config json_diff json_dir json_finfo json_login json_query json_report json_status json_tag json_timeline json_user json_wiki leaf loadctrl login lookslike main manifest markdown markdown_html md5 merge merge3 moderate name path piechart pivot popen pqueue printf publish purge rebuild regexp report rss schema search setup sha1 shun sitemap skins sqlcmd stash stat statrep style sync tag tar th_main timeline tkt tktsetup undo unicode update url user utf8 util verify vfile wiki wikiformat winfile winhttp wysiwyg xfer xfersetup zip shell sqlite3 th th_lang > $@
55 +echo fossil >> $@
56 +echo fossil >> $@
57 +echo $(LIBS) >> $@
58 +echo. >> $@
59 +echo fossil >> $@
@@ -554,10 +554,16 @@
554 $(OBJDIR)\path$O : path_.c path.h
555 $(TCC) -o$@ -c path_.c
556
557 path_.c : $(SRCDIR)\path.c
558 +translate$E $** > $@
559
560 $(OBJDIR)\piechart$O : piechart_.c piechart.h
561 $(TCC) -o$@ -c piechart_.c
562
563 piechart_.c : $(SRCDIR)\piechart.c
564 +translate$E $** > $@
565
566 $(OBJDIR)\pivot$O : pivot_.c pivot.h
567 $(TCC) -o$@ -c pivot_.c
568
569 pivot_.c : $(SRCDIR)\pivot.c
@@ -832,7 +838,7 @@
838
839 zip_.c : $(SRCDIR)\zip.c
840 +translate$E $** > $@
841
842 headers: makeheaders$E page_index.h builtin_data.h VERSION.h
843 +makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h builtin_.c:builtin.h bundle_.c:bundle.h cache_.c:cache.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 export_.c:export.h file_.c:file.h finfo_.c:finfo.h foci_.c:foci.h fusefs_.c:fusefs.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_status_.c:json_status.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h loadctrl_.c:loadctrl.h login_.c:login.h lookslike_.c:lookslike.h main_.c:main.h manifest_.c:manifest.h markdown_.c:markdown.h markdown_html_.c:markdown_html.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h path_.c:path.h piechart_.c:piechart.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h publish_.c:publish.h purge_.c:purge.h rebuild_.c:rebuild.h regexp_.c:regexp.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 sitemap_.c:sitemap.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h statrep_.c:statrep.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h unicode_.c:unicode.h update_.c:update.h url_.c:url.h user_.c:user.h utf8_.c:utf8.h util_.c:util.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winfile_.c:winfile.h winhttp_.c:winhttp.h wysiwyg_.c:wysiwyg.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h
844 @copy /Y nul: headers
845
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -447,10 +447,11 @@
447447
$(SRCDIR)/merge.c \
448448
$(SRCDIR)/merge3.c \
449449
$(SRCDIR)/moderate.c \
450450
$(SRCDIR)/name.c \
451451
$(SRCDIR)/path.c \
452
+ $(SRCDIR)/piechart.c \
452453
$(SRCDIR)/pivot.c \
453454
$(SRCDIR)/popen.c \
454455
$(SRCDIR)/pqueue.c \
455456
$(SRCDIR)/printf.c \
456457
$(SRCDIR)/publish.c \
@@ -618,10 +619,11 @@
618619
$(OBJDIR)/merge_.c \
619620
$(OBJDIR)/merge3_.c \
620621
$(OBJDIR)/moderate_.c \
621622
$(OBJDIR)/name_.c \
622623
$(OBJDIR)/path_.c \
624
+ $(OBJDIR)/piechart_.c \
623625
$(OBJDIR)/pivot_.c \
624626
$(OBJDIR)/popen_.c \
625627
$(OBJDIR)/pqueue_.c \
626628
$(OBJDIR)/printf_.c \
627629
$(OBJDIR)/publish_.c \
@@ -738,10 +740,11 @@
738740
$(OBJDIR)/merge.o \
739741
$(OBJDIR)/merge3.o \
740742
$(OBJDIR)/moderate.o \
741743
$(OBJDIR)/name.o \
742744
$(OBJDIR)/path.o \
745
+ $(OBJDIR)/piechart.o \
743746
$(OBJDIR)/pivot.o \
744747
$(OBJDIR)/popen.o \
745748
$(OBJDIR)/pqueue.o \
746749
$(OBJDIR)/printf.o \
747750
$(OBJDIR)/publish.o \
@@ -1051,10 +1054,11 @@
10511054
$(OBJDIR)/merge_.c:$(OBJDIR)/merge.h \
10521055
$(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h \
10531056
$(OBJDIR)/moderate_.c:$(OBJDIR)/moderate.h \
10541057
$(OBJDIR)/name_.c:$(OBJDIR)/name.h \
10551058
$(OBJDIR)/path_.c:$(OBJDIR)/path.h \
1059
+ $(OBJDIR)/piechart_.c:$(OBJDIR)/piechart.h \
10561060
$(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
10571061
$(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
10581062
$(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
10591063
$(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
10601064
$(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
@@ -1681,10 +1685,18 @@
16811685
16821686
$(OBJDIR)/path.o: $(OBJDIR)/path_.c $(OBJDIR)/path.h $(SRCDIR)/config.h
16831687
$(XTCC) -o $(OBJDIR)/path.o -c $(OBJDIR)/path_.c
16841688
16851689
$(OBJDIR)/path.h: $(OBJDIR)/headers
1690
+
1691
+$(OBJDIR)/piechart_.c: $(SRCDIR)/piechart.c $(TRANSLATE)
1692
+ $(TRANSLATE) $(SRCDIR)/piechart.c >$@
1693
+
1694
+$(OBJDIR)/piechart.o: $(OBJDIR)/piechart_.c $(OBJDIR)/piechart.h $(SRCDIR)/config.h
1695
+ $(XTCC) -o $(OBJDIR)/piechart.o -c $(OBJDIR)/piechart_.c
1696
+
1697
+$(OBJDIR)/piechart.h: $(OBJDIR)/headers
16861698
16871699
$(OBJDIR)/pivot_.c: $(SRCDIR)/pivot.c $(TRANSLATE)
16881700
$(TRANSLATE) $(SRCDIR)/pivot.c >$@
16891701
16901702
$(OBJDIR)/pivot.o: $(OBJDIR)/pivot_.c $(OBJDIR)/pivot.h $(SRCDIR)/config.h
@@ -2059,10 +2071,11 @@
20592071
-DSQLITE_DEFAULT_FILE_FORMAT=4 \
20602072
-DSQLITE_OMIT_DEPRECATED \
20612073
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
20622074
-DSQLITE_ENABLE_FTS4 \
20632075
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
2076
+ -DSQLITE_ENABLE_DBSTAT_VTAB \
20642077
-DSQLITE_WIN32_NO_ANSI \
20652078
-D_HAVE__MINGW_H \
20662079
-DSQLITE_USE_MALLOC_H \
20672080
-DSQLITE_USE_MSIZE
20682081
20692082
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -447,10 +447,11 @@
447 $(SRCDIR)/merge.c \
448 $(SRCDIR)/merge3.c \
449 $(SRCDIR)/moderate.c \
450 $(SRCDIR)/name.c \
451 $(SRCDIR)/path.c \
 
452 $(SRCDIR)/pivot.c \
453 $(SRCDIR)/popen.c \
454 $(SRCDIR)/pqueue.c \
455 $(SRCDIR)/printf.c \
456 $(SRCDIR)/publish.c \
@@ -618,10 +619,11 @@
618 $(OBJDIR)/merge_.c \
619 $(OBJDIR)/merge3_.c \
620 $(OBJDIR)/moderate_.c \
621 $(OBJDIR)/name_.c \
622 $(OBJDIR)/path_.c \
 
623 $(OBJDIR)/pivot_.c \
624 $(OBJDIR)/popen_.c \
625 $(OBJDIR)/pqueue_.c \
626 $(OBJDIR)/printf_.c \
627 $(OBJDIR)/publish_.c \
@@ -738,10 +740,11 @@
738 $(OBJDIR)/merge.o \
739 $(OBJDIR)/merge3.o \
740 $(OBJDIR)/moderate.o \
741 $(OBJDIR)/name.o \
742 $(OBJDIR)/path.o \
 
743 $(OBJDIR)/pivot.o \
744 $(OBJDIR)/popen.o \
745 $(OBJDIR)/pqueue.o \
746 $(OBJDIR)/printf.o \
747 $(OBJDIR)/publish.o \
@@ -1051,10 +1054,11 @@
1051 $(OBJDIR)/merge_.c:$(OBJDIR)/merge.h \
1052 $(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h \
1053 $(OBJDIR)/moderate_.c:$(OBJDIR)/moderate.h \
1054 $(OBJDIR)/name_.c:$(OBJDIR)/name.h \
1055 $(OBJDIR)/path_.c:$(OBJDIR)/path.h \
 
1056 $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
1057 $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
1058 $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
1059 $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
1060 $(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
@@ -1681,10 +1685,18 @@
1681
1682 $(OBJDIR)/path.o: $(OBJDIR)/path_.c $(OBJDIR)/path.h $(SRCDIR)/config.h
1683 $(XTCC) -o $(OBJDIR)/path.o -c $(OBJDIR)/path_.c
1684
1685 $(OBJDIR)/path.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
1686
1687 $(OBJDIR)/pivot_.c: $(SRCDIR)/pivot.c $(TRANSLATE)
1688 $(TRANSLATE) $(SRCDIR)/pivot.c >$@
1689
1690 $(OBJDIR)/pivot.o: $(OBJDIR)/pivot_.c $(OBJDIR)/pivot.h $(SRCDIR)/config.h
@@ -2059,10 +2071,11 @@
2059 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
2060 -DSQLITE_OMIT_DEPRECATED \
2061 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
2062 -DSQLITE_ENABLE_FTS4 \
2063 -DSQLITE_ENABLE_FTS3_PARENTHESIS \
 
2064 -DSQLITE_WIN32_NO_ANSI \
2065 -D_HAVE__MINGW_H \
2066 -DSQLITE_USE_MALLOC_H \
2067 -DSQLITE_USE_MSIZE
2068
2069
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -447,10 +447,11 @@
447 $(SRCDIR)/merge.c \
448 $(SRCDIR)/merge3.c \
449 $(SRCDIR)/moderate.c \
450 $(SRCDIR)/name.c \
451 $(SRCDIR)/path.c \
452 $(SRCDIR)/piechart.c \
453 $(SRCDIR)/pivot.c \
454 $(SRCDIR)/popen.c \
455 $(SRCDIR)/pqueue.c \
456 $(SRCDIR)/printf.c \
457 $(SRCDIR)/publish.c \
@@ -618,10 +619,11 @@
619 $(OBJDIR)/merge_.c \
620 $(OBJDIR)/merge3_.c \
621 $(OBJDIR)/moderate_.c \
622 $(OBJDIR)/name_.c \
623 $(OBJDIR)/path_.c \
624 $(OBJDIR)/piechart_.c \
625 $(OBJDIR)/pivot_.c \
626 $(OBJDIR)/popen_.c \
627 $(OBJDIR)/pqueue_.c \
628 $(OBJDIR)/printf_.c \
629 $(OBJDIR)/publish_.c \
@@ -738,10 +740,11 @@
740 $(OBJDIR)/merge.o \
741 $(OBJDIR)/merge3.o \
742 $(OBJDIR)/moderate.o \
743 $(OBJDIR)/name.o \
744 $(OBJDIR)/path.o \
745 $(OBJDIR)/piechart.o \
746 $(OBJDIR)/pivot.o \
747 $(OBJDIR)/popen.o \
748 $(OBJDIR)/pqueue.o \
749 $(OBJDIR)/printf.o \
750 $(OBJDIR)/publish.o \
@@ -1051,10 +1054,11 @@
1054 $(OBJDIR)/merge_.c:$(OBJDIR)/merge.h \
1055 $(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h \
1056 $(OBJDIR)/moderate_.c:$(OBJDIR)/moderate.h \
1057 $(OBJDIR)/name_.c:$(OBJDIR)/name.h \
1058 $(OBJDIR)/path_.c:$(OBJDIR)/path.h \
1059 $(OBJDIR)/piechart_.c:$(OBJDIR)/piechart.h \
1060 $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
1061 $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
1062 $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
1063 $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
1064 $(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
@@ -1681,10 +1685,18 @@
1685
1686 $(OBJDIR)/path.o: $(OBJDIR)/path_.c $(OBJDIR)/path.h $(SRCDIR)/config.h
1687 $(XTCC) -o $(OBJDIR)/path.o -c $(OBJDIR)/path_.c
1688
1689 $(OBJDIR)/path.h: $(OBJDIR)/headers
1690
1691 $(OBJDIR)/piechart_.c: $(SRCDIR)/piechart.c $(TRANSLATE)
1692 $(TRANSLATE) $(SRCDIR)/piechart.c >$@
1693
1694 $(OBJDIR)/piechart.o: $(OBJDIR)/piechart_.c $(OBJDIR)/piechart.h $(SRCDIR)/config.h
1695 $(XTCC) -o $(OBJDIR)/piechart.o -c $(OBJDIR)/piechart_.c
1696
1697 $(OBJDIR)/piechart.h: $(OBJDIR)/headers
1698
1699 $(OBJDIR)/pivot_.c: $(SRCDIR)/pivot.c $(TRANSLATE)
1700 $(TRANSLATE) $(SRCDIR)/pivot.c >$@
1701
1702 $(OBJDIR)/pivot.o: $(OBJDIR)/pivot_.c $(OBJDIR)/pivot.h $(SRCDIR)/config.h
@@ -2059,10 +2071,11 @@
2071 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
2072 -DSQLITE_OMIT_DEPRECATED \
2073 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
2074 -DSQLITE_ENABLE_FTS4 \
2075 -DSQLITE_ENABLE_FTS3_PARENTHESIS \
2076 -DSQLITE_ENABLE_DBSTAT_VTAB \
2077 -DSQLITE_WIN32_NO_ANSI \
2078 -D_HAVE__MINGW_H \
2079 -DSQLITE_USE_MALLOC_H \
2080 -DSQLITE_USE_MSIZE
2081
2082
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -447,10 +447,11 @@
447447
$(SRCDIR)/merge.c \
448448
$(SRCDIR)/merge3.c \
449449
$(SRCDIR)/moderate.c \
450450
$(SRCDIR)/name.c \
451451
$(SRCDIR)/path.c \
452
+ $(SRCDIR)/piechart.c \
452453
$(SRCDIR)/pivot.c \
453454
$(SRCDIR)/popen.c \
454455
$(SRCDIR)/pqueue.c \
455456
$(SRCDIR)/printf.c \
456457
$(SRCDIR)/publish.c \
@@ -618,10 +619,11 @@
618619
$(OBJDIR)/merge_.c \
619620
$(OBJDIR)/merge3_.c \
620621
$(OBJDIR)/moderate_.c \
621622
$(OBJDIR)/name_.c \
622623
$(OBJDIR)/path_.c \
624
+ $(OBJDIR)/piechart_.c \
623625
$(OBJDIR)/pivot_.c \
624626
$(OBJDIR)/popen_.c \
625627
$(OBJDIR)/pqueue_.c \
626628
$(OBJDIR)/printf_.c \
627629
$(OBJDIR)/publish_.c \
@@ -738,10 +740,11 @@
738740
$(OBJDIR)/merge.o \
739741
$(OBJDIR)/merge3.o \
740742
$(OBJDIR)/moderate.o \
741743
$(OBJDIR)/name.o \
742744
$(OBJDIR)/path.o \
745
+ $(OBJDIR)/piechart.o \
743746
$(OBJDIR)/pivot.o \
744747
$(OBJDIR)/popen.o \
745748
$(OBJDIR)/pqueue.o \
746749
$(OBJDIR)/printf.o \
747750
$(OBJDIR)/publish.o \
@@ -1051,10 +1054,11 @@
10511054
$(OBJDIR)/merge_.c:$(OBJDIR)/merge.h \
10521055
$(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h \
10531056
$(OBJDIR)/moderate_.c:$(OBJDIR)/moderate.h \
10541057
$(OBJDIR)/name_.c:$(OBJDIR)/name.h \
10551058
$(OBJDIR)/path_.c:$(OBJDIR)/path.h \
1059
+ $(OBJDIR)/piechart_.c:$(OBJDIR)/piechart.h \
10561060
$(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
10571061
$(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
10581062
$(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
10591063
$(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
10601064
$(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
@@ -1681,10 +1685,18 @@
16811685
16821686
$(OBJDIR)/path.o: $(OBJDIR)/path_.c $(OBJDIR)/path.h $(SRCDIR)/config.h
16831687
$(XTCC) -o $(OBJDIR)/path.o -c $(OBJDIR)/path_.c
16841688
16851689
$(OBJDIR)/path.h: $(OBJDIR)/headers
1690
+
1691
+$(OBJDIR)/piechart_.c: $(SRCDIR)/piechart.c $(TRANSLATE)
1692
+ $(TRANSLATE) $(SRCDIR)/piechart.c >$@
1693
+
1694
+$(OBJDIR)/piechart.o: $(OBJDIR)/piechart_.c $(OBJDIR)/piechart.h $(SRCDIR)/config.h
1695
+ $(XTCC) -o $(OBJDIR)/piechart.o -c $(OBJDIR)/piechart_.c
1696
+
1697
+$(OBJDIR)/piechart.h: $(OBJDIR)/headers
16861698
16871699
$(OBJDIR)/pivot_.c: $(SRCDIR)/pivot.c $(TRANSLATE)
16881700
$(TRANSLATE) $(SRCDIR)/pivot.c >$@
16891701
16901702
$(OBJDIR)/pivot.o: $(OBJDIR)/pivot_.c $(OBJDIR)/pivot.h $(SRCDIR)/config.h
@@ -2059,10 +2071,11 @@
20592071
-DSQLITE_DEFAULT_FILE_FORMAT=4 \
20602072
-DSQLITE_OMIT_DEPRECATED \
20612073
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
20622074
-DSQLITE_ENABLE_FTS4 \
20632075
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
2076
+ -DSQLITE_ENABLE_DBSTAT_VTAB \
20642077
-DSQLITE_WIN32_NO_ANSI \
20652078
-D_HAVE__MINGW_H \
20662079
-DSQLITE_USE_MALLOC_H \
20672080
-DSQLITE_USE_MSIZE
20682081
20692082
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -447,10 +447,11 @@
447 $(SRCDIR)/merge.c \
448 $(SRCDIR)/merge3.c \
449 $(SRCDIR)/moderate.c \
450 $(SRCDIR)/name.c \
451 $(SRCDIR)/path.c \
 
452 $(SRCDIR)/pivot.c \
453 $(SRCDIR)/popen.c \
454 $(SRCDIR)/pqueue.c \
455 $(SRCDIR)/printf.c \
456 $(SRCDIR)/publish.c \
@@ -618,10 +619,11 @@
618 $(OBJDIR)/merge_.c \
619 $(OBJDIR)/merge3_.c \
620 $(OBJDIR)/moderate_.c \
621 $(OBJDIR)/name_.c \
622 $(OBJDIR)/path_.c \
 
623 $(OBJDIR)/pivot_.c \
624 $(OBJDIR)/popen_.c \
625 $(OBJDIR)/pqueue_.c \
626 $(OBJDIR)/printf_.c \
627 $(OBJDIR)/publish_.c \
@@ -738,10 +740,11 @@
738 $(OBJDIR)/merge.o \
739 $(OBJDIR)/merge3.o \
740 $(OBJDIR)/moderate.o \
741 $(OBJDIR)/name.o \
742 $(OBJDIR)/path.o \
 
743 $(OBJDIR)/pivot.o \
744 $(OBJDIR)/popen.o \
745 $(OBJDIR)/pqueue.o \
746 $(OBJDIR)/printf.o \
747 $(OBJDIR)/publish.o \
@@ -1051,10 +1054,11 @@
1051 $(OBJDIR)/merge_.c:$(OBJDIR)/merge.h \
1052 $(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h \
1053 $(OBJDIR)/moderate_.c:$(OBJDIR)/moderate.h \
1054 $(OBJDIR)/name_.c:$(OBJDIR)/name.h \
1055 $(OBJDIR)/path_.c:$(OBJDIR)/path.h \
 
1056 $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
1057 $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
1058 $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
1059 $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
1060 $(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
@@ -1681,10 +1685,18 @@
1681
1682 $(OBJDIR)/path.o: $(OBJDIR)/path_.c $(OBJDIR)/path.h $(SRCDIR)/config.h
1683 $(XTCC) -o $(OBJDIR)/path.o -c $(OBJDIR)/path_.c
1684
1685 $(OBJDIR)/path.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
1686
1687 $(OBJDIR)/pivot_.c: $(SRCDIR)/pivot.c $(TRANSLATE)
1688 $(TRANSLATE) $(SRCDIR)/pivot.c >$@
1689
1690 $(OBJDIR)/pivot.o: $(OBJDIR)/pivot_.c $(OBJDIR)/pivot.h $(SRCDIR)/config.h
@@ -2059,10 +2071,11 @@
2059 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
2060 -DSQLITE_OMIT_DEPRECATED \
2061 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
2062 -DSQLITE_ENABLE_FTS4 \
2063 -DSQLITE_ENABLE_FTS3_PARENTHESIS \
 
2064 -DSQLITE_WIN32_NO_ANSI \
2065 -D_HAVE__MINGW_H \
2066 -DSQLITE_USE_MALLOC_H \
2067 -DSQLITE_USE_MSIZE
2068
2069
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -447,10 +447,11 @@
447 $(SRCDIR)/merge.c \
448 $(SRCDIR)/merge3.c \
449 $(SRCDIR)/moderate.c \
450 $(SRCDIR)/name.c \
451 $(SRCDIR)/path.c \
452 $(SRCDIR)/piechart.c \
453 $(SRCDIR)/pivot.c \
454 $(SRCDIR)/popen.c \
455 $(SRCDIR)/pqueue.c \
456 $(SRCDIR)/printf.c \
457 $(SRCDIR)/publish.c \
@@ -618,10 +619,11 @@
619 $(OBJDIR)/merge_.c \
620 $(OBJDIR)/merge3_.c \
621 $(OBJDIR)/moderate_.c \
622 $(OBJDIR)/name_.c \
623 $(OBJDIR)/path_.c \
624 $(OBJDIR)/piechart_.c \
625 $(OBJDIR)/pivot_.c \
626 $(OBJDIR)/popen_.c \
627 $(OBJDIR)/pqueue_.c \
628 $(OBJDIR)/printf_.c \
629 $(OBJDIR)/publish_.c \
@@ -738,10 +740,11 @@
740 $(OBJDIR)/merge.o \
741 $(OBJDIR)/merge3.o \
742 $(OBJDIR)/moderate.o \
743 $(OBJDIR)/name.o \
744 $(OBJDIR)/path.o \
745 $(OBJDIR)/piechart.o \
746 $(OBJDIR)/pivot.o \
747 $(OBJDIR)/popen.o \
748 $(OBJDIR)/pqueue.o \
749 $(OBJDIR)/printf.o \
750 $(OBJDIR)/publish.o \
@@ -1051,10 +1054,11 @@
1054 $(OBJDIR)/merge_.c:$(OBJDIR)/merge.h \
1055 $(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h \
1056 $(OBJDIR)/moderate_.c:$(OBJDIR)/moderate.h \
1057 $(OBJDIR)/name_.c:$(OBJDIR)/name.h \
1058 $(OBJDIR)/path_.c:$(OBJDIR)/path.h \
1059 $(OBJDIR)/piechart_.c:$(OBJDIR)/piechart.h \
1060 $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
1061 $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
1062 $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
1063 $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
1064 $(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
@@ -1681,10 +1685,18 @@
1685
1686 $(OBJDIR)/path.o: $(OBJDIR)/path_.c $(OBJDIR)/path.h $(SRCDIR)/config.h
1687 $(XTCC) -o $(OBJDIR)/path.o -c $(OBJDIR)/path_.c
1688
1689 $(OBJDIR)/path.h: $(OBJDIR)/headers
1690
1691 $(OBJDIR)/piechart_.c: $(SRCDIR)/piechart.c $(TRANSLATE)
1692 $(TRANSLATE) $(SRCDIR)/piechart.c >$@
1693
1694 $(OBJDIR)/piechart.o: $(OBJDIR)/piechart_.c $(OBJDIR)/piechart.h $(SRCDIR)/config.h
1695 $(XTCC) -o $(OBJDIR)/piechart.o -c $(OBJDIR)/piechart_.c
1696
1697 $(OBJDIR)/piechart.h: $(OBJDIR)/headers
1698
1699 $(OBJDIR)/pivot_.c: $(SRCDIR)/pivot.c $(TRANSLATE)
1700 $(TRANSLATE) $(SRCDIR)/pivot.c >$@
1701
1702 $(OBJDIR)/pivot.o: $(OBJDIR)/pivot_.c $(OBJDIR)/pivot.h $(SRCDIR)/config.h
@@ -2059,10 +2071,11 @@
2071 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
2072 -DSQLITE_OMIT_DEPRECATED \
2073 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
2074 -DSQLITE_ENABLE_FTS4 \
2075 -DSQLITE_ENABLE_FTS3_PARENTHESIS \
2076 -DSQLITE_ENABLE_DBSTAT_VTAB \
2077 -DSQLITE_WIN32_NO_ANSI \
2078 -D_HAVE__MINGW_H \
2079 -DSQLITE_USE_MALLOC_H \
2080 -DSQLITE_USE_MSIZE
2081
2082
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -199,10 +199,11 @@
199199
/DSQLITE_DEFAULT_FILE_FORMAT=4 \
200200
/DSQLITE_OMIT_DEPRECATED \
201201
/DSQLITE_ENABLE_EXPLAIN_COMMENTS \
202202
/DSQLITE_ENABLE_FTS4 \
203203
/DSQLITE_ENABLE_FTS3_PARENTHESIS \
204
+ /DSQLITE_ENABLE_DBSTAT_VTAB \
204205
/DSQLITE_WIN32_NO_ANSI
205206
206207
SHELL_OPTIONS = /Dmain=sqlite3_shell \
207208
/DSQLITE_OMIT_LOAD_EXTENSION=1 \
208209
/DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
@@ -286,10 +287,11 @@
286287
merge_.c \
287288
merge3_.c \
288289
moderate_.c \
289290
name_.c \
290291
path_.c \
292
+ piechart_.c \
291293
pivot_.c \
292294
popen_.c \
293295
pqueue_.c \
294296
printf_.c \
295297
publish_.c \
@@ -456,10 +458,11 @@
456458
$(OX)\merge$O \
457459
$(OX)\merge3$O \
458460
$(OX)\moderate$O \
459461
$(OX)\name$O \
460462
$(OX)\path$O \
463
+ $(OX)\piechart$O \
461464
$(OX)\pivot$O \
462465
$(OX)\popen$O \
463466
$(OX)\pqueue$O \
464467
$(OX)\printf$O \
465468
$(OX)\publish$O \
@@ -631,10 +634,11 @@
631634
echo $(OX)\merge.obj >> $@
632635
echo $(OX)\merge3.obj >> $@
633636
echo $(OX)\moderate.obj >> $@
634637
echo $(OX)\name.obj >> $@
635638
echo $(OX)\path.obj >> $@
639
+ echo $(OX)\piechart.obj >> $@
636640
echo $(OX)\pivot.obj >> $@
637641
echo $(OX)\popen.obj >> $@
638642
echo $(OX)\pqueue.obj >> $@
639643
echo $(OX)\printf.obj >> $@
640644
echo $(OX)\publish.obj >> $@
@@ -1212,10 +1216,16 @@
12121216
$(OX)\path$O : path_.c path.h
12131217
$(TCC) /Fo$@ -c path_.c
12141218
12151219
path_.c : $(SRCDIR)\path.c
12161220
translate$E $** > $@
1221
+
1222
+$(OX)\piechart$O : piechart_.c piechart.h
1223
+ $(TCC) /Fo$@ -c piechart_.c
1224
+
1225
+piechart_.c : $(SRCDIR)\piechart.c
1226
+ translate$E $** > $@
12171227
12181228
$(OX)\pivot$O : pivot_.c pivot.h
12191229
$(TCC) /Fo$@ -c pivot_.c
12201230
12211231
pivot_.c : $(SRCDIR)\pivot.c
@@ -1565,10 +1575,11 @@
15651575
merge_.c:merge.h \
15661576
merge3_.c:merge3.h \
15671577
moderate_.c:moderate.h \
15681578
name_.c:name.h \
15691579
path_.c:path.h \
1580
+ piechart_.c:piechart.h \
15701581
pivot_.c:pivot.h \
15711582
popen_.c:popen.h \
15721583
pqueue_.c:pqueue.h \
15731584
printf_.c:printf.h \
15741585
publish_.c:publish.h \
15751586
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -199,10 +199,11 @@
199 /DSQLITE_DEFAULT_FILE_FORMAT=4 \
200 /DSQLITE_OMIT_DEPRECATED \
201 /DSQLITE_ENABLE_EXPLAIN_COMMENTS \
202 /DSQLITE_ENABLE_FTS4 \
203 /DSQLITE_ENABLE_FTS3_PARENTHESIS \
 
204 /DSQLITE_WIN32_NO_ANSI
205
206 SHELL_OPTIONS = /Dmain=sqlite3_shell \
207 /DSQLITE_OMIT_LOAD_EXTENSION=1 \
208 /DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
@@ -286,10 +287,11 @@
286 merge_.c \
287 merge3_.c \
288 moderate_.c \
289 name_.c \
290 path_.c \
 
291 pivot_.c \
292 popen_.c \
293 pqueue_.c \
294 printf_.c \
295 publish_.c \
@@ -456,10 +458,11 @@
456 $(OX)\merge$O \
457 $(OX)\merge3$O \
458 $(OX)\moderate$O \
459 $(OX)\name$O \
460 $(OX)\path$O \
 
461 $(OX)\pivot$O \
462 $(OX)\popen$O \
463 $(OX)\pqueue$O \
464 $(OX)\printf$O \
465 $(OX)\publish$O \
@@ -631,10 +634,11 @@
631 echo $(OX)\merge.obj >> $@
632 echo $(OX)\merge3.obj >> $@
633 echo $(OX)\moderate.obj >> $@
634 echo $(OX)\name.obj >> $@
635 echo $(OX)\path.obj >> $@
 
636 echo $(OX)\pivot.obj >> $@
637 echo $(OX)\popen.obj >> $@
638 echo $(OX)\pqueue.obj >> $@
639 echo $(OX)\printf.obj >> $@
640 echo $(OX)\publish.obj >> $@
@@ -1212,10 +1216,16 @@
1212 $(OX)\path$O : path_.c path.h
1213 $(TCC) /Fo$@ -c path_.c
1214
1215 path_.c : $(SRCDIR)\path.c
1216 translate$E $** > $@
 
 
 
 
 
 
1217
1218 $(OX)\pivot$O : pivot_.c pivot.h
1219 $(TCC) /Fo$@ -c pivot_.c
1220
1221 pivot_.c : $(SRCDIR)\pivot.c
@@ -1565,10 +1575,11 @@
1565 merge_.c:merge.h \
1566 merge3_.c:merge3.h \
1567 moderate_.c:moderate.h \
1568 name_.c:name.h \
1569 path_.c:path.h \
 
1570 pivot_.c:pivot.h \
1571 popen_.c:popen.h \
1572 pqueue_.c:pqueue.h \
1573 printf_.c:printf.h \
1574 publish_.c:publish.h \
1575
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -199,10 +199,11 @@
199 /DSQLITE_DEFAULT_FILE_FORMAT=4 \
200 /DSQLITE_OMIT_DEPRECATED \
201 /DSQLITE_ENABLE_EXPLAIN_COMMENTS \
202 /DSQLITE_ENABLE_FTS4 \
203 /DSQLITE_ENABLE_FTS3_PARENTHESIS \
204 /DSQLITE_ENABLE_DBSTAT_VTAB \
205 /DSQLITE_WIN32_NO_ANSI
206
207 SHELL_OPTIONS = /Dmain=sqlite3_shell \
208 /DSQLITE_OMIT_LOAD_EXTENSION=1 \
209 /DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
@@ -286,10 +287,11 @@
287 merge_.c \
288 merge3_.c \
289 moderate_.c \
290 name_.c \
291 path_.c \
292 piechart_.c \
293 pivot_.c \
294 popen_.c \
295 pqueue_.c \
296 printf_.c \
297 publish_.c \
@@ -456,10 +458,11 @@
458 $(OX)\merge$O \
459 $(OX)\merge3$O \
460 $(OX)\moderate$O \
461 $(OX)\name$O \
462 $(OX)\path$O \
463 $(OX)\piechart$O \
464 $(OX)\pivot$O \
465 $(OX)\popen$O \
466 $(OX)\pqueue$O \
467 $(OX)\printf$O \
468 $(OX)\publish$O \
@@ -631,10 +634,11 @@
634 echo $(OX)\merge.obj >> $@
635 echo $(OX)\merge3.obj >> $@
636 echo $(OX)\moderate.obj >> $@
637 echo $(OX)\name.obj >> $@
638 echo $(OX)\path.obj >> $@
639 echo $(OX)\piechart.obj >> $@
640 echo $(OX)\pivot.obj >> $@
641 echo $(OX)\popen.obj >> $@
642 echo $(OX)\pqueue.obj >> $@
643 echo $(OX)\printf.obj >> $@
644 echo $(OX)\publish.obj >> $@
@@ -1212,10 +1216,16 @@
1216 $(OX)\path$O : path_.c path.h
1217 $(TCC) /Fo$@ -c path_.c
1218
1219 path_.c : $(SRCDIR)\path.c
1220 translate$E $** > $@
1221
1222 $(OX)\piechart$O : piechart_.c piechart.h
1223 $(TCC) /Fo$@ -c piechart_.c
1224
1225 piechart_.c : $(SRCDIR)\piechart.c
1226 translate$E $** > $@
1227
1228 $(OX)\pivot$O : pivot_.c pivot.h
1229 $(TCC) /Fo$@ -c pivot_.c
1230
1231 pivot_.c : $(SRCDIR)\pivot.c
@@ -1565,10 +1575,11 @@
1575 merge_.c:merge.h \
1576 merge3_.c:merge3.h \
1577 moderate_.c:moderate.h \
1578 name_.c:name.h \
1579 path_.c:path.h \
1580 piechart_.c:piechart.h \
1581 pivot_.c:pivot.h \
1582 popen_.c:popen.h \
1583 pqueue_.c:pqueue.h \
1584 printf_.c:printf.h \
1585 publish_.c:publish.h \
1586
+33 -14
--- www/build.wiki
+++ www/build.wiki
@@ -26,39 +26,39 @@
2626
<p><hr>
2727
2828
<h2>1.0 Obtaining The Source Code</h2>
2929
3030
<p>Fossil is self-hosting, so you can obtain a ZIP archive or tarball
31
-containing a snapshot of the <em>latest</em> version directly from
32
-Fossil's own fossil repository. Additionally, source archives of
31
+containing a snapshot of the <em>latest</em> version directly from
32
+Fossil's own fossil repository. Additionally, source archives of
3333
<em>released</em> versions of
3434
fossil are available from the <a href="http://www.fossil-scm.org/download.html">downloads page</a>.
3535
To obtain a development version of fossil, follow these steps:</p>
3636
3737
<ol>
3838
<li><p>Point your web browser to
3939
<a href="http://www.fossil-scm.org/">
4040
http://www.fossil-scm.org/</a>.</p></li>
4141
42
-<li><p>Click on the
43
-<a href="http://www.fossil-scm.org/fossil/timeline">Timeline</a>
42
+<li><p>Click on the
43
+<a href="http://www.fossil-scm.org/fossil/timeline">Timeline</a>
4444
link at the top of the page.</p></li>
4545
4646
<li><p>Select a version of of Fossil you want to download. The latest
4747
version on the trunk branch is usually a good choice. Click on its
4848
link.</p></li>
4949
5050
<li><p>Finally, click on one of the
5151
"Zip Archive" or "Tarball" links, according to your preference.
52
-These link will build a ZIP archive or a gzip-compressed tarball of the
52
+These link will build a ZIP archive or a gzip-compressed tarball of the
5353
complete source code and download it to your computer.
5454
</ol>
5555
5656
<h2>Aside: Is it really safe to use an unreleased development version of
5757
the Fossil source code?</h2>
5858
59
-Yes! Any check-in on the
59
+Yes! Any check-in on the
6060
[/timeline?t=trunk | trunk branch] of the Fossil
6161
[http://fossil-scm.org/fossil/timeline | Fossil self-hosting repository]
6262
will work fine. (Dodgy code is always on a branch.) In the unlikely
6363
event that you pick a version with a serious bug, it still won't
6464
clobber your files. Fossil uses several
@@ -90,10 +90,14 @@
9090
9191
<li><p>
9292
To build a statically linked binary (suitable for use inside a chroot
9393
jail) add the <b>--static</b> option.
9494
95
+<li><p>
96
+To enable the native [./th1.md#tclEval | Tcl integration feature] feature,
97
+add the <b>--with-tcl=1</b> and <b>--with-tcl-private-stubs=1</b> options.
98
+
9599
<li><p>
96100
Other configuration options can be seen by running
97101
<b>./configure --help</b>
98102
</ol>
99103
@@ -102,20 +106,26 @@
102106
103107
<ol type="a">
104108
<li><p><i>Unix</i> → the configure-generated Makefile should work on
105109
all Unix and Unix-like systems. Simply type "<b>make</b>".
106110
107
-<li><p><i>Unix without running "configure"</i> → if you prefer to avoid running configure, you
108
-can also use: <b>make -f Makefile.classic</b>. You may want to make minor
109
-edits to Makefile.classic to configure the build for your system.
111
+<li><p><i>Unix without running "configure"</i> → if you prefer to avoid
112
+running configure, you can also use: <b>make -f Makefile.classic</b>. You may
113
+want to make minor edits to Makefile.classic to configure the build for your
114
+system.
110115
111116
<li><p><i>MinGW3.x (not 4.0)/MinGW-w64</i> → Use the mingw makefile:
112117
"<b>make -f win/Makefile.mingw</b>". On a Windows box you will
113118
need either Cygwin or Msys as build environment. On Cygwin, Linux
114119
or Darwin you may want to make minor edits to win/Makefile.mingw
115120
to configure the cross-compile environment.
116121
122
+To enable the native [./th1.md#tclEval | Tcl integration feature], use a
123
+command line like the following (all on one line):
124
+
125
+<b>make -f win/Makefile.mingw FOSSIL_ENABLE_TCL=1 FOSSIL_ENABLE_TCL_STUBS=1 FOSSIL_ENABLE_TCL_PRIVATE_STUBS=1</b>
126
+
117127
Hint: don't use MinGW-4.0, it will compile but fossil won't work correctly, see
118128
<a href="https://www.fossil-scm.org/index.html/tktview/18cff45a4e210430e24c">https://www.fossil-scm.org/index.html/tktview/18cff45a4e210430e24c</a>.
119129
120130
<li><p><i>MSVC</i> → Use the MSVC makefile. First
121131
change to the "win/" subdirectory ("<b>cd win</b>") then run
@@ -134,10 +144,19 @@
134144
nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
135145
</pre></blockquote>
136146
<blockquote><pre>
137147
buildmsvc.bat FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
138148
</pre></blockquote>
149
+To enable the optional native [./th1.md#tclEval | Tcl integration feature],
150
+run one of the following commands or add the &quot;FOSSIL_ENABLE_TCL=1&quot;
151
+argument to one of the other NMAKE command lines:
152
+<blockquote><pre>
153
+nmake /f Makefile.msc FOSSIL_ENABLE_TCL=1
154
+</pre></blockquote>
155
+<blockquote><pre>
156
+buildmsvc.bat FOSSIL_ENABLE_TCL=1
157
+</pre></blockquote>
139158
140159
<li><p><i>Cygwin</i> → The same as other Unix-like systems. It is
141160
recommended to configure using: "<b>configure --disable-internal-sqlite</b>",
142161
making sure you have the "libsqlite3-devel" , "zlib-devel" and
143162
"openssl-devel" packages installed first.
@@ -146,12 +165,12 @@
146165
147166
<h2>3.0 Installing</h2>
148167
149168
<ol>
150169
<li value="8">
151
-<p>The finished binary is named "fossil" (or "fossil.exe" on Windows).
152
-Put this binary in a
170
+<p>The finished binary is named "fossil" (or "fossil.exe" on Windows).
171
+Put this binary in a
153172
directory that is somewhere on your PATH environment variable.
154173
It does not matter where.</p>
155174
156175
<li>
157176
<p><b>(Optional:)</b>
@@ -167,14 +186,14 @@
167186
Fossil manually, then refer to the
168187
[./makefile.wiki | Fossil Build Process] document which describes
169188
in detail what the makefiles do behind the scenes.
170189
171190
<li><p>
172
- The fossil executable is self-contained and stand-alone and usually
173
- requires no special libraries or other software to be installed. However,
191
+ The fossil executable is self-contained and stand-alone and usually
192
+ requires no special libraries or other software to be installed. However,
174193
the "--tk" option to the [/help/diff|diff command] requires that Tcl/Tk
175
- be installed on the local machine. You can get Tcl/Tk from
194
+ be installed on the local machine. You can get Tcl/Tk from
176195
[http://www.activestate.com/activetcl|ActiveState].
177196
178197
<li><p>
179198
To build on older Macs (circa 2002, MacOS 10.2) edit the Makefile
180199
generated by configure to add the following lines:
181200
--- www/build.wiki
+++ www/build.wiki
@@ -26,39 +26,39 @@
26 <p><hr>
27
28 <h2>1.0 Obtaining The Source Code</h2>
29
30 <p>Fossil is self-hosting, so you can obtain a ZIP archive or tarball
31 containing a snapshot of the <em>latest</em> version directly from
32 Fossil's own fossil repository. Additionally, source archives of
33 <em>released</em> versions of
34 fossil are available from the <a href="http://www.fossil-scm.org/download.html">downloads page</a>.
35 To obtain a development version of fossil, follow these steps:</p>
36
37 <ol>
38 <li><p>Point your web browser to
39 <a href="http://www.fossil-scm.org/">
40 http://www.fossil-scm.org/</a>.</p></li>
41
42 <li><p>Click on the
43 <a href="http://www.fossil-scm.org/fossil/timeline">Timeline</a>
44 link at the top of the page.</p></li>
45
46 <li><p>Select a version of of Fossil you want to download. The latest
47 version on the trunk branch is usually a good choice. Click on its
48 link.</p></li>
49
50 <li><p>Finally, click on one of the
51 "Zip Archive" or "Tarball" links, according to your preference.
52 These link will build a ZIP archive or a gzip-compressed tarball of the
53 complete source code and download it to your computer.
54 </ol>
55
56 <h2>Aside: Is it really safe to use an unreleased development version of
57 the Fossil source code?</h2>
58
59 Yes! Any check-in on the
60 [/timeline?t=trunk | trunk branch] of the Fossil
61 [http://fossil-scm.org/fossil/timeline | Fossil self-hosting repository]
62 will work fine. (Dodgy code is always on a branch.) In the unlikely
63 event that you pick a version with a serious bug, it still won't
64 clobber your files. Fossil uses several
@@ -90,10 +90,14 @@
90
91 <li><p>
92 To build a statically linked binary (suitable for use inside a chroot
93 jail) add the <b>--static</b> option.
94
 
 
 
 
95 <li><p>
96 Other configuration options can be seen by running
97 <b>./configure --help</b>
98 </ol>
99
@@ -102,20 +106,26 @@
102
103 <ol type="a">
104 <li><p><i>Unix</i> → the configure-generated Makefile should work on
105 all Unix and Unix-like systems. Simply type "<b>make</b>".
106
107 <li><p><i>Unix without running "configure"</i> → if you prefer to avoid running configure, you
108 can also use: <b>make -f Makefile.classic</b>. You may want to make minor
109 edits to Makefile.classic to configure the build for your system.
 
110
111 <li><p><i>MinGW3.x (not 4.0)/MinGW-w64</i> → Use the mingw makefile:
112 "<b>make -f win/Makefile.mingw</b>". On a Windows box you will
113 need either Cygwin or Msys as build environment. On Cygwin, Linux
114 or Darwin you may want to make minor edits to win/Makefile.mingw
115 to configure the cross-compile environment.
116
 
 
 
 
 
117 Hint: don't use MinGW-4.0, it will compile but fossil won't work correctly, see
118 <a href="https://www.fossil-scm.org/index.html/tktview/18cff45a4e210430e24c">https://www.fossil-scm.org/index.html/tktview/18cff45a4e210430e24c</a>.
119
120 <li><p><i>MSVC</i> → Use the MSVC makefile. First
121 change to the "win/" subdirectory ("<b>cd win</b>") then run
@@ -134,10 +144,19 @@
134 nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
135 </pre></blockquote>
136 <blockquote><pre>
137 buildmsvc.bat FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
138 </pre></blockquote>
 
 
 
 
 
 
 
 
 
139
140 <li><p><i>Cygwin</i> → The same as other Unix-like systems. It is
141 recommended to configure using: "<b>configure --disable-internal-sqlite</b>",
142 making sure you have the "libsqlite3-devel" , "zlib-devel" and
143 "openssl-devel" packages installed first.
@@ -146,12 +165,12 @@
146
147 <h2>3.0 Installing</h2>
148
149 <ol>
150 <li value="8">
151 <p>The finished binary is named "fossil" (or "fossil.exe" on Windows).
152 Put this binary in a
153 directory that is somewhere on your PATH environment variable.
154 It does not matter where.</p>
155
156 <li>
157 <p><b>(Optional:)</b>
@@ -167,14 +186,14 @@
167 Fossil manually, then refer to the
168 [./makefile.wiki | Fossil Build Process] document which describes
169 in detail what the makefiles do behind the scenes.
170
171 <li><p>
172 The fossil executable is self-contained and stand-alone and usually
173 requires no special libraries or other software to be installed. However,
174 the "--tk" option to the [/help/diff|diff command] requires that Tcl/Tk
175 be installed on the local machine. You can get Tcl/Tk from
176 [http://www.activestate.com/activetcl|ActiveState].
177
178 <li><p>
179 To build on older Macs (circa 2002, MacOS 10.2) edit the Makefile
180 generated by configure to add the following lines:
181
--- www/build.wiki
+++ www/build.wiki
@@ -26,39 +26,39 @@
26 <p><hr>
27
28 <h2>1.0 Obtaining The Source Code</h2>
29
30 <p>Fossil is self-hosting, so you can obtain a ZIP archive or tarball
31 containing a snapshot of the <em>latest</em> version directly from
32 Fossil's own fossil repository. Additionally, source archives of
33 <em>released</em> versions of
34 fossil are available from the <a href="http://www.fossil-scm.org/download.html">downloads page</a>.
35 To obtain a development version of fossil, follow these steps:</p>
36
37 <ol>
38 <li><p>Point your web browser to
39 <a href="http://www.fossil-scm.org/">
40 http://www.fossil-scm.org/</a>.</p></li>
41
42 <li><p>Click on the
43 <a href="http://www.fossil-scm.org/fossil/timeline">Timeline</a>
44 link at the top of the page.</p></li>
45
46 <li><p>Select a version of of Fossil you want to download. The latest
47 version on the trunk branch is usually a good choice. Click on its
48 link.</p></li>
49
50 <li><p>Finally, click on one of the
51 "Zip Archive" or "Tarball" links, according to your preference.
52 These link will build a ZIP archive or a gzip-compressed tarball of the
53 complete source code and download it to your computer.
54 </ol>
55
56 <h2>Aside: Is it really safe to use an unreleased development version of
57 the Fossil source code?</h2>
58
59 Yes! Any check-in on the
60 [/timeline?t=trunk | trunk branch] of the Fossil
61 [http://fossil-scm.org/fossil/timeline | Fossil self-hosting repository]
62 will work fine. (Dodgy code is always on a branch.) In the unlikely
63 event that you pick a version with a serious bug, it still won't
64 clobber your files. Fossil uses several
@@ -90,10 +90,14 @@
90
91 <li><p>
92 To build a statically linked binary (suitable for use inside a chroot
93 jail) add the <b>--static</b> option.
94
95 <li><p>
96 To enable the native [./th1.md#tclEval | Tcl integration feature] feature,
97 add the <b>--with-tcl=1</b> and <b>--with-tcl-private-stubs=1</b> options.
98
99 <li><p>
100 Other configuration options can be seen by running
101 <b>./configure --help</b>
102 </ol>
103
@@ -102,20 +106,26 @@
106
107 <ol type="a">
108 <li><p><i>Unix</i> → the configure-generated Makefile should work on
109 all Unix and Unix-like systems. Simply type "<b>make</b>".
110
111 <li><p><i>Unix without running "configure"</i> → if you prefer to avoid
112 running configure, you can also use: <b>make -f Makefile.classic</b>. You may
113 want to make minor edits to Makefile.classic to configure the build for your
114 system.
115
116 <li><p><i>MinGW3.x (not 4.0)/MinGW-w64</i> → Use the mingw makefile:
117 "<b>make -f win/Makefile.mingw</b>". On a Windows box you will
118 need either Cygwin or Msys as build environment. On Cygwin, Linux
119 or Darwin you may want to make minor edits to win/Makefile.mingw
120 to configure the cross-compile environment.
121
122 To enable the native [./th1.md#tclEval | Tcl integration feature], use a
123 command line like the following (all on one line):
124
125 <b>make -f win/Makefile.mingw FOSSIL_ENABLE_TCL=1 FOSSIL_ENABLE_TCL_STUBS=1 FOSSIL_ENABLE_TCL_PRIVATE_STUBS=1</b>
126
127 Hint: don't use MinGW-4.0, it will compile but fossil won't work correctly, see
128 <a href="https://www.fossil-scm.org/index.html/tktview/18cff45a4e210430e24c">https://www.fossil-scm.org/index.html/tktview/18cff45a4e210430e24c</a>.
129
130 <li><p><i>MSVC</i> → Use the MSVC makefile. First
131 change to the "win/" subdirectory ("<b>cd win</b>") then run
@@ -134,10 +144,19 @@
144 nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
145 </pre></blockquote>
146 <blockquote><pre>
147 buildmsvc.bat FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
148 </pre></blockquote>
149 To enable the optional native [./th1.md#tclEval | Tcl integration feature],
150 run one of the following commands or add the &quot;FOSSIL_ENABLE_TCL=1&quot;
151 argument to one of the other NMAKE command lines:
152 <blockquote><pre>
153 nmake /f Makefile.msc FOSSIL_ENABLE_TCL=1
154 </pre></blockquote>
155 <blockquote><pre>
156 buildmsvc.bat FOSSIL_ENABLE_TCL=1
157 </pre></blockquote>
158
159 <li><p><i>Cygwin</i> → The same as other Unix-like systems. It is
160 recommended to configure using: "<b>configure --disable-internal-sqlite</b>",
161 making sure you have the "libsqlite3-devel" , "zlib-devel" and
162 "openssl-devel" packages installed first.
@@ -146,12 +165,12 @@
165
166 <h2>3.0 Installing</h2>
167
168 <ol>
169 <li value="8">
170 <p>The finished binary is named "fossil" (or "fossil.exe" on Windows).
171 Put this binary in a
172 directory that is somewhere on your PATH environment variable.
173 It does not matter where.</p>
174
175 <li>
176 <p><b>(Optional:)</b>
@@ -167,14 +186,14 @@
186 Fossil manually, then refer to the
187 [./makefile.wiki | Fossil Build Process] document which describes
188 in detail what the makefiles do behind the scenes.
189
190 <li><p>
191 The fossil executable is self-contained and stand-alone and usually
192 requires no special libraries or other software to be installed. However,
193 the "--tk" option to the [/help/diff|diff command] requires that Tcl/Tk
194 be installed on the local machine. You can get Tcl/Tk from
195 [http://www.activestate.com/activetcl|ActiveState].
196
197 <li><p>
198 To build on older Macs (circa 2002, MacOS 10.2) edit the Makefile
199 generated by configure to add the following lines:
200
+35 -2
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,22 +1,55 @@
11
<title>Change Log</title>
22
33
<h2>Changes for Version 1.33 (not released yet)</h2>
4
+ * Improved fork detection on [/help?cmd=update|fossil update],
5
+ [/help?cmd=status|fossil status] and related commands.
6
+ * Change the default skin to what used to be called "San Francisco Modern".
7
+ * Add the [/repo-tabsize] web page
48
* Add [/help?cmd=import|fossil import --svn], for importing a subversion
59
repository into fossil which was exported using "svnadmin dump".
10
+ * Add the "--compress-only" option to [/help?cmd=rebuild|fossil rebuild].
11
+ * Use a pie chart on the [/reports?view=byuser] page.
12
+ * Enhanced [/help?cmd=clean|fossil clean --verily] so that it ignores
13
+ keep-glob and ignore-glob settings. Added the -x alias for --verily.
14
+ * Add the --soft and --hard options to [/help?cmd=rm|fossil rm] and
15
+ [/help?cmd=mv|fossil mv]. The default is still --soft, but that is
16
+ now configurable at compile-time or by the mv-rm-files setting.
17
+ * Improved ability to [./customgraph.md|customize the timelime graph].
18
+ * Improvements to the [/sitemap] page.
19
+ * Automatically adjust the [/help?cmd=timeline|CLI timeline] to the terminal
20
+ width on Linux.
621
* Added <nowiki>[info commands] and [info vars]</nowiki> commands to TH1.
722
These commands perform the same function as their Tcl counterparts,
823
except they do not accept a pattern argument.
924
* Fix some obscure issues with TH1 expression processing.
1025
* Fix titles in search results for documents that are not wiki, markdown,
1126
or HTML.
1227
* Formally translate TH1 to Tcl return codes and vice-versa, where
1328
necessary, in the Tcl integration subsystem.
14
- * Better fork detection on [/help?cmd=update|fossil update],
15
- [/help?cmd=status|fossil status] and related commands.
1629
* Add [/help?cmd=leaves|fossil leaves -multiple], for finding multiple
1730
leaves on the same branch.
31
+ * Added the "Blitz" skin option.
32
+ * Removed the ".fossil-settings/keep-glob" file. It should not have been
33
+ checked into the repository.
34
+ * Update the built-in SQLite to version 3.8.10.2.
35
+ * Make [/help?cmd=open|fossil open] honor ".fossil-settings/allow-symlinks".
36
+ * Allow [/help?cmd=add|fossil add] to be used on symlinks to nonexistent or
37
+ unreadable files in the same way as [/help?cmd=addremove|fossil addremove].
38
+ * Added fork warning to be issued if sync produced a fork
39
+ * Update the [/help?cmd=/info|info] page to report when a file becomes a
40
+ symlink. Additionally show the UUID for files whose types have changed
41
+ without changing contents or symlink target.
42
+ * Have [/help?cmd=changes|fossil changes] and
43
+ [/help?cmd=status|fossil status] report when executable or symlink status
44
+ changes on otherwise unmodified files.
45
+ * Permit filtering weekday and file [/help?cmd=/reports|reports] by user.
46
+ Also ensure the user parameter is preserved when changing types. Add a
47
+ field for direct entry of the user name to each applicable report.
48
+ * Create parent directories of [/help?cmd=settings|empty-dirs] if they don't
49
+ already exist.
50
+ * Inhibit timeline links to wiki pages that have been deleted.
1851
1952
<h2>Changes for Version 1.32 (2015-03-14)</h2>
2053
* When creating a new repository using [/help?cmd=init|fossil init], ensure
2154
that the new repository is fully compatible with historical versions of
2255
Fossil by having a valid manifest as RID 1.
2356
2457
ADDED www/customgraph.md
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,22 +1,55 @@
1 <title>Change Log</title>
2
3 <h2>Changes for Version 1.33 (not released yet)</h2>
 
 
 
 
4 * Add [/help?cmd=import|fossil import --svn], for importing a subversion
5 repository into fossil which was exported using "svnadmin dump".
 
 
 
 
 
 
 
 
 
 
 
6 * Added <nowiki>[info commands] and [info vars]</nowiki> commands to TH1.
7 These commands perform the same function as their Tcl counterparts,
8 except they do not accept a pattern argument.
9 * Fix some obscure issues with TH1 expression processing.
10 * Fix titles in search results for documents that are not wiki, markdown,
11 or HTML.
12 * Formally translate TH1 to Tcl return codes and vice-versa, where
13 necessary, in the Tcl integration subsystem.
14 * Better fork detection on [/help?cmd=update|fossil update],
15 [/help?cmd=status|fossil status] and related commands.
16 * Add [/help?cmd=leaves|fossil leaves -multiple], for finding multiple
17 leaves on the same branch.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
19 <h2>Changes for Version 1.32 (2015-03-14)</h2>
20 * When creating a new repository using [/help?cmd=init|fossil init], ensure
21 that the new repository is fully compatible with historical versions of
22 Fossil by having a valid manifest as RID 1.
23
24 DDED www/customgraph.md
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,22 +1,55 @@
1 <title>Change Log</title>
2
3 <h2>Changes for Version 1.33 (not released yet)</h2>
4 * Improved fork detection on [/help?cmd=update|fossil update],
5 [/help?cmd=status|fossil status] and related commands.
6 * Change the default skin to what used to be called "San Francisco Modern".
7 * Add the [/repo-tabsize] web page
8 * Add [/help?cmd=import|fossil import --svn], for importing a subversion
9 repository into fossil which was exported using "svnadmin dump".
10 * Add the "--compress-only" option to [/help?cmd=rebuild|fossil rebuild].
11 * Use a pie chart on the [/reports?view=byuser] page.
12 * Enhanced [/help?cmd=clean|fossil clean --verily] so that it ignores
13 keep-glob and ignore-glob settings. Added the -x alias for --verily.
14 * Add the --soft and --hard options to [/help?cmd=rm|fossil rm] and
15 [/help?cmd=mv|fossil mv]. The default is still --soft, but that is
16 now configurable at compile-time or by the mv-rm-files setting.
17 * Improved ability to [./customgraph.md|customize the timelime graph].
18 * Improvements to the [/sitemap] page.
19 * Automatically adjust the [/help?cmd=timeline|CLI timeline] to the terminal
20 width on Linux.
21 * Added <nowiki>[info commands] and [info vars]</nowiki> commands to TH1.
22 These commands perform the same function as their Tcl counterparts,
23 except they do not accept a pattern argument.
24 * Fix some obscure issues with TH1 expression processing.
25 * Fix titles in search results for documents that are not wiki, markdown,
26 or HTML.
27 * Formally translate TH1 to Tcl return codes and vice-versa, where
28 necessary, in the Tcl integration subsystem.
 
 
29 * Add [/help?cmd=leaves|fossil leaves -multiple], for finding multiple
30 leaves on the same branch.
31 * Added the "Blitz" skin option.
32 * Removed the ".fossil-settings/keep-glob" file. It should not have been
33 checked into the repository.
34 * Update the built-in SQLite to version 3.8.10.2.
35 * Make [/help?cmd=open|fossil open] honor ".fossil-settings/allow-symlinks".
36 * Allow [/help?cmd=add|fossil add] to be used on symlinks to nonexistent or
37 unreadable files in the same way as [/help?cmd=addremove|fossil addremove].
38 * Added fork warning to be issued if sync produced a fork
39 * Update the [/help?cmd=/info|info] page to report when a file becomes a
40 symlink. Additionally show the UUID for files whose types have changed
41 without changing contents or symlink target.
42 * Have [/help?cmd=changes|fossil changes] and
43 [/help?cmd=status|fossil status] report when executable or symlink status
44 changes on otherwise unmodified files.
45 * Permit filtering weekday and file [/help?cmd=/reports|reports] by user.
46 Also ensure the user parameter is preserved when changing types. Add a
47 field for direct entry of the user name to each applicable report.
48 * Create parent directories of [/help?cmd=settings|empty-dirs] if they don't
49 already exist.
50 * Inhibit timeline links to wiki pages that have been deleted.
51
52 <h2>Changes for Version 1.32 (2015-03-14)</h2>
53 * When creating a new repository using [/help?cmd=init|fossil init], ensure
54 that the new repository is fully compatible with historical versions of
55 Fossil by having a valid manifest as RID 1.
56
57 DDED www/customgraph.md
--- a/www/customgraph.md
+++ b/www/customgraph.md
@@ -0,0 +1,144 @@
1
+# Customizing the Timeline Graph
2
+
3
+Beginning with version 1.33, Fossil gives users and skin authors significantly
4
+more control over the look and feel of the timeline graph.
5
+
6
+## <a id="basic-style"></a>Basic Style Options
7
+
8
+Fossil includes several options for changing the graph's style without having
9
+to delve into CSS. These can be found in the details.txt file of your skin or
10
+under Admin/Skins/D###`timeline-arrowheads`
11
+
12
+ Set this to `0` to hide arrowheads on primary child lines.
13
+
14
+* ### Set this to `node s`**
15
+
16
+ Set this to `1` to### `timeline-color-graph-line`
17
+
18
+ Set this to `1` to colorize### `white-foreground`
19
+
20
+ Set this to `round`**
21
+
22
+ Seses white (or any light color) text.
23
+ This tells Fossil to generate darker background colors for branches.
24
+
25
+
26
+## <a id="adv-style"></a>Advanced Styling
27
+
28
+If the above options aren't enough for you, it's time to get your hands dirty
29
+with CSS. To get started, I recommend first copying all the [graph-related CSS
30
+rules](#default-css) to your stylesheet. Then it's simply a matter of making
31
+the necessary changes to achieve the look you want. So, next, let's look at the
32
+various graph elements and what purpose they serve.
33
+
34
+Each element used to construct the timeline graph falls into one of two
35
+categories: visible elements and positioning elements. We'll start with the
36
+latter, less obvious type.
37
+
38
+## <a id="pos-elems"></a>Positioning Elements
39
+
40
+These elements aren't intended to be seen. They're only used to h### <a id="
41
+
42
+ Set the left and right margins on this class to give the desired amount
43
+ of space between tunt
44
+ of space between the graph and its adjacent columns in the timeline.
45
+
46
+ #### Ad ditional Classes
47
+ **Additional Classes**
48
+
49
+ * `.sel`: See [`.tl-node`](#tl-node) ### <a id="tl-rail"></a>`.tl-rail`tl-rail"></a>**`.tl-rail`**
50
+
51
+ Think of rails as invisibl Think of rails as invisible vertical lines o placed. The more simultaneous branches in a graph, the more rails required
52
+ to draw it. Setting the `width` property on this class determines the
53
+ maximum spacing between rails. This spacing is automatically reduced as
54
+ the number of rails increases. If you change the `width` of `.tl-node`
55
+ elements, you'll probably need to ch###ing the Timeline Graph
56
+
57
+Begi# Customizing theoreground`**
58
+
59
+ Set this to `1` if your skin uses white (or any light color) text.
60
+ T`
61
+
62
+ Set this to `round`**
63
+
64
+ Set this to `1` if your skin uses white (or any light color) text.
65
+ This tells Fossil to generate darker background colors for branches.
66
+
67
+
68
+## <a id="adv-style"></a>Advanced Styling
69
+
70
+If the above options aren't enough for you, it's time to get your hands dirty
71
+with CSS. To get started, I recommend first copying all the [graph-related CSS
72
+rules](#default-css) to yourcessary changes to achieve the look you want. So, next, let's look at the
73
+various graph elements and what purpose they serve.
74
+
75
+Each element used to construct the timeline graph falls into one of two
76
+categories: visible elements and positioning elements. We'll start with the
77
+latter, less obvious type.
78
+
79
+## <a id="pos-elems"></a>Positioning Elements
80
+
81
+These elements aren't intended to be seen. They're only used to h### <a id="
82
+
83
+ Set the left and right margins on this class to give the desired amount
84
+ of space between the graph and its adjaidth` of `.tl-node`
85
+ elements, you'll probably need to ch###ing the Timeline Graph
86
+
87
+Begi# Customizing theoreground`**
88
+
89
+ Set this to ` Think of rails as invisibl node`](#tl-node) ### <a id="tl-rail"></a>`.tl-rail`tl-rail"></a>**`.tl-rail`**
90
+
91
+ Thin more simultaneous branches in a graph, the more rails required
92
+ to draw it. Setting the `width` property on this class determines the
93
+ maximum spacing between rails. This spacing is automatically reduced as
94
+ the number of rails increases. If you change the `width` of `.tl-node`
95
+ elements, you'll probably need to ch###ing the Timeline Graph
96
+
97
+Begi# Customizing theoreground`**
98
+
99
+ Set this to `1` if your skin uses white (or any light color) text.
100
+ T`
101
+
102
+ Set this to `round`**
103
+
104
+ Set this to `1` if your skin uses white (or any light color) text.
105
+ This tells Fossil to generate darker background colors for branches.
106
+
107
+
108
+## <a id="adv-style"></a>Advanced Styling
109
+
110
+If the above options ar round: transparent;
111
+ border: 0 dotted #000;
112
+ }
113
+ . d #000;
114
+ }
115
+ .tl-line.merge.h {
116
+ border-top-width: 1px;
117
+ -#### Additional Classesl-node) for more infasses**
118
+
119
+ * `.merge`: A merge line.
120
+
121
+ * skin authors significantly
122
+more# Customizing the Timeline Graph
123
+
124
+Beginning with version 1.33, Fossil gives users and skin authors significantly
125
+more control over the look and feel of the timeline graph.
126
+
127
+## <a id="basic-style"></a>Basic Sty skin authors significantly
128
+more control over the look and feel of the timeline graph.
129
+
130
+## <a id="basic-style"></a>Basic Style Options
131
+
132
+Fossil includes several options for changing the graph's style without having
133
+to delve into CSS. These can be found in the details.txt file of your skin or
134
+under Admin/Skins/D###`timeline-arrowheads`
135
+
136
+ Set this to `0` to hide arrowheads on primary child lines.
137
+
138
+* ### Set this to `nodes`**
139
+
140
+ Set this to `1` to### `timeline-color-graph-line`
141
+
142
+ Set this to `1` to colorize### `white-foreground`
143
+
144
+ Set this to `round`**
--- a/www/customgraph.md
+++ b/www/customgraph.md
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/www/customgraph.md
+++ b/www/customgraph.md
@@ -0,0 +1,144 @@
1 # Customizing the Timeline Graph
2
3 Beginning with version 1.33, Fossil gives users and skin authors significantly
4 more control over the look and feel of the timeline graph.
5
6 ## <a id="basic-style"></a>Basic Style Options
7
8 Fossil includes several options for changing the graph's style without having
9 to delve into CSS. These can be found in the details.txt file of your skin or
10 under Admin/Skins/D###`timeline-arrowheads`
11
12 Set this to `0` to hide arrowheads on primary child lines.
13
14 * ### Set this to `node s`**
15
16 Set this to `1` to### `timeline-color-graph-line`
17
18 Set this to `1` to colorize### `white-foreground`
19
20 Set this to `round`**
21
22 Seses white (or any light color) text.
23 This tells Fossil to generate darker background colors for branches.
24
25
26 ## <a id="adv-style"></a>Advanced Styling
27
28 If the above options aren't enough for you, it's time to get your hands dirty
29 with CSS. To get started, I recommend first copying all the [graph-related CSS
30 rules](#default-css) to your stylesheet. Then it's simply a matter of making
31 the necessary changes to achieve the look you want. So, next, let's look at the
32 various graph elements and what purpose they serve.
33
34 Each element used to construct the timeline graph falls into one of two
35 categories: visible elements and positioning elements. We'll start with the
36 latter, less obvious type.
37
38 ## <a id="pos-elems"></a>Positioning Elements
39
40 These elements aren't intended to be seen. They're only used to h### <a id="
41
42 Set the left and right margins on this class to give the desired amount
43 of space between tunt
44 of space between the graph and its adjacent columns in the timeline.
45
46 #### Ad ditional Classes
47 **Additional Classes**
48
49 * `.sel`: See [`.tl-node`](#tl-node) ### <a id="tl-rail"></a>`.tl-rail`tl-rail"></a>**`.tl-rail`**
50
51 Think of rails as invisibl Think of rails as invisible vertical lines o placed. The more simultaneous branches in a graph, the more rails required
52 to draw it. Setting the `width` property on this class determines the
53 maximum spacing between rails. This spacing is automatically reduced as
54 the number of rails increases. If you change the `width` of `.tl-node`
55 elements, you'll probably need to ch###ing the Timeline Graph
56
57 Begi# Customizing theoreground`**
58
59 Set this to `1` if your skin uses white (or any light color) text.
60 T`
61
62 Set this to `round`**
63
64 Set this to `1` if your skin uses white (or any light color) text.
65 This tells Fossil to generate darker background colors for branches.
66
67
68 ## <a id="adv-style"></a>Advanced Styling
69
70 If the above options aren't enough for you, it's time to get your hands dirty
71 with CSS. To get started, I recommend first copying all the [graph-related CSS
72 rules](#default-css) to yourcessary changes to achieve the look you want. So, next, let's look at the
73 various graph elements and what purpose they serve.
74
75 Each element used to construct the timeline graph falls into one of two
76 categories: visible elements and positioning elements. We'll start with the
77 latter, less obvious type.
78
79 ## <a id="pos-elems"></a>Positioning Elements
80
81 These elements aren't intended to be seen. They're only used to h### <a id="
82
83 Set the left and right margins on this class to give the desired amount
84 of space between the graph and its adjaidth` of `.tl-node`
85 elements, you'll probably need to ch###ing the Timeline Graph
86
87 Begi# Customizing theoreground`**
88
89 Set this to ` Think of rails as invisibl node`](#tl-node) ### <a id="tl-rail"></a>`.tl-rail`tl-rail"></a>**`.tl-rail`**
90
91 Thin more simultaneous branches in a graph, the more rails required
92 to draw it. Setting the `width` property on this class determines the
93 maximum spacing between rails. This spacing is automatically reduced as
94 the number of rails increases. If you change the `width` of `.tl-node`
95 elements, you'll probably need to ch###ing the Timeline Graph
96
97 Begi# Customizing theoreground`**
98
99 Set this to `1` if your skin uses white (or any light color) text.
100 T`
101
102 Set this to `round`**
103
104 Set this to `1` if your skin uses white (or any light color) text.
105 This tells Fossil to generate darker background colors for branches.
106
107
108 ## <a id="adv-style"></a>Advanced Styling
109
110 If the above options ar round: transparent;
111 border: 0 dotted #000;
112 }
113 . d #000;
114 }
115 .tl-line.merge.h {
116 border-top-width: 1px;
117 -#### Additional Classesl-node) for more infasses**
118
119 * `.merge`: A merge line.
120
121 * skin authors significantly
122 more# Customizing the Timeline Graph
123
124 Beginning with version 1.33, Fossil gives users and skin authors significantly
125 more control over the look and feel of the timeline graph.
126
127 ## <a id="basic-style"></a>Basic Sty skin authors significantly
128 more control over the look and feel of the timeline graph.
129
130 ## <a id="basic-style"></a>Basic Style Options
131
132 Fossil includes several options for changing the graph's style without having
133 to delve into CSS. These can be found in the details.txt file of your skin or
134 under Admin/Skins/D###`timeline-arrowheads`
135
136 Set this to `0` to hide arrowheads on primary child lines.
137
138 * ### Set this to `nodes`**
139
140 Set this to `1` to### `timeline-color-graph-line`
141
142 Set this to `1` to colorize### `white-foreground`
143
144 Set this to `round`**
--- www/customskin.md
+++ www/customskin.md
@@ -232,5 +232,10 @@
232232
233233
4. Copy/paste the resulting css.txt, details.txt,
234234
header.txt, and footer.txt files
235235
into the CSS, details, header, and footer configuration screens
236236
under the Admin/Skins menu.
237
+
238
+See Also
239
+--------
240
+
241
+* [Customizing the Timeline Graph](customgraph.md)
237242
--- www/customskin.md
+++ www/customskin.md
@@ -232,5 +232,10 @@
232
233 4. Copy/paste the resulting css.txt, details.txt,
234 header.txt, and footer.txt files
235 into the CSS, details, header, and footer configuration screens
236 under the Admin/Skins menu.
 
 
 
 
 
237
--- www/customskin.md
+++ www/customskin.md
@@ -232,5 +232,10 @@
232
233 4. Copy/paste the resulting css.txt, details.txt,
234 header.txt, and footer.txt files
235 into the CSS, details, header, and footer configuration screens
236 under the Admin/Skins menu.
237
238 See Also
239 --------
240
241 * [Customizing the Timeline Graph](customgraph.md)
242
--- www/mkindex.tcl
+++ www/mkindex.tcl
@@ -17,10 +17,11 @@
1717
checkin.wiki {Check-in Checklist}
1818
changes.wiki {Fossil Changelog}
1919
copyright-release.html {Contributor License Agreement}
2020
concepts.wiki {Fossil Core Concepts}
2121
contribute.wiki {Contributing Code or Documentation To The Fossil Project}
22
+ customgraph.md {Theming: Customizing the Timeline Graph}
2223
customskin.md {Theming: Customizing The Appearance of Web Pages}
2324
custom_ticket.wiki {Customizing The Ticket System}
2425
delta_encoder_algorithm.wiki {Fossil Delta Encoding Algorithm}
2526
delta_format.wiki {Fossil Delta Format}
2627
embeddeddoc.wiki {Embedded Project Documentation}
2728
--- www/mkindex.tcl
+++ www/mkindex.tcl
@@ -17,10 +17,11 @@
17 checkin.wiki {Check-in Checklist}
18 changes.wiki {Fossil Changelog}
19 copyright-release.html {Contributor License Agreement}
20 concepts.wiki {Fossil Core Concepts}
21 contribute.wiki {Contributing Code or Documentation To The Fossil Project}
 
22 customskin.md {Theming: Customizing The Appearance of Web Pages}
23 custom_ticket.wiki {Customizing The Ticket System}
24 delta_encoder_algorithm.wiki {Fossil Delta Encoding Algorithm}
25 delta_format.wiki {Fossil Delta Format}
26 embeddeddoc.wiki {Embedded Project Documentation}
27
--- www/mkindex.tcl
+++ www/mkindex.tcl
@@ -17,10 +17,11 @@
17 checkin.wiki {Check-in Checklist}
18 changes.wiki {Fossil Changelog}
19 copyright-release.html {Contributor License Agreement}
20 concepts.wiki {Fossil Core Concepts}
21 contribute.wiki {Contributing Code or Documentation To The Fossil Project}
22 customgraph.md {Theming: Customizing the Timeline Graph}
23 customskin.md {Theming: Customizing The Appearance of Web Pages}
24 custom_ticket.wiki {Customizing The Ticket System}
25 delta_encoder_algorithm.wiki {Fossil Delta Encoding Algorithm}
26 delta_format.wiki {Fossil Delta Format}
27 embeddeddoc.wiki {Embedded Project Documentation}
28
--- www/permutedindex.html
+++ www/permutedindex.html
@@ -34,12 +34,12 @@
3434
<li><a href="private.wiki">Branches &mdash; Creating, Syncing, and Deleting Private</a></li>
3535
<li><a href="branching.wiki">Branching, Forking, Merging, and Tagging</a></li>
3636
<li><a href="bugtheory.wiki">Bug Tracking In Fossil</a></li>
3737
<li><a href="makefile.wiki">Build Process &mdash; The Fossil</a></li>
3838
<li><a href="changes.wiki">Changelog &mdash; Fossil</a></li>
39
-<li><a href="checkin.wiki">Check-in Checklist</a></li>
4039
<li><a href="checkin_names.wiki">Check-in And Version Names</a></li>
40
+<li><a href="checkin.wiki">Check-in Checklist</a></li>
4141
<li><a href="checkin.wiki">Checklist &mdash; Check-in</a></li>
4242
<li><a href="../test/release-checklist.wiki">Checklist &mdash; Pre-Release Testing</a></li>
4343
<li><a href="foss-cklist.wiki">Checklist For Successful Open-Source Projects</a></li>
4444
<li><a href="selfcheck.wiki">Checks &mdash; Fossil Repository Integrity Self</a></li>
4545
<li><a href="contribute.wiki">Code or Documentation To The Fossil Project &mdash; Contributing</a></li>
@@ -54,10 +54,11 @@
5454
<li><a href="newrepo.wiki">Create A New Fossil Repository &mdash; How To</a></li>
5555
<li><a href="private.wiki">Creating, Syncing, and Deleting Private Branches</a></li>
5656
<li><a href="qandc.wiki">Criticisms &mdash; Questions And</a></li>
5757
<li><a href="customskin.md">Customizing The Appearance of Web Pages &mdash; Theming:</a></li>
5858
<li><a href="custom_ticket.wiki">Customizing The Ticket System</a></li>
59
+<li><a href="customgraph.md">Customizing the Timeline Graph &mdash; Theming:</a></li>
5960
<li><a href="tech_overview.wiki">Databases Used By Fossil &mdash; SQLite</a></li>
6061
<li><a href="antibot.wiki">Defense against Spiders and Bots</a></li>
6162
<li><a href="shunning.wiki">Deleting Content From Fossil &mdash; Shunning:</a></li>
6263
<li><a href="private.wiki">Deleting Private Branches &mdash; Creating, Syncing, and</a></li>
6364
<li><a href="delta_encoder_algorithm.wiki">Delta Encoding Algorithm &mdash; Fossil</a></li>
@@ -95,10 +96,11 @@
9596
<li><a href="inout.wiki">From Git &mdash; Import And Export To And</a></li>
9697
<li><a href="quotes.wiki">General &mdash; Quotes: What People Are Saying About Fossil, Git, and DVCSes in</a></li>
9798
<li><a href="fossil-v-git.wiki">Git &mdash; Fossil Versus</a></li>
9899
<li><a href="inout.wiki">Git &mdash; Import And Export To And From</a></li>
99100
<li><a href="quotes.wiki">Git, and DVCSes in General &mdash; Quotes: What People Are Saying About Fossil,</a></li>
101
+<li><a href="customgraph.md">Graph &mdash; Theming: Customizing the Timeline</a></li>
100102
<li><a href="quickstart.wiki">Guide &mdash; Fossil Quick Start</a></li>
101103
<li><a href="style.wiki">Guidelines &mdash; Source Code Style</a></li>
102104
<li><a href="hacker-howto.wiki">Hacker How-To</a></li>
103105
<li><a href="adding_code.wiki">Hacking Fossil</a></li>
104106
<li><a href="hints.wiki">Hints &mdash; Fossil Tips And Usage</a></li>
@@ -176,13 +178,15 @@
176178
<li><a href="sync.wiki">The Fossil Sync Protocol</a></li>
177179
<li><a href="tickets.wiki">The Fossil Ticket System</a></li>
178180
<li><a href="webui.wiki">The Fossil Web Interface</a></li>
179181
<li><a href="th1.md">The TH1 Scripting Language</a></li>
180182
<li><a href="customskin.md">Theming: Customizing The Appearance of Web Pages</a></li>
183
+<li><a href="customgraph.md">Theming: Customizing the Timeline Graph</a></li>
181184
<li><a href="theory1.wiki">Thoughts On The Design Of The Fossil DVCS</a></li>
182185
<li><a href="custom_ticket.wiki">Ticket System &mdash; Customizing The</a></li>
183186
<li><a href="tickets.wiki">Ticket System &mdash; The Fossil</a></li>
187
+<li><a href="customgraph.md">Timeline Graph &mdash; Theming: Customizing the</a></li>
184188
<li><a href="hints.wiki">Tips And Usage Hints &mdash; Fossil</a></li>
185189
<li><a href="bugtheory.wiki">Tracking In Fossil &mdash; Bug</a></li>
186190
<li><a href="fiveminutes.wiki">Update and Running in 5 Minutes as a Single User</a></li>
187191
<li><a href="hints.wiki">Usage Hints &mdash; Fossil Tips And</a></li>
188192
<li><a href="fiveminutes.wiki">User &mdash; Update and Running in 5 Minutes as a Single</a></li>
189193
--- www/permutedindex.html
+++ www/permutedindex.html
@@ -34,12 +34,12 @@
34 <li><a href="private.wiki">Branches &mdash; Creating, Syncing, and Deleting Private</a></li>
35 <li><a href="branching.wiki">Branching, Forking, Merging, and Tagging</a></li>
36 <li><a href="bugtheory.wiki">Bug Tracking In Fossil</a></li>
37 <li><a href="makefile.wiki">Build Process &mdash; The Fossil</a></li>
38 <li><a href="changes.wiki">Changelog &mdash; Fossil</a></li>
39 <li><a href="checkin.wiki">Check-in Checklist</a></li>
40 <li><a href="checkin_names.wiki">Check-in And Version Names</a></li>
 
41 <li><a href="checkin.wiki">Checklist &mdash; Check-in</a></li>
42 <li><a href="../test/release-checklist.wiki">Checklist &mdash; Pre-Release Testing</a></li>
43 <li><a href="foss-cklist.wiki">Checklist For Successful Open-Source Projects</a></li>
44 <li><a href="selfcheck.wiki">Checks &mdash; Fossil Repository Integrity Self</a></li>
45 <li><a href="contribute.wiki">Code or Documentation To The Fossil Project &mdash; Contributing</a></li>
@@ -54,10 +54,11 @@
54 <li><a href="newrepo.wiki">Create A New Fossil Repository &mdash; How To</a></li>
55 <li><a href="private.wiki">Creating, Syncing, and Deleting Private Branches</a></li>
56 <li><a href="qandc.wiki">Criticisms &mdash; Questions And</a></li>
57 <li><a href="customskin.md">Customizing The Appearance of Web Pages &mdash; Theming:</a></li>
58 <li><a href="custom_ticket.wiki">Customizing The Ticket System</a></li>
 
59 <li><a href="tech_overview.wiki">Databases Used By Fossil &mdash; SQLite</a></li>
60 <li><a href="antibot.wiki">Defense against Spiders and Bots</a></li>
61 <li><a href="shunning.wiki">Deleting Content From Fossil &mdash; Shunning:</a></li>
62 <li><a href="private.wiki">Deleting Private Branches &mdash; Creating, Syncing, and</a></li>
63 <li><a href="delta_encoder_algorithm.wiki">Delta Encoding Algorithm &mdash; Fossil</a></li>
@@ -95,10 +96,11 @@
95 <li><a href="inout.wiki">From Git &mdash; Import And Export To And</a></li>
96 <li><a href="quotes.wiki">General &mdash; Quotes: What People Are Saying About Fossil, Git, and DVCSes in</a></li>
97 <li><a href="fossil-v-git.wiki">Git &mdash; Fossil Versus</a></li>
98 <li><a href="inout.wiki">Git &mdash; Import And Export To And From</a></li>
99 <li><a href="quotes.wiki">Git, and DVCSes in General &mdash; Quotes: What People Are Saying About Fossil,</a></li>
 
100 <li><a href="quickstart.wiki">Guide &mdash; Fossil Quick Start</a></li>
101 <li><a href="style.wiki">Guidelines &mdash; Source Code Style</a></li>
102 <li><a href="hacker-howto.wiki">Hacker How-To</a></li>
103 <li><a href="adding_code.wiki">Hacking Fossil</a></li>
104 <li><a href="hints.wiki">Hints &mdash; Fossil Tips And Usage</a></li>
@@ -176,13 +178,15 @@
176 <li><a href="sync.wiki">The Fossil Sync Protocol</a></li>
177 <li><a href="tickets.wiki">The Fossil Ticket System</a></li>
178 <li><a href="webui.wiki">The Fossil Web Interface</a></li>
179 <li><a href="th1.md">The TH1 Scripting Language</a></li>
180 <li><a href="customskin.md">Theming: Customizing The Appearance of Web Pages</a></li>
 
181 <li><a href="theory1.wiki">Thoughts On The Design Of The Fossil DVCS</a></li>
182 <li><a href="custom_ticket.wiki">Ticket System &mdash; Customizing The</a></li>
183 <li><a href="tickets.wiki">Ticket System &mdash; The Fossil</a></li>
 
184 <li><a href="hints.wiki">Tips And Usage Hints &mdash; Fossil</a></li>
185 <li><a href="bugtheory.wiki">Tracking In Fossil &mdash; Bug</a></li>
186 <li><a href="fiveminutes.wiki">Update and Running in 5 Minutes as a Single User</a></li>
187 <li><a href="hints.wiki">Usage Hints &mdash; Fossil Tips And</a></li>
188 <li><a href="fiveminutes.wiki">User &mdash; Update and Running in 5 Minutes as a Single</a></li>
189
--- www/permutedindex.html
+++ www/permutedindex.html
@@ -34,12 +34,12 @@
34 <li><a href="private.wiki">Branches &mdash; Creating, Syncing, and Deleting Private</a></li>
35 <li><a href="branching.wiki">Branching, Forking, Merging, and Tagging</a></li>
36 <li><a href="bugtheory.wiki">Bug Tracking In Fossil</a></li>
37 <li><a href="makefile.wiki">Build Process &mdash; The Fossil</a></li>
38 <li><a href="changes.wiki">Changelog &mdash; Fossil</a></li>
 
39 <li><a href="checkin_names.wiki">Check-in And Version Names</a></li>
40 <li><a href="checkin.wiki">Check-in Checklist</a></li>
41 <li><a href="checkin.wiki">Checklist &mdash; Check-in</a></li>
42 <li><a href="../test/release-checklist.wiki">Checklist &mdash; Pre-Release Testing</a></li>
43 <li><a href="foss-cklist.wiki">Checklist For Successful Open-Source Projects</a></li>
44 <li><a href="selfcheck.wiki">Checks &mdash; Fossil Repository Integrity Self</a></li>
45 <li><a href="contribute.wiki">Code or Documentation To The Fossil Project &mdash; Contributing</a></li>
@@ -54,10 +54,11 @@
54 <li><a href="newrepo.wiki">Create A New Fossil Repository &mdash; How To</a></li>
55 <li><a href="private.wiki">Creating, Syncing, and Deleting Private Branches</a></li>
56 <li><a href="qandc.wiki">Criticisms &mdash; Questions And</a></li>
57 <li><a href="customskin.md">Customizing The Appearance of Web Pages &mdash; Theming:</a></li>
58 <li><a href="custom_ticket.wiki">Customizing The Ticket System</a></li>
59 <li><a href="customgraph.md">Customizing the Timeline Graph &mdash; Theming:</a></li>
60 <li><a href="tech_overview.wiki">Databases Used By Fossil &mdash; SQLite</a></li>
61 <li><a href="antibot.wiki">Defense against Spiders and Bots</a></li>
62 <li><a href="shunning.wiki">Deleting Content From Fossil &mdash; Shunning:</a></li>
63 <li><a href="private.wiki">Deleting Private Branches &mdash; Creating, Syncing, and</a></li>
64 <li><a href="delta_encoder_algorithm.wiki">Delta Encoding Algorithm &mdash; Fossil</a></li>
@@ -95,10 +96,11 @@
96 <li><a href="inout.wiki">From Git &mdash; Import And Export To And</a></li>
97 <li><a href="quotes.wiki">General &mdash; Quotes: What People Are Saying About Fossil, Git, and DVCSes in</a></li>
98 <li><a href="fossil-v-git.wiki">Git &mdash; Fossil Versus</a></li>
99 <li><a href="inout.wiki">Git &mdash; Import And Export To And From</a></li>
100 <li><a href="quotes.wiki">Git, and DVCSes in General &mdash; Quotes: What People Are Saying About Fossil,</a></li>
101 <li><a href="customgraph.md">Graph &mdash; Theming: Customizing the Timeline</a></li>
102 <li><a href="quickstart.wiki">Guide &mdash; Fossil Quick Start</a></li>
103 <li><a href="style.wiki">Guidelines &mdash; Source Code Style</a></li>
104 <li><a href="hacker-howto.wiki">Hacker How-To</a></li>
105 <li><a href="adding_code.wiki">Hacking Fossil</a></li>
106 <li><a href="hints.wiki">Hints &mdash; Fossil Tips And Usage</a></li>
@@ -176,13 +178,15 @@
178 <li><a href="sync.wiki">The Fossil Sync Protocol</a></li>
179 <li><a href="tickets.wiki">The Fossil Ticket System</a></li>
180 <li><a href="webui.wiki">The Fossil Web Interface</a></li>
181 <li><a href="th1.md">The TH1 Scripting Language</a></li>
182 <li><a href="customskin.md">Theming: Customizing The Appearance of Web Pages</a></li>
183 <li><a href="customgraph.md">Theming: Customizing the Timeline Graph</a></li>
184 <li><a href="theory1.wiki">Thoughts On The Design Of The Fossil DVCS</a></li>
185 <li><a href="custom_ticket.wiki">Ticket System &mdash; Customizing The</a></li>
186 <li><a href="tickets.wiki">Ticket System &mdash; The Fossil</a></li>
187 <li><a href="customgraph.md">Timeline Graph &mdash; Theming: Customizing the</a></li>
188 <li><a href="hints.wiki">Tips And Usage Hints &mdash; Fossil</a></li>
189 <li><a href="bugtheory.wiki">Tracking In Fossil &mdash; Bug</a></li>
190 <li><a href="fiveminutes.wiki">Update and Running in 5 Minutes as a Single User</a></li>
191 <li><a href="hints.wiki">Usage Hints &mdash; Fossil Tips And</a></li>
192 <li><a href="fiveminutes.wiki">User &mdash; Update and Running in 5 Minutes as a Single</a></li>
193
+78 -39
--- www/th1.md
+++ www/th1.md
@@ -166,90 +166,90 @@
166166
All commands starting with "tcl", with the exception of "tclReady",
167167
require the Tcl integration subsystem be included at compile-time.
168168
Additionally, the "tcl" repository setting must be enabled at runtime
169169
in order to successfully make use of these commands.
170170
171
-TH1 anoncap Command
--------------------
171
+<a name="anoncap"></a>TH1 anoncap Command
172
+-----------------------------------------
172173
173174
* anoncap STRING...
174175
175176
Returns true if the anonymous user has all of the capabilities listed
176177
in STRING.
177178
178
-TH1 anycap Command
-------------------
179
+<a name="anycap"></a>TH1 anycap Command
180
+---------------------------------------
179181
180182
* anycap STRING
181183
182184
Returns true if the current user user has any one of the capabilities
183185
listed in STRING.
184186
185
-TH1 artifact Command
---------------------
187
+<a name="artifact"></a>TH1 artifact Command
188
+-------------------------------------------
186189
187190
* artifact ID ?FILENAME?
188191
189192
Attempts to locate the specified artifact and return its contents. An
190193
error is generated if the repository is not open or the artifact cannot
191194
be found.
192195
193
-TH1 checkout Command
---------------------
196
+<a name="checkout"></a>TH1 checkout Command
197
+-------------------------------------------
194198
195199
* checkout ?BOOLEAN?
196200
197201
Return the fully qualified directory name of the current checkout or an
198202
empty string if it is not available. Optionally, it will attempt to find
199203
the current checkout, opening the configuration ("user") database and the
200204
repository as necessary, if the boolean argument is non-zero.
201205
202
-TH1 combobox Command
---------------------
206
+<a name="combobox"></a>TH1 combobox Command
207
+-------------------------------------------
203208
204209
* combobox NAME TEXT-LIST NUMLINES
205210
206211
Generates and emits an HTML combobox. NAME is both the name of the
207212
CGI parameter and the name of a variable that contains the currently
208213
selected value. TEXT-LIST is a list of possible values for the
209214
combobox. NUMLINES is 1 for a true combobox. If NUMLINES is greater
210215
than one then the display is a listbox with the number of lines given.
211216
212
-TH1 date Command
-----------------
217
+<a name="date"></a>TH1 date Command
218
+-----------------------------------
213219
214220
* date ?-local?
215221
216222
Return a strings which is the current time and date. If the -local
217223
option is used, the date appears using localtime instead of UTC.
218224
219
-TH1 decorate Command
---------------------
225
+<a name="decorate"></a>TH1 decorate Command
226
+-------------------------------------------
220227
221228
* decorate STRING
222229
223230
Renders STRING as wiki content; however, only links are handled. No
224231
other markup is processed.
225232
226
-TH1 enable_output Command
--------------------------
233
+<a name="enable_output"></a>TH1 enable_output Command
234
+-----------------------------------------------------
227235
228236
* enable_output BOOLEAN
229237
230238
Enable or disable sending output when the combobox, puts, or wiki
231239
commands are used.
232240
233
-TH1 getParameter Command
-------------------------
241
+<a name="getParameter"></a>TH1 getParameter Command
242
+---------------------------------------------------
234243
235244
* getParameter NAME ?DEFAULT?
236245
237246
Returns the value of the specified query parameter or the specified
238247
default value when there is no matching query parameter.
239248
240
-TH1 globalState Command
------------------------
249
+<a name="globalState"></a>TH1 globalState Command
250
+-------------------------------------------------
241251
242252
* globalState NAME ?DEFAULT?
243253
244254
Returns a string containing the value of the specified global state
245255
variable -OR- the specified default value. The supported items are:
@@ -266,20 +266,20 @@
266266
267267
Attempts to query for unsupported global state variables will result
268268
in a script error. Additional global state variables may be exposed
269269
in the future.
270270
271
-TH1 hascap Command
-------------------
271
+<a name="hascap"></a>TH1 hascap Command
272
+---------------------------------------
272273
273274
* hascap STRING...
274275
275276
Returns true if the current user has all of the capabilities listed
276277
in STRING.
277278
278
-TH1 hasfeature Command
-----------------------
279
+<a name="hasfeature"></a>TH1 hasfeature Command
280
+-----------------------------------------------
279281
280282
* hasfeature STRING
281283
282284
Returns true if the binary has the given compile-time feature enabled.
283285
The possible features are:
@@ -294,27 +294,27 @@
294294
1. **tclPrivateStubs** -- _Uses Tcl private stubs (i.e. header-only)._
295295
1. **json** -- _Support for the JSON APIs._
296296
1. **markdown** -- _Support for Markdown documentation format._
297297
1. **unicodeCmdLine** -- _The command line arguments are Unicode._
298298
299
-TH1 html Command
-----------------
299
+<a name="html"></a>TH1 html Command
300
+-----------------------------------
300301
301302
* html STRING
302303
303304
Outputs the STRING escaped for HTML.
304305
305
-TH1 htmlize Command
--------------------
306
+<a name="htmlize"></a>TH1 htmlize Command
307
+-----------------------------------------
306308
307309
* htmlize STRING
308310
309311
Escape all characters of STRING which have special meaning in HTML.
310312
Returns the escaped string.
311313
312
-TH1 http Command
-----------------
314
+<a name="http"></a>TH1 http Command
315
+-----------------------------------
313316
314317
* http ?-asynchronous? ?--? url ?payload?
315318
316319
Performs an HTTP or HTTPS request for the specified URL. If a
317320
payload is present, it will be interpreted as text/plain and
@@ -322,35 +322,35 @@
322322
be used. Upon success, if the -asynchronous option is used, an
323323
empty string is returned as the result; otherwise, the response
324324
from the server is returned as the result. Synchronous requests
325325
are not currently implemented.
326326
327
-TH1 httpize Command
--------------------
327
+<a name="httpize"></a>TH1 httpize Command
328
+-----------------------------------------
328329
329330
* httpize STRING
330331
331332
Escape all characters of STRING which have special meaning in URI
332333
components. Returns the escaped string.
333334
334
-TH1 linecount Command
----------------------
335
+<a name="linecount"></a>TH1 linecount Command
336
+---------------------------------------------
335337
336338
* linecount STRING MAX MIN
337339
338340
Returns one more than the number of \n characters in STRING. But
339341
never returns less than MIN or more than MAX.
340342
341
-TH1 puts Command
-----------------
343
+<a name="puts"></a>TH1 puts Command
344
+-----------------------------------
342345
343346
* puts STRING
344347
345348
Outputs the STRING unchanged.
346349
347
-TH1 query Command
------------------
350
+<a name="query"></a>TH1 query Command
351
+-------------------------------------
348352
349353
* query SQL CODE
350354
351355
Runs the SQL query given by the SQL argument. For each row in the result
352356
set, run CODE.
@@ -357,52 +357,52 @@
357357
358358
In SQL, parameters such as $var are filled in using the value of variable
359359
"var". Result values are stored in variables with the column name prior
360360
to each invocation of CODE.
361361
362
-TH1 randhex Command
--------------------
362
+<a name="randhex"></a>TH1 randhex Command
363
+-----------------------------------------
363364
364365
* randhex N
365366
366367
Returns a string of N*2 random hexadecimal digits with N<50. If N is
367368
omitted, use a value of 10.
368369
369
-TH1 regexp Command
-------------------
370
+<a name="regexp"></a>TH1 regexp Command
371
+---------------------------------------
370372
371373
* regexp ?-nocase? ?--? exp string
372374
373375
Checks the string against the specified regular expression and returns
374376
non-zero if it matches. If the regular expression is invalid or cannot
375377
be compiled, an error will be generated.
376378
377
-TH1 reinitialize Command
-------------------------
379
+<a name="reinitialize"></a>TH1 reinitialize Command
380
+---------------------------------------------------
378381
379382
* reinitialize ?FLAGS?
380383
381384
Reinitializes the TH1 interpreter using the specified flags.
382385
383
-TH1 render Command
-------------------
386
+<a name="render"></a>TH1 render Command
387
+---------------------------------------
384388
385389
* render STRING
386390
387391
Renders the TH1 template and writes the results.
388392
389
-TH1 repository Command
-----------------------
393
+<a name="repository"></a>TH1 repository Command
394
+-----------------------------------------------
390395
391396
* repository ?BOOLEAN?
392397
393398
Returns the fully qualified file name of the open repository or an empty
394399
string if one is not currently open. Optionally, it will attempt to open
395400
the repository if the boolean argument is non-zero.
396401
397
-TH1 searchable Command
-----------------------
402
+<a name="searchable"></a>TH1 searchable Command
403
+-----------------------------------------------
398404
399405
* searchable STRING...
400406
401407
Return true if searching in any of the document classes identified
402408
by STRING is enabled for the repository and user has the necessary
@@ -426,104 +426,104 @@
426426
if {[searchable cdtw]} {...}
427427
428428
This command is useful for enabling or disabling a "Search" entry on the
429429
menu bar.
430430
431
-TH1 setParameter Command
-------------------------
431
+<a name="setParameter"></a>TH1 setParameter Command
432
+---------------------------------------------------
432433
433434
* setParameter NAME VALUE
434435
435436
Sets the value of the specified query parameter.
436437
437
-TH1 setting Command
--------------------
438
+<a name="setting"></a>TH1 setting Command
439
+-----------------------------------------
438440
439441
* setting name
440442
441443
Gets and returns the value of the specified setting.
442444
443
-TH1 styleHeader Command
------------------------
445
+<a name="styleHeader"></a>TH1 styleHeader Command
446
+-------------------------------------------------
444447
445448
* styleHeader TITLE
446449
447450
Render the configured style header.
448451
449
-TH1 styleFooter Command
------------------------
452
+<a name="styleFooter"></a>TH1 styleFooter Command
453
+-------------------------------------------------
450454
451455
* styleFooter
452456
453457
Render the configured style footer.
454458
455
-TH1 tclEval Command
--------------------
459
+<a name="tclEval"></a>TH1 tclEval Command
460
+-----------------------------------------
456461
457462
**This command requires the Tcl integration feature.**
458463
459464
* tclEval arg ?arg ...?
460465
461466
Evaluates the Tcl script and returns its result verbatim. If a Tcl script
462467
error is generated, it will be transformed into a TH1 script error. A Tcl
463468
interpreter will be created automatically if it has not been already.
464469
465
-TH1 tclExpr Command
--------------------
470
+<a name="tclExpr"></a>TH1 tclExpr Command
471
+-----------------------------------------
466472
467473
**This command requires the Tcl integration feature.**
468474
469475
* tclExpr arg ?arg ...?
470476
471477
Evaluates the Tcl expression and returns its result verbatim. If a Tcl
472478
script error is generated, it will be transformed into a TH1 script error.
473479
A Tcl interpreter will be created automatically if it has not been already.
474480
475
-TH1 tclInvoke Command
----------------------
481
+<a name="tclInvoke"></a>TH1 tclInvoke Command
482
+---------------------------------------------
476483
477484
**This command requires the Tcl integration feature.**
478485
479486
* tclInvoke command ?arg ...?
480487
481488
Invokes the Tcl command using the supplied arguments. No additional
482489
substitutions are performed on the arguments. A Tcl interpreter will
483490
be created automatically if it has not been already.
484491
485
-TH1 tclReady Command
---------------------
492
+<a name="tclReady"></a>TH1 tclReady Command
493
+-------------------------------------------
486494
487495
* tclReady
488496
489497
Returns true if the binary has the Tcl integration feature enabled and it
490498
is currently available for use by TH1 scripts.
491499
492
-TH1 trace Command
------------------
500
+<a name="trace"></a>TH1 trace Command
501
+-------------------------------------
493502
494503
* trace STRING
495504
496505
Generates a TH1 trace message if TH1 tracing is enabled.
497506
498
-TH1 stime Command
------------------
507
+<a name="stime"></a>TH1 stime Command
508
+-------------------------------------
499509
500510
* stime
501511
502512
Returns the number of microseconds of CPU time consumed by the current
503513
process in system space.
504514
505
-TH1 utime Command
------------------
515
+<a name="utime"></a>TH1 utime Command
516
+-------------------------------------
506517
507518
* utime
508519
509520
Returns the number of microseconds of CPU time consumed by the current
510521
process in user space.
511522
512
-TH1 wiki Command
-----------------
523
+<a name="wiki"></a>TH1 wiki Command
524
+-----------------------------------
513525
514526
* wiki STRING
515527
516528
Renders STRING as wiki content.
517529
@@ -536,22 +536,22 @@
536536
Tcl commands:
537537
538538
* th1Eval
539539
* th1Expr
540540
541
-Tcl th1Eval Command
--------------------
541
+<a name="th1Eval"></a>Tcl th1Eval Command
542
+-----------------------------------------
542543
543544
**This command requires the Tcl integration feature.**
544545
545546
* th1Eval arg
546547
547548
Evaluates the TH1 script and returns its result verbatim. If a TH1 script
548549
error is generated, it will be transformed into a Tcl script error.
549550
550
-Tcl th1Expr Command
--------------------
551
+<a name="th1Expr"></a>Tcl th1Expr Command
552
+-----------------------------------------
551553
552554
**This command requires the Tcl integration feature.**
553555
554556
* th1Expr arg
555557
556558
--- www/th1.md
+++ www/th1.md
@@ -166,90 +166,90 @@
166 All commands starting with "tcl", with the exception of "tclReady",
167 require the Tcl integration subsystem be included at compile-time.
168 Additionally, the "tcl" repository setting must be enabled at runtime
169 in order to successfully make use of these commands.
170
171 TH1 anoncap Command
--------------------
 
 
172
173 * anoncap STRING...
174
175 Returns true if the anonymous user has all of the capabilities listed
176 in STRING.
177
178 TH1 anycap Command
-------------------
 
 
179
180 * anycap STRING
181
182 Returns true if the current user user has any one of the capabilities
183 listed in STRING.
184
185 TH1 artifact Command
---------------------
 
 
186
187 * artifact ID ?FILENAME?
188
189 Attempts to locate the specified artifact and return its contents. An
190 error is generated if the repository is not open or the artifact cannot
191 be found.
192
193 TH1 checkout Command
---------------------
 
 
194
195 * checkout ?BOOLEAN?
196
197 Return the fully qualified directory name of the current checkout or an
198 empty string if it is not available. Optionally, it will attempt to find
199 the current checkout, opening the configuration ("user") database and the
200 repository as necessary, if the boolean argument is non-zero.
201
202 TH1 combobox Command
---------------------
 
 
203
204 * combobox NAME TEXT-LIST NUMLINES
205
206 Generates and emits an HTML combobox. NAME is both the name of the
207 CGI parameter and the name of a variable that contains the currently
208 selected value. TEXT-LIST is a list of possible values for the
209 combobox. NUMLINES is 1 for a true combobox. If NUMLINES is greater
210 than one then the display is a listbox with the number of lines given.
211
212 TH1 date Command
-----------------
 
 
213
214 * date ?-local?
215
216 Return a strings which is the current time and date. If the -local
217 option is used, the date appears using localtime instead of UTC.
218
219 TH1 decorate Command
---------------------
 
 
220
221 * decorate STRING
222
223 Renders STRING as wiki content; however, only links are handled. No
224 other markup is processed.
225
226 TH1 enable_output Command
--------------------------
 
 
227
228 * enable_output BOOLEAN
229
230 Enable or disable sending output when the combobox, puts, or wiki
231 commands are used.
232
233 TH1 getParameter Command
-------------------------
 
 
234
235 * getParameter NAME ?DEFAULT?
236
237 Returns the value of the specified query parameter or the specified
238 default value when there is no matching query parameter.
239
240 TH1 globalState Command
------------------------
 
 
241
242 * globalState NAME ?DEFAULT?
243
244 Returns a string containing the value of the specified global state
245 variable -OR- the specified default value. The supported items are:
@@ -266,20 +266,20 @@
266
267 Attempts to query for unsupported global state variables will result
268 in a script error. Additional global state variables may be exposed
269 in the future.
270
271 TH1 hascap Command
-------------------
 
 
272
273 * hascap STRING...
274
275 Returns true if the current user has all of the capabilities listed
276 in STRING.
277
278 TH1 hasfeature Command
-----------------------
 
 
279
280 * hasfeature STRING
281
282 Returns true if the binary has the given compile-time feature enabled.
283 The possible features are:
@@ -294,27 +294,27 @@
294 1. **tclPrivateStubs** -- _Uses Tcl private stubs (i.e. header-only)._
295 1. **json** -- _Support for the JSON APIs._
296 1. **markdown** -- _Support for Markdown documentation format._
297 1. **unicodeCmdLine** -- _The command line arguments are Unicode._
298
299 TH1 html Command
-----------------
 
 
300
301 * html STRING
302
303 Outputs the STRING escaped for HTML.
304
305 TH1 htmlize Command
--------------------
 
 
306
307 * htmlize STRING
308
309 Escape all characters of STRING which have special meaning in HTML.
310 Returns the escaped string.
311
312 TH1 http Command
-----------------
 
 
313
314 * http ?-asynchronous? ?--? url ?payload?
315
316 Performs an HTTP or HTTPS request for the specified URL. If a
317 payload is present, it will be interpreted as text/plain and
@@ -322,35 +322,35 @@
322 be used. Upon success, if the -asynchronous option is used, an
323 empty string is returned as the result; otherwise, the response
324 from the server is returned as the result. Synchronous requests
325 are not currently implemented.
326
327 TH1 httpize Command
--------------------
 
 
328
329 * httpize STRING
330
331 Escape all characters of STRING which have special meaning in URI
332 components. Returns the escaped string.
333
334 TH1 linecount Command
----------------------
 
 
335
336 * linecount STRING MAX MIN
337
338 Returns one more than the number of \n characters in STRING. But
339 never returns less than MIN or more than MAX.
340
341 TH1 puts Command
-----------------
 
 
342
343 * puts STRING
344
345 Outputs the STRING unchanged.
346
347 TH1 query Command
------------------
 
 
348
349 * query SQL CODE
350
351 Runs the SQL query given by the SQL argument. For each row in the result
352 set, run CODE.
@@ -357,52 +357,52 @@
357
358 In SQL, parameters such as $var are filled in using the value of variable
359 "var". Result values are stored in variables with the column name prior
360 to each invocation of CODE.
361
362 TH1 randhex Command
--------------------
 
 
363
364 * randhex N
365
366 Returns a string of N*2 random hexadecimal digits with N<50. If N is
367 omitted, use a value of 10.
368
369 TH1 regexp Command
-------------------
 
 
370
371 * regexp ?-nocase? ?--? exp string
372
373 Checks the string against the specified regular expression and returns
374 non-zero if it matches. If the regular expression is invalid or cannot
375 be compiled, an error will be generated.
376
377 TH1 reinitialize Command
-------------------------
 
 
378
379 * reinitialize ?FLAGS?
380
381 Reinitializes the TH1 interpreter using the specified flags.
382
383 TH1 render Command
-------------------
 
 
384
385 * render STRING
386
387 Renders the TH1 template and writes the results.
388
389 TH1 repository Command
-----------------------
 
 
390
391 * repository ?BOOLEAN?
392
393 Returns the fully qualified file name of the open repository or an empty
394 string if one is not currently open. Optionally, it will attempt to open
395 the repository if the boolean argument is non-zero.
396
397 TH1 searchable Command
-----------------------
 
 
398
399 * searchable STRING...
400
401 Return true if searching in any of the document classes identified
402 by STRING is enabled for the repository and user has the necessary
@@ -426,104 +426,104 @@
426 if {[searchable cdtw]} {...}
427
428 This command is useful for enabling or disabling a "Search" entry on the
429 menu bar.
430
431 TH1 setParameter Command
-------------------------
 
 
432
433 * setParameter NAME VALUE
434
435 Sets the value of the specified query parameter.
436
437 TH1 setting Command
--------------------
 
 
438
439 * setting name
440
441 Gets and returns the value of the specified setting.
442
443 TH1 styleHeader Command
------------------------
 
 
444
445 * styleHeader TITLE
446
447 Render the configured style header.
448
449 TH1 styleFooter Command
------------------------
 
 
450
451 * styleFooter
452
453 Render the configured style footer.
454
455 TH1 tclEval Command
--------------------
 
 
456
457 **This command requires the Tcl integration feature.**
458
459 * tclEval arg ?arg ...?
460
461 Evaluates the Tcl script and returns its result verbatim. If a Tcl script
462 error is generated, it will be transformed into a TH1 script error. A Tcl
463 interpreter will be created automatically if it has not been already.
464
465 TH1 tclExpr Command
--------------------
 
 
466
467 **This command requires the Tcl integration feature.**
468
469 * tclExpr arg ?arg ...?
470
471 Evaluates the Tcl expression and returns its result verbatim. If a Tcl
472 script error is generated, it will be transformed into a TH1 script error.
473 A Tcl interpreter will be created automatically if it has not been already.
474
475 TH1 tclInvoke Command
----------------------
 
 
476
477 **This command requires the Tcl integration feature.**
478
479 * tclInvoke command ?arg ...?
480
481 Invokes the Tcl command using the supplied arguments. No additional
482 substitutions are performed on the arguments. A Tcl interpreter will
483 be created automatically if it has not been already.
484
485 TH1 tclReady Command
---------------------
 
 
486
487 * tclReady
488
489 Returns true if the binary has the Tcl integration feature enabled and it
490 is currently available for use by TH1 scripts.
491
492 TH1 trace Command
------------------
 
 
493
494 * trace STRING
495
496 Generates a TH1 trace message if TH1 tracing is enabled.
497
498 TH1 stime Command
------------------
 
 
499
500 * stime
501
502 Returns the number of microseconds of CPU time consumed by the current
503 process in system space.
504
505 TH1 utime Command
------------------
 
 
506
507 * utime
508
509 Returns the number of microseconds of CPU time consumed by the current
510 process in user space.
511
512 TH1 wiki Command
-----------------
 
 
513
514 * wiki STRING
515
516 Renders STRING as wiki content.
517
@@ -536,22 +536,22 @@
536 Tcl commands:
537
538 * th1Eval
539 * th1Expr
540
541 Tcl th1Eval Command
--------------------
 
 
542
543 **This command requires the Tcl integration feature.**
544
545 * th1Eval arg
546
547 Evaluates the TH1 script and returns its result verbatim. If a TH1 script
548 error is generated, it will be transformed into a Tcl script error.
549
550 Tcl th1Expr Command
--------------------
 
 
551
552 **This command requires the Tcl integration feature.**
553
554 * th1Expr arg
555
556
--- www/th1.md
+++ www/th1.md
@@ -166,90 +166,90 @@
166 All commands starting with "tcl", with the exception of "tclReady",
167 require the Tcl integration subsystem be included at compile-time.
168 Additionally, the "tcl" repository setting must be enabled at runtime
169 in order to successfully make use of these commands.
170
 
--------------------
171 <a name="anoncap"></a>TH1 anoncap Command
172 -----------------------------------------
173
174 * anoncap STRING...
175
176 Returns true if the anonymous user has all of the capabilities listed
177 in STRING.
178
 
-------------------
179 <a name="anycap"></a>TH1 anycap Command
180 ---------------------------------------
181
182 * anycap STRING
183
184 Returns true if the current user user has any one of the capabilities
185 listed in STRING.
186
 
---------------------
187 <a name="artifact"></a>TH1 artifact Command
188 -------------------------------------------
189
190 * artifact ID ?FILENAME?
191
192 Attempts to locate the specified artifact and return its contents. An
193 error is generated if the repository is not open or the artifact cannot
194 be found.
195
 
---------------------
196 <a name="checkout"></a>TH1 checkout Command
197 -------------------------------------------
198
199 * checkout ?BOOLEAN?
200
201 Return the fully qualified directory name of the current checkout or an
202 empty string if it is not available. Optionally, it will attempt to find
203 the current checkout, opening the configuration ("user") database and the
204 repository as necessary, if the boolean argument is non-zero.
205
 
---------------------
206 <a name="combobox"></a>TH1 combobox Command
207 -------------------------------------------
208
209 * combobox NAME TEXT-LIST NUMLINES
210
211 Generates and emits an HTML combobox. NAME is both the name of the
212 CGI parameter and the name of a variable that contains the currently
213 selected value. TEXT-LIST is a list of possible values for the
214 combobox. NUMLINES is 1 for a true combobox. If NUMLINES is greater
215 than one then the display is a listbox with the number of lines given.
216
 
-----------------
217 <a name="date"></a>TH1 date Command
218 -----------------------------------
219
220 * date ?-local?
221
222 Return a strings which is the current time and date. If the -local
223 option is used, the date appears using localtime instead of UTC.
224
 
---------------------
225 <a name="decorate"></a>TH1 decorate Command
226 -------------------------------------------
227
228 * decorate STRING
229
230 Renders STRING as wiki content; however, only links are handled. No
231 other markup is processed.
232
 
--------------------------
233 <a name="enable_output"></a>TH1 enable_output Command
234 -----------------------------------------------------
235
236 * enable_output BOOLEAN
237
238 Enable or disable sending output when the combobox, puts, or wiki
239 commands are used.
240
 
-------------------------
241 <a name="getParameter"></a>TH1 getParameter Command
242 ---------------------------------------------------
243
244 * getParameter NAME ?DEFAULT?
245
246 Returns the value of the specified query parameter or the specified
247 default value when there is no matching query parameter.
248
 
------------------------
249 <a name="globalState"></a>TH1 globalState Command
250 -------------------------------------------------
251
252 * globalState NAME ?DEFAULT?
253
254 Returns a string containing the value of the specified global state
255 variable -OR- the specified default value. The supported items are:
@@ -266,20 +266,20 @@
266
267 Attempts to query for unsupported global state variables will result
268 in a script error. Additional global state variables may be exposed
269 in the future.
270
 
-------------------
271 <a name="hascap"></a>TH1 hascap Command
272 ---------------------------------------
273
274 * hascap STRING...
275
276 Returns true if the current user has all of the capabilities listed
277 in STRING.
278
 
-----------------------
279 <a name="hasfeature"></a>TH1 hasfeature Command
280 -----------------------------------------------
281
282 * hasfeature STRING
283
284 Returns true if the binary has the given compile-time feature enabled.
285 The possible features are:
@@ -294,27 +294,27 @@
294 1. **tclPrivateStubs** -- _Uses Tcl private stubs (i.e. header-only)._
295 1. **json** -- _Support for the JSON APIs._
296 1. **markdown** -- _Support for Markdown documentation format._
297 1. **unicodeCmdLine** -- _The command line arguments are Unicode._
298
 
-----------------
299 <a name="html"></a>TH1 html Command
300 -----------------------------------
301
302 * html STRING
303
304 Outputs the STRING escaped for HTML.
305
 
--------------------
306 <a name="htmlize"></a>TH1 htmlize Command
307 -----------------------------------------
308
309 * htmlize STRING
310
311 Escape all characters of STRING which have special meaning in HTML.
312 Returns the escaped string.
313
 
-----------------
314 <a name="http"></a>TH1 http Command
315 -----------------------------------
316
317 * http ?-asynchronous? ?--? url ?payload?
318
319 Performs an HTTP or HTTPS request for the specified URL. If a
320 payload is present, it will be interpreted as text/plain and
@@ -322,35 +322,35 @@
322 be used. Upon success, if the -asynchronous option is used, an
323 empty string is returned as the result; otherwise, the response
324 from the server is returned as the result. Synchronous requests
325 are not currently implemented.
326
 
--------------------
327 <a name="httpize"></a>TH1 httpize Command
328 -----------------------------------------
329
330 * httpize STRING
331
332 Escape all characters of STRING which have special meaning in URI
333 components. Returns the escaped string.
334
 
----------------------
335 <a name="linecount"></a>TH1 linecount Command
336 ---------------------------------------------
337
338 * linecount STRING MAX MIN
339
340 Returns one more than the number of \n characters in STRING. But
341 never returns less than MIN or more than MAX.
342
 
-----------------
343 <a name="puts"></a>TH1 puts Command
344 -----------------------------------
345
346 * puts STRING
347
348 Outputs the STRING unchanged.
349
 
------------------
350 <a name="query"></a>TH1 query Command
351 -------------------------------------
352
353 * query SQL CODE
354
355 Runs the SQL query given by the SQL argument. For each row in the result
356 set, run CODE.
@@ -357,52 +357,52 @@
357
358 In SQL, parameters such as $var are filled in using the value of variable
359 "var". Result values are stored in variables with the column name prior
360 to each invocation of CODE.
361
 
--------------------
362 <a name="randhex"></a>TH1 randhex Command
363 -----------------------------------------
364
365 * randhex N
366
367 Returns a string of N*2 random hexadecimal digits with N<50. If N is
368 omitted, use a value of 10.
369
 
-------------------
370 <a name="regexp"></a>TH1 regexp Command
371 ---------------------------------------
372
373 * regexp ?-nocase? ?--? exp string
374
375 Checks the string against the specified regular expression and returns
376 non-zero if it matches. If the regular expression is invalid or cannot
377 be compiled, an error will be generated.
378
 
-------------------------
379 <a name="reinitialize"></a>TH1 reinitialize Command
380 ---------------------------------------------------
381
382 * reinitialize ?FLAGS?
383
384 Reinitializes the TH1 interpreter using the specified flags.
385
 
-------------------
386 <a name="render"></a>TH1 render Command
387 ---------------------------------------
388
389 * render STRING
390
391 Renders the TH1 template and writes the results.
392
 
-----------------------
393 <a name="repository"></a>TH1 repository Command
394 -----------------------------------------------
395
396 * repository ?BOOLEAN?
397
398 Returns the fully qualified file name of the open repository or an empty
399 string if one is not currently open. Optionally, it will attempt to open
400 the repository if the boolean argument is non-zero.
401
 
-----------------------
402 <a name="searchable"></a>TH1 searchable Command
403 -----------------------------------------------
404
405 * searchable STRING...
406
407 Return true if searching in any of the document classes identified
408 by STRING is enabled for the repository and user has the necessary
@@ -426,104 +426,104 @@
426 if {[searchable cdtw]} {...}
427
428 This command is useful for enabling or disabling a "Search" entry on the
429 menu bar.
430
 
-------------------------
431 <a name="setParameter"></a>TH1 setParameter Command
432 ---------------------------------------------------
433
434 * setParameter NAME VALUE
435
436 Sets the value of the specified query parameter.
437
 
--------------------
438 <a name="setting"></a>TH1 setting Command
439 -----------------------------------------
440
441 * setting name
442
443 Gets and returns the value of the specified setting.
444
 
------------------------
445 <a name="styleHeader"></a>TH1 styleHeader Command
446 -------------------------------------------------
447
448 * styleHeader TITLE
449
450 Render the configured style header.
451
 
------------------------
452 <a name="styleFooter"></a>TH1 styleFooter Command
453 -------------------------------------------------
454
455 * styleFooter
456
457 Render the configured style footer.
458
 
--------------------
459 <a name="tclEval"></a>TH1 tclEval Command
460 -----------------------------------------
461
462 **This command requires the Tcl integration feature.**
463
464 * tclEval arg ?arg ...?
465
466 Evaluates the Tcl script and returns its result verbatim. If a Tcl script
467 error is generated, it will be transformed into a TH1 script error. A Tcl
468 interpreter will be created automatically if it has not been already.
469
 
--------------------
470 <a name="tclExpr"></a>TH1 tclExpr Command
471 -----------------------------------------
472
473 **This command requires the Tcl integration feature.**
474
475 * tclExpr arg ?arg ...?
476
477 Evaluates the Tcl expression and returns its result verbatim. If a Tcl
478 script error is generated, it will be transformed into a TH1 script error.
479 A Tcl interpreter will be created automatically if it has not been already.
480
 
----------------------
481 <a name="tclInvoke"></a>TH1 tclInvoke Command
482 ---------------------------------------------
483
484 **This command requires the Tcl integration feature.**
485
486 * tclInvoke command ?arg ...?
487
488 Invokes the Tcl command using the supplied arguments. No additional
489 substitutions are performed on the arguments. A Tcl interpreter will
490 be created automatically if it has not been already.
491
 
---------------------
492 <a name="tclReady"></a>TH1 tclReady Command
493 -------------------------------------------
494
495 * tclReady
496
497 Returns true if the binary has the Tcl integration feature enabled and it
498 is currently available for use by TH1 scripts.
499
 
------------------
500 <a name="trace"></a>TH1 trace Command
501 -------------------------------------
502
503 * trace STRING
504
505 Generates a TH1 trace message if TH1 tracing is enabled.
506
 
------------------
507 <a name="stime"></a>TH1 stime Command
508 -------------------------------------
509
510 * stime
511
512 Returns the number of microseconds of CPU time consumed by the current
513 process in system space.
514
 
------------------
515 <a name="utime"></a>TH1 utime Command
516 -------------------------------------
517
518 * utime
519
520 Returns the number of microseconds of CPU time consumed by the current
521 process in user space.
522
 
-----------------
523 <a name="wiki"></a>TH1 wiki Command
524 -----------------------------------
525
526 * wiki STRING
527
528 Renders STRING as wiki content.
529
@@ -536,22 +536,22 @@
536 Tcl commands:
537
538 * th1Eval
539 * th1Expr
540
 
--------------------
541 <a name="th1Eval"></a>Tcl th1Eval Command
542 -----------------------------------------
543
544 **This command requires the Tcl integration feature.**
545
546 * th1Eval arg
547
548 Evaluates the TH1 script and returns its result verbatim. If a TH1 script
549 error is generated, it will be transformed into a Tcl script error.
550
 
--------------------
551 <a name="th1Expr"></a>Tcl th1Expr Command
552 -----------------------------------------
553
554 **This command requires the Tcl integration feature.**
555
556 * th1Expr arg
557
558

Keyboard Shortcuts

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